diff --git a/CHANGELOG.md b/CHANGELOG.md index 970a32f..b7b125d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Current Version +- Resolver: Support Result Highlighting + ### v0.8.2 - Config-Serialized Query Caches, Improved caching strategy for Document indexes and Resolver diff --git a/README.md b/README.md index 81d5c9e..a339577 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Getting instant help by the DeepWiki AI assistant: - + @@ -1299,7 +1299,7 @@ index.remove(0).update(1, 'foo').add(2, 'foobar'); ## Search Options - + @@ -1309,23 +1309,44 @@ index.remove(0).update(1, 'foo').add(2, 'foobar'); - + - + + + + + + + + - + + + + + + + + + + + + + + +
Option Values
limit numberSets the limit of results.Sets the limit of results 100
offset numberApply offset (skip items).Apply offset (skip items) 0
resolutionnumberLimit the resolution (score) of the results
suggest BooleanEnables suggestions in results.Enables Suggestions in results false
cacheBooleanUse a Query Cachefalse
resolveBooleanWhen set to false, an instance of a Resolver is returned to apply further operationstrue
## Suggestions @@ -1579,7 +1600,7 @@ The index size was measured after indexing the book "Gulliver's Travels". ## Fast-Update Mode -The default mode is highly optimized for search performance and adding contents to the index. Whenever you need to `update` or `remove` existing contents of an index you can enable an additional register which boost those tasks also to a high-performance level. This register will take an extra amount of memory (~30% increase of index size). +The default mode is highly optimized for search performance and adding contents to the index. Whenever you need to `update` or `remove` existing contents of an index you can enable an additional register that boosts those tasks also to a high-performance level. This register will take an extra amount of memory (~30% increase of index size). ```js const index = new Index({ diff --git a/dist/db/redis/index.cjs b/dist/db/redis/index.cjs index 6102b03..5b39f02 100644 --- a/dist/db/redis/index.cjs +++ b/dist/db/redis/index.cjs @@ -29,18 +29,16 @@ const defaults = { user: null, pass: null }; +let DB, TRX; function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } -let DB, TRX; - /** * @constructor * @implements StorageInterface */ - function RedisDB(name, config = {}){ if(!this || this.constructor !== RedisDB){ return new RedisDB(name, config); @@ -104,23 +102,26 @@ RedisDB.prototype.close = async function(){ }; RedisDB.prototype.destroy = function(){ - return this.clear(); + return this.clear(true); }; -RedisDB.prototype.clear = function(){ +RedisDB.prototype.clear = function(destroy = false){ if(!this.id) return; const self = this; - return this.db.keys( - this.id + "*" - - - - - - - ).then(function(keys){ + function unlink(keys){ return keys.length && self.db.unlink(keys); - }); + } + return Promise.all([ + this.db.keys(this.id + "map" + (destroy ? "" : this.field) + "*").then(unlink), + this.db.keys(this.id + "ctx" + (destroy ? "" : this.field) + "*").then(unlink), + this.db.keys(this.id + "tag" + (destroy ? "" : this.field) + "*").then(unlink), + this.db.keys(this.id + "ref" + (destroy ? "" : this.field) + "*").then(unlink), + unlink([ + this.id + "cfg" + (destroy ? "*" : this.field), + this.id + "doc", + this.id + "reg" + ]) + ]); }; function create_result(range, type, resolve, enrich, resolution){ @@ -216,7 +217,9 @@ RedisDB.prototype.enrich = function(ids){ }; RedisDB.prototype.has = function(id){ - return this.db.sIsMember(this.id + "reg", "" + id); + return this.db.sIsMember(this.id + "reg", "" + id).then(function(res){ + return !!res; + }); }; RedisDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 2a9a782..f314411 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.201 (Bundle/Debug) + * FlexSearch.js v0.8.202 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -7,30 +7,30 @@ */ (function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f; var w; -function H(a, c, b) { - const e = typeof b, d = typeof a; +function H(a, b, c) { + const e = typeof c, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { - if (b) { + if (c) { if ("function" === d && e === d) { - return function(h) { - return a(b(h)); + return function(k) { + return a(c(k)); }; } - c = a.constructor; - if (c === b.constructor) { - if (c === Array) { - return b.concat(a); + b = a.constructor; + if (b === c.constructor) { + if (b === Array) { + return c.concat(a); } - if (c === Map) { - var f = new Map(b); + if (b === Map) { + var f = new Map(c); for (var g of a) { f.set(g[0], g[1]); } return f; } - if (c === Set) { - g = new Set(b); + if (b === Set) { + g = new Set(c); for (f of a.values()) { g.add(f); } @@ -40,12 +40,12 @@ function H(a, c, b) { } return a; } - return b; + return c; } - return "undefined" === d ? c : a; + return "undefined" === d ? b : a; } -function aa(a, c) { - return "undefined" === typeof a ? c : a; +function aa(a, b) { + return "undefined" === typeof a ? b : a; } function I() { return Object.create(null); @@ -57,18 +57,18 @@ function ba(a) { return "object" === typeof a; } function ca(a) { - const c = []; - for (const b of a.keys()) { - c.push(b); + const b = []; + for (const c of a.keys()) { + b.push(c); } - return c; + return b; } -function da(a, c) { - if (N(c)) { - a = a[c]; +function da(a, b) { + if (N(b)) { + a = a[b]; } else { - for (let b = 0; a && b < c.length; b++) { - a = a[c[b]]; + for (let c = 0; a && c < b.length; c++) { + a = a[b[c]]; } } return a; @@ -89,27 +89,27 @@ function la(a = {}) { w = la.prototype; w.assign = function(a) { this.normalize = H(a.normalize, !0, this.normalize); - let c = a.include, b = c || a.exclude || a.split, e; - if (b || "" === b) { - if ("object" === typeof b && b.constructor !== RegExp) { + let b = a.include, c = b || a.exclude || a.split, e; + if (c || "" === c) { + if ("object" === typeof c && c.constructor !== RegExp) { let d = ""; - e = !c; - c || (d += "\\p{Z}"); - b.letter && (d += "\\p{L}"); - b.number && (d += "\\p{N}", e = !!c); - b.symbol && (d += "\\p{S}"); - b.punctuation && (d += "\\p{P}"); - b.control && (d += "\\p{C}"); - if (b = b.char) { - d += "object" === typeof b ? b.join("") : b; + e = !b; + b || (d += "\\p{Z}"); + c.letter && (d += "\\p{L}"); + c.number && (d += "\\p{N}", e = !!b); + c.symbol && (d += "\\p{S}"); + c.punctuation && (d += "\\p{P}"); + c.control && (d += "\\p{C}"); + if (c = c.char) { + d += "object" === typeof c ? c.join("") : c; } try { - this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); + this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); } catch (f) { - 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+/; + console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { - this.split = b, e = !1 === b || 2 > "a1a".split(b).length; + this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } this.numeric = H(a.numeric, e); } else { @@ -122,22 +122,22 @@ w.assign = function(a) { } this.prepare = H(a.prepare, null, this.prepare); this.finalize = H(a.finalize, null, this.finalize); - b = a.filter; - this.filter = "function" === typeof b ? b : H(b && new Set(b), null, this.filter); + c = a.filter; + this.filter = "function" === typeof c ? c : H(c && new Set(c), null, this.filter); this.dedupe = H(a.dedupe, !0, this.dedupe); - this.matcher = H((b = a.matcher) && new Map(b), null, this.matcher); - this.mapper = H((b = a.mapper) && new Map(b), null, this.mapper); - this.stemmer = H((b = a.stemmer) && new Map(b), null, this.stemmer); + this.matcher = H((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = H((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = H((c = a.stemmer) && new Map(c), null, this.stemmer); this.replacer = H(a.replacer, null, this.replacer); this.minlength = H(a.minlength, 1, this.minlength); this.maxlength = H(a.maxlength, 1024, this.maxlength); this.rtl = H(a.rtl, !1, this.rtl); - if (this.cache = b = H(a.cache, !0, this.cache)) { - this.I = null, this.R = "number" === typeof b ? b : 2e5, this.B = new Map(), this.H = new Map(), this.M = this.L = 128; + if (this.cache = c = H(a.cache, !0, this.cache)) { + this.I = null, this.R = "number" === typeof c ? c : 2e5, this.C = new Map(), this.H = new Map(), this.M = this.L = 128; } this.h = ""; this.N = null; - this.A = ""; + this.B = ""; this.O = null; if (this.matcher) { for (const d of this.matcher.keys()) { @@ -146,15 +146,15 @@ w.assign = function(a) { } if (this.stemmer) { for (const d of this.stemmer.keys()) { - this.A += (this.A ? "|" : "") + d; + this.B += (this.B ? "|" : "") + d; } } return this; }; -w.addStemmer = function(a, c) { +w.addStemmer = function(a, b) { this.stemmer || (this.stemmer = new Map()); - this.stemmer.set(a, c); - this.A += (this.A ? "|" : "") + a; + this.stemmer.set(a, b); + this.B += (this.B ? "|" : "") + a; this.O = null; this.cache && Q(this); return this; @@ -164,46 +164,46 @@ w.addFilter = function(a) { this.cache && Q(this); return this; }; -w.addMapper = function(a, c) { +w.addMapper = function(a, b) { if ("object" === typeof a) { - return this.addReplacer(a, c); + return this.addReplacer(a, b); } if (1 < a.length) { - return this.addMatcher(a, c); + return this.addMatcher(a, b); } this.mapper || (this.mapper = new Map()); - this.mapper.set(a, c); + this.mapper.set(a, b); this.cache && Q(this); return this; }; -w.addMatcher = function(a, c) { +w.addMatcher = function(a, b) { if ("object" === typeof a) { - return this.addReplacer(a, c); + return this.addReplacer(a, b); } if (2 > a.length && (this.dedupe || this.mapper)) { - return this.addMapper(a, c); + return this.addMapper(a, b); } this.matcher || (this.matcher = new Map()); - this.matcher.set(a, c); + this.matcher.set(a, b); this.h += (this.h ? "|" : "") + a; this.N = null; this.cache && Q(this); return this; }; -w.addReplacer = function(a, c) { +w.addReplacer = function(a, b) { if ("string" === typeof a) { - return this.addMatcher(a, c); + return this.addMatcher(a, b); } this.replacer || (this.replacer = []); - this.replacer.push(a, c); + this.replacer.push(a, b); this.cache && Q(this); return this; }; -w.encode = function(a, c) { +w.encode = function(a, b) { if (this.cache && a.length <= this.L) { if (this.I) { - if (this.B.has(a)) { - return this.B.get(a); + if (this.C.has(a)) { + return this.C.get(a); } } else { this.I = setTimeout(Q, 50, this); @@ -212,30 +212,30 @@ w.encode = function(a, c) { this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ka ? a.normalize("NFKD").replace(ka, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(ia, "$1 $2").replace(ja, "$1 $2").replace(ha, "$1 ")); - const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = I(), f, g, h = this.split || "" === this.split ? a.split(this.split) : [a]; - for (let m = 0, l, n; m < h.length; m++) { - if ((l = n = h[m]) && !(l.length < this.minlength || l.length > this.maxlength)) { - if (c) { - if (d[l]) { - continue; - } - d[l] = 1; - } else { - if (f === l) { - continue; - } - f = l; - } + const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + let e = [], d = I(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; + for (let l = 0, m, r; l < k.length; l++) { + if ((m = r = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (b) { - e.push(l); + if (d[m]) { + continue; + } + d[m] = 1; } else { - if (!this.filter || ("function" === typeof this.filter ? this.filter(l) : !this.filter.has(l))) { - if (this.cache && l.length <= this.M) { + 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.M) { if (this.I) { - var k = this.H.get(l); - if (k || "" === k) { - k && e.push(k); + var h = this.H.get(m); + if (h || "" === h) { + h && e.push(h); continue; } } else { @@ -243,68 +243,68 @@ w.encode = function(a, c) { } } if (this.stemmer) { - this.O || (this.O = new RegExp("(?!^)(" + this.A + ")$")); - let u; - for (; u !== l && 2 < l.length;) { - u = l, l = l.replace(this.O, p => this.stemmer.get(p)); + this.O || (this.O = new RegExp("(?!^)(" + this.B + ")$")); + let t; + for (; t !== m && 2 < m.length;) { + t = m, m = m.replace(this.O, q => this.stemmer.get(q)); } } - if (l && (this.mapper || this.dedupe && 1 < l.length)) { - k = ""; - for (let u = 0, p = "", t, r; u < l.length; u++) { - t = l.charAt(u), t === p && this.dedupe || ((r = this.mapper && this.mapper.get(t)) || "" === r ? r === p && this.dedupe || !(p = r) || (k += r) : k += p = t); + if (m && (this.mapper || this.dedupe && 1 < m.length)) { + h = ""; + for (let t = 0, q = "", u, n; t < m.length; t++) { + u = m.charAt(t), u === q && this.dedupe || ((n = this.mapper && this.mapper.get(u)) || "" === n ? n === q && this.dedupe || !(q = n) || (h += n) : h += q = u); } - l = k; + m = h; } - this.matcher && 1 < l.length && (this.N || (this.N = new RegExp("(" + this.h + ")", "g")), l = l.replace(this.N, u => this.matcher.get(u))); - if (l && this.replacer) { - for (k = 0; l && k < this.replacer.length; k += 2) { - l = l.replace(this.replacer[k], this.replacer[k + 1]); + this.matcher && 1 < m.length && (this.N || (this.N = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.N, t => this.matcher.get(t))); + if (m && this.replacer) { + for (h = 0; m && h < this.replacer.length; h += 2) { + m = m.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && n.length <= this.M && (this.H.set(n, l), this.H.size > this.R && (this.H.clear(), this.M = this.M / 1.1 | 0)); - if (l) { - if (l !== n) { - if (c) { - if (d[l]) { + this.cache && r.length <= this.M && (this.H.set(r, m), this.H.size > this.R && (this.H.clear(), this.M = this.M / 1.1 | 0)); + if (m) { + if (m !== r) { + if (b) { + if (d[m]) { continue; } - d[l] = 1; + d[m] = 1; } else { - if (g === l) { + if (g === m) { continue; } - g = l; + g = m; } } - e.push(l); + e.push(m); } } } } } this.finalize && (e = this.finalize(e) || e); - this.cache && a.length <= this.L && (this.B.set(a, e), this.B.size > this.R && (this.B.clear(), this.L = this.L / 1.1 | 0)); + this.cache && a.length <= this.L && (this.C.set(a, e), this.C.size > this.R && (this.C.clear(), this.L = this.L / 1.1 | 0)); return e; }; function Q(a) { a.I = null; - a.B.clear(); + a.C.clear(); a.H.clear(); } -;function ma(a, c, b) { - b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : b = a); - b && (a = b.query || a, c = b.limit || c); - let e = "" + (c || 0); - b && (e += (b.offset || 0) + !!b.context + !!b.suggest + (!1 !== b.resolve) + (b.resolution || this.resolution) + (b.boost || 0)); +;function ma(a, b, c) { + c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : c = a); + c && (a = c.query || a, b = c.limit || b); + let e = "" + (b || 0); + c && (e += (c.offset || 0) + !!c.context + !!c.suggest + (!1 !== c.resolve) + (c.resolution || this.resolution) + (c.boost || 0)); a = ("" + a).toLowerCase(); this.cache || (this.cache = new na()); let d = this.cache.get(a + e); if (!d) { - const f = b && b.cache; - f && (b.cache = !1); - d = this.search(a, c, b); - f && (b.cache = f); + const f = c && c.cache; + f && (c.cache = !1); + d = this.search(a, b, c); + f && (c.cache = f); this.cache.set(a + e, d); } return d; @@ -314,19 +314,19 @@ function na(a) { this.cache = new Map(); this.h = ""; } -na.prototype.set = function(a, c) { - this.cache.set(this.h = a, c); +na.prototype.set = function(a, b) { + this.cache.set(this.h = a, b); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; na.prototype.get = function(a) { - const c = this.cache.get(a); - c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); - return c; + const b = this.cache.get(a); + b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); + return b; }; na.prototype.remove = function(a) { - for (const c of this.cache) { - const b = c[0]; - c[1].includes(a) && this.cache.delete(b); + for (const b of this.cache) { + const c = b[0]; + b[1].includes(a) && this.cache.delete(c); } }; na.prototype.clear = function() { @@ -339,26 +339,26 @@ const sa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], const ta = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ua = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; const va = {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 wa = {Exact:qa, Default:ra, Normalize:ra, LatinBalance:{mapper:sa}, LatinAdvanced:{mapper:sa, matcher:ta, replacer:ua}, LatinExtra:{mapper:sa, replacer:ua.concat([/(?!^)[aeo]/g, ""]), matcher:ta}, 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 = va[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = va[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + for (let c = 0; c < a.length; c++) { + var b = a[c]; + let e = b.charAt(0), d = va[e]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = va[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[b] = e; + a[c] = e; } }}, CJK:{split:""}, LatinExact:qa, LatinDefault:ra, LatinSimple:ra}; -function za(a, c, b, e) { +function xa(a, b, c, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { - if (g = a.index[f], c >= g.length) { - c -= g.length; + if (g = a.index[f], b >= g.length) { + b -= g.length; } else { - c = g[e ? "splice" : "slice"](c, b); - const h = c.length; - if (h && (d = d.length ? d.concat(c) : c, b -= h, e && (a.length -= h), !b)) { + b = g[e ? "splice" : "slice"](b, c); + const k = b.length; + if (k && (d = d.length ? d.concat(b) : b, c -= k, e && (a.length -= k), !c)) { break; } - c = 0; + b = 0; } } return d; @@ -369,42 +369,42 @@ function Aa(a) { } this.index = a ? [a] : []; this.length = a ? a.length : 0; - const c = this; - return new Proxy([], {get(b, e) { + const b = this; + return new Proxy([], {get(c, e) { if ("length" === e) { - return c.length; + return b.length; } if ("push" === e) { return function(d) { - c.index[c.index.length - 1].push(d); - c.length++; + b.index[b.index.length - 1].push(d); + b.length++; }; } if ("pop" === e) { return function() { - if (c.length) { - return c.length--, c.index[c.index.length - 1].pop(); + if (b.length) { + return b.length--, b.index[b.index.length - 1].pop(); } }; } if ("indexOf" === e) { return function(d) { let f = 0; - for (let g = 0, h, k; g < c.index.length; g++) { - h = c.index[g]; - k = h.indexOf(d); - if (0 <= k) { - return f + k; + for (let g = 0, k, h; g < b.index.length; g++) { + k = b.index[g]; + h = k.indexOf(d); + if (0 <= h) { + return f + h; } - f += h.length; + f += k.length; } return -1; }; } if ("includes" === e) { return function(d) { - for (let f = 0; f < c.index.length; f++) { - if (c.index[f].includes(d)) { + for (let f = 0; f < b.index.length; f++) { + if (b.index[f].includes(d)) { return !0; } } @@ -413,24 +413,24 @@ function Aa(a) { } if ("slice" === e) { return function(d, f) { - return za(c, d || 0, f || c.length, !1); + return xa(b, d || 0, f || b.length, !1); }; } if ("splice" === e) { return function(d, f) { - return za(c, d || 0, f || c.length, !0); + return xa(b, d || 0, f || b.length, !0); }; } if ("constructor" === e) { return Array; } if ("symbol" !== typeof e) { - return (b = c.index[e / 2 ** 31 | 0]) && b[e]; + return (c = b.index[e / 2 ** 31 | 0]) && c[e]; } - }, set(b, e, d) { - b = e / 2 ** 31 | 0; - (c.index[b] || (c.index[b] = []))[e] = d; - c.length++; + }, set(c, e, d) { + c = e / 2 ** 31 | 0; + (b.index[c] || (b.index[c] = []))[e] = d; + b.length++; return !0; }}); } @@ -449,16 +449,16 @@ function R(a = 8) { this.index = I(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.C = Ba, this.B = BigInt(a)) : (this.C = Ca, this.B = a); } R.prototype.get = function(a) { - const c = this.index[this.B(a)]; - return c && c.get(a); + const b = this.index[this.C(a)]; + return b && b.get(a); }; -R.prototype.set = function(a, c) { - var b = this.B(a); - let e = this.index[b]; - e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++); +R.prototype.set = function(a, b) { + var c = this.C(a); + let e = this.index[c]; + e ? (c = e.size, e.set(a, b), (c -= e.size) && this.size++) : (this.index[c] = e = new Map([[a, b]]), this.h.push(e), this.size++); }; function S(a = 8) { if (!this || this.constructor !== S) { @@ -467,21 +467,21 @@ function S(a = 8) { this.index = I(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.C = Ba, this.B = BigInt(a)) : (this.C = Ca, this.B = a); } S.prototype.add = function(a) { - var c = this.B(a); - let b = this.index[c]; - b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.h.push(b), this.size++); + var b = this.C(a); + let c = this.index[b]; + c ? (b = c.size, c.add(a), (b -= c.size) && this.size++) : (this.index[b] = c = new Set([a]), this.h.push(c), this.size++); }; w = R.prototype; w.has = S.prototype.has = function(a) { - const c = this.index[this.B(a)]; - return c && c.has(a); + const b = this.index[this.C(a)]; + return b && b.has(a); }; w.delete = S.prototype.delete = function(a) { - const c = this.index[this.B(a)]; - c && c.delete(a) && this.size--; + const b = this.index[this.C(a)]; + b && b.delete(a) && this.size--; }; w.clear = S.prototype.clear = function() { this.index = I(); @@ -490,81 +490,81 @@ w.clear = S.prototype.clear = function() { }; w.values = S.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { - for (let c of this.h[a].values()) { - yield c; + for (let b of this.h[a].values()) { + yield b; } } }; w.keys = S.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { - for (let c of this.h[a].keys()) { - yield c; + for (let b of this.h[a].keys()) { + yield b; } } }; w.entries = S.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { - for (let c of this.h[a].entries()) { - yield c; + for (let b of this.h[a].entries()) { + yield b; } } }; function Ca(a) { - let c = 2 ** this.A - 1; + let b = 2 ** this.B - 1; if ("number" == typeof a) { - return a & c; + return a & b; } - let b = 0, e = this.A + 1; + let c = 0, e = this.B + 1; for (let d = 0; d < a.length; d++) { - b = (b * e ^ a.charCodeAt(d)) & c; + c = (c * e ^ a.charCodeAt(d)) & b; } - return 32 === this.A ? b + 2 ** 31 : b; + return 32 === this.B ? c + 2 ** 31 : c; } function Ba(a) { - let c = BigInt(2) ** this.A - BigInt(1); - var b = typeof a; - if ("bigint" === b) { - return a & c; + let b = BigInt(2) ** this.B - BigInt(1); + var c = typeof a; + if ("bigint" === c) { + return a & b; } - if ("number" === b) { - return BigInt(a) & c; + if ("number" === c) { + return BigInt(a) & b; } - b = BigInt(0); - let e = this.A + BigInt(1); + c = BigInt(0); + let e = this.B + BigInt(1); for (let d = 0; d < a.length; d++) { - b = (b * e ^ BigInt(a.charCodeAt(d))) & c; + c = (c * e ^ BigInt(a.charCodeAt(d))) & b; } - return b; + return c; } ;let Da, T; async function Ea(a) { a = a.data; - var c = a.task; - const b = a.id; + var b = a.task; + const c = a.id; let e = a.args; - switch(c) { + switch(b) { case "init": T = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), Da = new self.FlexSearch.Index(T), delete self.FlexSearch) : Da = new V(T); - postMessage({id:b}); + (b = a.factory) ? (Function("return " + b)()(self), Da = new self.FlexSearch.Index(T), delete self.FlexSearch) : Da = new V(T); + postMessage({id:c}); break; default: let d; - if ("export" === c) { + if ("export" === b) { if (!T.export || "function" !== typeof T.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } e[1] ? (e[0] = T.export, e[2] = 0, e[3] = 1) : e = null; } - if ("import" === c) { + if ("import" === b) { if (!T.import || "function" !== typeof T.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } e[0] && (a = await T.import.call(Da, e[0]), Da.import(e[0], a)); } else { - (d = e && Da[c].apply(Da, e)) && d.then && (d = await d), d && d.await && (d = await d.await), "search" === c && d.result && (d = d.result); + (d = e && Da[b].apply(Da, e)) && d.then && (d = await d), d && d.await && (d = await d.await), "search" === b && d.result && (d = d.result); } - postMessage("search" === c ? {id:b, msg:d} : {id:b}); + postMessage("search" === b ? {id:c, msg:d} : {id:c}); } } ;function Fa(a) { @@ -581,48 +581,48 @@ function Ka() { } function Ga(a) { this[a + "Async"] = function() { - const c = arguments; - var b = c[c.length - 1]; + const b = arguments; + var c = b[b.length - 1]; let e; - "function" === typeof b && (e = b, delete c[c.length - 1]); + "function" === typeof c && (e = c, delete b[b.length - 1]); Ha ? Ja || (Ja = Date.now() - Ia >= this.priority * this.priority * 3) : (Ha = setTimeout(Ka, 0), Ia = Date.now()); if (Ja) { const f = this; return new Promise(g => { setTimeout(function() { - g(f[a + "Async"].apply(f, c)); + g(f[a + "Async"].apply(f, b)); }, 0); }); } - const d = this[a].apply(this, c); - b = d.then ? d : new Promise(f => f(d)); - e && b.then(e); - return b; + const d = this[a].apply(this, b); + c = d.then ? d : new Promise(f => f(d)); + e && c.then(e); + return c; }; } ;let W = 0; -function La(a = {}, c) { - function b(h) { - function k(m) { - m = m.data || m; - const l = m.id, n = l && f.h[l]; - n && (n(m.msg), delete f.h[l]); +function La(a = {}, b) { + function c(k) { + function h(l) { + l = l.data || l; + const m = l.id, r = m && f.h[m]; + r && (r(l.msg), delete f.h[m]); } - this.worker = h; + this.worker = k; this.h = I(); if (this.worker) { - d ? this.worker.on("message", k) : this.worker.onmessage = k; + d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(m) { + return new Promise(function(l) { 1e9 < W && (W = 0); f.h[++W] = function() { - m(f); + l(f); }; f.worker.postMessage({id:W, task:"init", factory:e, options:a}); }); } this.priority = a.priority || 4; - this.encoder = c || null; + this.encoder = b || null; this.worker.postMessage({task:"init", factory:e, options:a}); return this; } @@ -634,9 +634,9 @@ function La(a = {}, c) { let e = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; e && (e = e.toString()); const d = "undefined" === typeof window, f = this, g = Ma(e, d, a.worker); - return g.then ? g.then(function(h) { - return b.call(f, h); - }) : b.call(this, g); + return g.then ? g.then(function(k) { + return c.call(f, k); + }) : c.call(this, g); } X("add"); X("append"); @@ -650,38 +650,38 @@ La.prototype.searchCache = ma; Fa(La.prototype); function X(a) { La.prototype[a] = function() { - const c = this, b = [].slice.call(arguments); - var e = b[b.length - 1]; + const b = this, c = [].slice.call(arguments); + var e = c[c.length - 1]; let d; - "function" === typeof e && (d = e, b.pop()); + "function" === typeof e && (d = e, c.pop()); e = new Promise(function(f) { - "export" === a && "function" === typeof b[0] && (b[0] = null); + "export" === a && "function" === typeof c[0] && (c[0] = null); 1e9 < W && (W = 0); - c.h[++W] = f; - c.worker.postMessage({task:a, id:W, args:b}); + b.h[++W] = f; + b.worker.postMessage({task:a, id:W, args:c}); }); return d ? (e.then(d), this) : e; }; } -function Ma(a, c, b) { - return c ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ea.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ma(a, b, c) { + return b ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ea.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;Na.prototype.add = function(a, c, b) { - ba(a) && (c = a, a = da(c, this.key)); - if (c && (a || 0 === a)) { - if (!b && this.reg.has(a)) { - return this.update(a, c); +;Na.prototype.add = function(a, b, c) { + ba(a) && (b = a, a = da(b, this.key)); + if (b && (a || 0 === a)) { + if (!c && this.reg.has(a)) { + return this.update(a, b); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.G[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); + for (let k = 0, h; k < this.field.length; k++) { + h = this.G[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(b); d && e.add(a, d, !1, !0); } else { - if (d = k.J, !d || d(c)) { - k.constructor === String ? k = ["" + k] : N(k) && (k = [k]), Oa(c, k, this.K, 0, e, a, k[0], b); + if (d = h.J, !d || d(b)) { + h.constructor === String ? h = ["" + h] : N(h) && (h = [h]), Oa(b, h, this.K, 0, e, a, h[0], c); } } } @@ -689,34 +689,34 @@ function Ma(a, c, b) { for (e = 0; e < this.F.length; e++) { var f = this.F[e], g = this.P[e]; d = this.tag.get(g); - let h = I(); + let k = I(); if ("function" === typeof f) { - if (f = f(c), !f) { + if (f = f(b), !f) { continue; } } else { - const k = f.J; - if (k && !k(c)) { + const h = f.J; + if (h && !h(b)) { continue; } f.constructor === String && (f = "" + f); - f = da(c, f); + f = da(b, f); } if (d && f) { N(f) && (f = [f]); - for (let k = 0, m, l; k < f.length; k++) { - if (m = f[k], !h[m] && (h[m] = 1, (g = d.get(m)) ? l = g : d.set(m, l = []), !b || !l.includes(a))) { - if (l.length === 2 ** 31 - 1) { - g = new Aa(l); + for (let h = 0, l, m; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !c || !m.includes(a))) { + if (m.length === 2 ** 31 - 1) { + g = new Aa(m); if (this.fastupdate) { - for (let n of this.reg.values()) { - n.includes(l) && (n[n.indexOf(l)] = g); + for (let r of this.reg.values()) { + r.includes(m) && (r[r.indexOf(m)] = g); } } - d.set(m, l = g); + d.set(l, m = g); } - l.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(l) : this.reg.set(a, [l])); + m.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); } } } else { @@ -724,99 +724,99 @@ function Ma(a, c, b) { } } } - if (this.store && (!b || !this.store.has(a))) { - let h; + if (this.store && (!c || !this.store.has(a))) { + let k; if (this.D) { - h = I(); - for (let k = 0, m; k < this.D.length; k++) { - m = this.D[k]; - if ((b = m.J) && !b(c)) { + k = I(); + for (let h = 0, l; h < this.D.length; h++) { + l = this.D[h]; + if ((c = l.J) && !c(b)) { continue; } - let l; - if ("function" === typeof m) { - l = m(c); - if (!l) { + let m; + if ("function" === typeof l) { + m = l(b); + if (!m) { continue; } - m = [m.U]; - } else if (N(m) || m.constructor === String) { - h[m] = c[m]; + l = [l.U]; + } else if (N(l) || l.constructor === String) { + k[l] = b[l]; continue; } - Ra(c, h, m, 0, m[0], l); + Ra(b, k, l, 0, l[0], m); } } - this.store.set(a, h || c); + this.store.set(a, k || b); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Ra(a, c, b, e, d, f) { +function Ra(a, b, c, e, d, f) { a = a[d]; - if (e === b.length - 1) { - c[d] = f || a; + if (e === c.length - 1) { + b[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Ra(a, c, b, e, d); + for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { + Ra(a, b, c, e, d); } } else { - c = c[d] || (c[d] = I()), d = b[++e], Ra(a, c, b, e, d); + b = b[d] || (b[d] = I()), d = c[++e], Ra(a, b, c, e, d); } } } -function Oa(a, c, b, e, d, f, g, h) { +function Oa(a, b, c, e, d, f, g, k) { if (a = a[g]) { - if (e === c.length - 1) { + if (e === b.length - 1) { if (a.constructor === Array) { - if (b[e]) { - for (c = 0; c < a.length; c++) { - d.add(f, a[c], !0, !0); + if (c[e]) { + for (b = 0; b < a.length; b++) { + d.add(f, a[b], !0, !0); } return; } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Oa(a, c, b, e, d, f, g, h); + Oa(a, b, c, e, d, f, g, k); } } else { - g = c[++e], Oa(a, c, b, e, d, f, g, h); + g = b[++e], Oa(a, b, c, e, d, f, g, k); } } } } -;function Sa(a, c, b, e) { +;function Sa(a, b, c, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a, e ? Ta.call(this, a) : a; + return a = a[0], a = c || a.length > b ? a.slice(c, c + b) : a, e ? Ta.call(this, a) : a; } let d = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { - if (b) { - if (b >= h) { - b -= h; + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { + if (c) { + if (c >= k) { + c -= k; continue; } - g = g.slice(b, b + c); - h = g.length; - b = 0; + g = g.slice(c, c + b); + k = g.length; + c = 0; } - h > c && (g = g.slice(0, c), h = c); - if (!d.length && h >= c) { + k > b && (g = g.slice(0, b), k = b); + if (!d.length && k >= b) { return e ? Ta.call(this, g) : g; } d.push(g); - c -= h; - if (!c) { + b -= k; + if (!b) { break; } } @@ -824,208 +824,206 @@ function Oa(a, c, b, e, d, f, g, h) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? Ta.call(this, d) : d; } -;function Ua(a, c, b, e) { +;function Ua(a, b, c, e) { var d = e[0]; if (d[0] && d[0].query) { - return a[c].apply(a, d); + return a[b].apply(a, d); } - if (!("and" !== c && "not" !== c || a.result.length || a.await || d.suggest)) { + if (!("and" !== b && "not" !== b || a.result.length || a.await || d.suggest)) { return 1 < e.length && (d = e[e.length - 1]), (e = d.resolve) ? a.await || a.result : a; } - let f = [], g = 0, h = 0, k, m, l; - var n; - let u; - for (c = 0; c < e.length; c++) { - if (d = e[c]) { - var p = void 0; + let f = [], g = 0, k = 0, h, l, m, r, t; + for (b = 0; b < e.length; b++) { + if (d = e[b]) { + var q = void 0; if (d.constructor === Y) { - p = d.await || d.result; + q = d.await || d.result; } else if (d.then || d.constructor === Array) { - p = d; + q = d; } else { g = d.limit || 0; - h = d.offset || 0; - l = d.suggest; - m = d.resolve; - k = (n = d.highlight && m) || d.enrich && m; - p = d.queue; - let t = d.async || p; - (n = d.index) ? a.index || (a.index = n) : n = a.index; + k = d.offset || 0; + m = d.suggest; + h = ((r = (l = d.resolve) && d.highlight) || d.enrich) && l; + q = d.queue; + let u = d.async || q, n = d.index; + n ? a.index || (a.index = n) : n = a.index; if (d.query || d.tag) { - if (!a.index) { + if (!n) { throw Error("Resolver can't apply because the corresponding Index was never specified"); } - const r = d.field || d.pluck; - if (r) { - if (!a.index.index) { + const p = d.field || d.pluck; + if (p) { + d.query && (a.query = d.query, a.field = p); + if (!n.index) { throw Error("Resolver can't apply because the corresponding Document Index was not specified"); } - n = a.index.index.get(r); + n = n.index.get(p); if (!n) { - throw Error("Resolver can't apply because the specified Document Field '" + r + "' was not found"); + throw Error("Resolver can't apply because the specified Document Field '" + p + "' was not found"); } } - if (p && (u || a.await)) { - u = 1; - let q; - const y = a.C.length, v = new Promise(function(A) { - q = A; + if (q && (t || a.await)) { + t = 1; + let y; + const v = a.A.length, D = new Promise(function(B) { + y = B; }); - (function(A, B) { - v.h = function() { - B.index = null; - B.resolve = !1; - let E = t ? A.searchAsync(B) : A.search(B); - if (E.then) { - return E.then(function(C) { - a.C[y] = C = C.result || C; - q(C); - return C; + (function(B, G) { + D.h = function() { + G.index = null; + G.resolve = !1; + let A = u ? B.searchAsync(G) : B.search(G); + if (A.then) { + return A.then(function(E) { + a.A[v] = E = E.result || E; + y(E); + return E; }); } - E = E.result || E; - q(E); - return E; + A = A.result || A; + y(A); + return A; }; })(n, Object.assign({}, d)); - a.C.push(v); - f[c] = v; + a.A.push(D); + f[b] = D; continue; } else { - d.resolve = !1, d.index = null, p = t ? n.searchAsync(d) : n.search(d), d.resolve = m, d.index = n; + d.resolve = !1, d.index = null, q = u ? n.searchAsync(d) : n.search(d), d.resolve = l, d.index = n; } } else if (d.and) { - p = Va(d, "and", n); + q = Va(d, "and", n); } else if (d.or) { - p = Va(d, "or", n); + q = Va(d, "or", n); } else if (d.not) { - p = Va(d, "not", n); + q = Va(d, "not", n); } else if (d.xor) { - p = Va(d, "xor", n); + q = Va(d, "xor", n); } else { continue; } } - p.await ? (u = 1, p = p.await) : p.then ? (u = 1, p = p.then(function(t) { - return t.result || t; - })) : p = p.result || p; - f[c] = p; + q.await ? (t = 1, q = q.await) : q.then ? (t = 1, q = q.then(function(u) { + return u.result || u; + })) : q = q.result || q; + f[b] = q; } } - u && !a.await && (a.await = new Promise(function(t) { - a.return = t; + t && !a.await && (a.await = new Promise(function(u) { + a.return = u; })); - if (u) { - const t = Promise.all(f).then(function(r) { - for (let q = 0; q < a.C.length; q++) { - if (a.C[q] === t) { - a.C[q] = function() { - return b.call(a, r, g, h, k, m, l); + if (t) { + const u = Promise.all(f).then(function(n) { + for (let p = 0; p < a.A.length; p++) { + if (a.A[p] === u) { + a.A[p] = function() { + return c.call(a, n, g, k, h, l, m, r); }; break; } } Wa(a); }); - a.C.push(t); + a.A.push(u); } else if (a.await) { - a.C.push(function() { - return b.call(a, f, g, h, k, m, l); + a.A.push(function() { + return c.call(a, f, g, k, h, l, m, r); }); } else { - return b.call(a, f, g, h, k, m, l); + return c.call(a, f, g, k, h, l, m, r); } - return m ? a.await || a.result : a; + return l ? a.await || a.result : a; } -function Va(a, c, b) { - a = a[c]; +function Va(a, b, c) { + a = a[b]; const e = a[0] || a; - e.index || (e.index = b); - b = new Y(e); - 1 < a.length && (b = b[c].apply(b, a.slice(1))); - return b; + e.index || (e.index = c); + c = new Y(e); + 1 < a.length && (c = c[b].apply(c, a.slice(1))); + return c; } ;Y.prototype.or = function() { return Ua(this, "or", Xa, arguments); }; -function Xa(a, c, b, e, d) { - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ya(a, c, b, !1, this.h), b = 0)); +function Xa(a, b, c, e, d, f, g) { + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ya(a, b, c, !1, this.h), c = 0)); d && (this.await = null); - return d ? this.resolve(c, b, e) : this; + return d ? this.resolve(b, c, e, g) : this; } ;Y.prototype.and = function() { return Ua(this, "and", Za, arguments); }; -function Za(a, c, b, e, d, f) { +function Za(a, b, c, e, d, f, g) { if (!f && !this.result.length) { return d ? this.result : this; } - let g; + let k; if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { let h = 0; - for (let k = 0, m, l; k < a.length; k++) { - if ((m = a[k]) && (l = m.length)) { - h < l && (h = l); + for (let l = 0, m, r; l < a.length; l++) { + if ((m = a[l]) && (r = m.length)) { + h < r && (h = r); } else if (!f) { h = 0; break; } } - h ? (this.result = $a(a, h, c, b, f, this.h, d), g = !0) : this.result = []; + h ? (this.result = $a(a, h, b, c, f, this.h, d), k = !0) : this.result = []; } } else { f || (this.result = a); } d && (this.await = null); - return d ? this.resolve(c, b, e, g) : this; + return d ? this.resolve(b, c, e, g, k) : this; } ;Y.prototype.xor = function() { return Ua(this, "xor", ab, arguments); }; -function ab(a, c, b, e, d, f) { +function ab(a, b, c, e, d, f, g) { if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { a: { - f = b; - var g = this.h; - const h = [], k = I(); + f = c; + var k = this.h; + const h = [], l = I(); let m = 0; - for (let l = 0, n; l < a.length; l++) { - if (n = a[l]) { - m < n.length && (m = n.length); - for (let u = 0, p; u < n.length; u++) { - if (p = n[u]) { - for (let t = 0, r; t < p.length; t++) { - r = p[t], k[r] = k[r] ? 2 : 1; + for (let r = 0, t; r < a.length; r++) { + if (t = a[r]) { + m < t.length && (m = t.length); + for (let q = 0, u; q < t.length; q++) { + if (u = t[q]) { + for (let n = 0, p; n < u.length; n++) { + p = u[n], l[p] = l[p] ? 2 : 1; } } } } } - for (let l = 0, n, u = 0; l < m; l++) { - for (let p = 0, t; p < a.length; p++) { - if (t = a[p]) { - if (n = t[l]) { - for (let r = 0, q; r < n.length; r++) { - if (q = n[r], 1 === k[q]) { + for (let r = 0, t, q = 0; r < m; r++) { + for (let u = 0, n; u < a.length; u++) { + if (n = a[u]) { + if (t = n[r]) { + for (let p = 0, y; p < t.length; p++) { + if (y = t[p], 1 === l[y]) { if (f) { f--; } else { if (d) { - if (h.push(q), h.length === c) { + if (h.push(y), h.length === b) { a = h; break a; } } else { - const y = l + (p ? g : 0); - h[y] || (h[y] = []); - h[y].push(q); - if (++u === c) { + const v = r + (u ? k : 0); + h[v] || (h[v] = []); + h[v].push(y); + if (++q === b) { a = h; break a; } @@ -1040,41 +1038,41 @@ function ab(a, c, b, e, d, f) { a = h; } this.result = a; - g = !0; + k = !0; } } else { f || (this.result = a); } d && (this.await = null); - return d ? this.resolve(c, b, e, g) : this; + return d ? this.resolve(b, c, e, g, k) : this; } ;Y.prototype.not = function() { return Ua(this, "not", bb, arguments); }; -function bb(a, c, b, e, d, f) { +function bb(a, b, c, e, d, f, g) { if (!f && !this.result.length) { return d ? this.result : this; } if (a.length && this.result.length) { a: { - f = b; - var g = []; + f = c; + var k = []; a = new Set(a.flat().flat()); - for (let h = 0, k, m = 0; h < this.result.length; h++) { - if (k = this.result[h]) { - for (let l = 0, n; l < k.length; l++) { - if (n = k[l], !a.has(n)) { + for (let h = 0, l, m = 0; h < this.result.length; h++) { + if (l = this.result[h]) { + for (let r = 0, t; r < l.length; r++) { + if (t = l[r], !a.has(t)) { if (f) { f--; } else { if (d) { - if (g.push(n), g.length === c) { - a = g; + if (k.push(t), k.length === b) { + a = k; break a; } } else { - if (g[h] || (g[h] = []), g[h].push(n), ++m === c) { - a = g; + if (k[h] || (k[h] = []), k[h].push(t), ++m === b) { + a = k; break a; } } @@ -1083,199 +1081,472 @@ function bb(a, c, b, e, d, f) { } } } - a = g; + a = k; } this.result = a; - g = !0; + k = !0; } d && (this.await = null); - return d ? this.resolve(c, b, e, g) : this; + return d ? this.resolve(b, c, e, g, k) : this; } -;function Y(a, c) { - if (!this || this.constructor !== Y) { - return new Y(a, c); +;function cb(a, b, c, e, d) { + let f, g, k; + "string" === typeof d ? (f = d, d = "") : f = d.template; + if (!f) { + throw Error('No template pattern was specified by the search option "highlight"'); } - let b = 0, e, d, f; + g = f.indexOf("$1"); + if (-1 === g) { + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); + } + k = f.substring(g + 2); + g = f.substring(0, g); + let h = d && d.boundary, l = !d || !1 !== d.clip, m = d && d.merge && k && g && new RegExp(k + " " + g, "g"); + d = d && d.ellipsis; + var r = 0; + if ("object" === typeof d) { + var t = d.template; + r = t.length - 2; + d = d.pattern; + } + "string" !== typeof d && (d = !1 === d ? "" : "..."); + r && (d = t.replace("$1", d)); + t = d.length - r; + let q, u; + "object" === typeof h && (q = h.before, 0 === q && (q = -1), u = h.after, 0 === u && (u = -1), h = h.total || 9e5); + r = new Map(); + for (let Pa = 0, ea, gb, oa; Pa < b.length; Pa++) { + let pa; + if (e) { + pa = b, oa = e; + } else { + var n = b[Pa]; + oa = n.field; + if (!oa) { + continue; + } + pa = n.result; + } + gb = c.get(oa); + ea = gb.encoder; + n = r.get(ea); + "string" !== typeof n && (n = ea.encode(a), r.set(ea, n)); + for (let ya = 0; ya < pa.length; ya++) { + var p = pa[ya].doc; + if (!p) { + continue; + } + p = da(p, oa); + if (!p) { + continue; + } + var y = p.trim().split(/\s+/); + if (!y.length) { + continue; + } + p = ""; + var v = []; + let za = []; + var D = -1, B = -1, G = 0; + for (var A = 0; A < y.length; A++) { + var E = y[A], z = ea.encode(E); + z = 1 < z.length ? z.join(" ") : z[0]; + let x; + if (z && E) { + var C = E.length, K = (ea.split ? E.replace(ea.split, "") : E).length - z.length, F = "", L = 0; + for (var O = 0; O < n.length; O++) { + var P = n[O]; + if (P) { + var M = P.length; + M += K; + L && M <= L || (P = z.indexOf(P), -1 < P && (F = (P ? E.substring(0, P) : "") + g + E.substring(P, P + M) + k + (P + M < C ? E.substring(P + M) : ""), L = M, x = !0)); + } + } + F && (h && (0 > D && (D = p.length + (p ? 1 : 0)), B = p.length + (p ? 1 : 0) + F.length, G += C, za.push(v.length), v.push({match:F})), p += (p ? " " : "") + F); + } + if (!x) { + E = y[A], p += (p ? " " : "") + E, h && v.push({text:E}); + } else if (h && G >= h) { + break; + } + } + G = za.length * (f.length - 2); + if (q || u || h && p.length - G > h) { + if (G = h + G - 2 * t, A = B - D, 0 < q && (A += q), 0 < u && (A += u), A <= G) { + y = q ? D - (0 < q ? q : 0) : D - ((G - A) / 2 | 0), v = u ? B + (0 < u ? u : 0) : y + G, l || (0 < y && " " !== p.charAt(y) && " " !== p.charAt(y - 1) && (y = p.indexOf(" ", y), 0 > y && (y = 0)), v < p.length && " " !== p.charAt(v - 1) && " " !== p.charAt(v) && (v = p.lastIndexOf(" ", v), v < B ? v = B : ++v)), p = (y ? d : "") + p.substring(y, v) + (v < p.length ? d : ""); + } else { + B = []; + D = {}; + G = {}; + A = {}; + E = {}; + z = {}; + F = K = C = 0; + for (O = L = 1;;) { + var U = void 0; + for (let x = 0, J; x < za.length; x++) { + J = za[x]; + if (F) { + if (K !== F) { + if (A[x + 1]) { + continue; + } + J += F; + if (D[J]) { + C -= t; + G[x + 1] = 1; + A[x + 1] = 1; + continue; + } + if (J >= v.length - 1) { + if (J >= v.length) { + A[x + 1] = 1; + J >= y.length && (G[x + 1] = 1); + continue; + } + C -= t; + } + p = v[J].text; + if (M = u && z[x]) { + if (0 < M) { + if (p.length > M) { + if (A[x + 1] = 1, l) { + p = p.substring(0, M); + } else { + continue; + } + } + (M -= p.length) || (M = -1); + z[x] = M; + } else { + A[x + 1] = 1; + continue; + } + } + if (C + p.length + 1 <= h) { + p = " " + p, B[x] += p; + } else if (l) { + U = h - C - 1, 0 < U && (p = " " + p.substring(0, U), B[x] += p), A[x + 1] = 1; + } else { + A[x + 1] = 1; + continue; + } + } else { + if (A[x]) { + continue; + } + J -= K; + if (D[J]) { + C -= t; + A[x] = 1; + G[x] = 1; + continue; + } + if (0 >= J) { + if (0 > J) { + A[x] = 1; + G[x] = 1; + continue; + } + C -= t; + } + p = v[J].text; + if (M = q && E[x]) { + if (0 < M) { + if (p.length > M) { + if (A[x] = 1, l) { + p = p.substring(p.length - M); + } else { + continue; + } + } + (M -= p.length) || (M = -1); + E[x] = M; + } else { + A[x] = 1; + continue; + } + } + if (C + p.length + 1 <= h) { + p += " ", B[x] = p + B[x]; + } else if (l) { + U = p.length + 1 - (h - C), 0 <= U && U < p.length && (p = p.substring(U) + " ", B[x] = p + B[x]), A[x] = 1; + } else { + A[x] = 1; + continue; + } + } + } else { + p = v[J].match; + q && (E[x] = q); + u && (z[x] = u); + x && C++; + let Qa; + J ? !x && t && (C += t) : (G[x] = 1, A[x] = 1); + J >= y.length - 1 ? Qa = 1 : J < v.length - 1 && v[J + 1].match ? Qa = 1 : t && (C += t); + C -= f.length - 2; + if (!x || C + p.length <= h) { + B[x] = p; + } else { + U = L = O = G[x] = 0; + break; + } + Qa && (G[x + 1] = 1, A[x + 1] = 1); + } + C += p.length; + U = D[J] = 1; + } + if (U) { + K === F ? F++ : K++; + } else { + K === F ? L = 0 : O = 0; + if (!L && !O) { + break; + } + L ? (K++, F = K) : F++; + } + } + p = ""; + for (let x = 0, J; x < B.length; x++) { + J = (x && G[x] ? " " : (x && !d ? " " : "") + d) + B[x], p += J; + } + d && !G[B.length] && (p += d); + } + } + m && (p = p.replace(m, " ")); + pa[ya].highlight = p; + } + if (e) { + break; + } + } + return b; +} +;function Y(a, b) { + if (!this || this.constructor !== Y) { + return new Y(a, b); + } + let c = 0, e, d, f, g, k; if (a && a.index) { - const g = a; - c = g.index; - b = g.boost || 0; - if (g.query) { - const h = g.resolve; - a = g.async || g.queue; - g.resolve = !1; - g.index = null; - a = a ? c.searchAsync(g) : c.search(g); - g.resolve = h; - g.index = c; + const h = a; + b = h.index; + c = h.boost || 0; + if (d = h.query) { + f = h.field || h.pluck; + const l = h.resolve; + a = h.async || h.queue; + h.resolve = !1; + h.index = null; + a = a ? b.searchAsync(h) : b.search(h); + h.resolve = l; + h.index = b; a = a.result || a; } else { a = []; } } if (a && a.then) { - const g = this; - a = a.then(function(h) { - g.C[0] = g.result = h.result || h; - Wa(g); + const h = this; + a = a.then(function(l) { + h.A[0] = h.result = l.result || l; + Wa(h); }); e = [a]; a = []; - d = new Promise(function(h) { - f = h; + g = new Promise(function(l) { + k = l; }); } - this.index = c || null; + this.index = b || null; this.result = a || []; - this.h = b; - this.C = e || []; - this.await = d || null; - this.return = f || null; + this.h = c; + this.A = e || []; + this.await = g || null; + this.return = k || null; + this.query = d || ""; + this.field = f || ""; } -Y.prototype.limit = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, e; b < this.result.length; b++) { - if (e = this.result[b]) { - if (e.length <= a) { - if (c[b] = e, a -= e.length, !a) { +w = Y.prototype; +w.limit = function(a) { + if (this.await) { + const b = this; + this.A.push(function() { + b.limit(a); + return b.result; + }); + } else { + if (this.result.length) { + const b = []; + for (let c = 0, e; c < this.result.length; c++) { + if (e = this.result[c]) { + if (e.length <= a) { + if (b[c] = e, a -= e.length, !a) { + break; + } + } else { + b[c] = e.slice(0, a); break; } - } else { - c[b] = e.slice(0, a); - break; } } + this.result = b; } - this.result = c; } return this; }; -Y.prototype.offset = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, e; b < this.result.length; b++) { - if (e = this.result[b]) { - e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0); +w.offset = function(a) { + if (this.await) { + const b = this; + this.A.push(function() { + b.offset(a); + return b.result; + }); + } else { + if (this.result.length) { + const b = []; + for (let c = 0, e; c < this.result.length; c++) { + if (e = this.result[c]) { + e.length <= a ? a -= e.length : (b[c] = e.slice(a), a = 0); + } } + this.result = b; } - this.result = c; } return this; }; -Y.prototype.boost = function(a) { - this.h += a; +w.boost = function(a) { + if (this.await) { + const b = this; + this.A.push(function() { + b.boost(a); + return b.result; + }); + } else { + this.h += a; + } return this; }; -function Wa(a, c) { - let b = a.result; - for (let d = 0, f; d < a.C.length; d++) { - if (f = a.C[d]) { - if ("function" === typeof f) { - b = f(), a.C[d] = b = b.result || b, d--; - } else if (f.h) { - b = f.h(), a.C[d] = b = b.result || b, d--; - } else if (f.then) { - return a.await; - } - } - } - const e = a.return; - a.result = b; - a.C = []; +function Wa(a, b) { + let c = a.result; + var e = a.await; a.await = null; + for (let d = 0, f; d < a.A.length; d++) { + if (f = a.A[d]) { + if ("function" === typeof f) { + c = f(), a.A[d] = c = c.result || c, d--; + } else if (f.h) { + c = f.h(), a.A[d] = c = c.result || c, d--; + } else if (f.then) { + return a.await = e; + } + } + } + e = a.return; + a.A = []; a.return = null; - c || e(b); - return b; + b || e(c); + return c; } -Y.prototype.resolve = function(a, c, b, e) { - let d = this.await ? Wa(this, !0) : this.result; - if (d.then) { - const f = this; - return d.then(function() { - return f.resolve(a, c, b); +w.resolve = function(a, b, c, e, d) { + let f = this.await ? Wa(this, !0) : this.result; + if (f.then) { + const g = this; + return f.then(function() { + return g.resolve(a, b, c, e, d); }); } - d.length && ("object" === typeof a && (b = a.enrich, c = a.offset, a.highlight && console.warn('Highlighting results is not supported within the resolve() method. Instead pass highlight options within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'), a = a.limit), d = e ? b ? Ta.call(this.index, d) : d : Sa.call(this.index, d, a || 100, c, b)); - e = this.return; - this.return = this.await = this.C = this.result = this.index = null; - e && e(d); - return d; + f.length && ("object" === typeof a ? (e = a.highlight, c = !!e || a.enrich, b = a.offset, a = a.limit) : c = !!e || c, f = d ? c ? Ta.call(this.index, f) : f : Sa.call(this.index, f, a || 100, b, c)); + return this.finalize(f, e); }; -function $a(a, c, b, e, d, f, g) { - const h = a.length; - let k = [], m, l; - m = I(); - for (let n = 0, u, p, t, r; n < c; n++) { - for (let q = 0; q < h; q++) { - if (t = a[q], n < t.length && (u = t[n])) { - for (let y = 0; y < u.length; y++) { - p = u[y]; - (l = m[p]) ? m[p]++ : (l = 0, m[p] = 1); - r = k[l] || (k[l] = []); +w.finalize = function(a, b) { + if (a.then) { + const e = this; + return a.then(function(d) { + return e.finalize(d, b); + }); + } + b && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); + b && a.length && this.query && (a = cb(this.query, a, this.index.index, this.field, b)); + const c = this.return; + this.index = this.result = this.A = this.await = this.return = null; + this.query = this.field = ""; + c && c(a); + return a; +}; +function $a(a, b, c, e, d, f, g) { + const k = a.length; + let h = [], l, m; + l = I(); + for (let r = 0, t, q, u, n; r < b; r++) { + for (let p = 0; p < k; p++) { + if (u = a[p], r < u.length && (t = u[r])) { + for (let y = 0; y < t.length; y++) { + q = t[y]; + (m = l[q]) ? l[q]++ : (m = 0, l[q] = 1); + n = h[m] || (h[m] = []); if (!g) { - let v = n + (q || !d ? 0 : f || 0); - r = r[v] || (r[v] = []); + let v = r + (p || !d ? 0 : f || 0); + n = n[v] || (n[v] = []); } - r.push(p); - if (g && b && l === h - 1 && r.length - e === b) { - return e ? r.slice(e) : r; + n.push(q); + if (g && c && m === k - 1 && n.length - e === c) { + return e ? n.slice(e) : n; } } } } } - if (a = k.length) { + if (a = h.length) { if (d) { - k = 1 < k.length ? Ya(k, b, e, g, f) : (k = k[0]) && b && k.length > b || e ? k.slice(e, b + e) : k; + h = 1 < h.length ? Ya(h, c, e, g, f) : (h = h[0]) && c && h.length > c || e ? h.slice(e, c + e) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; - if (b || e) { + h = h[a - 1]; + if (c || e) { if (g) { - if (k.length > b || e) { - k = k.slice(e, b + e); + if (h.length > c || e) { + h = h.slice(e, c + e); } } else { d = []; - for (let n = 0, u; n < k.length; n++) { - if (u = k[n]) { - if (e && u.length > e) { - e -= u.length; + for (let r = 0, t; r < h.length; r++) { + if (t = h[r]) { + if (e && t.length > e) { + e -= t.length; } else { - if (b && u.length > b || e) { - u = u.slice(e, b + e), b -= u.length, e && (e -= u.length); + if (c && t.length > c || e) { + t = t.slice(e, c + e), c -= t.length, e && (e -= t.length); } - d.push(u); - if (!b) { + d.push(t); + if (!c) { break; } } } } - k = d; + h = d; } } } } - return k; + return h; } -function Ya(a, c, b, e, d) { +function Ya(a, b, c, e, d) { const f = [], g = I(); - let h; - var k = a.length; - let m; + let k; + var h = a.length; + let l; if (e) { - for (d = k - 1; 0 <= d; d--) { - if (m = (e = a[d]) && e.length) { - for (k = 0; k < m; k++) { - if (h = e[k], !g[h]) { - if (g[h] = 1, b) { - b--; + for (d = h - 1; 0 <= d; d--) { + if (l = (e = a[d]) && e.length) { + for (h = 0; h < l; h++) { + if (k = e[h], !g[k]) { + if (g[k] = 1, c) { + c--; } else { - if (f.push(h), f.length === c) { + if (f.push(k), f.length === b) { return f; } } @@ -1284,18 +1555,18 @@ function Ya(a, c, b, e, d) { } } } else { - for (let l = k - 1, n, u = 0; 0 <= l; l--) { - n = a[l]; - for (let p = 0; p < n.length; p++) { - if (m = (e = n[p]) && e.length) { - for (let t = 0; t < m; t++) { - if (h = e[t], !g[h]) { - if (g[h] = 1, b) { - b--; + for (let m = h - 1, r, t = 0; 0 <= m; m--) { + r = a[m]; + for (let q = 0; q < r.length; q++) { + if (l = (e = r[q]) && e.length) { + for (let u = 0; u < l; u++) { + if (k = e[u], !g[k]) { + if (g[k] = 1, c) { + c--; } else { - let r = (p + (l < k - 1 ? d || 0 : 0)) / (l + 1) | 0; - (f[r] || (f[r] = [])).push(h); - if (++u === c) { + let n = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[n] || (f[n] = [])).push(k); + if (++t === b) { return f; } } @@ -1307,311 +1578,78 @@ function Ya(a, c, b, e, d) { } return f; } -function cb(a, c, b) { +function db(a, b, c) { const e = I(), d = []; - for (let f = 0, g; f < c.length; f++) { - g = c[f]; - for (let h = 0; h < g.length; h++) { - e[g[h]] = 1; + for (let f = 0, g; f < b.length; f++) { + g = b[f]; + for (let k = 0; k < g.length; k++) { + e[g[k]] = 1; } } - if (b) { + if (c) { for (let f = 0, g; f < a.length; f++) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, h; f < a.result.length; f++) { - for (g = a.result[f], c = 0; c < g.length; c++) { - h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); + for (let f = 0, g, k; f < a.result.length; f++) { + for (g = a.result[f], b = 0; b < g.length; b++) { + k = g[b], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); } } } return d; } ;I(); -function db(a, c, b, e, d) { - let f, g, h; - "string" === typeof d ? (f = d, d = "") : f = d.template; - if (!f) { - throw Error('No template pattern was specified by the search option "highlight"'); - } - g = f.indexOf("$1"); - if (-1 === g) { - throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); - } - h = f.substring(g + 2); - g = f.substring(0, g); - let k = d && d.boundary, m = !d || !1 !== d.clip, l = d && d.merge && h && g && new RegExp(h + " " + g, "g"); - d = d && d.ellipsis; - var n = 0; - if ("object" === typeof d) { - var u = d.template; - n = u.length - 2; - d = d.pattern; - } - "string" !== typeof d && (d = !1 === d ? "" : "..."); - n && (d = u.replace("$1", d)); - u = d.length - n; - let p, t; - "object" === typeof k && (p = k.before, 0 === p && (p = -1), t = k.after, 0 === t && (t = -1), k = k.total || 9e5); - n = new Map(); - for (let Pa = 0, ea, gb, oa; Pa < c.length; Pa++) { - let pa; - if (e) { - pa = c, oa = e; - } else { - var r = c[Pa]; - oa = r.field; - if (!oa) { - continue; - } - pa = r.result; - } - gb = b.get(oa); - ea = gb.encoder; - r = n.get(ea); - "string" !== typeof r && (r = ea.encode(a), n.set(ea, r)); - for (let xa = 0; xa < pa.length; xa++) { - var q = pa[xa].doc; - if (!q) { - continue; - } - q = da(q, oa); - if (!q) { - continue; - } - var y = q.trim().split(/\s+/); - if (!y.length) { - continue; - } - q = ""; - var v = []; - let ya = []; - var A = -1, B = -1, E = 0; - for (var C = 0; C < y.length; C++) { - var F = y[C], z = ea.encode(F); - z = 1 < z.length ? z.join(" ") : z[0]; - let x; - if (z && F) { - var D = F.length, K = (ea.split ? F.replace(ea.split, "") : F).length - z.length, G = "", L = 0; - for (var O = 0; O < r.length; O++) { - var P = r[O]; - if (P) { - var M = P.length; - M += K; - L && M <= L || (P = z.indexOf(P), -1 < P && (G = (P ? F.substring(0, P) : "") + g + F.substring(P, P + M) + h + (P + M < D ? F.substring(P + M) : ""), L = M, x = !0)); - } - } - G && (k && (0 > A && (A = q.length + (q ? 1 : 0)), B = q.length + (q ? 1 : 0) + G.length, E += D, ya.push(v.length), v.push({match:G})), q += (q ? " " : "") + G); - } - if (!x) { - F = y[C], q += (q ? " " : "") + F, k && v.push({text:F}); - } else if (k && E >= k) { - break; - } - } - E = ya.length * (f.length - 2); - if (p || t || k && q.length - E > k) { - if (E = k + E - 2 * u, C = B - A, 0 < p && (C += p), 0 < t && (C += t), C <= E) { - y = p ? A - (0 < p ? p : 0) : A - ((E - C) / 2 | 0), v = t ? B + (0 < t ? t : 0) : y + E, m || (0 < y && " " !== q.charAt(y) && " " !== q.charAt(y - 1) && (y = q.indexOf(" ", y), 0 > y && (y = 0)), v < q.length && " " !== q.charAt(v - 1) && " " !== q.charAt(v) && (v = q.lastIndexOf(" ", v), v < B ? v = B : ++v)), q = (y ? d : "") + q.substring(y, v) + (v < q.length ? d : ""); - } else { - B = []; - A = {}; - E = {}; - C = {}; - F = {}; - z = {}; - G = K = D = 0; - for (O = L = 1;;) { - var U = void 0; - for (let x = 0, J; x < ya.length; x++) { - J = ya[x]; - if (G) { - if (K !== G) { - if (C[x + 1]) { - continue; - } - J += G; - if (A[J]) { - D -= u; - E[x + 1] = 1; - C[x + 1] = 1; - continue; - } - if (J >= v.length - 1) { - if (J >= v.length) { - C[x + 1] = 1; - J >= y.length && (E[x + 1] = 1); - continue; - } - D -= u; - } - q = v[J].text; - if (M = t && z[x]) { - if (0 < M) { - if (q.length > M) { - if (C[x + 1] = 1, m) { - q = q.substring(0, M); - } else { - continue; - } - } - (M -= q.length) || (M = -1); - z[x] = M; - } else { - C[x + 1] = 1; - continue; - } - } - if (D + q.length + 1 <= k) { - q = " " + q, B[x] += q; - } else if (m) { - U = k - D - 1, 0 < U && (q = " " + q.substring(0, U), B[x] += q), C[x + 1] = 1; - } else { - C[x + 1] = 1; - continue; - } - } else { - if (C[x]) { - continue; - } - J -= K; - if (A[J]) { - D -= u; - C[x] = 1; - E[x] = 1; - continue; - } - if (0 >= J) { - if (0 > J) { - C[x] = 1; - E[x] = 1; - continue; - } - D -= u; - } - q = v[J].text; - if (M = p && F[x]) { - if (0 < M) { - if (q.length > M) { - if (C[x] = 1, m) { - q = q.substring(q.length - M); - } else { - continue; - } - } - (M -= q.length) || (M = -1); - F[x] = M; - } else { - C[x] = 1; - continue; - } - } - if (D + q.length + 1 <= k) { - q += " ", B[x] = q + B[x]; - } else if (m) { - U = q.length + 1 - (k - D), 0 <= U && U < q.length && (q = q.substring(U) + " ", B[x] = q + B[x]), C[x] = 1; - } else { - C[x] = 1; - continue; - } - } - } else { - q = v[J].match; - p && (F[x] = p); - t && (z[x] = t); - x && D++; - let Qa; - J ? !x && u && (D += u) : (E[x] = 1, C[x] = 1); - J >= y.length - 1 ? Qa = 1 : J < v.length - 1 && v[J + 1].match ? Qa = 1 : u && (D += u); - D -= f.length - 2; - if (!x || D + q.length <= k) { - B[x] = q; - } else { - U = L = O = E[x] = 0; - break; - } - Qa && (E[x + 1] = 1, C[x + 1] = 1); - } - D += q.length; - U = A[J] = 1; - } - if (U) { - K === G ? G++ : K++; - } else { - K === G ? L = 0 : O = 0; - if (!L && !O) { - break; - } - L ? (K++, G = K) : G++; - } - } - q = ""; - for (let x = 0, J; x < B.length; x++) { - J = (x && E[x] ? " " : (x && !d ? " " : "") + d) + B[x], q += J; - } - d && !E[B.length] && (q += d); - } - } - l && (q = q.replace(l, " ")); - pa[xa].highlight = q; - } - if (e) { - break; - } - } - return c; -} -;Na.prototype.search = function(a, c, b, e) { - b || (!c && ba(a) ? (b = a, a = "") : ba(c) && (b = c, c = 0)); +Na.prototype.search = function(a, b, c, e) { + c || (!b && ba(a) ? (c = a, a = "") : ba(b) && (c = b, b = 0)); let d = []; var f = []; let g; - let h, k, m, l, n; - let u = 0, p = !0, t; - if (b) { - b.constructor === Array && (b = {index:b}); - a = b.query || a; - g = b.pluck; - h = b.merge; - m = b.boost; - n = g || b.field || (n = b.index) && (n.index ? null : n); - var r = this.tag && b.tag; - k = b.suggest; - p = !1 !== b.resolve; - l = b.cache; - this.store && b.highlight && !p ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - t = p && this.store && b.highlight; - var q = !!t || p && this.store && b.enrich; - c = b.limit || c; - var y = b.offset || 0; - c || (c = p ? 100 : 0); - if (r && (!this.db || !e)) { - r.constructor !== Array && (r = [r]); + let k, h, l, m, r; + let t = 0, q = !0, u; + if (c) { + c.constructor === Array && (c = {index:c}); + a = c.query || a; + g = c.pluck; + k = c.merge; + l = c.boost; + r = g || c.field || (r = c.index) && (r.index ? null : r); + var n = this.tag && c.tag; + h = c.suggest; + q = !1 !== c.resolve; + m = c.cache; + this.store && c.highlight && !q ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && c.enrich && !q && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + u = q && this.store && c.highlight; + var p = !!u || q && this.store && c.enrich; + b = c.limit || b; + var y = c.offset || 0; + b || (b = q ? 100 : 0); + if (n && (!this.db || !e)) { + n.constructor !== Array && (n = [n]); var v = []; - for (let F = 0, z; F < r.length; F++) { - z = r[F]; + for (let E = 0, z; E < n.length; E++) { + z = n[E]; if (N(z)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (z.field && z.tag) { - var A = z.tag; - if (A.constructor === Array) { - for (var B = 0; B < A.length; B++) { - v.push(z.field, A[B]); + var D = z.tag; + if (D.constructor === Array) { + for (var B = 0; B < D.length; B++) { + v.push(z.field, D[B]); } } else { - v.push(z.field, A); + v.push(z.field, D); } } else { - A = Object.keys(z); - for (let D = 0, K, G; D < A.length; D++) { - if (K = A[D], G = z[K], G.constructor === Array) { - for (B = 0; B < G.length; B++) { - v.push(K, G[B]); + D = Object.keys(z); + for (let C = 0, K, F; C < D.length; C++) { + if (K = D[C], F = z[K], F.constructor === Array) { + for (B = 0; B < F.length; B++) { + v.push(K, F[B]); } } else { - v.push(K, G); + v.push(K, F); } } } @@ -1619,193 +1657,193 @@ function db(a, c, b, e, d) { if (!v.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - r = v; + n = v; if (!a) { f = []; if (v.length) { - for (r = 0; r < v.length; r += 2) { + for (n = 0; n < v.length; n += 2) { if (this.db) { - e = this.index.get(v[r]); + e = this.index.get(v[n]); if (!e) { - console.warn("Tag '" + v[r] + ":" + v[r + 1] + "' will be skipped because there is no field '" + v[r] + "'."); + console.warn("Tag '" + v[n] + ":" + v[n + 1] + "' will be skipped because there is no field '" + v[n] + "'."); continue; } - f.push(e = e.db.tag(v[r + 1], c, y, q)); + f.push(e = e.db.tag(v[n + 1], b, y, p)); } else { - e = eb.call(this, v[r], v[r + 1], c, y, q); + e = eb.call(this, v[n], v[n + 1], b, y, p); } - d.push(p ? {field:v[r], tag:v[r + 1], result:e} : [e]); + d.push(q ? {field:v[n], tag:v[n + 1], result:e} : [e]); } } if (f.length) { - const F = this; + const E = this; return Promise.all(f).then(function(z) { - for (let D = 0; D < z.length; D++) { - p ? d[D].result = z[D] : d[D] = z[D]; + for (let C = 0; C < z.length; C++) { + q ? d[C].result = z[C] : d[C] = z[C]; } - return p ? d : new Y(1 < d.length ? $a(d, 1, 0, 0, k, m) : d[0], F); + return q ? d : new Y(1 < d.length ? $a(d, 1, 0, 0, h, l) : d[0], E); }); } - return p ? d : new Y(1 < d.length ? $a(d, 1, 0, 0, k, m) : d[0], this); + return q ? d : new Y(1 < d.length ? $a(d, 1, 0, 0, h, l) : d[0], this); } } - if (!p && !g) { - if (n = n || this.field) { - N(n) ? g = n : (n.constructor === Array && 1 === n.length && (n = n[0]), g = n.field || n.index); + if (!q && !g) { + if (r = r || this.field) { + N(r) ? g = r : (r.constructor === Array && 1 === r.length && (r = r[0]), g = r.field || r.index); } if (!g) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - n && n.constructor !== Array && (n = [n]); + r && r.constructor !== Array && (r = [r]); } - n || (n = this.field); - let E; + r || (r = this.field); + let G; v = (this.worker || this.db) && !e && []; - for (let F = 0, z, D, K; F < n.length; F++) { - D = n[F]; - if (this.db && this.tag && !this.G[F]) { + for (let E = 0, z, C, K; E < r.length; E++) { + C = r[E]; + if (this.db && this.tag && !this.G[E]) { continue; } - let G; - N(D) || (G = D, D = G.field, a = G.query || a, c = aa(G.limit, c), y = aa(G.offset, y), k = aa(G.suggest, k), t = p && this.store && aa(G.highlight, t), q = !!t || p && this.store && aa(G.enrich, q), l = aa(G.cache, l)); + let F; + N(C) || (F = C, C = F.field, a = F.query || a, b = aa(F.limit, b), y = aa(F.offset, y), h = aa(F.suggest, h), u = q && this.store && aa(F.highlight, u), p = !!u || q && this.store && aa(F.enrich, p), m = aa(F.cache, m)); if (e) { - z = e[F]; + z = e[E]; } else { - A = G || b || {}; - B = A.enrich; - var C = this.index.get(D); - r && (this.db && (A.tag = r, E = C.db.support_tag_search, A.field = n), !E && B && (A.enrich = !1)); - z = l ? C.searchCache(a, c, A) : C.search(a, c, A); - B && (A.enrich = B); + D = F || c || {}; + B = D.enrich; + var A = this.index.get(C); + n && (this.db && (D.tag = n, G = A.db.support_tag_search, D.field = r), !G && B && (D.enrich = !1)); + z = m ? A.searchCache(a, b, D) : A.search(a, b, D); + B && (D.enrich = B); if (v) { - v[F] = z; + v[E] = z; continue; } } K = (z = z.result || z) && z.length; - if (r && K) { - A = []; + if (n && K) { + D = []; B = 0; if (this.db && e) { - if (!E) { - for (C = n.length; C < e.length; C++) { - let L = e[C]; + if (!G) { + for (A = r.length; A < e.length; A++) { + let L = e[A]; if (L && L.length) { - B++, A.push(L); - } else if (!k) { - return p ? d : new Y(d, this); + B++, D.push(L); + } else if (!h) { + return q ? d : new Y(d, this); } } } } else { - for (let L = 0, O, P; L < r.length; L += 2) { - O = this.tag.get(r[L]); + for (let L = 0, O, P; L < n.length; L += 2) { + O = this.tag.get(n[L]); if (!O) { - if (console.warn("Tag '" + r[L] + ":" + r[L + 1] + "' will be skipped because there is no field '" + r[L] + "'."), k) { + if (console.warn("Tag '" + n[L] + ":" + n[L + 1] + "' will be skipped because there is no field '" + n[L] + "'."), h) { continue; } else { - return p ? d : new Y(d, this); + return q ? d : new Y(d, this); } } - if (P = (O = O && O.get(r[L + 1])) && O.length) { - B++, A.push(O); - } else if (!k) { - return p ? d : new Y(d, this); + if (P = (O = O && O.get(n[L + 1])) && O.length) { + B++, D.push(O); + } else if (!h) { + return q ? d : new Y(d, this); } } } if (B) { - z = cb(z, A, p); + z = db(z, D, q); K = z.length; - if (!K && !k) { - return p ? z : new Y(z, this); + if (!K && !h) { + return q ? z : new Y(z, this); } B--; } } if (K) { - f[u] = D, d.push(z), u++; - } else if (1 === n.length) { - return p ? d : new Y(d, this); + f[t] = C, d.push(z), t++; + } else if (1 === r.length) { + return q ? d : new Y(d, this); } } if (v) { - if (this.db && r && r.length && !E) { - for (q = 0; q < r.length; q += 2) { - f = this.index.get(r[q]); + if (this.db && n && n.length && !G) { + for (p = 0; p < n.length; p += 2) { + f = this.index.get(n[p]); if (!f) { - if (console.warn("Tag '" + r[q] + ":" + r[q + 1] + "' was not found because there is no field '" + r[q] + "'."), k) { + if (console.warn("Tag '" + n[p] + ":" + n[p + 1] + "' was not found because there is no field '" + n[p] + "'."), h) { continue; } else { - return p ? d : new Y(d, this); + return q ? d : new Y(d, this); } } - v.push(f.db.tag(r[q + 1], c, y, !1)); + v.push(f.db.tag(n[p + 1], b, y, !1)); } } - const F = this; + const E = this; return Promise.all(v).then(function(z) { - b && (b.resolve = p); - z.length && (z = F.search(a, c, b, z)); + c && (c.resolve = q); + z.length && (z = E.search(a, b, c, z)); return z; }); } - if (!u) { - return p ? d : new Y(d, this); + if (!t) { + return q ? d : new Y(d, this); } - if (g && (!q || !this.store)) { - return d = d[0], p ? d : new Y(d, this); + if (g && (!p || !this.store)) { + return d = d[0], q ? d : new Y(d, this); } v = []; for (y = 0; y < f.length; y++) { - r = d[y]; - q && r.length && "undefined" === typeof r[0].doc && (this.db ? v.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = Ta.call(this, r)); + n = d[y]; + p && n.length && "undefined" === typeof n[0].doc && (this.db ? v.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = Ta.call(this, n)); if (g) { - return p ? t ? db(a, r, this.index, g, t) : r : new Y(r, this); + return q ? u ? cb(a, n, this.index, g, u) : n : new Y(n, this); } - d[y] = {field:f[y], result:r}; + d[y] = {field:f[y], result:n}; } - if (q && this.db && v.length) { - const F = this; + if (p && this.db && v.length) { + const E = this; return Promise.all(v).then(function(z) { - for (let D = 0; D < z.length; D++) { - d[D].result = z[D]; + for (let C = 0; C < z.length; C++) { + d[C].result = z[C]; } - t && (d = db(a, d, F.index, g, t)); - return h ? fb(d) : d; + u && (d = cb(a, d, E.index, g, u)); + return k ? fb(d) : d; }); } - t && (d = db(a, d, this.index, g, t)); - return h ? fb(d) : d; + u && (d = cb(a, d, this.index, g, u)); + return k ? fb(d) : d; }; function fb(a) { - const c = [], b = I(), e = I(); - for (let d = 0, f, g, h, k, m, l, n; d < a.length; d++) { + const b = [], c = I(), e = I(); + for (let d = 0, f, g, k, h, l, m, r; d < a.length; d++) { f = a[d]; g = f.field; - h = f.result; - for (let u = 0; u < h.length; u++) { - if (m = h[u], "object" !== typeof m ? m = {id:k = m} : k = m.id, (l = b[k]) ? l.push(g) : (m.field = b[k] = [g], c.push(m)), n = m.highlight) { - l = e[k], l || (e[k] = l = {}, m.highlight = l), l[g] = n; + k = f.result; + for (let t = 0; t < k.length; t++) { + if (l = k[t], "object" !== typeof l ? l = {id:h = l} : h = l.id, (m = c[h]) ? m.push(g) : (l.field = c[h] = [g], b.push(l)), r = l.highlight) { + m = e[h], m || (e[h] = m = {}, l.highlight = m), m[g] = r; } } } - return c; + return b; } -function eb(a, c, b, e, d) { +function eb(a, b, c, e, d) { a = this.tag.get(a); if (!a) { return []; } - a = a.get(c); + a = a.get(b); if (!a) { return []; } - c = a.length - e; - if (0 < c) { - if (b && c > b || e) { - a = a.slice(e, e + b); + b = a.length - e; + if (0 < b) { + if (c && b > c || e) { + a = a.slice(e, e + c); } d && (a = Ta.call(this, a)); } @@ -1818,40 +1856,40 @@ function Ta(a) { if (this.db) { return this.index.get(this.field[0]).db.enrich(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)}; + const b = Array(a.length); + for (let c = 0, e; c < a.length; c++) { + e = a[c], b[c] = {id:e, doc:this.store.get(e)}; } - return c; + return b; } ;function Na(a) { if (!this || this.constructor !== Na) { return new Na(a); } - const c = a.document || a.doc || a; - let b, e; + const b = a.document || a.doc || a; + let c, e; this.G = []; this.field = []; this.K = []; - this.key = (b = c.key || c.id) && hb(b, this.K) || "id"; + this.key = (c = b.key || b.id) && hb(c, this.K) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; this.reg = !this.fastupdate || a.worker || a.db ? e ? new S(e) : new Set() : e ? new R(e) : new Map(); - this.D = (b = c.store || null) && b && !0 !== b && []; - this.store = b && (e ? new R(e) : new Map()); - this.cache = (b = a.cache || null) && new na(b); + this.D = (c = b.store || null) && c && !0 !== c && []; + this.store = c && (e ? new R(e) : new Map()); + this.cache = (c = a.cache || null) && new na(c); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = ib.call(this, a, c); + this.index = ib.call(this, a, b); this.tag = null; - if (b = c.tag) { - if ("string" === typeof b && (b = [b]), b.length) { + if (c = b.tag) { + if ("string" === typeof c && (c = [c]), c.length) { this.tag = new Map(); this.F = []; this.P = []; - for (let d = 0, f, g; d < b.length; d++) { - f = b[d]; + for (let d = 0, f, g; d < c.length; d++) { + f = c[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); @@ -1872,10 +1910,10 @@ function Ta(a) { const d = this; return Promise.all(a).then(function(f) { let g = 0; - for (const h of d.index.entries()) { - const k = h[0]; - let m = h[1]; - m.then && (m = f[g], d.index.set(k, m), g++); + for (const k of d.index.entries()) { + const h = k[0]; + let l = k[1]; + l.then && (l = f[g], d.index.set(h, l), g++); } return d; }); @@ -1889,102 +1927,102 @@ w.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } - let c = this.field; + let b = this.field; if (this.tag) { for (let f = 0, g; f < this.P.length; f++) { g = this.P[f]; - var b = void 0; - this.index.set(g, b = new V({}, this.reg)); - c === this.field && (c = c.slice(0)); - c.push(g); - b.tag = this.tag.get(g); + var c = void 0; + this.index.set(g, c = new V({}, this.reg)); + b === this.field && (b = b.slice(0)); + b.push(g); + c.tag = this.tag.get(g); } } - b = []; + c = []; const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let f = 0, g, h; f < c.length; f++) { - e.field = h = c[f]; - g = this.index.get(h); - const k = new a.constructor(a.id, e); - k.id = a.id; - b[f] = k.mount(g); + for (let f = 0, g, k; f < b.length; f++) { + e.field = k = b[f]; + g = this.index.get(k); + const h = new a.constructor(a.id, e); + h.id = a.id; + c[f] = h.mount(g); g.document = !0; f ? g.bypass = !0 : g.store = this.store; } const d = this; - return this.db = Promise.all(b).then(function() { + return this.db = Promise.all(c).then(function() { d.db = !0; }); }; -w.commit = async function(a, c) { - const b = []; +w.commit = async function(a, b) { + const c = []; for (const e of this.index.values()) { - b.push(e.commit(a, c)); + c.push(e.commit(a, b)); } - await Promise.all(b); + await Promise.all(c); this.reg.clear(); }; w.destroy = function() { const a = []; - for (const c of this.index.values()) { - a.push(c.destroy()); + for (const b of this.index.values()) { + a.push(b.destroy()); } return Promise.all(a); }; -function ib(a, c) { - const b = new Map(); - let e = c.index || c.field || c; +function ib(a, b) { + const c = new Map(); + let e = b.index || b.field || b; N(e) && (e = [e]); - for (let f = 0, g, h; f < e.length; f++) { + for (let f = 0, g, k; f < e.length; f++) { g = e[f]; - N(g) || (h = g, g = g.field); - h = ba(h) ? Object.assign({}, a, h) : a; + N(g) || (k = g, g = g.field); + k = ba(k) ? Object.assign({}, a, k) : a; if (this.worker) { var d = void 0; - d = (d = h.encoder) && d.encode ? d : new la("string" === typeof d ? wa[d] : d || {}); - d = new La(h, d); - b.set(g, d); + d = (d = k.encoder) && d.encode ? d : new la("string" === typeof d ? wa[d] : d || {}); + d = new La(k, d); + c.set(g, d); } - this.worker || b.set(g, new V(h, this.reg)); - h.custom ? this.G[f] = h.custom : (this.G[f] = hb(g, this.K), h.filter && ("string" === typeof this.G[f] && (this.G[f] = new String(this.G[f])), this.G[f].J = h.filter)); + this.worker || c.set(g, new V(k, this.reg)); + k.custom ? this.G[f] = k.custom : (this.G[f] = hb(g, this.K), k.filter && ("string" === typeof this.G[f] && (this.G[f] = new String(this.G[f])), this.G[f].J = k.filter)); this.field[f] = g; } if (this.D) { - a = c.store; + a = b.store; N(a) && (a = [a]); - for (let f = 0, g, h; f < a.length; f++) { - g = a[f], h = g.field || g, g.custom ? (this.D[f] = g.custom, g.custom.U = h) : (this.D[f] = hb(h, this.K), g.filter && ("string" === typeof this.D[f] && (this.D[f] = new String(this.D[f])), this.D[f].J = g.filter)); + for (let f = 0, g, k; f < a.length; f++) { + g = a[f], k = g.field || g, g.custom ? (this.D[f] = g.custom, g.custom.U = k) : (this.D[f] = hb(k, this.K), g.filter && ("string" === typeof this.D[f] && (this.D[f] = new String(this.D[f])), this.D[f].J = g.filter)); } } - return b; + return c; } -function hb(a, c) { - const b = a.split(":"); +function hb(a, b) { + const c = a.split(":"); let e = 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); + for (let d = 0; d < c.length; d++) { + a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); } - e < b.length && (b.length = e); - return 1 < e ? b : b[0]; + e < c.length && (c.length = e); + return 1 < e ? c : c[0]; } -w.append = function(a, c) { - return this.add(a, c, !0); +w.append = function(a, b) { + return this.add(a, b, !0); }; -w.update = function(a, c) { - return this.remove(a).add(a, c); +w.update = function(a, b) { + return this.remove(a).add(a, b); }; w.remove = function(a) { ba(a) && (a = da(a, this.key)); - for (var c of this.index.values()) { - c.remove(a, !0); + for (var b of this.index.values()) { + b.remove(a, !0); } 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]; + for (let c of this.tag.values()) { + for (let e of c) { + b = e[0]; const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); + -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); } } } @@ -1996,13 +2034,13 @@ w.remove = function(a) { }; w.clear = function() { const a = []; - for (const c of this.index.values()) { - const b = c.clear(); - b.then && a.push(b); + for (const b of this.index.values()) { + const c = b.clear(); + c.then && a.push(c); } if (this.tag) { - for (const c of this.tag.values()) { - c.clear(); + for (const b of this.tag.values()) { + b.clear(); } } this.store && this.store.clear(); @@ -2019,175 +2057,175 @@ w.cleanup = function() { return this; }; w.get = function(a) { - return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) { - return c[0] && c[0].doc || null; + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { + return b[0] && b[0].doc || null; }) : this.store.get(a) || null; }; -w.set = function(a, c) { - "object" === typeof a && (c = a, a = da(c, this.key)); - this.store.set(a, c); +w.set = function(a, b) { + "object" === typeof a && (b = a, a = da(b, this.key)); + this.store.set(a, b); return this; }; w.searchCache = ma; w.export = jb; w.import = kb; Fa(Na.prototype); -function lb(a, c = 0) { - let b = [], e = []; - c && (c = 250000 / c * 5000 | 0); +function lb(a, b = 0) { + let c = [], e = []; + b && (b = 250000 / b * 5000 | 0); for (const d of a.entries()) { - e.push(d), e.length === c && (b.push(e), e = []); - } - e.length && b.push(e); - return b; -} -function mb(a, c) { - c || (c = new Map()); - for (let b = 0, e; b < a.length; b++) { - e = a[b], c.set(e[0], e[1]); + e.push(d), e.length === b && (c.push(e), e = []); } + e.length && c.push(e); return c; } -function nb(a, c = 0) { - let b = [], e = []; - c && (c = 250000 / c * 1000 | 0); - for (const d of a.entries()) { - e.push([d[0], lb(d[1])[0]]), e.length === c && (b.push(e), e = []); +function mb(a, b) { + b || (b = new Map()); + for (let c = 0, e; c < a.length; c++) { + e = a[c], b.set(e[0], e[1]); } - e.length && b.push(e); return b; } -function ob(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], mb(e[1], d)); +function nb(a, b = 0) { + let c = [], e = []; + b && (b = 250000 / b * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], lb(d[1])[0]]), e.length === b && (c.push(e), e = []); } + e.length && c.push(e); return c; } +function ob(a, b) { + b || (b = new Map()); + for (let c = 0, e, d; c < a.length; c++) { + e = a[c], d = b.get(e[0]), b.set(e[0], mb(e[1], d)); + } + return b; +} function pb(a) { - let c = [], b = []; + let b = [], c = []; for (const e of a.keys()) { - b.push(e), 250000 === b.length && (c.push(b), b = []); + c.push(e), 250000 === c.length && (b.push(c), c = []); } - b.length && c.push(b); - return c; + c.length && b.push(c); + return b; } -function qb(a, c) { - c || (c = new Set()); - for (let b = 0; b < a.length; b++) { - c.add(a[b]); +function qb(a, b) { + b || (b = new Set()); + for (let c = 0; c < a.length; c++) { + b.add(a[c]); } - return c; + return b; } -function rb(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { - return this.export(a, c, d, f + 1); +function rb(a, b, c, e, d, f, g = 0) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { + return this.export(a, b, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { - const m = this; - return k.then(function() { - return rb.call(m, a, c, b, h ? e : null, d, f, g + 1); + if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { + const l = this; + return h.then(function() { + return rb.call(l, a, b, c, k ? e : null, d, f, g + 1); }); } - return rb.call(this, a, c, b, h ? e : null, d, f, g + 1); + return rb.call(this, a, b, c, k ? e : null, d, f, g + 1); } -function jb(a, c, b = 0, e = 0) { - if (b < this.field.length) { - const g = this.field[b]; - if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const h = this; - return c.then(function() { - return h.export(a, g, b + 1); +function jb(a, b, c = 0, e = 0) { + if (c < this.field.length) { + const g = this.field[c]; + if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { + const k = this; + return b.then(function() { + return k.export(a, g, c + 1); }); } - return this.export(a, g, b + 1); + return this.export(a, g, c + 1); } let d, f; switch(e) { case 0: d = "reg"; f = pb(this.reg); - c = null; + b = null; break; case 1: d = "tag"; f = this.tag && nb(this.tag, this.reg.size); - c = null; + b = null; break; case 2: d = "doc"; f = this.store && lb(this.store); - c = null; + b = null; break; default: return; } - return rb.call(this, a, c, d, f, b, e); + return rb.call(this, a, b, d, f, c, e); } -function kb(a, c) { - var b = a.split("."); - "json" === b[b.length - 1] && b.pop(); - const e = 2 < b.length ? b[0] : ""; - b = 2 < b.length ? b[2] : b[1]; +function kb(a, b) { + var c = a.split("."); + "json" === c[c.length - 1] && c.pop(); + const e = 2 < c.length ? c[0] : ""; + c = 2 < c.length ? c[2] : c[1]; if (this.worker && e) { return this.index.get(e).import(a); } - if (c) { - "string" === typeof c && (c = JSON.parse(c)); + if (b) { + "string" === typeof b && (b = JSON.parse(b)); if (e) { - return this.index.get(e).import(b, c); + return this.index.get(e).import(c, b); } - switch(b) { + switch(c) { case "reg": this.fastupdate = !1; - this.reg = qb(c, this.reg); + this.reg = qb(b, this.reg); for (let d = 0, f; d < this.field.length; d++) { f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } if (this.worker) { - c = []; + b = []; for (const d of this.index.values()) { - c.push(d.import(a)); + b.push(d.import(a)); } - return Promise.all(c); + return Promise.all(b); } break; case "tag": - this.tag = ob(c, this.tag); + this.tag = ob(b, this.tag); break; case "doc": - this.store = mb(c, this.store); + this.store = mb(b, this.store); } } } -function sb(a, c) { - let b = ""; +function sb(a, b) { + let c = ""; for (const e of a.entries()) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, h; g < d.length; g++) { - h = d[g] || [""]; - let k = ""; - for (let m = 0; m < h.length; m++) { - k += (k ? "," : "") + ("string" === c ? '"' + h[m] + '"' : h[m]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === b ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; - b += (b ? "," : "") + f; + c += (c ? "," : "") + f; } - return b; + return c; } -;V.prototype.remove = function(a, c) { - const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (b) { +;V.prototype.remove = function(a, b) { + const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (c) { if (this.fastupdate) { - for (let e = 0, d, f; e < b.length; e++) { - if ((d = b[e]) && (f = d.length)) { + for (let e = 0, d, f; e < c.length; e++) { + if ((d = c[e]) && (f = d.length)) { if (d[f - 1] === a) { d.pop(); } else { @@ -2199,71 +2237,71 @@ function sb(a, c) { } else { tb(this.map, a), this.depth && tb(this.ctx, a); } - c || this.reg.delete(a); + b || this.reg.delete(a); } this.db && (this.commit_task.push({del:a}), this.S && ub(this)); this.cache && this.cache.remove(a); return this; }; -function tb(a, c) { - let b = 0; - var e = "undefined" === typeof c; +function tb(a, b) { + let c = 0; + var e = "undefined" === typeof b; if (a.constructor === Array) { - for (let d = 0, f, g, h; d < a.length; d++) { + for (let d = 0, f, g, k; d < a.length; d++) { if ((f = a[d]) && f.length) { if (e) { return 1; } - g = f.indexOf(c); + g = f.indexOf(b); if (0 <= g) { if (1 < f.length) { return f.splice(g, 1), 1; } delete a[d]; - if (b) { + if (c) { return 1; } - h = 1; + k = 1; } else { - if (h) { + if (k) { return 1; } - b++; + c++; } } } } else { for (let d of a.entries()) { - e = d[0], tb(d[1], c) ? b++ : a.delete(e); + e = d[0], tb(d[1], b) ? c++ : a.delete(e); } } - return b; + return c; } ;const vb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -V.prototype.add = function(a, c, b, e) { - if (c && (a || 0 === a)) { - if (!e && !b && this.reg.has(a)) { - return this.update(a, c); +V.prototype.add = function(a, b, c, e) { + if (b && (a || 0 === a)) { + if (!e && !c && this.reg.has(a)) { + return this.update(a, b); } e = this.depth; - c = this.encoder.encode(c, !e); - const m = c.length; - if (m) { - const l = I(), n = I(), u = this.resolution; - for (let p = 0; p < m; p++) { - let t = c[this.rtl ? m - 1 - p : p]; - var d = t.length; - if (d && (e || !n[t])) { - var f = this.score ? this.score(c, t, p, null, 0) : wb(u, m, p), g = ""; + b = this.encoder.encode(b, !e); + const l = b.length; + if (l) { + const m = I(), r = I(), t = this.resolution; + for (let q = 0; q < l; q++) { + let u = b[this.rtl ? l - 1 - q : q]; + var d = u.length; + if (d && (e || !r[u])) { + var f = this.score ? this.score(b, u, q, null, 0) : wb(t, l, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let r = 0, q; r < d; r++) { - for (f = d; f > r; f--) { - g = t.substring(r, f); - q = this.rtl ? d - 1 - r : r; - var h = this.score ? this.score(c, t, p, g, q) : wb(u, m, p, d, q); - xb(this, n, g, h, a, b); + for (let n = 0, p; n < d; n++) { + for (f = d; f > n; f--) { + g = u.substring(n, f); + p = this.rtl ? d - 1 - n : n; + var k = this.score ? this.score(b, u, q, g, p) : wb(t, l, q, d, p); + xb(this, r, g, k, a, c); } } break; @@ -2271,27 +2309,27 @@ V.prototype.add = function(a, c, b, e) { case "bidirectional": case "reverse": if (1 < d) { - for (h = d - 1; 0 < h; h--) { - g = t[this.rtl ? d - 1 - h : h] + g; - var k = this.score ? this.score(c, t, p, g, h) : wb(u, m, p, d, h); - xb(this, n, g, k, a, b); + for (k = d - 1; 0 < k; k--) { + g = u[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(b, u, q, g, k) : wb(t, l, q, d, k); + xb(this, r, g, h, a, c); } g = ""; } case "forward": if (1 < d) { - for (h = 0; h < d; h++) { - g += t[this.rtl ? d - 1 - h : h], xb(this, n, g, f, a, b); + for (k = 0; k < d; k++) { + g += u[this.rtl ? d - 1 - k : k], xb(this, r, g, f, a, c); } break; } default: - if (xb(this, n, t, f, a, b), e && 1 < m && p < m - 1) { - for (d = I(), g = this.T, f = t, h = Math.min(e + 1, this.rtl ? p + 1 : m - p), d[f] = 1, k = 1; k < h; k++) { - if ((t = c[this.rtl ? m - 1 - p - k : p + k]) && !d[t]) { - d[t] = 1; - const r = this.score ? this.score(c, f, p, t, k - 1) : wb(g + (m / 2 > g ? 0 : 1), m, p, h - 1, k - 1), q = this.bidirectional && t > f; - xb(this, l, q ? f : t, r, a, b, q ? t : f); + if (xb(this, r, u, f, a, c), e && 1 < l && q < l - 1) { + for (d = I(), g = this.T, f = u, k = Math.min(e + 1, this.rtl ? q + 1 : l - q), d[f] = 1, h = 1; h < k; h++) { + if ((u = b[this.rtl ? l - 1 - q - h : q + h]) && !d[u]) { + d[u] = 1; + const n = this.score ? this.score(b, f, q, u, h - 1) : wb(g + (l / 2 > g ? 0 : 1), l, q, k - 1, h - 1), p = this.bidirectional && u > f; + xb(this, m, p ? f : u, n, a, c, p ? u : f); } } } @@ -2300,109 +2338,109 @@ V.prototype.add = function(a, c, b, e) { } this.fastupdate || this.reg.add(a); } else { - c = ""; + b = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.S && ub(this)); + this.db && (b || this.commit_task.push({del:a}), this.S && ub(this)); return this; }; -function xb(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - if (g ? (c = k || (c[b] = I()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = k = []), h = h[e] || (h[e] = []), !f || !h.includes(d)) { - if (h.length === 2 ** 31 - 1) { - c = new Aa(h); +function xb(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] = I()), 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 Aa(k); if (a.fastupdate) { - for (let m of a.reg.values()) { - m.includes(h) && (m[m.indexOf(h)] = c); + for (let l of a.reg.values()) { + l.includes(k) && (l[l.indexOf(k)] = b); } } - k[e] = h = c; + h[e] = k = b; } - h.push(d); - a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h])); + k.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } } -function wb(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 wb(a, b, c, e, d) { + return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; } -;V.prototype.search = function(a, c, b) { - b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); - if (b && b.cache) { - return b.cache = !1, a = this.searchCache(a, c, b), b.cache = !0, a; +;V.prototype.search = function(a, b, c) { + c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); + if (c && c.cache) { + return c.cache = !1, a = this.searchCache(a, b, c), c.cache = !0, a; } - let e = [], d, f, g, h = 0, k, m, l, n, u; - b && (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, u = (k = b.resolve) && b.enrich, l = b.boost, n = b.resolution, m = this.db && b.tag); - "undefined" === typeof k && (k = this.resolve); + let e = [], d, f, g, k = 0, h, l, m, r, t; + c && (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, t = (h = c.resolve) && c.enrich, m = c.boost, r = c.resolution, l = this.db && c.tag); + "undefined" === typeof h && (h = this.resolve); f = this.depth && !1 !== f; - let p = this.encoder.encode(a, !f); - d = p.length; - c = c || (k ? 100 : 0); + let q = this.encoder.encode(a, !f); + d = q.length; + b = b || (h ? 100 : 0); if (1 === d) { - return yb.call(this, p[0], "", c, h, k, u, m); + return yb.call(this, q[0], "", b, k, h, t, l); } if (2 === d && f && !g) { - return yb.call(this, p[1], p[0], c, h, k, u, m); + return yb.call(this, q[1], q[0], b, k, h, t, l); } - let t = I(), r = 0, q; - f && (q = p[0], r = 1); - n || 0 === n || (n = q ? this.T : this.resolution); + let u = I(), n = 0, p; + f && (p = q[0], n = 1); + r || 0 === r || (r = p ? this.T : this.resolution); if (this.db) { - if (this.db.search && (b = this.db.search(this, p, c, h, g, k, u, m), !1 !== b)) { - return b; + if (this.db.search && (c = this.db.search(this, q, b, k, g, h, t, l), !1 !== c)) { + return c; } const y = this; return async function() { - for (let v, A; r < d; r++) { - if ((A = p[r]) && !t[A]) { - t[A] = 1; - v = await zb(y, A, q, 0, 0, !1, !1); - if (v = Ab(v, e, g, n)) { + for (let v, D; n < d; n++) { + if ((D = q[n]) && !u[D]) { + u[D] = 1; + v = await zb(y, D, p, 0, 0, !1, !1); + if (v = Ab(v, e, g, r)) { e = v; break; } - q && (g && v && e.length || (q = A)); + p && (g && v && e.length || (p = D)); } - g && q && r === d - 1 && !e.length && (n = y.resolution, q = "", r = -1, t = I()); + g && p && n === d - 1 && !e.length && (r = y.resolution, p = "", n = -1, u = I()); } - return Bb(e, n, c, h, g, l, k); + return Bb(e, r, b, k, g, m, h); }(); } - for (let y, v; r < d; r++) { - if ((v = p[r]) && !t[v]) { - t[v] = 1; - y = zb(this, v, q, 0, 0, !1, !1); - if (y = Ab(y, e, g, n)) { + for (let y, v; n < d; n++) { + if ((v = q[n]) && !u[v]) { + u[v] = 1; + y = zb(this, v, p, 0, 0, !1, !1); + if (y = Ab(y, e, g, r)) { e = y; break; } - q && (g && y && e.length || (q = v)); + p && (g && y && e.length || (p = v)); } - g && q && r === d - 1 && !e.length && (n = this.resolution, q = "", r = -1, t = I()); + g && p && n === d - 1 && !e.length && (r = this.resolution, p = "", n = -1, u = I()); } - return Bb(e, n, c, h, g, l, k); + return Bb(e, r, b, k, g, m, h); }; -function Bb(a, c, b, e, d, f, g) { - let h = a.length, k = a; - if (1 < h) { - k = $a(a, c, b, e, d, f, g); - } else if (1 === h) { - return g ? Sa.call(null, a[0], b, e) : new Y(a[0], this); +function Bb(a, b, c, e, d, f, g) { + let k = a.length, h = a; + if (1 < k) { + h = $a(a, b, c, e, d, f, g); + } else if (1 === k) { + return g ? Sa.call(null, a[0], c, e) : new Y(a[0], this); } - return g ? k : new Y(k, this); + return g ? h : new Y(h, this); } -function yb(a, c, b, e, d, f, g) { - a = zb(this, a, c, b, e, d, f, g); - return this.db ? a.then(function(h) { - return d ? h || [] : new Y(h, this); - }) : a && a.length ? d ? Sa.call(this, a, b, e) : new Y(a, this) : d ? [] : new Y([], this); +function yb(a, b, c, e, d, f, g) { + a = zb(this, a, b, c, e, d, f, g); + return this.db ? a.then(function(k) { + return d ? k || [] : new Y(k, this); + }) : a && a.length ? d ? Sa.call(this, a, c, e) : new Y(a, this) : d ? [] : new Y([], this); } -function Ab(a, c, b, e) { +function Ab(a, b, c, e) { let d = []; if (a && a.length) { if (a.length <= e) { - c.push(a); + b.push(a); return; } for (let f = 0, g; f < e; f++) { @@ -2411,53 +2449,53 @@ function Ab(a, c, b, e) { } } if (d.length) { - c.push(d); + b.push(d); return; } } - if (!b) { + if (!c) { return d; } } -function zb(a, c, b, e, d, f, g, h) { - let k; - b && (k = a.bidirectional && c > b) && (k = b, b = c, c = k); +function zb(a, b, c, e, d, f, g, k) { + let h; + c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); if (a.db) { - return a.db.get(c, b, e, d, f, g, h); + return a.db.get(b, c, e, d, f, g, k); } - a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); + a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;function V(a, c) { +;function V(a, b) { if (!this || this.constructor !== V) { return new V(a); } if (a) { - var b = N(a) ? a : a.preset; - b && (vb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, vb[b], a)); + var c = N(a) ? a : a.preset; + c && (vb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, vb[c], a)); } else { a = {}; } - b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = N(a.encoder) ? wa[a.encoder] : a.encode || a.encoder || {}; + c = a.context; + const e = !0 === c ? {depth:1} : c || {}, d = N(a.encoder) ? wa[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new la(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.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; e && e.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); - (b = a.keystore || 0) && (this.keystore = b); - this.map = b ? new R(b) : new Map(); - this.ctx = b ? new R(b) : new Map(); - this.reg = c || (this.fastupdate ? b ? new R(b) : new Map() : b ? new S(b) : new Set()); + (c = a.keystore || 0) && (this.keystore = c); + this.map = c ? new R(c) : new Map(); + this.ctx = c ? new R(c) : new Map(); + this.reg = b || (this.fastupdate ? c ? new R(c) : new Map() : c ? new S(c) : new Set()); this.T = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new na(b); + this.cache = (c = a.cache || null) && new na(c); this.resolve = !1 !== a.resolve; - if (b = a.db) { - this.db = this.mount(b); + if (c = a.db) { + this.db = this.mount(c); } this.S = !1 !== a.commit; this.commit_task = []; @@ -2469,9 +2507,9 @@ w.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -w.commit = function(a, c) { +w.commit = function(a, b) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, c); + return this.db.commit(this, a, b); }; w.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); @@ -2488,18 +2526,17 @@ w.clear = function() { 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; + return this.db ? (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [], this.db.clear()) : this; }; -w.append = function(a, c) { - return this.add(a, c, !0); +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, c) { - const b = this, e = this.remove(a); - return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); +w.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); }; w.cleanup = function() { if (!this.fastupdate) { @@ -2510,7 +2547,7 @@ w.cleanup = function() { return this; }; w.searchCache = ma; -w.export = function(a, c, b = 0, e = 0) { +w.export = function(a, b, c = 0, e = 0) { let d, f; switch(e) { case 0: @@ -2532,55 +2569,55 @@ w.export = function(a, c, b = 0, e = 0) { default: return; } - return rb.call(this, a, c, d, f, b, e); + return rb.call(this, a, b, d, f, c, e); }; -w.import = function(a, c) { - if (c) { - switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { +w.import = function(a, b) { + if (b) { + switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = qb(c, this.reg); + this.reg = qb(b, this.reg); break; case "map": - this.map = mb(c, this.map); + this.map = mb(b, this.map); break; case "ctx": - this.ctx = ob(c, this.ctx); + this.ctx = ob(b, this.ctx); } } }; w.serialize = function(a = !0) { - let c = "", b = "", e = ""; + let b = "", c = "", e = ""; if (this.reg.size) { let f; for (var d of this.reg.keys()) { - f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); + f || (f = typeof d), b += (b ? "," : "") + ("string" === f ? '"' + d + '"' : d); } - c = "index.reg=new Set([" + c + "]);"; - b = sb(this.map, f); - b = "index.map=new Map([" + b + "]);"; + b = "index.reg=new Set([" + b + "]);"; + c = sb(this.map, f); + c = "index.map=new Map([" + c + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let h = sb(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + d + '",' + h + "]"; - e += (e ? "," : "") + h; + let k = sb(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } - return a ? "function inject(index){" + c + b + e + "}" : c + b + e; + return a ? "function inject(index){" + b + c + e + "}" : b + c + e; }; Fa(V.prototype); const Cb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Db = ["map", "ctx", "tag", "reg", "cfg"], Eb = I(); -function Fb(a, c = {}) { +function Fb(a, b = {}) { if (!this || this.constructor !== Fb) { - return new Fb(a, c); + return new Fb(a, b); } - "object" === typeof a && (c = a, a = a.name); + "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); this.id = "flexsearch" + (a ? ":" + a.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""); - this.field = c.field ? c.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.type = c.type; + this.field = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; + this.type = b.type; this.fastupdate = this.support_tag_search = !1; this.db = null; this.h = {}; @@ -2601,18 +2638,18 @@ w.open = function() { navigator.storage && navigator.storage.persist(); Eb[a.id] || (Eb[a.id] = []); Eb[a.id].push(a.field); - const c = Cb.open(a.id, 1); - c.onupgradeneeded = function() { - const b = a.db = this.result; + const b = Cb.open(a.id, 1); + b.onupgradeneeded = function() { + const c = a.db = this.result; for (let e = 0, d; e < Db.length; e++) { d = Db[e]; for (let f = 0, g; f < Eb[a.id].length; f++) { - g = Eb[a.id][f], b.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || b.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); + g = Eb[a.id][f], c.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || c.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } } }; - return a.db = Z(c, function(b) { - a.db = b; + return a.db = Z(b, function(c) { + a.db = c; a.db.onversionchange = function() { a.close(); }; @@ -2628,72 +2665,72 @@ w.destroy = function() { }; w.clear = function() { const a = []; - for (let b = 0, e; b < Db.length; b++) { - e = Db[b]; + for (let c = 0, e; c < Db.length; c++) { + e = Db[c]; for (let d = 0, f; d < Eb[this.id].length; d++) { f = Eb[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } } - const c = this.db.transaction(a, "readwrite"); - for (let b = 0; b < a.length; b++) { - c.objectStore(a[b]).clear(); + const b = this.db.transaction(a, "readwrite"); + for (let c = 0; c < a.length; c++) { + b.objectStore(a[c]).clear(); } - return Z(c); + return Z(b); }; -w.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { - a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); +w.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { + a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); const g = this; - return Z(a).then(function(h) { - let k = []; - if (!h || !h.length) { - return k; + return Z(a).then(function(k) { + let h = []; + if (!k || !k.length) { + return h; } if (d) { - if (!b && !e && 1 === h.length) { - return h[0]; + if (!c && !e && 1 === k.length) { + return k[0]; } - for (let m = 0, l; m < h.length; m++) { - if ((l = h[m]) && l.length) { - if (e >= l.length) { - e -= l.length; + for (let l = 0, m; l < k.length; l++) { + if ((m = k[l]) && m.length) { + if (e >= m.length) { + e -= m.length; continue; } - const n = b ? e + Math.min(l.length - e, b) : l.length; - for (let u = e; u < n; u++) { - k.push(l[u]); + const r = c ? e + Math.min(m.length - e, c) : m.length; + for (let t = e; t < r; t++) { + h.push(m[t]); } e = 0; - if (k.length === b) { + if (h.length === c) { break; } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; -w.tag = function(a, c = 0, b = 0, e = !1) { +w.tag = function(a, b = 0, c = 0, e = !1) { a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); const d = this; return Z(a).then(function(f) { - if (!f || !f.length || b >= f.length) { + if (!f || !f.length || c >= f.length) { return []; } - if (!c && !b) { + if (!b && !c) { return f; } - f = f.slice(b, b + c); + f = f.slice(c, c + b); return e ? d.enrich(f) : f; }); }; w.enrich = function(a) { "object" !== typeof a && (a = [a]); - const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = []; + const b = this.db.transaction("reg", "readonly").objectStore("reg"), c = []; for (let e = 0; e < a.length; e++) { - b[e] = Z(c.get(a[e])); + c[e] = Z(b.get(a[e])); } - return Promise.all(b).then(function(e) { + return Promise.all(c).then(function(e) { for (let d = 0; d < e.length; d++) { e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null}; } @@ -2702,30 +2739,30 @@ w.enrich = function(a) { }; w.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Z(a).then(function(c) { - return !!c; + return Z(a).then(function(b) { + return !!b; }); }; w.search = null; w.info = function() { }; -w.transaction = function(a, c, b) { +w.transaction = function(a, b, c) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; - let e = this.h[a + ":" + c]; + let e = this.h[a + ":" + b]; if (e) { - return b.call(this, e); + return c.call(this, e); } - let d = this.db.transaction(a, c); - this.h[a + ":" + c] = e = d.objectStore(a); - const f = b.call(this, e); - this.h[a + ":" + c] = null; + let d = this.db.transaction(a, b); + this.h[a + ":" + b] = e = d.objectStore(a); + const f = c.call(this, e); + this.h[a + ":" + b] = null; return Z(d).finally(function() { d = e = null; return f; }); }; -w.commit = async function(a, c, b) { - if (c) { +w.commit = async function(a, b, c) { + if (b) { await this.clear(), a.commit_task = []; } else { let e = a.commit_task; @@ -2733,66 +2770,66 @@ w.commit = async function(a, c, b) { for (let d = 0, f; d < e.length; d++) { if (f = e[d], f.clear) { await this.clear(); - c = !0; + b = !0; break; } else { e[d] = f.del; } } - c || (b || (e = e.concat(ca(a.reg))), e.length && await this.remove(e)); + b || (c || (e = e.concat(ca(a.reg))), e.length && await this.remove(e)); } a.reg.size && (await this.transaction("map", "readwrite", function(e) { for (const d of a.map) { const f = d[0], g = d[1]; - g.length && (c ? e.put(g, f) : e.get(f).onsuccess = function() { - let h = this.result; - var k; - if (h && h.length) { - const m = Math.max(h.length, g.length); - for (let l = 0, n, u; l < m; l++) { - if ((u = g[l]) && u.length) { - if ((n = h[l]) && n.length) { - for (k = 0; k < u.length; k++) { - n.push(u[k]); + g.length && (b ? e.put(g, f) : e.get(f).onsuccess = function() { + let k = this.result; + var h; + if (k && k.length) { + const l = Math.max(k.length, g.length); + for (let m = 0, r, t; m < l; m++) { + if ((t = g[m]) && t.length) { + if ((r = k[m]) && r.length) { + for (h = 0; h < t.length; h++) { + r.push(t[h]); } } else { - h[l] = u; + k[m] = t; } - k = 1; + h = 1; } } } else { - h = g, k = 1; + k = g, h = 1; } - k && e.put(h, f); + h && e.put(k, f); }); } }), await this.transaction("ctx", "readwrite", function(e) { for (const d of a.ctx) { const f = d[0], g = d[1]; - for (const h of g) { - const k = h[0], m = h[1]; - m.length && (c ? e.put(m, f + ":" + k) : e.get(f + ":" + k).onsuccess = function() { - let l = this.result; - var n; - if (l && l.length) { - const u = Math.max(l.length, m.length); - for (let p = 0, t, r; p < u; p++) { - if ((r = m[p]) && r.length) { - if ((t = l[p]) && t.length) { - for (n = 0; n < r.length; n++) { - t.push(r[n]); + for (const k of g) { + const h = k[0], l = k[1]; + l.length && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { + let m = this.result; + var r; + if (m && m.length) { + const t = Math.max(m.length, l.length); + for (let q = 0, u, n; q < t; q++) { + if ((n = l[q]) && n.length) { + if ((u = m[q]) && u.length) { + for (r = 0; r < n.length; r++) { + u.push(n[r]); } } else { - l[p] = r; + m[q] = n; } - n = 1; + r = 1; } } } else { - l = m, n = 1; + m = l, r = 1; } - n && e.put(l, f + ":" + k); + r && e.put(m, f + ":" + h); }); } } @@ -2809,31 +2846,31 @@ w.commit = async function(a, c, b) { for (const d of a.tag) { const f = d[0], g = d[1]; g.length && (e.get(f).onsuccess = function() { - let h = this.result; - h = h && h.length ? h.concat(g) : g; - e.put(h, f); + let k = this.result; + k = k && k.length ? k.concat(g) : g; + e.put(k, f); }); } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function Gb(a, c, b) { +function Gb(a, b, c) { const e = a.value; let d, f = 0; - for (let g = 0, h; g < e.length; g++) { - if (h = b ? e : e[g]) { - for (let k = 0, m, l; k < c.length; k++) { - if (l = c[k], m = h.indexOf(l), 0 <= m) { - if (d = 1, 1 < h.length) { - h.splice(m, 1); + for (let g = 0, k; g < e.length; g++) { + if (k = c ? e : e[g]) { + for (let h = 0, l, m; h < b.length; h++) { + if (m = b[h], l = k.indexOf(m), 0 <= l) { + if (d = 1, 1 < k.length) { + k.splice(l, 1); } else { e[g] = []; break; } } } - f += h.length; + f += k.length; } - if (b) { + if (c) { break; } } @@ -2842,33 +2879,33 @@ function Gb(a, c, b) { } w.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map", "readwrite", function(c) { - c.openCursor().onsuccess = function() { - const b = this.result; - b && Gb(b, a); + return Promise.all([this.transaction("map", "readwrite", function(b) { + b.openCursor().onsuccess = function() { + const c = this.result; + c && Gb(c, a); }; - }), this.transaction("ctx", "readwrite", function(c) { - c.openCursor().onsuccess = function() { - const b = this.result; - b && Gb(b, a); + }), this.transaction("ctx", "readwrite", function(b) { + b.openCursor().onsuccess = function() { + const c = this.result; + c && Gb(c, a); }; - }), this.transaction("tag", "readwrite", function(c) { - c.openCursor().onsuccess = function() { - const b = this.result; - b && Gb(b, a, !0); + }), this.transaction("tag", "readwrite", function(b) { + b.openCursor().onsuccess = function() { + const c = this.result; + c && Gb(c, a, !0); }; - }), this.transaction("reg", "readwrite", function(c) { - for (let b = 0; b < a.length; b++) { - c.delete(a[b]); + }), this.transaction("reg", "readwrite", function(b) { + for (let c = 0; c < a.length; c++) { + b.delete(a[c]); } })]); }; -function Z(a, c) { - return new Promise((b, e) => { +function Z(a, b) { + return new Promise((c, e) => { a.onsuccess = a.oncomplete = function() { - c && c(this.result); - c = null; - b(this.result); + b && b(this.result); + b = null; + c(this.result); }; a.onerror = a.onblocked = e; a = null; diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index ed4863c..e5a781c 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,105 +1,107 @@ /**! - * FlexSearch.js v0.8.201 (Bundle) + * FlexSearch.js v0.8.202 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var w;function H(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function aa(a,c){return"undefined"===typeof a?c:a}function I(){return Object.create(null)} -function M(a){return"string"===typeof a}function ba(a){return"object"===typeof a}function ca(a){const c=[];for(const b of a.keys())c.push(b);return c}function ea(a,c){if(M(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,fa)}catch(d){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:H(b&&new Set(b),null,this.filter);this.dedupe=H(a.dedupe,!0,this.dedupe);this.matcher=H((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=H((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=H((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,1024,this.maxlength);this.rtl=H(a.rtl,!1,this.rtl);if(this.cache=b=H(a.cache,!0,this.cache))this.I=null,this.R="number"===typeof b?b:2E5,this.B=new Map,this.H=new Map,this.M=this.L=128;this.h="";this.N=null;this.A="";this.O=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= -(this.A?"|":"")+d;return this};w.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.A+=(this.A?"|":"")+a;this.O=null;this.cache&&Q(this);return this};w.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&Q(this);return this}; -w.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.N=null;this.cache&&Q(this);return this}; -w.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&Q(this);return this}; -w.encode=function(a,c){if(this.cache&&a.length<=this.L)if(this.I){if(this.B.has(a))return this.B.get(a)}else this.I=setTimeout(Q,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ka?a.normalize("NFKD").replace(ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(c){if(d[l])continue;d[l]=1}else{if(f===l)continue;f=l}if(b)e.push(l);else if(!this.filter||("function"===typeof this.filter?this.filter(l):!this.filter.has(l))){if(this.cache&&l.length<=this.M)if(this.I){var k=this.H.get(l);if(k||""===k){k&&e.push(k);continue}}else this.I=setTimeout(Q,50,this);if(this.stemmer){this.O||(this.O=new RegExp("(?!^)("+ -this.A+")$"));let u;for(;u!==l&&2this.stemmer.get(p))}if(l&&(this.mapper||this.dedupe&&1this.matcher.get(u)));if(l&&this.replacer)for(k=0;l&&kthis.R&&(this.H.clear(),this.M=this.M/1.1|0));if(l){if(l!==n)if(c){if(d[l])continue;d[l]=1}else{if(g===l)continue;g=l}e.push(l)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.L&&(this.B.set(a,e),this.B.size>this.R&&(this.B.clear(),this.L=this.L/1.1|0));return e};function Q(a){a.I=null;a.B.clear();a.H.clear()};function ma(a,c,b){b||(c||"object"!==typeof a?"object"===typeof c&&(b=c,c=0):b=a);b&&(a=b.query||a,c=b.limit||c);let e=""+(c||0);b&&(e+=(b.offset||0)+!!b.context+!!b.suggest+(!1!==b.resolve)+(b.resolution||this.resolution)+(b.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new R);let d=this.cache.get(a+e);if(!d){const f=b&&b.cache;f&&(b.cache=!1);d=this.search(a,c,b);f&&(b.cache=f);this.cache.set(a+e,d)}return d}function R(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""} -R.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};R.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};R.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};R.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:!1,numeric:!1,dedupe:!1};const qa={};const ra=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 sa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ta=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ua={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 va={Exact:na,Default:qa,Normalize:qa,LatinBalance:{mapper:ra},LatinAdvanced:{mapper:ra,matcher:sa,replacer:ta},LatinExtra:{mapper:ra,replacer:ta.concat([/(?!^)[aeo]/g,""]),matcher:sa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;b=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const h=c.length;if(h&&(d=d.length?d.concat(c):c,b-=h,e&&(a.length-=h),!b))break;c=0}return d} -function za(a){if(!this||this.constructor!==za)return new za(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;g=this.priority*this.priority*3):(Ha=setTimeout(Ka,0),Ia=Date.now());if(Ja){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let W=0; -function La(a={},c){function b(h){function k(m){m=m.data||m;const l=m.id,n=l&&f.h[l];n&&(n(m.msg),delete f.h[l])}this.worker=h;this.h=I();if(this.worker){d?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(m){1E9c?a.slice(b,b+c):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}g=g.slice(b,b+c);h=g.length;b=0}h>c&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?Ta.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ya(a,c,b,!1,this.h),b=0));d&&(this.await=null);return d?this.resolve(c,b,e):this};Y.prototype.and=function(){return Ua(this,"and",Za,arguments)};function Za(a,c,b,e,d,f){if(!f&&!this.result.length)return d?this.result:this;let g;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{let h=0;for(let k=0,m,l;ka.length)this.result=a[0];else{a:{f=b;var g=this.h;const h=[],k=I();let m=0;for(let l=0,n;lb||e?k.slice(e,b+e):k;else{if(ab||e)k=k.slice(e,b+ -e)}else{d=[];for(let n=0,u;ne)e-=u.length;else{if(b&&u.length>b||e)u=u.slice(e,b+e),b-=u.length,e&&(e-=u.length);d.push(u);if(!b)break}k=d}}return k} -function Ya(a,c,b,e,d){const f=[],g=I();let h;var k=a.length;let m;if(e)for(d=k-1;0<=d;d--){if(m=(e=a[d])&&e.length)for(k=0;kA&&(A=q.length+(q?1:0)),B=q.length+(q?1:0)+G.length,E+=D,ya.push(v.length),v.push({match:G})),q+=(q?" ":"")+G)}if(!x)F=y[C],q+=(q?" ":"")+F,k&&v.push({text:F});else if(k&&E>=k)break}E=ya.length*(f.length-2);if(p||t||k&&q.length-E>k)if(E=k+E-2*u,C=B-A,0y&&(y=0)),v=v.length-1){if(J>= -v.length){C[x+1]=1;J>=y.length&&(E[x+1]=1);continue}D-=u}q=v[J].text;if(L=t&&z[x])if(0L)if(C[x+1]=1,m)q=q.substring(0,L);else continue;(L-=q.length)||(L=-1);z[x]=L}else{C[x+1]=1;continue}if(D+q.length+1<=k)q=" "+q,B[x]+=q;else if(m)U=k-D-1,0=J){if(0>J){C[x]=1;E[x]=1;continue}D-=u}q=v[J].text;if(L=p&&F[x])if(0L)if(C[x]=1,m)q=q.substring(q.length- -L);else continue;(L-=q.length)||(L=-1);F[x]=L}else{C[x]=1;continue}if(D+q.length+1<=k)q+=" ",B[x]=q+B[x];else if(m)U=q.length+1-(k-D),0<=U&&U=y.length-1?Qa=1:Jb||e)a=a.slice(e,e+b);d&&(a=Ta.call(this,a))}return a} -function Ta(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);const c=Array(a.length);for(let b=0,e;br;f--){g=t.substring(r,f);q=this.rtl?d-1-r:r;var h=this.score?this.score(c,t,p,g,q):wb(u, -m,p,d,q);xb(this,n,g,h,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),m,p,h-1,k-1),q=this.bidirectional&&t>f;xb(this,l,q?f:t,r,a,b,q?t:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.S&&ub(this));return this}; -function xb(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])if(g?(c=k||(c[b]=I()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){c=new za(h);if(a.fastupdate)for(let m of a.reg.values())m.includes(h)&&(m[m.indexOf(h)]=c);k[e]=h=c}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function wb(a,c,b,e,d){return b&&1b)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function V(a,c){if(!this||this.constructor!==V)return new V(a);if(a){var b=M(a)?a:a.preset;b&&(a=Object.assign({},vb[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=M(a.encoder)?va[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new la(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;(b=a.keystore||0)&&(this.keystore=b);this.map=b?new S(b):new Map;this.ctx=b?new S(b):new Map;this.reg=c||(this.fastupdate?b?new S(b):new Map:b?new T(b):new Set);this.T=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(b=a.cache||null)&&new R(b);this.resolve=!1!==a.resolve;if(b=a.db)this.db=this.mount(b);this.S=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=V.prototype; -w.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};w.commit=function(a,c){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,c)};w.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function ub(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,c){return this.add(a,c,!0)};w.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};w.update=function(a,c){const b=this,e=this.remove(a);return e&&e.then?e.then(()=>b.add(a,c)):this.add(a,c)}; -w.cleanup=function(){if(!this.fastupdate)return this;tb(this.map);this.depth&&tb(this.ctx);return this};w.searchCache=ma;w.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=pb(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=lb(this.map,this.reg.size);break;case 3:d="ctx";f=nb(this.ctx,this.reg.size);break;default:return}return rb.call(this,a,c,d,f,b,e)}; -w.import=function(a,c){if(c)switch("string"===typeof c&&(c=JSON.parse(c)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=l.length){e-=l.length;continue}const n=b?e+Math.min(l.length-e,b):l.length;for(let u=e;u=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; -w.enrich=function(a){"object"!==typeof a&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};const Hb={Index:V,Charset:va,Encoder:la,Document:Na,Worker:La,Resolver:Y,IndexedDB:Fb,Language:{}},Ib="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let Jb;(Jb=Ib.define)&&Jb.amd?Jb([],function(){return Hb}):"object"===typeof Ib.exports?Ib.exports=Hb:Ib.FlexSearch=Hb;}(this||self)); +(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var w;function H(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function aa(a,b){return"undefined"===typeof a?b:a}function I(){return Object.create(null)} +function M(a){return"string"===typeof a}function ba(a){return"object"===typeof a}function ca(a){const b=[];for(const c of a.keys())b.push(c);return b}function ea(a,b){if(M(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; +this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,fa)}catch(d){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:H(c&&new Set(c),null,this.filter);this.dedupe=H(a.dedupe,!0,this.dedupe);this.matcher=H((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=H((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=H((c=a.stemmer)&&new Map(c), +null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,1024,this.maxlength);this.rtl=H(a.rtl,!1,this.rtl);if(this.cache=c=H(a.cache,!0,this.cache))this.I=null,this.R="number"===typeof c?c:2E5,this.C=new Map,this.H=new Map,this.M=this.L=128;this.h="";this.N=null;this.B="";this.O=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.B+= +(this.B?"|":"")+d;return this};w.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.B+=(this.B?"|":"")+a;this.O=null;this.cache&&Q(this);return this};w.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&Q(this);return this}; +w.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.N=null;this.cache&&Q(this);return this}; +w.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&Q(this);return this}; +w.encode=function(a,b){if(this.cache&&a.length<=this.L)if(this.I){if(this.C.has(a))return this.C.get(a)}else this.I=setTimeout(Q,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ka?a.normalize("NFKD").replace(ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(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.M)if(this.I){var k=this.H.get(m);if(k||""===k){k&&e.push(k);continue}}else this.I=setTimeout(Q,50,this);if(this.stemmer){this.O||(this.O=new RegExp("(?!^)("+ +this.B+")$"));let t;for(;t!==m&&2this.stemmer.get(r))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(t)));if(m&&this.replacer)for(k=0;m&&kthis.R&&(this.H.clear(),this.M=this.M/1.1|0));if(m){if(m!==q)if(b){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.L&&(this.C.set(a,e),this.C.size>this.R&&(this.C.clear(),this.L=this.L/1.1|0));return e};function Q(a){a.I=null;a.C.clear();a.H.clear()};function ma(a,b,c){c||(b||"object"!==typeof a?"object"===typeof b&&(c=b,b=0):c=a);c&&(a=c.query||a,b=c.limit||b);let e=""+(b||0);c&&(e+=(c.offset||0)+!!c.context+!!c.suggest+(!1!==c.resolve)+(c.resolution||this.resolution)+(c.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new R);let d=this.cache.get(a+e);if(!d){const f=c&&c.cache;f&&(c.cache=!1);d=this.search(a,b,c);f&&(c.cache=f);this.cache.set(a+e,d)}return d}function R(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""} +R.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};R.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};R.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};R.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:!1,numeric:!1,dedupe:!1};const qa={};const ra=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 sa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ta=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ua={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 va={Exact:na,Default:qa,Normalize:qa,LatinBalance:{mapper:ra},LatinAdvanced:{mapper:ra,matcher:sa,replacer:ta},LatinExtra:{mapper:ra,replacer:ta.concat([/(?!^)[aeo]/g,""]),matcher:sa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const h=b.length;if(h&&(d=d.length?d.concat(b):b,c-=h,e&&(a.length-=h),!c))break;b=0}return d} +function xa(a){if(!this||this.constructor!==xa)return new xa(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;g=this.priority*this.priority*3):(Ha=setTimeout(Ka,0),Ia=Date.now());if(Ja){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 W=0; +function La(a={},b){function c(h){function k(l){l=l.data||l;const m=l.id,q=m&&f.h[m];q&&(q(l.msg),delete f.h[m])}this.worker=h;this.h=I();if(this.worker){d?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(l){1E9b?a.slice(c,c+b):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}g=g.slice(c,c+b);h=g.length;c=0}h>b&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?Ta.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ya(a,b,c,!1,this.h),c=0));d&&(this.await=null);return d?this.resolve(b,c,e,g):this};Y.prototype.and=function(){return Ua(this,"and",Za,arguments)};function Za(a,b,c,e,d,f,g){if(!f&&!this.result.length)return d?this.result:this;let h;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{let k=0;for(let l=0,m,q;la.length)this.result=a[0];else{a:{f=c;var h=this.h;const k=[],l=I();let m=0;for(let q=0,t;qD&&(D=n.length+(n?1:0)),B=n.length+(n?1:0)+F.length,G+=C,za.push(v.length),v.push({match:F})),n+=(n?" ":"")+F)}if(!x)E=y[A],n+=(n?" ":"")+E,k&&v.push({text:E});else if(k&&G>=k)break}G=za.length*(f.length-2);if(r||u||k&&n.length-G>k)if(G=k+G-2*t,A=B-D,0y&&(y=0)),v=v.length-1){if(J>= +v.length){A[x+1]=1;J>=y.length&&(G[x+1]=1);continue}C-=t}n=v[J].text;if(L=u&&z[x])if(0L)if(A[x+1]=1,l)n=n.substring(0,L);else continue;(L-=n.length)||(L=-1);z[x]=L}else{A[x+1]=1;continue}if(C+n.length+1<=k)n=" "+n,B[x]+=n;else if(l)U=k-C-1,0=J){if(0>J){A[x]=1;G[x]=1;continue}C-=t}n=v[J].text;if(L=r&&E[x])if(0L)if(A[x]=1,l)n=n.substring(n.length- +L);else continue;(L-=n.length)||(L=-1);E[x]=L}else{A[x]=1;continue}if(C+n.length+1<=k)n+=" ",B[x]=n+B[x];else if(l)U=n.length+1-(k-C),0<=U&&U=y.length-1?Qa=1:Jc||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+ +e)}else{d=[];for(let q=0,t;qe)e-=t.length;else{if(c&&t.length>c||e)t=t.slice(e,c+e),c-=t.length,e&&(e-=t.length);d.push(t);if(!c)break}k=d}}return k} +function Ya(a,b,c,e,d){const f=[],g=I();let h;var k=a.length;let l;if(e)for(d=k-1;0<=d;d--){if(l=(e=a[d])&&e.length)for(k=0;kc||e)a=a.slice(e,e+c);d&&(a=Ta.call(this,a))}return a} +function Ta(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);const b=Array(a.length);for(let c=0,e;cp;f--){g=u.substring(p,f);n=this.rtl?d-1-p:p;var h=this.score?this.score(b,u,r,g,n):wb(t, +l,r,d,n);xb(this,q,g,h,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,r,h-1,k-1),n=this.bidirectional&&u>f;xb(this,m,n?f:u,p,a,c,n?u:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.S&&ub(this));return this}; +function xb(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=I()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new xa(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[e]=h=b}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} +function wb(a,b,c,e,d){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,e,d,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function V(a,b){if(!this||this.constructor!==V)return new V(a);if(a){var c=M(a)?a:a.preset;c&&(a=Object.assign({},vb[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=M(a.encoder)?va[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new la(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new S(c):new Map;this.ctx=c?new S(c):new Map;this.reg=b||(this.fastupdate?c?new S(c):new Map:c?new T(c):new Set);this.T=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new R(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.S=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=V.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 ub(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();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):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){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; +w.cleanup=function(){if(!this.fastupdate)return this;tb(this.map);this.depth&&tb(this.ctx);return this};w.searchCache=ma;w.export=function(a,b,c=0,e=0){let d,f;switch(e){case 0:d="reg";f=pb(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=lb(this.map,this.reg.size);break;case 3:d="ctx";f=nb(this.ctx,this.reg.size);break;default:return}return rb.call(this,a,b,d,f,c,e)}; +w.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=m.length){e-=m.length;continue}const q=c?e+Math.min(m.length-e,c):m.length;for(let t=e;t=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +w.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 Hb={Index:V,Charset:va,Encoder:la,Document:Na,Worker:La,Resolver:Y,IndexedDB:Fb,Language:{}},Ib="undefined"!==typeof self?self:"undefined"!==typeof global?global:self;let Jb;(Jb=Ib.define)&&Jb.amd?Jb([],function(){return Hb}):"object"===typeof Ib.exports?Ib.exports=Hb:Ib.FlexSearch=Hb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index c5764ee..0753e7e 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,35 +1,35 @@ /**! - * FlexSearch.js v0.8.201 (Bundle/Module/Debug) + * FlexSearch.js v0.8.202 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ var w; -function H(a, c, b) { - const e = typeof b, d = typeof a; +function H(a, b, c) { + const e = typeof c, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { - if (b) { + if (c) { if ("function" === d && e === d) { - return function(h) { - return a(b(h)); + return function(k) { + return a(c(k)); }; } - c = a.constructor; - if (c === b.constructor) { - if (c === Array) { - return b.concat(a); + b = a.constructor; + if (b === c.constructor) { + if (b === Array) { + return c.concat(a); } - if (c === Map) { - var f = new Map(b); + if (b === Map) { + var f = new Map(c); for (var g of a) { f.set(g[0], g[1]); } return f; } - if (c === Set) { - g = new Set(b); + if (b === Set) { + g = new Set(c); for (f of a.values()) { g.add(f); } @@ -39,12 +39,12 @@ function H(a, c, b) { } return a; } - return b; + return c; } - return "undefined" === d ? c : a; + return "undefined" === d ? b : a; } -function aa(a, c) { - return "undefined" === typeof a ? c : a; +function aa(a, b) { + return "undefined" === typeof a ? b : a; } function I() { return Object.create(null); @@ -56,18 +56,18 @@ function ba(a) { return "object" === typeof a; } function ca(a) { - const c = []; - for (const b of a.keys()) { - c.push(b); + const b = []; + for (const c of a.keys()) { + b.push(c); } - return c; + return b; } -function da(a, c) { - if (N(c)) { - a = a[c]; +function da(a, b) { + if (N(b)) { + a = a[b]; } else { - for (let b = 0; a && b < c.length; b++) { - a = a[c[b]]; + for (let c = 0; a && c < b.length; c++) { + a = a[b[c]]; } } return a; @@ -88,27 +88,27 @@ function la(a = {}) { w = la.prototype; w.assign = function(a) { this.normalize = H(a.normalize, !0, this.normalize); - let c = a.include, b = c || a.exclude || a.split, e; - if (b || "" === b) { - if ("object" === typeof b && b.constructor !== RegExp) { + let b = a.include, c = b || a.exclude || a.split, e; + if (c || "" === c) { + if ("object" === typeof c && c.constructor !== RegExp) { let d = ""; - e = !c; - c || (d += "\\p{Z}"); - b.letter && (d += "\\p{L}"); - b.number && (d += "\\p{N}", e = !!c); - b.symbol && (d += "\\p{S}"); - b.punctuation && (d += "\\p{P}"); - b.control && (d += "\\p{C}"); - if (b = b.char) { - d += "object" === typeof b ? b.join("") : b; + e = !b; + b || (d += "\\p{Z}"); + c.letter && (d += "\\p{L}"); + c.number && (d += "\\p{N}", e = !!b); + c.symbol && (d += "\\p{S}"); + c.punctuation && (d += "\\p{P}"); + c.control && (d += "\\p{C}"); + if (c = c.char) { + d += "object" === typeof c ? c.join("") : c; } try { - this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); + this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); } catch (f) { - 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+/; + console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { - this.split = b, e = !1 === b || 2 > "a1a".split(b).length; + this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } this.numeric = H(a.numeric, e); } else { @@ -121,22 +121,22 @@ w.assign = function(a) { } this.prepare = H(a.prepare, null, this.prepare); this.finalize = H(a.finalize, null, this.finalize); - b = a.filter; - this.filter = "function" === typeof b ? b : H(b && new Set(b), null, this.filter); + c = a.filter; + this.filter = "function" === typeof c ? c : H(c && new Set(c), null, this.filter); this.dedupe = H(a.dedupe, !0, this.dedupe); - this.matcher = H((b = a.matcher) && new Map(b), null, this.matcher); - this.mapper = H((b = a.mapper) && new Map(b), null, this.mapper); - this.stemmer = H((b = a.stemmer) && new Map(b), null, this.stemmer); + this.matcher = H((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = H((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = H((c = a.stemmer) && new Map(c), null, this.stemmer); this.replacer = H(a.replacer, null, this.replacer); this.minlength = H(a.minlength, 1, this.minlength); this.maxlength = H(a.maxlength, 1024, this.maxlength); this.rtl = H(a.rtl, !1, this.rtl); - if (this.cache = b = H(a.cache, !0, this.cache)) { - this.I = null, this.R = "number" === typeof b ? b : 2e5, this.B = new Map(), this.H = new Map(), this.M = this.L = 128; + if (this.cache = c = H(a.cache, !0, this.cache)) { + this.I = null, this.R = "number" === typeof c ? c : 2e5, this.C = new Map(), this.H = new Map(), this.M = this.L = 128; } this.h = ""; this.N = null; - this.A = ""; + this.B = ""; this.O = null; if (this.matcher) { for (const d of this.matcher.keys()) { @@ -145,15 +145,15 @@ w.assign = function(a) { } if (this.stemmer) { for (const d of this.stemmer.keys()) { - this.A += (this.A ? "|" : "") + d; + this.B += (this.B ? "|" : "") + d; } } return this; }; -w.addStemmer = function(a, c) { +w.addStemmer = function(a, b) { this.stemmer || (this.stemmer = new Map()); - this.stemmer.set(a, c); - this.A += (this.A ? "|" : "") + a; + this.stemmer.set(a, b); + this.B += (this.B ? "|" : "") + a; this.O = null; this.cache && Q(this); return this; @@ -163,46 +163,46 @@ w.addFilter = function(a) { this.cache && Q(this); return this; }; -w.addMapper = function(a, c) { +w.addMapper = function(a, b) { if ("object" === typeof a) { - return this.addReplacer(a, c); + return this.addReplacer(a, b); } if (1 < a.length) { - return this.addMatcher(a, c); + return this.addMatcher(a, b); } this.mapper || (this.mapper = new Map()); - this.mapper.set(a, c); + this.mapper.set(a, b); this.cache && Q(this); return this; }; -w.addMatcher = function(a, c) { +w.addMatcher = function(a, b) { if ("object" === typeof a) { - return this.addReplacer(a, c); + return this.addReplacer(a, b); } if (2 > a.length && (this.dedupe || this.mapper)) { - return this.addMapper(a, c); + return this.addMapper(a, b); } this.matcher || (this.matcher = new Map()); - this.matcher.set(a, c); + this.matcher.set(a, b); this.h += (this.h ? "|" : "") + a; this.N = null; this.cache && Q(this); return this; }; -w.addReplacer = function(a, c) { +w.addReplacer = function(a, b) { if ("string" === typeof a) { - return this.addMatcher(a, c); + return this.addMatcher(a, b); } this.replacer || (this.replacer = []); - this.replacer.push(a, c); + this.replacer.push(a, b); this.cache && Q(this); return this; }; -w.encode = function(a, c) { +w.encode = function(a, b) { if (this.cache && a.length <= this.L) { if (this.I) { - if (this.B.has(a)) { - return this.B.get(a); + if (this.C.has(a)) { + return this.C.get(a); } } else { this.I = setTimeout(Q, 50, this); @@ -211,30 +211,30 @@ w.encode = function(a, c) { this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ka ? a.normalize("NFKD").replace(ka, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(ia, "$1 $2").replace(ja, "$1 $2").replace(ha, "$1 ")); - const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = I(), f, g, h = this.split || "" === this.split ? a.split(this.split) : [a]; - for (let m = 0, l, n; m < h.length; m++) { - if ((l = n = h[m]) && !(l.length < this.minlength || l.length > this.maxlength)) { - if (c) { - if (d[l]) { - continue; - } - d[l] = 1; - } else { - if (f === l) { - continue; - } - f = l; - } + const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + let e = [], d = I(), f, g, k = this.split || "" === this.split ? a.split(this.split) : [a]; + for (let l = 0, m, r; l < k.length; l++) { + if ((m = r = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (b) { - e.push(l); + if (d[m]) { + continue; + } + d[m] = 1; } else { - if (!this.filter || ("function" === typeof this.filter ? this.filter(l) : !this.filter.has(l))) { - if (this.cache && l.length <= this.M) { + 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.M) { if (this.I) { - var k = this.H.get(l); - if (k || "" === k) { - k && e.push(k); + var h = this.H.get(m); + if (h || "" === h) { + h && e.push(h); continue; } } else { @@ -242,68 +242,68 @@ w.encode = function(a, c) { } } if (this.stemmer) { - this.O || (this.O = new RegExp("(?!^)(" + this.A + ")$")); - let u; - for (; u !== l && 2 < l.length;) { - u = l, l = l.replace(this.O, p => this.stemmer.get(p)); + this.O || (this.O = new RegExp("(?!^)(" + this.B + ")$")); + let t; + for (; t !== m && 2 < m.length;) { + t = m, m = m.replace(this.O, q => this.stemmer.get(q)); } } - if (l && (this.mapper || this.dedupe && 1 < l.length)) { - k = ""; - for (let u = 0, p = "", t, r; u < l.length; u++) { - t = l.charAt(u), t === p && this.dedupe || ((r = this.mapper && this.mapper.get(t)) || "" === r ? r === p && this.dedupe || !(p = r) || (k += r) : k += p = t); + if (m && (this.mapper || this.dedupe && 1 < m.length)) { + h = ""; + for (let t = 0, q = "", u, n; t < m.length; t++) { + u = m.charAt(t), u === q && this.dedupe || ((n = this.mapper && this.mapper.get(u)) || "" === n ? n === q && this.dedupe || !(q = n) || (h += n) : h += q = u); } - l = k; + m = h; } - this.matcher && 1 < l.length && (this.N || (this.N = new RegExp("(" + this.h + ")", "g")), l = l.replace(this.N, u => this.matcher.get(u))); - if (l && this.replacer) { - for (k = 0; l && k < this.replacer.length; k += 2) { - l = l.replace(this.replacer[k], this.replacer[k + 1]); + this.matcher && 1 < m.length && (this.N || (this.N = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.N, t => this.matcher.get(t))); + if (m && this.replacer) { + for (h = 0; m && h < this.replacer.length; h += 2) { + m = m.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && n.length <= this.M && (this.H.set(n, l), this.H.size > this.R && (this.H.clear(), this.M = this.M / 1.1 | 0)); - if (l) { - if (l !== n) { - if (c) { - if (d[l]) { + this.cache && r.length <= this.M && (this.H.set(r, m), this.H.size > this.R && (this.H.clear(), this.M = this.M / 1.1 | 0)); + if (m) { + if (m !== r) { + if (b) { + if (d[m]) { continue; } - d[l] = 1; + d[m] = 1; } else { - if (g === l) { + if (g === m) { continue; } - g = l; + g = m; } } - e.push(l); + e.push(m); } } } } } this.finalize && (e = this.finalize(e) || e); - this.cache && a.length <= this.L && (this.B.set(a, e), this.B.size > this.R && (this.B.clear(), this.L = this.L / 1.1 | 0)); + this.cache && a.length <= this.L && (this.C.set(a, e), this.C.size > this.R && (this.C.clear(), this.L = this.L / 1.1 | 0)); return e; }; function Q(a) { a.I = null; - a.B.clear(); + a.C.clear(); a.H.clear(); } -;function ma(a, c, b) { - b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : b = a); - b && (a = b.query || a, c = b.limit || c); - let e = "" + (c || 0); - b && (e += (b.offset || 0) + !!b.context + !!b.suggest + (!1 !== b.resolve) + (b.resolution || this.resolution) + (b.boost || 0)); +;function ma(a, b, c) { + c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : c = a); + c && (a = c.query || a, b = c.limit || b); + let e = "" + (b || 0); + c && (e += (c.offset || 0) + !!c.context + !!c.suggest + (!1 !== c.resolve) + (c.resolution || this.resolution) + (c.boost || 0)); a = ("" + a).toLowerCase(); this.cache || (this.cache = new na()); let d = this.cache.get(a + e); if (!d) { - const f = b && b.cache; - f && (b.cache = !1); - d = this.search(a, c, b); - f && (b.cache = f); + const f = c && c.cache; + f && (c.cache = !1); + d = this.search(a, b, c); + f && (c.cache = f); this.cache.set(a + e, d); } return d; @@ -313,19 +313,19 @@ function na(a) { this.cache = new Map(); this.h = ""; } -na.prototype.set = function(a, c) { - this.cache.set(this.h = a, c); +na.prototype.set = function(a, b) { + this.cache.set(this.h = a, b); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; na.prototype.get = function(a) { - const c = this.cache.get(a); - c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); - return c; + const b = this.cache.get(a); + b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); + return b; }; na.prototype.remove = function(a) { - for (const c of this.cache) { - const b = c[0]; - c[1].includes(a) && this.cache.delete(b); + for (const b of this.cache) { + const c = b[0]; + b[1].includes(a) && this.cache.delete(c); } }; na.prototype.clear = function() { @@ -338,26 +338,26 @@ const sa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], const ta = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ua = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; const va = {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 wa = {Exact:qa, Default:ra, Normalize:ra, LatinBalance:{mapper:sa}, LatinAdvanced:{mapper:sa, matcher:ta, replacer:ua}, LatinExtra:{mapper:sa, replacer:ua.concat([/(?!^)[aeo]/g, ""]), matcher:ta}, 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 = va[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = va[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + for (let c = 0; c < a.length; c++) { + var b = a[c]; + let e = b.charAt(0), d = va[e]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = va[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[b] = e; + a[c] = e; } }}, CJK:{split:""}, LatinExact:qa, LatinDefault:ra, LatinSimple:ra}; -function za(a, c, b, e) { +function xa(a, b, c, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { - if (g = a.index[f], c >= g.length) { - c -= g.length; + if (g = a.index[f], b >= g.length) { + b -= g.length; } else { - c = g[e ? "splice" : "slice"](c, b); - const h = c.length; - if (h && (d = d.length ? d.concat(c) : c, b -= h, e && (a.length -= h), !b)) { + b = g[e ? "splice" : "slice"](b, c); + const k = b.length; + if (k && (d = d.length ? d.concat(b) : b, c -= k, e && (a.length -= k), !c)) { break; } - c = 0; + b = 0; } } return d; @@ -368,42 +368,42 @@ function Aa(a) { } this.index = a ? [a] : []; this.length = a ? a.length : 0; - const c = this; - return new Proxy([], {get(b, e) { + const b = this; + return new Proxy([], {get(c, e) { if ("length" === e) { - return c.length; + return b.length; } if ("push" === e) { return function(d) { - c.index[c.index.length - 1].push(d); - c.length++; + b.index[b.index.length - 1].push(d); + b.length++; }; } if ("pop" === e) { return function() { - if (c.length) { - return c.length--, c.index[c.index.length - 1].pop(); + if (b.length) { + return b.length--, b.index[b.index.length - 1].pop(); } }; } if ("indexOf" === e) { return function(d) { let f = 0; - for (let g = 0, h, k; g < c.index.length; g++) { - h = c.index[g]; - k = h.indexOf(d); - if (0 <= k) { - return f + k; + for (let g = 0, k, h; g < b.index.length; g++) { + k = b.index[g]; + h = k.indexOf(d); + if (0 <= h) { + return f + h; } - f += h.length; + f += k.length; } return -1; }; } if ("includes" === e) { return function(d) { - for (let f = 0; f < c.index.length; f++) { - if (c.index[f].includes(d)) { + for (let f = 0; f < b.index.length; f++) { + if (b.index[f].includes(d)) { return !0; } } @@ -412,24 +412,24 @@ function Aa(a) { } if ("slice" === e) { return function(d, f) { - return za(c, d || 0, f || c.length, !1); + return xa(b, d || 0, f || b.length, !1); }; } if ("splice" === e) { return function(d, f) { - return za(c, d || 0, f || c.length, !0); + return xa(b, d || 0, f || b.length, !0); }; } if ("constructor" === e) { return Array; } if ("symbol" !== typeof e) { - return (b = c.index[e / 2 ** 31 | 0]) && b[e]; + return (c = b.index[e / 2 ** 31 | 0]) && c[e]; } - }, set(b, e, d) { - b = e / 2 ** 31 | 0; - (c.index[b] || (c.index[b] = []))[e] = d; - c.length++; + }, set(c, e, d) { + c = e / 2 ** 31 | 0; + (b.index[c] || (b.index[c] = []))[e] = d; + b.length++; return !0; }}); } @@ -448,16 +448,16 @@ function R(a = 8) { this.index = I(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.C = Ba, this.B = BigInt(a)) : (this.C = Ca, this.B = a); } R.prototype.get = function(a) { - const c = this.index[this.B(a)]; - return c && c.get(a); + const b = this.index[this.C(a)]; + return b && b.get(a); }; -R.prototype.set = function(a, c) { - var b = this.B(a); - let e = this.index[b]; - e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++); +R.prototype.set = function(a, b) { + var c = this.C(a); + let e = this.index[c]; + e ? (c = e.size, e.set(a, b), (c -= e.size) && this.size++) : (this.index[c] = e = new Map([[a, b]]), this.h.push(e), this.size++); }; function S(a = 8) { if (!this || this.constructor !== S) { @@ -466,21 +466,21 @@ function S(a = 8) { this.index = I(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.C = Ba, this.B = BigInt(a)) : (this.C = Ca, this.B = a); } S.prototype.add = function(a) { - var c = this.B(a); - let b = this.index[c]; - b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.h.push(b), this.size++); + var b = this.C(a); + let c = this.index[b]; + c ? (b = c.size, c.add(a), (b -= c.size) && this.size++) : (this.index[b] = c = new Set([a]), this.h.push(c), this.size++); }; w = R.prototype; w.has = S.prototype.has = function(a) { - const c = this.index[this.B(a)]; - return c && c.has(a); + const b = this.index[this.C(a)]; + return b && b.has(a); }; w.delete = S.prototype.delete = function(a) { - const c = this.index[this.B(a)]; - c && c.delete(a) && this.size--; + const b = this.index[this.C(a)]; + b && b.delete(a) && this.size--; }; w.clear = S.prototype.clear = function() { this.index = I(); @@ -489,81 +489,81 @@ w.clear = S.prototype.clear = function() { }; w.values = S.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { - for (let c of this.h[a].values()) { - yield c; + for (let b of this.h[a].values()) { + yield b; } } }; w.keys = S.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { - for (let c of this.h[a].keys()) { - yield c; + for (let b of this.h[a].keys()) { + yield b; } } }; w.entries = S.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { - for (let c of this.h[a].entries()) { - yield c; + for (let b of this.h[a].entries()) { + yield b; } } }; function Ca(a) { - let c = 2 ** this.A - 1; + let b = 2 ** this.B - 1; if ("number" == typeof a) { - return a & c; + return a & b; } - let b = 0, e = this.A + 1; + let c = 0, e = this.B + 1; for (let d = 0; d < a.length; d++) { - b = (b * e ^ a.charCodeAt(d)) & c; + c = (c * e ^ a.charCodeAt(d)) & b; } - return 32 === this.A ? b + 2 ** 31 : b; + return 32 === this.B ? c + 2 ** 31 : c; } function Ba(a) { - let c = BigInt(2) ** this.A - BigInt(1); - var b = typeof a; - if ("bigint" === b) { - return a & c; + let b = BigInt(2) ** this.B - BigInt(1); + var c = typeof a; + if ("bigint" === c) { + return a & b; } - if ("number" === b) { - return BigInt(a) & c; + if ("number" === c) { + return BigInt(a) & b; } - b = BigInt(0); - let e = this.A + BigInt(1); + c = BigInt(0); + let e = this.B + BigInt(1); for (let d = 0; d < a.length; d++) { - b = (b * e ^ BigInt(a.charCodeAt(d))) & c; + c = (c * e ^ BigInt(a.charCodeAt(d))) & b; } - return b; + return c; } ;let Da, T; async function Ea(a) { a = a.data; - var c = a.task; - const b = a.id; + var b = a.task; + const c = a.id; let e = a.args; - switch(c) { + switch(b) { case "init": T = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), Da = new self.FlexSearch.Index(T), delete self.FlexSearch) : Da = new V(T); - postMessage({id:b}); + (b = a.factory) ? (Function("return " + b)()(self), Da = new self.FlexSearch.Index(T), delete self.FlexSearch) : Da = new V(T); + postMessage({id:c}); break; default: let d; - if ("export" === c) { + if ("export" === b) { if (!T.export || "function" !== typeof T.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } e[1] ? (e[0] = T.export, e[2] = 0, e[3] = 1) : e = null; } - if ("import" === c) { + if ("import" === b) { if (!T.import || "function" !== typeof T.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } e[0] && (a = await T.import.call(Da, e[0]), Da.import(e[0], a)); } else { - (d = e && Da[c].apply(Da, e)) && d.then && (d = await d), d && d.await && (d = await d.await), "search" === c && d.result && (d = d.result); + (d = e && Da[b].apply(Da, e)) && d.then && (d = await d), d && d.await && (d = await d.await), "search" === b && d.result && (d = d.result); } - postMessage("search" === c ? {id:b, msg:d} : {id:b}); + postMessage("search" === b ? {id:c, msg:d} : {id:c}); } } ;function Fa(a) { @@ -580,48 +580,48 @@ function Ka() { } function Ga(a) { this[a + "Async"] = function() { - const c = arguments; - var b = c[c.length - 1]; + const b = arguments; + var c = b[b.length - 1]; let e; - "function" === typeof b && (e = b, delete c[c.length - 1]); + "function" === typeof c && (e = c, delete b[b.length - 1]); Ha ? Ja || (Ja = Date.now() - Ia >= this.priority * this.priority * 3) : (Ha = setTimeout(Ka, 0), Ia = Date.now()); if (Ja) { const f = this; return new Promise(g => { setTimeout(function() { - g(f[a + "Async"].apply(f, c)); + g(f[a + "Async"].apply(f, b)); }, 0); }); } - const d = this[a].apply(this, c); - b = d.then ? d : new Promise(f => f(d)); - e && b.then(e); - return b; + const d = this[a].apply(this, b); + c = d.then ? d : new Promise(f => f(d)); + e && c.then(e); + return c; }; } ;let W = 0; -function La(a = {}, c) { - function b(h) { - function k(m) { - m = m.data || m; - const l = m.id, n = l && f.h[l]; - n && (n(m.msg), delete f.h[l]); +function La(a = {}, b) { + function c(k) { + function h(l) { + l = l.data || l; + const m = l.id, r = m && f.h[m]; + r && (r(l.msg), delete f.h[m]); } - this.worker = h; + this.worker = k; this.h = I(); if (this.worker) { - d ? this.worker.on("message", k) : this.worker.onmessage = k; + d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(m) { + return new Promise(function(l) { 1e9 < W && (W = 0); f.h[++W] = function() { - m(f); + l(f); }; f.worker.postMessage({id:W, task:"init", factory:e, options:a}); }); } this.priority = a.priority || 4; - this.encoder = c || null; + this.encoder = b || null; this.worker.postMessage({task:"init", factory:e, options:a}); return this; } @@ -633,9 +633,9 @@ function La(a = {}, c) { let e = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; e && (e = e.toString()); const d = "undefined" === typeof window, f = this, g = Ma(e, d, a.worker); - return g.then ? g.then(function(h) { - return b.call(f, h); - }) : b.call(this, g); + return g.then ? g.then(function(k) { + return c.call(f, k); + }) : c.call(this, g); } X("add"); X("append"); @@ -649,38 +649,38 @@ La.prototype.searchCache = ma; Fa(La.prototype); function X(a) { La.prototype[a] = function() { - const c = this, b = [].slice.call(arguments); - var e = b[b.length - 1]; + const b = this, c = [].slice.call(arguments); + var e = c[c.length - 1]; let d; - "function" === typeof e && (d = e, b.pop()); + "function" === typeof e && (d = e, c.pop()); e = new Promise(function(f) { - "export" === a && "function" === typeof b[0] && (b[0] = null); + "export" === a && "function" === typeof c[0] && (c[0] = null); 1e9 < W && (W = 0); - c.h[++W] = f; - c.worker.postMessage({task:a, id:W, args:b}); + b.h[++W] = f; + b.worker.postMessage({task:a, id:W, args:c}); }); return d ? (e.then(d), this) : e; }; } -function Ma(a, c, b) { - return c ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ea.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ma(a, b, c) { + return b ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ea.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;Na.prototype.add = function(a, c, b) { - ba(a) && (c = a, a = da(c, this.key)); - if (c && (a || 0 === a)) { - if (!b && this.reg.has(a)) { - return this.update(a, c); +;Na.prototype.add = function(a, b, c) { + ba(a) && (b = a, a = da(b, this.key)); + if (b && (a || 0 === a)) { + if (!c && this.reg.has(a)) { + return this.update(a, b); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.G[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); + for (let k = 0, h; k < this.field.length; k++) { + h = this.G[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(b); d && e.add(a, d, !1, !0); } else { - if (d = k.J, !d || d(c)) { - k.constructor === String ? k = ["" + k] : N(k) && (k = [k]), Qa(c, k, this.K, 0, e, a, k[0], b); + if (d = h.J, !d || d(b)) { + h.constructor === String ? h = ["" + h] : N(h) && (h = [h]), Qa(b, h, this.K, 0, e, a, h[0], c); } } } @@ -688,34 +688,34 @@ function Ma(a, c, b) { for (e = 0; e < this.F.length; e++) { var f = this.F[e], g = this.P[e]; d = this.tag.get(g); - let h = I(); + let k = I(); if ("function" === typeof f) { - if (f = f(c), !f) { + if (f = f(b), !f) { continue; } } else { - const k = f.J; - if (k && !k(c)) { + const h = f.J; + if (h && !h(b)) { continue; } f.constructor === String && (f = "" + f); - f = da(c, f); + f = da(b, f); } if (d && f) { N(f) && (f = [f]); - for (let k = 0, m, l; k < f.length; k++) { - if (m = f[k], !h[m] && (h[m] = 1, (g = d.get(m)) ? l = g : d.set(m, l = []), !b || !l.includes(a))) { - if (l.length === 2 ** 31 - 1) { - g = new Aa(l); + for (let h = 0, l, m; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !c || !m.includes(a))) { + if (m.length === 2 ** 31 - 1) { + g = new Aa(m); if (this.fastupdate) { - for (let n of this.reg.values()) { - n.includes(l) && (n[n.indexOf(l)] = g); + for (let r of this.reg.values()) { + r.includes(m) && (r[r.indexOf(m)] = g); } } - d.set(m, l = g); + d.set(l, m = g); } - l.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(l) : this.reg.set(a, [l])); + m.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); } } } else { @@ -723,99 +723,99 @@ function Ma(a, c, b) { } } } - if (this.store && (!b || !this.store.has(a))) { - let h; + if (this.store && (!c || !this.store.has(a))) { + let k; if (this.D) { - h = I(); - for (let k = 0, m; k < this.D.length; k++) { - m = this.D[k]; - if ((b = m.J) && !b(c)) { + k = I(); + for (let h = 0, l; h < this.D.length; h++) { + l = this.D[h]; + if ((c = l.J) && !c(b)) { continue; } - let l; - if ("function" === typeof m) { - l = m(c); - if (!l) { + let m; + if ("function" === typeof l) { + m = l(b); + if (!m) { continue; } - m = [m.U]; - } else if (N(m) || m.constructor === String) { - h[m] = c[m]; + l = [l.U]; + } else if (N(l) || l.constructor === String) { + k[l] = b[l]; continue; } - Ra(c, h, m, 0, m[0], l); + Ra(b, k, l, 0, l[0], m); } } - this.store.set(a, h || c); + this.store.set(a, k || b); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Ra(a, c, b, e, d, f) { +function Ra(a, b, c, e, d, f) { a = a[d]; - if (e === b.length - 1) { - c[d] = f || a; + if (e === c.length - 1) { + b[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Ra(a, c, b, e, d); + for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { + Ra(a, b, c, e, d); } } else { - c = c[d] || (c[d] = I()), d = b[++e], Ra(a, c, b, e, d); + b = b[d] || (b[d] = I()), d = c[++e], Ra(a, b, c, e, d); } } } -function Qa(a, c, b, e, d, f, g, h) { +function Qa(a, b, c, e, d, f, g, k) { if (a = a[g]) { - if (e === c.length - 1) { + if (e === b.length - 1) { if (a.constructor === Array) { - if (b[e]) { - for (c = 0; c < a.length; c++) { - d.add(f, a[c], !0, !0); + if (c[e]) { + for (b = 0; b < a.length; b++) { + d.add(f, a[b], !0, !0); } return; } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Qa(a, c, b, e, d, f, g, h); + Qa(a, b, c, e, d, f, g, k); } } else { - g = c[++e], Qa(a, c, b, e, d, f, g, h); + g = b[++e], Qa(a, b, c, e, d, f, g, k); } } } } -;function Sa(a, c, b, e) { +;function Sa(a, b, c, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a, e ? Ta.call(this, a) : a; + return a = a[0], a = c || a.length > b ? a.slice(c, c + b) : a, e ? Ta.call(this, a) : a; } let d = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { - if (b) { - if (b >= h) { - b -= h; + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { + if (c) { + if (c >= k) { + c -= k; continue; } - g = g.slice(b, b + c); - h = g.length; - b = 0; + g = g.slice(c, c + b); + k = g.length; + c = 0; } - h > c && (g = g.slice(0, c), h = c); - if (!d.length && h >= c) { + k > b && (g = g.slice(0, b), k = b); + if (!d.length && k >= b) { return e ? Ta.call(this, g) : g; } d.push(g); - c -= h; - if (!c) { + b -= k; + if (!b) { break; } } @@ -823,208 +823,206 @@ function Qa(a, c, b, e, d, f, g, h) { d = 1 < d.length ? [].concat.apply([], d) : d[0]; return e ? Ta.call(this, d) : d; } -;function Ua(a, c, b, e) { +;function Ua(a, b, c, e) { var d = e[0]; if (d[0] && d[0].query) { - return a[c].apply(a, d); + return a[b].apply(a, d); } - if (!("and" !== c && "not" !== c || a.result.length || a.await || d.suggest)) { + if (!("and" !== b && "not" !== b || a.result.length || a.await || d.suggest)) { return 1 < e.length && (d = e[e.length - 1]), (e = d.resolve) ? a.await || a.result : a; } - let f = [], g = 0, h = 0, k, m, l; - var n; - let u; - for (c = 0; c < e.length; c++) { - if (d = e[c]) { - var p = void 0; + let f = [], g = 0, k = 0, h, l, m, r, t; + for (b = 0; b < e.length; b++) { + if (d = e[b]) { + var q = void 0; if (d.constructor === Y) { - p = d.await || d.result; + q = d.await || d.result; } else if (d.then || d.constructor === Array) { - p = d; + q = d; } else { g = d.limit || 0; - h = d.offset || 0; - l = d.suggest; - m = d.resolve; - k = (n = d.highlight && m) || d.enrich && m; - p = d.queue; - let t = d.async || p; - (n = d.index) ? a.index || (a.index = n) : n = a.index; + k = d.offset || 0; + m = d.suggest; + h = ((r = (l = d.resolve) && d.highlight) || d.enrich) && l; + q = d.queue; + let u = d.async || q, n = d.index; + n ? a.index || (a.index = n) : n = a.index; if (d.query || d.tag) { - if (!a.index) { + if (!n) { throw Error("Resolver can't apply because the corresponding Index was never specified"); } - const r = d.field || d.pluck; - if (r) { - if (!a.index.index) { + const p = d.field || d.pluck; + if (p) { + d.query && (a.query = d.query, a.field = p); + if (!n.index) { throw Error("Resolver can't apply because the corresponding Document Index was not specified"); } - n = a.index.index.get(r); + n = n.index.get(p); if (!n) { - throw Error("Resolver can't apply because the specified Document Field '" + r + "' was not found"); + throw Error("Resolver can't apply because the specified Document Field '" + p + "' was not found"); } } - if (p && (u || a.await)) { - u = 1; - let q; - const y = a.C.length, v = new Promise(function(A) { - q = A; + if (q && (t || a.await)) { + t = 1; + let y; + const v = a.A.length, D = new Promise(function(B) { + y = B; }); - (function(A, B) { - v.h = function() { - B.index = null; - B.resolve = !1; - let E = t ? A.searchAsync(B) : A.search(B); - if (E.then) { - return E.then(function(C) { - a.C[y] = C = C.result || C; - q(C); - return C; + (function(B, G) { + D.h = function() { + G.index = null; + G.resolve = !1; + let A = u ? B.searchAsync(G) : B.search(G); + if (A.then) { + return A.then(function(E) { + a.A[v] = E = E.result || E; + y(E); + return E; }); } - E = E.result || E; - q(E); - return E; + A = A.result || A; + y(A); + return A; }; })(n, Object.assign({}, d)); - a.C.push(v); - f[c] = v; + a.A.push(D); + f[b] = D; continue; } else { - d.resolve = !1, d.index = null, p = t ? n.searchAsync(d) : n.search(d), d.resolve = m, d.index = n; + d.resolve = !1, d.index = null, q = u ? n.searchAsync(d) : n.search(d), d.resolve = l, d.index = n; } } else if (d.and) { - p = Va(d, "and", n); + q = Va(d, "and", n); } else if (d.or) { - p = Va(d, "or", n); + q = Va(d, "or", n); } else if (d.not) { - p = Va(d, "not", n); + q = Va(d, "not", n); } else if (d.xor) { - p = Va(d, "xor", n); + q = Va(d, "xor", n); } else { continue; } } - p.await ? (u = 1, p = p.await) : p.then ? (u = 1, p = p.then(function(t) { - return t.result || t; - })) : p = p.result || p; - f[c] = p; + q.await ? (t = 1, q = q.await) : q.then ? (t = 1, q = q.then(function(u) { + return u.result || u; + })) : q = q.result || q; + f[b] = q; } } - u && !a.await && (a.await = new Promise(function(t) { - a.return = t; + t && !a.await && (a.await = new Promise(function(u) { + a.return = u; })); - if (u) { - const t = Promise.all(f).then(function(r) { - for (let q = 0; q < a.C.length; q++) { - if (a.C[q] === t) { - a.C[q] = function() { - return b.call(a, r, g, h, k, m, l); + if (t) { + const u = Promise.all(f).then(function(n) { + for (let p = 0; p < a.A.length; p++) { + if (a.A[p] === u) { + a.A[p] = function() { + return c.call(a, n, g, k, h, l, m, r); }; break; } } Wa(a); }); - a.C.push(t); + a.A.push(u); } else if (a.await) { - a.C.push(function() { - return b.call(a, f, g, h, k, m, l); + a.A.push(function() { + return c.call(a, f, g, k, h, l, m, r); }); } else { - return b.call(a, f, g, h, k, m, l); + return c.call(a, f, g, k, h, l, m, r); } - return m ? a.await || a.result : a; + return l ? a.await || a.result : a; } -function Va(a, c, b) { - a = a[c]; +function Va(a, b, c) { + a = a[b]; const e = a[0] || a; - e.index || (e.index = b); - b = new Y(e); - 1 < a.length && (b = b[c].apply(b, a.slice(1))); - return b; + e.index || (e.index = c); + c = new Y(e); + 1 < a.length && (c = c[b].apply(c, a.slice(1))); + return c; } ;Y.prototype.or = function() { return Ua(this, "or", Xa, arguments); }; -function Xa(a, c, b, e, d) { - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ya(a, c, b, !1, this.h), b = 0)); +function Xa(a, b, c, e, d, f, g) { + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ya(a, b, c, !1, this.h), c = 0)); d && (this.await = null); - return d ? this.resolve(c, b, e) : this; + return d ? this.resolve(b, c, e, g) : this; } ;Y.prototype.and = function() { return Ua(this, "and", Za, arguments); }; -function Za(a, c, b, e, d, f) { +function Za(a, b, c, e, d, f, g) { if (!f && !this.result.length) { return d ? this.result : this; } - let g; + let k; if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { let h = 0; - for (let k = 0, m, l; k < a.length; k++) { - if ((m = a[k]) && (l = m.length)) { - h < l && (h = l); + for (let l = 0, m, r; l < a.length; l++) { + if ((m = a[l]) && (r = m.length)) { + h < r && (h = r); } else if (!f) { h = 0; break; } } - h ? (this.result = $a(a, h, c, b, f, this.h, d), g = !0) : this.result = []; + h ? (this.result = $a(a, h, b, c, f, this.h, d), k = !0) : this.result = []; } } else { f || (this.result = a); } d && (this.await = null); - return d ? this.resolve(c, b, e, g) : this; + return d ? this.resolve(b, c, e, g, k) : this; } ;Y.prototype.xor = function() { return Ua(this, "xor", ab, arguments); }; -function ab(a, c, b, e, d, f) { +function ab(a, b, c, e, d, f, g) { if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { a: { - f = b; - var g = this.h; - const h = [], k = I(); + f = c; + var k = this.h; + const h = [], l = I(); let m = 0; - for (let l = 0, n; l < a.length; l++) { - if (n = a[l]) { - m < n.length && (m = n.length); - for (let u = 0, p; u < n.length; u++) { - if (p = n[u]) { - for (let t = 0, r; t < p.length; t++) { - r = p[t], k[r] = k[r] ? 2 : 1; + for (let r = 0, t; r < a.length; r++) { + if (t = a[r]) { + m < t.length && (m = t.length); + for (let q = 0, u; q < t.length; q++) { + if (u = t[q]) { + for (let n = 0, p; n < u.length; n++) { + p = u[n], l[p] = l[p] ? 2 : 1; } } } } } - for (let l = 0, n, u = 0; l < m; l++) { - for (let p = 0, t; p < a.length; p++) { - if (t = a[p]) { - if (n = t[l]) { - for (let r = 0, q; r < n.length; r++) { - if (q = n[r], 1 === k[q]) { + for (let r = 0, t, q = 0; r < m; r++) { + for (let u = 0, n; u < a.length; u++) { + if (n = a[u]) { + if (t = n[r]) { + for (let p = 0, y; p < t.length; p++) { + if (y = t[p], 1 === l[y]) { if (f) { f--; } else { if (d) { - if (h.push(q), h.length === c) { + if (h.push(y), h.length === b) { a = h; break a; } } else { - const y = l + (p ? g : 0); - h[y] || (h[y] = []); - h[y].push(q); - if (++u === c) { + const v = r + (u ? k : 0); + h[v] || (h[v] = []); + h[v].push(y); + if (++q === b) { a = h; break a; } @@ -1039,41 +1037,41 @@ function ab(a, c, b, e, d, f) { a = h; } this.result = a; - g = !0; + k = !0; } } else { f || (this.result = a); } d && (this.await = null); - return d ? this.resolve(c, b, e, g) : this; + return d ? this.resolve(b, c, e, g, k) : this; } ;Y.prototype.not = function() { return Ua(this, "not", bb, arguments); }; -function bb(a, c, b, e, d, f) { +function bb(a, b, c, e, d, f, g) { if (!f && !this.result.length) { return d ? this.result : this; } if (a.length && this.result.length) { a: { - f = b; - var g = []; + f = c; + var k = []; a = new Set(a.flat().flat()); - for (let h = 0, k, m = 0; h < this.result.length; h++) { - if (k = this.result[h]) { - for (let l = 0, n; l < k.length; l++) { - if (n = k[l], !a.has(n)) { + for (let h = 0, l, m = 0; h < this.result.length; h++) { + if (l = this.result[h]) { + for (let r = 0, t; r < l.length; r++) { + if (t = l[r], !a.has(t)) { if (f) { f--; } else { if (d) { - if (g.push(n), g.length === c) { - a = g; + if (k.push(t), k.length === b) { + a = k; break a; } } else { - if (g[h] || (g[h] = []), g[h].push(n), ++m === c) { - a = g; + if (k[h] || (k[h] = []), k[h].push(t), ++m === b) { + a = k; break a; } } @@ -1082,199 +1080,472 @@ function bb(a, c, b, e, d, f) { } } } - a = g; + a = k; } this.result = a; - g = !0; + k = !0; } d && (this.await = null); - return d ? this.resolve(c, b, e, g) : this; + return d ? this.resolve(b, c, e, g, k) : this; } -;function Y(a, c) { - if (!this || this.constructor !== Y) { - return new Y(a, c); +;function cb(a, b, c, e, d) { + let f, g, k; + "string" === typeof d ? (f = d, d = "") : f = d.template; + if (!f) { + throw Error('No template pattern was specified by the search option "highlight"'); } - let b = 0, e, d, f; + g = f.indexOf("$1"); + if (-1 === g) { + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); + } + k = f.substring(g + 2); + g = f.substring(0, g); + let h = d && d.boundary, l = !d || !1 !== d.clip, m = d && d.merge && k && g && new RegExp(k + " " + g, "g"); + d = d && d.ellipsis; + var r = 0; + if ("object" === typeof d) { + var t = d.template; + r = t.length - 2; + d = d.pattern; + } + "string" !== typeof d && (d = !1 === d ? "" : "..."); + r && (d = t.replace("$1", d)); + t = d.length - r; + let q, u; + "object" === typeof h && (q = h.before, 0 === q && (q = -1), u = h.after, 0 === u && (u = -1), h = h.total || 9e5); + r = new Map(); + for (let Oa = 0, ea, db, oa; Oa < b.length; Oa++) { + let pa; + if (e) { + pa = b, oa = e; + } else { + var n = b[Oa]; + oa = n.field; + if (!oa) { + continue; + } + pa = n.result; + } + db = c.get(oa); + ea = db.encoder; + n = r.get(ea); + "string" !== typeof n && (n = ea.encode(a), r.set(ea, n)); + for (let ya = 0; ya < pa.length; ya++) { + var p = pa[ya].doc; + if (!p) { + continue; + } + p = da(p, oa); + if (!p) { + continue; + } + var y = p.trim().split(/\s+/); + if (!y.length) { + continue; + } + p = ""; + var v = []; + let za = []; + var D = -1, B = -1, G = 0; + for (var A = 0; A < y.length; A++) { + var E = y[A], z = ea.encode(E); + z = 1 < z.length ? z.join(" ") : z[0]; + let x; + if (z && E) { + var C = E.length, K = (ea.split ? E.replace(ea.split, "") : E).length - z.length, F = "", L = 0; + for (var O = 0; O < n.length; O++) { + var P = n[O]; + if (P) { + var M = P.length; + M += K; + L && M <= L || (P = z.indexOf(P), -1 < P && (F = (P ? E.substring(0, P) : "") + g + E.substring(P, P + M) + k + (P + M < C ? E.substring(P + M) : ""), L = M, x = !0)); + } + } + F && (h && (0 > D && (D = p.length + (p ? 1 : 0)), B = p.length + (p ? 1 : 0) + F.length, G += C, za.push(v.length), v.push({match:F})), p += (p ? " " : "") + F); + } + if (!x) { + E = y[A], p += (p ? " " : "") + E, h && v.push({text:E}); + } else if (h && G >= h) { + break; + } + } + G = za.length * (f.length - 2); + if (q || u || h && p.length - G > h) { + if (G = h + G - 2 * t, A = B - D, 0 < q && (A += q), 0 < u && (A += u), A <= G) { + y = q ? D - (0 < q ? q : 0) : D - ((G - A) / 2 | 0), v = u ? B + (0 < u ? u : 0) : y + G, l || (0 < y && " " !== p.charAt(y) && " " !== p.charAt(y - 1) && (y = p.indexOf(" ", y), 0 > y && (y = 0)), v < p.length && " " !== p.charAt(v - 1) && " " !== p.charAt(v) && (v = p.lastIndexOf(" ", v), v < B ? v = B : ++v)), p = (y ? d : "") + p.substring(y, v) + (v < p.length ? d : ""); + } else { + B = []; + D = {}; + G = {}; + A = {}; + E = {}; + z = {}; + F = K = C = 0; + for (O = L = 1;;) { + var U = void 0; + for (let x = 0, J; x < za.length; x++) { + J = za[x]; + if (F) { + if (K !== F) { + if (A[x + 1]) { + continue; + } + J += F; + if (D[J]) { + C -= t; + G[x + 1] = 1; + A[x + 1] = 1; + continue; + } + if (J >= v.length - 1) { + if (J >= v.length) { + A[x + 1] = 1; + J >= y.length && (G[x + 1] = 1); + continue; + } + C -= t; + } + p = v[J].text; + if (M = u && z[x]) { + if (0 < M) { + if (p.length > M) { + if (A[x + 1] = 1, l) { + p = p.substring(0, M); + } else { + continue; + } + } + (M -= p.length) || (M = -1); + z[x] = M; + } else { + A[x + 1] = 1; + continue; + } + } + if (C + p.length + 1 <= h) { + p = " " + p, B[x] += p; + } else if (l) { + U = h - C - 1, 0 < U && (p = " " + p.substring(0, U), B[x] += p), A[x + 1] = 1; + } else { + A[x + 1] = 1; + continue; + } + } else { + if (A[x]) { + continue; + } + J -= K; + if (D[J]) { + C -= t; + A[x] = 1; + G[x] = 1; + continue; + } + if (0 >= J) { + if (0 > J) { + A[x] = 1; + G[x] = 1; + continue; + } + C -= t; + } + p = v[J].text; + if (M = q && E[x]) { + if (0 < M) { + if (p.length > M) { + if (A[x] = 1, l) { + p = p.substring(p.length - M); + } else { + continue; + } + } + (M -= p.length) || (M = -1); + E[x] = M; + } else { + A[x] = 1; + continue; + } + } + if (C + p.length + 1 <= h) { + p += " ", B[x] = p + B[x]; + } else if (l) { + U = p.length + 1 - (h - C), 0 <= U && U < p.length && (p = p.substring(U) + " ", B[x] = p + B[x]), A[x] = 1; + } else { + A[x] = 1; + continue; + } + } + } else { + p = v[J].match; + q && (E[x] = q); + u && (z[x] = u); + x && C++; + let Pa; + J ? !x && t && (C += t) : (G[x] = 1, A[x] = 1); + J >= y.length - 1 ? Pa = 1 : J < v.length - 1 && v[J + 1].match ? Pa = 1 : t && (C += t); + C -= f.length - 2; + if (!x || C + p.length <= h) { + B[x] = p; + } else { + U = L = O = G[x] = 0; + break; + } + Pa && (G[x + 1] = 1, A[x + 1] = 1); + } + C += p.length; + U = D[J] = 1; + } + if (U) { + K === F ? F++ : K++; + } else { + K === F ? L = 0 : O = 0; + if (!L && !O) { + break; + } + L ? (K++, F = K) : F++; + } + } + p = ""; + for (let x = 0, J; x < B.length; x++) { + J = (x && G[x] ? " " : (x && !d ? " " : "") + d) + B[x], p += J; + } + d && !G[B.length] && (p += d); + } + } + m && (p = p.replace(m, " ")); + pa[ya].highlight = p; + } + if (e) { + break; + } + } + return b; +} +;function Y(a, b) { + if (!this || this.constructor !== Y) { + return new Y(a, b); + } + let c = 0, e, d, f, g, k; if (a && a.index) { - const g = a; - c = g.index; - b = g.boost || 0; - if (g.query) { - const h = g.resolve; - a = g.async || g.queue; - g.resolve = !1; - g.index = null; - a = a ? c.searchAsync(g) : c.search(g); - g.resolve = h; - g.index = c; + const h = a; + b = h.index; + c = h.boost || 0; + if (d = h.query) { + f = h.field || h.pluck; + const l = h.resolve; + a = h.async || h.queue; + h.resolve = !1; + h.index = null; + a = a ? b.searchAsync(h) : b.search(h); + h.resolve = l; + h.index = b; a = a.result || a; } else { a = []; } } if (a && a.then) { - const g = this; - a = a.then(function(h) { - g.C[0] = g.result = h.result || h; - Wa(g); + const h = this; + a = a.then(function(l) { + h.A[0] = h.result = l.result || l; + Wa(h); }); e = [a]; a = []; - d = new Promise(function(h) { - f = h; + g = new Promise(function(l) { + k = l; }); } - this.index = c || null; + this.index = b || null; this.result = a || []; - this.h = b; - this.C = e || []; - this.await = d || null; - this.return = f || null; + this.h = c; + this.A = e || []; + this.await = g || null; + this.return = k || null; + this.query = d || ""; + this.field = f || ""; } -Y.prototype.limit = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, e; b < this.result.length; b++) { - if (e = this.result[b]) { - if (e.length <= a) { - if (c[b] = e, a -= e.length, !a) { +w = Y.prototype; +w.limit = function(a) { + if (this.await) { + const b = this; + this.A.push(function() { + b.limit(a); + return b.result; + }); + } else { + if (this.result.length) { + const b = []; + for (let c = 0, e; c < this.result.length; c++) { + if (e = this.result[c]) { + if (e.length <= a) { + if (b[c] = e, a -= e.length, !a) { + break; + } + } else { + b[c] = e.slice(0, a); break; } - } else { - c[b] = e.slice(0, a); - break; } } + this.result = b; } - this.result = c; } return this; }; -Y.prototype.offset = function(a) { - if (this.result.length) { - const c = []; - for (let b = 0, e; b < this.result.length; b++) { - if (e = this.result[b]) { - e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0); +w.offset = function(a) { + if (this.await) { + const b = this; + this.A.push(function() { + b.offset(a); + return b.result; + }); + } else { + if (this.result.length) { + const b = []; + for (let c = 0, e; c < this.result.length; c++) { + if (e = this.result[c]) { + e.length <= a ? a -= e.length : (b[c] = e.slice(a), a = 0); + } } + this.result = b; } - this.result = c; } return this; }; -Y.prototype.boost = function(a) { - this.h += a; +w.boost = function(a) { + if (this.await) { + const b = this; + this.A.push(function() { + b.boost(a); + return b.result; + }); + } else { + this.h += a; + } return this; }; -function Wa(a, c) { - let b = a.result; - for (let d = 0, f; d < a.C.length; d++) { - if (f = a.C[d]) { - if ("function" === typeof f) { - b = f(), a.C[d] = b = b.result || b, d--; - } else if (f.h) { - b = f.h(), a.C[d] = b = b.result || b, d--; - } else if (f.then) { - return a.await; - } - } - } - const e = a.return; - a.result = b; - a.C = []; +function Wa(a, b) { + let c = a.result; + var e = a.await; a.await = null; + for (let d = 0, f; d < a.A.length; d++) { + if (f = a.A[d]) { + if ("function" === typeof f) { + c = f(), a.A[d] = c = c.result || c, d--; + } else if (f.h) { + c = f.h(), a.A[d] = c = c.result || c, d--; + } else if (f.then) { + return a.await = e; + } + } + } + e = a.return; + a.A = []; a.return = null; - c || e(b); - return b; + b || e(c); + return c; } -Y.prototype.resolve = function(a, c, b, e) { - let d = this.await ? Wa(this, !0) : this.result; - if (d.then) { - const f = this; - return d.then(function() { - return f.resolve(a, c, b); +w.resolve = function(a, b, c, e, d) { + let f = this.await ? Wa(this, !0) : this.result; + if (f.then) { + const g = this; + return f.then(function() { + return g.resolve(a, b, c, e, d); }); } - d.length && ("object" === typeof a && (b = a.enrich, c = a.offset, a.highlight && console.warn('Highlighting results is not supported within the resolve() method. Instead pass highlight options within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'), a = a.limit), d = e ? b ? Ta.call(this.index, d) : d : Sa.call(this.index, d, a || 100, c, b)); - e = this.return; - this.return = this.await = this.C = this.result = this.index = null; - e && e(d); - return d; + f.length && ("object" === typeof a ? (e = a.highlight, c = !!e || a.enrich, b = a.offset, a = a.limit) : c = !!e || c, f = d ? c ? Ta.call(this.index, f) : f : Sa.call(this.index, f, a || 100, b, c)); + return this.finalize(f, e); }; -function $a(a, c, b, e, d, f, g) { - const h = a.length; - let k = [], m, l; - m = I(); - for (let n = 0, u, p, t, r; n < c; n++) { - for (let q = 0; q < h; q++) { - if (t = a[q], n < t.length && (u = t[n])) { - for (let y = 0; y < u.length; y++) { - p = u[y]; - (l = m[p]) ? m[p]++ : (l = 0, m[p] = 1); - r = k[l] || (k[l] = []); +w.finalize = function(a, b) { + if (a.then) { + const e = this; + return a.then(function(d) { + return e.finalize(d, b); + }); + } + b && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); + b && a.length && this.query && (a = cb(this.query, a, this.index.index, this.field, b)); + const c = this.return; + this.index = this.result = this.A = this.await = this.return = null; + this.query = this.field = ""; + c && c(a); + return a; +}; +function $a(a, b, c, e, d, f, g) { + const k = a.length; + let h = [], l, m; + l = I(); + for (let r = 0, t, q, u, n; r < b; r++) { + for (let p = 0; p < k; p++) { + if (u = a[p], r < u.length && (t = u[r])) { + for (let y = 0; y < t.length; y++) { + q = t[y]; + (m = l[q]) ? l[q]++ : (m = 0, l[q] = 1); + n = h[m] || (h[m] = []); if (!g) { - let v = n + (q || !d ? 0 : f || 0); - r = r[v] || (r[v] = []); + let v = r + (p || !d ? 0 : f || 0); + n = n[v] || (n[v] = []); } - r.push(p); - if (g && b && l === h - 1 && r.length - e === b) { - return e ? r.slice(e) : r; + n.push(q); + if (g && c && m === k - 1 && n.length - e === c) { + return e ? n.slice(e) : n; } } } } } - if (a = k.length) { + if (a = h.length) { if (d) { - k = 1 < k.length ? Ya(k, b, e, g, f) : (k = k[0]) && b && k.length > b || e ? k.slice(e, b + e) : k; + h = 1 < h.length ? Ya(h, c, e, g, f) : (h = h[0]) && c && h.length > c || e ? h.slice(e, c + e) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; - if (b || e) { + h = h[a - 1]; + if (c || e) { if (g) { - if (k.length > b || e) { - k = k.slice(e, b + e); + if (h.length > c || e) { + h = h.slice(e, c + e); } } else { d = []; - for (let n = 0, u; n < k.length; n++) { - if (u = k[n]) { - if (e && u.length > e) { - e -= u.length; + for (let r = 0, t; r < h.length; r++) { + if (t = h[r]) { + if (e && t.length > e) { + e -= t.length; } else { - if (b && u.length > b || e) { - u = u.slice(e, b + e), b -= u.length, e && (e -= u.length); + if (c && t.length > c || e) { + t = t.slice(e, c + e), c -= t.length, e && (e -= t.length); } - d.push(u); - if (!b) { + d.push(t); + if (!c) { break; } } } } - k = d; + h = d; } } } } - return k; + return h; } -function Ya(a, c, b, e, d) { +function Ya(a, b, c, e, d) { const f = [], g = I(); - let h; - var k = a.length; - let m; + let k; + var h = a.length; + let l; if (e) { - for (d = k - 1; 0 <= d; d--) { - if (m = (e = a[d]) && e.length) { - for (k = 0; k < m; k++) { - if (h = e[k], !g[h]) { - if (g[h] = 1, b) { - b--; + for (d = h - 1; 0 <= d; d--) { + if (l = (e = a[d]) && e.length) { + for (h = 0; h < l; h++) { + if (k = e[h], !g[k]) { + if (g[k] = 1, c) { + c--; } else { - if (f.push(h), f.length === c) { + if (f.push(k), f.length === b) { return f; } } @@ -1283,18 +1554,18 @@ function Ya(a, c, b, e, d) { } } } else { - for (let l = k - 1, n, u = 0; 0 <= l; l--) { - n = a[l]; - for (let p = 0; p < n.length; p++) { - if (m = (e = n[p]) && e.length) { - for (let t = 0; t < m; t++) { - if (h = e[t], !g[h]) { - if (g[h] = 1, b) { - b--; + for (let m = h - 1, r, t = 0; 0 <= m; m--) { + r = a[m]; + for (let q = 0; q < r.length; q++) { + if (l = (e = r[q]) && e.length) { + for (let u = 0; u < l; u++) { + if (k = e[u], !g[k]) { + if (g[k] = 1, c) { + c--; } else { - let r = (p + (l < k - 1 ? d || 0 : 0)) / (l + 1) | 0; - (f[r] || (f[r] = [])).push(h); - if (++u === c) { + let n = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[n] || (f[n] = [])).push(k); + if (++t === b) { return f; } } @@ -1306,311 +1577,78 @@ function Ya(a, c, b, e, d) { } return f; } -function cb(a, c, b) { +function eb(a, b, c) { const e = I(), d = []; - for (let f = 0, g; f < c.length; f++) { - g = c[f]; - for (let h = 0; h < g.length; h++) { - e[g[h]] = 1; + for (let f = 0, g; f < b.length; f++) { + g = b[f]; + for (let k = 0; k < g.length; k++) { + e[g[k]] = 1; } } - if (b) { + if (c) { for (let f = 0, g; f < a.length; f++) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, h; f < a.result.length; f++) { - for (g = a.result[f], c = 0; c < g.length; c++) { - h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); + for (let f = 0, g, k; f < a.result.length; f++) { + for (g = a.result[f], b = 0; b < g.length; b++) { + k = g[b], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); } } } return d; } ;I(); -function eb(a, c, b, e, d) { - let f, g, h; - "string" === typeof d ? (f = d, d = "") : f = d.template; - if (!f) { - throw Error('No template pattern was specified by the search option "highlight"'); - } - g = f.indexOf("$1"); - if (-1 === g) { - throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); - } - h = f.substring(g + 2); - g = f.substring(0, g); - let k = d && d.boundary, m = !d || !1 !== d.clip, l = d && d.merge && h && g && new RegExp(h + " " + g, "g"); - d = d && d.ellipsis; - var n = 0; - if ("object" === typeof d) { - var u = d.template; - n = u.length - 2; - d = d.pattern; - } - "string" !== typeof d && (d = !1 === d ? "" : "..."); - n && (d = u.replace("$1", d)); - u = d.length - n; - let p, t; - "object" === typeof k && (p = k.before, 0 === p && (p = -1), t = k.after, 0 === t && (t = -1), k = k.total || 9e5); - n = new Map(); - for (let Oa = 0, ea, db, oa; Oa < c.length; Oa++) { - let pa; - if (e) { - pa = c, oa = e; - } else { - var r = c[Oa]; - oa = r.field; - if (!oa) { - continue; - } - pa = r.result; - } - db = b.get(oa); - ea = db.encoder; - r = n.get(ea); - "string" !== typeof r && (r = ea.encode(a), n.set(ea, r)); - for (let xa = 0; xa < pa.length; xa++) { - var q = pa[xa].doc; - if (!q) { - continue; - } - q = da(q, oa); - if (!q) { - continue; - } - var y = q.trim().split(/\s+/); - if (!y.length) { - continue; - } - q = ""; - var v = []; - let ya = []; - var A = -1, B = -1, E = 0; - for (var C = 0; C < y.length; C++) { - var F = y[C], z = ea.encode(F); - z = 1 < z.length ? z.join(" ") : z[0]; - let x; - if (z && F) { - var D = F.length, K = (ea.split ? F.replace(ea.split, "") : F).length - z.length, G = "", L = 0; - for (var O = 0; O < r.length; O++) { - var P = r[O]; - if (P) { - var M = P.length; - M += K; - L && M <= L || (P = z.indexOf(P), -1 < P && (G = (P ? F.substring(0, P) : "") + g + F.substring(P, P + M) + h + (P + M < D ? F.substring(P + M) : ""), L = M, x = !0)); - } - } - G && (k && (0 > A && (A = q.length + (q ? 1 : 0)), B = q.length + (q ? 1 : 0) + G.length, E += D, ya.push(v.length), v.push({match:G})), q += (q ? " " : "") + G); - } - if (!x) { - F = y[C], q += (q ? " " : "") + F, k && v.push({text:F}); - } else if (k && E >= k) { - break; - } - } - E = ya.length * (f.length - 2); - if (p || t || k && q.length - E > k) { - if (E = k + E - 2 * u, C = B - A, 0 < p && (C += p), 0 < t && (C += t), C <= E) { - y = p ? A - (0 < p ? p : 0) : A - ((E - C) / 2 | 0), v = t ? B + (0 < t ? t : 0) : y + E, m || (0 < y && " " !== q.charAt(y) && " " !== q.charAt(y - 1) && (y = q.indexOf(" ", y), 0 > y && (y = 0)), v < q.length && " " !== q.charAt(v - 1) && " " !== q.charAt(v) && (v = q.lastIndexOf(" ", v), v < B ? v = B : ++v)), q = (y ? d : "") + q.substring(y, v) + (v < q.length ? d : ""); - } else { - B = []; - A = {}; - E = {}; - C = {}; - F = {}; - z = {}; - G = K = D = 0; - for (O = L = 1;;) { - var U = void 0; - for (let x = 0, J; x < ya.length; x++) { - J = ya[x]; - if (G) { - if (K !== G) { - if (C[x + 1]) { - continue; - } - J += G; - if (A[J]) { - D -= u; - E[x + 1] = 1; - C[x + 1] = 1; - continue; - } - if (J >= v.length - 1) { - if (J >= v.length) { - C[x + 1] = 1; - J >= y.length && (E[x + 1] = 1); - continue; - } - D -= u; - } - q = v[J].text; - if (M = t && z[x]) { - if (0 < M) { - if (q.length > M) { - if (C[x + 1] = 1, m) { - q = q.substring(0, M); - } else { - continue; - } - } - (M -= q.length) || (M = -1); - z[x] = M; - } else { - C[x + 1] = 1; - continue; - } - } - if (D + q.length + 1 <= k) { - q = " " + q, B[x] += q; - } else if (m) { - U = k - D - 1, 0 < U && (q = " " + q.substring(0, U), B[x] += q), C[x + 1] = 1; - } else { - C[x + 1] = 1; - continue; - } - } else { - if (C[x]) { - continue; - } - J -= K; - if (A[J]) { - D -= u; - C[x] = 1; - E[x] = 1; - continue; - } - if (0 >= J) { - if (0 > J) { - C[x] = 1; - E[x] = 1; - continue; - } - D -= u; - } - q = v[J].text; - if (M = p && F[x]) { - if (0 < M) { - if (q.length > M) { - if (C[x] = 1, m) { - q = q.substring(q.length - M); - } else { - continue; - } - } - (M -= q.length) || (M = -1); - F[x] = M; - } else { - C[x] = 1; - continue; - } - } - if (D + q.length + 1 <= k) { - q += " ", B[x] = q + B[x]; - } else if (m) { - U = q.length + 1 - (k - D), 0 <= U && U < q.length && (q = q.substring(U) + " ", B[x] = q + B[x]), C[x] = 1; - } else { - C[x] = 1; - continue; - } - } - } else { - q = v[J].match; - p && (F[x] = p); - t && (z[x] = t); - x && D++; - let Pa; - J ? !x && u && (D += u) : (E[x] = 1, C[x] = 1); - J >= y.length - 1 ? Pa = 1 : J < v.length - 1 && v[J + 1].match ? Pa = 1 : u && (D += u); - D -= f.length - 2; - if (!x || D + q.length <= k) { - B[x] = q; - } else { - U = L = O = E[x] = 0; - break; - } - Pa && (E[x + 1] = 1, C[x + 1] = 1); - } - D += q.length; - U = A[J] = 1; - } - if (U) { - K === G ? G++ : K++; - } else { - K === G ? L = 0 : O = 0; - if (!L && !O) { - break; - } - L ? (K++, G = K) : G++; - } - } - q = ""; - for (let x = 0, J; x < B.length; x++) { - J = (x && E[x] ? " " : (x && !d ? " " : "") + d) + B[x], q += J; - } - d && !E[B.length] && (q += d); - } - } - l && (q = q.replace(l, " ")); - pa[xa].highlight = q; - } - if (e) { - break; - } - } - return c; -} -;Na.prototype.search = function(a, c, b, e) { - b || (!c && ba(a) ? (b = a, a = "") : ba(c) && (b = c, c = 0)); +Na.prototype.search = function(a, b, c, e) { + c || (!b && ba(a) ? (c = a, a = "") : ba(b) && (c = b, b = 0)); let d = []; var f = []; let g; - let h, k, m, l, n; - let u = 0, p = !0, t; - if (b) { - b.constructor === Array && (b = {index:b}); - a = b.query || a; - g = b.pluck; - h = b.merge; - m = b.boost; - n = g || b.field || (n = b.index) && (n.index ? null : n); - var r = this.tag && b.tag; - k = b.suggest; - p = !1 !== b.resolve; - l = b.cache; - this.store && b.highlight && !p ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - t = p && this.store && b.highlight; - var q = !!t || p && this.store && b.enrich; - c = b.limit || c; - var y = b.offset || 0; - c || (c = p ? 100 : 0); - if (r && (!this.db || !e)) { - r.constructor !== Array && (r = [r]); + let k, h, l, m, r; + let t = 0, q = !0, u; + if (c) { + c.constructor === Array && (c = {index:c}); + a = c.query || a; + g = c.pluck; + k = c.merge; + l = c.boost; + r = g || c.field || (r = c.index) && (r.index ? null : r); + var n = this.tag && c.tag; + h = c.suggest; + q = !1 !== c.resolve; + m = c.cache; + this.store && c.highlight && !q ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && c.enrich && !q && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + u = q && this.store && c.highlight; + var p = !!u || q && this.store && c.enrich; + b = c.limit || b; + var y = c.offset || 0; + b || (b = q ? 100 : 0); + if (n && (!this.db || !e)) { + n.constructor !== Array && (n = [n]); var v = []; - for (let F = 0, z; F < r.length; F++) { - z = r[F]; + for (let E = 0, z; E < n.length; E++) { + z = n[E]; if (N(z)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (z.field && z.tag) { - var A = z.tag; - if (A.constructor === Array) { - for (var B = 0; B < A.length; B++) { - v.push(z.field, A[B]); + var D = z.tag; + if (D.constructor === Array) { + for (var B = 0; B < D.length; B++) { + v.push(z.field, D[B]); } } else { - v.push(z.field, A); + v.push(z.field, D); } } else { - A = Object.keys(z); - for (let D = 0, K, G; D < A.length; D++) { - if (K = A[D], G = z[K], G.constructor === Array) { - for (B = 0; B < G.length; B++) { - v.push(K, G[B]); + D = Object.keys(z); + for (let C = 0, K, F; C < D.length; C++) { + if (K = D[C], F = z[K], F.constructor === Array) { + for (B = 0; B < F.length; B++) { + v.push(K, F[B]); } } else { - v.push(K, G); + v.push(K, F); } } } @@ -1618,193 +1656,193 @@ function eb(a, c, b, e, d) { if (!v.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - r = v; + n = v; if (!a) { f = []; if (v.length) { - for (r = 0; r < v.length; r += 2) { + for (n = 0; n < v.length; n += 2) { if (this.db) { - e = this.index.get(v[r]); + e = this.index.get(v[n]); if (!e) { - console.warn("Tag '" + v[r] + ":" + v[r + 1] + "' will be skipped because there is no field '" + v[r] + "'."); + console.warn("Tag '" + v[n] + ":" + v[n + 1] + "' will be skipped because there is no field '" + v[n] + "'."); continue; } - f.push(e = e.db.tag(v[r + 1], c, y, q)); + f.push(e = e.db.tag(v[n + 1], b, y, p)); } else { - e = fb.call(this, v[r], v[r + 1], c, y, q); + e = fb.call(this, v[n], v[n + 1], b, y, p); } - d.push(p ? {field:v[r], tag:v[r + 1], result:e} : [e]); + d.push(q ? {field:v[n], tag:v[n + 1], result:e} : [e]); } } if (f.length) { - const F = this; + const E = this; return Promise.all(f).then(function(z) { - for (let D = 0; D < z.length; D++) { - p ? d[D].result = z[D] : d[D] = z[D]; + for (let C = 0; C < z.length; C++) { + q ? d[C].result = z[C] : d[C] = z[C]; } - return p ? d : new Y(1 < d.length ? $a(d, 1, 0, 0, k, m) : d[0], F); + return q ? d : new Y(1 < d.length ? $a(d, 1, 0, 0, h, l) : d[0], E); }); } - return p ? d : new Y(1 < d.length ? $a(d, 1, 0, 0, k, m) : d[0], this); + return q ? d : new Y(1 < d.length ? $a(d, 1, 0, 0, h, l) : d[0], this); } } - if (!p && !g) { - if (n = n || this.field) { - N(n) ? g = n : (n.constructor === Array && 1 === n.length && (n = n[0]), g = n.field || n.index); + if (!q && !g) { + if (r = r || this.field) { + N(r) ? g = r : (r.constructor === Array && 1 === r.length && (r = r[0]), g = r.field || r.index); } if (!g) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - n && n.constructor !== Array && (n = [n]); + r && r.constructor !== Array && (r = [r]); } - n || (n = this.field); - let E; + r || (r = this.field); + let G; v = (this.worker || this.db) && !e && []; - for (let F = 0, z, D, K; F < n.length; F++) { - D = n[F]; - if (this.db && this.tag && !this.G[F]) { + for (let E = 0, z, C, K; E < r.length; E++) { + C = r[E]; + if (this.db && this.tag && !this.G[E]) { continue; } - let G; - N(D) || (G = D, D = G.field, a = G.query || a, c = aa(G.limit, c), y = aa(G.offset, y), k = aa(G.suggest, k), t = p && this.store && aa(G.highlight, t), q = !!t || p && this.store && aa(G.enrich, q), l = aa(G.cache, l)); + let F; + N(C) || (F = C, C = F.field, a = F.query || a, b = aa(F.limit, b), y = aa(F.offset, y), h = aa(F.suggest, h), u = q && this.store && aa(F.highlight, u), p = !!u || q && this.store && aa(F.enrich, p), m = aa(F.cache, m)); if (e) { - z = e[F]; + z = e[E]; } else { - A = G || b || {}; - B = A.enrich; - var C = this.index.get(D); - r && (this.db && (A.tag = r, E = C.db.support_tag_search, A.field = n), !E && B && (A.enrich = !1)); - z = l ? C.searchCache(a, c, A) : C.search(a, c, A); - B && (A.enrich = B); + D = F || c || {}; + B = D.enrich; + var A = this.index.get(C); + n && (this.db && (D.tag = n, G = A.db.support_tag_search, D.field = r), !G && B && (D.enrich = !1)); + z = m ? A.searchCache(a, b, D) : A.search(a, b, D); + B && (D.enrich = B); if (v) { - v[F] = z; + v[E] = z; continue; } } K = (z = z.result || z) && z.length; - if (r && K) { - A = []; + if (n && K) { + D = []; B = 0; if (this.db && e) { - if (!E) { - for (C = n.length; C < e.length; C++) { - let L = e[C]; + if (!G) { + for (A = r.length; A < e.length; A++) { + let L = e[A]; if (L && L.length) { - B++, A.push(L); - } else if (!k) { - return p ? d : new Y(d, this); + B++, D.push(L); + } else if (!h) { + return q ? d : new Y(d, this); } } } } else { - for (let L = 0, O, P; L < r.length; L += 2) { - O = this.tag.get(r[L]); + for (let L = 0, O, P; L < n.length; L += 2) { + O = this.tag.get(n[L]); if (!O) { - if (console.warn("Tag '" + r[L] + ":" + r[L + 1] + "' will be skipped because there is no field '" + r[L] + "'."), k) { + if (console.warn("Tag '" + n[L] + ":" + n[L + 1] + "' will be skipped because there is no field '" + n[L] + "'."), h) { continue; } else { - return p ? d : new Y(d, this); + return q ? d : new Y(d, this); } } - if (P = (O = O && O.get(r[L + 1])) && O.length) { - B++, A.push(O); - } else if (!k) { - return p ? d : new Y(d, this); + if (P = (O = O && O.get(n[L + 1])) && O.length) { + B++, D.push(O); + } else if (!h) { + return q ? d : new Y(d, this); } } } if (B) { - z = cb(z, A, p); + z = eb(z, D, q); K = z.length; - if (!K && !k) { - return p ? z : new Y(z, this); + if (!K && !h) { + return q ? z : new Y(z, this); } B--; } } if (K) { - f[u] = D, d.push(z), u++; - } else if (1 === n.length) { - return p ? d : new Y(d, this); + f[t] = C, d.push(z), t++; + } else if (1 === r.length) { + return q ? d : new Y(d, this); } } if (v) { - if (this.db && r && r.length && !E) { - for (q = 0; q < r.length; q += 2) { - f = this.index.get(r[q]); + if (this.db && n && n.length && !G) { + for (p = 0; p < n.length; p += 2) { + f = this.index.get(n[p]); if (!f) { - if (console.warn("Tag '" + r[q] + ":" + r[q + 1] + "' was not found because there is no field '" + r[q] + "'."), k) { + if (console.warn("Tag '" + n[p] + ":" + n[p + 1] + "' was not found because there is no field '" + n[p] + "'."), h) { continue; } else { - return p ? d : new Y(d, this); + return q ? d : new Y(d, this); } } - v.push(f.db.tag(r[q + 1], c, y, !1)); + v.push(f.db.tag(n[p + 1], b, y, !1)); } } - const F = this; + const E = this; return Promise.all(v).then(function(z) { - b && (b.resolve = p); - z.length && (z = F.search(a, c, b, z)); + c && (c.resolve = q); + z.length && (z = E.search(a, b, c, z)); return z; }); } - if (!u) { - return p ? d : new Y(d, this); + if (!t) { + return q ? d : new Y(d, this); } - if (g && (!q || !this.store)) { - return d = d[0], p ? d : new Y(d, this); + if (g && (!p || !this.store)) { + return d = d[0], q ? d : new Y(d, this); } v = []; for (y = 0; y < f.length; y++) { - r = d[y]; - q && r.length && "undefined" === typeof r[0].doc && (this.db ? v.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = Ta.call(this, r)); + n = d[y]; + p && n.length && "undefined" === typeof n[0].doc && (this.db ? v.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = Ta.call(this, n)); if (g) { - return p ? t ? eb(a, r, this.index, g, t) : r : new Y(r, this); + return q ? u ? cb(a, n, this.index, g, u) : n : new Y(n, this); } - d[y] = {field:f[y], result:r}; + d[y] = {field:f[y], result:n}; } - if (q && this.db && v.length) { - const F = this; + if (p && this.db && v.length) { + const E = this; return Promise.all(v).then(function(z) { - for (let D = 0; D < z.length; D++) { - d[D].result = z[D]; + for (let C = 0; C < z.length; C++) { + d[C].result = z[C]; } - t && (d = eb(a, d, F.index, g, t)); - return h ? gb(d) : d; + u && (d = cb(a, d, E.index, g, u)); + return k ? gb(d) : d; }); } - t && (d = eb(a, d, this.index, g, t)); - return h ? gb(d) : d; + u && (d = cb(a, d, this.index, g, u)); + return k ? gb(d) : d; }; function gb(a) { - const c = [], b = I(), e = I(); - for (let d = 0, f, g, h, k, m, l, n; d < a.length; d++) { + const b = [], c = I(), e = I(); + for (let d = 0, f, g, k, h, l, m, r; d < a.length; d++) { f = a[d]; g = f.field; - h = f.result; - for (let u = 0; u < h.length; u++) { - if (m = h[u], "object" !== typeof m ? m = {id:k = m} : k = m.id, (l = b[k]) ? l.push(g) : (m.field = b[k] = [g], c.push(m)), n = m.highlight) { - l = e[k], l || (e[k] = l = {}, m.highlight = l), l[g] = n; + k = f.result; + for (let t = 0; t < k.length; t++) { + if (l = k[t], "object" !== typeof l ? l = {id:h = l} : h = l.id, (m = c[h]) ? m.push(g) : (l.field = c[h] = [g], b.push(l)), r = l.highlight) { + m = e[h], m || (e[h] = m = {}, l.highlight = m), m[g] = r; } } } - return c; + return b; } -function fb(a, c, b, e, d) { +function fb(a, b, c, e, d) { a = this.tag.get(a); if (!a) { return []; } - a = a.get(c); + a = a.get(b); if (!a) { return []; } - c = a.length - e; - if (0 < c) { - if (b && c > b || e) { - a = a.slice(e, e + b); + b = a.length - e; + if (0 < b) { + if (c && b > c || e) { + a = a.slice(e, e + c); } d && (a = Ta.call(this, a)); } @@ -1817,40 +1855,40 @@ function Ta(a) { if (this.db) { return this.index.get(this.field[0]).db.enrich(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)}; + const b = Array(a.length); + for (let c = 0, e; c < a.length; c++) { + e = a[c], b[c] = {id:e, doc:this.store.get(e)}; } - return c; + return b; } ;function Na(a) { if (!this || this.constructor !== Na) { return new Na(a); } - const c = a.document || a.doc || a; - let b, e; + const b = a.document || a.doc || a; + let c, e; this.G = []; this.field = []; this.K = []; - this.key = (b = c.key || c.id) && hb(b, this.K) || "id"; + this.key = (c = b.key || b.id) && hb(c, this.K) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; this.reg = !this.fastupdate || a.worker || a.db ? e ? new S(e) : new Set() : e ? new R(e) : new Map(); - this.D = (b = c.store || null) && b && !0 !== b && []; - this.store = b && (e ? new R(e) : new Map()); - this.cache = (b = a.cache || null) && new na(b); + this.D = (c = b.store || null) && c && !0 !== c && []; + this.store = c && (e ? new R(e) : new Map()); + this.cache = (c = a.cache || null) && new na(c); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = ib.call(this, a, c); + this.index = ib.call(this, a, b); this.tag = null; - if (b = c.tag) { - if ("string" === typeof b && (b = [b]), b.length) { + if (c = b.tag) { + if ("string" === typeof c && (c = [c]), c.length) { this.tag = new Map(); this.F = []; this.P = []; - for (let d = 0, f, g; d < b.length; d++) { - f = b[d]; + for (let d = 0, f, g; d < c.length; d++) { + f = c[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); @@ -1871,10 +1909,10 @@ function Ta(a) { const d = this; return Promise.all(a).then(function(f) { let g = 0; - for (const h of d.index.entries()) { - const k = h[0]; - let m = h[1]; - m.then && (m = f[g], d.index.set(k, m), g++); + for (const k of d.index.entries()) { + const h = k[0]; + let l = k[1]; + l.then && (l = f[g], d.index.set(h, l), g++); } return d; }); @@ -1888,102 +1926,102 @@ w.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); } - let c = this.field; + let b = this.field; if (this.tag) { for (let f = 0, g; f < this.P.length; f++) { g = this.P[f]; - var b = void 0; - this.index.set(g, b = new V({}, this.reg)); - c === this.field && (c = c.slice(0)); - c.push(g); - b.tag = this.tag.get(g); + var c = void 0; + this.index.set(g, c = new V({}, this.reg)); + b === this.field && (b = b.slice(0)); + b.push(g); + c.tag = this.tag.get(g); } } - b = []; + c = []; const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let f = 0, g, h; f < c.length; f++) { - e.field = h = c[f]; - g = this.index.get(h); - const k = new a.constructor(a.id, e); - k.id = a.id; - b[f] = k.mount(g); + for (let f = 0, g, k; f < b.length; f++) { + e.field = k = b[f]; + g = this.index.get(k); + const h = new a.constructor(a.id, e); + h.id = a.id; + c[f] = h.mount(g); g.document = !0; f ? g.bypass = !0 : g.store = this.store; } const d = this; - return this.db = Promise.all(b).then(function() { + return this.db = Promise.all(c).then(function() { d.db = !0; }); }; -w.commit = async function(a, c) { - const b = []; +w.commit = async function(a, b) { + const c = []; for (const e of this.index.values()) { - b.push(e.commit(a, c)); + c.push(e.commit(a, b)); } - await Promise.all(b); + await Promise.all(c); this.reg.clear(); }; w.destroy = function() { const a = []; - for (const c of this.index.values()) { - a.push(c.destroy()); + for (const b of this.index.values()) { + a.push(b.destroy()); } return Promise.all(a); }; -function ib(a, c) { - const b = new Map(); - let e = c.index || c.field || c; +function ib(a, b) { + const c = new Map(); + let e = b.index || b.field || b; N(e) && (e = [e]); - for (let f = 0, g, h; f < e.length; f++) { + for (let f = 0, g, k; f < e.length; f++) { g = e[f]; - N(g) || (h = g, g = g.field); - h = ba(h) ? Object.assign({}, a, h) : a; + N(g) || (k = g, g = g.field); + k = ba(k) ? Object.assign({}, a, k) : a; if (this.worker) { var d = void 0; - d = (d = h.encoder) && d.encode ? d : new la("string" === typeof d ? wa[d] : d || {}); - d = new La(h, d); - b.set(g, d); + d = (d = k.encoder) && d.encode ? d : new la("string" === typeof d ? wa[d] : d || {}); + d = new La(k, d); + c.set(g, d); } - this.worker || b.set(g, new V(h, this.reg)); - h.custom ? this.G[f] = h.custom : (this.G[f] = hb(g, this.K), h.filter && ("string" === typeof this.G[f] && (this.G[f] = new String(this.G[f])), this.G[f].J = h.filter)); + this.worker || c.set(g, new V(k, this.reg)); + k.custom ? this.G[f] = k.custom : (this.G[f] = hb(g, this.K), k.filter && ("string" === typeof this.G[f] && (this.G[f] = new String(this.G[f])), this.G[f].J = k.filter)); this.field[f] = g; } if (this.D) { - a = c.store; + a = b.store; N(a) && (a = [a]); - for (let f = 0, g, h; f < a.length; f++) { - g = a[f], h = g.field || g, g.custom ? (this.D[f] = g.custom, g.custom.U = h) : (this.D[f] = hb(h, this.K), g.filter && ("string" === typeof this.D[f] && (this.D[f] = new String(this.D[f])), this.D[f].J = g.filter)); + for (let f = 0, g, k; f < a.length; f++) { + g = a[f], k = g.field || g, g.custom ? (this.D[f] = g.custom, g.custom.U = k) : (this.D[f] = hb(k, this.K), g.filter && ("string" === typeof this.D[f] && (this.D[f] = new String(this.D[f])), this.D[f].J = g.filter)); } } - return b; + return c; } -function hb(a, c) { - const b = a.split(":"); +function hb(a, b) { + const c = a.split(":"); let e = 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); + for (let d = 0; d < c.length; d++) { + a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); } - e < b.length && (b.length = e); - return 1 < e ? b : b[0]; + e < c.length && (c.length = e); + return 1 < e ? c : c[0]; } -w.append = function(a, c) { - return this.add(a, c, !0); +w.append = function(a, b) { + return this.add(a, b, !0); }; -w.update = function(a, c) { - return this.remove(a).add(a, c); +w.update = function(a, b) { + return this.remove(a).add(a, b); }; w.remove = function(a) { ba(a) && (a = da(a, this.key)); - for (var c of this.index.values()) { - c.remove(a, !0); + for (var b of this.index.values()) { + b.remove(a, !0); } 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]; + for (let c of this.tag.values()) { + for (let e of c) { + b = e[0]; const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); + -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); } } } @@ -1995,13 +2033,13 @@ w.remove = function(a) { }; w.clear = function() { const a = []; - for (const c of this.index.values()) { - const b = c.clear(); - b.then && a.push(b); + for (const b of this.index.values()) { + const c = b.clear(); + c.then && a.push(c); } if (this.tag) { - for (const c of this.tag.values()) { - c.clear(); + for (const b of this.tag.values()) { + b.clear(); } } this.store && this.store.clear(); @@ -2018,175 +2056,175 @@ w.cleanup = function() { return this; }; w.get = function(a) { - return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) { - return c[0] && c[0].doc || null; + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { + return b[0] && b[0].doc || null; }) : this.store.get(a) || null; }; -w.set = function(a, c) { - "object" === typeof a && (c = a, a = da(c, this.key)); - this.store.set(a, c); +w.set = function(a, b) { + "object" === typeof a && (b = a, a = da(b, this.key)); + this.store.set(a, b); return this; }; w.searchCache = ma; w.export = jb; w.import = kb; Fa(Na.prototype); -function lb(a, c = 0) { - let b = [], e = []; - c && (c = 250000 / c * 5000 | 0); +function lb(a, b = 0) { + let c = [], e = []; + b && (b = 250000 / b * 5000 | 0); for (const d of a.entries()) { - e.push(d), e.length === c && (b.push(e), e = []); - } - e.length && b.push(e); - return b; -} -function mb(a, c) { - c || (c = new Map()); - for (let b = 0, e; b < a.length; b++) { - e = a[b], c.set(e[0], e[1]); + e.push(d), e.length === b && (c.push(e), e = []); } + e.length && c.push(e); return c; } -function nb(a, c = 0) { - let b = [], e = []; - c && (c = 250000 / c * 1000 | 0); - for (const d of a.entries()) { - e.push([d[0], lb(d[1])[0]]), e.length === c && (b.push(e), e = []); +function mb(a, b) { + b || (b = new Map()); + for (let c = 0, e; c < a.length; c++) { + e = a[c], b.set(e[0], e[1]); } - e.length && b.push(e); return b; } -function ob(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], mb(e[1], d)); +function nb(a, b = 0) { + let c = [], e = []; + b && (b = 250000 / b * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], lb(d[1])[0]]), e.length === b && (c.push(e), e = []); } + e.length && c.push(e); return c; } +function ob(a, b) { + b || (b = new Map()); + for (let c = 0, e, d; c < a.length; c++) { + e = a[c], d = b.get(e[0]), b.set(e[0], mb(e[1], d)); + } + return b; +} function pb(a) { - let c = [], b = []; + let b = [], c = []; for (const e of a.keys()) { - b.push(e), 250000 === b.length && (c.push(b), b = []); + c.push(e), 250000 === c.length && (b.push(c), c = []); } - b.length && c.push(b); - return c; + c.length && b.push(c); + return b; } -function qb(a, c) { - c || (c = new Set()); - for (let b = 0; b < a.length; b++) { - c.add(a[b]); +function qb(a, b) { + b || (b = new Set()); + for (let c = 0; c < a.length; c++) { + b.add(a[c]); } - return c; + return b; } -function rb(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { - return this.export(a, c, d, f + 1); +function rb(a, b, c, e, d, f, g = 0) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { + return this.export(a, b, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { - const m = this; - return k.then(function() { - return rb.call(m, a, c, b, h ? e : null, d, f, g + 1); + if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { + const l = this; + return h.then(function() { + return rb.call(l, a, b, c, k ? e : null, d, f, g + 1); }); } - return rb.call(this, a, c, b, h ? e : null, d, f, g + 1); + return rb.call(this, a, b, c, k ? e : null, d, f, g + 1); } -function jb(a, c, b = 0, e = 0) { - if (b < this.field.length) { - const g = this.field[b]; - if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const h = this; - return c.then(function() { - return h.export(a, g, b + 1); +function jb(a, b, c = 0, e = 0) { + if (c < this.field.length) { + const g = this.field[c]; + if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { + const k = this; + return b.then(function() { + return k.export(a, g, c + 1); }); } - return this.export(a, g, b + 1); + return this.export(a, g, c + 1); } let d, f; switch(e) { case 0: d = "reg"; f = pb(this.reg); - c = null; + b = null; break; case 1: d = "tag"; f = this.tag && nb(this.tag, this.reg.size); - c = null; + b = null; break; case 2: d = "doc"; f = this.store && lb(this.store); - c = null; + b = null; break; default: return; } - return rb.call(this, a, c, d, f, b, e); + return rb.call(this, a, b, d, f, c, e); } -function kb(a, c) { - var b = a.split("."); - "json" === b[b.length - 1] && b.pop(); - const e = 2 < b.length ? b[0] : ""; - b = 2 < b.length ? b[2] : b[1]; +function kb(a, b) { + var c = a.split("."); + "json" === c[c.length - 1] && c.pop(); + const e = 2 < c.length ? c[0] : ""; + c = 2 < c.length ? c[2] : c[1]; if (this.worker && e) { return this.index.get(e).import(a); } - if (c) { - "string" === typeof c && (c = JSON.parse(c)); + if (b) { + "string" === typeof b && (b = JSON.parse(b)); if (e) { - return this.index.get(e).import(b, c); + return this.index.get(e).import(c, b); } - switch(b) { + switch(c) { case "reg": this.fastupdate = !1; - this.reg = qb(c, this.reg); + this.reg = qb(b, this.reg); for (let d = 0, f; d < this.field.length; d++) { f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } if (this.worker) { - c = []; + b = []; for (const d of this.index.values()) { - c.push(d.import(a)); + b.push(d.import(a)); } - return Promise.all(c); + return Promise.all(b); } break; case "tag": - this.tag = ob(c, this.tag); + this.tag = ob(b, this.tag); break; case "doc": - this.store = mb(c, this.store); + this.store = mb(b, this.store); } } } -function sb(a, c) { - let b = ""; +function sb(a, b) { + let c = ""; for (const e of a.entries()) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, h; g < d.length; g++) { - h = d[g] || [""]; - let k = ""; - for (let m = 0; m < h.length; m++) { - k += (k ? "," : "") + ("string" === c ? '"' + h[m] + '"' : h[m]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === b ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; - b += (b ? "," : "") + f; + c += (c ? "," : "") + f; } - return b; + return c; } -;V.prototype.remove = function(a, c) { - const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (b) { +;V.prototype.remove = function(a, b) { + const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (c) { if (this.fastupdate) { - for (let e = 0, d, f; e < b.length; e++) { - if ((d = b[e]) && (f = d.length)) { + for (let e = 0, d, f; e < c.length; e++) { + if ((d = c[e]) && (f = d.length)) { if (d[f - 1] === a) { d.pop(); } else { @@ -2198,71 +2236,71 @@ function sb(a, c) { } else { tb(this.map, a), this.depth && tb(this.ctx, a); } - c || this.reg.delete(a); + b || this.reg.delete(a); } this.db && (this.commit_task.push({del:a}), this.S && ub(this)); this.cache && this.cache.remove(a); return this; }; -function tb(a, c) { - let b = 0; - var e = "undefined" === typeof c; +function tb(a, b) { + let c = 0; + var e = "undefined" === typeof b; if (a.constructor === Array) { - for (let d = 0, f, g, h; d < a.length; d++) { + for (let d = 0, f, g, k; d < a.length; d++) { if ((f = a[d]) && f.length) { if (e) { return 1; } - g = f.indexOf(c); + g = f.indexOf(b); if (0 <= g) { if (1 < f.length) { return f.splice(g, 1), 1; } delete a[d]; - if (b) { + if (c) { return 1; } - h = 1; + k = 1; } else { - if (h) { + if (k) { return 1; } - b++; + c++; } } } } else { for (let d of a.entries()) { - e = d[0], tb(d[1], c) ? b++ : a.delete(e); + e = d[0], tb(d[1], b) ? c++ : a.delete(e); } } - return b; + return c; } ;const vb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -V.prototype.add = function(a, c, b, e) { - if (c && (a || 0 === a)) { - if (!e && !b && this.reg.has(a)) { - return this.update(a, c); +V.prototype.add = function(a, b, c, e) { + if (b && (a || 0 === a)) { + if (!e && !c && this.reg.has(a)) { + return this.update(a, b); } e = this.depth; - c = this.encoder.encode(c, !e); - const m = c.length; - if (m) { - const l = I(), n = I(), u = this.resolution; - for (let p = 0; p < m; p++) { - let t = c[this.rtl ? m - 1 - p : p]; - var d = t.length; - if (d && (e || !n[t])) { - var f = this.score ? this.score(c, t, p, null, 0) : wb(u, m, p), g = ""; + b = this.encoder.encode(b, !e); + const l = b.length; + if (l) { + const m = I(), r = I(), t = this.resolution; + for (let q = 0; q < l; q++) { + let u = b[this.rtl ? l - 1 - q : q]; + var d = u.length; + if (d && (e || !r[u])) { + var f = this.score ? this.score(b, u, q, null, 0) : wb(t, l, q), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let r = 0, q; r < d; r++) { - for (f = d; f > r; f--) { - g = t.substring(r, f); - q = this.rtl ? d - 1 - r : r; - var h = this.score ? this.score(c, t, p, g, q) : wb(u, m, p, d, q); - xb(this, n, g, h, a, b); + for (let n = 0, p; n < d; n++) { + for (f = d; f > n; f--) { + g = u.substring(n, f); + p = this.rtl ? d - 1 - n : n; + var k = this.score ? this.score(b, u, q, g, p) : wb(t, l, q, d, p); + xb(this, r, g, k, a, c); } } break; @@ -2270,27 +2308,27 @@ V.prototype.add = function(a, c, b, e) { case "bidirectional": case "reverse": if (1 < d) { - for (h = d - 1; 0 < h; h--) { - g = t[this.rtl ? d - 1 - h : h] + g; - var k = this.score ? this.score(c, t, p, g, h) : wb(u, m, p, d, h); - xb(this, n, g, k, a, b); + for (k = d - 1; 0 < k; k--) { + g = u[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(b, u, q, g, k) : wb(t, l, q, d, k); + xb(this, r, g, h, a, c); } g = ""; } case "forward": if (1 < d) { - for (h = 0; h < d; h++) { - g += t[this.rtl ? d - 1 - h : h], xb(this, n, g, f, a, b); + for (k = 0; k < d; k++) { + g += u[this.rtl ? d - 1 - k : k], xb(this, r, g, f, a, c); } break; } default: - if (xb(this, n, t, f, a, b), e && 1 < m && p < m - 1) { - for (d = I(), g = this.T, f = t, h = Math.min(e + 1, this.rtl ? p + 1 : m - p), d[f] = 1, k = 1; k < h; k++) { - if ((t = c[this.rtl ? m - 1 - p - k : p + k]) && !d[t]) { - d[t] = 1; - const r = this.score ? this.score(c, f, p, t, k - 1) : wb(g + (m / 2 > g ? 0 : 1), m, p, h - 1, k - 1), q = this.bidirectional && t > f; - xb(this, l, q ? f : t, r, a, b, q ? t : f); + if (xb(this, r, u, f, a, c), e && 1 < l && q < l - 1) { + for (d = I(), g = this.T, f = u, k = Math.min(e + 1, this.rtl ? q + 1 : l - q), d[f] = 1, h = 1; h < k; h++) { + if ((u = b[this.rtl ? l - 1 - q - h : q + h]) && !d[u]) { + d[u] = 1; + const n = this.score ? this.score(b, f, q, u, h - 1) : wb(g + (l / 2 > g ? 0 : 1), l, q, k - 1, h - 1), p = this.bidirectional && u > f; + xb(this, m, p ? f : u, n, a, c, p ? u : f); } } } @@ -2299,109 +2337,109 @@ V.prototype.add = function(a, c, b, e) { } this.fastupdate || this.reg.add(a); } else { - c = ""; + b = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.S && ub(this)); + this.db && (b || this.commit_task.push({del:a}), this.S && ub(this)); return this; }; -function xb(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - if (g ? (c = k || (c[b] = I()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = k = []), h = h[e] || (h[e] = []), !f || !h.includes(d)) { - if (h.length === 2 ** 31 - 1) { - c = new Aa(h); +function xb(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] = I()), 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 Aa(k); if (a.fastupdate) { - for (let m of a.reg.values()) { - m.includes(h) && (m[m.indexOf(h)] = c); + for (let l of a.reg.values()) { + l.includes(k) && (l[l.indexOf(k)] = b); } } - k[e] = h = c; + h[e] = k = b; } - h.push(d); - a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h])); + k.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } } -function wb(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 wb(a, b, c, e, d) { + return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; } -;V.prototype.search = function(a, c, b) { - b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); - if (b && b.cache) { - return b.cache = !1, a = this.searchCache(a, c, b), b.cache = !0, a; +;V.prototype.search = function(a, b, c) { + c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); + if (c && c.cache) { + return c.cache = !1, a = this.searchCache(a, b, c), c.cache = !0, a; } - let e = [], d, f, g, h = 0, k, m, l, n, u; - b && (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, u = (k = b.resolve) && b.enrich, l = b.boost, n = b.resolution, m = this.db && b.tag); - "undefined" === typeof k && (k = this.resolve); + let e = [], d, f, g, k = 0, h, l, m, r, t; + c && (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, t = (h = c.resolve) && c.enrich, m = c.boost, r = c.resolution, l = this.db && c.tag); + "undefined" === typeof h && (h = this.resolve); f = this.depth && !1 !== f; - let p = this.encoder.encode(a, !f); - d = p.length; - c = c || (k ? 100 : 0); + let q = this.encoder.encode(a, !f); + d = q.length; + b = b || (h ? 100 : 0); if (1 === d) { - return yb.call(this, p[0], "", c, h, k, u, m); + return yb.call(this, q[0], "", b, k, h, t, l); } if (2 === d && f && !g) { - return yb.call(this, p[1], p[0], c, h, k, u, m); + return yb.call(this, q[1], q[0], b, k, h, t, l); } - let t = I(), r = 0, q; - f && (q = p[0], r = 1); - n || 0 === n || (n = q ? this.T : this.resolution); + let u = I(), n = 0, p; + f && (p = q[0], n = 1); + r || 0 === r || (r = p ? this.T : this.resolution); if (this.db) { - if (this.db.search && (b = this.db.search(this, p, c, h, g, k, u, m), !1 !== b)) { - return b; + if (this.db.search && (c = this.db.search(this, q, b, k, g, h, t, l), !1 !== c)) { + return c; } const y = this; return async function() { - for (let v, A; r < d; r++) { - if ((A = p[r]) && !t[A]) { - t[A] = 1; - v = await zb(y, A, q, 0, 0, !1, !1); - if (v = Ab(v, e, g, n)) { + for (let v, D; n < d; n++) { + if ((D = q[n]) && !u[D]) { + u[D] = 1; + v = await zb(y, D, p, 0, 0, !1, !1); + if (v = Ab(v, e, g, r)) { e = v; break; } - q && (g && v && e.length || (q = A)); + p && (g && v && e.length || (p = D)); } - g && q && r === d - 1 && !e.length && (n = y.resolution, q = "", r = -1, t = I()); + g && p && n === d - 1 && !e.length && (r = y.resolution, p = "", n = -1, u = I()); } - return Bb(e, n, c, h, g, l, k); + return Bb(e, r, b, k, g, m, h); }(); } - for (let y, v; r < d; r++) { - if ((v = p[r]) && !t[v]) { - t[v] = 1; - y = zb(this, v, q, 0, 0, !1, !1); - if (y = Ab(y, e, g, n)) { + for (let y, v; n < d; n++) { + if ((v = q[n]) && !u[v]) { + u[v] = 1; + y = zb(this, v, p, 0, 0, !1, !1); + if (y = Ab(y, e, g, r)) { e = y; break; } - q && (g && y && e.length || (q = v)); + p && (g && y && e.length || (p = v)); } - g && q && r === d - 1 && !e.length && (n = this.resolution, q = "", r = -1, t = I()); + g && p && n === d - 1 && !e.length && (r = this.resolution, p = "", n = -1, u = I()); } - return Bb(e, n, c, h, g, l, k); + return Bb(e, r, b, k, g, m, h); }; -function Bb(a, c, b, e, d, f, g) { - let h = a.length, k = a; - if (1 < h) { - k = $a(a, c, b, e, d, f, g); - } else if (1 === h) { - return g ? Sa.call(null, a[0], b, e) : new Y(a[0], this); +function Bb(a, b, c, e, d, f, g) { + let k = a.length, h = a; + if (1 < k) { + h = $a(a, b, c, e, d, f, g); + } else if (1 === k) { + return g ? Sa.call(null, a[0], c, e) : new Y(a[0], this); } - return g ? k : new Y(k, this); + return g ? h : new Y(h, this); } -function yb(a, c, b, e, d, f, g) { - a = zb(this, a, c, b, e, d, f, g); - return this.db ? a.then(function(h) { - return d ? h || [] : new Y(h, this); - }) : a && a.length ? d ? Sa.call(this, a, b, e) : new Y(a, this) : d ? [] : new Y([], this); +function yb(a, b, c, e, d, f, g) { + a = zb(this, a, b, c, e, d, f, g); + return this.db ? a.then(function(k) { + return d ? k || [] : new Y(k, this); + }) : a && a.length ? d ? Sa.call(this, a, c, e) : new Y(a, this) : d ? [] : new Y([], this); } -function Ab(a, c, b, e) { +function Ab(a, b, c, e) { let d = []; if (a && a.length) { if (a.length <= e) { - c.push(a); + b.push(a); return; } for (let f = 0, g; f < e; f++) { @@ -2410,53 +2448,53 @@ function Ab(a, c, b, e) { } } if (d.length) { - c.push(d); + b.push(d); return; } } - if (!b) { + if (!c) { return d; } } -function zb(a, c, b, e, d, f, g, h) { - let k; - b && (k = a.bidirectional && c > b) && (k = b, b = c, c = k); +function zb(a, b, c, e, d, f, g, k) { + let h; + c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); if (a.db) { - return a.db.get(c, b, e, d, f, g, h); + return a.db.get(b, c, e, d, f, g, k); } - a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); + a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;function V(a, c) { +;function V(a, b) { if (!this || this.constructor !== V) { return new V(a); } if (a) { - var b = N(a) ? a : a.preset; - b && (vb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, vb[b], a)); + var c = N(a) ? a : a.preset; + c && (vb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, vb[c], a)); } else { a = {}; } - b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = N(a.encoder) ? wa[a.encoder] : a.encode || a.encoder || {}; + c = a.context; + const e = !0 === c ? {depth:1} : c || {}, d = N(a.encoder) ? wa[a.encoder] : a.encode || a.encoder || {}; this.encoder = d.encode ? d : "object" === typeof d ? new la(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.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; e && e.depth && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); - (b = a.keystore || 0) && (this.keystore = b); - this.map = b ? new R(b) : new Map(); - this.ctx = b ? new R(b) : new Map(); - this.reg = c || (this.fastupdate ? b ? new R(b) : new Map() : b ? new S(b) : new Set()); + (c = a.keystore || 0) && (this.keystore = c); + this.map = c ? new R(c) : new Map(); + this.ctx = c ? new R(c) : new Map(); + this.reg = b || (this.fastupdate ? c ? new R(c) : new Map() : c ? new S(c) : new Set()); this.T = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new na(b); + this.cache = (c = a.cache || null) && new na(c); this.resolve = !1 !== a.resolve; - if (b = a.db) { - this.db = this.mount(b); + if (c = a.db) { + this.db = this.mount(c); } this.S = !1 !== a.commit; this.commit_task = []; @@ -2468,9 +2506,9 @@ w.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -w.commit = function(a, c) { +w.commit = function(a, b) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, c); + return this.db.commit(this, a, b); }; w.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); @@ -2487,18 +2525,17 @@ w.clear = function() { 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; + return this.db ? (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [], this.db.clear()) : this; }; -w.append = function(a, c) { - return this.add(a, c, !0); +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, c) { - const b = this, e = this.remove(a); - return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); +w.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); }; w.cleanup = function() { if (!this.fastupdate) { @@ -2509,7 +2546,7 @@ w.cleanup = function() { return this; }; w.searchCache = ma; -w.export = function(a, c, b = 0, e = 0) { +w.export = function(a, b, c = 0, e = 0) { let d, f; switch(e) { case 0: @@ -2531,55 +2568,55 @@ w.export = function(a, c, b = 0, e = 0) { default: return; } - return rb.call(this, a, c, d, f, b, e); + return rb.call(this, a, b, d, f, c, e); }; -w.import = function(a, c) { - if (c) { - switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { +w.import = function(a, b) { + if (b) { + switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = qb(c, this.reg); + this.reg = qb(b, this.reg); break; case "map": - this.map = mb(c, this.map); + this.map = mb(b, this.map); break; case "ctx": - this.ctx = ob(c, this.ctx); + this.ctx = ob(b, this.ctx); } } }; w.serialize = function(a = !0) { - let c = "", b = "", e = ""; + let b = "", c = "", e = ""; if (this.reg.size) { let f; for (var d of this.reg.keys()) { - f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); + f || (f = typeof d), b += (b ? "," : "") + ("string" === f ? '"' + d + '"' : d); } - c = "index.reg=new Set([" + c + "]);"; - b = sb(this.map, f); - b = "index.map=new Map([" + b + "]);"; + b = "index.reg=new Set([" + b + "]);"; + c = sb(this.map, f); + c = "index.map=new Map([" + c + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let h = sb(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + d + '",' + h + "]"; - e += (e ? "," : "") + h; + let k = sb(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } - return a ? "function inject(index){" + c + b + e + "}" : c + b + e; + return a ? "function inject(index){" + b + c + e + "}" : b + c + e; }; Fa(V.prototype); const Cb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Db = ["map", "ctx", "tag", "reg", "cfg"], Eb = I(); -function Fb(a, c = {}) { +function Fb(a, b = {}) { if (!this || this.constructor !== Fb) { - return new Fb(a, c); + return new Fb(a, b); } - "object" === typeof a && (c = a, a = a.name); + "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); this.id = "flexsearch" + (a ? ":" + a.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""); - this.field = c.field ? c.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.type = c.type; + this.field = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; + this.type = b.type; this.fastupdate = this.support_tag_search = !1; this.db = null; this.h = {}; @@ -2600,18 +2637,18 @@ w.open = function() { navigator.storage && navigator.storage.persist(); Eb[a.id] || (Eb[a.id] = []); Eb[a.id].push(a.field); - const c = Cb.open(a.id, 1); - c.onupgradeneeded = function() { - const b = a.db = this.result; + const b = Cb.open(a.id, 1); + b.onupgradeneeded = function() { + const c = a.db = this.result; for (let e = 0, d; e < Db.length; e++) { d = Db[e]; for (let f = 0, g; f < Eb[a.id].length; f++) { - g = Eb[a.id][f], b.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || b.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); + g = Eb[a.id][f], c.objectStoreNames.contains(d + ("reg" !== d ? g ? ":" + g : "" : "")) || c.createObjectStore(d + ("reg" !== d ? g ? ":" + g : "" : "")); } } }; - return a.db = Z(c, function(b) { - a.db = b; + return a.db = Z(b, function(c) { + a.db = c; a.db.onversionchange = function() { a.close(); }; @@ -2627,72 +2664,72 @@ w.destroy = function() { }; w.clear = function() { const a = []; - for (let b = 0, e; b < Db.length; b++) { - e = Db[b]; + for (let c = 0, e; c < Db.length; c++) { + e = Db[c]; for (let d = 0, f; d < Eb[this.id].length; d++) { f = Eb[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); } } - const c = this.db.transaction(a, "readwrite"); - for (let b = 0; b < a.length; b++) { - c.objectStore(a[b]).clear(); + const b = this.db.transaction(a, "readwrite"); + for (let c = 0; c < a.length; c++) { + b.objectStore(a[c]).clear(); } - return Z(c); + return Z(b); }; -w.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { - a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); +w.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { + a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); const g = this; - return Z(a).then(function(h) { - let k = []; - if (!h || !h.length) { - return k; + return Z(a).then(function(k) { + let h = []; + if (!k || !k.length) { + return h; } if (d) { - if (!b && !e && 1 === h.length) { - return h[0]; + if (!c && !e && 1 === k.length) { + return k[0]; } - for (let m = 0, l; m < h.length; m++) { - if ((l = h[m]) && l.length) { - if (e >= l.length) { - e -= l.length; + for (let l = 0, m; l < k.length; l++) { + if ((m = k[l]) && m.length) { + if (e >= m.length) { + e -= m.length; continue; } - const n = b ? e + Math.min(l.length - e, b) : l.length; - for (let u = e; u < n; u++) { - k.push(l[u]); + const r = c ? e + Math.min(m.length - e, c) : m.length; + for (let t = e; t < r; t++) { + h.push(m[t]); } e = 0; - if (k.length === b) { + if (h.length === c) { break; } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; -w.tag = function(a, c = 0, b = 0, e = !1) { +w.tag = function(a, b = 0, c = 0, e = !1) { a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); const d = this; return Z(a).then(function(f) { - if (!f || !f.length || b >= f.length) { + if (!f || !f.length || c >= f.length) { return []; } - if (!c && !b) { + if (!b && !c) { return f; } - f = f.slice(b, b + c); + f = f.slice(c, c + b); return e ? d.enrich(f) : f; }); }; w.enrich = function(a) { "object" !== typeof a && (a = [a]); - const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = []; + const b = this.db.transaction("reg", "readonly").objectStore("reg"), c = []; for (let e = 0; e < a.length; e++) { - b[e] = Z(c.get(a[e])); + c[e] = Z(b.get(a[e])); } - return Promise.all(b).then(function(e) { + return Promise.all(c).then(function(e) { for (let d = 0; d < e.length; d++) { e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null}; } @@ -2701,30 +2738,30 @@ w.enrich = function(a) { }; w.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Z(a).then(function(c) { - return !!c; + return Z(a).then(function(b) { + return !!b; }); }; w.search = null; w.info = function() { }; -w.transaction = function(a, c, b) { +w.transaction = function(a, b, c) { a += "reg" !== a ? this.field ? ":" + this.field : "" : ""; - let e = this.h[a + ":" + c]; + let e = this.h[a + ":" + b]; if (e) { - return b.call(this, e); + return c.call(this, e); } - let d = this.db.transaction(a, c); - this.h[a + ":" + c] = e = d.objectStore(a); - const f = b.call(this, e); - this.h[a + ":" + c] = null; + let d = this.db.transaction(a, b); + this.h[a + ":" + b] = e = d.objectStore(a); + const f = c.call(this, e); + this.h[a + ":" + b] = null; return Z(d).finally(function() { d = e = null; return f; }); }; -w.commit = async function(a, c, b) { - if (c) { +w.commit = async function(a, b, c) { + if (b) { await this.clear(), a.commit_task = []; } else { let e = a.commit_task; @@ -2732,66 +2769,66 @@ w.commit = async function(a, c, b) { for (let d = 0, f; d < e.length; d++) { if (f = e[d], f.clear) { await this.clear(); - c = !0; + b = !0; break; } else { e[d] = f.del; } } - c || (b || (e = e.concat(ca(a.reg))), e.length && await this.remove(e)); + b || (c || (e = e.concat(ca(a.reg))), e.length && await this.remove(e)); } a.reg.size && (await this.transaction("map", "readwrite", function(e) { for (const d of a.map) { const f = d[0], g = d[1]; - g.length && (c ? e.put(g, f) : e.get(f).onsuccess = function() { - let h = this.result; - var k; - if (h && h.length) { - const m = Math.max(h.length, g.length); - for (let l = 0, n, u; l < m; l++) { - if ((u = g[l]) && u.length) { - if ((n = h[l]) && n.length) { - for (k = 0; k < u.length; k++) { - n.push(u[k]); + g.length && (b ? e.put(g, f) : e.get(f).onsuccess = function() { + let k = this.result; + var h; + if (k && k.length) { + const l = Math.max(k.length, g.length); + for (let m = 0, r, t; m < l; m++) { + if ((t = g[m]) && t.length) { + if ((r = k[m]) && r.length) { + for (h = 0; h < t.length; h++) { + r.push(t[h]); } } else { - h[l] = u; + k[m] = t; } - k = 1; + h = 1; } } } else { - h = g, k = 1; + k = g, h = 1; } - k && e.put(h, f); + h && e.put(k, f); }); } }), await this.transaction("ctx", "readwrite", function(e) { for (const d of a.ctx) { const f = d[0], g = d[1]; - for (const h of g) { - const k = h[0], m = h[1]; - m.length && (c ? e.put(m, f + ":" + k) : e.get(f + ":" + k).onsuccess = function() { - let l = this.result; - var n; - if (l && l.length) { - const u = Math.max(l.length, m.length); - for (let p = 0, t, r; p < u; p++) { - if ((r = m[p]) && r.length) { - if ((t = l[p]) && t.length) { - for (n = 0; n < r.length; n++) { - t.push(r[n]); + for (const k of g) { + const h = k[0], l = k[1]; + l.length && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { + let m = this.result; + var r; + if (m && m.length) { + const t = Math.max(m.length, l.length); + for (let q = 0, u, n; q < t; q++) { + if ((n = l[q]) && n.length) { + if ((u = m[q]) && u.length) { + for (r = 0; r < n.length; r++) { + u.push(n[r]); } } else { - l[p] = r; + m[q] = n; } - n = 1; + r = 1; } } } else { - l = m, n = 1; + m = l, r = 1; } - n && e.put(l, f + ":" + k); + r && e.put(m, f + ":" + h); }); } } @@ -2808,31 +2845,31 @@ w.commit = async function(a, c, b) { for (const d of a.tag) { const f = d[0], g = d[1]; g.length && (e.get(f).onsuccess = function() { - let h = this.result; - h = h && h.length ? h.concat(g) : g; - e.put(h, f); + let k = this.result; + k = k && k.length ? k.concat(g) : g; + e.put(k, f); }); } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function Gb(a, c, b) { +function Gb(a, b, c) { const e = a.value; let d, f = 0; - for (let g = 0, h; g < e.length; g++) { - if (h = b ? e : e[g]) { - for (let k = 0, m, l; k < c.length; k++) { - if (l = c[k], m = h.indexOf(l), 0 <= m) { - if (d = 1, 1 < h.length) { - h.splice(m, 1); + for (let g = 0, k; g < e.length; g++) { + if (k = c ? e : e[g]) { + for (let h = 0, l, m; h < b.length; h++) { + if (m = b[h], l = k.indexOf(m), 0 <= l) { + if (d = 1, 1 < k.length) { + k.splice(l, 1); } else { e[g] = []; break; } } } - f += h.length; + f += k.length; } - if (b) { + if (c) { break; } } @@ -2841,33 +2878,33 @@ function Gb(a, c, b) { } w.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map", "readwrite", function(c) { - c.openCursor().onsuccess = function() { - const b = this.result; - b && Gb(b, a); + return Promise.all([this.transaction("map", "readwrite", function(b) { + b.openCursor().onsuccess = function() { + const c = this.result; + c && Gb(c, a); }; - }), this.transaction("ctx", "readwrite", function(c) { - c.openCursor().onsuccess = function() { - const b = this.result; - b && Gb(b, a); + }), this.transaction("ctx", "readwrite", function(b) { + b.openCursor().onsuccess = function() { + const c = this.result; + c && Gb(c, a); }; - }), this.transaction("tag", "readwrite", function(c) { - c.openCursor().onsuccess = function() { - const b = this.result; - b && Gb(b, a, !0); + }), this.transaction("tag", "readwrite", function(b) { + b.openCursor().onsuccess = function() { + const c = this.result; + c && Gb(c, a, !0); }; - }), this.transaction("reg", "readwrite", function(c) { - for (let b = 0; b < a.length; b++) { - c.delete(a[b]); + }), this.transaction("reg", "readwrite", function(b) { + for (let c = 0; c < a.length; c++) { + b.delete(a[c]); } })]); }; -function Z(a, c) { - return new Promise((b, e) => { +function Z(a, b) { + return new Promise((c, e) => { a.onsuccess = a.oncomplete = function() { - c && c(this.result); - c = null; - b(this.result); + b && b(this.result); + b = null; + c(this.result); }; a.onerror = a.onblocked = e; a = null; diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 5c1e7a7..bb7cb8f 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,106 +1,108 @@ /**! - * FlexSearch.js v0.8.201 (Bundle/Module) + * FlexSearch.js v0.8.202 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var w;function H(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function aa(a,c){return"undefined"===typeof a?c:a}function I(){return Object.create(null)} -function M(a){return"string"===typeof a}function ba(a){return"object"===typeof a}function ca(a){const c=[];for(const b of a.keys())c.push(b);return c}function ea(a,c){if(M(c))a=a[c];else for(let b=0;a&&b"a1a".split(b).length; -this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,fa)}catch(d){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);b=a.filter;this.filter="function"===typeof b?b:H(b&&new Set(b),null,this.filter);this.dedupe=H(a.dedupe,!0,this.dedupe);this.matcher=H((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=H((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=H((b=a.stemmer)&&new Map(b), -null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,1024,this.maxlength);this.rtl=H(a.rtl,!1,this.rtl);if(this.cache=b=H(a.cache,!0,this.cache))this.I=null,this.R="number"===typeof b?b:2E5,this.B=new Map,this.H=new Map,this.M=this.L=128;this.h="";this.N=null;this.A="";this.O=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= -(this.A?"|":"")+d;return this};w.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.A+=(this.A?"|":"")+a;this.O=null;this.cache&&Q(this);return this};w.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&Q(this);return this}; -w.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.N=null;this.cache&&Q(this);return this}; -w.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&Q(this);return this}; -w.encode=function(a,c){if(this.cache&&a.length<=this.L)if(this.I){if(this.B.has(a))return this.B.get(a)}else this.I=setTimeout(Q,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ka?a.normalize("NFKD").replace(ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(c){if(d[l])continue;d[l]=1}else{if(f===l)continue;f=l}if(b)e.push(l);else if(!this.filter||("function"===typeof this.filter?this.filter(l):!this.filter.has(l))){if(this.cache&&l.length<=this.M)if(this.I){var k=this.H.get(l);if(k||""===k){k&&e.push(k);continue}}else this.I=setTimeout(Q,50,this);if(this.stemmer){this.O||(this.O=new RegExp("(?!^)("+ -this.A+")$"));let u;for(;u!==l&&2this.stemmer.get(p))}if(l&&(this.mapper||this.dedupe&&1this.matcher.get(u)));if(l&&this.replacer)for(k=0;l&&kthis.R&&(this.H.clear(),this.M=this.M/1.1|0));if(l){if(l!==n)if(c){if(d[l])continue;d[l]=1}else{if(g===l)continue;g=l}e.push(l)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.L&&(this.B.set(a,e),this.B.size>this.R&&(this.B.clear(),this.L=this.L/1.1|0));return e};function Q(a){a.I=null;a.B.clear();a.H.clear()};function ma(a,c,b){b||(c||"object"!==typeof a?"object"===typeof c&&(b=c,c=0):b=a);b&&(a=b.query||a,c=b.limit||c);let e=""+(c||0);b&&(e+=(b.offset||0)+!!b.context+!!b.suggest+(!1!==b.resolve)+(b.resolution||this.resolution)+(b.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new R);let d=this.cache.get(a+e);if(!d){const f=b&&b.cache;f&&(b.cache=!1);d=this.search(a,c,b);f&&(b.cache=f);this.cache.set(a+e,d)}return d}function R(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""} -R.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};R.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};R.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};R.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:!1,numeric:!1,dedupe:!1};const qa={};const ra=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 sa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ta=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ua={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 va={Exact:na,Default:qa,Normalize:qa,LatinBalance:{mapper:ra},LatinAdvanced:{mapper:ra,matcher:sa,replacer:ta},LatinExtra:{mapper:ra,replacer:ta.concat([/(?!^)[aeo]/g,""]),matcher:sa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;b=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const h=c.length;if(h&&(d=d.length?d.concat(c):c,b-=h,e&&(a.length-=h),!b))break;c=0}return d} -function za(a){if(!this||this.constructor!==za)return new za(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;g=this.priority*this.priority*3):(Ha=setTimeout(Ka,0),Ia=Date.now());if(Ja){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let W=0; -function La(a={},c){function b(h){function k(m){m=m.data||m;const l=m.id,n=l&&f.h[l];n&&(n(m.msg),delete f.h[l])}this.worker=h;this.h=I();if(this.worker){d?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(m){1E9c?a.slice(b,b+c):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}g=g.slice(b,b+c);h=g.length;b=0}h>c&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?Ta.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ya(a,c,b,!1,this.h),b=0));d&&(this.await=null);return d?this.resolve(c,b,e):this};Y.prototype.and=function(){return Ua(this,"and",Za,arguments)};function Za(a,c,b,e,d,f){if(!f&&!this.result.length)return d?this.result:this;let g;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{let h=0;for(let k=0,m,l;ka.length)this.result=a[0];else{a:{f=b;var g=this.h;const h=[],k=I();let m=0;for(let l=0,n;lb||e?k.slice(e,b+e):k;else{if(ab||e)k=k.slice(e,b+ -e)}else{d=[];for(let n=0,u;ne)e-=u.length;else{if(b&&u.length>b||e)u=u.slice(e,b+e),b-=u.length,e&&(e-=u.length);d.push(u);if(!b)break}k=d}}return k} -function Ya(a,c,b,e,d){const f=[],g=I();let h;var k=a.length;let m;if(e)for(d=k-1;0<=d;d--){if(m=(e=a[d])&&e.length)for(k=0;kA&&(A=q.length+(q?1:0)),B=q.length+(q?1:0)+G.length,E+=D,ya.push(v.length),v.push({match:G})),q+=(q?" ":"")+G)}if(!x)F=y[C],q+=(q?" ":"")+F,k&&v.push({text:F});else if(k&&E>=k)break}E=ya.length*(f.length-2);if(p||t||k&&q.length-E>k)if(E=k+E-2*u,C=B-A,0y&&(y=0)),v=v.length-1){if(J>= -v.length){C[x+1]=1;J>=y.length&&(E[x+1]=1);continue}D-=u}q=v[J].text;if(L=t&&z[x])if(0L)if(C[x+1]=1,m)q=q.substring(0,L);else continue;(L-=q.length)||(L=-1);z[x]=L}else{C[x+1]=1;continue}if(D+q.length+1<=k)q=" "+q,B[x]+=q;else if(m)U=k-D-1,0=J){if(0>J){C[x]=1;E[x]=1;continue}D-=u}q=v[J].text;if(L=p&&F[x])if(0L)if(C[x]=1,m)q=q.substring(q.length- -L);else continue;(L-=q.length)||(L=-1);F[x]=L}else{C[x]=1;continue}if(D+q.length+1<=k)q+=" ",B[x]=q+B[x];else if(m)U=q.length+1-(k-D),0<=U&&U=y.length-1?Pa=1:Jb||e)a=a.slice(e,e+b);d&&(a=Ta.call(this,a))}return a} -function Ta(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);const c=Array(a.length);for(let b=0,e;br;f--){g=t.substring(r,f);q=this.rtl?d-1-r:r;var h=this.score?this.score(c,t,p,g,q):wb(u, -m,p,d,q);xb(this,n,g,h,a,b)}break}case "bidirectional":case "reverse":if(1g?0:1),m,p,h-1,k-1),q=this.bidirectional&&t>f;xb(this,l,q?f:t,r,a,b,q?t:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.S&&ub(this));return this}; -function xb(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])if(g?(c=k||(c[b]=I()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){c=new za(h);if(a.fastupdate)for(let m of a.reg.values())m.includes(h)&&(m[m.indexOf(h)]=c);k[e]=h=c}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function wb(a,c,b,e,d){return b&&1b)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function V(a,c){if(!this||this.constructor!==V)return new V(a);if(a){var b=M(a)?a:a.preset;b&&(a=Object.assign({},vb[b],a))}else a={};b=a.context;const e=!0===b?{depth:1}:b||{},d=M(a.encoder)?va[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new la(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&"default"!==b&&"exact"!==b&&b||"strict";this.depth="strict"===b&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;(b=a.keystore||0)&&(this.keystore=b);this.map=b?new S(b):new Map;this.ctx=b?new S(b):new Map;this.reg=c||(this.fastupdate?b?new S(b):new Map:b?new T(b):new Set);this.T=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(b=a.cache||null)&&new R(b);this.resolve=!1!==a.resolve;if(b=a.db)this.db=this.mount(b);this.S=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=V.prototype; -w.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};w.commit=function(a,c){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,c)};w.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function ub(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,c){return this.add(a,c,!0)};w.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};w.update=function(a,c){const b=this,e=this.remove(a);return e&&e.then?e.then(()=>b.add(a,c)):this.add(a,c)}; -w.cleanup=function(){if(!this.fastupdate)return this;tb(this.map);this.depth&&tb(this.ctx);return this};w.searchCache=ma;w.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=pb(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=lb(this.map,this.reg.size);break;case 3:d="ctx";f=nb(this.ctx,this.reg.size);break;default:return}return rb.call(this,a,c,d,f,b,e)}; -w.import=function(a,c){if(c)switch("string"===typeof c&&(c=JSON.parse(c)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=l.length){e-=l.length;continue}const n=b?e+Math.min(l.length-e,b):l.length;for(let u=e;u=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; -w.enrich=function(a){"object"!==typeof a&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:V,Charset:va,Encoder:la,Document:Na,Worker:La,Resolver:Y,IndexedDB:Fb,Language:{}}; +var w;function H(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function aa(a,b){return"undefined"===typeof a?b:a}function I(){return Object.create(null)} +function M(a){return"string"===typeof a}function ba(a){return"object"===typeof a}function ca(a){const b=[];for(const c of a.keys())b.push(c);return b}function ea(a,b){if(M(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; +this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,fa)}catch(d){this.split=/\s+/}this.numeric=H(a.numeric,H(this.numeric,!0))}this.prepare=H(a.prepare,null,this.prepare);this.finalize=H(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:H(c&&new Set(c),null,this.filter);this.dedupe=H(a.dedupe,!0,this.dedupe);this.matcher=H((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=H((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=H((c=a.stemmer)&&new Map(c), +null,this.stemmer);this.replacer=H(a.replacer,null,this.replacer);this.minlength=H(a.minlength,1,this.minlength);this.maxlength=H(a.maxlength,1024,this.maxlength);this.rtl=H(a.rtl,!1,this.rtl);if(this.cache=c=H(a.cache,!0,this.cache))this.I=null,this.R="number"===typeof c?c:2E5,this.C=new Map,this.H=new Map,this.M=this.L=128;this.h="";this.N=null;this.B="";this.O=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.B+= +(this.B?"|":"")+d;return this};w.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.B+=(this.B?"|":"")+a;this.O=null;this.cache&&Q(this);return this};w.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&Q(this);return this}; +w.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.N=null;this.cache&&Q(this);return this}; +w.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&Q(this);return this}; +w.encode=function(a,b){if(this.cache&&a.length<=this.L)if(this.I){if(this.C.has(a))return this.C.get(a)}else this.I=setTimeout(Q,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ka?a.normalize("NFKD").replace(ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(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.M)if(this.I){var k=this.H.get(m);if(k||""===k){k&&e.push(k);continue}}else this.I=setTimeout(Q,50,this);if(this.stemmer){this.O||(this.O=new RegExp("(?!^)("+ +this.B+")$"));let t;for(;t!==m&&2this.stemmer.get(r))}if(m&&(this.mapper||this.dedupe&&1this.matcher.get(t)));if(m&&this.replacer)for(k=0;m&&kthis.R&&(this.H.clear(),this.M=this.M/1.1|0));if(m){if(m!==q)if(b){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.L&&(this.C.set(a,e),this.C.size>this.R&&(this.C.clear(),this.L=this.L/1.1|0));return e};function Q(a){a.I=null;a.C.clear();a.H.clear()};function ma(a,b,c){c||(b||"object"!==typeof a?"object"===typeof b&&(c=b,b=0):c=a);c&&(a=c.query||a,b=c.limit||b);let e=""+(b||0);c&&(e+=(c.offset||0)+!!c.context+!!c.suggest+(!1!==c.resolve)+(c.resolution||this.resolution)+(c.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new R);let d=this.cache.get(a+e);if(!d){const f=c&&c.cache;f&&(c.cache=!1);d=this.search(a,b,c);f&&(c.cache=f);this.cache.set(a+e,d)}return d}function R(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""} +R.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};R.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};R.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};R.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:!1,numeric:!1,dedupe:!1};const qa={};const ra=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 sa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ta=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ua={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 va={Exact:na,Default:qa,Normalize:qa,LatinBalance:{mapper:ra},LatinAdvanced:{mapper:ra,matcher:sa,replacer:ta},LatinExtra:{mapper:ra,replacer:ta.concat([/(?!^)[aeo]/g,""]),matcher:sa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const h=b.length;if(h&&(d=d.length?d.concat(b):b,c-=h,e&&(a.length-=h),!c))break;b=0}return d} +function xa(a){if(!this||this.constructor!==xa)return new xa(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;g=this.priority*this.priority*3):(Ha=setTimeout(Ka,0),Ia=Date.now());if(Ja){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 W=0; +function La(a={},b){function c(h){function k(l){l=l.data||l;const m=l.id,q=m&&f.h[m];q&&(q(l.msg),delete f.h[m])}this.worker=h;this.h=I();if(this.worker){d?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(l){1E9b?a.slice(c,c+b):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}g=g.slice(c,c+b);h=g.length;c=0}h>b&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?Ta.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ya(a,b,c,!1,this.h),c=0));d&&(this.await=null);return d?this.resolve(b,c,e,g):this};Y.prototype.and=function(){return Ua(this,"and",Za,arguments)};function Za(a,b,c,e,d,f,g){if(!f&&!this.result.length)return d?this.result:this;let h;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{let k=0;for(let l=0,m,q;la.length)this.result=a[0];else{a:{f=c;var h=this.h;const k=[],l=I();let m=0;for(let q=0,t;qD&&(D=n.length+(n?1:0)),B=n.length+(n?1:0)+F.length,G+=C,za.push(v.length),v.push({match:F})),n+=(n?" ":"")+F)}if(!x)E=y[A],n+=(n?" ":"")+E,k&&v.push({text:E});else if(k&&G>=k)break}G=za.length*(f.length-2);if(r||u||k&&n.length-G>k)if(G=k+G-2*t,A=B-D,0y&&(y=0)),v=v.length-1){if(J>= +v.length){A[x+1]=1;J>=y.length&&(G[x+1]=1);continue}C-=t}n=v[J].text;if(L=u&&z[x])if(0L)if(A[x+1]=1,l)n=n.substring(0,L);else continue;(L-=n.length)||(L=-1);z[x]=L}else{A[x+1]=1;continue}if(C+n.length+1<=k)n=" "+n,B[x]+=n;else if(l)U=k-C-1,0=J){if(0>J){A[x]=1;G[x]=1;continue}C-=t}n=v[J].text;if(L=r&&E[x])if(0L)if(A[x]=1,l)n=n.substring(n.length- +L);else continue;(L-=n.length)||(L=-1);E[x]=L}else{A[x]=1;continue}if(C+n.length+1<=k)n+=" ",B[x]=n+B[x];else if(l)U=n.length+1-(k-C),0<=U&&U=y.length-1?Pa=1:Jc||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+ +e)}else{d=[];for(let q=0,t;qe)e-=t.length;else{if(c&&t.length>c||e)t=t.slice(e,c+e),c-=t.length,e&&(e-=t.length);d.push(t);if(!c)break}k=d}}return k} +function Ya(a,b,c,e,d){const f=[],g=I();let h;var k=a.length;let l;if(e)for(d=k-1;0<=d;d--){if(l=(e=a[d])&&e.length)for(k=0;kc||e)a=a.slice(e,e+c);d&&(a=Ta.call(this,a))}return a} +function Ta(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);const b=Array(a.length);for(let c=0,e;cp;f--){g=u.substring(p,f);n=this.rtl?d-1-p:p;var h=this.score?this.score(b,u,r,g,n):wb(t, +l,r,d,n);xb(this,q,g,h,a,c)}break}case "bidirectional":case "reverse":if(1g?0:1),l,r,h-1,k-1),n=this.bidirectional&&u>f;xb(this,m,n?f:u,p,a,c,n?u:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.S&&ub(this));return this}; +function xb(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=I()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new xa(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[e]=h=b}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} +function wb(a,b,c,e,d){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,e,d,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function V(a,b){if(!this||this.constructor!==V)return new V(a);if(a){var c=M(a)?a:a.preset;c&&(a=Object.assign({},vb[c],a))}else a={};c=a.context;const e=!0===c?{depth:1}:c||{},d=M(a.encoder)?va[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:"object"===typeof d?new la(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict";this.depth="strict"===c&&e.depth||0;this.bidirectional=!1!==e.bidirectional;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new S(c):new Map;this.ctx=c?new S(c):new Map;this.reg=b||(this.fastupdate?c?new S(c):new Map:c?new T(c):new Set);this.T=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new R(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.S=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=V.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 ub(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();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):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){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; +w.cleanup=function(){if(!this.fastupdate)return this;tb(this.map);this.depth&&tb(this.ctx);return this};w.searchCache=ma;w.export=function(a,b,c=0,e=0){let d,f;switch(e){case 0:d="reg";f=pb(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=lb(this.map,this.reg.size);break;case 3:d="ctx";f=nb(this.ctx,this.reg.size);break;default:return}return rb.call(this,a,b,d,f,c,e)}; +w.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=m.length){e-=m.length;continue}const q=c?e+Math.min(m.length-e,c):m.length;for(let t=e;t=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +w.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:V,Charset:va,Encoder:la,Document:Na,Worker:La,Resolver:Y,IndexedDB:Fb,Language:{}}; export const Index=V;export const Charset=va;export const Encoder=la;export const Document=Na;export const Worker=La;export const Resolver=Y;export const IndexedDB=Fb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index a553149..bbab09a 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.201 (Bundle/Debug) + * FlexSearch.js v0.8.202 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -516,21 +516,7 @@ function Aa(a, c, b, e, d, f, g, h) { } return e = 1 < e.length ? [].concat.apply([], e) : e[0]; } -;function Da(a, c) { - const b = M(), 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; - } - } - for (let d = 0, f; d < a.length; d++) { - f = a[d], b[f] && (e.push(f), b[f] = 0); - } - return e; -} -;M(); -function Ea(a, c, b, e, d) { +;function Da(a, c, b, e, d) { let f, g, h; "string" === typeof d ? (f = d, d = "") : f = d.template; if (!f) { @@ -763,7 +749,21 @@ function Ea(a, c, b, e, d) { } return c; } -;Y.prototype.search = function(a, c, b, e) { +;function Ea(a, c) { + const b = M(), 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; + } + } + for (let d = 0, f; d < a.length; d++) { + f = a[d], b[f] && (e.push(f), b[f] = 0); + } + return e; +} +;M(); +Y.prototype.search = function(a, c, b, e) { b || (!c && R(a) ? (b = a, a = "") : R(c) && (b = c, c = 0)); let d = []; var f = []; @@ -877,7 +877,7 @@ function Ea(a, c, b, e, d) { } } if (F) { - r = Da(r, u); + r = Ea(r, u); E = r.length; if (!E && !h) { return r; @@ -910,11 +910,11 @@ function Ea(a, c, b, e, d) { e = d[m]; g && e.length && "undefined" === typeof e[0].doc && (e = Ga.call(this, e)); if (p) { - return t ? Ea(a, e, this.index, p, t) : e; + return t ? Da(a, e, this.index, p, t) : e; } d[m] = {field:f[m], result:e}; } - t && (d = Ea(a, d, this.index, p, t)); + t && (d = Da(a, d, this.index, p, t)); return x ? Ha(d) : d; }; function Ha(a) { diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index d3cfc77..b019ff3 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.201 (Bundle) + * FlexSearch.js v0.8.202 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -21,17 +21,17 @@ W.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.li function X(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]);wa?ya||(ya=Date.now()-xa>=this.priority*this.priority*3):(wa=setTimeout(za,0),xa=Date.now());if(ya){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};Y.prototype.add=function(a,c,b){R(a)&&(c=a,a=S(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hc?a.slice(b,b+c):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}f=f.slice(b,b+c);g=f.length;b=0}g>c&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=1c?a.slice(b,b+c):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}f=f.slice(b,b+c);g=f.length;b=0}g>c&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=1E&&(E=m.length+(m?1:0)),z=m.length+(m?1:0)+L.length,r+=F,ja.push(u.length),u.push({match:L})),m+=(m?" ":"")+L)}if(!q)D=v[y],m+=(m?" ":"")+D,k&&u.push({text:D});else if(k&&r>=k)break}r=ja.length*(f.length-2);if(t||p||k&&m.length-r>k)if(r=k+r-2*w,y=z-E,0v&&(v=0)),u=u.length-1){if(G>=u.length){y[q+1]= 1;G>=v.length&&(r[q+1]=1);continue}F-=w}m=u[G].text;if(H=p&&B[q])if(0H)if(y[q+1]=1,n)m=m.substring(0,H);else continue;(H-=m.length)||(H=-1);B[q]=H}else{y[q+1]=1;continue}if(F+m.length+1<=k)m=" "+m,z[q]+=m;else if(n)O=k-F-1,0=G){if(0>G){y[q]=1;r[q]=1;continue}F-=w}m=u[G].text;if(H=t&&D[q])if(0H)if(y[q]=1,n)m=m.substring(m.length- H);else continue;(H-=m.length)||(H=-1);D[q]=H}else{y[q]=1;continue}if(F+m.length+1<=k)m+=" ",z[q]=m+z[q];else if(n)O=m.length+1-(k-F),0<=O&&O=v.length-1?ua=1:Gb||e)a=a.slice(e,e+b);d&&(a=Ga.call(this,a))}return a}function Ga(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.li function X(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]);wa?ya||(ya=Date.now()-xa>=this.priority*this.priority*3):(wa=setTimeout(za,0),xa=Date.now());if(ya){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};Y.prototype.add=function(a,c,b){R(a)&&(c=a,a=S(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hc?a.slice(b,b+c):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}f=f.slice(b,b+c);g=f.length;b=0}g>c&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=1c?a.slice(b,b+c):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}f=f.slice(b,b+c);g=f.length;b=0}g>c&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=1E&&(E=m.length+(m?1:0)),z=m.length+(m?1:0)+L.length,r+=F,ja.push(u.length),u.push({match:L})),m+=(m?" ":"")+L)}if(!q)D=v[y],m+=(m?" ":"")+D,k&&u.push({text:D});else if(k&&r>=k)break}r=ja.length*(f.length-2);if(t||p||k&&m.length-r>k)if(r=k+r-2*w,y=z-E,0v&&(v=0)),u=u.length-1){if(G>=u.length){y[q+1]= 1;G>=v.length&&(r[q+1]=1);continue}F-=w}m=u[G].text;if(H=p&&B[q])if(0H)if(y[q+1]=1,n)m=m.substring(0,H);else continue;(H-=m.length)||(H=-1);B[q]=H}else{y[q+1]=1;continue}if(F+m.length+1<=k)m=" "+m,z[q]+=m;else if(n)O=k-F-1,0=G){if(0>G){y[q]=1;r[q]=1;continue}F-=w}m=u[G].text;if(H=t&&D[q])if(0H)if(y[q]=1,n)m=m.substring(m.length- H);else continue;(H-=m.length)||(H=-1);D[q]=H}else{y[q]=1;continue}if(F+m.length+1<=k)m+=" ",z[q]=m+z[q];else if(n)O=m.length+1-(k-F),0<=O&&O=v.length-1?ta=1:Gb||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 c && (c = Math.max(c + e, 0)); c < e; c++) { - var g = d[c]; - if (g === b || Object.is(g, b)) { + var f = d[c]; + if (f === b || Object.is(f, b)) { return !0; } } @@ -843,8 +843,8 @@ function P(a, b, c) { if ("undefined" !== e) { if (c) { if ("function" === e && d === e) { - return function(g) { - return a(c(g)); + return function(f) { + return a(c(f)); }; } b = a.constructor; @@ -854,7 +854,7 @@ function P(a, b, c) { } if (b === Map) { b = new Map(c); - d = C(a); + d = B(a); for (e = d.next(); !e.done; e = d.next()) { e = e.value, b.set(e[0], e[1]); } @@ -862,7 +862,7 @@ function P(a, b, c) { } if (b === Set) { b = new Set(c); - d = C(a.values()); + d = B(a.values()); for (e = d.next(); !e.done; e = d.next()) { b.add(e.value); } @@ -890,7 +890,7 @@ function Ca(a) { } function Da(a) { var b = []; - a = C(a.keys()); + a = B(a.keys()); for (var c = a.next(); !c.done; c = a.next()) { b.push(c.value); } @@ -912,15 +912,15 @@ function Ka(a) { if (!this || this.constructor !== Ka) { var b = Function.prototype.bind, c = b.apply, d = [null], e = d.concat; if (arguments instanceof Array) { - var g = arguments; + var f = arguments; } else { - g = C(arguments); - for (var f, h = []; !(f = g.next()).done;) { - h.push(f.value); + f = B(arguments); + for (var h, g = []; !(h = f.next()).done;) { + g.push(h.value); } - g = h; + f = g; } - return new (c.call(b, Ka, e.call(d, g)))(); + return new (c.call(b, Ka, e.call(d, f)))(); } if (arguments.length) { for (b = 0; b < arguments.length; b++) { @@ -949,7 +949,7 @@ w.assign = function(a) { } try { this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); - } catch (g) { + } catch (f) { console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { @@ -959,7 +959,7 @@ w.assign = function(a) { } else { try { this.split = P(this.split, Fa); - } catch (g) { + } catch (f) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } this.numeric = P(a.numeric, P(this.numeric, !0)); @@ -977,19 +977,19 @@ w.assign = function(a) { this.maxlength = P(a.maxlength, 1024, this.maxlength); this.rtl = P(a.rtl, !1, this.rtl); if (this.cache = c = P(a.cache, !0, this.cache)) { - this.D = null, this.U = "number" === typeof c ? c : 2e5, this.B = new Map(), this.C = new Map(), this.I = this.H = 128; + this.F = null, this.U = "number" === typeof c ? c : 2e5, this.B = new Map(), this.D = new Map(), this.I = this.H = 128; } this.h = ""; this.N = null; this.A = ""; this.O = null; if (this.matcher) { - for (a = C(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { + for (a = B(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { this.h += (this.h ? "|" : "") + b.value; } } if (this.stemmer) { - for (a = C(this.stemmer.keys()), b = a.next(); !b.done; b = a.next()) { + for (a = B(this.stemmer.keys()), b = a.next(); !b.done; b = a.next()) { this.A += (this.A ? "|" : "") + b.value; } } @@ -1046,83 +1046,83 @@ w.addReplacer = function(a, b) { w.encode = function(a, b) { var c = this; if (this.cache && a.length <= this.H) { - if (this.D) { + if (this.F) { if (this.B.has(a)) { return this.B.get(a); } } else { - this.D = setTimeout(La, 50, this); + this.F = setTimeout(La, 50, this); } } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = Ja ? a.normalize("NFKD").replace(Ja, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(Ha, "$1 $2").replace(Ia, "$1 $2").replace(Ga, "$1 ")); - for (var d = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), e = [], g = S(), f, h, k = this.split || "" === this.split ? a.split(this.split) : [a], l = 0, m = void 0, p = void 0; l < k.length; l++) { - if ((m = p = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { + for (var d = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), e = [], f = S(), h, g, k = this.split || "" === this.split ? a.split(this.split) : [a], m = 0, l = void 0, p = void 0; m < k.length; m++) { + if ((l = p = k[m]) && !(l.length < this.minlength || l.length > this.maxlength)) { if (b) { - if (g[m]) { + if (f[l]) { continue; } - g[m] = 1; + f[l] = 1; } else { - if (f === m) { + if (h === l) { continue; } - f = m; + h = l; } if (d) { - e.push(m); + e.push(l); } else { - if (!this.filter || ("function" === typeof this.filter ? this.filter(m) : !this.filter.has(m))) { - if (this.cache && m.length <= this.I) { - if (this.D) { - var n = this.C.get(m); + if (!this.filter || ("function" === typeof this.filter ? this.filter(l) : !this.filter.has(l))) { + if (this.cache && l.length <= this.I) { + if (this.F) { + var n = this.D.get(l); if (n || "" === n) { n && e.push(n); continue; } } else { - this.D = setTimeout(La, 50, this); + this.F = setTimeout(La, 50, this); } } if (this.stemmer) { - for (this.O || (this.O = new RegExp("(?!^)(" + this.A + ")$")), n = void 0; n !== m && 2 < m.length;) { - n = m, m = m.replace(this.O, function(x) { - return c.stemmer.get(x); + for (this.O || (this.O = new RegExp("(?!^)(" + this.A + ")$")), n = void 0; n !== l && 2 < l.length;) { + n = l, l = l.replace(this.O, function(z) { + return c.stemmer.get(z); }); } } - if (m && (this.mapper || this.dedupe && 1 < m.length)) { + if (l && (this.mapper || this.dedupe && 1 < l.length)) { n = ""; - for (var q = 0, t = "", u = void 0, v = void 0; q < m.length; q++) { - u = m.charAt(q), u === t && this.dedupe || ((v = this.mapper && this.mapper.get(u)) || "" === v ? v === t && this.dedupe || !(t = v) || (n += v) : n += t = u); + for (var q = 0, t = "", v = void 0, u = void 0; q < l.length; q++) { + v = l.charAt(q), v === t && this.dedupe || ((u = this.mapper && this.mapper.get(v)) || "" === u ? u === t && this.dedupe || !(t = u) || (n += u) : n += t = v); } - m = n; + l = n; } - this.matcher && 1 < m.length && (this.N || (this.N = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.N, function(x) { - return c.matcher.get(x); + this.matcher && 1 < l.length && (this.N || (this.N = new RegExp("(" + this.h + ")", "g")), l = l.replace(this.N, function(z) { + return c.matcher.get(z); })); - if (m && this.replacer) { - for (n = 0; m && n < this.replacer.length; n += 2) { - m = m.replace(this.replacer[n], this.replacer[n + 1]); + if (l && this.replacer) { + for (n = 0; l && n < this.replacer.length; n += 2) { + l = l.replace(this.replacer[n], this.replacer[n + 1]); } } - this.cache && p.length <= this.I && (this.C.set(p, m), this.C.size > this.U && (this.C.clear(), this.I = this.I / 1.1 | 0)); - if (m) { - if (m !== p) { + this.cache && p.length <= this.I && (this.D.set(p, l), this.D.size > this.U && (this.D.clear(), this.I = this.I / 1.1 | 0)); + if (l) { + if (l !== p) { if (b) { - if (g[m]) { + if (f[l]) { continue; } - g[m] = 1; + f[l] = 1; } else { - if (h === m) { + if (g === l) { continue; } - h = m; + g = l; } } - e.push(m); + e.push(l); } } } @@ -1133,9 +1133,9 @@ w.encode = function(a, b) { return e; }; function La(a) { - a.D = null; + a.F = null; a.B.clear(); - a.C.clear(); + a.D.clear(); } ;function Ma(a, b, c) { c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : c = a); @@ -1149,10 +1149,10 @@ function La(a) { this.cache || (this.cache = new Na()); e = this.cache.get(a + d); if (!e) { - var g = c && c.cache; - g && (c.cache = !1); + var f = c && c.cache; + f && (c.cache = !1); e = this.search(a, b, c); - g && (c.cache = g); + f && (c.cache = f); this.cache.set(a + d, e); } return e; @@ -1172,7 +1172,7 @@ Na.prototype.get = function(a) { return b; }; Na.prototype.remove = function(a) { - for (var b = C(this.cache), c = b.next(); !c.done; c = b.next()) { + for (var b = B(this.cache), c = b.next(); !c.done; c = b.next()) { c = c.value; var d = c[0]; c[1].includes(a) && this.cache.delete(d); @@ -1189,19 +1189,19 @@ var Ra = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t" var Ta = {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 Ua = {Exact:Oa, Default:Pa, Normalize:Pa, LatinBalance:{mapper:Qa}, LatinAdvanced:{mapper:Qa, matcher:Ra, replacer:Sa}, LatinExtra:{mapper:Qa, replacer:Sa.concat([/(?!^)[aeo]/g, ""]), matcher:Ra}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (var b = 0; b < a.length; b++) { - for (var c = a[b], d = c.charAt(0), e = Ta[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = Ta[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { + for (var c = a[b], d = c.charAt(0), e = Ta[d], f = 1, h; f < c.length && (h = c.charAt(f), "h" === h || "w" === h || !(h = Ta[h]) || h === e || (d += h, e = h, 4 !== d.length)); f++) { } a[b] = d; } }}, CJK:{split:""}, LatinExact:Oa, LatinDefault:Pa, LatinSimple:Pa}; function Va(a, b, c, d) { - for (var e = [], g = 0, f; g < a.index.length; g++) { - if (f = a.index[g], b >= f.length) { - b -= f.length; + for (var e = [], f = 0, h; f < a.index.length; f++) { + if (h = a.index[f], b >= h.length) { + b -= h.length; } else { - b = f[d ? "splice" : "slice"](b, c); - if (f = b.length) { - if (e = e.length ? e.concat(b) : b, c -= f, d && (a.length -= f), !c) { + b = h[d ? "splice" : "slice"](b, c); + if (h = b.length) { + if (e = e.length ? e.concat(b) : b, c -= h, d && (a.length -= h), !c) { break; } } @@ -1236,21 +1236,21 @@ function Wa(a) { } if ("indexOf" === d) { return function(e) { - for (var g = 0, f = 0, h, k; f < b.index.length; f++) { - h = b.index[f]; - k = h.indexOf(e); + for (var f = 0, h = 0, g, k; h < b.index.length; h++) { + g = b.index[h]; + k = g.indexOf(e); if (0 <= k) { - return g + k; + return f + k; } - g += h.length; + f += g.length; } return -1; }; } if ("includes" === d) { return function(e) { - for (var g = 0; g < b.index.length; g++) { - if (b.index[g].includes(e)) { + for (var f = 0; f < b.index.length; f++) { + if (b.index[f].includes(e)) { return !0; } } @@ -1258,13 +1258,13 @@ function Wa(a) { }; } if ("slice" === d) { - return function(e, g) { - return Va(b, e || 0, g || b.length, !1); + return function(e, f) { + return Va(b, e || 0, f || b.length, !1); }; } if ("splice" === d) { - return function(e, g) { - return Va(b, e || 0, g || b.length, !0); + return function(e, f) { + return Va(b, e || 0, f || b.length, !0); }; } if ("constructor" === d) { @@ -1335,80 +1335,80 @@ w.clear = X.prototype.clear = function() { this.size = 0; }; w.values = X.prototype.values = function $a() { - var b, c = this, d, e, g; - return ua($a, function(f) { - switch(f.h) { + var b, c = this, d, e, f; + return ua($a, function(h) { + switch(h.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + h.h = 0; break; } - d = C(c.h[b].values()); + d = B(c.h[b].values()); e = d.next(); case 5: if (e.done) { b++; - f.h = 2; + h.h = 2; break; } - g = e.value; - return K(f, g, 6); + f = e.value; + return K(h, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), h.h = 5; } }); }; w.keys = X.prototype.keys = function ab() { - var b, c = this, d, e, g; - return ua(ab, function(f) { - switch(f.h) { + var b, c = this, d, e, f; + return ua(ab, function(h) { + switch(h.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + h.h = 0; break; } - d = C(c.h[b].keys()); + d = B(c.h[b].keys()); e = d.next(); case 5: if (e.done) { b++; - f.h = 2; + h.h = 2; break; } - g = e.value; - return K(f, g, 6); + f = e.value; + return K(h, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), h.h = 5; } }); }; w.entries = X.prototype.entries = function bb() { - var b, c = this, d, e, g; - return ua(bb, function(f) { - switch(f.h) { + var b, c = this, d, e, f; + return ua(bb, function(h) { + switch(h.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + h.h = 0; break; } - d = C(c.h[b].entries()); + d = B(c.h[b].entries()); e = d.next(); case 5: if (e.done) { b++; - f.h = 2; + h.h = 2; break; } - g = e.value; - return K(f, g, 6); + f = e.value; + return K(h, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), h.h = 5; } }); }; @@ -1427,9 +1427,9 @@ function Ya() { } ;var cb, db; function eb(a) { - var b, c, d, e, g, f; - return wa(function(h) { - switch(h.h) { + var b, c, d, e, f, h; + return wa(function(g) { + switch(g.h) { case 1: a = a.data; b = a.task; @@ -1442,9 +1442,9 @@ function eb(a) { postMessage({id:c}); break; default: - h.h = 2; + g.h = 2; return; - }h.h = 0; + }g.h = 0; break; case 2: if ("export" === b) { @@ -1458,35 +1458,35 @@ function eb(a) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } if (!d[0]) { - h.h = 5; + g.h = 5; break; } - return K(h, db.import.call(cb, d[0]), 11); + return K(g, db.import.call(cb, d[0]), 11); } - g = d && cb[b].apply(cb, d); - if (!g || !g.then) { - h.h = 6; + f = d && cb[b].apply(cb, d); + if (!f || !f.then) { + g.h = 6; break; } - return K(h, g, 7); + return K(g, f, 7); case 7: - g = h.B; + f = g.B; case 6: - if (!g || !g.await) { - h.h = 8; + if (!f || !f.await) { + g.h = 8; break; } - return K(h, g.await, 9); + return K(g, f.await, 9); case 9: - g = h.B; + f = g.B; case 8: - "search" === b && g.result && (g = g.result); - h.h = 5; + "search" === b && f.result && (f = f.result); + g.h = 5; break; case 11: - f = h.B, cb.import(d[0], f); + h = g.B, cb.import(d[0], h); case 5: - postMessage("search" === b ? {id:c, msg:g} : {id:c}), h.h = 0; + postMessage("search" === b ? {id:c, msg:f} : {id:c}), g.h = 0; } }); } @@ -1512,15 +1512,15 @@ function gb(a) { hb ? jb || (jb = Date.now() - ib >= this.priority * this.priority * 3) : (hb = setTimeout(kb, 0), ib = Date.now()); if (jb) { var e = this; - return new Promise(function(f) { + return new Promise(function(h) { setTimeout(function() { - f(e[a + "Async"].apply(e, b)); + h(e[a + "Async"].apply(e, b)); }, 0); }); } - var g = this[a].apply(this, b); - c = g.then ? g : new Promise(function(f) { - return f(g); + var f = this[a].apply(this, b); + c = f.then ? f : new Promise(function(h) { + return h(f); }); d && c.then(d); return c; @@ -1528,23 +1528,23 @@ function gb(a) { } ;var lb = 0; function mb(a, b) { - function c(h) { - function k(l) { - l = l.data || l; - var m = l.id, p = m && g.h[m]; - p && (p(l.msg), delete g.h[m]); + function c(g) { + function k(m) { + m = m.data || m; + var l = m.id, p = l && f.h[l]; + p && (p(m.msg), delete f.h[l]); } - this.worker = h; + this.worker = g; this.h = S(); if (this.worker) { e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(l) { + return new Promise(function(m) { 1e9 < lb && (lb = 0); - g.h[++lb] = function() { - l(g); + f.h[++lb] = function() { + m(f); }; - g.worker.postMessage({id:lb, task:"init", factory:d, options:a}); + f.worker.postMessage({id:lb, task:"init", factory:d, options:a}); }); } this.priority = a.priority || 4; @@ -1560,10 +1560,10 @@ function mb(a, b) { } var d = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; d && (d = d.toString()); - var e = "undefined" === typeof window, g = this, f = nb(d, e, a.worker); - return f.then ? f.then(function(h) { - return c.call(g, h); - }) : c.call(this, f); + var e = "undefined" === typeof window, f = this, h = nb(d, e, a.worker); + return h.then ? h.then(function(g) { + return c.call(f, g); + }) : c.call(this, h); } ob("add"); ob("append"); @@ -1582,10 +1582,10 @@ function ob(a) { var e = d; c.pop(); } - d = new Promise(function(g) { + d = new Promise(function(f) { "export" === a && "function" === typeof c[0] && (c[0] = null); 1e9 < lb && (lb = 0); - b.h[++lb] = g; + b.h[++lb] = f; b.worker.postMessage({task:a, id:lb, args:c}); }); return e ? (d.then(e), this) : d; @@ -1603,58 +1603,58 @@ function nb(a, b, c) { } for (var d = 0, e; d < this.field.length; d++) { e = this.M[d]; - var g = this.index.get(this.field[d]); + var f = this.index.get(this.field[d]); if ("function" === typeof e) { - (e = e(b)) && g.add(a, e, !1, !0); + (e = e(b)) && f.add(a, e, !1, !0); } else { - var f = e.S; - if (!f || f(b)) { - e.constructor === String ? e = ["" + e] : T(e) && (e = [e]), qb(b, e, this.T, 0, g, a, e[0], c); + var h = e.S; + if (!h || h(b)) { + e.constructor === String ? e = ["" + e] : T(e) && (e = [e]), qb(b, e, this.T, 0, f, a, e[0], c); } } } if (this.tag) { for (d = 0; d < this.L.length; d++) { - f = this.L[d]; - var h = this.ba[d]; - g = this.tag.get(h); + h = this.L[d]; + var g = this.ba[d]; + f = this.tag.get(g); e = S(); - if ("function" === typeof f) { - if (f = f(b), !f) { + if ("function" === typeof h) { + if (h = h(b), !h) { continue; } } else { - var k = f.S; + var k = h.S; if (k && !k(b)) { continue; } - f.constructor === String && (f = "" + f); - f = Ea(b, f); + h.constructor === String && (h = "" + h); + h = Ea(b, h); } - if (g && f) { - for (T(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { - var l = f[h]; - if (!e[l]) { - e[l] = 1; - var m; - (m = g.get(l)) ? k = m : g.set(l, k = []); + if (f && h) { + for (T(h) && (h = [h]), g = 0, k = void 0; g < h.length; g++) { + var m = h[g]; + if (!e[m]) { + e[m] = 1; + var l; + (l = f.get(m)) ? k = l : f.set(m, k = []); if (!c || !k.includes(a)) { if (k.length === Math.pow(2, 31) - 1) { - m = new Wa(k); + l = new Wa(k); if (this.fastupdate) { - for (var p = C(this.reg.values()), n = p.next(); !n.done; n = p.next()) { - n = n.value, n.includes(k) && (n[n.indexOf(k)] = m); + for (var p = B(this.reg.values()), n = p.next(); !n.done; n = p.next()) { + n = n.value, n.includes(k) && (n[n.indexOf(k)] = l); } } - g.set(l, k = m); + f.set(m, k = l); } k.push(a); - this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); + this.fastupdate && ((m = this.reg.get(a)) ? m.push(k) : this.reg.set(a, [k])); } } } } else { - g || console.warn("Tag '" + h + "' was not found"); + f || console.warn("Tag '" + g + "' was not found"); } } } @@ -1662,11 +1662,11 @@ function nb(a, b, c) { if (this.J) { var q = S(); for (c = 0; c < this.J.length; c++) { - if (d = this.J[c], g = d.S, !g || g(b)) { - g = void 0; + if (d = this.J[c], f = d.S, !f || f(b)) { + f = void 0; if ("function" === typeof d) { - g = d(b); - if (!g) { + f = d(b); + if (!f) { continue; } d = [d.na]; @@ -1674,7 +1674,7 @@ function nb(a, b, c) { q[d] = b[d]; continue; } - rb(b, q, d, 0, d[0], g); + rb(b, q, d, 0, d[0], f); } } } @@ -1684,10 +1684,10 @@ function nb(a, b, c) { } return this; }; -function rb(a, b, c, d, e, g) { +function rb(a, b, c, d, e, f) { a = a[e]; if (d === c.length - 1) { - b[e] = g || a; + b[e] = f || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { @@ -1698,26 +1698,26 @@ function rb(a, b, c, d, e, g) { } } } -function qb(a, b, c, d, e, g, f, h) { - if (a = a[f]) { +function qb(a, b, c, d, e, f, h, g) { + if (a = a[h]) { if (d === b.length - 1) { if (a.constructor === Array) { if (c[d]) { for (b = 0; b < a.length; b++) { - e.add(g, a[b], !0, !0); + e.add(f, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(g, a, h, !0); + e.add(f, a, g, !0); } else { if (a.constructor === Array) { - for (f = 0; f < a.length; f++) { - qb(a, b, c, d, e, g, f, h); + for (h = 0; h < a.length; h++) { + qb(a, b, c, d, e, f, h, g); } } else { - f = b[++d], qb(a, b, c, d, e, g, f, h); + h = b[++d], qb(a, b, c, d, e, f, h, g); } } } @@ -1729,23 +1729,23 @@ function qb(a, b, c, d, e, g, f, h) { if (1 === a.length) { return a = a[0], a = c || a.length > b ? a.slice(c, c + b) : a, d ? tb.call(this, a) : a; } - for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { - if ((f = a[g]) && (h = f.length)) { + for (var e = [], f = 0, h = void 0, g = void 0; f < a.length; f++) { + if ((h = a[f]) && (g = h.length)) { if (c) { - if (c >= h) { - c -= h; + if (c >= g) { + c -= g; continue; } - f = f.slice(c, c + b); - h = f.length; + h = h.slice(c, c + b); + g = h.length; c = 0; } - h > b && (f = f.slice(0, b), h = b); - if (!e.length && h >= b) { - return d ? tb.call(this, f) : f; + g > b && (h = h.slice(0, b), g = b); + if (!e.length && g >= b) { + return d ? tb.call(this, h) : h; } - e.push(f); - b -= h; + e.push(h); + b -= g; if (!b) { break; } @@ -1762,115 +1762,116 @@ function qb(a, b, c, d, e, g, f, h) { if (!("and" !== b && "not" !== b || a.result.length || a.await || e.suggest)) { return 1 < d.length && (e = d[d.length - 1]), (d = e.resolve) ? a.await || a.result : a; } - var g = [], f = 0, h = 0, k; + var f = [], h = 0, g = 0, k, m; b = {}; for (e = 0; e < d.length; b = {aa:void 0, $:void 0, ca:void 0, fa:void 0}, e++) { var l = d[e]; if (l) { - var m = void 0; + var p = void 0; if (l.constructor === Z) { - m = l.await || l.result; + p = l.await || l.result; } else if (l.then || l.constructor === Array) { - m = l; + p = l; } else { - f = l.limit || 0; - h = l.offset || 0; - var p = l.suggest; - var n = l.resolve; - var q = (k = l.highlight && n) || l.enrich && n; - m = l.queue; - b.ca = l.async || m; - (k = l.index) ? a.index || (a.index = k) : k = a.index; + h = l.limit || 0; + g = l.offset || 0; + var n = l.suggest; + var q = ((m = (k = l.resolve) && l.highlight) || l.enrich) && k; + p = l.queue; + b.ca = l.async || p; + var t = l.index; + t ? a.index || (a.index = t) : t = a.index; if (l.query || l.tag) { - if (!a.index) { + if (!t) { throw Error("Resolver can't apply because the corresponding Index was never specified"); } - var t = l.field || l.pluck; - if (t) { - if (!a.index.index) { + var v = l.field || l.pluck; + if (v) { + l.query && (a.query = l.query, a.field = v); + if (!t.index) { throw Error("Resolver can't apply because the corresponding Document Index was not specified"); } - k = a.index.index.get(t); - if (!k) { - throw Error("Resolver can't apply because the specified Document Field '" + t + "' was not found"); + t = t.index.get(v); + if (!t) { + throw Error("Resolver can't apply because the specified Document Field '" + v + "' was not found"); } } - if (m && (u || a.await)) { + if (p && (u || a.await)) { var u = 1; b.aa = void 0; - b.fa = a.G.length; + b.fa = a.C.length; b.$ = new Promise(function(x) { - return function(y) { - x.aa = y; + return function(C) { + x.aa = C; }; }(b)); (function(x) { - return function(y, E) { + return function(C, D) { x.$.H = function() { - E.index = null; - E.resolve = !1; - var B = x.ca ? y.searchAsync(E) : y.search(E); - if (B.then) { - return B.then(function(r) { - a.G[x.fa] = r = r.result || r; - (0,x.aa)(r); - return r; + D.index = null; + D.resolve = !1; + var r = x.ca ? C.searchAsync(D) : C.search(D); + if (r.then) { + return r.then(function(y) { + a.C[x.fa] = y = y.result || y; + (0,x.aa)(y); + return y; }); } - B = B.result || B; - (0,x.aa)(B); - return B; + r = r.result || r; + (0,x.aa)(r); + return r; }; }; - })(b)(k, Object.assign({}, l)); - a.G.push(b.$); - g[e] = b.$; + })(b)(t, Object.assign({}, l)); + a.C.push(b.$); + f[e] = b.$; continue; } else { - l.resolve = !1, l.index = null, m = b.ca ? k.searchAsync(l) : k.search(l), l.resolve = n, l.index = k; + l.resolve = !1, l.index = null, p = b.ca ? t.searchAsync(l) : t.search(l), l.resolve = k, l.index = t; } } else if (l.and) { - m = vb(l, "and", k); + p = vb(l, "and", t); } else if (l.or) { - m = vb(l, "or", k); + p = vb(l, "or", t); } else if (l.not) { - m = vb(l, "not", k); + p = vb(l, "not", t); } else if (l.xor) { - m = vb(l, "xor", k); + p = vb(l, "xor", t); } else { continue; } } - m.await ? (u = 1, m = m.await) : m.then ? (u = 1, m = m.then(function(x) { + p.await ? (u = 1, p = p.await) : p.then ? (u = 1, p = p.then(function(x) { return x.result || x; - })) : m = m.result || m; - g[e] = m; + })) : p = p.result || p; + f[e] = p; } } u && !a.await && (a.await = new Promise(function(x) { a.return = x; })); if (u) { - var v = Promise.all(g).then(function(x) { - for (var y = 0; y < a.G.length; y++) { - if (a.G[y] === v) { - a.G[y] = function() { - return c.call(a, x, f, h, q, n, p); + var z = Promise.all(f).then(function(x) { + for (var C = 0; C < a.C.length; C++) { + if (a.C[C] === z) { + a.C[C] = function() { + return c.call(a, x, h, g, q, k, n, m); }; break; } } wb(a); }); - a.G.push(v); + a.C.push(z); } else if (a.await) { - a.G.push(function() { - return c.call(a, g, f, h, q, n, p); + a.C.push(function() { + return c.call(a, f, h, g, q, k, n, m); }); } else { - return c.call(a, g, f, h, q, n, p); + return c.call(a, f, h, g, q, k, n, m); } - return n ? a.await || a.result : a; + return k ? a.await || a.result : a; } function vb(a, b, c) { a = a[b]; @@ -1883,86 +1884,86 @@ function vb(a, b, c) { ;Z.prototype.or = function() { return ub(this, "or", xb, arguments); }; -function xb(a, b, c, d, e) { +function xb(a, b, c, d, e, f, h) { a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = yb(a, b, c, !1, this.h), c = 0)); e && (this.await = null); - return e ? this.resolve(b, c, d) : this; + return e ? this.resolve(b, c, d, h) : this; } ;Z.prototype.and = function() { return ub(this, "and", zb, arguments); }; -function zb(a, b, c, d, e, g) { - if (!g && !this.result.length) { +function zb(a, b, c, d, e, f, h) { + if (!f && !this.result.length) { return e ? this.result : this; } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - for (var f = 0, h = 0, k = void 0, l = void 0; h < a.length; h++) { - if ((k = a[h]) && (l = k.length)) { - f < l && (f = l); - } else if (!g) { - f = 0; + for (var g = 0, k = 0, m = void 0, l = void 0; k < a.length; k++) { + if ((m = a[k]) && (l = m.length)) { + g < l && (g = l); + } else if (!f) { + g = 0; break; } } - if (f) { - this.result = Ab(a, f, b, c, g, this.h, e); - var m = !0; + if (g) { + this.result = Ab(a, g, b, c, f, this.h, e); + var p = !0; } else { this.result = []; } } } else { - g || (this.result = a); + f || (this.result = a); } e && (this.await = null); - return e ? this.resolve(b, c, d, m) : this; + return e ? this.resolve(b, c, d, h, p) : this; } ;Z.prototype.xor = function() { return ub(this, "xor", Bb, arguments); }; -function Bb(a, b, c, d, e, g) { +function Bb(a, b, c, d, e, f, h) { if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { a: { - g = c; - var f = this.h; - for (var h = [], k = S(), l = 0, m = 0, p; m < a.length; m++) { - if (p = a[m]) { - l < p.length && (l = p.length); - for (var n = 0, q; n < p.length; n++) { - if (q = p[n]) { - for (var t = 0, u; t < q.length; t++) { - u = q[t], k[u] = k[u] ? 2 : 1; + f = c; + var g = this.h; + for (var k = [], m = S(), l = 0, p = 0, n; p < a.length; p++) { + if (n = a[p]) { + l < n.length && (l = n.length); + for (var q = 0, t; q < n.length; q++) { + if (t = n[q]) { + for (var v = 0, u; v < t.length; v++) { + u = t[v], m[u] = m[u] ? 2 : 1; } } } } } - for (p = m = 0; m < l; m++) { - for (n = 0; n < a.length; n++) { - if (q = a[n]) { - if (q = q[m]) { - for (t = 0; t < q.length; t++) { - if (u = q[t], 1 === k[u]) { - if (g) { - g--; + for (n = p = 0; p < l; p++) { + for (q = 0; q < a.length; q++) { + if (t = a[q]) { + if (t = t[p]) { + for (v = 0; v < t.length; v++) { + if (u = t[v], 1 === m[u]) { + if (f) { + f--; } else { if (e) { - if (h.push(u), h.length === b) { - a = h; + if (k.push(u), k.length === b) { + a = k; break a; } } else { - var v = m + (n ? f : 0); - h[v] || (h[v] = []); - h[v].push(u); - if (++p === b) { - a = h; + var z = p + (q ? g : 0); + k[z] || (k[z] = []); + k[z].push(u); + if (++n === b) { + a = k; break a; } } @@ -1973,44 +1974,44 @@ function Bb(a, b, c, d, e, g) { } } } - a = h; + a = k; } this.result = a; - f = !0; + g = !0; } } else { - g || (this.result = a); + f || (this.result = a); } e && (this.await = null); - return e ? this.resolve(b, c, d, f) : this; + return e ? this.resolve(b, c, d, h, g) : this; } ;Z.prototype.not = function() { return ub(this, "not", Cb, arguments); }; -function Cb(a, b, c, d, e, g) { - if (!g && !this.result.length) { +function Cb(a, b, c, d, e, f, h) { + if (!f && !this.result.length) { return e ? this.result : this; } if (a.length && this.result.length) { a: { - g = c; - var f = []; + f = c; + var g = []; a = new Set(a.flat().flat()); - for (var h = 0, k, l = 0; h < this.result.length; h++) { - if (k = this.result[h]) { - for (var m = 0, p; m < k.length; m++) { - if (p = k[m], !a.has(p)) { - if (g) { - g--; + for (var k = 0, m, l = 0; k < this.result.length; k++) { + if (m = this.result[k]) { + for (var p = 0, n; p < m.length; p++) { + if (n = m[p], !a.has(n)) { + if (f) { + f--; } else { if (e) { - if (f.push(p), f.length === b) { - g = f; + if (g.push(n), g.length === b) { + f = g; break a; } } else { - if (f[h] || (f[h] = []), f[h].push(p), ++l === b) { - g = f; + if (g[k] || (g[k] = []), g[k].push(n), ++l === b) { + f = g; break a; } } @@ -2019,263 +2020,31 @@ function Cb(a, b, c, d, e, g) { } } } - g = f; + f = g; } - this.result = g; - f = !0; + this.result = f; + g = !0; } e && (this.await = null); - return e ? this.resolve(b, c, d, f) : this; + return e ? this.resolve(b, c, d, h, g) : this; } -;function Z(a, b) { - if (!this || this.constructor !== Z) { - return new Z(a, b); - } - var c = 0, d; - if (a && a.index) { - var e = a; - b = e.index; - c = e.boost || 0; - if (e.query) { - var g = e.resolve; - a = e.async || e.queue; - e.resolve = !1; - e.index = null; - a = a ? b.searchAsync(e) : b.search(e); - e.resolve = g; - e.index = b; - a = a.result || a; - } else { - a = []; - } - } - if (a && a.then) { - var f = this; - a = a.then(function(l) { - f.G[0] = f.result = l.result || l; - wb(f); - }); - var h = [a]; - a = []; - var k = new Promise(function(l) { - d = l; - }); - } - this.index = b || null; - this.result = a || []; - this.h = c; - this.G = h || []; - this.await = k || null; - this.return = d || null; -} -Z.prototype.limit = function(a) { - if (this.result.length) { - for (var b = [], c = 0, d; c < this.result.length; c++) { - if (d = this.result[c]) { - if (d.length <= a) { - if (b[c] = d, a -= d.length, !a) { - break; - } - } else { - b[c] = d.slice(0, a); - break; - } - } - } - this.result = b; - } - return this; -}; -Z.prototype.offset = function(a) { - if (this.result.length) { - for (var b = [], c = 0, d; c < this.result.length; c++) { - if (d = this.result[c]) { - d.length <= a ? a -= d.length : (b[c] = d.slice(a), a = 0); - } - } - this.result = b; - } - return this; -}; -Z.prototype.boost = function(a) { - this.h += a; - return this; -}; -function wb(a, b) { - for (var c = a.result, d = 0, e; d < a.G.length; d++) { - if (e = a.G[d]) { - if ("function" === typeof e) { - c = e(), a.G[d] = c = c.result || c, d--; - } else if (e.H) { - c = e.H(), a.G[d] = c = c.result || c, d--; - } else if (e.then) { - return a.await; - } - } - } - d = a.return; - a.result = c; - a.G = []; - a.await = null; - a.return = null; - b || d(c); - return c; -} -Z.prototype.resolve = function(a, b, c, d) { - var e = this.await ? wb(this, !0) : this.result; - if (e.then) { - var g = this; - return e.then(function() { - return g.resolve(a, b, c); - }); - } - e.length && ("object" === typeof a && (c = a.enrich, b = a.offset, a.highlight && console.warn('Highlighting results is not supported within the resolve() method. Instead pass highlight options within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'), a = a.limit), e = d ? c ? tb.call(this.index, e) : e : sb.call(this.index, e, a || 100, b, c)); - d = this.return; - this.return = this.await = this.G = this.result = this.index = null; - d && d(e); - return e; -}; -function Ab(a, b, c, d, e, g, f) { - var h = a.length, k = []; - var l = S(); - for (var m = 0, p = void 0, n, q; m < b; m++) { - for (var t = 0; t < h; t++) { - var u = a[t]; - if (m < u.length && (p = u[m])) { - for (var v = 0; v < p.length; v++) { - n = p[v]; - (u = l[n]) ? l[n]++ : (u = 0, l[n] = 1); - q = k[u] || (k[u] = []); - if (!f) { - var x = m + (t || !e ? 0 : g || 0); - q = q[x] || (q[x] = []); - } - q.push(n); - if (f && c && u === h - 1 && q.length - d === c) { - return d ? q.slice(d) : q; - } - } - } - } - } - if (a = k.length) { - if (e) { - k = 1 < k.length ? yb(k, c, d, f, g) : (k = k[0]) && c && k.length > c || d ? k.slice(d, c + d) : k; - } else { - if (a < h) { - return []; - } - k = k[a - 1]; - if (c || d) { - if (f) { - if (k.length > c || d) { - k = k.slice(d, c + d); - } - } else { - e = []; - for (g = 0; g < k.length; g++) { - if (f = k[g]) { - if (d && f.length > d) { - d -= f.length; - } else { - if (c && f.length > c || d) { - f = f.slice(d, c + d), c -= f.length, d && (d -= f.length); - } - e.push(f); - if (!c) { - break; - } - } - } - } - k = e; - } - } - } - } - return k; -} -function yb(a, b, c, d, e) { - var g = [], f = S(), h = a.length, k; - if (d) { - for (e = h - 1; 0 <= e; e--) { - if (k = (d = a[e]) && d.length) { - for (h = 0; h < k; h++) { - var l = d[h]; - if (!f[l]) { - if (f[l] = 1, c) { - c--; - } else { - if (g.push(l), g.length === b) { - return g; - } - } - } - } - } - } - } else { - for (var m = h - 1, p, n = 0; 0 <= m; m--) { - p = a[m]; - for (var q = 0; q < p.length; q++) { - if (k = (d = p[q]) && d.length) { - for (var t = 0; t < k; t++) { - if (l = d[t], !f[l]) { - if (f[l] = 1, c) { - c--; - } else { - var u = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; - (g[u] || (g[u] = [])).push(l); - if (++n === b) { - return g; - } - } - } - } - } - } - } - } - return g; -} -function Db(a, b, c) { - for (var d = S(), e = [], g = 0, f; g < b.length; g++) { - f = b[g]; - for (var h = 0; h < f.length; h++) { - d[f[h]] = 1; - } - } - if (c) { - for (b = 0; b < a.length; b++) { - c = a[b], d[c] && (e.push(c), d[c] = 0); - } - } else { - for (b = 0; b < a.result.length; b++) { - for (c = a.result[b], f = 0; f < c.length; f++) { - g = c[f], d[g] && ((e[b] || (e[b] = [])).push(g), d[g] = 0); - } - } - } - return e; -} -;S(); -function Eb(a, b, c, d, e) { +;function Db(a, b, c, d, e) { if ("string" === typeof e) { - var g = e; + var f = e; e = ""; } else { - g = e.template; + f = e.template; } - if (!g) { + if (!f) { throw Error('No template pattern was specified by the search option "highlight"'); } - var f = g.indexOf("$1"); - if (-1 === f) { - throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + g); + var h = f.indexOf("$1"); + if (-1 === h) { + throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); } - var h = g.substring(f + 2); - f = g.substring(0, f); - var k = e && e.boundary, l = !e || !1 !== e.clip, m = e && e.merge && h && f && new RegExp(h + " " + f, "g"); + var g = f.substring(h + 2); + h = f.substring(0, h); + var k = e && e.boundary, m = !e || !1 !== e.clip, l = e && e.merge && g && h && new RegExp(g + " " + h, "g"); e = e && e.ellipsis; var p = 0; if ("object" === typeof e) { @@ -2294,172 +2063,172 @@ function Eb(a, b, c, d, e) { k = k.total || 9e5; } p = new Map(); - for (var u, v = 0, x, y; v < b.length; v++) { + for (var v, u = 0, z, x; u < b.length; u++) { if (d) { - var E = b; - y = d; + var C = b; + x = d; } else { - E = b[v]; - y = E.field; - if (!y) { + C = b[u]; + x = C.field; + if (!x) { continue; } - E = E.result; + C = C.result; } - u = c.get(y); - x = u.encoder; - u = p.get(x); - "string" !== typeof u && (u = x.encode(a), p.set(x, u)); - for (var B = 0; B < E.length; B++) { - var r = E[B].doc; - if (r && (r = Ea(r, y))) { - var A = r.trim().split(/\s+/); - if (A.length) { + v = c.get(x); + z = v.encoder; + v = p.get(z); + "string" !== typeof v && (v = z.encode(a), p.set(z, v)); + for (var D = 0; D < C.length; D++) { + var r = C[D].doc; + if (r && (r = Ea(r, x))) { + var y = r.trim().split(/\s+/); + if (y.length) { r = ""; - for (var F = [], U = [], G = -1, N = -1, Q = 0, D = 0; D < A.length; D++) { - var R = A[D], W = x.encode(R); + for (var F = [], U = [], G = -1, N = -1, Q = 0, E = 0; E < y.length; E++) { + var R = y[E], W = z.encode(R); W = 1 < W.length ? W.join(" ") : W[0]; var O = void 0; if (W && R) { - for (var L = R.length, M = (x.split ? R.replace(x.split, "") : R).length - W.length, ba = "", oa = 0, z = 0; z < u.length; z++) { - var I = u[z]; + for (var L = R.length, M = (z.split ? R.replace(z.split, "") : R).length - W.length, ba = "", oa = 0, A = 0; A < v.length; A++) { + var I = v[A]; if (I) { var J = I.length; J += M; - oa && J <= oa || (I = W.indexOf(I), -1 < I && (ba = (I ? R.substring(0, I) : "") + f + R.substring(I, I + J) + h + (I + J < L ? R.substring(I + J) : ""), oa = J, O = !0)); + oa && J <= oa || (I = W.indexOf(I), -1 < I && (ba = (I ? R.substring(0, I) : "") + h + R.substring(I, I + J) + g + (I + J < L ? R.substring(I + J) : ""), oa = J, O = !0)); } } ba && (k && (0 > G && (G = r.length + (r ? 1 : 0)), N = r.length + (r ? 1 : 0) + ba.length, Q += L, U.push(F.length), F.push({match:ba})), r += (r ? " " : "") + ba); } if (!O) { - R = A[D], r += (r ? " " : "") + R, k && F.push({text:R}); + R = y[E], r += (r ? " " : "") + R, k && F.push({text:R}); } else if (k && Q >= k) { break; } } - Q = U.length * (g.length - 2); + Q = U.length * (f.length - 2); if (q || t || k && r.length - Q > k) { - if (Q = k + Q - 2 * n, D = N - G, 0 < q && (D += q), 0 < t && (D += t), D <= Q) { - A = q ? G - (0 < q ? q : 0) : G - ((Q - D) / 2 | 0), F = t ? N + (0 < t ? t : 0) : A + Q, l || (0 < A && " " !== r.charAt(A) && " " !== r.charAt(A - 1) && (A = r.indexOf(" ", A), 0 > A && (A = 0)), F < r.length && " " !== r.charAt(F - 1) && " " !== r.charAt(F) && (F = r.lastIndexOf(" ", F), F < N ? F = N : ++F)), r = (A ? e : "") + r.substring(A, F) + (F < r.length ? e : ""); + if (Q = k + Q - 2 * n, E = N - G, 0 < q && (E += q), 0 < t && (E += t), E <= Q) { + y = q ? G - (0 < q ? q : 0) : G - ((Q - E) / 2 | 0), F = t ? N + (0 < t ? t : 0) : y + Q, m || (0 < y && " " !== r.charAt(y) && " " !== r.charAt(y - 1) && (y = r.indexOf(" ", y), 0 > y && (y = 0)), F < r.length && " " !== r.charAt(F - 1) && " " !== r.charAt(F) && (F = r.lastIndexOf(" ", F), F < N ? F = N : ++F)), r = (y ? e : "") + r.substring(y, F) + (F < r.length ? e : ""); } else { N = []; Q = {}; G = {}; - D = {}; + E = {}; R = {}; W = {}; M = L = O = 0; for (oa = ba = 1;;) { I = void 0; - for (z = 0; z < U.length; z++) { - J = U[z]; + for (A = 0; A < U.length; A++) { + J = U[A]; if (M) { if (L !== M) { - if (D[z + 1]) { + if (E[A + 1]) { continue; } J += M; if (Q[J]) { O -= n; - G[z + 1] = 1; - D[z + 1] = 1; + G[A + 1] = 1; + E[A + 1] = 1; continue; } if (J >= F.length - 1) { if (J >= F.length) { - D[z + 1] = 1; - J >= A.length && (G[z + 1] = 1); + E[A + 1] = 1; + J >= y.length && (G[A + 1] = 1); continue; } O -= n; } r = F[J].text; - var V = t && W[z]; + var V = t && W[A]; if (V) { if (0 < V) { if (r.length > V) { - if (D[z + 1] = 1, l) { + if (E[A + 1] = 1, m) { r = r.substring(0, V); } else { continue; } } (V -= r.length) || (V = -1); - W[z] = V; + W[A] = V; } else { - D[z + 1] = 1; + E[A + 1] = 1; continue; } } if (O + r.length + 1 <= k) { - r = " " + r, N[z] += r; - } else if (l) { - I = k - O - 1, 0 < I && (r = " " + r.substring(0, I), N[z] += r), D[z + 1] = 1; + r = " " + r, N[A] += r; + } else if (m) { + I = k - O - 1, 0 < I && (r = " " + r.substring(0, I), N[A] += r), E[A + 1] = 1; } else { - D[z + 1] = 1; + E[A + 1] = 1; continue; } } else { - if (D[z]) { + if (E[A]) { continue; } J -= L; if (Q[J]) { O -= n; - D[z] = 1; - G[z] = 1; + E[A] = 1; + G[A] = 1; continue; } if (0 >= J) { if (0 > J) { - D[z] = 1; - G[z] = 1; + E[A] = 1; + G[A] = 1; continue; } O -= n; } r = F[J].text; - if (V = q && R[z]) { + if (V = q && R[A]) { if (0 < V) { if (r.length > V) { - if (D[z] = 1, l) { + if (E[A] = 1, m) { r = r.substring(r.length - V); } else { continue; } } (V -= r.length) || (V = -1); - R[z] = V; + R[A] = V; } else { - D[z] = 1; + E[A] = 1; continue; } } if (O + r.length + 1 <= k) { - r += " ", N[z] = r + N[z]; - } else if (l) { - I = r.length + 1 - (k - O), 0 <= I && I < r.length && (r = r.substring(I) + " ", N[z] = r + N[z]), D[z] = 1; + r += " ", N[A] = r + N[A]; + } else if (m) { + I = r.length + 1 - (k - O), 0 <= I && I < r.length && (r = r.substring(I) + " ", N[A] = r + N[A]), E[A] = 1; } else { - D[z] = 1; + E[A] = 1; continue; } } } else { r = F[J].match; - q && (R[z] = q); - t && (W[z] = t); - z && O++; + q && (R[A] = q); + t && (W[A] = t); + A && O++; I = void 0; - J ? !z && n && (O += n) : (G[z] = 1, D[z] = 1); - J >= A.length - 1 ? I = 1 : J < F.length - 1 && F[J + 1].match ? I = 1 : n && (O += n); - O -= g.length - 2; - if (!z || O + r.length <= k) { - N[z] = r; + J ? !A && n && (O += n) : (G[A] = 1, E[A] = 1); + J >= y.length - 1 ? I = 1 : J < F.length - 1 && F[J + 1].match ? I = 1 : n && (O += n); + O -= f.length - 2; + if (!A || O + r.length <= k) { + N[A] = r; } else { - I = ba = oa = G[z] = 0; + I = ba = oa = G[A] = 0; break; } - I && (G[z + 1] = 1, D[z + 1] = 1); + I && (G[A + 1] = 1, E[A + 1] = 1); } O += r.length; I = Q[J] = 1; @@ -2475,14 +2244,14 @@ function Eb(a, b, c, d, e) { } } r = ""; - for (A = 0; A < N.length; A++) { - F = (A && G[A] ? " " : (A && !e ? " " : "") + e) + N[A], r += F; + for (y = 0; y < N.length; y++) { + F = (y && G[y] ? " " : (y && !e ? " " : "") + e) + N[y], r += F; } e && !G[N.length] && (r += e); } } - m && (r = r.replace(m, " ")); - E[B].highlight = r; + l && (r = r.replace(l, " ")); + C[D].highlight = r; } } } @@ -2492,91 +2261,363 @@ function Eb(a, b, c, d, e) { } return b; } -;pb.prototype.search = function(a, b, c, d) { +;function Z(a, b) { + if (!this || this.constructor !== Z) { + return new Z(a, b); + } + var c = 0, d, e; + if (a && a.index) { + var f = a; + b = f.index; + c = f.boost || 0; + if (d = f.query) { + var h = f.field || f.pluck; + var g = f.resolve; + a = f.async || f.queue; + f.resolve = !1; + f.index = null; + a = a ? b.searchAsync(f) : b.search(f); + f.resolve = g; + f.index = b; + a = a.result || a; + } else { + a = []; + } + } + if (a && a.then) { + var k = this; + a = a.then(function(p) { + k.C[0] = k.result = p.result || p; + wb(k); + }); + var m = [a]; + a = []; + var l = new Promise(function(p) { + e = p; + }); + } + this.index = b || null; + this.result = a || []; + this.h = c; + this.C = m || []; + this.await = l || null; + this.return = e || null; + this.query = d || ""; + this.field = h || ""; +} +w = Z.prototype; +w.limit = function(a) { + if (this.await) { + var b = this; + this.C.push(function() { + b.limit(a); + return b.result; + }); + } else { + if (this.result.length) { + for (var c = [], d = 0, e = void 0; d < this.result.length; d++) { + if (e = this.result[d]) { + if (e.length <= a) { + if (c[d] = e, a -= e.length, !a) { + break; + } + } else { + c[d] = e.slice(0, a); + break; + } + } + } + this.result = c; + } + } + return this; +}; +w.offset = function(a) { + if (this.await) { + var b = this; + this.C.push(function() { + b.offset(a); + return b.result; + }); + } else { + if (this.result.length) { + for (var c = [], d = 0, e = void 0; d < this.result.length; d++) { + if (e = this.result[d]) { + e.length <= a ? a -= e.length : (c[d] = e.slice(a), a = 0); + } + } + this.result = c; + } + } + return this; +}; +w.boost = function(a) { + if (this.await) { + var b = this; + this.C.push(function() { + b.boost(a); + return b.result; + }); + } else { + this.h += a; + } + return this; +}; +function wb(a, b) { + var c = a.result, d = a.await; + a.await = null; + for (var e = 0, f; e < a.C.length; e++) { + if (f = a.C[e]) { + if ("function" === typeof f) { + c = f(), a.C[e] = c = c.result || c, e--; + } else if (f.H) { + c = f.H(), a.C[e] = c = c.result || c, e--; + } else if (f.then) { + return a.await = d; + } + } + } + d = a.return; + a.C = []; + a.return = null; + b || d(c); + return c; +} +w.resolve = function(a, b, c, d, e) { + var f = this.await ? wb(this, !0) : this.result; + if (f.then) { + var h = this; + return f.then(function() { + return h.resolve(a, b, c, d, e); + }); + } + f.length && ("object" === typeof a ? (d = a.highlight, c = !!d || a.enrich, b = a.offset, a = a.limit) : c = !!d || c, f = e ? c ? tb.call(this.index, f) : f : sb.call(this.index, f, a || 100, b, c)); + return this.finalize(f, d); +}; +w.finalize = function(a, b) { + if (a.then) { + var c = this; + return a.then(function(e) { + return c.finalize(e, b); + }); + } + b && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); + b && a.length && this.query && (a = Db(this.query, a, this.index.index, this.field, b)); + var d = this.return; + this.index = this.result = this.C = this.await = this.return = null; + this.query = this.field = ""; + d && d(a); + return a; +}; +function Ab(a, b, c, d, e, f, h) { + var g = a.length, k = []; + var m = S(); + for (var l = 0, p = void 0, n, q; l < b; l++) { + for (var t = 0; t < g; t++) { + var v = a[t]; + if (l < v.length && (p = v[l])) { + for (var u = 0; u < p.length; u++) { + n = p[u]; + (v = m[n]) ? m[n]++ : (v = 0, m[n] = 1); + q = k[v] || (k[v] = []); + if (!h) { + var z = l + (t || !e ? 0 : f || 0); + q = q[z] || (q[z] = []); + } + q.push(n); + if (h && c && v === g - 1 && q.length - d === c) { + return d ? q.slice(d) : q; + } + } + } + } + } + if (a = k.length) { + if (e) { + k = 1 < k.length ? yb(k, c, d, h, f) : (k = k[0]) && c && k.length > c || d ? k.slice(d, c + d) : k; + } else { + if (a < g) { + return []; + } + k = k[a - 1]; + if (c || d) { + if (h) { + if (k.length > c || d) { + k = k.slice(d, c + d); + } + } else { + e = []; + for (f = 0; f < k.length; f++) { + if (h = k[f]) { + if (d && h.length > d) { + d -= h.length; + } else { + if (c && h.length > c || d) { + h = h.slice(d, c + d), c -= h.length, d && (d -= h.length); + } + e.push(h); + if (!c) { + break; + } + } + } + } + k = e; + } + } + } + } + return k; +} +function yb(a, b, c, d, e) { + var f = [], h = S(), g = a.length, k; + if (d) { + for (e = g - 1; 0 <= e; e--) { + if (k = (d = a[e]) && d.length) { + for (g = 0; g < k; g++) { + var m = d[g]; + if (!h[m]) { + if (h[m] = 1, c) { + c--; + } else { + if (f.push(m), f.length === b) { + return f; + } + } + } + } + } + } + } else { + for (var l = g - 1, p, n = 0; 0 <= l; l--) { + p = a[l]; + for (var q = 0; q < p.length; q++) { + if (k = (d = p[q]) && d.length) { + for (var t = 0; t < k; t++) { + if (m = d[t], !h[m]) { + if (h[m] = 1, c) { + c--; + } else { + var v = (q + (l < g - 1 ? e || 0 : 0)) / (l + 1) | 0; + (f[v] || (f[v] = [])).push(m); + if (++n === b) { + return f; + } + } + } + } + } + } + } + } + return f; +} +function Eb(a, b, c) { + for (var d = S(), e = [], f = 0, h; f < b.length; f++) { + h = b[f]; + for (var g = 0; g < h.length; g++) { + d[h[g]] = 1; + } + } + if (c) { + for (b = 0; b < a.length; b++) { + c = a[b], d[c] && (e.push(c), d[c] = 0); + } + } else { + for (b = 0; b < a.result.length; b++) { + for (c = a.result[b], h = 0; h < c.length; h++) { + f = c[h], d[f] && ((e[b] || (e[b] = [])).push(f), d[f] = 0); + } + } + } + return e; +} +;S(); +pb.prototype.search = function(a, b, c, d) { c || (!b && Ca(a) ? (c = a, a = "") : Ca(b) && (c = b, b = 0)); - var e = [], g = [], f = 0, h = !0; + var e = [], f = [], h = 0, g = !0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; var k = c.pluck; - var l = c.merge; - var m = c.boost; + var m = c.merge; + var l = c.boost; var p = k || c.field || (p = c.index) && (p.index ? null : p); var n = this.tag && c.tag; var q = c.suggest; - h = !1 !== c.resolve; + g = !1 !== c.resolve; var t = c.cache; - this.store && c.highlight && !h ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && c.enrich && !h && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var u = h && this.store && c.highlight; - var v = !!u || h && this.store && c.enrich; + this.store && c.highlight && !g ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && c.enrich && !g && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var v = g && this.store && c.highlight; + var u = !!v || g && this.store && c.enrich; b = c.limit || b; - var x = c.offset || 0; - b || (b = h ? 100 : 0); + var z = c.offset || 0; + b || (b = g ? 100 : 0); if (n && (!this.db || !d)) { n.constructor !== Array && (n = [n]); - for (var y = [], E = 0, B = void 0; E < n.length; E++) { - B = n[E]; - if (T(B)) { + for (var x = [], C = 0, D = void 0; C < n.length; C++) { + D = n[C]; + if (T(D)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (B.field && B.tag) { - var r = B.tag; + if (D.field && D.tag) { + var r = D.tag; if (r.constructor === Array) { - for (var A = 0; A < r.length; A++) { - y.push(B.field, r[A]); + for (var y = 0; y < r.length; y++) { + x.push(D.field, r[y]); } } else { - y.push(B.field, r); + x.push(D.field, r); } } else { - r = Object.keys(B); - A = 0; - for (var F = void 0, U = void 0; A < r.length; A++) { - if (F = r[A], U = B[F], U.constructor === Array) { + r = Object.keys(D); + y = 0; + for (var F = void 0, U = void 0; y < r.length; y++) { + if (F = r[y], U = D[F], U.constructor === Array) { for (var G = 0; G < U.length; G++) { - y.push(F, U[G]); + x.push(F, U[G]); } } else { - y.push(F, U); + x.push(F, U); } } } } - if (!y.length) { + if (!x.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - n = y; + n = x; if (!a) { - g = []; - if (y.length) { - for (n = 0; n < y.length; n += 2) { + f = []; + if (x.length) { + for (n = 0; n < x.length; n += 2) { d = void 0; if (this.db) { - d = this.index.get(y[n]); + d = this.index.get(x[n]); if (!d) { - console.warn("Tag '" + y[n] + ":" + y[n + 1] + "' will be skipped because there is no field '" + y[n] + "'."); + console.warn("Tag '" + x[n] + ":" + x[n + 1] + "' will be skipped because there is no field '" + x[n] + "'."); continue; } - g.push(d = d.db.tag(y[n + 1], b, x, v)); + f.push(d = d.db.tag(x[n + 1], b, z, u)); } else { - d = Fb.call(this, y[n], y[n + 1], b, x, v); + d = Fb.call(this, x[n], x[n + 1], b, z, u); } - e.push(h ? {field:y[n], tag:y[n + 1], result:d} : [d]); + e.push(g ? {field:x[n], tag:x[n + 1], result:d} : [d]); } } - if (g.length) { + if (f.length) { var N = this; - return Promise.all(g).then(function(L) { + return Promise.all(f).then(function(L) { for (var M = 0; M < L.length; M++) { - h ? e[M].result = L[M] : e[M] = L[M]; + g ? e[M].result = L[M] : e[M] = L[M]; } - return h ? e : new Z(1 < e.length ? Ab(e, 1, 0, 0, q, m) : e[0], N); + return g ? e : new Z(1 < e.length ? Ab(e, 1, 0, 0, q, l) : e[0], N); }); } - return h ? e : new Z(1 < e.length ? Ab(e, 1, 0, 0, q, m) : e[0], this); + return g ? e : new Z(1 < e.length ? Ab(e, 1, 0, 0, q, l) : e[0], this); } } - if (!h && !k) { + if (!g && !k) { if (p = p || this.field) { T(p) ? k = p : (p.constructor === Array && 1 === p.length && (p = p[0]), k = p.field || p.index); } @@ -2587,139 +2628,139 @@ function Eb(a, b, c, d, e) { p && p.constructor !== Array && (p = [p]); } p || (p = this.field); - y = (this.worker || this.db) && !d && []; - E = 0; - for (A = B = r = void 0; E < p.length; E++) { - if (B = p[E], !this.db || !this.tag || this.M[E]) { + x = (this.worker || this.db) && !d && []; + C = 0; + for (y = D = r = void 0; C < p.length; C++) { + if (D = p[C], !this.db || !this.tag || this.M[C]) { r = void 0; - T(B) || (r = B, B = r.field, a = r.query || a, b = Ba(r.limit, b), x = Ba(r.offset, x), q = Ba(r.suggest, q), u = h && this.store && Ba(r.highlight, u), v = !!u || h && this.store && Ba(r.enrich, v), t = Ba(r.cache, t)); + T(D) || (r = D, D = r.field, a = r.query || a, b = Ba(r.limit, b), z = Ba(r.offset, z), q = Ba(r.suggest, q), v = g && this.store && Ba(r.highlight, v), u = !!v || g && this.store && Ba(r.enrich, u), t = Ba(r.cache, t)); if (d) { - r = d[E]; + r = d[C]; } else { - A = r || c || {}; - F = A.enrich; - r = this.index.get(B); + y = r || c || {}; + F = y.enrich; + r = this.index.get(D); if (n) { if (this.db) { - A.tag = n; + y.tag = n; var Q = r.db.support_tag_search; - A.field = p; + y.field = p; } - !Q && F && (A.enrich = !1); + !Q && F && (y.enrich = !1); } - r = t ? r.searchCache(a, b, A) : r.search(a, b, A); - F && (A.enrich = F); - if (y) { - y[E] = r; + r = t ? r.searchCache(a, b, y) : r.search(a, b, y); + F && (y.enrich = F); + if (x) { + x[C] = r; continue; } } - A = (r = r.result || r) && r.length; - if (n && A) { + y = (r = r.result || r) && r.length; + if (n && y) { F = []; U = 0; if (this.db && d) { if (!Q) { for (G = p.length; G < d.length; G++) { - var D = d[G]; - if (D && D.length) { - U++, F.push(D); + var E = d[G]; + if (E && E.length) { + U++, F.push(E); } else if (!q) { - return h ? e : new Z(e, this); + return g ? e : new Z(e, this); } } } } else { G = 0; - for (var R = D = void 0; G < n.length; G += 2) { - D = this.tag.get(n[G]); - if (!D) { + for (var R = E = void 0; G < n.length; G += 2) { + E = this.tag.get(n[G]); + if (!E) { if (console.warn("Tag '" + n[G] + ":" + n[G + 1] + "' will be skipped because there is no field '" + n[G] + "'."), q) { continue; } else { - return h ? e : new Z(e, this); + return g ? e : new Z(e, this); } } - if (R = (D = D && D.get(n[G + 1])) && D.length) { - U++, F.push(D); + if (R = (E = E && E.get(n[G + 1])) && E.length) { + U++, F.push(E); } else if (!q) { - return h ? e : new Z(e, this); + return g ? e : new Z(e, this); } } } if (U) { - r = Db(r, F, h); - A = r.length; - if (!A && !q) { - return h ? r : new Z(r, this); + r = Eb(r, F, g); + y = r.length; + if (!y && !q) { + return g ? r : new Z(r, this); } U--; } } - if (A) { - g[f] = B, e.push(r), f++; + if (y) { + f[h] = D, e.push(r), h++; } else if (1 === p.length) { - return h ? e : new Z(e, this); + return g ? e : new Z(e, this); } } } - if (y) { + if (x) { if (this.db && n && n.length && !Q) { - for (v = 0; v < n.length; v += 2) { - g = this.index.get(n[v]); - if (!g) { - if (console.warn("Tag '" + n[v] + ":" + n[v + 1] + "' was not found because there is no field '" + n[v] + "'."), q) { + for (u = 0; u < n.length; u += 2) { + f = this.index.get(n[u]); + if (!f) { + if (console.warn("Tag '" + n[u] + ":" + n[u + 1] + "' was not found because there is no field '" + n[u] + "'."), q) { continue; } else { - return h ? e : new Z(e, this); + return g ? e : new Z(e, this); } } - y.push(g.db.tag(n[v + 1], b, x, !1)); + x.push(f.db.tag(n[u + 1], b, z, !1)); } } var W = this; - return Promise.all(y).then(function(L) { - c && (c.resolve = h); + return Promise.all(x).then(function(L) { + c && (c.resolve = g); L.length && (L = W.search(a, b, c, L)); return L; }); } - if (!f) { - return h ? e : new Z(e, this); + if (!h) { + return g ? e : new Z(e, this); } - if (k && (!v || !this.store)) { - return e = e[0], h ? e : new Z(e, this); + if (k && (!u || !this.store)) { + return e = e[0], g ? e : new Z(e, this); } - y = []; - for (x = 0; x < g.length; x++) { - n = e[x]; - v && n.length && "undefined" === typeof n[0].doc && (this.db ? y.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = tb.call(this, n)); + x = []; + for (z = 0; z < f.length; z++) { + n = e[z]; + u && n.length && "undefined" === typeof n[0].doc && (this.db ? x.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = tb.call(this, n)); if (k) { - return h ? u ? Eb(a, n, this.index, k, u) : n : new Z(n, this); + return g ? v ? Db(a, n, this.index, k, v) : n : new Z(n, this); } - e[x] = {field:g[x], result:n}; + e[z] = {field:f[z], result:n}; } - if (v && this.db && y.length) { + if (u && this.db && x.length) { var O = this; - return Promise.all(y).then(function(L) { + return Promise.all(x).then(function(L) { for (var M = 0; M < L.length; M++) { e[M].result = L[M]; } - u && (e = Eb(a, e, O.index, k, u)); - return l ? Gb(e) : e; + v && (e = Db(a, e, O.index, k, v)); + return m ? Gb(e) : e; }); } - u && (e = Eb(a, e, this.index, k, u)); - return l ? Gb(e) : e; + v && (e = Db(a, e, this.index, k, v)); + return m ? Gb(e) : e; }; function Gb(a) { - for (var b = [], c = S(), d = S(), e = 0, g, f, h = void 0, k, l, m; e < a.length; e++) { - g = a[e]; - f = g.field; - g = g.result; - for (var p = 0; p < g.length; p++) { - if (k = g[p], "object" !== typeof k ? k = {id:h = k} : h = k.id, (l = c[h]) ? l.push(f) : (k.field = c[h] = [f], b.push(k)), m = k.highlight) { - l = d[h], l || (d[h] = l = {}, k.highlight = l), l[f] = m; + for (var b = [], c = S(), d = S(), e = 0, f, h, g = void 0, k, m, l; e < a.length; e++) { + f = a[e]; + h = f.field; + f = f.result; + for (var p = 0; p < f.length; p++) { + if (k = f[p], "object" !== typeof k ? k = {id:g = k} : g = k.id, (m = c[g]) ? m.push(h) : (k.field = c[g] = [h], b.push(k)), l = k.highlight) { + m = d[g], m || (d[g] = m = {}, k.highlight = m), m[h] = l; } } } @@ -2796,20 +2837,20 @@ function tb(a) { if (this.worker) { this.fastupdate = !1; a = []; - c = C(this.index.values()); + c = B(this.index.values()); for (b = c.next(); !b.done; b = c.next()) { b = b.value, b.then && a.push(b); } if (a.length) { - var g = this; - return Promise.all(a).then(function(f) { - for (var h = 0, k = C(g.index.entries()), l = k.next(); !l.done; l = k.next()) { - var m = l.value; - l = m[0]; - m = m[1]; - m.then && (m = f[h], g.index.set(l, m), h++); + var f = this; + return Promise.all(a).then(function(h) { + for (var g = 0, k = B(f.index.entries()), m = k.next(); !m.done; m = k.next()) { + var l = m.value; + m = l[0]; + l = l[1]; + l.then && (l = h[g], f.index.set(m, l), g++); } - return g; + return f; }); } } else { @@ -2835,38 +2876,38 @@ w.mount = function(a) { c = []; d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; e = 0; - var g = void 0; - for (g = void 0; e < b.length; e++) { - d.field = g = b[e]; - g = this.index.get(g); - var f = new a.constructor(a.id, d); - f.id = a.id; - c[e] = f.mount(g); - g.document = !0; - e ? g.bypass = !0 : g.store = this.store; + var f = void 0; + for (f = void 0; e < b.length; e++) { + d.field = f = b[e]; + f = this.index.get(f); + var h = new a.constructor(a.id, d); + h.id = a.id; + c[e] = h.mount(f); + f.document = !0; + e ? f.bypass = !0 : f.store = this.store; } - var h = this; + var g = this; return this.db = Promise.all(c).then(function() { - h.db = !0; + g.db = !0; }); }; w.commit = function(a, b) { - var c = this, d, e, g, f; - return wa(function(h) { - if (1 == h.h) { + var c = this, d, e, f, h; + return wa(function(g) { + if (1 == g.h) { d = []; - e = C(c.index.values()); - for (g = e.next(); !g.done; g = e.next()) { - f = g.value, d.push(f.commit(a, b)); + e = B(c.index.values()); + for (f = e.next(); !f.done; f = e.next()) { + h = f.value, d.push(h.commit(a, b)); } - return K(h, Promise.all(d), 2); + return K(g, Promise.all(d), 2); } c.reg.clear(); - h.h = 0; + g.h = 0; }); }; w.destroy = function() { - for (var a = [], b = C(this.index.values()), c = b.next(); !c.done; c = b.next()) { + for (var a = [], b = B(this.index.values()), c = b.next(); !c.done; c = b.next()) { a.push(c.value.destroy()); } return Promise.all(a); @@ -2874,18 +2915,18 @@ w.destroy = function() { function Ib(a, b) { var c = new Map(), d = b.index || b.field || b; T(d) && (d = [d]); - for (var e = 0, g, f = void 0; e < d.length; e++) { - g = d[e]; - T(g) || (f = g, g = g.field); - f = Ca(f) ? Object.assign({}, a, f) : a; + for (var e = 0, f, h = void 0; e < d.length; e++) { + f = d[e]; + T(f) || (h = f, f = f.field); + h = Ca(h) ? Object.assign({}, a, h) : a; if (this.worker) { - var h = (h = f.encoder) && h.encode ? h : new Ka("string" === typeof h ? Ua[h] : h || {}); - h = new mb(f, h); - c.set(g, h); + var g = (g = h.encoder) && g.encode ? g : new Ka("string" === typeof g ? Ua[g] : g || {}); + g = new mb(h, g); + c.set(f, g); } - this.worker || c.set(g, new Y(f, this.reg)); - f.custom ? this.M[e] = f.custom : (this.M[e] = Hb(g, this.T), f.filter && ("string" === typeof this.M[e] && (this.M[e] = new String(this.M[e])), this.M[e].S = f.filter)); - this.field[e] = g; + this.worker || c.set(f, new Y(h, this.reg)); + h.custom ? this.M[e] = h.custom : (this.M[e] = Hb(f, this.T), h.filter && ("string" === typeof this.M[e] && (this.M[e] = new String(this.M[e])), this.M[e].S = h.filter)); + this.field[e] = f; } if (this.J) { for (a = b.store, T(a) && (a = [a]), b = 0; b < a.length; b++) { @@ -2909,19 +2950,19 @@ w.update = function(a, b) { }; w.remove = function(a) { Ca(a) && (a = Ea(a, this.key)); - for (var b = C(this.index.values()), c = b.next(); !c.done; c = b.next()) { + for (var b = B(this.index.values()), c = b.next(); !c.done; c = b.next()) { c.value.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { - for (b = C(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = B(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c = c.value; - for (var d = C(c), e = d.next(); !e.done; e = d.next()) { - var g = e.value; - e = g[0]; - g = g[1]; - var f = g.indexOf(a); - -1 < f && (1 < g.length ? g.splice(f, 1) : c.delete(e)); + for (var d = B(c), e = d.next(); !e.done; e = d.next()) { + var f = e.value; + e = f[0]; + f = f[1]; + var h = f.indexOf(a); + -1 < h && (1 < f.length ? f.splice(h, 1) : c.delete(e)); } } } @@ -2932,11 +2973,11 @@ w.remove = function(a) { return this; }; w.clear = function() { - for (var a = [], b = C(this.index.values()), c = b.next(); !c.done; c = b.next()) { + for (var a = [], b = B(this.index.values()), c = b.next(); !c.done; c = b.next()) { c = c.value.clear(), c.then && a.push(c); } if (this.tag) { - for (b = C(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = B(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c.value.clear(); } } @@ -2948,7 +2989,7 @@ w.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; w.cleanup = function() { - for (var a = C(this.index.values()), b = a.next(); !b.done; b = a.next()) { + for (var a = B(this.index.values()), b = a.next(); !b.done; b = a.next()) { b.value.cleanup(); } return this; @@ -2971,7 +3012,7 @@ function Lb(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 5000 | 0); - a = C(a.entries()); + a = B(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { d.push(e.value), d.length === b && (c.push(d), d = []); } @@ -2989,7 +3030,7 @@ function Nb(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 1000 | 0); - a = C(a.entries()); + a = B(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { e = e.value, d.push([e[0], Lb(e[1])[0]]), d.length === b && (c.push(d), d = []); } @@ -3005,7 +3046,7 @@ function Ob(a, b) { } function Pb(a) { var b = [], c = []; - a = C(a.keys()); + a = B(a.keys()); for (var d = a.next(); !d.done; d = a.next()) { c.push(d.value), 250000 === c.length && (b.push(c), c = []); } @@ -3019,19 +3060,19 @@ function Qb(a, b) { } return b; } -function Rb(a, b, c, d, e, g, f) { - f = void 0 === f ? 0 : f; - var h = d && d.constructor === Array, k = h ? d.shift() : d; +function Rb(a, b, c, d, e, f, h) { + h = void 0 === h ? 0 : h; + var g = d && d.constructor === Array, k = g ? d.shift() : d; if (!k) { - return this.export(a, b, e, g + 1); + return this.export(a, b, e, f + 1); } - if ((k = a((b ? b + "." : "") + (f + 1) + "." + c, JSON.stringify(k))) && k.then) { - var l = this; + if ((k = a((b ? b + "." : "") + (h + 1) + "." + c, JSON.stringify(k))) && k.then) { + var m = this; return k.then(function() { - return Rb.call(l, a, b, c, h ? d : null, e, g, f + 1); + return Rb.call(m, a, b, c, g ? d : null, e, f, h + 1); }); } - return Rb.call(this, a, b, c, h ? d : null, e, g, f + 1); + return Rb.call(this, a, b, c, g ? d : null, e, f, h + 1); } function Jb(a, b, c, d) { c = void 0 === c ? 0 : c; @@ -3039,33 +3080,33 @@ function Jb(a, b, c, d) { if (c < this.field.length) { var e = this.field[c]; if ((b = this.index.get(e).export(a, e, c, d = 1)) && b.then) { - var g = this; + var f = this; return b.then(function() { - return g.export(a, e, c + 1); + return f.export(a, e, c + 1); }); } return this.export(a, e, c + 1); } switch(d) { case 0: - var f = "reg"; - var h = Pb(this.reg); + var h = "reg"; + var g = Pb(this.reg); b = null; break; case 1: - f = "tag"; - h = this.tag && Nb(this.tag, this.reg.size); + h = "tag"; + g = this.tag && Nb(this.tag, this.reg.size); b = null; break; case 2: - f = "doc"; - h = this.store && Lb(this.store); + h = "doc"; + g = this.store && Lb(this.store); b = null; break; default: return; } - return Rb.call(this, a, b, f, h, c, d); + return Rb.call(this, a, b, h, g, c, d); } function Kb(a, b) { var c = a.split("."); @@ -3089,7 +3130,7 @@ function Kb(a, b) { } if (this.worker) { b = []; - d = C(this.index.values()); + d = B(this.index.values()); for (c = d.next(); !c.done; c = d.next()) { b.push(c.value.import(a)); } @@ -3106,21 +3147,21 @@ function Kb(a, b) { } function Sb(a, b) { var c = ""; - a = C(a.entries()); + a = B(a.entries()); for (var d = a.next(); !d.done; d = a.next()) { var e = d.value; d = e[0]; e = e[1]; - for (var g = "", f = 0, h; f < e.length; f++) { - h = e[f] || [""]; - for (var k = "", l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === b ? '"' + h[l] + '"' : h[l]); + for (var f = "", h = 0, g; h < e.length; h++) { + g = e[h] || [""]; + for (var k = "", m = 0; m < g.length; m++) { + k += (k ? "," : "") + ("string" === b ? '"' + g[m] + '"' : g[m]); } k = "[" + k + "]"; - g += (g ? "," : "") + k; + f += (f ? "," : "") + k; } - g = '["' + d + '",[' + g + "]]"; - c += (c ? "," : "") + g; + f = '["' + d + '",[' + f + "]]"; + c += (c ? "," : "") + f; } return c; } @@ -3128,13 +3169,13 @@ function Sb(a, b) { var c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { - for (var d = 0, e = void 0, g = void 0; d < c.length; d++) { - if ((e = c[d]) && (g = e.length)) { - if (e[g - 1] === a) { + for (var d = 0, e = void 0, f = void 0; d < c.length; d++) { + if ((e = c[d]) && (f = e.length)) { + if (e[f - 1] === a) { e.pop(); } else { - var f = e.indexOf(a); - 0 <= f && e.splice(f, 1); + var h = e.indexOf(a); + 0 <= h && e.splice(h, 1); } } } @@ -3150,23 +3191,23 @@ function Sb(a, b) { function Tb(a, b) { var c = 0, d = "undefined" === typeof b; if (a.constructor === Array) { - for (var e = 0, g = void 0, f, h = void 0; e < a.length; e++) { - if ((g = a[e]) && g.length) { + for (var e = 0, f = void 0, h, g = void 0; e < a.length; e++) { + if ((f = a[e]) && f.length) { if (d) { return 1; } - f = g.indexOf(b); - if (0 <= f) { - if (1 < g.length) { - return g.splice(f, 1), 1; + h = f.indexOf(b); + if (0 <= h) { + if (1 < f.length) { + return f.splice(h, 1), 1; } delete a[e]; if (c) { return 1; } - h = 1; + g = 1; } else { - if (h) { + if (g) { return 1; } c++; @@ -3174,8 +3215,8 @@ function Tb(a, b) { } } } else { - for (d = C(a.entries()), e = d.next(); !e.done; e = d.next()) { - e = e.value, g = e[0], Tb(e[1], b) ? c++ : a.delete(g); + for (d = B(a.entries()), e = d.next(); !e.done; e = d.next()) { + e = e.value, f = e[0], Tb(e[1], b) ? c++ : a.delete(f); } } return c; @@ -3190,43 +3231,43 @@ Y.prototype.add = function(a, b, c, d) { b = this.encoder.encode(b, !d); var e = b.length; if (e) { - for (var g = S(), f = S(), h = this.resolution, k = 0; k < e; k++) { - var l = b[this.rtl ? e - 1 - k : k], m = l.length; - if (m && (d || !f[l])) { - var p = this.score ? this.score(b, l, k, null, 0) : Wb(h, e, k), n = ""; + for (var f = S(), h = S(), g = this.resolution, k = 0; k < e; k++) { + var m = b[this.rtl ? e - 1 - k : k], l = m.length; + if (l && (d || !h[m])) { + var p = this.score ? this.score(b, m, k, null, 0) : Wb(g, e, k), n = ""; switch(this.tokenize) { case "full": - if (2 < m) { + if (2 < l) { p = 0; - for (var q; p < m; p++) { - for (var t = m; t > p; t--) { - n = l.substring(p, t), q = this.rtl ? m - 1 - p : p, q = this.score ? this.score(b, l, k, n, q) : Wb(h, e, k, m, q), Xb(this, f, n, q, a, c); + for (var q; p < l; p++) { + for (var t = l; t > p; t--) { + n = m.substring(p, t), q = this.rtl ? l - 1 - p : p, q = this.score ? this.score(b, m, k, n, q) : Wb(g, e, k, l, q), Xb(this, h, n, q, a, c); } } break; } case "bidirectional": case "reverse": - if (1 < m) { - for (t = m - 1; 0 < t; t--) { - n = l[this.rtl ? m - 1 - t : t] + n, q = this.score ? this.score(b, l, k, n, t) : Wb(h, e, k, m, t), Xb(this, f, n, q, a, c); + if (1 < l) { + for (t = l - 1; 0 < t; t--) { + n = m[this.rtl ? l - 1 - t : t] + n, q = this.score ? this.score(b, m, k, n, t) : Wb(g, e, k, l, t), Xb(this, h, n, q, a, c); } n = ""; } case "forward": - if (1 < m) { - for (t = 0; t < m; t++) { - n += l[this.rtl ? m - 1 - t : t], Xb(this, f, n, p, a, c); + if (1 < l) { + for (t = 0; t < l; t++) { + n += m[this.rtl ? l - 1 - t : t], Xb(this, h, n, p, a, c); } break; } default: - if (Xb(this, f, l, p, a, c), d && 1 < e && k < e - 1) { - for (m = S(), n = this.ga, p = l, t = Math.min(d + 1, this.rtl ? k + 1 : e - k), q = m[p] = 1; q < t; q++) { - if ((l = b[this.rtl ? e - 1 - k - q : k + q]) && !m[l]) { - m[l] = 1; - var u = this.score ? this.score(b, p, k, l, q - 1) : Wb(n + (e / 2 > n ? 0 : 1), e, k, t - 1, q - 1), v = this.bidirectional && l > p; - Xb(this, g, v ? p : l, u, a, c, v ? l : p); + if (Xb(this, h, m, p, a, c), d && 1 < e && k < e - 1) { + for (l = S(), n = this.ga, p = m, t = Math.min(d + 1, this.rtl ? k + 1 : e - k), q = l[p] = 1; q < t; q++) { + if ((m = b[this.rtl ? e - 1 - k - q : k + q]) && !l[m]) { + l[m] = 1; + var v = this.score ? this.score(b, p, k, m, q - 1) : Wb(n + (e / 2 > n ? 0 : 1), e, k, t - 1, q - 1), u = this.bidirectional && m > p; + Xb(this, f, u ? p : m, v, a, c, u ? m : p); } } } @@ -3241,21 +3282,21 @@ Y.prototype.add = function(a, b, c, d) { this.db && (b || this.commit_task.push({del:a}), this.ea && Ub(this)); return this; }; -function Xb(a, b, c, d, e, g, f) { - var h = f ? a.ctx : a.map, k; - if (!b[c] || f && !(k = b[c])[f]) { - if (f ? (b = k || (b[c] = S()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { - if (h.length === Math.pow(2, 31) - 1) { - b = new Wa(h); +function Xb(a, b, c, d, e, f, h) { + var g = h ? a.ctx : a.map, k; + if (!b[c] || h && !(k = b[c])[h]) { + if (h ? (b = k || (b[c] = S()), b[h] = 1, (k = g.get(h)) ? g = k : g.set(h, g = new Map())) : b[c] = 1, (k = g.get(c)) ? g = k : g.set(c, g = k = []), g = g[d] || (g[d] = []), !f || !g.includes(e)) { + if (g.length === Math.pow(2, 31) - 1) { + b = new Wa(g); if (a.fastupdate) { - for (c = C(a.reg.values()), g = c.next(); !g.done; g = c.next()) { - g = g.value, g.includes(h) && (g[g.indexOf(h)] = b); + for (c = B(a.reg.values()), f = c.next(); !f.done; f = c.next()) { + f = f.value, f.includes(g) && (f[f.indexOf(g)] = b); } } - k[d] = h = b; + k[d] = g = b; } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + g.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(g) : a.reg.set(e, [g])); } } } @@ -3267,104 +3308,104 @@ function Wb(a, b, c, d, e) { if (c && c.cache) { return c.cache = !1, a = this.searchCache(a, b, c), c.cache = !0, a; } - var d = [], e = 0, g; + var d = [], e = 0, f; if (c) { a = c.query || a; b = c.limit || b; e = c.offset || 0; - var f = c.context; - var h = c.suggest; - var k = (g = c.resolve) && c.enrich; - var l = c.boost; - var m = c.resolution; + var h = c.context; + var g = c.suggest; + var k = (f = c.resolve) && c.enrich; + var m = c.boost; + var l = c.resolution; var p = this.db && c.tag; } - "undefined" === typeof g && (g = this.resolve); - f = this.depth && !1 !== f; - var n = this.encoder.encode(a, !f); + "undefined" === typeof f && (f = this.resolve); + h = this.depth && !1 !== h; + var n = this.encoder.encode(a, !h); var q = n.length; - b = b || (g ? 100 : 0); + b = b || (f ? 100 : 0); if (1 === q) { - return Yb.call(this, n[0], "", b, e, g, k, p); + return Yb.call(this, n[0], "", b, e, f, k, p); } - if (2 === q && f && !h) { - return Yb.call(this, n[1], n[0], b, e, g, k, p); + if (2 === q && h && !g) { + return Yb.call(this, n[1], n[0], b, e, f, k, p); } - var t = S(), u = 0; - if (f) { - var v = n[0]; - u = 1; + var t = S(), v = 0; + if (h) { + var u = n[0]; + v = 1; } - m || 0 === m || (m = v ? this.ga : this.resolution); + l || 0 === l || (l = u ? this.ga : this.resolution); if (this.db) { - if (this.db.search && (c = this.db.search(this, n, b, e, h, g, k, p), !1 !== c)) { + if (this.db.search && (c = this.db.search(this, n, b, e, g, f, k, p), !1 !== c)) { return c; } - var x = this; + var z = this; return function() { - var y, E; - return wa(function(B) { - switch(B.h) { + var x, C; + return wa(function(D) { + switch(D.h) { case 1: - E = y = void 0; + C = x = void 0; case 2: - if (!(u < q)) { - B.h = 4; + if (!(v < q)) { + D.h = 4; break; } - E = n[u]; - if (!E || t[E]) { - B.h = 5; + C = n[v]; + if (!C || t[C]) { + D.h = 5; break; } - t[E] = 1; - return K(B, Zb(x, E, v, 0, 0, !1, !1), 6); + t[C] = 1; + return K(D, Zb(z, C, u, 0, 0, !1, !1), 6); case 6: - y = B.B; - if (y = $b(y, d, h, m)) { - d = y; - B.h = 4; + x = D.B; + if (x = $b(x, d, g, l)) { + d = x; + D.h = 4; break; } - v && (h && y && d.length || (v = E)); + u && (g && x && d.length || (u = C)); case 5: - h && v && u === q - 1 && !d.length && (m = x.resolution, v = "", u = -1, t = S()); - u++; - B.h = 2; + g && u && v === q - 1 && !d.length && (l = z.resolution, u = "", v = -1, t = S()); + v++; + D.h = 2; break; case 4: - return B.return(ac(d, m, b, e, h, l, g)); + return D.return(ac(d, l, b, e, g, m, f)); } }); }(); } - for (a = c = void 0; u < q; u++) { - if ((a = n[u]) && !t[a]) { + for (a = c = void 0; v < q; v++) { + if ((a = n[v]) && !t[a]) { t[a] = 1; - c = Zb(this, a, v, 0, 0, !1, !1); - if (c = $b(c, d, h, m)) { + c = Zb(this, a, u, 0, 0, !1, !1); + if (c = $b(c, d, g, l)) { d = c; break; } - v && (h && c && d.length || (v = a)); + u && (g && c && d.length || (u = a)); } - h && v && u === q - 1 && !d.length && (m = this.resolution, v = "", u = -1, t = S()); + g && u && v === q - 1 && !d.length && (l = this.resolution, u = "", v = -1, t = S()); } - return ac(d, m, b, e, h, l, g); + return ac(d, l, b, e, g, m, f); }; -function ac(a, b, c, d, e, g, f) { - var h = a.length, k = a; - if (1 < h) { - k = Ab(a, b, c, d, e, g, f); - } else if (1 === h) { - return f ? sb.call(null, a[0], c, d) : new Z(a[0], this); +function ac(a, b, c, d, e, f, h) { + var g = a.length, k = a; + if (1 < g) { + k = Ab(a, b, c, d, e, f, h); + } else if (1 === g) { + return h ? sb.call(null, a[0], c, d) : new Z(a[0], this); } - return f ? k : new Z(k, this); + return h ? k : new Z(k, this); } -function Yb(a, b, c, d, e, g, f) { - a = Zb(this, a, b, c, d, e, g, f); - return this.db ? a.then(function(h) { - return e ? h || [] : new Z(h, this); +function Yb(a, b, c, d, e, f, h) { + a = Zb(this, a, b, c, d, e, f, h); + return this.db ? a.then(function(g) { + return e ? g || [] : new Z(g, this); }) : a && a.length ? e ? sb.call(this, a, c, d) : new Z(a, this) : e ? [] : new Z([], this); } function $b(a, b, c, d) { @@ -3374,9 +3415,9 @@ function $b(a, b, c, d) { b.push(a); return; } - for (var g = 0, f; g < d; g++) { - if (f = a[g]) { - e[g] = f; + for (var f = 0, h; f < d; f++) { + if (h = a[f]) { + e[f] = h; } } if (e.length) { @@ -3388,11 +3429,11 @@ function $b(a, b, c, d) { return e; } } -function Zb(a, b, c, d, e, g, f, h) { +function Zb(a, b, c, d, e, f, h, g) { var k; c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); if (a.db) { - return a.db.get(b, c, d, e, g, f, h); + return a.db.get(b, c, d, e, f, h, g); } a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; @@ -3457,8 +3498,7 @@ w.clear = function() { 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; + return this.db ? (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [], this.db.clear()) : this; }; w.append = function(a, b) { return this.add(a, b, !0); @@ -3487,24 +3527,24 @@ w.export = function(a, b, c, d) { switch(d) { case 0: var e = "reg"; - var g = Pb(this.reg); + var f = Pb(this.reg); break; case 1: e = "cfg"; - g = null; + f = null; break; case 2: e = "map"; - g = Lb(this.map, this.reg.size); + f = Lb(this.map, this.reg.size); break; case 3: e = "ctx"; - g = Nb(this.ctx, this.reg.size); + f = Nb(this.ctx, this.reg.size); break; default: return; } - return Rb.call(this, a, b, e, g, c, d); + return Rb.call(this, a, b, e, f, c, d); }; w.import = function(a, b) { if (b) { @@ -3526,21 +3566,21 @@ w.serialize = function(a) { var b = "", c = "", d = ""; if (this.reg.size) { var e; - c = C(this.reg.keys()); - for (var g = c.next(); !g.done; g = c.next()) { - g = g.value, e || (e = typeof g), b += (b ? "," : "") + ("string" === e ? '"' + g + '"' : g); + c = B(this.reg.keys()); + for (var f = c.next(); !f.done; f = c.next()) { + f = f.value, e || (e = typeof f), b += (b ? "," : "") + ("string" === e ? '"' + f + '"' : f); } b = "index.reg=new Set([" + b + "]);"; c = Sb(this.map, e); c = "index.map=new Map([" + c + "]);"; - g = C(this.ctx.entries()); - for (var f = g.next(); !f.done; f = g.next()) { - var h = f.value; - f = h[0]; - h = Sb(h[1], e); - h = "new Map([" + h + "])"; - h = '["' + f + '",' + h + "]"; - d += (d ? "," : "") + h; + f = B(this.ctx.entries()); + for (var h = f.next(); !h.done; h = f.next()) { + var g = h.value; + h = g[0]; + g = Sb(g[1], e); + g = "new Map([" + g + "])"; + g = '["' + h + '",' + g + "]"; + d += (d ? "," : "") + g; } d = "index.ctx=new Map([" + d + "]);"; } @@ -3582,8 +3622,8 @@ w.open = function() { b.onupgradeneeded = function() { for (var c = a.db = this.result, d = 0, e; d < cc.length; d++) { e = cc[d]; - for (var g = 0, f; g < dc[a.id].length; g++) { - f = dc[a.id][g], c.objectStoreNames.contains(e + ("reg" !== e ? f ? ":" + f : "" : "")) || c.createObjectStore(e + ("reg" !== e ? f ? ":" + f : "" : "")); + for (var f = 0, h; f < dc[a.id].length; f++) { + h = dc[a.id][f], c.objectStoreNames.contains(e + ("reg" !== e ? h ? ":" + h : "" : "")) || c.createObjectStore(e + ("reg" !== e ? h ? ":" + h : "" : "")); } } }; @@ -3615,29 +3655,29 @@ w.clear = function() { } return fc(b); }; -w.get = function(a, b, c, d, e, g) { +w.get = function(a, b, c, d, e, f) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; e = void 0 === e ? !0 : e; - g = void 0 === g ? !1 : g; + f = void 0 === f ? !1 : f; a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); - var f = this; - return fc(a).then(function(h) { + var h = this; + return fc(a).then(function(g) { var k = []; - if (!h || !h.length) { + if (!g || !g.length) { return k; } if (e) { - if (!c && !d && 1 === h.length) { - return h[0]; + if (!c && !d && 1 === g.length) { + return g[0]; } - for (var l = 0, m = void 0; l < h.length; l++) { - if ((m = h[l]) && m.length) { - if (d >= m.length) { - d -= m.length; + for (var m = 0, l = void 0; m < g.length; m++) { + if ((l = g[m]) && l.length) { + if (d >= l.length) { + d -= l.length; } else { - for (var p = c ? d + Math.min(m.length - d, c) : m.length, n = d; n < p; n++) { - k.push(m[n]); + for (var p = c ? d + Math.min(l.length - d, c) : l.length, n = d; n < p; n++) { + k.push(l[n]); } d = 0; if (k.length === c) { @@ -3646,9 +3686,9 @@ w.get = function(a, b, c, d, e, g) { } } } - return g ? f.enrich(k) : k; + return f ? h.enrich(k) : k; } - return h; + return g; }); }; w.tag = function(a, b, c, d) { @@ -3657,15 +3697,15 @@ w.tag = function(a, b, c, d) { d = void 0 === d ? !1 : d; a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); var e = this; - return fc(a).then(function(g) { - if (!g || !g.length || c >= g.length) { + return fc(a).then(function(f) { + if (!f || !f.length || c >= f.length) { return []; } if (!b && !c) { - return g; + return f; } - g = g.slice(c, c + b); - return d ? e.enrich(g) : g; + f = f.slice(c, c + b); + return d ? e.enrich(f) : f; }); }; w.enrich = function(a) { @@ -3674,8 +3714,8 @@ w.enrich = function(a) { c[d] = fc(b.get(a[d])); } return Promise.all(c).then(function(e) { - for (var g = 0; g < e.length; g++) { - e[g] = {id:a[g], doc:e[g] ? JSON.parse(e[g]) : null}; + for (var f = 0; f < e.length; f++) { + e[f] = {id:a[f], doc:e[f] ? JSON.parse(e[f]) : null}; } return e; }); @@ -3697,77 +3737,77 @@ w.transaction = function(a, b, c) { } var e = this.db.transaction(a, b); this.h[a + ":" + b] = d = e.objectStore(a); - var g = c.call(this, d); + var f = c.call(this, d); this.h[a + ":" + b] = null; return fc(e).finally(function() { e = d = null; - return g; + return f; }); }; w.commit = function(a, b, c) { - var d = this, e, g, f; - return wa(function(h) { - switch(h.h) { + var d = this, e, f, h; + return wa(function(g) { + switch(g.h) { case 1: if (b) { - return K(h, d.clear(), 12); + return K(g, d.clear(), 12); } e = a.commit_task; a.commit_task = []; - g = 0; - f = void 0; + f = 0; + h = void 0; case 4: - if (!(g < e.length)) { - h.h = 6; + if (!(f < e.length)) { + g.h = 6; break; } - f = e[g]; - if (!f.clear) { - e[g] = f.del; - h.h = 5; + h = e[f]; + if (!h.clear) { + e[f] = h.del; + g.h = 5; break; } - return K(h, d.clear(), 8); + return K(g, d.clear(), 8); case 8: b = !0; - h.h = 6; + g.h = 6; break; case 5: - g++; - h.h = 4; + f++; + g.h = 4; break; case 6: if (b) { - h.h = 3; + g.h = 3; break; } c || (e = e.concat(Da(a.reg))); if (!e.length) { - h.h = 10; + g.h = 10; break; } - return K(h, d.remove(e), 11); + return K(g, d.remove(e), 11); case 11: case 10: - h.h = 3; + g.h = 3; break; case 12: a.commit_task = []; case 3: - return a.reg.size ? K(h, d.transaction("map", "readwrite", function(k) { - for (var l = C(a.map), m = l.next(), p = {}; !m.done; p = {P:void 0, Y:void 0}, m = l.next()) { - m = m.value, p.Y = m[0], p.P = m[1], p.P.length && (b ? k.put(p.P, p.Y) : k.get(p.Y).onsuccess = function(n) { + return a.reg.size ? K(g, d.transaction("map", "readwrite", function(k) { + for (var m = B(a.map), l = m.next(), p = {}; !l.done; p = {P:void 0, Y:void 0}, l = m.next()) { + l = l.value, p.Y = l[0], p.P = l[1], p.P.length && (b ? k.put(p.P, p.Y) : k.get(p.Y).onsuccess = function(n) { return function() { var q = this.result, t; if (q && q.length) { - for (var u = Math.max(q.length, n.P.length), v = 0, x; v < u; v++) { - if ((x = n.P[v]) && x.length) { - if ((t = q[v]) && t.length) { - for (var y = 0; y < x.length; y++) { - t.push(x[y]); + for (var v = Math.max(q.length, n.P.length), u = 0, z; u < v; u++) { + if ((z = n.P[u]) && z.length) { + if ((t = q[u]) && t.length) { + for (var x = 0; x < z.length; x++) { + t.push(z[x]); } } else { - q[v] = x; + q[u] = z; } t = 1; } @@ -3779,34 +3819,34 @@ w.commit = function(a, b, c) { }; }(p)); } - }), 13) : h.return(); + }), 13) : g.return(); case 13: - return K(h, d.transaction("ctx", "readwrite", function(k) { - for (var l = C(a.ctx), m = l.next(), p = {}; !m.done; p = {W:void 0}, m = l.next()) { - m = m.value; - p.W = m[0]; - m = C(m[1]); - for (var n = m.next(), q = {}; !n.done; q = {R:void 0, Z:void 0}, n = m.next()) { - n = n.value, q.Z = n[0], q.R = n[1], q.R.length && (b ? k.put(q.R, p.W + ":" + q.Z) : k.get(p.W + ":" + q.Z).onsuccess = function(t, u) { + return K(g, d.transaction("ctx", "readwrite", function(k) { + for (var m = B(a.ctx), l = m.next(), p = {}; !l.done; p = {W:void 0}, l = m.next()) { + l = l.value; + p.W = l[0]; + l = B(l[1]); + for (var n = l.next(), q = {}; !n.done; q = {R:void 0, Z:void 0}, n = l.next()) { + n = n.value, q.Z = n[0], q.R = n[1], q.R.length && (b ? k.put(q.R, p.W + ":" + q.Z) : k.get(p.W + ":" + q.Z).onsuccess = function(t, v) { return function() { - var v = this.result, x; - if (v && v.length) { - for (var y = Math.max(v.length, t.R.length), E = 0, B; E < y; E++) { - if ((B = t.R[E]) && B.length) { - if ((x = v[E]) && x.length) { - for (var r = 0; r < B.length; r++) { - x.push(B[r]); + var u = this.result, z; + if (u && u.length) { + for (var x = Math.max(u.length, t.R.length), C = 0, D; C < x; C++) { + if ((D = t.R[C]) && D.length) { + if ((z = u[C]) && z.length) { + for (var r = 0; r < D.length; r++) { + z.push(D[r]); } } else { - v[E] = B; + u[C] = D; } - x = 1; + z = 1; } } } else { - v = t.R, x = 1; + u = t.R, z = 1; } - x && k.put(v, u.W + ":" + t.Z); + z && k.put(u, v.W + ":" + t.Z); }; }(q, p)); } @@ -3814,32 +3854,32 @@ w.commit = function(a, b, c) { }), 14); case 14: if (a.store) { - return K(h, d.transaction("reg", "readwrite", function(k) { - for (var l = C(a.store), m = l.next(); !m.done; m = l.next()) { - var p = m.value; - m = p[0]; + return K(g, d.transaction("reg", "readwrite", function(k) { + for (var m = B(a.store), l = m.next(); !l.done; l = m.next()) { + var p = l.value; + l = p[0]; p = p[1]; - k.put("object" === typeof p ? JSON.stringify(p) : 1, m); + k.put("object" === typeof p ? JSON.stringify(p) : 1, l); } }), 16); } if (a.bypass) { - h.h = 16; + g.h = 16; break; } - return K(h, d.transaction("reg", "readwrite", function(k) { - for (var l = C(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { - k.put(1, m.value); + return K(g, d.transaction("reg", "readwrite", function(k) { + for (var m = B(a.reg.keys()), l = m.next(); !l.done; l = m.next()) { + k.put(1, l.value); } }), 16); case 16: if (!a.tag) { - h.h = 20; + g.h = 20; break; } - return K(h, d.transaction("tag", "readwrite", function(k) { - for (var l = C(a.tag), m = l.next(), p = {}; !m.done; p = {X:void 0, da:void 0}, m = l.next()) { - m = m.value, p.da = m[0], p.X = m[1], p.X.length && (k.get(p.da).onsuccess = function(n) { + return K(g, d.transaction("tag", "readwrite", function(k) { + for (var m = B(a.tag), l = m.next(), p = {}; !l.done; p = {X:void 0, da:void 0}, l = m.next()) { + l = l.value, p.da = l[0], p.X = l[1], p.X.length && (k.get(p.da).onsuccess = function(n) { return function() { var q = this.result; q = q && q.length ? q.concat(n.X) : n.X; @@ -3849,30 +3889,30 @@ w.commit = function(a, b, c) { } }), 20); case 20: - a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), h.h = 0; + a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), g.h = 0; } }); }; function gc(a, b, c) { - for (var d = a.value, e, g = 0, f = 0, h; f < d.length; f++) { - if (h = c ? d : d[f]) { - for (var k = 0, l; k < b.length; k++) { - if (l = b[k], l = h.indexOf(l), 0 <= l) { - if (e = 1, 1 < h.length) { - h.splice(l, 1); + for (var d = a.value, e, f = 0, h = 0, g; h < d.length; h++) { + if (g = c ? d : d[h]) { + for (var k = 0, m; k < b.length; k++) { + if (m = b[k], m = g.indexOf(m), 0 <= m) { + if (e = 1, 1 < g.length) { + g.splice(m, 1); } else { - d[f] = []; + d[h] = []; break; } } } - g += h.length; + f += g.length; } if (c) { break; } } - g ? e && a.update(d) : a.delete(); + f ? e && a.update(d) : a.delete(); a.continue(); } w.remove = function(a) { diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index a1ec85a..a64d7ea 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,144 +1,146 @@ /**! - * FlexSearch.js v0.8.201 (ES5) + * FlexSearch.js v0.8.202 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ (function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var w;function aa(a){var b=0;return function(){return b>>0)+"_",e=0;return b}); -G("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c>>0)+"_",e=0;return b}); +H("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;cc&&(c=Math.max(c+e,0));c"a1a".split(c).length; -this.numeric=P(a.numeric,e)}else{try{this.split=P(this.split,Fa)}catch(g){this.split=/\s+/}this.numeric=P(a.numeric,P(this.numeric,!0))}this.prepare=P(a.prepare,null,this.prepare);this.finalize=P(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:P(c&&new Set(c),null,this.filter);this.dedupe=P(a.dedupe,!0,this.dedupe);this.matcher=P((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=P((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=P((c=a.stemmer)&&new Map(c), -null,this.stemmer);this.replacer=P(a.replacer,null,this.replacer);this.minlength=P(a.minlength,1,this.minlength);this.maxlength=P(a.maxlength,1024,this.maxlength);this.rtl=P(a.rtl,!1,this.rtl);if(this.cache=c=P(a.cache,!0,this.cache))this.D=null,this.U="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.I=this.H=128;this.h="";this.N=null;this.A="";this.O=null;if(this.matcher)for(a=B(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value;if(this.stemmer)for(a=B(this.stemmer.keys()), +H("WeakMap",function(a){function b(k){this.h=(g+=Math.random()+1).toString();if(k){k=B(k);for(var m;!(m=k.next()).done;)m=m.value,this.set(m[0],m[1])}}function c(){}function d(k){var m=typeof k;return"object"===m&&null!==k||"function"===m}function e(k){if(!za(k,h)){var m=new c;ca(k,h,{value:m})}}function f(k){var m=Object[k];m&&(Object[k]=function(l){if(l instanceof c)return l;Object.isExtensible(l)&&e(l);return m(l)})}if(function(){if(!a||!Object.seal)return!1;try{var k=Object.seal({}),m=Object.seal({}), +l=new a([[k,2],[m,3]]);if(2!=l.get(k)||3!=l.get(m))return!1;l.delete(k);l.set(m,4);return!l.has(k)&&4==l.get(m)}catch(n){return!1}}())return a;var h="$jscomp_hidden_"+Math.random();f("freeze");f("preventExtensions");f("seal");var g=0;b.prototype.set=function(k,m){if(!d(k))throw Error("Invalid WeakMap key");e(k);if(!za(k,h))throw Error("WeakMap key fail: "+k);k[h][this.h]=m;return this};b.prototype.get=function(k){return d(k)&&za(k,h)?k[h][this.h]:void 0};b.prototype.has=function(k){return d(k)&&za(k, +h)&&za(k[h],this.h)};b.prototype.delete=function(k){return d(k)&&za(k,h)&&za(k[h],this.h)?delete k[h][this.h]:!1};return b}); +H("Map",function(a){function b(){var g={};return g.K=g.next=g.head=g}function c(g,k){var m=g[1];return xa(function(){if(m){for(;m.head!=g[1];)m=m.K;for(;m.next!=m.head;)return m=m.next,{done:!1,value:k(m)};m=null}return{done:!0,value:void 0}})}function d(g,k){var m=k&&typeof k;"object"==m||"function"==m?f.has(k)?m=f.get(k):(m=""+ ++h,f.set(k,m)):m="p_"+k;var l=g[0][m];if(l&&za(g[0],m))for(g=0;gc&&(c=Math.max(c+e,0));c"a1a".split(c).length; +this.numeric=P(a.numeric,e)}else{try{this.split=P(this.split,Fa)}catch(f){this.split=/\s+/}this.numeric=P(a.numeric,P(this.numeric,!0))}this.prepare=P(a.prepare,null,this.prepare);this.finalize=P(a.finalize,null,this.finalize);c=a.filter;this.filter="function"===typeof c?c:P(c&&new Set(c),null,this.filter);this.dedupe=P(a.dedupe,!0,this.dedupe);this.matcher=P((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=P((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=P((c=a.stemmer)&&new Map(c), +null,this.stemmer);this.replacer=P(a.replacer,null,this.replacer);this.minlength=P(a.minlength,1,this.minlength);this.maxlength=P(a.maxlength,1024,this.maxlength);this.rtl=P(a.rtl,!1,this.rtl);if(this.cache=c=P(a.cache,!0,this.cache))this.F=null,this.U="number"===typeof c?c:2E5,this.B=new Map,this.D=new Map,this.I=this.H=128;this.h="";this.N=null;this.A="";this.O=null;if(this.matcher)for(a=B(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value;if(this.stemmer)for(a=B(this.stemmer.keys()), b=a.next();!b.done;b=a.next())this.A+=(this.A?"|":"")+b.value;return this};w.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.O=null;this.cache&&La(this);return this};w.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&La(this);return this}; w.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.N=null;this.cache&&La(this);return this}; w.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&La(this);return this}; -w.encode=function(a,b){var c=this;if(this.cache&&a.length<=this.H)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(La,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=Ja?a.normalize("NFKD").replace(Ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(g[m])continue;g[m]=1}else{if(f===m)continue;f=m}if(d)e.push(m);else if(!this.filter||("function"===typeof this.filter?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.I)if(this.D){var n=this.C.get(m);if(n||""===n){n&&e.push(n);continue}}else this.D=setTimeout(La,50,this);if(this.stemmer)for(this.O|| -(this.O=new RegExp("(?!^)("+this.A+")$")),n=void 0;n!==m&&2this.U&&(this.C.clear(),this.I=this.I/1.1|0));if(m){if(m!==p)if(b){if(g[m])continue;g[m]=1}else{if(h===m)continue;h=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.H&&(this.B.set(a,e),this.B.size>this.U&&(this.B.clear(),this.H=this.H/1.1|0));return e};function La(a){a.D=null;a.B.clear();a.C.clear()};function Ma(a,b,c){c||(b||"object"!==typeof a?"object"===typeof b&&(c=b,b=0):c=a);c&&(a=c.query||a,b=c.limit||b);var d=""+(b||0);if(c){var e=c;d+=(e.offset||0)+!!e.context+!!e.suggest+(!1!==e.resolve)+(e.resolution||this.resolution)+(e.boost||0)}a=(""+a).toLowerCase();this.cache||(this.cache=new Na);e=this.cache.get(a+d);if(!e){var g=c&&c.cache;g&&(c.cache=!1);e=this.search(a,b,c);g&&(c.cache=g);this.cache.set(a+d,e)}return e} +w.encode=function(a,b){var c=this;if(this.cache&&a.length<=this.H)if(this.F){if(this.B.has(a))return this.B.get(a)}else this.F=setTimeout(La,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=Ja?a.normalize("NFKD").replace(Ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.maxlength)){if(b){if(f[l])continue;f[l]=1}else{if(h===l)continue;h=l}if(d)e.push(l);else if(!this.filter||("function"===typeof this.filter?this.filter(l):!this.filter.has(l))){if(this.cache&&l.length<=this.I)if(this.F){var p=this.D.get(l);if(p||""===p){p&&e.push(p);continue}}else this.F=setTimeout(La,50,this);if(this.stemmer)for(this.O|| +(this.O=new RegExp("(?!^)("+this.A+")$")),p=void 0;p!==l&&2this.U&&(this.D.clear(),this.I=this.I/1.1|0));if(l){if(l!==n)if(b){if(f[l])continue;f[l]=1}else{if(g===l)continue;g=l}e.push(l)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.H&&(this.B.set(a,e),this.B.size>this.U&&(this.B.clear(),this.H=this.H/1.1|0));return e};function La(a){a.F=null;a.B.clear();a.D.clear()};function Ma(a,b,c){c||(b||"object"!==typeof a?"object"===typeof b&&(c=b,b=0):c=a);c&&(a=c.query||a,b=c.limit||b);var d=""+(b||0);if(c){var e=c;d+=(e.offset||0)+!!e.context+!!e.suggest+(!1!==e.resolve)+(e.resolution||this.resolution)+(e.boost||0)}a=(""+a).toLowerCase();this.cache||(this.cache=new Na);e=this.cache.get(a+d);if(!e){var f=c&&c.cache;f&&(c.cache=!1);e=this.search(a,b,c);f&&(c.cache=f);this.cache.set(a+d,e)}return e} function Na(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}Na.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};Na.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Na.prototype.remove=function(a){for(var b=B(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}}; -Na.prototype.clear=function(){this.cache.clear();this.h=""};var Oa={normalize:!1,numeric:!1,dedupe:!1};var Pa={};var Qa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Ra=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Sa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Ta={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 Ua={Exact:Oa,Default:Pa,Normalize:Pa,LatinBalance:{mapper:Qa},LatinAdvanced:{mapper:Qa,matcher:Ra,replacer:Sa},LatinExtra:{mapper:Qa,replacer:Sa.concat([/(?!^)[aeo]/g,""]),matcher:Ra},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;b=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} -function Wa(a){if(!this||this.constructor!==Wa)return new Wa(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;f=h.length)b-=h.length;else{b=h[d?"splice":"slice"](b,c);if(h=b.length)if(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c)break;b=0}return e} +function Wa(a){if(!this||this.constructor!==Wa)return new Wa(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var f=0,h=0,g,k;h=this.priority*this.priority*3):(hb=setTimeout(kb,0),ib=Date.now());if(jb){var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var lb=0; -function mb(a,b){function c(h){function k(l){l=l.data||l;var m=l.id,p=m&&g.h[m];p&&(p(l.msg),delete g.h[m])}this.worker=h;this.h=S();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(l){1E9=this.priority*this.priority*3):(hb=setTimeout(kb,0),ib=Date.now());if(jb){var e=this;return new Promise(function(h){setTimeout(function(){h(e[a+"Async"].apply(e,b))},0)})}var f=this[a].apply(this,b);c=f.then?f:new Promise(function(h){return h(f)});d&&c.then(d);return c}};var lb=0; +function mb(a,b){function c(g){function k(m){m=m.data||m;var l=m.id,n=l&&f.h[l];n&&(n(m.msg),delete f.h[l])}this.worker=g;this.h=S();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(m){1E9b?a.slice(c,c+b):a,d?tb.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}f=f.slice(c,c+b);h=f.length;c=0}h>b&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?tb.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=yb(a,b,c,!1,this.h),c=0));e&&(this.await=null);return e?this.resolve(b,c,d):this};Z.prototype.and=function(){return ub(this,"and",zb,arguments)};function zb(a,b,c,d,e,g){if(!g&&!this.result.length)return e?this.result:this;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{for(var f=0,h=0,k=void 0,l=void 0;ha.length)this.result=a[0];else{a:{g=c;var f=this.h;for(var h=[],k=S(),l=0,m=0,p;mc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d, -c+d)}else{e=[];for(g=0;gd)d-=f.length;else{if(c&&f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=e}}return k} -function yb(a,b,c,d,e){var g=[],f=S(),h=a.length,k;if(d)for(e=h-1;0<=e;e--){if(k=(d=a[e])&&d.length)for(h=0;hH&&(H=r.length+(r?1:0)),N=r.length+(r?1:0)+ba.length,Q+=L,U.push(F.length),F.push({match:ba})),r+=(r?" ":"")+ba)}if(!O)R=A[D],r+=(r?" ":"")+R,k&&F.push({text:R});else if(k&&Q>=k)break}Q=U.length*(g.length-2);if(q||t||k&&r.length-Q>k)if(Q=k+Q-2*n,D=N-H,0A&&(A=0)),F=F.length-1){if(J>=F.length){D[z+1]=1;J>=A.length&&(H[z+1]=1);continue}O-=n}r=F[J].text;var V=t&&W[z];if(V)if(0< -V){if(r.length>V)if(D[z+1]=1,l)r=r.substring(0,V);else continue;(V-=r.length)||(V=-1);W[z]=V}else{D[z+1]=1;continue}if(O+r.length+1<=k)r=" "+r,N[z]+=r;else if(l)I=k-O-1,0=J){if(0>J){D[z]=1;H[z]=1;continue}O-=n}r=F[J].text;if(V=q&&R[z])if(0V)if(D[z]=1,l)r=r.substring(r.length-V);else continue;(V-=r.length)||(V=-1);R[z]=V}else{D[z]=1;continue}if(O+ -r.length+1<=k)r+=" ",N[z]=r+N[z];else if(l)I=r.length+1-(k-O),0<=I&&I=A.length-1?I=1:Jc||d)a=a.slice(d,d+c);e&&(a=tb.call(this,a))}return a} +"module/worker/worker.js"),{type:"module"})};pb.prototype.add=function(a,b,c){Ca(a)&&(b=a,a=Ea(b,this.key));if(b&&(a||0===a)){if(!c&&this.reg.has(a))return this.update(a,b);for(var d=0,e;db?a.slice(c,c+b):a,d?tb.call(this,a):a;for(var e=[],f=0,h=void 0,g=void 0;f=g){c-=g;continue}h=h.slice(c,c+b);g=h.length;c=0}g>b&&(h=h.slice(0,b),g=b);if(!e.length&&g>=b)return d?tb.call(this,h):h;e.push(h);b-=g;if(!b)break}e=1a.length?this.result=a[0]:(this.result=yb(a,b,c,!1,this.h),c=0));e&&(this.await=null);return e?this.resolve(b,c,d,h):this};Z.prototype.and=function(){return ub(this,"and",zb,arguments)};function zb(a,b,c,d,e,f,h){if(!f&&!this.result.length)return e?this.result:this;if(a.length)if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{for(var g=0,k=0,m=void 0,l=void 0;ka.length)this.result=a[0];else{a:{f=c;var g=this.h;for(var k=[],m=S(),l=0,n=0,p;nG&&(G=r.length+(r?1:0)),N=r.length+(r?1:0)+ba.length,Q+=L,U.push(F.length),F.push({match:ba})),r+=(r?" ":"")+ba)}if(!O)R=y[E],r+=(r?" ":"")+R,k&&F.push({text:R});else if(k&&Q>=k)break}Q=U.length*(f.length-2);if(q||t||k&&r.length-Q>k)if(Q=k+Q-2*p,E=N-G,0y&&(y=0)),F=F.length-1){if(J>=F.length){E[A+1]=1;J>=y.length&&(G[A+1]=1);continue}O-=p}r=F[J].text;var V=t&&W[A];if(V)if(0< +V){if(r.length>V)if(E[A+1]=1,m)r=r.substring(0,V);else continue;(V-=r.length)||(V=-1);W[A]=V}else{E[A+1]=1;continue}if(O+r.length+1<=k)r=" "+r,N[A]+=r;else if(m)I=k-O-1,0=J){if(0>J){E[A]=1;G[A]=1;continue}O-=p}r=F[J].text;if(V=q&&R[A])if(0V)if(E[A]=1,m)r=r.substring(r.length-V);else continue;(V-=r.length)||(V=-1);R[A]=V}else{E[A]=1;continue}if(O+ +r.length+1<=k)r+=" ",N[A]=r+N[A];else if(m)I=r.length+1-(k-O),0<=I&&I=y.length-1?I=1:Jc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d, +c+d)}else{e=[];for(f=0;fd)d-=h.length;else{if(c&&h.length>c||d)h=h.slice(d,c+d),c-=h.length,d&&(d-=h.length);e.push(h);if(!c)break}k=e}}return k} +function yb(a,b,c,d,e){var f=[],h=S(),g=a.length,k;if(d)for(e=g-1;0<=e;e--){if(k=(d=a[e])&&d.length)for(g=0;gc||d)a=a.slice(d,d+c);e&&(a=tb.call(this,a))}return a} function tb(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);for(var b=Array(a.length),c=0,d;cp;t--)n=l.substring(p,t),q=this.rtl?m-1-p:p,q=this.score?this.score(b,l,k,n,q):Wb(h,e,k,m,q),Xb(this, -f,n,q,a,c);break}case "bidirectional":case "reverse":if(1n?0:1),e,k,t-1,q-1),v=this.bidirectional&& -l>p;Xb(this,g,v?p:l,u,a,c,v?l:p)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ea&&Ub(this));return this}; -function Xb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=S()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new Wa(h);if(a.fastupdate)for(c=B(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function Wb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function Y(a,b){if(!this||this.constructor!==Y)return new Y(a);if(a){var c=T(a)?a:a.preset;c&&(a=Object.assign({},Vb[c],a))}else a={};c=a.context;var d=!0===c?{depth:1}:c||{},e=T(a.encoder)?Ua[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new Ka(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; +return Promise.all(b)}break;case "tag":this.tag=Ob(b,this.tag);break;case "doc":this.store=Mb(b,this.store)}}}function Sb(a,b){var c="";a=B(a.entries());for(var d=a.next();!d.done;d=a.next()){var e=d.value;d=e[0];e=e[1];for(var f="",h=0,g;hn;t--)p=m.substring(n,t),q=this.rtl?l-1-n:n,q=this.score?this.score(b,m,k,p,q):Wb(g,e,k,l,q),Xb(this, +h,p,q,a,c);break}case "bidirectional":case "reverse":if(1p?0:1),e,k,t-1,q-1),v=this.bidirectional&& +m>n;Xb(this,f,v?n:m,u,a,c,v?m:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ea&&Ub(this));return this}; +function Xb(a,b,c,d,e,f,h){var g=h?a.ctx:a.map,k;if(!b[c]||h&&!(k=b[c])[h])if(h?(b=k||(b[c]=S()),b[h]=1,(k=g.get(h))?g=k:g.set(h,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!f||!g.includes(e)){if(g.length===Math.pow(2,31)-1){b=new Wa(g);if(a.fastupdate)for(c=B(a.reg.values()),f=c.next();!f.done;f=c.next())f=f.value,f.includes(g)&&(f[f.indexOf(g)]=b);k[d]=g=b}g.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(g):a.reg.set(e,[g]))}} +function Wb(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,h,g);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function Y(a,b){if(!this||this.constructor!==Y)return new Y(a);if(a){var c=T(a)?a:a.preset;c&&(a=Object.assign({},Vb[c],a))}else a={};c=a.context;var d=!0===c?{depth:1}:c||{},e=T(a.encoder)?Ua[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"===typeof e?new Ka(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 Xa(c):new Map;this.ctx=c?new Xa(c):new Map;this.reg=b||(this.fastupdate?c?new Xa(c):new Map:c?new X(c):new Set);this.ga=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new Na(c);this.resolve=!1!==a.resolve;if(c=a.db)this.db=this.mount(c);this.ea=!1!==a.commit;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=Y.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 Ub(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)}; -w.cleanup=function(){if(!this.fastupdate)return this;Tb(this.map);this.depth&&Tb(this.ctx);return this};w.searchCache=Ma;w.export=function(a,b,c,d){c=void 0===c?0:c;d=void 0===d?0:d;switch(d){case 0:var e="reg";var g=Pb(this.reg);break;case 1:e="cfg";g=null;break;case 2:e="map";g=Lb(this.map,this.reg.size);break;case 3:e="ctx";g=Nb(this.ctx,this.reg.size);break;default:return}return Rb.call(this,a,b,e,g,c,d)}; +w.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):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)}; +w.cleanup=function(){if(!this.fastupdate)return this;Tb(this.map);this.depth&&Tb(this.ctx);return this};w.searchCache=Ma;w.export=function(a,b,c,d){c=void 0===c?0:c;d=void 0===d?0:d;switch(d){case 0:var e="reg";var f=Pb(this.reg);break;case 1:e="cfg";f=null;break;case 2:e="map";f=Lb(this.map,this.reg.size);break;case 3:e="ctx";f=Nb(this.ctx,this.reg.size);break;default:return}return Rb.call(this,a,b,e,f,c,d)}; w.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a=a.split("."),"json"===a[a.length-1]&&a.pop(),3===a.length&&a.shift(),a=1=m.length)d-=m.length;else{for(var p=c?d+Math.min(m.length-d,c): -m.length,n=d;n=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; -w.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d=l.length)d-=l.length;else{for(var n=c?d+Math.min(l.length-d,c): +l.length,p=d;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; +w.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d} index + * @param {Map} index * @param {string} pluck * @param {HighlightOptions|string} config * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} @@ -79,7 +80,6 @@ export function highlight_fields(query, result, index, pluck, config) { let res; if (pluck) { - res = result; path = pluck; } else { @@ -92,7 +92,6 @@ export function highlight_fields(query, result, index, pluck, config) { idx = index.get(path); enc = idx.encoder; - idx.tokenize; query_enc = encoder.get(enc); if ("string" != typeof query_enc) { diff --git a/dist/module-debug/index.js b/dist/module-debug/index.js index b126295..9817cbe 100644 --- a/dist/module-debug/index.js +++ b/dist/module-debug/index.js @@ -132,7 +132,8 @@ Index.prototype.clear = function () { if (this.db) { this.commit_timer && clearTimeout(this.commit_timer); this.commit_timer = null; - this.commit_task = [{ clear: !0 }]; + this.commit_task = []; + return this.db.clear(); } return this; diff --git a/dist/module-debug/resolve/and.js b/dist/module-debug/resolve/and.js index c31b89b..cf4ef0e 100644 --- a/dist/module-debug/resolve/and.js +++ b/dist/module-debug/resolve/and.js @@ -1,7 +1,7 @@ import Resolver from "../resolver.js"; import { get_max_len } from "../common.js"; import { intersect } from "../intersect.js"; -import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, HighlightOptions } from "../type.js"; /** * @return { @@ -25,6 +25,7 @@ Resolver.prototype.and = function () { * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -35,7 +36,7 @@ Resolver.prototype.and = function () { * } */ -function return_result(final, limit, offset, enrich, resolve, suggest) { +function return_result(final, limit, offset, enrich, resolve, suggest, highlight) { if (!suggest && !this.result.length) { return resolve ? this.result : this; @@ -79,5 +80,5 @@ function return_result(final, limit, offset, enrich, resolve, suggest) { this.await = null; } - return resolve ? this.resolve(limit, offset, enrich, resolved) : this; + return resolve ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } \ No newline at end of file diff --git a/dist/module-debug/resolve/handler.js b/dist/module-debug/resolve/handler.js index 55a62b7..c1bd90e 100644 --- a/dist/module-debug/resolve/handler.js +++ b/dist/module-debug/resolve/handler.js @@ -70,8 +70,8 @@ Resolver.prototype.handler = function (method, fn, args) { offset = query.offset || 0; suggest = query.suggest; resolve = query.resolve; - highlight = query.highlight && resolve; - enrich = highlight || query.enrich && resolve; + highlight = resolve && query.highlight; + enrich = (highlight || query.enrich) && resolve; let opt_queue = query.queue, opt_async = query.async || opt_queue, index = query.index; @@ -84,18 +84,24 @@ Resolver.prototype.handler = function (method, fn, args) { } if (query.query || query.tag) { - if (!this.index) { + if (!index) { throw new Error("Resolver can't apply because the corresponding Index was never specified"); } { const field = query.field || query.pluck; if (field) { - if (!this.index.index) { + + if (query.query) { + this.query = query.query; + this.field = field; + } + + if (!index.index) { throw new Error("Resolver can't apply because the corresponding Document Index was not specified"); } - index = this.index.index.get(field); + index = index.index.get(field); if (!index) { throw new Error("Resolver can't apply because the specified Document Field '" + field + "' was not found"); @@ -144,10 +150,6 @@ Resolver.prototype.handler = function (method, fn, args) { query.resolve = resolve; query.index = index; } - - if (highlight) { - query.query; - } } else if (query.and) { result = inner_call(query, "and", index); } else if (query.or) { @@ -189,22 +191,23 @@ Resolver.prototype.handler = function (method, fn, args) { for (let i = 0; i < self.promises.length; i++) { if (self.promises[i] === promises) { self.promises[i] = function () { - return fn.call(self, final, limit, offset, enrich, resolve, suggest); + return fn.call(self, final, limit, offset, enrich, resolve, suggest, highlight); }; break; } } self.execute(); }); + this.promises.push(promises); } else if (this.await) { this.promises.push(function () { - return fn.call(self, final, limit, offset, enrich, resolve, suggest); + return fn.call(self, final, limit, offset, enrich, resolve, suggest, highlight); }); } else { - return fn.call(this, final, limit, offset, enrich, resolve, suggest); + return fn.call(this, final, limit, offset, enrich, resolve, suggest, highlight); } return resolve ? this.await || this.result : this; diff --git a/dist/module-debug/resolve/not.js b/dist/module-debug/resolve/not.js index 8dd9cf5..15f2081 100644 --- a/dist/module-debug/resolve/not.js +++ b/dist/module-debug/resolve/not.js @@ -1,5 +1,5 @@ import Resolver from "../resolver.js"; -import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, HighlightOptions } from "../type.js"; /** @this {Resolver} */ Resolver.prototype.not = function () { @@ -13,6 +13,7 @@ Resolver.prototype.not = function () { * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -22,7 +23,7 @@ Resolver.prototype.not = function () { * Resolver * } */ -function return_result(final, limit, offset, enrich, resolve, suggest) { +function return_result(final, limit, offset, enrich, resolve, suggest, highlight) { if (!suggest && !this.result.length) { return resolve ? this.result : this; @@ -39,7 +40,7 @@ function return_result(final, limit, offset, enrich, resolve, suggest) { this.await = null; } - return resolve ? this.resolve(limit, offset, enrich, resolved) : this; + return resolve ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } /** diff --git a/dist/module-debug/resolve/or.js b/dist/module-debug/resolve/or.js index 3abd217..4d21867 100644 --- a/dist/module-debug/resolve/or.js +++ b/dist/module-debug/resolve/or.js @@ -1,6 +1,6 @@ import Resolver from "../resolver.js"; import { union } from "../intersect.js"; -import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, HighlightOptions } from "../type.js"; /** @this {Resolver} */ Resolver.prototype.or = function () { @@ -15,6 +15,7 @@ Resolver.prototype.or = function () { * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -25,7 +26,7 @@ Resolver.prototype.or = function () { * } */ -function return_result(final, limit, offset, enrich, resolve) { +function return_result(final, limit, offset, enrich, resolve, suggest, highlight) { if (final.length) { this.result.length && final.push(this.result); @@ -44,5 +45,5 @@ function return_result(final, limit, offset, enrich, resolve) { this.await = null; } - return resolve ? this.resolve(limit, offset, enrich) : this; + return resolve ? this.resolve(limit, offset, enrich, highlight) : this; } \ No newline at end of file diff --git a/dist/module-debug/resolve/xor.js b/dist/module-debug/resolve/xor.js index a940b12..ed577e7 100644 --- a/dist/module-debug/resolve/xor.js +++ b/dist/module-debug/resolve/xor.js @@ -1,6 +1,6 @@ import Resolver from "../resolver.js"; import { create_object } from "../common.js"; -import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, HighlightOptions } from "../type.js"; /** @this {Resolver} */ Resolver.prototype.xor = function () { @@ -14,6 +14,7 @@ Resolver.prototype.xor = function () { * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -24,7 +25,7 @@ Resolver.prototype.xor = function () { * } */ -function return_result(final, limit, offset, enrich, resolve, suggest) { +function return_result(final, limit, offset, enrich, resolve, suggest, highlight) { let resolved; @@ -45,7 +46,7 @@ function return_result(final, limit, offset, enrich, resolve, suggest) { this.await = null; } - return resolve ? this.resolve(limit, offset, enrich, resolved) : this; + return resolve ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } /** diff --git a/dist/module-debug/resolver.js b/dist/module-debug/resolver.js index e441a0a..8dde904 100644 --- a/dist/module-debug/resolver.js +++ b/dist/module-debug/resolver.js @@ -1,5 +1,5 @@ -import { ResolverOptions, IntermediateSearchResults, SearchResults, EnrichedSearchResults } from "./type.js"; +import { ResolverOptions, IntermediateSearchResults, SearchResults, EnrichedSearchResults, HighlightOptions } from "./type.js"; import Index from "./index.js"; import Document from "./document.js"; import WorkerIndex from "./worker.js"; @@ -10,6 +10,7 @@ import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; import { apply_enrich } from "./document/search.js"; +import { highlight_fields } from "./document/highlight.js"; /** * @param {IntermediateSearchResults|ResolverOptions=} result @@ -24,6 +25,8 @@ export default function Resolver(result, index) { let boost = 0, promises, + query, + field, _await, _return; @@ -31,7 +34,8 @@ export default function Resolver(result, index) { const options = /** @type {ResolverOptions} */result; index = options.index; boost = options.boost || 0; - if (options.query) { + if (query = options.query) { + field = options.field || options.pluck; const resolve = options.resolve, async = options.async || options.queue; @@ -71,28 +75,41 @@ export default function Resolver(result, index) { this.await = _await || null; /** @type {Function} */ this.return = _return || null; + + /** @type {string} */ + this.query = query || ""; + /** @type {string} */ + this.field = field || ""; } /** * @param {number} limit */ Resolver.prototype.limit = function (limit) { - if (this.result.length) { - /** @type {IntermediateSearchResults} */ - const final = []; - for (let j = 0, ids; j < this.result.length; j++) { - if (ids = this.result[j]) { - if (ids.length <= limit) { - final[j] = ids; - limit -= ids.length; - if (!limit) break; - } else { - final[j] = ids.slice(0, limit); - break; + if (this.await) { + const self = this; + this.promises.push(function () { + self.limit(limit); + return self.result; + }); + } else { + if (this.result.length) { + /** @type {IntermediateSearchResults} */ + const final = []; + for (let j = 0, ids; j < this.result.length; j++) { + if (ids = this.result[j]) { + if (ids.length <= limit) { + final[j] = ids; + limit -= ids.length; + if (!limit) break; + } else { + final[j] = ids.slice(0, limit); + break; + } } } + this.result = final; } - this.result = final; } return this; }; @@ -101,20 +118,28 @@ Resolver.prototype.limit = function (limit) { * @param {number} offset */ Resolver.prototype.offset = function (offset) { - if (this.result.length) { - /** @type {IntermediateSearchResults} */ - const final = []; - for (let j = 0, ids; j < this.result.length; j++) { - if (ids = this.result[j]) { - if (ids.length <= offset) { - offset -= ids.length; - } else { - final[j] = ids.slice(offset); - offset = 0; + if (this.await) { + const self = this; + this.promises.push(function () { + self.offset(offset); + return self.result; + }); + } else { + if (this.result.length) { + /** @type {IntermediateSearchResults} */ + const final = []; + for (let j = 0, ids; j < this.result.length; j++) { + if (ids = this.result[j]) { + if (ids.length <= offset) { + offset -= ids.length; + } else { + final[j] = ids.slice(offset); + offset = 0; + } } } + this.result = final; } - this.result = final; } return this; }; @@ -123,7 +148,15 @@ Resolver.prototype.offset = function (offset) { * @param {number} boost */ Resolver.prototype.boost = function (boost) { - this.boostval += boost; + if (this.await) { + const self = this; + this.promises.push(function () { + self.boost(boost); + return self.result; + }); + } else { + this.boostval += boost; + } return this; }; @@ -132,12 +165,13 @@ Resolver.prototype.boost = function (boost) { * @this {Resolver} */ Resolver.prototype.execute = function (_skip_callback) { + let result = this.result, + execute = this.await; - let result = this.result; + this.await = null; for (let i = 0, promise; i < this.promises.length; i++) { - promise = this.promises[i]; - if (promise) { + if (promise = this.promises[i]) { if ("function" == typeof promise) { result = promise(); this.promises[i] = result = result.result || result; @@ -147,15 +181,14 @@ Resolver.prototype.execute = function (_skip_callback) { this.promises[i] = result = result.result || result; i--; } else if (promise.then) { - return this.await; + return this.await = execute; } } } const fn = this.return; - this.result = result; + this.promises = []; - this.await = null; this.return = null; _skip_callback || fn(result); @@ -166,42 +199,60 @@ Resolver.prototype.execute = function (_skip_callback) { * @param {number|ResolverOptions=} limit * @param {number=} offset * @param {boolean=} enrich + * @param {string|HighlightOptions|boolean=} highlight * @param {boolean=} _resolved */ -Resolver.prototype.resolve = function (limit, offset, enrich, _resolved) { +Resolver.prototype.resolve = function (limit, offset, enrich, highlight, _resolved) { let result = this.await ? this.execute(!0) : this.result; if (result.then) { const self = this; return result.then(function () { - return self.resolve(limit, offset, enrich); + return self.resolve(limit, offset, enrich, highlight, _resolved); }); } if (result.length) { if ("object" == typeof limit) { - enrich = limit.enrich; + highlight = limit.highlight; + enrich = !!highlight || limit.enrich; offset = limit.offset; - - - if (limit.highlight) { - console.warn('Highlighting results is not supported within the resolve() method. Instead pass highlight options within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); - } - limit = limit.limit; + } else { + highlight = highlight; + enrich = !!highlight || enrich; } result = _resolved ? enrich ? apply_enrich.call( /** @type {Document} */this.index, /** @type {SearchResults} */result) : result : default_resolver.call(this.index, result, limit || 100, offset, enrich); } + return this.finalize(result, highlight); +}; + +Resolver.prototype.finalize = function (result, highlight) { + + if (result.then) { + const self = this; + return result.then(function (result) { + return self.finalize(result, highlight); + }); + } + + if (highlight && !this.query) { + console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); + } + + if (highlight && result.length && this.query) { + result = highlight_fields(this.query, result, this.index.index, this.field, highlight); + } + const fn = this.return; - this.index = null; - this.result = null; - this.promises = null; - this.await = null; - this.return = null; + this.index = this.result = this.promises = this.await = this.return = null; + + this.query = this.field = ""; + fn && fn(result); return result; diff --git a/dist/module-min/db/redis/index.js b/dist/module-min/db/redis/index.js index 69c89c4..076d9b3 100644 --- a/dist/module-min/db/redis/index.js +++ b/dist/module-min/db/redis/index.js @@ -1 +1 @@ -import{createClient}from"redis";const defaults={host:"localhost",port:"6379",user:null,pass:null},VERSION=1,fields=["map","ctx","reg","tag","doc","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}let DB,TRX;export default function RedisDB(a,b={}){return this&&this.constructor===RedisDB?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id=(a?sanitize(a):"flexsearch")+"|",this.field=b.field?"-"+sanitize(b.field):"",this.type=b.type||"",this.fastupdate=!0,this.db=b.db||DB||null,this.support_tag_search=!0,this.resolution=9,this.resolution_ctx=9,Object.assign(defaults,b),this.db&&delete defaults.db):new RedisDB(a,b)}RedisDB.prototype.mount=function(a){return a.index?a.mount(this):(a.db=this,this.resolution=a.resolution,this.resolution_ctx=a.resolution_ctx,this.open())},RedisDB.prototype.open=async function(){if(this.db)return this.db;if(DB)return this.db=DB;let a=defaults.url;return a||(a=defaults.user?`redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`:`redis://${defaults.host}:${defaults.port}`),this.db=DB=await createClient(a).on("error",a=>console.error(a)).connect()},RedisDB.prototype.close=async function(){return DB&&(await this.db.disconnect()),this.db=DB=null,this},RedisDB.prototype.destroy=function(){return this.clear()},RedisDB.prototype.clear=function(){if(!this.id)return;const a=this;return this.db.keys(this.id+"*").then(function(b){return b.length&&a.db.unlink(b)})};function create_result(a,b,c,d,e){if(c){for(let c,e,f=0;f=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc","number"===this.type?a.map(a=>""+a):a).then(function(b){for(let c=0;ce,k.push(c+(f?d:e)+":"+(f?e:d)),l.push(1),e=d}else{const a=this.id+"map"+this.field+":";for(let c=0;cconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return DB&&(await this.db.disconnect()),this.db=DB=null,this},RedisDB.prototype.destroy=function(){return this.clear(!0)},RedisDB.prototype.clear=function(a=!1){function b(a){return a.length&&c.db.unlink(a)}if(!this.id)return;const c=this;return Promise.all([this.db.keys(this.id+"map"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"ctx"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"tag"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"ref"+(a?"":this.field)+"*").then(b),b([this.id+"cfg"+(a?"*":this.field),this.id+"doc",this.id+"reg"])])};function create_result(a,b,c,d,e){if(c){for(let c,e,f=0;f=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc","number"===this.type?a.map(a=>""+a):a).then(function(b){for(let c=0;ce,k.push(c+(f?d:e)+":"+(f?e:d)),l.push(1),e=d}else{const a=this.id+"map"+this.field+":";for(let c=0;cw&&(w=i.length+(i?1:0)),x=i.length+(i?1:0)+f.length,y+=a,v.push(u.length),u.push({match:f})),i+=(i?" ":"")+f)}if(!e){const b=d[a];i+=(i?" ":"")+b,l&&u.push({text:b})}else if(l&&y>=l)break}let z=v.length*(f.length-2);if(q||r||l&&i.length-z>l){let a,b,c=l+z-2*s,e=x-w;if(0a&&(a=0))),b=d.length-1?b=1:x=u.length-1){if(x>=u.length){e[y+1]=1,x>=d.length&&(c[y+1]=1);continue}j-=s}i=u[x].text;let f=r&&h[y];if(f)if(0f)if(e[y+1]=1,m)i=i.substring(0,f);else continue;f-=i.length,f||(f=-1),h[y]=f}else{e[y+1]=1;continue}if(j+i.length+1<=l)i=" "+i,a[y]+=i;else if(m){const b=l-j-1;0=x){if(0>x){e[y]=1,c[y]=1;continue}j-=s}i=u[x].text;let d=q&&g[y];if(d)if(0d)if(e[y]=1,m)i=i.substring(i.length-d);else continue;d-=i.length,d||(d=-1),g[y]=d}else{e[y]=1;continue}if(j+i.length+1<=l)i+=" ",a[y]=i+a[y];else if(m){const b=i.length+1-(l-j);0<=b&&bw&&(w=i.length+(i?1:0)),x=i.length+(i?1:0)+f.length,y+=a,v.push(u.length),u.push({match:f})),i+=(i?" ":"")+f)}if(!e){const b=d[a];i+=(i?" ":"")+b,l&&u.push({text:b})}else if(l&&y>=l)break}let z=v.length*(f.length-2);if(q||r||l&&i.length-z>l){let a,b,c=l+z-2*s,e=x-w;if(0a&&(a=0))),b=d.length-1?b=1:x=u.length-1){if(x>=u.length){e[y+1]=1,x>=d.length&&(c[y+1]=1);continue}j-=s}i=u[x].text;let f=r&&h[y];if(f)if(0f)if(e[y+1]=1,m)i=i.substring(0,f);else continue;f-=i.length,f||(f=-1),h[y]=f}else{e[y+1]=1;continue}if(j+i.length+1<=l)i=" "+i,a[y]+=i;else if(m){const b=l-j-1;0=x){if(0>x){e[y]=1,c[y]=1;continue}j-=s}i=u[x].text;let d=q&&g[y];if(d)if(0d)if(e[y]=1,m)i=i.substring(i.length-d);else continue;d-=i.length,d||(d=-1),g[y]=d}else{e[y]=1;continue}if(j+i.length+1<=l)i+=" ",a[y]=i+a[y];else if(m){const b=i.length+1-(l-j);0<=b&&bc.add(a,b)):this.add(a,b)},Index.prototype.cleanup=function(){return this.fastupdate?(remove_index(this.map),this.depth&&remove_index(this.ctx),this):(!1,this)},Index.prototype.searchCache=searchCache,Index.prototype.export=exportIndex,Index.prototype.import=importIndex,Index.prototype.serialize=serialize,apply_async(Index.prototype); \ No newline at end of file +import{IndexOptions,ContextOptions,EncoderOptions}from"./type.js";import Encoder,{fallback_encoder}from"./encoder.js";import Cache,{searchCache}from"./cache.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import{is_array,is_string}from"./common.js";import{exportIndex,importIndex,serialize}from"./serialize.js";import{remove_index}from"./index/remove.js";import apply_preset from"./preset.js";import apply_async from"./async.js";import tick from"./profiler.js";import"./index/add.js";import"./index/search.js";import"./index/remove.js";export default function Index(a,b){if(!this||this.constructor!==Index)return new Index(a);!1,a=a?apply_preset(a):{};let c=a.context;const d=!0===c?{depth:1}:c||{},e=is_string(a.encoder)?Charset[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"==typeof e?new Encoder(e):{encode:e},this.compress=a.compress||a.compression||!1,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,!1,c=a.keystore||0,c&&(this.keystore=c),this.map=c&&!0?new KeystoreMap(c):new Map,this.ctx=c&&!0?new KeystoreMap(c):new Map,this.reg=b||(this.fastupdate?c&&!0?new KeystoreMap(c):new Map:c&&!0?new KeystoreSet(c):new Set),this.resolution_ctx=d.resolution||3,this.rtl=e.rtl||a.rtl||!1,this.cache=(c=a.cache||null)&&new Cache(c),this.resolve=!1!==a.resolve,(c=a.db)&&(this.db=this.mount(c)),this.commit_auto=!1!==a.commit,this.commit_task=[],this.commit_timer=null,this.priority=a.priority||4}Index.prototype.mount=function(a){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),a.mount(this)},Index.prototype.commit=function(a,b){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.commit(this,a,b)},Index.prototype.destroy=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.destroy()};export function autoCommit(a,b,c){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null,a.db.commit(a,b,c)},1))}Index.prototype.clear=function(){return 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=[],this.db.clear()):this},Index.prototype.append=function(a,b){return this.add(a,b,!0)},Index.prototype.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)},Index.prototype.update=function(a,b){const c=this,d=this.remove(a);return d&&d.then?d.then(()=>c.add(a,b)):this.add(a,b)},Index.prototype.cleanup=function(){return this.fastupdate?(remove_index(this.map),this.depth&&remove_index(this.ctx),this):(!1,this)},Index.prototype.searchCache=searchCache,Index.prototype.export=exportIndex,Index.prototype.import=importIndex,Index.prototype.serialize=serialize,apply_async(Index.prototype); \ No newline at end of file diff --git a/dist/module-min/resolve/and.js b/dist/module-min/resolve/and.js index fd0c4b3..9961348 100644 --- a/dist/module-min/resolve/and.js +++ b/dist/module-min/resolve/and.js @@ -1 +1 @@ -import Resolver from"../resolver.js";import{get_max_len}from"../common.js";import{intersect}from"../intersect.js";import{SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";Resolver.prototype.and=function(){return this.handler("and",return_result,arguments)};function return_result(a,b,c,d,e,f){if(!f&&!this.result.length)return e?this.result:this;let g;if(!a.length)f||(this.result=a);else if(this.result.length&&a.unshift(this.result),2>a.length)this.result=a[0];else{let d=0;for(let b,c,e=0;ea.length)this.result=a[0];else{let d=0;for(let b,c,e=0;ea.length?this.result=a[0]:(this.result=union(a,b,c,!1,this.boostval),c=0)),e&&(this.await=null),e?this.resolve(b,c,d):this} \ No newline at end of file +import Resolver from"../resolver.js";import{union}from"../intersect.js";import{SearchResults,EnrichedSearchResults,IntermediateSearchResults,HighlightOptions}from"../type.js";Resolver.prototype.or=function(){return this.handler("or",return_result,arguments)};function return_result(a,b,c,d,e,f,g){return a.length&&(this.result.length&&a.push(this.result),2>a.length?this.result=a[0]:(this.result=union(a,b,c,!1,this.boostval),c=0)),e&&(this.await=null),e?this.resolve(b,c,d,g):this} \ No newline at end of file diff --git a/dist/module-min/resolve/xor.js b/dist/module-min/resolve/xor.js index 2545057..2888ce0 100644 --- a/dist/module-min/resolve/xor.js +++ b/dist/module-min/resolve/xor.js @@ -1 +1 @@ -import Resolver from"../resolver.js";import{create_object}from"../common.js";import{SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";Resolver.prototype.xor=function(){return this.handler("xor",return_result,arguments)};function return_result(a,b,c,d,e,f){let g;return a.length?(this.result.length&&a.unshift(this.result),2>a.length?this.result=a[0]:(this.result=exclusive.call(this,a,b,c,e,this.boostval),g=!0)):!f&&(this.result=a),e&&(this.await=null),e?this.resolve(b,c,d,g):this}function exclusive(a,b,c,d,e){const f=[],g=create_object();let h=0;for(let f,j=0;ja.length?this.result=a[0]:(this.result=exclusive.call(this,a,b,c,e,this.boostval),h=!0)):!f&&(this.result=a),e&&(this.await=null),e?this.resolve(b,c,d,g,h):this}function exclusive(a,b,c,d,e){const f=[],g=create_object();let h=0;for(let f,j=0;j} index + * @param {Map} index * @param {string} pluck * @param {HighlightOptions|string} config * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} @@ -69,7 +70,6 @@ export function highlight_fields(query, result, index, pluck, config) { let res; if (pluck) { - res = result; path = pluck; } else { @@ -82,7 +82,6 @@ export function highlight_fields(query, result, index, pluck, config) { idx = index.get(path); enc = idx.encoder; - idx.tokenize; query_enc = encoder.get(enc); if ("string" != typeof query_enc) { diff --git a/dist/module/index.js b/dist/module/index.js index 07160af..1c4ecb9 100644 --- a/dist/module/index.js +++ b/dist/module/index.js @@ -127,7 +127,8 @@ Index.prototype.clear = function () { if (this.db) { this.commit_timer && clearTimeout(this.commit_timer); this.commit_timer = null; - this.commit_task = [{ clear: !0 }]; + this.commit_task = []; + return this.db.clear(); } return this; diff --git a/dist/module/resolve/and.js b/dist/module/resolve/and.js index c31b89b..cf4ef0e 100644 --- a/dist/module/resolve/and.js +++ b/dist/module/resolve/and.js @@ -1,7 +1,7 @@ import Resolver from "../resolver.js"; import { get_max_len } from "../common.js"; import { intersect } from "../intersect.js"; -import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, HighlightOptions } from "../type.js"; /** * @return { @@ -25,6 +25,7 @@ Resolver.prototype.and = function () { * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -35,7 +36,7 @@ Resolver.prototype.and = function () { * } */ -function return_result(final, limit, offset, enrich, resolve, suggest) { +function return_result(final, limit, offset, enrich, resolve, suggest, highlight) { if (!suggest && !this.result.length) { return resolve ? this.result : this; @@ -79,5 +80,5 @@ function return_result(final, limit, offset, enrich, resolve, suggest) { this.await = null; } - return resolve ? this.resolve(limit, offset, enrich, resolved) : this; + return resolve ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } \ No newline at end of file diff --git a/dist/module/resolve/handler.js b/dist/module/resolve/handler.js index cd58493..626646a 100644 --- a/dist/module/resolve/handler.js +++ b/dist/module/resolve/handler.js @@ -70,8 +70,8 @@ Resolver.prototype.handler = function (method, fn, args) { offset = query.offset || 0; suggest = query.suggest; resolve = query.resolve; - highlight = query.highlight && resolve; - enrich = highlight || query.enrich && resolve; + highlight = resolve && query.highlight; + enrich = (highlight || query.enrich) && resolve; let opt_queue = query.queue, opt_async = query.async || opt_queue, index = query.index; @@ -88,7 +88,12 @@ Resolver.prototype.handler = function (method, fn, args) { const field = query.field || query.pluck; if (field) { - index = this.index.index.get(field); + if (query.query) { + this.query = query.query; + this.field = field; + } + + index = index.index.get(field); } } @@ -133,10 +138,6 @@ Resolver.prototype.handler = function (method, fn, args) { query.resolve = resolve; query.index = index; } - - if (highlight) { - query.query; - } } else if (query.and) { result = inner_call(query, "and", index); } else if (query.or) { @@ -178,22 +179,23 @@ Resolver.prototype.handler = function (method, fn, args) { for (let i = 0; i < self.promises.length; i++) { if (self.promises[i] === promises) { self.promises[i] = function () { - return fn.call(self, final, limit, offset, enrich, resolve, suggest); + return fn.call(self, final, limit, offset, enrich, resolve, suggest, highlight); }; break; } } self.execute(); }); + this.promises.push(promises); } else if (this.await) { this.promises.push(function () { - return fn.call(self, final, limit, offset, enrich, resolve, suggest); + return fn.call(self, final, limit, offset, enrich, resolve, suggest, highlight); }); } else { - return fn.call(this, final, limit, offset, enrich, resolve, suggest); + return fn.call(this, final, limit, offset, enrich, resolve, suggest, highlight); } return resolve ? this.await || this.result : this; diff --git a/dist/module/resolve/not.js b/dist/module/resolve/not.js index 8dd9cf5..15f2081 100644 --- a/dist/module/resolve/not.js +++ b/dist/module/resolve/not.js @@ -1,5 +1,5 @@ import Resolver from "../resolver.js"; -import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, HighlightOptions } from "../type.js"; /** @this {Resolver} */ Resolver.prototype.not = function () { @@ -13,6 +13,7 @@ Resolver.prototype.not = function () { * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -22,7 +23,7 @@ Resolver.prototype.not = function () { * Resolver * } */ -function return_result(final, limit, offset, enrich, resolve, suggest) { +function return_result(final, limit, offset, enrich, resolve, suggest, highlight) { if (!suggest && !this.result.length) { return resolve ? this.result : this; @@ -39,7 +40,7 @@ function return_result(final, limit, offset, enrich, resolve, suggest) { this.await = null; } - return resolve ? this.resolve(limit, offset, enrich, resolved) : this; + return resolve ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } /** diff --git a/dist/module/resolve/or.js b/dist/module/resolve/or.js index 3abd217..4d21867 100644 --- a/dist/module/resolve/or.js +++ b/dist/module/resolve/or.js @@ -1,6 +1,6 @@ import Resolver from "../resolver.js"; import { union } from "../intersect.js"; -import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, HighlightOptions } from "../type.js"; /** @this {Resolver} */ Resolver.prototype.or = function () { @@ -15,6 +15,7 @@ Resolver.prototype.or = function () { * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -25,7 +26,7 @@ Resolver.prototype.or = function () { * } */ -function return_result(final, limit, offset, enrich, resolve) { +function return_result(final, limit, offset, enrich, resolve, suggest, highlight) { if (final.length) { this.result.length && final.push(this.result); @@ -44,5 +45,5 @@ function return_result(final, limit, offset, enrich, resolve) { this.await = null; } - return resolve ? this.resolve(limit, offset, enrich) : this; + return resolve ? this.resolve(limit, offset, enrich, highlight) : this; } \ No newline at end of file diff --git a/dist/module/resolve/xor.js b/dist/module/resolve/xor.js index a940b12..ed577e7 100644 --- a/dist/module/resolve/xor.js +++ b/dist/module/resolve/xor.js @@ -1,6 +1,6 @@ import Resolver from "../resolver.js"; import { create_object } from "../common.js"; -import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, HighlightOptions } from "../type.js"; /** @this {Resolver} */ Resolver.prototype.xor = function () { @@ -14,6 +14,7 @@ Resolver.prototype.xor = function () { * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -24,7 +25,7 @@ Resolver.prototype.xor = function () { * } */ -function return_result(final, limit, offset, enrich, resolve, suggest) { +function return_result(final, limit, offset, enrich, resolve, suggest, highlight) { let resolved; @@ -45,7 +46,7 @@ function return_result(final, limit, offset, enrich, resolve, suggest) { this.await = null; } - return resolve ? this.resolve(limit, offset, enrich, resolved) : this; + return resolve ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } /** diff --git a/dist/module/resolver.js b/dist/module/resolver.js index 1b7055f..41b53a3 100644 --- a/dist/module/resolver.js +++ b/dist/module/resolver.js @@ -1,5 +1,5 @@ -import { ResolverOptions, IntermediateSearchResults, SearchResults, EnrichedSearchResults } from "./type.js"; +import { ResolverOptions, IntermediateSearchResults, SearchResults, EnrichedSearchResults, HighlightOptions } from "./type.js"; import Index from "./index.js"; import Document from "./document.js"; import WorkerIndex from "./worker.js"; @@ -10,6 +10,7 @@ import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; import { apply_enrich } from "./document/search.js"; +import { highlight_fields } from "./document/highlight.js"; /** * @param {IntermediateSearchResults|ResolverOptions=} result @@ -24,6 +25,8 @@ export default function Resolver(result, index) { let boost = 0, promises, + query, + field, _await, _return; @@ -31,7 +34,8 @@ export default function Resolver(result, index) { const options = /** @type {ResolverOptions} */result; index = options.index; boost = options.boost || 0; - if (options.query) { + if (query = options.query) { + field = options.field || options.pluck; const resolve = options.resolve, async = options.async || options.queue; @@ -71,28 +75,41 @@ export default function Resolver(result, index) { this.await = _await || null; /** @type {Function} */ this.return = _return || null; + + /** @type {string} */ + this.query = query || ""; + /** @type {string} */ + this.field = field || ""; } /** * @param {number} limit */ Resolver.prototype.limit = function (limit) { - if (this.result.length) { - /** @type {IntermediateSearchResults} */ - const final = []; - for (let j = 0, ids; j < this.result.length; j++) { - if (ids = this.result[j]) { - if (ids.length <= limit) { - final[j] = ids; - limit -= ids.length; - if (!limit) break; - } else { - final[j] = ids.slice(0, limit); - break; + if (this.await) { + const self = this; + this.promises.push(function () { + self.limit(limit); + return self.result; + }); + } else { + if (this.result.length) { + /** @type {IntermediateSearchResults} */ + const final = []; + for (let j = 0, ids; j < this.result.length; j++) { + if (ids = this.result[j]) { + if (ids.length <= limit) { + final[j] = ids; + limit -= ids.length; + if (!limit) break; + } else { + final[j] = ids.slice(0, limit); + break; + } } } + this.result = final; } - this.result = final; } return this; }; @@ -101,20 +118,28 @@ Resolver.prototype.limit = function (limit) { * @param {number} offset */ Resolver.prototype.offset = function (offset) { - if (this.result.length) { - /** @type {IntermediateSearchResults} */ - const final = []; - for (let j = 0, ids; j < this.result.length; j++) { - if (ids = this.result[j]) { - if (ids.length <= offset) { - offset -= ids.length; - } else { - final[j] = ids.slice(offset); - offset = 0; + if (this.await) { + const self = this; + this.promises.push(function () { + self.offset(offset); + return self.result; + }); + } else { + if (this.result.length) { + /** @type {IntermediateSearchResults} */ + const final = []; + for (let j = 0, ids; j < this.result.length; j++) { + if (ids = this.result[j]) { + if (ids.length <= offset) { + offset -= ids.length; + } else { + final[j] = ids.slice(offset); + offset = 0; + } } } + this.result = final; } - this.result = final; } return this; }; @@ -123,7 +148,15 @@ Resolver.prototype.offset = function (offset) { * @param {number} boost */ Resolver.prototype.boost = function (boost) { - this.boostval += boost; + if (this.await) { + const self = this; + this.promises.push(function () { + self.boost(boost); + return self.result; + }); + } else { + this.boostval += boost; + } return this; }; @@ -132,12 +165,13 @@ Resolver.prototype.boost = function (boost) { * @this {Resolver} */ Resolver.prototype.execute = function (_skip_callback) { + let result = this.result, + execute = this.await; - let result = this.result; + this.await = null; for (let i = 0, promise; i < this.promises.length; i++) { - promise = this.promises[i]; - if (promise) { + if (promise = this.promises[i]) { if ("function" == typeof promise) { result = promise(); this.promises[i] = result = result.result || result; @@ -147,15 +181,14 @@ Resolver.prototype.execute = function (_skip_callback) { this.promises[i] = result = result.result || result; i--; } else if (promise.then) { - return this.await; + return this.await = execute; } } } const fn = this.return; - this.result = result; + this.promises = []; - this.await = null; this.return = null; _skip_callback || fn(result); @@ -166,37 +199,56 @@ Resolver.prototype.execute = function (_skip_callback) { * @param {number|ResolverOptions=} limit * @param {number=} offset * @param {boolean=} enrich + * @param {string|HighlightOptions|boolean=} highlight * @param {boolean=} _resolved */ -Resolver.prototype.resolve = function (limit, offset, enrich, _resolved) { +Resolver.prototype.resolve = function (limit, offset, enrich, highlight, _resolved) { let result = this.await ? this.execute(!0) : this.result; if (result.then) { const self = this; return result.then(function () { - return self.resolve(limit, offset, enrich); + return self.resolve(limit, offset, enrich, highlight, _resolved); }); } if (result.length) { if ("object" == typeof limit) { - enrich = limit.enrich; + highlight = limit.highlight; + enrich = !!highlight || limit.enrich; offset = limit.offset; - limit = limit.limit; + } else { + highlight = highlight; + enrich = !!highlight || enrich; } result = _resolved ? enrich ? apply_enrich.call( /** @type {Document} */this.index, /** @type {SearchResults} */result) : result : default_resolver.call(this.index, result, limit || 100, offset, enrich); } + return this.finalize(result, highlight); +}; + +Resolver.prototype.finalize = function (result, highlight) { + + if (result.then) { + const self = this; + return result.then(function (result) { + return self.finalize(result, highlight); + }); + } + + if (highlight && result.length && this.query) { + result = highlight_fields(this.query, result, this.index.index, this.field, highlight); + } + const fn = this.return; - this.index = null; - this.result = null; - this.promises = null; - this.await = null; - this.return = null; + this.index = this.result = this.promises = this.await = this.return = null; + + this.query = this.field = ""; + fn && fn(result); return result; diff --git a/doc/document-search.md b/doc/document-search.md index c9814e6..025aeb0 100644 --- a/doc/document-search.md +++ b/doc/document-search.md @@ -27,14 +27,14 @@ FlexSearch Documents also contain these features: Default - document + document Document Descriptor Includes any specific information about how the document data should be indexed (mandatory) - worker + worker Boolean
String Enable a worker distributed model. Read more about here: Worker Index false @@ -43,7 +43,7 @@ FlexSearch Documents also contain these features: ### Document Search Options -> Document search options basically inherits from [Index Search Options](../README.md#search-options), so you can apply most of those options either in the top scope of the config (for all fields) or as per field or both of them. +> Document search options basically inherit from [Index Search Options](../README.md#search-options), so you can apply most of those options either in the top scope of the config (for all fields) or as per field or both of them. @@ -54,35 +54,45 @@ FlexSearch Documents also contain these features: - + - + - + - + + + + + + + + - + @@ -102,28 +112,28 @@ When creating a `Document`-Index you will need to define a document descriptor i - + - + - + - + - + @@ -143,21 +153,21 @@ When creating a `Document`-Index you will need to define a document descriptor i - + - + - + diff --git a/doc/resolver.md b/doc/resolver.md index 29202c1..6fc20ff 100644 --- a/doc/resolver.md +++ b/doc/resolver.md @@ -147,6 +147,191 @@ const result = new Resolver({ .resolve(100); ``` +## Resolver Tasks + +
Default
indexindex
field
String
Array<String>
Array<SearchOptions>
Sets the document fields which should be searched. When no field is set, all fields will be searched. Custom options per field are also supported.
tagtag Object<field:tag> Sets the document fields which should be searched. When no field is set, all fields will be searched. Custom options per field are also supported.
enrichenrich Boolean Enrich IDs from the results with the corresponding documents. false
mergehighlight + Highlighting Options
+ String +
Highlight query matches in the result (for Document Indexes only)false
merge Boolean Merge multiple fields in resultset into one and group results per ID false
pluckpluck String Pick and apply search to just one field and return a flat result representation falseDefault
idid String "id"
indexindex String
Array<String>
Array<FieldOptions>
tagtag String
Array<String>
Array<FieldOptions>
storestore Boolean
String
Array<String>
Array<FieldOptions>
falseDefault
fieldfield String The field name (colon seperated syntax) (mandatory)
filterfilter Function
customcustom Function
+ + + + + + + + + + + + + + + + + + + + + + + +
MethodDescriptionReturn
+ .and(options,...)
+ .or(options,...)
+ .not(options,...)
+ .xor(options,...) +
Apply an operationReturns a Resolver when resolve was not set to false within the options, otherwise it returns the result (or promise in async context).
+ .limit(number)
+ .offset(number)
+ .boost(number) +
Apply boost, limit and offset to the resultReturns a Resolver
+ .resolve(options) + Resolve resultsReturns the final result or promise in async context (can't be executed twice)
+ + +## Resolver Options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionValuesDescriptionDefault
Resolver Task Options:
query + String + The search query
index + Index
+ Document +
Assign the index where the query should be applied to
suggest + Boolean + Enables suggestions in resultsfalse
boost + Number + Boost or reduce the score of this query0
async + Boolean + Use a parallel processing workflowfalse
queue + Boolean + Use a queued processing workflowfalse
+ and
+ or
+ not
+ xor
+
+ Array<ResolverOptions> + Apply nested queries
resolve + Boolean + + Resolve the result immediately or not. When set to true all final resolve options are also allowed and there can't exist any further resolver operations. + false
Document Resolver Options:
field
pluck
+ String + Select the Document field on which the query should apply to.
Final Resolve Options:
enrich + Boolean + Enrich IDs from the results with the corresponding documents (for Document Indexes only)true
highlight + Highlighting Options
+ String +
Highlight query matches in the result (for Document Indexes only)
limit + Number + Sets the limit of results100
offset + Boolean + Apply offset (skip items)0
+ ### Using Cached Queries ```js diff --git a/package-lock.json b/package-lock.json index 56a78d1..ae2daf7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.201", + "version": "0.8.202", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.201", + "version": "0.8.202", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 940882d..9e6f1fc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.200", + "version": "0.8.202", "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/db/redis/index.js b/src/db/redis/index.js index 8e52820..b5d1759 100644 --- a/src/db/redis/index.js +++ b/src/db/redis/index.js @@ -1,26 +1,25 @@ import { createClient } from "redis"; +import StorageInterface from "../interface.js"; +import { toArray } from "../../common.js"; + +const VERSION = 1; +const fields = ["map", "ctx", "reg", "tag", "doc", "cfg"]; const defaults = { host: "localhost", port: "6379", user: null, pass: null }; -const VERSION = 1; -const fields = ["map", "ctx", "reg", "tag", "doc", "cfg"]; -import StorageInterface from "../interface.js"; -import { toArray } from "../../common.js"; +let DB, TRX; function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } -let DB, TRX; - /** * @constructor * @implements StorageInterface */ - export default function RedisDB(name, config = {}){ if(!this || this.constructor !== RedisDB){ return new RedisDB(name, config); @@ -88,23 +87,26 @@ RedisDB.prototype.close = async function(){ }; RedisDB.prototype.destroy = function(){ - return this.clear(); + return this.clear(true); }; -RedisDB.prototype.clear = function(){ +RedisDB.prototype.clear = function(destroy = false){ if(!this.id) return; const self = this; - return this.db.keys( - this.id + "*" - // this.id + "map" + this.field + "*", - // this.id + "ctx" + this.field + "*", - // this.id + "tag" + this.field + "*", - // this.id + "cfg" + this.field + "*", - // this.id + "doc", - // this.id + "reg" - ).then(function(keys){ + function unlink(keys){ return keys.length && self.db.unlink(keys); - }); + } + return Promise.all([ + this.db.keys(this.id + "map" + (destroy ? "" : this.field) + "*").then(unlink), + this.db.keys(this.id + "ctx" + (destroy ? "" : this.field) + "*").then(unlink), + this.db.keys(this.id + "tag" + (destroy ? "" : this.field) + "*").then(unlink), + this.db.keys(this.id + "ref" + (destroy ? "" : this.field) + "*").then(unlink), + unlink([ + this.id + "cfg" + (destroy ? "*" : this.field), + this.id + "doc", + this.id + "reg" + ]) + ]); }; function create_result(range, type, resolve, enrich, resolution){ @@ -200,7 +202,9 @@ RedisDB.prototype.enrich = function(ids){ }; RedisDB.prototype.has = function(id){ - return this.db.sIsMember(this.id + "reg", "" + id); + return this.db.sIsMember(this.id + "reg", "" + id).then(function(res){ + return !!res; + }); }; RedisDB.prototype.search = function(flexsearch, query, limit = 100, offset = 0, suggest = false, resolve = true, enrich = false, tags){ diff --git a/src/document/highlight.js b/src/document/highlight.js index 751e344..5b12153 100644 --- a/src/document/highlight.js +++ b/src/document/highlight.js @@ -3,6 +3,7 @@ import { DEBUG } from "../config.js"; // <-- COMPILER BLOCK import { parse_simple } from "../common.js"; import Index from "../index.js"; +import WorkerIndex from "../worker.js"; import { EnrichedDocumentSearchResults, EnrichedSearchResults, @@ -12,7 +13,7 @@ import { /** * @param {string} query * @param {EnrichedDocumentSearchResults|EnrichedSearchResults} result - * @param {Map} index + * @param {Map} index * @param {string} pluck * @param {HighlightOptions|string} config * @return {EnrichedDocumentSearchResults|EnrichedSearchResults} @@ -82,7 +83,6 @@ export function highlight_fields(query, result, index, pluck, config){ // cache shared encoders across fields let encoder = new Map(); let query_enc; - let tokenize; // todo remove this loop and pass in the field data directly // todo support field-specific configuration @@ -94,24 +94,22 @@ export function highlight_fields(query, result, index, pluck, config){ let res; if(pluck){ - //res = result[0].result; res = result; path = pluck; } else{ const tmp = result[i]; path = tmp.field; - // skip when not a field entry (e.g. tags) + // skip when not a field entry (e.g., tags) if(!path) continue; res = tmp.result; } idx = index.get(path); enc = idx.encoder; - tokenize = idx.tokenize; query_enc = encoder.get(enc); - // re-encode query when encoder has changed or take cache from shared encoders + // re-encode a query when encoder has changed or take cache from shared encoders if(typeof query_enc !== "string"){ query_enc = enc.encode(query); encoder.set(enc, query_enc); @@ -124,7 +122,7 @@ export function highlight_fields(query, result, index, pluck, config){ if(!doc) continue; const content = parse_simple(doc, path); if(!content) continue; - // just split on whitespace and keep original string (encoder split can't apply) + // just split on whitespace and keep the original string (encoder split can't apply) const doc_org = content.trim().split(/\s+/); if(!doc_org.length) continue; @@ -159,7 +157,7 @@ export function highlight_fields(query, result, index, pluck, config){ let query_enc_cur_len = query_enc_cur.length; // add length from shrinking phonetic transformations (todo: add tests) query_enc_cur_len += doc_org_diff; - // skip query token when match length can't exceed previously highest found match + // skip the query token when match length can't exceed the previously highest found match if(match_length && query_enc_cur_len <= match_length){ continue; } @@ -187,12 +185,12 @@ export function highlight_fields(query, result, index, pluck, config){ pos_first_match = str.length + (str ? 1 : 0); } pos_last_match = str.length + (str ? 1 : 0) + match.length; - // the overall length of all matches is used to check if matches exceeds the total boundary + // the overall length of all matches is used to check if matches exceed the total boundary // if so, it can early stop further processing length_matches_all += doc_org_cur_len; // the match positions are used to pick items for the final result more quickly pos_matches.push(str_arr.length) - // collect every term as match or text + // collect every term as a match or text str_arr.push({ match }); } str += (str ? " " : "") + match; @@ -202,12 +200,12 @@ export function highlight_fields(query, result, index, pluck, config){ if(!found){ const text = doc_org[k]; str += (str ? " " : "") + text; - // collect every term as match or text + // collect every term as a match or text boundary && str_arr.push({ text }); } else if(boundary){ if(length_matches_all >= boundary){ - // matches has reached total boundary + // matches have reached the total boundary break; } } @@ -219,7 +217,7 @@ export function highlight_fields(query, result, index, pluck, config){ // apply boundaries and align highlights if(boundary_before || boundary_after || (boundary && (str.length - markup_length) > boundary)){ - // also reduce ellipsis length from boundary + // also reduce ellipsis length from the boundary let boundary_length = boundary + markup_length - ellipsis_length * 2; let length = pos_last_match - pos_first_match; let start, end; @@ -351,12 +349,12 @@ export function highlight_fields(query, result, index, pluck, config){ // 2. add surrounded text to the result else{ // alternate direction term by term - // 2.1. extend to right first (index: k + 1) + // 2.1. extend to the right first (index: k + 1) if(shift_left !== shift_right){ if(finished[k + 1]) continue; pos += shift_right; - // overlap with other slot + // overlap with another slot if(check[pos]){ final_length -= ellipsis_length; seamless[k + 1] = 1; @@ -422,7 +420,7 @@ export function highlight_fields(query, result, index, pluck, config){ if(finished[k]) continue; pos -= shift_left; - // overlap with other slot + // overlap with another slot if(check[pos]){ final_length -= ellipsis_length; finished[k] = 1; @@ -500,11 +498,11 @@ export function highlight_fields(query, result, index, pluck, config){ shift_left === shift_right ? loop_left = 0 : loop_right = 0; - // break process when both directions are done + // break the process when both directions are done if(!loop_left && !loop_right){ break; } - // continue with opposite direction + // continue with the opposite direction if(loop_left){ shift_left++; shift_right = shift_left; @@ -603,7 +601,6 @@ export function highlight_fields(query, result, index, pluck, config){ // // cache shared encoders across fields // let encoder = new Map(); // let query_enc; -// let tokenize; // // // todo remove this loop and pass in the field data directly // // todo support field-specific configuration @@ -628,7 +625,6 @@ export function highlight_fields(query, result, index, pluck, config){ // // idx = index.get(path); // enc = idx.encoder; -// tokenize = idx.tokenize; // query_enc = encoder.get(enc); // // // re-encode query when encoder has changed or take cache from shared encoders diff --git a/src/index.js b/src/index.js index eefb476..900590a 100644 --- a/src/index.js +++ b/src/index.js @@ -193,7 +193,8 @@ Index.prototype.clear = function(){ if(SUPPORT_PERSISTENT && this.db){ this.commit_timer && clearTimeout(this.commit_timer); this.commit_timer = null; - this.commit_task = [{ "clear": true }]; + this.commit_task = [];// [{ "clear": true }]; + return this.db.clear(); } return this; diff --git a/src/resolve/and.js b/src/resolve/and.js index 19d8dc3..f8b398f 100644 --- a/src/resolve/and.js +++ b/src/resolve/and.js @@ -4,7 +4,8 @@ import { intersect } from "../intersect.js"; import { SearchResults, EnrichedSearchResults, - IntermediateSearchResults + IntermediateSearchResults, + HighlightOptions } from "../type.js"; /** @@ -29,6 +30,7 @@ Resolver.prototype["and"] = function(){ * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -39,7 +41,7 @@ Resolver.prototype["and"] = function(){ * } */ -function return_result(final, limit, offset, enrich, resolve, suggest){ +function return_result(final, limit, offset, enrich, resolve, suggest, highlight){ if(!suggest && !this.result.length){ return resolve @@ -101,6 +103,6 @@ function return_result(final, limit, offset, enrich, resolve, suggest){ } return resolve - ? this.resolve(limit, offset, enrich, resolved) + ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } diff --git a/src/resolve/handler.js b/src/resolve/handler.js index 4a401e0..ce0e6ac 100644 --- a/src/resolve/handler.js +++ b/src/resolve/handler.js @@ -56,7 +56,7 @@ Resolver.prototype.handler = function(method, fn, args){ const self = this; /** @type {!Array>} */ let final = []; - let limit = 0, offset = 0, enrich, resolve, suggest, highlight, highlight_query; + let limit = 0, offset = 0, enrich, resolve, suggest, highlight; let async; for(let i = 0; i < args.length; i++){ @@ -80,8 +80,8 @@ Resolver.prototype.handler = function(method, fn, args){ offset = query.offset || 0; suggest = query.suggest; resolve = query.resolve; - highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && query.highlight && resolve; - enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && highlight || (query.enrich && resolve); + highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && resolve && query.highlight; + enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && (highlight || query.enrich) && resolve; let opt_queue = SUPPORT_ASYNC && query.queue; let opt_async = SUPPORT_ASYNC && (query.async || opt_queue); let index = query.index; @@ -96,7 +96,7 @@ Resolver.prototype.handler = function(method, fn, args){ if(query.query || query.tag){ if(DEBUG){ - if(!this.index){ + if(!index){ throw new Error("Resolver can't apply because the corresponding Index was never specified"); } } @@ -105,13 +105,18 @@ Resolver.prototype.handler = function(method, fn, args){ const field = query.field || query.pluck; if(field){ + if(SUPPORT_STORE && SUPPORT_HIGHLIGHTING && query.query){ + this.query = query.query; + this.field = field; + } + if(DEBUG){ - if(!this.index.index){ + if(!index.index){ throw new Error("Resolver can't apply because the corresponding Document Index was not specified"); } } - index = this.index.index.get(field); + index = index.index.get(field); if(DEBUG){ if(!index){ @@ -169,10 +174,6 @@ Resolver.prototype.handler = function(method, fn, args){ query.resolve = resolve; query.index = index; } - - if(highlight){ - highlight_query = query.query; - } } else if(query.and){ result = inner_call(query, "and", index); @@ -227,7 +228,8 @@ Resolver.prototype.handler = function(method, fn, args){ offset, enrich, resolve, - suggest + suggest, + highlight ) }; break; @@ -235,6 +237,7 @@ Resolver.prototype.handler = function(method, fn, args){ } self.execute(); }); + this.promises.push(promises); } else if(this.await){ @@ -246,7 +249,8 @@ Resolver.prototype.handler = function(method, fn, args){ offset, enrich, resolve, - suggest + suggest, + highlight ); }); } @@ -258,7 +262,8 @@ Resolver.prototype.handler = function(method, fn, args){ offset, enrich, resolve, - suggest + suggest, + highlight ); } diff --git a/src/resolve/not.js b/src/resolve/not.js index 837a342..6be80d2 100644 --- a/src/resolve/not.js +++ b/src/resolve/not.js @@ -2,7 +2,8 @@ import Resolver from "../resolver.js"; import { SearchResults, EnrichedSearchResults, - IntermediateSearchResults + IntermediateSearchResults, + HighlightOptions } from "../type.js"; /** @this {Resolver} */ @@ -17,6 +18,7 @@ Resolver.prototype["not"] = function(){ * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -26,7 +28,7 @@ Resolver.prototype["not"] = function(){ * Resolver * } */ -function return_result(final, limit, offset, enrich, resolve, suggest){ +function return_result(final, limit, offset, enrich, resolve, suggest, highlight){ if(!suggest && !this.result.length){ return resolve @@ -52,7 +54,7 @@ function return_result(final, limit, offset, enrich, resolve, suggest){ } return resolve - ? this.resolve(limit, offset, enrich, resolved) + ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } diff --git a/src/resolve/or.js b/src/resolve/or.js index fd2a30a..3bbb49f 100644 --- a/src/resolve/or.js +++ b/src/resolve/or.js @@ -3,7 +3,8 @@ import { union } from "../intersect.js"; import { SearchResults, EnrichedSearchResults, - IntermediateSearchResults + IntermediateSearchResults, + HighlightOptions } from "../type.js"; /** @this {Resolver} */ @@ -19,6 +20,7 @@ Resolver.prototype["or"] = function(){ * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -29,7 +31,7 @@ Resolver.prototype["or"] = function(){ * } */ -function return_result(final, limit, offset, enrich, resolve, suggest){ +function return_result(final, limit, offset, enrich, resolve, suggest, highlight){ if(final.length){ this.result.length && (final.push(this.result)); @@ -58,6 +60,6 @@ function return_result(final, limit, offset, enrich, resolve, suggest){ } return resolve - ? this.resolve(limit, offset, enrich) + ? this.resolve(limit, offset, enrich, highlight) : this; } diff --git a/src/resolve/xor.js b/src/resolve/xor.js index 8552137..8b02ad3 100644 --- a/src/resolve/xor.js +++ b/src/resolve/xor.js @@ -3,7 +3,8 @@ import { create_object } from "../common.js"; import { SearchResults, EnrichedSearchResults, - IntermediateSearchResults + IntermediateSearchResults, + HighlightOptions } from "../type.js"; /** @this {Resolver} */ @@ -18,6 +19,7 @@ Resolver.prototype["xor"] = function(){ * @param {boolean=} enrich * @param {boolean=} resolve * @param {boolean=} suggest + * @param {string|HighlightOptions=} highlight * @this {Resolver} * @return { * SearchResults | @@ -28,7 +30,7 @@ Resolver.prototype["xor"] = function(){ * } */ -function return_result(final, limit, offset, enrich, resolve, suggest){ +function return_result(final, limit, offset, enrich, resolve, suggest, highlight){ let resolved; @@ -59,7 +61,7 @@ function return_result(final, limit, offset, enrich, resolve, suggest){ } return resolve - ? this.resolve(limit, offset, enrich, resolved) + ? this.resolve(limit, offset, enrich, highlight, resolved) : this; } diff --git a/src/resolver.js b/src/resolver.js index cd163bf..beaa2f6 100644 --- a/src/resolver.js +++ b/src/resolver.js @@ -2,7 +2,7 @@ import { DEBUG, SUPPORT_ASYNC, - SUPPORT_DOCUMENT, + SUPPORT_DOCUMENT, SUPPORT_HIGHLIGHTING, SUPPORT_STORE } from "./config.js"; // <-- COMPILER BLOCK @@ -10,7 +10,8 @@ import { ResolverOptions, IntermediateSearchResults, SearchResults, - EnrichedSearchResults + EnrichedSearchResults, + HighlightOptions } from "./type.js"; import Index from "./index.js"; import Document from "./document.js"; @@ -22,6 +23,7 @@ import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; import { apply_enrich } from "./document/search.js"; +import { highlight_fields } from "./document/highlight.js"; /** * @param {IntermediateSearchResults|ResolverOptions=} result @@ -38,6 +40,8 @@ export default function Resolver(result, index){ // } let boost = 0; let promises; + let query; + let field; let _await; let _return; @@ -45,7 +49,8 @@ export default function Resolver(result, index){ const options = /** @type {ResolverOptions} */ (result); index = options.index; boost = options.boost || 0; - if(options.query){ + if((query = options.query)){ + field = options.field || options.pluck; const resolve = options.resolve; const async = options.async || options.queue; options.resolve = false; @@ -62,11 +67,6 @@ export default function Resolver(result, index){ } } - // (async function(result){ - // console.log( result) - // console.log(await result) - // })(result); - if(result && result.then){ const self = this; result = result.then(function(result){ @@ -93,31 +93,44 @@ export default function Resolver(result, index){ /** @type {Function} */ this.return = _return || null; - ///** @type {string} */ - //this.query = ""; + if(SUPPORT_HIGHLIGHTING){ + /** @type {string} */ + this.query = query || ""; + /** @type {string} */ + this.field = field || ""; + } } /** * @param {number} limit */ Resolver.prototype.limit = function(limit){ - if(this.result.length){ - /** @type {IntermediateSearchResults} */ - const final = []; - for(let j = 0, ids; j < this.result.length; j++){ - if((ids = this.result[j])){ - if(ids.length <= limit){ - final[j] = ids; - limit -= ids.length; - if(!limit) break; - } - else{ - final[j] = ids.slice(0, limit); - break; + if(this.await){ + const self = this; + this.promises.push(function(){ + self.limit(limit); + return self.result; + }); + } + else{ + if(this.result.length){ + /** @type {IntermediateSearchResults} */ + const final = []; + for(let j = 0, ids; j < this.result.length; j++){ + if((ids = this.result[j])){ + if(ids.length <= limit){ + final[j] = ids; + limit -= ids.length; + if(!limit) break; + } + else{ + final[j] = ids.slice(0, limit); + break; + } } } + this.result = final; } - this.result = final; } return this; }; @@ -126,21 +139,30 @@ Resolver.prototype.limit = function(limit){ * @param {number} offset */ Resolver.prototype.offset = function(offset){ - if(this.result.length){ - /** @type {IntermediateSearchResults} */ - const final = []; - for(let j = 0, ids; j < this.result.length; j++){ - if((ids = this.result[j])){ - if(ids.length <= offset){ - offset -= ids.length; - } - else{ - final[j] = ids.slice(offset); - offset = 0; + if(this.await){ + const self = this; + this.promises.push(function(){ + self.offset(offset); + return self.result; + }); + } + else{ + if(this.result.length){ + /** @type {IntermediateSearchResults} */ + const final = []; + for(let j = 0, ids; j < this.result.length; j++){ + if((ids = this.result[j])){ + if(ids.length <= offset){ + offset -= ids.length; + } + else{ + final[j] = ids.slice(offset); + offset = 0; + } } } + this.result = final; } - this.result = final; } return this; }; @@ -149,7 +171,16 @@ Resolver.prototype.offset = function(offset){ * @param {number} boost */ Resolver.prototype.boost = function(boost){ - this.boostval += boost; + if(this.await){ + const self = this; + this.promises.push(function(){ + self.boost(boost); + return self.result; + }); + } + else{ + this.boostval += boost; + } return this; }; @@ -160,10 +191,13 @@ Resolver.prototype.boost = function(boost){ Resolver.prototype.execute = function(_skip_callback){ let result = this.result; + // temporary reset async state and restore when + // at least one unresolved promise was found + let execute = this.await; + this.await = null; for(let i = 0, promise; i < this.promises.length; i++){ - promise = this.promises[i]; - if(promise){ + if((promise = this.promises[i])){ if(typeof promise === "function"){ result = promise(); this.promises[i] = result = result.result || result; @@ -175,16 +209,16 @@ Resolver.prototype.execute = function(_skip_callback){ i--; } else if(promise.then){ - return this.await; + return this.await = execute; } } } const fn = this.return; - this.result = result; + //this.result = result; this.promises = []; - this.await = null; this.return = null; + //this.await = null; // return final result _skip_callback || fn(result); @@ -195,9 +229,10 @@ Resolver.prototype.execute = function(_skip_callback){ * @param {number|ResolverOptions=} limit * @param {number=} offset * @param {boolean=} enrich + * @param {string|HighlightOptions|boolean=} highlight * @param {boolean=} _resolved */ -Resolver.prototype.resolve = function(limit, offset, enrich, _resolved){ +Resolver.prototype.resolve = function(limit, offset, enrich, highlight, _resolved){ let result = this.await ? this.execute(true) @@ -206,22 +241,21 @@ Resolver.prototype.resolve = function(limit, offset, enrich, _resolved){ if(result.then){ const self = this; return result.then(function(){ - return self.resolve(limit, offset, enrich); + return self.resolve(limit, offset, enrich, highlight, _resolved); }); } if(result.length){ if(typeof limit === "object"){ - enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && limit.enrich; + highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && limit.highlight; + enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && (!!highlight || limit.enrich); offset = limit.offset; - if(DEBUG){ - // TODO - if(limit.highlight){ - console.warn('Highlighting results is not supported within the resolve() method. Instead pass highlight options within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); - } - } limit = limit.limit; } + else{ + highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && highlight; + enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && (!!highlight || enrich); + } result = _resolved ? (enrich ? apply_enrich.call( @@ -230,21 +264,41 @@ Resolver.prototype.resolve = function(limit, offset, enrich, _resolved){ ) : result) : default_resolver.call(this.index, result, limit || 100, offset, enrich); - // TODO - // if(highlight){ - // result = highlight_fields(result); - // } - // } + } + + return this.finalize(result, highlight); +}; + +Resolver.prototype.finalize = function(result, highlight){ + + if(result.then){ + const self = this; + return result.then(function(result){ + return self.finalize(result, highlight); + }); + } + + if(DEBUG){ + if(highlight && !this.query){ + console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); + } + } + if(SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && highlight && result.length && this.query){ + result = highlight_fields(this.query, result, this.index.index, this.field, highlight); } const fn = this.return; - this.index = null; - this.result = null; - this.promises = null; - this.await = null; + this.index = + this.result = + this.promises = + this.await = this.return = null; - //this.query = ""; + + if(SUPPORT_HIGHLIGHTING){ + this.query = + this.field = ""; + } fn && fn(result); return result; -}; +} diff --git a/test/.c8rc.json b/test/.c8rc.json index b01b2a0..a4852f2 100644 --- a/test/.c8rc.json +++ b/test/.c8rc.json @@ -1,19 +1,23 @@ { - "reporter": "text", - "reports-dir": "./test/report/", - "branches": 80, - "functions": 80, - "lines": 80, - "statements": 80, - "exclude": [ - "src/compress.js", - "src/db/indexeddb/**" - ], - "src": [ - "src" - ], - "include": [ - "test/*.js", - "src/**" - ] + "reporter": ["text", "text-summary", "html"], + "reports-dir": "./test/report/", + "branches": 80, + "functions": 80, + "lines": 80, + "statements": 80, + "src": [ + "src" + ], + "include": [ + "src/**" + ], + "exclude": [ + "test/*.js", + "src/compress.js", + "src/type.js", + "src/profiler.js", + "src/db/indexeddb/*", + "src/worker/node.js", + "src/worker/worker.js" + ] } \ No newline at end of file diff --git a/test/highlight.js b/test/highlight.js index d80d3db..ca71208 100644 --- a/test/highlight.js +++ b/test/highlight.js @@ -842,62 +842,62 @@ if(!build_light) describe("Result Highlighting", function(){ it("Should have been highlighted merged results properly", function(){ -// some test data -const data = [{ - "id": 1, - "title": "Carmencita", - "description": "Description: Carmencita" -},{ - "id": 2, - "title": "Le clown et ses chiens", - "description": "Description: Le clown et ses chiens" -}]; - -// create the document index -const index = new Document({ - encoder: Charset.LatinBalance, - document: { - store: true, - index: [{ - field: "title", - tokenize: "forward" + // some test data + const data = [{ + "id": 1, + "title": "Carmencita", + "description": "Description: Carmencita" },{ - field: "description", - tokenize: "forward" - }] - } -}); + "id": 2, + "title": "Le clown et ses chiens", + "description": "Description: Le clown et ses chiens" + }]; -// add test data -for(let i = 0; i < data.length; i++){ - index.add(data[i]); -} + // create the document index + const index = new Document({ + encoder: Charset.LatinBalance, + document: { + store: true, + index: [{ + field: "title", + tokenize: "forward" + },{ + field: "description", + tokenize: "forward" + }] + } + }); -let result = index.search({ - query: "karmen or clown or not found", - suggest: true, - enrich: true, - merge: true, - highlight: "$1" -}); + // add test data + for(let i = 0; i < data.length; i++){ + index.add(data[i]); + } -expect(result).to.eql([{ - id: 1, - doc: data[0], - field: ["title", "description"], - highlight: { - "title": 'Carmencita', - "description": 'Description: Carmencita', - } -},{ - id: 2, - doc: data[1], - field: ["title", "description"], - highlight: { - "title": 'Le clown et ses chiens', - "description": 'Description: Le clown et ses chiens', - } -}]); + let result = index.search({ + query: "karmen or clown or not found", + suggest: true, + enrich: true, + merge: true, + highlight: "$1" + }); + + expect(result).to.eql([{ + id: 1, + doc: data[0], + field: ["title", "description"], + highlight: { + "title": 'Carmencita', + "description": 'Description: Carmencita', + } + },{ + id: 2, + doc: data[1], + field: ["title", "description"], + highlight: { + "title": 'Le clown et ses chiens', + "description": 'Description: Le clown et ses chiens', + } + }]); }); it("Should have been highlighted results properly (#480)", function(){ diff --git a/test/package-lock.json b/test/package-lock.json index fa29ca1..396fe7b 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -13,7 +13,7 @@ "mocha": "^11.1.0", "mongodb": "^6.13.0", "pg-promise": "^11.10.2", - "redis": "^4.7.0", + "redis": "^5.1.0", "rollup": "^4.35.0", "sqlite3": "^5.1.7", "typescript": "^5.8.3" @@ -211,62 +211,63 @@ } }, "node_modules/@redis/bloom": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-1.2.0.tgz", - "integrity": "sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-5.1.0.tgz", + "integrity": "sha512-Gp5RWvVKbvItMU2sd848yhY/BnigToz8H4PYcvlBBSP5cQ3lVP1LMh5Kx2CYBNzCdDabVicwBKNvaoLBqPNqIg==", "dev": true, + "engines": { + "node": ">= 18" + }, "peerDependencies": { - "@redis/client": "^1.0.0" + "@redis/client": "^5.1.0" } }, "node_modules/@redis/client": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.6.0.tgz", - "integrity": "sha512-aR0uffYI700OEEH4gYnitAnv3vzVGXCFvYfdpu/CJKvk4pHfLPEy/JSZyrpQ+15WhXe1yJRXLtfQ84s4mEXnPg==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-5.1.0.tgz", + "integrity": "sha512-FMD35y2KgCWTBLOfF0MhwDSaIVcu5mOUuTV9Kw3JOWHMgON3+ulht31cjTB/gph0BfD1vzUvCeROeRaf/d+35w==", "dev": true, "dependencies": { - "cluster-key-slot": "1.1.2", - "generic-pool": "3.9.0", - "yallist": "4.0.0" + "cluster-key-slot": "1.1.2" }, "engines": { - "node": ">=14" - } - }, - "node_modules/@redis/graph": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.1.tgz", - "integrity": "sha512-FEMTcTHZozZciLRl6GiiIB4zGm5z5F3F6a6FZCyrfxdKOhFlGkiAqlexWMBzCi4DcRoyiOsuLfW+cjlGWyExOw==", - "dev": true, - "peerDependencies": { - "@redis/client": "^1.0.0" + "node": ">= 18" } }, "node_modules/@redis/json": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.7.tgz", - "integrity": "sha512-6UyXfjVaTBTJtKNG4/9Z8PSpKE6XgSyEb8iwaqDcy+uKrd/DGYHTWkUdnQDyzm727V7p21WUMhsqz5oy65kPcQ==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-5.1.0.tgz", + "integrity": "sha512-laXZt1Rlimk3py5ZoABBnd4xn/8dWbLUWGvVS7avgMhdczS+eWtXpElilJbFpc+7ZpVlol4vaSGFuR8ThDcTFw==", "dev": true, + "engines": { + "node": ">= 18" + }, "peerDependencies": { - "@redis/client": "^1.0.0" + "@redis/client": "^5.1.0" } }, "node_modules/@redis/search": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.2.0.tgz", - "integrity": "sha512-tYoDBbtqOVigEDMAcTGsRlMycIIjwMCgD8eR2t0NANeQmgK/lvxNAvYyb6bZDD4frHRhIHkJu2TBRvB0ERkOmw==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-5.1.0.tgz", + "integrity": "sha512-afQYMeIdWGNPjr84GxxgJVkolxMW3BBrlNOwhRHPdzbdGh0rTUPjOJpGHBig34ostHX6AhZ6QwqceU1zLluDEg==", "dev": true, + "engines": { + "node": ">= 18" + }, "peerDependencies": { - "@redis/client": "^1.0.0" + "@redis/client": "^5.1.0" } }, "node_modules/@redis/time-series": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.1.0.tgz", - "integrity": "sha512-c1Q99M5ljsIuc4YdaCwfUEXsofakb9c8+Zse2qxTadu8TalLXuAESzLvFAvNVbkmSlvlzIQOLpBCmWI9wTOt+g==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-5.1.0.tgz", + "integrity": "sha512-BjKndLXREPeb4ZtxrI6z1bz2FbzBj7LnWyyevNk6Wd7VRWQ3W10LSvJAJwguPD62mSqpTPhy0lMPqFJwo0gS7A==", "dev": true, + "engines": { + "node": ">= 18" + }, "peerDependencies": { - "@redis/client": "^1.0.0" + "@redis/client": "^5.1.0" } }, "node_modules/@rollup/rollup-android-arm-eabi": { @@ -1588,15 +1589,6 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, - "node_modules/generic-pool": { - "version": "3.9.0", - "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz", - "integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==", - "dev": true, - "engines": { - "node": ">= 4" - } - }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -3179,17 +3171,19 @@ } }, "node_modules/redis": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/redis/-/redis-4.7.0.tgz", - "integrity": "sha512-zvmkHEAdGMn+hMRXuMBtu4Vo5P6rHQjLoHftu+lBqq8ZTA3RCVC/WzD790bkKKiNFp7d5/9PcSD19fJyyRvOdQ==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/redis/-/redis-5.1.0.tgz", + "integrity": "sha512-5G5k9sYo5H5L0kd7UETiJZFTkIClH31fSmaEk2eU8E7mrmF0J1t6RqmFXOCJmSRlNd3QyvDUK/AWL9psbKaN0Q==", "dev": true, "dependencies": { - "@redis/bloom": "1.2.0", - "@redis/client": "1.6.0", - "@redis/graph": "1.1.1", - "@redis/json": "1.0.7", - "@redis/search": "1.2.0", - "@redis/time-series": "1.1.0" + "@redis/bloom": "5.1.0", + "@redis/client": "5.1.0", + "@redis/json": "5.1.0", + "@redis/search": "5.1.0", + "@redis/time-series": "5.1.0" + }, + "engines": { + "node": ">= 18" } }, "node_modules/request": { diff --git a/test/package.json b/test/package.json index 7fef9ee..7890cd8 100644 --- a/test/package.json +++ b/test/package.json @@ -18,7 +18,7 @@ "mocha": "^11.1.0", "mongodb": "^6.13.0", "pg-promise": "^11.10.2", - "redis": "^4.7.0", + "redis": "^5.1.0", "rollup": "^4.35.0", "sqlite3": "^5.1.7", "typescript": "^5.8.3" diff --git a/test/persistent.clickhouse.js b/test/persistent.clickhouse.js index 194d1b0..2c49120 100644 --- a/test/persistent.clickhouse.js +++ b/test/persistent.clickhouse.js @@ -10,11 +10,12 @@ const build_compact = env && env.includes(".compact"); const build_esm = !env || env.startsWith("module"); const Charset = _Charset || (await import("../src/charset.js")).default; -import Clickhouse from "flexsearch/db/clickhouse"; +import Clickhouse_src from "../src/db/clickhouse/index.js"; +import Clickhouse_dist from "../dist/module/db/clickhouse/index.js"; import tests from "./persistent.js"; if(!build_light && !build_compact){ describe("Persistent: Clickhouse", function(){ - tests(Clickhouse, "Clickhouse"); + tests(env ? Clickhouse_dist : Clickhouse_src, "Clickhouse"); }); } diff --git a/test/persistent.js b/test/persistent.js index 0cd89fb..20ecdb4 100644 --- a/test/persistent.js +++ b/test/persistent.js @@ -236,18 +236,13 @@ export default function(DB, DBClass){ // mount database to the index await document.mount(db); + await document.clear(); + expect(document.index.get("primaryTitle").db).to.be.instanceof(db.constructor); expect(document.index.get("originalTitle").db).to.be.instanceof(db.constructor); expect(document.index.get("startYear").db).to.be.instanceof(db.constructor); expect(document.index.get("genres").db).to.be.instanceof(db.constructor); - //await document.destroy(); - //expect(document.index.get("primaryTitle").db).to.be.instanceof(db.constructor); - // mount database to the index - //await db.mount(document); - //expect(document.index.get("primaryTitle").db).to.be.instanceof(db.constructor); - //await document.clear(); - // add test data for(let i = 0; i < data.length; i++){ document.add(data[i]); @@ -270,7 +265,6 @@ export default function(DB, DBClass){ // transfer changes in bulk await document.commit(); - //await new Promise(resolve => setTimeout(resolve, 200)); expect(document.index.get("primaryTitle").reg.size).to.equal(0); expect(document.index.get("primaryTitle").map.size).to.equal(0); @@ -382,6 +376,17 @@ export default function(DB, DBClass){ field: [ 'primaryTitle', 'originalTitle' ] }); + await document.clear(); + + result = await document.search({ + query: "karmen or clown or nothing", + suggest: true, + enrich: true, + merge: true + }); + + expect(result).to.eql([]); + for(const index of document.index.values()){ index.destroy(); index.db.close(); @@ -400,7 +405,7 @@ export default function(DB, DBClass){ }]; // create the document index - const index = new Document({ + const document = new Document({ cache: true, db: new DB("test-highlight", { type: "Integer" @@ -415,18 +420,18 @@ export default function(DB, DBClass){ } }); - //await index.mount(db); - await index.db; + //await document.mount(db); + await document.db; // add test data for(let i = 0; i < data.length; i++){ - index.add(data[i]); + document.add(data[i]); } - await index.commit(); + await document.commit(); // perform a query - let result = await index.searchCache({ + let result = await document.searchCache({ query: "karmen or clown or not found", suggest: true, highlight: "$1" @@ -443,7 +448,7 @@ export default function(DB, DBClass){ }]); // perform a query on cache - result = await index.searchCache({ + result = await document.searchCache({ query: "karmen or clown or not found", suggest: true, highlight: "$1" @@ -460,7 +465,7 @@ export default function(DB, DBClass){ }]); // perform a query using pluck - result = await index.search({ + result = await document.search({ query: "karmen or clown or not found", suggest: true, field: "title", @@ -476,6 +481,11 @@ export default function(DB, DBClass){ doc: data[1], highlight: 'Le clown et ses chiens' }]); + + for(const index of document.index.values()){ + index.destroy(); + index.db.close(); + } }); it("Resolver (Persistent)", async function(){ @@ -492,7 +502,7 @@ export default function(DB, DBClass){ }]; // create the document index - const index = new Document({ + const document = new Document({ db: new DB("test-store", { type: "integer" }), @@ -509,78 +519,77 @@ export default function(DB, DBClass){ } }); - await index.db; + await document.db; // add test data for(let i = 0; i < data.length; i++){ - index.add(data[i]); + document.add(data[i]); } - await index.commit(); + await document.commit(); let result = new Resolver({ - index: index, - query: "karmen", - field: "title" + index: document, + query: "not found", + field: "description" }); expect(result).to.be.instanceof(Resolver); - result = result.or({ - query: "clown", - pluck: "description", - }); - result = result.and({ - query: "not found", - field: "title", + query: "karmen or clown", + pluck: "title", suggest: true, enrich: true, resolve: true, - // TODO - //highlight: "$1" + highlight: "$1" }); expect(result).to.be.instanceof(Promise); expect(await result).to.eql([{ id: 1, doc: data[0], - //highlight: "Carmencita" + highlight: "Carmencita" },{ id: 2, doc: data[1], - //highlight: "Le clown et ses chiens" + highlight: "Le clown et ses chiens" }]); // ----------------------------------- result = new Resolver({ - index: index, - query: "karmen", - field: "title" + index: document, + query: "not found", + field: "description" }); expect(result).to.be.instanceof(Resolver); result = result.or({ - query: "clown", - pluck: "description", - }).and({ - query: "not found", - field: "title", + query: "karmen or clown", + pluck: "title", suggest: true }).resolve({ - enrich: true + enrich: true, + highlight: "$1" }); expect(result).to.be.instanceof(Promise); expect(await result).to.eql([{ id: 1, - doc: data[0] + doc: data[0], + highlight: "Carmencita" },{ id: 2, - doc: data[1] + doc: data[1], + highlight: "Le clown et ses chiens" }]); + + for(const index of document.index.values()){ + index.destroy(); + index.db.close(); + } }); it("Should have been resolved a Resolver properly (Async)", async function(){ @@ -744,6 +753,9 @@ export default function(DB, DBClass){ expect(resolver).to.be.instanceof(Promise); expect(await resolver).to.have.members([3, 1, 2]); + + await index.destroy(); + await index.db.close(); }); it("Should have been resolved a Resolver properly (Document Persistent)", async function(){ @@ -774,6 +786,7 @@ export default function(DB, DBClass){ // mount database to the index await document.mount(db); + await document.clear(); // add test data for(let i = 0; i < data.length; i++){ @@ -926,180 +939,11 @@ export default function(DB, DBClass){ expect(resolver).to.be.instanceof(Promise); expect(await resolver).to.eql(["tt0000001", "tt0000002"]); - }); - it("Should have been resolved a Resolver properly (Document Worker)", async function(){ - - // create the document index - const document = await new Document({ - worker: true, - encoder: Charset.LatinBalance, - document: { - id: "tconst", - store: true, - index: [{ - field: "primaryTitle", - tokenize: "forward" - },{ - field: "originalTitle", - tokenize: "forward" - }], - tag: [{ - field: "startYear" - },{ - field: "genres" - }] - } - }); - - // add test data - for(let i = 0; i < data.length; i++){ - await document.addAsync(data[i]); + for(const index of document.index.values()){ + index.destroy(); + index.db.close(); } - - let resolver = new Resolver({ - index: document, - query: "karmen or clown or nothing", - field: "primaryTitle", - suggest: true - }); - - expect(resolver).to.be.instanceof(Resolver); - expect(resolver.result).to.eql([]); - expect(resolver.await).to.be.instanceof(Promise); - - let tmp = resolver.await; - resolver = resolver.resolve(); - expect(resolver).to.be.instanceof(Promise); - expect(await resolver).to.have.members(["tt0000001", "tt0000002"]); - expect((await tmp)[0]).to.have.members(["tt0000001"]); - - // ----------------------------------- - - resolver = new Resolver({ - index: document, - async: true, - query: "karmen or clown or nothing", - field: "primaryTitle", - suggest: true - }); - - expect(resolver).to.be.instanceof(Resolver); - expect(resolver.result).to.eql([]); - expect(resolver.await).to.be.instanceof(Promise); - - tmp = resolver.await; - resolver = resolver.resolve({ enrich: true }); - expect(resolver).to.be.instanceof(Promise); - expect(await resolver).to.eql([{ - id: data[0].tconst, - doc: data[0] - }, { - id: data[1].tconst, - doc: data[1] - }]); - expect((await tmp)[0]).to.have.members(["tt0000001"]); - - // ----------------------------------- - - resolver = new Resolver({ - index: document, - async: true, - query: "karmen or clown or nothing", - field: "primaryTitle", - suggest: true - }).or({ - index: document, - queue: true, - query: "karmen or clown or nothing", - pluck: "primaryTitle", - suggest: true, - enrich: true, - resolve: true - }); - - expect(resolver).to.be.instanceof(Promise); - expect(await resolver).to.eql([{ - id: data[0].tconst, - doc: data[0] - }, { - id: data[1].tconst, - doc: data[1] - }]); - - // ----------------------------------- - - resolver = new Resolver({ - index: document, - async: true, - query: "karmen or clown or nothing", - pluck: "primaryTitle", - suggest: true - }); - - expect(resolver).to.be.instanceof(Resolver); - expect(resolver.result).to.eql([]); - expect(resolver.await).to.be.instanceof(Promise); - - resolver = resolver.resolve({ - limit: 1, - offset: 1 - }); - expect(resolver).to.be.instanceof(Promise); - expect(await resolver).to.eql(["tt0000002"]); - - // ----------------------------------- - - resolver = new Resolver({ - index: document, - async: true, - query: "karmen", - pluck: "primaryTitle" - }).or({ - queue: true, - cache: true, - query: "clown", - field: "originalTitle" - }).and({ - async: true, - query: "not found", - pluck: "originalTitle", - suggest: true - }); - - expect(resolver).to.be.instanceof(Resolver); - resolver = resolver.resolve(); - - expect(resolver).to.be.instanceof(Promise); - expect(await resolver).to.eql(["tt0000001", "tt0000002"]); - - // ----------------------------------- - - resolver = new Resolver({ - index: document, - async: true, - // TODO - //cache: true, - query: "karmen", - pluck: "primaryTitle" - }).or({ - and: [{ - async: true, - //cache: true, - query: "not found", - pluck: "originalTitle", - suggest: true - },{ - queue: true, - //cache: true, - query: "clown", - field: "originalTitle", - suggest: true - }] - }).resolve(); - - expect(resolver).to.be.instanceof(Promise); - expect(await resolver).to.eql(["tt0000001", "tt0000002"]); }); it("Should have been resolved a Resolver properly (Queue)", async function(){ @@ -1165,11 +1009,11 @@ export default function(DB, DBClass){ index: index, async: true, query: "bar" - }).and({ + }).limit(3).and({ queue: true, query: "foo", suggest: true - }); + }).limit(3); expect(resolver).to.be.instanceof(Resolver); resolver = resolver.resolve(); @@ -1179,6 +1023,24 @@ export default function(DB, DBClass){ // ----------------------------------- + resolver = new Resolver({ + index: index, + async: true, + query: "bar" + }).boost(2).and({ + queue: true, + query: "foo", + suggest: true + }).offset(1).limit(1); + + expect(resolver).to.be.instanceof(Resolver); + resolver = resolver.resolve(); + + expect(resolver).to.be.instanceof(Promise); + expect(await resolver).to.have.members([1]); + + // ----------------------------------- + resolver = new Resolver({ index: index, queue: true, @@ -1264,5 +1126,46 @@ export default function(DB, DBClass){ expect(resolver).to.be.instanceof(Promise); expect(await resolver).to.have.members([3, 1, 2]); + + await index.destroy(); + await index.db.close(); + }); + + it("#504", async function(){ + + const document = new Document({ + tokenize: "forward", + commit: true, + document: { + id: "id", + index: ["name", "shortName"], + store: true, + }, + }); + + const db = new DB("mystore", { type: "integer" }); + await document.mount(db); + await document.clear(); + + document.add({ + id: 1, + name: "a name", + shortName: "" // Or undefined + }); + + await document.commit(); + + const result = await document.search({ + query: "name" + }); + + expect(result).to.eql([ + { field: 'name', result: [ 1 ] } + ]); + + for(const index of document.index.values()){ + index.destroy(); + index.db.close(); + } }); } diff --git a/test/persistent.mongo.js b/test/persistent.mongo.js index 43d1e9b..1a5e478 100644 --- a/test/persistent.mongo.js +++ b/test/persistent.mongo.js @@ -10,11 +10,12 @@ const build_compact = env && env.includes(".compact"); const build_esm = !env || env.startsWith("module"); const Charset = _Charset || (await import("../src/charset.js")).default; -import Mongo from "flexsearch/db/mongodb"; +import Mongo_src from "../src/db/mongodb/index.js"; +import Mongo_dist from "../dist/module/db/mongodb/index.js"; import tests from "./persistent.js"; if(!build_light && !build_compact){ describe("Persistent: Mongo", function(){ - tests(Mongo, "Mongo"); + tests(env ? Mongo_dist : Mongo_src, "Mongo"); }); } diff --git a/test/persistent.postgres.js b/test/persistent.postgres.js index 1c417c2..88207df 100644 --- a/test/persistent.postgres.js +++ b/test/persistent.postgres.js @@ -10,11 +10,12 @@ const build_compact = env && env.includes(".compact"); const build_esm = !env || env.startsWith("module"); const Charset = _Charset || (await import("../src/charset.js")).default; -import Postgres from "flexsearch/db/postgres"; +import Postgres_src from "../src/db/postgres/index.js"; +import Postgres_dist from "../dist/module/db/postgres/index.js"; import tests from "./persistent.js"; if(!build_light && !build_compact){ describe("Persistent: Postgres", function(){ - tests(Postgres, "Postgres"); + tests(env ? Postgres_dist : Postgres_src, "Postgres"); }); } diff --git a/test/persistent.redis.js b/test/persistent.redis.js index 4bacde2..6e2f794 100644 --- a/test/persistent.redis.js +++ b/test/persistent.redis.js @@ -10,11 +10,12 @@ const build_compact = env && env.includes(".compact"); const build_esm = !env || env.startsWith("module"); const Charset = _Charset || (await import("../src/charset.js")).default; -import Redis from "flexsearch/db/redis"; +import Redis_src from "../src/db/redis/index.js"; +import Redis_dist from "../dist/module/db/redis/index.js"; import tests from "./persistent.js"; if(!build_light && !build_compact){ describe("Persistent: Redis", function(){ - tests(Redis, "Redis"); + tests(env ? Redis_dist : Redis_src, "Redis"); }); } diff --git a/test/persistent.sqlite.js b/test/persistent.sqlite.js index 946e022..40f320f 100644 --- a/test/persistent.sqlite.js +++ b/test/persistent.sqlite.js @@ -10,11 +10,12 @@ const build_compact = env && env.includes(".compact"); const build_esm = !env || env.startsWith("module"); const Charset = _Charset || (await import("../src/charset.js")).default; -import SQLite from "flexsearch/db/sqlite"; +import SQLite_src from "../src/db/sqlite/index.js"; +import SQLite_dist from "../dist/module/db/sqlite/index.js"; import tests from "./persistent.js"; if(!build_light && !build_compact){ describe("Persistent: SQLite", function(){ - tests(SQLite, "SQLite"); + tests(env ? SQLite_dist : SQLite_src, "SQLite"); }); } diff --git a/test/types.ts b/test/types.ts index 3d1e264..ea6a04d 100644 --- a/test/types.ts +++ b/test/types.ts @@ -16,6 +16,11 @@ import { DocumentData } from "flexsearch"; +test_index(); +test_document(); +test_persistent(); +test_worker(); + async function test_index() { const index = new Index(); diff --git a/test/worker.js b/test/worker.js index 58c5d4b..4b5c5d6 100644 --- a/test/worker.js +++ b/test/worker.js @@ -100,6 +100,289 @@ if(!build_light && !build_compact) describe("Worker", function(){ expect(await index.search("bar")).to.have.lengthOf(0); expect(await index.search("foobar")).to.have.lengthOf(0); }); + + it("Result Highlighting", async function(){ + + // some test data + const data = [{ + "id": 1, + "title": "Carmencita" + },{ + "id": 2, + "title": "Le clown et ses chiens" + }]; + + // create the document index + const document = await new Document({ + worker: true, + document: { + store: true, + index: [{ + field: "title", + tokenize: "forward", + encoder: Charset.LatinBalance + }] + } + }); + + // add test data + for(let i = 0; i < data.length; i++){ + await document.add(data[i]); + } + + // perform a query + let result = await document.searchCache({ + query: "karmen or clown or not found", + suggest: true, + highlight: "$1" + }); + + expect(result[0].result).to.eql([{ + id: 1, + doc: data[0], + highlight: 'Carmencita' + },{ + id: 2, + doc: data[1], + highlight: 'Le clown et ses chiens' + }]); + + // perform a query on cache + result = await document.searchCache({ + query: "karmen or clown or not found", + suggest: true, + highlight: "$1" + }); + + expect(result[0].result).to.eql([{ + id: 1, + doc: data[0], + highlight: 'Carmencita' + }, { + id: 2, + doc: data[1], + highlight: 'Le clown et ses chiens' + }]); + + // perform a query using pluck + result = await document.search({ + query: "karmen or clown or not found", + suggest: true, + field: "title", + highlight: "$1" + }); + + expect(result[0].result).to.eql([{ + id: 1, + doc: data[0], + highlight: 'Carmencita' + },{ + id: 2, + doc: data[1], + highlight: 'Le clown et ses chiens' + }]); + }); + + it("Should have been resolved a Resolver properly (Document Worker)", async function(){ + + const data = [{ + "tconst": "tt0000001", + "titleType": "short", + "primaryTitle": "Carmencita", + "originalTitle": "Carmencita", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + },{ + "tconst": "tt0000002", + "titleType": "short", + "primaryTitle": "Le clown et ses chiens", + "originalTitle": "Le clown et ses chiens", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "5", + "genres": [ + "Animation", + "Short" + ] + }]; + + // create the document index + const document = await new Document({ + worker: true, + encoder: Charset.LatinBalance, + document: { + id: "tconst", + store: true, + index: [{ + field: "primaryTitle", + tokenize: "forward" + },{ + field: "originalTitle", + tokenize: "forward" + }], + tag: [{ + field: "startYear" + },{ + field: "genres" + }] + } + }); + + // add test data + for(let i = 0; i < data.length; i++){ + await document.addAsync(data[i]); + } + + let resolver = new Resolver({ + index: document, + query: "karmen or clown or nothing", + field: "primaryTitle", + suggest: true + }); + + expect(resolver).to.be.instanceof(Resolver); + expect(resolver.result).to.eql([]); + expect(resolver.await).to.be.instanceof(Promise); + + let tmp = resolver.await; + resolver = resolver.resolve(); + expect(resolver).to.be.instanceof(Promise); + expect(await resolver).to.have.members(["tt0000001", "tt0000002"]); + expect((await tmp)[0]).to.have.members(["tt0000001"]); + + // ----------------------------------- + + resolver = new Resolver({ + index: document, + async: true, + query: "karmen or clown or nothing", + field: "primaryTitle", + suggest: true + }); + + expect(resolver).to.be.instanceof(Resolver); + expect(resolver.result).to.eql([]); + expect(resolver.await).to.be.instanceof(Promise); + + tmp = resolver.await; + resolver = resolver.resolve({ enrich: true }); + expect(resolver).to.be.instanceof(Promise); + expect(await resolver).to.eql([{ + id: data[0].tconst, + doc: data[0] + }, { + id: data[1].tconst, + doc: data[1] + }]); + expect((await tmp)[0]).to.have.members(["tt0000001"]); + + // ----------------------------------- + + resolver = new Resolver({ + index: document, + async: true, + query: "karmen or clown or nothing", + field: "primaryTitle", + suggest: true + }).or({ + index: document, + queue: true, + query: "karmen or clown or nothing", + pluck: "primaryTitle", + suggest: true, + enrich: true, + resolve: true + }); + + expect(resolver).to.be.instanceof(Promise); + expect(await resolver).to.eql([{ + id: data[0].tconst, + doc: data[0] + }, { + id: data[1].tconst, + doc: data[1] + }]); + + // ----------------------------------- + + resolver = new Resolver({ + index: document, + async: true, + query: "karmen or clown or nothing", + pluck: "primaryTitle", + suggest: true + }); + + expect(resolver).to.be.instanceof(Resolver); + expect(resolver.result).to.eql([]); + expect(resolver.await).to.be.instanceof(Promise); + + resolver = resolver.resolve({ + limit: 1, + offset: 1 + }); + expect(resolver).to.be.instanceof(Promise); + expect(await resolver).to.eql(["tt0000002"]); + + // ----------------------------------- + + resolver = new Resolver({ + index: document, + async: true, + query: "karmen", + pluck: "primaryTitle" + }).or({ + queue: true, + cache: true, + query: "clown", + field: "originalTitle" + }).and({ + async: true, + query: "not found", + pluck: "originalTitle", + suggest: true + }); + + expect(resolver).to.be.instanceof(Resolver); + resolver = resolver.resolve(); + + expect(resolver).to.be.instanceof(Promise); + expect(await resolver).to.eql(["tt0000001", "tt0000002"]); + + // ----------------------------------- + + resolver = new Resolver({ + index: document, + async: true, + cache: true, + query: "karmen", + pluck: "primaryTitle" + }).or({ + and: [{ + async: true, + cache: true, + query: "not found", + pluck: "originalTitle", + suggest: true + },{ + queue: true, + cache: true, + query: "clown", + field: "originalTitle", + suggest: true + }] + }).resolve(); + + expect(resolver).to.be.instanceof(Promise); + expect(await resolver).to.eql(["tt0000001", "tt0000002"]); + }); });