mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-25 21:08:59 +02:00
92 lines
1.9 KiB
HTML
92 lines
1.9 KiB
HTML
<!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/flexsearch@0.8.1/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> |