From f774be96460d0267594a63891bcf5a8edb0a9b0b Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Fri, 2 May 2025 13:29:07 +0200 Subject: [PATCH] extended result highlighting --- README.md | 10 +- dist/flexsearch.bundle.debug.js | 2485 ++++++++++++----------- dist/flexsearch.bundle.min.js | 181 +- dist/flexsearch.bundle.module.debug.js | 2479 +++++++++++----------- dist/flexsearch.bundle.module.min.js | 183 +- dist/flexsearch.compact.debug.js | 1180 ++++++----- dist/flexsearch.compact.min.js | 114 +- dist/flexsearch.compact.module.debug.js | 1174 ++++++----- dist/flexsearch.compact.module.min.js | 116 +- dist/flexsearch.es5.debug.js | 2056 ++++++++++--------- dist/flexsearch.es5.min.js | 259 +-- dist/flexsearch.light.debug.js | 2 +- dist/flexsearch.light.min.js | 2 +- dist/flexsearch.light.module.debug.js | 2 +- dist/flexsearch.light.module.min.js | 2 +- dist/module-debug/bundle.js | 15 +- dist/module-debug/document/highlight.js | 811 ++++++++ dist/module-debug/document/search.js | 125 +- dist/module-debug/type.js | 32 +- dist/module-min/bundle.js | 2 +- dist/module-min/document/highlight.js | 1 + dist/module-min/document/search.js | 2 +- dist/module-min/type.js | 2 +- dist/module/bundle.js | 15 +- dist/module/document/highlight.js | 801 ++++++++ dist/module/document/search.js | 125 +- dist/module/type.js | 32 +- doc/0.7.0-lang.md | 258 --- doc/0.7.0.md | 1767 ---------------- doc/custom-builds.md | 58 +- doc/result-highlighting.md | 314 ++- index.d.ts | 44 +- package-lock.json | 4 +- package.json | 30 +- src/bundle.js | 18 +- src/config.js | 7 +- src/document/highlight.js | 841 ++++++++ src/document/search.js | 129 +- src/index.js | 7 + src/type.js | 30 +- src/worker.js | 25 +- task/babel.bundle.json | 3 +- task/babel.debug.json | 3 +- task/babel.js | 5 +- task/babel.min.json | 3 +- test/highlight.js | 658 +++++- 46 files changed, 9155 insertions(+), 7257 deletions(-) create mode 100644 dist/module-debug/document/highlight.js create mode 100644 dist/module-min/document/highlight.js create mode 100644 dist/module/document/highlight.js delete mode 100644 doc/0.7.0-lang.md delete mode 100644 doc/0.7.0.md create mode 100644 src/document/highlight.js diff --git a/README.md b/README.md index 926634b..c0f8c2b 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ FlexSearch v0.8: [Overview and Migration Guide](doc/0.8.0.md) [Persistent Indexes](doc/persistent.md)  •  [Using Worker](doc/worker.md)  •  [Tag Search](doc/document-search.md#tag-search)  •  +[Highlighting](doc/result-highlighting.md)  •  [Resolver](doc/resolver.md)  •  [Changelog](CHANGELOG.md) @@ -472,7 +473,7 @@ The **_dist_** folder is located in: `node_modules/flexsearch/dist/` - Document Store + Document Datastore ✓ ✓ @@ -545,6 +546,13 @@ The **_dist_** folder is located in: `node_modules/flexsearch/dist/` - + + Result Highlighting + ✓ + ✓ + - + + Persistent Index (IndexedDB) ✓ diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 18fa21b..d1c6e1f 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,20 +1,20 @@ /**! - * FlexSearch.js v0.8.158 (Bundle/Debug) + * FlexSearch.js v0.8.160 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ (function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f; -var u; -function z(a, b, c) { - const d = typeof c, e = typeof a; - if ("undefined" !== d) { - if ("undefined" !== e) { +var v; +function F(a, b, c) { + const e = typeof c, d = typeof a; + if ("undefined" !== e) { + if ("undefined" !== d) { if (c) { - if ("function" === e && d === e) { - return function(h) { - return a(c(h)); + if ("function" === d && e === d) { + return function(k) { + return a(c(k)); }; } b = a.constructor; @@ -42,26 +42,26 @@ function z(a, b, c) { } return c; } - return "undefined" === e ? b : a; + return "undefined" === d ? b : a; } -function A() { +function G() { return Object.create(null); } -function D(a) { +function L(a) { return "string" === typeof a; } function aa(a) { return "object" === typeof a; } -function ba(a) { +function da(a) { const b = []; for (const c of a.keys()) { b.push(c); } return b; } -function ca(a, b) { - if (D(b)) { +function ea(a, b) { + if (L(b)) { a = a[b]; } else { for (let c = 0; a && c < b.length; c++) { @@ -70,17 +70,17 @@ function ca(a, b) { } return a; } -function da(a) { +function fa(a) { let b = 0; - for (let c = 0, d; c < a.length; c++) { - (d = a[c]) && b < d.length && (b = d.length); + for (let c = 0, e; c < a.length; c++) { + (e = a[c]) && b < e.length && (b = e.length); } return b; } -;const ea = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = /[\u0300-\u036f]/g; -function G(a = {}) { - if (!this || this.constructor !== G) { - return new G(...arguments); +;const ha = /[^\p{L}\p{N}]+/u, ia = /(\d{3})/g, ja = /(\D)(\d{3})/g, ka = /(\d{3})(\D)/g, la = /[\u0300-\u036f]/g; +function ma(a = {}) { + if (!this || this.constructor !== ma) { + return new ma(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -90,53 +90,53 @@ function G(a = {}) { this.assign(a); } } -u = G.prototype; -u.assign = function(a) { - this.normalize = z(a.normalize, !0, this.normalize); - let b = a.include, c = b || a.exclude || a.split, d; +v = ma.prototype; +v.assign = function(a) { + this.normalize = F(a.normalize, !0, this.normalize); + let b = a.include, c = b || a.exclude || a.split, e; if (c || "" === c) { if ("object" === typeof c && c.constructor !== RegExp) { - let e = ""; - d = !b; - b || (e += "\\p{Z}"); - c.letter && (e += "\\p{L}"); - c.number && (e += "\\p{N}", d = !!b); - c.symbol && (e += "\\p{S}"); - c.punctuation && (e += "\\p{P}"); - c.control && (e += "\\p{C}"); + let d = ""; + e = !b; + b || (d += "\\p{Z}"); + c.letter && (d += "\\p{L}"); + c.number && (d += "\\p{N}", e = !!b); + c.symbol && (d += "\\p{S}"); + c.punctuation && (d += "\\p{P}"); + c.control && (d += "\\p{C}"); if (c = c.char) { - e += "object" === typeof c ? c.join("") : c; + d += "object" === typeof c ? c.join("") : c; } try { - this.split = new RegExp("[" + (b ? "^" : "") + e + "]+", "u"); + this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); } catch (f) { 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 { - this.split = c, d = !1 === c || 2 > "a1a".split(c).length; + this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } - this.numeric = z(a.numeric, d); + this.numeric = F(a.numeric, e); } else { try { - this.split = z(this.split, ea); - } catch (e) { + this.split = F(this.split, ha); + } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = z(a.numeric, z(this.numeric, !0)); + this.numeric = F(a.numeric, F(this.numeric, !0)); } - this.prepare = z(a.prepare, null, this.prepare); - this.finalize = z(a.finalize, null, this.finalize); + this.prepare = F(a.prepare, null, this.prepare); + this.finalize = F(a.finalize, null, this.finalize); c = a.filter; - this.filter = "function" === typeof c ? c : z(c && new Set(c), null, this.filter); - this.dedupe = z(a.dedupe, !0, this.dedupe); - this.matcher = z((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = z((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = z((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = z(a.replacer, null, this.replacer); - this.minlength = z(a.minlength, 1, this.minlength); - this.maxlength = z(a.maxlength, 1024, this.maxlength); - this.rtl = z(a.rtl, !1, this.rtl); - if (this.cache = c = z(a.cache, !0, this.cache)) { + this.filter = "function" === typeof c ? c : F(c && new Set(c), null, this.filter); + this.dedupe = F(a.dedupe, !0, this.dedupe); + this.matcher = F((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = F((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = F((c = a.stemmer) && new Map(c), null, this.stemmer); + this.replacer = F(a.replacer, null, this.replacer); + this.minlength = F(a.minlength, 1, this.minlength); + this.maxlength = F(a.maxlength, 1024, this.maxlength); + this.rtl = F(a.rtl, !1, this.rtl); + if (this.cache = c = F(a.cache, !0, this.cache)) { this.H = null, this.S = "number" === typeof c ? c : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; @@ -144,31 +144,31 @@ u.assign = function(a) { this.A = ""; this.N = null; if (this.matcher) { - for (const e of this.matcher.keys()) { - this.h += (this.h ? "|" : "") + e; + for (const d of this.matcher.keys()) { + this.h += (this.h ? "|" : "") + d; } } if (this.stemmer) { - for (const e of this.stemmer.keys()) { - this.A += (this.A ? "|" : "") + e; + for (const d of this.stemmer.keys()) { + this.A += (this.A ? "|" : "") + d; } } return this; }; -u.addStemmer = function(a, b) { +v.addStemmer = function(a, b) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, b); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && H(this); + this.cache && N(this); return this; }; -u.addFilter = function(a) { +v.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && H(this); + this.cache && N(this); return this; }; -u.addMapper = function(a, b) { +v.addMapper = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -177,10 +177,10 @@ u.addMapper = function(a, b) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, b); - this.cache && H(this); + this.cache && N(this); return this; }; -u.addMatcher = function(a, b) { +v.addMatcher = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -191,40 +191,40 @@ u.addMatcher = function(a, b) { this.matcher.set(a, b); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && H(this); + this.cache && N(this); return this; }; -u.addReplacer = function(a, b) { +v.addReplacer = function(a, b) { if ("string" === typeof a) { return this.addMatcher(a, b); } this.replacer || (this.replacer = []); this.replacer.push(a, b); - this.cache && H(this); + this.cache && N(this); return this; }; -u.encode = function(a, b) { +v.encode = function(a, b) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.B.has(a)) { return this.B.get(a); } } else { - this.H = setTimeout(H, 50, this); + this.H = setTimeout(N, 50, this); } } - this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = la ? a.normalize("NFKD").replace(la, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(ja, "$1 $2").replace(ka, "$1 $2").replace(ia, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let d = [], e = A(), f, g, h = this.split || "" === this.split ? a.split(this.split) : [a]; - for (let l = 0, m, n; l < h.length; l++) { - if ((m = n = h[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { + let e = [], d = G(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; + for (let l = 0, m, n; l < k.length; l++) { + if ((m = n = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (b) { - if (e[m]) { + if (d[m]) { continue; } - e[m] = 1; + d[m] = 1; } else { if (f === m) { continue; @@ -232,48 +232,48 @@ u.encode = function(a, b) { f = m; } if (c) { - d.push(m); + e.push(m); } else { if (!this.filter || ("function" === typeof this.filter ? this.filter(m) : !this.filter.has(m))) { if (this.cache && m.length <= this.L) { if (this.H) { - var k = this.G.get(m); - if (k || "" === k) { - k && d.push(k); + var h = this.G.get(m); + if (h || "" === h) { + h && e.push(h); continue; } } else { - this.H = setTimeout(H, 50, this); + this.H = setTimeout(N, 50, this); } } if (this.stemmer) { this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")); - let p; - for (; p !== m && 2 < m.length;) { - p = m, m = m.replace(this.N, r => this.stemmer.get(r)); + let r; + for (; r !== m && 2 < m.length;) { + r = m, m = m.replace(this.N, q => this.stemmer.get(q)); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { - k = ""; - for (let p = 0, r = "", q, t; p < m.length; p++) { - q = m.charAt(p), q === r && this.dedupe || ((t = this.mapper && this.mapper.get(q)) || "" === t ? t === r && this.dedupe || !(r = t) || (k += t) : k += r = q); + h = ""; + for (let r = 0, q = "", t, u; r < m.length; r++) { + t = m.charAt(r), t === q && this.dedupe || ((u = this.mapper && this.mapper.get(t)) || "" === u ? u === q && this.dedupe || !(q = u) || (h += u) : h += q = t); } - m = k; + m = h; } - this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, p => this.matcher.get(p))); + this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, r => this.matcher.get(r))); if (m && this.replacer) { - for (k = 0; m && k < this.replacer.length; k += 2) { - m = m.replace(this.replacer[k], this.replacer[k + 1]); + for (h = 0; m && h < this.replacer.length; h += 2) { + m = m.replace(this.replacer[h], this.replacer[h + 1]); } } this.cache && n.length <= this.L && (this.G.set(n, m), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); if (m) { if (m !== n) { if (b) { - if (e[m]) { + if (d[m]) { continue; } - e[m] = 1; + d[m] = 1; } else { if (g === m) { continue; @@ -281,71 +281,71 @@ u.encode = function(a, b) { g = m; } } - d.push(m); + e.push(m); } } } } } - this.finalize && (d = this.finalize(d) || d); - this.cache && a.length <= this.K && (this.B.set(a, d), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); - return d; + this.finalize && (e = this.finalize(e) || e); + this.cache && a.length <= this.K && (this.B.set(a, e), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); + return e; }; -function H(a) { +function N(a) { a.H = null; a.B.clear(); a.G.clear(); } -;let I, L; -async function ka(a) { +;let pa, O; +async function qa(a) { a = a.data; var b = a.task; const c = a.id; - let d = a.args; + let e = a.args; switch(b) { case "init": - L = a.options || {}; - (b = a.factory) ? (Function("return " + b)()(self), I = new self.FlexSearch.Index(L), delete self.FlexSearch) : I = new N(L); + O = a.options || {}; + (b = a.factory) ? (Function("return " + b)()(self), pa = new self.FlexSearch.Index(O), delete self.FlexSearch) : pa = new P(O); postMessage({id:c}); break; default: - let e; + let d; if ("export" === b) { - if (!L.export || "function" !== typeof L.export) { + if (!O.export || "function" !== typeof O.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - d[1] ? (d[0] = L.export, d[2] = 0, d[3] = 1) : d = null; + e[1] ? (e[0] = O.export, e[2] = 0, e[3] = 1) : e = null; } if ("import" === b) { - if (!L.import || "function" !== typeof L.import) { + if (!O.import || "function" !== typeof O.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - d[0] && (a = await L.import.call(I, d[0]), I.import(d[0], a)); + e[0] && (a = await O.import.call(pa, e[0]), pa.import(e[0], a)); } else { - (e = d && I[b].apply(I, d)) && e.then && (e = await e); + (d = e && pa[b].apply(pa, e)) && d.then && (d = await d); } - postMessage("search" === b ? {id:c, msg:e} : {id:c}); + postMessage("search" === b ? {id:c, msg:d} : {id:c}); } } -;function la(a) { - ma.call(a, "add"); - ma.call(a, "append"); - ma.call(a, "search"); - ma.call(a, "update"); - ma.call(a, "remove"); +;function ra(a) { + sa.call(a, "add"); + sa.call(a, "append"); + sa.call(a, "search"); + sa.call(a, "update"); + sa.call(a, "remove"); } -let na, oa, pa; -function qa() { - na = pa = 0; +let ta, wa, xa; +function ya() { + ta = xa = 0; } -function ma(a) { +function sa(a) { this[a + "Async"] = function() { const b = arguments; var c = b[b.length - 1]; - let d; - "function" === typeof c && (d = c, delete b[b.length - 1]); - na ? pa || (pa = Date.now() - oa >= this.priority * this.priority * 3) : (na = setTimeout(qa, 0), oa = Date.now()); - if (pa) { + let e; + "function" === typeof c && (e = c, delete b[b.length - 1]); + ta ? xa || (xa = Date.now() - wa >= this.priority * this.priority * 3) : (ta = setTimeout(ya, 0), wa = Date.now()); + if (xa) { const f = this; return new Promise(g => { setTimeout(function() { @@ -353,31 +353,31 @@ function ma(a) { }, 0); }); } - const e = this[a].apply(this, b); - c = e.then ? e : new Promise(f => f(e)); - d && c.then(d); + const d = this[a].apply(this, b); + c = d.then ? d : new Promise(f => f(d)); + e && c.then(e); return c; }; } -;let O = 0; -function P(a = {}) { +;let za = 0; +function Aa(a = {}) { function b(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && e.h[l]; - m && (m(k.msg), delete e.h[l]); + 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 = A(); + this.h = G(); if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { - e.h[++O] = function() { - k(e); - 1e9 < O && (O = 0); + return new Promise(function(h) { + d.h[++za] = function() { + h(d); + 1e9 < za && (za = 0); }; - e.worker.postMessage({id:O, task:"init", factory:c, options:a}); + d.worker.postMessage({id:za, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); @@ -385,298 +385,298 @@ function P(a = {}) { return this; } } - if (!this || this.constructor !== P) { - return new P(a); + if (!this || this.constructor !== Aa) { + return new Aa(a); } let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - const d = "undefined" === typeof window, e = this, f = ra(c, d, a.worker); + const e = "undefined" === typeof window, d = this, f = Ba(c, e, a.worker); return f.then ? f.then(function(g) { - return b.call(e, g); + return b.call(d, g); }) : b.call(this, f); } -Q("add"); -Q("append"); -Q("search"); -Q("update"); -Q("remove"); -Q("clear"); -Q("export"); -Q("import"); -la(P.prototype); -function Q(a) { - P.prototype[a] = function() { +R("add"); +R("append"); +R("search"); +R("update"); +R("remove"); +R("clear"); +R("export"); +R("import"); +ra(Aa.prototype); +function R(a) { + Aa.prototype[a] = function() { const b = this, c = [].slice.call(arguments); - var d = c[c.length - 1]; - let e; - "function" === typeof d && (e = d, c.pop()); - d = new Promise(function(f) { + var e = c[c.length - 1]; + let d; + "function" === typeof e && (d = e, c.pop()); + e = new Promise(function(f) { "export" === a && "function" === typeof c[0] && (c[0] = null); - b.h[++O] = f; - b.worker.postMessage({task:a, id:O, args:c}); + b.h[++za] = f; + b.worker.postMessage({task:a, id:za, args:c}); }); - return e ? (d.then(e), this) : d; + return d ? (e.then(d), this) : e; }; } -function ra(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("string" === typeof c ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ba(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=" + qa.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof 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 sa(a, b = 0) { - let c = [], d = []; +;function Ca(a, b = 0) { + let c = [], e = []; b && (b = 250000 / b * 5000 | 0); - for (const e of a.entries()) { - d.push(e), d.length === b && (c.push(d), d = []); + for (const d of a.entries()) { + e.push(d), e.length === b && (c.push(e), e = []); } - d.length && c.push(d); + e.length && c.push(e); return c; } -function ta(a, b) { +function Da(a, b) { b || (b = new Map()); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b.set(d[0], d[1]); + for (let c = 0, e; c < a.length; c++) { + e = a[c], b.set(e[0], e[1]); } return b; } -function ua(a, b = 0) { - let c = [], d = []; +function Ea(a, b = 0) { + let c = [], e = []; b && (b = 250000 / b * 1000 | 0); - for (const e of a.entries()) { - d.push([e[0], sa(e[1])[0]]), d.length === b && (c.push(d), d = []); + for (const d of a.entries()) { + e.push([d[0], Ca(d[1])[0]]), e.length === b && (c.push(e), e = []); } - d.length && c.push(d); + e.length && c.push(e); return c; } -function va(a, b) { +function Fa(a, b) { b || (b = new Map()); - for (let c = 0, d, e; c < a.length; c++) { - d = a[c], e = b.get(d[0]), b.set(d[0], ta(d[1], e)); + for (let c = 0, e, d; c < a.length; c++) { + e = a[c], d = b.get(e[0]), b.set(e[0], Da(e[1], d)); } return b; } -function wa(a) { +function Ga(a) { let b = [], c = []; - for (const d of a.keys()) { - c.push(d), 250000 === c.length && (b.push(c), c = []); + for (const e of a.keys()) { + c.push(e), 250000 === c.length && (b.push(c), c = []); } c.length && b.push(c); return b; } -function xa(a, b) { +function Ha(a, b) { b || (b = new Set()); for (let c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function ya(a, b, c, d, e, f, g = 0) { - const h = d && d.constructor === Array; - var k = h ? d.shift() : d; - if (!k) { - return this.export(a, b, e, f + 1); +function Ia(a, b, c, e, d, f, g = 0) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { + return this.export(a, b, d, f + 1); } - if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return ya.call(l, a, b, c, h ? d : null, e, f, g + 1); + return h.then(function() { + return Ia.call(l, a, b, c, k ? e : null, d, f, g + 1); }); } - return ya.call(this, a, b, c, h ? d : null, e, f, g + 1); + return Ia.call(this, a, b, c, k ? e : null, d, f, g + 1); } -function za(a, b) { +function Ja(a, b) { let c = ""; - for (const d of a.entries()) { - a = d[0]; - const e = d[1]; + for (const e of a.entries()) { + a = e[0]; + const d = e[1]; let f = ""; - for (let g = 0, h; g < e.length; g++) { - h = e[g] || [""]; - let k = ""; - for (let l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === b ? '"' + h[l] + '"' : h[l]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === b ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; c += (c ? "," : "") + f; } return c; } -;function Aa(a, b, c, d) { - let e = []; +;function Ma(a, b, c, e) { + let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { b -= g.length; } else { - b = g[d ? "splice" : "slice"](b, c); - const h = b.length; - if (h && (e = e.length ? e.concat(b) : b, c -= h, d && (a.length -= h), !c)) { + 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 e; + return d; } -function R(a) { - if (!this || this.constructor !== R) { - return new R(a); +function T(a) { + if (!this || this.constructor !== T) { + return new T(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; const b = this; - return new Proxy([], {get(c, d) { - if ("length" === d) { + return new Proxy([], {get(c, e) { + if ("length" === e) { return b.length; } - if ("push" === d) { - return function(e) { - b.index[b.index.length - 1].push(e); + if ("push" === e) { + return function(d) { + b.index[b.index.length - 1].push(d); b.length++; }; } - if ("pop" === d) { + if ("pop" === e) { return function() { if (b.length) { return b.length--, b.index[b.index.length - 1].pop(); } }; } - if ("indexOf" === d) { - return function(e) { + if ("indexOf" === e) { + return function(d) { let f = 0; - for (let g = 0, h, k; g < b.index.length; g++) { - h = b.index[g]; - k = h.indexOf(e); - if (0 <= k) { - return f + k; + for (let g = 0, k, h; g < b.index.length; g++) { + k = b.index[g]; + h = k.indexOf(d); + if (0 <= h) { + return f + h; } - f += h.length; + f += k.length; } return -1; }; } - if ("includes" === d) { - return function(e) { + if ("includes" === e) { + return function(d) { for (let f = 0; f < b.index.length; f++) { - if (b.index[f].includes(e)) { + if (b.index[f].includes(d)) { return !0; } } return !1; }; } - if ("slice" === d) { - return function(e, f) { - return Aa(b, e || 0, f || b.length, !1); + if ("slice" === e) { + return function(d, f) { + return Ma(b, d || 0, f || b.length, !1); }; } - if ("splice" === d) { - return function(e, f) { - return Aa(b, e || 0, f || b.length, !0); + if ("splice" === e) { + return function(d, f) { + return Ma(b, d || 0, f || b.length, !0); }; } - if ("constructor" === d) { + if ("constructor" === e) { return Array; } - if ("symbol" !== typeof d) { - return (c = b.index[d / 2 ** 31 | 0]) && c[d]; + if ("symbol" !== typeof e) { + return (c = b.index[e / 2 ** 31 | 0]) && c[e]; } - }, set(c, d, e) { - c = d / 2 ** 31 | 0; - (b.index[c] || (b.index[c] = []))[d] = e; + }, set(c, e, d) { + c = e / 2 ** 31 | 0; + (b.index[c] || (b.index[c] = []))[e] = d; b.length++; return !0; }}); } -R.prototype.clear = function() { +T.prototype.clear = function() { this.index.length = 0; }; -R.prototype.destroy = function() { +T.prototype.destroy = function() { this.proxy = this.index = null; }; -R.prototype.push = function() { +T.prototype.push = function() { }; -function S(a = 8) { - if (!this || this.constructor !== S) { - return new S(a); +function U(a = 8) { + if (!this || this.constructor !== U) { + return new U(a); } - this.index = A(); + this.index = G(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.B = Na, this.A = BigInt(a)) : (this.B = Oa, this.A = a); } -S.prototype.get = function(a) { +U.prototype.get = function(a) { const b = this.index[this.B(a)]; return b && b.get(a); }; -S.prototype.set = function(a, b) { +U.prototype.set = function(a, b) { var c = this.B(a); - let 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.h.push(d), this.size++); + let e = this.index[c]; + e ? (c = e.size, e.set(a, b), (c -= e.size) && this.size++) : (this.index[c] = e = new Map([[a, b]]), this.h.push(e), this.size++); }; -function T(a = 8) { - if (!this || this.constructor !== T) { - return new T(a); +function V(a = 8) { + if (!this || this.constructor !== V) { + return new V(a); } - this.index = A(); + this.index = G(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.B = Na, this.A = BigInt(a)) : (this.B = Oa, this.A = a); } -T.prototype.add = function(a) { +V.prototype.add = function(a) { var b = this.B(a); let 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), this.size++); }; -u = S.prototype; -u.has = T.prototype.has = function(a) { +v = U.prototype; +v.has = V.prototype.has = function(a) { const b = this.index[this.B(a)]; return b && b.has(a); }; -u.delete = T.prototype.delete = function(a) { +v.delete = V.prototype.delete = function(a) { const b = this.index[this.B(a)]; b && b.delete(a) && this.size--; }; -u.clear = T.prototype.clear = function() { - this.index = A(); +v.clear = V.prototype.clear = function() { + this.index = G(); this.h = []; this.size = 0; }; -u.values = T.prototype.values = function*() { +v.values = V.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].values()) { yield b; } } }; -u.keys = T.prototype.keys = function*() { +v.keys = V.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].keys()) { yield b; } } }; -u.entries = T.prototype.entries = function*() { +v.entries = V.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].entries()) { yield b; } } }; -function Ca(a) { +function Oa(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; } - let c = 0, d = this.A + 1; - for (let e = 0; e < a.length; e++) { - c = (c * d ^ a.charCodeAt(e)) & b; + let c = 0, e = this.A + 1; + for (let d = 0; d < a.length; d++) { + c = (c * e ^ a.charCodeAt(d)) & b; } return 32 === this.A ? c + 2 ** 31 : c; } -function Ba(a) { +function Na(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -686,75 +686,75 @@ function Ba(a) { return BigInt(a) & b; } c = BigInt(0); - let d = this.A + BigInt(1); - for (let e = 0; e < a.length; e++) { - c = (c * d ^ BigInt(a.charCodeAt(e))) & b; + let e = this.A + BigInt(1); + for (let d = 0; d < a.length; d++) { + c = (c * e ^ BigInt(a.charCodeAt(d))) & b; } return c; } -;U.prototype.add = function(a, b, c) { - aa(a) && (b = a, a = ca(b, this.key)); +;Pa.prototype.add = function(a, b, c) { + aa(a) && (b = a, a = ea(b, this.key)); if (b && (a || 0 === a)) { if (!c && this.reg.has(a)) { return this.update(a, b); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.F[h]; - var d = this.index.get(this.field[h]); - if ("function" === typeof k) { - var e = k(b); - e && d.add(a, e, !1, !0); + for (let k = 0, h; k < this.field.length; k++) { + h = this.F[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(b); + d && e.add(a, d, !1, !0); } else { - if (e = k.I, !e || e(b)) { - k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), Da(b, k, this.J, 0, d, a, k[0], c); + if (d = h.I, !d || d(b)) { + h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), Qa(b, h, this.J, 0, e, a, h[0], c); } } } if (this.tag) { - for (d = 0; d < this.D.length; d++) { - var f = this.D[d], g = this.R[d]; - e = this.tag.get(g); - let h = A(); + for (e = 0; e < this.D.length; e++) { + var f = this.D[e], g = this.R[e]; + d = this.tag.get(g); + let k = G(); if ("function" === typeof f) { if (f = f(b), !f) { continue; } } else { - const k = f.I; - if (k && !k(b)) { + const h = f.I; + if (h && !h(b)) { continue; } f.constructor === String && (f = "" + f); - f = ca(b, f); + f = ea(b, f); } - if (e && f) { - D(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - if (l = f[k], !h[l] && (h[l] = 1, (g = e.get(l)) ? m = g : e.set(l, m = []), !c || !m.includes(a))) { + if (d && f) { + L(f) && (f = [f]); + for (let h = 0, l, m; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !c || !m.includes(a))) { if (m.length === 2 ** 31 - 1) { - g = new R(m); + g = new T(m); if (this.fastupdate) { for (let n of this.reg.values()) { n.includes(m) && (n[n.indexOf(m)] = g); } } - e.set(l, m = g); + d.set(l, m = g); } m.push(a); this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); } } } else { - e || console.warn("Tag '" + g + "' was not found"); + d || console.warn("Tag '" + g + "' was not found"); } } } if (this.store && (!c || !this.store.has(a))) { - let h; + let k; if (this.C) { - h = A(); - for (let k = 0, l; k < this.C.length; k++) { - l = this.C[k]; + k = G(); + for (let h = 0, l; h < this.C.length; h++) { + l = this.C[h]; if ((c = l.I) && !c(b)) { continue; } @@ -765,131 +765,131 @@ function Ba(a) { continue; } l = [l.V]; - } else if (D(l) || l.constructor === String) { - h[l] = b[l]; + } else if (L(l) || l.constructor === String) { + k[l] = b[l]; continue; } - Ea(b, h, l, 0, l[0], m); + Ra(b, k, l, 0, l[0], m); } } - this.store.set(a, h || b); + this.store.set(a, k || b); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Ea(a, b, c, d, e, f) { - a = a[e]; - if (d === c.length - 1) { - b[e] = f || a; +function Ra(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[e] = Array(a.length), e = 0; e < a.length; e++) { - Ea(a, b, c, d, e); + for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { + Ra(a, b, c, e, d); } } else { - b = b[e] || (b[e] = A()), e = c[++d], Ea(a, b, c, d, e); + b = b[d] || (b[d] = G()), d = c[++e], Ra(a, b, c, e, d); } } } -function Da(a, b, c, d, e, f, g, h) { +function Qa(a, b, c, e, d, f, g, k) { if (a = a[g]) { - if (d === b.length - 1) { + if (e === b.length - 1) { if (a.constructor === Array) { - if (c[d]) { + if (c[e]) { for (b = 0; b < a.length; b++) { - e.add(f, a[b], !0, !0); + d.add(f, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Da(a, b, c, d, e, f, g, h); + Qa(a, b, c, e, d, f, g, k); } } else { - g = b[++d], Da(a, b, c, d, e, f, g, h); + g = b[++e], Qa(a, b, c, e, d, f, g, k); } } } else { - e.db && e.remove(f); + d.db && d.remove(f); } } -;function Fa(a, b, c, d, e, f, g) { - const h = a.length; - let k = [], l, m; - l = A(); - for (let n = 0, p, r, q, t; n < b; n++) { - for (let v = 0; v < h; v++) { - if (q = a[v], n < q.length && (p = q[n])) { - for (let w = 0; w < p.length; w++) { - r = p[w]; - (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1); - t = k[m] || (k[m] = []); +;function Sa(a, b, c, e, d, f, g) { + const k = a.length; + let h = [], l, m; + l = G(); + for (let n = 0, r, q, t, u; n < b; n++) { + for (let p = 0; p < k; p++) { + if (t = a[p], n < t.length && (r = t[n])) { + for (let z = 0; z < r.length; z++) { + q = r[z]; + (m = l[q]) ? l[q]++ : (m = 0, l[q] = 1); + u = h[m] || (h[m] = []); if (!g) { - let x = n + (v || !e ? 0 : f || 0); - t = t[x] || (t[x] = []); + let x = n + (p || !d ? 0 : f || 0); + u = u[x] || (u[x] = []); } - t.push(r); - if (g && c && m === h - 1 && t.length - d === c) { - return d ? t.slice(d) : t; + u.push(q); + if (g && c && m === k - 1 && u.length - e === c) { + return e ? u.slice(e) : u; } } } } } - if (a = k.length) { - if (e) { - k = 1 < k.length ? Ga(k, c, d, g, f) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + if (a = h.length) { + if (d) { + h = 1 < h.length ? Ta(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; - if (c || d) { + h = h[a - 1]; + if (c || e) { if (g) { - if (k.length > c || d) { - k = k.slice(d, c + d); + if (h.length > c || e) { + h = h.slice(e, c + e); } } else { - e = []; - for (let n = 0, p; n < k.length; n++) { - if (p = k[n], p.length > d) { - d -= p.length; + d = []; + for (let n = 0, r; n < h.length; n++) { + if (r = h[n], r.length > e) { + e -= r.length; } else { - if (p.length > c || d) { - p = p.slice(d, c + d), c -= p.length, d && (d -= p.length); + if (r.length > c || e) { + r = r.slice(e, c + e), c -= r.length, e && (e -= r.length); } - e.push(p); + d.push(r); if (!c) { break; } } } - k = 1 < e.length ? [].concat.apply([], e) : e[0]; + h = 1 < d.length ? [].concat.apply([], d) : d[0]; } } } } - return k; + return h; } -function Ga(a, b, c, d, e) { - const f = [], g = A(); - let h; - var k = a.length; +function Ta(a, b, c, e, d) { + const f = [], g = G(); + let k; + var h = a.length; let l; - if (d) { - for (e = k - 1; 0 <= e; e--) { - if (l = (d = a[e]) && d.length) { - for (k = 0; k < l; k++) { - if (h = d[k], !g[h]) { - if (g[h] = 1, c) { + if (e) { + for (d = h - 1; 0 <= d; d--) { + if (l = (e = a[d]) && e.length) { + for (h = 0; h < l; h++) { + if (k = e[h], !g[k]) { + if (g[k] = 1, c) { c--; } else { - if (f.push(h), f.length === b) { + if (f.push(k), f.length === b) { return f; } } @@ -898,18 +898,18 @@ function Ga(a, b, c, d, e) { } } } else { - for (let m = k - 1, n, p = 0; 0 <= m; m--) { + for (let m = h - 1, n, r = 0; 0 <= m; m--) { n = a[m]; - for (let r = 0; r < n.length; r++) { - if (l = (d = n[r]) && d.length) { - for (let q = 0; q < l; q++) { - if (h = d[q], !g[h]) { - if (g[h] = 1, c) { + for (let q = 0; q < n.length; q++) { + if (l = (e = n[q]) && e.length) { + for (let t = 0; t < l; t++) { + if (k = e[t], !g[k]) { + if (g[k] = 1, c) { c--; } else { - let t = (r + (m < k - 1 ? e || 0 : 0)) / (m + 1) | 0; - (f[t] || (f[t] = [])).push(h); - if (++p === b) { + let u = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[u] || (f[u] = [])).push(k); + if (++r === b) { return f; } } @@ -921,217 +921,217 @@ function Ga(a, b, c, d, e) { } return f; } -function Ha(a, b, c) { - const d = A(), e = []; +function Ua(a, b, c) { + const e = G(), d = []; for (let f = 0, g; f < b.length; f++) { g = b[f]; - for (let h = 0; h < g.length; h++) { - d[g[h]] = 1; + for (let k = 0; k < g.length; k++) { + e[g[k]] = 1; } } if (c) { for (let f = 0, g; f < a.length; f++) { - g = a[f], d[g] && (e.push(g), d[g] = 0); + g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, h; f < a.result.length; f++) { + for (let f = 0, g, k; f < a.result.length; f++) { for (g = a.result[f], b = 0; b < g.length; b++) { - h = g[b], d[h] && ((e[f] || (e[f] = [])).push(h), d[h] = 0); + k = g[b], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); } } } - return e; + return d; } -;function Ia(a, b, c, d) { +;function Va(a, b, c, e) { 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 ? V.call(this, a) : a; + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, e ? X.call(this, a) : a; } - let e = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + let d = []; + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { if (c) { - if (c >= h) { - c -= h; + if (c >= k) { + c -= k; continue; } - c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); + c < k && (g = b ? g.slice(c, c + b) : g.slice(c), k = g.length, c = 0); } - h > b && (g = g.slice(0, b), h = b); - if (!e.length && h >= b) { - return d ? V.call(this, g) : g; + k > b && (g = g.slice(0, b), k = b); + if (!d.length && k >= b) { + return e ? X.call(this, g) : g; } - e.push(g); - b -= h; + d.push(g); + b -= k; if (!b) { break; } } } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? V.call(this, e) : e; + d = 1 < d.length ? [].concat.apply([], d) : d[0]; + return e ? X.call(this, d) : d; } -;function Ja(a, b, c) { - var d = c[0]; - if (d.then) { +;function Wa(a, b, c) { + var e = c[0]; + if (e.then) { return Promise.all(c).then(function(m) { return a[b].apply(a, m); }); } - if (d[0] && d[0].index) { - return a[b].apply(a, d); + if (e[0] && e[0].index) { + return a[b].apply(a, e); } - d = []; - let e = [], f = 0, g = 0, h, k, l; + e = []; + let d = [], f = 0, g = 0, k, h, l; for (let m = 0, n; m < c.length; m++) { if (n = c[m]) { - let p; - if (n.constructor === W) { - p = n.result; + let r; + if (n.constructor === Y) { + r = n.result; } else if (n.constructor === Array) { - p = n; + r = n; } else { - if (f = n.limit || 0, g = 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; + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { + n.resolve = !1, n.enrich = !1, r = n.index.search(n).result, n.resolve = h, n.enrich = k; } else if (n.and) { - p = a.and(n.and); + r = a.and(n.and); } else if (n.or) { - p = a.or(n.or); + r = a.or(n.or); } else if (n.xor) { - p = a.xor(n.xor); + r = a.xor(n.xor); } else if (n.not) { - p = a.not(n.not); + r = a.not(n.not); } else { continue; } } - if (p.then) { - e.push(p); - } else if (p.length) { - d[m] = p; + if (r.then) { + d.push(r); + } else if (r.length) { + e[m] = r; } else if (!l && ("and" === b || "xor" === b)) { - d = []; + e = []; break; } } } - return {O:d, P:e, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } -;W.prototype.or = function() { - const {O:a, P:b, limit:c, offset:d, enrich:e, resolve:f} = Ja(this, "or", arguments); - return Ka.call(this, a, b, c, d, e, f); +;Y.prototype.or = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Wa(this, "or", arguments); + return Xa.call(this, a, b, c, e, d, f); }; -function Ka(a, b, c, d, e, f) { +function Xa(a, b, c, e, d, f) { if (b.length) { const g = this; - return Promise.all(b).then(function(h) { - a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); - } - return Ka.call(g, a, [], c, d, e, f); - }); - } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ga(a, c, d, !1, this.h), d = 0)); - return f ? this.resolve(c, d, e) : this; -} -;W.prototype.and = function() { - let a = this.result.length, b, c, d, e; - if (!a) { - const f = arguments[0]; - f && (a = !!f.suggest, e = f.resolve, b = f.limit, c = f.offset, d = f.enrich && e); - } - if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); - return La.call(this, f, g, h, k, l, m, n); - } - return e ? this.resolve(b, c, d) : this; -}; -function La(a, b, c, d, e, f, g) { - if (b.length) { - const h = this; return Promise.all(b).then(function(k) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } - return La.call(h, a, [], c, d, e, f, g); + return Xa.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 = Ta(a, c, e, !1, this.h), e = 0)); + return f ? this.resolve(c, e, d) : this; +} +;Y.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} = Wa(this, "and", arguments); + return Ya.call(this, f, g, k, h, l, m, n); + } + return d ? this.resolve(b, c, e) : this; +}; +function Ya(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; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Ya.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 { - if (b = da(a)) { - return this.result = Fa(a, b, c, d, g, this.h, f), f ? e ? V.call(this.index, this.result) : this.result : this; + if (b = fa(a)) { + return this.result = Sa(a, b, c, e, g, this.h, f), f ? d ? X.call(this.index, this.result) : this.result : this; } this.result = []; } } else { g || (this.result = a); } - return f ? this.resolve(c, d, e) : this; + return f ? this.resolve(c, e, d) : this; } -;W.prototype.xor = function() { - const {O:a, P:b, limit:c, offset:d, enrich:e, resolve:f, suggest:g} = Ja(this, "xor", arguments); - return Ma.call(this, a, b, c, d, e, f, g); +;Y.prototype.xor = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Wa(this, "xor", arguments); + return Za.call(this, a, b, c, e, d, f, g); }; -function Ma(a, b, c, d, e, f, g) { +function Za(a, b, c, e, d, f, g) { if (b.length) { - const h = this; - return Promise.all(b).then(function(k) { + const k = this; + return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Ma.call(h, a, [], c, d, e, f, g); + return Za.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 = Na.call(this, a, c, d, f, this.h), f ? e ? V.call(this.index, this.result) : this.result : this; + return this.result = $a.call(this, a, c, e, f, this.h), f ? d ? X.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } - return f ? this.resolve(c, d, e) : this; + return f ? this.resolve(c, e, d) : this; } -function Na(a, b, c, d, e) { - const f = [], g = A(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); +function $a(a, b, c, e, d) { + const f = [], g = G(); + let k = 0; + for (let h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); for (let m = 0, n; m < l.length; m++) { if (n = l[m]) { - for (let p = 0, r; p < n.length; p++) { - r = n[p], g[r] = g[r] ? 2 : 1; + for (let r = 0, q; r < n.length; r++) { + q = n[r], g[q] = g[q] ? 2 : 1; } } } } } - for (let k = 0, l, m = 0; k < h; k++) { - for (let n = 0, p; n < a.length; n++) { - if (p = a[n]) { - if (l = p[k]) { - for (let r = 0, q; r < l.length; r++) { - if (q = l[r], 1 === g[q]) { + for (let h = 0, l, m = 0; h < k; h++) { + for (let n = 0, r; n < a.length; n++) { + if (r = a[n]) { + if (l = r[h]) { + for (let q = 0, t; q < l.length; q++) { + if (t = l[q], 1 === g[t]) { if (c) { c--; } else { - if (d) { - if (f.push(q), f.length === b) { + if (e) { + if (f.push(t), f.length === b) { return f; } } else { - const t = k + (n ? e : 0); - f[t] || (f[t] = []); - f[t].push(q); + const u = h + (n ? d : 0); + f[u] || (f[u] = []); + f[u].push(t); if (++m === b) { return f; } @@ -1145,45 +1145,45 @@ function Na(a, b, c, d, e) { } return f; } -;W.prototype.not = function() { - const {O:a, P:b, limit:c, offset:d, enrich:e, resolve:f, suggest:g} = Ja(this, "not", arguments); - return Oa.call(this, a, b, c, d, e, f, g); +;Y.prototype.not = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Wa(this, "not", arguments); + return ab.call(this, a, b, c, e, d, f, g); }; -function Oa(a, b, c, d, e, f, g) { +function ab(a, b, c, e, d, f, g) { if (b.length) { - const h = this; - return Promise.all(b).then(function(k) { + const k = this; + return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Oa.call(h, a, [], c, d, e, f, g); + return ab.call(k, a, [], c, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Pa.call(this, a, c, d, f); + this.result = bb.call(this, a, c, e, f); } else if (f) { - return this.resolve(c, d, e); + return this.resolve(c, e, d); } - return f ? e ? V.call(this.index, this.result) : this.result : this; + return f ? d ? X.call(this.index, this.result) : this.result : this; } -function Pa(a, b, c, d) { - const e = []; +function bb(a, b, c, e) { + const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { + for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (c) { c--; } else { - if (d) { - if (e.push(l), e.length === b) { - return e; + if (e) { + if (d.push(l), d.length === b) { + return d; } } else { - if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { - return e; + if (d[f] || (d[f] = []), d[f].push(l), ++k === b) { + return d; } } } @@ -1191,11 +1191,11 @@ function Pa(a, b, c, d) { } } } - return e; + return d; } -;function W(a) { - if (!this || this.constructor !== W) { - return new W(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; @@ -1204,17 +1204,17 @@ function Pa(a, b, c, d) { this.result = a || []; this.h = 0; } -W.prototype.limit = function(a) { +Y.prototype.limit = function(a) { if (this.result.length) { const b = []; - for (let c = 0, d; c < this.result.length; c++) { - if (d = this.result[c]) { - if (d.length <= a) { - if (b[c] = d, a -= d.length, !a) { + for (let c = 0, e; c < this.result.length; c++) { + if (e = this.result[c]) { + if (e.length <= a) { + if (b[c] = e, a -= e.length, !a) { break; } } else { - b[c] = d.slice(0, a); + b[c] = e.slice(0, a); break; } } @@ -1223,382 +1223,561 @@ W.prototype.limit = function(a) { } return this; }; -W.prototype.offset = function(a) { +Y.prototype.offset = function(a) { if (this.result.length) { const b = []; - for (let c = 0, d; c < this.result.length; c++) { - if (d = this.result[c]) { - d.length <= a ? a -= d.length : (b[c] = d.slice(a), a = 0); + for (let c = 0, e; c < this.result.length; c++) { + if (e = this.result[c]) { + e.length <= a ? a -= e.length : (b[c] = e.slice(a), a = 0); } } this.result = b; } return this; }; -W.prototype.boost = function(a) { +Y.prototype.boost = function(a) { this.h += a; return this; }; -W.prototype.resolve = function(a, b, c) { - const d = this.result, e = this.index; +Y.prototype.resolve = function(a, b, c) { + const e = this.result, d = this.index; this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ia.call(e, d, a || 100, b, c)) : d; + return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Va.call(d, e, a || 100, b, c)) : e; }; -A(); -U.prototype.search = function(a, b, c, d) { +G(); +function cb(a, b, c, e, d) { + let f, g, k; + "string" === typeof d ? (f = d, d = "") : f = d.template; + if (!f) { + throw Error('No template pattern was specified by the search option "highlight"'); + } + g = f.indexOf("$1"); + if (-1 === g) { + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); + } + k = f.substring(g + 2); + g = f.substring(0, g); + let h = d && d.boundary, l = !d || !1 !== d.clip, m = d && d.merge && k && g && new RegExp(k + " " + g, "g"); + d = d && d.ellipsis; + var n = 0; + if ("object" === typeof d) { + var r = d.template; + n = r.length - 2; + d = d.pattern; + } + "string" !== typeof d && (d = !1 === d ? "" : "..."); + n && (d = r.replace("$1", d)); + r = d.length - n; + let q, t; + "object" === typeof h && (q = h.before, 0 === q && (q = -1), t = h.after, 0 === t && (t = -1), h = h.total || 9e5); + n = new Map(); + for (let Ka = 0, ba, gb, na; Ka < b.length; Ka++) { + let oa; + if (e) { + oa = b, na = e; + } else { + var u = b[Ka]; + na = u.field; + if (!na) { + continue; + } + oa = u.result; + } + gb = c.get(na); + ba = gb.encoder; + u = n.get(ba); + "string" !== typeof u && (u = ba.encode(a), n.set(ba, u)); + for (let ua = 0; ua < oa.length; ua++) { + var p = oa[ua].doc; + if (!p) { + continue; + } + p = ea(p, na); + if (!p) { + continue; + } + var z = p.trim().split(/\s+/); + if (!z.length) { + continue; + } + p = ""; + var x = []; + let va = []; + var J = -1, B = -1, y = 0; + for (var A = 0; A < z.length; A++) { + var D = z[A], E = ba.encode(D); + E = 1 < E.length ? E.join(" ") : E[0]; + let w; + if (E && D) { + var C = D.length, H = (ba.split ? D.replace(ba.split, "") : D).length - E.length, M = "", W = 0; + for (var ca = 0; ca < u.length; ca++) { + var Q = u[ca]; + if (Q) { + var K = Q.length; + K += H; + W && K <= W || (Q = E.indexOf(Q), -1 < Q && (M = (Q ? D.substring(0, Q) : "") + g + D.substring(Q, Q + K) + k + (Q + K < C ? D.substring(Q + K) : ""), W = K, w = !0)); + } + } + M && (h && (0 > J && (J = p.length + (p ? 1 : 0)), B = p.length + (p ? 1 : 0) + M.length, y += C, va.push(x.length), x.push({match:M})), p += (p ? " " : "") + M); + } + if (!w) { + D = z[A], p += (p ? " " : "") + D, h && x.push({text:D}); + } else if (h && y >= h) { + break; + } + } + y = va.length * (f.length - 2); + if (q || t || h && p.length - y > h) { + if (y = h + y - 2 * r, A = B - J, 0 < q && (A += q), 0 < t && (A += t), A <= y) { + z = q ? J - (0 < q ? q : 0) : J - ((y - A) / 2 | 0), x = t ? B + (0 < t ? t : 0) : z + y, l || (0 < z && " " !== p.charAt(z) && " " !== p.charAt(z - 1) && (z = p.indexOf(" ", z), 0 > z && (z = 0)), x < p.length && " " !== p.charAt(x - 1) && " " !== p.charAt(x) && (x = p.lastIndexOf(" ", x), x < B ? x = B : ++x)), p = (z ? d : "") + p.substring(z, x) + (x < p.length ? d : ""); + } else { + B = []; + J = {}; + y = {}; + A = {}; + D = {}; + E = {}; + M = H = C = 0; + for (ca = W = 1;;) { + var S = void 0; + for (let w = 0, I; w < va.length; w++) { + I = va[w]; + if (M) { + if (H !== M) { + if (A[w + 1]) { + continue; + } + I += M; + if (J[I]) { + C -= r; + y[w + 1] = 1; + A[w + 1] = 1; + continue; + } + if (I >= x.length - 1) { + if (I >= x.length) { + A[w + 1] = 1; + I >= z.length && (y[w + 1] = 1); + continue; + } + C -= r; + } + p = x[I].text; + if (K = t && E[w]) { + if (0 < K) { + if (p.length > K) { + if (A[w + 1] = 1, l) { + p = p.substring(0, K); + } else { + continue; + } + } + (K -= p.length) || (K = -1); + E[w] = K; + } else { + A[w + 1] = 1; + continue; + } + } + if (C + p.length + 1 <= h) { + p = " " + p, B[w] += p; + } else if (l) { + S = h - C - 1, 0 < S && (p = " " + p.substring(0, S), B[w] += p), A[w + 1] = 1; + } else { + A[w + 1] = 1; + continue; + } + } else { + if (A[w]) { + continue; + } + I -= H; + if (J[I]) { + C -= r; + A[w] = 1; + y[w] = 1; + continue; + } + if (0 >= I) { + if (0 > I) { + A[w] = 1; + y[w] = 1; + continue; + } + C -= r; + } + p = x[I].text; + if (K = q && D[w]) { + if (0 < K) { + if (p.length > K) { + if (A[w] = 1, l) { + p = p.substring(p.length - K); + } else { + continue; + } + } + (K -= p.length) || (K = -1); + D[w] = K; + } else { + A[w] = 1; + continue; + } + } + if (C + p.length + 1 <= h) { + p += " ", B[w] = p + B[w]; + } else if (l) { + S = p.length + 1 - (h - C), 0 <= S && S < p.length && (p = p.substring(S) + " ", B[w] = p + B[w]), A[w] = 1; + } else { + A[w] = 1; + continue; + } + } + } else { + p = x[I].match; + q && (D[w] = q); + t && (E[w] = t); + w && C++; + let La; + I ? !w && r && (C += r) : (y[w] = 1, A[w] = 1); + I >= z.length - 1 ? La = 1 : I < x.length - 1 && x[I + 1].match ? La = 1 : r && (C += r); + C -= f.length - 2; + if (!w || C + p.length <= h) { + B[w] = p; + } else { + S = W = ca = y[w] = 0; + break; + } + La && (y[w + 1] = 1, A[w + 1] = 1); + } + C += p.length; + S = J[I] = 1; + } + if (S) { + H === M ? M++ : H++; + } else { + H === M ? W = 0 : ca = 0; + if (!W && !ca) { + break; + } + W ? (H++, M = H) : M++; + } + } + p = ""; + for (let w = 0, I; w < B.length; w++) { + I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], p += I; + } + d && !y[B.length] && (p += d); + } + } + m && (p = p.replace(m, " ")); + oa[ua].highlight = p; + } + if (e) { + break; + } + } + return b; +} +;Pa.prototype.search = function(a, b, c, e) { c || (!b && aa(a) ? (c = a, a = "") : aa(b) && (c = b, b = 0)); - let e = []; + let d = []; var f = []; let g; - var h; let k; - let l, m; - let n = 0; - var p = !0; + let h, l; + let m = 0; + var n = !0; let r; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; g = c.pluck; k = c.merge; - l = g || c.field || (l = c.index) && (l.index ? null : l); - m = this.tag && c.tag; + h = g || c.field || (h = c.index) && (h.index ? null : h); + l = this.tag && c.tag; var q = c.suggest; - p = !1 !== c.resolve; - if (!p && !g) { - if (l = l || this.field) { - D(l) ? g = l : (l.constructor === Array && 1 === l.length && (l = l[0]), g = l.field || l.index); + n = !1 !== c.resolve; + if (!n && !g) { + if (h = h || this.field) { + L(h) ? g = h : (h.constructor === Array && 1 === h.length && (h = h[0]), g = h.field || h.index); } if (!g) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - this.store && c.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - r = (h = this.store && c.enrich && p) && c.highlight; + this.store && c.enrich && !n && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var t = (r = n && this.store && c.highlight) || n && this.store && c.enrich; b = c.limit || b; - var t = c.offset || 0; + var u = c.offset || 0; b || (b = 100); - if (m && (!this.db || !d)) { - m.constructor !== Array && (m = [m]); - var v = []; - for (let B = 0, y; B < m.length; B++) { - y = m[B]; - if (D(y)) { + if (l && (!this.db || !e)) { + l.constructor !== Array && (l = [l]); + var p = []; + for (let B = 0, y; B < l.length; B++) { + y = l[B]; + if (L(y)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (y.field && y.tag) { - var w = y.tag; - if (w.constructor === Array) { - for (var x = 0; x < w.length; x++) { - v.push(y.field, w[x]); + var z = y.tag; + if (z.constructor === Array) { + for (var x = 0; x < z.length; x++) { + p.push(y.field, z[x]); } } else { - v.push(y.field, w); + p.push(y.field, z); } } else { - w = Object.keys(y); - for (let C = 0, M, E; C < w.length; C++) { - if (M = w[C], E = y[M], E.constructor === Array) { + z = Object.keys(y); + for (let A = 0, D, E; A < z.length; A++) { + if (D = z[A], E = y[D], E.constructor === Array) { for (x = 0; x < E.length; x++) { - v.push(M, E[x]); + p.push(D, E[x]); } } else { - v.push(M, E); + p.push(D, E); } } } } - if (!v.length) { + if (!p.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - m = v; + l = p; if (!a) { - p = []; - if (v.length) { - for (f = 0; f < v.length; f += 2) { + n = []; + if (p.length) { + for (f = 0; f < p.length; f += 2) { if (this.db) { - q = this.index.get(v[f]); + q = this.index.get(p[f]); if (!q) { - console.warn("Tag '" + v[f] + ":" + v[f + 1] + "' will be skipped because there is no field '" + v[f] + "'."); + console.warn("Tag '" + p[f] + ":" + p[f + 1] + "' will be skipped because there is no field '" + p[f] + "'."); continue; } - p.push(q = q.db.tag(v[f + 1], b, t, h)); + n.push(q = q.db.tag(p[f + 1], b, u, t)); } else { - q = Qa.call(this, v[f], v[f + 1], b, t, h); + q = db.call(this, p[f], p[f + 1], b, u, t); } - e.push({field:v[f], tag:v[f + 1], result:q}); + d.push({field:p[f], tag:p[f + 1], result:q}); } } - return p.length ? Promise.all(p).then(function(B) { + return n.length ? Promise.all(n).then(function(B) { for (let y = 0; y < B.length; y++) { - e[y].result = B[y]; + d[y].result = B[y]; } - return e; - }) : e; + return d; + }) : d; } } - l && l.constructor !== Array && (l = [l]); + h && h.constructor !== Array && (h = [h]); } - l || (l = this.field); - v = !d && (this.worker || this.db) && []; - let F; - for (let B = 0, y, C, M; B < l.length; B++) { - C = l[B]; + h || (h = this.field); + p = !e && (this.worker || this.db) && []; + let J; + for (let B = 0, y, A, D; B < h.length; B++) { + A = h[B]; if (this.db && this.tag && !this.F[B]) { continue; } let E; - D(C) || (E = C, C = E.field, a = E.query || a, b = E.limit || b, t = E.offset || t, q = E.suggest || q, h = this.store && (E.enrich || h)); - if (d) { - y = d[B]; + L(A) || (E = A, A = E.field, a = E.query || a, b = E.limit || b, u = E.offset || u, q = E.suggest || q, r = (t = this.store && (E.enrich || t)) && (c.highlight || r)); + if (e) { + y = e[B]; } else { - if (w = E || c, x = this.index.get(C), m && (this.db && (w.tag = m, F = x.db.support_tag_search, w.field = l), F || (w.enrich = !1)), v) { - v[B] = x.search(a, b, w); - w && h && (w.enrich = h); + if (z = E || c, x = this.index.get(A), l && (this.db && (z.tag = l, J = x.db.support_tag_search, z.field = h), J || (z.enrich = !1)), p) { + p[B] = x.search(a, b, z); + z && t && (z.enrich = t); continue; } else { - y = x.search(a, b, w), w && h && (w.enrich = h); + y = x.search(a, b, z), z && t && (z.enrich = t); } } - M = y && (p ? y.length : y.result.length); - if (m && M) { - w = []; + D = y && (n ? y.length : y.result.length); + if (l && D) { + z = []; x = 0; - if (this.db && d) { - if (!F) { - for (let J = l.length; J < d.length; J++) { - let K = d[J]; - if (K && K.length) { - x++, w.push(K); + if (this.db && e) { + if (!J) { + for (let C = h.length; C < e.length; C++) { + let H = e[C]; + if (H && H.length) { + x++, z.push(H); } else if (!q) { - return p ? e : new W(e); + return n ? d : new Y(d); } } } } else { - for (let J = 0, K, rb; J < m.length; J += 2) { - K = this.tag.get(m[J]); - if (!K) { - if (console.warn("Tag '" + m[J] + ":" + m[J + 1] + "' will be skipped because there is no field '" + m[J] + "'."), q) { + for (let C = 0, H, M; C < l.length; C += 2) { + H = this.tag.get(l[C]); + if (!H) { + if (console.warn("Tag '" + l[C] + ":" + l[C + 1] + "' will be skipped because there is no field '" + l[C] + "'."), q) { continue; } else { - return p ? e : new W(e); + return n ? d : new Y(d); } } - if (rb = (K = K && K.get(m[J + 1])) && K.length) { - x++, w.push(K); + if (M = (H = H && H.get(l[C + 1])) && H.length) { + x++, z.push(H); } else if (!q) { - return p ? e : new W(e); + return n ? d : new Y(d); } } } if (x) { - y = Ha(y, w, p); - M = y.length; - if (!M && !q) { - return p ? y : new W(y); + y = Ua(y, z, n); + D = y.length; + if (!D && !q) { + return n ? y : new Y(y); } x--; } } - if (M) { - f[n] = C, e.push(y), n++; - } else if (1 === l.length) { - return p ? e : new W(e); + if (D) { + f[m] = A, d.push(y), m++; + } else if (1 === h.length) { + return n ? d : new Y(d); } } - if (v) { - if (this.db && m && m.length && !F) { - for (h = 0; h < m.length; h += 2) { - f = this.index.get(m[h]); + if (p) { + if (this.db && l && l.length && !J) { + for (t = 0; t < l.length; t += 2) { + f = this.index.get(l[t]); if (!f) { - if (console.warn("Tag '" + m[h] + ":" + m[h + 1] + "' was not found because there is no field '" + m[h] + "'."), q) { + if (console.warn("Tag '" + l[t] + ":" + l[t + 1] + "' was not found because there is no field '" + l[t] + "'."), q) { continue; } else { - return p ? e : new W(e); + return n ? d : new Y(d); } } - v.push(f.db.tag(m[h + 1], b, t, !1)); + p.push(f.db.tag(l[t + 1], b, u, !1)); } } const B = this; - return Promise.all(v).then(function(y) { + return Promise.all(p).then(function(y) { return y.length ? B.search(a, b, c, y) : y; }); } - if (!n) { - return p ? e : new W(e); + if (!m) { + return n ? d : new Y(d); } - if (g && (!h || !this.store)) { - return e[0]; + if (g && (!t || !this.store)) { + return d[0]; } - v = []; - for (t = 0; t < f.length; t++) { - q = e[t]; - h && q.length && "undefined" === typeof q[0].doc && (this.db ? v.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = V.call(this, q)); + p = []; + for (u = 0; u < f.length; u++) { + q = d[u]; + t && q.length && "undefined" === typeof q[0].doc && (this.db ? p.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = X.call(this, q)); if (g) { - return p ? r ? Ra(a, q, this.index, g, r) : q : new W(q); + return n ? r ? cb(a, q, this.index, g, r) : q : new Y(q); } - e[t] = {field:f[t], result:q}; + d[u] = {field:f[u], result:q}; } - if (h && this.db && v.length) { + if (t && this.db && p.length) { const B = this; - return Promise.all(v).then(function(y) { - for (let C = 0; C < y.length; C++) { - e[C].result = y[C]; + return Promise.all(p).then(function(y) { + for (let A = 0; A < y.length; A++) { + d[A].result = y[A]; } - return k ? Sa(e) : r ? Ra(a, e, B.index, g, r) : e; + return k ? eb(d) : r ? cb(a, d, B.index, g, r) : d; }); } - return k ? Sa(e) : r ? Ra(a, e, this.index, g, r) : e; + return k ? eb(d) : r ? cb(a, d, this.index, g, r) : d; }; -function Ra(a, b, c, d, e) { - let f, g; - for (let k = 0, l, m, n; k < b.length; k++) { - let p; - if (d) { - p = b, n = d; - } else { - var h = b[k]; - n = h.field; - if (!n) { - continue; - } - p = h.result; - } - m = c.get(n); - l = m.encoder; - h = m.tokenize; - l !== f && (f = l, g = f.encode(a)); - for (let r = 0; r < p.length; r++) { - let q = "", t = ca(p[r].doc, n).split(/\s+/); - for (let v = 0, w, x; v < t.length; v++) { - w = t[v]; - x = l.encode(w); - x = 1 < x.length ? x.join(" ") : x[0]; - let F; - if (x && w) { - for (let B = 0, y; B < g.length; B++) { - if (y = g[B], "strict" === h) { - if (x === y) { - q += (q ? " " : "") + e.replace("$1", w); - F = !0; - break; - } - } else { - const C = x.indexOf(y); - if (-1 < C) { - q += (q ? " " : "") + w.substring(0, C) + e.replace("$1", w.substring(C, C + y.length)) + w.substring(C + y.length); - F = !0; - break; - } - } - } - } - F || (q += (q ? " " : "") + t[v]); - } - p[r].highlight = q; - } - if (d) { - break; +function eb(a) { + const b = [], c = G(); + for (let e = 0, d, f; e < a.length; e++) { + d = a[e]; + f = d.result; + for (let g = 0, k, h, l; g < f.length; g++) { + h = f[g], "object" !== typeof h && (h = {id:h}), k = h.id, (l = c[k]) ? l.push(d.field) : (h.field = c[k] = [d.field], b.push(h)); } } return b; } -function Sa(a) { - const b = [], c = A(); - for (let d = 0, e, f; d < a.length; d++) { - e = a[d]; - f = e.result; - for (let g = 0, h, k, l; g < f.length; g++) { - k = f[g], "object" !== typeof k && (k = {id:k}), h = k.id, (l = c[h]) ? l.push(e.field) : (k.field = c[h] = [e.field], b.push(k)); - } - } - return b; -} -function Qa(a, b, c, d, e) { +function db(a, b, c, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { - if (a > c || d) { - f = f.slice(d, d + c); + if ((a = (f = f && f.get(b)) && f.length - e) && 0 < a) { + if (a > c || e) { + f = f.slice(e, e + c); } - e && (f = V.call(this, f)); + d && (f = X.call(this, f)); return f; } } -function V(a) { +function X(a) { if (!this || !this.store) { return a; } const b = Array(a.length); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b[c] = {id:d, doc:this.store.get(d)}; + for (let c = 0, e; c < a.length; c++) { + e = a[c], b[c] = {id:e, doc:this.store.get(e)}; } return b; } -;function U(a) { - if (!this || this.constructor !== U) { - return new U(a); +;function Pa(a) { + if (!this || this.constructor !== Pa) { + return new Pa(a); } const b = a.document || a.doc || a; - let c, d; + let c, e; this.F = []; this.field = []; this.J = []; - this.key = (c = b.key || b.id) && Ta(c, this.J) || "id"; - (d = a.keystore || 0) && (this.keystore = d); + this.key = (c = b.key || b.id) && fb(c, this.J) || "id"; + (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; - this.reg = !this.fastupdate || a.worker || a.db ? d ? new T(d) : new Set() : d ? new S(d) : new Map(); + this.reg = !this.fastupdate || a.worker || a.db ? e ? new V(e) : new Set() : e ? new U(e) : new Map(); this.C = (c = b.store || null) && c && !0 !== c && []; - this.store = c && (d ? new S(d) : new Map()); - this.cache = (c = a.cache || null) && new X(c); + this.store = c && (e ? new U(e) : new Map()); + this.cache = (c = a.cache || null) && new hb(c); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = Ua.call(this, a, b); + this.index = ib.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { this.tag = new Map(); this.D = []; this.R = []; - for (let e = 0, f, g; e < c.length; e++) { - f = c[e]; + for (let d = 0, f, g; d < c.length; d++) { + f = c[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.D[e] = f.custom : (this.D[e] = Ta(g, this.J), f.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = f.filter)); - this.R[e] = g; + f.custom ? this.D[d] = f.custom : (this.D[d] = fb(g, this.J), f.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = f.filter)); + this.R[d] = g; this.tag.set(g, new Map()); } } } if (this.worker) { this.fastupdate = !1; - const e = []; + const d = []; for (const f of this.index.values()) { - f.then && e.push(f); + f.then && d.push(f); } - if (e.length) { + if (d.length) { const f = this; - return Promise.all(e).then(function(g) { - const h = new Map(); - let k = 0; + return Promise.all(d).then(function(g) { + const k = new Map(); + let h = 0; for (const m of f.index.entries()) { const n = m[0]; var l = m[1]; if (l.then) { - l = e[k].encoder || {}; - let p = h.get(l); - p || (p = l.encode ? l : new G(l), h.set(l, p)); - l = g[k]; - l.encoder = p; + l = d[h].encoder || {}; + let r = k.get(l); + r || (r = l.encode ? l : new ma(l), k.set(l, r)); + l = g[h]; + l.encoder = r; f.index.set(n, l); - k++; + h++; } } return f; @@ -1608,8 +1787,8 @@ function V(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -u = U.prototype; -u.mount = function(a) { +v = Pa.prototype; +v.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } @@ -1618,96 +1797,96 @@ u.mount = function(a) { for (let f = 0, g; f < this.R.length; f++) { g = this.R[f]; var c = void 0; - this.index.set(g, c = new N({}, this.reg)); + this.index.set(g, c = new P({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(g); c.tag = this.tag.get(g); } } c = []; - const d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let f = 0, g, h; f < b.length; f++) { - d.field = h = b[f]; - g = this.index.get(h); - const k = new a.constructor(a.id, d); - k.id = a.id; - c[f] = k.mount(g); + const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; + for (let f = 0, g, k; f < b.length; f++) { + e.field = k = b[f]; + g = this.index.get(k); + const h = new a.constructor(a.id, e); + h.id = a.id; + c[f] = h.mount(g); g.document = !0; f ? g.bypass = !0 : g.store = this.store; } - const e = this; + const d = this; return this.db = Promise.all(c).then(function() { - e.db = !0; + d.db = !0; }); }; -u.commit = async function(a, b) { +v.commit = async function(a, b) { const c = []; - for (const d of this.index.values()) { - c.push(d.commit(a, b)); + for (const e of this.index.values()) { + c.push(e.commit(a, b)); } await Promise.all(c); this.reg.clear(); }; -u.destroy = function() { +v.destroy = function() { const a = []; for (const b of this.index.values()) { a.push(b.destroy()); } return Promise.all(a); }; -function Ua(a, b) { +function ib(a, b) { const c = new Map(); - let d = b.index || b.field || b; - D(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e]; - D(f) || (g = f, f = f.field); + let e = b.index || b.field || b; + L(e) && (e = [e]); + for (let d = 0, f, g; d < e.length; d++) { + f = e[d]; + L(f) || (g = f, f = f.field); g = aa(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const h = new P(g); - h.encoder = g.encoder; - c.set(f, h); + const k = new Aa(g); + k.encoder = g.encoder; + c.set(f, k); } - this.worker || c.set(f, new N(g, this.reg)); - g.custom ? this.F[e] = g.custom : (this.F[e] = Ta(f, this.J), g.filter && ("string" === typeof this.F[e] && (this.F[e] = new String(this.F[e])), this.F[e].I = g.filter)); - this.field[e] = f; + this.worker || c.set(f, new P(g, this.reg)); + g.custom ? this.F[d] = g.custom : (this.F[d] = fb(f, this.J), g.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = g.filter)); + this.field[d] = f; } if (this.C) { a = b.store; - D(a) && (a = [a]); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.V = g) : (this.C[e] = Ta(g, this.J), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); + L(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] = fb(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 Ta(a, b) { +function fb(a, b) { const c = a.split(":"); - let d = 0; - for (let 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); + let e = 0; + for (let d = 0; d < c.length; d++) { + a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); } - d < c.length && (c.length = d); - return 1 < d ? c : c[0]; + e < c.length && (c.length = e); + return 1 < e ? c : c[0]; } -u.append = function(a, b) { +v.append = function(a, b) { return this.add(a, b, !0); }; -u.update = function(a, b) { +v.update = function(a, b) { return this.remove(a).add(a, b); }; -u.remove = function(a) { - aa(a) && (a = ca(a, this.key)); +v.remove = function(a) { + aa(a) && (a = ea(a, this.key)); for (var b of this.index.values()) { b.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { for (let c of this.tag.values()) { - for (let d of c) { - b = d[0]; - const e = d[1], f = e.indexOf(a); - -1 < f && (1 < e.length ? e.splice(f, 1) : c.delete(b)); + for (let e of c) { + b = e[0]; + const d = e[1], f = d.indexOf(a); + -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); } } } @@ -1717,7 +1896,7 @@ u.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -u.clear = function() { +v.clear = function() { const a = []; for (const b of this.index.values()) { const c = b.clear(); @@ -1732,185 +1911,185 @@ u.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -u.contain = function(a) { +v.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -u.cleanup = function() { +v.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -u.get = function(a) { +v.get = function(a) { return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { return b[0] && b[0].doc || null; }) : this.store.get(a) || null; }; -u.set = function(a, b) { - "object" === typeof a && (b = a, a = ca(b, this.key)); +v.set = function(a, b) { + "object" === typeof a && (b = a, a = ea(b, this.key)); this.store.set(a, b); return this; }; -u.searchCache = Va; -u.export = function(a, b, c = 0, d = 0) { +v.searchCache = jb; +v.export = function(a, b, c = 0, e = 0) { if (c < this.field.length) { const g = this.field[c]; - if ((b = this.index.get(g).export(a, g, c, d = 1)) && b.then) { - const h = this; + if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { + const k = this; return b.then(function() { - return h.export(a, g, c + 1); + return k.export(a, g, c + 1); }); } return this.export(a, g, c + 1); } - let e, f; - switch(d) { + let d, f; + switch(e) { case 0: - e = "reg"; - f = wa(this.reg); + d = "reg"; + f = Ga(this.reg); b = null; break; case 1: - e = "tag"; - f = this.tag && ua(this.tag, this.reg.size); + d = "tag"; + f = this.tag && Ea(this.tag, this.reg.size); b = null; break; case 2: - e = "doc"; - f = this.store && sa(this.store); + d = "doc"; + f = this.store && Ca(this.store); b = null; break; default: return; } - return ya.call(this, a, b, e, f, c, d); + return Ia.call(this, a, b, d, f, c, e); }; -u.import = function(a, b) { +v.import = function(a, b) { var c = a.split("."); "json" === c[c.length - 1] && c.pop(); - const d = 2 < c.length ? c[0] : ""; + const e = 2 < c.length ? c[0] : ""; c = 2 < c.length ? c[2] : c[1]; - if (this.worker && d) { - return this.index.get(d).import(a); + if (this.worker && e) { + return this.index.get(e).import(a); } if (b) { "string" === typeof b && (b = JSON.parse(b)); - if (d) { - return this.index.get(d).import(c, b); + if (e) { + return this.index.get(e).import(c, b); } switch(c) { case "reg": this.fastupdate = !1; - this.reg = xa(b, this.reg); - for (let e = 0, f; e < this.field.length; e++) { - f = this.index.get(this.field[e]), f.fastupdate = !1, f.reg = this.reg; + this.reg = Ha(b, this.reg); + for (let d = 0, f; d < this.field.length; d++) { + f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } if (this.worker) { b = []; - for (const e of this.index.values()) { - b.push(e.import(a)); + for (const d of this.index.values()) { + b.push(d.import(a)); } return Promise.all(b); } break; case "tag": - this.tag = va(b, this.tag); + this.tag = Fa(b, this.tag); break; case "doc": - this.store = ta(b, this.store); + this.store = Da(b, this.store); } } }; -la(U.prototype); -function Va(a, b, c) { - const d = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new X()); - let e = this.cache.get(d); - if (!e) { - e = this.search(a, b, c); - if (e.then) { +ra(Pa.prototype); +function jb(a, b, c) { + const e = ("object" === typeof a ? "" + a.query : a).toLowerCase(); + this.cache || (this.cache = new hb()); + let d = this.cache.get(e); + if (!d) { + d = this.search(a, b, c); + if (d.then) { const f = this; - e.then(function(g) { - f.cache.set(d, g); + d.then(function(g) { + f.cache.set(e, g); return g; }); } - this.cache.set(d, e); + this.cache.set(e, d); } - return e; + return d; } -function X(a) { +function hb(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -X.prototype.set = function(a, b) { +hb.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); }; -X.prototype.get = function(a) { +hb.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; }; -X.prototype.remove = function(a) { +hb.prototype.remove = function(a) { for (const b of this.cache) { const c = b[0]; b[1].includes(a) && this.cache.delete(c); } }; -X.prototype.clear = function() { +hb.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Wa = {normalize:!1, numeric:!1, dedupe:!1}; -const Xa = {}; -const Ya = 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 Za = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), $a = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const ab = {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 bb = {Exact:Wa, Default:Xa, Normalize:Xa, LatinBalance:{mapper:Ya}, LatinAdvanced:{mapper:Ya, matcher:Za, replacer:$a}, LatinExtra:{mapper:Ya, replacer:$a.concat([/(?!^)[aeo]/g, ""]), matcher:Za}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +const kb = {normalize:!1, numeric:!1, dedupe:!1}; +const lb = {}; +const mb = 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 nb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ob = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const pb = {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 qb = {Exact:kb, Default:lb, Normalize:lb, LatinBalance:{mapper:mb}, LatinAdvanced:{mapper:mb, matcher:nb, replacer:ob}, LatinExtra:{mapper:mb, replacer:ob.concat([/(?!^)[aeo]/g, ""]), matcher:nb}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let d = b.charAt(0), e = ab[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = ab[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + let e = b.charAt(0), d = pb[e]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = pb[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = d; + a[c] = e; } -}}, CJK:{split:""}, LatinExact:Wa, LatinDefault:Xa, LatinSimple:Xa}; -N.prototype.remove = function(a, b) { +}}, CJK:{split:""}, LatinExact:kb, LatinDefault:lb, LatinSimple:lb}; +P.prototype.remove = function(a, b) { const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { - for (let d = 0, e; d < c.length; d++) { - if (e = c[d]) { - if (2 > e.length) { - e.pop(); + for (let e = 0, d; e < c.length; e++) { + if (d = c[e]) { + if (2 > d.length) { + d.pop(); } else { - const f = e.indexOf(a); - f === c.length - 1 ? e.pop() : e.splice(f, 1); + const f = d.indexOf(a); + f === c.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - cb(this.map, a), this.depth && cb(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.T && db(this)); + this.db && (this.commit_task.push({del:a}), this.T && sb(this)); this.cache && this.cache.remove(a); return this; }; -function cb(a, b) { +function rb(a, b) { let c = 0; - var d = "undefined" === typeof b; + var e = "undefined" === typeof b; if (a.constructor === Array) { - for (let e = 0, f, g; e < a.length; e++) { - if ((f = a[e]) && f.length) { - if (d) { + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && f.length) { + if (e) { c++; } else { if (g = f.indexOf(b), 0 <= g) { - 1 < f.length ? (f.splice(g, 1), c++) : delete a[e]; + 1 < f.length ? (f.splice(g, 1), c++) : delete a[d]; break; } else { c++; @@ -1919,67 +2098,67 @@ function cb(a, b) { } } } else { - for (let e of a.entries()) { - d = e[0]; - const f = cb(e[1], b); - f ? c += f : a.delete(d); + for (let d of a.entries()) { + e = d[0]; + const f = rb(d[1], b); + f ? c += f : a.delete(e); } } return c; } -;const eb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -N.prototype.add = function(a, b, c, d) { +;const tb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +P.prototype.add = function(a, b, c, e) { if (b && (a || 0 === a)) { - if (!d && !c && this.reg.has(a)) { + if (!e && !c && this.reg.has(a)) { return this.update(a, b); } - d = this.depth; - b = this.encoder.encode(b, !d); + e = this.depth; + b = this.encoder.encode(b, !e); const l = b.length; if (l) { - const m = A(), n = A(), p = this.resolution; - for (let r = 0; r < l; r++) { - let q = b[this.rtl ? l - 1 - r : r]; - var e = q.length; - if (e && (d || !n[q])) { - var f = this.score ? this.score(b, q, r, null, 0) : fb(p, l, r), g = ""; + const m = G(), n = G(), r = this.resolution; + for (let q = 0; q < l; q++) { + let t = b[this.rtl ? l - 1 - q : q]; + var d = t.length; + if (d && (e || !n[t])) { + var f = this.score ? this.score(b, t, q, null, 0) : ub(r, l, q), g = ""; switch(this.tokenize) { case "full": - if (2 < e) { - for (let t = 0, v; t < e; t++) { - for (f = e; f > t; f--) { - g = q.substring(t, f); - v = this.rtl ? e - 1 - t : t; - var h = this.score ? this.score(b, q, r, g, v) : fb(p, l, r, e, v); - gb(this, n, g, h, a, c); + if (2 < d) { + for (let u = 0, p; u < d; u++) { + for (f = d; f > u; f--) { + g = t.substring(u, f); + p = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(b, t, q, g, p) : ub(r, l, q, d, p); + vb(this, n, g, k, a, c); } } break; } case "bidirectional": case "reverse": - if (1 < e) { - for (h = e - 1; 0 < h; h--) { - g = q[this.rtl ? e - 1 - h : h] + g; - var k = this.score ? this.score(b, q, r, g, h) : fb(p, l, r, e, h); - gb(this, n, g, k, a, c); + if (1 < d) { + for (k = d - 1; 0 < k; k--) { + g = t[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(b, t, q, g, k) : ub(r, l, q, d, k); + vb(this, n, g, h, a, c); } g = ""; } case "forward": - if (1 < e) { - for (h = 0; h < e; h++) { - g += q[this.rtl ? e - 1 - h : h], gb(this, n, g, f, a, c); + if (1 < d) { + for (k = 0; k < d; k++) { + g += t[this.rtl ? d - 1 - k : k], vb(this, n, g, f, a, c); } break; } default: - if (gb(this, n, q, f, a, c), d && 1 < l && r < l - 1) { - for (e = A(), g = this.U, f = q, h = Math.min(d + 1, this.rtl ? r + 1 : l - r), e[f] = 1, k = 1; k < h; k++) { - if ((q = b[this.rtl ? l - 1 - r - k : r + k]) && !e[q]) { - e[q] = 1; - const t = this.score ? this.score(b, f, r, q, k - 1) : fb(g + (l / 2 > g ? 0 : 1), l, r, h - 1, k - 1), v = this.bidirectional && q > f; - gb(this, m, v ? f : q, t, a, c, v ? q : f); + if (vb(this, n, t, f, a, c), e && 1 < l && q < l - 1) { + for (d = G(), g = this.U, f = t, k = Math.min(e + 1, this.rtl ? q + 1 : l - q), d[f] = 1, h = 1; h < k; h++) { + if ((t = b[this.rtl ? l - 1 - q - h : q + h]) && !d[t]) { + d[t] = 1; + const u = this.score ? this.score(b, f, q, t, h - 1) : ub(g + (l / 2 > g ? 0 : 1), l, q, k - 1, h - 1), p = this.bidirectional && t > f; + vb(this, m, p ? f : t, u, a, c, p ? t : f); } } } @@ -1991,154 +2170,154 @@ N.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && db(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && sb(this)); return this; }; -function gb(a, b, c, d, e, f, g) { - let h = g ? a.ctx : a.map, k; - if (!b[c] || g && !(k = b[c])[g]) { - if (g ? (b = k || (b[c] = A()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { - if (h.length === 2 ** 31 - 1) { - b = new R(h); +function vb(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] = G()), 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 T(k); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(h) && (l[l.indexOf(h)] = b); + l.includes(k) && (l[l.indexOf(k)] = b); } } - k[d] = h = b; + h[e] = k = b; } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + k.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } } -function fb(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; +function ub(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; } -;N.prototype.search = function(a, b, c) { +;P.prototype.search = function(a, b, c) { c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); - let d = [], e, f, g, h = 0, k, l, m, n, p; - c ? (a = c.query || a, b = c.limit || b, h = c.offset || 0, f = c.context, g = c.suggest, p = (k = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : k = this.resolve; + let e = [], d, f, g, k = 0, h, l, m, n, r; + c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, r = (h = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : h = this.resolve; f = this.depth && !1 !== f; - let r = this.encoder.encode(a, !f); - e = r.length; - b = b || (k ? 100 : 0); - if (1 === e) { - return hb.call(this, r[0], "", b, h, k, p, l); + let q = this.encoder.encode(a, !f); + d = q.length; + b = b || (h ? 100 : 0); + if (1 === d) { + return wb.call(this, q[0], "", b, k, h, r, l); } - if (2 === e && f && !g) { - return hb.call(this, r[1], r[0], b, h, k, p, l); + if (2 === d && f && !g) { + return wb.call(this, q[1], q[0], b, k, h, r, l); } - let q = A(), t = 0, v; - f && (v = r[0], t = 1); - n || 0 === n || (n = v ? this.U : this.resolution); + let t = G(), u = 0, p; + f && (p = q[0], u = 1); + n || 0 === n || (n = p ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, r, b, h, g, k, p, l), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, q, b, k, g, h, r, l), !1 !== a)) { return a; } - const w = this; + const z = this; return async function() { - for (let x, F; t < e; t++) { - if ((F = r[t]) && !q[F]) { - q[F] = 1; - x = await ib(w, F, v, 0, 0, !1, !1); - if (x = jb(x, d, g, n)) { - d = x; + for (let x, J; u < d; u++) { + if ((J = q[u]) && !t[J]) { + t[J] = 1; + x = await xb(z, J, p, 0, 0, !1, !1); + if (x = yb(x, e, g, n)) { + e = x; break; } - v && (g && x && d.length || (v = F)); + p && (g && x && e.length || (p = J)); } - g && v && t === e - 1 && !d.length && (n = w.resolution, v = "", t = -1, q = A()); + g && p && u === d - 1 && !e.length && (n = z.resolution, p = "", u = -1, t = G()); } - return kb(d, n, b, h, g, m, k); + return zb(e, n, b, k, g, m, h); }(); } - for (let w, x; t < e; t++) { - if ((x = r[t]) && !q[x]) { - q[x] = 1; - w = ib(this, x, v, 0, 0, !1, !1); - if (w = jb(w, d, g, n)) { - d = w; + for (let z, x; u < d; u++) { + if ((x = q[u]) && !t[x]) { + t[x] = 1; + z = xb(this, x, p, 0, 0, !1, !1); + if (z = yb(z, e, g, n)) { + e = z; break; } - v && (g && w && d.length || (v = x)); + p && (g && z && e.length || (p = x)); } - g && v && t === e - 1 && !d.length && (n = this.resolution, v = "", t = -1, q = A()); + g && p && u === d - 1 && !e.length && (n = this.resolution, p = "", u = -1, t = G()); } - return kb(d, n, b, h, g, m, k); + return zb(e, n, b, k, g, m, h); }; -function kb(a, b, c, d, e, f, g) { - let h = a.length, k = a; - if (1 < h) { - k = Fa(a, b, c, d, e, f, g); - } else if (1 === h) { - return g ? Ia.call(null, a[0], c, d) : new W(a[0]); +function zb(a, b, c, e, d, f, g) { + let k = a.length, h = a; + if (1 < k) { + h = Sa(a, b, c, e, d, f, g); + } else if (1 === k) { + return g ? Va.call(null, a[0], c, e) : new Y(a[0]); } - return g ? k : new W(k); + return g ? h : new Y(h); } -function hb(a, b, c, d, e, f, g) { - a = ib(this, a, b, c, d, e, f, g); - return this.db ? a.then(function(h) { - return e ? h || [] : new W(h); - }) : a && a.length ? e ? Ia.call(this, a, c, d) : new W(a) : e ? [] : new W(); +function wb(a, b, c, e, d, f, g) { + a = xb(this, a, b, c, e, d, f, g); + return this.db ? a.then(function(k) { + return d ? k || [] : new Y(k); + }) : a && a.length ? d ? Va.call(this, a, c, e) : new Y(a) : d ? [] : new Y(); } -function jb(a, b, c, d) { - let e = []; +function yb(a, b, c, e) { + let d = []; if (a && a.length) { - if (a.length <= d) { + if (a.length <= e) { b.push(a); return; } - for (let f = 0, g; f < d; f++) { + for (let f = 0, g; f < e; f++) { if (g = a[f]) { - e[f] = g; + d[f] = g; } } - if (e.length) { - b.push(e); + if (d.length) { + b.push(d); return; } } if (!c) { - return e; + return d; } } -function ib(a, b, c, d, e, f, g, h) { - let k; - c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); +function xb(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) { - return a.db.get(b, c, d, e, f, g, h); + 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; } -;function N(a, b) { - if (!this || this.constructor !== N) { - return new N(a); +;function P(a, b) { + if (!this || this.constructor !== P) { + return new P(a); } if (a) { - var c = D(a) ? a : a.preset; - c && (eb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, eb[c], a)); + var c = L(a) ? a : a.preset; + c && (tb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, tb[c], a)); } else { a = {}; } c = a.context; - const d = !0 === c ? {depth:1} : c || {}, e = D(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || {}; - this.encoder = e.encode ? e : "object" === typeof e ? new G(e) : {encode:e}; + const e = !0 === c ? {depth:1} : c || {}, d = L(a.encoder) ? qb[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : "object" === typeof d ? new ma(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = c = (c = a.tokenize) && "default" !== c && "exact" !== c && c || "strict"; - this.depth = "strict" === c && d.depth || 0; - this.bidirectional = !1 !== d.bidirectional; + this.depth = "strict" === c && e.depth || 0; + this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; - d && d.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); + e && e.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); (c = a.keystore || 0) && (this.keystore = c); - this.map = c ? new S(c) : new Map(); - this.ctx = c ? new S(c) : new Map(); - this.reg = b || (this.fastupdate ? c ? new S(c) : new Map() : c ? new T(c) : new Set()); - this.U = d.resolution || 3; - this.rtl = e.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new X(c); + 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.U = e.resolution || 3; + this.rtl = d.rtl || a.rtl || !1; + this.cache = (c = a.cache || null) && new hb(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); @@ -2148,26 +2327,26 @@ function ib(a, b, c, d, e, f, g, h) { this.commit_timer = null; this.priority = a.priority || 4; } -u = N.prototype; -u.mount = function(a) { +v = P.prototype; +v.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -u.commit = function(a, b) { +v.commit = function(a, b) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.commit(this, a, b); }; -u.destroy = function() { +v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function db(a) { +function sb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 1)); } -u.clear = function() { +v.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -2175,90 +2354,90 @@ u.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -u.append = function(a, b) { +v.append = function(a, b) { return this.add(a, b, !0); }; -u.contain = function(a) { +v.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -u.update = function(a, b) { - const c = this, d = this.remove(a); - return d && d.then ? d.then(() => c.add(a, b)) : this.add(a, b); +v.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); }; -u.cleanup = function() { +v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - cb(this.map); - this.depth && cb(this.ctx); + rb(this.map); + this.depth && rb(this.ctx); return this; }; -u.searchCache = Va; -u.export = function(a, b, c = 0, d = 0) { - let e, f; - switch(d) { +v.searchCache = jb; +v.export = function(a, b, c = 0, e = 0) { + let d, f; + switch(e) { case 0: - e = "reg"; - f = wa(this.reg); + d = "reg"; + f = Ga(this.reg); break; case 1: - e = "cfg"; + d = "cfg"; f = null; break; case 2: - e = "map"; - f = sa(this.map, this.reg.size); + d = "map"; + f = Ca(this.map, this.reg.size); break; case 3: - e = "ctx"; - f = ua(this.ctx, this.reg.size); + d = "ctx"; + f = Ea(this.ctx, this.reg.size); break; default: return; } - return ya.call(this, a, b, e, f, c, d); + return Ia.call(this, a, b, d, f, c, e); }; -u.import = function(a, b) { +v.import = function(a, b) { if (b) { switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = xa(b, this.reg); + this.reg = Ha(b, this.reg); break; case "map": - this.map = ta(b, this.map); + this.map = Da(b, this.map); break; case "ctx": - this.ctx = va(b, this.ctx); + this.ctx = Fa(b, this.ctx); } } }; -u.serialize = function(a = !0) { - let b = "", c = "", d = ""; +v.serialize = function(a = !0) { + let b = "", c = "", e = ""; if (this.reg.size) { let f; - for (var e of this.reg.keys()) { - f || (f = typeof e), b += (b ? "," : "") + ("string" === f ? '"' + e + '"' : e); + for (var d of this.reg.keys()) { + f || (f = typeof d), b += (b ? "," : "") + ("string" === f ? '"' + d + '"' : d); } b = "index.reg=new Set([" + b + "]);"; - c = za(this.map, f); + c = Ja(this.map, f); c = "index.map=new Map([" + c + "]);"; for (const g of this.ctx.entries()) { - e = g[0]; - let h = za(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + e + '",' + h + "]"; - d += (d ? "," : "") + h; + d = g[0]; + let k = Ja(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } - d = "index.ctx=new Map([" + d + "]);"; + e = "index.ctx=new Map([" + e + "]);"; } - return a ? "function inject(index){" + b + c + d + "}" : b + c + d; + return a ? "function inject(index){" + b + c + e + "}" : b + c + e; }; -la(N.prototype); -const lb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), mb = ["map", "ctx", "tag", "reg", "cfg"], Y = A(); -function nb(a, b = {}) { - if (!this || this.constructor !== nb) { - return new nb(a, b); +ra(P.prototype); +const Ab = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Bb = ["map", "ctx", "tag", "reg", "cfg"], Cb = G(); +function Db(a, b = {}) { + if (!this || this.constructor !== Db) { + return new Db(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2269,29 +2448,29 @@ function nb(a, b = {}) { this.db = null; this.h = {}; } -u = nb.prototype; -u.mount = function(a) { +v = Db.prototype; +v.mount = function(a) { if (a.index) { return a.mount(this); } a.db = this; return this.open(); }; -u.open = function() { +v.open = function() { if (this.db) { return this.db; } let a = this; navigator.storage && navigator.storage.persist(); - Y[a.id] || (Y[a.id] = []); - Y[a.id].push(a.field); - const b = lb.open(a.id, 1); + Cb[a.id] || (Cb[a.id] = []); + Cb[a.id].push(a.field); + const b = Ab.open(a.id, 1); b.onupgradeneeded = function() { const c = a.db = this.result; - for (let d = 0, e; d < mb.length; d++) { - e = mb[d]; - for (let f = 0, g; f < Y[a.id].length; f++) { - g = Y[a.id][f], c.objectStoreNames.contains(e + ("reg" !== e ? g ? ":" + g : "" : "")) || c.createObjectStore(e + ("reg" !== e ? g ? ":" + g : "" : "")); + for (let e = 0, d; e < Bb.length; e++) { + d = Bb[e]; + for (let f = 0, g; f < Cb[a.id].length; f++) { + g = Cb[a.id][f], c.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || c.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } } }; @@ -2302,20 +2481,20 @@ u.open = function() { }; }); }; -u.close = function() { +v.close = function() { this.db && this.db.close(); this.db = null; }; -u.destroy = function() { - const a = lb.deleteDatabase(this.id); +v.destroy = function() { + const a = Ab.deleteDatabase(this.id); return Z(a); }; -u.clear = function() { +v.clear = function() { const a = []; - for (let c = 0, d; c < mb.length; c++) { - d = mb[c]; - for (let e = 0, f; e < Y[this.id].length; e++) { - f = Y[this.id][e], a.push(d + ("reg" !== d ? f ? ":" + f : "" : "")); + for (let c = 0, e; c < Bb.length; c++) { + e = Bb[c]; + for (let d = 0, f; d < Cb[this.id].length; d++) { + f = Cb[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } } const b = this.db.transaction(a, "readwrite"); @@ -2324,42 +2503,42 @@ u.clear = function() { } return Z(b); }; -u.get = function(a, b, c = 0, d = 0, e = !0, f = !1) { +v.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); const g = this; - return Z(a).then(function(h) { - let k = []; - if (!h || !h.length) { - return k; + return Z(a).then(function(k) { + let h = []; + if (!k || !k.length) { + return h; } - if (e) { - if (!c && !d && 1 === h.length) { - return h[0]; + if (d) { + if (!c && !e && 1 === k.length) { + return k[0]; } - for (let l = 0, m; l < h.length; l++) { - if ((m = h[l]) && m.length) { - if (d >= m.length) { - d -= m.length; + for (let l = 0, m; l < k.length; l++) { + if ((m = k[l]) && m.length) { + if (e >= m.length) { + e -= m.length; continue; } - const n = c ? d + Math.min(m.length - d, c) : m.length; - for (let p = d; p < n; p++) { - k.push(m[p]); + const n = c ? e + Math.min(m.length - e, c) : m.length; + for (let r = e; r < n; r++) { + h.push(m[r]); } - d = 0; - if (k.length === c) { + e = 0; + if (h.length === c) { break; } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; -u.tag = function(a, b = 0, c = 0, d = !1) { +v.tag = function(a, b = 0, c = 0, e = !1) { a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); - const e = this; + const d = this; return Z(a).then(function(f) { if (!f || !f.length || c >= f.length) { return []; @@ -2368,107 +2547,107 @@ u.tag = function(a, b = 0, c = 0, d = !1) { return f; } f = f.slice(c, c + b); - return d ? e.enrich(f) : f; + return e ? d.enrich(f) : f; }); }; -u.enrich = function(a) { +v.enrich = function(a) { "object" !== typeof a && (a = [a]); const b = this.db.transaction("reg", "readonly").objectStore("reg"), c = []; - for (let d = 0; d < a.length; d++) { - c[d] = Z(b.get(a[d])); + for (let e = 0; e < a.length; e++) { + c[e] = Z(b.get(a[e])); } - return Promise.all(c).then(function(d) { - for (let e = 0; e < d.length; e++) { - d[e] = {id:a[e], doc:d[e] ? JSON.parse(d[e]) : null}; + return Promise.all(c).then(function(e) { + for (let d = 0; d < e.length; d++) { + e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null}; } - return d; + return e; }); }; -u.has = function(a) { +v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); return Z(a).then(function(b) { return !!b; }); }; -u.search = null; -u.info = function() { +v.search = null; +v.info = function() { }; -u.transaction = function(a, b, c) { +v.transaction = function(a, b, c) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; - let d = this.h[a + ":" + b]; - if (d) { - return c.call(this, d); + let e = this.h[a + ":" + b]; + if (e) { + return c.call(this, e); } - let e = this.db.transaction(a, b); - this.h[a + ":" + b] = d = e.objectStore(a); - const f = c.call(this, d); + let d = this.db.transaction(a, b); + this.h[a + ":" + b] = e = d.objectStore(a); + const f = c.call(this, e); this.h[a + ":" + b] = null; - return Z(e).finally(function() { - e = d = null; + return Z(d).finally(function() { + d = e = null; return f; }); }; -u.commit = async function(a, b, c) { +v.commit = async function(a, b, c) { if (b) { await this.clear(), a.commit_task = []; } else { - let d = a.commit_task; + let e = a.commit_task; a.commit_task = []; - for (let e = 0, f; e < d.length; e++) { - if (f = d[e], f.clear) { + for (let d = 0, f; d < e.length; d++) { + if (f = e[d], f.clear) { await this.clear(); b = !0; break; } else { - d[e] = f.del; + e[d] = f.del; } } - b || (c || (d = d.concat(ba(a.reg))), d.length && await this.remove(d)); + b || (c || (e = e.concat(da(a.reg))), e.length && await this.remove(e)); } - a.reg.size && (await this.transaction("map", "readwrite", function(d) { - for (const e of a.map) { - const f = e[0], g = e[1]; - g.length && (b ? d.put(g, f) : d.get(f).onsuccess = function() { - let h = this.result; - var k; - if (h && h.length) { - const l = Math.max(h.length, g.length); - for (let m = 0, n, p; m < l; m++) { - if ((p = g[m]) && p.length) { - if ((n = h[m]) && n.length) { - for (k = 0; k < p.length; k++) { - n.push(p[k]); + a.reg.size && (await this.transaction("map", "readwrite", function(e) { + for (const d of a.map) { + const f = d[0], g = d[1]; + g.length && (b ? e.put(g, f) : e.get(f).onsuccess = function() { + let k = this.result; + var h; + if (k && k.length) { + const l = Math.max(k.length, g.length); + for (let m = 0, n, r; m < l; m++) { + if ((r = g[m]) && r.length) { + if ((n = k[m]) && n.length) { + for (h = 0; h < r.length; h++) { + n.push(r[h]); } } else { - h[m] = p; + k[m] = r; } - k = 1; + h = 1; } } } else { - h = g, k = 1; + k = g, h = 1; } - k && d.put(h, f); + h && e.put(k, f); }); } - }), await this.transaction("ctx", "readwrite", function(d) { - for (const e of a.ctx) { - const f = e[0], g = e[1]; - for (const h of g) { - const k = h[0], l = h[1]; - l.length && (b ? d.put(l, f + ":" + k) : d.get(f + ":" + k).onsuccess = function() { + }), await this.transaction("ctx", "readwrite", function(e) { + for (const d of a.ctx) { + const f = d[0], g = d[1]; + for (const k of g) { + const h = k[0], l = k[1]; + l.length && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { let m = this.result; var n; if (m && m.length) { - const p = Math.max(m.length, l.length); - for (let r = 0, q, t; r < p; r++) { - if ((t = l[r]) && t.length) { - if ((q = m[r]) && q.length) { - for (n = 0; n < t.length; n++) { - q.push(t[n]); + const r = Math.max(m.length, l.length); + for (let q = 0, t, u; q < r; q++) { + if ((u = l[q]) && u.length) { + if ((t = m[q]) && t.length) { + for (n = 0; n < u.length; n++) { + t.push(u[n]); } } else { - m[r] = t; + m[q] = u; } n = 1; } @@ -2476,70 +2655,70 @@ u.commit = async function(a, b, c) { } else { m = l, n = 1; } - n && d.put(m, f + ":" + k); + n && e.put(m, f + ":" + h); }); } } - }), a.store ? await this.transaction("reg", "readwrite", function(d) { - for (const e of a.store) { - const f = e[0], g = e[1]; - d.put("object" === typeof g ? JSON.stringify(g) : 1, f); + }), a.store ? await this.transaction("reg", "readwrite", function(e) { + for (const d of a.store) { + const f = d[0], g = d[1]; + e.put("object" === typeof g ? JSON.stringify(g) : 1, f); } - }) : a.bypass || await this.transaction("reg", "readwrite", function(d) { - for (const e of a.reg.keys()) { - d.put(1, e); + }) : a.bypass || await this.transaction("reg", "readwrite", function(e) { + for (const d of a.reg.keys()) { + e.put(1, d); } - }), a.tag && await this.transaction("tag", "readwrite", function(d) { - for (const e of a.tag) { - const f = e[0], g = e[1]; - g.length && (d.get(f).onsuccess = function() { - let h = this.result; - h = h && h.length ? h.concat(g) : g; - d.put(h, f); + }), a.tag && await this.transaction("tag", "readwrite", function(e) { + for (const d of a.tag) { + const f = d[0], g = d[1]; + g.length && (e.get(f).onsuccess = function() { + let k = this.result; + k = k && k.length ? k.concat(g) : g; + e.put(k, f); }); } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function ob(a, b, c) { - const d = a.value; - let e, f = 0; - for (let g = 0, h; g < d.length; g++) { - if (h = c ? d : d[g]) { - for (let k = 0, l, m; k < b.length; k++) { - if (m = b[k], l = h.indexOf(m), 0 <= l) { - if (e = 1, 1 < h.length) { - h.splice(l, 1); +function Eb(a, b, c) { + const e = a.value; + let d, f = 0; + for (let g = 0, k; g < e.length; g++) { + if (k = c ? e : e[g]) { + for (let h = 0, l, m; h < b.length; h++) { + if (m = b[h], l = k.indexOf(m), 0 <= l) { + if (d = 1, 1 < k.length) { + k.splice(l, 1); } else { - d[g] = []; + e[g] = []; break; } } } - f += h.length; + f += k.length; } if (c) { break; } } - f ? e && a.update(d) : a.delete(); + f ? d && a.update(e) : a.delete(); a.continue(); } -u.remove = function(a) { +v.remove = function(a) { "object" !== typeof a && (a = [a]); return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && ob(c, a); + c && Eb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && ob(c, a); + c && Eb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && ob(c, a, !0); + c && Eb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2548,19 +2727,19 @@ u.remove = function(a) { })]); }; function Z(a, b) { - return new Promise((c, d) => { + return new Promise((c, e) => { a.onsuccess = a.oncomplete = function() { b && b(this.result); b = null; c(this.result); }; - a.onerror = a.onblocked = d; + a.onerror = a.onblocked = e; a = null; }); } -;const pb = {Index:N, Charset:bb, Encoder:G, Document:U, Worker:P, Resolver:W, IndexedDB:nb, Language:{}}, qb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; -let sb; -(sb = qb.define) && sb.amd ? sb([], function() { - return pb; -}) : "object" === typeof qb.exports ? qb.exports = pb : qb.FlexSearch = pb; +;const Fb = {Index:P, Charset:qb, Encoder:ma, Document:Pa, Worker:Aa, Resolver:Y, IndexedDB:Db, Language:{}}, Gb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let Hb; +(Hb = Gb.define) && Hb.amd ? Hb([], function() { + return Fb; +}) : "object" === typeof Gb.exports ? Gb.exports = Fb : Gb.FlexSearch = Fb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index 768e9dd..04cb8c5 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,94 +1,99 @@ /**! - * FlexSearch.js v0.8.158 (Bundle) + * FlexSearch.js v0.8.160 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var u;function z(a,b,c){const d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===e?b:a}function A(){return Object.create(null)}function D(a){return"string"===typeof a} -function G(a){return"object"===typeof a}function aa(a){const b=[];for(const c of a.keys())b.push(c);return b}function ba(a,b){if(D(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; -this.numeric=z(a.numeric,d)}else{try{this.split=z(this.split,da)}catch(e){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:z(c&&new Set(c),null,this.filter);this.dedupe=z(a.dedupe,!0,this.dedupe);this.matcher=z((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=z((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=z((c=a.stemmer)&&new Map(c), -null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,1024,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=c=z(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const e of this.matcher.keys())this.h+=(this.h?"|":"")+e;if(this.stemmer)for(const e of this.stemmer.keys())this.A+= -(this.A?"|":"")+e;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&I(this);return this};u.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&I(this);return this}; -u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&I(this);return this}; -u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&I(this);return this}; -u.encode=function(a,b){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(I,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ia?a.normalize("NFKD").replace(ia,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(e[m])continue;e[m]=1}else{if(f===m)continue;f=m}if(c)d.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var k=this.G.get(m);if(k||""===k){k&&d.push(k);continue}}else this.H=setTimeout(I,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ -this.A+")$"));let p;for(;p!==m&&2this.stemmer.get(r))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(p)));if(m&&this.replacer)for(k=0;m&&kthis.S&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==n)if(b){if(e[m])continue;e[m]=1}else{if(g===m)continue;g=m}d.push(m)}}}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.K&&(this.B.set(a,d),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return d};function I(a){a.H=null;a.B.clear();a.G.clear()};let K,ja;async function ka(a){a=a.data;var b=a.task;const c=a.id;let d=a.args;switch(b){case "init":ja=a.options||{};(b=a.factory)?(Function("return "+b)()(self),K=new self.FlexSearch.Index(ja),delete self.FlexSearch):K=new M(ja);postMessage({id:c});break;default:let e;"export"===b&&(d[1]?(d[0]=ja.export,d[2]=0,d[3]=1):d=null);"import"===b?d[0]&&(a=await ja.import.call(K,d[0]),K.import(d[0],a)):(e=d&&K[b].apply(K,d))&&e.then&&(e=await e);postMessage("search"===b?{id:c,msg:e}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} -function ma(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const e=this[a].apply(this,b);c=e.then?e:new Promise(f=>f(e));d&&c.then(d);return c}};let N=0; -function P(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=A();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++N]=function(){k(e);1E9=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} -function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e= -[];for(let n=0,p;nd)d-=p.length;else{if(p.length>c||d)p=p.slice(d,c+d),c-=p.length,d&&(d-=p.length);e.push(p);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?V.call(this,a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!e.length&&h>=b)return d?V.call(this,g):g;e.push(g);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=Ga(a,c,d,!1,this.h),d=0));return f?this.resolve(c,d,e):this};W.prototype.and=function(){let a=this.result.length,b,c,d,e;if(!a){const f=arguments[0];f&&(a=!!f.suggest,e=f.resolve,b=f.limit,c=f.offset,d=f.enrich&&e)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,m,n)}return e?this.resolve(b,c,d):this}; -function La(a,b,c,d,e,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,d,g,this.h,f),f?e?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,d,e):this};W.prototype.xor=function(){const {O:a,P:b,limit:c,offset:d,enrich:e,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,d,e,f,g)}; -function Ma(a,b,c,d,e,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,d,f,this.h),f?e?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,d,e):this} -function Na(a,b,c,d,e){const f=[],g=A();let h=0;for(let k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -X.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};X.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:!1,numeric:!1,dedupe:!1};const Xa={};const Ya=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 Za=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),$a=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ab={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 bb={Exact:Wa,Default:Xa,Normalize:Xa,LatinBalance:{mapper:Ya},LatinAdvanced:{mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;ce.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else cb(this.map,a),this.depth&&cb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&db(this));this.cache&&this.cache.remove(a);return this}; -function cb(a,b){let c=0;var d="undefined"===typeof b;if(a.constructor===Array)for(let e=0,f,g;et;f--){g=q.substring(t,f);v=this.rtl?e-1-t:t;var h=this.score?this.score(b,q,r,g,v):fb(p, -l,r,e,v);gb(this,n,g,h,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,r,h-1,k-1),v=this.bidirectional&&q>f;gb(this,m,v?f:q,t,a,c,v?q:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&db(this));return this}; -function gb(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=A()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function fb(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,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function M(a,b){if(!this||this.constructor!==M)return new M(a);if(a){var c=D(a)?a:a.preset;c&&(a=Object.assign({},eb[c],a))}else a={};c=a.context;const d=!0===c?{depth:1}:c||{},e=D(a.encoder)?bb[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new H(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&d.depth||0;this.bidirectional=!1!==d.bidirectional;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new S(c):new Map;this.ctx=c?new S(c):new Map;this.reg=b||(this.fastupdate?c?new S(c):new Map:c?new T(c):new Set);this.U=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new X(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.T=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}u=M.prototype; -u.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};u.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};u.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function db(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} -u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};u.update=function(a,b){const c=this,d=this.remove(a);return d&&d.then?d.then(()=>c.add(a,b)):this.add(a,b)}; -u.cleanup=function(){if(!this.fastupdate)return this;cb(this.map);this.depth&&cb(this.ctx);return this};u.searchCache=Va;u.export=function(a,b,c=0,d=0){let e,f;switch(d){case 0:e="reg";f=wa(this.reg);break;case 1:e="cfg";f=null;break;case 2:e="map";f=sa(this.map,this.reg.size);break;case 3:e="ctx";f=ua(this.ctx,this.reg.size);break;default:return}return ya.call(this,a,b,e,f,c,d)}; -u.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let p=d;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=d;a=null})};const pb={Index:M,Charset:bb,Encoder:H,Document:U,Worker:P,Resolver:W,IndexedDB:nb,Language:{}},rb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let sb;(sb=rb.define)&&sb.amd?sb([],function(){return pb}):"object"===typeof rb.exports?rb.exports=pb:rb.FlexSearch=pb;}(this||self)); +(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var v;function F(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(k){return a(c(k))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function G(){return Object.create(null)}function L(a){return"string"===typeof a} +function ca(a){return"object"===typeof a}function da(a){const b=[];for(const c of a.keys())b.push(c);return b}function ea(a,b){if(L(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; +this.numeric=F(a.numeric,e)}else{try{this.split=F(this.split,ha)}catch(d){this.split=/\s+/}this.numeric=F(a.numeric,F(this.numeric,!0))}this.prepare=F(a.prepare,null,this.prepare);this.finalize=F(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:F(c&&new Set(c),null,this.filter);this.dedupe=F(a.dedupe,!0,this.dedupe);this.matcher=F((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=F((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=F((c=a.stemmer)&&new Map(c), +null,this.stemmer);this.replacer=F(a.replacer,null,this.replacer);this.minlength=F(a.minlength,1,this.minlength);this.maxlength=F(a.maxlength,1024,this.maxlength);this.rtl=F(a.rtl,!1,this.rtl);if(this.cache=c=F(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};v.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&N(this);return this};v.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&N(this);return this}; +v.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&N(this);return this}; +v.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&N(this);return this}; +v.encode=function(a,b){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(N,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=la?a.normalize("NFKD").replace(la,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(c)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var h=this.G.get(m);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(N,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ +this.A+")$"));let r;for(;r!==m&&2this.stemmer.get(q))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(r)));if(m&&this.replacer)for(h=0;m&&hthis.S&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==n)if(b){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.B.set(a,e),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return e};function N(a){a.H=null;a.B.clear();a.G.clear()};let pa,qa;async function ra(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":qa=a.options||{};(b=a.factory)?(Function("return "+b)()(self),pa=new self.FlexSearch.Index(qa),delete self.FlexSearch):pa=new O(qa);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=qa.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await qa.import.call(pa,e[0]),pa.import(e[0],a)):(d=e&&pa[b].apply(pa,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function sa(a){ta.call(a,"add");ta.call(a,"append");ta.call(a,"search");ta.call(a,"update");ta.call(a,"remove")}let wa,xa,ya;function za(){wa=ya=0} +function ta(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]);wa?ya||(ya=Date.now()-xa>=this.priority*this.priority*3):(wa=setTimeout(za,0),xa=Date.now());if(ya){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 Aa=0; +function Ba(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=G();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++Aa]=function(){h(d);1E9=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 R(a){if(!this||this.constructor!==R)return new R(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,r;ne)e-=r.length;else{if(r.length>c||e)r=r.slice(e,c+e),c-=r.length,e&&(e-=r.length);d.push(r);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?X.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?X.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ta(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};Y.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}=Wa(this,"and",arguments);return Ya.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; +function Ya(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=fa(a))return this.result=Sa(a,b,c,e,g,this.h,f),f?d?X.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};Y.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Wa(this,"xor",arguments);return Za.call(this,a,b,c,e,d,f,g)}; +function Za(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=$a.call(this,a,c,e,f,this.h),f?d?X.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function $a(a,b,c,e,d){const f=[],g=G();let k=0;for(let h=0,l;hJ&&(J=p.length+(p?1:0)),B=p.length+(p?1:0)+M.length,z+=E,va.push(x.length),x.push({match:M})),p+=(p?" ":"")+M)}if(!w)C=y[A],p+=(p?" ":"")+C,h&&x.push({text:C});else if(h&&z>=h)break}z=va.length*(f.length-2);if(q||t||h&&p.length-z>h)if(z=h+z-2*r,A=B-J, +0y&&(y=0)),x=x.length-1){if(I>= +x.length){A[w+1]=1;I>=y.length&&(z[w+1]=1);continue}E-=r}p=x[I].text;if(K=t&&D[w])if(0K)if(A[w+1]=1,l)p=p.substring(0,K);else continue;(K-=p.length)||(K=-1);D[w]=K}else{A[w+1]=1;continue}if(E+p.length+1<=h)p=" "+p,B[w]+=p;else if(l)S=h-E-1,0=I){if(0>I){A[w]=1;z[w]=1;continue}E-=r}p=x[I].text;if(K=q&&C[w])if(0K)if(A[w]=1,l)p=p.substring(p.length- +K);else continue;(K-=p.length)||(K=-1);C[w]=K}else{A[w]=1;continue}if(E+p.length+1<=h)p+=" ",B[w]=p+B[w];else if(l)S=p.length+1-(h-E),0<=S&&S=y.length-1?La=1:Ic||e)a=a.slice(e,e+c);d&&(a=X.call(this,a));return a}} +function X(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)}; +hb.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};hb.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};hb.prototype.clear=function(){this.cache.clear();this.h=""};const kb={normalize:!1,numeric:!1,dedupe:!1};const lb={};const mb=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 nb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ob=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const pb={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 qb={Exact:kb,Default:lb,Normalize:lb,LatinBalance:{mapper:mb},LatinAdvanced:{mapper:mb,matcher:nb,replacer:ob},LatinExtra:{mapper:mb,replacer:ob.concat([/(?!^)[aeo]/g,""]),matcher:nb},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cd.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,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.T&&sb(this));this.cache&&this.cache.remove(a);return this}; +function rb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;du;f--){g=t.substring(u,f);p=this.rtl?d-1-u:u;var k=this.score?this.score(b,t,q,g,p):ub(r, +l,q,d,p);vb(this,n,g,k,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,q,k-1,h-1),p=this.bidirectional&&t>f;vb(this,m,p?f:t,u,a,c,p?t:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&sb(this));return this}; +function vb(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]=G()),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 R(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 ub(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};function O(a,b){if(!this||this.constructor!==O)return new O(a);if(a){var c=L(a)?a:a.preset;c&&(a=Object.assign({},tb[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=L(a.encoder)?qb[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ma(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;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.U=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new hb(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.T=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}v=O.prototype; +v.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};v.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};v.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function sb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} +v.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};v.append=function(a,b){return this.add(a,b,!0)};v.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};v.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)}; +v.cleanup=function(){if(!this.fastupdate)return this;rb(this.map);this.depth&&rb(this.ctx);return this};v.searchCache=jb;v.export=function(a,b,c=0,e=0){let d,f;switch(e){case 0:d="reg";f=Ha(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=Da(this.map,this.reg.size);break;case 3:d="ctx";f=Fa(this.ctx,this.reg.size);break;default:return}return Ja.call(this,a,b,d,f,c,e)}; +v.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let r=e;r=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +v.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};const Fb={Index:O,Charset:qb,Encoder:ma,Document:W,Worker:Ba,Resolver:Y,IndexedDB:Db,Language:{}},Gb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let Hb;(Hb=Gb.define)&&Hb.amd?Hb([],function(){return Fb}):"object"===typeof Gb.exports?Gb.exports=Fb:Gb.FlexSearch=Fb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index 88f54cc..c44b630 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,19 +1,19 @@ /**! - * FlexSearch.js v0.8.158 (Bundle/Module/Debug) + * FlexSearch.js v0.8.160 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u; -function z(a, b, c) { - const d = typeof c, e = typeof a; - if ("undefined" !== d) { - if ("undefined" !== e) { +var v; +function F(a, b, c) { + const e = typeof c, d = typeof a; + if ("undefined" !== e) { + if ("undefined" !== d) { if (c) { - if ("function" === e && d === e) { - return function(h) { - return a(c(h)); + if ("function" === d && e === d) { + return function(k) { + return a(c(k)); }; } b = a.constructor; @@ -41,26 +41,26 @@ function z(a, b, c) { } return c; } - return "undefined" === e ? b : a; + return "undefined" === d ? b : a; } -function A() { +function G() { return Object.create(null); } -function D(a) { +function L(a) { return "string" === typeof a; } function aa(a) { return "object" === typeof a; } -function ba(a) { +function da(a) { const b = []; for (const c of a.keys()) { b.push(c); } return b; } -function ca(a, b) { - if (D(b)) { +function ea(a, b) { + if (L(b)) { a = a[b]; } else { for (let c = 0; a && c < b.length; c++) { @@ -69,17 +69,17 @@ function ca(a, b) { } return a; } -function da(a) { +function fa(a) { let b = 0; - for (let c = 0, d; c < a.length; c++) { - (d = a[c]) && b < d.length && (b = d.length); + for (let c = 0, e; c < a.length; c++) { + (e = a[c]) && b < e.length && (b = e.length); } return b; } -;const ea = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = /[\u0300-\u036f]/g; -function G(a = {}) { - if (!this || this.constructor !== G) { - return new G(...arguments); +;const ha = /[^\p{L}\p{N}]+/u, ia = /(\d{3})/g, ja = /(\D)(\d{3})/g, ka = /(\d{3})(\D)/g, la = /[\u0300-\u036f]/g; +function ma(a = {}) { + if (!this || this.constructor !== ma) { + return new ma(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -89,53 +89,53 @@ function G(a = {}) { this.assign(a); } } -u = G.prototype; -u.assign = function(a) { - this.normalize = z(a.normalize, !0, this.normalize); - let b = a.include, c = b || a.exclude || a.split, d; +v = ma.prototype; +v.assign = function(a) { + this.normalize = F(a.normalize, !0, this.normalize); + let b = a.include, c = b || a.exclude || a.split, e; if (c || "" === c) { if ("object" === typeof c && c.constructor !== RegExp) { - let e = ""; - d = !b; - b || (e += "\\p{Z}"); - c.letter && (e += "\\p{L}"); - c.number && (e += "\\p{N}", d = !!b); - c.symbol && (e += "\\p{S}"); - c.punctuation && (e += "\\p{P}"); - c.control && (e += "\\p{C}"); + let d = ""; + e = !b; + b || (d += "\\p{Z}"); + c.letter && (d += "\\p{L}"); + c.number && (d += "\\p{N}", e = !!b); + c.symbol && (d += "\\p{S}"); + c.punctuation && (d += "\\p{P}"); + c.control && (d += "\\p{C}"); if (c = c.char) { - e += "object" === typeof c ? c.join("") : c; + d += "object" === typeof c ? c.join("") : c; } try { - this.split = new RegExp("[" + (b ? "^" : "") + e + "]+", "u"); + this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); } catch (f) { 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 { - this.split = c, d = !1 === c || 2 > "a1a".split(c).length; + this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } - this.numeric = z(a.numeric, d); + this.numeric = F(a.numeric, e); } else { try { - this.split = z(this.split, ea); - } catch (e) { + this.split = F(this.split, ha); + } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = z(a.numeric, z(this.numeric, !0)); + this.numeric = F(a.numeric, F(this.numeric, !0)); } - this.prepare = z(a.prepare, null, this.prepare); - this.finalize = z(a.finalize, null, this.finalize); + this.prepare = F(a.prepare, null, this.prepare); + this.finalize = F(a.finalize, null, this.finalize); c = a.filter; - this.filter = "function" === typeof c ? c : z(c && new Set(c), null, this.filter); - this.dedupe = z(a.dedupe, !0, this.dedupe); - this.matcher = z((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = z((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = z((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = z(a.replacer, null, this.replacer); - this.minlength = z(a.minlength, 1, this.minlength); - this.maxlength = z(a.maxlength, 1024, this.maxlength); - this.rtl = z(a.rtl, !1, this.rtl); - if (this.cache = c = z(a.cache, !0, this.cache)) { + this.filter = "function" === typeof c ? c : F(c && new Set(c), null, this.filter); + this.dedupe = F(a.dedupe, !0, this.dedupe); + this.matcher = F((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = F((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = F((c = a.stemmer) && new Map(c), null, this.stemmer); + this.replacer = F(a.replacer, null, this.replacer); + this.minlength = F(a.minlength, 1, this.minlength); + this.maxlength = F(a.maxlength, 1024, this.maxlength); + this.rtl = F(a.rtl, !1, this.rtl); + if (this.cache = c = F(a.cache, !0, this.cache)) { this.H = null, this.S = "number" === typeof c ? c : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; @@ -143,31 +143,31 @@ u.assign = function(a) { this.A = ""; this.N = null; if (this.matcher) { - for (const e of this.matcher.keys()) { - this.h += (this.h ? "|" : "") + e; + for (const d of this.matcher.keys()) { + this.h += (this.h ? "|" : "") + d; } } if (this.stemmer) { - for (const e of this.stemmer.keys()) { - this.A += (this.A ? "|" : "") + e; + for (const d of this.stemmer.keys()) { + this.A += (this.A ? "|" : "") + d; } } return this; }; -u.addStemmer = function(a, b) { +v.addStemmer = function(a, b) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, b); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && H(this); + this.cache && N(this); return this; }; -u.addFilter = function(a) { +v.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && H(this); + this.cache && N(this); return this; }; -u.addMapper = function(a, b) { +v.addMapper = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -176,10 +176,10 @@ u.addMapper = function(a, b) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, b); - this.cache && H(this); + this.cache && N(this); return this; }; -u.addMatcher = function(a, b) { +v.addMatcher = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -190,40 +190,40 @@ u.addMatcher = function(a, b) { this.matcher.set(a, b); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && H(this); + this.cache && N(this); return this; }; -u.addReplacer = function(a, b) { +v.addReplacer = function(a, b) { if ("string" === typeof a) { return this.addMatcher(a, b); } this.replacer || (this.replacer = []); this.replacer.push(a, b); - this.cache && H(this); + this.cache && N(this); return this; }; -u.encode = function(a, b) { +v.encode = function(a, b) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.B.has(a)) { return this.B.get(a); } } else { - this.H = setTimeout(H, 50, this); + this.H = setTimeout(N, 50, this); } } - this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = la ? a.normalize("NFKD").replace(la, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(ja, "$1 $2").replace(ka, "$1 $2").replace(ia, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let d = [], e = A(), f, g, h = this.split || "" === this.split ? a.split(this.split) : [a]; - for (let l = 0, m, n; l < h.length; l++) { - if ((m = n = h[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { + let e = [], d = G(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; + for (let l = 0, m, n; l < k.length; l++) { + if ((m = n = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (b) { - if (e[m]) { + if (d[m]) { continue; } - e[m] = 1; + d[m] = 1; } else { if (f === m) { continue; @@ -231,48 +231,48 @@ u.encode = function(a, b) { f = m; } if (c) { - d.push(m); + e.push(m); } else { if (!this.filter || ("function" === typeof this.filter ? this.filter(m) : !this.filter.has(m))) { if (this.cache && m.length <= this.L) { if (this.H) { - var k = this.G.get(m); - if (k || "" === k) { - k && d.push(k); + var h = this.G.get(m); + if (h || "" === h) { + h && e.push(h); continue; } } else { - this.H = setTimeout(H, 50, this); + this.H = setTimeout(N, 50, this); } } if (this.stemmer) { this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")); - let p; - for (; p !== m && 2 < m.length;) { - p = m, m = m.replace(this.N, r => this.stemmer.get(r)); + let r; + for (; r !== m && 2 < m.length;) { + r = m, m = m.replace(this.N, q => this.stemmer.get(q)); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { - k = ""; - for (let p = 0, r = "", q, t; p < m.length; p++) { - q = m.charAt(p), q === r && this.dedupe || ((t = this.mapper && this.mapper.get(q)) || "" === t ? t === r && this.dedupe || !(r = t) || (k += t) : k += r = q); + h = ""; + for (let r = 0, q = "", t, u; r < m.length; r++) { + t = m.charAt(r), t === q && this.dedupe || ((u = this.mapper && this.mapper.get(t)) || "" === u ? u === q && this.dedupe || !(q = u) || (h += u) : h += q = t); } - m = k; + m = h; } - this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, p => this.matcher.get(p))); + this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, r => this.matcher.get(r))); if (m && this.replacer) { - for (k = 0; m && k < this.replacer.length; k += 2) { - m = m.replace(this.replacer[k], this.replacer[k + 1]); + for (h = 0; m && h < this.replacer.length; h += 2) { + m = m.replace(this.replacer[h], this.replacer[h + 1]); } } this.cache && n.length <= this.L && (this.G.set(n, m), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); if (m) { if (m !== n) { if (b) { - if (e[m]) { + if (d[m]) { continue; } - e[m] = 1; + d[m] = 1; } else { if (g === m) { continue; @@ -280,71 +280,71 @@ u.encode = function(a, b) { g = m; } } - d.push(m); + e.push(m); } } } } } - this.finalize && (d = this.finalize(d) || d); - this.cache && a.length <= this.K && (this.B.set(a, d), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); - return d; + this.finalize && (e = this.finalize(e) || e); + this.cache && a.length <= this.K && (this.B.set(a, e), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); + return e; }; -function H(a) { +function N(a) { a.H = null; a.B.clear(); a.G.clear(); } -;let I, L; -async function ka(a) { +;let pa, O; +async function qa(a) { a = a.data; var b = a.task; const c = a.id; - let d = a.args; + let e = a.args; switch(b) { case "init": - L = a.options || {}; - (b = a.factory) ? (Function("return " + b)()(self), I = new self.FlexSearch.Index(L), delete self.FlexSearch) : I = new N(L); + O = a.options || {}; + (b = a.factory) ? (Function("return " + b)()(self), pa = new self.FlexSearch.Index(O), delete self.FlexSearch) : pa = new P(O); postMessage({id:c}); break; default: - let e; + let d; if ("export" === b) { - if (!L.export || "function" !== typeof L.export) { + if (!O.export || "function" !== typeof O.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - d[1] ? (d[0] = L.export, d[2] = 0, d[3] = 1) : d = null; + e[1] ? (e[0] = O.export, e[2] = 0, e[3] = 1) : e = null; } if ("import" === b) { - if (!L.import || "function" !== typeof L.import) { + if (!O.import || "function" !== typeof O.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - d[0] && (a = await L.import.call(I, d[0]), I.import(d[0], a)); + e[0] && (a = await O.import.call(pa, e[0]), pa.import(e[0], a)); } else { - (e = d && I[b].apply(I, d)) && e.then && (e = await e); + (d = e && pa[b].apply(pa, e)) && d.then && (d = await d); } - postMessage("search" === b ? {id:c, msg:e} : {id:c}); + postMessage("search" === b ? {id:c, msg:d} : {id:c}); } } -;function la(a) { - ma.call(a, "add"); - ma.call(a, "append"); - ma.call(a, "search"); - ma.call(a, "update"); - ma.call(a, "remove"); +;function ra(a) { + sa.call(a, "add"); + sa.call(a, "append"); + sa.call(a, "search"); + sa.call(a, "update"); + sa.call(a, "remove"); } -let na, oa, pa; -function qa() { - na = pa = 0; +let ta, wa, xa; +function ya() { + ta = xa = 0; } -function ma(a) { +function sa(a) { this[a + "Async"] = function() { const b = arguments; var c = b[b.length - 1]; - let d; - "function" === typeof c && (d = c, delete b[b.length - 1]); - na ? pa || (pa = Date.now() - oa >= this.priority * this.priority * 3) : (na = setTimeout(qa, 0), oa = Date.now()); - if (pa) { + let e; + "function" === typeof c && (e = c, delete b[b.length - 1]); + ta ? xa || (xa = Date.now() - wa >= this.priority * this.priority * 3) : (ta = setTimeout(ya, 0), wa = Date.now()); + if (xa) { const f = this; return new Promise(g => { setTimeout(function() { @@ -352,31 +352,31 @@ function ma(a) { }, 0); }); } - const e = this[a].apply(this, b); - c = e.then ? e : new Promise(f => f(e)); - d && c.then(d); + const d = this[a].apply(this, b); + c = d.then ? d : new Promise(f => f(d)); + e && c.then(e); return c; }; } -;let O = 0; -function P(a = {}) { +;let za = 0; +function Aa(a = {}) { function b(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && e.h[l]; - m && (m(k.msg), delete e.h[l]); + 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 = A(); + this.h = G(); if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { - e.h[++O] = function() { - k(e); - 1e9 < O && (O = 0); + return new Promise(function(h) { + d.h[++za] = function() { + h(d); + 1e9 < za && (za = 0); }; - e.worker.postMessage({id:O, task:"init", factory:c, options:a}); + d.worker.postMessage({id:za, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); @@ -384,298 +384,298 @@ function P(a = {}) { return this; } } - if (!this || this.constructor !== P) { - return new P(a); + if (!this || this.constructor !== Aa) { + return new Aa(a); } let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - const d = "undefined" === typeof window, e = this, f = ra(c, d, a.worker); + const e = "undefined" === typeof window, d = this, f = Ba(c, e, a.worker); return f.then ? f.then(function(g) { - return b.call(e, g); + return b.call(d, g); }) : b.call(this, f); } -Q("add"); -Q("append"); -Q("search"); -Q("update"); -Q("remove"); -Q("clear"); -Q("export"); -Q("import"); -la(P.prototype); -function Q(a) { - P.prototype[a] = function() { +R("add"); +R("append"); +R("search"); +R("update"); +R("remove"); +R("clear"); +R("export"); +R("import"); +ra(Aa.prototype); +function R(a) { + Aa.prototype[a] = function() { const b = this, c = [].slice.call(arguments); - var d = c[c.length - 1]; - let e; - "function" === typeof d && (e = d, c.pop()); - d = new Promise(function(f) { + var e = c[c.length - 1]; + let d; + "function" === typeof e && (d = e, c.pop()); + e = new Promise(function(f) { "export" === a && "function" === typeof c[0] && (c[0] = null); - b.h[++O] = f; - b.worker.postMessage({task:a, id:O, args:c}); + b.h[++za] = f; + b.worker.postMessage({task:a, id:za, args:c}); }); - return e ? (d.then(e), this) : d; + return d ? (e.then(d), this) : e; }; } -function ra(a, b, c) { - return b ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/worker/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("string" === typeof c ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ba(a, b, c) { + return b ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/worker/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=" + qa.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;function sa(a, b = 0) { - let c = [], d = []; +;function Ca(a, b = 0) { + let c = [], e = []; b && (b = 250000 / b * 5000 | 0); - for (const e of a.entries()) { - d.push(e), d.length === b && (c.push(d), d = []); + for (const d of a.entries()) { + e.push(d), e.length === b && (c.push(e), e = []); } - d.length && c.push(d); + e.length && c.push(e); return c; } -function ta(a, b) { +function Da(a, b) { b || (b = new Map()); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b.set(d[0], d[1]); + for (let c = 0, e; c < a.length; c++) { + e = a[c], b.set(e[0], e[1]); } return b; } -function ua(a, b = 0) { - let c = [], d = []; +function Ea(a, b = 0) { + let c = [], e = []; b && (b = 250000 / b * 1000 | 0); - for (const e of a.entries()) { - d.push([e[0], sa(e[1])[0]]), d.length === b && (c.push(d), d = []); + for (const d of a.entries()) { + e.push([d[0], Ca(d[1])[0]]), e.length === b && (c.push(e), e = []); } - d.length && c.push(d); + e.length && c.push(e); return c; } -function va(a, b) { +function Fa(a, b) { b || (b = new Map()); - for (let c = 0, d, e; c < a.length; c++) { - d = a[c], e = b.get(d[0]), b.set(d[0], ta(d[1], e)); + for (let c = 0, e, d; c < a.length; c++) { + e = a[c], d = b.get(e[0]), b.set(e[0], Da(e[1], d)); } return b; } -function wa(a) { +function Ga(a) { let b = [], c = []; - for (const d of a.keys()) { - c.push(d), 250000 === c.length && (b.push(c), c = []); + for (const e of a.keys()) { + c.push(e), 250000 === c.length && (b.push(c), c = []); } c.length && b.push(c); return b; } -function xa(a, b) { +function Ha(a, b) { b || (b = new Set()); for (let c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function ya(a, b, c, d, e, f, g = 0) { - const h = d && d.constructor === Array; - var k = h ? d.shift() : d; - if (!k) { - return this.export(a, b, e, f + 1); +function Ia(a, b, c, e, d, f, g = 0) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { + return this.export(a, b, d, f + 1); } - if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return ya.call(l, a, b, c, h ? d : null, e, f, g + 1); + return h.then(function() { + return Ia.call(l, a, b, c, k ? e : null, d, f, g + 1); }); } - return ya.call(this, a, b, c, h ? d : null, e, f, g + 1); + return Ia.call(this, a, b, c, k ? e : null, d, f, g + 1); } -function za(a, b) { +function La(a, b) { let c = ""; - for (const d of a.entries()) { - a = d[0]; - const e = d[1]; + for (const e of a.entries()) { + a = e[0]; + const d = e[1]; let f = ""; - for (let g = 0, h; g < e.length; g++) { - h = e[g] || [""]; - let k = ""; - for (let l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === b ? '"' + h[l] + '"' : h[l]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === b ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; c += (c ? "," : "") + f; } return c; } -;function Aa(a, b, c, d) { - let e = []; +;function Ma(a, b, c, e) { + let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { b -= g.length; } else { - b = g[d ? "splice" : "slice"](b, c); - const h = b.length; - if (h && (e = e.length ? e.concat(b) : b, c -= h, d && (a.length -= h), !c)) { + 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 e; + return d; } -function R(a) { - if (!this || this.constructor !== R) { - return new R(a); +function T(a) { + if (!this || this.constructor !== T) { + return new T(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; const b = this; - return new Proxy([], {get(c, d) { - if ("length" === d) { + return new Proxy([], {get(c, e) { + if ("length" === e) { return b.length; } - if ("push" === d) { - return function(e) { - b.index[b.index.length - 1].push(e); + if ("push" === e) { + return function(d) { + b.index[b.index.length - 1].push(d); b.length++; }; } - if ("pop" === d) { + if ("pop" === e) { return function() { if (b.length) { return b.length--, b.index[b.index.length - 1].pop(); } }; } - if ("indexOf" === d) { - return function(e) { + if ("indexOf" === e) { + return function(d) { let f = 0; - for (let g = 0, h, k; g < b.index.length; g++) { - h = b.index[g]; - k = h.indexOf(e); - if (0 <= k) { - return f + k; + for (let g = 0, k, h; g < b.index.length; g++) { + k = b.index[g]; + h = k.indexOf(d); + if (0 <= h) { + return f + h; } - f += h.length; + f += k.length; } return -1; }; } - if ("includes" === d) { - return function(e) { + if ("includes" === e) { + return function(d) { for (let f = 0; f < b.index.length; f++) { - if (b.index[f].includes(e)) { + if (b.index[f].includes(d)) { return !0; } } return !1; }; } - if ("slice" === d) { - return function(e, f) { - return Aa(b, e || 0, f || b.length, !1); + if ("slice" === e) { + return function(d, f) { + return Ma(b, d || 0, f || b.length, !1); }; } - if ("splice" === d) { - return function(e, f) { - return Aa(b, e || 0, f || b.length, !0); + if ("splice" === e) { + return function(d, f) { + return Ma(b, d || 0, f || b.length, !0); }; } - if ("constructor" === d) { + if ("constructor" === e) { return Array; } - if ("symbol" !== typeof d) { - return (c = b.index[d / 2 ** 31 | 0]) && c[d]; + if ("symbol" !== typeof e) { + return (c = b.index[e / 2 ** 31 | 0]) && c[e]; } - }, set(c, d, e) { - c = d / 2 ** 31 | 0; - (b.index[c] || (b.index[c] = []))[d] = e; + }, set(c, e, d) { + c = e / 2 ** 31 | 0; + (b.index[c] || (b.index[c] = []))[e] = d; b.length++; return !0; }}); } -R.prototype.clear = function() { +T.prototype.clear = function() { this.index.length = 0; }; -R.prototype.destroy = function() { +T.prototype.destroy = function() { this.proxy = this.index = null; }; -R.prototype.push = function() { +T.prototype.push = function() { }; -function S(a = 8) { - if (!this || this.constructor !== S) { - return new S(a); +function U(a = 8) { + if (!this || this.constructor !== U) { + return new U(a); } - this.index = A(); + this.index = G(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.B = Na, this.A = BigInt(a)) : (this.B = Oa, this.A = a); } -S.prototype.get = function(a) { +U.prototype.get = function(a) { const b = this.index[this.B(a)]; return b && b.get(a); }; -S.prototype.set = function(a, b) { +U.prototype.set = function(a, b) { var c = this.B(a); - let 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.h.push(d), this.size++); + let e = this.index[c]; + e ? (c = e.size, e.set(a, b), (c -= e.size) && this.size++) : (this.index[c] = e = new Map([[a, b]]), this.h.push(e), this.size++); }; -function T(a = 8) { - if (!this || this.constructor !== T) { - return new T(a); +function V(a = 8) { + if (!this || this.constructor !== V) { + return new V(a); } - this.index = A(); + this.index = G(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.B = Na, this.A = BigInt(a)) : (this.B = Oa, this.A = a); } -T.prototype.add = function(a) { +V.prototype.add = function(a) { var b = this.B(a); let 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), this.size++); }; -u = S.prototype; -u.has = T.prototype.has = function(a) { +v = U.prototype; +v.has = V.prototype.has = function(a) { const b = this.index[this.B(a)]; return b && b.has(a); }; -u.delete = T.prototype.delete = function(a) { +v.delete = V.prototype.delete = function(a) { const b = this.index[this.B(a)]; b && b.delete(a) && this.size--; }; -u.clear = T.prototype.clear = function() { - this.index = A(); +v.clear = V.prototype.clear = function() { + this.index = G(); this.h = []; this.size = 0; }; -u.values = T.prototype.values = function*() { +v.values = V.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].values()) { yield b; } } }; -u.keys = T.prototype.keys = function*() { +v.keys = V.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].keys()) { yield b; } } }; -u.entries = T.prototype.entries = function*() { +v.entries = V.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].entries()) { yield b; } } }; -function Ca(a) { +function Oa(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; } - let c = 0, d = this.A + 1; - for (let e = 0; e < a.length; e++) { - c = (c * d ^ a.charCodeAt(e)) & b; + let c = 0, e = this.A + 1; + for (let d = 0; d < a.length; d++) { + c = (c * e ^ a.charCodeAt(d)) & b; } return 32 === this.A ? c + 2 ** 31 : c; } -function Ba(a) { +function Na(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -685,75 +685,75 @@ function Ba(a) { return BigInt(a) & b; } c = BigInt(0); - let d = this.A + BigInt(1); - for (let e = 0; e < a.length; e++) { - c = (c * d ^ BigInt(a.charCodeAt(e))) & b; + let e = this.A + BigInt(1); + for (let d = 0; d < a.length; d++) { + c = (c * e ^ BigInt(a.charCodeAt(d))) & b; } return c; } -;U.prototype.add = function(a, b, c) { - aa(a) && (b = a, a = ca(b, this.key)); +;Pa.prototype.add = function(a, b, c) { + aa(a) && (b = a, a = ea(b, this.key)); if (b && (a || 0 === a)) { if (!c && this.reg.has(a)) { return this.update(a, b); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.F[h]; - var d = this.index.get(this.field[h]); - if ("function" === typeof k) { - var e = k(b); - e && d.add(a, e, !1, !0); + for (let k = 0, h; k < this.field.length; k++) { + h = this.F[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(b); + d && e.add(a, d, !1, !0); } else { - if (e = k.I, !e || e(b)) { - k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), Da(b, k, this.J, 0, d, a, k[0], c); + if (d = h.I, !d || d(b)) { + h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), Qa(b, h, this.J, 0, e, a, h[0], c); } } } if (this.tag) { - for (d = 0; d < this.D.length; d++) { - var f = this.D[d], g = this.R[d]; - e = this.tag.get(g); - let h = A(); + for (e = 0; e < this.D.length; e++) { + var f = this.D[e], g = this.R[e]; + d = this.tag.get(g); + let k = G(); if ("function" === typeof f) { if (f = f(b), !f) { continue; } } else { - const k = f.I; - if (k && !k(b)) { + const h = f.I; + if (h && !h(b)) { continue; } f.constructor === String && (f = "" + f); - f = ca(b, f); + f = ea(b, f); } - if (e && f) { - D(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - if (l = f[k], !h[l] && (h[l] = 1, (g = e.get(l)) ? m = g : e.set(l, m = []), !c || !m.includes(a))) { + if (d && f) { + L(f) && (f = [f]); + for (let h = 0, l, m; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !c || !m.includes(a))) { if (m.length === 2 ** 31 - 1) { - g = new R(m); + g = new T(m); if (this.fastupdate) { for (let n of this.reg.values()) { n.includes(m) && (n[n.indexOf(m)] = g); } } - e.set(l, m = g); + d.set(l, m = g); } m.push(a); this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); } } } else { - e || console.warn("Tag '" + g + "' was not found"); + d || console.warn("Tag '" + g + "' was not found"); } } } if (this.store && (!c || !this.store.has(a))) { - let h; + let k; if (this.C) { - h = A(); - for (let k = 0, l; k < this.C.length; k++) { - l = this.C[k]; + k = G(); + for (let h = 0, l; h < this.C.length; h++) { + l = this.C[h]; if ((c = l.I) && !c(b)) { continue; } @@ -764,131 +764,131 @@ function Ba(a) { continue; } l = [l.V]; - } else if (D(l) || l.constructor === String) { - h[l] = b[l]; + } else if (L(l) || l.constructor === String) { + k[l] = b[l]; continue; } - Ea(b, h, l, 0, l[0], m); + Ra(b, k, l, 0, l[0], m); } } - this.store.set(a, h || b); + this.store.set(a, k || b); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Ea(a, b, c, d, e, f) { - a = a[e]; - if (d === c.length - 1) { - b[e] = f || a; +function Ra(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[e] = Array(a.length), e = 0; e < a.length; e++) { - Ea(a, b, c, d, e); + for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { + Ra(a, b, c, e, d); } } else { - b = b[e] || (b[e] = A()), e = c[++d], Ea(a, b, c, d, e); + b = b[d] || (b[d] = G()), d = c[++e], Ra(a, b, c, e, d); } } } -function Da(a, b, c, d, e, f, g, h) { +function Qa(a, b, c, e, d, f, g, k) { if (a = a[g]) { - if (d === b.length - 1) { + if (e === b.length - 1) { if (a.constructor === Array) { - if (c[d]) { + if (c[e]) { for (b = 0; b < a.length; b++) { - e.add(f, a[b], !0, !0); + d.add(f, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Da(a, b, c, d, e, f, g, h); + Qa(a, b, c, e, d, f, g, k); } } else { - g = b[++d], Da(a, b, c, d, e, f, g, h); + g = b[++e], Qa(a, b, c, e, d, f, g, k); } } } else { - e.db && e.remove(f); + d.db && d.remove(f); } } -;function Fa(a, b, c, d, e, f, g) { - const h = a.length; - let k = [], l, m; - l = A(); - for (let n = 0, p, r, q, t; n < b; n++) { - for (let v = 0; v < h; v++) { - if (q = a[v], n < q.length && (p = q[n])) { - for (let w = 0; w < p.length; w++) { - r = p[w]; - (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1); - t = k[m] || (k[m] = []); +;function Sa(a, b, c, e, d, f, g) { + const k = a.length; + let h = [], l, m; + l = G(); + for (let n = 0, r, q, t, u; n < b; n++) { + for (let p = 0; p < k; p++) { + if (t = a[p], n < t.length && (r = t[n])) { + for (let z = 0; z < r.length; z++) { + q = r[z]; + (m = l[q]) ? l[q]++ : (m = 0, l[q] = 1); + u = h[m] || (h[m] = []); if (!g) { - let x = n + (v || !e ? 0 : f || 0); - t = t[x] || (t[x] = []); + let x = n + (p || !d ? 0 : f || 0); + u = u[x] || (u[x] = []); } - t.push(r); - if (g && c && m === h - 1 && t.length - d === c) { - return d ? t.slice(d) : t; + u.push(q); + if (g && c && m === k - 1 && u.length - e === c) { + return e ? u.slice(e) : u; } } } } } - if (a = k.length) { - if (e) { - k = 1 < k.length ? Ga(k, c, d, g, f) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + if (a = h.length) { + if (d) { + h = 1 < h.length ? Ta(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; - if (c || d) { + h = h[a - 1]; + if (c || e) { if (g) { - if (k.length > c || d) { - k = k.slice(d, c + d); + if (h.length > c || e) { + h = h.slice(e, c + e); } } else { - e = []; - for (let n = 0, p; n < k.length; n++) { - if (p = k[n], p.length > d) { - d -= p.length; + d = []; + for (let n = 0, r; n < h.length; n++) { + if (r = h[n], r.length > e) { + e -= r.length; } else { - if (p.length > c || d) { - p = p.slice(d, c + d), c -= p.length, d && (d -= p.length); + if (r.length > c || e) { + r = r.slice(e, c + e), c -= r.length, e && (e -= r.length); } - e.push(p); + d.push(r); if (!c) { break; } } } - k = 1 < e.length ? [].concat.apply([], e) : e[0]; + h = 1 < d.length ? [].concat.apply([], d) : d[0]; } } } } - return k; + return h; } -function Ga(a, b, c, d, e) { - const f = [], g = A(); - let h; - var k = a.length; +function Ta(a, b, c, e, d) { + const f = [], g = G(); + let k; + var h = a.length; let l; - if (d) { - for (e = k - 1; 0 <= e; e--) { - if (l = (d = a[e]) && d.length) { - for (k = 0; k < l; k++) { - if (h = d[k], !g[h]) { - if (g[h] = 1, c) { + if (e) { + for (d = h - 1; 0 <= d; d--) { + if (l = (e = a[d]) && e.length) { + for (h = 0; h < l; h++) { + if (k = e[h], !g[k]) { + if (g[k] = 1, c) { c--; } else { - if (f.push(h), f.length === b) { + if (f.push(k), f.length === b) { return f; } } @@ -897,18 +897,18 @@ function Ga(a, b, c, d, e) { } } } else { - for (let m = k - 1, n, p = 0; 0 <= m; m--) { + for (let m = h - 1, n, r = 0; 0 <= m; m--) { n = a[m]; - for (let r = 0; r < n.length; r++) { - if (l = (d = n[r]) && d.length) { - for (let q = 0; q < l; q++) { - if (h = d[q], !g[h]) { - if (g[h] = 1, c) { + for (let q = 0; q < n.length; q++) { + if (l = (e = n[q]) && e.length) { + for (let t = 0; t < l; t++) { + if (k = e[t], !g[k]) { + if (g[k] = 1, c) { c--; } else { - let t = (r + (m < k - 1 ? e || 0 : 0)) / (m + 1) | 0; - (f[t] || (f[t] = [])).push(h); - if (++p === b) { + let u = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[u] || (f[u] = [])).push(k); + if (++r === b) { return f; } } @@ -920,217 +920,217 @@ function Ga(a, b, c, d, e) { } return f; } -function Ha(a, b, c) { - const d = A(), e = []; +function Ua(a, b, c) { + const e = G(), d = []; for (let f = 0, g; f < b.length; f++) { g = b[f]; - for (let h = 0; h < g.length; h++) { - d[g[h]] = 1; + for (let k = 0; k < g.length; k++) { + e[g[k]] = 1; } } if (c) { for (let f = 0, g; f < a.length; f++) { - g = a[f], d[g] && (e.push(g), d[g] = 0); + g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, h; f < a.result.length; f++) { + for (let f = 0, g, k; f < a.result.length; f++) { for (g = a.result[f], b = 0; b < g.length; b++) { - h = g[b], d[h] && ((e[f] || (e[f] = [])).push(h), d[h] = 0); + k = g[b], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); } } } - return e; + return d; } -;function Ia(a, b, c, d) { +;function Va(a, b, c, e) { 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 ? V.call(this, a) : a; + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, e ? X.call(this, a) : a; } - let e = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + let d = []; + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { if (c) { - if (c >= h) { - c -= h; + if (c >= k) { + c -= k; continue; } - c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); + c < k && (g = b ? g.slice(c, c + b) : g.slice(c), k = g.length, c = 0); } - h > b && (g = g.slice(0, b), h = b); - if (!e.length && h >= b) { - return d ? V.call(this, g) : g; + k > b && (g = g.slice(0, b), k = b); + if (!d.length && k >= b) { + return e ? X.call(this, g) : g; } - e.push(g); - b -= h; + d.push(g); + b -= k; if (!b) { break; } } } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? V.call(this, e) : e; + d = 1 < d.length ? [].concat.apply([], d) : d[0]; + return e ? X.call(this, d) : d; } -;function Ja(a, b, c) { - var d = c[0]; - if (d.then) { +;function Wa(a, b, c) { + var e = c[0]; + if (e.then) { return Promise.all(c).then(function(m) { return a[b].apply(a, m); }); } - if (d[0] && d[0].index) { - return a[b].apply(a, d); + if (e[0] && e[0].index) { + return a[b].apply(a, e); } - d = []; - let e = [], f = 0, g = 0, h, k, l; + e = []; + let d = [], f = 0, g = 0, k, h, l; for (let m = 0, n; m < c.length; m++) { if (n = c[m]) { - let p; - if (n.constructor === W) { - p = n.result; + let r; + if (n.constructor === Y) { + r = n.result; } else if (n.constructor === Array) { - p = n; + r = n; } else { - if (f = n.limit || 0, g = 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; + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { + n.resolve = !1, n.enrich = !1, r = n.index.search(n).result, n.resolve = h, n.enrich = k; } else if (n.and) { - p = a.and(n.and); + r = a.and(n.and); } else if (n.or) { - p = a.or(n.or); + r = a.or(n.or); } else if (n.xor) { - p = a.xor(n.xor); + r = a.xor(n.xor); } else if (n.not) { - p = a.not(n.not); + r = a.not(n.not); } else { continue; } } - if (p.then) { - e.push(p); - } else if (p.length) { - d[m] = p; + if (r.then) { + d.push(r); + } else if (r.length) { + e[m] = r; } else if (!l && ("and" === b || "xor" === b)) { - d = []; + e = []; break; } } } - return {O:d, P:e, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } -;W.prototype.or = function() { - const {O:a, P:b, limit:c, offset:d, enrich:e, resolve:f} = Ja(this, "or", arguments); - return Ka.call(this, a, b, c, d, e, f); +;Y.prototype.or = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Wa(this, "or", arguments); + return Xa.call(this, a, b, c, e, d, f); }; -function Ka(a, b, c, d, e, f) { +function Xa(a, b, c, e, d, f) { if (b.length) { const g = this; - return Promise.all(b).then(function(h) { - a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); - } - return Ka.call(g, a, [], c, d, e, f); - }); - } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ga(a, c, d, !1, this.h), d = 0)); - return f ? this.resolve(c, d, e) : this; -} -;W.prototype.and = function() { - let a = this.result.length, b, c, d, e; - if (!a) { - const f = arguments[0]; - f && (a = !!f.suggest, e = f.resolve, b = f.limit, c = f.offset, d = f.enrich && e); - } - if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); - return La.call(this, f, g, h, k, l, m, n); - } - return e ? this.resolve(b, c, d) : this; -}; -function La(a, b, c, d, e, f, g) { - if (b.length) { - const h = this; return Promise.all(b).then(function(k) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } - return La.call(h, a, [], c, d, e, f, g); + return Xa.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 = Ta(a, c, e, !1, this.h), e = 0)); + return f ? this.resolve(c, e, d) : this; +} +;Y.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} = Wa(this, "and", arguments); + return Ya.call(this, f, g, k, h, l, m, n); + } + return d ? this.resolve(b, c, e) : this; +}; +function Ya(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; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Ya.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 { - if (b = da(a)) { - return this.result = Fa(a, b, c, d, g, this.h, f), f ? e ? V.call(this.index, this.result) : this.result : this; + if (b = fa(a)) { + return this.result = Sa(a, b, c, e, g, this.h, f), f ? d ? X.call(this.index, this.result) : this.result : this; } this.result = []; } } else { g || (this.result = a); } - return f ? this.resolve(c, d, e) : this; + return f ? this.resolve(c, e, d) : this; } -;W.prototype.xor = function() { - const {O:a, P:b, limit:c, offset:d, enrich:e, resolve:f, suggest:g} = Ja(this, "xor", arguments); - return Ma.call(this, a, b, c, d, e, f, g); +;Y.prototype.xor = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Wa(this, "xor", arguments); + return Za.call(this, a, b, c, e, d, f, g); }; -function Ma(a, b, c, d, e, f, g) { +function Za(a, b, c, e, d, f, g) { if (b.length) { - const h = this; - return Promise.all(b).then(function(k) { + const k = this; + return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Ma.call(h, a, [], c, d, e, f, g); + return Za.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 = Na.call(this, a, c, d, f, this.h), f ? e ? V.call(this.index, this.result) : this.result : this; + return this.result = $a.call(this, a, c, e, f, this.h), f ? d ? X.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } - return f ? this.resolve(c, d, e) : this; + return f ? this.resolve(c, e, d) : this; } -function Na(a, b, c, d, e) { - const f = [], g = A(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); +function $a(a, b, c, e, d) { + const f = [], g = G(); + let k = 0; + for (let h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); for (let m = 0, n; m < l.length; m++) { if (n = l[m]) { - for (let p = 0, r; p < n.length; p++) { - r = n[p], g[r] = g[r] ? 2 : 1; + for (let r = 0, q; r < n.length; r++) { + q = n[r], g[q] = g[q] ? 2 : 1; } } } } } - for (let k = 0, l, m = 0; k < h; k++) { - for (let n = 0, p; n < a.length; n++) { - if (p = a[n]) { - if (l = p[k]) { - for (let r = 0, q; r < l.length; r++) { - if (q = l[r], 1 === g[q]) { + for (let h = 0, l, m = 0; h < k; h++) { + for (let n = 0, r; n < a.length; n++) { + if (r = a[n]) { + if (l = r[h]) { + for (let q = 0, t; q < l.length; q++) { + if (t = l[q], 1 === g[t]) { if (c) { c--; } else { - if (d) { - if (f.push(q), f.length === b) { + if (e) { + if (f.push(t), f.length === b) { return f; } } else { - const t = k + (n ? e : 0); - f[t] || (f[t] = []); - f[t].push(q); + const u = h + (n ? d : 0); + f[u] || (f[u] = []); + f[u].push(t); if (++m === b) { return f; } @@ -1144,45 +1144,45 @@ function Na(a, b, c, d, e) { } return f; } -;W.prototype.not = function() { - const {O:a, P:b, limit:c, offset:d, enrich:e, resolve:f, suggest:g} = Ja(this, "not", arguments); - return Oa.call(this, a, b, c, d, e, f, g); +;Y.prototype.not = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Wa(this, "not", arguments); + return ab.call(this, a, b, c, e, d, f, g); }; -function Oa(a, b, c, d, e, f, g) { +function ab(a, b, c, e, d, f, g) { if (b.length) { - const h = this; - return Promise.all(b).then(function(k) { + const k = this; + return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Oa.call(h, a, [], c, d, e, f, g); + return ab.call(k, a, [], c, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Pa.call(this, a, c, d, f); + this.result = bb.call(this, a, c, e, f); } else if (f) { - return this.resolve(c, d, e); + return this.resolve(c, e, d); } - return f ? e ? V.call(this.index, this.result) : this.result : this; + return f ? d ? X.call(this.index, this.result) : this.result : this; } -function Pa(a, b, c, d) { - const e = []; +function bb(a, b, c, e) { + const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { + for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (c) { c--; } else { - if (d) { - if (e.push(l), e.length === b) { - return e; + if (e) { + if (d.push(l), d.length === b) { + return d; } } else { - if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { - return e; + if (d[f] || (d[f] = []), d[f].push(l), ++k === b) { + return d; } } } @@ -1190,11 +1190,11 @@ function Pa(a, b, c, d) { } } } - return e; + return d; } -;function W(a) { - if (!this || this.constructor !== W) { - return new W(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; @@ -1203,17 +1203,17 @@ function Pa(a, b, c, d) { this.result = a || []; this.h = 0; } -W.prototype.limit = function(a) { +Y.prototype.limit = function(a) { if (this.result.length) { const b = []; - for (let c = 0, d; c < this.result.length; c++) { - if (d = this.result[c]) { - if (d.length <= a) { - if (b[c] = d, a -= d.length, !a) { + for (let c = 0, e; c < this.result.length; c++) { + if (e = this.result[c]) { + if (e.length <= a) { + if (b[c] = e, a -= e.length, !a) { break; } } else { - b[c] = d.slice(0, a); + b[c] = e.slice(0, a); break; } } @@ -1222,382 +1222,561 @@ W.prototype.limit = function(a) { } return this; }; -W.prototype.offset = function(a) { +Y.prototype.offset = function(a) { if (this.result.length) { const b = []; - for (let c = 0, d; c < this.result.length; c++) { - if (d = this.result[c]) { - d.length <= a ? a -= d.length : (b[c] = d.slice(a), a = 0); + for (let c = 0, e; c < this.result.length; c++) { + if (e = this.result[c]) { + e.length <= a ? a -= e.length : (b[c] = e.slice(a), a = 0); } } this.result = b; } return this; }; -W.prototype.boost = function(a) { +Y.prototype.boost = function(a) { this.h += a; return this; }; -W.prototype.resolve = function(a, b, c) { - const d = this.result, e = this.index; +Y.prototype.resolve = function(a, b, c) { + const e = this.result, d = this.index; this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ia.call(e, d, a || 100, b, c)) : d; + return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Va.call(d, e, a || 100, b, c)) : e; }; -A(); -U.prototype.search = function(a, b, c, d) { +G(); +function cb(a, b, c, e, d) { + let f, g, k; + "string" === typeof d ? (f = d, d = "") : f = d.template; + if (!f) { + throw Error('No template pattern was specified by the search option "highlight"'); + } + g = f.indexOf("$1"); + if (-1 === g) { + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); + } + k = f.substring(g + 2); + g = f.substring(0, g); + let h = d && d.boundary, l = !d || !1 !== d.clip, m = d && d.merge && k && g && new RegExp(k + " " + g, "g"); + d = d && d.ellipsis; + var n = 0; + if ("object" === typeof d) { + var r = d.template; + n = r.length - 2; + d = d.pattern; + } + "string" !== typeof d && (d = !1 === d ? "" : "..."); + n && (d = r.replace("$1", d)); + r = d.length - n; + let q, t; + "object" === typeof h && (q = h.before, 0 === q && (q = -1), t = h.after, 0 === t && (t = -1), h = h.total || 9e5); + n = new Map(); + for (let Ja = 0, ba, db, na; Ja < b.length; Ja++) { + let oa; + if (e) { + oa = b, na = e; + } else { + var u = b[Ja]; + na = u.field; + if (!na) { + continue; + } + oa = u.result; + } + db = c.get(na); + ba = db.encoder; + u = n.get(ba); + "string" !== typeof u && (u = ba.encode(a), n.set(ba, u)); + for (let ua = 0; ua < oa.length; ua++) { + var p = oa[ua].doc; + if (!p) { + continue; + } + p = ea(p, na); + if (!p) { + continue; + } + var z = p.trim().split(/\s+/); + if (!z.length) { + continue; + } + p = ""; + var x = []; + let va = []; + var J = -1, B = -1, y = 0; + for (var A = 0; A < z.length; A++) { + var D = z[A], E = ba.encode(D); + E = 1 < E.length ? E.join(" ") : E[0]; + let w; + if (E && D) { + var C = D.length, H = (ba.split ? D.replace(ba.split, "") : D).length - E.length, M = "", W = 0; + for (var ca = 0; ca < u.length; ca++) { + var Q = u[ca]; + if (Q) { + var K = Q.length; + K += H; + W && K <= W || (Q = E.indexOf(Q), -1 < Q && (M = (Q ? D.substring(0, Q) : "") + g + D.substring(Q, Q + K) + k + (Q + K < C ? D.substring(Q + K) : ""), W = K, w = !0)); + } + } + M && (h && (0 > J && (J = p.length + (p ? 1 : 0)), B = p.length + (p ? 1 : 0) + M.length, y += C, va.push(x.length), x.push({match:M})), p += (p ? " " : "") + M); + } + if (!w) { + D = z[A], p += (p ? " " : "") + D, h && x.push({text:D}); + } else if (h && y >= h) { + break; + } + } + y = va.length * (f.length - 2); + if (q || t || h && p.length - y > h) { + if (y = h + y - 2 * r, A = B - J, 0 < q && (A += q), 0 < t && (A += t), A <= y) { + z = q ? J - (0 < q ? q : 0) : J - ((y - A) / 2 | 0), x = t ? B + (0 < t ? t : 0) : z + y, l || (0 < z && " " !== p.charAt(z) && " " !== p.charAt(z - 1) && (z = p.indexOf(" ", z), 0 > z && (z = 0)), x < p.length && " " !== p.charAt(x - 1) && " " !== p.charAt(x) && (x = p.lastIndexOf(" ", x), x < B ? x = B : ++x)), p = (z ? d : "") + p.substring(z, x) + (x < p.length ? d : ""); + } else { + B = []; + J = {}; + y = {}; + A = {}; + D = {}; + E = {}; + M = H = C = 0; + for (ca = W = 1;;) { + var S = void 0; + for (let w = 0, I; w < va.length; w++) { + I = va[w]; + if (M) { + if (H !== M) { + if (A[w + 1]) { + continue; + } + I += M; + if (J[I]) { + C -= r; + y[w + 1] = 1; + A[w + 1] = 1; + continue; + } + if (I >= x.length - 1) { + if (I >= x.length) { + A[w + 1] = 1; + I >= z.length && (y[w + 1] = 1); + continue; + } + C -= r; + } + p = x[I].text; + if (K = t && E[w]) { + if (0 < K) { + if (p.length > K) { + if (A[w + 1] = 1, l) { + p = p.substring(0, K); + } else { + continue; + } + } + (K -= p.length) || (K = -1); + E[w] = K; + } else { + A[w + 1] = 1; + continue; + } + } + if (C + p.length + 1 <= h) { + p = " " + p, B[w] += p; + } else if (l) { + S = h - C - 1, 0 < S && (p = " " + p.substring(0, S), B[w] += p), A[w + 1] = 1; + } else { + A[w + 1] = 1; + continue; + } + } else { + if (A[w]) { + continue; + } + I -= H; + if (J[I]) { + C -= r; + A[w] = 1; + y[w] = 1; + continue; + } + if (0 >= I) { + if (0 > I) { + A[w] = 1; + y[w] = 1; + continue; + } + C -= r; + } + p = x[I].text; + if (K = q && D[w]) { + if (0 < K) { + if (p.length > K) { + if (A[w] = 1, l) { + p = p.substring(p.length - K); + } else { + continue; + } + } + (K -= p.length) || (K = -1); + D[w] = K; + } else { + A[w] = 1; + continue; + } + } + if (C + p.length + 1 <= h) { + p += " ", B[w] = p + B[w]; + } else if (l) { + S = p.length + 1 - (h - C), 0 <= S && S < p.length && (p = p.substring(S) + " ", B[w] = p + B[w]), A[w] = 1; + } else { + A[w] = 1; + continue; + } + } + } else { + p = x[I].match; + q && (D[w] = q); + t && (E[w] = t); + w && C++; + let Ka; + I ? !w && r && (C += r) : (y[w] = 1, A[w] = 1); + I >= z.length - 1 ? Ka = 1 : I < x.length - 1 && x[I + 1].match ? Ka = 1 : r && (C += r); + C -= f.length - 2; + if (!w || C + p.length <= h) { + B[w] = p; + } else { + S = W = ca = y[w] = 0; + break; + } + Ka && (y[w + 1] = 1, A[w + 1] = 1); + } + C += p.length; + S = J[I] = 1; + } + if (S) { + H === M ? M++ : H++; + } else { + H === M ? W = 0 : ca = 0; + if (!W && !ca) { + break; + } + W ? (H++, M = H) : M++; + } + } + p = ""; + for (let w = 0, I; w < B.length; w++) { + I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], p += I; + } + d && !y[B.length] && (p += d); + } + } + m && (p = p.replace(m, " ")); + oa[ua].highlight = p; + } + if (e) { + break; + } + } + return b; +} +;Pa.prototype.search = function(a, b, c, e) { c || (!b && aa(a) ? (c = a, a = "") : aa(b) && (c = b, b = 0)); - let e = []; + let d = []; var f = []; let g; - var h; let k; - let l, m; - let n = 0; - var p = !0; + let h, l; + let m = 0; + var n = !0; let r; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; g = c.pluck; k = c.merge; - l = g || c.field || (l = c.index) && (l.index ? null : l); - m = this.tag && c.tag; + h = g || c.field || (h = c.index) && (h.index ? null : h); + l = this.tag && c.tag; var q = c.suggest; - p = !1 !== c.resolve; - if (!p && !g) { - if (l = l || this.field) { - D(l) ? g = l : (l.constructor === Array && 1 === l.length && (l = l[0]), g = l.field || l.index); + n = !1 !== c.resolve; + if (!n && !g) { + if (h = h || this.field) { + L(h) ? g = h : (h.constructor === Array && 1 === h.length && (h = h[0]), g = h.field || h.index); } if (!g) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - this.store && c.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - r = (h = this.store && c.enrich && p) && c.highlight; + this.store && c.enrich && !n && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var t = (r = n && this.store && c.highlight) || n && this.store && c.enrich; b = c.limit || b; - var t = c.offset || 0; + var u = c.offset || 0; b || (b = 100); - if (m && (!this.db || !d)) { - m.constructor !== Array && (m = [m]); - var v = []; - for (let B = 0, y; B < m.length; B++) { - y = m[B]; - if (D(y)) { + if (l && (!this.db || !e)) { + l.constructor !== Array && (l = [l]); + var p = []; + for (let B = 0, y; B < l.length; B++) { + y = l[B]; + if (L(y)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (y.field && y.tag) { - var w = y.tag; - if (w.constructor === Array) { - for (var x = 0; x < w.length; x++) { - v.push(y.field, w[x]); + var z = y.tag; + if (z.constructor === Array) { + for (var x = 0; x < z.length; x++) { + p.push(y.field, z[x]); } } else { - v.push(y.field, w); + p.push(y.field, z); } } else { - w = Object.keys(y); - for (let C = 0, M, E; C < w.length; C++) { - if (M = w[C], E = y[M], E.constructor === Array) { + z = Object.keys(y); + for (let A = 0, D, E; A < z.length; A++) { + if (D = z[A], E = y[D], E.constructor === Array) { for (x = 0; x < E.length; x++) { - v.push(M, E[x]); + p.push(D, E[x]); } } else { - v.push(M, E); + p.push(D, E); } } } } - if (!v.length) { + if (!p.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - m = v; + l = p; if (!a) { - p = []; - if (v.length) { - for (f = 0; f < v.length; f += 2) { + n = []; + if (p.length) { + for (f = 0; f < p.length; f += 2) { if (this.db) { - q = this.index.get(v[f]); + q = this.index.get(p[f]); if (!q) { - console.warn("Tag '" + v[f] + ":" + v[f + 1] + "' will be skipped because there is no field '" + v[f] + "'."); + console.warn("Tag '" + p[f] + ":" + p[f + 1] + "' will be skipped because there is no field '" + p[f] + "'."); continue; } - p.push(q = q.db.tag(v[f + 1], b, t, h)); + n.push(q = q.db.tag(p[f + 1], b, u, t)); } else { - q = Qa.call(this, v[f], v[f + 1], b, t, h); + q = eb.call(this, p[f], p[f + 1], b, u, t); } - e.push({field:v[f], tag:v[f + 1], result:q}); + d.push({field:p[f], tag:p[f + 1], result:q}); } } - return p.length ? Promise.all(p).then(function(B) { + return n.length ? Promise.all(n).then(function(B) { for (let y = 0; y < B.length; y++) { - e[y].result = B[y]; + d[y].result = B[y]; } - return e; - }) : e; + return d; + }) : d; } } - l && l.constructor !== Array && (l = [l]); + h && h.constructor !== Array && (h = [h]); } - l || (l = this.field); - v = !d && (this.worker || this.db) && []; - let F; - for (let B = 0, y, C, M; B < l.length; B++) { - C = l[B]; + h || (h = this.field); + p = !e && (this.worker || this.db) && []; + let J; + for (let B = 0, y, A, D; B < h.length; B++) { + A = h[B]; if (this.db && this.tag && !this.F[B]) { continue; } let E; - D(C) || (E = C, C = E.field, a = E.query || a, b = E.limit || b, t = E.offset || t, q = E.suggest || q, h = this.store && (E.enrich || h)); - if (d) { - y = d[B]; + L(A) || (E = A, A = E.field, a = E.query || a, b = E.limit || b, u = E.offset || u, q = E.suggest || q, r = (t = this.store && (E.enrich || t)) && (c.highlight || r)); + if (e) { + y = e[B]; } else { - if (w = E || c, x = this.index.get(C), m && (this.db && (w.tag = m, F = x.db.support_tag_search, w.field = l), F || (w.enrich = !1)), v) { - v[B] = x.search(a, b, w); - w && h && (w.enrich = h); + if (z = E || c, x = this.index.get(A), l && (this.db && (z.tag = l, J = x.db.support_tag_search, z.field = h), J || (z.enrich = !1)), p) { + p[B] = x.search(a, b, z); + z && t && (z.enrich = t); continue; } else { - y = x.search(a, b, w), w && h && (w.enrich = h); + y = x.search(a, b, z), z && t && (z.enrich = t); } } - M = y && (p ? y.length : y.result.length); - if (m && M) { - w = []; + D = y && (n ? y.length : y.result.length); + if (l && D) { + z = []; x = 0; - if (this.db && d) { - if (!F) { - for (let J = l.length; J < d.length; J++) { - let K = d[J]; - if (K && K.length) { - x++, w.push(K); + if (this.db && e) { + if (!J) { + for (let C = h.length; C < e.length; C++) { + let H = e[C]; + if (H && H.length) { + x++, z.push(H); } else if (!q) { - return p ? e : new W(e); + return n ? d : new Y(d); } } } } else { - for (let J = 0, K, ob; J < m.length; J += 2) { - K = this.tag.get(m[J]); - if (!K) { - if (console.warn("Tag '" + m[J] + ":" + m[J + 1] + "' will be skipped because there is no field '" + m[J] + "'."), q) { + for (let C = 0, H, M; C < l.length; C += 2) { + H = this.tag.get(l[C]); + if (!H) { + if (console.warn("Tag '" + l[C] + ":" + l[C + 1] + "' will be skipped because there is no field '" + l[C] + "'."), q) { continue; } else { - return p ? e : new W(e); + return n ? d : new Y(d); } } - if (ob = (K = K && K.get(m[J + 1])) && K.length) { - x++, w.push(K); + if (M = (H = H && H.get(l[C + 1])) && H.length) { + x++, z.push(H); } else if (!q) { - return p ? e : new W(e); + return n ? d : new Y(d); } } } if (x) { - y = Ha(y, w, p); - M = y.length; - if (!M && !q) { - return p ? y : new W(y); + y = Ua(y, z, n); + D = y.length; + if (!D && !q) { + return n ? y : new Y(y); } x--; } } - if (M) { - f[n] = C, e.push(y), n++; - } else if (1 === l.length) { - return p ? e : new W(e); + if (D) { + f[m] = A, d.push(y), m++; + } else if (1 === h.length) { + return n ? d : new Y(d); } } - if (v) { - if (this.db && m && m.length && !F) { - for (h = 0; h < m.length; h += 2) { - f = this.index.get(m[h]); + if (p) { + if (this.db && l && l.length && !J) { + for (t = 0; t < l.length; t += 2) { + f = this.index.get(l[t]); if (!f) { - if (console.warn("Tag '" + m[h] + ":" + m[h + 1] + "' was not found because there is no field '" + m[h] + "'."), q) { + if (console.warn("Tag '" + l[t] + ":" + l[t + 1] + "' was not found because there is no field '" + l[t] + "'."), q) { continue; } else { - return p ? e : new W(e); + return n ? d : new Y(d); } } - v.push(f.db.tag(m[h + 1], b, t, !1)); + p.push(f.db.tag(l[t + 1], b, u, !1)); } } const B = this; - return Promise.all(v).then(function(y) { + return Promise.all(p).then(function(y) { return y.length ? B.search(a, b, c, y) : y; }); } - if (!n) { - return p ? e : new W(e); + if (!m) { + return n ? d : new Y(d); } - if (g && (!h || !this.store)) { - return e[0]; + if (g && (!t || !this.store)) { + return d[0]; } - v = []; - for (t = 0; t < f.length; t++) { - q = e[t]; - h && q.length && "undefined" === typeof q[0].doc && (this.db ? v.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = V.call(this, q)); + p = []; + for (u = 0; u < f.length; u++) { + q = d[u]; + t && q.length && "undefined" === typeof q[0].doc && (this.db ? p.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = X.call(this, q)); if (g) { - return p ? r ? Ra(a, q, this.index, g, r) : q : new W(q); + return n ? r ? cb(a, q, this.index, g, r) : q : new Y(q); } - e[t] = {field:f[t], result:q}; + d[u] = {field:f[u], result:q}; } - if (h && this.db && v.length) { + if (t && this.db && p.length) { const B = this; - return Promise.all(v).then(function(y) { - for (let C = 0; C < y.length; C++) { - e[C].result = y[C]; + return Promise.all(p).then(function(y) { + for (let A = 0; A < y.length; A++) { + d[A].result = y[A]; } - return k ? Sa(e) : r ? Ra(a, e, B.index, g, r) : e; + return k ? fb(d) : r ? cb(a, d, B.index, g, r) : d; }); } - return k ? Sa(e) : r ? Ra(a, e, this.index, g, r) : e; + return k ? fb(d) : r ? cb(a, d, this.index, g, r) : d; }; -function Ra(a, b, c, d, e) { - let f, g; - for (let k = 0, l, m, n; k < b.length; k++) { - let p; - if (d) { - p = b, n = d; - } else { - var h = b[k]; - n = h.field; - if (!n) { - continue; - } - p = h.result; - } - m = c.get(n); - l = m.encoder; - h = m.tokenize; - l !== f && (f = l, g = f.encode(a)); - for (let r = 0; r < p.length; r++) { - let q = "", t = ca(p[r].doc, n).split(/\s+/); - for (let v = 0, w, x; v < t.length; v++) { - w = t[v]; - x = l.encode(w); - x = 1 < x.length ? x.join(" ") : x[0]; - let F; - if (x && w) { - for (let B = 0, y; B < g.length; B++) { - if (y = g[B], "strict" === h) { - if (x === y) { - q += (q ? " " : "") + e.replace("$1", w); - F = !0; - break; - } - } else { - const C = x.indexOf(y); - if (-1 < C) { - q += (q ? " " : "") + w.substring(0, C) + e.replace("$1", w.substring(C, C + y.length)) + w.substring(C + y.length); - F = !0; - break; - } - } - } - } - F || (q += (q ? " " : "") + t[v]); - } - p[r].highlight = q; - } - if (d) { - break; +function fb(a) { + const b = [], c = G(); + for (let e = 0, d, f; e < a.length; e++) { + d = a[e]; + f = d.result; + for (let g = 0, k, h, l; g < f.length; g++) { + h = f[g], "object" !== typeof h && (h = {id:h}), k = h.id, (l = c[k]) ? l.push(d.field) : (h.field = c[k] = [d.field], b.push(h)); } } return b; } -function Sa(a) { - const b = [], c = A(); - for (let d = 0, e, f; d < a.length; d++) { - e = a[d]; - f = e.result; - for (let g = 0, h, k, l; g < f.length; g++) { - k = f[g], "object" !== typeof k && (k = {id:k}), h = k.id, (l = c[h]) ? l.push(e.field) : (k.field = c[h] = [e.field], b.push(k)); - } - } - return b; -} -function Qa(a, b, c, d, e) { +function eb(a, b, c, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { - if (a > c || d) { - f = f.slice(d, d + c); + if ((a = (f = f && f.get(b)) && f.length - e) && 0 < a) { + if (a > c || e) { + f = f.slice(e, e + c); } - e && (f = V.call(this, f)); + d && (f = X.call(this, f)); return f; } } -function V(a) { +function X(a) { if (!this || !this.store) { return a; } const b = Array(a.length); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b[c] = {id:d, doc:this.store.get(d)}; + for (let c = 0, e; c < a.length; c++) { + e = a[c], b[c] = {id:e, doc:this.store.get(e)}; } return b; } -;function U(a) { - if (!this || this.constructor !== U) { - return new U(a); +;function Pa(a) { + if (!this || this.constructor !== Pa) { + return new Pa(a); } const b = a.document || a.doc || a; - let c, d; + let c, e; this.F = []; this.field = []; this.J = []; - this.key = (c = b.key || b.id) && Ta(c, this.J) || "id"; - (d = a.keystore || 0) && (this.keystore = d); + this.key = (c = b.key || b.id) && gb(c, this.J) || "id"; + (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; - this.reg = !this.fastupdate || a.worker || a.db ? d ? new T(d) : new Set() : d ? new S(d) : new Map(); + this.reg = !this.fastupdate || a.worker || a.db ? e ? new V(e) : new Set() : e ? new U(e) : new Map(); this.C = (c = b.store || null) && c && !0 !== c && []; - this.store = c && (d ? new S(d) : new Map()); - this.cache = (c = a.cache || null) && new X(c); + this.store = c && (e ? new U(e) : new Map()); + this.cache = (c = a.cache || null) && new hb(c); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = Ua.call(this, a, b); + this.index = ib.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { this.tag = new Map(); this.D = []; this.R = []; - for (let e = 0, f, g; e < c.length; e++) { - f = c[e]; + for (let d = 0, f, g; d < c.length; d++) { + f = c[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.D[e] = f.custom : (this.D[e] = Ta(g, this.J), f.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = f.filter)); - this.R[e] = g; + f.custom ? this.D[d] = f.custom : (this.D[d] = gb(g, this.J), f.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = f.filter)); + this.R[d] = g; this.tag.set(g, new Map()); } } } if (this.worker) { this.fastupdate = !1; - const e = []; + const d = []; for (const f of this.index.values()) { - f.then && e.push(f); + f.then && d.push(f); } - if (e.length) { + if (d.length) { const f = this; - return Promise.all(e).then(function(g) { - const h = new Map(); - let k = 0; + return Promise.all(d).then(function(g) { + const k = new Map(); + let h = 0; for (const m of f.index.entries()) { const n = m[0]; var l = m[1]; if (l.then) { - l = e[k].encoder || {}; - let p = h.get(l); - p || (p = l.encode ? l : new G(l), h.set(l, p)); - l = g[k]; - l.encoder = p; + l = d[h].encoder || {}; + let r = k.get(l); + r || (r = l.encode ? l : new ma(l), k.set(l, r)); + l = g[h]; + l.encoder = r; f.index.set(n, l); - k++; + h++; } } return f; @@ -1607,8 +1786,8 @@ function V(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -u = U.prototype; -u.mount = function(a) { +v = Pa.prototype; +v.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } @@ -1617,96 +1796,96 @@ u.mount = function(a) { for (let f = 0, g; f < this.R.length; f++) { g = this.R[f]; var c = void 0; - this.index.set(g, c = new N({}, this.reg)); + this.index.set(g, c = new P({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(g); c.tag = this.tag.get(g); } } c = []; - const d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let f = 0, g, h; f < b.length; f++) { - d.field = h = b[f]; - g = this.index.get(h); - const k = new a.constructor(a.id, d); - k.id = a.id; - c[f] = k.mount(g); + const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; + for (let f = 0, g, k; f < b.length; f++) { + e.field = k = b[f]; + g = this.index.get(k); + const h = new a.constructor(a.id, e); + h.id = a.id; + c[f] = h.mount(g); g.document = !0; f ? g.bypass = !0 : g.store = this.store; } - const e = this; + const d = this; return this.db = Promise.all(c).then(function() { - e.db = !0; + d.db = !0; }); }; -u.commit = async function(a, b) { +v.commit = async function(a, b) { const c = []; - for (const d of this.index.values()) { - c.push(d.commit(a, b)); + for (const e of this.index.values()) { + c.push(e.commit(a, b)); } await Promise.all(c); this.reg.clear(); }; -u.destroy = function() { +v.destroy = function() { const a = []; for (const b of this.index.values()) { a.push(b.destroy()); } return Promise.all(a); }; -function Ua(a, b) { +function ib(a, b) { const c = new Map(); - let d = b.index || b.field || b; - D(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e]; - D(f) || (g = f, f = f.field); + let e = b.index || b.field || b; + L(e) && (e = [e]); + for (let d = 0, f, g; d < e.length; d++) { + f = e[d]; + L(f) || (g = f, f = f.field); g = aa(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const h = new P(g); - h.encoder = g.encoder; - c.set(f, h); + const k = new Aa(g); + k.encoder = g.encoder; + c.set(f, k); } - this.worker || c.set(f, new N(g, this.reg)); - g.custom ? this.F[e] = g.custom : (this.F[e] = Ta(f, this.J), g.filter && ("string" === typeof this.F[e] && (this.F[e] = new String(this.F[e])), this.F[e].I = g.filter)); - this.field[e] = f; + this.worker || c.set(f, new P(g, this.reg)); + g.custom ? this.F[d] = g.custom : (this.F[d] = gb(f, this.J), g.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = g.filter)); + this.field[d] = f; } if (this.C) { a = b.store; - D(a) && (a = [a]); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.V = g) : (this.C[e] = Ta(g, this.J), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); + L(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] = gb(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 Ta(a, b) { +function gb(a, b) { const c = a.split(":"); - let d = 0; - for (let 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); + let e = 0; + for (let d = 0; d < c.length; d++) { + a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); } - d < c.length && (c.length = d); - return 1 < d ? c : c[0]; + e < c.length && (c.length = e); + return 1 < e ? c : c[0]; } -u.append = function(a, b) { +v.append = function(a, b) { return this.add(a, b, !0); }; -u.update = function(a, b) { +v.update = function(a, b) { return this.remove(a).add(a, b); }; -u.remove = function(a) { - aa(a) && (a = ca(a, this.key)); +v.remove = function(a) { + aa(a) && (a = ea(a, this.key)); for (var b of this.index.values()) { b.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { for (let c of this.tag.values()) { - for (let d of c) { - b = d[0]; - const e = d[1], f = e.indexOf(a); - -1 < f && (1 < e.length ? e.splice(f, 1) : c.delete(b)); + for (let e of c) { + b = e[0]; + const d = e[1], f = d.indexOf(a); + -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); } } } @@ -1716,7 +1895,7 @@ u.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -u.clear = function() { +v.clear = function() { const a = []; for (const b of this.index.values()) { const c = b.clear(); @@ -1731,185 +1910,185 @@ u.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -u.contain = function(a) { +v.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -u.cleanup = function() { +v.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -u.get = function(a) { +v.get = function(a) { return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { return b[0] && b[0].doc || null; }) : this.store.get(a) || null; }; -u.set = function(a, b) { - "object" === typeof a && (b = a, a = ca(b, this.key)); +v.set = function(a, b) { + "object" === typeof a && (b = a, a = ea(b, this.key)); this.store.set(a, b); return this; }; -u.searchCache = Va; -u.export = function(a, b, c = 0, d = 0) { +v.searchCache = jb; +v.export = function(a, b, c = 0, e = 0) { if (c < this.field.length) { const g = this.field[c]; - if ((b = this.index.get(g).export(a, g, c, d = 1)) && b.then) { - const h = this; + if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { + const k = this; return b.then(function() { - return h.export(a, g, c + 1); + return k.export(a, g, c + 1); }); } return this.export(a, g, c + 1); } - let e, f; - switch(d) { + let d, f; + switch(e) { case 0: - e = "reg"; - f = wa(this.reg); + d = "reg"; + f = Ga(this.reg); b = null; break; case 1: - e = "tag"; - f = this.tag && ua(this.tag, this.reg.size); + d = "tag"; + f = this.tag && Ea(this.tag, this.reg.size); b = null; break; case 2: - e = "doc"; - f = this.store && sa(this.store); + d = "doc"; + f = this.store && Ca(this.store); b = null; break; default: return; } - return ya.call(this, a, b, e, f, c, d); + return Ia.call(this, a, b, d, f, c, e); }; -u.import = function(a, b) { +v.import = function(a, b) { var c = a.split("."); "json" === c[c.length - 1] && c.pop(); - const d = 2 < c.length ? c[0] : ""; + const e = 2 < c.length ? c[0] : ""; c = 2 < c.length ? c[2] : c[1]; - if (this.worker && d) { - return this.index.get(d).import(a); + if (this.worker && e) { + return this.index.get(e).import(a); } if (b) { "string" === typeof b && (b = JSON.parse(b)); - if (d) { - return this.index.get(d).import(c, b); + if (e) { + return this.index.get(e).import(c, b); } switch(c) { case "reg": this.fastupdate = !1; - this.reg = xa(b, this.reg); - for (let e = 0, f; e < this.field.length; e++) { - f = this.index.get(this.field[e]), f.fastupdate = !1, f.reg = this.reg; + this.reg = Ha(b, this.reg); + for (let d = 0, f; d < this.field.length; d++) { + f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } if (this.worker) { b = []; - for (const e of this.index.values()) { - b.push(e.import(a)); + for (const d of this.index.values()) { + b.push(d.import(a)); } return Promise.all(b); } break; case "tag": - this.tag = va(b, this.tag); + this.tag = Fa(b, this.tag); break; case "doc": - this.store = ta(b, this.store); + this.store = Da(b, this.store); } } }; -la(U.prototype); -function Va(a, b, c) { - const d = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new X()); - let e = this.cache.get(d); - if (!e) { - e = this.search(a, b, c); - if (e.then) { +ra(Pa.prototype); +function jb(a, b, c) { + const e = ("object" === typeof a ? "" + a.query : a).toLowerCase(); + this.cache || (this.cache = new hb()); + let d = this.cache.get(e); + if (!d) { + d = this.search(a, b, c); + if (d.then) { const f = this; - e.then(function(g) { - f.cache.set(d, g); + d.then(function(g) { + f.cache.set(e, g); return g; }); } - this.cache.set(d, e); + this.cache.set(e, d); } - return e; + return d; } -function X(a) { +function hb(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -X.prototype.set = function(a, b) { +hb.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); }; -X.prototype.get = function(a) { +hb.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; }; -X.prototype.remove = function(a) { +hb.prototype.remove = function(a) { for (const b of this.cache) { const c = b[0]; b[1].includes(a) && this.cache.delete(c); } }; -X.prototype.clear = function() { +hb.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Wa = {normalize:!1, numeric:!1, dedupe:!1}; -const Xa = {}; -const Ya = 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 Za = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), $a = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const ab = {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 bb = {Exact:Wa, Default:Xa, Normalize:Xa, LatinBalance:{mapper:Ya}, LatinAdvanced:{mapper:Ya, matcher:Za, replacer:$a}, LatinExtra:{mapper:Ya, replacer:$a.concat([/(?!^)[aeo]/g, ""]), matcher:Za}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +const kb = {normalize:!1, numeric:!1, dedupe:!1}; +const lb = {}; +const mb = 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 nb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ob = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const pb = {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 qb = {Exact:kb, Default:lb, Normalize:lb, LatinBalance:{mapper:mb}, LatinAdvanced:{mapper:mb, matcher:nb, replacer:ob}, LatinExtra:{mapper:mb, replacer:ob.concat([/(?!^)[aeo]/g, ""]), matcher:nb}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let d = b.charAt(0), e = ab[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = ab[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + let e = b.charAt(0), d = pb[e]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = pb[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = d; + a[c] = e; } -}}, CJK:{split:""}, LatinExact:Wa, LatinDefault:Xa, LatinSimple:Xa}; -N.prototype.remove = function(a, b) { +}}, CJK:{split:""}, LatinExact:kb, LatinDefault:lb, LatinSimple:lb}; +P.prototype.remove = function(a, b) { const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { - for (let d = 0, e; d < c.length; d++) { - if (e = c[d]) { - if (2 > e.length) { - e.pop(); + for (let e = 0, d; e < c.length; e++) { + if (d = c[e]) { + if (2 > d.length) { + d.pop(); } else { - const f = e.indexOf(a); - f === c.length - 1 ? e.pop() : e.splice(f, 1); + const f = d.indexOf(a); + f === c.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - cb(this.map, a), this.depth && cb(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.T && db(this)); + this.db && (this.commit_task.push({del:a}), this.T && sb(this)); this.cache && this.cache.remove(a); return this; }; -function cb(a, b) { +function rb(a, b) { let c = 0; - var d = "undefined" === typeof b; + var e = "undefined" === typeof b; if (a.constructor === Array) { - for (let e = 0, f, g; e < a.length; e++) { - if ((f = a[e]) && f.length) { - if (d) { + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && f.length) { + if (e) { c++; } else { if (g = f.indexOf(b), 0 <= g) { - 1 < f.length ? (f.splice(g, 1), c++) : delete a[e]; + 1 < f.length ? (f.splice(g, 1), c++) : delete a[d]; break; } else { c++; @@ -1918,67 +2097,67 @@ function cb(a, b) { } } } else { - for (let e of a.entries()) { - d = e[0]; - const f = cb(e[1], b); - f ? c += f : a.delete(d); + for (let d of a.entries()) { + e = d[0]; + const f = rb(d[1], b); + f ? c += f : a.delete(e); } } return c; } -;const eb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -N.prototype.add = function(a, b, c, d) { +;const tb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +P.prototype.add = function(a, b, c, e) { if (b && (a || 0 === a)) { - if (!d && !c && this.reg.has(a)) { + if (!e && !c && this.reg.has(a)) { return this.update(a, b); } - d = this.depth; - b = this.encoder.encode(b, !d); + e = this.depth; + b = this.encoder.encode(b, !e); const l = b.length; if (l) { - const m = A(), n = A(), p = this.resolution; - for (let r = 0; r < l; r++) { - let q = b[this.rtl ? l - 1 - r : r]; - var e = q.length; - if (e && (d || !n[q])) { - var f = this.score ? this.score(b, q, r, null, 0) : fb(p, l, r), g = ""; + const m = G(), n = G(), r = this.resolution; + for (let q = 0; q < l; q++) { + let t = b[this.rtl ? l - 1 - q : q]; + var d = t.length; + if (d && (e || !n[t])) { + var f = this.score ? this.score(b, t, q, null, 0) : ub(r, l, q), g = ""; switch(this.tokenize) { case "full": - if (2 < e) { - for (let t = 0, v; t < e; t++) { - for (f = e; f > t; f--) { - g = q.substring(t, f); - v = this.rtl ? e - 1 - t : t; - var h = this.score ? this.score(b, q, r, g, v) : fb(p, l, r, e, v); - gb(this, n, g, h, a, c); + if (2 < d) { + for (let u = 0, p; u < d; u++) { + for (f = d; f > u; f--) { + g = t.substring(u, f); + p = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(b, t, q, g, p) : ub(r, l, q, d, p); + vb(this, n, g, k, a, c); } } break; } case "bidirectional": case "reverse": - if (1 < e) { - for (h = e - 1; 0 < h; h--) { - g = q[this.rtl ? e - 1 - h : h] + g; - var k = this.score ? this.score(b, q, r, g, h) : fb(p, l, r, e, h); - gb(this, n, g, k, a, c); + if (1 < d) { + for (k = d - 1; 0 < k; k--) { + g = t[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(b, t, q, g, k) : ub(r, l, q, d, k); + vb(this, n, g, h, a, c); } g = ""; } case "forward": - if (1 < e) { - for (h = 0; h < e; h++) { - g += q[this.rtl ? e - 1 - h : h], gb(this, n, g, f, a, c); + if (1 < d) { + for (k = 0; k < d; k++) { + g += t[this.rtl ? d - 1 - k : k], vb(this, n, g, f, a, c); } break; } default: - if (gb(this, n, q, f, a, c), d && 1 < l && r < l - 1) { - for (e = A(), g = this.U, f = q, h = Math.min(d + 1, this.rtl ? r + 1 : l - r), e[f] = 1, k = 1; k < h; k++) { - if ((q = b[this.rtl ? l - 1 - r - k : r + k]) && !e[q]) { - e[q] = 1; - const t = this.score ? this.score(b, f, r, q, k - 1) : fb(g + (l / 2 > g ? 0 : 1), l, r, h - 1, k - 1), v = this.bidirectional && q > f; - gb(this, m, v ? f : q, t, a, c, v ? q : f); + if (vb(this, n, t, f, a, c), e && 1 < l && q < l - 1) { + for (d = G(), g = this.U, f = t, k = Math.min(e + 1, this.rtl ? q + 1 : l - q), d[f] = 1, h = 1; h < k; h++) { + if ((t = b[this.rtl ? l - 1 - q - h : q + h]) && !d[t]) { + d[t] = 1; + const u = this.score ? this.score(b, f, q, t, h - 1) : ub(g + (l / 2 > g ? 0 : 1), l, q, k - 1, h - 1), p = this.bidirectional && t > f; + vb(this, m, p ? f : t, u, a, c, p ? t : f); } } } @@ -1990,154 +2169,154 @@ N.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && db(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && sb(this)); return this; }; -function gb(a, b, c, d, e, f, g) { - let h = g ? a.ctx : a.map, k; - if (!b[c] || g && !(k = b[c])[g]) { - if (g ? (b = k || (b[c] = A()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { - if (h.length === 2 ** 31 - 1) { - b = new R(h); +function vb(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] = G()), 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 T(k); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(h) && (l[l.indexOf(h)] = b); + l.includes(k) && (l[l.indexOf(k)] = b); } } - k[d] = h = b; + h[e] = k = b; } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + k.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } } -function fb(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; +function ub(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; } -;N.prototype.search = function(a, b, c) { +;P.prototype.search = function(a, b, c) { c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); - let d = [], e, f, g, h = 0, k, l, m, n, p; - c ? (a = c.query || a, b = c.limit || b, h = c.offset || 0, f = c.context, g = c.suggest, p = (k = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : k = this.resolve; + let e = [], d, f, g, k = 0, h, l, m, n, r; + c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, r = (h = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : h = this.resolve; f = this.depth && !1 !== f; - let r = this.encoder.encode(a, !f); - e = r.length; - b = b || (k ? 100 : 0); - if (1 === e) { - return hb.call(this, r[0], "", b, h, k, p, l); + let q = this.encoder.encode(a, !f); + d = q.length; + b = b || (h ? 100 : 0); + if (1 === d) { + return wb.call(this, q[0], "", b, k, h, r, l); } - if (2 === e && f && !g) { - return hb.call(this, r[1], r[0], b, h, k, p, l); + if (2 === d && f && !g) { + return wb.call(this, q[1], q[0], b, k, h, r, l); } - let q = A(), t = 0, v; - f && (v = r[0], t = 1); - n || 0 === n || (n = v ? this.U : this.resolution); + let t = G(), u = 0, p; + f && (p = q[0], u = 1); + n || 0 === n || (n = p ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, r, b, h, g, k, p, l), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, q, b, k, g, h, r, l), !1 !== a)) { return a; } - const w = this; + const z = this; return async function() { - for (let x, F; t < e; t++) { - if ((F = r[t]) && !q[F]) { - q[F] = 1; - x = await ib(w, F, v, 0, 0, !1, !1); - if (x = jb(x, d, g, n)) { - d = x; + for (let x, J; u < d; u++) { + if ((J = q[u]) && !t[J]) { + t[J] = 1; + x = await xb(z, J, p, 0, 0, !1, !1); + if (x = yb(x, e, g, n)) { + e = x; break; } - v && (g && x && d.length || (v = F)); + p && (g && x && e.length || (p = J)); } - g && v && t === e - 1 && !d.length && (n = w.resolution, v = "", t = -1, q = A()); + g && p && u === d - 1 && !e.length && (n = z.resolution, p = "", u = -1, t = G()); } - return kb(d, n, b, h, g, m, k); + return zb(e, n, b, k, g, m, h); }(); } - for (let w, x; t < e; t++) { - if ((x = r[t]) && !q[x]) { - q[x] = 1; - w = ib(this, x, v, 0, 0, !1, !1); - if (w = jb(w, d, g, n)) { - d = w; + for (let z, x; u < d; u++) { + if ((x = q[u]) && !t[x]) { + t[x] = 1; + z = xb(this, x, p, 0, 0, !1, !1); + if (z = yb(z, e, g, n)) { + e = z; break; } - v && (g && w && d.length || (v = x)); + p && (g && z && e.length || (p = x)); } - g && v && t === e - 1 && !d.length && (n = this.resolution, v = "", t = -1, q = A()); + g && p && u === d - 1 && !e.length && (n = this.resolution, p = "", u = -1, t = G()); } - return kb(d, n, b, h, g, m, k); + return zb(e, n, b, k, g, m, h); }; -function kb(a, b, c, d, e, f, g) { - let h = a.length, k = a; - if (1 < h) { - k = Fa(a, b, c, d, e, f, g); - } else if (1 === h) { - return g ? Ia.call(null, a[0], c, d) : new W(a[0]); +function zb(a, b, c, e, d, f, g) { + let k = a.length, h = a; + if (1 < k) { + h = Sa(a, b, c, e, d, f, g); + } else if (1 === k) { + return g ? Va.call(null, a[0], c, e) : new Y(a[0]); } - return g ? k : new W(k); + return g ? h : new Y(h); } -function hb(a, b, c, d, e, f, g) { - a = ib(this, a, b, c, d, e, f, g); - return this.db ? a.then(function(h) { - return e ? h || [] : new W(h); - }) : a && a.length ? e ? Ia.call(this, a, c, d) : new W(a) : e ? [] : new W(); +function wb(a, b, c, e, d, f, g) { + a = xb(this, a, b, c, e, d, f, g); + return this.db ? a.then(function(k) { + return d ? k || [] : new Y(k); + }) : a && a.length ? d ? Va.call(this, a, c, e) : new Y(a) : d ? [] : new Y(); } -function jb(a, b, c, d) { - let e = []; +function yb(a, b, c, e) { + let d = []; if (a && a.length) { - if (a.length <= d) { + if (a.length <= e) { b.push(a); return; } - for (let f = 0, g; f < d; f++) { + for (let f = 0, g; f < e; f++) { if (g = a[f]) { - e[f] = g; + d[f] = g; } } - if (e.length) { - b.push(e); + if (d.length) { + b.push(d); return; } } if (!c) { - return e; + return d; } } -function ib(a, b, c, d, e, f, g, h) { - let k; - c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); +function xb(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) { - return a.db.get(b, c, d, e, f, g, h); + 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; } -;function N(a, b) { - if (!this || this.constructor !== N) { - return new N(a); +;function P(a, b) { + if (!this || this.constructor !== P) { + return new P(a); } if (a) { - var c = D(a) ? a : a.preset; - c && (eb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, eb[c], a)); + var c = L(a) ? a : a.preset; + c && (tb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, tb[c], a)); } else { a = {}; } c = a.context; - const d = !0 === c ? {depth:1} : c || {}, e = D(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || {}; - this.encoder = e.encode ? e : "object" === typeof e ? new G(e) : {encode:e}; + const e = !0 === c ? {depth:1} : c || {}, d = L(a.encoder) ? qb[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : "object" === typeof d ? new ma(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = c = (c = a.tokenize) && "default" !== c && "exact" !== c && c || "strict"; - this.depth = "strict" === c && d.depth || 0; - this.bidirectional = !1 !== d.bidirectional; + this.depth = "strict" === c && e.depth || 0; + this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; - d && d.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); + e && e.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); (c = a.keystore || 0) && (this.keystore = c); - this.map = c ? new S(c) : new Map(); - this.ctx = c ? new S(c) : new Map(); - this.reg = b || (this.fastupdate ? c ? new S(c) : new Map() : c ? new T(c) : new Set()); - this.U = d.resolution || 3; - this.rtl = e.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new X(c); + 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.U = e.resolution || 3; + this.rtl = d.rtl || a.rtl || !1; + this.cache = (c = a.cache || null) && new hb(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); @@ -2147,26 +2326,26 @@ function ib(a, b, c, d, e, f, g, h) { this.commit_timer = null; this.priority = a.priority || 4; } -u = N.prototype; -u.mount = function(a) { +v = P.prototype; +v.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -u.commit = function(a, b) { +v.commit = function(a, b) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.commit(this, a, b); }; -u.destroy = function() { +v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function db(a) { +function sb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 1)); } -u.clear = function() { +v.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -2174,90 +2353,90 @@ u.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -u.append = function(a, b) { +v.append = function(a, b) { return this.add(a, b, !0); }; -u.contain = function(a) { +v.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -u.update = function(a, b) { - const c = this, d = this.remove(a); - return d && d.then ? d.then(() => c.add(a, b)) : this.add(a, b); +v.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); }; -u.cleanup = function() { +v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - cb(this.map); - this.depth && cb(this.ctx); + rb(this.map); + this.depth && rb(this.ctx); return this; }; -u.searchCache = Va; -u.export = function(a, b, c = 0, d = 0) { - let e, f; - switch(d) { +v.searchCache = jb; +v.export = function(a, b, c = 0, e = 0) { + let d, f; + switch(e) { case 0: - e = "reg"; - f = wa(this.reg); + d = "reg"; + f = Ga(this.reg); break; case 1: - e = "cfg"; + d = "cfg"; f = null; break; case 2: - e = "map"; - f = sa(this.map, this.reg.size); + d = "map"; + f = Ca(this.map, this.reg.size); break; case 3: - e = "ctx"; - f = ua(this.ctx, this.reg.size); + d = "ctx"; + f = Ea(this.ctx, this.reg.size); break; default: return; } - return ya.call(this, a, b, e, f, c, d); + return Ia.call(this, a, b, d, f, c, e); }; -u.import = function(a, b) { +v.import = function(a, b) { if (b) { switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = xa(b, this.reg); + this.reg = Ha(b, this.reg); break; case "map": - this.map = ta(b, this.map); + this.map = Da(b, this.map); break; case "ctx": - this.ctx = va(b, this.ctx); + this.ctx = Fa(b, this.ctx); } } }; -u.serialize = function(a = !0) { - let b = "", c = "", d = ""; +v.serialize = function(a = !0) { + let b = "", c = "", e = ""; if (this.reg.size) { let f; - for (var e of this.reg.keys()) { - f || (f = typeof e), b += (b ? "," : "") + ("string" === f ? '"' + e + '"' : e); + for (var d of this.reg.keys()) { + f || (f = typeof d), b += (b ? "," : "") + ("string" === f ? '"' + d + '"' : d); } b = "index.reg=new Set([" + b + "]);"; - c = za(this.map, f); + c = La(this.map, f); c = "index.map=new Map([" + c + "]);"; for (const g of this.ctx.entries()) { - e = g[0]; - let h = za(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + e + '",' + h + "]"; - d += (d ? "," : "") + h; + d = g[0]; + let k = La(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } - d = "index.ctx=new Map([" + d + "]);"; + e = "index.ctx=new Map([" + e + "]);"; } - return a ? "function inject(index){" + b + c + d + "}" : b + c + d; + return a ? "function inject(index){" + b + c + e + "}" : b + c + e; }; -la(N.prototype); -const lb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), mb = ["map", "ctx", "tag", "reg", "cfg"], Y = A(); -function nb(a, b = {}) { - if (!this || this.constructor !== nb) { - return new nb(a, b); +ra(P.prototype); +const Ab = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Bb = ["map", "ctx", "tag", "reg", "cfg"], Cb = G(); +function Db(a, b = {}) { + if (!this || this.constructor !== Db) { + return new Db(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2268,29 +2447,29 @@ function nb(a, b = {}) { this.db = null; this.h = {}; } -u = nb.prototype; -u.mount = function(a) { +v = Db.prototype; +v.mount = function(a) { if (a.index) { return a.mount(this); } a.db = this; return this.open(); }; -u.open = function() { +v.open = function() { if (this.db) { return this.db; } let a = this; navigator.storage && navigator.storage.persist(); - Y[a.id] || (Y[a.id] = []); - Y[a.id].push(a.field); - const b = lb.open(a.id, 1); + Cb[a.id] || (Cb[a.id] = []); + Cb[a.id].push(a.field); + const b = Ab.open(a.id, 1); b.onupgradeneeded = function() { const c = a.db = this.result; - for (let d = 0, e; d < mb.length; d++) { - e = mb[d]; - for (let f = 0, g; f < Y[a.id].length; f++) { - g = Y[a.id][f], c.objectStoreNames.contains(e + ("reg" !== e ? g ? ":" + g : "" : "")) || c.createObjectStore(e + ("reg" !== e ? g ? ":" + g : "" : "")); + for (let e = 0, d; e < Bb.length; e++) { + d = Bb[e]; + for (let f = 0, g; f < Cb[a.id].length; f++) { + g = Cb[a.id][f], c.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || c.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } } }; @@ -2301,20 +2480,20 @@ u.open = function() { }; }); }; -u.close = function() { +v.close = function() { this.db && this.db.close(); this.db = null; }; -u.destroy = function() { - const a = lb.deleteDatabase(this.id); +v.destroy = function() { + const a = Ab.deleteDatabase(this.id); return Z(a); }; -u.clear = function() { +v.clear = function() { const a = []; - for (let c = 0, d; c < mb.length; c++) { - d = mb[c]; - for (let e = 0, f; e < Y[this.id].length; e++) { - f = Y[this.id][e], a.push(d + ("reg" !== d ? f ? ":" + f : "" : "")); + for (let c = 0, e; c < Bb.length; c++) { + e = Bb[c]; + for (let d = 0, f; d < Cb[this.id].length; d++) { + f = Cb[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } } const b = this.db.transaction(a, "readwrite"); @@ -2323,42 +2502,42 @@ u.clear = function() { } return Z(b); }; -u.get = function(a, b, c = 0, d = 0, e = !0, f = !1) { +v.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); const g = this; - return Z(a).then(function(h) { - let k = []; - if (!h || !h.length) { - return k; + return Z(a).then(function(k) { + let h = []; + if (!k || !k.length) { + return h; } - if (e) { - if (!c && !d && 1 === h.length) { - return h[0]; + if (d) { + if (!c && !e && 1 === k.length) { + return k[0]; } - for (let l = 0, m; l < h.length; l++) { - if ((m = h[l]) && m.length) { - if (d >= m.length) { - d -= m.length; + for (let l = 0, m; l < k.length; l++) { + if ((m = k[l]) && m.length) { + if (e >= m.length) { + e -= m.length; continue; } - const n = c ? d + Math.min(m.length - d, c) : m.length; - for (let p = d; p < n; p++) { - k.push(m[p]); + const n = c ? e + Math.min(m.length - e, c) : m.length; + for (let r = e; r < n; r++) { + h.push(m[r]); } - d = 0; - if (k.length === c) { + e = 0; + if (h.length === c) { break; } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; -u.tag = function(a, b = 0, c = 0, d = !1) { +v.tag = function(a, b = 0, c = 0, e = !1) { a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); - const e = this; + const d = this; return Z(a).then(function(f) { if (!f || !f.length || c >= f.length) { return []; @@ -2367,107 +2546,107 @@ u.tag = function(a, b = 0, c = 0, d = !1) { return f; } f = f.slice(c, c + b); - return d ? e.enrich(f) : f; + return e ? d.enrich(f) : f; }); }; -u.enrich = function(a) { +v.enrich = function(a) { "object" !== typeof a && (a = [a]); const b = this.db.transaction("reg", "readonly").objectStore("reg"), c = []; - for (let d = 0; d < a.length; d++) { - c[d] = Z(b.get(a[d])); + for (let e = 0; e < a.length; e++) { + c[e] = Z(b.get(a[e])); } - return Promise.all(c).then(function(d) { - for (let e = 0; e < d.length; e++) { - d[e] = {id:a[e], doc:d[e] ? JSON.parse(d[e]) : null}; + return Promise.all(c).then(function(e) { + for (let d = 0; d < e.length; d++) { + e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null}; } - return d; + return e; }); }; -u.has = function(a) { +v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); return Z(a).then(function(b) { return !!b; }); }; -u.search = null; -u.info = function() { +v.search = null; +v.info = function() { }; -u.transaction = function(a, b, c) { +v.transaction = function(a, b, c) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; - let d = this.h[a + ":" + b]; - if (d) { - return c.call(this, d); + let e = this.h[a + ":" + b]; + if (e) { + return c.call(this, e); } - let e = this.db.transaction(a, b); - this.h[a + ":" + b] = d = e.objectStore(a); - const f = c.call(this, d); + let d = this.db.transaction(a, b); + this.h[a + ":" + b] = e = d.objectStore(a); + const f = c.call(this, e); this.h[a + ":" + b] = null; - return Z(e).finally(function() { - e = d = null; + return Z(d).finally(function() { + d = e = null; return f; }); }; -u.commit = async function(a, b, c) { +v.commit = async function(a, b, c) { if (b) { await this.clear(), a.commit_task = []; } else { - let d = a.commit_task; + let e = a.commit_task; a.commit_task = []; - for (let e = 0, f; e < d.length; e++) { - if (f = d[e], f.clear) { + for (let d = 0, f; d < e.length; d++) { + if (f = e[d], f.clear) { await this.clear(); b = !0; break; } else { - d[e] = f.del; + e[d] = f.del; } } - b || (c || (d = d.concat(ba(a.reg))), d.length && await this.remove(d)); + b || (c || (e = e.concat(da(a.reg))), e.length && await this.remove(e)); } - a.reg.size && (await this.transaction("map", "readwrite", function(d) { - for (const e of a.map) { - const f = e[0], g = e[1]; - g.length && (b ? d.put(g, f) : d.get(f).onsuccess = function() { - let h = this.result; - var k; - if (h && h.length) { - const l = Math.max(h.length, g.length); - for (let m = 0, n, p; m < l; m++) { - if ((p = g[m]) && p.length) { - if ((n = h[m]) && n.length) { - for (k = 0; k < p.length; k++) { - n.push(p[k]); + a.reg.size && (await this.transaction("map", "readwrite", function(e) { + for (const d of a.map) { + const f = d[0], g = d[1]; + g.length && (b ? e.put(g, f) : e.get(f).onsuccess = function() { + let k = this.result; + var h; + if (k && k.length) { + const l = Math.max(k.length, g.length); + for (let m = 0, n, r; m < l; m++) { + if ((r = g[m]) && r.length) { + if ((n = k[m]) && n.length) { + for (h = 0; h < r.length; h++) { + n.push(r[h]); } } else { - h[m] = p; + k[m] = r; } - k = 1; + h = 1; } } } else { - h = g, k = 1; + k = g, h = 1; } - k && d.put(h, f); + h && e.put(k, f); }); } - }), await this.transaction("ctx", "readwrite", function(d) { - for (const e of a.ctx) { - const f = e[0], g = e[1]; - for (const h of g) { - const k = h[0], l = h[1]; - l.length && (b ? d.put(l, f + ":" + k) : d.get(f + ":" + k).onsuccess = function() { + }), await this.transaction("ctx", "readwrite", function(e) { + for (const d of a.ctx) { + const f = d[0], g = d[1]; + for (const k of g) { + const h = k[0], l = k[1]; + l.length && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { let m = this.result; var n; if (m && m.length) { - const p = Math.max(m.length, l.length); - for (let r = 0, q, t; r < p; r++) { - if ((t = l[r]) && t.length) { - if ((q = m[r]) && q.length) { - for (n = 0; n < t.length; n++) { - q.push(t[n]); + const r = Math.max(m.length, l.length); + for (let q = 0, t, u; q < r; q++) { + if ((u = l[q]) && u.length) { + if ((t = m[q]) && t.length) { + for (n = 0; n < u.length; n++) { + t.push(u[n]); } } else { - m[r] = t; + m[q] = u; } n = 1; } @@ -2475,70 +2654,70 @@ u.commit = async function(a, b, c) { } else { m = l, n = 1; } - n && d.put(m, f + ":" + k); + n && e.put(m, f + ":" + h); }); } } - }), a.store ? await this.transaction("reg", "readwrite", function(d) { - for (const e of a.store) { - const f = e[0], g = e[1]; - d.put("object" === typeof g ? JSON.stringify(g) : 1, f); + }), a.store ? await this.transaction("reg", "readwrite", function(e) { + for (const d of a.store) { + const f = d[0], g = d[1]; + e.put("object" === typeof g ? JSON.stringify(g) : 1, f); } - }) : a.bypass || await this.transaction("reg", "readwrite", function(d) { - for (const e of a.reg.keys()) { - d.put(1, e); + }) : a.bypass || await this.transaction("reg", "readwrite", function(e) { + for (const d of a.reg.keys()) { + e.put(1, d); } - }), a.tag && await this.transaction("tag", "readwrite", function(d) { - for (const e of a.tag) { - const f = e[0], g = e[1]; - g.length && (d.get(f).onsuccess = function() { - let h = this.result; - h = h && h.length ? h.concat(g) : g; - d.put(h, f); + }), a.tag && await this.transaction("tag", "readwrite", function(e) { + for (const d of a.tag) { + const f = d[0], g = d[1]; + g.length && (e.get(f).onsuccess = function() { + let k = this.result; + k = k && k.length ? k.concat(g) : g; + e.put(k, f); }); } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function pb(a, b, c) { - const d = a.value; - let e, f = 0; - for (let g = 0, h; g < d.length; g++) { - if (h = c ? d : d[g]) { - for (let k = 0, l, m; k < b.length; k++) { - if (m = b[k], l = h.indexOf(m), 0 <= l) { - if (e = 1, 1 < h.length) { - h.splice(l, 1); +function Eb(a, b, c) { + const e = a.value; + let d, f = 0; + for (let g = 0, k; g < e.length; g++) { + if (k = c ? e : e[g]) { + for (let h = 0, l, m; h < b.length; h++) { + if (m = b[h], l = k.indexOf(m), 0 <= l) { + if (d = 1, 1 < k.length) { + k.splice(l, 1); } else { - d[g] = []; + e[g] = []; break; } } } - f += h.length; + f += k.length; } if (c) { break; } } - f ? e && a.update(d) : a.delete(); + f ? d && a.update(e) : a.delete(); a.continue(); } -u.remove = function(a) { +v.remove = function(a) { "object" !== typeof a && (a = [a]); return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && pb(c, a); + c && Eb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && pb(c, a); + c && Eb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && pb(c, a, !0); + c && Eb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2547,16 +2726,16 @@ u.remove = function(a) { })]); }; function Z(a, b) { - return new Promise((c, d) => { + return new Promise((c, e) => { a.onsuccess = a.oncomplete = function() { b && b(this.result); b = null; c(this.result); }; - a.onerror = a.onblocked = d; + a.onerror = a.onblocked = e; a = null; }); } -;export default {Index:N, Charset:bb, Encoder:G, Document:U, Worker:P, Resolver:W, IndexedDB:nb, Language:{}}; +;export default {Index:P, Charset:qb, Encoder:ma, Document:Pa, Worker:Aa, Resolver:Y, IndexedDB:Db, Language:{}}; -export const Index=N;export const Charset=bb;export const Encoder=G;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=nb;export const Language={}; \ No newline at end of file +export const Index=P;export const Charset=qb;export const Encoder=ma;export const Document=Pa;export const Worker=Aa;export const Resolver=Y;export const IndexedDB=Db;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 13cbe02..508cee1 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,95 +1,100 @@ /**! - * FlexSearch.js v0.8.158 (Bundle/Module) + * FlexSearch.js v0.8.160 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u;function z(a,b,c){const d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===e?b:a}function A(){return Object.create(null)}function D(a){return"string"===typeof a} -function G(a){return"object"===typeof a}function aa(a){const b=[];for(const c of a.keys())b.push(c);return b}function ba(a,b){if(D(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; -this.numeric=z(a.numeric,d)}else{try{this.split=z(this.split,da)}catch(e){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:z(c&&new Set(c),null,this.filter);this.dedupe=z(a.dedupe,!0,this.dedupe);this.matcher=z((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=z((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=z((c=a.stemmer)&&new Map(c), -null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,1024,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=c=z(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const e of this.matcher.keys())this.h+=(this.h?"|":"")+e;if(this.stemmer)for(const e of this.stemmer.keys())this.A+= -(this.A?"|":"")+e;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&I(this);return this};u.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&I(this);return this}; -u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&I(this);return this}; -u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&I(this);return this}; -u.encode=function(a,b){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(I,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ia?a.normalize("NFKD").replace(ia,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(e[m])continue;e[m]=1}else{if(f===m)continue;f=m}if(c)d.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var k=this.G.get(m);if(k||""===k){k&&d.push(k);continue}}else this.H=setTimeout(I,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ -this.A+")$"));let p;for(;p!==m&&2this.stemmer.get(r))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(p)));if(m&&this.replacer)for(k=0;m&&kthis.S&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==n)if(b){if(e[m])continue;e[m]=1}else{if(g===m)continue;g=m}d.push(m)}}}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.K&&(this.B.set(a,d),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return d};function I(a){a.H=null;a.B.clear();a.G.clear()};let K,ja;async function ka(a){a=a.data;var b=a.task;const c=a.id;let d=a.args;switch(b){case "init":ja=a.options||{};(b=a.factory)?(Function("return "+b)()(self),K=new self.FlexSearch.Index(ja),delete self.FlexSearch):K=new M(ja);postMessage({id:c});break;default:let e;"export"===b&&(d[1]?(d[0]=ja.export,d[2]=0,d[3]=1):d=null);"import"===b?d[0]&&(a=await ja.import.call(K,d[0]),K.import(d[0],a)):(e=d&&K[b].apply(K,d))&&e.then&&(e=await e);postMessage("search"===b?{id:c,msg:e}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} -function ma(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const e=this[a].apply(this,b);c=e.then?e:new Promise(f=>f(e));d&&c.then(d);return c}};let N=0; -function P(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=A();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++N]=function(){k(e);1E9=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} -function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e= -[];for(let n=0,p;nd)d-=p.length;else{if(p.length>c||d)p=p.slice(d,c+d),c-=p.length,d&&(d-=p.length);e.push(p);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?V.call(this,a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!e.length&&h>=b)return d?V.call(this,g):g;e.push(g);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=Ga(a,c,d,!1,this.h),d=0));return f?this.resolve(c,d,e):this};W.prototype.and=function(){let a=this.result.length,b,c,d,e;if(!a){const f=arguments[0];f&&(a=!!f.suggest,e=f.resolve,b=f.limit,c=f.offset,d=f.enrich&&e)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,m,n)}return e?this.resolve(b,c,d):this}; -function La(a,b,c,d,e,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,d,g,this.h,f),f?e?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,d,e):this};W.prototype.xor=function(){const {O:a,P:b,limit:c,offset:d,enrich:e,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,d,e,f,g)}; -function Ma(a,b,c,d,e,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,d,f,this.h),f?e?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,d,e):this} -function Na(a,b,c,d,e){const f=[],g=A();let h=0;for(let k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -X.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};X.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:!1,numeric:!1,dedupe:!1};const Xa={};const Ya=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 Za=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),$a=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ab={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 bb={Exact:Wa,Default:Xa,Normalize:Xa,LatinBalance:{mapper:Ya},LatinAdvanced:{mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;ce.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else cb(this.map,a),this.depth&&cb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&db(this));this.cache&&this.cache.remove(a);return this}; -function cb(a,b){let c=0;var d="undefined"===typeof b;if(a.constructor===Array)for(let e=0,f,g;et;f--){g=q.substring(t,f);v=this.rtl?e-1-t:t;var h=this.score?this.score(b,q,r,g,v):fb(p, -l,r,e,v);gb(this,n,g,h,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,r,h-1,k-1),v=this.bidirectional&&q>f;gb(this,m,v?f:q,t,a,c,v?q:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&db(this));return this}; -function gb(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=A()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function fb(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,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function M(a,b){if(!this||this.constructor!==M)return new M(a);if(a){var c=D(a)?a:a.preset;c&&(a=Object.assign({},eb[c],a))}else a={};c=a.context;const d=!0===c?{depth:1}:c||{},e=D(a.encoder)?bb[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new H(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&d.depth||0;this.bidirectional=!1!==d.bidirectional;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new S(c):new Map;this.ctx=c?new S(c):new Map;this.reg=b||(this.fastupdate?c?new S(c):new Map:c?new T(c):new Set);this.U=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new X(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.T=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}u=M.prototype; -u.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};u.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};u.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function db(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} -u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};u.update=function(a,b){const c=this,d=this.remove(a);return d&&d.then?d.then(()=>c.add(a,b)):this.add(a,b)}; -u.cleanup=function(){if(!this.fastupdate)return this;cb(this.map);this.depth&&cb(this.ctx);return this};u.searchCache=Va;u.export=function(a,b,c=0,d=0){let e,f;switch(d){case 0:e="reg";f=wa(this.reg);break;case 1:e="cfg";f=null;break;case 2:e="map";f=sa(this.map,this.reg.size);break;case 3:e="ctx";f=ua(this.ctx,this.reg.size);break;default:return}return ya.call(this,a,b,e,f,c,d)}; -u.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let p=d;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=d;a=null})};export default {Index:M,Charset:bb,Encoder:H,Document:U,Worker:P,Resolver:W,IndexedDB:ob,Language:{}}; -export const Index=M;export const Charset=bb;export const Encoder=H;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=ob;export const Language={}; \ No newline at end of file +var v;function F(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(k){return a(c(k))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function G(){return Object.create(null)}function L(a){return"string"===typeof a} +function ca(a){return"object"===typeof a}function da(a){const b=[];for(const c of a.keys())b.push(c);return b}function ea(a,b){if(L(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; +this.numeric=F(a.numeric,e)}else{try{this.split=F(this.split,ha)}catch(d){this.split=/\s+/}this.numeric=F(a.numeric,F(this.numeric,!0))}this.prepare=F(a.prepare,null,this.prepare);this.finalize=F(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:F(c&&new Set(c),null,this.filter);this.dedupe=F(a.dedupe,!0,this.dedupe);this.matcher=F((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=F((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=F((c=a.stemmer)&&new Map(c), +null,this.stemmer);this.replacer=F(a.replacer,null,this.replacer);this.minlength=F(a.minlength,1,this.minlength);this.maxlength=F(a.maxlength,1024,this.maxlength);this.rtl=F(a.rtl,!1,this.rtl);if(this.cache=c=F(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};v.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&N(this);return this};v.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&N(this);return this}; +v.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&N(this);return this}; +v.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&N(this);return this}; +v.encode=function(a,b){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(N,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=la?a.normalize("NFKD").replace(la,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(c)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var h=this.G.get(m);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(N,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ +this.A+")$"));let r;for(;r!==m&&2this.stemmer.get(q))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(r)));if(m&&this.replacer)for(h=0;m&&hthis.S&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==n)if(b){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.B.set(a,e),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return e};function N(a){a.H=null;a.B.clear();a.G.clear()};let pa,qa;async function ra(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":qa=a.options||{};(b=a.factory)?(Function("return "+b)()(self),pa=new self.FlexSearch.Index(qa),delete self.FlexSearch):pa=new O(qa);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=qa.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await qa.import.call(pa,e[0]),pa.import(e[0],a)):(d=e&&pa[b].apply(pa,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function sa(a){ta.call(a,"add");ta.call(a,"append");ta.call(a,"search");ta.call(a,"update");ta.call(a,"remove")}let wa,xa,ya;function za(){wa=ya=0} +function ta(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]);wa?ya||(ya=Date.now()-xa>=this.priority*this.priority*3):(wa=setTimeout(za,0),xa=Date.now());if(ya){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 Aa=0; +function Ba(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=G();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++Aa]=function(){h(d);1E9=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 R(a){if(!this||this.constructor!==R)return new R(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,r;ne)e-=r.length;else{if(r.length>c||e)r=r.slice(e,c+e),c-=r.length,e&&(e-=r.length);d.push(r);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?X.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?X.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ta(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};Y.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}=Wa(this,"and",arguments);return Ya.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; +function Ya(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=fa(a))return this.result=Sa(a,b,c,e,g,this.h,f),f?d?X.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};Y.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Wa(this,"xor",arguments);return Za.call(this,a,b,c,e,d,f,g)}; +function Za(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=$a.call(this,a,c,e,f,this.h),f?d?X.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function $a(a,b,c,e,d){const f=[],g=G();let k=0;for(let h=0,l;hJ&&(J=p.length+(p?1:0)),B=p.length+(p?1:0)+M.length,z+=E,va.push(x.length),x.push({match:M})),p+=(p?" ":"")+M)}if(!w)C=y[A],p+=(p?" ":"")+C,h&&x.push({text:C});else if(h&&z>=h)break}z=va.length*(f.length-2);if(q||t||h&&p.length-z>h)if(z=h+z-2*r,A=B-J, +0y&&(y=0)),x=x.length-1){if(I>= +x.length){A[w+1]=1;I>=y.length&&(z[w+1]=1);continue}E-=r}p=x[I].text;if(K=t&&D[w])if(0K)if(A[w+1]=1,l)p=p.substring(0,K);else continue;(K-=p.length)||(K=-1);D[w]=K}else{A[w+1]=1;continue}if(E+p.length+1<=h)p=" "+p,B[w]+=p;else if(l)S=h-E-1,0=I){if(0>I){A[w]=1;z[w]=1;continue}E-=r}p=x[I].text;if(K=q&&C[w])if(0K)if(A[w]=1,l)p=p.substring(p.length- +K);else continue;(K-=p.length)||(K=-1);C[w]=K}else{A[w]=1;continue}if(E+p.length+1<=h)p+=" ",B[w]=p+B[w];else if(l)S=p.length+1-(h-E),0<=S&&S=y.length-1?Ka=1:Ic||e)a=a.slice(e,e+c);d&&(a=X.call(this,a));return a}} +function X(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)}; +hb.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};hb.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};hb.prototype.clear=function(){this.cache.clear();this.h=""};const kb={normalize:!1,numeric:!1,dedupe:!1};const lb={};const mb=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 nb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ob=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const pb={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 qb={Exact:kb,Default:lb,Normalize:lb,LatinBalance:{mapper:mb},LatinAdvanced:{mapper:mb,matcher:nb,replacer:ob},LatinExtra:{mapper:mb,replacer:ob.concat([/(?!^)[aeo]/g,""]),matcher:nb},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cd.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,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.T&&sb(this));this.cache&&this.cache.remove(a);return this}; +function rb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;du;f--){g=t.substring(u,f);p=this.rtl?d-1-u:u;var k=this.score?this.score(b,t,q,g,p):ub(r, +l,q,d,p);vb(this,n,g,k,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,q,k-1,h-1),p=this.bidirectional&&t>f;vb(this,m,p?f:t,u,a,c,p?t:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&sb(this));return this}; +function vb(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]=G()),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 R(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 ub(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};function O(a,b){if(!this||this.constructor!==O)return new O(a);if(a){var c=L(a)?a:a.preset;c&&(a=Object.assign({},tb[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=L(a.encoder)?qb[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ma(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;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.U=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new hb(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.T=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}v=O.prototype; +v.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};v.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};v.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function sb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} +v.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};v.append=function(a,b){return this.add(a,b,!0)};v.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};v.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)}; +v.cleanup=function(){if(!this.fastupdate)return this;rb(this.map);this.depth&&rb(this.ctx);return this};v.searchCache=jb;v.export=function(a,b,c=0,e=0){let d,f;switch(e){case 0:d="reg";f=Ha(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=Da(this.map,this.reg.size);break;case 3:d="ctx";f=Fa(this.ctx,this.reg.size);break;default:return}return La.call(this,a,b,d,f,c,e)}; +v.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let r=e;r=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +v.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:O,Charset:qb,Encoder:ma,Document:W,Worker:Ba,Resolver:Y,IndexedDB:Db,Language:{}}; +export const Index=O;export const Charset=qb;export const Encoder=ma;export const Document=W;export const Worker=Ba;export const Resolver=Y;export const IndexedDB=Db;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 21f448e..5f82494 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,13 +1,13 @@ /**! - * FlexSearch.js v0.8.158 (Bundle/Debug) + * FlexSearch.js v0.8.160 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ (function(self){'use strict'; -var x; -function z(a, c, b) { +var A; +function I(a, c, b) { const e = typeof b, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { @@ -44,17 +44,17 @@ function z(a, c, b) { } return "undefined" === d ? c : a; } -function B() { +function J() { return Object.create(null); } -function C(a) { +function K(a) { return "string" === typeof a; } -function G(a) { +function M(a) { return "object" === typeof a; } -function H(a, c) { - if (C(c)) { +function Q(a, c) { + if (K(c)) { a = a[c]; } else { for (let b = 0; a && b < c.length; b++) { @@ -70,10 +70,10 @@ function aa(a) { } return c; } -;const ba = /[^\p{L}\p{N}]+/u, ca = /(\d{3})/g, da = /(\D)(\d{3})/g, ea = /(\d{3})(\D)/g, fa = /[\u0300-\u036f]/g; -function I(a = {}) { - if (!this || this.constructor !== I) { - return new I(...arguments); +;const ba = /[^\p{L}\p{N}]+/u, ea = /(\d{3})/g, fa = /(\D)(\d{3})/g, ha = /(\d{3})(\D)/g, ia = /[\u0300-\u036f]/g; +function ja(a = {}) { + if (!this || this.constructor !== ja) { + return new ja(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -83,9 +83,9 @@ function I(a = {}) { this.assign(a); } } -x = I.prototype; -x.assign = function(a) { - this.normalize = z(a.normalize, !0, this.normalize); +A = ja.prototype; +A.assign = function(a) { + this.normalize = I(a.normalize, !0, this.normalize); let c = a.include, b = c || a.exclude || a.split, e; if (b || "" === b) { if ("object" === typeof b && b.constructor !== RegExp) { @@ -108,28 +108,28 @@ x.assign = function(a) { } else { this.split = b, e = !1 === b || 2 > "a1a".split(b).length; } - this.numeric = z(a.numeric, e); + this.numeric = I(a.numeric, e); } else { try { - this.split = z(this.split, ba); + this.split = I(this.split, ba); } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = z(a.numeric, z(this.numeric, !0)); + this.numeric = I(a.numeric, I(this.numeric, !0)); } - this.prepare = z(a.prepare, null, this.prepare); - this.finalize = z(a.finalize, null, this.finalize); + this.prepare = I(a.prepare, null, this.prepare); + this.finalize = I(a.finalize, null, this.finalize); b = a.filter; - this.filter = "function" === typeof b ? b : z(b && new Set(b), null, this.filter); - this.dedupe = z(a.dedupe, !0, this.dedupe); - this.matcher = z((b = a.matcher) && new Map(b), null, this.matcher); - this.mapper = z((b = a.mapper) && new Map(b), null, this.mapper); - this.stemmer = z((b = a.stemmer) && new Map(b), null, this.stemmer); - this.replacer = z(a.replacer, null, this.replacer); - this.minlength = z(a.minlength, 1, this.minlength); - this.maxlength = z(a.maxlength, 1024, this.maxlength); - this.rtl = z(a.rtl, !1, this.rtl); - if (this.cache = b = z(a.cache, !0, this.cache)) { + this.filter = "function" === typeof b ? b : I(b && new Set(b), null, this.filter); + this.dedupe = I(a.dedupe, !0, this.dedupe); + this.matcher = I((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = I((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = I((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = I(a.replacer, null, this.replacer); + this.minlength = I(a.minlength, 1, this.minlength); + this.maxlength = I(a.maxlength, 1024, this.maxlength); + this.rtl = I(a.rtl, !1, this.rtl); + if (this.cache = b = I(a.cache, !0, this.cache)) { this.H = null, this.R = "number" === typeof b ? b : 2e5, this.F = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; @@ -148,20 +148,20 @@ x.assign = function(a) { } return this; }; -x.addStemmer = function(a, c) { +A.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); this.C += (this.C ? "|" : "") + a; this.N = null; - this.cache && J(this); + this.cache && R(this); return this; }; -x.addFilter = function(a) { +A.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && J(this); + this.cache && R(this); return this; }; -x.addMapper = function(a, c) { +A.addMapper = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -170,10 +170,10 @@ x.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && J(this); + this.cache && R(this); return this; }; -x.addMatcher = function(a, c) { +A.addMatcher = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -184,35 +184,35 @@ x.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && J(this); + this.cache && R(this); return this; }; -x.addReplacer = function(a, c) { +A.addReplacer = function(a, c) { if ("string" === typeof a) { return this.addMatcher(a, c); } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && J(this); + this.cache && R(this); return this; }; -x.encode = function(a, c) { +A.encode = function(a, c) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.F.has(a)) { return this.F.get(a); } } else { - this.H = setTimeout(J, 50, this); + this.H = setTimeout(R, 50, this); } } - this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = fa ? a.normalize("NFKD").replace(fa, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ia ? a.normalize("NFKD").replace(ia, "").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 ")); + this.numeric && 3 < a.length && (a = a.replace(fa, "$1 $2").replace(ha, "$1 $2").replace(ea, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = B(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; - for (let l = 0, m, n; l < k.length; l++) { - if ((m = n = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { + let e = [], d = J(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; + for (let l = 0, m, p; l < k.length; l++) { + if ((m = p = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (c) { if (d[m]) { continue; @@ -236,20 +236,20 @@ x.encode = function(a, c) { continue; } } else { - this.H = setTimeout(J, 50, this); + this.H = setTimeout(R, 50, this); } } if (this.stemmer) { this.N || (this.N = new RegExp("(?!^)(" + this.C + ")$")); let r; for (; r !== m && 2 < m.length;) { - r = m, m = m.replace(this.N, p => this.stemmer.get(p)); + r = m, m = m.replace(this.N, q => this.stemmer.get(q)); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { h = ""; - for (let r = 0, p = "", q, t; r < m.length; r++) { - q = m.charAt(r), q === p && this.dedupe || ((t = this.mapper && this.mapper.get(q)) || "" === t ? t === p && this.dedupe || !(p = t) || (h += t) : h += p = q); + for (let r = 0, q = "", t, w; r < m.length; r++) { + t = m.charAt(r), t === q && this.dedupe || ((w = this.mapper && this.mapper.get(t)) || "" === w ? w === q && this.dedupe || !(q = w) || (h += w) : h += q = t); } m = h; } @@ -259,9 +259,9 @@ x.encode = function(a, c) { m = m.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && n.length <= this.L && (this.G.set(n, m), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && p.length <= this.L && (this.G.set(p, m), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); if (m) { - if (m !== n) { + if (m !== p) { if (c) { if (d[m]) { continue; @@ -284,61 +284,30 @@ x.encode = function(a, c) { this.cache && a.length <= this.K && (this.F.set(a, e), this.F.size > this.R && (this.F.clear(), this.K = this.K / 1.1 | 0)); return e; }; -function J(a) { +function R(a) { a.H = null; a.F.clear(); a.G.clear(); } -;let K, L; -async function ha(a) { - a = a.data; - var c = a.task; - const b = a.id; - let e = a.args; - switch(c) { - case "init": - L = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), K = new self.FlexSearch.Index(L), delete self.FlexSearch) : K = new M(L); - postMessage({id:b}); - break; - default: - let d; - if ("export" === c) { - if (!L.export || "function" !== typeof L.export) { - throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); - } - e[1] ? (e[0] = L.export, e[2] = 0, e[3] = 1) : e = null; - } - if ("import" === c) { - if (!L.import || "function" !== typeof L.import) { - throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); - } - e[0] && (a = await L.import.call(K, e[0]), K.import(e[0], a)); - } else { - (d = e && K[c].apply(K, e)) && d.then && (d = await d); - } - postMessage("search" === c ? {id:b, msg:d} : {id:b}); - } +;function ka(a) { + na.call(a, "add"); + na.call(a, "append"); + na.call(a, "search"); + na.call(a, "update"); + na.call(a, "remove"); } -;function ia(a) { - P.call(a, "add"); - P.call(a, "append"); - P.call(a, "search"); - P.call(a, "update"); - P.call(a, "remove"); +let oa, pa, qa; +function ra() { + oa = qa = 0; } -let ja, ka, Q; -function la() { - ja = Q = 0; -} -function P(a) { +function na(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]); - ja ? Q || (Q = Date.now() - ka >= this.priority * this.priority * 3) : (ja = setTimeout(la, 0), ka = Date.now()); - if (Q) { + oa ? qa || (qa = Date.now() - pa >= this.priority * this.priority * 3) : (oa = setTimeout(ra, 0), pa = Date.now()); + if (qa) { const f = this; return new Promise(g => { setTimeout(function() { @@ -352,70 +321,7 @@ function P(a) { return b; }; } -;let R = 0; -function S(a = {}) { - function c(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[++R] = function() { - h(d); - 1e9 < R && (R = 0); - }; - d.worker.postMessage({id:R, task:"init", factory:b, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:b, options:a}); - this.priority = a.priority || 4; - return this; - } - } - if (!this || this.constructor !== S) { - return new S(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 = ma(b, e, a.worker); - return f.then ? f.then(function(g) { - return c.call(d, g); - }) : c.call(this, f); -} -T("add"); -T("append"); -T("search"); -T("update"); -T("remove"); -T("clear"); -T("export"); -T("import"); -ia(S.prototype); -function T(a) { - S.prototype[a] = function() { - const c = this, b = [].slice.call(arguments); - var e = b[b.length - 1]; - let d; - "function" === typeof e && (d = e, b.pop()); - e = new Promise(function(f) { - "export" === a && "function" === typeof b[0] && (b[0] = null); - c.h[++R] = f; - c.worker.postMessage({task:a, id:R, args:b}); - }); - return d ? (e.then(d), this) : e; - }; -} -function ma(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=" + ha.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 na(a, c = 0) { +;function sa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -424,30 +330,30 @@ function ma(a, c, b) { e.length && b.push(e); return b; } -function oa(a, c) { +function ta(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 pa(a, c = 0) { +function ua(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], na(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], sa(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function qa(a, c) { +function va(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], oa(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], ta(e[1], d)); } return c; } -function ra(a) { +function ya(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -455,14 +361,14 @@ function ra(a) { b.length && c.push(b); return c; } -function sa(a, c) { +function za(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function ta(a, c, b, e, d, f, g = 0) { +function Aa(a, c, b, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { @@ -471,12 +377,12 @@ function ta(a, c, b, e, d, f, g = 0) { if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return ta.call(l, a, c, b, k ? e : null, d, f, g + 1); + return Aa.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return ta.call(this, a, c, b, k ? e : null, d, f, g + 1); + return Aa.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function ua(a, c) { +function Ba(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; @@ -496,8 +402,8 @@ function ua(a, c) { } return b; } -;U.prototype.add = function(a, c, b) { - G(a) && (c = a, a = H(c, this.key)); +;T.prototype.add = function(a, c, b) { + M(a) && (c = a, a = Q(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -510,7 +416,7 @@ function ua(a, c) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : C(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : K(h) && (h = [h]), Ca(c, h, this.J, 0, e, a, h[0], b); } } } @@ -518,7 +424,7 @@ function ua(a, c) { for (e = 0; e < this.B.length; e++) { var f = this.B[e], g = this.T[e]; d = this.tag.get(g); - let k = B(); + let k = J(); if ("function" === typeof f) { if (f = f(c), !f) { continue; @@ -529,10 +435,10 @@ function ua(a, c) { continue; } f.constructor === String && (f = "" + f); - f = H(c, f); + f = Q(c, f); } if (d && f) { - C(f) && (f = [f]); + K(f) && (f = [f]); for (let h = 0, l, m; h < f.length; h++) { l = f[h], k[l] || (k[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])))); } @@ -544,7 +450,7 @@ function ua(a, c) { if (this.store && (!b || !this.store.has(a))) { let k; if (this.A) { - k = B(); + k = J(); for (let h = 0, l; h < this.A.length; h++) { l = this.A[h]; if ((b = l.I) && !b(c)) { @@ -557,11 +463,11 @@ function ua(a, c) { continue; } l = [l.U]; - } else if (C(l) || l.constructor === String) { + } else if (K(l) || l.constructor === String) { k[l] = c[l]; continue; } - wa(c, k, l, 0, l[0], m); + Da(c, k, l, 0, l[0], m); } } this.store.set(a, k || c); @@ -569,21 +475,21 @@ function ua(a, c) { } return this; }; -function wa(a, c, b, e, d, f) { +function Da(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++) { - wa(a, c, b, e, d); + Da(a, c, b, e, d); } } else { - c = c[d] || (c[d] = B()), d = b[++e], wa(a, c, b, e, d); + c = c[d] || (c[d] = J()), d = b[++e], Da(a, c, b, e, d); } } } -function va(a, c, b, e, d, f, g, k) { +function Ca(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -599,24 +505,24 @@ function va(a, c, b, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - va(a, c, b, e, d, f, g, k); + Ca(a, c, b, e, d, f, g, k); } } else { - g = c[++e], va(a, c, b, e, d, f, g, k); + g = c[++e], Ca(a, c, b, e, d, f, g, k); } } } } -;function xa(a, c, b, e, d) { +;function Ea(a, c, b, e, d) { const f = a.length; let g = [], k, h; - k = B(); - for (let l = 0, m, n, r, p; l < c; l++) { - for (let q = 0; q < f; q++) { - if (r = a[q], l < r.length && (m = r[l])) { - for (let t = 0; t < m.length; t++) { - if (n = m[t], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n), b && h === f - 1 && p.length - e === b) { - return e ? p.slice(e) : p; + k = J(); + for (let l = 0, m, p, r, q; l < c; l++) { + for (let t = 0; t < f; t++) { + if (r = a[t], l < r.length && (m = r[l])) { + for (let w = 0; w < m.length; w++) { + if (p = m[w], (h = k[p]) ? k[p]++ : (h = 0, k[p] = 1), q = g[h] || (g[h] = []), q.push(p), b && h === f - 1 && q.length - e === b) { + return e ? q.slice(e) : q; } } } @@ -624,7 +530,7 @@ function va(a, c, b, e, d, f, g, k) { } if (a = g.length) { if (d) { - g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? Fa(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -639,8 +545,8 @@ function va(a, c, b, e, d, f, g, k) { } return g; } -function ya(a, c, b) { - const e = [], d = B(); +function Fa(a, c, b) { + const e = [], d = J(); let f; var g = a.length; let k; @@ -661,8 +567,8 @@ function ya(a, c, b) { } return e; } -function za(a, c) { - const b = B(), e = []; +function Ga(a, c) { + const b = J(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; for (let g = 0; g < f.length; g++) { @@ -674,12 +580,12 @@ function za(a, c) { } return e; } -;function Aa(a, c, b, e) { +;function Ha(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 ? V.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? U.call(this, a) : a; } let d = []; for (let f = 0, g, k; f < a.length; f++) { @@ -693,7 +599,7 @@ function za(a, c) { } k > c && (g = g.slice(0, c), k = c); if (!d.length && k >= c) { - return e ? V.call(this, g) : g; + return e ? U.call(this, g) : g; } d.push(g); c -= k; @@ -703,9 +609,9 @@ function za(a, c) { } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? V.call(this, d) : d; + return e ? U.call(this, d) : d; } -;function Ba(a, c, b) { +;function Ia(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -717,24 +623,24 @@ function za(a, c) { } e = []; let d = [], f = 0, g = 0, k, h, l; - for (let m = 0, n; m < b.length; m++) { - if (n = b[m]) { + for (let m = 0, p; m < b.length; m++) { + if (p = b[m]) { let r; - if (n.constructor === W) { - r = n.result; - } else if (n.constructor === Array) { - r = n; + if (p.constructor === X) { + r = p.result; + } else if (p.constructor === Array) { + r = p; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, r = n.index.search(n).result, n.resolve = h, n.enrich = k; - } else if (n.and) { - r = a.and(n.and); - } else if (n.or) { - r = a.or(n.or); - } else if (n.xor) { - r = a.xor(n.xor); - } else if (n.not) { - r = a.not(n.not); + if (f = p.limit || 0, g = p.offset || 0, l = p.suggest, h = p.resolve, k = p.enrich && h, p.index) { + p.resolve = !1, p.enrich = !1, r = p.index.search(p).result, p.resolve = h, p.enrich = k; + } else if (p.and) { + r = a.and(p.and); + } else if (p.or) { + r = a.or(p.or); + } else if (p.xor) { + r = a.xor(p.xor); + } else if (p.not) { + r = a.not(p.not); } else { continue; } @@ -751,11 +657,11 @@ function za(a, c) { } return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } -;W.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); +;X.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ia(this, "or", arguments); + return Ja.call(this, a, c, b, e, d, f); }; -function Ca(a, c, b, e, d, f) { +function Ja(a, c, b, e, d, f) { if (c.length) { const g = this; return Promise.all(c).then(function(k) { @@ -763,25 +669,25 @@ function Ca(a, c, b, e, d, f) { for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return Ca.call(g, a, [], b, e, d, f); + return Ja.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 = ya(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Fa(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } -;W.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:k, offset:h, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); - return Da.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:p} = Ia(this, "and", arguments); + return Ka.call(this, f, g, k, h, l, m, p); } return d ? this.resolve(c, b, e) : this; }; -function Da(a, c, b, e, d, f, g) { +function Ka(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -789,7 +695,7 @@ function Da(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Da.call(k, a, [], b, e, d, f, g); + return Ka.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -797,7 +703,7 @@ function Da(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = xa(a, c, b, e, g), f ? d ? V.call(this.index, this.result) : this.result : this; + return this.result = Ea(a, c, b, e, g), f ? d ? U.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -806,11 +712,11 @@ function Da(a, c, b, e, d, f, g) { } return f ? this.resolve(b, e, d) : this; } -;W.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); +;X.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ia(this, "xor", arguments); + return La.call(this, a, c, b, e, d, f, g); }; -function Ea(a, c, b, e, d, f, g) { +function La(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -818,52 +724,52 @@ function Ea(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ea.call(k, a, [], b, e, d, f, g); + return La.call(k, 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 = Fa.call(this, a, b, e, f, this.h), f ? d ? V.call(this.index, this.result) : this.result : this; + return this.result = Ma.call(this, a, b, e, f, this.h), f ? d ? U.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 = B(); +function Ma(a, c, b, e, d) { + const f = [], g = J(); let k = 0; for (let h = 0, l; h < a.length; h++) { if (l = a[h]) { k < l.length && (k = l.length); - for (let m = 0, n; m < l.length; m++) { - if (n = l[m]) { - for (let r = 0, p; r < n.length; r++) { - p = n[r], g[p] = g[p] ? 2 : 1; + for (let m = 0, p; m < l.length; m++) { + if (p = l[m]) { + for (let r = 0, q; r < p.length; r++) { + q = p[r], g[q] = g[q] ? 2 : 1; } } } } } for (let h = 0, l, m = 0; h < k; h++) { - for (let n = 0, r; n < a.length; n++) { - if (r = a[n]) { + for (let p = 0, r; p < a.length; p++) { + if (r = a[p]) { if (l = r[h]) { - for (let p = 0, q; p < l.length; p++) { - if (q = l[p], 1 === g[q]) { + for (let q = 0, t; q < l.length; q++) { + if (t = l[q], 1 === g[t]) { if (b) { b--; } else { if (e) { - if (f.push(q), f.length === c) { + if (f.push(t), f.length === c) { return f; } } else { - const t = h + (n ? d : 0); - f[t] || (f[t] = []); - f[t].push(q); + const w = h + (p ? d : 0); + f[w] || (f[w] = []); + f[w].push(t); if (++m === c) { return f; } @@ -877,11 +783,11 @@ function Fa(a, c, b, e, d) { } return f; } -;W.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); +;X.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ia(this, "not", arguments); + return Na.call(this, a, c, b, e, d, f, g); }; -function Ga(a, c, b, e, d, f, g) { +function Na(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -889,17 +795,17 @@ function Ga(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ga.call(k, a, [], b, e, d, f, g); + return Na.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ha.call(this, a, b, e, f); + this.result = Oa.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? V.call(this.index, this.result) : this.result : this; + return f ? d ? U.call(this.index, this.result) : this.result : this; } -function Ha(a, c, b, e) { +function Oa(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { @@ -925,9 +831,9 @@ function Ha(a, c, b, e) { } return d; } -;function W(a) { - if (!this || this.constructor !== W) { - return new W(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; @@ -936,7 +842,7 @@ function Ha(a, c, b, e) { this.result = a || []; this.h = 0; } -W.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++) { @@ -955,7 +861,7 @@ W.prototype.limit = function(a) { } return this; }; -W.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++) { @@ -967,81 +873,314 @@ W.prototype.offset = function(a) { } return this; }; -W.prototype.boost = function(a) { +X.prototype.boost = function(a) { this.h += a; return this; }; -W.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), Aa.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Ha.call(d, e, a || 100, c, b)) : e; }; -B(); -U.prototype.search = function(a, c, b, e) { - b || (!c && G(a) ? (b = a, a = "") : G(c) && (b = c, c = 0)); +J(); +function Pa(a, c, b, e, d) { + let f, g, k; + "string" === typeof d ? (f = d, d = "") : f = d.template; + if (!f) { + throw Error('No template pattern was specified by the search option "highlight"'); + } + g = f.indexOf("$1"); + if (-1 === g) { + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); + } + k = f.substring(g + 2); + g = f.substring(0, g); + let h = d && d.boundary, l = !d || !1 !== d.clip, m = d && d.merge && k && g && new RegExp(k + " " + g, "g"); + d = d && d.ellipsis; + var p = 0; + if ("object" === typeof d) { + var r = d.template; + p = r.length - 2; + d = d.pattern; + } + "string" !== typeof d && (d = !1 === d ? "" : "..."); + p && (d = r.replace("$1", d)); + r = d.length - p; + let q, t; + "object" === typeof h && (q = h.before, 0 === q && (q = -1), t = h.after, 0 === t && (t = -1), h = h.total || 9e5); + p = new Map(); + for (let wa = 0, V, Ra, ca; wa < c.length; wa++) { + let da; + if (e) { + da = c, ca = e; + } else { + var w = c[wa]; + ca = w.field; + if (!ca) { + continue; + } + da = w.result; + } + Ra = b.get(ca); + V = Ra.encoder; + w = p.get(V); + "string" !== typeof w && (w = V.encode(a), p.set(V, w)); + for (let la = 0; la < da.length; la++) { + var n = da[la].doc; + if (!n) { + continue; + } + n = Q(n, ca); + if (!n) { + continue; + } + var x = n.trim().split(/\s+/); + if (!x.length) { + continue; + } + n = ""; + var y = []; + let ma = []; + var E = -1, v = -1, B = 0; + for (var z = 0; z < x.length; z++) { + var C = x[z], H = V.encode(C); + H = 1 < H.length ? H.join(" ") : H[0]; + let u; + if (H && C) { + var D = C.length, N = (V.split ? C.replace(V.split, "") : C).length - H.length, L = "", S = 0; + for (var W = 0; W < w.length; W++) { + var O = w[W]; + if (O) { + var G = O.length; + G += N; + S && G <= S || (O = H.indexOf(O), -1 < O && (L = (O ? C.substring(0, O) : "") + g + C.substring(O, O + G) + k + (O + G < D ? C.substring(O + G) : ""), S = G, u = !0)); + } + } + L && (h && (0 > E && (E = n.length + (n ? 1 : 0)), v = n.length + (n ? 1 : 0) + L.length, B += D, ma.push(y.length), y.push({match:L})), n += (n ? " " : "") + L); + } + if (!u) { + C = x[z], n += (n ? " " : "") + C, h && y.push({text:C}); + } else if (h && B >= h) { + break; + } + } + B = ma.length * (f.length - 2); + if (q || t || h && n.length - B > h) { + if (B = h + B - 2 * r, z = v - E, 0 < q && (z += q), 0 < t && (z += t), z <= B) { + x = q ? E - (0 < q ? q : 0) : E - ((B - z) / 2 | 0), y = t ? v + (0 < t ? t : 0) : x + B, l || (0 < x && " " !== n.charAt(x) && " " !== n.charAt(x - 1) && (x = n.indexOf(" ", x), 0 > x && (x = 0)), y < n.length && " " !== n.charAt(y - 1) && " " !== n.charAt(y) && (y = n.lastIndexOf(" ", y), y < v ? y = v : ++y)), n = (x ? d : "") + n.substring(x, y) + (y < n.length ? d : ""); + } else { + v = []; + E = {}; + B = {}; + z = {}; + C = {}; + H = {}; + L = N = D = 0; + for (W = S = 1;;) { + var P = void 0; + for (let u = 0, F; u < ma.length; u++) { + F = ma[u]; + if (L) { + if (N !== L) { + if (z[u + 1]) { + continue; + } + F += L; + if (E[F]) { + D -= r; + B[u + 1] = 1; + z[u + 1] = 1; + continue; + } + if (F >= y.length - 1) { + if (F >= y.length) { + z[u + 1] = 1; + F >= x.length && (B[u + 1] = 1); + continue; + } + D -= r; + } + n = y[F].text; + if (G = t && H[u]) { + if (0 < G) { + if (n.length > G) { + if (z[u + 1] = 1, l) { + n = n.substring(0, G); + } else { + continue; + } + } + (G -= n.length) || (G = -1); + H[u] = G; + } else { + z[u + 1] = 1; + continue; + } + } + if (D + n.length + 1 <= h) { + n = " " + n, v[u] += n; + } else if (l) { + P = h - D - 1, 0 < P && (n = " " + n.substring(0, P), v[u] += n), z[u + 1] = 1; + } else { + z[u + 1] = 1; + continue; + } + } else { + if (z[u]) { + continue; + } + F -= N; + if (E[F]) { + D -= r; + z[u] = 1; + B[u] = 1; + continue; + } + if (0 >= F) { + if (0 > F) { + z[u] = 1; + B[u] = 1; + continue; + } + D -= r; + } + n = y[F].text; + if (G = q && C[u]) { + if (0 < G) { + if (n.length > G) { + if (z[u] = 1, l) { + n = n.substring(n.length - G); + } else { + continue; + } + } + (G -= n.length) || (G = -1); + C[u] = G; + } else { + z[u] = 1; + continue; + } + } + if (D + n.length + 1 <= h) { + n += " ", v[u] = n + v[u]; + } else if (l) { + P = n.length + 1 - (h - D), 0 <= P && P < n.length && (n = n.substring(P) + " ", v[u] = n + v[u]), z[u] = 1; + } else { + z[u] = 1; + continue; + } + } + } else { + n = y[F].match; + q && (C[u] = q); + t && (H[u] = t); + u && D++; + let xa; + F ? !u && r && (D += r) : (B[u] = 1, z[u] = 1); + F >= x.length - 1 ? xa = 1 : F < y.length - 1 && y[F + 1].match ? xa = 1 : r && (D += r); + D -= f.length - 2; + if (!u || D + n.length <= h) { + v[u] = n; + } else { + P = S = W = B[u] = 0; + break; + } + xa && (B[u + 1] = 1, z[u + 1] = 1); + } + D += n.length; + P = E[F] = 1; + } + if (P) { + N === L ? L++ : N++; + } else { + N === L ? S = 0 : W = 0; + if (!S && !W) { + break; + } + S ? (N++, L = N) : L++; + } + } + n = ""; + for (let u = 0, F; u < v.length; u++) { + F = (u && B[u] ? " " : (u && !d ? " " : "") + d) + v[u], n += F; + } + d && !B[v.length] && (n += d); + } + } + m && (n = n.replace(m, " ")); + da[la].highlight = n; + } + if (e) { + break; + } + } + return c; +} +;T.prototype.search = function(a, c, b, e) { + b || (!c && M(a) ? (b = a, a = "") : M(c) && (b = c, c = 0)); let d = []; var f = []; let g; let k, h, l; - let m = 0, n = !0, r; + let m = 0, p = !0, r; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; - var p = b.pluck; - var q = b.merge; - h = p || b.field || (h = b.index) && (h.index ? null : h); + var q = b.pluck; + var t = b.merge; + h = q || b.field || (h = b.index) && (h.index ? null : h); l = this.tag && b.tag; k = b.suggest; - n = !0; - this.store && b.enrich && !n && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - r = (g = this.store && b.enrich && n) && b.highlight; + p = !0; + this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + g = (r = p && this.store && b.highlight) || p && this.store && b.enrich; c = b.limit || c; - var t = b.offset || 0; + var w = b.offset || 0; c || (c = 100); if (l) { l.constructor !== Array && (l = [l]); - var u = []; - for (let A = 0, v; A < l.length; A++) { - v = l[A]; - if (C(v)) { + var n = []; + for (let E = 0, v; E < l.length; E++) { + v = l[E]; + if (K(v)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (v.field && v.tag) { - var w = v.tag; - if (w.constructor === Array) { - for (var y = 0; y < w.length; y++) { - u.push(v.field, w[y]); + var x = v.tag; + if (x.constructor === Array) { + for (var y = 0; y < x.length; y++) { + n.push(v.field, x[y]); } } else { - u.push(v.field, w); + n.push(v.field, x); } } else { - w = Object.keys(v); - for (let D = 0, E, F; D < w.length; D++) { - if (E = w[D], F = v[E], F.constructor === Array) { - for (y = 0; y < F.length; y++) { - u.push(E, F[y]); + x = Object.keys(v); + for (let B = 0, z, C; B < x.length; B++) { + if (z = x[B], C = v[z], C.constructor === Array) { + for (y = 0; y < C.length; y++) { + n.push(z, C[y]); } } else { - u.push(E, F); + n.push(z, C); } } } } - if (!u.length) { + if (!n.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = u; + l = n; if (!a) { f = []; - if (u.length) { - for (p = 0; p < u.length; p += 2) { - q = Ia.call(this, u[p], u[p + 1], c, t, g), d.push({field:u[p], tag:u[p + 1], result:q}); + if (n.length) { + for (q = 0; q < n.length; q += 2) { + t = Qa.call(this, n[q], n[q + 1], c, w, g), d.push({field:n[q], tag:n[q + 1], result:t}); } } - return f.length ? Promise.all(f).then(function(A) { - for (let v = 0; v < A.length; v++) { - d[v].result = A[v]; + return f.length ? Promise.all(f).then(function(E) { + for (let v = 0; v < E.length; v++) { + d[v].result = E[v]; } return d; }) : d; @@ -1050,134 +1189,81 @@ U.prototype.search = function(a, c, b, e) { h && h.constructor !== Array && (h = [h]); } h || (h = this.field); - u = !e && (this.worker || this.db) && []; - for (let A = 0, v, D, E; A < h.length; A++) { - D = h[A]; - let F; - C(D) || (F = D, D = F.field, a = F.query || a, c = F.limit || c, t = F.offset || t, k = F.suggest || k, g = this.store && (F.enrich || g)); + n = !e && (this.worker || this.db) && []; + for (let E = 0, v, B, z; E < h.length; E++) { + B = h[E]; + let C; + K(B) || (C = B, B = C.field, a = C.query || a, c = C.limit || c, w = C.offset || w, k = C.suggest || k, r = (g = this.store && (C.enrich || g)) && (b.highlight || r)); if (e) { - v = e[A]; + v = e[E]; } else { - if (w = F || b, y = this.index.get(D), l && (w.enrich = !1), u) { - u[A] = y.search(a, c, w); - w && g && (w.enrich = g); + if (x = C || b, y = this.index.get(B), l && (x.enrich = !1), n) { + n[E] = y.search(a, c, x); + x && g && (x.enrich = g); continue; } else { - v = y.search(a, c, w), w && g && (w.enrich = g); + v = y.search(a, c, x), x && g && (x.enrich = g); } } - E = v && (n ? v.length : v.result.length); - if (l && E) { - w = []; + z = v && (p ? v.length : v.result.length); + if (l && z) { + x = []; y = 0; - for (let N = 0, O, Za; N < l.length; N += 2) { - O = this.tag.get(l[N]); - if (!O) { - if (console.warn("Tag '" + l[N] + ":" + l[N + 1] + "' will be skipped because there is no field '" + l[N] + "'."), k) { + for (let H = 0, D, N; H < l.length; H += 2) { + D = this.tag.get(l[H]); + if (!D) { + if (console.warn("Tag '" + l[H] + ":" + l[H + 1] + "' will be skipped because there is no field '" + l[H] + "'."), k) { continue; } else { - return n ? d : new W(d); + return p ? d : new X(d); } } - if (Za = (O = O && O.get(l[N + 1])) && O.length) { - y++, w.push(O); + if (N = (D = D && D.get(l[H + 1])) && D.length) { + y++, x.push(D); } else if (!k) { - return n ? d : new W(d); + return p ? d : new X(d); } } if (y) { - v = za(v, w); - E = v.length; - if (!E && !k) { - return n ? v : new W(v); + v = Ga(v, x); + z = v.length; + if (!z && !k) { + return p ? v : new X(v); } y--; } } - if (E) { - f[m] = D, d.push(v), m++; + if (z) { + f[m] = B, d.push(v), m++; } else if (1 === h.length) { - return n ? d : new W(d); + return p ? d : new X(d); } } - if (u) { - const A = this; - return Promise.all(u).then(function(v) { - return v.length ? A.search(a, c, b, v) : v; + if (n) { + const E = this; + return Promise.all(n).then(function(v) { + return v.length ? E.search(a, c, b, v) : v; }); } if (!m) { - return n ? d : new W(d); + return p ? d : new X(d); } - if (p && (!g || !this.store)) { + if (q && (!g || !this.store)) { return d[0]; } - u = []; - for (t = 0; t < f.length; t++) { - e = d[t]; - g && e.length && "undefined" === typeof e[0].doc && (e = V.call(this, e)); - if (p) { - return n ? r ? Ja(a, e, this.index, p, r) : e : new W(e); + n = []; + for (w = 0; w < f.length; w++) { + e = d[w]; + g && e.length && "undefined" === typeof e[0].doc && (e = U.call(this, e)); + if (q) { + return p ? r ? Pa(a, e, this.index, q, r) : e : new X(e); } - d[t] = {field:f[t], result:e}; + d[w] = {field:f[w], result:e}; } - return q ? Ka(d) : r ? Ja(a, d, this.index, p, r) : d; + return t ? Sa(d) : r ? Pa(a, d, this.index, q, r) : d; }; -function Ja(a, c, b, e, d) { - let f, g; - for (let h = 0, l, m, n; h < c.length; h++) { - let r; - if (e) { - r = c, n = e; - } else { - var k = c[h]; - n = k.field; - if (!n) { - continue; - } - r = k.result; - } - m = b.get(n); - l = m.encoder; - k = m.tokenize; - l !== f && (f = l, g = f.encode(a)); - for (let p = 0; p < r.length; p++) { - let q = "", t = H(r[p].doc, n).split(/\s+/); - for (let u = 0, w, y; u < t.length; u++) { - w = t[u]; - y = l.encode(w); - y = 1 < y.length ? y.join(" ") : y[0]; - let A; - if (y && w) { - for (let v = 0, D; v < g.length; v++) { - if (D = g[v], "strict" === k) { - if (y === D) { - q += (q ? " " : "") + d.replace("$1", w); - A = !0; - break; - } - } else { - const E = y.indexOf(D); - if (-1 < E) { - q += (q ? " " : "") + w.substring(0, E) + d.replace("$1", w.substring(E, E + D.length)) + w.substring(E + D.length); - A = !0; - break; - } - } - } - } - A || (q += (q ? " " : "") + t[u]); - } - r[p].highlight = q; - } - if (e) { - break; - } - } - return c; -} -function Ka(a) { - const c = [], b = B(); +function Sa(a) { + const c = [], b = J(); for (let e = 0, d, f; e < a.length; e++) { d = a[e]; f = d.result; @@ -1187,7 +1273,7 @@ function Ka(a) { } return c; } -function Ia(a, c, b, e, d) { +function Qa(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1196,11 +1282,11 @@ function Ia(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = V.call(this, f)); + d && (f = U.call(this, f)); return f; } } -function V(a) { +function U(a) { if (!this || !this.store) { return a; } @@ -1210,33 +1296,33 @@ function V(a) { } return c; } -;function U(a) { - if (!this || this.constructor !== U) { - return new U(a); +;function T(a) { + if (!this || this.constructor !== T) { + return new T(a); } const c = a.document || a.doc || a; var b; this.D = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && La(b, this.J) || "id"; + this.key = (b = c.key || c.id) && Ta(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 X(b); + this.cache = (b = a.cache || null) && new Y(b); a.cache = !1; this.priority = a.priority || 4; b = new Map(); let e = c.index || c.field || c; - C(e) && (e = [e]); + K(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], C(f) || (g = f, f = f.field), g = G(g) ? Object.assign({}, a, g) : a, b.set(f, new M(g, this.reg)), g.custom ? this.D[d] = g.custom : (this.D[d] = La(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; + f = e[d], K(f) || (g = f, f = f.field), g = M(g) ? Object.assign({}, a, g) : a, b.set(f, new Z(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.A) { a = c.store; - C(a) && (a = [a]); + K(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] = 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)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = Ta(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; @@ -1252,14 +1338,14 @@ function V(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - 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)); + f.custom ? this.B[d] = f.custom : (this.B[d] = Ta(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 La(a, c) { +function Ta(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1268,15 +1354,15 @@ function La(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -x = U.prototype; -x.append = function(a, c) { +A = T.prototype; +A.append = function(a, c) { return this.add(a, c, !0); }; -x.update = function(a, c) { +A.update = function(a, c) { return this.remove(a).add(a, c); }; -x.remove = function(a) { - G(a) && (a = H(a, this.key)); +A.remove = function(a) { + M(a) && (a = Q(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1296,7 +1382,7 @@ x.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -x.clear = function() { +A.clear = function() { const a = []; for (const c of this.index.values()) { const b = c.clear(); @@ -1311,25 +1397,25 @@ x.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -x.contain = function(a) { +A.contain = function(a) { return this.reg.has(a); }; -x.cleanup = function() { +A.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -x.get = function(a) { +A.get = function(a) { return this.store.get(a) || null; }; -x.set = function(a, c) { - "object" === typeof a && (c = a, a = H(c, this.key)); +A.set = function(a, c) { + "object" === typeof a && (c = a, a = Q(c, this.key)); this.store.set(a, c); return this; }; -x.searchCache = Ma; -x.export = function(a, c, b = 0, e = 0) { +A.searchCache = Ua; +A.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { @@ -1344,25 +1430,25 @@ x.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = ra(this.reg); + f = ya(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && pa(this.tag, this.reg.size); + f = this.tag && ua(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && na(this.store); + f = this.store && sa(this.store); c = null; break; default: return; } - return ta.call(this, a, c, d, f, b, e); + return Aa.call(this, a, c, d, f, b, e); }; -x.import = function(a, c) { +A.import = function(a, c) { var b = a.split("."); "json" === b[b.length - 1] && b.pop(); a = 2 < b.length ? b[0] : ""; @@ -1375,23 +1461,23 @@ x.import = function(a, c) { switch(b) { case "reg": this.fastupdate = !1; - this.reg = sa(c, this.reg); + this.reg = za(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 = qa(c, this.tag); + this.tag = va(c, this.tag); break; case "doc": - this.store = oa(c, this.store); + this.store = ta(c, this.store); } } }; -ia(U.prototype); -function Ma(a, c, b) { +ka(T.prototype); +function Ua(a, c, b) { const e = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new X()); + this.cache || (this.cache = new Y()); let d = this.cache.get(e); if (!d) { d = this.search(a, c, b); @@ -1406,45 +1492,45 @@ function Ma(a, c, b) { } return d; } -function X(a) { +function Y(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -X.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); }; -X.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; }; -X.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); } }; -X.prototype.clear = function() { +Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Na = {normalize:!1, numeric:!1, dedupe:!1}; -const Oa = {}; -const Pa = 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 Qa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ra = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Sa = {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 Ta = {Exact:Na, Default:Oa, Normalize:Oa, LatinBalance:{mapper:Pa}, LatinAdvanced:{mapper:Pa, matcher:Qa, replacer:Ra}, LatinExtra:{mapper:Pa, replacer:Ra.concat([/(?!^)[aeo]/g, ""]), matcher:Qa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Va = {normalize:!1, numeric:!1, dedupe:!1}; +const Wa = {}; +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"], ["ph", "f"], ["pf", "f"]]), Za = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\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}; +var ab = {Exact:Va, Default:Wa, Normalize:Wa, LatinBalance:{mapper:Xa}, LatinAdvanced:{mapper:Xa, matcher:Ya, replacer:Za}, LatinExtra:{mapper:Xa, replacer:Za.concat([/(?!^)[aeo]/g, ""]), matcher:Ya}, LatinSoundex:{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 = Sa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Sa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = $a[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = $a[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } -}}, CJK:{split:""}, LatinExact:Na, LatinDefault:Oa, LatinSimple:Oa}; -M.prototype.remove = function(a, c) { +}}, CJK:{split:""}, LatinExact:Va, LatinDefault:Wa, LatinSimple:Wa}; +Z.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) { @@ -1459,14 +1545,14 @@ M.prototype.remove = function(a, c) { } } } else { - Y(this.map, a), this.depth && Y(this.ctx, a); + bb(this.map, a), this.depth && bb(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Y(a, c) { +function bb(a, c) { let b = 0; var e = "undefined" === typeof c; if (a.constructor === Array) { @@ -1487,14 +1573,14 @@ function Y(a, c) { } else { for (let d of a.entries()) { e = d[0]; - const f = Y(d[1], c); + const f = bb(d[1], c); f ? b += f : a.delete(e); } } return b; } -;const Ua = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -M.prototype.add = function(a, c, b, e) { +;const cb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +Z.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -1503,21 +1589,21 @@ M.prototype.add = function(a, c, b, e) { c = this.encoder.encode(c, !e); const l = c.length; if (l) { - const m = B(), n = B(), r = this.resolution; - for (let p = 0; p < l; p++) { - let q = c[this.rtl ? l - 1 - p : p]; - var d = q.length; - if (d && (e || !n[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Va(r, l, p), g = ""; + const m = J(), p = J(), r = this.resolution; + for (let q = 0; q < l; q++) { + let t = c[this.rtl ? l - 1 - q : q]; + var d = t.length; + if (d && (e || !p[t])) { + var f = this.score ? this.score(c, t, q, null, 0) : db(r, l, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let t = 0, u; t < d; t++) { - for (f = d; f > t; f--) { - g = q.substring(t, f); - u = this.rtl ? d - 1 - t : t; - var k = this.score ? this.score(c, q, p, g, u) : Va(r, l, p, d, u); - Z(this, n, g, k, a, b); + for (let w = 0, n; w < d; w++) { + for (f = d; f > w; f--) { + g = t.substring(w, f); + n = this.rtl ? d - 1 - w : w; + var k = this.score ? this.score(c, t, q, g, n) : db(r, l, q, d, n); + eb(this, p, g, k, a, b); } } break; @@ -1526,26 +1612,26 @@ M.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (k = d - 1; 0 < k; k--) { - g = q[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, q, p, g, k) : Va(r, l, p, d, k); - Z(this, n, g, h, a, b); + g = t[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, t, q, g, k) : db(r, l, q, d, k); + eb(this, p, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += q[this.rtl ? d - 1 - k : k], Z(this, n, g, f, a, b); + g += t[this.rtl ? d - 1 - k : k], eb(this, p, g, f, a, b); } break; } default: - if (Z(this, n, q, f, a, b), e && 1 < l && p < l - 1) { - for (d = B(), g = this.S, f = q, k = Math.min(e + 1, this.rtl ? p + 1 : l - p), d[f] = 1, h = 1; h < k; h++) { - if ((q = c[this.rtl ? l - 1 - p - h : p + h]) && !d[q]) { - d[q] = 1; - const t = this.score ? this.score(c, f, p, q, h - 1) : Va(g + (l / 2 > g ? 0 : 1), l, p, k - 1, h - 1), u = this.bidirectional && q > f; - Z(this, m, u ? f : q, t, a, b, u ? q : f); + if (eb(this, p, t, f, a, b), e && 1 < l && q < l - 1) { + for (d = J(), g = this.S, f = t, k = Math.min(e + 1, this.rtl ? q + 1 : l - q), d[f] = 1, h = 1; h < k; h++) { + if ((t = c[this.rtl ? l - 1 - q - h : q + h]) && !d[t]) { + d[t] = 1; + const w = this.score ? this.score(c, f, q, t, h - 1) : db(g + (l / 2 > g ? 0 : 1), l, q, k - 1, h - 1), n = this.bidirectional && t > f; + eb(this, m, n ? f : t, w, a, b, n ? t : f); } } } @@ -1557,16 +1643,16 @@ M.prototype.add = function(a, c, b, e) { } return this; }; -function Z(a, c, b, e, d, f, g) { +function eb(a, c, b, e, d, f, g) { let k = g ? a.ctx : a.map, h; if (!c[b] || g && !(h = c[b])[g]) { - g ? (c = h || (c[b] = B()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); + g ? (c = h || (c[b] = J()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); } } -function Va(a, c, b, e, d) { +function db(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; } -;M.prototype.search = function(a, c, b) { +;Z.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); var e = [], d = 0; if (b) { @@ -1585,86 +1671,86 @@ function Va(a, c, b, e, d) { b = a.length; c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Wa(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; + return g = c, (c = fb(this, a[0], "")) && c.length ? Ha.call(this, c, g, d) : []; } if (2 === b && f && !g) { - return g = c, (c = Wa(this, a[1], a[0])) && c.length ? Aa.call(this, c, g, d) : []; + return g = c, (c = fb(this, a[1], a[0])) && c.length ? Ha.call(this, c, g, d) : []; } - k = B(); + k = J(); let l = 0; if (f) { var m = a[0]; l = 1; } h || 0 === h || (h = m ? this.S : this.resolution); - for (let q, t; l < b; l++) { - if ((t = a[l]) && !k[t]) { - k[t] = 1; - q = Wa(this, t, m); + for (let t, w; l < b; l++) { + if ((w = a[l]) && !k[w]) { + k[w] = 1; + t = fb(this, w, m); a: { - f = q; - var n = e, r = g, p = h; - let u = []; + f = t; + var p = e, r = g, q = h; + let n = []; if (f && f.length) { - if (f.length <= p) { - n.push(f); - q = void 0; + if (f.length <= q) { + p.push(f); + t = void 0; break a; } - for (let w = 0, y; w < p; w++) { - if (y = f[w]) { - u[w] = y; + for (let x = 0, y; x < q; x++) { + if (y = f[x]) { + n[x] = y; } } - if (u.length) { - n.push(u); - q = void 0; + if (n.length) { + p.push(n); + t = void 0; break a; } } - q = r ? void 0 : u; + t = r ? void 0 : n; } - if (q) { - e = q; + if (t) { + e = t; break; } - m && (g && q && e.length || (m = t)); + m && (g && t && e.length || (m = w)); } - g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = B()); + g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = J()); } a: { a = e; e = a.length; m = a; if (1 < e) { - m = xa(a, h, c, d, g); + m = Ea(a, h, c, d, g); } else if (1 === e) { - g = Aa.call(null, a[0], c, d); + g = Ha.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Wa(a, c, b) { +function fb(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; } -;function M(a, c) { - if (!this || this.constructor !== M) { - return new M(a); +;function Z(a, c) { + if (!this || this.constructor !== Z) { + return new Z(a); } if (a) { - var b = C(a) ? a : a.preset; - b && (Ua[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ua[b], a)); + var b = K(a) ? a : a.preset; + b && (cb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, cb[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = C(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || {}; - this.encoder = d.encode ? d : "object" === typeof d ? new I(d) : {encode:d}; + const e = !0 === b ? {depth:1} : b || {}, d = K(a.encoder) ? ab[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : "object" === typeof d ? new ja(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; this.depth = "strict" === b && e.depth || 0; @@ -1678,42 +1764,42 @@ function Wa(a, c, b) { 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 X(b); + this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; } -x = M.prototype; -x.clear = function() { +A = Z.prototype; +A.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); this.cache && this.cache.clear(); return this; }; -x.append = function(a, c) { +A.append = function(a, c) { return this.add(a, c, !0); }; -x.contain = function(a) { +A.contain = function(a) { return this.reg.has(a); }; -x.update = function(a, c) { +A.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); }; -x.cleanup = function() { +A.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Y(this.map); - this.depth && Y(this.ctx); + bb(this.map); + this.depth && bb(this.ctx); return this; }; -x.searchCache = Ma; -x.export = function(a, c, b = 0, e = 0) { +A.searchCache = Ua; +A.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = ra(this.reg); + f = ya(this.reg); break; case 1: d = "cfg"; @@ -1721,33 +1807,33 @@ x.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = na(this.map, this.reg.size); + f = sa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = pa(this.ctx, this.reg.size); + f = ua(this.ctx, this.reg.size); break; default: return; } - return ta.call(this, a, c, d, f, b, e); + return Aa.call(this, a, c, d, f, b, e); }; -x.import = function(a, c) { +A.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = sa(c, this.reg); + this.reg = za(c, this.reg); break; case "map": - this.map = oa(c, this.map); + this.map = ta(c, this.map); break; case "ctx": - this.ctx = qa(c, this.ctx); + this.ctx = va(c, this.ctx); } } }; -x.serialize = function(a = !0) { +A.serialize = function(a = !0) { let c = "", b = "", e = ""; if (this.reg.size) { let f; @@ -1755,11 +1841,11 @@ x.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = ua(this.map, f); + b = Ba(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = ua(g[1], f); + let k = Ba(g[1], f); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; e += (e ? "," : "") + k; @@ -1768,11 +1854,11 @@ x.serialize = function(a = !0) { } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; -ia(M.prototype); -B(); -const Xa = {Index:M, Charset:Ta, Encoder:I, Document:U, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Ya = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; -let $a; -($a = Ya.define) && $a.amd ? $a([], function() { - return Xa; -}) : "object" === typeof Ya.exports ? Ya.exports = Xa : Ya.FlexSearch = Xa; +ka(Z.prototype); +J(); +const gb = {Index:Z, Charset:ab, Encoder:ja, Document:T, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, hb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let ib; +(ib = hb.define) && ib.amd ? ib([], function() { + return gb; +}) : "object" === typeof hb.exports ? hb.exports = gb : hb.FlexSearch = gb; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 0ab471a..867b628 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,63 +1,63 @@ /**! - * FlexSearch.js v0.8.158 (Bundle) + * FlexSearch.js v0.8.160 (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 x;function z(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(k){return a(b(k))};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 B(){return Object.create(null)}function C(a){return"string"===typeof a} -function G(a){return"object"===typeof a}function H(a,c){if(C(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ba)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!0,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=z((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,1024,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=b=z(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof b?b:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.C="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.C+= -(this.C?"|":"")+d;return this};x.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.C+=(this.C?"|":"")+a;this.N=null;this.cache&&J(this);return this};x.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&J(this);return this}; -x.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.h+=(this.h?"|":"")+a;this.M=null;this.cache&&J(this);return this}; -x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&J(this);return this}; -x.encode=function(a,c){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(J,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ha?a.normalize("NFKD").replace(ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(c){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(b)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var h=this.G.get(m);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(J,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ -this.C+")$"));let r;for(;r!==m&&2this.stemmer.get(p))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(r)));if(m&&this.replacer)for(h=0;m&&hthis.R&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==n)if(c){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.F.set(a,e),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return e};function J(a){a.H=null;a.F.clear();a.G.clear()};let K,L;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":L=a.options||{};(c=a.factory)?(Function("return "+c)()(self),K=new self.FlexSearch.Index(L),delete self.FlexSearch):K=new N(L);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=L.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await L.import.call(K,e[0]),K.import(e[0],a)):(d=e&&K[c].apply(K,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){O.call(a,"add");O.call(a,"append");O.call(a,"search");O.call(a,"update");O.call(a,"remove")}let ka,la,P;function ma(){ka=P=0} -function O(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]);ka?P||(P=Date.now()-la>=this.priority*this.priority*3):(ka=setTimeout(ma,0),la=Date.now());if(P){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 Q=0; -function R(a={}){function c(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[++Q]=function(){h(d);1E9b||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=B();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?V.call(this,g):g;d.push(g);c-=k;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};W.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:k,offset:h,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; -function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){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?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.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 k=this;return Promise.all(c).then(function(h){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?V.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=B();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(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)}; -X.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};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:!1,numeric:!1,dedupe:!1};const Oa={};const Pa=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 Qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Sa={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 Ta={Exact:Na,Default:Oa,Normalize:Oa,LatinBalance:{mapper:Pa},LatinAdvanced:{mapper:Pa,matcher:Qa,replacer:Ra},LatinExtra:{mapper:Pa,replacer:Ra.concat([/(?!^)[aeo]/g,""]),matcher:Qa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bd.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,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;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,f,g;dt;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Va(r, -l,p,d,u);Z(this,n,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g? -0:1),l,p,k-1,h-1),u=this.bidirectional&&q>f;Z(this,m,u?f:q,t,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=B()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Va(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};function N(a,c){if(!this||this.constructor!==N)return new N(a);if(a){var b=C(a)?a:a.preset;b&&(a=Object.assign({},Ua[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=C(a.encoder)?Ta[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new I(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;b=!1;this.map=new Map;this.ctx=new Map;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 X(b);this.priority=a.priority||4}x=N.prototype;x.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};x.append=function(a,c){return this.add(a,c,!0)};x.contain=function(a){return this.reg.has(a)}; -x.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)};x.cleanup=function(){if(!this.fastupdate)return this;Y(this.map);this.depth&&Y(this.ctx);return this};x.searchCache=Ma;x.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=sa(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=oa(this.map,this.reg.size);break;case 3:d="ctx";f=qa(this.ctx,this.reg.size);break;default:return}return T.call(this,a,c,d,f,b,e)}; -x.import=function(a,c){if(c)switch("string"===typeof c&&(c=JSON.parse(c)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1"a1a".split(b).length; +this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,ba)}catch(d){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:H(b&&new Set(b),null,this.filter);this.dedupe=H(a.dedupe,!0,this.dedupe);this.matcher=H((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=H((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=H((b=a.stemmer)&&new Map(b), +null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,1024,this.maxlength);this.rtl=H(a.rtl,!1,this.rtl);if(this.cache=b=H(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof b?b:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.C="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.C+= +(this.C?"|":"")+d;return this};A.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.C+=(this.C?"|":"")+a;this.N=null;this.cache&&R(this);return this};A.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&R(this);return this}; +A.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.h+=(this.h?"|":"")+a;this.M=null;this.cache&&R(this);return this}; +A.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&R(this);return this}; +A.encode=function(a,c){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(R,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ia?a.normalize("NFKD").replace(ia,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(c){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(b)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var h=this.G.get(m);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(R,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ +this.C+")$"));let r;for(;r!==m&&2this.stemmer.get(q))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(r)));if(m&&this.replacer)for(h=0;m&&hthis.R&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==p)if(c){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.F.set(a,e),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return e};function R(a){a.H=null;a.F.clear();a.G.clear()};function ka(a){na.call(a,"add");na.call(a,"append");na.call(a,"search");na.call(a,"update");na.call(a,"remove")}let oa,pa,qa;function ra(){oa=qa=0} +function na(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]);oa?qa||(qa=Date.now()-pa>=this.priority*this.priority*3):(oa=setTimeout(ra,0),pa=Date.now());if(qa){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 sa(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 ta(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 Fa(a,c,b){const e=[],d=I();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?U.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?U.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Fa(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:k,offset:h,enrich:l,resolve:m,suggest:p}=Ia(this,"and",arguments);return Ka.call(this,f,g,k,h,l,m,p)}return d?this.resolve(c,b,e):this}; +function Ka(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=Ea(a,c,b,e,g),f?d?U.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}=Ia(this,"xor",arguments);return La.call(this,a,c,b,e,d,f,g)}; +function La(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Ma.call(this,a,b,e,f,this.h),f?d?U.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Ma(a,c,b,e,d){const f=[],g=I();let k=0;for(let h=0,l;hE&&(E=n.length+(n?1:0)),v=n.length+(n?1:0)+L.length,B+=D,ma.push(y.length),y.push({match:L})),n+=(n?" ":"")+L)}if(!u)C=x[z],n+=(n?" ":"")+C,h&&y.push({text:C});else if(h&&B>=h)break}B=ma.length*(f.length-2);if(q||t||h&&n.length-B>h)if(B=h+B-2*r,z=v-E,0x&&(x=0)),y=y.length-1){if(F>=y.length){z[u+1]= +1;F>=x.length&&(B[u+1]=1);continue}D-=r}n=y[F].text;if(G=t&&K[u])if(0G)if(z[u+1]=1,l)n=n.substring(0,G);else continue;(G-=n.length)||(G=-1);K[u]=G}else{z[u+1]=1;continue}if(D+n.length+1<=h)n=" "+n,v[u]+=n;else if(l)P=h-D-1,0=F){if(0>F){z[u]=1;B[u]=1;continue}D-=r}n=y[F].text;if(G=q&&C[u])if(0G)if(z[u]=1,l)n=n.substring(n.length- +G);else continue;(G-=n.length)||(G=-1);C[u]=G}else{z[u]=1;continue}if(D+n.length+1<=h)n+=" ",v[u]=n+v[u];else if(l)P=n.length+1-(h-D),0<=P&&P=x.length-1?xa=1:Fb||e)a=a.slice(e,e+b);d&&(a=U.call(this,a));return a}} +function U(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 Va={normalize:!1,numeric:!1,dedupe:!1};const Wa={};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"],["ph","f"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\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};var ab={Exact:Va,Default:Wa,Normalize:Wa,LatinBalance:{mapper:Xa},LatinAdvanced:{mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bd.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else bb(this.map,a),this.depth&&bb(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function bb(a,c){let b=0;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,f,g;dw;f--){g=t.substring(w,f);n=this.rtl?d-1-w:w;var k=this.score?this.score(c,t,q,g,n):db(r, +l,q,d,n);eb(this,p,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),l,q,k-1,h-1),n=this.bidirectional&&t>f;eb(this,m,n?f:t,w,a,b,n?t:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function eb(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=I()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))} +function db(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};function Z(a,c){if(!this||this.constructor!==Z)return new Z(a);if(a){var b=J(a)?a:a.preset;b&&(a=Object.assign({},cb[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=J(a.encoder)?ab[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ja(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;b=!1;this.map=new Map;this.ctx=new Map;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 Y(b);this.priority=a.priority||4}A=Z.prototype;A.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};A.append=function(a,c){return this.add(a,c,!0)};A.contain=function(a){return this.reg.has(a)}; +A.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)};A.cleanup=function(){if(!this.fastupdate)return this;bb(this.map);this.depth&&bb(this.ctx);return this};A.searchCache=Ua;A.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=ya(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=sa(this.map,this.reg.size);break;case 3:d="ctx";f=ua(this.ctx,this.reg.size);break;default:return}return Aa.call(this,a,c,d,f,b,e)}; +A.import=function(a,c){if(c)switch("string"===typeof c&&(c=JSON.parse(c)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1 "a1a".split(b).length; } - this.numeric = z(a.numeric, e); + this.numeric = I(a.numeric, e); } else { try { - this.split = z(this.split, ba); + this.split = I(this.split, ba); } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = z(a.numeric, z(this.numeric, !0)); + this.numeric = I(a.numeric, I(this.numeric, !0)); } - this.prepare = z(a.prepare, null, this.prepare); - this.finalize = z(a.finalize, null, this.finalize); + this.prepare = I(a.prepare, null, this.prepare); + this.finalize = I(a.finalize, null, this.finalize); b = a.filter; - this.filter = "function" === typeof b ? b : z(b && new Set(b), null, this.filter); - this.dedupe = z(a.dedupe, !0, this.dedupe); - this.matcher = z((b = a.matcher) && new Map(b), null, this.matcher); - this.mapper = z((b = a.mapper) && new Map(b), null, this.mapper); - this.stemmer = z((b = a.stemmer) && new Map(b), null, this.stemmer); - this.replacer = z(a.replacer, null, this.replacer); - this.minlength = z(a.minlength, 1, this.minlength); - this.maxlength = z(a.maxlength, 1024, this.maxlength); - this.rtl = z(a.rtl, !1, this.rtl); - if (this.cache = b = z(a.cache, !0, this.cache)) { + this.filter = "function" === typeof b ? b : I(b && new Set(b), null, this.filter); + this.dedupe = I(a.dedupe, !0, this.dedupe); + this.matcher = I((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = I((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = I((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = I(a.replacer, null, this.replacer); + this.minlength = I(a.minlength, 1, this.minlength); + this.maxlength = I(a.maxlength, 1024, this.maxlength); + this.rtl = I(a.rtl, !1, this.rtl); + if (this.cache = b = I(a.cache, !0, this.cache)) { this.H = null, this.R = "number" === typeof b ? b : 2e5, this.F = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; @@ -147,20 +147,20 @@ x.assign = function(a) { } return this; }; -x.addStemmer = function(a, c) { +A.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); this.C += (this.C ? "|" : "") + a; this.N = null; - this.cache && J(this); + this.cache && R(this); return this; }; -x.addFilter = function(a) { +A.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && J(this); + this.cache && R(this); return this; }; -x.addMapper = function(a, c) { +A.addMapper = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -169,10 +169,10 @@ x.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && J(this); + this.cache && R(this); return this; }; -x.addMatcher = function(a, c) { +A.addMatcher = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -183,35 +183,35 @@ x.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && J(this); + this.cache && R(this); return this; }; -x.addReplacer = function(a, c) { +A.addReplacer = function(a, c) { if ("string" === typeof a) { return this.addMatcher(a, c); } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && J(this); + this.cache && R(this); return this; }; -x.encode = function(a, c) { +A.encode = function(a, c) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.F.has(a)) { return this.F.get(a); } } else { - this.H = setTimeout(J, 50, this); + this.H = setTimeout(R, 50, this); } } - this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = fa ? a.normalize("NFKD").replace(fa, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ia ? a.normalize("NFKD").replace(ia, "").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 ")); + this.numeric && 3 < a.length && (a = a.replace(fa, "$1 $2").replace(ha, "$1 $2").replace(ea, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = B(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; - for (let l = 0, m, n; l < k.length; l++) { - if ((m = n = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { + let e = [], d = J(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; + for (let l = 0, m, p; l < k.length; l++) { + if ((m = p = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (c) { if (d[m]) { continue; @@ -235,20 +235,20 @@ x.encode = function(a, c) { continue; } } else { - this.H = setTimeout(J, 50, this); + this.H = setTimeout(R, 50, this); } } if (this.stemmer) { this.N || (this.N = new RegExp("(?!^)(" + this.C + ")$")); let r; for (; r !== m && 2 < m.length;) { - r = m, m = m.replace(this.N, p => this.stemmer.get(p)); + r = m, m = m.replace(this.N, q => this.stemmer.get(q)); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { h = ""; - for (let r = 0, p = "", q, t; r < m.length; r++) { - q = m.charAt(r), q === p && this.dedupe || ((t = this.mapper && this.mapper.get(q)) || "" === t ? t === p && this.dedupe || !(p = t) || (h += t) : h += p = q); + for (let r = 0, q = "", t, w; r < m.length; r++) { + t = m.charAt(r), t === q && this.dedupe || ((w = this.mapper && this.mapper.get(t)) || "" === w ? w === q && this.dedupe || !(q = w) || (h += w) : h += q = t); } m = h; } @@ -258,9 +258,9 @@ x.encode = function(a, c) { m = m.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && n.length <= this.L && (this.G.set(n, m), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && p.length <= this.L && (this.G.set(p, m), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); if (m) { - if (m !== n) { + if (m !== p) { if (c) { if (d[m]) { continue; @@ -283,61 +283,30 @@ x.encode = function(a, c) { this.cache && a.length <= this.K && (this.F.set(a, e), this.F.size > this.R && (this.F.clear(), this.K = this.K / 1.1 | 0)); return e; }; -function J(a) { +function R(a) { a.H = null; a.F.clear(); a.G.clear(); } -;let K, L; -async function ha(a) { - a = a.data; - var c = a.task; - const b = a.id; - let e = a.args; - switch(c) { - case "init": - L = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), K = new self.FlexSearch.Index(L), delete self.FlexSearch) : K = new M(L); - postMessage({id:b}); - break; - default: - let d; - if ("export" === c) { - if (!L.export || "function" !== typeof L.export) { - throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); - } - e[1] ? (e[0] = L.export, e[2] = 0, e[3] = 1) : e = null; - } - if ("import" === c) { - if (!L.import || "function" !== typeof L.import) { - throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); - } - e[0] && (a = await L.import.call(K, e[0]), K.import(e[0], a)); - } else { - (d = e && K[c].apply(K, e)) && d.then && (d = await d); - } - postMessage("search" === c ? {id:b, msg:d} : {id:b}); - } +;function ka(a) { + na.call(a, "add"); + na.call(a, "append"); + na.call(a, "search"); + na.call(a, "update"); + na.call(a, "remove"); } -;function ia(a) { - P.call(a, "add"); - P.call(a, "append"); - P.call(a, "search"); - P.call(a, "update"); - P.call(a, "remove"); +let oa, pa, qa; +function ra() { + oa = qa = 0; } -let ja, ka, Q; -function la() { - ja = Q = 0; -} -function P(a) { +function na(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]); - ja ? Q || (Q = Date.now() - ka >= this.priority * this.priority * 3) : (ja = setTimeout(la, 0), ka = Date.now()); - if (Q) { + oa ? qa || (qa = Date.now() - pa >= this.priority * this.priority * 3) : (oa = setTimeout(ra, 0), pa = Date.now()); + if (qa) { const f = this; return new Promise(g => { setTimeout(function() { @@ -351,70 +320,7 @@ function P(a) { return b; }; } -;let R = 0; -function S(a = {}) { - function c(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[++R] = function() { - h(d); - 1e9 < R && (R = 0); - }; - d.worker.postMessage({id:R, task:"init", factory:b, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:b, options:a}); - this.priority = a.priority || 4; - return this; - } - } - if (!this || this.constructor !== S) { - return new S(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 = ma(b, e, a.worker); - return f.then ? f.then(function(g) { - return c.call(d, g); - }) : c.call(this, f); -} -T("add"); -T("append"); -T("search"); -T("update"); -T("remove"); -T("clear"); -T("export"); -T("import"); -ia(S.prototype); -function T(a) { - S.prototype[a] = function() { - const c = this, b = [].slice.call(arguments); - var e = b[b.length - 1]; - let d; - "function" === typeof e && (d = e, b.pop()); - e = new Promise(function(f) { - "export" === a && "function" === typeof b[0] && (b[0] = null); - c.h[++R] = f; - c.worker.postMessage({task:a, id:R, args:b}); - }); - return d ? (e.then(d), this) : e; - }; -} -function ma(a, c, b) { - return c ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/worker/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 na(a, c = 0) { +;function sa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -423,30 +329,30 @@ function ma(a, c, b) { e.length && b.push(e); return b; } -function oa(a, c) { +function ta(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 pa(a, c = 0) { +function ua(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], na(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], sa(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function qa(a, c) { +function xa(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], oa(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], ta(e[1], d)); } return c; } -function ra(a) { +function ya(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -454,14 +360,14 @@ function ra(a) { b.length && c.push(b); return c; } -function sa(a, c) { +function za(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function ta(a, c, b, e, d, f, g = 0) { +function Aa(a, c, b, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { @@ -470,12 +376,12 @@ function ta(a, c, b, e, d, f, g = 0) { if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return ta.call(l, a, c, b, k ? e : null, d, f, g + 1); + return Aa.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return ta.call(this, a, c, b, k ? e : null, d, f, g + 1); + return Aa.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function ua(a, c) { +function Ba(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; @@ -495,8 +401,8 @@ function ua(a, c) { } return b; } -;U.prototype.add = function(a, c, b) { - G(a) && (c = a, a = H(c, this.key)); +;T.prototype.add = function(a, c, b) { + M(a) && (c = a, a = Q(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -509,7 +415,7 @@ function ua(a, c) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : C(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : K(h) && (h = [h]), Ca(c, h, this.J, 0, e, a, h[0], b); } } } @@ -517,7 +423,7 @@ function ua(a, c) { for (e = 0; e < this.B.length; e++) { var f = this.B[e], g = this.T[e]; d = this.tag.get(g); - let k = B(); + let k = J(); if ("function" === typeof f) { if (f = f(c), !f) { continue; @@ -528,10 +434,10 @@ function ua(a, c) { continue; } f.constructor === String && (f = "" + f); - f = H(c, f); + f = Q(c, f); } if (d && f) { - C(f) && (f = [f]); + K(f) && (f = [f]); for (let h = 0, l, m; h < f.length; h++) { l = f[h], k[l] || (k[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])))); } @@ -543,7 +449,7 @@ function ua(a, c) { if (this.store && (!b || !this.store.has(a))) { let k; if (this.A) { - k = B(); + k = J(); for (let h = 0, l; h < this.A.length; h++) { l = this.A[h]; if ((b = l.I) && !b(c)) { @@ -556,11 +462,11 @@ function ua(a, c) { continue; } l = [l.U]; - } else if (C(l) || l.constructor === String) { + } else if (K(l) || l.constructor === String) { k[l] = c[l]; continue; } - wa(c, k, l, 0, l[0], m); + Da(c, k, l, 0, l[0], m); } } this.store.set(a, k || c); @@ -568,21 +474,21 @@ function ua(a, c) { } return this; }; -function wa(a, c, b, e, d, f) { +function Da(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++) { - wa(a, c, b, e, d); + Da(a, c, b, e, d); } } else { - c = c[d] || (c[d] = B()), d = b[++e], wa(a, c, b, e, d); + c = c[d] || (c[d] = J()), d = b[++e], Da(a, c, b, e, d); } } } -function va(a, c, b, e, d, f, g, k) { +function Ca(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -598,24 +504,24 @@ function va(a, c, b, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - va(a, c, b, e, d, f, g, k); + Ca(a, c, b, e, d, f, g, k); } } else { - g = c[++e], va(a, c, b, e, d, f, g, k); + g = c[++e], Ca(a, c, b, e, d, f, g, k); } } } } -;function xa(a, c, b, e, d) { +;function Ea(a, c, b, e, d) { const f = a.length; let g = [], k, h; - k = B(); - for (let l = 0, m, n, r, p; l < c; l++) { - for (let q = 0; q < f; q++) { - if (r = a[q], l < r.length && (m = r[l])) { - for (let t = 0; t < m.length; t++) { - if (n = m[t], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n), b && h === f - 1 && p.length - e === b) { - return e ? p.slice(e) : p; + k = J(); + for (let l = 0, m, p, r, q; l < c; l++) { + for (let t = 0; t < f; t++) { + if (r = a[t], l < r.length && (m = r[l])) { + for (let w = 0; w < m.length; w++) { + if (p = m[w], (h = k[p]) ? k[p]++ : (h = 0, k[p] = 1), q = g[h] || (g[h] = []), q.push(p), b && h === f - 1 && q.length - e === b) { + return e ? q.slice(e) : q; } } } @@ -623,7 +529,7 @@ function va(a, c, b, e, d, f, g, k) { } if (a = g.length) { if (d) { - g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? Fa(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -638,8 +544,8 @@ function va(a, c, b, e, d, f, g, k) { } return g; } -function ya(a, c, b) { - const e = [], d = B(); +function Fa(a, c, b) { + const e = [], d = J(); let f; var g = a.length; let k; @@ -660,8 +566,8 @@ function ya(a, c, b) { } return e; } -function za(a, c) { - const b = B(), e = []; +function Ga(a, c) { + const b = J(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; for (let g = 0; g < f.length; g++) { @@ -673,12 +579,12 @@ function za(a, c) { } return e; } -;function Aa(a, c, b, e) { +;function Ha(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 ? V.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? U.call(this, a) : a; } let d = []; for (let f = 0, g, k; f < a.length; f++) { @@ -692,7 +598,7 @@ function za(a, c) { } k > c && (g = g.slice(0, c), k = c); if (!d.length && k >= c) { - return e ? V.call(this, g) : g; + return e ? U.call(this, g) : g; } d.push(g); c -= k; @@ -702,9 +608,9 @@ function za(a, c) { } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? V.call(this, d) : d; + return e ? U.call(this, d) : d; } -;function Ba(a, c, b) { +;function Ia(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -716,24 +622,24 @@ function za(a, c) { } e = []; let d = [], f = 0, g = 0, k, h, l; - for (let m = 0, n; m < b.length; m++) { - if (n = b[m]) { + for (let m = 0, p; m < b.length; m++) { + if (p = b[m]) { let r; - if (n.constructor === W) { - r = n.result; - } else if (n.constructor === Array) { - r = n; + if (p.constructor === X) { + r = p.result; + } else if (p.constructor === Array) { + r = p; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, r = n.index.search(n).result, n.resolve = h, n.enrich = k; - } else if (n.and) { - r = a.and(n.and); - } else if (n.or) { - r = a.or(n.or); - } else if (n.xor) { - r = a.xor(n.xor); - } else if (n.not) { - r = a.not(n.not); + if (f = p.limit || 0, g = p.offset || 0, l = p.suggest, h = p.resolve, k = p.enrich && h, p.index) { + p.resolve = !1, p.enrich = !1, r = p.index.search(p).result, p.resolve = h, p.enrich = k; + } else if (p.and) { + r = a.and(p.and); + } else if (p.or) { + r = a.or(p.or); + } else if (p.xor) { + r = a.xor(p.xor); + } else if (p.not) { + r = a.not(p.not); } else { continue; } @@ -750,11 +656,11 @@ function za(a, c) { } return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } -;W.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); +;X.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ia(this, "or", arguments); + return Ja.call(this, a, c, b, e, d, f); }; -function Ca(a, c, b, e, d, f) { +function Ja(a, c, b, e, d, f) { if (c.length) { const g = this; return Promise.all(c).then(function(k) { @@ -762,25 +668,25 @@ function Ca(a, c, b, e, d, f) { for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return Ca.call(g, a, [], b, e, d, f); + return Ja.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 = ya(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Fa(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } -;W.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:k, offset:h, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); - return Da.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:p} = Ia(this, "and", arguments); + return Ka.call(this, f, g, k, h, l, m, p); } return d ? this.resolve(c, b, e) : this; }; -function Da(a, c, b, e, d, f, g) { +function Ka(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -788,7 +694,7 @@ function Da(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Da.call(k, a, [], b, e, d, f, g); + return Ka.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -796,7 +702,7 @@ function Da(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = xa(a, c, b, e, g), f ? d ? V.call(this.index, this.result) : this.result : this; + return this.result = Ea(a, c, b, e, g), f ? d ? U.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -805,11 +711,11 @@ function Da(a, c, b, e, d, f, g) { } return f ? this.resolve(b, e, d) : this; } -;W.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); +;X.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ia(this, "xor", arguments); + return La.call(this, a, c, b, e, d, f, g); }; -function Ea(a, c, b, e, d, f, g) { +function La(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -817,52 +723,52 @@ function Ea(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ea.call(k, a, [], b, e, d, f, g); + return La.call(k, 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 = Fa.call(this, a, b, e, f, this.h), f ? d ? V.call(this.index, this.result) : this.result : this; + return this.result = Ma.call(this, a, b, e, f, this.h), f ? d ? U.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 = B(); +function Ma(a, c, b, e, d) { + const f = [], g = J(); let k = 0; for (let h = 0, l; h < a.length; h++) { if (l = a[h]) { k < l.length && (k = l.length); - for (let m = 0, n; m < l.length; m++) { - if (n = l[m]) { - for (let r = 0, p; r < n.length; r++) { - p = n[r], g[p] = g[p] ? 2 : 1; + for (let m = 0, p; m < l.length; m++) { + if (p = l[m]) { + for (let r = 0, q; r < p.length; r++) { + q = p[r], g[q] = g[q] ? 2 : 1; } } } } } for (let h = 0, l, m = 0; h < k; h++) { - for (let n = 0, r; n < a.length; n++) { - if (r = a[n]) { + for (let p = 0, r; p < a.length; p++) { + if (r = a[p]) { if (l = r[h]) { - for (let p = 0, q; p < l.length; p++) { - if (q = l[p], 1 === g[q]) { + for (let q = 0, t; q < l.length; q++) { + if (t = l[q], 1 === g[t]) { if (b) { b--; } else { if (e) { - if (f.push(q), f.length === c) { + if (f.push(t), f.length === c) { return f; } } else { - const t = h + (n ? d : 0); - f[t] || (f[t] = []); - f[t].push(q); + const w = h + (p ? d : 0); + f[w] || (f[w] = []); + f[w].push(t); if (++m === c) { return f; } @@ -876,11 +782,11 @@ function Fa(a, c, b, e, d) { } return f; } -;W.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); +;X.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ia(this, "not", arguments); + return Na.call(this, a, c, b, e, d, f, g); }; -function Ga(a, c, b, e, d, f, g) { +function Na(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -888,17 +794,17 @@ function Ga(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Ga.call(k, a, [], b, e, d, f, g); + return Na.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ha.call(this, a, b, e, f); + this.result = Pa.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? V.call(this.index, this.result) : this.result : this; + return f ? d ? U.call(this.index, this.result) : this.result : this; } -function Ha(a, c, b, e) { +function Pa(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { @@ -924,9 +830,9 @@ function Ha(a, c, b, e) { } return d; } -;function W(a) { - if (!this || this.constructor !== W) { - return new W(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; @@ -935,7 +841,7 @@ function Ha(a, c, b, e) { this.result = a || []; this.h = 0; } -W.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++) { @@ -954,7 +860,7 @@ W.prototype.limit = function(a) { } return this; }; -W.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++) { @@ -966,81 +872,314 @@ W.prototype.offset = function(a) { } return this; }; -W.prototype.boost = function(a) { +X.prototype.boost = function(a) { this.h += a; return this; }; -W.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), Aa.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Ha.call(d, e, a || 100, c, b)) : e; }; -B(); -U.prototype.search = function(a, c, b, e) { - b || (!c && G(a) ? (b = a, a = "") : G(c) && (b = c, c = 0)); +J(); +function Qa(a, c, b, e, d) { + let f, g, k; + "string" === typeof d ? (f = d, d = "") : f = d.template; + if (!f) { + throw Error('No template pattern was specified by the search option "highlight"'); + } + g = f.indexOf("$1"); + if (-1 === g) { + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); + } + k = f.substring(g + 2); + g = f.substring(0, g); + let h = d && d.boundary, l = !d || !1 !== d.clip, m = d && d.merge && k && g && new RegExp(k + " " + g, "g"); + d = d && d.ellipsis; + var p = 0; + if ("object" === typeof d) { + var r = d.template; + p = r.length - 2; + d = d.pattern; + } + "string" !== typeof d && (d = !1 === d ? "" : "..."); + p && (d = r.replace("$1", d)); + r = d.length - p; + let q, t; + "object" === typeof h && (q = h.before, 0 === q && (q = -1), t = h.after, 0 === t && (t = -1), h = h.total || 9e5); + p = new Map(); + for (let va = 0, V, Oa, ca; va < c.length; va++) { + let da; + if (e) { + da = c, ca = e; + } else { + var w = c[va]; + ca = w.field; + if (!ca) { + continue; + } + da = w.result; + } + Oa = b.get(ca); + V = Oa.encoder; + w = p.get(V); + "string" !== typeof w && (w = V.encode(a), p.set(V, w)); + for (let la = 0; la < da.length; la++) { + var n = da[la].doc; + if (!n) { + continue; + } + n = Q(n, ca); + if (!n) { + continue; + } + var x = n.trim().split(/\s+/); + if (!x.length) { + continue; + } + n = ""; + var y = []; + let ma = []; + var E = -1, v = -1, B = 0; + for (var z = 0; z < x.length; z++) { + var C = x[z], H = V.encode(C); + H = 1 < H.length ? H.join(" ") : H[0]; + let u; + if (H && C) { + var D = C.length, N = (V.split ? C.replace(V.split, "") : C).length - H.length, L = "", S = 0; + for (var W = 0; W < w.length; W++) { + var O = w[W]; + if (O) { + var G = O.length; + G += N; + S && G <= S || (O = H.indexOf(O), -1 < O && (L = (O ? C.substring(0, O) : "") + g + C.substring(O, O + G) + k + (O + G < D ? C.substring(O + G) : ""), S = G, u = !0)); + } + } + L && (h && (0 > E && (E = n.length + (n ? 1 : 0)), v = n.length + (n ? 1 : 0) + L.length, B += D, ma.push(y.length), y.push({match:L})), n += (n ? " " : "") + L); + } + if (!u) { + C = x[z], n += (n ? " " : "") + C, h && y.push({text:C}); + } else if (h && B >= h) { + break; + } + } + B = ma.length * (f.length - 2); + if (q || t || h && n.length - B > h) { + if (B = h + B - 2 * r, z = v - E, 0 < q && (z += q), 0 < t && (z += t), z <= B) { + x = q ? E - (0 < q ? q : 0) : E - ((B - z) / 2 | 0), y = t ? v + (0 < t ? t : 0) : x + B, l || (0 < x && " " !== n.charAt(x) && " " !== n.charAt(x - 1) && (x = n.indexOf(" ", x), 0 > x && (x = 0)), y < n.length && " " !== n.charAt(y - 1) && " " !== n.charAt(y) && (y = n.lastIndexOf(" ", y), y < v ? y = v : ++y)), n = (x ? d : "") + n.substring(x, y) + (y < n.length ? d : ""); + } else { + v = []; + E = {}; + B = {}; + z = {}; + C = {}; + H = {}; + L = N = D = 0; + for (W = S = 1;;) { + var P = void 0; + for (let u = 0, F; u < ma.length; u++) { + F = ma[u]; + if (L) { + if (N !== L) { + if (z[u + 1]) { + continue; + } + F += L; + if (E[F]) { + D -= r; + B[u + 1] = 1; + z[u + 1] = 1; + continue; + } + if (F >= y.length - 1) { + if (F >= y.length) { + z[u + 1] = 1; + F >= x.length && (B[u + 1] = 1); + continue; + } + D -= r; + } + n = y[F].text; + if (G = t && H[u]) { + if (0 < G) { + if (n.length > G) { + if (z[u + 1] = 1, l) { + n = n.substring(0, G); + } else { + continue; + } + } + (G -= n.length) || (G = -1); + H[u] = G; + } else { + z[u + 1] = 1; + continue; + } + } + if (D + n.length + 1 <= h) { + n = " " + n, v[u] += n; + } else if (l) { + P = h - D - 1, 0 < P && (n = " " + n.substring(0, P), v[u] += n), z[u + 1] = 1; + } else { + z[u + 1] = 1; + continue; + } + } else { + if (z[u]) { + continue; + } + F -= N; + if (E[F]) { + D -= r; + z[u] = 1; + B[u] = 1; + continue; + } + if (0 >= F) { + if (0 > F) { + z[u] = 1; + B[u] = 1; + continue; + } + D -= r; + } + n = y[F].text; + if (G = q && C[u]) { + if (0 < G) { + if (n.length > G) { + if (z[u] = 1, l) { + n = n.substring(n.length - G); + } else { + continue; + } + } + (G -= n.length) || (G = -1); + C[u] = G; + } else { + z[u] = 1; + continue; + } + } + if (D + n.length + 1 <= h) { + n += " ", v[u] = n + v[u]; + } else if (l) { + P = n.length + 1 - (h - D), 0 <= P && P < n.length && (n = n.substring(P) + " ", v[u] = n + v[u]), z[u] = 1; + } else { + z[u] = 1; + continue; + } + } + } else { + n = y[F].match; + q && (C[u] = q); + t && (H[u] = t); + u && D++; + let wa; + F ? !u && r && (D += r) : (B[u] = 1, z[u] = 1); + F >= x.length - 1 ? wa = 1 : F < y.length - 1 && y[F + 1].match ? wa = 1 : r && (D += r); + D -= f.length - 2; + if (!u || D + n.length <= h) { + v[u] = n; + } else { + P = S = W = B[u] = 0; + break; + } + wa && (B[u + 1] = 1, z[u + 1] = 1); + } + D += n.length; + P = E[F] = 1; + } + if (P) { + N === L ? L++ : N++; + } else { + N === L ? S = 0 : W = 0; + if (!S && !W) { + break; + } + S ? (N++, L = N) : L++; + } + } + n = ""; + for (let u = 0, F; u < v.length; u++) { + F = (u && B[u] ? " " : (u && !d ? " " : "") + d) + v[u], n += F; + } + d && !B[v.length] && (n += d); + } + } + m && (n = n.replace(m, " ")); + da[la].highlight = n; + } + if (e) { + break; + } + } + return c; +} +;T.prototype.search = function(a, c, b, e) { + b || (!c && M(a) ? (b = a, a = "") : M(c) && (b = c, c = 0)); let d = []; var f = []; let g; let k, h, l; - let m = 0, n = !0, r; + let m = 0, p = !0, r; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; - var p = b.pluck; - var q = b.merge; - h = p || b.field || (h = b.index) && (h.index ? null : h); + var q = b.pluck; + var t = b.merge; + h = q || b.field || (h = b.index) && (h.index ? null : h); l = this.tag && b.tag; k = b.suggest; - n = !0; - this.store && b.enrich && !n && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - r = (g = this.store && b.enrich && n) && b.highlight; + p = !0; + this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + g = (r = p && this.store && b.highlight) || p && this.store && b.enrich; c = b.limit || c; - var t = b.offset || 0; + var w = b.offset || 0; c || (c = 100); if (l) { l.constructor !== Array && (l = [l]); - var u = []; - for (let A = 0, v; A < l.length; A++) { - v = l[A]; - if (C(v)) { + var n = []; + for (let E = 0, v; E < l.length; E++) { + v = l[E]; + if (K(v)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (v.field && v.tag) { - var w = v.tag; - if (w.constructor === Array) { - for (var y = 0; y < w.length; y++) { - u.push(v.field, w[y]); + var x = v.tag; + if (x.constructor === Array) { + for (var y = 0; y < x.length; y++) { + n.push(v.field, x[y]); } } else { - u.push(v.field, w); + n.push(v.field, x); } } else { - w = Object.keys(v); - for (let D = 0, E, F; D < w.length; D++) { - if (E = w[D], F = v[E], F.constructor === Array) { - for (y = 0; y < F.length; y++) { - u.push(E, F[y]); + x = Object.keys(v); + for (let B = 0, z, C; B < x.length; B++) { + if (z = x[B], C = v[z], C.constructor === Array) { + for (y = 0; y < C.length; y++) { + n.push(z, C[y]); } } else { - u.push(E, F); + n.push(z, C); } } } } - if (!u.length) { + if (!n.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = u; + l = n; if (!a) { f = []; - if (u.length) { - for (p = 0; p < u.length; p += 2) { - q = Ia.call(this, u[p], u[p + 1], c, t, g), d.push({field:u[p], tag:u[p + 1], result:q}); + if (n.length) { + for (q = 0; q < n.length; q += 2) { + t = Ra.call(this, n[q], n[q + 1], c, w, g), d.push({field:n[q], tag:n[q + 1], result:t}); } } - return f.length ? Promise.all(f).then(function(A) { - for (let v = 0; v < A.length; v++) { - d[v].result = A[v]; + return f.length ? Promise.all(f).then(function(E) { + for (let v = 0; v < E.length; v++) { + d[v].result = E[v]; } return d; }) : d; @@ -1049,134 +1188,81 @@ U.prototype.search = function(a, c, b, e) { h && h.constructor !== Array && (h = [h]); } h || (h = this.field); - u = !e && (this.worker || this.db) && []; - for (let A = 0, v, D, E; A < h.length; A++) { - D = h[A]; - let F; - C(D) || (F = D, D = F.field, a = F.query || a, c = F.limit || c, t = F.offset || t, k = F.suggest || k, g = this.store && (F.enrich || g)); + n = !e && (this.worker || this.db) && []; + for (let E = 0, v, B, z; E < h.length; E++) { + B = h[E]; + let C; + K(B) || (C = B, B = C.field, a = C.query || a, c = C.limit || c, w = C.offset || w, k = C.suggest || k, r = (g = this.store && (C.enrich || g)) && (b.highlight || r)); if (e) { - v = e[A]; + v = e[E]; } else { - if (w = F || b, y = this.index.get(D), l && (w.enrich = !1), u) { - u[A] = y.search(a, c, w); - w && g && (w.enrich = g); + if (x = C || b, y = this.index.get(B), l && (x.enrich = !1), n) { + n[E] = y.search(a, c, x); + x && g && (x.enrich = g); continue; } else { - v = y.search(a, c, w), w && g && (w.enrich = g); + v = y.search(a, c, x), x && g && (x.enrich = g); } } - E = v && (n ? v.length : v.result.length); - if (l && E) { - w = []; + z = v && (p ? v.length : v.result.length); + if (l && z) { + x = []; y = 0; - for (let N = 0, O, Wa; N < l.length; N += 2) { - O = this.tag.get(l[N]); - if (!O) { - if (console.warn("Tag '" + l[N] + ":" + l[N + 1] + "' will be skipped because there is no field '" + l[N] + "'."), k) { + for (let H = 0, D, N; H < l.length; H += 2) { + D = this.tag.get(l[H]); + if (!D) { + if (console.warn("Tag '" + l[H] + ":" + l[H + 1] + "' will be skipped because there is no field '" + l[H] + "'."), k) { continue; } else { - return n ? d : new W(d); + return p ? d : new X(d); } } - if (Wa = (O = O && O.get(l[N + 1])) && O.length) { - y++, w.push(O); + if (N = (D = D && D.get(l[H + 1])) && D.length) { + y++, x.push(D); } else if (!k) { - return n ? d : new W(d); + return p ? d : new X(d); } } if (y) { - v = za(v, w); - E = v.length; - if (!E && !k) { - return n ? v : new W(v); + v = Ga(v, x); + z = v.length; + if (!z && !k) { + return p ? v : new X(v); } y--; } } - if (E) { - f[m] = D, d.push(v), m++; + if (z) { + f[m] = B, d.push(v), m++; } else if (1 === h.length) { - return n ? d : new W(d); + return p ? d : new X(d); } } - if (u) { - const A = this; - return Promise.all(u).then(function(v) { - return v.length ? A.search(a, c, b, v) : v; + if (n) { + const E = this; + return Promise.all(n).then(function(v) { + return v.length ? E.search(a, c, b, v) : v; }); } if (!m) { - return n ? d : new W(d); + return p ? d : new X(d); } - if (p && (!g || !this.store)) { + if (q && (!g || !this.store)) { return d[0]; } - u = []; - for (t = 0; t < f.length; t++) { - e = d[t]; - g && e.length && "undefined" === typeof e[0].doc && (e = V.call(this, e)); - if (p) { - return n ? r ? Ja(a, e, this.index, p, r) : e : new W(e); + n = []; + for (w = 0; w < f.length; w++) { + e = d[w]; + g && e.length && "undefined" === typeof e[0].doc && (e = U.call(this, e)); + if (q) { + return p ? r ? Qa(a, e, this.index, q, r) : e : new X(e); } - d[t] = {field:f[t], result:e}; + d[w] = {field:f[w], result:e}; } - return q ? Ka(d) : r ? Ja(a, d, this.index, p, r) : d; + return t ? Sa(d) : r ? Qa(a, d, this.index, q, r) : d; }; -function Ja(a, c, b, e, d) { - let f, g; - for (let h = 0, l, m, n; h < c.length; h++) { - let r; - if (e) { - r = c, n = e; - } else { - var k = c[h]; - n = k.field; - if (!n) { - continue; - } - r = k.result; - } - m = b.get(n); - l = m.encoder; - k = m.tokenize; - l !== f && (f = l, g = f.encode(a)); - for (let p = 0; p < r.length; p++) { - let q = "", t = H(r[p].doc, n).split(/\s+/); - for (let u = 0, w, y; u < t.length; u++) { - w = t[u]; - y = l.encode(w); - y = 1 < y.length ? y.join(" ") : y[0]; - let A; - if (y && w) { - for (let v = 0, D; v < g.length; v++) { - if (D = g[v], "strict" === k) { - if (y === D) { - q += (q ? " " : "") + d.replace("$1", w); - A = !0; - break; - } - } else { - const E = y.indexOf(D); - if (-1 < E) { - q += (q ? " " : "") + w.substring(0, E) + d.replace("$1", w.substring(E, E + D.length)) + w.substring(E + D.length); - A = !0; - break; - } - } - } - } - A || (q += (q ? " " : "") + t[u]); - } - r[p].highlight = q; - } - if (e) { - break; - } - } - return c; -} -function Ka(a) { - const c = [], b = B(); +function Sa(a) { + const c = [], b = J(); for (let e = 0, d, f; e < a.length; e++) { d = a[e]; f = d.result; @@ -1186,7 +1272,7 @@ function Ka(a) { } return c; } -function Ia(a, c, b, e, d) { +function Ra(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1195,11 +1281,11 @@ function Ia(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = V.call(this, f)); + d && (f = U.call(this, f)); return f; } } -function V(a) { +function U(a) { if (!this || !this.store) { return a; } @@ -1209,33 +1295,33 @@ function V(a) { } return c; } -;function U(a) { - if (!this || this.constructor !== U) { - return new U(a); +;function T(a) { + if (!this || this.constructor !== T) { + return new T(a); } const c = a.document || a.doc || a; var b; this.D = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && La(b, this.J) || "id"; + this.key = (b = c.key || c.id) && Ta(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 X(b); + this.cache = (b = a.cache || null) && new Y(b); a.cache = !1; this.priority = a.priority || 4; b = new Map(); let e = c.index || c.field || c; - C(e) && (e = [e]); + K(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], C(f) || (g = f, f = f.field), g = G(g) ? Object.assign({}, a, g) : a, b.set(f, new M(g, this.reg)), g.custom ? this.D[d] = g.custom : (this.D[d] = La(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; + f = e[d], K(f) || (g = f, f = f.field), g = M(g) ? Object.assign({}, a, g) : a, b.set(f, new Z(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.A) { a = c.store; - C(a) && (a = [a]); + K(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] = 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)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = Ta(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; @@ -1251,14 +1337,14 @@ function V(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - 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)); + f.custom ? this.B[d] = f.custom : (this.B[d] = Ta(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 La(a, c) { +function Ta(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1267,15 +1353,15 @@ function La(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -x = U.prototype; -x.append = function(a, c) { +A = T.prototype; +A.append = function(a, c) { return this.add(a, c, !0); }; -x.update = function(a, c) { +A.update = function(a, c) { return this.remove(a).add(a, c); }; -x.remove = function(a) { - G(a) && (a = H(a, this.key)); +A.remove = function(a) { + M(a) && (a = Q(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1295,7 +1381,7 @@ x.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -x.clear = function() { +A.clear = function() { const a = []; for (const c of this.index.values()) { const b = c.clear(); @@ -1310,25 +1396,25 @@ x.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -x.contain = function(a) { +A.contain = function(a) { return this.reg.has(a); }; -x.cleanup = function() { +A.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -x.get = function(a) { +A.get = function(a) { return this.store.get(a) || null; }; -x.set = function(a, c) { - "object" === typeof a && (c = a, a = H(c, this.key)); +A.set = function(a, c) { + "object" === typeof a && (c = a, a = Q(c, this.key)); this.store.set(a, c); return this; }; -x.searchCache = Ma; -x.export = function(a, c, b = 0, e = 0) { +A.searchCache = Ua; +A.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { @@ -1343,25 +1429,25 @@ x.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = ra(this.reg); + f = ya(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && pa(this.tag, this.reg.size); + f = this.tag && ua(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && na(this.store); + f = this.store && sa(this.store); c = null; break; default: return; } - return ta.call(this, a, c, d, f, b, e); + return Aa.call(this, a, c, d, f, b, e); }; -x.import = function(a, c) { +A.import = function(a, c) { var b = a.split("."); "json" === b[b.length - 1] && b.pop(); a = 2 < b.length ? b[0] : ""; @@ -1374,23 +1460,23 @@ x.import = function(a, c) { switch(b) { case "reg": this.fastupdate = !1; - this.reg = sa(c, this.reg); + this.reg = za(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 = qa(c, this.tag); + this.tag = xa(c, this.tag); break; case "doc": - this.store = oa(c, this.store); + this.store = ta(c, this.store); } } }; -ia(U.prototype); -function Ma(a, c, b) { +ka(T.prototype); +function Ua(a, c, b) { const e = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new X()); + this.cache || (this.cache = new Y()); let d = this.cache.get(e); if (!d) { d = this.search(a, c, b); @@ -1405,45 +1491,45 @@ function Ma(a, c, b) { } return d; } -function X(a) { +function Y(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -X.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); }; -X.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; }; -X.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); } }; -X.prototype.clear = function() { +Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Na = {normalize:!1, numeric:!1, dedupe:!1}; -const Oa = {}; -const Pa = 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 Qa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ra = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Sa = {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 Ta = {Exact:Na, Default:Oa, Normalize:Oa, LatinBalance:{mapper:Pa}, LatinAdvanced:{mapper:Pa, matcher:Qa, replacer:Ra}, LatinExtra:{mapper:Pa, replacer:Ra.concat([/(?!^)[aeo]/g, ""]), matcher:Qa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Va = {normalize:!1, numeric:!1, dedupe:!1}; +const Wa = {}; +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"], ["ph", "f"], ["pf", "f"]]), Za = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\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}; +var ab = {Exact:Va, Default:Wa, Normalize:Wa, LatinBalance:{mapper:Xa}, LatinAdvanced:{mapper:Xa, matcher:Ya, replacer:Za}, LatinExtra:{mapper:Xa, replacer:Za.concat([/(?!^)[aeo]/g, ""]), matcher:Ya}, LatinSoundex:{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 = Sa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Sa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = $a[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = $a[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } -}}, CJK:{split:""}, LatinExact:Na, LatinDefault:Oa, LatinSimple:Oa}; -M.prototype.remove = function(a, c) { +}}, CJK:{split:""}, LatinExact:Va, LatinDefault:Wa, LatinSimple:Wa}; +Z.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) { @@ -1458,14 +1544,14 @@ M.prototype.remove = function(a, c) { } } } else { - Y(this.map, a), this.depth && Y(this.ctx, a); + bb(this.map, a), this.depth && bb(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Y(a, c) { +function bb(a, c) { let b = 0; var e = "undefined" === typeof c; if (a.constructor === Array) { @@ -1486,14 +1572,14 @@ function Y(a, c) { } else { for (let d of a.entries()) { e = d[0]; - const f = Y(d[1], c); + const f = bb(d[1], c); f ? b += f : a.delete(e); } } return b; } -;const Ua = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -M.prototype.add = function(a, c, b, e) { +;const cb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +Z.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -1502,21 +1588,21 @@ M.prototype.add = function(a, c, b, e) { c = this.encoder.encode(c, !e); const l = c.length; if (l) { - const m = B(), n = B(), r = this.resolution; - for (let p = 0; p < l; p++) { - let q = c[this.rtl ? l - 1 - p : p]; - var d = q.length; - if (d && (e || !n[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Va(r, l, p), g = ""; + const m = J(), p = J(), r = this.resolution; + for (let q = 0; q < l; q++) { + let t = c[this.rtl ? l - 1 - q : q]; + var d = t.length; + if (d && (e || !p[t])) { + var f = this.score ? this.score(c, t, q, null, 0) : db(r, l, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let t = 0, u; t < d; t++) { - for (f = d; f > t; f--) { - g = q.substring(t, f); - u = this.rtl ? d - 1 - t : t; - var k = this.score ? this.score(c, q, p, g, u) : Va(r, l, p, d, u); - Z(this, n, g, k, a, b); + for (let w = 0, n; w < d; w++) { + for (f = d; f > w; f--) { + g = t.substring(w, f); + n = this.rtl ? d - 1 - w : w; + var k = this.score ? this.score(c, t, q, g, n) : db(r, l, q, d, n); + eb(this, p, g, k, a, b); } } break; @@ -1525,26 +1611,26 @@ M.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (k = d - 1; 0 < k; k--) { - g = q[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, q, p, g, k) : Va(r, l, p, d, k); - Z(this, n, g, h, a, b); + g = t[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, t, q, g, k) : db(r, l, q, d, k); + eb(this, p, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += q[this.rtl ? d - 1 - k : k], Z(this, n, g, f, a, b); + g += t[this.rtl ? d - 1 - k : k], eb(this, p, g, f, a, b); } break; } default: - if (Z(this, n, q, f, a, b), e && 1 < l && p < l - 1) { - for (d = B(), g = this.S, f = q, k = Math.min(e + 1, this.rtl ? p + 1 : l - p), d[f] = 1, h = 1; h < k; h++) { - if ((q = c[this.rtl ? l - 1 - p - h : p + h]) && !d[q]) { - d[q] = 1; - const t = this.score ? this.score(c, f, p, q, h - 1) : Va(g + (l / 2 > g ? 0 : 1), l, p, k - 1, h - 1), u = this.bidirectional && q > f; - Z(this, m, u ? f : q, t, a, b, u ? q : f); + if (eb(this, p, t, f, a, b), e && 1 < l && q < l - 1) { + for (d = J(), g = this.S, f = t, k = Math.min(e + 1, this.rtl ? q + 1 : l - q), d[f] = 1, h = 1; h < k; h++) { + if ((t = c[this.rtl ? l - 1 - q - h : q + h]) && !d[t]) { + d[t] = 1; + const w = this.score ? this.score(c, f, q, t, h - 1) : db(g + (l / 2 > g ? 0 : 1), l, q, k - 1, h - 1), n = this.bidirectional && t > f; + eb(this, m, n ? f : t, w, a, b, n ? t : f); } } } @@ -1556,16 +1642,16 @@ M.prototype.add = function(a, c, b, e) { } return this; }; -function Z(a, c, b, e, d, f, g) { +function eb(a, c, b, e, d, f, g) { let k = g ? a.ctx : a.map, h; if (!c[b] || g && !(h = c[b])[g]) { - g ? (c = h || (c[b] = B()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); + g ? (c = h || (c[b] = J()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); } } -function Va(a, c, b, e, d) { +function db(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; } -;M.prototype.search = function(a, c, b) { +;Z.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); var e = [], d = 0; if (b) { @@ -1584,86 +1670,86 @@ function Va(a, c, b, e, d) { b = a.length; c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Xa(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; + return g = c, (c = fb(this, a[0], "")) && c.length ? Ha.call(this, c, g, d) : []; } if (2 === b && f && !g) { - return g = c, (c = Xa(this, a[1], a[0])) && c.length ? Aa.call(this, c, g, d) : []; + return g = c, (c = fb(this, a[1], a[0])) && c.length ? Ha.call(this, c, g, d) : []; } - k = B(); + k = J(); let l = 0; if (f) { var m = a[0]; l = 1; } h || 0 === h || (h = m ? this.S : this.resolution); - for (let q, t; l < b; l++) { - if ((t = a[l]) && !k[t]) { - k[t] = 1; - q = Xa(this, t, m); + for (let t, w; l < b; l++) { + if ((w = a[l]) && !k[w]) { + k[w] = 1; + t = fb(this, w, m); a: { - f = q; - var n = e, r = g, p = h; - let u = []; + f = t; + var p = e, r = g, q = h; + let n = []; if (f && f.length) { - if (f.length <= p) { - n.push(f); - q = void 0; + if (f.length <= q) { + p.push(f); + t = void 0; break a; } - for (let w = 0, y; w < p; w++) { - if (y = f[w]) { - u[w] = y; + for (let x = 0, y; x < q; x++) { + if (y = f[x]) { + n[x] = y; } } - if (u.length) { - n.push(u); - q = void 0; + if (n.length) { + p.push(n); + t = void 0; break a; } } - q = r ? void 0 : u; + t = r ? void 0 : n; } - if (q) { - e = q; + if (t) { + e = t; break; } - m && (g && q && e.length || (m = t)); + m && (g && t && e.length || (m = w)); } - g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = B()); + g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = J()); } a: { a = e; e = a.length; m = a; if (1 < e) { - m = xa(a, h, c, d, g); + m = Ea(a, h, c, d, g); } else if (1 === e) { - g = Aa.call(null, a[0], c, d); + g = Ha.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Xa(a, c, b) { +function fb(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; } -;function M(a, c) { - if (!this || this.constructor !== M) { - return new M(a); +;function Z(a, c) { + if (!this || this.constructor !== Z) { + return new Z(a); } if (a) { - var b = C(a) ? a : a.preset; - b && (Ua[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ua[b], a)); + var b = K(a) ? a : a.preset; + b && (cb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, cb[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = C(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || {}; - this.encoder = d.encode ? d : "object" === typeof d ? new I(d) : {encode:d}; + const e = !0 === b ? {depth:1} : b || {}, d = K(a.encoder) ? ab[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : "object" === typeof d ? new ja(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; this.depth = "strict" === b && e.depth || 0; @@ -1677,42 +1763,42 @@ function Xa(a, c, b) { 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 X(b); + this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; } -x = M.prototype; -x.clear = function() { +A = Z.prototype; +A.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); this.cache && this.cache.clear(); return this; }; -x.append = function(a, c) { +A.append = function(a, c) { return this.add(a, c, !0); }; -x.contain = function(a) { +A.contain = function(a) { return this.reg.has(a); }; -x.update = function(a, c) { +A.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); }; -x.cleanup = function() { +A.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Y(this.map); - this.depth && Y(this.ctx); + bb(this.map); + this.depth && bb(this.ctx); return this; }; -x.searchCache = Ma; -x.export = function(a, c, b = 0, e = 0) { +A.searchCache = Ua; +A.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = ra(this.reg); + f = ya(this.reg); break; case 1: d = "cfg"; @@ -1720,33 +1806,33 @@ x.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = na(this.map, this.reg.size); + f = sa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = pa(this.ctx, this.reg.size); + f = ua(this.ctx, this.reg.size); break; default: return; } - return ta.call(this, a, c, d, f, b, e); + return Aa.call(this, a, c, d, f, b, e); }; -x.import = function(a, c) { +A.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = sa(c, this.reg); + this.reg = za(c, this.reg); break; case "map": - this.map = oa(c, this.map); + this.map = ta(c, this.map); break; case "ctx": - this.ctx = qa(c, this.ctx); + this.ctx = xa(c, this.ctx); } } }; -x.serialize = function(a = !0) { +A.serialize = function(a = !0) { let c = "", b = "", e = ""; if (this.reg.size) { let f; @@ -1754,11 +1840,11 @@ x.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = ua(this.map, f); + b = Ba(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = ua(g[1], f); + let k = Ba(g[1], f); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; e += (e ? "," : "") + k; @@ -1767,8 +1853,8 @@ x.serialize = function(a = !0) { } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; -ia(M.prototype); -B(); -export default {Index:M, Charset:Ta, Encoder:I, Document:U, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +ka(Z.prototype); +J(); +export default {Index:Z, Charset:ab, Encoder:ja, Document:T, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=M;export const Charset=Ta;export const Encoder=I;export const Document=U;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=Z;export const Charset=ab;export const Encoder=ja;export const Document=T;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 504aa1b..4bf583c 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,64 +1,64 @@ /**! - * FlexSearch.js v0.8.158 (Bundle) + * FlexSearch.js v0.8.160 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var x;function z(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(k){return a(b(k))};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 B(){return Object.create(null)}function C(a){return"string"===typeof a} -function G(a){return"object"===typeof a}function H(a,c){if(C(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ba)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!0,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=z((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,1024,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=b=z(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof b?b:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.C="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.C+= -(this.C?"|":"")+d;return this};x.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.C+=(this.C?"|":"")+a;this.N=null;this.cache&&J(this);return this};x.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&J(this);return this}; -x.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.h+=(this.h?"|":"")+a;this.M=null;this.cache&&J(this);return this}; -x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&J(this);return this}; -x.encode=function(a,c){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(J,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ha?a.normalize("NFKD").replace(ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(c){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(b)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var h=this.G.get(m);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(J,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ -this.C+")$"));let r;for(;r!==m&&2this.stemmer.get(p))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(r)));if(m&&this.replacer)for(h=0;m&&hthis.R&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==n)if(c){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.F.set(a,e),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return e};function J(a){a.H=null;a.F.clear();a.G.clear()};let K,L;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":L=a.options||{};(c=a.factory)?(Function("return "+c)()(self),K=new self.FlexSearch.Index(L),delete self.FlexSearch):K=new N(L);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=L.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await L.import.call(K,e[0]),K.import(e[0],a)):(d=e&&K[c].apply(K,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){O.call(a,"add");O.call(a,"append");O.call(a,"search");O.call(a,"update");O.call(a,"remove")}let ka,la,P;function ma(){ka=P=0} -function O(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]);ka?P||(P=Date.now()-la>=this.priority*this.priority*3):(ka=setTimeout(ma,0),la=Date.now());if(P){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 Q=0; -function R(a={}){function c(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[++Q]=function(){h(d);1E9b||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=B();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?V.call(this,g):g;d.push(g);c-=k;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};W.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:k,offset:h,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; -function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){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?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.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 k=this;return Promise.all(c).then(function(h){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?V.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=B();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(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)}; -X.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};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:!1,numeric:!1,dedupe:!1};const Oa={};const Pa=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 Qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Sa={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 Ta={Exact:Na,Default:Oa,Normalize:Oa,LatinBalance:{mapper:Pa},LatinAdvanced:{mapper:Pa,matcher:Qa,replacer:Ra},LatinExtra:{mapper:Pa,replacer:Ra.concat([/(?!^)[aeo]/g,""]),matcher:Qa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bd.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,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;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,f,g;dt;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Wa(r, -l,p,d,u);Z(this,n,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g? -0:1),l,p,k-1,h-1),u=this.bidirectional&&q>f;Z(this,m,u?f:q,t,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=B()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Wa(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};function N(a,c){if(!this||this.constructor!==N)return new N(a);if(a){var b=C(a)?a:a.preset;b&&(a=Object.assign({},Ua[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=C(a.encoder)?Ta[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new I(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;b=!1;this.map=new Map;this.ctx=new Map;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 X(b);this.priority=a.priority||4}x=N.prototype;x.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};x.append=function(a,c){return this.add(a,c,!0)};x.contain=function(a){return this.reg.has(a)}; -x.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)};x.cleanup=function(){if(!this.fastupdate)return this;Y(this.map);this.depth&&Y(this.ctx);return this};x.searchCache=Ma;x.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=sa(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=oa(this.map,this.reg.size);break;case 3:d="ctx";f=qa(this.ctx,this.reg.size);break;default:return}return T.call(this,a,c,d,f,b,e)}; -x.import=function(a,c){if(c)switch("string"===typeof c&&(c=JSON.parse(c)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1"a1a".split(b).length; +this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,ba)}catch(d){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:H(b&&new Set(b),null,this.filter);this.dedupe=H(a.dedupe,!0,this.dedupe);this.matcher=H((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=H((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=H((b=a.stemmer)&&new Map(b), +null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,1024,this.maxlength);this.rtl=H(a.rtl,!1,this.rtl);if(this.cache=b=H(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof b?b:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.C="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.C+= +(this.C?"|":"")+d;return this};A.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.C+=(this.C?"|":"")+a;this.N=null;this.cache&&R(this);return this};A.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&R(this);return this}; +A.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.h+=(this.h?"|":"")+a;this.M=null;this.cache&&R(this);return this}; +A.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&R(this);return this}; +A.encode=function(a,c){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(R,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ia?a.normalize("NFKD").replace(ia,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(c){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(b)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var h=this.G.get(m);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(R,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ +this.C+")$"));let r;for(;r!==m&&2this.stemmer.get(q))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(r)));if(m&&this.replacer)for(h=0;m&&hthis.R&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==p)if(c){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.F.set(a,e),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return e};function R(a){a.H=null;a.F.clear();a.G.clear()};function ka(a){na.call(a,"add");na.call(a,"append");na.call(a,"search");na.call(a,"update");na.call(a,"remove")}let oa,pa,qa;function ra(){oa=qa=0} +function na(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]);oa?qa||(qa=Date.now()-pa>=this.priority*this.priority*3):(oa=setTimeout(ra,0),pa=Date.now());if(qa){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 sa(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 ta(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 Fa(a,c,b){const e=[],d=I();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?U.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?U.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Fa(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:k,offset:h,enrich:l,resolve:m,suggest:p}=Ia(this,"and",arguments);return Ka.call(this,f,g,k,h,l,m,p)}return d?this.resolve(c,b,e):this}; +function Ka(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=Ea(a,c,b,e,g),f?d?U.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}=Ia(this,"xor",arguments);return La.call(this,a,c,b,e,d,f,g)}; +function La(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Ma.call(this,a,b,e,f,this.h),f?d?U.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Ma(a,c,b,e,d){const f=[],g=I();let k=0;for(let h=0,l;hE&&(E=n.length+(n?1:0)),v=n.length+(n?1:0)+L.length,B+=D,ma.push(y.length),y.push({match:L})),n+=(n?" ":"")+L)}if(!u)C=x[z],n+=(n?" ":"")+C,h&&y.push({text:C});else if(h&&B>=h)break}B=ma.length*(f.length-2);if(q||t||h&&n.length-B>h)if(B=h+B-2*r,z=v-E,0x&&(x=0)),y=y.length-1){if(F>=y.length){z[u+1]= +1;F>=x.length&&(B[u+1]=1);continue}D-=r}n=y[F].text;if(G=t&&K[u])if(0G)if(z[u+1]=1,l)n=n.substring(0,G);else continue;(G-=n.length)||(G=-1);K[u]=G}else{z[u+1]=1;continue}if(D+n.length+1<=h)n=" "+n,v[u]+=n;else if(l)P=h-D-1,0=F){if(0>F){z[u]=1;B[u]=1;continue}D-=r}n=y[F].text;if(G=q&&C[u])if(0G)if(z[u]=1,l)n=n.substring(n.length- +G);else continue;(G-=n.length)||(G=-1);C[u]=G}else{z[u]=1;continue}if(D+n.length+1<=h)n+=" ",v[u]=n+v[u];else if(l)P=n.length+1-(h-D),0<=P&&P=x.length-1?wa=1:Fb||e)a=a.slice(e,e+b);d&&(a=U.call(this,a));return a}} +function U(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 Va={normalize:!1,numeric:!1,dedupe:!1};const Wa={};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"],["ph","f"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\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};var ab={Exact:Va,Default:Wa,Normalize:Wa,LatinBalance:{mapper:Xa},LatinAdvanced:{mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bd.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else bb(this.map,a),this.depth&&bb(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function bb(a,c){let b=0;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,f,g;dw;f--){g=t.substring(w,f);n=this.rtl?d-1-w:w;var k=this.score?this.score(c,t,q,g,n):db(r, +l,q,d,n);eb(this,p,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),l,q,k-1,h-1),n=this.bidirectional&&t>f;eb(this,m,n?f:t,w,a,b,n?t:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function eb(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=I()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))} +function db(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};function Z(a,c){if(!this||this.constructor!==Z)return new Z(a);if(a){var b=J(a)?a:a.preset;b&&(a=Object.assign({},cb[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=J(a.encoder)?ab[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ja(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;b=!1;this.map=new Map;this.ctx=new Map;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 Y(b);this.priority=a.priority||4}A=Z.prototype;A.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};A.append=function(a,c){return this.add(a,c,!0)};A.contain=function(a){return this.reg.has(a)}; +A.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)};A.cleanup=function(){if(!this.fastupdate)return this;bb(this.map);this.depth&&bb(this.ctx);return this};A.searchCache=Ua;A.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=ya(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=sa(this.map,this.reg.size);break;case 3:d="ctx";f=ua(this.ctx,this.reg.size);break;default:return}return Aa.call(this,a,c,d,f,b,e)}; +A.import=function(a,c){if(c)switch("string"===typeof c&&(c=JSON.parse(c)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1>> 0) + "_", e = 0; return b; }); -C("Symbol.iterator", function(a) { +I("Symbol.iterator", function(a) { if (a) { return a; } a = Symbol("Symbol.iterator"); for (var b = "Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "), c = 0; c < b.length; c++) { - var d = B[b[c]]; - "function" === typeof d && "function" != typeof d.prototype[a] && ba(d.prototype, a, {configurable:!0, writable:!0, value:function() { - return ua(aa(this)); + var d = ea[b[c]]; + "function" === typeof d && "function" != typeof d.prototype[a] && ca(d.prototype, a, {configurable:!0, writable:!0, value:function() { + return ya(ba(this)); }}); } return a; }); -function ua(a) { +function ya(a) { a = {next:a}; a[Symbol.iterator] = function() { return this; }; return a; } -C("Promise", function(a) { +I("Promise", function(a) { function b(g) { this.A = 0; this.B = void 0; @@ -281,7 +281,7 @@ C("Promise", function(a) { } this.h.push(g); }; - var e = B.setTimeout; + var e = ea.setTimeout; c.prototype.B = function(g) { e(g, 0); }; @@ -367,7 +367,7 @@ C("Promise", function(a) { var g = this; e(function() { if (g.T()) { - var h = B.console; + var h = ea.console; "undefined" !== typeof h && h.error(g.B); } }, 1); @@ -376,11 +376,11 @@ C("Promise", function(a) { if (this.H) { return !1; } - var g = B.CustomEvent, h = B.Event, k = B.dispatchEvent; + var g = ea.CustomEvent, h = ea.Event, k = ea.dispatchEvent; if ("undefined" === typeof k) { return !0; } - "function" === typeof g ? g = new g("unhandledrejection", {cancelable:!0}) : "function" === typeof h ? g = new h("unhandledrejection", {cancelable:!0}) : (g = B.document.createEvent("CustomEvent"), g.initCustomEvent("unhandledrejection", !1, !0, g)); + "function" === typeof g ? g = new g("unhandledrejection", {cancelable:!0}) : "function" === typeof h ? g = new h("unhandledrejection", {cancelable:!0}) : (g = ea.document.createEvent("CustomEvent"), g.initCustomEvent("unhandledrejection", !1, !0, g)); g.promise = this; g.reason = this.B; return k(g); @@ -407,21 +407,21 @@ C("Promise", function(a) { } }; b.prototype.then = function(g, h) { - function k(p, q) { - return "function" == typeof p ? function(t) { + function k(n, q) { + return "function" == typeof n ? function(r) { try { - l(p(t)); - } catch (v) { - m(v); + l(n(r)); + } catch (w) { + m(w); } } : q; } - var l, m, n = new b(function(p, q) { - l = p; + var l, m, p = new b(function(n, q) { + l = n; m = q; }); this.U(k(g, l), k(h, m)); - return n; + return p; }; b.prototype.catch = function(g) { return this.then(void 0, g); @@ -451,30 +451,30 @@ C("Promise", function(a) { }; b.race = function(g) { return new b(function(h, k) { - for (var l = y(g), m = l.next(); !m.done; m = l.next()) { + for (var l = z(g), m = l.next(); !m.done; m = l.next()) { d(m.value).U(h, k); } }); }; b.all = function(g) { - var h = y(g), k = h.next(); + var h = z(g), k = h.next(); return k.done ? d([]) : new b(function(l, m) { - function n(t) { - return function(v) { - p[t] = v; + function p(r) { + return function(w) { + n[r] = w; q--; - 0 == q && l(p); + 0 == q && l(n); }; } - var p = [], q = 0; + var n = [], q = 0; do { - p.push(void 0), q++, d(k.value).U(n(p.length - 1), m), k = h.next(); + n.push(void 0), q++, d(k.value).U(p(n.length - 1), m), k = h.next(); } while (!k.done); }); }; return b; }); -function va(a, b) { +function za(a, b) { a instanceof String && (a += ""); var c = 0, d = !1, e = {next:function() { if (!d && c < a.length) { @@ -489,28 +489,28 @@ function va(a, b) { }; return e; } -C("Array.prototype.values", function(a) { +I("Array.prototype.values", function(a) { return a ? a : function() { - return va(this, function(b, c) { + return za(this, function(b, c) { return c; }); }; }); -C("Array.prototype.keys", function(a) { +I("Array.prototype.keys", function(a) { return a ? a : function() { - return va(this, function(b) { + return za(this, function(b) { return b; }); }; }); -function F(a, b) { +function Aa(a, b) { return Object.prototype.hasOwnProperty.call(a, b); } -C("WeakMap", function(a) { +I("WeakMap", function(a) { function b(k) { this.h = (h += Math.random() + 1).toString(); if (k) { - k = y(k); + k = z(k); for (var l; !(l = k.next()).done;) { l = l.value, this.set(l[0], l[1]); } @@ -523,9 +523,9 @@ C("WeakMap", function(a) { return "object" === l && null !== k || "function" === l; } function e(k) { - if (!F(k, g)) { + if (!Aa(k, g)) { var l = new c(); - ba(k, g, {value:l}); + ca(k, g, {value:l}); } } function f(k) { @@ -550,7 +550,7 @@ C("WeakMap", function(a) { m.delete(k); m.set(l, 4); return !m.has(k) && 4 == m.get(l); - } catch (n) { + } catch (p) { return !1; } }()) { @@ -566,31 +566,31 @@ C("WeakMap", function(a) { throw Error("Invalid WeakMap key"); } e(k); - if (!F(k, g)) { + if (!Aa(k, g)) { throw Error("WeakMap key fail: " + k); } k[g][this.h] = l; return this; }; b.prototype.get = function(k) { - return d(k) && F(k, g) ? k[g][this.h] : void 0; + return d(k) && Aa(k, g) ? k[g][this.h] : void 0; }; b.prototype.has = function(k) { - return d(k) && F(k, g) && F(k[g], this.h); + return d(k) && Aa(k, g) && Aa(k[g], this.h); }; b.prototype.delete = function(k) { - return d(k) && F(k, g) && F(k[g], this.h) ? delete k[g][this.h] : !1; + return d(k) && Aa(k, g) && Aa(k[g], this.h) ? delete k[g][this.h] : !1; }; return b; }); -C("Map", function(a) { +I("Map", function(a) { function b() { var h = {}; return h.J = h.next = h.head = h; } function c(h, k) { var l = h[1]; - return ua(function() { + return ya(function() { if (l) { for (; l.head != h[1];) { l = l.J; @@ -607,11 +607,11 @@ C("Map", function(a) { var l = k && typeof k; "object" == l || "function" == l ? f.has(k) ? l = f.get(k) : (l = "" + ++g, f.set(k, l)) : l = "p_" + k; var m = h[0][l]; - if (m && F(h[0], l)) { + if (m && Aa(h[0], l)) { for (h = 0; h < m.length; h++) { - var n = m[h]; - if (k !== k && n.key !== n.key || k === n.key) { - return {id:l, list:m, index:h, F:n}; + var p = m[h]; + if (k !== k && p.key !== p.key || k === p.key) { + return {id:l, list:m, index:h, F:p}; } } } @@ -622,7 +622,7 @@ C("Map", function(a) { this[1] = b(); this.size = 0; if (h) { - h = y(h); + h = z(h); for (var k; !(k = h.next()).done;) { k = k.value, this.set(k[0], k[1]); } @@ -633,7 +633,7 @@ C("Map", function(a) { return !1; } try { - var h = Object.seal({x:4}), k = new a(y([[h, "s"]])); + var h = Object.seal({x:4}), k = new a(z([[h, "s"]])); if ("s" != k.get(h) || 1 != k.size || k.get({x:4}) || k.set({x:4}, "t") != k || 2 != k.size) { return !1; } @@ -643,7 +643,7 @@ C("Map", function(a) { } m = l.next(); return m.done || 4 != m.value[0].x || "t" != m.value[1] || !l.next().done ? !1 : !0; - } catch (n) { + } catch (p) { return !1; } }()) { @@ -696,11 +696,11 @@ C("Map", function(a) { var g = 0; return e; }); -C("Set", function(a) { +I("Set", function(a) { function b(c) { this.h = new Map(); if (c) { - c = y(c); + c = z(c); for (var d; !(d = c.next()).done;) { this.add(d.value); } @@ -712,7 +712,7 @@ C("Set", function(a) { return !1; } try { - var c = Object.seal({x:4}), d = new a(y([c])); + var c = Object.seal({x:4}), d = new a(z([c])); if (!d.has(c) || 1 != d.size || d.add(c) != d || 1 != d.size || d.add({x:4}) != d || 2 != d.size) { return !1; } @@ -762,19 +762,19 @@ C("Set", function(a) { }; return b; }); -C("Array.prototype.entries", function(a) { +I("Array.prototype.entries", function(a) { return a ? a : function() { - return va(this, function(b, c) { + return za(this, function(b, c) { return [b, c]; }); }; }); -C("Object.is", function(a) { +I("Object.is", function(a) { return a ? a : function(b, c) { return b === c ? 0 !== b || 1 / b === 1 / c : b !== b && c !== c; }; }); -C("Array.prototype.includes", function(a) { +I("Array.prototype.includes", function(a) { return a ? a : function(b, c) { var d = this; d instanceof String && (d = String(d)); @@ -789,7 +789,7 @@ C("Array.prototype.includes", function(a) { return !1; }; }); -C("String.prototype.includes", function(a) { +I("String.prototype.includes", function(a) { return a ? a : function(b, c) { if (null == this) { throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined"); @@ -800,7 +800,7 @@ C("String.prototype.includes", function(a) { return -1 !== this.indexOf(b, c || 0); }; }); -C("Array.prototype.flat", function(a) { +I("Array.prototype.flat", function(a) { return a ? a : function(b) { b = void 0 === b ? 1 : b; var c = []; @@ -810,21 +810,21 @@ C("Array.prototype.flat", function(a) { return c; }; }); -var wa = "function" == typeof Object.assign ? Object.assign : function(a, b) { +var Ba = "function" == typeof Object.assign ? Object.assign : function(a, b) { for (var c = 1; c < arguments.length; c++) { var d = arguments[c]; if (d) { for (var e in d) { - F(d, e) && (a[e] = d[e]); + Aa(d, e) && (a[e] = d[e]); } } } return a; }; -C("Object.assign", function(a) { - return a || wa; +I("Object.assign", function(a) { + return a || Ba; }); -C("Promise.prototype.finally", function(a) { +I("Promise.prototype.finally", function(a) { return a ? a : function(b) { return this.then(function(c) { return Promise.resolve(b()).then(function() { @@ -837,7 +837,7 @@ C("Promise.prototype.finally", function(a) { }); }; }); -function G(a, b, c) { +function O(a, b, c) { var d = typeof c, e = typeof a; if ("undefined" !== d) { if ("undefined" !== e) { @@ -854,7 +854,7 @@ function G(a, b, c) { } if (b === Map) { b = new Map(c); - d = y(a); + d = z(a); for (e = d.next(); !e.done; e = d.next()) { e = e.value, b.set(e[0], e[1]); } @@ -862,7 +862,7 @@ function G(a, b, c) { } if (b === Set) { b = new Set(c); - d = y(a.values()); + d = z(a.values()); for (e = d.next(); !e.done; e = d.next()) { b.add(e.value); } @@ -876,25 +876,25 @@ function G(a, b, c) { } return "undefined" === e ? b : a; } -function I() { +function Q() { return Object.create(null); } -function J(a) { +function R(a) { return "string" === typeof a; } -function xa(a) { +function Ca(a) { return "object" === typeof a; } -function ya(a) { +function Da(a) { var b = []; - a = y(a.keys()); + a = z(a.keys()); for (var c = a.next(); !c.done; c = a.next()) { b.push(c.value); } return b; } -function za(a, b) { - if (J(b)) { +function Ea(a, b) { + if (R(b)) { a = a[b]; } else { for (var c = 0; a && c < b.length; c++) { @@ -903,27 +903,27 @@ function za(a, b) { } return a; } -function Aa(a) { +function Fa(a) { for (var b = 0, c = 0, d = void 0; c < a.length; c++) { (d = a[c]) && b < d.length && (b = d.length); } return b; } -;var Ba = /[^\p{L}\p{N}]+/u, Ca = /(\d{3})/g, Da = /(\D)(\d{3})/g, Ea = /(\d{3})(\D)/g, Fa = /[\u0300-\u036f]/g; -function Ga(a) { +;var Ga = /[^\p{L}\p{N}]+/u, Ha = /(\d{3})/g, Ia = /(\D)(\d{3})/g, Ja = /(\d{3})(\D)/g, Ka = /[\u0300-\u036f]/g; +function La(a) { a = void 0 === a ? {} : a; - if (!this || this.constructor !== Ga) { + if (!this || this.constructor !== La) { var b = Function.prototype.bind, c = b.apply, d = [null], e = d.concat; if (arguments instanceof Array) { var f = arguments; } else { - f = y(arguments); + f = z(arguments); for (var g, h = []; !(g = f.next()).done;) { h.push(g.value); } f = h; } - return new (c.call(b, Ga, e.call(d, f)))(); + return new (c.call(b, La, e.call(d, f)))(); } if (arguments.length) { for (b = 0; b < arguments.length; b++) { @@ -933,9 +933,9 @@ function Ga(a) { this.assign(a); } } -u = Ga.prototype; -u.assign = function(a) { - this.normalize = G(a.normalize, !0, this.normalize); +v = La.prototype; +v.assign = function(a) { + this.normalize = O(a.normalize, !0, this.normalize); var b = a.include, c = b || a.exclude || a.split; if (c || "" === c) { if ("object" === typeof c && c.constructor !== RegExp) { @@ -958,28 +958,28 @@ u.assign = function(a) { } else { this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } - this.numeric = G(a.numeric, e); + this.numeric = O(a.numeric, e); } else { try { - this.split = G(this.split, Ba); + this.split = O(this.split, Ga); } catch (f) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = G(a.numeric, G(this.numeric, !0)); + this.numeric = O(a.numeric, O(this.numeric, !0)); } - this.prepare = G(a.prepare, null, this.prepare); - this.finalize = G(a.finalize, null, this.finalize); + this.prepare = O(a.prepare, null, this.prepare); + this.finalize = O(a.finalize, null, this.finalize); c = a.filter; - this.filter = "function" === typeof c ? c : G(c && new Set(c), null, this.filter); - this.dedupe = G(a.dedupe, !0, this.dedupe); - this.matcher = G((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = G((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = G((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = G(a.replacer, null, this.replacer); - this.minlength = G(a.minlength, 1, this.minlength); - this.maxlength = G(a.maxlength, 1024, this.maxlength); - this.rtl = G(a.rtl, !1, this.rtl); - if (this.cache = c = G(a.cache, !0, this.cache)) { + this.filter = "function" === typeof c ? c : O(c && new Set(c), null, this.filter); + this.dedupe = O(a.dedupe, !0, this.dedupe); + this.matcher = O((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = O((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = O((c = a.stemmer) && new Map(c), null, this.stemmer); + this.replacer = O(a.replacer, null, this.replacer); + this.minlength = O(a.minlength, 1, this.minlength); + this.maxlength = O(a.maxlength, 1024, this.maxlength); + this.rtl = O(a.rtl, !1, this.rtl); + if (this.cache = c = O(a.cache, !0, this.cache)) { this.D = null, this.T = "number" === typeof c ? c : 2e5, this.B = new Map(), this.C = new Map(), this.H = this.G = 128; } this.h = ""; @@ -987,31 +987,31 @@ u.assign = function(a) { this.A = ""; this.N = null; if (this.matcher) { - for (a = y(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { + for (a = z(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { this.h += (this.h ? "|" : "") + b.value; } } if (this.stemmer) { - for (a = y(this.stemmer.keys()), b = a.next(); !b.done; b = a.next()) { + for (a = z(this.stemmer.keys()), b = a.next(); !b.done; b = a.next()) { this.A += (this.A ? "|" : "") + b.value; } } return this; }; -u.addStemmer = function(a, b) { +v.addStemmer = function(a, b) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, b); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && K(this); + this.cache && Ma(this); return this; }; -u.addFilter = function(a) { +v.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && K(this); + this.cache && Ma(this); return this; }; -u.addMapper = function(a, b) { +v.addMapper = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -1020,10 +1020,10 @@ u.addMapper = function(a, b) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, b); - this.cache && K(this); + this.cache && Ma(this); return this; }; -u.addMatcher = function(a, b) { +v.addMatcher = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -1034,19 +1034,19 @@ u.addMatcher = function(a, b) { this.matcher.set(a, b); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && K(this); + this.cache && Ma(this); return this; }; -u.addReplacer = function(a, b) { +v.addReplacer = function(a, b) { if ("string" === typeof a) { return this.addMatcher(a, b); } this.replacer || (this.replacer = []); this.replacer.push(a, b); - this.cache && K(this); + this.cache && Ma(this); return this; }; -u.encode = function(a, b) { +v.encode = function(a, b) { var c = this; if (this.cache && a.length <= this.G) { if (this.D) { @@ -1054,14 +1054,14 @@ u.encode = function(a, b) { return this.B.get(a); } } else { - this.D = setTimeout(K, 50, this); + this.D = setTimeout(Ma, 50, this); } } - this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = Fa ? a.normalize("NFKD").replace(Fa, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = Ka ? a.normalize("NFKD").replace(Ka, "").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 d = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), e = [], f = I(), g, h, k = this.split || "" === this.split ? a.split(this.split) : [a], l = 0, m = void 0, n = void 0; l < k.length; l++) { - if ((m = n = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { + this.numeric && 3 < a.length && (a = a.replace(Ia, "$1 $2").replace(Ja, "$1 $2").replace(Ha, "$1 ")); + for (var d = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), e = [], f = Q(), g, h, k = this.split || "" === this.split ? a.split(this.split) : [a], l = 0, m = void 0, p = void 0; l < k.length; l++) { + if ((m = p = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (b) { if (f[m]) { continue; @@ -1079,40 +1079,40 @@ u.encode = function(a, b) { if (!this.filter || ("function" === typeof this.filter ? this.filter(m) : !this.filter.has(m))) { if (this.cache && m.length <= this.H) { if (this.D) { - var p = this.C.get(m); - if (p || "" === p) { - p && e.push(p); + var n = this.C.get(m); + if (n || "" === n) { + n && e.push(n); continue; } } else { - this.D = setTimeout(K, 50, this); + this.D = setTimeout(Ma, 50, this); } } if (this.stemmer) { - for (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), p = void 0; p !== m && 2 < m.length;) { - p = m, m = m.replace(this.N, function(z) { - return c.stemmer.get(z); + for (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), n = void 0; n !== m && 2 < m.length;) { + n = m, m = m.replace(this.N, function(B) { + return c.stemmer.get(B); }); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { - p = ""; - for (var q = 0, t = "", v = void 0, r = void 0; q < m.length; q++) { - v = m.charAt(q), v === t && this.dedupe || ((r = this.mapper && this.mapper.get(v)) || "" === r ? r === t && this.dedupe || !(t = r) || (p += r) : p += t = v); + n = ""; + for (var q = 0, r = "", w = void 0, u = void 0; q < m.length; q++) { + w = m.charAt(q), w === r && this.dedupe || ((u = this.mapper && this.mapper.get(w)) || "" === u ? u === r && this.dedupe || !(r = u) || (n += u) : n += r = w); } - m = p; + m = n; } - this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, function(z) { - return c.matcher.get(z); + this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, function(B) { + return c.matcher.get(B); })); if (m && this.replacer) { - for (p = 0; m && p < this.replacer.length; p += 2) { - m = m.replace(this.replacer[p], this.replacer[p + 1]); + for (n = 0; m && n < this.replacer.length; n += 2) { + m = m.replace(this.replacer[n], this.replacer[n + 1]); } } - this.cache && n.length <= this.H && (this.C.set(n, m), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); + this.cache && p.length <= this.H && (this.C.set(p, m), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); if (m) { - if (m !== n) { + if (m !== p) { if (b) { if (f[m]) { continue; @@ -1135,15 +1135,15 @@ u.encode = function(a, b) { this.cache && a.length <= this.G && (this.B.set(a, e), this.B.size > this.T && (this.B.clear(), this.G = this.G / 1.1 | 0)); return e; }; -function K(a) { +function Ma(a) { a.D = null; a.B.clear(); a.C.clear(); } -;var Ha, M; -function Ia(a) { +;var Na, Oa; +function Pa(a) { var b, c, d, e, f, g; - return ta(function(h) { + return xa(function(h) { switch(h.h) { case 1: a = a.data; @@ -1152,8 +1152,8 @@ function Ia(a) { d = a.args; switch(b) { case "init": - M = a.options || {}; - (e = a.factory) ? (Function("return " + e)()(self), Ha = new self.FlexSearch.Index(M), delete self.FlexSearch) : Ha = new O(M); + Oa = a.options || {}; + (e = a.factory) ? (Function("return " + e)()(self), Na = new self.FlexSearch.Index(Oa), delete self.FlexSearch) : Na = new U(Oa); postMessage({id:c}); break; default: @@ -1163,58 +1163,58 @@ function Ia(a) { break; case 2: if ("export" === b) { - if (!M.export || "function" !== typeof M.export) { + if (!Oa.export || "function" !== typeof Oa.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - d[1] ? (d[0] = M.export, d[2] = 0, d[3] = 1) : d = null; + d[1] ? (d[0] = Oa.export, d[2] = 0, d[3] = 1) : d = null; } if ("import" === b) { - if (!M.import || "function" !== typeof M.import) { + if (!Oa.import || "function" !== typeof Oa.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } if (!d[0]) { h.h = 5; break; } - return E(h, M.import.call(Ha, d[0]), 9); + return L(h, Oa.import.call(Na, d[0]), 9); } - f = d && Ha[b].apply(Ha, d); + f = d && Na[b].apply(Na, d); if (!f || !f.then) { h.h = 5; break; } - return E(h, f, 7); + return L(h, f, 7); case 7: f = h.D; h.h = 5; break; case 9: - g = h.D, Ha.import(d[0], g); + g = h.D, Na.import(d[0], g); case 5: postMessage("search" === b ? {id:c, msg:f} : {id:c}), h.h = 0; } }); } -;function Ja(a) { - Ka.call(a, "add"); - Ka.call(a, "append"); - Ka.call(a, "search"); - Ka.call(a, "update"); - Ka.call(a, "remove"); +;function Qa(a) { + Ra.call(a, "add"); + Ra.call(a, "append"); + Ra.call(a, "search"); + Ra.call(a, "update"); + Ra.call(a, "remove"); } -var La, Na, Oa; -function Pa() { - La = Oa = 0; +var Sa, Ta, Ua; +function Va() { + Sa = Ua = 0; } -function Ka(a) { +function Ra(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]; } - La ? Oa || (Oa = Date.now() - Na >= this.priority * this.priority * 3) : (La = setTimeout(Pa, 0), Na = Date.now()); - if (Oa) { + Sa ? Ua || (Ua = Date.now() - Ta >= this.priority * this.priority * 3) : (Sa = setTimeout(Va, 0), Ta = Date.now()); + if (Ua) { var e = this; return new Promise(function(g) { setTimeout(function() { @@ -1230,8 +1230,8 @@ function Ka(a) { return c; }; } -;var Qa = 0; -function Ra(a) { +;var Wa = 0; +function Xa(a) { function b(g) { function h(k) { k = k.data || k; @@ -1239,16 +1239,16 @@ function Ra(a) { m && (m(k.msg), delete e.h[l]); } this.worker = g; - this.h = I(); + this.h = Q(); if (this.worker) { d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { return new Promise(function(k) { - e.h[++Qa] = function() { + e.h[++Wa] = function() { k(e); - 1e9 < Qa && (Qa = 0); + 1e9 < Wa && (Wa = 0); }; - e.worker.postMessage({id:Qa, task:"init", factory:c, options:a}); + e.worker.postMessage({id:Wa, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); @@ -1257,27 +1257,27 @@ function Ra(a) { } } a = void 0 === a ? {} : a; - if (!this || this.constructor !== Ra) { - return new Ra(a); + if (!this || this.constructor !== Xa) { + return new Xa(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 = Sa(c, d, a.worker); + var d = "undefined" === typeof window, e = this, f = Ya(c, d, a.worker); return f.then ? f.then(function(g) { return b.call(e, g); }) : b.call(this, f); } -P("add"); -P("append"); -P("search"); -P("update"); -P("remove"); -P("clear"); -P("export"); -P("import"); -Ja(Ra.prototype); -function P(a) { - Ra.prototype[a] = function() { +Za("add"); +Za("append"); +Za("search"); +Za("update"); +Za("remove"); +Za("clear"); +Za("export"); +Za("import"); +Qa(Xa.prototype); +function Za(a) { + Xa.prototype[a] = function() { var b = this, c = [].slice.call(arguments), d = c[c.length - 1]; if ("function" === typeof d) { var e = d; @@ -1285,69 +1285,69 @@ function P(a) { } d = new Promise(function(f) { "export" === a && "function" === typeof c[0] && (c[0] = null); - b.h[++Qa] = f; - b.worker.postMessage({task:a, id:Qa, args:c}); + b.h[++Wa] = f; + b.worker.postMessage({task:a, id:Wa, args:c}); }); return e ? (d.then(e), this) : d; }; } -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=" + Ia.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ya(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=" + Pa.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof 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) { +;function $a(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 5000 | 0); - a = y(a.entries()); + a = z(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 Ua(a, b) { +function ab(a, b) { b || (b = new Map()); for (var c = 0, d; c < a.length; c++) { d = a[c], b.set(d[0], d[1]); } return b; } -function Va(a, b) { +function bb(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 1000 | 0); - a = y(a.entries()); + a = z(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { - e = e.value, d.push([e[0], Ta(e[1])[0]]), d.length === b && (c.push(d), d = []); + e = e.value, d.push([e[0], $a(e[1])[0]]), d.length === b && (c.push(d), d = []); } d.length && c.push(d); return c; } -function Wa(a, b) { +function cb(a, b) { b || (b = new Map()); for (var c = 0, d, e; c < a.length; c++) { - d = a[c], e = b.get(d[0]), b.set(d[0], Ua(d[1], e)); + d = a[c], e = b.get(d[0]), b.set(d[0], ab(d[1], e)); } return b; } -function Xa(a) { +function db(a) { var b = [], c = []; - a = y(a.keys()); + a = z(a.keys()); for (var d = a.next(); !d.done; d = a.next()) { c.push(d.value), 250000 === c.length && (b.push(c), c = []); } c.length && b.push(c); return b; } -function Ya(a, b) { +function eb(a, b) { b || (b = new Set()); for (var c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function Za(a, b, c, d, e, f, g) { +function fb(a, b, c, d, e, f, g) { g = void 0 === g ? 0 : g; var h = d && d.constructor === Array, k = h ? d.shift() : d; if (!k) { @@ -1356,14 +1356,14 @@ function Za(a, b, c, d, e, f, g) { if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { var l = this; return k.then(function() { - return Za.call(l, a, b, c, h ? d : null, e, f, g + 1); + return fb.call(l, a, b, c, h ? d : null, e, f, g + 1); }); } - return Za.call(this, a, b, c, h ? d : null, e, f, g + 1); + return fb.call(this, a, b, c, h ? d : null, e, f, g + 1); } -function $a(a, b) { +function gb(a, b) { var c = ""; - a = y(a.entries()); + a = z(a.entries()); for (var d = a.next(); !d.done; d = a.next()) { var e = d.value; d = e[0]; @@ -1381,7 +1381,7 @@ function $a(a, b) { } return c; } -;function ab(a, b, c, d) { +;function hb(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; @@ -1397,9 +1397,9 @@ function $a(a, b) { } return e; } -function S(a) { - if (!this || this.constructor !== S) { - return new S(a); +function ib(a) { + if (!this || this.constructor !== ib) { + return new ib(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -1446,12 +1446,12 @@ function S(a) { } if ("slice" === d) { return function(e, f) { - return ab(b, e || 0, f || b.length, !1); + return hb(b, e || 0, f || b.length, !1); }; } if ("splice" === d) { return function(e, f) { - return ab(b, e || 0, f || b.length, !0); + return hb(b, e || 0, f || b.length, !0); }; } if ("constructor" === d) { @@ -1467,63 +1467,63 @@ function S(a) { return !0; }}); } -S.prototype.clear = function() { +ib.prototype.clear = function() { this.index.length = 0; }; -S.prototype.destroy = function() { +ib.prototype.destroy = function() { this.proxy = this.index = null; }; -S.prototype.push = function() { +ib.prototype.push = function() { }; -function T(a) { +function V(a) { a = void 0 === a ? 8 : a; - if (!this || this.constructor !== T) { - return new T(a); + if (!this || this.constructor !== V) { + return new V(a); } - this.index = I(); + this.index = Q(); this.h = []; this.size = 0; - 32 < a ? (this.A = bb, this.B = BigInt(a)) : (this.A = cb, this.B = a); + 32 < a ? (this.A = jb, this.B = BigInt(a)) : (this.A = kb, this.B = a); } -T.prototype.get = function(a) { +V.prototype.get = function(a) { var b = this.A(a); return (b = this.index[b]) && b.get(a); }; -T.prototype.set = function(a, b) { +V.prototype.set = function(a, b) { var c = this.A(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.h.push(d), this.size++); }; -function U(a) { +function W(a) { a = void 0 === a ? 8 : a; - if (!this || this.constructor !== U) { - return new U(a); + if (!this || this.constructor !== W) { + return new W(a); } - this.index = I(); + this.index = Q(); this.h = []; this.size = 0; - 32 < a ? (this.A = bb, this.B = BigInt(a)) : (this.A = cb, this.B = a); + 32 < a ? (this.A = jb, this.B = BigInt(a)) : (this.A = kb, this.B = a); } -U.prototype.add = function(a) { +W.prototype.add = function(a) { var b = this.A(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), this.size++); }; -u = T.prototype; -u.has = U.prototype.has = function(a) { +v = V.prototype; +v.has = W.prototype.has = function(a) { var b = this.A(a); return (b = this.index[b]) && b.has(a); }; -u.delete = U.prototype.delete = function(a) { +v.delete = W.prototype.delete = function(a) { var b = this.A(a); (b = this.index[b]) && b.delete(a) && this.size--; }; -u.clear = U.prototype.clear = function() { - this.index = I(); +v.clear = W.prototype.clear = function() { + this.index = Q(); this.h = []; this.size = 0; }; -u.values = U.prototype.values = function db() { +v.values = W.prototype.values = function lb() { var b, c = this, d, e, f; - return ra(db, function(g) { + return va(lb, function(g) { switch(g.h) { case 1: b = 0; @@ -1532,7 +1532,7 @@ u.values = U.prototype.values = function db() { g.h = 0; break; } - d = y(c.h[b].values()); + d = z(c.h[b].values()); e = d.next(); case 5: if (e.done) { @@ -1541,15 +1541,15 @@ u.values = U.prototype.values = function db() { break; } f = e.value; - return E(g, f, 6); + return L(g, f, 6); case 6: e = d.next(), g.h = 5; } }); }; -u.keys = U.prototype.keys = function eb() { +v.keys = W.prototype.keys = function mb() { var b, c = this, d, e, f; - return ra(eb, function(g) { + return va(mb, function(g) { switch(g.h) { case 1: b = 0; @@ -1558,7 +1558,7 @@ u.keys = U.prototype.keys = function eb() { g.h = 0; break; } - d = y(c.h[b].keys()); + d = z(c.h[b].keys()); e = d.next(); case 5: if (e.done) { @@ -1567,15 +1567,15 @@ u.keys = U.prototype.keys = function eb() { break; } f = e.value; - return E(g, f, 6); + return L(g, f, 6); case 6: e = d.next(), g.h = 5; } }); }; -u.entries = U.prototype.entries = function fb() { +v.entries = W.prototype.entries = function nb() { var b, c = this, d, e, f; - return ra(fb, function(g) { + return va(nb, function(g) { switch(g.h) { case 1: b = 0; @@ -1584,7 +1584,7 @@ u.entries = U.prototype.entries = function fb() { g.h = 0; break; } - d = y(c.h[b].entries()); + d = z(c.h[b].entries()); e = d.next(); case 5: if (e.done) { @@ -1593,13 +1593,13 @@ u.entries = U.prototype.entries = function fb() { break; } f = e.value; - return E(g, f, 6); + return L(g, f, 6); case 6: e = d.next(), g.h = 5; } }); }; -function cb(a) { +function kb(a) { var b = Math.pow(2, this.B) - 1; if ("number" == typeof a) { return a & b; @@ -1609,11 +1609,11 @@ function cb(a) { } return 32 === this.B ? c + Math.pow(2, 31) : c; } -function bb() { +function jb() { throw Error("The keystore is limited to 32 for EcmaScript5"); } -;V.prototype.add = function(a, b, c) { - xa(a) && (b = a, a = za(b, this.key)); +;ob.prototype.add = function(a, b, c) { + Ca(a) && (b = a, a = Ea(b, this.key)); if (b && (a || 0 === a)) { if (!c && this.reg.has(a)) { return this.update(a, b); @@ -1626,7 +1626,7 @@ function bb() { } else { var g = e.R; if (!g || g(b)) { - e.constructor === String ? e = ["" + e] : J(e) && (e = [e]), gb(b, e, this.S, 0, f, a, e[0], c); + e.constructor === String ? e = ["" + e] : R(e) && (e = [e]), pb(b, e, this.S, 0, f, a, e[0], c); } } } @@ -1635,7 +1635,7 @@ function bb() { g = this.K[d]; var h = this.aa[d]; f = this.tag.get(h); - e = I(); + e = Q(); if ("function" === typeof g) { if (g = g(b), !g) { continue; @@ -1646,10 +1646,10 @@ function bb() { continue; } g.constructor === String && (g = "" + g); - g = za(b, g); + g = Ea(b, g); } if (f && g) { - for (J(g) && (g = [g]), h = 0, k = void 0; h < g.length; h++) { + for (R(g) && (g = [g]), h = 0, k = void 0; h < g.length; h++) { var l = g[h]; if (!e[l]) { e[l] = 1; @@ -1657,10 +1657,10 @@ function bb() { (m = f.get(l)) ? k = m : f.set(l, k = []); if (!c || !k.includes(a)) { if (k.length === Math.pow(2, 31) - 1) { - m = new S(k); + m = new ib(k); if (this.fastupdate) { - for (var n = y(this.reg.values()), p = n.next(); !p.done; p = n.next()) { - p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); + for (var p = z(this.reg.values()), n = p.next(); !n.done; n = p.next()) { + n = n.value, n.includes(k) && (n[n.indexOf(k)] = m); } } f.set(l, k = m); @@ -1677,7 +1677,7 @@ function bb() { } if (this.store && (!c || !this.store.has(a))) { if (this.I) { - var q = I(); + var q = Q(); for (c = 0; c < this.I.length; c++) { if (d = this.I[c], f = d.R, !f || f(b)) { f = void 0; @@ -1687,11 +1687,11 @@ function bb() { continue; } d = [d.ja]; - } else if (J(d) || d.constructor === String) { + } else if (R(d) || d.constructor === String) { q[d] = b[d]; continue; } - hb(b, q, d, 0, d[0], f); + qb(b, q, d, 0, d[0], f); } } } @@ -1701,21 +1701,21 @@ function bb() { } return this; }; -function hb(a, b, c, d, e, f) { +function qb(a, b, c, d, e, f) { a = a[e]; if (d === c.length - 1) { b[e] = f || 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); + qb(a, b, c, d, e); } } else { - b = b[e] || (b[e] = I()), e = c[++d], hb(a, b, c, d, e); + b = b[e] || (b[e] = Q()), e = c[++d], qb(a, b, c, d, e); } } } -function gb(a, b, c, d, e, f, g, h) { +function pb(a, b, c, d, e, f, g, h) { if (a = a[g]) { if (d === b.length - 1) { if (a.constructor === Array) { @@ -1731,33 +1731,33 @@ function gb(a, b, c, d, e, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - gb(a, b, c, d, e, f, g, h); + pb(a, b, c, d, e, f, g, h); } } else { - g = b[++d], gb(a, b, c, d, e, f, g, h); + g = b[++d], pb(a, b, c, d, e, f, g, h); } } } else { e.db && e.remove(f); } } -;function ib(a, b, c, d, e, f, g) { +;function rb(a, b, c, d, e, f, g) { var h = a.length, k = []; - var l = I(); - for (var m = 0, n = void 0, p, q; m < b; m++) { - for (var t = 0; t < h; t++) { - var v = a[t]; - if (m < v.length && (n = v[m])) { - for (var r = 0; r < n.length; r++) { - p = n[r]; - (v = l[p]) ? l[p]++ : (v = 0, l[p] = 1); - q = k[v] || (k[v] = []); + var l = Q(); + for (var m = 0, p = void 0, n, q; m < b; m++) { + for (var r = 0; r < h; r++) { + var w = a[r]; + if (m < w.length && (p = w[m])) { + for (var u = 0; u < p.length; u++) { + n = p[u]; + (w = l[n]) ? l[n]++ : (w = 0, l[n] = 1); + q = k[w] || (k[w] = []); if (!g) { - var z = m + (t || !e ? 0 : f || 0); - q = q[z] || (q[z] = []); + var B = m + (r || !e ? 0 : f || 0); + q = q[B] || (q[B] = []); } - q.push(p); - if (g && c && v === h - 1 && q.length - d === c) { + q.push(n); + if (g && c && w === h - 1 && q.length - d === c) { return d ? q.slice(d) : q; } } @@ -1766,7 +1766,7 @@ 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 ? sb(k, c, d, g, f) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { if (a < h) { return []; @@ -1799,8 +1799,8 @@ function gb(a, b, c, d, e, f, g, h) { } return k; } -function jb(a, b, c, d, e) { - var f = [], g = I(), h = a.length, k; +function sb(a, b, c, d, e) { + var f = [], g = Q(), h = a.length, k; if (d) { for (e = h - 1; 0 <= e; e--) { if (k = (d = a[e]) && d.length) { @@ -1819,18 +1819,18 @@ function jb(a, b, c, d, e) { } } } else { - for (var m = h - 1, n, p = 0; 0 <= m; m--) { - n = a[m]; - 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]) { + for (var m = h - 1, p, n = 0; 0 <= m; m--) { + p = a[m]; + for (var q = 0; q < p.length; q++) { + if (k = (d = p[q]) && d.length) { + for (var r = 0; r < k; r++) { + if (l = d[r], !g[l]) { if (g[l] = 1, c) { c--; } else { - var v = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; - (f[v] || (f[v] = [])).push(l); - if (++p === b) { + var w = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; + (f[w] || (f[w] = [])).push(l); + if (++n === b) { return f; } } @@ -1842,8 +1842,8 @@ function jb(a, b, c, d, e) { } return f; } -function kb(a, b, c) { - for (var d = I(), e = [], f = 0, g; f < b.length; f++) { +function tb(a, b, c) { + for (var d = Q(), e = [], f = 0, g; f < b.length; f++) { g = b[f]; for (var h = 0; h < g.length; h++) { d[g[h]] = 1; @@ -1862,12 +1862,12 @@ function kb(a, b, c) { } return e; } -;function lb(a, b, c, d) { +;function ub(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 ? vb.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)) { @@ -1880,7 +1880,7 @@ function kb(a, b, c) { } h > b && (g = g.slice(0, b), h = b); if (!e.length && h >= b) { - return d ? W.call(this, g) : g; + return d ? vb.call(this, g) : g; } e.push(g); b -= h; @@ -1890,9 +1890,9 @@ function kb(a, b, c) { } } e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? W.call(this, e) : e; + return d ? vb.call(this, e) : e; } -;function mb(a, b, c) { +;function wb(a, b, c) { var d = c[0]; if (d.then) { return Promise.all(c).then(function(q) { @@ -1903,32 +1903,32 @@ 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++) { - if (n = c[m]) { - var p = void 0; - if (n.constructor === X) { - p = n.result; - } else if (n.constructor === Array) { - p = n; + for (var e = [], f = 0, g = 0, h, k, l, m = 0, p = void 0; m < c.length; m++) { + if (p = c[m]) { + var n = void 0; + if (p.constructor === X) { + n = p.result; + } else if (p.constructor === Array) { + n = p; } else { - if (f = n.limit || 0, g = 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); - } else if (n.or) { - p = a.or(n.or); - } else if (n.xor) { - p = a.xor(n.xor); - } else if (n.not) { - p = a.not(n.not); + if (f = p.limit || 0, g = p.offset || 0, l = p.suggest, k = p.resolve, h = p.enrich && k, p.index) { + p.resolve = !1, p.enrich = !1, n = p.index.search(p).result, p.resolve = k, p.enrich = h; + } else if (p.and) { + n = a.and(p.and); + } else if (p.or) { + n = a.or(p.or); + } else if (p.xor) { + n = a.xor(p.xor); + } else if (p.not) { + n = a.not(p.not); } else { continue; } } - if (p.then) { - e.push(p); - } else if (p.length) { - d[m] = p; + if (n.then) { + e.push(n); + } else if (n.length) { + d[m] = n; } else if (!l && ("and" === b || "xor" === b)) { d = []; break; @@ -1938,10 +1938,10 @@ function kb(a, b, c) { return {W:d, $:e, limit:f, offset:g, 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); + var a = wb(this, "or", arguments); + return xb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve); }; -function nb(a, b, c, d, e, f) { +function xb(a, b, c, d, e, f) { if (b.length) { var g = this; return Promise.all(b).then(function(h) { @@ -1949,10 +1949,10 @@ function nb(a, b, c, d, e, f) { 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 xb.call(g, a, [], c, d, e, f); }); } - 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)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = sb(a, c, d, !1, this.h), d = 0)); return f ? this.resolve(c, d, e) : this; } ;X.prototype.and = function() { @@ -1967,9 +1967,9 @@ function nb(a, b, c, d, e, f) { var f = 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 = wb(this, "and", arguments), yb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest)) : c ? this.resolve(d, e, f) : this; }; -function ob(a, b, c, d, e, f, g) { +function yb(a, b, c, d, e, f, g) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -1977,15 +1977,15 @@ 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 yb.call(h, a, [], c, d, e, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - if (b = Aa(a)) { - return this.result = ib(a, b, c, d, g, this.h, f), f ? e ? W.call(this.index, this.result) : this.result : this; + if (b = Fa(a)) { + return this.result = rb(a, b, c, d, g, this.h, f), f ? e ? vb.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -1995,10 +1995,10 @@ function ob(a, b, c, d, e, f, g) { return f ? 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); + var a = wb(this, "xor", arguments); + return zb.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 zb(a, b, c, d, e, f, g) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -2006,28 +2006,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 zb.call(h, a, [], c, d, e, f, g); }); } 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 = Ab.call(this, a, c, d, f, this.h), f ? e ? vb.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(c, d, e) : this; } -function qb(a, b, c, d, e) { - for (var f = [], g = I(), h = 0, k = 0, l; k < a.length; k++) { +function Ab(a, b, c, d, e) { + for (var f = [], g = Q(), 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; + for (var m = 0, p; m < l.length; m++) { + if (p = l[m]) { + for (var n = 0, q; n < p.length; n++) { + q = p[n], g[q] = g[q] ? 2 : 1; } } } @@ -2035,10 +2035,10 @@ function qb(a, b, c, d, e) { } for (l = k = 0; k < h; k++) { for (m = 0; m < a.length; m++) { - if (n = a[m]) { - if (n = n[k]) { - for (p = 0; p < n.length; p++) { - if (q = n[p], 1 === g[q]) { + if (p = a[m]) { + if (p = p[k]) { + for (n = 0; n < p.length; n++) { + if (q = p[n], 1 === g[q]) { if (c) { c--; } else { @@ -2047,9 +2047,9 @@ function qb(a, b, c, d, e) { return f; } } else { - var t = k + (m ? e : 0); - f[t] || (f[t] = []); - f[t].push(q); + var r = k + (m ? e : 0); + f[r] || (f[r] = []); + f[r].push(q); if (++l === b) { return f; } @@ -2064,10 +2064,10 @@ function qb(a, b, c, d, e) { return f; } ;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); + var a = wb(this, "not", arguments); + return Bb.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 Bb(a, b, c, d, e, f, g) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -2075,17 +2075,17 @@ 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 Bb.call(h, a, [], c, d, e, f, g); }); } if (a.length && this.result.length) { - this.result = sb.call(this, a, c, d, f); + this.result = Cb.call(this, a, c, d, f); } else if (f) { return this.resolve(c, d, e); } - return f ? e ? W.call(this.index, this.result) : this.result : this; + return f ? e ? vb.call(this.index, this.result) : this.result : this; } -function sb(a, b, c, d) { +function Cb(a, b, c, d) { var e = []; a = new Set(a.flat().flat()); for (var f = 0, g, h = 0; f < this.result.length; f++) { @@ -2158,262 +2158,235 @@ X.prototype.boost = function(a) { X.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), ub.call(e, d, a || 100, b, c)) : d; }; -I(); -V.prototype.search = function(a, b, c, d) { - c || (!b && xa(a) ? (c = a, a = "") : xa(b) && (c = b, b = 0)); - var e = [], f = [], g, h = 0, k = !0; - if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - var l = c.pluck; - var m = c.merge; - var n = l || c.field || (n = c.index) && (n.index ? null : n); - var p = this.tag && c.tag; - var q = c.suggest; - k = !1 !== c.resolve; - if (!k && !l) { - if (n = n || this.field) { - J(n) ? l = n : (n.constructor === Array && 1 === n.length && (n = n[0]), l = n.field || n.index); - } - if (!l) { - throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); - } - } - this.store && c.enrich && !k && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var t = (g = this.store && c.enrich && k) && c.highlight; - b = c.limit || b; - var v = c.offset || 0; - b || (b = 100); - if (p && (!this.db || !d)) { - p.constructor !== Array && (p = [p]); - for (var r = [], z = 0, A = void 0; z < p.length; z++) { - A = p[z]; - if (J(A)) { - throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); - } - if (A.field && A.tag) { - var w = A.tag; - if (w.constructor === Array) { - for (var x = 0; x < w.length; x++) { - r.push(A.field, w[x]); - } - } else { - r.push(A.field, w); - } - } else { - w = Object.keys(A); - x = 0; - for (var D = void 0, N = void 0; x < w.length; x++) { - if (D = w[x], N = A[D], N.constructor === Array) { - for (var H = 0; H < N.length; H++) { - r.push(D, N[H]); - } - } else { - r.push(D, N); - } - } - } - } - if (!r.length) { - throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); - } - p = r; - if (!a) { - k = []; - if (r.length) { - for (f = 0; f < r.length; f += 2) { - q = void 0; - if (this.db) { - q = this.index.get(r[f]); - if (!q) { - console.warn("Tag '" + r[f] + ":" + r[f + 1] + "' will be skipped because there is no field '" + r[f] + "'."); - continue; - } - k.push(q = q.db.tag(r[f + 1], b, v, g)); - } else { - q = tb.call(this, r[f], r[f + 1], b, v, g); - } - e.push({field:r[f], tag:r[f + 1], result:q}); - } - } - return k.length ? Promise.all(k).then(function(Q) { - for (var R = 0; R < Q.length; R++) { - e[R].result = Q[R]; - } - return e; - }) : e; - } - } - n && n.constructor !== Array && (n = [n]); +Q(); +function Db(a, b, c, d, e) { + if ("string" === typeof e) { + var f = e; + e = ""; + } else { + f = e.template; } - n || (n = this.field); - r = !d && (this.worker || this.db) && []; - z = 0; - for (x = A = w = void 0; z < n.length; z++) { - if (A = n[z], !this.db || !this.tag || this.L[z]) { - w = void 0; - J(A) || (w = A, A = w.field, a = w.query || a, b = w.limit || b, v = w.offset || v, q = w.suggest || q, g = this.store && (w.enrich || g)); - if (d) { - w = d[z]; - } else { - x = w || c; - w = this.index.get(A); - if (p) { - if (this.db) { - x.tag = p; - var Ma = w.db.support_tag_search; - x.field = n; - } - Ma || (x.enrich = !1); - } - if (r) { - r[z] = w.search(a, b, x); - x && g && (x.enrich = g); - continue; - } else { - w = w.search(a, b, x), x && g && (x.enrich = g); - } - } - x = w && (k ? w.length : w.result.length); - if (p && x) { - D = []; - N = 0; - if (this.db && d) { - if (!Ma) { - for (H = n.length; H < d.length; H++) { - var L = d[H]; - if (L && L.length) { - N++, D.push(L); - } else if (!q) { - return k ? e : new X(e); - } - } - } - } else { - H = 0; - for (var Wb = L = void 0; H < p.length; H += 2) { - L = this.tag.get(p[H]); - if (!L) { - if (console.warn("Tag '" + p[H] + ":" + p[H + 1] + "' will be skipped because there is no field '" + p[H] + "'."), q) { - continue; - } else { - return k ? e : new X(e); - } - } - if (Wb = (L = L && L.get(p[H + 1])) && L.length) { - N++, D.push(L); - } else if (!q) { - return k ? e : new X(e); - } - } - } - if (N) { - w = kb(w, D, k); - x = w.length; - if (!x && !q) { - return k ? w : new X(w); - } - N--; - } - } - if (x) { - f[h] = A, e.push(w), h++; - } else if (1 === n.length) { - return k ? e : new X(e); - } - } + if (!f) { + throw Error('No template pattern was specified by the search option "highlight"'); } - if (r) { - if (this.db && p && p.length && !Ma) { - for (g = 0; g < p.length; g += 2) { - f = this.index.get(p[g]); - if (!f) { - if (console.warn("Tag '" + p[g] + ":" + p[g + 1] + "' was not found because there is no field '" + p[g] + "'."), q) { - continue; - } else { - return k ? e : new X(e); - } - } - r.push(f.db.tag(p[g + 1], b, v, !1)); - } - } - var Xb = this; - return Promise.all(r).then(function(Q) { - return Q.length ? Xb.search(a, b, c, Q) : Q; - }); + var g = f.indexOf("$1"); + if (-1 === g) { + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); } - if (!h) { - return k ? e : new X(e); + var h = f.substring(g + 2); + g = f.substring(0, g); + var k = e && e.boundary, l = !e || !1 !== e.clip, m = e && e.merge && h && g && new RegExp(h + " " + g, "g"); + e = e && e.ellipsis; + var p = 0; + if ("object" === typeof e) { + var n = e.template; + p = n.length - 2; + e = e.pattern; } - if (l && (!g || !this.store)) { - return e[0]; + "string" !== typeof e && (e = !1 === e ? "" : "..."); + p && (e = n.replace("$1", e)); + n = e.length - p; + if ("object" === typeof k) { + var q = k.before; + 0 === q && (q = -1); + var r = k.after; + 0 === r && (r = -1); + k = k.total || 9e5; } - r = []; - for (v = 0; v < f.length; v++) { - q = e[v]; - g && q.length && "undefined" === typeof q[0].doc && (this.db ? r.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = W.call(this, q)); - if (l) { - return k ? t ? ub(a, q, this.index, l, t) : q : new X(q); - } - e[v] = {field:f[v], result:q}; - } - if (g && this.db && r.length) { - var Yb = this; - return Promise.all(r).then(function(Q) { - for (var R = 0; R < Q.length; R++) { - e[R].result = Q[R]; - } - return m ? vb(e) : t ? ub(a, e, Yb.index, l, t) : e; - }); - } - return m ? vb(e) : t ? ub(a, e, this.index, l, t) : e; -}; -function ub(a, b, c, d, e) { - for (var f, g, h, k = 0, l, m; k < b.length; k++) { + p = new Map(); + for (var w, u = 0, B, D; u < b.length; u++) { if (d) { - var n = b; - m = d; + var x = b; + D = d; } else { - l = b[k]; - m = l.field; - if (!m) { + x = b[u]; + D = x.field; + if (!D) { continue; } - n = l.result; + x = x.result; } - h = c.get(m); - l = h.encoder; - h = h.tokenize; - l !== f && (f = l, g = f.encode(a)); - for (var p = 0; p < n.length; p++) { - for (var q = "", t = za(n[p].doc, m).split(/\s+/), v = 0, r, z; v < t.length; v++) { - r = t[v]; - z = l.encode(r); - z = 1 < z.length ? z.join(" ") : z[0]; - var A = void 0; - if (z && r) { - for (var w = 0, x; w < g.length; w++) { - if (x = g[w], "strict" === h) { - if (z === x) { - q += (q ? " " : "") + e.replace("$1", r); - A = !0; - break; - } - } else { - var D = z.indexOf(x); - if (-1 < D) { - q += (q ? " " : "") + r.substring(0, D) + e.replace("$1", r.substring(D, D + x.length)) + r.substring(D + x.length); - A = !0; - break; + w = c.get(D); + B = w.encoder; + w = p.get(B); + "string" !== typeof w && (w = B.encode(a), p.set(B, w)); + for (var A = 0; A < x.length; A++) { + var t = x[A].doc; + if (t && (t = Ea(t, D))) { + var E = t.trim().split(/\s+/); + if (E.length) { + t = ""; + for (var C = [], ha = [], G = -1, N = -1, S = 0, F = 0; F < E.length; F++) { + var J = E[F], M = B.encode(J); + M = 1 < M.length ? M.join(" ") : M[0]; + var P = void 0; + if (M && J) { + for (var Y = J.length, Z = (B.split ? J.replace(B.split, "") : J).length - M.length, aa = "", ma = 0, y = 0; y < w.length; y++) { + var H = w[y]; + if (H) { + var K = H.length; + K += Z; + ma && K <= ma || (H = M.indexOf(H), -1 < H && (aa = (H ? J.substring(0, H) : "") + g + J.substring(H, H + K) + h + (H + K < Y ? J.substring(H + K) : ""), ma = K, P = !0)); + } } + aa && (k && (0 > G && (G = t.length + (t ? 1 : 0)), N = t.length + (t ? 1 : 0) + aa.length, S += Y, ha.push(C.length), C.push({match:aa})), t += (t ? " " : "") + aa); + } + if (!P) { + J = E[F], t += (t ? " " : "") + J, k && C.push({text:J}); + } else if (k && S >= k) { + break; } } + S = ha.length * (f.length - 2); + if (q || r || k && t.length - S > k) { + if (S = k + S - 2 * n, F = N - G, 0 < q && (F += q), 0 < r && (F += r), F <= S) { + E = q ? G - (0 < q ? q : 0) : G - ((S - F) / 2 | 0), C = r ? N + (0 < r ? r : 0) : E + S, l || (0 < E && " " !== t.charAt(E) && " " !== t.charAt(E - 1) && (E = t.indexOf(" ", E), 0 > E && (E = 0)), C < t.length && " " !== t.charAt(C - 1) && " " !== t.charAt(C) && (C = t.lastIndexOf(" ", C), C < N ? C = N : ++C)), t = (E ? e : "") + t.substring(E, C) + (C < t.length ? e : ""); + } else { + N = []; + S = {}; + G = {}; + F = {}; + J = {}; + M = {}; + Z = Y = P = 0; + for (ma = aa = 1;;) { + H = void 0; + for (y = 0; y < ha.length; y++) { + K = ha[y]; + if (Z) { + if (Y !== Z) { + if (F[y + 1]) { + continue; + } + K += Z; + if (S[K]) { + P -= n; + G[y + 1] = 1; + F[y + 1] = 1; + continue; + } + if (K >= C.length - 1) { + if (K >= C.length) { + F[y + 1] = 1; + K >= E.length && (G[y + 1] = 1); + continue; + } + P -= n; + } + t = C[K].text; + var T = r && M[y]; + if (T) { + if (0 < T) { + if (t.length > T) { + if (F[y + 1] = 1, l) { + t = t.substring(0, T); + } else { + continue; + } + } + (T -= t.length) || (T = -1); + M[y] = T; + } else { + F[y + 1] = 1; + continue; + } + } + if (P + t.length + 1 <= k) { + t = " " + t, N[y] += t; + } else if (l) { + H = k - P - 1, 0 < H && (t = " " + t.substring(0, H), N[y] += t), F[y + 1] = 1; + } else { + F[y + 1] = 1; + continue; + } + } else { + if (F[y]) { + continue; + } + K -= Y; + if (S[K]) { + P -= n; + F[y] = 1; + G[y] = 1; + continue; + } + if (0 >= K) { + if (0 > K) { + F[y] = 1; + G[y] = 1; + continue; + } + P -= n; + } + t = C[K].text; + if (T = q && J[y]) { + if (0 < T) { + if (t.length > T) { + if (F[y] = 1, l) { + t = t.substring(t.length - T); + } else { + continue; + } + } + (T -= t.length) || (T = -1); + J[y] = T; + } else { + F[y] = 1; + continue; + } + } + if (P + t.length + 1 <= k) { + t += " ", N[y] = t + N[y]; + } else if (l) { + H = t.length + 1 - (k - P), 0 <= H && H < t.length && (t = t.substring(H) + " ", N[y] = t + N[y]), F[y] = 1; + } else { + F[y] = 1; + continue; + } + } + } else { + t = C[K].match; + q && (J[y] = q); + r && (M[y] = r); + y && P++; + H = void 0; + K ? !y && n && (P += n) : (G[y] = 1, F[y] = 1); + K >= E.length - 1 ? H = 1 : K < C.length - 1 && C[K + 1].match ? H = 1 : n && (P += n); + P -= f.length - 2; + if (!y || P + t.length <= k) { + N[y] = t; + } else { + H = aa = ma = G[y] = 0; + break; + } + H && (G[y + 1] = 1, F[y + 1] = 1); + } + P += t.length; + H = S[K] = 1; + } + if (H) { + Y === Z ? Z++ : Y++; + } else { + Y === Z ? aa = 0 : ma = 0; + if (!aa && !ma) { + break; + } + aa ? (Y++, Z = Y) : Z++; + } + } + t = ""; + for (E = 0; E < N.length; E++) { + C = (E && G[E] ? " " : (E && !e ? " " : "") + e) + N[E], t += C; + } + e && !G[N.length] && (t += e); + } + } + m && (t = t.replace(m, " ")); + x[A].highlight = t; } - A || (q += (q ? " " : "") + t[v]); } - n[p].highlight = q; } if (d) { break; @@ -2421,8 +2394,217 @@ function ub(a, b, c, d, e) { } return b; } -function vb(a) { - for (var b = [], c = I(), d = 0, e, f; d < a.length; d++) { +;ob.prototype.search = function(a, b, c, d) { + c || (!b && Ca(a) ? (c = a, a = "") : Ca(b) && (c = b, b = 0)); + var e = [], f = [], g = 0, h = !0, k; + if (c) { + c.constructor === Array && (c = {index:c}); + a = c.query || a; + var l = c.pluck; + var m = c.merge; + var p = l || c.field || (p = c.index) && (p.index ? null : p); + var n = this.tag && c.tag; + var q = c.suggest; + h = !1 !== c.resolve; + if (!h && !l) { + if (p = p || this.field) { + R(p) ? l = p : (p.constructor === Array && 1 === p.length && (p = p[0]), l = p.field || p.index); + } + if (!l) { + throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); + } + } + this.store && c.enrich && !h && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var r = (k = h && this.store && c.highlight) || h && this.store && c.enrich; + b = c.limit || b; + var w = c.offset || 0; + b || (b = 100); + if (n && (!this.db || !d)) { + n.constructor !== Array && (n = [n]); + for (var u = [], B = 0, D = void 0; B < n.length; B++) { + D = n[B]; + if (R(D)) { + throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); + } + if (D.field && D.tag) { + var x = D.tag; + if (x.constructor === Array) { + for (var A = 0; A < x.length; A++) { + u.push(D.field, x[A]); + } + } else { + u.push(D.field, x); + } + } else { + x = Object.keys(D); + A = 0; + for (var t = void 0, E = void 0; A < x.length; A++) { + if (t = x[A], E = D[t], E.constructor === Array) { + for (var C = 0; C < E.length; C++) { + u.push(t, E[C]); + } + } else { + u.push(t, E); + } + } + } + } + if (!u.length) { + throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); + } + n = u; + if (!a) { + h = []; + if (u.length) { + for (f = 0; f < u.length; f += 2) { + q = void 0; + if (this.db) { + q = this.index.get(u[f]); + if (!q) { + console.warn("Tag '" + u[f] + ":" + u[f + 1] + "' will be skipped because there is no field '" + u[f] + "'."); + continue; + } + h.push(q = q.db.tag(u[f + 1], b, w, r)); + } else { + q = Eb.call(this, u[f], u[f + 1], b, w, r); + } + e.push({field:u[f], tag:u[f + 1], result:q}); + } + } + return h.length ? Promise.all(h).then(function(J) { + for (var M = 0; M < J.length; M++) { + e[M].result = J[M]; + } + return e; + }) : e; + } + } + p && p.constructor !== Array && (p = [p]); + } + p || (p = this.field); + u = !d && (this.worker || this.db) && []; + B = 0; + for (A = D = x = void 0; B < p.length; B++) { + if (D = p[B], !this.db || !this.tag || this.L[B]) { + x = void 0; + R(D) || (x = D, D = x.field, a = x.query || a, b = x.limit || b, w = x.offset || w, q = x.suggest || q, k = (r = this.store && (x.enrich || r)) && (c.highlight || k)); + if (d) { + x = d[B]; + } else { + A = x || c; + x = this.index.get(D); + if (n) { + if (this.db) { + A.tag = n; + var ha = x.db.support_tag_search; + A.field = p; + } + ha || (A.enrich = !1); + } + if (u) { + u[B] = x.search(a, b, A); + A && r && (A.enrich = r); + continue; + } else { + x = x.search(a, b, A), A && r && (A.enrich = r); + } + } + A = x && (h ? x.length : x.result.length); + if (n && A) { + t = []; + E = 0; + if (this.db && d) { + if (!ha) { + for (C = p.length; C < d.length; C++) { + var G = d[C]; + if (G && G.length) { + E++, t.push(G); + } else if (!q) { + return h ? e : new X(e); + } + } + } + } else { + C = 0; + for (var N = G = void 0; C < n.length; C += 2) { + G = this.tag.get(n[C]); + if (!G) { + if (console.warn("Tag '" + n[C] + ":" + n[C + 1] + "' will be skipped because there is no field '" + n[C] + "'."), q) { + continue; + } else { + return h ? e : new X(e); + } + } + if (N = (G = G && G.get(n[C + 1])) && G.length) { + E++, t.push(G); + } else if (!q) { + return h ? e : new X(e); + } + } + } + if (E) { + x = tb(x, t, h); + A = x.length; + if (!A && !q) { + return h ? x : new X(x); + } + E--; + } + } + if (A) { + f[g] = D, e.push(x), g++; + } else if (1 === p.length) { + return h ? e : new X(e); + } + } + } + if (u) { + if (this.db && n && n.length && !ha) { + for (r = 0; r < n.length; r += 2) { + f = this.index.get(n[r]); + if (!f) { + if (console.warn("Tag '" + n[r] + ":" + n[r + 1] + "' was not found because there is no field '" + n[r] + "'."), q) { + continue; + } else { + return h ? e : new X(e); + } + } + u.push(f.db.tag(n[r + 1], b, w, !1)); + } + } + var S = this; + return Promise.all(u).then(function(J) { + return J.length ? S.search(a, b, c, J) : J; + }); + } + if (!g) { + return h ? e : new X(e); + } + if (l && (!r || !this.store)) { + return e[0]; + } + u = []; + for (w = 0; w < f.length; w++) { + q = e[w]; + r && q.length && "undefined" === typeof q[0].doc && (this.db ? u.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = vb.call(this, q)); + if (l) { + return h ? k ? Db(a, q, this.index, l, k) : q : new X(q); + } + e[w] = {field:f[w], result:q}; + } + if (r && this.db && u.length) { + var F = this; + return Promise.all(u).then(function(J) { + for (var M = 0; M < J.length; M++) { + e[M].result = J[M]; + } + return m ? Fb(e) : k ? Db(a, e, F.index, l, k) : e; + }); + } + return m ? Fb(e) : k ? Db(a, e, this.index, l, k) : e; +}; +function Fb(a) { + for (var b = [], c = Q(), d = 0, e, f; d < a.length; d++) { e = a[d]; f = e.result; for (var g = 0, h, k, l; g < f.length; g++) { @@ -2431,7 +2613,7 @@ function vb(a) { } return b; } -function tb(a, b, c, d, e) { +function Eb(a, b, c, d, e) { var f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -2440,11 +2622,11 @@ function tb(a, b, c, d, e) { if (a > c || d) { f = f.slice(d, d + c); } - e && (f = W.call(this, f)); + e && (f = vb.call(this, f)); return f; } } -function W(a) { +function vb(a) { if (!this || !this.store) { return a; } @@ -2453,25 +2635,25 @@ function W(a) { } return b; } -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); +;function ob(a) { + if (!this || this.constructor !== ob) { + return new ob(a); } var b = a.document || a.doc || a, c, d; this.L = []; this.field = []; this.S = []; - this.key = (c = b.key || b.id) && wb(c, this.S) || "id"; + this.key = (c = b.key || b.id) && Gb(c, this.S) || "id"; (d = a.keystore || 0) && (this.keystore = d); this.fastupdate = !!a.fastupdate; - this.reg = !this.fastupdate || a.worker || a.db ? d ? new U(d) : new Set() : d ? new T(d) : new Map(); + this.reg = !this.fastupdate || a.worker || a.db ? d ? new W(d) : new Set() : d ? new V(d) : new Map(); 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 V(d) : new Map()); + this.cache = (c = a.cache || null) && new Hb(c); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = xb.call(this, a, b); + this.index = Ib.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -2485,7 +2667,7 @@ function W(a) { if (!e) { throw Error("The tag field from the document descriptor is undefined."); } - d.custom ? this.K[b] = d.custom : (this.K[b] = wb(e, this.S), d.filter && ("string" === typeof this.K[b] && (this.K[b] = new String(this.K[b])), this.K[b].R = d.filter)); + d.custom ? this.K[b] = d.custom : (this.K[b] = Gb(e, this.S), d.filter && ("string" === typeof this.K[b] && (this.K[b] = new String(this.K[b])), this.K[b].R = d.filter)); this.aa[b] = e; this.tag.set(e, new Map()); } @@ -2494,18 +2676,18 @@ function W(a) { if (this.worker) { this.fastupdate = !1; var f = []; - a = y(this.index.values()); + a = z(this.index.values()); for (c = a.next(); !c.done; c = a.next()) { c = c.value, c.then && f.push(c); } if (f.length) { var g = this; return Promise.all(f).then(function(h) { - for (var k = new Map(), l = 0, m = y(g.index.entries()), n = m.next(); !n.done; n = m.next()) { - var p = n.value; - n = p[0]; - var q = p[1]; - q.then && (q = f[l].encoder || {}, p = k.get(q), p || (p = q.encode ? q : new Ga(q), k.set(q, p)), q = h[l], q.encoder = p, g.index.set(n, q), l++); + for (var k = new Map(), l = 0, m = z(g.index.entries()), p = m.next(); !p.done; p = m.next()) { + var n = p.value; + p = n[0]; + var q = n[1]; + q.then && (q = f[l].encoder || {}, n = k.get(q), n || (n = q.encode ? q : new La(q), k.set(q, n)), q = h[l], q.encoder = n, g.index.set(p, q), l++); } return g; }); @@ -2514,8 +2696,8 @@ function W(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -u = V.prototype; -u.mount = function(a) { +v = ob.prototype; +v.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } @@ -2524,7 +2706,7 @@ u.mount = function(a) { for (var c = 0, d = void 0; c < this.aa.length; c++) { d = this.aa[c]; var e = void 0; - this.index.set(d, e = new O({}, this.reg)); + this.index.set(d, e = new U({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(d); e.tag = this.tag.get(d); @@ -2548,73 +2730,73 @@ u.mount = function(a) { h.db = !0; }); }; -u.commit = function(a, b) { +v.commit = function(a, b) { var c = this, d, e, f, g; - return ta(function(h) { + return xa(function(h) { if (1 == h.h) { d = []; - e = y(c.index.values()); + e = z(c.index.values()); for (f = e.next(); !f.done; f = e.next()) { g = f.value, d.push(g.commit(a, b)); } - return E(h, Promise.all(d), 2); + return L(h, Promise.all(d), 2); } c.reg.clear(); h.h = 0; }); }; -u.destroy = function() { - for (var a = [], b = y(this.index.values()), c = b.next(); !c.done; c = b.next()) { +v.destroy = function() { + for (var a = [], b = z(this.index.values()), c = b.next(); !c.done; c = b.next()) { a.push(c.value.destroy()); } return Promise.all(a); }; -function xb(a, b) { +function Ib(a, b) { var c = new Map(), d = b.index || b.field || b; - J(d) && (d = [d]); + R(d) && (d = [d]); for (var e = 0, f, g = void 0; e < d.length; e++) { f = d[e]; - J(f) || (g = f, f = f.field); - g = xa(g) ? Object.assign({}, a, g) : a; + R(f) || (g = f, f = f.field); + g = Ca(g) ? Object.assign({}, a, g) : a; if (this.worker) { - var h = new Ra(g); + var h = new Xa(g); h.encoder = g.encoder; c.set(f, h); } - this.worker || c.set(f, new O(g, this.reg)); - g.custom ? this.L[e] = g.custom : (this.L[e] = wb(f, this.S), g.filter && ("string" === typeof this.L[e] && (this.L[e] = new String(this.L[e])), this.L[e].R = g.filter)); + this.worker || c.set(f, new U(g, this.reg)); + g.custom ? this.L[e] = g.custom : (this.L[e] = Gb(f, this.S), g.filter && ("string" === typeof this.L[e] && (this.L[e] = new String(this.L[e])), this.L[e].R = g.filter)); this.field[e] = f; } if (this.I) { - for (a = b.store, J(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)); + for (a = b.store, R(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] = Gb(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 Gb(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); } d < c.length && (c.length = d); return 1 < d ? c : c[0]; } -u.append = function(a, b) { +v.append = function(a, b) { return this.add(a, b, !0); }; -u.update = function(a, b) { +v.update = function(a, b) { return this.remove(a).add(a, b); }; -u.remove = function(a) { - xa(a) && (a = za(a, this.key)); - for (var b = y(this.index.values()), c = b.next(); !c.done; c = b.next()) { +v.remove = function(a) { + Ca(a) && (a = Ea(a, this.key)); + for (var b = z(this.index.values()), c = b.next(); !c.done; c = b.next()) { c.value.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { - for (b = y(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = z(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c = c.value; - for (var d = y(c), e = d.next(); !e.done; e = d.next()) { + for (var d = z(c), e = d.next(); !e.done; e = d.next()) { var f = e.value; e = f[0]; f = f[1]; @@ -2629,12 +2811,12 @@ u.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -u.clear = function() { - for (var a = [], b = y(this.index.values()), c = b.next(); !c.done; c = b.next()) { +v.clear = function() { + for (var a = [], b = z(this.index.values()), c = b.next(); !c.done; c = b.next()) { c = c.value.clear(), c.then && a.push(c); } if (this.tag) { - for (b = y(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = z(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c.value.clear(); } } @@ -2642,27 +2824,27 @@ u.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -u.contain = function(a) { +v.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -u.cleanup = function() { - for (var a = y(this.index.values()), b = a.next(); !b.done; b = a.next()) { +v.cleanup = function() { + for (var a = z(this.index.values()), b = a.next(); !b.done; b = a.next()) { b.value.cleanup(); } return this; }; -u.get = function(a) { +v.get = function(a) { return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { return b[0] && b[0].doc || null; }) : this.store.get(a) || null; }; -u.set = function(a, b) { - "object" === typeof a && (b = a, a = za(b, this.key)); +v.set = function(a, b) { + "object" === typeof a && (b = a, a = Ea(b, this.key)); this.store.set(a, b); return this; }; -u.searchCache = yb; -u.export = function(a, b, c, d) { +v.searchCache = Jb; +v.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; if (c < this.field.length) { @@ -2678,25 +2860,25 @@ u.export = function(a, b, c, d) { switch(d) { case 0: var g = "reg"; - var h = Xa(this.reg); + var h = db(this.reg); b = null; break; case 1: g = "tag"; - h = this.tag && Va(this.tag, this.reg.size); + h = this.tag && bb(this.tag, this.reg.size); b = null; break; case 2: g = "doc"; - h = this.store && Ta(this.store); + h = this.store && $a(this.store); b = null; break; default: return; } - return Za.call(this, a, b, g, h, c, d); + return fb.call(this, a, b, g, h, c, d); }; -u.import = function(a, b) { +v.import = function(a, b) { var c = a.split("."); "json" === c[c.length - 1] && c.pop(); var d = 2 < c.length ? c[0] : ""; @@ -2712,13 +2894,13 @@ u.import = function(a, b) { switch(c) { case "reg": this.fastupdate = !1; - this.reg = Ya(b, this.reg); + this.reg = eb(b, this.reg); for (b = 0; b < this.field.length; b++) { d = this.index.get(this.field[b]), d.fastupdate = !1, d.reg = this.reg; } if (this.worker) { b = []; - d = y(this.index.values()); + d = z(this.index.values()); for (c = d.next(); !c.done; c = d.next()) { b.push(c.value.import(a)); } @@ -2726,17 +2908,17 @@ u.import = function(a, b) { } break; case "tag": - this.tag = Wa(b, this.tag); + this.tag = cb(b, this.tag); break; case "doc": - this.store = Ua(b, this.store); + this.store = ab(b, this.store); } } }; -Ja(V.prototype); -function yb(a, b, c) { +Qa(ob.prototype); +function Jb(a, b, c) { var d = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Y()); + this.cache || (this.cache = new Hb()); var e = this.cache.get(d); if (!e) { e = this.search(a, b, c); @@ -2751,44 +2933,44 @@ function yb(a, b, c) { } return e; } -function Y(a) { +function Hb(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -Y.prototype.set = function(a, b) { +Hb.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) { +Hb.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 = y(this.cache), c = b.next(); !c.done; c = b.next()) { +Hb.prototype.remove = function(a) { + for (var b = z(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() { +Hb.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -var zb = {normalize:!1, numeric:!1, dedupe:!1}; -var Ab = {}; -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"], ["ph", "f"], ["pf", "f"]]), Db = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\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 = {Exact:zb, Default:Ab, Normalize:Ab, LatinBalance:{mapper:Bb}, LatinAdvanced:{mapper:Bb, matcher:Cb, replacer:Db}, LatinExtra:{mapper:Bb, replacer:Db.concat([/(?!^)[aeo]/g, ""]), matcher:Cb}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +var Kb = {normalize:!1, numeric:!1, dedupe:!1}; +var Lb = {}; +var Mb = 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 Nb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ob = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +var Pb = {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 Qb = {Exact:Kb, Default:Lb, Normalize:Lb, LatinBalance:{mapper:Mb}, LatinAdvanced:{mapper:Mb, matcher:Nb, replacer:Ob}, LatinExtra:{mapper:Mb, replacer:Ob.concat([/(?!^)[aeo]/g, ""]), matcher:Nb}, LatinSoundex:{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 = Eb[d], f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Eb[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + for (var c = a[b], d = c.charAt(0), e = Pb[d], f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Pb[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { } a[b] = d; } -}}, CJK:{split:""}, LatinExact:zb, LatinDefault:Ab, LatinSimple:Ab}; -O.prototype.remove = function(a, b) { +}}, CJK:{split:""}, LatinExact:Kb, LatinDefault:Lb, LatinSimple:Lb}; +U.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) { @@ -2803,15 +2985,15 @@ O.prototype.remove = function(a, b) { } } } else { - Gb(this.map, a), this.depth && Gb(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 && Hb(this)); + this.db && (this.commit_task.push({del:a}), this.ca && Sb(this)); this.cache && this.cache.remove(a); return this; }; -function Gb(a, b) { +function Rb(a, b) { var c = 0, d = "undefined" === typeof b; if (a.constructor === Array) { for (var e = 0, f = void 0, g; e < a.length; e++) { @@ -2829,14 +3011,14 @@ function Gb(a, b) { } } } else { - for (d = y(a.entries()), e = d.next(); !e.done; e = d.next()) { - f = e.value, e = f[0], (f = Gb(f[1], b)) ? c += f : a.delete(e); + for (d = z(a.entries()), e = d.next(); !e.done; e = d.next()) { + f = e.value, e = f[0], (f = Rb(f[1], b)) ? c += f : a.delete(e); } } return c; } -;var Ib = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -O.prototype.add = function(a, b, c, d) { +;var Tb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +U.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { if (!d && !c && this.reg.has(a)) { return this.update(a, b); @@ -2845,17 +3027,17 @@ O.prototype.add = function(a, b, c, d) { b = this.encoder.encode(b, !d); var e = b.length; if (e) { - for (var f = I(), g = I(), h = this.resolution, k = 0; k < e; k++) { + for (var f = Q(), g = Q(), h = this.resolution, k = 0; k < e; k++) { var l = b[this.rtl ? e - 1 - k : k], m = l.length; if (m && (d || !g[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : Jb(h, e, k), p = ""; + var p = this.score ? this.score(b, l, k, null, 0) : Ub(h, e, k), n = ""; switch(this.tokenize) { case "full": if (2 < m) { - n = 0; - for (var q; n < m; n++) { - for (var t = m; t > n; t--) { - p = l.substring(n, t), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, k, p, q) : Jb(h, e, k, m, q), Kb(this, g, p, q, a, c); + p = 0; + for (var q; p < m; p++) { + for (var r = m; r > p; r--) { + n = l.substring(p, r), q = this.rtl ? m - 1 - p : p, q = this.score ? this.score(b, l, k, n, q) : Ub(h, e, k, m, q), Vb(this, g, n, q, a, c); } } break; @@ -2863,25 +3045,25 @@ O.prototype.add = function(a, b, c, d) { case "bidirectional": case "reverse": if (1 < m) { - for (t = m - 1; 0 < t; t--) { - p = l[this.rtl ? m - 1 - t : t] + p, q = this.score ? this.score(b, l, k, p, t) : Jb(h, e, k, m, t), Kb(this, g, p, q, a, c); + for (r = m - 1; 0 < r; r--) { + n = l[this.rtl ? m - 1 - r : r] + n, q = this.score ? this.score(b, l, k, n, r) : Ub(h, e, k, m, r), Vb(this, g, n, q, a, c); } - p = ""; + n = ""; } case "forward": if (1 < m) { - for (t = 0; t < m; t++) { - p += l[this.rtl ? m - 1 - t : t], Kb(this, g, p, n, a, c); + for (r = 0; r < m; r++) { + n += l[this.rtl ? m - 1 - r : r], Vb(this, g, n, p, a, c); } break; } default: - if (Kb(this, g, l, n, a, c), d && 1 < e && k < e - 1) { - for (m = I(), p = this.da, n = l, t = Math.min(d + 1, this.rtl ? k + 1 : e - k), q = m[n] = 1; q < t; q++) { + if (Vb(this, g, l, p, a, c), d && 1 < e && k < e - 1) { + for (m = Q(), n = this.da, p = l, r = Math.min(d + 1, this.rtl ? k + 1 : e - k), q = m[p] = 1; q < r; q++) { if ((l = b[this.rtl ? e - 1 - k - q : k + q]) && !m[l]) { m[l] = 1; - var v = this.score ? this.score(b, n, k, l, q - 1) : Jb(p + (e / 2 > p ? 0 : 1), e, k, t - 1, q - 1), r = this.bidirectional && l > n; - Kb(this, f, r ? n : l, v, a, c, r ? l : n); + var w = this.score ? this.score(b, p, k, l, q - 1) : Ub(n + (e / 2 > n ? 0 : 1), e, k, r - 1, q - 1), u = this.bidirectional && l > p; + Vb(this, f, u ? p : l, w, a, c, u ? l : p); } } } @@ -2893,17 +3075,17 @@ O.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.ca && Hb(this)); + this.db && (b || this.commit_task.push({del:a}), this.ca && Sb(this)); return this; }; -function Kb(a, b, c, d, e, f, g) { +function Vb(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] = I()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { + if (g ? (b = k || (b[c] = Q()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { if (h.length === Math.pow(2, 31) - 1) { - b = new S(h); + b = new ib(h); if (a.fastupdate) { - for (c = y(a.reg.values()), f = c.next(); !f.done; f = c.next()) { + for (c = z(a.reg.values()), f = c.next(); !f.done; f = c.next()) { f = f.value, f.includes(h) && (f[f.indexOf(h)] = b); } } @@ -2914,10 +3096,10 @@ function Kb(a, b, c, d, e, f, g) { } } } -function Jb(a, b, c, d, e) { +function Ub(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) { +;U.prototype.search = function(a, b, c) { c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); var d = [], e = 0, f; if (c) { @@ -2929,98 +3111,98 @@ function Jb(a, b, c, d, e) { var k = (f = !1 !== c.resolve) && c.enrich; var l = c.boost; var m = c.resolution; - var n = this.db && c.tag; + var p = this.db && c.tag; } else { f = this.resolve; } g = this.depth && !1 !== g; - var p = this.encoder.encode(a, !g); - var q = p.length; + var n = this.encoder.encode(a, !g); + var q = n.length; b = b || (f ? 100 : 0); if (1 === q) { - return Lb.call(this, p[0], "", b, e, f, k, n); + return Wb.call(this, n[0], "", b, e, f, k, p); } if (2 === q && g && !h) { - return Lb.call(this, p[1], p[0], b, e, f, k, n); + return Wb.call(this, n[1], n[0], b, e, f, k, p); } - var t = I(), v = 0; + var r = Q(), w = 0; if (g) { - var r = p[0]; - v = 1; + var u = n[0]; + w = 1; } - m || 0 === m || (m = r ? this.da : this.resolution); + m || 0 === m || (m = u ? 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, n, b, e, h, f, k, p), !1 !== a)) { return a; } - var z = this; + var B = this; return function() { - var A, w; - return ta(function(x) { - switch(x.h) { + var D, x; + return xa(function(A) { + switch(A.h) { case 1: - w = A = void 0; + x = D = void 0; case 2: - if (!(v < q)) { - x.h = 4; + if (!(w < q)) { + A.h = 4; break; } - w = p[v]; - if (!w || t[w]) { - x.h = 5; + x = n[w]; + if (!x || r[x]) { + A.h = 5; break; } - t[w] = 1; - return E(x, Mb(z, w, r, 0, 0, !1, !1), 6); + r[x] = 1; + return L(A, Xb(B, x, u, 0, 0, !1, !1), 6); case 6: - A = x.D; - if (A = Nb(A, d, h, m)) { - d = A; - x.h = 4; + D = A.D; + if (D = Yb(D, d, h, m)) { + d = D; + A.h = 4; break; } - r && (h && A && d.length || (r = w)); + u && (h && D && d.length || (u = x)); case 5: - h && r && v === q - 1 && !d.length && (m = z.resolution, r = "", v = -1, t = I()); - v++; - x.h = 2; + h && u && w === q - 1 && !d.length && (m = B.resolution, u = "", w = -1, r = Q()); + w++; + A.h = 2; break; case 4: - return x.return(Ob(d, m, b, e, h, l, f)); + return A.return(Zb(d, m, b, e, h, l, f)); } }); }(); } - for (c = a = void 0; v < q; v++) { - if ((c = p[v]) && !t[c]) { - t[c] = 1; - a = Mb(this, c, r, 0, 0, !1, !1); - if (a = Nb(a, d, h, m)) { + for (c = a = void 0; w < q; w++) { + if ((c = n[w]) && !r[c]) { + r[c] = 1; + a = Xb(this, c, u, 0, 0, !1, !1); + if (a = Yb(a, d, h, m)) { d = a; break; } - r && (h && a && d.length || (r = c)); + u && (h && a && d.length || (u = c)); } - h && r && v === q - 1 && !d.length && (m = this.resolution, r = "", v = -1, t = I()); + h && u && w === q - 1 && !d.length && (m = this.resolution, u = "", w = -1, r = Q()); } - return Ob(d, m, b, e, h, l, f); + return Zb(d, m, b, e, h, l, f); }; -function Ob(a, b, c, d, e, f, g) { +function Zb(a, b, c, d, e, f, g) { var h = a.length, k = a; if (1 < h) { - k = ib(a, b, c, d, e, f, g); + k = rb(a, b, c, d, e, f, g); } else if (1 === h) { - return g ? lb.call(null, a[0], c, d) : new X(a[0]); + return g ? ub.call(null, a[0], c, d) : new X(a[0]); } return g ? k : new X(k); } -function Lb(a, b, c, d, e, f, g) { - a = Mb(this, a, b, c, d, e, f, g); +function Wb(a, b, c, d, e, f, g) { + a = Xb(this, a, b, c, d, e, f, g); 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(); + }) : a && a.length ? e ? ub.call(this, a, c, d) : new X(a) : e ? [] : new X(); } -function Nb(a, b, c, d) { +function Yb(a, b, c, d) { var e = []; if (a && a.length) { if (a.length <= d) { @@ -3041,7 +3223,7 @@ function Nb(a, b, c, d) { return e; } } -function Mb(a, b, c, d, e, f, g, h) { +function Xb(a, b, c, d, e, f, g, h) { var k; c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); if (a.db) { @@ -3050,19 +3232,19 @@ function Mb(a, b, c, d, e, f, g, h) { a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;function O(a, b) { - if (!this || this.constructor !== O) { - return new O(a); +;function U(a, b) { + if (!this || this.constructor !== U) { + return new U(a); } if (a) { - var c = J(a) ? a : a.preset; - c && (Ib[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ib[c], a)); + var c = R(a) ? a : a.preset; + c && (Tb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Tb[c], a)); } else { a = {}; } c = a.context; - var d = !0 === c ? {depth:1} : c || {}, e = J(a.encoder) ? Fb[a.encoder] : a.encode || a.encoder || {}; - this.encoder = e.encode ? e : "object" === typeof e ? new Ga(e) : {encode:e}; + var d = !0 === c ? {depth:1} : c || {}, e = R(a.encoder) ? Qb[a.encoder] : a.encode || a.encoder || {}; + this.encoder = e.encode ? e : "object" === typeof e ? new La(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = c = (c = a.tokenize) && "default" !== c && "exact" !== c && c || "strict"; this.depth = "strict" === c && d.depth || 0; @@ -3071,12 +3253,12 @@ function Mb(a, b, c, d, e, f, g, h) { this.score = a.score || null; d && d.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); (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 V(c) : new Map(); + this.ctx = c ? new V(c) : new Map(); + this.reg = b || (this.fastupdate ? c ? new V(c) : new Map() : c ? new W(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 Hb(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); @@ -3086,26 +3268,26 @@ function Mb(a, b, c, d, e, f, g, h) { this.commit_timer = null; this.priority = a.priority || 4; } -u = O.prototype; -u.mount = function(a) { +v = U.prototype; +v.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -u.commit = function(a, b) { +v.commit = function(a, b) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.commit(this, a, b); }; -u.destroy = function() { +v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Hb(a) { +function Sb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 1)); } -u.clear = function() { +v.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -3113,34 +3295,34 @@ u.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -u.append = function(a, b) { +v.append = function(a, b) { return this.add(a, b, !0); }; -u.contain = function(a) { +v.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -u.update = function(a, b) { +v.update = function(a, b) { var c = this, d = this.remove(a); return d && d.then ? d.then(function() { return c.add(a, b); }) : this.add(a, b); }; -u.cleanup = function() { +v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Gb(this.map); - this.depth && Gb(this.ctx); + Rb(this.map); + this.depth && Rb(this.ctx); return this; }; -u.searchCache = yb; -u.export = function(a, b, c, d) { +v.searchCache = Jb; +v.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 = Xa(this.reg); + var f = db(this.reg); break; case 1: e = "cfg"; @@ -3148,49 +3330,49 @@ u.export = function(a, b, c, d) { break; case 2: e = "map"; - f = Ta(this.map, this.reg.size); + f = $a(this.map, this.reg.size); break; case 3: e = "ctx"; - f = Va(this.ctx, this.reg.size); + f = bb(this.ctx, this.reg.size); break; default: return; } - return Za.call(this, a, b, e, f, c, d); + return fb.call(this, a, b, e, f, c, d); }; -u.import = function(a, b) { +v.import = function(a, b) { if (b) { switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = Ya(b, this.reg); + this.reg = eb(b, this.reg); break; case "map": - this.map = Ua(b, this.map); + this.map = ab(b, this.map); break; case "ctx": - this.ctx = Wa(b, this.ctx); + this.ctx = cb(b, this.ctx); } } }; -u.serialize = function(a) { +v.serialize = function(a) { a = void 0 === a ? !0 : a; var b = "", c = "", d = ""; if (this.reg.size) { var e; - c = y(this.reg.keys()); + c = z(this.reg.keys()); for (var f = c.next(); !f.done; f = c.next()) { f = f.value, e || (e = typeof f), b += (b ? "," : "") + ("string" === e ? '"' + f + '"' : f); } b = "index.reg=new Set([" + b + "]);"; - c = $a(this.map, e); + c = gb(this.map, e); c = "index.map=new Map([" + c + "]);"; - f = y(this.ctx.entries()); + f = z(this.ctx.entries()); for (var g = f.next(); !g.done; g = f.next()) { var h = g.value; g = h[0]; - h = $a(h[1], e); + h = gb(h[1], e); h = "new Map([" + h + "])"; h = '["' + g + '",' + h + "]"; d += (d ? "," : "") + h; @@ -3199,12 +3381,12 @@ u.serialize = function(a) { } return a ? "function inject(index){" + b + c + d + "}" : b + c + d; }; -Ja(O.prototype); -var Pb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Qb = ["map", "ctx", "tag", "reg", "cfg"], Rb = I(); -function Sb(a, b) { +Qa(U.prototype); +var $b = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ac = ["map", "ctx", "tag", "reg", "cfg"], bc = Q(); +function cc(a, b) { b = void 0 === b ? {} : b; - if (!this || this.constructor !== Sb) { - return new Sb(a, b); + if (!this || this.constructor !== cc) { + return new cc(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3215,67 +3397,67 @@ function Sb(a, b) { this.db = null; this.h = {}; } -u = Sb.prototype; -u.mount = function(a) { +v = cc.prototype; +v.mount = function(a) { if (a.index) { return a.mount(this); } a.db = this; return this.open(); }; -u.open = function() { +v.open = function() { if (this.db) { return this.db; } var a = this; navigator.storage && navigator.storage.persist(); - Rb[a.id] || (Rb[a.id] = []); - Rb[a.id].push(a.field); - var b = Pb.open(a.id, 1); + bc[a.id] || (bc[a.id] = []); + bc[a.id].push(a.field); + var b = $b.open(a.id, 1); b.onupgradeneeded = function() { - for (var c = a.db = this.result, d = 0, e; d < Qb.length; d++) { - e = Qb[d]; - for (var f = 0, g; f < Rb[a.id].length; f++) { - g = Rb[a.id][f], c.objectStoreNames.contains(e + ("reg" !== e ? g ? ":" + g : "" : "")) || c.createObjectStore(e + ("reg" !== e ? g ? ":" + g : "" : "")); + for (var c = a.db = this.result, d = 0, e; d < ac.length; d++) { + e = ac[d]; + for (var f = 0, g; f < bc[a.id].length; f++) { + g = bc[a.id][f], c.objectStoreNames.contains(e + ("reg" !== e ? g ? ":" + g : "" : "")) || c.createObjectStore(e + ("reg" !== e ? g ? ":" + g : "" : "")); } } }; - return a.db = Z(b, function(c) { + return a.db = dc(b, function(c) { a.db = c; a.db.onversionchange = function() { a.close(); }; }); }; -u.close = function() { +v.close = function() { this.db && this.db.close(); this.db = null; }; -u.destroy = function() { - var a = Pb.deleteDatabase(this.id); - return Z(a); +v.destroy = function() { + var a = $b.deleteDatabase(this.id); + return dc(a); }; -u.clear = function() { - for (var a = [], b = 0, c; b < Qb.length; b++) { - c = Qb[b]; - for (var d = 0, e; d < Rb[this.id].length; d++) { - e = Rb[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); +v.clear = function() { + for (var a = [], b = 0, c; b < ac.length; b++) { + c = ac[b]; + for (var d = 0, e; d < bc[this.id].length; d++) { + e = bc[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); } } b = this.db.transaction(a, "readwrite"); for (c = 0; c < a.length; c++) { b.objectStore(a[c]).clear(); } - return Z(b); + return dc(b); }; -u.get = function(a, b, c, d, e, f) { +v.get = function(a, b, c, d, e, f) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; e = void 0 === e ? !0 : e; f = void 0 === f ? !1 : f; a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); var g = this; - return Z(a).then(function(h) { + return dc(a).then(function(h) { var k = []; if (!h || !h.length) { return k; @@ -3289,8 +3471,8 @@ u.get = function(a, b, c, d, e, f) { if (d >= m.length) { d -= m.length; } else { - for (var n = c ? d + Math.min(m.length - d, c) : m.length, p = d; p < n; p++) { - k.push(m[p]); + for (var p = c ? d + Math.min(m.length - d, c) : m.length, n = d; n < p; n++) { + k.push(m[n]); } d = 0; if (k.length === c) { @@ -3304,13 +3486,13 @@ u.get = function(a, b, c, d, e, f) { return h; }); }; -u.tag = function(a, b, c, d) { +v.tag = function(a, b, c, d) { b = void 0 === b ? 0 : b; c = void 0 === c ? 0 : c; d = void 0 === d ? !1 : d; a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); var e = this; - return Z(a).then(function(f) { + return dc(a).then(function(f) { if (!f || !f.length || c >= f.length) { return []; } @@ -3321,10 +3503,10 @@ u.tag = function(a, b, c, d) { return d ? e.enrich(f) : f; }); }; -u.enrich = function(a) { +v.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] = dc(b.get(a[d])); } return Promise.all(c).then(function(e) { for (var f = 0; f < e.length; f++) { @@ -3333,16 +3515,16 @@ u.enrich = function(a) { return e; }); }; -u.has = function(a) { +v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Z(a).then(function(b) { + return dc(a).then(function(b) { return !!b; }); }; -u.search = null; -u.info = function() { +v.search = null; +v.info = function() { }; -u.transaction = function(a, b, c) { +v.transaction = function(a, b, c) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; var d = this.h[a + ":" + b]; if (d) { @@ -3352,18 +3534,18 @@ u.transaction = function(a, b, c) { this.h[a + ":" + b] = d = e.objectStore(a); var f = c.call(this, d); this.h[a + ":" + b] = null; - return Z(e).finally(function() { + return dc(e).finally(function() { e = d = null; return f; }); }; -u.commit = function(a, b, c) { +v.commit = function(a, b, c) { var d = this, e, f, g; - return ta(function(h) { + return xa(function(h) { switch(h.h) { case 1: if (b) { - return E(h, d.clear(), 12); + return L(h, d.clear(), 12); } e = a.commit_task; a.commit_task = []; @@ -3380,7 +3562,7 @@ u.commit = function(a, b, c) { h.h = 5; break; } - return E(h, d.clear(), 8); + return L(h, d.clear(), 8); case 8: b = !0; h.h = 6; @@ -3394,12 +3576,12 @@ u.commit = function(a, b, c) { h.h = 3; break; } - c || (e = e.concat(ya(a.reg))); + c || (e = e.concat(Da(a.reg))); if (!e.length) { h.h = 10; break; } - return E(h, d.remove(e), 11); + return L(h, d.remove(e), 11); case 11: case 10: h.h = 3; @@ -3407,72 +3589,72 @@ u.commit = function(a, b, c) { case 12: a.commit_task = []; case 3: - return a.reg.size ? E(h, d.transaction("map", "readwrite", function(k) { - for (var l = y(a.map), m = l.next(), n = {}; !m.done; n = {O:void 0, Y:void 0}, m = l.next()) { - m = m.value, n.Y = m[0], n.O = m[1], n.O.length && (b ? k.put(n.O, n.Y) : k.get(n.Y).onsuccess = function(p) { + return a.reg.size ? L(h, d.transaction("map", "readwrite", function(k) { + for (var l = z(a.map), m = l.next(), p = {}; !m.done; p = {O:void 0, Y:void 0}, m = l.next()) { + m = m.value, p.Y = m[0], p.O = m[1], p.O.length && (b ? k.put(p.O, p.Y) : k.get(p.Y).onsuccess = function(n) { return function() { - var q = this.result, t; + var q = this.result, r; if (q && q.length) { - for (var v = Math.max(q.length, p.O.length), r = 0, z; r < v; r++) { - if ((z = p.O[r]) && z.length) { - if ((t = q[r]) && t.length) { - for (var A = 0; A < z.length; A++) { - t.push(z[A]); + for (var w = Math.max(q.length, n.O.length), u = 0, B; u < w; u++) { + if ((B = n.O[u]) && B.length) { + if ((r = q[u]) && r.length) { + for (var D = 0; D < B.length; D++) { + r.push(B[D]); } } else { - q[r] = z; + q[u] = B; } - t = 1; + r = 1; } } } else { - q = p.O, t = 1; + q = n.O, r = 1; } - t && k.put(q, p.Y); + r && k.put(q, n.Y); }; - }(n)); + }(p)); } }), 13) : h.return(); case 13: - return E(h, d.transaction("ctx", "readwrite", function(k) { - for (var l = y(a.ctx), m = l.next(), n = {}; !m.done; n = {V:void 0}, m = l.next()) { + return L(h, d.transaction("ctx", "readwrite", function(k) { + for (var l = z(a.ctx), m = l.next(), p = {}; !m.done; p = {V:void 0}, m = l.next()) { m = m.value; - n.V = m[0]; - m = y(m[1]); - for (var p = m.next(), q = {}; !p.done; q = {P:void 0, Z:void 0}, p = m.next()) { - p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? k.put(q.P, n.V + ":" + q.Z) : k.get(n.V + ":" + q.Z).onsuccess = function(t, v) { + p.V = m[0]; + m = z(m[1]); + for (var n = m.next(), q = {}; !n.done; q = {P:void 0, Z:void 0}, n = m.next()) { + n = n.value, q.Z = n[0], q.P = n[1], q.P.length && (b ? k.put(q.P, p.V + ":" + q.Z) : k.get(p.V + ":" + q.Z).onsuccess = function(r, w) { return function() { - var r = this.result, z; - if (r && r.length) { - for (var A = Math.max(r.length, t.P.length), w = 0, x; w < A; w++) { - if ((x = t.P[w]) && x.length) { - if ((z = r[w]) && z.length) { - for (var D = 0; D < x.length; D++) { - z.push(x[D]); + var u = this.result, B; + if (u && u.length) { + for (var D = Math.max(u.length, r.P.length), x = 0, A; x < D; x++) { + if ((A = r.P[x]) && A.length) { + if ((B = u[x]) && B.length) { + for (var t = 0; t < A.length; t++) { + B.push(A[t]); } } else { - r[w] = x; + u[x] = A; } - z = 1; + B = 1; } } } else { - r = t.P, z = 1; + u = r.P, B = 1; } - z && k.put(r, v.V + ":" + t.Z); + B && k.put(u, w.V + ":" + r.Z); }; - }(q, n)); + }(q, p)); } } }), 14); case 14: if (a.store) { - return E(h, d.transaction("reg", "readwrite", function(k) { - for (var l = y(a.store), m = l.next(); !m.done; m = l.next()) { - var n = m.value; - m = n[0]; - n = n[1]; - k.put("object" === typeof n ? JSON.stringify(n) : 1, m); + return L(h, d.transaction("reg", "readwrite", function(k) { + for (var l = z(a.store), m = l.next(); !m.done; m = l.next()) { + var p = m.value; + m = p[0]; + p = p[1]; + k.put("object" === typeof p ? JSON.stringify(p) : 1, m); } }), 16); } @@ -3480,8 +3662,8 @@ u.commit = function(a, b, c) { h.h = 16; break; } - return E(h, d.transaction("reg", "readwrite", function(k) { - for (var l = y(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { + return L(h, d.transaction("reg", "readwrite", function(k) { + for (var l = z(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { k.put(1, m.value); } }), 16); @@ -3490,15 +3672,15 @@ u.commit = function(a, b, c) { h.h = 20; break; } - return E(h, d.transaction("tag", "readwrite", function(k) { - for (var l = y(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) { - m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (k.get(n.ba).onsuccess = function(p) { + return L(h, d.transaction("tag", "readwrite", function(k) { + for (var l = z(a.tag), m = l.next(), p = {}; !m.done; p = {X:void 0, ba:void 0}, m = l.next()) { + m = m.value, p.ba = m[0], p.X = m[1], p.X.length && (k.get(p.ba).onsuccess = function(n) { return function() { var q = this.result; - q = q && q.length ? q.concat(p.X) : p.X; - k.put(q, p.ba); + q = q && q.length ? q.concat(n.X) : n.X; + k.put(q, n.ba); }; - }(n)); + }(p)); } }), 20); case 20: @@ -3506,7 +3688,7 @@ u.commit = function(a, b, c) { } }); }; -function Tb(a, b, c) { +function ec(a, b, c) { for (var d = a.value, e, f = 0, g = 0, h; g < d.length; g++) { if (h = c ? d : d[g]) { for (var k = 0, l; k < b.length; k++) { @@ -3528,22 +3710,22 @@ function Tb(a, b, c) { f ? e && a.update(d) : a.delete(); a.continue(); } -u.remove = function(a) { +v.remove = function(a) { "object" !== typeof a && (a = [a]); return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Tb(c, a); + c && ec(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Tb(c, a); + c && ec(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Tb(c, a, !0); + c && ec(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3551,7 +3733,7 @@ u.remove = function(a) { } })]); }; -function Z(a, b) { +function dc(a, b) { return new Promise(function(c, d) { a.onsuccess = a.oncomplete = function() { b && b(this.result); @@ -3562,8 +3744,8 @@ function Z(a, b) { a = null; }); } -;var Ub = {Index:O, Charset:Fb, Encoder:Ga, Document:V, Worker:Ra, Resolver:X, IndexedDB:Sb, Language:{}}, Vb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, Zb; -(Zb = Vb.define) && Zb.amd ? Zb([], function() { - return Ub; -}) : "object" === typeof Vb.exports ? Vb.exports = Ub : Vb.FlexSearch = Ub; +;var fc = {Index:U, Charset:Qb, Encoder:La, Document:ob, Worker:Xa, Resolver:X, IndexedDB:cc, Language:{}}, gc = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, hc; +(hc = gc.define) && hc.amd ? hc([], function() { + return fc; +}) : "object" === typeof gc.exports ? gc.exports = fc : gc.FlexSearch = fc; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index c36f8e5..fea2c39 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,134 +1,139 @@ /**! - * FlexSearch.js v0.8.158 (ES5) + * FlexSearch.js v0.8.160 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var u;function aa(a){var b=0;return function(){return b>>0)+"_",e=0;return b}); -C("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c>>0)+"_",e=0;return b}); +I("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;cc&&(c=Math.max(c+e,0));c"a1a".split(c).length; -this.numeric=G(a.numeric,e)}else{try{this.split=G(this.split,Ba)}catch(g){this.split=/\s+/}this.numeric=G(a.numeric,G(this.numeric,!0))}this.prepare=G(a.prepare,null,this.prepare);this.finalize=G(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:G(c&&new Set(c),null,this.filter);this.dedupe=G(a.dedupe,!0,this.dedupe);this.matcher=G((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=G((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=G((c=a.stemmer)&&new Map(c), -null,this.stemmer);this.replacer=G(a.replacer,null,this.replacer);this.minlength=G(a.minlength,1,this.minlength);this.maxlength=G(a.maxlength,1024,this.maxlength);this.rtl=G(a.rtl,!1,this.rtl);if(this.cache=c=G(a.cache,!0,this.cache))this.D=null,this.T="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.H=this.G=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(a=y(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value;if(this.stemmer)for(a=y(this.stemmer.keys()), -b=a.next();!b.done;b=a.next())this.A+=(this.A?"|":"")+b.value;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&K(this);return this};u.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; -u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&K(this);return this}; -u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&K(this);return this}; -u.encode=function(a,b){var c=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(K,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.maxlength)){if(b){if(g[m])continue;g[m]=1}else{if(f===m)continue;f=m}if(d)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.H)if(this.D){var p=this.C.get(m);if(p||""===p){p&&e.push(p);continue}}else this.D=setTimeout(K,50,this);if(this.stemmer)for(this.N||(this.N= -new RegExp("(?!^)("+this.A+")$")),p=void 0;p!==m&&2this.T&&(this.C.clear(),this.H=this.H/1.1|0));if(m){if(m!==n)if(b){if(g[m])continue;g[m]=1}else{if(h===m)continue;h=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.G&&(this.B.set(a,e),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return e};function K(a){a.D=null;a.B.clear();a.C.clear()};var Ha,Ia; -function Ja(a){var b,c,d,e,g,f;return ta(function(h){switch(h.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Ia=a.options||{};(e=a.factory)?(Function("return "+e)()(self),Ha=new self.FlexSearch.Index(Ia),delete self.FlexSearch):Ha=new M(Ia);postMessage({id:c});break;default:h.h=2;return}h.h=0;break;case 2:"export"===b&&(d[1]?(d[0]=Ia.export,d[2]=0,d[3]=1):d=null);if("import"===b){if(!d[0]){h.h=5;break}return E(h,Ia.import.call(Ha,d[0]),9)}g=d&&Ha[b].apply(Ha,d);if(!g||!g.then){h.h= -5;break}return E(h,g,7);case 7:g=h.D;h.h=5;break;case 9:f=h.D,Ha.import(d[0],f);case 5:postMessage("search"===b?{id:c,msg:g}:{id:c}),h.h=0}})};function Ka(a){La.call(a,"add");La.call(a,"append");La.call(a,"search");La.call(a,"update");La.call(a,"remove")}var Na,Oa,Pa;function Qa(){Na=Pa=0} -function La(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?Pa||(Pa=Date.now()-Oa>=this.priority*this.priority*3):(Na=setTimeout(Qa,0),Oa=Date.now());if(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}};var Ra=0; -function Sa(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[++Ra]=function(){k(e);1E9=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} -function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;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?V.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?V.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};W.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=Aa(a))return this.result=jb(a,b,c,d,f,this.h,g),g?e?V.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};W.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?V.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=V.call(this,a));return a}}function V(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)}; -X.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};X.prototype.remove=function(a){for(var b=y(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)}};X.prototype.clear=function(){this.cache.clear();this.h=""};var Ab={normalize:!1,numeric:!1,dedupe:!1};var Bb={};var Cb=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 Db=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Eb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Fb={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 Gb={Exact:Ab,Default:Bb,Normalize:Bb,LatinBalance:{mapper:Cb},LatinAdvanced:{mapper:Cb,matcher:Db,replacer:Eb},LatinExtra:{mapper:Cb,replacer:Eb.concat([/(?!^)[aeo]/g,""]),matcher:Db},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;be.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Hb(this.map,a),this.depth&&Hb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Ib(this));this.cache&&this.cache.remove(a);return this}; -function Hb(a,b){var c=0,d="undefined"===typeof b;if(a.constructor===Array)for(var e=0,g=void 0,f;en;r--)p=l.substring(n,r),q=this.rtl?m-1-n:n,q=this.score?this.score(b,l,k,p,q):Kb(h,e,k,m,q),Lb(this, -f,p,q,a,c);break}case "bidirectional":case "reverse":if(1p?0:1),e,k,r-1,q-1),t=this.bidirectional&& -l>n;Lb(this,g,t?n:l,v,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ca&&Ib(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 R(h);if(a.fastupdate)for(c=y(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};function M(a,b){if(!this||this.constructor!==M)return new M(a);if(a){var c=J(a)?a:a.preset;c&&(a=Object.assign({},Jb[c],a))}else a={};c=a.context;var d=!0===c?{depth:1}:c||{},e=J(a.encoder)?Gb[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new Ga(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&d.depth||0;this.bidirectional=!1!==d.bidirectional;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new S(c):new Map;this.ctx=c?new S(c):new Map;this.reg=b||(this.fastupdate?c?new S(c):new Map:c?new T(c):new Set);this.da=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new X(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.ca=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}u=M.prototype; -u.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};u.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};u.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function Ib(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} -u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};u.update=function(a,b){var c=this,d=this.remove(a);return d&&d.then?d.then(function(){return c.add(a,b)}):this.add(a,b)}; -u.cleanup=function(){if(!this.fastupdate)return this;Hb(this.map);this.depth&&Hb(this.ctx);return this};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 g=Ya(this.reg);break;case 1:e="cfg";g=null;break;case 2:e="map";g=Ua(this.map,this.reg.size);break;case 3:e="ctx";g=Wa(this.ctx,this.reg.size);break;default:return}return $a.call(this,a,b,e,g,c,d)}; -u.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=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;dc&&(c=Math.max(c+e,0));c"a1a".split(c).length; +this.numeric=O(a.numeric,e)}else{try{this.split=O(this.split,Ga)}catch(f){this.split=/\s+/}this.numeric=O(a.numeric,O(this.numeric,!0))}this.prepare=O(a.prepare,null,this.prepare);this.finalize=O(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:O(c&&new Set(c),null,this.filter);this.dedupe=O(a.dedupe,!0,this.dedupe);this.matcher=O((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=O((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=O((c=a.stemmer)&&new Map(c), +null,this.stemmer);this.replacer=O(a.replacer,null,this.replacer);this.minlength=O(a.minlength,1,this.minlength);this.maxlength=O(a.maxlength,1024,this.maxlength);this.rtl=O(a.rtl,!1,this.rtl);if(this.cache=c=O(a.cache,!0,this.cache))this.D=null,this.T="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.H=this.G=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(a=z(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value;if(this.stemmer)for(a=z(this.stemmer.keys()), +b=a.next();!b.done;b=a.next())this.A+=(this.A?"|":"")+b.value;return this};v.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&Ma(this);return this};v.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&Ma(this);return this}; +v.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&Ma(this);return this}; +v.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&Ma(this);return this}; +v.encode=function(a,b){var c=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(Ma,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=Ka?a.normalize("NFKD").replace(Ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(f[m])continue;f[m]=1}else{if(g===m)continue;g=m}if(d)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.H)if(this.D){var p=this.C.get(m);if(p||""===p){p&&e.push(p);continue}}else this.D=setTimeout(Ma,50,this);if(this.stemmer)for(this.N|| +(this.N=new RegExp("(?!^)("+this.A+")$")),p=void 0;p!==m&&2this.T&&(this.C.clear(),this.H=this.H/1.1|0));if(m){if(m!==n)if(b){if(f[m])continue;f[m]=1}else{if(h===m)continue;h=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.G&&(this.B.set(a,e),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return e};function Ma(a){a.D=null;a.B.clear();a.C.clear()};var Na,Oa; +function Pa(a){var b,c,d,e,f,g;return xa(function(h){switch(h.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Oa=a.options||{};(e=a.factory)?(Function("return "+e)()(self),Na=new self.FlexSearch.Index(Oa),delete self.FlexSearch):Na=new U(Oa);postMessage({id:c});break;default:h.h=2;return}h.h=0;break;case 2:"export"===b&&(d[1]?(d[0]=Oa.export,d[2]=0,d[3]=1):d=null);if("import"===b){if(!d[0]){h.h=5;break}return L(h,Oa.import.call(Na,d[0]),9)}f=d&&Na[b].apply(Na,d);if(!f||!f.then){h.h= +5;break}return L(h,f,7);case 7:f=h.D;h.h=5;break;case 9:g=h.D,Na.import(d[0],g);case 5:postMessage("search"===b?{id:c,msg:f}:{id:c}),h.h=0}})};function Qa(a){Ra.call(a,"add");Ra.call(a,"append");Ra.call(a,"search");Ra.call(a,"update");Ra.call(a,"remove")}var Sa,Ta,Ua;function Va(){Sa=Ua=0} +function Ra(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]}Sa?Ua||(Ua=Date.now()-Ta>=this.priority*this.priority*3):(Sa=setTimeout(Va,0),Ta=Date.now());if(Ua){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}};var Wa=0; +function Xa(a){function b(g){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.h=Q();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Wa]=function(){k(e);1E9=g.length)b-=g.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)break;b=0}return e} +function ib(a){if(!this||this.constructor!==ib)return new ib(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 f=0,g=0,h,k;gc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+ +d)}else{e=[];for(f=0;fd)d-=g.length;else{if(g.length>c||d)g=g.slice(d,c+d),c-=g.length,d&&(d-=g.length);e.push(g);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?vb.call(this,a):a;for(var e=[],f=0,g=void 0,h=void 0;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!e.length&&h>=b)return d?vb.call(this,g):g;e.push(g);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=sb(a,c,d,!1,this.h),d=0));return f?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 f=b.enrich&&c}}return a?(a=wb(this,"and",arguments),yb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,f):this}; +function yb(a,b,c,d,e,f,g){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=Fa(a))return this.result=rb(a,b,c,d,g,this.h,f),f?e?vb.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,d,e):this};X.prototype.xor=function(){var a=wb(this,"xor",arguments);return zb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; +function zb(a,b,c,d,e,f,g){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=Ab.call(this,a,c,d,f,this.h),f?e?vb.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,d,e):this} +function Ab(a,b,c,d,e){for(var f=[],g=Q(),h=0,k=0,l;kG&&(G=t.length+(t?1:0)),N=t.length+(t?1:0)+aa.length,S+=Y,fa.push(C.length),C.push({match:aa})),t+=(t?" ":"")+aa)}if(!P)J=D[F],t+=(t?" ":"")+J,k&&C.push({text:J});else if(k&&S>=k)break}S=fa.length*(f.length-2);if(q||r||k&&t.length-S>k)if(S=k+S-2*p,F=N-G,0D&&(D=0)),C=C.length-1){if(K>=C.length){F[y+1]=1;K>=D.length&&(G[y+1]=1);continue}P-=p}t=C[K].text;var T=r&&M[y]; +if(T)if(0T)if(F[y+1]=1,l)t=t.substring(0,T);else continue;(T-=t.length)||(T=-1);M[y]=T}else{F[y+1]=1;continue}if(P+t.length+1<=k)t=" "+t,N[y]+=t;else if(l)H=k-P-1,0=K){if(0>K){F[y]=1;G[y]=1;continue}P-=p}t=C[K].text;if(T=q&&J[y])if(0T)if(F[y]=1,l)t=t.substring(t.length-T);else continue;(T-=t.length)||(T=-1);J[y]=T}else{F[y]=1;continue}if(P+ +t.length+1<=k)t+=" ",N[y]=t+N[y];else if(l)H=t.length+1-(k-P),0<=H&&H=D.length-1?H=1:Kc||d)a=a.slice(d,d+c);e&&(a=vb.call(this,a));return a}} +function vb(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)}; +Hb.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};Hb.prototype.remove=function(a){for(var b=z(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)}};Hb.prototype.clear=function(){this.cache.clear();this.h=""};var Kb={normalize:!1,numeric:!1,dedupe:!1};var Lb={};var Mb=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 Nb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ob=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Pb={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 Qb={Exact:Kb,Default:Lb,Normalize:Lb,LatinBalance:{mapper:Mb},LatinAdvanced:{mapper:Mb,matcher:Nb,replacer:Ob},LatinExtra:{mapper:Mb,replacer:Ob.concat([/(?!^)[aeo]/g,""]),matcher:Nb},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;be.length)e.pop();else{var f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,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&&Sb(this));this.cache&&this.cache.remove(a);return this}; +function Rb(a,b){var c=0,d="undefined"===typeof b;if(a.constructor===Array)for(var e=0,f=void 0,g;en;r--)p=l.substring(n,r),q=this.rtl?m-1-n:n,q=this.score?this.score(b,l,k,p,q):Ub(h,e,k,m,q),Vb(this, +g,p,q,a,c);break}case "bidirectional":case "reverse":if(1p?0:1),e,k,r-1,q-1),u=this.bidirectional&& +l>n;Vb(this,f,u?n:l,w,a,c,u?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ca&&Sb(this));return this}; +function Vb(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]=Q()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new ib(h);if(a.fastupdate)for(c=z(a.reg.values()),f=c.next();!f.done;f=c.next())f=f.value,f.includes(h)&&(f[f.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 Ub(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,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function U(a,b){if(!this||this.constructor!==U)return new U(a);if(a){var c=R(a)?a:a.preset;c&&(a=Object.assign({},Tb[c],a))}else a={};c=a.context;var d=!0===c?{depth:1}:c||{},e=R(a.encoder)?Qb[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new La(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&d.depth||0;this.bidirectional=!1!==d.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new V(c):new Map;this.ctx=c?new V(c):new Map;this.reg=b||(this.fastupdate?c?new V(c):new Map:c?new W(c):new Set);this.da=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new Hb(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.ca=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}v=U.prototype; +v.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};v.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};v.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function Sb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} +v.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};v.append=function(a,b){return this.add(a,b,!0)};v.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};v.update=function(a,b){var c=this,d=this.remove(a);return d&&d.then?d.then(function(){return c.add(a,b)}):this.add(a,b)}; +v.cleanup=function(){if(!this.fastupdate)return this;Rb(this.map);this.depth&&Rb(this.ctx);return this};v.searchCache=Jb;v.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=db(this.reg);break;case 1:e="cfg";f=null;break;case 2:e="map";f=$a(this.map,this.reg.size);break;case 3:e="ctx";f=bb(this.ctx,this.reg.size);break;default:return}return fb.call(this,a,b,e,f,c,d)}; +v.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c): +m.length,p=d;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; +v.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d} index + * @param {string} pluck + * @param {HighlightOptions|string} config + * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} + */ +export function highlight_fields(query, result, index, pluck, config) { + + // The biggest issue is dealing with custom encoders, for this reason + // a combined regular expression can't apply as a template + + let template, markup_open, markup_close; + + if ("string" == typeof config) { + template = config; + config = ""; + } else { + template = config.template; + } + + if (!template) { + throw new Error('No template pattern was specified by the search option "highlight"'); + } + + + markup_open = template.indexOf("$1"); + + if (-1 === markup_open) { + throw new Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + template); + } + + + markup_close = template.substring(markup_open + 2); + markup_open = template.substring(0, markup_open); + + let boundary = config && config.boundary, + clip = !config || /* suggest */ /* append: */!1 !== config.clip, + merge = config && config.merge && markup_close && markup_open && new RegExp(markup_close + " " + markup_open, "g"), + ellipsis = config && config.ellipsis, + ellipsis_markup_length = 0, + ellipsis_markup; + + if ("object" == typeof ellipsis) { + ellipsis_markup = ellipsis.template; + ellipsis_markup_length = ellipsis_markup.length - 2; + ellipsis = ellipsis.pattern; + } + if ("string" != typeof ellipsis) { + ellipsis = !1 === ellipsis ? "" : "..."; + } + if (ellipsis_markup_length) { + ellipsis = ellipsis_markup.replace("$1", ellipsis); + } + + let ellipsis_length = ellipsis.length - ellipsis_markup_length, + boundary_before, + boundary_after; + + + if ("object" == typeof boundary) { + boundary_before = boundary.before; + if (0 === boundary_before) boundary_before = -1; + boundary_after = boundary.after; + if (0 === boundary_after) boundary_after = -1; + boundary = boundary.total || 9e5; + } + + // cache shared encoders across fields + let encoder = new Map(), + query_enc; + + + // todo remove this loop and pass in the field data directly + // todo support field-specific configuration + + // for every field + for (let i = 0, enc, idx, path; i < result.length; i++) { + + /** @type {EnrichedSearchResults} */ + let res; + + if (pluck) { + res = result; + path = pluck; + } else { + const tmp = result[i]; + path = tmp.field; + // skip when not a field entry (e.g. tags) + if (!path) continue; + res = tmp.result; + } + + idx = index.get(path); + enc = idx.encoder; + idx.tokenize; + query_enc = encoder.get(enc); + + // re-encode query when encoder has changed or take cache from shared encoders + if ("string" != typeof query_enc) { + query_enc = enc.encode(query); + encoder.set(enc, query_enc); + } + + // for every doc in results + for (let j = 0; j < res.length; j++) { + + const doc = res[j].doc; + if (!doc) continue; + const content = parse_simple(doc, path); + if (!content) continue; + // just split on whitespace and keep original string (encoder split can't apply) + const doc_org = content.trim().split(/\s+/); + if (!doc_org.length) continue; + + let str = "", + str_arr = [], + pos_matches = [], + pos_first_match = -1, + pos_last_match = -1, + length_matches_all = 0; + + + // loop terms of encoded doc content + for (let k = 0; k < doc_org.length; k++) { + let doc_org_cur = doc_org[k], + doc_enc_cur = enc.encode(doc_org_cur); + + doc_enc_cur = 1 < doc_enc_cur.length ? doc_enc_cur.join(" ") : doc_enc_cur[0]; + + let found; + + if (doc_enc_cur && doc_org_cur) { + let doc_org_cur_len = doc_org_cur.length, + doc_org_diff = (enc.split ? doc_org_cur.replace(enc.split, "") : doc_org_cur).length - doc_enc_cur.length, + match = "", + match_length = 0; + + + // loop terms of encoded query content and determine the longest match + for (let l = 0, query_enc_cur; l < query_enc.length; l++) { + query_enc_cur = query_enc[l]; + + if (!query_enc_cur) continue; + let query_enc_cur_len = query_enc_cur.length; + // add length from shrinking phonetic transformations (todo: add tests) + query_enc_cur_len += doc_org_diff; + // skip query token when match length can't exceed previously highest found match + if (match_length && query_enc_cur_len <= match_length) { + continue; + } + const position = doc_enc_cur.indexOf(query_enc_cur); + if (-1 < position) { + match = + // prefix + (position ? doc_org_cur.substring(0, position) : "") + + // match + markup_open + doc_org_cur.substring(position, position + query_enc_cur_len) + markup_close + ( + // suffix + position + query_enc_cur_len < doc_org_cur_len ? doc_org_cur.substring(position + query_enc_cur_len) : ""); + match_length = query_enc_cur_len; + found = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; + } + //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position, match) + } + + // apply the longest match + if (match) { + if (boundary) { + // the outer boundary is used to check if all matches are within the total boundary + // if so, it can apply a simpler alignment + if (0 > pos_first_match) { + pos_first_match = str.length + (str ? 1 : 0); + } + pos_last_match = str.length + (str ? 1 : 0) + match.length; + // the overall length of all matches is used to check if matches exceeds the total boundary + // if so, it can early stop further processing + length_matches_all += doc_org_cur_len; + // the match positions are used to pick items for the final result more quickly + pos_matches.push(str_arr.length); + // collect every term as match or text + str_arr.push({ match }); + } + str += (str ? " " : "") + match; + } + } + + if (!found) { + const text = doc_org[k]; + str += (str ? " " : "") + text; + // collect every term as match or text + boundary && str_arr.push({ text }); + } else if (boundary) { + if (length_matches_all >= boundary) { + // matches has reached total boundary + break; + } + } + } + + // the markup length does not apply to the total boundary + let markup_length = pos_matches.length * (template.length - 2); + + // apply boundaries and align highlights + if (boundary_before || boundary_after || boundary && str.length - markup_length > boundary) { + + // also reduce ellipsis length from boundary + let boundary_length = boundary + markup_length - 2 * ellipsis_length, + length = pos_last_match - pos_first_match, + start, + end; + + + if (0 < boundary_before) { + length += boundary_before; + } + if (0 < boundary_after) { + length += boundary_after; + } + + // 1. all matches are withing the overall boundary (apply simple alignment) + if (length <= boundary_length) { + + start = boundary_before ? pos_first_match - (0 < boundary_before ? boundary_before : 0) : pos_first_match - (0 | (boundary_length - length) / 2); + end = boundary_after ? pos_last_match + (0 < boundary_after ? boundary_after : 0) : start + boundary_length; + + // do not clip terms + if (!clip) { + if (0 < start) { + if (" " === str.charAt(start)) {} else if (" " !== str.charAt(start - 1)) { + start = str.indexOf(" ", start); + 0 > start && (start = 0); + } + } + if (end < str.length) { + if (" " === str.charAt(end - 1)) {} else if (" " !== str.charAt(end)) { + end = str.lastIndexOf(" ", end); + end < pos_last_match ? end = pos_last_match : ++end; + } + } + } + + str = (start ? ellipsis : "") + str.substring(start, end) + (end < str.length ? ellipsis : ""); + } + // 2. matches needs to be split by surrounded terms to fit into the boundary + else { + const final = [], + check = {}, + seamless = {}, + finished = {}, + before = {}, + after = {}; + let final_length = 0, + shift_left = 0, + shift_right = 0, + loop_left = 1, + loop_right = 1; + + + while (!0) { + + let loop; + + for (let k = 0, pos; k < pos_matches.length; k++) { + + pos = pos_matches[k]; + + // 1. add matches to the result + if (!shift_right) { + str = str_arr[pos].match; + + // initialize custom boundaries for each slot + if (boundary_before) { + before[k] = boundary_before; + } + if (boundary_after) { + after[k] = boundary_after; + } + + // count whitespaces between each term + if (k) { + final_length++; + } + + let close; + + // close left side when first term was matched + if (!pos) { + // it can be set before content was added, + // because the first term match is always added + seamless[k] = 1; + finished[k] = 1; + } + // initial ellipsis + else if (!k && ellipsis_length) { + final_length += ellipsis_length; + } + + // close right side when last term was matched + if (pos >= doc_org.length - 1) { + close = 1; + } + // close right side when next term was a match + else if (pos < str_arr.length - 1 && str_arr[pos + 1].match) { + close = 1; + } else if (ellipsis_length) { + final_length += ellipsis_length; + } + + // reduce template length on matches + final_length -= template.length - 2; + + // at least add one match + if (!k || final_length + str.length <= boundary) { + final[k] = str; + } else { + seamless[k] = 0; + loop = loop_left = loop_right = 0; + break; + } + + // update state when term was added + if (close) { + seamless[k + 1] = 1; + finished[k + 1] = 1; + } + } + // 2. add surrounded text to the result + else { + // alternate direction term by term + // 2.1. extend to right first (index: k + 1) + if (shift_left != shift_right) { + if (finished[k + 1]) continue; + pos += shift_right; + + // overlap with other slot + if (check[pos]) { + final_length -= ellipsis_length; + seamless[k + 1] = 1; + finished[k + 1] = 1; + continue; + } + // end reached + if (pos >= str_arr.length - 1) { + if (pos >= str_arr.length) { + finished[k + 1] = 1; + if (pos >= doc_org.length) { + seamless[k + 1] = 1; + } + continue; + } + final_length -= ellipsis_length; + } + + str = str_arr[pos].text; + + let current_after = boundary_after && after[k]; + if (current_after) { + if (0 < current_after) { + if (str.length > current_after) { + finished[k + 1] = 1; + if (clip) { + str = str.substring(0, current_after); + } else { + continue; + } + } + current_after -= str.length; + if (!current_after) current_after = -1; + after[k] = current_after; + } else { + finished[k + 1] = 1; + continue; + } + } + + // count whitespaces between each term + if (final_length + str.length + 1 <= boundary) { + str = " " + str; + final[k] += str; + } else if (clip) { + const diff = boundary - final_length - 1; + if (0 < diff) { + str = " " + str.substring(0, diff); + final[k] += str; + } + finished[k + 1] = 1; + } else { + finished[k + 1] = 1; + continue; + } + } + // 2.2. extend to left (index: k) + else { + if (finished[k]) continue; + pos -= shift_left; + + // overlap with other slot + if (check[pos]) { + final_length -= ellipsis_length; + finished[k] = 1; + seamless[k] = 1; + continue; + } + // start reached + if (0 >= pos) { + if (0 > pos) { + finished[k] = 1; + seamless[k] = 1; + continue; + } + final_length -= ellipsis_length; + } + + str = str_arr[pos].text; + + let current_before = boundary_before && before[k]; + if (current_before) { + if (0 < current_before) { + if (str.length > current_before) { + finished[k] = 1; + if (clip) { + str = str.substring(str.length - current_before); + } else { + continue; + } + } + current_before -= str.length; + if (!current_before) current_before = -1; + before[k] = current_before; + } else { + finished[k] = 1; + continue; + } + } + + // count whitespaces between each term + if (final_length + str.length + 1 <= boundary) { + str += " "; + final[k] = str + final[k]; + } else if (clip) { + const diff = str.length + 1 - (boundary - final_length); + if (0 <= diff && diff < str.length) { + str = str.substring(diff) + " "; + final[k] = str + final[k]; + } + finished[k] = 1; + } else { + finished[k] = 1; + continue; + } + } + } + + // update state when term was added + final_length += str.length; + check[pos] = 1; + loop = 1; + } + + if (loop) { + // alternate shift direction + shift_left == shift_right ? shift_right++ : shift_left++; + } else { + // check finish state + shift_left == shift_right ? loop_left = 0 : loop_right = 0; + // break process when both directions are done + if (!loop_left && !loop_right) { + break; + } + // continue with opposite direction + if (loop_left) { + shift_left++; + shift_right = shift_left; + } else { + shift_right++; + } + } + } + + str = ""; + for (let k = 0, tmp; k < final.length; k++) { + tmp = (k && seamless[k] ? " " : (k && !ellipsis ? " " : "") + ellipsis) + final[k]; + str += tmp; + } + if (ellipsis && !seamless[final.length]) { + str += ellipsis; + } + //console.log(query, seamless, final) + } + } + + if (merge) { + str = str.replace( /** @type {RegExp} */merge, " "); + } + + res[j].highlight = str; + } + + if (pluck) { + break; + } + } + + return result; +} + +// /** +// * @param {string} query +// * @param {EnrichedDocumentSearchResults|EnrichedSearchResults} result +// * @param {Map} index +// * @param {string} pluck +// * @param {HighlightOptions|string} config +// * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} +// */ +// export function highlight_fields(query, result, index, pluck, config){ +// +// // The biggest issue is dealing with custom encoders, for this reason +// // a combined regular expression can't apply as a template +// +// let template, markup_open, markup_close; +// +// if(typeof config === "string"){ +// template = config; +// config = ""; +// } +// else{ +// template = config.template; +// } +// +// if(DEBUG){ +// if(!template){ +// throw new Error('No template pattern was specified by the search option "highlight"'); +// } +// } +// +// markup_open = template.indexOf("$1"); +// +// if(DEBUG){ +// if(markup_open === -1){ +// throw new Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + template); +// } +// } +// +// markup_close = template.substring(markup_open + 2); +// markup_open = template.substring(0, markup_open); +// +// let boundary = config && config.boundary; +// let clip = !config || config.clip !== false; +// let merge = config && config.merge && markup_close && markup_open && new RegExp(markup_close + " " + markup_open, "g"); +// let ellipsis = config && config.ellipsis; +// if(typeof ellipsis !== "string"){ +// ellipsis = "..."; +// } +// +// let boundary_before, boundary_after; +// +// if(typeof boundary === "object"){ +// boundary_before = boundary.before; +// if(boundary_before === 0) boundary_before = -1; +// boundary_after = boundary.after; +// if(boundary_after === 0) boundary_after = -1; +// boundary = boundary.total || 9e5; +// } +// +// // cache shared encoders across fields +// let encoder = new Map(); +// let query_enc; +// let tokenize; +// +// // todo remove this loop and pass in the field data directly +// // todo support field-specific configuration +// +// // for every field +// for(let i = 0, enc, idx, path; i < result.length; i++){ +// +// /** @type {EnrichedSearchResults} */ +// let res; +// +// if(pluck){ +// res = result; +// path = pluck; +// } +// else{ +// const tmp = result[i]; +// path = tmp.field; +// // skip when not a field entry (e.g. tags) +// if(!path) continue; +// res = tmp.result; +// } +// +// idx = index.get(path); +// enc = idx.encoder; +// tokenize = idx.tokenize; +// query_enc = encoder.get(enc); +// +// // re-encode query when encoder has changed or take cache from shared encoders +// if(typeof query_enc !== "string"){ +// query_enc = enc.encode(query); +// encoder.set(enc, query_enc); +// } +// +// // for every doc in results +// for(let j = 0; j < res.length; j++){ +// +// const doc = res[j]["doc"]; +// if(!doc) continue; +// const content = parse_simple(doc, path); +// if(!content) continue; +// const doc_org = content.trim().split(/\s+/); +// if(!doc_org.length) continue; +// +// let str = ""; +// let pos_matches = []; +// let length_matches_all = 0; +// +// // loop terms of encoded doc content +// for(let k = 0; k < doc_org.length; k++){ +// let doc_org_cur = doc_org[k]; +// let doc_org_cur_len = doc_org_cur.length; +// let doc_enc_cur = enc.encode(doc_org_cur); +// doc_enc_cur = doc_enc_cur.length > 1 +// ? doc_enc_cur.join(" ") +// : doc_enc_cur[0]; +// +// let found; +// +// if(doc_enc_cur && doc_org_cur){ +// +// let match = ""; +// let match_length = 0; +// +// // loop terms of encoded query content and determine the longest match +// for(let l = 0; l < query_enc.length; l++){ +// let query_enc_cur = query_enc[l]; +// if(!query_enc_cur) continue; +// let query_enc_cur_len = query_enc_cur.length; +// // add length from shrinking phonetic transformations (todo: add tests) +// query_enc_cur_len += doc_org_cur.length - doc_enc_cur.length; +// // skip query token when match length can't exceed previously highest found match +// if(match_length && query_enc_cur_len <= match_length){ +// continue; +// } +// const position = doc_enc_cur.indexOf(query_enc_cur); +// //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position) +// if(position > -1){ +// match = +// // prefix +// (position ? doc_org_cur.substring(0, position) : "") + +// // match +// markup_open + doc_org_cur.substring(position, position + query_enc_cur_len) + markup_close + +// // suffix +// (position + query_enc_cur_len < doc_org_cur_len ? doc_org_cur.substring(position + query_enc_cur_len) : ""); +// match_length = query_enc_cur_len; +// found = true; +// } +// } +// +// // apply the longest match +// if(match){ +// if(boundary){ +// if(!pos_matches.length && k) length_matches_all += ellipsis.length; +// // the overall length of all matches is used to check if matches exceeds the total boundary +// // if so, it can early stop further processing +// length_matches_all += match.length;//doc_org_cur_len + (str ? 1 : 0) + (k < doc_org.length - 1 ? ellipsis.length : 0); +// // the match positions are used to pick items for the final result more quickly +// pos_matches.push([ +// str.length + (str ? 1 : 0), +// str.length + (str ? 1 : 0) + match.length, +// k +// ]); +// } +// str += (str ? " " : "") + match; +// } +// } +// +// if(!found){ +// const text = doc_org[k]; +// str += (str ? " " : "") + text; +// } +// else if(boundary){ +// if(length_matches_all >= boundary){ +// // matches has reached total boundary +// break; +// } +// } +// } +// +// // the markup length does not apply to the total boundary +// let markup_length = pos_matches.length * (template.length - 2); +// +// // apply boundaries and align highlights +// if(boundary_before || boundary_after || (boundary && (str.length - markup_length) > boundary)){ +// +// let final = ""; +// let surrounded_length = (((((boundary + markup_length) - length_matches_all) / pos_matches.length) - ellipsis.length) / 2); +// //if(surrounded_length < 0) surrounded_length = 0; +// +// let before = boundary_before || ( +// surrounded_length > 0 +// ? Math.floor(surrounded_length + +// (boundary_after +// ? surrounded_length - boundary_after +// : 0)) +// : 0 +// ); +// let after = boundary_after || ( +// surrounded_length > 0 +// ? Math.ceil(surrounded_length + +// (boundary_before +// ? surrounded_length - boundary_before +// : 0)) +// : 0 +// ); +// +// //console.log(surrounded_length, before, after) +// +// for(let k = 0, cur, prev, next; k < pos_matches.length; k++){ +// +// prev = cur; +// cur = next || pos_matches[k]; +// next = pos_matches[k + 1]; +// +// let start = cur[0] - before; +// let end = cur[1] + after; +// let closed_left; +// let closed_right; +// +// // if(k){ +// // closed_left = 1; +// // } +// +// // apply right limit +// if(next && (end >= next[0] - before)){ +// end = cur[1] + (next[0] - cur[1]) / 2 | 0; +// start -= ellipsis.length + 1; +// closed_right = 1; +// } +// // apply left limit +// if(prev && (start <= prev[1] + after)){ +// start = cur[0] - (cur[0] - prev[1]) / 2 | 0; +// end += ellipsis.length + 1; +// closed_left = 1; +// +// // repeat right limit +// if(next && (end >= next[0] - before)){ +// end = cur[1] + (next[0] - cur[1]) / 2 | 0; +// closed_right = 1; +// } +// } +// +// //console.log(start, end, prev, cur, next); +// +// // do not clip terms +// if(!clip){ +// if(start){ +// if(str.charAt(start) === " "){ +// //start++; +// } +// else if(str.charAt(start - 1) !== " "){ +// start = str.indexOf(" ", start); +// start < 0 +// ? start = cur[0] +// : start;//++; +// } +// } +// if(end < str.length){ +// if(str.charAt(end - 1) === " "){ +// //end--; +// } +// else if(str.charAt(end) !== " "){ +// end = str.lastIndexOf(" ", end); +// end < cur[1] +// ? end = cur[1] +// : end++; +// } +// } +// } +// +// final += +// /*(final ? " " : "") +*/ +// (!closed_left && start > 0 ? ellipsis : "") + +// str.substring(start, end) + +// (!closed_right && cur[2] < doc_org.length - 1 ? ellipsis : ""); +// +// //console.log(final) +// } +// +// str = final; +// } +// +// if(merge){ +// str = str.replace(merge, " "); +// } +// +// res[j]["highlight"] = str; +// } +// +// if(pluck){ +// break; +// } +// } +// +// return result; +// } \ No newline at end of file diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index 8ca49a4..2042b57 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -1,11 +1,12 @@ import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults, MergedDocumentSearchEntry, EnrichedSearchResults, SearchResults, IntermediateSearchResults } from "../type.js"; -import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; +import { create_object, is_array, is_object, is_string } from "../common.js"; import { intersect_union } from "../intersect.js"; import Document from "../document.js"; import Index from "../index.js"; import Resolver from "../resolver.js"; import tick from "../profiler.js"; +import { highlight_fields } from "./highlight.js"; /** * @param {!string|DocumentSearchOptions} query @@ -62,7 +63,8 @@ Document.prototype.search = function (query, limit, options, _promises) { tag, offset, count = 0, - resolve = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, + resolve = /* tag? */ /* stringify */ /* stringify */ + /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, highlight; @@ -105,8 +107,8 @@ Document.prototype.search = function (query, limit, options, _promises) { } - enrich = this.store && options.enrich && resolve; - highlight = enrich && options.highlight; + highlight = resolve && this.store && options.highlight; + enrich = highlight || resolve && this.store && options.enrich; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -237,6 +239,7 @@ Document.prototype.search = function (query, limit, options, _promises) { offset = field_options.offset || offset; suggest = field_options.suggest || suggest; enrich = this.store && (field_options.enrich || enrich); + highlight = enrich && (options.highlight || highlight); } if (_promises) { @@ -430,120 +433,6 @@ Document.prototype.search = function (query, limit, options, _promises) { return merge ? merge_fields(result) : highlight ? highlight_fields( /** @type {string} */query, result, this.index, pluck, highlight) : /** @type {DocumentSearchResults} */result; }; -/** - * @param {string} query - * @param {EnrichedDocumentSearchResults|EnrichedSearchResults} result - * @param {Map} index - * @param {string} pluck - * @param {string} template - * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} - */ -function highlight_fields(query, result, index, pluck, template) { - - // The biggest issue is dealing with custom encoders, for this reason - // a regular expression can't apply - // Todo: when one of the basic encoders was used, provide - // combined regex - // - // if(typeof template === "string"){ - // template = new RegExp(template, "g"); - // } - - let encoder, query_enc, tokenize; - - - // for every field - for (let i = 0, enc, idx, path; i < result.length; i++) { - - /** @type {EnrichedSearchResults} */ - let res; - - if (pluck) { - res = result; - path = pluck; - } else { - const tmp = result[i]; - path = tmp.field; - if (!path) continue; - res = tmp.result; - } - - // skip when not a field entry (e.g. tags) - - idx = index.get(path); - enc = idx.encoder; - tokenize = idx.tokenize; - - // re-encode query when encoder has changed - if (enc !== encoder) { - encoder = enc; - query_enc = encoder.encode(query); - } - - // for every doc in results - for (let j = 0; j < res.length; j++) { - let str = "", - content = parse_simple(res[j].doc, path), - doc_org = content.split(/\s+/); - //let doc_enc = encoder.encode(content); - - // loop terms of encoded doc content - for (let k = 0, doc_org_cur, doc_enc_cur; k < doc_org.length; k++) { - doc_org_cur = doc_org[k]; - //doc_enc_cur = doc_enc[k]; - doc_enc_cur = enc.encode(doc_org_cur); - doc_enc_cur = 1 < doc_enc_cur.length ? doc_enc_cur.join(" ") : doc_enc_cur[0]; - - let found; - - if (doc_enc_cur && doc_org_cur) { - - // loop terms of encoded query content - for (let l = 0, query_enc_cur; l < query_enc.length; l++) { - query_enc_cur = query_enc[l]; - // todo tokenize could be custom also when "strict" was used - if ("strict" === tokenize) { - if (doc_enc_cur === query_enc_cur) { - str += (str ? " " : "") + template.replace("$1", doc_org_cur); - found = !0; - break; - } - } else { - const position = doc_enc_cur.indexOf(query_enc_cur); - //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position) - if (-1 < position) { - str += (str ? " " : "") + - // prefix - doc_org_cur.substring(0, position) + - // match - template.replace("$1", doc_org_cur.substring(position, position + query_enc_cur.length)) + - // suffix - doc_org_cur.substring(position + query_enc_cur.length); - found = !0; - break; - } - } - - //str += doc_enc[k].replace(new RegExp("(" + doc_enc[k] + ")", "g"), template.replace("$1", content)) - } - } - - if (!found) { - str += (str ? " " : "") + doc_org[k]; - } - } - - res[j].highlight = str; - } - - if (pluck) { - break; - } - } - - return result; -} - // todo support Resolver // todo when searching through multiple fields each term should // be found at least by one field to get a valid match without diff --git a/dist/module-debug/type.js b/dist/module-debug/type.js index 768bbc8..f2c0217 100644 --- a/dist/module-debug/type.js +++ b/dist/module-debug/type.js @@ -142,7 +142,7 @@ export let SearchOptions = {}; * index: (Array|Array|DocumentSearchOptions|string|undefined), * pluck: (string|DocumentSearchOptions|undefined), * merge: (boolean|undefined), - * highlight: (string|undefined) + * highlight: (HighlightOptions|string|undefined) * }} */ export let DocumentSearchOptions = {}; @@ -261,4 +261,32 @@ export let PersistentOptions = {}; * not: (ResolverOptions|Array|undefined) * }} */ -export let ResolverOptions = {}; \ No newline at end of file +export let ResolverOptions = {}; + +/** + * @typedef {{ + * before: (number|undefined), + * after: (number|undefined), + * total: (number|undefined) + * }} + */ +export let HighlightBoundaryOptions = {}; + +/** + * @typedef {{ + * template: string, + * pattern: (string|boolean|undefined) + * }} + */ +export let HighlightEllipsisOptions = {}; + +/** + * @typedef {{ + * template: string, + * boundary: (HighlightBoundaryOptions|number|undefined), + * clip: (boolean|undefined), + * merge: (boolean|undefined), + * ellipsis: (HighlightEllipsisOptions|string|boolean|undefined) + * }} + */ +export let HighlightOptions = {}; \ No newline at end of file diff --git a/dist/module-min/bundle.js b/dist/module-min/bundle.js index b0f5349..b01c8a5 100644 --- a/dist/module-min/bundle.js +++ b/dist/module-min/bundle.js @@ -1 +1 @@ -import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreArray,KeystoreSet}from"./keystore.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.encoder,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Document.prototype.field,Document.prototype.index,Document.prototype.reg,Document.prototype.tag,Document.prototype.store,Document.prototype.fastupdate,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,KeystoreArray.length,KeystoreMap.size,KeystoreSet.size,Charset.Exact,Charset.Default,Charset.Normalize,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.CJK,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.worker,IndexOptions.config,IndexOptions.priority,IndexOptions.export,IndexOptions.import,FieldOptions.preset,FieldOptions.context,FieldOptions.encoder,FieldOptions.encode,FieldOptions.resolution,FieldOptions.tokenize,FieldOptions.fastupdate,FieldOptions.score,FieldOptions.keystore,FieldOptions.rtl,FieldOptions.cache,FieldOptions.db,FieldOptions.config,FieldOptions.resolve,FieldOptions.field,FieldOptions.filter,FieldOptions.custom,FieldOptions.worker,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,DocumentOptions.priority,DocumentOptions.export,DocumentOptions.import,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,DocumentDescriptor.id,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not,ResolverOptions.pluck,ResolverOptions.field;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{const a="undefined"==typeof self?"undefined"==typeof global?self:global:self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file +import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions,HighlightBoundaryOptions,HighlightEllipsisOptions,HighlightOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreArray,KeystoreSet}from"./keystore.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.encoder,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Document.prototype.field,Document.prototype.index,Document.prototype.reg,Document.prototype.tag,Document.prototype.store,Document.prototype.fastupdate,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,KeystoreArray.length,KeystoreMap.size,KeystoreSet.size,Charset.Exact,Charset.Default,Charset.Normalize,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.CJK,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.worker,IndexOptions.config,IndexOptions.priority,IndexOptions.export,IndexOptions.import,FieldOptions.preset,FieldOptions.context,FieldOptions.encoder,FieldOptions.encode,FieldOptions.resolution,FieldOptions.tokenize,FieldOptions.fastupdate,FieldOptions.score,FieldOptions.keystore,FieldOptions.rtl,FieldOptions.cache,FieldOptions.db,FieldOptions.config,FieldOptions.resolve,FieldOptions.field,FieldOptions.filter,FieldOptions.custom,FieldOptions.worker,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,DocumentOptions.priority,DocumentOptions.export,DocumentOptions.import,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,DocumentDescriptor.id,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not,ResolverOptions.pluck,ResolverOptions.field,HighlightBoundaryOptions.before,HighlightBoundaryOptions.after,HighlightBoundaryOptions.total,HighlightEllipsisOptions.template,HighlightEllipsisOptions.pattern,HighlightOptions.template,HighlightOptions.boundary,HighlightOptions.ellipsis,HighlightOptions.clip,HighlightOptions.merge;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{const a="undefined"==typeof self?"undefined"==typeof global?self:global:self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file diff --git a/dist/module-min/document/highlight.js b/dist/module-min/document/highlight.js new file mode 100644 index 0000000..20df5b7 --- /dev/null +++ b/dist/module-min/document/highlight.js @@ -0,0 +1 @@ +import{parse_simple}from"../common.js";import Index from"../index.js";import{EnrichedDocumentSearchResults,EnrichedSearchResults,HighlightOptions}from"../type.js";export function highlight_fields(a,b,c,d,e){let f,g,h;"string"==typeof e?(f=e,e=""):f=e.template;g=f.indexOf("$1");h=f.substring(g+2),g=f.substring(0,g);let i,l=e&&e.boundary,m=!e||!1!==e.clip,n=e&&e.merge&&h&&g&&new RegExp(h+" "+g,"g"),o=e&&e.ellipsis,p=0;"object"==typeof o&&(i=o.template,p=i.length-2,o=o.pattern),"string"!=typeof o&&(o=!1===o?"":"..."),p&&(o=i.replace("$1",o));let q,r,s=o.length-p;"object"==typeof l&&(q=l.before,0===q&&(q=-1),r=l.after,0===r&&(r=-1),l=l.total||9e5);let t,u,v=new Map;for(let j,k,p,w=0;ww&&(w=i.length+(i?1:0)),x=i.length+(i?1:0)+f.length,y+=a,v.push(u.length),u.push({match:f})),i+=(i?" ":"")+f)}if(!e){const b=d[a];i+=(i?" ":"")+b,l&&u.push({text:b})}else if(l&&y>=l)break}let z=v.length*(f.length-2);if(q||r||l&&i.length-z>l){let a,b,c=l+z-2*s,e=x-w;if(0a&&(a=0))),b=d.length-1?b=1:x=u.length-1){if(x>=u.length){e[y+1]=1,x>=d.length&&(c[y+1]=1);continue}j-=s}i=u[x].text;let f=r&&h[y];if(f)if(0f)if(e[y+1]=1,m)i=i.substring(0,f);else continue;f-=i.length,f||(f=-1),h[y]=f}else{e[y+1]=1;continue}if(j+i.length+1<=l)i=" "+i,a[y]+=i;else if(m){const b=l-j-1;0=x){if(0>x){e[y]=1,c[y]=1;continue}j-=s}i=u[x].text;let d=q&&g[y];if(d)if(0d)if(e[y]=1,m)i=i.substring(i.length-d);else continue;d-=i.length,d||(d=-1),g[y]=d}else{e[y]=1;continue}if(j+i.length+1<=l)i+=" ",a[y]=i+a[y];else if(m){const b=i.length+1-(l-j);0<=b&&b} index + * @param {string} pluck + * @param {HighlightOptions|string} config + * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} + */ +export function highlight_fields(query, result, index, pluck, config) { + + // The biggest issue is dealing with custom encoders, for this reason + // a combined regular expression can't apply as a template + + let template, markup_open, markup_close; + + if ("string" == typeof config) { + template = config; + config = ""; + } else { + template = config.template; + } + + markup_open = template.indexOf("$1"); + + markup_close = template.substring(markup_open + 2); + markup_open = template.substring(0, markup_open); + + let boundary = config && config.boundary, + clip = !config || /* suggest */ /* append: */!1 !== config.clip, + merge = config && config.merge && markup_close && markup_open && new RegExp(markup_close + " " + markup_open, "g"), + ellipsis = config && config.ellipsis, + ellipsis_markup_length = 0, + ellipsis_markup; + + if ("object" == typeof ellipsis) { + ellipsis_markup = ellipsis.template; + ellipsis_markup_length = ellipsis_markup.length - 2; + ellipsis = ellipsis.pattern; + } + if ("string" != typeof ellipsis) { + ellipsis = !1 === ellipsis ? "" : "..."; + } + if (ellipsis_markup_length) { + ellipsis = ellipsis_markup.replace("$1", ellipsis); + } + + let ellipsis_length = ellipsis.length - ellipsis_markup_length, + boundary_before, + boundary_after; + + + if ("object" == typeof boundary) { + boundary_before = boundary.before; + if (0 === boundary_before) boundary_before = -1; + boundary_after = boundary.after; + if (0 === boundary_after) boundary_after = -1; + boundary = boundary.total || 9e5; + } + + // cache shared encoders across fields + let encoder = new Map(), + query_enc; + + + // todo remove this loop and pass in the field data directly + // todo support field-specific configuration + + // for every field + for (let i = 0, enc, idx, path; i < result.length; i++) { + + /** @type {EnrichedSearchResults} */ + let res; + + if (pluck) { + res = result; + path = pluck; + } else { + const tmp = result[i]; + path = tmp.field; + // skip when not a field entry (e.g. tags) + if (!path) continue; + res = tmp.result; + } + + idx = index.get(path); + enc = idx.encoder; + idx.tokenize; + query_enc = encoder.get(enc); + + // re-encode query when encoder has changed or take cache from shared encoders + if ("string" != typeof query_enc) { + query_enc = enc.encode(query); + encoder.set(enc, query_enc); + } + + // for every doc in results + for (let j = 0; j < res.length; j++) { + + const doc = res[j].doc; + if (!doc) continue; + const content = parse_simple(doc, path); + if (!content) continue; + // just split on whitespace and keep original string (encoder split can't apply) + const doc_org = content.trim().split(/\s+/); + if (!doc_org.length) continue; + + let str = "", + str_arr = [], + pos_matches = [], + pos_first_match = -1, + pos_last_match = -1, + length_matches_all = 0; + + + // loop terms of encoded doc content + for (let k = 0; k < doc_org.length; k++) { + let doc_org_cur = doc_org[k], + doc_enc_cur = enc.encode(doc_org_cur); + + doc_enc_cur = 1 < doc_enc_cur.length ? doc_enc_cur.join(" ") : doc_enc_cur[0]; + + let found; + + if (doc_enc_cur && doc_org_cur) { + let doc_org_cur_len = doc_org_cur.length, + doc_org_diff = (enc.split ? doc_org_cur.replace(enc.split, "") : doc_org_cur).length - doc_enc_cur.length, + match = "", + match_length = 0; + + + // loop terms of encoded query content and determine the longest match + for (let l = 0, query_enc_cur; l < query_enc.length; l++) { + query_enc_cur = query_enc[l]; + + if (!query_enc_cur) continue; + let query_enc_cur_len = query_enc_cur.length; + // add length from shrinking phonetic transformations (todo: add tests) + query_enc_cur_len += doc_org_diff; + // skip query token when match length can't exceed previously highest found match + if (match_length && query_enc_cur_len <= match_length) { + continue; + } + const position = doc_enc_cur.indexOf(query_enc_cur); + if (-1 < position) { + match = + // prefix + (position ? doc_org_cur.substring(0, position) : "") + + // match + markup_open + doc_org_cur.substring(position, position + query_enc_cur_len) + markup_close + ( + // suffix + position + query_enc_cur_len < doc_org_cur_len ? doc_org_cur.substring(position + query_enc_cur_len) : ""); + match_length = query_enc_cur_len; + found = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; + } + //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position, match) + } + + // apply the longest match + if (match) { + if (boundary) { + // the outer boundary is used to check if all matches are within the total boundary + // if so, it can apply a simpler alignment + if (0 > pos_first_match) { + pos_first_match = str.length + (str ? 1 : 0); + } + pos_last_match = str.length + (str ? 1 : 0) + match.length; + // the overall length of all matches is used to check if matches exceeds the total boundary + // if so, it can early stop further processing + length_matches_all += doc_org_cur_len; + // the match positions are used to pick items for the final result more quickly + pos_matches.push(str_arr.length); + // collect every term as match or text + str_arr.push({ match }); + } + str += (str ? " " : "") + match; + } + } + + if (!found) { + const text = doc_org[k]; + str += (str ? " " : "") + text; + // collect every term as match or text + boundary && str_arr.push({ text }); + } else if (boundary) { + if (length_matches_all >= boundary) { + // matches has reached total boundary + break; + } + } + } + + // the markup length does not apply to the total boundary + let markup_length = pos_matches.length * (template.length - 2); + + // apply boundaries and align highlights + if (boundary_before || boundary_after || boundary && str.length - markup_length > boundary) { + + // also reduce ellipsis length from boundary + let boundary_length = boundary + markup_length - 2 * ellipsis_length, + length = pos_last_match - pos_first_match, + start, + end; + + + if (0 < boundary_before) { + length += boundary_before; + } + if (0 < boundary_after) { + length += boundary_after; + } + + // 1. all matches are withing the overall boundary (apply simple alignment) + if (length <= boundary_length) { + + start = boundary_before ? pos_first_match - (0 < boundary_before ? boundary_before : 0) : pos_first_match - (0 | (boundary_length - length) / 2); + end = boundary_after ? pos_last_match + (0 < boundary_after ? boundary_after : 0) : start + boundary_length; + + // do not clip terms + if (!clip) { + if (0 < start) { + if (" " === str.charAt(start)) {} else if (" " !== str.charAt(start - 1)) { + start = str.indexOf(" ", start); + 0 > start && (start = 0); + } + } + if (end < str.length) { + if (" " === str.charAt(end - 1)) {} else if (" " !== str.charAt(end)) { + end = str.lastIndexOf(" ", end); + end < pos_last_match ? end = pos_last_match : ++end; + } + } + } + + str = (start ? ellipsis : "") + str.substring(start, end) + (end < str.length ? ellipsis : ""); + } + // 2. matches needs to be split by surrounded terms to fit into the boundary + else { + const final = [], + check = {}, + seamless = {}, + finished = {}, + before = {}, + after = {}; + let final_length = 0, + shift_left = 0, + shift_right = 0, + loop_left = 1, + loop_right = 1; + + + while (!0) { + + let loop; + + for (let k = 0, pos; k < pos_matches.length; k++) { + + pos = pos_matches[k]; + + // 1. add matches to the result + if (!shift_right) { + str = str_arr[pos].match; + + // initialize custom boundaries for each slot + if (boundary_before) { + before[k] = boundary_before; + } + if (boundary_after) { + after[k] = boundary_after; + } + + // count whitespaces between each term + if (k) { + final_length++; + } + + let close; + + // close left side when first term was matched + if (!pos) { + // it can be set before content was added, + // because the first term match is always added + seamless[k] = 1; + finished[k] = 1; + } + // initial ellipsis + else if (!k && ellipsis_length) { + final_length += ellipsis_length; + } + + // close right side when last term was matched + if (pos >= doc_org.length - 1) { + close = 1; + } + // close right side when next term was a match + else if (pos < str_arr.length - 1 && str_arr[pos + 1].match) { + close = 1; + } else if (ellipsis_length) { + final_length += ellipsis_length; + } + + // reduce template length on matches + final_length -= template.length - 2; + + // at least add one match + if (!k || final_length + str.length <= boundary) { + final[k] = str; + } else { + seamless[k] = 0; + loop = loop_left = loop_right = 0; + break; + } + + // update state when term was added + if (close) { + seamless[k + 1] = 1; + finished[k + 1] = 1; + } + } + // 2. add surrounded text to the result + else { + // alternate direction term by term + // 2.1. extend to right first (index: k + 1) + if (shift_left != shift_right) { + if (finished[k + 1]) continue; + pos += shift_right; + + // overlap with other slot + if (check[pos]) { + final_length -= ellipsis_length; + seamless[k + 1] = 1; + finished[k + 1] = 1; + continue; + } + // end reached + if (pos >= str_arr.length - 1) { + if (pos >= str_arr.length) { + finished[k + 1] = 1; + if (pos >= doc_org.length) { + seamless[k + 1] = 1; + } + continue; + } + final_length -= ellipsis_length; + } + + str = str_arr[pos].text; + + let current_after = boundary_after && after[k]; + if (current_after) { + if (0 < current_after) { + if (str.length > current_after) { + finished[k + 1] = 1; + if (clip) { + str = str.substring(0, current_after); + } else { + continue; + } + } + current_after -= str.length; + if (!current_after) current_after = -1; + after[k] = current_after; + } else { + finished[k + 1] = 1; + continue; + } + } + + // count whitespaces between each term + if (final_length + str.length + 1 <= boundary) { + str = " " + str; + final[k] += str; + } else if (clip) { + const diff = boundary - final_length - 1; + if (0 < diff) { + str = " " + str.substring(0, diff); + final[k] += str; + } + finished[k + 1] = 1; + } else { + finished[k + 1] = 1; + continue; + } + } + // 2.2. extend to left (index: k) + else { + if (finished[k]) continue; + pos -= shift_left; + + // overlap with other slot + if (check[pos]) { + final_length -= ellipsis_length; + finished[k] = 1; + seamless[k] = 1; + continue; + } + // start reached + if (0 >= pos) { + if (0 > pos) { + finished[k] = 1; + seamless[k] = 1; + continue; + } + final_length -= ellipsis_length; + } + + str = str_arr[pos].text; + + let current_before = boundary_before && before[k]; + if (current_before) { + if (0 < current_before) { + if (str.length > current_before) { + finished[k] = 1; + if (clip) { + str = str.substring(str.length - current_before); + } else { + continue; + } + } + current_before -= str.length; + if (!current_before) current_before = -1; + before[k] = current_before; + } else { + finished[k] = 1; + continue; + } + } + + // count whitespaces between each term + if (final_length + str.length + 1 <= boundary) { + str += " "; + final[k] = str + final[k]; + } else if (clip) { + const diff = str.length + 1 - (boundary - final_length); + if (0 <= diff && diff < str.length) { + str = str.substring(diff) + " "; + final[k] = str + final[k]; + } + finished[k] = 1; + } else { + finished[k] = 1; + continue; + } + } + } + + // update state when term was added + final_length += str.length; + check[pos] = 1; + loop = 1; + } + + if (loop) { + // alternate shift direction + shift_left == shift_right ? shift_right++ : shift_left++; + } else { + // check finish state + shift_left == shift_right ? loop_left = 0 : loop_right = 0; + // break process when both directions are done + if (!loop_left && !loop_right) { + break; + } + // continue with opposite direction + if (loop_left) { + shift_left++; + shift_right = shift_left; + } else { + shift_right++; + } + } + } + + str = ""; + for (let k = 0, tmp; k < final.length; k++) { + tmp = (k && seamless[k] ? " " : (k && !ellipsis ? " " : "") + ellipsis) + final[k]; + str += tmp; + } + if (ellipsis && !seamless[final.length]) { + str += ellipsis; + } + //console.log(query, seamless, final) + } + } + + if (merge) { + str = str.replace( /** @type {RegExp} */merge, " "); + } + + res[j].highlight = str; + } + + if (pluck) { + break; + } + } + + return result; +} + +// /** +// * @param {string} query +// * @param {EnrichedDocumentSearchResults|EnrichedSearchResults} result +// * @param {Map} index +// * @param {string} pluck +// * @param {HighlightOptions|string} config +// * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} +// */ +// export function highlight_fields(query, result, index, pluck, config){ +// +// // The biggest issue is dealing with custom encoders, for this reason +// // a combined regular expression can't apply as a template +// +// let template, markup_open, markup_close; +// +// if(typeof config === "string"){ +// template = config; +// config = ""; +// } +// else{ +// template = config.template; +// } +// +// if(DEBUG){ +// if(!template){ +// throw new Error('No template pattern was specified by the search option "highlight"'); +// } +// } +// +// markup_open = template.indexOf("$1"); +// +// if(DEBUG){ +// if(markup_open === -1){ +// throw new Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + template); +// } +// } +// +// markup_close = template.substring(markup_open + 2); +// markup_open = template.substring(0, markup_open); +// +// let boundary = config && config.boundary; +// let clip = !config || config.clip !== false; +// let merge = config && config.merge && markup_close && markup_open && new RegExp(markup_close + " " + markup_open, "g"); +// let ellipsis = config && config.ellipsis; +// if(typeof ellipsis !== "string"){ +// ellipsis = "..."; +// } +// +// let boundary_before, boundary_after; +// +// if(typeof boundary === "object"){ +// boundary_before = boundary.before; +// if(boundary_before === 0) boundary_before = -1; +// boundary_after = boundary.after; +// if(boundary_after === 0) boundary_after = -1; +// boundary = boundary.total || 9e5; +// } +// +// // cache shared encoders across fields +// let encoder = new Map(); +// let query_enc; +// let tokenize; +// +// // todo remove this loop and pass in the field data directly +// // todo support field-specific configuration +// +// // for every field +// for(let i = 0, enc, idx, path; i < result.length; i++){ +// +// /** @type {EnrichedSearchResults} */ +// let res; +// +// if(pluck){ +// res = result; +// path = pluck; +// } +// else{ +// const tmp = result[i]; +// path = tmp.field; +// // skip when not a field entry (e.g. tags) +// if(!path) continue; +// res = tmp.result; +// } +// +// idx = index.get(path); +// enc = idx.encoder; +// tokenize = idx.tokenize; +// query_enc = encoder.get(enc); +// +// // re-encode query when encoder has changed or take cache from shared encoders +// if(typeof query_enc !== "string"){ +// query_enc = enc.encode(query); +// encoder.set(enc, query_enc); +// } +// +// // for every doc in results +// for(let j = 0; j < res.length; j++){ +// +// const doc = res[j]["doc"]; +// if(!doc) continue; +// const content = parse_simple(doc, path); +// if(!content) continue; +// const doc_org = content.trim().split(/\s+/); +// if(!doc_org.length) continue; +// +// let str = ""; +// let pos_matches = []; +// let length_matches_all = 0; +// +// // loop terms of encoded doc content +// for(let k = 0; k < doc_org.length; k++){ +// let doc_org_cur = doc_org[k]; +// let doc_org_cur_len = doc_org_cur.length; +// let doc_enc_cur = enc.encode(doc_org_cur); +// doc_enc_cur = doc_enc_cur.length > 1 +// ? doc_enc_cur.join(" ") +// : doc_enc_cur[0]; +// +// let found; +// +// if(doc_enc_cur && doc_org_cur){ +// +// let match = ""; +// let match_length = 0; +// +// // loop terms of encoded query content and determine the longest match +// for(let l = 0; l < query_enc.length; l++){ +// let query_enc_cur = query_enc[l]; +// if(!query_enc_cur) continue; +// let query_enc_cur_len = query_enc_cur.length; +// // add length from shrinking phonetic transformations (todo: add tests) +// query_enc_cur_len += doc_org_cur.length - doc_enc_cur.length; +// // skip query token when match length can't exceed previously highest found match +// if(match_length && query_enc_cur_len <= match_length){ +// continue; +// } +// const position = doc_enc_cur.indexOf(query_enc_cur); +// //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position) +// if(position > -1){ +// match = +// // prefix +// (position ? doc_org_cur.substring(0, position) : "") + +// // match +// markup_open + doc_org_cur.substring(position, position + query_enc_cur_len) + markup_close + +// // suffix +// (position + query_enc_cur_len < doc_org_cur_len ? doc_org_cur.substring(position + query_enc_cur_len) : ""); +// match_length = query_enc_cur_len; +// found = true; +// } +// } +// +// // apply the longest match +// if(match){ +// if(boundary){ +// if(!pos_matches.length && k) length_matches_all += ellipsis.length; +// // the overall length of all matches is used to check if matches exceeds the total boundary +// // if so, it can early stop further processing +// length_matches_all += match.length;//doc_org_cur_len + (str ? 1 : 0) + (k < doc_org.length - 1 ? ellipsis.length : 0); +// // the match positions are used to pick items for the final result more quickly +// pos_matches.push([ +// str.length + (str ? 1 : 0), +// str.length + (str ? 1 : 0) + match.length, +// k +// ]); +// } +// str += (str ? " " : "") + match; +// } +// } +// +// if(!found){ +// const text = doc_org[k]; +// str += (str ? " " : "") + text; +// } +// else if(boundary){ +// if(length_matches_all >= boundary){ +// // matches has reached total boundary +// break; +// } +// } +// } +// +// // the markup length does not apply to the total boundary +// let markup_length = pos_matches.length * (template.length - 2); +// +// // apply boundaries and align highlights +// if(boundary_before || boundary_after || (boundary && (str.length - markup_length) > boundary)){ +// +// let final = ""; +// let surrounded_length = (((((boundary + markup_length) - length_matches_all) / pos_matches.length) - ellipsis.length) / 2); +// //if(surrounded_length < 0) surrounded_length = 0; +// +// let before = boundary_before || ( +// surrounded_length > 0 +// ? Math.floor(surrounded_length + +// (boundary_after +// ? surrounded_length - boundary_after +// : 0)) +// : 0 +// ); +// let after = boundary_after || ( +// surrounded_length > 0 +// ? Math.ceil(surrounded_length + +// (boundary_before +// ? surrounded_length - boundary_before +// : 0)) +// : 0 +// ); +// +// //console.log(surrounded_length, before, after) +// +// for(let k = 0, cur, prev, next; k < pos_matches.length; k++){ +// +// prev = cur; +// cur = next || pos_matches[k]; +// next = pos_matches[k + 1]; +// +// let start = cur[0] - before; +// let end = cur[1] + after; +// let closed_left; +// let closed_right; +// +// // if(k){ +// // closed_left = 1; +// // } +// +// // apply right limit +// if(next && (end >= next[0] - before)){ +// end = cur[1] + (next[0] - cur[1]) / 2 | 0; +// start -= ellipsis.length + 1; +// closed_right = 1; +// } +// // apply left limit +// if(prev && (start <= prev[1] + after)){ +// start = cur[0] - (cur[0] - prev[1]) / 2 | 0; +// end += ellipsis.length + 1; +// closed_left = 1; +// +// // repeat right limit +// if(next && (end >= next[0] - before)){ +// end = cur[1] + (next[0] - cur[1]) / 2 | 0; +// closed_right = 1; +// } +// } +// +// //console.log(start, end, prev, cur, next); +// +// // do not clip terms +// if(!clip){ +// if(start){ +// if(str.charAt(start) === " "){ +// //start++; +// } +// else if(str.charAt(start - 1) !== " "){ +// start = str.indexOf(" ", start); +// start < 0 +// ? start = cur[0] +// : start;//++; +// } +// } +// if(end < str.length){ +// if(str.charAt(end - 1) === " "){ +// //end--; +// } +// else if(str.charAt(end) !== " "){ +// end = str.lastIndexOf(" ", end); +// end < cur[1] +// ? end = cur[1] +// : end++; +// } +// } +// } +// +// final += +// /*(final ? " " : "") +*/ +// (!closed_left && start > 0 ? ellipsis : "") + +// str.substring(start, end) + +// (!closed_right && cur[2] < doc_org.length - 1 ? ellipsis : ""); +// +// //console.log(final) +// } +// +// str = final; +// } +// +// if(merge){ +// str = str.replace(merge, " "); +// } +// +// res[j]["highlight"] = str; +// } +// +// if(pluck){ +// break; +// } +// } +// +// return result; +// } \ No newline at end of file diff --git a/dist/module/document/search.js b/dist/module/document/search.js index b90993f..9380fdf 100644 --- a/dist/module/document/search.js +++ b/dist/module/document/search.js @@ -1,11 +1,12 @@ import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults, MergedDocumentSearchEntry, EnrichedSearchResults, SearchResults, IntermediateSearchResults } from "../type.js"; -import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; +import { create_object, is_array, is_object, is_string } from "../common.js"; import { intersect_union } from "../intersect.js"; import Document from "../document.js"; import Index from "../index.js"; import Resolver from "../resolver.js"; import tick from "../profiler.js"; +import { highlight_fields } from "./highlight.js"; /** * @param {!string|DocumentSearchOptions} query @@ -62,7 +63,8 @@ Document.prototype.search = function (query, limit, options, _promises) { tag, offset, count = 0, - resolve = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, + resolve = /* tag? */ /* stringify */ /* stringify */ + /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, highlight; @@ -97,8 +99,8 @@ Document.prototype.search = function (query, limit, options, _promises) { } } - enrich = this.store && options.enrich && resolve; - highlight = enrich && options.highlight; + highlight = resolve && this.store && options.highlight; + enrich = highlight || resolve && this.store && options.enrich; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -221,6 +223,7 @@ Document.prototype.search = function (query, limit, options, _promises) { offset = field_options.offset || offset; suggest = field_options.suggest || suggest; enrich = this.store && (field_options.enrich || enrich); + highlight = enrich && (options.highlight || highlight); } if (_promises) { @@ -410,120 +413,6 @@ Document.prototype.search = function (query, limit, options, _promises) { return merge ? merge_fields(result) : highlight ? highlight_fields( /** @type {string} */query, result, this.index, pluck, highlight) : /** @type {DocumentSearchResults} */result; }; -/** - * @param {string} query - * @param {EnrichedDocumentSearchResults|EnrichedSearchResults} result - * @param {Map} index - * @param {string} pluck - * @param {string} template - * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} - */ -function highlight_fields(query, result, index, pluck, template) { - - // The biggest issue is dealing with custom encoders, for this reason - // a regular expression can't apply - // Todo: when one of the basic encoders was used, provide - // combined regex - // - // if(typeof template === "string"){ - // template = new RegExp(template, "g"); - // } - - let encoder, query_enc, tokenize; - - - // for every field - for (let i = 0, enc, idx, path; i < result.length; i++) { - - /** @type {EnrichedSearchResults} */ - let res; - - if (pluck) { - res = result; - path = pluck; - } else { - const tmp = result[i]; - path = tmp.field; - if (!path) continue; - res = tmp.result; - } - - // skip when not a field entry (e.g. tags) - - idx = index.get(path); - enc = idx.encoder; - tokenize = idx.tokenize; - - // re-encode query when encoder has changed - if (enc !== encoder) { - encoder = enc; - query_enc = encoder.encode(query); - } - - // for every doc in results - for (let j = 0; j < res.length; j++) { - let str = "", - content = parse_simple(res[j].doc, path), - doc_org = content.split(/\s+/); - //let doc_enc = encoder.encode(content); - - // loop terms of encoded doc content - for (let k = 0, doc_org_cur, doc_enc_cur; k < doc_org.length; k++) { - doc_org_cur = doc_org[k]; - //doc_enc_cur = doc_enc[k]; - doc_enc_cur = enc.encode(doc_org_cur); - doc_enc_cur = 1 < doc_enc_cur.length ? doc_enc_cur.join(" ") : doc_enc_cur[0]; - - let found; - - if (doc_enc_cur && doc_org_cur) { - - // loop terms of encoded query content - for (let l = 0, query_enc_cur; l < query_enc.length; l++) { - query_enc_cur = query_enc[l]; - // todo tokenize could be custom also when "strict" was used - if ("strict" === tokenize) { - if (doc_enc_cur === query_enc_cur) { - str += (str ? " " : "") + template.replace("$1", doc_org_cur); - found = !0; - break; - } - } else { - const position = doc_enc_cur.indexOf(query_enc_cur); - //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position) - if (-1 < position) { - str += (str ? " " : "") + - // prefix - doc_org_cur.substring(0, position) + - // match - template.replace("$1", doc_org_cur.substring(position, position + query_enc_cur.length)) + - // suffix - doc_org_cur.substring(position + query_enc_cur.length); - found = !0; - break; - } - } - - //str += doc_enc[k].replace(new RegExp("(" + doc_enc[k] + ")", "g"), template.replace("$1", content)) - } - } - - if (!found) { - str += (str ? " " : "") + doc_org[k]; - } - } - - res[j].highlight = str; - } - - if (pluck) { - break; - } - } - - return result; -} - // todo support Resolver // todo when searching through multiple fields each term should // be found at least by one field to get a valid match without diff --git a/dist/module/type.js b/dist/module/type.js index 768bbc8..f2c0217 100644 --- a/dist/module/type.js +++ b/dist/module/type.js @@ -142,7 +142,7 @@ export let SearchOptions = {}; * index: (Array|Array|DocumentSearchOptions|string|undefined), * pluck: (string|DocumentSearchOptions|undefined), * merge: (boolean|undefined), - * highlight: (string|undefined) + * highlight: (HighlightOptions|string|undefined) * }} */ export let DocumentSearchOptions = {}; @@ -261,4 +261,32 @@ export let PersistentOptions = {}; * not: (ResolverOptions|Array|undefined) * }} */ -export let ResolverOptions = {}; \ No newline at end of file +export let ResolverOptions = {}; + +/** + * @typedef {{ + * before: (number|undefined), + * after: (number|undefined), + * total: (number|undefined) + * }} + */ +export let HighlightBoundaryOptions = {}; + +/** + * @typedef {{ + * template: string, + * pattern: (string|boolean|undefined) + * }} + */ +export let HighlightEllipsisOptions = {}; + +/** + * @typedef {{ + * template: string, + * boundary: (HighlightBoundaryOptions|number|undefined), + * clip: (boolean|undefined), + * merge: (boolean|undefined), + * ellipsis: (HighlightEllipsisOptions|string|boolean|undefined) + * }} + */ +export let HighlightOptions = {}; \ No newline at end of file diff --git a/doc/0.7.0-lang.md b/doc/0.7.0-lang.md deleted file mode 100644 index d6f407e..0000000 --- a/doc/0.7.0-lang.md +++ /dev/null @@ -1,258 +0,0 @@ -## Documentation 0.7.0-rev2 - -### Language Handler - -Handling languages was completely replaced by a more generic approach. All language-specific definitions has excluded and was optimized for maximum dead-code elimination when using compiler/bundler. Each language exists of 5 definitions, which are divided into two groups: - -1. Charset - 1. ___encode___, type: `function(string):string[]` - 2. ___rtl___, type: `boolean` -2. Language - 1. ___matcher___, type: `{string: string}` - 2. ___stemmer___, type: `{string: string}` - 3. ___filter___, type: `string[]` - -The charset contains the encoding logic, the language contains stemmer, stopword filter and matchers. Multiple language definitions can use the same charset encoder. Also this separation let you manage different language definitions for special use cases (e.g. names, cities, dialects/slang, etc.). - -To fully describe a custom language __on the fly__ you need to pass: - -```js -const index = FlexSearch({ - // mandatory: - encode: (str) => [str], - // optionally: - rtl: false, - stemmer: {}, - matcher: {}, - filter: [] -}); -``` - -When passing no parameter it uses the `latin:default` schema by default. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FieldCategoryDescription
encodecharsetThe encoder function. Has to return an array of separated words (or an empty string).
rtlcharsetA boolean property which indicates right-to-left encoding.
filterlanguageFilter are also known as "stopwords", they completely filter out words from being indexed.
stemmerlanguageStemmer removes word endings and is a kind of "partial normalization". A word ending just matched when the word length is bigger than the matched partial.
matcherlanguageMatcher replaces all occurrences of a given string regardless of its position and is also a kind of "partial normalization".
- -### 1. Language Packs: ES6 Modules - -The most simple way to assign charset/language specific encoding via modules is: - -```js -import charset from "./dist/module/lang/latin/soundex.js"; -import lang from "./dist/module/lang/en.js"; - -const index = FlexSearch({ - charset: charset, - lang: lang -}); -``` - -Just import the __default export__ by each module and assign them accordingly. - -The full qualified example from above is: - -```js -import { encode, rtl, tokenize } from "./dist/module/lang/latin/soundex.js"; -import { stemmer, filter, matcher } from "./dist/module/lang/en.js"; - -const index = FlexSearch({ - encode: encode, - // assign forced tokenizer first: - tokenize: tokenize || "forward", - rtl: rtl, - stemmer: stemmer, - matcher: matcher, - filter: filter -}); -``` - -The example above is the standard interface which is at least exported from each charset/language. - -__Note:__ Some of the encoder variants limit the use of built-in tokenizer (e.g. soundex). To be save prioritize the forced tokenizer and fall back to your choice, e.g. `tokenize || "forward"`. - -#### Encoder Variants - -You remember the encoding variants like `simple`, `advanced`, `extra`, or `balanced`? These are also supported and provides you several variants of encoding (which differs in performance and degree of normalization). - -It is pretty straight forward when using a encoder variant: - -```js -import advanced from "./dist/module/lang/latin/advanced.js"; -import { encode } from "./dist/module/lang/latin/extra.js"; - -const index_advanced = FlexSearch({ - // apply all definitions: - charset: advanced -}); - -const index_extra = FlexSearch({ - // just apply the encoder: - encode: encode -}); -``` - -#### Available Latin Encoders - -1. default -2. simple -3. advanced -4. extra -5. balance -6. soundex - -You can assign a charset by passing the charset during initialization, e.g. `charset: "latin"` for the default charset encoder or `charset: "latin:soundex"` for a encoder variant. - -#### Dialect / Slang - -Language definitions (especially matchers) also could be used to normalize dialect and slang of a specific language. - -### 2. Language Packs: ES5 Modules - -You need to make the charset and/or language definitions available by: - -1. All charset definitions are included in the `flexsearch.min.js` build by default, but no language-specific definitions are included -2. You can load packages located in `/dist/lang/` (files refers to languages, folders are charsets) -3. You can make a custom build - -When loading language packs, make sure that the library was loaded before: - -```html - - - -``` - -Because you loading packs as external packages (non-ES6-modules) you have to initialize them by shortcuts: - -```js -const index = FlexSearch({ - charset: "latin:soundex", - lang: "en" -}); -``` - -> Use the `charset:variant` notation to assign charset and its variants. When just passing the charset without a variant will automatically resolve as `charset:default`. - -You can also override existing definitions, e.g.: - -```js -const index = FlexSearch({ - charset: "latin", - lang: "en", - matcher: {} -}); -``` - -Passed definitions will __not__ extend default definitions, they will replace them. When you like to extend a definition just create a new language file and put in all the content. - -#### Encoder Variants - -It is pretty straight forward when using an encoder variant: - -```html - - - - -``` - -```js -const index_advanced = FlexSearch({ - charset: "latin:advanced" -}); - -const index_extra = FlexSearch({ - charset: "latin:extra" -}); -``` - -Again use the `charset:variant` notation to define charset and its variants. - -### Partial Tokenizer - -In FlexSearch you can't provide your own partial tokenizer, because it is a direct dependency to the core unit. The built-in tokenizer of FlexSearch splits each word into chunks by different patterns: - -1. strict (supports contextual index) -2. forward -3. reverse / both -4. full -5. ngram (supports contextual index, coming soon) - -### Language Processing Pipeline - -This is the default pipeline provided by FlexSearch: - -

- -

- -#### Custom Pipeline - -At first take a look into the default pipeline in `src/common.js`. It is very simple and straight forward. The pipeline will process as some sort of inversion of control, the final encoder implementation has to handle charset and also language specific transformations. This workaround has left over from many tests. - -Inject the default pipeline by e.g.: - -```js -this.pipeline( - - /* string: */ str.toLowerCase(), - /* normalize: */ false, - /* split: */ split, - /* collapse: */ false -); -``` - -Use the pipeline schema from above to understand the iteration and the difference of pre-encoding and post-encoding. Stemmer and matchers needs to be applied after charset normalization but before language transformations, filters also. - -Here is a good example of extending pipelines: `src/lang/latin/extra.js` → `src/lang/latin/advanced.js` → `src/lang/latin/simple.js`. - -### How to contribute? - -Search for your language in `src/lang/`, if it exists you can extend or provide variants (like dialect/slang). If the language doesn't exist create a new file and check if any of the existing charsets (e.g. latin) fits to your language. When no charset exist, you need to provide a charset as a base for the language. - -A new charset should provide at least: - -1. `encode` A function which normalize the charset of a passed text content (remove special chars, lingual transformations, etc.) and __returns an array of separated words__. Also stemmer, matcher or stopword filter needs to be applied here. When the language has no words make sure to provide something similar, e.g. each chinese sign could also be a "word". Don't return the whole text content without split. -3. `rtl` A boolean flag which indicates right-to-left encoding - -Basically the charset needs just to provide an encoder function along with an indicator for right-to-left encoding: - -```js -export function encode(str){ return [str] } -export const rtl = false; -``` diff --git a/doc/0.7.0.md b/doc/0.7.0.md deleted file mode 100644 index a306373..0000000 --- a/doc/0.7.0.md +++ /dev/null @@ -1,1767 +0,0 @@ -

- FlexSearch.js: Next-Generation full text search library for Browser and Node.js -

-

- -### FlexSearch v0.7.0 - -A long journey finally comes to its end. This document gives you some insights of the current state plus an overview of introduced new features and changes. - -I ended up by building the whole library from scratch again, starting from a blank file. FlexSearch was one of my first open source libraries from which I've learned much about how to make a codebase ready for continuously adding new features. Putting features to the old codebase over and over again ends in a structural disaster. I also started an implementation in Rust where I finally recognized that the old codebase has to be thrown away completely. - -My first step was addressing each issue and goal as "acceptance criteria". Most of them are about matching and scoring, but also keeping the performance was very important. The criteria for scoring are really hard, there is no library out which could pass those tests actually. The half of them are currently covered, that's a really great capability. Don't worry, the final release will not being delayed by the completion of those criteria. - -Let's talk about the current state. The most difficult part (aka "the core development") has almost finished. I'm very satisfying with the result, which is an improvement in every single aspect. To be honest, it is still complex of course, probably more complex than the old generation was, so please don't expect too much about the simplicity of the code. My biggest focus was on code structure and process flow. - -FlexSearch basically is now divided into two Classes: - -1. Index -2. Document - -The index is a pure (flat) implementation, greatly optimized to perform fast. The document usually exists of multiple indexes (for each field in document). - -In a document every field/index can have its own configuration including a custom `encoder` for each field. - -You can use an instance of Index directly (very much like the old FlexSearch when not indexing documents, instead just ID and text contents). - -### Load Library - -#### ES6 Modules: - -```js -import Index from "./index.js"; -import Document from "./document.js"; -import WorkerIndex from "./worker/index.js"; - -const index = new Index(options); -const document = new Document(options); -const worker = new WorkerIndex(options); -``` - -#### Browser Bundle (ES5 Support): - -Or load one of the builds from the folder `dist` to your html as a script and use as follows: - -```js -var index = new FlexSearch.Index(options); -var document = new FlexSearch.Document(options); -var worker = new FlexSearch.Worker(options); -``` - -#### Node.js: - -Install the non-published beta version: - -```cmd -npm install https://github.com/nextapps-de/flexsearch/tarball/0.7.0 -``` - -Use as a npm package: - -```js -const { Index, Document, Worker } = require("flexsearch"); -``` - -### Basic Usage - -The method signature stays almost unchanged: - -```js -var index = new Index(options); -index.add(id, text); -index.search(text, limit); -index.search(text, options); -index.search(text, limit, options); -index.search(options); -``` - -```js -var document = new Document(options); -document.add(doc); -document.add(id, doc); -document.search(text, limit); -document.search(text, options); -document.search(text, limit, options); -document.search(options); -``` - -## Source Code - -Source Code v0.7.0-pre-alpha available here:
-https://github.com/nextapps-de/flexsearch/tree/0.7.0/src - -What is not included yet but comes soon? - -- ~~WebWorker~~ -- ~~Worker for Node.js~~ -- ~~Inline Worker (optionally)~~ -- ~~Offset-Pagination~~ -- ~~Export/Import~~ -- ~~Tags~~ -- ~~Bundles: Light, Compact, Full~~ -- Test Automation (needs to be migrated) -- Benchmark Suite (almost done) - -What is not included yet and comes later? - -- Engines (Custom Indexes) - -What will be dropped? - -- Where-Clause -- Index Information `index.info()` -- Paging Cursor (was replaced by offset) - -## Builtin Profiles - -1. `memory` (primary optimize for memory) -2. `performance` (primary optimize for performance) -3. `match` (primary optimize for matching) -4. `score` (primary optimize for scoring) -5. `default` (the default balanced profile) - -These profiles are covering standard use cases. It is recommended to apply custom configuration instead of using profiles to get the best out for your situation. Every profile could be optimized further to its specific task, e.g. extreme performance optimized configuration or extreme memory and so on. - -## Improvements - -- Bidirectional Context (the order of words can now vary, does not increase memory when using bidirectional context) -- New memory-friendly strategy for indexes (switchable, saves up to 50% of memory for each index, slightly decrease performance) -- Better scoring calculation (one of the biggest concerns of the old implementation was that the order of arrays processed in the intersection has affected the order of relevance in the final result) -- Fix resolution (the resolution in the old implementation was not fully stretched through the whole range in some cases) -- Skip words (optionally, automatically skip words from the context chain which are too short) -- Hugely improves performance of long queries (up to 450x faster!) and also memory allocation (up to 250x less memory) -- New fast-update strategy (optionally, hugely improves performance of all updates and removals of indexed contents up to 2850x) -- Improved auto-balanced cache (keep and expire cache by popularity) -- Append contents to already existing entries (already indexed documents or contents) -- New method "contain" to check if an ID was already indexed -- Access documents directly from internal store (read/write) -- Suggestions are hugely improved, falls back from context search all the way down to single term match -- Document descriptor has now array support (optionally adds array entries via the new `append` under the hood to provide a unique relevance context for each entry) -- Document storage handler gets improved -- Results from document index now grouped by field (this is one of the few bigger breaking changes which needs migrations of your old code) -- Boolean search has a new concept (use in combination of the new result structure) -- Node.js Worker Threads -- Improved default latin encoders -- New parallelization model and workload distribution -- Improved Export/Import -- Tag Search -- Offset pagination -- Enhanced Field Search -- Improved sorting by relevance (score) -- Added Context Scoring (context index has its own resolution) -- Enhanced charset normalization -- Improved bundler (support for inline WebWorker) - -The whole "context" strategy has greatly improved. - -### Migration Quick Overview - -> Define document fields as object keys is not longer supported due to the unification of all option payloads. - -A full configuration example for a context-based index: - -```js -var index = new Index({ - tokenize: "strict", - resolution: 9, - minlength: 3, - optimize: true, - fastupdate: true, - cache: 100, - context: { - depth: 1, - resolution: 3, - bidirectional: true - } -}); -``` - -The `resolution` could be set also for the contextual index. - -A full configuration example for a document based index: - -```js -const index = new Document({ - tokenize: "forward", - optimize: true, - resolution: 9, - cache: 100, - worker: true, - document: { - id: "id", - tag: "tag", - store: [ - "title", "content" - ], - index: [{ - field: "title", - tokenize: "forward", - optimize: true, - resolution: 9 - },{ - field: "content", - tokenize: "strict", - optimize: true, - resolution: 9, - minlength: 3, - context: { - depth: 1, - resolution: 3 - } - }] - } -}); -``` - -A full configuration example for a document search: - -```js -index.search({ - enrich: true, - bool: "and", - tag: ["cat", "dog"], - index: [{ - field: "title", - query: "some query", - limit: 100, - suggest: true - },{ - field: "content", - query: "same or other query", - limit: 100, - suggest: true - }] -}); -``` - -## Index Stack-flow - -The process flow of an index could be switched between "memory-optimized" and "default". - -> The default flow performs slightly faster, because it provides two additional optimizations: 1. "fast fail" (stop early when term was not found) and 2. "fast success" (return early when the result has reached the limit). - -Default flow:
-`{term} => [score] => [ids]` - -Memory-optimized flow:
-`[score] => {term} => [ids]` - -The contextual index has the same schema as the lexical index above, but goes one level deeper: - -Default flow:
-`{keyword} => {term} => [score] => [ids]` - -Memory-optimized flow:
-`[score] => {keyword} => {term} => [ids]` - -## Tokenizer - -The tokenizers are also available again. They affect the capability of matching partials (parts of a term). - -1. `strict` -2. `forward` -3. `reverse` -4. `full` - -## Changes - -I decide to use less parameter variation to make the code cleaner and also to make type definitions more practicable. - -### Async - -The "async" options was removed, instead you can call each method in its async version, e.g. `index.addAsync` or `index.searchAsync`. - -The advantage is you can now use both variations on the same index, whereas the old version is just performing asynchronous for all methods when the option flag was set. - -You can assign callbacks to each async function: - -```js -index.addAsync(id, content, function(){ - console.log("Task Done"); -}); -``` - -```js -index.searchAsync(query, function(result){ - console.log("Results: ", result); -}); -``` - -Or did not pass a callback function and getting back a `Promise` instead: - -```js -index.addAsync(id, content).then(function(){ - console.log("Task Done"); -}); -``` - -```js -index.searchAsync(query).then(function(result){ - console.log("Results: ", result); -}); -``` - -Or use `async` and `await`: - -```js -async function add(){ - await index.addAsync(id, content); - console.log("Task Done"); -} -``` - -```js -async function search(){ - const results = await index.searchAsync(query); - console.log("Results: ", result); -} -``` - -### Auto-Balanced Cache (By Popularity) - -The cache was improved and has a new strategy for balance/expire cache entries by popularity. - -Also, to prevent inner calls to the same function recursively the cache gets a new method. Again, this make it possible to switch between both kind of queries (cached/uncached) on the same index. - -You still need to initialize the cache and its limit during the creation of the index: - -```js -const index = new Index({ cache: 100 }); -``` - -```js -const results = index.searchCache(query); -``` - -A common scenario for using a cache is an autocomplete or instant search when typing. - -### Append Contents - -You can now append contents to an existing index like: - -```js -index.append(id, content); -``` - -This will not overwrite the old indexed contents as it will do when perform `index.update(id, content)`. Keep in mind that `index.add(id, content)` will also perform "update" under the hood when the id was already being indexed. - -Appended contents will have their own context and also their own full `resolution`. Therefore, the relevance isn't being stacked but gets its own context. - -Let us take this example: - -```js -index.add(0, "some index"); -index.append(0, "some appended content"); - -index.add(1, "some text"); -index.append(1, "index appended content"); -``` - -When you query `index.search("index")` then you will get index id 1 as the first entry in the result, because the context starts from zero for the appended data (isn't stacked to the old context) and here "index" is the first term. - -If you didn't want this behavior then just ust `index.add(id, content)` and provide the full length of content. - -#### Check existence of already indexed IDs - -You can check if an ID was already indexed by: - -```js -if(index.contain(1)){ - console.log("ID is already in index"); -} -``` - -## Document Index - -One of the key improvements is how documents will be indexed and processed. Such an index is getting its own class `Document` which contains instances of `Index` for each field under the hood. One advantage is you can query every `Index` of a document directly if you like. That comes close to the old "tag" feature, but runs significantly faster, e.g. when just query against one field. This way using a document can logically divide and distribute your contents through multiple indexes and is performing faster when query against one field compared to a non-document approach where you put in all your data to one index. Of course, a query through more than one field can't beat the non-document index performance-wise. - -### Document Descriptor - -Every document needs an ID. When your documents has no ID, then you need to create one by passing an index or count or something else as an ID (a value from type `number` is highly recommended). Those IDs are unique references to a given content. This is important when you update or adding over content through existing IDs. When referencing is not a concern, you can simply use something simple like `count++`. - -Assuming our document has a data structure like this: - -```json -{ - "id": 0, - "content": "some text" -} -``` - -Old syntax FlexSearch v0.6.3 (___not supported anymore!___): - -```js -const index = new Document({ - doc: { - id: "id", - field: ["content"] - } -}); -``` - -> The document descriptor has slightly changed, there is no `field` branch anymore, instead just apply one level higher, so `key` becomes a main member of options. - -For the new syntax the field "doc" was renamed to `document` and the field "field" was renamed to `index`: - -```js -const index = new Document({ - document: { - id: "id", - index: ["content"] - } -}); - -index.add({ - id: 0, - content: "some text" -}); -``` - -The field `id` describes where the ID or unique key lives inside your documents. The default key gets the value `id` by default when not passed, so you can shorten the example from above to: - -```js -const index = new Document({ - document: { - index: ["content"] - } -}); -``` - -The member `index` has a list of fields which you want to be indexed from your documents. When just selecting one field, then you can pass a string. When also using default key `id` then this shortens to just: - -```js -const index = new Document({ document: "content" }); -index.add({ id: 0, content: "some text" }); -``` - -Assuming you have several fields, you can pass custom options for each field also: - -```js -const index = new Document({ - id: "id", - index: [{ - field: "title", - tokenize: "forward", - optimize: true, - resolution: 9 - },{ - field: "content", - tokenize: "strict", - optimize: true, - resolution: 9, - minlength: 3, - context: { - depth: 1, - resolution: 3 - } - }] -}); -``` - -Field options gets inherited when also global options was passed, e.g.: - -```js -const index = new Document({ - tokenize: "strict", - optimize: true, - resolution: 9, - document: { - id: "id", - index:[{ - field: "title", - tokenize: "forward" - },{ - field: "content", - minlength: 3, - context: { - depth: 1, - resolution: 3 - } - }] - } -}); -``` - -Note: The context options from the field "content" also gets inherited by the corresponding field options, whereas this field options was inherited by the global option. - -### Nested Data Fields - -```json -{ - "record": { - "id": 0, - "title": "some title", - "content": { - "header": "some text", - "footer": "some text" - } - } -} -``` - -> Use the colon ":" syntax to name each field hierarchically starting from the root, e.g.: - -```js -const index = new Document({ - document: { - id: "record:id", - index: [ - "record:title", - "record:content:header", - "record:content:footer" - ] - } -}); -``` - -> Just add fields you want to query against. Do not add fields to the index, you just need in the result (but did not query against). For this purpose you can store documents independently of its index (read below). - -When you want to query through a field you have to pass the exact key of the field you have defined in the `doc` as a field name (with colon syntax): - -```js -index.search(query, { - index: [ - "record:title", - "record:content:header", - "record:content:footer" - ] -}); -``` - -Same as: - -```js -index.search(query, [ - "record:title", - "record:content:header", - "record:content:footer" -]); -``` - -Using field-specific options: - -```js -index.search([{ - field: "record:title", - query: "some query", - limit: 100, - suggest: true -},{ - field: "record:title", - query: "some other query", - limit: 100, - suggest: true -}]); -``` - -You can perform a search through the same field with different queries. - -> When passing field-specific options you need to provide the full configuration for each field. They get not inherited like the document descriptor. - -### Complex Documents - -You need to follow 2 rules for your documents: - -1. The document cannot start with an Array at the root index. This will introduce sequential data and isn't supported yet. See below for a workaround for such data. - -```js -[ // <-- not allowed as document start! - { - "id": 0, - "title": "title" - } -] -``` - -2. The id can't be nested inside an array (also none of the parent fields can't be an array). This will introduce sequential data and isn't supported yet. See below for a workaround for such data. - -```js -{ - "records": [ // <-- not allowed when ID or tag lives inside! - { - "id": 0, - "title": "title" - } - ] -} -``` - -Here an example for a supported complex document: - -```json -{ - "meta": { - "tag": "cat", - "id": 0 - }, - "contents": [ - { - "body": { - "title": "some title", - "footer": "some text" - }, - "keywords": ["some", "key", "words"] - }, - { - "body": { - "title": "some title", - "footer": "some text" - }, - "keywords": ["some", "key", "words"] - } - ] -} -``` - -The corresponding document descriptor (when all fields should be indexed) looks like: - -```js -const index = new Document({ - document: { - id: "meta:id", - tag: "meta:tag", - index: [ - "contents[]:body:title", - "contents[]:body:footer", - "contents[]:keywords" - ] - } -}); -``` - -Again, when searching you have to use the same colon-separated-string from your field definition. - -```js -index.search(query, { - index: "contents[]:body:title" -}); -``` - -### Not Supported Documents (Sequential Data) - -This example breaks both rules from above: - -```js -[ // <-- not allowed as document start! - { - "tag": "cat", - "records": [ // <-- not allowed when ID or tag lives inside! - { - "id": 0, - "body": { - "title": "some title", - "footer": "some text" - }, - "keywords": ["some", "key", "words"] - }, - { - "id": 1, - "body": { - "title": "some title", - "footer": "some text" - }, - "keywords": ["some", "key", "words"] - } - ] - } -] -``` - -You need to apply some kind of structure normalization. - -A workaround to such a data structure looks like this: - -```js -const index = new Document({ - document: { - id: "record:id", - tag: "tag", - index: [ - "record:body:title", - "record:body:footer", - "record:body:keywords" - ] - } -}); - -function add(sequential_data){ - - for(let x = 0, data; x < sequential_data.length; x++){ - - data = sequential_data[x]; - - for(let y = 0, record; y < data.records.length; y++){ - - record = data.records[y]; - - index.add({ - id: record.id, - tag: data.tag, - record: record - }); - } - } -} - -// now just use add() helper method as usual: - -add([{ - // sequential structured data - // take the data example above -}]); -``` - -You can skip the first loop when your document data has just one index as the outer array. - -### Join / Append Arrays - -On the complex example above, the field `keywords` is an array but here the markup did not have brackets like `keywords[]`. That will also detect the array but instead of appending each entry to a new context, the array will be joined into on large string and added to the index. - -The difference of both kinds of adding array contents is the relevance when searching. When adding each item of an array via `append()` to its own context by using the syntax `field[]`, then the relevance of the last entry concurrent with the first entry. When you left the brackets in the notation, it will join the array to one whitespace-separated string. Here the first entry has the highest relevance, whereas the last entry has the lowest relevance. - -So assuming the keyword from the example above are pre-sorted by relevance to its popularity, then you want to keep this order (information of relevance). For this purpose do not add brackets to the notation. Otherwise, it would take the entries in a new scoring context (the old order is getting lost). - -Also you can left bracket notation for better performance and smaller memory footprint. Use it when you did not need the granularity of relevance by the entries. - -### Field Search - -Search through all fields: - -```js -index.search(query); -``` - -Search through a specific field: - -```js -index.search(query, { index: "title" }); -``` - -Search through a given set of fields: - -```js -index.search(query, { index: ["title", "content"] }); -``` - -Same as: - -```js -index.search(query, ["title", "content"]); -``` - -Pass custom modifiers and queries to each field: - -```js -index.search([{ - field: "content", - query: "some query", - limit: 100, - suggest: true -},{ - field: "content", - query: "some other query", - limit: 100, - suggest: true -}]); -``` - -You can perform a search through the same field with different queries. - -### New Result Set - -One of the few breaking changes which needs migration of your old implementation is the result set. I was thinking a long time about it and came to the conclusion, that this new structure might look weird on the first time, but also comes with some nice new capabilities. - -Schema of the result-set: - -> `fields[] => { field, result[] => { document }}` - -The first index is an array of fields the query was applied to. Each of this field has a record (object) with 2 properties "field" and "result". The "result" is also an array and includes the result for this specific field. The result could be an array of IDs or as enriched with stored document data. - -A non-enriched result set now looks like: - -```js -[{ - field: "title", - result: [0, 1, 2] -},{ - field: "content", - result: [3, 4, 5] -}] -``` - -An enriched result set now looks like: - -```js -[{ - field: "title", - result: [ - { id: 0, doc: { /* document */ }}, - { id: 1, doc: { /* document */ }}, - { id: 2, doc: { /* document */ }} - ] -},{ - field: "content", - result: [ - { id: 3, doc: { /* document */ }}, - { id: 4, doc: { /* document */ }}, - { id: 5, doc: { /* document */ }} - ] -}] -``` - -When using `pluck` instead of "field" you can explicitly select just one field and get back a flat representation: - -```js -index.search(query, { pluck: "title", enrich: true }); -``` - -```js -[ - { id: 0, doc: { /* document */ }}, - { id: 1, doc: { /* document */ }}, - { id: 2, doc: { /* document */ }} -] -``` - -These change is basically based on "boolean search". Instead of applying your bool logic to a nested object (which almost ends in structured hell), you can apply your logic by yourself on top of the result-set dynamically. This opens hugely capabilities on how you process the results. Therefore, the results from the fields aren't squashed into one result anymore. That keeps some important information, like the name of the field as well as the relevance of each field results which didn't get mixed anymore. - -> A field search will apply a query with the boolean "or" logic by default. Each field has its own result to the given query. - -There is one situation where the `bool` property is still supported. When you like to switch the default "or" logic from the field search into "and", e.g.: - -```js -index.search(query, { - index: ["title", "content"], - bool: "and" -}); -``` - -You will just get results which contains the query in both fields. That's it. - -### Tags - -Like the `key` for the ID just define the path to the tag: - -```js -const index = new Document({ - document: { - id: "id", - tag: "tag", - index: "content" - } -}); -``` - -```js -index.add({ - id: 0, - tag: "cat", - content: "Some content ..." -}); -``` - -Your data also can have multiple tags as an array: - -```js -index.add({ - id: 1, - tag: ["animal", "dog"], - content: "Some content ..." -}); -``` - -You can perform a tag-specific search by: - -```js -index.search(query, { - index: "content", - tag: "animal" -}); -``` - -This just gives you result which was tagged with the given tag. - -Use multiple tags when searching: - -```js -index.search(query, { - index: "content", - tag: ["cat", "dog"] -}); -``` - -This gives you result which are tagged with one of the given tag. - -> Multiple tags will apply as the boolean "or" by default. It just needs one of the tags to be existing. - -This is another situation where the `bool` property is still supported. When you like to switch the default "or" logic from the tag search into "and", e.g.: - -```js -index.search(query, { - index: "content", - tag: ["dog", "animal"], - bool: "and" -}); -``` - -You will just get results which contains both tags (in this example there is just one records which has the tag "dog" and "animal"). - -### Tag Search - -You can also fetch results from one or more tags when no query was passed: - -```js -index.search({ tag: ["cat", "dog"] }); -``` - -In this case the result-set looks like: - -```js -[{ - tag: "cat", - result: [ /* all cats */ ] -},{ - tag: "dog", - result: [ /* all dogs */ ] -}] -``` - -### Limit & Offset - -> By default, every query is limited to 100 entries. Unbounded queries leads into issues. You need to set the limit as an option to adjust the size. - -You can set the limit and the offset for each query: - -```js -index.search(query, { limit: 20, offset: 100 }); -``` - -> You cannot pre-count the size of the result-set. That's a limit by the design of FlexSearch. When you really need a count of all results you are able to page through, then just assign a high enough limit and get back all results and apply your paging offset manually (this works also on server-side). FlexSearch is fast enough that this isn't an issue. - -## Document Stores - -> Do not use a store when: 1. an array of IDs as the result is good enough, or 2. you already have the contents/documents stored elsewhere (outside the index). - -Only a document index can have a store. You can use a document index instead of a flat index to get this functionality also when only storing ID-content-pairs. - -This will add the whole original content to the store: - -```js -const index = new Document({ - document: { - index: "content", - store: true - } -}); -index.add({ id: 0, content: "some text" }); -``` - -### Access documents from internal store - -You can get indexed documents from the store: - -```js -var data = index.get(1); -``` - -You can update/change store contents directly without changing the index by: - -```js -index.set(1, data); -``` - -To update the store and also update the index then just use `index.update`, `index.add` or `index.append`. - -When you perform a query, weather it is a document index or a flat index, then you will always get back an array of IDs. - -Optionally you can enrich the query results automatically with stored contents by: - -```js -index.search(query, { enrich: true }); -``` - -Your results look now like: - -```js -[{ - id: 0, - doc: { /* content from store */ } -},{ - id: 1, - doc: { /* content from store */ } -}] -``` - -### Configure Storage (Recommended) - -This will add just specific fields from a document to the store (the ID isn't necessary to keep in store): - -```js -const index = new Document({ - document: { - index: "content", - store: ["author", "email"] - } -}); - -index.add(id, content); -``` - -You can configure independently what should being indexed and what should being stored. It is highly recommended to make use of this whenever you can. - -Here a useful example of configuring doc and store: - -```js -const index = new Document({ - document: { - index: "content", - store: ["author", "email"] - } -}); - -index.add({ - id: 0, - author: "Jon Doe", - email: "john@mail.com", - content: "Some content for the index ..." -}); -``` - -You can query through the contents and will get back the stored values instead: - -```js -index.search("some content", { enrich: true }); -``` - -Your results are now looking like: - -```js -[{ - field: "content", - result: [{ - id: 0, - doc: { - author: "Jon Doe", - email: "john@mail.com", - } - }] -}] -``` - -Both field "author" and "email" are not indexed. - -## Worker Parallelism (Browser + Node.js) - -The whole worker implementation has changed by also keeping Node.js support in mind. The good news is worker will also get supported by Node.js by the library. - -One important change is how workers divided their tasks and how contents are distributed. One big issue was that in the old model workers cycles for each task (Round Robin). Theoretically that provides an optimal balance of workload and storage. But that breaks the internal architecture of this search library and almost every performance optimization is getting lost. - -Let us take an example. Assuming you have 4 workers and you will add 4 contents to the index, then each content is delegated to one worker (a perfect balance but index becomes a partial index). - -Old syntax FlexSearch v0.6.3 (___not supported anymore!___): - -```js -const index = new FlexSearch({ worker: 4 }); -index.add(1, "some") - .add(2, "content") - .add(3, "to") - .add(4, "index"); -``` - -``` -Worker 1: { 1: "some" } -Worker 2: { 2: "content" } -Worker 3: { 3: "to" } -Worker 4: { 4: "index" } -``` - -The issue starts when you query a term. Each of the worker has to resolve the search on its own index and has to delegate back the results to apply the intersection calculation. That's the problem. No one of the workers could solve a search task completely, they have to transmit intermediate results back. Therefore, no optimization path could be applied early, because every worker has to send back the full (non-limited) result first. - -The new worker model from v0.7.0 is divided into "fields" from the document (1 worker = 1 field index). This way the worker becomes able to solve tasks (subtasks) completely. The downside of this paradigm is they might not have been perfect balanced in storing contents (fields may have different length of contents). On the other hand there is no indication that balancing the storage gives any advantage (they all require the same amount in total). - -```js -const index = new Document({ - index: ["tag", "name", "title", "text"], - worker: true -}); - -index.add({ - id: 1, tag: "cat", name: "Tom", title: "some", text: "some" -}).add({ - id: 2, tag: "dog", name: "Ben", title: "title", text: "content" -}).add({ - id: 3, tag: "cat", name: "Max", title: "to", text: "to" -}).add({ - id: 4, tag: "dog", name: "Tim", title: "index", text: "index" -}); -``` - -``` -Worker 1: { 1: "cat", 2: "dog", 3: "cat", 4: "dog" } -Worker 2: { 1: "Tom", 2: "Ben", 3: "Max", 4: "Tim" } -Worker 3: { 1: "some", 2: "title", 3: "to", 4: "index" } -Worker 4: { 1: "some", 2: "content", 3: "to", 4: "index" } -``` - -When you perform a field search through all fields then this task is perfectly balanced through all workers, which can solve their subtasks independently. - -### WorkerIndex (Adapter) - -Above we have seen that documents will create worker automatically for each field. You can also create a WorkerIndex directly (same like using `Index` instead of `Document`). - -Use as ES6 module: - -```js -import WorkerIndex from "./worker/index.js"; -const index = new WorkerIndex(options); -index.add(1, "some") - .add(2, "content") - .add(3, "to") - .add(4, "index"); -``` - -Or when bundled version was used instead: - -```js -var index = new FlexSearch.Worker(options); -index.add(1, "some") - .add(2, "content") - .add(3, "to") - .add(4, "index"); -``` - -Such a WorkerIndex works pretty much the same as a created instance of `Index`. - -> A WorkerIndex only support the `async` variant of all methods. That means when you call `index.search()` on a WorkerIndex this will perform also in async the same way as `index.searchAsync()` will do. - -### Worker Threads (Node.js) - -The worker model for Node.js is based on "worker threads" and works exactly the same way: - -```js -const { Document } = require("flexsearch"); - -const index = new Document({ - index: ["tag", "name", "title", "text"], - worker: true -}); -``` - -Or create a single worker instance for a non-document index: - -```js -const { Worker } = require("flexsearch"); -const index = new Worker({ options }); -``` - -### The Worker Async Model (Best Practices) - -A worker will always perform as async. On a query method call you always should handle the returned promise (e.g. use `await`) or pass a callback function as the last parameter. - -```js -const index = new Document({ - index: ["tag", "name", "title", "text"], - worker: true -}); -``` - -All requests and sub-tasks will run in parallel (prioritize "all tasks completed"): - -```js -index.searchAsync(query, callback); -index.searchAsync(query, callback); -index.searchAsync(query, callback); -``` - -Also (prioritize "all tasks completed"): - -```js -index.searchAsync(query).then(callback); -index.searchAsync(query).then(callback); -index.searchAsync(query).then(callback); -``` - -Or when you have just one callback when all requests are done, simply use `Promise.all()` which also prioritize "all tasks completed": - -```js -Promise.all([ - - index.searchAsync(query).then(callback), - index.searchAsync(query).then(callback), - index.searchAsync(query).then(callback) - -]).then(callback); -``` - -Inside the callback of `Promise.all()` you will also get an array of results as the first parameter respectively for each query you put into. - -When using `await` you can prioritize the order (prioritize "first task completed") and solve requests one by one and just process the sub-tasks in parallel: - -```js -await index.searchAsync(query); -await index.searchAsync(query); -await index.searchAsync(query); -``` - -Same for `index.add()`, `index.append()`, `index.remove()` or `index.update()`. Here there is a special case which isn't disabled by the library, but you need to keep in mind when using Workers. - -When you call the "synced" version on a worker index: - -```js -index.add(doc); -index.add(doc); -index.add(doc); -// contents aren't indexed yet, -// they just queued on the message channel -``` - -Of course, you can do that but keep in mind that the main thread does not have an additional queue for distributed worker tasks. Running these in a long loop fires content massively to the message channel via `worker.postMessage()` internally. Luckily the browser and Node.js will handle such incoming tasks for you automatically (as long enough free RAM is available). When using the "synced" version on a worker index, the content isn't indexed one line below, because all calls are treated as async by default. - -> When adding/updating/removing large bulks of content to the index (or high frequency), it is recommended to use the async version along with `async/await` to keep a low memory footprint during long processes. - -## Export / Import - -### Export - -The export has slightly changed. The export now consist of several smaller parts, instead of just one large bulk. You need to pass a callback function which has 2 arguments "key" and "data". This callback function is called by each part, e.g.: - -```js -index.export(function(key, data){ - - // you need to store both the key and the data! - // e.g. use the key for the filename and save your data - - localStorage.setItem(key, data); -}); -``` - -Exporting data to the localStorage isn't really a good practice, but if size is not a concern then use it if you like. The export primarily exists for the usage in Node.js or to store indexes you want to delegate from a server to the client. - -> The size of the export corresponds to the memory consumption of the library. To reduce export size you have to use a configuration which has less memory footprint (use the table at the bottom to get information about configs and its memory allocation). - -When your save routine runs asynchronously you have to return a promise: - -```js -index.export(function(key, data){ - - return new Promise(function(resolve){ - - // do the saving as async - - resolve(); - }); -}); -``` - -> You cannot export the additional table for the "fastupdate" feature. These table exists of references and when stored they fully get serialized and becomes too large. The lib will handle these automatically for you. When importing data, the index automatically disables "fastupdate". - -### Import - -Before you can import data, you need to create your index first. For document indexes provide the same document descriptor you used when export the data. This configuration isn't stored in the export. - -```js -var index = new Index({ ... }); -``` - -To import the data just pass a key and data: - -```js -index.import(key, localStorage.getItem(key)); -``` - -You need to import every key! Otherwise, your index does not work. You need to store the keys from the export and use this keys for the import (the order of the keys can differ). - -This is just for demonstration and is not recommended, because you might have other keys in your localStorage which aren't supported as an import: - -```js -var keys = Object.keys(localStorage); - -for(let i = 0, key; i < keys.length; i++){ - - key = keys[i]; - index.import(key, localStorage.getItem(key)); -} -``` - - - -## Benchmark (Search) - -### Contextual Search - -FlexSearch v0.6.3 (fastest profile): - -``` -query-single 4313828 op/s, Memory: 1 -query-multi 1526028 op/s, Memory: 1 -query-long 57181 op/s, Memory: 8 -query-dupes 1460489 op/s, Memory: 1 -not-found 2423155 op/s, Memory: 1 -``` - -FlexSearch v0.7.0 (equivalent profile): - -``` -query-single 7344119 op/s, Memory: 1 -query-multi 2460401 op/s, Memory: 1 -query-long 931957 op/s, Memory: 1 -query-dupes 2137628 op/s, Memory: 1 -not-found 3028110 op/s, Memory: 1 -``` - -This is a performance gain up to 16x faster. - -### Lexical Search - -FlexSearch v0.6.3 (fastest profile): - -``` -query-single 4154241 op/s, Memory: 1 -query-multi 175687 op/s, Memory: 3 -query-long 1453 op/s, Memory: 516 -query-dupes 969917 op/s, Memory: 1 -not-found 2289013 op/s, Memory: 1 -``` - -There was a performance leak when using extra long queries (for this test I've picked a worst-case scenario). - -FlexSearch v0.7.0 (equivalent profile): - -``` -query-single 7362096 op/s, Memory: 1 -query-multi 580524 op/s, Memory: 4 -query-long 645983 op/s, Memory: 2 -query-dupes 2136893 op/s, Memory: 1 -not-found 3061433 op/s, Memory: 1 -``` - -This is a performance gain up to 450x faster, also reduced memory allocation up to 250x. - -### Search + Cache - -FlexSearch v0.6.3: - -``` -query-single 2342487 op/s, Memory: 1 -query-multi 2445660 op/s, Memory: 1 -query-long 3823374 op/s, Memory: 1 -query-dupes 4162607 op/s, Memory: 1 -not-found 3858238 op/s, Memory: 1 -``` - -A fun fact is that the new version is almost as fast as the old version with cache enabled. - -FlexSearch v0.7.0: - -``` -query-single 29266333 op/s, Memory: 1 -query-multi 35164612 op/s, Memory: 1 -query-long 33610046 op/s, Memory: 1 -query-dupes 30240771 op/s, Memory: 1 -not-found 36181951 op/s, Memory: 1 -``` - -This is a performance gain up to 14 times faster. - -## Benchmark (Add, Update, Delete) - -One part which also gets massively improvements is the update and removal of indexed contents by `index.update(id, content)` or by `index.remove(id)`. That was the worst case scenario for FlexSearch. - -The new option flag "fastupdate" make use of an additional register and pushes performance of all updates and removals of __already indexed contents__ by a factor up to 2850x faster. This additional register comes with a moderate memory cost (+5%). When your index needs to be updated __already indexed contents__ frequently, then this option is highly recommended. When just adding new contents (with new IDs), this option is useless and the extra memory cost isn't worth it. - -FlexSearch v0.6.3 (fastest profile): - -``` -add 84788 op/s, Memory: 166 -update 717 op/s, Memory: 785 -remove 1186 op/s, Memory: 535 -``` - -FlexSearch v0.7.0 (equivalent profile): - -``` -add 261529 op/s, Memory: 3 -update 3043 op/s, Memory: 113 -remove 5572 op/s, Memory: 530 -``` - -This is a performance gain up to 5x faster. - -FlexSearch v0.7.0 + "fastupdate" enabled: - -``` -add 261172 op/s, Memory: 3 -update 238025 op/s, Memory: 1 -remove 3430364 op/s, Memory: 1 -``` - -This is a performance gain up to 2850x faster. - -## Contextual Search - -The advantage of using a contextual search is the scoring of relevance which take the distance between each term from the indexed documents into account. That brings relevance search to a complete new level compared to TF-IDF. In fact a TF-IDF tells nothing about the relevance of a query which exist of multiple terms. TF-IDF is just useful when using one term queries and is also used by FlexSearch as a fallback for this purpose. - -The context starts by a query which have more than one term and will increase for each additional term. Often you will need 3 or 4 words to get the __absolutely perfect match__ in a complex document. A nice bonus is the performance boost you will get by internally cutting down the intersection calculations on multiple-term queries. - -The contextual index is an additional index to the pre-scored lexical standard index. This addition comes with a memory cost. - -## Memory Allocation - -The book "Gulliver's Travels Swift Jonathan 1726" was fully indexed for the examples below. - -The most memory-optimized meaningful setting will allocate just 1.2 Mb for the whole book indexed! This is probably the most tiny memory footprint you will get from a search library. - -```js -import { encode } from "./lang/latin/extra.js"; - -index = new Index({ - encode: encode, - tokenize: "strict", - optimize: true, - resolution: 1, - minlength: 3, - fastupdate: false, - context: false -}); -``` - -### Compare Impact of Memory Allocation - -by default a lexical index is very small:
-`depth: 0, bidirectional: 0, resolution: 3, minlength: 0` => 2.1 Mb - -a higher resolution will increase the memory allocation:
-`depth: 0, bidirectional: 0, resolution: 9, minlength: 0` => 2.9 Mb - -using the contextual index will increase the memory allocation:
-`depth: 1, bidirectional: 0, resolution: 9, minlength: 0` => 12.5 Mb - -a higher contextual depth will increase the memory allocation:
-`depth: 2, bidirectional: 0, resolution: 9, minlength: 0` => 21.5 Mb - -a higher minlength will decrease memory allocation:
-`depth: 2, bidirectional: 0, resolution: 9, minlength: 3` => 19.0 Mb - -using bidirectional will decrease memory allocation:
-`depth: 2, bidirectional: 1, resolution: 9, minlength: 3` => 17.9 Mb - -enable the option "fastupdate" will increase memory allocation:
-`depth: 2, bidirectional: 1, resolution: 9, minlength: 3` => 6.3 Mb - -### Full Comparison Table - -Every search library is constantly in competition with these 4 properties: - -1. Memory Allocation -2. Performance -3. Matching Capabilities -4. Relevance Order (Scoring) - -FlexSearch provides you many parameters you can use to adjust the optimal balance for your specific use-case. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ModifierMemory Impact *Performance Impact **Matching Impact **Scoring Impact **
resolution+1 (per level)+1 (per level)0+2 (per level)
depth+4 (per level)-1 (per level)-10 + depth+10
minlength-2 (per level)+2 (per level)-3 (per level)+2 (per level)
bidirectional-20+3-1
fastupdate+1+10 (update, remove)00
optimize: true-7-10-3
encoder: "icase"0000
encoder: "simple"-2-1+20
encoder: "advanced"-3-2+40
encoder: "extra"-5-5+60
encoder: "soundex"-6-2+80
tokenize: "strict"0000
tokenize: "forward"+3-2+50
tokenize: "reverse"+5-4+70
tokenize: "full"+8-5+100
document index+3 (per field)-1 (per field)00
document tags+1 (per tag)-1 (per tag)00
store: true+5 (per document)000
store: [fields]+1 (per field)000
cache: true+10+1000
cache: 100+1+900
type of ids: number0000
type of ids: string+3-300
-* range from -10 to 10, lower is better (-10 => big decrease, 0 => unchanged, +10 => big increase)
-** range from -10 to 10, higher is better - ---- - -Copyright 2019 Nextapps GmbH
-Released under the Apache 2.0 License
diff --git a/doc/custom-builds.md b/doc/custom-builds.md index ae471f0..aef7f50 100644 --- a/doc/custom-builds.md +++ b/doc/custom-builds.md @@ -1,6 +1,9 @@ ## Custom Builds -The `/src/` folder of this repository requires some compilation to resolve the build flags. Those are your options: +The `/src/` folder of this repository requires some compilation to resolve the build flags. + + You can run any of the basic builds located in the `/dist/` folder, e.g.: @@ -62,115 +66,123 @@ The custom build will be saved to `dist/flexsearch.custom.xxxx.min.js` or when f SUPPORT_WORKER true, false - + Worker Indexes SUPPORT_ENCODER true, false - + When not included you'll need to pass a custom encode method when creating an index SUPPORT_CHARSET true, false - + Includes: LatinBalance, LatinAdvanced, LatinExtra, LatinSoundex SUPPORT_CACHE true, false - + Support for index.searchCache() SUPPORT_ASYNC true, false - Asynchronous Rendering (support Promises) + The async version of index standard methods SUPPORT_STORE true, false - + Document Datastore SUPPORT_SUGGESTION true, false - + Use the option suggestions when searching SUPPORT_SERIALIZE true, false - + Export / Import / Serialize Index SUPPORT_DOCUMENT true, false - + Document Indexes SUPPORT_TAGS true, false - + Tag-Search SUPPORT_PERSISTENT true, false - + Use any of the persistent indexes SUPPORT_KEYSTORE true, false - + Extended size for InMemory indexes + SUPPORT_RESOLVER true, false - + Apply complex queries by chaining boolean operations + + + + SUPPORT_HIGHLIGHTING + true, false + Result Highlighting for Document-Search (also requires SUPPORT_STORE)
Compiler Flags DEBUG - true, false - Output debug information to the console (default: false) + true, false + Apply common checks and throw errors more frequently, output debug information and helpful hints to the console - RELEASE




- custom
custom.module
bundle
bundle.module
es5
light
compact - + RELEASE + custom
custom.module + Choose build schema: custom = Legacy Browser (window.FlexSearch), custom.module = ES6 Modules (ESM) POLYFILL - true, false - Include Polyfills (based on LANGUAGE_OUT) + true, false + Include Polyfills (based on LANGUAGE_OUT) PROFILER - true, false + true, false Just used for automatic performance tests - LANGUAGE_OUT










+ LANGUAGE_OUT ECMASCRIPT3
ECMASCRIPT5
ECMASCRIPT_2015
ECMASCRIPT_2016
ECMASCRIPT_2017
ECMASCRIPT_2018
ECMASCRIPT_2019
ECMASCRIPT_2020
ECMASCRIPT_2021
ECMASCRIPT_2022
ECMASCRIPT_NEXT
STABLE Target language diff --git a/doc/result-highlighting.md b/doc/result-highlighting.md index 8e2da58..fe3753c 100644 --- a/doc/result-highlighting.md +++ b/doc/result-highlighting.md @@ -4,12 +4,13 @@ Demo: $1" + // use highlighting options or pass a template, where $1 is + // a placeholder for the matched partial + highlight: "$1", + // optionally pick and apply search to just + // one field and get back a flat result + pluck: "title" }); ``` The result will look like: -```js +```json [{ - "field": "title", - "result": [{ - "id": 1, - "doc": { - "id": 1, - "title": "Carmencita" - }, - "highlight": "Carmencita" - },{ - "id": 2, - "doc": { - "id": 2, - "title": "Le clown et ses chiens" - }, - "highlight": "Le clown et ses chiens" - } - ] + "id": 1, + "highlight": "Carmencita" +},{ + "id": 2, + "highlight": "Le clown et ses chiens" }] ``` + +There are several options to customize result highlighting. + +### Highlighting Options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionValuesDescriptionDefault
template + String + The template to be applied on matches (e.g. "<b>$1</b>"), where $1 is a placeholder for the matched partial(mandatory)
boundary + Boundary Options
+ Number +
Limit the total length of highlighted content (add ellipsis by default). The template markup does not stack to the total length.false
ellipsis + Ellipsis Options
+ Boolean
+ String +
+ Define a custom ellipsis or disable + "..."
merge + Boolean + Wrap consecutive matches by just a single templatefalse
clip + Boolean + Allow to clip termstrue
Boundary Options
boundary.total + Number + Limit the total length of highlighted contentfalse
boundary.before + Number + Limit the length of content before highlighted parts(auto)
boundary.after + Number + Limit the length of content after highlighted parts(auto)
Ellipsis Options
ellipsis.template + String + The template to be applied on ellipsis (e.g. "<i>$1</i>"), where $1 is a placeholder for the ellipsis(mandatory)
ellipsis.pattern + Boolean
+ String +
+ Define a custom ellipsis or disable + "..."
+ +### Boundaries & Alignment + +You can limit the length of the highlighted content and also define a custom ellipsis. +By default, all matches are automatically aligned to fit into the total size. You can customize these boundaries when also passing limits for surrounded text. + +Add some content to the index: +```js +index.add({ + "id": 1, + "title": "Lorem ipsum dolor sit amet consetetur sadipscing elitr." +}); +``` + +Perform a highlighted search (no boundaries): +```js +const result = index.search({ + query: "sit amet", + highlight: "$1" +}); +``` + +Result: +```js +"Lorem ipsum dolor sit amet consetetur sadipscing elitr." +``` +___ + +#### Limit total boundary +```js +const result = index.search({ + query: "sit amet", + highlight: { + template: "$1", + boundary: 32 + } +}); +``` +> The highlight markup does not stack to the total length. +> +Result: +```js +"...um dolor sit amet consetet..." +``` +___ + +#### Define custom ellipsis (text) +```js +const result = index.search({ + query: "sit amet", + highlight: { + template: "$1", + boundary: 32, + ellipsis: "[...]" + } +}); +``` + +Result: +```js +"[...] dolor sit amet conset[...]" +``` + +You can also apply `""` or `false` to remove ellipsis. +___ + +#### Do not clip terms +```js +const result = index.search({ + query: "sit amet", + highlight: { + template: "$1", + boundary: 32, + clip: false + } +}); +``` + +Result: +```js +"... dolor sit amet ..." +``` +--- + +#### Merge consecutive matches +```js +const result = index.search({ + query: "sit amet", + highlight: { + template: "$1", + boundary: 32, + merge: true + } +}); +``` + +Result: +```js +"...um dolor sit amet consetet..." +``` +--- + +#### Limit surrounded text + +> Each of the boundary limits are optionally. Combine them as needed. + +```js +const result = index.search({ + query: "sit amet", + highlight: { + template: "$1", + boundary: { + // length before match + before: 3, + // length after match + after: 15, + // overall length + total: 32 + } + } +}); +``` + +Result: +```js +"...or sit amet consetetur sad..." +``` + +#### Use custom ellipsis (markup) + +When using markup within `ellipsis`, the markup length stack up to the total boundary. You can provide a `template` also for ellipsis to apply total boundary properly by do not stack up the markup length. + +```js +const result = index.search({ + query: "sit amet", + highlight: { + template: "$1", + // limit the total length to 32 chars + boundary: 32, + ellipsis: { + // pass a template, where $1 is + // a placeholder for the ellipsis + template: "$1", + // define custom ellipsis + pattern: "..." + } + } +}); +``` + +Result: +```js +"... dolor sit amet conset..." +``` diff --git a/index.d.ts b/index.d.ts index c877f62..4d3fb19 100644 --- a/index.d.ts +++ b/index.d.ts @@ -105,6 +105,9 @@ declare module "flexsearch" { type WorkerConfigPath = string; type SerializedFunctionString = string; type FieldName = string; + /** + * The template to be applied on matches (e.g. "\$1\"), where \$1 is a placeholder for the matched partial + */ type TemplateResultHighlighting = string; /** @@ -254,6 +257,7 @@ declare module "flexsearch" { content: string, callback?: AsyncCallback ): Promise; + /** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */ appendAsync( id: Id, content: string, @@ -383,9 +387,9 @@ declare module "flexsearch" { field?: Array | DocumentSearchOptions | string[] | string; index?: Array | DocumentSearchOptions | string[] | string; pluck?: FieldName | DocumentSearchOptions; + highlight?: HighlightOptions | TemplateResultHighlighting; enrich?: boolean; merge?: boolean; - highlight?: TemplateResultHighlighting; }; type DocumentValue = @@ -453,11 +457,13 @@ declare module "flexsearch" { document: DocumentData, callback?: AsyncCallback ): Promise; + /** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */ appendAsync( id: Id, document: DocumentData, callback?: AsyncCallback ): Promise; + /** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */ appendAsync( document: DocumentData, callback?: AsyncCallback @@ -533,20 +539,38 @@ declare module "flexsearch" { type ResolverOptions = DefaultResolve & { index?: Index | Document; - resolve?: boolean; - suggest?: boolean; - /** only usable when "resolve" was set to true */ - enrich?: boolean; - boost?: number; - limit?: number; - offset?: number; + pluck?: FieldName; + field?: FieldName; and?: ResolverOptions | Array; or?: ResolverOptions | Array; xor?: ResolverOptions | Array; not?: ResolverOptions | Array; - pluck?: FieldName; - field?: FieldName; + boost?: number; + suggest?: boolean; + resolve?: boolean; + limit?: number; + offset?: number; + /** only usable when "resolve" was set to true */ + enrich?: boolean; + }; + type HighlightBoundaryOptions = { + before?: number; + after?: number; + total?: number; + }; + + type HighlightEllipsisOptions = { + template?: TemplateResultHighlighting; + pattern?: string | boolean; + }; + + type HighlightOptions = { + template?: TemplateResultHighlighting; + boundary?: HighlightBoundaryOptions | number; + ellipsis?: HighlightEllipsisOptions | string | boolean; + clip?: boolean; + merge?: boolean; }; export class Encoder { diff --git a/package-lock.json b/package-lock.json index c408d92..90d9e13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.158", + "version": "0.8.160", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.158", + "version": "0.8.160", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 53e03e6..81dd7a4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.158", + "version": "0.8.160", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", @@ -64,25 +64,25 @@ }, "scripts": { "build": "npm run build:bundle && npm run build:bundle:debug && exit 0", - "build:bundle": "node task/build RELEASE=bundle DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false", - "build:bundle:debug": "node task/build RELEASE=bundle DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:compact": "node task/build RELEASE=compact DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", - "build:compact:debug": "node task/build RELEASE=compact DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:light": "node task/build RELEASE=light DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", - "build:light:debug": "node task/build RELEASE=light DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:es5": "node task/build RELEASE=es5 DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false LANGUAGE_OUT=ECMASCRIPT5_STRICT", - "build:es5:debug": "node task/build RELEASE=es5 DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT LANGUAGE_OUT=ECMASCRIPT5_STRICT", + "build:bundle": "node task/build RELEASE=bundle DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false", + "build:bundle:debug": "node task/build RELEASE=bundle DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:compact": "node task/build RELEASE=compact DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", + "build:compact:debug": "node task/build RELEASE=compact DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:light": "node task/build RELEASE=light DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_HIGHLIGHTING=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", + "build:light:debug": "node task/build RELEASE=light DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_HIGHLIGHTING=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:es5": "node task/build RELEASE=es5 DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false LANGUAGE_OUT=ECMASCRIPT5_STRICT", + "build:es5:debug": "node task/build RELEASE=es5 DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT LANGUAGE_OUT=ECMASCRIPT5_STRICT", "build:lang": "node task/build RELEASE=lang", "build:db": "npx rollup tmp/db/indexeddb/index.js --file dist/db/indexeddb/index.cjs --format cjs && npx rollup tmp/db/postgres/index.js --file dist/db/postgres/index.cjs --format cjs && npx rollup tmp/db/sqlite/index.js --file dist/db/sqlite/index.cjs --format cjs && npx rollup tmp/db/mongodb/index.js --file dist/db/mongodb/index.cjs --format cjs && npx rollup tmp/db/redis/index.js --file dist/db/redis/index.cjs --format cjs && npx rollup tmp/db/clickhouse/index.js --file dist/db/clickhouse/index.cjs --format cjs", "build:module": "node task/babel && exit 0", "build:module:debug": "node task/babel DEBUG=true && exit 0", "build:module:min": "node task/babel RELEASE=min && exit 0", - "build:module:bundle": "node task/build RELEASE=bundle.module DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false", - "build:module:bundle:debug": "node task/build RELEASE=bundle.module DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:module:compact": "node task/build RELEASE=compact.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", - "build:module:compact:debug": "node task/build RELEASE=compact.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:module:light": "node task/build RELEASE=light.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", - "build:module:light:debug": "node task/build RELEASE=light.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:module:bundle": "node task/build RELEASE=bundle.module DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false", + "build:module:bundle:debug": "node task/build RELEASE=bundle.module DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:module:compact": "node task/build RELEASE=compact.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", + "build:module:compact:debug": "node task/build RELEASE=compact.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_HIGHLIGHTING=true SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:module:light": "node task/build RELEASE=light.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_HIGHLIGHTING=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", + "build:module:light:debug": "node task/build RELEASE=light.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_HIGHLIGHTING=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", "build:all": "npm run build:bundle && npm run build:bundle:debug && npm run build:light && npm run build:light:debug && npm run build:compact && npm run build:compact:debug && npm run build:module && npm run build:module:debug && npm run build:module:min && npm run build:module:bundle && npm run build:module:bundle:debug && npm run build:module:light && npm run build:module:light:debug && npm run build:module:compact && npm run build:module:compact:debug && npm run build:es5 && npm run build:es5:debug && npm run build:lang && npm run build:db", "build:custom": "node task/build RELEASE=custom", "test:all": "cd test/ && npm install && npm run test:all && cd ..", diff --git a/src/bundle.js b/src/bundle.js index 7abc0a3..53d57ea 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -23,7 +23,10 @@ import { EncoderOptions, EncoderSplitOptions, PersistentOptions, - ResolverOptions + ResolverOptions, + HighlightBoundaryOptions, + HighlightEllipsisOptions, + HighlightOptions } from "./type.js"; import StorageInterface from "./db/interface.js"; import Document from "./document.js"; @@ -305,6 +308,19 @@ if(SUPPORT_SERIALIZE){ /** @export */ ResolverOptions.pluck; /** @export */ ResolverOptions.field; +/** @export */ HighlightBoundaryOptions.before; +/** @export */ HighlightBoundaryOptions.after; +/** @export */ HighlightBoundaryOptions.total; + +/** @export */ HighlightEllipsisOptions.template; +/** @export */ HighlightEllipsisOptions.pattern; + +/** @export */ HighlightOptions.template; +/** @export */ HighlightOptions.boundary; +/** @export */ HighlightOptions.ellipsis; +/** @export */ HighlightOptions.clip; +/** @export */ HighlightOptions.merge; + const FlexSearch = { "Index": Index, "Charset": SUPPORT_CHARSET ? Charset : null, diff --git a/src/config.js b/src/config.js index a599317..e1935ce 100644 --- a/src/config.js +++ b/src/config.js @@ -1,5 +1,5 @@ /** @define {string} */ -export const RELEASE = "custom"; +export const RELEASE = "source"; /** @define {boolean} */ export const DEBUG = true; @@ -50,4 +50,7 @@ export const SUPPORT_KEYSTORE = true; export const SUPPORT_COMPRESSION = false; /** @define {boolean} */ -export const SUPPORT_RESOLVER = true; \ No newline at end of file +export const SUPPORT_RESOLVER = true; + +/** @define {boolean} */ +export const SUPPORT_HIGHLIGHTING = true; \ No newline at end of file diff --git a/src/document/highlight.js b/src/document/highlight.js new file mode 100644 index 0000000..e81cd1b --- /dev/null +++ b/src/document/highlight.js @@ -0,0 +1,841 @@ +// COMPILER BLOCK --> +import { DEBUG } from "../config.js"; +// <-- COMPILER BLOCK +import { parse_simple } from "../common.js"; +import Index from "../index.js"; +import { + EnrichedDocumentSearchResults, + EnrichedSearchResults, + HighlightOptions +} from "../type.js"; + +/** + * @param {string} query + * @param {EnrichedDocumentSearchResults|EnrichedSearchResults} result + * @param {Map} index + * @param {string} pluck + * @param {HighlightOptions|string} config + * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} + */ +export function highlight_fields(query, result, index, pluck, config){ + + // The biggest issue is dealing with custom encoders, for this reason + // a combined regular expression can't apply as a template + + let template, markup_open, markup_close; + + if(typeof config === "string"){ + template = config; + config = ""; + } + else{ + template = config.template; + } + + if(DEBUG){ + if(!template){ + throw new Error('No template pattern was specified by the search option "highlight"'); + } + } + + markup_open = template.indexOf("$1"); + + if(DEBUG){ + if(markup_open === -1){ + throw new Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + template); + } + } + + markup_close = template.substring(markup_open + 2); + markup_open = template.substring(0, markup_open); + + let boundary = config && config.boundary; + let clip = !config || config.clip !== false; + let merge = config && config.merge && markup_close && markup_open && new RegExp(markup_close + " " + markup_open, "g"); + let ellipsis = config && config.ellipsis; + + let ellipsis_markup_length = 0; + let ellipsis_markup; + if(typeof ellipsis === "object"){ + ellipsis_markup = ellipsis.template; + ellipsis_markup_length = ellipsis_markup.length - 2; + ellipsis = ellipsis.pattern; + } + if(typeof ellipsis !== "string"){ + ellipsis = ellipsis === false ? "" : "..."; + } + if(ellipsis_markup_length){ + ellipsis = ellipsis_markup.replace("$1", ellipsis); + } + + let ellipsis_length = ellipsis.length - ellipsis_markup_length; + let boundary_before, boundary_after; + + if(typeof boundary === "object"){ + boundary_before = boundary.before; + if(boundary_before === 0) boundary_before = -1; + boundary_after = boundary.after; + if(boundary_after === 0) boundary_after = -1; + boundary = boundary.total || 9e5; + } + + // cache shared encoders across fields + let encoder = new Map(); + let query_enc; + let tokenize; + + // todo remove this loop and pass in the field data directly + // todo support field-specific configuration + + // for every field + for(let i = 0, enc, idx, path; i < result.length; i++){ + + /** @type {EnrichedSearchResults} */ + let res; + + if(pluck){ + res = result; + path = pluck; + } + else{ + const tmp = result[i]; + path = tmp.field; + // skip when not a field entry (e.g. tags) + if(!path) continue; + res = tmp.result; + } + + idx = index.get(path); + enc = idx.encoder; + tokenize = idx.tokenize; + query_enc = encoder.get(enc); + + // re-encode query when encoder has changed or take cache from shared encoders + if(typeof query_enc !== "string"){ + query_enc = enc.encode(query); + encoder.set(enc, query_enc); + } + + // for every doc in results + for(let j = 0; j < res.length; j++){ + + const doc = res[j]["doc"]; + if(!doc) continue; + const content = parse_simple(doc, path); + if(!content) continue; + // just split on whitespace and keep original string (encoder split can't apply) + const doc_org = content.trim().split(/\s+/); + if(!doc_org.length) continue; + + let str = ""; + let str_arr = []; + let pos_matches = []; + let pos_first_match = -1; + let pos_last_match = -1; + let length_matches_all = 0; + + // loop terms of encoded doc content + for(let k = 0; k < doc_org.length; k++){ + let doc_org_cur = doc_org[k]; + let doc_enc_cur = enc.encode(doc_org_cur); + doc_enc_cur = doc_enc_cur.length > 1 + ? doc_enc_cur.join(" ") + : doc_enc_cur[0]; + + let found; + + if(doc_enc_cur && doc_org_cur){ + + let doc_org_cur_len = doc_org_cur.length; + let doc_org_diff = (enc.split ? doc_org_cur.replace(enc.split, "") : doc_org_cur).length - doc_enc_cur.length; + let match = ""; + let match_length = 0; + + // loop terms of encoded query content and determine the longest match + for(let l = 0; l < query_enc.length; l++){ + let query_enc_cur = query_enc[l]; + if(!query_enc_cur) continue; + let query_enc_cur_len = query_enc_cur.length; + // add length from shrinking phonetic transformations (todo: add tests) + query_enc_cur_len += doc_org_diff; + // skip query token when match length can't exceed previously highest found match + if(match_length && query_enc_cur_len <= match_length){ + continue; + } + const position = doc_enc_cur.indexOf(query_enc_cur); + if(position > -1){ + match = + // prefix + (position ? doc_org_cur.substring(0, position) : "") + + // match + markup_open + doc_org_cur.substring(position, position + query_enc_cur_len) + markup_close + + // suffix + (position + query_enc_cur_len < doc_org_cur_len ? doc_org_cur.substring(position + query_enc_cur_len) : ""); + match_length = query_enc_cur_len; + found = true; + } + //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position, match) + } + + // apply the longest match + if(match){ + if(boundary){ + // the outer boundary is used to check if all matches are within the total boundary + // if so, it can apply a simpler alignment + if(pos_first_match < 0){ + pos_first_match = str.length + (str ? 1 : 0); + } + pos_last_match = str.length + (str ? 1 : 0) + match.length; + // the overall length of all matches is used to check if matches exceeds the total boundary + // if so, it can early stop further processing + length_matches_all += doc_org_cur_len; + // the match positions are used to pick items for the final result more quickly + pos_matches.push(str_arr.length) + // collect every term as match or text + str_arr.push({ match }); + } + str += (str ? " " : "") + match; + } + } + + if(!found){ + const text = doc_org[k]; + str += (str ? " " : "") + text; + // collect every term as match or text + boundary && str_arr.push({ text }); + } + else if(boundary){ + if(length_matches_all >= boundary){ + // matches has reached total boundary + break; + } + } + } + + // the markup length does not apply to the total boundary + let markup_length = pos_matches.length * (template.length - 2); + + // apply boundaries and align highlights + if(boundary_before || boundary_after || (boundary && (str.length - markup_length) > boundary)){ + + // also reduce ellipsis length from boundary + let boundary_length = boundary + markup_length - ellipsis_length * 2; + let length = pos_last_match - pos_first_match; + let start, end; + + if(boundary_before > 0){ + length += boundary_before; + } + if(boundary_after > 0){ + length += boundary_after; + } + + // 1. all matches are withing the overall boundary (apply simple alignment) + if(length <= boundary_length){ + + start = boundary_before + ? pos_first_match - (boundary_before > 0 ? boundary_before : 0) + : pos_first_match - ((boundary_length - length) / 2 | 0); + end = boundary_after + ? pos_last_match + (boundary_after > 0 ? boundary_after : 0) + : start + boundary_length; + + // do not clip terms + if(!clip){ + if(start > 0){ + if(str.charAt(start) === " "){} + else if(str.charAt(start - 1) !== " "){ + start = str.indexOf(" ", start); + (start < 0) && (start = 0); + } + } + if(end < str.length){ + if(str.charAt(end - 1) === " "){} + else if(str.charAt(end) !== " "){ + end = str.lastIndexOf(" ", end); + end < pos_last_match + ? end = pos_last_match + : ++end; + } + } + } + + str = (start ? ellipsis : "") + str.substring(start, end) + (end < str.length ? ellipsis : ""); + } + // 2. matches needs to be split by surrounded terms to fit into the boundary + else{ + + const final = []; + const check = {}; + const seamless = {}; + const finished = {}; + const before = {}; + const after = {}; + let final_length = 0; + let shift_left = 0; + let shift_right = 0; + let loop_left = 1; + let loop_right = 1; + + while(true){ + + let loop; + + for(let k = 0, pos; k < pos_matches.length; k++){ + + pos = pos_matches[k]; + + // 1. add matches to the result + if(!shift_right){ + str = str_arr[pos].match; + + // initialize custom boundaries for each slot + if(boundary_before){ + before[k] = boundary_before; + } + if(boundary_after){ + after[k] = boundary_after; + } + + // count whitespaces between each term + if(k){ + final_length++; + } + + let close; + + // close left side when first term was matched + if(!pos){ + // it can be set before content was added, + // because the first term match is always added + seamless[k] = 1; + finished[k] = 1; + } + // initial ellipsis + else if(!k && ellipsis_length){ + final_length += ellipsis_length; + } + + // close right side when last term was matched + if(pos >= doc_org.length - 1){ + close = 1; + } + // close right side when next term was a match + else if((pos < str_arr.length - 1) && str_arr[pos + 1].match){ + close = 1; + } + else if(ellipsis_length){ + final_length += ellipsis_length; + } + + // reduce template length on matches + final_length -= template.length - 2; + + // at least add one match + if(!k || (final_length + str.length <= boundary)){ + final[k] = str; + } + else{ + seamless[k] = 0; + loop = loop_left = loop_right = 0; + break; + } + + // update state when term was added + if(close){ + seamless[k + 1] = 1; + finished[k + 1] = 1; + } + } + // 2. add surrounded text to the result + else{ + // alternate direction term by term + // 2.1. extend to right first (index: k + 1) + if(shift_left !== shift_right){ + if(finished[k + 1]) continue; + pos += shift_right; + + // overlap with other slot + if(check[pos]){ + final_length -= ellipsis_length; + seamless[k + 1] = 1; + finished[k + 1] = 1; + continue; + } + // end reached + if(pos >= str_arr.length - 1){ + if(pos >= str_arr.length){ + finished[k + 1] = 1; + if(pos >= doc_org.length){ + seamless[k + 1] = 1; + } + continue; + } + final_length -= ellipsis_length; + } + + str = str_arr[pos].text; + + let current_after = boundary_after && after[k]; + if(current_after){ + if(current_after > 0){ + if(str.length > current_after){ + finished[k + 1] = 1; + if(clip){ + str = str.substring(0, current_after); + } + else{ + continue; + } + } + current_after -= str.length; + if(!current_after) current_after = -1; + after[k] = current_after; + } + else{ + finished[k + 1] = 1; + continue; + } + } + + // count whitespaces between each term + if(final_length + str.length + 1 <= boundary){ + str = " " + str; + final[k] += str; + } + else if(clip){ + const diff = boundary - final_length - 1; + if(diff > 0){ + str = " " + str.substring(0, diff); + final[k] += str; + } + finished[k + 1] = 1; + } + else{ + finished[k + 1] = 1; + continue; + } + } + // 2.2. extend to left (index: k) + else{ + if(finished[k]) continue; + pos -= shift_left; + + // overlap with other slot + if(check[pos]){ + final_length -= ellipsis_length; + finished[k] = 1; + seamless[k] = 1; + continue; + } + // start reached + if(pos <= 0){ + if(pos < 0){ + finished[k] = 1; + seamless[k] = 1; + continue; + } + final_length -= ellipsis_length; + } + + str = str_arr[pos].text; + + let current_before = boundary_before && before[k]; + if(current_before){ + if(current_before > 0){ + if(str.length > current_before){ + finished[k] = 1; + if(clip){ + str = str.substring(str.length - current_before); + } + else{ + continue; + } + } + current_before -= str.length; + if(!current_before) current_before = -1; + before[k] = current_before; + } + else{ + finished[k] = 1; + continue; + } + } + + // count whitespaces between each term + if(final_length + str.length + 1 <= boundary){ + str += " "; + final[k] = str + final[k]; + } + else if(clip){ + const diff = str.length + 1 - (boundary - final_length); + if(diff >= 0 && diff < str.length){ + str = str.substring(diff) + " "; + final[k] = str + final[k]; + } + finished[k] = 1; + } + else{ + finished[k] = 1; + continue; + } + } + } + + // update state when term was added + final_length += str.length; + check[pos] = 1; + loop = 1; + } + + if(loop){ + // alternate shift direction + shift_left === shift_right + ? shift_right++ + : shift_left++; + } + else{ + // check finish state + shift_left === shift_right + ? loop_left = 0 + : loop_right = 0; + // break process when both directions are done + if(!loop_left && !loop_right){ + break; + } + // continue with opposite direction + if(loop_left){ + shift_left++; + shift_right = shift_left; + } + else{ + shift_right++; + } + } + } + + str = ""; + for(let k = 0, tmp; k < final.length; k++){ + tmp = (k && seamless[k] ? " " : (k && !ellipsis ? " " : "") + ellipsis) + final[k]; + str += tmp; + } + if(ellipsis && !seamless[final.length]){ + str += ellipsis; + } + //console.log(query, seamless, final) + } + } + + if(merge){ + str = str.replace(/** @type {RegExp} */ (merge), " "); + } + + res[j]["highlight"] = str; + } + + if(pluck){ + break; + } + } + + return result; +} + +// /** +// * @param {string} query +// * @param {EnrichedDocumentSearchResults|EnrichedSearchResults} result +// * @param {Map} index +// * @param {string} pluck +// * @param {HighlightOptions|string} config +// * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} +// */ +// export function highlight_fields(query, result, index, pluck, config){ +// +// // The biggest issue is dealing with custom encoders, for this reason +// // a combined regular expression can't apply as a template +// +// let template, markup_open, markup_close; +// +// if(typeof config === "string"){ +// template = config; +// config = ""; +// } +// else{ +// template = config.template; +// } +// +// if(DEBUG){ +// if(!template){ +// throw new Error('No template pattern was specified by the search option "highlight"'); +// } +// } +// +// markup_open = template.indexOf("$1"); +// +// if(DEBUG){ +// if(markup_open === -1){ +// throw new Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + template); +// } +// } +// +// markup_close = template.substring(markup_open + 2); +// markup_open = template.substring(0, markup_open); +// +// let boundary = config && config.boundary; +// let clip = !config || config.clip !== false; +// let merge = config && config.merge && markup_close && markup_open && new RegExp(markup_close + " " + markup_open, "g"); +// let ellipsis = config && config.ellipsis; +// if(typeof ellipsis !== "string"){ +// ellipsis = "..."; +// } +// +// let boundary_before, boundary_after; +// +// if(typeof boundary === "object"){ +// boundary_before = boundary.before; +// if(boundary_before === 0) boundary_before = -1; +// boundary_after = boundary.after; +// if(boundary_after === 0) boundary_after = -1; +// boundary = boundary.total || 9e5; +// } +// +// // cache shared encoders across fields +// let encoder = new Map(); +// let query_enc; +// let tokenize; +// +// // todo remove this loop and pass in the field data directly +// // todo support field-specific configuration +// +// // for every field +// for(let i = 0, enc, idx, path; i < result.length; i++){ +// +// /** @type {EnrichedSearchResults} */ +// let res; +// +// if(pluck){ +// res = result; +// path = pluck; +// } +// else{ +// const tmp = result[i]; +// path = tmp.field; +// // skip when not a field entry (e.g. tags) +// if(!path) continue; +// res = tmp.result; +// } +// +// idx = index.get(path); +// enc = idx.encoder; +// tokenize = idx.tokenize; +// query_enc = encoder.get(enc); +// +// // re-encode query when encoder has changed or take cache from shared encoders +// if(typeof query_enc !== "string"){ +// query_enc = enc.encode(query); +// encoder.set(enc, query_enc); +// } +// +// // for every doc in results +// for(let j = 0; j < res.length; j++){ +// +// const doc = res[j]["doc"]; +// if(!doc) continue; +// const content = parse_simple(doc, path); +// if(!content) continue; +// const doc_org = content.trim().split(/\s+/); +// if(!doc_org.length) continue; +// +// let str = ""; +// let pos_matches = []; +// let length_matches_all = 0; +// +// // loop terms of encoded doc content +// for(let k = 0; k < doc_org.length; k++){ +// let doc_org_cur = doc_org[k]; +// let doc_org_cur_len = doc_org_cur.length; +// let doc_enc_cur = enc.encode(doc_org_cur); +// doc_enc_cur = doc_enc_cur.length > 1 +// ? doc_enc_cur.join(" ") +// : doc_enc_cur[0]; +// +// let found; +// +// if(doc_enc_cur && doc_org_cur){ +// +// let match = ""; +// let match_length = 0; +// +// // loop terms of encoded query content and determine the longest match +// for(let l = 0; l < query_enc.length; l++){ +// let query_enc_cur = query_enc[l]; +// if(!query_enc_cur) continue; +// let query_enc_cur_len = query_enc_cur.length; +// // add length from shrinking phonetic transformations (todo: add tests) +// query_enc_cur_len += doc_org_cur.length - doc_enc_cur.length; +// // skip query token when match length can't exceed previously highest found match +// if(match_length && query_enc_cur_len <= match_length){ +// continue; +// } +// const position = doc_enc_cur.indexOf(query_enc_cur); +// //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position) +// if(position > -1){ +// match = +// // prefix +// (position ? doc_org_cur.substring(0, position) : "") + +// // match +// markup_open + doc_org_cur.substring(position, position + query_enc_cur_len) + markup_close + +// // suffix +// (position + query_enc_cur_len < doc_org_cur_len ? doc_org_cur.substring(position + query_enc_cur_len) : ""); +// match_length = query_enc_cur_len; +// found = true; +// } +// } +// +// // apply the longest match +// if(match){ +// if(boundary){ +// if(!pos_matches.length && k) length_matches_all += ellipsis.length; +// // the overall length of all matches is used to check if matches exceeds the total boundary +// // if so, it can early stop further processing +// length_matches_all += match.length;//doc_org_cur_len + (str ? 1 : 0) + (k < doc_org.length - 1 ? ellipsis.length : 0); +// // the match positions are used to pick items for the final result more quickly +// pos_matches.push([ +// str.length + (str ? 1 : 0), +// str.length + (str ? 1 : 0) + match.length, +// k +// ]); +// } +// str += (str ? " " : "") + match; +// } +// } +// +// if(!found){ +// const text = doc_org[k]; +// str += (str ? " " : "") + text; +// } +// else if(boundary){ +// if(length_matches_all >= boundary){ +// // matches has reached total boundary +// break; +// } +// } +// } +// +// // the markup length does not apply to the total boundary +// let markup_length = pos_matches.length * (template.length - 2); +// +// // apply boundaries and align highlights +// if(boundary_before || boundary_after || (boundary && (str.length - markup_length) > boundary)){ +// +// let final = ""; +// let surrounded_length = (((((boundary + markup_length) - length_matches_all) / pos_matches.length) - ellipsis.length) / 2); +// //if(surrounded_length < 0) surrounded_length = 0; +// +// let before = boundary_before || ( +// surrounded_length > 0 +// ? Math.floor(surrounded_length + +// (boundary_after +// ? surrounded_length - boundary_after +// : 0)) +// : 0 +// ); +// let after = boundary_after || ( +// surrounded_length > 0 +// ? Math.ceil(surrounded_length + +// (boundary_before +// ? surrounded_length - boundary_before +// : 0)) +// : 0 +// ); +// +// //console.log(surrounded_length, before, after) +// +// for(let k = 0, cur, prev, next; k < pos_matches.length; k++){ +// +// prev = cur; +// cur = next || pos_matches[k]; +// next = pos_matches[k + 1]; +// +// let start = cur[0] - before; +// let end = cur[1] + after; +// let closed_left; +// let closed_right; +// +// // if(k){ +// // closed_left = 1; +// // } +// +// // apply right limit +// if(next && (end >= next[0] - before)){ +// end = cur[1] + (next[0] - cur[1]) / 2 | 0; +// start -= ellipsis.length + 1; +// closed_right = 1; +// } +// // apply left limit +// if(prev && (start <= prev[1] + after)){ +// start = cur[0] - (cur[0] - prev[1]) / 2 | 0; +// end += ellipsis.length + 1; +// closed_left = 1; +// +// // repeat right limit +// if(next && (end >= next[0] - before)){ +// end = cur[1] + (next[0] - cur[1]) / 2 | 0; +// closed_right = 1; +// } +// } +// +// //console.log(start, end, prev, cur, next); +// +// // do not clip terms +// if(!clip){ +// if(start){ +// if(str.charAt(start) === " "){ +// //start++; +// } +// else if(str.charAt(start - 1) !== " "){ +// start = str.indexOf(" ", start); +// start < 0 +// ? start = cur[0] +// : start;//++; +// } +// } +// if(end < str.length){ +// if(str.charAt(end - 1) === " "){ +// //end--; +// } +// else if(str.charAt(end) !== " "){ +// end = str.lastIndexOf(" ", end); +// end < cur[1] +// ? end = cur[1] +// : end++; +// } +// } +// } +// +// final += +// /*(final ? " " : "") +*/ +// (!closed_left && start > 0 ? ellipsis : "") + +// str.substring(start, end) + +// (!closed_right && cur[2] < doc_org.length - 1 ? ellipsis : ""); +// +// //console.log(final) +// } +// +// str = final; +// } +// +// if(merge){ +// str = str.replace(merge, " "); +// } +// +// res[j]["highlight"] = str; +// } +// +// if(pluck){ +// break; +// } +// } +// +// return result; +// } \ No newline at end of file diff --git a/src/document/search.js b/src/document/search.js index 2fcc8f9..58c7487 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -1,7 +1,7 @@ // COMPILER BLOCK --> import { DEBUG, - PROFILER, + PROFILER, SUPPORT_HIGHLIGHTING, SUPPORT_PERSISTENT, SUPPORT_RESOLVER, SUPPORT_STORE, @@ -19,12 +19,13 @@ import { SearchResults, IntermediateSearchResults } from "../type.js"; -import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; +import { create_object, is_array, is_object, is_string } from "../common.js"; import { intersect_union } from "../intersect.js"; import Document from "../document.js"; import Index from "../index.js"; import Resolver from "../resolver.js"; import tick from "../profiler.js"; +import { highlight_fields } from "./highlight.js"; /** * @param {!string|DocumentSearchOptions} query @@ -120,8 +121,8 @@ Document.prototype.search = function(query, limit, options, _promises){ } } - enrich = SUPPORT_STORE && this.store && options.enrich && resolve; - highlight = enrich && options.highlight; + highlight = SUPPORT_STORE && SUPPORT_HIGHLIGHTING && resolve && this.store && options.highlight; + enrich = SUPPORT_STORE && (highlight || (resolve && this.store && options.enrich)); limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -258,6 +259,7 @@ Document.prototype.search = function(query, limit, options, _promises){ offset = field_options.offset || offset; suggest = SUPPORT_SUGGESTION && (field_options.suggest || suggest); enrich = SUPPORT_STORE && this.store && (field_options.enrich || enrich); + highlight = SUPPORT_STORE && SUPPORT_HIGHLIGHTING && enrich && (options.highlight || highlight); } if(_promises){ @@ -496,125 +498,6 @@ Document.prototype.search = function(query, limit, options, _promises){ ); } -/** - * @param {string} query - * @param {EnrichedDocumentSearchResults|EnrichedSearchResults} result - * @param {Map} index - * @param {string} pluck - * @param {string} template - * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} - */ -function highlight_fields(query, result, index, pluck, template){ - - // The biggest issue is dealing with custom encoders, for this reason - // a regular expression can't apply - // Todo: when one of the basic encoders was used, provide - // combined regex - // - // if(typeof template === "string"){ - // template = new RegExp(template, "g"); - // } - - let encoder; - let query_enc; - let tokenize; - - // for every field - for(let i = 0, enc, idx, path; i < result.length; i++){ - - /** @type {EnrichedSearchResults} */ - let res; - - if(pluck){ - res = result; - path = pluck; - } - else{ - const tmp = result[i]; - path = tmp.field; - if(!path) continue; - res = tmp.result; - } - - // skip when not a field entry (e.g. tags) - - idx = index.get(path); - enc = idx.encoder; - tokenize = idx.tokenize; - - // re-encode query when encoder has changed - if(enc !== encoder){ - encoder = enc; - query_enc = encoder.encode(query); - } - - // for every doc in results - for(let j = 0; j < res.length; j++){ - let str = ""; - let content = parse_simple(res[j]["doc"], path); - //let doc_enc = encoder.encode(content); - let doc_org = content.split(/\s+/); - - // loop terms of encoded doc content - for(let k = 0, doc_org_cur, doc_enc_cur; k < doc_org.length; k++){ - doc_org_cur = doc_org[k]; - //doc_enc_cur = doc_enc[k]; - doc_enc_cur = enc.encode(doc_org_cur); - doc_enc_cur = doc_enc_cur.length > 1 - ? doc_enc_cur.join(" ") - : doc_enc_cur[0]; - - let found; - - if(doc_enc_cur && doc_org_cur){ - - // loop terms of encoded query content - for(let l = 0, query_enc_cur; l < query_enc.length; l++){ - query_enc_cur = query_enc[l]; - // todo tokenize could be custom also when "strict" was used - if(tokenize === "strict"){ - if(doc_enc_cur === query_enc_cur){ - str += (str ? " " : "") + template.replace("$1", doc_org_cur); - found = true; - break; - } - } - else{ - const position = doc_enc_cur.indexOf(query_enc_cur); - //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position) - if(position > -1){ - str += (str ? " " : "") + - // prefix - doc_org_cur.substring(0, position) + - // match - template.replace("$1", doc_org_cur.substring(position, position + query_enc_cur.length)) + - // suffix - doc_org_cur.substring(position + query_enc_cur.length); - found = true; - break; - } - } - - //str += doc_enc[k].replace(new RegExp("(" + doc_enc[k] + ")", "g"), template.replace("$1", content)) - } - } - - if(!found){ - str += (str ? " " : "") + doc_org[k]; - } - } - - res[j]["highlight"] = str; - } - - if(pluck){ - break; - } - } - - return result; -} - // todo support Resolver // todo when searching through multiple fields each term should // be found at least by one field to get a valid match without diff --git a/src/index.js b/src/index.js index f0e6b81..b3a8dd2 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ // COMPILER BLOCK --> import { + RELEASE, DEBUG, PROFILER, SUPPORT_ENCODER, @@ -38,6 +39,12 @@ import "./index/add.js"; import "./index/search.js"; import "./index/remove.js"; +if(DEBUG && RELEASE === "source"){ + typeof console !== "undefined" && console.log && console.log( + "You see this warning, because it looks like you are using the source folder of FlexSearch which is not intended to use directly. Consider using one of the builds from the /dist/ folder instead. More information: https://github.com/nextapps-de/flexsearch?tab=readme-ov-file#load-library-nodejs-esm-legacy-browser" + ); +} + /** * @constructor * @param {IndexOptions|string=} options Options or preset as string diff --git a/src/type.js b/src/type.js index eb4e0e6..856983c 100644 --- a/src/type.js +++ b/src/type.js @@ -142,7 +142,7 @@ export let SearchOptions = {}; * index: (Array|Array|DocumentSearchOptions|string|undefined), * pluck: (string|DocumentSearchOptions|undefined), * merge: (boolean|undefined), - * highlight: (string|undefined) + * highlight: (HighlightOptions|string|undefined) * }} */ export let DocumentSearchOptions = {}; @@ -262,3 +262,31 @@ export let PersistentOptions = {}; * }} */ export let ResolverOptions = {}; + +/** + * @typedef {{ + * before: (number|undefined), + * after: (number|undefined), + * total: (number|undefined) + * }} + */ +export let HighlightBoundaryOptions = {}; + +/** + * @typedef {{ + * template: string, + * pattern: (string|boolean|undefined) + * }} + */ +export let HighlightEllipsisOptions = {}; + +/** + * @typedef {{ + * template: string, + * boundary: (HighlightBoundaryOptions|number|undefined), + * clip: (boolean|undefined), + * merge: (boolean|undefined), + * ellipsis: (HighlightEllipsisOptions|string|boolean|undefined) + * }} + */ +export let HighlightOptions = {}; diff --git a/src/worker.js b/src/worker.js index 40d1ca7..09d6d40 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,5 +1,5 @@ // COMPILER BLOCK --> -import { SUPPORT_ASYNC } from "./config.js"; +import { SUPPORT_ASYNC, SUPPORT_WORKER } from "./config.js"; // <-- COMPILER BLOCK import { IndexOptions } from "./type.js"; import { create_object } from "./common.js"; @@ -100,17 +100,20 @@ export default function WorkerIndex(options = /** @type IndexOptions */ ({})){ : init.call(this, worker); } -register("add"); -register("append"); -register("search"); -register("update"); -register("remove"); -register("clear"); -register("export"); -register("import"); +if(SUPPORT_WORKER){ -if(SUPPORT_ASYNC){ - apply_async(WorkerIndex.prototype); + register("add"); + register("append"); + register("search"); + register("update"); + register("remove"); + register("clear"); + register("export"); + register("import"); + + if(SUPPORT_ASYNC){ + apply_async(WorkerIndex.prototype); + } } function register(key){ diff --git a/task/babel.bundle.json b/task/babel.bundle.json index de58d7c..6312a58 100644 --- a/task/babel.bundle.json +++ b/task/babel.bundle.json @@ -20,7 +20,8 @@ "SUPPORT_PERSISTENT": true, "SUPPORT_KEYSTORE": true, "SUPPORT_COMPRESSION": true, - "SUPPORT_RESOLVER": true + "SUPPORT_RESOLVER": true, + "SUPPORT_HIGHLIGHTING": true } }], "babel-plugin-minify-constant-folding", diff --git a/task/babel.debug.json b/task/babel.debug.json index 5f8bf18..9302750 100644 --- a/task/babel.debug.json +++ b/task/babel.debug.json @@ -20,7 +20,8 @@ "SUPPORT_PERSISTENT": true, "SUPPORT_KEYSTORE": true, "SUPPORT_COMPRESSION": true, - "SUPPORT_RESOLVER": true + "SUPPORT_RESOLVER": true, + "SUPPORT_HIGHLIGHTING": true } }], "babel-plugin-minify-constant-folding", diff --git a/task/babel.js b/task/babel.js index faf16ab..136dafc 100644 --- a/task/babel.js +++ b/task/babel.js @@ -48,10 +48,7 @@ fs.existsSync("dist") || fs.mkdirSync("dist"); "worker", "lang", "charset/", - "charset/latin", - //"charset/arabic", - //"charset/cjk", - //"charset/cyrillic" + "charset/latin" ]; for(let i = 0, path; i < dirs.length; i++){ diff --git a/task/babel.min.json b/task/babel.min.json index 7ba01c8..d5043e9 100644 --- a/task/babel.min.json +++ b/task/babel.min.json @@ -20,7 +20,8 @@ "SUPPORT_PERSISTENT": true, "SUPPORT_KEYSTORE": true, "SUPPORT_COMPRESSION": true, - "SUPPORT_RESOLVER": true + "SUPPORT_RESOLVER": true, + "SUPPORT_HIGHLIGHTING": true } }], "babel-plugin-minify-constant-folding", diff --git a/test/highlight.js b/test/highlight.js index 69cc0a8..63420c2 100644 --- a/test/highlight.js +++ b/test/highlight.js @@ -9,7 +9,6 @@ const build_light = env && env.includes(".light"); const build_compact = env && env.includes(".compact"); const build_esm = !env || env.startsWith("module"); const Charset = _Charset || (await import("../src/charset.js")).default; -import SQLite from "flexsearch/db/sqlite"; if(!build_light) describe("Result Highlighting", function(){ @@ -46,7 +45,6 @@ if(!build_light) describe("Result Highlighting", function(){ let result = index.searchCache({ query: "karmen or clown or not found", suggest: true, - // set enrich to true (required) enrich: true, // highlight template // $1 is a placeholder for the matched partial @@ -67,7 +65,6 @@ if(!build_light) describe("Result Highlighting", function(){ result = index.searchCache({ query: "karmen or clown or not found", suggest: true, - // set enrich to true (required) enrich: true, // highlight template // $1 is a placeholder for the matched partial @@ -88,7 +85,6 @@ if(!build_light) describe("Result Highlighting", function(){ result = index.search({ query: "karmen or clown or not found", suggest: true, - // set enrich to true (required) enrich: true, pluck: "title", // highlight template @@ -141,7 +137,6 @@ if(!build_light) describe("Result Highlighting", function(){ let result = await index.searchCache({ query: "karmen or clown or not found", suggest: true, - // set enrich to true (required) enrich: true, // highlight template // $1 is a placeholder for the matched partial @@ -162,7 +157,6 @@ if(!build_light) describe("Result Highlighting", function(){ result = await index.searchCache({ query: "karmen or clown or not found", suggest: true, - // set enrich to true (required) enrich: true, // highlight template // $1 is a placeholder for the matched partial @@ -183,7 +177,6 @@ if(!build_light) describe("Result Highlighting", function(){ result = await index.search({ query: "karmen or clown or not found", suggest: true, - // set enrich to true (required) enrich: true, pluck: "title", // highlight template @@ -202,6 +195,651 @@ if(!build_light) describe("Result Highlighting", function(){ }]); }); + it.only("Should have been highlighted results by boundary properly", function(){ + + const data = [{ + "id": 1, + "title": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." + },{ + "id": 2, + "title": "Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua." + }]; + + const index = new Document({ + document: { + store: true, + index: [{ + field: "title", + tokenize: "full", + encoder: Charset.LatinBalance + }] + } + }); + + // add test data + for(let i = 0; i < data.length; i++){ + index.add(data[i]); + } + + + const tmp = index.search({ + query: "sit amet", + pluck: "title", + highlight: { + template: "$1", + boundary: 80, + clip: true + } + }); + + // ------------------------------ + + let result = index.search({ + query: "undefined akusam undefined", + suggest: true, + enrich: true, + highlight: { + // highlight template + // $1 is a placeholder for the matched partial + template: "$1", + boundary: 49 + } + }); + + expect(result[0].result).to.eql([{ + id: 2, + doc: data[1], + highlight: "...t. At vero eos et accusam et justo duo dolo..." + },{ + id: 1, + doc: data[0], + highlight: "...a. At vero eos et accusam et justo duo dolo..." + }]); + + expect(result[0].result[0].highlight.length).to.equal(49 + (3 + 4)); + expect(result[0].result[1].highlight.length).to.equal(49 + (3 + 4)); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined", + suggest: true, + enrich: true, + highlight: { + // highlight template + // $1 is a placeholder for the matched partial + template: "$1", + ellipsis: "", + boundary: 49 + } + }); + + expect(result[0].result).to.eql([{ + id: 2, + doc: data[1], + highlight: "amet. At vero eos et accusam et justo duo dolores" + },{ + id: 1, + doc: data[0], + highlight: "ptua. At vero eos et accusam et justo duo dolores" + }]); + + expect(result[0].result[0].highlight.length).to.equal(49 + (3 + 4)); + expect(result[0].result[1].highlight.length).to.equal(49 + (3 + 4)); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined", + suggest: true, + enrich: true, + highlight: { + // highlight template + // $1 is a placeholder for the matched partial + template: "$1", + clip: false, + boundary: 49 + } + }); + + expect(result[0].result).to.eql([{ + id: 2, + doc: data[1], + highlight: "... At vero eos et accusam et justo duo ..." + },{ + id: 1, + doc: data[0], + highlight: "... At vero eos et accusam et justo duo ..." + }]); + + expect(result[0].result[0].highlight.length).to.below(49 + (3 + 4)); + expect(result[0].result[1].highlight.length).to.below(49 + (3 + 4)); + + // ------------------------------ + + result = index.search({ + query: "akusam", + enrich: true, + highlight: { + template: "$1", + boundary: 5 + } + }); + + expect(result[0].result[0].highlight).to.equal("...accusam..."); + expect(result[0].result[1].highlight).to.equal("...accusam..."); + + // ------------------------------ + + result = index.search({ + query: "akusam", + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "", + boundary: 5 + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam"); + expect(result[0].result[1].highlight).to.equal("accusam"); + + // ------------------------------ + + result = index.search({ + query: "akusam", + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "", + boundary: { + before: 50, + after: 50, + total: 5 + } + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam"); + expect(result[0].result[1].highlight).to.equal("accusam"); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "", + boundary: 5 + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam"); + expect(result[0].result[1].highlight).to.equal("accusam"); + + // ------------------------------ + + result = index.search({ + query: "akus", + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "", + boundary: 5 + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam"); + expect(result[0].result[1].highlight).to.equal("accusam"); + + // ------------------------------ + + result = index.search({ + query: "cusa", + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "", + boundary: 5 + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam"); + expect(result[0].result[1].highlight).to.equal("accusam"); + + // ------------------------------ + + result = index.search({ + query: "cusa", + enrich: true, + highlight: { + template: "$1", + ellipsis: "...", + clip: false, + boundary: 5 + } + }); + + expect(result[0].result[0].highlight).to.equal("...accusam..."); + expect(result[0].result[1].highlight).to.equal("...accusam..."); + + // ------------------------------ + + result = index.search({ + query: "cusa", + enrich: true, + highlight: { + template: "$1", + ellipsis: "...", + clip: true, + boundary: 5 + } + }); + + expect(result[0].result[0].highlight).to.equal("...accusam..."); + expect(result[0].result[1].highlight).to.equal("...accusam..."); + + // ------------------------------ + + result = index.search({ + query: "akusam", + enrich: true, + highlight: { + template: "$1", + clip: true, + ellipsis: false, + boundary: { + before: 5, + after: 5 + } + } + }); + + expect(result[0].result[0].highlight).to.equal("s et accusam et j"); + expect(result[0].result[1].highlight).to.equal("s et accusam et j"); + + // ------------------------------ + + result = index.search({ + query: "akusam", + enrich: true, + highlight: { + template: "$1", + clip: true, + ellipsis: "", + boundary: { + before: 0, + after: 0 + } + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam"); + expect(result[0].result[1].highlight).to.equal("accusam"); + + // ------------------------------ + + result = index.search({ + query: "akusam", + enrich: true, + highlight: { + template: "$1", + clip: true, + ellipsis: "", + boundary: { + before: 5, + total: 50 + } + } + }); + + expect(result[0].result[0].highlight).to.equal("s et accusam et justo duo dolores et ea rebum. Lor"); + expect(result[0].result[1].highlight).to.equal("s et accusam et justo duo dolores et ea rebum. Ste"); + + // ------------------------------ + + result = index.search({ + query: "akusam", + enrich: true, + highlight: { + template: "$1", + clip: true, + ellipsis: "", + boundary: { + after: 5, + total: 50 + } + } + }); + + expect(result[0].result[0].highlight).to.equal("et. At vero eos et accusam et j"); + expect(result[0].result[1].highlight).to.equal("ua. At vero eos et accusam et j"); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + boundary: 51 + } + }); + + expect(result[0].result[0].highlight).to.equal("... eos et accusam et justo duo dolores et ea re..."); + expect(result[0].result[1].highlight).to.equal("... eos et accusam et justo duo dolores et ea re..."); + expect(result[0].result[0].highlight.length).to.equal(51 + 3 * (3 + 4)); + expect(result[0].result[1].highlight.length).to.equal(51 + 3 * (3 + 4)); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "...", + boundary: 51 + } + }); + + expect(result[0].result[0].highlight).to.equal("... eos et accusam et justo duo dolores et ea ..."); + expect(result[0].result[1].highlight).to.equal("... eos et accusam et justo duo dolores et ea ..."); + expect(result[0].result[0].highlight.length).to.below(51 + 3 * (3 + 4)); + expect(result[0].result[1].highlight.length).to.below(51 + 3 * (3 + 4)); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "", + boundary: 52 + } + }); + + expect(result[0].result[0].highlight).to.equal("vero eos et accusam et justo duo dolores et ea "); + expect(result[0].result[1].highlight).to.equal("vero eos et accusam et justo duo dolores et ea "); + expect(result[0].result[0].highlight.length).to.below(51 + 3 * (3 + 4)); + expect(result[0].result[1].highlight.length).to.below(51 + 3 * (3 + 4)); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "", + boundary: 7 + 1 + 5 + 1 + 7 + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam justo dolores"); + expect(result[0].result[1].highlight).to.equal("accusam justo dolores"); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "", + boundary: 20 + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam justo"); + expect(result[0].result[1].highlight).to.equal("accusam justo"); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + merge: true, + ellipsis: "", + boundary: 21 + } + }); + + expect(result[0].result[0].highlight).to.equal("accusam justo dolores"); + expect(result[0].result[1].highlight).to.equal("accusam justo dolores"); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "...", + boundary: 18 + } + }); + + expect(result[0].result[0].highlight).to.equal("...accusam..."); + expect(result[0].result[1].highlight).to.equal("...accusam..."); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "...", + boundary: 7 + 5 + (3 * 3) + 1 + } + }); + + expect(result[0].result[0].highlight).to.equal("...accusam...justo..."); + expect(result[0].result[1].highlight).to.equal("...accusam...justo..."); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "...", + boundary: 7 + 5 + (3 * 3) + 1 - 1 + } + }); + + expect(result[0].result[0].highlight).to.equal("...accusam..."); + expect(result[0].result[1].highlight).to.equal("...accusam..."); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: true, + ellipsis: "...", + boundary: 7 + 5 + (3 * 3) + 1 - 1 + } + }); + + expect(result[0].result[0].highlight).to.equal("...accusam..."); + expect(result[0].result[1].highlight).to.equal("...accusam..."); + + // ------------------------------ + + result = index.search({ + query: "undefined aku undefined usam undefined akusam undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "...", + boundary: 7 + 5 + (3 * 3) + 1 + } + }); + + expect(result[0].result[0].highlight).to.equal("... et accusam et ..."); + expect(result[0].result[1].highlight).to.equal("... et accusam et ..."); + expect(result[0].result[0].highlight.length).to.below(7 + 5 + (3 * 3) + 1 + 7); + expect(result[0].result[1].highlight.length).to.below(7 + 5 + (3 * 3) + 1 + 7); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined justo undefined dolores undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + clip: false, + ellipsis: "...", + boundary: 50 + } + }); + + expect(result[0].result[0].highlight).to.equal("... eos et accusam et justo duo dolores et ea ..."); + expect(result[0].result[1].highlight).to.equal("... eos et accusam et justo duo dolores et ea ..."); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined labore undefined sanktus undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + boundary: 100 + } + }); + + expect(result[0].result).to.eql([{ + id: 2, + doc: data[1], + highlight: "...sea takimata sanctus est Lorem ipsu...eos et accusam et justo...invidunt ut labore et dolore..." + },{ + id: 1, + doc: data[0], + highlight: "...invidunt ut labore et dolore magn...eos et accusam et justo...sea takimata sanctus est Lorem..." + }]); + + // ------------------------------ + + result = index.search({ + query: "undefined akusam undefined labore undefined sanktus undefined", + suggest: true, + enrich: true, + highlight: { + template: "$1", + boundary: { + before: 15, + after: 15, + total: 100 + } + } + }); + + expect(result[0].result).to.eql([{ + id: 2, + doc: data[1], + highlight: "...sea takimata sanctus est Lorem ipsu...eos et accusam et justo...invidunt ut labore et dolore..." + },{ + id: 1, + doc: data[0], + highlight: "...invidunt ut labore et dolore magn...eos et accusam et justo...sea takimata sanctus est Lorem..." + }]); + + // ------------------------------ + + result = index.search({ + query: "sit amet", + pluck: "title", + highlight: { + template: "$1", + boundary: 80, + clip: true + } + }); + + expect(result[0].highlight).to.eql("...dolor sit amet, consetetur sadipscing...r, sed diam...sed diam...sit amet."); + expect(result[1].highlight).to.eql("...or sit amet. At...sit amet, consetetur sadipscing...sed diam...sed diam..."); + + expect(result[0].highlight.length).to.below(80 + (7 * 7)); + expect(result[1].highlight.length).to.below(80 + (7 * 7)); + + // ------------------------------ + + result = index.search({ + query: "sit amet", + pluck: "title", + highlight: { + template: "$1", + boundary: 32, + clip: true + } + }); + + expect(result[0].highlight).to.eql("...sit amet, consetetur..."); + expect(result[1].highlight).to.eql("...sit amet....sit amet,..."); + + expect(result[0].highlight.length).to.below(80 + (7 * 7)); + expect(result[1].highlight.length).to.below(80 + (7 * 7)); + + // ------------------------------ + + result = index.search({ + query: "sit amet", + pluck: "title", + highlight: { + template: "$1", + boundary: 32, + ellipsis: { + template: "$1", + pattern: "..." + }, + clip: true + } + }); + + expect(result[0].highlight).to.eql("...sit amet, consetetur..."); + expect(result[1].highlight).to.eql("...sit amet....sit amet,..."); + + expect(result[0].highlight.length).to.below(80 + (7 * 7)); + expect(result[1].highlight.length).to.below(80 + (7 * 7)); + }); + it("Should have been highlighted results properly (#480)", function(){ const index = new Document({ @@ -271,7 +909,7 @@ if(!build_light) describe("Result Highlighting", function(){ it("Should have been highlighted results properly (#489)", async function(){ const index = new Document({ - encoder: Charset.LatinBalance, + encoder: Charset.Normalize, document: { store: true, index: [ @@ -296,11 +934,11 @@ if(!build_light) describe("Result Highlighting", function(){ const search = await index.search("h", { suggest: true, enrich: true, - highlight: `$1`, + highlight: `$1` }); expect(search.length).to.equal(1); expect(search[0].result.length).to.equal(1); - expect(search[0].result[0].highlight).to.equal('Published: April 14, 2025 From bold color choices to intricate patterns, there are many ways to make your springtime holiday decorations stand out from the rest. The Onion shares tips for dyeing Easter eggs.'); + expect(search[0].result[0].highlight).to.equal('Published: April 14, 2025 From bold color choices to intricate patterns, there are many ways to make your springtime holiday decorations stand out from the rest. The Onion shares tips for dyeing Easter eggs.'); }); });