@algolia/wizard 0.8.0-rc.65.53 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +620 -1417
- package/docs/algolia-sdk/README.md +26 -47
- package/docs/algolia-sdk/search-single-index.md +42 -0
- package/package.json +2 -2
- package/docs/algolia-sdk/instantsearch-setup-templates.md +0 -92
- package/docs/algolia-sdk/save-records-csharp.md +0 -71
- package/docs/algolia-sdk/save-records-go.md +0 -62
- package/docs/algolia-sdk/save-records-java.md +0 -66
- package/docs/algolia-sdk/save-records-kotlin.md +0 -60
- package/docs/algolia-sdk/save-records-php.md +0 -50
- package/docs/algolia-sdk/save-records-python.md +0 -51
- package/docs/algolia-sdk/save-records-ruby.md +0 -48
- package/docs/algolia-sdk/save-records-scala.md +0 -68
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Save records (algoliasearch-scala v2)
|
|
2
|
-
|
|
3
|
-
Adds records to an index. Write op — use a **write key**, server-side only.
|
|
4
|
-
|
|
5
|
-
sbt (`%%` appends the Scala binary version, resolving to
|
|
6
|
-
`com.algolia:algoliasearch-scala_2.13` on Scala 2.13):
|
|
7
|
-
|
|
8
|
-
```scala
|
|
9
|
-
libraryDependencies += "com.algolia" %% "algoliasearch-scala" % "2.22.0"
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
The object MUST be `AlgoliaWizardIngest` with an explicit `main` (not `extends
|
|
13
|
-
App`), in the **default package** (no `package` statement) — the wizard runs
|
|
14
|
-
`sbt "runMain AlgoliaWizardIngest"`.
|
|
15
|
-
|
|
16
|
-
```scala
|
|
17
|
-
import algoliasearch.api.SearchClient
|
|
18
|
-
import algoliasearch.extension.SearchClientExtensions // brings saveObjects into scope
|
|
19
|
-
import scala.concurrent.Await
|
|
20
|
-
import scala.concurrent.ExecutionContext.Implicits.global
|
|
21
|
-
import scala.concurrent.duration.Duration
|
|
22
|
-
|
|
23
|
-
object AlgoliaWizardIngest {
|
|
24
|
-
def main(args: Array[String]): Unit = {
|
|
25
|
-
val indexName = "products"
|
|
26
|
-
val records: Seq[Map[String, Any]] = Seq(Map("objectID" -> "1", "name" -> "Hot 100"))
|
|
27
|
-
|
|
28
|
-
val client = SearchClient(
|
|
29
|
-
appId = sys.env("ALGOLIA_APPLICATION_ID"),
|
|
30
|
-
apiKey = sys.env("ALGOLIA_WRITE_API_KEY")
|
|
31
|
-
)
|
|
32
|
-
try {
|
|
33
|
-
Await.result(client.saveObjects(indexName, records), Duration(120, "sec"))
|
|
34
|
-
println(s"ALGOLIA_WIZARD_RECORD_COUNT=${records.size}")
|
|
35
|
-
} finally client.close() // else okhttp's non-daemon threads hang the JVM
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Future-based API: a script must `Await.result` with a generous timeout, and an
|
|
41
|
-
implicit `ExecutionContext` must be in scope.
|
|
42
|
-
|
|
43
|
-
```scala
|
|
44
|
-
// objects: Seq[Map[String, Any]] or case classes, each carrying an objectID
|
|
45
|
-
def saveObjects(indexName: String, objects: Seq[Any], waitForTasks: Boolean = false,
|
|
46
|
-
batchSize: Int = 1000, requestOptions: Option[RequestOptions] = None)(
|
|
47
|
-
implicit ec: ExecutionContext): Future[Seq[BatchResponse]]
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Yields one `BatchResponse` (`taskID`, `objectIDs`) per batch of 1,000, not per record.
|
|
51
|
-
|
|
52
|
-
Read records from a JSON file (json4s ships with the client):
|
|
53
|
-
|
|
54
|
-
```scala
|
|
55
|
-
import algoliasearch.search.JsonSupport
|
|
56
|
-
import org.json4s.native.JsonMethods
|
|
57
|
-
import org.json4s.jvalue2extractable
|
|
58
|
-
import scala.io.Source
|
|
59
|
-
import scala.util.Using
|
|
60
|
-
|
|
61
|
-
implicit val formats: org.json4s.Formats = JsonSupport.format // required by extract
|
|
62
|
-
val records = JsonMethods
|
|
63
|
-
.parse(Using(Source.fromFile("records.json"))(_.mkString).get)
|
|
64
|
-
.extract[Seq[Map[String, Any]]]
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
After a successful ingest print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` (n = records
|
|
68
|
-
read, not the returned `Seq` size) as the last stdout line.
|