@algolia/wizard 0.6.0-rc.55.29 → 0.6.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.
@@ -1,48 +0,0 @@
1
- # Save records (algolia v3)
2
-
3
- Adds records to an index. Write op — use a **write key**, server-side only.
4
-
5
- Dependency: gem `algolia`, `~> 3.0` (`gem 'algolia', '~> 3.0'`).
6
-
7
- `require "algolia"` (gem name is `algolia`, not `algoliasearch`). Build the client
8
- with `Algolia::SearchClient.create`.
9
-
10
- ```ruby
11
- require "algolia"
12
-
13
- app_id = ENV.fetch("ALGOLIA_APPLICATION_ID")
14
- api_key = ENV.fetch("ALGOLIA_WRITE_API_KEY")
15
- index_name = "playlists"
16
-
17
- client = Algolia::SearchClient.create(app_id, api_key)
18
-
19
- records = [{ "objectID" => "1", "name" => "Hot 100", "visibility" => "public" }]
20
-
21
- responses = client.save_objects(index_name, records, true)
22
- ```
23
-
24
- ```ruby
25
- save_objects(
26
- index_name, # String, required
27
- objects, # Array<Hash>, required
28
- wait_for_tasks = false,
29
- batch_size = 1000,
30
- request_options = {}
31
- ) # => Array<Algolia::Search::BatchResponse>, one entry per 1,000-record batch
32
- ```
33
-
34
- Args are **positional**, and every method/field is **snake_case**: read
35
- `r.task_id` and `r.object_ids`, not `taskID`/`objectIDs`. The return value is an
36
- array — never treat it as one object.
37
-
38
- Read records from a JSON file:
39
-
40
- ```ruby
41
- require "json"
42
-
43
- records = JSON.parse(File.read(records_path))
44
- ```
45
-
46
- After a successful ingest, print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` as the last
47
- stdout line (`puts "ALGOLIA_WIZARD_RECORD_COUNT=#{records.length}"`), with no
48
- other output after it.
@@ -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.
@@ -1,88 +0,0 @@
1
- # Save records (algoliasearch-client-swift v9)
2
-
3
- Adds records to an index. Write op — use a **write key**, server-side only.
4
-
5
- The generated script is a standalone SwiftPM executable package at
6
- `.algolia-wizard/Ingest` (`Package.swift` + `Sources/Ingest/main.swift`), run with
7
- `swift run --package-path .algolia-wizard/Ingest`.
8
-
9
- ```swift
10
- // swift-tools-version: 5.9
11
- import PackageDescription
12
-
13
- let package = Package(
14
- name: "Ingest",
15
- platforms: [.macOS(.v13)],
16
- products: [.executable(name: "Ingest", targets: ["Ingest"])],
17
- dependencies: [
18
- .package(url: "https://github.com/algolia/algoliasearch-client-swift", from: "9.0.0"),
19
- ],
20
- targets: [
21
- .executableTarget(name: "Ingest", dependencies: [
22
- .product(name: "AlgoliaSearch", package: "algoliasearch-client-swift"),
23
- .product(name: "AlgoliaCore", package: "algoliasearch-client-swift"),
24
- ]),
25
- ]
26
- )
27
- ```
28
-
29
- Exactly one executable product, so `swift run --package-path` needs no target name.
30
- `platforms:` must be declared (the client requires macOS 11+); it is ignored on
31
- Linux. `package:` is the repo name, not the manifest's `AlgoliaSearchClient`.
32
-
33
- `main.swift` top-level code can't propagate a thrown error — wrap calls in `do`/`catch`.
34
-
35
- ```swift
36
- import Foundation
37
- #if canImport(AlgoliaCore)
38
- import AlgoliaCore
39
- #endif
40
- import AlgoliaSearch
41
-
42
- let env = ProcessInfo.processInfo.environment
43
- guard let appID = env["ALGOLIA_APPLICATION_ID"],
44
- let writeKey = env["ALGOLIA_WRITE_API_KEY"]
45
- else {
46
- FileHandle.standardError.write(Data("missing Algolia credentials\n".utf8))
47
- exit(1)
48
- }
49
- let indexName = "products"
50
-
51
- do {
52
- let client = try SearchClient(appID: appID, apiKey: writeKey)
53
- let records: [AnyCodable] = [
54
- ["objectID": "1", "name": "Adam"],
55
- ["objectID": "2", "name": "Benoit"],
56
- ]
57
- let responses = try await client.saveObjects(
58
- indexName: indexName, objects: records, waitForTasks: true
59
- )
60
- FileHandle.standardError.write(Data("batches: \(responses.count)\n".utf8))
61
- print("ALGOLIA_WIZARD_RECORD_COUNT=\(records.count)")
62
- } catch {
63
- FileHandle.standardError.write(Data("\(error)\n".utf8))
64
- exit(1)
65
- }
66
- ```
67
-
68
- ```swift
69
- func saveObjects(
70
- indexName: String, objects: [some Encodable], waitForTasks: Bool = false,
71
- batchSize: Int = 1000, requestOptions: RequestOptions? = nil
72
- ) async throws -> [BatchResponse]
73
- ```
74
-
75
- Records need an `objectID`; batching in 1,000s is automatic. Returns an **array**
76
- of `BatchResponse` (`taskID`, `objectIDs`), one per batch. `objects` is
77
- `[some Encodable]` — one homogeneous element type, so use `[AnyCodable]` (from
78
- `AlgoliaCore`) for arbitrary JSON records.
79
-
80
- Read records from a JSON file:
81
-
82
- ```swift
83
- let data = try Data(contentsOf: URL(fileURLWithPath: "records.json"))
84
- let records = try JSONDecoder().decode([AnyCodable].self, from: data)
85
- ```
86
-
87
- After a successful ingest, print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` as the last
88
- stdout line; send all other logging to stderr so nothing follows it on stdout.