-
-
Notifications
You must be signed in to change notification settings - Fork 520
Expand file tree
/
Copy pathindex.html
More file actions
100 lines (93 loc) · 2.14 KB
/
index.html
File metadata and controls
100 lines (93 loc) · 2.14 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-module-document-resolver</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Document, Charset, Resolver } from "https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@0.8.2/dist/flexsearch.compact.module.min.js";
// some test data
const data = [{
"tconst": "tt0000001",
"titleType": "short",
"primaryTitle": "Carmencita",
"originalTitle": "Carmencita",
"isAdult": 0,
"startYear": "1894",
"endYear": "",
"runtimeMinutes": "1",
"genres": [
"Documentary",
"Short"
]
},{
"tconst": "tt0000002",
"titleType": "short",
"primaryTitle": "Le clown et ses chiens",
"originalTitle": "Le clown et ses chiens",
"isAdult": 0,
"startYear": "1892",
"endYear": "",
"runtimeMinutes": "5",
"genres": [
"Animation",
"Short"
]
}];
// create the document index
const index = 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"
}]
}
});
// add test data
for(let i = 0; i < data.length; i++){
index.add(data[i]);
}
// perform a complex query + enrich results
let result = new Resolver({
index: index,
query: "karmen",
pluck: "primaryTitle"
}).or({
query: "clown",
pluck: "primaryTitle"
}).and({
query: "not found",
field: "originalTitle",
suggest: true
}).not({
query: "clown",
pluck: "primaryTitle"
}).resolve({
enrich: true
});
// display results
console.log(result);
log(JSON.stringify(result, null, 2));
log("\n-------------------------------------\n");
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>