From 3769259c53fcf82d21777ad1585917333f491fa6 Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Sat, 10 May 2025 21:13:35 +0200 Subject: [PATCH] fix document resolver issues #500 --- dist/flexsearch.bundle.debug.js | 346 +++++++------- dist/flexsearch.bundle.min.js | 65 +-- dist/flexsearch.bundle.module.debug.js | 346 +++++++------- dist/flexsearch.bundle.module.min.js | 65 +-- dist/flexsearch.compact.debug.js | 610 ++++++++++++------------ dist/flexsearch.compact.min.js | 6 +- dist/flexsearch.compact.module.debug.js | 610 ++++++++++++------------ dist/flexsearch.compact.module.min.js | 6 +- dist/flexsearch.es5.debug.js | 77 +-- dist/flexsearch.es5.min.js | 21 +- dist/flexsearch.light.debug.js | 2 +- dist/flexsearch.light.min.js | 2 +- dist/flexsearch.light.module.debug.js | 2 +- dist/flexsearch.light.module.min.js | 2 +- dist/module-debug/document/search.js | 20 +- dist/module-debug/index/search.js | 12 +- dist/module-debug/intersect.js | 16 +- dist/module-debug/resolve/handler.js | 30 +- dist/module-debug/resolver.js | 14 +- dist/module-debug/type.js | 2 +- dist/module-min/document/search.js | 2 +- dist/module-min/index/search.js | 2 +- dist/module-min/intersect.js | 2 +- dist/module-min/resolve/handler.js | 2 +- dist/module-min/resolver.js | 2 +- dist/module/document/search.js | 20 +- dist/module/index/search.js | 12 +- dist/module/intersect.js | 16 +- dist/module/resolve/handler.js | 18 +- dist/module/resolver.js | 14 +- dist/module/type.js | 2 +- index.d.ts | 52 +- package-lock.json | 4 +- package.json | 2 +- src/document/search.js | 20 +- src/index/search.js | 11 +- src/intersect.js | 19 +- src/resolve/handler.js | 54 ++- src/resolver.js | 14 +- src/type.js | 2 +- test/issues.js | 46 ++ 41 files changed, 1379 insertions(+), 1191 deletions(-) diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 4845a46..30cab18 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle/Debug) + * FlexSearch.js v0.8.163 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -250,13 +250,13 @@ v.encode = function(a, c) { this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")); let q; for (; q !== m && 2 < m.length;) { - q = m, m = m.replace(this.N, p => this.stemmer.get(p)); + q = m, m = m.replace(this.N, n => this.stemmer.get(n)); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { h = ""; - for (let q = 0, p = "", r, u; q < m.length; q++) { - r = m.charAt(q), r === p && this.dedupe || ((u = this.mapper && this.mapper.get(r)) || "" === u ? u === p && this.dedupe || !(p = u) || (h += u) : h += p = r); + for (let q = 0, n = "", r, u; q < m.length; q++) { + r = m.charAt(q), r === n && this.dedupe || ((u = this.mapper && this.mapper.get(r)) || "" === u ? u === n && this.dedupe || !(n = u) || (h += u) : h += n = r); } m = h; } @@ -823,18 +823,18 @@ function Qa(a, c, b, e, d, f, g, k) { const k = a.length; let h = [], l, m; l = G(); - for (let t = 0, q, p, r, u; t < c; t++) { - for (let n = 0; n < k; n++) { - if (r = a[n], t < r.length && (q = r[t])) { + for (let t = 0, q, n, r, u; t < c; t++) { + for (let p = 0; p < k; p++) { + if (r = a[p], t < r.length && (q = r[t])) { for (let z = 0; z < q.length; z++) { - p = q[z]; - (m = l[p]) ? l[p]++ : (m = 0, l[p] = 1); + n = q[z]; + (m = l[n]) ? l[n]++ : (m = 0, l[n] = 1); u = h[m] || (h[m] = []); if (!g) { - let x = t + (n || !d ? 0 : f || 0); + let x = t + (p || !d ? 0 : f || 0); u = u[x] || (u[x] = []); } - u.push(p); + u.push(n); if (g && b && m === k - 1 && u.length - e === b) { return e ? u.slice(e) : u; } @@ -858,19 +858,21 @@ function Qa(a, c, b, e, d, f, g, k) { } else { d = []; for (let t = 0, q; t < h.length; t++) { - if (q = h[t], q.length > e) { - 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; + if (q = h[t]) { + if (e && q.length > e) { + e -= q.length; + } else { + if (b && q.length > b || e) { + q = q.slice(e, b + e), b -= q.length, e && (e -= q.length); + } + d.push(q); + if (!b) { + break; + } } } } - h = 1 < d.length ? [].concat.apply([], d) : d[0]; + h = d; } } } @@ -901,14 +903,14 @@ function Ta(a, c, b, e, d) { } else { for (let m = h - 1, t, q = 0; 0 <= m; m--) { t = a[m]; - for (let p = 0; p < t.length; p++) { - if (l = (e = t[p]) && e.length) { + for (let n = 0; n < t.length; n++) { + if (l = (e = t[n]) && e.length) { for (let r = 0; r < l; r++) { if (k = e[r], !g[k]) { if (g[k] = 1, b) { b--; } else { - let u = (p + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + let u = (n + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; (f[u] || (f[u] = [])).push(k); if (++q === c) { return f; @@ -986,24 +988,46 @@ function Ua(a, c, b) { } e = []; let d = [], f = 0, g = 0, k, h, l, m, t; - for (let q = 0, p; q < b.length; q++) { - if (p = b[q]) { + for (let q = 0, n; q < b.length; q++) { + if (n = b[q]) { let r; - if (p.constructor === Y) { - r = p.result; - } else if (p.constructor === Array) { - r = p; + if (n.constructor === Y) { + r = n.result; + } else if (n.constructor === Array) { + r = n; } else { - if (f = p.limit || 0, g = p.offset || 0, l = p.suggest, h = p.resolve, k = (m = p.highlight && h) || p.enrich && h, p.index) { - p.resolve = !1, r = p.index.search(p).result, p.resolve = h, m && (t = p.search); - } else if (p.and) { - r = a.and(p.and); - } else if (p.or) { - r = a.or(p.or); - } else if (p.xor) { - r = a.xor(p.xor); - } else if (p.not) { - r = a.not(p.not); + f = n.limit || 0; + g = n.offset || 0; + l = n.suggest; + h = n.resolve; + k = (m = n.highlight && h) || n.enrich && h; + let u; + n.index && (a.index = u = n.index); + if (n.query || n.tag) { + if (!a.index) { + throw Error("Resolver can't apply because the corresponding Index was never specified"); + } + if (n.field) { + if (!a.index.index) { + throw Error("Resolver can't apply because the corresponding Document Index was not specified"); + } + u = a.index.index.get(n.field); + if (!u) { + throw Error("Resolver can't apply because the specified Document field '" + n.field + "' was not found"); + } + } + n.resolve = !1; + r = u.search(n).result; + n.resolve = h; + m && (t = n.query); + } else if (n.and) { + r = a.and(n.and); + } else if (n.or) { + r = a.or(n.or); + } else if (n.xor) { + r = a.xor(n.xor); + } else if (n.not) { + r = a.not(n.not); } else { continue; } @@ -1109,8 +1133,8 @@ function $a(a, c, b, e, d) { k < l.length && (k = l.length); for (let m = 0, t; m < l.length; m++) { if (t = l[m]) { - for (let q = 0, p; q < t.length; q++) { - p = t[q], g[p] = g[p] ? 2 : 1; + for (let q = 0, n; q < t.length; q++) { + n = t[q], g[n] = g[n] ? 2 : 1; } } } @@ -1120,8 +1144,8 @@ function $a(a, c, b, e, d) { for (let t = 0, q; t < a.length; t++) { if (q = a[t]) { if (l = q[h]) { - for (let p = 0, r; p < l.length; p++) { - if (r = l[p], 1 === g[r]) { + for (let n = 0, r; n < l.length; n++) { + if (r = l[n], 1 === g[r]) { if (b) { b--; } else { @@ -1217,8 +1241,8 @@ function bb(a, c, b, e) { "string" !== typeof d && (d = !1 === d ? "" : "..."); t && (d = q.replace("$1", d)); q = d.length - t; - let p, r; - "object" === typeof h && (p = h.before, 0 === p && (p = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); + let n, r; + "object" === typeof h && (n = h.before, 0 === n && (n = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); t = new Map(); for (let La = 0, ba, hb, na; La < c.length; La++) { let oa; @@ -1237,19 +1261,19 @@ function bb(a, c, b, e) { u = t.get(ba); "string" !== typeof u && (u = ba.encode(a), t.set(ba, u)); for (let va = 0; va < oa.length; va++) { - var n = oa[va].doc; - if (!n) { + var p = oa[va].doc; + if (!p) { continue; } - n = ea(n, na); - if (!n) { + p = ea(p, na); + if (!p) { continue; } - var z = n.trim().split(/\s+/); + var z = p.trim().split(/\s+/); if (!z.length) { continue; } - n = ""; + p = ""; var x = []; let wa = []; var J = -1, B = -1, y = 0; @@ -1267,18 +1291,18 @@ function bb(a, c, b, e) { W && K <= W || (Q = D.indexOf(Q), -1 < Q && (M = (Q ? E.substring(0, Q) : "") + g + E.substring(Q, Q + K) + k + (Q + K < C ? E.substring(Q + K) : ""), W = K, w = !0)); } } - M && (h && (0 > J && (J = n.length + (n ? 1 : 0)), B = n.length + (n ? 1 : 0) + M.length, y += C, wa.push(x.length), x.push({match:M})), n += (n ? " " : "") + M); + M && (h && (0 > J && (J = p.length + (p ? 1 : 0)), B = p.length + (p ? 1 : 0) + M.length, y += C, wa.push(x.length), x.push({match:M})), p += (p ? " " : "") + M); } if (!w) { - E = z[A], n += (n ? " " : "") + E, h && x.push({text:E}); + E = z[A], p += (p ? " " : "") + E, h && x.push({text:E}); } else if (h && y >= h) { break; } } y = wa.length * (f.length - 2); - if (p || r || h && n.length - y > h) { - if (y = h + y - 2 * q, A = B - J, 0 < p && (A += p), 0 < r && (A += r), A <= y) { - z = p ? J - (0 < p ? p : 0) : J - ((y - A) / 2 | 0), x = r ? B + (0 < r ? r : 0) : z + y, l || (0 < z && " " !== n.charAt(z) && " " !== n.charAt(z - 1) && (z = n.indexOf(" ", z), 0 > z && (z = 0)), x < n.length && " " !== n.charAt(x - 1) && " " !== n.charAt(x) && (x = n.lastIndexOf(" ", x), x < B ? x = B : ++x)), n = (z ? d : "") + n.substring(z, x) + (x < n.length ? d : ""); + if (n || r || h && p.length - y > h) { + if (y = h + y - 2 * q, A = B - J, 0 < n && (A += n), 0 < r && (A += r), A <= y) { + z = n ? J - (0 < n ? n : 0) : J - ((y - A) / 2 | 0), x = r ? B + (0 < r ? r : 0) : z + y, l || (0 < z && " " !== p.charAt(z) && " " !== p.charAt(z - 1) && (z = p.indexOf(" ", z), 0 > z && (z = 0)), x < p.length && " " !== p.charAt(x - 1) && " " !== p.charAt(x) && (x = p.lastIndexOf(" ", x), x < B ? x = B : ++x)), p = (z ? d : "") + p.substring(z, x) + (x < p.length ? d : ""); } else { B = []; J = {}; @@ -1311,27 +1335,27 @@ function bb(a, c, b, e) { } C -= q; } - n = x[I].text; + p = x[I].text; if (K = r && D[w]) { if (0 < K) { - if (n.length > K) { + if (p.length > K) { if (A[w + 1] = 1, l) { - n = n.substring(0, K); + p = p.substring(0, K); } else { continue; } } - (K -= n.length) || (K = -1); + (K -= p.length) || (K = -1); D[w] = K; } else { A[w + 1] = 1; continue; } } - if (C + n.length + 1 <= h) { - n = " " + n, B[w] += n; + if (C + p.length + 1 <= h) { + p = " " + p, B[w] += p; } else if (l) { - S = h - C - 1, 0 < S && (n = " " + n.substring(0, S), B[w] += n), A[w + 1] = 1; + S = h - C - 1, 0 < S && (p = " " + p.substring(0, S), B[w] += p), A[w + 1] = 1; } else { A[w + 1] = 1; continue; @@ -1355,50 +1379,50 @@ function bb(a, c, b, e) { } C -= q; } - n = x[I].text; - if (K = p && E[w]) { + p = x[I].text; + if (K = n && E[w]) { if (0 < K) { - if (n.length > K) { + if (p.length > K) { if (A[w] = 1, l) { - n = n.substring(n.length - K); + p = p.substring(p.length - K); } else { continue; } } - (K -= n.length) || (K = -1); + (K -= p.length) || (K = -1); E[w] = K; } else { A[w] = 1; continue; } } - if (C + n.length + 1 <= h) { - n += " ", B[w] = n + B[w]; + if (C + p.length + 1 <= h) { + p += " ", B[w] = p + B[w]; } else if (l) { - S = n.length + 1 - (h - C), 0 <= S && S < n.length && (n = n.substring(S) + " ", B[w] = n + B[w]), A[w] = 1; + S = p.length + 1 - (h - C), 0 <= S && S < p.length && (p = p.substring(S) + " ", B[w] = p + B[w]), A[w] = 1; } else { A[w] = 1; continue; } } } else { - n = x[I].match; - p && (E[w] = p); + p = x[I].match; + n && (E[w] = n); r && (D[w] = r); w && C++; let Ma; I ? !w && q && (C += q) : (y[w] = 1, A[w] = 1); I >= z.length - 1 ? Ma = 1 : I < x.length - 1 && x[I + 1].match ? Ma = 1 : q && (C += q); C -= f.length - 2; - if (!w || C + n.length <= h) { - B[w] = n; + if (!w || C + p.length <= h) { + B[w] = p; } else { S = W = ca = y[w] = 0; break; } Ma && (y[w + 1] = 1, A[w + 1] = 1); } - C += n.length; + C += p.length; S = J[I] = 1; } if (S) { @@ -1411,15 +1435,15 @@ function bb(a, c, b, e) { W ? (H++, M = H) : M++; } } - n = ""; + p = ""; for (let w = 0, I; w < B.length; w++) { - I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], n += I; + I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], p += I; } - d && !y[B.length] && (n += d); + d && !y[B.length] && (p += d); } } - m && (n = n.replace(m, " ")); - oa[va].highlight = n; + m && (p = p.replace(m, " ")); + oa[va].highlight = p; } if (e) { break; @@ -1427,14 +1451,14 @@ function bb(a, c, b, e) { } return c; } -;function Y(a) { +;function Y(a, c) { if (!this || this.constructor !== Y) { - return new Y(a); + return new Y(a, c); } 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; + return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = this.index.search(a).result, this; } - this.index = null; + this.index = c || null; this.result = a || []; this.h = 0; } @@ -1495,7 +1519,7 @@ Pa.prototype.search = function(a, c, b, e) { let l, m; let t = 0; var q = !0; - let p; + let n; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; @@ -1514,14 +1538,14 @@ Pa.prototype.search = function(a, c, b, e) { } } this.store && b.highlight && !q ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !q && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - p = q && this.store && b.highlight; - d = !!p || q && this.store && b.enrich; + n = q && this.store && b.highlight; + d = !!n || q && this.store && b.enrich; c = b.limit || c; var u = b.offset || 0; c || (c = 100); if (m && (!this.db || !e)) { m.constructor !== Array && (m = [m]); - var n = []; + var p = []; for (let B = 0, y; B < m.length; B++) { y = m[B]; if (L(y)) { @@ -1531,43 +1555,43 @@ Pa.prototype.search = function(a, c, b, e) { var z = y.tag; if (z.constructor === Array) { for (var x = 0; x < z.length; x++) { - n.push(y.field, z[x]); + p.push(y.field, z[x]); } } else { - n.push(y.field, z); + p.push(y.field, z); } } else { z = Object.keys(y); for (let A = 0, E, D; A < z.length; A++) { if (E = z[A], D = y[E], D.constructor === Array) { for (x = 0; x < D.length; x++) { - n.push(E, D[x]); + p.push(E, D[x]); } } else { - n.push(E, D); + p.push(E, D); } } } } - if (!n.length) { + if (!p.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - m = n; + m = p; if (!a) { q = []; - if (n.length) { - for (g = 0; g < n.length; g += 2) { + if (p.length) { + for (g = 0; g < p.length; g += 2) { if (this.db) { - r = this.index.get(n[g]); + r = this.index.get(p[g]); if (!r) { - console.warn("Tag '" + n[g] + ":" + n[g + 1] + "' will be skipped because there is no field '" + n[g] + "'."); + console.warn("Tag '" + p[g] + ":" + p[g + 1] + "' will be skipped because there is no field '" + p[g] + "'."); continue; } - q.push(r = r.db.tag(n[g + 1], c, u, d)); + q.push(r = r.db.tag(p[g + 1], c, u, d)); } else { - r = db.call(this, n[g], n[g + 1], c, u, d); + r = db.call(this, p[g], p[g + 1], c, u, d); } - f.push({field:n[g], tag:n[g + 1], result:r}); + f.push({field:p[g], tag:p[g + 1], result:r}); } } return q.length ? Promise.all(q).then(function(B) { @@ -1582,19 +1606,19 @@ Pa.prototype.search = function(a, c, b, e) { } l || (l = this.field); let J; - n = (this.worker || this.db) && !e && []; + p = (this.worker || this.db) && !e && []; for (let B = 0, y, A, E; B < l.length; B++) { A = l[B]; if (this.db && this.tag && !this.F[B]) { continue; } let D; - L(A) || (D = A, A = D.field, a = D.query || a, c = eb(D.limit, c), u = eb(D.offset, u), r = eb(D.suggest, r), p = q && this.store && eb(D.highlight, p), d = !!p || q && this.store && eb(D.enrich, d)); + L(A) || (D = A, A = D.field, a = D.query || a, c = eb(D.limit, c), u = eb(D.offset, u), r = eb(D.suggest, r), n = q && this.store && eb(D.highlight, n), d = !!n || q && this.store && eb(D.enrich, d)); if (e) { y = e[B]; } else { - if (z = D || b, x = this.index.get(A), m && (this.db && (z.tag = m, J = x.db.support_tag_search, z.field = l), J || (z.enrich = !1)), n) { - n[B] = x.search(a, c, z); + if (z = D || b, x = this.index.get(A), m && (this.db && (z.tag = m, J = x.db.support_tag_search, z.field = l), J || (z.enrich = !1)), p) { + p[B] = x.search(a, c, z); z && d && (z.enrich = d); continue; } else { @@ -1612,7 +1636,7 @@ Pa.prototype.search = function(a, c, b, e) { if (H && H.length) { x++, z.push(H); } else if (!r) { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } } @@ -1623,13 +1647,13 @@ Pa.prototype.search = function(a, c, b, e) { if (console.warn("Tag '" + m[C] + ":" + m[C + 1] + "' will be skipped because there is no field '" + m[C] + "'."), r) { continue; } else { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } if (M = (H = H && H.get(m[C + 1])) && H.length) { x++, z.push(H); } else if (!r) { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } } @@ -1637,7 +1661,7 @@ Pa.prototype.search = function(a, c, b, e) { y = Ua(y, z, q); E = y.length; if (!E && !r) { - return q ? y : new Y(y); + return q ? y : new Y(y, this); } x--; } @@ -1645,10 +1669,10 @@ Pa.prototype.search = function(a, c, b, e) { if (E) { g[t] = A, f.push(y), t++; } else if (1 === l.length) { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } - if (n) { + if (p) { if (this.db && m && m.length && !J) { for (d = 0; d < m.length; d += 2) { g = this.index.get(m[d]); @@ -1656,42 +1680,42 @@ Pa.prototype.search = function(a, c, b, e) { if (console.warn("Tag '" + m[d] + ":" + m[d + 1] + "' was not found because there is no field '" + m[d] + "'."), r) { continue; } else { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } - n.push(g.db.tag(m[d + 1], c, u, !1)); + p.push(g.db.tag(m[d + 1], c, u, !1)); } } const B = this; - return Promise.all(n).then(function(y) { + return Promise.all(p).then(function(y) { return y.length ? B.search(a, c, b, y) : y; }); } if (!t) { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } if (k && (!d || !this.store)) { - return f[0]; + return f = f[0], q || (f.index = this), f; } - n = []; + p = []; for (u = 0; u < g.length; u++) { r = f[u]; - d && r.length && "undefined" === typeof r[0].doc && (this.db ? n.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = X.call(this, r)); + d && r.length && "undefined" === typeof r[0].doc && (this.db ? p.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = X.call(this, r)); if (k) { - return q ? p ? cb(a, r, this.index, k, p) : r : new Y(r); + return q ? n ? cb(a, r, this.index, k, n) : r : new Y(r, this); } f[u] = {field:g[u], result:r}; } - if (d && this.db && n.length) { + if (d && this.db && p.length) { const B = this; - return Promise.all(n).then(function(y) { + return Promise.all(p).then(function(y) { for (let A = 0; A < y.length; A++) { f[A].result = y[A]; } - return h ? fb(f) : p ? cb(a, f, B.index, k, p) : f; + return h ? fb(f) : n ? cb(a, f, B.index, k, n) : f; }); } - return h ? fb(f) : p ? cb(a, f, this.index, k, p) : f; + return h ? fb(f) : n ? cb(a, f, this.index, k, n) : f; }; function eb(a, c) { return "undefined" === typeof a ? c : a; @@ -2129,19 +2153,19 @@ P.prototype.add = function(a, c, b, e) { const l = c.length; if (l) { const m = G(), t = G(), q = this.resolution; - for (let p = 0; p < l; p++) { - let r = c[this.rtl ? l - 1 - p : p]; + for (let n = 0; n < l; n++) { + let r = c[this.rtl ? l - 1 - n : n]; var d = r.length; if (d && (e || !t[r])) { - var f = this.score ? this.score(c, r, p, null, 0) : vb(q, l, p), g = ""; + var f = this.score ? this.score(c, r, n, null, 0) : vb(q, l, n), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let u = 0, n; u < d; u++) { + for (let u = 0, p; u < d; u++) { for (f = d; f > u; f--) { g = r.substring(u, f); - n = this.rtl ? d - 1 - u : u; - var k = this.score ? this.score(c, r, p, g, n) : vb(q, l, p, d, n); + p = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(c, r, n, g, p) : vb(q, l, n, d, p); wb(this, t, g, k, a, b); } } @@ -2152,7 +2176,7 @@ P.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) : vb(q, l, p, d, k); + var h = this.score ? this.score(c, r, n, g, k) : vb(q, l, n, d, k); wb(this, t, g, h, a, b); } g = ""; @@ -2165,12 +2189,12 @@ P.prototype.add = function(a, c, b, e) { break; } default: - if (wb(this, t, r, f, a, b), e && 1 < l && p < l - 1) { - for (d = G(), g = this.U, f = r, k = Math.min(e + 1, this.rtl ? p + 1 : l - p), d[f] = 1, h = 1; h < k; h++) { - if ((r = c[this.rtl ? l - 1 - p - h : p + h]) && !d[r]) { + if (wb(this, t, r, f, a, b), e && 1 < l && n < l - 1) { + for (d = G(), g = this.U, f = r, k = Math.min(e + 1, this.rtl ? n + 1 : l - n), d[f] = 1, h = 1; h < k; h++) { + if ((r = c[this.rtl ? l - 1 - n - h : n + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(c, f, p, r, h - 1) : vb(g + (l / 2 > g ? 0 : 1), l, p, k - 1, h - 1), n = this.bidirectional && r > f; - wb(this, m, n ? f : r, u, a, b, n ? r : f); + const u = this.score ? this.score(c, f, n, r, h - 1) : vb(g + (l / 2 > g ? 0 : 1), l, n, k - 1, h - 1), p = this.bidirectional && r > f; + wb(this, m, p ? f : r, u, a, b, p ? r : f); } } } @@ -2215,50 +2239,50 @@ function vb(a, c, b, e, d) { b && (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, q = (h = b.resolve) && b.enrich, m = b.boost, t = b.resolution, l = this.db && b.tag); "undefined" === typeof h && (h = this.resolve); f = this.depth && !1 !== f; - let p = this.encoder.encode(a, !f); - d = p.length; + let n = this.encoder.encode(a, !f); + d = n.length; c = c || (h ? 100 : 0); if (1 === d) { - return xb.call(this, p[0], "", c, k, h, q, l); + return xb.call(this, n[0], "", c, k, h, q, l); } if (2 === d && f && !g) { - return xb.call(this, p[1], p[0], c, k, h, q, l); + return xb.call(this, n[1], n[0], c, k, h, q, l); } - let r = G(), u = 0, n; - f && (n = p[0], u = 1); - t || 0 === t || (t = n ? this.U : this.resolution); + let r = G(), u = 0, p; + f && (p = n[0], u = 1); + t || 0 === t || (t = p ? this.U : this.resolution); if (this.db) { - if (this.db.search && (b = this.db.search(this, p, c, k, g, h, q, l), !1 !== b)) { + if (this.db.search && (b = this.db.search(this, n, c, k, g, h, q, l), !1 !== b)) { return b; } const z = this; return async function() { for (let x, J; u < d; u++) { - if ((J = p[u]) && !r[J]) { + if ((J = n[u]) && !r[J]) { r[J] = 1; - x = await yb(z, J, n, 0, 0, !1, !1); + x = await yb(z, J, p, 0, 0, !1, !1); if (x = zb(x, e, g, t)) { e = x; break; } - n && (g && x && e.length || (n = J)); + p && (g && x && e.length || (p = J)); } - g && n && u === d - 1 && !e.length && (t = z.resolution, n = "", u = -1, r = G()); + g && p && u === d - 1 && !e.length && (t = z.resolution, p = "", u = -1, r = G()); } return Ab(e, t, c, k, g, m, h); }(); } for (let z, x; u < d; u++) { - if ((x = p[u]) && !r[x]) { + if ((x = n[u]) && !r[x]) { r[x] = 1; - z = yb(this, x, n, 0, 0, !1, !1); + z = yb(this, x, p, 0, 0, !1, !1); if (z = zb(z, e, g, t)) { e = z; break; } - n && (g && z && e.length || (n = x)); + p && (g && z && e.length || (p = x)); } - g && n && u === d - 1 && !e.length && (t = this.resolution, n = "", u = -1, r = G()); + g && p && u === d - 1 && !e.length && (t = this.resolution, p = "", u = -1, r = G()); } return Ab(e, t, c, k, g, m, h); }; @@ -2267,15 +2291,15 @@ function Ab(a, c, b, e, d, f, g) { if (1 < k) { h = Sa(a, c, b, e, d, f, g); } else if (1 === k) { - return g ? Va.call(null, a[0], b, e) : new Y(a[0]); + return g ? Va.call(null, a[0], b, e) : new Y(a[0], this); } - return g ? h : new Y(h); + return g ? h : new Y(h, this); } function xb(a, c, b, e, d, f, g) { a = yb(this, a, c, b, e, d, f, g); return this.db ? a.then(function(k) { - return d ? k || [] : new Y(k); - }) : a && a.length ? d ? Va.call(this, a, b, e) : new Y(a) : d ? [] : new Y(); + return d ? k || [] : new Y(k, this); + }) : a && a.length ? d ? Va.call(this, a, b, e) : new Y(a, this) : d ? [] : new Y([], this); } function zb(a, c, b, e) { let d = []; @@ -2656,14 +2680,14 @@ v.commit = async function(a, c, b) { var t; if (m && m.length) { const q = Math.max(m.length, l.length); - for (let p = 0, r, u; p < q; p++) { - if ((u = l[p]) && u.length) { - if ((r = m[p]) && r.length) { + for (let n = 0, r, u; n < q; n++) { + if ((u = l[n]) && u.length) { + if ((r = m[n]) && r.length) { for (t = 0; t < u.length; t++) { r.push(u[t]); } } else { - m[p] = u; + m[n] = u; } t = 1; } diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index 88f375e..37f94a3 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle) + * FlexSearch.js v0.8.163 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -15,7 +15,7 @@ v.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if v.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&N(this);return this}; v.encode=function(a,b){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(N,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=la?a.normalize("NFKD").replace(la,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(c)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var h=this.G.get(m);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(N,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ -this.A+")$"));let q;for(;q!==m&&2this.stemmer.get(p))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(q)));if(m&&this.replacer)for(h=0;m&&hthis.stemmer.get(n))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(q)));if(m&&this.replacer)for(h=0;m&&hthis.S&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==t)if(b){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.B.set(a,e),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return e};function N(a){a.H=null;a.B.clear();a.G.clear()};let pa,qa;async function ra(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":qa=a.options||{};(b=a.factory)?(Function("return "+b)()(self),pa=new self.FlexSearch.Index(qa),delete self.FlexSearch):pa=new O(qa);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=qa.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await qa.import.call(pa,e[0]),pa.import(e[0],a)):(d=e&&pa[b].apply(pa,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function sa(a){ta.call(a,"add");ta.call(a,"append");ta.call(a,"search");ta.call(a,"update");ta.call(a,"remove");ta.call(a,"searchCache")}let ua,xa,ya;function za(){ua=ya=0} function ta(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);ua?ya||(ya=Date.now()-xa>=this.priority*this.priority*3):(ua=setTimeout(za,0),xa=Date.now());if(ya){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let Aa=0; function Ba(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=G();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++Aa]=function(){h(d);1E9c||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d= -[];for(let t=0,q;te)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}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?X.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?X.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ta(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};Y.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:t}=Wa(this,"and",arguments);return Ya.call(this,f,g,k,h,l,m,t)}return d?this.resolve(b,c,e):this}; +function Qa(a,b,c,e,d,f,g,k){if(a=a[g])if(e===b.length-1){if(a.constructor===Array){if(c[e]){for(b=0;bc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d= +[];for(let t=0,q;te)e-=q.length;else{if(c&&q.length>c||e)q=q.slice(e,c+e),c-=q.length,e&&(e-=q.length);d.push(q);if(!c)break}h=d}}return h} +function Ta(a,b,c,e,d){const f=[],g=G();let k;var h=a.length;let l;if(e)for(d=h-1;0<=d;d--){if(l=(e=a[d])&&e.length)for(h=0;hb?b?a.slice(c,c+b):a.slice(c):a,e?X.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?X.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ta(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};Y.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:t}=Wa(this,"and",arguments);return Ya.call(this,f,g,k,h,l,m,t)}return d?this.resolve(b,c,e):this}; function Ya(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=fa(a))return this.result=Sa(a,b,c,e,g,this.h,f),f?d?X.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};Y.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Wa(this,"xor",arguments);return Za.call(this,a,b,c,e,d,f,g)}; function Za(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=$a.call(this,a,c,e,f,this.h),f?d?X.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function $a(a,b,c,e,d){const f=[],g=G();let k=0;for(let h=0,l;hJ&&(J=n.length+(n?1:0)),B=n.length+(n?1:0)+M.length,z+=E,wa.push(x.length),x.push({match:M})),n+=(n?" ":"")+M)}if(!w)D=y[A],n+=(n?" ":"")+D,h&&x.push({text:D});else if(h&&z>=h)break}z=wa.length*(f.length-2);if(p||r||h&&n.length-z>h)if(z=h+z-2*q,A=B-J, -0y&&(y=0)),x=x.length-1){if(I>= -x.length){A[w+1]=1;I>=y.length&&(z[w+1]=1);continue}E-=q}n=x[I].text;if(K=r&&C[w])if(0K)if(A[w+1]=1,l)n=n.substring(0,K);else continue;(K-=n.length)||(K=-1);C[w]=K}else{A[w+1]=1;continue}if(E+n.length+1<=h)n=" "+n,B[w]+=n;else if(l)S=h-E-1,0=I){if(0>I){A[w]=1;z[w]=1;continue}E-=q}n=x[I].text;if(K=p&&D[w])if(0K)if(A[w]=1,l)n=n.substring(n.length- -K);else continue;(K-=n.length)||(K=-1);D[w]=K}else{A[w]=1;continue}if(E+n.length+1<=h)n+=" ",B[w]=n+B[w];else if(l)S=n.length+1-(h-E),0<=S&&S=y.length-1?Ma=1:Ic||e)a=a.slice(e,e+c);d&&(a=X.call(this,a));return a}} -function X(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cJ&&(J=p.length+(p?1:0)),B=p.length+(p?1:0)+M.length,z+=E,wa.push(x.length),x.push({match:M})),p+=(p?" ":"")+M)}if(!w)D=y[A],p+=(p?" ":"")+D,h&&x.push({text:D});else if(h&&z>=h)break}z=wa.length*(f.length-2);if(n||r||h&&p.length-z>h)if(z=h+z-2*q,A=B-J, +0y&&(y=0)),x=x.length-1){if(I>= +x.length){A[w+1]=1;I>=y.length&&(z[w+1]=1);continue}E-=q}p=x[I].text;if(K=r&&C[w])if(0K)if(A[w+1]=1,l)p=p.substring(0,K);else continue;(K-=p.length)||(K=-1);C[w]=K}else{A[w+1]=1;continue}if(E+p.length+1<=h)p=" "+p,B[w]+=p;else if(l)S=h-E-1,0=I){if(0>I){A[w]=1;z[w]=1;continue}E-=q}p=x[I].text;if(K=n&&D[w])if(0K)if(A[w]=1,l)p=p.substring(p.length- +K);else continue;(K-=p.length)||(K=-1);D[w]=K}else{A[w]=1;continue}if(E+p.length+1<=h)p+=" ",B[w]=p+B[w];else if(l)S=p.length+1-(h-E),0<=S&&S=y.length-1?Ma=1:Ic||e)a=a.slice(e,e+c);d&&(a=X.call(this,a));return a}}function X(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; ib.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};ib.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};ib.prototype.clear=function(){this.cache.clear();this.h=""};const lb={normalize:!1,numeric:!1,dedupe:!1};const mb={};const nb=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const ob=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),pb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const qb={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var rb={Exact:lb,Default:mb,Normalize:mb,LatinBalance:{mapper:nb},LatinAdvanced:{mapper:nb,matcher:ob,replacer:pb},LatinExtra:{mapper:nb,replacer:pb.concat([/(?!^)[aeo]/g,""]),matcher:ob},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cd.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else sb(this.map,a),this.depth&&sb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&tb(this));this.cache&&this.cache.remove(a);return this}; -function sb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;du;f--){g=r.substring(u,f);n=this.rtl?d-1-u:u;var k=this.score?this.score(b,r,p,g,n):vb(q, -l,p,d,n);wb(this,t,g,k,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,p,k-1,h-1),n=this.bidirectional&&r>f;wb(this,m,n?f:r,u,a,c,n?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&tb(this));return this}; +function sb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;du;f--){g=r.substring(u,f);p=this.rtl?d-1-u:u;var k=this.score?this.score(b,r,n,g,p):vb(q, +l,n,d,p);wb(this,t,g,k,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,n,k-1,h-1),p=this.bidirectional&&r>f;wb(this,m,p?f:r,u,a,c,p?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&tb(this));return this}; function wb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=G()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new R(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function vb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function O(a,b){if(!this||this.constructor!==O)return new O(a);if(a){var c=L(a)?a:a.preset;c&&(a=Object.assign({},ub[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=L(a.encoder)?rb[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ma(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +function vb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function O(a,b){if(!this||this.constructor!==O)return new O(a);if(a){var c=L(a)?a:a.preset;c&&(a=Object.assign({},ub[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=L(a.encoder)?rb[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ma(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new T(c):new Map;this.ctx=c?new T(c):new Map;this.reg=b||(this.fastupdate?c?new T(c):new Map:c?new U(c):new Set);this.U=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new ib(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.T=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}v=O.prototype; v.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};v.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};v.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function tb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} v.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};v.append=function(a,b){return this.add(a,b,!0)};v.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};v.update=function(a,b){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; @@ -92,8 +93,8 @@ g.enrich(h):h}return k})};v.tag=function(a,b=0,c=0,e=!1){a=this.db.transaction(" v.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};const Gb={Index:O,Charset:rb,Encoder:ma,Document:W,Worker:Ba,Resolver:Y,IndexedDB:Eb,Language:{}},Hb="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let Ib;(Ib=Hb.define)&&Ib.amd?Ib([],function(){return Gb}):"object"===typeof Hb.exports?Hb.exports=Gb:Hb.FlexSearch=Gb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index d5ce4b4..d2617d6 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle/Module/Debug) + * FlexSearch.js v0.8.163 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -249,13 +249,13 @@ v.encode = function(a, c) { this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")); let q; for (; q !== m && 2 < m.length;) { - q = m, m = m.replace(this.N, p => this.stemmer.get(p)); + q = m, m = m.replace(this.N, n => this.stemmer.get(n)); } } if (m && (this.mapper || this.dedupe && 1 < m.length)) { h = ""; - for (let q = 0, p = "", r, u; q < m.length; q++) { - r = m.charAt(q), r === p && this.dedupe || ((u = this.mapper && this.mapper.get(r)) || "" === u ? u === p && this.dedupe || !(p = u) || (h += u) : h += p = r); + for (let q = 0, n = "", r, u; q < m.length; q++) { + r = m.charAt(q), r === n && this.dedupe || ((u = this.mapper && this.mapper.get(r)) || "" === u ? u === n && this.dedupe || !(n = u) || (h += u) : h += n = r); } m = h; } @@ -822,18 +822,18 @@ function Qa(a, c, b, e, d, f, g, k) { const k = a.length; let h = [], l, m; l = G(); - for (let t = 0, q, p, r, u; t < c; t++) { - for (let n = 0; n < k; n++) { - if (r = a[n], t < r.length && (q = r[t])) { + for (let t = 0, q, n, r, u; t < c; t++) { + for (let p = 0; p < k; p++) { + if (r = a[p], t < r.length && (q = r[t])) { for (let z = 0; z < q.length; z++) { - p = q[z]; - (m = l[p]) ? l[p]++ : (m = 0, l[p] = 1); + n = q[z]; + (m = l[n]) ? l[n]++ : (m = 0, l[n] = 1); u = h[m] || (h[m] = []); if (!g) { - let x = t + (n || !d ? 0 : f || 0); + let x = t + (p || !d ? 0 : f || 0); u = u[x] || (u[x] = []); } - u.push(p); + u.push(n); if (g && b && m === k - 1 && u.length - e === b) { return e ? u.slice(e) : u; } @@ -857,19 +857,21 @@ function Qa(a, c, b, e, d, f, g, k) { } else { d = []; for (let t = 0, q; t < h.length; t++) { - if (q = h[t], q.length > e) { - 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; + if (q = h[t]) { + if (e && q.length > e) { + e -= q.length; + } else { + if (b && q.length > b || e) { + q = q.slice(e, b + e), b -= q.length, e && (e -= q.length); + } + d.push(q); + if (!b) { + break; + } } } } - h = 1 < d.length ? [].concat.apply([], d) : d[0]; + h = d; } } } @@ -900,14 +902,14 @@ function Ta(a, c, b, e, d) { } else { for (let m = h - 1, t, q = 0; 0 <= m; m--) { t = a[m]; - for (let p = 0; p < t.length; p++) { - if (l = (e = t[p]) && e.length) { + for (let n = 0; n < t.length; n++) { + if (l = (e = t[n]) && e.length) { for (let r = 0; r < l; r++) { if (k = e[r], !g[k]) { if (g[k] = 1, b) { b--; } else { - let u = (p + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + let u = (n + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; (f[u] || (f[u] = [])).push(k); if (++q === c) { return f; @@ -985,24 +987,46 @@ function Ua(a, c, b) { } e = []; let d = [], f = 0, g = 0, k, h, l, m, t; - for (let q = 0, p; q < b.length; q++) { - if (p = b[q]) { + for (let q = 0, n; q < b.length; q++) { + if (n = b[q]) { let r; - if (p.constructor === Y) { - r = p.result; - } else if (p.constructor === Array) { - r = p; + if (n.constructor === Y) { + r = n.result; + } else if (n.constructor === Array) { + r = n; } else { - if (f = p.limit || 0, g = p.offset || 0, l = p.suggest, h = p.resolve, k = (m = p.highlight && h) || p.enrich && h, p.index) { - p.resolve = !1, r = p.index.search(p).result, p.resolve = h, m && (t = p.search); - } else if (p.and) { - r = a.and(p.and); - } else if (p.or) { - r = a.or(p.or); - } else if (p.xor) { - r = a.xor(p.xor); - } else if (p.not) { - r = a.not(p.not); + f = n.limit || 0; + g = n.offset || 0; + l = n.suggest; + h = n.resolve; + k = (m = n.highlight && h) || n.enrich && h; + let u; + n.index && (a.index = u = n.index); + if (n.query || n.tag) { + if (!a.index) { + throw Error("Resolver can't apply because the corresponding Index was never specified"); + } + if (n.field) { + if (!a.index.index) { + throw Error("Resolver can't apply because the corresponding Document Index was not specified"); + } + u = a.index.index.get(n.field); + if (!u) { + throw Error("Resolver can't apply because the specified Document field '" + n.field + "' was not found"); + } + } + n.resolve = !1; + r = u.search(n).result; + n.resolve = h; + m && (t = n.query); + } else if (n.and) { + r = a.and(n.and); + } else if (n.or) { + r = a.or(n.or); + } else if (n.xor) { + r = a.xor(n.xor); + } else if (n.not) { + r = a.not(n.not); } else { continue; } @@ -1108,8 +1132,8 @@ function $a(a, c, b, e, d) { k < l.length && (k = l.length); for (let m = 0, t; m < l.length; m++) { if (t = l[m]) { - for (let q = 0, p; q < t.length; q++) { - p = t[q], g[p] = g[p] ? 2 : 1; + for (let q = 0, n; q < t.length; q++) { + n = t[q], g[n] = g[n] ? 2 : 1; } } } @@ -1119,8 +1143,8 @@ function $a(a, c, b, e, d) { for (let t = 0, q; t < a.length; t++) { if (q = a[t]) { if (l = q[h]) { - for (let p = 0, r; p < l.length; p++) { - if (r = l[p], 1 === g[r]) { + for (let n = 0, r; n < l.length; n++) { + if (r = l[n], 1 === g[r]) { if (b) { b--; } else { @@ -1216,8 +1240,8 @@ function bb(a, c, b, e) { "string" !== typeof d && (d = !1 === d ? "" : "..."); t && (d = q.replace("$1", d)); q = d.length - t; - let p, r; - "object" === typeof h && (p = h.before, 0 === p && (p = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); + let n, r; + "object" === typeof h && (n = h.before, 0 === n && (n = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); t = new Map(); for (let Ka = 0, ba, eb, na; Ka < c.length; Ka++) { let oa; @@ -1236,19 +1260,19 @@ function bb(a, c, b, e) { u = t.get(ba); "string" !== typeof u && (u = ba.encode(a), t.set(ba, u)); for (let va = 0; va < oa.length; va++) { - var n = oa[va].doc; - if (!n) { + var p = oa[va].doc; + if (!p) { continue; } - n = ea(n, na); - if (!n) { + p = ea(p, na); + if (!p) { continue; } - var z = n.trim().split(/\s+/); + var z = p.trim().split(/\s+/); if (!z.length) { continue; } - n = ""; + p = ""; var x = []; let wa = []; var J = -1, B = -1, y = 0; @@ -1266,18 +1290,18 @@ function bb(a, c, b, e) { W && K <= W || (Q = D.indexOf(Q), -1 < Q && (M = (Q ? E.substring(0, Q) : "") + g + E.substring(Q, Q + K) + k + (Q + K < C ? E.substring(Q + K) : ""), W = K, w = !0)); } } - M && (h && (0 > J && (J = n.length + (n ? 1 : 0)), B = n.length + (n ? 1 : 0) + M.length, y += C, wa.push(x.length), x.push({match:M})), n += (n ? " " : "") + M); + M && (h && (0 > J && (J = p.length + (p ? 1 : 0)), B = p.length + (p ? 1 : 0) + M.length, y += C, wa.push(x.length), x.push({match:M})), p += (p ? " " : "") + M); } if (!w) { - E = z[A], n += (n ? " " : "") + E, h && x.push({text:E}); + E = z[A], p += (p ? " " : "") + E, h && x.push({text:E}); } else if (h && y >= h) { break; } } y = wa.length * (f.length - 2); - if (p || r || h && n.length - y > h) { - if (y = h + y - 2 * q, A = B - J, 0 < p && (A += p), 0 < r && (A += r), A <= y) { - z = p ? J - (0 < p ? p : 0) : J - ((y - A) / 2 | 0), x = r ? B + (0 < r ? r : 0) : z + y, l || (0 < z && " " !== n.charAt(z) && " " !== n.charAt(z - 1) && (z = n.indexOf(" ", z), 0 > z && (z = 0)), x < n.length && " " !== n.charAt(x - 1) && " " !== n.charAt(x) && (x = n.lastIndexOf(" ", x), x < B ? x = B : ++x)), n = (z ? d : "") + n.substring(z, x) + (x < n.length ? d : ""); + if (n || r || h && p.length - y > h) { + if (y = h + y - 2 * q, A = B - J, 0 < n && (A += n), 0 < r && (A += r), A <= y) { + z = n ? J - (0 < n ? n : 0) : J - ((y - A) / 2 | 0), x = r ? B + (0 < r ? r : 0) : z + y, l || (0 < z && " " !== p.charAt(z) && " " !== p.charAt(z - 1) && (z = p.indexOf(" ", z), 0 > z && (z = 0)), x < p.length && " " !== p.charAt(x - 1) && " " !== p.charAt(x) && (x = p.lastIndexOf(" ", x), x < B ? x = B : ++x)), p = (z ? d : "") + p.substring(z, x) + (x < p.length ? d : ""); } else { B = []; J = {}; @@ -1310,27 +1334,27 @@ function bb(a, c, b, e) { } C -= q; } - n = x[I].text; + p = x[I].text; if (K = r && D[w]) { if (0 < K) { - if (n.length > K) { + if (p.length > K) { if (A[w + 1] = 1, l) { - n = n.substring(0, K); + p = p.substring(0, K); } else { continue; } } - (K -= n.length) || (K = -1); + (K -= p.length) || (K = -1); D[w] = K; } else { A[w + 1] = 1; continue; } } - if (C + n.length + 1 <= h) { - n = " " + n, B[w] += n; + if (C + p.length + 1 <= h) { + p = " " + p, B[w] += p; } else if (l) { - S = h - C - 1, 0 < S && (n = " " + n.substring(0, S), B[w] += n), A[w + 1] = 1; + S = h - C - 1, 0 < S && (p = " " + p.substring(0, S), B[w] += p), A[w + 1] = 1; } else { A[w + 1] = 1; continue; @@ -1354,50 +1378,50 @@ function bb(a, c, b, e) { } C -= q; } - n = x[I].text; - if (K = p && E[w]) { + p = x[I].text; + if (K = n && E[w]) { if (0 < K) { - if (n.length > K) { + if (p.length > K) { if (A[w] = 1, l) { - n = n.substring(n.length - K); + p = p.substring(p.length - K); } else { continue; } } - (K -= n.length) || (K = -1); + (K -= p.length) || (K = -1); E[w] = K; } else { A[w] = 1; continue; } } - if (C + n.length + 1 <= h) { - n += " ", B[w] = n + B[w]; + if (C + p.length + 1 <= h) { + p += " ", B[w] = p + B[w]; } else if (l) { - S = n.length + 1 - (h - C), 0 <= S && S < n.length && (n = n.substring(S) + " ", B[w] = n + B[w]), A[w] = 1; + S = p.length + 1 - (h - C), 0 <= S && S < p.length && (p = p.substring(S) + " ", B[w] = p + B[w]), A[w] = 1; } else { A[w] = 1; continue; } } } else { - n = x[I].match; - p && (E[w] = p); + p = x[I].match; + n && (E[w] = n); r && (D[w] = r); w && C++; let La; I ? !w && q && (C += q) : (y[w] = 1, A[w] = 1); I >= z.length - 1 ? La = 1 : I < x.length - 1 && x[I + 1].match ? La = 1 : q && (C += q); C -= f.length - 2; - if (!w || C + n.length <= h) { - B[w] = n; + if (!w || C + p.length <= h) { + B[w] = p; } else { S = W = ca = y[w] = 0; break; } La && (y[w + 1] = 1, A[w + 1] = 1); } - C += n.length; + C += p.length; S = J[I] = 1; } if (S) { @@ -1410,15 +1434,15 @@ function bb(a, c, b, e) { W ? (H++, M = H) : M++; } } - n = ""; + p = ""; for (let w = 0, I; w < B.length; w++) { - I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], n += I; + I = (w && y[w] ? " " : (w && !d ? " " : "") + d) + B[w], p += I; } - d && !y[B.length] && (n += d); + d && !y[B.length] && (p += d); } } - m && (n = n.replace(m, " ")); - oa[va].highlight = n; + m && (p = p.replace(m, " ")); + oa[va].highlight = p; } if (e) { break; @@ -1426,14 +1450,14 @@ function bb(a, c, b, e) { } return c; } -;function Y(a) { +;function Y(a, c) { if (!this || this.constructor !== Y) { - return new Y(a); + return new Y(a, c); } 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; + return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = this.index.search(a).result, this; } - this.index = null; + this.index = c || null; this.result = a || []; this.h = 0; } @@ -1494,7 +1518,7 @@ Pa.prototype.search = function(a, c, b, e) { let l, m; let t = 0; var q = !0; - let p; + let n; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; @@ -1513,14 +1537,14 @@ Pa.prototype.search = function(a, c, b, e) { } } this.store && b.highlight && !q ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !q && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - p = q && this.store && b.highlight; - d = !!p || q && this.store && b.enrich; + n = q && this.store && b.highlight; + d = !!n || q && this.store && b.enrich; c = b.limit || c; var u = b.offset || 0; c || (c = 100); if (m && (!this.db || !e)) { m.constructor !== Array && (m = [m]); - var n = []; + var p = []; for (let B = 0, y; B < m.length; B++) { y = m[B]; if (L(y)) { @@ -1530,43 +1554,43 @@ Pa.prototype.search = function(a, c, b, e) { var z = y.tag; if (z.constructor === Array) { for (var x = 0; x < z.length; x++) { - n.push(y.field, z[x]); + p.push(y.field, z[x]); } } else { - n.push(y.field, z); + p.push(y.field, z); } } else { z = Object.keys(y); for (let A = 0, E, D; A < z.length; A++) { if (E = z[A], D = y[E], D.constructor === Array) { for (x = 0; x < D.length; x++) { - n.push(E, D[x]); + p.push(E, D[x]); } } else { - n.push(E, D); + p.push(E, D); } } } } - if (!n.length) { + if (!p.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - m = n; + m = p; if (!a) { q = []; - if (n.length) { - for (g = 0; g < n.length; g += 2) { + if (p.length) { + for (g = 0; g < p.length; g += 2) { if (this.db) { - r = this.index.get(n[g]); + r = this.index.get(p[g]); if (!r) { - console.warn("Tag '" + n[g] + ":" + n[g + 1] + "' will be skipped because there is no field '" + n[g] + "'."); + console.warn("Tag '" + p[g] + ":" + p[g + 1] + "' will be skipped because there is no field '" + p[g] + "'."); continue; } - q.push(r = r.db.tag(n[g + 1], c, u, d)); + q.push(r = r.db.tag(p[g + 1], c, u, d)); } else { - r = db.call(this, n[g], n[g + 1], c, u, d); + r = db.call(this, p[g], p[g + 1], c, u, d); } - f.push({field:n[g], tag:n[g + 1], result:r}); + f.push({field:p[g], tag:p[g + 1], result:r}); } } return q.length ? Promise.all(q).then(function(B) { @@ -1581,19 +1605,19 @@ Pa.prototype.search = function(a, c, b, e) { } l || (l = this.field); let J; - n = (this.worker || this.db) && !e && []; + p = (this.worker || this.db) && !e && []; for (let B = 0, y, A, E; B < l.length; B++) { A = l[B]; if (this.db && this.tag && !this.F[B]) { continue; } let D; - L(A) || (D = A, A = D.field, a = D.query || a, c = fb(D.limit, c), u = fb(D.offset, u), r = fb(D.suggest, r), p = q && this.store && fb(D.highlight, p), d = !!p || q && this.store && fb(D.enrich, d)); + L(A) || (D = A, A = D.field, a = D.query || a, c = fb(D.limit, c), u = fb(D.offset, u), r = fb(D.suggest, r), n = q && this.store && fb(D.highlight, n), d = !!n || q && this.store && fb(D.enrich, d)); if (e) { y = e[B]; } else { - if (z = D || b, x = this.index.get(A), m && (this.db && (z.tag = m, J = x.db.support_tag_search, z.field = l), J || (z.enrich = !1)), n) { - n[B] = x.search(a, c, z); + if (z = D || b, x = this.index.get(A), m && (this.db && (z.tag = m, J = x.db.support_tag_search, z.field = l), J || (z.enrich = !1)), p) { + p[B] = x.search(a, c, z); z && d && (z.enrich = d); continue; } else { @@ -1611,7 +1635,7 @@ Pa.prototype.search = function(a, c, b, e) { if (H && H.length) { x++, z.push(H); } else if (!r) { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } } @@ -1622,13 +1646,13 @@ Pa.prototype.search = function(a, c, b, e) { if (console.warn("Tag '" + m[C] + ":" + m[C + 1] + "' will be skipped because there is no field '" + m[C] + "'."), r) { continue; } else { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } if (M = (H = H && H.get(m[C + 1])) && H.length) { x++, z.push(H); } else if (!r) { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } } @@ -1636,7 +1660,7 @@ Pa.prototype.search = function(a, c, b, e) { y = Ua(y, z, q); E = y.length; if (!E && !r) { - return q ? y : new Y(y); + return q ? y : new Y(y, this); } x--; } @@ -1644,10 +1668,10 @@ Pa.prototype.search = function(a, c, b, e) { if (E) { g[t] = A, f.push(y), t++; } else if (1 === l.length) { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } - if (n) { + if (p) { if (this.db && m && m.length && !J) { for (d = 0; d < m.length; d += 2) { g = this.index.get(m[d]); @@ -1655,42 +1679,42 @@ Pa.prototype.search = function(a, c, b, e) { if (console.warn("Tag '" + m[d] + ":" + m[d + 1] + "' was not found because there is no field '" + m[d] + "'."), r) { continue; } else { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } } - n.push(g.db.tag(m[d + 1], c, u, !1)); + p.push(g.db.tag(m[d + 1], c, u, !1)); } } const B = this; - return Promise.all(n).then(function(y) { + return Promise.all(p).then(function(y) { return y.length ? B.search(a, c, b, y) : y; }); } if (!t) { - return q ? f : new Y(f); + return q ? f : new Y(f, this); } if (k && (!d || !this.store)) { - return f[0]; + return f = f[0], q || (f.index = this), f; } - n = []; + p = []; for (u = 0; u < g.length; u++) { r = f[u]; - d && r.length && "undefined" === typeof r[0].doc && (this.db ? n.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = X.call(this, r)); + d && r.length && "undefined" === typeof r[0].doc && (this.db ? p.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = X.call(this, r)); if (k) { - return q ? p ? cb(a, r, this.index, k, p) : r : new Y(r); + return q ? n ? cb(a, r, this.index, k, n) : r : new Y(r, this); } f[u] = {field:g[u], result:r}; } - if (d && this.db && n.length) { + if (d && this.db && p.length) { const B = this; - return Promise.all(n).then(function(y) { + return Promise.all(p).then(function(y) { for (let A = 0; A < y.length; A++) { f[A].result = y[A]; } - return h ? gb(f) : p ? cb(a, f, B.index, k, p) : f; + return h ? gb(f) : n ? cb(a, f, B.index, k, n) : f; }); } - return h ? gb(f) : p ? cb(a, f, this.index, k, p) : f; + return h ? gb(f) : n ? cb(a, f, this.index, k, n) : f; }; function fb(a, c) { return "undefined" === typeof a ? c : a; @@ -2128,19 +2152,19 @@ P.prototype.add = function(a, c, b, e) { const l = c.length; if (l) { const m = G(), t = G(), q = this.resolution; - for (let p = 0; p < l; p++) { - let r = c[this.rtl ? l - 1 - p : p]; + for (let n = 0; n < l; n++) { + let r = c[this.rtl ? l - 1 - n : n]; var d = r.length; if (d && (e || !t[r])) { - var f = this.score ? this.score(c, r, p, null, 0) : vb(q, l, p), g = ""; + var f = this.score ? this.score(c, r, n, null, 0) : vb(q, l, n), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let u = 0, n; u < d; u++) { + for (let u = 0, p; u < d; u++) { for (f = d; f > u; f--) { g = r.substring(u, f); - n = this.rtl ? d - 1 - u : u; - var k = this.score ? this.score(c, r, p, g, n) : vb(q, l, p, d, n); + p = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(c, r, n, g, p) : vb(q, l, n, d, p); wb(this, t, g, k, a, b); } } @@ -2151,7 +2175,7 @@ P.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) : vb(q, l, p, d, k); + var h = this.score ? this.score(c, r, n, g, k) : vb(q, l, n, d, k); wb(this, t, g, h, a, b); } g = ""; @@ -2164,12 +2188,12 @@ P.prototype.add = function(a, c, b, e) { break; } default: - if (wb(this, t, r, f, a, b), e && 1 < l && p < l - 1) { - for (d = G(), g = this.U, f = r, k = Math.min(e + 1, this.rtl ? p + 1 : l - p), d[f] = 1, h = 1; h < k; h++) { - if ((r = c[this.rtl ? l - 1 - p - h : p + h]) && !d[r]) { + if (wb(this, t, r, f, a, b), e && 1 < l && n < l - 1) { + for (d = G(), g = this.U, f = r, k = Math.min(e + 1, this.rtl ? n + 1 : l - n), d[f] = 1, h = 1; h < k; h++) { + if ((r = c[this.rtl ? l - 1 - n - h : n + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(c, f, p, r, h - 1) : vb(g + (l / 2 > g ? 0 : 1), l, p, k - 1, h - 1), n = this.bidirectional && r > f; - wb(this, m, n ? f : r, u, a, b, n ? r : f); + const u = this.score ? this.score(c, f, n, r, h - 1) : vb(g + (l / 2 > g ? 0 : 1), l, n, k - 1, h - 1), p = this.bidirectional && r > f; + wb(this, m, p ? f : r, u, a, b, p ? r : f); } } } @@ -2214,50 +2238,50 @@ function vb(a, c, b, e, d) { b && (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, q = (h = b.resolve) && b.enrich, m = b.boost, t = b.resolution, l = this.db && b.tag); "undefined" === typeof h && (h = this.resolve); f = this.depth && !1 !== f; - let p = this.encoder.encode(a, !f); - d = p.length; + let n = this.encoder.encode(a, !f); + d = n.length; c = c || (h ? 100 : 0); if (1 === d) { - return xb.call(this, p[0], "", c, k, h, q, l); + return xb.call(this, n[0], "", c, k, h, q, l); } if (2 === d && f && !g) { - return xb.call(this, p[1], p[0], c, k, h, q, l); + return xb.call(this, n[1], n[0], c, k, h, q, l); } - let r = G(), u = 0, n; - f && (n = p[0], u = 1); - t || 0 === t || (t = n ? this.U : this.resolution); + let r = G(), u = 0, p; + f && (p = n[0], u = 1); + t || 0 === t || (t = p ? this.U : this.resolution); if (this.db) { - if (this.db.search && (b = this.db.search(this, p, c, k, g, h, q, l), !1 !== b)) { + if (this.db.search && (b = this.db.search(this, n, c, k, g, h, q, l), !1 !== b)) { return b; } const z = this; return async function() { for (let x, J; u < d; u++) { - if ((J = p[u]) && !r[J]) { + if ((J = n[u]) && !r[J]) { r[J] = 1; - x = await yb(z, J, n, 0, 0, !1, !1); + x = await yb(z, J, p, 0, 0, !1, !1); if (x = zb(x, e, g, t)) { e = x; break; } - n && (g && x && e.length || (n = J)); + p && (g && x && e.length || (p = J)); } - g && n && u === d - 1 && !e.length && (t = z.resolution, n = "", u = -1, r = G()); + g && p && u === d - 1 && !e.length && (t = z.resolution, p = "", u = -1, r = G()); } return Ab(e, t, c, k, g, m, h); }(); } for (let z, x; u < d; u++) { - if ((x = p[u]) && !r[x]) { + if ((x = n[u]) && !r[x]) { r[x] = 1; - z = yb(this, x, n, 0, 0, !1, !1); + z = yb(this, x, p, 0, 0, !1, !1); if (z = zb(z, e, g, t)) { e = z; break; } - n && (g && z && e.length || (n = x)); + p && (g && z && e.length || (p = x)); } - g && n && u === d - 1 && !e.length && (t = this.resolution, n = "", u = -1, r = G()); + g && p && u === d - 1 && !e.length && (t = this.resolution, p = "", u = -1, r = G()); } return Ab(e, t, c, k, g, m, h); }; @@ -2266,15 +2290,15 @@ function Ab(a, c, b, e, d, f, g) { if (1 < k) { h = Sa(a, c, b, e, d, f, g); } else if (1 === k) { - return g ? Va.call(null, a[0], b, e) : new Y(a[0]); + return g ? Va.call(null, a[0], b, e) : new Y(a[0], this); } - return g ? h : new Y(h); + return g ? h : new Y(h, this); } function xb(a, c, b, e, d, f, g) { a = yb(this, a, c, b, e, d, f, g); return this.db ? a.then(function(k) { - return d ? k || [] : new Y(k); - }) : a && a.length ? d ? Va.call(this, a, b, e) : new Y(a) : d ? [] : new Y(); + return d ? k || [] : new Y(k, this); + }) : a && a.length ? d ? Va.call(this, a, b, e) : new Y(a, this) : d ? [] : new Y([], this); } function zb(a, c, b, e) { let d = []; @@ -2655,14 +2679,14 @@ v.commit = async function(a, c, b) { var t; if (m && m.length) { const q = Math.max(m.length, l.length); - for (let p = 0, r, u; p < q; p++) { - if ((u = l[p]) && u.length) { - if ((r = m[p]) && r.length) { + for (let n = 0, r, u; n < q; n++) { + if ((u = l[n]) && u.length) { + if ((r = m[n]) && r.length) { for (t = 0; t < u.length; t++) { r.push(u[t]); } } else { - m[p] = u; + m[n] = u; } t = 1; } diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 873266d..909b4ac 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle/Module) + * FlexSearch.js v0.8.163 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -15,7 +15,7 @@ v.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if v.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&N(this);return this}; v.encode=function(a,b){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(N,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=la?a.normalize("NFKD").replace(la,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(c)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.L)if(this.H){var h=this.G.get(m);if(h||""===h){h&&e.push(h);continue}}else this.H=setTimeout(N,50,this);if(this.stemmer){this.N||(this.N=new RegExp("(?!^)("+ -this.A+")$"));let q;for(;q!==m&&2this.stemmer.get(p))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(q)));if(m&&this.replacer)for(h=0;m&&hthis.stemmer.get(n))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(q)));if(m&&this.replacer)for(h=0;m&&hthis.S&&(this.G.clear(),this.L=this.L/1.1|0));if(m){if(m!==t)if(b){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.K&&(this.B.set(a,e),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return e};function N(a){a.H=null;a.B.clear();a.G.clear()};let pa,qa;async function ra(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":qa=a.options||{};(b=a.factory)?(Function("return "+b)()(self),pa=new self.FlexSearch.Index(qa),delete self.FlexSearch):pa=new O(qa);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=qa.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await qa.import.call(pa,e[0]),pa.import(e[0],a)):(d=e&&pa[b].apply(pa,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function sa(a){ta.call(a,"add");ta.call(a,"append");ta.call(a,"search");ta.call(a,"update");ta.call(a,"remove");ta.call(a,"searchCache")}let ua,xa,ya;function za(){ua=ya=0} function ta(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);ua?ya||(ya=Date.now()-xa>=this.priority*this.priority*3):(ua=setTimeout(za,0),xa=Date.now());if(ya){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let Aa=0; function Ba(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=G();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++Aa]=function(){h(d);1E9c||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d= -[];for(let t=0,q;te)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}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?X.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?X.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ta(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};Y.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:t}=Wa(this,"and",arguments);return Ya.call(this,f,g,k,h,l,m,t)}return d?this.resolve(b,c,e):this}; +function Qa(a,b,c,e,d,f,g,k){if(a=a[g])if(e===b.length-1){if(a.constructor===Array){if(c[e]){for(b=0;bc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d= +[];for(let t=0,q;te)e-=q.length;else{if(c&&q.length>c||e)q=q.slice(e,c+e),c-=q.length,e&&(e-=q.length);d.push(q);if(!c)break}h=d}}return h} +function Ta(a,b,c,e,d){const f=[],g=G();let k;var h=a.length;let l;if(e)for(d=h-1;0<=d;d--){if(l=(e=a[d])&&e.length)for(h=0;hb?b?a.slice(c,c+b):a.slice(c):a,e?X.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?X.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ta(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};Y.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:t}=Wa(this,"and",arguments);return Ya.call(this,f,g,k,h,l,m,t)}return d?this.resolve(b,c,e):this}; function Ya(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=fa(a))return this.result=Sa(a,b,c,e,g,this.h,f),f?d?X.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};Y.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Wa(this,"xor",arguments);return Za.call(this,a,b,c,e,d,f,g)}; function Za(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=$a.call(this,a,c,e,f,this.h),f?d?X.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function $a(a,b,c,e,d){const f=[],g=G();let k=0;for(let h=0,l;hJ&&(J=n.length+(n?1:0)),B=n.length+(n?1:0)+M.length,z+=E,wa.push(x.length),x.push({match:M})),n+=(n?" ":"")+M)}if(!w)D=y[A],n+=(n?" ":"")+D,h&&x.push({text:D});else if(h&&z>=h)break}z=wa.length*(f.length-2);if(p||r||h&&n.length-z>h)if(z=h+z-2*q,A=B-J, -0y&&(y=0)),x=x.length-1){if(I>= -x.length){A[w+1]=1;I>=y.length&&(z[w+1]=1);continue}E-=q}n=x[I].text;if(K=r&&C[w])if(0K)if(A[w+1]=1,l)n=n.substring(0,K);else continue;(K-=n.length)||(K=-1);C[w]=K}else{A[w+1]=1;continue}if(E+n.length+1<=h)n=" "+n,B[w]+=n;else if(l)S=h-E-1,0=I){if(0>I){A[w]=1;z[w]=1;continue}E-=q}n=x[I].text;if(K=p&&D[w])if(0K)if(A[w]=1,l)n=n.substring(n.length- -K);else continue;(K-=n.length)||(K=-1);D[w]=K}else{A[w]=1;continue}if(E+n.length+1<=h)n+=" ",B[w]=n+B[w];else if(l)S=n.length+1-(h-E),0<=S&&S=y.length-1?La=1:Ic||e)a=a.slice(e,e+c);d&&(a=X.call(this,a));return a}} -function X(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cJ&&(J=p.length+(p?1:0)),B=p.length+(p?1:0)+M.length,z+=E,wa.push(x.length),x.push({match:M})),p+=(p?" ":"")+M)}if(!w)D=y[A],p+=(p?" ":"")+D,h&&x.push({text:D});else if(h&&z>=h)break}z=wa.length*(f.length-2);if(n||r||h&&p.length-z>h)if(z=h+z-2*q,A=B-J, +0y&&(y=0)),x=x.length-1){if(I>= +x.length){A[w+1]=1;I>=y.length&&(z[w+1]=1);continue}E-=q}p=x[I].text;if(K=r&&C[w])if(0K)if(A[w+1]=1,l)p=p.substring(0,K);else continue;(K-=p.length)||(K=-1);C[w]=K}else{A[w+1]=1;continue}if(E+p.length+1<=h)p=" "+p,B[w]+=p;else if(l)S=h-E-1,0=I){if(0>I){A[w]=1;z[w]=1;continue}E-=q}p=x[I].text;if(K=n&&D[w])if(0K)if(A[w]=1,l)p=p.substring(p.length- +K);else continue;(K-=p.length)||(K=-1);D[w]=K}else{A[w]=1;continue}if(E+p.length+1<=h)p+=" ",B[w]=p+B[w];else if(l)S=p.length+1-(h-E),0<=S&&S=y.length-1?La=1:Ic||e)a=a.slice(e,e+c);d&&(a=X.call(this,a));return a}}function X(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; ib.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};ib.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};ib.prototype.clear=function(){this.cache.clear();this.h=""};const lb={normalize:!1,numeric:!1,dedupe:!1};const mb={};const nb=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const ob=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),pb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const qb={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var rb={Exact:lb,Default:mb,Normalize:mb,LatinBalance:{mapper:nb},LatinAdvanced:{mapper:nb,matcher:ob,replacer:pb},LatinExtra:{mapper:nb,replacer:pb.concat([/(?!^)[aeo]/g,""]),matcher:ob},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cd.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else sb(this.map,a),this.depth&&sb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&tb(this));this.cache&&this.cache.remove(a);return this}; -function sb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;du;f--){g=r.substring(u,f);n=this.rtl?d-1-u:u;var k=this.score?this.score(b,r,p,g,n):vb(q, -l,p,d,n);wb(this,t,g,k,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,p,k-1,h-1),n=this.bidirectional&&r>f;wb(this,m,n?f:r,u,a,c,n?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&tb(this));return this}; +function sb(a,b){let c=0;var e="undefined"===typeof b;if(a.constructor===Array)for(let d=0,f,g;du;f--){g=r.substring(u,f);p=this.rtl?d-1-u:u;var k=this.score?this.score(b,r,n,g,p):vb(q, +l,n,d,p);wb(this,t,g,k,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,n,k-1,h-1),p=this.bidirectional&&r>f;wb(this,m,p?f:r,u,a,c,p?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&tb(this));return this}; function wb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=G()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new R(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function vb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function O(a,b){if(!this||this.constructor!==O)return new O(a);if(a){var c=L(a)?a:a.preset;c&&(a=Object.assign({},ub[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=L(a.encoder)?rb[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ma(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +function vb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function O(a,b){if(!this||this.constructor!==O)return new O(a);if(a){var c=L(a)?a:a.preset;c&&(a=Object.assign({},ub[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=L(a.encoder)?rb[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new ma(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new T(c):new Map;this.ctx=c?new T(c):new Map;this.reg=b||(this.fastupdate?c?new T(c):new Map:c?new U(c):new Set);this.U=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new ib(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.T=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}v=O.prototype; v.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};v.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};v.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function tb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} v.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};v.append=function(a,b){return this.add(a,b,!0)};v.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};v.update=function(a,b){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; @@ -92,8 +93,8 @@ g.enrich(h):h}return k})};v.tag=function(a,b=0,c=0,e=!1){a=this.db.transaction(" v.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:O,Charset:rb,Encoder:ma,Document:W,Worker:Ba,Resolver:Y,IndexedDB:Eb,Language:{}}; diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 693c466..a819b32 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle/Debug) + * FlexSearch.js v0.8.163 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -8,11 +8,11 @@ (function(self){'use strict'; var A; function I(a, c, b) { - const e = typeof b, d = typeof a; - if ("undefined" !== e) { + const f = typeof b, d = typeof a; + if ("undefined" !== f) { if ("undefined" !== d) { if (b) { - if ("function" === d && e === d) { + if ("function" === d && f === d) { return function(k) { return a(b(k)); }; @@ -23,16 +23,16 @@ function I(a, c, b) { return b.concat(a); } if (c === Map) { - var f = new Map(b); + var e = new Map(b); for (var g of a) { - f.set(g[0], g[1]); + e.set(g[0], g[1]); } - return f; + return e; } if (c === Set) { g = new Set(b); - for (f of a.values()) { - g.add(f); + for (e of a.values()) { + g.add(e); } return g; } @@ -79,14 +79,14 @@ function S(a = {}) { A = S.prototype; A.assign = function(a) { this.normalize = I(a.normalize, !0, this.normalize); - let c = a.include, b = c || a.exclude || a.split, e; + let c = a.include, b = c || a.exclude || a.split, f; if (b || "" === b) { if ("object" === typeof b && b.constructor !== RegExp) { let d = ""; - e = !c; + f = !c; c || (d += "\\p{Z}"); b.letter && (d += "\\p{L}"); - b.number && (d += "\\p{N}", e = !!c); + b.number && (d += "\\p{N}", f = !!c); b.symbol && (d += "\\p{S}"); b.punctuation && (d += "\\p{P}"); b.control && (d += "\\p{C}"); @@ -95,13 +95,13 @@ A.assign = function(a) { } try { this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); - } catch (f) { + } catch (e) { console.error("Your split configuration:", b, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { - this.split = b, e = !1 === b || 2 > "a1a".split(b).length; + this.split = b, f = !1 === b || 2 > "a1a".split(b).length; } - this.numeric = I(a.numeric, e); + this.numeric = I(a.numeric, f); } else { try { this.split = I(this.split, ca); @@ -203,29 +203,29 @@ A.encode = function(a, c) { this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = J(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; - for (let m = 0, n, C; m < k.length; m++) { - if ((n = C = k[m]) && !(n.length < this.minlength || n.length > this.maxlength)) { + let f = [], d = J(), e, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; + for (let m = 0, n, B; m < k.length; m++) { + if ((n = B = k[m]) && !(n.length < this.minlength || n.length > this.maxlength)) { if (c) { if (d[n]) { continue; } d[n] = 1; } else { - if (f === n) { + if (e === n) { continue; } - f = n; + e = n; } if (b) { - e.push(n); + f.push(n); } else { if (!this.filter || ("function" === typeof this.filter ? this.filter(n) : !this.filter.has(n))) { if (this.cache && n.length <= this.L) { if (this.H) { var h = this.G.get(n); if (h || "" === h) { - h && e.push(h); + h && f.push(h); continue; } } else { @@ -252,9 +252,9 @@ A.encode = function(a, c) { n = n.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && C.length <= this.L && (this.G.set(C, n), this.G.size > this.O && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && B.length <= this.L && (this.G.set(B, n), this.G.size > this.O && (this.G.clear(), this.L = this.L / 1.1 | 0)); if (n) { - if (n !== C) { + if (n !== B) { if (c) { if (d[n]) { continue; @@ -267,15 +267,15 @@ A.encode = function(a, c) { g = n; } } - e.push(n); + f.push(n); } } } } } - this.finalize && (e = this.finalize(e) || e); - this.cache && a.length <= this.K && (this.F.set(a, e), this.F.size > this.O && (this.F.clear(), this.K = this.K / 1.1 | 0)); - return e; + this.finalize && (f = this.finalize(f) || f); + this.cache && a.length <= this.K && (this.F.set(a, f), this.F.size > this.O && (this.F.clear(), this.K = this.K / 1.1 | 0)); + return f; }; function V(a) { a.H = null; @@ -298,59 +298,59 @@ function W(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; - let e; - "function" === typeof b && (e = b, delete c[c.length - 1]); + let f; + "function" === typeof b && (f = b, delete c[c.length - 1]); la ? na || (na = Date.now() - ma >= this.priority * this.priority * 3) : (la = setTimeout(oa, 0), ma = Date.now()); if (na) { - const f = this; + const e = this; return new Promise(g => { setTimeout(function() { - g(f[a + "Async"].apply(f, c)); + g(e[a + "Async"].apply(e, c)); }, 0); }); } const d = this[a].apply(this, c); - b = d.then ? d : new Promise(f => f(d)); - e && b.then(e); + b = d.then ? d : new Promise(e => e(d)); + f && b.then(f); return b; }; } ;function pa(a, c = 0) { - let b = [], e = []; + let b = [], f = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { - e.push(d), e.length === c && (b.push(e), e = []); + f.push(d), f.length === c && (b.push(f), f = []); } - e.length && b.push(e); + f.length && b.push(f); return b; } function qa(a, c) { c || (c = new Map()); - for (let b = 0, e; b < a.length; b++) { - e = a[b], c.set(e[0], e[1]); + for (let b = 0, f; b < a.length; b++) { + f = a[b], c.set(f[0], f[1]); } return c; } function ra(a, c = 0) { - let b = [], e = []; + let b = [], f = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], pa(d[1])[0]]), e.length === c && (b.push(e), e = []); + f.push([d[0], pa(d[1])[0]]), f.length === c && (b.push(f), f = []); } - e.length && b.push(e); + f.length && b.push(f); return b; } function sa(a, c) { c || (c = new Map()); - for (let b = 0, e, d; b < a.length; b++) { - e = a[b], d = c.get(e[0]), c.set(e[0], qa(e[1], d)); + for (let b = 0, f, d; b < a.length; b++) { + f = a[b], d = c.get(f[0]), c.set(f[0], qa(f[1], d)); } return c; } function ta(a) { let c = [], b = []; - for (const e of a.keys()) { - b.push(e), 250000 === b.length && (c.push(b), b = []); + for (const f of a.keys()) { + b.push(f), 250000 === b.length && (c.push(b), b = []); } b.length && c.push(b); return c; @@ -362,26 +362,26 @@ function wa(a, c) { } return c; } -function xa(a, c, b, e, d, f, g = 0) { - const k = e && e.constructor === Array; - var h = k ? e.shift() : e; +function xa(a, c, b, f, d, e, g = 0) { + const k = f && f.constructor === Array; + var h = k ? f.shift() : f; if (!h) { - return this.export(a, c, d, f + 1); + return this.export(a, c, d, e + 1); } if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const m = this; return h.then(function() { - return xa.call(m, a, c, b, k ? e : null, d, f, g + 1); + return xa.call(m, a, c, b, k ? f : null, d, e, g + 1); }); } - return xa.call(this, a, c, b, k ? e : null, d, f, g + 1); + return xa.call(this, a, c, b, k ? f : null, d, e, g + 1); } function ya(a, c) { let b = ""; - for (const e of a.entries()) { - a = e[0]; - const d = e[1]; - let f = ""; + for (const f of a.entries()) { + a = f[0]; + const d = f[1]; + let e = ""; for (let g = 0, k; g < d.length; g++) { k = d[g] || [""]; let h = ""; @@ -389,10 +389,10 @@ function ya(a, c) { h += (h ? "," : "") + ("string" === c ? '"' + k[m] + '"' : k[m]); } h = "[" + h + "]"; - f += (f ? "," : "") + h; + e += (e ? "," : "") + h; } - f = '["' + a + '",[' + f + "]]"; - b += (b ? "," : "") + f; + e = '["' + a + '",[' + e + "]]"; + b += (b ? "," : "") + e; } return b; } @@ -404,37 +404,37 @@ function ya(a, c) { } for (let k = 0, h; k < this.field.length; k++) { h = this.D[k]; - var e = this.index.get(this.field[k]); + var f = this.index.get(this.field[k]); if ("function" === typeof h) { var d = h(c); - d && e.add(a, d, !1, !0); + d && f.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), za(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), za(c, h, this.J, 0, f, a, h[0], b); } } } if (this.tag) { - for (e = 0; e < this.B.length; e++) { - var f = this.B[e], g = this.R[e]; + for (f = 0; f < this.B.length; f++) { + var e = this.B[f], g = this.R[f]; d = this.tag.get(g); let k = J(); - if ("function" === typeof f) { - if (f = f(c), !f) { + if ("function" === typeof e) { + if (e = e(c), !e) { continue; } } else { - const h = f.I; + const h = e.I; if (h && !h(c)) { continue; } - f.constructor === String && (f = "" + f); - f = R(c, f); + e.constructor === String && (e = "" + e); + e = R(c, e); } - if (d && f) { - L(f) && (f = [f]); - for (let h = 0, m, n; h < f.length; h++) { - m = f[h], k[m] || (k[m] = 1, (g = d.get(m)) ? n = g : d.set(m, n = []), b && n.includes(a) || (n.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])))); + if (d && e) { + L(e) && (e = [e]); + for (let h = 0, m, n; h < e.length; h++) { + m = e[h], k[m] || (k[m] = 1, (g = d.get(m)) ? n = g : d.set(m, n = []), b && n.includes(a) || (n.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -469,56 +469,56 @@ function ya(a, c) { } return this; }; -function Aa(a, c, b, e, d, f) { +function Aa(a, c, b, f, d, e) { a = a[d]; - if (e === b.length - 1) { - c[d] = f || a; + if (f === b.length - 1) { + c[d] = e || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Aa(a, c, b, e, d); + Aa(a, c, b, f, d); } } else { - c = c[d] || (c[d] = J()), d = b[++e], Aa(a, c, b, e, d); + c = c[d] || (c[d] = J()), d = b[++f], Aa(a, c, b, f, d); } } } -function za(a, c, b, e, d, f, g, k) { +function za(a, c, b, f, d, e, g, k) { if (a = a[g]) { - if (e === c.length - 1) { + if (f === c.length - 1) { if (a.constructor === Array) { - if (b[e]) { + if (b[f]) { for (c = 0; c < a.length; c++) { - d.add(f, a[c], !0, !0); + d.add(e, a[c], !0, !0); } return; } a = a.join(" "); } - d.add(f, a, k, !0); + d.add(e, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - za(a, c, b, e, d, f, g, k); + za(a, c, b, f, d, e, g, k); } } else { - g = c[++e], za(a, c, b, e, d, f, g, k); + g = c[++f], za(a, c, b, f, d, e, g, k); } } } } ;function Ba(a, c) { - const b = J(), e = []; - for (let d = 0, f; d < c.length; d++) { - f = c[d]; - for (let g = 0; g < f.length; g++) { - b[f[g]] = 1; + const b = J(), f = []; + for (let d = 0, e; d < c.length; d++) { + e = c[d]; + for (let g = 0; g < e.length; g++) { + b[e[g]] = 1; } } - for (let d = 0, f; d < a.length; d++) { - f = a[d], b[f] && (e.push(f), b[f] = 0); + for (let d = 0, e; d < a.length; d++) { + e = a[d], b[e] && (f.push(e), b[e] = 0); } - return e; + return f; } ;function Ca(a, c, b) { if (!a.length) { @@ -527,59 +527,59 @@ function za(a, c, b, e, d, f, g, k) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } - let e = []; - for (let d = 0, f, g; d < a.length; d++) { - if ((f = a[d]) && (g = f.length)) { + let f = []; + for (let d = 0, e, g; d < a.length; d++) { + if ((e = a[d]) && (g = e.length)) { if (b) { if (b >= g) { b -= g; continue; } - b < g && (f = c ? f.slice(b, b + c) : f.slice(b), g = f.length, b = 0); + b < g && (e = c ? e.slice(b, b + c) : e.slice(b), g = e.length, b = 0); } - g > c && (f = f.slice(0, c), g = c); - if (!e.length && g >= c) { - return f; + g > c && (e = e.slice(0, c), g = c); + if (!f.length && g >= c) { + return e; } - e.push(f); + f.push(e); c -= g; if (!c) { break; } } } - return e = 1 < e.length ? [].concat.apply([], e) : e[0]; + return f = 1 < f.length ? [].concat.apply([], f) : f[0]; } -;function Da(a, c, b, e, d) { - let f, g, k; - "string" === typeof d ? (f = d, d = "") : f = d.template; - if (!f) { +;function Da(a, c, b, f, d) { + let e, g, k; + "string" === typeof d ? (e = d, d = "") : e = d.template; + if (!e) { throw Error('No template pattern was specified by the search option "highlight"'); } - g = f.indexOf("$1"); + g = e.indexOf("$1"); if (-1 === g) { - throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + e); } - k = f.substring(g + 2); - g = f.substring(0, g); + k = e.substring(g + 2); + g = e.substring(0, g); let h = d && d.boundary, m = !d || !1 !== d.clip, n = d && d.merge && k && g && new RegExp(k + " " + g, "g"); d = d && d.ellipsis; - var C = 0; + var B = 0; if ("object" === typeof d) { var x = d.template; - C = x.length - 2; + B = x.length - 2; d = d.pattern; } "string" !== typeof d && (d = !1 === d ? "" : "..."); - C && (d = x.replace("$1", d)); - x = d.length - C; + B && (d = x.replace("$1", d)); + x = d.length - B; let q, r; "object" === typeof h && (q = h.before, 0 === q && (q = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); - C = new Map(); + B = new Map(); for (let ua = 0, T, Ja, aa; ua < c.length; ua++) { let ba; - if (e) { - ba = c, aa = e; + if (f) { + ba = c, aa = f; } else { var w = c[ua]; aa = w.field; @@ -590,8 +590,8 @@ function za(a, c, b, e, d, f, g, k) { } Ja = b.get(aa); T = Ja.encoder; - w = C.get(T); - "string" !== typeof w && (w = T.encode(a), C.set(T, w)); + w = B.get(T); + "string" !== typeof w && (w = T.encode(a), B.set(T, w)); for (let ia = 0; ia < ba.length; ia++) { var l = ba[ia].doc; if (!l) { @@ -608,7 +608,7 @@ function za(a, c, b, e, d, f, g, k) { l = ""; var v = []; let ja = []; - var E = -1, t = -1, B = 0; + var E = -1, t = -1, C = 0; for (var y = 0; y < u.length; y++) { var z = u[y], H = T.encode(z); H = 1 < H.length ? H.join(" ") : H[0]; @@ -623,22 +623,22 @@ function za(a, c, b, e, d, f, g, k) { Q && G <= Q || (N = H.indexOf(N), -1 < N && (K = (N ? z.substring(0, N) : "") + g + z.substring(N, N + G) + k + (N + G < D ? z.substring(N + G) : ""), Q = G, p = !0)); } } - K && (h && (0 > E && (E = l.length + (l ? 1 : 0)), t = l.length + (l ? 1 : 0) + K.length, B += D, ja.push(v.length), v.push({match:K})), l += (l ? " " : "") + K); + K && (h && (0 > E && (E = l.length + (l ? 1 : 0)), t = l.length + (l ? 1 : 0) + K.length, C += D, ja.push(v.length), v.push({match:K})), l += (l ? " " : "") + K); } if (!p) { z = u[y], l += (l ? " " : "") + z, h && v.push({text:z}); - } else if (h && B >= h) { + } else if (h && C >= h) { break; } } - B = ja.length * (f.length - 2); - if (q || r || h && l.length - B > h) { - if (B = h + B - 2 * x, y = t - E, 0 < q && (y += q), 0 < r && (y += r), y <= B) { - u = q ? E - (0 < q ? q : 0) : E - ((B - y) / 2 | 0), v = r ? t + (0 < r ? r : 0) : u + B, m || (0 < u && " " !== l.charAt(u) && " " !== l.charAt(u - 1) && (u = l.indexOf(" ", u), 0 > u && (u = 0)), v < l.length && " " !== l.charAt(v - 1) && " " !== l.charAt(v) && (v = l.lastIndexOf(" ", v), v < t ? v = t : ++v)), l = (u ? d : "") + l.substring(u, v) + (v < l.length ? d : ""); + C = ja.length * (e.length - 2); + if (q || r || h && l.length - C > h) { + if (C = h + C - 2 * x, y = t - E, 0 < q && (y += q), 0 < r && (y += r), y <= C) { + u = q ? E - (0 < q ? q : 0) : E - ((C - y) / 2 | 0), v = r ? t + (0 < r ? r : 0) : u + C, m || (0 < u && " " !== l.charAt(u) && " " !== l.charAt(u - 1) && (u = l.indexOf(" ", u), 0 > u && (u = 0)), v < l.length && " " !== l.charAt(v - 1) && " " !== l.charAt(v) && (v = l.lastIndexOf(" ", v), v < t ? v = t : ++v)), l = (u ? d : "") + l.substring(u, v) + (v < l.length ? d : ""); } else { t = []; E = {}; - B = {}; + C = {}; y = {}; z = {}; H = {}; @@ -655,14 +655,14 @@ function za(a, c, b, e, d, f, g, k) { F += K; if (E[F]) { D -= x; - B[p + 1] = 1; + C[p + 1] = 1; y[p + 1] = 1; continue; } if (F >= v.length - 1) { if (F >= v.length) { y[p + 1] = 1; - F >= u.length && (B[p + 1] = 1); + F >= u.length && (C[p + 1] = 1); continue; } D -= x; @@ -700,13 +700,13 @@ function za(a, c, b, e, d, f, g, k) { if (E[F]) { D -= x; y[p] = 1; - B[p] = 1; + C[p] = 1; continue; } if (0 >= F) { if (0 > F) { y[p] = 1; - B[p] = 1; + C[p] = 1; continue; } D -= x; @@ -743,16 +743,16 @@ function za(a, c, b, e, d, f, g, k) { r && (H[p] = r); p && D++; let va; - F ? !p && x && (D += x) : (B[p] = 1, y[p] = 1); + F ? !p && x && (D += x) : (C[p] = 1, y[p] = 1); F >= u.length - 1 ? va = 1 : F < v.length - 1 && v[F + 1].match ? va = 1 : x && (D += x); - D -= f.length - 2; + D -= e.length - 2; if (!p || D + l.length <= h) { t[p] = l; } else { - O = Q = U = B[p] = 0; + O = Q = U = C[p] = 0; break; } - va && (B[p + 1] = 1, y[p + 1] = 1); + va && (C[p + 1] = 1, y[p + 1] = 1); } D += l.length; O = E[F] = 1; @@ -769,22 +769,22 @@ function za(a, c, b, e, d, f, g, k) { } l = ""; for (let p = 0, F; p < t.length; p++) { - F = (p && B[p] ? " " : (p && !d ? " " : "") + d) + t[p], l += F; + F = (p && C[p] ? " " : (p && !d ? " " : "") + d) + t[p], l += F; } - d && !B[t.length] && (l += d); + d && !C[t.length] && (l += d); } } n && (l = l.replace(n, " ")); ba[ia].highlight = l; } - if (e) { + if (f) { break; } } return c; } ;J(); -X.prototype.search = function(a, c, b, e) { +X.prototype.search = function(a, c, b, f) { b || (!c && P(a) ? (b = a, a = "") : P(c) && (b = c, c = 0)); if (b && b.cache) { b.cache = !1; @@ -792,10 +792,10 @@ X.prototype.search = function(a, c, b, e) { b.cache = !0; return d; } - let f = []; + let e = []; var g = []; let k, h, m; - let n = 0, C = !0, x; + let n = 0, B = !0, x; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; @@ -804,10 +804,10 @@ X.prototype.search = function(a, c, b, e) { h = q || b.field || (h = b.index) && (h.index ? null : h); m = this.tag && b.tag; k = b.suggest; - C = !0; - this.store && b.highlight && !C ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !C && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - x = C && this.store && b.highlight; - d = !!x || C && this.store && b.enrich; + B = !0; + this.store && b.highlight && !B ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !B && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + x = B && this.store && b.highlight; + d = !!x || B && this.store && b.enrich; c = b.limit || c; var w = b.offset || 0; c || (c = 100); @@ -830,8 +830,8 @@ X.prototype.search = function(a, c, b, e) { } } else { u = Object.keys(t); - for (let B = 0, y, z; B < u.length; B++) { - if (y = u[B], z = t[y], z.constructor === Array) { + for (let C = 0, y, z; C < u.length; C++) { + if (y = u[C], z = t[y], z.constructor === Array) { for (v = 0; v < z.length; v++) { l.push(y, z[v]); } @@ -849,29 +849,29 @@ X.prototype.search = function(a, c, b, e) { g = []; if (l.length) { for (q = 0; q < l.length; q += 2) { - r = Ea.call(this, l[q], l[q + 1], c, w, d), f.push({field:l[q], tag:l[q + 1], result:r}); + r = Ea.call(this, l[q], l[q + 1], c, w, d), e.push({field:l[q], tag:l[q + 1], result:r}); } } return g.length ? Promise.all(g).then(function(E) { for (let t = 0; t < E.length; t++) { - f[t].result = E[t]; + e[t].result = E[t]; } - return f; - }) : f; + return e; + }) : e; } } h && h.constructor !== Array && (h = [h]); } h || (h = this.field); l = !1; - for (let E = 0, t, B, y; E < h.length; E++) { - B = h[E]; + for (let E = 0, t, C, y; E < h.length; E++) { + C = h[E]; let z; - L(B) || (z = B, B = z.field, a = z.query || a, c = Fa(z.limit, c), w = Fa(z.offset, w), k = Fa(z.suggest, k), x = C && this.store && Fa(z.highlight, x), d = !!x || C && this.store && Fa(z.enrich, d)); - if (e) { - t = e[E]; + L(C) || (z = C, C = z.field, a = z.query || a, c = Fa(z.limit, c), w = Fa(z.offset, w), k = Fa(z.suggest, k), x = B && this.store && Fa(z.highlight, x), d = !!x || B && this.store && Fa(z.enrich, d)); + if (f) { + t = f[E]; } else { - if (u = z || b, v = this.index.get(B), m && (u.enrich = !1), l) { + if (u = z || b, v = this.index.get(C), m && (u.enrich = !1), l) { l[E] = v.search(a, c, u); u && d && (u.enrich = d); continue; @@ -879,7 +879,7 @@ X.prototype.search = function(a, c, b, e) { t = v.search(a, c, u), u && d && (u.enrich = d); } } - y = t && (C ? t.length : t.result.length); + y = t && (B ? t.length : t.result.length); if (m && y) { u = []; v = 0; @@ -889,13 +889,13 @@ X.prototype.search = function(a, c, b, e) { if (console.warn("Tag '" + m[H] + ":" + m[H + 1] + "' will be skipped because there is no field '" + m[H] + "'."), k) { continue; } else { - return f; + return e; } } if (M = (D = D && D.get(m[H + 1])) && D.length) { v++, u.push(D); } else if (!k) { - return f; + return e; } } if (v) { @@ -908,9 +908,9 @@ X.prototype.search = function(a, c, b, e) { } } if (y) { - g[n] = B, f.push(t), n++; + g[n] = C, e.push(t), n++; } else if (1 === h.length) { - return f; + return e; } } if (l) { @@ -920,47 +920,47 @@ X.prototype.search = function(a, c, b, e) { }); } if (!n) { - return f; + return e; } if (q && (!d || !this.store)) { - return f[0]; + return e = e[0], B || (e.index = this), e; } l = []; for (w = 0; w < g.length; w++) { - e = f[w]; - d && e.length && "undefined" === typeof e[0].doc && (e = Ga.call(this, e)); + f = e[w]; + d && f.length && "undefined" === typeof f[0].doc && (f = Ga.call(this, f)); if (q) { - return x ? Da(a, e, this.index, q, x) : e; + return x ? Da(a, f, this.index, q, x) : f; } - f[w] = {field:g[w], result:e}; + e[w] = {field:g[w], result:f}; } - return r ? Ha(f) : x ? Da(a, f, this.index, q, x) : f; + return r ? Ha(e) : x ? Da(a, e, this.index, q, x) : e; }; function Fa(a, c) { return "undefined" === typeof a ? c : a; } function Ha(a) { const c = [], b = J(); - for (let e = 0, d, f; e < a.length; e++) { - d = a[e]; - f = d.result; - for (let g = 0, k, h, m; g < f.length; g++) { - h = f[g], "object" !== typeof h && (h = {id:h}), k = h.id, (m = b[k]) ? m.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); + for (let f = 0, d, e; f < a.length; f++) { + d = a[f]; + e = d.result; + for (let g = 0, k, h, m; g < e.length; g++) { + h = e[g], "object" !== typeof h && (h = {id:h}), k = h.id, (m = b[k]) ? m.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); } } return c; } -function Ea(a, c, b, e, d) { - let f = this.tag.get(a); - if (!f) { +function Ea(a, c, b, f, d) { + let e = this.tag.get(a); + if (!e) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { - if (a > b || e) { - f = f.slice(e, e + b); + if ((a = (e = e && e.get(c)) && e.length - f) && 0 < a) { + if (a > b || f) { + e = e.slice(f, f + b); } - d && (f = Ga.call(this, f)); - return f; + d && (e = Ga.call(this, e)); + return e; } } function Ga(a) { @@ -968,8 +968,8 @@ function Ga(a) { return a; } const c = Array(a.length); - for (let b = 0, e; b < a.length; b++) { - e = a[b], c[b] = {id:e, doc:this.store.get(e)}; + for (let b = 0, f; b < a.length; b++) { + f = a[b], c[b] = {id:f, doc:this.store.get(f)}; } return c; } @@ -990,16 +990,16 @@ function Ga(a) { a.cache = !1; this.priority = a.priority || 4; b = new Map(); - let e = c.index || c.field || c; - L(e) && (e = [e]); - for (let d = 0, f, g; d < e.length; d++) { - f = e[d], L(f) || (g = f, f = f.field), g = P(g) ? Object.assign({}, a, g) : a, b.set(f, new Z(g, this.reg)), g.custom ? this.D[d] = g.custom : (this.D[d] = Ia(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)), this.field[d] = f; + let f = c.index || c.field || c; + L(f) && (f = [f]); + for (let d = 0, e, g; d < f.length; d++) { + e = f[d], L(e) || (g = e, e = e.field), g = P(g) ? Object.assign({}, a, g) : a, b.set(e, new Z(g, this.reg)), g.custom ? this.D[d] = g.custom : (this.D[d] = Ia(e, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)), this.field[d] = e; } if (this.A) { a = c.store; L(a) && (a = [a]); - for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Ia(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + for (let d = 0, e, g; d < a.length; d++) { + e = a[d], g = e.field || e, e.custom ? (this.A[d] = e.custom, e.custom.S = g) : (this.A[d] = Ia(g, this.J), e.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = e.filter)); } } this.index = b; @@ -1009,13 +1009,13 @@ function Ga(a) { this.tag = new Map(); this.B = []; this.R = []; - for (let d = 0, f, g; d < b.length; d++) { - f = b[d]; - g = f.field || f; + for (let d = 0, e, g; d < b.length; d++) { + e = b[d]; + g = e.field || e; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Ia(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + e.custom ? this.B[d] = e.custom : (this.B[d] = Ia(g, this.J), e.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = e.filter)); this.R[d] = g; this.tag.set(g, new Map()); } @@ -1024,12 +1024,12 @@ function Ga(a) { } function Ia(a, c) { const b = a.split(":"); - let e = 0; + let f = 0; for (let d = 0; d < b.length; d++) { - a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[f] = !0), a && (b[f++] = a); } - e < b.length && (b.length = e); - return 1 < e ? b : b[0]; + f < b.length && (b.length = f); + return 1 < f ? b : b[0]; } A = X.prototype; A.append = function(a, c) { @@ -1046,10 +1046,10 @@ A.remove = function(a) { if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { for (let b of this.tag.values()) { - for (let e of b) { - c = e[0]; - const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); + for (let f of b) { + c = f[0]; + const d = f[1], e = d.indexOf(a); + -1 < e && (1 < d.length ? d.splice(e, 1) : b.delete(c)); } } } @@ -1092,10 +1092,10 @@ A.set = function(a, c) { return this; }; A.searchCache = Ka; -A.export = function(a, c, b = 0, e = 0) { +A.export = function(a, c, b = 0, f = 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) { + if ((c = this.index.get(g).export(a, g, b, f = 1)) && c.then) { const k = this; return c.then(function() { return k.export(a, g, b + 1); @@ -1103,27 +1103,27 @@ A.export = function(a, c, b = 0, e = 0) { } return this.export(a, g, b + 1); } - let d, f; - switch(e) { + let d, e; + switch(f) { case 0: d = "reg"; - f = ta(this.reg); + e = ta(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && ra(this.tag, this.reg.size); + e = this.tag && ra(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && pa(this.store); + e = this.store && pa(this.store); c = null; break; default: return; } - return xa.call(this, a, c, d, f, b, e); + return xa.call(this, a, c, d, e, b, f); }; A.import = function(a, c) { var b = a.split("."); @@ -1139,8 +1139,8 @@ A.import = function(a, c) { case "reg": this.fastupdate = !1; this.reg = wa(c, this.reg); - for (let e = 0, d; e < this.field.length; e++) { - d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; + for (let f = 0, d; f < this.field.length; f++) { + d = this.index.get(this.field[f]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": @@ -1153,19 +1153,19 @@ A.import = function(a, c) { }; ka(X.prototype); function Ka(a, c, b) { - const e = (c ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); + const f = (c ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); - let d = this.cache.get(e); + let d = this.cache.get(f); if (!d) { d = this.search(a, c, b); if (d.then) { - const f = this; + const e = this; d.then(function(g) { - f.cache.set(e, g); + e.cache.set(f, g); return g; }); } - this.cache.set(e, d); + this.cache.set(f, d); } return d; } @@ -1201,23 +1201,23 @@ const Qa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j: var Ra = {Exact:La, Default:Ma, Normalize:Ma, LatinBalance:{mapper:Na}, LatinAdvanced:{mapper:Na, matcher:Oa, replacer:Pa}, LatinExtra:{mapper:Na, replacer:Pa.concat([/(?!^)[aeo]/g, ""]), matcher:Oa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Qa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let f = c.charAt(0), d = Qa[f]; + for (let e = 1, g; e < c.length && (g = c.charAt(e), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (f += g, d = g, 4 !== f.length)); e++) { } - a[b] = e; + a[b] = f; } }}, CJK:{split:""}, LatinExact:La, LatinDefault:Ma, LatinSimple:Ma}; Z.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { - for (let e = 0, d; e < b.length; e++) { - if (d = b[e]) { + for (let f = 0, d; f < b.length; f++) { + if (d = b[f]) { if (2 > d.length) { d.pop(); } else { - const f = d.indexOf(a); - f === b.length - 1 ? d.pop() : d.splice(f, 1); + const e = d.indexOf(a); + e === b.length - 1 ? d.pop() : d.splice(e, 1); } } } @@ -1231,15 +1231,15 @@ Z.prototype.remove = function(a, c) { }; function Sa(a, c) { let b = 0; - var e = "undefined" === typeof c; + var f = "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) { + for (let d = 0, e, g; d < a.length; d++) { + if ((e = a[d]) && e.length) { + if (f) { b++; } else { - if (g = f.indexOf(c), 0 <= g) { - 1 < f.length ? (f.splice(g, 1), b++) : delete a[d]; + if (g = e.indexOf(c), 0 <= g) { + 1 < e.length ? (e.splice(g, 1), b++) : delete a[d]; break; } else { b++; @@ -1249,38 +1249,38 @@ function Sa(a, c) { } } else { for (let d of a.entries()) { - e = d[0]; - const f = Sa(d[1], c); - f ? b += f : a.delete(e); + f = d[0]; + const e = Sa(d[1], c); + e ? b += e : a.delete(f); } } return b; } ;const Ta = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -Z.prototype.add = function(a, c, b, e) { +Z.prototype.add = function(a, c, b, f) { if (c && (a || 0 === a)) { - if (!e && !b && this.reg.has(a)) { + if (!f && !b && this.reg.has(a)) { return this.update(a, c); } - e = this.depth; - c = this.encoder.encode(c, !e); + f = this.depth; + c = this.encoder.encode(c, !f); const m = c.length; if (m) { - const n = J(), C = J(), x = this.resolution; + const n = J(), B = J(), x = this.resolution; for (let q = 0; q < m; q++) { let r = c[this.rtl ? m - 1 - q : q]; var d = r.length; - if (d && (e || !C[r])) { - var f = this.score ? this.score(c, r, q, null, 0) : Ua(x, m, q), g = ""; + if (d && (f || !B[r])) { + var e = this.score ? this.score(c, r, q, null, 0) : Ua(x, m, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (let w = 0, l; w < d; w++) { - for (f = d; f > w; f--) { - g = r.substring(w, f); + for (e = d; e > w; e--) { + g = r.substring(w, e); l = this.rtl ? d - 1 - w : w; var k = this.score ? this.score(c, r, q, g, l) : Ua(x, m, q, d, l); - Va(this, C, g, k, a, b); + Va(this, B, g, k, a, b); } } break; @@ -1291,24 +1291,24 @@ Z.prototype.add = function(a, c, b, e) { for (k = d - 1; 0 < k; k--) { g = r[this.rtl ? d - 1 - k : k] + g; var h = this.score ? this.score(c, r, q, g, k) : Ua(x, m, q, d, k); - Va(this, C, g, h, a, b); + Va(this, B, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[this.rtl ? d - 1 - k : k], Va(this, C, g, f, a, b); + g += r[this.rtl ? d - 1 - k : k], Va(this, B, g, e, a, b); } break; } default: - if (Va(this, C, r, f, a, b), e && 1 < m && q < m - 1) { - for (d = J(), g = this.P, f = r, k = Math.min(e + 1, this.rtl ? q + 1 : m - q), d[f] = 1, h = 1; h < k; h++) { + if (Va(this, B, r, e, a, b), f && 1 < m && q < m - 1) { + for (d = J(), g = this.P, e = r, k = Math.min(f + 1, this.rtl ? q + 1 : m - q), d[e] = 1, h = 1; h < k; h++) { if ((r = c[this.rtl ? m - 1 - q - h : q + h]) && !d[r]) { d[r] = 1; - const w = this.score ? this.score(c, f, q, r, h - 1) : Ua(g + (m / 2 > g ? 0 : 1), m, q, k - 1, h - 1), l = this.bidirectional && r > f; - Va(this, n, l ? f : r, w, a, b, l ? r : f); + const w = this.score ? this.score(c, e, q, r, h - 1) : Ua(g + (m / 2 > g ? 0 : 1), m, q, k - 1, h - 1), l = this.bidirectional && r > e; + Va(this, n, l ? e : r, w, a, b, l ? r : e); } } } @@ -1320,44 +1320,44 @@ Z.prototype.add = function(a, c, b, e) { } return this; }; -function Va(a, c, b, e, d, f, g) { +function Va(a, c, b, f, d, e, g) { let k = g ? a.ctx : a.map, h; if (!c[b] || g && !(h = c[b])[g]) { - g ? (c = h || (c[b] = J()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); + g ? (c = h || (c[b] = J()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[f] || (k[f] = []), e && 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 && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; +function Ua(a, c, b, f, d) { + return b && 1 < a ? c + (f || 0) <= a ? b + (d || 0) : (a - 1) / (c + (f || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;Z.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); if (b && b.cache) { return b.cache = !1, c = this.searchCache(a, c, b), b.cache = !0, c; } - var e = [], d = 0; + var f = [], d = 0; if (b) { a = b.query || a; c = b.limit || c; d = b.offset || 0; - var f = b.context; + var e = b.context; var g = b.suggest; var k = !0; var h = b.resolution; } "undefined" === typeof k && (k = !0); - f = this.depth && !1 !== f; - b = this.encoder.encode(a, !f); + e = this.depth && !1 !== e; + b = this.encoder.encode(a, !e); a = b.length; c = c || (k ? 100 : 0); if (1 === a) { return g = d, (d = Wa(this, b[0], "")) && d.length ? Ca.call(this, d, c, g) : []; } - if (2 === a && f && !g) { + if (2 === a && e && !g) { return g = d, (d = Wa(this, b[1], b[0])) && d.length ? Ca.call(this, d, c, g) : []; } k = J(); var m = 0; - if (f) { + if (e) { var n = b[0]; m = 1; } @@ -1367,22 +1367,22 @@ function Ua(a, c, b, e, d) { k[w] = 1; r = Wa(this, w, n); a: { - f = r; - var C = e, x = g, q = h; + e = r; + var B = f, x = g, q = h; let l = []; - if (f && f.length) { - if (f.length <= q) { - C.push(f); + if (e && e.length) { + if (e.length <= q) { + B.push(e); r = void 0; break a; } for (let u = 0, v; u < q; u++) { - if (v = f[u]) { + if (v = e[u]) { l[u] = v; } } if (l.length) { - C.push(l); + B.push(l); r = void 0; break a; } @@ -1390,28 +1390,28 @@ function Ua(a, c, b, e, d) { r = x ? void 0 : l; } if (r) { - e = r; + f = r; break; } - n && (g && r && e.length || (n = w)); + n && (g && r && f.length || (n = w)); } - g && n && m === a - 1 && !e.length && (h = this.resolution, n = "", m = -1, k = J()); + g && n && m === a - 1 && !f.length && (h = this.resolution, n = "", m = -1, k = J()); } a: { - b = e; - e = b.length; + b = f; + f = b.length; n = b; - if (1 < e) { + if (1 < f) { b: { - e = g; + f = g; n = b.length; g = []; a = J(); for (let r = 0, w, l, u, v; r < h; r++) { for (m = 0; m < n; m++) { if (u = b[m], r < u.length && (w = u[r])) { - for (f = 0; f < w.length; f++) { - if (l = w[f], (k = a[l]) ? a[l]++ : (k = 0, a[l] = 1), v = g[k] || (g[k] = []), v.push(l), c && k === n - 1 && v.length - d === c) { + for (e = 0; e < w.length; e++) { + if (l = w[e], (k = a[l]) ? a[l]++ : (k = 0, a[l] = 1), v = g[k] || (g[k] = []), v.push(l), c && k === n - 1 && v.length - d === c) { n = d ? v.slice(d) : v; break b; } @@ -1420,13 +1420,13 @@ function Ua(a, c, b, e, d) { } } if (b = g.length) { - if (e) { + if (f) { if (1 < g.length) { c: { - for (b = [], h = J(), e = g.length, k = e - 1; 0 <= k; k--) { - if (a = (e = g[k]) && e.length) { + for (b = [], h = J(), f = g.length, k = f - 1; 0 <= k; k--) { + if (a = (f = g[k]) && f.length) { for (m = 0; m < a; m++) { - if (n = e[m], !h[n]) { + if (n = f[m], !h[n]) { if (h[n] = 1, d) { d--; } else { @@ -1458,7 +1458,7 @@ function Ua(a, c, b, e, d) { } n = g; } - } else if (1 === e) { + } else if (1 === f) { c = Ca.call(null, b[0], c, d); break a; } @@ -1467,8 +1467,8 @@ function Ua(a, c, b, e, d) { return c; }; function Wa(a, c, b) { - let e; - b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); + let f; + b && (f = a.bidirectional && c > b) && (f = b, b = c, c = f); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } @@ -1483,20 +1483,20 @@ function Wa(a, c, b) { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = L(a.encoder) ? Ra[a.encoder] : a.encode || a.encoder || {}; + const f = !0 === b ? {depth:1} : b || {}, d = L(a.encoder) ? Ra[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new S(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; - this.depth = "strict" === b && e.depth || 0; - this.bidirectional = !1 !== e.bidirectional; + this.depth = "strict" === b && f.depth || 0; + this.bidirectional = !1 !== f.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; - e && e.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); + f && f.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); b = !1; this.map = new Map(); this.ctx = new Map(); this.reg = c || (this.fastupdate ? new Map() : new Set()); - this.P = e.resolution || 3; + this.P = f.resolution || 3; this.rtl = d.rtl || a.rtl || !1; this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; @@ -1516,8 +1516,8 @@ A.contain = function(a) { return this.reg.has(a); }; A.update = function(a, c) { - const b = this, e = this.remove(a); - return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); + const b = this, f = this.remove(a); + return f && f.then ? f.then(() => b.add(a, c)) : this.add(a, c); }; A.cleanup = function() { if (!this.fastupdate) { @@ -1528,29 +1528,29 @@ A.cleanup = function() { return this; }; A.searchCache = Ka; -A.export = function(a, c, b = 0, e = 0) { - let d, f; - switch(e) { +A.export = function(a, c, b = 0, f = 0) { + let d, e; + switch(f) { case 0: d = "reg"; - f = ta(this.reg); + e = ta(this.reg); break; case 1: d = "cfg"; - f = null; + e = null; break; case 2: d = "map"; - f = pa(this.map, this.reg.size); + e = pa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ra(this.ctx, this.reg.size); + e = ra(this.ctx, this.reg.size); break; default: return; } - return xa.call(this, a, c, d, f, b, e); + return xa.call(this, a, c, d, e, b, f); }; A.import = function(a, c) { if (c) { @@ -1568,25 +1568,25 @@ A.import = function(a, c) { } }; A.serialize = function(a = !0) { - let c = "", b = "", e = ""; + let c = "", b = "", f = ""; if (this.reg.size) { - let f; + let e; for (var d of this.reg.keys()) { - f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); + e || (e = typeof d), c += (c ? "," : "") + ("string" === e ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = ya(this.map, f); + b = ya(this.map, e); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = ya(g[1], f); + let k = ya(g[1], e); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; - e += (e ? "," : "") + k; + f += (f ? "," : "") + k; } - e = "index.ctx=new Map([" + e + "]);"; + f = "index.ctx=new Map([" + f + "]);"; } - return a ? "function inject(index){" + c + b + e + "}" : c + b + e; + return a ? "function inject(index){" + c + b + f + "}" : c + b + f; }; ka(Z.prototype); J(); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 4050b77..193bf4a 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle) + * FlexSearch.js v0.8.163 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -32,8 +32,8 @@ G);else continue;(G-=l.length)||(G=-1);z[p]=G}else{y[p]=1;continue}if(D+l.length K?Q=0:U=0;if(!Q&&!U)break;Q?(L++,K=L):K++}}l="";for(let p=0,F;pb||e)a=a.slice(e,e+b);d&&(a=Ga.call(this,a));return a}}function Ga(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;b "a1a".split(b).length; + this.split = b, f = !1 === b || 2 > "a1a".split(b).length; } - this.numeric = I(a.numeric, e); + this.numeric = I(a.numeric, f); } else { try { this.split = I(this.split, ca); @@ -202,29 +202,29 @@ A.encode = function(a, c) { this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = J(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; - for (let m = 0, n, C; m < k.length; m++) { - if ((n = C = k[m]) && !(n.length < this.minlength || n.length > this.maxlength)) { + let f = [], d = J(), e, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; + for (let m = 0, n, B; m < k.length; m++) { + if ((n = B = k[m]) && !(n.length < this.minlength || n.length > this.maxlength)) { if (c) { if (d[n]) { continue; } d[n] = 1; } else { - if (f === n) { + if (e === n) { continue; } - f = n; + e = n; } if (b) { - e.push(n); + f.push(n); } else { if (!this.filter || ("function" === typeof this.filter ? this.filter(n) : !this.filter.has(n))) { if (this.cache && n.length <= this.L) { if (this.H) { var h = this.G.get(n); if (h || "" === h) { - h && e.push(h); + h && f.push(h); continue; } } else { @@ -251,9 +251,9 @@ A.encode = function(a, c) { n = n.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && C.length <= this.L && (this.G.set(C, n), this.G.size > this.O && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && B.length <= this.L && (this.G.set(B, n), this.G.size > this.O && (this.G.clear(), this.L = this.L / 1.1 | 0)); if (n) { - if (n !== C) { + if (n !== B) { if (c) { if (d[n]) { continue; @@ -266,15 +266,15 @@ A.encode = function(a, c) { g = n; } } - e.push(n); + f.push(n); } } } } } - this.finalize && (e = this.finalize(e) || e); - this.cache && a.length <= this.K && (this.F.set(a, e), this.F.size > this.O && (this.F.clear(), this.K = this.K / 1.1 | 0)); - return e; + this.finalize && (f = this.finalize(f) || f); + this.cache && a.length <= this.K && (this.F.set(a, f), this.F.size > this.O && (this.F.clear(), this.K = this.K / 1.1 | 0)); + return f; }; function V(a) { a.H = null; @@ -297,59 +297,59 @@ function W(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; - let e; - "function" === typeof b && (e = b, delete c[c.length - 1]); + let f; + "function" === typeof b && (f = b, delete c[c.length - 1]); la ? na || (na = Date.now() - ma >= this.priority * this.priority * 3) : (la = setTimeout(oa, 0), ma = Date.now()); if (na) { - const f = this; + const e = this; return new Promise(g => { setTimeout(function() { - g(f[a + "Async"].apply(f, c)); + g(e[a + "Async"].apply(e, c)); }, 0); }); } const d = this[a].apply(this, c); - b = d.then ? d : new Promise(f => f(d)); - e && b.then(e); + b = d.then ? d : new Promise(e => e(d)); + f && b.then(f); return b; }; } ;function pa(a, c = 0) { - let b = [], e = []; + let b = [], f = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { - e.push(d), e.length === c && (b.push(e), e = []); + f.push(d), f.length === c && (b.push(f), f = []); } - e.length && b.push(e); + f.length && b.push(f); return b; } function qa(a, c) { c || (c = new Map()); - for (let b = 0, e; b < a.length; b++) { - e = a[b], c.set(e[0], e[1]); + for (let b = 0, f; b < a.length; b++) { + f = a[b], c.set(f[0], f[1]); } return c; } function ra(a, c = 0) { - let b = [], e = []; + let b = [], f = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], pa(d[1])[0]]), e.length === c && (b.push(e), e = []); + f.push([d[0], pa(d[1])[0]]), f.length === c && (b.push(f), f = []); } - e.length && b.push(e); + f.length && b.push(f); return b; } function sa(a, c) { c || (c = new Map()); - for (let b = 0, e, d; b < a.length; b++) { - e = a[b], d = c.get(e[0]), c.set(e[0], qa(e[1], d)); + for (let b = 0, f, d; b < a.length; b++) { + f = a[b], d = c.get(f[0]), c.set(f[0], qa(f[1], d)); } return c; } function va(a) { let c = [], b = []; - for (const e of a.keys()) { - b.push(e), 250000 === b.length && (c.push(b), b = []); + for (const f of a.keys()) { + b.push(f), 250000 === b.length && (c.push(b), b = []); } b.length && c.push(b); return c; @@ -361,26 +361,26 @@ function wa(a, c) { } return c; } -function xa(a, c, b, e, d, f, g = 0) { - const k = e && e.constructor === Array; - var h = k ? e.shift() : e; +function xa(a, c, b, f, d, e, g = 0) { + const k = f && f.constructor === Array; + var h = k ? f.shift() : f; if (!h) { - return this.export(a, c, d, f + 1); + return this.export(a, c, d, e + 1); } if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const m = this; return h.then(function() { - return xa.call(m, a, c, b, k ? e : null, d, f, g + 1); + return xa.call(m, a, c, b, k ? f : null, d, e, g + 1); }); } - return xa.call(this, a, c, b, k ? e : null, d, f, g + 1); + return xa.call(this, a, c, b, k ? f : null, d, e, g + 1); } function ya(a, c) { let b = ""; - for (const e of a.entries()) { - a = e[0]; - const d = e[1]; - let f = ""; + for (const f of a.entries()) { + a = f[0]; + const d = f[1]; + let e = ""; for (let g = 0, k; g < d.length; g++) { k = d[g] || [""]; let h = ""; @@ -388,10 +388,10 @@ function ya(a, c) { h += (h ? "," : "") + ("string" === c ? '"' + k[m] + '"' : k[m]); } h = "[" + h + "]"; - f += (f ? "," : "") + h; + e += (e ? "," : "") + h; } - f = '["' + a + '",[' + f + "]]"; - b += (b ? "," : "") + f; + e = '["' + a + '",[' + e + "]]"; + b += (b ? "," : "") + e; } return b; } @@ -403,37 +403,37 @@ function ya(a, c) { } for (let k = 0, h; k < this.field.length; k++) { h = this.D[k]; - var e = this.index.get(this.field[k]); + var f = this.index.get(this.field[k]); if ("function" === typeof h) { var d = h(c); - d && e.add(a, d, !1, !0); + d && f.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), za(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : L(h) && (h = [h]), za(c, h, this.J, 0, f, a, h[0], b); } } } if (this.tag) { - for (e = 0; e < this.B.length; e++) { - var f = this.B[e], g = this.R[e]; + for (f = 0; f < this.B.length; f++) { + var e = this.B[f], g = this.R[f]; d = this.tag.get(g); let k = J(); - if ("function" === typeof f) { - if (f = f(c), !f) { + if ("function" === typeof e) { + if (e = e(c), !e) { continue; } } else { - const h = f.I; + const h = e.I; if (h && !h(c)) { continue; } - f.constructor === String && (f = "" + f); - f = R(c, f); + e.constructor === String && (e = "" + e); + e = R(c, e); } - if (d && f) { - L(f) && (f = [f]); - for (let h = 0, m, n; h < f.length; h++) { - m = f[h], k[m] || (k[m] = 1, (g = d.get(m)) ? n = g : d.set(m, n = []), b && n.includes(a) || (n.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])))); + if (d && e) { + L(e) && (e = [e]); + for (let h = 0, m, n; h < e.length; h++) { + m = e[h], k[m] || (k[m] = 1, (g = d.get(m)) ? n = g : d.set(m, n = []), b && n.includes(a) || (n.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -468,56 +468,56 @@ function ya(a, c) { } return this; }; -function Aa(a, c, b, e, d, f) { +function Aa(a, c, b, f, d, e) { a = a[d]; - if (e === b.length - 1) { - c[d] = f || a; + if (f === b.length - 1) { + c[d] = e || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Aa(a, c, b, e, d); + Aa(a, c, b, f, d); } } else { - c = c[d] || (c[d] = J()), d = b[++e], Aa(a, c, b, e, d); + c = c[d] || (c[d] = J()), d = b[++f], Aa(a, c, b, f, d); } } } -function za(a, c, b, e, d, f, g, k) { +function za(a, c, b, f, d, e, g, k) { if (a = a[g]) { - if (e === c.length - 1) { + if (f === c.length - 1) { if (a.constructor === Array) { - if (b[e]) { + if (b[f]) { for (c = 0; c < a.length; c++) { - d.add(f, a[c], !0, !0); + d.add(e, a[c], !0, !0); } return; } a = a.join(" "); } - d.add(f, a, k, !0); + d.add(e, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - za(a, c, b, e, d, f, g, k); + za(a, c, b, f, d, e, g, k); } } else { - g = c[++e], za(a, c, b, e, d, f, g, k); + g = c[++f], za(a, c, b, f, d, e, g, k); } } } } ;function Ba(a, c) { - const b = J(), e = []; - for (let d = 0, f; d < c.length; d++) { - f = c[d]; - for (let g = 0; g < f.length; g++) { - b[f[g]] = 1; + const b = J(), f = []; + for (let d = 0, e; d < c.length; d++) { + e = c[d]; + for (let g = 0; g < e.length; g++) { + b[e[g]] = 1; } } - for (let d = 0, f; d < a.length; d++) { - f = a[d], b[f] && (e.push(f), b[f] = 0); + for (let d = 0, e; d < a.length; d++) { + e = a[d], b[e] && (f.push(e), b[e] = 0); } - return e; + return f; } ;function Ca(a, c, b) { if (!a.length) { @@ -526,59 +526,59 @@ function za(a, c, b, e, d, f, g, k) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } - let e = []; - for (let d = 0, f, g; d < a.length; d++) { - if ((f = a[d]) && (g = f.length)) { + let f = []; + for (let d = 0, e, g; d < a.length; d++) { + if ((e = a[d]) && (g = e.length)) { if (b) { if (b >= g) { b -= g; continue; } - b < g && (f = c ? f.slice(b, b + c) : f.slice(b), g = f.length, b = 0); + b < g && (e = c ? e.slice(b, b + c) : e.slice(b), g = e.length, b = 0); } - g > c && (f = f.slice(0, c), g = c); - if (!e.length && g >= c) { - return f; + g > c && (e = e.slice(0, c), g = c); + if (!f.length && g >= c) { + return e; } - e.push(f); + f.push(e); c -= g; if (!c) { break; } } } - return e = 1 < e.length ? [].concat.apply([], e) : e[0]; + return f = 1 < f.length ? [].concat.apply([], f) : f[0]; } -;function Da(a, c, b, e, d) { - let f, g, k; - "string" === typeof d ? (f = d, d = "") : f = d.template; - if (!f) { +;function Da(a, c, b, f, d) { + let e, g, k; + "string" === typeof d ? (e = d, d = "") : e = d.template; + if (!e) { throw Error('No template pattern was specified by the search option "highlight"'); } - g = f.indexOf("$1"); + g = e.indexOf("$1"); if (-1 === g) { - throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + e); } - k = f.substring(g + 2); - g = f.substring(0, g); + k = e.substring(g + 2); + g = e.substring(0, g); let h = d && d.boundary, m = !d || !1 !== d.clip, n = d && d.merge && k && g && new RegExp(k + " " + g, "g"); d = d && d.ellipsis; - var C = 0; + var B = 0; if ("object" === typeof d) { var x = d.template; - C = x.length - 2; + B = x.length - 2; d = d.pattern; } "string" !== typeof d && (d = !1 === d ? "" : "..."); - C && (d = x.replace("$1", d)); - x = d.length - C; + B && (d = x.replace("$1", d)); + x = d.length - B; let q, r; "object" === typeof h && (q = h.before, 0 === q && (q = -1), r = h.after, 0 === r && (r = -1), h = h.total || 9e5); - C = new Map(); + B = new Map(); for (let ta = 0, T, Ga, aa; ta < c.length; ta++) { let ba; - if (e) { - ba = c, aa = e; + if (f) { + ba = c, aa = f; } else { var w = c[ta]; aa = w.field; @@ -589,8 +589,8 @@ function za(a, c, b, e, d, f, g, k) { } Ga = b.get(aa); T = Ga.encoder; - w = C.get(T); - "string" !== typeof w && (w = T.encode(a), C.set(T, w)); + w = B.get(T); + "string" !== typeof w && (w = T.encode(a), B.set(T, w)); for (let ia = 0; ia < ba.length; ia++) { var l = ba[ia].doc; if (!l) { @@ -607,7 +607,7 @@ function za(a, c, b, e, d, f, g, k) { l = ""; var v = []; let ja = []; - var E = -1, t = -1, B = 0; + var E = -1, t = -1, C = 0; for (var y = 0; y < u.length; y++) { var z = u[y], H = T.encode(z); H = 1 < H.length ? H.join(" ") : H[0]; @@ -622,22 +622,22 @@ function za(a, c, b, e, d, f, g, k) { Q && G <= Q || (N = H.indexOf(N), -1 < N && (K = (N ? z.substring(0, N) : "") + g + z.substring(N, N + G) + k + (N + G < D ? z.substring(N + G) : ""), Q = G, p = !0)); } } - K && (h && (0 > E && (E = l.length + (l ? 1 : 0)), t = l.length + (l ? 1 : 0) + K.length, B += D, ja.push(v.length), v.push({match:K})), l += (l ? " " : "") + K); + K && (h && (0 > E && (E = l.length + (l ? 1 : 0)), t = l.length + (l ? 1 : 0) + K.length, C += D, ja.push(v.length), v.push({match:K})), l += (l ? " " : "") + K); } if (!p) { z = u[y], l += (l ? " " : "") + z, h && v.push({text:z}); - } else if (h && B >= h) { + } else if (h && C >= h) { break; } } - B = ja.length * (f.length - 2); - if (q || r || h && l.length - B > h) { - if (B = h + B - 2 * x, y = t - E, 0 < q && (y += q), 0 < r && (y += r), y <= B) { - u = q ? E - (0 < q ? q : 0) : E - ((B - y) / 2 | 0), v = r ? t + (0 < r ? r : 0) : u + B, m || (0 < u && " " !== l.charAt(u) && " " !== l.charAt(u - 1) && (u = l.indexOf(" ", u), 0 > u && (u = 0)), v < l.length && " " !== l.charAt(v - 1) && " " !== l.charAt(v) && (v = l.lastIndexOf(" ", v), v < t ? v = t : ++v)), l = (u ? d : "") + l.substring(u, v) + (v < l.length ? d : ""); + C = ja.length * (e.length - 2); + if (q || r || h && l.length - C > h) { + if (C = h + C - 2 * x, y = t - E, 0 < q && (y += q), 0 < r && (y += r), y <= C) { + u = q ? E - (0 < q ? q : 0) : E - ((C - y) / 2 | 0), v = r ? t + (0 < r ? r : 0) : u + C, m || (0 < u && " " !== l.charAt(u) && " " !== l.charAt(u - 1) && (u = l.indexOf(" ", u), 0 > u && (u = 0)), v < l.length && " " !== l.charAt(v - 1) && " " !== l.charAt(v) && (v = l.lastIndexOf(" ", v), v < t ? v = t : ++v)), l = (u ? d : "") + l.substring(u, v) + (v < l.length ? d : ""); } else { t = []; E = {}; - B = {}; + C = {}; y = {}; z = {}; H = {}; @@ -654,14 +654,14 @@ function za(a, c, b, e, d, f, g, k) { F += K; if (E[F]) { D -= x; - B[p + 1] = 1; + C[p + 1] = 1; y[p + 1] = 1; continue; } if (F >= v.length - 1) { if (F >= v.length) { y[p + 1] = 1; - F >= u.length && (B[p + 1] = 1); + F >= u.length && (C[p + 1] = 1); continue; } D -= x; @@ -699,13 +699,13 @@ function za(a, c, b, e, d, f, g, k) { if (E[F]) { D -= x; y[p] = 1; - B[p] = 1; + C[p] = 1; continue; } if (0 >= F) { if (0 > F) { y[p] = 1; - B[p] = 1; + C[p] = 1; continue; } D -= x; @@ -742,16 +742,16 @@ function za(a, c, b, e, d, f, g, k) { r && (H[p] = r); p && D++; let ua; - F ? !p && x && (D += x) : (B[p] = 1, y[p] = 1); + F ? !p && x && (D += x) : (C[p] = 1, y[p] = 1); F >= u.length - 1 ? ua = 1 : F < v.length - 1 && v[F + 1].match ? ua = 1 : x && (D += x); - D -= f.length - 2; + D -= e.length - 2; if (!p || D + l.length <= h) { t[p] = l; } else { - O = Q = U = B[p] = 0; + O = Q = U = C[p] = 0; break; } - ua && (B[p + 1] = 1, y[p + 1] = 1); + ua && (C[p + 1] = 1, y[p + 1] = 1); } D += l.length; O = E[F] = 1; @@ -768,22 +768,22 @@ function za(a, c, b, e, d, f, g, k) { } l = ""; for (let p = 0, F; p < t.length; p++) { - F = (p && B[p] ? " " : (p && !d ? " " : "") + d) + t[p], l += F; + F = (p && C[p] ? " " : (p && !d ? " " : "") + d) + t[p], l += F; } - d && !B[t.length] && (l += d); + d && !C[t.length] && (l += d); } } n && (l = l.replace(n, " ")); ba[ia].highlight = l; } - if (e) { + if (f) { break; } } return c; } ;J(); -X.prototype.search = function(a, c, b, e) { +X.prototype.search = function(a, c, b, f) { b || (!c && P(a) ? (b = a, a = "") : P(c) && (b = c, c = 0)); if (b && b.cache) { b.cache = !1; @@ -791,10 +791,10 @@ X.prototype.search = function(a, c, b, e) { b.cache = !0; return d; } - let f = []; + let e = []; var g = []; let k, h, m; - let n = 0, C = !0, x; + let n = 0, B = !0, x; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; @@ -803,10 +803,10 @@ X.prototype.search = function(a, c, b, e) { h = q || b.field || (h = b.index) && (h.index ? null : h); m = this.tag && b.tag; k = b.suggest; - C = !0; - this.store && b.highlight && !C ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !C && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - x = C && this.store && b.highlight; - d = !!x || C && this.store && b.enrich; + B = !0; + this.store && b.highlight && !B ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !B && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + x = B && this.store && b.highlight; + d = !!x || B && this.store && b.enrich; c = b.limit || c; var w = b.offset || 0; c || (c = 100); @@ -829,8 +829,8 @@ X.prototype.search = function(a, c, b, e) { } } else { u = Object.keys(t); - for (let B = 0, y, z; B < u.length; B++) { - if (y = u[B], z = t[y], z.constructor === Array) { + for (let C = 0, y, z; C < u.length; C++) { + if (y = u[C], z = t[y], z.constructor === Array) { for (v = 0; v < z.length; v++) { l.push(y, z[v]); } @@ -848,29 +848,29 @@ X.prototype.search = function(a, c, b, e) { g = []; if (l.length) { for (q = 0; q < l.length; q += 2) { - r = Ea.call(this, l[q], l[q + 1], c, w, d), f.push({field:l[q], tag:l[q + 1], result:r}); + r = Ea.call(this, l[q], l[q + 1], c, w, d), e.push({field:l[q], tag:l[q + 1], result:r}); } } return g.length ? Promise.all(g).then(function(E) { for (let t = 0; t < E.length; t++) { - f[t].result = E[t]; + e[t].result = E[t]; } - return f; - }) : f; + return e; + }) : e; } } h && h.constructor !== Array && (h = [h]); } h || (h = this.field); l = !1; - for (let E = 0, t, B, y; E < h.length; E++) { - B = h[E]; + for (let E = 0, t, C, y; E < h.length; E++) { + C = h[E]; let z; - L(B) || (z = B, B = z.field, a = z.query || a, c = Fa(z.limit, c), w = Fa(z.offset, w), k = Fa(z.suggest, k), x = C && this.store && Fa(z.highlight, x), d = !!x || C && this.store && Fa(z.enrich, d)); - if (e) { - t = e[E]; + L(C) || (z = C, C = z.field, a = z.query || a, c = Fa(z.limit, c), w = Fa(z.offset, w), k = Fa(z.suggest, k), x = B && this.store && Fa(z.highlight, x), d = !!x || B && this.store && Fa(z.enrich, d)); + if (f) { + t = f[E]; } else { - if (u = z || b, v = this.index.get(B), m && (u.enrich = !1), l) { + if (u = z || b, v = this.index.get(C), m && (u.enrich = !1), l) { l[E] = v.search(a, c, u); u && d && (u.enrich = d); continue; @@ -878,7 +878,7 @@ X.prototype.search = function(a, c, b, e) { t = v.search(a, c, u), u && d && (u.enrich = d); } } - y = t && (C ? t.length : t.result.length); + y = t && (B ? t.length : t.result.length); if (m && y) { u = []; v = 0; @@ -888,13 +888,13 @@ X.prototype.search = function(a, c, b, e) { if (console.warn("Tag '" + m[H] + ":" + m[H + 1] + "' will be skipped because there is no field '" + m[H] + "'."), k) { continue; } else { - return f; + return e; } } if (M = (D = D && D.get(m[H + 1])) && D.length) { v++, u.push(D); } else if (!k) { - return f; + return e; } } if (v) { @@ -907,9 +907,9 @@ X.prototype.search = function(a, c, b, e) { } } if (y) { - g[n] = B, f.push(t), n++; + g[n] = C, e.push(t), n++; } else if (1 === h.length) { - return f; + return e; } } if (l) { @@ -919,47 +919,47 @@ X.prototype.search = function(a, c, b, e) { }); } if (!n) { - return f; + return e; } if (q && (!d || !this.store)) { - return f[0]; + return e = e[0], B || (e.index = this), e; } l = []; for (w = 0; w < g.length; w++) { - e = f[w]; - d && e.length && "undefined" === typeof e[0].doc && (e = Ha.call(this, e)); + f = e[w]; + d && f.length && "undefined" === typeof f[0].doc && (f = Ha.call(this, f)); if (q) { - return x ? Da(a, e, this.index, q, x) : e; + return x ? Da(a, f, this.index, q, x) : f; } - f[w] = {field:g[w], result:e}; + e[w] = {field:g[w], result:f}; } - return r ? Ia(f) : x ? Da(a, f, this.index, q, x) : f; + return r ? Ia(e) : x ? Da(a, e, this.index, q, x) : e; }; function Fa(a, c) { return "undefined" === typeof a ? c : a; } function Ia(a) { const c = [], b = J(); - for (let e = 0, d, f; e < a.length; e++) { - d = a[e]; - f = d.result; - for (let g = 0, k, h, m; g < f.length; g++) { - h = f[g], "object" !== typeof h && (h = {id:h}), k = h.id, (m = b[k]) ? m.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); + for (let f = 0, d, e; f < a.length; f++) { + d = a[f]; + e = d.result; + for (let g = 0, k, h, m; g < e.length; g++) { + h = e[g], "object" !== typeof h && (h = {id:h}), k = h.id, (m = b[k]) ? m.push(d.field) : (h.field = b[k] = [d.field], c.push(h)); } } return c; } -function Ea(a, c, b, e, d) { - let f = this.tag.get(a); - if (!f) { +function Ea(a, c, b, f, d) { + let e = this.tag.get(a); + if (!e) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { - if (a > b || e) { - f = f.slice(e, e + b); + if ((a = (e = e && e.get(c)) && e.length - f) && 0 < a) { + if (a > b || f) { + e = e.slice(f, f + b); } - d && (f = Ha.call(this, f)); - return f; + d && (e = Ha.call(this, e)); + return e; } } function Ha(a) { @@ -967,8 +967,8 @@ function Ha(a) { return a; } const c = Array(a.length); - for (let b = 0, e; b < a.length; b++) { - e = a[b], c[b] = {id:e, doc:this.store.get(e)}; + for (let b = 0, f; b < a.length; b++) { + f = a[b], c[b] = {id:f, doc:this.store.get(f)}; } return c; } @@ -989,16 +989,16 @@ function Ha(a) { a.cache = !1; this.priority = a.priority || 4; b = new Map(); - let e = c.index || c.field || c; - L(e) && (e = [e]); - for (let d = 0, f, g; d < e.length; d++) { - f = e[d], L(f) || (g = f, f = f.field), g = P(g) ? Object.assign({}, a, g) : a, b.set(f, new Z(g, this.reg)), g.custom ? this.D[d] = g.custom : (this.D[d] = Ja(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)), this.field[d] = f; + let f = c.index || c.field || c; + L(f) && (f = [f]); + for (let d = 0, e, g; d < f.length; d++) { + e = f[d], L(e) || (g = e, e = e.field), g = P(g) ? Object.assign({}, a, g) : a, b.set(e, new Z(g, this.reg)), g.custom ? this.D[d] = g.custom : (this.D[d] = Ja(e, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)), this.field[d] = e; } if (this.A) { a = c.store; L(a) && (a = [a]); - for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Ja(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + for (let d = 0, e, g; d < a.length; d++) { + e = a[d], g = e.field || e, e.custom ? (this.A[d] = e.custom, e.custom.S = g) : (this.A[d] = Ja(g, this.J), e.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = e.filter)); } } this.index = b; @@ -1008,13 +1008,13 @@ function Ha(a) { this.tag = new Map(); this.B = []; this.R = []; - for (let d = 0, f, g; d < b.length; d++) { - f = b[d]; - g = f.field || f; + for (let d = 0, e, g; d < b.length; d++) { + e = b[d]; + g = e.field || e; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Ja(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + e.custom ? this.B[d] = e.custom : (this.B[d] = Ja(g, this.J), e.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = e.filter)); this.R[d] = g; this.tag.set(g, new Map()); } @@ -1023,12 +1023,12 @@ function Ha(a) { } function Ja(a, c) { const b = a.split(":"); - let e = 0; + let f = 0; for (let d = 0; d < b.length; d++) { - a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[f] = !0), a && (b[f++] = a); } - e < b.length && (b.length = e); - return 1 < e ? b : b[0]; + f < b.length && (b.length = f); + return 1 < f ? b : b[0]; } A = X.prototype; A.append = function(a, c) { @@ -1045,10 +1045,10 @@ A.remove = function(a) { if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { for (let b of this.tag.values()) { - for (let e of b) { - c = e[0]; - const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); + for (let f of b) { + c = f[0]; + const d = f[1], e = d.indexOf(a); + -1 < e && (1 < d.length ? d.splice(e, 1) : b.delete(c)); } } } @@ -1091,10 +1091,10 @@ A.set = function(a, c) { return this; }; A.searchCache = Ka; -A.export = function(a, c, b = 0, e = 0) { +A.export = function(a, c, b = 0, f = 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) { + if ((c = this.index.get(g).export(a, g, b, f = 1)) && c.then) { const k = this; return c.then(function() { return k.export(a, g, b + 1); @@ -1102,27 +1102,27 @@ A.export = function(a, c, b = 0, e = 0) { } return this.export(a, g, b + 1); } - let d, f; - switch(e) { + let d, e; + switch(f) { case 0: d = "reg"; - f = va(this.reg); + e = va(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && ra(this.tag, this.reg.size); + e = this.tag && ra(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && pa(this.store); + e = this.store && pa(this.store); c = null; break; default: return; } - return xa.call(this, a, c, d, f, b, e); + return xa.call(this, a, c, d, e, b, f); }; A.import = function(a, c) { var b = a.split("."); @@ -1138,8 +1138,8 @@ A.import = function(a, c) { case "reg": this.fastupdate = !1; this.reg = wa(c, this.reg); - for (let e = 0, d; e < this.field.length; e++) { - d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; + for (let f = 0, d; f < this.field.length; f++) { + d = this.index.get(this.field[f]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": @@ -1152,19 +1152,19 @@ A.import = function(a, c) { }; ka(X.prototype); function Ka(a, c, b) { - const e = (c ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); + const f = (c ? "" + a : "object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); - let d = this.cache.get(e); + let d = this.cache.get(f); if (!d) { d = this.search(a, c, b); if (d.then) { - const f = this; + const e = this; d.then(function(g) { - f.cache.set(e, g); + e.cache.set(f, g); return g; }); } - this.cache.set(e, d); + this.cache.set(f, d); } return d; } @@ -1200,23 +1200,23 @@ const Qa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j: var Ra = {Exact:La, Default:Ma, Normalize:Ma, LatinBalance:{mapper:Na}, LatinAdvanced:{mapper:Na, matcher:Oa, replacer:Pa}, LatinExtra:{mapper:Na, replacer:Pa.concat([/(?!^)[aeo]/g, ""]), matcher:Oa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Qa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let f = c.charAt(0), d = Qa[f]; + for (let e = 1, g; e < c.length && (g = c.charAt(e), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (f += g, d = g, 4 !== f.length)); e++) { } - a[b] = e; + a[b] = f; } }}, CJK:{split:""}, LatinExact:La, LatinDefault:Ma, LatinSimple:Ma}; Z.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { - for (let e = 0, d; e < b.length; e++) { - if (d = b[e]) { + for (let f = 0, d; f < b.length; f++) { + if (d = b[f]) { if (2 > d.length) { d.pop(); } else { - const f = d.indexOf(a); - f === b.length - 1 ? d.pop() : d.splice(f, 1); + const e = d.indexOf(a); + e === b.length - 1 ? d.pop() : d.splice(e, 1); } } } @@ -1230,15 +1230,15 @@ Z.prototype.remove = function(a, c) { }; function Sa(a, c) { let b = 0; - var e = "undefined" === typeof c; + var f = "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) { + for (let d = 0, e, g; d < a.length; d++) { + if ((e = a[d]) && e.length) { + if (f) { b++; } else { - if (g = f.indexOf(c), 0 <= g) { - 1 < f.length ? (f.splice(g, 1), b++) : delete a[d]; + if (g = e.indexOf(c), 0 <= g) { + 1 < e.length ? (e.splice(g, 1), b++) : delete a[d]; break; } else { b++; @@ -1248,38 +1248,38 @@ function Sa(a, c) { } } else { for (let d of a.entries()) { - e = d[0]; - const f = Sa(d[1], c); - f ? b += f : a.delete(e); + f = d[0]; + const e = Sa(d[1], c); + e ? b += e : a.delete(f); } } return b; } ;const Ta = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -Z.prototype.add = function(a, c, b, e) { +Z.prototype.add = function(a, c, b, f) { if (c && (a || 0 === a)) { - if (!e && !b && this.reg.has(a)) { + if (!f && !b && this.reg.has(a)) { return this.update(a, c); } - e = this.depth; - c = this.encoder.encode(c, !e); + f = this.depth; + c = this.encoder.encode(c, !f); const m = c.length; if (m) { - const n = J(), C = J(), x = this.resolution; + const n = J(), B = J(), x = this.resolution; for (let q = 0; q < m; q++) { let r = c[this.rtl ? m - 1 - q : q]; var d = r.length; - if (d && (e || !C[r])) { - var f = this.score ? this.score(c, r, q, null, 0) : Ua(x, m, q), g = ""; + if (d && (f || !B[r])) { + var e = this.score ? this.score(c, r, q, null, 0) : Ua(x, m, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (let w = 0, l; w < d; w++) { - for (f = d; f > w; f--) { - g = r.substring(w, f); + for (e = d; e > w; e--) { + g = r.substring(w, e); l = this.rtl ? d - 1 - w : w; var k = this.score ? this.score(c, r, q, g, l) : Ua(x, m, q, d, l); - Va(this, C, g, k, a, b); + Va(this, B, g, k, a, b); } } break; @@ -1290,24 +1290,24 @@ Z.prototype.add = function(a, c, b, e) { for (k = d - 1; 0 < k; k--) { g = r[this.rtl ? d - 1 - k : k] + g; var h = this.score ? this.score(c, r, q, g, k) : Ua(x, m, q, d, k); - Va(this, C, g, h, a, b); + Va(this, B, g, h, a, b); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[this.rtl ? d - 1 - k : k], Va(this, C, g, f, a, b); + g += r[this.rtl ? d - 1 - k : k], Va(this, B, g, e, a, b); } break; } default: - if (Va(this, C, r, f, a, b), e && 1 < m && q < m - 1) { - for (d = J(), g = this.P, f = r, k = Math.min(e + 1, this.rtl ? q + 1 : m - q), d[f] = 1, h = 1; h < k; h++) { + if (Va(this, B, r, e, a, b), f && 1 < m && q < m - 1) { + for (d = J(), g = this.P, e = r, k = Math.min(f + 1, this.rtl ? q + 1 : m - q), d[e] = 1, h = 1; h < k; h++) { if ((r = c[this.rtl ? m - 1 - q - h : q + h]) && !d[r]) { d[r] = 1; - const w = this.score ? this.score(c, f, q, r, h - 1) : Ua(g + (m / 2 > g ? 0 : 1), m, q, k - 1, h - 1), l = this.bidirectional && r > f; - Va(this, n, l ? f : r, w, a, b, l ? r : f); + const w = this.score ? this.score(c, e, q, r, h - 1) : Ua(g + (m / 2 > g ? 0 : 1), m, q, k - 1, h - 1), l = this.bidirectional && r > e; + Va(this, n, l ? e : r, w, a, b, l ? r : e); } } } @@ -1319,44 +1319,44 @@ Z.prototype.add = function(a, c, b, e) { } return this; }; -function Va(a, c, b, e, d, f, g) { +function Va(a, c, b, f, d, e, g) { let k = g ? a.ctx : a.map, h; if (!c[b] || g && !(h = c[b])[g]) { - g ? (c = h || (c[b] = J()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); + g ? (c = h || (c[b] = J()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[f] || (k[f] = []), e && 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 && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; +function Ua(a, c, b, f, d) { + return b && 1 < a ? c + (f || 0) <= a ? b + (d || 0) : (a - 1) / (c + (f || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;Z.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); if (b && b.cache) { return b.cache = !1, c = this.searchCache(a, c, b), b.cache = !0, c; } - var e = [], d = 0; + var f = [], d = 0; if (b) { a = b.query || a; c = b.limit || c; d = b.offset || 0; - var f = b.context; + var e = b.context; var g = b.suggest; var k = !0; var h = b.resolution; } "undefined" === typeof k && (k = !0); - f = this.depth && !1 !== f; - b = this.encoder.encode(a, !f); + e = this.depth && !1 !== e; + b = this.encoder.encode(a, !e); a = b.length; c = c || (k ? 100 : 0); if (1 === a) { return g = d, (d = Wa(this, b[0], "")) && d.length ? Ca.call(this, d, c, g) : []; } - if (2 === a && f && !g) { + if (2 === a && e && !g) { return g = d, (d = Wa(this, b[1], b[0])) && d.length ? Ca.call(this, d, c, g) : []; } k = J(); var m = 0; - if (f) { + if (e) { var n = b[0]; m = 1; } @@ -1366,22 +1366,22 @@ function Ua(a, c, b, e, d) { k[w] = 1; r = Wa(this, w, n); a: { - f = r; - var C = e, x = g, q = h; + e = r; + var B = f, x = g, q = h; let l = []; - if (f && f.length) { - if (f.length <= q) { - C.push(f); + if (e && e.length) { + if (e.length <= q) { + B.push(e); r = void 0; break a; } for (let u = 0, v; u < q; u++) { - if (v = f[u]) { + if (v = e[u]) { l[u] = v; } } if (l.length) { - C.push(l); + B.push(l); r = void 0; break a; } @@ -1389,28 +1389,28 @@ function Ua(a, c, b, e, d) { r = x ? void 0 : l; } if (r) { - e = r; + f = r; break; } - n && (g && r && e.length || (n = w)); + n && (g && r && f.length || (n = w)); } - g && n && m === a - 1 && !e.length && (h = this.resolution, n = "", m = -1, k = J()); + g && n && m === a - 1 && !f.length && (h = this.resolution, n = "", m = -1, k = J()); } a: { - b = e; - e = b.length; + b = f; + f = b.length; n = b; - if (1 < e) { + if (1 < f) { b: { - e = g; + f = g; n = b.length; g = []; a = J(); for (let r = 0, w, l, u, v; r < h; r++) { for (m = 0; m < n; m++) { if (u = b[m], r < u.length && (w = u[r])) { - for (f = 0; f < w.length; f++) { - if (l = w[f], (k = a[l]) ? a[l]++ : (k = 0, a[l] = 1), v = g[k] || (g[k] = []), v.push(l), c && k === n - 1 && v.length - d === c) { + for (e = 0; e < w.length; e++) { + if (l = w[e], (k = a[l]) ? a[l]++ : (k = 0, a[l] = 1), v = g[k] || (g[k] = []), v.push(l), c && k === n - 1 && v.length - d === c) { n = d ? v.slice(d) : v; break b; } @@ -1419,13 +1419,13 @@ function Ua(a, c, b, e, d) { } } if (b = g.length) { - if (e) { + if (f) { if (1 < g.length) { c: { - for (b = [], h = J(), e = g.length, k = e - 1; 0 <= k; k--) { - if (a = (e = g[k]) && e.length) { + for (b = [], h = J(), f = g.length, k = f - 1; 0 <= k; k--) { + if (a = (f = g[k]) && f.length) { for (m = 0; m < a; m++) { - if (n = e[m], !h[n]) { + if (n = f[m], !h[n]) { if (h[n] = 1, d) { d--; } else { @@ -1457,7 +1457,7 @@ function Ua(a, c, b, e, d) { } n = g; } - } else if (1 === e) { + } else if (1 === f) { c = Ca.call(null, b[0], c, d); break a; } @@ -1466,8 +1466,8 @@ function Ua(a, c, b, e, d) { return c; }; function Wa(a, c, b) { - let e; - b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); + let f; + b && (f = a.bidirectional && c > b) && (f = b, b = c, c = f); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } @@ -1482,20 +1482,20 @@ function Wa(a, c, b) { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = L(a.encoder) ? Ra[a.encoder] : a.encode || a.encoder || {}; + const f = !0 === b ? {depth:1} : b || {}, d = L(a.encoder) ? Ra[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new S(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && "exact" !== b && b || "strict"; - this.depth = "strict" === b && e.depth || 0; - this.bidirectional = !1 !== e.bidirectional; + this.depth = "strict" === b && f.depth || 0; + this.bidirectional = !1 !== f.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; - e && e.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); + f && f.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); b = !1; this.map = new Map(); this.ctx = new Map(); this.reg = c || (this.fastupdate ? new Map() : new Set()); - this.P = e.resolution || 3; + this.P = f.resolution || 3; this.rtl = d.rtl || a.rtl || !1; this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; @@ -1515,8 +1515,8 @@ A.contain = function(a) { return this.reg.has(a); }; A.update = function(a, c) { - const b = this, e = this.remove(a); - return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); + const b = this, f = this.remove(a); + return f && f.then ? f.then(() => b.add(a, c)) : this.add(a, c); }; A.cleanup = function() { if (!this.fastupdate) { @@ -1527,29 +1527,29 @@ A.cleanup = function() { return this; }; A.searchCache = Ka; -A.export = function(a, c, b = 0, e = 0) { - let d, f; - switch(e) { +A.export = function(a, c, b = 0, f = 0) { + let d, e; + switch(f) { case 0: d = "reg"; - f = va(this.reg); + e = va(this.reg); break; case 1: d = "cfg"; - f = null; + e = null; break; case 2: d = "map"; - f = pa(this.map, this.reg.size); + e = pa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ra(this.ctx, this.reg.size); + e = ra(this.ctx, this.reg.size); break; default: return; } - return xa.call(this, a, c, d, f, b, e); + return xa.call(this, a, c, d, e, b, f); }; A.import = function(a, c) { if (c) { @@ -1567,25 +1567,25 @@ A.import = function(a, c) { } }; A.serialize = function(a = !0) { - let c = "", b = "", e = ""; + let c = "", b = "", f = ""; if (this.reg.size) { - let f; + let e; for (var d of this.reg.keys()) { - f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); + e || (e = typeof d), c += (c ? "," : "") + ("string" === e ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = ya(this.map, f); + b = ya(this.map, e); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = ya(g[1], f); + let k = ya(g[1], e); k = "new Map([" + k + "])"; k = '["' + d + '",' + k + "]"; - e += (e ? "," : "") + k; + f += (f ? "," : "") + k; } - e = "index.ctx=new Map([" + e + "]);"; + f = "index.ctx=new Map([" + f + "]);"; } - return a ? "function inject(index){" + c + b + e + "}" : c + b + e; + return a ? "function inject(index){" + c + b + f + "}" : c + b + f; }; ka(Z.prototype); J(); diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index eb62a88..1c0ce90 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle) + * FlexSearch.js v0.8.163 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -32,8 +32,8 @@ G);else continue;(G-=l.length)||(G=-1);z[p]=G}else{y[p]=1;continue}if(D+l.length K?Q=0:U=0;if(!Q&&!U)break;Q?(L++,K=L):K++}}l="";for(let p=0,F;pb||e)a=a.slice(e,e+b);d&&(a=Ha.call(this,a));return a}}function Ha(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;b d) { - d -= g.length; - } else { - if (g.length > c || d) { - g = g.slice(d, c + d), c -= g.length, d && (d -= g.length); - } - e.push(g); - if (!c) { - break; + if (g = h[f]) { + if (d && g.length > d) { + d -= g.length; + } else { + if (c && g.length > c || d) { + g = g.slice(d, c + d), c -= g.length, d && (d -= g.length); + } + e.push(g); + if (!c) { + break; + } } } } - h = 1 < e.length ? [].concat.apply([], e) : e[0]; + h = e; } } } @@ -1912,8 +1914,23 @@ function tb(a, b, c) { } else if (n.constructor === Array) { r = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = (m = n.highlight && h) || n.enrich && h, n.index) { - n.resolve = !1, r = n.index.search(n).result, n.resolve = h, m && (q = n.search); + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = (m = n.highlight && h) || n.enrich && h, r = void 0, n.index && (a.index = r = n.index), n.query || n.tag) { + if (!a.index) { + throw Error("Resolver can't apply because the corresponding Index was never specified"); + } + if (n.field) { + if (!a.index.index) { + throw Error("Resolver can't apply because the corresponding Document Index was not specified"); + } + r = a.index.index.get(n.field); + if (!r) { + throw Error("Resolver can't apply because the specified Document field '" + n.field + "' was not found"); + } + } + n.resolve = !1; + r = r.search(n).result; + n.resolve = h; + m && (q = n.query); } else if (n.and) { r = a.and(n.and); } else if (n.or) { @@ -2345,14 +2362,14 @@ function Cb(a, b, c, d) { } return b; } -;function X(a) { +;function X(a, b) { if (!this || this.constructor !== X) { - return new X(a); + return new X(a, b); } 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; + return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = this.index.search(a).result, this; } - this.index = null; + this.index = b || null; this.result = a || []; this.h = 0; } @@ -2529,7 +2546,7 @@ ob.prototype.search = function(a, b, c, d) { if (G && G.length) { E++, t.push(G); } else if (!n) { - return h ? f : new X(f); + return h ? f : new X(f, this); } } } @@ -2541,13 +2558,13 @@ ob.prototype.search = function(a, b, c, d) { if (console.warn("Tag '" + p[C] + ":" + p[C + 1] + "' will be skipped because there is no field '" + p[C] + "'."), n) { continue; } else { - return h ? f : new X(f); + return h ? f : new X(f, this); } } if (N = (G = G && G.get(p[C + 1])) && G.length) { E++, t.push(G); } else if (!n) { - return h ? f : new X(f); + return h ? f : new X(f, this); } } } @@ -2555,7 +2572,7 @@ ob.prototype.search = function(a, b, c, d) { x = tb(x, t, h); A = x.length; if (!A && !n) { - return h ? x : new X(x); + return h ? x : new X(x, this); } E--; } @@ -2563,7 +2580,7 @@ ob.prototype.search = function(a, b, c, d) { if (A) { g[k] = D, f.push(x), k++; } else if (1 === q.length) { - return h ? f : new X(f); + return h ? f : new X(f, this); } } } @@ -2575,7 +2592,7 @@ ob.prototype.search = function(a, b, c, d) { if (console.warn("Tag '" + p[e] + ":" + p[e + 1] + "' was not found because there is no field '" + p[e] + "'."), n) { continue; } else { - return h ? f : new X(f); + return h ? f : new X(f, this); } } u.push(g.db.tag(p[e + 1], b, v, !1)); @@ -2587,17 +2604,17 @@ ob.prototype.search = function(a, b, c, d) { }); } if (!k) { - return h ? f : new X(f); + return h ? f : new X(f, this); } if (l && (!e || !this.store)) { - return f[0]; + return f = f[0], h || (f.index = this), f; } u = []; for (v = 0; v < g.length; v++) { n = f[v]; e && n.length && "undefined" === typeof n[0].doc && (this.db ? u.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = vb.call(this, n)); if (l) { - return h ? r ? Db(a, n, this.index, l, r) : n : new X(n); + return h ? r ? Db(a, n, this.index, l, r) : n : new X(n, this); } f[v] = {field:g[v], result:n}; } @@ -3206,15 +3223,15 @@ function $b(a, b, c, d, e, f, g) { if (1 < k) { h = rb(a, b, c, d, e, f, g); } else if (1 === k) { - return g ? ub.call(null, a[0], c, d) : new X(a[0]); + return g ? ub.call(null, a[0], c, d) : new X(a[0], this); } - return g ? h : new X(h); + return g ? h : new X(h, this); } function Xb(a, b, c, d, e, f, g) { a = Yb(this, a, b, c, d, e, f, g); return this.db ? a.then(function(k) { - return e ? k || [] : new X(k); - }) : a && a.length ? e ? ub.call(this, a, c, d) : new X(a) : e ? [] : new X(); + return e ? k || [] : new X(k, this); + }) : a && a.length ? e ? ub.call(this, a, c, d) : new X(a, this) : e ? [] : new X([], this); } function Zb(a, b, c, d) { var e = []; diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 082cef8..fee1f51 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (ES5) + * FlexSearch.js v0.8.163 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -71,10 +71,10 @@ function jb(){throw Error("The keystore is limited to 32 for EcmaScript5");};ob. g.R;if(h&&!h(b))continue;g.constructor===String&&(g=""+g);g=Ea(b,g)}if(f&&g){R(g)&&(g=[g]);h=0;for(var k,l=void 0;hc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+ -d)}else{e=[];for(f=0;fd)d-=g.length;else{if(g.length>c||d)g=g.slice(d,c+d),c-=g.length,d&&(d-=g.length);e.push(g);if(!c)break}k=1d)d-=g.length;else{if(c&&g.length>c||d)g=g.slice(d,c+d),c-=g.length,d&&(d-=g.length);e.push(g);if(!c)break}k=e}}return k} function sb(a,b,c,d,e){var f=[],g=Q(),h=a.length,k;if(d)for(e=h-1;0<=e;e--){if(k=(d=a[e])&&d.length)for(h=0;hb?b?a.slice(c,c+b):a.slice(c):a,d?vb.call(this,a):a;for(var e=[],f=0,g=void 0,h=void 0;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!e.length&&h>=b)return d?vb.call(this,g):g;e.push(g);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=sb(a,c,d,!1,this.h),d=0));return f?this.resolve(c,d,e):this};X.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var f=b.enrich&&c}}return a?(a=wb(this,"and",arguments),yb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,f):this}; +function tb(a,b,c){for(var d=Q(),e=[],f=0,g;fb?b?a.slice(c,c+b):a.slice(c):a,d?vb.call(this,a):a;for(var e=[],f=0,g=void 0,h=void 0;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!e.length&&h>=b)return d?vb.call(this,g):g;e.push(g);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=sb(a,c,d,!1,this.h),d=0));return f?this.resolve(c,d,e):this};X.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var f=b.enrich&&c}}return a?(a=wb(this,"and",arguments),yb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,f):this}; function yb(a,b,c,d,e,f,g){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=Fa(a))return this.result=rb(a,b,c,d,g,this.h,f),f?e?vb.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,d,e):this};X.prototype.xor=function(){var a=wb(this,"xor",arguments);return zb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; function zb(a,b,c,d,e,f,g){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=Ab.call(this,a,c,d,f,this.h),f?e?vb.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,d,e):this} function Ab(a,b,c,d,e){for(var f=[],g=Q(),h=0,k=0,l;kD&&(D=0)),C=C.length-1){if(K>=C.length){F[y+1]=1;K>=D.length&&(G[y+1]=1);continue}P-=p}t=C[K].text;var T=r&&M[y]; if(T)if(0T)if(F[y+1]=1,l)t=t.substring(0,T);else continue;(T-=t.length)||(T=-1);M[y]=T}else{F[y+1]=1;continue}if(P+t.length+1<=k)t=" "+t,N[y]+=t;else if(l)H=k-P-1,0=K){if(0>K){F[y]=1;G[y]=1;continue}P-=p}t=C[K].text;if(T=n&&J[y])if(0T)if(F[y]=1,l)t=t.substring(t.length-T);else continue;(T-=t.length)||(T=-1);J[y]=T}else{F[y]=1;continue}if(P+ t.length+1<=k)t+=" ",N[y]=t+N[y];else if(l)H=t.length+1-(k-P),0<=H&&H=D.length-1?H=1:Kc||d)a=a.slice(d,d+c);e&&(a=vb.call(this,a));return a}}function vb(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cq;Wb(this,f,u?q:l,v,a,c,u?l:q)}}}}this.fastupdate||this.reg.add(a)}else b=""}t function Wb(a,b,c,d,e,f,g){var h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=Q()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new ib(h);if(a.fastupdate)for(c=z(a.reg.values()),f=c.next();!f.done;f=c.next())f=f.value,f.includes(h)&&(f[f.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} function Vb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function U(a,b){if(!this||this.constructor!==U)return new U(a);if(a){var c=R(a)?a:a.preset;c&&(a=Object.assign({},Ub[c],a))}else a={};c=a.context;var d=!0===c?{depth:1}:c||{},e=R(a.encoder)?Rb[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new La(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&d.depth||0;this.bidirectional=!1!==d.bidirectional;this.fastupdate=!!a.fastupdate; +case 5:h&&u&&v===n-1&&!d.length&&(m=B.resolution,u="",v=-1,r=Q());v++;A.h=2;break;case 4:return A.return($b(d,m,b,e,h,l,f))}})}()}for(a=c=void 0;vc)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function U(a,b){if(!this||this.constructor!==U)return new U(a);if(a){var c=R(a)?a:a.preset;c&&(a=Object.assign({},Ub[c],a))}else a={};c=a.context;var d=!0===c?{depth:1}:c||{},e=R(a.encoder)?Rb[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new La(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&d.depth||0;this.bidirectional=!1!==d.bidirectional;this.fastupdate=!!a.fastupdate; this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new V(c):new Map;this.ctx=c?new V(c):new Map;this.reg=b||(this.fastupdate?c?new V(c):new Map:c?new W(c):new Set);this.da=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new Ib(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.ca=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=U.prototype; w.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};w.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};w.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function Tb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} w.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};w.append=function(a,b){return this.add(a,b,!0)};w.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};w.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)}; diff --git a/dist/flexsearch.light.debug.js b/dist/flexsearch.light.debug.js index ee4a23c..d71f9ea 100644 --- a/dist/flexsearch.light.debug.js +++ b/dist/flexsearch.light.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Light/Debug) + * FlexSearch.js v0.8.163 (Light/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index f87eeb8..18d0053 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Light) + * FlexSearch.js v0.8.163 (Light) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH diff --git a/dist/flexsearch.light.module.debug.js b/dist/flexsearch.light.module.debug.js index 0e30c1a..60616b1 100644 --- a/dist/flexsearch.light.module.debug.js +++ b/dist/flexsearch.light.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle/Debug) + * FlexSearch.js v0.8.163 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index 5dad66d..34fe507 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.162 (Bundle) + * FlexSearch.js v0.8.163 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index 6a98bfb..4e6f56c 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -307,7 +307,7 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return resolve || !!0 ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result, this); } } } @@ -323,7 +323,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return resolve || !!0 ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result, this); } } @@ -335,7 +335,7 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return resolve || !!0 ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result, this); } } } @@ -345,7 +345,7 @@ Document.prototype.search = function (query, limit, options, _promises) { len = res.length; if (!len && !suggest) { // nothing matched - return resolve || !!0 ? res : new Resolver( /** @type {IntermediateSearchResults} */res); + return resolve || !!0 ? res : new Resolver( /** @type {IntermediateSearchResults} */res, this); } // move counter back by 1 count--; @@ -358,7 +358,7 @@ Document.prototype.search = function (query, limit, options, _promises) { count++; } else if (1 === field.length) { // fast path: nothing matched - return resolve || !!0 ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result, this); } } @@ -376,7 +376,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return resolve || !!0 ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result, this); } } @@ -394,10 +394,12 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (!count) { - return resolve || !!0 ? result : new Resolver(result); + return resolve || !!0 ? result : new Resolver(result, this); } if (pluck && (!enrich || !this.store)) { - return (/** @type {SearchResults} */result[0] + result = result[0]; + if (!resolve) result.index = this; + return (/** @type {SearchResults|Resolver} */result ); } @@ -422,7 +424,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (pluck) { - return resolve || !!0 ? highlight ? highlight_fields( /** @type {string} */query, res, this.index, pluck, highlight) : /** @type {SearchResults|EnrichedSearchResults} */res : new Resolver( /** @type {IntermediateSearchResults} */res); + return resolve || !!0 ? highlight ? highlight_fields( /** @type {string} */query, res, this.index, pluck, highlight) : /** @type {SearchResults|EnrichedSearchResults} */res : new Resolver( /** @type {IntermediateSearchResults} */res, this); } result[i] = { diff --git a/dist/module-debug/index/search.js b/dist/module-debug/index/search.js index 18dc573..d9c8921 100644 --- a/dist/module-debug/index/search.js +++ b/dist/module-debug/index/search.js @@ -32,8 +32,7 @@ Index.prototype.search = function (query, limit, options) { if (options && options.cache) { options.cache = /* suggest */ /* append: */ /* enrich */!1; const res = this.searchCache(query, limit, options); - options.cache = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ - ; + options.cache = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; return res; } @@ -277,7 +276,6 @@ Index.prototype.search = function (query, limit, options) { } if (keyword) { - // the context is a moving window where the keyword is going forward like a cursor // 1. when suggestion enabled just forward keyword if term was found // 2. as long as the result is empty forward the pointer also @@ -324,10 +322,10 @@ function return_result(result, resolution, limit, offset, suggest, boost, resolv if (1 < length) { final = intersect(result, resolution, limit, offset, suggest, boost, resolve); } else if (1 === length) { - return resolve ? resolve_default.call(null, result[0], limit, offset) : new Resolver(result[0]); + return resolve ? resolve_default.call(null, result[0], limit, offset) : new Resolver(result[0], this); } - return resolve ? final : new Resolver(final); + return resolve ? final : new Resolver(final, this); } /** @@ -351,11 +349,11 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { if (this.db) { return result.then(function (result) { - return resolve ? result || [] : new Resolver(result); + return resolve ? result || [] : new Resolver(result, this); }); } - return result && result.length ? resolve ? resolve_default.call(this, /** @type {SearchResults|EnrichedSearchResults} */result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver(); + return result && result.length ? resolve ? resolve_default.call(this, /** @type {SearchResults|EnrichedSearchResults} */result, limit, offset) : new Resolver(result, this) : resolve ? [] : new Resolver([], this); } /** diff --git a/dist/module-debug/intersect.js b/dist/module-debug/intersect.js index 8a1753f..8181a6f 100644 --- a/dist/module-debug/intersect.js +++ b/dist/module-debug/intersect.js @@ -119,12 +119,12 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res const final = []; for (let i = 0, arr; i < result.length; i++) { arr = result[i]; - //if(!arr) continue; - if (arr.length > offset) { + if (!arr) continue; + if (offset && arr.length > offset) { offset -= arr.length; continue; } - if (arr.length > limit || offset) { + if (limit && arr.length > limit || offset) { arr = arr.slice(offset, limit + offset); limit -= arr.length; if (offset) offset -= arr.length; @@ -134,11 +134,15 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res break; } } - result = 1 < final.length ? concat(final) : final[0]; + result = final; + // result = final.length > 1 + // ? concat(final) + // : final[0]; } - return (/** @type {SearchResults|IntermediateSearchResults} */result - ); + // return /** @type {SearchResults|IntermediateSearchResults} */ ( + // result + // ); } } else { diff --git a/dist/module-debug/resolve/handler.js b/dist/module-debug/resolve/handler.js index f9e71da..f069c15 100644 --- a/dist/module-debug/resolve/handler.js +++ b/dist/module-debug/resolve/handler.js @@ -59,18 +59,42 @@ Resolver.prototype.handler = function (fn, args) { resolve = query.resolve; highlight = query.highlight && resolve; enrich = highlight || query.enrich && resolve; + let index; if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; + this.index = index = query.index; + } + + if (query.query || query.tag) { + if (!this.index) { + throw new Error("Resolver can't apply because the corresponding Index was never specified"); + } + + if (query.field) { + if (!this.index.index) { + throw new Error("Resolver can't apply because the corresponding Document Index was not specified"); + } + + + index = this.index.index.get(query.field); + + if (!index) { + throw new Error("Resolver can't apply because the specified Document field '" + query.field + "' was not found"); + } + } + + + query.resolve = /* suggest */ + /* append: */ /* enrich */!1; //if(DEBUG) //query.enrich = false; - result = query.index.search(query).result; + result = index.search(query).result; query.resolve = resolve; //if(DEBUG) //query.enrich = enrich; if (highlight) { - highlight_query = query.search; + highlight_query = query.query; } } else if (query.and) { result = this.and(query.and); diff --git a/dist/module-debug/resolver.js b/dist/module-debug/resolver.js index 9799719..4fed2ac 100644 --- a/dist/module-debug/resolver.js +++ b/dist/module-debug/resolver.js @@ -1,4 +1,5 @@ import Index from "./index.js"; +import Document from "./document.js"; import default_resolver from "./resolve/default.js"; import { apply_enrich } from "./document/search.js"; import { ResolverOptions, IntermediateSearchResults } from "./type.js"; @@ -11,13 +12,14 @@ import { highlight_fields } from "./document/highlight.js"; /** * @param {IntermediateSearchResults|ResolverOptions=} result + * @param {Index|Document=} index * @return {Resolver} * @constructor */ -export default function Resolver(result) { +export default function Resolver(result, index) { if (!this || this.constructor !== Resolver) { - return new Resolver(result); + return new Resolver(result, index); } // if(result && result.constructor === Resolver){ // // todo test this branch @@ -27,13 +29,13 @@ export default function Resolver(result) { if (result && result.index) { // result = /** @type {ResolverOptions} */ (result); result.resolve = /* suggest */ /* append: */ /* enrich */ /* resolve: */!1; - this.index = /** @type {Index} */result.index; + this.index = /** @type {Index|Document} */result.index; this.boostval = result.boost || 0; - this.result = result.index.search(result).result; + this.result = this.index.search(result).result; return this; } - /** @type {Index|null} */ - this.index = null; + /** @type {Index|Document|null} */ + this.index = index || null; /** @type {IntermediateSearchResults} */ this.result = /** @type {IntermediateSearchResults} */result || []; /** @type {number} */ diff --git a/dist/module-debug/type.js b/dist/module-debug/type.js index 5c1df48..df3bbb6 100644 --- a/dist/module-debug/type.js +++ b/dist/module-debug/type.js @@ -252,7 +252,7 @@ export let PersistentOptions = {}; /** * @typedef {{ - * index: (Index|undefined), + * index: (Index|Document|undefined), * query: (string|undefined), * limit: (number|undefined), * offset: (number|undefined), diff --git a/dist/module-min/document/search.js b/dist/module-min/document/search.js index 7443fcf..34bc717 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}from"../common.js";import{intersect_union}from"../intersect.js";import Document from"../document.js";import Index from"../index.js";import Resolver from"../resolver.js";import tick from"../profiler.js";import{highlight_fields}from"./highlight.js";Document.prototype.search=function(a,b,c,d){if(!1,c||(!b&&is_object(a)?(c=a,a=""):is_object(b)&&(c=b,b=0)),c&&c.cache){c.cache=!1;const d=this.searchCache(a,b,c);return c.cache=!0,d}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,m=q&&this.store&&c.highlight,f=!!m||q&&this.store&&c.enrich,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;bb,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file +import{SearchOptions,SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";import{create_object,is_object,sort_by_length_down}from"../common.js";import Index from"../index.js";import default_compress from"../compress.js";import Resolver from"../resolver.js";import{intersect}from"../intersect.js";import resolve_default from"../resolve/default.js";Index.prototype.search=function(a,b,c){if(c||(b||"object"!=typeof a?"object"==typeof b&&(c=b,b=0):(c=a,a="")),c&&c.cache){c.cache=!1;const d=this.searchCache(a,b,c);return c.cache=!0,d}let d,e,f,g,h,i,j,k,l=[],m=0;c&&(a=c.query||a,b=c.limit||b,m=c.offset||0,e=c.context,f=c.suggest,g=c.resolve,k=g&&c.enrich,i=c.boost,j=c.resolution,h=this.db&&c.tag),"undefined"==typeof g&&(g=this.resolve),e=this.depth&&!1!==e;let n=this.encoder.encode(a,!e);if(d=n.length,b=b||(g?100:0),1===d)return single_term_query.call(this,n[0],"",b,m,g,k,h);if(2===d&&e&&!f)return single_term_query.call(this,n[1],n[0],b,m,g,k,h);let o,p=create_object(),q=0;if(e&&(o=n[0],q=1),j||0===j||(j=o?this.resolution_ctx:this.resolution),this.db){if(this.db.search){const a=this.db.search(this,n,b,m,f,g,k,h);if(!1!==a)return a}const a=this;return async function(){for(let b,c;qb,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file diff --git a/dist/module-min/intersect.js b/dist/module-min/intersect.js index 14a44f3..7aa9df0 100644 --- a/dist/module-min/intersect.js +++ b/dist/module-min/intersect.js @@ -1 +1 @@ -import{create_object,concat,sort_by_length_up,get_max_len}from"./common.js";import{SearchResults,IntermediateSearchResults}from"./type.js";export function intersect(a,b,c,d,e,f,g){const h=a.length;let i,j,k=[];i=create_object();for(let l,m,n,o,p=0;pc||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((c&&b.length>c||d)&&(b=b.slice(d,c+d),c-=b.length,d&&(d-=b.length)),a.push(b),!c)break}k=a}}else 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 offset) { + if (!arr) continue; + if (offset && arr.length > offset) { offset -= arr.length; continue; } - if (arr.length > limit || offset) { + if (limit && arr.length > limit || offset) { arr = arr.slice(offset, limit + offset); limit -= arr.length; if (offset) offset -= arr.length; @@ -134,11 +134,15 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res break; } } - result = 1 < final.length ? concat(final) : final[0]; + result = final; + // result = final.length > 1 + // ? concat(final) + // : final[0]; } - return (/** @type {SearchResults|IntermediateSearchResults} */result - ); + // return /** @type {SearchResults|IntermediateSearchResults} */ ( + // result + // ); } } else { diff --git a/dist/module/resolve/handler.js b/dist/module/resolve/handler.js index f9e71da..a570e1a 100644 --- a/dist/module/resolve/handler.js +++ b/dist/module/resolve/handler.js @@ -59,18 +59,30 @@ Resolver.prototype.handler = function (fn, args) { resolve = query.resolve; highlight = query.highlight && resolve; enrich = highlight || query.enrich && resolve; + let index; if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; + this.index = index = query.index; + } + + if (query.query || query.tag) { + if (query.field) { + + index = this.index.index.get(query.field); + } + + + query.resolve = /* suggest */ + /* append: */ /* enrich */!1; //if(DEBUG) //query.enrich = false; - result = query.index.search(query).result; + result = index.search(query).result; query.resolve = resolve; //if(DEBUG) //query.enrich = enrich; if (highlight) { - highlight_query = query.search; + highlight_query = query.query; } } else if (query.and) { result = this.and(query.and); diff --git a/dist/module/resolver.js b/dist/module/resolver.js index 9799719..4fed2ac 100644 --- a/dist/module/resolver.js +++ b/dist/module/resolver.js @@ -1,4 +1,5 @@ import Index from "./index.js"; +import Document from "./document.js"; import default_resolver from "./resolve/default.js"; import { apply_enrich } from "./document/search.js"; import { ResolverOptions, IntermediateSearchResults } from "./type.js"; @@ -11,13 +12,14 @@ import { highlight_fields } from "./document/highlight.js"; /** * @param {IntermediateSearchResults|ResolverOptions=} result + * @param {Index|Document=} index * @return {Resolver} * @constructor */ -export default function Resolver(result) { +export default function Resolver(result, index) { if (!this || this.constructor !== Resolver) { - return new Resolver(result); + return new Resolver(result, index); } // if(result && result.constructor === Resolver){ // // todo test this branch @@ -27,13 +29,13 @@ export default function Resolver(result) { if (result && result.index) { // result = /** @type {ResolverOptions} */ (result); result.resolve = /* suggest */ /* append: */ /* enrich */ /* resolve: */!1; - this.index = /** @type {Index} */result.index; + this.index = /** @type {Index|Document} */result.index; this.boostval = result.boost || 0; - this.result = result.index.search(result).result; + this.result = this.index.search(result).result; return this; } - /** @type {Index|null} */ - this.index = null; + /** @type {Index|Document|null} */ + this.index = index || null; /** @type {IntermediateSearchResults} */ this.result = /** @type {IntermediateSearchResults} */result || []; /** @type {number} */ diff --git a/dist/module/type.js b/dist/module/type.js index 5c1df48..df3bbb6 100644 --- a/dist/module/type.js +++ b/dist/module/type.js @@ -252,7 +252,7 @@ export let PersistentOptions = {}; /** * @typedef {{ - * index: (Index|undefined), + * index: (Index|Document|undefined), * query: (string|undefined), * limit: (number|undefined), * offset: (number|undefined), diff --git a/index.d.ts b/index.d.ts index 931776d..3c5afa3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -583,35 +583,19 @@ declare module "flexsearch" { > { constructor(options: DocumentOptions); - add(id: Id, document: D): W extends WorkerType - ? Promise - : this; - add(document: D): W extends WorkerType - ? Promise - : this; + add(id: Id, document: D): W extends false ? this : Promise; + add(document: D): W extends false ? this : Promise; /** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */ - append(id: Id, document: D): W extends WorkerType - ? Promise - : this; + append(id: Id, document: D): W extends false ? this : Promise; /** @deprecated The method "append" will be removed in an upcoming release, just use "add" instead */ - append(document: D): W extends WorkerType - ? Promise - : this; + append(document: D): W extends false ? this : Promise; - update(id: Id, document: D): W extends WorkerType - ? Promise - : this; - update(document: D): W extends WorkerType - ? Promise - : this; + update(id: Id, document: D): W extends false ? this : Promise; + update(document: D): W extends false ? this : Promise; - remove(id: Id): W extends WorkerType - ? Promise - : this; - remove(document: D): W extends WorkerType - ? Promise - : this; + remove(id: Id): W extends false ? this : Promise; + remove(document: D): W extends false ? this : Promise; // https://github.com/nextapps-de/flexsearch#field-search search(query: string): DocumentSearchResultsWrapper; @@ -687,21 +671,19 @@ declare module "flexsearch" { ): DocumentSearchResultsWrapper; // https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids - contain(id: Id): D extends StorageInterface - ? Promise - : boolean; + contain(id: Id): S extends false + ? boolean + : Promise; - clear(): D extends StorageInterface - ? Promise - : W extends WorkerType - ? Promise - : void; + clear(): S extends false + ? W extends false ? void : Promise + : Promise; cleanup(): void; - get(id: Id): D extends StorageInterface - ? Promise - : D | null; + get(id: Id): S extends false + ? D | null + : Promise; set(id: Id, document: D): this; set(document: D): this; diff --git a/package-lock.json b/package-lock.json index fe08ac0..b81f2a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.162", + "version": "0.8.163", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.162", + "version": "0.8.163", "funding": [ { "type": "github", diff --git a/package.json b/package.json index eacd8a6..573ca93 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.162", + "version": "0.8.163", "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/document/search.js b/src/document/search.js index 62ed71a..12d7455 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -338,7 +338,7 @@ Document.prototype.search = function(query, limit, options, _promises){ // no tags found return resolve || !SUPPORT_RESOLVER ? result - : new Resolver(result) + : new Resolver(result, this) } } } @@ -361,7 +361,7 @@ Document.prototype.search = function(query, limit, options, _promises){ else{ return resolve || !SUPPORT_RESOLVER ? result - : new Resolver(result) + : new Resolver(result, this) } } @@ -376,7 +376,7 @@ Document.prototype.search = function(query, limit, options, _promises){ // no tags found return resolve || !SUPPORT_RESOLVER ? result - : new Resolver(result) + : new Resolver(result, this) } } } @@ -389,7 +389,7 @@ Document.prototype.search = function(query, limit, options, _promises){ // nothing matched return resolve || !SUPPORT_RESOLVER ? res - : new Resolver(/** @type {IntermediateSearchResults} */ (res)); + : new Resolver(/** @type {IntermediateSearchResults} */ (res), this); } // move counter back by 1 count--; @@ -405,7 +405,7 @@ Document.prototype.search = function(query, limit, options, _promises){ // fast path: nothing matched return resolve || !SUPPORT_RESOLVER ? result - : new Resolver(result); + : new Resolver(result, this); } } @@ -427,7 +427,7 @@ Document.prototype.search = function(query, limit, options, _promises){ else{ return resolve || !SUPPORT_RESOLVER ? result - : new Resolver(result); + : new Resolver(result, this); } } PROFILER && tick("Document.search:tag:get:" + tag[y + 1]); @@ -449,10 +449,12 @@ Document.prototype.search = function(query, limit, options, _promises){ if(!count){ return resolve || !SUPPORT_RESOLVER ? result - : new Resolver(result); + : new Resolver(result, this); } if(pluck && (!enrich || !this.store)){ - return /** @type {SearchResults} */ (result[0]); + result = result[0]; + if(!resolve) result.index = this; + return /** @type {SearchResults|Resolver} */ (result); } promises = []; @@ -481,7 +483,7 @@ Document.prototype.search = function(query, limit, options, _promises){ ? (highlight ? highlight_fields(/** @type {string} */ (query), res, this.index, pluck, highlight) : /** @type {SearchResults|EnrichedSearchResults} */ (res)) - : new Resolver(/** @type {IntermediateSearchResults} */ (res)); + : new Resolver(/** @type {IntermediateSearchResults} */ (res), this); } result[i] = { diff --git a/src/index/search.js b/src/index/search.js index 8b54608..90b59e6 100644 --- a/src/index/search.js +++ b/src/index/search.js @@ -304,7 +304,6 @@ Index.prototype.search = function(query, limit, options){ } if(keyword){ - // the context is a moving window where the keyword is going forward like a cursor // 1. when suggestion enabled just forward keyword if term was found // 2. as long as the result is empty forward the pointer also @@ -373,12 +372,12 @@ function return_result(result, resolution, limit, offset, suggest, boost, resolv limit, offset ) - : new Resolver(result[0]); + : new Resolver(result[0], this); } return !SUPPORT_RESOLVER || resolve ? final - : new Resolver(final); + : new Resolver(final, this); } /** @@ -412,18 +411,18 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag){ return result.then(function(result){ return !SUPPORT_RESOLVER || resolve ? result || [] - : new Resolver(result); + : new Resolver(result, this); }); } return result && result.length ? (!SUPPORT_RESOLVER || resolve ? resolve_default.call(this, /** @type {SearchResults|EnrichedSearchResults} */ (result), limit, offset) - : new Resolver(result) + : new Resolver(result, this) ) : !SUPPORT_RESOLVER || resolve ? [] - : new Resolver(); + : new Resolver([], this); } /** diff --git a/src/intersect.js b/src/intersect.js index 218901f..22b7e52 100644 --- a/src/intersect.js +++ b/src/intersect.js @@ -126,12 +126,12 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res const final = []; for(let i = 0, arr; i < result.length; i++){ arr = result[i]; - //if(!arr) continue; - if(arr.length > offset){ + if(!arr) continue; + if(offset && arr.length > offset){ offset -= arr.length; continue; } - if((arr.length > limit) || offset){ + if((limit && arr.length > limit) || offset){ arr = arr.slice(offset, limit + offset); limit -= arr.length; if(offset) offset -= arr.length; @@ -141,14 +141,15 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res break; } } - result = final.length > 1 - ? concat(final) - : final[0]; + result = final + // result = final.length > 1 + // ? concat(final) + // : final[0]; } - return /** @type {SearchResults|IntermediateSearchResults} */ ( - result - ); + // return /** @type {SearchResults|IntermediateSearchResults} */ ( + // result + // ); } } else{ diff --git a/src/resolve/handler.js b/src/resolve/handler.js index a5c7fca..22f14b8 100644 --- a/src/resolve/handler.js +++ b/src/resolve/handler.js @@ -1,8 +1,17 @@ // COMPILER BLOCK --> -import { DEBUG, SUPPORT_HIGHLIGHTING } from "../config.js"; +import { + DEBUG, + SUPPORT_DOCUMENT, + SUPPORT_HIGHLIGHTING, + SUPPORT_STORE +} from "../config.js"; // <-- COMPILER BLOCK import Resolver from "../resolver.js"; -import { ResolverOptions, SearchResults, IntermediateSearchResults } from "../type.js"; +import { + ResolverOptions, + SearchResults, + IntermediateSearchResults +} from "../type.js"; /** * @param {string} fn @@ -57,20 +66,51 @@ Resolver.prototype.handler = function(fn, args){ offset = query.offset || 0; suggest = query.suggest; resolve = query.resolve; - highlight = query.highlight && resolve; - enrich = highlight || (query.enrich && resolve); + highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && query.highlight && resolve; + enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && highlight || (query.enrich && resolve); + let index; if(query.index){ + this.index = index = query.index; + } + + if(query.query || query.tag){ + + if(DEBUG){ + if(!this.index){ + throw new Error("Resolver can't apply because the corresponding Index was never specified"); + } + } + + if(SUPPORT_DOCUMENT){ + if(query.field){ + + if(DEBUG){ + if(!this.index.index){ + throw new Error("Resolver can't apply because the corresponding Document Index was not specified"); + } + } + + index = this.index.index.get(query.field); + + if(DEBUG){ + if(!index){ + throw new Error("Resolver can't apply because the specified Document field '" + query.field + "' was not found"); + } + } + } + } + query.resolve = false; //if(DEBUG) //query.enrich = false; - result = query.index.search(query).result; + result = index.search(query).result; query.resolve = resolve; //if(DEBUG) //query.enrich = enrich; - if(SUPPORT_HIGHLIGHTING && highlight){ - highlight_query = query.search; + if(highlight){ + highlight_query = query.query; } } else if(query.and){ diff --git a/src/resolver.js b/src/resolver.js index b12b3d6..a1b719f 100644 --- a/src/resolver.js +++ b/src/resolver.js @@ -1,4 +1,5 @@ import Index from "./index.js"; +import Document from "./document.js"; import default_resolver from "./resolve/default.js"; import { apply_enrich } from "./document/search.js"; import { ResolverOptions, IntermediateSearchResults } from "./type.js"; @@ -11,13 +12,14 @@ import { highlight_fields } from "./document/highlight.js"; /** * @param {IntermediateSearchResults|ResolverOptions=} result + * @param {Index|Document=} index * @return {Resolver} * @constructor */ -export default function Resolver(result){ +export default function Resolver(result, index){ if(!this || this.constructor !== Resolver){ - return new Resolver(result); + return new Resolver(result, index); } // if(result && result.constructor === Resolver){ // // todo test this branch @@ -27,13 +29,13 @@ export default function Resolver(result){ if(result && result.index){ // result = /** @type {ResolverOptions} */ (result); result.resolve = false; - this.index = /** @type {Index} */ (result.index); + this.index = /** @type {Index|Document} */ (result.index); this.boostval = result.boost || 0; - this.result = result.index.search(result).result; + this.result = this.index.search(result).result; return this; } - /** @type {Index|null} */ - this.index = null; + /** @type {Index|Document|null} */ + this.index = index || null; /** @type {IntermediateSearchResults} */ this.result = /** @type {IntermediateSearchResults} */ (result) || []; /** @type {number} */ diff --git a/src/type.js b/src/type.js index a7dd737..b380720 100644 --- a/src/type.js +++ b/src/type.js @@ -252,7 +252,7 @@ export let PersistentOptions = {}; /** * @typedef {{ - * index: (Index|undefined), + * index: (Index|Document|undefined), * query: (string|undefined), * limit: (number|undefined), * offset: (number|undefined), diff --git a/test/issues.js b/test/issues.js index 7ad9c7d..5508e3c 100644 --- a/test/issues.js +++ b/test/issues.js @@ -105,4 +105,50 @@ describe("Github Issues", function(){ expect(userResult).to.eql([1]); expect(usersResult).to.eql([1]); }); + + it("#500", function(){ + + const indexableFields = ['field1', 'field2']; + + const searchIndex = new Document({ + document: { + id: '_id', + index: indexableFields.map(f => ({field: f, tokenize: 'full', encoder: Charset.LatinExtra})), + }, + }); + + searchIndex.add({ + _id: '123', + field1: '1234', + field2: '123 b', + }); + + const submitSearch = query => { + + // Since there are subfields to account for, build up the query one field at a time + let res = searchIndex.search({ + query, + field: "field1", + resolve: false + }); + + // Combine the queries with "or" and "resolve" them to get the results + res = res.or({ + query, + field: "field2" + }); + + res = res.resolve(); + + return res; + }; + + // console.log('this works', submitSearch('123')); + // console.log('this throws an error', submitSearch('1234')); + // console.log('this throws an error', submitSearch('123 b')); + + expect(submitSearch('123')).to.eql(["123"]); + expect(submitSearch('1234')).to.eql(["123"]); + expect(submitSearch('123 b')).to.eql(["123"]); + }); });