-
-
Notifications
You must be signed in to change notification settings - Fork 499
/
Copy pathindex.html
131 lines (119 loc) · 2.82 KB
/
index.html
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!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-worker-extern-config</title>
</head>
<body style="white-space: pre">
<script type="module">
// you can't load from CDN because of worker Same-Origin-Policy
import { Document } from "../../../dist/flexsearch.bundle.module.min.js";
const dirname = import.meta.url.replace("/index.html", "");
// 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 and await (!) for the instance response
const index = await new Document({
worker: true,
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
config: dirname + "/config.primaryTitle.js"
},{
field: "originalTitle",
config: dirname + "/config.originalTitle.js"
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
// add test data
for(let i = 0; i < data.length; i++){
await index.add(data[i]);
}
// perform a query
const result = await index.search({
query: "karmen",
tag: {
"startYear": "1894",
"genres": [
"Documentary",
"Short"
]
},
enrich: true
});
// display results
console.log(result);
log(JSON.stringify(result, null, 2));
log("\n-------------------------------------\n");
// perform a query + merge results
const merged = await index.search({
query: "karmen",
tag: {
"startYear": "1894",
"genres": [
"Documentary",
"Short"
]
},
enrich: true,
merge: true
});
// display results
console.log(merged);
log(JSON.stringify(merged, null, 2));
log("\n-------------------------------------\n");
// perform a query + get suggestions
const suggestions = await index.search({
query: "karmen or clown or not found",
tag: {
// no data for this category:
"genres": "Movie"
},
suggest: true,
enrich: true,
merge: true
});
// display results
console.log(suggestions);
log(JSON.stringify(suggestions, null, 2));
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>