@algolia/wizard 0.8.0-rc.63.52 → 0.8.0-rc.64.51
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
CHANGED
|
@@ -907,7 +907,7 @@ var accessItems = [
|
|
|
907
907
|
{
|
|
908
908
|
tag: "READ",
|
|
909
909
|
title: "Project files",
|
|
910
|
-
description: "reads your dependency manifests (package.json, pyproject.toml, Gemfile, go.mod\u2026), configs & source to detect your stack. Read-only; nothing is uploaded."
|
|
910
|
+
description: "reads your dependency manifests (package.json, pyproject.toml, Gemfile, go.mod, pom.xml\u2026), configs & source to detect your stack. Read-only; nothing is uploaded."
|
|
911
911
|
},
|
|
912
912
|
{
|
|
913
913
|
tag: "WRITE",
|
|
@@ -2429,6 +2429,155 @@ var LANGUAGE_PROFILES = {
|
|
|
2429
2429
|
],
|
|
2430
2430
|
envReadInstruction: "Read them from `os.Getenv`.",
|
|
2431
2431
|
skipDirs: ["vendor", "bin"]
|
|
2432
|
+
},
|
|
2433
|
+
java: {
|
|
2434
|
+
id: "java",
|
|
2435
|
+
displayName: "Java",
|
|
2436
|
+
aliases: ["java"],
|
|
2437
|
+
manifests: ["pom.xml", "build.gradle", "build.gradle.kts"],
|
|
2438
|
+
packageManagers: [
|
|
2439
|
+
{
|
|
2440
|
+
id: "maven",
|
|
2441
|
+
detectFiles: ["pom.xml"],
|
|
2442
|
+
sdkVersionPin: "[4,5)",
|
|
2443
|
+
dependency: { mode: "agent-declares", file: "pom.xml" },
|
|
2444
|
+
installSteps: [{ argv: ["mvn", "-q", "-DskipTests", "compile"] }],
|
|
2445
|
+
// The main class is a wizard constant the instructions require the agent
|
|
2446
|
+
// to use, so execution can't be redirected by agent output. Runnable only
|
|
2447
|
+
// because the install step above compiles src/main/java first — which is
|
|
2448
|
+
// why the entrypoint lives there rather than under .algolia-wizard/.
|
|
2449
|
+
ingest: {
|
|
2450
|
+
kind: "auto",
|
|
2451
|
+
argv: [
|
|
2452
|
+
"mvn",
|
|
2453
|
+
"-q",
|
|
2454
|
+
"org.codehaus.mojo:exec-maven-plugin:3.5.0:java",
|
|
2455
|
+
"-Dexec.mainClass=AlgoliaWizardIngest"
|
|
2456
|
+
],
|
|
2457
|
+
entrypointExtensions: [".java"]
|
|
2458
|
+
}
|
|
2459
|
+
},
|
|
2460
|
+
{
|
|
2461
|
+
id: "gradle",
|
|
2462
|
+
detectFiles: ["build.gradle", "build.gradle.kts"],
|
|
2463
|
+
dependency: {
|
|
2464
|
+
mode: "agent-declares",
|
|
2465
|
+
file: "build.gradle",
|
|
2466
|
+
alternatives: ["build.gradle.kts"]
|
|
2467
|
+
},
|
|
2468
|
+
installSteps: [],
|
|
2469
|
+
// Auto-running means executing the repo's own ./gradlew wrapper; out of
|
|
2470
|
+
// scope for now, so the wizard writes the code and prints the command.
|
|
2471
|
+
ingest: {
|
|
2472
|
+
kind: "manual",
|
|
2473
|
+
entrypointExtensions: [".java"],
|
|
2474
|
+
runCommand: "./gradlew runAlgoliaIngest",
|
|
2475
|
+
requiresBuildTask: "runAlgoliaIngest"
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
],
|
|
2479
|
+
sdk: {
|
|
2480
|
+
packageName: "com.algolia:algoliasearch",
|
|
2481
|
+
versionPin: "4.+",
|
|
2482
|
+
docKey: "java",
|
|
2483
|
+
alsoRequires: "The class must be named AlgoliaWizardIngest, in the default package (no `package` statement), with a `public static void main`."
|
|
2484
|
+
},
|
|
2485
|
+
// Not under .algolia-wizard/: Maven and Gradle only compile src/main/<lang>,
|
|
2486
|
+
// so a class outside it never makes it onto the classpath and the run command
|
|
2487
|
+
// fails with "class not found".
|
|
2488
|
+
ingestEntrypointExample: "src/main/java/AlgoliaWizardIngest.java",
|
|
2489
|
+
verification: [
|
|
2490
|
+
{
|
|
2491
|
+
label: "mvn compile",
|
|
2492
|
+
argv: ["mvn", "-q", "-DskipTests", "compile"],
|
|
2493
|
+
requiresFile: "pom.xml"
|
|
2494
|
+
}
|
|
2495
|
+
],
|
|
2496
|
+
envReadInstruction: "Read them from `System.getenv`.",
|
|
2497
|
+
skipDirs: ["target", "build", "out"]
|
|
2498
|
+
},
|
|
2499
|
+
kotlin: {
|
|
2500
|
+
id: "kotlin",
|
|
2501
|
+
displayName: "Kotlin",
|
|
2502
|
+
aliases: ["kotlin", "kt", "ktor"],
|
|
2503
|
+
manifests: ["build.gradle.kts", "build.gradle", "pom.xml"],
|
|
2504
|
+
packageManagers: [
|
|
2505
|
+
{
|
|
2506
|
+
id: "gradle",
|
|
2507
|
+
detectFiles: ["build.gradle.kts", "build.gradle"],
|
|
2508
|
+
dependency: {
|
|
2509
|
+
mode: "agent-declares",
|
|
2510
|
+
file: "build.gradle.kts",
|
|
2511
|
+
alternatives: ["build.gradle"]
|
|
2512
|
+
},
|
|
2513
|
+
installSteps: [],
|
|
2514
|
+
ingest: {
|
|
2515
|
+
kind: "manual",
|
|
2516
|
+
entrypointExtensions: [".kt"],
|
|
2517
|
+
runCommand: "./gradlew runAlgoliaIngest",
|
|
2518
|
+
requiresBuildTask: "runAlgoliaIngest"
|
|
2519
|
+
}
|
|
2520
|
+
},
|
|
2521
|
+
// Kotlin/Maven is rare but real, and pom.xml is a Kotlin manifest — without
|
|
2522
|
+
// this spec such a repo falls through to Gradle and is told to run a
|
|
2523
|
+
// ./gradlew task that doesn't exist. Compiling needs the repo's own
|
|
2524
|
+
// kotlin-maven-plugin, so the run stays the developer's step.
|
|
2525
|
+
{
|
|
2526
|
+
id: "maven",
|
|
2527
|
+
detectFiles: ["pom.xml"],
|
|
2528
|
+
sdkVersionPin: "[3,4)",
|
|
2529
|
+
dependency: { mode: "agent-declares", file: "pom.xml" },
|
|
2530
|
+
installSteps: [{ argv: ["mvn", "-q", "-DskipTests", "compile"] }],
|
|
2531
|
+
ingest: {
|
|
2532
|
+
kind: "manual",
|
|
2533
|
+
entrypointExtensions: [".kt"],
|
|
2534
|
+
runCommand: "mvn -q org.codehaus.mojo:exec-maven-plugin:3.5.0:java -Dexec.mainClass=AlgoliaWizardIngest"
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
],
|
|
2538
|
+
sdk: {
|
|
2539
|
+
packageName: "com.algolia:algoliasearch-client-kotlin",
|
|
2540
|
+
versionPin: "3.+",
|
|
2541
|
+
docKey: "kotlin",
|
|
2542
|
+
// The published client's commonMain ships only ktor-client-core; without an
|
|
2543
|
+
// engine the script compiles and then fails at its first request.
|
|
2544
|
+
alsoRequires: "The Kotlin client bundles no HTTP engine, so also declare one (e.g. io.ktor:ktor-client-okhttp). Name the object AlgoliaWizardIngest in the default package, with a @JvmStatic main."
|
|
2545
|
+
},
|
|
2546
|
+
ingestEntrypointExample: "src/main/kotlin/AlgoliaWizardIngest.kt",
|
|
2547
|
+
verification: [],
|
|
2548
|
+
envReadInstruction: "Read them from `System.getenv`.",
|
|
2549
|
+
skipDirs: ["build", "out"]
|
|
2550
|
+
},
|
|
2551
|
+
scala: {
|
|
2552
|
+
id: "scala",
|
|
2553
|
+
displayName: "Scala",
|
|
2554
|
+
aliases: ["scala", "sbt"],
|
|
2555
|
+
manifests: ["build.sbt", "build.sc"],
|
|
2556
|
+
packageManagers: [
|
|
2557
|
+
{
|
|
2558
|
+
id: "sbt",
|
|
2559
|
+
dependency: { mode: "agent-declares", file: "build.sbt" },
|
|
2560
|
+
installSteps: [],
|
|
2561
|
+
ingest: {
|
|
2562
|
+
kind: "manual",
|
|
2563
|
+
entrypointExtensions: [".scala"],
|
|
2564
|
+
runCommand: 'sbt "runMain AlgoliaWizardIngest"'
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
],
|
|
2568
|
+
sdk: {
|
|
2569
|
+
packageName: "com.algolia:algoliasearch-scala_2.13",
|
|
2570
|
+
versionPin: "2.+",
|
|
2571
|
+
docKey: "scala",
|
|
2572
|
+
alsoRequires: "Name the object AlgoliaWizardIngest in the default package (no `package` statement) so `runMain AlgoliaWizardIngest` resolves it."
|
|
2573
|
+
},
|
|
2574
|
+
ingestEntrypointExample: "src/main/scala/AlgoliaWizardIngest.scala",
|
|
2575
|
+
verification: [],
|
|
2576
|
+
envReadInstruction: "Read them from `sys.env`.",
|
|
2577
|
+
// `project/` holds sbt's build definition, but the name is generic enough
|
|
2578
|
+
// that some repos use it for source; scanning it is cheap, missing source
|
|
2579
|
+
// is not.
|
|
2580
|
+
skipDirs: ["target"]
|
|
2432
2581
|
}
|
|
2433
2582
|
};
|
|
2434
2583
|
var DEFAULT_LANGUAGE_ID = "javascript";
|
|
@@ -3111,9 +3260,9 @@ var detectLanguageSchema = z16.object({
|
|
|
3111
3260
|
var detectLanguage = () => runAgent({
|
|
3112
3261
|
instructions: [
|
|
3113
3262
|
"Analyze the codebase and determine the programming languages and frameworks used",
|
|
3114
|
-
"Start from the dependency manifests: package.json, pyproject.toml, requirements.txt, Gemfile, composer.json, go.mod.",
|
|
3263
|
+
"Start from the dependency manifests: package.json, pyproject.toml, requirements.txt, Gemfile, composer.json, go.mod, pom.xml, build.gradle(.kts), build.sbt.",
|
|
3115
3264
|
"List the language that owns the backend/data code first \u2014 that is the one an ingestion script will be written in.",
|
|
3116
|
-
"If a superset language is found, exclude the subset language. TS-over-JS.",
|
|
3265
|
+
"If a superset language is found, exclude the subset language. TS-over-JS. Kotlin-over-Java when Kotlin is primary.",
|
|
3117
3266
|
"If a meta-framework is used, exclude the framework. Next-over-React.",
|
|
3118
3267
|
"Frameworks include backend and server-rendering frameworks (e.g. Rails, Django, Laravel, Symfony, Spring Boot, ASP.NET Core, Flask, Gin, Ktor) as well as frontend ones (React, Vue, Angular, Svelte) and mobile ones (Flutter, SwiftUI).",
|
|
3119
3268
|
"Return the exact version",
|
|
@@ -3164,7 +3313,7 @@ var MODE_CONFIG = {
|
|
|
3164
3313
|
"Analyze the codebase to find the data entities (models) that should be ingested into Algolia.",
|
|
3165
3314
|
"For each entity, return its name, the file path(s) where it is defined, and its indexable attribute keys (the fields a user would search or filter on).",
|
|
3166
3315
|
"Inspect the source of each entity to extract real field names for attributes \u2014 do not guess or leave attributes empty.",
|
|
3167
|
-
"Entities live wherever the stack keeps them: TypeScript interfaces or a Prisma schema, Django models.py, Rails app/models, Laravel Eloquent models, Go structs, Pydantic models.",
|
|
3316
|
+
"Entities live wherever the stack keeps them: TypeScript interfaces or a Prisma schema, Django models.py, Rails app/models, Laravel Eloquent models, JPA @Entity classes, Go structs, Pydantic models.",
|
|
3168
3317
|
"Prefer domain models (e.g. Document, Product, User) over framework or infrastructure types.",
|
|
3169
3318
|
"Use as few tools as possible, but do not guess. If you cannot find any entities, return an empty array.",
|
|
3170
3319
|
"Ignore directories that may be related to testing, like `/fixtures`, `/tests`, etc",
|
|
@@ -3187,7 +3336,7 @@ var MODE_CONFIG = {
|
|
|
3187
3336
|
verification: {
|
|
3188
3337
|
instructions: [
|
|
3189
3338
|
"Analyze the codebase to determine which code-quality tools are available to validate changes.",
|
|
3190
|
-
"Look at the dependency manifest and config files for the project's languages: package.json scripts with tsconfig/eslint/prettier, pyproject.toml or setup.cfg (ruff, mypy, black), Gemfile with .rubocop.yml, composer.json scripts (phpstan, pint), go.mod with a golangci-lint config.",
|
|
3339
|
+
"Look at the dependency manifest and config files for the project's languages: package.json scripts with tsconfig/eslint/prettier, pyproject.toml or setup.cfg (ruff, mypy, black), Gemfile with .rubocop.yml, composer.json scripts (phpstan, pint), go.mod with a golangci-lint config, Maven/Gradle verification tasks.",
|
|
3191
3340
|
'Return the tool names as an array, e.g. ["eslint", "prettier", "tsc"] or ["ruff", "mypy"].',
|
|
3192
3341
|
"Use as few tools as possible, but do not guess. If you cannot find any, return an empty array.",
|
|
3193
3342
|
"Ignore directories that may be related to testing, like `/fixtures`, `/tests`, etc",
|
|
@@ -3215,7 +3364,7 @@ async function runAnalysis(mode, extraInstructions = []) {
|
|
|
3215
3364
|
// package.json
|
|
3216
3365
|
var package_default = {
|
|
3217
3366
|
name: "@algolia/wizard",
|
|
3218
|
-
version: "0.8.0-rc.
|
|
3367
|
+
version: "0.8.0-rc.64.51",
|
|
3219
3368
|
description: "Magically implement Algolia functionality in your codebase",
|
|
3220
3369
|
type: "module",
|
|
3221
3370
|
engines: {
|
|
@@ -3681,7 +3830,7 @@ ${JSON.stringify(s.output, null, 2)}`
|
|
|
3681
3830
|
}
|
|
3682
3831
|
function formatReviewSummary(result) {
|
|
3683
3832
|
const nextStepLines = result.nextSteps.map((step) => {
|
|
3684
|
-
const isIngestCommand = step.includes("algolia-wizard/");
|
|
3833
|
+
const isIngestCommand = step.includes("algolia-wizard/") || step.includes("AlgoliaWizardIngest");
|
|
3685
3834
|
const isWorktreeCommand = step.includes("/worktrees/");
|
|
3686
3835
|
return {
|
|
3687
3836
|
text: `\u2192 ${step}`,
|
|
@@ -20,6 +20,9 @@ Install the latest stable within the major; never pin an exact patch.
|
|
|
20
20
|
| Ruby | `algolia` | `~> 3.0` |
|
|
21
21
|
| PHP | `algolia/algoliasearch-client-php` | `^4` |
|
|
22
22
|
| Go | `github.com/algolia/algoliasearch-client-go/v4` | `v4` |
|
|
23
|
+
| Java | `com.algolia:algoliasearch` | `4.+` |
|
|
24
|
+
| Kotlin | `com.algolia:algoliasearch-client-kotlin` | `3.+` |
|
|
25
|
+
| Scala | `com.algolia:algoliasearch-scala_2.13` | `2.+` |
|
|
23
26
|
|
|
24
27
|
## Search UI
|
|
25
28
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Save records (algoliasearch Java v4)
|
|
2
|
+
|
|
3
|
+
Adds records to an index. Write op — use a **write key**, server-side only.
|
|
4
|
+
|
|
5
|
+
```xml
|
|
6
|
+
<dependency>
|
|
7
|
+
<groupId>com.algolia</groupId>
|
|
8
|
+
<artifactId>algoliasearch</artifactId>
|
|
9
|
+
<version>4.20.0</version>
|
|
10
|
+
</dependency>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```groovy
|
|
14
|
+
implementation 'com.algolia:algoliasearch:4.20.0'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The class MUST be `AlgoliaWizardIngest` with a `public static void main`, in the
|
|
18
|
+
**default package** (no `package` statement) — the wizard runs a fixed main class.
|
|
19
|
+
|
|
20
|
+
```java
|
|
21
|
+
import com.algolia.api.SearchClient;
|
|
22
|
+
import java.util.List;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
|
|
25
|
+
public class AlgoliaWizardIngest {
|
|
26
|
+
|
|
27
|
+
public static void main(String[] args) throws Exception {
|
|
28
|
+
String indexName = "products";
|
|
29
|
+
List<Map<String, Object>> records = List.of(Map.of("objectID", "1", "name", "Hot 100"));
|
|
30
|
+
|
|
31
|
+
SearchClient client =
|
|
32
|
+
new SearchClient(System.getenv("ALGOLIA_APPLICATION_ID"), System.getenv("ALGOLIA_WRITE_API_KEY"));
|
|
33
|
+
try {
|
|
34
|
+
client.saveObjects(indexName, records);
|
|
35
|
+
System.out.printf("ALGOLIA_WIZARD_RECORD_COUNT=%d%n", records.size());
|
|
36
|
+
} finally {
|
|
37
|
+
client.close(); // required: okhttp's non-daemon threads keep the JVM alive otherwise
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Blocking API — calls return directly and throw `AlgoliaApiException` on failure.
|
|
44
|
+
|
|
45
|
+
```java
|
|
46
|
+
// objects: Maps or POJOs (Jackson-serialized), each with an objectID
|
|
47
|
+
<T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects)
|
|
48
|
+
<T> List<BatchResponse> saveObjects(String indexName, Iterable<T> objects,
|
|
49
|
+
boolean waitForTasks, int batchSize, RequestOptions requestOptions) // batchSize default 1000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
One `BatchResponse` (`getTaskID()`, `getObjectIDs()`) per batch of 1,000, not per record.
|
|
53
|
+
|
|
54
|
+
Read records from a JSON file (Jackson is a transitive dependency):
|
|
55
|
+
|
|
56
|
+
```java
|
|
57
|
+
import com.fasterxml.jackson.core.type.TypeReference;
|
|
58
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
59
|
+
import java.io.File;
|
|
60
|
+
|
|
61
|
+
List<Map<String, Object>> records = new ObjectMapper()
|
|
62
|
+
.readValue(new File("records.json"), new TypeReference<List<Map<String, Object>>>() {});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
After a successful ingest print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` (n = records
|
|
66
|
+
read, not the returned list size) as the last stdout line.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Save records (algoliasearch-client-kotlin v3)
|
|
2
|
+
|
|
3
|
+
Adds records to an index. Write op — use a **write key**, server-side only.
|
|
4
|
+
|
|
5
|
+
Gradle Kotlin DSL. The client ships only `ktor-client-core`, so a JVM engine must
|
|
6
|
+
be declared too or the first call fails with no HTTP engine found:
|
|
7
|
+
|
|
8
|
+
```kotlin
|
|
9
|
+
implementation("com.algolia:algoliasearch-client-kotlin:3.23.0")
|
|
10
|
+
implementation("io.ktor:ktor-client-okhttp:3.2.0")
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`saveObjects` is a `suspend` extension, so a standalone script wraps it in
|
|
14
|
+
`runBlocking`. The object MUST be `AlgoliaWizardIngest` in the **default package**
|
|
15
|
+
(no `package` statement), and `@JvmStatic` is required — a `fun main` inside an
|
|
16
|
+
object is not a JVM entrypoint without it.
|
|
17
|
+
|
|
18
|
+
```kotlin
|
|
19
|
+
import com.algolia.client.api.SearchClient
|
|
20
|
+
import com.algolia.client.extensions.*
|
|
21
|
+
import java.io.File
|
|
22
|
+
import kotlinx.coroutines.runBlocking
|
|
23
|
+
import kotlinx.serialization.json.*
|
|
24
|
+
|
|
25
|
+
object AlgoliaWizardIngest {
|
|
26
|
+
@JvmStatic
|
|
27
|
+
fun main(args: Array<String>): Unit = runBlocking {
|
|
28
|
+
val indexName = "products"
|
|
29
|
+
val records: List<JsonObject> = listOf(buildJsonObject { put("objectID", "1"); put("name", "Hot 100") })
|
|
30
|
+
|
|
31
|
+
// System.getenv returns String?; the constructor params are non-null
|
|
32
|
+
SearchClient(
|
|
33
|
+
appId = requireNotNull(System.getenv("ALGOLIA_APPLICATION_ID")),
|
|
34
|
+
apiKey = requireNotNull(System.getenv("ALGOLIA_WRITE_API_KEY")),
|
|
35
|
+
).use { client -> // AutoCloseable: without use/close, okhttp's non-daemon threads hang the JVM
|
|
36
|
+
client.saveObjects(indexName = indexName, objects = records)
|
|
37
|
+
println("ALGOLIA_WIZARD_RECORD_COUNT=${records.size}")
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```kotlin
|
|
44
|
+
// objects is List<JsonObject> — not arbitrary data classes; each needs an objectID
|
|
45
|
+
suspend fun SearchClient.saveObjects(
|
|
46
|
+
indexName: String, objects: List<JsonObject>, waitForTasks: Boolean = false,
|
|
47
|
+
batchSize: Int = 1000, requestOptions: RequestOptions? = null,
|
|
48
|
+
): List<BatchResponse>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
One `BatchResponse` (`taskID`, `objectIDs`) per batch of 1,000, not per record.
|
|
52
|
+
|
|
53
|
+
Read records from a JSON file (no serialization plugin needed for `JsonObject`):
|
|
54
|
+
|
|
55
|
+
```kotlin
|
|
56
|
+
val records = Json.parseToJsonElement(File("records.json").readText()).jsonArray.map { it.jsonObject }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
After a successful ingest print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` (n = records
|
|
60
|
+
read, not the returned list size) as the last stdout line.
|
|
@@ -0,0 +1,68 @@
|
|
|
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.
|