From 2431b51a4fb5ec774a4df9253d5ef8c2503b3f2f Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Thu, 8 May 2025 20:47:58 +0200 Subject: [PATCH] update index.d.ts --- dist/db/redis/index.cjs | 2 +- dist/flexsearch.bundle.debug.js | 1930 ++++++++++++----------- dist/flexsearch.bundle.min.js | 110 +- dist/flexsearch.bundle.module.debug.js | 1926 +++++++++++----------- dist/flexsearch.bundle.module.min.js | 114 +- dist/flexsearch.compact.debug.js | 1322 +++++++--------- dist/flexsearch.compact.min.js | 104 +- dist/flexsearch.compact.module.debug.js | 1316 ++++++---------- dist/flexsearch.compact.module.min.js | 106 +- dist/flexsearch.es5.debug.js | 1047 ++++++------ dist/flexsearch.es5.min.js | 76 +- dist/flexsearch.light.debug.js | 5 +- dist/flexsearch.light.min.js | 10 +- dist/flexsearch.light.module.debug.js | 5 +- dist/flexsearch.light.module.min.js | 10 +- dist/module-debug/async.js | 3 + dist/module-debug/bundle.js | 6 + dist/module-debug/cache.js | 2 +- dist/module-debug/db/redis/index.js | 7 +- dist/module-debug/document/highlight.js | 1 + dist/module-debug/document/search.js | 55 +- dist/module-debug/encoder.js | 3 +- dist/module-debug/index/search.js | 23 +- dist/module-debug/intersect.js | 1 + dist/module-debug/resolver.js | 3 - dist/module-debug/type.js | 4 + dist/module-min/async.js | 2 +- dist/module-min/bundle.js | 2 +- dist/module-min/cache.js | 2 +- dist/module-min/db/redis/index.js | 2 +- dist/module-min/document/search.js | 2 +- dist/module-min/index/search.js | 2 +- dist/module/async.js | 3 + dist/module/bundle.js | 6 + dist/module/cache.js | 2 +- dist/module/db/redis/index.js | 7 +- dist/module/document/highlight.js | 1 + dist/module/document/search.js | 51 +- dist/module/encoder.js | 3 +- dist/module/index/search.js | 23 +- dist/module/intersect.js | 1 + dist/module/resolver.js | 3 - dist/module/type.js | 4 + index.d.ts | 394 +++-- package-lock.json | 4 +- package.json | 2 +- src/async.js | 6 + src/bundle.js | 6 + src/cache.js | 8 +- src/db/redis/index.js | 2 +- src/document/highlight.js | 1 + src/document/search.js | 59 +- src/index.js | 2 +- src/index/search.js | 25 +- src/intersect.js | 1 + src/resolver.js | 3 - src/type.js | 4 + test/package-lock.json | 16 +- test/package.json | 12 +- test/persistent.js | 10 +- test/types.ts | 200 ++- 61 files changed, 4455 insertions(+), 4607 deletions(-) diff --git a/dist/db/redis/index.cjs b/dist/db/redis/index.cjs index 9a6c9f5..f36353f 100644 --- a/dist/db/redis/index.cjs +++ b/dist/db/redis/index.cjs @@ -205,7 +205,7 @@ RedisDB.prototype.enrich = function(ids){ if(typeof ids !== "object"){ ids = [ids]; } - return this.db.hmGet(this.id + "doc", ids).then(function(res){ + return this.db.hmGet(this.id + "doc", this.type === "number" ? ids.map(i => "" + i) : ids).then(function(res){ for(let i = 0; i < res.length; i++){ res[i] = { id: ids[i], diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index d1c6e1f..cf4ced7 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.160 (Bundle/Debug) + * FlexSearch.js v0.8.161 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -7,30 +7,30 @@ */ (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; +function F(a, c, b) { + const e = typeof b, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { - if (c) { + if (b) { if ("function" === d && e === d) { return function(k) { - return a(c(k)); + return a(b(k)); }; } - b = a.constructor; - if (b === c.constructor) { - if (b === Array) { - return c.concat(a); + c = a.constructor; + if (c === b.constructor) { + if (c === Array) { + return b.concat(a); } - if (b === Map) { - var f = new Map(c); + if (c === Map) { + var f = new Map(b); for (var g of a) { f.set(g[0], g[1]); } return f; } - if (b === Set) { - g = new Set(c); + if (c === Set) { + g = new Set(b); for (f of a.values()) { g.add(f); } @@ -40,9 +40,9 @@ function F(a, b, c) { } return a; } - return c; + return b; } - return "undefined" === d ? b : a; + return "undefined" === d ? c : a; } function G() { return Object.create(null); @@ -54,28 +54,28 @@ function aa(a) { return "object" === typeof a; } function da(a) { - const b = []; - for (const c of a.keys()) { - b.push(c); + const c = []; + for (const b of a.keys()) { + c.push(b); } - return b; + return c; } -function ea(a, b) { - if (L(b)) { - a = a[b]; +function ea(a, c) { + if (L(c)) { + a = a[c]; } else { - for (let c = 0; a && c < b.length; c++) { - a = a[b[c]]; + for (let b = 0; a && b < c.length; b++) { + a = a[c[b]]; } } return a; } function fa(a) { - let b = 0; - for (let c = 0, e; c < a.length; c++) { - (e = a[c]) && b < e.length && (b = e.length); + let c = 0; + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && c < e.length && (c = e.length); } - return b; + return c; } ;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 = {}) { @@ -93,27 +93,27 @@ function ma(a = {}) { 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 c = a.include, b = c || a.exclude || a.split, e; + if (b || "" === b) { + if ("object" === typeof b && b.constructor !== RegExp) { 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) { - d += "object" === typeof c ? c.join("") : c; + e = !c; + c || (d += "\\p{Z}"); + b.letter && (d += "\\p{L}"); + b.number && (d += "\\p{N}", e = !!c); + b.symbol && (d += "\\p{S}"); + b.punctuation && (d += "\\p{P}"); + b.control && (d += "\\p{C}"); + if (b = b.char) { + d += "object" === typeof b ? b.join("") : b; } try { - this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); + this.split = new RegExp("[" + (c ? "^" : "") + 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+/; + console.error("Your split configuration:", b, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { - this.split = c, e = !1 === c || 2 > "a1a".split(c).length; + this.split = b, e = !1 === b || 2 > "a1a".split(b).length; } this.numeric = F(a.numeric, e); } else { @@ -126,18 +126,18 @@ v.assign = function(a) { } 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); + b = a.filter; + this.filter = "function" === typeof b ? b : F(b && new Set(b), 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.matcher = F((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = F((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = F((b = a.stemmer) && new Map(b), 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; + if (this.cache = b = F(a.cache, !0, this.cache)) { + this.H = null, this.S = "number" === typeof b ? b : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; this.M = null; @@ -155,9 +155,9 @@ v.assign = function(a) { } return this; }; -v.addStemmer = function(a, b) { +v.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); - this.stemmer.set(a, b); + this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.N = null; this.cache && N(this); @@ -168,42 +168,42 @@ v.addFilter = function(a) { this.cache && N(this); return this; }; -v.addMapper = function(a, b) { +v.addMapper = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (1 < a.length) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.mapper || (this.mapper = new Map()); - this.mapper.set(a, b); + this.mapper.set(a, c); this.cache && N(this); return this; }; -v.addMatcher = function(a, b) { +v.addMatcher = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (2 > a.length && (this.dedupe || this.mapper)) { - return this.addMapper(a, b); + return this.addMapper(a, c); } this.matcher || (this.matcher = new Map()); - this.matcher.set(a, b); + this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; this.cache && N(this); return this; }; -v.addReplacer = function(a, b) { +v.addReplacer = function(a, c) { if ("string" === typeof a) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.replacer || (this.replacer = []); - this.replacer.push(a, b); + this.replacer.push(a, c); this.cache && N(this); return this; }; -v.encode = function(a, b) { +v.encode = function(a, c) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.B.has(a)) { @@ -216,11 +216,11 @@ v.encode = function(a, b) { 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(ja, "$1 $2").replace(ka, "$1 $2").replace(ia, "$1 ")); - const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); 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) { + for (let l = 0, m, q; l < k.length; l++) { + if ((m = q = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { + if (c) { if (d[m]) { continue; } @@ -231,7 +231,7 @@ v.encode = function(a, b) { } f = m; } - if (c) { + if (b) { e.push(m); } else { if (!this.filter || ("function" === typeof this.filter ? this.filter(m) : !this.filter.has(m))) { @@ -248,28 +248,28 @@ v.encode = function(a, b) { } if (this.stemmer) { this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")); - let r; - for (; r !== m && 2 < m.length;) { - r = m, m = m.replace(this.N, q => this.stemmer.get(q)); + let p; + for (; p !== m && 2 < m.length;) { + p = m, m = m.replace(this.N, t => this.stemmer.get(t)); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { 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); + for (let p = 0, t = "", r, u; p < m.length; p++) { + r = m.charAt(p), r === t && this.dedupe || ((u = this.mapper && this.mapper.get(r)) || "" === u ? u === t && this.dedupe || !(t = u) || (h += u) : h += t = r); } m = h; } - this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, r => this.matcher.get(r))); + this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, p => this.matcher.get(p))); if (m && this.replacer) { 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)); + this.cache && q.length <= this.L && (this.G.set(q, m), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); if (m) { - if (m !== n) { - if (b) { + if (m !== q) { + if (c) { if (d[m]) { continue; } @@ -299,32 +299,32 @@ function N(a) { ;let pa, O; async function qa(a) { a = a.data; - var b = a.task; - const c = a.id; + var c = a.task; + const b = a.id; let e = a.args; - switch(b) { + switch(c) { case "init": 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}); + (c = a.factory) ? (Function("return " + c)()(self), pa = new self.FlexSearch.Index(O), delete self.FlexSearch) : pa = new P(O); + postMessage({id:b}); break; default: let d; - if ("export" === b) { + if ("export" === c) { 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".'); } e[1] ? (e[0] = O.export, e[2] = 0, e[3] = 1) : e = null; } - if ("import" === b) { + if ("import" === c) { 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".'); } e[0] && (a = await O.import.call(pa, e[0]), pa.import(e[0], a)); } else { - (d = e && pa[b].apply(pa, e)) && d.then && (d = await d); + (d = e && pa[c].apply(pa, e)) && d.then && (d = await d); } - postMessage("search" === b ? {id:c, msg:d} : {id:c}); + postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } ;function ra(a) { @@ -333,35 +333,36 @@ async function qa(a) { sa.call(a, "search"); sa.call(a, "update"); sa.call(a, "remove"); + sa.call(a, "searchCache"); } -let ta, wa, xa; +let ta, ua, xa; function ya() { ta = xa = 0; } function sa(a) { this[a + "Async"] = function() { - const b = arguments; - var c = b[b.length - 1]; + const c = arguments; + var b = c[c.length - 1]; 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()); + "function" === typeof b && (e = b, delete c[c.length - 1]); + ta ? xa || (xa = Date.now() - ua >= this.priority * this.priority * 3) : (ta = setTimeout(ya, 0), ua = Date.now()); if (xa) { const f = this; return new Promise(g => { setTimeout(function() { - g(f[a + "Async"].apply(f, b)); + g(f[a + "Async"].apply(f, c)); }, 0); }); } - const d = this[a].apply(this, b); - c = d.then ? d : new Promise(f => f(d)); - e && c.then(e); - return c; + const d = this[a].apply(this, c); + b = d.then ? d : new Promise(f => f(d)); + e && b.then(e); + return b; }; } ;let za = 0; function Aa(a = {}) { - function b(g) { + function c(g) { function k(h) { h = h.data || h; const l = h.id, m = l && d.h[l]; @@ -377,10 +378,10 @@ function Aa(a = {}) { h(d); 1e9 < za && (za = 0); }; - d.worker.postMessage({id:za, task:"init", factory:c, options:a}); + d.worker.postMessage({id:za, task:"init", factory:b, options:a}); }); } - this.worker.postMessage({task:"init", factory:c, options:a}); + this.worker.postMessage({task:"init", factory:b, options:a}); this.priority = a.priority || 4; return this; } @@ -388,12 +389,12 @@ function Aa(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 e = "undefined" === typeof window, d = this, f = Ba(c, e, a.worker); + 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 = Ba(b, e, a.worker); return f.then ? f.then(function(g) { - return b.call(d, g); - }) : b.call(this, f); + return c.call(d, g); + }) : c.call(this, f); } R("add"); R("append"); @@ -406,85 +407,85 @@ R("import"); ra(Aa.prototype); function R(a) { Aa.prototype[a] = function() { - const b = this, c = [].slice.call(arguments); - var e = c[c.length - 1]; + const c = this, b = [].slice.call(arguments); + var e = b[b.length - 1]; let d; - "function" === typeof e && (d = e, c.pop()); + "function" === typeof e && (d = e, b.pop()); e = new Promise(function(f) { - "export" === a && "function" === typeof c[0] && (c[0] = null); - b.h[++za] = f; - b.worker.postMessage({task:a, id:za, args:c}); + "export" === a && "function" === typeof b[0] && (b[0] = null); + c.h[++za] = f; + c.worker.postMessage({task:a, id:za, args:b}); }); return d ? (e.then(d), this) : e; }; } -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", +function Ba(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=" + qa.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 Ca(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 5000 | 0); +;function Ca(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { - e.push(d), e.length === b && (c.push(e), e = []); - } - e.length && c.push(e); - return c; -} -function Da(a, b) { - b || (b = new Map()); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b.set(e[0], e[1]); + e.push(d), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } -function Ea(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 1000 | 0); - for (const d of a.entries()) { - e.push([d[0], Ca(d[1])[0]]), e.length === b && (c.push(e), e = []); +function Da(a, c) { + c || (c = new Map()); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c.set(e[0], e[1]); } - e.length && c.push(e); return c; } -function Fa(a, b) { - b || (b = new Map()); - for (let c = 0, e, d; c < a.length; c++) { - e = a[c], d = b.get(e[0]), b.set(e[0], Da(e[1], d)); +function Ea(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], Ca(d[1])[0]]), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } +function Fa(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], Da(e[1], d)); + } + return c; +} function Ga(a) { - let b = [], c = []; + let c = [], b = []; for (const e of a.keys()) { - c.push(e), 250000 === c.length && (b.push(c), c = []); + b.push(e), 250000 === b.length && (c.push(b), b = []); } - c.length && b.push(c); - return b; + b.length && c.push(b); + return c; } -function Ha(a, b) { - b || (b = new Set()); - for (let c = 0; c < a.length; c++) { - b.add(a[c]); +function Ha(a, c) { + c || (c = new Set()); + for (let b = 0; b < a.length; b++) { + c.add(a[b]); } - return b; + return c; } -function Ia(a, b, c, e, d, f, g = 0) { +function Ia(a, c, b, 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); + return this.export(a, c, d, f + 1); } - if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return Ia.call(l, a, b, c, k ? e : null, d, f, g + 1); + return Ia.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return Ia.call(this, a, b, c, k ? e : null, d, f, g + 1); + return Ia.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function Ja(a, b) { - let c = ""; +function Ja(a, c) { + let b = ""; for (const e of a.entries()) { a = e[0]; const d = e[1]; @@ -493,28 +494,28 @@ function Ja(a, b) { k = d[g] || [""]; let h = ""; for (let l = 0; l < k.length; l++) { - h += (h ? "," : "") + ("string" === b ? '"' + k[l] + '"' : k[l]); + h += (h ? "," : "") + ("string" === c ? '"' + k[l] + '"' : k[l]); } h = "[" + h + "]"; f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; - c += (c ? "," : "") + f; + b += (b ? "," : "") + f; } - return c; + return b; } -;function Ma(a, b, c, e) { +;function Ka(a, c, b, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { - if (g = a.index[f], b >= g.length) { - b -= g.length; + if (g = a.index[f], c >= g.length) { + c -= 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)) { + c = g[e ? "splice" : "slice"](c, b); + const k = c.length; + if (k && (d = d.length ? d.concat(c) : c, b -= k, e && (a.length -= k), !b)) { break; } - b = 0; + c = 0; } } return d; @@ -525,29 +526,29 @@ function T(a) { } this.index = a ? [a] : []; this.length = a ? a.length : 0; - const b = this; - return new Proxy([], {get(c, e) { + const c = this; + return new Proxy([], {get(b, e) { if ("length" === e) { - return b.length; + return c.length; } if ("push" === e) { return function(d) { - b.index[b.index.length - 1].push(d); - b.length++; + c.index[c.index.length - 1].push(d); + c.length++; }; } if ("pop" === e) { return function() { - if (b.length) { - return b.length--, b.index[b.index.length - 1].pop(); + if (c.length) { + return c.length--, c.index[c.index.length - 1].pop(); } }; } if ("indexOf" === e) { return function(d) { let f = 0; - for (let g = 0, k, h; g < b.index.length; g++) { - k = b.index[g]; + for (let g = 0, k, h; g < c.index.length; g++) { + k = c.index[g]; h = k.indexOf(d); if (0 <= h) { return f + h; @@ -559,8 +560,8 @@ function T(a) { } if ("includes" === e) { return function(d) { - for (let f = 0; f < b.index.length; f++) { - if (b.index[f].includes(d)) { + for (let f = 0; f < c.index.length; f++) { + if (c.index[f].includes(d)) { return !0; } } @@ -569,24 +570,24 @@ function T(a) { } if ("slice" === e) { return function(d, f) { - return Ma(b, d || 0, f || b.length, !1); + return Ka(c, d || 0, f || c.length, !1); }; } if ("splice" === e) { return function(d, f) { - return Ma(b, d || 0, f || b.length, !0); + return Ka(c, d || 0, f || c.length, !0); }; } if ("constructor" === e) { return Array; } if ("symbol" !== typeof e) { - return (c = b.index[e / 2 ** 31 | 0]) && c[e]; + return (b = c.index[e / 2 ** 31 | 0]) && b[e]; } - }, set(c, e, d) { - c = e / 2 ** 31 | 0; - (b.index[c] || (b.index[c] = []))[e] = d; - b.length++; + }, set(b, e, d) { + b = e / 2 ** 31 | 0; + (c.index[b] || (c.index[b] = []))[e] = d; + c.length++; return !0; }}); } @@ -608,13 +609,13 @@ function U(a = 8) { 32 < a ? (this.B = Na, this.A = BigInt(a)) : (this.B = Oa, this.A = a); } U.prototype.get = function(a) { - const b = this.index[this.B(a)]; - return b && b.get(a); + const c = this.index[this.B(a)]; + return c && c.get(a); }; -U.prototype.set = function(a, b) { - var c = this.B(a); - 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++); +U.prototype.set = function(a, c) { + var b = this.B(a); + let e = this.index[b]; + e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++); }; function V(a = 8) { if (!this || this.constructor !== V) { @@ -626,18 +627,18 @@ function V(a = 8) { 32 < a ? (this.B = Na, this.A = BigInt(a)) : (this.B = Oa, this.A = 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++); + var c = this.B(a); + let b = this.index[c]; + b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.h.push(b), this.size++); }; v = U.prototype; v.has = V.prototype.has = function(a) { - const b = this.index[this.B(a)]; - return b && b.has(a); + const c = this.index[this.B(a)]; + return c && c.has(a); }; v.delete = V.prototype.delete = function(a) { - const b = this.index[this.B(a)]; - b && b.delete(a) && this.size--; + const c = this.index[this.B(a)]; + c && c.delete(a) && this.size--; }; v.clear = V.prototype.clear = function() { this.index = G(); @@ -646,67 +647,67 @@ v.clear = V.prototype.clear = 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; + for (let c of this.h[a].values()) { + yield c; } } }; 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; + for (let c of this.h[a].keys()) { + yield c; } } }; 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; + for (let c of this.h[a].entries()) { + yield c; } } }; function Oa(a) { - let b = 2 ** this.A - 1; + let c = 2 ** this.A - 1; if ("number" == typeof a) { - return a & b; + return a & c; } - let c = 0, e = this.A + 1; + let b = 0, e = this.A + 1; for (let d = 0; d < a.length; d++) { - c = (c * e ^ a.charCodeAt(d)) & b; + b = (b * e ^ a.charCodeAt(d)) & c; } - return 32 === this.A ? c + 2 ** 31 : c; + return 32 === this.A ? b + 2 ** 31 : b; } function Na(a) { - let b = BigInt(2) ** this.A - BigInt(1); - var c = typeof a; - if ("bigint" === c) { - return a & b; + let c = BigInt(2) ** this.A - BigInt(1); + var b = typeof a; + if ("bigint" === b) { + return a & c; } - if ("number" === c) { - return BigInt(a) & b; + if ("number" === b) { + return BigInt(a) & c; } - c = BigInt(0); + b = BigInt(0); let e = this.A + BigInt(1); for (let d = 0; d < a.length; d++) { - c = (c * e ^ BigInt(a.charCodeAt(d))) & b; + b = (b * e ^ BigInt(a.charCodeAt(d))) & c; } - return c; + return b; } -;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); +;Pa.prototype.add = function(a, c, b) { + aa(a) && (c = a, a = ea(c, this.key)); + if (c && (a || 0 === a)) { + if (!b && this.reg.has(a)) { + return this.update(a, c); } 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); + var d = h(c); d && e.add(a, d, !1, !0); } else { - 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 (d = h.I, !d || d(c)) { + h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), Qa(c, h, this.J, 0, e, a, h[0], b); } } } @@ -716,26 +717,26 @@ function Na(a) { d = this.tag.get(g); let k = G(); if ("function" === typeof f) { - if (f = f(b), !f) { + if (f = f(c), !f) { continue; } } else { const h = f.I; - if (h && !h(b)) { + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); - f = ea(b, f); + f = ea(c, f); } 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 (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !b || !m.includes(a))) { if (m.length === 2 ** 31 - 1) { g = new T(m); if (this.fastupdate) { - for (let n of this.reg.values()) { - n.includes(m) && (n[n.indexOf(m)] = g); + for (let q of this.reg.values()) { + q.includes(m) && (q[q.indexOf(m)] = g); } } d.set(l, m = g); @@ -749,56 +750,56 @@ function Na(a) { } } } - if (this.store && (!c || !this.store.has(a))) { + if (this.store && (!b || !this.store.has(a))) { let k; if (this.C) { k = G(); for (let h = 0, l; h < this.C.length; h++) { l = this.C[h]; - if ((c = l.I) && !c(b)) { + if ((b = l.I) && !b(c)) { continue; } let m; if ("function" === typeof l) { - m = l(b); + m = l(c); if (!m) { continue; } l = [l.V]; } else if (L(l) || l.constructor === String) { - k[l] = b[l]; + k[l] = c[l]; continue; } - Ra(b, k, l, 0, l[0], m); + Ra(c, k, l, 0, l[0], m); } } - this.store.set(a, k || b); + this.store.set(a, k || c); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Ra(a, b, c, e, d, f) { +function Ra(a, c, b, e, d, f) { a = a[d]; - if (e === c.length - 1) { - b[d] = f || a; + if (e === b.length - 1) { + c[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { - Ra(a, b, c, e, d); + for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { + Ra(a, c, b, e, d); } } else { - b = b[d] || (b[d] = G()), d = c[++e], Ra(a, b, c, e, d); + c = c[d] || (c[d] = G()), d = b[++e], Ra(a, c, b, e, d); } } } -function Qa(a, b, c, e, d, f, g, k) { +function Qa(a, c, b, e, d, f, g, k) { if (a = a[g]) { - if (e === b.length - 1) { + if (e === c.length - 1) { if (a.constructor === Array) { - if (c[e]) { - for (b = 0; b < a.length; b++) { - d.add(f, a[b], !0, !0); + if (b[e]) { + for (c = 0; c < a.length; c++) { + d.add(f, a[c], !0, !0); } return; } @@ -808,33 +809,33 @@ function Qa(a, b, c, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Qa(a, b, c, e, d, f, g, k); + Qa(a, c, b, e, d, f, g, k); } } else { - g = b[++e], Qa(a, b, c, e, d, f, g, k); + g = c[++e], Qa(a, c, b, e, d, f, g, k); } } } else { d.db && d.remove(f); } } -;function Sa(a, b, c, e, d, f, g) { +;function Sa(a, c, b, 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); + for (let q = 0, p, t, r, u; q < c; q++) { + for (let n = 0; n < k; n++) { + if (r = a[n], q < r.length && (p = r[q])) { + for (let z = 0; z < p.length; z++) { + t = p[z]; + (m = l[t]) ? l[t]++ : (m = 0, l[t] = 1); u = h[m] || (h[m] = []); if (!g) { - let x = n + (p || !d ? 0 : f || 0); + let x = q + (n || !d ? 0 : f || 0); u = u[x] || (u[x] = []); } - u.push(q); - if (g && c && m === k - 1 && u.length - e === c) { + u.push(t); + if (g && b && m === k - 1 && u.length - e === b) { return e ? u.slice(e) : u; } } @@ -843,28 +844,28 @@ function Qa(a, b, c, e, d, f, g, 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; + h = 1 < h.length ? Ta(h, b, e, g, f) : (h = h[0]).length > b || e ? h.slice(e, b + e) : h; } else { if (a < k) { return []; } h = h[a - 1]; - if (c || e) { + if (b || e) { if (g) { - if (h.length > c || e) { - h = h.slice(e, c + e); + if (h.length > b || e) { + h = h.slice(e, b + e); } } else { d = []; - for (let n = 0, r; n < h.length; n++) { - if (r = h[n], r.length > e) { - e -= r.length; + for (let q = 0, p; q < h.length; q++) { + if (p = h[q], p.length > e) { + e -= p.length; } else { - if (r.length > c || e) { - r = r.slice(e, c + e), c -= r.length, e && (e -= r.length); + if (p.length > b || e) { + p = p.slice(e, b + e), b -= p.length, e && (e -= p.length); } - d.push(r); - if (!c) { + d.push(p); + if (!b) { break; } } @@ -876,7 +877,7 @@ function Qa(a, b, c, e, d, f, g, k) { } return h; } -function Ta(a, b, c, e, d) { +function Ta(a, c, b, e, d) { const f = [], g = G(); let k; var h = a.length; @@ -886,10 +887,10 @@ function Ta(a, b, c, e, 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--; + if (g[k] = 1, b) { + b--; } else { - if (f.push(k), f.length === b) { + if (f.push(k), f.length === c) { return f; } } @@ -898,18 +899,18 @@ function Ta(a, b, c, e, d) { } } } else { - for (let m = h - 1, n, r = 0; 0 <= m; m--) { - n = a[m]; - 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--; + for (let m = h - 1, q, p = 0; 0 <= m; m--) { + q = a[m]; + for (let t = 0; t < q.length; t++) { + if (l = (e = q[t]) && e.length) { + for (let r = 0; r < l; r++) { + if (k = e[r], !g[k]) { + if (g[k] = 1, b) { + b--; } else { - let u = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + let u = (t + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; (f[u] || (f[u] = [])).push(k); - if (++r === b) { + if (++p === c) { return f; } } @@ -921,51 +922,51 @@ function Ta(a, b, c, e, d) { } return f; } -function Ua(a, b, c) { +function Ua(a, c, b) { const e = G(), d = []; - for (let f = 0, g; f < b.length; f++) { - g = b[f]; + for (let f = 0, g; f < c.length; f++) { + g = c[f]; for (let k = 0; k < g.length; k++) { e[g[k]] = 1; } } - if (c) { + if (b) { for (let f = 0, g; f < a.length; f++) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { for (let f = 0, g, k; f < a.result.length; f++) { - for (g = a.result[f], b = 0; b < g.length; b++) { - k = g[b], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); + for (g = a.result[f], c = 0; c < g.length; c++) { + k = g[c], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); } } } return d; } -;function Va(a, b, c, e) { +;function Va(a, c, b, 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, e ? X.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? X.call(this, a) : a; } let d = []; for (let f = 0, g, k; f < a.length; f++) { if ((g = a[f]) && (k = g.length)) { - if (c) { - if (c >= k) { - c -= k; + if (b) { + if (b >= k) { + b -= k; continue; } - c < k && (g = b ? g.slice(c, c + b) : g.slice(c), k = g.length, c = 0); + b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); } - k > b && (g = g.slice(0, b), k = b); - if (!d.length && k >= b) { + k > c && (g = g.slice(0, c), k = c); + if (!d.length && k >= c) { return e ? X.call(this, g) : g; } d.push(g); - b -= k; - if (!b) { + c -= k; + if (!c) { break; } } @@ -973,45 +974,45 @@ function Ua(a, b, c) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? X.call(this, d) : d; } -;function Wa(a, b, c) { - var e = c[0]; +;function Wa(a, c, b) { + var e = b[0]; if (e.then) { - return Promise.all(c).then(function(m) { - return a[b].apply(a, m); + return Promise.all(b).then(function(m) { + return a[c].apply(a, m); }); } if (e[0] && e[0].index) { - return a[b].apply(a, e); + return a[c].apply(a, e); } e = []; let d = [], f = 0, g = 0, k, h, l; - for (let m = 0, n; m < c.length; m++) { - if (n = c[m]) { - let r; - if (n.constructor === Y) { - r = n.result; - } else if (n.constructor === Array) { - r = n; + for (let m = 0, q; m < b.length; m++) { + if (q = b[m]) { + let p; + if (q.constructor === Y) { + p = q.result; + } else if (q.constructor === Array) { + p = q; } 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 = q.limit || 0, g = q.offset || 0, l = q.suggest, h = q.resolve, k = q.enrich && h, q.index) { + q.resolve = !1, q.enrich = !1, p = q.index.search(q).result, q.resolve = h, q.enrich = k; + } else if (q.and) { + p = a.and(q.and); + } else if (q.or) { + p = a.or(q.or); + } else if (q.xor) { + p = a.xor(q.xor); + } else if (q.not) { + p = a.not(q.not); } else { continue; } } - if (r.then) { - d.push(r); - } else if (r.length) { - e[m] = r; - } else if (!l && ("and" === b || "xor" === b)) { + if (p.then) { + d.push(p); + } else if (p.length) { + e[m] = p; + } else if (!l && ("and" === c || "xor" === c)) { e = []; break; } @@ -1020,119 +1021,119 @@ function Ua(a, b, c) { return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;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); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Wa(this, "or", arguments); + return Xa.call(this, a, c, b, e, d, f); }; -function Xa(a, b, c, e, d, f) { - if (b.length) { +function Xa(a, c, b, e, d, f) { + if (c.length) { const g = this; - return Promise.all(b).then(function(k) { + return Promise.all(c).then(function(k) { a = []; for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return Xa.call(g, a, [], c, e, d, f); + return Xa.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 = Ta(a, c, e, !1, this.h), e = 0)); - return f ? this.resolve(c, e, d) : this; + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ta(a, b, e, !1, this.h), e = 0)); + return f ? this.resolve(b, e, d) : this; } ;Y.prototype.and = function() { - let a = this.result.length, b, c, e, d; + let a = this.result.length, c, b, 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); + 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} = Wa(this, "and", arguments); - return Ya.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:q} = Wa(this, "and", arguments); + return Ya.call(this, f, g, k, h, l, m, q); } - return d ? this.resolve(b, c, e) : this; + return d ? this.resolve(c, b, e) : this; }; -function Ya(a, b, c, e, d, f, g) { - if (b.length) { +function Ya(a, c, b, e, d, f, g) { + if (c.length) { const k = this; - return Promise.all(b).then(function(h) { + return Promise.all(c).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); + return Ya.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 { - 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; + if (c = fa(a)) { + return this.result = Sa(a, c, b, 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; + return f ? this.resolve(b, 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); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Wa(this, "xor", arguments); + return Za.call(this, a, c, b, e, d, f, g); }; -function Za(a, b, c, e, d, f, g) { - if (b.length) { +function Za(a, c, b, e, d, f, g) { + if (c.length) { const k = this; - return Promise.all(b).then(function(h) { + return Promise.all(c).then(function(h) { a = []; for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Za.call(k, a, [], c, e, d, f, g); + return Za.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 = $a.call(this, a, c, e, f, this.h), f ? d ? X.call(this.index, this.result) : this.result : this; + return this.result = $a.call(this, a, b, 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; + return f ? this.resolve(b, e, d) : this; } -function $a(a, b, c, e, d) { +function $a(a, c, b, 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 r = 0, q; r < n.length; r++) { - q = n[r], g[q] = g[q] ? 2 : 1; + for (let m = 0, q; m < l.length; m++) { + if (q = l[m]) { + for (let p = 0, t; p < q.length; p++) { + t = q[p], g[t] = g[t] ? 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]) { - if (l = r[h]) { - for (let q = 0, t; q < l.length; q++) { - if (t = l[q], 1 === g[t]) { - if (c) { - c--; + for (let q = 0, p; q < a.length; q++) { + if (p = a[q]) { + if (l = p[h]) { + for (let t = 0, r; t < l.length; t++) { + if (r = l[t], 1 === g[r]) { + if (b) { + b--; } else { if (e) { - if (f.push(t), f.length === b) { + if (f.push(r), f.length === c) { return f; } } else { - const u = h + (n ? d : 0); + const u = h + (q ? d : 0); f[u] || (f[u] = []); - f[u].push(t); - if (++m === b) { + f[u].push(r); + if (++m === c) { return f; } } @@ -1146,43 +1147,43 @@ function $a(a, b, c, e, d) { return f; } ;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); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Wa(this, "not", arguments); + return ab.call(this, a, c, b, e, d, f, g); }; -function ab(a, b, c, e, d, f, g) { - if (b.length) { +function ab(a, c, b, e, d, f, g) { + if (c.length) { const k = this; - return Promise.all(b).then(function(h) { + return Promise.all(c).then(function(h) { a = []; for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return ab.call(k, a, [], c, e, d, f, g); + return ab.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = bb.call(this, a, c, e, f); + this.result = bb.call(this, a, b, e, f); } else if (f) { - return this.resolve(c, e, d); + return this.resolve(b, e, d); } return f ? d ? X.call(this.index, this.result) : this.result : this; } -function bb(a, b, c, e) { +function bb(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { for (let h = 0, l; h < g.length; h++) { if (l = g[h], !a.has(l)) { - if (c) { - c--; + if (b) { + b--; } else { if (e) { - if (d.push(l), d.length === b) { + if (d.push(l), d.length === c) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++k === b) { + if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { return d; } } @@ -1206,32 +1207,32 @@ function bb(a, b, c, e) { } Y.prototype.limit = function(a) { if (this.result.length) { - const b = []; - for (let c = 0, e; c < this.result.length; c++) { - if (e = this.result[c]) { + const c = []; + for (let b = 0, e; b < this.result.length; b++) { + if (e = this.result[b]) { if (e.length <= a) { - if (b[c] = e, a -= e.length, !a) { + if (c[b] = e, a -= e.length, !a) { break; } } else { - b[c] = e.slice(0, a); + c[b] = e.slice(0, a); break; } } } - this.result = b; + this.result = c; } return this; }; Y.prototype.offset = function(a) { if (this.result.length) { - const b = []; - 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); + const c = []; + for (let b = 0, e; b < this.result.length; b++) { + if (e = this.result[b]) { + e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0); } } - this.result = b; + this.result = c; } return this; }; @@ -1239,13 +1240,13 @@ Y.prototype.boost = function(a) { this.h += a; return this; }; -Y.prototype.resolve = function(a, b, c) { +Y.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Va.call(d, e, a || 100, b, c)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Va.call(d, e, a || 100, c, b)) : e; }; G(); -function cb(a, b, c, e, d) { +function cb(a, c, b, e, d) { let f, g, k; "string" === typeof d ? (f = d, d = "") : f = d.template; if (!f) { @@ -1259,89 +1260,89 @@ function cb(a, b, c, e, d) { 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; + var q = 0; if ("object" === typeof d) { - var r = d.template; - n = r.length - 2; + var p = d.template; + q = p.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++) { + q && (d = p.replace("$1", d)); + p = d.length - q; + let t, r; + "object" === typeof h && (t = h.before, 0 === t && (t = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); + q = new Map(); + for (let La = 0, ba, hb, na; La < c.length; La++) { let oa; if (e) { - oa = b, na = e; + oa = c, na = e; } else { - var u = b[Ka]; + var u = c[La]; 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) { + hb = b.get(na); + ba = hb.encoder; + u = q.get(ba); + "string" !== typeof u && (u = ba.encode(a), q.set(ba, u)); + for (let va = 0; va < oa.length; va++) { + var n = oa[va].doc; + if (!n) { continue; } - p = ea(p, na); - if (!p) { + n = ea(n, na); + if (!n) { continue; } - var z = p.trim().split(/\s+/); + var z = n.trim().split(/\s+/); if (!z.length) { continue; } - p = ""; + n = ""; var x = []; - let va = []; + let wa = []; 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]; + var E = z[A], D = ba.encode(E); + D = 1 < D.length ? D.join(" ") : D[0]; let w; - if (E && D) { - var C = D.length, H = (ba.split ? D.replace(ba.split, "") : D).length - E.length, M = "", W = 0; + if (D && E) { + var C = E.length, H = (ba.split ? E.replace(ba.split, "") : E).length - D.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)); + W && K <= W || (Q = D.indexOf(Q), -1 < Q && (M = (Q ? E.substring(0, Q) : "") + g + E.substring(Q, Q + K) + k + (Q + K < C ? E.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); + M && (h && (0 > J && (J = n.length + (n ? 1 : 0)), B = n.length + (n ? 1 : 0) + M.length, y += C, wa.push(x.length), x.push({match:M})), n += (n ? " " : "") + M); } if (!w) { - D = z[A], p += (p ? " " : "") + D, h && x.push({text:D}); + E = z[A], n += (n ? " " : "") + E, h && x.push({text:E}); } 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 : ""); + y = wa.length * (f.length - 2); + if (t || r || h && n.length - y > h) { + if (y = h + y - 2 * p, A = B - J, 0 < t && (A += t), 0 < r && (A += r), A <= y) { + z = t ? J - (0 < t ? t : 0) : J - ((y - A) / 2 | 0), x = r ? B + (0 < r ? r : 0) : z + y, l || (0 < z && " " !== n.charAt(z) && " " !== n.charAt(z - 1) && (z = n.indexOf(" ", z), 0 > z && (z = 0)), x < n.length && " " !== n.charAt(x - 1) && " " !== n.charAt(x) && (x = n.lastIndexOf(" ", x), x < B ? x = B : ++x)), n = (z ? d : "") + n.substring(z, x) + (x < n.length ? d : ""); } else { B = []; J = {}; y = {}; A = {}; - D = {}; E = {}; + D = {}; M = H = C = 0; for (ca = W = 1;;) { var S = void 0; - for (let w = 0, I; w < va.length; w++) { - I = va[w]; + for (let w = 0, I; w < wa.length; w++) { + I = wa[w]; if (M) { if (H !== M) { if (A[w + 1]) { @@ -1349,7 +1350,7 @@ function cb(a, b, c, e, d) { } I += M; if (J[I]) { - C -= r; + C -= p; y[w + 1] = 1; A[w + 1] = 1; continue; @@ -1360,29 +1361,29 @@ function cb(a, b, c, e, d) { I >= z.length && (y[w + 1] = 1); continue; } - C -= r; + C -= p; } - p = x[I].text; - if (K = t && E[w]) { + n = x[I].text; + if (K = r && D[w]) { if (0 < K) { - if (p.length > K) { + if (n.length > K) { if (A[w + 1] = 1, l) { - p = p.substring(0, K); + n = n.substring(0, K); } else { continue; } } - (K -= p.length) || (K = -1); - E[w] = K; + (K -= n.length) || (K = -1); + D[w] = K; } else { A[w + 1] = 1; continue; } } - if (C + p.length + 1 <= h) { - p = " " + p, B[w] += p; + if (C + n.length + 1 <= h) { + n = " " + n, B[w] += n; } else if (l) { - S = h - C - 1, 0 < S && (p = " " + p.substring(0, S), B[w] += p), A[w + 1] = 1; + S = h - C - 1, 0 < S && (n = " " + n.substring(0, S), B[w] += n), A[w + 1] = 1; } else { A[w + 1] = 1; continue; @@ -1393,7 +1394,7 @@ function cb(a, b, c, e, d) { } I -= H; if (J[I]) { - C -= r; + C -= p; A[w] = 1; y[w] = 1; continue; @@ -1404,52 +1405,52 @@ function cb(a, b, c, e, d) { y[w] = 1; continue; } - C -= r; + C -= p; } - p = x[I].text; - if (K = q && D[w]) { + n = x[I].text; + if (K = t && E[w]) { if (0 < K) { - if (p.length > K) { + if (n.length > K) { if (A[w] = 1, l) { - p = p.substring(p.length - K); + n = n.substring(n.length - K); } else { continue; } } - (K -= p.length) || (K = -1); - D[w] = K; + (K -= n.length) || (K = -1); + E[w] = K; } else { A[w] = 1; continue; } } - if (C + p.length + 1 <= h) { - p += " ", B[w] = p + B[w]; + if (C + n.length + 1 <= h) { + n += " ", B[w] = n + 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; + S = n.length + 1 - (h - C), 0 <= S && S < n.length && (n = n.substring(S) + " ", B[w] = n + B[w]), A[w] = 1; } else { A[w] = 1; continue; } } } else { - p = x[I].match; - q && (D[w] = q); + n = x[I].match; t && (E[w] = t); + r && (D[w] = r); 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); + let Ma; + I ? !w && p && (C += p) : (y[w] = 1, A[w] = 1); + I >= z.length - 1 ? Ma = 1 : I < x.length - 1 && x[I + 1].match ? Ma = 1 : p && (C += p); C -= f.length - 2; - if (!w || C + p.length <= h) { - B[w] = p; + if (!w || C + n.length <= h) { + B[w] = n; } else { S = W = ca = y[w] = 0; break; } - La && (y[w + 1] = 1, A[w + 1] = 1); + Ma && (y[w + 1] = 1, A[w + 1] = 1); } - C += p.length; + C += n.length; S = J[I] = 1; } if (S) { @@ -1462,59 +1463,65 @@ function cb(a, b, c, e, d) { W ? (H++, M = H) : M++; } } - p = ""; + n = ""; for (let w = 0, I; w < B.length; w++) { - I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], p += I; + I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], n += I; } - d && !y[B.length] && (p += d); + d && !y[B.length] && (n += d); } } - m && (p = p.replace(m, " ")); - oa[ua].highlight = p; + m && (n = n.replace(m, " ")); + oa[va].highlight = n; } if (e) { break; } } - return b; + return c; } -;Pa.prototype.search = function(a, b, c, e) { - c || (!b && aa(a) ? (c = a, a = "") : aa(b) && (c = b, b = 0)); - let d = []; - var f = []; - let g; - let k; - 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; - h = g || c.field || (h = c.index) && (h.index ? null : h); - l = this.tag && c.tag; - var q = c.suggest; - 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); +;Pa.prototype.search = function(a, c, b, e) { + b || (!c && aa(a) ? (b = a, a = "") : aa(c) && (b = c, c = 0)); + if (b && b.cache) { + b.cache = !1; + var d = this.searchCache(a, c, b); + b.cache = !0; + return d; + } + let f = []; + var g = []; + let k, h; + let l, m; + let q = 0; + var p = !0; + let t; + if (b) { + b.constructor === Array && (b = {index:b}); + a = b.query || a; + k = b.pluck; + h = b.merge; + l = k || b.field || (l = b.index) && (l.index ? null : l); + m = this.tag && b.tag; + var r = b.suggest; + p = !1 !== b.resolve; + if (!p && !k) { + if (l = l || this.field) { + L(l) ? k = l : (l.constructor === Array && 1 === l.length && (l = l[0]), k = l.field || l.index); } - if (!g) { + if (!k) { 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 && !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 u = c.offset || 0; - b || (b = 100); - if (l && (!this.db || !e)) { - l.constructor !== Array && (l = [l]); - var p = []; - for (let B = 0, y; B < l.length; B++) { - y = l[B]; + this.store && b.highlight && !p ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + t = p && this.store && b.highlight; + d = !!t || p && this.store && b.enrich; + c = b.limit || c; + var u = b.offset || 0; + c || (c = 100); + if (m && (!this.db || !e)) { + m.constructor !== Array && (m = [m]); + var n = []; + for (let B = 0, y; B < m.length; B++) { + y = m[B]; if (L(y)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } @@ -1522,187 +1529,190 @@ function cb(a, b, c, e, d) { var z = y.tag; if (z.constructor === Array) { for (var x = 0; x < z.length; x++) { - p.push(y.field, z[x]); + n.push(y.field, z[x]); } } else { - p.push(y.field, z); + n.push(y.field, z); } } else { 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++) { - p.push(D, E[x]); + for (let A = 0, E, D; A < z.length; A++) { + if (E = z[A], D = y[E], D.constructor === Array) { + for (x = 0; x < D.length; x++) { + n.push(E, D[x]); } } else { - p.push(D, E); + n.push(E, D); } } } } - if (!p.length) { + if (!n.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = p; + m = n; if (!a) { - n = []; - if (p.length) { - for (f = 0; f < p.length; f += 2) { + p = []; + if (n.length) { + for (g = 0; g < n.length; g += 2) { if (this.db) { - q = this.index.get(p[f]); - if (!q) { - console.warn("Tag '" + p[f] + ":" + p[f + 1] + "' will be skipped because there is no field '" + p[f] + "'."); + r = this.index.get(n[g]); + if (!r) { + console.warn("Tag '" + n[g] + ":" + n[g + 1] + "' will be skipped because there is no field '" + n[g] + "'."); continue; } - n.push(q = q.db.tag(p[f + 1], b, u, t)); + p.push(r = r.db.tag(n[g + 1], c, u, d)); } else { - q = db.call(this, p[f], p[f + 1], b, u, t); + r = db.call(this, n[g], n[g + 1], c, u, d); } - d.push({field:p[f], tag:p[f + 1], result:q}); + f.push({field:n[g], tag:n[g + 1], result:r}); } } - return n.length ? Promise.all(n).then(function(B) { + return p.length ? Promise.all(p).then(function(B) { for (let y = 0; y < B.length; y++) { - d[y].result = B[y]; + f[y].result = B[y]; } - return d; - }) : d; + return f; + }) : f; } } - h && h.constructor !== Array && (h = [h]); + l && l.constructor !== Array && (l = [l]); } - h || (h = this.field); - p = !e && (this.worker || this.db) && []; + l || (l = this.field); let J; - for (let B = 0, y, A, D; B < h.length; B++) { - A = h[B]; + n = (this.worker || this.db) && !e && []; + for (let B = 0, y, A, E; B < l.length; B++) { + A = l[B]; if (this.db && this.tag && !this.F[B]) { continue; } - let E; - 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)); + let D; + L(A) || (D = A, A = D.field, a = D.query || a, c = eb(D.limit, c), u = eb(D.offset, u), r = eb(D.suggest, r), t = p && this.store && eb(D.highlight, t), d = !!t || p && this.store && eb(D.enrich, d)); if (e) { y = e[B]; } else { - 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); + if (z = D || b, x = this.index.get(A), m && (this.db && (z.tag = m, J = x.db.support_tag_search, z.field = l), J || (z.enrich = !1)), n) { + n[B] = x.search(a, c, z); + z && d && (z.enrich = d); continue; } else { - y = x.search(a, b, z), z && t && (z.enrich = t); + y = x.search(a, c, z), z && d && (z.enrich = d); } } - D = y && (n ? y.length : y.result.length); - if (l && D) { + E = y && (p ? y.length : y.result.length); + if (m && E) { z = []; x = 0; if (this.db && e) { if (!J) { - for (let C = h.length; C < e.length; C++) { + for (let C = l.length; C < e.length; C++) { let H = e[C]; if (H && H.length) { x++, z.push(H); - } else if (!q) { - return n ? d : new Y(d); + } else if (!r) { + return p ? f : new Y(f); } } } } else { - for (let C = 0, H, M; C < l.length; C += 2) { - H = this.tag.get(l[C]); + for (let C = 0, H, M; C < m.length; C += 2) { + H = this.tag.get(m[C]); if (!H) { - if (console.warn("Tag '" + l[C] + ":" + l[C + 1] + "' will be skipped because there is no field '" + l[C] + "'."), q) { + if (console.warn("Tag '" + m[C] + ":" + m[C + 1] + "' will be skipped because there is no field '" + m[C] + "'."), r) { continue; } else { - return n ? d : new Y(d); + return p ? f : new Y(f); } } - if (M = (H = H && H.get(l[C + 1])) && H.length) { + if (M = (H = H && H.get(m[C + 1])) && H.length) { x++, z.push(H); - } else if (!q) { - return n ? d : new Y(d); + } else if (!r) { + return p ? f : new Y(f); } } } if (x) { - y = Ua(y, z, n); - D = y.length; - if (!D && !q) { - return n ? y : new Y(y); + y = Ua(y, z, p); + E = y.length; + if (!E && !r) { + return p ? y : new Y(y); } x--; } } - if (D) { - f[m] = A, d.push(y), m++; - } else if (1 === h.length) { - return n ? d : new Y(d); + if (E) { + g[q] = A, f.push(y), q++; + } else if (1 === l.length) { + return p ? f : new Y(f); } } - 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 '" + l[t] + ":" + l[t + 1] + "' was not found because there is no field '" + l[t] + "'."), q) { + if (n) { + if (this.db && m && m.length && !J) { + for (d = 0; d < m.length; d += 2) { + g = this.index.get(m[d]); + if (!g) { + if (console.warn("Tag '" + m[d] + ":" + m[d + 1] + "' was not found because there is no field '" + m[d] + "'."), r) { continue; } else { - return n ? d : new Y(d); + return p ? f : new Y(f); } } - p.push(f.db.tag(l[t + 1], b, u, !1)); + n.push(g.db.tag(m[d + 1], c, u, !1)); } } const B = this; - return Promise.all(p).then(function(y) { - return y.length ? B.search(a, b, c, y) : y; + return Promise.all(n).then(function(y) { + return y.length ? B.search(a, c, b, y) : y; }); } - if (!m) { - return n ? d : new Y(d); + if (!q) { + return p ? f : new Y(f); } - if (g && (!t || !this.store)) { - return d[0]; + if (k && (!d || !this.store)) { + return f[0]; } - 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 n ? r ? cb(a, q, this.index, g, r) : q : new Y(q); + n = []; + for (u = 0; u < g.length; u++) { + r = f[u]; + d && r.length && "undefined" === typeof r[0].doc && (this.db ? n.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = X.call(this, r)); + if (k) { + return p ? t ? cb(a, r, this.index, k, t) : r : new Y(r); } - d[u] = {field:f[u], result:q}; + f[u] = {field:g[u], result:r}; } - if (t && this.db && p.length) { + if (d && this.db && n.length) { const B = this; - return Promise.all(p).then(function(y) { + return Promise.all(n).then(function(y) { for (let A = 0; A < y.length; A++) { - d[A].result = y[A]; + f[A].result = y[A]; } - return k ? eb(d) : r ? cb(a, d, B.index, g, r) : d; + return h ? fb(f) : t ? cb(a, f, B.index, k, t) : f; }); } - return k ? eb(d) : r ? cb(a, d, this.index, g, r) : d; + return h ? fb(f) : t ? cb(a, f, this.index, k, t) : f; }; -function eb(a) { - const b = [], c = G(); +function eb(a, c) { + return "undefined" === typeof a ? c : a; +} +function fb(a) { + const c = [], b = 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)); + h = f[g], "object" !== typeof h && (h = {id:h}), k = h.id, (l = b[k]) ? l.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); } } - return b; + return c; } -function db(a, b, c, e, d) { +function db(a, c, b, 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 - e) && 0 < a) { - if (a > c || e) { - f = f.slice(e, e + c); + if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if (a > b || e) { + f = f.slice(e, e + b); } d && (f = X.call(this, f)); return f; @@ -1712,45 +1722,45 @@ function X(a) { if (!this || !this.store) { return a; } - const b = Array(a.length); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b[c] = {id:e, doc:this.store.get(e)}; + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; } - return b; + return c; } ;function Pa(a) { if (!this || this.constructor !== Pa) { return new Pa(a); } - const b = a.document || a.doc || a; - let c, e; + const c = a.document || a.doc || a; + let b, e; this.F = []; this.field = []; this.J = []; - this.key = (c = b.key || b.id) && fb(c, this.J) || "id"; + this.key = (b = c.key || c.id) && gb(b, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; 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 && (e ? new U(e) : new Map()); - this.cache = (c = a.cache || null) && new hb(c); + this.C = (b = c.store || null) && b && !0 !== b && []; + this.store = b && (e ? new U(e) : new Map()); + this.cache = (b = a.cache || null) && new ib(b); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = ib.call(this, a, b); + this.index = jb.call(this, a, c); this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { + if (b = c.tag) { + if ("string" === typeof b && (b = [b]), b.length) { this.tag = new Map(); this.D = []; this.R = []; - for (let d = 0, f, g; d < c.length; d++) { - f = c[d]; + for (let d = 0, f, g; d < b.length; d++) { + f = b[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - 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)); + 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()); } @@ -1768,15 +1778,15 @@ function X(a) { const k = new Map(); let h = 0; for (const m of f.index.entries()) { - const n = m[0]; + const q = m[0]; var l = m[1]; if (l.then) { l = d[h].encoder || {}; - let r = k.get(l); - r || (r = l.encode ? l : new ma(l), k.set(l, r)); + let p = k.get(l); + p || (p = l.encode ? l : new ma(l), k.set(l, p)); l = g[h]; - l.encoder = r; - f.index.set(n, l); + l.encoder = p; + f.index.set(q, l); h++; } } @@ -1792,51 +1802,51 @@ 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)."); } - let b = this.field; + let c = this.field; if (this.tag) { for (let f = 0, g; f < this.R.length; f++) { g = this.R[f]; - var c = void 0; - 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); + var b = void 0; + this.index.set(g, b = new P({}, this.reg)); + c === this.field && (c = c.slice(0)); + c.push(g); + b.tag = this.tag.get(g); } } - c = []; + b = []; 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]; + for (let f = 0, g, k; f < c.length; f++) { + e.field = k = c[f]; g = this.index.get(k); const h = new a.constructor(a.id, e); h.id = a.id; - c[f] = h.mount(g); + b[f] = h.mount(g); g.document = !0; f ? g.bypass = !0 : g.store = this.store; } const d = this; - return this.db = Promise.all(c).then(function() { + return this.db = Promise.all(b).then(function() { d.db = !0; }); }; -v.commit = async function(a, b) { - const c = []; +v.commit = async function(a, c) { + const b = []; for (const e of this.index.values()) { - c.push(e.commit(a, b)); + b.push(e.commit(a, c)); } - await Promise.all(c); + await Promise.all(b); this.reg.clear(); }; v.destroy = function() { const a = []; - for (const b of this.index.values()) { - a.push(b.destroy()); + for (const c of this.index.values()) { + a.push(c.destroy()); } return Promise.all(a); }; -function ib(a, b) { - const c = new Map(); - let e = b.index || b.field || b; +function jb(a, c) { + const b = new Map(); + let e = c.index || c.field || c; L(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { f = e[d]; @@ -1845,48 +1855,48 @@ function ib(a, b) { if (this.worker) { const k = new Aa(g); k.encoder = g.encoder; - c.set(f, k); + b.set(f, k); } - 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.worker || b.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; + a = c.store; 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)); + 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; + return b; } -function fb(a, b) { - const c = a.split(":"); +function gb(a, c) { + const b = a.split(":"); 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); + for (let d = 0; d < b.length; d++) { + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); } - e < c.length && (c.length = e); - return 1 < e ? c : c[0]; + e < b.length && (b.length = e); + return 1 < e ? b : b[0]; } -v.append = function(a, b) { - return this.add(a, b, !0); +v.append = function(a, c) { + return this.add(a, c, !0); }; -v.update = function(a, b) { - return this.remove(a).add(a, b); +v.update = function(a, c) { + return this.remove(a).add(a, c); }; v.remove = function(a) { aa(a) && (a = ea(a, this.key)); - for (var b of this.index.values()) { - b.remove(a, !0); + for (var c of this.index.values()) { + c.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { - for (let c of this.tag.values()) { - for (let e of c) { - b = e[0]; + for (let b of this.tag.values()) { + for (let e of b) { + c = e[0]; const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); + -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); } } } @@ -1898,13 +1908,13 @@ v.remove = function(a) { }; v.clear = function() { const a = []; - for (const b of this.index.values()) { - const c = b.clear(); - c.then && a.push(c); + for (const c of this.index.values()) { + const b = c.clear(); + b.then && a.push(b); } if (this.tag) { - for (const b of this.tag.values()) { - b.clear(); + for (const c of this.tag.values()) { + c.clear(); } } this.store && this.store.clear(); @@ -1921,92 +1931,92 @@ v.cleanup = function() { return this; }; 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; + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) { + return c[0] && c[0].doc || null; }) : this.store.get(a) || null; }; -v.set = function(a, b) { - "object" === typeof a && (b = a, a = ea(b, this.key)); - this.store.set(a, b); +v.set = function(a, c) { + "object" === typeof a && (c = a, a = ea(c, this.key)); + this.store.set(a, c); return this; }; -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, e = 1)) && b.then) { +v.searchCache = kb; +v.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) { const k = this; - return b.then(function() { - return k.export(a, g, c + 1); + return c.then(function() { + return k.export(a, g, b + 1); }); } - return this.export(a, g, c + 1); + return this.export(a, g, b + 1); } let d, f; switch(e) { case 0: d = "reg"; f = Ga(this.reg); - b = null; + c = null; break; case 1: d = "tag"; f = this.tag && Ea(this.tag, this.reg.size); - b = null; + c = null; break; case 2: d = "doc"; f = this.store && Ca(this.store); - b = null; + c = null; break; default: return; } - return Ia.call(this, a, b, d, f, c, e); + return Ia.call(this, a, c, d, f, b, e); }; -v.import = function(a, b) { - var c = a.split("."); - "json" === c[c.length - 1] && c.pop(); - const e = 2 < c.length ? c[0] : ""; - c = 2 < c.length ? c[2] : c[1]; +v.import = function(a, c) { + var b = a.split("."); + "json" === b[b.length - 1] && b.pop(); + const e = 2 < b.length ? b[0] : ""; + b = 2 < b.length ? b[2] : b[1]; if (this.worker && e) { return this.index.get(e).import(a); } - if (b) { - "string" === typeof b && (b = JSON.parse(b)); + if (c) { + "string" === typeof c && (c = JSON.parse(c)); if (e) { - return this.index.get(e).import(c, b); + return this.index.get(e).import(b, c); } - switch(c) { + switch(b) { case "reg": this.fastupdate = !1; - this.reg = Ha(b, this.reg); + this.reg = Ha(c, 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 = []; + c = []; for (const d of this.index.values()) { - b.push(d.import(a)); + c.push(d.import(a)); } - return Promise.all(b); + return Promise.all(c); } break; case "tag": - this.tag = Fa(b, this.tag); + this.tag = Fa(c, this.tag); break; case "doc": - this.store = Da(b, this.store); + this.store = Da(c, this.store); } } }; ra(Pa.prototype); -function jb(a, b, c) { - const e = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new hb()); +function kb(a, c, b) { + const e = (c ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); + this.cache || (this.cache = new ib()); let d = this.cache.get(e); if (!d) { - d = this.search(a, b, c); + d = this.search(a, c, b); if (d.then) { const f = this; d.then(function(g) { @@ -2018,81 +2028,81 @@ function jb(a, b, c) { } return d; } -function hb(a) { +function ib(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -hb.prototype.set = function(a, b) { - this.cache.set(this.h = a, b); +ib.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); }; -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; +ib.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; }; -hb.prototype.remove = function(a) { - for (const b of this.cache) { - const c = b[0]; - b[1].includes(a) && this.cache.delete(c); +ib.prototype.remove = function(a) { + for (const c of this.cache) { + const b = c[0]; + c[1].includes(a) && this.cache.delete(b); } }; -hb.prototype.clear = function() { +ib.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; c < a.length; c++) { - var b = a[c]; - 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++) { +const lb = {normalize:!1, numeric:!1, dedupe:!1}; +const mb = {}; +const nb = 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 ob = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), pb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const qb = {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 rb = {Exact:lb, Default:mb, Normalize:mb, LatinBalance:{mapper:nb}, LatinAdvanced:{mapper:nb, matcher:ob, replacer:pb}, LatinExtra:{mapper:nb, replacer:pb.concat([/(?!^)[aeo]/g, ""]), matcher:ob}, 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 = qb[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = qb[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = e; + a[b] = e; } -}}, 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) { +}}, CJK:{split:""}, LatinExact:lb, LatinDefault:mb, LatinSimple:mb}; +P.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { if (this.fastupdate) { - for (let e = 0, d; e < c.length; e++) { - if (d = c[e]) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { if (2 > d.length) { d.pop(); } else { const f = d.indexOf(a); - f === c.length - 1 ? d.pop() : d.splice(f, 1); + f === b.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - rb(this.map, a), this.depth && rb(this.ctx, a); + sb(this.map, a), this.depth && sb(this.ctx, a); } - b || this.reg.delete(a); + c || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && sb(this)); + this.db && (this.commit_task.push({del:a}), this.T && tb(this)); this.cache && this.cache.remove(a); return this; }; -function rb(a, b) { - let c = 0; - var e = "undefined" === typeof b; +function sb(a, c) { + let b = 0; + var e = "undefined" === typeof c; if (a.constructor === Array) { for (let d = 0, f, g; d < a.length; d++) { if ((f = a[d]) && f.length) { if (e) { - c++; + b++; } else { - if (g = f.indexOf(b), 0 <= g) { - 1 < f.length ? (f.splice(g, 1), c++) : delete a[d]; + if (g = f.indexOf(c), 0 <= g) { + 1 < f.length ? (f.splice(g, 1), b++) : delete a[d]; break; } else { - c++; + b++; } } } @@ -2100,37 +2110,37 @@ function rb(a, b) { } else { for (let d of a.entries()) { e = d[0]; - const f = rb(d[1], b); - f ? c += f : a.delete(e); + const f = sb(d[1], c); + f ? b += f : a.delete(e); } } - return c; + return b; } -;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 (!e && !c && this.reg.has(a)) { - return this.update(a, b); +;const ub = {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, c, b, e) { + if (c && (a || 0 === a)) { + if (!e && !b && this.reg.has(a)) { + return this.update(a, c); } e = this.depth; - b = this.encoder.encode(b, !e); - const l = b.length; + c = this.encoder.encode(c, !e); + const l = c.length; if (l) { - 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 = ""; + const m = G(), q = G(), p = this.resolution; + for (let t = 0; t < l; t++) { + let r = c[this.rtl ? l - 1 - t : t]; + var d = r.length; + if (d && (e || !q[r])) { + var f = this.score ? this.score(c, r, t, null, 0) : vb(p, l, t), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let u = 0, p; u < d; u++) { + for (let u = 0, n; 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); + g = r.substring(u, f); + n = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(c, r, t, g, n) : vb(p, l, t, d, n); + wb(this, q, g, k, a, b); } } break; @@ -2139,26 +2149,26 @@ P.prototype.add = function(a, b, c, e) { case "reverse": 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 = r[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, r, t, g, k) : vb(p, l, t, d, k); + wb(this, q, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += t[this.rtl ? d - 1 - k : k], vb(this, n, g, f, a, c); + g += r[this.rtl ? d - 1 - k : k], wb(this, q, g, f, a, b); } break; } default: - 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); + if (wb(this, q, r, f, a, b), e && 1 < l && t < l - 1) { + for (d = G(), g = this.U, f = r, k = Math.min(e + 1, this.rtl ? t + 1 : l - t), d[f] = 1, h = 1; h < k; h++) { + if ((r = c[this.rtl ? l - 1 - t - h : t + h]) && !d[r]) { + d[r] = 1; + const u = this.score ? this.score(c, f, t, r, h - 1) : vb(g + (l / 2 > g ? 0 : 1), l, t, k - 1, h - 1), n = this.bidirectional && r > f; + wb(this, m, n ? f : r, u, a, b, n ? r : f); } } } @@ -2167,105 +2177,109 @@ P.prototype.add = function(a, b, c, e) { } this.fastupdate || this.reg.add(a); } else { - b = ""; + c = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && sb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && tb(this)); return this; }; -function vb(a, b, c, e, d, f, g) { +function wb(a, c, b, 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 (!c[b] || g && !(h = c[b])[g]) { + if (g ? (c = h || (c[b] = G()), 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 = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { if (k.length === 2 ** 31 - 1) { - b = new T(k); + c = new T(k); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(k) && (l[l.indexOf(k)] = b); + l.includes(k) && (l[l.indexOf(k)] = c); } } - h[e] = k = b; + h[e] = k = c; } 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 && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; +function vb(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; } -;P.prototype.search = function(a, b, c) { - c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); - 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; +;P.prototype.search = function(a, c, b) { + b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); + if (b && b.cache) { + return b.cache = !1, a = this.searchCache(a, c, b), b.cache = !0, a; + } + let e = [], d, f, g, k = 0, h, l, m, q, p; + b && (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, p = (h = b.resolve) && b.enrich, m = b.boost, q = b.resolution, l = this.db && b.tag); + "undefined" === typeof h && (h = this.resolve); f = this.depth && !1 !== f; - let q = this.encoder.encode(a, !f); - d = q.length; - b = b || (h ? 100 : 0); + let t = this.encoder.encode(a, !f); + d = t.length; + c = c || (h ? 100 : 0); if (1 === d) { - return wb.call(this, q[0], "", b, k, h, r, l); + return xb.call(this, t[0], "", c, k, h, p, l); } if (2 === d && f && !g) { - return wb.call(this, q[1], q[0], b, k, h, r, l); + return xb.call(this, t[1], t[0], c, k, h, p, l); } - let t = G(), u = 0, p; - f && (p = q[0], u = 1); - n || 0 === n || (n = p ? this.U : this.resolution); + let r = G(), u = 0, n; + f && (n = t[0], u = 1); + q || 0 === q || (q = n ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, q, b, k, g, h, r, l), !1 !== a)) { - return a; + if (this.db.search && (b = this.db.search(this, t, c, k, g, h, p, l), !1 !== b)) { + return b; } const z = this; return async function() { 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)) { + if ((J = t[u]) && !r[J]) { + r[J] = 1; + x = await yb(z, J, n, 0, 0, !1, !1); + if (x = zb(x, e, g, q)) { e = x; break; } - p && (g && x && e.length || (p = J)); + n && (g && x && e.length || (n = J)); } - g && p && u === d - 1 && !e.length && (n = z.resolution, p = "", u = -1, t = G()); + g && n && u === d - 1 && !e.length && (q = z.resolution, n = "", u = -1, r = G()); } - return zb(e, n, b, k, g, m, h); + return Ab(e, q, c, k, g, m, h); }(); } 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)) { + if ((x = t[u]) && !r[x]) { + r[x] = 1; + z = yb(this, x, n, 0, 0, !1, !1); + if (z = zb(z, e, g, q)) { e = z; break; } - p && (g && z && e.length || (p = x)); + n && (g && z && e.length || (n = x)); } - g && p && u === d - 1 && !e.length && (n = this.resolution, p = "", u = -1, t = G()); + g && n && u === d - 1 && !e.length && (q = this.resolution, n = "", u = -1, r = G()); } - return zb(e, n, b, k, g, m, h); + return Ab(e, q, c, k, g, m, h); }; -function zb(a, b, c, e, d, f, g) { +function Ab(a, c, b, e, d, f, g) { let k = a.length, h = a; if (1 < k) { - h = Sa(a, b, c, e, d, f, g); + h = Sa(a, c, b, e, d, f, g); } else if (1 === k) { - return g ? Va.call(null, a[0], c, e) : new Y(a[0]); + return g ? Va.call(null, a[0], b, e) : new Y(a[0]); } return g ? h : new Y(h); } -function wb(a, b, c, e, d, f, g) { - a = xb(this, a, b, c, e, d, f, g); +function xb(a, c, b, e, d, f, g) { + a = yb(this, a, c, b, 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(); + }) : a && a.length ? d ? Va.call(this, a, b, e) : new Y(a) : d ? [] : new Y(); } -function yb(a, b, c, e) { +function zb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { - b.push(a); + c.push(a); return; } for (let f = 0, g; f < e; f++) { @@ -2274,53 +2288,53 @@ function yb(a, b, c, e) { } } if (d.length) { - b.push(d); + c.push(d); return; } } - if (!c) { + if (!b) { return d; } } -function xb(a, b, c, e, d, f, g, k) { +function yb(a, c, b, e, d, f, g, k) { let h; - c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); + b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); if (a.db) { - return a.db.get(b, c, e, d, f, g, k); + return a.db.get(c, b, e, d, f, g, k); } - a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); + a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;function P(a, b) { +;function P(a, c) { if (!this || this.constructor !== P) { return new P(a); } if (a) { - var c = L(a) ? a : a.preset; - c && (tb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, tb[c], a)); + var b = L(a) ? a : a.preset; + b && (ub[b] || console.warn("Preset not found: " + b), a = Object.assign({}, ub[b], a)); } else { a = {}; } - c = a.context; - const e = !0 === c ? {depth:1} : c || {}, d = L(a.encoder) ? qb[a.encoder] : a.encode || a.encoder || {}; + b = a.context; + const e = !0 === b ? {depth:1} : b || {}, d = L(a.encoder) ? rb[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.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; 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 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()); + (b = a.keystore || 0) && (this.keystore = b); + this.map = b ? new U(b) : new Map(); + this.ctx = b ? new U(b) : new Map(); + this.reg = c || (this.fastupdate ? b ? new U(b) : new Map() : b ? new V(b) : new Set()); this.U = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new hb(c); + this.cache = (b = a.cache || null) && new ib(b); this.resolve = !1 !== a.resolve; - if (c = a.db) { - this.db = this.mount(c); + if (b = a.db) { + this.db = this.mount(b); } this.T = !1 !== a.commit; this.commit_task = []; @@ -2332,15 +2346,15 @@ v.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -v.commit = function(a, b) { +v.commit = function(a, c) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, b); + return this.db.commit(this, a, c); }; v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function sb(a) { +function tb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2354,26 +2368,26 @@ v.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -v.append = function(a, b) { - return this.add(a, b, !0); +v.append = function(a, c) { + return this.add(a, c, !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.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); }; v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - rb(this.map); - this.depth && rb(this.ctx); + sb(this.map); + this.depth && sb(this.ctx); return this; }; -v.searchCache = jb; -v.export = function(a, b, c = 0, e = 0) { +v.searchCache = kb; +v.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -2395,33 +2409,33 @@ v.export = function(a, b, c = 0, e = 0) { default: return; } - return Ia.call(this, a, b, d, f, c, e); + return Ia.call(this, a, c, d, f, b, 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 < a.length ? a[1] : a[0], a) { +v.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 = Ha(b, this.reg); + this.reg = Ha(c, this.reg); break; case "map": - this.map = Da(b, this.map); + this.map = Da(c, this.map); break; case "ctx": - this.ctx = Fa(b, this.ctx); + this.ctx = Fa(c, this.ctx); } } }; v.serialize = function(a = !0) { - let b = "", c = "", e = ""; + let c = "", b = "", e = ""; if (this.reg.size) { let f; for (var d of this.reg.keys()) { - f || (f = typeof d), b += (b ? "," : "") + ("string" === f ? '"' + d + '"' : d); + f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } - b = "index.reg=new Set([" + b + "]);"; - c = Ja(this.map, f); - c = "index.map=new Map([" + c + "]);"; + c = "index.reg=new Set([" + c + "]);"; + b = Ja(this.map, f); + b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; let k = Ja(g[1], f); @@ -2431,24 +2445,24 @@ v.serialize = function(a = !0) { } e = "index.ctx=new Map([" + e + "]);"; } - return a ? "function inject(index){" + b + c + e + "}" : b + c + e; + return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; 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); +const Bb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Cb = ["map", "ctx", "tag", "reg", "cfg"], Db = G(); +function Eb(a, c = {}) { + if (!this || this.constructor !== Eb) { + return new Eb(a, c); } - "object" === typeof a && (b = a, a = a.name); + "object" === typeof a && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); this.id = "flexsearch" + (a ? ":" + a.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""); - this.field = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.type = b.type; + this.field = c.field ? c.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; + this.type = c.type; this.fastupdate = this.support_tag_search = !1; this.db = null; this.h = {}; } -v = Db.prototype; +v = Eb.prototype; v.mount = function(a) { if (a.index) { return a.mount(this); @@ -2462,20 +2476,20 @@ v.open = function() { } let a = this; navigator.storage && navigator.storage.persist(); - 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 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 : "" : "")); + Db[a.id] || (Db[a.id] = []); + Db[a.id].push(a.field); + const c = Bb.open(a.id, 1); + c.onupgradeneeded = function() { + const b = a.db = this.result; + for (let e = 0, d; e < Cb.length; e++) { + d = Cb[e]; + for (let f = 0, g; f < Db[a.id].length; f++) { + g = Db[a.id][f], b.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || b.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } } }; - return a.db = Z(b, function(c) { - a.db = c; + return a.db = Z(c, function(b) { + a.db = b; a.db.onversionchange = function() { a.close(); }; @@ -2486,25 +2500,25 @@ v.close = function() { this.db = null; }; v.destroy = function() { - const a = Ab.deleteDatabase(this.id); + const a = Bb.deleteDatabase(this.id); return Z(a); }; v.clear = function() { const a = []; - 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 : "" : "")); + for (let b = 0, e; b < Cb.length; b++) { + e = Cb[b]; + for (let d = 0, f; d < Db[this.id].length; d++) { + f = Db[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } } - const b = this.db.transaction(a, "readwrite"); - for (let c = 0; c < a.length; c++) { - b.objectStore(a[c]).clear(); + const c = this.db.transaction(a, "readwrite"); + for (let b = 0; b < a.length; b++) { + c.objectStore(a[b]).clear(); } - return Z(b); + return Z(c); }; -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); +v.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { + a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); const g = this; return Z(a).then(function(k) { let h = []; @@ -2512,7 +2526,7 @@ v.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { return h; } if (d) { - if (!c && !e && 1 === k.length) { + if (!b && !e && 1 === k.length) { return k[0]; } for (let l = 0, m; l < k.length; l++) { @@ -2521,12 +2535,12 @@ v.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { e -= m.length; continue; } - const n = c ? e + Math.min(m.length - e, c) : m.length; - for (let r = e; r < n; r++) { - h.push(m[r]); + const q = b ? e + Math.min(m.length - e, b) : m.length; + for (let p = e; p < q; p++) { + h.push(m[p]); } e = 0; - if (h.length === c) { + if (h.length === b) { break; } } @@ -2536,27 +2550,27 @@ v.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { return k; }); }; -v.tag = function(a, b = 0, c = 0, e = !1) { +v.tag = function(a, c = 0, b = 0, e = !1) { a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); const d = this; return Z(a).then(function(f) { - if (!f || !f.length || c >= f.length) { + if (!f || !f.length || b >= f.length) { return []; } - if (!b && !c) { + if (!c && !b) { return f; } - f = f.slice(c, c + b); + f = f.slice(b, b + c); 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 = []; + const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = []; for (let e = 0; e < a.length; e++) { - c[e] = Z(b.get(a[e])); + b[e] = Z(c.get(a[e])); } - return Promise.all(c).then(function(e) { + return Promise.all(b).then(function(e) { for (let d = 0; d < e.length; d++) { e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null}; } @@ -2565,30 +2579,30 @@ v.enrich = function(a) { }; v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Z(a).then(function(b) { - return !!b; + return Z(a).then(function(c) { + return !!c; }); }; v.search = null; v.info = function() { }; -v.transaction = function(a, b, c) { +v.transaction = function(a, c, b) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; - let e = this.h[a + ":" + b]; + let e = this.h[a + ":" + c]; if (e) { - return c.call(this, e); + return b.call(this, e); } - 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; + let d = this.db.transaction(a, c); + this.h[a + ":" + c] = e = d.objectStore(a); + const f = b.call(this, e); + this.h[a + ":" + c] = null; return Z(d).finally(function() { d = e = null; return f; }); }; -v.commit = async function(a, b, c) { - if (b) { +v.commit = async function(a, c, b) { + if (c) { await this.clear(), a.commit_task = []; } else { let e = a.commit_task; @@ -2596,30 +2610,30 @@ v.commit = async function(a, b, c) { for (let d = 0, f; d < e.length; d++) { if (f = e[d], f.clear) { await this.clear(); - b = !0; + c = !0; break; } else { e[d] = f.del; } } - b || (c || (e = e.concat(da(a.reg))), e.length && await this.remove(e)); + c || (b || (e = e.concat(da(a.reg))), e.length && await this.remove(e)); } 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() { + g.length && (c ? 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]); + for (let m = 0, q, p; m < l; m++) { + if ((p = g[m]) && p.length) { + if ((q = k[m]) && q.length) { + for (h = 0; h < p.length; h++) { + q.push(p[h]); } } else { - k[m] = r; + k[m] = p; } h = 1; } @@ -2635,27 +2649,27 @@ v.commit = async function(a, b, c) { 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() { + l.length && (c ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { let m = this.result; - var n; + var q; if (m && m.length) { - 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]); + const p = Math.max(m.length, l.length); + for (let t = 0, r, u; t < p; t++) { + if ((u = l[t]) && u.length) { + if ((r = m[t]) && r.length) { + for (q = 0; q < u.length; q++) { + r.push(u[q]); } } else { - m[q] = u; + m[t] = u; } - n = 1; + q = 1; } } } else { - m = l, n = 1; + m = l, q = 1; } - n && e.put(m, f + ":" + h); + q && e.put(m, f + ":" + h); }); } } @@ -2679,13 +2693,13 @@ v.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function Eb(a, b, c) { +function Fb(a, c, b) { 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 (k = b ? e : e[g]) { + for (let h = 0, l, m; h < c.length; h++) { + if (m = c[h], l = k.indexOf(m), 0 <= l) { if (d = 1, 1 < k.length) { k.splice(l, 1); } else { @@ -2696,7 +2710,7 @@ function Eb(a, b, c) { } f += k.length; } - if (c) { + if (b) { break; } } @@ -2705,41 +2719,41 @@ function Eb(a, b, c) { } 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 && Eb(c, a); + return Promise.all([this.transaction("map", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && Fb(b, a); }; - }), this.transaction("ctx", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && Eb(c, a); + }), this.transaction("ctx", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && Fb(b, a); }; - }), this.transaction("tag", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && Eb(c, a, !0); + }), this.transaction("tag", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && Fb(b, a, !0); }; - }), this.transaction("reg", "readwrite", function(b) { - for (let c = 0; c < a.length; c++) { - b.delete(a[c]); + }), this.transaction("reg", "readwrite", function(c) { + for (let b = 0; b < a.length; b++) { + c.delete(a[b]); } })]); }; -function Z(a, b) { - return new Promise((c, e) => { +function Z(a, c) { + return new Promise((b, e) => { a.onsuccess = a.oncomplete = function() { - b && b(this.result); - b = null; - c(this.result); + c && c(this.result); + c = null; + b(this.result); }; a.onerror = a.onblocked = e; a = null; }); } -;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; +;const Gb = {Index:P, Charset:rb, Encoder:ma, Document:Pa, Worker:Aa, Resolver:Y, IndexedDB:Eb, 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.bundle.min.js b/dist/flexsearch.bundle.min.js index 04cb8c5..c14cfb3 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.160 (Bundle) + * FlexSearch.js v0.8.161 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -14,10 +14,10 @@ null,this.stemmer);this.replacer=F(a.replacer,null,this.replacer);this.minlength 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; +[],d=G(),f,g,k=this.split||""===this.split?a.split(this.split):[a];for(let l=0,m,q;lthis.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 p;for(;p!==m&&2this.stemmer.get(t))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(p)));if(m&&this.replacer)for(h=0;m&&hthis.S&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==q)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");ta.call(a,"searchCache")}let ua,xa,ya;function za(){ua=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]);ua?ya||(ya=Date.now()-xa>=this.priority*this.priority*3):(ua=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 Ka(a,b){let c="";for(const e of a.entries()){a=e[0];const d=e[1];let f="";for(let g=0,k;g=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 Qa(a,b,c,e,d,f,g,k){if(a=a[g])if(e===b.length-1){if(a.constructor===Array){if(c[e]){for(b=0;bc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d= +[];for(let q=0,p;qe)e-=p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?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:q}=Wa(this,"and",arguments);return Ya.call(this,f,g,k,h,l,m,q)}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;cJ&&(J=n.length+(n?1:0)),B=n.length+(n?1:0)+M.length,z+=E,wa.push(x.length),x.push({match:M})),n+=(n?" ":"")+M)}if(!w)D=y[A],n+=(n?" ":"")+D,h&&x.push({text:D});else if(h&&z>=h)break}z=wa.length*(f.length-2);if(t||r||h&&n.length-z>h)if(z=h+z-2*p,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-=p}n=x[I].text;if(K=r&&C[w])if(0K)if(A[w+1]=1,l)n=n.substring(0,K);else continue;(K-=n.length)||(K=-1);C[w]=K}else{A[w+1]=1;continue}if(E+n.length+1<=h)n=" "+n,B[w]+=n;else if(l)S=h-E-1,0=I){if(0>I){A[w]=1;z[w]=1;continue}E-=p}n=x[I].text;if(K=t&&D[w])if(0K)if(A[w]=1,l)n=n.substring(n.length- +K);else continue;(K-=n.length)||(K=-1);D[w]=K}else{A[w]=1;continue}if(E+n.length+1<=h)n+=" ",B[w]=n+B[w];else if(l)S=n.length+1-(h-E),0<=S&&S=y.length-1?Ma=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))} +return Promise.all(b)}break;case "tag":this.tag=Ga(b,this.tag);break;case "doc":this.store=Ea(b,this.store)}}};sa(W.prototype);function kb(a,b,c){const e=(b?""+a:"object"===typeof a?""+a.query:a).toLowerCase();this.cache||(this.cache=new ib);let d=this.cache.get(e);if(!d){d=this.search(a,b,c);if(d.then){const f=this;d.then(function(g){f.cache.set(e,g);return g})}this.cache.set(e,d)}return d}function ib(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}ib.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)}; +ib.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};ib.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};ib.prototype.clear=function(){this.cache.clear();this.h=""};const lb={normalize:!1,numeric:!1,dedupe:!1};const mb={};const nb=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 ob=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),pb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const qb={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 rb={Exact:lb,Default:mb,Normalize:mb,LatinBalance:{mapper:nb},LatinAdvanced:{mapper:nb,matcher:ob,replacer:pb},LatinExtra:{mapper:nb,replacer:pb.concat([/(?!^)[aeo]/g,""]),matcher:ob},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 sb(this.map,a),this.depth&&sb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&tb(this));this.cache&&this.cache.remove(a);return this}; +function sb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;du;f--){g=r.substring(u,f);n=this.rtl?d-1-u:u;var k=this.score?this.score(b,r,t,g,n):vb(p, +l,t,d,n);wb(this,q,g,k,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,t,k-1,h-1),n=this.bidirectional&&r>f;wb(this,m,n?f:r,u,a,c,n?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&tb(this));return this}; +function wb(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 vb(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({},ub[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=L(a.encoder)?rb[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 ib(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 tb(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.cleanup=function(){if(!this.fastupdate)return this;sb(this.map);this.depth&&sb(this.ctx);return this};v.searchCache=kb;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=m.length){e-=m.length;continue}const q=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; 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)); +for(let m=0,q,p;m{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};const Gb={Index:O,Charset:rb,Encoder:ma,Document:W,Worker:Ba,Resolver:Y,IndexedDB:Eb,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.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index c44b630..154fec3 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,35 +1,35 @@ /**! - * FlexSearch.js v0.8.160 (Bundle/Module/Debug) + * FlexSearch.js v0.8.161 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ var v; -function F(a, b, c) { - const e = typeof c, d = typeof a; +function F(a, c, b) { + const e = typeof b, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { - if (c) { + if (b) { if ("function" === d && e === d) { return function(k) { - return a(c(k)); + return a(b(k)); }; } - b = a.constructor; - if (b === c.constructor) { - if (b === Array) { - return c.concat(a); + c = a.constructor; + if (c === b.constructor) { + if (c === Array) { + return b.concat(a); } - if (b === Map) { - var f = new Map(c); + if (c === Map) { + var f = new Map(b); for (var g of a) { f.set(g[0], g[1]); } return f; } - if (b === Set) { - g = new Set(c); + if (c === Set) { + g = new Set(b); for (f of a.values()) { g.add(f); } @@ -39,9 +39,9 @@ function F(a, b, c) { } return a; } - return c; + return b; } - return "undefined" === d ? b : a; + return "undefined" === d ? c : a; } function G() { return Object.create(null); @@ -53,28 +53,28 @@ function aa(a) { return "object" === typeof a; } function da(a) { - const b = []; - for (const c of a.keys()) { - b.push(c); + const c = []; + for (const b of a.keys()) { + c.push(b); } - return b; + return c; } -function ea(a, b) { - if (L(b)) { - a = a[b]; +function ea(a, c) { + if (L(c)) { + a = a[c]; } else { - for (let c = 0; a && c < b.length; c++) { - a = a[b[c]]; + for (let b = 0; a && b < c.length; b++) { + a = a[c[b]]; } } return a; } function fa(a) { - let b = 0; - for (let c = 0, e; c < a.length; c++) { - (e = a[c]) && b < e.length && (b = e.length); + let c = 0; + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && c < e.length && (c = e.length); } - return b; + return c; } ;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 = {}) { @@ -92,27 +92,27 @@ function ma(a = {}) { 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 c = a.include, b = c || a.exclude || a.split, e; + if (b || "" === b) { + if ("object" === typeof b && b.constructor !== RegExp) { 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) { - d += "object" === typeof c ? c.join("") : c; + e = !c; + c || (d += "\\p{Z}"); + b.letter && (d += "\\p{L}"); + b.number && (d += "\\p{N}", e = !!c); + b.symbol && (d += "\\p{S}"); + b.punctuation && (d += "\\p{P}"); + b.control && (d += "\\p{C}"); + if (b = b.char) { + d += "object" === typeof b ? b.join("") : b; } try { - this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); + this.split = new RegExp("[" + (c ? "^" : "") + 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+/; + console.error("Your split configuration:", b, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { - this.split = c, e = !1 === c || 2 > "a1a".split(c).length; + this.split = b, e = !1 === b || 2 > "a1a".split(b).length; } this.numeric = F(a.numeric, e); } else { @@ -125,18 +125,18 @@ v.assign = function(a) { } 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); + b = a.filter; + this.filter = "function" === typeof b ? b : F(b && new Set(b), 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.matcher = F((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = F((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = F((b = a.stemmer) && new Map(b), 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; + if (this.cache = b = F(a.cache, !0, this.cache)) { + this.H = null, this.S = "number" === typeof b ? b : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; this.M = null; @@ -154,9 +154,9 @@ v.assign = function(a) { } return this; }; -v.addStemmer = function(a, b) { +v.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); - this.stemmer.set(a, b); + this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.N = null; this.cache && N(this); @@ -167,42 +167,42 @@ v.addFilter = function(a) { this.cache && N(this); return this; }; -v.addMapper = function(a, b) { +v.addMapper = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (1 < a.length) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.mapper || (this.mapper = new Map()); - this.mapper.set(a, b); + this.mapper.set(a, c); this.cache && N(this); return this; }; -v.addMatcher = function(a, b) { +v.addMatcher = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (2 > a.length && (this.dedupe || this.mapper)) { - return this.addMapper(a, b); + return this.addMapper(a, c); } this.matcher || (this.matcher = new Map()); - this.matcher.set(a, b); + this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; this.cache && N(this); return this; }; -v.addReplacer = function(a, b) { +v.addReplacer = function(a, c) { if ("string" === typeof a) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.replacer || (this.replacer = []); - this.replacer.push(a, b); + this.replacer.push(a, c); this.cache && N(this); return this; }; -v.encode = function(a, b) { +v.encode = function(a, c) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.B.has(a)) { @@ -215,11 +215,11 @@ v.encode = function(a, b) { 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(ja, "$1 $2").replace(ka, "$1 $2").replace(ia, "$1 ")); - const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); 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) { + for (let l = 0, m, q; l < k.length; l++) { + if ((m = q = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { + if (c) { if (d[m]) { continue; } @@ -230,7 +230,7 @@ v.encode = function(a, b) { } f = m; } - if (c) { + if (b) { e.push(m); } else { if (!this.filter || ("function" === typeof this.filter ? this.filter(m) : !this.filter.has(m))) { @@ -247,28 +247,28 @@ v.encode = function(a, b) { } if (this.stemmer) { this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")); - let r; - for (; r !== m && 2 < m.length;) { - r = m, m = m.replace(this.N, q => this.stemmer.get(q)); + let p; + for (; p !== m && 2 < m.length;) { + p = m, m = m.replace(this.N, t => this.stemmer.get(t)); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { 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); + for (let p = 0, t = "", r, u; p < m.length; p++) { + r = m.charAt(p), r === t && this.dedupe || ((u = this.mapper && this.mapper.get(r)) || "" === u ? u === t && this.dedupe || !(t = u) || (h += u) : h += t = r); } m = h; } - this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, r => this.matcher.get(r))); + this.matcher && 1 < m.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.M, p => this.matcher.get(p))); if (m && this.replacer) { 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)); + this.cache && q.length <= this.L && (this.G.set(q, m), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); if (m) { - if (m !== n) { - if (b) { + if (m !== q) { + if (c) { if (d[m]) { continue; } @@ -298,32 +298,32 @@ function N(a) { ;let pa, O; async function qa(a) { a = a.data; - var b = a.task; - const c = a.id; + var c = a.task; + const b = a.id; let e = a.args; - switch(b) { + switch(c) { case "init": 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}); + (c = a.factory) ? (Function("return " + c)()(self), pa = new self.FlexSearch.Index(O), delete self.FlexSearch) : pa = new P(O); + postMessage({id:b}); break; default: let d; - if ("export" === b) { + if ("export" === c) { 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".'); } e[1] ? (e[0] = O.export, e[2] = 0, e[3] = 1) : e = null; } - if ("import" === b) { + if ("import" === c) { 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".'); } e[0] && (a = await O.import.call(pa, e[0]), pa.import(e[0], a)); } else { - (d = e && pa[b].apply(pa, e)) && d.then && (d = await d); + (d = e && pa[c].apply(pa, e)) && d.then && (d = await d); } - postMessage("search" === b ? {id:c, msg:d} : {id:c}); + postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } ;function ra(a) { @@ -332,35 +332,36 @@ async function qa(a) { sa.call(a, "search"); sa.call(a, "update"); sa.call(a, "remove"); + sa.call(a, "searchCache"); } -let ta, wa, xa; +let ta, ua, xa; function ya() { ta = xa = 0; } function sa(a) { this[a + "Async"] = function() { - const b = arguments; - var c = b[b.length - 1]; + const c = arguments; + var b = c[c.length - 1]; 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()); + "function" === typeof b && (e = b, delete c[c.length - 1]); + ta ? xa || (xa = Date.now() - ua >= this.priority * this.priority * 3) : (ta = setTimeout(ya, 0), ua = Date.now()); if (xa) { const f = this; return new Promise(g => { setTimeout(function() { - g(f[a + "Async"].apply(f, b)); + g(f[a + "Async"].apply(f, c)); }, 0); }); } - const d = this[a].apply(this, b); - c = d.then ? d : new Promise(f => f(d)); - e && c.then(e); - return c; + const d = this[a].apply(this, c); + b = d.then ? d : new Promise(f => f(d)); + e && b.then(e); + return b; }; } ;let za = 0; function Aa(a = {}) { - function b(g) { + function c(g) { function k(h) { h = h.data || h; const l = h.id, m = l && d.h[l]; @@ -376,10 +377,10 @@ function Aa(a = {}) { h(d); 1e9 < za && (za = 0); }; - d.worker.postMessage({id:za, task:"init", factory:c, options:a}); + d.worker.postMessage({id:za, task:"init", factory:b, options:a}); }); } - this.worker.postMessage({task:"init", factory:c, options:a}); + this.worker.postMessage({task:"init", factory:b, options:a}); this.priority = a.priority || 4; return this; } @@ -387,12 +388,12 @@ function Aa(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 e = "undefined" === typeof window, d = this, f = Ba(c, e, a.worker); + 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 = Ba(b, e, a.worker); return f.then ? f.then(function(g) { - return b.call(d, g); - }) : b.call(this, f); + return c.call(d, g); + }) : c.call(this, f); } R("add"); R("append"); @@ -405,85 +406,85 @@ R("import"); ra(Aa.prototype); function R(a) { Aa.prototype[a] = function() { - const b = this, c = [].slice.call(arguments); - var e = c[c.length - 1]; + const c = this, b = [].slice.call(arguments); + var e = b[b.length - 1]; let d; - "function" === typeof e && (d = e, c.pop()); + "function" === typeof e && (d = e, b.pop()); e = new Promise(function(f) { - "export" === a && "function" === typeof c[0] && (c[0] = null); - b.h[++za] = f; - b.worker.postMessage({task:a, id:za, args:c}); + "export" === a && "function" === typeof b[0] && (b[0] = null); + c.h[++za] = f; + c.worker.postMessage({task:a, id:za, args:b}); }); return d ? (e.then(d), this) : e; }; } -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", +function Ba(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=" + qa.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 Ca(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 5000 | 0); +;function Ca(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { - e.push(d), e.length === b && (c.push(e), e = []); - } - e.length && c.push(e); - return c; -} -function Da(a, b) { - b || (b = new Map()); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b.set(e[0], e[1]); + e.push(d), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } -function Ea(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 1000 | 0); - for (const d of a.entries()) { - e.push([d[0], Ca(d[1])[0]]), e.length === b && (c.push(e), e = []); +function Da(a, c) { + c || (c = new Map()); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c.set(e[0], e[1]); } - e.length && c.push(e); return c; } -function Fa(a, b) { - b || (b = new Map()); - for (let c = 0, e, d; c < a.length; c++) { - e = a[c], d = b.get(e[0]), b.set(e[0], Da(e[1], d)); +function Ea(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], Ca(d[1])[0]]), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } +function Fa(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], Da(e[1], d)); + } + return c; +} function Ga(a) { - let b = [], c = []; + let c = [], b = []; for (const e of a.keys()) { - c.push(e), 250000 === c.length && (b.push(c), c = []); + b.push(e), 250000 === b.length && (c.push(b), b = []); } - c.length && b.push(c); - return b; + b.length && c.push(b); + return c; } -function Ha(a, b) { - b || (b = new Set()); - for (let c = 0; c < a.length; c++) { - b.add(a[c]); +function Ha(a, c) { + c || (c = new Set()); + for (let b = 0; b < a.length; b++) { + c.add(a[b]); } - return b; + return c; } -function Ia(a, b, c, e, d, f, g = 0) { +function Ia(a, c, b, 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); + return this.export(a, c, d, f + 1); } - if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return Ia.call(l, a, b, c, k ? e : null, d, f, g + 1); + return Ia.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return Ia.call(this, a, b, c, k ? e : null, d, f, g + 1); + return Ia.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function La(a, b) { - let c = ""; +function Ja(a, c) { + let b = ""; for (const e of a.entries()) { a = e[0]; const d = e[1]; @@ -492,28 +493,28 @@ function La(a, b) { k = d[g] || [""]; let h = ""; for (let l = 0; l < k.length; l++) { - h += (h ? "," : "") + ("string" === b ? '"' + k[l] + '"' : k[l]); + h += (h ? "," : "") + ("string" === c ? '"' + k[l] + '"' : k[l]); } h = "[" + h + "]"; f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; - c += (c ? "," : "") + f; + b += (b ? "," : "") + f; } - return c; + return b; } -;function Ma(a, b, c, e) { +;function Ma(a, c, b, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { - if (g = a.index[f], b >= g.length) { - b -= g.length; + if (g = a.index[f], c >= g.length) { + c -= 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)) { + c = g[e ? "splice" : "slice"](c, b); + const k = c.length; + if (k && (d = d.length ? d.concat(c) : c, b -= k, e && (a.length -= k), !b)) { break; } - b = 0; + c = 0; } } return d; @@ -524,29 +525,29 @@ function T(a) { } this.index = a ? [a] : []; this.length = a ? a.length : 0; - const b = this; - return new Proxy([], {get(c, e) { + const c = this; + return new Proxy([], {get(b, e) { if ("length" === e) { - return b.length; + return c.length; } if ("push" === e) { return function(d) { - b.index[b.index.length - 1].push(d); - b.length++; + c.index[c.index.length - 1].push(d); + c.length++; }; } if ("pop" === e) { return function() { - if (b.length) { - return b.length--, b.index[b.index.length - 1].pop(); + if (c.length) { + return c.length--, c.index[c.index.length - 1].pop(); } }; } if ("indexOf" === e) { return function(d) { let f = 0; - for (let g = 0, k, h; g < b.index.length; g++) { - k = b.index[g]; + for (let g = 0, k, h; g < c.index.length; g++) { + k = c.index[g]; h = k.indexOf(d); if (0 <= h) { return f + h; @@ -558,8 +559,8 @@ function T(a) { } if ("includes" === e) { return function(d) { - for (let f = 0; f < b.index.length; f++) { - if (b.index[f].includes(d)) { + for (let f = 0; f < c.index.length; f++) { + if (c.index[f].includes(d)) { return !0; } } @@ -568,24 +569,24 @@ function T(a) { } if ("slice" === e) { return function(d, f) { - return Ma(b, d || 0, f || b.length, !1); + return Ma(c, d || 0, f || c.length, !1); }; } if ("splice" === e) { return function(d, f) { - return Ma(b, d || 0, f || b.length, !0); + return Ma(c, d || 0, f || c.length, !0); }; } if ("constructor" === e) { return Array; } if ("symbol" !== typeof e) { - return (c = b.index[e / 2 ** 31 | 0]) && c[e]; + return (b = c.index[e / 2 ** 31 | 0]) && b[e]; } - }, set(c, e, d) { - c = e / 2 ** 31 | 0; - (b.index[c] || (b.index[c] = []))[e] = d; - b.length++; + }, set(b, e, d) { + b = e / 2 ** 31 | 0; + (c.index[b] || (c.index[b] = []))[e] = d; + c.length++; return !0; }}); } @@ -607,13 +608,13 @@ function U(a = 8) { 32 < a ? (this.B = Na, this.A = BigInt(a)) : (this.B = Oa, this.A = a); } U.prototype.get = function(a) { - const b = this.index[this.B(a)]; - return b && b.get(a); + const c = this.index[this.B(a)]; + return c && c.get(a); }; -U.prototype.set = function(a, b) { - var c = this.B(a); - 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++); +U.prototype.set = function(a, c) { + var b = this.B(a); + let e = this.index[b]; + e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++); }; function V(a = 8) { if (!this || this.constructor !== V) { @@ -625,18 +626,18 @@ function V(a = 8) { 32 < a ? (this.B = Na, this.A = BigInt(a)) : (this.B = Oa, this.A = 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++); + var c = this.B(a); + let b = this.index[c]; + b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.h.push(b), this.size++); }; v = U.prototype; v.has = V.prototype.has = function(a) { - const b = this.index[this.B(a)]; - return b && b.has(a); + const c = this.index[this.B(a)]; + return c && c.has(a); }; v.delete = V.prototype.delete = function(a) { - const b = this.index[this.B(a)]; - b && b.delete(a) && this.size--; + const c = this.index[this.B(a)]; + c && c.delete(a) && this.size--; }; v.clear = V.prototype.clear = function() { this.index = G(); @@ -645,67 +646,67 @@ v.clear = V.prototype.clear = 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; + for (let c of this.h[a].values()) { + yield c; } } }; 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; + for (let c of this.h[a].keys()) { + yield c; } } }; 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; + for (let c of this.h[a].entries()) { + yield c; } } }; function Oa(a) { - let b = 2 ** this.A - 1; + let c = 2 ** this.A - 1; if ("number" == typeof a) { - return a & b; + return a & c; } - let c = 0, e = this.A + 1; + let b = 0, e = this.A + 1; for (let d = 0; d < a.length; d++) { - c = (c * e ^ a.charCodeAt(d)) & b; + b = (b * e ^ a.charCodeAt(d)) & c; } - return 32 === this.A ? c + 2 ** 31 : c; + return 32 === this.A ? b + 2 ** 31 : b; } function Na(a) { - let b = BigInt(2) ** this.A - BigInt(1); - var c = typeof a; - if ("bigint" === c) { - return a & b; + let c = BigInt(2) ** this.A - BigInt(1); + var b = typeof a; + if ("bigint" === b) { + return a & c; } - if ("number" === c) { - return BigInt(a) & b; + if ("number" === b) { + return BigInt(a) & c; } - c = BigInt(0); + b = BigInt(0); let e = this.A + BigInt(1); for (let d = 0; d < a.length; d++) { - c = (c * e ^ BigInt(a.charCodeAt(d))) & b; + b = (b * e ^ BigInt(a.charCodeAt(d))) & c; } - return c; + return b; } -;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); +;Pa.prototype.add = function(a, c, b) { + aa(a) && (c = a, a = ea(c, this.key)); + if (c && (a || 0 === a)) { + if (!b && this.reg.has(a)) { + return this.update(a, c); } 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); + var d = h(c); d && e.add(a, d, !1, !0); } else { - 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 (d = h.I, !d || d(c)) { + h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), Qa(c, h, this.J, 0, e, a, h[0], b); } } } @@ -715,26 +716,26 @@ function Na(a) { d = this.tag.get(g); let k = G(); if ("function" === typeof f) { - if (f = f(b), !f) { + if (f = f(c), !f) { continue; } } else { const h = f.I; - if (h && !h(b)) { + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); - f = ea(b, f); + f = ea(c, f); } 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 (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !b || !m.includes(a))) { if (m.length === 2 ** 31 - 1) { g = new T(m); if (this.fastupdate) { - for (let n of this.reg.values()) { - n.includes(m) && (n[n.indexOf(m)] = g); + for (let q of this.reg.values()) { + q.includes(m) && (q[q.indexOf(m)] = g); } } d.set(l, m = g); @@ -748,56 +749,56 @@ function Na(a) { } } } - if (this.store && (!c || !this.store.has(a))) { + if (this.store && (!b || !this.store.has(a))) { let k; if (this.C) { k = G(); for (let h = 0, l; h < this.C.length; h++) { l = this.C[h]; - if ((c = l.I) && !c(b)) { + if ((b = l.I) && !b(c)) { continue; } let m; if ("function" === typeof l) { - m = l(b); + m = l(c); if (!m) { continue; } l = [l.V]; } else if (L(l) || l.constructor === String) { - k[l] = b[l]; + k[l] = c[l]; continue; } - Ra(b, k, l, 0, l[0], m); + Ra(c, k, l, 0, l[0], m); } } - this.store.set(a, k || b); + this.store.set(a, k || c); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Ra(a, b, c, e, d, f) { +function Ra(a, c, b, e, d, f) { a = a[d]; - if (e === c.length - 1) { - b[d] = f || a; + if (e === b.length - 1) { + c[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { - Ra(a, b, c, e, d); + for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { + Ra(a, c, b, e, d); } } else { - b = b[d] || (b[d] = G()), d = c[++e], Ra(a, b, c, e, d); + c = c[d] || (c[d] = G()), d = b[++e], Ra(a, c, b, e, d); } } } -function Qa(a, b, c, e, d, f, g, k) { +function Qa(a, c, b, e, d, f, g, k) { if (a = a[g]) { - if (e === b.length - 1) { + if (e === c.length - 1) { if (a.constructor === Array) { - if (c[e]) { - for (b = 0; b < a.length; b++) { - d.add(f, a[b], !0, !0); + if (b[e]) { + for (c = 0; c < a.length; c++) { + d.add(f, a[c], !0, !0); } return; } @@ -807,33 +808,33 @@ function Qa(a, b, c, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Qa(a, b, c, e, d, f, g, k); + Qa(a, c, b, e, d, f, g, k); } } else { - g = b[++e], Qa(a, b, c, e, d, f, g, k); + g = c[++e], Qa(a, c, b, e, d, f, g, k); } } } else { d.db && d.remove(f); } } -;function Sa(a, b, c, e, d, f, g) { +;function Sa(a, c, b, 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); + for (let q = 0, p, t, r, u; q < c; q++) { + for (let n = 0; n < k; n++) { + if (r = a[n], q < r.length && (p = r[q])) { + for (let z = 0; z < p.length; z++) { + t = p[z]; + (m = l[t]) ? l[t]++ : (m = 0, l[t] = 1); u = h[m] || (h[m] = []); if (!g) { - let x = n + (p || !d ? 0 : f || 0); + let x = q + (n || !d ? 0 : f || 0); u = u[x] || (u[x] = []); } - u.push(q); - if (g && c && m === k - 1 && u.length - e === c) { + u.push(t); + if (g && b && m === k - 1 && u.length - e === b) { return e ? u.slice(e) : u; } } @@ -842,28 +843,28 @@ function Qa(a, b, c, e, d, f, g, 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; + h = 1 < h.length ? Ta(h, b, e, g, f) : (h = h[0]).length > b || e ? h.slice(e, b + e) : h; } else { if (a < k) { return []; } h = h[a - 1]; - if (c || e) { + if (b || e) { if (g) { - if (h.length > c || e) { - h = h.slice(e, c + e); + if (h.length > b || e) { + h = h.slice(e, b + e); } } else { d = []; - for (let n = 0, r; n < h.length; n++) { - if (r = h[n], r.length > e) { - e -= r.length; + for (let q = 0, p; q < h.length; q++) { + if (p = h[q], p.length > e) { + e -= p.length; } else { - if (r.length > c || e) { - r = r.slice(e, c + e), c -= r.length, e && (e -= r.length); + if (p.length > b || e) { + p = p.slice(e, b + e), b -= p.length, e && (e -= p.length); } - d.push(r); - if (!c) { + d.push(p); + if (!b) { break; } } @@ -875,7 +876,7 @@ function Qa(a, b, c, e, d, f, g, k) { } return h; } -function Ta(a, b, c, e, d) { +function Ta(a, c, b, e, d) { const f = [], g = G(); let k; var h = a.length; @@ -885,10 +886,10 @@ function Ta(a, b, c, e, 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--; + if (g[k] = 1, b) { + b--; } else { - if (f.push(k), f.length === b) { + if (f.push(k), f.length === c) { return f; } } @@ -897,18 +898,18 @@ function Ta(a, b, c, e, d) { } } } else { - for (let m = h - 1, n, r = 0; 0 <= m; m--) { - n = a[m]; - 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--; + for (let m = h - 1, q, p = 0; 0 <= m; m--) { + q = a[m]; + for (let t = 0; t < q.length; t++) { + if (l = (e = q[t]) && e.length) { + for (let r = 0; r < l; r++) { + if (k = e[r], !g[k]) { + if (g[k] = 1, b) { + b--; } else { - let u = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + let u = (t + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; (f[u] || (f[u] = [])).push(k); - if (++r === b) { + if (++p === c) { return f; } } @@ -920,51 +921,51 @@ function Ta(a, b, c, e, d) { } return f; } -function Ua(a, b, c) { +function Ua(a, c, b) { const e = G(), d = []; - for (let f = 0, g; f < b.length; f++) { - g = b[f]; + for (let f = 0, g; f < c.length; f++) { + g = c[f]; for (let k = 0; k < g.length; k++) { e[g[k]] = 1; } } - if (c) { + if (b) { for (let f = 0, g; f < a.length; f++) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { for (let f = 0, g, k; f < a.result.length; f++) { - for (g = a.result[f], b = 0; b < g.length; b++) { - k = g[b], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); + for (g = a.result[f], c = 0; c < g.length; c++) { + k = g[c], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); } } } return d; } -;function Va(a, b, c, e) { +;function Va(a, c, b, 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, e ? X.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? X.call(this, a) : a; } let d = []; for (let f = 0, g, k; f < a.length; f++) { if ((g = a[f]) && (k = g.length)) { - if (c) { - if (c >= k) { - c -= k; + if (b) { + if (b >= k) { + b -= k; continue; } - c < k && (g = b ? g.slice(c, c + b) : g.slice(c), k = g.length, c = 0); + b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); } - k > b && (g = g.slice(0, b), k = b); - if (!d.length && k >= b) { + k > c && (g = g.slice(0, c), k = c); + if (!d.length && k >= c) { return e ? X.call(this, g) : g; } d.push(g); - b -= k; - if (!b) { + c -= k; + if (!c) { break; } } @@ -972,45 +973,45 @@ function Ua(a, b, c) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? X.call(this, d) : d; } -;function Wa(a, b, c) { - var e = c[0]; +;function Wa(a, c, b) { + var e = b[0]; if (e.then) { - return Promise.all(c).then(function(m) { - return a[b].apply(a, m); + return Promise.all(b).then(function(m) { + return a[c].apply(a, m); }); } if (e[0] && e[0].index) { - return a[b].apply(a, e); + return a[c].apply(a, e); } e = []; let d = [], f = 0, g = 0, k, h, l; - for (let m = 0, n; m < c.length; m++) { - if (n = c[m]) { - let r; - if (n.constructor === Y) { - r = n.result; - } else if (n.constructor === Array) { - r = n; + for (let m = 0, q; m < b.length; m++) { + if (q = b[m]) { + let p; + if (q.constructor === Y) { + p = q.result; + } else if (q.constructor === Array) { + p = q; } 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 = q.limit || 0, g = q.offset || 0, l = q.suggest, h = q.resolve, k = q.enrich && h, q.index) { + q.resolve = !1, q.enrich = !1, p = q.index.search(q).result, q.resolve = h, q.enrich = k; + } else if (q.and) { + p = a.and(q.and); + } else if (q.or) { + p = a.or(q.or); + } else if (q.xor) { + p = a.xor(q.xor); + } else if (q.not) { + p = a.not(q.not); } else { continue; } } - if (r.then) { - d.push(r); - } else if (r.length) { - e[m] = r; - } else if (!l && ("and" === b || "xor" === b)) { + if (p.then) { + d.push(p); + } else if (p.length) { + e[m] = p; + } else if (!l && ("and" === c || "xor" === c)) { e = []; break; } @@ -1019,119 +1020,119 @@ function Ua(a, b, c) { return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;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); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Wa(this, "or", arguments); + return Xa.call(this, a, c, b, e, d, f); }; -function Xa(a, b, c, e, d, f) { - if (b.length) { +function Xa(a, c, b, e, d, f) { + if (c.length) { const g = this; - return Promise.all(b).then(function(k) { + return Promise.all(c).then(function(k) { a = []; for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return Xa.call(g, a, [], c, e, d, f); + return Xa.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 = Ta(a, c, e, !1, this.h), e = 0)); - return f ? this.resolve(c, e, d) : this; + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ta(a, b, e, !1, this.h), e = 0)); + return f ? this.resolve(b, e, d) : this; } ;Y.prototype.and = function() { - let a = this.result.length, b, c, e, d; + let a = this.result.length, c, b, 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); + 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} = Wa(this, "and", arguments); - return Ya.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:q} = Wa(this, "and", arguments); + return Ya.call(this, f, g, k, h, l, m, q); } - return d ? this.resolve(b, c, e) : this; + return d ? this.resolve(c, b, e) : this; }; -function Ya(a, b, c, e, d, f, g) { - if (b.length) { +function Ya(a, c, b, e, d, f, g) { + if (c.length) { const k = this; - return Promise.all(b).then(function(h) { + return Promise.all(c).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); + return Ya.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 { - 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; + if (c = fa(a)) { + return this.result = Sa(a, c, b, 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; + return f ? this.resolve(b, 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); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Wa(this, "xor", arguments); + return Za.call(this, a, c, b, e, d, f, g); }; -function Za(a, b, c, e, d, f, g) { - if (b.length) { +function Za(a, c, b, e, d, f, g) { + if (c.length) { const k = this; - return Promise.all(b).then(function(h) { + return Promise.all(c).then(function(h) { a = []; for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Za.call(k, a, [], c, e, d, f, g); + return Za.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 = $a.call(this, a, c, e, f, this.h), f ? d ? X.call(this.index, this.result) : this.result : this; + return this.result = $a.call(this, a, b, 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; + return f ? this.resolve(b, e, d) : this; } -function $a(a, b, c, e, d) { +function $a(a, c, b, 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 r = 0, q; r < n.length; r++) { - q = n[r], g[q] = g[q] ? 2 : 1; + for (let m = 0, q; m < l.length; m++) { + if (q = l[m]) { + for (let p = 0, t; p < q.length; p++) { + t = q[p], g[t] = g[t] ? 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]) { - if (l = r[h]) { - for (let q = 0, t; q < l.length; q++) { - if (t = l[q], 1 === g[t]) { - if (c) { - c--; + for (let q = 0, p; q < a.length; q++) { + if (p = a[q]) { + if (l = p[h]) { + for (let t = 0, r; t < l.length; t++) { + if (r = l[t], 1 === g[r]) { + if (b) { + b--; } else { if (e) { - if (f.push(t), f.length === b) { + if (f.push(r), f.length === c) { return f; } } else { - const u = h + (n ? d : 0); + const u = h + (q ? d : 0); f[u] || (f[u] = []); - f[u].push(t); - if (++m === b) { + f[u].push(r); + if (++m === c) { return f; } } @@ -1145,43 +1146,43 @@ function $a(a, b, c, e, d) { return f; } ;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); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Wa(this, "not", arguments); + return ab.call(this, a, c, b, e, d, f, g); }; -function ab(a, b, c, e, d, f, g) { - if (b.length) { +function ab(a, c, b, e, d, f, g) { + if (c.length) { const k = this; - return Promise.all(b).then(function(h) { + return Promise.all(c).then(function(h) { a = []; for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return ab.call(k, a, [], c, e, d, f, g); + return ab.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = bb.call(this, a, c, e, f); + this.result = bb.call(this, a, b, e, f); } else if (f) { - return this.resolve(c, e, d); + return this.resolve(b, e, d); } return f ? d ? X.call(this.index, this.result) : this.result : this; } -function bb(a, b, c, e) { +function bb(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { for (let h = 0, l; h < g.length; h++) { if (l = g[h], !a.has(l)) { - if (c) { - c--; + if (b) { + b--; } else { if (e) { - if (d.push(l), d.length === b) { + if (d.push(l), d.length === c) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++k === b) { + if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { return d; } } @@ -1205,32 +1206,32 @@ function bb(a, b, c, e) { } Y.prototype.limit = function(a) { if (this.result.length) { - const b = []; - for (let c = 0, e; c < this.result.length; c++) { - if (e = this.result[c]) { + const c = []; + for (let b = 0, e; b < this.result.length; b++) { + if (e = this.result[b]) { if (e.length <= a) { - if (b[c] = e, a -= e.length, !a) { + if (c[b] = e, a -= e.length, !a) { break; } } else { - b[c] = e.slice(0, a); + c[b] = e.slice(0, a); break; } } } - this.result = b; + this.result = c; } return this; }; Y.prototype.offset = function(a) { if (this.result.length) { - const b = []; - 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); + const c = []; + for (let b = 0, e; b < this.result.length; b++) { + if (e = this.result[b]) { + e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0); } } - this.result = b; + this.result = c; } return this; }; @@ -1238,13 +1239,13 @@ Y.prototype.boost = function(a) { this.h += a; return this; }; -Y.prototype.resolve = function(a, b, c) { +Y.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Va.call(d, e, a || 100, b, c)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Va.call(d, e, a || 100, c, b)) : e; }; G(); -function cb(a, b, c, e, d) { +function cb(a, c, b, e, d) { let f, g, k; "string" === typeof d ? (f = d, d = "") : f = d.template; if (!f) { @@ -1258,89 +1259,89 @@ function cb(a, b, c, e, d) { 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; + var q = 0; if ("object" === typeof d) { - var r = d.template; - n = r.length - 2; + var p = d.template; + q = p.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++) { + q && (d = p.replace("$1", d)); + p = d.length - q; + let t, r; + "object" === typeof h && (t = h.before, 0 === t && (t = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); + q = new Map(); + for (let Ka = 0, ba, eb, na; Ka < c.length; Ka++) { let oa; if (e) { - oa = b, na = e; + oa = c, na = e; } else { - var u = b[Ja]; + var u = c[Ka]; 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) { + eb = b.get(na); + ba = eb.encoder; + u = q.get(ba); + "string" !== typeof u && (u = ba.encode(a), q.set(ba, u)); + for (let va = 0; va < oa.length; va++) { + var n = oa[va].doc; + if (!n) { continue; } - p = ea(p, na); - if (!p) { + n = ea(n, na); + if (!n) { continue; } - var z = p.trim().split(/\s+/); + var z = n.trim().split(/\s+/); if (!z.length) { continue; } - p = ""; + n = ""; var x = []; - let va = []; + let wa = []; 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]; + var E = z[A], D = ba.encode(E); + D = 1 < D.length ? D.join(" ") : D[0]; let w; - if (E && D) { - var C = D.length, H = (ba.split ? D.replace(ba.split, "") : D).length - E.length, M = "", W = 0; + if (D && E) { + var C = E.length, H = (ba.split ? E.replace(ba.split, "") : E).length - D.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)); + W && K <= W || (Q = D.indexOf(Q), -1 < Q && (M = (Q ? E.substring(0, Q) : "") + g + E.substring(Q, Q + K) + k + (Q + K < C ? E.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); + M && (h && (0 > J && (J = n.length + (n ? 1 : 0)), B = n.length + (n ? 1 : 0) + M.length, y += C, wa.push(x.length), x.push({match:M})), n += (n ? " " : "") + M); } if (!w) { - D = z[A], p += (p ? " " : "") + D, h && x.push({text:D}); + E = z[A], n += (n ? " " : "") + E, h && x.push({text:E}); } 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 : ""); + y = wa.length * (f.length - 2); + if (t || r || h && n.length - y > h) { + if (y = h + y - 2 * p, A = B - J, 0 < t && (A += t), 0 < r && (A += r), A <= y) { + z = t ? J - (0 < t ? t : 0) : J - ((y - A) / 2 | 0), x = r ? B + (0 < r ? r : 0) : z + y, l || (0 < z && " " !== n.charAt(z) && " " !== n.charAt(z - 1) && (z = n.indexOf(" ", z), 0 > z && (z = 0)), x < n.length && " " !== n.charAt(x - 1) && " " !== n.charAt(x) && (x = n.lastIndexOf(" ", x), x < B ? x = B : ++x)), n = (z ? d : "") + n.substring(z, x) + (x < n.length ? d : ""); } else { B = []; J = {}; y = {}; A = {}; - D = {}; E = {}; + D = {}; M = H = C = 0; for (ca = W = 1;;) { var S = void 0; - for (let w = 0, I; w < va.length; w++) { - I = va[w]; + for (let w = 0, I; w < wa.length; w++) { + I = wa[w]; if (M) { if (H !== M) { if (A[w + 1]) { @@ -1348,7 +1349,7 @@ function cb(a, b, c, e, d) { } I += M; if (J[I]) { - C -= r; + C -= p; y[w + 1] = 1; A[w + 1] = 1; continue; @@ -1359,29 +1360,29 @@ function cb(a, b, c, e, d) { I >= z.length && (y[w + 1] = 1); continue; } - C -= r; + C -= p; } - p = x[I].text; - if (K = t && E[w]) { + n = x[I].text; + if (K = r && D[w]) { if (0 < K) { - if (p.length > K) { + if (n.length > K) { if (A[w + 1] = 1, l) { - p = p.substring(0, K); + n = n.substring(0, K); } else { continue; } } - (K -= p.length) || (K = -1); - E[w] = K; + (K -= n.length) || (K = -1); + D[w] = K; } else { A[w + 1] = 1; continue; } } - if (C + p.length + 1 <= h) { - p = " " + p, B[w] += p; + if (C + n.length + 1 <= h) { + n = " " + n, B[w] += n; } else if (l) { - S = h - C - 1, 0 < S && (p = " " + p.substring(0, S), B[w] += p), A[w + 1] = 1; + S = h - C - 1, 0 < S && (n = " " + n.substring(0, S), B[w] += n), A[w + 1] = 1; } else { A[w + 1] = 1; continue; @@ -1392,7 +1393,7 @@ function cb(a, b, c, e, d) { } I -= H; if (J[I]) { - C -= r; + C -= p; A[w] = 1; y[w] = 1; continue; @@ -1403,52 +1404,52 @@ function cb(a, b, c, e, d) { y[w] = 1; continue; } - C -= r; + C -= p; } - p = x[I].text; - if (K = q && D[w]) { + n = x[I].text; + if (K = t && E[w]) { if (0 < K) { - if (p.length > K) { + if (n.length > K) { if (A[w] = 1, l) { - p = p.substring(p.length - K); + n = n.substring(n.length - K); } else { continue; } } - (K -= p.length) || (K = -1); - D[w] = K; + (K -= n.length) || (K = -1); + E[w] = K; } else { A[w] = 1; continue; } } - if (C + p.length + 1 <= h) { - p += " ", B[w] = p + B[w]; + if (C + n.length + 1 <= h) { + n += " ", B[w] = n + 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; + S = n.length + 1 - (h - C), 0 <= S && S < n.length && (n = n.substring(S) + " ", B[w] = n + B[w]), A[w] = 1; } else { A[w] = 1; continue; } } } else { - p = x[I].match; - q && (D[w] = q); + n = x[I].match; t && (E[w] = t); + r && (D[w] = r); 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); + let La; + I ? !w && p && (C += p) : (y[w] = 1, A[w] = 1); + I >= z.length - 1 ? La = 1 : I < x.length - 1 && x[I + 1].match ? La = 1 : p && (C += p); C -= f.length - 2; - if (!w || C + p.length <= h) { - B[w] = p; + if (!w || C + n.length <= h) { + B[w] = n; } else { S = W = ca = y[w] = 0; break; } - Ka && (y[w + 1] = 1, A[w + 1] = 1); + La && (y[w + 1] = 1, A[w + 1] = 1); } - C += p.length; + C += n.length; S = J[I] = 1; } if (S) { @@ -1461,59 +1462,65 @@ function cb(a, b, c, e, d) { W ? (H++, M = H) : M++; } } - p = ""; + n = ""; for (let w = 0, I; w < B.length; w++) { - I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], p += I; + I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], n += I; } - d && !y[B.length] && (p += d); + d && !y[B.length] && (n += d); } } - m && (p = p.replace(m, " ")); - oa[ua].highlight = p; + m && (n = n.replace(m, " ")); + oa[va].highlight = n; } if (e) { break; } } - return b; + return c; } -;Pa.prototype.search = function(a, b, c, e) { - c || (!b && aa(a) ? (c = a, a = "") : aa(b) && (c = b, b = 0)); - let d = []; - var f = []; - let g; - let k; - 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; - h = g || c.field || (h = c.index) && (h.index ? null : h); - l = this.tag && c.tag; - var q = c.suggest; - 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); +;Pa.prototype.search = function(a, c, b, e) { + b || (!c && aa(a) ? (b = a, a = "") : aa(c) && (b = c, c = 0)); + if (b && b.cache) { + b.cache = !1; + var d = this.searchCache(a, c, b); + b.cache = !0; + return d; + } + let f = []; + var g = []; + let k, h; + let l, m; + let q = 0; + var p = !0; + let t; + if (b) { + b.constructor === Array && (b = {index:b}); + a = b.query || a; + k = b.pluck; + h = b.merge; + l = k || b.field || (l = b.index) && (l.index ? null : l); + m = this.tag && b.tag; + var r = b.suggest; + p = !1 !== b.resolve; + if (!p && !k) { + if (l = l || this.field) { + L(l) ? k = l : (l.constructor === Array && 1 === l.length && (l = l[0]), k = l.field || l.index); } - if (!g) { + if (!k) { 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 && !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 u = c.offset || 0; - b || (b = 100); - if (l && (!this.db || !e)) { - l.constructor !== Array && (l = [l]); - var p = []; - for (let B = 0, y; B < l.length; B++) { - y = l[B]; + this.store && b.highlight && !p ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + t = p && this.store && b.highlight; + d = !!t || p && this.store && b.enrich; + c = b.limit || c; + var u = b.offset || 0; + c || (c = 100); + if (m && (!this.db || !e)) { + m.constructor !== Array && (m = [m]); + var n = []; + for (let B = 0, y; B < m.length; B++) { + y = m[B]; if (L(y)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } @@ -1521,187 +1528,190 @@ function cb(a, b, c, e, d) { var z = y.tag; if (z.constructor === Array) { for (var x = 0; x < z.length; x++) { - p.push(y.field, z[x]); + n.push(y.field, z[x]); } } else { - p.push(y.field, z); + n.push(y.field, z); } } else { 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++) { - p.push(D, E[x]); + for (let A = 0, E, D; A < z.length; A++) { + if (E = z[A], D = y[E], D.constructor === Array) { + for (x = 0; x < D.length; x++) { + n.push(E, D[x]); } } else { - p.push(D, E); + n.push(E, D); } } } } - if (!p.length) { + if (!n.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = p; + m = n; if (!a) { - n = []; - if (p.length) { - for (f = 0; f < p.length; f += 2) { + p = []; + if (n.length) { + for (g = 0; g < n.length; g += 2) { if (this.db) { - q = this.index.get(p[f]); - if (!q) { - console.warn("Tag '" + p[f] + ":" + p[f + 1] + "' will be skipped because there is no field '" + p[f] + "'."); + r = this.index.get(n[g]); + if (!r) { + console.warn("Tag '" + n[g] + ":" + n[g + 1] + "' will be skipped because there is no field '" + n[g] + "'."); continue; } - n.push(q = q.db.tag(p[f + 1], b, u, t)); + p.push(r = r.db.tag(n[g + 1], c, u, d)); } else { - q = eb.call(this, p[f], p[f + 1], b, u, t); + r = db.call(this, n[g], n[g + 1], c, u, d); } - d.push({field:p[f], tag:p[f + 1], result:q}); + f.push({field:n[g], tag:n[g + 1], result:r}); } } - return n.length ? Promise.all(n).then(function(B) { + return p.length ? Promise.all(p).then(function(B) { for (let y = 0; y < B.length; y++) { - d[y].result = B[y]; + f[y].result = B[y]; } - return d; - }) : d; + return f; + }) : f; } } - h && h.constructor !== Array && (h = [h]); + l && l.constructor !== Array && (l = [l]); } - h || (h = this.field); - p = !e && (this.worker || this.db) && []; + l || (l = this.field); let J; - for (let B = 0, y, A, D; B < h.length; B++) { - A = h[B]; + n = (this.worker || this.db) && !e && []; + for (let B = 0, y, A, E; B < l.length; B++) { + A = l[B]; if (this.db && this.tag && !this.F[B]) { continue; } - let E; - 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)); + let D; + L(A) || (D = A, A = D.field, a = D.query || a, c = fb(D.limit, c), u = fb(D.offset, u), r = fb(D.suggest, r), t = p && this.store && fb(D.highlight, t), d = !!t || p && this.store && fb(D.enrich, d)); if (e) { y = e[B]; } else { - 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); + if (z = D || b, x = this.index.get(A), m && (this.db && (z.tag = m, J = x.db.support_tag_search, z.field = l), J || (z.enrich = !1)), n) { + n[B] = x.search(a, c, z); + z && d && (z.enrich = d); continue; } else { - y = x.search(a, b, z), z && t && (z.enrich = t); + y = x.search(a, c, z), z && d && (z.enrich = d); } } - D = y && (n ? y.length : y.result.length); - if (l && D) { + E = y && (p ? y.length : y.result.length); + if (m && E) { z = []; x = 0; if (this.db && e) { if (!J) { - for (let C = h.length; C < e.length; C++) { + for (let C = l.length; C < e.length; C++) { let H = e[C]; if (H && H.length) { x++, z.push(H); - } else if (!q) { - return n ? d : new Y(d); + } else if (!r) { + return p ? f : new Y(f); } } } } else { - for (let C = 0, H, M; C < l.length; C += 2) { - H = this.tag.get(l[C]); + for (let C = 0, H, M; C < m.length; C += 2) { + H = this.tag.get(m[C]); if (!H) { - if (console.warn("Tag '" + l[C] + ":" + l[C + 1] + "' will be skipped because there is no field '" + l[C] + "'."), q) { + if (console.warn("Tag '" + m[C] + ":" + m[C + 1] + "' will be skipped because there is no field '" + m[C] + "'."), r) { continue; } else { - return n ? d : new Y(d); + return p ? f : new Y(f); } } - if (M = (H = H && H.get(l[C + 1])) && H.length) { + if (M = (H = H && H.get(m[C + 1])) && H.length) { x++, z.push(H); - } else if (!q) { - return n ? d : new Y(d); + } else if (!r) { + return p ? f : new Y(f); } } } if (x) { - y = Ua(y, z, n); - D = y.length; - if (!D && !q) { - return n ? y : new Y(y); + y = Ua(y, z, p); + E = y.length; + if (!E && !r) { + return p ? y : new Y(y); } x--; } } - if (D) { - f[m] = A, d.push(y), m++; - } else if (1 === h.length) { - return n ? d : new Y(d); + if (E) { + g[q] = A, f.push(y), q++; + } else if (1 === l.length) { + return p ? f : new Y(f); } } - 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 '" + l[t] + ":" + l[t + 1] + "' was not found because there is no field '" + l[t] + "'."), q) { + if (n) { + if (this.db && m && m.length && !J) { + for (d = 0; d < m.length; d += 2) { + g = this.index.get(m[d]); + if (!g) { + if (console.warn("Tag '" + m[d] + ":" + m[d + 1] + "' was not found because there is no field '" + m[d] + "'."), r) { continue; } else { - return n ? d : new Y(d); + return p ? f : new Y(f); } } - p.push(f.db.tag(l[t + 1], b, u, !1)); + n.push(g.db.tag(m[d + 1], c, u, !1)); } } const B = this; - return Promise.all(p).then(function(y) { - return y.length ? B.search(a, b, c, y) : y; + return Promise.all(n).then(function(y) { + return y.length ? B.search(a, c, b, y) : y; }); } - if (!m) { - return n ? d : new Y(d); + if (!q) { + return p ? f : new Y(f); } - if (g && (!t || !this.store)) { - return d[0]; + if (k && (!d || !this.store)) { + return f[0]; } - 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 n ? r ? cb(a, q, this.index, g, r) : q : new Y(q); + n = []; + for (u = 0; u < g.length; u++) { + r = f[u]; + d && r.length && "undefined" === typeof r[0].doc && (this.db ? n.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = X.call(this, r)); + if (k) { + return p ? t ? cb(a, r, this.index, k, t) : r : new Y(r); } - d[u] = {field:f[u], result:q}; + f[u] = {field:g[u], result:r}; } - if (t && this.db && p.length) { + if (d && this.db && n.length) { const B = this; - return Promise.all(p).then(function(y) { + return Promise.all(n).then(function(y) { for (let A = 0; A < y.length; A++) { - d[A].result = y[A]; + f[A].result = y[A]; } - return k ? fb(d) : r ? cb(a, d, B.index, g, r) : d; + return h ? gb(f) : t ? cb(a, f, B.index, k, t) : f; }); } - return k ? fb(d) : r ? cb(a, d, this.index, g, r) : d; + return h ? gb(f) : t ? cb(a, f, this.index, k, t) : f; }; -function fb(a) { - const b = [], c = G(); +function fb(a, c) { + return "undefined" === typeof a ? c : a; +} +function gb(a) { + const c = [], b = 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)); + h = f[g], "object" !== typeof h && (h = {id:h}), k = h.id, (l = b[k]) ? l.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); } } - return b; + return c; } -function eb(a, b, c, e, d) { +function db(a, c, b, 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 - e) && 0 < a) { - if (a > c || e) { - f = f.slice(e, e + c); + if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if (a > b || e) { + f = f.slice(e, e + b); } d && (f = X.call(this, f)); return f; @@ -1711,45 +1721,45 @@ function X(a) { if (!this || !this.store) { return a; } - const b = Array(a.length); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b[c] = {id:e, doc:this.store.get(e)}; + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; } - return b; + return c; } ;function Pa(a) { if (!this || this.constructor !== Pa) { return new Pa(a); } - const b = a.document || a.doc || a; - let c, e; + const c = a.document || a.doc || a; + let b, e; this.F = []; this.field = []; this.J = []; - this.key = (c = b.key || b.id) && gb(c, this.J) || "id"; + this.key = (b = c.key || c.id) && hb(b, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; 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 && (e ? new U(e) : new Map()); - this.cache = (c = a.cache || null) && new hb(c); + this.C = (b = c.store || null) && b && !0 !== b && []; + this.store = b && (e ? new U(e) : new Map()); + this.cache = (b = a.cache || null) && new ib(b); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = ib.call(this, a, b); + this.index = jb.call(this, a, c); this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { + if (b = c.tag) { + if ("string" === typeof b && (b = [b]), b.length) { this.tag = new Map(); this.D = []; this.R = []; - for (let d = 0, f, g; d < c.length; d++) { - f = c[d]; + for (let d = 0, f, g; d < b.length; d++) { + f = b[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - 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)); + f.custom ? this.D[d] = f.custom : (this.D[d] = hb(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()); } @@ -1767,15 +1777,15 @@ function X(a) { const k = new Map(); let h = 0; for (const m of f.index.entries()) { - const n = m[0]; + const q = m[0]; var l = m[1]; if (l.then) { l = d[h].encoder || {}; - let r = k.get(l); - r || (r = l.encode ? l : new ma(l), k.set(l, r)); + let p = k.get(l); + p || (p = l.encode ? l : new ma(l), k.set(l, p)); l = g[h]; - l.encoder = r; - f.index.set(n, l); + l.encoder = p; + f.index.set(q, l); h++; } } @@ -1791,51 +1801,51 @@ 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)."); } - let b = this.field; + let c = this.field; if (this.tag) { for (let f = 0, g; f < this.R.length; f++) { g = this.R[f]; - var c = void 0; - 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); + var b = void 0; + this.index.set(g, b = new P({}, this.reg)); + c === this.field && (c = c.slice(0)); + c.push(g); + b.tag = this.tag.get(g); } } - c = []; + b = []; 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]; + for (let f = 0, g, k; f < c.length; f++) { + e.field = k = c[f]; g = this.index.get(k); const h = new a.constructor(a.id, e); h.id = a.id; - c[f] = h.mount(g); + b[f] = h.mount(g); g.document = !0; f ? g.bypass = !0 : g.store = this.store; } const d = this; - return this.db = Promise.all(c).then(function() { + return this.db = Promise.all(b).then(function() { d.db = !0; }); }; -v.commit = async function(a, b) { - const c = []; +v.commit = async function(a, c) { + const b = []; for (const e of this.index.values()) { - c.push(e.commit(a, b)); + b.push(e.commit(a, c)); } - await Promise.all(c); + await Promise.all(b); this.reg.clear(); }; v.destroy = function() { const a = []; - for (const b of this.index.values()) { - a.push(b.destroy()); + for (const c of this.index.values()) { + a.push(c.destroy()); } return Promise.all(a); }; -function ib(a, b) { - const c = new Map(); - let e = b.index || b.field || b; +function jb(a, c) { + const b = new Map(); + let e = c.index || c.field || c; L(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { f = e[d]; @@ -1844,48 +1854,48 @@ function ib(a, b) { if (this.worker) { const k = new Aa(g); k.encoder = g.encoder; - c.set(f, k); + b.set(f, k); } - 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.worker || b.set(f, new P(g, this.reg)); + g.custom ? this.F[d] = g.custom : (this.F[d] = hb(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; + a = c.store; 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)); + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = hb(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; + return b; } -function gb(a, b) { - const c = a.split(":"); +function hb(a, c) { + const b = a.split(":"); 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); + for (let d = 0; d < b.length; d++) { + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); } - e < c.length && (c.length = e); - return 1 < e ? c : c[0]; + e < b.length && (b.length = e); + return 1 < e ? b : b[0]; } -v.append = function(a, b) { - return this.add(a, b, !0); +v.append = function(a, c) { + return this.add(a, c, !0); }; -v.update = function(a, b) { - return this.remove(a).add(a, b); +v.update = function(a, c) { + return this.remove(a).add(a, c); }; v.remove = function(a) { aa(a) && (a = ea(a, this.key)); - for (var b of this.index.values()) { - b.remove(a, !0); + for (var c of this.index.values()) { + c.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { - for (let c of this.tag.values()) { - for (let e of c) { - b = e[0]; + for (let b of this.tag.values()) { + for (let e of b) { + c = e[0]; const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); + -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); } } } @@ -1897,13 +1907,13 @@ v.remove = function(a) { }; v.clear = function() { const a = []; - for (const b of this.index.values()) { - const c = b.clear(); - c.then && a.push(c); + for (const c of this.index.values()) { + const b = c.clear(); + b.then && a.push(b); } if (this.tag) { - for (const b of this.tag.values()) { - b.clear(); + for (const c of this.tag.values()) { + c.clear(); } } this.store && this.store.clear(); @@ -1920,92 +1930,92 @@ v.cleanup = function() { return this; }; 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; + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) { + return c[0] && c[0].doc || null; }) : this.store.get(a) || null; }; -v.set = function(a, b) { - "object" === typeof a && (b = a, a = ea(b, this.key)); - this.store.set(a, b); +v.set = function(a, c) { + "object" === typeof a && (c = a, a = ea(c, this.key)); + this.store.set(a, c); return this; }; -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, e = 1)) && b.then) { +v.searchCache = kb; +v.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) { const k = this; - return b.then(function() { - return k.export(a, g, c + 1); + return c.then(function() { + return k.export(a, g, b + 1); }); } - return this.export(a, g, c + 1); + return this.export(a, g, b + 1); } let d, f; switch(e) { case 0: d = "reg"; f = Ga(this.reg); - b = null; + c = null; break; case 1: d = "tag"; f = this.tag && Ea(this.tag, this.reg.size); - b = null; + c = null; break; case 2: d = "doc"; f = this.store && Ca(this.store); - b = null; + c = null; break; default: return; } - return Ia.call(this, a, b, d, f, c, e); + return Ia.call(this, a, c, d, f, b, e); }; -v.import = function(a, b) { - var c = a.split("."); - "json" === c[c.length - 1] && c.pop(); - const e = 2 < c.length ? c[0] : ""; - c = 2 < c.length ? c[2] : c[1]; +v.import = function(a, c) { + var b = a.split("."); + "json" === b[b.length - 1] && b.pop(); + const e = 2 < b.length ? b[0] : ""; + b = 2 < b.length ? b[2] : b[1]; if (this.worker && e) { return this.index.get(e).import(a); } - if (b) { - "string" === typeof b && (b = JSON.parse(b)); + if (c) { + "string" === typeof c && (c = JSON.parse(c)); if (e) { - return this.index.get(e).import(c, b); + return this.index.get(e).import(b, c); } - switch(c) { + switch(b) { case "reg": this.fastupdate = !1; - this.reg = Ha(b, this.reg); + this.reg = Ha(c, 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 = []; + c = []; for (const d of this.index.values()) { - b.push(d.import(a)); + c.push(d.import(a)); } - return Promise.all(b); + return Promise.all(c); } break; case "tag": - this.tag = Fa(b, this.tag); + this.tag = Fa(c, this.tag); break; case "doc": - this.store = Da(b, this.store); + this.store = Da(c, this.store); } } }; ra(Pa.prototype); -function jb(a, b, c) { - const e = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new hb()); +function kb(a, c, b) { + const e = (c ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); + this.cache || (this.cache = new ib()); let d = this.cache.get(e); if (!d) { - d = this.search(a, b, c); + d = this.search(a, c, b); if (d.then) { const f = this; d.then(function(g) { @@ -2017,81 +2027,81 @@ function jb(a, b, c) { } return d; } -function hb(a) { +function ib(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -hb.prototype.set = function(a, b) { - this.cache.set(this.h = a, b); +ib.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); }; -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; +ib.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; }; -hb.prototype.remove = function(a) { - for (const b of this.cache) { - const c = b[0]; - b[1].includes(a) && this.cache.delete(c); +ib.prototype.remove = function(a) { + for (const c of this.cache) { + const b = c[0]; + c[1].includes(a) && this.cache.delete(b); } }; -hb.prototype.clear = function() { +ib.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; c < a.length; c++) { - var b = a[c]; - 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++) { +const lb = {normalize:!1, numeric:!1, dedupe:!1}; +const mb = {}; +const nb = 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 ob = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), pb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const qb = {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 rb = {Exact:lb, Default:mb, Normalize:mb, LatinBalance:{mapper:nb}, LatinAdvanced:{mapper:nb, matcher:ob, replacer:pb}, LatinExtra:{mapper:nb, replacer:pb.concat([/(?!^)[aeo]/g, ""]), matcher:ob}, 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 = qb[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = qb[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = e; + a[b] = e; } -}}, 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) { +}}, CJK:{split:""}, LatinExact:lb, LatinDefault:mb, LatinSimple:mb}; +P.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { if (this.fastupdate) { - for (let e = 0, d; e < c.length; e++) { - if (d = c[e]) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { if (2 > d.length) { d.pop(); } else { const f = d.indexOf(a); - f === c.length - 1 ? d.pop() : d.splice(f, 1); + f === b.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - rb(this.map, a), this.depth && rb(this.ctx, a); + sb(this.map, a), this.depth && sb(this.ctx, a); } - b || this.reg.delete(a); + c || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && sb(this)); + this.db && (this.commit_task.push({del:a}), this.T && tb(this)); this.cache && this.cache.remove(a); return this; }; -function rb(a, b) { - let c = 0; - var e = "undefined" === typeof b; +function sb(a, c) { + let b = 0; + var e = "undefined" === typeof c; if (a.constructor === Array) { for (let d = 0, f, g; d < a.length; d++) { if ((f = a[d]) && f.length) { if (e) { - c++; + b++; } else { - if (g = f.indexOf(b), 0 <= g) { - 1 < f.length ? (f.splice(g, 1), c++) : delete a[d]; + if (g = f.indexOf(c), 0 <= g) { + 1 < f.length ? (f.splice(g, 1), b++) : delete a[d]; break; } else { - c++; + b++; } } } @@ -2099,37 +2109,37 @@ function rb(a, b) { } else { for (let d of a.entries()) { e = d[0]; - const f = rb(d[1], b); - f ? c += f : a.delete(e); + const f = sb(d[1], c); + f ? b += f : a.delete(e); } } - return c; + return b; } -;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 (!e && !c && this.reg.has(a)) { - return this.update(a, b); +;const ub = {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, c, b, e) { + if (c && (a || 0 === a)) { + if (!e && !b && this.reg.has(a)) { + return this.update(a, c); } e = this.depth; - b = this.encoder.encode(b, !e); - const l = b.length; + c = this.encoder.encode(c, !e); + const l = c.length; if (l) { - 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 = ""; + const m = G(), q = G(), p = this.resolution; + for (let t = 0; t < l; t++) { + let r = c[this.rtl ? l - 1 - t : t]; + var d = r.length; + if (d && (e || !q[r])) { + var f = this.score ? this.score(c, r, t, null, 0) : vb(p, l, t), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let u = 0, p; u < d; u++) { + for (let u = 0, n; 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); + g = r.substring(u, f); + n = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(c, r, t, g, n) : vb(p, l, t, d, n); + wb(this, q, g, k, a, b); } } break; @@ -2138,26 +2148,26 @@ P.prototype.add = function(a, b, c, e) { case "reverse": 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 = r[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, r, t, g, k) : vb(p, l, t, d, k); + wb(this, q, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += t[this.rtl ? d - 1 - k : k], vb(this, n, g, f, a, c); + g += r[this.rtl ? d - 1 - k : k], wb(this, q, g, f, a, b); } break; } default: - 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); + if (wb(this, q, r, f, a, b), e && 1 < l && t < l - 1) { + for (d = G(), g = this.U, f = r, k = Math.min(e + 1, this.rtl ? t + 1 : l - t), d[f] = 1, h = 1; h < k; h++) { + if ((r = c[this.rtl ? l - 1 - t - h : t + h]) && !d[r]) { + d[r] = 1; + const u = this.score ? this.score(c, f, t, r, h - 1) : vb(g + (l / 2 > g ? 0 : 1), l, t, k - 1, h - 1), n = this.bidirectional && r > f; + wb(this, m, n ? f : r, u, a, b, n ? r : f); } } } @@ -2166,105 +2176,109 @@ P.prototype.add = function(a, b, c, e) { } this.fastupdate || this.reg.add(a); } else { - b = ""; + c = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && sb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && tb(this)); return this; }; -function vb(a, b, c, e, d, f, g) { +function wb(a, c, b, 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 (!c[b] || g && !(h = c[b])[g]) { + if (g ? (c = h || (c[b] = G()), 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 = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { if (k.length === 2 ** 31 - 1) { - b = new T(k); + c = new T(k); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(k) && (l[l.indexOf(k)] = b); + l.includes(k) && (l[l.indexOf(k)] = c); } } - h[e] = k = b; + h[e] = k = c; } 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 && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; +function vb(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; } -;P.prototype.search = function(a, b, c) { - c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); - 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; +;P.prototype.search = function(a, c, b) { + b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); + if (b && b.cache) { + return b.cache = !1, a = this.searchCache(a, c, b), b.cache = !0, a; + } + let e = [], d, f, g, k = 0, h, l, m, q, p; + b && (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, p = (h = b.resolve) && b.enrich, m = b.boost, q = b.resolution, l = this.db && b.tag); + "undefined" === typeof h && (h = this.resolve); f = this.depth && !1 !== f; - let q = this.encoder.encode(a, !f); - d = q.length; - b = b || (h ? 100 : 0); + let t = this.encoder.encode(a, !f); + d = t.length; + c = c || (h ? 100 : 0); if (1 === d) { - return wb.call(this, q[0], "", b, k, h, r, l); + return xb.call(this, t[0], "", c, k, h, p, l); } if (2 === d && f && !g) { - return wb.call(this, q[1], q[0], b, k, h, r, l); + return xb.call(this, t[1], t[0], c, k, h, p, l); } - let t = G(), u = 0, p; - f && (p = q[0], u = 1); - n || 0 === n || (n = p ? this.U : this.resolution); + let r = G(), u = 0, n; + f && (n = t[0], u = 1); + q || 0 === q || (q = n ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, q, b, k, g, h, r, l), !1 !== a)) { - return a; + if (this.db.search && (b = this.db.search(this, t, c, k, g, h, p, l), !1 !== b)) { + return b; } const z = this; return async function() { 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)) { + if ((J = t[u]) && !r[J]) { + r[J] = 1; + x = await yb(z, J, n, 0, 0, !1, !1); + if (x = zb(x, e, g, q)) { e = x; break; } - p && (g && x && e.length || (p = J)); + n && (g && x && e.length || (n = J)); } - g && p && u === d - 1 && !e.length && (n = z.resolution, p = "", u = -1, t = G()); + g && n && u === d - 1 && !e.length && (q = z.resolution, n = "", u = -1, r = G()); } - return zb(e, n, b, k, g, m, h); + return Ab(e, q, c, k, g, m, h); }(); } 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)) { + if ((x = t[u]) && !r[x]) { + r[x] = 1; + z = yb(this, x, n, 0, 0, !1, !1); + if (z = zb(z, e, g, q)) { e = z; break; } - p && (g && z && e.length || (p = x)); + n && (g && z && e.length || (n = x)); } - g && p && u === d - 1 && !e.length && (n = this.resolution, p = "", u = -1, t = G()); + g && n && u === d - 1 && !e.length && (q = this.resolution, n = "", u = -1, r = G()); } - return zb(e, n, b, k, g, m, h); + return Ab(e, q, c, k, g, m, h); }; -function zb(a, b, c, e, d, f, g) { +function Ab(a, c, b, e, d, f, g) { let k = a.length, h = a; if (1 < k) { - h = Sa(a, b, c, e, d, f, g); + h = Sa(a, c, b, e, d, f, g); } else if (1 === k) { - return g ? Va.call(null, a[0], c, e) : new Y(a[0]); + return g ? Va.call(null, a[0], b, e) : new Y(a[0]); } return g ? h : new Y(h); } -function wb(a, b, c, e, d, f, g) { - a = xb(this, a, b, c, e, d, f, g); +function xb(a, c, b, e, d, f, g) { + a = yb(this, a, c, b, 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(); + }) : a && a.length ? d ? Va.call(this, a, b, e) : new Y(a) : d ? [] : new Y(); } -function yb(a, b, c, e) { +function zb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { - b.push(a); + c.push(a); return; } for (let f = 0, g; f < e; f++) { @@ -2273,53 +2287,53 @@ function yb(a, b, c, e) { } } if (d.length) { - b.push(d); + c.push(d); return; } } - if (!c) { + if (!b) { return d; } } -function xb(a, b, c, e, d, f, g, k) { +function yb(a, c, b, e, d, f, g, k) { let h; - c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); + b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); if (a.db) { - return a.db.get(b, c, e, d, f, g, k); + return a.db.get(c, b, e, d, f, g, k); } - a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); + a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;function P(a, b) { +;function P(a, c) { if (!this || this.constructor !== P) { return new P(a); } if (a) { - var c = L(a) ? a : a.preset; - c && (tb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, tb[c], a)); + var b = L(a) ? a : a.preset; + b && (ub[b] || console.warn("Preset not found: " + b), a = Object.assign({}, ub[b], a)); } else { a = {}; } - c = a.context; - const e = !0 === c ? {depth:1} : c || {}, d = L(a.encoder) ? qb[a.encoder] : a.encode || a.encoder || {}; + b = a.context; + const e = !0 === b ? {depth:1} : b || {}, d = L(a.encoder) ? rb[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.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; 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 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()); + (b = a.keystore || 0) && (this.keystore = b); + this.map = b ? new U(b) : new Map(); + this.ctx = b ? new U(b) : new Map(); + this.reg = c || (this.fastupdate ? b ? new U(b) : new Map() : b ? new V(b) : new Set()); this.U = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new hb(c); + this.cache = (b = a.cache || null) && new ib(b); this.resolve = !1 !== a.resolve; - if (c = a.db) { - this.db = this.mount(c); + if (b = a.db) { + this.db = this.mount(b); } this.T = !1 !== a.commit; this.commit_task = []; @@ -2331,15 +2345,15 @@ v.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -v.commit = function(a, b) { +v.commit = function(a, c) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, b); + return this.db.commit(this, a, c); }; v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function sb(a) { +function tb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2353,26 +2367,26 @@ v.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -v.append = function(a, b) { - return this.add(a, b, !0); +v.append = function(a, c) { + return this.add(a, c, !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.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); }; v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - rb(this.map); - this.depth && rb(this.ctx); + sb(this.map); + this.depth && sb(this.ctx); return this; }; -v.searchCache = jb; -v.export = function(a, b, c = 0, e = 0) { +v.searchCache = kb; +v.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -2394,60 +2408,60 @@ v.export = function(a, b, c = 0, e = 0) { default: return; } - return Ia.call(this, a, b, d, f, c, e); + return Ia.call(this, a, c, d, f, b, 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 < a.length ? a[1] : a[0], a) { +v.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 = Ha(b, this.reg); + this.reg = Ha(c, this.reg); break; case "map": - this.map = Da(b, this.map); + this.map = Da(c, this.map); break; case "ctx": - this.ctx = Fa(b, this.ctx); + this.ctx = Fa(c, this.ctx); } } }; v.serialize = function(a = !0) { - let b = "", c = "", e = ""; + let c = "", b = "", e = ""; if (this.reg.size) { let f; for (var d of this.reg.keys()) { - f || (f = typeof d), b += (b ? "," : "") + ("string" === f ? '"' + d + '"' : d); + f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } - b = "index.reg=new Set([" + b + "]);"; - c = La(this.map, f); - c = "index.map=new Map([" + c + "]);"; + c = "index.reg=new Set([" + c + "]);"; + b = Ja(this.map, f); + b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = La(g[1], f); + let k = Ja(g[1], f); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } - return a ? "function inject(index){" + b + c + e + "}" : b + c + e; + return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; 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); +const Bb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Cb = ["map", "ctx", "tag", "reg", "cfg"], Db = G(); +function Eb(a, c = {}) { + if (!this || this.constructor !== Eb) { + return new Eb(a, c); } - "object" === typeof a && (b = a, a = a.name); + "object" === typeof a && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); this.id = "flexsearch" + (a ? ":" + a.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""); - this.field = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.type = b.type; + this.field = c.field ? c.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; + this.type = c.type; this.fastupdate = this.support_tag_search = !1; this.db = null; this.h = {}; } -v = Db.prototype; +v = Eb.prototype; v.mount = function(a) { if (a.index) { return a.mount(this); @@ -2461,20 +2475,20 @@ v.open = function() { } let a = this; navigator.storage && navigator.storage.persist(); - 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 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 : "" : "")); + Db[a.id] || (Db[a.id] = []); + Db[a.id].push(a.field); + const c = Bb.open(a.id, 1); + c.onupgradeneeded = function() { + const b = a.db = this.result; + for (let e = 0, d; e < Cb.length; e++) { + d = Cb[e]; + for (let f = 0, g; f < Db[a.id].length; f++) { + g = Db[a.id][f], b.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || b.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } } }; - return a.db = Z(b, function(c) { - a.db = c; + return a.db = Z(c, function(b) { + a.db = b; a.db.onversionchange = function() { a.close(); }; @@ -2485,25 +2499,25 @@ v.close = function() { this.db = null; }; v.destroy = function() { - const a = Ab.deleteDatabase(this.id); + const a = Bb.deleteDatabase(this.id); return Z(a); }; v.clear = function() { const a = []; - 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 : "" : "")); + for (let b = 0, e; b < Cb.length; b++) { + e = Cb[b]; + for (let d = 0, f; d < Db[this.id].length; d++) { + f = Db[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } } - const b = this.db.transaction(a, "readwrite"); - for (let c = 0; c < a.length; c++) { - b.objectStore(a[c]).clear(); + const c = this.db.transaction(a, "readwrite"); + for (let b = 0; b < a.length; b++) { + c.objectStore(a[b]).clear(); } - return Z(b); + return Z(c); }; -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); +v.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { + a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); const g = this; return Z(a).then(function(k) { let h = []; @@ -2511,7 +2525,7 @@ v.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { return h; } if (d) { - if (!c && !e && 1 === k.length) { + if (!b && !e && 1 === k.length) { return k[0]; } for (let l = 0, m; l < k.length; l++) { @@ -2520,12 +2534,12 @@ v.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { e -= m.length; continue; } - const n = c ? e + Math.min(m.length - e, c) : m.length; - for (let r = e; r < n; r++) { - h.push(m[r]); + const q = b ? e + Math.min(m.length - e, b) : m.length; + for (let p = e; p < q; p++) { + h.push(m[p]); } e = 0; - if (h.length === c) { + if (h.length === b) { break; } } @@ -2535,27 +2549,27 @@ v.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { return k; }); }; -v.tag = function(a, b = 0, c = 0, e = !1) { +v.tag = function(a, c = 0, b = 0, e = !1) { a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); const d = this; return Z(a).then(function(f) { - if (!f || !f.length || c >= f.length) { + if (!f || !f.length || b >= f.length) { return []; } - if (!b && !c) { + if (!c && !b) { return f; } - f = f.slice(c, c + b); + f = f.slice(b, b + c); 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 = []; + const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = []; for (let e = 0; e < a.length; e++) { - c[e] = Z(b.get(a[e])); + b[e] = Z(c.get(a[e])); } - return Promise.all(c).then(function(e) { + return Promise.all(b).then(function(e) { for (let d = 0; d < e.length; d++) { e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null}; } @@ -2564,30 +2578,30 @@ v.enrich = function(a) { }; v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Z(a).then(function(b) { - return !!b; + return Z(a).then(function(c) { + return !!c; }); }; v.search = null; v.info = function() { }; -v.transaction = function(a, b, c) { +v.transaction = function(a, c, b) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; - let e = this.h[a + ":" + b]; + let e = this.h[a + ":" + c]; if (e) { - return c.call(this, e); + return b.call(this, e); } - 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; + let d = this.db.transaction(a, c); + this.h[a + ":" + c] = e = d.objectStore(a); + const f = b.call(this, e); + this.h[a + ":" + c] = null; return Z(d).finally(function() { d = e = null; return f; }); }; -v.commit = async function(a, b, c) { - if (b) { +v.commit = async function(a, c, b) { + if (c) { await this.clear(), a.commit_task = []; } else { let e = a.commit_task; @@ -2595,30 +2609,30 @@ v.commit = async function(a, b, c) { for (let d = 0, f; d < e.length; d++) { if (f = e[d], f.clear) { await this.clear(); - b = !0; + c = !0; break; } else { e[d] = f.del; } } - b || (c || (e = e.concat(da(a.reg))), e.length && await this.remove(e)); + c || (b || (e = e.concat(da(a.reg))), e.length && await this.remove(e)); } 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() { + g.length && (c ? 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]); + for (let m = 0, q, p; m < l; m++) { + if ((p = g[m]) && p.length) { + if ((q = k[m]) && q.length) { + for (h = 0; h < p.length; h++) { + q.push(p[h]); } } else { - k[m] = r; + k[m] = p; } h = 1; } @@ -2634,27 +2648,27 @@ v.commit = async function(a, b, c) { 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() { + l.length && (c ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { let m = this.result; - var n; + var q; if (m && m.length) { - 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]); + const p = Math.max(m.length, l.length); + for (let t = 0, r, u; t < p; t++) { + if ((u = l[t]) && u.length) { + if ((r = m[t]) && r.length) { + for (q = 0; q < u.length; q++) { + r.push(u[q]); } } else { - m[q] = u; + m[t] = u; } - n = 1; + q = 1; } } } else { - m = l, n = 1; + m = l, q = 1; } - n && e.put(m, f + ":" + h); + q && e.put(m, f + ":" + h); }); } } @@ -2678,13 +2692,13 @@ v.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function Eb(a, b, c) { +function Fb(a, c, b) { 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 (k = b ? e : e[g]) { + for (let h = 0, l, m; h < c.length; h++) { + if (m = c[h], l = k.indexOf(m), 0 <= l) { if (d = 1, 1 < k.length) { k.splice(l, 1); } else { @@ -2695,7 +2709,7 @@ function Eb(a, b, c) { } f += k.length; } - if (c) { + if (b) { break; } } @@ -2704,38 +2718,38 @@ function Eb(a, b, c) { } 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 && Eb(c, a); + return Promise.all([this.transaction("map", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && Fb(b, a); }; - }), this.transaction("ctx", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && Eb(c, a); + }), this.transaction("ctx", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && Fb(b, a); }; - }), this.transaction("tag", "readwrite", function(b) { - b.openCursor().onsuccess = function() { - const c = this.result; - c && Eb(c, a, !0); + }), this.transaction("tag", "readwrite", function(c) { + c.openCursor().onsuccess = function() { + const b = this.result; + b && Fb(b, a, !0); }; - }), this.transaction("reg", "readwrite", function(b) { - for (let c = 0; c < a.length; c++) { - b.delete(a[c]); + }), this.transaction("reg", "readwrite", function(c) { + for (let b = 0; b < a.length; b++) { + c.delete(a[b]); } })]); }; -function Z(a, b) { - return new Promise((c, e) => { +function Z(a, c) { + return new Promise((b, e) => { a.onsuccess = a.oncomplete = function() { - b && b(this.result); - b = null; - c(this.result); + c && c(this.result); + c = null; + b(this.result); }; a.onerror = a.onblocked = e; a = null; }); } -;export default {Index:P, Charset:qb, Encoder:ma, Document:Pa, Worker:Aa, Resolver:Y, IndexedDB:Db, Language:{}}; +;export default {Index:P, Charset:rb, Encoder:ma, Document:Pa, Worker:Aa, Resolver:Y, IndexedDB:Eb, Language:{}}; -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 +export const Index=P;export const Charset=rb;export const Encoder=ma;export const Document=Pa;export const Worker=Aa;export const Resolver=Y;export const IndexedDB=Eb;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 508cee1..9696a49 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.160 (Bundle/Module) + * FlexSearch.js v0.8.161 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -14,17 +14,17 @@ null,this.stemmer);this.replacer=F(a.replacer,null,this.replacer);this.minlength 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; +[],d=G(),f,g,k=this.split||""===this.split?a.split(this.split):[a];for(let l=0,m,q;lthis.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 p;for(;p!==m&&2this.stemmer.get(t))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(p)));if(m&&this.replacer)for(h=0;m&&hthis.S&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==q)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");ta.call(a,"searchCache")}let ua,xa,ya;function za(){ua=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]);ua?ya||(ya=Date.now()-xa>=this.priority*this.priority*3):(ua=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 Qa(a,b,c,e,d,f,g,k){if(a=a[g])if(e===b.length-1){if(a.constructor===Array){if(c[e]){for(b=0;bc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d= +[];for(let q=0,p;qe)e-=p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?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:q}=Wa(this,"and",arguments);return Ya.call(this,f,g,k,h,l,m,q)}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;cJ&&(J=n.length+(n?1:0)),B=n.length+(n?1:0)+M.length,z+=E,wa.push(x.length),x.push({match:M})),n+=(n?" ":"")+M)}if(!w)D=y[A],n+=(n?" ":"")+D,h&&x.push({text:D});else if(h&&z>=h)break}z=wa.length*(f.length-2);if(t||r||h&&n.length-z>h)if(z=h+z-2*p,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-=p}n=x[I].text;if(K=r&&C[w])if(0K)if(A[w+1]=1,l)n=n.substring(0,K);else continue;(K-=n.length)||(K=-1);C[w]=K}else{A[w+1]=1;continue}if(E+n.length+1<=h)n=" "+n,B[w]+=n;else if(l)S=h-E-1,0=I){if(0>I){A[w]=1;z[w]=1;continue}E-=p}n=x[I].text;if(K=t&&D[w])if(0K)if(A[w]=1,l)n=n.substring(n.length- +K);else continue;(K-=n.length)||(K=-1);D[w]=K}else{A[w]=1;continue}if(E+n.length+1<=h)n+=" ",B[w]=n+B[w];else if(l)S=n.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))} +return Promise.all(b)}break;case "tag":this.tag=Ga(b,this.tag);break;case "doc":this.store=Ea(b,this.store)}}};sa(W.prototype);function kb(a,b,c){const e=(b?""+a:"object"===typeof a?""+a.query:a).toLowerCase();this.cache||(this.cache=new ib);let d=this.cache.get(e);if(!d){d=this.search(a,b,c);if(d.then){const f=this;d.then(function(g){f.cache.set(e,g);return g})}this.cache.set(e,d)}return d}function ib(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}ib.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)}; +ib.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};ib.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};ib.prototype.clear=function(){this.cache.clear();this.h=""};const lb={normalize:!1,numeric:!1,dedupe:!1};const mb={};const nb=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 ob=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),pb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const qb={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 rb={Exact:lb,Default:mb,Normalize:mb,LatinBalance:{mapper:nb},LatinAdvanced:{mapper:nb,matcher:ob,replacer:pb},LatinExtra:{mapper:nb,replacer:pb.concat([/(?!^)[aeo]/g,""]),matcher:ob},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 sb(this.map,a),this.depth&&sb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&tb(this));this.cache&&this.cache.remove(a);return this}; +function sb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;du;f--){g=r.substring(u,f);n=this.rtl?d-1-u:u;var k=this.score?this.score(b,r,t,g,n):vb(p, +l,t,d,n);wb(this,q,g,k,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,t,k-1,h-1),n=this.bidirectional&&r>f;wb(this,m,n?f:r,u,a,c,n?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&tb(this));return this}; +function wb(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 vb(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({},ub[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=L(a.encoder)?rb[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 ib(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 tb(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.cleanup=function(){if(!this.fastupdate)return this;sb(this.map);this.depth&&sb(this.ctx);return this};v.searchCache=kb;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=m.length){e-=m.length;continue}const q=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; 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 +for(let m=0,q,p;m{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:rb,Encoder:ma,Document:W,Worker:Ba,Resolver:Y,IndexedDB:Eb,Language:{}}; +export const Index=O;export const Charset=rb;export const Encoder=ma;export const Document=W;export const Worker=Ba;export const Resolver=Y;export const IndexedDB=Eb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 5f82494..905accc 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.160 (Bundle/Debug) + * FlexSearch.js v0.8.161 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -47,14 +47,14 @@ function I(a, c, b) { function J() { return Object.create(null); } -function K(a) { +function L(a) { return "string" === typeof a; } -function M(a) { +function P(a) { return "object" === typeof a; } -function Q(a, c) { - if (K(c)) { +function R(a, c) { + if (L(c)) { a = a[c]; } else { for (let b = 0; a && b < c.length; b++) { @@ -63,17 +63,10 @@ function Q(a, c) { } return a; } -function aa(a) { - let c = 0; - for (let b = 0, e; b < a.length; b++) { - (e = a[b]) && c < e.length && (c = e.length); - } - return c; -} -;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); +;const ca = /[^\p{L}\p{N}]+/u, da = /(\d{3})/g, ea = /(\D)(\d{3})/g, fa = /(\d{3})(\D)/g, ha = /[\u0300-\u036f]/g; +function S(a = {}) { + if (!this || this.constructor !== S) { + return new S(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -83,7 +76,7 @@ function ja(a = {}) { this.assign(a); } } -A = ja.prototype; +A = S.prototype; A.assign = function(a) { this.normalize = I(a.normalize, !0, this.normalize); let c = a.include, b = c || a.exclude || a.split, e; @@ -111,7 +104,7 @@ A.assign = function(a) { this.numeric = I(a.numeric, e); } else { try { - this.split = I(this.split, ba); + this.split = I(this.split, ca); } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } @@ -130,7 +123,7 @@ A.assign = function(a) { 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 = null, this.O = "number" === typeof b ? b : 2e5, this.F = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; this.M = null; @@ -153,12 +146,12 @@ A.addStemmer = function(a, c) { this.stemmer.set(a, c); this.C += (this.C ? "|" : "") + a; this.N = null; - this.cache && R(this); + this.cache && V(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); + this.cache && V(this); return this; }; A.addMapper = function(a, c) { @@ -170,7 +163,7 @@ A.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && R(this); + this.cache && V(this); return this; }; A.addMatcher = function(a, c) { @@ -184,7 +177,7 @@ A.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && R(this); + this.cache && V(this); return this; }; A.addReplacer = function(a, c) { @@ -193,7 +186,7 @@ A.addReplacer = function(a, c) { } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && R(this); + this.cache && V(this); return this; }; A.encode = function(a, c) { @@ -203,111 +196,112 @@ A.encode = function(a, c) { return this.F.get(a); } } else { - this.H = setTimeout(R, 50, this); + this.H = setTimeout(V, 50, this); } } - this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ia ? a.normalize("NFKD").replace(ia, "").toLowerCase() : a.toLowerCase()); + 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 && 3 < a.length && (a = a.replace(fa, "$1 $2").replace(ha, "$1 $2").replace(ea, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); 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)) { + for (let m = 0, n, C; m < k.length; m++) { + if ((n = C = k[m]) && !(n.length < this.minlength || n.length > this.maxlength)) { if (c) { - if (d[m]) { + if (d[n]) { continue; } - d[m] = 1; + d[n] = 1; } else { - if (f === m) { + if (f === n) { continue; } - f = m; + f = n; } if (b) { - e.push(m); + e.push(n); } else { - if (!this.filter || ("function" === typeof this.filter ? this.filter(m) : !this.filter.has(m))) { - if (this.cache && m.length <= this.L) { + if (!this.filter || ("function" === typeof this.filter ? this.filter(n) : !this.filter.has(n))) { + if (this.cache && n.length <= this.L) { if (this.H) { - var h = this.G.get(m); + var h = this.G.get(n); if (h || "" === h) { h && e.push(h); continue; } } else { - this.H = setTimeout(R, 50, this); + this.H = setTimeout(V, 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, q => this.stemmer.get(q)); + let x; + for (; x !== n && 2 < n.length;) { + x = n, n = n.replace(this.N, q => this.stemmer.get(q)); } } - if (m && (this.mapper || this.dedupe && 1 < m.length)) { + if (n && (this.mapper || this.dedupe && 1 < n.length)) { h = ""; - 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); + for (let x = 0, q = "", r, w; x < n.length; x++) { + r = n.charAt(x), r === q && this.dedupe || ((w = this.mapper && this.mapper.get(r)) || "" === w ? w === q && this.dedupe || !(q = w) || (h += w) : h += q = r); } - m = h; + n = h; } - 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 (h = 0; m && h < this.replacer.length; h += 2) { - m = m.replace(this.replacer[h], this.replacer[h + 1]); + this.matcher && 1 < n.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), n = n.replace(this.M, x => this.matcher.get(x))); + if (n && this.replacer) { + for (h = 0; n && h < this.replacer.length; h += 2) { + n = n.replace(this.replacer[h], this.replacer[h + 1]); } } - 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 !== p) { + this.cache && C.length <= this.L && (this.G.set(C, n), this.G.size > this.O && (this.G.clear(), this.L = this.L / 1.1 | 0)); + if (n) { + if (n !== C) { if (c) { - if (d[m]) { + if (d[n]) { continue; } - d[m] = 1; + d[n] = 1; } else { - if (g === m) { + if (g === n) { continue; } - g = m; + g = n; } } - e.push(m); + e.push(n); } } } } } 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)); + this.cache && a.length <= this.K && (this.F.set(a, e), this.F.size > this.O && (this.F.clear(), this.K = this.K / 1.1 | 0)); return e; }; -function R(a) { +function V(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"); + W.call(a, "add"); + W.call(a, "append"); + W.call(a, "search"); + W.call(a, "update"); + W.call(a, "remove"); + W.call(a, "searchCache"); } -let oa, pa, qa; -function ra() { - oa = qa = 0; +let la, ma, na; +function oa() { + la = na = 0; } -function na(a) { +function W(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) { + la ? na || (na = Date.now() - ma >= this.priority * this.priority * 3) : (la = setTimeout(oa, 0), ma = Date.now()); + if (na) { const f = this; return new Promise(g => { setTimeout(function() { @@ -321,7 +315,7 @@ function na(a) { return b; }; } -;function sa(a, c = 0) { +;function pa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -330,30 +324,30 @@ function na(a) { e.length && b.push(e); return b; } -function ta(a, c) { +function qa(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 ua(a, c = 0) { +function ra(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], sa(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], pa(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function va(a, c) { +function sa(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], ta(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], qa(e[1], d)); } return c; } -function ya(a) { +function ta(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -361,28 +355,28 @@ function ya(a) { b.length && c.push(b); return c; } -function za(a, c) { +function wa(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function Aa(a, c, b, e, d, f, g = 0) { +function xa(a, c, b, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { return this.export(a, c, d, f + 1); } if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { - const l = this; + const m = this; return h.then(function() { - return Aa.call(l, a, c, b, k ? e : null, d, f, g + 1); + return xa.call(m, a, c, b, k ? e : null, d, f, g + 1); }); } - return Aa.call(this, a, c, b, k ? e : null, d, f, g + 1); + return xa.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function Ba(a, c) { +function ya(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; @@ -391,8 +385,8 @@ function Ba(a, c) { 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" === c ? '"' + k[l] + '"' : k[l]); + for (let m = 0; m < k.length; m++) { + h += (h ? "," : "") + ("string" === c ? '"' + k[m] + '"' : k[m]); } h = "[" + h + "]"; f += (f ? "," : "") + h; @@ -402,8 +396,8 @@ function Ba(a, c) { } return b; } -;T.prototype.add = function(a, c, b) { - M(a) && (c = a, a = Q(c, this.key)); +;X.prototype.add = function(a, c, b) { + P(a) && (c = a, a = R(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -416,13 +410,13 @@ function Ba(a, c) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : K(h) && (h = [h]), Ca(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), za(c, h, this.J, 0, e, a, h[0], b); } } } if (this.tag) { for (e = 0; e < this.B.length; e++) { - var f = this.B[e], g = this.T[e]; + var f = this.B[e], g = this.R[e]; d = this.tag.get(g); let k = J(); if ("function" === typeof f) { @@ -435,12 +429,12 @@ function Ba(a, c) { continue; } f.constructor === String && (f = "" + f); - f = Q(c, f); + f = R(c, f); } if (d && 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])))); + L(f) && (f = [f]); + for (let h = 0, m, n; h < f.length; h++) { + m = f[h], k[m] || (k[m] = 1, (g = d.get(m)) ? n = g : d.set(m, n = []), b && n.includes(a) || (n.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -451,23 +445,23 @@ function Ba(a, c) { let k; if (this.A) { k = J(); - for (let h = 0, l; h < this.A.length; h++) { - l = this.A[h]; - if ((b = l.I) && !b(c)) { + for (let h = 0, m; h < this.A.length; h++) { + m = this.A[h]; + if ((b = m.I) && !b(c)) { continue; } - let m; - if ("function" === typeof l) { - m = l(c); - if (!m) { + let n; + if ("function" === typeof m) { + n = m(c); + if (!n) { continue; } - l = [l.U]; - } else if (K(l) || l.constructor === String) { - k[l] = c[l]; + m = [m.S]; + } else if (L(m) || m.constructor === String) { + k[m] = c[m]; continue; } - Da(c, k, l, 0, l[0], m); + Aa(c, k, m, 0, m[0], n); } } this.store.set(a, k || c); @@ -475,21 +469,21 @@ function Ba(a, c) { } return this; }; -function Da(a, c, b, e, d, f) { +function Aa(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++) { - Da(a, c, b, e, d); + Aa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = J()), d = b[++e], Da(a, c, b, e, d); + c = c[d] || (c[d] = J()), d = b[++e], Aa(a, c, b, e, d); } } } -function Ca(a, c, b, e, d, f, g, k) { +function za(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -505,69 +499,15 @@ function Ca(a, c, b, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ca(a, c, b, e, d, f, g, k); + za(a, c, b, e, d, f, g, k); } } else { - g = c[++e], Ca(a, c, b, e, d, f, g, k); + g = c[++e], za(a, c, b, e, d, f, g, k); } } } } -;function Ea(a, c, b, e, d) { - const f = a.length; - let g = [], k, h; - 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; - } - } - } - } - } - if (a = g.length) { - if (d) { - 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 []; - } - g = g[a - 1]; - if (b || e) { - if (g.length > b || e) { - g = g.slice(e, b + e); - } - } - } - } - return g; -} -function Fa(a, c, b) { - const e = [], d = J(); - 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; l < k; l++) { - if (f = g[l], !d[f]) { - if (d[f] = 1, b) { - b--; - } else { - if (e.push(f), e.length === c) { - return e; - } - } - } - } - } - } - return e; -} -function Ga(a, c) { +;function Ba(a, c) { const b = J(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -580,310 +520,38 @@ function Ga(a, c) { } return e; } -;function Ha(a, c, b, e) { +;function Ca(a, c, b) { 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 ? U.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } - let d = []; - for (let f = 0, g, k; f < a.length; f++) { - if ((g = a[f]) && (k = g.length)) { + let e = []; + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && (g = f.length)) { if (b) { - if (b >= k) { - b -= k; + if (b >= g) { + b -= g; continue; } - b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); + b < g && (f = c ? f.slice(b, b + c) : f.slice(b), g = f.length, b = 0); } - k > c && (g = g.slice(0, c), k = c); - if (!d.length && k >= c) { - return e ? U.call(this, g) : g; + g > c && (f = f.slice(0, c), g = c); + if (!e.length && g >= c) { + return f; } - d.push(g); - c -= k; + e.push(f); + c -= g; if (!c) { break; } } } - d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? U.call(this, d) : d; + return e = 1 < e.length ? [].concat.apply([], e) : e[0]; } -;function Ia(a, c, b) { - var e = b[0]; - if (e.then) { - return Promise.all(b).then(function(m) { - return a[c].apply(a, m); - }); - } - if (e[0] && e[0].index) { - return a[c].apply(a, e); - } - e = []; - let d = [], f = 0, g = 0, k, h, l; - for (let m = 0, p; m < b.length; m++) { - if (p = b[m]) { - let r; - if (p.constructor === X) { - r = p.result; - } else if (p.constructor === Array) { - r = p; - } else { - 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; - } - } - if (r.then) { - d.push(r); - } else if (r.length) { - e[m] = r; - } else if (!l && ("and" === c || "xor" === c)) { - e = []; - break; - } - } - } - return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; -} -;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 Ja(a, c, b, e, d, f) { - if (c.length) { - const g = this; - return Promise.all(c).then(function(k) { - a = []; - for (let h = 0, l; h < k.length; h++) { - (l = k[h]).length && (a[h] = l); - } - 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 = 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; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); - } - return Ka.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 { - 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; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); - } - 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 = 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 = 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, 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 p = 0, r; p < a.length; p++) { - if (r = a[p]) { - if (l = r[h]) { - 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(t), f.length === c) { - return f; - } - } else { - const w = h + (p ? d : 0); - f[w] || (f[w] = []); - f[w].push(t); - if (++m === c) { - return f; - } - } - } - } - } - } - } - } - } - return f; -} -;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 Na(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; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); - } - return Na.call(k, a, [], b, e, d, f, g); - }); - } - if (a.length && this.result.length) { - this.result = Oa.call(this, a, b, e, f); - } else if (f) { - return this.resolve(b, e, d); - } - return f ? d ? U.call(this.index, this.result) : this.result : this; -} -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++) { - if (g = this.result[f]) { - for (let h = 0, l; h < g.length; h++) { - if (l = g[h], !a.has(l)) { - if (b) { - b--; - } else { - if (e) { - if (d.push(l), d.length === c) { - return d; - } - } else { - if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { - return d; - } - } - } - } - } - } - } - return d; -} -;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; - } - this.index = null; - this.result = a || []; - this.h = 0; -} -X.prototype.limit = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, e; b < this.result.length; b++) { - if (e = this.result[b]) { - if (e.length <= a) { - if (c[b] = e, a -= e.length, !a) { - break; - } - } else { - c[b] = e.slice(0, a); - break; - } - } - } - this.result = c; - } - return this; -}; -X.prototype.offset = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, e; b < this.result.length; b++) { - if (e = this.result[b]) { - e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0); - } - } - this.result = c; - } - return this; -}; -X.prototype.boost = function(a) { - this.h += a; - return this; -}; -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), Ha.call(d, e, a || 100, c, b)) : e; -}; -J(); -function Pa(a, c, b, e, d) { +;J(); +function Da(a, c, b, e, d) { let f, g, k; "string" === typeof d ? (f = d, d = "") : f = d.template; if (!f) { @@ -895,220 +563,220 @@ function Pa(a, c, b, e, d) { } 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"); + let h = d && d.boundary, m = !d || !1 !== d.clip, n = d && d.merge && k && g && new RegExp(k + " " + g, "g"); d = d && d.ellipsis; - var p = 0; + var C = 0; if ("object" === typeof d) { - var r = d.template; - p = r.length - 2; + var x = d.template; + C = x.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; + C && (d = x.replace("$1", d)); + x = d.length - C; + let q, r; + "object" === typeof h && (q = h.before, 0 === q && (q = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); + C = new Map(); + for (let ua = 0, T, Ja, aa; ua < c.length; ua++) { + let ba; if (e) { - da = c, ca = e; + ba = c, aa = e; } else { - var w = c[wa]; - ca = w.field; - if (!ca) { + var w = c[ua]; + aa = w.field; + if (!aa) { continue; } - da = w.result; + ba = 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) { + Ja = b.get(aa); + T = Ja.encoder; + w = C.get(T); + "string" !== typeof w && (w = T.encode(a), C.set(T, w)); + for (let ia = 0; ia < ba.length; ia++) { + var l = ba[ia].doc; + if (!l) { continue; } - n = Q(n, ca); - if (!n) { + l = R(l, aa); + if (!l) { continue; } - var x = n.trim().split(/\s+/); - if (!x.length) { + var u = l.trim().split(/\s+/); + if (!u.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); + l = ""; + var v = []; + let ja = []; + var E = -1, t = -1, B = 0; + for (var y = 0; y < u.length; y++) { + var z = u[y], H = T.encode(z); 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)); + let p; + if (H && z) { + var D = z.length, M = (T.split ? z.replace(T.split, "") : z).length - H.length, K = "", Q = 0; + for (var U = 0; U < w.length; U++) { + var N = w[U]; + if (N) { + var G = N.length; + G += M; + Q && G <= Q || (N = H.indexOf(N), -1 < N && (K = (N ? z.substring(0, N) : "") + g + z.substring(N, N + G) + k + (N + G < D ? z.substring(N + G) : ""), Q = G, p = !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); + K && (h && (0 > E && (E = l.length + (l ? 1 : 0)), t = l.length + (l ? 1 : 0) + K.length, B += D, ja.push(v.length), v.push({match:K})), l += (l ? " " : "") + K); } - if (!u) { - C = x[z], n += (n ? " " : "") + C, h && y.push({text:C}); + if (!p) { + z = u[y], l += (l ? " " : "") + z, h && v.push({text:z}); } 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 : ""); + B = ja.length * (f.length - 2); + if (q || r || h && l.length - B > h) { + if (B = h + B - 2 * x, y = t - E, 0 < q && (y += q), 0 < r && (y += r), y <= B) { + u = q ? E - (0 < q ? q : 0) : E - ((B - y) / 2 | 0), v = r ? t + (0 < r ? r : 0) : u + B, m || (0 < u && " " !== l.charAt(u) && " " !== l.charAt(u - 1) && (u = l.indexOf(" ", u), 0 > u && (u = 0)), v < l.length && " " !== l.charAt(v - 1) && " " !== l.charAt(v) && (v = l.lastIndexOf(" ", v), v < t ? v = t : ++v)), l = (u ? d : "") + l.substring(u, v) + (v < l.length ? d : ""); } else { - v = []; + t = []; E = {}; B = {}; + y = {}; 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]) { + K = M = D = 0; + for (U = Q = 1;;) { + var O = void 0; + for (let p = 0, F; p < ja.length; p++) { + F = ja[p]; + if (K) { + if (M !== K) { + if (y[p + 1]) { continue; } - F += L; + F += K; if (E[F]) { - D -= r; - B[u + 1] = 1; - z[u + 1] = 1; + D -= x; + B[p + 1] = 1; + y[p + 1] = 1; continue; } - if (F >= y.length - 1) { - if (F >= y.length) { - z[u + 1] = 1; - F >= x.length && (B[u + 1] = 1); + if (F >= v.length - 1) { + if (F >= v.length) { + y[p + 1] = 1; + F >= u.length && (B[p + 1] = 1); continue; } - D -= r; + D -= x; } - n = y[F].text; - if (G = t && H[u]) { + l = v[F].text; + if (G = r && H[p]) { if (0 < G) { - if (n.length > G) { - if (z[u + 1] = 1, l) { - n = n.substring(0, G); + if (l.length > G) { + if (y[p + 1] = 1, m) { + l = l.substring(0, G); } else { continue; } } - (G -= n.length) || (G = -1); - H[u] = G; + (G -= l.length) || (G = -1); + H[p] = G; } else { - z[u + 1] = 1; + y[p + 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; + if (D + l.length + 1 <= h) { + l = " " + l, t[p] += l; + } else if (m) { + O = h - D - 1, 0 < O && (l = " " + l.substring(0, O), t[p] += l), y[p + 1] = 1; } else { - z[u + 1] = 1; + y[p + 1] = 1; continue; } } else { - if (z[u]) { + if (y[p]) { continue; } - F -= N; + F -= M; if (E[F]) { - D -= r; - z[u] = 1; - B[u] = 1; + D -= x; + y[p] = 1; + B[p] = 1; continue; } if (0 >= F) { if (0 > F) { - z[u] = 1; - B[u] = 1; + y[p] = 1; + B[p] = 1; continue; } - D -= r; + D -= x; } - n = y[F].text; - if (G = q && C[u]) { + l = v[F].text; + if (G = q && z[p]) { if (0 < G) { - if (n.length > G) { - if (z[u] = 1, l) { - n = n.substring(n.length - G); + if (l.length > G) { + if (y[p] = 1, m) { + l = l.substring(l.length - G); } else { continue; } } - (G -= n.length) || (G = -1); - C[u] = G; + (G -= l.length) || (G = -1); + z[p] = G; } else { - z[u] = 1; + y[p] = 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; + if (D + l.length + 1 <= h) { + l += " ", t[p] = l + t[p]; + } else if (m) { + O = l.length + 1 - (h - D), 0 <= O && O < l.length && (l = l.substring(O) + " ", t[p] = l + t[p]), y[p] = 1; } else { - z[u] = 1; + y[p] = 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); + l = v[F].match; + q && (z[p] = q); + r && (H[p] = r); + p && D++; + let va; + F ? !p && x && (D += x) : (B[p] = 1, y[p] = 1); + F >= u.length - 1 ? va = 1 : F < v.length - 1 && v[F + 1].match ? va = 1 : x && (D += x); D -= f.length - 2; - if (!u || D + n.length <= h) { - v[u] = n; + if (!p || D + l.length <= h) { + t[p] = l; } else { - P = S = W = B[u] = 0; + O = Q = U = B[p] = 0; break; } - xa && (B[u + 1] = 1, z[u + 1] = 1); + va && (B[p + 1] = 1, y[p + 1] = 1); } - D += n.length; - P = E[F] = 1; + D += l.length; + O = E[F] = 1; } - if (P) { - N === L ? L++ : N++; + if (O) { + M === K ? K++ : M++; } else { - N === L ? S = 0 : W = 0; - if (!S && !W) { + M === K ? Q = 0 : U = 0; + if (!Q && !U) { break; } - S ? (N++, L = N) : L++; + Q ? (M++, K = M) : K++; } } - n = ""; - for (let u = 0, F; u < v.length; u++) { - F = (u && B[u] ? " " : (u && !d ? " " : "") + d) + v[u], n += F; + l = ""; + for (let p = 0, F; p < t.length; p++) { + F = (p && B[p] ? " " : (p && !d ? " " : "") + d) + t[p], l += F; } - d && !B[v.length] && (n += d); + d && !B[t.length] && (l += d); } } - m && (n = n.replace(m, " ")); - da[la].highlight = n; + n && (l = l.replace(n, " ")); + ba[ia].highlight = l; } if (e) { break; @@ -1116,164 +784,173 @@ function Pa(a, c, b, e, d) { } 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, p = !0, r; +;X.prototype.search = function(a, c, b, e) { + b || (!c && P(a) ? (b = a, a = "") : P(c) && (b = c, c = 0)); + if (b && b.cache) { + b.cache = !1; + var d = this.searchCache(a, c, b); + b.cache = !0; + return d; + } + let f = []; + var g = []; + let k, h, m; + let n = 0, C = !0, x; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var q = b.pluck; - var t = b.merge; + var r = b.merge; h = q || b.field || (h = b.index) && (h.index ? null : h); - l = this.tag && b.tag; + m = this.tag && b.tag; k = b.suggest; - 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 = !0; + this.store && b.highlight && !C ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !C && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + x = C && this.store && b.highlight; + d = !!x || C && this.store && b.enrich; c = b.limit || c; var w = b.offset || 0; c || (c = 100); - if (l) { - l.constructor !== Array && (l = [l]); - var n = []; - for (let E = 0, v; E < l.length; E++) { - v = l[E]; - if (K(v)) { + if (m) { + m.constructor !== Array && (m = [m]); + var l = []; + for (let E = 0, t; E < m.length; E++) { + t = m[E]; + if (L(t)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (v.field && v.tag) { - var x = v.tag; - if (x.constructor === Array) { - for (var y = 0; y < x.length; y++) { - n.push(v.field, x[y]); + if (t.field && t.tag) { + var u = t.tag; + if (u.constructor === Array) { + for (var v = 0; v < u.length; v++) { + l.push(t.field, u[v]); } } else { - n.push(v.field, x); + l.push(t.field, u); } } else { - 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]); + u = Object.keys(t); + for (let B = 0, y, z; B < u.length; B++) { + if (y = u[B], z = t[y], z.constructor === Array) { + for (v = 0; v < z.length; v++) { + l.push(y, z[v]); } } else { - n.push(z, C); + l.push(y, z); } } } } - if (!n.length) { + if (!l.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = n; + m = l; if (!a) { - f = []; - 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}); + g = []; + if (l.length) { + for (q = 0; q < l.length; q += 2) { + r = Ea.call(this, l[q], l[q + 1], c, w, d), f.push({field:l[q], tag:l[q + 1], result:r}); } } - return f.length ? Promise.all(f).then(function(E) { - for (let v = 0; v < E.length; v++) { - d[v].result = E[v]; + return g.length ? Promise.all(g).then(function(E) { + for (let t = 0; t < E.length; t++) { + f[t].result = E[t]; } - return d; - }) : d; + return f; + }) : f; } } h && h.constructor !== Array && (h = [h]); } h || (h = this.field); - n = !e && (this.worker || this.db) && []; - for (let E = 0, v, B, z; E < h.length; E++) { + l = !1; + for (let E = 0, t, B, y; 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)); + let z; + L(B) || (z = B, B = z.field, a = z.query || a, c = Fa(z.limit, c), w = Fa(z.offset, w), k = Fa(z.suggest, k), x = C && this.store && Fa(z.highlight, x), d = !!x || C && this.store && Fa(z.enrich, d)); if (e) { - v = e[E]; + t = e[E]; } else { - 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); + if (u = z || b, v = this.index.get(B), m && (u.enrich = !1), l) { + l[E] = v.search(a, c, u); + u && d && (u.enrich = d); continue; } else { - v = y.search(a, c, x), x && g && (x.enrich = g); + t = v.search(a, c, u), u && d && (u.enrich = d); } } - z = v && (p ? v.length : v.result.length); - if (l && z) { - x = []; - y = 0; - for (let H = 0, D, N; H < l.length; H += 2) { - D = this.tag.get(l[H]); + y = t && (C ? t.length : t.result.length); + if (m && y) { + u = []; + v = 0; + for (let H = 0, D, M; H < m.length; H += 2) { + D = this.tag.get(m[H]); if (!D) { - if (console.warn("Tag '" + l[H] + ":" + l[H + 1] + "' will be skipped because there is no field '" + l[H] + "'."), k) { + if (console.warn("Tag '" + m[H] + ":" + m[H + 1] + "' will be skipped because there is no field '" + m[H] + "'."), k) { continue; } else { - return p ? d : new X(d); + return f; } } - if (N = (D = D && D.get(l[H + 1])) && D.length) { - y++, x.push(D); + if (M = (D = D && D.get(m[H + 1])) && D.length) { + v++, u.push(D); } else if (!k) { - return p ? d : new X(d); + return f; } } - if (y) { - v = Ga(v, x); - z = v.length; - if (!z && !k) { - return p ? v : new X(v); + if (v) { + t = Ba(t, u); + y = t.length; + if (!y && !k) { + return t; } - y--; + v--; } } - if (z) { - f[m] = B, d.push(v), m++; + if (y) { + g[n] = B, f.push(t), n++; } else if (1 === h.length) { - return p ? d : new X(d); + return f; } } - if (n) { + if (l) { const E = this; - return Promise.all(n).then(function(v) { - return v.length ? E.search(a, c, b, v) : v; + return Promise.all(l).then(function(t) { + return t.length ? E.search(a, c, b, t) : t; }); } - if (!m) { - return p ? d : new X(d); + if (!n) { + return f; } - if (q && (!g || !this.store)) { - return d[0]; + if (q && (!d || !this.store)) { + return f[0]; } - n = []; - for (w = 0; w < f.length; w++) { - e = d[w]; - g && e.length && "undefined" === typeof e[0].doc && (e = U.call(this, e)); + l = []; + for (w = 0; w < g.length; w++) { + e = f[w]; + d && e.length && "undefined" === typeof e[0].doc && (e = Ga.call(this, e)); if (q) { - return p ? r ? Pa(a, e, this.index, q, r) : e : new X(e); + return x ? Da(a, e, this.index, q, x) : e; } - d[w] = {field:f[w], result:e}; + f[w] = {field:g[w], result:e}; } - return t ? Sa(d) : r ? Pa(a, d, this.index, q, r) : d; + return r ? Ha(f) : x ? Da(a, f, this.index, q, x) : f; }; -function Sa(a) { +function Fa(a, c) { + return "undefined" === typeof a ? c : a; +} +function Ha(a) { const c = [], b = J(); 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 = b[k]) ? l.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); + for (let g = 0, k, h, m; g < f.length; g++) { + h = f[g], "object" !== typeof h && (h = {id:h}), k = h.id, (m = b[k]) ? m.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); } } return c; } -function Qa(a, c, b, e, d) { +function Ea(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1282,11 +959,11 @@ function Qa(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = U.call(this, f)); + d && (f = Ga.call(this, f)); return f; } } -function U(a) { +function Ga(a) { if (!this || !this.store) { return a; } @@ -1296,16 +973,16 @@ function U(a) { } return c; } -;function T(a) { - if (!this || this.constructor !== T) { - return new T(a); +;function X(a) { + if (!this || this.constructor !== X) { + return new X(a); } const c = a.document || a.doc || a; var b; this.D = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && Ta(b, this.J) || "id"; + this.key = (b = c.key || c.id) && Ia(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(); @@ -1314,15 +991,15 @@ function U(a) { this.priority = a.priority || 4; b = new Map(); let e = c.index || c.field || c; - K(e) && (e = [e]); + L(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - 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; + f = e[d], L(f) || (g = f, f = f.field), g = P(g) ? Object.assign({}, a, g) : a, b.set(f, new Z(g, this.reg)), g.custom ? this.D[d] = g.custom : (this.D[d] = Ia(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; - K(a) && (a = [a]); + L(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] = 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)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Ia(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; @@ -1331,21 +1008,21 @@ function U(a) { if ("string" === typeof b && (b = [b]), b.length) { this.tag = new Map(); this.B = []; - this.T = []; + this.R = []; for (let d = 0, f, g; d < b.length; d++) { f = b[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - 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; + f.custom ? this.B[d] = f.custom : (this.B[d] = Ia(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.R[d] = g; this.tag.set(g, new Map()); } } } } -function Ta(a, c) { +function Ia(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1354,7 +1031,7 @@ function Ta(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -A = T.prototype; +A = X.prototype; A.append = function(a, c) { return this.add(a, c, !0); }; @@ -1362,7 +1039,7 @@ A.update = function(a, c) { return this.remove(a).add(a, c); }; A.remove = function(a) { - M(a) && (a = Q(a, this.key)); + P(a) && (a = R(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1410,11 +1087,11 @@ A.get = function(a) { return this.store.get(a) || null; }; A.set = function(a, c) { - "object" === typeof a && (c = a, a = Q(c, this.key)); + "object" === typeof a && (c = a, a = R(c, this.key)); this.store.set(a, c); return this; }; -A.searchCache = Ua; +A.searchCache = Ka; A.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; @@ -1430,23 +1107,23 @@ A.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = ya(this.reg); + f = ta(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && ua(this.tag, this.reg.size); + f = this.tag && ra(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && sa(this.store); + f = this.store && pa(this.store); c = null; break; default: return; } - return Aa.call(this, a, c, d, f, b, e); + return xa.call(this, a, c, d, f, b, e); }; A.import = function(a, c) { var b = a.split("."); @@ -1461,22 +1138,22 @@ A.import = function(a, c) { switch(b) { case "reg": this.fastupdate = !1; - this.reg = za(c, this.reg); + this.reg = wa(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 = va(c, this.tag); + this.tag = sa(c, this.tag); break; case "doc": - this.store = ta(c, this.store); + this.store = qa(c, this.store); } } }; -ka(T.prototype); -function Ua(a, c, b) { - const e = ("object" === typeof a ? "" + a.query : a).toLowerCase(); +ka(X.prototype); +function Ka(a, c, b) { + const e = (c ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let d = this.cache.get(e); if (!d) { @@ -1516,20 +1193,20 @@ 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) { +const La = {normalize:!1, numeric:!1, dedupe:!1}; +const Ma = {}; +const Na = 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 Oa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Pa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const Qa = {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 Ra = {Exact:La, Default:Ma, Normalize:Ma, LatinBalance:{mapper:Na}, LatinAdvanced:{mapper:Na, matcher:Oa, replacer:Pa}, LatinExtra:{mapper:Na, replacer:Pa.concat([/(?!^)[aeo]/g, ""]), matcher:Oa}, 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 = $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++) { + let e = c.charAt(0), d = Qa[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } -}}, CJK:{split:""}, LatinExact:Va, LatinDefault:Wa, LatinSimple:Wa}; +}}, CJK:{split:""}, LatinExact:La, LatinDefault:Ma, LatinSimple:Ma}; Z.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { @@ -1545,14 +1222,14 @@ Z.prototype.remove = function(a, c) { } } } else { - bb(this.map, a), this.depth && bb(this.ctx, a); + Sa(this.map, a), this.depth && Sa(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function bb(a, c) { +function Sa(a, c) { let b = 0; var e = "undefined" === typeof c; if (a.constructor === Array) { @@ -1573,13 +1250,13 @@ function bb(a, c) { } else { for (let d of a.entries()) { e = d[0]; - const f = bb(d[1], c); + const f = Sa(d[1], c); f ? b += f : a.delete(e); } } return b; } -;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}}}; +;const Ta = {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)) { @@ -1587,23 +1264,23 @@ Z.prototype.add = function(a, c, b, e) { } e = this.depth; c = this.encoder.encode(c, !e); - const l = c.length; - if (l) { - 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 = ""; + const m = c.length; + if (m) { + const n = J(), C = J(), x = this.resolution; + for (let q = 0; q < m; q++) { + let r = c[this.rtl ? m - 1 - q : q]; + var d = r.length; + if (d && (e || !C[r])) { + var f = this.score ? this.score(c, r, q, null, 0) : Ua(x, m, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let w = 0, n; w < d; w++) { + for (let w = 0, l; 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); + g = r.substring(w, f); + l = this.rtl ? d - 1 - w : w; + var k = this.score ? this.score(c, r, q, g, l) : Ua(x, m, q, d, l); + Va(this, C, g, k, a, b); } } break; @@ -1612,26 +1289,26 @@ Z.prototype.add = function(a, c, b, e) { case "reverse": 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(c, t, q, g, k) : db(r, l, q, d, k); - eb(this, p, g, h, a, b); + g = r[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, r, q, g, k) : Ua(x, m, q, d, k); + Va(this, C, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += t[this.rtl ? d - 1 - k : k], eb(this, p, g, f, a, b); + g += r[this.rtl ? d - 1 - k : k], Va(this, C, g, f, a, b); } break; } default: - 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); + if (Va(this, C, r, f, a, b), e && 1 < m && q < m - 1) { + for (d = J(), g = this.P, f = r, k = Math.min(e + 1, this.rtl ? q + 1 : m - q), d[f] = 1, h = 1; h < k; h++) { + if ((r = c[this.rtl ? m - 1 - q - h : q + h]) && !d[r]) { + d[r] = 1; + const w = this.score ? this.score(c, f, q, r, h - 1) : Ua(g + (m / 2 > g ? 0 : 1), m, q, k - 1, h - 1), l = this.bidirectional && r > f; + Va(this, n, l ? f : r, w, a, b, l ? r : f); } } } @@ -1643,17 +1320,20 @@ Z.prototype.add = function(a, c, b, e) { } return this; }; -function eb(a, c, b, e, d, f, g) { +function Va(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] = 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 db(a, c, b, e, d) { +function Ua(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; } ;Z.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); + if (b && b.cache) { + return b.cache = !1, c = this.searchCache(a, c, b), b.cache = !0, c; + } var e = [], d = 0; if (b) { a = b.query || a; @@ -1663,76 +1343,130 @@ function db(a, c, b, e, d) { var g = b.suggest; var k = !0; var h = b.resolution; - } else { - k = !0; } + "undefined" === typeof k && (k = !0); f = this.depth && !1 !== f; - a = this.encoder.encode(a, !f); - b = a.length; + b = this.encoder.encode(a, !f); + a = b.length; c = c || (k ? 100 : 0); - if (1 === b) { - return g = c, (c = fb(this, a[0], "")) && c.length ? Ha.call(this, c, g, d) : []; + if (1 === a) { + return g = d, (d = Wa(this, b[0], "")) && d.length ? Ca.call(this, d, c, g) : []; } - if (2 === b && f && !g) { - return g = c, (c = fb(this, a[1], a[0])) && c.length ? Ha.call(this, c, g, d) : []; + if (2 === a && f && !g) { + return g = d, (d = Wa(this, b[1], b[0])) && d.length ? Ca.call(this, d, c, g) : []; } k = J(); - let l = 0; + var m = 0; if (f) { - var m = a[0]; - l = 1; + var n = b[0]; + m = 1; } - h || 0 === h || (h = m ? this.S : this.resolution); - for (let t, w; l < b; l++) { - if ((w = a[l]) && !k[w]) { + h || 0 === h || (h = n ? this.P : this.resolution); + for (let r, w; m < a; m++) { + if ((w = b[m]) && !k[w]) { k[w] = 1; - t = fb(this, w, m); + r = Wa(this, w, n); a: { - f = t; - var p = e, r = g, q = h; - let n = []; + f = r; + var C = e, x = g, q = h; + let l = []; if (f && f.length) { if (f.length <= q) { - p.push(f); - t = void 0; + C.push(f); + r = void 0; break a; } - for (let x = 0, y; x < q; x++) { - if (y = f[x]) { - n[x] = y; + for (let u = 0, v; u < q; u++) { + if (v = f[u]) { + l[u] = v; } } - if (n.length) { - p.push(n); - t = void 0; + if (l.length) { + C.push(l); + r = void 0; break a; } } - t = r ? void 0 : n; + r = x ? void 0 : l; } - if (t) { - e = t; + if (r) { + e = r; break; } - m && (g && t && e.length || (m = w)); + n && (g && r && e.length || (n = w)); } - g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = J()); + g && n && m === a - 1 && !e.length && (h = this.resolution, n = "", m = -1, k = J()); } a: { - a = e; - e = a.length; - m = a; + b = e; + e = b.length; + n = b; if (1 < e) { - m = Ea(a, h, c, d, g); + b: { + e = g; + n = b.length; + g = []; + a = J(); + for (let r = 0, w, l, u, v; r < h; r++) { + for (m = 0; m < n; m++) { + if (u = b[m], r < u.length && (w = u[r])) { + for (f = 0; f < w.length; f++) { + if (l = w[f], (k = a[l]) ? a[l]++ : (k = 0, a[l] = 1), v = g[k] || (g[k] = []), v.push(l), c && k === n - 1 && v.length - d === c) { + n = d ? v.slice(d) : v; + break b; + } + } + } + } + } + if (b = g.length) { + if (e) { + if (1 < g.length) { + c: { + for (b = [], h = J(), e = g.length, k = e - 1; 0 <= k; k--) { + if (a = (e = g[k]) && e.length) { + for (m = 0; m < a; m++) { + if (n = e[m], !h[n]) { + if (h[n] = 1, d) { + d--; + } else { + if (b.push(n), b.length === c) { + break c; + } + } + } + } + } + } + } + } else { + b = (g = g[0]).length > c || d ? g.slice(d, c + d) : g; + } + g = b; + } else { + if (b < n) { + n = []; + break b; + } + g = g[b - 1]; + if (c || d) { + if (g.length > c || d) { + g = g.slice(d, c + d); + } + } + } + } + n = g; + } } else if (1 === e) { - g = Ha.call(null, a[0], c, d); + c = Ca.call(null, b[0], c, d); break a; } - g = m; + c = n; } - return g; + return c; }; -function fb(a, c, b) { +function Wa(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); @@ -1743,14 +1477,14 @@ function fb(a, c, b) { return new Z(a); } if (a) { - var b = K(a) ? a : a.preset; - b && (cb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, cb[b], a)); + var b = L(a) ? a : a.preset; + b && (Ta[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ta[b], a)); } else { a = {}; } b = a.context; - 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}; + const e = !0 === b ? {depth:1} : b || {}, d = L(a.encoder) ? Ra[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : "object" === typeof d ? new S(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; @@ -1762,7 +1496,7 @@ function fb(a, c, b) { this.map = new Map(); this.ctx = new Map(); this.reg = c || (this.fastupdate ? new Map() : new Set()); - this.S = e.resolution || 3; + this.P = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; @@ -1789,17 +1523,17 @@ A.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - bb(this.map); - this.depth && bb(this.ctx); + Sa(this.map); + this.depth && Sa(this.ctx); return this; }; -A.searchCache = Ua; +A.searchCache = Ka; A.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = ya(this.reg); + f = ta(this.reg); break; case 1: d = "cfg"; @@ -1807,29 +1541,29 @@ A.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = sa(this.map, this.reg.size); + f = pa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ua(this.ctx, this.reg.size); + f = ra(this.ctx, this.reg.size); break; default: return; } - return Aa.call(this, a, c, d, f, b, e); + return xa.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 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = za(c, this.reg); + this.reg = wa(c, this.reg); break; case "map": - this.map = ta(c, this.map); + this.map = qa(c, this.map); break; case "ctx": - this.ctx = va(c, this.ctx); + this.ctx = sa(c, this.ctx); } } }; @@ -1841,11 +1575,11 @@ A.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = Ba(this.map, f); + b = ya(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = Ba(g[1], f); + let k = ya(g[1], f); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; e += (e ? "," : "") + k; @@ -1856,9 +1590,9 @@ A.serialize = function(a = !0) { }; 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; +const Xa = {Index:Z, Charset:Ra, Encoder:S, Document:X, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Ya = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let Za; +(Za = Ya.define) && Za.amd ? Za([], function() { + return Xa; +}) : "object" === typeof Ya.exports ? Ya.exports = Xa : Ya.FlexSearch = Xa; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 867b628..907ebe2 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,63 +1,57 @@ /**! - * FlexSearch.js v0.8.160 (Bundle) + * FlexSearch.js v0.8.161 (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 A;function H(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 I(){return Object.create(null)}function J(a){return"string"===typeof a} -function O(a){return"object"===typeof a}function Q(a,c){if(J(c))a=a[c];else for(let b=0;a&&b"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;ba.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&&V(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&&V(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(V,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[n])continue;d[n]=1}else{if(f===n)continue;f=n}if(b)e.push(n);else if(!this.filter||("function"===typeof this.filter?this.filter(n):!this.filter.has(n))){if(this.cache&&n.length<=this.L)if(this.H){var h=this.G.get(n);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(V,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ +this.C+")$"));let x;for(;x!==n&&2this.stemmer.get(q))}if(n&&(this.mapper||this.dedupe&&1this.matcher.get(x)));if(n&&this.replacer)for(h=0;n&&hthis.O&&(this.G.clear(),this.L=this.L/1.1|0));if(n){if(n!==C)if(c){if(d[n])continue;d[n]=1}else{if(g===n)continue;g=n}e.push(n)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.F.set(a,e),this.F.size>this.O&&(this.F.clear(),this.K=this.K/1.1|0));return e};function V(a){a.H=null;a.F.clear();a.G.clear()};function ka(a){W.call(a,"add");W.call(a,"append");W.call(a,"search");W.call(a,"update");W.call(a,"remove");W.call(a,"searchCache")}let la,ma,na;function oa(){la=na=0} +function W(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]);la?na||(na=Date.now()-ma>=this.priority*this.priority*3):(la=setTimeout(oa,0),ma=Date.now());if(na){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 pa(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 qa(a,c){c||(c=new Map);for(let b=0,e;bc?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=1E&&(E=l.length+(l?1:0)),t=l.length+(l?1:0)+K.length,B+=D,ja.push(v.length),v.push({match:K})),l+=(l?" ":"")+K)}if(!p)z=u[y],l+=(l?" ":"")+z,h&&v.push({text:z});else if(h&&B>=h)break}B=ja.length*(f.length-2);if(q||r||h&&l.length-B>h)if(B=h+B-2*x,y=t-E,0u&&(u=0)),v=v.length-1){if(F>=v.length){y[p+1]= +1;F>=u.length&&(B[p+1]=1);continue}D-=x}l=v[F].text;if(G=r&&J[p])if(0G)if(y[p+1]=1,m)l=l.substring(0,G);else continue;(G-=l.length)||(G=-1);J[p]=G}else{y[p+1]=1;continue}if(D+l.length+1<=h)l=" "+l,t[p]+=l;else if(m)O=h-D-1,0=F){if(0>F){y[p]=1;B[p]=1;continue}D-=x}l=v[F].text;if(G=q&&z[p])if(0G)if(y[p]=1,m)l=l.substring(l.length- +G);else continue;(G-=l.length)||(G=-1);z[p]=G}else{y[p]=1;continue}if(D+l.length+1<=h)l+=" ",t[p]=l+t[p];else if(m)O=l.length+1-(h-D),0<=O&&O=u.length-1?va=1:Fb||e)a=a.slice(e,e+b);d&&(a=Ga.call(this,a));return a}}function Ga(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=1this.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 La={normalize:!1,numeric:!1,dedupe:!1};const Ma={};const Na=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 Oa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Pa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Qa={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 Ra={Exact:La,Default:Ma,Normalize:Ma,LatinBalance:{mapper:Na},LatinAdvanced:{mapper:Na,matcher:Oa,replacer:Pa},LatinExtra:{mapper:Na,replacer:Pa.concat([/(?!^)[aeo]/g,""]),matcher:Oa},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 Sa(this.map,a),this.depth&&Sa(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Sa(a,c){let b=0;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,f,g;dw;f--){g=r.substring(w,f);l=this.rtl?d-1-w:w;var k=this.score?this.score(c,r,q,g,l):Ua(x, +m,q,d,l);Va(this,C,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),m,q,k-1,h-1),l=this.bidirectional&&r>f;Va(this,n,l?f:r,w,a,b,l?r:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Va(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 Ua(a,c,b,e,d){return b&&1c||d?g.slice(d,c+d):g;g=b}else{if(b< +n){n=[];break b}g=g[b-1];if(c||d)if(g.length>c||d)g=g.slice(d,c+d)}n=g}else if(1===e){c=Ca.call(null,b[0],c,d);break a}c=n}return c};function Wa(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 Z(a,c){if(!this||this.constructor!==Z)return new Z(a);if(a){var b=N(a)?a:a.preset;b&&(a=Object.assign({},Ta[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=N(a.encoder)?Ra[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new S(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.P=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;Sa(this.map);this.depth&&Sa(this.ctx);return this};A.searchCache=Ka;A.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=ta(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=pa(this.map,this.reg.size);break;case 3:d="ctx";f=ra(this.ctx,this.reg.size);break;default:return}return xa.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 this.maxlength)) { + for (let m = 0, n, C; m < k.length; m++) { + if ((n = C = k[m]) && !(n.length < this.minlength || n.length > this.maxlength)) { if (c) { - if (d[m]) { + if (d[n]) { continue; } - d[m] = 1; + d[n] = 1; } else { - if (f === m) { + if (f === n) { continue; } - f = m; + f = n; } if (b) { - e.push(m); + e.push(n); } else { - if (!this.filter || ("function" === typeof this.filter ? this.filter(m) : !this.filter.has(m))) { - if (this.cache && m.length <= this.L) { + if (!this.filter || ("function" === typeof this.filter ? this.filter(n) : !this.filter.has(n))) { + if (this.cache && n.length <= this.L) { if (this.H) { - var h = this.G.get(m); + var h = this.G.get(n); if (h || "" === h) { h && e.push(h); continue; } } else { - this.H = setTimeout(R, 50, this); + this.H = setTimeout(V, 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, q => this.stemmer.get(q)); + let x; + for (; x !== n && 2 < n.length;) { + x = n, n = n.replace(this.N, q => this.stemmer.get(q)); } } - if (m && (this.mapper || this.dedupe && 1 < m.length)) { + if (n && (this.mapper || this.dedupe && 1 < n.length)) { h = ""; - 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); + for (let x = 0, q = "", r, w; x < n.length; x++) { + r = n.charAt(x), r === q && this.dedupe || ((w = this.mapper && this.mapper.get(r)) || "" === w ? w === q && this.dedupe || !(q = w) || (h += w) : h += q = r); } - m = h; + n = h; } - 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 (h = 0; m && h < this.replacer.length; h += 2) { - m = m.replace(this.replacer[h], this.replacer[h + 1]); + this.matcher && 1 < n.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), n = n.replace(this.M, x => this.matcher.get(x))); + if (n && this.replacer) { + for (h = 0; n && h < this.replacer.length; h += 2) { + n = n.replace(this.replacer[h], this.replacer[h + 1]); } } - 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 !== p) { + this.cache && C.length <= this.L && (this.G.set(C, n), this.G.size > this.O && (this.G.clear(), this.L = this.L / 1.1 | 0)); + if (n) { + if (n !== C) { if (c) { - if (d[m]) { + if (d[n]) { continue; } - d[m] = 1; + d[n] = 1; } else { - if (g === m) { + if (g === n) { continue; } - g = m; + g = n; } } - e.push(m); + e.push(n); } } } } } 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)); + this.cache && a.length <= this.K && (this.F.set(a, e), this.F.size > this.O && (this.F.clear(), this.K = this.K / 1.1 | 0)); return e; }; -function R(a) { +function V(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"); + W.call(a, "add"); + W.call(a, "append"); + W.call(a, "search"); + W.call(a, "update"); + W.call(a, "remove"); + W.call(a, "searchCache"); } -let oa, pa, qa; -function ra() { - oa = qa = 0; +let la, ma, na; +function oa() { + la = na = 0; } -function na(a) { +function W(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) { + la ? na || (na = Date.now() - ma >= this.priority * this.priority * 3) : (la = setTimeout(oa, 0), ma = Date.now()); + if (na) { const f = this; return new Promise(g => { setTimeout(function() { @@ -320,7 +314,7 @@ function na(a) { return b; }; } -;function sa(a, c = 0) { +;function pa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -329,30 +323,30 @@ function na(a) { e.length && b.push(e); return b; } -function ta(a, c) { +function qa(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 ua(a, c = 0) { +function ra(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], sa(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], pa(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function xa(a, c) { +function sa(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], ta(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], qa(e[1], d)); } return c; } -function ya(a) { +function va(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -360,28 +354,28 @@ function ya(a) { b.length && c.push(b); return c; } -function za(a, c) { +function wa(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function Aa(a, c, b, e, d, f, g = 0) { +function xa(a, c, b, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { return this.export(a, c, d, f + 1); } if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { - const l = this; + const m = this; return h.then(function() { - return Aa.call(l, a, c, b, k ? e : null, d, f, g + 1); + return xa.call(m, a, c, b, k ? e : null, d, f, g + 1); }); } - return Aa.call(this, a, c, b, k ? e : null, d, f, g + 1); + return xa.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function Ba(a, c) { +function ya(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; @@ -390,8 +384,8 @@ function Ba(a, c) { 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" === c ? '"' + k[l] + '"' : k[l]); + for (let m = 0; m < k.length; m++) { + h += (h ? "," : "") + ("string" === c ? '"' + k[m] + '"' : k[m]); } h = "[" + h + "]"; f += (f ? "," : "") + h; @@ -401,8 +395,8 @@ function Ba(a, c) { } return b; } -;T.prototype.add = function(a, c, b) { - M(a) && (c = a, a = Q(c, this.key)); +;X.prototype.add = function(a, c, b) { + P(a) && (c = a, a = R(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -415,13 +409,13 @@ function Ba(a, c) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : K(h) && (h = [h]), Ca(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), za(c, h, this.J, 0, e, a, h[0], b); } } } if (this.tag) { for (e = 0; e < this.B.length; e++) { - var f = this.B[e], g = this.T[e]; + var f = this.B[e], g = this.R[e]; d = this.tag.get(g); let k = J(); if ("function" === typeof f) { @@ -434,12 +428,12 @@ function Ba(a, c) { continue; } f.constructor === String && (f = "" + f); - f = Q(c, f); + f = R(c, f); } if (d && 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])))); + L(f) && (f = [f]); + for (let h = 0, m, n; h < f.length; h++) { + m = f[h], k[m] || (k[m] = 1, (g = d.get(m)) ? n = g : d.set(m, n = []), b && n.includes(a) || (n.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -450,23 +444,23 @@ function Ba(a, c) { let k; if (this.A) { k = J(); - for (let h = 0, l; h < this.A.length; h++) { - l = this.A[h]; - if ((b = l.I) && !b(c)) { + for (let h = 0, m; h < this.A.length; h++) { + m = this.A[h]; + if ((b = m.I) && !b(c)) { continue; } - let m; - if ("function" === typeof l) { - m = l(c); - if (!m) { + let n; + if ("function" === typeof m) { + n = m(c); + if (!n) { continue; } - l = [l.U]; - } else if (K(l) || l.constructor === String) { - k[l] = c[l]; + m = [m.S]; + } else if (L(m) || m.constructor === String) { + k[m] = c[m]; continue; } - Da(c, k, l, 0, l[0], m); + Aa(c, k, m, 0, m[0], n); } } this.store.set(a, k || c); @@ -474,21 +468,21 @@ function Ba(a, c) { } return this; }; -function Da(a, c, b, e, d, f) { +function Aa(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++) { - Da(a, c, b, e, d); + Aa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = J()), d = b[++e], Da(a, c, b, e, d); + c = c[d] || (c[d] = J()), d = b[++e], Aa(a, c, b, e, d); } } } -function Ca(a, c, b, e, d, f, g, k) { +function za(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -504,69 +498,15 @@ function Ca(a, c, b, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ca(a, c, b, e, d, f, g, k); + za(a, c, b, e, d, f, g, k); } } else { - g = c[++e], Ca(a, c, b, e, d, f, g, k); + g = c[++e], za(a, c, b, e, d, f, g, k); } } } } -;function Ea(a, c, b, e, d) { - const f = a.length; - let g = [], k, h; - 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; - } - } - } - } - } - if (a = g.length) { - if (d) { - 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 []; - } - g = g[a - 1]; - if (b || e) { - if (g.length > b || e) { - g = g.slice(e, b + e); - } - } - } - } - return g; -} -function Fa(a, c, b) { - const e = [], d = J(); - 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; l < k; l++) { - if (f = g[l], !d[f]) { - if (d[f] = 1, b) { - b--; - } else { - if (e.push(f), e.length === c) { - return e; - } - } - } - } - } - } - return e; -} -function Ga(a, c) { +;function Ba(a, c) { const b = J(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -579,310 +519,38 @@ function Ga(a, c) { } return e; } -;function Ha(a, c, b, e) { +;function Ca(a, c, b) { 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 ? U.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } - let d = []; - for (let f = 0, g, k; f < a.length; f++) { - if ((g = a[f]) && (k = g.length)) { + let e = []; + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && (g = f.length)) { if (b) { - if (b >= k) { - b -= k; + if (b >= g) { + b -= g; continue; } - b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); + b < g && (f = c ? f.slice(b, b + c) : f.slice(b), g = f.length, b = 0); } - k > c && (g = g.slice(0, c), k = c); - if (!d.length && k >= c) { - return e ? U.call(this, g) : g; + g > c && (f = f.slice(0, c), g = c); + if (!e.length && g >= c) { + return f; } - d.push(g); - c -= k; + e.push(f); + c -= g; if (!c) { break; } } } - d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? U.call(this, d) : d; + return e = 1 < e.length ? [].concat.apply([], e) : e[0]; } -;function Ia(a, c, b) { - var e = b[0]; - if (e.then) { - return Promise.all(b).then(function(m) { - return a[c].apply(a, m); - }); - } - if (e[0] && e[0].index) { - return a[c].apply(a, e); - } - e = []; - let d = [], f = 0, g = 0, k, h, l; - for (let m = 0, p; m < b.length; m++) { - if (p = b[m]) { - let r; - if (p.constructor === X) { - r = p.result; - } else if (p.constructor === Array) { - r = p; - } else { - 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; - } - } - if (r.then) { - d.push(r); - } else if (r.length) { - e[m] = r; - } else if (!l && ("and" === c || "xor" === c)) { - e = []; - break; - } - } - } - return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; -} -;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 Ja(a, c, b, e, d, f) { - if (c.length) { - const g = this; - return Promise.all(c).then(function(k) { - a = []; - for (let h = 0, l; h < k.length; h++) { - (l = k[h]).length && (a[h] = l); - } - 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 = 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; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); - } - return Ka.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 { - 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; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); - } - 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 = 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 = 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, 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 p = 0, r; p < a.length; p++) { - if (r = a[p]) { - if (l = r[h]) { - 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(t), f.length === c) { - return f; - } - } else { - const w = h + (p ? d : 0); - f[w] || (f[w] = []); - f[w].push(t); - if (++m === c) { - return f; - } - } - } - } - } - } - } - } - } - return f; -} -;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 Na(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; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); - } - return Na.call(k, a, [], b, e, d, f, g); - }); - } - if (a.length && this.result.length) { - this.result = Pa.call(this, a, b, e, f); - } else if (f) { - return this.resolve(b, e, d); - } - return f ? d ? U.call(this.index, this.result) : this.result : this; -} -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++) { - if (g = this.result[f]) { - for (let h = 0, l; h < g.length; h++) { - if (l = g[h], !a.has(l)) { - if (b) { - b--; - } else { - if (e) { - if (d.push(l), d.length === c) { - return d; - } - } else { - if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { - return d; - } - } - } - } - } - } - } - return d; -} -;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; - } - this.index = null; - this.result = a || []; - this.h = 0; -} -X.prototype.limit = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, e; b < this.result.length; b++) { - if (e = this.result[b]) { - if (e.length <= a) { - if (c[b] = e, a -= e.length, !a) { - break; - } - } else { - c[b] = e.slice(0, a); - break; - } - } - } - this.result = c; - } - return this; -}; -X.prototype.offset = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, e; b < this.result.length; b++) { - if (e = this.result[b]) { - e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0); - } - } - this.result = c; - } - return this; -}; -X.prototype.boost = function(a) { - this.h += a; - return this; -}; -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), Ha.call(d, e, a || 100, c, b)) : e; -}; -J(); -function Qa(a, c, b, e, d) { +;J(); +function Da(a, c, b, e, d) { let f, g, k; "string" === typeof d ? (f = d, d = "") : f = d.template; if (!f) { @@ -894,220 +562,220 @@ function Qa(a, c, b, e, d) { } 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"); + let h = d && d.boundary, m = !d || !1 !== d.clip, n = d && d.merge && k && g && new RegExp(k + " " + g, "g"); d = d && d.ellipsis; - var p = 0; + var C = 0; if ("object" === typeof d) { - var r = d.template; - p = r.length - 2; + var x = d.template; + C = x.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; + C && (d = x.replace("$1", d)); + x = d.length - C; + let q, r; + "object" === typeof h && (q = h.before, 0 === q && (q = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); + C = new Map(); + for (let ta = 0, T, Ga, aa; ta < c.length; ta++) { + let ba; if (e) { - da = c, ca = e; + ba = c, aa = e; } else { - var w = c[va]; - ca = w.field; - if (!ca) { + var w = c[ta]; + aa = w.field; + if (!aa) { continue; } - da = w.result; + ba = 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) { + Ga = b.get(aa); + T = Ga.encoder; + w = C.get(T); + "string" !== typeof w && (w = T.encode(a), C.set(T, w)); + for (let ia = 0; ia < ba.length; ia++) { + var l = ba[ia].doc; + if (!l) { continue; } - n = Q(n, ca); - if (!n) { + l = R(l, aa); + if (!l) { continue; } - var x = n.trim().split(/\s+/); - if (!x.length) { + var u = l.trim().split(/\s+/); + if (!u.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); + l = ""; + var v = []; + let ja = []; + var E = -1, t = -1, B = 0; + for (var y = 0; y < u.length; y++) { + var z = u[y], H = T.encode(z); 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)); + let p; + if (H && z) { + var D = z.length, M = (T.split ? z.replace(T.split, "") : z).length - H.length, K = "", Q = 0; + for (var U = 0; U < w.length; U++) { + var N = w[U]; + if (N) { + var G = N.length; + G += M; + Q && G <= Q || (N = H.indexOf(N), -1 < N && (K = (N ? z.substring(0, N) : "") + g + z.substring(N, N + G) + k + (N + G < D ? z.substring(N + G) : ""), Q = G, p = !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); + K && (h && (0 > E && (E = l.length + (l ? 1 : 0)), t = l.length + (l ? 1 : 0) + K.length, B += D, ja.push(v.length), v.push({match:K})), l += (l ? " " : "") + K); } - if (!u) { - C = x[z], n += (n ? " " : "") + C, h && y.push({text:C}); + if (!p) { + z = u[y], l += (l ? " " : "") + z, h && v.push({text:z}); } 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 : ""); + B = ja.length * (f.length - 2); + if (q || r || h && l.length - B > h) { + if (B = h + B - 2 * x, y = t - E, 0 < q && (y += q), 0 < r && (y += r), y <= B) { + u = q ? E - (0 < q ? q : 0) : E - ((B - y) / 2 | 0), v = r ? t + (0 < r ? r : 0) : u + B, m || (0 < u && " " !== l.charAt(u) && " " !== l.charAt(u - 1) && (u = l.indexOf(" ", u), 0 > u && (u = 0)), v < l.length && " " !== l.charAt(v - 1) && " " !== l.charAt(v) && (v = l.lastIndexOf(" ", v), v < t ? v = t : ++v)), l = (u ? d : "") + l.substring(u, v) + (v < l.length ? d : ""); } else { - v = []; + t = []; E = {}; B = {}; + y = {}; 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]) { + K = M = D = 0; + for (U = Q = 1;;) { + var O = void 0; + for (let p = 0, F; p < ja.length; p++) { + F = ja[p]; + if (K) { + if (M !== K) { + if (y[p + 1]) { continue; } - F += L; + F += K; if (E[F]) { - D -= r; - B[u + 1] = 1; - z[u + 1] = 1; + D -= x; + B[p + 1] = 1; + y[p + 1] = 1; continue; } - if (F >= y.length - 1) { - if (F >= y.length) { - z[u + 1] = 1; - F >= x.length && (B[u + 1] = 1); + if (F >= v.length - 1) { + if (F >= v.length) { + y[p + 1] = 1; + F >= u.length && (B[p + 1] = 1); continue; } - D -= r; + D -= x; } - n = y[F].text; - if (G = t && H[u]) { + l = v[F].text; + if (G = r && H[p]) { if (0 < G) { - if (n.length > G) { - if (z[u + 1] = 1, l) { - n = n.substring(0, G); + if (l.length > G) { + if (y[p + 1] = 1, m) { + l = l.substring(0, G); } else { continue; } } - (G -= n.length) || (G = -1); - H[u] = G; + (G -= l.length) || (G = -1); + H[p] = G; } else { - z[u + 1] = 1; + y[p + 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; + if (D + l.length + 1 <= h) { + l = " " + l, t[p] += l; + } else if (m) { + O = h - D - 1, 0 < O && (l = " " + l.substring(0, O), t[p] += l), y[p + 1] = 1; } else { - z[u + 1] = 1; + y[p + 1] = 1; continue; } } else { - if (z[u]) { + if (y[p]) { continue; } - F -= N; + F -= M; if (E[F]) { - D -= r; - z[u] = 1; - B[u] = 1; + D -= x; + y[p] = 1; + B[p] = 1; continue; } if (0 >= F) { if (0 > F) { - z[u] = 1; - B[u] = 1; + y[p] = 1; + B[p] = 1; continue; } - D -= r; + D -= x; } - n = y[F].text; - if (G = q && C[u]) { + l = v[F].text; + if (G = q && z[p]) { if (0 < G) { - if (n.length > G) { - if (z[u] = 1, l) { - n = n.substring(n.length - G); + if (l.length > G) { + if (y[p] = 1, m) { + l = l.substring(l.length - G); } else { continue; } } - (G -= n.length) || (G = -1); - C[u] = G; + (G -= l.length) || (G = -1); + z[p] = G; } else { - z[u] = 1; + y[p] = 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; + if (D + l.length + 1 <= h) { + l += " ", t[p] = l + t[p]; + } else if (m) { + O = l.length + 1 - (h - D), 0 <= O && O < l.length && (l = l.substring(O) + " ", t[p] = l + t[p]), y[p] = 1; } else { - z[u] = 1; + y[p] = 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); + l = v[F].match; + q && (z[p] = q); + r && (H[p] = r); + p && D++; + let ua; + F ? !p && x && (D += x) : (B[p] = 1, y[p] = 1); + F >= u.length - 1 ? ua = 1 : F < v.length - 1 && v[F + 1].match ? ua = 1 : x && (D += x); D -= f.length - 2; - if (!u || D + n.length <= h) { - v[u] = n; + if (!p || D + l.length <= h) { + t[p] = l; } else { - P = S = W = B[u] = 0; + O = Q = U = B[p] = 0; break; } - wa && (B[u + 1] = 1, z[u + 1] = 1); + ua && (B[p + 1] = 1, y[p + 1] = 1); } - D += n.length; - P = E[F] = 1; + D += l.length; + O = E[F] = 1; } - if (P) { - N === L ? L++ : N++; + if (O) { + M === K ? K++ : M++; } else { - N === L ? S = 0 : W = 0; - if (!S && !W) { + M === K ? Q = 0 : U = 0; + if (!Q && !U) { break; } - S ? (N++, L = N) : L++; + Q ? (M++, K = M) : K++; } } - n = ""; - for (let u = 0, F; u < v.length; u++) { - F = (u && B[u] ? " " : (u && !d ? " " : "") + d) + v[u], n += F; + l = ""; + for (let p = 0, F; p < t.length; p++) { + F = (p && B[p] ? " " : (p && !d ? " " : "") + d) + t[p], l += F; } - d && !B[v.length] && (n += d); + d && !B[t.length] && (l += d); } } - m && (n = n.replace(m, " ")); - da[la].highlight = n; + n && (l = l.replace(n, " ")); + ba[ia].highlight = l; } if (e) { break; @@ -1115,164 +783,173 @@ function Qa(a, c, b, e, d) { } 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, p = !0, r; +;X.prototype.search = function(a, c, b, e) { + b || (!c && P(a) ? (b = a, a = "") : P(c) && (b = c, c = 0)); + if (b && b.cache) { + b.cache = !1; + var d = this.searchCache(a, c, b); + b.cache = !0; + return d; + } + let f = []; + var g = []; + let k, h, m; + let n = 0, C = !0, x; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var q = b.pluck; - var t = b.merge; + var r = b.merge; h = q || b.field || (h = b.index) && (h.index ? null : h); - l = this.tag && b.tag; + m = this.tag && b.tag; k = b.suggest; - 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 = !0; + this.store && b.highlight && !C ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !C && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + x = C && this.store && b.highlight; + d = !!x || C && this.store && b.enrich; c = b.limit || c; var w = b.offset || 0; c || (c = 100); - if (l) { - l.constructor !== Array && (l = [l]); - var n = []; - for (let E = 0, v; E < l.length; E++) { - v = l[E]; - if (K(v)) { + if (m) { + m.constructor !== Array && (m = [m]); + var l = []; + for (let E = 0, t; E < m.length; E++) { + t = m[E]; + if (L(t)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (v.field && v.tag) { - var x = v.tag; - if (x.constructor === Array) { - for (var y = 0; y < x.length; y++) { - n.push(v.field, x[y]); + if (t.field && t.tag) { + var u = t.tag; + if (u.constructor === Array) { + for (var v = 0; v < u.length; v++) { + l.push(t.field, u[v]); } } else { - n.push(v.field, x); + l.push(t.field, u); } } else { - 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]); + u = Object.keys(t); + for (let B = 0, y, z; B < u.length; B++) { + if (y = u[B], z = t[y], z.constructor === Array) { + for (v = 0; v < z.length; v++) { + l.push(y, z[v]); } } else { - n.push(z, C); + l.push(y, z); } } } } - if (!n.length) { + if (!l.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = n; + m = l; if (!a) { - f = []; - 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}); + g = []; + if (l.length) { + for (q = 0; q < l.length; q += 2) { + r = Ea.call(this, l[q], l[q + 1], c, w, d), f.push({field:l[q], tag:l[q + 1], result:r}); } } - return f.length ? Promise.all(f).then(function(E) { - for (let v = 0; v < E.length; v++) { - d[v].result = E[v]; + return g.length ? Promise.all(g).then(function(E) { + for (let t = 0; t < E.length; t++) { + f[t].result = E[t]; } - return d; - }) : d; + return f; + }) : f; } } h && h.constructor !== Array && (h = [h]); } h || (h = this.field); - n = !e && (this.worker || this.db) && []; - for (let E = 0, v, B, z; E < h.length; E++) { + l = !1; + for (let E = 0, t, B, y; 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)); + let z; + L(B) || (z = B, B = z.field, a = z.query || a, c = Fa(z.limit, c), w = Fa(z.offset, w), k = Fa(z.suggest, k), x = C && this.store && Fa(z.highlight, x), d = !!x || C && this.store && Fa(z.enrich, d)); if (e) { - v = e[E]; + t = e[E]; } else { - 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); + if (u = z || b, v = this.index.get(B), m && (u.enrich = !1), l) { + l[E] = v.search(a, c, u); + u && d && (u.enrich = d); continue; } else { - v = y.search(a, c, x), x && g && (x.enrich = g); + t = v.search(a, c, u), u && d && (u.enrich = d); } } - z = v && (p ? v.length : v.result.length); - if (l && z) { - x = []; - y = 0; - for (let H = 0, D, N; H < l.length; H += 2) { - D = this.tag.get(l[H]); + y = t && (C ? t.length : t.result.length); + if (m && y) { + u = []; + v = 0; + for (let H = 0, D, M; H < m.length; H += 2) { + D = this.tag.get(m[H]); if (!D) { - if (console.warn("Tag '" + l[H] + ":" + l[H + 1] + "' will be skipped because there is no field '" + l[H] + "'."), k) { + if (console.warn("Tag '" + m[H] + ":" + m[H + 1] + "' will be skipped because there is no field '" + m[H] + "'."), k) { continue; } else { - return p ? d : new X(d); + return f; } } - if (N = (D = D && D.get(l[H + 1])) && D.length) { - y++, x.push(D); + if (M = (D = D && D.get(m[H + 1])) && D.length) { + v++, u.push(D); } else if (!k) { - return p ? d : new X(d); + return f; } } - if (y) { - v = Ga(v, x); - z = v.length; - if (!z && !k) { - return p ? v : new X(v); + if (v) { + t = Ba(t, u); + y = t.length; + if (!y && !k) { + return t; } - y--; + v--; } } - if (z) { - f[m] = B, d.push(v), m++; + if (y) { + g[n] = B, f.push(t), n++; } else if (1 === h.length) { - return p ? d : new X(d); + return f; } } - if (n) { + if (l) { const E = this; - return Promise.all(n).then(function(v) { - return v.length ? E.search(a, c, b, v) : v; + return Promise.all(l).then(function(t) { + return t.length ? E.search(a, c, b, t) : t; }); } - if (!m) { - return p ? d : new X(d); + if (!n) { + return f; } - if (q && (!g || !this.store)) { - return d[0]; + if (q && (!d || !this.store)) { + return f[0]; } - n = []; - for (w = 0; w < f.length; w++) { - e = d[w]; - g && e.length && "undefined" === typeof e[0].doc && (e = U.call(this, e)); + l = []; + for (w = 0; w < g.length; w++) { + e = f[w]; + d && e.length && "undefined" === typeof e[0].doc && (e = Ha.call(this, e)); if (q) { - return p ? r ? Qa(a, e, this.index, q, r) : e : new X(e); + return x ? Da(a, e, this.index, q, x) : e; } - d[w] = {field:f[w], result:e}; + f[w] = {field:g[w], result:e}; } - return t ? Sa(d) : r ? Qa(a, d, this.index, q, r) : d; + return r ? Ia(f) : x ? Da(a, f, this.index, q, x) : f; }; -function Sa(a) { +function Fa(a, c) { + return "undefined" === typeof a ? c : a; +} +function Ia(a) { const c = [], b = J(); 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 = b[k]) ? l.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); + for (let g = 0, k, h, m; g < f.length; g++) { + h = f[g], "object" !== typeof h && (h = {id:h}), k = h.id, (m = b[k]) ? m.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); } } return c; } -function Ra(a, c, b, e, d) { +function Ea(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1281,11 +958,11 @@ function Ra(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = U.call(this, f)); + d && (f = Ha.call(this, f)); return f; } } -function U(a) { +function Ha(a) { if (!this || !this.store) { return a; } @@ -1295,16 +972,16 @@ function U(a) { } return c; } -;function T(a) { - if (!this || this.constructor !== T) { - return new T(a); +;function X(a) { + if (!this || this.constructor !== X) { + return new X(a); } const c = a.document || a.doc || a; var b; this.D = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && Ta(b, this.J) || "id"; + this.key = (b = c.key || c.id) && Ja(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(); @@ -1313,15 +990,15 @@ function U(a) { this.priority = a.priority || 4; b = new Map(); let e = c.index || c.field || c; - K(e) && (e = [e]); + L(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - 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; + f = e[d], L(f) || (g = f, f = f.field), g = P(g) ? Object.assign({}, a, g) : a, b.set(f, new Z(g, this.reg)), g.custom ? this.D[d] = g.custom : (this.D[d] = Ja(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; - K(a) && (a = [a]); + L(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] = 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)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Ja(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; @@ -1330,21 +1007,21 @@ function U(a) { if ("string" === typeof b && (b = [b]), b.length) { this.tag = new Map(); this.B = []; - this.T = []; + this.R = []; for (let d = 0, f, g; d < b.length; d++) { f = b[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - 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; + f.custom ? this.B[d] = f.custom : (this.B[d] = Ja(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.R[d] = g; this.tag.set(g, new Map()); } } } } -function Ta(a, c) { +function Ja(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1353,7 +1030,7 @@ function Ta(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -A = T.prototype; +A = X.prototype; A.append = function(a, c) { return this.add(a, c, !0); }; @@ -1361,7 +1038,7 @@ A.update = function(a, c) { return this.remove(a).add(a, c); }; A.remove = function(a) { - M(a) && (a = Q(a, this.key)); + P(a) && (a = R(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1409,11 +1086,11 @@ A.get = function(a) { return this.store.get(a) || null; }; A.set = function(a, c) { - "object" === typeof a && (c = a, a = Q(c, this.key)); + "object" === typeof a && (c = a, a = R(c, this.key)); this.store.set(a, c); return this; }; -A.searchCache = Ua; +A.searchCache = Ka; A.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; @@ -1429,23 +1106,23 @@ A.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = ya(this.reg); + f = va(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && ua(this.tag, this.reg.size); + f = this.tag && ra(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && sa(this.store); + f = this.store && pa(this.store); c = null; break; default: return; } - return Aa.call(this, a, c, d, f, b, e); + return xa.call(this, a, c, d, f, b, e); }; A.import = function(a, c) { var b = a.split("."); @@ -1460,22 +1137,22 @@ A.import = function(a, c) { switch(b) { case "reg": this.fastupdate = !1; - this.reg = za(c, this.reg); + this.reg = wa(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 = xa(c, this.tag); + this.tag = sa(c, this.tag); break; case "doc": - this.store = ta(c, this.store); + this.store = qa(c, this.store); } } }; -ka(T.prototype); -function Ua(a, c, b) { - const e = ("object" === typeof a ? "" + a.query : a).toLowerCase(); +ka(X.prototype); +function Ka(a, c, b) { + const e = (c ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let d = this.cache.get(e); if (!d) { @@ -1515,20 +1192,20 @@ 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) { +const La = {normalize:!1, numeric:!1, dedupe:!1}; +const Ma = {}; +const Na = 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 Oa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Pa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const Qa = {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 Ra = {Exact:La, Default:Ma, Normalize:Ma, LatinBalance:{mapper:Na}, LatinAdvanced:{mapper:Na, matcher:Oa, replacer:Pa}, LatinExtra:{mapper:Na, replacer:Pa.concat([/(?!^)[aeo]/g, ""]), matcher:Oa}, 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 = $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++) { + let e = c.charAt(0), d = Qa[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } -}}, CJK:{split:""}, LatinExact:Va, LatinDefault:Wa, LatinSimple:Wa}; +}}, CJK:{split:""}, LatinExact:La, LatinDefault:Ma, LatinSimple:Ma}; Z.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { @@ -1544,14 +1221,14 @@ Z.prototype.remove = function(a, c) { } } } else { - bb(this.map, a), this.depth && bb(this.ctx, a); + Sa(this.map, a), this.depth && Sa(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function bb(a, c) { +function Sa(a, c) { let b = 0; var e = "undefined" === typeof c; if (a.constructor === Array) { @@ -1572,13 +1249,13 @@ function bb(a, c) { } else { for (let d of a.entries()) { e = d[0]; - const f = bb(d[1], c); + const f = Sa(d[1], c); f ? b += f : a.delete(e); } } return b; } -;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}}}; +;const Ta = {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)) { @@ -1586,23 +1263,23 @@ Z.prototype.add = function(a, c, b, e) { } e = this.depth; c = this.encoder.encode(c, !e); - const l = c.length; - if (l) { - 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 = ""; + const m = c.length; + if (m) { + const n = J(), C = J(), x = this.resolution; + for (let q = 0; q < m; q++) { + let r = c[this.rtl ? m - 1 - q : q]; + var d = r.length; + if (d && (e || !C[r])) { + var f = this.score ? this.score(c, r, q, null, 0) : Ua(x, m, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let w = 0, n; w < d; w++) { + for (let w = 0, l; 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); + g = r.substring(w, f); + l = this.rtl ? d - 1 - w : w; + var k = this.score ? this.score(c, r, q, g, l) : Ua(x, m, q, d, l); + Va(this, C, g, k, a, b); } } break; @@ -1611,26 +1288,26 @@ Z.prototype.add = function(a, c, b, e) { case "reverse": 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(c, t, q, g, k) : db(r, l, q, d, k); - eb(this, p, g, h, a, b); + g = r[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, r, q, g, k) : Ua(x, m, q, d, k); + Va(this, C, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += t[this.rtl ? d - 1 - k : k], eb(this, p, g, f, a, b); + g += r[this.rtl ? d - 1 - k : k], Va(this, C, g, f, a, b); } break; } default: - 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); + if (Va(this, C, r, f, a, b), e && 1 < m && q < m - 1) { + for (d = J(), g = this.P, f = r, k = Math.min(e + 1, this.rtl ? q + 1 : m - q), d[f] = 1, h = 1; h < k; h++) { + if ((r = c[this.rtl ? m - 1 - q - h : q + h]) && !d[r]) { + d[r] = 1; + const w = this.score ? this.score(c, f, q, r, h - 1) : Ua(g + (m / 2 > g ? 0 : 1), m, q, k - 1, h - 1), l = this.bidirectional && r > f; + Va(this, n, l ? f : r, w, a, b, l ? r : f); } } } @@ -1642,17 +1319,20 @@ Z.prototype.add = function(a, c, b, e) { } return this; }; -function eb(a, c, b, e, d, f, g) { +function Va(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] = 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 db(a, c, b, e, d) { +function Ua(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; } ;Z.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); + if (b && b.cache) { + return b.cache = !1, c = this.searchCache(a, c, b), b.cache = !0, c; + } var e = [], d = 0; if (b) { a = b.query || a; @@ -1662,76 +1342,130 @@ function db(a, c, b, e, d) { var g = b.suggest; var k = !0; var h = b.resolution; - } else { - k = !0; } + "undefined" === typeof k && (k = !0); f = this.depth && !1 !== f; - a = this.encoder.encode(a, !f); - b = a.length; + b = this.encoder.encode(a, !f); + a = b.length; c = c || (k ? 100 : 0); - if (1 === b) { - return g = c, (c = fb(this, a[0], "")) && c.length ? Ha.call(this, c, g, d) : []; + if (1 === a) { + return g = d, (d = Wa(this, b[0], "")) && d.length ? Ca.call(this, d, c, g) : []; } - if (2 === b && f && !g) { - return g = c, (c = fb(this, a[1], a[0])) && c.length ? Ha.call(this, c, g, d) : []; + if (2 === a && f && !g) { + return g = d, (d = Wa(this, b[1], b[0])) && d.length ? Ca.call(this, d, c, g) : []; } k = J(); - let l = 0; + var m = 0; if (f) { - var m = a[0]; - l = 1; + var n = b[0]; + m = 1; } - h || 0 === h || (h = m ? this.S : this.resolution); - for (let t, w; l < b; l++) { - if ((w = a[l]) && !k[w]) { + h || 0 === h || (h = n ? this.P : this.resolution); + for (let r, w; m < a; m++) { + if ((w = b[m]) && !k[w]) { k[w] = 1; - t = fb(this, w, m); + r = Wa(this, w, n); a: { - f = t; - var p = e, r = g, q = h; - let n = []; + f = r; + var C = e, x = g, q = h; + let l = []; if (f && f.length) { if (f.length <= q) { - p.push(f); - t = void 0; + C.push(f); + r = void 0; break a; } - for (let x = 0, y; x < q; x++) { - if (y = f[x]) { - n[x] = y; + for (let u = 0, v; u < q; u++) { + if (v = f[u]) { + l[u] = v; } } - if (n.length) { - p.push(n); - t = void 0; + if (l.length) { + C.push(l); + r = void 0; break a; } } - t = r ? void 0 : n; + r = x ? void 0 : l; } - if (t) { - e = t; + if (r) { + e = r; break; } - m && (g && t && e.length || (m = w)); + n && (g && r && e.length || (n = w)); } - g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = J()); + g && n && m === a - 1 && !e.length && (h = this.resolution, n = "", m = -1, k = J()); } a: { - a = e; - e = a.length; - m = a; + b = e; + e = b.length; + n = b; if (1 < e) { - m = Ea(a, h, c, d, g); + b: { + e = g; + n = b.length; + g = []; + a = J(); + for (let r = 0, w, l, u, v; r < h; r++) { + for (m = 0; m < n; m++) { + if (u = b[m], r < u.length && (w = u[r])) { + for (f = 0; f < w.length; f++) { + if (l = w[f], (k = a[l]) ? a[l]++ : (k = 0, a[l] = 1), v = g[k] || (g[k] = []), v.push(l), c && k === n - 1 && v.length - d === c) { + n = d ? v.slice(d) : v; + break b; + } + } + } + } + } + if (b = g.length) { + if (e) { + if (1 < g.length) { + c: { + for (b = [], h = J(), e = g.length, k = e - 1; 0 <= k; k--) { + if (a = (e = g[k]) && e.length) { + for (m = 0; m < a; m++) { + if (n = e[m], !h[n]) { + if (h[n] = 1, d) { + d--; + } else { + if (b.push(n), b.length === c) { + break c; + } + } + } + } + } + } + } + } else { + b = (g = g[0]).length > c || d ? g.slice(d, c + d) : g; + } + g = b; + } else { + if (b < n) { + n = []; + break b; + } + g = g[b - 1]; + if (c || d) { + if (g.length > c || d) { + g = g.slice(d, c + d); + } + } + } + } + n = g; + } } else if (1 === e) { - g = Ha.call(null, a[0], c, d); + c = Ca.call(null, b[0], c, d); break a; } - g = m; + c = n; } - return g; + return c; }; -function fb(a, c, b) { +function Wa(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); @@ -1742,14 +1476,14 @@ function fb(a, c, b) { return new Z(a); } if (a) { - var b = K(a) ? a : a.preset; - b && (cb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, cb[b], a)); + var b = L(a) ? a : a.preset; + b && (Ta[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ta[b], a)); } else { a = {}; } b = a.context; - 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}; + const e = !0 === b ? {depth:1} : b || {}, d = L(a.encoder) ? Ra[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : "object" === typeof d ? new S(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; @@ -1761,7 +1495,7 @@ function fb(a, c, b) { this.map = new Map(); this.ctx = new Map(); this.reg = c || (this.fastupdate ? new Map() : new Set()); - this.S = e.resolution || 3; + this.P = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; @@ -1788,17 +1522,17 @@ A.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - bb(this.map); - this.depth && bb(this.ctx); + Sa(this.map); + this.depth && Sa(this.ctx); return this; }; -A.searchCache = Ua; +A.searchCache = Ka; A.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = ya(this.reg); + f = va(this.reg); break; case 1: d = "cfg"; @@ -1806,29 +1540,29 @@ A.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = sa(this.map, this.reg.size); + f = pa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ua(this.ctx, this.reg.size); + f = ra(this.ctx, this.reg.size); break; default: return; } - return Aa.call(this, a, c, d, f, b, e); + return xa.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 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = za(c, this.reg); + this.reg = wa(c, this.reg); break; case "map": - this.map = ta(c, this.map); + this.map = qa(c, this.map); break; case "ctx": - this.ctx = xa(c, this.ctx); + this.ctx = sa(c, this.ctx); } } }; @@ -1840,11 +1574,11 @@ A.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = Ba(this.map, f); + b = ya(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = Ba(g[1], f); + let k = ya(g[1], f); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; e += (e ? "," : "") + k; @@ -1855,6 +1589,6 @@ A.serialize = function(a = !0) { }; ka(Z.prototype); J(); -export default {Index:Z, Charset:ab, Encoder:ja, Document:T, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:Z, Charset:Ra, Encoder:S, Document:X, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -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 +export const Index=Z;export const Charset=Ra;export const Encoder=S;export const Document=X;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 4bf583c..0469f24 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,64 +1,58 @@ /**! - * FlexSearch.js v0.8.160 (Bundle) + * FlexSearch.js v0.8.161 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var A;function H(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 I(){return Object.create(null)}function J(a){return"string"===typeof a} -function O(a){return"object"===typeof a}function Q(a,c){if(J(c))a=a[c];else for(let b=0;a&&b"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;ba.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&&V(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&&V(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(V,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[n])continue;d[n]=1}else{if(f===n)continue;f=n}if(b)e.push(n);else if(!this.filter||("function"===typeof this.filter?this.filter(n):!this.filter.has(n))){if(this.cache&&n.length<=this.L)if(this.H){var h=this.G.get(n);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(V,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ +this.C+")$"));let x;for(;x!==n&&2this.stemmer.get(q))}if(n&&(this.mapper||this.dedupe&&1this.matcher.get(x)));if(n&&this.replacer)for(h=0;n&&hthis.O&&(this.G.clear(),this.L=this.L/1.1|0));if(n){if(n!==C)if(c){if(d[n])continue;d[n]=1}else{if(g===n)continue;g=n}e.push(n)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.F.set(a,e),this.F.size>this.O&&(this.F.clear(),this.K=this.K/1.1|0));return e};function V(a){a.H=null;a.F.clear();a.G.clear()};function ka(a){W.call(a,"add");W.call(a,"append");W.call(a,"search");W.call(a,"update");W.call(a,"remove");W.call(a,"searchCache")}let la,ma,na;function oa(){la=na=0} +function W(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]);la?na||(na=Date.now()-ma>=this.priority*this.priority*3):(la=setTimeout(oa,0),ma=Date.now());if(na){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 pa(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 qa(a,c){c||(c=new Map);for(let b=0,e;bc?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=1E&&(E=l.length+(l?1:0)),t=l.length+(l?1:0)+K.length,B+=D,ja.push(v.length),v.push({match:K})),l+=(l?" ":"")+K)}if(!p)z=u[y],l+=(l?" ":"")+z,h&&v.push({text:z});else if(h&&B>=h)break}B=ja.length*(f.length-2);if(q||r||h&&l.length-B>h)if(B=h+B-2*x,y=t-E,0u&&(u=0)),v=v.length-1){if(F>=v.length){y[p+1]= +1;F>=u.length&&(B[p+1]=1);continue}D-=x}l=v[F].text;if(G=r&&J[p])if(0G)if(y[p+1]=1,m)l=l.substring(0,G);else continue;(G-=l.length)||(G=-1);J[p]=G}else{y[p+1]=1;continue}if(D+l.length+1<=h)l=" "+l,t[p]+=l;else if(m)O=h-D-1,0=F){if(0>F){y[p]=1;B[p]=1;continue}D-=x}l=v[F].text;if(G=q&&z[p])if(0G)if(y[p]=1,m)l=l.substring(l.length- +G);else continue;(G-=l.length)||(G=-1);z[p]=G}else{y[p]=1;continue}if(D+l.length+1<=h)l+=" ",t[p]=l+t[p];else if(m)O=l.length+1-(h-D),0<=O&&O=u.length-1?ua=1:Fb||e)a=a.slice(e,e+b);d&&(a=Ha.call(this,a));return a}}function Ha(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=1this.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 La={normalize:!1,numeric:!1,dedupe:!1};const Ma={};const Na=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 Oa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Pa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Qa={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 Ra={Exact:La,Default:Ma,Normalize:Ma,LatinBalance:{mapper:Na},LatinAdvanced:{mapper:Na,matcher:Oa,replacer:Pa},LatinExtra:{mapper:Na,replacer:Pa.concat([/(?!^)[aeo]/g,""]),matcher:Oa},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 Sa(this.map,a),this.depth&&Sa(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Sa(a,c){let b=0;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,f,g;dw;f--){g=r.substring(w,f);l=this.rtl?d-1-w:w;var k=this.score?this.score(c,r,q,g,l):Ua(x, +m,q,d,l);Va(this,C,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),m,q,k-1,h-1),l=this.bidirectional&&r>f;Va(this,n,l?f:r,w,a,b,l?r:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Va(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 Ua(a,c,b,e,d){return b&&1c||d?g.slice(d,c+d):g;g=b}else{if(b< +n){n=[];break b}g=g[b-1];if(c||d)if(g.length>c||d)g=g.slice(d,c+d)}n=g}else if(1===e){c=Ca.call(null,b[0],c,d);break a}c=n}return c};function Wa(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 Z(a,c){if(!this||this.constructor!==Z)return new Z(a);if(a){var b=N(a)?a:a.preset;b&&(a=Object.assign({},Ta[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=N(a.encoder)?Ra[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new S(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.P=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;Sa(this.map);this.depth&&Sa(this.ctx);return this};A.searchCache=Ka;A.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=va(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=pa(this.map,this.reg.size);break;case 3:d="ctx";f=ra(this.ctx,this.reg.size);break;default:return}return xa.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 this.maxlength)) { + for (var d = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), e = [], f = Q(), g, k, h = this.split || "" === this.split ? a.split(this.split) : [a], l = 0, m = void 0, p = void 0; l < h.length; l++) { + if ((m = p = h[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (b) { if (f[m]) { continue; @@ -1119,10 +1119,10 @@ v.encode = function(a, b) { } f[m] = 1; } else { - if (h === m) { + if (k === m) { continue; } - h = m; + k = m; } } e.push(m); @@ -1143,8 +1143,8 @@ function Ma(a) { ;var Na, Oa; function Pa(a) { var b, c, d, e, f, g; - return xa(function(h) { - switch(h.h) { + return xa(function(k) { + switch(k.h) { case 1: a = a.data; b = a.task; @@ -1157,9 +1157,9 @@ function Pa(a) { postMessage({id:c}); break; default: - h.h = 2; + k.h = 2; return; - }h.h = 0; + }k.h = 0; break; case 2: if ("export" === b) { @@ -1173,25 +1173,25 @@ function Pa(a) { 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; + k.h = 5; break; } - return L(h, Oa.import.call(Na, d[0]), 9); + return L(k, Oa.import.call(Na, d[0]), 9); } f = d && Na[b].apply(Na, d); if (!f || !f.then) { - h.h = 5; + k.h = 5; break; } - return L(h, f, 7); + return L(k, f, 7); case 7: - f = h.D; - h.h = 5; + f = k.D; + k.h = 5; break; case 9: - g = h.D, Na.import(d[0], g); + g = k.D, Na.import(d[0], g); case 5: - postMessage("search" === b ? {id:c, msg:f} : {id:c}), h.h = 0; + postMessage("search" === b ? {id:c, msg:f} : {id:c}), k.h = 0; } }); } @@ -1201,6 +1201,7 @@ function Pa(a) { Ra.call(a, "search"); Ra.call(a, "update"); Ra.call(a, "remove"); + Ra.call(a, "searchCache"); } var Sa, Ta, Ua; function Va() { @@ -1233,19 +1234,19 @@ function Ra(a) { ;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]); + function k(h) { + h = h.data || h; + var l = h.id, m = l && e.h[l]; + m && (m(h.msg), delete e.h[l]); } this.worker = g; this.h = Q(); if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; + d ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { + return new Promise(function(h) { e.h[++Wa] = function() { - k(e); + h(e); 1e9 < Wa && (Wa = 0); }; e.worker.postMessage({id:Wa, task:"init", factory:c, options:a}); @@ -1349,17 +1350,17 @@ function eb(a, b) { } 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) { + var k = d && d.constructor === Array, h = k ? d.shift() : d; + if (!h) { return this.export(a, b, e, 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) { var l = this; - return k.then(function() { - return fb.call(l, a, b, c, h ? d : null, e, f, g + 1); + return h.then(function() { + return fb.call(l, a, b, c, k ? d : null, e, f, g + 1); }); } - return fb.call(this, a, b, c, h ? d : null, e, f, g + 1); + return fb.call(this, a, b, c, k ? d : null, e, f, g + 1); } function gb(a, b) { var c = ""; @@ -1368,13 +1369,13 @@ function gb(a, b) { var e = d.value; d = e[0]; e = e[1]; - for (var f = "", g = 0, h; g < e.length; g++) { - h = e[g] || [""]; - for (var k = "", l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === b ? '"' + h[l] + '"' : h[l]); + for (var f = "", g = 0, k; g < e.length; g++) { + k = e[g] || [""]; + for (var h = "", 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 = '["' + d + '",[' + f + "]]"; c += (c ? "," : "") + f; @@ -1423,13 +1424,13 @@ function ib(a) { } if ("indexOf" === d) { return function(e) { - for (var f = 0, g = 0, h, k; g < b.index.length; g++) { - h = b.index[g]; - k = h.indexOf(e); - if (0 <= k) { - return f + k; + for (var f = 0, g = 0, k, h; g < b.index.length; g++) { + k = b.index[g]; + h = k.indexOf(e); + if (0 <= h) { + return f + h; } - f += h.length; + f += k.length; } return -1; }; @@ -1633,45 +1634,45 @@ function jb() { if (this.tag) { for (d = 0; d < this.K.length; d++) { g = this.K[d]; - var h = this.aa[d]; - f = this.tag.get(h); + var k = this.aa[d]; + f = this.tag.get(k); e = Q(); if ("function" === typeof g) { if (g = g(b), !g) { continue; } } else { - var k = g.R; - if (k && !k(b)) { + var h = g.R; + if (h && !h(b)) { continue; } g.constructor === String && (g = "" + g); g = Ea(b, g); } if (f && g) { - for (R(g) && (g = [g]), h = 0, k = void 0; h < g.length; h++) { - var l = g[h]; + for (R(g) && (g = [g]), k = 0, h = void 0; k < g.length; k++) { + var l = g[k]; if (!e[l]) { e[l] = 1; var m; - (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 ib(k); + (m = f.get(l)) ? h = m : f.set(l, h = []); + if (!c || !h.includes(a)) { + if (h.length === Math.pow(2, 31) - 1) { + m = new ib(h); if (this.fastupdate) { 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); + n = n.value, n.includes(h) && (n[n.indexOf(h)] = m); } } - f.set(l, k = m); + f.set(l, h = m); } - k.push(a); - this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); + h.push(a); + this.fastupdate && ((l = this.reg.get(a)) ? l.push(h) : this.reg.set(a, [h])); } } } } else { - f || console.warn("Tag '" + h + "' was not found"); + f || console.warn("Tag '" + k + "' was not found"); } } } @@ -1715,7 +1716,7 @@ function qb(a, b, c, d, e, f) { } } } -function pb(a, b, c, d, e, f, g, h) { +function pb(a, b, c, d, e, f, g, k) { if (a = a[g]) { if (d === b.length - 1) { if (a.constructor === Array) { @@ -1727,14 +1728,14 @@ function pb(a, b, c, d, e, f, g, h) { } a = a.join(" "); } - e.add(f, a, h, !0); + e.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - pb(a, b, c, d, e, f, g, h); + pb(a, b, c, d, e, f, g, k); } } else { - g = b[++d], pb(a, b, c, d, e, f, g, h); + g = b[++d], pb(a, b, c, d, e, f, g, k); } } } else { @@ -1742,45 +1743,45 @@ function pb(a, b, c, d, e, f, g, h) { } } ;function rb(a, b, c, d, e, f, g) { - var h = a.length, k = []; + var k = a.length, h = []; var l = Q(); for (var m = 0, p = void 0, n, q; m < b; m++) { - for (var r = 0; r < h; r++) { + for (var r = 0; r < k; 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] = []); + q = h[w] || (h[w] = []); if (!g) { var B = m + (r || !e ? 0 : f || 0); q = q[B] || (q[B] = []); } q.push(n); - if (g && c && w === h - 1 && q.length - d === c) { + if (g && c && w === k - 1 && q.length - d === c) { return d ? q.slice(d) : q; } } } } } - if (a = k.length) { + if (a = h.length) { if (e) { - k = 1 < k.length ? sb(k, c, d, g, f) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + h = 1 < h.length ? sb(h, c, d, g, f) : (h = h[0]).length > c || d ? h.slice(d, c + d) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; + h = h[a - 1]; if (c || d) { if (g) { - if (k.length > c || d) { - k = k.slice(d, c + d); + if (h.length > c || d) { + h = h.slice(d, c + d); } } else { e = []; - for (f = 0; f < k.length; f++) { - if (g = k[f], g.length > d) { + for (f = 0; f < h.length; f++) { + if (g = h[f], g.length > d) { d -= g.length; } else { if (g.length > c || d) { @@ -1792,20 +1793,20 @@ function pb(a, b, c, d, e, f, g, h) { } } } - k = 1 < e.length ? [].concat.apply([], e) : e[0]; + h = 1 < e.length ? [].concat.apply([], e) : e[0]; } } } } - return k; + return h; } function sb(a, b, c, d, e) { - var f = [], g = Q(), h = a.length, k; + var f = [], g = Q(), k = a.length, h; if (d) { - for (e = h - 1; 0 <= e; e--) { - if (k = (d = a[e]) && d.length) { - for (h = 0; h < k; h++) { - var l = d[h]; + for (e = k - 1; 0 <= e; e--) { + if (h = (d = a[e]) && d.length) { + for (k = 0; k < h; k++) { + var l = d[k]; if (!g[l]) { if (g[l] = 1, c) { c--; @@ -1819,16 +1820,16 @@ function sb(a, b, c, d, e) { } } } else { - for (var m = h - 1, p, n = 0; 0 <= m; m--) { + for (var m = k - 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 (h = (d = p[q]) && d.length) { + for (var r = 0; r < h; r++) { if (l = d[r], !g[l]) { if (g[l] = 1, c) { c--; } else { - var w = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; + var w = (q + (m < k - 1 ? e || 0 : 0)) / (m + 1) | 0; (f[w] || (f[w] = [])).push(l); if (++n === b) { return f; @@ -1845,8 +1846,8 @@ function sb(a, b, c, d, e) { 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; + for (var k = 0; k < g.length; k++) { + d[g[k]] = 1; } } if (c) { @@ -1869,21 +1870,21 @@ function tb(a, b, c) { if (1 === a.length) { 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)) { + for (var e = [], f = 0, g = void 0, k = void 0; 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) { + k > b && (g = g.slice(0, b), k = b); + if (!e.length && k >= b) { return d ? vb.call(this, g) : g; } e.push(g); - b -= h; + b -= k; if (!b) { break; } @@ -1903,7 +1904,7 @@ function tb(a, b, c) { return a[b].apply(a, d); } d = []; - for (var e = [], f = 0, g = 0, h, k, l, m = 0, p = void 0; m < c.length; m++) { + for (var e = [], f = 0, g = 0, k, h, l, m = 0, p = void 0; m < c.length; m++) { if (p = c[m]) { var n = void 0; if (p.constructor === X) { @@ -1911,8 +1912,8 @@ function tb(a, b, c) { } else if (p.constructor === Array) { n = p; } else { - 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; + 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, n = p.index.search(p).result, p.resolve = h, p.enrich = k; } else if (p.and) { n = a.and(p.and); } else if (p.or) { @@ -1935,7 +1936,7 @@ function tb(a, b, c) { } } } - return {W:d, $:e, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {W:d, $:e, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;X.prototype.or = function() { var a = wb(this, "or", arguments); @@ -1944,10 +1945,10 @@ function tb(a, b, c) { function xb(a, b, c, d, e, f) { if (b.length) { var g = this; - return Promise.all(b).then(function(h) { + return Promise.all(b).then(function(k) { a = []; - for (var k = 0, l = void 0; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); + for (var h = 0, l = void 0; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } return xb.call(g, a, [], c, d, e, f); }); @@ -1971,13 +1972,13 @@ function xb(a, b, c, d, e, f) { }; function yb(a, b, c, d, e, f, g) { if (b.length) { - var h = this; - return Promise.all(b).then(function(k) { + var k = this; + return Promise.all(b).then(function(h) { a = []; - for (var l = 0, m = void 0; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return yb.call(h, a, [], c, d, e, f, g); + return yb.call(k, a, [], c, d, e, f, g); }); } if (a.length) { @@ -2000,13 +2001,13 @@ function yb(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) { + var k = this; + return Promise.all(b).then(function(h) { a = []; - for (var l = 0, m = void 0; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return zb.call(h, a, [], c, d, e, f, g); + return zb.call(k, a, [], c, d, e, f, g); }); } if (a.length) { @@ -2021,9 +2022,9 @@ function zb(a, b, c, d, e, f, g) { 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; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); + for (var f = [], g = Q(), k = 0, h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); for (var m = 0, p; m < l.length; m++) { if (p = l[m]) { for (var n = 0, q; n < p.length; n++) { @@ -2033,10 +2034,10 @@ function Ab(a, b, c, d, e) { } } } - for (l = k = 0; k < h; k++) { + for (l = h = 0; h < k; h++) { for (m = 0; m < a.length; m++) { if (p = a[m]) { - if (p = p[k]) { + if (p = p[h]) { for (n = 0; n < p.length; n++) { if (q = p[n], 1 === g[q]) { if (c) { @@ -2047,7 +2048,7 @@ function Ab(a, b, c, d, e) { return f; } } else { - var r = k + (m ? e : 0); + var r = h + (m ? e : 0); f[r] || (f[r] = []); f[r].push(q); if (++l === b) { @@ -2069,13 +2070,13 @@ function Ab(a, b, c, d, e) { }; function Bb(a, b, c, d, e, f, g) { if (b.length) { - var h = this; - return Promise.all(b).then(function(k) { + var k = this; + return Promise.all(b).then(function(h) { a = []; - for (var l = 0, m = void 0; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Bb.call(h, a, [], c, d, e, f, g); + return Bb.call(k, a, [], c, d, e, f, g); }); } if (a.length && this.result.length) { @@ -2088,10 +2089,10 @@ function Bb(a, b, c, d, e, f, g) { 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++) { + for (var f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (var k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (var h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (c) { c--; } else { @@ -2100,7 +2101,7 @@ function Cb(a, b, c, d) { return e; } } else { - if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { + if (e[f] || (e[f] = []), e[f].push(l), ++k === b) { return e; } } @@ -2175,9 +2176,9 @@ function Db(a, b, c, d, e) { if (-1 === g) { throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); } - var h = f.substring(g + 2); + var k = 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"); + var h = e && e.boundary, l = !e || !1 !== e.clip, m = e && e.merge && k && g && new RegExp(k + " " + g, "g"); e = e && e.ellipsis; var p = 0; if ("object" === typeof e) { @@ -2188,12 +2189,12 @@ function Db(a, b, c, d, e) { "string" !== typeof e && (e = !1 === e ? "" : "..."); p && (e = n.replace("$1", e)); n = e.length - p; - if ("object" === typeof k) { - var q = k.before; + if ("object" === typeof h) { + var q = h.before; 0 === q && (q = -1); - var r = k.after; + var r = h.after; 0 === r && (r = -1); - k = k.total || 9e5; + h = h.total || 9e5; } p = new Map(); for (var w, u = 0, B, D; u < b.length; u++) { @@ -2228,20 +2229,20 @@ function Db(a, b, c, d, e) { 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)); + ma && K <= ma || (H = M.indexOf(H), -1 < H && (aa = (H ? J.substring(0, H) : "") + g + J.substring(H, H + K) + k + (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); + aa && (h && (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) { + J = E[F], t += (t ? " " : "") + J, h && C.push({text:J}); + } else if (h && S >= h) { 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) { + if (q || r || h && t.length - S > h) { + if (S = h + 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 = []; @@ -2293,10 +2294,10 @@ function Db(a, b, c, d, e) { continue; } } - if (P + t.length + 1 <= k) { + if (P + t.length + 1 <= h) { 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; + H = h - P - 1, 0 < H && (t = " " + t.substring(0, H), N[y] += t), F[y + 1] = 1; } else { F[y + 1] = 1; continue; @@ -2337,10 +2338,10 @@ function Db(a, b, c, d, e) { continue; } } - if (P + t.length + 1 <= k) { + if (P + t.length + 1 <= h) { 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; + H = t.length + 1 - (h - P), 0 <= H && H < t.length && (t = t.substring(H) + " ", N[y] = t + N[y]), F[y] = 1; } else { F[y] = 1; continue; @@ -2355,7 +2356,7 @@ function Db(a, b, c, d, e) { 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) { + if (!y || P + t.length <= h) { N[y] = t; } else { H = aa = ma = G[y] = 0; @@ -2396,7 +2397,13 @@ function Db(a, b, c, d, e) { } ;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.cache) { + c.cache = !1; + var e = this.searchCache(a, b, c); + c.cache = !0; + return e; + } + var f = [], g = [], k = 0, h = !0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; @@ -2414,8 +2421,9 @@ function Db(a, b, c, d, e) { 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; + this.store && c.highlight && !h ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : 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 = h && this.store && c.highlight; + e = !!r || h && this.store && c.enrich; b = c.limit || b; var w = c.offset || 0; b || (b = 100); @@ -2456,38 +2464,38 @@ function Db(a, b, c, d, e) { if (!a) { h = []; if (u.length) { - for (f = 0; f < u.length; f += 2) { + for (g = 0; g < u.length; g += 2) { q = void 0; if (this.db) { - q = this.index.get(u[f]); + q = this.index.get(u[g]); if (!q) { - console.warn("Tag '" + u[f] + ":" + u[f + 1] + "' will be skipped because there is no field '" + u[f] + "'."); + console.warn("Tag '" + u[g] + ":" + u[g + 1] + "' will be skipped because there is no field '" + u[g] + "'."); continue; } - h.push(q = q.db.tag(u[f + 1], b, w, r)); + h.push(q = q.db.tag(u[g + 1], b, w, e)); } else { - q = Eb.call(this, u[f], u[f + 1], b, w, r); + q = Eb.call(this, u[g], u[g + 1], b, w, e); } - e.push({field:u[f], tag:u[f + 1], result:q}); + f.push({field:u[g], tag:u[g + 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]; + f[M].result = J[M]; } - return e; - }) : e; + return f; + }) : f; } } p && p.constructor !== Array && (p = [p]); } p || (p = this.field); - u = !d && (this.worker || this.db) && []; + u = (this.worker || this.db) && !d && []; 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)); + R(D) || (x = D, D = x.field, a = x.query || a, b = Fb(x.limit, b), w = Fb(x.offset, w), q = Fb(x.suggest, q), r = h && this.store && Fb(x.highlight, r), e = !!r || h && this.store && Fb(x.enrich, e)); if (d) { x = d[B]; } else { @@ -2503,10 +2511,10 @@ function Db(a, b, c, d, e) { } if (u) { u[B] = x.search(a, b, A); - A && r && (A.enrich = r); + A && e && (A.enrich = e); continue; } else { - x = x.search(a, b, A), A && r && (A.enrich = r); + x = x.search(a, b, A), A && e && (A.enrich = e); } } A = x && (h ? x.length : x.result.length); @@ -2520,7 +2528,7 @@ function Db(a, b, c, d, e) { if (G && G.length) { E++, t.push(G); } else if (!q) { - return h ? e : new X(e); + return h ? f : new X(f); } } } @@ -2532,13 +2540,13 @@ function Db(a, b, c, d, e) { 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); + return h ? f : new X(f); } } if (N = (G = G && G.get(n[C + 1])) && G.length) { E++, t.push(G); } else if (!q) { - return h ? e : new X(e); + return h ? f : new X(f); } } } @@ -2552,24 +2560,24 @@ function Db(a, b, c, d, e) { } } if (A) { - f[g] = D, e.push(x), g++; + g[k] = D, f.push(x), k++; } else if (1 === p.length) { - return h ? e : new X(e); + return h ? f : new X(f); } } } 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) { + for (e = 0; e < n.length; e += 2) { + g = this.index.get(n[e]); + if (!g) { + if (console.warn("Tag '" + n[e] + ":" + n[e + 1] + "' was not found because there is no field '" + n[e] + "'."), q) { continue; } else { - return h ? e : new X(e); + return h ? f : new X(f); } } - u.push(f.db.tag(n[r + 1], b, w, !1)); + u.push(g.db.tag(n[e + 1], b, w, !1)); } } var S = this; @@ -2577,38 +2585,41 @@ function Db(a, b, c, d, e) { return J.length ? S.search(a, b, c, J) : J; }); } - if (!g) { - return h ? e : new X(e); + if (!k) { + return h ? f : new X(f); } - if (l && (!r || !this.store)) { - return e[0]; + if (l && (!e || !this.store)) { + return f[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)); + for (w = 0; w < g.length; w++) { + q = f[w]; + e && 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); + return h ? r ? Db(a, q, this.index, l, r) : q : new X(q); } - e[w] = {field:f[w], result:q}; + f[w] = {field:g[w], result:q}; } - if (r && this.db && u.length) { + if (e && 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]; + f[M].result = J[M]; } - return m ? Fb(e) : k ? Db(a, e, F.index, l, k) : e; + return m ? Gb(f) : r ? Db(a, f, F.index, l, r) : f; }); } - return m ? Fb(e) : k ? Db(a, e, this.index, l, k) : e; + return m ? Gb(f) : r ? Db(a, f, this.index, l, r) : f; }; -function Fb(a) { +function Fb(a, b) { + return "undefined" === typeof a ? b : a; +} +function Gb(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++) { - 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)); + for (var 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(e.field) : (h.field = c[k] = [e.field], b.push(h)); } } return b; @@ -2643,17 +2654,17 @@ function vb(a) { this.L = []; this.field = []; this.S = []; - this.key = (c = b.key || b.id) && Gb(c, this.S) || "id"; + this.key = (c = b.key || b.id) && Hb(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 W(d) : new Set() : d ? new V(d) : new Map(); this.I = (c = b.store || null) && c && !0 !== c && []; this.store = c && (d ? new V(d) : new Map()); - this.cache = (c = a.cache || null) && new Hb(c); + this.cache = (c = a.cache || null) && new Ib(c); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = Ib.call(this, a, b); + this.index = Jb.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -2667,7 +2678,7 @@ function vb(a) { if (!e) { throw Error("The tag field from the document descriptor is undefined."); } - 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)); + d.custom ? this.K[b] = d.custom : (this.K[b] = Hb(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()); } @@ -2682,12 +2693,12 @@ function vb(a) { } if (f.length) { var g = this; - return Promise.all(f).then(function(h) { - for (var k = new Map(), l = 0, m = z(g.index.entries()), p = m.next(); !p.done; p = m.next()) { + return Promise.all(f).then(function(k) { + for (var h = 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++); + q.then && (q = f[l].encoder || {}, n = h.get(q), n || (n = q.encode ? q : new La(q), h.set(q, n)), q = k[l], q.encoder = n, g.index.set(p, q), l++); } return g; }); @@ -2725,24 +2736,24 @@ v.mount = function(a) { f.document = !0; e ? f.bypass = !0 : f.store = this.store; } - var h = this; + var k = this; return this.db = Promise.all(c).then(function() { - h.db = !0; + k.db = !0; }); }; v.commit = function(a, b) { var c = this, d, e, f, g; - return xa(function(h) { - if (1 == h.h) { + return xa(function(k) { + if (1 == k.h) { d = []; e = z(c.index.values()); for (f = e.next(); !f.done; f = e.next()) { g = f.value, d.push(g.commit(a, b)); } - return L(h, Promise.all(d), 2); + return L(k, Promise.all(d), 2); } c.reg.clear(); - h.h = 0; + k.h = 0; }); }; v.destroy = function() { @@ -2751,7 +2762,7 @@ v.destroy = function() { } return Promise.all(a); }; -function Ib(a, b) { +function Jb(a, b) { var c = new Map(), d = b.index || b.field || b; R(d) && (d = [d]); for (var e = 0, f, g = void 0; e < d.length; e++) { @@ -2759,22 +2770,22 @@ function Ib(a, b) { R(f) || (g = f, f = f.field); g = Ca(g) ? Object.assign({}, a, g) : a; if (this.worker) { - var h = new Xa(g); - h.encoder = g.encoder; - c.set(f, h); + var k = new Xa(g); + k.encoder = g.encoder; + c.set(f, k); } 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)); + g.custom ? this.L[e] = g.custom : (this.L[e] = Hb(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, 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)); + d = a[b], e = d.field || d, d.custom ? (this.I[b] = d.custom, d.custom.ja = e) : (this.I[b] = Hb(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 Gb(a, b) { +function Hb(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); } @@ -2843,7 +2854,7 @@ v.set = function(a, b) { this.store.set(a, b); return this; }; -v.searchCache = Jb; +v.searchCache = Kb; v.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; @@ -2860,23 +2871,23 @@ v.export = function(a, b, c, d) { switch(d) { case 0: var g = "reg"; - var h = db(this.reg); + var k = db(this.reg); b = null; break; case 1: g = "tag"; - h = this.tag && bb(this.tag, this.reg.size); + k = this.tag && bb(this.tag, this.reg.size); b = null; break; case 2: g = "doc"; - h = this.store && $a(this.store); + k = this.store && $a(this.store); b = null; break; default: return; } - return fb.call(this, a, b, g, h, c, d); + return fb.call(this, a, b, g, k, c, d); }; v.import = function(a, b) { var c = a.split("."); @@ -2916,9 +2927,9 @@ v.import = function(a, b) { } }; Qa(ob.prototype); -function Jb(a, b, c) { - var d = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Hb()); +function Kb(a, b, c) { + var d = (b ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); + this.cache || (this.cache = new Ib()); var e = this.cache.get(d); if (!e) { e = this.search(a, b, c); @@ -2933,43 +2944,43 @@ function Jb(a, b, c) { } return e; } -function Hb(a) { +function Ib(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -Hb.prototype.set = function(a, b) { +Ib.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); }; -Hb.prototype.get = function(a) { +Ib.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) { +Ib.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() { +Ib.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) { +var Lb = {normalize:!1, numeric:!1, dedupe:!1}; +var Mb = {}; +var Nb = 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 Ob = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Pb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +var Qb = {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 Rb = {Exact:Lb, Default:Mb, Normalize:Mb, LatinBalance:{mapper:Nb}, LatinAdvanced:{mapper:Nb, matcher:Ob, replacer:Pb}, LatinExtra:{mapper:Nb, replacer:Pb.concat([/(?!^)[aeo]/g, ""]), matcher:Ob}, 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 = 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++) { + for (var c = a[b], d = c.charAt(0), e = Qb[d], f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qb[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { } a[b] = d; } -}}, CJK:{split:""}, LatinExact:Kb, LatinDefault:Lb, LatinSimple:Lb}; +}}, CJK:{split:""}, LatinExact:Lb, LatinDefault:Mb, LatinSimple:Mb}; U.prototype.remove = function(a, b) { var c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { @@ -2985,15 +2996,15 @@ U.prototype.remove = function(a, b) { } } } else { - Rb(this.map, a), this.depth && Rb(this.ctx, a); + Sb(this.map, a), this.depth && Sb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.ca && Sb(this)); + this.db && (this.commit_task.push({del:a}), this.ca && Tb(this)); this.cache && this.cache.remove(a); return this; }; -function Rb(a, b) { +function Sb(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++) { @@ -3012,12 +3023,12 @@ function Rb(a, b) { } } else { 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); + f = e.value, e = f[0], (f = Sb(f[1], b)) ? c += f : a.delete(e); } } return c; } -;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}}}; +;var Ub = {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)) { @@ -3027,17 +3038,17 @@ U.prototype.add = function(a, b, c, d) { b = this.encoder.encode(b, !d); var e = b.length; if (e) { - 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; + for (var f = Q(), g = Q(), k = this.resolution, h = 0; h < e; h++) { + var l = b[this.rtl ? e - 1 - h : h], m = l.length; if (m && (d || !g[l])) { - var p = this.score ? this.score(b, l, k, null, 0) : Ub(h, e, k), n = ""; + var p = this.score ? this.score(b, l, h, null, 0) : Vb(k, e, h), n = ""; switch(this.tokenize) { case "full": if (2 < m) { 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); + n = l.substring(p, r), q = this.rtl ? m - 1 - p : p, q = this.score ? this.score(b, l, h, n, q) : Vb(k, e, h, m, q), Wb(this, g, n, q, a, c); } } break; @@ -3046,24 +3057,24 @@ U.prototype.add = function(a, b, c, d) { case "reverse": if (1 < m) { 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); + n = l[this.rtl ? m - 1 - r : r] + n, q = this.score ? this.score(b, l, h, n, r) : Vb(k, e, h, m, r), Wb(this, g, n, q, a, c); } n = ""; } case "forward": if (1 < m) { for (r = 0; r < m; r++) { - n += l[this.rtl ? m - 1 - r : r], Vb(this, g, n, p, a, c); + n += l[this.rtl ? m - 1 - r : r], Wb(this, g, n, p, a, c); } break; } default: - 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]) { + if (Wb(this, g, l, p, a, c), d && 1 < e && h < e - 1) { + for (m = Q(), n = this.da, p = l, r = Math.min(d + 1, this.rtl ? h + 1 : e - h), q = m[p] = 1; q < r; q++) { + if ((l = b[this.rtl ? e - 1 - h - q : h + q]) && !m[l]) { m[l] = 1; - 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); + var w = this.score ? this.score(b, p, h, l, q - 1) : Vb(n + (e / 2 > n ? 0 : 1), e, h, r - 1, q - 1), u = this.bidirectional && l > p; + Wb(this, f, u ? p : l, w, a, c, u ? l : p); } } } @@ -3075,55 +3086,57 @@ U.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.ca && Sb(this)); + this.db && (b || this.commit_task.push({del:a}), this.ca && Tb(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); +function Wb(a, b, c, d, e, f, g) { + var k = g ? a.ctx : a.map, h; + if (!b[c] || g && !(h = b[c])[g]) { + if (g ? (b = h || (b[c] = Q()), 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[d] || (k[d] = []), !f || !k.includes(e)) { + if (k.length === Math.pow(2, 31) - 1) { + b = new ib(k); 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); + f = f.value, f.includes(k) && (f[f.indexOf(k)] = b); } } - k[d] = h = b; + h[d] = k = b; } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + k.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(k) : a.reg.set(e, [k])); } } } -function Ub(a, b, c, d, e) { +function Vb(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; } ;U.prototype.search = function(a, b, c) { c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); + if (c && c.cache) { + return c.cache = !1, a = this.searchCache(a, b, c), c.cache = !0, a; + } var d = [], e = 0, f; if (c) { a = c.query || a; b = c.limit || b; e = c.offset || 0; var g = c.context; - var h = c.suggest; - var k = (f = !1 !== c.resolve) && c.enrich; + var k = c.suggest; + var h = (f = c.resolve) && c.enrich; var l = c.boost; var m = c.resolution; var p = this.db && c.tag; - } else { - f = this.resolve; } + "undefined" === typeof f && (f = this.resolve); g = this.depth && !1 !== g; var n = this.encoder.encode(a, !g); var q = n.length; b = b || (f ? 100 : 0); if (1 === q) { - return Wb.call(this, n[0], "", b, e, f, k, p); + return Xb.call(this, n[0], "", b, e, f, h, p); } - if (2 === q && g && !h) { - return Wb.call(this, n[1], n[0], b, e, f, k, p); + if (2 === q && g && !k) { + return Xb.call(this, n[1], n[0], b, e, f, h, p); } var r = Q(), w = 0; if (g) { @@ -3132,8 +3145,8 @@ function Ub(a, b, c, d, e) { } m || 0 === m || (m = u ? this.da : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, n, b, e, h, f, k, p), !1 !== a)) { - return a; + if (this.db.search && (c = this.db.search(this, n, b, e, k, f, h, p), !1 !== c)) { + return c; } var B = this; return function() { @@ -3153,56 +3166,56 @@ function Ub(a, b, c, d, e) { break; } r[x] = 1; - return L(A, Xb(B, x, u, 0, 0, !1, !1), 6); + return L(A, Yb(B, x, u, 0, 0, !1, !1), 6); case 6: D = A.D; - if (D = Yb(D, d, h, m)) { + if (D = Zb(D, d, k, m)) { d = D; A.h = 4; break; } - u && (h && D && d.length || (u = x)); + u && (k && D && d.length || (u = x)); case 5: - h && u && w === q - 1 && !d.length && (m = B.resolution, u = "", w = -1, r = Q()); + k && u && w === q - 1 && !d.length && (m = B.resolution, u = "", w = -1, r = Q()); w++; A.h = 2; break; case 4: - return A.return(Zb(d, m, b, e, h, l, f)); + return A.return($b(d, m, b, e, k, l, f)); } }); }(); } - 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; + for (a = c = void 0; w < q; w++) { + if ((a = n[w]) && !r[a]) { + r[a] = 1; + c = Yb(this, a, u, 0, 0, !1, !1); + if (c = Zb(c, d, k, m)) { + d = c; break; } - u && (h && a && d.length || (u = c)); + u && (k && c && d.length || (u = a)); } - h && u && w === q - 1 && !d.length && (m = this.resolution, u = "", w = -1, r = Q()); + k && u && w === q - 1 && !d.length && (m = this.resolution, u = "", w = -1, r = Q()); } - return Zb(d, m, b, e, h, l, f); + return $b(d, m, b, e, k, l, f); }; -function Zb(a, b, c, d, e, f, g) { - var h = a.length, k = a; - if (1 < h) { - k = rb(a, b, c, d, e, f, g); - } else if (1 === h) { +function $b(a, b, c, d, e, f, g) { + var k = a.length, h = a; + if (1 < k) { + h = rb(a, b, c, d, e, f, g); + } else if (1 === k) { return g ? ub.call(null, a[0], c, d) : new X(a[0]); } - return g ? k : new X(k); + return g ? h : new X(h); } -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); +function Xb(a, b, c, d, e, f, g) { + a = Yb(this, a, b, c, d, e, f, g); + return this.db ? a.then(function(k) { + return e ? k || [] : new X(k); }) : a && a.length ? e ? ub.call(this, a, c, d) : new X(a) : e ? [] : new X(); } -function Yb(a, b, c, d) { +function Zb(a, b, c, d) { var e = []; if (a && a.length) { if (a.length <= d) { @@ -3223,11 +3236,11 @@ function Yb(a, b, c, d) { return e; } } -function Xb(a, b, c, d, e, f, g, h) { - var k; - c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); +function Yb(a, b, c, d, e, f, g, k) { + var 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, d, e, f, g, k); } a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; @@ -3238,12 +3251,12 @@ function Xb(a, b, c, d, e, f, g, h) { } if (a) { var c = R(a) ? a : a.preset; - c && (Tb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Tb[c], a)); + c && (Ub[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ub[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 || {}; + var d = !0 === c ? {depth:1} : c || {}, e = R(a.encoder) ? Rb[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"; @@ -3258,7 +3271,7 @@ function Xb(a, b, c, d, e, f, g, h) { 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.cache = (c = a.cache || null) && new Ib(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); @@ -3281,7 +3294,7 @@ v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Sb(a) { +function Tb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -3311,11 +3324,11 @@ v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Rb(this.map); - this.depth && Rb(this.ctx); + Sb(this.map); + this.depth && Sb(this.ctx); return this; }; -v.searchCache = Jb; +v.searchCache = Kb; v.export = function(a, b, c, d) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; @@ -3370,23 +3383,23 @@ v.serialize = function(a) { c = "index.map=new Map([" + c + "]);"; f = z(this.ctx.entries()); for (var g = f.next(); !g.done; g = f.next()) { - var h = g.value; - g = h[0]; - h = gb(h[1], e); - h = "new Map([" + h + "])"; - h = '["' + g + '",' + h + "]"; - d += (d ? "," : "") + h; + var k = g.value; + g = k[0]; + k = gb(k[1], e); + k = "new Map([" + k + "])"; + k = '["' + g + '",' + k + "]"; + d += (d ? "," : "") + k; } d = "index.ctx=new Map([" + d + "]);"; } return a ? "function inject(index){" + b + c + d + "}" : b + c + d; }; 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) { +var ac = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), bc = ["map", "ctx", "tag", "reg", "cfg"], cc = Q(); +function dc(a, b) { b = void 0 === b ? {} : b; - if (!this || this.constructor !== cc) { - return new cc(a, b); + if (!this || this.constructor !== dc) { + return new dc(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3397,7 +3410,7 @@ function cc(a, b) { this.db = null; this.h = {}; } -v = cc.prototype; +v = dc.prototype; v.mount = function(a) { if (a.index) { return a.mount(this); @@ -3411,18 +3424,18 @@ v.open = function() { } var a = this; navigator.storage && navigator.storage.persist(); - bc[a.id] || (bc[a.id] = []); - bc[a.id].push(a.field); - var b = $b.open(a.id, 1); + cc[a.id] || (cc[a.id] = []); + cc[a.id].push(a.field); + var b = ac.open(a.id, 1); b.onupgradeneeded = function() { - 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 : "" : "")); + for (var c = a.db = this.result, d = 0, e; d < bc.length; d++) { + e = bc[d]; + for (var f = 0, g; f < cc[a.id].length; f++) { + g = cc[a.id][f], c.objectStoreNames.contains(e + ("reg" !== e ? g ? ":" + g : "" : "")) || c.createObjectStore(e + ("reg" !== e ? g ? ":" + g : "" : "")); } } }; - return a.db = dc(b, function(c) { + return a.db = ec(b, function(c) { a.db = c; a.db.onversionchange = function() { a.close(); @@ -3434,21 +3447,21 @@ v.close = function() { this.db = null; }; v.destroy = function() { - var a = $b.deleteDatabase(this.id); - return dc(a); + var a = ac.deleteDatabase(this.id); + return ec(a); }; 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 : "" : "")); + for (var a = [], b = 0, c; b < bc.length; b++) { + c = bc[b]; + for (var d = 0, e; d < cc[this.id].length; d++) { + e = cc[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 dc(b); + return ec(b); }; v.get = function(a, b, c, d, e, f) { c = void 0 === c ? 0 : c; @@ -3457,33 +3470,33 @@ v.get = function(a, b, c, d, e, f) { 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 dc(a).then(function(h) { - var k = []; - if (!h || !h.length) { - return k; + return ec(a).then(function(k) { + var h = []; + if (!k || !k.length) { + return h; } if (e) { - if (!c && !d && 1 === h.length) { - return h[0]; + if (!c && !d && 1 === k.length) { + return k[0]; } - for (var l = 0, m = void 0; l < h.length; l++) { - if ((m = h[l]) && m.length) { + for (var l = 0, m = void 0; l < k.length; l++) { + if ((m = k[l]) && m.length) { if (d >= m.length) { d -= m.length; } else { for (var p = c ? d + Math.min(m.length - d, c) : m.length, n = d; n < p; n++) { - k.push(m[n]); + h.push(m[n]); } d = 0; - if (k.length === c) { + if (h.length === c) { break; } } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; v.tag = function(a, b, c, d) { @@ -3492,7 +3505,7 @@ v.tag = function(a, b, c, d) { 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 dc(a).then(function(f) { + return ec(a).then(function(f) { if (!f || !f.length || c >= f.length) { return []; } @@ -3506,7 +3519,7 @@ v.tag = function(a, b, c, d) { 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] = dc(b.get(a[d])); + c[d] = ec(b.get(a[d])); } return Promise.all(c).then(function(e) { for (var f = 0; f < e.length; f++) { @@ -3517,7 +3530,7 @@ v.enrich = function(a) { }; v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return dc(a).then(function(b) { + return ec(a).then(function(b) { return !!b; }); }; @@ -3534,18 +3547,18 @@ v.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 dc(e).finally(function() { + return ec(e).finally(function() { e = d = null; return f; }); }; v.commit = function(a, b, c) { var d = this, e, f, g; - return xa(function(h) { - switch(h.h) { + return xa(function(k) { + switch(k.h) { case 1: if (b) { - return L(h, d.clear(), 12); + return L(k, d.clear(), 12); } e = a.commit_task; a.commit_task = []; @@ -3553,45 +3566,45 @@ v.commit = function(a, b, c) { g = void 0; case 4: if (!(f < e.length)) { - h.h = 6; + k.h = 6; break; } g = e[f]; if (!g.clear) { e[f] = g.del; - h.h = 5; + k.h = 5; break; } - return L(h, d.clear(), 8); + return L(k, d.clear(), 8); case 8: b = !0; - h.h = 6; + k.h = 6; break; case 5: f++; - h.h = 4; + k.h = 4; break; case 6: if (b) { - h.h = 3; + k.h = 3; break; } c || (e = e.concat(Da(a.reg))); if (!e.length) { - h.h = 10; + k.h = 10; break; } - return L(h, d.remove(e), 11); + return L(k, d.remove(e), 11); case 11: case 10: - h.h = 3; + k.h = 3; break; case 12: a.commit_task = []; case 3: - return a.reg.size ? L(h, d.transaction("map", "readwrite", function(k) { + return a.reg.size ? L(k, d.transaction("map", "readwrite", function(h) { 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) { + m = m.value, p.Y = m[0], p.O = m[1], p.O.length && (b ? h.put(p.O, p.Y) : h.get(p.Y).onsuccess = function(n) { return function() { var q = this.result, r; if (q && q.length) { @@ -3610,19 +3623,19 @@ v.commit = function(a, b, c) { } else { q = n.O, r = 1; } - r && k.put(q, n.Y); + r && h.put(q, n.Y); }; }(p)); } - }), 13) : h.return(); + }), 13) : k.return(); case 13: - return L(h, d.transaction("ctx", "readwrite", function(k) { + return L(k, d.transaction("ctx", "readwrite", function(h) { for (var l = z(a.ctx), m = l.next(), p = {}; !m.done; p = {V:void 0}, m = l.next()) { m = m.value; 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) { + n = n.value, q.Z = n[0], q.P = n[1], q.P.length && (b ? h.put(q.P, p.V + ":" + q.Z) : h.get(p.V + ":" + q.Z).onsuccess = function(r, w) { return function() { var u = this.result, B; if (u && u.length) { @@ -3641,7 +3654,7 @@ v.commit = function(a, b, c) { } else { u = r.P, B = 1; } - B && k.put(u, w.V + ":" + r.Z); + B && h.put(u, w.V + ":" + r.Z); }; }(q, p)); } @@ -3649,59 +3662,59 @@ v.commit = function(a, b, c) { }), 14); case 14: if (a.store) { - return L(h, d.transaction("reg", "readwrite", function(k) { + return L(k, d.transaction("reg", "readwrite", function(h) { 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); + h.put("object" === typeof p ? JSON.stringify(p) : 1, m); } }), 16); } if (a.bypass) { - h.h = 16; + k.h = 16; break; } - return L(h, d.transaction("reg", "readwrite", function(k) { + return L(k, d.transaction("reg", "readwrite", function(h) { for (var l = z(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { - k.put(1, m.value); + h.put(1, m.value); } }), 16); case 16: if (!a.tag) { - h.h = 20; + k.h = 20; break; } - return L(h, d.transaction("tag", "readwrite", function(k) { + return L(k, d.transaction("tag", "readwrite", function(h) { 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) { + m = m.value, p.ba = m[0], p.X = m[1], p.X.length && (h.get(p.ba).onsuccess = function(n) { return function() { var q = this.result; q = q && q.length ? q.concat(n.X) : n.X; - k.put(q, n.ba); + h.put(q, n.ba); }; }(p)); } }), 20); case 20: - a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), h.h = 0; + a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), k.h = 0; } }); }; -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++) { - if (l = b[k], l = h.indexOf(l), 0 <= l) { - if (e = 1, 1 < h.length) { - h.splice(l, 1); +function fc(a, b, c) { + for (var d = a.value, e, f = 0, g = 0, k; g < d.length; g++) { + if (k = c ? d : d[g]) { + for (var h = 0, l; h < b.length; h++) { + if (l = b[h], l = k.indexOf(l), 0 <= l) { + if (e = 1, 1 < k.length) { + k.splice(l, 1); } else { d[g] = []; break; } } } - f += h.length; + f += k.length; } if (c) { break; @@ -3715,17 +3728,17 @@ v.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && ec(c, a); + c && fc(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && ec(c, a); + c && fc(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && ec(c, a, !0); + c && fc(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3733,7 +3746,7 @@ v.remove = function(a) { } })]); }; -function dc(a, b) { +function ec(a, b) { return new Promise(function(c, d) { a.onsuccess = a.oncomplete = function() { b && b(this.result); @@ -3744,8 +3757,8 @@ function dc(a, b) { a = null; }); } -;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; +;var gc = {Index:U, Charset:Rb, Encoder:La, Document:ob, Worker:Xa, Resolver:X, IndexedDB:dc, Language:{}}, hc = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, ic; +(ic = hc.define) && ic.amd ? ic([], function() { + return gc; +}) : "object" === typeof hc.exports ? hc.exports = gc : hc.FlexSearch = gc; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index fea2c39..c56b11c 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.160 (ES5) + * FlexSearch.js v0.8.161 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -49,7 +49,7 @@ e=[],f=Q(),g,h,k=this.split||""===this.split?a.split(this.split):[a],l=0,m=void (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} +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");Ra.call(a,"searchCache")}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);1E9D&&(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;cc||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))} +return Promise.all(b)}break;case "tag":this.tag=cb(b,this.tag);break;case "doc":this.store=ab(b,this.store)}}};Qa(ob.prototype);function Kb(a,b,c){var d=(b?""+a:"object"===typeof a?""+a.query:a).toLowerCase();this.cache||(this.cache=new Ib);var e=this.cache.get(d);if(!e){e=this.search(a,b,c);if(e.then){var f=this;e.then(function(g){f.cache.set(d,g);return g})}this.cache.set(d,e)}return e}function Ib(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}Ib.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)}; +Ib.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};Ib.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)}};Ib.prototype.clear=function(){this.cache.clear();this.h=""};var Lb={normalize:!1,numeric:!1,dedupe:!1};var Mb={};var Nb=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 Ob=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Pb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Qb={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 Rb={Exact:Lb,Default:Mb,Normalize:Mb,LatinBalance:{mapper:Nb},LatinAdvanced:{mapper:Nb,matcher:Ob,replacer:Pb},LatinExtra:{mapper:Nb,replacer:Pb.concat([/(?!^)[aeo]/g,""]),matcher:Ob},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 Sb(this.map,a),this.depth&&Sb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Tb(this));this.cache&&this.cache.remove(a);return this}; +function Sb(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):Vb(h,e,k,m,q),Wb(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;Wb(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&&Tb(this));return this}; +function Wb(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 Vb(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({},Ub[c],a))}else a={};c=a.context;var d=!0===c?{depth:1}:c||{},e=R(a.encoder)?Rb[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 Ib(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 Tb(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.cleanup=function(){if(!this.fastupdate)return this;Sb(this.map);this.depth&&Sb(this.ctx);return this};v.searchCache=Kb;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=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;dthis.stemm this.replacer[l+1]);this.cache&&w.length<=this.o&&(this.j.set(w,h),this.j.size>this.A&&(this.j.clear(),this.o=this.o/1.1|0));if(h){if(h!==w)if(c){if(d[h])continue;d[h]=1}else{if(f===h)continue;f=h}e.push(h)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.m&&(this.i.set(a,e),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return e};function G(a){a.l=null;a.i.clear();a.j.clear()};function H(a,c,b){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;let e=[];for(let d=0,g,f;d=f){b-=f;continue}bc&&(g=g.slice(0,c),f=c);if(!e.length&&f>=c)return g;e.push(g);c-=f;if(!c)break}return e=1d.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else J(this.map,a),this.depth&&J(this.ctx,a);c||this.reg.delete(a)}return this}; function J(a,c){let b=0;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,g,f;dq;g--){f=m.substring(q,g);t=this.rtl?d-1-q:q;var k=this.score?this.score(c,m,p,f,t):L(v, n,p,d,t);M(this,w,f,k,a,b)}break}case "bidirectional":case "reverse":if(1f?0: -1),n,p,k-1,l-1),t=this.bidirectional&&m>g;M(this,h,t?g:m,q,a,b,t?m:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function M(a,c,b,e,d,g,f){let k=f?a.ctx:a.map,l;if(!c[b]||f&&!(l=c[b])[f])f?(c=l||(c[b]=x()),c[f]=1,(l=k.get(f))?k=l:k.set(f,k=new Map)):c[b]=1,(l=k.get(b))?k=l:k.set(b,k=[]),k=k[e]||(k[e]=[]),g&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function L(a,c,b,e,d){return b&&1c||d?f.slice(d,c+d):f;f=a}else{if(ac||d)f=f.slice(d,c+d)}h=f}else if(1===e){c=H.call(null,a[0], -c,d);break a}c=h}return c};function N(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 I(a,c){if(!this||this.constructor!==I)return new I(a);if(a){var b="string"===typeof a?a:a.preset;b&&(a=Object.assign({},K[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new F(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= +1),n,p,k-1,l-1),t=this.bidirectional&&m>g;M(this,h,t?g:m,q,a,b,t?m:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function M(a,c,b,e,d,g,f){let k=f?a.ctx:a.map,l;if(!c[b]||f&&!(l=c[b])[f])f?(c=l||(c[b]=x()),c[f]=1,(l=k.get(f))?k=l:k.set(f,k=new Map)):c[b]=1,(l=k.get(b))?k=l:k.set(b,k=[]),k=k[e]||(k[e]=[]),g&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function L(a,c,b,e,d){return b&&1c||d?f.slice(d,c+d):f;f=a}else{if(ac||d)f=f.slice(d,c+d)}h=f}else if(1===e){c= +H.call(null,a[0],c,d);break a}c=h}return c};function N(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 I(a,c){if(!this||this.constructor!==I)return new I(a);if(a){var b="string"===typeof a?a:a.preset;b&&(a=Object.assign({},K[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new F(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;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.v=e.resolution||3;this.rtl=d.rtl||a.rtl||!1}r=I.prototype;r.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};r.append=function(a,c){return this.add(a,c,!0)};r.contain=function(a){return this.reg.has(a)};r.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)}; r.cleanup=function(){if(!this.fastupdate)return this;J(this.map);this.depth&&J(this.ctx);return this};x();const O={Index:I,Charset:null,Encoder:F,Document:null,Worker:null,Resolver:null,IndexedDB:null,Language:{}},P="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let Q;(Q=P.define)&&Q.amd?Q([],function(){return O}):"object"===typeof P.exports?P.exports=O:P.FlexSearch=O;}(this||self)); diff --git a/dist/flexsearch.light.module.debug.js b/dist/flexsearch.light.module.debug.js index 7270863..74e9269 100644 --- a/dist/flexsearch.light.module.debug.js +++ b/dist/flexsearch.light.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.160 (Bundle/Debug) + * FlexSearch.js v0.8.161 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -428,9 +428,8 @@ function L(a, c, b, e, d) { var f = b.suggest; var k = !0; var l = b.resolution; - } else { - k = !0; } + "undefined" === typeof k && (k = !0); g = this.depth && !1 !== g; a = this.encoder.encode(a, !g); b = a.length; diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index aae5d1e..784c0ac 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.160 (Bundle) + * FlexSearch.js v0.8.161 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -18,10 +18,10 @@ this.h+")$"));let v;for(;v!==h&&2this.stemm this.replacer[l+1]);this.cache&&w.length<=this.o&&(this.j.set(w,h),this.j.size>this.A&&(this.j.clear(),this.o=this.o/1.1|0));if(h){if(h!==w)if(c){if(d[h])continue;d[h]=1}else{if(f===h)continue;f=h}e.push(h)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.m&&(this.i.set(a,e),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return e};function G(a){a.l=null;a.i.clear();a.j.clear()};function H(a,c,b){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;let e=[];for(let d=0,g,f;d=f){b-=f;continue}bc&&(g=g.slice(0,c),f=c);if(!e.length&&f>=c)return g;e.push(g);c-=f;if(!c)break}return e=1d.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else J(this.map,a),this.depth&&J(this.ctx,a);c||this.reg.delete(a)}return this}; function J(a,c){let b=0;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,g,f;dq;g--){f=m.substring(q,g);t=this.rtl?d-1-q:q;var k=this.score?this.score(c,m,p,f,t):L(v, n,p,d,t);M(this,w,f,k,a,b)}break}case "bidirectional":case "reverse":if(1f?0: -1),n,p,k-1,l-1),t=this.bidirectional&&m>g;M(this,h,t?g:m,q,a,b,t?m:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function M(a,c,b,e,d,g,f){let k=f?a.ctx:a.map,l;if(!c[b]||f&&!(l=c[b])[f])f?(c=l||(c[b]=x()),c[f]=1,(l=k.get(f))?k=l:k.set(f,k=new Map)):c[b]=1,(l=k.get(b))?k=l:k.set(b,k=[]),k=k[e]||(k[e]=[]),g&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function L(a,c,b,e,d){return b&&1c||d?f.slice(d,c+d):f;f=a}else{if(ac||d)f=f.slice(d,c+d)}h=f}else if(1===e){c=H.call(null,a[0], -c,d);break a}c=h}return c};function N(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 I(a,c){if(!this||this.constructor!==I)return new I(a);if(a){var b="string"===typeof a?a:a.preset;b&&(a=Object.assign({},K[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new F(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= +1),n,p,k-1,l-1),t=this.bidirectional&&m>g;M(this,h,t?g:m,q,a,b,t?m:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function M(a,c,b,e,d,g,f){let k=f?a.ctx:a.map,l;if(!c[b]||f&&!(l=c[b])[f])f?(c=l||(c[b]=x()),c[f]=1,(l=k.get(f))?k=l:k.set(f,k=new Map)):c[b]=1,(l=k.get(b))?k=l:k.set(b,k=[]),k=k[e]||(k[e]=[]),g&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function L(a,c,b,e,d){return b&&1c||d?f.slice(d,c+d):f;f=a}else{if(ac||d)f=f.slice(d,c+d)}h=f}else if(1===e){c= +H.call(null,a[0],c,d);break a}c=h}return c};function N(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 I(a,c){if(!this||this.constructor!==I)return new I(a);if(a){var b="string"===typeof a?a:a.preset;b&&(a=Object.assign({},K[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new F(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;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.v=e.resolution||3;this.rtl=d.rtl||a.rtl||!1}r=I.prototype;r.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};r.append=function(a,c){return this.add(a,c,!0)};r.contain=function(a){return this.reg.has(a)};r.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)}; r.cleanup=function(){if(!this.fastupdate)return this;J(this.map);this.depth&&J(this.ctx);return this};x();export default {Index:I,Charset:null,Encoder:F,Document:null,Worker:null,Resolver:null,IndexedDB:null,Language:{}}; export const Index=I;export const Charset=null;export const Encoder=F;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/module-debug/async.js b/dist/module-debug/async.js index 88fdcec..2a028de 100644 --- a/dist/module-debug/async.js +++ b/dist/module-debug/async.js @@ -1,3 +1,4 @@ + import Document from "./document.js"; import Index from "./index.js"; import WorkerIndex from "./worker.js"; @@ -8,6 +9,8 @@ export default function (prototype) { register.call(prototype, "search"); register.call(prototype, "update"); register.call(prototype, "remove"); + + register.call(prototype, "searchCache"); } let timer, timestamp, cycle; diff --git a/dist/module-debug/bundle.js b/dist/module-debug/bundle.js index ef8d1c1..1319942 100644 --- a/dist/module-debug/bundle.js +++ b/dist/module-debug/bundle.js @@ -22,6 +22,7 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */Index.prototype.addAsync; /** @export */Index.prototype.appendAsync; /** @export */Index.prototype.searchAsync; +/** @export */Index.prototype.searchCacheAsync; /** @export */Index.prototype.updateAsync; /** @export */Index.prototype.removeAsync; /** @export */Index.prototype.export; @@ -66,6 +67,7 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */Document.prototype.addAsync; /** @export */Document.prototype.appendAsync; /** @export */Document.prototype.searchAsync; +/** @export */Document.prototype.searchCacheAsync; /** @export */Document.prototype.updateAsync; /** @export */Document.prototype.removeAsync; /** @export */Document.prototype.mount; @@ -217,6 +219,7 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */SearchOptions.suggest; /** @export */SearchOptions.resolve; /** @export */SearchOptions.enrich; +/** @export */SearchOptions.cache; /** @export */SearchOptions.resolution; /** @export */DocumentSearchOptions.query; @@ -224,7 +227,10 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */DocumentSearchOptions.offset; /** @export */DocumentSearchOptions.context; /** @export */DocumentSearchOptions.suggest; +/** @export */DocumentSearchOptions.resolve; /** @export */DocumentSearchOptions.enrich; +/** @export */DocumentSearchOptions.cache; +/** @export */DocumentSearchOptions.resolution; /** @export */DocumentSearchOptions.tag; /** @export */DocumentSearchOptions.field; /** @export */DocumentSearchOptions.index; diff --git a/dist/module-debug/cache.js b/dist/module-debug/cache.js index e8ba4af..789d1fd 100644 --- a/dist/module-debug/cache.js +++ b/dist/module-debug/cache.js @@ -12,7 +12,7 @@ import { SearchOptions, DocumentSearchOptions } from "./type.js"; export function searchCache(query_or_options, limit_or_options, options) { - const query = ("object" == typeof query_or_options ? "" + query_or_options.query : "" + query_or_options).toLowerCase(); + const query = (limit_or_options ? "" + query_or_options : "object" == typeof query_or_options ? "" + query_or_options.query : query_or_options).toLowerCase(); if (!this.cache) { this.cache = new CacheClass(); diff --git a/dist/module-debug/db/redis/index.js b/dist/module-debug/db/redis/index.js index 76be90f..96d59c0 100644 --- a/dist/module-debug/db/redis/index.js +++ b/dist/module-debug/db/redis/index.js @@ -36,8 +36,7 @@ export default function RedisDB(name, config = {}) { this.id = (name ? sanitize(name) : "flexsearch") + "|"; this.field = config.field ? "-" + sanitize(config.field) : ""; this.type = config.type || ""; - this.fastupdate = /* tag? */ /* stringify */ /* stringify */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ - /*await rows.hasNext()*/; + this.fastupdate = /* tag? */ /* stringify */ /* stringify */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; this.db = config.db || DB || null; this.support_tag_search = !0; this.resolution = 9; @@ -156,7 +155,7 @@ RedisDB.prototype.enrich = function (ids) { if ("object" != typeof ids) { ids = [ids]; } - return this.db.hmGet(this.id + "doc", ids).then(function (res) { + return this.db.hmGet(this.id + "doc", "number" === this.type ? ids.map(i => "" + i) : ids).then(function (res) { for (let i = 0; i < res.length; i++) { res[i] = { id: ids[i], @@ -384,7 +383,7 @@ RedisDB.prototype.commit = async function (flexsearch, _replace, _append) { const ref = this.id + "ctx" + this.field + ":" + ctx_key + ":" + key; trx.zAdd(ref, result); // if(this.fastupdate) for(let j = 0; j < ids.length; j++){ - + // trx.sAdd("ref" + this.field + ":" + ids[j], ref); // } if (this.fastupdate) for (let j = 0, id; j < ids.length; j++) { // Map performs bad when pushing numeric-like values as key diff --git a/dist/module-debug/document/highlight.js b/dist/module-debug/document/highlight.js index 24aa7be..8b9c7a1 100644 --- a/dist/module-debug/document/highlight.js +++ b/dist/module-debug/document/highlight.js @@ -87,6 +87,7 @@ export function highlight_fields(query, result, index, pluck, config) { let res; if (pluck) { + //res = result[0].result; res = result; path = pluck; } else { diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index 2042b57..6a98bfb 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -45,6 +45,13 @@ Document.prototype.search = function (query, limit, options, _promises) { } } + if (options && options.cache) { + options.cache = /* suggest */ /* append: */ /* enrich */!1; + const res = this.searchCache(query, limit, options); + options.cache = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; + return res; + } + /** @type { * DocumentSearchResults| * EnrichedDocumentSearchResults| @@ -63,8 +70,7 @@ 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 = !0, highlight; @@ -82,7 +88,7 @@ Document.prototype.search = function (query, limit, options, _promises) { field = pluck || options.field || (field = options.index) && (field.index ? null : field); tag = this.tag && options.tag; suggest = options.suggest; - resolve = /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + resolve = !1 !== options.resolve; // upgrade pluck when missing if (!resolve && !pluck) { @@ -102,13 +108,15 @@ Document.prototype.search = function (query, limit, options, _promises) { } } - if (this.store && options.enrich && !resolve) { + if (this.store && options.highlight && !resolve) { + console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })"); + } else if (this.store && options.enrich && !resolve) { console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); } highlight = resolve && this.store && options.highlight; - enrich = highlight || resolve && this.store && options.enrich; + enrich = !!highlight || resolve && this.store && options.enrich; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -211,8 +219,11 @@ Document.prototype.search = function (query, limit, options, _promises) { } field || (field = this.field); - let promises = !_promises && (this.worker || this.db /*|| this.async*/) && [], - db_tag_search; + + let db_tag_search, + promises = (this.worker || this.db /*|| + (SUPPORT_ASYNC && this.async)*/ + ) && !_promises && []; // multi field search @@ -235,11 +246,11 @@ Document.prototype.search = function (query, limit, options, _promises) { field_options = key; key = field_options.field; query = field_options.query || query; - limit = field_options.limit || limit; - offset = field_options.offset || offset; - suggest = field_options.suggest || suggest; - enrich = this.store && (field_options.enrich || enrich); - highlight = enrich && (options.highlight || highlight); + limit = inherit(field_options.limit, limit); + offset = inherit(field_options.offset, offset); + suggest = inherit(field_options.suggest, suggest); + highlight = resolve && this.store && inherit(field_options.highlight, highlight); + enrich = !!highlight || resolve && this.store && inherit(field_options.enrich, enrich); } if (_promises) { @@ -296,7 +307,7 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } } @@ -312,7 +323,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } @@ -324,7 +335,7 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } } @@ -334,7 +345,7 @@ Document.prototype.search = function (query, limit, options, _promises) { len = res.length; if (!len && !suggest) { // nothing matched - return resolve ? res : new Resolver( /** @type {IntermediateSearchResults} */res); + return resolve || !!0 ? res : new Resolver( /** @type {IntermediateSearchResults} */res); } // move counter back by 1 count--; @@ -347,7 +358,7 @@ Document.prototype.search = function (query, limit, options, _promises) { count++; } else if (1 === field.length) { // fast path: nothing matched - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } @@ -365,7 +376,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } @@ -383,7 +394,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (!count) { - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } if (pluck && (!enrich || !this.store)) { return (/** @type {SearchResults} */result[0] @@ -411,7 +422,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (pluck) { - return resolve ? highlight ? highlight_fields( /** @type {string} */query, res, this.index, pluck, highlight) : /** @type {SearchResults|EnrichedSearchResults} */res : new Resolver( /** @type {IntermediateSearchResults} */res); + return resolve || !!0 ? highlight ? highlight_fields( /** @type {string} */query, res, this.index, pluck, highlight) : /** @type {SearchResults|EnrichedSearchResults} */res : new Resolver( /** @type {IntermediateSearchResults} */res); } result[i] = { @@ -433,6 +444,10 @@ 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; }; +function inherit(target_value, default_value) { + return "undefined" == typeof target_value ? default_value : target_value; +} + // 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/encoder.js b/dist/module-debug/encoder.js index 6990786..4bcd871 100644 --- a/dist/module-debug/encoder.js +++ b/dist/module-debug/encoder.js @@ -92,8 +92,7 @@ Encoder.prototype.assign = function (options) { * pre-processing string input * @type {Function|boolean} */ - this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ - /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ + this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize); // { diff --git a/dist/module-debug/index/search.js b/dist/module-debug/index/search.js index 4cf55bd..18dc573 100644 --- a/dist/module-debug/index/search.js +++ b/dist/module-debug/index/search.js @@ -8,12 +8,6 @@ import Resolver from "../resolver.js"; import { intersect } from "../intersect.js"; import resolve_default from "../resolve/default.js"; -// todo remove -// let global_resolve = 1; -// export function set_resolve(resolve){ -// global_resolve = resolve; -// } - /** * @param {string|SearchOptions} query * @param {number|SearchOptions=} limit @@ -35,6 +29,14 @@ Index.prototype.search = function (query, limit, options) { } } + if (options && options.cache) { + options.cache = /* suggest */ /* append: */ /* enrich */!1; + const res = this.searchCache(query, limit, options); + options.cache = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ + ; + return res; + } + /** @type {!Array} */ let result = [], length, @@ -57,14 +59,15 @@ Index.prototype.search = function (query, limit, options) { offset = options.offset || 0; context = options.context; suggest = options.suggest; - resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; - //resolve || (global_resolve = 0); + resolve = options.resolve; enrich = resolve && options.enrich; boost = options.boost; resolution = options.resolution; tag = this.db && options.tag; - } else { - resolve = this.resolve; // || global_resolve; + } + + if ("undefined" == typeof resolve) { + resolve = this.resolve; } context = this.depth && !1 !== context; diff --git a/dist/module-debug/intersect.js b/dist/module-debug/intersect.js index c64394e..8a1753f 100644 --- a/dist/module-debug/intersect.js +++ b/dist/module-debug/intersect.js @@ -119,6 +119,7 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res const final = []; for (let i = 0, arr; i < result.length; i++) { arr = result[i]; + //if(!arr) continue; if (arr.length > offset) { offset -= arr.length; continue; diff --git a/dist/module-debug/resolver.js b/dist/module-debug/resolver.js index 6fdd07f..2ba2b60 100644 --- a/dist/module-debug/resolver.js +++ b/dist/module-debug/resolver.js @@ -1,6 +1,5 @@ import Index from "./index.js"; import default_resolver from "./resolve/default.js"; -//import { set_resolve } from "./index/search.js"; import { apply_enrich } from "./document/search.js"; import { ResolverOptions, IntermediateSearchResults } from "./type.js"; import "./resolve/handler.js"; @@ -100,8 +99,6 @@ Resolver.prototype.boost = function (boost) { * @param {boolean=} enrich */ Resolver.prototype.resolve = function (limit, offset, enrich) { - - //set_resolve(1); const result = this.result, index = this.index; diff --git a/dist/module-debug/type.js b/dist/module-debug/type.js index f2c0217..5c1df48 100644 --- a/dist/module-debug/type.js +++ b/dist/module-debug/type.js @@ -125,6 +125,7 @@ export let StoreOptions = {}; * suggest: (boolean|undefined), * resolve: (boolean|undefined), * enrich: (boolean|undefined), + * cache: (boolean|undefined) * }} */ export let SearchOptions = {}; @@ -134,9 +135,12 @@ export let SearchOptions = {}; * query: (string|undefined), * limit: (number|undefined), * offset: (number|undefined), + * resolution: (number|undefined), * context: (boolean|undefined), * suggest: (boolean|undefined), + * resolve: (boolean|undefined), * enrich: (boolean|undefined), + * cache: (boolean|undefined), * tag: (Object|Array|undefined), * field: (Array|Array|DocumentSearchOptions|string|undefined), * index: (Array|Array|DocumentSearchOptions|string|undefined), diff --git a/dist/module-min/async.js b/dist/module-min/async.js index 1717b4f..f8eb6fb 100644 --- a/dist/module-min/async.js +++ b/dist/module-min/async.js @@ -1 +1 @@ -import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";export default function(a){register.call(a,"add"),register.call(a,"append"),register.call(a,"search"),register.call(a,"update"),register.call(a,"remove")}let timer,timestamp,cycle;function tick(){timer=cycle=0}function register(a){this[a+"Async"]=function(){const b=arguments,c=b[b.length-1];let d;if("function"==typeof c&&(d=c,delete b[b.length-1]),!timer)timer=setTimeout(tick,0),timestamp=Date.now();else if(!cycle){const a=Date.now(),b=a-timestamp,c=3*(this.priority*this.priority);cycle=b>=c}if(cycle){const c=this;return new Promise(d=>{setTimeout(function(){d(c[a+"Async"].apply(c,b))},0)})}const e=this[a].apply(this,b),f=e.then?e:new Promise(a=>a(e));return d&&f.then(d),f}} \ No newline at end of file +import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";export default function(a){register.call(a,"add"),register.call(a,"append"),register.call(a,"search"),register.call(a,"update"),register.call(a,"remove"),register.call(a,"searchCache")}let timer,timestamp,cycle;function tick(){timer=cycle=0}function register(a){this[a+"Async"]=function(){const b=arguments,c=b[b.length-1];let d;if("function"==typeof c&&(d=c,delete b[b.length-1]),!timer)timer=setTimeout(tick,0),timestamp=Date.now();else if(!cycle){const a=Date.now(),b=a-timestamp,c=3*(this.priority*this.priority);cycle=b>=c}if(cycle){const c=this;return new Promise(d=>{setTimeout(function(){d(c[a+"Async"].apply(c,b))},0)})}const e=this[a].apply(this,b),f=e.then?e:new Promise(a=>a(e));return d&&f.then(d),f}} \ No newline at end of file diff --git a/dist/module-min/bundle.js b/dist/module-min/bundle.js index b01c8a5..cf583b1 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,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 +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.searchCacheAsync,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.searchCacheAsync,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.cache,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.resolve,DocumentSearchOptions.enrich,DocumentSearchOptions.cache,DocumentSearchOptions.resolution,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/cache.js b/dist/module-min/cache.js index 60577eb..801af41 100644 --- a/dist/module-min/cache.js +++ b/dist/module-min/cache.js @@ -1 +1 @@ -import Index from"./index.js";import Document from"./document.js";import{SearchOptions,DocumentSearchOptions}from"./type.js";export function searchCache(a,b,c){const d=("object"==typeof a?""+a.query:""+a).toLowerCase();this.cache||(this.cache=new CacheClass);let e=this.cache.get(d);if(!e){if(e=this.search(a,b,c),e.then){const a=this;e.then(function(b){return a.cache.set(d,b),b})}this.cache.set(d,e)}return e}export default function CacheClass(a){this.limit=a&&!0!==a?a:1000,this.cache=new Map,this.last=""}CacheClass.prototype.set=function(a,b){this.cache.set(this.last=a,b),this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)},CacheClass.prototype.get=function(a){const b=this.cache.get(a);return b&&this.last!==a&&(this.cache.delete(a),this.cache.set(this.last=a,b)),b},CacheClass.prototype.remove=function(a){for(const b of this.cache){const c=b[0],d=b[1];d.includes(a)&&this.cache.delete(c)}},CacheClass.prototype.clear=function(){this.cache.clear(),this.last=""}; \ No newline at end of file +import Index from"./index.js";import Document from"./document.js";import{SearchOptions,DocumentSearchOptions}from"./type.js";export function searchCache(a,b,c){const d=(b?""+a:"object"==typeof a?""+a.query:a).toLowerCase();this.cache||(this.cache=new CacheClass);let e=this.cache.get(d);if(!e){if(e=this.search(a,b,c),e.then){const a=this;e.then(function(b){return a.cache.set(d,b),b})}this.cache.set(d,e)}return e}export default function CacheClass(a){this.limit=a&&!0!==a?a:1000,this.cache=new Map,this.last=""}CacheClass.prototype.set=function(a,b){this.cache.set(this.last=a,b),this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)},CacheClass.prototype.get=function(a){const b=this.cache.get(a);return b&&this.last!==a&&(this.cache.delete(a),this.cache.set(this.last=a,b)),b},CacheClass.prototype.remove=function(a){for(const b of this.cache){const c=b[0],d=b[1];d.includes(a)&&this.cache.delete(c)}},CacheClass.prototype.clear=function(){this.cache.clear(),this.last=""}; \ No newline at end of file diff --git a/dist/module-min/db/redis/index.js b/dist/module-min/db/redis/index.js index b196c69..199f58d 100644 --- a/dist/module-min/db/redis/index.js +++ b/dist/module-min/db/redis/index.js @@ -1 +1 @@ -import{createClient}from"redis";const defaults={host:"localhost",port:"6379",user:null,pass:null},VERSION=1,fields=["map","ctx","reg","tag","doc","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}let DB,TRX;export default function RedisDB(a,b={}){return this&&this.constructor===RedisDB?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id=(a?sanitize(a):"flexsearch")+"|",this.field=b.field?"-"+sanitize(b.field):"",this.type=b.type||"",this.fastupdate=!0,this.db=b.db||DB||null,this.support_tag_search=!0,this.resolution=9,this.resolution_ctx=9,Object.assign(defaults,b),this.db&&delete defaults.db):new RedisDB(a,b)}RedisDB.prototype.mount=function(a){return a.index?a.mount(this):(a.db=this,this.resolution=a.resolution,this.resolution_ctx=a.resolution_ctx,this.open())},RedisDB.prototype.open=async function(){if(this.db)return this.db;if(DB)return this.db=DB;let a=defaults.url;return a||(a=defaults.user?`redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`:`redis://${defaults.host}:${defaults.port}`),this.db=DB=await createClient(a).on("error",a=>console.error(a)).connect()},RedisDB.prototype.close=async function(){return DB&&(await this.db.disconnect()),this.db=DB=null,this},RedisDB.prototype.destroy=function(){return this.clear()},RedisDB.prototype.clear=function(){return this.db.unlink([this.id+"map"+this.field,this.id+"ctx"+this.field,this.id+"tag"+this.field,this.id+"cfg"+this.field,this.id+"doc",this.id+"reg"])};function create_result(a,b,c,d,e){if(c){if("number"===b)for(let c,e,f=0;f=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc",a).then(function(b){for(let c=0;ce,k.push(c+(f?d:e)+":"+(f?e:d)),l.push(1),e=d}else{const a=this.id+"map"+this.field+":";for(let c=0;cconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return DB&&(await this.db.disconnect()),this.db=DB=null,this},RedisDB.prototype.destroy=function(){return this.clear()},RedisDB.prototype.clear=function(){return this.db.unlink([this.id+"map"+this.field,this.id+"ctx"+this.field,this.id+"tag"+this.field,this.id+"cfg"+this.field,this.id+"doc",this.id+"reg"])};function create_result(a,b,c,d,e){if(c){if("number"===b)for(let c,e,f=0;f=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc","number"===this.type?a.map(a=>""+a):a).then(function(b){for(let c=0;ce,k.push(c+(f?d:e)+":"+(f?e:d)),l.push(1),e=d}else{const a=this.id+"map"+this.field+":";for(let c=0;cb,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file +import{SearchOptions,SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";import{create_object,is_object,sort_by_length_down}from"../common.js";import Index from"../index.js";import default_compress from"../compress.js";import Resolver from"../resolver.js";import{intersect}from"../intersect.js";import resolve_default from"../resolve/default.js";Index.prototype.search=function(a,b,c){if(c||(b||"object"!=typeof a?"object"==typeof b&&(c=b,b=0):(c=a,a="")),c&&c.cache){c.cache=!1;const d=this.searchCache(a,b,c);return c.cache=!0,d}let d,e,f,g,h,i,j,k,l=[],m=0;c&&(a=c.query||a,b=c.limit||b,m=c.offset||0,e=c.context,f=c.suggest,g=c.resolve,k=g&&c.enrich,i=c.boost,j=c.resolution,h=this.db&&c.tag),"undefined"==typeof g&&(g=this.resolve),e=this.depth&&!1!==e;let n=this.encoder.encode(a,!e);if(d=n.length,b=b||(g?100:0),1===d)return single_term_query.call(this,n[0],"",b,m,g,k,h);if(2===d&&e&&!f)return single_term_query.call(this,n[1],n[0],b,m,g,k,h);let o,p=create_object(),q=0;if(e&&(o=n[0],q=1),j||0===j||(j=o?this.resolution_ctx:this.resolution),this.db){if(this.db.search){const a=this.db.search(this,n,b,m,f,g,k,h);if(!1!==a)return a}const a=this;return async function(){for(let b,c;qb,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file diff --git a/dist/module/async.js b/dist/module/async.js index 88fdcec..2a028de 100644 --- a/dist/module/async.js +++ b/dist/module/async.js @@ -1,3 +1,4 @@ + import Document from "./document.js"; import Index from "./index.js"; import WorkerIndex from "./worker.js"; @@ -8,6 +9,8 @@ export default function (prototype) { register.call(prototype, "search"); register.call(prototype, "update"); register.call(prototype, "remove"); + + register.call(prototype, "searchCache"); } let timer, timestamp, cycle; diff --git a/dist/module/bundle.js b/dist/module/bundle.js index ef8d1c1..1319942 100644 --- a/dist/module/bundle.js +++ b/dist/module/bundle.js @@ -22,6 +22,7 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */Index.prototype.addAsync; /** @export */Index.prototype.appendAsync; /** @export */Index.prototype.searchAsync; +/** @export */Index.prototype.searchCacheAsync; /** @export */Index.prototype.updateAsync; /** @export */Index.prototype.removeAsync; /** @export */Index.prototype.export; @@ -66,6 +67,7 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */Document.prototype.addAsync; /** @export */Document.prototype.appendAsync; /** @export */Document.prototype.searchAsync; +/** @export */Document.prototype.searchCacheAsync; /** @export */Document.prototype.updateAsync; /** @export */Document.prototype.removeAsync; /** @export */Document.prototype.mount; @@ -217,6 +219,7 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */SearchOptions.suggest; /** @export */SearchOptions.resolve; /** @export */SearchOptions.enrich; +/** @export */SearchOptions.cache; /** @export */SearchOptions.resolution; /** @export */DocumentSearchOptions.query; @@ -224,7 +227,10 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */DocumentSearchOptions.offset; /** @export */DocumentSearchOptions.context; /** @export */DocumentSearchOptions.suggest; +/** @export */DocumentSearchOptions.resolve; /** @export */DocumentSearchOptions.enrich; +/** @export */DocumentSearchOptions.cache; +/** @export */DocumentSearchOptions.resolution; /** @export */DocumentSearchOptions.tag; /** @export */DocumentSearchOptions.field; /** @export */DocumentSearchOptions.index; diff --git a/dist/module/cache.js b/dist/module/cache.js index e8ba4af..789d1fd 100644 --- a/dist/module/cache.js +++ b/dist/module/cache.js @@ -12,7 +12,7 @@ import { SearchOptions, DocumentSearchOptions } from "./type.js"; export function searchCache(query_or_options, limit_or_options, options) { - const query = ("object" == typeof query_or_options ? "" + query_or_options.query : "" + query_or_options).toLowerCase(); + const query = (limit_or_options ? "" + query_or_options : "object" == typeof query_or_options ? "" + query_or_options.query : query_or_options).toLowerCase(); if (!this.cache) { this.cache = new CacheClass(); diff --git a/dist/module/db/redis/index.js b/dist/module/db/redis/index.js index 76be90f..96d59c0 100644 --- a/dist/module/db/redis/index.js +++ b/dist/module/db/redis/index.js @@ -36,8 +36,7 @@ export default function RedisDB(name, config = {}) { this.id = (name ? sanitize(name) : "flexsearch") + "|"; this.field = config.field ? "-" + sanitize(config.field) : ""; this.type = config.type || ""; - this.fastupdate = /* tag? */ /* stringify */ /* stringify */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ - /*await rows.hasNext()*/; + this.fastupdate = /* tag? */ /* stringify */ /* stringify */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; this.db = config.db || DB || null; this.support_tag_search = !0; this.resolution = 9; @@ -156,7 +155,7 @@ RedisDB.prototype.enrich = function (ids) { if ("object" != typeof ids) { ids = [ids]; } - return this.db.hmGet(this.id + "doc", ids).then(function (res) { + return this.db.hmGet(this.id + "doc", "number" === this.type ? ids.map(i => "" + i) : ids).then(function (res) { for (let i = 0; i < res.length; i++) { res[i] = { id: ids[i], @@ -384,7 +383,7 @@ RedisDB.prototype.commit = async function (flexsearch, _replace, _append) { const ref = this.id + "ctx" + this.field + ":" + ctx_key + ":" + key; trx.zAdd(ref, result); // if(this.fastupdate) for(let j = 0; j < ids.length; j++){ - + // trx.sAdd("ref" + this.field + ":" + ids[j], ref); // } if (this.fastupdate) for (let j = 0, id; j < ids.length; j++) { // Map performs bad when pushing numeric-like values as key diff --git a/dist/module/document/highlight.js b/dist/module/document/highlight.js index bb7757d..87d7e97 100644 --- a/dist/module/document/highlight.js +++ b/dist/module/document/highlight.js @@ -77,6 +77,7 @@ export function highlight_fields(query, result, index, pluck, config) { let res; if (pluck) { + //res = result[0].result; res = result; path = pluck; } else { diff --git a/dist/module/document/search.js b/dist/module/document/search.js index 9380fdf..bebd3e1 100644 --- a/dist/module/document/search.js +++ b/dist/module/document/search.js @@ -45,6 +45,13 @@ Document.prototype.search = function (query, limit, options, _promises) { } } + if (options && options.cache) { + options.cache = /* suggest */ /* append: */ /* enrich */!1; + const res = this.searchCache(query, limit, options); + options.cache = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; + return res; + } + /** @type { * DocumentSearchResults| * EnrichedDocumentSearchResults| @@ -63,8 +70,7 @@ 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 = !0, highlight; @@ -82,7 +88,7 @@ Document.prototype.search = function (query, limit, options, _promises) { field = pluck || options.field || (field = options.index) && (field.index ? null : field); tag = this.tag && options.tag; suggest = options.suggest; - resolve = /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + resolve = !1 !== options.resolve; // upgrade pluck when missing if (!resolve && !pluck) { @@ -100,7 +106,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } highlight = resolve && this.store && options.highlight; - enrich = highlight || resolve && this.store && options.enrich; + enrich = !!highlight || resolve && this.store && options.enrich; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -195,8 +201,11 @@ Document.prototype.search = function (query, limit, options, _promises) { } field || (field = this.field); - let promises = !_promises && (this.worker || this.db /*|| this.async*/) && [], - db_tag_search; + + let db_tag_search, + promises = (this.worker || this.db /*|| + (SUPPORT_ASYNC && this.async)*/ + ) && !_promises && []; // multi field search @@ -219,11 +228,11 @@ Document.prototype.search = function (query, limit, options, _promises) { field_options = key; key = field_options.field; query = field_options.query || query; - limit = field_options.limit || limit; - offset = field_options.offset || offset; - suggest = field_options.suggest || suggest; - enrich = this.store && (field_options.enrich || enrich); - highlight = enrich && (options.highlight || highlight); + limit = inherit(field_options.limit, limit); + offset = inherit(field_options.offset, offset); + suggest = inherit(field_options.suggest, suggest); + highlight = resolve && this.store && inherit(field_options.highlight, highlight); + enrich = !!highlight || resolve && this.store && inherit(field_options.enrich, enrich); } if (_promises) { @@ -280,7 +289,7 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } } @@ -294,7 +303,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } @@ -306,7 +315,7 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } } @@ -316,7 +325,7 @@ Document.prototype.search = function (query, limit, options, _promises) { len = res.length; if (!len && !suggest) { // nothing matched - return resolve ? res : new Resolver( /** @type {IntermediateSearchResults} */res); + return resolve || !!0 ? res : new Resolver( /** @type {IntermediateSearchResults} */res); } // move counter back by 1 count--; @@ -329,7 +338,7 @@ Document.prototype.search = function (query, limit, options, _promises) { count++; } else if (1 === field.length) { // fast path: nothing matched - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } @@ -345,7 +354,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } } @@ -363,7 +372,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (!count) { - return resolve ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result); } if (pluck && (!enrich || !this.store)) { return (/** @type {SearchResults} */result[0] @@ -391,7 +400,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (pluck) { - return resolve ? highlight ? highlight_fields( /** @type {string} */query, res, this.index, pluck, highlight) : /** @type {SearchResults|EnrichedSearchResults} */res : new Resolver( /** @type {IntermediateSearchResults} */res); + return resolve || !!0 ? highlight ? highlight_fields( /** @type {string} */query, res, this.index, pluck, highlight) : /** @type {SearchResults|EnrichedSearchResults} */res : new Resolver( /** @type {IntermediateSearchResults} */res); } result[i] = { @@ -413,6 +422,10 @@ 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; }; +function inherit(target_value, default_value) { + return "undefined" == typeof target_value ? default_value : target_value; +} + // 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/encoder.js b/dist/module/encoder.js index 1d51a96..da772a0 100644 --- a/dist/module/encoder.js +++ b/dist/module/encoder.js @@ -92,8 +92,7 @@ Encoder.prototype.assign = function (options) { * pre-processing string input * @type {Function|boolean} */ - this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ - /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ + this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize); // { diff --git a/dist/module/index/search.js b/dist/module/index/search.js index 4cf55bd..18dc573 100644 --- a/dist/module/index/search.js +++ b/dist/module/index/search.js @@ -8,12 +8,6 @@ import Resolver from "../resolver.js"; import { intersect } from "../intersect.js"; import resolve_default from "../resolve/default.js"; -// todo remove -// let global_resolve = 1; -// export function set_resolve(resolve){ -// global_resolve = resolve; -// } - /** * @param {string|SearchOptions} query * @param {number|SearchOptions=} limit @@ -35,6 +29,14 @@ Index.prototype.search = function (query, limit, options) { } } + if (options && options.cache) { + options.cache = /* suggest */ /* append: */ /* enrich */!1; + const res = this.searchCache(query, limit, options); + options.cache = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ + ; + return res; + } + /** @type {!Array} */ let result = [], length, @@ -57,14 +59,15 @@ Index.prototype.search = function (query, limit, options) { offset = options.offset || 0; context = options.context; suggest = options.suggest; - resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; - //resolve || (global_resolve = 0); + resolve = options.resolve; enrich = resolve && options.enrich; boost = options.boost; resolution = options.resolution; tag = this.db && options.tag; - } else { - resolve = this.resolve; // || global_resolve; + } + + if ("undefined" == typeof resolve) { + resolve = this.resolve; } context = this.depth && !1 !== context; diff --git a/dist/module/intersect.js b/dist/module/intersect.js index c64394e..8a1753f 100644 --- a/dist/module/intersect.js +++ b/dist/module/intersect.js @@ -119,6 +119,7 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res const final = []; for (let i = 0, arr; i < result.length; i++) { arr = result[i]; + //if(!arr) continue; if (arr.length > offset) { offset -= arr.length; continue; diff --git a/dist/module/resolver.js b/dist/module/resolver.js index 6fdd07f..2ba2b60 100644 --- a/dist/module/resolver.js +++ b/dist/module/resolver.js @@ -1,6 +1,5 @@ import Index from "./index.js"; import default_resolver from "./resolve/default.js"; -//import { set_resolve } from "./index/search.js"; import { apply_enrich } from "./document/search.js"; import { ResolverOptions, IntermediateSearchResults } from "./type.js"; import "./resolve/handler.js"; @@ -100,8 +99,6 @@ Resolver.prototype.boost = function (boost) { * @param {boolean=} enrich */ Resolver.prototype.resolve = function (limit, offset, enrich) { - - //set_resolve(1); const result = this.result, index = this.index; diff --git a/dist/module/type.js b/dist/module/type.js index f2c0217..5c1df48 100644 --- a/dist/module/type.js +++ b/dist/module/type.js @@ -125,6 +125,7 @@ export let StoreOptions = {}; * suggest: (boolean|undefined), * resolve: (boolean|undefined), * enrich: (boolean|undefined), + * cache: (boolean|undefined) * }} */ export let SearchOptions = {}; @@ -134,9 +135,12 @@ export let SearchOptions = {}; * query: (string|undefined), * limit: (number|undefined), * offset: (number|undefined), + * resolution: (number|undefined), * context: (boolean|undefined), * suggest: (boolean|undefined), + * resolve: (boolean|undefined), * enrich: (boolean|undefined), + * cache: (boolean|undefined), * tag: (Object|Array|undefined), * field: (Array|Array|DocumentSearchOptions|string|undefined), * index: (Array|Array|DocumentSearchOptions|string|undefined), diff --git a/index.d.ts b/index.d.ts index ef0994e..2bad641 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,7 +12,7 @@ declare module "flexsearch" { type Limit = number; type ExportHandler = (key: string, data: string) => void; type ExportHandlerAsync = (key: string, data: string) => Promise; - type AsyncCallback = (result?: T) => Promise; + type AsyncCallback = (result?: T) => void; /************************************/ /* Common Options */ @@ -82,6 +82,7 @@ declare module "flexsearch" { suggest?: boolean; resolution?: number; context?: boolean; + cache?: R extends true ? boolean : false; resolve?: R; }; @@ -154,7 +155,7 @@ declare module "flexsearch" { * * Language: https://github.com/nextapps-de/flexsearch/doc/encoder.md#built-in-language-packs */ export type IndexOptions< - S extends StorageInterface = undefined, + S extends StorageInterface | boolean = false, R extends boolean = true > = { preset?: Preset; @@ -190,7 +191,14 @@ declare module "flexsearch" { export type DefaultSearchResults = Id[]; export type IntermediateSearchResults = Array; - export type SearchResults = R extends true ? DefaultSearchResults : Resolver; + export type SearchResults< + W extends WorkerType = false, + S extends StorageInterface | boolean = false, + R extends boolean = true, + D extends DocumentData = undefined + > = R extends true + ? DefaultSearchResults + : Resolver; /** * Basic usage and variants: https://github.com/nextapps-de/flexsearch#basic-usage-and-variants \ @@ -199,21 +207,22 @@ declare module "flexsearch" { */ export type IndexSearchResultsWrapper< - W extends boolean = false, - S extends StorageInterface = undefined, + W extends WorkerType = false, + S extends StorageInterface | boolean = false, R extends boolean = true > = W extends false - ? S extends undefined - ? SearchResults - : Promise> - : Promise> + ? S extends false + ? SearchResults + : Promise> + : Promise> export class Index< - W extends boolean = false, - S extends StorageInterface = undefined, + W extends WorkerType = false, + S extends StorageInterface | boolean = false, r extends boolean = true > { constructor(options?: Preset | IndexOptions); + db: Promise; add(id: Id, content: string): this | Promise; @@ -226,20 +235,19 @@ declare module "flexsearch" { remove(id: Id): this | Promise; + search(query: string): IndexSearchResultsWrapper; /** @deprecated Pass "limit" within options */ - search(query: string, limit?: Limit): IndexSearchResultsWrapper; - /** @deprecated Pass "limit" within options */ + search(query: string, limit: Limit, options?: SearchOptions): IndexSearchResultsWrapper; search(query: string, options?: SearchOptions): IndexSearchResultsWrapper; - /** @deprecated Pass "limit" within options */ - search(query: string, limit: Limit, options: SearchOptions): IndexSearchResultsWrapper; search(options: SearchOptions): IndexSearchResultsWrapper; + searchCache(query: string): IndexSearchResultsWrapper; /** @deprecated Pass "limit" within options */ - searchCache(query: string, limit?: Limit): W extends false ? SearchResults : Promise; - searchCache(query: string, options?: SearchOptions): IndexSearchResultsWrapper; + searchCache(query: string, limit: Limit): IndexSearchResultsWrapper; /** @deprecated Pass "limit" within options */ - searchCache(query: string, limit: Limit, options: SearchOptions): IndexSearchResultsWrapper; - searchCache(options: SearchOptions): IndexSearchResultsWrapper; + searchCache(query: string, limit: Limit, options?: SearchOptions): IndexSearchResultsWrapper; + searchCache(query: string, options?: SearchOptions): IndexSearchResultsWrapper; + searchCache(options: SearchOptions): IndexSearchResultsWrapper; // https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids contain(id: Id): boolean | Promise; @@ -285,35 +293,65 @@ declare module "flexsearch" { removeAsync( id: Id, - callback?: AsyncCallback, + callback?: AsyncCallback ): Promise; searchAsync( query: string, - callback?: AsyncCallback, - ): Promise + callback?: AsyncCallback> + ): Promise>; + searchCacheAsync( + query: string, + callback?: AsyncCallback> + ): Promise>; + /** @deprecated Pass "limit" within options */ searchAsync( query: string, - limit?: Limit, - callback?: AsyncCallback, - ): Promise - searchAsync( + limit: Limit, + callback?: AsyncCallback> + ): Promise>; + /** @deprecated Pass "limit" within options */ + searchCacheAsync( query: string, - options?: SearchOptions, - callback?: AsyncCallback>, - ): Promise> + limit: Limit, + callback?: AsyncCallback> + ): Promise>; + /** @deprecated Pass "limit" within options */ searchAsync( query: string, limit: Limit, options?: SearchOptions, - callback?: AsyncCallback>, - ): Promise>; + callback?: AsyncCallback> + ): Promise>; + /** @deprecated Pass "limit" within options */ + searchCacheAsync( + query: string, + limit: Limit, + options?: SearchOptions, + callback?: AsyncCallback> + ): Promise>; + + searchAsync( + query: string, + options?: SearchOptions, + callback?: AsyncCallback> + ): Promise>; + searchCacheAsync( + query: string, + options?: SearchOptions, + callback?: AsyncCallback> + ): Promise>; + searchAsync( options: SearchOptions, - callback?: AsyncCallback>, - ): Promise>; + callback?: AsyncCallback> + ): Promise>; + searchCacheAsync( + options: SearchOptions, + callback?: AsyncCallback> + ): Promise>; } /************************************/ @@ -347,11 +385,13 @@ declare module "flexsearch" { /* Document Search */ /************************************/ + type CustomFN = (doc: D) => string | boolean; + /** * The template to be applied on matches (e.g. "\$1\"), where \$1 is a placeholder for the matched partial */ export type TemplateResultHighlighting = string; - type TagName = string; + export type TagName = string; export type FieldName = D extends object ? { [K in keyof D]: K extends string @@ -359,30 +399,26 @@ declare module "flexsearch" { ? `${ K }` | `${ K }[]:${ FieldName & string }` : K | `${ K }:${ FieldName & string }` : never - }[keyof D] + }[keyof D] : never; - export type FieldOptions = IndexOptions & { - field: FieldName, - filter?: (content: string) => boolean; - custom?: (content: string) => string | boolean; + export type DefaultFieldOptions< + D = DocumentData, + C extends CustomFN | boolean = false + > = IndexOptions & { + custom?: C; + field: C extends false ? FieldName : FieldName; + filter?: (doc: D) => boolean; + db?: StorageInterface; + }; + + export type FieldOptions = IndexOptions & DefaultFieldOptions & { config?: WorkerConfigURL | WorkerConfigPath; - db?: StorageInterface; }; - export type TagOptions = { - field: FieldName; - filter?: (content: string) => boolean; - custom?: (content: string) => string | boolean; - db?: StorageInterface; - }; + export type TagOptions = DefaultFieldOptions; - export type StoreOptions = { - field: FieldName; - filter?: (content: string) => boolean; - custom?: (content: string) => string | boolean; - db?: StorageInterface; - }; + export type StoreOptions = DefaultFieldOptions; /** * # Document Search Result @@ -402,7 +438,7 @@ declare module "flexsearch" { export type DocumentOptions< D extends DocumentData = DocumentData, W extends WorkerType = false, - S extends StorageInterface = undefined + S extends StorageInterface | boolean = false > = IndexOptions & DocumentDescriptor & { worker?: W; doc?: DocumentDescriptor; @@ -418,7 +454,7 @@ declare module "flexsearch" { field?: FieldName | FieldName[] | FieldOptions | Array>; index?: FieldName | FieldName[] | FieldOptions | Array>; tag?: FieldName | FieldName[] | TagOptions | Array>; - store?: FieldName | FieldName[] | StoreOptions | Array | boolean; + store?: FieldName | FieldName[] | StoreOptions | Array> | boolean; }; export type DefaultDocumentSearchResults = Array<{ @@ -442,54 +478,54 @@ declare module "flexsearch" { export type MergedDocumentSearchResults = Array<{ id: Id; doc?: D | null; - field?: FieldName[]; - tag?: FieldName[]; + field?: FieldName[]; + tag?: FieldName[]; highlight?: {[field: FieldName]: string}; }>; + export type PluckOptions< + D extends DocumentData = DocumentData, + H extends HighlightOptions | boolean = false, + R extends boolean = true, + E extends boolean = false + > = FieldName | DocumentSearchOptions; + export type DocumentSearchResults< D extends DocumentData = DocumentData, - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false > = R extends true - ? P extends PluckOptions - ? E extends true - ? EnrichedResults - : DefaultSearchResults - : M extends true + ? P extends false + ? M extends true ? MergedDocumentSearchResults : E extends true ? EnrichedDocumentSearchResults - : H extends HighlightOptions - ? EnrichedDocumentSearchResults - : DefaultDocumentSearchResults + : H extends false + ? DefaultDocumentSearchResults + : EnrichedDocumentSearchResults + : E extends true + ? EnrichedResults + : DefaultSearchResults : Resolver; - export type PluckOptions< - D extends DocumentData = DocumentData, - H extends HighlightOptions = undefined, - R extends boolean = true, - E extends boolean = false - > = FieldName | DocumentSearchOptions; - /** * **Document:** * * Document search options: https://github.com/nextapps-de/flexsearch#document-search-options */ export type DocumentSearchOptions< D extends DocumentData = DocumentData, - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false, > = SearchOptions & { tag?: {[field: FieldName]: TagName} | Array<{[field: FieldName]: TagName}>; - field?: Array> | DocumentSearchOptions | FieldName[] | FieldName; - index?: Array> | DocumentSearchOptions | FieldName[] | FieldName; + field?: Array> | DocumentSearchOptions | FieldName[] | FieldName; + index?: Array> | DocumentSearchOptions | FieldName[] | FieldName; pluck?: P; highlight?: H; enrich?: E; @@ -510,14 +546,14 @@ declare module "flexsearch" { export type DocumentSearchResultsWrapper< D extends DocumentData = DocumentData, W extends WorkerType = false, - S extends StorageInterface = undefined, - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + S extends StorageInterface | boolean = false, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false > = W extends false - ? S extends undefined + ? S extends false ? DocumentSearchResults : Promise> : Promise> @@ -530,7 +566,7 @@ declare module "flexsearch" { export class Document< D extends DocumentData = DocumentData, W extends WorkerType = false, - S extends StorageInterface = undefined + S extends StorageInterface | boolean = false > { constructor(options: DocumentOptions); @@ -565,14 +601,16 @@ declare module "flexsearch" { : this; // https://github.com/nextapps-de/flexsearch#field-search + search(query: string): DocumentSearchResultsWrapper; + searchCache(query: string): DocumentSearchResultsWrapper; /** @deprecated Pass "limit" within options */ search(query: string, limit: Limit): DocumentSearchResultsWrapper; /** @deprecated Pass "limit" within options */ searchCache(query: string, limit: Limit): DocumentSearchResultsWrapper; search< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -581,8 +619,8 @@ declare module "flexsearch" { options: DocumentSearchOptions, ): DocumentSearchResultsWrapper; searchCache< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -593,8 +631,8 @@ declare module "flexsearch" { /** @deprecated Pass "limit" within options */ search< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -605,8 +643,8 @@ declare module "flexsearch" { ): DocumentSearchResultsWrapper; /** @deprecated Pass "limit" within options */ searchCache< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -617,8 +655,8 @@ declare module "flexsearch" { ): DocumentSearchResultsWrapper; search< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -626,8 +664,8 @@ declare module "flexsearch" { options: DocumentSearchOptions, ): DocumentSearchResultsWrapper; searchCache< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -635,7 +673,6 @@ declare module "flexsearch" { options: DocumentSearchOptions, ): DocumentSearchResultsWrapper; - // https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids contain(id: Id): D extends StorageInterface ? Promise @@ -711,12 +748,19 @@ declare module "flexsearch" { callback?: AsyncCallback, ): Promise; - /** @deprecated Pass "limit" within options */ - searchAsync(query: string, limit?: Limit): Promise> - searchAsync< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, + R extends boolean = true, + E extends boolean = false, + M extends boolean = false + >( + query: string, + callback?: AsyncCallback>, + ): Promise> + searchCacheAsync< + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -725,22 +769,48 @@ declare module "flexsearch" { callback?: AsyncCallback>, ): Promise> + /** @deprecated Pass "limit" within options */ searchAsync< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false >( query: string, + limit: Limit, + callback?: AsyncCallback>, + ): Promise> + /** @deprecated Pass "limit" within options */ + searchCacheAsync< + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, + R extends boolean = true, + E extends boolean = false, + M extends boolean = false + >( + query: string, + limit: Limit, + callback?: AsyncCallback>, + ): Promise> + + /** @deprecated Pass "limit" within options */ + searchAsync< + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, + R extends boolean = true, + E extends boolean = false, + M extends boolean = false + >( + query: string, + limit: Limit, options?: DocumentSearchOptions, callback?: AsyncCallback>, - ): Promise> - + ): Promise>; /** @deprecated Pass "limit" within options */ - searchAsync< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + searchCacheAsync< + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -752,8 +822,41 @@ declare module "flexsearch" { ): Promise>; searchAsync< - H extends HighlightOptions = undefined, - P extends PluckOptions = undefined, + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, + R extends boolean = true, + E extends boolean = false, + M extends boolean = false + >( + query: string, + options?: DocumentSearchOptions, + callback?: AsyncCallback>, + ): Promise> + searchCacheAsync< + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, + R extends boolean = true, + E extends boolean = false, + M extends boolean = false + >( + query: string, + options?: DocumentSearchOptions, + callback?: AsyncCallback>, + ): Promise> + + searchAsync< + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, + R extends boolean = true, + E extends boolean = false, + M extends boolean = false + >( + options: DocumentSearchOptions, + callback?: AsyncCallback>, + ): Promise>; + searchCacheAsync< + H extends HighlightOptions | boolean = false, + P extends PluckOptions | boolean = false, R extends boolean = true, E extends boolean = false, M extends boolean = false @@ -792,30 +895,36 @@ declare module "flexsearch" { }; export type DefaultResolve< - D extends DocumentData = DocumentData, - H extends HighlightOptions = undefined, + D extends DocumentData = undefined, + H extends HighlightOptions | boolean = false, + R extends boolean = true, E extends boolean = false > = { limit?: number; offset?: number; + resolve?: R; /** only usable when "resolve" was not set to false */ - enrich?: D extends DocumentData ? E : undefined; + enrich?: D extends DocumentData + ? R extends true ? E : false + : false; /** only usable when "resolve" was not set to false */ - highlight?: D extends DocumentData ? H : undefined; + highlight?: D extends DocumentData + ? R extends true ? H : false + : false; }; export type ResolverOptions< - D extends DocumentData = DocumentData, + D extends DocumentData = undefined, W extends WorkerType = false, - S extends StorageInterface = undefined, - H extends HighlightOptions = undefined, - R extends boolean = true, + S extends StorageInterface | boolean = false, + H extends HighlightOptions | boolean = false, + R extends boolean = false, E extends boolean = false - > = DefaultResolve & { + > = DefaultResolve & { query?: string; - index?: Index | Document; - pluck?: FieldName; - field?: FieldName; + index?: Index | Document; + pluck?: FieldName; + field?: FieldName; tag?: {[field: FieldName]: TagName} | Array<{[field: FieldName]: TagName}>; and?: ResolverOptions | Array>; or?: ResolverOptions | Array>; @@ -823,7 +932,6 @@ declare module "flexsearch" { not?: ResolverOptions | Array>; boost?: number; suggest?: boolean; - resolve?: R; }; export type HighlightBoundaryOptions = { @@ -863,26 +971,34 @@ declare module "flexsearch" { addReplacer(match: string | RegExp, replace: string): this; } - export class Resolver { + export class Resolver< + D extends DocumentData = undefined, + W extends WorkerType = false, + S extends StorageInterface | boolean = false + > { result: IntermediateSearchResults; - constructor(options?: ResolverOptions | IntermediateSearchResults); + constructor(options?: ResolverOptions | IntermediateSearchResults); - and(options: ResolverOptions): this; + and(...args: ResolverOptions[]): + SearchResults; - or(options: ResolverOptions): this; + or(...args: ResolverOptions[]): + SearchResults; - xor(options: ResolverOptions): this; + xor(...args: ResolverOptions[]): + SearchResults; - not(options: ResolverOptions): this; + not(...args: ResolverOptions[]): + SearchResults; - limit(limit: number): this; + limit(limit: number): Resolver; - offset(offset: number): this; + offset(offset: number): Resolver; - boost(boost: number): this; + boost(boost: number): Resolver; - resolve(options?: DefaultResolve): SearchResults; + resolve(options?: DefaultResolve): SearchResults; } export class StorageInterface { @@ -903,7 +1019,7 @@ declare module "flexsearch" { } export class IndexedDB extends StorageInterface { - db: IDBDatabase; + /*db: IDBDatabase;*/ } const FlexSearch: { @@ -926,12 +1042,12 @@ declare module "flexsearch/db/*" { export default StorageInterface; } -declare module "flexsearch/db/indexeddb" { - import { StorageInterface } from "flexsearch"; - export default class IndexedDB extends StorageInterface{ - db: IDBDatabase - } -} +// declare module "flexsearch/db/indexeddb" { +// import { StorageInterface } from "flexsearch"; +// export default class IndexedDB extends StorageInterface{ +// db: IDBDatabase; +// } +// } // ----------------------------------- diff --git a/package-lock.json b/package-lock.json index 90d9e13..7b99574 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.160", + "version": "0.8.161", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.160", + "version": "0.8.161", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 81dd7a4..09627a6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.160", + "version": "0.8.161", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/src/async.js b/src/async.js index fa2b7b3..3d2f46d 100644 --- a/src/async.js +++ b/src/async.js @@ -1,3 +1,6 @@ +// COMPILER BLOCK --> +import { SUPPORT_CACHE } from "./config.js"; +// <-- COMPILER BLOCK import Document from "./document.js"; import Index from "./index.js"; import WorkerIndex from "./worker.js"; @@ -8,6 +11,9 @@ export default function(prototype){ register.call(prototype, "search"); register.call(prototype, "update"); register.call(prototype, "remove"); + if(SUPPORT_CACHE){ + register.call(prototype, "searchCache"); + } } let timer; diff --git a/src/bundle.js b/src/bundle.js index 53d57ea..c8cdaaf 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -50,6 +50,7 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */ Index.prototype.addAsync; /** @export */ Index.prototype.appendAsync; /** @export */ Index.prototype.searchAsync; +/** @export */ Index.prototype.searchCacheAsync; /** @export */ Index.prototype.updateAsync; /** @export */ Index.prototype.removeAsync; /** @export */ Index.prototype.export; @@ -98,6 +99,7 @@ if(SUPPORT_PERSISTENT){ /** @export */ Document.prototype.addAsync; /** @export */ Document.prototype.appendAsync; /** @export */ Document.prototype.searchAsync; +/** @export */ Document.prototype.searchCacheAsync; /** @export */ Document.prototype.updateAsync; /** @export */ Document.prototype.removeAsync; /** @export */ Document.prototype.mount; @@ -251,6 +253,7 @@ if(SUPPORT_SERIALIZE){ /** @export */ SearchOptions.suggest; /** @export */ SearchOptions.resolve; /** @export */ SearchOptions.enrich; +/** @export */ SearchOptions.cache; /** @export */ SearchOptions.resolution; /** @export */ DocumentSearchOptions.query; @@ -258,7 +261,10 @@ if(SUPPORT_SERIALIZE){ /** @export */ DocumentSearchOptions.offset; /** @export */ DocumentSearchOptions.context; /** @export */ DocumentSearchOptions.suggest; +/** @export */ DocumentSearchOptions.resolve; /** @export */ DocumentSearchOptions.enrich; +/** @export */ DocumentSearchOptions.cache; +/** @export */ DocumentSearchOptions.resolution; /** @export */ DocumentSearchOptions.tag; /** @export */ DocumentSearchOptions.field; /** @export */ DocumentSearchOptions.index; diff --git a/src/cache.js b/src/cache.js index 758f4ff..7070922 100644 --- a/src/cache.js +++ b/src/cache.js @@ -12,9 +12,11 @@ import { SearchOptions, DocumentSearchOptions } from "./type.js"; export function searchCache(query_or_options, limit_or_options, options){ - const query = (typeof query_or_options === "object" - ? "" + query_or_options.query - : "" + query_or_options + const query = (limit_or_options + ? "" + query_or_options + : typeof query_or_options === "object" + ? "" + query_or_options.query + : query_or_options ).toLowerCase(); if(!this.cache){ diff --git a/src/db/redis/index.js b/src/db/redis/index.js index c7bfd3a..2cccad8 100644 --- a/src/db/redis/index.js +++ b/src/db/redis/index.js @@ -185,7 +185,7 @@ RedisDB.prototype.enrich = function(ids){ if(typeof ids !== "object"){ ids = [ids]; } - return this.db.hmGet(this.id + "doc", ids).then(function(res){ + return this.db.hmGet(this.id + "doc", this.type === "number" ? ids.map(i => "" + i) : ids).then(function(res){ for(let i = 0; i < res.length; i++){ res[i] = { id: ids[i], diff --git a/src/document/highlight.js b/src/document/highlight.js index e81cd1b..751e344 100644 --- a/src/document/highlight.js +++ b/src/document/highlight.js @@ -94,6 +94,7 @@ export function highlight_fields(query, result, index, pluck, config){ let res; if(pluck){ + //res = result[0].result; res = result; path = pluck; } diff --git a/src/document/search.js b/src/document/search.js index 58c7487..62ed71a 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -1,12 +1,14 @@ // COMPILER BLOCK --> import { DEBUG, - PROFILER, SUPPORT_HIGHLIGHTING, + PROFILER, SUPPORT_ASYNC, SUPPORT_CACHE, + SUPPORT_HIGHLIGHTING, SUPPORT_PERSISTENT, SUPPORT_RESOLVER, SUPPORT_STORE, SUPPORT_SUGGESTION, - SUPPORT_TAGS + SUPPORT_TAGS, + SUPPORT_WORKER } from "../config.js"; // <-- COMPILER BLOCK import { @@ -67,6 +69,13 @@ Document.prototype.search = function(query, limit, options, _promises){ } } + if(SUPPORT_CACHE && options && options.cache){ + options.cache = false; + const res = this.searchCache(query, limit, options); + options.cache = true; + return res; + } + /** @type { * DocumentSearchResults| * EnrichedDocumentSearchResults| @@ -116,13 +125,16 @@ Document.prototype.search = function(query, limit, options, _promises){ } if(DEBUG){ - if(SUPPORT_STORE && this.store && options.enrich && !resolve){ + if(SUPPORT_STORE && this.store && options.highlight && !resolve){ + console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })"); + } + else if(SUPPORT_STORE && this.store && options.enrich && !resolve){ console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); } } highlight = SUPPORT_STORE && SUPPORT_HIGHLIGHTING && resolve && this.store && options.highlight; - enrich = SUPPORT_STORE && (highlight || (resolve && this.store && options.enrich)); + enrich = SUPPORT_STORE && (!!highlight || (resolve && this.store && options.enrich)); limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -232,8 +244,13 @@ Document.prototype.search = function(query, limit, options, _promises){ } field || (field = this.field); - let promises = !_promises && (this.worker || this.db /*|| this.async*/) && []; + let db_tag_search; + let promises = ( + (SUPPORT_WORKER && this.worker) || + (SUPPORT_PERSISTENT && this.db) /*|| + (SUPPORT_ASYNC && this.async)*/ + ) && !_promises && []; // multi field search // field could be a custom set of selected fields by this query @@ -255,11 +272,11 @@ Document.prototype.search = function(query, limit, options, _promises){ field_options = key; key = field_options.field; query = field_options.query || query; - limit = field_options.limit || limit; - 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); + limit = inherit(field_options.limit, limit); + offset = inherit(field_options.offset, offset); + suggest = SUPPORT_SUGGESTION && inherit(field_options.suggest, suggest); + highlight = SUPPORT_STORE && SUPPORT_HIGHLIGHTING && resolve && this.store && inherit(field_options.highlight, highlight); + enrich = SUPPORT_STORE && (!!highlight || (resolve && this.store && inherit(field_options.enrich, enrich))); } if(_promises){ @@ -319,7 +336,7 @@ Document.prototype.search = function(query, limit, options, _promises){ } else if(!suggest){ // no tags found - return resolve + return resolve || !SUPPORT_RESOLVER ? result : new Resolver(result) } @@ -342,7 +359,7 @@ Document.prototype.search = function(query, limit, options, _promises){ continue; } else{ - return resolve + return resolve || !SUPPORT_RESOLVER ? result : new Resolver(result) } @@ -357,7 +374,7 @@ Document.prototype.search = function(query, limit, options, _promises){ } else if(!suggest){ // no tags found - return resolve + return resolve || !SUPPORT_RESOLVER ? result : new Resolver(result) } @@ -370,7 +387,7 @@ Document.prototype.search = function(query, limit, options, _promises){ len = res.length; if(!len && !suggest){ // nothing matched - return resolve + return resolve || !SUPPORT_RESOLVER ? res : new Resolver(/** @type {IntermediateSearchResults} */ (res)); } @@ -386,7 +403,7 @@ Document.prototype.search = function(query, limit, options, _promises){ } else if(field.length === 1){ // fast path: nothing matched - return resolve + return resolve || !SUPPORT_RESOLVER ? result : new Resolver(result); } @@ -408,7 +425,7 @@ Document.prototype.search = function(query, limit, options, _promises){ continue; } else{ - return resolve + return resolve || !SUPPORT_RESOLVER ? result : new Resolver(result); } @@ -430,7 +447,7 @@ Document.prototype.search = function(query, limit, options, _promises){ } if(!count){ - return resolve + return resolve || !SUPPORT_RESOLVER ? result : new Resolver(result); } @@ -460,7 +477,7 @@ Document.prototype.search = function(query, limit, options, _promises){ } if(pluck){ - return resolve + return resolve || !SUPPORT_RESOLVER ? (highlight ? highlight_fields(/** @type {string} */ (query), res, this.index, pluck, highlight) : /** @type {SearchResults|EnrichedSearchResults} */ (res)) @@ -498,6 +515,12 @@ Document.prototype.search = function(query, limit, options, _promises){ ); } +function inherit(target_value, default_value){ + return typeof target_value === "undefined" + ? default_value + : target_value; +} + // 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 b3a8dd2..eefb476 100644 --- a/src/index.js +++ b/src/index.js @@ -161,7 +161,7 @@ if(SUPPORT_PERSISTENT){ this.commit_timer = null; } return this.db.destroy(); - } + }; } /** diff --git a/src/index/search.js b/src/index/search.js index 622cfc1..8b54608 100644 --- a/src/index/search.js +++ b/src/index/search.js @@ -18,12 +18,6 @@ import Resolver from "../resolver.js"; import { intersect } from "../intersect.js"; import resolve_default from "../resolve/default.js"; -// todo remove -// let global_resolve = 1; -// export function set_resolve(resolve){ -// global_resolve = resolve; -// } - /** * @param {string|SearchOptions} query * @param {number|SearchOptions=} limit @@ -46,6 +40,13 @@ Index.prototype.search = function(query, limit, options){ } } + if(SUPPORT_CACHE && options && options.cache){ + options.cache = false; + const res = this.searchCache(query, limit, options); + options.cache = true; + return res; + } + /** @type {!Array} */ let result = []; let length; @@ -66,15 +67,15 @@ Index.prototype.search = function(query, limit, options){ offset = options.offset || 0; context = options.context; suggest = SUPPORT_SUGGESTION && options.suggest; - resolve = !SUPPORT_RESOLVER || (/*global_resolve &&*/ options.resolve !== false); - //resolve || (global_resolve = 0); + resolve = !SUPPORT_RESOLVER || options.resolve; enrich = resolve && options.enrich; - boost = options.boost; + boost = SUPPORT_DOCUMENT && options.boost; resolution = options.resolution; - tag = SUPPORT_PERSISTENT && SUPPORT_DOCUMENT && SUPPORT_TAGS && this.db && options.tag; + tag = SUPPORT_DOCUMENT && SUPPORT_TAGS && SUPPORT_PERSISTENT && this.db && options.tag; } - else{ - resolve = !SUPPORT_RESOLVER || this.resolve; // || global_resolve; + + if(typeof resolve === "undefined"){ + resolve = !SUPPORT_RESOLVER || this.resolve; } context = this.depth && context !== false; diff --git a/src/intersect.js b/src/intersect.js index bc7db6e..218901f 100644 --- a/src/intersect.js +++ b/src/intersect.js @@ -126,6 +126,7 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res const final = []; for(let i = 0, arr; i < result.length; i++){ arr = result[i]; + //if(!arr) continue; if(arr.length > offset){ offset -= arr.length; continue; diff --git a/src/resolver.js b/src/resolver.js index 1317d33..8bfbdb4 100644 --- a/src/resolver.js +++ b/src/resolver.js @@ -1,6 +1,5 @@ import Index from "./index.js"; import default_resolver from "./resolve/default.js"; -//import { set_resolve } from "./index/search.js"; import { apply_enrich } from "./document/search.js"; import { ResolverOptions, IntermediateSearchResults } from "./type.js"; import "./resolve/handler.js"; @@ -9,7 +8,6 @@ import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; - /** * @param {IntermediateSearchResults|ResolverOptions=} result * @return {Resolver} @@ -104,7 +102,6 @@ Resolver.prototype.boost = function(boost){ */ Resolver.prototype.resolve = function(limit, offset, enrich){ - //set_resolve(1); const result = this.result; const index = this.index; this.index = null; diff --git a/src/type.js b/src/type.js index 856983c..a7dd737 100644 --- a/src/type.js +++ b/src/type.js @@ -125,6 +125,7 @@ export let StoreOptions = {}; * suggest: (boolean|undefined), * resolve: (boolean|undefined), * enrich: (boolean|undefined), + * cache: (boolean|undefined) * }} */ export let SearchOptions = {}; @@ -134,9 +135,12 @@ export let SearchOptions = {}; * query: (string|undefined), * limit: (number|undefined), * offset: (number|undefined), + * resolution: (number|undefined), * context: (boolean|undefined), * suggest: (boolean|undefined), + * resolve: (boolean|undefined), * enrich: (boolean|undefined), + * cache: (boolean|undefined), * tag: (Object|Array|undefined), * field: (Array|Array|DocumentSearchOptions|string|undefined), * index: (Array|Array|DocumentSearchOptions|string|undefined), diff --git a/test/package-lock.json b/test/package-lock.json index 33512d5..41a746d 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -15,7 +15,8 @@ "pg-promise": "^11.10.2", "redis": "^4.7.0", "rollup": "^4.35.0", - "sqlite3": "^5.1.7" + "sqlite3": "^5.1.7", + "typescript": "^5.8.3" } }, "node_modules/@bcoe/v8-coverage": { @@ -3861,6 +3862,19 @@ "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==", "dev": true }, + "node_modules/typescript": { + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/unique-filename": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", diff --git a/test/package.json b/test/package.json index 33aa577..d8da6b1 100644 --- a/test/package.json +++ b/test/package.json @@ -3,22 +3,24 @@ "type": "module", "scripts": { "test": "mocha ./*.js --exit", - "test:github": "mocha async.js --exit flexsearch.compact.min", + "test:ts": "npx tsc --noEmit --lib esnext ./types.ts", + "test:github": "npm run test:ts && mocha async.js --exit flexsearch.compact.min", "test:coverage": "c8 -c ./.c8rc.json mocha ./*.js --exit", "test:keystore": "set NODE_OPTIONS=--max-old-space-size=16000 && c8 -c ./.c8rc.json mocha ./keystore.js --exit", "test:db": "c8 -c ./.c8rc.json mocha ./persistent.*.js --exit", - "test:all": "npx mocha ./*.js --exit module/bundle && npx mocha ./*.js --exit module-debug/bundle && npx mocha ./*.js --exit module-min/bundle && npx mocha ./*.js --exit flexsearch.bundle.debug && npx mocha ./*.js --exit flexsearch.bundle.min && npx mocha ./*.js --exit flexsearch.bundle.module.debug && npx mocha ./*.js --exit flexsearch.bundle.module.min && npx mocha ./*.js --exit flexsearch.compact.debug && npx mocha ./*.js --exit flexsearch.compact.min && npx mocha ./*.js --exit flexsearch.compact.module.debug && npx mocha ./*.js --exit flexsearch.compact.module.min && npx mocha ./*.js --exit flexsearch.es5.debug && npx mocha ./*.js --exit flexsearch.es5.min && npx mocha ./*.js --exit flexsearch.light.debug && npx mocha ./*.js --exit flexsearch.light.min && npx mocha ./*.js --exit flexsearch.light.module.debug && npx mocha ./*.js --exit flexsearch.light.module.min" + "test:all": "npm run test:ts && npx mocha ./*.js --exit module/bundle && npx mocha ./*.js --exit module-debug/bundle && npx mocha ./*.js --exit module-min/bundle && npx mocha ./*.js --exit flexsearch.bundle.debug && npx mocha ./*.js --exit flexsearch.bundle.min && npx mocha ./*.js --exit flexsearch.bundle.module.debug && npx mocha ./*.js --exit flexsearch.bundle.module.min && npx mocha ./*.js --exit flexsearch.compact.debug && npx mocha ./*.js --exit flexsearch.compact.min && npx mocha ./*.js --exit flexsearch.compact.module.debug && npx mocha ./*.js --exit flexsearch.compact.module.min && npx mocha ./*.js --exit flexsearch.es5.debug && npx mocha ./*.js --exit flexsearch.es5.min && npx mocha ./*.js --exit flexsearch.light.debug && npx mocha ./*.js --exit flexsearch.light.min && npx mocha ./*.js --exit flexsearch.light.module.debug && npx mocha ./*.js --exit flexsearch.light.module.min" }, "devDependencies": { "c8": "^10.1.3", "chai": "^5.2.0", - "mocha": "^11.1.0", + "clickhouse": "^2.6.0", "flexsearch": "^0.8.117", + "mocha": "^11.1.0", + "mongodb": "^6.13.0", "pg-promise": "^11.10.2", "redis": "^4.7.0", - "mongodb": "^6.13.0", "rollup": "^4.35.0", "sqlite3": "^5.1.7", - "clickhouse": "^2.6.0" + "typescript": "^5.8.3" } } diff --git a/test/persistent.js b/test/persistent.js index 19720a6..91b6f52 100644 --- a/test/persistent.js +++ b/test/persistent.js @@ -428,8 +428,6 @@ export default function(DB, DBClass){ 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 highlight: "$1" @@ -449,8 +447,6 @@ export default function(DB, DBClass){ 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 highlight: "$1" @@ -470,15 +466,13 @@ export default function(DB, DBClass){ result = await index.search({ query: "karmen or clown or not found", suggest: true, - // set enrich to true (required) - enrich: true, - pluck: "title", + field: "title", // highlight template // $1 is a placeholder for the matched partial highlight: "$1" }); - expect(result).to.eql([{ + expect(result[0].result).to.eql([{ id: 1, doc: data[0], highlight: 'Carmencita' diff --git a/test/types.ts b/test/types.ts index 2079ca4..347811d 100644 --- a/test/types.ts +++ b/test/types.ts @@ -1,14 +1,88 @@ import { - DefaultDocumentSearchResults, Document, Index, Worker, Resolver, + IndexedDB +} from "flexsearch"; +import { + DefaultDocumentSearchResults, StorageInterface, DefaultSearchResults, + EnrichedDocumentSearchResults, + MergedDocumentSearchResults, + DocumentData } from "flexsearch"; -async function test() { +async function test_index() { + + const index = new Index(); + const index2 = new Index({ resolve: false }); + const index3 = new Index({ db: new IndexedDB("my-store") }); + + const idx1: DefaultSearchResults = index.search({ cache: true }); + const idx2: Promise = index.searchAsync({ cache: true }); + const idx3: Resolver = index.search({ resolve: false }); + const idx4: Resolver = index2.search({}); + const idx5: Resolver = idx3.and({}, {}).limit(100).or({}, {}).boost(2).xor({}, { resolve: false }).not({}, {}).offset(10); + const idx6: DefaultSearchResults = idx5.resolve({ limit: 10, offset: 2 }); + const idx7: DefaultSearchResults = idx5.and({}, { resolve: true }); + const idx8: DefaultSearchResults = index.searchCache({}); + const idx9: Promise = index.searchCacheAsync({}); + + const db1: Promise = index3.db; + const db2: IndexedDB = await index3.db; + const idx10: Promise = index3.search({ cache: true }); + const idx11: Promise = index3.searchAsync({ cache: true }, function(res: DefaultSearchResults){}); + const idx12: Promise = index3.commit(); + const idx13: Promise = index3.mount(db2); + const idx14: Promise = index3.searchCache({}); + const idx15: Promise = index3.searchCacheAsync({}); + const idx16: Promise = index3.search({ resolve: true, cache: true }); + const idx17: Promise = index3.searchAsync({ resolve: true, cache: true }); + const idx18: Resolver = index2.searchCache({}); + const idx19: Promise = index2.searchCacheAsync({}); + + const res1: Resolver = new Resolver({ index }); + const res2: Resolver = res1.and({ index }).limit(100); + const res3: DefaultSearchResults = res2.resolve(); + + // @ts-expect-error + const idx_err1 = index.search({ highlight: true }); + // @ts-expect-error + const idx_err2 = index.search({ pluck: true }); + // @ts-expect-error + const idx_err3 = index.search({ enrich: true }); + // @ts-expect-error + const idx_err4 = index.search({ merge: true }); + // @ts-expect-error + const index4 = new Index({ document: {} }); + // @ts-expect-error + const index5 = new Index({ worker: true }); + + // @ts-expect-error + const idx_err5: DefaultSearchResults = idx5.resolve({}, { boost: 1 }); + // @ts-expect-error + const idx_err6: DefaultSearchResults = idx5.resolve({}, { enrich: true }); + // @ts-expect-error + const idx_err7: DefaultSearchResults = idx5.resolve({}, { highlight: true }); + // @ts-expect-error + const idx_err8: DefaultSearchResults = idx5.and({}, { resolve: true }).limit(100); + + // @ts-expect-error + const idx_err9: Resolver = index2.search({ cache: true }); + // @ts-expect-error + const idx_err10: Promise = index2.searchAsync({ cache: true }); + // @ts-expect-error + const idx_err11: Resolver = index3.search({ resolve: false, cache: true }); + // @ts-expect-error + const idx_err12: Promise = index3.searchAsync({ resolve: false, cache: true }); + +} + +async function test_document() { + + // ---------------------------------------------------------------- const document = new Document<{ id: number, @@ -16,43 +90,101 @@ async function test() { description: string, tags: string[] }>({ + encoder: "LatinBalance", + resolution: 9, + context: false, document: { id: "id", + store: [ "title", "description" ], index: [ "title", "description" ], - tag: [ "tags" ], - store: [ "title", "description" ] + tag: [ "tags" ] }, }); - // The correct type - const doc1 = await document.searchAsync({}); - const doc2: Resolver = await document.searchAsync({ - resolve: false, - }); - const doc3 = await document.searchAsync({ - enrich: true, - }); - const doc4 = await document.searchAsync({ - enrich: true, - merge: true, - }); - doc4[0].doc.title; + type doctype = { + id: number, + meta: { + title: string, + description: string, + tags: string[] + } + }; - // The wrong type + const document2 = new Document({ + document: { + id: "id", + store: [{ + field: "meta:title", + filter: function(data){ + return true; + } + },{ + field: "meta:description" + },{ + field: "custom", + custom: function(data){ + return false; + } + }], + index: [{ + field: "meta:title", + filter: function(data){ + return true; + } + },{ + field: "meta:description", + encoder: "LatinBalance", + resolution: 9, + context: false, + },{ + field: "custom", + custom: function(data){ + return data.meta.title + " " + data.meta.description; + } + }], + tag: [{ + field: "meta:tags", + filter: function(data){ + return true; + } + },{ + field: "custom", + custom: function(data){ + return "tag"; + } + }] + }, + }); + + const doc1: DefaultDocumentSearchResults = document.search({ cache: true }); + const doc2: EnrichedDocumentSearchResults = document.search({ enrich: true }); + const doc3: MergedDocumentSearchResults = document.search({ merge: true }); + const doc4: EnrichedDocumentSearchResults = document.search({ highlight: true }); + const doc5: Promise = document.searchAsync({}); + const doc6: Resolver = document.search({ resolve: false }); + const doc7: DefaultSearchResults = document.search({ pluck: "title" }); + const doc8: DefaultSearchResults = document2.search({ pluck: "meta:title" }); + const doc9: DefaultDocumentSearchResults = document.searchCache({}); + const doc10: Promise = document.searchAsync({ cache: true }); + const doc11: Promise = document.searchCacheAsync({}); + const doc13: DefaultDocumentSearchResults = document.search({ resolve: true }); + const doc14: Resolver = document.search({ resolve: false }); + const doc15: DefaultSearchResults = doc14.resolve({}); + const doc16: DefaultSearchResults = doc14.and({ resolve: true }); + + const res1: Resolver = doc14.and({ index: document, field: "meta:title" }); + const res2: DefaultDocumentSearchResults = doc14.resolve(); - const t_1_1: DefaultSearchResults = document.search("test", { pluck: "title" }); // @ts-expect-error - const t_1_2: DefaultSearchResults = document.search("test", {}); + let tmp1: DocumentData = doc1[0].result[0].doc; + let tmp2: DocumentData = doc2[0].result[0].doc; + let tmp3: DocumentData = doc3[0].doc; - const t_2_1: DefaultDocumentSearchResults = document.search("test", {}); + // @ts-expect-error + const t_2_1: DefaultSearchResults = document2.search({ pluck: "title" }); // @ts-expect-error const t_2_2: DefaultSearchResults = document.search("test", {}); - const t_3_1: DefaultDocumentSearchResults = document.search({}); - const t_3_2: DefaultDocumentSearchResults = document.search({ resolve: true }); - - const t_4_1: Resolver = document.search({ resolve: false }); - const t_4_2: Resolver = new Resolver(); // @ts-expect-error const t_4_3: Resolver = document.search({}); // @ts-expect-error @@ -75,23 +207,23 @@ async function test() { const docw7: DefaultDocumentSearchResults = await document.searchAsync({ pluck: false }); // @ts-expect-error const docw8: DefaultDocumentSearchResults = await document.searchAsync({ enrich: false }); - // Promise? + +} + +async function test_worker() { const documentNoWorker = new Document({}); - const doc5 = documentNoWorker.search({}); // No Promise + const doc6 = documentNoWorker.search({}); // No Promise const documentWorker = new Document({ worker: true, }); - const doc6 = await documentWorker.search({}) // Promise + const doc7 = await documentWorker.search({}) // Promise const documentWorker2 = new Document({ worker: '...', }); - const doc7 = await documentWorker2.search({}) // Promise - - const index = new Index({}) - const idx = index.search({}) // No Promise + const doc8 = await documentWorker2.search({}) // Promise const worker = new Worker() const wkr = await worker.search({}) // Promise @@ -100,6 +232,6 @@ async function test() { db: {} as unknown as StorageInterface }) - const doc8 = documentDb.search({}) // Promise + const doc9 = documentDb.search({}) // Promise }