1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-31 01:30:01 +02:00

update examples

This commit is contained in:
Thomas Wilkerling
2025-03-13 00:07:56 +01:00
parent 11c3377e90
commit 5d3eb14cd8
80 changed files with 2381 additions and 340 deletions

View File

@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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>
(async function(){
// create DB instance with namespace
const db = new FlexSearch.IndexedDB("my-store");
// create a simple index which can store id-content-pairs
const index = new FlexSearch.Index({
tokenize: "forward"
});
// mount database to the index
await index.mount(db);
// await document.destroy();
// await document.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',
'cute cat '
];
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
});
// 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,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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>
// 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 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({
query: "black or cute or yellow cat",
suggest: true
});
// 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,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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>
(async function(){
// create a simple index which can store id-content-pairs
const index = new FlexSearch.Worker({
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'
];
for(let i = 0; i < data.length; i++){
await index.add(i, data[i]);
}
// perform query
const result = await index.search({
query: "cute cat",
suggest: true
});
// 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,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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>
// 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 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]);
log(data[i]);
});
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>

View File

@@ -0,0 +1,143 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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>
(async function(){
// 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 DB instance with namespace
const db = new FlexSearch.IndexedDB("my-store");
// create the document index
const index = new FlexSearch.Document({
// hint: the encoder is shared for both index fields
// because primaryTitle and originalTitle has almost
// equal content, otherwise you should set the encoder
// option to each of the field options separately
encoder: FlexSearch.Charset.LatinBalance,
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward"
},{
field: "originalTitle",
tokenize: "forward"
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
await index.mount(db);
// await document.destroy();
// await document.mount(db);
// add test data
for(let i = 0; i < data.length; i++){
index.add(data[i]);
}
// transfer changes (bulk)
await index.commit();
// 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>

View File

@@ -0,0 +1,135 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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>
(async function(){
// 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 index
const index = new FlexSearch.Document({
// enable worker:
worker: true,
// hint: the encoder is shared for both index fields
// because primaryTitle and originalTitle has almost
// equal content, otherwise you should set the encoder
// option to each of the field options separately
encoder: FlexSearch.Charset.LatinBalance,
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward"
},{
field: "originalTitle",
tokenize: "forward"
}],
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>

View File

@@ -0,0 +1,131 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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>
// 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 index
const index = new FlexSearch.Document({
// hint: the encoder is shared for both index fields
// because primaryTitle and originalTitle has almost
// equal content, otherwise you should set the encoder
// option to each of the field options separately
encoder: FlexSearch.Charset.LatinBalance,
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward"
},{
field: "originalTitle",
tokenize: "forward"
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
// add test data
for(let i = 0; i < data.length; i++){
index.add(data[i]);
}
// perform a query
const result = 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 = 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 = 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>

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-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";
// create DB instance with namespace
const db = new IndexedDB("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'
];
data.forEach((item, id) => {
index.add(id, item);
});
// transfer changes (bulk)
await index.commit();
const result = await index.search({
query: "cute cat",
suggest: true
});
console.log(result);
result.forEach(i => {
log(data[i]);
});
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>

View File

@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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";
// 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 mnop cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
'cats cute'
];
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
const result = index.search({
query: "black or cute or yellow cat",
suggest: true
});
// 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,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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";
// 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 mnop cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
'cats cute'
];
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
const result = await index.search({
query: "cute cat",
suggest: true
});
// 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,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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";
// create a simple index which can store id-content-pairs
const index = 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'
];
data.forEach((item, id) => {
index.add(id, item);
});
// perform query
const result = await index.search({
query: "cute cat",
suggest: true
});
// 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,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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";
// 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 mnop cute',
'cats abcd efgh ijkl cute',
'cats abcd efgh cute',
'cats abcd cute',
'cats cute'
];
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 => {
const result = data[i];
log(result);
});
function log(str){
document.body.appendChild(
document.createTextNode(str + "\n")
);
}
</script>
</body>
</html>

View File

@@ -0,0 +1,140 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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";
// 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 DB instance with namespace
const db = new IndexedDB("my-store");
// create the document index
const index = new Document({
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward",
encoder: Charset.LatinBalance
},{
field: "originalTitle",
tokenize: "forward",
encoder: Charset.LatinBalance
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
await index.mount(db);
// await document.destroy();
// await document.mount(db);
// add test data
for(let i = 0; i < data.length; i++){
index.add(data[i]);
}
// transfer changes (bulk)
await index.commit();
// 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>

View File

@@ -0,0 +1,17 @@
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";
export default {
tokenize: "forward",
encoder: new Encoder(
Charset.LatinBalance,
EnglishPreset,
{
normalize: function(str){
return str.toLowerCase();
},
filter: false,
minlength: 3
}
)
};

View File

@@ -0,0 +1,17 @@
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";
export default {
tokenize: "forward",
encoder: new Encoder(
Charset.LatinBalance,
EnglishPreset,
{
normalize: function(str){
return str.toLowerCase();
},
filter: false,
minlength: 3
}
)
};

View File

@@ -0,0 +1,130 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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";
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>

View File

@@ -0,0 +1,131 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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";
// 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 index
const index = new Document({
worker: true,
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward",
encoder: "LatinBalance"
},{
field: "originalTitle",
tokenize: "forward",
encoder: "LatinBalance"
}],
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>

View File

@@ -0,0 +1,129 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height">
<title>Example: browser-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";
// 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 index
const index = new Document({
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward",
encoder: Charset.LatinBalance
},{
field: "originalTitle",
tokenize: "forward",
encoder: Charset.LatinBalance
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
// add test data
for(let i = 0; i < data.length; i++){
index.add(data[i]);
}
// perform a query
const result = 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 = 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 = 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>

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

@@ -6,7 +6,7 @@ const Sqlite = require("flexsearch/db/sqlite");
// const Clickhouse = require("flexsearch/db/clickhouse");
// loading test data
const data = require(__dirname + "/../data.json");
const data = require(__dirname + "/data.json");
(async function(){
@@ -35,6 +35,7 @@ const data = require(__dirname + "/../data.json");
}
});
// mount database to the index
await document.mount(db);
// await document.destroy();
// await document.mount(db);

View File

@@ -1,5 +1,5 @@
{
"name": "nodejs-persistent",
"name": "nodejs-commonjs-document-persistent",
"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,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,51 @@
const { Document } = require("flexsearch");
// loading test data
const data = require(__dirname + "/data.json");
(async function(){
// create the document and await (!) for the instance response
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"
}]
}
});
// add test data
for(let i = 0; i < data.length; i++){
await document.add(data[i]);
}
// perform a query
const result = await document.search({
query: "karmen",
tag: {
"startYear": "1894",
"genres": [
"Documentary",
"Short"
]
},
suggest: true,
enrich: true,
merge: true
});
console.log(result);
}());

View File

@@ -0,0 +1,6 @@
{
"name": "nodejs-commonjs-document-worker-extern-config",
"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

@@ -1,7 +1,7 @@
const { Document } = require("flexsearch");
// loading test data
const data = require(__dirname + "/../data.json");
const data = require(__dirname + "/data.json");
(async function(){
@@ -14,11 +14,11 @@ const data = require(__dirname + "/../data.json");
index: [{
field: "primaryTitle",
tokenize: "forward",
config: __dirname + "/config.primaryTitle.js"
encoder: "LatinBalance"
},{
field: "originalTitle",
tokenize: "forward",
config: __dirname + "/config.originalTitle.js"
encoder: "LatinBalance"
}],
tag: [{
field: "startYear"
@@ -35,7 +35,7 @@ const data = require(__dirname + "/../data.json");
// perform a query
const result = await document.search({
query: "carmen",
query: "karmen",
tag: {
"startYear": "1894",
"genres": [

View File

@@ -0,0 +1,6 @@
{
"name": "nodejs-commonjs-document-worker",
"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

@@ -1,7 +1,7 @@
const { Document, Charset } = require("flexsearch");
// loading test data
const data = require(__dirname + "/../data.json");
const data = require(__dirname + "/data.json");
// create the document index
const document = new Document({
@@ -11,11 +11,11 @@ const document = new Document({
index: [{
field: "primaryTitle",
tokenize: "forward",
encoder: Charset.LatinSimple
encoder: Charset.LatinBalance
},{
field: "originalTitle",
tokenize: "forward",
encoder: Charset.LatinSimple
encoder: Charset.LatinBalance
}],
tag: [{
field: "startYear"
@@ -32,7 +32,7 @@ for(let i = 0; i < data.length; i++){
// perform a query
const result = document.search({
query: "carmencita",
query: "karmen",
tag: {
"startYear": "1894",
"genres": [

View File

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

View File

@@ -1,3 +0,0 @@
{
"type": "module"
}

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,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

@@ -1,17 +1,18 @@
import { Document, Charset } from "flexsearch/esm";
import { promises as fs } from "fs";
const dirname = import.meta.dirname;
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";
import fs from "fs";
const dirname = import.meta.dirname;
// loading test data
const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
(async function(){
// loading test data
const data = JSON.parse(await fs.readFile(dirname + "/data.json"));
// create DB instance with namespace
const db = new Sqlite("my-store");
@@ -23,11 +24,11 @@ const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
index: [{
field: "primaryTitle",
tokenize: "forward",
encoder: Charset.LatinSimple
encoder: Charset.LatinBalance
},{
field: "originalTitle",
tokenize: "forward",
encoder: Charset.LatinSimple
encoder: Charset.LatinBalance
}],
tag: [{
field: "startYear"
@@ -46,12 +47,12 @@ const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
document.add(data[i]);
}
// transfer changes (bulk)
// transfer changes in bulk
await document.commit();
// perform a query
const result = await document.search({
query: "carmen",
query: "karmen",
tag: {
"startYear": "1894",
"genres": [

View File

@@ -1,5 +1,6 @@
{
"name": "nodejs-worker-persistent",
"name": "nodejs-esm-document-persistent",
"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,17 @@
import { Encoder, Charset } from "flexsearch/esm";
import EnglishPreset from "flexsearch/esm/lang/en";
export default {
tokenize: "forward",
encoder: new Encoder(
Charset.LatinBalance,
EnglishPreset,
{
normalize: function(str){
return str.toLowerCase();
},
filter: false,
minlength: 3
}
)
};

View File

@@ -0,0 +1,17 @@
import { Encoder, Charset } from "flexsearch/esm";
import EnglishPreset from "flexsearch/esm/lang/en";
export default {
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

@@ -1,25 +1,23 @@
import { Document } from "flexsearch/esm";
import fs from "fs";
import { promises as fs } from "fs";
const dirname = import.meta.dirname;
// loading test data
const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
(async function(){
// create the document
const document = new Document({
worker: true,
// loading test data
const data = JSON.parse(await fs.readFile(dirname + "/data.json"));
// create the document and await (!) for the instance response
const document = await new Document({
worker: "true",
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward",
config: dirname + "/config.primaryTitle.js"
},{
field: "originalTitle",
tokenize: "forward",
config: dirname + "/config.originalTitle.js"
}],
tag: [{
@@ -30,6 +28,8 @@ const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
}
});
//console.log(document)
// add test data
for(let i = 0; i < data.length; i++){
await document.add(data[i]);
@@ -37,7 +37,7 @@ const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
// perform a query
const result = await document.search({
query: "carmen",
query: "karmen",
tag: {
"startYear": "1894",
"genres": [

View File

@@ -0,0 +1,7 @@
{
"name": "nodejs-esm-document-worker-extern-config",
"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,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,55 @@
import { Document } from "flexsearch/esm";
import { promises as fs } from "fs";
const dirname = import.meta.dirname;
(async function(){
// loading test data
const data = JSON.parse(await fs.readFile(dirname + "/data.json"));
// create the document and await for the instance response
const document = await new Document({
worker: "true",
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward",
encoder: "LatinBalance"
},{
field: "originalTitle",
tokenize: "forward",
encoder: "LatinBalance"
}],
tag: [{
field: "startYear"
},{
field: "genres"
}]
}
});
// add test data
for(let i = 0; i < data.length; i++){
await document.add(data[i]);
}
// perform a query
const result = await document.search({
query: "karmen",
tag: {
"startYear": "1894",
"genres": [
"Documentary",
"Short"
]
},
suggest: true,
enrich: true,
merge: true
});
console.log(result);
}());

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,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

@@ -3,7 +3,7 @@ import fs from "fs";
const dirname = import.meta.dirname;
// loading test data
const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
const data = JSON.parse(fs.readFileSync(dirname + "/data.json", "utf8"));
// create the document index
const document = new Document({
@@ -13,11 +13,11 @@ const document = new Document({
index: [{
field: "primaryTitle",
tokenize: "forward",
encoder: Charset.LatinSimple
encoder: Charset.LatinBalance
},{
field: "originalTitle",
tokenize: "forward",
encoder: Charset.LatinSimple
encoder: Charset.LatinBalance
}],
tag: [{
field: "startYear"
@@ -34,7 +34,7 @@ for(let i = 0; i < data.length; i++){
// perform a query
const result = document.search({
query: "carmencita",
query: "karmen",
tag: {
"startYear": "1894",
"genres": [

View File

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

View File

@@ -1,11 +0,0 @@
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");
module.exports = {
db: new Sqlite("my-store", {
field: "genres"
})
};

View File

@@ -1,14 +0,0 @@
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");
const { Charset } = require("flexsearch");
module.exports = {
tokenize: "forward",
encoder: Charset.LatinSimple,
db: new Sqlite("my-store", {
field: "originalTitle"
})
};

View File

@@ -1,14 +0,0 @@
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");
const { Charset } = require("flexsearch");
module.exports = {
tokenize: "forward",
encoder: Charset.LatinSimple,
db: new Sqlite("my-store", {
field: "primaryTitle"
})
};

View File

@@ -1,11 +0,0 @@
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");
module.exports = {
db: new Sqlite("my-store", {
field: "startYear"
})
};

View File

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

@@ -1,11 +0,0 @@
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";
export default {
db: new Sqlite("my-store", {
field: "genres"
})
};

View File

@@ -1,14 +0,0 @@
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";
import { Charset } from "flexsearch/esm";
export default {
tokenize: "forward",
encoder: Charset.LatinSimple,
db: new Sqlite("my-store", {
field: "originalTitle"
})
};

View File

@@ -1,14 +0,0 @@
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";
import { Charset } from "flexsearch/esm";
export default {
tokenize: "forward",
encoder: Charset.LatinSimple,
db: new Sqlite("my-store", {
field: "primaryTitle"
})
};

View File

@@ -1,11 +0,0 @@
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";
export default {
db: new Sqlite("my-store", {
field: "startYear"
})
};

View File

@@ -1,72 +0,0 @@
import { Document } from "flexsearch/esm";
import Sqlite from "flexsearch/esm/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";
import fs from "fs";
const dirname = import.meta.dirname;
// loading test data
const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
(async function(){
// create DB instance with namespace
const db = new Sqlite("my-store");
// create the document index
const document = new Document({
worker: true,
document: {
id: "tconst",
store: true,
index: [{
field: "primaryTitle",
tokenize: "forward",
config: dirname + "/config.primaryTitle.js"
},{
field: "originalTitle",
tokenize: "forward",
config: dirname + "/config.originalTitle.js"
}],
tag: [{
field: "startYear",
config: dirname + "/config.startYear.js"
},{
field: "genres",
config: dirname + "/config.genres.js"
}]
}
});
await document.mount(db);
// await document.destroy();
// await document.mount(db);
// add test data
for(let i = 0; i < data.length; i++){
document.add(data[i]);
}
// transfer changes (bulk)
await document.commit();
// 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

@@ -1,6 +0,0 @@
const { Charset } = require("flexsearch");
module.exports = {
tokenize: "forward",
encoder: Charset.LatinSimple
};

View File

@@ -1,6 +0,0 @@
const { Charset } = require("flexsearch");
module.exports = {
tokenize: "forward",
encoder: Charset.LatinSimple
};

View File

@@ -1,6 +0,0 @@
import { Charset } from "flexsearch/esm";
export default {
tokenize: "forward",
encoder: Charset.LatinSimple
};

View File

@@ -1,6 +0,0 @@
import { Charset } from "flexsearch/esm";
export default {
tokenize: "forward",
encoder: Charset.LatinSimple
};