From b2c79cfd0e0710dd2428d058c073b37f14f4263e Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Thu, 20 Mar 2025 09:42:26 +0100 Subject: [PATCH] worker index basic support export/import --- README.md | 2 + dist/flexsearch.bundle.debug.js | 501 +++--- dist/flexsearch.bundle.min.js | 118 +- dist/flexsearch.bundle.module.debug.js | 495 +++--- dist/flexsearch.bundle.module.min.js | 120 +- dist/flexsearch.compact.debug.js | 508 +++--- dist/flexsearch.compact.min.js | 91 +- dist/flexsearch.compact.module.debug.js | 502 +++--- dist/flexsearch.compact.module.min.js | 93 +- dist/flexsearch.es5.debug.js | 1441 +++++++++-------- dist/flexsearch.es5.min.js | 128 +- dist/flexsearch.light.debug.js | 353 ++-- dist/flexsearch.light.min.js | 54 +- dist/flexsearch.light.module.debug.js | 335 ++-- dist/flexsearch.light.module.min.js | 54 +- dist/module-debug/bundle.js | 2 +- dist/module-debug/worker.js | 9 +- dist/module-debug/worker/handler.js | 38 +- dist/module-debug/worker/node.js | 33 +- dist/module-min/bundle.js | 2 +- dist/module-min/worker.js | 2 +- dist/module-min/worker/handler.js | 2 +- dist/module-min/worker/node.js | 2 +- dist/module/bundle.js | 2 +- dist/module/worker.js | 9 +- dist/module/worker/handler.js | 38 +- dist/module/worker/node.js | 33 +- dist/node/node.js | 26 +- dist/node/node.mjs | 24 +- doc/0.8.0.md | 6 +- .../basic-export-import/index.js | 2 + .../basic-worker-export-import/config.js | 29 + .../basic-worker-export-import/index.js | 68 + .../basic-worker-export-import/package.json | 6 + .../basic-worker-extern-config/config.js | 4 +- .../basic-worker-export-import/config.js | 29 + .../basic-worker-export-import/index.js | 69 + .../basic-worker-export-import/package.json | 7 + package-lock.json | 4 +- package.json | 2 +- src/bundle.js | 4 +- src/worker.js | 8 +- src/worker/handler.js | 35 +- src/worker/node.js | 26 +- src/worker/node.mjs | 24 +- 45 files changed, 3059 insertions(+), 2281 deletions(-) create mode 100644 example/nodejs-commonjs/basic-worker-export-import/config.js create mode 100644 example/nodejs-commonjs/basic-worker-export-import/index.js create mode 100644 example/nodejs-commonjs/basic-worker-export-import/package.json create mode 100644 example/nodejs-esm/basic-worker-export-import/config.js create mode 100644 example/nodejs-esm/basic-worker-export-import/index.js create mode 100644 example/nodejs-esm/basic-worker-export-import/package.json diff --git a/README.md b/README.md index 244b2a7..1a61300 100644 --- a/README.md +++ b/README.md @@ -679,6 +679,7 @@ The `worker` inherits from type `Index` and does not inherit from type `Document - [basic-resolver](example/nodejs-commonjs/basic-resolver) - [basic-worker](example/nodejs-commonjs/basic-worker) - [basic-worker-extern-config](example/nodejs-commonjs/basic-worker-extern-config) + - [basic-worker-export-import](example/nodejs-commonjs/basic-worker-export-import) - [basic-export-import](example/nodejs-commonjs/basic-export-import) - [document](example/nodejs-commonjs/document) - [document-persistent](example/nodejs-commonjs/document-persistent) @@ -693,6 +694,7 @@ The `worker` inherits from type `Index` and does not inherit from type `Document - [basic-resolver](example/nodejs-esm/basic-resolver) - [basic-worker](example/nodejs-esm/basic-worker) - [basic-worker-extern-config](example/nodejs-esm/basic-worker-extern-config) + - [basic-worker-export-import](example/nodejs-esm/basic-worker-export-import) - [basic-export-import](example/nodejs-esm/basic-export-import) - [document](example/nodejs-esm/document) - [document-persistent](example/nodejs-esm/document-persistent) diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index e81f71b..8c897d9 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.107 (Bundle/Debug) + * FlexSearch.js v0.8.108 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -269,89 +269,36 @@ function L(a) { a.B.clear(); a.G.clear(); } -;async function ka(a) { +;let M, N; +async function ka(a) { a = a.data; - var b = self._index; - const c = a.args; - var e = a.task; - switch(e) { + const b = a.task, c = a.id; + let e = a.args; + switch(b) { case "init": - e = a.options || {}; - (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new M(e); - postMessage({id:a.id}); + N = a.options || {}; + (a = a.factory) ? (Function("return " + a)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + postMessage({id:c}); break; default: - a = a.id, b = b[e].apply(b, c), postMessage("search" === e ? {id:a, msg:b} : {id:a}); + let d; + "export" === b && (e = [N.export]); + "import" === b ? await N.import.call(M, M) : d = M[b].apply(M, e); + postMessage("search" === b ? {id:c, msg:d} : {id:c}); } } -;let la = 0; -function N(a = {}) { - function b(g) { - function k(h) { - h = h.data || h; - const l = h.id, m = l && d.h[l]; - m && (m(h.msg), delete d.h[l]); - } - this.worker = g; - this.h = B(); - if (this.worker) { - e ? this.worker.on("message", k) : this.worker.onmessage = k; - if (a.config) { - return new Promise(function(h) { - d.h[++la] = function() { - h(d); - }; - d.worker.postMessage({id:la, task:"init", factory:c, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:c, options:a}); - return this; - } - } - if (!this || this.constructor !== N) { - return new N(a); - } - let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - c && (c = c.toString()); - const e = "undefined" === typeof window, d = this, f = ma(c, e, a.worker); - return f.then ? f.then(function(g) { - return b.call(d, g); - }) : b.call(this, f); -} -O("add"); -O("append"); -O("search"); -O("update"); -O("remove"); -function O(a) { - N.prototype[a] = N.prototype[a + "Async"] = async function() { - const b = this, c = [].slice.call(arguments); - var e = c[c.length - 1]; - let d; - "function" === typeof e && (d = e, c.splice(c.length - 1, 1)); - e = new Promise(function(f) { - b.h[++la] = f; - b.worker.postMessage({task:a, id:la, args:c}); - }); - return d ? (e.then(d), this) : e; - }; -} -function ma(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker(E(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", - "module/worker/worker.js"), {type:"module"}); -} -;function na(a) { +;function la(a) { P.call(a, "add"); P.call(a, "append"); P.call(a, "search"); P.call(a, "update"); P.call(a, "remove"); } -let Q, oa; -const pa = {}, R = {}; +let ma, na; +const oa = {}, pa = {}; function qa(a) { - Q = 0; - pa[a] = R[a]; + ma = 0; + oa[a] = pa[a]; } function P(a) { this[a + "Async"] = function() { @@ -359,11 +306,11 @@ function P(a) { var c = b[b.length - 1]; let e; "function" === typeof c && (e = c, delete b[b.length - 1]); - Q || (Q = setTimeout(qa, 0, a), oa = Date.now()); - R[a] || (R[a] = pa[a] = 1000); - if (!--pa[a]) { - pa[a] = R[a] = R[a] * this.priority * this.priority * 3 / (Date.now() - oa) | 0 || 1; - Q = clearTimeout(Q); + ma || (ma = setTimeout(qa, 0, a), na = Date.now()); + pa[a] || (pa[a] = oa[a] = 1000); + if (!--oa[a]) { + oa[a] = pa[a] = pa[a] * this.priority * this.priority * 3 / (Date.now() - na) | 0 || 1; + ma = clearTimeout(ma); const f = this; return new Promise(g => { setTimeout(function() { @@ -377,7 +324,67 @@ function P(a) { return c; }; } -;function ra(a, b = 0) { +;let ra = 0; +function Q(a = {}) { + function b(g) { + function k(h) { + h = h.data || h; + const l = h.id, m = l && d.h[l]; + m && (m(h.msg), delete d.h[l]); + } + this.worker = g; + this.h = B(); + if (this.worker) { + e ? this.worker.on("message", k) : this.worker.onmessage = k; + if (a.config) { + return new Promise(function(h) { + d.h[++ra] = function() { + h(d); + }; + d.worker.postMessage({id:ra, task:"init", factory:c, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:c, options:a}); + return this; + } + } + if (!this || this.constructor !== Q) { + return new Q(a); + } + let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + c && (c = c.toString()); + const e = "undefined" === typeof window, d = this, f = sa(c, e, a.worker); + return f.then ? f.then(function(g) { + return b.call(d, g); + }) : b.call(this, f); +} +R("add"); +R("append"); +R("search"); +R("update"); +R("remove"); +R("clear"); +R("export"); +R("import"); +la(Q.prototype); +function R(a) { + Q.prototype[a] = async function() { + const b = this, c = [].slice.call(arguments); + var e = c[c.length - 1]; + let d; + "function" === typeof e && (d = e, c.splice(c.length - 1, 1)); + e = new Promise(function(f) { + b.h[++ra] = f; + b.worker.postMessage({task:a, id:ra, args:c}); + }); + return d ? (e.then(d), this) : e; + }; +} +function sa(a, b, c) { + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker(E(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function ta(a, b = 0) { let c = [], e = []; b && (b = 250000 / b * 5000 | 0); for (const d of a.entries()) { @@ -386,30 +393,30 @@ function P(a) { e.length && c.push(e); return c; } -function sa(a, b) { +function ua(a, b) { b || (b = new Map()); for (let c = 0, e; c < a.length; c++) { e = a[c], b.set(e[0], e[1]); } return b; } -function ta(a, b = 0) { +function va(a, b = 0) { let c = [], e = []; b && (b = 250000 / b * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], ra(d[1])[0]]), e.length === b && (c.push(e), e = []); + e.push([d[0], ta(d[1])[0]]), e.length === b && (c.push(e), e = []); } e.length && c.push(e); return c; } -function ua(a, b) { +function wa(a, b) { b || (b = new Map()); for (let c = 0, e, d; c < a.length; c++) { - e = a[c], d = b.get(e[0]), b.set(e[0], sa(e[1], d)); + e = a[c], d = b.get(e[0]), b.set(e[0], ua(e[1], d)); } return b; } -function va(a) { +function xa(a) { let b = [], c = []; for (const e of a.keys()) { c.push(e), 250000 === c.length && (b.push(c), c = []); @@ -417,14 +424,14 @@ function va(a) { c.length && b.push(c); return b; } -function wa(a, b) { +function ya(a, b) { b || (b = new Set()); for (let c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function xa(a, b, c, e, d, f, g = 0) { +function za(a, b, c, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { @@ -433,12 +440,12 @@ function xa(a, b, c, e, d, f, g = 0) { if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return xa.call(l, a, b, c, k ? e : null, d, f, g + 1); + return za.call(l, a, b, c, k ? e : null, d, f, g + 1); }); } - return xa.call(this, a, b, c, k ? e : null, d, f, g + 1); + return za.call(this, a, b, c, k ? e : null, d, f, g + 1); } -;function ya(a, b, c, e) { +;function Aa(a, b, c, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { @@ -504,12 +511,12 @@ function S(a) { } if ("slice" === e) { return function(d, f) { - return ya(b, d || 0, f || b.length, !1); + return Aa(b, d || 0, f || b.length, !1); }; } if ("splice" === e) { return function(d, f) { - return ya(b, d || 0, f || b.length, !0); + return Aa(b, d || 0, f || b.length, !0); }; } if ("constructor" === e) { @@ -540,7 +547,7 @@ function T(a = 8) { this.index = B(); this.B = []; this.size = 0; - 32 < a ? (this.h = za, this.A = BigInt(a)) : (this.h = Aa, this.A = a); + 32 < a ? (this.h = Ba, this.A = BigInt(a)) : (this.h = Ca, this.A = a); } T.prototype.get = function(a) { const b = this.index[this.h(a)]; @@ -557,7 +564,7 @@ function U(a = 8) { } this.index = B(); this.h = []; - 32 < a ? (this.B = za, this.A = BigInt(a)) : (this.B = Aa, this.A = a); + 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } U.prototype.add = function(a) { var b = this.B(a); @@ -599,7 +606,7 @@ t.entries = U.prototype.entries = function*() { } } }; -function Aa(a) { +function Ca(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; @@ -610,7 +617,7 @@ function Aa(a) { } return 32 === this.A ? c + 2 ** 31 : c; } -function za(a) { +function Ba(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -640,7 +647,7 @@ function za(a) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(b)) { - h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Ba(b, h, this.J, 0, e, a, h[0], c); + h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Da(b, h, this.J, 0, e, a, h[0], c); } } } @@ -703,7 +710,7 @@ function za(a) { k[l] = b[l]; continue; } - Ca(b, k, l, 0, l[0], m); + Ea(b, k, l, 0, l[0], m); } } this.store.set(a, k || b); @@ -711,21 +718,21 @@ function za(a) { } return this; }; -function Ca(a, b, c, e, d, f) { +function Ea(a, b, c, e, d, f) { a = a[d]; if (e === c.length - 1) { b[d] = f || a; } else if (a) { if (a.constructor === Array) { for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { - Ca(a, b, c, e, d); + Ea(a, b, c, e, d); } } else { - b = b[d] || (b[d] = B()), d = c[++e], Ca(a, b, c, e, d); + b = b[d] || (b[d] = B()), d = c[++e], Ea(a, b, c, e, d); } } } -function Ba(a, b, c, e, d, f, g, k) { +function Da(a, b, c, e, d, f, g, k) { if (a = a[g]) { if (e === b.length - 1) { if (a.constructor === Array) { @@ -741,17 +748,17 @@ function Ba(a, b, c, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ba(a, b, c, e, d, f, g, k); + Da(a, b, c, e, d, f, g, k); } } else { - g = b[++e], Ba(a, b, c, e, d, f, g, k); + g = b[++e], Da(a, b, c, e, d, f, g, k); } } } else { d.db && d.remove(f); } } -;function Da(a, b, c, e, d, f, g) { +;function Fa(a, b, c, e, d, f, g) { const k = a.length; let h = [], l; var m; @@ -767,7 +774,7 @@ function Ba(a, b, c, e, d, f, g, k) { } if (a = h.length) { if (d) { - h = 1 < h.length ? Ea(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; + h = 1 < h.length ? Ga(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; } else { if (a < k) { return []; @@ -800,7 +807,7 @@ function Ba(a, b, c, e, d, f, g, k) { } return h; } -function Ea(a, b, c, e, d) { +function Ga(a, b, c, e, d) { const f = [], g = B(); let k; var h = a.length; @@ -845,7 +852,7 @@ function Ea(a, b, c, e, d) { } return f; } -function Fa(a, b, c) { +function Ha(a, b, c) { const e = B(), d = []; for (let f = 0, g; f < b.length; f++) { g = b[f]; @@ -866,7 +873,7 @@ function Fa(a, b, c) { } return d; } -;function Ga(a, b, c, e) { +;function Ia(a, b, c, e) { if (!a.length) { return a; } @@ -897,7 +904,7 @@ function Fa(a, b, c) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? W.call(this, d) : d; } -;function Ha(a, b, c) { +;function Ja(a, b, c) { var e = c[0]; if (e.then) { return Promise.all(c).then(function(m) { @@ -944,10 +951,10 @@ function Fa(a, b, c) { return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;X.prototype.or = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Ha(this, "or", arguments); - return Ia.call(this, a, b, c, e, d, f); + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Ja(this, "or", arguments); + return Ka.call(this, a, b, c, e, d, f); }; -function Ia(a, b, c, e, d, f) { +function Ka(a, b, c, e, d, f) { if (b.length) { const g = this; return Promise.all(b).then(function(k) { @@ -955,10 +962,10 @@ function Ia(a, b, c, e, d, f) { for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return Ia.call(g, a, [], c, e, d, f); + return Ka.call(g, a, [], c, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ea(a, c, e, !1, this.h), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ga(a, c, e, !1, this.h), e = 0)); return f ? this.resolve(c, e, d) : this; } ;X.prototype.and = function() { @@ -968,12 +975,12 @@ function Ia(a, b, c, e, d, f) { f && (a = !!f.suggest, d = f.resolve, b = f.limit, c = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ha(this, "and", arguments); - return Ja.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); + return La.call(this, f, g, k, h, l, m, n); } return d ? this.resolve(b, c, e) : this; }; -function Ja(a, b, c, e, d, f, g) { +function La(a, b, c, e, d, f, g) { if (b.length) { const k = this; return Promise.all(b).then(function(h) { @@ -981,7 +988,7 @@ function Ja(a, b, c, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ja.call(k, a, [], c, e, d, f, g); + return La.call(k, a, [], c, e, d, f, g); }); } if (a.length) { @@ -989,7 +996,7 @@ function Ja(a, b, c, e, d, f, g) { this.result = a[0]; } else { if (b = ca(a)) { - return this.result = Da(a, b, c, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Fa(a, b, c, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -999,10 +1006,10 @@ function Ja(a, b, c, e, d, f, g) { return f ? this.resolve(c, e, d) : this; } ;X.prototype.xor = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ha(this, "xor", arguments); - return Ka.call(this, a, b, c, e, d, f, g); + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "xor", arguments); + return Ma.call(this, a, b, c, e, d, f, g); }; -function Ka(a, b, c, e, d, f, g) { +function Ma(a, b, c, e, d, f, g) { if (b.length) { const k = this; return Promise.all(b).then(function(h) { @@ -1010,21 +1017,21 @@ function Ka(a, b, c, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ka.call(k, a, [], c, e, d, f, g); + return Ma.call(k, a, [], c, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = La.call(this, a, c, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Na.call(this, a, c, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(c, e, d) : this; } -function La(a, b, c, e, d) { +function Na(a, b, c, e, d) { const f = [], g = B(); let k = 0; for (let h = 0, l; h < a.length; h++) { @@ -1070,10 +1077,10 @@ function La(a, b, c, e, d) { return f; } ;X.prototype.not = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ha(this, "not", arguments); - return Ma.call(this, a, b, c, e, d, f, g); + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "not", arguments); + return Oa.call(this, a, b, c, e, d, f, g); }; -function Ma(a, b, c, e, d, f, g) { +function Oa(a, b, c, e, d, f, g) { if (b.length) { const k = this; return Promise.all(b).then(function(h) { @@ -1081,17 +1088,17 @@ function Ma(a, b, c, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ma.call(k, a, [], c, e, d, f, g); + return Oa.call(k, a, [], c, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Na.call(this, a, c, e, f); + this.result = Pa.call(this, a, c, e, f); } else if (f) { return this.resolve(c, e, d); } return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Na(a, b, c, e) { +function Pa(a, b, c, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { @@ -1166,7 +1173,7 @@ X.prototype.boost = function(a) { X.prototype.resolve = function(a, b, c) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ga.call(d, e, a || 100, b, c)) : e; + return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ia.call(d, e, a || 100, b, c)) : e; }; B(); V.prototype.search = function(a, b, c, e) { @@ -1245,7 +1252,7 @@ V.prototype.search = function(a, b, c, e) { } q.push(r = r.db.tag(v[p + 1], b, l, u)); } else { - r = Oa.call(this, v[p], v[p + 1], b, l, u); + r = Qa.call(this, v[p], v[p + 1], b, l, u); } d.push({field:v[p], tag:v[p + 1], result:r}); } @@ -1297,7 +1304,7 @@ V.prototype.search = function(a, b, c, e) { } } } else { - for (let G = 0, K, pb; G < p.length; G += 2) { + for (let G = 0, K, rb; G < p.length; G += 2) { K = this.tag.get(p[G]); if (!K) { if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), q) { @@ -1306,7 +1313,7 @@ V.prototype.search = function(a, b, c, e) { return r ? d : new X(d); } } - if (pb = (K = K && K.get(p[G + 1])) && K.length) { + if (rb = (K = K && K.get(p[G + 1])) && K.length) { y++, x.push(K); } else if (!q) { return r ? d : new X(d); @@ -1314,7 +1321,7 @@ V.prototype.search = function(a, b, c, e) { } } if (y) { - w = Fa(w, x, r); + w = Ha(w, x, r); H = w.length; if (!H && !q) { return r ? w : new X(w); @@ -1368,12 +1375,12 @@ V.prototype.search = function(a, b, c, e) { for (let D = 0; D < w.length; D++) { d[D].result = w[D]; } - return k ? Pa(d, b) : n ? Qa(d, a, z.index, z.field, z.D, n) : d; + return k ? Ra(d, b) : n ? Sa(d, a, z.index, z.field, z.D, n) : d; }); } - return k ? Pa(d, b) : n ? Qa(d, a, this.index, this.field, this.D, n) : d; + return k ? Ra(d, b) : n ? Sa(d, a, this.index, this.field, this.D, n) : d; }; -function Qa(a, b, c, e, d, f) { +function Sa(a, b, c, e, d, f) { let g, k, h; for (let m = 0, n, p, q, r, u; m < a.length; m++) { n = a[m].result; @@ -1415,7 +1422,7 @@ function Qa(a, b, c, e, d, f) { } return a; } -function Pa(a, b) { +function Ra(a, b) { const c = [], e = B(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1434,7 +1441,7 @@ function Pa(a, b) { } return c; } -function Oa(a, b, c, e, d) { +function Qa(a, b, c, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1466,7 +1473,7 @@ function W(a) { this.D = []; this.field = []; this.J = []; - this.key = (c = b.key || b.id) && Ra(c, this.J) || "id"; + this.key = (c = b.key || b.id) && Ta(c, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.reg = (this.fastupdate = !!a.fastupdate) ? e ? new T(e) : new Map() : e ? new U(e) : new Set(); this.C = (c = b.store || null) && c && !0 !== c && []; @@ -1474,7 +1481,7 @@ function W(a) { this.cache = (c = a.cache || null) && new Y(c); a.cache = !1; this.worker = a.worker; - this.index = Sa.call(this, a, b); + this.index = Ua.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -1487,7 +1494,7 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.F[d] = f.custom : (this.F[d] = Ra(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); + f.custom ? this.F[d] = f.custom : (this.F[d] = Ta(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); this.R[d] = g; this.tag.set(g, new Map()); } @@ -1520,7 +1527,7 @@ t.mount = function(a) { for (let d = 0, f; d < this.R.length; d++) { f = this.R[d]; var c = void 0; - this.index.set(f, c = new M({}, this.reg)); + 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); @@ -1555,7 +1562,7 @@ t.destroy = function() { } return Promise.all(a); }; -function Sa(a, b) { +function Ua(a, b) { const c = new Map(); let e = b.index || b.field || b; E(e) && (e = [e]); @@ -1564,23 +1571,23 @@ function Sa(a, b) { E(f) || (g = f, f = f.field); g = I(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const k = new N(g); + const k = new Q(g); c.set(f, k); } - this.worker || c.set(f, new M(g, this.reg)); - g.custom ? this.D[d] = g.custom : (this.D[d] = Ra(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); + this.worker || c.set(f, new O(g, this.reg)); + g.custom ? this.D[d] = g.custom : (this.D[d] = Ta(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); this.field[d] = f; } if (this.C) { a = b.store; E(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ra(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ta(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); } } return c; } -function Ra(a, b) { +function Ta(a, b) { const c = a.split(":"); let e = 0; for (let d = 0; d < c.length; d++) { @@ -1646,7 +1653,7 @@ t.set = function(a, b) { this.store.set(a, b); return this; }; -t.searchCache = Ta; +t.searchCache = Va; t.export = function(a, b, c = 0, e = 0) { if (c < this.field.length) { const g = this.field[c]; @@ -1662,17 +1669,17 @@ t.export = function(a, b, c = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = va(this.reg); + f = xa(this.reg); b = null; break; case 1: d = "tag"; - f = ta(this.tag, this.reg.size); + f = va(this.tag, this.reg.size); b = null; break; case 2: d = "doc"; - f = ra(this.store); + f = ta(this.store); b = null; break; case 3: @@ -1682,7 +1689,7 @@ t.export = function(a, b, c = 0, e = 0) { default: return; } - return xa.call(this, a, b, d, f, c, e); + return za.call(this, a, b, d, f, c, e); }; t.import = function(a, b) { if (b) { @@ -1697,21 +1704,21 @@ t.import = function(a, b) { switch(a) { case "reg": this.fastupdate = !1; - this.reg = wa(b, this.reg); + this.reg = ya(b, this.reg); for (let e = 0, d; e < this.field.length; e++) { d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = ua(b, this.tag); + this.tag = wa(b, this.tag); break; case "doc": - this.store = sa(b, this.store); + this.store = ua(b, this.store); } } }; -na(V.prototype); -function Ta(a, b, c) { +la(V.prototype); +function Va(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let e = this.cache.get(a); @@ -1752,32 +1759,32 @@ Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ua = {normalize:function(a) { +const Wa = {normalize:function(a) { return a.toLowerCase(); }}; -const Va = 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 Wa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Xa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const Ya = {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 Za = /[\x00-\x7F]+/g; -const $a = /[\x00-\x7F]+/g; +const Xa = 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 Ya = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Za = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +const $a = {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 ab = /[\x00-\x7F]+/g; -var bb = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ua, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Va}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Va, matcher:Wa, replacer:Xa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Va, replacer:Xa.concat([/(?!^)[aeo]/g, ""]), matcher:Wa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const bb = /[\x00-\x7F]+/g; +const cb = /[\x00-\x7F]+/g; +var db = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Wa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Xa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Xa, matcher:Ya, replacer:Za}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Xa, replacer:Za.concat([/(?!^)[aeo]/g, ""]), matcher:Ya}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let e = b.charAt(0), d = Ya[e]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Ya[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = b.charAt(0), d = $a[e]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = $a[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[c] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Za, " "); -}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace($a, ""); -}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { return ("" + a).replace(ab, " "); +}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { + return ("" + a).replace(bb, ""); +}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(cb, " "); }}}; -const cb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -M.prototype.add = function(a, b, c, e) { +const eb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +O.prototype.add = function(a, b, c, e) { if (b && (a || 0 === a)) { if (!e && !c && this.reg.has(a)) { return this.update(a, b); @@ -1789,15 +1796,15 @@ M.prototype.add = function(a, b, c, e) { let r = b[this.rtl ? e - 1 - q : q]; var d = r.length; if (d && (n || !m[r])) { - var f = this.score ? this.score(b, r, q, null, 0) : db(p, e, q), g = ""; + var f = this.score ? this.score(b, r, q, null, 0) : fb(p, e, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var k = d; k > f; k--) { g = r.substring(f, k); - var h = this.score ? this.score(b, r, q, g, f) : db(p, e, q, d, f); - eb(this, m, g, h, a, c); + var h = this.score ? this.score(b, r, q, g, f) : fb(p, e, q, d, f); + gb(this, m, g, h, a, c); } } break; @@ -1805,24 +1812,24 @@ M.prototype.add = function(a, b, c, e) { case "reverse": if (1 < d) { for (k = d - 1; 0 < k; k--) { - g = r[k] + g, h = this.score ? this.score(b, r, q, g, k) : db(p, e, q, d, k), eb(this, m, g, h, a, c); + g = r[k] + g, h = this.score ? this.score(b, r, q, g, k) : fb(p, e, q, d, k), gb(this, m, g, h, a, c); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[k], eb(this, m, g, f, a, c); + g += r[k], gb(this, m, g, f, a, c); } break; } default: - if (eb(this, m, r, f, a, c), n && 1 < e && q < e - 1) { + if (gb(this, m, r, f, a, c), n && 1 < e && q < e - 1) { for (d = B(), g = this.U, f = r, k = Math.min(n + 1, e - q), d[f] = 1, h = 1; h < k; h++) { if ((r = b[this.rtl ? e - 1 - q - h : q + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(b, f, q, r, h) : db(g + (e / 2 > g ? 0 : 1), e, q, k - 1, h - 1), v = this.bidirectional && r > f; - eb(this, l, v ? f : r, u, a, c, v ? r : f); + const u = this.score ? this.score(b, f, q, r, h) : fb(g + (e / 2 > g ? 0 : 1), e, q, k - 1, h - 1), v = this.bidirectional && r > f; + gb(this, l, v ? f : r, u, a, c, v ? r : f); } } } @@ -1834,10 +1841,10 @@ M.prototype.add = function(a, b, c, e) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && fb(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && hb(this)); return this; }; -function eb(a, b, c, e, d, f, g) { +function gb(a, b, c, e, d, f, g) { let k = g ? a.ctx : a.map, h; if (!b[c] || g && !(h = b[c])[g]) { if (g ? (b = h || (b[c] = B()), b[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : b[c] = 1, (h = k.get(c)) ? k = h : k.set(c, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { @@ -1855,10 +1862,10 @@ function eb(a, b, c, e, d, f, g) { } } } -function db(a, b, c, e, d) { +function fb(a, b, c, e, d) { return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; } -;M.prototype.search = function(a, b, c) { +;O.prototype.search = function(a, b, c) { c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); let e = [], d, f, g, k = 0, h, l, m, n, p; c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, p = (h = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : h = this.resolve; @@ -1866,11 +1873,11 @@ function db(a, b, c, e, d) { d = q.length; b = b || (h ? 100 : 0); if (1 === d) { - return gb.call(this, q[0], "", b, k, h, p, l); + return ib.call(this, q[0], "", b, k, h, p, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return gb.call(this, q[0], q[1], b, k, h, p, l); + return ib.call(this, q[0], q[1], b, k, h, p, l); } let r = B(), u = 0, v; 1 < d && f && (v = q[0], u = 1); @@ -1884,8 +1891,8 @@ function db(a, b, c, e, d) { for (let y, F; u < d; u++) { if ((F = q[u]) && !r[F]) { r[F] = 1; - y = await hb(x, F, v, 0, 0, !1, !1); - if (y = ib(y, e, g, n)) { + y = await jb(x, F, v, 0, 0, !1, !1); + if (y = kb(y, e, g, n)) { e = y; break; } @@ -1893,14 +1900,14 @@ function db(a, b, c, e, d) { } g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return jb(e, n, b, k, g, m, h); + return lb(e, n, b, k, g, m, h); }(); } for (let x, y; u < d; u++) { if ((y = q[u]) && !r[y]) { r[y] = 1; - x = hb(this, y, v, 0, 0, !1, !1); - if (x = ib(x, e, g, n)) { + x = jb(this, y, v, 0, 0, !1, !1); + if (x = kb(x, e, g, n)) { e = x; break; } @@ -1908,24 +1915,24 @@ function db(a, b, c, e, d) { } g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return jb(e, n, b, k, g, m, h); + return lb(e, n, b, k, g, m, h); }; -function jb(a, b, c, e, d, f, g) { +function lb(a, b, c, e, d, f, g) { let k = a.length, h = a; if (1 < k) { - h = Da(a, b, c, e, d, f, g); + h = Fa(a, b, c, e, d, f, g); } else if (1 === k) { - return g ? Ga.call(null, a[0], c, e) : new X(a[0]); + return g ? Ia.call(null, a[0], c, e) : new X(a[0]); } return g ? h : new X(h); } -function gb(a, b, c, e, d, f, g) { - a = hb(this, a, b, c, e, d, f, g); +function ib(a, b, c, e, d, f, g) { + a = jb(this, a, b, c, e, d, f, g); return this.db ? a.then(function(k) { return d ? k || [] : new X(k); - }) : a && a.length ? d ? Ga.call(this, a, c, e) : new X(a) : d ? [] : new X(); + }) : a && a.length ? d ? Ia.call(this, a, c, e) : new X(a) : d ? [] : new X(); } -function ib(a, b, c, e) { +function kb(a, b, c, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -1946,7 +1953,7 @@ function ib(a, b, c, e) { return d; } } -function hb(a, b, c, e, d, f, g, k) { +function jb(a, b, c, e, d, f, g, k) { let h; c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); if (a.db) { @@ -1955,7 +1962,7 @@ function hb(a, b, c, e, d, f, g, k) { a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;M.prototype.remove = function(a, b) { +;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) { @@ -1970,15 +1977,15 @@ function hb(a, b, c, e, d, f, g, k) { } } } else { - kb(this.map, a), this.depth && kb(this.ctx, a); + mb(this.map, a), this.depth && mb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && fb(this)); + this.db && (this.commit_task.push({del:a}), this.T && hb(this)); this.cache && this.cache.remove(a); return this; }; -function kb(a, b) { +function mb(a, b) { let c = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1993,24 +2000,24 @@ function kb(a, b) { } } else { for (let e of a.entries()) { - const d = e[0], f = kb(e[1], b); + const d = e[0], f = mb(e[1], b); f ? c += f : a.delete(d); } } return c; } -;function M(a, b) { - if (!this || this.constructor !== M) { - return new M(a); +;function O(a, b) { + if (!this || this.constructor !== O) { + return new O(a); } if (a) { var c = E(a) ? a : a.preset; - c && (cb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, cb[c], a)); + c && (eb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, eb[c], a)); } else { a = {}; } c = a.context; - const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || Ua; + const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? db[a.encoder] : a.encode || a.encoder || Wa; this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = c = a.tokenize || "strict"; @@ -2034,7 +2041,7 @@ function kb(a, b) { this.commit_timer = null; this.priority = a.priority || 4; } -t = M.prototype; +t = O.prototype; t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -2047,7 +2054,7 @@ t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function fb(a) { +function hb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2071,7 +2078,7 @@ t.update = function(a, b) { const c = this, e = this.remove(a); return e && e.then ? e.then(() => c.add(a, b)) : this.add(a, b); }; -function lb(a) { +function nb(a) { let b = 0; if (a.constructor === Array) { for (let c = 0, e; c < a.length; c++) { @@ -2079,7 +2086,7 @@ function lb(a) { } } else { for (const c of a) { - const e = c[0], d = lb(c[1]); + const e = c[0], d = nb(c[1]); d ? b += d : a.delete(e); } } @@ -2089,17 +2096,17 @@ t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - lb(this.map); - this.depth && lb(this.ctx); + nb(this.map); + this.depth && nb(this.ctx); return this; }; -t.searchCache = Ta; +t.searchCache = Va; t.export = function(a, b, c = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = va(this.reg); + f = xa(this.reg); break; case 1: d = "cfg"; @@ -2107,29 +2114,29 @@ t.export = function(a, b, c = 0, e = 0) { break; case 2: d = "map"; - f = ra(this.map, this.reg.size); + f = ta(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ta(this.ctx, this.reg.size); + f = va(this.ctx, this.reg.size); break; default: return; } - return xa.call(this, a, b, d, f, c, e); + return za.call(this, a, b, d, f, c, e); }; t.import = function(a, b) { if (b) { switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = wa(b, this.reg); + this.reg = ya(b, this.reg); break; case "map": - this.map = sa(b, this.map); + this.map = ua(b, this.map); break; case "ctx": - this.ctx = ua(b, this.ctx); + this.ctx = wa(b, this.ctx); } } }; @@ -2183,11 +2190,11 @@ t.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + b + e + d + "}" : b + e + d; }; -na(M.prototype); -const mb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), nb = ["map", "ctx", "tag", "reg", "cfg"]; -function ob(a, b = {}) { +la(O.prototype); +const ob = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), pb = ["map", "ctx", "tag", "reg", "cfg"]; +function qb(a, b = {}) { if (!this) { - return new ob(a, b); + return new qb(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2198,7 +2205,7 @@ function ob(a, b = {}) { this.db = null; this.h = {}; } -t = ob.prototype; +t = qb.prototype; t.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2210,10 +2217,10 @@ t.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const e = mb.open(a.id + (a.field ? ":" + a.field : ""), 1); + const e = ob.open(a.id + (a.field ? ":" + a.field : ""), 1); e.onupgradeneeded = function() { const d = a.db = this.result; - nb.forEach(f => { + pb.forEach(f => { d.objectStoreNames.contains(f) || d.createObjectStore(f); }); }; @@ -2239,13 +2246,13 @@ t.close = function() { this.db = null; }; t.destroy = function() { - const a = mb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const a = ob.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); return Z(a); }; t.clear = function() { - const a = this.db.transaction(nb, "readwrite"); - for (let b = 0; b < nb.length; b++) { - a.objectStore(nb[b]).clear(); + const a = this.db.transaction(pb, "readwrite"); + for (let b = 0; b < pb.length; b++) { + a.objectStore(pb[b]).clear(); } return Z(a); }; @@ -2429,7 +2436,7 @@ t.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function qb(a, b, c) { +function sb(a, b, c) { const e = a.value; let d, f, g = 0; for (let k = 0, h; k < e.length; k++) { @@ -2458,17 +2465,17 @@ t.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && qb(c, a); + c && sb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && qb(c, a); + c && sb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && qb(c, a, !0); + c && sb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2488,9 +2495,9 @@ function Z(a) { a = null; }); } -;const rb = {Index:M, Charset:bb, Encoder:J, Document:V, Worker:N, Resolver:X, IndexedDB:ob, Language:{}}, sb = self; -let tb; -(tb = sb.define) && tb.amd ? tb([], function() { - return rb; -}) : "object" === typeof sb.exports ? sb.exports = rb : sb.FlexSearch = rb; +;const tb = {Index:O, Charset:db, Encoder:J, Document:V, Worker:Q, Resolver:X, IndexedDB:qb, Language:{}}, ub = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; +let vb; +(vb = ub.define) && vb.amd ? vb([], function() { + return tb; +}) : "object" === typeof ub.exports ? ub.exports = tb : ub.FlexSearch = tb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index c6939f8..a200c4c 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.107 (Bundle) + * FlexSearch.js v0.8.108 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -21,72 +21,72 @@ t.addMatcher=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);i t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};async function ka(a){a=a.data;var b=self._index;const c=a.args;var e=a.task;switch(e){case "init":e=a.options||{};(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new M(e);postMessage({id:a.id});break;default:a=a.id,b=b[e].apply(b,c),postMessage("search"===e?{id:a,msg:b}:{id:a})}};let la=0; -function N(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++la]=function(){h(d)};d.worker.postMessage({id:la,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==N)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=ma(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); -function O(a){N.prototype[a]=N.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.splice(c.length-1,1));e=new Promise(function(f){b.h[++la]=f;b.worker.postMessage({task:a,id:la,args:c})});return d?(e.then(d),this):e}} -function ma(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ka.toString()],{type:"text/javascript"}))):new window.Worker(E(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function na(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let Q,oa;const pa={},R={};function qa(a){Q=0;pa[a]=R[a]} -function P(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);Q||(Q=setTimeout(qa,0,a),oa=Date.now());R[a]||(R[a]=pa[a]=1E3);if(!--pa[a]){pa[a]=R[a]=R[a]*this.priority*this.priority*3/(Date.now()-oa)|0||1;Q=clearTimeout(Q);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};function ra(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function sa(a,b){b||(b=new Map);for(let c=0,e;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} +this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;const b=a.task,c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(a=a.factory)?(Function("return "+a)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e=[N.export]);"import"===b?await N.import.call(M,M):d=M[b].apply(M,e);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ma,na;const oa={},pa={};function qa(a){ma=0;oa[a]=pa[a]} +function P(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);ma||(ma=setTimeout(qa,0,a),na=Date.now());pa[a]||(pa[a]=oa[a]=1E3);if(!--oa[a]){oa[a]=pa[a]=pa[a]*this.priority*this.priority*3/(Date.now()-na)|0||1;ma=clearTimeout(ma);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let ra=0; +function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ra]=function(){h(d)};d.worker.postMessage({id:ra,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==Q)return new Q(a);let c="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=sa(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}R("add");R("append");R("search");R("update");R("remove");R("clear");R("export");R("import");la(Q.prototype); +function R(a){Q.prototype[a]=async function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.splice(c.length-1,1));e=new Promise(function(f){b.h[++ra]=f;b.worker.postMessage({task:a,id:ra,args:c})});return d?(e.then(d),this):e}} +function sa(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ka.toString()],{type:"text/javascript"}))):new window.Worker(E(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function ta(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function ua(a,b){b||(b=new Map);for(let c=0,e;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;gc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= +this.C[h];if((c=l.I)&&!c(b))continue;let m;if("function"===typeof l){m=l(b);if(!m)continue;l=[l.V]}else if(E(l)||l.constructor===String){k[l]=b[l];continue}Ea(b,k,l,0,l[0],m)}}this.store.set(a,k||b)}}return this};function Ea(a,b,c,e,d,f){a=a[d];if(e===c.length-1)b[d]=f||a;else if(a)if(a.constructor===Array)for(b=b[d]=Array(a.length),d=0;dc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ea(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ha(this,"and",arguments);return Ja.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; -function Ja(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Da(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ha(this,"xor",arguments);return Ka.call(this,a,b,c,e,d,f,g)}; -function Ka(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=La.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function La(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hb?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ja(this,"and",arguments);return La.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; +function La(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; +function Ma(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Na(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.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};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Ua={normalize:function(a){return a.toLowerCase()}};const Va=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 Wa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Xa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ya={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 Za=/[\x00-\x7F]+/g;const $a=/[\x00-\x7F]+/g;const ab=/[\x00-\x7F]+/g;var bb={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ua,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Va},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Va,matcher:Wa,replacer:Xa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Va,replacer:Xa.concat([/(?!^)[aeo]/g,""]),matcher:Wa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):db(p,e,q,d,f);eb(this,m,g,h,a,c)}break}case "reverse":if(1< -d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;eb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.T&&fb(this));return this};function eb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new S(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function db(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};M.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 e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else kb(this.map,a),this.depth&&kb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&fb(this));this.cache&&this.cache.remove(a);return this}; -function kb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.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};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=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 Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const $a={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 ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):fb(p,e,q,d,f);gb(this,m,g,h,a,c)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&hb(this));return this};function gb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new S(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} +function fb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(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 e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,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.T&&hb(this));this.cache&&this.cache.remove(a);return this}; +function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; -function lb(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -t.close=function(){this.db.close();this.db=null};t.destroy=function(){const a=mb.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(nb,"readwrite");for(let b=0;b{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +t.close=function(){this.db.close();this.db=null};t.destroy=function(){const a=ob.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(pb,"readwrite");for(let b=0;b=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; t.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;em&&!f&&"string"===typeof n&&!isNaN(n)&&(m=h.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const rb={Index:M,Charset:bb,Encoder:J,Document:V,Worker:N,Resolver:X,IndexedDB:pb,Language:{}},sb=self;let tb;(tb=sb.define)&&tb.amd?tb([],function(){return rb}):"object"===typeof sb.exports?sb.exports=rb:sb.FlexSearch=rb;}(this||self)); +function sb(a,b,c){const e=a.value;let d,f,g=0;for(let k=0,h;km&&!f&&"string"===typeof n&&!isNaN(n)&&(m=h.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const tb={Index:O,Charset:db,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:rb,Language:{}},ub="undefined"!==typeof self?self:"undefined"!==typeof global?global:"undefined"!==typeof window?window:{};let vb;(vb=ub.define)&&vb.amd?vb([],function(){return tb}):"object"===typeof ub.exports?ub.exports=tb:ub.FlexSearch=tb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index 31699d5..243ed61 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.107 (Bundle/Module/Debug) + * FlexSearch.js v0.8.108 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -268,89 +268,36 @@ function L(a) { a.B.clear(); a.G.clear(); } -;async function ka(a) { +;let M, N; +async function ka(a) { a = a.data; - var b = self._index; - const c = a.args; - var e = a.task; - switch(e) { + const b = a.task, c = a.id; + let e = a.args; + switch(b) { case "init": - e = a.options || {}; - (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new M(e); - postMessage({id:a.id}); + N = a.options || {}; + (a = a.factory) ? (Function("return " + a)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + postMessage({id:c}); break; default: - a = a.id, b = b[e].apply(b, c), postMessage("search" === e ? {id:a, msg:b} : {id:a}); + let d; + "export" === b && (e = [N.export]); + "import" === b ? await N.import.call(M, M) : d = M[b].apply(M, e); + postMessage("search" === b ? {id:c, msg:d} : {id:c}); } } -;let la = 0; -function N(a = {}) { - function b(g) { - function k(h) { - h = h.data || h; - const l = h.id, m = l && d.h[l]; - m && (m(h.msg), delete d.h[l]); - } - this.worker = g; - this.h = B(); - if (this.worker) { - e ? this.worker.on("message", k) : this.worker.onmessage = k; - if (a.config) { - return new Promise(function(h) { - d.h[++la] = function() { - h(d); - }; - d.worker.postMessage({id:la, task:"init", factory:c, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:c, options:a}); - return this; - } - } - if (!this || this.constructor !== N) { - return new N(a); - } - let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - c && (c = c.toString()); - const e = "undefined" === typeof window, d = this, f = ma(c, e, a.worker); - return f.then ? f.then(function(g) { - return b.call(d, g); - }) : b.call(this, f); -} -O("add"); -O("append"); -O("search"); -O("update"); -O("remove"); -function O(a) { - N.prototype[a] = N.prototype[a + "Async"] = async function() { - const b = this, c = [].slice.call(arguments); - var e = c[c.length - 1]; - let d; - "function" === typeof e && (d = e, c.splice(c.length - 1, 1)); - e = new Promise(function(f) { - b.h[++la] = f; - b.worker.postMessage({task:a, id:la, args:c}); - }); - return d ? (e.then(d), this) : e; - }; -} -function ma(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker(E(c) ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", - "module/worker/worker.js"), {type:"module"}); -} -;function na(a) { +;function la(a) { P.call(a, "add"); P.call(a, "append"); P.call(a, "search"); P.call(a, "update"); P.call(a, "remove"); } -let Q, oa; -const pa = {}, R = {}; +let ma, na; +const oa = {}, pa = {}; function qa(a) { - Q = 0; - pa[a] = R[a]; + ma = 0; + oa[a] = pa[a]; } function P(a) { this[a + "Async"] = function() { @@ -358,11 +305,11 @@ function P(a) { var c = b[b.length - 1]; let e; "function" === typeof c && (e = c, delete b[b.length - 1]); - Q || (Q = setTimeout(qa, 0, a), oa = Date.now()); - R[a] || (R[a] = pa[a] = 1000); - if (!--pa[a]) { - pa[a] = R[a] = R[a] * this.priority * this.priority * 3 / (Date.now() - oa) | 0 || 1; - Q = clearTimeout(Q); + ma || (ma = setTimeout(qa, 0, a), na = Date.now()); + pa[a] || (pa[a] = oa[a] = 1000); + if (!--oa[a]) { + oa[a] = pa[a] = pa[a] * this.priority * this.priority * 3 / (Date.now() - na) | 0 || 1; + ma = clearTimeout(ma); const f = this; return new Promise(g => { setTimeout(function() { @@ -376,7 +323,67 @@ function P(a) { return c; }; } -;function ra(a, b = 0) { +;let ra = 0; +function Q(a = {}) { + function b(g) { + function k(h) { + h = h.data || h; + const l = h.id, m = l && d.h[l]; + m && (m(h.msg), delete d.h[l]); + } + this.worker = g; + this.h = B(); + if (this.worker) { + e ? this.worker.on("message", k) : this.worker.onmessage = k; + if (a.config) { + return new Promise(function(h) { + d.h[++ra] = function() { + h(d); + }; + d.worker.postMessage({id:ra, task:"init", factory:c, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:c, options:a}); + return this; + } + } + if (!this || this.constructor !== Q) { + return new Q(a); + } + let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + c && (c = c.toString()); + const e = "undefined" === typeof window, d = this, f = sa(c, e, a.worker); + return f.then ? f.then(function(g) { + return b.call(d, g); + }) : b.call(this, f); +} +R("add"); +R("append"); +R("search"); +R("update"); +R("remove"); +R("clear"); +R("export"); +R("import"); +la(Q.prototype); +function R(a) { + Q.prototype[a] = async function() { + const b = this, c = [].slice.call(arguments); + var e = c[c.length - 1]; + let d; + "function" === typeof e && (d = e, c.splice(c.length - 1, 1)); + e = new Promise(function(f) { + b.h[++ra] = f; + b.worker.postMessage({task:a, id:ra, args:c}); + }); + return d ? (e.then(d), this) : e; + }; +} +function sa(a, b, c) { + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker(E(c) ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function ta(a, b = 0) { let c = [], e = []; b && (b = 250000 / b * 5000 | 0); for (const d of a.entries()) { @@ -385,30 +392,30 @@ function P(a) { e.length && c.push(e); return c; } -function sa(a, b) { +function ua(a, b) { b || (b = new Map()); for (let c = 0, e; c < a.length; c++) { e = a[c], b.set(e[0], e[1]); } return b; } -function ta(a, b = 0) { +function va(a, b = 0) { let c = [], e = []; b && (b = 250000 / b * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], ra(d[1])[0]]), e.length === b && (c.push(e), e = []); + e.push([d[0], ta(d[1])[0]]), e.length === b && (c.push(e), e = []); } e.length && c.push(e); return c; } -function ua(a, b) { +function wa(a, b) { b || (b = new Map()); for (let c = 0, e, d; c < a.length; c++) { - e = a[c], d = b.get(e[0]), b.set(e[0], sa(e[1], d)); + e = a[c], d = b.get(e[0]), b.set(e[0], ua(e[1], d)); } return b; } -function va(a) { +function xa(a) { let b = [], c = []; for (const e of a.keys()) { c.push(e), 250000 === c.length && (b.push(c), c = []); @@ -416,14 +423,14 @@ function va(a) { c.length && b.push(c); return b; } -function wa(a, b) { +function ya(a, b) { b || (b = new Set()); for (let c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function xa(a, b, c, e, d, f, g = 0) { +function za(a, b, c, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { @@ -432,12 +439,12 @@ function xa(a, b, c, e, d, f, g = 0) { if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return xa.call(l, a, b, c, k ? e : null, d, f, g + 1); + return za.call(l, a, b, c, k ? e : null, d, f, g + 1); }); } - return xa.call(this, a, b, c, k ? e : null, d, f, g + 1); + return za.call(this, a, b, c, k ? e : null, d, f, g + 1); } -;function ya(a, b, c, e) { +;function Aa(a, b, c, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { @@ -503,12 +510,12 @@ function S(a) { } if ("slice" === e) { return function(d, f) { - return ya(b, d || 0, f || b.length, !1); + return Aa(b, d || 0, f || b.length, !1); }; } if ("splice" === e) { return function(d, f) { - return ya(b, d || 0, f || b.length, !0); + return Aa(b, d || 0, f || b.length, !0); }; } if ("constructor" === e) { @@ -539,7 +546,7 @@ function T(a = 8) { this.index = B(); this.B = []; this.size = 0; - 32 < a ? (this.h = za, this.A = BigInt(a)) : (this.h = Aa, this.A = a); + 32 < a ? (this.h = Ba, this.A = BigInt(a)) : (this.h = Ca, this.A = a); } T.prototype.get = function(a) { const b = this.index[this.h(a)]; @@ -556,7 +563,7 @@ function U(a = 8) { } this.index = B(); this.h = []; - 32 < a ? (this.B = za, this.A = BigInt(a)) : (this.B = Aa, this.A = a); + 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } U.prototype.add = function(a) { var b = this.B(a); @@ -598,7 +605,7 @@ t.entries = U.prototype.entries = function*() { } } }; -function Aa(a) { +function Ca(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; @@ -609,7 +616,7 @@ function Aa(a) { } return 32 === this.A ? c + 2 ** 31 : c; } -function za(a) { +function Ba(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -639,7 +646,7 @@ function za(a) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(b)) { - h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Ba(b, h, this.J, 0, e, a, h[0], c); + h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Da(b, h, this.J, 0, e, a, h[0], c); } } } @@ -702,7 +709,7 @@ function za(a) { k[l] = b[l]; continue; } - Ca(b, k, l, 0, l[0], m); + Ea(b, k, l, 0, l[0], m); } } this.store.set(a, k || b); @@ -710,21 +717,21 @@ function za(a) { } return this; }; -function Ca(a, b, c, e, d, f) { +function Ea(a, b, c, e, d, f) { a = a[d]; if (e === c.length - 1) { b[d] = f || a; } else if (a) { if (a.constructor === Array) { for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { - Ca(a, b, c, e, d); + Ea(a, b, c, e, d); } } else { - b = b[d] || (b[d] = B()), d = c[++e], Ca(a, b, c, e, d); + b = b[d] || (b[d] = B()), d = c[++e], Ea(a, b, c, e, d); } } } -function Ba(a, b, c, e, d, f, g, k) { +function Da(a, b, c, e, d, f, g, k) { if (a = a[g]) { if (e === b.length - 1) { if (a.constructor === Array) { @@ -740,17 +747,17 @@ function Ba(a, b, c, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ba(a, b, c, e, d, f, g, k); + Da(a, b, c, e, d, f, g, k); } } else { - g = b[++e], Ba(a, b, c, e, d, f, g, k); + g = b[++e], Da(a, b, c, e, d, f, g, k); } } } else { d.db && d.remove(f); } } -;function Da(a, b, c, e, d, f, g) { +;function Fa(a, b, c, e, d, f, g) { const k = a.length; let h = [], l; var m; @@ -766,7 +773,7 @@ function Ba(a, b, c, e, d, f, g, k) { } if (a = h.length) { if (d) { - h = 1 < h.length ? Ea(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; + h = 1 < h.length ? Ga(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; } else { if (a < k) { return []; @@ -799,7 +806,7 @@ function Ba(a, b, c, e, d, f, g, k) { } return h; } -function Ea(a, b, c, e, d) { +function Ga(a, b, c, e, d) { const f = [], g = B(); let k; var h = a.length; @@ -844,7 +851,7 @@ function Ea(a, b, c, e, d) { } return f; } -function Fa(a, b, c) { +function Ha(a, b, c) { const e = B(), d = []; for (let f = 0, g; f < b.length; f++) { g = b[f]; @@ -865,7 +872,7 @@ function Fa(a, b, c) { } return d; } -;function Ga(a, b, c, e) { +;function Ia(a, b, c, e) { if (!a.length) { return a; } @@ -896,7 +903,7 @@ function Fa(a, b, c) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? W.call(this, d) : d; } -;function Ha(a, b, c) { +;function Ja(a, b, c) { var e = c[0]; if (e.then) { return Promise.all(c).then(function(m) { @@ -943,10 +950,10 @@ function Fa(a, b, c) { return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;X.prototype.or = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Ha(this, "or", arguments); - return Ia.call(this, a, b, c, e, d, f); + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Ja(this, "or", arguments); + return Ka.call(this, a, b, c, e, d, f); }; -function Ia(a, b, c, e, d, f) { +function Ka(a, b, c, e, d, f) { if (b.length) { const g = this; return Promise.all(b).then(function(k) { @@ -954,10 +961,10 @@ function Ia(a, b, c, e, d, f) { for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return Ia.call(g, a, [], c, e, d, f); + return Ka.call(g, a, [], c, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ea(a, c, e, !1, this.h), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ga(a, c, e, !1, this.h), e = 0)); return f ? this.resolve(c, e, d) : this; } ;X.prototype.and = function() { @@ -967,12 +974,12 @@ function Ia(a, b, c, e, d, f) { f && (a = !!f.suggest, d = f.resolve, b = f.limit, c = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ha(this, "and", arguments); - return Ja.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); + return La.call(this, f, g, k, h, l, m, n); } return d ? this.resolve(b, c, e) : this; }; -function Ja(a, b, c, e, d, f, g) { +function La(a, b, c, e, d, f, g) { if (b.length) { const k = this; return Promise.all(b).then(function(h) { @@ -980,7 +987,7 @@ function Ja(a, b, c, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ja.call(k, a, [], c, e, d, f, g); + return La.call(k, a, [], c, e, d, f, g); }); } if (a.length) { @@ -988,7 +995,7 @@ function Ja(a, b, c, e, d, f, g) { this.result = a[0]; } else { if (b = ca(a)) { - return this.result = Da(a, b, c, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Fa(a, b, c, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -998,10 +1005,10 @@ function Ja(a, b, c, e, d, f, g) { return f ? this.resolve(c, e, d) : this; } ;X.prototype.xor = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ha(this, "xor", arguments); - return Ka.call(this, a, b, c, e, d, f, g); + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "xor", arguments); + return Ma.call(this, a, b, c, e, d, f, g); }; -function Ka(a, b, c, e, d, f, g) { +function Ma(a, b, c, e, d, f, g) { if (b.length) { const k = this; return Promise.all(b).then(function(h) { @@ -1009,21 +1016,21 @@ function Ka(a, b, c, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ka.call(k, a, [], c, e, d, f, g); + return Ma.call(k, a, [], c, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = La.call(this, a, c, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Na.call(this, a, c, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(c, e, d) : this; } -function La(a, b, c, e, d) { +function Na(a, b, c, e, d) { const f = [], g = B(); let k = 0; for (let h = 0, l; h < a.length; h++) { @@ -1069,10 +1076,10 @@ function La(a, b, c, e, d) { return f; } ;X.prototype.not = function() { - const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ha(this, "not", arguments); - return Ma.call(this, a, b, c, e, d, f, g); + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "not", arguments); + return Oa.call(this, a, b, c, e, d, f, g); }; -function Ma(a, b, c, e, d, f, g) { +function Oa(a, b, c, e, d, f, g) { if (b.length) { const k = this; return Promise.all(b).then(function(h) { @@ -1080,17 +1087,17 @@ function Ma(a, b, c, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ma.call(k, a, [], c, e, d, f, g); + return Oa.call(k, a, [], c, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Na.call(this, a, c, e, f); + this.result = Pa.call(this, a, c, e, f); } else if (f) { return this.resolve(c, e, d); } return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Na(a, b, c, e) { +function Pa(a, b, c, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { @@ -1165,7 +1172,7 @@ X.prototype.boost = function(a) { X.prototype.resolve = function(a, b, c) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ga.call(d, e, a || 100, b, c)) : e; + return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ia.call(d, e, a || 100, b, c)) : e; }; B(); V.prototype.search = function(a, b, c, e) { @@ -1244,7 +1251,7 @@ V.prototype.search = function(a, b, c, e) { } q.push(r = r.db.tag(v[p + 1], b, l, u)); } else { - r = Oa.call(this, v[p], v[p + 1], b, l, u); + r = Qa.call(this, v[p], v[p + 1], b, l, u); } d.push({field:v[p], tag:v[p + 1], result:r}); } @@ -1296,7 +1303,7 @@ V.prototype.search = function(a, b, c, e) { } } } else { - for (let G = 0, K, mb; G < p.length; G += 2) { + for (let G = 0, K, ob; G < p.length; G += 2) { K = this.tag.get(p[G]); if (!K) { if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), q) { @@ -1305,7 +1312,7 @@ V.prototype.search = function(a, b, c, e) { return r ? d : new X(d); } } - if (mb = (K = K && K.get(p[G + 1])) && K.length) { + if (ob = (K = K && K.get(p[G + 1])) && K.length) { y++, x.push(K); } else if (!q) { return r ? d : new X(d); @@ -1313,7 +1320,7 @@ V.prototype.search = function(a, b, c, e) { } } if (y) { - w = Fa(w, x, r); + w = Ha(w, x, r); H = w.length; if (!H && !q) { return r ? w : new X(w); @@ -1367,12 +1374,12 @@ V.prototype.search = function(a, b, c, e) { for (let D = 0; D < w.length; D++) { d[D].result = w[D]; } - return k ? Pa(d, b) : n ? Qa(d, a, z.index, z.field, z.D, n) : d; + return k ? Ra(d, b) : n ? Sa(d, a, z.index, z.field, z.D, n) : d; }); } - return k ? Pa(d, b) : n ? Qa(d, a, this.index, this.field, this.D, n) : d; + return k ? Ra(d, b) : n ? Sa(d, a, this.index, this.field, this.D, n) : d; }; -function Qa(a, b, c, e, d, f) { +function Sa(a, b, c, e, d, f) { let g, k, h; for (let m = 0, n, p, q, r, u; m < a.length; m++) { n = a[m].result; @@ -1414,7 +1421,7 @@ function Qa(a, b, c, e, d, f) { } return a; } -function Pa(a, b) { +function Ra(a, b) { const c = [], e = B(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1433,7 +1440,7 @@ function Pa(a, b) { } return c; } -function Oa(a, b, c, e, d) { +function Qa(a, b, c, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1465,7 +1472,7 @@ function W(a) { this.D = []; this.field = []; this.J = []; - this.key = (c = b.key || b.id) && Ra(c, this.J) || "id"; + this.key = (c = b.key || b.id) && Ta(c, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.reg = (this.fastupdate = !!a.fastupdate) ? e ? new T(e) : new Map() : e ? new U(e) : new Set(); this.C = (c = b.store || null) && c && !0 !== c && []; @@ -1473,7 +1480,7 @@ function W(a) { this.cache = (c = a.cache || null) && new Y(c); a.cache = !1; this.worker = a.worker; - this.index = Sa.call(this, a, b); + this.index = Ua.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -1486,7 +1493,7 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.F[d] = f.custom : (this.F[d] = Ra(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); + f.custom ? this.F[d] = f.custom : (this.F[d] = Ta(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); this.R[d] = g; this.tag.set(g, new Map()); } @@ -1519,7 +1526,7 @@ t.mount = function(a) { for (let d = 0, f; d < this.R.length; d++) { f = this.R[d]; var c = void 0; - this.index.set(f, c = new M({}, this.reg)); + 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); @@ -1554,7 +1561,7 @@ t.destroy = function() { } return Promise.all(a); }; -function Sa(a, b) { +function Ua(a, b) { const c = new Map(); let e = b.index || b.field || b; E(e) && (e = [e]); @@ -1563,23 +1570,23 @@ function Sa(a, b) { E(f) || (g = f, f = f.field); g = I(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const k = new N(g); + const k = new Q(g); c.set(f, k); } - this.worker || c.set(f, new M(g, this.reg)); - g.custom ? this.D[d] = g.custom : (this.D[d] = Ra(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); + this.worker || c.set(f, new O(g, this.reg)); + g.custom ? this.D[d] = g.custom : (this.D[d] = Ta(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); this.field[d] = f; } if (this.C) { a = b.store; E(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ra(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ta(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); } } return c; } -function Ra(a, b) { +function Ta(a, b) { const c = a.split(":"); let e = 0; for (let d = 0; d < c.length; d++) { @@ -1645,7 +1652,7 @@ t.set = function(a, b) { this.store.set(a, b); return this; }; -t.searchCache = Ta; +t.searchCache = Va; t.export = function(a, b, c = 0, e = 0) { if (c < this.field.length) { const g = this.field[c]; @@ -1661,17 +1668,17 @@ t.export = function(a, b, c = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = va(this.reg); + f = xa(this.reg); b = null; break; case 1: d = "tag"; - f = ta(this.tag, this.reg.size); + f = va(this.tag, this.reg.size); b = null; break; case 2: d = "doc"; - f = ra(this.store); + f = ta(this.store); b = null; break; case 3: @@ -1681,7 +1688,7 @@ t.export = function(a, b, c = 0, e = 0) { default: return; } - return xa.call(this, a, b, d, f, c, e); + return za.call(this, a, b, d, f, c, e); }; t.import = function(a, b) { if (b) { @@ -1696,21 +1703,21 @@ t.import = function(a, b) { switch(a) { case "reg": this.fastupdate = !1; - this.reg = wa(b, this.reg); + this.reg = ya(b, this.reg); for (let e = 0, d; e < this.field.length; e++) { d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = ua(b, this.tag); + this.tag = wa(b, this.tag); break; case "doc": - this.store = sa(b, this.store); + this.store = ua(b, this.store); } } }; -na(V.prototype); -function Ta(a, b, c) { +la(V.prototype); +function Va(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let e = this.cache.get(a); @@ -1751,32 +1758,32 @@ Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ua = {normalize:function(a) { +const Wa = {normalize:function(a) { return a.toLowerCase(); }}; -const Va = 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 Wa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Xa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const Ya = {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 Za = /[\x00-\x7F]+/g; -const $a = /[\x00-\x7F]+/g; +const Xa = 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 Ya = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Za = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +const $a = {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 ab = /[\x00-\x7F]+/g; -var bb = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ua, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Va}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Va, matcher:Wa, replacer:Xa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Va, replacer:Xa.concat([/(?!^)[aeo]/g, ""]), matcher:Wa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const bb = /[\x00-\x7F]+/g; +const cb = /[\x00-\x7F]+/g; +var db = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Wa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Xa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Xa, matcher:Ya, replacer:Za}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Xa, replacer:Za.concat([/(?!^)[aeo]/g, ""]), matcher:Ya}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let e = b.charAt(0), d = Ya[e]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Ya[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = b.charAt(0), d = $a[e]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = $a[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[c] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Za, " "); -}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace($a, ""); -}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { return ("" + a).replace(ab, " "); +}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { + return ("" + a).replace(bb, ""); +}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(cb, " "); }}}; -const cb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -M.prototype.add = function(a, b, c, e) { +const eb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +O.prototype.add = function(a, b, c, e) { if (b && (a || 0 === a)) { if (!e && !c && this.reg.has(a)) { return this.update(a, b); @@ -1788,15 +1795,15 @@ M.prototype.add = function(a, b, c, e) { let r = b[this.rtl ? e - 1 - q : q]; var d = r.length; if (d && (n || !m[r])) { - var f = this.score ? this.score(b, r, q, null, 0) : db(p, e, q), g = ""; + var f = this.score ? this.score(b, r, q, null, 0) : fb(p, e, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var k = d; k > f; k--) { g = r.substring(f, k); - var h = this.score ? this.score(b, r, q, g, f) : db(p, e, q, d, f); - eb(this, m, g, h, a, c); + var h = this.score ? this.score(b, r, q, g, f) : fb(p, e, q, d, f); + gb(this, m, g, h, a, c); } } break; @@ -1804,24 +1811,24 @@ M.prototype.add = function(a, b, c, e) { case "reverse": if (1 < d) { for (k = d - 1; 0 < k; k--) { - g = r[k] + g, h = this.score ? this.score(b, r, q, g, k) : db(p, e, q, d, k), eb(this, m, g, h, a, c); + g = r[k] + g, h = this.score ? this.score(b, r, q, g, k) : fb(p, e, q, d, k), gb(this, m, g, h, a, c); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[k], eb(this, m, g, f, a, c); + g += r[k], gb(this, m, g, f, a, c); } break; } default: - if (eb(this, m, r, f, a, c), n && 1 < e && q < e - 1) { + if (gb(this, m, r, f, a, c), n && 1 < e && q < e - 1) { for (d = B(), g = this.U, f = r, k = Math.min(n + 1, e - q), d[f] = 1, h = 1; h < k; h++) { if ((r = b[this.rtl ? e - 1 - q - h : q + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(b, f, q, r, h) : db(g + (e / 2 > g ? 0 : 1), e, q, k - 1, h - 1), v = this.bidirectional && r > f; - eb(this, l, v ? f : r, u, a, c, v ? r : f); + const u = this.score ? this.score(b, f, q, r, h) : fb(g + (e / 2 > g ? 0 : 1), e, q, k - 1, h - 1), v = this.bidirectional && r > f; + gb(this, l, v ? f : r, u, a, c, v ? r : f); } } } @@ -1833,10 +1840,10 @@ M.prototype.add = function(a, b, c, e) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && fb(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && hb(this)); return this; }; -function eb(a, b, c, e, d, f, g) { +function gb(a, b, c, e, d, f, g) { let k = g ? a.ctx : a.map, h; if (!b[c] || g && !(h = b[c])[g]) { if (g ? (b = h || (b[c] = B()), b[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : b[c] = 1, (h = k.get(c)) ? k = h : k.set(c, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { @@ -1854,10 +1861,10 @@ function eb(a, b, c, e, d, f, g) { } } } -function db(a, b, c, e, d) { +function fb(a, b, c, e, d) { return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; } -;M.prototype.search = function(a, b, c) { +;O.prototype.search = function(a, b, c) { c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); let e = [], d, f, g, k = 0, h, l, m, n, p; c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, p = (h = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : h = this.resolve; @@ -1865,11 +1872,11 @@ function db(a, b, c, e, d) { d = q.length; b = b || (h ? 100 : 0); if (1 === d) { - return gb.call(this, q[0], "", b, k, h, p, l); + return ib.call(this, q[0], "", b, k, h, p, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return gb.call(this, q[0], q[1], b, k, h, p, l); + return ib.call(this, q[0], q[1], b, k, h, p, l); } let r = B(), u = 0, v; 1 < d && f && (v = q[0], u = 1); @@ -1883,8 +1890,8 @@ function db(a, b, c, e, d) { for (let y, F; u < d; u++) { if ((F = q[u]) && !r[F]) { r[F] = 1; - y = await hb(x, F, v, 0, 0, !1, !1); - if (y = ib(y, e, g, n)) { + y = await jb(x, F, v, 0, 0, !1, !1); + if (y = kb(y, e, g, n)) { e = y; break; } @@ -1892,14 +1899,14 @@ function db(a, b, c, e, d) { } g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return jb(e, n, b, k, g, m, h); + return lb(e, n, b, k, g, m, h); }(); } for (let x, y; u < d; u++) { if ((y = q[u]) && !r[y]) { r[y] = 1; - x = hb(this, y, v, 0, 0, !1, !1); - if (x = ib(x, e, g, n)) { + x = jb(this, y, v, 0, 0, !1, !1); + if (x = kb(x, e, g, n)) { e = x; break; } @@ -1907,24 +1914,24 @@ function db(a, b, c, e, d) { } g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return jb(e, n, b, k, g, m, h); + return lb(e, n, b, k, g, m, h); }; -function jb(a, b, c, e, d, f, g) { +function lb(a, b, c, e, d, f, g) { let k = a.length, h = a; if (1 < k) { - h = Da(a, b, c, e, d, f, g); + h = Fa(a, b, c, e, d, f, g); } else if (1 === k) { - return g ? Ga.call(null, a[0], c, e) : new X(a[0]); + return g ? Ia.call(null, a[0], c, e) : new X(a[0]); } return g ? h : new X(h); } -function gb(a, b, c, e, d, f, g) { - a = hb(this, a, b, c, e, d, f, g); +function ib(a, b, c, e, d, f, g) { + a = jb(this, a, b, c, e, d, f, g); return this.db ? a.then(function(k) { return d ? k || [] : new X(k); - }) : a && a.length ? d ? Ga.call(this, a, c, e) : new X(a) : d ? [] : new X(); + }) : a && a.length ? d ? Ia.call(this, a, c, e) : new X(a) : d ? [] : new X(); } -function ib(a, b, c, e) { +function kb(a, b, c, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -1945,7 +1952,7 @@ function ib(a, b, c, e) { return d; } } -function hb(a, b, c, e, d, f, g, k) { +function jb(a, b, c, e, d, f, g, k) { let h; c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); if (a.db) { @@ -1954,7 +1961,7 @@ function hb(a, b, c, e, d, f, g, k) { a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;M.prototype.remove = function(a, b) { +;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) { @@ -1969,15 +1976,15 @@ function hb(a, b, c, e, d, f, g, k) { } } } else { - kb(this.map, a), this.depth && kb(this.ctx, a); + mb(this.map, a), this.depth && mb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && fb(this)); + this.db && (this.commit_task.push({del:a}), this.T && hb(this)); this.cache && this.cache.remove(a); return this; }; -function kb(a, b) { +function mb(a, b) { let c = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1992,24 +1999,24 @@ function kb(a, b) { } } else { for (let e of a.entries()) { - const d = e[0], f = kb(e[1], b); + const d = e[0], f = mb(e[1], b); f ? c += f : a.delete(d); } } return c; } -;function M(a, b) { - if (!this || this.constructor !== M) { - return new M(a); +;function O(a, b) { + if (!this || this.constructor !== O) { + return new O(a); } if (a) { var c = E(a) ? a : a.preset; - c && (cb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, cb[c], a)); + c && (eb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, eb[c], a)); } else { a = {}; } c = a.context; - const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || Ua; + const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? db[a.encoder] : a.encode || a.encoder || Wa; this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = c = a.tokenize || "strict"; @@ -2033,7 +2040,7 @@ function kb(a, b) { this.commit_timer = null; this.priority = a.priority || 4; } -t = M.prototype; +t = O.prototype; t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -2046,7 +2053,7 @@ t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function fb(a) { +function hb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2070,7 +2077,7 @@ t.update = function(a, b) { const c = this, e = this.remove(a); return e && e.then ? e.then(() => c.add(a, b)) : this.add(a, b); }; -function lb(a) { +function nb(a) { let b = 0; if (a.constructor === Array) { for (let c = 0, e; c < a.length; c++) { @@ -2078,7 +2085,7 @@ function lb(a) { } } else { for (const c of a) { - const e = c[0], d = lb(c[1]); + const e = c[0], d = nb(c[1]); d ? b += d : a.delete(e); } } @@ -2088,17 +2095,17 @@ t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - lb(this.map); - this.depth && lb(this.ctx); + nb(this.map); + this.depth && nb(this.ctx); return this; }; -t.searchCache = Ta; +t.searchCache = Va; t.export = function(a, b, c = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = va(this.reg); + f = xa(this.reg); break; case 1: d = "cfg"; @@ -2106,29 +2113,29 @@ t.export = function(a, b, c = 0, e = 0) { break; case 2: d = "map"; - f = ra(this.map, this.reg.size); + f = ta(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ta(this.ctx, this.reg.size); + f = va(this.ctx, this.reg.size); break; default: return; } - return xa.call(this, a, b, d, f, c, e); + return za.call(this, a, b, d, f, c, e); }; t.import = function(a, b) { if (b) { switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = wa(b, this.reg); + this.reg = ya(b, this.reg); break; case "map": - this.map = sa(b, this.map); + this.map = ua(b, this.map); break; case "ctx": - this.ctx = ua(b, this.ctx); + this.ctx = wa(b, this.ctx); } } }; @@ -2182,11 +2189,11 @@ t.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + b + e + d + "}" : b + e + d; }; -na(M.prototype); -const nb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ob = ["map", "ctx", "tag", "reg", "cfg"]; -function pb(a, b = {}) { +la(O.prototype); +const pb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), qb = ["map", "ctx", "tag", "reg", "cfg"]; +function rb(a, b = {}) { if (!this) { - return new pb(a, b); + return new rb(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2197,7 +2204,7 @@ function pb(a, b = {}) { this.db = null; this.h = {}; } -t = pb.prototype; +t = rb.prototype; t.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2209,10 +2216,10 @@ t.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const e = nb.open(a.id + (a.field ? ":" + a.field : ""), 1); + const e = pb.open(a.id + (a.field ? ":" + a.field : ""), 1); e.onupgradeneeded = function() { const d = a.db = this.result; - ob.forEach(f => { + qb.forEach(f => { d.objectStoreNames.contains(f) || d.createObjectStore(f); }); }; @@ -2238,13 +2245,13 @@ t.close = function() { this.db = null; }; t.destroy = function() { - const a = nb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const a = pb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); return Z(a); }; t.clear = function() { - const a = this.db.transaction(ob, "readwrite"); - for (let b = 0; b < ob.length; b++) { - a.objectStore(ob[b]).clear(); + const a = this.db.transaction(qb, "readwrite"); + for (let b = 0; b < qb.length; b++) { + a.objectStore(qb[b]).clear(); } return Z(a); }; @@ -2428,7 +2435,7 @@ t.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function qb(a, b, c) { +function sb(a, b, c) { const e = a.value; let d, f, g = 0; for (let k = 0, h; k < e.length; k++) { @@ -2457,17 +2464,17 @@ t.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && qb(c, a); + c && sb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && qb(c, a); + c && sb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && qb(c, a, !0); + c && sb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2487,6 +2494,6 @@ function Z(a) { a = null; }); } -;export default {Index:M, Charset:bb, Encoder:J, Document:V, Worker:N, Resolver:X, IndexedDB:pb, Language:{}}; +;export default {Index:O, Charset:db, Encoder:J, Document:V, Worker:Q, Resolver:X, IndexedDB:rb, Language:{}}; -export const Index=M;export const Charset=bb;export const Encoder=J;export const Document=V;export const Worker=N;export const Resolver=X;export const IndexedDB=pb;export const Language={}; \ No newline at end of file +export const Index=O;export const Charset=db;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=rb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index d359d0a..d43e6c5 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.107 (Bundle/Module) + * FlexSearch.js v0.8.108 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -21,72 +21,72 @@ t.addMatcher=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);i t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};async function ka(a){a=a.data;var b=self._index;const c=a.args;var e=a.task;switch(e){case "init":e=a.options||{};(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new M(e);postMessage({id:a.id});break;default:a=a.id,b=b[e].apply(b,c),postMessage("search"===e?{id:a,msg:b}:{id:a})}};let la=0; -function N(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++la]=function(){h(d)};d.worker.postMessage({id:la,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==N)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=ma(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); -function O(a){N.prototype[a]=N.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.splice(c.length-1,1));e=new Promise(function(f){b.h[++la]=f;b.worker.postMessage({task:a,id:la,args:c})});return d?(e.then(d),this):e}} -function ma(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ka.toString()],{type:"text/javascript"}))):new window.Worker(E(c)?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function na(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let Q,oa;const pa={},R={};function qa(a){Q=0;pa[a]=R[a]} -function P(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);Q||(Q=setTimeout(qa,0,a),oa=Date.now());R[a]||(R[a]=pa[a]=1E3);if(!--pa[a]){pa[a]=R[a]=R[a]*this.priority*this.priority*3/(Date.now()-oa)|0||1;Q=clearTimeout(Q);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};function ra(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function sa(a,b){b||(b=new Map);for(let c=0,e;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} +this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;const b=a.task,c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(a=a.factory)?(Function("return "+a)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e=[N.export]);"import"===b?await N.import.call(M,M):d=M[b].apply(M,e);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ma,na;const oa={},pa={};function qa(a){ma=0;oa[a]=pa[a]} +function P(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);ma||(ma=setTimeout(qa,0,a),na=Date.now());pa[a]||(pa[a]=oa[a]=1E3);if(!--oa[a]){oa[a]=pa[a]=pa[a]*this.priority*this.priority*3/(Date.now()-na)|0||1;ma=clearTimeout(ma);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let ra=0; +function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ra]=function(){h(d)};d.worker.postMessage({id:ra,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==Q)return new Q(a);let c="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=sa(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}R("add");R("append");R("search");R("update");R("remove");R("clear");R("export");R("import");la(Q.prototype); +function R(a){Q.prototype[a]=async function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.splice(c.length-1,1));e=new Promise(function(f){b.h[++ra]=f;b.worker.postMessage({task:a,id:ra,args:c})});return d?(e.then(d),this):e}} +function sa(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ka.toString()],{type:"text/javascript"}))):new window.Worker(E(c)?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function ta(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function ua(a,b){b||(b=new Map);for(let c=0,e;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;gc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= +this.C[h];if((c=l.I)&&!c(b))continue;let m;if("function"===typeof l){m=l(b);if(!m)continue;l=[l.V]}else if(E(l)||l.constructor===String){k[l]=b[l];continue}Ea(b,k,l,0,l[0],m)}}this.store.set(a,k||b)}}return this};function Ea(a,b,c,e,d,f){a=a[d];if(e===c.length-1)b[d]=f||a;else if(a)if(a.constructor===Array)for(b=b[d]=Array(a.length),d=0;dc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ea(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ha(this,"and",arguments);return Ja.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; -function Ja(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Da(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ha(this,"xor",arguments);return Ka.call(this,a,b,c,e,d,f,g)}; -function Ka(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=La.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function La(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hb?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ja(this,"and",arguments);return La.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; +function La(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; +function Ma(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Na(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.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};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Ua={normalize:function(a){return a.toLowerCase()}};const Va=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 Wa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Xa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ya={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 Za=/[\x00-\x7F]+/g;const $a=/[\x00-\x7F]+/g;const ab=/[\x00-\x7F]+/g;var bb={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ua,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Va},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Va,matcher:Wa,replacer:Xa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Va,replacer:Xa.concat([/(?!^)[aeo]/g,""]),matcher:Wa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):db(p,e,q,d,f);eb(this,m,g,h,a,c)}break}case "reverse":if(1< -d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;eb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.T&&fb(this));return this};function eb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new S(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function db(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};M.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 e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else kb(this.map,a),this.depth&&kb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&fb(this));this.cache&&this.cache.remove(a);return this}; -function kb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.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};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=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 Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const $a={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 ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):fb(p,e,q,d,f);gb(this,m,g,h,a,c)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&hb(this));return this};function gb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new S(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} +function fb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(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 e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,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.T&&hb(this));this.cache&&this.cache.remove(a);return this}; +function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; -function mb(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -t.close=function(){this.db.close();this.db=null};t.destroy=function(){const a=nb.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(ob,"readwrite");for(let b=0;b{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +t.close=function(){this.db.close();this.db=null};t.destroy=function(){const a=pb.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(qb,"readwrite");for(let b=0;b=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; t.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;em&&!f&&"string"===typeof n&&!isNaN(n)&&(m=h.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:M,Charset:bb,Encoder:J,Document:V,Worker:N,Resolver:X,IndexedDB:pb,Language:{}}; -export const Index=M;export const Charset=bb;export const Encoder=J;export const Document=V;export const Worker=N;export const Resolver=X;export const IndexedDB=pb;export const Language={}; \ No newline at end of file +function sb(a,b,c){const e=a.value;let d,f,g=0;for(let k=0,h;km&&!f&&"string"===typeof n&&!isNaN(n)&&(m=h.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:O,Charset:db,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:rb,Language:{}}; +export const Index=O;export const Charset=db;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=rb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index dc68519..3baf3af 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.107 (Bundle/Debug) + * FlexSearch.js v0.8.108 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -47,14 +47,14 @@ function A(a, c, b) { function C() { return Object.create(null); } -function E(a) { +function D(a) { return "string" === typeof a; } -function I(a) { +function H(a) { return "object" === typeof a; } function J(a, c) { - if (E(c)) { + if (D(c)) { a = a[c]; } else { for (let b = 0; a && b < c.length; b++) { @@ -262,30 +262,48 @@ function L(a) { a.F.clear(); a.G.clear(); } -;function ia(a) { - M.call(a, "add"); - M.call(a, "append"); - M.call(a, "search"); - M.call(a, "update"); - M.call(a, "remove"); +;let M, N; +async function ia(a) { + a = a.data; + const c = a.task, b = a.id; + let e = a.args; + switch(c) { + case "init": + N = a.options || {}; + (a = a.factory) ? (Function("return " + a)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + postMessage({id:b}); + break; + default: + let d; + "export" === c && (e = [N.export]); + "import" === c ? await N.import.call(M, M) : d = M[c].apply(M, e); + postMessage("search" === c ? {id:b, msg:d} : {id:b}); + } } -let N, ja; -const O = {}, P = {}; -function ka(a) { - N = 0; - O[a] = P[a]; +;function ja(a) { + P.call(a, "add"); + P.call(a, "append"); + P.call(a, "search"); + P.call(a, "update"); + P.call(a, "remove"); } -function M(a) { +let Q, ka; +const R = {}, S = {}; +function la(a) { + Q = 0; + R[a] = S[a]; +} +function P(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; let e; "function" === typeof b && (e = b, delete c[c.length - 1]); - N || (N = setTimeout(ka, 0, a), ja = Date.now()); - P[a] || (P[a] = O[a] = 1000); - if (!--O[a]) { - O[a] = P[a] = P[a] * this.priority * this.priority * 3 / (Date.now() - ja) | 0 || 1; - N = clearTimeout(N); + Q || (Q = setTimeout(la, 0, a), ka = Date.now()); + S[a] || (S[a] = R[a] = 1000); + if (!--R[a]) { + R[a] = S[a] = S[a] * this.priority * this.priority * 3 / (Date.now() - ka) | 0 || 1; + Q = clearTimeout(Q); const f = this; return new Promise(g => { setTimeout(function() { @@ -299,7 +317,67 @@ function M(a) { return b; }; } -;function la(a, c = 0) { +;let T = 0; +function ma(a = {}) { + function c(g) { + function h(k) { + k = k.data || k; + const l = k.id, m = l && d.h[l]; + m && (m(k.msg), delete d.h[l]); + } + this.worker = g; + this.h = C(); + if (this.worker) { + e ? this.worker.on("message", h) : this.worker.onmessage = h; + if (a.config) { + return new Promise(function(k) { + d.h[++T] = function() { + k(d); + }; + d.worker.postMessage({id:T, task:"init", factory:b, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:b, options:a}); + return this; + } + } + if (!this || this.constructor !== ma) { + return new ma(a); + } + let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + b && (b = b.toString()); + const e = "undefined" === typeof window, d = this, f = na(b, e, a.worker); + return f.then ? f.then(function(g) { + return c.call(d, g); + }) : c.call(this, f); +} +U("add"); +U("append"); +U("search"); +U("update"); +U("remove"); +U("clear"); +U("export"); +U("import"); +ja(ma.prototype); +function U(a) { + ma.prototype[a] = async function() { + const c = this, b = [].slice.call(arguments); + var e = b[b.length - 1]; + let d; + "function" === typeof e && (d = e, b.splice(b.length - 1, 1)); + e = new Promise(function(f) { + c.h[++T] = f; + c.worker.postMessage({task:a, id:T, args:b}); + }); + return d ? (e.then(d), this) : e; + }; +} +function na(a, c, b) { + return c ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ia.toString()], {type:"text/javascript"}))) : new window.Worker(D(b) ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function oa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -308,30 +386,30 @@ function M(a) { e.length && b.push(e); return b; } -function ma(a, c) { +function pa(a, c) { c || (c = new Map()); for (let b = 0, e; b < a.length; b++) { e = a[b], c.set(e[0], e[1]); } return c; } -function na(a, c = 0) { +function qa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], la(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], oa(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function oa(a, c) { +function ra(a, c) { c || (c = new Map()); for (let b = 0, e, d; b < a.length; b++) { - e = a[b], d = c.get(e[0]), c.set(e[0], ma(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], pa(e[1], d)); } return c; } -function pa(a) { +function sa(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -339,14 +417,14 @@ function pa(a) { b.length && c.push(b); return c; } -function qa(a, c) { +function ta(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function Q(a, c, b, e, d, f, g = 0) { +function ua(a, c, b, e, d, f, g = 0) { const h = e && e.constructor === Array; var k = h ? e.shift() : e; if (!k) { @@ -355,13 +433,13 @@ function Q(a, c, b, e, d, f, g = 0) { if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { const l = this; return k.then(function() { - return Q.call(l, a, c, b, h ? e : null, d, f, g + 1); + return ua.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return Q.call(this, a, c, b, h ? e : null, d, f, g + 1); + return ua.call(this, a, c, b, h ? e : null, d, f, g + 1); } -;R.prototype.add = function(a, c, b) { - I(a) && (c = a, a = J(c, this.key)); +;V.prototype.add = function(a, c, b) { + H(a) && (c = a, a = J(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -374,7 +452,7 @@ function Q(a, c, b, e, d, f, g = 0) { d && e.add(a, d, !1, !0); } else { if (d = k.I, !d || d(c)) { - k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), ra(c, k, this.J, 0, e, a, k[0], b); + k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), va(c, k, this.J, 0, e, a, k[0], b); } } } @@ -396,7 +474,7 @@ function Q(a, c, b, e, d, f, g = 0) { f = J(c, f); } if (d && f) { - E(f) && (f = [f]); + D(f) && (f = [f]); for (let k = 0, l, m; k < f.length; k++) { l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } @@ -421,11 +499,11 @@ function Q(a, c, b, e, d, f, g = 0) { continue; } l = [l.U]; - } else if (E(l) || l.constructor === String) { + } else if (D(l) || l.constructor === String) { h[l] = c[l]; continue; } - sa(c, h, l, 0, l[0], m); + wa(c, h, l, 0, l[0], m); } } this.store.set(a, h || c); @@ -433,21 +511,21 @@ function Q(a, c, b, e, d, f, g = 0) { } return this; }; -function sa(a, c, b, e, d, f) { +function wa(a, c, b, e, d, f) { a = a[d]; if (e === b.length - 1) { c[d] = f || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - sa(a, c, b, e, d); + wa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], sa(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], wa(a, c, b, e, d); } } } -function ra(a, c, b, e, d, f, g, h) { +function va(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -463,15 +541,15 @@ function ra(a, c, b, e, d, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - ra(a, c, b, e, d, f, g, h); + va(a, c, b, e, d, f, g, h); } } else { - g = c[++e], ra(a, c, b, e, d, f, g, h); + g = c[++e], va(a, c, b, e, d, f, g, h); } } } } -;function ta(a, c, b, e, d) { +;function xa(a, c, b, e, d) { const f = a.length; let g = [], h, k; h = C(); @@ -486,7 +564,7 @@ function ra(a, c, b, e, d, f, g, h) { } if (a = g.length) { if (d) { - g = 1 < g.length ? ua(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -501,7 +579,7 @@ function ra(a, c, b, e, d, f, g, h) { } return g; } -function ua(a, c, b) { +function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; @@ -523,7 +601,7 @@ function ua(a, c, b) { } return e; } -function va(a, c, b) { +function za(a, c, b) { const e = C(), d = []; for (let f = 0, g; f < c.length; f++) { g = c[f]; @@ -544,12 +622,12 @@ function va(a, c, b) { } return d; } -;function wa(a, c, b, e) { +;function Aa(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? S.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; } let d = []; for (let f = 0, g, h; f < a.length; f++) { @@ -563,7 +641,7 @@ function va(a, c, b) { } h > c && (g = g.slice(0, c), h = c); if (!d.length && h >= c) { - return e ? S.call(this, g) : g; + return e ? W.call(this, g) : g; } d.push(g); c -= h; @@ -573,9 +651,9 @@ function va(a, c, b) { } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? S.call(this, d) : d; + return e ? W.call(this, d) : d; } -;function T(a, c, b) { +;function Ba(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -590,7 +668,7 @@ function va(a, c, b) { for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { let t; - if (n.constructor === U) { + if (n.constructor === X) { t = n.result; } else if (n.constructor === Array) { t = n; @@ -621,11 +699,11 @@ function va(a, c, b) { } return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; } -;U.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = T(this, "or", arguments); - return xa.call(this, a, c, b, e, d, f); +;X.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); + return Ca.call(this, a, c, b, e, d, f); }; -function xa(a, c, b, e, d, f) { +function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; return Promise.all(c).then(function(h) { @@ -633,25 +711,25 @@ function xa(a, c, b, e, d, f) { for (let k = 0, l; k < h.length; k++) { (l = h[k]).length && (a[k] = l); } - return xa.call(g, a, [], b, e, d, f); + return Ca.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ua(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ya(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } -;U.prototype.and = function() { +;X.prototype.and = function() { let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = T(this, "and", arguments); - return ya.call(this, f, g, h, k, l, m, n); + const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); + return Da.call(this, f, g, h, k, l, m, n); } return d ? this.resolve(c, b, e) : this; }; -function ya(a, c, b, e, d, f, g) { +function Da(a, c, b, e, d, f, g) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -659,7 +737,7 @@ function ya(a, c, b, e, d, f, g) { for (let l = 0, m; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return ya.call(h, a, [], b, e, d, f, g); + return Da.call(h, a, [], b, e, d, f, g); }); } if (a.length) { @@ -667,7 +745,7 @@ function ya(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = ta(a, c, b, e, g), f ? d ? S.call(this.index, this.result) : this.result : this; + return this.result = xa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -676,11 +754,11 @@ function ya(a, c, b, e, d, f, g) { } return f ? this.resolve(b, e, d) : this; } -;U.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = T(this, "xor", arguments); - return za.call(this, a, c, b, e, d, f, g); +;X.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); + return Ea.call(this, a, c, b, e, d, f, g); }; -function za(a, c, b, e, d, f, g) { +function Ea(a, c, b, e, d, f, g) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -688,21 +766,21 @@ function za(a, c, b, e, d, f, g) { for (let l = 0, m; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return za.call(h, a, [], b, e, d, f, g); + return Ea.call(h, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Aa.call(this, a, b, e, f, this.h), f ? d ? S.call(this.index, this.result) : this.result : this; + return this.result = Fa.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Aa(a, c, b, e, d) { +function Fa(a, c, b, e, d) { const f = [], g = C(); let h = 0; for (let k = 0, l; k < a.length; k++) { @@ -747,11 +825,11 @@ function Aa(a, c, b, e, d) { } return f; } -;U.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = T(this, "not", arguments); - return Ba.call(this, a, c, b, e, d, f, g); +;X.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); + return Ga.call(this, a, c, b, e, d, f, g); }; -function Ba(a, c, b, e, d, f, g) { +function Ga(a, c, b, e, d, f, g) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -759,17 +837,17 @@ function Ba(a, c, b, e, d, f, g) { for (let l = 0, m; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return Ba.call(h, a, [], b, e, d, f, g); + return Ga.call(h, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ca.call(this, a, b, e, f); + this.result = Ha.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? S.call(this.index, this.result) : this.result : this; + return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Ca(a, c, b, e) { +function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, h = 0; f < this.result.length; f++) { @@ -795,9 +873,9 @@ function Ca(a, c, b, e) { } return d; } -;function U(a) { - if (!this || this.constructor !== U) { - return new U(a); +;function X(a) { + if (!this || this.constructor !== X) { + return new X(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -806,7 +884,7 @@ function Ca(a, c, b, e) { this.result = a || []; this.h = 0; } -U.prototype.limit = function(a) { +X.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -825,7 +903,7 @@ U.prototype.limit = function(a) { } return this; }; -U.prototype.offset = function(a) { +X.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -837,18 +915,18 @@ U.prototype.offset = function(a) { } return this; }; -U.prototype.boost = function(a) { +X.prototype.boost = function(a) { this.h += a; return this; }; -U.prototype.resolve = function(a, c, b) { +X.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), wa.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; }; C(); -R.prototype.search = function(a, c, b, e) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); +V.prototype.search = function(a, c, b, e) { + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let d = []; var f = []; let g, h, k, l, m, n, t = 0, p, q; @@ -872,7 +950,7 @@ R.prototype.search = function(a, c, b, e) { var u = []; for (let x = 0, r; x < m.length; x++) { r = m[x]; - if (E(r)) { + if (D(r)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (r.field && r.tag) { @@ -886,8 +964,8 @@ R.prototype.search = function(a, c, b, e) { } } else { v = Object.keys(r); - for (let D = 0, F, B; D < v.length; D++) { - if (F = v[D], B = r[F], B.constructor === Array) { + for (let E = 0, F, B; E < v.length; E++) { + if (F = v[E], B = r[F], B.constructor === Array) { for (z = 0; z < B.length; z++) { u.push(F, B[z]); } @@ -905,7 +983,7 @@ R.prototype.search = function(a, c, b, e) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - y = Da.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); + y = Ia.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); } } return e.length ? Promise.all(e).then(function(x) { @@ -920,14 +998,14 @@ R.prototype.search = function(a, c, b, e) { } l || (l = this.field); u = !e && (this.worker || this.db) && []; - for (let x = 0, r, D, F; x < l.length; x++) { - D = l[x]; + for (let x = 0, r, E, F; x < l.length; x++) { + E = l[x]; let B; - E(D) || (B = D, D = B.field, a = B.query || a, c = B.limit || c, n = B.offset || n, k = B.suggest || k, g = this.store && (B.enrich || g)); + D(E) || (B = E, E = B.field, a = B.query || a, c = B.limit || c, n = B.offset || n, k = B.suggest || k, g = this.store && (B.enrich || g)); if (e) { r = e[x]; } else { - if (v = B || b, z = this.index.get(D), m && (v.enrich = !1), u) { + if (v = B || b, z = this.index.get(E), m && (v.enrich = !1), u) { u[x] = z.search(a, c, v); v && g && (v.enrich = g); continue; @@ -939,34 +1017,34 @@ R.prototype.search = function(a, c, b, e) { if (m && F) { v = []; z = 0; - for (let G = 0, H, Ta; G < m.length; G += 2) { - H = this.tag.get(m[G]); - if (!H) { + for (let G = 0, I, $a; G < m.length; G += 2) { + I = this.tag.get(m[G]); + if (!I) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { continue; } else { - return p ? d : new U(d); + return p ? d : new X(d); } } - if (Ta = (H = H && H.get(m[G + 1])) && H.length) { - z++, v.push(H); + if ($a = (I = I && I.get(m[G + 1])) && I.length) { + z++, v.push(I); } else if (!k) { - return p ? d : new U(d); + return p ? d : new X(d); } } if (z) { - r = va(r, v, p); + r = za(r, v, p); F = r.length; if (!F && !k) { - return p ? r : new U(r); + return p ? r : new X(r); } z--; } } if (F) { - f[t] = D, d.push(r), t++; + f[t] = E, d.push(r), t++; } else if (1 === l.length) { - return p ? d : new U(d); + return p ? d : new X(d); } } if (u) { @@ -976,7 +1054,7 @@ R.prototype.search = function(a, c, b, e) { }); } if (!t) { - return p ? d : new U(d); + return p ? d : new X(d); } if (y && (!g || !this.store)) { return d[0]; @@ -984,15 +1062,15 @@ R.prototype.search = function(a, c, b, e) { u = []; for (let x = 0, r; x < f.length; x++) { r = d[x]; - g && r.length && !r[0].doc && (r = S.call(this, r)); + g && r.length && !r[0].doc && (r = W.call(this, r)); if (y) { - return p ? r : new U(r); + return p ? r : new X(r); } d[x] = {field:f[x], result:r}; } - return h ? Ea(d, c) : q ? Fa(d, a, this.index, this.field, this.C, q) : d; + return h ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; }; -function Fa(a, c, b, e, d, f) { +function Ka(a, c, b, e, d, f) { let g, h, k; for (let m = 0, n, t, p, q, y; m < a.length; m++) { n = a[m].result; @@ -1007,21 +1085,21 @@ function Fa(a, c, b, e, d, f) { var l = J(n[u].doc, y); let z = g.encode(l); l = l.split(g.split); - for (let x = 0, r, D; x < z.length; x++) { + for (let x = 0, r, E; x < z.length; x++) { r = z[x]; - D = l[x]; + E = l[x]; let F; for (let B = 0, G; B < h.length; B++) { if (G = h[B], "strict" === k) { if (r === G) { - v += (v ? " " : "") + f.replace("$1", D); + v += (v ? " " : "") + f.replace("$1", E); F = !0; break; } } else { - const H = r.indexOf(G); - if (-1 < H) { - v += (v ? " " : "") + D.substring(0, H) + f.replace("$1", D.substring(H, G.length)) + D.substring(H + G.length); + const I = r.indexOf(G); + if (-1 < I) { + v += (v ? " " : "") + E.substring(0, I) + f.replace("$1", E.substring(I, G.length)) + E.substring(I + G.length); F = !0; break; } @@ -1034,7 +1112,7 @@ function Fa(a, c, b, e, d, f) { } return a; } -function Ea(a, c) { +function Ja(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1053,7 +1131,7 @@ function Ea(a, c) { } return b; } -function Da(a, c, b, e, d) { +function Ia(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1062,11 +1140,11 @@ function Da(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = S.call(this, f)); + d && (f = W.call(this, f)); return f; } } -function S(a) { +function W(a) { if (!this || !this.store) { return a; } @@ -1076,32 +1154,32 @@ function S(a) { } return c; } -;function R(a) { - if (!this || this.constructor !== R) { - return new R(a); +;function V(a) { + if (!this || this.constructor !== V) { + return new V(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && V(b, this.J) || "id"; + this.key = (b = c.key || c.id) && La(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); - this.cache = (b = a.cache || null) && new W(b); + this.cache = (b = a.cache || null) && new Y(b); a.cache = !1; b = new Map(); let e = c.index || c.field || c; - E(e) && (e = [e]); + D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], E(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new X(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = V(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; - E(a) && (a = [a]); + D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = V(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1117,14 +1195,14 @@ function S(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = V(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function V(a, c) { +function La(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1133,7 +1211,7 @@ function V(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -w = R.prototype; +w = V.prototype; w.append = function(a, c) { return this.add(a, c, !0); }; @@ -1141,7 +1219,7 @@ w.update = function(a, c) { return this.remove(a).add(a, c); }; w.remove = function(a) { - I(a) && (a = J(a, this.key)); + H(a) && (a = J(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1189,7 +1267,7 @@ w.set = function(a, c) { this.store.set(a, c); return this; }; -w.searchCache = Ga; +w.searchCache = Ma; w.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; @@ -1205,17 +1283,17 @@ w.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = pa(this.reg); + f = sa(this.reg); c = null; break; case 1: d = "tag"; - f = na(this.tag, this.reg.size); + f = qa(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = la(this.store); + f = oa(this.store); c = null; break; case 3: @@ -1225,7 +1303,7 @@ w.export = function(a, c, b = 0, e = 0) { default: return; } - return Q.call(this, a, c, d, f, b, e); + return ua.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { if (c) { @@ -1240,23 +1318,23 @@ w.import = function(a, c) { switch(a) { case "reg": this.fastupdate = !1; - this.reg = qa(c, this.reg); + this.reg = ta(c, this.reg); for (let e = 0, d; e < this.field.length; e++) { d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = oa(c, this.tag); + this.tag = ra(c, this.tag); break; case "doc": - this.store = ma(c, this.store); + this.store = pa(c, this.store); } } }; -ia(R.prototype); -function Ga(a, c, b) { +ja(V.prototype); +function Ma(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new W()); + this.cache || (this.cache = new Y()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -1271,56 +1349,56 @@ function Ga(a, c, b) { } return e; } -function W(a) { +function Y(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -W.prototype.set = function(a, c) { +Y.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); }; -W.prototype.get = function(a) { +Y.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; }; -W.prototype.remove = function(a) { +Y.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -W.prototype.clear = function() { +Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ha = {normalize:function(a) { +const Na = {normalize:function(a) { return a.toLowerCase(); }}; -const 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"]]); -const Ja = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ka = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const 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}; -const Ma = /[\x00-\x7F]+/g; -const Na = /[\x00-\x7F]+/g; -const 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, matcher:Ja, replacer:Ka}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ia, replacer:Ka.concat([/(?!^)[aeo]/g, ""]), matcher:Ja}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +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([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +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, matcher:Pa, replacer:Qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = La[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = La[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Ra[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[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(Ma, " "); + return ("" + a).replace(Sa, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Na, ""); + return ("" + a).replace(Ta, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Oa, " "); + return ("" + a).replace(Ua, " "); }}}; -const Qa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -X.prototype.add = function(a, c, b, e) { +const Wa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -1332,14 +1410,14 @@ X.prototype.add = function(a, c, b, e) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Y(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Xa(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var h = d; h > f; h--) { g = q.substring(f, h); - var k = this.score ? this.score(c, q, p, g, f) : Y(t, e, p, d, f); + var k = this.score ? this.score(c, q, p, g, f) : Xa(t, e, p, d, f); Z(this, m, g, k, a, b); } } @@ -1348,7 +1426,7 @@ X.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : Y(t, e, p, d, h), Z(this, m, g, k, a, b); + g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : Xa(t, e, p, d, h), Z(this, m, g, k, a, b); } g = ""; } @@ -1364,7 +1442,7 @@ X.prototype.add = function(a, c, b, e) { for (d = C(), g = this.S, f = q, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { d[q] = 1; - const y = this.score ? this.score(c, f, p, q, k) : Y(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; + const y = this.score ? this.score(c, f, p, q, k) : Xa(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, y, a, b, u ? q : f); } } @@ -1383,11 +1461,11 @@ function Z(a, c, b, e, d, f, g) { g ? (c = k || (c[b] = C()), 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 Y(a, c, b, e, d) { +function Xa(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;X.prototype.search = function(a, c, b) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); +;O.prototype.search = function(a, c, b) { + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { a = b.query || a; @@ -1404,11 +1482,11 @@ function Y(a, c, b, e, d) { a = b.length; c = c || (h ? 100 : 0); if (1 === a) { - return Ra.call(this, b[0], "", c, d, h); + return Ya.call(this, b[0], "", c, d, h); } f = this.depth && !1 !== f; if (2 === a && f && !g) { - return Ra.call(this, b[0], b[1], c, d, h); + return Ya.call(this, b[0], b[1], c, d, h); } h = C(); let l = 0; @@ -1420,7 +1498,7 @@ function Y(a, c, b, e, d) { for (let q, y; l < a; l++) { if ((y = b[l]) && !h[y]) { h[y] = 1; - q = Sa(this, y, m); + q = Za(this, y, m); a: { f = q; var n = e, t = g, p = k; @@ -1456,27 +1534,27 @@ function Y(a, c, b, e, d) { m = e.length; a = e; if (1 < m) { - a = ta(e, k, c, d, g); + a = xa(e, k, c, d, g); } else if (1 === m) { - g = wa.call(null, e[0], c, d); + g = Aa.call(null, e[0], c, d); break a; } g = a; } return g; }; -function Ra(a, c, b, e, d) { - a = Sa(this, a, c); +function Ya(a, c, b, e, d) { + a = Za(this, a, c); d = !0; - return a && a.length ? d ? wa.call(this, a, b, e) : new U(a) : d ? [] : new U(); + return a && a.length ? d ? Aa.call(this, a, b, e) : new X(a) : d ? [] : new X(); } -function Sa(a, c, b) { +function Za(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;X.prototype.remove = function(a, c) { +;O.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) { @@ -1491,14 +1569,14 @@ function Sa(a, c, b) { } } } else { - Ua(this.map, a), this.depth && Ua(this.ctx, a); + ab(this.map, a), this.depth && ab(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Ua(a, c) { +function ab(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1513,24 +1591,24 @@ function Ua(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = Ua(e[1], c); + const d = e[0], f = ab(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function X(a, c) { - if (!this || this.constructor !== X) { - return new X(a); +;function O(a, c) { + if (!this || this.constructor !== O) { + return new O(a); } if (a) { - var b = E(a) ? a : a.preset; - b && (Qa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Qa[b], a)); + var b = D(a) ? a : a.preset; + b && (Wa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Wa[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? Pa[a.encoder] : a.encode || a.encoder || Ha; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = a.tokenize || "strict"; @@ -1544,10 +1622,10 @@ function Ua(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.S = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new W(b); + this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; } -w = X.prototype; +w = O.prototype; w.clear = function() { this.map.clear(); this.ctx.clear(); @@ -1565,7 +1643,7 @@ w.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 Va(a) { +function bb(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1573,7 +1651,7 @@ function Va(a) { } } else { for (const b of a) { - const e = b[0], d = Va(b[1]); + const e = b[0], d = bb(b[1]); d ? c += d : a.delete(e); } } @@ -1583,17 +1661,17 @@ w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Va(this.map); - this.depth && Va(this.ctx); + bb(this.map); + this.depth && bb(this.ctx); return this; }; -w.searchCache = Ga; +w.searchCache = Ma; w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = pa(this.reg); + f = sa(this.reg); break; case 1: d = "cfg"; @@ -1601,29 +1679,29 @@ w.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = la(this.map, this.reg.size); + f = oa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = na(this.ctx, this.reg.size); + f = qa(this.ctx, this.reg.size); break; default: return; } - return Q.call(this, a, c, d, f, b, e); + return ua.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = qa(c, this.reg); + this.reg = ta(c, this.reg); break; case "map": - this.map = ma(c, this.map); + this.map = pa(c, this.map); break; case "ctx": - this.ctx = oa(c, this.ctx); + this.ctx = ra(c, this.ctx); } } }; @@ -1677,10 +1755,10 @@ w.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ia(X.prototype); -const Wa = {Index:X, Charset:Pa, Encoder:K, Document:R, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Xa = self; -let Ya; -(Ya = Xa.define) && Ya.amd ? Ya([], function() { - return Wa; -}) : "object" === typeof Xa.exports ? Xa.exports = Wa : Xa.FlexSearch = Wa; +ja(O.prototype); +const cb = {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, db = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; +let eb; +(eb = db.define) && eb.amd ? eb([], function() { + return cb; +}) : "object" === typeof db.exports ? db.exports = cb : db.FlexSearch = cb; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 1bacee9..d5e4856 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,12 +1,12 @@ /**! - * FlexSearch.js v0.8.107 (Bundle) + * FlexSearch.js v0.8.108 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';var v;function A(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function E(a){return"string"===typeof a} -function H(a){return"object"===typeof a}function J(a,c){if(E(c))a=a[c];else for(let b=0;a&&bthis.stemmer.get(k)),g.lengththis.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&d -this.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};function ia(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}let N,ja;const O={},P={};function ka(a){N=0;O[a]=P[a]} -function M(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);N||(N=setTimeout(ka,0,a),ja=Date.now());P[a]||(P[a]=O[a]=1E3);if(!--O[a]){O[a]=P[a]=P[a]*this.priority*this.priority*3/(Date.now()-ja)|0||1;N=clearTimeout(N);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};function la(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function ma(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function ua(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?S.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?S.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ua(a,b,e),e=0));return f?this.resolve(b,e,d):this};U.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=T(this,"and",arguments);return ya.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; -function ya(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=ta(a,c,b,e,g),f?d?S.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};U.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=T(this,"xor",arguments);return za.call(this,a,c,b,e,d,f,g)}; -function za(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Aa.call(this,a,b,e,f,this.h),f?d?S.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Aa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kthis.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;const c=a.task,b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(a=a.factory)?(Function("return "+a)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e=[N.export]);"import"===c?await N.import.call(M,M):d=M[c].apply(M,e);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let Q,ka;const R={},S={};function la(a){Q=0;R[a]=S[a]} +function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);Q||(Q=setTimeout(la,0,a),ka=Date.now());S[a]||(S[a]=R[a]=1E3);if(!--R[a]){R[a]=S[a]=S[a]*this.priority*this.priority*3/(Date.now()-ka)|0||1;Q=clearTimeout(Q);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let T=0; +function ma(a={}){function c(g){function h(k){k=k.data||k;const l=k.id,m=l&&d.h[l];m&&(m(k.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++T]=function(){k(d)};d.worker.postMessage({id:T,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==ma)return new ma(a);let b="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;b&&(b=b.toString());const e="undefined"===typeof window,d=this,f=na(b,e,a.worker);return f.then?f.then(function(g){return c.call(d,g)}):c.call(this,f)}U("add");U("append");U("search");U("update");U("remove");U("clear");U("export");U("import");ja(ma.prototype); +function U(a){ma.prototype[a]=async function(){const c=this,b=[].slice.call(arguments);var e=b[b.length-1];let d;"function"===typeof e&&(d=e,b.splice(b.length-1,1));e=new Promise(function(f){c.h[++T]=f;c.worker.postMessage({task:a,id:T,args:b})});return d?(e.then(d),this):e}} +function na(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ia.toString()],{type:"text/javascript"}))):new window.Worker(D(b)?b:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function oa(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function pa(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?W.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=S.call(this,a));return a}} -function S(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -W.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};W.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};W.prototype.clear=function(){this.cache.clear();this.h=""};const Ha={normalize:function(a){return a.toLowerCase()}};const 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"]]);const Ja=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ka=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const 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};const Ma=/[\x00-\x7F]+/g;const Na=/[\x00-\x7F]+/g;const 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,matcher:Ja,replacer:Ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka.concat([/(?!^)[aeo]/g,""]),matcher:Ja},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):Y(t,e,p,d,f);Z(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),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=C()),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 Y(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};X.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 Ua(this.map,a),this.depth&&Ua(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Ua(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function Va(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}} +function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.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};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};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([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];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,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):Xa(t,e,p,d,f);Z(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),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=C()),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 Xa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.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 ab(this.map,a),this.depth&&ab(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function ab(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function bb(a){let c=0;if(a.constructor===Array)for(let b=0,e;b { setTimeout(function() { @@ -298,7 +316,67 @@ function M(a) { return b; }; } -;function la(a, c = 0) { +;let T = 0; +function ma(a = {}) { + function c(g) { + function h(k) { + k = k.data || k; + const l = k.id, m = l && d.h[l]; + m && (m(k.msg), delete d.h[l]); + } + this.worker = g; + this.h = C(); + if (this.worker) { + e ? this.worker.on("message", h) : this.worker.onmessage = h; + if (a.config) { + return new Promise(function(k) { + d.h[++T] = function() { + k(d); + }; + d.worker.postMessage({id:T, task:"init", factory:b, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:b, options:a}); + return this; + } + } + if (!this || this.constructor !== ma) { + return new ma(a); + } + let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + b && (b = b.toString()); + const e = "undefined" === typeof window, d = this, f = na(b, e, a.worker); + return f.then ? f.then(function(g) { + return c.call(d, g); + }) : c.call(this, f); +} +U("add"); +U("append"); +U("search"); +U("update"); +U("remove"); +U("clear"); +U("export"); +U("import"); +ja(ma.prototype); +function U(a) { + ma.prototype[a] = async function() { + const c = this, b = [].slice.call(arguments); + var e = b[b.length - 1]; + let d; + "function" === typeof e && (d = e, b.splice(b.length - 1, 1)); + e = new Promise(function(f) { + c.h[++T] = f; + c.worker.postMessage({task:a, id:T, args:b}); + }); + return d ? (e.then(d), this) : e; + }; +} +function na(a, c, b) { + return c ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ia.toString()], {type:"text/javascript"}))) : new window.Worker(D(b) ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function oa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -307,30 +385,30 @@ function M(a) { e.length && b.push(e); return b; } -function ma(a, c) { +function pa(a, c) { c || (c = new Map()); for (let b = 0, e; b < a.length; b++) { e = a[b], c.set(e[0], e[1]); } return c; } -function na(a, c = 0) { +function qa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], la(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], oa(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function oa(a, c) { +function ra(a, c) { c || (c = new Map()); for (let b = 0, e, d; b < a.length; b++) { - e = a[b], d = c.get(e[0]), c.set(e[0], ma(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], pa(e[1], d)); } return c; } -function pa(a) { +function sa(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -338,14 +416,14 @@ function pa(a) { b.length && c.push(b); return c; } -function qa(a, c) { +function ta(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function Q(a, c, b, e, d, f, g = 0) { +function ua(a, c, b, e, d, f, g = 0) { const h = e && e.constructor === Array; var k = h ? e.shift() : e; if (!k) { @@ -354,13 +432,13 @@ function Q(a, c, b, e, d, f, g = 0) { if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { const l = this; return k.then(function() { - return Q.call(l, a, c, b, h ? e : null, d, f, g + 1); + return ua.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return Q.call(this, a, c, b, h ? e : null, d, f, g + 1); + return ua.call(this, a, c, b, h ? e : null, d, f, g + 1); } -;R.prototype.add = function(a, c, b) { - I(a) && (c = a, a = J(c, this.key)); +;V.prototype.add = function(a, c, b) { + H(a) && (c = a, a = J(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -373,7 +451,7 @@ function Q(a, c, b, e, d, f, g = 0) { d && e.add(a, d, !1, !0); } else { if (d = k.I, !d || d(c)) { - k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), ra(c, k, this.J, 0, e, a, k[0], b); + k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), va(c, k, this.J, 0, e, a, k[0], b); } } } @@ -395,7 +473,7 @@ function Q(a, c, b, e, d, f, g = 0) { f = J(c, f); } if (d && f) { - E(f) && (f = [f]); + D(f) && (f = [f]); for (let k = 0, l, m; k < f.length; k++) { l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } @@ -420,11 +498,11 @@ function Q(a, c, b, e, d, f, g = 0) { continue; } l = [l.U]; - } else if (E(l) || l.constructor === String) { + } else if (D(l) || l.constructor === String) { h[l] = c[l]; continue; } - sa(c, h, l, 0, l[0], m); + wa(c, h, l, 0, l[0], m); } } this.store.set(a, h || c); @@ -432,21 +510,21 @@ function Q(a, c, b, e, d, f, g = 0) { } return this; }; -function sa(a, c, b, e, d, f) { +function wa(a, c, b, e, d, f) { a = a[d]; if (e === b.length - 1) { c[d] = f || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - sa(a, c, b, e, d); + wa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], sa(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], wa(a, c, b, e, d); } } } -function ra(a, c, b, e, d, f, g, h) { +function va(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -462,15 +540,15 @@ function ra(a, c, b, e, d, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - ra(a, c, b, e, d, f, g, h); + va(a, c, b, e, d, f, g, h); } } else { - g = c[++e], ra(a, c, b, e, d, f, g, h); + g = c[++e], va(a, c, b, e, d, f, g, h); } } } } -;function ta(a, c, b, e, d) { +;function xa(a, c, b, e, d) { const f = a.length; let g = [], h, k; h = C(); @@ -485,7 +563,7 @@ function ra(a, c, b, e, d, f, g, h) { } if (a = g.length) { if (d) { - g = 1 < g.length ? ua(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -500,7 +578,7 @@ function ra(a, c, b, e, d, f, g, h) { } return g; } -function ua(a, c, b) { +function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; @@ -522,7 +600,7 @@ function ua(a, c, b) { } return e; } -function va(a, c, b) { +function za(a, c, b) { const e = C(), d = []; for (let f = 0, g; f < c.length; f++) { g = c[f]; @@ -543,12 +621,12 @@ function va(a, c, b) { } return d; } -;function wa(a, c, b, e) { +;function Aa(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? S.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; } let d = []; for (let f = 0, g, h; f < a.length; f++) { @@ -562,7 +640,7 @@ function va(a, c, b) { } h > c && (g = g.slice(0, c), h = c); if (!d.length && h >= c) { - return e ? S.call(this, g) : g; + return e ? W.call(this, g) : g; } d.push(g); c -= h; @@ -572,9 +650,9 @@ function va(a, c, b) { } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? S.call(this, d) : d; + return e ? W.call(this, d) : d; } -;function T(a, c, b) { +;function Ba(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -589,7 +667,7 @@ function va(a, c, b) { for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { let t; - if (n.constructor === U) { + if (n.constructor === X) { t = n.result; } else if (n.constructor === Array) { t = n; @@ -620,11 +698,11 @@ function va(a, c, b) { } return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; } -;U.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = T(this, "or", arguments); - return xa.call(this, a, c, b, e, d, f); +;X.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); + return Ca.call(this, a, c, b, e, d, f); }; -function xa(a, c, b, e, d, f) { +function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; return Promise.all(c).then(function(h) { @@ -632,25 +710,25 @@ function xa(a, c, b, e, d, f) { for (let k = 0, l; k < h.length; k++) { (l = h[k]).length && (a[k] = l); } - return xa.call(g, a, [], b, e, d, f); + return Ca.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ua(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ya(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } -;U.prototype.and = function() { +;X.prototype.and = function() { let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = T(this, "and", arguments); - return ya.call(this, f, g, h, k, l, m, n); + const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); + return Da.call(this, f, g, h, k, l, m, n); } return d ? this.resolve(c, b, e) : this; }; -function ya(a, c, b, e, d, f, g) { +function Da(a, c, b, e, d, f, g) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -658,7 +736,7 @@ function ya(a, c, b, e, d, f, g) { for (let l = 0, m; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return ya.call(h, a, [], b, e, d, f, g); + return Da.call(h, a, [], b, e, d, f, g); }); } if (a.length) { @@ -666,7 +744,7 @@ function ya(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = ta(a, c, b, e, g), f ? d ? S.call(this.index, this.result) : this.result : this; + return this.result = xa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -675,11 +753,11 @@ function ya(a, c, b, e, d, f, g) { } return f ? this.resolve(b, e, d) : this; } -;U.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = T(this, "xor", arguments); - return za.call(this, a, c, b, e, d, f, g); +;X.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); + return Ea.call(this, a, c, b, e, d, f, g); }; -function za(a, c, b, e, d, f, g) { +function Ea(a, c, b, e, d, f, g) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -687,21 +765,21 @@ function za(a, c, b, e, d, f, g) { for (let l = 0, m; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return za.call(h, a, [], b, e, d, f, g); + return Ea.call(h, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Aa.call(this, a, b, e, f, this.h), f ? d ? S.call(this.index, this.result) : this.result : this; + return this.result = Fa.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Aa(a, c, b, e, d) { +function Fa(a, c, b, e, d) { const f = [], g = C(); let h = 0; for (let k = 0, l; k < a.length; k++) { @@ -746,11 +824,11 @@ function Aa(a, c, b, e, d) { } return f; } -;U.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = T(this, "not", arguments); - return Ba.call(this, a, c, b, e, d, f, g); +;X.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); + return Ga.call(this, a, c, b, e, d, f, g); }; -function Ba(a, c, b, e, d, f, g) { +function Ga(a, c, b, e, d, f, g) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -758,17 +836,17 @@ function Ba(a, c, b, e, d, f, g) { for (let l = 0, m; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return Ba.call(h, a, [], b, e, d, f, g); + return Ga.call(h, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ca.call(this, a, b, e, f); + this.result = Ha.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? S.call(this.index, this.result) : this.result : this; + return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Ca(a, c, b, e) { +function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, h = 0; f < this.result.length; f++) { @@ -794,9 +872,9 @@ function Ca(a, c, b, e) { } return d; } -;function U(a) { - if (!this || this.constructor !== U) { - return new U(a); +;function X(a) { + if (!this || this.constructor !== X) { + return new X(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -805,7 +883,7 @@ function Ca(a, c, b, e) { this.result = a || []; this.h = 0; } -U.prototype.limit = function(a) { +X.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -824,7 +902,7 @@ U.prototype.limit = function(a) { } return this; }; -U.prototype.offset = function(a) { +X.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -836,18 +914,18 @@ U.prototype.offset = function(a) { } return this; }; -U.prototype.boost = function(a) { +X.prototype.boost = function(a) { this.h += a; return this; }; -U.prototype.resolve = function(a, c, b) { +X.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), wa.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; }; C(); -R.prototype.search = function(a, c, b, e) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); +V.prototype.search = function(a, c, b, e) { + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let d = []; var f = []; let g, h, k, l, m, n, t = 0, p, q; @@ -871,7 +949,7 @@ R.prototype.search = function(a, c, b, e) { var u = []; for (let x = 0, r; x < m.length; x++) { r = m[x]; - if (E(r)) { + if (D(r)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (r.field && r.tag) { @@ -885,8 +963,8 @@ R.prototype.search = function(a, c, b, e) { } } else { v = Object.keys(r); - for (let D = 0, F, B; D < v.length; D++) { - if (F = v[D], B = r[F], B.constructor === Array) { + for (let E = 0, F, B; E < v.length; E++) { + if (F = v[E], B = r[F], B.constructor === Array) { for (z = 0; z < B.length; z++) { u.push(F, B[z]); } @@ -904,7 +982,7 @@ R.prototype.search = function(a, c, b, e) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - y = Da.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); + y = Ia.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); } } return e.length ? Promise.all(e).then(function(x) { @@ -919,14 +997,14 @@ R.prototype.search = function(a, c, b, e) { } l || (l = this.field); u = !e && (this.worker || this.db) && []; - for (let x = 0, r, D, F; x < l.length; x++) { - D = l[x]; + for (let x = 0, r, E, F; x < l.length; x++) { + E = l[x]; let B; - E(D) || (B = D, D = B.field, a = B.query || a, c = B.limit || c, n = B.offset || n, k = B.suggest || k, g = this.store && (B.enrich || g)); + D(E) || (B = E, E = B.field, a = B.query || a, c = B.limit || c, n = B.offset || n, k = B.suggest || k, g = this.store && (B.enrich || g)); if (e) { r = e[x]; } else { - if (v = B || b, z = this.index.get(D), m && (v.enrich = !1), u) { + if (v = B || b, z = this.index.get(E), m && (v.enrich = !1), u) { u[x] = z.search(a, c, v); v && g && (v.enrich = g); continue; @@ -938,34 +1016,34 @@ R.prototype.search = function(a, c, b, e) { if (m && F) { v = []; z = 0; - for (let G = 0, H, Qa; G < m.length; G += 2) { - H = this.tag.get(m[G]); - if (!H) { + for (let G = 0, I, Xa; G < m.length; G += 2) { + I = this.tag.get(m[G]); + if (!I) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { continue; } else { - return p ? d : new U(d); + return p ? d : new X(d); } } - if (Qa = (H = H && H.get(m[G + 1])) && H.length) { - z++, v.push(H); + if (Xa = (I = I && I.get(m[G + 1])) && I.length) { + z++, v.push(I); } else if (!k) { - return p ? d : new U(d); + return p ? d : new X(d); } } if (z) { - r = va(r, v, p); + r = za(r, v, p); F = r.length; if (!F && !k) { - return p ? r : new U(r); + return p ? r : new X(r); } z--; } } if (F) { - f[t] = D, d.push(r), t++; + f[t] = E, d.push(r), t++; } else if (1 === l.length) { - return p ? d : new U(d); + return p ? d : new X(d); } } if (u) { @@ -975,7 +1053,7 @@ R.prototype.search = function(a, c, b, e) { }); } if (!t) { - return p ? d : new U(d); + return p ? d : new X(d); } if (y && (!g || !this.store)) { return d[0]; @@ -983,15 +1061,15 @@ R.prototype.search = function(a, c, b, e) { u = []; for (let x = 0, r; x < f.length; x++) { r = d[x]; - g && r.length && !r[0].doc && (r = S.call(this, r)); + g && r.length && !r[0].doc && (r = W.call(this, r)); if (y) { - return p ? r : new U(r); + return p ? r : new X(r); } d[x] = {field:f[x], result:r}; } - return h ? Ea(d, c) : q ? Fa(d, a, this.index, this.field, this.C, q) : d; + return h ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; }; -function Fa(a, c, b, e, d, f) { +function Ka(a, c, b, e, d, f) { let g, h, k; for (let m = 0, n, t, p, q, y; m < a.length; m++) { n = a[m].result; @@ -1006,21 +1084,21 @@ function Fa(a, c, b, e, d, f) { var l = J(n[u].doc, y); let z = g.encode(l); l = l.split(g.split); - for (let x = 0, r, D; x < z.length; x++) { + for (let x = 0, r, E; x < z.length; x++) { r = z[x]; - D = l[x]; + E = l[x]; let F; for (let B = 0, G; B < h.length; B++) { if (G = h[B], "strict" === k) { if (r === G) { - v += (v ? " " : "") + f.replace("$1", D); + v += (v ? " " : "") + f.replace("$1", E); F = !0; break; } } else { - const H = r.indexOf(G); - if (-1 < H) { - v += (v ? " " : "") + D.substring(0, H) + f.replace("$1", D.substring(H, G.length)) + D.substring(H + G.length); + const I = r.indexOf(G); + if (-1 < I) { + v += (v ? " " : "") + E.substring(0, I) + f.replace("$1", E.substring(I, G.length)) + E.substring(I + G.length); F = !0; break; } @@ -1033,7 +1111,7 @@ function Fa(a, c, b, e, d, f) { } return a; } -function Ea(a, c) { +function Ja(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1052,7 +1130,7 @@ function Ea(a, c) { } return b; } -function Da(a, c, b, e, d) { +function Ia(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1061,11 +1139,11 @@ function Da(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = S.call(this, f)); + d && (f = W.call(this, f)); return f; } } -function S(a) { +function W(a) { if (!this || !this.store) { return a; } @@ -1075,32 +1153,32 @@ function S(a) { } return c; } -;function R(a) { - if (!this || this.constructor !== R) { - return new R(a); +;function V(a) { + if (!this || this.constructor !== V) { + return new V(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && V(b, this.J) || "id"; + this.key = (b = c.key || c.id) && La(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); - this.cache = (b = a.cache || null) && new W(b); + this.cache = (b = a.cache || null) && new Y(b); a.cache = !1; b = new Map(); let e = c.index || c.field || c; - E(e) && (e = [e]); + D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], E(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new X(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = V(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; - E(a) && (a = [a]); + D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = V(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1116,14 +1194,14 @@ function S(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = V(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function V(a, c) { +function La(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1132,7 +1210,7 @@ function V(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -w = R.prototype; +w = V.prototype; w.append = function(a, c) { return this.add(a, c, !0); }; @@ -1140,7 +1218,7 @@ w.update = function(a, c) { return this.remove(a).add(a, c); }; w.remove = function(a) { - I(a) && (a = J(a, this.key)); + H(a) && (a = J(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1188,7 +1266,7 @@ w.set = function(a, c) { this.store.set(a, c); return this; }; -w.searchCache = Ga; +w.searchCache = Ma; w.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; @@ -1204,17 +1282,17 @@ w.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = pa(this.reg); + f = sa(this.reg); c = null; break; case 1: d = "tag"; - f = na(this.tag, this.reg.size); + f = qa(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = la(this.store); + f = oa(this.store); c = null; break; case 3: @@ -1224,7 +1302,7 @@ w.export = function(a, c, b = 0, e = 0) { default: return; } - return Q.call(this, a, c, d, f, b, e); + return ua.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { if (c) { @@ -1239,23 +1317,23 @@ w.import = function(a, c) { switch(a) { case "reg": this.fastupdate = !1; - this.reg = qa(c, this.reg); + this.reg = ta(c, this.reg); for (let e = 0, d; e < this.field.length; e++) { d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = oa(c, this.tag); + this.tag = ra(c, this.tag); break; case "doc": - this.store = ma(c, this.store); + this.store = pa(c, this.store); } } }; -ia(R.prototype); -function Ga(a, c, b) { +ja(V.prototype); +function Ma(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new W()); + this.cache || (this.cache = new Y()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -1270,56 +1348,56 @@ function Ga(a, c, b) { } return e; } -function W(a) { +function Y(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -W.prototype.set = function(a, c) { +Y.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); }; -W.prototype.get = function(a) { +Y.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; }; -W.prototype.remove = function(a) { +Y.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -W.prototype.clear = function() { +Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ha = {normalize:function(a) { +const Na = {normalize:function(a) { return a.toLowerCase(); }}; -const 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"]]); -const Ja = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ka = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const 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}; -const Ma = /[\x00-\x7F]+/g; -const Na = /[\x00-\x7F]+/g; -const 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, matcher:Ja, replacer:Ka}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ia, replacer:Ka.concat([/(?!^)[aeo]/g, ""]), matcher:Ja}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +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([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +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, matcher:Pa, replacer:Qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = La[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = La[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Ra[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[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(Ma, " "); + return ("" + a).replace(Sa, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Na, ""); + return ("" + a).replace(Ta, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Oa, " "); + return ("" + a).replace(Ua, " "); }}}; -const Ra = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -X.prototype.add = function(a, c, b, e) { +const Wa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -1331,14 +1409,14 @@ X.prototype.add = function(a, c, b, e) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Y(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Ya(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var h = d; h > f; h--) { g = q.substring(f, h); - var k = this.score ? this.score(c, q, p, g, f) : Y(t, e, p, d, f); + var k = this.score ? this.score(c, q, p, g, f) : Ya(t, e, p, d, f); Z(this, m, g, k, a, b); } } @@ -1347,7 +1425,7 @@ X.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : Y(t, e, p, d, h), Z(this, m, g, k, a, b); + g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : Ya(t, e, p, d, h), Z(this, m, g, k, a, b); } g = ""; } @@ -1363,7 +1441,7 @@ X.prototype.add = function(a, c, b, e) { for (d = C(), g = this.S, f = q, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { d[q] = 1; - const y = this.score ? this.score(c, f, p, q, k) : Y(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; + const y = this.score ? this.score(c, f, p, q, k) : Ya(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, y, a, b, u ? q : f); } } @@ -1382,11 +1460,11 @@ function Z(a, c, b, e, d, f, g) { g ? (c = k || (c[b] = C()), 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 Y(a, c, b, e, d) { +function Ya(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;X.prototype.search = function(a, c, b) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); +;O.prototype.search = function(a, c, b) { + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { a = b.query || a; @@ -1403,11 +1481,11 @@ function Y(a, c, b, e, d) { a = b.length; c = c || (h ? 100 : 0); if (1 === a) { - return Sa.call(this, b[0], "", c, d, h); + return Za.call(this, b[0], "", c, d, h); } f = this.depth && !1 !== f; if (2 === a && f && !g) { - return Sa.call(this, b[0], b[1], c, d, h); + return Za.call(this, b[0], b[1], c, d, h); } h = C(); let l = 0; @@ -1419,7 +1497,7 @@ function Y(a, c, b, e, d) { for (let q, y; l < a; l++) { if ((y = b[l]) && !h[y]) { h[y] = 1; - q = Ta(this, y, m); + q = $a(this, y, m); a: { f = q; var n = e, t = g, p = k; @@ -1455,27 +1533,27 @@ function Y(a, c, b, e, d) { m = e.length; a = e; if (1 < m) { - a = ta(e, k, c, d, g); + a = xa(e, k, c, d, g); } else if (1 === m) { - g = wa.call(null, e[0], c, d); + g = Aa.call(null, e[0], c, d); break a; } g = a; } return g; }; -function Sa(a, c, b, e, d) { - a = Ta(this, a, c); +function Za(a, c, b, e, d) { + a = $a(this, a, c); d = !0; - return a && a.length ? d ? wa.call(this, a, b, e) : new U(a) : d ? [] : new U(); + return a && a.length ? d ? Aa.call(this, a, b, e) : new X(a) : d ? [] : new X(); } -function Ta(a, c, b) { +function $a(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;X.prototype.remove = function(a, c) { +;O.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) { @@ -1490,14 +1568,14 @@ function Ta(a, c, b) { } } } else { - Ua(this.map, a), this.depth && Ua(this.ctx, a); + ab(this.map, a), this.depth && ab(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Ua(a, c) { +function ab(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1512,24 +1590,24 @@ function Ua(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = Ua(e[1], c); + const d = e[0], f = ab(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function X(a, c) { - if (!this || this.constructor !== X) { - return new X(a); +;function O(a, c) { + if (!this || this.constructor !== O) { + return new O(a); } if (a) { - var b = E(a) ? a : a.preset; - b && (Ra[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ra[b], a)); + var b = D(a) ? a : a.preset; + b && (Wa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Wa[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? Pa[a.encoder] : a.encode || a.encoder || Ha; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = a.tokenize || "strict"; @@ -1543,10 +1621,10 @@ function Ua(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.S = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new W(b); + this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; } -w = X.prototype; +w = O.prototype; w.clear = function() { this.map.clear(); this.ctx.clear(); @@ -1564,7 +1642,7 @@ w.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 Va(a) { +function bb(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1572,7 +1650,7 @@ function Va(a) { } } else { for (const b of a) { - const e = b[0], d = Va(b[1]); + const e = b[0], d = bb(b[1]); d ? c += d : a.delete(e); } } @@ -1582,17 +1660,17 @@ w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Va(this.map); - this.depth && Va(this.ctx); + bb(this.map); + this.depth && bb(this.ctx); return this; }; -w.searchCache = Ga; +w.searchCache = Ma; w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = pa(this.reg); + f = sa(this.reg); break; case 1: d = "cfg"; @@ -1600,29 +1678,29 @@ w.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = la(this.map, this.reg.size); + f = oa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = na(this.ctx, this.reg.size); + f = qa(this.ctx, this.reg.size); break; default: return; } - return Q.call(this, a, c, d, f, b, e); + return ua.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = qa(c, this.reg); + this.reg = ta(c, this.reg); break; case "map": - this.map = ma(c, this.map); + this.map = pa(c, this.map); break; case "ctx": - this.ctx = oa(c, this.ctx); + this.ctx = ra(c, this.ctx); } } }; @@ -1676,7 +1754,7 @@ w.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ia(X.prototype); -export default {Index:X, Charset:Pa, Encoder:K, Document:R, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +ja(O.prototype); +export default {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=X;export const Charset=Pa;export const Encoder=K;export const Document=R;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=O;export const Charset=Va;export const Encoder=K;export const Document=V;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index d9a9ddf..5519abc 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,12 +1,12 @@ /**! - * FlexSearch.js v0.8.107 (Bundle) + * FlexSearch.js v0.8.108 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var v;function A(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function E(a){return"string"===typeof a} -function H(a){return"object"===typeof a}function J(a,c){if(E(c))a=a[c];else for(let b=0;a&&bthis.stemmer.get(k)),g.lengththis.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&d -this.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};function ia(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}let N,ja;const O={},P={};function ka(a){N=0;O[a]=P[a]} -function M(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);N||(N=setTimeout(ka,0,a),ja=Date.now());P[a]||(P[a]=O[a]=1E3);if(!--O[a]){O[a]=P[a]=P[a]*this.priority*this.priority*3/(Date.now()-ja)|0||1;N=clearTimeout(N);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};function la(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function ma(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function ua(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?S.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?S.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ua(a,b,e),e=0));return f?this.resolve(b,e,d):this};U.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=T(this,"and",arguments);return ya.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; -function ya(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=ta(a,c,b,e,g),f?d?S.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};U.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=T(this,"xor",arguments);return za.call(this,a,c,b,e,d,f,g)}; -function za(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Aa.call(this,a,b,e,f,this.h),f?d?S.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Aa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kthis.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;const c=a.task,b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(a=a.factory)?(Function("return "+a)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e=[N.export]);"import"===c?await N.import.call(M,M):d=M[c].apply(M,e);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let Q,ka;const R={},S={};function la(a){Q=0;R[a]=S[a]} +function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);Q||(Q=setTimeout(la,0,a),ka=Date.now());S[a]||(S[a]=R[a]=1E3);if(!--R[a]){R[a]=S[a]=S[a]*this.priority*this.priority*3/(Date.now()-ka)|0||1;Q=clearTimeout(Q);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let T=0; +function ma(a={}){function c(g){function h(k){k=k.data||k;const l=k.id,m=l&&d.h[l];m&&(m(k.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++T]=function(){k(d)};d.worker.postMessage({id:T,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==ma)return new ma(a);let b="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;b&&(b=b.toString());const e="undefined"===typeof window,d=this,f=na(b,e,a.worker);return f.then?f.then(function(g){return c.call(d,g)}):c.call(this,f)}U("add");U("append");U("search");U("update");U("remove");U("clear");U("export");U("import");ja(ma.prototype); +function U(a){ma.prototype[a]=async function(){const c=this,b=[].slice.call(arguments);var e=b[b.length-1];let d;"function"===typeof e&&(d=e,b.splice(b.length-1,1));e=new Promise(function(f){c.h[++T]=f;c.worker.postMessage({task:a,id:T,args:b})});return d?(e.then(d),this):e}} +function na(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ia.toString()],{type:"text/javascript"}))):new window.Worker(D(b)?b:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function oa(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function pa(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?W.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=S.call(this,a));return a}} -function S(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -W.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};W.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};W.prototype.clear=function(){this.cache.clear();this.h=""};const Ha={normalize:function(a){return a.toLowerCase()}};const 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"]]);const Ja=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ka=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const 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};const Ma=/[\x00-\x7F]+/g;const Na=/[\x00-\x7F]+/g;const Oa=/[\x00-\x7F]+/g;var Qa={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,matcher:Ja,replacer:Ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka.concat([/(?!^)[aeo]/g,""]),matcher:Ja},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):Y(t,e,p,d,f);Z(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),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=C()),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 Y(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};X.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 Ua(this.map,a),this.depth&&Ua(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Ua(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function Va(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}} +function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.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};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};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([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];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,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):Ya(t,e,p,d,f);Z(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),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=C()),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 Ya(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.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 ab(this.map,a),this.depth&&ab(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function ab(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function bb(a){let c=0;if(a.constructor===Array)for(let b=0,e;b c && (c = Math.max(c + e, 0)); c < e; c++) { - var f = d[c]; - if (f === b || Object.is(f, b)) { + var g = d[c]; + if (g === b || Object.is(g, b)) { return !0; } } @@ -830,8 +830,8 @@ function I(a, b, c) { if ("undefined" !== e) { if (c) { if ("function" === e && d === e) { - return function(f) { - return a(c(f)); + return function(g) { + return a(c(g)); }; } b = a.constructor; @@ -909,15 +909,15 @@ function Ga(a) { if (!this || this.constructor !== Ga) { var b = Function.prototype.bind, c = b.apply, d = [null], e = d.concat; if (arguments instanceof Array) { - var f = arguments; + var g = arguments; } else { - f = w(arguments); - for (var g, h = []; !(g = f.next()).done;) { - h.push(g.value); + g = w(arguments); + for (var f, h = []; !(f = g.next()).done;) { + h.push(f.value); } - f = h; + g = h; } - return new (c.call(b, Ga, e.call(d, f)))(); + return new (c.call(b, Ga, e.call(d, g)))(); } for (b = 0; b < arguments.length; b++) { this.assign(arguments[b]); @@ -942,7 +942,7 @@ u.assign = function(a) { } try { this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); - } catch (f) { + } catch (g) { console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { @@ -952,7 +952,7 @@ u.assign = function(a) { } else { try { this.split = I(this.split, Ba); - } catch (f) { + } catch (g) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } this.numeric = I(a.numeric, I(this.numeric, !0)); @@ -1051,15 +1051,15 @@ u.encode = function(a) { this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = Fa ? a.normalize("NFKD").replace(Fa, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(Da, "$1 $2").replace(Ea, "$1 $2").replace(Ca, "$1 ")); - for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, f = 0, g = void 0, h = void 0; f < e.length; f++) { - if ((g = h = e[f]) && !(g.length < this.minlength)) { + for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, g = 0, f = void 0, h = void 0; g < e.length; g++) { + if ((f = h = e[g]) && !(f.length < this.minlength)) { if (c) { - d.push(g); + d.push(f); } else { - if (!this.filter || !this.filter.has(g)) { - if (this.cache && g.length <= this.H) { + if (!this.filter || !this.filter.has(f)) { + if (this.cache && f.length <= this.H) { if (this.D) { - var k = this.C.get(g); + var k = this.C.get(f); if (k || "" === k) { k && d.push(k); continue; @@ -1068,26 +1068,26 @@ u.encode = function(a) { this.D = setTimeout(N, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, function(q) { + this.stemmer && 2 < f.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), f = f.replace(this.N, function(q) { return b.stemmer.get(q); - }), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); - if (g && (this.mapper || this.dedupe && 1 < g.length)) { + }), f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); + if (f && (this.mapper || this.dedupe && 1 < f.length)) { k = ""; - for (var l = 0, m = "", n = void 0, p = void 0; l < g.length; l++) { - n = g.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); + for (var l = 0, m = "", n = void 0, p = void 0; l < f.length; l++) { + n = f.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); } - g = k; + f = k; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, function(q) { + this.matcher && 1 < f.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), f = f.replace(this.M, function(q) { return b.matcher.get(q); })); - if (g && this.replacer) { - for (k = 0; g && k < this.replacer.length; k += 2) { - g = g.replace(this.replacer[k], this.replacer[k + 1]); + if (f && this.replacer) { + for (k = 0; f && k < this.replacer.length; k += 2) { + f = f.replace(this.replacer[k], this.replacer[k + 1]); } } - this.cache && h.length <= this.H && (this.C.set(h, g), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); - g && d.push(g); + this.cache && h.length <= this.H && (this.C.set(h, f), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); + f && d.push(f); } } } @@ -1101,43 +1101,93 @@ function N(a) { a.B.clear(); a.C.clear(); } -;function Ja(a) { - var b, c, d, e, f, g, h; - return ta(function(k) { - a = a.data; - b = self._index; - c = a.args; - d = a.task; - switch(d) { - case "init": - e = a.options || {}; - (f = a.factory) ? (Function("return " + f)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new O(e); - postMessage({id:a.id}); - break; - default: - g = a.id, h = b[d].apply(b, c), postMessage("search" === d ? {id:g, msg:h} : {id:g}); +;var O, Ha; +function Ia(a) { + var b, c, d, e, g; + return ta(function(f) { + if (1 == f.h) { + switch(a = a.data, b = a.task, c = a.id, d = a.args, b) { + case "init": + Ha = a.options || {}; + (e = a.factory) ? (Function("return " + e)()(self), O = new self.FlexSearch.Index(Ha), delete self.FlexSearch) : O = new R(Ha); + postMessage({id:c}); + break; + default: + f.h = 2; + return; + } + } else { + if (4 != f.h) { + "export" === b && (d = [Ha.export]); + if ("import" !== b) { + g = O[b].apply(O, d); + f.h = 4; + return; + } + return E(f, Ha.import.call(O, O), 4); + } + postMessage("search" === b ? {id:c, msg:g} : {id:c}); } - k.h = 0; + f.h = 0; }); } -;var Ka = 0; -function R(a) { - function b(g) { +;function Ja(a) { + Ma.call(a, "add"); + Ma.call(a, "append"); + Ma.call(a, "search"); + Ma.call(a, "update"); + Ma.call(a, "remove"); +} +var Na, Oa, Pa = {}, Qa = {}; +function Ra(a) { + Na = 0; + Pa[a] = Qa[a]; +} +function Ma(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]; + } + Na || (Na = setTimeout(Ra, 0, a), Oa = Date.now()); + Qa[a] || (Qa[a] = Pa[a] = 1000); + if (!--Pa[a]) { + Pa[a] = Qa[a] = Qa[a] * this.priority * this.priority * 3 / (Date.now() - Oa) | 0 || 1; + Na = clearTimeout(Na); + var e = this; + return new Promise(function(f) { + setTimeout(function() { + f(e[a + "Async"].apply(e, b)); + }, 0); + }); + } + var g = this[a].apply(this, b); + c = g.then ? g : new Promise(function(f) { + return f(g); + }); + d && c.then(d); + return c; + }; +} +;var Sa = 0; +function S(a) { + function b(f) { function h(k) { k = k.data || k; var l = k.id, m = l && e.h[l]; m && (m(k.msg), delete e.h[l]); } - this.worker = g; + this.worker = f; this.h = J(); if (this.worker) { d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { return new Promise(function(k) { - e.h[++Ka] = function() { + e.h[++Sa] = function() { k(e); }; - e.worker.postMessage({id:Ka, task:"init", factory:c, options:a}); + e.worker.postMessage({id:Sa, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); @@ -1145,80 +1195,45 @@ function R(a) { } } a = void 0 === a ? {} : a; - if (!this || this.constructor !== R) { - return new R(a); + if (!this || this.constructor !== S) { + return new S(a); } var c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - var d = "undefined" === typeof window, e = this, f = La(c, d, a.worker); - return f.then ? f.then(function(g) { - return b.call(e, g); - }) : b.call(this, f); + var d = "undefined" === typeof window, e = this, g = Ta(c, d, a.worker); + return g.then ? g.then(function(f) { + return b.call(e, f); + }) : b.call(this, g); } -Ma("add"); -Ma("append"); -Ma("search"); -Ma("update"); -Ma("remove"); -function Ma(a) { - R.prototype[a] = R.prototype[a + "Async"] = function() { - var b = this, c = arguments, d, e, f, g, h; +T("add"); +T("append"); +T("search"); +T("update"); +T("remove"); +T("clear"); +T("export"); +T("import"); +Ja(S.prototype); +function T(a) { + S.prototype[a] = function() { + var b = this, c = arguments, d, e, g, f, h; return ta(function(k) { d = b; e = [].slice.call(c); - f = e[e.length - 1]; - "function" === typeof f && (g = f, e.splice(e.length - 1, 1)); + g = e[e.length - 1]; + "function" === typeof g && (f = g, e.splice(e.length - 1, 1)); h = new Promise(function(l) { - d.h[++Ka] = l; - d.worker.postMessage({task:a, id:Ka, args:e}); + d.h[++Sa] = l; + d.worker.postMessage({task:a, id:Sa, args:e}); }); - return g ? (h.then(g), k.return(b)) : k.return(h); + return f ? (h.then(f), k.return(b)) : k.return(h); }); }; } -function La(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ja.toString()], {type:"text/javascript"}))) : new window.Worker(K(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ta(a, b, c) { + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ia.toString()], {type:"text/javascript"}))) : new window.Worker(K(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;function Na(a) { - Oa.call(a, "add"); - Oa.call(a, "append"); - Oa.call(a, "search"); - Oa.call(a, "update"); - Oa.call(a, "remove"); -} -var Pa, Qa, Ra = {}, Sa = {}; -function Ta(a) { - Pa = 0; - Ra[a] = Sa[a]; -} -function Oa(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]; - } - Pa || (Pa = setTimeout(Ta, 0, a), Qa = Date.now()); - Sa[a] || (Sa[a] = Ra[a] = 1000); - if (!--Ra[a]) { - Ra[a] = Sa[a] = Sa[a] * this.priority * this.priority * 3 / (Date.now() - Qa) | 0 || 1; - Pa = clearTimeout(Pa); - var e = this; - return new Promise(function(g) { - setTimeout(function() { - g(e[a + "Async"].apply(e, b)); - }, 0); - }); - } - var f = this[a].apply(this, b); - c = f.then ? f : new Promise(function(g) { - return g(f); - }); - d && c.then(d); - return c; - }; -} ;function Ua(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; @@ -1271,28 +1286,28 @@ function Za(a, b) { } return b; } -function $a(a, b, c, d, e, f, g) { - g = void 0 === g ? 0 : g; +function $a(a, b, c, d, e, g, f) { + f = void 0 === f ? 0 : f; var h = d && d.constructor === Array, k = h ? d.shift() : d; if (!k) { - return this.export(a, b, e, f + 1); + return this.export(a, b, e, g + 1); } - if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((k = a((b ? b + "." : "") + (f + 1) + "." + c, JSON.stringify(k))) && k.then) { var l = this; return k.then(function() { - return $a.call(l, a, b, c, h ? d : null, e, f, g + 1); + return $a.call(l, a, b, c, h ? d : null, e, g, f + 1); }); } - return $a.call(this, a, b, c, h ? d : null, e, f, g + 1); + return $a.call(this, a, b, c, h ? d : null, e, g, f + 1); } ;function ab(a, b, c, d) { - for (var e = [], f = 0, g; f < a.index.length; f++) { - if (g = a.index[f], b >= g.length) { - b -= g.length; + for (var e = [], g = 0, f; g < a.index.length; g++) { + if (f = a.index[g], b >= f.length) { + b -= f.length; } else { - b = g[d ? "splice" : "slice"](b, c); - if (g = b.length) { - if (e = e.length ? e.concat(b) : b, c -= g, d && (a.length -= g), !c) { + 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; } } @@ -1301,9 +1316,9 @@ function $a(a, b, c, d, e, f, g) { } return e; } -function S(a) { +function bb(a) { if (!this) { - return new S(a); + return new bb(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -1327,21 +1342,21 @@ function S(a) { } if ("indexOf" === d) { return function(e) { - for (var f = 0, g = 0, h, k; g < b.index.length; g++) { - h = b.index[g]; + for (var g = 0, f = 0, h, k; f < b.index.length; f++) { + h = b.index[f]; k = h.indexOf(e); if (0 <= k) { - return f + k; + return g + k; } - f += h.length; + g += h.length; } return -1; }; } if ("includes" === d) { return function(e) { - for (var f = 0; f < b.index.length; f++) { - if (b.index[f].includes(e)) { + for (var g = 0; g < b.index.length; g++) { + if (b.index[g].includes(e)) { return !0; } } @@ -1349,13 +1364,13 @@ function S(a) { }; } if ("slice" === d) { - return function(e, f) { - return ab(b, e || 0, f || b.length, !1); + return function(e, g) { + return ab(b, e || 0, g || b.length, !1); }; } if ("splice" === d) { - return function(e, f) { - return ab(b, e || 0, f || b.length, !0); + return function(e, g) { + return ab(b, e || 0, g || b.length, !0); }; } if ("constructor" === d) { @@ -1371,31 +1386,13 @@ function S(a) { return !0; }}); } -S.prototype.clear = function() { +bb.prototype.clear = function() { this.index.length = 0; }; -S.prototype.destroy = function() { +bb.prototype.destroy = function() { this.proxy = this.index = null; }; -S.prototype.push = function() { -}; -function T(a) { - a = void 0 === a ? 8 : a; - if (!this) { - return new T(a); - } - this.index = J(); - this.B = []; - this.size = 0; - 32 < a ? (this.h = bb, this.A = BigInt(a)) : (this.h = cb, this.A = 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)); +bb.prototype.push = function() { }; function U(a) { a = void 0 === a ? 8 : a; @@ -1403,36 +1400,54 @@ function U(a) { return new U(a); } this.index = J(); - this.h = []; - 32 < a ? (this.B = bb, this.A = BigInt(a)) : (this.B = cb, this.A = a); + this.B = []; + this.size = 0; + 32 < a ? (this.h = cb, this.A = BigInt(a)) : (this.h = db, this.A = a); } -U.prototype.add = function(a) { +U.prototype.get = function(a) { + var b = this.h(a); + return (b = this.index[b]) && b.get(a); +}; +U.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 V(a) { + a = void 0 === a ? 8 : a; + if (!this) { + return new V(a); + } + this.index = J(); + this.h = []; + 32 < a ? (this.B = cb, this.A = BigInt(a)) : (this.B = db, this.A = a); +} +V.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)); }; -u = T.prototype; -u.has = U.prototype.has = function(a) { +u = U.prototype; +u.has = V.prototype.has = function(a) { var b = this.B(a); return (b = this.index[b]) && b.has(a); }; -u.delete = U.prototype.delete = function(a) { +u.delete = V.prototype.delete = function(a) { var b = this.B(a); (b = this.index[b]) && b.delete(a) && this.size--; }; -u.clear = U.prototype.clear = function() { +u.clear = V.prototype.clear = function() { this.index = J(); this.h = []; this.size = 0; }; -u.values = U.prototype.values = function db() { - var b, c = this, d, e, f; - return ra(db, function(g) { - switch(g.h) { +u.values = V.prototype.values = function eb() { + var b, c = this, d, e, g; + return ra(eb, function(f) { + switch(f.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - g.h = 0; + f.h = 0; break; } d = w(c.h[b].values()); @@ -1440,25 +1455,25 @@ u.values = U.prototype.values = function db() { case 5: if (e.done) { b++; - g.h = 2; + f.h = 2; break; } - f = e.value; - return E(g, f, 6); + g = e.value; + return E(f, g, 6); case 6: - e = d.next(), g.h = 5; + e = d.next(), f.h = 5; } }); }; -u.keys = U.prototype.keys = function eb() { - var b, c = this, d, e, f; - return ra(eb, function(g) { - switch(g.h) { +u.keys = V.prototype.keys = function fb() { + var b, c = this, d, e, g; + return ra(fb, function(f) { + switch(f.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - g.h = 0; + f.h = 0; break; } d = w(c.h[b].keys()); @@ -1466,25 +1481,25 @@ u.keys = U.prototype.keys = function eb() { case 5: if (e.done) { b++; - g.h = 2; + f.h = 2; break; } - f = e.value; - return E(g, f, 6); + g = e.value; + return E(f, g, 6); case 6: - e = d.next(), g.h = 5; + e = d.next(), f.h = 5; } }); }; -u.entries = U.prototype.entries = function fb() { - var b, c = this, d, e, f; - return ra(fb, function(g) { - switch(g.h) { +u.entries = V.prototype.entries = function gb() { + var b, c = this, d, e, g; + return ra(gb, function(f) { + switch(f.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - g.h = 0; + f.h = 0; break; } d = w(c.h[b].entries()); @@ -1492,17 +1507,17 @@ u.entries = U.prototype.entries = function fb() { case 5: if (e.done) { b++; - g.h = 2; + f.h = 2; break; } - f = e.value; - return E(g, f, 6); + g = e.value; + return E(f, g, 6); case 6: - e = d.next(), g.h = 5; + e = d.next(), f.h = 5; } }); }; -function cb(a) { +function db(a) { var b = Math.pow(2, this.A) - 1; if ("number" == typeof a) { return a & b; @@ -1512,10 +1527,10 @@ function cb(a) { } return 32 === this.A ? c + Math.pow(2, 31) : c; } -function bb() { +function cb() { throw Error("The keystore is limited to 32 for EcmaScript5"); } -;V.prototype.add = function(a, b, c) { +;W.prototype.add = function(a, b, c) { M(a) && (b = a, a = ya(b, this.key)); if (b && (a || 0 === a)) { if (!c && this.reg.has(a)) { @@ -1523,50 +1538,50 @@ function bb() { } for (var d = 0, e; d < this.field.length; d++) { e = this.J[d]; - var f = this.index.get(this.field[d]); + var g = this.index.get(this.field[d]); if ("function" === typeof e) { - (e = e(b)) && f.add(a, e, !1, !0); + (e = e(b)) && g.add(a, e, !1, !0); } else { - var g = e.R; - if (!g || g(b)) { - e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), gb(b, e, this.S, 0, f, a, e[0], c); + var f = e.R; + if (!f || f(b)) { + e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), hb(b, e, this.S, 0, g, a, e[0], c); } } } if (this.tag) { for (d = 0; d < this.L.length; d++) { - g = this.L[d]; + f = this.L[d]; var h = this.aa[d]; - f = this.tag.get(h); + g = this.tag.get(h); e = J(); - if ("function" === typeof g) { - if (g = g(b), !g) { + if ("function" === typeof f) { + if (f = f(b), !f) { continue; } } else { - var k = g.R; + var k = f.R; if (k && !k(b)) { continue; } - g.constructor === String && (g = "" + g); - g = ya(b, g); + f.constructor === String && (f = "" + f); + f = ya(b, f); } - if (f && g) { - for (K(g) && (g = [g]), h = 0, k = void 0; h < g.length; h++) { - var l = g[h]; + if (g && f) { + for (K(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { + var l = f[h]; if (!e[l]) { e[l] = 1; var m; - (m = f.get(l)) ? k = m : f.set(l, k = []); + (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 S(k); + m = new bb(k); if (this.fastupdate) { for (var n = w(this.reg.values()), p = n.next(); !p.done; p = n.next()) { p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); } } - f.set(l, k = m); + g.set(l, k = m); } k.push(a); this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); @@ -1574,7 +1589,7 @@ function bb() { } } } else { - f || console.warn("Tag '" + h + "' was not found"); + g || console.warn("Tag '" + h + "' was not found"); } } } @@ -1582,11 +1597,11 @@ function bb() { if (this.I) { var q = J(); for (c = 0; c < this.I.length; c++) { - if (d = this.I[c], f = d.R, !f || f(b)) { - f = void 0; + if (d = this.I[c], g = d.R, !g || g(b)) { + g = void 0; if ("function" === typeof d) { - f = d(b); - if (!f) { + g = d(b); + if (!g) { continue; } d = [d.ja]; @@ -1594,7 +1609,7 @@ function bb() { q[d] = b[d]; continue; } - hb(b, q, d, 0, d[0], f); + ib(b, q, d, 0, d[0], g); } } } @@ -1603,47 +1618,47 @@ function bb() { } return this; }; -function hb(a, b, c, d, e, f) { +function ib(a, b, c, d, e, g) { a = a[e]; if (d === c.length - 1) { - b[e] = f || a; + b[e] = g || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - hb(a, b, c, d, e); + ib(a, b, c, d, e); } } else { - b = b[e] || (b[e] = J()), e = c[++d], hb(a, b, c, d, e); + b = b[e] || (b[e] = J()), e = c[++d], ib(a, b, c, d, e); } } } -function gb(a, b, c, d, e, f, g, h) { - if (a = a[g]) { +function hb(a, b, c, d, e, g, f, h) { + if (a = a[f]) { if (d === b.length - 1) { if (a.constructor === Array) { if (c[d]) { for (b = 0; b < a.length; b++) { - e.add(f, a[b], !0, !0); + e.add(g, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(f, a, h, !0); + e.add(g, a, h, !0); } else { if (a.constructor === Array) { - for (g = 0; g < a.length; g++) { - gb(a, b, c, d, e, f, g, h); + for (f = 0; f < a.length; f++) { + hb(a, b, c, d, e, g, f, h); } } else { - g = b[++d], gb(a, b, c, d, e, f, g, h); + f = b[++d], hb(a, b, c, d, e, g, f, h); } } } else { - e.db && e.remove(f); + e.db && e.remove(g); } } -;function ib(a, b, c, d, e, f, g) { +;function jb(a, b, c, d, e, g, f) { var h = a.length, k = [], l; var m = J(); for (var n = 0, p = void 0, q; n < b; n++) { @@ -1653,8 +1668,8 @@ function gb(a, b, c, d, e, f, g, h) { q = p[x]; (l = m[q]) ? m[q]++ : (l = 0, m[q] = 1); l = k[l] || (k[l] = []); - if (!g) { - var r = n + (t || !e ? 0 : f || 0); + if (!f) { + var r = n + (t || !e ? 0 : g || 0); l = l[r] || (l[r] = []); } l.push(q); @@ -1664,27 +1679,27 @@ function gb(a, b, c, d, e, f, g, h) { } if (a = k.length) { if (e) { - k = 1 < k.length ? jb(k, c, d, g, f) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + k = 1 < k.length ? kb(k, c, d, f, g) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { if (a < h) { return []; } k = k[a - 1]; if (c || d) { - if (g) { + if (f) { if (k.length > c || d) { k = k.slice(d, c + d); } } else { e = []; - for (f = 0; f < k.length; f++) { - if (g = k[f], g.length > d) { - d -= g.length; + for (g = 0; g < k.length; g++) { + if (f = k[g], f.length > d) { + d -= f.length; } else { - if (g.length > c || d) { - g = g.slice(d, c + d), c -= g.length, d && (d -= g.length); + if (f.length > c || d) { + f = f.slice(d, c + d), c -= f.length, d && (d -= f.length); } - e.push(g); + e.push(f); if (!c) { break; } @@ -1697,19 +1712,19 @@ function gb(a, b, c, d, e, f, g, h) { } return k; } -function jb(a, b, c, d, e) { - var f = [], g = J(), h = a.length, k; +function kb(a, b, c, d, e) { + var g = [], f = J(), h = a.length, k; if (d) { for (e = h - 1; 0 <= e; e--) { if (k = (d = a[e]) && d.length) { for (h = 0; h < k; h++) { var l = d[h]; - if (!g[l]) { - if (g[l] = 1, c) { + if (!f[l]) { + if (f[l] = 1, c) { c--; } else { - if (f.push(l), f.length === b) { - return f; + if (g.push(l), g.length === b) { + return g; } } } @@ -1722,14 +1737,14 @@ function jb(a, b, c, d, e) { for (var q = 0; q < n.length; q++) { if (k = (d = n[q]) && d.length) { for (var t = 0; t < k; t++) { - if (l = d[t], !g[l]) { - if (g[l] = 1, c) { + if (l = d[t], !f[l]) { + if (f[l] = 1, c) { c--; } else { var x = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; - (f[x] || (f[x] = [])).push(l); + (g[x] || (g[x] = [])).push(l); if (++p === b) { - return f; + return g; } } } @@ -1738,13 +1753,13 @@ function jb(a, b, c, d, e) { } } } - return f; + return g; } -function kb(a, b, c) { - for (var d = J(), e = [], f = 0, g; f < b.length; f++) { - g = b[f]; - for (var h = 0; h < g.length; h++) { - d[g[h]] = 1; +function lb(a, b, c) { + for (var d = J(), e = [], g = 0, f; g < b.length; g++) { + f = b[g]; + for (var h = 0; h < f.length; h++) { + d[f[h]] = 1; } } if (c) { @@ -1753,34 +1768,34 @@ function kb(a, b, c) { } } else { for (b = 0; b < a.result.length; b++) { - for (c = a.result[b], g = 0; g < c.length; g++) { - f = c[g], d[f] && ((e[b] || (e[b] = [])).push(f), d[f] = 0); + for (c = a.result[b], f = 0; f < c.length; f++) { + g = c[f], d[g] && ((e[b] || (e[b] = [])).push(g), d[g] = 0); } } } return e; } -;function lb(a, b, c, d) { +;function mb(a, b, c, d) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? W.call(this, a) : a; + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? X.call(this, a) : a; } - for (var e = [], f = 0, g = void 0, h = void 0; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { + if ((f = a[g]) && (h = f.length)) { if (c) { if (c >= h) { c -= h; continue; } - c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); + c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); } - h > b && (g = g.slice(0, b), h = b); + h > b && (f = f.slice(0, b), h = b); if (!e.length && h >= b) { - return d ? W.call(this, g) : g; + return d ? X.call(this, f) : f; } - e.push(g); + e.push(f); b -= h; if (!b) { break; @@ -1788,9 +1803,9 @@ function kb(a, b, c) { } } e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? W.call(this, e) : e; + return d ? X.call(this, e) : e; } -;function mb(a, b, c) { +;function nb(a, b, c) { var d = c[0]; if (d.then) { return Promise.all(c).then(function(q) { @@ -1801,15 +1816,15 @@ function kb(a, b, c) { return a[b].apply(a, d); } d = []; - for (var e = [], f = 0, g = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { + for (var e = [], g = 0, f = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { if (n = c[m]) { var p = void 0; - if (n.constructor === X) { + if (n.constructor === Y) { p = n.result; } else if (n.constructor === Array) { p = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + if (g = n.limit || 0, f = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = k, n.enrich = h; } else if (n.and) { p = a.and(n.and); @@ -1833,27 +1848,27 @@ function kb(a, b, c) { } } } - return {W:d, $:e, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {W:d, $:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; } -;X.prototype.or = function() { - var a = mb(this, "or", arguments); - return nb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve); +;Y.prototype.or = function() { + var a = nb(this, "or", arguments); + return ob.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve); }; -function nb(a, b, c, d, e, f) { +function ob(a, b, c, d, e, g) { if (b.length) { - var g = this; + var f = this; return Promise.all(b).then(function(h) { a = []; for (var k = 0, l = void 0; k < h.length; k++) { (l = h[k]).length && (a[k] = l); } - return nb.call(g, a, [], c, d, e, f); + return ob.call(f, a, [], c, d, e, g); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = jb(a, c, d, !1, this.h), d = 0)); - return f ? this.resolve(c, d, e) : this; + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = kb(a, c, d, !1, this.h), d = 0)); + return g ? this.resolve(c, d, e) : this; } -;X.prototype.and = function() { +;Y.prototype.and = function() { var a = this.result.length; if (!a) { var b = arguments[0]; @@ -1862,12 +1877,12 @@ function nb(a, b, c, d, e, f) { var c = b.resolve; var d = b.limit; var e = b.offset; - var f = b.enrich && c; + var g = b.enrich && c; } } - return a ? (a = mb(this, "and", arguments), ob.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest)) : c ? this.resolve(d, e, f) : this; + return a ? (a = nb(this, "and", arguments), pb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest)) : c ? this.resolve(d, e, g) : this; }; -function ob(a, b, c, d, e, f, g) { +function pb(a, b, c, d, e, g, f) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -1875,7 +1890,7 @@ function ob(a, b, c, d, e, f, g) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return ob.call(h, a, [], c, d, e, f, g); + return pb.call(h, a, [], c, d, e, g, f); }); } if (a.length) { @@ -1883,20 +1898,20 @@ function ob(a, b, c, d, e, f, g) { this.result = a[0]; } else { if (b = za(a)) { - return this.result = ib(a, b, c, d, g, this.h, f), f ? e ? W.call(this.index, this.result) : this.result : this; + return this.result = jb(a, b, c, d, f, this.h, g), g ? e ? X.call(this.index, this.result) : this.result : this; } this.result = []; } } else { - g || (this.result = a); + f || (this.result = a); } - return f ? this.resolve(c, d, e) : this; + return g ? this.resolve(c, d, e) : this; } -;X.prototype.xor = function() { - var a = mb(this, "xor", arguments); - return pb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); +;Y.prototype.xor = function() { + var a = nb(this, "xor", arguments); + return qb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); }; -function pb(a, b, c, d, e, f, g) { +function qb(a, b, c, d, e, g, f) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -1904,28 +1919,28 @@ function pb(a, b, c, d, e, f, g) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return pb.call(h, a, [], c, d, e, f, g); + return qb.call(h, a, [], c, d, e, g, f); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = qb.call(this, a, c, d, f, this.h), f ? e ? W.call(this.index, this.result) : this.result : this; + return this.result = rb.call(this, a, c, d, g, this.h), g ? e ? X.call(this.index, this.result) : this.result : this; } } else { - g || (this.result = a); + f || (this.result = a); } - return f ? this.resolve(c, d, e) : this; + return g ? this.resolve(c, d, e) : this; } -function qb(a, b, c, d, e) { - for (var f = [], g = J(), h = 0, k = 0, l; k < a.length; k++) { +function rb(a, b, c, d, e) { + for (var g = [], f = J(), h = 0, k = 0, l; k < a.length; k++) { if (l = a[k]) { h < l.length && (h = l.length); for (var m = 0, n; m < l.length; m++) { if (n = l[m]) { for (var p = 0, q; p < n.length; p++) { - q = n[p], g[q] = g[q] ? 2 : 1; + q = n[p], f[q] = f[q] ? 2 : 1; } } } @@ -1936,20 +1951,20 @@ function qb(a, b, c, d, e) { if (n = a[m]) { if (n = n[k]) { for (p = 0; p < n.length; p++) { - if (q = n[p], 1 === g[q]) { + if (q = n[p], 1 === f[q]) { if (c) { c--; } else { if (d) { - if (f.push(q), f.length === b) { - return f; + if (g.push(q), g.length === b) { + return g; } } else { var t = k + (m ? e : 0); - f[t] || (f[t] = []); - f[t].push(q); + g[t] || (g[t] = []); + g[t].push(q); if (++l === b) { - return f; + return g; } } } @@ -1959,13 +1974,13 @@ function qb(a, b, c, d, e) { } } } - return f; + return g; } -;X.prototype.not = function() { - var a = mb(this, "not", arguments); - return rb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); +;Y.prototype.not = function() { + var a = nb(this, "not", arguments); + return sb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); }; -function rb(a, b, c, d, e, f, g) { +function sb(a, b, c, d, e, g, f) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -1973,23 +1988,23 @@ function rb(a, b, c, d, e, f, g) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return rb.call(h, a, [], c, d, e, f, g); + return sb.call(h, a, [], c, d, e, g, f); }); } if (a.length && this.result.length) { - this.result = sb.call(this, a, c, d, f); - } else if (f) { + this.result = tb.call(this, a, c, d, g); + } else if (g) { return this.resolve(c, d, e); } - return f ? e ? W.call(this.index, this.result) : this.result : this; + return g ? e ? X.call(this.index, this.result) : this.result : this; } -function sb(a, b, c, d) { +function tb(a, b, c, d) { var e = []; a = new Set(a.flat().flat()); - for (var f = 0, g, h = 0; f < this.result.length; f++) { - if (g = this.result[f]) { - for (var k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (var g = 0, f, h = 0; g < this.result.length; g++) { + if (f = this.result[g]) { + for (var k = 0, l; k < f.length; k++) { + if (l = f[k], !a.has(l)) { if (c) { c--; } else { @@ -1998,7 +2013,7 @@ function sb(a, b, c, d) { return e; } } else { - if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { + if (e[g] || (e[g] = []), e[g].push(l), ++h === b) { return e; } } @@ -2009,9 +2024,9 @@ function sb(a, b, c, d) { } return e; } -;function X(a) { - if (!this || this.constructor !== X) { - return new X(a); +;function Y(a) { + if (!this || this.constructor !== Y) { + return new Y(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -2020,7 +2035,7 @@ function sb(a, b, c, d) { this.result = a || []; this.h = 0; } -X.prototype.limit = function(a) { +Y.prototype.limit = function(a) { if (this.result.length) { for (var b = [], c = 0, d; c < this.result.length; c++) { if (d = this.result[c]) { @@ -2038,7 +2053,7 @@ X.prototype.limit = function(a) { } return this; }; -X.prototype.offset = function(a) { +Y.prototype.offset = function(a) { if (this.result.length) { for (var b = [], c = 0, d; c < this.result.length; c++) { if (d = this.result[c]) { @@ -2049,19 +2064,19 @@ X.prototype.offset = function(a) { } return this; }; -X.prototype.boost = function(a) { +Y.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, b, c) { +Y.prototype.resolve = function(a, b, c) { var d = this.result, e = this.index; this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), lb.call(e, d, a || 100, b, c)) : d; + return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), mb.call(e, d, a || 100, b, c)) : d; }; J(); -V.prototype.search = function(a, b, c, d) { +W.prototype.search = function(a, b, c, d) { c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); - var e = [], f = [], g = 0; + var e = [], g = [], f = 0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; @@ -2122,19 +2137,19 @@ V.prototype.search = function(a, b, c, d) { if (!a) { p = []; if (r.length) { - for (f = 0; f < r.length; f += 2) { + for (g = 0; g < r.length; g += 2) { h = void 0; if (this.db) { - h = this.index.get(r[f]); + h = this.index.get(r[g]); if (!h) { - console.warn("Tag '" + r[f] + ":" + r[f + 1] + "' will be skipped because there is no field '" + r[f] + "'."); + console.warn("Tag '" + r[g] + ":" + r[g + 1] + "' will be skipped because there is no field '" + r[g] + "'."); continue; } - p.push(h = h.db.tag(r[f + 1], b, x, q)); + p.push(h = h.db.tag(r[g + 1], b, x, q)); } else { - h = tb.call(this, r[f], r[f + 1], b, x, q); + h = ub.call(this, r[g], r[g + 1], b, x, q); } - e.push({field:r[f], tag:r[f + 1], result:h}); + e.push({field:r[g], tag:r[g + 1], result:h}); } } return p.length ? Promise.all(p).then(function(P) { @@ -2162,10 +2177,10 @@ V.prototype.search = function(a, b, c, d) { if (m) { if (this.db) { y.tag = m; - var Ha = v.db.support_tag_search; + var Ka = v.db.support_tag_search; y.field = l; } - Ha || (y.enrich = !1); + Ka || (y.enrich = !1); } if (r) { r[A] = v.search(a, b, y); @@ -2180,115 +2195,115 @@ V.prototype.search = function(a, b, c, d) { D = []; F = 0; if (this.db && d) { - if (!Ha) { + if (!Ka) { for (G = l.length; G < d.length; G++) { var L = d[G]; if (L && L.length) { F++, D.push(L); } else if (!n) { - return p ? e : new X(e); + return p ? e : new Y(e); } } } } else { G = 0; - for (var Vb = L = void 0; G < m.length; G += 2) { + for (var Xb = L = void 0; G < m.length; G += 2) { L = this.tag.get(m[G]); if (!L) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), n) { continue; } else { - return p ? e : new X(e); + return p ? e : new Y(e); } } - if (Vb = (L = L && L.get(m[G + 1])) && L.length) { + if (Xb = (L = L && L.get(m[G + 1])) && L.length) { F++, D.push(L); } else if (!n) { - return p ? e : new X(e); + return p ? e : new Y(e); } } } if (F) { - v = kb(v, D, p); + v = lb(v, D, p); y = v.length; if (!y && !n) { - return p ? v : new X(v); + return p ? v : new Y(v); } F--; } } if (y) { - f[g] = z, e.push(v), g++; + g[f] = z, e.push(v), f++; } else if (1 === l.length) { - return p ? e : new X(e); + return p ? e : new Y(e); } } } if (r) { - if (this.db && m && m.length && !Ha) { + if (this.db && m && m.length && !Ka) { for (q = 0; q < m.length; q += 2) { - f = this.index.get(m[q]); - if (!f) { + g = this.index.get(m[q]); + if (!g) { if (console.warn("Tag '" + m[q] + ":" + m[q + 1] + "' was not found because there is no field '" + m[q] + "'."), n) { continue; } else { - return p ? e : new X(e); + return p ? e : new Y(e); } } - r.push(f.db.tag(m[q + 1], b, x, !1)); + r.push(g.db.tag(m[q + 1], b, x, !1)); } } - var Wb = this; + var Yb = this; return Promise.all(r).then(function(P) { - return P.length ? Wb.search(a, b, c, P) : P; + return P.length ? Yb.search(a, b, c, P) : P; }); } - if (!g) { - return p ? e : new X(e); + if (!f) { + return p ? e : new Y(e); } if (h && (!q || !this.store)) { return e[0]; } r = []; x = 0; - for (n = void 0; x < f.length; x++) { + for (n = void 0; x < g.length; x++) { n = e[x]; - q && n.length && !n[0].doc && (this.db ? r.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = W.call(this, n)); + q && n.length && !n[0].doc && (this.db ? r.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = X.call(this, n)); if (h) { - return p ? n : new X(n); + return p ? n : new Y(n); } - e[x] = {field:f[x], result:n}; + e[x] = {field:g[x], result:n}; } if (q && this.db && r.length) { - var Ia = this; + var La = this; return Promise.all(r).then(function(P) { for (var Q = 0; Q < P.length; Q++) { e[Q].result = P[Q]; } - return k ? ub(e, b) : t ? vb(e, a, Ia.index, Ia.field, Ia.J, t) : e; + return k ? vb(e, b) : t ? wb(e, a, La.index, La.field, La.J, t) : e; }); } - return k ? ub(e, b) : t ? vb(e, a, this.index, this.field, this.J, t) : e; + return k ? vb(e, b) : t ? wb(e, a, this.index, this.field, this.J, t) : e; }; -function vb(a, b, c, d, e, f) { - for (var g, h, k, l = 0, m, n, p; l < a.length; l++) { - for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== g && (g = p, h = g.encode(b)), p = 0; p < m.length; p++) { - var q = "", t = ya(m[p].doc, n), x = g.encode(t); - t = t.split(g.split); +function wb(a, b, c, d, e, g) { + for (var f, h, k, l = 0, m, n, p; l < a.length; l++) { + for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== f && (f = p, h = f.encode(b)), p = 0; p < m.length; p++) { + var q = "", t = ya(m[p].doc, n), x = f.encode(t); + t = t.split(f.split); for (var r = 0, A, z; r < x.length; r++) { A = x[r]; z = t[r]; for (var v = void 0, y = 0, D; y < h.length; y++) { if (D = h[y], "strict" === k) { if (A === D) { - q += (q ? " " : "") + f.replace("$1", z); + q += (q ? " " : "") + g.replace("$1", z); v = !0; break; } } else { var F = A.indexOf(D); if (-1 < F) { - q += (q ? " " : "") + z.substring(0, F) + f.replace("$1", z.substring(F, D.length)) + z.substring(F + D.length); + q += (q ? " " : "") + z.substring(0, F) + g.replace("$1", z.substring(F, D.length)) + z.substring(F + D.length); v = !0; break; } @@ -2301,38 +2316,38 @@ function vb(a, b, c, d, e, f) { } return a; } -function ub(a, b) { - for (var c = [], d = J(), e = 0, f, g; e < a.length; e++) { - f = a[e]; - g = f.result; - for (var h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = d[k]) { - m.push(f.field); +function vb(a, b) { + for (var c = [], d = J(), 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++) { + if (l = f[h], k = l.id, m = d[k]) { + m.push(g.field); } else { if (c.length === b) { return c; } - l.field = d[k] = [f.field]; + l.field = d[k] = [g.field]; c.push(l); } } } return c; } -function tb(a, b, c, d, e) { - var f = this.tag.get(a); - if (!f) { +function ub(a, b, c, d, e) { + var g = this.tag.get(a); + if (!g) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { + if ((a = (g = g && g.get(b)) && g.length - d) && 0 < a) { if (a > c || d) { - f = f.slice(d, d + c); + g = g.slice(d, d + c); } - e && (f = W.call(this, f)); - return f; + e && (g = X.call(this, g)); + return g; } } -function W(a) { +function X(a) { if (!this || !this.store) { return a; } @@ -2341,23 +2356,23 @@ function W(a) { } return b; } -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); +;function W(a) { + if (!this || this.constructor !== W) { + return new W(a); } var b = a.document || a.doc || a, c, d; this.J = []; this.field = []; this.S = []; - this.key = (c = b.key || b.id) && wb(c, this.S) || "id"; + this.key = (c = b.key || b.id) && xb(c, this.S) || "id"; (d = a.keystore || 0) && (this.keystore = d); - this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new T(d) : new Map() : d ? new U(d) : new Set(); + this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new U(d) : new Map() : d ? new V(d) : new Set(); this.I = (c = b.store || null) && c && !0 !== c && []; - this.store = c && (d ? new T(d) : new Map()); - this.cache = (c = a.cache || null) && new Y(c); + this.store = c && (d ? new U(d) : new Map()); + this.cache = (c = a.cache || null) && new Z(c); a.cache = !1; this.worker = a.worker; - this.index = xb.call(this, a, b); + this.index = yb.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -2371,7 +2386,7 @@ function W(a) { if (!e) { throw Error("The tag field from the document descriptor is undefined."); } - d.custom ? this.L[b] = d.custom : (this.L[b] = wb(e, this.S), d.filter && ("string" === typeof this.L[b] && (this.L[b] = new String(this.L[b])), this.L[b].R = d.filter)); + d.custom ? this.L[b] = d.custom : (this.L[b] = xb(e, this.S), d.filter && ("string" === typeof this.L[b] && (this.L[b] = new String(this.L[b])), this.L[b].R = d.filter)); this.aa[b] = e; this.tag.set(e, new Map()); } @@ -2384,28 +2399,28 @@ function W(a) { b = b.value, b.then && a.push(b); } if (a.length) { - var f = this; - return Promise.all(a).then(function(g) { - for (var h = 0, k = w(f.index.entries()), l = k.next(); !l.done; l = k.next()) { + var g = this; + return Promise.all(a).then(function(f) { + for (var h = 0, k = w(g.index.entries()), l = k.next(); !l.done; l = k.next()) { l = l.value; var m = l[0]; - l[1].then && f.index.set(m, g[h++]); + l[1].then && g.index.set(m, f[h++]); } - return f; + return g; }); } } else { a.db && this.mount(a.db); } } -u = V.prototype; +u = W.prototype; u.mount = function(a) { var b = this.field; if (this.tag) { for (var c = 0, d; c < this.aa.length; c++) { d = this.aa[c]; var e; - this.index.set(d, e = new O({}, this.reg)); + this.index.set(d, e = new R({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(d); e.tag = this.tag.get(d); @@ -2414,26 +2429,26 @@ u.mount = function(a) { c = []; d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; e = 0; - for (var f; e < b.length; e++) { - d.field = f = b[e]; - f = this.index.get(f); - var g = new a.constructor(a.id, d); - g.id = a.id; - c[e] = g.mount(f); - f.document = !0; - e ? f.bypass = !0 : f.store = this.store; + for (var g; e < b.length; e++) { + d.field = g = b[e]; + g = this.index.get(g); + var f = new a.constructor(a.id, d); + f.id = a.id; + c[e] = f.mount(g); + g.document = !0; + e ? g.bypass = !0 : g.store = this.store; } this.db = !0; return Promise.all(c); }; u.commit = function(a, b) { - var c = this, d, e, f, g; + var c = this, d, e, g, f; return ta(function(h) { if (1 == h.h) { d = []; e = w(c.index.values()); - for (f = e.next(); !f.done; f = e.next()) { - g = f.value, d.push(g.db.commit(g, a, b)); + for (g = e.next(); !g.done; g = e.next()) { + f = g.value, d.push(f.db.commit(f, a, b)); } return E(h, Promise.all(d), 2); } @@ -2447,29 +2462,29 @@ u.destroy = function() { } return Promise.all(a); }; -function xb(a, b) { +function yb(a, b) { var c = new Map(), d = b.index || b.field || b; K(d) && (d = [d]); - for (var e = 0, f, g = void 0; e < d.length; e++) { - f = d[e]; - K(f) || (g = f, f = f.field); - g = M(g) ? Object.assign({}, a, g) : a; + for (var e = 0, g, f = void 0; e < d.length; e++) { + g = d[e]; + K(g) || (f = g, g = g.field); + f = M(f) ? Object.assign({}, a, f) : a; if (this.worker) { - var h = new R(g); - c.set(f, h); + var h = new S(f); + c.set(g, h); } - this.worker || c.set(f, new O(g, this.reg)); - g.custom ? this.J[e] = g.custom : (this.J[e] = wb(f, this.S), g.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = g.filter)); - this.field[e] = f; + this.worker || c.set(g, new R(f, this.reg)); + f.custom ? this.J[e] = f.custom : (this.J[e] = xb(g, this.S), f.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = f.filter)); + this.field[e] = g; } if (this.I) { for (a = b.store, K(a) && (a = [a]), b = 0; b < a.length; b++) { - d = a[b], e = d.field || d, d.custom ? (this.I[b] = d.custom, d.custom.ja = e) : (this.I[b] = wb(e, this.S), d.filter && ("string" === typeof this.I[b] && (this.I[b] = new String(this.I[b])), this.I[b].R = d.filter)); + d = a[b], e = d.field || d, d.custom ? (this.I[b] = d.custom, d.custom.ja = e) : (this.I[b] = xb(e, this.S), d.filter && ("string" === typeof this.I[b] && (this.I[b] = new String(this.I[b])), this.I[b].R = d.filter)); } } return c; } -function wb(a, b) { +function xb(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); } @@ -2492,11 +2507,11 @@ u.remove = function(a) { for (b = w(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c = c.value; for (var d = w(c), e = d.next(); !e.done; e = d.next()) { - var f = e.value; - e = f[0]; - f = f[1]; - var g = f.indexOf(a); - -1 < g && (1 < f.length ? f.splice(g, 1) : c.delete(e)); + var g = e.value; + e = g[0]; + g = g[1]; + var f = g.indexOf(a); + -1 < f && (1 < g.length ? g.splice(f, 1) : c.delete(e)); } } } @@ -2536,44 +2551,44 @@ u.set = function(a, b) { this.store.set(a, b); return this; }; -u.searchCache = yb; +u.searchCache = zb; u.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; if (c < this.field.length) { var e = this.field[c]; if ((b = this.index.get(e).export(a, e, c, d = 1)) && b.then) { - var f = this; + var g = this; return b.then(function() { - return f.export(a, e, c + 1); + return g.export(a, e, c + 1); }); } return this.export(a, e, c + 1); } switch(d) { case 0: - var g = "reg"; + var f = "reg"; var h = Ya(this.reg); b = null; break; case 1: - g = "tag"; + f = "tag"; h = Wa(this.tag, this.reg.size); b = null; break; case 2: - g = "doc"; + f = "doc"; h = Ua(this.store); b = null; break; case 3: - g = "cfg"; + f = "cfg"; b = h = null; break; default: return; } - return $a.call(this, a, b, g, h, c, d); + return $a.call(this, a, b, f, h, c, d); }; u.import = function(a, b) { if (b) { @@ -2601,91 +2616,91 @@ u.import = function(a, b) { } } }; -Na(V.prototype); -function yb(a, b, c) { +Ja(W.prototype); +function zb(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Y()); + this.cache || (this.cache = new Z()); var d = this.cache.get(a); if (!d) { d = this.search(a, b, c); if (d.then) { var e = this; - d.then(function(f) { - e.cache.set(a, f); - return f; + d.then(function(g) { + e.cache.set(a, g); + return g; }); } this.cache.set(a, d); } return d; } -function Y(a) { +function Z(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -Y.prototype.set = function(a, b) { +Z.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); }; -Y.prototype.get = function(a) { +Z.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; }; -Y.prototype.remove = function(a) { +Z.prototype.remove = function(a) { for (var b = w(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); } }; -Y.prototype.clear = function() { +Z.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -var zb = {normalize:function(a) { +var Ab = {normalize:function(a) { return a.toLowerCase(); }}; -var Ab = 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 Bb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Cb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -var Db = {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 Eb = /[\x00-\x7F]+/g; +var Bb = 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 Cb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Db = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +var Eb = {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 Fb = /[\x00-\x7F]+/g; var Gb = /[\x00-\x7F]+/g; -var Hb = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:zb, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ab}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ab, matcher:Bb, replacer:Cb}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ab, replacer:Cb.concat([/(?!^)[aeo]/g, ""]), matcher:Bb}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +var Hb = /[\x00-\x7F]+/g; +var Ib = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ab, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Bb}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Bb, matcher:Cb, replacer:Db}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Bb, replacer:Db.concat([/(?!^)[aeo]/g, ""]), matcher:Cb}, 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 = Db[d], f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Db[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + for (var c = a[b], d = c.charAt(0), e = Eb[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = Eb[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(Eb, " "); + return ("" + a).replace(Fb, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Fb, ""); + return ("" + a).replace(Gb, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Gb, " "); + return ("" + a).replace(Hb, " "); }}}; -var Ib = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -O.prototype.add = function(a, b, c, d) { +var Jb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +R.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { if (!d && !c && this.reg.has(a)) { return this.update(a, b); } b = this.encoder.encode(b); if (d = b.length) { - for (var e = J(), f = J(), g = this.depth, h = this.resolution, k = 0; k < d; k++) { + for (var e = J(), g = J(), 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 && (g || !f[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : Jb(h, d, k), p = ""; + if (m && (f || !g[l])) { + var n = this.score ? this.score(b, l, k, null, 0) : Kb(h, d, k), p = ""; switch(this.tokenize) { case "full": if (2 < m) { for (n = 0; n < m; n++) { for (var q = m; q > n; q--) { p = l.substring(n, q); - var t = this.score ? this.score(b, l, k, p, n) : Jb(h, d, k, m, n); - Kb(this, f, p, t, a, c); + var t = this.score ? this.score(b, l, k, p, n) : Kb(h, d, k, m, n); + Lb(this, g, p, t, a, c); } } break; @@ -2693,24 +2708,24 @@ O.prototype.add = function(a, b, c, d) { case "reverse": if (1 < m) { for (q = m - 1; 0 < q; q--) { - p = l[q] + p, t = this.score ? this.score(b, l, k, p, q) : Jb(h, d, k, m, q), Kb(this, f, p, t, a, c); + p = l[q] + p, t = this.score ? this.score(b, l, k, p, q) : Kb(h, d, k, m, q), Lb(this, g, p, t, a, c); } p = ""; } case "forward": if (1 < m) { for (q = 0; q < m; q++) { - p += l[q], Kb(this, f, p, n, a, c); + p += l[q], Lb(this, g, p, n, a, c); } break; } default: - if (Kb(this, f, l, n, a, c), g && 1 < d && k < d - 1) { - for (m = J(), p = this.da, n = l, q = Math.min(g + 1, d - k), t = m[n] = 1; t < q; t++) { + if (Lb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { + for (m = J(), p = this.da, n = l, q = Math.min(f + 1, d - k), t = m[n] = 1; t < q; t++) { if ((l = b[this.rtl ? d - 1 - k - t : k + t]) && !m[l]) { m[l] = 1; - var x = this.score ? this.score(b, n, k, l, t) : Jb(p + (d / 2 > p ? 0 : 1), d, k, q - 1, t - 1), r = this.bidirectional && l > n; - Kb(this, e, r ? n : l, x, a, c, r ? l : n); + var x = this.score ? this.score(b, n, k, l, t) : Kb(p + (d / 2 > p ? 0 : 1), d, k, q - 1, t - 1), r = this.bidirectional && l > n; + Lb(this, e, r ? n : l, x, a, c, r ? l : n); } } } @@ -2722,18 +2737,18 @@ O.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.ca && Lb(this)); + this.db && (b || this.commit_task.push({del:a}), this.ca && Mb(this)); return this; }; -function Kb(a, b, c, d, e, f, g) { - var h = g ? a.ctx : a.map, k; - if (!b[c] || g && !(k = b[c])[g]) { - if (g ? (b = k || (b[c] = J()), 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)) { +function Lb(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] = J()), 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); + b = new bb(h); if (a.fastupdate) { - for (c = w(a.reg.values()), f = c.next(); !f.done; f = c.next()) { - f = f.value, f.includes(h) && (f[f.indexOf(h)] = b); + for (c = w(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; @@ -2743,43 +2758,43 @@ function Kb(a, b, c, d, e, f, g) { } } } -function Jb(a, b, c, d, e) { +function Kb(a, b, c, d, e) { return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; } -;O.prototype.search = function(a, b, c) { +;R.prototype.search = function(a, b, c) { c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); - var d = [], e = 0, f; + var d = [], e = 0, g; if (c) { a = c.query || a; b = c.limit || b; e = c.offset || 0; - var g = c.context; + var f = c.context; var h = c.suggest; - var k = (f = !1 !== c.resolve) && c.enrich; + var k = (g = !1 !== c.resolve) && c.enrich; var l = c.boost; var m = c.resolution; var n = this.db && c.tag; } else { - f = this.resolve; + g = this.resolve; } var p = this.encoder.encode(a); var q = p.length; - b = b || (f ? 100 : 0); + b = b || (g ? 100 : 0); if (1 === q) { - return Mb.call(this, p[0], "", b, e, f, k, n); + return Nb.call(this, p[0], "", b, e, g, k, n); } - g = this.depth && !1 !== g; - if (2 === q && g && !h) { - return Mb.call(this, p[0], p[1], b, e, f, k, n); + f = this.depth && !1 !== f; + if (2 === q && f && !h) { + return Nb.call(this, p[0], p[1], b, e, g, k, n); } var t = J(), x = 0; - if (1 < q && g) { + if (1 < q && f) { var r = p[0]; x = 1; } m || 0 === m || (m = r ? this.da : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, p, b, e, h, f, k, n), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, b, e, h, g, k, n), !1 !== a)) { return a; } var A = this; @@ -2800,10 +2815,10 @@ function Jb(a, b, c, d, e) { break; } t[v] = 1; - return E(y, Nb(A, v, r, 0, 0, !1, !1), 6); + return E(y, Ob(A, v, r, 0, 0, !1, !1), 6); case 6: z = y.G; - if (z = Ob(z, d, h, m)) { + if (z = Pb(z, d, h, m)) { d = z; y.h = 4; break; @@ -2815,7 +2830,7 @@ function Jb(a, b, c, d, e) { y.h = 2; break; case 4: - return y.return(Pb(d, m, b, e, h, l, f)); + return y.return(Qb(d, m, b, e, h, l, g)); } }); }(); @@ -2823,8 +2838,8 @@ function Jb(a, b, c, d, e) { for (c = a = void 0; x < q; x++) { if ((c = p[x]) && !t[c]) { t[c] = 1; - a = Nb(this, c, r, 0, 0, !1, !1); - if (a = Ob(a, d, h, m)) { + a = Ob(this, c, r, 0, 0, !1, !1); + if (a = Pb(a, d, h, m)) { d = a; break; } @@ -2832,33 +2847,33 @@ function Jb(a, b, c, d, e) { } h && r && x === q - 1 && !d.length && (r = "", x = -1, t = J()); } - return Pb(d, m, b, e, h, l, f); + return Qb(d, m, b, e, h, l, g); }; -function Pb(a, b, c, d, e, f, g) { +function Qb(a, b, c, d, e, g, f) { var h = a.length, k = a; if (1 < h) { - k = ib(a, b, c, d, e, f, g); + k = jb(a, b, c, d, e, g, f); } else if (1 === h) { - return g ? lb.call(null, a[0], c, d) : new X(a[0]); + return f ? mb.call(null, a[0], c, d) : new Y(a[0]); } - return g ? k : new X(k); + return f ? k : new Y(k); } -function Mb(a, b, c, d, e, f, g) { - a = Nb(this, a, b, c, d, e, f, g); +function Nb(a, b, c, d, e, g, f) { + a = Ob(this, a, b, c, d, e, g, f); return this.db ? a.then(function(h) { - return e ? h || [] : new X(h); - }) : a && a.length ? e ? lb.call(this, a, c, d) : new X(a) : e ? [] : new X(); + return e ? h || [] : new Y(h); + }) : a && a.length ? e ? mb.call(this, a, c, d) : new Y(a) : e ? [] : new Y(); } -function Ob(a, b, c, d) { +function Pb(a, b, c, d) { var e = []; if (a && a.length) { if (a.length <= d) { b.push(a); return; } - for (var f = 0, g; f < d; f++) { - if (g = a[f]) { - e[f] = g; + for (var g = 0, f; g < d; g++) { + if (f = a[g]) { + e[g] = f; } } if (e.length) { @@ -2870,16 +2885,16 @@ function Ob(a, b, c, d) { return e; } } -function Nb(a, b, c, d, e, f, g, h) { +function Ob(a, b, c, d, e, g, f, h) { var k; c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); if (a.db) { - return a.db.get(b, c, d, e, f, g, h); + return a.db.get(b, c, d, e, g, f, h); } a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;O.prototype.remove = function(a, b) { +;R.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) { @@ -2888,27 +2903,27 @@ function Nb(a, b, c, d, e, f, g, h) { if (2 > e.length) { e.pop(); } else { - var f = e.indexOf(a); - f === c.length - 1 ? e.pop() : e.splice(f, 1); + var g = e.indexOf(a); + g === c.length - 1 ? e.pop() : e.splice(g, 1); } } } } else { - Qb(this.map, a), this.depth && Qb(this.ctx, a); + Rb(this.map, a), this.depth && Rb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.ca && Lb(this)); + this.db && (this.commit_task.push({del:a}), this.ca && Mb(this)); this.cache && this.cache.remove(a); return this; }; -function Qb(a, b) { +function Rb(a, b) { var c = 0; if (a.constructor === Array) { - for (var d = 0, e = void 0, f; d < a.length; d++) { + for (var d = 0, e = void 0, g; d < a.length; d++) { if ((e = a[d]) && e.length) { - if (f = e.indexOf(b), 0 <= f) { - 1 < e.length ? (e.splice(f, 1), c++) : delete a[d]; + if (g = e.indexOf(b), 0 <= g) { + 1 < e.length ? (e.splice(g, 1), c++) : delete a[d]; break; } else { c++; @@ -2917,23 +2932,23 @@ function Qb(a, b) { } } else { for (d = w(a.entries()), e = d.next(); !e.done; e = d.next()) { - f = e.value, e = f[0], (f = Qb(f[1], b)) ? c += f : a.delete(e); + g = e.value, e = g[0], (g = Rb(g[1], b)) ? c += g : a.delete(e); } } return c; } -;function O(a, b) { - if (!this || this.constructor !== O) { - return new O(a); +;function R(a, b) { + if (!this || this.constructor !== R) { + return new R(a); } if (a) { var c = K(a) ? a : a.preset; - c && (Ib[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ib[c], a)); + c && (Jb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Jb[c], a)); } else { a = {}; } c = a.context; - var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Hb[a.encoder] : a.encode || a.encoder || zb; + var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Ib[a.encoder] : a.encode || a.encoder || Ab; this.encoder = e.encode ? e : "object" === typeof e ? new Ga(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = c = a.tokenize || "strict"; @@ -2942,12 +2957,12 @@ function Qb(a, b) { this.fastupdate = !!a.fastupdate; this.score = a.score || null; (c = a.keystore || 0) && (this.keystore = c); - this.map = c ? new T(c) : new Map(); - this.ctx = c ? new T(c) : new Map(); - this.reg = b || (this.fastupdate ? c ? new T(c) : new Map() : c ? new U(c) : new Set()); + this.map = c ? new U(c) : new Map(); + this.ctx = c ? new U(c) : new Map(); + this.reg = b || (this.fastupdate ? c ? new U(c) : new Map() : c ? new V(c) : new Set()); this.da = d.resolution || 3; this.rtl = e.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new Y(c); + this.cache = (c = a.cache || null) && new Z(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); @@ -2957,7 +2972,7 @@ function Qb(a, b) { this.commit_timer = null; this.priority = a.priority || 4; } -u = O.prototype; +u = R.prototype; u.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -2970,7 +2985,7 @@ u.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Lb(a) { +function Mb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2996,7 +3011,7 @@ u.update = function(a, b) { return c.add(a, b); }) : this.add(a, b); }; -function Rb(a) { +function Sb(a) { var b = 0; if (a.constructor === Array) { for (var c = 0, d = void 0; c < a.length; c++) { @@ -3006,7 +3021,7 @@ function Rb(a) { for (c = w(a), d = c.next(); !d.done; d = c.next()) { var e = d.value; d = e[0]; - (e = Rb(e[1])) ? b += e : a.delete(d); + (e = Sb(e[1])) ? b += e : a.delete(d); } } return b; @@ -3015,35 +3030,35 @@ u.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Rb(this.map); - this.depth && Rb(this.ctx); + Sb(this.map); + this.depth && Sb(this.ctx); return this; }; -u.searchCache = yb; +u.searchCache = zb; u.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; switch(d) { case 0: var e = "reg"; - var f = Ya(this.reg); + var g = Ya(this.reg); break; case 1: e = "cfg"; - f = null; + g = null; break; case 2: e = "map"; - f = Ua(this.map, this.reg.size); + g = Ua(this.map, this.reg.size); break; case 3: e = "ctx"; - f = Wa(this.ctx, this.reg.size); + g = Wa(this.ctx, this.reg.size); break; default: return; } - return $a.call(this, a, b, e, f, c, d); + return $a.call(this, a, b, e, g, c, d); }; u.import = function(a, b) { if (b) { @@ -3071,26 +3086,26 @@ u.serialize = function(a) { b = "index.reg=new Set([" + b + "]);"; d = ""; e = w(this.map.entries()); - for (var f = e.next(); !f.done; f = e.next()) { - var g = f.value; - f = g[0]; - g = g[1]; - for (var h = "", k = 0, l; k < g.length; k++) { - l = g[k] || [""]; + for (var g = e.next(); !g.done; g = e.next()) { + var f = g.value; + g = f[0]; + f = f[1]; + for (var h = "", k = 0, l; k < f.length; k++) { + l = f[k] || [""]; for (var m = "", n = 0; n < l.length; n++) { m += (m ? "," : "") + ("string" === c ? '"' + l[n] + '"' : l[n]); } m = "[" + m + "]"; h += (h ? "," : "") + m; } - h = '["' + f + '",[' + h + "]]"; + h = '["' + g + '",[' + h + "]]"; d += (d ? "," : "") + h; } d = "index.map=new Map([" + d + "]);"; e = ""; - f = w(this.ctx.entries()); - for (g = f.next(); !g.done; g = f.next()) { - for (h = g.value, g = h[0], h = w(h[1].entries()), k = h.next(); !k.done; k = h.next()) { + g = w(this.ctx.entries()); + for (f = g.next(); !f.done; f = g.next()) { + for (h = f.value, f = h[0], h = w(h[1].entries()), k = h.next(); !k.done; k = h.next()) { l = k.value; k = l[0]; l = l[1]; @@ -3105,19 +3120,19 @@ u.serialize = function(a) { m += (m ? "," : "") + q; } m = 'new Map([["' + k + '",[' + m + "]]])"; - m = '["' + g + '",' + m + "]"; + m = '["' + f + '",' + m + "]"; e += (e ? "," : "") + m; } } e = "index.ctx=new Map([" + e + "]);"; return a ? "function inject(index){" + b + d + e + "}" : b + d + e; }; -Na(O.prototype); -var Sb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Tb = ["map", "ctx", "tag", "reg", "cfg"]; -function Ub(a, b) { +Ja(R.prototype); +var Tb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ub = ["map", "ctx", "tag", "reg", "cfg"]; +function Vb(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Ub(a, b); + return new Vb(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3128,7 +3143,7 @@ function Ub(a, b) { this.db = null; this.h = {}; } -u = Ub.prototype; +u = Vb.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -3140,11 +3155,11 @@ u.open = function() { var a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - var d = Sb.open(a.id + (a.field ? ":" + a.field : ""), 1); + var d = Tb.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { var e = a.db = this.result; - Tb.forEach(function(f) { - e.objectStoreNames.contains(f) || e.createObjectStore(f); + Ub.forEach(function(g) { + e.objectStoreNames.contains(g) || e.createObjectStore(g); }); }; d.onblocked = function(e) { @@ -3169,23 +3184,23 @@ u.close = function() { this.db = null; }; u.destroy = function() { - var a = Sb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); - return Z(a); + var a = Tb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Wb(a); }; u.clear = function() { - for (var a = this.db.transaction(Tb, "readwrite"), b = 0; b < Tb.length; b++) { - a.objectStore(Tb[b]).clear(); + for (var a = this.db.transaction(Ub, "readwrite"), b = 0; b < Ub.length; b++) { + a.objectStore(Ub[b]).clear(); } - return Z(a); + return Wb(a); }; -u.get = function(a, b, c, d, e, f) { +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; - f = void 0 === f ? !1 : f; + g = void 0 === g ? !1 : g; a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); - var g = this; - return Z(a).then(function(h) { + var f = this; + return Wb(a).then(function(h) { var k = []; if (!h || !h.length) { return k; @@ -3209,7 +3224,7 @@ u.get = function(a, b, c, d, e, f) { } } } - return f ? g.enrich(k) : k; + return g ? f.enrich(k) : k; } return h; }); @@ -3220,32 +3235,32 @@ u.tag = function(a, b, c, d) { d = void 0 === d ? !1 : d; a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); var e = this; - return Z(a).then(function(f) { - if (!f || !f.length || c >= f.length) { + return Wb(a).then(function(g) { + if (!g || !g.length || c >= g.length) { return []; } if (!b && !c) { - return f; + return g; } - f = f.slice(c, c + b); - return d ? e.enrich(f) : f; + 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; d < a.length; d++) { - c[d] = Z(b.get(a[d])); + c[d] = Wb(b.get(a[d])); } return Promise.all(c).then(function(e) { - for (var f = 0; f < e.length; f++) { - e[f] = {id:a[f], doc:e[f] ? JSON.parse(e[f]) : null}; + for (var g = 0; g < e.length; g++) { + e[g] = {id:a[g], doc:e[g] ? JSON.parse(e[g]) : null}; } return e; }); }; u.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Z(a); + return Wb(a); }; u.search = null; u.info = function() { @@ -3255,24 +3270,24 @@ u.transaction = function(a, b, c) { if (e) { return c.call(this, e); } - var f = this.db.transaction(a, b); - this.h[a + ":" + b] = e = f.objectStore(a); - return new Promise(function(g, h) { - f.onerror = function(k) { + var g = this.db.transaction(a, b); + this.h[a + ":" + b] = e = g.objectStore(a); + return new Promise(function(f, h) { + g.onerror = function(k) { d.h[a + ":" + b] = null; - f.abort(); - f = e = null; + g.abort(); + g = e = null; h(k); }; - f.oncomplete = function(k) { - f = e = d.h[a + ":" + b] = null; - g(k || !0); + g.oncomplete = function(k) { + g = e = d.h[a + ":" + b] = null; + f(k || !0); }; return c.call(d, e); }); }; u.commit = function(a, b, c) { - var d = this, e, f, g; + var d = this, e, g, f; return ta(function(h) { switch(h.h) { case 1: @@ -3281,16 +3296,16 @@ u.commit = function(a, b, c) { } e = a.commit_task; a.commit_task = []; - f = 0; - g = void 0; + g = 0; + f = void 0; case 4: - if (!(f < e.length)) { + if (!(g < e.length)) { h.h = 6; break; } - g = e[f]; - if (!g.clear) { - e[f] = g.ma; + f = e[g]; + if (!f.clear) { + e[g] = f.ma; h.h = 5; break; } @@ -3300,7 +3315,7 @@ u.commit = function(a, b, c) { h.h = 6; break; case 5: - f++; + g++; h.h = 4; break; case 6: @@ -3420,11 +3435,11 @@ u.commit = function(a, b, c) { } }); }; -function Xb(a, b, c) { - for (var d = a.value, e, f, g = 0, h = 0, k; h < d.length; h++) { +function Zb(a, b, c) { + for (var d = a.value, e, g, f = 0, h = 0, k; h < d.length; h++) { if (k = c ? d : d[h]) { for (var l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = k.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { + if (n = b[l], m = k.indexOf(g ? parseInt(n, 10) : n), 0 > m && !g && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (g = 1), 0 <= m) { if (e = 1, 1 < k.length) { k.splice(m, 1); } else { @@ -3433,13 +3448,13 @@ function Xb(a, b, c) { } } } - g += k.length; + f += k.length; } if (c) { break; } } - g ? e && a.update(d) : a.delete(); + f ? e && a.update(d) : a.delete(); a.continue(); } u.remove = function(a) { @@ -3447,17 +3462,17 @@ u.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Xb(c, a); + c && Zb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Xb(c, a); + c && Zb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Xb(c, a, !0); + c && Zb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3465,7 +3480,7 @@ u.remove = function(a) { } })]); }; -function Z(a) { +function Wb(a) { return new Promise(function(b, c) { a.onsuccess = function() { b(this.result); @@ -3477,8 +3492,8 @@ function Z(a) { a = null; }); } -;var Yb = {Index:O, Charset:Hb, Encoder:Ga, Document:V, Worker:R, Resolver:X, IndexedDB:Ub, Language:{}}, Zb = self, $b; -($b = Zb.define) && $b.amd ? $b([], function() { - return Yb; -}) : "object" === typeof Zb.exports ? Zb.exports = Yb : Zb.FlexSearch = Yb; +;var $b = {Index:R, Charset:Ib, Encoder:Ga, Document:W, Worker:S, Resolver:Y, IndexedDB:Vb, Language:{}}, ac = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}, bc; +(bc = ac.define) && bc.amd ? bc([], function() { + return $b; +}) : "object" === typeof ac.exports ? ac.exports = $b : ac.FlexSearch = $b; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index beef916..ce05e76 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.107 (ES5) + * FlexSearch.js v0.8.108 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -51,85 +51,85 @@ u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);t u.encode=function(a){var b=this;if(this.cache&&a.length<=this.G)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(N,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=Fa?a.normalize("NFKD").replace(Fa,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};function Ja(a){var b,c,d,e,g,f,h;return ta(function(k){a=a.data;b=self._index;c=a.args;d=a.task;switch(d){case "init":e=a.options||{};(g=a.factory)?(Function("return "+g)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new O(e);postMessage({id:a.id});break;default:f=a.id,h=b[d].apply(b,c),postMessage("search"===d?{id:f,msg:h}:{id:f})}k.h=0})};var Ka=0; -function R(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=I();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Ka]=function(){k(e)};e.worker.postMessage({id:Ka,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(!this||this.constructor!==R)return new R(a);var c="undefined"!==typeof self?self._factory: -"undefined"!==typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,g=La(c,d,a.worker);return g.then?g.then(function(f){return b.call(e,f)}):b.call(this,g)}Ma("add");Ma("append");Ma("search");Ma("update");Ma("remove"); -function Ma(a){R.prototype[a]=R.prototype[a+"Async"]=function(){var b=this,c=arguments,d,e,g,f,h;return ta(function(k){d=b;e=[].slice.call(c);g=e[e.length-1];"function"===typeof g&&(f=g,e.splice(e.length-1,1));h=new Promise(function(l){d.h[++Ka]=l;d.worker.postMessage({task:a,id:Ka,args:e})});return f?(h.then(f),k.return(b)):k.return(h)})}} -function La(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ja.toString()],{type:"text/javascript"}))):new window.Worker(K(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function Na(a){Oa.call(a,"add");Oa.call(a,"append");Oa.call(a,"search");Oa.call(a,"update");Oa.call(a,"remove")}var Pa,Qa,Ra={},Sa={};function Ta(a){Pa=0;Ra[a]=Sa[a]} -function Oa(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]}Pa||(Pa=setTimeout(Ta,0,a),Qa=Date.now());Sa[a]||(Sa[a]=Ra[a]=1E3);if(!--Ra[a]){Ra[a]=Sa[a]=Sa[a]*this.priority*this.priority*3/(Date.now()-Qa)|0||1;Pa=clearTimeout(Pa);var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};function Ua(a,b){b=void 0===b?0:b;var c=[],d=[];b&&(b=25E4/b*5E3|0);a=w(a.entries());for(var e=a.next();!e.done;e=a.next())d.push(e.value),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function Va(a,b){b||(b=new Map);for(var c=0,d;cthis.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};var O,Ha;function Ia(a){var b,c,d,e,g;return ta(function(f){if(1==f.h)switch(a=a.data,b=a.task,c=a.id,d=a.args,b){case "init":Ha=a.options||{};(e=a.factory)?(Function("return "+e)()(self),O=new self.FlexSearch.Index(Ha),delete self.FlexSearch):O=new R(Ha);postMessage({id:c});break;default:f.h=2;return}else{if(4!=f.h){"export"===b&&(d=[Ha.export]);if("import"!==b){g=O[b].apply(O,d);f.h=4;return}return E(f,Ha.import.call(O,O),4)}postMessage("search"===b?{id:c,msg:g}:{id:c})}f.h=0})};function Ja(a){Ma.call(a,"add");Ma.call(a,"append");Ma.call(a,"search");Ma.call(a,"update");Ma.call(a,"remove")}var Na,Oa,Pa={},Qa={};function Ra(a){Na=0;Pa[a]=Qa[a]} +function Ma(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]}Na||(Na=setTimeout(Ra,0,a),Oa=Date.now());Qa[a]||(Qa[a]=Pa[a]=1E3);if(!--Pa[a]){Pa[a]=Qa[a]=Qa[a]*this.priority*this.priority*3/(Date.now()-Oa)|0||1;Na=clearTimeout(Na);var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var Sa=0; +function S(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=I();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Sa]=function(){k(e)};e.worker.postMessage({id:Sa,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(!this||this.constructor!==S)return new S(a);var c="undefined"!==typeof self?self._factory: +"undefined"!==typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,g=Ta(c,d,a.worker);return g.then?g.then(function(f){return b.call(e,f)}):b.call(this,g)}T("add");T("append");T("search");T("update");T("remove");T("clear");T("export");T("import");Ja(S.prototype); +function T(a){S.prototype[a]=function(){var b=this,c=arguments,d,e,g,f,h;return ta(function(k){d=b;e=[].slice.call(c);g=e[e.length-1];"function"===typeof g&&(f=g,e.splice(e.length-1,1));h=new Promise(function(l){d.h[++Sa]=l;d.worker.postMessage({task:a,id:Sa,args:e})});return f?(h.then(f),k.return(b)):k.return(h)})}} +function Ta(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ia.toString()],{type:"text/javascript"}))):new window.Worker(K(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function Ua(a,b){b=void 0===b?0:b;var c=[],d=[];b&&(b=25E4/b*5E3|0);a=w(a.entries());for(var e=a.next();!e.done;e=a.next())d.push(e.value),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function Va(a,b){b||(b=new Map);for(var c=0,d;c=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;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(g=0;gd)d-=f.length; +function bb(a){if(!this)return new bb(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;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(g=0;gd)d-=f.length; else{if(f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?W.call(this,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=b);if(!e.length&&h>=b)return d?W.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=jb(a,c,d,!1,this.h),d=0));return g?this.resolve(c,d,e):this};X.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var g=b.enrich&&c}}return a?(a=mb(this,"and",arguments),ob.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; -function ob(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=ib(a,b,c,d,f,this.h,g),g?e?W.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};X.prototype.xor=function(){var a=mb(this,"xor",arguments);return pb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; -function pb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=qb.call(this,a,c,d,g,this.h),g?e?W.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} -function qb(a,b,c,d,e){for(var g=[],f=I(),h=0,k=0,l;kb?b?a.slice(c,c+b):a.slice(c):a,d?X.call(this,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=b);if(!e.length&&h>=b)return d?X.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=kb(a,c,d,!1,this.h),d=0));return g?this.resolve(c,d,e):this};Y.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var g=b.enrich&&c}}return a?(a=nb(this,"and",arguments),pb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; +function pb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=jb(a,b,c,d,f,this.h,g),g?e?X.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};Y.prototype.xor=function(){var a=nb(this,"xor",arguments);return qb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; +function qb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=rb.call(this,a,c,d,g,this.h),g?e?X.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} +function rb(a,b,c,d,e){for(var g=[],f=I(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=W.call(this,a));return a}} -function W(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=X.call(this,a));return a}} +function X(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.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};Y.prototype.remove=function(a){for(var b=w(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)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};var zb={normalize:function(a){return a.toLowerCase()}};var Ab=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 Bb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Cb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];var Db={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 Eb=/[\x00-\x7F]+/g;var Fb=/[\x00-\x7F]+/g;var Gb=/[\x00-\x7F]+/g;var Hb={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:zb,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ab},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ab,matcher:Bb,replacer:Cb},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ab,replacer:Cb.concat([/(?!^)[aeo]/g,""]),matcher:Bb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):Jb(h,d,k,m,n);Kb(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),t=this.bidirectional&&l>n;Kb(this,e,t?n:l,x,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.ca&&Lb(this));return this}; -function Kb(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]=I()),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=w(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 Jb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.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 Qb(this.map,a),this.depth&&Qb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Lb(this));this.cache&&this.cache.remove(a);return this}; -function Qb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Z.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};Z.prototype.remove=function(a){for(var b=w(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)}};Z.prototype.clear=function(){this.cache.clear();this.h=""};var Ab={normalize:function(a){return a.toLowerCase()}};var Bb=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 Cb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Db=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];var Eb={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 Fb=/[\x00-\x7F]+/g;var Gb=/[\x00-\x7F]+/g;var Hb=/[\x00-\x7F]+/g;var Ib={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ab,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Bb},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Bb,matcher:Cb,replacer:Db},LatinExtra:{normalize:!0,dedupe:!0,mapper:Bb,replacer:Db.concat([/(?!^)[aeo]/g,""]),matcher:Cb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):Kb(h,d,k,m,n);Lb(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),t=this.bidirectional&&l>n;Lb(this,e,t?n:l,x,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.ca&&Mb(this));return this}; +function Lb(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]=I()),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 bb(h);if(a.fastupdate)for(c=w(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 Kb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};R.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 Rb(this.map,a),this.depth&&Rb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Mb(this));this.cache&&this.cache.remove(a);return this}; +function Rb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;d=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;d=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,1m&&!g&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(g=1),0<=m)if(e=1,1 this.stemmer.get(k)), f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); @@ -232,12 +232,125 @@ t.encode = function(a) { this.cache && a.length <= this.o && (this.i.set(a, b), this.i.size > this.C && (this.i.clear(), this.o = this.o / 1.1 | 0)); return b; }; -function B(a) { +function z(a) { a.l = null; a.i.clear(); a.j.clear(); } -;function C(a, c, b, d, e) { +;let A, C; +async function fa(a) { + a = a.data; + const c = a.task, b = a.id; + let d = a.args; + switch(c) { + case "init": + C = a.options || {}; + (a = a.factory) ? (Function("return " + a)()(self), A = new self.FlexSearch.Index(C), delete self.FlexSearch) : A = new D(C); + postMessage({id:b}); + break; + default: + let e; + "export" === c && (d = [C.export]); + "import" === c ? await C.import.call(A, A) : e = A[c].apply(A, d); + postMessage("search" === c ? {id:b, msg:e} : {id:b}); + } +} +;let E, F; +const G = {}, H = {}; +function ha(a) { + E = 0; + G[a] = H[a]; +} +function I(a) { + this[a + "Async"] = function() { + const c = arguments; + var b = c[c.length - 1]; + let d; + "function" === typeof b && (d = b, delete c[c.length - 1]); + E || (E = setTimeout(ha, 0, a), F = Date.now()); + H[a] || (H[a] = G[a] = 1000); + if (!--G[a]) { + G[a] = H[a] = H[a] * this.priority * this.priority * 3 / (Date.now() - F) | 0 || 1; + E = clearTimeout(E); + const g = this; + return new Promise(f => { + setTimeout(function() { + f(g[a + "Async"].apply(g, c)); + }, 0); + }); + } + const e = this[a].apply(this, c); + b = e.then ? e : new Promise(g => g(e)); + d && b.then(d); + return b; + }; +} +;let J = 0; +function K(a = {}) { + function c(f) { + function h(k) { + k = k.data || k; + const l = k.id, n = l && e.g[l]; + n && (n(k.msg), delete e.g[l]); + } + this.worker = f; + this.g = w(); + if (this.worker) { + d ? this.worker.on("message", h) : this.worker.onmessage = h; + if (a.config) { + return new Promise(function(k) { + e.g[++J] = function() { + k(e); + }; + e.worker.postMessage({id:J, task:"init", factory:b, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:b, options:a}); + return this; + } + } + if (!this || this.constructor !== K) { + return new K(a); + } + let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + b && (b = b.toString()); + const d = "undefined" === typeof window, e = this, g = ia(b, d, a.worker); + return g.then ? g.then(function(f) { + return c.call(e, f); + }) : c.call(this, g); +} +L("add"); +L("append"); +L("search"); +L("update"); +L("remove"); +L("clear"); +L("export"); +L("import"); +var M = K.prototype; +I.call(M, "add"); +I.call(M, "append"); +I.call(M, "search"); +I.call(M, "update"); +I.call(M, "remove"); +function L(a) { + K.prototype[a] = async function() { + const c = this, b = [].slice.call(arguments); + var d = b[b.length - 1]; + let e; + "function" === typeof d && (e = d, b.splice(b.length - 1, 1)); + d = new Promise(function(g) { + c.g[++J] = g; + c.worker.postMessage({task:a, id:J, args:b}); + }); + return e ? (d.then(e), this) : d; + }; +} +function ia(a, c, b) { + return c ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + fa.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function ja(a, c, b, d, e) { const g = a.length; let f = [], h, k; h = w(); @@ -252,7 +365,7 @@ function B(a) { } if (a = f.length) { if (e) { - f = 1 < f.length ? D(f, b, d) : (f = f[0]).length > b || d ? f.slice(d, b + d) : f; + f = 1 < f.length ? la(f, b, d) : (f = f[0]).length > b || d ? f.slice(d, b + d) : f; } else { if (a < g) { return []; @@ -267,7 +380,7 @@ function B(a) { } return f; } -function D(a, c, b) { +function la(a, c, b) { const d = [], e = w(); let g; var f = a.length; @@ -289,12 +402,12 @@ function D(a, c, b) { } return d; } -;function E(a, c, b, d) { +;function N(a, c, b, d) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, d ? F.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, d ? O.call(this, a) : a; } let e = []; for (let g = 0, f, h; g < a.length; g++) { @@ -308,7 +421,7 @@ function D(a, c, b) { } h > c && (f = f.slice(0, c), h = c); if (!e.length && h >= c) { - return d ? F.call(this, f) : f; + return d ? O.call(this, f) : f; } e.push(f); c -= h; @@ -318,9 +431,9 @@ function D(a, c, b) { } } e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? F.call(this, e) : e; + return d ? O.call(this, e) : e; } -;function G(a, c, b) { +;function P(a, c, b) { var d = b[0]; if (d.then) { return Promise.all(b).then(function(n) { @@ -335,7 +448,7 @@ function D(a, c, b) { for (let n = 0, m; n < b.length; n++) { if (m = b[n]) { let r; - if (m.constructor === I) { + if (m.constructor === Q) { r = m.result; } else if (m.constructor === Array) { r = m; @@ -366,11 +479,11 @@ function D(a, c, b) { } return {m:d, u:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; } -;I.prototype.or = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g} = G(this, "or", arguments); - return J.call(this, a, c, b, d, e, g); +;Q.prototype.or = function() { + const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g} = P(this, "or", arguments); + return ma.call(this, a, c, b, d, e, g); }; -function J(a, c, b, d, e, g) { +function ma(a, c, b, d, e, g) { if (c.length) { const f = this; return Promise.all(c).then(function(h) { @@ -378,25 +491,25 @@ function J(a, c, b, d, e, g) { for (let k = 0, l; k < h.length; k++) { (l = h[k]).length && (a[k] = l); } - return J.call(f, a, [], b, d, e, g); + return ma.call(f, a, [], b, d, e, g); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = D(a, b, d), d = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = la(a, b, d), d = 0)); return g ? this.resolve(b, d, e) : this; } -;I.prototype.and = function() { +;Q.prototype.and = function() { let a = this.result.length, c, b, d, e; if (!a) { const g = arguments[0]; g && (a = !!g.suggest, e = g.resolve, c = g.limit, b = g.offset, d = g.enrich && e); } if (a) { - const {m:g, u:f, limit:h, offset:k, enrich:l, resolve:n, suggest:m} = G(this, "and", arguments); - return K.call(this, g, f, h, k, l, n, m); + const {m:g, u:f, limit:h, offset:k, enrich:l, resolve:n, suggest:m} = P(this, "and", arguments); + return na.call(this, g, f, h, k, l, n, m); } return e ? this.resolve(c, b, d) : this; }; -function K(a, c, b, d, e, g, f) { +function na(a, c, b, d, e, g, f) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -404,15 +517,15 @@ function K(a, c, b, d, e, g, f) { for (let l = 0, n; l < k.length; l++) { (n = k[l]).length && (a[l] = n); } - return K.call(h, a, [], b, d, e, g, f); + return na.call(h, a, [], b, d, e, g, f); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - if (c = x(a)) { - return this.result = C(a, c, b, d, f), g ? e ? F.call(this.index, this.result) : this.result : this; + if (c = aa(a)) { + return this.result = ja(a, c, b, d, f), g ? e ? O.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -421,11 +534,11 @@ function K(a, c, b, d, e, g, f) { } return g ? this.resolve(b, d, e) : this; } -;I.prototype.xor = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = G(this, "xor", arguments); - return L.call(this, a, c, b, d, e, g, f); +;Q.prototype.xor = function() { + const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = P(this, "xor", arguments); + return oa.call(this, a, c, b, d, e, g, f); }; -function L(a, c, b, d, e, g, f) { +function oa(a, c, b, d, e, g, f) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -433,21 +546,21 @@ function L(a, c, b, d, e, g, f) { for (let l = 0, n; l < k.length; l++) { (n = k[l]).length && (a[l] = n); } - return L.call(h, a, [], b, d, e, g, f); + return oa.call(h, a, [], b, d, e, g, f); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = ea.call(this, a, b, d, g, this.g), g ? e ? F.call(this.index, this.result) : this.result : this; + return this.result = pa.call(this, a, b, d, g, this.g), g ? e ? O.call(this.index, this.result) : this.result : this; } } else { f || (this.result = a); } return g ? this.resolve(b, d, e) : this; } -function ea(a, c, b, d, e) { +function pa(a, c, b, d, e) { const g = [], f = w(); let h = 0; for (let k = 0, l; k < a.length; k++) { @@ -492,11 +605,11 @@ function ea(a, c, b, d, e) { } return g; } -;I.prototype.not = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = G(this, "not", arguments); - return M.call(this, a, c, b, d, e, g, f); +;Q.prototype.not = function() { + const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = P(this, "not", arguments); + return qa.call(this, a, c, b, d, e, g, f); }; -function M(a, c, b, d, e, g, f) { +function qa(a, c, b, d, e, g, f) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -504,17 +617,17 @@ function M(a, c, b, d, e, g, f) { for (let l = 0, n; l < k.length; l++) { (n = k[l]).length && (a[l] = n); } - return M.call(h, a, [], b, d, e, g, f); + return qa.call(h, a, [], b, d, e, g, f); }); } if (a.length && this.result.length) { - this.result = fa.call(this, a, b, d, g); + this.result = ra.call(this, a, b, d, g); } else if (g) { return this.resolve(b, d, e); } - return g ? e ? F.call(this.index, this.result) : this.result : this; + return g ? e ? O.call(this.index, this.result) : this.result : this; } -function fa(a, c, b, d) { +function ra(a, c, b, d) { const e = []; a = new Set(a.flat().flat()); for (let g = 0, f, h = 0; g < this.result.length; g++) { @@ -540,9 +653,9 @@ function fa(a, c, b, d) { } return e; } -;function I(a) { - if (!this || this.constructor !== I) { - return new I(a); +;function Q(a) { + if (!this || this.constructor !== Q) { + return new Q(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.g = a.boost || 0, this.result = a.index.search(a).result, this; @@ -551,7 +664,7 @@ function fa(a, c, b, d) { this.result = a || []; this.g = 0; } -I.prototype.limit = function(a) { +Q.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, d; b < this.result.length; b++) { @@ -570,7 +683,7 @@ I.prototype.limit = function(a) { } return this; }; -I.prototype.offset = function(a) { +Q.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, d; b < this.result.length; b++) { @@ -582,17 +695,17 @@ I.prototype.offset = function(a) { } return this; }; -I.prototype.boost = function(a) { +Q.prototype.boost = function(a) { this.g += a; return this; }; -I.prototype.resolve = function(a, c, b) { +Q.prototype.resolve = function(a, c, b) { const d = this.result, e = this.index; this.result = this.index = null; - return d.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), E.call(e, d, a || 100, c, b)) : d; + return d.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), N.call(e, d, a || 100, c, b)) : d; }; w(); -function F(a) { +function O(a) { if (!this || !this.store) { return a; } @@ -602,35 +715,35 @@ function F(a) { } return c; } -;function N(a) { +;function S(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.g = ""; } -N.prototype.set = function(a, c) { +S.prototype.set = function(a, c) { this.cache.set(this.g = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -N.prototype.get = function(a) { +S.prototype.get = function(a) { const c = this.cache.get(a); c && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c)); return c; }; -N.prototype.remove = function(a) { +S.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -N.prototype.clear = function() { +S.prototype.clear = function() { this.cache.clear(); this.g = ""; }; -const ha = {normalize:function(a) { +const sa = {normalize:function(a) { return a.toLowerCase(); }}; -const O = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -P.prototype.add = function(a, c, b, d) { +const ta = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +D.prototype.add = function(a, c, b, d) { if (c && (a || 0 === a)) { if (!d && !b && this.reg.has(a)) { return this.update(a, c); @@ -642,15 +755,15 @@ P.prototype.add = function(a, c, b, d) { let p = c[this.rtl ? d - 1 - q : q]; var e = p.length; if (e && (m || !n[p])) { - var g = this.score ? this.score(c, p, q, null, 0) : Q(r, d, q), f = ""; + var g = this.score ? this.score(c, p, q, null, 0) : T(r, d, q), f = ""; switch(this.tokenize) { case "full": if (2 < e) { for (g = 0; g < e; g++) { for (var h = e; h > g; h--) { f = p.substring(g, h); - var k = this.score ? this.score(c, p, q, f, g) : Q(r, d, q, e, g); - R(this, n, f, k, a, b); + var k = this.score ? this.score(c, p, q, f, g) : T(r, d, q, e, g); + U(this, n, f, k, a, b); } } break; @@ -658,24 +771,24 @@ P.prototype.add = function(a, c, b, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - f = p[h] + f, k = this.score ? this.score(c, p, q, f, h) : Q(r, d, q, e, h), R(this, n, f, k, a, b); + f = p[h] + f, k = this.score ? this.score(c, p, q, f, h) : T(r, d, q, e, h), U(this, n, f, k, a, b); } f = ""; } case "forward": if (1 < e) { for (h = 0; h < e; h++) { - f += p[h], R(this, n, f, g, a, b); + f += p[h], U(this, n, f, g, a, b); } break; } default: - if (R(this, n, p, g, a, b), m && 1 < d && q < d - 1) { + if (U(this, n, p, g, a, b), m && 1 < d && q < d - 1) { for (e = w(), f = this.B, g = p, h = Math.min(m + 1, d - q), e[g] = 1, k = 1; k < h; k++) { if ((p = c[this.rtl ? d - 1 - q - k : q + k]) && !e[p]) { e[p] = 1; - const v = this.score ? this.score(c, g, q, p, k) : Q(f + (d / 2 > f ? 0 : 1), d, q, h - 1, k - 1), A = this.bidirectional && p > g; - R(this, l, A ? g : p, v, a, b, A ? p : g); + const v = this.score ? this.score(c, g, q, p, k) : T(f + (d / 2 > f ? 0 : 1), d, q, h - 1, k - 1), B = this.bidirectional && p > g; + U(this, l, B ? g : p, v, a, b, B ? p : g); } } } @@ -687,16 +800,16 @@ P.prototype.add = function(a, c, b, d) { } return this; }; -function R(a, c, b, d, e, g, f) { +function U(a, c, b, d, e, g, f) { let h = f ? a.ctx : a.map, k; if (!c[b] || f && !(k = c[b])[f]) { f ? (c = k || (c[b] = w()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.reg.get(e)) ? c.push(h) : a.reg.set(e, [h]))); } } -function Q(a, c, b, d, e) { +function T(a, c, b, d, e) { return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0; } -;P.prototype.search = function(a, c, b) { +;D.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); var d = [], e = 0; if (b) { @@ -714,11 +827,11 @@ function Q(a, c, b, d, e) { a = b.length; c = c || (h ? 100 : 0); if (1 === a) { - return S.call(this, b[0], "", c, e, h); + return ua.call(this, b[0], "", c, e, h); } g = this.depth && !1 !== g; if (2 === a && g && !f) { - return S.call(this, b[0], b[1], c, e, h); + return ua.call(this, b[0], b[1], c, e, h); } h = w(); let l = 0; @@ -730,29 +843,29 @@ function Q(a, c, b, d, e) { for (let p, v; l < a; l++) { if ((v = b[l]) && !h[v]) { h[v] = 1; - p = T(this, v, n); + p = va(this, v, n); a: { g = p; var m = d, r = f, q = k; - let A = []; + let B = []; if (g && g.length) { if (g.length <= q) { m.push(g); p = void 0; break a; } - for (let H = 0, Y; H < q; H++) { - if (Y = g[H]) { - A[H] = Y; + for (let R = 0, ka; R < q; R++) { + if (ka = g[R]) { + B[R] = ka; } } - if (A.length) { - m.push(A); + if (B.length) { + m.push(B); p = void 0; break a; } } - p = r ? void 0 : A; + p = r ? void 0 : B; } if (p) { d = p; @@ -766,27 +879,27 @@ function Q(a, c, b, d, e) { n = d.length; a = d; if (1 < n) { - a = C(d, k, c, e, f); + a = ja(d, k, c, e, f); } else if (1 === n) { - f = E.call(null, d[0], c, e); + f = N.call(null, d[0], c, e); break a; } f = a; } return f; }; -function S(a, c, b, d, e) { - a = T(this, a, c); +function ua(a, c, b, d, e) { + a = va(this, a, c); e = !0; - return a && a.length ? e ? E.call(this, a, b, d) : new I(a) : e ? [] : new I(); + return a && a.length ? e ? N.call(this, a, b, d) : new Q(a) : e ? [] : new Q(); } -function T(a, c, b) { +function va(a, c, b) { let d; b && (d = a.bidirectional && c > b) && (d = b, b = c, c = d); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;P.prototype.remove = function(a, c) { +;D.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) { @@ -801,14 +914,14 @@ function T(a, c, b) { } } } else { - U(this.map, a), this.depth && U(this.ctx, a); + V(this.map, a), this.depth && V(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function U(a, c) { +function V(a, c) { let b = 0; if (a.constructor === Array) { for (let d = 0, e, g; d < a.length; d++) { @@ -823,25 +936,25 @@ function U(a, c) { } } else { for (let d of a.entries()) { - const e = d[0], g = U(d[1], c); + const e = d[0], g = V(d[1], c); g ? b += g : a.delete(e); } } return b; } -;function P(a, c) { - if (!this || this.constructor !== P) { - return new P(a); +;function D(a, c) { + if (!this || this.constructor !== D) { + return new D(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (O[b] || console.warn("Preset not found: " + b), a = Object.assign({}, O[b], a)); + b && (ta[b] || console.warn("Preset not found: " + b), a = Object.assign({}, ta[b], a)); } else { a = {}; } b = a.context; - const d = !0 === b ? {depth:1} : b || {}, e = a.encode || a.encoder || ha; - this.encoder = e.encode ? e : "object" === typeof e ? new z(e) : {encode:e}; + const d = !0 === b ? {depth:1} : b || {}, e = a.encode || a.encoder || sa; + this.encoder = e.encode ? e : "object" === typeof e ? new y(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = b = a.tokenize || "strict"; this.depth = "strict" === b && d.depth || 0; @@ -854,9 +967,9 @@ function U(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.B = d.resolution || 3; this.rtl = e.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new N(b); + this.cache = (b = a.cache || null) && new S(b); } -t = P.prototype; +t = D.prototype; t.clear = function() { this.map.clear(); this.ctx.clear(); @@ -874,7 +987,7 @@ t.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) { +function W(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, d; b < a.length; b++) { @@ -882,7 +995,7 @@ function V(a) { } } else { for (const b of a) { - const d = b[0], e = V(b[1]); + const d = b[0], e = W(b[1]); e ? c += e : a.delete(d); } } @@ -892,13 +1005,13 @@ t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - V(this.map); - this.depth && V(this.ctx); + W(this.map); + this.depth && W(this.ctx); return this; }; t.searchCache = function(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new N()); + this.cache || (this.cache = new S()); let d = this.cache.get(a); if (!d) { d = this.search(a, c, b); @@ -913,9 +1026,9 @@ t.searchCache = function(a, c, b) { } return d; }; -const W = {Index:P, Charset:null, Encoder:z, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, X = self; +const X = {Index:D, Charset:null, Encoder:y, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Y = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; let Z; -(Z = X.define) && Z.amd ? Z([], function() { - return W; -}) : "object" === typeof X.exports ? X.exports = W : X.FlexSearch = W; +(Z = Y.define) && Z.amd ? Z([], function() { + return X; +}) : "object" === typeof Y.exports ? Y.exports = X : Y.FlexSearch = X; }(this||self)); diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index 6f06d10..03dee1f 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -1,34 +1,40 @@ /**! - * FlexSearch.js v0.8.107 (Light) + * FlexSearch.js v0.8.108 (Light) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ (function(self){'use strict';var t;function u(a,c,b){const d=typeof b,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(b){if("function"===e&&d===e)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===e?c:a}function w(){return Object.create(null)} -function x(a){let c=0;for(let b=0,d;b"a1a".split(b).length; -this.numeric=u(a.numeric,d)}else{try{this.split=u(this.split,y)}catch(e){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), +this.numeric=u(a.numeric,d)}else{try{this.split=u(this.split,ba)}catch(e){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.C="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.s=this.o=128;this.g="";this.v=null;this.h="";this.A=null;if(this.matcher)for(const e of this.matcher.keys())this.g+=(this.g?"|":"")+e;if(this.stemmer)for(const e of this.stemmer.keys())this.h+=(this.h?"|":"")+e;return this}; -t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.A=null;this.cache&&C(this);return this};t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&C(this);return this};t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.v=null;this.cache&&C(this);return this};t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&C(this);return this}; -t.encode=function(a){if(this.cache&&a.length<=this.o)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(C,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=z?a.normalize("NFKD").replace(z,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),f.lengtha.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.v=null;this.cache&&z(this);return this};t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&z(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.o)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(z,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=x?a.normalize("NFKD").replace(x,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),f.lengththis.matcher.get(k)));if(f&&this.replacer)for(e=0;f&&ethis.C&& -(this.j.clear(),this.s=this.s/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.o&&(this.i.set(a,b),this.i.size>this.C&&(this.i.clear(),this.o=this.o/1.1|0));return b};function C(a){a.l=null;a.i.clear();a.j.clear()};function D(a,c,b,d,e){const g=a.length;let f=[],h,k;h=w();for(let l=0,n,m,r,q;lb||d?f.slice(d,b+d):f;else{if(ab||d)f=f.slice(d,b+d)}return f} -function E(a,c,b){const d=[],e=w();let g;var f=a.length;let h;for(let k=f-1;0<=k;k--)if(h=(f=a[k])&&f.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,d?G.call(this,a):a;let e=[];for(let g=0,f,h;g=h){b-=h;continue}bc&&(f=f.slice(0,c),h=c);if(!e.length&&h>=c)return d?G.call(this,f):f;e.push(f);c-=h;if(!c)break}e=1a.length?this.result=a[0]:(this.result=E(a,b,d),d=0));return g?this.resolve(b,d,e):this};J.prototype.and=function(){let a=this.result.length,c,b,d,e;if(!a){const g=arguments[0];g&&(a=!!g.suggest,e=g.resolve,c=g.limit,b=g.offset,d=g.enrich&&e)}if(a){const {m:g,u:f,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=I(this,"and",arguments);return L.call(this,g,f,h,k,l,n,m)}return e?this.resolve(c,b,d):this}; -function L(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=x(a))return this.result=D(a,c,b,d,f),g?e?G.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(b,d,e):this};J.prototype.xor=function(){const {m:a,u:c,limit:b,offset:d,enrich:e,resolve:g,suggest:f}=I(this,"xor",arguments);return M.call(this,a,c,b,d,e,g,f)}; -function M(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=da.call(this,a,b,d,g,this.g),g?e?G.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(b,d,e):this} -function da(a,c,b,d,e){const g=[],f=w();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)};O.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};O.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -O.prototype.clear=function(){this.cache.clear();this.g=""};const fa={normalize:function(a){return a.toLowerCase()}};const ha={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};P.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 l=w(),n=w(),m=this.depth,r=this.resolution;for(let q=0;qg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,q,f,g):Q(r,d,q,e,g);R(this,n,f,k,a,b)}break}case "reverse":if(1< -e){for(h=e-1;0f?0:1),d,q,h-1,k-1),A=this.bidirectional&&p>g;R(this,l,A?g:p,v,a,b,A?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function R(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h])))}function Q(a,c,b,d,e){return b&&1b)&&(d=b,b=c,c=d);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};P.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 U(this.map,a),this.depth&&U(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function U(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; -function V(a){let c=0;if(a.constructor===Array)for(let b=0,d;bthis.C&&(this.i.clear(),this.o=this.o/1.1|0));return b};function z(a){a.l=null;a.i.clear();a.j.clear()};let A,C;async function fa(a){a=a.data;const c=a.task,b=a.id;let d=a.args;switch(c){case "init":C=a.options||{};(a=a.factory)?(Function("return "+a)()(self),A=new self.FlexSearch.Index(C),delete self.FlexSearch):A=new D(C);postMessage({id:b});break;default:let e;"export"===c&&(d=[C.export]);"import"===c?await C.import.call(A,A):e=A[c].apply(A,d);postMessage("search"===c?{id:b,msg:e}:{id:b})}};let E,F;const G={},H={};function ha(a){E=0;G[a]=H[a]} +function I(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let d;"function"===typeof b&&(d=b,delete c[c.length-1]);E||(E=setTimeout(ha,0,a),F=Date.now());H[a]||(H[a]=G[a]=1E3);if(!--G[a]){G[a]=H[a]=H[a]*this.priority*this.priority*3/(Date.now()-F)|0||1;E=clearTimeout(E);const g=this;return new Promise(f=>{setTimeout(function(){f(g[a+"Async"].apply(g,c))},0)})}const e=this[a].apply(this,c);b=e.then?e:new Promise(g=>g(e));d&&b.then(d);return b}};let J=0; +function K(a={}){function c(f){function h(k){k=k.data||k;const l=k.id,n=l&&e.g[l];n&&(n(k.msg),delete e.g[l])}this.worker=f;this.g=w();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.g[++J]=function(){k(e)};e.worker.postMessage({id:J,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==K)return new K(a);let b="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;b&&(b=b.toString());const d="undefined"===typeof window,e=this,g=ia(b,d,a.worker);return g.then?g.then(function(f){return c.call(e,f)}):c.call(this,g)}L("add");L("append");L("search");L("update");L("remove");L("clear");L("export");L("import");var M=K.prototype;I.call(M,"add");I.call(M,"append");I.call(M,"search");I.call(M,"update");I.call(M,"remove"); +function L(a){K.prototype[a]=async function(){const c=this,b=[].slice.call(arguments);var d=b[b.length-1];let e;"function"===typeof d&&(e=d,b.splice(b.length-1,1));d=new Promise(function(g){c.g[++J]=g;c.worker.postMessage({task:a,id:J,args:b})});return e?(d.then(e),this):d}} +function ia(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+fa.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof b?b:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function ka(a,c,b,d,e){const g=a.length;let f=[],h,k;h=w();for(let l=0,n,m,r,q;lb||d?f.slice(d,b+d):f;else{if(ab||d)f=f.slice(d,b+d)}return f} +function la(a,c,b){const d=[],e=w();let g;var f=a.length;let h;for(let k=f-1;0<=k;k--)if(h=(f=a[k])&&f.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,d?O.call(this,a):a;let e=[];for(let g=0,f,h;g=h){b-=h;continue}bc&&(f=f.slice(0,c),h=c);if(!e.length&&h>=c)return d?O.call(this,f):f;e.push(f);c-=h;if(!c)break}e=1a.length?this.result=a[0]:(this.result=la(a,b,d),d=0));return g?this.resolve(b,d,e):this};Q.prototype.and=function(){let a=this.result.length,c,b,d,e;if(!a){const g=arguments[0];g&&(a=!!g.suggest,e=g.resolve,c=g.limit,b=g.offset,d=g.enrich&&e)}if(a){const {m:g,u:f,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=P(this,"and",arguments);return na.call(this,g,f,h,k,l,n,m)}return e?this.resolve(c,b,d):this}; +function na(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=aa(a))return this.result=ka(a,c,b,d,f),g?e?O.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(b,d,e):this};Q.prototype.xor=function(){const {m:a,u:c,limit:b,offset:d,enrich:e,resolve:g,suggest:f}=P(this,"xor",arguments);return oa.call(this,a,c,b,d,e,g,f)}; +function oa(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=pa.call(this,a,b,d,g,this.g),g?e?O.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(b,d,e):this} +function pa(a,c,b,d,e){const g=[],f=w();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)};S.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};S.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; +S.prototype.clear=function(){this.cache.clear();this.g=""};const sa={normalize:function(a){return a.toLowerCase()}};const ta={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};D.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 l=w(),n=w(),m=this.depth,r=this.resolution;for(let q=0;qg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,q,f,g):T(r,d,q,e,g);U(this,n,f,k,a,b)}break}case "reverse":if(1< +e){for(h=e-1;0f?0:1),d,q,h-1,k-1),B=this.bidirectional&&p>g;U(this,l,B?g:p,v,a,b,B?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function U(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h])))}function T(a,c,b,d,e){return b&&1b)&&(d=b,b=c,c=d);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};D.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 V(this.map,a),this.depth&&V(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function V(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; +function W(a){let c=0;if(a.constructor===Array)for(let b=0,d;b this.stemmer.get(k)), f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); @@ -231,12 +231,125 @@ t.encode = function(a) { this.cache && a.length <= this.o && (this.i.set(a, b), this.i.size > this.C && (this.i.clear(), this.o = this.o / 1.1 | 0)); return b; }; -function E(a) { +function z(a) { a.l = null; a.i.clear(); a.j.clear(); } -;function F(a, c, b, d, e) { +;let A, C; +async function fa(a) { + a = a.data; + const c = a.task, b = a.id; + let d = a.args; + switch(c) { + case "init": + C = a.options || {}; + (a = a.factory) ? (Function("return " + a)()(self), A = new self.FlexSearch.Index(C), delete self.FlexSearch) : A = new D(C); + postMessage({id:b}); + break; + default: + let e; + "export" === c && (d = [C.export]); + "import" === c ? await C.import.call(A, A) : e = A[c].apply(A, d); + postMessage("search" === c ? {id:b, msg:e} : {id:b}); + } +} +;let E, F; +const G = {}, H = {}; +function ia(a) { + E = 0; + G[a] = H[a]; +} +function I(a) { + this[a + "Async"] = function() { + const c = arguments; + var b = c[c.length - 1]; + let d; + "function" === typeof b && (d = b, delete c[c.length - 1]); + E || (E = setTimeout(ia, 0, a), F = Date.now()); + H[a] || (H[a] = G[a] = 1000); + if (!--G[a]) { + G[a] = H[a] = H[a] * this.priority * this.priority * 3 / (Date.now() - F) | 0 || 1; + E = clearTimeout(E); + const g = this; + return new Promise(f => { + setTimeout(function() { + f(g[a + "Async"].apply(g, c)); + }, 0); + }); + } + const e = this[a].apply(this, c); + b = e.then ? e : new Promise(g => g(e)); + d && b.then(d); + return b; + }; +} +;let J = 0; +function K(a = {}) { + function c(f) { + function h(k) { + k = k.data || k; + const l = k.id, n = l && e.g[l]; + n && (n(k.msg), delete e.g[l]); + } + this.worker = f; + this.g = w(); + if (this.worker) { + d ? this.worker.on("message", h) : this.worker.onmessage = h; + if (a.config) { + return new Promise(function(k) { + e.g[++J] = function() { + k(e); + }; + e.worker.postMessage({id:J, task:"init", factory:b, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:b, options:a}); + return this; + } + } + if (!this || this.constructor !== K) { + return new K(a); + } + let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + b && (b = b.toString()); + const d = "undefined" === typeof window, e = this, g = ja(b, d, a.worker); + return g.then ? g.then(function(f) { + return c.call(e, f); + }) : c.call(this, g); +} +L("add"); +L("append"); +L("search"); +L("update"); +L("remove"); +L("clear"); +L("export"); +L("import"); +var M = K.prototype; +I.call(M, "add"); +I.call(M, "append"); +I.call(M, "search"); +I.call(M, "update"); +I.call(M, "remove"); +function L(a) { + K.prototype[a] = async function() { + const c = this, b = [].slice.call(arguments); + var d = b[b.length - 1]; + let e; + "function" === typeof d && (e = d, b.splice(b.length - 1, 1)); + d = new Promise(function(g) { + c.g[++J] = g; + c.worker.postMessage({task:a, id:J, args:b}); + }); + return e ? (d.then(e), this) : d; + }; +} +function ja(a, c, b) { + return c ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + fa.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function N(a, c, b, d, e) { const g = a.length; let f = [], h, k; h = w(); @@ -251,7 +364,7 @@ function E(a) { } if (a = f.length) { if (e) { - f = 1 < f.length ? G(f, b, d) : (f = f[0]).length > b || d ? f.slice(d, b + d) : f; + f = 1 < f.length ? O(f, b, d) : (f = f[0]).length > b || d ? f.slice(d, b + d) : f; } else { if (a < g) { return []; @@ -266,7 +379,7 @@ function E(a) { } return f; } -function G(a, c, b) { +function O(a, c, b) { const d = [], e = w(); let g; var f = a.length; @@ -288,12 +401,12 @@ function G(a, c, b) { } return d; } -;function I(a, c, b, d) { +;function P(a, c, b, d) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, d ? J.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, d ? Q.call(this, a) : a; } let e = []; for (let g = 0, f, h; g < a.length; g++) { @@ -307,7 +420,7 @@ function G(a, c, b) { } h > c && (f = f.slice(0, c), h = c); if (!e.length && h >= c) { - return d ? J.call(this, f) : f; + return d ? Q.call(this, f) : f; } e.push(f); c -= h; @@ -317,9 +430,9 @@ function G(a, c, b) { } } e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? J.call(this, e) : e; + return d ? Q.call(this, e) : e; } -;function K(a, c, b) { +;function S(a, c, b) { var d = b[0]; if (d.then) { return Promise.all(b).then(function(n) { @@ -334,7 +447,7 @@ function G(a, c, b) { for (let n = 0, m; n < b.length; n++) { if (m = b[n]) { let r; - if (m.constructor === L) { + if (m.constructor === T) { r = m.result; } else if (m.constructor === Array) { r = m; @@ -365,11 +478,11 @@ function G(a, c, b) { } return {m:d, u:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; } -;L.prototype.or = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g} = K(this, "or", arguments); - return M.call(this, a, c, b, d, e, g); +;T.prototype.or = function() { + const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g} = S(this, "or", arguments); + return U.call(this, a, c, b, d, e, g); }; -function M(a, c, b, d, e, g) { +function U(a, c, b, d, e, g) { if (c.length) { const f = this; return Promise.all(c).then(function(h) { @@ -377,25 +490,25 @@ function M(a, c, b, d, e, g) { for (let k = 0, l; k < h.length; k++) { (l = h[k]).length && (a[k] = l); } - return M.call(f, a, [], b, d, e, g); + return U.call(f, a, [], b, d, e, g); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = G(a, b, d), d = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = O(a, b, d), d = 0)); return g ? this.resolve(b, d, e) : this; } -;L.prototype.and = function() { +;T.prototype.and = function() { let a = this.result.length, c, b, d, e; if (!a) { const g = arguments[0]; g && (a = !!g.suggest, e = g.resolve, c = g.limit, b = g.offset, d = g.enrich && e); } if (a) { - const {m:g, u:f, limit:h, offset:k, enrich:l, resolve:n, suggest:m} = K(this, "and", arguments); - return N.call(this, g, f, h, k, l, n, m); + const {m:g, u:f, limit:h, offset:k, enrich:l, resolve:n, suggest:m} = S(this, "and", arguments); + return ka.call(this, g, f, h, k, l, n, m); } return e ? this.resolve(c, b, d) : this; }; -function N(a, c, b, d, e, g, f) { +function ka(a, c, b, d, e, g, f) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -403,15 +516,15 @@ function N(a, c, b, d, e, g, f) { for (let l = 0, n; l < k.length; l++) { (n = k[l]).length && (a[l] = n); } - return N.call(h, a, [], b, d, e, g, f); + return ka.call(h, a, [], b, d, e, g, f); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - if (c = x(a)) { - return this.result = F(a, c, b, d, f), g ? e ? J.call(this.index, this.result) : this.result : this; + if (c = aa(a)) { + return this.result = N(a, c, b, d, f), g ? e ? Q.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -420,11 +533,11 @@ function N(a, c, b, d, e, g, f) { } return g ? this.resolve(b, d, e) : this; } -;L.prototype.xor = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = K(this, "xor", arguments); - return O.call(this, a, c, b, d, e, g, f); +;T.prototype.xor = function() { + const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = S(this, "xor", arguments); + return la.call(this, a, c, b, d, e, g, f); }; -function O(a, c, b, d, e, g, f) { +function la(a, c, b, d, e, g, f) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -432,21 +545,21 @@ function O(a, c, b, d, e, g, f) { for (let l = 0, n; l < k.length; l++) { (n = k[l]).length && (a[l] = n); } - return O.call(h, a, [], b, d, e, g, f); + return la.call(h, a, [], b, d, e, g, f); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = ba.call(this, a, b, d, g, this.g), g ? e ? J.call(this.index, this.result) : this.result : this; + return this.result = ma.call(this, a, b, d, g, this.g), g ? e ? Q.call(this.index, this.result) : this.result : this; } } else { f || (this.result = a); } return g ? this.resolve(b, d, e) : this; } -function ba(a, c, b, d, e) { +function ma(a, c, b, d, e) { const g = [], f = w(); let h = 0; for (let k = 0, l; k < a.length; k++) { @@ -491,11 +604,11 @@ function ba(a, c, b, d, e) { } return g; } -;L.prototype.not = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = K(this, "not", arguments); - return P.call(this, a, c, b, d, e, g, f); +;T.prototype.not = function() { + const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = S(this, "not", arguments); + return na.call(this, a, c, b, d, e, g, f); }; -function P(a, c, b, d, e, g, f) { +function na(a, c, b, d, e, g, f) { if (c.length) { const h = this; return Promise.all(c).then(function(k) { @@ -503,17 +616,17 @@ function P(a, c, b, d, e, g, f) { for (let l = 0, n; l < k.length; l++) { (n = k[l]).length && (a[l] = n); } - return P.call(h, a, [], b, d, e, g, f); + return na.call(h, a, [], b, d, e, g, f); }); } if (a.length && this.result.length) { - this.result = ca.call(this, a, b, d, g); + this.result = oa.call(this, a, b, d, g); } else if (g) { return this.resolve(b, d, e); } - return g ? e ? J.call(this.index, this.result) : this.result : this; + return g ? e ? Q.call(this.index, this.result) : this.result : this; } -function ca(a, c, b, d) { +function oa(a, c, b, d) { const e = []; a = new Set(a.flat().flat()); for (let g = 0, f, h = 0; g < this.result.length; g++) { @@ -539,9 +652,9 @@ function ca(a, c, b, d) { } return e; } -;function L(a) { - if (!this || this.constructor !== L) { - return new L(a); +;function T(a) { + if (!this || this.constructor !== T) { + return new T(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.g = a.boost || 0, this.result = a.index.search(a).result, this; @@ -550,7 +663,7 @@ function ca(a, c, b, d) { this.result = a || []; this.g = 0; } -L.prototype.limit = function(a) { +T.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, d; b < this.result.length; b++) { @@ -569,7 +682,7 @@ L.prototype.limit = function(a) { } return this; }; -L.prototype.offset = function(a) { +T.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, d; b < this.result.length; b++) { @@ -581,17 +694,17 @@ L.prototype.offset = function(a) { } return this; }; -L.prototype.boost = function(a) { +T.prototype.boost = function(a) { this.g += a; return this; }; -L.prototype.resolve = function(a, c, b) { +T.prototype.resolve = function(a, c, b) { const d = this.result, e = this.index; this.result = this.index = null; - return d.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), I.call(e, d, a || 100, c, b)) : d; + return d.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), P.call(e, d, a || 100, c, b)) : d; }; w(); -function J(a) { +function Q(a) { if (!this || !this.store) { return a; } @@ -601,35 +714,35 @@ function J(a) { } return c; } -;function Q(a) { +;function V(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.g = ""; } -Q.prototype.set = function(a, c) { +V.prototype.set = function(a, c) { this.cache.set(this.g = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -Q.prototype.get = function(a) { +V.prototype.get = function(a) { const c = this.cache.get(a); c && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c)); return c; }; -Q.prototype.remove = function(a) { +V.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -Q.prototype.clear = function() { +V.prototype.clear = function() { this.cache.clear(); this.g = ""; }; -const da = {normalize:function(a) { +const pa = {normalize:function(a) { return a.toLowerCase(); }}; -const R = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -S.prototype.add = function(a, c, b, d) { +const qa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +D.prototype.add = function(a, c, b, d) { if (c && (a || 0 === a)) { if (!d && !b && this.reg.has(a)) { return this.update(a, c); @@ -641,15 +754,15 @@ S.prototype.add = function(a, c, b, d) { let p = c[this.rtl ? d - 1 - q : q]; var e = p.length; if (e && (m || !n[p])) { - var g = this.score ? this.score(c, p, q, null, 0) : T(r, d, q), f = ""; + var g = this.score ? this.score(c, p, q, null, 0) : W(r, d, q), f = ""; switch(this.tokenize) { case "full": if (2 < e) { for (g = 0; g < e; g++) { for (var h = e; h > g; h--) { f = p.substring(g, h); - var k = this.score ? this.score(c, p, q, f, g) : T(r, d, q, e, g); - U(this, n, f, k, a, b); + var k = this.score ? this.score(c, p, q, f, g) : W(r, d, q, e, g); + X(this, n, f, k, a, b); } } break; @@ -657,24 +770,24 @@ S.prototype.add = function(a, c, b, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - f = p[h] + f, k = this.score ? this.score(c, p, q, f, h) : T(r, d, q, e, h), U(this, n, f, k, a, b); + f = p[h] + f, k = this.score ? this.score(c, p, q, f, h) : W(r, d, q, e, h), X(this, n, f, k, a, b); } f = ""; } case "forward": if (1 < e) { for (h = 0; h < e; h++) { - f += p[h], U(this, n, f, g, a, b); + f += p[h], X(this, n, f, g, a, b); } break; } default: - if (U(this, n, p, g, a, b), m && 1 < d && q < d - 1) { + if (X(this, n, p, g, a, b), m && 1 < d && q < d - 1) { for (e = w(), f = this.B, g = p, h = Math.min(m + 1, d - q), e[g] = 1, k = 1; k < h; k++) { if ((p = c[this.rtl ? d - 1 - q - k : q + k]) && !e[p]) { e[p] = 1; - const v = this.score ? this.score(c, g, q, p, k) : T(f + (d / 2 > f ? 0 : 1), d, q, h - 1, k - 1), A = this.bidirectional && p > g; - U(this, l, A ? g : p, v, a, b, A ? p : g); + const v = this.score ? this.score(c, g, q, p, k) : W(f + (d / 2 > f ? 0 : 1), d, q, h - 1, k - 1), B = this.bidirectional && p > g; + X(this, l, B ? g : p, v, a, b, B ? p : g); } } } @@ -686,16 +799,16 @@ S.prototype.add = function(a, c, b, d) { } return this; }; -function U(a, c, b, d, e, g, f) { +function X(a, c, b, d, e, g, f) { let h = f ? a.ctx : a.map, k; if (!c[b] || f && !(k = c[b])[f]) { f ? (c = k || (c[b] = w()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.reg.get(e)) ? c.push(h) : a.reg.set(e, [h]))); } } -function T(a, c, b, d, e) { +function W(a, c, b, d, e) { return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0; } -;S.prototype.search = function(a, c, b) { +;D.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); var d = [], e = 0; if (b) { @@ -713,11 +826,11 @@ function T(a, c, b, d, e) { a = b.length; c = c || (h ? 100 : 0); if (1 === a) { - return W.call(this, b[0], "", c, e, h); + return ra.call(this, b[0], "", c, e, h); } g = this.depth && !1 !== g; if (2 === a && g && !f) { - return W.call(this, b[0], b[1], c, e, h); + return ra.call(this, b[0], b[1], c, e, h); } h = w(); let l = 0; @@ -729,29 +842,29 @@ function T(a, c, b, d, e) { for (let p, v; l < a; l++) { if ((v = b[l]) && !h[v]) { h[v] = 1; - p = X(this, v, n); + p = sa(this, v, n); a: { g = p; var m = d, r = f, q = k; - let A = []; + let B = []; if (g && g.length) { if (g.length <= q) { m.push(g); p = void 0; break a; } - for (let H = 0, V; H < q; H++) { - if (V = g[H]) { - A[H] = V; + for (let R = 0, ha; R < q; R++) { + if (ha = g[R]) { + B[R] = ha; } } - if (A.length) { - m.push(A); + if (B.length) { + m.push(B); p = void 0; break a; } } - p = r ? void 0 : A; + p = r ? void 0 : B; } if (p) { d = p; @@ -765,27 +878,27 @@ function T(a, c, b, d, e) { n = d.length; a = d; if (1 < n) { - a = F(d, k, c, e, f); + a = N(d, k, c, e, f); } else if (1 === n) { - f = I.call(null, d[0], c, e); + f = P.call(null, d[0], c, e); break a; } f = a; } return f; }; -function W(a, c, b, d, e) { - a = X(this, a, c); +function ra(a, c, b, d, e) { + a = sa(this, a, c); e = !0; - return a && a.length ? e ? I.call(this, a, b, d) : new L(a) : e ? [] : new L(); + return a && a.length ? e ? P.call(this, a, b, d) : new T(a) : e ? [] : new T(); } -function X(a, c, b) { +function sa(a, c, b) { let d; b && (d = a.bidirectional && c > b) && (d = b, b = c, c = d); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;S.prototype.remove = function(a, c) { +;D.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) { @@ -828,19 +941,19 @@ function Y(a, c) { } return b; } -;function S(a, c) { - if (!this || this.constructor !== S) { - return new S(a); +;function D(a, c) { + if (!this || this.constructor !== D) { + return new D(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (R[b] || console.warn("Preset not found: " + b), a = Object.assign({}, R[b], a)); + b && (qa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, qa[b], a)); } else { a = {}; } b = a.context; - const d = !0 === b ? {depth:1} : b || {}, e = a.encode || a.encoder || da; - this.encoder = e.encode ? e : "object" === typeof e ? new D(e) : {encode:e}; + const d = !0 === b ? {depth:1} : b || {}, e = a.encode || a.encoder || pa; + this.encoder = e.encode ? e : "object" === typeof e ? new y(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = b = a.tokenize || "strict"; this.depth = "strict" === b && d.depth || 0; @@ -853,9 +966,9 @@ function Y(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.B = d.resolution || 3; this.rtl = e.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new Q(b); + this.cache = (b = a.cache || null) && new V(b); } -t = S.prototype; +t = D.prototype; t.clear = function() { this.map.clear(); this.ctx.clear(); @@ -897,7 +1010,7 @@ t.cleanup = function() { }; t.searchCache = function(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Q()); + this.cache || (this.cache = new V()); let d = this.cache.get(a); if (!d) { d = this.search(a, c, b); @@ -912,6 +1025,6 @@ t.searchCache = function(a, c, b) { } return d; }; -export default {Index:S, Charset:null, Encoder:D, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:D, Charset:null, Encoder:y, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=S;export const Charset=null;export const Encoder=D;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=D;export const Charset=null;export const Encoder=y;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index 39dbe84..acae027 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,35 +1,41 @@ /**! - * FlexSearch.js v0.8.107 (Bundle) + * FlexSearch.js v0.8.108 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ var t;function u(a,c,b){const d=typeof b,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(b){if("function"===e&&d===e)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===e?c:a}function w(){return Object.create(null)} -function x(a){let c=0;for(let b=0,d;b"a1a".split(b).length; -this.numeric=u(a.numeric,d)}else{try{this.split=u(this.split,y)}catch(e){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), +this.numeric=u(a.numeric,d)}else{try{this.split=u(this.split,ba)}catch(e){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.C="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.s=this.o=128;this.g="";this.v=null;this.h="";this.A=null;if(this.matcher)for(const e of this.matcher.keys())this.g+=(this.g?"|":"")+e;if(this.stemmer)for(const e of this.stemmer.keys())this.h+=(this.h?"|":"")+e;return this}; -t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.A=null;this.cache&&F(this);return this};t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&F(this);return this};t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.v=null;this.cache&&F(this);return this};t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&F(this);return this}; -t.encode=function(a){if(this.cache&&a.length<=this.o)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(F,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=D?a.normalize("NFKD").replace(D,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),f.lengtha.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.v=null;this.cache&&z(this);return this};t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&z(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.o)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(z,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=x?a.normalize("NFKD").replace(x,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),f.lengththis.matcher.get(k)));if(f&&this.replacer)for(e=0;f&&ethis.C&& -(this.j.clear(),this.s=this.s/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.o&&(this.i.set(a,b),this.i.size>this.C&&(this.i.clear(),this.o=this.o/1.1|0));return b};function F(a){a.l=null;a.i.clear();a.j.clear()};function G(a,c,b,d,e){const g=a.length;let f=[],h,k;h=w();for(let l=0,n,m,r,q;lb||d?f.slice(d,b+d):f;else{if(ab||d)f=f.slice(d,b+d)}return f} -function I(a,c,b){const d=[],e=w();let g;var f=a.length;let h;for(let k=f-1;0<=k;k--)if(h=(f=a[k])&&f.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,d?K.call(this,a):a;let e=[];for(let g=0,f,h;g=h){b-=h;continue}bc&&(f=f.slice(0,c),h=c);if(!e.length&&h>=c)return d?K.call(this,f):f;e.push(f);c-=h;if(!c)break}e=1a.length?this.result=a[0]:(this.result=I(a,b,d),d=0));return g?this.resolve(b,d,e):this};M.prototype.and=function(){let a=this.result.length,c,b,d,e;if(!a){const g=arguments[0];g&&(a=!!g.suggest,e=g.resolve,c=g.limit,b=g.offset,d=g.enrich&&e)}if(a){const {m:g,u:f,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=L(this,"and",arguments);return O.call(this,g,f,h,k,l,n,m)}return e?this.resolve(c,b,d):this}; -function O(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=x(a))return this.result=G(a,c,b,d,f),g?e?K.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(b,d,e):this};M.prototype.xor=function(){const {m:a,u:c,limit:b,offset:d,enrich:e,resolve:g,suggest:f}=L(this,"xor",arguments);return P.call(this,a,c,b,d,e,g,f)}; -function P(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=aa.call(this,a,b,d,g,this.g),g?e?K.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(b,d,e):this} -function aa(a,c,b,d,e){const g=[],f=w();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)};R.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};R.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -R.prototype.clear=function(){this.cache.clear();this.g=""};const ca={normalize:function(a){return a.toLowerCase()}};const da={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};S.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 l=w(),n=w(),m=this.depth,r=this.resolution;for(let q=0;qg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,q,f,g):T(r,d,q,e,g);V(this,n,f,k,a,b)}break}case "reverse":if(1< -e){for(h=e-1;0f?0:1),d,q,h-1,k-1),A=this.bidirectional&&p>g;V(this,l,A?g:p,v,a,b,A?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function V(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h])))}function T(a,c,b,d,e){return b&&1b)&&(d=b,b=c,c=d);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};S.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 Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Y(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; +(this.j.clear(),this.s=this.s/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.o&&(this.i.set(a,b),this.i.size>this.C&&(this.i.clear(),this.o=this.o/1.1|0));return b};function z(a){a.l=null;a.i.clear();a.j.clear()};let A,C;async function ha(a){a=a.data;const c=a.task,b=a.id;let d=a.args;switch(c){case "init":C=a.options||{};(a=a.factory)?(Function("return "+a)()(self),A=new self.FlexSearch.Index(C),delete self.FlexSearch):A=new D(C);postMessage({id:b});break;default:let e;"export"===c&&(d=[C.export]);"import"===c?await C.import.call(A,A):e=A[c].apply(A,d);postMessage("search"===c?{id:b,msg:e}:{id:b})}};let E,F;const G={},H={};function ia(a){E=0;G[a]=H[a]} +function I(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let d;"function"===typeof b&&(d=b,delete c[c.length-1]);E||(E=setTimeout(ia,0,a),F=Date.now());H[a]||(H[a]=G[a]=1E3);if(!--G[a]){G[a]=H[a]=H[a]*this.priority*this.priority*3/(Date.now()-F)|0||1;E=clearTimeout(E);const g=this;return new Promise(f=>{setTimeout(function(){f(g[a+"Async"].apply(g,c))},0)})}const e=this[a].apply(this,c);b=e.then?e:new Promise(g=>g(e));d&&b.then(d);return b}};let J=0; +function K(a={}){function c(f){function h(k){k=k.data||k;const l=k.id,n=l&&e.g[l];n&&(n(k.msg),delete e.g[l])}this.worker=f;this.g=w();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.g[++J]=function(){k(e)};e.worker.postMessage({id:J,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==K)return new K(a);let b="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;b&&(b=b.toString());const d="undefined"===typeof window,e=this,g=ja(b,d,a.worker);return g.then?g.then(function(f){return c.call(e,f)}):c.call(this,g)}L("add");L("append");L("search");L("update");L("remove");L("clear");L("export");L("import");var M=K.prototype;I.call(M,"add");I.call(M,"append");I.call(M,"search");I.call(M,"update");I.call(M,"remove"); +function L(a){K.prototype[a]=async function(){const c=this,b=[].slice.call(arguments);var d=b[b.length-1];let e;"function"===typeof d&&(e=d,b.splice(b.length-1,1));d=new Promise(function(g){c.g[++J]=g;c.worker.postMessage({task:a,id:J,args:b})});return e?(d.then(e),this):d}} +function ja(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ha.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof b?b:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function N(a,c,b,d,e){const g=a.length;let f=[],h,k;h=w();for(let l=0,n,m,r,q;lb||d?f.slice(d,b+d):f;else{if(ab||d)f=f.slice(d,b+d)}return f} +function O(a,c,b){const d=[],e=w();let g;var f=a.length;let h;for(let k=f-1;0<=k;k--)if(h=(f=a[k])&&f.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,d?Q.call(this,a):a;let e=[];for(let g=0,f,h;g=h){b-=h;continue}bc&&(f=f.slice(0,c),h=c);if(!e.length&&h>=c)return d?Q.call(this,f):f;e.push(f);c-=h;if(!c)break}e=1a.length?this.result=a[0]:(this.result=O(a,b,d),d=0));return g?this.resolve(b,d,e):this};T.prototype.and=function(){let a=this.result.length,c,b,d,e;if(!a){const g=arguments[0];g&&(a=!!g.suggest,e=g.resolve,c=g.limit,b=g.offset,d=g.enrich&&e)}if(a){const {m:g,u:f,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=S(this,"and",arguments);return ka.call(this,g,f,h,k,l,n,m)}return e?this.resolve(c,b,d):this}; +function ka(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=aa(a))return this.result=N(a,c,b,d,f),g?e?Q.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(b,d,e):this};T.prototype.xor=function(){const {m:a,u:c,limit:b,offset:d,enrich:e,resolve:g,suggest:f}=S(this,"xor",arguments);return la.call(this,a,c,b,d,e,g,f)}; +function la(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=ma.call(this,a,b,d,g,this.g),g?e?Q.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(b,d,e):this} +function ma(a,c,b,d,e){const g=[],f=w();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)};V.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};V.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; +V.prototype.clear=function(){this.cache.clear();this.g=""};const pa={normalize:function(a){return a.toLowerCase()}};const qa={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};D.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 l=w(),n=w(),m=this.depth,r=this.resolution;for(let q=0;qg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,q,f,g):W(r,d,q,e,g);X(this,n,f,k,a,b)}break}case "reverse":if(1< +e){for(h=e-1;0f?0:1),d,q,h-1,k-1),B=this.bidirectional&&p>g;X(this,l,B?g:p,v,a,b,B?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function X(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h])))}function W(a,c,b,d,e){return b&&1b)&&(d=b,b=c,c=d);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};D.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 Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Y(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; function Z(a){let c=0;if(a.constructor===Array)for(let b=0,d;b {}); +}()); + +module.exports = { + tokenize: "forward", + encoder: new Encoder({ + normalize: function(str){ + return str.toLowerCase(); + } + }), + export: async function(key, data){ + + await fs.writeFile("./export/" + key, data, "utf8"); + }, + import: async function(index){ + + let files = await fs.readdir("./export/"); + files = await Promise.all(files); + + for(let i = 0; i < files.length; i++){ + const data = await fs.readFile("./export/" + files[i], "utf8"); + index.import(files[i], data); + } + } +}; \ No newline at end of file diff --git a/example/nodejs-commonjs/basic-worker-export-import/index.js b/example/nodejs-commonjs/basic-worker-export-import/index.js new file mode 100644 index 0000000..5997146 --- /dev/null +++ b/example/nodejs-commonjs/basic-worker-export-import/index.js @@ -0,0 +1,68 @@ +const { Worker: WorkerIndex } = require("flexsearch"); + +(async function(){ + + // create a simple index which can store id-content-pairs + // and await (!) for the worker response + let index = await new WorkerIndex({ + tokenize: "forward", + config: __dirname + "/config.js" + }); + + // some test data + const data = [ + 'cats abcd efgh ijkl mnop qrst uvwx cute', + 'cats abcd efgh ijkl mnop qrst cute', + 'cats abcd efgh ijkl mnop cute', + 'cats abcd efgh ijkl cute', + 'cats abcd efgh cute', + 'cats abcd cute', + 'cats cute' + ]; + + // add test data + data.forEach((item, id) => { + index.add(id, item); + }); + + // perform query + let result = await index.search({ + query: "cute cat", + }); + + // display results + result.forEach(i => { + console.log(data[i]); + }); + + // ----------------------- + // EXPORT + // ----------------------- + + await index.export(function(){ + // do nothing here + }); + + index = await new WorkerIndex({ + tokenize: "forward", + config: __dirname + "/config.js" + }); + + // ----------------------- + // IMPORT + // ----------------------- + + await index.import(); + + // perform query + result = await index.search({ + query: "cute cat", + }); + + // display results + console.log("-------------------------------------"); + result.forEach(i => { + console.log(data[i]); + }); + +}()); diff --git a/example/nodejs-commonjs/basic-worker-export-import/package.json b/example/nodejs-commonjs/basic-worker-export-import/package.json new file mode 100644 index 0000000..340dea6 --- /dev/null +++ b/example/nodejs-commonjs/basic-worker-export-import/package.json @@ -0,0 +1,6 @@ +{ + "name": "nodejs-commonjs-basic-worker-extern-config", + "dependencies": { + "flexsearch": "^0.8.105" + } +} diff --git a/example/nodejs-commonjs/basic-worker-extern-config/config.js b/example/nodejs-commonjs/basic-worker-extern-config/config.js index 3bf5a68..e8f81f9 100644 --- a/example/nodejs-commonjs/basic-worker-extern-config/config.js +++ b/example/nodejs-commonjs/basic-worker-extern-config/config.js @@ -1,6 +1,6 @@ -import { Encoder } from "flexsearch/esm"; +const { Encoder } = require("flexsearch"); -export default { +module.exports = { tokenize: "forward", encoder: new Encoder({ normalize: function(str){ diff --git a/example/nodejs-esm/basic-worker-export-import/config.js b/example/nodejs-esm/basic-worker-export-import/config.js new file mode 100644 index 0000000..907c96d --- /dev/null +++ b/example/nodejs-esm/basic-worker-export-import/config.js @@ -0,0 +1,29 @@ +import { Encoder } from "flexsearch/esm"; +import { promises as fs } from "fs"; + +(async function(){ + await fs.mkdir("./export/").catch(e => {}); +}()); + +export default { + tokenize: "forward", + encoder: new Encoder({ + normalize: function(str){ + return str.toLowerCase(); + } + }), + export: async function(key, data){ + + await fs.writeFile("./export/" + key, data, "utf8"); + }, + import: async function(index){ + + let files = await fs.readdir("./export/"); + files = await Promise.all(files); + + for(let i = 0; i < files.length; i++){ + const data = await fs.readFile("./export/" + files[i], "utf8"); + index.import(files[i], data); + } + } +}; \ No newline at end of file diff --git a/example/nodejs-esm/basic-worker-export-import/index.js b/example/nodejs-esm/basic-worker-export-import/index.js new file mode 100644 index 0000000..271f13c --- /dev/null +++ b/example/nodejs-esm/basic-worker-export-import/index.js @@ -0,0 +1,69 @@ +import { Worker as WorkerIndex } from "flexsearch/esm"; +const dirname = import.meta.dirname; + +(async function(){ + + // create a simple index which can store id-content-pairs + // and await (!) for the worker response + let index = await new WorkerIndex({ + tokenize: "forward", + config: dirname + "/config.js" + }); + + // some test data + const data = [ + 'cats abcd efgh ijkl mnop qrst uvwx cute', + 'cats abcd efgh ijkl mnop qrst cute', + 'cats abcd efgh ijkl mnop cute', + 'cats abcd efgh ijkl cute', + 'cats abcd efgh cute', + 'cats abcd cute', + 'cats cute' + ]; + + // add test data + data.forEach((item, id) => { + index.add(id, item); + }); + + // perform query + let result = await index.search({ + query: "cute cat", + }); + + // display results + result.forEach(i => { + console.log(data[i]); + }); + + // ----------------------- + // EXPORT + // ----------------------- + + await index.export(function(){ + // do nothing here + }); + + index = await new WorkerIndex({ + tokenize: "forward", + config: dirname + "/config.js" + }); + + // ----------------------- + // IMPORT + // ----------------------- + + await index.import(); + + // perform query + result = await index.search({ + query: "cute cat", + }); + + // display results + console.log("-------------------------------------"); + result.forEach(i => { + console.log(data[i]); + }); + +}()); diff --git a/example/nodejs-esm/basic-worker-export-import/package.json b/example/nodejs-esm/basic-worker-export-import/package.json new file mode 100644 index 0000000..c179cf9 --- /dev/null +++ b/example/nodejs-esm/basic-worker-export-import/package.json @@ -0,0 +1,7 @@ +{ + "name": "nodejs-esm-basic-worker-extern-config", + "type": "module", + "dependencies": { + "flexsearch": "^0.8.105" + } +} diff --git a/package-lock.json b/package-lock.json index d24f6ee..074291a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.107", + "version": "0.8.108", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.107", + "version": "0.8.108", "funding": [ { "type": "github", diff --git a/package.json b/package.json index c2e7b14..ed9fa6a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.107", + "version": "0.8.108", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/src/bundle.js b/src/bundle.js index ac905d8..85a24e2 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -310,7 +310,9 @@ if(RELEASE !== "bundle.module" && FlexSearch["Language"] = {}; - const root = self; + const root = typeof self !== "undefined" ? self : + typeof global !== "undefined" ? global : + typeof window !== "undefined" ? window : {}; let prop; // AMD (RequireJS) diff --git a/src/worker.js b/src/worker.js index 860ad87..c5fac26 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,6 +1,7 @@ import { IndexOptions } from "./type.js"; import { create_object, is_function, is_object, is_string } from "./common.js"; import handler from "./worker/handler.js"; +import apply_async from "./async.js"; let pid = 0; @@ -97,11 +98,16 @@ register("append"); register("search"); register("update"); register("remove"); +register("clear"); +register("export"); +register("import"); + +apply_async(WorkerIndex.prototype); function register(key){ WorkerIndex.prototype[key] = - WorkerIndex.prototype[key + "Async"] = async function(){ + /*WorkerIndex.prototype[key + "Async"] =*/ async function(){ const self = this; const args = [].slice.call(arguments); diff --git a/src/worker/handler.js b/src/worker/handler.js index 37747c0..0f4f7c0 100644 --- a/src/worker/handler.js +++ b/src/worker/handler.js @@ -1,21 +1,24 @@ import Index from "../index.js"; import { IndexOptions } from "../type.js"; +/** @type Index */ +let index; +/** @type {IndexOptions} */ +let options; + export default async function(data) { data = data["data"]; - /** @type Index */ - const index = self["_index"]; - const args = data["args"]; const task = data["task"]; + const id = data["id"]; + let args = data["args"]; switch(task){ case "init": - /** @type {IndexOptions} */ - let options = data["options"] || {}; + options = data["options"] || {}; let filepath = options.config; if(filepath){ options = options; @@ -31,24 +34,34 @@ export default async function(data) { // export the FlexSearch global payload to "self" Function("return " + factory)()(self); - /** @type Index */ - self["_index"] = new self["FlexSearch"]["Index"](options); + index = new self["FlexSearch"]["Index"](options); // destroy the exported payload delete self["FlexSearch"]; } else{ - self["_index"] = new Index(options); + index = new Index(options); } - postMessage({ "id": data["id"] }); + postMessage({ "id": id }); break; default: - const id = data["id"]; - const message = index[task].apply(index, args); + let message; + + if(task === "export"){ + args = [options.export]; + } + if(task === "import"){ + await options.import.call(index, index); + //args = [options.import]; + } + else{ + message = index[task].apply(index, args); + } + postMessage( task === "search" ? { "id": id, "msg": message } diff --git a/src/worker/node.js b/src/worker/node.js index 3898b9a..dc3f76b 100644 --- a/src/worker/node.js +++ b/src/worker/node.js @@ -1,23 +1,25 @@ const { parentPort } = require("worker_threads"); -const { join } = require("path"); +//const { join } = require("path"); // Test Path //const { Index } = require("../../dist/flexsearch.bundle.min.js"); -const { Index } = require("../flexsearch.bundle.min.js"); +const { Index } = require("flexsearch"); +/** @type Index */ let index; +/** @type {IndexOptions} */ +let options; parentPort.on("message", async function(data){ - /** @type Index */ - const args = data["args"]; const task = data["task"]; const id = data["id"]; + let args = data["args"]; switch(task){ case "init": - let options = data["options"] || {}; + options = data["options"] || {}; // load extern field configuration let filepath = options["config"]; if(filepath){ @@ -33,7 +35,19 @@ parentPort.on("message", async function(data){ default: - const message = index[task].apply(index, args); + let message; + + if(task === "export"){ + args = [options.export]; + } + if(task === "import"){ + await options.import.call(index, index); + //args = [options.import]; + } + else{ + message = index[task].apply(index, args); + } + parentPort.postMessage( task === "search" ? { "id": id, "msg": message } diff --git a/src/worker/node.mjs b/src/worker/node.mjs index 0248f08..12eda37 100644 --- a/src/worker/node.mjs +++ b/src/worker/node.mjs @@ -3,22 +3,24 @@ import { join } from "path"; // Test Path //import Index from "../../src/index.js"; //import { Index } from "../../dist/flexsearch.bundle.module.min.js"; -import { Index } from "../flexsearch.bundle.module.min.js"; +import { Index } from "flexsearch/esm"; +/** @type Index */ let index; +/** @type {IndexOptions} */ +let options; parentPort.on("message", async function(data){ - /** @type Index */ - const args = data["args"]; const task = data["task"]; const id = data["id"]; + let args = data["args"]; switch(task){ case "init": - let options = data["options"] || {}; + options = data["options"] || {}; // load extern field configuration let filepath = options["config"]; if(filepath){ @@ -35,7 +37,19 @@ parentPort.on("message", async function(data){ default: - const message = index[task].apply(index, args); + let message; + + if(task === "export"){ + args = [options.export]; + } + if(task === "import"){ + await options.import.call(index, index); + //args = [options.import]; + } + else{ + message = index[task].apply(index, args); + } + parentPort.postMessage( task === "search" ? { "id": id, "msg": message }