diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 8c897d9..6f9516f 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.108 (Bundle/Debug) + * FlexSearch.js v0.8.109 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -282,8 +282,20 @@ async function ka(a) { break; default: let d; - "export" === b && (e = [N.export]); - "import" === b ? await N.import.call(M, M) : d = M[b].apply(M, e); + if ("export" === b) { + if (!N.export || "function" !== typeof N.export) { + throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); + } + e = [N.export]; + } + if ("import" === b) { + if (!N.import || "function" !== typeof N.import) { + throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); + } + await N.import.call(M, M); + } else { + d = M[b].apply(M, e); + } postMessage("search" === b ? {id:c, msg:d} : {id:c}); } } @@ -1475,7 +1487,8 @@ function W(a) { this.J = []; this.key = (c = b.key || b.id) && Ta(c, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); - this.reg = (this.fastupdate = !!a.fastupdate) ? e ? new T(e) : new Map() : e ? new U(e) : new Set(); + this.fastupdate = !!a.fastupdate; + this.reg = !this.fastupdate || a.worker || a.db ? e ? new U(e) : new Set() : e ? new T(e) : new Map(); this.C = (c = b.store || null) && c && !0 !== c && []; this.store = c && (e ? new T(e) : new Map()); this.cache = (c = a.cache || null) && new Y(c); @@ -1501,6 +1514,7 @@ function W(a) { } } if (this.worker) { + this.fastupdate = !1; a = []; for (const d of this.index.values()) { d.then && a.push(d); @@ -1517,11 +1531,14 @@ function W(a) { }); } } else { - a.db && this.mount(a.db); + a.db && (this.fastupdate = !1, this.mount(a.db)); } } t = V.prototype; t.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; if (this.tag) { for (let d = 0, f; d < this.R.length; d++) { @@ -2020,7 +2037,7 @@ function mb(a, b) { const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? db[a.encoder] : a.encode || a.encoder || Wa; this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = c = a.tokenize || "strict"; + this.tokenize = (c = a.tokenize) && "default" !== c || "strict"; this.depth = "strict" === c && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index a200c4c..4c384cf 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.108 (Bundle) + * FlexSearch.js v0.8.109 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -55,9 +55,9 @@ else if(!q)return r?d:new X(d)}if(y){w=Ha(w,x,r);G=w.length;if(!G&&!q)return r?w d[z];u&&w.length&&!w[0].doc&&(this.db?v.push(w=this.index.get(this.field[0]).db.enrich(w)):w=W.call(this,w));if(g)return r?w:new X(w);d[z]={field:f[z],result:w}}if(u&&this.db&&v.length){const z=this;return Promise.all(v).then(function(w){for(let D=0;Dc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cc)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&hb(this));this.cache&&this.cache.remove(a);return this}; -function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; function nb(a){let b=0;if(a.constructor===Array)for(let c=0,e;cc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cc)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&hb(this));this.cache&&this.cache.remove(a);return this}; -function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; function ob(a){let b=0;if(a.constructor===Array)for(let c=0,e;c "a1a".split(b).length; } - this.numeric = A(a.numeric, e); + this.numeric = B(a.numeric, e); } else { try { - this.split = A(this.split, ca); + this.split = B(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+/; } - this.numeric = A(a.numeric, A(this.numeric, !0)); + this.numeric = B(a.numeric, B(this.numeric, !0)); } - this.prepare = A(a.prepare, null, this.prepare); - this.finalize = A(a.finalize, null, this.finalize); + this.prepare = B(a.prepare, null, this.prepare); + this.finalize = B(a.finalize, null, this.finalize); ha || (this.mapper = new Map(ba)); - this.rtl = A(a.rtl, !1, this.rtl); - this.dedupe = A(a.dedupe, !1, this.dedupe); - this.filter = A((b = a.filter) && new Set(b), null, this.filter); - this.matcher = A((b = a.matcher) && new Map(b), null, this.matcher); - this.mapper = A((b = a.mapper) && new Map(b), null, this.mapper); - this.stemmer = A((b = a.stemmer) && new Map(b), null, this.stemmer); - this.replacer = A(a.replacer, null, this.replacer); - this.minlength = A(a.minlength, 1, this.minlength); - this.maxlength = A(a.maxlength, 0, this.maxlength); - if (this.cache = b = A(a.cache, !0, this.cache)) { + this.rtl = B(a.rtl, !1, this.rtl); + this.dedupe = B(a.dedupe, !1, this.dedupe); + this.filter = B((b = a.filter) && new Set(b), null, this.filter); + this.matcher = B((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = B((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = B((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = B(a.replacer, null, this.replacer); + this.minlength = B(a.minlength, 1, this.minlength); + this.maxlength = B(a.maxlength, 0, this.maxlength); + if (this.cache = b = B(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 = ""; @@ -216,8 +216,8 @@ w.encode = function(a) { this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, h; f < e.length; f++) { - if ((g = h = e[f]) && !(g.length < this.minlength)) { + for (let f = 0, g, k; f < e.length; f++) { + if ((g = k = e[f]) && !(g.length < this.minlength)) { if (c) { b.push(g); } else { @@ -233,21 +233,21 @@ w.encode = function(a) { this.H = setTimeout(L, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, k => this.stemmer.get(k)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let k = 0, l = "", m, n; k < g.length; k++) { - m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let h = 0, l = "", m, n; h < g.length; h++) { + m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); g && b.push(g); } } @@ -275,8 +275,20 @@ async function ia(a) { break; default: let d; - "export" === c && (e = [N.export]); - "import" === c ? await N.import.call(M, M) : d = M[c].apply(M, e); + if ("export" === c) { + if (!N.export || "function" !== typeof N.export) { + throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); + } + e = [N.export]; + } + if ("import" === c) { + if (!N.import || "function" !== typeof N.import) { + throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); + } + await N.import.call(M, M); + } else { + d = M[c].apply(M, e); + } postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } @@ -320,19 +332,19 @@ function P(a) { ;let T = 0; function ma(a = {}) { function c(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && d.h[l]; - m && (m(k.msg), delete d.h[l]); + 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 = C(); if (this.worker) { - e ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { + return new Promise(function(h) { d.h[++T] = function() { - k(d); + h(d); }; d.worker.postMessage({id:T, task:"init", factory:b, options:a}); }); @@ -425,18 +437,18 @@ function ta(a, c) { return c; } function ua(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { return this.export(a, c, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return ua.call(l, a, c, b, h ? e : null, d, f, g + 1); + return h.then(function() { + return ua.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return ua.call(this, a, c, b, h ? e : null, d, f, g + 1); + return ua.call(this, a, c, b, k ? e : null, d, f, g + 1); } ;V.prototype.add = function(a, c, b) { H(a) && (c = a, a = J(c, this.key)); @@ -444,15 +456,15 @@ function ua(a, c, b, e, d, f, g = 0) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.C[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); + for (let k = 0, h; k < this.field.length; k++) { + h = this.C[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(c); d && e.add(a, d, !1, !0); } else { - if (d = k.I, !d || d(c)) { - k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), va(c, k, this.J, 0, e, a, k[0], b); + if (d = h.I, !d || d(c)) { + h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); } } } @@ -460,14 +472,14 @@ function ua(a, c, b, e, d, f, g = 0) { for (e = 0; e < this.B.length; e++) { var f = this.B[e], g = this.T[e]; d = this.tag.get(g); - let h = C(); + let k = C(); if ("function" === typeof f) { if (f = f(c), !f) { continue; } } else { - const k = f.I; - if (k && !k(c)) { + const h = f.I; + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); @@ -475,8 +487,8 @@ function ua(a, c, b, e, d, f, g = 0) { } if (d && f) { D(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + 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])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -484,11 +496,11 @@ function ua(a, c, b, e, d, f, g = 0) { } } if (this.store && (!b || !this.store.has(a))) { - let h; + let k; if (this.A) { - h = C(); - for (let k = 0, l; k < this.A.length; k++) { - l = this.A[k]; + k = C(); + for (let h = 0, l; h < this.A.length; h++) { + l = this.A[h]; if ((b = l.I) && !b(c)) { continue; } @@ -500,13 +512,13 @@ function ua(a, c, b, e, d, f, g = 0) { } l = [l.U]; } else if (D(l) || l.constructor === String) { - h[l] = c[l]; + k[l] = c[l]; continue; } - wa(c, h, l, 0, l[0], m); + wa(c, k, l, 0, l[0], m); } } - this.store.set(a, h || c); + this.store.set(a, k || c); } } return this; @@ -525,7 +537,7 @@ function wa(a, c, b, e, d, f) { } } } -function va(a, c, b, e, d, f, g, h) { +function va(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -537,27 +549,27 @@ function va(a, c, b, e, d, f, g, h) { } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - va(a, c, b, e, d, f, g, h); + va(a, c, b, e, d, f, g, k); } } else { - g = c[++e], va(a, c, b, e, d, f, g, h); + g = c[++e], va(a, c, b, e, d, f, g, k); } } } } ;function xa(a, c, b, e, d) { const f = a.length; - let g = [], h, k; - h = C(); + let g = [], k, h; + k = C(); for (let l = 0, m, n, t, p; l < c; l++) { for (let q = 0; q < f; q++) { if (t = a[q], l < t.length && (m = t[l])) { for (let y = 0; y < m.length; y++) { - n = m[y], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), p = g[k] || (g[k] = []), p.push(n); + n = m[y], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n); } } } @@ -583,10 +595,10 @@ function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; - let h; - for (let k = g - 1; 0 <= k; k--) { - if (h = (g = a[k]) && g.length) { - for (let l = 0; l < h; l++) { + 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--; @@ -601,26 +613,18 @@ function ya(a, c, b) { } return e; } -function za(a, c, b) { - const e = C(), d = []; - for (let f = 0, g; f < c.length; f++) { - g = c[f]; - for (let h = 0; h < g.length; h++) { - e[g[h]] = 1; +function za(a, c) { + const b = C(), e = []; + for (let d = 0, f; d < c.length; d++) { + f = c[d]; + for (let g = 0; g < f.length; g++) { + b[f[g]] = 1; } } - 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, h; f < a.result.length; f++) { - for (g = a.result[f], c = 0; c < g.length; c++) { - h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); - } - } + for (let d = 0, f; d < a.length; d++) { + f = a[d], b[f] && (e.push(f), b[f] = 0); } - return d; + return e; } ;function Aa(a, c, b, e) { if (!a.length) { @@ -630,21 +634,21 @@ function za(a, c, b) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; } let d = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { if (b) { - if (b >= h) { - b -= h; + if (b >= k) { + b -= k; continue; } - b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); + b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); } - h > c && (g = g.slice(0, c), h = c); - if (!d.length && h >= c) { + k > c && (g = g.slice(0, c), k = c); + if (!d.length && k >= c) { return e ? W.call(this, g) : g; } d.push(g); - c -= h; + c -= k; if (!c) { break; } @@ -664,7 +668,7 @@ function za(a, c, b) { return a[c].apply(a, e); } e = []; - let d = [], f = 0, g = 0, h, k, l; + let d = [], f = 0, g = 0, k, h, l; for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { let t; @@ -673,8 +677,8 @@ function za(a, c, b) { } else if (n.constructor === Array) { t = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { - n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = k, n.enrich = h; + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { + n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = h, n.enrich = k; } else if (n.and) { t = a.and(n.and); } else if (n.or) { @@ -697,7 +701,7 @@ function za(a, c, b) { } } } - return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;X.prototype.or = function() { const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); @@ -706,10 +710,10 @@ function za(a, c, b) { function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; - return Promise.all(c).then(function(h) { + return Promise.all(c).then(function(k) { a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } return Ca.call(g, a, [], b, e, d, f); }); @@ -724,20 +728,20 @@ function Ca(a, c, b, e, d, f) { f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); - return Da.call(this, f, g, h, k, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); + return Da.call(this, f, g, k, h, l, m, n); } return d ? this.resolve(c, b, e) : this; }; function Da(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Da.call(h, a, [], b, e, d, f, g); + return Da.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -760,13 +764,13 @@ function Da(a, c, b, e, d, f, g) { }; function Ea(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Ea.call(h, a, [], b, e, d, f, g); + return Ea.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -782,10 +786,10 @@ function Ea(a, c, b, e, d, f, g) { } function Fa(a, c, b, e, d) { const f = [], g = C(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); + 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 t = 0, p; t < n.length; t++) { @@ -795,10 +799,10 @@ function Fa(a, c, b, e, d) { } } } - for (let k = 0, l, m = 0; k < h; k++) { + for (let h = 0, l, m = 0; h < k; h++) { for (let n = 0, t; n < a.length; n++) { if (t = a[n]) { - if (l = t[k]) { + if (l = t[h]) { for (let p = 0, q; p < l.length; p++) { if (q = l[p], 1 === g[q]) { if (b) { @@ -809,7 +813,7 @@ function Fa(a, c, b, e, d) { return f; } } else { - const y = k + (n ? d : 0); + const y = h + (n ? d : 0); f[y] || (f[y] = []); f[y].push(q); if (++m === c) { @@ -831,13 +835,13 @@ function Fa(a, c, b, e, d) { }; function Ga(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Ga.call(h, a, [], b, e, d, f, g); + return Ga.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { @@ -850,10 +854,10 @@ function Ga(a, c, b, e, d, f, g) { function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { + for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (b) { b--; } else { @@ -862,7 +866,7 @@ function Ha(a, c, b, e) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { + if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { return d; } } @@ -929,15 +933,15 @@ V.prototype.search = function(a, c, b, e) { b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let d = []; var f = []; - let g, h, k, l, m, n, t = 0, p, q; + let g, k, h, l, m, n, t = 0, p, q; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var y = b.pluck; - h = b.merge; + k = b.merge; l = y || b.field || (l = b.index) && (l.index ? null : l); m = this.tag && b.tag; - k = b.suggest; + h = 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 = this.store && b.enrich && p; @@ -964,13 +968,13 @@ V.prototype.search = function(a, c, b, e) { } } else { v = Object.keys(r); - for (let E = 0, F, B; E < v.length; E++) { - if (F = v[E], B = r[F], B.constructor === Array) { - for (z = 0; z < B.length; z++) { - u.push(F, B[z]); + for (let E = 0, F, A; E < v.length; E++) { + if (F = v[E], A = r[F], A.constructor === Array) { + for (z = 0; z < A.length; z++) { + u.push(F, A[z]); } } else { - u.push(F, B); + u.push(F, A); } } } @@ -1000,12 +1004,12 @@ V.prototype.search = function(a, c, b, e) { u = !e && (this.worker || this.db) && []; for (let x = 0, r, E, F; x < l.length; x++) { E = l[x]; - let B; - D(E) || (B = E, E = B.field, a = B.query || a, c = B.limit || c, n = B.offset || n, k = B.suggest || k, g = this.store && (B.enrich || g)); + let A; + D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, h = A.suggest || h, g = this.store && (A.enrich || g)); if (e) { r = e[x]; } else { - if (v = B || b, z = this.index.get(E), m && (v.enrich = !1), u) { + if (v = A || b, z = this.index.get(E), m && (v.enrich = !1), u) { u[x] = z.search(a, c, v); v && g && (v.enrich = g); continue; @@ -1017,25 +1021,25 @@ V.prototype.search = function(a, c, b, e) { if (m && F) { v = []; z = 0; - for (let G = 0, I, $a; G < m.length; G += 2) { + for (let G = 0, I, Za; G < m.length; G += 2) { I = this.tag.get(m[G]); if (!I) { - if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { + if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), h) { continue; } else { return p ? d : new X(d); } } - if ($a = (I = I && I.get(m[G + 1])) && I.length) { + if (Za = (I = I && I.get(m[G + 1])) && I.length) { z++, v.push(I); - } else if (!k) { + } else if (!h) { return p ? d : new X(d); } } if (z) { - r = za(r, v, p); + r = za(r, v); F = r.length; - if (!F && !k) { + if (!F && !h) { return p ? r : new X(r); } z--; @@ -1068,18 +1072,18 @@ V.prototype.search = function(a, c, b, e) { } d[x] = {field:f[x], result:r}; } - return h ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; + return k ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; }; function Ka(a, c, b, e, d, f) { - let g, h, k; + let g, k, h; for (let m = 0, n, t, p, q, y; m < a.length; m++) { n = a[m].result; t = a[m].field; q = b.get(t); p = q.encoder; - k = q.tokenize; + h = q.tokenize; y = d[e.indexOf(t)]; - p !== g && (g = p, h = g.encode(c)); + p !== g && (g = p, k = g.encode(c)); for (let u = 0; u < n.length; u++) { let v = ""; var l = J(n[u].doc, y); @@ -1089,8 +1093,8 @@ function Ka(a, c, b, e, d, f) { r = z[x]; E = l[x]; let F; - for (let B = 0, G; B < h.length; B++) { - if (G = h[B], "strict" === k) { + for (let A = 0, G; A < k.length; A++) { + if (G = k[A], "strict" === h) { if (r === G) { v += (v ? " " : "") + f.replace("$1", E); F = !0; @@ -1117,14 +1121,14 @@ function Ja(a, c) { for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = e[k]) { + for (let k = 0, h, l, m; k < g.length; k++) { + if (l = g[k], h = l.id, m = e[h]) { m.push(f.field); } else { if (b.length === c) { return b; } - l.field = e[k] = [f.field]; + l.field = e[h] = [f.field]; b.push(l); } } @@ -1272,9 +1276,9 @@ w.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 h = this; + const k = this; return c.then(function() { - return h.export(a, g, b + 1); + return k.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -1415,34 +1419,34 @@ O.prototype.add = function(a, c, b, e) { case "full": if (2 < d) { for (f = 0; f < d; f++) { - for (var h = d; h > f; h--) { - g = q.substring(f, h); - var k = this.score ? this.score(c, q, p, g, f) : Xa(t, e, p, d, f); - Z(this, m, g, k, a, b); + for (var k = d; k > f; k--) { + g = q.substring(f, k); + var h = this.score ? this.score(c, q, p, g, f) : Xa(t, e, p, d, f); + Z(this, m, g, h, a, b); } } break; } case "reverse": if (1 < d) { - for (h = d - 1; 0 < h; h--) { - g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : Xa(t, e, p, d, h), Z(this, m, g, k, a, b); + for (k = d - 1; 0 < k; k--) { + g = q[k] + g, h = this.score ? this.score(c, q, p, g, k) : Xa(t, e, p, d, k), Z(this, m, g, h, a, b); } g = ""; } case "forward": if (1 < d) { - for (h = 0; h < d; h++) { - g += q[h], Z(this, m, g, f, a, b); + for (k = 0; k < d; k++) { + g += q[k], Z(this, m, g, f, a, b); } break; } default: if (Z(this, m, q, f, a, b), n && 1 < e && p < e - 1) { - for (d = C(), g = this.S, f = q, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { - if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { + for (d = C(), g = this.S, f = q, k = Math.min(n + 1, e - p), d[f] = 1, h = 1; h < k; h++) { + if ((q = c[this.rtl ? e - 1 - p - h : p + h]) && !d[q]) { d[q] = 1; - const y = this.score ? this.score(c, f, p, q, k) : Xa(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; + const y = this.score ? this.score(c, f, p, q, h) : Xa(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, y, a, b, u ? q : f); } } @@ -1456,9 +1460,9 @@ O.prototype.add = function(a, c, b, e) { return this; }; function Z(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); + let k = g ? a.ctx : a.map, h; + if (!c[b] || g && !(h = c[b])[g]) { + g ? (c = h || (c[b] = C()), 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 Xa(a, c, b, e, d) { @@ -1473,35 +1477,35 @@ function Xa(a, c, b, e, d) { d = b.offset || 0; var f = b.context; var g = b.suggest; - var h = !0; - var k = b.resolution; + var k = !0; + var h = b.resolution; } else { - h = !0; + k = !0; } - b = this.encoder.encode(a); - a = b.length; - c = c || (h ? 100 : 0); - if (1 === a) { - return Ya.call(this, b[0], "", c, d, h); + a = this.encoder.encode(a); + b = a.length; + c = c || (k ? 100 : 0); + if (1 === b) { + return g = c, (c = Ya(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; } f = this.depth && !1 !== f; - if (2 === a && f && !g) { - return Ya.call(this, b[0], b[1], c, d, h); + if (2 === b && f && !g) { + return g = c, (c = Ya(this, a[0], a[1])) && c.length ? Aa.call(this, c, g, d) : []; } - h = C(); + k = C(); let l = 0; - if (1 < a && f) { - var m = b[0]; + if (1 < b && f) { + var m = a[0]; l = 1; } - k || 0 === k || (k = m ? this.S : this.resolution); - for (let q, y; l < a; l++) { - if ((y = b[l]) && !h[y]) { - h[y] = 1; - q = Za(this, y, m); + h || 0 === h || (h = m ? this.S : this.resolution); + for (let q, y; l < b; l++) { + if ((y = a[l]) && !k[y]) { + k[y] = 1; + q = Ya(this, y, m); a: { f = q; - var n = e, t = g, p = k; + var n = e, t = g, p = h; let u = []; if (f && f.length) { if (f.length <= p) { @@ -1528,27 +1532,23 @@ function Xa(a, c, b, e, d) { } m && (g && q && e.length || (m = y)); } - g && m && l === a - 1 && !e.length && (m = "", l = -1, h = C()); + g && m && l === b - 1 && !e.length && (m = "", l = -1, k = C()); } a: { - m = e.length; a = e; - if (1 < m) { - a = xa(e, k, c, d, g); - } else if (1 === m) { - g = Aa.call(null, e[0], c, d); + e = a.length; + m = a; + if (1 < e) { + m = xa(a, h, c, d, g); + } else if (1 === e) { + g = Aa.call(null, a[0], c, d); break a; } - g = a; + g = m; } return g; }; -function Ya(a, c, b, e, d) { - a = Za(this, a, c); - d = !0; - return a && a.length ? d ? Aa.call(this, a, b, e) : new X(a) : d ? [] : new X(); -} -function Za(a, c, b) { +function Ya(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); @@ -1569,14 +1569,14 @@ function Za(a, c, b) { } } } else { - ab(this.map, a), this.depth && ab(this.ctx, a); + $a(this.map, a), this.depth && $a(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function ab(a, c) { +function $a(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1591,7 +1591,7 @@ function ab(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = ab(e[1], c); + const d = e[0], f = $a(e[1], c); f ? b += f : a.delete(d); } } @@ -1611,7 +1611,7 @@ function ab(a, c) { const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = b = a.tokenize || "strict"; + this.tokenize = (b = a.tokenize) && "default" !== b || "strict"; this.depth = "strict" === b && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; @@ -1643,7 +1643,7 @@ w.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function bb(a) { +function ab(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1651,7 +1651,7 @@ function bb(a) { } } else { for (const b of a) { - const e = b[0], d = bb(b[1]); + const e = b[0], d = ab(b[1]); d ? c += d : a.delete(e); } } @@ -1661,8 +1661,8 @@ w.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); + ab(this.map); + this.depth && ab(this.ctx); return this; }; w.searchCache = Ma; @@ -1716,18 +1716,18 @@ w.serialize = function(a = !0) { c = "index.reg=new Set([" + c + "]);"; e = ""; for (var d of this.map.entries()) { - var f = d[0], g = d[1], h = ""; + var f = d[0], g = d[1], k = ""; for (let m = 0, n; m < g.length; m++) { n = g[m] || [""]; - var k = ""; + var h = ""; for (var l = 0; l < n.length; l++) { - k += (k ? "," : "") + ("string" === b ? '"' + n[l] + '"' : n[l]); + h += (h ? "," : "") + ("string" === b ? '"' + n[l] + '"' : n[l]); } - k = "[" + k + "]"; - h += (h ? "," : "") + k; + h = "[" + h + "]"; + k += (k ? "," : "") + h; } - h = '["' + f + '",[' + h + "]]"; - e += (e ? "," : "") + h; + k = '["' + f + '",[' + k + "]]"; + e += (e ? "," : "") + k; } e = "index.map=new Map([" + e + "]);"; d = ""; @@ -1736,29 +1736,29 @@ w.serialize = function(a = !0) { g = m[1]; for (const n of g.entries()) { g = n[0]; - h = n[1]; - k = ""; - for (let t = 0, p; t < h.length; t++) { - p = h[t] || [""]; + k = n[1]; + h = ""; + for (let t = 0, p; t < k.length; t++) { + p = k[t] || [""]; l = ""; for (let q = 0; q < p.length; q++) { l += (l ? "," : "") + ("string" === b ? '"' + p[q] + '"' : p[q]); } l = "[" + l + "]"; - k += (k ? "," : "") + l; + h += (h ? "," : "") + l; } - k = 'new Map([["' + g + '",[' + k + "]]])"; - k = '["' + f + '",' + k + "]"; - d += (d ? "," : "") + k; + h = 'new Map([["' + g + '",[' + h + "]]])"; + h = '["' + f + '",' + h + "]"; + d += (d ? "," : "") + h; } } d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; ja(O.prototype); -const cb = {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, db = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; -let eb; -(eb = db.define) && eb.amd ? eb([], function() { - return cb; -}) : "object" === typeof db.exports ? db.exports = cb : db.FlexSearch = cb; +const bb = {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, cb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; +let db; +(db = cb.define) && db.amd ? db([], function() { + return bb; +}) : "object" === typeof cb.exports ? cb.exports = bb : cb.FlexSearch = bb; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index d5e4856..322bd48 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.108 (Bundle) + * FlexSearch.js v0.8.109 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';var v;function A(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} +(function(self){'use strict';var v;function B(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 C(){return Object.create(null)}function D(a){return"string"===typeof a} function H(a){return"object"===typeof a}function I(a,c){if(D(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);ha||(this.mapper=new Map(ba));this.rtl=A(a.rtl,!1,this.rtl);this.dedupe=A(a.dedupe,!1,this.dedupe);this.filter=A((b=a.filter)&&new Set(b),null,this.filter);this.matcher=A((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=A((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= -A((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);if(this.cache=b=A(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.D="";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.D+= +v.assign=function(a){this.normalize=B(a.normalize,!0,this.normalize);let c=a.include,b=c||a.exclude||a.split,e;if(b||""===b){if("object"===typeof b&&b.constructor!==RegExp){let d="";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("["+(c?"^":"")+d+"]+","u")}catch(f){this.split=/\s+/}}else this.split=b,e=!1===b||2>"a1a".split(b).length; +this.numeric=B(a.numeric,e)}else{try{this.split=B(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=B(a.numeric,B(this.numeric,!0))}this.prepare=B(a.prepare,null,this.prepare);this.finalize=B(a.finalize,null,this.finalize);ha||(this.mapper=new Map(ba));this.rtl=B(a.rtl,!1,this.rtl);this.dedupe=B(a.dedupe,!1,this.dedupe);this.filter=B((b=a.filter)&&new Set(b),null,this.filter);this.matcher=B((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=B((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= +B((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=B(a.replacer,null,this.replacer);this.minlength=B(a.minlength,1,this.minlength);this.maxlength=B(a.maxlength,0,this.maxlength);if(this.cache=b=B(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.D="";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.D+= (this.D?"|":"")+d;return this};v.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&L(this);return this};v.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&L(this);return this};v.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&&L(this);return this};v.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; v.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(L,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.stemmer.get(k)),g.lengththis.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&d +[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,k;fthis.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d this.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;const c=a.task,b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(a=a.factory)?(Function("return "+a)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e=[N.export]);"import"===c?await N.import.call(M,M):d=M[c].apply(M,e);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let Q,ka;const R={},S={};function la(a){Q=0;R[a]=S[a]} function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);Q||(Q=setTimeout(la,0,a),ka=Date.now());S[a]||(S[a]=R[a]=1E3);if(!--R[a]){R[a]=S[a]=S[a]*this.priority*this.priority*3/(Date.now()-ka)|0||1;Q=clearTimeout(Q);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let T=0; -function ma(a={}){function c(g){function h(k){k=k.data||k;const l=k.id,m=l&&d.h[l];m&&(m(k.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++T]=function(){k(d)};d.worker.postMessage({id:T,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==ma)return new ma(a);let b="undefined"!==typeof self?self._factory:"undefined"!== +function ma(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++T]=function(){h(d)};d.worker.postMessage({id:T,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==ma)return new ma(a);let b="undefined"!==typeof self?self._factory:"undefined"!== typeof window?window._factory:null;b&&(b=b.toString());const e="undefined"===typeof window,d=this,f=na(b,e,a.worker);return f.then?f.then(function(g){return c.call(d,g)}):c.call(this,f)}U("add");U("append");U("search");U("update");U("remove");U("clear");U("export");U("import");ja(ma.prototype); function U(a){ma.prototype[a]=async function(){const c=this,b=[].slice.call(arguments);var e=b[b.length-1];let d;"function"===typeof e&&(d=e,b.splice(b.length-1,1));e=new Promise(function(f){c.h[++T]=f;c.worker.postMessage({task:a,id:T,args:b})});return d?(e.then(d),this):e}} function na(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ia.toString()],{type:"text/javascript"}))):new window.Worker(D(b)?b:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"),{type:"module"})};function oa(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function pa(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?W.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; -function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; -function Ea(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Fa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let 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?W.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?W.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}} +function Ka(a,c,b,e,d,f){let g,k,h;for(let m=0,n,t,p,q,y;mb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}} function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; Y.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};const Oa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Pa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;const Ua=/[\x00-\x7F]+/g;var Va={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Oa,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):Xa(t,e,p,d,f);Z(this,m,g,k,a,b)}break}case "reverse":if(1< -d){for(h=d-1;0g?0:1),e,p,h-1,k-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=C()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Xa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else ab(this.map,a),this.depth&&ab(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function ab(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function bb(a){let c=0;if(a.constructor===Array)for(let b=0,e;bf;k--){g=q.substring(f,k);var h=this.score?this.score(c,q,p,g,f):Xa(t,e,p,d,f);Z(this,m,g,h,a,b)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,p,k-1,h-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),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 Xa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else $a(this.map,a),this.depth&&$a(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function $a(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function ab(a){let c=0;if(a.constructor===Array)for(let b=0,e;b "a1a".split(b).length; } - this.numeric = A(a.numeric, e); + this.numeric = B(a.numeric, e); } else { try { - this.split = A(this.split, ca); + this.split = B(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+/; } - this.numeric = A(a.numeric, A(this.numeric, !0)); + this.numeric = B(a.numeric, B(this.numeric, !0)); } - this.prepare = A(a.prepare, null, this.prepare); - this.finalize = A(a.finalize, null, this.finalize); + this.prepare = B(a.prepare, null, this.prepare); + this.finalize = B(a.finalize, null, this.finalize); ha || (this.mapper = new Map(ba)); - this.rtl = A(a.rtl, !1, this.rtl); - this.dedupe = A(a.dedupe, !1, this.dedupe); - this.filter = A((b = a.filter) && new Set(b), null, this.filter); - this.matcher = A((b = a.matcher) && new Map(b), null, this.matcher); - this.mapper = A((b = a.mapper) && new Map(b), null, this.mapper); - this.stemmer = A((b = a.stemmer) && new Map(b), null, this.stemmer); - this.replacer = A(a.replacer, null, this.replacer); - this.minlength = A(a.minlength, 1, this.minlength); - this.maxlength = A(a.maxlength, 0, this.maxlength); - if (this.cache = b = A(a.cache, !0, this.cache)) { + this.rtl = B(a.rtl, !1, this.rtl); + this.dedupe = B(a.dedupe, !1, this.dedupe); + this.filter = B((b = a.filter) && new Set(b), null, this.filter); + this.matcher = B((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = B((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = B((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = B(a.replacer, null, this.replacer); + this.minlength = B(a.minlength, 1, this.minlength); + this.maxlength = B(a.maxlength, 0, this.maxlength); + if (this.cache = b = B(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 = ""; @@ -215,8 +215,8 @@ w.encode = function(a) { this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, h; f < e.length; f++) { - if ((g = h = e[f]) && !(g.length < this.minlength)) { + for (let f = 0, g, k; f < e.length; f++) { + if ((g = k = e[f]) && !(g.length < this.minlength)) { if (c) { b.push(g); } else { @@ -232,21 +232,21 @@ w.encode = function(a) { this.H = setTimeout(L, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, k => this.stemmer.get(k)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let k = 0, l = "", m, n; k < g.length; k++) { - m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let h = 0, l = "", m, n; h < g.length; h++) { + m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); g && b.push(g); } } @@ -274,8 +274,20 @@ async function ia(a) { break; default: let d; - "export" === c && (e = [N.export]); - "import" === c ? await N.import.call(M, M) : d = M[c].apply(M, e); + if ("export" === c) { + if (!N.export || "function" !== typeof N.export) { + throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); + } + e = [N.export]; + } + if ("import" === c) { + if (!N.import || "function" !== typeof N.import) { + throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); + } + await N.import.call(M, M); + } else { + d = M[c].apply(M, e); + } postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } @@ -319,19 +331,19 @@ function P(a) { ;let T = 0; function ma(a = {}) { function c(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && d.h[l]; - m && (m(k.msg), delete d.h[l]); + 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 = C(); if (this.worker) { - e ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { + return new Promise(function(h) { d.h[++T] = function() { - k(d); + h(d); }; d.worker.postMessage({id:T, task:"init", factory:b, options:a}); }); @@ -424,18 +436,18 @@ function ta(a, c) { return c; } function ua(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { return this.export(a, c, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return ua.call(l, a, c, b, h ? e : null, d, f, g + 1); + return h.then(function() { + return ua.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return ua.call(this, a, c, b, h ? e : null, d, f, g + 1); + return ua.call(this, a, c, b, k ? e : null, d, f, g + 1); } ;V.prototype.add = function(a, c, b) { H(a) && (c = a, a = J(c, this.key)); @@ -443,15 +455,15 @@ function ua(a, c, b, e, d, f, g = 0) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.C[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); + for (let k = 0, h; k < this.field.length; k++) { + h = this.C[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(c); d && e.add(a, d, !1, !0); } else { - if (d = k.I, !d || d(c)) { - k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), va(c, k, this.J, 0, e, a, k[0], b); + if (d = h.I, !d || d(c)) { + h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); } } } @@ -459,14 +471,14 @@ function ua(a, c, b, e, d, f, g = 0) { for (e = 0; e < this.B.length; e++) { var f = this.B[e], g = this.T[e]; d = this.tag.get(g); - let h = C(); + let k = C(); if ("function" === typeof f) { if (f = f(c), !f) { continue; } } else { - const k = f.I; - if (k && !k(c)) { + const h = f.I; + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); @@ -474,8 +486,8 @@ function ua(a, c, b, e, d, f, g = 0) { } if (d && f) { D(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + 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])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -483,11 +495,11 @@ function ua(a, c, b, e, d, f, g = 0) { } } if (this.store && (!b || !this.store.has(a))) { - let h; + let k; if (this.A) { - h = C(); - for (let k = 0, l; k < this.A.length; k++) { - l = this.A[k]; + k = C(); + for (let h = 0, l; h < this.A.length; h++) { + l = this.A[h]; if ((b = l.I) && !b(c)) { continue; } @@ -499,13 +511,13 @@ function ua(a, c, b, e, d, f, g = 0) { } l = [l.U]; } else if (D(l) || l.constructor === String) { - h[l] = c[l]; + k[l] = c[l]; continue; } - wa(c, h, l, 0, l[0], m); + wa(c, k, l, 0, l[0], m); } } - this.store.set(a, h || c); + this.store.set(a, k || c); } } return this; @@ -524,7 +536,7 @@ function wa(a, c, b, e, d, f) { } } } -function va(a, c, b, e, d, f, g, h) { +function va(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -536,27 +548,27 @@ function va(a, c, b, e, d, f, g, h) { } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - va(a, c, b, e, d, f, g, h); + va(a, c, b, e, d, f, g, k); } } else { - g = c[++e], va(a, c, b, e, d, f, g, h); + g = c[++e], va(a, c, b, e, d, f, g, k); } } } } ;function xa(a, c, b, e, d) { const f = a.length; - let g = [], h, k; - h = C(); + let g = [], k, h; + k = C(); for (let l = 0, m, n, t, p; l < c; l++) { for (let q = 0; q < f; q++) { if (t = a[q], l < t.length && (m = t[l])) { for (let y = 0; y < m.length; y++) { - n = m[y], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), p = g[k] || (g[k] = []), p.push(n); + n = m[y], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n); } } } @@ -582,10 +594,10 @@ function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; - let h; - for (let k = g - 1; 0 <= k; k--) { - if (h = (g = a[k]) && g.length) { - for (let l = 0; l < h; l++) { + 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--; @@ -600,26 +612,18 @@ function ya(a, c, b) { } return e; } -function za(a, c, b) { - const e = C(), d = []; - for (let f = 0, g; f < c.length; f++) { - g = c[f]; - for (let h = 0; h < g.length; h++) { - e[g[h]] = 1; +function za(a, c) { + const b = C(), e = []; + for (let d = 0, f; d < c.length; d++) { + f = c[d]; + for (let g = 0; g < f.length; g++) { + b[f[g]] = 1; } } - 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, h; f < a.result.length; f++) { - for (g = a.result[f], c = 0; c < g.length; c++) { - h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); - } - } + for (let d = 0, f; d < a.length; d++) { + f = a[d], b[f] && (e.push(f), b[f] = 0); } - return d; + return e; } ;function Aa(a, c, b, e) { if (!a.length) { @@ -629,21 +633,21 @@ function za(a, c, b) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; } let d = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { if (b) { - if (b >= h) { - b -= h; + if (b >= k) { + b -= k; continue; } - b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); + b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); } - h > c && (g = g.slice(0, c), h = c); - if (!d.length && h >= c) { + k > c && (g = g.slice(0, c), k = c); + if (!d.length && k >= c) { return e ? W.call(this, g) : g; } d.push(g); - c -= h; + c -= k; if (!c) { break; } @@ -663,7 +667,7 @@ function za(a, c, b) { return a[c].apply(a, e); } e = []; - let d = [], f = 0, g = 0, h, k, l; + let d = [], f = 0, g = 0, k, h, l; for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { let t; @@ -672,8 +676,8 @@ function za(a, c, b) { } else if (n.constructor === Array) { t = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { - n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = k, n.enrich = h; + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { + n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = h, n.enrich = k; } else if (n.and) { t = a.and(n.and); } else if (n.or) { @@ -696,7 +700,7 @@ function za(a, c, b) { } } } - return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;X.prototype.or = function() { const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); @@ -705,10 +709,10 @@ function za(a, c, b) { function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; - return Promise.all(c).then(function(h) { + return Promise.all(c).then(function(k) { a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } return Ca.call(g, a, [], b, e, d, f); }); @@ -723,20 +727,20 @@ function Ca(a, c, b, e, d, f) { f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); - return Da.call(this, f, g, h, k, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); + return Da.call(this, f, g, k, h, l, m, n); } return d ? this.resolve(c, b, e) : this; }; function Da(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Da.call(h, a, [], b, e, d, f, g); + return Da.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -759,13 +763,13 @@ function Da(a, c, b, e, d, f, g) { }; function Ea(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Ea.call(h, a, [], b, e, d, f, g); + return Ea.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -781,10 +785,10 @@ function Ea(a, c, b, e, d, f, g) { } function Fa(a, c, b, e, d) { const f = [], g = C(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); + 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 t = 0, p; t < n.length; t++) { @@ -794,10 +798,10 @@ function Fa(a, c, b, e, d) { } } } - for (let k = 0, l, m = 0; k < h; k++) { + for (let h = 0, l, m = 0; h < k; h++) { for (let n = 0, t; n < a.length; n++) { if (t = a[n]) { - if (l = t[k]) { + if (l = t[h]) { for (let p = 0, q; p < l.length; p++) { if (q = l[p], 1 === g[q]) { if (b) { @@ -808,7 +812,7 @@ function Fa(a, c, b, e, d) { return f; } } else { - const y = k + (n ? d : 0); + const y = h + (n ? d : 0); f[y] || (f[y] = []); f[y].push(q); if (++m === c) { @@ -830,13 +834,13 @@ function Fa(a, c, b, e, d) { }; function Ga(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return Ga.call(h, a, [], b, e, d, f, g); + return Ga.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { @@ -849,10 +853,10 @@ function Ga(a, c, b, e, d, f, g) { function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { + for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (b) { b--; } else { @@ -861,7 +865,7 @@ function Ha(a, c, b, e) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { + if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { return d; } } @@ -928,15 +932,15 @@ V.prototype.search = function(a, c, b, e) { b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let d = []; var f = []; - let g, h, k, l, m, n, t = 0, p, q; + let g, k, h, l, m, n, t = 0, p, q; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var y = b.pluck; - h = b.merge; + k = b.merge; l = y || b.field || (l = b.index) && (l.index ? null : l); m = this.tag && b.tag; - k = b.suggest; + h = 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 = this.store && b.enrich && p; @@ -963,13 +967,13 @@ V.prototype.search = function(a, c, b, e) { } } else { v = Object.keys(r); - for (let E = 0, F, B; E < v.length; E++) { - if (F = v[E], B = r[F], B.constructor === Array) { - for (z = 0; z < B.length; z++) { - u.push(F, B[z]); + for (let E = 0, F, A; E < v.length; E++) { + if (F = v[E], A = r[F], A.constructor === Array) { + for (z = 0; z < A.length; z++) { + u.push(F, A[z]); } } else { - u.push(F, B); + u.push(F, A); } } } @@ -999,12 +1003,12 @@ V.prototype.search = function(a, c, b, e) { u = !e && (this.worker || this.db) && []; for (let x = 0, r, E, F; x < l.length; x++) { E = l[x]; - let B; - D(E) || (B = E, E = B.field, a = B.query || a, c = B.limit || c, n = B.offset || n, k = B.suggest || k, g = this.store && (B.enrich || g)); + let A; + D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, h = A.suggest || h, g = this.store && (A.enrich || g)); if (e) { r = e[x]; } else { - if (v = B || b, z = this.index.get(E), m && (v.enrich = !1), u) { + if (v = A || b, z = this.index.get(E), m && (v.enrich = !1), u) { u[x] = z.search(a, c, v); v && g && (v.enrich = g); continue; @@ -1016,25 +1020,25 @@ V.prototype.search = function(a, c, b, e) { if (m && F) { v = []; z = 0; - for (let G = 0, I, Xa; G < m.length; G += 2) { + for (let G = 0, I, Wa; G < m.length; G += 2) { I = this.tag.get(m[G]); if (!I) { - if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { + if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), h) { continue; } else { return p ? d : new X(d); } } - if (Xa = (I = I && I.get(m[G + 1])) && I.length) { + if (Wa = (I = I && I.get(m[G + 1])) && I.length) { z++, v.push(I); - } else if (!k) { + } else if (!h) { return p ? d : new X(d); } } if (z) { - r = za(r, v, p); + r = za(r, v); F = r.length; - if (!F && !k) { + if (!F && !h) { return p ? r : new X(r); } z--; @@ -1067,18 +1071,18 @@ V.prototype.search = function(a, c, b, e) { } d[x] = {field:f[x], result:r}; } - return h ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; + return k ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; }; function Ka(a, c, b, e, d, f) { - let g, h, k; + let g, k, h; for (let m = 0, n, t, p, q, y; m < a.length; m++) { n = a[m].result; t = a[m].field; q = b.get(t); p = q.encoder; - k = q.tokenize; + h = q.tokenize; y = d[e.indexOf(t)]; - p !== g && (g = p, h = g.encode(c)); + p !== g && (g = p, k = g.encode(c)); for (let u = 0; u < n.length; u++) { let v = ""; var l = J(n[u].doc, y); @@ -1088,8 +1092,8 @@ function Ka(a, c, b, e, d, f) { r = z[x]; E = l[x]; let F; - for (let B = 0, G; B < h.length; B++) { - if (G = h[B], "strict" === k) { + for (let A = 0, G; A < k.length; A++) { + if (G = k[A], "strict" === h) { if (r === G) { v += (v ? " " : "") + f.replace("$1", E); F = !0; @@ -1116,14 +1120,14 @@ function Ja(a, c) { for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = e[k]) { + for (let k = 0, h, l, m; k < g.length; k++) { + if (l = g[k], h = l.id, m = e[h]) { m.push(f.field); } else { if (b.length === c) { return b; } - l.field = e[k] = [f.field]; + l.field = e[h] = [f.field]; b.push(l); } } @@ -1271,9 +1275,9 @@ w.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 h = this; + const k = this; return c.then(function() { - return h.export(a, g, b + 1); + return k.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -1396,7 +1400,7 @@ var Va = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Na, LatinSimple:{no }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { return ("" + a).replace(Ua, " "); }}}; -const Wa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +const Xa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1414,34 +1418,34 @@ O.prototype.add = function(a, c, b, e) { case "full": if (2 < d) { for (f = 0; f < d; f++) { - for (var h = d; h > f; h--) { - g = q.substring(f, h); - var k = this.score ? this.score(c, q, p, g, f) : Ya(t, e, p, d, f); - Z(this, m, g, k, a, b); + for (var k = d; k > f; k--) { + g = q.substring(f, k); + var h = this.score ? this.score(c, q, p, g, f) : Ya(t, e, p, d, f); + Z(this, m, g, h, a, b); } } break; } case "reverse": if (1 < d) { - for (h = d - 1; 0 < h; h--) { - g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : Ya(t, e, p, d, h), Z(this, m, g, k, a, b); + for (k = d - 1; 0 < k; k--) { + g = q[k] + g, h = this.score ? this.score(c, q, p, g, k) : Ya(t, e, p, d, k), Z(this, m, g, h, a, b); } g = ""; } case "forward": if (1 < d) { - for (h = 0; h < d; h++) { - g += q[h], Z(this, m, g, f, a, b); + for (k = 0; k < d; k++) { + g += q[k], Z(this, m, g, f, a, b); } break; } default: if (Z(this, m, q, f, a, b), n && 1 < e && p < e - 1) { - for (d = C(), g = this.S, f = q, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { - if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { + for (d = C(), g = this.S, f = q, k = Math.min(n + 1, e - p), d[f] = 1, h = 1; h < k; h++) { + if ((q = c[this.rtl ? e - 1 - p - h : p + h]) && !d[q]) { d[q] = 1; - const y = this.score ? this.score(c, f, p, q, k) : Ya(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; + const y = this.score ? this.score(c, f, p, q, h) : Ya(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, y, a, b, u ? q : f); } } @@ -1455,9 +1459,9 @@ O.prototype.add = function(a, c, b, e) { return this; }; function Z(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); + let k = g ? a.ctx : a.map, h; + if (!c[b] || g && !(h = c[b])[g]) { + g ? (c = h || (c[b] = C()), 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 Ya(a, c, b, e, d) { @@ -1472,35 +1476,35 @@ function Ya(a, c, b, e, d) { d = b.offset || 0; var f = b.context; var g = b.suggest; - var h = !0; - var k = b.resolution; + var k = !0; + var h = b.resolution; } else { - h = !0; + k = !0; } - b = this.encoder.encode(a); - a = b.length; - c = c || (h ? 100 : 0); - if (1 === a) { - return Za.call(this, b[0], "", c, d, h); + a = this.encoder.encode(a); + b = a.length; + c = c || (k ? 100 : 0); + if (1 === b) { + return g = c, (c = Za(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; } f = this.depth && !1 !== f; - if (2 === a && f && !g) { - return Za.call(this, b[0], b[1], c, d, h); + if (2 === b && f && !g) { + return g = c, (c = Za(this, a[0], a[1])) && c.length ? Aa.call(this, c, g, d) : []; } - h = C(); + k = C(); let l = 0; - if (1 < a && f) { - var m = b[0]; + if (1 < b && f) { + var m = a[0]; l = 1; } - k || 0 === k || (k = m ? this.S : this.resolution); - for (let q, y; l < a; l++) { - if ((y = b[l]) && !h[y]) { - h[y] = 1; - q = $a(this, y, m); + h || 0 === h || (h = m ? this.S : this.resolution); + for (let q, y; l < b; l++) { + if ((y = a[l]) && !k[y]) { + k[y] = 1; + q = Za(this, y, m); a: { f = q; - var n = e, t = g, p = k; + var n = e, t = g, p = h; let u = []; if (f && f.length) { if (f.length <= p) { @@ -1527,27 +1531,23 @@ function Ya(a, c, b, e, d) { } m && (g && q && e.length || (m = y)); } - g && m && l === a - 1 && !e.length && (m = "", l = -1, h = C()); + g && m && l === b - 1 && !e.length && (m = "", l = -1, k = C()); } a: { - m = e.length; a = e; - if (1 < m) { - a = xa(e, k, c, d, g); - } else if (1 === m) { - g = Aa.call(null, e[0], c, d); + e = a.length; + m = a; + if (1 < e) { + m = xa(a, h, c, d, g); + } else if (1 === e) { + g = Aa.call(null, a[0], c, d); break a; } - g = a; + g = m; } return g; }; -function Za(a, c, b, e, d) { - a = $a(this, a, c); - d = !0; - return a && a.length ? d ? Aa.call(this, a, b, e) : new X(a) : d ? [] : new X(); -} -function $a(a, c, b) { +function Za(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); @@ -1568,14 +1568,14 @@ function $a(a, c, b) { } } } else { - ab(this.map, a), this.depth && ab(this.ctx, a); + $a(this.map, a), this.depth && $a(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function ab(a, c) { +function $a(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1590,7 +1590,7 @@ function ab(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = ab(e[1], c); + const d = e[0], f = $a(e[1], c); f ? b += f : a.delete(d); } } @@ -1602,7 +1602,7 @@ function ab(a, c) { } if (a) { var b = D(a) ? a : a.preset; - b && (Wa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Wa[b], a)); + b && (Xa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Xa[b], a)); } else { a = {}; } @@ -1610,7 +1610,7 @@ function ab(a, c) { const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = b = a.tokenize || "strict"; + this.tokenize = (b = a.tokenize) && "default" !== b || "strict"; this.depth = "strict" === b && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; @@ -1642,7 +1642,7 @@ w.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function bb(a) { +function ab(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1650,7 +1650,7 @@ function bb(a) { } } else { for (const b of a) { - const e = b[0], d = bb(b[1]); + const e = b[0], d = ab(b[1]); d ? c += d : a.delete(e); } } @@ -1660,8 +1660,8 @@ w.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); + ab(this.map); + this.depth && ab(this.ctx); return this; }; w.searchCache = Ma; @@ -1715,18 +1715,18 @@ w.serialize = function(a = !0) { c = "index.reg=new Set([" + c + "]);"; e = ""; for (var d of this.map.entries()) { - var f = d[0], g = d[1], h = ""; + var f = d[0], g = d[1], k = ""; for (let m = 0, n; m < g.length; m++) { n = g[m] || [""]; - var k = ""; + var h = ""; for (var l = 0; l < n.length; l++) { - k += (k ? "," : "") + ("string" === b ? '"' + n[l] + '"' : n[l]); + h += (h ? "," : "") + ("string" === b ? '"' + n[l] + '"' : n[l]); } - k = "[" + k + "]"; - h += (h ? "," : "") + k; + h = "[" + h + "]"; + k += (k ? "," : "") + h; } - h = '["' + f + '",[' + h + "]]"; - e += (e ? "," : "") + h; + k = '["' + f + '",[' + k + "]]"; + e += (e ? "," : "") + k; } e = "index.map=new Map([" + e + "]);"; d = ""; @@ -1735,20 +1735,20 @@ w.serialize = function(a = !0) { g = m[1]; for (const n of g.entries()) { g = n[0]; - h = n[1]; - k = ""; - for (let t = 0, p; t < h.length; t++) { - p = h[t] || [""]; + k = n[1]; + h = ""; + for (let t = 0, p; t < k.length; t++) { + p = k[t] || [""]; l = ""; for (let q = 0; q < p.length; q++) { l += (l ? "," : "") + ("string" === b ? '"' + p[q] + '"' : p[q]); } l = "[" + l + "]"; - k += (k ? "," : "") + l; + h += (h ? "," : "") + l; } - k = 'new Map([["' + g + '",[' + k + "]]])"; - k = '["' + f + '",' + k + "]"; - d += (d ? "," : "") + k; + h = 'new Map([["' + g + '",[' + h + "]]])"; + h = '["' + f + '",' + h + "]"; + d += (d ? "," : "") + h; } } d = "index.ctx=new Map([" + d + "]);"; diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index 5519abc..1230346 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.108 (Bundle) + * FlexSearch.js v0.8.109 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var v;function A(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} +var v;function B(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 C(){return Object.create(null)}function D(a){return"string"===typeof a} function H(a){return"object"===typeof a}function I(a,c){if(D(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);ha||(this.mapper=new Map(ba));this.rtl=A(a.rtl,!1,this.rtl);this.dedupe=A(a.dedupe,!1,this.dedupe);this.filter=A((b=a.filter)&&new Set(b),null,this.filter);this.matcher=A((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=A((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= -A((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);if(this.cache=b=A(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.D="";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.D+= +v.assign=function(a){this.normalize=B(a.normalize,!0,this.normalize);let c=a.include,b=c||a.exclude||a.split,e;if(b||""===b){if("object"===typeof b&&b.constructor!==RegExp){let d="";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("["+(c?"^":"")+d+"]+","u")}catch(f){this.split=/\s+/}}else this.split=b,e=!1===b||2>"a1a".split(b).length; +this.numeric=B(a.numeric,e)}else{try{this.split=B(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=B(a.numeric,B(this.numeric,!0))}this.prepare=B(a.prepare,null,this.prepare);this.finalize=B(a.finalize,null,this.finalize);ha||(this.mapper=new Map(ba));this.rtl=B(a.rtl,!1,this.rtl);this.dedupe=B(a.dedupe,!1,this.dedupe);this.filter=B((b=a.filter)&&new Set(b),null,this.filter);this.matcher=B((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=B((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= +B((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=B(a.replacer,null,this.replacer);this.minlength=B(a.minlength,1,this.minlength);this.maxlength=B(a.maxlength,0,this.maxlength);if(this.cache=b=B(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.D="";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.D+= (this.D?"|":"")+d;return this};v.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&L(this);return this};v.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&L(this);return this};v.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&&L(this);return this};v.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; v.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(L,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.stemmer.get(k)),g.lengththis.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&d +[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,k;fthis.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d this.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;const c=a.task,b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(a=a.factory)?(Function("return "+a)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e=[N.export]);"import"===c?await N.import.call(M,M):d=M[c].apply(M,e);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let Q,ka;const R={},S={};function la(a){Q=0;R[a]=S[a]} function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);Q||(Q=setTimeout(la,0,a),ka=Date.now());S[a]||(S[a]=R[a]=1E3);if(!--R[a]){R[a]=S[a]=S[a]*this.priority*this.priority*3/(Date.now()-ka)|0||1;Q=clearTimeout(Q);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let T=0; -function ma(a={}){function c(g){function h(k){k=k.data||k;const l=k.id,m=l&&d.h[l];m&&(m(k.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++T]=function(){k(d)};d.worker.postMessage({id:T,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==ma)return new ma(a);let b="undefined"!==typeof self?self._factory:"undefined"!== +function ma(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++T]=function(){h(d)};d.worker.postMessage({id:T,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==ma)return new ma(a);let b="undefined"!==typeof self?self._factory:"undefined"!== typeof window?window._factory:null;b&&(b=b.toString());const e="undefined"===typeof window,d=this,f=na(b,e,a.worker);return f.then?f.then(function(g){return c.call(d,g)}):c.call(this,f)}U("add");U("append");U("search");U("update");U("remove");U("clear");U("export");U("import");ja(ma.prototype); function U(a){ma.prototype[a]=async function(){const c=this,b=[].slice.call(arguments);var e=b[b.length-1];let d;"function"===typeof e&&(d=e,b.splice(b.length-1,1));e=new Promise(function(f){c.h[++T]=f;c.worker.postMessage({task:a,id:T,args:b})});return d?(e.then(d),this):e}} function na(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ia.toString()],{type:"text/javascript"}))):new window.Worker(D(b)?b:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"),{type:"module"})};function oa(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function pa(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?W.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; -function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; -function Ea(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Fa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let 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?W.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?W.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}} +function Ka(a,c,b,e,d,f){let g,k,h;for(let m=0,n,t,p,q,y;mb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}} function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};const Oa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Pa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;const Ua=/[\x00-\x7F]+/g;var Va={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Oa,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):Ya(t,e,p,d,f);Z(this,m,g,k,a,b)}break}case "reverse":if(1< -d){for(h=d-1;0g?0:1),e,p,h-1,k-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=C()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Ya(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else ab(this.map,a),this.depth&&ab(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function ab(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function bb(a){let c=0;if(a.constructor===Array)for(let b=0,e;bf;k--){g=q.substring(f,k);var h=this.score?this.score(c,q,p,g,f):Ya(t,e,p,d,f);Z(this,m,g,h,a,b)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,p,k-1,h-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),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 Ya(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else $a(this.map,a),this.depth&&$a(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function $a(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function ab(a){let c=0;if(a.constructor===Array)for(let b=0,e;bc||d)a=a.slice(d,d+c);e&&(a=X.call(this,a));return a}} -function X(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cc)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};R.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Rb(this.map,a),this.depth&&Rb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Mb(this));this.cache&&this.cache.remove(a);return this}; -function Rb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;d "a1a".split(b).length; + this.split = b, f = !1 === b || 2 > "a1a".split(b).length; } - this.numeric = u(a.numeric, d); + this.numeric = r(a.numeric, f); } else { try { - this.split = u(this.split, ba); - } catch (e) { + this.split = r(this.split, y); + } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = u(a.numeric, u(this.numeric, !0)); + this.numeric = r(a.numeric, r(this.numeric, !0)); } - this.prepare = u(a.prepare, null, this.prepare); - this.finalize = u(a.finalize, null, this.finalize); - this.rtl = u(a.rtl, !1, this.rtl); - this.dedupe = u(a.dedupe, !1, this.dedupe); - this.filter = u((b = a.filter) && new Set(b), null, this.filter); - this.matcher = u((b = a.matcher) && new Map(b), null, this.matcher); - this.mapper = u((b = a.mapper) && new Map(b), null, this.mapper); - this.stemmer = u((b = a.stemmer) && new Map(b), null, this.stemmer); - this.replacer = u(a.replacer, null, this.replacer); - this.minlength = u(a.minlength, 1, this.minlength); - this.maxlength = u(a.maxlength, 0, this.maxlength); - if (this.cache = b = u(a.cache, !0, this.cache)) { - this.l = null, this.C = "number" === typeof b ? b : 2e5, this.i = new Map(), this.j = new Map(), this.s = this.o = 128; + this.prepare = r(a.prepare, null, this.prepare); + this.finalize = r(a.finalize, null, this.finalize); + this.rtl = r(a.rtl, !1, this.rtl); + this.dedupe = r(a.dedupe, !1, this.dedupe); + this.filter = r((b = a.filter) && new Set(b), null, this.filter); + this.matcher = r((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = r((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = r((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = r(a.replacer, null, this.replacer); + this.minlength = r(a.minlength, 1, this.minlength); + this.maxlength = r(a.maxlength, 0, this.maxlength); + if (this.cache = b = r(a.cache, !0, this.cache)) { + this.l = null, this.A = "number" === typeof b ? b : 2e5, this.i = new Map(), this.j = new Map(), this.o = this.m = 128; } this.g = ""; - this.v = null; + this.s = null; this.h = ""; - this.A = null; + this.u = null; if (this.matcher) { - for (const e of this.matcher.keys()) { - this.g += (this.g ? "|" : "") + e; + for (const d of this.matcher.keys()) { + this.g += (this.g ? "|" : "") + d; } } if (this.stemmer) { - for (const e of this.stemmer.keys()) { - this.h += (this.h ? "|" : "") + e; + for (const d of this.stemmer.keys()) { + this.h += (this.h ? "|" : "") + d; } } return this; }; -t.addStemmer = function(a, c) { +q.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); this.h += (this.h ? "|" : "") + a; - this.A = null; - this.cache && z(this); + this.u = null; + this.cache && G(this); return this; }; -t.addFilter = function(a) { +q.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); - this.cache && z(this); + this.cache && G(this); return this; }; -t.addMapper = function(a, c) { +q.addMapper = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -150,10 +143,10 @@ t.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && z(this); + this.cache && G(this); return this; }; -t.addMatcher = function(a, c) { +q.addMatcher = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -163,632 +156,185 @@ t.addMatcher = function(a, c) { this.matcher || (this.matcher = new Map()); this.matcher.set(a, c); this.g += (this.g ? "|" : "") + a; - this.v = null; - this.cache && z(this); + this.s = null; + this.cache && G(this); return this; }; -t.addReplacer = function(a, c) { +q.addReplacer = function(a, c) { if ("string" === typeof a) { return this.addMatcher(a, c); } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && z(this); + this.cache && G(this); return this; }; -t.encode = function(a) { - if (this.cache && a.length <= this.o) { +q.encode = function(a) { + if (this.cache && a.length <= this.m) { if (this.l) { if (this.i.has(a)) { return this.i.get(a); } } else { - this.l = setTimeout(z, 50, this); + this.l = setTimeout(G, 50, this); } } - this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = x ? a.normalize("NFKD").replace(x, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = D ? a.normalize("NFKD").replace(D, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(da, "$1 $2").replace(ea, "$1 $2").replace(ca, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(A, "$1 $2").replace(B, "$1 $2").replace(z, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let b = [], d = this.split || "" === this.split ? a.split(this.split) : a; - for (let g = 0, f, h; g < d.length; g++) { - if ((f = h = d[g]) && !(f.length < this.minlength)) { + let b = [], f = this.split || "" === this.split ? a.split(this.split) : a; + for (let g = 0, e, h; g < f.length; g++) { + if ((e = h = f[g]) && !(e.length < this.minlength)) { if (c) { - b.push(f); + b.push(e); } else { - if (!this.filter || !this.filter.has(f)) { - if (this.cache && f.length <= this.s) { + if (!this.filter || !this.filter.has(e)) { + if (this.cache && e.length <= this.o) { if (this.l) { - var e = this.j.get(f); - if (e || "" === e) { - e && b.push(e); + var d = this.j.get(e); + if (d || "" === d) { + d && b.push(d); continue; } } else { - this.l = setTimeout(z, 50, this); + this.l = setTimeout(G, 50, this); } } - this.stemmer && 2 < f.length && (this.A || (this.A = new RegExp("(?!^)(" + this.h + ")$")), f = f.replace(this.A, k => this.stemmer.get(k)), f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); - if (f && (this.mapper || this.dedupe && 1 < f.length)) { - e = ""; - for (let k = 0, l = "", n, m; k < f.length; k++) { - n = f.charAt(k), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (e += m) : e += l = n); + this.stemmer && 2 < e.length && (this.u || (this.u = new RegExp("(?!^)(" + this.h + ")$")), e = e.replace(this.u, k => this.stemmer.get(k)), e.length < this.minlength || this.filter && this.filter.has(e)) && (e = ""); + if (e && (this.mapper || this.dedupe && 1 < e.length)) { + d = ""; + for (let k = 0, n = "", m, u; k < e.length; k++) { + m = e.charAt(k), m === n && this.dedupe || ((u = this.mapper && this.mapper.get(m)) || "" === u ? u === n && this.dedupe || !(n = u) || (d += u) : d += n = m); } - f = e; + e = d; } - this.matcher && 1 < f.length && (this.v || (this.v = new RegExp("(" + this.g + ")", "g")), f = f.replace(this.v, k => this.matcher.get(k))); - if (f && this.replacer) { - for (e = 0; f && e < this.replacer.length; e += 2) { - f = f.replace(this.replacer[e], this.replacer[e + 1]); + this.matcher && 1 < e.length && (this.s || (this.s = new RegExp("(" + this.g + ")", "g")), e = e.replace(this.s, k => this.matcher.get(k))); + if (e && this.replacer) { + for (d = 0; e && d < this.replacer.length; d += 2) { + e = e.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.s && (this.j.set(h, f), this.j.size > this.C && (this.j.clear(), this.s = this.s / 1.1 | 0)); - f && b.push(f); + this.cache && h.length <= this.o && (this.j.set(h, e), this.j.size > this.A && (this.j.clear(), this.o = this.o / 1.1 | 0)); + e && b.push(e); } } } } this.finalize && (b = this.finalize(b) || b); - this.cache && a.length <= this.o && (this.i.set(a, b), this.i.size > this.C && (this.i.clear(), this.o = this.o / 1.1 | 0)); + this.cache && a.length <= this.m && (this.i.set(a, b), this.i.size > this.A && (this.i.clear(), this.m = this.m / 1.1 | 0)); return b; }; -function z(a) { +function G(a) { a.l = null; a.i.clear(); a.j.clear(); } -;let A, C; -async function fa(a) { - a = a.data; - const c = a.task, b = a.id; - let d = a.args; - switch(c) { - case "init": - C = a.options || {}; - (a = a.factory) ? (Function("return " + a)()(self), A = new self.FlexSearch.Index(C), delete self.FlexSearch) : A = new D(C); - postMessage({id:b}); - break; - default: - let e; - "export" === c && (d = [C.export]); - "import" === c ? await C.import.call(A, A) : e = A[c].apply(A, d); - postMessage("search" === c ? {id:b, msg:e} : {id:b}); - } -} -;let E, F; -const G = {}, H = {}; -function ha(a) { - E = 0; - G[a] = H[a]; -} -function I(a) { - this[a + "Async"] = function() { - const c = arguments; - var b = c[c.length - 1]; - let d; - "function" === typeof b && (d = b, delete c[c.length - 1]); - E || (E = setTimeout(ha, 0, a), F = Date.now()); - H[a] || (H[a] = G[a] = 1000); - if (!--G[a]) { - G[a] = H[a] = H[a] * this.priority * this.priority * 3 / (Date.now() - F) | 0 || 1; - E = clearTimeout(E); - const g = this; - return new Promise(f => { - setTimeout(function() { - f(g[a + "Async"].apply(g, c)); - }, 0); - }); - } - const e = this[a].apply(this, c); - b = e.then ? e : new Promise(g => g(e)); - d && b.then(d); - return b; - }; -} -;let J = 0; -function K(a = {}) { - function c(f) { - function h(k) { - k = k.data || k; - const l = k.id, n = l && e.g[l]; - n && (n(k.msg), delete e.g[l]); - } - this.worker = f; - this.g = w(); - if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; - if (a.config) { - return new Promise(function(k) { - e.g[++J] = function() { - k(e); - }; - e.worker.postMessage({id:J, task:"init", factory:b, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:b, options:a}); - return this; - } - } - if (!this || this.constructor !== K) { - return new K(a); - } - let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - b && (b = b.toString()); - const d = "undefined" === typeof window, e = this, g = ia(b, d, a.worker); - return g.then ? g.then(function(f) { - return c.call(e, f); - }) : c.call(this, g); -} -L("add"); -L("append"); -L("search"); -L("update"); -L("remove"); -L("clear"); -L("export"); -L("import"); -var M = K.prototype; -I.call(M, "add"); -I.call(M, "append"); -I.call(M, "search"); -I.call(M, "update"); -I.call(M, "remove"); -function L(a) { - K.prototype[a] = async function() { - const c = this, b = [].slice.call(arguments); - var d = b[b.length - 1]; - let e; - "function" === typeof d && (e = d, b.splice(b.length - 1, 1)); - d = new Promise(function(g) { - c.g[++J] = g; - c.worker.postMessage({task:a, id:J, args:b}); - }); - return e ? (d.then(e), this) : d; - }; -} -function ia(a, c, b) { - return c ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + fa.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", - "module/worker/worker.js"), {type:"module"}); -} -;function ja(a, c, b, d, e) { - const g = a.length; - let f = [], h, k; - h = w(); - for (let l = 0, n, m, r, q; l < c; l++) { - for (let p = 0; p < g; p++) { - if (r = a[p], l < r.length && (n = r[l])) { - for (let v = 0; v < n.length; v++) { - m = n[v], (k = h[m]) ? h[m]++ : (k = 0, h[m] = 1), q = f[k] || (f[k] = []), q.push(m); - } - } - } - } - if (a = f.length) { - if (e) { - f = 1 < f.length ? la(f, b, d) : (f = f[0]).length > b || d ? f.slice(d, b + d) : f; - } else { - if (a < g) { - return []; - } - f = f[a - 1]; - if (b || d) { - if (f.length > b || d) { - f = f.slice(d, b + d); - } - } - } - } - return f; -} -function la(a, c, b) { - const d = [], e = w(); - let g; - var f = a.length; - let h; - for (let k = f - 1; 0 <= k; k--) { - if (h = (f = a[k]) && f.length) { - for (let l = 0; l < h; l++) { - if (g = f[l], !e[g]) { - if (e[g] = 1, b) { - b--; - } else { - if (d.push(g), d.length === c) { - return d; - } - } - } - } - } - } - return d; -} -;function N(a, c, b, d) { +;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, d ? O.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } - let e = []; - for (let g = 0, f, h; g < a.length; g++) { - if ((f = a[g]) && (h = f.length)) { + let f = []; + for (let d = 0, g, e; d < a.length; d++) { + if ((g = a[d]) && (e = g.length)) { if (b) { - if (b >= h) { - b -= h; + if (b >= e) { + b -= e; continue; } - b < h && (f = c ? f.slice(b, b + c) : f.slice(b), h = f.length, b = 0); + b < e && (g = c ? g.slice(b, b + c) : g.slice(b), e = g.length, b = 0); } - h > c && (f = f.slice(0, c), h = c); - if (!e.length && h >= c) { - return d ? O.call(this, f) : f; + e > c && (g = g.slice(0, c), e = c); + if (!f.length && e >= c) { + return g; } - e.push(f); - c -= h; + f.push(g); + c -= e; if (!c) { break; } } } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? O.call(this, e) : e; + return f = 1 < f.length ? [].concat.apply([], f) : f[0]; } -;function P(a, c, b) { - var d = b[0]; - if (d.then) { - return Promise.all(b).then(function(n) { - return a[c].apply(a, n); - }); - } - if (d[0] && d[0].index) { - return a[c].apply(a, d); - } - d = []; - let e = [], g = 0, f = 0, h, k, l; - for (let n = 0, m; n < b.length; n++) { - if (m = b[n]) { - let r; - if (m.constructor === Q) { - r = m.result; - } else if (m.constructor === Array) { - r = m; - } else { - if (g = m.limit || 0, f = m.offset || 0, l = m.suggest, k = m.resolve, h = m.enrich && k, m.index) { - m.resolve = !1, m.enrich = !1, r = m.index.search(m).result, m.resolve = k, m.enrich = h; - } else if (m.and) { - r = a.and(m.and); - } else if (m.or) { - r = a.or(m.or); - } else if (m.xor) { - r = a.xor(m.xor); - } else if (m.not) { - r = a.not(m.not); - } else { - continue; - } - } - if (r.then) { - e.push(r); - } else if (r.length) { - d[n] = r; - } else if (!l && ("and" === c || "xor" === c)) { - d = []; - break; - } - } - } - return {m:d, u:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; -} -;Q.prototype.or = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g} = P(this, "or", arguments); - return ma.call(this, a, c, b, d, e, g); -}; -function ma(a, c, b, d, e, g) { - if (c.length) { - const f = this; - return Promise.all(c).then(function(h) { - a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); - } - return ma.call(f, a, [], b, d, e, g); - }); - } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = la(a, b, d), d = 0)); - return g ? this.resolve(b, d, e) : this; -} -;Q.prototype.and = function() { - let a = this.result.length, c, b, d, e; - if (!a) { - const g = arguments[0]; - g && (a = !!g.suggest, e = g.resolve, c = g.limit, b = g.offset, d = g.enrich && e); - } - if (a) { - const {m:g, u:f, limit:h, offset:k, enrich:l, resolve:n, suggest:m} = P(this, "and", arguments); - return na.call(this, g, f, h, k, l, n, m); - } - return e ? this.resolve(c, b, d) : this; -}; -function na(a, c, b, d, e, g, f) { - if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { - a = []; - for (let l = 0, n; l < k.length; l++) { - (n = k[l]).length && (a[l] = n); - } - return na.call(h, a, [], b, d, e, g, f); - }); - } - if (a.length) { - if (this.result.length && a.unshift(this.result), 2 > a.length) { - this.result = a[0]; - } else { - if (c = aa(a)) { - return this.result = ja(a, c, b, d, f), g ? e ? O.call(this.index, this.result) : this.result : this; - } - this.result = []; - } - } else { - f || (this.result = a); - } - return g ? this.resolve(b, d, e) : this; -} -;Q.prototype.xor = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = P(this, "xor", arguments); - return oa.call(this, a, c, b, d, e, g, f); -}; -function oa(a, c, b, d, e, g, f) { - if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { - a = []; - for (let l = 0, n; l < k.length; l++) { - (n = k[l]).length && (a[l] = n); - } - return oa.call(h, a, [], b, d, e, g, f); - }); - } - if (a.length) { - if (this.result.length && a.unshift(this.result), 2 > a.length) { - this.result = a[0]; - } else { - return this.result = pa.call(this, a, b, d, g, this.g), g ? e ? O.call(this.index, this.result) : this.result : this; - } - } else { - f || (this.result = a); - } - return g ? this.resolve(b, d, e) : this; -} -function pa(a, c, b, d, e) { - const g = [], f = w(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); - for (let n = 0, m; n < l.length; n++) { - if (m = l[n]) { - for (let r = 0, q; r < m.length; r++) { - q = m[r], f[q] = f[q] ? 2 : 1; - } - } - } - } - } - for (let k = 0, l, n = 0; k < h; k++) { - for (let m = 0, r; m < a.length; m++) { - if (r = a[m]) { - if (l = r[k]) { - for (let q = 0, p; q < l.length; q++) { - if (p = l[q], 1 === f[p]) { - if (b) { - b--; - } else { - if (d) { - if (g.push(p), g.length === c) { - return g; - } - } else { - const v = k + (m ? e : 0); - g[v] || (g[v] = []); - g[v].push(p); - if (++n === c) { - return g; - } - } - } - } - } - } - } - } - } - return g; -} -;Q.prototype.not = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = P(this, "not", arguments); - return qa.call(this, a, c, b, d, e, g, f); -}; -function qa(a, c, b, d, e, g, f) { - if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { - a = []; - for (let l = 0, n; l < k.length; l++) { - (n = k[l]).length && (a[l] = n); - } - return qa.call(h, a, [], b, d, e, g, f); - }); - } - if (a.length && this.result.length) { - this.result = ra.call(this, a, b, d, g); - } else if (g) { - return this.resolve(b, d, e); - } - return g ? e ? O.call(this.index, this.result) : this.result : this; -} -function ra(a, c, b, d) { - const e = []; - a = new Set(a.flat().flat()); - for (let g = 0, f, h = 0; g < this.result.length; g++) { - if (f = this.result[g]) { - for (let k = 0, l; k < f.length; k++) { - if (l = f[k], !a.has(l)) { - if (b) { - b--; - } else { - if (d) { - if (e.push(l), e.length === c) { - return e; - } - } else { - if (e[g] || (e[g] = []), e[g].push(l), ++h === c) { - return e; - } - } - } - } - } - } - } - return e; -} -;function Q(a) { - if (!this || this.constructor !== Q) { - return new Q(a); - } - if (a && a.index) { - return a.resolve = !1, this.index = a.index, this.g = a.boost || 0, this.result = a.index.search(a).result, this; - } - this.index = null; - this.result = a || []; - this.g = 0; -} -Q.prototype.limit = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, d; b < this.result.length; b++) { - if (d = this.result[b]) { - if (d.length <= a) { - if (c[b] = d, a -= d.length, !a) { - break; - } - } else { - c[b] = d.slice(0, a); - break; - } - } - } - this.result = c; - } - return this; -}; -Q.prototype.offset = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, d; b < this.result.length; b++) { - if (d = this.result[b]) { - d.length <= a ? a -= d.length : (c[b] = d.slice(a), a = 0); - } - } - this.result = c; - } - return this; -}; -Q.prototype.boost = function(a) { - this.g += a; - return this; -}; -Q.prototype.resolve = function(a, c, b) { - const d = this.result, e = this.index; - this.result = this.index = null; - return d.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), N.call(e, d, a || 100, c, b)) : d; -}; -w(); -function O(a) { - if (!this || !this.store) { - return a; - } - const c = Array(a.length); - for (let b = 0, d; b < a.length; b++) { - d = a[b], c[b] = {id:d, doc:this.store.get(d)}; - } - return c; -} -;function S(a) { +;w(); +function I(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.g = ""; } -S.prototype.set = function(a, c) { +I.prototype.set = function(a, c) { this.cache.set(this.g = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -S.prototype.get = function(a) { +I.prototype.get = function(a) { const c = this.cache.get(a); c && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c)); return c; }; -S.prototype.remove = function(a) { +I.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -S.prototype.clear = function() { +I.prototype.clear = function() { this.cache.clear(); this.g = ""; }; -const sa = {normalize:function(a) { +const J = {normalize:function(a) { return a.toLowerCase(); }}; -const ta = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -D.prototype.add = function(a, c, b, d) { +const K = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +L.prototype.add = function(a, c, b, f) { if (c && (a || 0 === a)) { - if (!d && !b && this.reg.has(a)) { + if (!f && !b && this.reg.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); - if (d = c.length) { - const l = w(), n = w(), m = this.depth, r = this.resolution; - for (let q = 0; q < d; q++) { - let p = c[this.rtl ? d - 1 - q : q]; - var e = p.length; - if (e && (m || !n[p])) { - var g = this.score ? this.score(c, p, q, null, 0) : T(r, d, q), f = ""; + if (f = c.length) { + const n = w(), m = w(), u = this.depth, C = this.resolution; + for (let p = 0; p < f; p++) { + let l = c[this.rtl ? f - 1 - p : p]; + var d = l.length; + if (d && (u || !m[l])) { + var g = this.score ? this.score(c, l, p, null, 0) : M(C, f, p), e = ""; switch(this.tokenize) { case "full": - if (2 < e) { - for (g = 0; g < e; g++) { - for (var h = e; h > g; h--) { - f = p.substring(g, h); - var k = this.score ? this.score(c, p, q, f, g) : T(r, d, q, e, g); - U(this, n, f, k, a, b); + if (2 < d) { + for (g = 0; g < d; g++) { + for (var h = d; h > g; h--) { + e = l.substring(g, h); + var k = this.score ? this.score(c, l, p, e, g) : M(C, f, p, d, g); + N(this, m, e, k, a, b); } } break; } case "reverse": - if (1 < e) { - for (h = e - 1; 0 < h; h--) { - f = p[h] + f, k = this.score ? this.score(c, p, q, f, h) : T(r, d, q, e, h), U(this, n, f, k, a, b); + if (1 < d) { + for (h = d - 1; 0 < h; h--) { + e = l[h] + e, k = this.score ? this.score(c, l, p, e, h) : M(C, f, p, d, h), N(this, m, e, k, a, b); } - f = ""; + e = ""; } case "forward": - if (1 < e) { - for (h = 0; h < e; h++) { - f += p[h], U(this, n, f, g, a, b); + if (1 < d) { + for (h = 0; h < d; h++) { + e += l[h], N(this, m, e, g, a, b); } break; } default: - if (U(this, n, p, g, a, b), m && 1 < d && q < d - 1) { - for (e = w(), f = this.B, g = p, h = Math.min(m + 1, d - q), e[g] = 1, k = 1; k < h; k++) { - if ((p = c[this.rtl ? d - 1 - q - k : q + k]) && !e[p]) { - e[p] = 1; - const v = this.score ? this.score(c, g, q, p, k) : T(f + (d / 2 > f ? 0 : 1), d, q, h - 1, k - 1), B = this.bidirectional && p > g; - U(this, l, B ? g : p, v, a, b, B ? p : g); + if (N(this, m, l, g, a, b), u && 1 < f && p < f - 1) { + for (d = w(), e = this.v, g = l, h = Math.min(u + 1, f - p), d[g] = 1, k = 1; k < h; k++) { + if ((l = c[this.rtl ? f - 1 - p - k : p + k]) && !d[l]) { + d[l] = 1; + const v = this.score ? this.score(c, g, p, l, k) : M(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; + N(this, n, t ? g : l, v, a, b, t ? l : g); } } } @@ -800,134 +346,182 @@ D.prototype.add = function(a, c, b, d) { } return this; }; -function U(a, c, b, d, e, g, f) { - let h = f ? a.ctx : a.map, k; - if (!c[b] || f && !(k = c[b])[f]) { - f ? (c = k || (c[b] = w()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.reg.get(e)) ? c.push(h) : a.reg.set(e, [h]))); +function N(a, c, b, f, d, g, e) { + let h = e ? a.ctx : a.map, k; + if (!c[b] || e && !(k = c[b])[e]) { + e ? (c = k || (c[b] = w()), c[e] = 1, (k = h.get(e)) ? h = k : h.set(e, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[f] || (h[f] = []), g && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function T(a, c, b, d, e) { - return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0; +function M(a, c, b, f, d) { + return b && 1 < a ? c + (f || 0) <= a ? b + (d || 0) : (a - 1) / (c + (f || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;D.prototype.search = function(a, c, b) { +;L.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); - var d = [], e = 0; + var f = [], d = 0; if (b) { a = b.query || a; c = b.limit || c; - e = b.offset || 0; + d = b.offset || 0; var g = b.context; - var f = b.suggest; + var e = b.suggest; var h = !0; var k = b.resolution; } else { h = !0; } - b = this.encoder.encode(a); - a = b.length; + a = this.encoder.encode(a); + b = a.length; c = c || (h ? 100 : 0); - if (1 === a) { - return ua.call(this, b[0], "", c, e, h); + if (1 === b) { + return e = d, (d = O(this, a[0], "")) && d.length ? H.call(this, d, c, e) : []; } g = this.depth && !1 !== g; - if (2 === a && g && !f) { - return ua.call(this, b[0], b[1], c, e, h); + if (2 === b && g && !e) { + return e = d, (d = O(this, a[0], a[1])) && d.length ? H.call(this, d, c, e) : []; } h = w(); - let l = 0; - if (1 < a && g) { - var n = b[0]; - l = 1; + var n = 0; + if (1 < b && g) { + var m = a[0]; + n = 1; } - k || 0 === k || (k = n ? this.B : this.resolution); - for (let p, v; l < a; l++) { - if ((v = b[l]) && !h[v]) { + k || 0 === k || (k = m ? this.v : this.resolution); + for (let l, v; n < b; n++) { + if ((v = a[n]) && !h[v]) { h[v] = 1; - p = va(this, v, n); + l = O(this, v, m); a: { - g = p; - var m = d, r = f, q = k; - let B = []; + g = l; + var u = f, C = e, p = k; + let t = []; if (g && g.length) { - if (g.length <= q) { - m.push(g); - p = void 0; + if (g.length <= p) { + u.push(g); + l = void 0; break a; } - for (let R = 0, ka; R < q; R++) { - if (ka = g[R]) { - B[R] = ka; + for (let x = 0, E; x < p; x++) { + if (E = g[x]) { + t[x] = E; } } - if (B.length) { - m.push(B); - p = void 0; + if (t.length) { + u.push(t); + l = void 0; break a; } } - p = r ? void 0 : B; + l = C ? void 0 : t; } - if (p) { - d = p; + if (l) { + f = l; break; } - n && (f && p && d.length || (n = v)); + m && (e && l && f.length || (m = v)); } - f && n && l === a - 1 && !d.length && (n = "", l = -1, h = w()); + e && m && n === b - 1 && !f.length && (m = "", n = -1, h = w()); } a: { - n = d.length; - a = d; - if (1 < n) { - a = ja(d, k, c, e, f); - } else if (1 === n) { - f = N.call(null, d[0], c, e); + a = f; + f = a.length; + m = a; + if (1 < f) { + b: { + f = e; + m = a.length; + e = []; + b = w(); + for (let l = 0, v, t, x, E; l < k; l++) { + for (n = 0; n < m; n++) { + if (x = a[n], l < x.length && (v = x[l])) { + for (g = 0; g < v.length; g++) { + t = v[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), E = e[h] || (e[h] = []), E.push(t); + } + } + } + } + if (a = e.length) { + if (f) { + if (1 < e.length) { + c: { + for (a = [], k = w(), f = e.length, h = f - 1; 0 <= h; h--) { + if (b = (f = e[h]) && f.length) { + for (n = 0; n < b; n++) { + if (m = f[n], !k[m]) { + if (k[m] = 1, d) { + d--; + } else { + if (a.push(m), a.length === c) { + break c; + } + } + } + } + } + } + } + } else { + a = (e = e[0]).length > c || d ? e.slice(d, c + d) : e; + } + e = a; + } else { + if (a < m) { + m = []; + break b; + } + e = e[a - 1]; + if (c || d) { + if (e.length > c || d) { + e = e.slice(d, c + d); + } + } + } + } + m = e; + } + } else if (1 === f) { + c = H.call(null, a[0], c, d); break a; } - f = a; + c = m; } - return f; + return c; }; -function ua(a, c, b, d, e) { - a = va(this, a, c); - e = !0; - return a && a.length ? e ? N.call(this, a, b, d) : new Q(a) : e ? [] : new Q(); -} -function va(a, c, b) { - let d; - b && (d = a.bidirectional && c > b) && (d = b, b = c, c = d); +function O(a, c, b) { + let f; + b && (f = a.bidirectional && c > b) && (f = b, b = c, c = f); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;D.prototype.remove = function(a, c) { +;L.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { - for (let d = 0, e; d < b.length; d++) { - if (e = b[d]) { - if (2 > e.length) { - e.pop(); + for (let f = 0, d; f < b.length; f++) { + if (d = b[f]) { + if (2 > d.length) { + d.pop(); } else { - const g = e.indexOf(a); - g === b.length - 1 ? e.pop() : e.splice(g, 1); + const g = d.indexOf(a); + g === b.length - 1 ? d.pop() : d.splice(g, 1); } } } } else { - V(this.map, a), this.depth && V(this.ctx, a); + P(this.map, a), this.depth && P(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function V(a, c) { +function P(a, c) { let b = 0; if (a.constructor === Array) { - for (let d = 0, e, g; d < a.length; d++) { - if ((e = a[d]) && e.length) { - if (g = e.indexOf(c), 0 <= g) { - 1 < e.length ? (e.splice(g, 1), b++) : delete a[d]; + for (let f = 0, d, g; f < a.length; f++) { + if ((d = a[f]) && d.length) { + if (g = d.indexOf(c), 0 <= g) { + 1 < d.length ? (d.splice(g, 1), b++) : delete a[f]; break; } else { b++; @@ -935,100 +529,100 @@ function V(a, c) { } } } else { - for (let d of a.entries()) { - const e = d[0], g = V(d[1], c); - g ? b += g : a.delete(e); + for (let f of a.entries()) { + const d = f[0], g = P(f[1], c); + g ? b += g : a.delete(d); } } return b; } -;function D(a, c) { - if (!this || this.constructor !== D) { - return new D(a); +;function L(a, c) { + if (!this || this.constructor !== L) { + return new L(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (ta[b] || console.warn("Preset not found: " + b), a = Object.assign({}, ta[b], a)); + b && (K[b] || console.warn("Preset not found: " + b), a = Object.assign({}, K[b], a)); } else { a = {}; } b = a.context; - const d = !0 === b ? {depth:1} : b || {}, e = a.encode || a.encoder || sa; - this.encoder = e.encode ? e : "object" === typeof e ? new y(e) : {encode:e}; + const f = !0 === b ? {depth:1} : b || {}, d = a.encode || a.encoder || J; + this.encoder = d.encode ? d : "object" === typeof d ? new F(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = b = a.tokenize || "strict"; - this.depth = "strict" === b && d.depth || 0; - this.bidirectional = !1 !== d.bidirectional; + this.tokenize = (b = a.tokenize) && "default" !== b || "strict"; + this.depth = "strict" === b && f.depth || 0; + this.bidirectional = !1 !== f.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.B = d.resolution || 3; - this.rtl = e.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new S(b); + this.v = f.resolution || 3; + this.rtl = d.rtl || a.rtl || !1; + this.cache = (b = a.cache || null) && new I(b); } -t = D.prototype; -t.clear = function() { +q = L.prototype; +q.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); this.cache && this.cache.clear(); return this; }; -t.append = function(a, c) { +q.append = function(a, c) { return this.add(a, c, !0); }; -t.contain = function(a) { +q.contain = function(a) { return this.reg.has(a); }; -t.update = function(a, c) { - const b = this, d = this.remove(a); - return d && d.then ? d.then(() => b.add(a, c)) : this.add(a, c); +q.update = function(a, c) { + const b = this, f = this.remove(a); + return f && f.then ? f.then(() => b.add(a, c)) : this.add(a, c); }; -function W(a) { +function Q(a) { let c = 0; if (a.constructor === Array) { - for (let b = 0, d; b < a.length; b++) { - (d = a[b]) && (c += d.length); + for (let b = 0, f; b < a.length; b++) { + (f = a[b]) && (c += f.length); } } else { for (const b of a) { - const d = b[0], e = W(b[1]); - e ? c += e : a.delete(d); + const f = b[0], d = Q(b[1]); + d ? c += d : a.delete(f); } } return c; } -t.cleanup = function() { +q.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - W(this.map); - this.depth && W(this.ctx); + Q(this.map); + this.depth && Q(this.ctx); return this; }; -t.searchCache = function(a, c, b) { +q.searchCache = function(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new S()); - let d = this.cache.get(a); - if (!d) { - d = this.search(a, c, b); - if (d.then) { - const e = this; - d.then(function(g) { - e.cache.set(a, g); + this.cache || (this.cache = new I()); + let f = this.cache.get(a); + if (!f) { + f = this.search(a, c, b); + if (f.then) { + const d = this; + f.then(function(g) { + d.cache.set(a, g); return g; }); } - this.cache.set(a, d); + this.cache.set(a, f); } - return d; + return f; }; -const X = {Index:D, Charset:null, Encoder:y, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Y = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; -let Z; -(Z = Y.define) && Z.amd ? Z([], function() { - return X; -}) : "object" === typeof Y.exports ? Y.exports = X : Y.FlexSearch = X; +const R = {Index:L, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, S = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; +let T; +(T = S.define) && T.amd ? T([], function() { + return R; +}) : "object" === typeof S.exports ? S.exports = R : S.FlexSearch = R; }(this||self)); diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index 03dee1f..b2b00e5 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -1,40 +1,27 @@ /**! - * FlexSearch.js v0.8.108 (Light) + * FlexSearch.js v0.8.109 (Light) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';var t;function u(a,c,b){const d=typeof b,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(b){if("function"===e&&d===e)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===e?c:a}function w(){return Object.create(null)} -function aa(a){let c=0;for(let b=0,d;b"a1a".split(b).length; -this.numeric=u(a.numeric,d)}else{try{this.split=u(this.split,ba)}catch(e){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.C="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.s=this.o=128;this.g="";this.v=null;this.h="";this.A=null;if(this.matcher)for(const e of this.matcher.keys())this.g+=(this.g?"|":"")+e;if(this.stemmer)for(const e of this.stemmer.keys())this.h+=(this.h?"|":"")+e;return this}; -t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.A=null;this.cache&&z(this);return this};t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&z(this);return this};t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.v=null;this.cache&&z(this);return this};t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&z(this);return this}; -t.encode=function(a){if(this.cache&&a.length<=this.o)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(z,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=x?a.normalize("NFKD").replace(x,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),f.lengththis.matcher.get(k)));if(f&&this.replacer)for(e=0;f&&ethis.C&& -(this.j.clear(),this.s=this.s/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.o&&(this.i.set(a,b),this.i.size>this.C&&(this.i.clear(),this.o=this.o/1.1|0));return b};function z(a){a.l=null;a.i.clear();a.j.clear()};let A,C;async function fa(a){a=a.data;const c=a.task,b=a.id;let d=a.args;switch(c){case "init":C=a.options||{};(a=a.factory)?(Function("return "+a)()(self),A=new self.FlexSearch.Index(C),delete self.FlexSearch):A=new D(C);postMessage({id:b});break;default:let e;"export"===c&&(d=[C.export]);"import"===c?await C.import.call(A,A):e=A[c].apply(A,d);postMessage("search"===c?{id:b,msg:e}:{id:b})}};let E,F;const G={},H={};function ha(a){E=0;G[a]=H[a]} -function I(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let d;"function"===typeof b&&(d=b,delete c[c.length-1]);E||(E=setTimeout(ha,0,a),F=Date.now());H[a]||(H[a]=G[a]=1E3);if(!--G[a]){G[a]=H[a]=H[a]*this.priority*this.priority*3/(Date.now()-F)|0||1;E=clearTimeout(E);const g=this;return new Promise(f=>{setTimeout(function(){f(g[a+"Async"].apply(g,c))},0)})}const e=this[a].apply(this,c);b=e.then?e:new Promise(g=>g(e));d&&b.then(d);return b}};let J=0; -function K(a={}){function c(f){function h(k){k=k.data||k;const l=k.id,n=l&&e.g[l];n&&(n(k.msg),delete e.g[l])}this.worker=f;this.g=w();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.g[++J]=function(){k(e)};e.worker.postMessage({id:J,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==K)return new K(a);let b="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;b&&(b=b.toString());const d="undefined"===typeof window,e=this,g=ia(b,d,a.worker);return g.then?g.then(function(f){return c.call(e,f)}):c.call(this,g)}L("add");L("append");L("search");L("update");L("remove");L("clear");L("export");L("import");var M=K.prototype;I.call(M,"add");I.call(M,"append");I.call(M,"search");I.call(M,"update");I.call(M,"remove"); -function L(a){K.prototype[a]=async function(){const c=this,b=[].slice.call(arguments);var d=b[b.length-1];let e;"function"===typeof d&&(e=d,b.splice(b.length-1,1));d=new Promise(function(g){c.g[++J]=g;c.worker.postMessage({task:a,id:J,args:b})});return e?(d.then(e),this):d}} -function ia(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+fa.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof b?b:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function ka(a,c,b,d,e){const g=a.length;let f=[],h,k;h=w();for(let l=0,n,m,r,q;lb||d?f.slice(d,b+d):f;else{if(ab||d)f=f.slice(d,b+d)}return f} -function la(a,c,b){const d=[],e=w();let g;var f=a.length;let h;for(let k=f-1;0<=k;k--)if(h=(f=a[k])&&f.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,d?O.call(this,a):a;let e=[];for(let g=0,f,h;g=h){b-=h;continue}bc&&(f=f.slice(0,c),h=c);if(!e.length&&h>=c)return d?O.call(this,f):f;e.push(f);c-=h;if(!c)break}e=1a.length?this.result=a[0]:(this.result=la(a,b,d),d=0));return g?this.resolve(b,d,e):this};Q.prototype.and=function(){let a=this.result.length,c,b,d,e;if(!a){const g=arguments[0];g&&(a=!!g.suggest,e=g.resolve,c=g.limit,b=g.offset,d=g.enrich&&e)}if(a){const {m:g,u:f,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=P(this,"and",arguments);return na.call(this,g,f,h,k,l,n,m)}return e?this.resolve(c,b,d):this}; -function na(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=aa(a))return this.result=ka(a,c,b,d,f),g?e?O.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(b,d,e):this};Q.prototype.xor=function(){const {m:a,u:c,limit:b,offset:d,enrich:e,resolve:g,suggest:f}=P(this,"xor",arguments);return oa.call(this,a,c,b,d,e,g,f)}; -function oa(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=pa.call(this,a,b,d,g,this.g),g?e?O.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(b,d,e):this} -function pa(a,c,b,d,e){const g=[],f=w();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)};S.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};S.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -S.prototype.clear=function(){this.cache.clear();this.g=""};const sa={normalize:function(a){return a.toLowerCase()}};const ta={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};D.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const l=w(),n=w(),m=this.depth,r=this.resolution;for(let q=0;qg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,q,f,g):T(r,d,q,e,g);U(this,n,f,k,a,b)}break}case "reverse":if(1< -e){for(h=e-1;0f?0:1),d,q,h-1,k-1),B=this.bidirectional&&p>g;U(this,l,B?g:p,v,a,b,B?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function U(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h])))}function T(a,c,b,d,e){return b&&1b)&&(d=b,b=c,c=d);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};D.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else V(this.map,a),this.depth&&V(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function V(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; -function W(a){let c=0;if(a.constructor===Array)for(let b=0,d;b"a1a".split(b).length; +this.numeric=r(a.numeric,f)}else{try{this.split=r(this.split,y)}catch(d){this.split=/\s+/}this.numeric=r(a.numeric,r(this.numeric,!0))}this.prepare=r(a.prepare,null,this.prepare);this.finalize=r(a.finalize,null,this.finalize);this.rtl=r(a.rtl,!1,this.rtl);this.dedupe=r(a.dedupe,!1,this.dedupe);this.filter=r((b=a.filter)&&new Set(b),null,this.filter);this.matcher=r((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=r((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=r((b=a.stemmer)&&new Map(b), +null,this.stemmer);this.replacer=r(a.replacer,null,this.replacer);this.minlength=r(a.minlength,1,this.minlength);this.maxlength=r(a.maxlength,0,this.maxlength);if(this.cache=b=r(a.cache,!0,this.cache))this.l=null,this.A="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.o=this.m=128;this.g="";this.s=null;this.h="";this.u=null;if(this.matcher)for(const d of this.matcher.keys())this.g+=(this.g?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.h+=(this.h?"|":"")+d;return this}; +q.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.u=null;this.cache&&G(this);return this};q.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&G(this);return this};q.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&G(this);return this};q.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; +q.encode=function(a){if(this.cache&&a.length<=this.m)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(G,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=D?a.normalize("NFKD").replace(D,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),e.lengththis.matcher.get(k)));if(e&&this.replacer)for(d=0;e&&dthis.A&& +(this.j.clear(),this.o=this.o/1.1|0));e&&b.push(e)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.m&&(this.i.set(a,b),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return b};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 f=[];for(let d=0,g,e;d=e){b-=e;continue}bc&&(g=g.slice(0,c),e=c);if(!f.length&&e>=c)return g;f.push(g);c-=e;if(!c)break}return f=1this.limit&&this.cache.delete(this.cache.keys().next().value)};I.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};I.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; +I.prototype.clear=function(){this.cache.clear();this.g=""};const J={normalize:function(a){return a.toLowerCase()}};const K={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};L.prototype.add=function(a,c,b,f){if(c&&(a||0===a)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(f=c.length){const n=w(),m=w(),u=this.depth,C=this.resolution;for(let p=0;pg;h--){e=l.substring(g,h);var k=this.score?this.score(c,l,p,e,g):M(C,f,p,d,g);N(this,m,e,k,a,b)}break}case "reverse":if(1< +d){for(h=d-1;0e?0:1),f,p,h-1,k-1),t=this.bidirectional&&l>g;N(this,n,t?g:l,v,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function N(a,c,b,f,d,g,e){let h=e?a.ctx:a.map,k;if(!c[b]||e&&!(k=c[b])[e])e?(c=k||(c[b]=w()),c[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function M(a,c,b,f,d){return b&&1c||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}m=e}else if(1===f){c=H.call(null,a[0],c,d);break a}c=m}return c}; +function O(a,c,b){let f;b&&(f=a.bidirectional&&c>b)&&(f=b,b=c,c=f);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};L.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 f=0,d;fd.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function P(a,c){let b=0;if(a.constructor===Array)for(let f=0,d,g;fb.add(a,c)):this.add(a,c)}; +function Q(a){let c=0;if(a.constructor===Array)for(let b=0,f;b "a1a".split(b).length; + this.split = b, f = !1 === b || 2 > "a1a".split(b).length; } - this.numeric = u(a.numeric, d); + this.numeric = r(a.numeric, f); } else { try { - this.split = u(this.split, ba); - } catch (e) { + this.split = r(this.split, y); + } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = u(a.numeric, u(this.numeric, !0)); + this.numeric = r(a.numeric, r(this.numeric, !0)); } - this.prepare = u(a.prepare, null, this.prepare); - this.finalize = u(a.finalize, null, this.finalize); - this.rtl = u(a.rtl, !1, this.rtl); - this.dedupe = u(a.dedupe, !1, this.dedupe); - this.filter = u((b = a.filter) && new Set(b), null, this.filter); - this.matcher = u((b = a.matcher) && new Map(b), null, this.matcher); - this.mapper = u((b = a.mapper) && new Map(b), null, this.mapper); - this.stemmer = u((b = a.stemmer) && new Map(b), null, this.stemmer); - this.replacer = u(a.replacer, null, this.replacer); - this.minlength = u(a.minlength, 1, this.minlength); - this.maxlength = u(a.maxlength, 0, this.maxlength); - if (this.cache = b = u(a.cache, !0, this.cache)) { - this.l = null, this.C = "number" === typeof b ? b : 2e5, this.i = new Map(), this.j = new Map(), this.s = this.o = 128; + this.prepare = r(a.prepare, null, this.prepare); + this.finalize = r(a.finalize, null, this.finalize); + this.rtl = r(a.rtl, !1, this.rtl); + this.dedupe = r(a.dedupe, !1, this.dedupe); + this.filter = r((b = a.filter) && new Set(b), null, this.filter); + this.matcher = r((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = r((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = r((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = r(a.replacer, null, this.replacer); + this.minlength = r(a.minlength, 1, this.minlength); + this.maxlength = r(a.maxlength, 0, this.maxlength); + if (this.cache = b = r(a.cache, !0, this.cache)) { + this.l = null, this.A = "number" === typeof b ? b : 2e5, this.i = new Map(), this.j = new Map(), this.o = this.m = 128; } this.g = ""; - this.v = null; + this.s = null; this.h = ""; - this.A = null; + this.u = null; if (this.matcher) { - for (const e of this.matcher.keys()) { - this.g += (this.g ? "|" : "") + e; + for (const d of this.matcher.keys()) { + this.g += (this.g ? "|" : "") + d; } } if (this.stemmer) { - for (const e of this.stemmer.keys()) { - this.h += (this.h ? "|" : "") + e; + for (const d of this.stemmer.keys()) { + this.h += (this.h ? "|" : "") + d; } } return this; }; -t.addStemmer = function(a, c) { +q.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); this.h += (this.h ? "|" : "") + a; - this.A = null; - this.cache && z(this); + this.u = null; + this.cache && G(this); return this; }; -t.addFilter = function(a) { +q.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); - this.cache && z(this); + this.cache && G(this); return this; }; -t.addMapper = function(a, c) { +q.addMapper = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -149,10 +142,10 @@ t.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && z(this); + this.cache && G(this); return this; }; -t.addMatcher = function(a, c) { +q.addMatcher = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -162,632 +155,185 @@ t.addMatcher = function(a, c) { this.matcher || (this.matcher = new Map()); this.matcher.set(a, c); this.g += (this.g ? "|" : "") + a; - this.v = null; - this.cache && z(this); + this.s = null; + this.cache && G(this); return this; }; -t.addReplacer = function(a, c) { +q.addReplacer = function(a, c) { if ("string" === typeof a) { return this.addMatcher(a, c); } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && z(this); + this.cache && G(this); return this; }; -t.encode = function(a) { - if (this.cache && a.length <= this.o) { +q.encode = function(a) { + if (this.cache && a.length <= this.m) { if (this.l) { if (this.i.has(a)) { return this.i.get(a); } } else { - this.l = setTimeout(z, 50, this); + this.l = setTimeout(G, 50, this); } } - this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = x ? a.normalize("NFKD").replace(x, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = D ? a.normalize("NFKD").replace(D, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(da, "$1 $2").replace(ea, "$1 $2").replace(ca, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(A, "$1 $2").replace(B, "$1 $2").replace(z, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let b = [], d = this.split || "" === this.split ? a.split(this.split) : a; - for (let g = 0, f, h; g < d.length; g++) { - if ((f = h = d[g]) && !(f.length < this.minlength)) { + let b = [], f = this.split || "" === this.split ? a.split(this.split) : a; + for (let g = 0, e, h; g < f.length; g++) { + if ((e = h = f[g]) && !(e.length < this.minlength)) { if (c) { - b.push(f); + b.push(e); } else { - if (!this.filter || !this.filter.has(f)) { - if (this.cache && f.length <= this.s) { + if (!this.filter || !this.filter.has(e)) { + if (this.cache && e.length <= this.o) { if (this.l) { - var e = this.j.get(f); - if (e || "" === e) { - e && b.push(e); + var d = this.j.get(e); + if (d || "" === d) { + d && b.push(d); continue; } } else { - this.l = setTimeout(z, 50, this); + this.l = setTimeout(G, 50, this); } } - this.stemmer && 2 < f.length && (this.A || (this.A = new RegExp("(?!^)(" + this.h + ")$")), f = f.replace(this.A, k => this.stemmer.get(k)), f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); - if (f && (this.mapper || this.dedupe && 1 < f.length)) { - e = ""; - for (let k = 0, l = "", n, m; k < f.length; k++) { - n = f.charAt(k), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (e += m) : e += l = n); + this.stemmer && 2 < e.length && (this.u || (this.u = new RegExp("(?!^)(" + this.h + ")$")), e = e.replace(this.u, k => this.stemmer.get(k)), e.length < this.minlength || this.filter && this.filter.has(e)) && (e = ""); + if (e && (this.mapper || this.dedupe && 1 < e.length)) { + d = ""; + for (let k = 0, n = "", m, u; k < e.length; k++) { + m = e.charAt(k), m === n && this.dedupe || ((u = this.mapper && this.mapper.get(m)) || "" === u ? u === n && this.dedupe || !(n = u) || (d += u) : d += n = m); } - f = e; + e = d; } - this.matcher && 1 < f.length && (this.v || (this.v = new RegExp("(" + this.g + ")", "g")), f = f.replace(this.v, k => this.matcher.get(k))); - if (f && this.replacer) { - for (e = 0; f && e < this.replacer.length; e += 2) { - f = f.replace(this.replacer[e], this.replacer[e + 1]); + this.matcher && 1 < e.length && (this.s || (this.s = new RegExp("(" + this.g + ")", "g")), e = e.replace(this.s, k => this.matcher.get(k))); + if (e && this.replacer) { + for (d = 0; e && d < this.replacer.length; d += 2) { + e = e.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.s && (this.j.set(h, f), this.j.size > this.C && (this.j.clear(), this.s = this.s / 1.1 | 0)); - f && b.push(f); + this.cache && h.length <= this.o && (this.j.set(h, e), this.j.size > this.A && (this.j.clear(), this.o = this.o / 1.1 | 0)); + e && b.push(e); } } } } this.finalize && (b = this.finalize(b) || b); - this.cache && a.length <= this.o && (this.i.set(a, b), this.i.size > this.C && (this.i.clear(), this.o = this.o / 1.1 | 0)); + this.cache && a.length <= this.m && (this.i.set(a, b), this.i.size > this.A && (this.i.clear(), this.m = this.m / 1.1 | 0)); return b; }; -function z(a) { +function G(a) { a.l = null; a.i.clear(); a.j.clear(); } -;let A, C; -async function fa(a) { - a = a.data; - const c = a.task, b = a.id; - let d = a.args; - switch(c) { - case "init": - C = a.options || {}; - (a = a.factory) ? (Function("return " + a)()(self), A = new self.FlexSearch.Index(C), delete self.FlexSearch) : A = new D(C); - postMessage({id:b}); - break; - default: - let e; - "export" === c && (d = [C.export]); - "import" === c ? await C.import.call(A, A) : e = A[c].apply(A, d); - postMessage("search" === c ? {id:b, msg:e} : {id:b}); - } -} -;let E, F; -const G = {}, H = {}; -function ia(a) { - E = 0; - G[a] = H[a]; -} -function I(a) { - this[a + "Async"] = function() { - const c = arguments; - var b = c[c.length - 1]; - let d; - "function" === typeof b && (d = b, delete c[c.length - 1]); - E || (E = setTimeout(ia, 0, a), F = Date.now()); - H[a] || (H[a] = G[a] = 1000); - if (!--G[a]) { - G[a] = H[a] = H[a] * this.priority * this.priority * 3 / (Date.now() - F) | 0 || 1; - E = clearTimeout(E); - const g = this; - return new Promise(f => { - setTimeout(function() { - f(g[a + "Async"].apply(g, c)); - }, 0); - }); - } - const e = this[a].apply(this, c); - b = e.then ? e : new Promise(g => g(e)); - d && b.then(d); - return b; - }; -} -;let J = 0; -function K(a = {}) { - function c(f) { - function h(k) { - k = k.data || k; - const l = k.id, n = l && e.g[l]; - n && (n(k.msg), delete e.g[l]); - } - this.worker = f; - this.g = w(); - if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; - if (a.config) { - return new Promise(function(k) { - e.g[++J] = function() { - k(e); - }; - e.worker.postMessage({id:J, task:"init", factory:b, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:b, options:a}); - return this; - } - } - if (!this || this.constructor !== K) { - return new K(a); - } - let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - b && (b = b.toString()); - const d = "undefined" === typeof window, e = this, g = ja(b, d, a.worker); - return g.then ? g.then(function(f) { - return c.call(e, f); - }) : c.call(this, g); -} -L("add"); -L("append"); -L("search"); -L("update"); -L("remove"); -L("clear"); -L("export"); -L("import"); -var M = K.prototype; -I.call(M, "add"); -I.call(M, "append"); -I.call(M, "search"); -I.call(M, "update"); -I.call(M, "remove"); -function L(a) { - K.prototype[a] = async function() { - const c = this, b = [].slice.call(arguments); - var d = b[b.length - 1]; - let e; - "function" === typeof d && (e = d, b.splice(b.length - 1, 1)); - d = new Promise(function(g) { - c.g[++J] = g; - c.worker.postMessage({task:a, id:J, args:b}); - }); - return e ? (d.then(e), this) : d; - }; -} -function ja(a, c, b) { - return c ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + fa.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", - "module/worker/worker.js"), {type:"module"}); -} -;function N(a, c, b, d, e) { - const g = a.length; - let f = [], h, k; - h = w(); - for (let l = 0, n, m, r, q; l < c; l++) { - for (let p = 0; p < g; p++) { - if (r = a[p], l < r.length && (n = r[l])) { - for (let v = 0; v < n.length; v++) { - m = n[v], (k = h[m]) ? h[m]++ : (k = 0, h[m] = 1), q = f[k] || (f[k] = []), q.push(m); - } - } - } - } - if (a = f.length) { - if (e) { - f = 1 < f.length ? O(f, b, d) : (f = f[0]).length > b || d ? f.slice(d, b + d) : f; - } else { - if (a < g) { - return []; - } - f = f[a - 1]; - if (b || d) { - if (f.length > b || d) { - f = f.slice(d, b + d); - } - } - } - } - return f; -} -function O(a, c, b) { - const d = [], e = w(); - let g; - var f = a.length; - let h; - for (let k = f - 1; 0 <= k; k--) { - if (h = (f = a[k]) && f.length) { - for (let l = 0; l < h; l++) { - if (g = f[l], !e[g]) { - if (e[g] = 1, b) { - b--; - } else { - if (d.push(g), d.length === c) { - return d; - } - } - } - } - } - } - return d; -} -;function P(a, c, b, d) { +;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, d ? Q.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } - let e = []; - for (let g = 0, f, h; g < a.length; g++) { - if ((f = a[g]) && (h = f.length)) { + let f = []; + for (let d = 0, g, e; d < a.length; d++) { + if ((g = a[d]) && (e = g.length)) { if (b) { - if (b >= h) { - b -= h; + if (b >= e) { + b -= e; continue; } - b < h && (f = c ? f.slice(b, b + c) : f.slice(b), h = f.length, b = 0); + b < e && (g = c ? g.slice(b, b + c) : g.slice(b), e = g.length, b = 0); } - h > c && (f = f.slice(0, c), h = c); - if (!e.length && h >= c) { - return d ? Q.call(this, f) : f; + e > c && (g = g.slice(0, c), e = c); + if (!f.length && e >= c) { + return g; } - e.push(f); - c -= h; + f.push(g); + c -= e; if (!c) { break; } } } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? Q.call(this, e) : e; + return f = 1 < f.length ? [].concat.apply([], f) : f[0]; } -;function S(a, c, b) { - var d = b[0]; - if (d.then) { - return Promise.all(b).then(function(n) { - return a[c].apply(a, n); - }); - } - if (d[0] && d[0].index) { - return a[c].apply(a, d); - } - d = []; - let e = [], g = 0, f = 0, h, k, l; - for (let n = 0, m; n < b.length; n++) { - if (m = b[n]) { - let r; - if (m.constructor === T) { - r = m.result; - } else if (m.constructor === Array) { - r = m; - } else { - if (g = m.limit || 0, f = m.offset || 0, l = m.suggest, k = m.resolve, h = m.enrich && k, m.index) { - m.resolve = !1, m.enrich = !1, r = m.index.search(m).result, m.resolve = k, m.enrich = h; - } else if (m.and) { - r = a.and(m.and); - } else if (m.or) { - r = a.or(m.or); - } else if (m.xor) { - r = a.xor(m.xor); - } else if (m.not) { - r = a.not(m.not); - } else { - continue; - } - } - if (r.then) { - e.push(r); - } else if (r.length) { - d[n] = r; - } else if (!l && ("and" === c || "xor" === c)) { - d = []; - break; - } - } - } - return {m:d, u:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; -} -;T.prototype.or = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g} = S(this, "or", arguments); - return U.call(this, a, c, b, d, e, g); -}; -function U(a, c, b, d, e, g) { - if (c.length) { - const f = this; - return Promise.all(c).then(function(h) { - a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); - } - return U.call(f, a, [], b, d, e, g); - }); - } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = O(a, b, d), d = 0)); - return g ? this.resolve(b, d, e) : this; -} -;T.prototype.and = function() { - let a = this.result.length, c, b, d, e; - if (!a) { - const g = arguments[0]; - g && (a = !!g.suggest, e = g.resolve, c = g.limit, b = g.offset, d = g.enrich && e); - } - if (a) { - const {m:g, u:f, limit:h, offset:k, enrich:l, resolve:n, suggest:m} = S(this, "and", arguments); - return ka.call(this, g, f, h, k, l, n, m); - } - return e ? this.resolve(c, b, d) : this; -}; -function ka(a, c, b, d, e, g, f) { - if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { - a = []; - for (let l = 0, n; l < k.length; l++) { - (n = k[l]).length && (a[l] = n); - } - return ka.call(h, a, [], b, d, e, g, f); - }); - } - if (a.length) { - if (this.result.length && a.unshift(this.result), 2 > a.length) { - this.result = a[0]; - } else { - if (c = aa(a)) { - return this.result = N(a, c, b, d, f), g ? e ? Q.call(this.index, this.result) : this.result : this; - } - this.result = []; - } - } else { - f || (this.result = a); - } - return g ? this.resolve(b, d, e) : this; -} -;T.prototype.xor = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = S(this, "xor", arguments); - return la.call(this, a, c, b, d, e, g, f); -}; -function la(a, c, b, d, e, g, f) { - if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { - a = []; - for (let l = 0, n; l < k.length; l++) { - (n = k[l]).length && (a[l] = n); - } - return la.call(h, a, [], b, d, e, g, f); - }); - } - if (a.length) { - if (this.result.length && a.unshift(this.result), 2 > a.length) { - this.result = a[0]; - } else { - return this.result = ma.call(this, a, b, d, g, this.g), g ? e ? Q.call(this.index, this.result) : this.result : this; - } - } else { - f || (this.result = a); - } - return g ? this.resolve(b, d, e) : this; -} -function ma(a, c, b, d, e) { - const g = [], f = w(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); - for (let n = 0, m; n < l.length; n++) { - if (m = l[n]) { - for (let r = 0, q; r < m.length; r++) { - q = m[r], f[q] = f[q] ? 2 : 1; - } - } - } - } - } - for (let k = 0, l, n = 0; k < h; k++) { - for (let m = 0, r; m < a.length; m++) { - if (r = a[m]) { - if (l = r[k]) { - for (let q = 0, p; q < l.length; q++) { - if (p = l[q], 1 === f[p]) { - if (b) { - b--; - } else { - if (d) { - if (g.push(p), g.length === c) { - return g; - } - } else { - const v = k + (m ? e : 0); - g[v] || (g[v] = []); - g[v].push(p); - if (++n === c) { - return g; - } - } - } - } - } - } - } - } - } - return g; -} -;T.prototype.not = function() { - const {m:a, u:c, limit:b, offset:d, enrich:e, resolve:g, suggest:f} = S(this, "not", arguments); - return na.call(this, a, c, b, d, e, g, f); -}; -function na(a, c, b, d, e, g, f) { - if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { - a = []; - for (let l = 0, n; l < k.length; l++) { - (n = k[l]).length && (a[l] = n); - } - return na.call(h, a, [], b, d, e, g, f); - }); - } - if (a.length && this.result.length) { - this.result = oa.call(this, a, b, d, g); - } else if (g) { - return this.resolve(b, d, e); - } - return g ? e ? Q.call(this.index, this.result) : this.result : this; -} -function oa(a, c, b, d) { - const e = []; - a = new Set(a.flat().flat()); - for (let g = 0, f, h = 0; g < this.result.length; g++) { - if (f = this.result[g]) { - for (let k = 0, l; k < f.length; k++) { - if (l = f[k], !a.has(l)) { - if (b) { - b--; - } else { - if (d) { - if (e.push(l), e.length === c) { - return e; - } - } else { - if (e[g] || (e[g] = []), e[g].push(l), ++h === c) { - return e; - } - } - } - } - } - } - } - return e; -} -;function T(a) { - if (!this || this.constructor !== T) { - return new T(a); - } - if (a && a.index) { - return a.resolve = !1, this.index = a.index, this.g = a.boost || 0, this.result = a.index.search(a).result, this; - } - this.index = null; - this.result = a || []; - this.g = 0; -} -T.prototype.limit = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, d; b < this.result.length; b++) { - if (d = this.result[b]) { - if (d.length <= a) { - if (c[b] = d, a -= d.length, !a) { - break; - } - } else { - c[b] = d.slice(0, a); - break; - } - } - } - this.result = c; - } - return this; -}; -T.prototype.offset = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, d; b < this.result.length; b++) { - if (d = this.result[b]) { - d.length <= a ? a -= d.length : (c[b] = d.slice(a), a = 0); - } - } - this.result = c; - } - return this; -}; -T.prototype.boost = function(a) { - this.g += a; - return this; -}; -T.prototype.resolve = function(a, c, b) { - const d = this.result, e = this.index; - this.result = this.index = null; - return d.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), P.call(e, d, a || 100, c, b)) : d; -}; -w(); -function Q(a) { - if (!this || !this.store) { - return a; - } - const c = Array(a.length); - for (let b = 0, d; b < a.length; b++) { - d = a[b], c[b] = {id:d, doc:this.store.get(d)}; - } - return c; -} -;function V(a) { +;w(); +function I(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.g = ""; } -V.prototype.set = function(a, c) { +I.prototype.set = function(a, c) { this.cache.set(this.g = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -V.prototype.get = function(a) { +I.prototype.get = function(a) { const c = this.cache.get(a); c && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c)); return c; }; -V.prototype.remove = function(a) { +I.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -V.prototype.clear = function() { +I.prototype.clear = function() { this.cache.clear(); this.g = ""; }; -const pa = {normalize:function(a) { +const J = {normalize:function(a) { return a.toLowerCase(); }}; -const qa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -D.prototype.add = function(a, c, b, d) { +const K = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +L.prototype.add = function(a, c, b, f) { if (c && (a || 0 === a)) { - if (!d && !b && this.reg.has(a)) { + if (!f && !b && this.reg.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); - if (d = c.length) { - const l = w(), n = w(), m = this.depth, r = this.resolution; - for (let q = 0; q < d; q++) { - let p = c[this.rtl ? d - 1 - q : q]; - var e = p.length; - if (e && (m || !n[p])) { - var g = this.score ? this.score(c, p, q, null, 0) : W(r, d, q), f = ""; + if (f = c.length) { + const n = w(), m = w(), u = this.depth, C = this.resolution; + for (let p = 0; p < f; p++) { + let l = c[this.rtl ? f - 1 - p : p]; + var d = l.length; + if (d && (u || !m[l])) { + var g = this.score ? this.score(c, l, p, null, 0) : M(C, f, p), e = ""; switch(this.tokenize) { case "full": - if (2 < e) { - for (g = 0; g < e; g++) { - for (var h = e; h > g; h--) { - f = p.substring(g, h); - var k = this.score ? this.score(c, p, q, f, g) : W(r, d, q, e, g); - X(this, n, f, k, a, b); + if (2 < d) { + for (g = 0; g < d; g++) { + for (var h = d; h > g; h--) { + e = l.substring(g, h); + var k = this.score ? this.score(c, l, p, e, g) : M(C, f, p, d, g); + N(this, m, e, k, a, b); } } break; } case "reverse": - if (1 < e) { - for (h = e - 1; 0 < h; h--) { - f = p[h] + f, k = this.score ? this.score(c, p, q, f, h) : W(r, d, q, e, h), X(this, n, f, k, a, b); + if (1 < d) { + for (h = d - 1; 0 < h; h--) { + e = l[h] + e, k = this.score ? this.score(c, l, p, e, h) : M(C, f, p, d, h), N(this, m, e, k, a, b); } - f = ""; + e = ""; } case "forward": - if (1 < e) { - for (h = 0; h < e; h++) { - f += p[h], X(this, n, f, g, a, b); + if (1 < d) { + for (h = 0; h < d; h++) { + e += l[h], N(this, m, e, g, a, b); } break; } default: - if (X(this, n, p, g, a, b), m && 1 < d && q < d - 1) { - for (e = w(), f = this.B, g = p, h = Math.min(m + 1, d - q), e[g] = 1, k = 1; k < h; k++) { - if ((p = c[this.rtl ? d - 1 - q - k : q + k]) && !e[p]) { - e[p] = 1; - const v = this.score ? this.score(c, g, q, p, k) : W(f + (d / 2 > f ? 0 : 1), d, q, h - 1, k - 1), B = this.bidirectional && p > g; - X(this, l, B ? g : p, v, a, b, B ? p : g); + if (N(this, m, l, g, a, b), u && 1 < f && p < f - 1) { + for (d = w(), e = this.v, g = l, h = Math.min(u + 1, f - p), d[g] = 1, k = 1; k < h; k++) { + if ((l = c[this.rtl ? f - 1 - p - k : p + k]) && !d[l]) { + d[l] = 1; + const v = this.score ? this.score(c, g, p, l, k) : M(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; + N(this, n, t ? g : l, v, a, b, t ? l : g); } } } @@ -799,134 +345,182 @@ D.prototype.add = function(a, c, b, d) { } return this; }; -function X(a, c, b, d, e, g, f) { - let h = f ? a.ctx : a.map, k; - if (!c[b] || f && !(k = c[b])[f]) { - f ? (c = k || (c[b] = w()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.reg.get(e)) ? c.push(h) : a.reg.set(e, [h]))); +function N(a, c, b, f, d, g, e) { + let h = e ? a.ctx : a.map, k; + if (!c[b] || e && !(k = c[b])[e]) { + e ? (c = k || (c[b] = w()), c[e] = 1, (k = h.get(e)) ? h = k : h.set(e, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[f] || (h[f] = []), g && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function W(a, c, b, d, e) { - return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0; +function M(a, c, b, f, d) { + return b && 1 < a ? c + (f || 0) <= a ? b + (d || 0) : (a - 1) / (c + (f || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;D.prototype.search = function(a, c, b) { +;L.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); - var d = [], e = 0; + var f = [], d = 0; if (b) { a = b.query || a; c = b.limit || c; - e = b.offset || 0; + d = b.offset || 0; var g = b.context; - var f = b.suggest; + var e = b.suggest; var h = !0; var k = b.resolution; } else { h = !0; } - b = this.encoder.encode(a); - a = b.length; + a = this.encoder.encode(a); + b = a.length; c = c || (h ? 100 : 0); - if (1 === a) { - return ra.call(this, b[0], "", c, e, h); + if (1 === b) { + return e = d, (d = O(this, a[0], "")) && d.length ? H.call(this, d, c, e) : []; } g = this.depth && !1 !== g; - if (2 === a && g && !f) { - return ra.call(this, b[0], b[1], c, e, h); + if (2 === b && g && !e) { + return e = d, (d = O(this, a[0], a[1])) && d.length ? H.call(this, d, c, e) : []; } h = w(); - let l = 0; - if (1 < a && g) { - var n = b[0]; - l = 1; + var n = 0; + if (1 < b && g) { + var m = a[0]; + n = 1; } - k || 0 === k || (k = n ? this.B : this.resolution); - for (let p, v; l < a; l++) { - if ((v = b[l]) && !h[v]) { + k || 0 === k || (k = m ? this.v : this.resolution); + for (let l, v; n < b; n++) { + if ((v = a[n]) && !h[v]) { h[v] = 1; - p = sa(this, v, n); + l = O(this, v, m); a: { - g = p; - var m = d, r = f, q = k; - let B = []; + g = l; + var u = f, C = e, p = k; + let t = []; if (g && g.length) { - if (g.length <= q) { - m.push(g); - p = void 0; + if (g.length <= p) { + u.push(g); + l = void 0; break a; } - for (let R = 0, ha; R < q; R++) { - if (ha = g[R]) { - B[R] = ha; + for (let x = 0, E; x < p; x++) { + if (E = g[x]) { + t[x] = E; } } - if (B.length) { - m.push(B); - p = void 0; + if (t.length) { + u.push(t); + l = void 0; break a; } } - p = r ? void 0 : B; + l = C ? void 0 : t; } - if (p) { - d = p; + if (l) { + f = l; break; } - n && (f && p && d.length || (n = v)); + m && (e && l && f.length || (m = v)); } - f && n && l === a - 1 && !d.length && (n = "", l = -1, h = w()); + e && m && n === b - 1 && !f.length && (m = "", n = -1, h = w()); } a: { - n = d.length; - a = d; - if (1 < n) { - a = N(d, k, c, e, f); - } else if (1 === n) { - f = P.call(null, d[0], c, e); + a = f; + f = a.length; + m = a; + if (1 < f) { + b: { + f = e; + m = a.length; + e = []; + b = w(); + for (let l = 0, v, t, x, E; l < k; l++) { + for (n = 0; n < m; n++) { + if (x = a[n], l < x.length && (v = x[l])) { + for (g = 0; g < v.length; g++) { + t = v[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), E = e[h] || (e[h] = []), E.push(t); + } + } + } + } + if (a = e.length) { + if (f) { + if (1 < e.length) { + c: { + for (a = [], k = w(), f = e.length, h = f - 1; 0 <= h; h--) { + if (b = (f = e[h]) && f.length) { + for (n = 0; n < b; n++) { + if (m = f[n], !k[m]) { + if (k[m] = 1, d) { + d--; + } else { + if (a.push(m), a.length === c) { + break c; + } + } + } + } + } + } + } + } else { + a = (e = e[0]).length > c || d ? e.slice(d, c + d) : e; + } + e = a; + } else { + if (a < m) { + m = []; + break b; + } + e = e[a - 1]; + if (c || d) { + if (e.length > c || d) { + e = e.slice(d, c + d); + } + } + } + } + m = e; + } + } else if (1 === f) { + c = H.call(null, a[0], c, d); break a; } - f = a; + c = m; } - return f; + return c; }; -function ra(a, c, b, d, e) { - a = sa(this, a, c); - e = !0; - return a && a.length ? e ? P.call(this, a, b, d) : new T(a) : e ? [] : new T(); -} -function sa(a, c, b) { - let d; - b && (d = a.bidirectional && c > b) && (d = b, b = c, c = d); +function O(a, c, b) { + let f; + b && (f = a.bidirectional && c > b) && (f = b, b = c, c = f); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;D.prototype.remove = function(a, c) { +;L.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { - for (let d = 0, e; d < b.length; d++) { - if (e = b[d]) { - if (2 > e.length) { - e.pop(); + for (let f = 0, d; f < b.length; f++) { + if (d = b[f]) { + if (2 > d.length) { + d.pop(); } else { - const g = e.indexOf(a); - g === b.length - 1 ? e.pop() : e.splice(g, 1); + const g = d.indexOf(a); + g === b.length - 1 ? d.pop() : d.splice(g, 1); } } } } else { - Y(this.map, a), this.depth && Y(this.ctx, a); + P(this.map, a), this.depth && P(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Y(a, c) { +function P(a, c) { let b = 0; if (a.constructor === Array) { - for (let d = 0, e, g; d < a.length; d++) { - if ((e = a[d]) && e.length) { - if (g = e.indexOf(c), 0 <= g) { - 1 < e.length ? (e.splice(g, 1), b++) : delete a[d]; + for (let f = 0, d, g; f < a.length; f++) { + if ((d = a[f]) && d.length) { + if (g = d.indexOf(c), 0 <= g) { + 1 < d.length ? (d.splice(g, 1), b++) : delete a[f]; break; } else { b++; @@ -934,97 +528,97 @@ function Y(a, c) { } } } else { - for (let d of a.entries()) { - const e = d[0], g = Y(d[1], c); - g ? b += g : a.delete(e); + for (let f of a.entries()) { + const d = f[0], g = P(f[1], c); + g ? b += g : a.delete(d); } } return b; } -;function D(a, c) { - if (!this || this.constructor !== D) { - return new D(a); +;function L(a, c) { + if (!this || this.constructor !== L) { + return new L(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (qa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, qa[b], a)); + b && (K[b] || console.warn("Preset not found: " + b), a = Object.assign({}, K[b], a)); } else { a = {}; } b = a.context; - const d = !0 === b ? {depth:1} : b || {}, e = a.encode || a.encoder || pa; - this.encoder = e.encode ? e : "object" === typeof e ? new y(e) : {encode:e}; + const f = !0 === b ? {depth:1} : b || {}, d = a.encode || a.encoder || J; + this.encoder = d.encode ? d : "object" === typeof d ? new F(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = b = a.tokenize || "strict"; - this.depth = "strict" === b && d.depth || 0; - this.bidirectional = !1 !== d.bidirectional; + this.tokenize = (b = a.tokenize) && "default" !== b || "strict"; + this.depth = "strict" === b && f.depth || 0; + this.bidirectional = !1 !== f.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.B = d.resolution || 3; - this.rtl = e.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new V(b); + this.v = f.resolution || 3; + this.rtl = d.rtl || a.rtl || !1; + this.cache = (b = a.cache || null) && new I(b); } -t = D.prototype; -t.clear = function() { +q = L.prototype; +q.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); this.cache && this.cache.clear(); return this; }; -t.append = function(a, c) { +q.append = function(a, c) { return this.add(a, c, !0); }; -t.contain = function(a) { +q.contain = function(a) { return this.reg.has(a); }; -t.update = function(a, c) { - const b = this, d = this.remove(a); - return d && d.then ? d.then(() => b.add(a, c)) : this.add(a, c); +q.update = function(a, c) { + const b = this, f = this.remove(a); + return f && f.then ? f.then(() => b.add(a, c)) : this.add(a, c); }; -function Z(a) { +function Q(a) { let c = 0; if (a.constructor === Array) { - for (let b = 0, d; b < a.length; b++) { - (d = a[b]) && (c += d.length); + for (let b = 0, f; b < a.length; b++) { + (f = a[b]) && (c += f.length); } } else { for (const b of a) { - const d = b[0], e = Z(b[1]); - e ? c += e : a.delete(d); + const f = b[0], d = Q(b[1]); + d ? c += d : a.delete(f); } } return c; } -t.cleanup = function() { +q.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Z(this.map); - this.depth && Z(this.ctx); + Q(this.map); + this.depth && Q(this.ctx); return this; }; -t.searchCache = function(a, c, b) { +q.searchCache = function(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new V()); - let d = this.cache.get(a); - if (!d) { - d = this.search(a, c, b); - if (d.then) { - const e = this; - d.then(function(g) { - e.cache.set(a, g); + this.cache || (this.cache = new I()); + let f = this.cache.get(a); + if (!f) { + f = this.search(a, c, b); + if (f.then) { + const d = this; + f.then(function(g) { + d.cache.set(a, g); return g; }); } - this.cache.set(a, d); + this.cache.set(a, f); } - return d; + return f; }; -export default {Index:D, Charset:null, Encoder:y, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:L, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=D;export const Charset=null;export const Encoder=y;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=L;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/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index acae027..2fe41ef 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,41 +1,28 @@ /**! - * FlexSearch.js v0.8.108 (Bundle) + * FlexSearch.js v0.8.109 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var t;function u(a,c,b){const d=typeof b,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(b){if("function"===e&&d===e)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===e?c:a}function w(){return Object.create(null)} -function aa(a){let c=0;for(let b=0,d;b"a1a".split(b).length; -this.numeric=u(a.numeric,d)}else{try{this.split=u(this.split,ba)}catch(e){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.C="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.s=this.o=128;this.g="";this.v=null;this.h="";this.A=null;if(this.matcher)for(const e of this.matcher.keys())this.g+=(this.g?"|":"")+e;if(this.stemmer)for(const e of this.stemmer.keys())this.h+=(this.h?"|":"")+e;return this}; -t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.A=null;this.cache&&z(this);return this};t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&z(this);return this};t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.v=null;this.cache&&z(this);return this};t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&z(this);return this}; -t.encode=function(a){if(this.cache&&a.length<=this.o)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(z,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=x?a.normalize("NFKD").replace(x,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),f.lengththis.matcher.get(k)));if(f&&this.replacer)for(e=0;f&&ethis.C&& -(this.j.clear(),this.s=this.s/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.o&&(this.i.set(a,b),this.i.size>this.C&&(this.i.clear(),this.o=this.o/1.1|0));return b};function z(a){a.l=null;a.i.clear();a.j.clear()};let A,C;async function ha(a){a=a.data;const c=a.task,b=a.id;let d=a.args;switch(c){case "init":C=a.options||{};(a=a.factory)?(Function("return "+a)()(self),A=new self.FlexSearch.Index(C),delete self.FlexSearch):A=new D(C);postMessage({id:b});break;default:let e;"export"===c&&(d=[C.export]);"import"===c?await C.import.call(A,A):e=A[c].apply(A,d);postMessage("search"===c?{id:b,msg:e}:{id:b})}};let E,F;const G={},H={};function ia(a){E=0;G[a]=H[a]} -function I(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let d;"function"===typeof b&&(d=b,delete c[c.length-1]);E||(E=setTimeout(ia,0,a),F=Date.now());H[a]||(H[a]=G[a]=1E3);if(!--G[a]){G[a]=H[a]=H[a]*this.priority*this.priority*3/(Date.now()-F)|0||1;E=clearTimeout(E);const g=this;return new Promise(f=>{setTimeout(function(){f(g[a+"Async"].apply(g,c))},0)})}const e=this[a].apply(this,c);b=e.then?e:new Promise(g=>g(e));d&&b.then(d);return b}};let J=0; -function K(a={}){function c(f){function h(k){k=k.data||k;const l=k.id,n=l&&e.g[l];n&&(n(k.msg),delete e.g[l])}this.worker=f;this.g=w();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.g[++J]=function(){k(e)};e.worker.postMessage({id:J,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==K)return new K(a);let b="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;b&&(b=b.toString());const d="undefined"===typeof window,e=this,g=ja(b,d,a.worker);return g.then?g.then(function(f){return c.call(e,f)}):c.call(this,g)}L("add");L("append");L("search");L("update");L("remove");L("clear");L("export");L("import");var M=K.prototype;I.call(M,"add");I.call(M,"append");I.call(M,"search");I.call(M,"update");I.call(M,"remove"); -function L(a){K.prototype[a]=async function(){const c=this,b=[].slice.call(arguments);var d=b[b.length-1];let e;"function"===typeof d&&(e=d,b.splice(b.length-1,1));d=new Promise(function(g){c.g[++J]=g;c.worker.postMessage({task:a,id:J,args:b})});return e?(d.then(e),this):d}} -function ja(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ha.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof b?b:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function N(a,c,b,d,e){const g=a.length;let f=[],h,k;h=w();for(let l=0,n,m,r,q;lb||d?f.slice(d,b+d):f;else{if(ab||d)f=f.slice(d,b+d)}return f} -function O(a,c,b){const d=[],e=w();let g;var f=a.length;let h;for(let k=f-1;0<=k;k--)if(h=(f=a[k])&&f.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,d?Q.call(this,a):a;let e=[];for(let g=0,f,h;g=h){b-=h;continue}bc&&(f=f.slice(0,c),h=c);if(!e.length&&h>=c)return d?Q.call(this,f):f;e.push(f);c-=h;if(!c)break}e=1a.length?this.result=a[0]:(this.result=O(a,b,d),d=0));return g?this.resolve(b,d,e):this};T.prototype.and=function(){let a=this.result.length,c,b,d,e;if(!a){const g=arguments[0];g&&(a=!!g.suggest,e=g.resolve,c=g.limit,b=g.offset,d=g.enrich&&e)}if(a){const {m:g,u:f,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=S(this,"and",arguments);return ka.call(this,g,f,h,k,l,n,m)}return e?this.resolve(c,b,d):this}; -function ka(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=aa(a))return this.result=N(a,c,b,d,f),g?e?Q.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(b,d,e):this};T.prototype.xor=function(){const {m:a,u:c,limit:b,offset:d,enrich:e,resolve:g,suggest:f}=S(this,"xor",arguments);return la.call(this,a,c,b,d,e,g,f)}; -function la(a,c,b,d,e,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=ma.call(this,a,b,d,g,this.g),g?e?Q.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(b,d,e):this} -function ma(a,c,b,d,e){const g=[],f=w();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)};V.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};V.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -V.prototype.clear=function(){this.cache.clear();this.g=""};const pa={normalize:function(a){return a.toLowerCase()}};const qa={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};D.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const l=w(),n=w(),m=this.depth,r=this.resolution;for(let q=0;qg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,q,f,g):W(r,d,q,e,g);X(this,n,f,k,a,b)}break}case "reverse":if(1< -e){for(h=e-1;0f?0:1),d,q,h-1,k-1),B=this.bidirectional&&p>g;X(this,l,B?g:p,v,a,b,B?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function X(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h])))}function W(a,c,b,d,e){return b&&1b)&&(d=b,b=c,c=d);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};D.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Y(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; -function Z(a){let c=0;if(a.constructor===Array)for(let b=0,d;b"a1a".split(b).length; +this.numeric=r(a.numeric,f)}else{try{this.split=r(this.split,y)}catch(d){this.split=/\s+/}this.numeric=r(a.numeric,r(this.numeric,!0))}this.prepare=r(a.prepare,null,this.prepare);this.finalize=r(a.finalize,null,this.finalize);this.rtl=r(a.rtl,!1,this.rtl);this.dedupe=r(a.dedupe,!1,this.dedupe);this.filter=r((b=a.filter)&&new Set(b),null,this.filter);this.matcher=r((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=r((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=r((b=a.stemmer)&&new Map(b), +null,this.stemmer);this.replacer=r(a.replacer,null,this.replacer);this.minlength=r(a.minlength,1,this.minlength);this.maxlength=r(a.maxlength,0,this.maxlength);if(this.cache=b=r(a.cache,!0,this.cache))this.l=null,this.A="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.o=this.m=128;this.g="";this.s=null;this.h="";this.u=null;if(this.matcher)for(const d of this.matcher.keys())this.g+=(this.g?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.h+=(this.h?"|":"")+d;return this}; +q.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.u=null;this.cache&&G(this);return this};q.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&G(this);return this};q.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&G(this);return this};q.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; +q.encode=function(a){if(this.cache&&a.length<=this.m)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(G,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=D?a.normalize("NFKD").replace(D,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),e.lengththis.matcher.get(k)));if(e&&this.replacer)for(d=0;e&&dthis.A&& +(this.j.clear(),this.o=this.o/1.1|0));e&&b.push(e)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.m&&(this.i.set(a,b),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return b};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 f=[];for(let d=0,g,e;d=e){b-=e;continue}bc&&(g=g.slice(0,c),e=c);if(!f.length&&e>=c)return g;f.push(g);c-=e;if(!c)break}return f=1this.limit&&this.cache.delete(this.cache.keys().next().value)};I.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};I.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; +I.prototype.clear=function(){this.cache.clear();this.g=""};const J={normalize:function(a){return a.toLowerCase()}};const K={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};L.prototype.add=function(a,c,b,f){if(c&&(a||0===a)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(f=c.length){const n=w(),m=w(),u=this.depth,C=this.resolution;for(let p=0;pg;h--){e=l.substring(g,h);var k=this.score?this.score(c,l,p,e,g):M(C,f,p,d,g);N(this,m,e,k,a,b)}break}case "reverse":if(1< +d){for(h=d-1;0e?0:1),f,p,h-1,k-1),t=this.bidirectional&&l>g;N(this,n,t?g:l,v,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function N(a,c,b,f,d,g,e){let h=e?a.ctx:a.map,k;if(!c[b]||e&&!(k=c[b])[e])e?(c=k||(c[b]=w()),c[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function M(a,c,b,f,d){return b&&1c||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}m=e}else if(1===f){c=H.call(null,a[0],c,d);break a}c=m}return c}; +function O(a,c,b){let f;b&&(f=a.bidirectional&&c>b)&&(f=b,b=c,c=f);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};L.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 f=0,d;fd.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function P(a,c){let b=0;if(a.constructor===Array)for(let f=0,d,g;fb.add(a,c)):this.add(a,c)}; +function Q(a){let c=0;if(a.constructor===Array)for(let b=0,f;b>} */ Document.prototype.mount = function (db) { + if (this.worker) { + throw new 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 fields = this.field; diff --git a/dist/module-debug/index.js b/dist/module-debug/index.js index dfca438..b75d50f 100644 --- a/dist/module-debug/index.js +++ b/dist/module-debug/index.js @@ -47,7 +47,7 @@ export default function Index(options, _register) { this.resolution = options.resolution || 9; - this.tokenize = tmp = options.tokenize || "strict"; + this.tokenize = (tmp = options.tokenize) && "default" !== tmp || "strict"; this.depth = "strict" === tmp && context.depth || 0; this.bidirectional = !1 !== context.bidirectional; this.fastupdate = !!options.fastupdate; diff --git a/dist/module-debug/index/search.js b/dist/module-debug/index/search.js index b9f773d..b9bb217 100644 --- a/dist/module-debug/index/search.js +++ b/dist/module-debug/index/search.js @@ -350,8 +350,6 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag); - resolve = resolve; - if (this.db) { return result.then(function (result) { return resolve ? result || [] : new Resolver(result); diff --git a/dist/module-debug/type.js b/dist/module-debug/type.js index 799b141..e32479f 100644 --- a/dist/module-debug/type.js +++ b/dist/module-debug/type.js @@ -21,7 +21,9 @@ import StorageInterface from "./db/interface.js"; * commit: (boolean|undefined), * worker: (string|undefined), * config: (string|undefined), - * priority: (number|undefined) + * priority: (number|undefined), + * export: (Function|undefined), + * import: (Function|undefined) * }} */ export let IndexOptions = {}; @@ -65,7 +67,9 @@ export let FieldOptions = {}; * doc: (DocumentDescriptor|Array|undefined), * document: (DocumentDescriptor|Array|undefined), * worker: (boolean|string|undefined), - * priority: (number|undefined) + * priority: (number|undefined), + * export: (Function|undefined), + * import: (Function|undefined) * }} */ export let DocumentOptions = {}; diff --git a/dist/module-debug/worker.js b/dist/module-debug/worker.js index 2fc99f1..ff286dd 100644 --- a/dist/module-debug/worker.js +++ b/dist/module-debug/worker.js @@ -1,3 +1,4 @@ + import { IndexOptions } from "./type.js"; import { create_object, is_function, is_object, is_string } from "./common.js"; import handler from "./worker/handler.js"; @@ -97,6 +98,7 @@ register("import"); apply_async(WorkerIndex.prototype); + function register(key) { WorkerIndex.prototype[key] = diff --git a/dist/module-debug/worker/handler.js b/dist/module-debug/worker/handler.js index 990e152..48c286b 100644 --- a/dist/module-debug/worker/handler.js +++ b/dist/module-debug/worker/handler.js @@ -1,3 +1,4 @@ + import Index from "../index.js"; import { IndexOptions } from "../type.js"; @@ -21,6 +22,7 @@ export default (async function (data) { options = data.options || {}; let filepath = options.config; if (filepath) { + // compiler fix options = options; // will be replaced after build with the line below because // there is an issue with closure compiler dynamic import @@ -33,9 +35,7 @@ export default (async function (data) { // export the FlexSearch global payload to "self" Function("return " + factory)()(self); - index = new self.FlexSearch.Index(options); - // destroy the exported payload delete self.FlexSearch; } else { @@ -51,11 +51,18 @@ export default (async function (data) { let message; if ("export" === task) { + if (!options.export || "function" != typeof options.export) { + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); + } + args = [options.export]; } if ("import" === task) { + if (!options.import || "function" != typeof options.import) { + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); + } + await options.import.call(index, index); - //args = [options.import]; } else { message = index[task].apply(index, args); } diff --git a/dist/module-debug/worker/node.js b/dist/module-debug/worker/node.js index 9d154eb..b31e9a0 100644 --- a/dist/module-debug/worker/node.js +++ b/dist/module-debug/worker/node.js @@ -29,8 +29,8 @@ parentPort.on("message", async function (data) { index = new Index(options); //index.db && await index.db; - parentPort.postMessage({ id: id }); + parentPort.postMessage({ id: id }); break; default: @@ -38,11 +38,18 @@ parentPort.on("message", async function (data) { let message; if ("export" === task) { + if (!options.export || "function" != typeof options.export) { + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); + } + args = [options.export]; } if ("import" === task) { + if (!options.import || "function" != typeof options.import) { + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); + } + await options.import.call(index, index); - //args = [options.import]; } else { message = index[task].apply(index, args); } diff --git a/dist/module-min/async.js b/dist/module-min/async.js index f2487ae..ca8a04b 100644 --- a/dist/module-min/async.js +++ b/dist/module-min/async.js @@ -1 +1 @@ -import Document from"./document.js";import Index from"./index.js";export default function(a){register.call(a,"add"),register.call(a,"append"),register.call(a,"search"),register.call(a,"update"),register.call(a,"remove")}let timer,timestamp;const current={},limit={};function tick(a){timer=0,current[a]=limit[a]}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,a),timestamp=Date.now()),limit[a]||(limit[a]=current[a]=1000),! --current[a]){const c=Date.now(),d=c-timestamp,e=3*(this.priority*this.priority);current[a]=limit[a]=0|limit[a]*e/d||1,timer=clearTimeout(timer);const f=this;return new Promise(c=>{setTimeout(function(){c(f[a+"Async"].apply(f,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")}let timer,timestamp;const current={},limit={};function tick(a){timer=0,current[a]=limit[a]}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,a),timestamp=Date.now()),limit[a]||(limit[a]=current[a]=1000),! --current[a]){const c=Date.now(),d=c-timestamp,e=3*(this.priority*this.priority);current[a]=limit[a]=0|limit[a]*e/d||1,timer=clearTimeout(timer);const f=this;return new Promise(c=>{setTimeout(function(){c(f[a+"Async"].apply(f,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 c8ecace..b12c4b3 100644 --- a/dist/module-min/bundle.js +++ b/dist/module-min/bundle.js @@ -1 +1 @@ -import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";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.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,Index.prototype.encoder,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,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,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,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,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,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;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{FlexSearch.Language={};const a="undefined"==typeof self?"undefined"==typeof global?"undefined"==typeof window?{}:window: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}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";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.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,Index.prototype.encoder,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,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,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,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;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{FlexSearch.Language={};const a="undefined"==typeof self?"undefined"==typeof global?"undefined"==typeof window?{}:window:global:self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file diff --git a/dist/module-min/document.js b/dist/module-min/document.js index 59ad0a4..cd0528e 100644 --- a/dist/module-min/document.js +++ b/dist/module-min/document.js @@ -1 +1 @@ -import{IndexOptions,DocumentOptions,DocumentDescriptor,FieldOptions,StoreOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Cache,{searchCache}from"./cache.js";import{is_string,is_object,parse_simple}from"./common.js";import apply_async from"./async.js";import{exportDocument,importDocument}from"./serialize.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import"./document/add.js";import"./document/search.js";export default function Document(a){if(!this||this.constructor!==Document)return new Document(a);const b=a.document||a.doc||a;let c,d;if(this.tree=[],this.field=[],this.marker=[],this.key=(c=b.key||b.id)&&parse_tree(c,this.marker)||"id",d=a.keystore||0,d&&(this.keystore=d),this.fastupdate=!!a.fastupdate,this.reg=this.fastupdate?d&&!0?new KeystoreMap(d):new Map:d&&!0?new KeystoreSet(d):new Set,this.storetree=(c=b.store||null)&&c&&!0!==c&&[],this.store=c&&(d&&!0?new KeystoreMap(d):new Map),this.cache=(c=a.cache||null)&&new Cache(c),a.cache=!1,this.worker=a.worker,this.index=parse_descriptor.call(this,a,b),(this.tag=null,(c=b.tag)&&("string"==typeof c&&(c=[c]),c.length))){this.tag=new Map,this.tagtree=[],this.tagfield=[];for(let a,b,d=0;dc.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;dc.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;db,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){c||(!b&&is_object(a)?(c=a,a=""):is_object(b)&&(c=b,b=0));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=!1!==c.resolve,k=g&&c.enrich,i=c.boost,j=c.resolution,h=this.db&&c.tag):g=this.resolve;let n=this.encoder.encode(a);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(e=this.depth&&!1!==e,2===d&&e&&!f)return single_term_query.call(this,n[0],n[1],b,m,g,k,h);let o,p=create_object(),q=0;if(1b,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-min/worker/handler.js b/dist/module-min/worker/handler.js index df303f1..9a84022 100644 --- a/dist/module-min/worker/handler.js +++ b/dist/module-min/worker/handler.js @@ -1 +1 @@ -import Index from"../index.js";import{IndexOptions}from"../type.js";let index,options;export default(async function(a){a=a.data;const b=a.task,c=a.id;let d=a.args;switch(b){case"init":options=a.options||{};let e=options.config;e&&(options=options);const f=a.factory;f?(Function("return "+f)()(self),index=new self.FlexSearch.Index(options),delete self.FlexSearch):index=new Index(options),postMessage({id:c});break;default:let g;"export"===b&&(d=[options.export]),"import"===b?await options.import.call(index,index):g=index[b].apply(index,d),postMessage("search"===b?{id:c,msg:g}:{id:c});}}); \ No newline at end of file +import Index from"../index.js";import{IndexOptions}from"../type.js";let index,options;export default(async function(a){a=a.data;const b=a.task,c=a.id;let d=a.args;switch(b){case"init":options=a.options||{};let e=options.config;e&&(options=options);const f=a.factory;f?(Function("return "+f)()(self),index=new self.FlexSearch.Index(options),delete self.FlexSearch):index=new Index(options),postMessage({id:c});break;default:let g;"export"===b&&(d=[options.export]);"import"===b?await options.import.call(index,index):g=index[b].apply(index,d);postMessage("search"===b?{id:c,msg:g}:{id:c});}}); \ No newline at end of file diff --git a/dist/module-min/worker/node.js b/dist/module-min/worker/node.js index 10913b8..6d7a4fd 100644 --- a/dist/module-min/worker/node.js +++ b/dist/module-min/worker/node.js @@ -1 +1 @@ -const{parentPort}=require("worker_threads"),{Index}=require("flexsearch");let index,options;parentPort.on("message",async function(a){const b=a.task,c=a.id;let d=a.args;switch(b){case"init":options=a.options||{};let e=options.config;e&&(options=Object.assign({},options,require(e)),delete options.worker),index=new Index(options),parentPort.postMessage({id:c});break;default:let f;"export"===b&&(d=[options.export]),"import"===b?await options.import.call(index,index):f=index[b].apply(index,d),parentPort.postMessage("search"===b?{id:c,msg:f}:{id:c});}}); \ No newline at end of file +const{parentPort}=require("worker_threads"),{Index}=require("flexsearch");let index,options;parentPort.on("message",async function(a){const b=a.task,c=a.id;let d=a.args;switch(b){case"init":options=a.options||{};let e=options.config;e&&(options=Object.assign({},options,require(e)),delete options.worker),index=new Index(options),parentPort.postMessage({id:c});break;default:let f;"export"===b&&(d=[options.export]);"import"===b?await options.import.call(index,index):f=index[b].apply(index,d);parentPort.postMessage("search"===b?{id:c,msg:f}:{id:c});}}); \ No newline at end of file diff --git a/dist/module/async.js b/dist/module/async.js index 8ce1ad0..1b5ac54 100644 --- a/dist/module/async.js +++ b/dist/module/async.js @@ -1,5 +1,6 @@ import Document from "./document.js"; import Index from "./index.js"; +import WorkerIndex from "./worker.js"; export default function (prototype) { register.call(prototype, "add"); @@ -21,7 +22,7 @@ function tick(key) { /** * @param {!string} key - * @this {Index|Document} + * @this {Index|Document|WorkerIndex} */ function register(key) { diff --git a/dist/module/bundle.js b/dist/module/bundle.js index fa3752c..6767c99 100644 --- a/dist/module/bundle.js +++ b/dist/module/bundle.js @@ -138,6 +138,8 @@ import Charset from "./charset.js"; /** @export */IndexOptions.worker; // worker url /** @export */IndexOptions.config; // config url /** @export */IndexOptions.priority; +/** @export */IndexOptions.export; +/** @export */IndexOptions.import; /** @export */FieldOptions.preset; /** @export */FieldOptions.context; @@ -173,6 +175,8 @@ import Charset from "./charset.js"; /** @export */DocumentOptions.document; /** @export */DocumentOptions.worker; /** @export */DocumentOptions.priority; +/** @export */DocumentOptions.export; +/** @export */DocumentOptions.import; /** @export */ContextOptions.depth; /** @export */ContextOptions.bidirectional; diff --git a/dist/module/document.js b/dist/module/document.js index 95f915f..4248511 100644 --- a/dist/module/document.js +++ b/dist/module/document.js @@ -42,8 +42,7 @@ export default function Document(options) { keystore = options.keystore || 0; keystore && (this.keystore = keystore); this.fastupdate = !!options.fastupdate; - this.reg = this.fastupdate ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ - /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); + this.reg = this.fastupdate && !options.worker && !options.db ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); // todo support custom filter function this.storetree = (tmp = document.store || null) && tmp && !0 !== tmp && []; @@ -52,8 +51,7 @@ export default function Document(options) { this.cache = (tmp = options.cache || null) && new Cache(tmp); // do not apply cache again for the indexes since .searchCache() // is just a wrapper over .search() - options.cache = /* suggest */ /* append: */ - /* enrich */!1; + options.cache = /* suggest */ /* append: */ /* enrich */!1; this.worker = options.worker; @@ -105,6 +103,7 @@ export default function Document(options) { // resolve worker promises and swap instances if (this.worker) { + this.fastupdate = !1; const promises = []; for (const index of this.index.values()) { index.then && promises.push(index); @@ -123,7 +122,10 @@ export default function Document(options) { }); } } else { - options.db && this.mount(options.db); + if (options.db) { + this.fastupdate = !1; + this.mount(options.db); + } } } diff --git a/dist/module/index.js b/dist/module/index.js index 61d8de7..9e2e0eb 100644 --- a/dist/module/index.js +++ b/dist/module/index.js @@ -47,7 +47,7 @@ export default function Index(options, _register) { this.resolution = options.resolution || 9; - this.tokenize = tmp = options.tokenize || "strict"; + this.tokenize = (tmp = options.tokenize) && "default" !== tmp || "strict"; this.depth = "strict" === tmp && context.depth || 0; this.bidirectional = !1 !== context.bidirectional; this.fastupdate = !!options.fastupdate; diff --git a/dist/module/index/search.js b/dist/module/index/search.js index b9f773d..b9bb217 100644 --- a/dist/module/index/search.js +++ b/dist/module/index/search.js @@ -350,8 +350,6 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag); - resolve = resolve; - if (this.db) { return result.then(function (result) { return resolve ? result || [] : new Resolver(result); diff --git a/dist/module/type.js b/dist/module/type.js index 799b141..e32479f 100644 --- a/dist/module/type.js +++ b/dist/module/type.js @@ -21,7 +21,9 @@ import StorageInterface from "./db/interface.js"; * commit: (boolean|undefined), * worker: (string|undefined), * config: (string|undefined), - * priority: (number|undefined) + * priority: (number|undefined), + * export: (Function|undefined), + * import: (Function|undefined) * }} */ export let IndexOptions = {}; @@ -65,7 +67,9 @@ export let FieldOptions = {}; * doc: (DocumentDescriptor|Array|undefined), * document: (DocumentDescriptor|Array|undefined), * worker: (boolean|string|undefined), - * priority: (number|undefined) + * priority: (number|undefined), + * export: (Function|undefined), + * import: (Function|undefined) * }} */ export let DocumentOptions = {}; diff --git a/dist/module/worker.js b/dist/module/worker.js index 2fc99f1..ff286dd 100644 --- a/dist/module/worker.js +++ b/dist/module/worker.js @@ -1,3 +1,4 @@ + import { IndexOptions } from "./type.js"; import { create_object, is_function, is_object, is_string } from "./common.js"; import handler from "./worker/handler.js"; @@ -97,6 +98,7 @@ register("import"); apply_async(WorkerIndex.prototype); + function register(key) { WorkerIndex.prototype[key] = diff --git a/dist/module/worker/handler.js b/dist/module/worker/handler.js index 990e152..42feacc 100644 --- a/dist/module/worker/handler.js +++ b/dist/module/worker/handler.js @@ -1,3 +1,4 @@ + import Index from "../index.js"; import { IndexOptions } from "../type.js"; @@ -21,6 +22,7 @@ export default (async function (data) { options = data.options || {}; let filepath = options.config; if (filepath) { + // compiler fix options = options; // will be replaced after build with the line below because // there is an issue with closure compiler dynamic import @@ -33,9 +35,7 @@ export default (async function (data) { // export the FlexSearch global payload to "self" Function("return " + factory)()(self); - index = new self.FlexSearch.Index(options); - // destroy the exported payload delete self.FlexSearch; } else { @@ -55,7 +55,6 @@ export default (async function (data) { } if ("import" === task) { await options.import.call(index, index); - //args = [options.import]; } else { message = index[task].apply(index, args); } diff --git a/dist/module/worker/node.js b/dist/module/worker/node.js index 9d154eb..1602804 100644 --- a/dist/module/worker/node.js +++ b/dist/module/worker/node.js @@ -29,8 +29,8 @@ parentPort.on("message", async function (data) { index = new Index(options); //index.db && await index.db; - parentPort.postMessage({ id: id }); + parentPort.postMessage({ id: id }); break; default: @@ -42,7 +42,6 @@ parentPort.on("message", async function (data) { } if ("import" === task) { await options.import.call(index, index); - //args = [options.import]; } else { message = index[task].apply(index, args); } diff --git a/dist/node/node.js b/dist/node/node.js index dc3f76b..6ad967c 100644 --- a/dist/node/node.js +++ b/dist/node/node.js @@ -1,3 +1,6 @@ +// COMPILER BLOCK --> +import { DEBUG } from "../config.js"; +// <-- COMPILER BLOCK const { parentPort } = require("worker_threads"); //const { join } = require("path"); // Test Path @@ -29,8 +32,8 @@ parentPort.on("message", async function(data){ index = new Index(options); //index.db && await index.db; - parentPort.postMessage({ "id": id }); + parentPort.postMessage({ "id": id }); break; default: @@ -38,11 +41,20 @@ parentPort.on("message", async function(data){ let message; if(task === "export"){ + if(DEBUG){ + if(!options.export || typeof options.export !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); + } + } args = [options.export]; } if(task === "import"){ + if(DEBUG){ + if(!options.import || typeof options.import !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); + } + } await options.import.call(index, index); - //args = [options.import]; } else{ message = index[task].apply(index, args); diff --git a/dist/node/node.mjs b/dist/node/node.mjs index 12eda37..fc79cbb 100644 --- a/dist/node/node.mjs +++ b/dist/node/node.mjs @@ -1,3 +1,6 @@ +// COMPILER BLOCK --> +import { DEBUG } from "../config.js"; +// <-- COMPILER BLOCK import { parentPort } from "worker_threads"; import { join } from "path"; // Test Path @@ -31,8 +34,8 @@ parentPort.on("message", async function(data){ index = new Index(options); //index.db && await index.db; - parentPort.postMessage({ "id": id }); + parentPort.postMessage({ "id": id }); break; default: @@ -40,11 +43,20 @@ parentPort.on("message", async function(data){ let message; if(task === "export"){ + if(DEBUG){ + if(!options.export || typeof options.export !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); + } + } args = [options.export]; } if(task === "import"){ + if(DEBUG){ + if(!options.import || typeof options.import !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); + } + } await options.import.call(index, index); - //args = [options.import]; } else{ message = index[task].apply(index, args); diff --git a/example/nodejs-commonjs/basic-export-import/index.js b/example/nodejs-commonjs/basic-export-import/index.js index 58b125f..1ceb239 100644 --- a/example/nodejs-commonjs/basic-export-import/index.js +++ b/example/nodejs-commonjs/basic-export-import/index.js @@ -59,7 +59,7 @@ const { Index } = require("flexsearch"); const files = await fs.readdir("./export/"); await Promise.all(files.map(async file => { const data = await fs.readFile("./export/" + file, "utf8"); - await index.import(file, data); + index.import(file, data); })); // perform query diff --git a/example/nodejs-commonjs/basic-worker-export-import/index.js b/example/nodejs-commonjs/basic-worker-export-import/index.js index 5997146..966c04e 100644 --- a/example/nodejs-commonjs/basic-worker-export-import/index.js +++ b/example/nodejs-commonjs/basic-worker-export-import/index.js @@ -1,13 +1,18 @@ const { Worker: WorkerIndex } = require("flexsearch"); +// you will need to keep the index configuration +// they will not export, also every change to the +// configuration requires a full re-index +const config = { + tokenize: "forward", + config: __dirname + "/config.js" +}; + (async function(){ // create a simple index which can store id-content-pairs // and await (!) for the worker response - let index = await new WorkerIndex({ - tokenize: "forward", - config: __dirname + "/config.js" - }); + let index = await new WorkerIndex(config); // some test data const data = [ @@ -39,19 +44,16 @@ const { Worker: WorkerIndex } = require("flexsearch"); // EXPORT // ----------------------- - await index.export(function(){ - // do nothing here - }); - - index = await new WorkerIndex({ - tokenize: "forward", - config: __dirname + "/config.js" - }); + await index.export(); // ----------------------- // IMPORT // ----------------------- + // create the same type of index you have used by .export() + // along with the same configuration + index = await new WorkerIndex(config); + await index.import(); // perform query diff --git a/example/nodejs-esm/basic-export-import/index.js b/example/nodejs-esm/basic-export-import/index.js index aeed3ca..744c906 100644 --- a/example/nodejs-esm/basic-export-import/index.js +++ b/example/nodejs-esm/basic-export-import/index.js @@ -34,6 +34,7 @@ result.forEach(i => { console.log(data[i]); }); +// ----------------------- // EXPORT // ----------------------- @@ -44,6 +45,7 @@ await index.export(async function(key, data){ await fs.writeFile("./export/" + key, data, "utf8"); }); +// ----------------------- // IMPORT // ----------------------- @@ -55,7 +57,7 @@ index = new Index(config); const files = await fs.readdir("./export/"); await Promise.all(files.map(async file => { const data = await fs.readFile("./export/" + file, "utf8"); - await index.import(file, data); + index.import(file, data); })) // perform query diff --git a/example/nodejs-esm/basic-worker-export-import/index.js b/example/nodejs-esm/basic-worker-export-import/index.js index 271f13c..eafd40d 100644 --- a/example/nodejs-esm/basic-worker-export-import/index.js +++ b/example/nodejs-esm/basic-worker-export-import/index.js @@ -1,14 +1,19 @@ import { Worker as WorkerIndex } from "flexsearch/esm"; const dirname = import.meta.dirname; +// you will need to keep the index configuration +// they will not export, also every change to the +// configuration requires a full re-index +const config = { + tokenize: "forward", + config: dirname + "/config.js" +}; + (async function(){ // create a simple index which can store id-content-pairs // and await (!) for the worker response - let index = await new WorkerIndex({ - tokenize: "forward", - config: dirname + "/config.js" - }); + let index = await new WorkerIndex(config); // some test data const data = [ @@ -44,15 +49,14 @@ const dirname = import.meta.dirname; // do nothing here }); - index = await new WorkerIndex({ - tokenize: "forward", - config: dirname + "/config.js" - }); - // ----------------------- // IMPORT // ----------------------- + // create the same type of index you have used by .export() + // along with the same configuration + index = await new WorkerIndex(config); + await index.import(); // perform query diff --git a/index.d.ts b/index.d.ts index 8625632..f2b513e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -38,7 +38,8 @@ declare module "flexsearch" { | "strict" | "forward" | "reverse" - | "full"; + | "full" + | "default"; /** * **Document:** @@ -187,12 +188,14 @@ declare module "flexsearch" { // Language-specific Options and Encoding encoder?: Charset | Encoders | EncoderOptions; - encode?: ((x: string) => string[]), + encode?: (text: string) => string[], rtl?: boolean; }; type WorkerIndexOptions = IndexOptions & { config?: WorkerConfigURL | WorkerConfigPath, + export?: () => Promise; + import?: () => Promise; db: null, commit: null }; @@ -297,6 +300,8 @@ declare module "flexsearch" { export class Worker extends Index { constructor(options?: Preset | WorkerIndexOptions); + export(): Promise; + import(): Promise; } /************************************/ @@ -520,7 +525,7 @@ declare module "flexsearch" { type PersistentOptions = { name?: string; type?: IdType; - db?: StorageInterface; + db?: any; }; type DefaultResolve = { @@ -560,7 +565,7 @@ declare module "flexsearch" { result: IntermediateSearchResults } - export class StorageInterface { + class StorageInterface { constructor(name: string, config: PersistentOptions); constructor(config: string | PersistentOptions); mount(index: Index | Document) : Promise; @@ -570,4 +575,8 @@ declare module "flexsearch" { clear() : Promise; db: any; } + + export class IndexedDB extends StorageInterface{ + db: IDBDatabase + } } diff --git a/package-lock.json b/package-lock.json index 074291a..784dead 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.108", + "version": "0.8.109", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.108", + "version": "0.8.109", "funding": [ { "type": "github", @@ -1701,17 +1701,24 @@ } }, "node_modules/glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/glob-base": { @@ -2279,12 +2286,15 @@ } }, "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "dependencies": { "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" } }, "node_modules/minimist": { @@ -4819,15 +4829,15 @@ "optional": true }, "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } @@ -5272,9 +5282,9 @@ } }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "requires": { "brace-expansion": "^1.1.7" diff --git a/package.json b/package.json index ed9fa6a..0a744df 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.108", + "version": "0.8.109", "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 bf7dc29..af366e3 100644 --- a/src/async.js +++ b/src/async.js @@ -1,5 +1,6 @@ import Document from "./document.js"; import Index from "./index.js"; +import WorkerIndex from "./worker.js"; export default function(prototype){ register.call(prototype, "add"); @@ -21,7 +22,7 @@ function tick(key){ /** * @param {!string} key - * @this {Index|Document} + * @this {Index|Document|WorkerIndex} */ function register(key){ diff --git a/src/bundle.js b/src/bundle.js index 85a24e2..79385b9 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -169,6 +169,8 @@ if(SUPPORT_SERIALIZE){ /** @export */ IndexOptions.worker; // worker url /** @export */ IndexOptions.config; // config url /** @export */ IndexOptions.priority; +/** @export */ IndexOptions.export; +/** @export */ IndexOptions.import; /** @export */ FieldOptions.preset; /** @export */ FieldOptions.context; @@ -204,6 +206,8 @@ if(SUPPORT_SERIALIZE){ /** @export */ DocumentOptions.document; /** @export */ DocumentOptions.worker; /** @export */ DocumentOptions.priority; +/** @export */ DocumentOptions.export; +/** @export */ DocumentOptions.import; /** @export */ ContextOptions.depth; /** @export */ ContextOptions.bidirectional; diff --git a/src/config.js b/src/config.js index 24d6904..0782c7f 100644 --- a/src/config.js +++ b/src/config.js @@ -5,7 +5,7 @@ export const RELEASE = "custom"; export const DEBUG = true; /** @define {boolean} */ -export const PROFILER = true; +export const PROFILER = false; /** @define {boolean} */ export const POLYFILL = false; diff --git a/src/document.js b/src/document.js index b5e1c1b..dc5335a 100644 --- a/src/document.js +++ b/src/document.js @@ -58,7 +58,7 @@ export default function Document(options){ keystore = SUPPORT_KEYSTORE && (options.keystore || 0); keystore && (this.keystore = keystore); this.fastupdate = !!options.fastupdate; - this.reg = this.fastupdate + this.reg = this.fastupdate && (!SUPPORT_WORKER || !options.worker) && (!SUPPORT_PERSISTENT || !options.db) ? (keystore && SUPPORT_KEYSTORE ? new KeystoreMap(keystore) : new Map()) : (keystore && SUPPORT_KEYSTORE ? new KeystoreSet(keystore) : new Set()); @@ -134,6 +134,7 @@ export default function Document(options){ // resolve worker promises and swap instances if(SUPPORT_WORKER && this.worker){ + this.fastupdate = false; const promises = []; for(const index of this.index.values()){ index.then && promises.push(index); @@ -152,7 +153,10 @@ export default function Document(options){ } } else if(SUPPORT_PERSISTENT){ - options.db && this.mount(options.db); + if(options.db){ + this.fastupdate = false; + this.mount(options.db); + } } } @@ -164,6 +168,12 @@ if(SUPPORT_PERSISTENT){ */ Document.prototype.mount = function(db){ + if(DEBUG){ + if(this.worker){ + throw new 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 fields = this.field; if(SUPPORT_TAGS && this.tag){ diff --git a/src/index.js b/src/index.js index c9a7d26..0efa6ac 100644 --- a/src/index.js +++ b/src/index.js @@ -83,7 +83,7 @@ export default function Index(options, _register){ } this.resolution = options.resolution || 9; - this.tokenize = tmp = options.tokenize || "strict"; + this.tokenize = ((tmp = options.tokenize) && tmp !== "default") || "strict"; this.depth = (tmp === "strict" && context.depth) || 0; this.bidirectional = context.bidirectional !== false; this.fastupdate = !!options.fastupdate; diff --git a/src/index/search.js b/src/index/search.js index 9f4b5e0..967d426 100644 --- a/src/index/search.js +++ b/src/index/search.js @@ -413,22 +413,20 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag){ tag ); - resolve = !SUPPORT_RESOLVER || resolve; - if(SUPPORT_PERSISTENT && this.db){ return result.then(function(result){ - return resolve + return !SUPPORT_RESOLVER || resolve ? result || [] : new Resolver(result); }); } return result && result.length - ? (resolve + ? (!SUPPORT_RESOLVER || resolve ? resolve_default.call(this, /** @type {SearchResults|EnrichedSearchResults} */ (result), limit, offset) : new Resolver(result) ) - : resolve + : !SUPPORT_RESOLVER || resolve ? [] : new Resolver(); } diff --git a/src/intersect.js b/src/intersect.js index 62b72b4..f596838 100644 --- a/src/intersect.js +++ b/src/intersect.js @@ -252,7 +252,7 @@ export function intersect_union(arrays, mandatory, resolve) { } } - if(resolve){ + if(!SUPPORT_RESOLVER || resolve){ for(let i = 0, id; i < arrays.length; i++){ id = arrays[i]; if(check[id]){ diff --git a/src/type.js b/src/type.js index d343c8d..3816e96 100644 --- a/src/type.js +++ b/src/type.js @@ -21,7 +21,9 @@ import StorageInterface from "./db/interface.js"; * commit: (boolean|undefined), * worker: (string|undefined), * config: (string|undefined), - * priority: (number|undefined) + * priority: (number|undefined), + * export: (Function|undefined), + * import: (Function|undefined) * }} */ export let IndexOptions = {}; @@ -65,7 +67,9 @@ export let FieldOptions = {}; * doc: (DocumentDescriptor|Array|undefined), * document: (DocumentDescriptor|Array|undefined), * worker: (boolean|string|undefined), - * priority: (number|undefined) + * priority: (number|undefined), + * export: (Function|undefined), + * import: (Function|undefined) * }} */ export let DocumentOptions = {}; diff --git a/src/worker.js b/src/worker.js index c5fac26..14ae6bf 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,3 +1,6 @@ +// COMPILER BLOCK --> +import { SUPPORT_ASYNC } from "./config.js"; +// <-- COMPILER BLOCK import { IndexOptions } from "./type.js"; import { create_object, is_function, is_object, is_string } from "./common.js"; import handler from "./worker/handler.js"; @@ -102,7 +105,9 @@ register("clear"); register("export"); register("import"); -apply_async(WorkerIndex.prototype); +if(SUPPORT_ASYNC){ + apply_async(WorkerIndex.prototype); +} function register(key){ diff --git a/src/worker/handler.js b/src/worker/handler.js index 0f4f7c0..4e420da 100644 --- a/src/worker/handler.js +++ b/src/worker/handler.js @@ -1,3 +1,6 @@ +// COMPILER BLOCK --> +import { DEBUG } from "../config.js"; +// <-- COMPILER BLOCK import Index from "../index.js"; import { IndexOptions } from "../type.js"; @@ -21,6 +24,7 @@ export default async function(data) { options = data["options"] || {}; let filepath = options.config; if(filepath){ + // compiler fix options = options; // will be replaced after build with the line below because // there is an issue with closure compiler dynamic import @@ -33,9 +37,7 @@ export default async function(data) { // export the FlexSearch global payload to "self" Function("return " + factory)()(self); - index = new self["FlexSearch"]["Index"](options); - // destroy the exported payload delete self["FlexSearch"]; } @@ -52,11 +54,20 @@ export default async function(data) { let message; if(task === "export"){ + if(DEBUG){ + if(!options.export || typeof options.export !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); + } + } args = [options.export]; } if(task === "import"){ + if(DEBUG){ + if(!options.import || typeof options.import !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); + } + } await options.import.call(index, index); - //args = [options.import]; } else{ message = index[task].apply(index, args); diff --git a/src/worker/node.js b/src/worker/node.js index dc3f76b..6ad967c 100644 --- a/src/worker/node.js +++ b/src/worker/node.js @@ -1,3 +1,6 @@ +// COMPILER BLOCK --> +import { DEBUG } from "../config.js"; +// <-- COMPILER BLOCK const { parentPort } = require("worker_threads"); //const { join } = require("path"); // Test Path @@ -29,8 +32,8 @@ parentPort.on("message", async function(data){ index = new Index(options); //index.db && await index.db; - parentPort.postMessage({ "id": id }); + parentPort.postMessage({ "id": id }); break; default: @@ -38,11 +41,20 @@ parentPort.on("message", async function(data){ let message; if(task === "export"){ + if(DEBUG){ + if(!options.export || typeof options.export !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); + } + } args = [options.export]; } if(task === "import"){ + if(DEBUG){ + if(!options.import || typeof options.import !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); + } + } await options.import.call(index, index); - //args = [options.import]; } else{ message = index[task].apply(index, args); diff --git a/src/worker/node.mjs b/src/worker/node.mjs index 12eda37..fc79cbb 100644 --- a/src/worker/node.mjs +++ b/src/worker/node.mjs @@ -1,3 +1,6 @@ +// COMPILER BLOCK --> +import { DEBUG } from "../config.js"; +// <-- COMPILER BLOCK import { parentPort } from "worker_threads"; import { join } from "path"; // Test Path @@ -31,8 +34,8 @@ parentPort.on("message", async function(data){ index = new Index(options); //index.db && await index.db; - parentPort.postMessage({ "id": id }); + parentPort.postMessage({ "id": id }); break; default: @@ -40,11 +43,20 @@ parentPort.on("message", async function(data){ let message; if(task === "export"){ + if(DEBUG){ + if(!options.export || typeof options.export !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); + } + } args = [options.export]; } if(task === "import"){ + if(DEBUG){ + if(!options.import || typeof options.import !== "function"){ + throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); + } + } await options.import.call(index, index); - //args = [options.import]; } else{ message = index[task].apply(index, args);