-
-
Notifications
You must be signed in to change notification settings - Fork 499
/
Copy pathindex.js
70 lines (59 loc) · 1.71 KB
/
index.js
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
import { Document, Charset } from "flexsearch";
import { promises as fs } from "fs";
const dirname = import.meta.dirname;
import Sqlite from "flexsearch/db/sqlite";
// import Postgres from "flexsearch/db/postgres";
// import MongoDB from "flexsearch/db/mongodb";
// import Redis from "flexsearch/db/redis";
// import Clickhouse from "flexsearch/db/clickhouse";
(async function(){
// loading test data
const data = JSON.parse(await fs.readFile(dirname + "/data.json"));
// create DB instance with namespace
const db = new Sqlite("my-store");
// create the document index
const document = new Document({
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward",
encoder: Charset.LatinBalance
},{
field: "originalTitle",
tokenize: "forward",
encoder: Charset.LatinBalance
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
await document.mount(db);
// await document.destroy();
// await document.mount(db);
// add test data
for(let i = 0; i < data.length; i++){
document.add(data[i]);
}
// transfer changes in bulk
await document.commit();
// perform a query
const result = await document.search({
query: "karmen",
tag: {
"startYear": "1894",
"genres": [
"Documentary",
"Short"
]
},
suggest: true,
enrich: true,
merge: true
});
console.log(result);
}());