-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypesense-local.ts
72 lines (61 loc) · 1.99 KB
/
typesense-local.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { existsSync } from "fs";
import Typesense from "typesense";
const client = new Typesense.Client({
nodes: [
{
host: "localhost",
port: 8108,
protocol: "http",
},
],
apiKey: "xyz",
connectionTimeoutSeconds: 2,
});
if (existsSync("./.iiif/build/meta/typesense/manifests.schema.json")) {
const schema = await Bun.file(
"./.iiif/build/meta/typesense/manifests.schema.json",
).json();
const data = await Bun.file(
"./.iiif/build/meta/typesense/manifests.jsonl",
).text();
const jsonDocuments = data.split("\n").map((line) => JSON.parse(line));
const collections = await client.collections().retrieve();
const manifestsCollection = collections.find(
(collection) => collection.name === "manifests",
);
if (manifestsCollection) {
await client.collections("manifests").delete();
}
await client.collections().create(schema);
await client
.collections("manifests")
.documents()
.import(jsonDocuments, { action: "upsert" });
console.log(
`Imported ${jsonDocuments.length} documents into the 'manifests' collection`,
);
}
if (existsSync("./.iiif/build/meta/typesense/manifest-plaintext.schema.json")) {
const schema = await Bun.file(
"./.iiif/build/meta/typesense/manifest-plaintext.schema.json",
).json();
const data = await Bun.file(
"./.iiif/build/meta/typesense/manifest-plaintext.jsonl",
).text();
const jsonDocuments = data.split("\n").map((line) => JSON.parse(line));
const collections = await client.collections().retrieve();
const manifestsCollection = collections.find(
(collection) => collection.name === "manifest-plaintext",
);
if (manifestsCollection) {
await client.collections("manifest-plaintext").delete();
}
await client.collections().create(schema);
await client
.collections("manifest-plaintext")
.documents()
.import(jsonDocuments, { action: "upsert" });
console.log(
`Imported ${jsonDocuments.length} documents into the 'manifest-plaintext' collection`,
);
}