diff --git a/README.md b/README.md
index 2ac1142..a374c32 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,22 @@ 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
+### Example Node.js
+
+- [nodejs-document](example/nodejs-document)
+ - [commonjs](example/nodejs-document/commonjs)
+ - [esm](example/nodejs-document/esm)
+- [nodejs-persistent](example/nodejs-persistent)
+ - [commonjs](example/nodejs-persistent/commonjs)
+ - [esm](example/nodejs-persistent/esm)
+- [nodejs-worker](example/nodejs-worker)
+ - [commonjs](example/nodejs-worker/commonjs)
+ - [esm](example/nodejs-worker/esm)
+- [nodejs-worker-persistent](example/nodejs-worker-persistent)
+ - [commonjs](example/nodejs-worker-persistent/commonjs)
+ - [esm](example/nodejs-worker-persistent/esm)
+
+### Example Browser
```js
import FlexSearchIndex from "./index.js";
@@ -1499,6 +1514,12 @@ The used index configuration has 2 fields (using bidirectional context of `depth
A non-Worker Document index requires 181 seconds to index all contents.
The Worker index just takes 32 seconds to index them all, by processing every field and tag in parallel. For such large content it is a quite impressive result.
+### CSP-friendly Worker (Browser)
+
+When just using worker by passing the option `worker: true`, the worker will be created by code generation under the hood. This might have issues when using strict CSP settings.
+
+You can overcome this issue by passing the filepath to the worker file like `worker: "./worker.js"`. The original worker file is located at `src/worker/worker.js`.
+
## Fuzzy-Search
Fuzzysearch describes a basic concept of how making queries more tolerant. FlexSearch provides several methods to achieve fuzziness:
@@ -1664,15 +1685,19 @@ function inject(index){
}
```
+You could store this function by e.g. `fs.writeFileSync("inject.js", fn_string);` or place it as string in your markup.
+
After creating the index on client side just call the inject method like:
```js
-const index = new Index();
+const index = new Index({/* use same configuration! */});
inject(index);
```
That's it.
+> You'll need to use the same configuration as you used before the export. Any changes on the configuration needs to be re-indexed.
+
### 2. Create just a function body as string
Alternatively you can use lazy function declaration by passing `false` to the serialize function:
@@ -1704,7 +1729,9 @@ inject(index);
## Load Library (Node.js, ESM, Legacy Browser)
+
```bash
npm install flexsearch
@@ -2137,8 +2164,15 @@ The custom build will be saved to `dist/flexsearch.custom.xxxx.min.js` or when f
+### Misc
+
+A formula to determine a well balanced value for the `resolution` is: $2*floor(\sqrt{content.length})$ where content is the value pushed by `index.add()`. Here the maximum length of all contents should be used.
+
## Migration
+
- 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()`
@@ -2151,4 +2185,5 @@ The custom build will be saved to `dist/flexsearch.custom.xxxx.min.js` or when f
- The property `bool` from DocumentOptions was removed (replaced by `Resolver`)
- 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)
\ No newline at end of file
+- 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.
\ No newline at end of file
diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js
index 91b3cda..434eb32 100644
--- a/dist/flexsearch.bundle.debug.js
+++ b/dist/flexsearch.bundle.debug.js
@@ -5,7 +5,7 @@
* Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch
*/
-(function _f(self){'use strict';if(typeof module!=='undefined')self=module;self._factory=_f;
+(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;
var u;
function y(a, b, c) {
const d = typeof c, e = typeof a;
@@ -138,12 +138,12 @@ G.prototype.assign = function(a) {
this.minlength = y(a.minlength, 1, this.minlength);
this.maxlength = y(a.maxlength, 0, this.maxlength);
if (this.cache = c = y(a.cache, !0, this.cache)) {
- this.L = null, this.S = "number" === typeof c ? c : 2e5, this.H = new Map(), this.J = new Map(), this.A = this.h = 128;
+ this.L = null, this.T = "number" === typeof c ? c : 2e5, this.H = new Map(), this.J = new Map(), this.A = this.h = 128;
}
this.B = "";
- this.O = null;
- this.M = "";
this.P = null;
+ this.M = "";
+ this.R = null;
if (this.matcher) {
for (const d of this.matcher.keys()) {
this.B += (this.B ? "|" : "") + d;
@@ -197,8 +197,8 @@ G.prototype.encode = function(a) {
}
}
let k;
- this.stemmer && 2 < g.length && (this.P || (this.P = new RegExp("(?!^)(" + this.M + ")$")), g = g.replace(this.P, l => this.stemmer.get(l)), k = 1);
- this.matcher && 1 < g.length && (this.O || (this.O = new RegExp("(" + this.B + ")", "g")), g = g.replace(this.O, l => this.matcher.get(l)), k = 1);
+ this.stemmer && 2 < g.length && (this.R || (this.R = new RegExp("(?!^)(" + this.M + ")$")), g = g.replace(this.R, l => this.stemmer.get(l)), k = 1);
+ this.matcher && 1 < g.length && (this.P || (this.P = new RegExp("(" + this.B + ")", "g")), g = g.replace(this.P, l => this.matcher.get(l)), k = 1);
g && k && (g.length < this.minlength || this.filter && this.filter.has(g)) && (g = "");
if (g && (this.mapper || this.dedupe && 1 < g.length)) {
e = "";
@@ -212,11 +212,11 @@ G.prototype.encode = function(a) {
g = g.replace(this.replacer[e], this.replacer[e + 1]);
}
}
- this.cache && h.length <= this.A && (this.J.set(h, g), this.J.size > this.S && (this.J.clear(), this.A = this.A / 1.1 | 0));
+ this.cache && h.length <= this.A && (this.J.set(h, g), this.J.size > this.T && (this.J.clear(), this.A = this.A / 1.1 | 0));
g && c.push(g);
}
this.finalize && (c = this.finalize(c) || c);
- this.cache && a.length <= this.h && (this.H.set(a, c), this.H.size > this.S && (this.H.clear(), this.h = this.h / 1.1 | 0));
+ this.cache && a.length <= this.h && (this.H.set(a, c), this.H.size > this.T && (this.H.clear(), this.h = this.h / 1.1 | 0));
return c;
};
function la(a) {
@@ -495,9 +495,7 @@ function N(a) {
const c = b[b.length - 1];
let d;
"function" === typeof c && (d = c, delete b[b.length - 1]);
- this.async = !0;
b = this[a].apply(this, b);
- this.async = !1;
d && (b.then ? b.then(d) : d(b));
return b;
};
@@ -544,7 +542,7 @@ O.prototype.add = function(a, b, c, d) {
}
default:
if (Q(this, m, p, f, a, c), n && 1 < d && r < d - 1) {
- for (e = z(), g = this.R, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) {
+ for (e = z(), g = this.S, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) {
if ((p = b[this.rtl ? d - 1 - r - k : r + k]) && !e[p]) {
e[p] = 1;
const t = this.score ? this.score(b, f, r, p, k) : P(g + (d / 2 > g ? 0 : 1), d, r, h - 1, k - 1), x = this.bidirectional && p > f;
@@ -560,7 +558,7 @@ O.prototype.add = function(a, b, c, d) {
b = "";
}
}
- this.db && (b || this.commit_task.push({del:a}), this.T && Ca(this));
+ this.db && (b || this.commit_task.push({del:a}), this.U && Ca(this));
return this;
};
function Q(a, b, c, d, e, f, g) {
@@ -1134,7 +1132,7 @@ O.prototype.search = function(a, b, c) {
return async function() {
for (let t, x; q < e; q++) {
x = a[q];
- r ? (t = await V(p, x, r), t = Ka(t, d, f, p.R, b, g, 2 === e), f && !1 === t && d.length || (r = x)) : (t = await V(p, x), t = Ka(t, d, f, p.resolution, b, g, 1 === e));
+ r ? (t = await V(p, x, r), t = Ka(t, d, f, p.S, b, g, 2 === e), f && !1 === t && d.length || (r = x)) : (t = await V(p, x), t = Ka(t, d, f, p.resolution, b, g, 1 === e));
if (t) {
return t;
}
@@ -1158,7 +1156,7 @@ O.prototype.search = function(a, b, c) {
}
for (let p, t; q < e; q++) {
t = a[q];
- r ? (p = V(this, t, r), p = Ka(p, d, f, this.R, b, g, 2 === e), f && !1 === p && d.length || (r = t)) : (p = V(this, t), p = Ka(p, d, f, this.resolution, b, g, 1 === e));
+ r ? (p = V(this, t, r), p = Ka(p, d, f, this.S, b, g, 2 === e), f && !1 === p && d.length || (r = t)) : (p = V(this, t), p = Ka(p, d, f, this.resolution, b, g, 1 === e));
if (p) {
return p;
}
@@ -1235,7 +1233,7 @@ function V(a, b, c, d, e, f, g, h) {
}
b || this.reg.delete(a);
}
- this.db && (this.commit_task.push({del:a}), this.T && Ca(this));
+ this.db && (this.commit_task.push({del:a}), this.U && Ca(this));
this.cache && this.cache.remove(a);
return this;
};
@@ -1284,14 +1282,14 @@ function La(a, b) {
this.map = e ? new L(e) : new Map();
this.ctx = e ? new L(e) : new Map();
this.reg = b || (this.fastupdate ? e ? new L(e) : new Map() : e ? new M(e) : new Set());
- this.R = c.resolution || 1;
+ this.S = c.resolution || 1;
this.rtl = d.rtl || a.rtl || !1;
this.cache = (e = a.cache || null) && new H(e);
this.resolve = !1 !== a.resolve;
if (e = a.db) {
this.db = e.mount(this);
}
- this.T = !1 !== a.commit;
+ this.U = !1 !== a.commit;
this.commit_task = [];
this.commit_timer = null;
}
@@ -1304,6 +1302,10 @@ u.commit = function(a, b) {
this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
return this.db.commit(this, a, b);
};
+u.destroy = function() {
+ this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
+ return this.db.destroy();
+};
function Ca(a) {
a.commit_timer || (a.commit_timer = setTimeout(function() {
a.commit_timer = null;
@@ -1325,11 +1327,8 @@ u.contain = function(a) {
return this.db ? this.db.has(a) : this.reg.has(a);
};
u.update = function(a, b) {
- if (this.async) {
- const c = this, d = this.remove(a);
- return d.then ? d.then(() => c.add(a, b)) : this.add(a, b);
- }
- return this.remove(a).add(a, b);
+ const c = this, d = this.remove(a);
+ return d && d.then ? d.then(() => c.add(a, b)) : this.add(a, b);
};
function Ma(a) {
let b = 0;
@@ -1478,32 +1477,34 @@ async function Na(a) {
}
;let Oa = 0;
function W(a) {
- function b(f) {
- f = f.data || f;
- const g = f.id, h = g && e.h[g];
- h && (h(f.msg), delete e.h[g]);
- }
if (!this) {
return new W(a);
}
a || (a = {});
- let c = (self || window)._factory;
- c && (c = c.toString());
- const d = "undefined" === typeof window && self.exports, e = this;
- this.worker = Pa(c, d, a.worker);
- this.h = z();
- if (this.worker) {
- d ? this.worker.on("message", b) : this.worker.onmessage = b;
- if (a.config) {
- return new Promise(function(f) {
- e.h[++Oa] = function() {
- f(e);
- };
- e.worker.postMessage({id:Oa, task:"init", factory:c, options:a});
- });
+ let b = "undefined" !== typeof self && (self || window)._factory;
+ b && (b = b.toString());
+ const c = "undefined" === typeof window, d = this;
+ (async function() {
+ function e(f) {
+ f = f.data || f;
+ const g = f.id, h = g && d.N[g];
+ h && (h(f.msg), delete d.N[g]);
}
- this.worker.postMessage({task:"init", factory:c, options:a});
- }
+ this.worker = await Pa(b, c, a.worker);
+ this.N = z();
+ if (this.worker) {
+ c ? this.worker.on("message", e) : this.worker.onmessage = e;
+ if (a.config) {
+ return delete a.db, new Promise(function(f) {
+ d.N[++Oa] = function() {
+ f(d);
+ };
+ d.worker.postMessage({id:Oa, task:"init", factory:b, options:a});
+ });
+ }
+ this.worker.postMessage({task:"init", factory:b, options:a});
+ }
+ }).call(this);
}
X("add");
X("append");
@@ -1517,14 +1518,14 @@ function X(a) {
let e;
"function" === typeof d && (e = d, c.splice(c.length - 1, 1));
d = new Promise(function(f) {
- b.h[++Oa] = f;
+ b.N[++Oa] = f;
b.worker.postMessage({task:a, id:Oa, args:c});
});
return e ? (d.then(e), this) : d;
};
}
-function Pa(a, b, c) {
- return b ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Na.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : "worker/worker.js", {type:"module"});
+async function Pa(a, b, c) {
+ return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : new ((await import("worker_threads"))["Worker"])((1,eval)("import.meta.dirname") + "/node/node.mjs") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Na.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : "worker/worker.js", {type:"module"});
}
;Y.prototype.add = function(a, b, c) {
C(a) && (b = a, a = ca(b, this.key));
@@ -1546,7 +1547,7 @@ function Pa(a, b, c) {
}
if (this.tag) {
for (d = 0; d < this.F.length; d++) {
- var f = this.F[d], g = this.N[d];
+ var f = this.F[d], g = this.O[d];
e = this.tag.get(g);
let h = z();
if ("function" === typeof f) {
@@ -1598,7 +1599,7 @@ function Pa(a, b, c) {
if (!m) {
continue;
}
- l = [l.U];
+ l = [l.V];
} else if (B(l) || l.constructor === String) {
h[l] = b[l];
continue;
@@ -1731,7 +1732,7 @@ function Qa(a, b, c, d, e, f, g, h) {
B(k) && (k = [k]);
}
k || (k = this.field);
- p = !d && (this.worker || this.async) && [];
+ p = !d && (this.worker || this.db) && [];
let A;
for (let w = 0, v, I, J; w < k.length; w++) {
I = k[w];
@@ -1895,7 +1896,6 @@ function Ta(a) {
this.cache = (c = a.cache || null) && new H(c);
a.cache = !1;
this.worker = a.worker;
- this.async = !1;
c = new Map();
d = b.index || b.field || b;
B(d) && (d = [d]);
@@ -1916,7 +1916,7 @@ function Ta(a) {
d = b.store;
B(d) && (d = [d]);
for (let e = 0, f, g; e < d.length; e++) {
- f = d[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Va(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter));
+ f = d[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.V = g) : (this.C[e] = Va(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter));
}
}
this.index = c;
@@ -1925,7 +1925,7 @@ function Ta(a) {
if ("string" === typeof c && (c = [c]), c.length) {
this.tag = new Map();
this.F = [];
- this.N = [];
+ this.O = [];
for (let e = 0, f, g; e < c.length; e++) {
f = c[e];
g = f.field || f;
@@ -1933,7 +1933,7 @@ function Ta(a) {
throw Error("The tag field from the document descriptor is undefined.");
}
f.custom ? this.F[e] = f.custom : (this.F[e] = Va(g, this.K), f.filter && ("string" === typeof this.F[e] && (this.F[e] = new String(this.F[e])), this.F[e].I = f.filter));
- this.N[e] = g;
+ this.O[e] = g;
this.tag.set(g, new Map());
}
}
@@ -1944,10 +1944,12 @@ u = Y.prototype;
u.mount = function(a) {
let b = this.field;
if (this.tag) {
- for (let e = 0, f; e < this.N.length; e++) {
- f = this.N[e];
- var c = this.index.get(f);
- c || (this.index.set(f, c = new O({}, this.reg)), b === this.field && (b = b.slice(0)), b.push(f));
+ for (let e = 0, f; e < this.O.length; e++) {
+ f = this.O[e];
+ var c = void 0;
+ this.index.set(f, c = new O({}, this.reg));
+ b === this.field && (b = b.slice(0));
+ b.push(f);
c.tag = this.tag.get(f);
}
}
@@ -1962,7 +1964,7 @@ u.mount = function(a) {
f.document = !0;
e ? f.bypass = !0 : f.store = this.store;
}
- this.db = this.async = !0;
+ this.db = !0;
return Promise.all(c);
};
u.commit = async function(a, b) {
@@ -1973,6 +1975,13 @@ u.commit = async function(a, b) {
await Promise.all(c);
this.reg.clear();
};
+u.destroy = function() {
+ const a = [];
+ for (const b of this.index.values()) {
+ a.push(b.destroy());
+ }
+ return Promise.all(a);
+};
function Va(a, b) {
const c = a.split(":");
let d = 0;
@@ -2151,7 +2160,6 @@ u.close = function() {
this.db = null;
};
u.destroy = function() {
- this.db && this.close();
return Wa.deleteDatabase(this.id + (this.field ? ":" + this.field : ""));
};
u.clear = function() {
@@ -2261,7 +2269,7 @@ u.commit = async function(a, b, c) {
b = !0;
break;
} else {
- d[e] = f.V;
+ d[e] = f.W;
}
}
b || (c || (d = d.concat(ba(a.reg))), d.length && await this.remove(d));
diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js
index ba5e61b..dd085d2 100644
--- a/dist/flexsearch.bundle.min.js
+++ b/dist/flexsearch.bundle.min.js
@@ -5,7 +5,7 @@
* Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch
*/
-(function _f(self){'use strict';if(typeof module!=='undefined')self=module;self._factory=_f;var u;function y(a,b,c){const d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===e?b:a}function z(){return Object.create(null)}function aa(a,b){return b.length-a.length}
+(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var u;function y(a,b,c){const d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===e?b:a}function z(){return Object.create(null)}function aa(a,b){return b.length-a.length}
function B(a){return"string"===typeof a}function C(a){return"object"===typeof a}function ba(a){const b=[];for(const c of a.keys())b.push(c);return b}function ca(a,b){if(B(b))a=a[b];else for(let c=0;a&&cthis.stemmer.get(l)),k=1);this.matcher&&
-1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function la(a){a.L=null;a.H.clear();a.J.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function G(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}G.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};
+let c=[],d=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.stemmer.get(l)),k=1);this.matcher&&
+1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.T&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.T&&(this.H.clear(),this.h=this.h/1.1|0));return c};function la(a){a.L=null;a.H.clear();a.J.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function G(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}G.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};
G.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};G.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};G.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:function(a){return a.toLowerCase()},dedupe:!1};const oa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const pa=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),qa=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const sa=/[\x00-\x7F]+/g;const ta=/[\x00-\x7F]+/g;const ua=/[\x00-\x7F]+/g;var va={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:oa,replacer:qa,matcher:pa},LatinExtra:{normalize:!0,dedupe:!0,mapper:oa,replacer:qa.concat([/(?!^)[aeoy]/g,""]),matcher:pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e}
function J(a){if(!this)return new J(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gf;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,r,g,f):P(q,d,r,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1<
-e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&
-(b||this.commit_task.push({del:a}),this.T&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}}
+function ya(a){let b=2**this.A-1;if("number"==typeof a)return a&b;let c=0,d=this.A+1;for(let e=0;ef;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,r,g,f):P(q,d,r,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1<
+e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&
+(b||this.commit_task.push({del:a}),this.U&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}}
function P(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Da(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Da(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Ca(this));this.cache&&this.cache.remove(a);return this};
+function Ka(a,b,c,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,l=0,m;k=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.U&&Ca(this));this.cache&&this.cache.remove(a);return this};
function La(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)};function Ma(a){let b=0;if(a.constructor===Array)for(let c=0,d;cc.add(a,b)):this.add(a,b)};
+function Ma(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=z();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof c&&f&&f();return}za(a,b||this,c,h,d,e,k,f);return g};
u.import=function(a,b){if(b)switch(B(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}};
u.serialize=function(a=!0){if(!this.reg.size)return"";let b="",c="";for(var d of this.reg.keys())c||(c=typeof d),b+=(b?",":"")+("string"===c?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let m=0,n;mc||d)a=a.slice(d,d+c);e&&(a=Ta.call(this,a));return a}}
-function Ta(a){const b=Array(a.length);for(let c=0,d;c{f=k}));e||(e=0);d||(d=0);if(d{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})};
-u.close=function(){this.db.close();this.db=null};u.destroy=function(){this.db&&this.close();return Wa.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(Xa,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let q=d;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})};
u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})};
-u.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let e=0,f;e this.stemmer.get(l)), k = 1);
- this.matcher && 1 < g.length && (this.O || (this.O = new RegExp("(" + this.B + ")", "g")), g = g.replace(this.O, l => this.matcher.get(l)), k = 1);
+ this.stemmer && 2 < g.length && (this.R || (this.R = new RegExp("(?!^)(" + this.M + ")$")), g = g.replace(this.R, l => this.stemmer.get(l)), k = 1);
+ this.matcher && 1 < g.length && (this.P || (this.P = new RegExp("(" + this.B + ")", "g")), g = g.replace(this.P, l => this.matcher.get(l)), k = 1);
g && k && (g.length < this.minlength || this.filter && this.filter.has(g)) && (g = "");
if (g && (this.mapper || this.dedupe && 1 < g.length)) {
e = "";
@@ -211,11 +211,11 @@ G.prototype.encode = function(a) {
g = g.replace(this.replacer[e], this.replacer[e + 1]);
}
}
- this.cache && h.length <= this.A && (this.J.set(h, g), this.J.size > this.S && (this.J.clear(), this.A = this.A / 1.1 | 0));
+ this.cache && h.length <= this.A && (this.J.set(h, g), this.J.size > this.T && (this.J.clear(), this.A = this.A / 1.1 | 0));
g && c.push(g);
}
this.finalize && (c = this.finalize(c) || c);
- this.cache && a.length <= this.h && (this.H.set(a, c), this.H.size > this.S && (this.H.clear(), this.h = this.h / 1.1 | 0));
+ this.cache && a.length <= this.h && (this.H.set(a, c), this.H.size > this.T && (this.H.clear(), this.h = this.h / 1.1 | 0));
return c;
};
function la(a) {
@@ -494,9 +494,7 @@ function N(a) {
const c = b[b.length - 1];
let d;
"function" === typeof c && (d = c, delete b[b.length - 1]);
- this.async = !0;
b = this[a].apply(this, b);
- this.async = !1;
d && (b.then ? b.then(d) : d(b));
return b;
};
@@ -543,7 +541,7 @@ O.prototype.add = function(a, b, c, d) {
}
default:
if (Q(this, m, p, f, a, c), n && 1 < d && r < d - 1) {
- for (e = z(), g = this.R, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) {
+ for (e = z(), g = this.S, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) {
if ((p = b[this.rtl ? d - 1 - r - k : r + k]) && !e[p]) {
e[p] = 1;
const t = this.score ? this.score(b, f, r, p, k) : P(g + (d / 2 > g ? 0 : 1), d, r, h - 1, k - 1), x = this.bidirectional && p > f;
@@ -559,7 +557,7 @@ O.prototype.add = function(a, b, c, d) {
b = "";
}
}
- this.db && (b || this.commit_task.push({del:a}), this.T && Ca(this));
+ this.db && (b || this.commit_task.push({del:a}), this.U && Ca(this));
return this;
};
function Q(a, b, c, d, e, f, g) {
@@ -1133,7 +1131,7 @@ O.prototype.search = function(a, b, c) {
return async function() {
for (let t, x; q < e; q++) {
x = a[q];
- r ? (t = await V(p, x, r), t = Ka(t, d, f, p.R, b, g, 2 === e), f && !1 === t && d.length || (r = x)) : (t = await V(p, x), t = Ka(t, d, f, p.resolution, b, g, 1 === e));
+ r ? (t = await V(p, x, r), t = Ka(t, d, f, p.S, b, g, 2 === e), f && !1 === t && d.length || (r = x)) : (t = await V(p, x), t = Ka(t, d, f, p.resolution, b, g, 1 === e));
if (t) {
return t;
}
@@ -1157,7 +1155,7 @@ O.prototype.search = function(a, b, c) {
}
for (let p, t; q < e; q++) {
t = a[q];
- r ? (p = V(this, t, r), p = Ka(p, d, f, this.R, b, g, 2 === e), f && !1 === p && d.length || (r = t)) : (p = V(this, t), p = Ka(p, d, f, this.resolution, b, g, 1 === e));
+ r ? (p = V(this, t, r), p = Ka(p, d, f, this.S, b, g, 2 === e), f && !1 === p && d.length || (r = t)) : (p = V(this, t), p = Ka(p, d, f, this.resolution, b, g, 1 === e));
if (p) {
return p;
}
@@ -1234,7 +1232,7 @@ function V(a, b, c, d, e, f, g, h) {
}
b || this.reg.delete(a);
}
- this.db && (this.commit_task.push({del:a}), this.T && Ca(this));
+ this.db && (this.commit_task.push({del:a}), this.U && Ca(this));
this.cache && this.cache.remove(a);
return this;
};
@@ -1283,14 +1281,14 @@ function La(a, b) {
this.map = e ? new L(e) : new Map();
this.ctx = e ? new L(e) : new Map();
this.reg = b || (this.fastupdate ? e ? new L(e) : new Map() : e ? new M(e) : new Set());
- this.R = c.resolution || 1;
+ this.S = c.resolution || 1;
this.rtl = d.rtl || a.rtl || !1;
this.cache = (e = a.cache || null) && new H(e);
this.resolve = !1 !== a.resolve;
if (e = a.db) {
this.db = e.mount(this);
}
- this.T = !1 !== a.commit;
+ this.U = !1 !== a.commit;
this.commit_task = [];
this.commit_timer = null;
}
@@ -1303,6 +1301,10 @@ u.commit = function(a, b) {
this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
return this.db.commit(this, a, b);
};
+u.destroy = function() {
+ this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
+ return this.db.destroy();
+};
function Ca(a) {
a.commit_timer || (a.commit_timer = setTimeout(function() {
a.commit_timer = null;
@@ -1324,11 +1326,8 @@ u.contain = function(a) {
return this.db ? this.db.has(a) : this.reg.has(a);
};
u.update = function(a, b) {
- if (this.async) {
- const c = this, d = this.remove(a);
- return d.then ? d.then(() => c.add(a, b)) : this.add(a, b);
- }
- return this.remove(a).add(a, b);
+ const c = this, d = this.remove(a);
+ return d && d.then ? d.then(() => c.add(a, b)) : this.add(a, b);
};
function Ma(a) {
let b = 0;
@@ -1477,32 +1476,34 @@ async function Na(a) {
}
;let Oa = 0;
function W(a) {
- function b(f) {
- f = f.data || f;
- const g = f.id, h = g && e.h[g];
- h && (h(f.msg), delete e.h[g]);
- }
if (!this) {
return new W(a);
}
a || (a = {});
- let c = (self || window)._factory;
- c && (c = c.toString());
- const d = "undefined" === typeof window && self.exports, e = this;
- this.worker = Pa(c, d, a.worker);
- this.h = z();
- if (this.worker) {
- d ? this.worker.on("message", b) : this.worker.onmessage = b;
- if (a.config) {
- return new Promise(function(f) {
- e.h[++Oa] = function() {
- f(e);
- };
- e.worker.postMessage({id:Oa, task:"init", factory:c, options:a});
- });
+ let b = "undefined" !== typeof self && (self || window)._factory;
+ b && (b = b.toString());
+ const c = "undefined" === typeof window, d = this;
+ (async function() {
+ function e(f) {
+ f = f.data || f;
+ const g = f.id, h = g && d.N[g];
+ h && (h(f.msg), delete d.N[g]);
}
- this.worker.postMessage({task:"init", factory:c, options:a});
- }
+ this.worker = await Pa(b, c, a.worker);
+ this.N = z();
+ if (this.worker) {
+ c ? this.worker.on("message", e) : this.worker.onmessage = e;
+ if (a.config) {
+ return delete a.db, new Promise(function(f) {
+ d.N[++Oa] = function() {
+ f(d);
+ };
+ d.worker.postMessage({id:Oa, task:"init", factory:b, options:a});
+ });
+ }
+ this.worker.postMessage({task:"init", factory:b, options:a});
+ }
+ }).call(this);
}
X("add");
X("append");
@@ -1516,14 +1517,14 @@ function X(a) {
let e;
"function" === typeof d && (e = d, c.splice(c.length - 1, 1));
d = new Promise(function(f) {
- b.h[++Oa] = f;
+ b.N[++Oa] = f;
b.worker.postMessage({task:a, id:Oa, args:c});
});
return e ? (d.then(e), this) : d;
};
}
-function Pa(a, b, c) {
- return b ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Na.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : "worker/worker.js", {type:"module"});
+async function Pa(a, b, c) {
+ return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/node/node.mjs") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Na.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : "worker/worker.js", {type:"module"});
}
;Y.prototype.add = function(a, b, c) {
C(a) && (b = a, a = ca(b, this.key));
@@ -1545,7 +1546,7 @@ function Pa(a, b, c) {
}
if (this.tag) {
for (d = 0; d < this.F.length; d++) {
- var f = this.F[d], g = this.N[d];
+ var f = this.F[d], g = this.O[d];
e = this.tag.get(g);
let h = z();
if ("function" === typeof f) {
@@ -1597,7 +1598,7 @@ function Pa(a, b, c) {
if (!m) {
continue;
}
- l = [l.U];
+ l = [l.V];
} else if (B(l) || l.constructor === String) {
h[l] = b[l];
continue;
@@ -1730,7 +1731,7 @@ function Qa(a, b, c, d, e, f, g, h) {
B(k) && (k = [k]);
}
k || (k = this.field);
- p = !d && (this.worker || this.async) && [];
+ p = !d && (this.worker || this.db) && [];
let A;
for (let w = 0, v, I, J; w < k.length; w++) {
I = k[w];
@@ -1894,7 +1895,6 @@ function Ta(a) {
this.cache = (c = a.cache || null) && new H(c);
a.cache = !1;
this.worker = a.worker;
- this.async = !1;
c = new Map();
d = b.index || b.field || b;
B(d) && (d = [d]);
@@ -1915,7 +1915,7 @@ function Ta(a) {
d = b.store;
B(d) && (d = [d]);
for (let e = 0, f, g; e < d.length; e++) {
- f = d[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Va(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter));
+ f = d[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.V = g) : (this.C[e] = Va(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter));
}
}
this.index = c;
@@ -1924,7 +1924,7 @@ function Ta(a) {
if ("string" === typeof c && (c = [c]), c.length) {
this.tag = new Map();
this.F = [];
- this.N = [];
+ this.O = [];
for (let e = 0, f, g; e < c.length; e++) {
f = c[e];
g = f.field || f;
@@ -1932,7 +1932,7 @@ function Ta(a) {
throw Error("The tag field from the document descriptor is undefined.");
}
f.custom ? this.F[e] = f.custom : (this.F[e] = Va(g, this.K), f.filter && ("string" === typeof this.F[e] && (this.F[e] = new String(this.F[e])), this.F[e].I = f.filter));
- this.N[e] = g;
+ this.O[e] = g;
this.tag.set(g, new Map());
}
}
@@ -1943,10 +1943,12 @@ u = Y.prototype;
u.mount = function(a) {
let b = this.field;
if (this.tag) {
- for (let e = 0, f; e < this.N.length; e++) {
- f = this.N[e];
- var c = this.index.get(f);
- c || (this.index.set(f, c = new O({}, this.reg)), b === this.field && (b = b.slice(0)), b.push(f));
+ for (let e = 0, f; e < this.O.length; e++) {
+ f = this.O[e];
+ var c = void 0;
+ this.index.set(f, c = new O({}, this.reg));
+ b === this.field && (b = b.slice(0));
+ b.push(f);
c.tag = this.tag.get(f);
}
}
@@ -1961,7 +1963,7 @@ u.mount = function(a) {
f.document = !0;
e ? f.bypass = !0 : f.store = this.store;
}
- this.db = this.async = !0;
+ this.db = !0;
return Promise.all(c);
};
u.commit = async function(a, b) {
@@ -1972,6 +1974,13 @@ u.commit = async function(a, b) {
await Promise.all(c);
this.reg.clear();
};
+u.destroy = function() {
+ const a = [];
+ for (const b of this.index.values()) {
+ a.push(b.destroy());
+ }
+ return Promise.all(a);
+};
function Va(a, b) {
const c = a.split(":");
let d = 0;
@@ -2150,7 +2159,6 @@ u.close = function() {
this.db = null;
};
u.destroy = function() {
- this.db && this.close();
return Wa.deleteDatabase(this.id + (this.field ? ":" + this.field : ""));
};
u.clear = function() {
@@ -2260,7 +2268,7 @@ u.commit = async function(a, b, c) {
b = !0;
break;
} else {
- d[e] = f.V;
+ d[e] = f.W;
}
}
b || (c || (d = d.concat(ba(a.reg))), d.length && await this.remove(d));
diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js
index 26b13e9..5861dbd 100644
--- a/dist/flexsearch.bundle.module.min.js
+++ b/dist/flexsearch.bundle.module.min.js
@@ -15,11 +15,11 @@ function B(a){return"string"===typeof a}function C(a){return"object"===typeof a}
["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]];const fa=/[^\p{L}\p{N}]+/u,ha=/(\d{3})/g,ia=/(\D)(\d{3})/g,ja=/(\d{3})(\D)/g,ka="".normalize&&/[\u0300-\u036f]/g;function F(a){if(!this)return new F(...arguments);for(let b=0;bthis.stemmer.get(l)),k=1);this.matcher&&
-1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function la(a){a.L=null;a.H.clear();a.J.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function G(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}G.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};
+let c=[],d=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.stemmer.get(l)),k=1);this.matcher&&
+1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.T&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.T&&(this.H.clear(),this.h=this.h/1.1|0));return c};function la(a){a.L=null;a.H.clear();a.J.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function G(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}G.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};
G.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};G.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};G.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:function(a){return a.toLowerCase()},dedupe:!1};const oa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const pa=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),qa=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const sa=/[\x00-\x7F]+/g;const ta=/[\x00-\x7F]+/g;const ua=/[\x00-\x7F]+/g;var va={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:oa,replacer:qa,matcher:pa},LatinExtra:{normalize:!0,dedupe:!0,mapper:oa,replacer:qa.concat([/(?!^)[aeoy]/g,""]),matcher:pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e}
function J(a){if(!this)return new J(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gf;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,r,g,f):P(q,d,r,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1<
-e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&
-(b||this.commit_task.push({del:a}),this.T&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}}
+function ya(a){let b=2**this.A-1;if("number"==typeof a)return a&b;let c=0,d=this.A+1;for(let e=0;ef;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,r,g,f):P(q,d,r,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1<
+e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&
+(b||this.commit_task.push({del:a}),this.U&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}}
function P(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Da(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Da(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Ca(this));this.cache&&this.cache.remove(a);return this};
+function Ka(a,b,c,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,l=0,m;k=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.U&&Ca(this));this.cache&&this.cache.remove(a);return this};
function La(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)};function Ma(a){let b=0;if(a.constructor===Array)for(let c=0,d;cc.add(a,b)):this.add(a,b)};
+function Ma(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=z();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof c&&f&&f();return}za(a,b||this,c,h,d,e,k,f);return g};
u.import=function(a,b){if(b)switch(B(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}};
u.serialize=function(a=!0){if(!this.reg.size)return"";let b="",c="";for(var d of this.reg.keys())c||(c=typeof d),b+=(b?",":"")+("string"===c?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let m=0,n;mc||d)a=a.slice(d,d+c);e&&(a=Ta.call(this,a));return a}}
-function Ta(a){const b=Array(a.length);for(let c=0,d;c{f=k}));e||(e=0);d||(d=0);if(d{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})};
-u.close=function(){this.db.close();this.db=null};u.destroy=function(){this.db&&this.close();return Wa.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(Xa,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let q=d;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})};
u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})};
-u.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let e=0,f;e b.add(a, c)) : this.add(a, c);
- }
- return this.remove(a).add(a, c);
+ const b = this, e = this.remove(a);
+ return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c);
};
function U(a) {
let c = 0;
@@ -973,7 +968,7 @@ function W(a, c, b, e, d, f, g, h) {
z(l) && (l = [l]);
}
l || (l = this.field);
- p = !e && (this.worker || this.async) && [];
+ p = !e && (this.worker || this.db) && [];
for (let v = 0, r, C, D; v < l.length; v++) {
C = l[v];
let A;
@@ -1099,7 +1094,7 @@ function xa(a) {
this.A = (b = c.store || null) && !0 !== b && [];
this.store = b && new Map();
this.cache = (b = a.cache || null) && new K(b);
- this.async = a.cache = !1;
+ a.cache = !1;
b = new Map();
let e = c.index || c.field || c;
z(e) && (e = [e]);
diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js
index 7ac3d99..92d5f08 100644
--- a/dist/flexsearch.compact.min.js
+++ b/dist/flexsearch.compact.min.js
@@ -21,14 +21,14 @@ let b=[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.matcher.get(l)),k=1);g&&k&&(g.lengththis.O&&(this.H.clear(),this.D=this.D/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.F.set(a,b),this.F.size>this.O&&(this.F.clear(),this.h=this.h/1.1|0));return b};function ha(a){a.J=null;a.F.clear();a.H.clear()};function ia(a,c,b){a=("object"===typeof a?""+a.query:a).toLowerCase();let e=this.cache.get(a);if(!e){e=this.search(a,c,b);if(e.then){const d=this;e.then(function(f){d.cache.set(a,f);return f})}this.cache.set(a,e)}return e}function J(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}J.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};
J.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};J.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};J.prototype.clear=function(){this.cache.clear();this.h=""};const ja={normalize:function(a){return a.toLowerCase()},dedupe:!1};const K=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const ka=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),la=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const ma={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const na=/[\x00-\x7F]+/g;const oa=/[\x00-\x7F]+/g;const pa=/[\x00-\x7F]+/g;var qa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ja,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:K},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:K,replacer:la,matcher:ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:K,replacer:la.concat([/(?!^)[aeoy]/g,""]),matcher:ka},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=n.substring(f,h);var k=this.score?this.score(c,n,p,g,f):N(t,e,p,d,f);O(this,m,g,k,a,b)}break}case "reverse":if(1<
+g||"w"===g||!(g=ma[g])||g===d||(e+=g,d=g,4!==e.length));f++);a[b]=e}}},ArabicDefault:{rtl:!0,normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(na," ")}},CjkDefault:{normalize:!1,dedupe:!0,split:"",prepare:function(a){return(""+a).replace(oa,"")}},CyrillicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(pa," ")}}};function ra(a,c,b,e,d,f,g,h){(e=a(b?b+"."+e:e,JSON.stringify(g)))&&e.then?e.then(function(){c.export(a,c,b,d,f+1,h)}):c.export(a,c,b,d,f+1,h)};const sa={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};function ta(a){L.call(a,"add");L.call(a,"append");L.call(a,"search");L.call(a,"update");L.call(a,"remove")}function L(a){this[a+"Async"]=function(){var c=arguments;const b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);c=this[a].apply(this,c);e&&(c.then?c.then(e):e(c));return c}};y();M.prototype.add=function(a,c,b,e){if(c&&(a||0===a)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(e=c.length){const l=y(),m=y(),q=this.depth,t=this.resolution;for(let p=0;pf;h--){g=n.substring(f,h);var k=this.score?this.score(c,n,p,g,f):N(t,e,p,d,f);O(this,m,g,k,a,b)}break}case "reverse":if(1<
d){for(h=d-1;0g?0:1),e,p,h-1,k-1),B=this.bidirectional&&n>f;O(this,l,B?f:n,w,a,b,B?n:f)}}}}this.fastupdate||this.reg.add(a)}}return this};
function O(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=y()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h]))))}function N(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),e.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;e=[f]}c-=g;if(!c)break}return e.length?e=1c||d)b=b.slice(d,c+d)}e=b}return e};function R(a,c,b,e){return(a=S(this,a,c))&&a.length?Q(a,b,e):[]}
function va(a,c,b,e,d,f,g){let h=[];if(a){e=Math.min(a.length,e);for(let k=0,l=0,m;k=d)))break;if(h.length){if(g)return Q(h,d,0);c.push(h);return}}return!b&&h}function S(a,c,b){let e;b&&(e=a.bidirectional&&c>b);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};M.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else T(this.map,a),this.depth&&T(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this};
function T(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}return this.remove(a).add(a,c)};
+new Set);this.P=b.resolution||1;this.rtl=e.rtl||a.rtl||!1;this.cache=(d=a.cache||null)&&new J(d)}u=M.prototype;u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};u.append=function(a,c){return this.add(a,c,!0)};u.contain=function(a){return this.reg.has(a)};u.update=function(a,c){const b=this,e=this.remove(a);return e&&e.then?e.then(()=>b.add(a,c)):this.add(a,c)};
function U(a){let c=0;if(a.constructor===Array)for(let b=0,e;b{f=l}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}ra(a,c||this,b,h,e,d,k,f);return g};
u.import=function(a,c){if(c)switch(z(c)&&(c=JSON.parse(c)),a){case "cfg":this.h=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}};
@@ -37,13 +37,13 @@ m[0];g=m[1];for(const q of g.entries()){g=q[0];h=q[1];k="";for(let t=0,p;tb||e)a=a.slice(e,e+b);d&&(a=xa.call(this,a));return a}}
-function xa(a){const c=Array(a.length);for(let b=0,e;b b.add(a, c)) : this.add(a, c);
- }
- return this.remove(a).add(a, c);
+ const b = this, d = this.remove(a);
+ return d && d.then ? d.then(() => b.add(a, c)) : this.add(a, c);
};
function V(a) {
let c = 0;
@@ -871,7 +866,7 @@ function X(a, c, b, d, f, e, g, h) {
z(m) && (m = [m]);
}
m || (m = this.field);
- p = !d && (this.worker || this.async) && [];
+ p = !d && (this.worker || this.db) && [];
for (let v = 0, q, C, D; v < m.length; v++) {
C = m[v];
let A;
@@ -996,7 +991,6 @@ function ta(a) {
this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set();
this.h = (b = c.store || null) && !0 !== b && [];
this.store = b && new Map();
- this.async = !1;
b = new Map();
let d = c.index || c.field || c;
z(d) && (d = [d]);
diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js
index 11ddce8..534e4be 100644
--- a/dist/flexsearch.compact.module.min.js
+++ b/dist/flexsearch.compact.module.min.js
@@ -19,14 +19,14 @@ x(a.minlength,1,this.minlength);this.maxlength=x(a.maxlength,0,this.maxlength);t
I.prototype.encode=function(a){this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):H?a.normalize("NFKD").replace(H,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g=1);this.matcher&&1this.matcher.get(h)),g=1);f&&g&&(f.lengthf;h--){g=n.substring(f,h);var k=this.score?this.score(c,n,p,g,f):P(t,d,p,e,f);Q(this,l,g,k,a,b)}break}case "reverse":if(1<
+"w"===g||!(g=ia[g])||g===e||(d+=g,e=g,4!==d.length));f++);a[b]=d}}},ArabicDefault:{rtl:!0,normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(ja," ")}},CjkDefault:{normalize:!1,dedupe:!0,split:"",prepare:function(a){return(""+a).replace(ka,"")}},CyrillicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(la," ")}}};function na(a,c,b,d,e,f,g,h){(d=a(b?b+"."+d:d,JSON.stringify(g)))&&d.then?d.then(function(){c.export(a,c,b,e,f+1,h)}):c.export(a,c,b,e,f+1,h)};const oa={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};function pa(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}function M(a){this[a+"Async"]=function(){var c=arguments;const b=c[c.length-1];let d;"function"===typeof b&&(d=b,delete c[c.length-1]);c=this[a].apply(this,c);d&&(c.then?c.then(d):d(c));return c}};y();N.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const m=y(),l=y(),r=this.depth,t=this.resolution;for(let p=0;pf;h--){g=n.substring(f,h);var k=this.score?this.score(c,n,p,g,f):P(t,d,p,e,f);Q(this,l,g,k,a,b)}break}case "reverse":if(1<
e){for(h=e-1;0g?0:1),d,p,h-1,k-1),B=this.bidirectional&&n>f;Q(this,m,B?f:n,w,a,b,B?n:f)}}}}this.fastupdate||this.reg.add(a)}}return this};
function Q(a,c,b,d,e,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=y()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function P(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,f,g;e=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),d.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;d=[f]}c-=g;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d};function S(a,c,b,d){return(a=T(this,a,c))&&a.length?R(a,b,d):[]}
function ra(a,c,b,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,m=0,l;k=e)))break;if(h.length){if(g)return R(h,e,0);c.push(h);return}}return!b&&h}function T(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};N.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===b.length-1?e.pop():e.splice(f,1)}}else U(this.map,a),this.depth&&U(this.ctx,a);c||this.reg.delete(a)}return this};
function U(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,f;db.add(a,c)):this.add(a,c)}return this.remove(a).add(a,c)};
+new Set);this.I=b.resolution||1;this.rtl=d.rtl||a.rtl||!1}u=N.prototype;u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};u.append=function(a,c){return this.add(a,c,!0)};u.contain=function(a){return this.reg.has(a)};u.update=function(a,c){const b=this,d=this.remove(a);return d&&d.then?d.then(()=>b.add(a,c)):this.add(a,c)};
function V(a){let c=0;if(a.constructor===Array)for(let b=0,d;b{f=m}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let m of this.reg.keys())k[m]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.C?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}na(a,c||this,b,h,d,e,k,f);return g};
u.import=function(a,c){if(c)switch(A(c)&&(c=JSON.parse(c)),a){case "cfg":this.C=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}};
@@ -34,12 +34,12 @@ u.serialize=function(a=!0){if(!this.reg.size)return"";let c="",b="";for(var d of
l[0];g=l[1];for(const r of g.entries()){g=r[0];h=r[1];k="";for(let t=0,p;tb||d)a=a.slice(d,d+b);e&&(a=ta.call(this,a));return a}}
-function ta(a){const c=Array(a.length);for(let b=0,d;b{f=k}));e||(e=0);d||(d=0);if(d this.J && (this.N.clear(), this.h = this.h / 1.1 | 0));
return d;
};
-function Ga(a) {
+function Fa(a) {
a.U = null;
a.N.clear();
a.S.clear();
}
-;function Ha(a, b, c) {
+;function Ga(a, b, c) {
a = ("object" === typeof a ? "" + a.query : a).toLowerCase();
var d = this.cache.get(a);
if (!d) {
@@ -1067,54 +1067,54 @@ function Ga(a) {
}
return d;
}
-function Q(a) {
+function R(a) {
this.limit = a && !0 !== a ? a : 1000;
this.cache = new Map();
this.h = "";
}
-Q.prototype.set = function(a, b) {
+R.prototype.set = function(a, b) {
this.cache.set(this.h = a, b);
this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value);
};
-Q.prototype.get = function(a) {
+R.prototype.get = function(a) {
var b = this.cache.get(a);
b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b));
return b;
};
-Q.prototype.remove = function(a) {
+R.prototype.remove = function(a) {
for (var b = x(this.cache), c = b.next(); !c.done; c = b.next()) {
c = c.value;
var d = c[0];
c[1].includes(a) && this.cache.delete(d);
}
};
-Q.prototype.clear = function() {
+R.prototype.clear = function() {
this.cache.clear();
this.h = "";
};
-var Ia = {normalize:function(a) {
+var Ha = {normalize:function(a) {
return a.toLowerCase();
}, dedupe:!1};
-var Ja = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]);
-var Ka = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), La = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"];
-var Ma = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6};
+var Ia = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]);
+var Ja = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ka = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"];
+var La = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6};
+var Ma = /[\x00-\x7F]+/g;
var Na = /[\x00-\x7F]+/g;
var Oa = /[\x00-\x7F]+/g;
-var Pa = /[\x00-\x7F]+/g;
-var Qa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ia, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ja}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ja, replacer:La, matcher:Ka}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ja, replacer:La.concat([/(?!^)[aeoy]/g, ""]), matcher:Ka}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) {
+var Pa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ha, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ia}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ia, replacer:Ka, matcher:Ja}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ia, replacer:Ka.concat([/(?!^)[aeoy]/g, ""]), matcher:Ja}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) {
for (var b = 0; b < a.length; b++) {
- for (var c = a[b], d = c.charAt(0), e = Ma[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = Ma[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) {
+ for (var c = a[b], d = c.charAt(0), e = La[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = La[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) {
}
a[b] = d;
}
}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) {
- return ("" + a).replace(Na, " ");
+ return ("" + a).replace(Ma, " ");
}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) {
- return ("" + a).replace(Oa, "");
+ return ("" + a).replace(Na, "");
}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) {
- return ("" + a).replace(Pa, " ");
+ return ("" + a).replace(Oa, " ");
}}};
-function Ra(a, b, c, d) {
+function Qa(a, b, c, d) {
for (var e = [], g = 0, f; g < a.index.length; g++) {
if (f = a.index[g], b >= f.length) {
b -= f.length;
@@ -1130,9 +1130,9 @@ function Ra(a, b, c, d) {
}
return e;
}
-function R(a) {
+function S(a) {
if (!this) {
- return new R(a);
+ return new S(a);
}
this.index = a ? [a] : [];
this.length = a ? a.length : 0;
@@ -1179,12 +1179,12 @@ function R(a) {
}
if ("slice" === d) {
return function(e, g) {
- return Ra(b, e || 0, g || b.length, !1);
+ return Qa(b, e || 0, g || b.length, !1);
};
}
if ("splice" === d) {
return function(e, g) {
- return Ra(b, e || 0, g || b.length, !0);
+ return Qa(b, e || 0, g || b.length, !0);
};
}
if ("constructor" === d) {
@@ -1200,62 +1200,62 @@ function R(a) {
return !0;
}});
}
-R.prototype.clear = function() {
+S.prototype.clear = function() {
this.index.length = 0;
};
-R.prototype.destroy = function() {
+S.prototype.destroy = function() {
this.proxy = this.index = null;
};
-R.prototype.push = function() {
-};
-function S(a) {
- a = void 0 === a ? 8 : a;
- if (!this) {
- return new S(a);
- }
- this.index = K();
- this.B = [];
- this.size = 0;
- 32 < a ? (this.h = Sa, this.A = BigInt(a)) : (this.h = Ta, this.A = a);
-}
-S.prototype.get = function(a) {
- var b = this.h(a);
- return (b = this.index[b]) && b.get(a);
-};
-S.prototype.set = function(a, b) {
- var c = this.h(a), d = this.index[c];
- d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.B.push(d));
+S.prototype.push = function() {
};
function T(a) {
a = void 0 === a ? 8 : a;
if (!this) {
return new T(a);
}
- this.index = K();
- this.h = [];
- 32 < a ? (this.B = Sa, this.A = BigInt(a)) : (this.B = Ta, this.A = a);
+ this.index = L();
+ this.B = [];
+ this.size = 0;
+ 32 < a ? (this.h = Ra, this.A = BigInt(a)) : (this.h = Sa, this.A = a);
}
-T.prototype.add = function(a) {
+T.prototype.get = function(a) {
+ var b = this.h(a);
+ return (b = this.index[b]) && b.get(a);
+};
+T.prototype.set = function(a, b) {
+ var c = this.h(a), d = this.index[c];
+ d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.B.push(d));
+};
+function U(a) {
+ a = void 0 === a ? 8 : a;
+ if (!this) {
+ return new U(a);
+ }
+ this.index = L();
+ this.h = [];
+ 32 < a ? (this.B = Ra, this.A = BigInt(a)) : (this.B = Sa, this.A = a);
+}
+U.prototype.add = function(a) {
var b = this.B(a), c = this.index[b];
c ? (b = c.size, c.add(a), (b -= c.size) && this.size++) : (this.index[b] = c = new Set([a]), this.h.push(c));
};
-v = S.prototype;
-v.has = T.prototype.has = function(a) {
+u = T.prototype;
+u.has = U.prototype.has = function(a) {
var b = this.B(a);
return (b = this.index[b]) && b.has(a);
};
-v.delete = T.prototype.delete = function(a) {
+u.delete = U.prototype.delete = function(a) {
var b = this.B(a);
(b = this.index[b]) && b.delete(a) && this.size--;
};
-v.clear = T.prototype.clear = function() {
- this.index = K();
+u.clear = U.prototype.clear = function() {
+ this.index = L();
this.h = [];
this.size = 0;
};
-v.values = T.prototype.values = function Ua() {
+u.values = U.prototype.values = function Ta() {
var b, c = this, d, e, g;
- return qa(Ua, function(f) {
+ return qa(Ta, function(f) {
switch(f.h) {
case 1:
b = 0;
@@ -1279,9 +1279,9 @@ v.values = T.prototype.values = function Ua() {
}
});
};
-v.keys = T.prototype.keys = function Va() {
+u.keys = U.prototype.keys = function Ua() {
var b, c = this, d, e, g;
- return qa(Va, function(f) {
+ return qa(Ua, function(f) {
switch(f.h) {
case 1:
b = 0;
@@ -1305,9 +1305,9 @@ v.keys = T.prototype.keys = function Va() {
}
});
};
-v.entries = T.prototype.entries = function Wa() {
+u.entries = U.prototype.entries = function Va() {
var b, c = this, d, e, g;
- return qa(Wa, function(f) {
+ return qa(Va, function(f) {
switch(f.h) {
case 1:
b = 0;
@@ -1331,7 +1331,7 @@ v.entries = T.prototype.entries = function Wa() {
}
});
};
-function Ta(a) {
+function Sa(a) {
var b = Math.pow(2, this.A) - 1;
if ("number" == typeof a) {
return a & b;
@@ -1341,37 +1341,35 @@ function Ta(a) {
}
return 32 === this.A ? c + Math.pow(2, 31) : c;
}
-function Sa() {
+function Ra() {
throw Error("The keystore is limited to 32 for EcmaScript5");
}
-;function Xa(a, b, c, d, e, g, f, h) {
+;function Wa(a, b, c, d, e, g, f, h) {
(d = a(c ? c + "." + d : d, JSON.stringify(f))) && d.then ? d.then(function() {
b.export(a, b, c, e, g + 1, h);
}) : b.export(a, b, c, e, g + 1, h);
}
-;var Ya = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}};
-function Za(a) {
- U.call(a, "add");
- U.call(a, "append");
- U.call(a, "search");
- U.call(a, "update");
- U.call(a, "remove");
+;var Xa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}};
+function Ya(a) {
+ Za.call(a, "add");
+ Za.call(a, "append");
+ Za.call(a, "search");
+ Za.call(a, "update");
+ Za.call(a, "remove");
}
-function U(a) {
+function Za(a) {
this[a + "Async"] = function() {
var b = arguments, c = b[b.length - 1];
if ("function" === typeof c) {
var d = c;
delete b[b.length - 1];
}
- this.async = !0;
b = this[a].apply(this, b);
- this.async = !1;
d && (b.then ? b.then(d) : d(b));
return b;
};
}
-;K();
+;L();
V.prototype.add = function(a, b, c, d) {
if (b && (a || 0 === a)) {
if (!d && !c && this.reg.has(a)) {
@@ -1379,7 +1377,7 @@ V.prototype.add = function(a, b, c, d) {
}
b = this.encoder.encode(b);
if (d = b.length) {
- for (var e = K(), g = K(), f = this.depth, h = this.resolution, k = 0; k < d; k++) {
+ for (var e = L(), g = L(), f = this.depth, h = this.resolution, k = 0; k < d; k++) {
var l = b[this.rtl ? d - 1 - k : k], m = l.length;
if (m && (f || !g[l])) {
var n = this.score ? this.score(b, l, k, null, 0) : $a(h, d, k), p = "";
@@ -1411,11 +1409,11 @@ V.prototype.add = function(a, b, c, d) {
}
default:
if (ab(this, g, l, n, a, c), f && 1 < d && k < d - 1) {
- for (m = K(), p = this.aa, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) {
+ for (m = L(), p = this.ba, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) {
if ((l = b[this.rtl ? d - 1 - k - r : k + r]) && !m[l]) {
m[l] = 1;
- var y = this.score ? this.score(b, n, k, l, r) : $a(p + (d / 2 > p ? 0 : 1), d, k, q - 1, r - 1), u = this.bidirectional && l > n;
- ab(this, e, u ? n : l, y, a, c, u ? l : n);
+ var y = this.score ? this.score(b, n, k, l, r) : $a(p + (d / 2 > p ? 0 : 1), d, k, q - 1, r - 1), v = this.bidirectional && l > n;
+ ab(this, e, v ? n : l, y, a, c, v ? l : n);
}
}
}
@@ -1427,15 +1425,15 @@ V.prototype.add = function(a, b, c, d) {
b = "";
}
}
- this.db && (b || this.commit_task.push({del:a}), this.da && bb(this));
+ this.db && (b || this.commit_task.push({del:a}), this.ea && bb(this));
return this;
};
function ab(a, b, c, d, e, g, f) {
var h = f ? a.ctx : a.map, k;
if (!b[c] || !f || !(k = b[c])[f]) {
- if (f ? (b = k || (b[c] = K()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) {
+ if (f ? (b = k || (b[c] = L()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) {
if (h.length === Math.pow(2, 31) - 1) {
- b = new R(h);
+ b = new S(h);
if (a.fastupdate) {
for (c = x(a.reg.values()), g = c.next(); !g.done; g = c.next()) {
g = g.value, g.includes(h) && (g[g.indexOf(h)] = b);
@@ -1548,7 +1546,7 @@ function db(a, b, c, d, e, g) {
return e ? W(a[0], b, c, d) : a[0];
}
d = [];
- for (var f = 0, h = K(), k = za(a), l = 0, m; l < k; l++) {
+ for (var f = 0, h = L(), k = ya(a), l = 0, m; l < k; l++) {
for (var n = 0; n < a.length; n++) {
if (m = a[n]) {
if (m = m[l]) {
@@ -1631,7 +1629,7 @@ function eb(a, b, c, d, e) {
if (2 > a.length) {
return [];
}
- var g = [], f = 0, h = K(), k = za(a);
+ var g = [], f = 0, h = L(), k = ya(a);
if (!k) {
return g;
}
@@ -1640,10 +1638,10 @@ function eb(a, b, c, d, e) {
if (!m || !m.length) {
return [];
}
- for (var n = K(), p = 0, q = l === a.length - 1, r = 0, y; r < k; r++) {
+ for (var n = L(), p = 0, q = l === a.length - 1, r = 0, y; r < k; r++) {
if (y = m[r]) {
- for (var u = 0, t, w; u < y.length; u++) {
- if (t = y[u], !l) {
+ for (var v = 0, t, w; v < y.length; v++) {
+ if (t = y[v], !l) {
n[t] = r + 1 + (l ? e : 0), p = 1;
} else if (q) {
if (w = h[t]) {
@@ -1725,7 +1723,7 @@ function fb(a, b, c, d, e, g) {
return e ? W(a[0], b, c, d) : a[0];
}
b = [];
- c = K();
+ c = L();
d = 0;
for (var f; d < a.length; d++) {
if (f = a[d]) {
@@ -1867,7 +1865,7 @@ X.prototype.resolve = function(a, b, c) {
};
function ib(a, b, c, d, e) {
var g = a.length, f = [], h;
- var k = K();
+ var k = L();
for (var l = 0, m = void 0, n; l < b; l++) {
for (var p = 0; p < g; p++) {
if (n = a[p], l < n.length && (m = n[l])) {
@@ -1882,7 +1880,7 @@ function ib(a, b, c, d, e) {
if (1 < f.length) {
e = f;
g = [];
- f = K();
+ f = L();
k = e.length;
for (m = 0; m < k; m++) {
for (a = e[m], l = a.length, p = 0; p < l; p++) {
@@ -1915,7 +1913,7 @@ function ib(a, b, c, d, e) {
return f;
}
function jb(a, b) {
- for (var c = K(), d = [], e = 0, g; e < b.length; e++) {
+ for (var c = L(), d = [], e = 0, g; e < b.length; e++) {
g = b[e];
for (var f = 0; f < g.length; f++) {
c[g[f]] = 1;
@@ -1928,7 +1926,7 @@ function jb(a, b) {
}
;var hb = 1;
V.prototype.search = function(a, b, c) {
- c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0));
+ c || (!b && N(a) ? (c = a, a = "") : N(b) && (c = b, b = 0));
var d = [], e = 0, g;
if (c) {
a = c.query || a;
@@ -1954,7 +1952,7 @@ V.prototype.search = function(a, b, c) {
}
var n = c = 0;
if (1 < m) {
- for (var p = K(), q = [], r = 0, y = void 0; r < m; r++) {
+ for (var p = L(), q = [], r = 0, y = void 0; r < m; r++) {
if ((y = a[r]) && !p[y]) {
if (h || this.db || Y(this, y)) {
q.push(y), p[y] = 1;
@@ -1972,7 +1970,7 @@ V.prototype.search = function(a, b, c) {
if (!m) {
return g ? d : new X(d);
}
- var u = 0;
+ var v = 0;
if (1 === m) {
return kb.call(this, a[0], "", b, e, g, k, l);
}
@@ -1982,9 +1980,9 @@ V.prototype.search = function(a, b, c) {
if (1 < m) {
if (f) {
var t = a[0];
- u = 1;
+ v = 1;
} else {
- 9 < c && 3 < c / n && a.sort(wa);
+ 9 < c && 3 < c / n && a.sort(va);
}
}
if (this.db) {
@@ -1994,34 +1992,34 @@ V.prototype.search = function(a, b, c) {
var w = this;
return function() {
var A, D, B;
- return sa(function(E) {
+ return H(function(E) {
switch(E.h) {
case 1:
D = A = void 0;
case 2:
- if (!(u < m)) {
+ if (!(v < m)) {
E.h = 4;
break;
}
- D = a[u];
+ D = a[v];
return t ? F(E, Y(w, D, t), 8) : F(E, Y(w, D), 7);
case 7:
- A = E.F;
+ A = E.D;
A = lb(A, d, h, w.resolution, b, e, 1 === m);
E.h = 6;
break;
case 8:
- A = E.F, A = lb(A, d, h, w.aa, b, e, 2 === m), h && !1 === A && d.length || (t = D);
+ A = E.D, A = lb(A, d, h, w.ba, b, e, 2 === m), h && !1 === A && d.length || (t = D);
case 6:
if (A) {
return E.return(A);
}
- if (h && u === m - 1) {
+ if (h && v === m - 1) {
B = d.length;
if (!B) {
if (t) {
t = "";
- u = -1;
+ v = -1;
E.h = 3;
break;
}
@@ -2032,7 +2030,7 @@ V.prototype.search = function(a, b, c) {
}
}
case 3:
- u++;
+ v++;
E.h = 2;
break;
case 4:
@@ -2041,18 +2039,18 @@ V.prototype.search = function(a, b, c) {
});
}();
}
- for (k = f = void 0; u < m; u++) {
- k = a[u];
- t ? (f = Y(this, k, t), f = lb(f, d, h, this.aa, b, e, 2 === m), h && !1 === f && d.length || (t = k)) : (f = Y(this, k), f = lb(f, d, h, this.resolution, b, e, 1 === m));
+ for (k = f = void 0; v < m; v++) {
+ k = a[v];
+ t ? (f = Y(this, k, t), f = lb(f, d, h, this.ba, b, e, 2 === m), h && !1 === f && d.length || (t = k)) : (f = Y(this, k), f = lb(f, d, h, this.resolution, b, e, 1 === m));
if (f) {
return f;
}
- if (h && u === m - 1) {
+ if (h && v === m - 1) {
f = d.length;
if (!f) {
if (t) {
t = "";
- u = -1;
+ v = -1;
continue;
}
return d;
@@ -2120,7 +2118,7 @@ function Y(a, b, c, d, e, g, f, h) {
}
b || this.reg.delete(a);
}
- this.db && (this.commit_task.push({del:a}), this.da && bb(this));
+ this.db && (this.commit_task.push({del:a}), this.ea && bb(this));
this.cache && this.cache.remove(a);
return this;
};
@@ -2149,14 +2147,14 @@ function mb(a, b) {
return new V(a);
}
if (a) {
- var c = L(a) ? a : a.preset;
- c && (Ya[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ya[c], a));
+ var c = M(a) ? a : a.preset;
+ c && (Xa[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Xa[c], a));
} else {
a = {};
}
c = a.context || {};
- var d = a.encode || a.encoder || Ia;
- this.encoder = d.encode ? d : "object" === typeof d ? new N(d) : {encode:d};
+ var d = a.encode || a.encoder || Ha;
+ this.encoder = d.encode ? d : "object" === typeof d ? new Q(d) : {encode:d};
var e;
this.resolution = a.resolution || 9;
this.tokenize = e = a.tokenize || "strict";
@@ -2165,36 +2163,40 @@ function mb(a, b) {
this.fastupdate = !!a.fastupdate;
this.score = a.score || null;
(e = a.keystore || 0) && (this.keystore = e);
- this.map = e ? new S(e) : new Map();
- this.ctx = e ? new S(e) : new Map();
- this.reg = b || (this.fastupdate ? e ? new S(e) : new Map() : e ? new T(e) : new Set());
- this.aa = c.resolution || 1;
+ this.map = e ? new T(e) : new Map();
+ this.ctx = e ? new T(e) : new Map();
+ this.reg = b || (this.fastupdate ? e ? new T(e) : new Map() : e ? new U(e) : new Set());
+ this.ba = c.resolution || 1;
this.rtl = d.rtl || a.rtl || !1;
- this.cache = (e = a.cache || null) && new Q(e);
+ this.cache = (e = a.cache || null) && new R(e);
this.resolve = !1 !== a.resolve;
if (e = a.db) {
this.db = e.mount(this);
}
- this.da = !1 !== a.commit;
+ this.ea = !1 !== a.commit;
this.commit_task = [];
this.commit_timer = null;
}
-v = V.prototype;
-v.mount = function(a) {
+u = V.prototype;
+u.mount = function(a) {
this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
return a.mount(this);
};
-v.commit = function(a, b) {
+u.commit = function(a, b) {
this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
return this.db.commit(this, a, b);
};
+u.destroy = function() {
+ this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
+ return this.db.destroy();
+};
function bb(a) {
a.commit_timer || (a.commit_timer = setTimeout(function() {
a.commit_timer = null;
a.db.commit(a, void 0, void 0);
}, 0));
}
-v.clear = function() {
+u.clear = function() {
this.map.clear();
this.ctx.clear();
this.reg.clear();
@@ -2202,20 +2204,17 @@ v.clear = function() {
this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]);
return this;
};
-v.append = function(a, b) {
+u.append = function(a, b) {
return this.add(a, b, !0);
};
-v.contain = function(a) {
+u.contain = function(a) {
return this.db ? this.db.has(a) : this.reg.has(a);
};
-v.update = function(a, b) {
- if (this.async) {
- var c = this, d = this.remove(a);
- return d.then ? d.then(function() {
- return c.add(a, b);
- }) : this.add(a, b);
- }
- return this.remove(a).add(a, b);
+u.update = function(a, b) {
+ var c = this, d = this.remove(a);
+ return d && d.then ? d.then(function() {
+ return c.add(a, b);
+ }) : this.add(a, b);
};
function nb(a) {
var b = 0;
@@ -2232,7 +2231,7 @@ function nb(a) {
}
return b;
}
-v.cleanup = function() {
+u.cleanup = function() {
if (!this.fastupdate) {
return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this;
}
@@ -2240,8 +2239,8 @@ v.cleanup = function() {
this.depth && nb(this.ctx);
return this;
};
-v.searchCache = Ha;
-v.export = function(a, b, c, d, e, g) {
+u.searchCache = Ga;
+u.export = function(a, b, c, d, e, g) {
var f = !0;
"undefined" === typeof g && (f = new Promise(function(n) {
g = n;
@@ -2250,7 +2249,7 @@ v.export = function(a, b, c, d, e, g) {
case 0:
var h = "reg";
if (this.fastupdate) {
- var k = K();
+ var k = L();
for (var l = x(this.reg.keys()), m = l.next(); !m.done; m = l.next()) {
k[m.value] = 1;
}
@@ -2274,12 +2273,12 @@ v.export = function(a, b, c, d, e, g) {
"undefined" === typeof c && g && g();
return;
}
- Xa(a, b || this, c, h, d, e, k, g);
+ Wa(a, b || this, c, h, d, e, k, g);
return f;
};
-v.import = function(a, b) {
+u.import = function(a, b) {
if (b) {
- switch(L(b) && (b = JSON.parse(b)), a) {
+ switch(M(b) && (b = JSON.parse(b)), a) {
case "cfg":
this.h = !!b.opt;
break;
@@ -2295,7 +2294,7 @@ v.import = function(a, b) {
}
}
};
-v.serialize = function(a) {
+u.serialize = function(a) {
a = void 0 === a ? !0 : a;
if (!this.reg.size) {
return "";
@@ -2347,10 +2346,10 @@ v.serialize = function(a) {
e = "index.ctx=new Map([" + e + "]);";
return a ? "function inject(index){" + b + d + e + "}" : b + d + e;
};
-Za(V.prototype);
+Ya(V.prototype);
function ob(a) {
var b, c, d, e, g, f, h, k;
- return sa(function(l) {
+ return H(function(l) {
a = a.data;
b = self._index;
c = a.args;
@@ -2370,32 +2369,42 @@ function ob(a) {
}
;var pb = 0;
function qb(a) {
- function b(g) {
- g = g.data || g;
- var f = g.id, h = f && e.h[f];
- h && (h(g.msg), delete e.h[f]);
- }
if (!this) {
return new qb(a);
}
a || (a = {});
- var c = (self || window)._factory;
- c && (c = c.toString());
- var d = "undefined" === typeof window && self.exports, e = this;
- this.worker = rb(c, d, a.worker);
- this.h = K();
- if (this.worker) {
- d ? this.worker.on("message", b) : this.worker.onmessage = b;
- if (a.config) {
- return new Promise(function(g) {
- e.h[++pb] = function() {
- g(e);
- };
- e.worker.postMessage({id:pb, task:"init", factory:c, options:a});
- });
+ var b = "undefined" !== typeof self && (self || window)._factory;
+ b && (b = b.toString());
+ var c = "undefined" === typeof window, d = this;
+ (function() {
+ function e(f) {
+ f = f.data || f;
+ var h = f.id, k = h && d.$[h];
+ k && (k(f.msg), delete d.$[h]);
}
- this.worker.postMessage({task:"init", factory:c, options:a});
- }
+ var g = this;
+ return H(function(f) {
+ if (1 == f.h) {
+ return F(f, rb(b, c, a.worker), 2);
+ }
+ g.worker = f.D;
+ g.$ = L();
+ if (!g.worker) {
+ return f.return();
+ }
+ c ? g.worker.on("message", e) : g.worker.onmessage = e;
+ if (a.config) {
+ return delete a.db, f.return(new Promise(function(h) {
+ d.$[++pb] = function() {
+ h(d);
+ };
+ d.worker.postMessage({id:pb, task:"init", factory:b, options:a});
+ }));
+ }
+ g.worker.postMessage({task:"init", factory:b, options:a});
+ f.h = 0;
+ });
+ }).call(this);
}
sb("add");
sb("append");
@@ -2410,17 +2419,21 @@ function sb(a) {
c.splice(c.length - 1, 1);
}
d = new Promise(function(g) {
- b.h[++pb] = g;
+ b.$[++pb] = g;
b.worker.postMessage({task:a, id:pb, args:c});
});
return e ? (d.then(e), this) : d;
};
}
function rb(a, b, c) {
- return b ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ob.toString()], {type:"text/javascript"}))) : new window.Worker(L(c) ? c : "worker/worker.js", {type:"module"});
+ var d;
+ return H(function(e) {
+ d = b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : new ((await import("worker_threads"))["Worker"])((1,eval)("import.meta.dirname") + "/node/node.mjs") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ob.toString()], {type:"text/javascript"}))) : new window.Worker(M(c) ? c : "worker/worker.js", {type:"module"});
+ return e.return(d);
+ });
}
;Z.prototype.add = function(a, b, c) {
- M(a) && (b = a, a = ya(b, this.key));
+ N(a) && (b = a, a = xa(b, this.key));
if (b && (a || 0 === a)) {
if (!c && this.reg.has(a)) {
return this.update(a, b);
@@ -2433,16 +2446,16 @@ function rb(a, b, c) {
} else {
var f = e.R;
if (!f || f(b)) {
- e.constructor === String ? e = ["" + e] : L(e) && (e = [e]), tb(b, e, this.T, 0, g, a, e[0], c);
+ e.constructor === String ? e = ["" + e] : M(e) && (e = [e]), tb(b, e, this.T, 0, g, a, e[0], c);
}
}
}
if (this.tag) {
for (d = 0; d < this.L.length; d++) {
f = this.L[d];
- var h = this.$[d];
+ var h = this.aa[d];
g = this.tag.get(h);
- e = K();
+ e = L();
if ("function" === typeof f) {
if (f = f(b), !f) {
continue;
@@ -2453,10 +2466,10 @@ function rb(a, b, c) {
continue;
}
f.constructor === String && (f = "" + f);
- f = ya(b, f);
+ f = xa(b, f);
}
if (g && f) {
- for (L(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) {
+ for (M(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) {
var l = f[h];
if (!e[l]) {
e[l] = 1;
@@ -2464,7 +2477,7 @@ function rb(a, b, c) {
(m = g.get(l)) ? k = m : g.set(l, k = []);
if (!c || !k.includes(a)) {
if (k.length === Math.pow(2, 31) - 1) {
- m = new R(k);
+ m = new S(k);
if (this.fastupdate) {
for (var n = x(this.reg.values()), p = n.next(); !p.done; p = n.next()) {
p = p.value, p.includes(k) && (p[p.indexOf(k)] = m);
@@ -2484,7 +2497,7 @@ function rb(a, b, c) {
}
if (this.store && (!c || !this.store.has(a))) {
if (this.H) {
- var q = K();
+ var q = L();
for (c = 0; c < this.H.length; c++) {
if (d = this.H[c], g = d.R, !g || g(b)) {
g = void 0;
@@ -2493,8 +2506,8 @@ function rb(a, b, c) {
if (!g) {
continue;
}
- d = [d.la];
- } else if (L(d) || d.constructor === String) {
+ d = [d.ma];
+ } else if (M(d) || d.constructor === String) {
q[d] = b[d];
continue;
}
@@ -2517,7 +2530,7 @@ function ub(a, b, c, d, e, g) {
ub(a, b, c, d, e);
}
} else {
- b = b[e] || (b[e] = K()), e = c[++d], ub(a, b, c, d, e);
+ b = b[e] || (b[e] = L()), e = c[++d], ub(a, b, c, d, e);
}
}
}
@@ -2548,7 +2561,7 @@ function tb(a, b, c, d, e, g, f, h) {
}
}
;Z.prototype.search = function(a, b, c, d) {
- c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0));
+ c || (!b && N(a) ? (c = a, a = "") : N(b) && (c = b, b = 0));
var e = [], g = [], f = 0;
if (c) {
c.constructor === Array && (c = {index:c});
@@ -2564,25 +2577,25 @@ function tb(a, b, c, d, e, g, f, h) {
b || (b = 100);
if (m && (!this.db || !d)) {
m.constructor !== Array && (m = [m]);
- for (var r = [], y = 0, u = void 0; y < m.length; y++) {
- u = m[y];
- if (L(u)) {
+ for (var r = [], y = 0, v = void 0; y < m.length; y++) {
+ v = m[y];
+ if (M(v)) {
throw Error("A tag option can't be a string, instead it needs a { field: tag } format.");
}
- if (u.field && u.tag) {
- var t = u.tag;
+ if (v.field && v.tag) {
+ var t = v.tag;
if (t.constructor === Array) {
for (var w = 0; w < t.length; w++) {
- r.push(u.field, t[w]);
+ r.push(v.field, t[w]);
}
} else {
- r.push(u.field, t);
+ r.push(v.field, t);
}
} else {
- t = Object.keys(u);
+ t = Object.keys(v);
w = 0;
for (var A = void 0, D = void 0; w < t.length; w++) {
- if (A = t[w], D = u[A], D.constructor === Array) {
+ if (A = t[w], D = v[A], D.constructor === Array) {
for (var B = 0; B < D.length; B++) {
r.push(A, D[B]);
}
@@ -2622,20 +2635,20 @@ function tb(a, b, c, d, e, g, f, h) {
}) : e;
}
}
- L(l) && (l = [l]);
+ M(l) && (l = [l]);
}
l || (l = this.field);
- r = !d && (this.worker || this.async) && [];
+ r = !d && (this.worker || this.db) && [];
y = 0;
- for (w = u = t = void 0; y < l.length; y++) {
- if (u = l[y], !this.db || !this.tag || this.M[y]) {
+ for (w = v = t = void 0; y < l.length; y++) {
+ if (v = l[y], !this.db || !this.tag || this.M[y]) {
t = void 0;
- L(u) || (t = u, u = t.field, a = t.query || a, b = t.limit || b, p = t.suggest || p);
+ M(v) || (t = v, v = t.field, a = t.query || a, b = t.limit || b, p = t.suggest || p);
if (d) {
t = d[y];
} else {
w = t || c;
- t = this.index.get(u);
+ t = this.index.get(v);
if (m) {
if (this.db) {
w.tag = m;
@@ -2695,7 +2708,7 @@ function tb(a, b, c, d, e, g, f, h) {
}
}
if (w) {
- g[f] = u, e.push(t), f++;
+ g[f] = v, e.push(t), f++;
} else if (1 === l.length) {
return e;
}
@@ -2744,7 +2757,7 @@ function tb(a, b, c, d, e, g, f, h) {
}) : k ? xb(e, b) : e;
};
function xb(a, b) {
- for (var c = [], d = K(), e = 0, g, f; e < a.length; e++) {
+ for (var c = [], d = L(), e = 0, g, f; e < a.length; e++) {
g = a[e];
f = g.result;
for (var h = 0, k, l, m; h < f.length; h++) {
@@ -2790,20 +2803,19 @@ function wb(a) {
this.T = [];
this.key = (c = b.key || b.id) && yb(c, this.T) || "id";
(d = a.keystore || 0) && (this.keystore = d);
- this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new S(d) : new Map() : d ? new T(d) : new Set();
+ this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new T(d) : new Map() : d ? new U(d) : new Set();
this.H = (c = b.store || null) && !0 !== c && [];
- this.store = c && (d ? new S(d) : new Map());
- this.cache = (c = a.cache || null) && new Q(c);
+ this.store = c && (d ? new T(d) : new Map());
+ this.cache = (c = a.cache || null) && new R(c);
a.cache = !1;
this.worker = a.worker;
- this.async = !1;
c = new Map();
d = b.index || b.field || b;
- L(d) && (d = [d]);
+ M(d) && (d = [d]);
for (var e = 0, g, f = void 0; e < d.length; e++) {
g = d[e];
- L(g) || (f = g, g = g.field);
- f = M(f) ? Object.assign({}, a, f) : a;
+ M(g) || (f = g, g = g.field);
+ f = N(f) ? Object.assign({}, a, f) : a;
if (this.worker) {
var h = new qb(f);
c.set(g, h);
@@ -2814,36 +2826,38 @@ function wb(a) {
this.field[e] = g;
}
if (this.H) {
- for (d = b.store, L(d) && (d = [d]), e = 0; e < d.length; e++) {
- g = d[e], f = g.field || g, g.custom ? (this.H[e] = g.custom, g.custom.la = f) : (this.H[e] = yb(f, this.T), g.filter && ("string" === typeof this.H[e] && (this.H[e] = new String(this.H[e])), this.H[e].R = g.filter));
+ for (d = b.store, M(d) && (d = [d]), e = 0; e < d.length; e++) {
+ g = d[e], f = g.field || g, g.custom ? (this.H[e] = g.custom, g.custom.ma = f) : (this.H[e] = yb(f, this.T), g.filter && ("string" === typeof this.H[e] && (this.H[e] = new String(this.H[e])), this.H[e].R = g.filter));
}
}
this.index = c;
this.tag = null;
if (c = b.tag) {
if ("string" === typeof c && (c = [c]), c.length) {
- for (this.tag = new Map(), this.L = [], this.$ = [], b = 0; b < c.length; b++) {
+ for (this.tag = new Map(), this.L = [], this.aa = [], b = 0; b < c.length; b++) {
d = c[b];
e = d.field || d;
if (!e) {
throw Error("The tag field from the document descriptor is undefined.");
}
d.custom ? this.L[b] = d.custom : (this.L[b] = yb(e, this.T), d.filter && ("string" === typeof this.L[b] && (this.L[b] = new String(this.L[b])), this.L[b].R = d.filter));
- this.$[b] = e;
+ this.aa[b] = e;
this.tag.set(e, new Map());
}
}
}
a.db && this.mount(a.db);
}
-v = Z.prototype;
-v.mount = function(a) {
+u = Z.prototype;
+u.mount = function(a) {
var b = this.field;
if (this.tag) {
- for (var c = 0, d; c < this.$.length; c++) {
- d = this.$[c];
- var e = this.index.get(d);
- e || (this.index.set(d, e = new V({}, this.reg)), b === this.field && (b = b.slice(0)), b.push(d));
+ for (var c = 0, d; c < this.aa.length; c++) {
+ d = this.aa[c];
+ var e;
+ this.index.set(d, e = new V({}, this.reg));
+ b === this.field && (b = b.slice(0));
+ b.push(d);
e.tag = this.tag.get(d);
}
}
@@ -2859,12 +2873,12 @@ v.mount = function(a) {
g.document = !0;
e ? g.bypass = !0 : g.store = this.store;
}
- this.db = this.async = !0;
+ this.db = !0;
return Promise.all(c);
};
-v.commit = function(a, b) {
+u.commit = function(a, b) {
var c = this, d, e, g, f;
- return sa(function(h) {
+ return H(function(h) {
if (1 == h.h) {
d = [];
e = x(c.index.values());
@@ -2877,6 +2891,12 @@ v.commit = function(a, b) {
h.h = 0;
});
};
+u.destroy = function() {
+ for (var a = [], b = x(this.index.values()), c = b.next(); !c.done; c = b.next()) {
+ a.push(c.value.destroy());
+ }
+ return Promise.all(a);
+};
function yb(a, b) {
for (var c = a.split(":"), d = 0, e = 0; e < c.length; e++) {
a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a);
@@ -2884,14 +2904,14 @@ function yb(a, b) {
d < c.length && (c.length = d);
return 1 < d ? c : c[0];
}
-v.append = function(a, b) {
+u.append = function(a, b) {
return this.add(a, b, !0);
};
-v.update = function(a, b) {
+u.update = function(a, b) {
return this.remove(a).add(a, b);
};
-v.remove = function(a) {
- M(a) && (a = ya(a, this.key));
+u.remove = function(a) {
+ N(a) && (a = xa(a, this.key));
for (var b = x(this.index.values()), c = b.next(); !c.done; c = b.next()) {
c.value.remove(a, !0);
}
@@ -2914,7 +2934,7 @@ v.remove = function(a) {
this.cache && this.cache.remove(a);
return this;
};
-v.clear = function() {
+u.clear = function() {
for (var a = x(this.index.values()), b = a.next(); !b.done; b = a.next()) {
b.value.clear();
}
@@ -2926,26 +2946,26 @@ v.clear = function() {
this.store && this.store.clear();
return this;
};
-v.contain = function(a) {
+u.contain = function(a) {
return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a);
};
-v.cleanup = function() {
+u.cleanup = function() {
for (var a = x(this.index.values()), b = a.next(); !b.done; b = a.next()) {
b.value.cleanup();
}
return this;
};
-v.get = function(a) {
+u.get = function(a) {
return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) {
return b[0] && b[0].doc;
}) : this.store.get(a);
};
-v.set = function(a, b) {
+u.set = function(a, b) {
this.store.set(a, b);
return this;
};
-v.searchCache = Ha;
-v.export = function(a, b, c, d, e, g) {
+u.searchCache = Ga;
+u.export = function(a, b, c, d, e, g) {
var f;
"undefined" === typeof g && (f = new Promise(function(k) {
g = k;
@@ -2973,13 +2993,13 @@ v.export = function(a, b, c, d, e, g) {
g();
return;
}
- Xa(a, this, c, b, d, e, h, g);
+ Wa(a, this, c, b, d, e, h, g);
}
return f;
};
-v.import = function(a, b) {
+u.import = function(a, b) {
if (b) {
- switch(L(b) && (b = JSON.parse(b)), a) {
+ switch(M(b) && (b = JSON.parse(b)), a) {
case "tag":
this.A = b;
break;
@@ -2999,7 +3019,7 @@ v.import = function(a, b) {
}
}
};
-Za(Z.prototype);
+Ya(Z.prototype);
var zb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ab = ["map", "ctx", "tag", "reg", "cfg"];
function Bb(a, b) {
b = void 0 === b ? {} : b;
@@ -3014,15 +3034,15 @@ function Bb(a, b) {
this.db = null;
this.h = {};
}
-v = Bb.prototype;
-v.mount = function(a) {
+u = Bb.prototype;
+u.mount = function(a) {
if (a.constructor === Z) {
return a.mount(this);
}
a.db = this;
return this.open();
};
-v.open = function() {
+u.open = function() {
var a = this;
navigator.storage && navigator.storage.persist();
return this.db || new Promise(function(b, c) {
@@ -3050,21 +3070,20 @@ v.open = function() {
};
});
};
-v.close = function() {
+u.close = function() {
this.db.close();
this.db = null;
};
-v.destroy = function() {
- this.db && this.close();
+u.destroy = function() {
return zb.deleteDatabase(this.id + (this.field ? ":" + this.field : ""));
};
-v.clear = function() {
+u.clear = function() {
for (var a = this.db.transaction(Ab, "readwrite"), b = 0; b < Ab.length; b++) {
a.objectStore(Ab[b]).clear();
}
return Cb(a);
};
-v.get = function(a, b, c, d, e, g) {
+u.get = function(a, b, c, d, e, g) {
c = void 0 === c ? 0 : c;
d = void 0 === d ? 0 : d;
e = void 0 === e ? !0 : e;
@@ -3100,7 +3119,7 @@ v.get = function(a, b, c, d, e, g) {
return h;
});
};
-v.tag = function(a, b, c, d) {
+u.tag = function(a, b, c, d) {
b = void 0 === b ? 0 : b;
c = void 0 === c ? 0 : c;
d = void 0 === d ? !1 : d;
@@ -3117,7 +3136,7 @@ v.tag = function(a, b, c, d) {
return d ? e.enrich(g) : g;
});
};
-v.enrich = function(a) {
+u.enrich = function(a) {
"object" !== typeof a && (a = [a]);
for (var b = this.db.transaction("reg", "readonly").objectStore("reg"), c = [], d = 0; d < a.length; d++) {
c[d] = Cb(b.get(a[d]));
@@ -3129,14 +3148,14 @@ v.enrich = function(a) {
return e;
});
};
-v.has = function(a) {
+u.has = function(a) {
a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a);
return Cb(a);
};
-v.search = null;
-v.info = function() {
+u.search = null;
+u.info = function() {
};
-v.transaction = function(a, b, c) {
+u.transaction = function(a, b, c) {
var d = this, e = this.h[a + ":" + b];
if (e) {
return c.call(this, e);
@@ -3157,9 +3176,9 @@ v.transaction = function(a, b, c) {
return c.call(d, e);
});
};
-v.commit = function(a, b, c) {
+u.commit = function(a, b, c) {
var d = this, e, g, f;
- return sa(function(h) {
+ return H(function(h) {
switch(h.h) {
case 1:
if (b) {
@@ -3176,7 +3195,7 @@ v.commit = function(a, b, c) {
}
f = e[g];
if (!f.clear) {
- e[g] = f.oa;
+ e[g] = f.pa;
h.h = 5;
break;
}
@@ -3194,7 +3213,7 @@ v.commit = function(a, b, c) {
h.h = 3;
break;
}
- c || (e = e.concat(xa(a.reg)));
+ c || (e = e.concat(wa(a.reg)));
if (!e.length) {
h.h = 10;
break;
@@ -3213,14 +3232,14 @@ v.commit = function(a, b, c) {
return function() {
var q = this.result, r;
if (q && q.length) {
- for (var y = Math.max(q.length, p.O.length), u = 0, t; u < y; u++) {
- if ((t = p.O[u]) && t.length) {
- if ((r = q[u]) && r.length) {
+ for (var y = Math.max(q.length, p.O.length), v = 0, t; v < y; v++) {
+ if ((t = p.O[v]) && t.length) {
+ if ((r = q[v]) && r.length) {
for (var w = 0; w < t.length; w++) {
r.push(t[w]);
}
} else {
- q[u] = t;
+ q[v] = t;
}
r = 1;
}
@@ -3242,24 +3261,24 @@ v.commit = function(a, b, c) {
for (var p = m.next(), q = {}; !p.done; q = {P:void 0, Z:void 0}, p = m.next()) {
p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? k.put(q.P, n.W + ":" + q.Z) : k.get(n.W + ":" + q.Z).onsuccess = function(r, y) {
return function() {
- var u = this.result, t;
- if (u && u.length) {
- for (var w = Math.max(u.length, r.P.length), A = 0, D; A < w; A++) {
+ var v = this.result, t;
+ if (v && v.length) {
+ for (var w = Math.max(v.length, r.P.length), A = 0, D; A < w; A++) {
if ((D = r.P[A]) && D.length) {
- if ((t = u[A]) && t.length) {
+ if ((t = v[A]) && t.length) {
for (var B = 0; B < D.length; B++) {
t.push(D[B]);
}
} else {
- u[A] = D;
+ v[A] = D;
}
t = 1;
}
}
} else {
- u = r.P, t = 1;
+ v = r.P, t = 1;
}
- t && k.put(u, y.W + ":" + r.Z);
+ t && k.put(v, y.W + ":" + r.Z);
};
}(q, n));
}
@@ -3291,12 +3310,12 @@ v.commit = function(a, b, c) {
break;
}
return F(h, d.transaction("tag", "readwrite", function(k) {
- for (var l = x(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) {
- m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (k.get(n.ba).onsuccess = function(p) {
+ for (var l = x(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ca:void 0}, m = l.next()) {
+ m = m.value, n.ca = m[0], n.X = m[1], n.X.length && (k.get(n.ca).onsuccess = function(p) {
return function() {
var q = this.result;
q = q && q.length ? q.concat(p.X) : p.X;
- k.put(q, p.ba);
+ k.put(q, p.ca);
};
}(n));
}
@@ -3328,7 +3347,7 @@ function Db(a, b, c) {
f ? e && a.update(d) : a.delete();
a.continue();
}
-v.remove = function(a) {
+u.remove = function(a) {
"object" !== typeof a && (a = [a]);
return Promise.all([this.transaction("map", "readwrite", function(b) {
b.openCursor().onsuccess = function() {
@@ -3363,7 +3382,7 @@ function Cb(a) {
a = null;
});
}
-;var Eb = {Index:V, Charset:Qa, Encoder:N, Document:Z, Worker:qb, Resolver:X, IndexedDB:Bb, Language:{}}, Fb = self, Gb;
+;var Eb = {Index:V, Charset:Pa, Encoder:Q, Document:Z, Worker:qb, Resolver:X, IndexedDB:Bb, Language:{}}, Fb = self, Gb;
(Gb = Fb.define) && Gb.amd ? Gb([], function() {
return Eb;
}) : "object" === typeof Fb.exports ? Fb.exports = Eb : Fb.FlexSearch = Eb;
diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js
index f32afb4..e18498d 100644
--- a/dist/flexsearch.es5.min.js
+++ b/dist/flexsearch.es5.min.js
@@ -7,119 +7,119 @@
*/
(function(self){'use strict';var u;function aa(a){var b=0;return function(){return b>>0)+"_",e=0;return b});
-B("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;cc&&(c=Math.max(c+e,0));cthis.J&&(this.S.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.h&&(this.N.set(a,d),this.N.size>this.J&&(this.N.clear(),this.h=this.h/1.1|0));return d};function Ga(a){a.U=null;a.N.clear();a.S.clear()};function Ha(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();var d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){var e=this;d.then(function(g){e.cache.set(a,g);return g})}this.cache.set(a,d)}return d}function Q(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}Q.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};
-Q.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Q.prototype.remove=function(a){for(var b=x(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};Q.prototype.clear=function(){this.cache.clear();this.h=""};var Ia={normalize:function(a){return a.toLowerCase()},dedupe:!1};var Ja=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Ka=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),La=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var Ma={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Na=/[\x00-\x7F]+/g;var Oa=/[\x00-\x7F]+/g;var Pa=/[\x00-\x7F]+/g;var Qa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ia,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ja},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ja,replacer:La,matcher:Ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ja,replacer:La.concat([/(?!^)[aeoy]/g,""]),matcher:Ka},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;b=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e}
-function R(a){if(!this)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):$a(h,d,k,m,n);ab(this,g,p,r,a,c)}break}case "reverse":if(1<
-m){for(q=m-1;0p?0:1),d,k,q-1,r-1),v=this.bidirectional&&l>n;ab(this,e,v?n:l,y,a,c,v?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&
-(b||this.commit_task.push({del:a}),this.da&&bb(this));return this};
-function ab(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||!f||!(k=b[c])[f])if(f?(b=k||(b[c]=K()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new R(h);if(a.fastupdate)for(c=x(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}}
+["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]];var Aa=/[^\p{L}\p{N}]+/u,Ba=/(\d{3})/g,Ca=/(\D)(\d{3})/g,Da=/(\d{3})(\D)/g,Ea="".normalize&&/[\u0300-\u036f]/g;function Q(a){if(!this){var b=Function.prototype.bind,c=b.apply,d=[null],e=d.concat;if(arguments instanceof Array)var g=arguments;else{g=x(arguments);for(var f,h=[];!(f=g.next()).done;)h.push(f.value);g=h}return new (c.call(b,Q,e.call(d,g)))}for(b=0;bthis.J&&(this.S.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.h&&(this.N.set(a,d),this.N.size>this.J&&(this.N.clear(),this.h=this.h/1.1|0));return d};function Fa(a){a.U=null;a.N.clear();a.S.clear()};function Ga(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();var d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){var e=this;d.then(function(g){e.cache.set(a,g);return g})}this.cache.set(a,d)}return d}function R(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}R.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};
+R.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};R.prototype.remove=function(a){for(var b=x(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};R.prototype.clear=function(){this.cache.clear();this.h=""};var Ha={normalize:function(a){return a.toLowerCase()},dedupe:!1};var Ia=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Ja=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Ka=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var La={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Ma=/[\x00-\x7F]+/g;var Na=/[\x00-\x7F]+/g;var Oa=/[\x00-\x7F]+/g;var Pa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ha,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ia},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka,matcher:Ja},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka.concat([/(?!^)[aeoy]/g,""]),matcher:Ja},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;b=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e}
+function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):$a(h,d,k,m,n);ab(this,g,p,r,a,c)}break}case "reverse":if(1<
+m){for(q=m-1;0p?0:1),d,k,q-1,r-1),v=this.bidirectional&&l>n;ab(this,e,v?n:l,y,a,c,v?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&
+(b||this.commit_task.push({del:a}),this.ea&&bb(this));return this};
+function ab(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||!f||!(k=b[c])[f])if(f?(b=k||(b[c]=L()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new S(h);if(a.fastupdate)for(c=x(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}}
function $a(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?cb(a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}cb&&(f=f.slice(0,b),h=f.length),e.push(f);else{if(h>=b)return h>b&&(f=f.slice(0,b)),d?cb(f):f;e=[f]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length)return e?W(a[0],b,c,d):a[0];d=[];for(var f=0,h=K(),k=za(a),l=0,m;la.length)return e?W(a[0],b,c,d):a[0];d=[];for(var f=0,h=L(),k=ya(a),l=0,m;la.length)return[];var g=[],f=0,h=K(),k=za(a);if(!k)return g;for(var l=0,m;la.length)return[];var g=[],f=0,h=L(),k=ya(a);if(!k)return g;for(var l=0,m;la.length)return e?W(a[0],b,c,d):a[0];b=[];c=K();d=0;for(var f;da.length)return e?W(a[0],b,c,d):a[0];b=[];c=L();d=0;for(var f;dc||d)f=f.slice(d,c+d)}return f}
-function jb(a,b){for(var c=K(),d=[],e=0,g;e=e)))break;if(h.length){if(f)return W(h,e,0);b.push(h);return}}return!c&&h}function Y(a,b,c,d,e,g,f,h){var k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,g,f,h):a.db.get(b,"",d,e,g,f,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};V.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.da&&bb(this));this.cache&&this.cache.remove(a);return this};
-function mb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;dc||d)f=f.slice(d,c+d)}return f}
+function jb(a,b){for(var c=L(),d=[],e=0,g;e=e)))break;if(h.length){if(f)return W(h,e,0);b.push(h);return}}return!c&&h}function Y(a,b,c,d,e,g,f,h){var k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,g,f,h):a.db.get(b,"",d,e,g,f,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};V.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ea&&bb(this));this.cache&&this.cache.remove(a);return this};
+function mb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;dc||d)a=a.slice(d,d+c);e&&(a=wb.call(this,a));return a}}function wb(a){for(var b=Array(a.length),c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=wb.call(this,a));return a}}function wb(a){for(var b=Array(a.length),c=0,d;c=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})};
u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;dm&&!g&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(g=1),0<=m)if(e=1,1 b.add(a, c)) : this.add(a, c);
- }
- return this.remove(a).add(a, c);
+ const b = this, d = this.remove(a);
+ return d && d.then ? d.then(() => b.add(a, c)) : this.add(a, c);
};
function Q(a) {
let c = 0;
diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js
index e66e1e2..942ce72 100644
--- a/dist/flexsearch.light.min.js
+++ b/dist/flexsearch.light.min.js
@@ -20,6 +20,6 @@ h=Math.max(h,q);k=k?Math.min(k,q):q}a=p;b=a.length}if(!b)return d;m=0;if(1===b)r
l=a.length;b=[];g=u();for(let p=0,r,n,q,A;pc||e)b=b.slice(e,c+e)}d=b}return d};
function M(a,c,b,d){return(a=N(this,a,c))&&a.length?K(a,b,d):[]}function O(a,c,b,d,e,g,f){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,m=0,l;k=e)))break;if(h.length){if(f)return K(h,e,0);c.push(h);return}}return!b&&h}function N(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this};
function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}return this.remove(a).add(a,c)};
+new Map:new Set);this.A=b.resolution||1;this.rtl=d.rtl||a.rtl||!1;this.cache=(e=a.cache||null)&&new E(e)}H.prototype.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};H.prototype.append=function(a,c){return this.add(a,c,!0)};H.prototype.contain=function(a){return this.reg.has(a)};H.prototype.update=function(a,c){const b=this,d=this.remove(a);return d&&d.then?d.then(()=>b.add(a,c)):this.add(a,c)};
function Q(a){let c=0;if(a.constructor===Array)for(let b=0,d;b b.add(a, c)) : this.add(a, c);
- }
- return this.remove(a).add(a, c);
+ const b = this, d = this.remove(a);
+ return d && d.then ? d.then(() => b.add(a, c)) : this.add(a, c);
};
function Q(a) {
let c = 0;
diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js
index 86a7a73..a81dbde 100644
--- a/dist/flexsearch.light.module.min.js
+++ b/dist/flexsearch.light.module.min.js
@@ -14,7 +14,7 @@ n);k=k?Math.min(k,n):n}a=q;b=a.length}if(!b)return d;p=0;if(1===b)return M.call(
b=[];f=t();for(let q=0,r,l,n,y;qc||e)b=b.slice(e,c+e)}d=b}return d};
function M(a,c,b,d){return(a=N(this,a,c))&&a.length?L(a,b,d):[]}function O(a,c,b,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,p=0,m;k=e)))break;if(h.length){if(g)return L(h,e,0);c.push(h);return}}return!b&&h}function N(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===b.length-1?e.pop():e.splice(f,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this};
function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,f;db.add(a,c)):this.add(a,c)}return this.remove(a).add(a,c)};
+this.A=b.resolution||1;this.rtl=d.rtl||a.rtl||!1;this.cache=(e=a.cache||null)&&new v(e)}H.prototype.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};H.prototype.append=function(a,c){return this.add(a,c,!0)};H.prototype.contain=function(a){return this.reg.has(a)};H.prototype.update=function(a,c){const b=this,d=this.remove(a);return d&&d.then?d.then(()=>b.add(a,c)):this.add(a,c)};
function Q(a){let c=0;if(a.constructor===Array)for(let b=0,d;b}
+ * @export
+ */
this.index = parse_descriptor.call(this, options, document);
this.tag = null;
@@ -106,17 +111,17 @@ Document.prototype.mount = function (db) {
// move tags to their field indexes respectively
for (let i = 0, field; i < this.tagfield.length; i++) {
field = this.tagfield[i];
- let index = this.index.get(field);
- if (!index) {
- // create raw index when not exists
- this.index.set(field, index = new Index({}, this.reg));
- // copy and push to the field selection
- if (fields === this.field) {
- fields = fields.slice(0);
- }
- // tag indexes also needs to be upgraded to db instances
- fields.push(field);
+ let index; // = this.index.get(field);
+ //if(!index){
+ // create raw index when not exists
+ this.index.set(field, index = new Index({}, this.reg));
+ // copy and push to the field selection
+ if (fields === this.field) {
+ fields = fields.slice(0);
}
+ // tag indexes also needs to be upgraded to db instances
+ fields.push(field);
+ //}
// assign reference
index.tag = this.tag.get(field);
}
@@ -150,7 +155,7 @@ Document.prototype.mount = function (db) {
}
}
- this.async = !0;
+ //this.async = true;
this.db = !0;
return Promise.all(promises);
};
@@ -170,6 +175,14 @@ Document.prototype.commit = async function (replace, append) {
// this.reg.clear();
};
+Document.prototype.destroy = function () {
+ const promises = [];
+ for (const idx of this.index.values()) {
+ promises.push(idx.destroy());
+ }
+ return Promise.all(promises);
+};
+
/**
* @this Document
*/
diff --git a/dist/module-debug/document/add.js b/dist/module-debug/document/add.js
index 5c826a6..e5b455f 100644
--- a/dist/module-debug/document/add.js
+++ b/dist/module-debug/document/add.js
@@ -34,8 +34,7 @@ Document.prototype.add = function (id, content, _append) {
if ("function" == typeof tree) {
const tmp = tree(content);
if (tmp) {
- index.add(id, tmp, /* suggest */ /* append: */!1, /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/
- /*await rows.hasNext()*/ /*await rows.hasNext()*/);
+ index.add(id, tmp, /* suggest */ /* append: */!1, /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/);
}
} else {
const filter = tree._filter;
diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js
index 9acdb58..1a68f26 100644
--- a/dist/module-debug/document/search.js
+++ b/dist/module-debug/document/search.js
@@ -155,7 +155,7 @@ Document.prototype.search = function (query, limit, options, _resolve) {
}
field || (field = this.field);
- let promises = !_resolve && (this.worker || this.async) && [],
+ let promises = !_resolve && (this.worker || this.db) && [],
db_tag_search;
diff --git a/dist/module-debug/encoder.js b/dist/module-debug/encoder.js
index 677d280..30e5a35 100644
--- a/dist/module-debug/encoder.js
+++ b/dist/module-debug/encoder.js
@@ -79,9 +79,9 @@ Encoder.prototype.assign = function (options) {
* pre-processing string input
* @type {Function|boolean}
*/
- this.normalize = /** @type {Function|boolean} */parse_option(options.normalize, /* tag? */
- /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */
- /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize);
+ this.normalize = /** @type {Function|boolean} */parse_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */
+ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/
+ /*await rows.hasNext()*/, this.normalize);
// {
// letter: true,
@@ -165,8 +165,7 @@ Encoder.prototype.assign = function (options) {
// options
- this.rtl = options.rtl ||
- /* suggest */ /* append: */ /* enrich */!1;
+ this.rtl = options.rtl || /* suggest */ /* append: */ /* enrich */!1;
this.dedupe = parse_option(options.dedupe, !0, this.dedupe);
this.filter = parse_option((tmp = options.filter) && new Set(tmp), null, this.filter);
this.matcher = parse_option((tmp = options.matcher) && new Map(tmp), null, this.matcher);
@@ -421,7 +420,7 @@ Encoder.prototype.encode = function (str) {
//
// // const position = word.length - key.length;
// // if(position > 0 && word.substring(position) === key){
- // // word = word.substring(0, position) + value;
+
// // break;
// // }
// }
diff --git a/dist/module-debug/index.js b/dist/module-debug/index.js
index a52c37a..5dfbbcb 100644
--- a/dist/module-debug/index.js
+++ b/dist/module-debug/index.js
@@ -88,12 +88,13 @@ Index.prototype.commit = function (replace, append) {
}
return this.db.commit(this, replace, append);
};
-
-// if(SUPPORT_RESOLVER){
-// Index.prototype.resolve = function(params){
-// return new Resolver(params);
-// };
-// }
+Index.prototype.destroy = function () {
+ if (this.commit_timer) {
+ clearTimeout(this.commit_timer);
+ this.commit_timer = null;
+ }
+ return this.db.destroy();
+};
/**
* @param {!Index} self
@@ -112,9 +113,6 @@ export function autoCommit(self, replace, append) {
Index.prototype.clear = function () {
- //this.map = new Map();
- //this.ctx = new Map();
- //this.reg = this.fastupdate ? new Map() : new Set();
this.map.clear();
this.ctx.clear();
this.reg.clear();
@@ -126,14 +124,11 @@ Index.prototype.clear = function () {
this.commit_timer && clearTimeout(this.commit_timer);
this.commit_timer = null;
this.commit_task = [{ clear: !0 }];
- //return this.db.clear();
}
return this;
};
-//Index.prototype.pipeline = pipeline;
-
/**
* @param {!number|string} id
* @param {!string} content
@@ -144,25 +139,14 @@ Index.prototype.append = function (id, content) {
};
Index.prototype.contain = function (id) {
-
- if (this.db) {
- return this.db.has(id);
- }
-
- return this.reg.has(id);
+ return this.db ? this.db.has(id) : this.reg.has(id);
};
Index.prototype.update = function (id, content) {
+ const self = this,
+ res = this.remove(id);
- // todo check the async part
- if (this.async /*|| (SUPPORT_PERSISTENT && this.db)*/) {
- const self = this,
- res = this.remove(id);
-
- return res.then ? res.then(() => self.add(id, content)) : this.add(id, content);
- }
-
- return this.remove(id).add(id, content);
+ return res && res.then ? res.then(() => self.add(id, content)) : this.add(id, content);
};
/**
diff --git a/dist/module-debug/keystore.js b/dist/module-debug/keystore.js
index 9f222ac..63a550e 100644
--- a/dist/module-debug/keystore.js
+++ b/dist/module-debug/keystore.js
@@ -39,8 +39,7 @@ export function KeystoreObj(bitlength = 8) {
obj[key] = value;
return (/* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */
// splice:
- !0 /*await rows.hasNext()*/
- /*await rows.hasNext()*/ /*await rows.hasNext()*/
+ !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/
);
},
delete(target, key) {
diff --git a/dist/module-debug/webpack.js b/dist/module-debug/webpack.js
index 90013e6..128e45a 100644
--- a/dist/module-debug/webpack.js
+++ b/dist/module-debug/webpack.js
@@ -28,6 +28,7 @@ import Charset from "./charset.js";
/** @export */Index.prototype.serialize;
/** @export */Index.prototype.mount;
/** @export */Index.prototype.commit;
+/** @export */Index.prototype.destroy;
/** @export */Index.prototype.reg;
/** @export */Index.prototype.map;
@@ -59,6 +60,7 @@ import Charset from "./charset.js";
/** @export */Document.prototype.removeAsync;
/** @export */Document.prototype.mount;
/** @export */Document.prototype.commit;
+/** @export */Document.prototype.destroy;
/** @export */Document.prototype.export;
/** @export */Document.prototype.import;
/** @export */Document.prototype.searchCache;
diff --git a/dist/module-debug/worker.js b/dist/module-debug/worker.js
index b3136b9..97189d3 100644
--- a/dist/module-debug/worker.js
+++ b/dist/module-debug/worker.js
@@ -10,7 +10,7 @@ let pid = 0;
* @constructor
*/
-function WorkerIndex(options) {
+export default function WorkerIndex(options) {
if (!this) {
return new WorkerIndex(options);
@@ -23,61 +23,63 @@ function WorkerIndex(options) {
// the factory is the outer wrapper from the build
// we use "self" as a trap for node.js
- let factory = (self || window)._factory;
+ let factory = "undefined" != typeof self && (self || window)._factory;
if (factory) {
factory = factory.toString();
}
- const is_node_js = "undefined" == typeof window && self.exports,
+ const is_node_js = "undefined" == typeof window /*&& self["exports"]*/,
_self = this;
- this.worker = create(factory, is_node_js, options.worker);
- this.resolver = create_object();
+ (async function () {
- if (!this.worker) {
+ this.worker = await create(factory, is_node_js, options.worker);
+ this.resolver = create_object();
- return;
- }
-
- function onmessage(msg) {
- msg = msg.data || msg;
- const id = msg.id,
- res = id && _self.resolver[id];
-
- if (res) {
- res(msg.msg);
- delete _self.resolver[id];
+ if (!this.worker) {
+ return;
}
- }
- is_node_js ? this.worker.on("message", onmessage) : this.worker.onmessage = onmessage;
+ function onmessage(msg) {
+ msg = msg.data || msg;
+ const id = msg.id,
+ res = id && _self.resolver[id];
- if (options.config) {
+ if (res) {
+ res(msg.msg);
+ delete _self.resolver[id];
+ }
+ }
- // when extern configuration needs to be loaded
- // it needs to return a promise to await for
- return new Promise(function (resolve) {
- _self.resolver[++pid] = function () {
- resolve(_self);
- };
- _self.worker.postMessage({
- id: pid,
- task: "init",
- factory: factory,
- options: options
+ is_node_js ? this.worker.on("message", onmessage) : this.worker.onmessage = onmessage;
+
+ if (options.config) {
+
+ delete options.db;
+
+ // when extern configuration needs to be loaded
+ // it needs to return a promise to await for
+ return new Promise(function (resolve) {
+ _self.resolver[++pid] = function () {
+ resolve(_self);
+ };
+ _self.worker.postMessage({
+ id: pid,
+ task: "init",
+ factory: factory,
+ options: options
+ });
});
+ }
+
+ this.worker.postMessage({
+ task: "init",
+ factory: factory,
+ options: options
});
- }
-
- this.worker.postMessage({
- task: "init",
- factory: factory,
- options: options
- });
+ }).call(this);
}
-export default WorkerIndex;
-
register("add");
register("append");
register("search");
@@ -119,11 +121,15 @@ function register(key) {
};
}
-function create(factory, is_node_js, worker_path) {
+async function create(factory, is_node_js, worker_path) {
let worker = is_node_js ?
// This eval will be removed when compiling, it isn't there in final build
- (0, eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
+
+ "undefined" != typeof module ? (0, eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
+ //: (0,eval)('new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/worker/node.mjs")')
+ : (0, eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")')
+
//eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
: factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker(is_string(worker_path) ? worker_path : "worker/worker.js", { type: "module" });
diff --git a/dist/module-debug/worker/node.js b/dist/module-debug/worker/node.js
index df97e98..d11807a 100644
--- a/dist/module-debug/worker/node.js
+++ b/dist/module-debug/worker/node.js
@@ -23,11 +23,11 @@ parentPort.on("message", function (data) {
// load extern field configuration
- if (filepath && "/" !== filepath[0] && "\\" !== filepath[0]) {
- // current working directory
- const dir = process.cwd();
- filepath = join(dir, filepath);
- }
+ // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){
+ // // current working directory
+ // const dir = process.cwd();
+ // filepath = join(dir, filepath);
+ // }
if (filepath) {
options = require(filepath);
}
diff --git a/dist/module-min/async.js b/dist/module-min/async.js
index d382705..fbaa2dc 100644
--- a/dist/module-min/async.js
+++ b/dist/module-min/async.js
@@ -1 +1 @@
-import Document from"./document.js";import Index from"./index.js";export default function(a){register.call(a,"add"),register.call(a,"append"),register.call(a,"search"),register.call(a,"update"),register.call(a,"remove")}function register(a){this[a+"Async"]=function(){const b=arguments,c=b[b.length-1];let d;"function"==typeof c&&(d=c,delete b[b.length-1]),this.async=!0;const e=this[a].apply(this,b);return this.async=!1,d&&(e.then?e.then(d):d(e)),e}}
\ No newline at end of file
+import Document from"./document.js";import Index from"./index.js";export default function(a){register.call(a,"add"),register.call(a,"append"),register.call(a,"search"),register.call(a,"update"),register.call(a,"remove")}function register(a){this[a+"Async"]=function(){const b=arguments,c=b[b.length-1];let d;"function"==typeof c&&(d=c,delete b[b.length-1]);const e=this[a].apply(this,b);return d&&(e.then?e.then(d):d(e)),e}}
\ No newline at end of file
diff --git a/dist/module-min/db/clickhouse/index.js b/dist/module-min/db/clickhouse/index.js
index 0a73fcc..58f9f02 100644
--- a/dist/module-min/db/clickhouse/index.js
+++ b/dist/module-min/db/clickhouse/index.js
@@ -41,7 +41,7 @@ import{ClickHouse}from"clickhouse";import StorageInterface from"../interface.js"
cfg String
)
ENGINE = TinyLog;
- `).toPromise();}return this.db},ClickhouseDB.prototype.close=function(){return this.db.close(),this.db=null,this},ClickhouseDB.prototype.destroy=async function(){await Promise.all([this.db.query(`DROP TABLE ${this.id}.map${this.field};`).toPromise(),this.db.query(`DROP TABLE ${this.id}.ctx${this.field};`).toPromise(),this.db.query(`DROP TABLE ${this.id}.tag${this.field};`).toPromise(),this.db.query(`DROP TABLE ${this.id}.cfg${this.field};`).toPromise(),this.db.query(`DROP TABLE ${this.id}.reg;`).toPromise()]),this.close()},ClickhouseDB.prototype.clear=function(){return Promise.all([this.db.query(`TRUNCATE TABLE ${this.id}.map${this.field};`).toPromise(),this.db.query(`TRUNCATE TABLE ${this.id}.ctx${this.field};`).toPromise(),this.db.query(`TRUNCATE TABLE ${this.id}.tag${this.field};`).toPromise(),this.db.query(`TRUNCATE TABLE ${this.id}.cfg${this.field};`).toPromise(),this.db.query(`TRUNCATE TABLE ${this.id}.reg;`).toPromise()])};function create_result(a,b,c){if(b){for(let b=0;b{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){return this.db&&this.close(),IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""))},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b(e.onerror=c=>{this.trx[a+":"+b]=null,e.abort(),e=d=null,g(c)},e.oncomplete=c=>{this.trx[a+":"+b]=null,e=d=null,f(c||!0)},c.call(this,d)))},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})}
\ No newline at end of file
+import Document from"../../document.js";import{PersistentOptions}from"../../type.js";const VERSION=1,IndexedDB="undefined"!=typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),IDBTransaction="undefined"!=typeof window&&(window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction),IDBKeyRange="undefined"!=typeof window&&(window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}export default function IdxDB(a,b={}){return this?void("object"==typeof a&&(a=a.name,b=a),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?":"+sanitize(a):""),this.field=b.field?sanitize(b.field):"",this.support_tag_search=!1,this.db=null,this.trx={}):new IdxDB(a,b)}IdxDB.prototype.mount=function(a){return a.constructor===Document?a.mount(this):(a.db=this,this.open())},IdxDB.prototype.open=function(){let a=this;return navigator.storage&&navigator.storage.persist(),this.db||new Promise(function(b,c){const d=IndexedDB.open(a.id+(a.field?":"+a.field:""),VERSION);d.onupgradeneeded=function(){const b=a.db=this.result;fields.forEach(a=>{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){return IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""))},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b(e.onerror=c=>{this.trx[a+":"+b]=null,e.abort(),e=d=null,g(c)},e.oncomplete=c=>{this.trx[a+":"+b]=null,e=d=null,f(c||!0)},c.call(this,d)))},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})}
\ No newline at end of file
diff --git a/dist/module-min/db/mongo/index.js b/dist/module-min/db/mongo/index.js
index 277e2ff..05ef2ee 100644
--- a/dist/module-min/db/mongo/index.js
+++ b/dist/module-min/db/mongo/index.js
@@ -1 +1 @@
-import{MongoClient}from"mongodb";const defaults={host:"localhost",port:"27017",user:null,pass:null},VERSION=1,fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import Document from"../../document.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}let CLIENT,DB=Object.create(null);export default function MongoDB(a,b={}){return this?void("object"==typeof a&&(a=a.name,b=a),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?"-"+sanitize(a):""),this.field=b.field?"-"+sanitize(b.field):"",this.type=b.type||"",this.db=b.db||DB[this.id]||CLIENT||null,this.trx=!1,this.support_tag_search=!0,Object.assign(defaults,b),this.db&&delete defaults.db):new MongoDB(a,b)}MongoDB.prototype.mount=function(a){return a.constructor===Document?a.mount(this):(a.db=this,this.open())};async function createCollection(a,b,c){"map"===b?(await a.createCollection("map"+c),await a.collection("map"+c).createIndex({key:1}),await a.collection("map"+c).createIndex({id:1})):"ctx"===b?(await a.createCollection("ctx"+c),await a.collection("ctx"+c).createIndex({ctx:1,key:1}),await a.collection("ctx"+c).createIndex({id:1})):"tag"===b?(await a.createCollection("tag"+c),await a.collection("tag"+c).createIndex({tag:1}),await a.collection("tag"+c).createIndex({id:1})):"reg"===b?(await a.createCollection("reg"),await a.collection("reg").createIndex({id:1})):"cfg"===b?await a.createCollection("cfg"+c):void 0}MongoDB.prototype.open=async function(){if(!this.db&&!(this.db=DB[this.id])&&!(this.db=CLIENT)){let a=defaults.url;a||(a=defaults.user?`mongodb://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`:`mongodb://${defaults.host}:${defaults.port}`),this.db=CLIENT=new MongoClient(a),await this.db.connect()}this.db.db&&(this.db=DB[this.id]=this.db.db(this.id));const a=await this.db.listCollections().toArray();for(let b,c=0;cl;k.push({ctx:d?j:l,key:d?l:j}),l=j}let m=f?{_id:1}:{_id:1,res:1};const n=[{$match:{$or:k}},{$group:{_id:"$id",res:e?{$sum:1}:{$min:1},count:{$sum:1}}}];if(e||n.push({$match:{count:b.length-1}}),g&&(m.doc="$doc.doc",n.push({$lookup:{from:"reg",localField:"_id",foreignField:"id",as:"doc"}},{$unwind:{path:"$doc",preserveNullAndEmptyArrays:!0}})),h){const a={};for(let b=0,c=1;bl;k.push({ctx:d?j:l,key:d?l:j}),l=j}let m=f?{_id:1}:{_id:1,res:1};const n=[{$match:{$or:k}},{$group:{_id:"$id",res:e?{$sum:1}:{$min:1},count:{$sum:1}}}];if(e||n.push({$match:{count:b.length-1}}),g&&(m.doc="$doc.doc",n.push({$lookup:{from:"reg",localField:"_id",foreignField:"id",as:"doc"}},{$unwind:{path:"$doc",preserveNullAndEmptyArrays:!0}})),h){const a={};for(let b=0,c=1;bconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return await this.db.disconnect(),this.db=null,this},RedisDB.prototype.clear=function(){return this.db.unlink([this.id+"map"+this.field,this.id+"ctx"+this.field,this.id+"tag"+this.field,this.id+"cfg"+this.field,this.id+"doc",this.id+"reg"])};function create_result(a,b,c,d){if(c){for(let c,d,e=0;e=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc",a).then(function(b){for(let c=0;cf,e.push(c+(g?d:f)+":"+(g?f:d)),f=d;b=e}else{const a=this.id+"map"+this.field+":";for(let c=0;cconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return await this.db.disconnect(),this.db=null,this},RedisDB.prototype.destroy=function(){return this.clear()},RedisDB.prototype.clear=function(){return this.db.unlink([this.id+"map"+this.field,this.id+"ctx"+this.field,this.id+"tag"+this.field,this.id+"cfg"+this.field,this.id+"doc",this.id+"reg"])};function create_result(a,b,c,d){if(c){for(let c,d,e=0;e=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc",a).then(function(b){for(let c=0;cf,e.push(c+(g?d:f)+":"+(g?f:d)),f=d;b=e}else{const a=this.id+"map"+this.field+":";for(let c=0;cc.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;dc.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;d}
+ * @export
+ */
this.index = parse_descriptor.call(this, options, document);
this.tag = null;
@@ -106,17 +111,17 @@ Document.prototype.mount = function (db) {
// move tags to their field indexes respectively
for (let i = 0, field; i < this.tagfield.length; i++) {
field = this.tagfield[i];
- let index = this.index.get(field);
- if (!index) {
- // create raw index when not exists
- this.index.set(field, index = new Index({}, this.reg));
- // copy and push to the field selection
- if (fields === this.field) {
- fields = fields.slice(0);
- }
- // tag indexes also needs to be upgraded to db instances
- fields.push(field);
+ let index; // = this.index.get(field);
+ //if(!index){
+ // create raw index when not exists
+ this.index.set(field, index = new Index({}, this.reg));
+ // copy and push to the field selection
+ if (fields === this.field) {
+ fields = fields.slice(0);
}
+ // tag indexes also needs to be upgraded to db instances
+ fields.push(field);
+ //}
// assign reference
index.tag = this.tag.get(field);
}
@@ -150,7 +155,7 @@ Document.prototype.mount = function (db) {
}
}
- this.async = !0;
+ //this.async = true;
this.db = !0;
return Promise.all(promises);
};
@@ -170,6 +175,14 @@ Document.prototype.commit = async function (replace, append) {
// this.reg.clear();
};
+Document.prototype.destroy = function () {
+ const promises = [];
+ for (const idx of this.index.values()) {
+ promises.push(idx.destroy());
+ }
+ return Promise.all(promises);
+};
+
/**
* @this Document
*/
diff --git a/dist/module/document/add.js b/dist/module/document/add.js
index 17cce81..23d9f7d 100644
--- a/dist/module/document/add.js
+++ b/dist/module/document/add.js
@@ -34,8 +34,7 @@ Document.prototype.add = function (id, content, _append) {
if ("function" == typeof tree) {
const tmp = tree(content);
if (tmp) {
- index.add(id, tmp, /* suggest */ /* append: */!1, /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/
- /*await rows.hasNext()*/ /*await rows.hasNext()*/);
+ index.add(id, tmp, /* suggest */ /* append: */!1, /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/);
}
} else {
const filter = tree._filter;
diff --git a/dist/module/document/search.js b/dist/module/document/search.js
index db4879d..2bbcbe4 100644
--- a/dist/module/document/search.js
+++ b/dist/module/document/search.js
@@ -147,7 +147,7 @@ Document.prototype.search = function (query, limit, options, _resolve) {
}
field || (field = this.field);
- let promises = !_resolve && (this.worker || this.async) && [],
+ let promises = !_resolve && (this.worker || this.db) && [],
db_tag_search;
diff --git a/dist/module/encoder.js b/dist/module/encoder.js
index 677d280..30e5a35 100644
--- a/dist/module/encoder.js
+++ b/dist/module/encoder.js
@@ -79,9 +79,9 @@ Encoder.prototype.assign = function (options) {
* pre-processing string input
* @type {Function|boolean}
*/
- this.normalize = /** @type {Function|boolean} */parse_option(options.normalize, /* tag? */
- /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */
- /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize);
+ this.normalize = /** @type {Function|boolean} */parse_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */
+ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/
+ /*await rows.hasNext()*/, this.normalize);
// {
// letter: true,
@@ -165,8 +165,7 @@ Encoder.prototype.assign = function (options) {
// options
- this.rtl = options.rtl ||
- /* suggest */ /* append: */ /* enrich */!1;
+ this.rtl = options.rtl || /* suggest */ /* append: */ /* enrich */!1;
this.dedupe = parse_option(options.dedupe, !0, this.dedupe);
this.filter = parse_option((tmp = options.filter) && new Set(tmp), null, this.filter);
this.matcher = parse_option((tmp = options.matcher) && new Map(tmp), null, this.matcher);
@@ -421,7 +420,7 @@ Encoder.prototype.encode = function (str) {
//
// // const position = word.length - key.length;
// // if(position > 0 && word.substring(position) === key){
- // // word = word.substring(0, position) + value;
+
// // break;
// // }
// }
diff --git a/dist/module/index.js b/dist/module/index.js
index 90a5974..77c34e2 100644
--- a/dist/module/index.js
+++ b/dist/module/index.js
@@ -88,12 +88,13 @@ Index.prototype.commit = function (replace, append) {
}
return this.db.commit(this, replace, append);
};
-
-// if(SUPPORT_RESOLVER){
-// Index.prototype.resolve = function(params){
-// return new Resolver(params);
-// };
-// }
+Index.prototype.destroy = function () {
+ if (this.commit_timer) {
+ clearTimeout(this.commit_timer);
+ this.commit_timer = null;
+ }
+ return this.db.destroy();
+};
/**
* @param {!Index} self
@@ -112,9 +113,6 @@ export function autoCommit(self, replace, append) {
Index.prototype.clear = function () {
- //this.map = new Map();
- //this.ctx = new Map();
- //this.reg = this.fastupdate ? new Map() : new Set();
this.map.clear();
this.ctx.clear();
this.reg.clear();
@@ -126,14 +124,11 @@ Index.prototype.clear = function () {
this.commit_timer && clearTimeout(this.commit_timer);
this.commit_timer = null;
this.commit_task = [{ clear: !0 }];
- //return this.db.clear();
}
return this;
};
-//Index.prototype.pipeline = pipeline;
-
/**
* @param {!number|string} id
* @param {!string} content
@@ -144,25 +139,14 @@ Index.prototype.append = function (id, content) {
};
Index.prototype.contain = function (id) {
-
- if (this.db) {
- return this.db.has(id);
- }
-
- return this.reg.has(id);
+ return this.db ? this.db.has(id) : this.reg.has(id);
};
Index.prototype.update = function (id, content) {
+ const self = this,
+ res = this.remove(id);
- // todo check the async part
- if (this.async /*|| (SUPPORT_PERSISTENT && this.db)*/) {
- const self = this,
- res = this.remove(id);
-
- return res.then ? res.then(() => self.add(id, content)) : this.add(id, content);
- }
-
- return this.remove(id).add(id, content);
+ return res && res.then ? res.then(() => self.add(id, content)) : this.add(id, content);
};
/**
diff --git a/dist/module/keystore.js b/dist/module/keystore.js
index 9f222ac..63a550e 100644
--- a/dist/module/keystore.js
+++ b/dist/module/keystore.js
@@ -39,8 +39,7 @@ export function KeystoreObj(bitlength = 8) {
obj[key] = value;
return (/* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */
// splice:
- !0 /*await rows.hasNext()*/
- /*await rows.hasNext()*/ /*await rows.hasNext()*/
+ !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/
);
},
delete(target, key) {
diff --git a/dist/module/webpack.js b/dist/module/webpack.js
index 90013e6..128e45a 100644
--- a/dist/module/webpack.js
+++ b/dist/module/webpack.js
@@ -28,6 +28,7 @@ import Charset from "./charset.js";
/** @export */Index.prototype.serialize;
/** @export */Index.prototype.mount;
/** @export */Index.prototype.commit;
+/** @export */Index.prototype.destroy;
/** @export */Index.prototype.reg;
/** @export */Index.prototype.map;
@@ -59,6 +60,7 @@ import Charset from "./charset.js";
/** @export */Document.prototype.removeAsync;
/** @export */Document.prototype.mount;
/** @export */Document.prototype.commit;
+/** @export */Document.prototype.destroy;
/** @export */Document.prototype.export;
/** @export */Document.prototype.import;
/** @export */Document.prototype.searchCache;
diff --git a/dist/module/worker.js b/dist/module/worker.js
index b3136b9..97189d3 100644
--- a/dist/module/worker.js
+++ b/dist/module/worker.js
@@ -10,7 +10,7 @@ let pid = 0;
* @constructor
*/
-function WorkerIndex(options) {
+export default function WorkerIndex(options) {
if (!this) {
return new WorkerIndex(options);
@@ -23,61 +23,63 @@ function WorkerIndex(options) {
// the factory is the outer wrapper from the build
// we use "self" as a trap for node.js
- let factory = (self || window)._factory;
+ let factory = "undefined" != typeof self && (self || window)._factory;
if (factory) {
factory = factory.toString();
}
- const is_node_js = "undefined" == typeof window && self.exports,
+ const is_node_js = "undefined" == typeof window /*&& self["exports"]*/,
_self = this;
- this.worker = create(factory, is_node_js, options.worker);
- this.resolver = create_object();
+ (async function () {
- if (!this.worker) {
+ this.worker = await create(factory, is_node_js, options.worker);
+ this.resolver = create_object();
- return;
- }
-
- function onmessage(msg) {
- msg = msg.data || msg;
- const id = msg.id,
- res = id && _self.resolver[id];
-
- if (res) {
- res(msg.msg);
- delete _self.resolver[id];
+ if (!this.worker) {
+ return;
}
- }
- is_node_js ? this.worker.on("message", onmessage) : this.worker.onmessage = onmessage;
+ function onmessage(msg) {
+ msg = msg.data || msg;
+ const id = msg.id,
+ res = id && _self.resolver[id];
- if (options.config) {
+ if (res) {
+ res(msg.msg);
+ delete _self.resolver[id];
+ }
+ }
- // when extern configuration needs to be loaded
- // it needs to return a promise to await for
- return new Promise(function (resolve) {
- _self.resolver[++pid] = function () {
- resolve(_self);
- };
- _self.worker.postMessage({
- id: pid,
- task: "init",
- factory: factory,
- options: options
+ is_node_js ? this.worker.on("message", onmessage) : this.worker.onmessage = onmessage;
+
+ if (options.config) {
+
+ delete options.db;
+
+ // when extern configuration needs to be loaded
+ // it needs to return a promise to await for
+ return new Promise(function (resolve) {
+ _self.resolver[++pid] = function () {
+ resolve(_self);
+ };
+ _self.worker.postMessage({
+ id: pid,
+ task: "init",
+ factory: factory,
+ options: options
+ });
});
+ }
+
+ this.worker.postMessage({
+ task: "init",
+ factory: factory,
+ options: options
});
- }
-
- this.worker.postMessage({
- task: "init",
- factory: factory,
- options: options
- });
+ }).call(this);
}
-export default WorkerIndex;
-
register("add");
register("append");
register("search");
@@ -119,11 +121,15 @@ function register(key) {
};
}
-function create(factory, is_node_js, worker_path) {
+async function create(factory, is_node_js, worker_path) {
let worker = is_node_js ?
// This eval will be removed when compiling, it isn't there in final build
- (0, eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
+
+ "undefined" != typeof module ? (0, eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
+ //: (0,eval)('new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/worker/node.mjs")')
+ : (0, eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")')
+
//eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
: factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker(is_string(worker_path) ? worker_path : "worker/worker.js", { type: "module" });
diff --git a/dist/module/worker/node.js b/dist/module/worker/node.js
index df97e98..d11807a 100644
--- a/dist/module/worker/node.js
+++ b/dist/module/worker/node.js
@@ -23,11 +23,11 @@ parentPort.on("message", function (data) {
// load extern field configuration
- if (filepath && "/" !== filepath[0] && "\\" !== filepath[0]) {
- // current working directory
- const dir = process.cwd();
- filepath = join(dir, filepath);
- }
+ // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){
+ // // current working directory
+ // const dir = process.cwd();
+ // filepath = join(dir, filepath);
+ // }
if (filepath) {
options = require(filepath);
}
diff --git a/dist/node/node.js b/dist/node/node.js
index e2cce36..a35758d 100644
--- a/dist/node/node.js
+++ b/dist/node/node.js
@@ -21,11 +21,11 @@ parentPort.on("message", function(data){
// load extern field configuration
let filepath = options["config"];
- if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){
- // current working directory
- const dir = process.cwd();
- filepath = join(dir, filepath);
- }
+ // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){
+ // // current working directory
+ // const dir = process.cwd();
+ // filepath = join(dir, filepath);
+ // }
if(filepath){
options = require(filepath);
}
diff --git a/example/nodejs-document/commonjs/index.js b/example/nodejs-document/commonjs/index.js
new file mode 100644
index 0000000..85c0cf8
--- /dev/null
+++ b/example/nodejs-document/commonjs/index.js
@@ -0,0 +1,49 @@
+const { Document, Charset } = require("flexsearch");
+const fs = require("fs");
+
+// loading test data
+const data = JSON.parse(fs.readFileSync(__dirname + "/../data.json", "utf8"));
+
+// create the document index
+const document = new Document({
+ document: {
+ id: "tconst",
+ store: true,
+ index: [{
+ field: "primaryTitle",
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+ },{
+ field: "originalTitle",
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+ }],
+ tag: [{
+ field: "startYear"
+ },{
+ field: "genres"
+ }]
+ }
+});
+
+// add test data
+for(let i = 0; i < data.length; i++){
+ document.add(data[i]);
+}
+
+// perform a query
+const result = document.search({
+ query: "carmencita",
+ tag: {
+ "startYear": "1894",
+ "genres": [
+ "Documentary",
+ "Short"
+ ]
+ },
+ suggest: true,
+ enrich: true,
+ merge: true
+});
+
+console.log(result);
\ No newline at end of file
diff --git a/example/nodejs-document/commonjs/package.json b/example/nodejs-document/commonjs/package.json
new file mode 100644
index 0000000..5bbefff
--- /dev/null
+++ b/example/nodejs-document/commonjs/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "commonjs"
+}
diff --git a/example/nodejs-document/data.json b/example/nodejs-document/data.json
new file mode 100644
index 0000000..1fd5660
--- /dev/null
+++ b/example/nodejs-document/data.json
@@ -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"
+ ]
+ }
+]
\ No newline at end of file
diff --git a/example/nodejs-document/esm/index.js b/example/nodejs-document/esm/index.js
new file mode 100644
index 0000000..df30d03
--- /dev/null
+++ b/example/nodejs-document/esm/index.js
@@ -0,0 +1,50 @@
+import { Document, Charset } from "flexsearch/esm";
+import fs from "fs";
+
+const dirname = import.meta.dirname;
+// loading test data
+const data = JSON.parse(fs.readFileSync(dirname + "/../data.json", "utf8"));
+
+// create the document index
+const document = new Document({
+ document: {
+ id: "tconst",
+ store: true,
+ index: [{
+ field: "primaryTitle",
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+ },{
+ field: "originalTitle",
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+ }],
+ tag: [{
+ field: "startYear"
+ },{
+ field: "genres"
+ }]
+ }
+});
+
+// add test data
+for(let i = 0; i < data.length; i++){
+ document.add(data[i]);
+}
+
+// perform a query
+const result = document.search({
+ query: "carmencita",
+ tag: {
+ "startYear": "1894",
+ "genres": [
+ "Documentary",
+ "Short"
+ ]
+ },
+ suggest: true,
+ enrich: true,
+ merge: true
+});
+
+console.log(result);
\ No newline at end of file
diff --git a/example/nodejs-document/esm/package.json b/example/nodejs-document/esm/package.json
new file mode 100644
index 0000000..3dbc1ca
--- /dev/null
+++ b/example/nodejs-document/esm/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "module"
+}
diff --git a/example/nodejs-document/package.json b/example/nodejs-document/package.json
new file mode 100644
index 0000000..073e14f
--- /dev/null
+++ b/example/nodejs-document/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "nodejs-document",
+ "dependencies": {
+ "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
+ }
+}
diff --git a/example/nodejs-persistent/commonjs/index.js b/example/nodejs-persistent/commonjs/index.js
new file mode 100644
index 0000000..e679cbc
--- /dev/null
+++ b/example/nodejs-persistent/commonjs/index.js
@@ -0,0 +1,64 @@
+const { Document, Charset } = require("flexsearch");
+const Postgres = require("flexsearch/db/postgres");
+const fs = require("fs");
+
+// loading test data
+const data = JSON.parse(fs.readFileSync(__dirname + "/../data.json", "utf8"));
+
+(async function(){
+
+ // create DB instance with namespace
+ const db = new Postgres("my-store");
+
+ // create the document index
+ const document = new Document({
+ document: {
+ id: "tconst",
+ store: true,
+ index: [{
+ field: "primaryTitle",
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+ },{
+ field: "originalTitle",
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+ }],
+ 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++){
+ document.add(data[i]);
+ }
+
+ // transfer changes (bulk)
+ await document.commit();
+
+ // perform a query
+ const result = await document.search({
+ query: "carmencita",
+ tag: {
+ "startYear": "1894",
+ "genres": [
+ "Documentary",
+ "Short"
+ ]
+ },
+ suggest: true,
+ enrich: true,
+ merge: true
+ });
+
+ console.log(result);
+
+}());
diff --git a/example/nodejs-persistent/commonjs/package.json b/example/nodejs-persistent/commonjs/package.json
new file mode 100644
index 0000000..5bbefff
--- /dev/null
+++ b/example/nodejs-persistent/commonjs/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "commonjs"
+}
diff --git a/example/nodejs-persistent/data.json b/example/nodejs-persistent/data.json
new file mode 100644
index 0000000..1fd5660
--- /dev/null
+++ b/example/nodejs-persistent/data.json
@@ -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"
+ ]
+ }
+]
\ No newline at end of file
diff --git a/example/nodejs-persistent/esm/index.js b/example/nodejs-persistent/esm/index.js
new file mode 100644
index 0000000..89c9821
--- /dev/null
+++ b/example/nodejs-persistent/esm/index.js
@@ -0,0 +1,65 @@
+import { Document, Charset } from "flexsearch/esm";
+import Postgres from "flexsearch/esm/db/postgres";
+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 Postgres("my-store");
+
+ // create the document index
+ const document = new Document({
+ document: {
+ id: "tconst",
+ store: true,
+ index: [{
+ field: "primaryTitle",
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+ },{
+ field: "originalTitle",
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+ }],
+ 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++){
+ document.add(data[i]);
+ }
+
+ // transfer changes (bulk)
+ await document.commit();
+
+ // perform a query
+ const result = await document.search({
+ query: "carmencita",
+ tag: {
+ "startYear": "1894",
+ "genres": [
+ "Documentary",
+ "Short"
+ ]
+ },
+ suggest: true,
+ enrich: true,
+ merge: true
+ });
+
+ console.log(result);
+
+}());
diff --git a/example/nodejs-persistent/esm/package.json b/example/nodejs-persistent/esm/package.json
new file mode 100644
index 0000000..3dbc1ca
--- /dev/null
+++ b/example/nodejs-persistent/esm/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "module"
+}
diff --git a/example/nodejs-persistent/package-lock.json b/example/nodejs-persistent/package-lock.json
new file mode 100644
index 0000000..660c969
--- /dev/null
+++ b/example/nodejs-persistent/package-lock.json
@@ -0,0 +1,240 @@
+{
+ "name": "nodejs-worker-persistent",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "nodejs-worker-persistent",
+ "dependencies": {
+ "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview",
+ "pg-promise": "^11.11.0"
+ }
+ },
+ "node_modules/assert-options": {
+ "version": "0.8.2",
+ "resolved": "https://registry.npmjs.org/assert-options/-/assert-options-0.8.2.tgz",
+ "integrity": "sha512-XaXoMxY0zuwAb0YuZjxIm8FeWvNq0aWNIbrzHhFjme8Smxw4JlPoyrAKQ6808k5UvQdhvnWqHZCphq5mXd4TDA==",
+ "engines": {
+ "node": ">=10.0.0"
+ }
+ },
+ "node_modules/flexsearch": {
+ "version": "0.8.0",
+ "resolved": "git+ssh://git@github.com/nextapps-de/flexsearch.git#a253897675cdb1361554abdc7f57305a6d52de25",
+ "license": "Apache-2.0"
+ },
+ "node_modules/pg": {
+ "version": "8.14.0",
+ "resolved": "https://registry.npmjs.org/pg/-/pg-8.14.0.tgz",
+ "integrity": "sha512-nXbVpyoaXVmdqlKEzToFf37qzyeeh7mbiXsnoWvstSqohj88yaa/I/Rq/HEVn2QPSZEuLIJa/jSpRDyzjEx4FQ==",
+ "peer": true,
+ "dependencies": {
+ "pg-connection-string": "^2.7.0",
+ "pg-pool": "^3.8.0",
+ "pg-protocol": "^1.8.0",
+ "pg-types": "^2.1.0",
+ "pgpass": "1.x"
+ },
+ "engines": {
+ "node": ">= 8.0.0"
+ },
+ "optionalDependencies": {
+ "pg-cloudflare": "^1.1.1"
+ },
+ "peerDependencies": {
+ "pg-native": ">=3.0.1"
+ },
+ "peerDependenciesMeta": {
+ "pg-native": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/pg-cloudflare": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz",
+ "integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==",
+ "optional": true
+ },
+ "node_modules/pg-connection-string": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz",
+ "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA=="
+ },
+ "node_modules/pg-cursor": {
+ "version": "2.13.0",
+ "resolved": "https://registry.npmjs.org/pg-cursor/-/pg-cursor-2.13.0.tgz",
+ "integrity": "sha512-13jHi54EawM9aQhmf0+xRtvaL/g4kBjnx/tEXWAIPNKm4bxUofPfc5navrgt47z85AsxUDx4f40IzF1y9tUyeA==",
+ "peer": true,
+ "peerDependencies": {
+ "pg": "^8"
+ }
+ },
+ "node_modules/pg-int8": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
+ "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
+ "engines": {
+ "node": ">=4.0.0"
+ }
+ },
+ "node_modules/pg-minify": {
+ "version": "1.7.0",
+ "resolved": "https://registry.npmjs.org/pg-minify/-/pg-minify-1.7.0.tgz",
+ "integrity": "sha512-kFPxAWAhPMvOqnY7klP3scdU5R7bxpAYOm8vGExuIkcSIwuFkZYl4C4XIPQ8DtXY2NzVmAX1aFHpvFSXQ/qQmA==",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
+ "node_modules/pg-pool": {
+ "version": "3.8.0",
+ "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.8.0.tgz",
+ "integrity": "sha512-VBw3jiVm6ZOdLBTIcXLNdSotb6Iy3uOCwDGFAksZCXmi10nyRvnP2v3jl4d+IsLYRyXf6o9hIm/ZtUzlByNUdw==",
+ "peerDependencies": {
+ "pg": ">=8.0"
+ }
+ },
+ "node_modules/pg-promise": {
+ "version": "11.11.0",
+ "resolved": "https://registry.npmjs.org/pg-promise/-/pg-promise-11.11.0.tgz",
+ "integrity": "sha512-nqtNHp9dvE1aMug2spLJBy6AazT9arorTlRqreHXu50pCArwQDpbu/R0tDUcyNYY4XP5HczwknkUzYi+ivyozQ==",
+ "dependencies": {
+ "assert-options": "0.8.2",
+ "pg": "8.13.3",
+ "pg-minify": "1.7.0",
+ "spex": "3.4.0"
+ },
+ "engines": {
+ "node": ">=14.0"
+ },
+ "peerDependencies": {
+ "pg-query-stream": "4.7.3"
+ }
+ },
+ "node_modules/pg-promise/node_modules/pg": {
+ "version": "8.13.3",
+ "resolved": "https://registry.npmjs.org/pg/-/pg-8.13.3.tgz",
+ "integrity": "sha512-P6tPt9jXbL9HVu/SSRERNYaYG++MjnscnegFh9pPHihfoBSujsrka0hyuymMzeJKFWrcG8wvCKy8rCe8e5nDUQ==",
+ "dependencies": {
+ "pg-connection-string": "^2.7.0",
+ "pg-pool": "^3.7.1",
+ "pg-protocol": "^1.7.1",
+ "pg-types": "^2.1.0",
+ "pgpass": "1.x"
+ },
+ "engines": {
+ "node": ">= 8.0.0"
+ },
+ "optionalDependencies": {
+ "pg-cloudflare": "^1.1.1"
+ },
+ "peerDependencies": {
+ "pg-native": ">=3.0.1"
+ },
+ "peerDependenciesMeta": {
+ "pg-native": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/pg-protocol": {
+ "version": "1.8.0",
+ "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.8.0.tgz",
+ "integrity": "sha512-jvuYlEkL03NRvOoyoRktBK7+qU5kOvlAwvmrH8sr3wbLrOdVWsRxQfz8mMy9sZFsqJ1hEWNfdWKI4SAmoL+j7g=="
+ },
+ "node_modules/pg-query-stream": {
+ "version": "4.7.3",
+ "resolved": "https://registry.npmjs.org/pg-query-stream/-/pg-query-stream-4.7.3.tgz",
+ "integrity": "sha512-WvsdwYXrvIXNZJflX/2MEQLjKs5TopZWeiyam1zcaFfhwQtL19ENOvGdzVsihGsbsNGdVRU5yiqg2G5p06UAbg==",
+ "peer": true,
+ "dependencies": {
+ "pg-cursor": "^2.12.3"
+ },
+ "peerDependencies": {
+ "pg": "^8"
+ }
+ },
+ "node_modules/pg-types": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
+ "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
+ "dependencies": {
+ "pg-int8": "1.0.1",
+ "postgres-array": "~2.0.0",
+ "postgres-bytea": "~1.0.0",
+ "postgres-date": "~1.0.4",
+ "postgres-interval": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/pgpass": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
+ "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
+ "dependencies": {
+ "split2": "^4.1.0"
+ }
+ },
+ "node_modules/postgres-array": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
+ "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/postgres-bytea": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
+ "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/postgres-date": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
+ "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/postgres-interval": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
+ "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
+ "dependencies": {
+ "xtend": "^4.0.0"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/spex": {
+ "version": "3.4.0",
+ "resolved": "https://registry.npmjs.org/spex/-/spex-3.4.0.tgz",
+ "integrity": "sha512-8JeZJ7QlEBnSj1W1fKXgbB2KUPA8k4BxFMf6lZX/c1ZagU/1b9uZWZK0yD6yjfzqAIuTNG4YlRmtMpQiXuohsg==",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
+ "node_modules/split2": {
+ "version": "4.2.0",
+ "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
+ "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
+ "engines": {
+ "node": ">= 10.x"
+ }
+ },
+ "node_modules/xtend": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
+ "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
+ "engines": {
+ "node": ">=0.4"
+ }
+ }
+ }
+}
diff --git a/example/nodejs-persistent/package.json b/example/nodejs-persistent/package.json
new file mode 100644
index 0000000..954a820
--- /dev/null
+++ b/example/nodejs-persistent/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "nodejs-persistent",
+ "dependencies": {
+ "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview",
+ "pg-promise": "^11.11.0"
+ }
+}
diff --git a/example/nodejs-worker-persistent/commonjs/config.genres.js b/example/nodejs-worker-persistent/commonjs/config.genres.js
new file mode 100644
index 0000000..39ff447
--- /dev/null
+++ b/example/nodejs-worker-persistent/commonjs/config.genres.js
@@ -0,0 +1,7 @@
+const Postgres = require("flexsearch/db/postgres");
+
+module.exports = {
+ db: new Postgres("my-store", {
+ field: "genres"
+ })
+};
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/commonjs/config.originalTitle.js b/example/nodejs-worker-persistent/commonjs/config.originalTitle.js
new file mode 100644
index 0000000..fa7b559
--- /dev/null
+++ b/example/nodejs-worker-persistent/commonjs/config.originalTitle.js
@@ -0,0 +1,10 @@
+const Postgres = require("flexsearch/db/postgres");
+const { Charset } = require("flexsearch");
+
+module.exports = {
+ tokenize: "forward",
+ encoder: Charset.LatinSimple,
+ db: new Postgres("my-store", {
+ field: "originalTitle"
+ })
+};
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/commonjs/config.primaryTitle.js b/example/nodejs-worker-persistent/commonjs/config.primaryTitle.js
new file mode 100644
index 0000000..b6dd069
--- /dev/null
+++ b/example/nodejs-worker-persistent/commonjs/config.primaryTitle.js
@@ -0,0 +1,10 @@
+const Postgres = require("flexsearch/db/postgres");
+const { Charset } = require("flexsearch");
+
+module.exports = {
+ tokenize: "forward",
+ encoder: Charset.LatinSimple,
+ db: new Postgres("my-store", {
+ field: "primaryTitle"
+ })
+};
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/commonjs/config.startYear.js b/example/nodejs-worker-persistent/commonjs/config.startYear.js
new file mode 100644
index 0000000..1bfa5a6
--- /dev/null
+++ b/example/nodejs-worker-persistent/commonjs/config.startYear.js
@@ -0,0 +1,7 @@
+const Postgres = require("flexsearch/db/postgres");
+
+module.exports = {
+ db: new Postgres("my-store", {
+ field: "startYear"
+ })
+};
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/commonjs/index.js b/example/nodejs-worker-persistent/commonjs/index.js
new file mode 100644
index 0000000..82459a4
--- /dev/null
+++ b/example/nodejs-worker-persistent/commonjs/index.js
@@ -0,0 +1,65 @@
+const { Document } = require("flexsearch");
+const Postgres = require("flexsearch/db/postgres");
+const fs = require("fs");
+
+// loading test data
+const data = JSON.parse(fs.readFileSync(__dirname + "/../data.json", "utf8"));
+
+(async function(){
+
+ // create DB instance with namespace
+ const db = new Postgres("my-store");
+
+ // create the document index
+ const document = 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",
+ 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);
+
+}());
diff --git a/example/nodejs-worker-persistent/commonjs/package.json b/example/nodejs-worker-persistent/commonjs/package.json
new file mode 100644
index 0000000..5bbefff
--- /dev/null
+++ b/example/nodejs-worker-persistent/commonjs/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "commonjs"
+}
diff --git a/example/nodejs-worker-persistent/data.json b/example/nodejs-worker-persistent/data.json
new file mode 100644
index 0000000..1fd5660
--- /dev/null
+++ b/example/nodejs-worker-persistent/data.json
@@ -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"
+ ]
+ }
+]
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/esm/config.genres.js b/example/nodejs-worker-persistent/esm/config.genres.js
new file mode 100644
index 0000000..faaa38a
--- /dev/null
+++ b/example/nodejs-worker-persistent/esm/config.genres.js
@@ -0,0 +1,7 @@
+import Postgres from "flexsearch/db/postgres";
+
+export default {
+ db: new Postgres("my-store", {
+ field: "genres"
+ })
+};
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/esm/config.originalTitle.js b/example/nodejs-worker-persistent/esm/config.originalTitle.js
new file mode 100644
index 0000000..f2be3a9
--- /dev/null
+++ b/example/nodejs-worker-persistent/esm/config.originalTitle.js
@@ -0,0 +1,10 @@
+import Postgres from "flexsearch/esm/db/postgres";
+import { Charset } from "flexsearch/esm";
+
+export default {
+ tokenize: "forward",
+ encoder: Charset.LatinSimple,
+ db: new Postgres("my-store", {
+ field: "originalTitle"
+ })
+};
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/esm/config.primaryTitle.js b/example/nodejs-worker-persistent/esm/config.primaryTitle.js
new file mode 100644
index 0000000..3990e03
--- /dev/null
+++ b/example/nodejs-worker-persistent/esm/config.primaryTitle.js
@@ -0,0 +1,10 @@
+import Postgres from "flexsearch/esm/db/postgres";
+import { Charset } from "flexsearch/esm";
+
+export default {
+ tokenize: "forward",
+ encoder: Charset.LatinSimple,
+ db: new Postgres("my-store", {
+ field: "primaryTitle"
+ })
+};
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/esm/config.startYear.js b/example/nodejs-worker-persistent/esm/config.startYear.js
new file mode 100644
index 0000000..b1bebf7
--- /dev/null
+++ b/example/nodejs-worker-persistent/esm/config.startYear.js
@@ -0,0 +1,7 @@
+import Postgres from "flexsearch/db/postgres";
+
+export default {
+ db: new Postgres("my-store", {
+ field: "startYear"
+ })
+};
\ No newline at end of file
diff --git a/example/nodejs-worker-persistent/esm/index.js b/example/nodejs-worker-persistent/esm/index.js
new file mode 100644
index 0000000..9c8f5d0
--- /dev/null
+++ b/example/nodejs-worker-persistent/esm/index.js
@@ -0,0 +1,66 @@
+import { Document } from "flexsearch/esm";
+import Postgres from "flexsearch/esm/db/postgres";
+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 Postgres("my-store");
+
+ // create the document index
+ const document = 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",
+ 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);
+
+}());
diff --git a/example/nodejs-worker-persistent/esm/package.json b/example/nodejs-worker-persistent/esm/package.json
new file mode 100644
index 0000000..3dbc1ca
--- /dev/null
+++ b/example/nodejs-worker-persistent/esm/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "module"
+}
diff --git a/example/nodejs-worker-persistent/package-lock.json b/example/nodejs-worker-persistent/package-lock.json
new file mode 100644
index 0000000..660c969
--- /dev/null
+++ b/example/nodejs-worker-persistent/package-lock.json
@@ -0,0 +1,240 @@
+{
+ "name": "nodejs-worker-persistent",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "nodejs-worker-persistent",
+ "dependencies": {
+ "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview",
+ "pg-promise": "^11.11.0"
+ }
+ },
+ "node_modules/assert-options": {
+ "version": "0.8.2",
+ "resolved": "https://registry.npmjs.org/assert-options/-/assert-options-0.8.2.tgz",
+ "integrity": "sha512-XaXoMxY0zuwAb0YuZjxIm8FeWvNq0aWNIbrzHhFjme8Smxw4JlPoyrAKQ6808k5UvQdhvnWqHZCphq5mXd4TDA==",
+ "engines": {
+ "node": ">=10.0.0"
+ }
+ },
+ "node_modules/flexsearch": {
+ "version": "0.8.0",
+ "resolved": "git+ssh://git@github.com/nextapps-de/flexsearch.git#a253897675cdb1361554abdc7f57305a6d52de25",
+ "license": "Apache-2.0"
+ },
+ "node_modules/pg": {
+ "version": "8.14.0",
+ "resolved": "https://registry.npmjs.org/pg/-/pg-8.14.0.tgz",
+ "integrity": "sha512-nXbVpyoaXVmdqlKEzToFf37qzyeeh7mbiXsnoWvstSqohj88yaa/I/Rq/HEVn2QPSZEuLIJa/jSpRDyzjEx4FQ==",
+ "peer": true,
+ "dependencies": {
+ "pg-connection-string": "^2.7.0",
+ "pg-pool": "^3.8.0",
+ "pg-protocol": "^1.8.0",
+ "pg-types": "^2.1.0",
+ "pgpass": "1.x"
+ },
+ "engines": {
+ "node": ">= 8.0.0"
+ },
+ "optionalDependencies": {
+ "pg-cloudflare": "^1.1.1"
+ },
+ "peerDependencies": {
+ "pg-native": ">=3.0.1"
+ },
+ "peerDependenciesMeta": {
+ "pg-native": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/pg-cloudflare": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz",
+ "integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==",
+ "optional": true
+ },
+ "node_modules/pg-connection-string": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz",
+ "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA=="
+ },
+ "node_modules/pg-cursor": {
+ "version": "2.13.0",
+ "resolved": "https://registry.npmjs.org/pg-cursor/-/pg-cursor-2.13.0.tgz",
+ "integrity": "sha512-13jHi54EawM9aQhmf0+xRtvaL/g4kBjnx/tEXWAIPNKm4bxUofPfc5navrgt47z85AsxUDx4f40IzF1y9tUyeA==",
+ "peer": true,
+ "peerDependencies": {
+ "pg": "^8"
+ }
+ },
+ "node_modules/pg-int8": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
+ "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
+ "engines": {
+ "node": ">=4.0.0"
+ }
+ },
+ "node_modules/pg-minify": {
+ "version": "1.7.0",
+ "resolved": "https://registry.npmjs.org/pg-minify/-/pg-minify-1.7.0.tgz",
+ "integrity": "sha512-kFPxAWAhPMvOqnY7klP3scdU5R7bxpAYOm8vGExuIkcSIwuFkZYl4C4XIPQ8DtXY2NzVmAX1aFHpvFSXQ/qQmA==",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
+ "node_modules/pg-pool": {
+ "version": "3.8.0",
+ "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.8.0.tgz",
+ "integrity": "sha512-VBw3jiVm6ZOdLBTIcXLNdSotb6Iy3uOCwDGFAksZCXmi10nyRvnP2v3jl4d+IsLYRyXf6o9hIm/ZtUzlByNUdw==",
+ "peerDependencies": {
+ "pg": ">=8.0"
+ }
+ },
+ "node_modules/pg-promise": {
+ "version": "11.11.0",
+ "resolved": "https://registry.npmjs.org/pg-promise/-/pg-promise-11.11.0.tgz",
+ "integrity": "sha512-nqtNHp9dvE1aMug2spLJBy6AazT9arorTlRqreHXu50pCArwQDpbu/R0tDUcyNYY4XP5HczwknkUzYi+ivyozQ==",
+ "dependencies": {
+ "assert-options": "0.8.2",
+ "pg": "8.13.3",
+ "pg-minify": "1.7.0",
+ "spex": "3.4.0"
+ },
+ "engines": {
+ "node": ">=14.0"
+ },
+ "peerDependencies": {
+ "pg-query-stream": "4.7.3"
+ }
+ },
+ "node_modules/pg-promise/node_modules/pg": {
+ "version": "8.13.3",
+ "resolved": "https://registry.npmjs.org/pg/-/pg-8.13.3.tgz",
+ "integrity": "sha512-P6tPt9jXbL9HVu/SSRERNYaYG++MjnscnegFh9pPHihfoBSujsrka0hyuymMzeJKFWrcG8wvCKy8rCe8e5nDUQ==",
+ "dependencies": {
+ "pg-connection-string": "^2.7.0",
+ "pg-pool": "^3.7.1",
+ "pg-protocol": "^1.7.1",
+ "pg-types": "^2.1.0",
+ "pgpass": "1.x"
+ },
+ "engines": {
+ "node": ">= 8.0.0"
+ },
+ "optionalDependencies": {
+ "pg-cloudflare": "^1.1.1"
+ },
+ "peerDependencies": {
+ "pg-native": ">=3.0.1"
+ },
+ "peerDependenciesMeta": {
+ "pg-native": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/pg-protocol": {
+ "version": "1.8.0",
+ "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.8.0.tgz",
+ "integrity": "sha512-jvuYlEkL03NRvOoyoRktBK7+qU5kOvlAwvmrH8sr3wbLrOdVWsRxQfz8mMy9sZFsqJ1hEWNfdWKI4SAmoL+j7g=="
+ },
+ "node_modules/pg-query-stream": {
+ "version": "4.7.3",
+ "resolved": "https://registry.npmjs.org/pg-query-stream/-/pg-query-stream-4.7.3.tgz",
+ "integrity": "sha512-WvsdwYXrvIXNZJflX/2MEQLjKs5TopZWeiyam1zcaFfhwQtL19ENOvGdzVsihGsbsNGdVRU5yiqg2G5p06UAbg==",
+ "peer": true,
+ "dependencies": {
+ "pg-cursor": "^2.12.3"
+ },
+ "peerDependencies": {
+ "pg": "^8"
+ }
+ },
+ "node_modules/pg-types": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
+ "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
+ "dependencies": {
+ "pg-int8": "1.0.1",
+ "postgres-array": "~2.0.0",
+ "postgres-bytea": "~1.0.0",
+ "postgres-date": "~1.0.4",
+ "postgres-interval": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/pgpass": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
+ "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
+ "dependencies": {
+ "split2": "^4.1.0"
+ }
+ },
+ "node_modules/postgres-array": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
+ "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/postgres-bytea": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
+ "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/postgres-date": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
+ "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/postgres-interval": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
+ "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
+ "dependencies": {
+ "xtend": "^4.0.0"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/spex": {
+ "version": "3.4.0",
+ "resolved": "https://registry.npmjs.org/spex/-/spex-3.4.0.tgz",
+ "integrity": "sha512-8JeZJ7QlEBnSj1W1fKXgbB2KUPA8k4BxFMf6lZX/c1ZagU/1b9uZWZK0yD6yjfzqAIuTNG4YlRmtMpQiXuohsg==",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
+ "node_modules/split2": {
+ "version": "4.2.0",
+ "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
+ "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
+ "engines": {
+ "node": ">= 10.x"
+ }
+ },
+ "node_modules/xtend": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
+ "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
+ "engines": {
+ "node": ">=0.4"
+ }
+ }
+ }
+}
diff --git a/example/nodejs-worker-persistent/package.json b/example/nodejs-worker-persistent/package.json
new file mode 100644
index 0000000..cdb034e
--- /dev/null
+++ b/example/nodejs-worker-persistent/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "nodejs-worker-persistent",
+ "dependencies": {
+ "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview",
+ "pg-promise": "^11.11.0"
+ }
+}
diff --git a/example/nodejs-worker/commonjs/config.originalTitle.js b/example/nodejs-worker/commonjs/config.originalTitle.js
new file mode 100644
index 0000000..8071c54
--- /dev/null
+++ b/example/nodejs-worker/commonjs/config.originalTitle.js
@@ -0,0 +1,6 @@
+const { Charset } = require("flexsearch");
+
+module.exports = {
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+};
\ No newline at end of file
diff --git a/example/nodejs-worker/commonjs/config.primaryTitle.js b/example/nodejs-worker/commonjs/config.primaryTitle.js
new file mode 100644
index 0000000..8071c54
--- /dev/null
+++ b/example/nodejs-worker/commonjs/config.primaryTitle.js
@@ -0,0 +1,6 @@
+const { Charset } = require("flexsearch");
+
+module.exports = {
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+};
\ No newline at end of file
diff --git a/example/nodejs-worker/commonjs/index.js b/example/nodejs-worker/commonjs/index.js
new file mode 100644
index 0000000..61c2846
--- /dev/null
+++ b/example/nodejs-worker/commonjs/index.js
@@ -0,0 +1,52 @@
+const { Document } = require("flexsearch");
+const fs = require("fs");
+
+// loading test data
+const data = JSON.parse(fs.readFileSync(__dirname + "/../data.json", "utf8"));
+
+(async function(){
+
+ // create the document index
+ const document = 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 document.add(data[i]);
+ }
+
+ // 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);
+
+}());
diff --git a/example/nodejs-worker/commonjs/package.json b/example/nodejs-worker/commonjs/package.json
new file mode 100644
index 0000000..5bbefff
--- /dev/null
+++ b/example/nodejs-worker/commonjs/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "commonjs"
+}
diff --git a/example/nodejs-worker/data.json b/example/nodejs-worker/data.json
new file mode 100644
index 0000000..1fd5660
--- /dev/null
+++ b/example/nodejs-worker/data.json
@@ -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"
+ ]
+ }
+]
\ No newline at end of file
diff --git a/example/nodejs-worker/esm/config.originalTitle.js b/example/nodejs-worker/esm/config.originalTitle.js
new file mode 100644
index 0000000..b894502
--- /dev/null
+++ b/example/nodejs-worker/esm/config.originalTitle.js
@@ -0,0 +1,6 @@
+import { Charset } from "flexsearch/esm";
+
+export default {
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+};
\ No newline at end of file
diff --git a/example/nodejs-worker/esm/config.primaryTitle.js b/example/nodejs-worker/esm/config.primaryTitle.js
new file mode 100644
index 0000000..b894502
--- /dev/null
+++ b/example/nodejs-worker/esm/config.primaryTitle.js
@@ -0,0 +1,6 @@
+import { Charset } from "flexsearch/esm";
+
+export default {
+ tokenize: "forward",
+ encoder: Charset.LatinSimple
+};
\ No newline at end of file
diff --git a/example/nodejs-worker/esm/index.js b/example/nodejs-worker/esm/index.js
new file mode 100644
index 0000000..79730fe
--- /dev/null
+++ b/example/nodejs-worker/esm/index.js
@@ -0,0 +1,53 @@
+import { Document } from "flexsearch/esm";
+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 the document
+ const document = 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 document.add(data[i]);
+ }
+
+ // 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);
+
+}());
diff --git a/example/nodejs-worker/esm/package.json b/example/nodejs-worker/esm/package.json
new file mode 100644
index 0000000..3dbc1ca
--- /dev/null
+++ b/example/nodejs-worker/esm/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "module"
+}
diff --git a/example/nodejs-worker/package-lock.json b/example/nodejs-worker/package-lock.json
new file mode 100644
index 0000000..4700a27
--- /dev/null
+++ b/example/nodejs-worker/package-lock.json
@@ -0,0 +1,18 @@
+{
+ "name": "nodejs-worker-persistent",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "nodejs-worker-persistent",
+ "dependencies": {
+ "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
+ }
+ },
+ "node_modules/flexsearch": {
+ "version": "0.8.0",
+ "resolved": "git+ssh://git@github.com/nextapps-de/flexsearch.git#a253897675cdb1361554abdc7f57305a6d52de25",
+ "license": "Apache-2.0"
+ }
+ }
+}
diff --git a/example/nodejs-worker/package.json b/example/nodejs-worker/package.json
new file mode 100644
index 0000000..50b0b2d
--- /dev/null
+++ b/example/nodejs-worker/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "nodejs-worker",
+ "dependencies": {
+ "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview"
+ }
+}
diff --git a/package.json b/package.json
index ae5bfb6..8372c8d 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,14 @@
"./lang/*.js": "./dist/lang/*.min.js",
"./db/*": "./dist/db/*/index.cjs",
"./db/*/index": "./dist/db/*/index.cjs",
- "./db/*/index.js": "./dist/db/*/index.cjs"
+ "./db/*/index.js": "./dist/db/*/index.cjs",
+ "./esm": "./dist/flexsearch.bundle.module.min.js",
+ "./esm/": "./dist/flexsearch.bundle.module.min.js",
+ "./esm/lang/*": "./dist/module/lang/*.js",
+ "./esm/lang/*.js": "./dist/module/lang/*.js",
+ "./esm/db/*": "./dist/module/db/*/index.js",
+ "./esm/db/*/index": "./dist/module/db/*/index.js",
+ "./esm/db/*/index.js": "./dist/module/db/*/index.js"
},
"module": "dist/flexsearch.bundle.module.min.js",
"browser": {
@@ -103,5 +110,24 @@
"babel-plugin-transform-undefined-to-void": "^6.9.4",
"google-closure-compiler": "^20240317.0.0",
"rollup": "^4.35.0"
- }
+ },
+ "funding": [{
+ "type": "github",
+ "url": "https://github.com/ts-thomas"
+ },{
+ "type": "opencollective",
+ "url": "https://opencollective.com/flexsearch"
+ },{
+ "type": "patreon",
+ "url": "https://patreon.com/user?u=96245532"
+ },{
+ "type": "liberapay",
+ "url": "https://liberapay.com/ts-thomas"
+ },{
+ "type": "paypal",
+ "url": "https://www.paypal.com/donate/?hosted_button_id=GEVR88FC9BWRW"
+ },{
+ "type": "bountysource",
+ "url": "https://salt.bountysource.com/teams/ts-thomas"
+ }]
}
diff --git a/src/async.js b/src/async.js
index b17e453..918c1b0 100644
--- a/src/async.js
+++ b/src/async.js
@@ -61,9 +61,9 @@ function register(key){
delete args[args.length - 1];
}
- this.async = true;
+ //this.async = true;
const res = this[key].apply(this, args);
- this.async = false;
+ //this.async = false;
if(callback){
res.then
? res.then(callback)
diff --git a/src/db/clickhouse/index.js b/src/db/clickhouse/index.js
index 79d05b2..2af50a8 100644
--- a/src/db/clickhouse/index.js
+++ b/src/db/clickhouse/index.js
@@ -183,15 +183,14 @@ ClickhouseDB.prototype.close = function(){
return this;
};
-ClickhouseDB.prototype.destroy = async function(){
- await Promise.all([
+ClickhouseDB.prototype.destroy = function(){
+ return Promise.all([
this.db.query(`DROP TABLE ${this.id}.map${this.field};`).toPromise(),
this.db.query(`DROP TABLE ${this.id}.ctx${this.field};`).toPromise(),
this.db.query(`DROP TABLE ${this.id}.tag${this.field};`).toPromise(),
this.db.query(`DROP TABLE ${this.id}.cfg${this.field};`).toPromise(),
this.db.query(`DROP TABLE ${this.id}.reg;`).toPromise()
]);
- this.close();
};
ClickhouseDB.prototype.clear = function(){
diff --git a/src/db/indexeddb/index.js b/src/db/indexeddb/index.js
index 267e8a8..1a47954 100644
--- a/src/db/indexeddb/index.js
+++ b/src/db/indexeddb/index.js
@@ -133,7 +133,6 @@ IdxDB.prototype.close = function(){
};
IdxDB.prototype.destroy = function(){
- this.db && this.close();
return IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : ""));
};
diff --git a/src/db/mongo/index.js b/src/db/mongo/index.js
index 2ed4731..6774595 100644
--- a/src/db/mongo/index.js
+++ b/src/db/mongo/index.js
@@ -128,15 +128,14 @@ MongoDB.prototype.close = function(){
return this;
};
-MongoDB.prototype.destroy = async function(){
- await Promise.all([
+MongoDB.prototype.destroy = function(){
+ return Promise.all([
this.db.dropCollection("map" + this.field),
this.db.dropCollection("ctx" + this.field),
this.db.dropCollection("tag" + this.field),
this.db.dropCollection("cfg" + this.field),
this.db.dropCollection("reg")
]);
- this.close();
};
async function clear(ref){
diff --git a/src/db/postgres/index.js b/src/db/postgres/index.js
index cc2cdec..3065f8b 100644
--- a/src/db/postgres/index.js
+++ b/src/db/postgres/index.js
@@ -15,7 +15,7 @@ const defaults = {
port: "5432"
};
-const pgp = pg_promise(/*{ noWarnings: true }*/);
+const pgp = pg_promise({ noWarnings: !DEBUG });
const VERSION = 1;
const MAXIMUM_QUERY_VARS = 16000;
const fields = ["map", "ctx", "reg", "tag", "cfg"];
@@ -189,15 +189,14 @@ PostgresDB.prototype.close = function(){
return this;
};
-PostgresDB.prototype.destroy = async function(){
- await this.db.none(`
+PostgresDB.prototype.destroy = function(){
+ return this.db.none(`
DROP TABLE IF EXISTS ${this.id}.map${this.field};
DROP TABLE IF EXISTS ${this.id}.ctx${this.field};
DROP TABLE IF EXISTS ${this.id}.tag${this.field};
DROP TABLE IF EXISTS ${this.id}.cfg${this.field};
DROP TABLE IF EXISTS ${this.id}.reg;
`);
- this.close();
};
PostgresDB.prototype.clear = function(){
diff --git a/src/db/redis/index.js b/src/db/redis/index.js
index 1fd9ce3..1e9b9ba 100644
--- a/src/db/redis/index.js
+++ b/src/db/redis/index.js
@@ -87,6 +87,10 @@ RedisDB.prototype.close = async function(){
return this;
};
+RedisDB.prototype.destroy = function(){
+ return this.clear();
+};
+
RedisDB.prototype.clear = function(){
return this.db.unlink([
this.id + "map" + this.field,
diff --git a/src/db/sqlite/index.js b/src/db/sqlite/index.js
index c640dd2..d2c974b 100644
--- a/src/db/sqlite/index.js
+++ b/src/db/sqlite/index.js
@@ -205,18 +205,19 @@ SqliteDB.prototype.open = async function(){
SqliteDB.prototype.close = function(){
this.db.close();
this.db = null;
+ DB[this.id] = null;
+ TRX[this.id] = null;
return this;
};
-SqliteDB.prototype.destroy = async function(){
- await this.transaction(function(){
+SqliteDB.prototype.destroy = function(){
+ return this.transaction(function(){
this.db.run("DROP TABLE IF EXISTS main.map" + this.field + ";");
this.db.run("DROP TABLE IF EXISTS main.ctx" + this.field + ";");
this.db.run("DROP TABLE IF EXISTS main.tag" + this.field + ";");
this.db.run("DROP TABLE IF EXISTS main.cfg" + this.field + ";");
this.db.run("DROP TABLE IF EXISTS main.reg;");
});
- this.close();
};
SqliteDB.prototype.clear = function(){
diff --git a/src/document.js b/src/document.js
index 1201949..e1dc22c 100644
--- a/src/document.js
+++ b/src/document.js
@@ -79,12 +79,15 @@ export default function Document(options){
this.worker = options.worker;
}
- if(SUPPORT_ASYNC){
- // this switch is used by recall of promise callbacks
- this.async = false;
- }
+ // if(SUPPORT_ASYNC){
+ // // this switch is used by recall of promise callbacks
+ // this.async = false;
+ // }
- /** @export */
+ /**
+ * @type {Map}
+ * @export
+ */
this.index = parse_descriptor.call(this, options, document);
if(SUPPORT_TAGS){
@@ -141,8 +144,8 @@ if(SUPPORT_PERSISTENT){
// move tags to their field indexes respectively
for(let i = 0, field; i < this.tagfield.length; i++){
field = this.tagfield[i];
- let index = this.index.get(field);
- if(!index){
+ let index;// = this.index.get(field);
+ //if(!index){
// create raw index when not exists
this.index.set(field, index = new Index({}, this.reg));
// copy and push to the field selection
@@ -151,7 +154,7 @@ if(SUPPORT_PERSISTENT){
}
// tag indexes also needs to be upgraded to db instances
fields.push(field);
- }
+ //}
// assign reference
index.tag = this.tag.get(field);
}
@@ -185,7 +188,7 @@ if(SUPPORT_PERSISTENT){
}
}
- this.async = true;
+ //this.async = true;
this.db = true;
return Promise.all(promises);
};
@@ -204,6 +207,14 @@ if(SUPPORT_PERSISTENT){
// }
// this.reg.clear();
};
+
+ Document.prototype.destroy = function(){
+ const promises = [];
+ for(const idx of this.index.values()){
+ promises.push(idx.destroy());
+ }
+ return Promise.all(promises);
+ }
}
/**
diff --git a/src/document/search.js b/src/document/search.js
index 531780b..cf34b16 100644
--- a/src/document/search.js
+++ b/src/document/search.js
@@ -165,7 +165,7 @@ Document.prototype.search = function(query, limit, options, _resolve){
}
field || (field = this.field);
- let promises = !_resolve && (this.worker || this.async) && [];
+ let promises = !_resolve && (this.worker || this.db) && [];
let db_tag_search;
// multi field search
diff --git a/src/index.js b/src/index.js
index c611952..b4d5f43 100644
--- a/src/index.js
+++ b/src/index.js
@@ -132,14 +132,15 @@ if(SUPPORT_PERSISTENT){
}
return this.db.commit(this, replace, append);
};
+ Index.prototype.destroy = function(){
+ if(this.commit_timer){
+ clearTimeout(this.commit_timer);
+ this.commit_timer = null;
+ }
+ return this.db.destroy();
+ }
}
-// if(SUPPORT_RESOLVER){
-// Index.prototype.resolve = function(params){
-// return new Resolver(params);
-// };
-// }
-
/**
* @param {!Index} self
* @param {boolean=} replace
@@ -157,9 +158,6 @@ export function autoCommit(self, replace, append){
Index.prototype.clear = function(){
- //this.map = new Map();
- //this.ctx = new Map();
- //this.reg = this.fastupdate ? new Map() : new Set();
this.map.clear();
this.ctx.clear();
this.reg.clear();
@@ -173,14 +171,11 @@ Index.prototype.clear = function(){
this.commit_timer && clearTimeout(this.commit_timer);
this.commit_timer = null;
this.commit_task = [{ "clear": true }];
- //return this.db.clear();
}
return this;
};
-//Index.prototype.pipeline = pipeline;
-
/**
* @param {!number|string} id
* @param {!string} content
@@ -191,26 +186,18 @@ Index.prototype.append = function(id, content){
};
Index.prototype.contain = function(id){
-
- if(SUPPORT_PERSISTENT && this.db){
- return this.db.has(id);
- }
-
- return this.reg.has(id);
+ return SUPPORT_PERSISTENT && this.db
+ ? this.db.has(id)
+ : this.reg.has(id);
};
Index.prototype.update = function(id, content){
- // todo check the async part
- if(this.async /*|| (SUPPORT_PERSISTENT && this.db)*/){
- const self = this;
- const res = this.remove(id);
- return res.then ? res.then(
- () => self.add(id, content)
- ) : this.add(id, content);
- }
-
- return this.remove(id).add(id, content);
+ const self = this;
+ const res = this.remove(id);
+ return res && res.then
+ ? res.then(() => self.add(id, content))
+ : this.add(id, content);
};
/**
diff --git a/src/webpack.js b/src/webpack.js
index a257875..17e3ede 100644
--- a/src/webpack.js
+++ b/src/webpack.js
@@ -52,6 +52,7 @@ import Charset from "./charset.js";
/** @export */ Index.prototype.serialize;
/** @export */ Index.prototype.mount;
/** @export */ Index.prototype.commit;
+/** @export */ Index.prototype.destroy;
if(SUPPORT_SERIALIZE || SUPPORT_PERSISTENT){
/** @export */ Index.prototype.reg;
@@ -87,6 +88,7 @@ if(SUPPORT_PERSISTENT){
/** @export */ Document.prototype.removeAsync;
/** @export */ Document.prototype.mount;
/** @export */ Document.prototype.commit;
+/** @export */ Document.prototype.destroy;
/** @export */ Document.prototype.export;
/** @export */ Document.prototype.import;
/** @export */ Document.prototype.searchCache;
diff --git a/src/worker.js b/src/worker.js
index 48d9c9f..b1ca593 100644
--- a/src/worker.js
+++ b/src/worker.js
@@ -10,7 +10,7 @@ let pid = 0;
* @constructor
*/
-function WorkerIndex(options){
+export default function WorkerIndex(options){
if(!this) {
return new WorkerIndex(options);
@@ -30,62 +30,65 @@ function WorkerIndex(options){
// the factory is the outer wrapper from the build
// we use "self" as a trap for node.js
- let factory = (self||window)["_factory"];
+ let factory = typeof self !== "undefined" && (self||window)["_factory"];
if(factory){
factory = factory.toString();
}
- const is_node_js = typeof window === "undefined" && self["exports"];
+ const is_node_js = typeof window === "undefined" /*&& self["exports"]*/;
const _self = this;
- this.worker = create(factory, is_node_js, options.worker);
- this.resolver = create_object();
+ (async function(){
- if(!this.worker){
+ this.worker = await create(factory, is_node_js, options.worker);
+ this.resolver = create_object();
- return;
- }
-
- function onmessage(msg){
- msg = msg["data"] || msg;
- const id = msg["id"];
- const res = id && _self.resolver[id];
- if(res){
- res(msg["msg"]);
- delete _self.resolver[id];
+ if(!this.worker){
+ return;
}
- }
- is_node_js
- ? this.worker["on"]("message", onmessage)
- : this.worker.onmessage = onmessage;
+ function onmessage(msg){
+ msg = msg["data"] || msg;
+ const id = msg["id"];
+ const res = id && _self.resolver[id];
+ if(res){
+ res(msg["msg"]);
+ delete _self.resolver[id];
+ }
+ }
- if(options["config"]){
+ is_node_js
+ ? this.worker["on"]("message", onmessage)
+ : this.worker.onmessage = onmessage;
- // when extern configuration needs to be loaded
- // it needs to return a promise to await for
- return new Promise(function(resolve){
- _self.resolver[++pid] = function(){
- resolve(_self);
- };
- _self.worker.postMessage({
- "id": pid,
- "task": "init",
- "factory": factory,
- "options": options
+ if(options.config){
+
+ delete options.db;
+
+ // when extern configuration needs to be loaded
+ // it needs to return a promise to await for
+ return new Promise(function(resolve){
+ _self.resolver[++pid] = function(){
+ resolve(_self);
+ };
+ _self.worker.postMessage({
+ "id": pid,
+ "task": "init",
+ "factory": factory,
+ "options": options
+ });
});
+ }
+
+ this.worker.postMessage({
+ "task": "init",
+ "factory": factory,
+ "options": options
});
- }
- this.worker.postMessage({
- "task": "init",
- "factory": factory,
- "options": options
- });
+ }.call(this));
}
-export default WorkerIndex;
-
register("add");
register("append");
register("search");
@@ -129,13 +132,18 @@ function register(key){
};
}
-function create(factory, is_node_js, worker_path){
+async function create(factory, is_node_js, worker_path){
let worker
worker = is_node_js ?
// This eval will be removed when compiling, it isn't there in final build
- (0,eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
+
+ typeof module !== "undefined"
+ ? (0,eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
+ //: (0,eval)('new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/worker/node.mjs")')
+ : (0,eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")')
+
//eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
:(
factory ?
diff --git a/src/worker/node.js b/src/worker/node.js
index e2cce36..a35758d 100644
--- a/src/worker/node.js
+++ b/src/worker/node.js
@@ -21,11 +21,11 @@ parentPort.on("message", function(data){
// load extern field configuration
let filepath = options["config"];
- if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){
- // current working directory
- const dir = process.cwd();
- filepath = join(dir, filepath);
- }
+ // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){
+ // // current working directory
+ // const dir = process.cwd();
+ // filepath = join(dir, filepath);
+ // }
if(filepath){
options = require(filepath);
}
diff --git a/src/worker/node.mjs b/src/worker/node.mjs
new file mode 100644
index 0000000..11c9e08
--- /dev/null
+++ b/src/worker/node.mjs
@@ -0,0 +1,42 @@
+import { parentPort } from "worker_threads";
+import { join } from "path";
+// Test Path
+import { Index } from "../../dist/flexsearch.bundle.module.min.js";
+//import { Index } from "../flexsearch.bundle.module.min.js";
+
+let index;
+
+parentPort.on("message", async function(data){
+
+ /** @type Index */
+ const args = data["args"];
+ const task = data["task"];
+ const id = data["id"];
+
+ switch(task){
+
+ case "init":
+
+ let options = data["options"] || {};
+
+ // load extern field configuration
+ let filepath = options["config"];
+ // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){
+ // // current working directory
+ // const dir = process.cwd();
+ // filepath = "file:///" + join(dir, filepath);
+ // }
+ if(filepath){
+ filepath = "file:///" + filepath;
+ options = await import(filepath);
+ }
+
+ index = new Index(options);
+ break;
+
+ default:
+
+ const message = index[task].apply(index, args);
+ parentPort.postMessage(task === "search" ? { "id": id, "msg": message } : { "id": id });
+ }
+});
diff --git a/task/build.js b/task/build.js
index c836c21..b89c9c2 100644
--- a/task/build.js
+++ b/task/build.js
@@ -307,7 +307,7 @@ else (async function(){
process.platform === "darwin" ? "\"node_modules/google-closure-compiler-osx/compiler\"" :
"java -jar node_modules/google-closure-compiler-java/compiler.jar";
- exec(executable + parameter + " --js='tmp/**.js' --js='!tmp/**/node.js'" + flag_str + " --js_output_file='" + filename + "' && exit 0", function(){
+ exec(executable + parameter + " --js='tmp/**.js' --js='!tmp/**/node.js' --js='!tmp/**/node.mjs'" + flag_str + " --js_output_file='" + filename + "' && exit 0", function(){
let build = fs.readFileSync(filename);
let preserve = fs.readFileSync("src/index.js", "utf8");
@@ -355,21 +355,26 @@ else (async function(){
//build = build.substring(0, pos_start) + part + build.substring(pos_end);
build = build.replace(/window\.FlexSearch(\s+)?=(\s+)?/, "export default ") + part;
//build = build.replace(/self\.FlexSearch(\s+)?=(\s+)?/, "export default ");
+
+ // replace the eval wrapper
+ build = build.replace('(1,eval)("import.meta.dirname")', "import.meta.dirname");
}
// fix closure compiler dynamic import
build = build.replace(/\(([a-z])=([a-z]).config\)&&\(([a-z])=([a-z])\)/, "($1=$2.config)&&($3=await import($4))");
if(release === "bundle"){
- build = build.replace("(function(self){'use strict';", "(function _f(self){'use strict';if(typeof module!=='undefined')self=module;self._factory=_f;");
+ build = build.replace("(function(self){'use strict';", "(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;");
}
// replace the eval wrapper
- build = build.replace(/\(0,eval\)\('([^']+)'\)/, "$1");
+ build = build.replace(/\(0,eval\)\('([^']+)'\)/g, "$1");
+
fs.writeFileSync(filename, build);
fs.existsSync("dist/node/") || fs.mkdirSync("dist/node/");
fs.copyFileSync("src/worker/node.js", "dist/node/node.js");
+ fs.copyFileSync("src/worker/node.mjs", "dist/node/node.mjs");
console.log("Saved to " + filename);
console.log("Build Complete.");