From 112a07725f72cdbf59ba96dfddf3b826bc53708b Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Tue, 1 Apr 2025 10:29:03 +0200 Subject: [PATCH] improve result highlighting #480 --- dist/flexsearch.bundle.debug.js | 578 +++++++++---------- dist/flexsearch.bundle.min.js | 175 +++--- dist/flexsearch.bundle.module.debug.js | 572 +++++++++--------- dist/flexsearch.bundle.module.min.js | 177 +++--- dist/flexsearch.compact.debug.js | 736 ++++++++++++------------ dist/flexsearch.compact.min.js | 95 ++- dist/flexsearch.compact.module.debug.js | 730 ++++++++++++----------- dist/flexsearch.compact.module.min.js | 97 ++-- dist/flexsearch.es5.debug.js | 626 ++++++++++---------- dist/flexsearch.es5.min.js | 157 +++-- dist/flexsearch.light.debug.js | 190 +++--- dist/flexsearch.light.min.js | 26 +- dist/flexsearch.light.module.debug.js | 184 +++--- dist/flexsearch.light.module.min.js | 28 +- dist/module-debug/bundle.js | 2 + dist/module-debug/document/search.js | 67 +-- dist/module-debug/index.js | 56 +- dist/module-debug/index/remove.js | 35 +- dist/module-debug/intersect.js | 7 +- dist/module-min/bundle.js | 2 +- dist/module-min/document/search.js | 2 +- dist/module-min/index.js | 2 +- dist/module-min/index/remove.js | 2 +- dist/module-min/intersect.js | 2 +- dist/module/bundle.js | 2 + dist/module/document/search.js | 67 +-- dist/module/index.js | 56 +- dist/module/index/remove.js | 35 +- dist/module/intersect.js | 7 +- index.d.ts | 55 +- package-lock.json | 4 +- package.json | 2 +- src/bundle.js | 2 + src/document/search.js | 68 +-- test/highlight.js | 69 ++- 35 files changed, 2466 insertions(+), 2449 deletions(-) diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 76c6f3f..c844cad 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,12 +1,12 @@ /**! - * FlexSearch.js v0.8.147 (Bundle/Debug) + * FlexSearch.js v0.8.149 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ (function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f; -var t; +var v; function z(a, c, b) { const e = typeof b, d = typeof a; if ("undefined" !== e) { @@ -47,10 +47,10 @@ function z(a, c, b) { function B() { return Object.create(null); } -function E(a) { +function F(a) { return "string" === typeof a; } -function I(a) { +function H(a) { return "object" === typeof a; } function aa(a) { @@ -61,7 +61,7 @@ function aa(a) { return c; } function ba(a, c) { - if (E(c)) { + if (F(c)) { a = a[c]; } else { for (let b = 0; a && b < c.length; b++) { @@ -90,8 +90,8 @@ function ja(a = {}) { this.assign(a); } } -t = ja.prototype; -t.assign = function(a) { +v = ja.prototype; +v.assign = function(a) { this.normalize = z(a.normalize, !0, this.normalize); let c = a.include, b = c || a.exclude || a.split, e; if (b || "" === b) { @@ -155,20 +155,20 @@ t.assign = function(a) { } return this; }; -t.addStemmer = function(a, c) { +v.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && J(this); + this.cache && I(this); return this; }; -t.addFilter = function(a) { +v.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && J(this); + this.cache && I(this); return this; }; -t.addMapper = function(a, c) { +v.addMapper = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -177,10 +177,10 @@ t.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && J(this); + this.cache && I(this); return this; }; -t.addMatcher = function(a, c) { +v.addMatcher = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -191,26 +191,26 @@ t.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && J(this); + this.cache && I(this); return this; }; -t.addReplacer = function(a, c) { +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 && J(this); + this.cache && I(this); return this; }; -t.encode = function(a) { +v.encode = function(a) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.B.has(a)) { return this.B.get(a); } } else { - this.H = setTimeout(J, 50, this); + this.H = setTimeout(I, 50, this); } } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ia ? a.normalize("NFKD").replace(ia, "").toLowerCase() : a.toLowerCase()); @@ -232,7 +232,7 @@ t.encode = function(a) { continue; } } else { - this.H = setTimeout(J, 50, this); + this.H = setTimeout(I, 50, this); } } this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), d = g, g = g.replace(this.N, h => this.stemmer.get(h)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); @@ -259,12 +259,12 @@ t.encode = function(a) { this.cache && a.length <= this.K && (this.B.set(a, b), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); return b; }; -function J(a) { +function I(a) { a.H = null; a.B.clear(); a.G.clear(); } -;let K, M; +;let J, M; async function ka(a) { a = a.data; var c = a.task; @@ -273,7 +273,7 @@ async function ka(a) { switch(c) { case "init": M = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), K = new self.FlexSearch.Index(M), delete self.FlexSearch) : K = new N(M); + (c = a.factory) ? (Function("return " + c)()(self), J = new self.FlexSearch.Index(M), delete self.FlexSearch) : J = new N(M); postMessage({id:b}); break; default: @@ -288,9 +288,9 @@ async function ka(a) { if (!M.import || "function" !== typeof M.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - e[0] && (a = await M.import.call(K, e[0]), K.import(e[0], a)); + e[0] && (a = await M.import.call(J, e[0]), J.import(e[0], a)); } else { - (d = e && K[c].apply(K, e)) && d.then && (d = await d); + (d = e && J[c].apply(J, e)) && d.then && (d = await d); } postMessage("search" === c ? {id:b, msg:d} : {id:b}); } @@ -598,35 +598,35 @@ T.prototype.add = function(a) { let b = this.index[c]; b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.h.push(b), this.size++); }; -t = S.prototype; -t.has = T.prototype.has = function(a) { +v = S.prototype; +v.has = T.prototype.has = function(a) { const c = this.index[this.B(a)]; return c && c.has(a); }; -t.delete = T.prototype.delete = function(a) { +v.delete = T.prototype.delete = function(a) { const c = this.index[this.B(a)]; c && c.delete(a) && this.size--; }; -t.clear = T.prototype.clear = function() { +v.clear = T.prototype.clear = function() { this.index = B(); this.h = []; this.size = 0; }; -t.values = T.prototype.values = function*() { +v.values = T.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].values()) { yield c; } } }; -t.keys = T.prototype.keys = function*() { +v.keys = T.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].keys()) { yield c; } } }; -t.entries = T.prototype.entries = function*() { +v.entries = T.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].entries()) { yield c; @@ -661,7 +661,7 @@ function Ba(a) { return b; } ;U.prototype.add = function(a, c, b) { - I(a) && (c = a, a = ba(c, this.key)); + H(a) && (c = a, a = ba(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -674,7 +674,7 @@ function Ba(a) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Da(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : F(h) && (h = [h]), Da(c, h, this.J, 0, e, a, h[0], b); } } } @@ -696,7 +696,7 @@ function Ba(a) { f = ba(c, f); } if (d && f) { - E(f) && (f = [f]); + F(f) && (f = [f]); for (let h = 0, l, n; h < f.length; h++) { if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? n = g : d.set(l, n = []), !b || !n.includes(a))) { if (n.length === 2 ** 31 - 1) { @@ -733,7 +733,7 @@ function Ba(a) { continue; } l = [l.V]; - } else if (E(l) || l.constructor === String) { + } else if (F(l) || l.constructor === String) { k[l] = c[l]; continue; } @@ -791,19 +791,19 @@ function Da(a, c, b, e, d, f, g, k) { let h = [], l, n; l = B(); for (let m = 0, q, p, r, u; m < c; m++) { - for (let v = 0; v < k; v++) { - if (r = a[v], m < r.length && (q = r[m])) { + for (let t = 0; t < k; t++) { + if (r = a[t], m < r.length && (q = r[m])) { for (let w = 0; w < q.length; w++) { p = q[w]; (n = l[p]) ? l[p]++ : (n = 0, l[p] = 1); u = h[n] || (h[n] = []); if (!g) { - let y = m + (v || !d ? 0 : f || 0); + let y = m + (t || !d ? 0 : f || 0); u = u[y] || (u[y] = []); } u.push(p); if (g && b && n === k - 1 && u.length - e === b) { - return u; + return e ? u.slice(e) : u; } } } @@ -1214,7 +1214,7 @@ W.prototype.resolve = function(a, c, b) { }; B(); U.prototype.search = function(a, c, b, e) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let d = []; var f = [], g; let k; @@ -1233,7 +1233,7 @@ U.prototype.search = function(a, c, b, e) { m = !1 !== b.resolve; if (!m && !p) { if (h = h || this.field) { - E(h) ? p = h : (h.constructor === Array && 1 === h.length && (h = h[0]), p = h.field || h.index); + F(h) ? p = h : (h.constructor === Array && 1 === h.length && (h = h[0]), p = h.field || h.index); } if (!p) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); @@ -1246,53 +1246,53 @@ U.prototype.search = function(a, c, b, e) { c || (c = 100); if (l && (!this.db || !e)) { l.constructor !== Array && (l = [l]); - var v = []; + var t = []; for (let A = 0, x; A < l.length; A++) { x = l[A]; - if (E(x)) { + if (F(x)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (x.field && x.tag) { var w = x.tag; if (w.constructor === Array) { for (var y = 0; y < w.length; y++) { - v.push(x.field, w[y]); + t.push(x.field, w[y]); } } else { - v.push(x.field, w); + t.push(x.field, w); } } else { w = Object.keys(x); - for (let D = 0, H, C; D < w.length; D++) { - if (H = w[D], C = x[H], C.constructor === Array) { - for (y = 0; y < C.length; y++) { - v.push(H, C[y]); + for (let C = 0, G, D; C < w.length; C++) { + if (G = w[C], D = x[G], D.constructor === Array) { + for (y = 0; y < D.length; y++) { + t.push(G, D[y]); } } else { - v.push(H, C); + t.push(G, D); } } } } - if (!v.length) { + if (!t.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = v; + l = t; if (!a) { m = []; - if (v.length) { - for (f = 0; f < v.length; f += 2) { + if (t.length) { + for (f = 0; f < t.length; f += 2) { if (this.db) { - p = this.index.get(v[f]); + p = this.index.get(t[f]); if (!p) { - console.warn("Tag '" + v[f] + ":" + v[f + 1] + "' will be skipped because there is no field '" + v[f] + "'."); + console.warn("Tag '" + t[f] + ":" + t[f + 1] + "' will be skipped because there is no field '" + t[f] + "'."); continue; } - m.push(p = p.db.tag(v[f + 1], c, u, g)); + m.push(p = p.db.tag(t[f + 1], c, u, g)); } else { - p = Qa.call(this, v[f], v[f + 1], c, u, g); + p = Qa.call(this, t[f], t[f + 1], c, u, g); } - d.push({field:v[f], tag:v[f + 1], result:p}); + d.push({field:t[f], tag:t[f + 1], result:p}); } } return m.length ? Promise.all(m).then(function(A) { @@ -1306,34 +1306,34 @@ U.prototype.search = function(a, c, b, e) { h && h.constructor !== Array && (h = [h]); } h || (h = this.field); - v = !e && (this.worker || this.db) && []; - let F; - for (let A = 0, x, D, H; A < h.length; A++) { - D = h[A]; + t = !e && (this.worker || this.db) && []; + let E; + for (let A = 0, x, C, G; A < h.length; A++) { + C = h[A]; if (this.db && this.tag && !this.D[A]) { continue; } - let C; - E(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, u = C.offset || u, r = C.suggest || r, g = this.store && (C.enrich || g)); + let D; + F(C) || (D = C, C = D.field, a = D.query || a, c = D.limit || c, u = D.offset || u, r = D.suggest || r, g = this.store && (D.enrich || g)); if (e) { x = e[A]; } else { - if (w = C || b, y = this.index.get(D), l && (this.db && (w.tag = l, F = y.db.support_tag_search, w.field = h), F || (w.enrich = !1)), v) { - v[A] = y.search(a, c, w); + if (w = D || b, y = this.index.get(C), l && (this.db && (w.tag = l, E = y.db.support_tag_search, w.field = h), E || (w.enrich = !1)), t) { + t[A] = y.search(a, c, w); w && g && (w.enrich = g); continue; } else { x = y.search(a, c, w), w && g && (w.enrich = g); } } - H = x && (m ? x.length : x.result.length); - if (l && H) { + G = x && (m ? x.length : x.result.length); + if (l && G) { w = []; y = 0; if (this.db && e) { - if (!F) { - for (let G = h.length; G < e.length; G++) { - let L = e[G]; + if (!E) { + for (let K = h.length; K < e.length; K++) { + let L = e[K]; if (L && L.length) { y++, w.push(L); } else if (!r) { @@ -1342,16 +1342,16 @@ U.prototype.search = function(a, c, b, e) { } } } else { - for (let G = 0, L, sb; G < l.length; G += 2) { - L = this.tag.get(l[G]); + for (let K = 0, L, rb; K < l.length; K += 2) { + L = this.tag.get(l[K]); if (!L) { - if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), r) { + if (console.warn("Tag '" + l[K] + ":" + l[K + 1] + "' will be skipped because there is no field '" + l[K] + "'."), r) { continue; } else { return m ? d : new W(d); } } - if (sb = (L = L && L.get(l[G + 1])) && L.length) { + if (rb = (L = L && L.get(l[K + 1])) && L.length) { y++, w.push(L); } else if (!r) { return m ? d : new W(d); @@ -1360,21 +1360,21 @@ U.prototype.search = function(a, c, b, e) { } if (y) { x = Ha(x, w, m); - H = x.length; - if (!H && !r) { + G = x.length; + if (!G && !r) { return m ? x : new W(x); } y--; } } - if (H) { - f[n] = D, d.push(x), n++; + if (G) { + f[n] = C, d.push(x), n++; } else if (1 === h.length) { return m ? d : new W(d); } } - if (v) { - if (this.db && l && l.length && !F) { + if (t) { + if (this.db && l && l.length && !E) { for (g = 0; g < l.length; g += 2) { f = this.index.get(l[g]); if (!f) { @@ -1384,11 +1384,11 @@ U.prototype.search = function(a, c, b, e) { return m ? d : new W(d); } } - v.push(f.db.tag(l[g + 1], c, u, !1)); + t.push(f.db.tag(l[g + 1], c, u, !1)); } } const A = this; - return Promise.all(v).then(function(x) { + return Promise.all(t).then(function(x) { return x.length ? A.search(a, c, b, x) : x; }); } @@ -1398,20 +1398,20 @@ U.prototype.search = function(a, c, b, e) { if (p && (!g || !this.store)) { return d[0]; } - v = []; + t = []; for (u = 0; u < f.length; u++) { r = d[u]; - g && r.length && "undefined" === typeof r[0].doc && (this.db ? v.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = V.call(this, r)); + g && r.length && "undefined" === typeof r[0].doc && (this.db ? t.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = V.call(this, r)); if (p) { return m ? r : new W(r); } d[u] = {field:f[u], result:r}; } - if (g && this.db && v.length) { + if (g && this.db && t.length) { const A = this; - return Promise.all(v).then(function(x) { - for (let D = 0; D < x.length; D++) { - d[D].result = x[D]; + return Promise.all(t).then(function(x) { + for (let C = 0; C < x.length; C++) { + d[C].result = x[C]; } return k ? Ra(d, c) : q ? Sa(d, a, A.index, A.field, A.D, q) : d; }); @@ -1420,45 +1420,41 @@ U.prototype.search = function(a, c, b, e) { }; function Sa(a, c, b, e, d, f) { let g, k, h; - for (let n = 0, m, q, p, r; n < a.length; n++) { - let u = a[n].result; - m = a[n].field; - p = b.get(m); - q = p.encoder; - h = p.tokenize; - r = d[e.indexOf(m)]; - q !== g && (g = q, k = g.encode(c)); - for (let v = 0; v < u.length; v++) { - let w = ""; - var l = ba(u[v].doc, r); - let y = g.encode(l); - l = l.split(g.split); - for (let F = 0, A, x; F < y.length; F++) { - A = y[F]; - x = l[F]; - if (!A || !x) { - continue; - } - let D; - for (let H = 0, C; H < k.length; H++) { - if (C = k[H], "strict" === h) { - if (A === C) { - w += (w ? " " : "") + f.replace("$1", x); - D = !0; - break; - } - } else { - const G = A.indexOf(C); - if (-1 < G) { - w += (w ? " " : "") + x.substring(0, G) + f.replace("$1", x.substring(G, C.length)) + x.substring(G + C.length); - D = !0; - break; + for (let l = 0, n, m, q, p; l < a.length; l++) { + let r = a[l].result; + n = a[l].field; + q = b.get(n); + m = q.encoder; + h = q.tokenize; + p = d[e.indexOf(n)]; + m !== g && (g = m, k = g.encode(c)); + for (let u = 0; u < r.length; u++) { + let t = "", w = ba(r[u].doc, p).split(/\s+/); + for (let y = 0, E, A; y < w.length; y++) { + E = w[y]; + A = g.encode(E).join(" "); + let x; + if (A && E) { + for (let C = 0, G; C < k.length; C++) { + if (G = k[C], "strict" === h) { + if (A === G) { + t += (t ? " " : "") + f.replace("$1", E); + x = !0; + break; + } + } else { + const D = A.indexOf(G); + if (-1 < D) { + t += (t ? " " : "") + E.substring(0, D) + f.replace("$1", E.substring(D, G.length)) + E.substring(D + G.length); + x = !0; + break; + } } } } - D || (w += (w ? " " : "") + l[F]); + x || (t += (t ? " " : "") + w[y]); } - u[v].highlight = w; + r[u].highlight = t; } } return a; @@ -1564,8 +1560,8 @@ function V(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -t = U.prototype; -t.mount = function(a) { +v = U.prototype; +v.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } @@ -1594,7 +1590,7 @@ t.mount = function(a) { this.db = !0; return Promise.all(b); }; -t.commit = async function(a, c) { +v.commit = async function(a, c) { const b = []; for (const e of this.index.values()) { b.push(e.commit(a, c)); @@ -1602,7 +1598,7 @@ t.commit = async function(a, c) { await Promise.all(b); this.reg.clear(); }; -t.destroy = function() { +v.destroy = function() { const a = []; for (const c of this.index.values()) { a.push(c.destroy()); @@ -1612,11 +1608,11 @@ t.destroy = function() { function Ua(a, c) { const b = new Map(); let e = c.index || c.field || c; - E(e) && (e = [e]); + F(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { f = e[d]; - E(f) || (g = f, f = f.field); - g = I(g) ? Object.assign({}, a, g) : a; + F(f) || (g = f, f = f.field); + g = H(g) ? Object.assign({}, a, g) : a; if (this.worker) { const k = new P(g); b.set(f, k); @@ -1627,7 +1623,7 @@ function Ua(a, c) { } if (this.C) { a = c.store; - E(a) && (a = [a]); + F(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ta(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); } @@ -1643,14 +1639,14 @@ function Ta(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -t.append = function(a, c) { +v.append = function(a, c) { return this.add(a, c, !0); }; -t.update = function(a, c) { +v.update = function(a, c) { return this.remove(a).add(a, c); }; -t.remove = function(a) { - I(a) && (a = ba(a, this.key)); +v.remove = function(a) { + H(a) && (a = ba(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1670,7 +1666,7 @@ t.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -t.clear = function() { +v.clear = function() { const a = []; for (const c of this.index.values()) { const b = c.clear(); @@ -1685,27 +1681,27 @@ t.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -t.contain = function(a) { +v.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -t.cleanup = function() { +v.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -t.get = function(a) { +v.get = function(a) { return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) { return c[0] && c[0].doc || null; }) : this.store.get(a) || null; }; -t.set = function(a, c) { +v.set = function(a, c) { "object" === typeof a && (c = a, a = ba(c, this.key)); this.store.set(a, c); return this; }; -t.searchCache = Va; -t.export = function(a, c, b = 0, e = 0) { +v.searchCache = Va; +v.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { @@ -1738,7 +1734,7 @@ t.export = function(a, c, b = 0, e = 0) { } return ya.call(this, a, c, d, f, b, e); }; -t.import = function(a, c) { +v.import = function(a, c) { var b = a.split("."); "json" === b[b.length - 1] && b.pop(); const e = 2 < b.length ? b[0] : ""; @@ -1830,7 +1826,57 @@ var bb = {X:Wa, W:Xa, Y:Xa, LatinBalance:{dedupe:!0, mapper:Ya}, LatinAdvanced:{ a[b] = e; } }}, LatinExact:Wa, LatinDefault:Xa, LatinSimple:Xa}; -const cb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +N.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { + if (this.fastupdate) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { + if (2 > d.length) { + d.pop(); + } else { + const f = d.indexOf(a); + f === b.length - 1 ? d.pop() : d.splice(f, 1); + } + } + } + } else { + cb(this.map, a), this.depth && cb(this.ctx, a); + } + c || this.reg.delete(a); + } + this.db && (this.commit_task.push({del:a}), this.T && db(this)); + this.cache && this.cache.remove(a); + return this; +}; +function cb(a, c) { + let b = 0; + var e = "undefined" === typeof c; + if (a.constructor === Array) { + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && f.length) { + if (e) { + b++; + } else { + if (g = f.indexOf(c), 0 <= g) { + 1 < f.length ? (f.splice(g, 1), b++) : delete a[d]; + break; + } else { + b++; + } + } + } + } + } else { + for (let d of a.entries()) { + e = d[0]; + const f = cb(d[1], c); + f ? b += f : a.delete(e); + } + } + return b; +} +;const eb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; N.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1843,16 +1889,16 @@ N.prototype.add = function(a, c, b, e) { let r = c[this.rtl ? e - 1 - p : p]; var d = r.length; if (d && (m || !n[r])) { - var f = this.score ? this.score(c, r, p, null, 0) : db(q, e, p), g = ""; + var f = this.score ? this.score(c, r, p, null, 0) : fb(q, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let u = 0, v; u < d; u++) { + for (let u = 0, t; u < d; u++) { for (f = d; f > u; f--) { g = r.substring(u, f); - v = this.rtl ? d - 1 - u : u; - var k = this.score ? this.score(c, r, p, g, v) : db(q, e, p, d, v); - eb(this, n, g, k, a, b); + t = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(c, r, p, g, t) : fb(q, e, p, d, t); + gb(this, n, g, k, a, b); } } break; @@ -1862,25 +1908,25 @@ N.prototype.add = function(a, c, b, e) { if (1 < d) { for (k = d - 1; 0 < k; k--) { g = r[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, r, p, g, k) : db(q, e, p, d, k); - eb(this, n, g, h, a, b); + var h = this.score ? this.score(c, r, p, g, k) : fb(q, e, p, d, k); + gb(this, n, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[this.rtl ? d - 1 - k : k], eb(this, n, g, f, a, b); + g += r[this.rtl ? d - 1 - k : k], gb(this, n, g, f, a, b); } break; } default: - if (eb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { + if (gb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { for (d = B(), g = this.U, f = r, k = Math.min(m + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { if ((r = c[this.rtl ? e - 1 - p - h : p + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(c, f, p, r, h - 1) : db(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; - eb(this, l, v ? f : r, u, a, b, v ? r : f); + const u = this.score ? this.score(c, f, p, r, h - 1) : fb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), t = this.bidirectional && r > f; + gb(this, l, t ? f : r, u, a, b, t ? r : f); } } } @@ -1892,10 +1938,10 @@ N.prototype.add = function(a, c, b, e) { c = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.T && fb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && db(this)); return this; }; -function eb(a, c, b, e, d, f, g) { +function gb(a, c, b, e, d, f, g) { let k = g ? a.ctx : a.map, h; if (!c[b] || g && !(h = c[b])[g]) { if (g ? (c = h || (c[b] = B()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { @@ -1913,62 +1959,62 @@ function eb(a, c, b, e, d, f, g) { } } } -function db(a, c, b, e, d) { +function fb(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;N.prototype.search = function(a, c, b) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let e = [], d, f, g, k = 0, h, l, n, m, q; b ? (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, q = (h = !1 !== b.resolve) && b.enrich, n = b.boost, m = b.resolution, l = this.db && b.tag) : h = this.resolve; let p = this.encoder.encode(a); d = p.length; c = c || (h ? 100 : 0); if (1 === d) { - return gb.call(this, p[0], "", c, k, h, q, l); + return hb.call(this, p[0], "", c, k, h, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return gb.call(this, p[1], p[0], c, k, h, q, l); + return hb.call(this, p[1], p[0], c, k, h, q, l); } - let r = B(), u = 0, v; - 1 < d && f && (v = p[0], u = 1); - m || 0 === m || (m = v ? this.U : this.resolution); + let r = B(), u = 0, t; + 1 < d && f && (t = p[0], u = 1); + m || 0 === m || (m = t ? this.U : this.resolution); if (this.db) { if (this.db.search && (a = this.db.search(this, p, c, k, g, h, q, l), !1 !== a)) { return a; } const w = this; return async function() { - for (let y, F; u < d; u++) { - if ((F = p[u]) && !r[F]) { - r[F] = 1; - y = await hb(w, F, v, 0, 0, !1, !1); - if (y = ib(y, e, g, m)) { + for (let y, E; u < d; u++) { + if ((E = p[u]) && !r[E]) { + r[E] = 1; + y = await ib(w, E, t, 0, 0, !1, !1); + if (y = jb(y, e, g, m)) { e = y; break; } - v && (g && y && e.length || (v = F)); + t && (g && y && e.length || (t = E)); } - g && v && u === d - 1 && !e.length && (m = w.resolution, v = "", u = -1, r = B()); + g && t && u === d - 1 && !e.length && (m = w.resolution, t = "", u = -1, r = B()); } - return jb(e, m, c, k, g, n, h); + return kb(e, m, c, k, g, n, h); }(); } for (let w, y; u < d; u++) { if ((y = p[u]) && !r[y]) { r[y] = 1; - w = hb(this, y, v, 0, 0, !1, !1); - if (w = ib(w, e, g, m)) { + w = ib(this, y, t, 0, 0, !1, !1); + if (w = jb(w, e, g, m)) { e = w; break; } - v && (g && w && e.length || (v = y)); + t && (g && w && e.length || (t = y)); } - g && v && u === d - 1 && !e.length && (m = this.resolution, v = "", u = -1, r = B()); + g && t && u === d - 1 && !e.length && (m = this.resolution, t = "", u = -1, r = B()); } - return jb(e, m, c, k, g, n, h); + return kb(e, m, c, k, g, n, h); }; -function jb(a, c, b, e, d, f, g) { +function kb(a, c, b, e, d, f, g) { let k = a.length, h = a; if (1 < k) { h = Fa(a, c, b, e, d, f, g); @@ -1977,13 +2023,13 @@ function jb(a, c, b, e, d, f, g) { } return g ? h : new W(h); } -function gb(a, c, b, e, d, f, g) { - a = hb(this, a, c, b, e, d, f, g); +function hb(a, c, b, e, d, f, g) { + a = ib(this, a, c, b, e, d, f, g); return this.db ? a.then(function(k) { return d ? k || [] : new W(k); }) : a && a.length ? d ? Ia.call(this, a, b, e) : new W(a) : d ? [] : new W(); } -function ib(a, c, b, e) { +function jb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -2004,7 +2050,7 @@ function ib(a, c, b, e) { return d; } } -function hb(a, c, b, e, d, f, g, k) { +function ib(a, c, b, e, d, f, g, k) { let h; b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); if (a.db) { @@ -2013,62 +2059,18 @@ function hb(a, c, b, e, d, f, g, k) { a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;N.prototype.remove = function(a, c) { - const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (b) { - if (this.fastupdate) { - for (let e = 0, d; e < b.length; e++) { - if (d = b[e]) { - if (2 > d.length) { - d.pop(); - } else { - const f = d.indexOf(a); - f === b.length - 1 ? d.pop() : d.splice(f, 1); - } - } - } - } else { - kb(this.map, a), this.depth && kb(this.ctx, a); - } - c || this.reg.delete(a); - } - this.db && (this.commit_task.push({del:a}), this.T && fb(this)); - this.cache && this.cache.remove(a); - return this; -}; -function kb(a, c) { - let b = 0; - if (a.constructor === Array) { - for (let e = 0, d, f; e < a.length; e++) { - if ((d = a[e]) && d.length) { - if (f = d.indexOf(c), 0 <= f) { - 1 < d.length ? (d.splice(f, 1), b++) : delete a[e]; - break; - } else { - b++; - } - } - } - } else { - for (let e of a.entries()) { - const d = e[0], f = kb(e[1], c); - f ? b += f : a.delete(d); - } - } - return b; -} ;function N(a, c) { if (!this || this.constructor !== N) { return new N(a); } if (a) { - var b = E(a) ? a : a.preset; - b && (cb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, cb[b], a)); + var b = F(a) ? a : a.preset; + b && (eb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, eb[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || {}; + const e = !0 === b ? {depth:1} : b || {}, d = F(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new ja(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; @@ -2093,26 +2095,26 @@ function kb(a, c) { this.commit_timer = null; this.priority = a.priority || 4; } -t = N.prototype; -t.mount = function(a) { +v = N.prototype; +v.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -t.commit = function(a, c) { +v.commit = function(a, c) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.commit(this, a, c); }; -t.destroy = function() { +v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function fb(a) { +function db(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 1)); } -t.clear = function() { +v.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -2120,40 +2122,26 @@ t.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -t.append = function(a, c) { +v.append = function(a, c) { return this.add(a, c, !0); }; -t.contain = function(a) { +v.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -t.update = function(a, c) { +v.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function lb(a) { - let c = 0; - if (a.constructor === Array) { - for (let b = 0, e; b < a.length; b++) { - (e = a[b]) && (c += e.length); - } - } else { - for (const b of a.entries()) { - const e = b[0], d = lb(b[1]); - d ? c += d : a.delete(e); - } - } - return c; -} -t.cleanup = function() { +v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - lb(this.map); - this.depth && lb(this.ctx); + cb(this.map); + this.depth && cb(this.ctx); return this; }; -t.searchCache = Va; -t.export = function(a, c, b = 0, e = 0) { +v.searchCache = Va; +v.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -2177,7 +2165,7 @@ t.export = function(a, c, b = 0, e = 0) { } return ya.call(this, a, c, d, f, b, e); }; -t.import = function(a, c) { +v.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": @@ -2192,7 +2180,7 @@ t.import = function(a, c) { } } }; -t.serialize = function(a = !0) { +v.serialize = function(a = !0) { let c = "", b = "", e = ""; if (this.reg.size) { let f; @@ -2214,10 +2202,10 @@ t.serialize = function(a = !0) { return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; la(N.prototype); -const mb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), nb = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); -function ob(a, c = {}) { +const lb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), mb = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); +function nb(a, c = {}) { if (!this) { - return new ob(a, c); + return new nb(a, c); } "object" === typeof a && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2228,15 +2216,15 @@ function ob(a, c = {}) { this.db = null; this.h = {}; } -t = ob.prototype; -t.mount = function(a) { +v = nb.prototype; +v.mount = function(a) { if (!a.encoder) { return a.mount(this); } a.db = this; return this.open(); }; -t.open = function() { +v.open = function() { if (this.db) { return this.db; } @@ -2244,11 +2232,11 @@ t.open = function() { navigator.storage && navigator.storage.persist(); Y[a.id] || (Y[a.id] = []); Y[a.id].push(a.field); - const c = mb.open(a.id, 1); + const c = lb.open(a.id, 1); c.onupgradeneeded = function() { const b = a.db = this.result; - for (let e = 0, d; e < nb.length; e++) { - d = nb[e]; + for (let e = 0, d; e < mb.length; e++) { + d = mb[e]; for (let f = 0, g; f < Y[a.id].length; f++) { g = Y[a.id][f], b.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || b.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } @@ -2261,18 +2249,18 @@ t.open = function() { }; }); }; -t.close = function() { +v.close = function() { this.db && this.db.close(); this.db = null; }; -t.destroy = function() { - const a = mb.deleteDatabase(this.id); +v.destroy = function() { + const a = lb.deleteDatabase(this.id); return Z(a); }; -t.clear = function() { +v.clear = function() { const a = []; - for (let b = 0, e; b < nb.length; b++) { - e = nb[b]; + for (let b = 0, e; b < mb.length; b++) { + e = mb[b]; for (let d = 0, f; d < Y[this.id].length; d++) { f = Y[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } @@ -2283,7 +2271,7 @@ t.clear = function() { } return Z(c); }; -t.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { +v.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); const g = this; return Z(a).then(function(k) { @@ -2316,7 +2304,7 @@ t.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { return k; }); }; -t.tag = function(a, c = 0, b = 0, e = !1) { +v.tag = function(a, c = 0, b = 0, e = !1) { a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); const d = this; return Z(a).then(function(f) { @@ -2330,7 +2318,7 @@ t.tag = function(a, c = 0, b = 0, e = !1) { return e ? d.enrich(f) : f; }); }; -t.enrich = function(a) { +v.enrich = function(a) { "object" !== typeof a && (a = [a]); const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = []; for (let e = 0; e < a.length; e++) { @@ -2343,16 +2331,16 @@ t.enrich = function(a) { return e; }); }; -t.has = function(a) { +v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); return Z(a).then(function(c) { return !!c; }); }; -t.search = null; -t.info = function() { +v.search = null; +v.info = function() { }; -t.transaction = function(a, c, b) { +v.transaction = function(a, c, b) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; let e = this.h[a + ":" + c]; if (e) { @@ -2367,7 +2355,7 @@ t.transaction = function(a, c, b) { return f; }); }; -t.commit = async function(a, c, b) { +v.commit = async function(a, c, b) { if (c) { await this.clear(), a.commit_task = []; } else { @@ -2459,7 +2447,7 @@ t.commit = async function(a, c, b) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function pb(a, c, b) { +function ob(a, c, b) { const e = a.value; let d, f = 0; for (let g = 0, k; g < e.length; g++) { @@ -2483,22 +2471,22 @@ function pb(a, c, b) { f ? d && a.update(e) : a.delete(); a.continue(); } -t.remove = function(a) { +v.remove = function(a) { "object" !== typeof a && (a = [a]); return Promise.all([this.transaction("map", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && pb(b, a); + b && ob(b, a); }; }), this.transaction("ctx", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && pb(b, a); + b && ob(b, a); }; }), this.transaction("tag", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && pb(b, a, !0); + b && ob(b, a, !0); }; }), this.transaction("reg", "readwrite", function(c) { for (let b = 0; b < a.length; b++) { @@ -2517,9 +2505,9 @@ function Z(a, c) { a = null; }); } -;const qb = {Index:N, Charset:bb, Encoder:ja, Document:U, Worker:P, Resolver:W, IndexedDB:ob, Language:{}}, rb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; -let tb; -(tb = rb.define) && tb.amd ? tb([], function() { - return qb; -}) : "object" === typeof rb.exports ? rb.exports = qb : rb.FlexSearch = qb; +;const pb = {Index:N, Charset:bb, Encoder:ja, Document:U, Worker:P, Resolver:W, IndexedDB:nb, Language:{}}, qb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let sb; +(sb = qb.define) && sb.amd ? sb([], function() { + return pb; +}) : "object" === typeof qb.exports ? qb.exports = pb : qb.FlexSearch = pb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index 2eed83a..51df6b6 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,95 +1,94 @@ /**! - * FlexSearch.js v0.8.147 (Bundle) + * FlexSearch.js v0.8.149 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var t;function z(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(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 B(){return Object.create(null)}function E(a){return"string"===typeof a} -function I(a){return"object"===typeof a}function aa(a){const c=[];for(const b of a.keys())c.push(b);return c}function J(a,c){if(E(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=z((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=b=z(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof b?b:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= -(this.A?"|":"")+d;return this};t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&K(this);return this};t.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; -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.h+=(this.h?"|":"")+a;this.M=null;this.cache&&K(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&&K(this);return this}; -t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(K,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)),d!==g&&this.filter&& +(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var u;function z(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function B(){return Object.create(null)}function F(a){return"string"===typeof a} +function H(a){return"object"===typeof a}function aa(a){const b=[];for(const c of a.keys())b.push(c);return b}function I(a,b){if(F(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; +this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:z(c&&new Set(c),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=z((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=z((c=a.stemmer)&&new Map(c), +null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=c=z(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&J(this);return this};u.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&J(this);return this}; +u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&J(this);return this}; +u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&J(this);return this}; +u.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(J,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ha?a.normalize("NFKD").replace(ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==g&&this.filter&& g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.S&&(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.B.set(a,b),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return b};function K(a){a.H=null;a.B.clear();a.G.clear()};let M,ja;async function ka(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ja=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ja),delete self.FlexSearch):M=new N(ja);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ja.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ja.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} -function ma(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,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 O=0; -function P(a={}){function c(g){function h(k){k=k.data||k;const l=k.id,n=l&&d.h[l];n&&(n(k.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++O]=function(){k(d);1E9=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const h=c.length;if(h&&(d=d.length?d.concat(c):c,b-=h,e&&(a.length-=h),!b))break;c=0}return d} -function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gb||e?k.slice(e,b+e):k;else{if(ab||e)k=k.slice(e,b+e)}else{d=[];for(let m= -0,q;me)e-=q.length;else{if(q.length>b||e)q=q.slice(e,b+e),b-=q.length,e&&(e-=q.length);d.push(q);if(!b)break}k=1c?c?a.slice(b,b+c):a.slice(b):a,e?V.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?V.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,b,e,!1,this.h),e=0));return f?this.resolve(b,e,d):this};W.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,n,m)}return d?this.resolve(c,b,e):this}; -function La(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,n;la.length)this.result=a[0];else{if(c=ba(a))return this.result=Fa(a,c,b,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,c,b,e,d,f,g)}; -function Ma(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,n;la.length)this.result=a[0];else return this.result=Na.call(this,a,b,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Na(a,c,b,e,d){const f=[],g=B();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -X.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:!1,numeric:!1};const Xa={};const Ya=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Za=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),$a=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ab={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var bb={X:Wa,W:Xa,Y:Xa,LatinBalance:{dedupe:!0,mapper:Ya},LatinAdvanced:{dedupe:!0,mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{dedupe:!0,mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(c,r,p,g,v):db(q,e,p,d,v); -eb(this,n,g,h,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1), -e,p,h-1,k-1),v=this.bidirectional&&r>f;eb(this,l,v?f:r,u,a,b,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.T&&fb(this));return this}; -function eb(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])if(g?(c=k||(c[b]=B()),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=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){c=new R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=c);k[e]=h=c}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function db(a,c,b,e,d){return b&&1b)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};N.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else kb(this.map,a),this.depth&&kb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&fb(this));this.cache&&this.cache.remove(a);return this}; -function kb(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; -function lb(a){let c=0;if(a.constructor===Array)for(let b=0,e;b=n.length){e-=n.length;continue}const m=b?e+Math.min(n.length-e,b):n.length;for(let q=e;q=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; -t.enrich=function(a){"object"!==typeof a&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};const qb={Index:N,Charset:bb,Encoder:ia,Document:U,Worker:P,Resolver:W,IndexedDB:ob,Language:{}},sb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let tb;(tb=sb.define)&&tb.amd?tb([],function(){return qb}):"object"===typeof sb.exports?sb.exports=qb:sb.FlexSearch=qb;}(this||self)); +this.replacer[d+1]);this.cache&&h.length<=this.L&&(this.G.set(h,g),this.G.size>this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function J(a){a.H=null;a.B.clear();a.G.clear()};let L,ja;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":ja=a.options||{};(b=a.factory)?(Function("return "+b)()(self),L=new self.FlexSearch.Index(ja),delete self.FlexSearch):L=new M(ja);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=ja.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await ja.import.call(L,e[0]),L.import(e[0],a)):(d=e&&L[b].apply(L,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} +function ma(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let N=0; +function P(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,n=l&&d.h[l];n&&(n(k.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++N]=function(){k(d);1E9=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const h=b.length;if(h&&(d=d.length?d.concat(b):b,c-=h,e&&(a.length-=h),!c))break;b=0}return d} +function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gc||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+e)}else{d= +[];for(let m=0,q;me)e-=q.length;else{if(q.length>c||e)q=q.slice(e,c+e),c-=q.length,e&&(e-=q.length);d.push(q);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,e?V.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?V.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};W.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,n,m)}return d?this.resolve(b,c,e):this}; +function La(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(b=ba(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};W.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; +function Ma(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Na(a,b,c,e,d){const f=[],g=B();let h=0;for(let k=0,l;kc||e)a=a.slice(e,e+c);d&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +X.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};X.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:!1,numeric:!1};const Xa={};const Ya=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Za=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),$a=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ab={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var bb={X:Wa,W:Xa,Y:Xa,LatinBalance:{dedupe:!0,mapper:Ya},LatinAdvanced:{dedupe:!0,mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{dedupe:!0,mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cd.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else cb(this.map,a),this.depth&&cb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&db(this));this.cache&&this.cache.remove(a);return this}; +function cb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;dt;f--){g=r.substring(t,f);v=this.rtl?d-1-t:t;var h=this.score?this.score(b,r,p,g,v):fb(q,e,p,d,v); +gb(this,n,g,h,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1), +e,p,h-1,k-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,t,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&db(this));return this}; +function gb(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[e]=h=b}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} +function fb(a,b,c,e,d){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,e,d,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function M(a,b){if(!this||this.constructor!==M)return new M(a);if(a){var c=F(a)?a:a.preset;c&&(a=Object.assign({},eb[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=F(a.encoder)?bb[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ia(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new S(c):new Map;this.ctx=c?new S(c):new Map;this.reg=b||(this.fastupdate?c?new S(c):new Map:c?new T(c):new Set);this.U=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new X(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.T=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}u=M.prototype; +u.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};u.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};u.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function db(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} +u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};u.update=function(a,b){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; +u.cleanup=function(){if(!this.fastupdate)return this;cb(this.map);this.depth&&cb(this.ctx);return this};u.searchCache=Va;u.export=function(a,b,c=0,e=0){let d,f;switch(e){case 0:d="reg";f=wa(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=sa(this.map,this.reg.size);break;case 3:d="ctx";f=ua(this.ctx,this.reg.size);break;default:return}return ya.call(this,a,b,d,f,c,e)}; +u.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=n.length){e-=n.length;continue}const m=c?e+Math.min(n.length-e,c):n.length;for(let q=e;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};const pb={Index:M,Charset:bb,Encoder:ia,Document:U,Worker:P,Resolver:W,IndexedDB:nb,Language:{}},rb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let sb;(sb=rb.define)&&sb.amd?sb([],function(){return pb}):"object"===typeof rb.exports?rb.exports=pb:rb.FlexSearch=pb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index d542f4c..66ddbbb 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.147 (Bundle/Module/Debug) + * FlexSearch.js v0.8.149 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var t; +var v; function z(a, c, b) { const e = typeof b, d = typeof a; if ("undefined" !== e) { @@ -46,10 +46,10 @@ function z(a, c, b) { function B() { return Object.create(null); } -function E(a) { +function F(a) { return "string" === typeof a; } -function I(a) { +function H(a) { return "object" === typeof a; } function aa(a) { @@ -60,7 +60,7 @@ function aa(a) { return c; } function ba(a, c) { - if (E(c)) { + if (F(c)) { a = a[c]; } else { for (let b = 0; a && b < c.length; b++) { @@ -89,8 +89,8 @@ function ja(a = {}) { this.assign(a); } } -t = ja.prototype; -t.assign = function(a) { +v = ja.prototype; +v.assign = function(a) { this.normalize = z(a.normalize, !0, this.normalize); let c = a.include, b = c || a.exclude || a.split, e; if (b || "" === b) { @@ -154,20 +154,20 @@ t.assign = function(a) { } return this; }; -t.addStemmer = function(a, c) { +v.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && J(this); + this.cache && I(this); return this; }; -t.addFilter = function(a) { +v.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && J(this); + this.cache && I(this); return this; }; -t.addMapper = function(a, c) { +v.addMapper = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -176,10 +176,10 @@ t.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && J(this); + this.cache && I(this); return this; }; -t.addMatcher = function(a, c) { +v.addMatcher = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -190,26 +190,26 @@ t.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && J(this); + this.cache && I(this); return this; }; -t.addReplacer = function(a, c) { +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 && J(this); + this.cache && I(this); return this; }; -t.encode = function(a) { +v.encode = function(a) { if (this.cache && a.length <= this.K) { if (this.H) { if (this.B.has(a)) { return this.B.get(a); } } else { - this.H = setTimeout(J, 50, this); + this.H = setTimeout(I, 50, this); } } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ia ? a.normalize("NFKD").replace(ia, "").toLowerCase() : a.toLowerCase()); @@ -231,7 +231,7 @@ t.encode = function(a) { continue; } } else { - this.H = setTimeout(J, 50, this); + this.H = setTimeout(I, 50, this); } } this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), d = g, g = g.replace(this.N, h => this.stemmer.get(h)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); @@ -258,12 +258,12 @@ t.encode = function(a) { this.cache && a.length <= this.K && (this.B.set(a, b), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); return b; }; -function J(a) { +function I(a) { a.H = null; a.B.clear(); a.G.clear(); } -;let K, M; +;let J, M; async function ka(a) { a = a.data; var c = a.task; @@ -272,7 +272,7 @@ async function ka(a) { switch(c) { case "init": M = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), K = new self.FlexSearch.Index(M), delete self.FlexSearch) : K = new N(M); + (c = a.factory) ? (Function("return " + c)()(self), J = new self.FlexSearch.Index(M), delete self.FlexSearch) : J = new N(M); postMessage({id:b}); break; default: @@ -287,9 +287,9 @@ async function ka(a) { if (!M.import || "function" !== typeof M.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - e[0] && (a = await M.import.call(K, e[0]), K.import(e[0], a)); + e[0] && (a = await M.import.call(J, e[0]), J.import(e[0], a)); } else { - (d = e && K[c].apply(K, e)) && d.then && (d = await d); + (d = e && J[c].apply(J, e)) && d.then && (d = await d); } postMessage("search" === c ? {id:b, msg:d} : {id:b}); } @@ -597,35 +597,35 @@ T.prototype.add = function(a) { let b = this.index[c]; b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.h.push(b), this.size++); }; -t = S.prototype; -t.has = T.prototype.has = function(a) { +v = S.prototype; +v.has = T.prototype.has = function(a) { const c = this.index[this.B(a)]; return c && c.has(a); }; -t.delete = T.prototype.delete = function(a) { +v.delete = T.prototype.delete = function(a) { const c = this.index[this.B(a)]; c && c.delete(a) && this.size--; }; -t.clear = T.prototype.clear = function() { +v.clear = T.prototype.clear = function() { this.index = B(); this.h = []; this.size = 0; }; -t.values = T.prototype.values = function*() { +v.values = T.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].values()) { yield c; } } }; -t.keys = T.prototype.keys = function*() { +v.keys = T.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].keys()) { yield c; } } }; -t.entries = T.prototype.entries = function*() { +v.entries = T.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].entries()) { yield c; @@ -660,7 +660,7 @@ function Ba(a) { return b; } ;U.prototype.add = function(a, c, b) { - I(a) && (c = a, a = ba(c, this.key)); + H(a) && (c = a, a = ba(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -673,7 +673,7 @@ function Ba(a) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Da(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : F(h) && (h = [h]), Da(c, h, this.J, 0, e, a, h[0], b); } } } @@ -695,7 +695,7 @@ function Ba(a) { f = ba(c, f); } if (d && f) { - E(f) && (f = [f]); + F(f) && (f = [f]); for (let h = 0, l, n; h < f.length; h++) { if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? n = g : d.set(l, n = []), !b || !n.includes(a))) { if (n.length === 2 ** 31 - 1) { @@ -732,7 +732,7 @@ function Ba(a) { continue; } l = [l.V]; - } else if (E(l) || l.constructor === String) { + } else if (F(l) || l.constructor === String) { k[l] = c[l]; continue; } @@ -790,19 +790,19 @@ function Da(a, c, b, e, d, f, g, k) { let h = [], l, n; l = B(); for (let m = 0, q, p, r, u; m < c; m++) { - for (let v = 0; v < k; v++) { - if (r = a[v], m < r.length && (q = r[m])) { + for (let t = 0; t < k; t++) { + if (r = a[t], m < r.length && (q = r[m])) { for (let w = 0; w < q.length; w++) { p = q[w]; (n = l[p]) ? l[p]++ : (n = 0, l[p] = 1); u = h[n] || (h[n] = []); if (!g) { - let y = m + (v || !d ? 0 : f || 0); + let y = m + (t || !d ? 0 : f || 0); u = u[y] || (u[y] = []); } u.push(p); if (g && b && n === k - 1 && u.length - e === b) { - return u; + return e ? u.slice(e) : u; } } } @@ -1213,7 +1213,7 @@ W.prototype.resolve = function(a, c, b) { }; B(); U.prototype.search = function(a, c, b, e) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let d = []; var f = [], g; let k; @@ -1232,7 +1232,7 @@ U.prototype.search = function(a, c, b, e) { m = !1 !== b.resolve; if (!m && !p) { if (h = h || this.field) { - E(h) ? p = h : (h.constructor === Array && 1 === h.length && (h = h[0]), p = h.field || h.index); + F(h) ? p = h : (h.constructor === Array && 1 === h.length && (h = h[0]), p = h.field || h.index); } if (!p) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); @@ -1245,53 +1245,53 @@ U.prototype.search = function(a, c, b, e) { c || (c = 100); if (l && (!this.db || !e)) { l.constructor !== Array && (l = [l]); - var v = []; + var t = []; for (let A = 0, x; A < l.length; A++) { x = l[A]; - if (E(x)) { + if (F(x)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (x.field && x.tag) { var w = x.tag; if (w.constructor === Array) { for (var y = 0; y < w.length; y++) { - v.push(x.field, w[y]); + t.push(x.field, w[y]); } } else { - v.push(x.field, w); + t.push(x.field, w); } } else { w = Object.keys(x); - for (let D = 0, H, C; D < w.length; D++) { - if (H = w[D], C = x[H], C.constructor === Array) { - for (y = 0; y < C.length; y++) { - v.push(H, C[y]); + for (let C = 0, G, D; C < w.length; C++) { + if (G = w[C], D = x[G], D.constructor === Array) { + for (y = 0; y < D.length; y++) { + t.push(G, D[y]); } } else { - v.push(H, C); + t.push(G, D); } } } } - if (!v.length) { + if (!t.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = v; + l = t; if (!a) { m = []; - if (v.length) { - for (f = 0; f < v.length; f += 2) { + if (t.length) { + for (f = 0; f < t.length; f += 2) { if (this.db) { - p = this.index.get(v[f]); + p = this.index.get(t[f]); if (!p) { - console.warn("Tag '" + v[f] + ":" + v[f + 1] + "' will be skipped because there is no field '" + v[f] + "'."); + console.warn("Tag '" + t[f] + ":" + t[f + 1] + "' will be skipped because there is no field '" + t[f] + "'."); continue; } - m.push(p = p.db.tag(v[f + 1], c, u, g)); + m.push(p = p.db.tag(t[f + 1], c, u, g)); } else { - p = Qa.call(this, v[f], v[f + 1], c, u, g); + p = Qa.call(this, t[f], t[f + 1], c, u, g); } - d.push({field:v[f], tag:v[f + 1], result:p}); + d.push({field:t[f], tag:t[f + 1], result:p}); } } return m.length ? Promise.all(m).then(function(A) { @@ -1305,34 +1305,34 @@ U.prototype.search = function(a, c, b, e) { h && h.constructor !== Array && (h = [h]); } h || (h = this.field); - v = !e && (this.worker || this.db) && []; - let F; - for (let A = 0, x, D, H; A < h.length; A++) { - D = h[A]; + t = !e && (this.worker || this.db) && []; + let E; + for (let A = 0, x, C, G; A < h.length; A++) { + C = h[A]; if (this.db && this.tag && !this.D[A]) { continue; } - let C; - E(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, u = C.offset || u, r = C.suggest || r, g = this.store && (C.enrich || g)); + let D; + F(C) || (D = C, C = D.field, a = D.query || a, c = D.limit || c, u = D.offset || u, r = D.suggest || r, g = this.store && (D.enrich || g)); if (e) { x = e[A]; } else { - if (w = C || b, y = this.index.get(D), l && (this.db && (w.tag = l, F = y.db.support_tag_search, w.field = h), F || (w.enrich = !1)), v) { - v[A] = y.search(a, c, w); + if (w = D || b, y = this.index.get(C), l && (this.db && (w.tag = l, E = y.db.support_tag_search, w.field = h), E || (w.enrich = !1)), t) { + t[A] = y.search(a, c, w); w && g && (w.enrich = g); continue; } else { x = y.search(a, c, w), w && g && (w.enrich = g); } } - H = x && (m ? x.length : x.result.length); - if (l && H) { + G = x && (m ? x.length : x.result.length); + if (l && G) { w = []; y = 0; if (this.db && e) { - if (!F) { - for (let G = h.length; G < e.length; G++) { - let L = e[G]; + if (!E) { + for (let K = h.length; K < e.length; K++) { + let L = e[K]; if (L && L.length) { y++, w.push(L); } else if (!r) { @@ -1341,16 +1341,16 @@ U.prototype.search = function(a, c, b, e) { } } } else { - for (let G = 0, L, pb; G < l.length; G += 2) { - L = this.tag.get(l[G]); + for (let K = 0, L, ob; K < l.length; K += 2) { + L = this.tag.get(l[K]); if (!L) { - if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), r) { + if (console.warn("Tag '" + l[K] + ":" + l[K + 1] + "' will be skipped because there is no field '" + l[K] + "'."), r) { continue; } else { return m ? d : new W(d); } } - if (pb = (L = L && L.get(l[G + 1])) && L.length) { + if (ob = (L = L && L.get(l[K + 1])) && L.length) { y++, w.push(L); } else if (!r) { return m ? d : new W(d); @@ -1359,21 +1359,21 @@ U.prototype.search = function(a, c, b, e) { } if (y) { x = Ha(x, w, m); - H = x.length; - if (!H && !r) { + G = x.length; + if (!G && !r) { return m ? x : new W(x); } y--; } } - if (H) { - f[n] = D, d.push(x), n++; + if (G) { + f[n] = C, d.push(x), n++; } else if (1 === h.length) { return m ? d : new W(d); } } - if (v) { - if (this.db && l && l.length && !F) { + if (t) { + if (this.db && l && l.length && !E) { for (g = 0; g < l.length; g += 2) { f = this.index.get(l[g]); if (!f) { @@ -1383,11 +1383,11 @@ U.prototype.search = function(a, c, b, e) { return m ? d : new W(d); } } - v.push(f.db.tag(l[g + 1], c, u, !1)); + t.push(f.db.tag(l[g + 1], c, u, !1)); } } const A = this; - return Promise.all(v).then(function(x) { + return Promise.all(t).then(function(x) { return x.length ? A.search(a, c, b, x) : x; }); } @@ -1397,20 +1397,20 @@ U.prototype.search = function(a, c, b, e) { if (p && (!g || !this.store)) { return d[0]; } - v = []; + t = []; for (u = 0; u < f.length; u++) { r = d[u]; - g && r.length && "undefined" === typeof r[0].doc && (this.db ? v.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = V.call(this, r)); + g && r.length && "undefined" === typeof r[0].doc && (this.db ? t.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = V.call(this, r)); if (p) { return m ? r : new W(r); } d[u] = {field:f[u], result:r}; } - if (g && this.db && v.length) { + if (g && this.db && t.length) { const A = this; - return Promise.all(v).then(function(x) { - for (let D = 0; D < x.length; D++) { - d[D].result = x[D]; + return Promise.all(t).then(function(x) { + for (let C = 0; C < x.length; C++) { + d[C].result = x[C]; } return k ? Ra(d, c) : q ? Sa(d, a, A.index, A.field, A.D, q) : d; }); @@ -1419,45 +1419,41 @@ U.prototype.search = function(a, c, b, e) { }; function Sa(a, c, b, e, d, f) { let g, k, h; - for (let n = 0, m, q, p, r; n < a.length; n++) { - let u = a[n].result; - m = a[n].field; - p = b.get(m); - q = p.encoder; - h = p.tokenize; - r = d[e.indexOf(m)]; - q !== g && (g = q, k = g.encode(c)); - for (let v = 0; v < u.length; v++) { - let w = ""; - var l = ba(u[v].doc, r); - let y = g.encode(l); - l = l.split(g.split); - for (let F = 0, A, x; F < y.length; F++) { - A = y[F]; - x = l[F]; - if (!A || !x) { - continue; - } - let D; - for (let H = 0, C; H < k.length; H++) { - if (C = k[H], "strict" === h) { - if (A === C) { - w += (w ? " " : "") + f.replace("$1", x); - D = !0; - break; - } - } else { - const G = A.indexOf(C); - if (-1 < G) { - w += (w ? " " : "") + x.substring(0, G) + f.replace("$1", x.substring(G, C.length)) + x.substring(G + C.length); - D = !0; - break; + for (let l = 0, n, m, q, p; l < a.length; l++) { + let r = a[l].result; + n = a[l].field; + q = b.get(n); + m = q.encoder; + h = q.tokenize; + p = d[e.indexOf(n)]; + m !== g && (g = m, k = g.encode(c)); + for (let u = 0; u < r.length; u++) { + let t = "", w = ba(r[u].doc, p).split(/\s+/); + for (let y = 0, E, A; y < w.length; y++) { + E = w[y]; + A = g.encode(E).join(" "); + let x; + if (A && E) { + for (let C = 0, G; C < k.length; C++) { + if (G = k[C], "strict" === h) { + if (A === G) { + t += (t ? " " : "") + f.replace("$1", E); + x = !0; + break; + } + } else { + const D = A.indexOf(G); + if (-1 < D) { + t += (t ? " " : "") + E.substring(0, D) + f.replace("$1", E.substring(D, G.length)) + E.substring(D + G.length); + x = !0; + break; + } } } } - D || (w += (w ? " " : "") + l[F]); + x || (t += (t ? " " : "") + w[y]); } - u[v].highlight = w; + r[u].highlight = t; } } return a; @@ -1563,8 +1559,8 @@ function V(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -t = U.prototype; -t.mount = function(a) { +v = U.prototype; +v.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } @@ -1593,7 +1589,7 @@ t.mount = function(a) { this.db = !0; return Promise.all(b); }; -t.commit = async function(a, c) { +v.commit = async function(a, c) { const b = []; for (const e of this.index.values()) { b.push(e.commit(a, c)); @@ -1601,7 +1597,7 @@ t.commit = async function(a, c) { await Promise.all(b); this.reg.clear(); }; -t.destroy = function() { +v.destroy = function() { const a = []; for (const c of this.index.values()) { a.push(c.destroy()); @@ -1611,11 +1607,11 @@ t.destroy = function() { function Ua(a, c) { const b = new Map(); let e = c.index || c.field || c; - E(e) && (e = [e]); + F(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { f = e[d]; - E(f) || (g = f, f = f.field); - g = I(g) ? Object.assign({}, a, g) : a; + F(f) || (g = f, f = f.field); + g = H(g) ? Object.assign({}, a, g) : a; if (this.worker) { const k = new P(g); b.set(f, k); @@ -1626,7 +1622,7 @@ function Ua(a, c) { } if (this.C) { a = c.store; - E(a) && (a = [a]); + F(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ta(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); } @@ -1642,14 +1638,14 @@ function Ta(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -t.append = function(a, c) { +v.append = function(a, c) { return this.add(a, c, !0); }; -t.update = function(a, c) { +v.update = function(a, c) { return this.remove(a).add(a, c); }; -t.remove = function(a) { - I(a) && (a = ba(a, this.key)); +v.remove = function(a) { + H(a) && (a = ba(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1669,7 +1665,7 @@ t.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -t.clear = function() { +v.clear = function() { const a = []; for (const c of this.index.values()) { const b = c.clear(); @@ -1684,27 +1680,27 @@ t.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -t.contain = function(a) { +v.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -t.cleanup = function() { +v.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -t.get = function(a) { +v.get = function(a) { return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) { return c[0] && c[0].doc || null; }) : this.store.get(a) || null; }; -t.set = function(a, c) { +v.set = function(a, c) { "object" === typeof a && (c = a, a = ba(c, this.key)); this.store.set(a, c); return this; }; -t.searchCache = Va; -t.export = function(a, c, b = 0, e = 0) { +v.searchCache = Va; +v.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { @@ -1737,7 +1733,7 @@ t.export = function(a, c, b = 0, e = 0) { } return ya.call(this, a, c, d, f, b, e); }; -t.import = function(a, c) { +v.import = function(a, c) { var b = a.split("."); "json" === b[b.length - 1] && b.pop(); const e = 2 < b.length ? b[0] : ""; @@ -1829,7 +1825,57 @@ var bb = {X:Wa, W:Xa, Y:Xa, LatinBalance:{dedupe:!0, mapper:Ya}, LatinAdvanced:{ a[b] = e; } }}, LatinExact:Wa, LatinDefault:Xa, LatinSimple:Xa}; -const cb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +N.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { + if (this.fastupdate) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { + if (2 > d.length) { + d.pop(); + } else { + const f = d.indexOf(a); + f === b.length - 1 ? d.pop() : d.splice(f, 1); + } + } + } + } else { + cb(this.map, a), this.depth && cb(this.ctx, a); + } + c || this.reg.delete(a); + } + this.db && (this.commit_task.push({del:a}), this.T && db(this)); + this.cache && this.cache.remove(a); + return this; +}; +function cb(a, c) { + let b = 0; + var e = "undefined" === typeof c; + if (a.constructor === Array) { + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && f.length) { + if (e) { + b++; + } else { + if (g = f.indexOf(c), 0 <= g) { + 1 < f.length ? (f.splice(g, 1), b++) : delete a[d]; + break; + } else { + b++; + } + } + } + } + } else { + for (let d of a.entries()) { + e = d[0]; + const f = cb(d[1], c); + f ? b += f : a.delete(e); + } + } + return b; +} +;const eb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; N.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1842,16 +1888,16 @@ N.prototype.add = function(a, c, b, e) { let r = c[this.rtl ? e - 1 - p : p]; var d = r.length; if (d && (m || !n[r])) { - var f = this.score ? this.score(c, r, p, null, 0) : db(q, e, p), g = ""; + var f = this.score ? this.score(c, r, p, null, 0) : fb(q, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let u = 0, v; u < d; u++) { + for (let u = 0, t; u < d; u++) { for (f = d; f > u; f--) { g = r.substring(u, f); - v = this.rtl ? d - 1 - u : u; - var k = this.score ? this.score(c, r, p, g, v) : db(q, e, p, d, v); - eb(this, n, g, k, a, b); + t = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(c, r, p, g, t) : fb(q, e, p, d, t); + gb(this, n, g, k, a, b); } } break; @@ -1861,25 +1907,25 @@ N.prototype.add = function(a, c, b, e) { if (1 < d) { for (k = d - 1; 0 < k; k--) { g = r[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, r, p, g, k) : db(q, e, p, d, k); - eb(this, n, g, h, a, b); + var h = this.score ? this.score(c, r, p, g, k) : fb(q, e, p, d, k); + gb(this, n, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[this.rtl ? d - 1 - k : k], eb(this, n, g, f, a, b); + g += r[this.rtl ? d - 1 - k : k], gb(this, n, g, f, a, b); } break; } default: - if (eb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { + if (gb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { for (d = B(), g = this.U, f = r, k = Math.min(m + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { if ((r = c[this.rtl ? e - 1 - p - h : p + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(c, f, p, r, h - 1) : db(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; - eb(this, l, v ? f : r, u, a, b, v ? r : f); + const u = this.score ? this.score(c, f, p, r, h - 1) : fb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), t = this.bidirectional && r > f; + gb(this, l, t ? f : r, u, a, b, t ? r : f); } } } @@ -1891,10 +1937,10 @@ N.prototype.add = function(a, c, b, e) { c = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.T && fb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && db(this)); return this; }; -function eb(a, c, b, e, d, f, g) { +function gb(a, c, b, e, d, f, g) { let k = g ? a.ctx : a.map, h; if (!c[b] || g && !(h = c[b])[g]) { if (g ? (c = h || (c[b] = B()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { @@ -1912,62 +1958,62 @@ function eb(a, c, b, e, d, f, g) { } } } -function db(a, c, b, e, d) { +function fb(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;N.prototype.search = function(a, c, b) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let e = [], d, f, g, k = 0, h, l, n, m, q; b ? (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, q = (h = !1 !== b.resolve) && b.enrich, n = b.boost, m = b.resolution, l = this.db && b.tag) : h = this.resolve; let p = this.encoder.encode(a); d = p.length; c = c || (h ? 100 : 0); if (1 === d) { - return gb.call(this, p[0], "", c, k, h, q, l); + return hb.call(this, p[0], "", c, k, h, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return gb.call(this, p[1], p[0], c, k, h, q, l); + return hb.call(this, p[1], p[0], c, k, h, q, l); } - let r = B(), u = 0, v; - 1 < d && f && (v = p[0], u = 1); - m || 0 === m || (m = v ? this.U : this.resolution); + let r = B(), u = 0, t; + 1 < d && f && (t = p[0], u = 1); + m || 0 === m || (m = t ? this.U : this.resolution); if (this.db) { if (this.db.search && (a = this.db.search(this, p, c, k, g, h, q, l), !1 !== a)) { return a; } const w = this; return async function() { - for (let y, F; u < d; u++) { - if ((F = p[u]) && !r[F]) { - r[F] = 1; - y = await hb(w, F, v, 0, 0, !1, !1); - if (y = ib(y, e, g, m)) { + for (let y, E; u < d; u++) { + if ((E = p[u]) && !r[E]) { + r[E] = 1; + y = await ib(w, E, t, 0, 0, !1, !1); + if (y = jb(y, e, g, m)) { e = y; break; } - v && (g && y && e.length || (v = F)); + t && (g && y && e.length || (t = E)); } - g && v && u === d - 1 && !e.length && (m = w.resolution, v = "", u = -1, r = B()); + g && t && u === d - 1 && !e.length && (m = w.resolution, t = "", u = -1, r = B()); } - return jb(e, m, c, k, g, n, h); + return kb(e, m, c, k, g, n, h); }(); } for (let w, y; u < d; u++) { if ((y = p[u]) && !r[y]) { r[y] = 1; - w = hb(this, y, v, 0, 0, !1, !1); - if (w = ib(w, e, g, m)) { + w = ib(this, y, t, 0, 0, !1, !1); + if (w = jb(w, e, g, m)) { e = w; break; } - v && (g && w && e.length || (v = y)); + t && (g && w && e.length || (t = y)); } - g && v && u === d - 1 && !e.length && (m = this.resolution, v = "", u = -1, r = B()); + g && t && u === d - 1 && !e.length && (m = this.resolution, t = "", u = -1, r = B()); } - return jb(e, m, c, k, g, n, h); + return kb(e, m, c, k, g, n, h); }; -function jb(a, c, b, e, d, f, g) { +function kb(a, c, b, e, d, f, g) { let k = a.length, h = a; if (1 < k) { h = Fa(a, c, b, e, d, f, g); @@ -1976,13 +2022,13 @@ function jb(a, c, b, e, d, f, g) { } return g ? h : new W(h); } -function gb(a, c, b, e, d, f, g) { - a = hb(this, a, c, b, e, d, f, g); +function hb(a, c, b, e, d, f, g) { + a = ib(this, a, c, b, e, d, f, g); return this.db ? a.then(function(k) { return d ? k || [] : new W(k); }) : a && a.length ? d ? Ia.call(this, a, b, e) : new W(a) : d ? [] : new W(); } -function ib(a, c, b, e) { +function jb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -2003,7 +2049,7 @@ function ib(a, c, b, e) { return d; } } -function hb(a, c, b, e, d, f, g, k) { +function ib(a, c, b, e, d, f, g, k) { let h; b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); if (a.db) { @@ -2012,62 +2058,18 @@ function hb(a, c, b, e, d, f, g, k) { a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;N.prototype.remove = function(a, c) { - const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (b) { - if (this.fastupdate) { - for (let e = 0, d; e < b.length; e++) { - if (d = b[e]) { - if (2 > d.length) { - d.pop(); - } else { - const f = d.indexOf(a); - f === b.length - 1 ? d.pop() : d.splice(f, 1); - } - } - } - } else { - kb(this.map, a), this.depth && kb(this.ctx, a); - } - c || this.reg.delete(a); - } - this.db && (this.commit_task.push({del:a}), this.T && fb(this)); - this.cache && this.cache.remove(a); - return this; -}; -function kb(a, c) { - let b = 0; - if (a.constructor === Array) { - for (let e = 0, d, f; e < a.length; e++) { - if ((d = a[e]) && d.length) { - if (f = d.indexOf(c), 0 <= f) { - 1 < d.length ? (d.splice(f, 1), b++) : delete a[e]; - break; - } else { - b++; - } - } - } - } else { - for (let e of a.entries()) { - const d = e[0], f = kb(e[1], c); - f ? b += f : a.delete(d); - } - } - return b; -} ;function N(a, c) { if (!this || this.constructor !== N) { return new N(a); } if (a) { - var b = E(a) ? a : a.preset; - b && (cb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, cb[b], a)); + var b = F(a) ? a : a.preset; + b && (eb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, eb[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || {}; + const e = !0 === b ? {depth:1} : b || {}, d = F(a.encoder) ? bb[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new ja(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; @@ -2092,26 +2094,26 @@ function kb(a, c) { this.commit_timer = null; this.priority = a.priority || 4; } -t = N.prototype; -t.mount = function(a) { +v = N.prototype; +v.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -t.commit = function(a, c) { +v.commit = function(a, c) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.commit(this, a, c); }; -t.destroy = function() { +v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function fb(a) { +function db(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 1)); } -t.clear = function() { +v.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -2119,40 +2121,26 @@ t.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -t.append = function(a, c) { +v.append = function(a, c) { return this.add(a, c, !0); }; -t.contain = function(a) { +v.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -t.update = function(a, c) { +v.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function lb(a) { - let c = 0; - if (a.constructor === Array) { - for (let b = 0, e; b < a.length; b++) { - (e = a[b]) && (c += e.length); - } - } else { - for (const b of a.entries()) { - const e = b[0], d = lb(b[1]); - d ? c += d : a.delete(e); - } - } - return c; -} -t.cleanup = function() { +v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - lb(this.map); - this.depth && lb(this.ctx); + cb(this.map); + this.depth && cb(this.ctx); return this; }; -t.searchCache = Va; -t.export = function(a, c, b = 0, e = 0) { +v.searchCache = Va; +v.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -2176,7 +2164,7 @@ t.export = function(a, c, b = 0, e = 0) { } return ya.call(this, a, c, d, f, b, e); }; -t.import = function(a, c) { +v.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": @@ -2191,7 +2179,7 @@ t.import = function(a, c) { } } }; -t.serialize = function(a = !0) { +v.serialize = function(a = !0) { let c = "", b = "", e = ""; if (this.reg.size) { let f; @@ -2213,10 +2201,10 @@ t.serialize = function(a = !0) { return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; la(N.prototype); -const mb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), nb = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); -function ob(a, c = {}) { +const lb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), mb = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); +function nb(a, c = {}) { if (!this) { - return new ob(a, c); + return new nb(a, c); } "object" === typeof a && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2227,15 +2215,15 @@ function ob(a, c = {}) { this.db = null; this.h = {}; } -t = ob.prototype; -t.mount = function(a) { +v = nb.prototype; +v.mount = function(a) { if (!a.encoder) { return a.mount(this); } a.db = this; return this.open(); }; -t.open = function() { +v.open = function() { if (this.db) { return this.db; } @@ -2243,11 +2231,11 @@ t.open = function() { navigator.storage && navigator.storage.persist(); Y[a.id] || (Y[a.id] = []); Y[a.id].push(a.field); - const c = mb.open(a.id, 1); + const c = lb.open(a.id, 1); c.onupgradeneeded = function() { const b = a.db = this.result; - for (let e = 0, d; e < nb.length; e++) { - d = nb[e]; + for (let e = 0, d; e < mb.length; e++) { + d = mb[e]; for (let f = 0, g; f < Y[a.id].length; f++) { g = Y[a.id][f], b.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || b.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } @@ -2260,18 +2248,18 @@ t.open = function() { }; }); }; -t.close = function() { +v.close = function() { this.db && this.db.close(); this.db = null; }; -t.destroy = function() { - const a = mb.deleteDatabase(this.id); +v.destroy = function() { + const a = lb.deleteDatabase(this.id); return Z(a); }; -t.clear = function() { +v.clear = function() { const a = []; - for (let b = 0, e; b < nb.length; b++) { - e = nb[b]; + for (let b = 0, e; b < mb.length; b++) { + e = mb[b]; for (let d = 0, f; d < Y[this.id].length; d++) { f = Y[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } @@ -2282,7 +2270,7 @@ t.clear = function() { } return Z(c); }; -t.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { +v.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); const g = this; return Z(a).then(function(k) { @@ -2315,7 +2303,7 @@ t.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { return k; }); }; -t.tag = function(a, c = 0, b = 0, e = !1) { +v.tag = function(a, c = 0, b = 0, e = !1) { a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); const d = this; return Z(a).then(function(f) { @@ -2329,7 +2317,7 @@ t.tag = function(a, c = 0, b = 0, e = !1) { return e ? d.enrich(f) : f; }); }; -t.enrich = function(a) { +v.enrich = function(a) { "object" !== typeof a && (a = [a]); const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = []; for (let e = 0; e < a.length; e++) { @@ -2342,16 +2330,16 @@ t.enrich = function(a) { return e; }); }; -t.has = function(a) { +v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); return Z(a).then(function(c) { return !!c; }); }; -t.search = null; -t.info = function() { +v.search = null; +v.info = function() { }; -t.transaction = function(a, c, b) { +v.transaction = function(a, c, b) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; let e = this.h[a + ":" + c]; if (e) { @@ -2366,7 +2354,7 @@ t.transaction = function(a, c, b) { return f; }); }; -t.commit = async function(a, c, b) { +v.commit = async function(a, c, b) { if (c) { await this.clear(), a.commit_task = []; } else { @@ -2458,7 +2446,7 @@ t.commit = async function(a, c, b) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function qb(a, c, b) { +function pb(a, c, b) { const e = a.value; let d, f = 0; for (let g = 0, k; g < e.length; g++) { @@ -2482,22 +2470,22 @@ function qb(a, c, b) { f ? d && a.update(e) : a.delete(); a.continue(); } -t.remove = function(a) { +v.remove = function(a) { "object" !== typeof a && (a = [a]); return Promise.all([this.transaction("map", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && qb(b, a); + b && pb(b, a); }; }), this.transaction("ctx", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && qb(b, a); + b && pb(b, a); }; }), this.transaction("tag", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && qb(b, a, !0); + b && pb(b, a, !0); }; }), this.transaction("reg", "readwrite", function(c) { for (let b = 0; b < a.length; b++) { @@ -2516,6 +2504,6 @@ function Z(a, c) { a = null; }); } -;export default {Index:N, Charset:bb, Encoder:ja, Document:U, Worker:P, Resolver:W, IndexedDB:ob, Language:{}}; +;export default {Index:N, Charset:bb, Encoder:ja, Document:U, Worker:P, Resolver:W, IndexedDB:nb, Language:{}}; -export const Index=N;export const Charset=bb;export const Encoder=ja;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=ob;export const Language={}; \ No newline at end of file +export const Index=N;export const Charset=bb;export const Encoder=ja;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=nb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 5367920..8d7ead9 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,96 +1,95 @@ /**! - * FlexSearch.js v0.8.147 (Bundle/Module) + * FlexSearch.js v0.8.149 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var t;function z(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(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 B(){return Object.create(null)}function E(a){return"string"===typeof a} -function I(a){return"object"===typeof a}function aa(a){const c=[];for(const b of a.keys())c.push(b);return c}function J(a,c){if(E(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=z((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=b=z(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof b?b:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= -(this.A?"|":"")+d;return this};t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&K(this);return this};t.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; -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.h+=(this.h?"|":"")+a;this.M=null;this.cache&&K(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&&K(this);return this}; -t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(K,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)),d!==g&&this.filter&& +var u;function z(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function B(){return Object.create(null)}function F(a){return"string"===typeof a} +function H(a){return"object"===typeof a}function aa(a){const b=[];for(const c of a.keys())b.push(c);return b}function I(a,b){if(F(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; +this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:z(c&&new Set(c),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=z((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=z((c=a.stemmer)&&new Map(c), +null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=c=z(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&J(this);return this};u.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&J(this);return this}; +u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&J(this);return this}; +u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&J(this);return this}; +u.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(J,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ha?a.normalize("NFKD").replace(ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==g&&this.filter&& g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.S&&(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.B.set(a,b),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return b};function K(a){a.H=null;a.B.clear();a.G.clear()};let M,ja;async function ka(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ja=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ja),delete self.FlexSearch):M=new N(ja);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ja.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ja.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} -function ma(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,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 O=0; -function P(a={}){function c(g){function h(k){k=k.data||k;const l=k.id,n=l&&d.h[l];n&&(n(k.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++O]=function(){k(d);1E9=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const h=c.length;if(h&&(d=d.length?d.concat(c):c,b-=h,e&&(a.length-=h),!b))break;c=0}return d} -function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gb||e?k.slice(e,b+e):k;else{if(ab||e)k=k.slice(e,b+e)}else{d=[];for(let m= -0,q;me)e-=q.length;else{if(q.length>b||e)q=q.slice(e,b+e),b-=q.length,e&&(e-=q.length);d.push(q);if(!b)break}k=1c?c?a.slice(b,b+c):a.slice(b):a,e?V.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?V.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,b,e,!1,this.h),e=0));return f?this.resolve(b,e,d):this};W.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,n,m)}return d?this.resolve(c,b,e):this}; -function La(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,n;la.length)this.result=a[0];else{if(c=ba(a))return this.result=Fa(a,c,b,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,c,b,e,d,f,g)}; -function Ma(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,n;la.length)this.result=a[0];else return this.result=Na.call(this,a,b,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Na(a,c,b,e,d){const f=[],g=B();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -X.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:!1,numeric:!1};const Xa={};const Ya=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Za=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),$a=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ab={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var bb={X:Wa,W:Xa,Y:Xa,LatinBalance:{dedupe:!0,mapper:Ya},LatinAdvanced:{dedupe:!0,mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{dedupe:!0,mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(c,r,p,g,v):db(q,e,p,d,v); -eb(this,n,g,h,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1), -e,p,h-1,k-1),v=this.bidirectional&&r>f;eb(this,l,v?f:r,u,a,b,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.T&&fb(this));return this}; -function eb(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])if(g?(c=k||(c[b]=B()),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=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){c=new R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=c);k[e]=h=c}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function db(a,c,b,e,d){return b&&1b)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};N.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else kb(this.map,a),this.depth&&kb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&fb(this));this.cache&&this.cache.remove(a);return this}; -function kb(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; -function lb(a){let c=0;if(a.constructor===Array)for(let b=0,e;b=n.length){e-=n.length;continue}const m=b?e+Math.min(n.length-e,b):n.length;for(let q=e;q=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; -t.enrich=function(a){"object"!==typeof a&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:N,Charset:bb,Encoder:ia,Document:U,Worker:P,Resolver:W,IndexedDB:pb,Language:{}}; -export const Index=N;export const Charset=bb;export const Encoder=ia;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=pb;export const Language={}; \ No newline at end of file +this.replacer[d+1]);this.cache&&h.length<=this.L&&(this.G.set(h,g),this.G.size>this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function J(a){a.H=null;a.B.clear();a.G.clear()};let L,ja;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":ja=a.options||{};(b=a.factory)?(Function("return "+b)()(self),L=new self.FlexSearch.Index(ja),delete self.FlexSearch):L=new M(ja);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=ja.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await ja.import.call(L,e[0]),L.import(e[0],a)):(d=e&&L[b].apply(L,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} +function ma(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let N=0; +function P(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,n=l&&d.h[l];n&&(n(k.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++N]=function(){k(d);1E9=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const h=b.length;if(h&&(d=d.length?d.concat(b):b,c-=h,e&&(a.length-=h),!c))break;b=0}return d} +function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gc||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+e)}else{d= +[];for(let m=0,q;me)e-=q.length;else{if(q.length>c||e)q=q.slice(e,c+e),c-=q.length,e&&(e-=q.length);d.push(q);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,e?V.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?V.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};W.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,n,m)}return d?this.resolve(b,c,e):this}; +function La(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(b=ba(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};W.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; +function Ma(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Na(a,b,c,e,d){const f=[],g=B();let h=0;for(let k=0,l;kc||e)a=a.slice(e,e+c);d&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +X.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};X.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:!1,numeric:!1};const Xa={};const Ya=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Za=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),$a=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ab={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var bb={X:Wa,W:Xa,Y:Xa,LatinBalance:{dedupe:!0,mapper:Ya},LatinAdvanced:{dedupe:!0,mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{dedupe:!0,mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cd.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else cb(this.map,a),this.depth&&cb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&db(this));this.cache&&this.cache.remove(a);return this}; +function cb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;dt;f--){g=r.substring(t,f);v=this.rtl?d-1-t:t;var h=this.score?this.score(b,r,p,g,v):fb(q,e,p,d,v); +gb(this,n,g,h,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1), +e,p,h-1,k-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,t,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&db(this));return this}; +function gb(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new R(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[e]=h=b}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} +function fb(a,b,c,e,d){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,e,d,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function M(a,b){if(!this||this.constructor!==M)return new M(a);if(a){var c=F(a)?a:a.preset;c&&(a=Object.assign({},eb[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=F(a.encoder)?bb[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ia(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new S(c):new Map;this.ctx=c?new S(c):new Map;this.reg=b||(this.fastupdate?c?new S(c):new Map:c?new T(c):new Set);this.U=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new X(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.T=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}u=M.prototype; +u.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};u.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};u.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function db(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} +u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};u.update=function(a,b){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; +u.cleanup=function(){if(!this.fastupdate)return this;cb(this.map);this.depth&&cb(this.ctx);return this};u.searchCache=Va;u.export=function(a,b,c=0,e=0){let d,f;switch(e){case 0:d="reg";f=wa(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=sa(this.map,this.reg.size);break;case 3:d="ctx";f=ua(this.ctx,this.reg.size);break;default:return}return ya.call(this,a,b,d,f,c,e)}; +u.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=n.length){e-=n.length;continue}const m=c?e+Math.min(n.length-e,c):n.length;for(let q=e;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:M,Charset:bb,Encoder:ia,Document:U,Worker:P,Resolver:W,IndexedDB:ob,Language:{}}; +export const Index=M;export const Charset=bb;export const Encoder=ia;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=ob;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 7efd114..679812e 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,12 +1,12 @@ /**! - * FlexSearch.js v0.8.147 (Bundle/Debug) + * FlexSearch.js v0.8.149 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ (function(self){'use strict'; -var x; +var w; function B(a, c, b) { const e = typeof b, d = typeof a; if ("undefined" !== e) { @@ -50,10 +50,10 @@ function C() { function D(a) { return "string" === typeof a; } -function I(a) { +function H(a) { return "object" === typeof a; } -function J(a, c) { +function I(a, c) { if (D(c)) { a = a[c]; } else { @@ -71,9 +71,9 @@ function aa(a) { return c; } ;const ba = /[^\p{L}\p{N}]+/u, ca = /(\d{3})/g, da = /(\D)(\d{3})/g, ea = /(\d{3})(\D)/g, fa = /[\u0300-\u036f]/g; -function K(a = {}) { - if (!this || this.constructor !== K) { - return new K(...arguments); +function J(a = {}) { + if (!this || this.constructor !== J) { + return new J(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -83,8 +83,8 @@ function K(a = {}) { this.assign(a); } } -x = K.prototype; -x.assign = function(a) { +w = J.prototype; +w.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) { @@ -148,20 +148,20 @@ x.assign = function(a) { } return this; }; -x.addStemmer = function(a, c) { +w.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); + this.cache && K(this); return this; }; -x.addFilter = function(a) { +w.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && L(this); + this.cache && K(this); return this; }; -x.addMapper = function(a, c) { +w.addMapper = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -170,10 +170,10 @@ x.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && L(this); + this.cache && K(this); return this; }; -x.addMatcher = function(a, c) { +w.addMatcher = function(a, c) { if ("object" === typeof a) { return this.addReplacer(a, c); } @@ -184,26 +184,26 @@ x.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && L(this); + this.cache && K(this); return this; }; -x.addReplacer = function(a, c) { +w.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); + this.cache && K(this); return this; }; -x.encode = function(a) { +w.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.H = setTimeout(K, 50, this); } } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = fa ? a.normalize("NFKD").replace(fa, "").toLowerCase() : a.toLowerCase()); @@ -225,7 +225,7 @@ x.encode = function(a) { continue; } } else { - this.H = setTimeout(L, 50, this); + this.H = setTimeout(K, 50, this); } } this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), d = g, g = g.replace(this.N, h => this.stemmer.get(h)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); @@ -252,12 +252,12 @@ x.encode = function(a) { 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) { +function K(a) { a.H = null; a.F.clear(); a.G.clear(); } -;let M, N; +;let L, M; async function ha(a) { a = a.data; var c = a.task; @@ -265,41 +265,41 @@ async function ha(a) { let e = a.args; switch(c) { case "init": - N = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + M = a.options || {}; + (c = a.factory) ? (Function("return " + c)()(self), L = new self.FlexSearch.Index(M), delete self.FlexSearch) : L = new N(M); postMessage({id:b}); break; default: let d; if ("export" === c) { - if (!N.export || "function" !== typeof N.export) { + if (!M.export || "function" !== typeof M.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - e[1] ? (e[0] = N.export, e[2] = 0, e[3] = 1) : e = null; + e[1] ? (e[0] = M.export, e[2] = 0, e[3] = 1) : e = null; } if ("import" === c) { - if (!N.import || "function" !== typeof N.import) { + if (!M.import || "function" !== typeof M.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - e[0] && (a = await N.import.call(M, e[0]), M.import(e[0], a)); + e[0] && (a = await M.import.call(L, e[0]), L.import(e[0], a)); } else { - (d = e && M[c].apply(M, e)) && d.then && (d = await d); + (d = e && L[c].apply(L, e)) && d.then && (d = await d); } postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } ;function ia(a) { - P.call(a, "add"); - P.call(a, "append"); - P.call(a, "search"); - P.call(a, "update"); - P.call(a, "remove"); + O.call(a, "add"); + O.call(a, "append"); + O.call(a, "search"); + O.call(a, "update"); + O.call(a, "remove"); } let ja, ka, Q; function la() { ja = Q = 0; } -function P(a) { +function O(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; @@ -430,7 +430,7 @@ function sa(a, c) { } return c; } -function U(a, c, b, e, d, f, g = 0) { +function ta(a, c, b, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { @@ -439,12 +439,12 @@ function U(a, c, b, e, d, f, g = 0) { if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return U.call(l, a, c, b, k ? e : null, d, f, g + 1); + return ta.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return U.call(this, a, c, b, k ? e : null, d, f, g + 1); + return ta.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function ta(a, c) { +function ua(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; @@ -464,8 +464,8 @@ function ta(a, c) { } return b; } -;V.prototype.add = function(a, c, b) { - I(a) && (c = a, a = J(c, this.key)); +;U.prototype.add = function(a, c, b) { + H(a) && (c = a, a = I(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -478,7 +478,7 @@ function ta(a, c) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), ua(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); } } } @@ -497,7 +497,7 @@ function ta(a, c) { continue; } f.constructor === String && (f = "" + f); - f = J(c, f); + f = I(c, f); } if (d && f) { D(f) && (f = [f]); @@ -529,7 +529,7 @@ function ta(a, c) { k[l] = c[l]; continue; } - va(c, k, l, 0, l[0], m); + wa(c, k, l, 0, l[0], m); } } this.store.set(a, k || c); @@ -537,21 +537,21 @@ function ta(a, c) { } return this; }; -function va(a, c, b, e, d, f) { +function wa(a, c, b, e, d, f) { a = a[d]; if (e === b.length - 1) { c[d] = f || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - va(a, c, b, e, d); + wa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], va(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], wa(a, c, b, e, d); } } } -function ua(a, c, b, e, d, f, g, k) { +function va(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -567,24 +567,24 @@ function ua(a, c, b, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - ua(a, c, b, e, d, f, g, k); + va(a, c, b, e, d, f, g, k); } } else { - g = c[++e], ua(a, c, b, e, d, f, g, k); + g = c[++e], va(a, c, b, e, d, f, g, k); } } } } -;function wa(a, c, b, e, d) { +;function xa(a, c, b, e, d) { const f = a.length; let g = [], k, h; k = C(); - for (let l = 0, m, n, r, p; l < c; l++) { + for (let l = 0, m, n, u, p; l < c; l++) { for (let q = 0; q < f; q++) { - if (r = a[q], l < r.length && (m = r[l])) { + if (u = a[q], l < u.length && (m = u[l])) { for (let t = 0; t < m.length; t++) { if (n = m[t], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n), b && h === f - 1 && p.length - e === b) { - return p; + return e ? p.slice(e) : p; } } } @@ -592,7 +592,7 @@ function ua(a, c, b, e, d, f, g, k) { } if (a = g.length) { if (d) { - g = 1 < g.length ? xa(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -607,7 +607,7 @@ function ua(a, c, b, e, d, f, g, k) { } return g; } -function xa(a, c, b) { +function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; @@ -629,7 +629,7 @@ function xa(a, c, b) { } return e; } -function ya(a, c) { +function za(a, c) { const b = C(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -642,12 +642,12 @@ function ya(a, c) { } return e; } -;function za(a, c, b, e) { +;function Aa(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? V.call(this, a) : a; } let d = []; for (let f = 0, g, k; f < a.length; f++) { @@ -661,7 +661,7 @@ function ya(a, c) { } k > c && (g = g.slice(0, c), k = c); if (!d.length && k >= c) { - return e ? W.call(this, g) : g; + return e ? V.call(this, g) : g; } d.push(g); c -= k; @@ -671,9 +671,9 @@ function ya(a, c) { } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? W.call(this, d) : d; + return e ? V.call(this, d) : d; } -;function Aa(a, c, b) { +;function Ba(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -687,30 +687,30 @@ function ya(a, c) { let d = [], f = 0, g = 0, k, h, l; for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { - let r; - if (n.constructor === X) { - r = n.result; + let u; + if (n.constructor === W) { + u = n.result; } else if (n.constructor === Array) { - r = n; + u = n; } else { if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, r = n.index.search(n).result, n.resolve = h, n.enrich = k; + n.resolve = !1, n.enrich = !1, u = n.index.search(n).result, n.resolve = h, n.enrich = k; } else if (n.and) { - r = a.and(n.and); + u = a.and(n.and); } else if (n.or) { - r = a.or(n.or); + u = a.or(n.or); } else if (n.xor) { - r = a.xor(n.xor); + u = a.xor(n.xor); } else if (n.not) { - r = a.not(n.not); + u = a.not(n.not); } else { continue; } } - if (r.then) { - d.push(r); - } else if (r.length) { - e[m] = r; + if (u.then) { + d.push(u); + } else if (u.length) { + e[m] = u; } else if (!l && ("and" === c || "xor" === c)) { e = []; break; @@ -719,11 +719,11 @@ function ya(a, c) { } 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} = Aa(this, "or", arguments); - return Ba.call(this, a, c, b, e, d, f); +;W.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); + return Ca.call(this, a, c, b, e, d, f); }; -function Ba(a, c, b, e, d, f) { +function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; return Promise.all(c).then(function(k) { @@ -731,53 +731,24 @@ function Ba(a, c, b, e, d, f) { for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return Ba.call(g, a, [], b, e, d, f); + return Ca.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = xa(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ya(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } -;X.prototype.and = function() { +;W.prototype.and = function() { let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Aa(this, "and", arguments); - return Ca.call(this, f, g, k, h, 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 Ca(a, c, b, e, d, f, g) { - if (c.length) { - const k = this; - return Promise.all(c).then(function(h) { - a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); - } - return Ca.call(k, a, [], b, e, d, f, g); - }); - } - if (a.length) { - if (this.result.length && a.unshift(this.result), 2 > a.length) { - this.result = a[0]; - } else { - if (c = aa(a)) { - return this.result = wa(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} = Aa(this, "xor", arguments); - return Da.call(this, a, c, b, e, d, f, g); -}; function Da(a, c, b, e, d, f, g) { if (c.length) { const k = this; @@ -793,14 +764,43 @@ function Da(a, c, b, e, d, f, g) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Ea.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + if (c = aa(a)) { + return this.result = xa(a, c, b, e, g), f ? d ? V.call(this.index, this.result) : this.result : this; + } + this.result = []; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Ea(a, c, b, e, d) { +;W.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); + return Ea.call(this, a, c, b, e, d, f, g); +}; +function Ea(a, c, b, e, d, f, g) { + if (c.length) { + const k = this; + return Promise.all(c).then(function(h) { + a = []; + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Ea.call(k, a, [], b, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = Fa.call(this, a, b, e, f, this.h), f ? d ? V.call(this.index, this.result) : this.result : this; + } + } 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; h < a.length; h++) { @@ -808,17 +808,17 @@ function Ea(a, c, b, e, d) { k < l.length && (k = l.length); for (let m = 0, n; m < l.length; m++) { if (n = l[m]) { - for (let r = 0, p; r < n.length; r++) { - p = n[r], g[p] = g[p] ? 2 : 1; + for (let u = 0, p; u < n.length; u++) { + p = n[u], g[p] = g[p] ? 2 : 1; } } } } } for (let h = 0, l, m = 0; h < k; h++) { - for (let n = 0, r; n < a.length; n++) { - if (r = a[n]) { - if (l = r[h]) { + for (let n = 0, u; n < a.length; n++) { + if (u = a[n]) { + if (l = u[h]) { for (let p = 0, q; p < l.length; p++) { if (q = l[p], 1 === g[q]) { if (b) { @@ -845,11 +845,11 @@ function Ea(a, c, b, e, d) { } return f; } -;X.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "not", arguments); - return Fa.call(this, a, c, b, e, d, f, g); +;W.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); + return Ga.call(this, a, c, b, e, d, f, g); }; -function Fa(a, c, b, e, d, f, g) { +function Ga(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -857,17 +857,17 @@ function Fa(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Fa.call(k, a, [], b, e, d, f, g); + return Ga.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ga.call(this, a, b, e, f); + this.result = Ha.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? W.call(this.index, this.result) : this.result : this; + return f ? d ? V.call(this.index, this.result) : this.result : this; } -function Ga(a, c, b, e) { +function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { @@ -893,9 +893,9 @@ function Ga(a, c, b, e) { } return d; } -;function X(a) { - if (!this || this.constructor !== X) { - return new X(a); +;function W(a) { + if (!this || this.constructor !== W) { + return new W(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -904,7 +904,7 @@ function Ga(a, c, b, e) { this.result = a || []; this.h = 0; } -X.prototype.limit = function(a) { +W.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -923,7 +923,7 @@ X.prototype.limit = function(a) { } return this; }; -X.prototype.offset = function(a) { +W.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -935,23 +935,23 @@ X.prototype.offset = function(a) { } return this; }; -X.prototype.boost = function(a) { +W.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, c, b) { +W.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), za.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; }; C(); -V.prototype.search = function(a, c, b, e) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); +U.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; let k, h, l; - let m = 0, n = !0, r; + let m = 0, n = !0, u; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; @@ -962,49 +962,49 @@ V.prototype.search = function(a, c, b, e) { k = b.suggest; n = !0; this.store && b.enrich && !n && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - r = (g = this.store && b.enrich && n) && b.highlight; + u = (g = this.store && b.enrich && n) && b.highlight; c = b.limit || c; var t = b.offset || 0; c || (c = 100); if (l) { l.constructor !== Array && (l = [l]); - var u = []; + var r = []; for (let y = 0, v; y < l.length; y++) { v = l[y]; if (D(v)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (v.field && v.tag) { - var w = v.tag; - if (w.constructor === Array) { - for (var z = 0; z < w.length; z++) { - u.push(v.field, w[z]); + var x = v.tag; + if (x.constructor === Array) { + for (var z = 0; z < x.length; z++) { + r.push(v.field, x[z]); } } else { - u.push(v.field, w); + r.push(v.field, x); } } else { - w = Object.keys(v); - for (let E = 0, F, A; E < w.length; E++) { - if (F = w[E], A = v[F], A.constructor === Array) { + x = Object.keys(v); + for (let E = 0, F, A; E < x.length; E++) { + if (F = x[E], A = v[F], A.constructor === Array) { for (z = 0; z < A.length; z++) { - u.push(F, A[z]); + r.push(F, A[z]); } } else { - u.push(F, A); + r.push(F, A); } } } } - if (!u.length) { + if (!r.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = u; + l = r; if (!a) { f = []; - if (u.length) { - for (p = 0; p < u.length; p += 2) { - q = Ha.call(this, u[p], u[p + 1], c, t, g), d.push({field:u[p], tag:u[p + 1], result:q}); + if (r.length) { + for (p = 0; p < r.length; p += 2) { + q = Ia.call(this, r[p], r[p + 1], c, t, g), d.push({field:r[p], tag:r[p + 1], result:q}); } } return f.length ? Promise.all(f).then(function(y) { @@ -1018,7 +1018,7 @@ V.prototype.search = function(a, c, b, e) { h && h.constructor !== Array && (h = [h]); } h || (h = this.field); - u = !e && (this.worker || this.db) && []; + r = !e && (this.worker || this.db) && []; for (let y = 0, v, E, F; y < h.length; y++) { E = h[y]; let A; @@ -1026,38 +1026,38 @@ V.prototype.search = function(a, c, b, e) { if (e) { v = e[y]; } else { - if (w = A || b, z = this.index.get(E), l && (w.enrich = !1), u) { - u[y] = z.search(a, c, w); - w && g && (w.enrich = g); + if (x = A || b, z = this.index.get(E), l && (x.enrich = !1), r) { + r[y] = z.search(a, c, x); + x && g && (x.enrich = g); continue; } else { - v = z.search(a, c, w), w && g && (w.enrich = g); + v = z.search(a, c, x), x && g && (x.enrich = g); } } F = v && (n ? v.length : v.result.length); if (l && F) { - w = []; + x = []; z = 0; - for (let G = 0, H, Za; G < l.length; G += 2) { - H = this.tag.get(l[G]); - if (!H) { + for (let G = 0, P, Ya; G < l.length; G += 2) { + P = this.tag.get(l[G]); + if (!P) { if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), k) { continue; } else { - return n ? d : new X(d); + return n ? d : new W(d); } } - if (Za = (H = H && H.get(l[G + 1])) && H.length) { - z++, w.push(H); + if (Ya = (P = P && P.get(l[G + 1])) && P.length) { + z++, x.push(P); } else if (!k) { - return n ? d : new X(d); + return n ? d : new W(d); } } if (z) { - v = ya(v, w); + v = za(v, x); F = v.length; if (!F && !k) { - return n ? v : new X(v); + return n ? v : new W(v); } z--; } @@ -1065,78 +1065,74 @@ V.prototype.search = function(a, c, b, e) { if (F) { f[m] = E, d.push(v), m++; } else if (1 === h.length) { - return n ? d : new X(d); + return n ? d : new W(d); } } - if (u) { + if (r) { const y = this; - return Promise.all(u).then(function(v) { + return Promise.all(r).then(function(v) { return v.length ? y.search(a, c, b, v) : v; }); } if (!m) { - return n ? d : new X(d); + return n ? d : new W(d); } if (p && (!g || !this.store)) { return d[0]; } - u = []; + r = []; for (t = 0; t < f.length; t++) { e = d[t]; - g && e.length && "undefined" === typeof e[0].doc && (e = W.call(this, e)); + g && e.length && "undefined" === typeof e[0].doc && (e = V.call(this, e)); if (p) { - return n ? e : new X(e); + return n ? e : new W(e); } d[t] = {field:f[t], result:e}; } - return q ? Ia(d, c) : r ? Ja(d, a, this.index, this.field, this.C, r) : d; + return q ? Ja(d, c) : u ? Ka(d, a, this.index, this.field, this.C, u) : d; }; -function Ja(a, c, b, e, d, f) { +function Ka(a, c, b, e, d, f) { let g, k, h; - for (let m = 0, n, r, p, q; m < a.length; m++) { - let t = a[m].result; - n = a[m].field; - p = b.get(n); - r = p.encoder; - h = p.tokenize; - q = d[e.indexOf(n)]; - r !== g && (g = r, k = g.encode(c)); - for (let u = 0; u < t.length; u++) { - let w = ""; - var l = J(t[u].doc, q); - let z = g.encode(l); - l = l.split(g.split); - for (let y = 0, v, E; y < z.length; y++) { - v = z[y]; - E = l[y]; - if (!v || !E) { - continue; - } - let F; - for (let A = 0, G; A < k.length; A++) { - if (G = k[A], "strict" === h) { - if (v === G) { - w += (w ? " " : "") + f.replace("$1", E); - F = !0; - break; - } - } else { - const H = v.indexOf(G); - if (-1 < H) { - w += (w ? " " : "") + E.substring(0, H) + f.replace("$1", E.substring(H, G.length)) + E.substring(H + G.length); - F = !0; - break; + for (let l = 0, m, n, u, p; l < a.length; l++) { + let q = a[l].result; + m = a[l].field; + u = b.get(m); + n = u.encoder; + h = u.tokenize; + p = d[e.indexOf(m)]; + n !== g && (g = n, k = g.encode(c)); + for (let t = 0; t < q.length; t++) { + let r = "", x = I(q[t].doc, p).split(/\s+/); + for (let z = 0, y, v; z < x.length; z++) { + y = x[z]; + v = g.encode(y).join(" "); + let E; + if (v && y) { + for (let F = 0, A; F < k.length; F++) { + if (A = k[F], "strict" === h) { + if (v === A) { + r += (r ? " " : "") + f.replace("$1", y); + E = !0; + break; + } + } else { + const G = v.indexOf(A); + if (-1 < G) { + r += (r ? " " : "") + y.substring(0, G) + f.replace("$1", y.substring(G, A.length)) + y.substring(G + A.length); + E = !0; + break; + } } } } - F || (w += (w ? " " : "") + l[y]); + E || (r += (r ? " " : "") + x[z]); } - t[u].highlight = w; + q[t].highlight = r; } } return a; } -function Ia(a, c) { +function Ja(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1155,7 +1151,7 @@ function Ia(a, c) { } return b; } -function Ha(a, c, b, e, d) { +function Ia(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1164,11 +1160,11 @@ function Ha(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = W.call(this, f)); + d && (f = V.call(this, f)); return f; } } -function W(a) { +function V(a) { if (!this || !this.store) { return a; } @@ -1178,33 +1174,33 @@ function W(a) { } return c; } -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); +;function U(a) { + if (!this || this.constructor !== U) { + return new U(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && Ka(b, this.J) || "id"; + this.key = (b = c.key || c.id) && La(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); - this.cache = (b = a.cache || null) && new Y(b); + this.cache = (b = a.cache || null) && new X(b); a.cache = !1; this.priority = a.priority || 4; b = new Map(); let e = c.index || c.field || c; D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Ka(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, b.set(f, new N(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = Ka(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1220,14 +1216,14 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Ka(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function Ka(a, c) { +function La(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1236,15 +1232,15 @@ function Ka(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -x = V.prototype; -x.append = function(a, c) { +w = U.prototype; +w.append = function(a, c) { return this.add(a, c, !0); }; -x.update = function(a, c) { +w.update = function(a, c) { return this.remove(a).add(a, c); }; -x.remove = function(a) { - I(a) && (a = J(a, this.key)); +w.remove = function(a) { + H(a) && (a = I(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1264,7 +1260,7 @@ x.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -x.clear = function() { +w.clear = function() { const a = []; for (const c of this.index.values()) { const b = c.clear(); @@ -1279,25 +1275,25 @@ x.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -x.contain = function(a) { +w.contain = function(a) { return this.reg.has(a); }; -x.cleanup = function() { +w.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -x.get = function(a) { +w.get = function(a) { return this.store.get(a) || null; }; -x.set = function(a, c) { - "object" === typeof a && (c = a, a = J(c, this.key)); +w.set = function(a, c) { + "object" === typeof a && (c = a, a = I(c, this.key)); this.store.set(a, c); return this; }; -x.searchCache = La; -x.export = function(a, c, b = 0, e = 0) { +w.searchCache = Ma; +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) { @@ -1328,9 +1324,9 @@ x.export = function(a, c, b = 0, e = 0) { default: return; } - return U.call(this, a, c, d, f, b, e); + return ta.call(this, a, c, d, f, b, e); }; -x.import = function(a, c) { +w.import = function(a, c) { var b = a.split("."); "json" === b[b.length - 1] && b.pop(); a = 2 < b.length ? b[0] : ""; @@ -1356,10 +1352,10 @@ x.import = function(a, c) { } } }; -ia(V.prototype); -function La(a, c, b) { +ia(U.prototype); +function Ma(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Y()); + this.cache || (this.cache = new X()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -1374,66 +1370,115 @@ function La(a, c, b) { } return e; } -function Y(a) { +function X(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -Y.prototype.set = function(a, c) { +X.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -Y.prototype.get = function(a) { +X.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -Y.prototype.remove = function(a) { +X.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() { +X.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ma = {normalize:!1, numeric:!1}; -const Na = {}; -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"], ["ph", "f"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\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}; -var Sa = {W:Ma, V:Na, X:Na, LatinBalance:{dedupe:!0, mapper:Oa}, LatinAdvanced:{dedupe:!0, mapper:Oa, matcher:Pa, replacer:Qa}, LatinExtra:{dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Na = {normalize:!1, numeric:!1}; +const Oa = {}; +const Pa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Qa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ra = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const Sa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +var Ta = {W:Na, V:Oa, X:Oa, LatinBalance:{dedupe:!0, mapper:Pa}, LatinAdvanced:{dedupe:!0, mapper:Pa, matcher:Qa, replacer:Ra}, LatinExtra:{dedupe:!0, mapper:Pa, replacer:Ra.concat([/(?!^)[aeo]/g, ""]), matcher:Qa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Ra[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Sa[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Sa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } -}}, LatinExact:Ma, LatinDefault:Na, LatinSimple:Na}; -const Ta = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -O.prototype.add = function(a, c, b, e) { +}}, LatinExact:Na, LatinDefault:Oa, LatinSimple:Oa}; +N.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { + if (this.fastupdate) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { + if (2 > d.length) { + d.pop(); + } else { + const f = d.indexOf(a); + f === b.length - 1 ? d.pop() : d.splice(f, 1); + } + } + } + } else { + Y(this.map, a), this.depth && Y(this.ctx, a); + } + c || this.reg.delete(a); + } + this.cache && this.cache.remove(a); + return this; +}; +function Y(a, c) { + let b = 0; + var e = "undefined" === typeof c; + if (a.constructor === Array) { + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && f.length) { + if (e) { + b++; + } else { + if (g = f.indexOf(c), 0 <= g) { + 1 < f.length ? (f.splice(g, 1), b++) : delete a[d]; + break; + } else { + b++; + } + } + } + } + } else { + for (let d of a.entries()) { + e = d[0]; + const f = Y(d[1], c); + f ? b += f : a.delete(e); + } + } + return b; +} +;const Ua = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +N.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); if (e = c.length) { - const l = C(), m = C(), n = this.depth, r = this.resolution; + const l = C(), m = C(), n = this.depth, u = this.resolution; for (let p = 0; p < e; p++) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Ua(r, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Va(u, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let t = 0, u; t < d; t++) { + for (let t = 0, r; t < d; t++) { for (f = d; f > t; f--) { g = q.substring(t, f); - u = this.rtl ? d - 1 - t : t; - var k = this.score ? this.score(c, q, p, g, u) : Ua(r, e, p, d, u); + r = this.rtl ? d - 1 - t : t; + var k = this.score ? this.score(c, q, p, g, r) : Va(u, e, p, d, r); Z(this, m, g, k, a, b); } } @@ -1444,7 +1489,7 @@ O.prototype.add = function(a, c, b, e) { if (1 < d) { for (k = d - 1; 0 < k; k--) { g = q[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, q, p, g, k) : Ua(r, e, p, d, k); + var h = this.score ? this.score(c, q, p, g, k) : Va(u, e, p, d, k); Z(this, m, g, h, a, b); } g = ""; @@ -1461,8 +1506,8 @@ O.prototype.add = function(a, c, b, e) { for (d = C(), g = this.S, f = q, k = Math.min(n + 1, this.rtl ? p + 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 t = this.score ? this.score(c, f, p, q, h - 1) : Ua(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; - Z(this, l, u ? f : q, t, a, b, u ? q : f); + const t = this.score ? this.score(c, f, p, q, h - 1) : Va(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), r = this.bidirectional && q > f; + Z(this, l, r ? f : q, t, a, b, r ? q : f); } } } @@ -1480,11 +1525,11 @@ function Z(a, c, b, e, d, f, 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 Ua(a, c, b, e, d) { +function Va(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;O.prototype.search = function(a, c, b) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); +;N.prototype.search = function(a, c, b) { + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { a = b.query || a; @@ -1501,11 +1546,11 @@ function Ua(a, c, b, e, d) { b = a.length; c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Va(this, a[0], "")) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Wa(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Va(this, a[1], a[0])) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Wa(this, a[1], a[0])) && c.length ? Aa.call(this, c, g, d) : []; } k = C(); let l = 0; @@ -1517,29 +1562,29 @@ function Ua(a, c, b, e, d) { for (let q, t; l < b; l++) { if ((t = a[l]) && !k[t]) { k[t] = 1; - q = Va(this, t, m); + q = Wa(this, t, m); a: { f = q; - var n = e, r = g, p = h; - let u = []; + var n = e, u = g, p = h; + let r = []; if (f && f.length) { if (f.length <= p) { n.push(f); q = void 0; break a; } - for (let w = 0, z; w < p; w++) { - if (z = f[w]) { - u[w] = z; + for (let x = 0, z; x < p; x++) { + if (z = f[x]) { + r[x] = z; } } - if (u.length) { - n.push(u); + if (r.length) { + n.push(r); q = void 0; break a; } } - q = r ? void 0 : u; + q = u ? void 0 : r; } if (q) { e = q; @@ -1554,77 +1599,34 @@ function Ua(a, c, b, e, d) { e = a.length; m = a; if (1 < e) { - m = wa(a, h, c, d, g); + m = xa(a, h, c, d, g); } else if (1 === e) { - g = za.call(null, a[0], c, d); + g = Aa.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Va(a, c, b) { +function Wa(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); 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; e < b.length; e++) { - if (d = b[e]) { - if (2 > d.length) { - d.pop(); - } else { - const f = d.indexOf(a); - f === b.length - 1 ? d.pop() : d.splice(f, 1); - } - } - } - } else { - Wa(this.map, a), this.depth && Wa(this.ctx, a); - } - c || this.reg.delete(a); - } - this.cache && this.cache.remove(a); - return this; -}; -function Wa(a, c) { - let b = 0; - if (a.constructor === Array) { - for (let e = 0, d, f; e < a.length; e++) { - if ((d = a[e]) && d.length) { - if (f = d.indexOf(c), 0 <= f) { - 1 < d.length ? (d.splice(f, 1), b++) : delete a[e]; - break; - } else { - b++; - } - } - } - } else { - for (let e of a.entries()) { - const d = e[0], f = Wa(e[1], c); - f ? b += f : a.delete(d); - } - } - return b; -} -;function O(a, c) { - if (!this || this.constructor !== O) { - return new O(a); +;function N(a, c) { + if (!this || this.constructor !== N) { + return new N(a); } if (a) { var b = D(a) ? a : a.preset; - b && (Ta[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ta[b], a)); + b && (Ua[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ua[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Sa[a.encoder] : a.encode || a.encoder || {}; - this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; this.depth = "strict" === b && e.depth || 0; @@ -1638,51 +1640,37 @@ function Wa(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.S = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new Y(b); + this.cache = (b = a.cache || null) && new X(b); this.priority = a.priority || 4; } -x = O.prototype; -x.clear = function() { +w = N.prototype; +w.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); this.cache && this.cache.clear(); return this; }; -x.append = function(a, c) { +w.append = function(a, c) { return this.add(a, c, !0); }; -x.contain = function(a) { +w.contain = function(a) { return this.reg.has(a); }; -x.update = function(a, c) { +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 Xa(a) { - let c = 0; - if (a.constructor === Array) { - for (let b = 0, e; b < a.length; b++) { - (e = a[b]) && (c += e.length); - } - } else { - for (const b of a.entries()) { - const e = b[0], d = Xa(b[1]); - d ? c += d : a.delete(e); - } - } - return c; -} -x.cleanup = function() { +w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Xa(this.map); - this.depth && Xa(this.ctx); + Y(this.map); + this.depth && Y(this.ctx); return this; }; -x.searchCache = La; -x.export = function(a, c, b = 0, e = 0) { +w.searchCache = Ma; +w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -1704,9 +1692,9 @@ x.export = function(a, c, b = 0, e = 0) { default: return; } - return U.call(this, a, c, d, f, b, e); + return ta.call(this, a, c, d, f, b, e); }; -x.import = function(a, c) { +w.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": @@ -1721,7 +1709,7 @@ x.import = function(a, c) { } } }; -x.serialize = function(a = !0) { +w.serialize = function(a = !0) { let c = "", b = "", e = ""; if (this.reg.size) { let f; @@ -1729,11 +1717,11 @@ x.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = ta(this.map, f); + b = ua(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = ta(g[1], f); + let k = ua(g[1], f); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; e += (e ? "," : "") + k; @@ -1742,11 +1730,11 @@ x.serialize = function(a = !0) { } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; -ia(O.prototype); +ia(N.prototype); C(); -const Ya = {Index:O, Charset:Sa, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, $a = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; -let ab; -(ab = $a.define) && ab.amd ? ab([], function() { - return Ya; -}) : "object" === typeof $a.exports ? $a.exports = Ya : $a.FlexSearch = Ya; +const Xa = {Index:N, Charset:Ta, Encoder:J, Document:U, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Za = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let $a; +($a = Za.define) && $a.amd ? $a([], function() { + return Xa; +}) : "object" === typeof Za.exports ? Za.exports = Xa : Za.FlexSearch = Xa; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 40cc71a..0760219 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,22 +1,22 @@ /**! - * FlexSearch.js v0.8.147 (Bundle) + * FlexSearch.js v0.8.149 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';var x;function 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; +(function(self){'use strict';var w;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 G(a){return"object"===typeof a}function H(a,c){if(D(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; this.numeric=B(a.numeric,e)}else{try{this.split=B(this.split,ba)}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);b=a.filter;this.filter="function"===typeof b?b:B(b&&new Set(b),null,this.filter);this.dedupe=B(a.dedupe,!1,this.dedupe);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);this.rtl=B(a.rtl,!1,this.rtl);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};x.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};x.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&L(this);return this}; -x.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&L(this);return this}; -x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; -x.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=fa?a.normalize("NFKD").replace(fa,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),d!==g&&this.filter&& +(this.D?"|":"")+d;return this};w.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&&K(this);return this};w.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; +w.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&&K(this);return this}; +w.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&K(this);return this}; +w.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(K,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=fa?a.normalize("NFKD").replace(fa,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),d!==g&&this.filter&& g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&dthis.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 ha(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ia(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ja,ka,Q;function la(){ja=Q=0} +this.replacer[d+1]);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)}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 K(a){a.H=null;a.F.clear();a.G.clear()};let L,M;async function ha(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":M=a.options||{};(c=a.factory)?(Function("return "+c)()(self),L=new self.FlexSearch.Index(M),delete self.FlexSearch):L=new N(M);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=M.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await M.import.call(L,e[0]),L.import(e[0],a)):(d=e&&L[c].apply(L,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ia(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ja,ka,Q;function la(){ja=Q=0} 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]);ja?Q||(Q=Date.now()-ka>=this.priority*this.priority*3):(ja=setTimeout(la,0),ka=Date.now());if(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 R=0; function S(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++R]=function(){h(d);1E9b||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function xa(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=xa(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}=Aa(this,"and",arguments);return Ca.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; -function Ca(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=wa(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}=Aa(this,"xor",arguments);return Da.call(this,a,c,b,e,d,f,g)}; -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 return this.result=Ea.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 Ea(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 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 Ma={normalize:!1,numeric:!1};const Na={};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"],["ph","f"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\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};var Sa={W:Ma,V:Na,X:Na,LatinBalance:{dedupe:!0,mapper:Oa},LatinAdvanced:{dedupe:!0,mapper:Oa,matcher:Pa,replacer:Qa},LatinExtra:{dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bt;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Ua(r,e,p,d,u); -Z(this,m,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),e,p, -k-1,h-1),u=this.bidirectional&&q>f;Z(this,l,u?f:q,t,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=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 Ua(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 Wa(this.map,a),this.depth&&Wa(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Wa(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function Xa(a){let c=0;if(a.constructor===Array)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 k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?V.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};W.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +X.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:!1,numeric:!1};const Oa={};const Pa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Sa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Ta={W:Na,V:Oa,X:Oa,LatinBalance:{dedupe:!0,mapper:Pa},LatinAdvanced:{dedupe:!0,mapper:Pa,matcher:Qa,replacer:Ra},LatinExtra:{dedupe:!0,mapper:Pa,replacer:Ra.concat([/(?!^)[aeo]/g,""]),matcher:Qa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bd.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Y(a,c){let b=0;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,f,g;dr;f--){g=q.substring(r,f);t=this.rtl?d-1-r:r;var k=this.score?this.score(c,q,p,g,t):Va(u,e,p,d,t); +Z(this,m,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),e,p, +k-1,h-1),t=this.bidirectional&&q>f;Z(this,l,t?f:q,r,a,b,t?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 Va(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function N(a,c){if(!this||this.constructor!==N)return new N(a);if(a){var b=D(a)?a:a.preset;b&&(a=Object.assign({},Ua[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=D(a.encoder)?Ta[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new J(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;b=!1;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.S=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(b=a.cache||null)&&new X(b);this.priority=a.priority||4}w=N.prototype;w.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};w.append=function(a,c){return this.add(a,c,!0)};w.contain=function(a){return this.reg.has(a)}; +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)};w.cleanup=function(){if(!this.fastupdate)return this;Y(this.map);this.depth&&Y(this.ctx);return this};w.searchCache=Ma;w.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=ra(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=na(this.map,this.reg.size);break;case 3:d="ctx";f=pa(this.ctx,this.reg.size);break;default:return}return ta.call(this,a,c,d,f,b,e)}; +w.import=function(a,c){if(c)switch("string"===typeof c&&(c=JSON.parse(c)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1 this.stemmer.get(h)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); @@ -251,12 +251,12 @@ x.encode = function(a) { 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) { +function K(a) { a.H = null; a.F.clear(); a.G.clear(); } -;let M, N; +;let L, M; async function ha(a) { a = a.data; var c = a.task; @@ -264,41 +264,41 @@ async function ha(a) { let e = a.args; switch(c) { case "init": - N = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + M = a.options || {}; + (c = a.factory) ? (Function("return " + c)()(self), L = new self.FlexSearch.Index(M), delete self.FlexSearch) : L = new N(M); postMessage({id:b}); break; default: let d; if ("export" === c) { - if (!N.export || "function" !== typeof N.export) { + if (!M.export || "function" !== typeof M.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - e[1] ? (e[0] = N.export, e[2] = 0, e[3] = 1) : e = null; + e[1] ? (e[0] = M.export, e[2] = 0, e[3] = 1) : e = null; } if ("import" === c) { - if (!N.import || "function" !== typeof N.import) { + if (!M.import || "function" !== typeof M.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - e[0] && (a = await N.import.call(M, e[0]), M.import(e[0], a)); + e[0] && (a = await M.import.call(L, e[0]), L.import(e[0], a)); } else { - (d = e && M[c].apply(M, e)) && d.then && (d = await d); + (d = e && L[c].apply(L, e)) && d.then && (d = await d); } postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } ;function ia(a) { - P.call(a, "add"); - P.call(a, "append"); - P.call(a, "search"); - P.call(a, "update"); - P.call(a, "remove"); + O.call(a, "add"); + O.call(a, "append"); + O.call(a, "search"); + O.call(a, "update"); + O.call(a, "remove"); } let ja, ka, Q; function la() { ja = Q = 0; } -function P(a) { +function O(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; @@ -429,7 +429,7 @@ function sa(a, c) { } return c; } -function U(a, c, b, e, d, f, g = 0) { +function ta(a, c, b, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { @@ -438,12 +438,12 @@ function U(a, c, b, e, d, f, g = 0) { if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return U.call(l, a, c, b, k ? e : null, d, f, g + 1); + return ta.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return U.call(this, a, c, b, k ? e : null, d, f, g + 1); + return ta.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function ta(a, c) { +function ua(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; @@ -463,8 +463,8 @@ function ta(a, c) { } return b; } -;V.prototype.add = function(a, c, b) { - I(a) && (c = a, a = J(c, this.key)); +;U.prototype.add = function(a, c, b) { + H(a) && (c = a, a = I(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { return this.update(a, c); @@ -477,7 +477,7 @@ function ta(a, c) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), ua(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); } } } @@ -496,7 +496,7 @@ function ta(a, c) { continue; } f.constructor === String && (f = "" + f); - f = J(c, f); + f = I(c, f); } if (d && f) { D(f) && (f = [f]); @@ -528,7 +528,7 @@ function ta(a, c) { k[l] = c[l]; continue; } - va(c, k, l, 0, l[0], m); + wa(c, k, l, 0, l[0], m); } } this.store.set(a, k || c); @@ -536,21 +536,21 @@ function ta(a, c) { } return this; }; -function va(a, c, b, e, d, f) { +function wa(a, c, b, e, d, f) { a = a[d]; if (e === b.length - 1) { c[d] = f || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - va(a, c, b, e, d); + wa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], va(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], wa(a, c, b, e, d); } } } -function ua(a, c, b, e, d, f, g, k) { +function va(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -566,24 +566,24 @@ function ua(a, c, b, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - ua(a, c, b, e, d, f, g, k); + va(a, c, b, e, d, f, g, k); } } else { - g = c[++e], ua(a, c, b, e, d, f, g, k); + g = c[++e], va(a, c, b, e, d, f, g, k); } } } } -;function wa(a, c, b, e, d) { +;function xa(a, c, b, e, d) { const f = a.length; let g = [], k, h; k = C(); - for (let l = 0, m, n, r, p; l < c; l++) { + for (let l = 0, m, n, u, p; l < c; l++) { for (let q = 0; q < f; q++) { - if (r = a[q], l < r.length && (m = r[l])) { + if (u = a[q], l < u.length && (m = u[l])) { for (let t = 0; t < m.length; t++) { if (n = m[t], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n), b && h === f - 1 && p.length - e === b) { - return p; + return e ? p.slice(e) : p; } } } @@ -591,7 +591,7 @@ function ua(a, c, b, e, d, f, g, k) { } if (a = g.length) { if (d) { - g = 1 < g.length ? xa(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -606,7 +606,7 @@ function ua(a, c, b, e, d, f, g, k) { } return g; } -function xa(a, c, b) { +function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; @@ -628,7 +628,7 @@ function xa(a, c, b) { } return e; } -function ya(a, c) { +function za(a, c) { const b = C(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -641,12 +641,12 @@ function ya(a, c) { } return e; } -;function za(a, c, b, e) { +;function Aa(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? V.call(this, a) : a; } let d = []; for (let f = 0, g, k; f < a.length; f++) { @@ -660,7 +660,7 @@ function ya(a, c) { } k > c && (g = g.slice(0, c), k = c); if (!d.length && k >= c) { - return e ? W.call(this, g) : g; + return e ? V.call(this, g) : g; } d.push(g); c -= k; @@ -670,9 +670,9 @@ function ya(a, c) { } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? W.call(this, d) : d; + return e ? V.call(this, d) : d; } -;function Aa(a, c, b) { +;function Ba(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -686,30 +686,30 @@ function ya(a, c) { let d = [], f = 0, g = 0, k, h, l; for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { - let r; - if (n.constructor === X) { - r = n.result; + let u; + if (n.constructor === W) { + u = n.result; } else if (n.constructor === Array) { - r = n; + u = n; } else { if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, r = n.index.search(n).result, n.resolve = h, n.enrich = k; + n.resolve = !1, n.enrich = !1, u = n.index.search(n).result, n.resolve = h, n.enrich = k; } else if (n.and) { - r = a.and(n.and); + u = a.and(n.and); } else if (n.or) { - r = a.or(n.or); + u = a.or(n.or); } else if (n.xor) { - r = a.xor(n.xor); + u = a.xor(n.xor); } else if (n.not) { - r = a.not(n.not); + u = a.not(n.not); } else { continue; } } - if (r.then) { - d.push(r); - } else if (r.length) { - e[m] = r; + if (u.then) { + d.push(u); + } else if (u.length) { + e[m] = u; } else if (!l && ("and" === c || "xor" === c)) { e = []; break; @@ -718,11 +718,11 @@ function ya(a, c) { } 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} = Aa(this, "or", arguments); - return Ba.call(this, a, c, b, e, d, f); +;W.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); + return Ca.call(this, a, c, b, e, d, f); }; -function Ba(a, c, b, e, d, f) { +function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; return Promise.all(c).then(function(k) { @@ -730,53 +730,24 @@ function Ba(a, c, b, e, d, f) { for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return Ba.call(g, a, [], b, e, d, f); + return Ca.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = xa(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ya(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } -;X.prototype.and = function() { +;W.prototype.and = function() { let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Aa(this, "and", arguments); - return Ca.call(this, f, g, k, h, 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 Ca(a, c, b, e, d, f, g) { - if (c.length) { - const k = this; - return Promise.all(c).then(function(h) { - a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); - } - return Ca.call(k, a, [], b, e, d, f, g); - }); - } - if (a.length) { - if (this.result.length && a.unshift(this.result), 2 > a.length) { - this.result = a[0]; - } else { - if (c = aa(a)) { - return this.result = wa(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} = Aa(this, "xor", arguments); - return Da.call(this, a, c, b, e, d, f, g); -}; function Da(a, c, b, e, d, f, g) { if (c.length) { const k = this; @@ -792,14 +763,43 @@ function Da(a, c, b, e, d, f, g) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Ea.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + if (c = aa(a)) { + return this.result = xa(a, c, b, e, g), f ? d ? V.call(this.index, this.result) : this.result : this; + } + this.result = []; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Ea(a, c, b, e, d) { +;W.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); + return Ea.call(this, a, c, b, e, d, f, g); +}; +function Ea(a, c, b, e, d, f, g) { + if (c.length) { + const k = this; + return Promise.all(c).then(function(h) { + a = []; + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Ea.call(k, a, [], b, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = Fa.call(this, a, b, e, f, this.h), f ? d ? V.call(this.index, this.result) : this.result : this; + } + } 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; h < a.length; h++) { @@ -807,17 +807,17 @@ function Ea(a, c, b, e, d) { k < l.length && (k = l.length); for (let m = 0, n; m < l.length; m++) { if (n = l[m]) { - for (let r = 0, p; r < n.length; r++) { - p = n[r], g[p] = g[p] ? 2 : 1; + for (let u = 0, p; u < n.length; u++) { + p = n[u], g[p] = g[p] ? 2 : 1; } } } } } for (let h = 0, l, m = 0; h < k; h++) { - for (let n = 0, r; n < a.length; n++) { - if (r = a[n]) { - if (l = r[h]) { + for (let n = 0, u; n < a.length; n++) { + if (u = a[n]) { + if (l = u[h]) { for (let p = 0, q; p < l.length; p++) { if (q = l[p], 1 === g[q]) { if (b) { @@ -844,11 +844,11 @@ function Ea(a, c, b, e, d) { } return f; } -;X.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "not", arguments); - return Fa.call(this, a, c, b, e, d, f, g); +;W.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); + return Ga.call(this, a, c, b, e, d, f, g); }; -function Fa(a, c, b, e, d, f, g) { +function Ga(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -856,17 +856,17 @@ function Fa(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Fa.call(k, a, [], b, e, d, f, g); + return Ga.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ga.call(this, a, b, e, f); + this.result = Ha.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? W.call(this.index, this.result) : this.result : this; + return f ? d ? V.call(this.index, this.result) : this.result : this; } -function Ga(a, c, b, e) { +function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { @@ -892,9 +892,9 @@ function Ga(a, c, b, e) { } return d; } -;function X(a) { - if (!this || this.constructor !== X) { - return new X(a); +;function W(a) { + if (!this || this.constructor !== W) { + return new W(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -903,7 +903,7 @@ function Ga(a, c, b, e) { this.result = a || []; this.h = 0; } -X.prototype.limit = function(a) { +W.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -922,7 +922,7 @@ X.prototype.limit = function(a) { } return this; }; -X.prototype.offset = function(a) { +W.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -934,23 +934,23 @@ X.prototype.offset = function(a) { } return this; }; -X.prototype.boost = function(a) { +W.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, c, b) { +W.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), za.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; }; C(); -V.prototype.search = function(a, c, b, e) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); +U.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; let k, h, l; - let m = 0, n = !0, r; + let m = 0, n = !0, u; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; @@ -961,49 +961,49 @@ V.prototype.search = function(a, c, b, e) { k = b.suggest; n = !0; this.store && b.enrich && !n && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - r = (g = this.store && b.enrich && n) && b.highlight; + u = (g = this.store && b.enrich && n) && b.highlight; c = b.limit || c; var t = b.offset || 0; c || (c = 100); if (l) { l.constructor !== Array && (l = [l]); - var u = []; + var r = []; for (let y = 0, v; y < l.length; y++) { v = l[y]; if (D(v)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (v.field && v.tag) { - var w = v.tag; - if (w.constructor === Array) { - for (var z = 0; z < w.length; z++) { - u.push(v.field, w[z]); + var x = v.tag; + if (x.constructor === Array) { + for (var z = 0; z < x.length; z++) { + r.push(v.field, x[z]); } } else { - u.push(v.field, w); + r.push(v.field, x); } } else { - w = Object.keys(v); - for (let E = 0, F, A; E < w.length; E++) { - if (F = w[E], A = v[F], A.constructor === Array) { + x = Object.keys(v); + for (let E = 0, F, A; E < x.length; E++) { + if (F = x[E], A = v[F], A.constructor === Array) { for (z = 0; z < A.length; z++) { - u.push(F, A[z]); + r.push(F, A[z]); } } else { - u.push(F, A); + r.push(F, A); } } } } - if (!u.length) { + if (!r.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = u; + l = r; if (!a) { f = []; - if (u.length) { - for (p = 0; p < u.length; p += 2) { - q = Ha.call(this, u[p], u[p + 1], c, t, g), d.push({field:u[p], tag:u[p + 1], result:q}); + if (r.length) { + for (p = 0; p < r.length; p += 2) { + q = Ia.call(this, r[p], r[p + 1], c, t, g), d.push({field:r[p], tag:r[p + 1], result:q}); } } return f.length ? Promise.all(f).then(function(y) { @@ -1017,7 +1017,7 @@ V.prototype.search = function(a, c, b, e) { h && h.constructor !== Array && (h = [h]); } h || (h = this.field); - u = !e && (this.worker || this.db) && []; + r = !e && (this.worker || this.db) && []; for (let y = 0, v, E, F; y < h.length; y++) { E = h[y]; let A; @@ -1025,38 +1025,38 @@ V.prototype.search = function(a, c, b, e) { if (e) { v = e[y]; } else { - if (w = A || b, z = this.index.get(E), l && (w.enrich = !1), u) { - u[y] = z.search(a, c, w); - w && g && (w.enrich = g); + if (x = A || b, z = this.index.get(E), l && (x.enrich = !1), r) { + r[y] = z.search(a, c, x); + x && g && (x.enrich = g); continue; } else { - v = z.search(a, c, w), w && g && (w.enrich = g); + v = z.search(a, c, x), x && g && (x.enrich = g); } } F = v && (n ? v.length : v.result.length); if (l && F) { - w = []; + x = []; z = 0; - for (let G = 0, H, Wa; G < l.length; G += 2) { - H = this.tag.get(l[G]); - if (!H) { + for (let G = 0, P, Va; G < l.length; G += 2) { + P = this.tag.get(l[G]); + if (!P) { if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), k) { continue; } else { - return n ? d : new X(d); + return n ? d : new W(d); } } - if (Wa = (H = H && H.get(l[G + 1])) && H.length) { - z++, w.push(H); + if (Va = (P = P && P.get(l[G + 1])) && P.length) { + z++, x.push(P); } else if (!k) { - return n ? d : new X(d); + return n ? d : new W(d); } } if (z) { - v = ya(v, w); + v = za(v, x); F = v.length; if (!F && !k) { - return n ? v : new X(v); + return n ? v : new W(v); } z--; } @@ -1064,78 +1064,74 @@ V.prototype.search = function(a, c, b, e) { if (F) { f[m] = E, d.push(v), m++; } else if (1 === h.length) { - return n ? d : new X(d); + return n ? d : new W(d); } } - if (u) { + if (r) { const y = this; - return Promise.all(u).then(function(v) { + return Promise.all(r).then(function(v) { return v.length ? y.search(a, c, b, v) : v; }); } if (!m) { - return n ? d : new X(d); + return n ? d : new W(d); } if (p && (!g || !this.store)) { return d[0]; } - u = []; + r = []; for (t = 0; t < f.length; t++) { e = d[t]; - g && e.length && "undefined" === typeof e[0].doc && (e = W.call(this, e)); + g && e.length && "undefined" === typeof e[0].doc && (e = V.call(this, e)); if (p) { - return n ? e : new X(e); + return n ? e : new W(e); } d[t] = {field:f[t], result:e}; } - return q ? Ia(d, c) : r ? Ja(d, a, this.index, this.field, this.C, r) : d; + return q ? Ja(d, c) : u ? Ka(d, a, this.index, this.field, this.C, u) : d; }; -function Ja(a, c, b, e, d, f) { +function Ka(a, c, b, e, d, f) { let g, k, h; - for (let m = 0, n, r, p, q; m < a.length; m++) { - let t = a[m].result; - n = a[m].field; - p = b.get(n); - r = p.encoder; - h = p.tokenize; - q = d[e.indexOf(n)]; - r !== g && (g = r, k = g.encode(c)); - for (let u = 0; u < t.length; u++) { - let w = ""; - var l = J(t[u].doc, q); - let z = g.encode(l); - l = l.split(g.split); - for (let y = 0, v, E; y < z.length; y++) { - v = z[y]; - E = l[y]; - if (!v || !E) { - continue; - } - let F; - for (let A = 0, G; A < k.length; A++) { - if (G = k[A], "strict" === h) { - if (v === G) { - w += (w ? " " : "") + f.replace("$1", E); - F = !0; - break; - } - } else { - const H = v.indexOf(G); - if (-1 < H) { - w += (w ? " " : "") + E.substring(0, H) + f.replace("$1", E.substring(H, G.length)) + E.substring(H + G.length); - F = !0; - break; + for (let l = 0, m, n, u, p; l < a.length; l++) { + let q = a[l].result; + m = a[l].field; + u = b.get(m); + n = u.encoder; + h = u.tokenize; + p = d[e.indexOf(m)]; + n !== g && (g = n, k = g.encode(c)); + for (let t = 0; t < q.length; t++) { + let r = "", x = I(q[t].doc, p).split(/\s+/); + for (let z = 0, y, v; z < x.length; z++) { + y = x[z]; + v = g.encode(y).join(" "); + let E; + if (v && y) { + for (let F = 0, A; F < k.length; F++) { + if (A = k[F], "strict" === h) { + if (v === A) { + r += (r ? " " : "") + f.replace("$1", y); + E = !0; + break; + } + } else { + const G = v.indexOf(A); + if (-1 < G) { + r += (r ? " " : "") + y.substring(0, G) + f.replace("$1", y.substring(G, A.length)) + y.substring(G + A.length); + E = !0; + break; + } } } } - F || (w += (w ? " " : "") + l[y]); + E || (r += (r ? " " : "") + x[z]); } - t[u].highlight = w; + q[t].highlight = r; } } return a; } -function Ia(a, c) { +function Ja(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1154,7 +1150,7 @@ function Ia(a, c) { } return b; } -function Ha(a, c, b, e, d) { +function Ia(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1163,11 +1159,11 @@ function Ha(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = W.call(this, f)); + d && (f = V.call(this, f)); return f; } } -function W(a) { +function V(a) { if (!this || !this.store) { return a; } @@ -1177,33 +1173,33 @@ function W(a) { } return c; } -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); +;function U(a) { + if (!this || this.constructor !== U) { + return new U(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && Ka(b, this.J) || "id"; + this.key = (b = c.key || c.id) && La(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); - this.cache = (b = a.cache || null) && new Y(b); + this.cache = (b = a.cache || null) && new X(b); a.cache = !1; this.priority = a.priority || 4; b = new Map(); let e = c.index || c.field || c; D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Ka(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, b.set(f, new N(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = Ka(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1219,14 +1215,14 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Ka(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function Ka(a, c) { +function La(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1235,15 +1231,15 @@ function Ka(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -x = V.prototype; -x.append = function(a, c) { +w = U.prototype; +w.append = function(a, c) { return this.add(a, c, !0); }; -x.update = function(a, c) { +w.update = function(a, c) { return this.remove(a).add(a, c); }; -x.remove = function(a) { - I(a) && (a = J(a, this.key)); +w.remove = function(a) { + H(a) && (a = I(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1263,7 +1259,7 @@ x.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -x.clear = function() { +w.clear = function() { const a = []; for (const c of this.index.values()) { const b = c.clear(); @@ -1278,25 +1274,25 @@ x.clear = function() { this.cache && this.cache.clear(); return a.length ? Promise.all(a) : this; }; -x.contain = function(a) { +w.contain = function(a) { return this.reg.has(a); }; -x.cleanup = function() { +w.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -x.get = function(a) { +w.get = function(a) { return this.store.get(a) || null; }; -x.set = function(a, c) { - "object" === typeof a && (c = a, a = J(c, this.key)); +w.set = function(a, c) { + "object" === typeof a && (c = a, a = I(c, this.key)); this.store.set(a, c); return this; }; -x.searchCache = La; -x.export = function(a, c, b = 0, e = 0) { +w.searchCache = Ma; +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) { @@ -1327,9 +1323,9 @@ x.export = function(a, c, b = 0, e = 0) { default: return; } - return U.call(this, a, c, d, f, b, e); + return ta.call(this, a, c, d, f, b, e); }; -x.import = function(a, c) { +w.import = function(a, c) { var b = a.split("."); "json" === b[b.length - 1] && b.pop(); a = 2 < b.length ? b[0] : ""; @@ -1355,10 +1351,10 @@ x.import = function(a, c) { } } }; -ia(V.prototype); -function La(a, c, b) { +ia(U.prototype); +function Ma(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Y()); + this.cache || (this.cache = new X()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -1373,66 +1369,115 @@ function La(a, c, b) { } return e; } -function Y(a) { +function X(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -Y.prototype.set = function(a, c) { +X.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -Y.prototype.get = function(a) { +X.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -Y.prototype.remove = function(a) { +X.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() { +X.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ma = {normalize:!1, numeric:!1}; -const Na = {}; -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"], ["ph", "f"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\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}; -var Sa = {W:Ma, V:Na, X:Na, LatinBalance:{dedupe:!0, mapper:Oa}, LatinAdvanced:{dedupe:!0, mapper:Oa, matcher:Pa, replacer:Qa}, LatinExtra:{dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Na = {normalize:!1, numeric:!1}; +const Oa = {}; +const Pa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Qa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ra = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const Sa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +var Ta = {W:Na, V:Oa, X:Oa, LatinBalance:{dedupe:!0, mapper:Pa}, LatinAdvanced:{dedupe:!0, mapper:Pa, matcher:Qa, replacer:Ra}, LatinExtra:{dedupe:!0, mapper:Pa, replacer:Ra.concat([/(?!^)[aeo]/g, ""]), matcher:Qa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Ra[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Sa[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Sa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } -}}, LatinExact:Ma, LatinDefault:Na, LatinSimple:Na}; -const Ta = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -O.prototype.add = function(a, c, b, e) { +}}, LatinExact:Na, LatinDefault:Oa, LatinSimple:Oa}; +N.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { + if (this.fastupdate) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { + if (2 > d.length) { + d.pop(); + } else { + const f = d.indexOf(a); + f === b.length - 1 ? d.pop() : d.splice(f, 1); + } + } + } + } else { + Y(this.map, a), this.depth && Y(this.ctx, a); + } + c || this.reg.delete(a); + } + this.cache && this.cache.remove(a); + return this; +}; +function Y(a, c) { + let b = 0; + var e = "undefined" === typeof c; + if (a.constructor === Array) { + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && f.length) { + if (e) { + b++; + } else { + if (g = f.indexOf(c), 0 <= g) { + 1 < f.length ? (f.splice(g, 1), b++) : delete a[d]; + break; + } else { + b++; + } + } + } + } + } else { + for (let d of a.entries()) { + e = d[0]; + const f = Y(d[1], c); + f ? b += f : a.delete(e); + } + } + return b; +} +;const Ua = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +N.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); if (e = c.length) { - const l = C(), m = C(), n = this.depth, r = this.resolution; + const l = C(), m = C(), n = this.depth, u = this.resolution; for (let p = 0; p < e; p++) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Ua(r, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Wa(u, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let t = 0, u; t < d; t++) { + for (let t = 0, r; t < d; t++) { for (f = d; f > t; f--) { g = q.substring(t, f); - u = this.rtl ? d - 1 - t : t; - var k = this.score ? this.score(c, q, p, g, u) : Ua(r, e, p, d, u); + r = this.rtl ? d - 1 - t : t; + var k = this.score ? this.score(c, q, p, g, r) : Wa(u, e, p, d, r); Z(this, m, g, k, a, b); } } @@ -1443,7 +1488,7 @@ O.prototype.add = function(a, c, b, e) { if (1 < d) { for (k = d - 1; 0 < k; k--) { g = q[this.rtl ? d - 1 - k : k] + g; - var h = this.score ? this.score(c, q, p, g, k) : Ua(r, e, p, d, k); + var h = this.score ? this.score(c, q, p, g, k) : Wa(u, e, p, d, k); Z(this, m, g, h, a, b); } g = ""; @@ -1460,8 +1505,8 @@ O.prototype.add = function(a, c, b, e) { for (d = C(), g = this.S, f = q, k = Math.min(n + 1, this.rtl ? p + 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 t = this.score ? this.score(c, f, p, q, h - 1) : Ua(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; - Z(this, l, u ? f : q, t, a, b, u ? q : f); + const t = this.score ? this.score(c, f, p, q, h - 1) : Wa(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), r = this.bidirectional && q > f; + Z(this, l, r ? f : q, t, a, b, r ? q : f); } } } @@ -1479,11 +1524,11 @@ function Z(a, c, b, e, d, f, 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 Ua(a, c, b, e, d) { +function Wa(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;O.prototype.search = function(a, c, b) { - b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); +;N.prototype.search = function(a, c, b) { + b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { a = b.query || a; @@ -1500,11 +1545,11 @@ function Ua(a, c, b, e, d) { b = a.length; c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Va(this, a[0], "")) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Xa(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Va(this, a[1], a[0])) && c.length ? za.call(this, c, g, d) : []; + return g = c, (c = Xa(this, a[1], a[0])) && c.length ? Aa.call(this, c, g, d) : []; } k = C(); let l = 0; @@ -1516,29 +1561,29 @@ function Ua(a, c, b, e, d) { for (let q, t; l < b; l++) { if ((t = a[l]) && !k[t]) { k[t] = 1; - q = Va(this, t, m); + q = Xa(this, t, m); a: { f = q; - var n = e, r = g, p = h; - let u = []; + var n = e, u = g, p = h; + let r = []; if (f && f.length) { if (f.length <= p) { n.push(f); q = void 0; break a; } - for (let w = 0, z; w < p; w++) { - if (z = f[w]) { - u[w] = z; + for (let x = 0, z; x < p; x++) { + if (z = f[x]) { + r[x] = z; } } - if (u.length) { - n.push(u); + if (r.length) { + n.push(r); q = void 0; break a; } } - q = r ? void 0 : u; + q = u ? void 0 : r; } if (q) { e = q; @@ -1553,77 +1598,34 @@ function Ua(a, c, b, e, d) { e = a.length; m = a; if (1 < e) { - m = wa(a, h, c, d, g); + m = xa(a, h, c, d, g); } else if (1 === e) { - g = za.call(null, a[0], c, d); + g = Aa.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Va(a, c, b) { +function Xa(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;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; e < b.length; e++) { - if (d = b[e]) { - if (2 > d.length) { - d.pop(); - } else { - const f = d.indexOf(a); - f === b.length - 1 ? d.pop() : d.splice(f, 1); - } - } - } - } else { - Xa(this.map, a), this.depth && Xa(this.ctx, a); - } - c || this.reg.delete(a); - } - this.cache && this.cache.remove(a); - return this; -}; -function Xa(a, c) { - let b = 0; - if (a.constructor === Array) { - for (let e = 0, d, f; e < a.length; e++) { - if ((d = a[e]) && d.length) { - if (f = d.indexOf(c), 0 <= f) { - 1 < d.length ? (d.splice(f, 1), b++) : delete a[e]; - break; - } else { - b++; - } - } - } - } else { - for (let e of a.entries()) { - const d = e[0], f = Xa(e[1], c); - f ? b += f : a.delete(d); - } - } - return b; -} -;function O(a, c) { - if (!this || this.constructor !== O) { - return new O(a); +;function N(a, c) { + if (!this || this.constructor !== N) { + return new N(a); } if (a) { var b = D(a) ? a : a.preset; - b && (Ta[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ta[b], a)); + b && (Ua[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ua[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Sa[a.encoder] : a.encode || a.encoder || {}; - this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; this.depth = "strict" === b && e.depth || 0; @@ -1637,51 +1639,37 @@ function Xa(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.S = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new Y(b); + this.cache = (b = a.cache || null) && new X(b); this.priority = a.priority || 4; } -x = O.prototype; -x.clear = function() { +w = N.prototype; +w.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); this.cache && this.cache.clear(); return this; }; -x.append = function(a, c) { +w.append = function(a, c) { return this.add(a, c, !0); }; -x.contain = function(a) { +w.contain = function(a) { return this.reg.has(a); }; -x.update = function(a, c) { +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 Ya(a) { - let c = 0; - if (a.constructor === Array) { - for (let b = 0, e; b < a.length; b++) { - (e = a[b]) && (c += e.length); - } - } else { - for (const b of a.entries()) { - const e = b[0], d = Ya(b[1]); - d ? c += d : a.delete(e); - } - } - return c; -} -x.cleanup = function() { +w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Ya(this.map); - this.depth && Ya(this.ctx); + Y(this.map); + this.depth && Y(this.ctx); return this; }; -x.searchCache = La; -x.export = function(a, c, b = 0, e = 0) { +w.searchCache = Ma; +w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -1703,9 +1691,9 @@ x.export = function(a, c, b = 0, e = 0) { default: return; } - return U.call(this, a, c, d, f, b, e); + return ta.call(this, a, c, d, f, b, e); }; -x.import = function(a, c) { +w.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": @@ -1720,7 +1708,7 @@ x.import = function(a, c) { } } }; -x.serialize = function(a = !0) { +w.serialize = function(a = !0) { let c = "", b = "", e = ""; if (this.reg.size) { let f; @@ -1728,11 +1716,11 @@ x.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = ta(this.map, f); + b = ua(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = ta(g[1], f); + let k = ua(g[1], f); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; e += (e ? "," : "") + k; @@ -1741,8 +1729,8 @@ x.serialize = function(a = !0) { } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; -ia(O.prototype); +ia(N.prototype); C(); -export default {Index:O, Charset:Sa, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:N, Charset:Ta, Encoder:J, Document:U, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=O;export const Charset=Sa;export const Encoder=K;export const Document=V;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=N;export const Charset=Ta;export const Encoder=J;export const Document=U;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index bda1152..367ef74 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,22 +1,22 @@ /**! - * FlexSearch.js v0.8.147 (Bundle) + * FlexSearch.js v0.8.149 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var x;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; +var w;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 G(a){return"object"===typeof a}function H(a,c){if(D(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; this.numeric=B(a.numeric,e)}else{try{this.split=B(this.split,ba)}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);b=a.filter;this.filter="function"===typeof b?b:B(b&&new Set(b),null,this.filter);this.dedupe=B(a.dedupe,!1,this.dedupe);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);this.rtl=B(a.rtl,!1,this.rtl);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};x.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};x.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&L(this);return this}; -x.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&L(this);return this}; -x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; -x.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=fa?a.normalize("NFKD").replace(fa,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),d!==g&&this.filter&& +(this.D?"|":"")+d;return this};w.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&&K(this);return this};w.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; +w.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&&K(this);return this}; +w.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&K(this);return this}; +w.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(K,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=fa?a.normalize("NFKD").replace(fa,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),d!==g&&this.filter&& g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&dthis.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 ha(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ia(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ja,ka,Q;function la(){ja=Q=0} +this.replacer[d+1]);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)}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 K(a){a.H=null;a.F.clear();a.G.clear()};let L,M;async function ha(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":M=a.options||{};(c=a.factory)?(Function("return "+c)()(self),L=new self.FlexSearch.Index(M),delete self.FlexSearch):L=new N(M);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=M.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await M.import.call(L,e[0]),L.import(e[0],a)):(d=e&&L[c].apply(L,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ia(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ja,ka,Q;function la(){ja=Q=0} 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]);ja?Q||(Q=Date.now()-ka>=this.priority*this.priority*3):(ja=setTimeout(la,0),ka=Date.now());if(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 R=0; function S(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++R]=function(){h(d);1E9b||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function xa(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=xa(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}=Aa(this,"and",arguments);return Ca.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; -function Ca(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=wa(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}=Aa(this,"xor",arguments);return Da.call(this,a,c,b,e,d,f,g)}; -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 return this.result=Ea.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 Ea(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 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 Ma={normalize:!1,numeric:!1};const Na={};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"],["ph","f"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\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};var Sa={W:Ma,V:Na,X:Na,LatinBalance:{dedupe:!0,mapper:Oa},LatinAdvanced:{dedupe:!0,mapper:Oa,matcher:Pa,replacer:Qa},LatinExtra:{dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bt;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Ua(r,e,p,d,u); -Z(this,m,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),e,p, -k-1,h-1),u=this.bidirectional&&q>f;Z(this,l,u?f:q,t,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=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 Ua(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 Xa(this.map,a),this.depth&&Xa(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Xa(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function Ya(a){let c=0;if(a.constructor===Array)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 k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?V.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};W.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +X.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:!1,numeric:!1};const Oa={};const Pa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Sa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Ta={W:Na,V:Oa,X:Oa,LatinBalance:{dedupe:!0,mapper:Pa},LatinAdvanced:{dedupe:!0,mapper:Pa,matcher:Qa,replacer:Ra},LatinExtra:{dedupe:!0,mapper:Pa,replacer:Ra.concat([/(?!^)[aeo]/g,""]),matcher:Qa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bd.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Y(a,c){let b=0;var e="undefined"===typeof c;if(a.constructor===Array)for(let d=0,f,g;dr;f--){g=q.substring(r,f);t=this.rtl?d-1-r:r;var k=this.score?this.score(c,q,p,g,t):Wa(u,e,p,d,t); +Z(this,m,g,k,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),e,p, +k-1,h-1),t=this.bidirectional&&q>f;Z(this,l,t?f:q,r,a,b,t?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 Wa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function N(a,c){if(!this||this.constructor!==N)return new N(a);if(a){var b=D(a)?a:a.preset;b&&(a=Object.assign({},Va[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=D(a.encoder)?Ta[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new J(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;b=!1;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.S=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(b=a.cache||null)&&new X(b);this.priority=a.priority||4}w=N.prototype;w.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};w.append=function(a,c){return this.add(a,c,!0)};w.contain=function(a){return this.reg.has(a)}; +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)};w.cleanup=function(){if(!this.fastupdate)return this;Y(this.map);this.depth&&Y(this.ctx);return this};w.searchCache=Ma;w.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=ra(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=na(this.map,this.reg.size);break;case 3:d="ctx";f=pa(this.ctx,this.reg.size);break;default:return}return ta.call(this,a,c,d,f,b,e)}; +w.import=function(a,c){if(c)switch("string"===typeof c&&(c=JSON.parse(c)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1 this.T && (this.B.clear(), this.G = this.G / 1.1 | 0)); return d; }; -function N(a) { +function M(a) { a.D = null; a.B.clear(); a.C.clear(); @@ -1146,14 +1146,14 @@ function Ha(a) { h.h = 5; break; } - return E(h, O.import.call(Ga, d[0]), 9); + return D(h, O.import.call(Ga, d[0]), 9); } g = d && Ga[b].apply(Ga, d); if (!g || !g.then) { h.h = 5; break; } - return E(h, g, 7); + return D(h, g, 7); case 7: g = h.D; h.h = 5; @@ -1172,9 +1172,9 @@ function Ha(a) { Ja.call(a, "update"); Ja.call(a, "remove"); } -var Ma, Na, Oa; +var Ka, Na, Oa; function Pa() { - Ma = Oa = 0; + Ka = Oa = 0; } function Ja(a) { this[a + "Async"] = function() { @@ -1183,7 +1183,7 @@ function Ja(a) { var d = c; delete b[b.length - 1]; } - Ma ? Oa || (Oa = Date.now() - Na >= this.priority * this.priority * 3) : (Ma = setTimeout(Pa, 0), Na = Date.now()); + Ka ? Oa || (Oa = Date.now() - Na >= this.priority * this.priority * 3) : (Ka = setTimeout(Pa, 0), Na = Date.now()); if (Oa) { var e = this; return new Promise(function(f) { @@ -1209,7 +1209,7 @@ function Ra(a) { m && (m(k.msg), delete e.h[l]); } this.worker = f; - this.h = J(); + this.h = I(); if (this.worker) { d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { @@ -1269,7 +1269,7 @@ function Sa(a, b, c) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 5000 | 0); - a = x(a.entries()); + a = y(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { d.push(e.value), d.length === b && (c.push(d), d = []); } @@ -1287,7 +1287,7 @@ function Va(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 1000 | 0); - a = x(a.entries()); + a = y(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { e = e.value, d.push([e[0], Ta(e[1])[0]]), d.length === b && (c.push(d), d = []); } @@ -1303,7 +1303,7 @@ function Wa(a, b) { } function Xa(a) { var b = [], c = []; - a = x(a.keys()); + a = y(a.keys()); for (var d = a.next(); !d.done; d = a.next()) { c.push(d.value), 250000 === c.length && (b.push(c), c = []); } @@ -1333,7 +1333,7 @@ function Za(a, b, c, d, e, g, f) { } function $a(a, b) { var c = ""; - a = x(a.entries()); + a = y(a.entries()); for (var d = a.next(); !d.done; d = a.next()) { var e = d.value; d = e[0]; @@ -1450,7 +1450,7 @@ function U(a) { if (!this || this.constructor !== U) { return new U(a); } - this.index = J(); + this.index = I(); this.h = []; this.size = 0; 32 < a ? (this.A = bb, this.B = BigInt(a)) : (this.A = cb, this.B = a); @@ -1468,7 +1468,7 @@ function V(a) { if (!this || this.constructor !== V) { return new V(a); } - this.index = J(); + this.index = I(); this.h = []; this.size = 0; 32 < a ? (this.A = bb, this.B = BigInt(a)) : (this.A = cb, this.B = a); @@ -1487,7 +1487,7 @@ u.delete = V.prototype.delete = function(a) { (b = this.index[b]) && b.delete(a) && this.size--; }; u.clear = V.prototype.clear = function() { - this.index = J(); + this.index = I(); this.h = []; this.size = 0; }; @@ -1502,7 +1502,7 @@ u.values = V.prototype.values = function db() { f.h = 0; break; } - d = x(c.h[b].values()); + d = y(c.h[b].values()); e = d.next(); case 5: if (e.done) { @@ -1511,7 +1511,7 @@ u.values = V.prototype.values = function db() { break; } g = e.value; - return E(f, g, 6); + return D(f, g, 6); case 6: e = d.next(), f.h = 5; } @@ -1528,7 +1528,7 @@ u.keys = V.prototype.keys = function eb() { f.h = 0; break; } - d = x(c.h[b].keys()); + d = y(c.h[b].keys()); e = d.next(); case 5: if (e.done) { @@ -1537,7 +1537,7 @@ u.keys = V.prototype.keys = function eb() { break; } g = e.value; - return E(f, g, 6); + return D(f, g, 6); case 6: e = d.next(), f.h = 5; } @@ -1554,7 +1554,7 @@ u.entries = V.prototype.entries = function fb() { f.h = 0; break; } - d = x(c.h[b].entries()); + d = y(c.h[b].entries()); e = d.next(); case 5: if (e.done) { @@ -1563,7 +1563,7 @@ u.entries = V.prototype.entries = function fb() { break; } g = e.value; - return E(f, g, 6); + return D(f, g, 6); case 6: e = d.next(), f.h = 5; } @@ -1583,7 +1583,7 @@ function bb() { throw Error("The keystore is limited to 32 for EcmaScript5"); } ;W.prototype.add = function(a, b, c) { - L(a) && (b = a, a = ya(b, this.key)); + K(a) && (b = a, a = ya(b, this.key)); if (b && (a || 0 === a)) { if (!c && this.reg.has(a)) { return this.update(a, b); @@ -1596,7 +1596,7 @@ function bb() { } else { var f = e.R; if (!f || f(b)) { - e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), gb(b, e, this.S, 0, g, a, e[0], c); + e.constructor === String ? e = ["" + e] : J(e) && (e = [e]), gb(b, e, this.S, 0, g, a, e[0], c); } } } @@ -1605,7 +1605,7 @@ function bb() { f = this.L[d]; var h = this.aa[d]; g = this.tag.get(h); - e = J(); + e = I(); if ("function" === typeof f) { if (f = f(b), !f) { continue; @@ -1619,7 +1619,7 @@ function bb() { f = ya(b, f); } if (g && f) { - for (K(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { + for (J(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { var l = f[h]; if (!e[l]) { e[l] = 1; @@ -1629,7 +1629,7 @@ function bb() { if (k.length === Math.pow(2, 31) - 1) { m = new T(k); if (this.fastupdate) { - for (var n = x(this.reg.values()), p = n.next(); !p.done; p = n.next()) { + for (var n = y(this.reg.values()), p = n.next(); !p.done; p = n.next()) { p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); } } @@ -1647,7 +1647,7 @@ function bb() { } if (this.store && (!c || !this.store.has(a))) { if (this.I) { - var q = J(); + var q = I(); for (c = 0; c < this.I.length; c++) { if (d = this.I[c], g = d.R, !g || g(b)) { g = void 0; @@ -1657,7 +1657,7 @@ function bb() { continue; } d = [d.ja]; - } else if (K(d) || d.constructor === String) { + } else if (J(d) || d.constructor === String) { q[d] = b[d]; continue; } @@ -1681,7 +1681,7 @@ function hb(a, b, c, d, e, g) { hb(a, b, c, d, e); } } else { - b = b[e] || (b[e] = J()), e = c[++d], hb(a, b, c, d, e); + b = b[e] || (b[e] = I()), e = c[++d], hb(a, b, c, d, e); } } } @@ -1713,7 +1713,7 @@ function gb(a, b, c, d, e, g, f, h) { } ;function ib(a, b, c, d, e, g, f) { var h = a.length, k = []; - var l = J(); + var l = I(); for (var m = 0, n = void 0, p, q; m < b; m++) { for (var t = 0; t < h; t++) { var w = a[t]; @@ -1723,12 +1723,12 @@ function gb(a, b, c, d, e, g, f, h) { (w = l[p]) ? l[p]++ : (w = 0, l[p] = 1); q = k[w] || (k[w] = []); if (!f) { - var A = m + (t || !e ? 0 : g || 0); - q = q[A] || (q[A] = []); + var z = m + (t || !e ? 0 : g || 0); + q = q[z] || (q[z] = []); } q.push(p); if (f && c && w === h - 1 && q.length - d === c) { - return q; + return d ? q.slice(d) : q; } } } @@ -1770,7 +1770,7 @@ function gb(a, b, c, d, e, g, f, h) { return k; } function jb(a, b, c, d, e) { - var g = [], f = J(), h = a.length, k; + var g = [], f = I(), h = a.length, k; if (d) { for (e = h - 1; 0 <= e; e--) { if (k = (d = a[e]) && d.length) { @@ -1813,7 +1813,7 @@ function jb(a, b, c, d, e) { return g; } function kb(a, b, c) { - for (var d = J(), e = [], g = 0, f; g < b.length; g++) { + for (var d = I(), e = [], g = 0, f; g < b.length; g++) { f = b[g]; for (var h = 0; h < f.length; h++) { d[f[h]] = 1; @@ -1991,7 +1991,7 @@ function pb(a, b, c, d, e, g, f) { return g ? this.resolve(c, d, e) : this; } function qb(a, b, c, d, e) { - for (var g = [], f = J(), h = 0, k = 0, l; k < a.length; k++) { + for (var g = [], f = I(), h = 0, k = 0, l; k < a.length; k++) { if (l = a[k]) { h < l.length && (h = l.length); for (var m = 0, n; m < l.length; m++) { @@ -2130,9 +2130,9 @@ Y.prototype.resolve = function(a, b, c) { this.result = this.index = null; return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), lb.call(e, d, a || 100, b, c)) : d; }; -J(); +I(); W.prototype.search = function(a, b, c, d) { - c || (!b && L(a) ? (c = a, a = "") : L(b) && (c = b, b = 0)); + c || (!b && K(a) ? (c = a, a = "") : K(b) && (c = b, b = 0)); var e = [], g = [], f, h = 0, k = !0; if (c) { c.constructor === Array && (c = {index:c}); @@ -2145,7 +2145,7 @@ W.prototype.search = function(a, b, c, d) { k = !1 !== c.resolve; if (!k && !l) { if (n = n || this.field) { - K(n) ? l = n : (n.constructor === Array && 1 === n.length && (n = n[0]), l = n.field || n.index); + J(n) ? l = n : (n.constructor === Array && 1 === n.length && (n = n[0]), l = n.field || n.index); } if (!l) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); @@ -2158,30 +2158,30 @@ W.prototype.search = function(a, b, c, d) { b || (b = 100); if (p && (!this.db || !d)) { p.constructor !== Array && (p = [p]); - for (var r = [], A = 0, z = void 0; A < p.length; A++) { - z = p[A]; - if (K(z)) { + for (var r = [], z = 0, A = void 0; z < p.length; z++) { + A = p[z]; + if (J(A)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (z.field && z.tag) { - var v = z.tag; + if (A.field && A.tag) { + var v = A.tag; if (v.constructor === Array) { - for (var y = 0; y < v.length; y++) { - r.push(z.field, v[y]); + for (var x = 0; x < v.length; x++) { + r.push(A.field, v[x]); } } else { - r.push(z.field, v); + r.push(A.field, v); } } else { - v = Object.keys(z); - y = 0; - for (var D = void 0, H = void 0; y < v.length; y++) { - if (D = v[y], H = z[D], H.constructor === Array) { - for (var I = 0; I < H.length; I++) { - r.push(D, H[I]); + v = Object.keys(A); + x = 0; + for (var E = void 0, N = void 0; x < v.length; x++) { + if (E = v[x], N = A[E], N.constructor === Array) { + for (var H = 0; H < N.length; H++) { + r.push(E, N[H]); } } else { - r.push(D, H); + r.push(E, N); } } } @@ -2220,83 +2220,83 @@ W.prototype.search = function(a, b, c, d) { } n || (n = this.field); r = !d && (this.worker || this.db) && []; - A = 0; - for (y = z = v = void 0; A < n.length; A++) { - if (z = n[A], !this.db || !this.tag || this.J[A]) { + z = 0; + for (x = A = v = void 0; z < n.length; z++) { + if (A = n[z], !this.db || !this.tag || this.J[z]) { v = void 0; - K(z) || (v = z, z = v.field, a = v.query || a, b = v.limit || b, w = v.offset || w, q = v.suggest || q, f = this.store && (v.enrich || f)); + J(A) || (v = A, A = v.field, a = v.query || a, b = v.limit || b, w = v.offset || w, q = v.suggest || q, f = this.store && (v.enrich || f)); if (d) { - v = d[A]; + v = d[z]; } else { - y = v || c; - v = this.index.get(z); + x = v || c; + v = this.index.get(A); if (p) { if (this.db) { - y.tag = p; - var Ka = v.db.support_tag_search; - y.field = n; + x.tag = p; + var La = v.db.support_tag_search; + x.field = n; } - Ka || (y.enrich = !1); + La || (x.enrich = !1); } if (r) { - r[A] = v.search(a, b, y); - y && f && (y.enrich = f); + r[z] = v.search(a, b, x); + x && f && (x.enrich = f); continue; } else { - v = v.search(a, b, y), y && f && (y.enrich = f); + v = v.search(a, b, x), x && f && (x.enrich = f); } } - y = v && (k ? v.length : v.result.length); - if (p && y) { - D = []; - H = 0; + x = v && (k ? v.length : v.result.length); + if (p && x) { + E = []; + N = 0; if (this.db && d) { - if (!Ka) { - for (I = n.length; I < d.length; I++) { - var M = d[I]; - if (M && M.length) { - H++, D.push(M); + if (!La) { + for (H = n.length; H < d.length; H++) { + var L = d[H]; + if (L && L.length) { + N++, E.push(L); } else if (!q) { return k ? e : new Y(e); } } } } else { - I = 0; - for (var Yb = M = void 0; I < p.length; I += 2) { - M = this.tag.get(p[I]); - if (!M) { - if (console.warn("Tag '" + p[I] + ":" + p[I + 1] + "' will be skipped because there is no field '" + p[I] + "'."), q) { + H = 0; + for (var Xb = L = void 0; H < p.length; H += 2) { + L = this.tag.get(p[H]); + if (!L) { + if (console.warn("Tag '" + p[H] + ":" + p[H + 1] + "' will be skipped because there is no field '" + p[H] + "'."), q) { continue; } else { return k ? e : new Y(e); } } - if (Yb = (M = M && M.get(p[I + 1])) && M.length) { - H++, D.push(M); + if (Xb = (L = L && L.get(p[H + 1])) && L.length) { + N++, E.push(L); } else if (!q) { return k ? e : new Y(e); } } } - if (H) { - v = kb(v, D, k); - y = v.length; - if (!y && !q) { + if (N) { + v = kb(v, E, k); + x = v.length; + if (!x && !q) { return k ? v : new Y(v); } - H--; + N--; } } - if (y) { - g[h] = z, e.push(v), h++; + if (x) { + g[h] = A, e.push(v), h++; } else if (1 === n.length) { return k ? e : new Y(e); } } } if (r) { - if (this.db && p && p.length && !Ka) { + if (this.db && p && p.length && !La) { for (f = 0; f < p.length; f += 2) { g = this.index.get(p[f]); if (!g) { @@ -2309,9 +2309,9 @@ W.prototype.search = function(a, b, c, d) { r.push(g.db.tag(p[f + 1], b, w, !1)); } } - var Zb = this; + var Yb = this; return Promise.all(r).then(function(Q) { - return Q.length ? Zb.search(a, b, c, Q) : Q; + return Q.length ? Yb.search(a, b, c, Q) : Q; }); } if (!h) { @@ -2330,12 +2330,12 @@ W.prototype.search = function(a, b, c, d) { e[w] = {field:g[w], result:q}; } if (f && this.db && r.length) { - var La = this; + var Ma = this; return Promise.all(r).then(function(Q) { for (var R = 0; R < Q.length; R++) { e[R].result = Q[R]; } - return m ? ub(e, b) : t ? vb(e, a, La.index, La.field, La.J, t) : e; + return m ? ub(e, b) : t ? vb(e, a, Ma.index, Ma.field, Ma.J, t) : e; }); } return m ? ub(e, b) : t ? vb(e, a, this.index, this.field, this.J, t) : e; @@ -2350,28 +2350,29 @@ function vb(a, b, c, d, e, g) { m = e[d.indexOf(m)]; n !== f && (f = n, h = f.encode(b)); for (n = 0; n < p.length; n++) { - var q = "", t = ya(p[n].doc, m), w = f.encode(t); - t = t.split(f.split); - for (var r = 0, A, z; r < w.length; r++) { - if (A = w[r], z = t[r], A && z) { - for (var v = void 0, y = 0, D; y < h.length; y++) { - if (D = h[y], "strict" === k) { - if (A === D) { - q += (q ? " " : "") + g.replace("$1", z); - v = !0; + for (var q = "", t = ya(p[n].doc, m).split(/\s+/), w = 0, r, z; w < t.length; w++) { + r = t[w]; + z = f.encode(r).join(" "); + var A = void 0; + if (z && r) { + for (var v = 0, x; v < h.length; v++) { + if (x = h[v], "strict" === k) { + if (z === x) { + q += (q ? " " : "") + g.replace("$1", r); + A = !0; break; } } else { - var H = A.indexOf(D); - if (-1 < H) { - q += (q ? " " : "") + z.substring(0, H) + g.replace("$1", z.substring(H, D.length)) + z.substring(H + D.length); - v = !0; + var E = z.indexOf(x); + if (-1 < E) { + q += (q ? " " : "") + r.substring(0, E) + g.replace("$1", r.substring(E, x.length)) + r.substring(E + x.length); + A = !0; break; } } } - v || (q += (q ? " " : "") + t[r]); } + A || (q += (q ? " " : "") + t[w]); } p[n].highlight = q; } @@ -2379,7 +2380,7 @@ function vb(a, b, c, d, e, g) { return a; } function ub(a, b) { - for (var c = [], d = J(), e = 0, g, f; e < a.length; e++) { + for (var c = [], d = I(), e = 0, g, f; e < a.length; e++) { g = a[e]; f = g.result; for (var h = 0, k, l, m; h < f.length; h++) { @@ -2459,14 +2460,14 @@ function X(a) { if (this.worker) { this.fastupdate = !1; a = []; - c = x(this.index.values()); + c = y(this.index.values()); for (b = c.next(); !b.done; b = c.next()) { b = b.value, b.then && a.push(b); } if (a.length) { var g = this; return Promise.all(a).then(function(f) { - for (var h = 0, k = x(g.index.entries()), l = k.next(); !l.done; l = k.next()) { + for (var h = 0, k = y(g.index.entries()), l = k.next(); !l.done; l = k.next()) { l = l.value; var m = l[0]; l[1].then && g.index.set(m, f[h++]); @@ -2514,29 +2515,29 @@ u.commit = function(a, b) { return ta(function(h) { if (1 == h.h) { d = []; - e = x(c.index.values()); + e = y(c.index.values()); for (g = e.next(); !g.done; g = e.next()) { f = g.value, d.push(f.commit(a, b)); } - return E(h, Promise.all(d), 2); + return D(h, Promise.all(d), 2); } c.reg.clear(); h.h = 0; }); }; u.destroy = function() { - for (var a = [], b = x(this.index.values()), c = b.next(); !c.done; c = b.next()) { + for (var a = [], b = y(this.index.values()), c = b.next(); !c.done; c = b.next()) { a.push(c.value.destroy()); } return Promise.all(a); }; function yb(a, b) { var c = new Map(), d = b.index || b.field || b; - K(d) && (d = [d]); + J(d) && (d = [d]); for (var e = 0, g, f = void 0; e < d.length; e++) { g = d[e]; - K(g) || (f = g, g = g.field); - f = L(f) ? Object.assign({}, a, f) : a; + J(g) || (f = g, g = g.field); + f = K(f) ? Object.assign({}, a, f) : a; if (this.worker) { var h = new Ra(f); c.set(g, h); @@ -2546,7 +2547,7 @@ function yb(a, b) { this.field[e] = g; } if (this.I) { - for (a = b.store, K(a) && (a = [a]), b = 0; b < a.length; b++) { + for (a = b.store, J(a) && (a = [a]), b = 0; b < a.length; b++) { d = a[b], e = d.field || d, d.custom ? (this.I[b] = d.custom, d.custom.ja = e) : (this.I[b] = wb(e, this.S), d.filter && ("string" === typeof this.I[b] && (this.I[b] = new String(this.I[b])), this.I[b].R = d.filter)); } } @@ -2566,15 +2567,15 @@ u.update = function(a, b) { return this.remove(a).add(a, b); }; u.remove = function(a) { - L(a) && (a = ya(a, this.key)); - for (var b = x(this.index.values()), c = b.next(); !c.done; c = b.next()) { + K(a) && (a = ya(a, this.key)); + for (var b = y(this.index.values()), c = b.next(); !c.done; c = b.next()) { c.value.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { - for (b = x(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = y(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c = c.value; - for (var d = x(c), e = d.next(); !e.done; e = d.next()) { + for (var d = y(c), e = d.next(); !e.done; e = d.next()) { var g = e.value; e = g[0]; g = g[1]; @@ -2590,11 +2591,11 @@ u.remove = function(a) { return this; }; u.clear = function() { - for (var a = [], b = x(this.index.values()), c = b.next(); !c.done; c = b.next()) { + for (var a = [], b = y(this.index.values()), c = b.next(); !c.done; c = b.next()) { c = c.value.clear(), c.then && a.push(c); } if (this.tag) { - for (b = x(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = y(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c.value.clear(); } } @@ -2606,7 +2607,7 @@ u.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; u.cleanup = function() { - for (var a = x(this.index.values()), b = a.next(); !b.done; b = a.next()) { + for (var a = y(this.index.values()), b = a.next(); !b.done; b = a.next()) { b.value.cleanup(); } return this; @@ -2678,7 +2679,7 @@ u.import = function(a, b) { } if (this.worker) { b = []; - d = x(this.index.values()); + d = y(this.index.values()); for (c = d.next(); !c.done; c = d.next()) { b.push(c.value.import(a)); } @@ -2726,7 +2727,7 @@ xb.prototype.get = function(a) { return b; }; xb.prototype.remove = function(a) { - for (var b = x(this.cache), c = b.next(); !c.done; c = b.next()) { + for (var b = y(this.cache), c = b.next(); !c.done; c = b.next()) { c = c.value; var d = c[0]; c[1].includes(a) && this.cache.delete(d); @@ -2748,7 +2749,54 @@ var Gb = {na:Ab, ma:Bb, oa:Bb, LatinBalance:{dedupe:!0, mapper:Cb}, LatinAdvance a[b] = d; } }}, LatinExact:Ab, LatinDefault:Bb, LatinSimple:Bb}; -var Hb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +P.prototype.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; d < c.length; d++) { + if (e = c[d]) { + if (2 > e.length) { + e.pop(); + } else { + var g = e.indexOf(a); + g === c.length - 1 ? e.pop() : e.splice(g, 1); + } + } + } + } else { + Hb(this.map, a), this.depth && Hb(this.ctx, a); + } + b || this.reg.delete(a); + } + this.db && (this.commit_task.push({del:a}), this.ca && Ib(this)); + this.cache && this.cache.remove(a); + return this; +}; +function Hb(a, b) { + var c = 0, d = "undefined" === typeof b; + if (a.constructor === Array) { + for (var e = 0, g = void 0, f; e < a.length; e++) { + if ((g = a[e]) && g.length) { + if (d) { + c++; + } else { + if (f = g.indexOf(b), 0 <= f) { + 1 < g.length ? (g.splice(f, 1), c++) : delete a[e]; + break; + } else { + c++; + } + } + } + } + } else { + for (d = y(a.entries()), e = d.next(); !e.done; e = d.next()) { + g = e.value, e = g[0], (g = Hb(g[1], b)) ? c += g : a.delete(e); + } + } + return c; +} +;var Jb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; P.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { if (!d && !c && this.reg.has(a)) { @@ -2756,17 +2804,17 @@ P.prototype.add = function(a, b, c, d) { } b = this.encoder.encode(b); if (d = b.length) { - for (var e = J(), g = J(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { + for (var e = I(), g = I(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { var l = b[this.rtl ? d - 1 - k : k], m = l.length; if (m && (f || !g[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : Ib(h, d, k), p = ""; + var n = this.score ? this.score(b, l, k, null, 0) : Kb(h, d, k), p = ""; switch(this.tokenize) { case "full": if (2 < m) { n = 0; for (var q; n < m; n++) { for (var t = m; t > n; t--) { - p = l.substring(n, t), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, k, p, q) : Ib(h, d, k, m, q), Jb(this, g, p, q, a, c); + p = l.substring(n, t), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, k, p, q) : Kb(h, d, k, m, q), Lb(this, g, p, q, a, c); } } break; @@ -2775,24 +2823,24 @@ P.prototype.add = function(a, b, c, d) { case "reverse": if (1 < m) { for (t = m - 1; 0 < t; t--) { - p = l[this.rtl ? m - 1 - t : t] + p, q = this.score ? this.score(b, l, k, p, t) : Ib(h, d, k, m, t), Jb(this, g, p, q, a, c); + p = l[this.rtl ? m - 1 - t : t] + p, q = this.score ? this.score(b, l, k, p, t) : Kb(h, d, k, m, t), Lb(this, g, p, q, a, c); } p = ""; } case "forward": if (1 < m) { for (t = 0; t < m; t++) { - p += l[this.rtl ? m - 1 - t : t], Jb(this, g, p, n, a, c); + p += l[this.rtl ? m - 1 - t : t], Lb(this, g, p, n, a, c); } break; } default: - if (Jb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { - for (m = J(), p = this.da, n = l, t = Math.min(f + 1, this.rtl ? k + 1 : d - k), q = m[n] = 1; q < t; q++) { + if (Lb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { + for (m = I(), p = this.da, n = l, t = Math.min(f + 1, this.rtl ? k + 1 : d - k), q = m[n] = 1; q < t; q++) { if ((l = b[this.rtl ? d - 1 - k - q : k + q]) && !m[l]) { m[l] = 1; - var w = this.score ? this.score(b, n, k, l, q - 1) : Ib(p + (d / 2 > p ? 0 : 1), d, k, t - 1, q - 1), r = this.bidirectional && l > n; - Jb(this, e, r ? n : l, w, a, c, r ? l : n); + var w = this.score ? this.score(b, n, k, l, q - 1) : Kb(p + (d / 2 > p ? 0 : 1), d, k, t - 1, q - 1), r = this.bidirectional && l > n; + Lb(this, e, r ? n : l, w, a, c, r ? l : n); } } } @@ -2804,17 +2852,17 @@ P.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.ca && Kb(this)); + this.db && (b || this.commit_task.push({del:a}), this.ca && Ib(this)); return this; }; -function Jb(a, b, c, d, e, g, f) { +function Lb(a, b, c, d, e, g, f) { var h = f ? a.ctx : a.map, k; if (!b[c] || f && !(k = b[c])[f]) { - if (f ? (b = k || (b[c] = J()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { + if (f ? (b = k || (b[c] = I()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { if (h.length === Math.pow(2, 31) - 1) { b = new T(h); if (a.fastupdate) { - for (c = x(a.reg.values()), g = c.next(); !g.done; g = c.next()) { + for (c = y(a.reg.values()), g = c.next(); !g.done; g = c.next()) { g = g.value, g.includes(h) && (g[g.indexOf(h)] = b); } } @@ -2825,11 +2873,11 @@ function Jb(a, b, c, d, e, g, f) { } } } -function Ib(a, b, c, d, e) { +function Kb(a, b, c, d, e) { return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; } ;P.prototype.search = function(a, b, c) { - c || (!b && L(a) ? (c = a, a = "") : L(b) && (c = b, b = 0)); + c || (!b && K(a) ? (c = a, a = "") : K(b) && (c = b, b = 0)); var d = [], e = 0, g; if (c) { a = c.query || a; @@ -2848,13 +2896,13 @@ function Ib(a, b, c, d, e) { var q = p.length; b = b || (g ? 100 : 0); if (1 === q) { - return Lb.call(this, p[0], "", b, e, g, k, n); + return Mb.call(this, p[0], "", b, e, g, k, n); } f = this.depth && !1 !== f; if (2 === q && f && !h) { - return Lb.call(this, p[1], p[0], b, e, g, k, n); + return Mb.call(this, p[1], p[0], b, e, g, k, n); } - var t = J(), w = 0; + var t = I(), w = 0; if (1 < q && f) { var r = p[0]; w = 1; @@ -2864,40 +2912,40 @@ function Ib(a, b, c, d, e) { if (this.db.search && (a = this.db.search(this, p, b, e, h, g, k, n), !1 !== a)) { return a; } - var A = this; + var z = this; return function() { - var z, v; - return ta(function(y) { - switch(y.h) { + var A, v; + return ta(function(x) { + switch(x.h) { case 1: - v = z = void 0; + v = A = void 0; case 2: if (!(w < q)) { - y.h = 4; + x.h = 4; break; } v = p[w]; if (!v || t[v]) { - y.h = 5; + x.h = 5; break; } t[v] = 1; - return E(y, Mb(A, v, r, 0, 0, !1, !1), 6); + return D(x, Nb(z, v, r, 0, 0, !1, !1), 6); case 6: - z = y.D; - if (z = Nb(z, d, h, m)) { - d = z; - y.h = 4; + A = x.D; + if (A = Ob(A, d, h, m)) { + d = A; + x.h = 4; break; } - r && (h && z && d.length || (r = v)); + r && (h && A && d.length || (r = v)); case 5: - h && r && w === q - 1 && !d.length && (m = A.resolution, r = "", w = -1, t = J()); + h && r && w === q - 1 && !d.length && (m = z.resolution, r = "", w = -1, t = I()); w++; - y.h = 2; + x.h = 2; break; case 4: - return y.return(Ob(d, m, b, e, h, l, g)); + return x.return(Pb(d, m, b, e, h, l, g)); } }); }(); @@ -2905,18 +2953,18 @@ function Ib(a, b, c, d, e) { for (c = a = void 0; w < q; w++) { if ((c = p[w]) && !t[c]) { t[c] = 1; - a = Mb(this, c, r, 0, 0, !1, !1); - if (a = Nb(a, d, h, m)) { + a = Nb(this, c, r, 0, 0, !1, !1); + if (a = Ob(a, d, h, m)) { d = a; break; } r && (h && a && d.length || (r = c)); } - h && r && w === q - 1 && !d.length && (m = this.resolution, r = "", w = -1, t = J()); + h && r && w === q - 1 && !d.length && (m = this.resolution, r = "", w = -1, t = I()); } - return Ob(d, m, b, e, h, l, g); + return Pb(d, m, b, e, h, l, g); }; -function Ob(a, b, c, d, e, g, f) { +function Pb(a, b, c, d, e, g, f) { var h = a.length, k = a; if (1 < h) { k = ib(a, b, c, d, e, g, f); @@ -2925,13 +2973,13 @@ function Ob(a, b, c, d, e, g, f) { } return f ? k : new Y(k); } -function Lb(a, b, c, d, e, g, f) { - a = Mb(this, a, b, c, d, e, g, f); +function Mb(a, b, c, d, e, g, f) { + a = Nb(this, a, b, c, d, e, g, f); return this.db ? a.then(function(h) { return e ? h || [] : new Y(h); }) : a && a.length ? e ? lb.call(this, a, c, d) : new Y(a) : e ? [] : new Y(); } -function Nb(a, b, c, d) { +function Ob(a, b, c, d) { var e = []; if (a && a.length) { if (a.length <= d) { @@ -2952,7 +3000,7 @@ function Nb(a, b, c, d) { return e; } } -function Mb(a, b, c, d, e, g, f, h) { +function Nb(a, b, c, d, e, g, f, h) { var k; c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); if (a.db) { @@ -2961,61 +3009,18 @@ function Mb(a, b, c, d, e, g, f, h) { a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;P.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; d < c.length; d++) { - if (e = c[d]) { - if (2 > e.length) { - e.pop(); - } else { - var g = e.indexOf(a); - g === c.length - 1 ? e.pop() : e.splice(g, 1); - } - } - } - } else { - Pb(this.map, a), this.depth && Pb(this.ctx, a); - } - b || this.reg.delete(a); - } - this.db && (this.commit_task.push({del:a}), this.ca && Kb(this)); - this.cache && this.cache.remove(a); - return this; -}; -function Pb(a, b) { - var c = 0; - if (a.constructor === Array) { - for (var d = 0, e = void 0, g; d < a.length; d++) { - if ((e = a[d]) && e.length) { - if (g = e.indexOf(b), 0 <= g) { - 1 < e.length ? (e.splice(g, 1), c++) : delete a[d]; - break; - } else { - c++; - } - } - } - } else { - for (d = x(a.entries()), e = d.next(); !e.done; e = d.next()) { - g = e.value, e = g[0], (g = Pb(g[1], b)) ? c += g : a.delete(e); - } - } - return c; -} ;function P(a, b) { if (!this || this.constructor !== P) { return new P(a); } if (a) { - var c = K(a) ? a : a.preset; - c && (Hb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Hb[c], a)); + var c = J(a) ? a : a.preset; + c && (Jb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Jb[c], a)); } else { a = {}; } c = a.context; - var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Gb[a.encoder] : a.encode || a.encoder || {}; + var d = !0 === c ? {depth:1} : c || {}, e = J(a.encoder) ? Gb[a.encoder] : a.encode || a.encoder || {}; this.encoder = e.encode ? e : "object" === typeof e ? new Fa(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = c = (c = a.tokenize) && "default" !== c && "exact" !== c && c || "strict"; @@ -3053,7 +3058,7 @@ u.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Kb(a) { +function Ib(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -3079,27 +3084,12 @@ u.update = function(a, b) { return c.add(a, b); }) : this.add(a, b); }; -function Qb(a) { - var b = 0; - if (a.constructor === Array) { - for (var c = 0, d = void 0; c < a.length; c++) { - (d = a[c]) && (b += d.length); - } - } else { - for (c = x(a.entries()), d = c.next(); !d.done; d = c.next()) { - var e = d.value; - d = e[0]; - (e = Qb(e[1])) ? b += e : a.delete(d); - } - } - return b; -} u.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Qb(this.map); - this.depth && Qb(this.ctx); + Hb(this.map); + this.depth && Hb(this.ctx); return this; }; u.searchCache = zb; @@ -3148,14 +3138,14 @@ u.serialize = function(a) { var b = "", c = "", d = ""; if (this.reg.size) { var e; - c = x(this.reg.keys()); + c = y(this.reg.keys()); for (var g = c.next(); !g.done; g = c.next()) { g = g.value, e || (e = typeof g), b += (b ? "," : "") + ("string" === e ? '"' + g + '"' : g); } b = "index.reg=new Set([" + b + "]);"; c = $a(this.map, e); c = "index.map=new Map([" + c + "]);"; - g = x(this.ctx.entries()); + g = y(this.ctx.entries()); for (var f = g.next(); !f.done; f = g.next()) { var h = f.value; f = h[0]; @@ -3169,11 +3159,11 @@ u.serialize = function(a) { return a ? "function inject(index){" + b + c + d + "}" : b + c + d; }; Ia(P.prototype); -var Rb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Sb = ["map", "ctx", "tag", "reg", "cfg"], Tb = J(); -function Ub(a, b) { +var Qb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Rb = ["map", "ctx", "tag", "reg", "cfg"], Sb = I(); +function Tb(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Ub(a, b); + return new Tb(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3184,7 +3174,7 @@ function Ub(a, b) { this.db = null; this.h = {}; } -u = Ub.prototype; +u = Tb.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -3198,14 +3188,14 @@ u.open = function() { } var a = this; navigator.storage && navigator.storage.persist(); - Tb[a.id] || (Tb[a.id] = []); - Tb[a.id].push(a.field); - var b = Rb.open(a.id, 1); + Sb[a.id] || (Sb[a.id] = []); + Sb[a.id].push(a.field); + var b = Qb.open(a.id, 1); b.onupgradeneeded = function() { - for (var c = a.db = this.result, d = 0, e; d < Sb.length; d++) { - e = Sb[d]; - for (var g = 0, f; g < Tb[a.id].length; g++) { - f = Tb[a.id][g], c.objectStoreNames.contains(e + ("reg" !== e ? f ? ":" + f : "" : "")) || c.createObjectStore(e + ("reg" !== e ? f ? ":" + f : "" : "")); + for (var c = a.db = this.result, d = 0, e; d < Rb.length; d++) { + e = Rb[d]; + for (var g = 0, f; g < Sb[a.id].length; g++) { + f = Sb[a.id][g], c.objectStoreNames.contains(e + ("reg" !== e ? f ? ":" + f : "" : "")) || c.createObjectStore(e + ("reg" !== e ? f ? ":" + f : "" : "")); } } }; @@ -3221,14 +3211,14 @@ u.close = function() { this.db = null; }; u.destroy = function() { - var a = Rb.deleteDatabase(this.id); + var a = Qb.deleteDatabase(this.id); return Z(a); }; u.clear = function() { - for (var a = [], b = 0, c; b < Sb.length; b++) { - c = Sb[b]; - for (var d = 0, e; d < Tb[this.id].length; d++) { - e = Tb[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); + for (var a = [], b = 0, c; b < Rb.length; b++) { + c = Rb[b]; + for (var d = 0, e; d < Sb[this.id].length; d++) { + e = Sb[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); } } b = this.db.transaction(a, "readwrite"); @@ -3332,7 +3322,7 @@ u.commit = function(a, b, c) { switch(h.h) { case 1: if (b) { - return E(h, d.clear(), 12); + return D(h, d.clear(), 12); } e = a.commit_task; a.commit_task = []; @@ -3349,7 +3339,7 @@ u.commit = function(a, b, c) { h.h = 5; break; } - return E(h, d.clear(), 8); + return D(h, d.clear(), 8); case 8: b = !0; h.h = 6; @@ -3368,7 +3358,7 @@ u.commit = function(a, b, c) { h.h = 10; break; } - return E(h, d.remove(e), 11); + return D(h, d.remove(e), 11); case 11: case 10: h.h = 3; @@ -3376,20 +3366,20 @@ u.commit = function(a, b, c) { case 12: a.commit_task = []; case 3: - return a.reg.size ? E(h, d.transaction("map", "readwrite", function(k) { - for (var l = x(a.map), m = l.next(), n = {}; !m.done; n = {O:void 0, Y:void 0}, m = l.next()) { + return a.reg.size ? D(h, d.transaction("map", "readwrite", function(k) { + for (var l = y(a.map), m = l.next(), n = {}; !m.done; n = {O:void 0, Y:void 0}, m = l.next()) { m = m.value, n.Y = m[0], n.O = m[1], n.O.length && (b ? k.put(n.O, n.Y) : k.get(n.Y).onsuccess = function(p) { return function() { var q = this.result, t; if (q && q.length) { - for (var w = Math.max(q.length, p.O.length), r = 0, A; r < w; r++) { - if ((A = p.O[r]) && A.length) { + for (var w = Math.max(q.length, p.O.length), r = 0, z; r < w; r++) { + if ((z = p.O[r]) && z.length) { if ((t = q[r]) && t.length) { - for (var z = 0; z < A.length; z++) { - t.push(A[z]); + for (var A = 0; A < z.length; A++) { + t.push(z[A]); } } else { - q[r] = A; + q[r] = z; } t = 1; } @@ -3403,32 +3393,32 @@ u.commit = function(a, b, c) { } }), 13) : h.return(); case 13: - return E(h, d.transaction("ctx", "readwrite", function(k) { - for (var l = x(a.ctx), m = l.next(), n = {}; !m.done; n = {V:void 0}, m = l.next()) { + return D(h, d.transaction("ctx", "readwrite", function(k) { + for (var l = y(a.ctx), m = l.next(), n = {}; !m.done; n = {V:void 0}, m = l.next()) { m = m.value; n.V = m[0]; - m = x(m[1]); + m = y(m[1]); for (var p = m.next(), q = {}; !p.done; q = {P:void 0, Z:void 0}, p = m.next()) { p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? k.put(q.P, n.V + ":" + q.Z) : k.get(n.V + ":" + q.Z).onsuccess = function(t, w) { return function() { - var r = this.result, A; + var r = this.result, z; if (r && r.length) { - for (var z = Math.max(r.length, t.P.length), v = 0, y; v < z; v++) { - if ((y = t.P[v]) && y.length) { - if ((A = r[v]) && A.length) { - for (var D = 0; D < y.length; D++) { - A.push(y[D]); + for (var A = Math.max(r.length, t.P.length), v = 0, x; v < A; v++) { + if ((x = t.P[v]) && x.length) { + if ((z = r[v]) && z.length) { + for (var E = 0; E < x.length; E++) { + z.push(x[E]); } } else { - r[v] = y; + r[v] = x; } - A = 1; + z = 1; } } } else { - r = t.P, A = 1; + r = t.P, z = 1; } - A && k.put(r, w.V + ":" + t.Z); + z && k.put(r, w.V + ":" + t.Z); }; }(q, n)); } @@ -3436,8 +3426,8 @@ u.commit = function(a, b, c) { }), 14); case 14: if (a.store) { - return E(h, d.transaction("reg", "readwrite", function(k) { - for (var l = x(a.store), m = l.next(); !m.done; m = l.next()) { + return D(h, d.transaction("reg", "readwrite", function(k) { + for (var l = y(a.store), m = l.next(); !m.done; m = l.next()) { var n = m.value; m = n[0]; n = n[1]; @@ -3449,8 +3439,8 @@ u.commit = function(a, b, c) { h.h = 16; break; } - return E(h, d.transaction("reg", "readwrite", function(k) { - for (var l = x(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { + return D(h, d.transaction("reg", "readwrite", function(k) { + for (var l = y(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { k.put(1, m.value); } }), 16); @@ -3459,8 +3449,8 @@ u.commit = function(a, b, c) { h.h = 20; break; } - return E(h, d.transaction("tag", "readwrite", function(k) { - for (var l = x(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) { + return D(h, d.transaction("tag", "readwrite", function(k) { + for (var l = y(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) { m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (k.get(n.ba).onsuccess = function(p) { return function() { var q = this.result; @@ -3475,7 +3465,7 @@ u.commit = function(a, b, c) { } }); }; -function Vb(a, b, c) { +function Ub(a, b, c) { for (var d = a.value, e, g = 0, f = 0, h; f < d.length; f++) { if (h = c ? d : d[f]) { for (var k = 0, l; k < b.length; k++) { @@ -3502,17 +3492,17 @@ u.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Vb(c, a); + c && Ub(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Vb(c, a); + c && Ub(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Vb(c, a, !0); + c && Ub(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3531,8 +3521,8 @@ function Z(a, b) { a = null; }); } -;var Wb = {Index:P, Charset:Gb, Encoder:Fa, Document:W, Worker:Ra, Resolver:Y, IndexedDB:Ub, Language:{}}, Xb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, $b; -($b = Xb.define) && $b.amd ? $b([], function() { - return Wb; -}) : "object" === typeof Xb.exports ? Xb.exports = Wb : Xb.FlexSearch = Wb; +;var Vb = {Index:P, Charset:Gb, Encoder:Fa, Document:W, Worker:Ra, Resolver:Y, IndexedDB:Tb, Language:{}}, Wb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self, Zb; +(Zb = Wb.define) && Zb.amd ? Zb([], function() { + return Vb; +}) : "object" === typeof Wb.exports ? Wb.exports = Vb : Wb.FlexSearch = Vb; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 812a25c..2a502b4 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,14 +1,14 @@ /**! - * FlexSearch.js v0.8.147 (ES5) + * FlexSearch.js v0.8.149 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var u;function aa(a){var b=0;return function(){return bc&&(c=Math.max(c+e,0));c"a1a".split(c).length; this.numeric=G(a.numeric,e)}else{try{this.split=G(this.split,Aa)}catch(g){this.split=/\s+/}this.numeric=G(a.numeric,G(this.numeric,!0))}this.prepare=G(a.prepare,null,this.prepare);this.finalize=G(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:G(c&&new Set(c),null,this.filter);this.dedupe=G(a.dedupe,!1,this.dedupe);this.matcher=G((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=G((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=G((c=a.stemmer)&&new Map(c), -null,this.stemmer);this.replacer=G(a.replacer,null,this.replacer);this.minlength=G(a.minlength,1,this.minlength);this.maxlength=G(a.maxlength,0,this.maxlength);this.rtl=G(a.rtl,!1,this.rtl);if(this.cache=c=G(a.cache,!0,this.cache))this.D=null,this.T="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.H=this.G=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(a=x(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value;if(this.stemmer)for(a=x(this.stemmer.keys()), -b=a.next();!b.done;b=a.next())this.A+=(this.A?"|":"")+b.value;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&N(this);return this};u.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&N(this);return this}; -u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&N(this);return this}; -u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&N(this);return this}; -u.encode=function(a){var b=this;if(this.cache&&a.length<=this.G)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(N,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=Ea?a.normalize("NFKD").replace(Ea,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&M(this);return this}; +u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&M(this);return this}; +u.encode=function(a){var b=this;if(this.cache&&a.length<=this.G)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(M,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=Ea?a.normalize("NFKD").replace(Ea,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3=this.minlength&&("function"===typeof this.filter?!this.filter(f):this.filter.has(f))&&(f=""));if(f&&(this.mapper||this.dedupe&&1this.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};var Ga,Ha; -function Ia(a){var b,c,d,e,g,f;return ta(function(h){switch(h.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Ha=a.options||{};(e=a.factory)?(Function("return "+e)()(self),Ga=new self.FlexSearch.Index(Ha),delete self.FlexSearch):Ga=new O(Ha);postMessage({id:c});break;default:h.h=2;return}h.h=0;break;case 2:"export"===b&&(d[1]?(d[0]=Ha.export,d[2]=0,d[3]=1):d=null);if("import"===b){if(!d[0]){h.h=5;break}return E(h,Ha.import.call(Ga,d[0]),9)}g=d&&Ga[b].apply(Ga,d);if(!g||!g.then){h.h= -5;break}return E(h,g,7);case 7:g=h.D;h.h=5;break;case 9:f=h.D,Ga.import(d[0],f);case 5:postMessage("search"===b?{id:c,msg:g}:{id:c}),h.h=0}})};function Ja(a){Ma.call(a,"add");Ma.call(a,"append");Ma.call(a,"search");Ma.call(a,"update");Ma.call(a,"remove")}var Na,Oa,Pa;function Qa(){Na=Pa=0} -function Ma(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}Na?Pa||(Pa=Date.now()-Oa>=this.priority*this.priority*3):(Na=setTimeout(Qa,0),Oa=Date.now());if(Pa){var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var Ra=0; -function Sa(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=J();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Ra]=function(){k(e);1E9this.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function M(a){a.D=null;a.B.clear();a.C.clear()};var Ga,Ha; +function Ia(a){var b,c,d,e,g,f;return ta(function(h){switch(h.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Ha=a.options||{};(e=a.factory)?(Function("return "+e)()(self),Ga=new self.FlexSearch.Index(Ha),delete self.FlexSearch):Ga=new O(Ha);postMessage({id:c});break;default:h.h=2;return}h.h=0;break;case 2:"export"===b&&(d[1]?(d[0]=Ha.export,d[2]=0,d[3]=1):d=null);if("import"===b){if(!d[0]){h.h=5;break}return D(h,Ha.import.call(Ga,d[0]),9)}g=d&&Ga[b].apply(Ga,d);if(!g||!g.then){h.h= +5;break}return D(h,g,7);case 7:g=h.D;h.h=5;break;case 9:f=h.D,Ga.import(d[0],f);case 5:postMessage("search"===b?{id:c,msg:g}:{id:c}),h.h=0}})};function Ja(a){Ka.call(a,"add");Ka.call(a,"append");Ka.call(a,"search");Ka.call(a,"update");Ka.call(a,"remove")}var Na,Oa,Pa;function Qa(){Na=Pa=0} +function Ka(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}Na?Pa||(Pa=Date.now()-Oa>=this.priority*this.priority*3):(Na=setTimeout(Qa,0),Oa=Date.now());if(Pa){var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var Ra=0; +function Sa(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=I();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Ra]=function(){k(e);1E9=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} +function ab(a,b){var c="";a=y(a.entries());for(var d=a.next();!d.done;d=a.next()){var e=d.value;d=e[0];e=e[1];for(var g="",f=0,h;f=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} function S(a){if(!this||this.constructor!==S)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[]; -for(g=0;gd)d-=f.length;else{if(f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?W.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}cb&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?W.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1c||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+ +d)}else{e=[];for(g=0;gd)d-=f.length;else{if(f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?W.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}cb&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?W.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=kb(a,c,d,!1,this.h),d=0));return g?this.resolve(c,d,e):this};X.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var g=b.enrich&&c}}return a?(a=nb(this,"and",arguments),pb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; function pb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=jb(a,b,c,d,f,this.h,g),g?e?W.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};X.prototype.xor=function(){var a=nb(this,"xor",arguments);return qb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; function qb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=rb.call(this,a,c,d,g,this.h),g?e?W.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} -function rb(a,b,c,d,e){for(var g=[],f=J(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(var b=x(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};var Ab={normalize:!1,numeric:!1};var Bb={};var Cb=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Db=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Eb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Fb={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Gb={na:Ab,ma:Bb,oa:Bb,LatinBalance:{dedupe:!0,mapper:Cb},LatinAdvanced:{dedupe:!0,mapper:Cb,matcher:Db,replacer:Eb},LatinExtra:{dedupe:!0,mapper:Cb,replacer:Eb.concat([/(?!^)[aeo]/g,""]),matcher:Db},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;r--)p=l.substring(n,r),q=this.rtl?m-1-n:n,q=this.score?this.score(b,l,k,p,q):Ib(h,d,k,m,q),Jb(this,g,p, -q,a,c);break}case "bidirectional":case "reverse":if(1p?0:1),d,k,r-1,q-1),t=this.bidirectional&& -l>n;Jb(this,e,t?n:l,w,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ca&&Kb(this));return this}; -function Jb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=J()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new S(h);if(a.fastupdate)for(c=x(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function Ib(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Pb(this.map,a),this.depth&&Pb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Kb(this));this.cache&&this.cache.remove(a);return this}; -function Pb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Hb(this.map,a),this.depth&&Hb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Ib(this));this.cache&&this.cache.remove(a);return this}; +function Hb(a,b){var c=0,d="undefined"===typeof b;if(a.constructor===Array)for(var e=0,g=void 0,f;en;t--)p=l.substring(n,t),q=this.rtl?m-1-n:n,q=this.score?this.score(b,l,k,p,q):Kb(h,d,k,m,q),Lb(this,g,p, +q,a,c);break}case "bidirectional":case "reverse":if(1p?0:1),d,k,t-1,q-1),r=this.bidirectional&& +l>n;Lb(this,e,r?n:l,w,a,c,r?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ca&&Ib(this));return this}; +function Lb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=I()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new S(h);if(a.fastupdate)for(c=y(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +function Kb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function O(a,b){if(!this||this.constructor!==O)return new O(a);if(a){var c=J(a)?a:a.preset;c&&(a=Object.assign({},Jb[c],a))}else a={};c=a.context;var d=!0===c?{depth:1}:c||{},e=J(a.encoder)?Gb[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new Fa(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&d.depth||0;this.bidirectional=!1!==d.bidirectional;this.fastupdate=!!a.fastupdate; this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new T(c):new Map;this.ctx=c?new T(c):new Map;this.reg=b||(this.fastupdate?c?new T(c):new Map:c?new U(c):new Set);this.da=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new Y(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.ca=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}u=O.prototype; -u.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};u.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};u.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function Kb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} +u.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};u.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};u.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function Ib(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};u.update=function(a,b){var c=this,d=this.remove(a);return d&&d.then?d.then(function(){return c.add(a,b)}):this.add(a,b)}; -function Qb(a){var b=0;if(a.constructor===Array)for(var c=0,d=void 0;c=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length, p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d c.length) { + c.pop(); + } else { + const g = c.indexOf(a); + g === b.length - 1 ? c.pop() : c.splice(g, 1); + } + } + } + } else { + J(this.map, a), this.depth && J(this.ctx, a); + } + d || this.reg.delete(a); + } + return this; +}; +function J(a, d) { + let b = 0; + var f = "undefined" === typeof d; + if (a.constructor === Array) { + for (let c = 0, g, e; c < a.length; c++) { + if ((g = a[c]) && g.length) { + if (f) { + b++; + } else { + if (e = g.indexOf(d), 0 <= e) { + 1 < g.length ? (g.splice(e, 1), b++) : delete a[c]; + break; + } else { + b++; + } + } + } + } + } else { + for (let c of a.entries()) { + f = c[0]; + const g = J(c[1], d); + g ? b += g : a.delete(f); + } + } + return b; +} +;const K = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +I.prototype.add = function(a, d, b, f) { if (d && (a || 0 === a)) { if (!f && !b && this.reg.has(a)) { return this.update(a, d); } d = this.encoder.encode(d); if (f = d.length) { - const n = w(), m = w(), v = this.depth, C = this.resolution; + const n = w(), m = w(), v = this.depth, D = this.resolution; for (let p = 0; p < f; p++) { let l = d[this.rtl ? f - 1 - p : p]; var c = l.length; if (c && (v || !m[l])) { - var g = this.score ? this.score(d, l, p, null, 0) : K(C, f, p), e = ""; + var g = this.score ? this.score(d, l, p, null, 0) : L(D, f, p), e = ""; switch(this.tokenize) { case "full": if (2 < c) { @@ -286,8 +334,8 @@ J.prototype.add = function(a, d, b, f) { for (g = c; g > q; g--) { e = l.substring(q, g); t = this.rtl ? c - 1 - q : q; - var h = this.score ? this.score(d, l, p, e, t) : K(C, f, p, c, t); - L(this, m, e, h, a, b); + var h = this.score ? this.score(d, l, p, e, t) : L(D, f, p, c, t); + M(this, m, e, h, a, b); } } break; @@ -297,25 +345,25 @@ J.prototype.add = function(a, d, b, f) { if (1 < c) { for (h = c - 1; 0 < h; h--) { e = l[this.rtl ? c - 1 - h : h] + e; - var k = this.score ? this.score(d, l, p, e, h) : K(C, f, p, c, h); - L(this, m, e, k, a, b); + var k = this.score ? this.score(d, l, p, e, h) : L(D, f, p, c, h); + M(this, m, e, k, a, b); } e = ""; } case "forward": if (1 < c) { for (h = 0; h < c; h++) { - e += l[this.rtl ? c - 1 - h : h], L(this, m, e, g, a, b); + e += l[this.rtl ? c - 1 - h : h], M(this, m, e, g, a, b); } break; } default: - if (L(this, m, l, g, a, b), v && 1 < f && p < f - 1) { + if (M(this, m, l, g, a, b), v && 1 < f && p < f - 1) { for (c = w(), e = this.v, g = l, h = Math.min(v + 1, this.rtl ? p + 1 : f - p), c[g] = 1, k = 1; k < h; k++) { if ((l = d[this.rtl ? f - 1 - p - k : p + k]) && !c[l]) { c[l] = 1; - const q = this.score ? this.score(d, g, p, l, k - 1) : K(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; - L(this, n, t ? g : l, q, a, b, t ? l : g); + const q = this.score ? this.score(d, g, p, l, k - 1) : L(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; + M(this, n, t ? g : l, q, a, b, t ? l : g); } } } @@ -327,16 +375,16 @@ J.prototype.add = function(a, d, b, f) { } return this; }; -function L(a, d, b, f, c, g, e) { +function M(a, d, b, f, c, g, e) { let h = e ? a.ctx : a.map, k; if (!d[b] || e && !(k = d[b])[e]) { e ? (d = k || (d[b] = w()), d[e] = 1, (k = h.get(e)) ? h = k : h.set(e, h = new Map())) : d[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[f] || (h[f] = []), g && h.includes(c) || (h.push(c), a.fastupdate && ((d = a.reg.get(c)) ? d.push(h) : a.reg.set(c, [h]))); } } -function K(a, d, b, f, c) { +function L(a, d, b, f, c) { return b && 1 < a ? d + (f || 0) <= a ? b + (c || 0) : (a - 1) / (d + (f || 0)) * (b + (c || 0)) + 1 | 0 : 0; } -;J.prototype.search = function(a, d, b) { +;I.prototype.search = function(a, d, b) { b || (d || "object" !== typeof a ? "object" === typeof d && (b = d, d = 0) : (b = a, a = "")); var f = [], c = 0; if (b) { @@ -354,11 +402,11 @@ function K(a, d, b, f, c) { b = a.length; d = d || (h ? 100 : 0); if (1 === b) { - return e = c, (c = M(this, a[0], "")) && c.length ? H.call(this, c, d, e) : []; + return e = c, (c = N(this, a[0], "")) && c.length ? H.call(this, c, d, e) : []; } g = this.depth && !1 !== g; if (2 === b && g && !e) { - return e = c, (c = M(this, a[1], a[0])) && c.length ? H.call(this, c, d, e) : []; + return e = c, (c = N(this, a[1], a[0])) && c.length ? H.call(this, c, d, e) : []; } h = w(); var n = 0; @@ -370,10 +418,10 @@ function K(a, d, b, f, c) { for (let l, q; n < b; n++) { if ((q = a[n]) && !h[q]) { h[q] = 1; - l = M(this, q, m); + l = N(this, q, m); a: { g = l; - var v = f, C = e, p = k; + var v = f, D = e, p = k; let t = []; if (g && g.length) { if (g.length <= p) { @@ -381,9 +429,9 @@ function K(a, d, b, f, c) { l = void 0; break a; } - for (let x = 0, A; x < p; x++) { - if (A = g[x]) { - t[x] = A; + for (let x = 0, y; x < p; x++) { + if (y = g[x]) { + t[x] = y; } } if (t.length) { @@ -392,7 +440,7 @@ function K(a, d, b, f, c) { break a; } } - l = C ? void 0 : t; + l = D ? void 0 : t; } if (l) { f = l; @@ -412,12 +460,12 @@ function K(a, d, b, f, c) { m = a.length; e = []; b = w(); - for (let l = 0, q, t, x, A; l < k; l++) { + for (let l = 0, q, t, x, y; l < k; l++) { for (n = 0; n < m; n++) { if (x = a[n], l < x.length && (q = x[l])) { for (g = 0; g < q.length; g++) { - if (t = q[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), A = e[h] || (e[h] = []), A.push(t), d && h === m - 1 && A.length - c === d) { - m = A; + if (t = q[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), y = e[h] || (e[h] = []), y.push(t), d && h === m - 1 && y.length - c === d) { + m = c ? y.slice(c) : y; break b; } } @@ -471,61 +519,19 @@ function K(a, d, b, f, c) { } return d; }; -function M(a, d, b) { +function N(a, d, b) { let f; b && (f = a.bidirectional && d > b) && (f = b, b = d, d = f); a = b ? (a = a.ctx.get(b)) && a.get(d) : a.map.get(d); return a; } -;J.prototype.remove = function(a, d) { - const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (b) { - if (this.fastupdate) { - for (let f = 0, c; f < b.length; f++) { - if (c = b[f]) { - if (2 > c.length) { - c.pop(); - } else { - const g = c.indexOf(a); - g === b.length - 1 ? c.pop() : c.splice(g, 1); - } - } - } - } else { - N(this.map, a), this.depth && N(this.ctx, a); - } - d || this.reg.delete(a); - } - return this; -}; -function N(a, d) { - let b = 0; - if (a.constructor === Array) { - for (let f = 0, c, g; f < a.length; f++) { - if ((c = a[f]) && c.length) { - if (g = c.indexOf(d), 0 <= g) { - 1 < c.length ? (c.splice(g, 1), b++) : delete a[f]; - break; - } else { - b++; - } - } - } - } else { - for (let f of a.entries()) { - const c = f[0], g = N(f[1], d); - g ? b += g : a.delete(c); - } - } - return b; -} -;function J(a, d) { - if (!this || this.constructor !== J) { - return new J(a); +;function I(a, d) { + if (!this || this.constructor !== I) { + return new I(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (I[b] || console.warn("Preset not found: " + b), a = Object.assign({}, I[b], a)); + b && (K[b] || console.warn("Preset not found: " + b), a = Object.assign({}, K[b], a)); } else { a = {}; } @@ -545,7 +551,7 @@ function N(a, d) { this.v = f.resolution || 3; this.rtl = c.rtl || a.rtl || !1; } -r = J.prototype; +r = I.prototype; r.clear = function() { this.map.clear(); this.ctx.clear(); @@ -562,32 +568,18 @@ r.update = function(a, d) { const b = this, f = this.remove(a); return f && f.then ? f.then(() => b.add(a, d)) : this.add(a, d); }; -function O(a) { - let d = 0; - if (a.constructor === Array) { - for (let b = 0, f; b < a.length; b++) { - (f = a[b]) && (d += f.length); - } - } else { - for (const b of a.entries()) { - const f = b[0], c = O(b[1]); - c ? d += c : a.delete(f); - } - } - return d; -} r.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - O(this.map); - this.depth && O(this.ctx); + J(this.map); + this.depth && J(this.ctx); return this; }; w(); -const P = {Index:J, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Q = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; -let R; -(R = Q.define) && R.amd ? R([], function() { - return P; -}) : "object" === typeof Q.exports ? Q.exports = P : Q.FlexSearch = P; +const O = {Index:I, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, P = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : self; +let Q; +(Q = P.define) && Q.amd ? Q([], function() { + return O; +}) : "object" === typeof P.exports ? P.exports = O : P.FlexSearch = O; }(this||self)); diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index fb81e3f..db03d27 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -1,26 +1,26 @@ /**! - * FlexSearch.js v0.8.147 (Light) + * FlexSearch.js v0.8.149 (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 r;function u(a,d,b){const f=typeof b,c=typeof a;if("undefined"!==f){if("undefined"!==c){if(b){if("function"===c&&f===c)return function(h){return a(b(h))};d=a.constructor;if(d===b.constructor){if(d===Array)return b.concat(a);if(d===Map){var g=new Map(b);for(var e of a)g.set(e[0],e[1]);return g}if(d===Set){e=new Set(b);for(g of a.values())e.add(g);return e}}}return a}return b}return"undefined"===c?d:a}function w(){return Object.create(null)};const y=/[^\p{L}\p{N}]+/u,z=/(\d{3})/g,B=/(\D)(\d{3})/g,D=/(\d{3})(\D)/g,E=/[\u0300-\u036f]/g;function F(a={}){if(!this||this.constructor!==F)return new F(...arguments);if(arguments.length)for(a=0;a"a1a".split(b).length; -this.numeric=u(a.numeric,f)}else{try{this.split=u(this.split,y)}catch(c){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);b=a.filter;this.filter="function"===typeof b?b:u(b&&new Set(b),null,this.filter);this.dedupe=u(a.dedupe,!1,this.dedupe);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), +this.numeric=u(a.numeric,f)}else{try{this.split=u(this.split,z)}catch(c){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);b=a.filter;this.filter="function"===typeof b?b:u(b&&new Set(b),null,this.filter);this.dedupe=u(a.dedupe,!1,this.dedupe);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);this.rtl=u(a.rtl,!1,this.rtl);if(this.cache=b=u(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 c of this.matcher.keys())this.g+=(this.g?"|":"")+c;if(this.stemmer)for(const c of this.stemmer.keys())this.h+= (this.h?"|":"")+c;return this};r.addStemmer=function(a,d){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,d);this.h+=(this.h?"|":"")+a;this.u=null;this.cache&&G(this);return this};r.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&G(this);return this}; r.addMapper=function(a,d){if("object"===typeof a)return this.addReplacer(a,d);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,d);this.matcher||(this.matcher=new Map);this.matcher.set(a,d);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&G(this);return this}; r.addReplacer=function(a,d){if("string"===typeof a)return this.addMatcher(a,d);this.replacer||(this.replacer=[]);this.replacer.push(a,d);this.cache&&G(this);return this}; -r.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=E?a.normalize("NFKD").replace(E,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),c!==e&&this.filter&& e.length>=this.minlength&&("function"===typeof this.filter?!this.filter(e):this.filter.has(e))&&(e=""));if(e&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(e&&this.replacer)for(c=0;e&&cthis.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,d,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>d?d?a.slice(b,b+d):a.slice(b):a;let f=[];for(let c=0,g,e;c=e){b-=e;continue}bd&&(g=g.slice(0,d),e=d);if(!f.length&&e>=d)return g;f.push(g);d-=e;if(!d)break}return f=1q;g--){e=l.substring(q,g);t=this.rtl?c-1-q:q;var h=this.score?this.score(d,l,p,e,t):K(C,f,p,c,t);L(this, -m,e,h,a,b)}break}case "bidirectional":case "reverse":if(1e?0:1),f,p,h-1,k-1), -t=this.bidirectional&&l>g;L(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function L(a,d,b,f,c,g,e){let h=e?a.ctx:a.map,k;if(!d[b]||e&&!(k=d[b])[e])e?(d=k||(d[b]=w()),d[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):d[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(c)||(h.push(c),a.fastupdate&&((d=a.reg.get(c))?d.push(h):a.reg.set(c,[h])))}function K(a,d,b,f,c){return b&&1d||c?e.slice(c,d+c):e;e=a}else{if(ad||c)e=e.slice(c,d+c)}m=e}else if(1===f){d=H.call(null,a[0], -d,c);break a}d=m}return d};function M(a,d,b){let f;b&&(f=a.bidirectional&&d>b)&&(f=b,b=d,d=f);a=b?(a=a.ctx.get(b))&&a.get(d):a.map.get(d);return a};J.prototype.remove=function(a,d){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,c;fc.length)c.pop();else{const g=c.indexOf(a);g===b.length-1?c.pop():c.splice(g,1)}}else N(this.map,a),this.depth&&N(this.ctx,a);d||this.reg.delete(a)}return this}; -function N(a,d){let b=0;if(a.constructor===Array)for(let f=0,c,g;fb.add(a,d)):this.add(a,d)}; -function O(a){let d=0;if(a.constructor===Array)for(let b=0,f;bthis.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,d,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>d?d?a.slice(b,b+d):a.slice(b):a;let f=[];for(let c=0,g,e;c=e){b-=e;continue}bd&&(g=g.slice(0,d),e=d);if(!f.length&&e>=d)return g;f.push(g);d-=e;if(!d)break}return f=1c.length)c.pop();else{const g=c.indexOf(a);g===b.length-1?c.pop():c.splice(g,1)}}else J(this.map,a),this.depth&&J(this.ctx,a);d||this.reg.delete(a)}return this}; +function J(a,d){let b=0;var f="undefined"===typeof d;if(a.constructor===Array)for(let c=0,g,e;cq;g--){e=l.substring(q,g);t=this.rtl?c-1-q:q;var h=this.score?this.score(d,l,p,e,t):L(D,f,p,c,t);M(this, +m,e,h,a,b)}break}case "bidirectional":case "reverse":if(1e?0:1),f,p,h-1,k-1), +t=this.bidirectional&&l>g;M(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function M(a,d,b,f,c,g,e){let h=e?a.ctx:a.map,k;if(!d[b]||e&&!(k=d[b])[e])e?(d=k||(d[b]=w()),d[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):d[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(c)||(h.push(c),a.fastupdate&&((d=a.reg.get(c))?d.push(h):a.reg.set(c,[h])))}function L(a,d,b,f,c){return b&&1d||c?e.slice(c,d+c):e;e=a}else{if(ad||c)e=e.slice(c,d+c)}m=e}else if(1===f){d=H.call(null, +a[0],d,c);break a}d=m}return d};function N(a,d,b){let f;b&&(f=a.bidirectional&&d>b)&&(f=b,b=d,d=f);a=b?(a=a.ctx.get(b))&&a.get(d):a.map.get(d);return a};function I(a,d){if(!this||this.constructor!==I)return new I(a);if(a){var b="string"===typeof a?a:a.preset;b&&(a=Object.assign({},K[b],a))}else a={};b=a.context;const f=!0===b?{depth:1}:b||{},c=a.encode||a.encoder||{};this.encoder=c.encode?c:"object"===typeof c?new F(c):{encode:c};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&f.depth||0;this.bidirectional=!1!==f.bidirectional;this.fastupdate=!!a.fastupdate;this.score= +a.score||null;this.map=new Map;this.ctx=new Map;this.reg=d||(this.fastupdate?new Map:new Set);this.v=f.resolution||3;this.rtl=c.rtl||a.rtl||!1}r=I.prototype;r.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};r.append=function(a,d){return this.add(a,d,!0)};r.contain=function(a){return this.reg.has(a)};r.update=function(a,d){const b=this,f=this.remove(a);return f&&f.then?f.then(()=>b.add(a,d)):this.add(a,d)}; +r.cleanup=function(){if(!this.fastupdate)return this;J(this.map);this.depth&&J(this.ctx);return this};w();const O={Index:I,Charset:null,Encoder:F,Document:null,Worker:null,Resolver:null,IndexedDB:null,Language:{}},P="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let Q;(Q=P.define)&&Q.amd?Q([],function(){return O}):"object"===typeof P.exports?P.exports=O:P.FlexSearch=O;}(this||self)); diff --git a/dist/flexsearch.light.module.debug.js b/dist/flexsearch.light.module.debug.js index 93e2141..8edd1eb 100644 --- a/dist/flexsearch.light.module.debug.js +++ b/dist/flexsearch.light.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.147 (Bundle/Debug) + * FlexSearch.js v0.8.149 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -46,7 +46,7 @@ function u(a, d, b) { function w() { return Object.create(null); } -;const y = /[^\p{L}\p{N}]+/u, z = /(\d{3})/g, B = /(\D)(\d{3})/g, D = /(\d{3})(\D)/g, E = /[\u0300-\u036f]/g; +;const z = /[^\p{L}\p{N}]+/u, A = /(\d{3})/g, B = /(\D)(\d{3})/g, C = /(\d{3})(\D)/g, E = /[\u0300-\u036f]/g; function F(a = {}) { if (!this || this.constructor !== F) { return new F(...arguments); @@ -87,7 +87,7 @@ r.assign = function(a) { this.numeric = u(a.numeric, f); } else { try { - this.split = u(this.split, y); + this.split = u(this.split, z); } catch (c) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } @@ -184,7 +184,7 @@ r.encode = function(a) { } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = E ? a.normalize("NFKD").replace(E, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(B, "$1 $2").replace(D, "$1 $2").replace(z, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(B, "$1 $2").replace(C, "$1 $2").replace(A, "$1 ")); const d = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], f = this.split || "" === this.split ? a.split(this.split) : a; for (let g = 0, e, h; g < f.length; g++) { @@ -264,20 +264,68 @@ function G(a) { return f = 1 < f.length ? [].concat.apply([], f) : f[0]; } ;w(); -const I = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -J.prototype.add = function(a, d, b, f) { +I.prototype.remove = function(a, d) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { + if (this.fastupdate) { + for (let f = 0, c; f < b.length; f++) { + if (c = b[f]) { + if (2 > c.length) { + c.pop(); + } else { + const g = c.indexOf(a); + g === b.length - 1 ? c.pop() : c.splice(g, 1); + } + } + } + } else { + J(this.map, a), this.depth && J(this.ctx, a); + } + d || this.reg.delete(a); + } + return this; +}; +function J(a, d) { + let b = 0; + var f = "undefined" === typeof d; + if (a.constructor === Array) { + for (let c = 0, g, e; c < a.length; c++) { + if ((g = a[c]) && g.length) { + if (f) { + b++; + } else { + if (e = g.indexOf(d), 0 <= e) { + 1 < g.length ? (g.splice(e, 1), b++) : delete a[c]; + break; + } else { + b++; + } + } + } + } + } else { + for (let c of a.entries()) { + f = c[0]; + const g = J(c[1], d); + g ? b += g : a.delete(f); + } + } + return b; +} +;const K = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +I.prototype.add = function(a, d, b, f) { if (d && (a || 0 === a)) { if (!f && !b && this.reg.has(a)) { return this.update(a, d); } d = this.encoder.encode(d); if (f = d.length) { - const n = w(), m = w(), v = this.depth, C = this.resolution; + const n = w(), m = w(), v = this.depth, D = this.resolution; for (let p = 0; p < f; p++) { let l = d[this.rtl ? f - 1 - p : p]; var c = l.length; if (c && (v || !m[l])) { - var g = this.score ? this.score(d, l, p, null, 0) : K(C, f, p), e = ""; + var g = this.score ? this.score(d, l, p, null, 0) : L(D, f, p), e = ""; switch(this.tokenize) { case "full": if (2 < c) { @@ -285,8 +333,8 @@ J.prototype.add = function(a, d, b, f) { for (g = c; g > q; g--) { e = l.substring(q, g); t = this.rtl ? c - 1 - q : q; - var h = this.score ? this.score(d, l, p, e, t) : K(C, f, p, c, t); - L(this, m, e, h, a, b); + var h = this.score ? this.score(d, l, p, e, t) : L(D, f, p, c, t); + M(this, m, e, h, a, b); } } break; @@ -296,25 +344,25 @@ J.prototype.add = function(a, d, b, f) { if (1 < c) { for (h = c - 1; 0 < h; h--) { e = l[this.rtl ? c - 1 - h : h] + e; - var k = this.score ? this.score(d, l, p, e, h) : K(C, f, p, c, h); - L(this, m, e, k, a, b); + var k = this.score ? this.score(d, l, p, e, h) : L(D, f, p, c, h); + M(this, m, e, k, a, b); } e = ""; } case "forward": if (1 < c) { for (h = 0; h < c; h++) { - e += l[this.rtl ? c - 1 - h : h], L(this, m, e, g, a, b); + e += l[this.rtl ? c - 1 - h : h], M(this, m, e, g, a, b); } break; } default: - if (L(this, m, l, g, a, b), v && 1 < f && p < f - 1) { + if (M(this, m, l, g, a, b), v && 1 < f && p < f - 1) { for (c = w(), e = this.v, g = l, h = Math.min(v + 1, this.rtl ? p + 1 : f - p), c[g] = 1, k = 1; k < h; k++) { if ((l = d[this.rtl ? f - 1 - p - k : p + k]) && !c[l]) { c[l] = 1; - const q = this.score ? this.score(d, g, p, l, k - 1) : K(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; - L(this, n, t ? g : l, q, a, b, t ? l : g); + const q = this.score ? this.score(d, g, p, l, k - 1) : L(e + (f / 2 > e ? 0 : 1), f, p, h - 1, k - 1), t = this.bidirectional && l > g; + M(this, n, t ? g : l, q, a, b, t ? l : g); } } } @@ -326,16 +374,16 @@ J.prototype.add = function(a, d, b, f) { } return this; }; -function L(a, d, b, f, c, g, e) { +function M(a, d, b, f, c, g, e) { let h = e ? a.ctx : a.map, k; if (!d[b] || e && !(k = d[b])[e]) { e ? (d = k || (d[b] = w()), d[e] = 1, (k = h.get(e)) ? h = k : h.set(e, h = new Map())) : d[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[f] || (h[f] = []), g && h.includes(c) || (h.push(c), a.fastupdate && ((d = a.reg.get(c)) ? d.push(h) : a.reg.set(c, [h]))); } } -function K(a, d, b, f, c) { +function L(a, d, b, f, c) { return b && 1 < a ? d + (f || 0) <= a ? b + (c || 0) : (a - 1) / (d + (f || 0)) * (b + (c || 0)) + 1 | 0 : 0; } -;J.prototype.search = function(a, d, b) { +;I.prototype.search = function(a, d, b) { b || (d || "object" !== typeof a ? "object" === typeof d && (b = d, d = 0) : (b = a, a = "")); var f = [], c = 0; if (b) { @@ -353,11 +401,11 @@ function K(a, d, b, f, c) { b = a.length; d = d || (h ? 100 : 0); if (1 === b) { - return e = c, (c = M(this, a[0], "")) && c.length ? H.call(this, c, d, e) : []; + return e = c, (c = N(this, a[0], "")) && c.length ? H.call(this, c, d, e) : []; } g = this.depth && !1 !== g; if (2 === b && g && !e) { - return e = c, (c = M(this, a[1], a[0])) && c.length ? H.call(this, c, d, e) : []; + return e = c, (c = N(this, a[1], a[0])) && c.length ? H.call(this, c, d, e) : []; } h = w(); var n = 0; @@ -369,10 +417,10 @@ function K(a, d, b, f, c) { for (let l, q; n < b; n++) { if ((q = a[n]) && !h[q]) { h[q] = 1; - l = M(this, q, m); + l = N(this, q, m); a: { g = l; - var v = f, C = e, p = k; + var v = f, D = e, p = k; let t = []; if (g && g.length) { if (g.length <= p) { @@ -380,9 +428,9 @@ function K(a, d, b, f, c) { l = void 0; break a; } - for (let x = 0, A; x < p; x++) { - if (A = g[x]) { - t[x] = A; + for (let x = 0, y; x < p; x++) { + if (y = g[x]) { + t[x] = y; } } if (t.length) { @@ -391,7 +439,7 @@ function K(a, d, b, f, c) { break a; } } - l = C ? void 0 : t; + l = D ? void 0 : t; } if (l) { f = l; @@ -411,12 +459,12 @@ function K(a, d, b, f, c) { m = a.length; e = []; b = w(); - for (let l = 0, q, t, x, A; l < k; l++) { + for (let l = 0, q, t, x, y; l < k; l++) { for (n = 0; n < m; n++) { if (x = a[n], l < x.length && (q = x[l])) { for (g = 0; g < q.length; g++) { - if (t = q[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), A = e[h] || (e[h] = []), A.push(t), d && h === m - 1 && A.length - c === d) { - m = A; + if (t = q[g], (h = b[t]) ? b[t]++ : (h = 0, b[t] = 1), y = e[h] || (e[h] = []), y.push(t), d && h === m - 1 && y.length - c === d) { + m = c ? y.slice(c) : y; break b; } } @@ -470,61 +518,19 @@ function K(a, d, b, f, c) { } return d; }; -function M(a, d, b) { +function N(a, d, b) { let f; b && (f = a.bidirectional && d > b) && (f = b, b = d, d = f); a = b ? (a = a.ctx.get(b)) && a.get(d) : a.map.get(d); return a; } -;J.prototype.remove = function(a, d) { - const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (b) { - if (this.fastupdate) { - for (let f = 0, c; f < b.length; f++) { - if (c = b[f]) { - if (2 > c.length) { - c.pop(); - } else { - const g = c.indexOf(a); - g === b.length - 1 ? c.pop() : c.splice(g, 1); - } - } - } - } else { - N(this.map, a), this.depth && N(this.ctx, a); - } - d || this.reg.delete(a); - } - return this; -}; -function N(a, d) { - let b = 0; - if (a.constructor === Array) { - for (let f = 0, c, g; f < a.length; f++) { - if ((c = a[f]) && c.length) { - if (g = c.indexOf(d), 0 <= g) { - 1 < c.length ? (c.splice(g, 1), b++) : delete a[f]; - break; - } else { - b++; - } - } - } - } else { - for (let f of a.entries()) { - const c = f[0], g = N(f[1], d); - g ? b += g : a.delete(c); - } - } - return b; -} -;function J(a, d) { - if (!this || this.constructor !== J) { - return new J(a); +;function I(a, d) { + if (!this || this.constructor !== I) { + return new I(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (I[b] || console.warn("Preset not found: " + b), a = Object.assign({}, I[b], a)); + b && (K[b] || console.warn("Preset not found: " + b), a = Object.assign({}, K[b], a)); } else { a = {}; } @@ -544,7 +550,7 @@ function N(a, d) { this.v = f.resolution || 3; this.rtl = c.rtl || a.rtl || !1; } -r = J.prototype; +r = I.prototype; r.clear = function() { this.map.clear(); this.ctx.clear(); @@ -561,29 +567,15 @@ r.update = function(a, d) { const b = this, f = this.remove(a); return f && f.then ? f.then(() => b.add(a, d)) : this.add(a, d); }; -function O(a) { - let d = 0; - if (a.constructor === Array) { - for (let b = 0, f; b < a.length; b++) { - (f = a[b]) && (d += f.length); - } - } else { - for (const b of a.entries()) { - const f = b[0], c = O(b[1]); - c ? d += c : a.delete(f); - } - } - return d; -} r.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - O(this.map); - this.depth && O(this.ctx); + J(this.map); + this.depth && J(this.ctx); return this; }; w(); -export default {Index:J, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:I, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=J;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 +export const Index=I;export const Charset=null;export const Encoder=F;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index cb0057a..0f08b6c 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,27 +1,27 @@ /**! - * FlexSearch.js v0.8.147 (Bundle) + * FlexSearch.js v0.8.149 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var r;function u(a,d,b){const f=typeof b,c=typeof a;if("undefined"!==f){if("undefined"!==c){if(b){if("function"===c&&f===c)return function(h){return a(b(h))};d=a.constructor;if(d===b.constructor){if(d===Array)return b.concat(a);if(d===Map){var g=new Map(b);for(var e of a)g.set(e[0],e[1]);return g}if(d===Set){e=new Set(b);for(g of a.values())e.add(g);return e}}}return a}return b}return"undefined"===c?d:a}function w(){return Object.create(null)};const y=/[^\p{L}\p{N}]+/u,z=/(\d{3})/g,B=/(\D)(\d{3})/g,D=/(\d{3})(\D)/g,E=/[\u0300-\u036f]/g;function F(a={}){if(!this||this.constructor!==F)return new F(...arguments);if(arguments.length)for(a=0;a"a1a".split(b).length; -this.numeric=u(a.numeric,f)}else{try{this.split=u(this.split,y)}catch(c){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);b=a.filter;this.filter="function"===typeof b?b:u(b&&new Set(b),null,this.filter);this.dedupe=u(a.dedupe,!1,this.dedupe);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), +this.numeric=u(a.numeric,f)}else{try{this.split=u(this.split,z)}catch(c){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);b=a.filter;this.filter="function"===typeof b?b:u(b&&new Set(b),null,this.filter);this.dedupe=u(a.dedupe,!1,this.dedupe);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);this.rtl=u(a.rtl,!1,this.rtl);if(this.cache=b=u(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 c of this.matcher.keys())this.g+=(this.g?"|":"")+c;if(this.stemmer)for(const c of this.stemmer.keys())this.h+= (this.h?"|":"")+c;return this};r.addStemmer=function(a,d){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,d);this.h+=(this.h?"|":"")+a;this.u=null;this.cache&&G(this);return this};r.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&G(this);return this}; r.addMapper=function(a,d){if("object"===typeof a)return this.addReplacer(a,d);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,d);this.matcher||(this.matcher=new Map);this.matcher.set(a,d);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&G(this);return this}; r.addReplacer=function(a,d){if("string"===typeof a)return this.addMatcher(a,d);this.replacer||(this.replacer=[]);this.replacer.push(a,d);this.cache&&G(this);return this}; -r.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=E?a.normalize("NFKD").replace(E,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),c!==e&&this.filter&& e.length>=this.minlength&&("function"===typeof this.filter?!this.filter(e):this.filter.has(e))&&(e=""));if(e&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(e&&this.replacer)for(c=0;e&&cthis.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,d,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>d?d?a.slice(b,b+d):a.slice(b):a;let f=[];for(let c=0,g,e;c=e){b-=e;continue}bd&&(g=g.slice(0,d),e=d);if(!f.length&&e>=d)return g;f.push(g);d-=e;if(!d)break}return f=1q;g--){e=l.substring(q,g);t=this.rtl?c-1-q:q;var h=this.score?this.score(d,l,p,e,t):K(C,f,p,c,t);L(this, -m,e,h,a,b)}break}case "bidirectional":case "reverse":if(1e?0:1),f,p,h-1,k-1), -t=this.bidirectional&&l>g;L(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function L(a,d,b,f,c,g,e){let h=e?a.ctx:a.map,k;if(!d[b]||e&&!(k=d[b])[e])e?(d=k||(d[b]=w()),d[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):d[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(c)||(h.push(c),a.fastupdate&&((d=a.reg.get(c))?d.push(h):a.reg.set(c,[h])))}function K(a,d,b,f,c){return b&&1d||c?e.slice(c,d+c):e;e=a}else{if(ad||c)e=e.slice(c,d+c)}m=e}else if(1===f){d=H.call(null,a[0], -d,c);break a}d=m}return d};function M(a,d,b){let f;b&&(f=a.bidirectional&&d>b)&&(f=b,b=d,d=f);a=b?(a=a.ctx.get(b))&&a.get(d):a.map.get(d);return a};J.prototype.remove=function(a,d){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,c;fc.length)c.pop();else{const g=c.indexOf(a);g===b.length-1?c.pop():c.splice(g,1)}}else N(this.map,a),this.depth&&N(this.ctx,a);d||this.reg.delete(a)}return this}; -function N(a,d){let b=0;if(a.constructor===Array)for(let f=0,c,g;fb.add(a,d)):this.add(a,d)}; -function O(a){let d=0;if(a.constructor===Array)for(let b=0,f;bthis.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,d,b){if(!a.length)return a;if(1===a.length)return a=a[0],a=b||a.length>d?d?a.slice(b,b+d):a.slice(b):a;let f=[];for(let c=0,g,e;c=e){b-=e;continue}bd&&(g=g.slice(0,d),e=d);if(!f.length&&e>=d)return g;f.push(g);d-=e;if(!d)break}return f=1c.length)c.pop();else{const g=c.indexOf(a);g===b.length-1?c.pop():c.splice(g,1)}}else J(this.map,a),this.depth&&J(this.ctx,a);d||this.reg.delete(a)}return this}; +function J(a,d){let b=0;var f="undefined"===typeof d;if(a.constructor===Array)for(let c=0,g,e;cq;g--){e=l.substring(q,g);t=this.rtl?c-1-q:q;var h=this.score?this.score(d,l,p,e,t):L(D,f,p,c,t);M(this, +m,e,h,a,b)}break}case "bidirectional":case "reverse":if(1e?0:1),f,p,h-1,k-1), +t=this.bidirectional&&l>g;M(this,n,t?g:l,q,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this};function M(a,d,b,f,c,g,e){let h=e?a.ctx:a.map,k;if(!d[b]||e&&!(k=d[b])[e])e?(d=k||(d[b]=w()),d[e]=1,(k=h.get(e))?h=k:h.set(e,h=new Map)):d[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[f]||(h[f]=[]),g&&h.includes(c)||(h.push(c),a.fastupdate&&((d=a.reg.get(c))?d.push(h):a.reg.set(c,[h])))}function L(a,d,b,f,c){return b&&1d||c?e.slice(c,d+c):e;e=a}else{if(ad||c)e=e.slice(c,d+c)}m=e}else if(1===f){d=H.call(null, +a[0],d,c);break a}d=m}return d};function N(a,d,b){let f;b&&(f=a.bidirectional&&d>b)&&(f=b,b=d,d=f);a=b?(a=a.ctx.get(b))&&a.get(d):a.map.get(d);return a};function I(a,d){if(!this||this.constructor!==I)return new I(a);if(a){var b="string"===typeof a?a:a.preset;b&&(a=Object.assign({},K[b],a))}else a={};b=a.context;const f=!0===b?{depth:1}:b||{},c=a.encode||a.encoder||{};this.encoder=c.encode?c:"object"===typeof c?new F(c):{encode:c};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&f.depth||0;this.bidirectional=!1!==f.bidirectional;this.fastupdate=!!a.fastupdate;this.score= +a.score||null;this.map=new Map;this.ctx=new Map;this.reg=d||(this.fastupdate?new Map:new Set);this.v=f.resolution||3;this.rtl=c.rtl||a.rtl||!1}r=I.prototype;r.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};r.append=function(a,d){return this.add(a,d,!0)};r.contain=function(a){return this.reg.has(a)};r.update=function(a,d){const b=this,f=this.remove(a);return f&&f.then?f.then(()=>b.add(a,d)):this.add(a,d)}; +r.cleanup=function(){if(!this.fastupdate)return this;J(this.map);this.depth&&J(this.ctx);return this};w();export default {Index:I,Charset:null,Encoder:F,Document:null,Worker:null,Resolver:null,IndexedDB:null,Language:{}}; +export const Index=I;export const Charset=null;export const Encoder=F;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/module-debug/bundle.js b/dist/module-debug/bundle.js index 95e5e38..19a3757 100644 --- a/dist/module-debug/bundle.js +++ b/dist/module-debug/bundle.js @@ -267,6 +267,8 @@ import { KeystoreMap, KeystoreArray, KeystoreSet } from "./keystore.js"; /** @export */ResolverOptions.or; /** @export */ResolverOptions.xor; /** @export */ResolverOptions.not; +/** @export */ResolverOptions.pluck; +/** @export */ResolverOptions.field; const FlexSearch = { Index: Index, diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index 68f56b6..9a923fc 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -463,44 +463,45 @@ function highlight_fields(result, query, index, field, tree, template) { for (let j = 0; j < res.length; j++) { let str = "", content = parse_simple(res[j].doc, path), - doc_enc = encoder.encode(content), - doc_org = content.split(encoder.split); + doc_org = content.split(/\s+/); + //let doc_enc = encoder.encode(content); - - for (let k = 0, doc_enc_cur, doc_org_cur; k < doc_enc.length; k++) { - doc_enc_cur = doc_enc[k]; + for (let k = 0, doc_org_cur, doc_enc_cur; k < doc_org.length; k++) { doc_org_cur = doc_org[k]; - - if (!doc_enc_cur || !doc_org_cur) { - continue; - } + //doc_enc_cur = doc_enc[k]; + doc_enc_cur = encoder.encode(doc_org_cur).join(" "); let found; - for (let l = 0, query_enc_cur; l < query_enc.length; l++) { - query_enc_cur = query_enc[l]; - // todo tokenize could be custom also when "strict" was used - if ("strict" === tokenize) { - if (doc_enc_cur === query_enc_cur) { - str += (str ? " " : "") + template.replace("$1", doc_org_cur); - found = !0; - break; - } - } else { - const position = doc_enc_cur.indexOf(query_enc_cur); - if (-1 < position) { - str += (str ? " " : "") + - // prefix - doc_org_cur.substring(0, position) + - // match - template.replace("$1", doc_org_cur.substring(position, query_enc_cur.length)) + - // suffix - doc_org_cur.substring(position + query_enc_cur.length); - found = !0; - break; - } - } - //str += doc_enc[k].replace(new RegExp("(" + doc_enc[k] + ")", "g"), template.replace("$1", content)) + if (doc_enc_cur && doc_org_cur) { + + for (let l = 0, query_enc_cur; l < query_enc.length; l++) { + query_enc_cur = query_enc[l]; + // todo tokenize could be custom also when "strict" was used + if ("strict" === tokenize) { + if (doc_enc_cur === query_enc_cur) { + str += (str ? " " : "") + template.replace("$1", doc_org_cur); + found = !0; + break; + } + } else { + const position = doc_enc_cur.indexOf(query_enc_cur); + //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position) + if (-1 < position) { + str += (str ? " " : "") + + // prefix + doc_org_cur.substring(0, position) + + // match + template.replace("$1", doc_org_cur.substring(position, query_enc_cur.length)) + + // suffix + doc_org_cur.substring(position + query_enc_cur.length); + found = !0; + break; + } + } + + //str += doc_enc[k].replace(new RegExp("(" + doc_enc[k] + ")", "g"), template.replace("$1", content)) + } } if (!found) { diff --git a/dist/module-debug/index.js b/dist/module-debug/index.js index e5e3f02..95f9449 100644 --- a/dist/module-debug/index.js +++ b/dist/module-debug/index.js @@ -13,6 +13,7 @@ import Charset from "./charset.js"; import { KeystoreMap, KeystoreSet } from "./keystore.js"; import { is_array, is_string } from "./common.js"; import { exportIndex, importIndex, serialize } from "./serialize.js"; +import { remove_index } from "./index/remove.js"; //import default_encoder from "./charset/latin/default.js"; import apply_preset from "./preset.js"; import apply_async from "./async.js"; @@ -160,29 +161,31 @@ Index.prototype.update = function (id, content) { return res && res.then ? res.then(() => self.add(id, content)) : this.add(id, content); }; -/** - * @param map - * @return {number} - */ - -function cleanup_index(map) { - - let count = 0; - - if (is_array(map)) { - for (let i = 0, arr; i < map.length; i++) { - (arr = map[i]) && (count += arr.length); - } - } else for (const item of map.entries()) { - const key = item[0], - value = item[1], - tmp = cleanup_index(value); - - tmp ? count += tmp : map.delete(key); - } - - return count; -} +// /** +// * @param map +// * @return {number} +// */ +// +// function cleanup_index(map){ +// +// let count = 0; +// +// if(is_array(map)){ +// for(let i = 0, arr; i < map.length; i++){ +// (arr = map[i]) && +// (count += arr.length); +// } +// } +// else for(const item of map.entries()){ +// const key = item[0]; +// const value = item[1]; +// const tmp = cleanup_index(value); +// tmp ? count += tmp +// : map.delete(key); +// } +// +// return count; +// } Index.prototype.cleanup = function () { @@ -191,8 +194,11 @@ Index.prototype.cleanup = function () { return this; } - cleanup_index(this.map); - this.depth && cleanup_index(this.ctx); + remove_index(this.map); + //cleanup_index(this.map); + this.depth && + //cleanup_index(this.ctx); + remove_index(this.ctx); return this; }; diff --git a/dist/module-debug/index/remove.js b/dist/module-debug/index/remove.js index 481d4ae..2675be2 100644 --- a/dist/module-debug/index/remove.js +++ b/dist/module-debug/index/remove.js @@ -94,33 +94,40 @@ Index.prototype.remove = function (id, _skip_deletion) { }; /** + * When called without passing ID it just will clean up * @param {!Map|Array>} map - * @param {!number|string} id + * @param {!number|string=} id * @return {number} */ -function remove_index(map, id) { +export function remove_index(map, id) { // a check counter of filled resolution slots // to prevent removing the field let count = 0; + if (is_array(map)) { for (let x = 0, arr, index; x < map.length; x++) { if ((arr = map[x]) && arr.length) { - index = arr.indexOf(id); - if (0 <= index) { - if (1 < arr.length) { - arr.splice(index, 1); - count++; - } else { - // remove resolution slot - delete map[x]; - } - // the index key:[res, id] is unique - break; - } else { + if ("undefined" == typeof id) { + //count += arr.length; count++; + } else { + index = arr.indexOf(id); + if (0 <= index) { + if (1 < arr.length) { + arr.splice(index, 1); + count++; + } else { + // remove resolution slot + delete map[x]; + } + // the index key:[res, id] is unique + break; + } else { + count++; + } } } } diff --git a/dist/module-debug/intersect.js b/dist/module-debug/intersect.js index cf7105b..c64394e 100644 --- a/dist/module-debug/intersect.js +++ b/dist/module-debug/intersect.js @@ -81,11 +81,8 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res // fast path early result when limit was set if (resolve) { if (limit && count === length - 1) { - // if(tmp.length - offset > limit){ - // return tmp.slice(offset, limit + offset); - // } if (tmp.length - offset === limit) { - return tmp; + return offset ? tmp.slice(offset) : tmp; } } } @@ -196,7 +193,7 @@ export function union(arrays, limit, offset, resolve, boost) { // adjust score to reduce resolution of suggestions // todo: instead of applying the resolve task directly it could // be added to the chain and resolved later, that will keep - // the original score but also can't resolve early because of + // the original score but also can't resolve early when // nothing was found let score = 0 | (k + (i < arr_len - 1 ? boost || 0 : 0)) / (i + 1), arr = result[score] || (result[score] = []); diff --git a/dist/module-min/bundle.js b/dist/module-min/bundle.js index 26f07c1..0d916b2 100644 --- a/dist/module-min/bundle.js +++ b/dist/module-min/bundle.js @@ -1 +1 @@ -import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreArray,KeystoreSet}from"./keystore.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.encoder,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Document.prototype.field,Document.prototype.index,Document.prototype.reg,Document.prototype.tag,Document.prototype.store,Document.prototype.fastupdate,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,KeystoreArray.length,KeystoreMap.size,KeystoreSet.size,Charset.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,DocumentDescriptor.id,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{const a="undefined"==typeof self?"undefined"==typeof global?self:global:self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file +import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreArray,KeystoreSet}from"./keystore.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.encoder,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Document.prototype.field,Document.prototype.index,Document.prototype.reg,Document.prototype.tag,Document.prototype.store,Document.prototype.fastupdate,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,KeystoreArray.length,KeystoreMap.size,KeystoreSet.size,Charset.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,DocumentDescriptor.id,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not,ResolverOptions.pluck,ResolverOptions.field;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{const a="undefined"==typeof self?"undefined"==typeof global?self:global:self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file diff --git a/dist/module-min/document/search.js b/dist/module-min/document/search.js index 905590e..45e0478 100644 --- a/dist/module-min/document/search.js +++ b/dist/module-min/document/search.js @@ -1 +1 @@ -import{DocumentSearchOptions,DocumentSearchResults,EnrichedDocumentSearchResults,MergedDocumentSearchResults,MergedDocumentSearchEntry,EnrichedSearchResults,SearchResults,IntermediateSearchResults}from"../type.js";import{create_object,is_array,is_object,is_string,parse_simple}from"../common.js";import{intersect_union}from"../intersect.js";import Document from"../document.js";import Index from"../index.js";import Resolver from"../resolver.js";import tick from"../profiler.js";Document.prototype.search=function(a,b,c,d){!1,c||(!b&&is_object(a)?(c=a,a=""):is_object(b)&&(c=b,b=0));let e,f,g,h,j,k,l,m,n=[],o=[],p=0,q=!0;if(c){if(is_array(c)&&(c={index:c}),a=c.query||a,e=c.pluck,g=c.merge,j=e||c.field||(j=c.index)&&(j.index?null:j),k=this.tag&&c.tag,h=c.suggest,q=!1!==c.resolve,(q||e||(j=j||this.field,j&&(is_string(j)?e=j:(is_array(j)&&1===j.length&&(j=j[0]),e=j.field||j.index))),!1,f=this.store&&c.enrich&&q,m=f&&c.highlight,b=c.limit||b,l=c.offset||0,b||(b=100),k&&(!this.db||!d))){!1,k.constructor!==Array&&(k=[k]);let c=[];for(let a,b=0;bc.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)},Index.prototype.cleanup=function(){return this.fastupdate?(remove_index(this.map),this.depth&&remove_index(this.ctx),this):(!1,this)},Index.prototype.searchCache=searchCache,Index.prototype.export=exportIndex,Index.prototype.import=importIndex,Index.prototype.serialize=serialize,apply_async(Index.prototype); \ No newline at end of file diff --git a/dist/module-min/index/remove.js b/dist/module-min/index/remove.js index 7474a4c..70c23a2 100644 --- a/dist/module-min/index/remove.js +++ b/dist/module-min/index/remove.js @@ -1 +1 @@ -import{is_array}from"../common.js";import Index,{autoCommit}from"../index.js";Index.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 b,d=0;db.length)b.pop();else{const d=b.indexOf(a);d===c.length-1?b.pop():b.splice(d,1)}}else remove_index(this.map,a),this.depth&&remove_index(this.ctx,a);b||this.reg.delete(a)}return this.db&&(this.commit_task.push({del:a}),this.commit_auto&&autoCommit(this)),this.cache&&this.cache.remove(a),this};function remove_index(a,b){let c=0;if(is_array(a)){for(let d,e,f=0;fb.length)b.pop();else{const d=b.indexOf(a);d===c.length-1?b.pop():b.splice(d,1)}}else remove_index(this.map,a),this.depth&&remove_index(this.ctx,a);b||this.reg.delete(a)}return this.db&&(this.commit_task.push({del:a}),this.commit_auto&&autoCommit(this)),this.cache&&this.cache.remove(a),this};export function remove_index(a,b){let c=0;if(is_array(a)){for(let d,e,f=0;fc||d)&&(k=k.slice(d,c+d));else{const a=[];for(let b,e=0;ed){d-=b.length;continue}if((b.length>c||d)&&(b=b.slice(d,c+d),c-=b.length,d&&(d-=b.length)),a.push(b),!c)break}k=1c||d?k.slice(d,c+d):k;return k}export function union(a,b,c,d,e){const f=[],g=create_object();let h,l,m,n=a.length;if(!d)for(let d,j=n-1,i=0;0<=j;j--){d=a[j];for(let a=0;ac||d)&&(k=k.slice(d,c+d));else{const a=[];for(let b,e=0;ed){d-=b.length;continue}if((b.length>c||d)&&(b=b.slice(d,c+d),c-=b.length,d&&(d-=b.length)),a.push(b),!c)break}k=1c||d?k.slice(d,c+d):k;return k}export function union(a,b,c,d,e){const f=[],g=create_object();let h,l,m,n=a.length;if(!d)for(let d,j=n-1,i=0;0<=j;j--){d=a[j];for(let a=0;a self.add(id, content)) : this.add(id, content); }; -/** - * @param map - * @return {number} - */ - -function cleanup_index(map) { - - let count = 0; - - if (is_array(map)) { - for (let i = 0, arr; i < map.length; i++) { - (arr = map[i]) && (count += arr.length); - } - } else for (const item of map.entries()) { - const key = item[0], - value = item[1], - tmp = cleanup_index(value); - - tmp ? count += tmp : map.delete(key); - } - - return count; -} +// /** +// * @param map +// * @return {number} +// */ +// +// function cleanup_index(map){ +// +// let count = 0; +// +// if(is_array(map)){ +// for(let i = 0, arr; i < map.length; i++){ +// (arr = map[i]) && +// (count += arr.length); +// } +// } +// else for(const item of map.entries()){ +// const key = item[0]; +// const value = item[1]; +// const tmp = cleanup_index(value); +// tmp ? count += tmp +// : map.delete(key); +// } +// +// return count; +// } Index.prototype.cleanup = function () { @@ -185,8 +188,11 @@ Index.prototype.cleanup = function () { return this; } - cleanup_index(this.map); - this.depth && cleanup_index(this.ctx); + remove_index(this.map); + //cleanup_index(this.map); + this.depth && + //cleanup_index(this.ctx); + remove_index(this.ctx); return this; }; diff --git a/dist/module/index/remove.js b/dist/module/index/remove.js index 481d4ae..2675be2 100644 --- a/dist/module/index/remove.js +++ b/dist/module/index/remove.js @@ -94,33 +94,40 @@ Index.prototype.remove = function (id, _skip_deletion) { }; /** + * When called without passing ID it just will clean up * @param {!Map|Array>} map - * @param {!number|string} id + * @param {!number|string=} id * @return {number} */ -function remove_index(map, id) { +export function remove_index(map, id) { // a check counter of filled resolution slots // to prevent removing the field let count = 0; + if (is_array(map)) { for (let x = 0, arr, index; x < map.length; x++) { if ((arr = map[x]) && arr.length) { - index = arr.indexOf(id); - if (0 <= index) { - if (1 < arr.length) { - arr.splice(index, 1); - count++; - } else { - // remove resolution slot - delete map[x]; - } - // the index key:[res, id] is unique - break; - } else { + if ("undefined" == typeof id) { + //count += arr.length; count++; + } else { + index = arr.indexOf(id); + if (0 <= index) { + if (1 < arr.length) { + arr.splice(index, 1); + count++; + } else { + // remove resolution slot + delete map[x]; + } + // the index key:[res, id] is unique + break; + } else { + count++; + } } } } diff --git a/dist/module/intersect.js b/dist/module/intersect.js index cf7105b..c64394e 100644 --- a/dist/module/intersect.js +++ b/dist/module/intersect.js @@ -81,11 +81,8 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res // fast path early result when limit was set if (resolve) { if (limit && count === length - 1) { - // if(tmp.length - offset > limit){ - // return tmp.slice(offset, limit + offset); - // } if (tmp.length - offset === limit) { - return tmp; + return offset ? tmp.slice(offset) : tmp; } } } @@ -196,7 +193,7 @@ export function union(arrays, limit, offset, resolve, boost) { // adjust score to reduce resolution of suggestions // todo: instead of applying the resolve task directly it could // be added to the chain and resolved later, that will keep - // the original score but also can't resolve early because of + // the original score but also can't resolve early when // nothing was found let score = 0 | (k + (i < arr_len - 1 ? boost || 0 : 0)) / (i + 1), arr = result[score] || (result[score] = []); diff --git a/index.d.ts b/index.d.ts index 7b04796..135360b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -206,15 +206,7 @@ declare module "flexsearch" { type DefaultSearchResults = Id[]; type IntermediateSearchResults = Array; - type EnrichedSearchResults = Array<{ - id: Id; - score: number; - }>; - type SearchResults = - DefaultSearchResults | - EnrichedSearchResults | - Resolver | - Promise; + type SearchResults = DefaultSearchResults | Resolver; /** * **Document:** @@ -232,12 +224,12 @@ declare module "flexsearch" { append(id: Id, content: string): this | Promise; update(id: Id, content: string): this | Promise; remove(id: Id): this | Promise; - search(query: string, options?: Limit | SearchOptions): SearchResults; - search(query: string, limit: number, options: SearchOptions): SearchResults; - search(options: SearchOptions): SearchResults; - searchCache(query: string, options?: Limit | SearchOptions): SearchResults; - searchCache(query: string, limit: number, options: SearchOptions): SearchResults; - searchCache(options: SearchOptions): SearchResults; + search(query: string, options?: Limit | SearchOptions): SearchResults | Promise; + search(query: string, limit: number, options: SearchOptions): SearchResults | Promise; + search(options: SearchOptions): SearchResults | Promise; + searchCache(query: string, options?: Limit | SearchOptions): SearchResults | Promise; + searchCache(query: string, limit: number, options: SearchOptions): SearchResults | Promise; + searchCache(options: SearchOptions): SearchResults | Promise; // https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids contain(id: Id): boolean | Promise; clear(): void | Promise; @@ -349,16 +341,16 @@ declare module "flexsearch" { type EnrichedDocumentSearchResults = Array<{ field?: FieldName; tag?: FieldName; - highlight?: TemplateResultHighlighting; result: Array<{ id: Id; - doc: Object | null; + doc: DocumentData | null; + highlight?: string; }>; }>; type MergedDocumentSearchResults = Array<{ id: Id; - doc: Object | null; + doc: DocumentData | null; field?: FieldName[]; tag?: FieldName[]; }>; @@ -367,7 +359,7 @@ declare module "flexsearch" { DefaultDocumentSearchResults | EnrichedDocumentSearchResults | MergedDocumentSearchResults | - Promise; + Resolver; /** * # Document Search Result @@ -399,11 +391,10 @@ declare module "flexsearch" { | number | boolean | null - | DocumentValue[] - | {[key: string]: DocumentValue}; + | DocumentData; type DocumentData = { - [k: string]: DocumentValue; + [key: string]: DocumentValue | DocumentValue[]; }; /** @@ -426,12 +417,12 @@ declare module "flexsearch" { remove(id: Id): this | Promise; remove(document: DocumentData): this | Promise; // https://github.com/nextapps-de/flexsearch#field-search - search(query: string, options?: Limit | DocumentSearchOptions): DocumentSearchResults; - search(query: string, limit: number, options: DocumentSearchOptions): DocumentSearchResults; - search(options: DocumentSearchOptions): DocumentSearchResults; - searchCache(query: string, options?: Limit | DocumentSearchOptions): DocumentSearchResults; - searchCache(query: string, limit: number, options: DocumentSearchOptions): DocumentSearchResults; - searchCache(options: DocumentSearchOptions): DocumentSearchResults; + search(query: string, options?: Limit | DocumentSearchOptions): DocumentSearchResults | Promise; + search(query: string, limit: number, options: DocumentSearchOptions): DocumentSearchResults | Promise; + search(options: DocumentSearchOptions): DocumentSearchResults | Promise; + searchCache(query: string, options?: Limit | DocumentSearchOptions): DocumentSearchResults | Promise; + searchCache(query: string, limit: number, options: DocumentSearchOptions): DocumentSearchResults | Promise; + searchCache(options: DocumentSearchOptions): DocumentSearchResults | Promise; // https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids contain(id: Id): boolean | Promise; clear(): void | Promise; @@ -542,10 +533,18 @@ declare module "flexsearch" { index?: Index | Document; resolve?: boolean; suggest?: boolean; + /** only usable when "resolve" was set to true */ + enrich?: boolean; + boost?: number; + limit?: number; + offset?: number; and?: ResolverOptions | Array; or?: ResolverOptions | Array; xor?: ResolverOptions | Array; not?: ResolverOptions | Array; + pluck?: FieldName; + field?: FieldName; + }; export class Encoder { diff --git a/package-lock.json b/package-lock.json index 9ef7d07..1ac8321 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.147", + "version": "0.8.149", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.147", + "version": "0.8.149", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 24bdd8f..341d6b8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.148", + "version": "0.8.149", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/src/bundle.js b/src/bundle.js index 7f72476..54d22d0 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -298,6 +298,8 @@ if(SUPPORT_SERIALIZE){ /** @export */ ResolverOptions.or; /** @export */ ResolverOptions.xor; /** @export */ ResolverOptions.not; +/** @export */ ResolverOptions.pluck; +/** @export */ ResolverOptions.field; const FlexSearch = { "Index": Index, diff --git a/src/document/search.js b/src/document/search.js index 1f0c393..a5cbdad 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -524,44 +524,46 @@ function highlight_fields(result, query, index, field, tree, template, limit, of for(let j = 0; j < res.length; j++){ let str = ""; let content = parse_simple(res[j]["doc"], path); - let doc_enc = encoder.encode(content); - let doc_org = content.split(encoder.split); + //let doc_enc = encoder.encode(content); + let doc_org = content.split(/\s+/); - for(let k = 0, doc_enc_cur, doc_org_cur; k < doc_enc.length; k++){ - doc_enc_cur = doc_enc[k]; + for(let k = 0, doc_org_cur, doc_enc_cur; k < doc_org.length; k++){ doc_org_cur = doc_org[k]; - - if(!doc_enc_cur || !doc_org_cur){ - continue; - } + //doc_enc_cur = doc_enc[k]; + doc_enc_cur = encoder.encode(doc_org_cur).join(" "); let found; - for(let l = 0, query_enc_cur; l < query_enc.length; l++){ - query_enc_cur = query_enc[l]; - // todo tokenize could be custom also when "strict" was used - if(tokenize === "strict"){ - if(doc_enc_cur === query_enc_cur){ - str += (str ? " " : "") + template.replace("$1", doc_org_cur); - found = true; - break; - } - } - else{ - const position = doc_enc_cur.indexOf(query_enc_cur); - if(position > -1){ - str += (str ? " " : "") + - // prefix - doc_org_cur.substring(0, position) + - // match - template.replace("$1", doc_org_cur.substring(position, query_enc_cur.length)) + - // suffix - doc_org_cur.substring(position + query_enc_cur.length); - found = true; - break; - } - } - //str += doc_enc[k].replace(new RegExp("(" + doc_enc[k] + ")", "g"), template.replace("$1", content)) + if(doc_enc_cur && doc_org_cur){ + + for(let l = 0, query_enc_cur; l < query_enc.length; l++){ + query_enc_cur = query_enc[l]; + // todo tokenize could be custom also when "strict" was used + if(tokenize === "strict"){ + if(doc_enc_cur === query_enc_cur){ + str += (str ? " " : "") + template.replace("$1", doc_org_cur); + found = true; + break; + } + } + else{ + const position = doc_enc_cur.indexOf(query_enc_cur); + //console.log(doc_org_cur, doc_enc_cur, query_enc_cur, position) + if(position > -1){ + str += (str ? " " : "") + + // prefix + doc_org_cur.substring(0, position) + + // match + template.replace("$1", doc_org_cur.substring(position, query_enc_cur.length)) + + // suffix + doc_org_cur.substring(position + query_enc_cur.length); + found = true; + break; + } + } + + //str += doc_enc[k].replace(new RegExp("(" + doc_enc[k] + ")", "g"), template.replace("$1", content)) + } } if(!found){ diff --git a/test/highlight.js b/test/highlight.js index 55fec58..dd2b2bf 100644 --- a/test/highlight.js +++ b/test/highlight.js @@ -12,7 +12,7 @@ const Charset = _Charset || (await import("../src/charset.js")).default; if(!build_light) describe("Result Highlighting", function(){ - it("Should have been indexed properly (tag)", function(){ + it("Should have been indexed properly", function(){ // some test data const data = [{ @@ -61,4 +61,71 @@ if(!build_light) describe("Result Highlighting", function(){ highlight: 'Le clown et ses chiens' }]); }); + + it("Should have been indexed properly (#480)", function(){ + + const index = new Document({ + document: { + store: true, + index: [{ + field: "title", + tokenize: "forward", + encoder: Charset.LatinDefault + },{ + field: "text", + tokenize: "forward", + encoder: Charset.LatinDefault + }] + } + }); + + let all_docs = [{ + id: "469", + title: "Polygon", + text: "A polygon is a two dimensional figure" + },{ + id: "888", + title: "Spain", + text: "Spain is a country." + },{ + id: "473", + text: "Madrid (pronounced: “mah-drid or /məˈdrɪd/) is the capital and largest city of Spain. Madrid is in the middle of Spain, in the Community of Madrid. The Community is a large area that includes the city as well as small towns and villages outside the city. 7 million people live in the Community. More than 3 million live in the city itself. It is the largest city of Spain and, at 655 m (2,100 ft) above sea level, the second highest capital in Europe (after the Andorran capital Andorra la Vella). It is the second largest city in the European Union. As it is the capital city, Madrid is where the monarch lives and also where the government meets. Madrid is the financial centre of Spain. Many large businesses have their main offices there. It has four important footballs teams, Real Madrid, Atlético Madrid, Getafe, and Rayo Vallecano. People who live in Madrid are called madrileños. Madrid was ruled by the Romans from the 2nd century. After AD 711 it was occupied by the Moors. In 1083 Spain was ruled again by Spaniards. Catholic kings ruled the country. By the mid-16th century it had become the capital of a very large empire. Spain was ruled by monarchs from the House of Habsburg, then the House of Bourbon. After the Spanish Civil War it was ruled by a dictator until the mid-1970s when it became a democracy. Although it is a modern city, a lot of its history can be seen and felt as one walks along the streets and in the large squares of the city. There are beautiful parks, famous buildings, art galleries and concert halls. == History == During the history of Spain many different people have lived there. Madrid's name comes from the Arabic word magerit, meaning “place of many streams\\\". The Phoenicians came in 1100 BC, followed by Carthaginians, Romans, Vandals, Visigoths and Moors. It was not until 1492, when the Catholic Monarchs got power, that Spain became a united country. establishments in Europe Category:Establishments in Spain", + title: "Madrid" + }]; + + for(let i = 0; i < all_docs.length; i++){ + index.add(all_docs[i]); + } + + let result = index.search({ + query: "spain", + suggest: true, + enrich: true, + highlight: "$1" + }); + + + expect(result.length).to.equal(2); + expect(result[0]).to.eql({ + field: "title", + result: [{ + id: all_docs[1].id, + doc: all_docs[1], + highlight: 'Spain' + }] + }); + + expect(result[1]).to.eql({ + field: "text", + result: [{ + id: all_docs[1].id, + doc: all_docs[1], + highlight: all_docs[1].text.replace(/(spain)/gi, "$1") + },{ + id: all_docs[2].id, + doc: all_docs[2], + highlight: all_docs[2].text.replace(/(spain)/gi, "$1") + }] + }); + }); });