-
-
Notifications
You must be signed in to change notification settings - Fork 500
/
Copy pathindex.js
68 lines (58 loc) · 1.67 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
const { Document, Charset } = require("flexsearch");
const Sqlite = require("flexsearch/db/sqlite");
// const Postgres = require("flexsearch/db/postgres");
// const MongoDB = require("flexsearch/db/mongodb");
// const Redis = require("flexsearch/db/redis");
// const Clickhouse = require("flexsearch/db/clickhouse");
// loading test data
const data = require(__dirname + "/data.json");
(async function(){
// 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.LatinSimple
},{
field: "originalTitle",
tokenize: "forward",
encoder: Charset.LatinSimple
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
// mount database to the index
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 (bulk)
await document.commit();
// perform a query
const result = await document.search({
query: "carmen",
tag: {
"startYear": "1894",
"genres": [
"Documentary",
"Short"
]
},
suggest: true,
enrich: true,
merge: true
});
console.log(result);
}());