mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-08-20 21:01:47 +02:00
update examples
This commit is contained in:
@@ -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]);
|
||||
});
|
||||
|
||||
|
69
example/browser-module/basic-resolver/index.html
Normal file
69
example/browser-module/basic-resolver/index.html
Normal 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>
|
@@ -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
|
||||
});
|
||||
|
||||
|
10
example/browser-module/basic-worker-extern-config/config.js
Normal file
10
example/browser-module/basic-worker-extern-config/config.js
Normal 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();
|
||||
}
|
||||
})
|
||||
};
|
@@ -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
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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);
|
||||
});
|
||||
|
@@ -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 = [{
|
||||
|
@@ -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",
|
||||
|
@@ -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",
|
||||
|
@@ -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
|
||||
|
@@ -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 = [{
|
||||
|
@@ -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
|
||||
|
62
example/browser-module/language-pack/index.html
Normal file
62
example/browser-module/language-pack/index.html
Normal 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 doesn’t get up at six o’clock.',
|
||||
'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>
|
Reference in New Issue
Block a user