1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-26 23:35:45 +02:00

update examples

This commit is contained in:
Thomas Wilkerling
2025-03-14 18:27:35 +01:00
parent bc54664434
commit 114303831c
75 changed files with 1363 additions and 71 deletions

View File

@@ -8,7 +8,7 @@ npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
- Persistent indexes support for: `IndexedDB` (Browser), `Redis`, `SQLite`, `Postgres`, `MongoDB`, `Clickhouse`
- Enhanced language customization via the new `Encoder` class
- Query performance achieve results up to 7 times faster compared to the previous generation v0.7.x
- Query performance achieve results up to 4.5 times faster compared to the previous generation v0.7.x by also improving the quality of results
- Enhanced support for larger indexes or larger result sets
- Improved offset and limit processing achieve up to 100 times faster traversal performance through large datasets
- Support for larger In-Memory index with extended key size (the defaults maximum keystore limit is: 2^24)
@@ -70,40 +70,57 @@ All search capabilities are available on persistent indexes like:
All persistent variants are optimized for larger sized indexes under heavy workload. Almost every task will be streamlined to run in batch/parallel, getting the most out of the selected database engine. Whereas the InMemory index can't share their data between different nodes when running in a cluster, every persistent storage can handle this by default.
### Example Node.js
### Examples Node.js
- [nodejs-commonjs](example/nodejs-commonjs):
- [basic](example/nodejs-commonjs/basic)
- [basic-suggestion](example/nodejs-commonjs/basic-suggestion)
- [basic-persistent](example/nodejs-commonjs/basic-persistent)
- [basic-resolver](example/nodejs-commonjs/basic-resolver)
- [basic-worker](example/nodejs-commonjs/basic-worker)
- [basic-worker-extern-config](example/nodejs-commonjs/basic-worker-extern-config)
- [document](example/nodejs-commonjs/document)
- [document-persistent](example/nodejs-commonjs/document-persistent)
- [document-worker](example/nodejs-commonjs/document-worker)
- [document-worker-extern-config](example/nodejs-commonjs/document-worker-extern-config)
- [language-pack](example/nodejs-commonjs/language-pack)
- [nodejs-esm](example/nodejs-esm):
- [basic](example/nodejs-esm/basic)
- [basic-suggestion](example/nodejs-esm/basic-suggestion)
- [basic-persistent](example/nodejs-esm/basic-persistent)
- [basic-resolver](example/nodejs-esm/basic-resolver)
- [basic-worker](example/nodejs-esm/basic-worker)
- [basic-worker-extern-config](example/nodejs-esm/basic-worker-extern-config)
- [document](example/nodejs-esm/document)
- [document-persistent](example/nodejs-esm/document-persistent)
- [document-worker](example/nodejs-esm/document-worker)
- [document-worker-extern-config](example/nodejs-esm/document-worker-extern-config)
- [language-packs](example/nodejs-esm/language-packs)
- [language-pack](example/nodejs-esm/language-pack)
### Example Browser
### Examples Browser
- [browser-legacy](example/browser-legacy):
- [basic](example/browser-legacy/basic)
- [basic-persistent](example/browser-legacy/basic-persistent)
- [basic-suggestion](example/browser-legacy/basic-suggestion)
- [basic-persistent](example/browser-legacy/basic-persistent)
- [basic-resolver](example/browser-legacy/basic-resolver)
- [basic-worker](example/browser-legacy/basic-worker)
- [document](example/browser-legacy/document)
- [document-persistent](example/browser-legacy/document-persistent)
- [document-worker](example/browser-legacy/document-worker)
- [language-pack](example/browser-legacy/language-pack)
- [browser-module](example/browser-module):
- [basic](example/browser-module/basic)
- [basic-persistent](example/browser-module/basic-persistent)
- [basic-suggestion](example/browser-module/basic-suggestion)
- [basic-persistent](example/browser-module/basic-persistent)
- [basic-resolver](example/browser-module/basic-resolver)
- [basic-worker](example/browser-module/basic-worker)
- [basic-worker-extern-config](example/browser-module/basic-worker-extern-config)
- [document](example/browser-module/document)
- [document-persistent](example/browser-module/document-persistent)
- [document-worker](example/browser-module/document-worker)
- [document-worker-extern-config](example/browser-module/document-worker-extern-config)
- [language-pack](example/browser-module/language-pack)
```js
import FlexSearchIndex from "./index.js";
@@ -2188,9 +2205,6 @@ A formula to determine a well balanced value for the `resolution` is: $2*floor(\
## Migration
<!--
- Using the `async` variants like `.searchAsync` is now deprecated, asynchronous responses will always return from Worker-Index and from Persistent-Index, everything else will return a non-promised result. Having both types of methods looks like the developers can choose between them, but they can't.
-->
- The index option property "minlength" has moved to the Encoder Class
- The index option flag "optimize" was removed
- The index option flag "lang" was replaced by the Encoder Class `.assign()`
@@ -2204,4 +2218,13 @@ A formula to determine a well balanced value for the `resolution` is: $2*floor(\
- The static methods `FlexSearch.registerCharset()` and `FlexSearch.registerLanguage()` was removed, those collections are now exported to `FlexSearch.Charset` which can be accessed as module `import { Charset } from "flexsearch"` and language packs are now applied by `encoder.assign()`
- Instead of e.g. "latin:simple" the Charset collection is exported as a module and has to be imported by e.g. `import LatinSimple from "./charset.js"` and then assigned to an existing Encoder by `encoder.assign(LatinSimple)` or by creation `encoder = new Encoder(LatinSimple)`
- You can import language packs by `dist/module/lang/*` when using ESM and by `const EnglishPreset = require("flexsearch/lang/en");` when using CommonJS (Node.js)
- The method `index.append()` is now deprecated and will be removed in the near future, because it isn't consistent and leads into unexpected behavior when not used properly. You should only use `index.add()` which also supports an Array of contents.
- The method `index.append()` is now deprecated and will be removed in the near future, because it isn't consistent and leads into unexpected behavior when not used properly. You should only use `index.add()` to push contents to the index.
- Using the `async` variants like `.searchAsync` is now deprecated (but still works), asynchronous responses will always return from Worker-Index and from Persistent-Index, everything else will return a non-promised result. Having both types of methods looks like the developers can choose between them, but they can't.
## Not finished yet
Unfortunately, not everything could be finished and needs to be done in the upcoming version.
- The `Resolver` does not support Document-Indexes, there is still some work to do.
- Config serialization for persistent indexes (store configuration, check migrations, import and restore field configurations)
- Tooling for persistent indexes (list all tables, remove tables)

View File

@@ -3,10 +3,10 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic-persistent</title>
<title>Example: browser-legacy-basic-persistent</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.min.js"></script>
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.min.js"></script>
<script>
(async function(){

View File

@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-legacy-basic-resolver</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.min.js"></script>
<script>
// create a simple index which can store id-content-pairs
const index = new FlexSearch.Index({
tokenize: "forward"
});
// some test data
const data = [
'cats abcd efgh ijkl dogs pigs rats cute',
'cats abcd efgh ijkl dogs pigs cute',
'cats abcd efgh ijkl dogs 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);
});
// perform query
const result = new FlexSearch.Resolver({
index: index,
query: "black"
})
.or({
index: index,
query: "cute"
})
.and([{
index: index,
query: "dog"
},{
index: index,
query: "cat"
}])
.not({
index: index,
query: "rat"
})
.resolve();
// display results
result.forEach(i => {
console.log(data[i]);
log(data[i]);
});
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>

View File

@@ -3,10 +3,10 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic-suggestion</title>
<title>Example: browser-legacy-basic-suggestion</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.light.min.js"></script>
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.light.min.js"></script>
<script>
// create a simple index which can store id-content-pairs
@@ -18,7 +18,7 @@
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl mnop cute',
'cats abcd efgh ijkl dogs cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
@@ -32,7 +32,7 @@
// perform query
const result = index.search({
query: "black or cute or yellow cat",
query: "black dog or cute cat",
suggest: true
});

View File

@@ -3,10 +3,10 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic-worker</title>
<title>Example: browser-legacy-basic-worker</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.min.js"></script>
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.min.js"></script>
<script>
(async function(){

View File

@@ -3,14 +3,16 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic</title>
<title>Example: browser-legacy-basic</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.light.min.js"></script>
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.light.min.js"></script>
<script>
// create a simple index which can store id-content-pairs
const index = new FlexSearch.Index({
// use forward when you want to match partials
// e.g. match "flexsearch" when query "flex"
tokenize: "forward"
});

View File

@@ -3,10 +3,10 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-document-persistent</title>
<title>Example: browser-legacy-document-persistent</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.min.js"></script>
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.min.js"></script>
<script>
(async function(){

View File

@@ -3,10 +3,10 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-document-worker</title>
<title>Example: browser-legacy-document-worker</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.min.js"></script>
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.min.js"></script>
<script>
(async function(){

View File

@@ -3,10 +3,10 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-document</title>
<title>Example: browser-legacy-document</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.compact.min.js"></script>
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.compact.min.js"></script>
<script>
// some test data

View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-legacy-language-packs</title>
</head>
<body style="white-space: pre">
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.compact.min.js"></script>
<!-- Load language pack after loading the library -->
<script src="https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/lang/en.min.js"></script>
<script>
const encoder = new FlexSearch.Encoder(
FlexSearch.Charset.LatinSimple,
FlexSearch.Language.en
);
// create a simple index which can store id-content-pairs
const index = new FlexSearch.Index({
tokenize: "forward",
encoder: encoder
});
// some test data
const data = [
'She doesnt get up at six oclock.',
'It\'s been raining for five hours now.'
];
// add data to the index
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
let result = index.search("she does not at clock");
// display results
result.forEach(i => {
console.log(data[i]);
log(data[i]);
log("\n-------------------------------------\n");
});
// perform query
result = index.search("it is raining now");
// display results
result.forEach(i => {
console.log(data[i]);
log(data[i]);
});
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>

View File

@@ -3,12 +3,12 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic-persistent</title>
<title>Example: browser-module-basic-persistent</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Index, IndexedDB } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.module.min.js";
import { Index, IndexedDB } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.module.min.js";
// create DB instance with namespace
const db = new IndexedDB("my-store");
@@ -34,6 +34,7 @@
'cats cute'
];
// add data to the index
data.forEach((item, id) => {
index.add(id, item);
});
@@ -41,14 +42,14 @@
// transfer changes (bulk)
await index.commit();
// perform query
const result = await index.search({
query: "cute cat",
suggest: true
});
console.log(result);
result.forEach(i => {
console.log(data[i]);
log(data[i]);
});

View File

@@ -0,0 +1,69 @@
<!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-resolver</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Index, Resolver } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.module.min.js";
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward"
});
// some test data
const data = [
'cats abcd efgh ijkl dogs pigs rats cute',
'cats abcd efgh ijkl dogs pigs cute',
'cats abcd efgh ijkl dogs 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);
});
// perform query
const result = new Resolver({
index: index,
query: "black"
})
.or({
index: index,
query: "cute"
})
.and([{
index: index,
query: "dog"
},{
index: index,
query: "cat"
}])
.not({
index: index,
query: "rat"
})
.resolve();
// display results
result.forEach(i => {
console.log(data[i]);
log(data[i]);
});
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>

View File

@@ -3,12 +3,12 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic-suggestion</title>
<title>Example: browser-module-basic-suggestion</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Index } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.light.module.min.js";
import { Index } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.light.module.min.js";
// create a simple index which can store id-content-pairs
const index = new Index({
@@ -19,20 +19,21 @@
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl mnop cute',
'cats abcd efgh ijkl dogs 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);
});
// perform query
const result = index.search({
query: "black or cute or yellow cat",
query: "black dog or cute cat",
suggest: true
});

View File

@@ -0,0 +1,10 @@
import { Encoder } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.module.min.js";
export default {
tokenize: "forward",
encoder: new Encoder({
normalize: function(str){
return str.toLowerCase();
}
})
};

View File

@@ -3,16 +3,18 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic-worker-extern-config</title>
<title>Example: browser-module-basic-worker-extern-config</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Index } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.module.min.js";
// you can't load from CDN because of Same-Origin-Policy
import { Worker as WorkerIndex } from "../../../dist/flexsearch.bundle.module.min.js";
const dirname = import.meta.url.replace("/index.html", "");
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward"
const index = await new WorkerIndex({
config: dirname + "/config.js"
});
// some test data
@@ -26,14 +28,14 @@
'cats cute'
];
// add data to the index
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
const result = await index.search({
query: "cute cat",
suggest: true
query: "cute cat"
});
// display results

View File

@@ -3,12 +3,13 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic-worker</title>
<title>Example: browser-module-basic-worker</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Worker as WorkerIndex } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.module.min.js";
// you can't load from CDN because of Same-Origin-Policy
import { Worker as WorkerIndex } from "../../../dist/flexsearch.bundle.module.min.js";
// create a simple index which can store id-content-pairs
const index = new WorkerIndex({
@@ -26,6 +27,7 @@
'cats cute'
];
// add test data
data.forEach((item, id) => {
index.add(id, item);
});

View File

@@ -3,15 +3,17 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-basic</title>
<title>Example: browser-module-basic</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Index } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.light.module.min.js";
import { Index } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.light.module.min.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"
});
@@ -26,21 +28,13 @@
'cats cute'
];
// add data to the index
data.forEach((item, id) => {
index.add(id, item);
});
index.search("cute cats").forEach(i => {
const result = data[i];
log(result);
});
log("\n----------------------\n");
index.search({
query: "black or cute or yellow cats",
suggest: true
}).forEach(i => {
// perform query
index.search("cute cat").forEach(i => {
const result = data[i];
log(result);
});

View File

@@ -3,12 +3,12 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-document-persistent</title>
<title>Example: browser-module-document-persistent</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Document, Charset, IndexedDB } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.module.min.js";
import { Document, Charset, IndexedDB } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.module.min.js";
// some test data
const data = [{

View File

@@ -1,5 +1,5 @@
import { Encoder, Charset } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.module.min.js";
import EnglishPreset from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/module/lang/en.js";
import { Encoder, Charset } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.module.min.js";
import EnglishPreset from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/module/lang/en.js";
export default {
tokenize: "forward",

View File

@@ -1,5 +1,5 @@
import { Encoder, Charset } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.module.min.js";
import EnglishPreset from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/module/lang/en.js";
import { Encoder, Charset } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.bundle.module.min.js";
import EnglishPreset from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/module/lang/en.js";
export default {
tokenize: "forward",

View File

@@ -3,12 +3,13 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-document-worker-extern-config</title>
<title>Example: browser-module-document-worker-extern-config</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Document } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.module.min.js";
// you can't load from CDN because of Same-Origin-Policy
import { Document } from "../../../dist/flexsearch.bundle.module.min.js";
const dirname = import.meta.url.replace("/index.html", "");
// some test data

View File

@@ -3,12 +3,13 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-document-worker</title>
<title>Example: browser-module-document-worker</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Document } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.bundle.module.min.js";
// you can't load from CDN because of Same-Origin-Policy
import { Document } from "../../../dist/flexsearch.bundle.module.min.js";
// some test data
const data = [{

View File

@@ -3,12 +3,12 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-document</title>
<title>Example: browser-module-document</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Document, Charset } from "https://rawcdn.githack.com/nextapps-de/flexsearch/v0.8-preview/dist/flexsearch.compact.module.min.js";
import { Document, Charset } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.compact.module.min.js";
// some test data
const data = [{
@@ -76,7 +76,8 @@
"Short"
]
},
enrich: true
enrich: true,
highlight: "<b>$1</b>"
});
// display results

View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-module-language-packs</title>
</head>
<body style="white-space: pre">
<script type="module">
import { Index, Encoder, Charset } from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/flexsearch.compact.module.min.js";
import EnglishPreset from "https://rawcdn.githack.com/nextapps-de/flexsearch/aff94f2b1d830e21463b237070f7e6f7eb556b82/dist/module/lang/en.js";
const encoder = new Encoder(
Charset.LatinSimple,
EnglishPreset
);
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward",
encoder: encoder
});
// some test data
const data = [
'She doesnt get up at six oclock.',
'It\'s been raining for five hours now.'
];
// add data to the index
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
let result = index.search("she does not at clock");
// display results
result.forEach(i => {
console.log(data[i]);
log(data[i]);
log("\n-------------------------------------\n");
});
// perform query
result = index.search("it is raining now");
// display results
result.forEach(i => {
console.log(data[i]);
log(data[i]);
});
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>

View File

@@ -0,0 +1,17 @@
const { Encoder, Charset } = require("flexsearch");
const EnglishPreset = require("flexsearch/lang/en");
module.exports = {
tokenize: "forward",
encoder: new Encoder(
Charset.LatinBalance,
EnglishPreset,
{
normalize: function(str){
return str.toLowerCase();
},
filter: false,
minlength: 3
}
)
};

View File

@@ -0,0 +1,17 @@
const { Encoder, Charset } = require("flexsearch");
const EnglishPreset = require("flexsearch/lang/en");
module.exports = {
tokenize: "forward",
encoder: new Encoder(
Charset.LatinBalance,
EnglishPreset,
{
normalize: function(str){
return str.toLowerCase();
},
filter: false,
minlength: 3
}
)
};

View File

@@ -0,0 +1,141 @@
[
{
"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"
]
},
{
"tconst": "tt0000003",
"titleType": "short",
"primaryTitle": "Pauvre Pierrot",
"originalTitle": "Pauvre Pierrot",
"isAdult": 0,
"startYear": "1892",
"endYear": "",
"runtimeMinutes": "4",
"genres": [
"Animation",
"Comedy",
"Romance"
]
},
{
"tconst": "tt0000004",
"titleType": "short",
"primaryTitle": "Un bon bock",
"originalTitle": "Un bon bock",
"isAdult": 0,
"startYear": "1892",
"endYear": "",
"runtimeMinutes": "12",
"genres": [
"Animation",
"Short"
]
},
{
"tconst": "tt0000005",
"titleType": "short",
"primaryTitle": "Blacksmith Scene",
"originalTitle": "Blacksmith Scene",
"isAdult": 0,
"startYear": "1893",
"endYear": "",
"runtimeMinutes": "1",
"genres": [
"Comedy",
"Short"
]
},
{
"tconst": "tt0000006",
"titleType": "short",
"primaryTitle": "Chinese Opium Den",
"originalTitle": "Chinese Opium Den",
"isAdult": 0,
"startYear": "1894",
"endYear": "",
"runtimeMinutes": "1",
"genres": [
"Short"
]
},
{
"tconst": "tt0000007",
"titleType": "short",
"primaryTitle": "Corbett and Courtney Before the Kinetograph",
"originalTitle": "Corbett and Courtney Before the Kinetograph",
"isAdult": 0,
"startYear": "1894",
"endYear": "",
"runtimeMinutes": "1",
"genres": [
"Short",
"Sport"
]
},
{
"tconst": "tt0000008",
"titleType": "short",
"primaryTitle": "Edison Kinetoscopic Record of a Sneeze",
"originalTitle": "Edison Kinetoscopic Record of a Sneeze",
"isAdult": 0,
"startYear": "1894",
"endYear": "",
"runtimeMinutes": "1",
"genres": [
"Documentary",
"Short"
]
},
{
"tconst": "tt0000009",
"titleType": "movie",
"primaryTitle": "Miss Jerry",
"originalTitle": "Miss Jerry",
"isAdult": 0,
"startYear": "1894",
"endYear": "",
"runtimeMinutes": "45",
"genres": [
"Romance"
]
},
{
"tconst": "tt0000010",
"titleType": "short",
"primaryTitle": "Leaving the Factory",
"originalTitle": "La sortie de l'usine Lumière à Lyon",
"isAdult": 0,
"startYear": "1895",
"endYear": "",
"runtimeMinutes": "1",
"genres": [
"Documentary",
"Short"
]
}
]

View File

@@ -0,0 +1,68 @@
const { Document } = 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 = await new Document({
worker: true,
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
config: __dirname + "/config.primaryTitle.js"
},{
field: "originalTitle",
config: __dirname + "/config.primaryTitle.js"
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
//await document.mount(db);
// await document.destroy();
// await document.mount(db);
// add test data
for(let i = 0; i < data.length; i++){
await document.add(data[i]);
}
// transfer changes (bulk)
//await document.commit();
console.log(document)
// 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);
}());

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-worker-persistent",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview",
"sqlite3": "^5.1.7"
}
}

View File

@@ -0,0 +1,9 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
npm install sqlite3@5.1.7
```
```bash
node index.js
```

View File

@@ -0,0 +1,52 @@
const { Index } = 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");
(async function(){
// create DB instance with namespace
const db = new Sqlite("my-store");
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward"
});
// mount database to the index
await index.mount(db);
// await index.destroy();
// await index.mount(db);
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst 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);
});
// transfer changes (bulk)
await index.commit();
// perform query
const result = await index.search({
query: "cute cat"
});
// display results
result.forEach(i => {
console.log(data[i]);
});
}());

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-commonjs-document",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview",
"sqlite3": "^5.1.7"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,33 @@
const { Index } = require("flexsearch");
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward"
});
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl dogs 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);
});
// perform query
const result = index.search({
query: "black dog or cute cat",
suggest: true
});
// display results
result.forEach(i => {
console.log(data[i]);
});

View File

@@ -0,0 +1,6 @@
{
"name": "nodejs-commonjs-document",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,33 @@
const { Index } = require("flexsearch");
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward"
});
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl dogs 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);
});
// perform query
const result = index.search({
query: "black dog or cute cat",
suggest: true
});
// display results
result.forEach(i => {
console.log(data[i]);
});

View File

@@ -0,0 +1,6 @@
{
"name": "nodejs-commonjs-document",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,10 @@
import { Encoder } from "flexsearch/esm";
export default {
tokenize: "forward",
encoder: new Encoder({
normalize: function(str){
return str.toLowerCase();
}
})
};

View File

@@ -0,0 +1,38 @@
const { Worker: WorkerIndex } = require("flexsearch");
(async function(){
// create a simple index which can store id-content-pairs
// and await (!) for the worker response
const index = await new WorkerIndex({
tokenize: "forward",
config: __dirname + "/config.js"
});
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl mnop cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
'cats cute'
];
// add test data
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
const result = await index.search({
query: "cute cat",
});
// display results
result.forEach(i => {
console.log(data[i]);
});
}());

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-esm-document-worker",
"type": "module",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,36 @@
const { Worker: WorkerIndex } = require("flexsearch");
(async function(){
// create a simple index which can store id-content-pairs
const index = await new WorkerIndex({
tokenize: "forward"
});
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl mnop cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
'cats cute'
];
// add test data
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
const result = await index.search({
query: "cute cat",
});
// display results
result.forEach(i => {
console.log(data[i]);
});
}());

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-esm-document-worker",
"type": "module",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,32 @@
const { Index } = require("flexsearch");
// 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 = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst 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);
});
// perform query
const result = index.search("cute cat");
// display results
result.forEach(i => {
console.log(data[i]);
});

View File

@@ -0,0 +1,6 @@
{
"name": "nodejs-commonjs-document",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -1,7 +1,9 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
npm install sqlite3@5.1.7
```
```bash
node index.js
```

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,41 @@
const { Index, Encoder, Charset } = require("flexsearch");
const EnglishPreset = require("flexsearch/lang/en");
const encoder = new Encoder(
Charset.LatinSimple,
EnglishPreset
);
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward",
encoder: encoder
});
// some test data
const data = [
'She doesnt get up at six oclock.',
'It\'s been raining for five hours now.'
];
// add data to the index
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
let result = index.search("she does not at clock");
// display results
result.forEach(i => {
console.log(data[i]);
console.log("-------------------------------------");
});
// perform query
result = index.search("it is raining");
// display results
result.forEach(i => {
console.log(data[i]);
});

View File

@@ -0,0 +1,6 @@
{
"name": "nodejs-commonjs-document",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,9 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
npm install sqlite3@5.1.7
```
```bash
node index.js
```

View File

@@ -0,0 +1,49 @@
import { Index } from "flexsearch/esm";
import Sqlite from "flexsearch/db/sqlite";
// import Postgres from "flexsearch/db/postgres";
// import MongoDB from "flexsearch/db/mongodb";
// import Redis from "flexsearch/db/redis";
// import Clickhouse from "flexsearch/db/clickhouse";
(async function(){
// create DB instance with namespace
const db = new Sqlite("my-store");
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward"
});
// mount database to the index
await index.mount(db);
// await index.destroy();
// await index.mount(db);
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst 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);
});
// transfer changes (bulk)
await index.commit();
// perform query
const result = await index.search({
query: "cute cat",
suggest: true
});
console.log(result);
}());

View File

@@ -0,0 +1,8 @@
{
"name": "nodejs-commonjs-document",
"type": "module",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview",
"sqlite3": "^5.1.7"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,33 @@
import { Index } from "flexsearch/esm";
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward"
});
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl dogs 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);
});
// perform query
const result = index.search({
query: "black dog or cute cat",
suggest: true
});
// display results
result.forEach(i => {
console.log(data[i]);
});

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-commonjs-document",
"type": "module",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,33 @@
import { Index } from "flexsearch/esm";
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward"
});
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl dogs 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);
});
// perform query
const result = index.search({
query: "black dog or cute cat",
suggest: true
});
// display results
result.forEach(i => {
console.log(data[i]);
});

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-commonjs-document",
"type": "module",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,10 @@
import { Encoder } from "flexsearch/esm";
export default {
tokenize: "forward",
encoder: new Encoder({
normalize: function(str){
return str.toLowerCase();
}
})
};

View File

@@ -0,0 +1,39 @@
import { Worker as WorkerIndex } from "flexsearch/esm";
const dirname = import.meta.dirname;
(async function(){
// create a simple index which can store id-content-pairs
// and await (!) for the worker response
const index = await new WorkerIndex({
tokenize: "forward",
config: dirname + "/config.js"
});
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl mnop cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
'cats cute'
];
// add test data
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
const result = await index.search({
query: "cute cat",
});
// display results
result.forEach(i => {
console.log(data[i]);
});
}());

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-esm-document-worker",
"type": "module",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,36 @@
import { Worker as WorkerIndex } from "flexsearch/esm";
(async function(){
// create a simple index which can store id-content-pairs
const index = await new WorkerIndex({
tokenize: "forward"
});
// some test data
const data = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst cute',
'cats abcd efgh ijkl mnop cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
'cats cute'
];
// add test data
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
const result = await index.search({
query: "cute cat",
});
// display results
result.forEach(i => {
console.log(data[i]);
});
}());

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-esm-document-worker",
"type": "module",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,32 @@
import { Index } from "flexsearch/esm";
// 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 = [
'cats abcd efgh ijkl mnop qrst uvwx cute',
'cats abcd efgh ijkl mnop qrst 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);
});
// perform query
const result = index.search("cute cat");
// display results
result.forEach(i => {
console.log(data[i]);
});

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-commonjs-document",
"type": "module",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}

View File

@@ -1,7 +1,9 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
npm install sqlite3@5.1.7
```
```bash
node index.js
```

View File

@@ -1,7 +1,9 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
npm install sqlite3@5.1.7
```
```bash
node index.js
```

View File

@@ -0,0 +1,7 @@
```bash
npm install git+https://github.com/nextapps-de/flexsearch/tree/v0.8-preview
```
```bash
node index.js
```

View File

@@ -0,0 +1,41 @@
import { Index, Encoder, Charset } from "flexsearch/esm";
import EnglishPreset from "flexsearch/esm/lang/en";
const encoder = new Encoder(
Charset.LatinSimple,
EnglishPreset
);
// create a simple index which can store id-content-pairs
const index = new Index({
tokenize: "forward",
encoder: encoder
});
// some test data
const data = [
'She doesnt get up at six oclock.',
'It\'s been raining for five hours now.'
];
// add data to the index
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
let result = index.search("she does not at clock");
// display results
result.forEach(i => {
console.log(data[i]);
console.log("-------------------------------------");
});
// perform query
result = index.search("it is raining");
// display results
result.forEach(i => {
console.log(data[i]);
});

View File

@@ -0,0 +1,6 @@
{
"name": "nodejs-commonjs-document",
"dependencies": {
"flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
}
}