-
-
Notifications
You must be signed in to change notification settings - Fork 499
/
Copy pathindex.html
92 lines (81 loc) · 1.94 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-module-basic</title>
</head>
<body style="white-space: pre">
<script type="module">
//import { Index } from "https://cdn.jsdelivr.net/gh/nextapps-de/[email protected]/dist/flexsearch.light.module.min.js";
import Index from "../../../src/index.js";
import Resolver from "../../../src/resolver.js";
import Encoder from "../../../src/encoder.js";
// create a simple index which can store id-content-pairs
const index = new Index({
// use forward when you want to match partials
// e.g. match "flexsearch" when query "flex"
tokenize: "forward"
});
// some test data
const data = [
'rats',
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop dogs cute',
'cats abcd efgh ijkl mnop cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
'cats cute'
];
// add data to the index
data.forEach((item, id) => {
index.add(id, item);
});
// console.log(index.encoder)
// console.log(index.encoder.encode("cute"))
// let test = Encoder({}, {}, {});
// console.log(test)
new Resolver({
index: index,
query: "dog"
})
.boost(2)
.or({
index: index,
query: "cut",
suggest: true,
limit: 10,
offset: 0,
resolve: true
})
// .not({
// index: index,
// query: "mnop",
//
// })
// .xor({
// index: index,
// query: "rats",
// limit: 10,
// offset: 0,
// enrich: true,
// resolve: true
// })
.forEach(i => {
const result = data[i];
log(result);
});
// // perform query
// index.search("cute dog", { suggest: true }).forEach(i => {
// const result = data[i];
// log(result);
// });
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>