diff --git a/README.md b/README.md index b704bd0..244b2a7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ FlexSearch v0.8: [Overview and Migration Guide](doc/0.8.0.md) - + diff --git a/dist/db/indexeddb/index.js b/dist/db/indexeddb/index.js index 37fce61..03d122e 100644 --- a/dist/db/indexeddb/index.js +++ b/dist/db/indexeddb/index.js @@ -31,6 +31,10 @@ const IndexedDB = typeof window !== "undefined" && ( ); const fields = ["map", "ctx", "tag", "reg", "cfg"]; +/** + * @param {!string} str + * @return {string} + */ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } @@ -55,7 +59,9 @@ function IdxDB(name, config = {}){ } this.id = "flexsearch" + (name ? ":" + sanitize(name) : ""); this.field = config.field ? sanitize(config.field) : ""; + this.type = config.type; this.support_tag_search = false; + this.fastupdate = false; this.db = null; this.trx = {}; } @@ -134,8 +140,12 @@ IdxDB.prototype.close = function(){ this.db = null; }; +/** + * @return {!Promise} + */ IdxDB.prototype.destroy = function(){ - return IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const req = IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return promisfy(req); }; // IdxDB.prototype.set = function(ref, key, ctx, data){ @@ -152,6 +162,9 @@ IdxDB.prototype.destroy = function(){ // return transaction;//promisfy(req, callback); // }; +/** + * @return {!Promise} + */ IdxDB.prototype.clear = function(){ const transaction = this.db.transaction(fields, "readwrite"); for(let i = 0; i < fields.length; i++){ @@ -160,6 +173,15 @@ IdxDB.prototype.clear = function(){ return promisfy(transaction); }; +/** + * @param {!string} key + * @param {string=} ctx + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @return {!Promise} + */ IdxDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, enrich = false){ const transaction = this.db.transaction(ctx ? "ctx" : "map", "readonly"); const map = transaction.objectStore(ctx ? "ctx" : "map"); @@ -202,6 +224,13 @@ IdxDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, { + /** + * @param {!string} tag + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} enrich + * @return {!Promise} + */ IdxDB.prototype.tag = function(tag, limit = 0, offset = 0, enrich = false){ const transaction = this.db.transaction("tag", "readonly"); const map = transaction.objectStore("tag"); @@ -220,6 +249,10 @@ IdxDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, { + /** + * @param {SearchResults} ids + * @return {!Promise} + */ IdxDB.prototype.enrich = function(ids){ if(typeof ids !== "object"){ ids = [ids]; @@ -242,6 +275,10 @@ IdxDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, }; } +/** + * @param {number|string} id + * @return {!Promise} + */ IdxDB.prototype.has = function(id){ const transaction = this.db.transaction("reg", "readonly"); const map = transaction.objectStore("reg"); @@ -507,7 +544,7 @@ IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ /** * @param {IDBCursorWithValue} cursor - * @param {Array} ids + * @param {Array} ids * @param {boolean=} _tag */ @@ -560,6 +597,10 @@ function handle(cursor, ids, _tag){ cursor.continue(); } +/** + * @param {Array} ids + * @return {!Promise} + */ IdxDB.prototype.remove = function(ids){ if(typeof ids !== "object"){ diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 349640e..1253878 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,20 +1,20 @@ /**! - * FlexSearch.js v0.8.103 (Bundle/Debug) + * FlexSearch.js v0.8.105 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ (function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f; -var u; -function z(a, b, c) { - const d = typeof c, e = typeof a; - if ("undefined" !== d) { - if ("undefined" !== e) { +var t; +function A(a, b, c) { + const e = typeof c, d = typeof a; + if ("undefined" !== e) { + if ("undefined" !== d) { if (c) { - if ("function" === e && d === e) { - return function(h) { - return a(c(h)); + if ("function" === d && e === d) { + return function(k) { + return a(c(k)); }; } b = a.constructor; @@ -42,21 +42,18 @@ function z(a, b, c) { } return c; } - return "undefined" === e ? b : a; + return "undefined" === d ? b : a; } function B() { return Object.create(null); } -function aa(a, b) { - return b.length - a.length; -} -function G(a) { +function E(a) { return "string" === typeof a; } -function H(a) { +function I(a) { return "object" === typeof a; } -function ba(a) { +function aa(a) { const b = []; for (const c of a.keys()) { b.push(c); @@ -64,7 +61,7 @@ function ba(a) { return b; } function J(a, b) { - if (G(b)) { + if (E(b)) { a = a[b]; } else { for (let c = 0; a && c < b.length; c++) { @@ -73,14 +70,14 @@ function J(a, b) { } return a; } -function ca(a) { +function ba(a) { let b = 0; - for (let c = 0, d; c < a.length; c++) { - (d = a[c]) && b < d.length && (b = d.length); + for (let c = 0, e; c < a.length; c++) { + (e = a[c]) && b < e.length && (b = e.length); } return b; } -;var da = [["\u00aa", "a"], ["\u00b2", "2"], ["\u00b3", "3"], ["\u00b9", "1"], ["\u00ba", "o"], ["\u00bc", "1\u20444"], ["\u00bd", "1\u20442"], ["\u00be", "3\u20444"], ["\u00e0", "a"], ["\u00e1", "a"], ["\u00e2", "a"], ["\u00e3", "a"], ["\u00e4", "a"], ["\u00e5", "a"], ["\u00e7", "c"], ["\u00e8", "e"], ["\u00e9", "e"], ["\u00ea", "e"], ["\u00eb", "e"], ["\u00ec", "i"], ["\u00ed", "i"], ["\u00ee", "i"], ["\u00ef", "i"], ["\u00f1", "n"], ["\u00f2", "o"], ["\u00f3", "o"], ["\u00f4", "o"], ["\u00f5", +;var ca = [["\u00aa", "a"], ["\u00b2", "2"], ["\u00b3", "3"], ["\u00b9", "1"], ["\u00ba", "o"], ["\u00bc", "1\u20444"], ["\u00bd", "1\u20442"], ["\u00be", "3\u20444"], ["\u00e0", "a"], ["\u00e1", "a"], ["\u00e2", "a"], ["\u00e3", "a"], ["\u00e4", "a"], ["\u00e5", "a"], ["\u00e7", "c"], ["\u00e8", "e"], ["\u00e9", "e"], ["\u00ea", "e"], ["\u00eb", "e"], ["\u00ec", "i"], ["\u00ed", "i"], ["\u00ee", "i"], ["\u00ef", "i"], ["\u00f1", "n"], ["\u00f2", "o"], ["\u00f3", "o"], ["\u00f4", "o"], ["\u00f5", "o"], ["\u00f6", "o"], ["\u00f9", "u"], ["\u00fa", "u"], ["\u00fb", "u"], ["\u00fc", "u"], ["\u00fd", "y"], ["\u00ff", "y"], ["\u0101", "a"], ["\u0103", "a"], ["\u0105", "a"], ["\u0107", "c"], ["\u0109", "c"], ["\u010b", "c"], ["\u010d", "c"], ["\u010f", "d"], ["\u0113", "e"], ["\u0115", "e"], ["\u0117", "e"], ["\u0119", "e"], ["\u011b", "e"], ["\u011d", "g"], ["\u011f", "g"], ["\u0121", "g"], ["\u0123", "g"], ["\u0125", "h"], ["\u0129", "i"], ["\u012b", "i"], ["\u012d", "i"], ["\u012f", "i"], ["\u0133", "ij"], ["\u0135", "j"], ["\u0137", "k"], ["\u013a", "l"], ["\u013c", "l"], ["\u013e", "l"], ["\u0140", "l"], ["\u0144", "n"], ["\u0146", "n"], ["\u0148", "n"], ["\u0149", "n"], ["\u014d", "o"], ["\u014f", "o"], ["\u0151", "o"], ["\u0155", "r"], ["\u0157", "r"], ["\u0159", "r"], ["\u015b", "s"], ["\u015d", "s"], ["\u015f", "s"], ["\u0161", "s"], ["\u0163", "t"], ["\u0165", "t"], ["\u0169", "u"], ["\u016b", "u"], ["\u016d", "u"], ["\u016f", "u"], ["\u0171", "u"], ["\u0173", "u"], ["\u0175", "w"], ["\u0177", "y"], ["\u017a", "z"], ["\u017c", "z"], ["\u017e", "z"], ["\u017f", "s"], ["\u01a1", "o"], ["\u01b0", "u"], ["\u01c6", "dz"], ["\u01c9", "lj"], ["\u01cc", "nj"], ["\u01ce", "a"], ["\u01d0", "i"], ["\u01d2", "o"], ["\u01d4", "u"], ["\u01d6", "u"], ["\u01d8", "u"], ["\u01da", "u"], ["\u01dc", "u"], ["\u01df", "a"], ["\u01e1", "a"], ["\u01e3", "ae"], ["\u00e6", "ae"], ["\u01fd", "ae"], ["\u01e7", "g"], ["\u01e9", "k"], ["\u01eb", "o"], ["\u01ed", "o"], ["\u01ef", "\u0292"], ["\u01f0", "j"], ["\u01f3", @@ -88,63 +85,68 @@ function ca(a) { ["\u02b2", "j"], ["\u02b3", "r"], ["\u02b4", "\u0279"], ["\u02b5", "\u027b"], ["\u02b6", "\u0281"], ["\u02b7", "w"], ["\u02b8", "y"], ["\u02e0", "\u0263"], ["\u02e1", "l"], ["\u02e2", "s"], ["\u02e3", "x"], ["\u02e4", "\u0295"], ["\u0390", "\u03b9"], ["\u03ac", "\u03b1"], ["\u03ad", "\u03b5"], ["\u03ae", "\u03b7"], ["\u03af", "\u03b9"], ["\u03b0", "\u03c5"], ["\u03ca", "\u03b9"], ["\u03cb", "\u03c5"], ["\u03cc", "\u03bf"], ["\u03cd", "\u03c5"], ["\u03ce", "\u03c9"], ["\u03d0", "\u03b2"], ["\u03d1", "\u03b8"], ["\u03d2", "\u03a5"], ["\u03d3", "\u03a5"], ["\u03d4", "\u03a5"], ["\u03d5", "\u03c6"], ["\u03d6", "\u03c0"], ["\u03f0", "\u03ba"], ["\u03f1", "\u03c1"], ["\u03f2", "\u03c2"], ["\u03f5", "\u03b5"], ["\u0439", "\u0438"], ["\u0450", "\u0435"], ["\u0451", "\u0435"], ["\u0453", "\u0433"], ["\u0457", "\u0456"], ["\u045c", "\u043a"], ["\u045d", "\u0438"], ["\u045e", "\u0443"], ["\u0477", "\u0475"], ["\u04c2", "\u0436"], ["\u04d1", "\u0430"], ["\u04d3", "\u0430"], ["\u04d7", "\u0435"], ["\u04db", "\u04d9"], ["\u04dd", "\u0436"], ["\u04df", "\u0437"], ["\u04e3", "\u0438"], ["\u04e5", "\u0438"], ["\u04e7", "\u043e"], ["\u04eb", "\u04e9"], ["\u04ed", "\u044d"], ["\u04ef", "\u0443"], ["\u04f1", "\u0443"], ["\u04f3", "\u0443"], ["\u04f5", "\u0447"]]; -const ea = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = "".normalize && /[\u0300-\u036f]/g; -function K(a) { - if (!this || this.constructor !== K) { - return new K(...arguments); +const da = /[^\p{L}\p{N}]+/u, ea = /(\d{3})/g, fa = /(\D)(\d{3})/g, ha = /(\d{3})(\D)/g, ia = "".normalize && /[\u0300-\u036f]/g; +function L(a) { + if (!this || this.constructor !== L) { + return new L(...arguments); } for (let b = 0; b < arguments.length; b++) { this.assign(arguments[b]); } } -u = K.prototype; -u.assign = function(a) { - this.normalize = z(a.normalize, !0, this.normalize); - let b = a.include, c = b || a.exclude || a.split; - if ("object" === typeof c) { - let d = !b, e = ""; - a.include || (e += "\\p{Z}"); - c.letter && (e += "\\p{L}"); - c.number && (e += "\\p{N}", d = !!b); - c.symbol && (e += "\\p{S}"); - c.punctuation && (e += "\\p{P}"); - c.control && (e += "\\p{C}"); - if (c = c.char) { - e += "object" === typeof c ? c.join("") : c; +t = L.prototype; +t.assign = function(a) { + this.normalize = A(a.normalize, !0, this.normalize); + let b = a.include, c = b || a.exclude || a.split, e; + if (c || "" === c) { + if ("object" === typeof c && c.constructor !== RegExp) { + let d = ""; + e = !b; + b || (d += "\\p{Z}"); + c.letter && (d += "\\p{L}"); + c.number && (d += "\\p{N}", e = !!b); + c.symbol && (d += "\\p{S}"); + c.punctuation && (d += "\\p{P}"); + c.control && (d += "\\p{C}"); + if (c = c.char) { + d += "object" === typeof c ? c.join("") : c; + } + try { + this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); + } catch (f) { + console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; + } + } else { + this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } - try { - this.split = new RegExp("[" + (b ? "^" : "") + e + "]+", "u"); - } catch (f) { - this.split = /\s+/; - } - this.numeric = d; + this.numeric = A(a.numeric, e); } else { try { - this.split = z(c, ea, this.split); + this.split = A(this.split, da); } catch (d) { - this.split = /\s+/; + console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = z(this.numeric, !0); + this.numeric = A(a.numeric, A(this.numeric, !0)); } - this.prepare = z(a.prepare, null, this.prepare); - this.finalize = z(a.finalize, null, this.finalize); - ja || (this.mapper = new Map(da)); - this.rtl = a.rtl || !1; - this.dedupe = z(a.dedupe, !1, this.dedupe); - this.filter = z((c = a.filter) && new Set(c), null, this.filter); - this.matcher = z((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = z((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = z((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = z(a.replacer, null, this.replacer); - this.minlength = z(a.minlength, 1, this.minlength); - this.maxlength = z(a.maxlength, 0, this.maxlength); - if (this.cache = c = z(a.cache, !0, this.cache)) { - this.L = null, this.S = "number" === typeof c ? c : 2e5, this.H = new Map(), this.I = new Map(), this.M = this.B = 128; + this.prepare = A(a.prepare, null, this.prepare); + this.finalize = A(a.finalize, null, this.finalize); + ia || (this.mapper = new Map(ca)); + this.rtl = A(a.rtl, !1, this.rtl); + this.dedupe = A(a.dedupe, !1, this.dedupe); + this.filter = A((c = a.filter) && new Set(c), null, this.filter); + this.matcher = A((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = A((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = A((c = a.stemmer) && new Map(c), null, this.stemmer); + this.replacer = A(a.replacer, null, this.replacer); + this.minlength = A(a.minlength, 1, this.minlength); + this.maxlength = A(a.maxlength, 0, this.maxlength); + if (this.cache = c = A(a.cache, !0, this.cache)) { + this.H = null, this.S = "number" === typeof c ? c : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; - this.N = null; + this.M = null; this.A = ""; - this.O = null; + this.N = null; if (this.matcher) { for (const d of this.matcher.keys()) { this.h += (this.h ? "|" : "") + d; @@ -157,35 +159,21 @@ u.assign = function(a) { } return this; }; -u.addMatcher = function(a, b) { - if ("object" === typeof a) { - return this.addReplacer(a, b); - } - if (2 > a.length) { - 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 && L(this); - return this; -}; -u.addStemmer = function(a, b) { +t.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 && L(this); + this.N = null; + this.cache && M(this); return this; }; -u.addFilter = function(a) { +t.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); - this.cache && L(this); + this.cache && M(this); return this; }; -u.addMapper = function(a, b) { +t.addMapper = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -194,411 +182,416 @@ u.addMapper = function(a, b) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, b); - this.cache && L(this); + this.cache && M(this); return this; }; -u.addReplacer = function(a, b) { - "string" === typeof a && (a = new RegExp(a, "g")); +t.addMatcher = function(a, b) { + if ("object" === typeof a) { + return this.addReplacer(a, b); + } + if (2 > a.length && (this.dedupe || this.mapper)) { + return this.addMapper(a, b); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(a, b); + this.h += (this.h ? "|" : "") + a; + this.M = null; + this.cache && M(this); + return this; +}; +t.addReplacer = function(a, b) { + if ("string" === typeof a) { + return this.addMatcher(a, b); + } this.replacer || (this.replacer = []); - this.replacer.push(a, b || ""); - this.cache && L(this); + this.replacer.push(a, b); + this.cache && M(this); return this; }; -function L(a) { - a.H.clear(); - a.I.clear(); -} -u.encode = function(a) { - if (this.cache && a.length <= this.B) { - if (this.L) { - if (this.H.has(a)) { - return this.H.get(a); +t.encode = function(a) { + if (this.cache && a.length <= this.K) { + if (this.H) { + if (this.B.has(a)) { + return this.B.get(a); } } else { - this.L = setTimeout(ka, 50, this); + this.H = setTimeout(M, 50, this); } } - this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ia ? a.normalize("NFKD").replace(ia, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(fa, "$1 $2").replace(ha, "$1 $2").replace(ea, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let c = [], d = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, h; f < d.length; f++) { - if (!(g = h = d[f])) { - continue; - } - if (g.length < this.minlength) { - continue; - } - if (b) { - c.push(g); - continue; - } - if (this.filter && this.filter.has(g)) { - continue; - } - if (this.cache && g.length <= this.M) { - if (this.L) { - var e = this.I.get(g); - if (e || "" === e) { - e && c.push(e); - continue; - } + let c = [], e = this.split || "" === this.split ? a.split(this.split) : a; + for (let f = 0, g, k; f < e.length; f++) { + if ((g = k = e[f]) && !(g.length < this.minlength)) { + if (b) { + c.push(g); } else { - this.L = setTimeout(ka, 50, this); + if (!this.filter || !this.filter.has(g)) { + if (this.cache && g.length <= this.L) { + if (this.H) { + var d = this.G.get(g); + if (d || "" === d) { + d && c.push(d); + continue; + } + } else { + this.H = setTimeout(M, 50, this); + } + } + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + if (g && (this.mapper || this.dedupe && 1 < g.length)) { + d = ""; + for (let h = 0, l = "", m, n; h < g.length; h++) { + m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + } + g = d; + } + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); + if (g && this.replacer) { + for (d = 0; g && d < this.replacer.length; d += 2) { + g = g.replace(this.replacer[d], this.replacer[d + 1]); + } + } + this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); + g && c.push(g); + } } } - let k; - this.stemmer && 2 < g.length && (this.O || (this.O = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.O, l => this.stemmer.get(l)), k = 1); - g && k && (g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); - if (g && (this.mapper || this.dedupe && 1 < g.length)) { - e = ""; - for (let l = 0, m = "", q, n; l < g.length; l++) { - q = g.charAt(l), q === m && this.dedupe || ((n = this.mapper && this.mapper.get(q)) || "" === n ? n === m && this.dedupe || !(m = n) || (e += n) : e += m = q); - } - g = e; - } - this.matcher && 1 < g.length && (this.N || (this.N = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.N, l => this.matcher.get(l))); - if (g && this.replacer) { - for (e = 0; g && e < this.replacer.length; e += 2) { - g = g.replace(this.replacer[e], this.replacer[e + 1]); - } - } - this.cache && h.length <= this.M && (this.I.set(h, g), this.I.size > this.S && (this.I.clear(), this.M = this.M / 1.1 | 0)); - g && c.push(g); } this.finalize && (c = this.finalize(c) || c); - this.cache && a.length <= this.B && (this.H.set(a, c), this.H.size > this.S && (this.H.clear(), this.B = this.B / 1.1 | 0)); + this.cache && a.length <= this.K && (this.B.set(a, c), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); return c; }; -function ka(a) { - a.L = null; - a.H.clear(); - a.I.clear(); +function M(a) { + a.H = null; + a.B.clear(); + a.G.clear(); } -;async function la(a) { +;async function ja(a) { a = a.data; var b = self._index; const c = a.args; - var d = a.task; - switch(d) { + var e = a.task; + switch(e) { case "init": - d = a.options || {}; - (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(d), delete self.FlexSearch) : self._index = new M(d); + e = a.options || {}; + (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new N(e); postMessage({id:a.id}); break; default: - a = a.id, b = b[d].apply(b, c), postMessage("search" === d ? {id:a, msg:b} : {id:a}); + a = a.id, b = b[e].apply(b, c), postMessage("search" === e ? {id:a, msg:b} : {id:a}); } } -;let ma = 0; -function N(a = {}) { +;let ka = 0; +function O(a = {}) { function b(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && e.h[l]; - m && (m(k.msg), delete e.h[l]); + function k(h) { + h = h.data || h; + const l = h.id, m = l && d.h[l]; + m && (m(h.msg), delete d.h[l]); } this.worker = g; this.h = B(); if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { - e.h[++ma] = function() { - k(e); + return new Promise(function(h) { + d.h[++ka] = function() { + h(d); }; - e.worker.postMessage({id:ma, task:"init", factory:c, options:a}); + d.worker.postMessage({id:ka, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); return this; } } - if (!this || this.constructor !== N) { - return new N(a); + if (!this || this.constructor !== O) { + return new O(a); } let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - const d = "undefined" === typeof window, e = this, f = na(c, d, a.worker); + const e = "undefined" === typeof window, d = this, f = la(c, e, a.worker); return f.then ? f.then(function(g) { - return b.call(e, g); + return b.call(d, g); }) : b.call(this, f); } -O("add"); -O("append"); -O("search"); -O("update"); -O("remove"); -function O(a) { - N.prototype[a] = N.prototype[a + "Async"] = async function() { +P("add"); +P("append"); +P("search"); +P("update"); +P("remove"); +function P(a) { + O.prototype[a] = O.prototype[a + "Async"] = async function() { const b = this, c = [].slice.call(arguments); - var d = c[c.length - 1]; - let e; - "function" === typeof d && (e = d, c.splice(c.length - 1, 1)); - d = new Promise(function(f) { - b.h[++ma] = f; - b.worker.postMessage({task:a, id:ma, args:c}); + var e = c[c.length - 1]; + let d; + "function" === typeof e && (d = e, c.splice(c.length - 1, 1)); + e = new Promise(function(f) { + b.h[++ka] = f; + b.worker.postMessage({task:a, id:ka, args:c}); }); - return e ? (d.then(e), this) : d; + return d ? (e.then(d), this) : e; }; } -function na(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=" + la.toString()], {type:"text/javascript"}))) : new window.Worker(G(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function la(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=" + ja.toString()], {type:"text/javascript"}))) : new window.Worker(E(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"}); } -;function oa(a) { - P.call(a, "add"); - P.call(a, "append"); - P.call(a, "search"); - P.call(a, "update"); - P.call(a, "remove"); +;function ma(a) { + Q.call(a, "add"); + Q.call(a, "append"); + Q.call(a, "search"); + Q.call(a, "update"); + Q.call(a, "remove"); } -function P(a) { +function Q(a) { this[a + "Async"] = function() { var b = arguments; const c = b[b.length - 1]; - let d; - "function" === typeof c && (d = c, delete b[b.length - 1]); + let e; + "function" === typeof c && (e = c, delete b[b.length - 1]); b = this[a].apply(this, b); - d && (b.then ? b.then(d) : d(b)); + e && (b.then ? b.then(e) : e(b)); return b; }; } -;function pa(a, b = 0) { - let c = [], d = []; +;function na(a, b = 0) { + let c = [], e = []; b && (b = 250000 / b * 5000 | 0); - for (const e of a.entries()) { - d.push(e), d.length === b && (c.push(d), d = []); + for (const d of a.entries()) { + e.push(d), e.length === b && (c.push(e), e = []); } - d.length && c.push(d); + e.length && c.push(e); + return c; +} +function oa(a, b) { + b || (b = new Map()); + for (let c = 0, e; c < a.length; c++) { + e = a[c], b.set(e[0], e[1]); + } + return b; +} +function pa(a, b = 0) { + let c = [], e = []; + b && (b = 250000 / b * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], na(d[1])[0]]), e.length === b && (c.push(e), e = []); + } + e.length && c.push(e); return c; } function qa(a, b) { b || (b = new Map()); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b.set(d[0], d[1]); + for (let c = 0, e, d; c < a.length; c++) { + e = a[c], d = b.get(e[0]), b.set(e[0], oa(e[1], d)); } return b; } -function ra(a, b = 0) { - let c = [], d = []; - b && (b = 250000 / b * 1000 | 0); - for (const e of a.entries()) { - d.push([e[0], pa(e[1])[0]]), d.length === b && (c.push(d), d = []); - } - d.length && c.push(d); - return c; -} -function sa(a, b) { - b || (b = new Map()); - for (let c = 0, d, e; c < a.length; c++) { - d = a[c], e = b.get(d[0]), b.set(d[0], qa(d[1], e)); - } - return b; -} -function ta(a) { +function ra(a) { let b = [], c = []; - for (const d of a.keys()) { - c.push(d), 250000 === c.length && (b.push(c), c = []); + for (const e of a.keys()) { + c.push(e), 250000 === c.length && (b.push(c), c = []); } c.length && b.push(c); return b; } -function ua(a, b) { +function sa(a, b) { b || (b = new Set()); for (let c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function va(a, b, c, d, e, f, g = 0) { - const h = d && d.constructor === Array; - var k = h ? d.shift() : d; - if (!k) { - return this.export(a, b, e, f + 1); +function ta(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((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return va.call(l, a, b, c, h ? d : null, e, f, g + 1); + return h.then(function() { + return ta.call(l, a, b, c, k ? e : null, d, f, g + 1); }); } - return va.call(this, a, b, c, h ? d : null, e, f, g + 1); + return ta.call(this, a, b, c, k ? e : null, d, f, g + 1); } -;function wa(a, b, c, d) { - let e = []; +;function ua(a, b, c, e) { + let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { b -= g.length; } else { - b = g[d ? "splice" : "slice"](b, c); - const h = b.length; - if (h && (e = e.length ? e.concat(b) : b, c -= h, d && (a.length -= h), !c)) { + b = g[e ? "splice" : "slice"](b, c); + const k = b.length; + if (k && (d = d.length ? d.concat(b) : b, c -= k, e && (a.length -= k), !c)) { break; } b = 0; } } - return e; + return d; } -function Q(a) { +function R(a) { if (!this) { - return new Q(a); + return new R(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; const b = this; - return new Proxy([], {get(c, d) { - if ("length" === d) { + return new Proxy([], {get(c, e) { + if ("length" === e) { return b.length; } - if ("push" === d) { - return function(e) { - b.index[b.index.length - 1].push(e); + if ("push" === e) { + return function(d) { + b.index[b.index.length - 1].push(d); b.length++; }; } - if ("pop" === d) { + if ("pop" === e) { return function() { if (b.length) { return b.length--, b.index[b.index.length - 1].pop(); } }; } - if ("indexOf" === d) { - return function(e) { + if ("indexOf" === e) { + return function(d) { let f = 0; - for (let g = 0, h, k; g < b.index.length; g++) { - h = b.index[g]; - k = h.indexOf(e); - 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" === d) { - return function(e) { + if ("includes" === e) { + return function(d) { for (let f = 0; f < b.index.length; f++) { - if (b.index[f].includes(e)) { + if (b.index[f].includes(d)) { return !0; } } return !1; }; } - if ("slice" === d) { - return function(e, f) { - return wa(b, e || 0, f || b.length, !1); + if ("slice" === e) { + return function(d, f) { + return ua(b, d || 0, f || b.length, !1); }; } - if ("splice" === d) { - return function(e, f) { - return wa(b, e || 0, f || b.length, !0); + if ("splice" === e) { + return function(d, f) { + return ua(b, d || 0, f || b.length, !0); }; } - if ("constructor" === d) { + if ("constructor" === e) { return Array; } - if ("symbol" !== typeof d) { - return (c = b.index[d / 2 ** 31 | 0]) && c[d]; + if ("symbol" !== typeof e) { + return (c = b.index[e / 2 ** 31 | 0]) && c[e]; } - }, set(c, d, e) { - c = d / 2 ** 31 | 0; - (b.index[c] || (b.index[c] = []))[d] = e; + }, set(c, e, d) { + c = e / 2 ** 31 | 0; + (b.index[c] || (b.index[c] = []))[e] = d; b.length++; return !0; }}); } -Q.prototype.clear = function() { +R.prototype.clear = function() { this.index.length = 0; }; -Q.prototype.destroy = function() { +R.prototype.destroy = function() { this.proxy = this.index = null; }; -Q.prototype.push = function() { -}; -function R(a = 8) { - if (!this) { - return new R(a); - } - this.index = B(); - this.B = []; - this.size = 0; - 32 < a ? (this.h = xa, this.A = BigInt(a)) : (this.h = ya, this.A = a); -} -R.prototype.get = function(a) { - const b = this.index[this.h(a)]; - return b && b.get(a); -}; -R.prototype.set = function(a, b) { - var c = this.h(a); - let d = this.index[c]; - d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.B.push(d)); +R.prototype.push = function() { }; function S(a = 8) { if (!this) { return new S(a); } this.index = B(); - this.h = []; - 32 < a ? (this.B = xa, this.A = BigInt(a)) : (this.B = ya, this.A = a); + this.B = []; + this.size = 0; + 32 < a ? (this.h = va, this.A = BigInt(a)) : (this.h = wa, this.A = a); } -S.prototype.add = function(a) { +S.prototype.get = function(a) { + const b = this.index[this.h(a)]; + return b && b.get(a); +}; +S.prototype.set = function(a, b) { + var c = this.h(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.B.push(e)); +}; +function T(a = 8) { + if (!this) { + return new T(a); + } + this.index = B(); + this.h = []; + 32 < a ? (this.B = va, this.A = BigInt(a)) : (this.B = wa, this.A = a); +} +T.prototype.add = function(a) { var b = this.B(a); let c = this.index[b]; c ? (b = c.size, c.add(a), (b -= c.size) && this.size++) : (this.index[b] = c = new Set([a]), this.h.push(c)); }; -u = R.prototype; -u.has = S.prototype.has = function(a) { +t = S.prototype; +t.has = T.prototype.has = function(a) { const b = this.index[this.B(a)]; return b && b.has(a); }; -u.delete = S.prototype.delete = function(a) { +t.delete = T.prototype.delete = function(a) { const b = this.index[this.B(a)]; b && b.delete(a) && this.size--; }; -u.clear = S.prototype.clear = function() { +t.clear = T.prototype.clear = function() { this.index = B(); this.h = []; this.size = 0; }; -u.values = S.prototype.values = function*() { +t.values = T.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].values()) { yield b; } } }; -u.keys = S.prototype.keys = function*() { +t.keys = T.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].keys()) { yield b; } } }; -u.entries = S.prototype.entries = function*() { +t.entries = T.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].entries()) { yield b; } } }; -function ya(a) { +function wa(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; } - let c = 0, d = this.A + 1; - for (let e = 0; e < a.length; e++) { - c = (c * d ^ a.charCodeAt(e)) & b; + let c = 0, e = this.A + 1; + for (let d = 0; d < a.length; d++) { + c = (c * e ^ a.charCodeAt(d)) & b; } return 32 === this.A ? c + 2 ** 31 : c; } -function xa(a) { +function va(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -608,76 +601,76 @@ function xa(a) { return BigInt(a) & b; } c = BigInt(0); - let d = this.A + BigInt(1); - for (let e = 0; e < a.length; e++) { - c = (c * d ^ BigInt(a.charCodeAt(e))) & b; + let e = this.A + BigInt(1); + for (let d = 0; d < a.length; d++) { + c = (c * e ^ BigInt(a.charCodeAt(d))) & b; } return c; } -;T.prototype.add = function(a, b, c) { - H(a) && (b = a, a = J(b, this.key)); +;U.prototype.add = function(a, b, c) { + I(a) && (b = a, a = J(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.D[h]; - var d = this.index.get(this.field[h]); - if ("function" === typeof k) { - var e = k(b); - e && d.add(a, e, !1, !0); + for (let k = 0, h; k < this.field.length; k++) { + h = this.D[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 (e = k.J, !e || e(b)) { - k.constructor === String ? k = ["" + k] : G(k) && (k = [k]), za(b, k, this.K, 0, d, a, k[0], c); + if (d = h.I, !d || d(b)) { + h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), xa(b, h, this.J, 0, e, a, h[0], c); } } } if (this.tag) { - for (d = 0; d < this.G.length; d++) { - var f = this.G[d], g = this.P[d]; - e = this.tag.get(g); - let h = B(); + for (e = 0; e < this.F.length; e++) { + var f = this.F[e], g = this.R[e]; + d = this.tag.get(g); + let k = B(); if ("function" === typeof f) { if (f = f(b), !f) { continue; } } else { - const k = f.J; - if (k && !k(b)) { + const h = f.I; + if (h && !h(b)) { continue; } f.constructor === String && (f = "" + f); f = J(b, f); } - if (e && f) { - G(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - if (l = f[k], !h[l] && (h[l] = 1, (g = e.get(l)) ? m = g : e.set(l, m = []), !c || !m.includes(a))) { + if (d && f) { + E(f) && (f = [f]); + for (let h = 0, l, m; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !c || !m.includes(a))) { if (m.length === 2 ** 31 - 1) { - g = new Q(m); + g = new R(m); if (this.fastupdate) { - for (let q of this.reg.values()) { - q.includes(m) && (q[q.indexOf(m)] = g); + for (let n of this.reg.values()) { + n.includes(m) && (n[n.indexOf(m)] = g); } } - e.set(l, m = g); + d.set(l, m = g); } m.push(a); this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); } } } else { - e || console.warn("Tag '" + g + "' was not found"); + d || console.warn("Tag '" + g + "' was not found"); } } } if (this.store && (!c || !this.store.has(a))) { - let h; + let k; if (this.C) { - h = B(); - for (let k = 0, l; k < this.C.length; k++) { - l = this.C[k]; - if ((c = l.J) && !c(b)) { + k = B(); + for (let h = 0, l; h < this.C.length; h++) { + l = this.C[h]; + if ((c = l.I) && !c(b)) { continue; } let m; @@ -686,140 +679,142 @@ function xa(a) { if (!m) { continue; } - l = [l.U]; - } else if (G(l) || l.constructor === String) { - h[l] = b[l]; + l = [l.V]; + } else if (E(l) || l.constructor === String) { + k[l] = b[l]; continue; } - Aa(b, h, l, 0, l[0], m); + ya(b, k, l, 0, l[0], m); } } - this.store.set(a, h || b); + this.store.set(a, k || b); } } return this; }; -function Aa(a, b, c, d, e, f) { - a = a[e]; - if (d === c.length - 1) { - b[e] = f || a; +function ya(a, b, c, e, d, f) { + a = a[d]; + if (e === c.length - 1) { + b[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - Aa(a, b, c, d, e); + for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { + ya(a, b, c, e, d); } } else { - b = b[e] || (b[e] = B()), e = c[++d], Aa(a, b, c, d, e); + b = b[d] || (b[d] = B()), d = c[++e], ya(a, b, c, e, d); } } } -function za(a, b, c, d, e, f, g, h) { +function xa(a, b, c, e, d, f, g, k) { if (a = a[g]) { - if (d === b.length - 1) { + if (e === b.length - 1) { if (a.constructor === Array) { - if (c[d]) { + if (c[e]) { for (b = 0; b < a.length; b++) { - e.add(f, a[b], !0, !0); + d.add(f, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - za(a, b, c, d, e, f, g, h); + xa(a, b, c, e, d, f, g, k); } } else { - g = b[++d], za(a, b, c, d, e, f, g, h); + g = b[++e], xa(a, b, c, e, d, f, g, k); } } } else { - e.db && e.remove(f); + d.db && d.remove(f); } } -;function Ba(a, b, c, d, e, f, g) { - const h = a.length; - let k = [], l; +;function za(a, b, c, e, d, f, g) { + const k = a.length; + let h = [], l; var m; l = B(); - for (let q = 0, n, p, r, t; q < b; q++) { - for (let v = 0; v < h; v++) { - if (r = a[v], q < r.length && (n = r[q])) { - for (let x = 0; x < n.length; x++) { - p = n[x], (m = l[p]) ? l[p]++ : (m = 0, l[p] = 1), t = k[m] || (k[m] = []), g || (m = q + (v ? 0 : f || 0), t = t[m] || (t[m] = [])), t.push(p); + for (let n = 0, p, q, r, u; n < b; n++) { + for (let v = 0; v < k; v++) { + if (r = a[v], n < r.length && (p = r[n])) { + for (let x = 0; x < p.length; x++) { + q = p[x], (m = l[q]) ? l[q]++ : (m = 0, l[q] = 1), u = h[m] || (h[m] = []), g || (m = n + (v || !d ? 0 : f || 0), u = u[m] || (u[m] = [])), u.push(q); } } } } - if (a = k.length) { - if (e) { - k = 1 < k.length ? Ca(k, d, c, g, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + if (a = h.length) { + if (d) { + h = 1 < h.length ? Aa(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; - if (c || d) { + h = h[a - 1]; + if (c || e) { if (g) { - if (k.length > c || d) { - k = k.slice(d, c + d); + if (h.length > c || e) { + h = h.slice(e, c + e); } } else { - e = []; - for (let q = 0, n; q < k.length; q++) { - if (n = k[q], n.length > d) { - d -= n.length; + d = []; + for (let n = 0, p; n < h.length; n++) { + if (p = h[n], p.length > e) { + e -= p.length; } else { - if (n.length > c || d) { - n = n.slice(d, c + d), c -= n.length, d && (d -= n.length); + if (p.length > c || e) { + p = p.slice(e, c + e), c -= p.length, e && (e -= p.length); } - e.push(n); + d.push(p); if (!c) { break; } } } - k = 1 < e.length ? [].concat.apply([], e) : e[0]; + h = 1 < d.length ? [].concat.apply([], d) : d[0]; } } } } - return k; + return h; } -function Ca(a, b, c, d, e) { +function Aa(a, b, c, e, d) { const f = [], g = B(); - let h; - var k = a.length; - let l, m = 0; - if (d) { - for (e = k - 1; 0 <= e; e--) { - for (d = a[e], l = d.length, k = 0; k < l; k++) { - if (h = d[k], !g[h]) { - if (g[h] = 1, b) { - b--; - } else { - if (f.push(h), f.length === c) { - return f; + let k; + var h = a.length; + let l; + if (e) { + for (d = h - 1; 0 <= d; d--) { + if (l = (e = a[d]) && e.length) { + for (h = 0; h < l; h++) { + if (k = e[h], !g[k]) { + if (g[k] = 1, c) { + c--; + } else { + if (f.push(k), f.length === b) { + return f; + } } } } } } } else { - let q = ca(a); - for (let n = 0; n < q; n++) { - for (let p = k - 1; 0 <= p; p--) { - if (l = (d = a[p][n]) && d.length) { + for (let m = h - 1, n, p = 0; 0 <= m; m--) { + n = a[m]; + for (let q = 0; q < n.length; q++) { + if (l = (e = n[q]) && e.length) { for (let r = 0; r < l; r++) { - if (h = d[r], !g[h]) { - if (g[h] = 1, b) { - b--; + if (k = e[r], !g[k]) { + if (g[k] = 1, c) { + c--; } else { - let t = n + (p < k - 1 ? e || 0 : 0); - (f[t] || (f[t] = [])).push(h); - if (++m === c) { + let u = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[u] || (f[u] = [])).push(k); + if (++p === b) { return f; } } @@ -831,443 +826,764 @@ function Ca(a, b, c, d, e) { } return f; } -function Da(a, b) { - const c = B(), d = []; - for (let e = 0, f; e < b.length; e++) { - f = b[e]; - for (let g = 0; g < f.length; g++) { - c[f[g]] = 1; +function Ba(a, b, c) { + const e = B(), d = []; + for (let f = 0, g; f < b.length; f++) { + g = b[f]; + for (let k = 0; k < g.length; k++) { + e[g[k]] = 1; } } - for (let e = 0, f; e < a.length; e++) { - f = a[e], 1 === c[f] && (d.push(f), c[f] = 2); + 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, 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; } -;T.prototype.search = function(a, b, c, d) { - c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); - let e = [], f = [], g; - let h; +;function Ca(a, b, c, e) { + if (!a.length) { + return a; + } + if (1 === a.length) { + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, e ? V.call(this, a) : a; + } + let d = []; + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { + if (c) { + if (c >= k) { + c -= k; + continue; + } + c < k && (g = b ? g.slice(c, c + b) : g.slice(c), k = g.length, c = 0); + } + k > b && (g = g.slice(0, b), k = b); + if (!d.length && k >= b) { + return e ? V.call(this, g) : g; + } + d.push(g); + b -= k; + if (!b) { + break; + } + } + } + d = 1 < d.length ? [].concat.apply([], d) : d[0]; + return e ? V.call(this, d) : d; +} +;function Da(a, b, c) { + var e = c[0]; + if (e.then) { + return Promise.all(c).then(function(m) { + return a[b].apply(a, m); + }); + } + if (e[0] && e[0].index) { + return a[b].apply(a, e); + } + e = []; + let d = [], f = 0, g = 0, k, h, l; + for (let m = 0, n; m < c.length; m++) { + if (n = c[m]) { + let p; + if (n.constructor === W) { + p = n.result; + } else if (n.constructor === Array) { + p = n; + } else { + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { + n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = h, n.enrich = k; + } else if (n.and) { + p = a.and(n.and); + } else if (n.or) { + p = a.or(n.or); + } else if (n.xor) { + p = a.xor(n.xor); + } else if (n.not) { + p = a.not(n.not); + } else { + continue; + } + } + if (p.then) { + d.push(p); + } else if (p.length) { + e[m] = p; + } else if (!l && ("and" === b || "xor" === b)) { + e = []; + break; + } + } + } + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; +} +;W.prototype.or = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Da(this, "or", arguments); + return Ea.call(this, a, b, c, e, d, f); +}; +function Ea(a, b, c, e, d, f) { + if (b.length) { + const g = this; + return Promise.all(b).then(function(k) { + a = []; + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); + } + return Ea.call(g, a, [], c, e, d, f); + }); + } + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Aa(a, c, e, !1, this.h), e = 0)); + return f ? this.resolve(c, e, d) : this; +} +;W.prototype.and = function() { + let a = this.result.length, b, c, e, d; + if (!a) { + const f = arguments[0]; + f && (a = !!f.suggest, d = f.resolve, b = f.limit, c = f.offset, e = f.enrich && d); + } + if (a) { + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Da(this, "and", arguments); + return Fa.call(this, f, g, k, h, l, m, n); + } + return d ? this.resolve(b, c, e) : this; +}; +function Fa(a, b, c, e, d, f, g) { + if (b.length) { + const k = this; + return Promise.all(b).then(function(h) { + a = []; + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Fa.call(k, a, [], c, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + if (b = ba(a)) { + return this.result = za(a, b, c, e, g, this.h, f), f ? d ? V.call(this.index, this.result) : this.result : this; + } + this.result = []; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(c, e, d) : this; +} +;W.prototype.xor = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Da(this, "xor", arguments); + return Ga.call(this, a, b, c, e, d, f, g); +}; +function Ga(a, b, c, e, d, f, g) { + if (b.length) { + const k = this; + return Promise.all(b).then(function(h) { + a = []; + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Ga.call(k, a, [], c, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = Ha.call(this, a, c, e, f, this.h), f ? d ? V.call(this.index, this.result) : this.result : this; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(c, e, d) : this; +} +function Ha(a, b, c, e, d) { + const f = [], g = B(); + let k = 0; + for (let h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); + for (let m = 0, n; m < l.length; m++) { + if (n = l[m]) { + for (let p = 0, q; p < n.length; p++) { + q = n[p], g[q] = g[q] ? 2 : 1; + } + } + } + } + } + for (let h = 0, l, m = 0; h < k; h++) { + for (let n = 0, p; n < a.length; n++) { + if (p = a[n]) { + if (l = p[h]) { + for (let q = 0, r; q < l.length; q++) { + if (r = l[q], 1 === g[r]) { + if (c) { + c--; + } else { + if (e) { + if (f.push(r), f.length === b) { + return f; + } + } else { + const u = h + (n ? d : 0); + f[u] || (f[u] = []); + f[u].push(r); + if (++m === b) { + return f; + } + } + } + } + } + } + } + } + } + return f; +} +;W.prototype.not = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Da(this, "not", arguments); + return Ia.call(this, a, b, c, e, d, f, g); +}; +function Ia(a, b, c, e, d, f, g) { + if (b.length) { + const k = this; + return Promise.all(b).then(function(h) { + a = []; + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Ia.call(k, a, [], c, e, d, f, g); + }); + } + if (a.length && this.result.length) { + this.result = Ja.call(this, a, c, e, f); + } else if (f) { + return this.resolve(c, e, d); + } + return f ? d ? V.call(this.index, this.result) : this.result : this; +} +function Ja(a, b, c, e) { + const d = []; + a = new Set(a.flat().flat()); + for (let f = 0, g, k = 0; f < this.result.length; f++) { + if (g = this.result[f]) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { + if (c) { + c--; + } else { + if (e) { + if (d.push(l), d.length === b) { + return d; + } + } else { + if (d[f] || (d[f] = []), d[f].push(l), ++k === b) { + return d; + } + } + } + } + } + } + } + return d; +} +;function W(a) { + if (!this || this.constructor !== W) { + return new W(a); + } + if (a && a.index) { + return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; + } + this.index = null; + this.result = a || []; + this.h = 0; +} +W.prototype.limit = function(a) { + if (this.result.length) { + const b = []; + let c = 0; + for (let e = 0, d; e < this.result.length; e++) { + if (d = this.result[e], d.length + c < a) { + b[e] = d, c += d.length; + } else { + b[e] = d.slice(0, a - c); + this.result = b; + break; + } + } + } + return this; +}; +W.prototype.offset = function(a) { + if (this.result.length) { + const b = []; + let c = 0; + for (let e = 0, d; e < this.result.length; e++) { + d = this.result[e], d.length + c < a ? c += d.length : (b[e] = d.slice(a - c), c = a); + } + this.result = b; + } + return this; +}; +W.prototype.boost = function(a) { + this.h += a; + return this; +}; +W.prototype.resolve = function(a, b, c) { + const e = this.result, d = this.index; + this.result = this.index = null; + return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ca.call(d, e, a || 100, b, c)) : e; +}; +B(); +U.prototype.search = function(a, b, c, e) { + c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); + let d = [], f = [], g; let k; - let l, m = 0, q; + let h; + let l, m = 0; + let n; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; g = c.pluck; - h = c.merge; - k = g || c.field || c.index; - var n = this.tag && c.tag; - var p = this.store && c.enrich; - var r = c.suggest; - q = c.highlight; + k = c.merge; + h = g || c.field || (h = c.index) && (h.index ? null : h); + var p = this.tag && c.tag; + var q = c.suggest; + var r = !1 !== c.resolve; + if (!r && !g) { + if (h = h || this.field) { + E(h) ? g = h : (h.constructor === Array && 1 === h.length && (h = h[0]), g = h.field || h.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."); + } + } + this.store && c.enrich && !r && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var u = this.store && c.enrich && r; + n = c.highlight && u; b = c.limit || b; l = c.offset || 0; b || (b = 100); - if (n && (!this.db || !d)) { - n.constructor !== Array && (n = [n]); - var t = []; - for (let y = 0, w; y < n.length; y++) { - w = n[y]; - if (G(w)) { + if (p && (!this.db || !e)) { + p.constructor !== Array && (p = [p]); + var v = []; + for (let z = 0, w; z < p.length; z++) { + w = p[z]; + if (E(w)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (w.field && w.tag) { - var v = w.tag; - if (v.constructor === Array) { - for (var x = 0; x < v.length; x++) { - t.push(w.field, v[x]); + var x = w.tag; + if (x.constructor === Array) { + for (var y = 0; y < x.length; y++) { + v.push(w.field, x[y]); } } else { - t.push(w.field, v); + v.push(w.field, x); } } else { - v = Object.keys(w); - for (let A = 0, I, C; A < v.length; A++) { - if (I = v[A], C = w[I], C.constructor === Array) { - for (x = 0; x < C.length; x++) { - t.push(I, C[x]); + x = Object.keys(w); + for (let D = 0, H, C; D < x.length; D++) { + if (H = x[D], C = w[H], C.constructor === Array) { + for (y = 0; y < C.length; y++) { + v.push(H, C[y]); } } else { - t.push(I, C); + v.push(H, C); } } } } - if (!t.length) { + if (!v.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - n = t; + p = v; if (!a) { - r = []; - if (t.length) { - for (n = 0; n < t.length; n += 2) { + q = []; + if (v.length) { + for (p = 0; p < v.length; p += 2) { if (this.db) { - d = this.index.get(t[n]); - if (!d) { - console.warn("Tag '" + t[n] + ":" + t[n + 1] + "' will be skipped because there is no field '" + t[n] + "'."); + r = this.index.get(v[p]); + if (!r) { + console.warn("Tag '" + v[p] + ":" + v[p + 1] + "' will be skipped because there is no field '" + v[p] + "'."); continue; } - r.push(d = d.db.tag(t[n + 1], b, l, p)); + q.push(r = r.db.tag(v[p + 1], b, l, u)); } else { - d = Ea.call(this, t[n], t[n + 1], b, l, p); + r = Ka.call(this, v[p], v[p + 1], b, l, u); } - e.push({field:t[n], tag:t[n + 1], result:d}); + d.push({field:v[p], tag:v[p + 1], result:r}); } } - return r.length ? Promise.all(r).then(function(y) { - for (let w = 0; w < y.length; w++) { - e[w].result = y[w]; + return q.length ? Promise.all(q).then(function(z) { + for (let w = 0; w < z.length; w++) { + d[w].result = z[w]; } - return e; - }) : e; + return d; + }) : d; } } - G(k) && (k = [k]); + h && h.constructor !== Array && (h = [h]); } - k || (k = this.field); - t = !d && (this.worker || this.db) && []; - let E; - for (let y = 0, w, A, I; y < k.length; y++) { - A = k[y]; - if (this.db && this.tag && !this.D[y]) { + h || (h = this.field); + v = !e && (this.worker || this.db) && []; + let F; + for (let z = 0, w, D, H; z < h.length; z++) { + D = h[z]; + if (this.db && this.tag && !this.D[z]) { continue; } let C; - G(A) || (C = A, A = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, r = C.suggest || r, p = this.store && (C.enrich || p)); - if (d) { - w = d[y]; + E(D) || (C = D, D = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, q = C.suggest || q, u = this.store && (C.enrich || u)); + if (e) { + w = e[z]; } else { - if (v = C || c, x = this.index.get(A), n && (this.db && (v.tag = n, E = x.db.support_tag_search, v.field = k), E || (v.enrich = !1)), t) { - t[y] = x.search(a, b, v); - v && p && (v.enrich = p); + if (x = C || c, y = this.index.get(D), p && (this.db && (x.tag = p, F = y.db.support_tag_search, x.field = h), F || (x.enrich = !1)), v) { + v[z] = y.search(a, b, x); + x && u && (x.enrich = u); continue; } else { - w = x.search(a, b, v), v && p && (v.enrich = p); + w = y.search(a, b, x), x && u && (x.enrich = u); } } - I = w && w.length; - if (n && I) { - v = []; - x = 0; - if (this.db && d) { - if (!E) { - for (let D = k.length; D < d.length; D++) { - let F = d[D]; - if (F && F.length) { - x++, v.push(F); - } else if (!r) { - return e; + H = w && (r ? w.length : w.result.length); + if (p && H) { + x = []; + y = 0; + if (this.db && e) { + if (!F) { + for (let G = h.length; G < e.length; G++) { + let K = e[G]; + if (K && K.length) { + y++, x.push(K); + } else if (!q) { + return r ? d : new W(d); } } } } else { - for (let D = 0, F, jb; D < n.length; D += 2) { - F = this.tag.get(n[D]); - if (!F) { - if (console.warn("Tag '" + n[D] + ":" + n[D + 1] + "' will be skipped because there is no field '" + n[D] + "'."), r) { + for (let G = 0, K, kb; G < p.length; G += 2) { + K = this.tag.get(p[G]); + if (!K) { + if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), q) { continue; } else { - return e; + return r ? d : new W(d); } } - if (jb = (F = F && F.get(n[D + 1])) && F.length) { - x++, v.push(F); - } else if (!r) { - return e; + if (kb = (K = K && K.get(p[G + 1])) && K.length) { + y++, x.push(K); + } else if (!q) { + return r ? d : new W(d); } } } - if (x) { - w = Da(w, v); - I = w.length; - if (!I && !r) { - return e; + if (y) { + w = Ba(w, x, r); + H = w.length; + if (!H && !q) { + return r ? w : new W(w); } - x--; + y--; } } - if (I) { - f[m] = A, e.push(w), m++; - } else if (1 === k.length) { - return e; + if (H) { + f[m] = D, d.push(w), m++; + } else if (1 === h.length) { + return r ? d : new W(d); } } - if (t) { - if (this.db && n && n.length && !E) { - for (p = 0; p < n.length; p += 2) { - d = this.index.get(n[p]); - if (!d) { - if (console.warn("Tag '" + n[p] + ":" + n[p + 1] + "' was not found because there is no field '" + n[p] + "'."), r) { + if (v) { + if (this.db && p && p.length && !F) { + for (u = 0; u < p.length; u += 2) { + e = this.index.get(p[u]); + if (!e) { + if (console.warn("Tag '" + p[u] + ":" + p[u + 1] + "' was not found because there is no field '" + p[u] + "'."), q) { continue; } else { - return e; + return r ? d : new W(d); } } - t.push(d.db.tag(n[p + 1], b, l, !1)); + v.push(e.db.tag(p[u + 1], b, l, !1)); } } - const y = this; - return Promise.all(t).then(function(w) { - return w.length ? y.search(a, b, c, w) : w; + const z = this; + return Promise.all(v).then(function(w) { + return w.length ? z.search(a, b, c, w) : w; }); } if (!m) { - return e; + return r ? d : new W(d); } - if (g && (!p || !this.store)) { - return e[0]; + if (g && (!u || !this.store)) { + return d[0]; } - t = []; - for (let y = 0, w; y < f.length; y++) { - w = e[y]; - p && w.length && !w[0].doc && (this.db ? t.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = Fa.call(this, w))); + v = []; + for (let z = 0, w; z < f.length; z++) { + w = d[z]; + u && w.length && !w[0].doc && (this.db ? v.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = V.call(this, w)); if (g) { - return w; + return r ? w : new W(w); } - e[y] = {field:f[y], result:w}; + d[z] = {field:f[z], result:w}; } - if (p && this.db && t.length) { - const y = this; - return Promise.all(t).then(function(w) { - for (let A = 0; A < w.length; A++) { - e[A].result = w[A]; + if (u && this.db && v.length) { + const z = this; + return Promise.all(v).then(function(w) { + for (let D = 0; D < w.length; D++) { + d[D].result = w[D]; } - return h ? Ga(e, b) : q ? Ha(e, a, y.index, y.field, y.D, q) : e; + return k ? La(d, b) : n ? Ma(d, a, z.index, z.field, z.D, n) : d; }); } - return h ? Ga(e, b) : q ? Ha(e, a, this.index, this.field, this.D, q) : e; + return k ? La(d, b) : n ? Ma(d, a, this.index, this.field, this.D, n) : d; }; -function Ha(a, b, c, d, e, f) { - let g, h, k; - for (let m = 0, q, n, p, r, t; m < a.length; m++) { - q = a[m].result; - n = a[m].field; - r = c.get(n); - p = r.encoder; - k = r.tokenize; - t = e[d.indexOf(n)]; - p !== g && (g = p, h = g.encode(b)); - for (let v = 0; v < q.length; v++) { +function Ma(a, b, c, e, d, f) { + let g, k, h; + for (let m = 0, n, p, q, r, u; m < a.length; m++) { + n = a[m].result; + p = a[m].field; + r = c.get(p); + q = r.encoder; + h = r.tokenize; + u = d[e.indexOf(p)]; + q !== g && (g = q, k = g.encode(b)); + for (let v = 0; v < n.length; v++) { let x = ""; - var l = J(q[v].doc, t); - let E = g.encode(l); + var l = J(n[v].doc, u); + let y = g.encode(l); l = l.split(g.split); - for (let y = 0, w, A; y < E.length; y++) { - w = E[y]; - A = l[y]; - let I; - for (let C = 0, D; C < h.length; C++) { - if (D = h[C], "strict" === k) { - if (w === D) { - x += (x ? " " : "") + f.replace("$1", A); - I = !0; + for (let F = 0, z, w; F < y.length; F++) { + z = y[F]; + w = l[F]; + let D; + for (let H = 0, C; H < k.length; H++) { + if (C = k[H], "strict" === h) { + if (z === C) { + x += (x ? " " : "") + f.replace("$1", w); + D = !0; break; } } else { - const F = w.indexOf(D); - if (-1 < F) { - x += (x ? " " : "") + A.substring(0, F) + f.replace("$1", A.substring(F, D.length)) + A.substring(F + D.length); - I = !0; + const G = z.indexOf(C); + if (-1 < G) { + x += (x ? " " : "") + w.substring(0, G) + f.replace("$1", w.substring(G, C.length)) + w.substring(G + C.length); + D = !0; break; } } } - I || (x += (x ? " " : "") + l[y]); + D || (x += (x ? " " : "") + l[F]); } - q[v].highlight = x; + n[v].highlight = x; } } return a; } -function Ga(a, b) { - const c = [], d = B(); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e]; +function La(a, b) { + const c = [], e = B(); + for (let d = 0, f, g; d < a.length; d++) { + f = a[d]; g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = d[k]) { + for (let k = 0, h, l, m; k < g.length; k++) { + if (l = g[k], h = l.id, m = e[h]) { m.push(f.field); } else { if (c.length === b) { return c; } - l.field = d[k] = [f.field]; + l.field = e[h] = [f.field]; c.push(l); } } } return c; } -function Ea(a, b, c, d, e) { +function Ka(a, b, c, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { - if (a > c || d) { - f = f.slice(d, d + c); + if ((a = (f = f && f.get(b)) && f.length - e) && 0 < a) { + if (a > c || e) { + f = f.slice(e, e + c); } - e && (f = Fa.call(this, f)); + d && (f = V.call(this, f)); return f; } } -function Fa(a) { +function V(a) { + if (!this || !this.store) { + return a; + } const b = Array(a.length); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b[c] = {id:d, doc:this.store.get(d)}; + for (let c = 0, e; c < a.length; c++) { + e = a[c], b[c] = {id:e, doc:this.store.get(e)}; } return b; } -;function T(a) { - if (!this || this.constructor !== T) { - return new T(a); +;function U(a) { + if (!this || this.constructor !== U) { + return new U(a); } const b = a.document || a.doc || a; - let c, d; + let c, e; this.D = []; this.field = []; - this.K = []; - this.key = (c = b.key || b.id) && Ia(c, this.K) || "id"; - (d = a.keystore || 0) && (this.keystore = d); - this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new R(d) : new Map() : d ? new S(d) : new Set(); + this.J = []; + this.key = (c = b.key || b.id) && Na(c, this.J) || "id"; + (e = a.keystore || 0) && (this.keystore = e); + this.reg = (this.fastupdate = !!a.fastupdate) ? e ? new S(e) : new Map() : e ? new T(e) : new Set(); this.C = (c = b.store || null) && c && !0 !== c && []; - this.store = c && (d ? new R(d) : new Map()); - this.cache = (c = a.cache || null) && new U(c); + this.store = c && (e ? new S(e) : new Map()); + this.cache = (c = a.cache || null) && new X(c); a.cache = !1; this.worker = a.worker; - this.index = Ja.call(this, a, b); + this.index = Oa.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { this.tag = new Map(); - this.G = []; - this.P = []; - for (let e = 0, f, g; e < c.length; e++) { - f = c[e]; + this.F = []; + this.R = []; + 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."); } - f.custom ? this.G[e] = f.custom : (this.G[e] = Ia(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].J = f.filter)); - this.P[e] = g; + f.custom ? this.F[d] = f.custom : (this.F[d] = Na(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); + this.R[d] = g; this.tag.set(g, new Map()); } } } if (this.worker) { a = []; - for (const e of this.index.values()) { - e.then && a.push(e); + for (const d of this.index.values()) { + d.then && a.push(d); } if (a.length) { - const e = this; + const d = this; return Promise.all(a).then(function(f) { let g = 0; - for (const h of e.index.entries()) { - const k = h[0]; - h[1].then && e.index.set(k, f[g++]); + for (const k of d.index.entries()) { + const h = k[0]; + k[1].then && d.index.set(h, f[g++]); } - return e; + return d; }); } } else { a.db && this.mount(a.db); } } -u = T.prototype; -u.mount = function(a) { +t = U.prototype; +t.mount = function(a) { let b = this.field; if (this.tag) { - for (let e = 0, f; e < this.P.length; e++) { - f = this.P[e]; + for (let d = 0, f; d < this.R.length; d++) { + f = this.R[d]; var c = void 0; - this.index.set(f, c = new M({}, this.reg)); + this.index.set(f, c = new N({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(f); c.tag = this.tag.get(f); } } c = []; - const d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let e = 0, f, g; e < b.length; e++) { - d.field = g = b[e]; + const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; + for (let d = 0, f, g; d < b.length; d++) { + e.field = g = b[d]; f = this.index.get(g); - const h = new a.constructor(a.id, d); - h.id = a.id; - c[e] = h.mount(f); + const k = new a.constructor(a.id, e); + k.id = a.id; + c[d] = k.mount(f); f.document = !0; - e ? f.bypass = !0 : f.store = this.store; + d ? f.bypass = !0 : f.store = this.store; } this.db = !0; return Promise.all(c); }; -u.commit = async function(a, b) { +t.commit = async function(a, b) { const c = []; - for (const d of this.index.values()) { - c.push(d.db.commit(d, a, b)); + for (const e of this.index.values()) { + c.push(e.db.commit(e, a, b)); } await Promise.all(c); this.reg.clear(); }; -u.destroy = function() { +t.destroy = function() { const a = []; for (const b of this.index.values()) { a.push(b.destroy()); } return Promise.all(a); }; -function Ja(a, b) { +function Oa(a, b) { const c = new Map(); - let d = b.index || b.field || b; - G(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e]; - G(f) || (g = f, f = f.field); - g = H(g) ? Object.assign({}, a, g) : a; + let e = b.index || b.field || b; + E(e) && (e = [e]); + for (let d = 0, f, g; d < e.length; d++) { + f = e[d]; + E(f) || (g = f, f = f.field); + g = I(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const h = new N(g); - c.set(f, h); + const k = new O(g); + c.set(f, k); } - this.worker || c.set(f, new M(g, this.reg)); - g.custom ? this.D[e] = g.custom : (this.D[e] = Ia(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].J = g.filter)); - this.field[e] = f; + this.worker || c.set(f, new N(g, this.reg)); + g.custom ? this.D[d] = g.custom : (this.D[d] = Na(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); + this.field[d] = f; } if (this.C) { a = b.store; - G(a) && (a = [a]); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ia(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].J = f.filter)); + E(a) && (a = [a]); + for (let d = 0, f, g; d < a.length; d++) { + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Na(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); } } return c; } -function Ia(a, b) { +function Na(a, b) { const c = a.split(":"); - let d = 0; - for (let e = 0; e < c.length; e++) { - a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); + let e = 0; + for (let d = 0; d < c.length; d++) { + a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); } - d < c.length && (c.length = d); - return 1 < d ? c : c[0]; + e < c.length && (c.length = e); + return 1 < e ? c : c[0]; } -u.append = function(a, b) { +t.append = function(a, b) { return this.add(a, b, !0); }; -u.update = function(a, b) { +t.update = function(a, b) { return this.remove(a).add(a, b); }; -u.remove = function(a) { - H(a) && (a = J(a, this.key)); +t.remove = function(a) { + I(a) && (a = J(a, this.key)); for (var b of this.index.values()) { b.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { for (let c of this.tag.values()) { - for (let d of c) { - b = d[0]; - const e = d[1], f = e.indexOf(a); - -1 < f && (1 < e.length ? e.splice(f, 1) : c.delete(b)); + 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) : c.delete(b)); } } } @@ -1277,7 +1593,7 @@ u.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -u.clear = function() { +t.clear = function() { for (const a of this.index.values()) { a.clear(); } @@ -1289,66 +1605,66 @@ u.clear = function() { this.store && this.store.clear(); return this; }; -u.contain = function(a) { +t.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -u.cleanup = function() { +t.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -u.get = function(a) { +t.get = function(a) { return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { return b[0] && b[0].doc; }) : this.store.get(a); }; -u.set = function(a, b) { +t.set = function(a, b) { this.store.set(a, b); return this; }; -u.searchCache = Ka; -u.export = function(a, b, c = 0, d = 0) { +t.searchCache = Pa; +t.export = function(a, b, c = 0, e = 0) { if (c < this.field.length) { const g = this.field[c]; - if ((b = this.index.get(g).export(a, g, c, d = 1)) && b.then) { - const h = this; + if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { + const k = this; return b.then(function() { - return h.export(a, g, c + 1); + return k.export(a, g, c + 1); }); } return this.export(a, g, c + 1); } - let e, f; - switch(d) { + let d, f; + switch(e) { case 0: - e = "reg"; - f = ta(this.reg); + d = "reg"; + f = ra(this.reg); b = null; break; case 1: - e = "tag"; - f = ra(this.tag, this.reg.size); + d = "tag"; + f = pa(this.tag, this.reg.size); b = null; break; case 2: - e = "doc"; - f = pa(this.store); + d = "doc"; + f = na(this.store); b = null; break; case 3: - e = "cfg"; + d = "cfg"; f = {}; b = null; break; default: return; } - return va.call(this, a, b, e, f, c, d); + return ta.call(this, a, b, d, f, c, e); }; -u.import = function(a, b) { +t.import = function(a, b) { if (b) { - G(b) && (b = JSON.parse(b)); + "string" === typeof b && (b = JSON.parse(b)); a = a.split("."); "json" === a[a.length - 1] && a.pop(); var c = 2 < a.length ? a[0] : ""; @@ -1359,133 +1675,132 @@ u.import = function(a, b) { switch(a) { case "reg": this.fastupdate = !1; - this.reg = ua(b, this.reg); - for (let d = 0, e; d < this.field.length; d++) { - e = this.index.get(this.field[d]), e.fastupdate = !1, e.reg = this.reg; + this.reg = sa(b, this.reg); + for (let e = 0, d; e < this.field.length; e++) { + d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = sa(b, this.tag); + this.tag = qa(b, this.tag); break; case "doc": - this.store = qa(b, this.store); + this.store = oa(b, this.store); } } }; -oa(T.prototype); -function Ka(a, b, c) { +ma(U.prototype); +function Pa(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new U()); - let d = this.cache.get(a); - if (!d) { - d = this.search(a, b, c); - if (d.then) { - const e = this; - d.then(function(f) { - e.cache.set(a, f); + this.cache || (this.cache = new X()); + let e = this.cache.get(a); + if (!e) { + e = this.search(a, b, c); + if (e.then) { + const d = this; + e.then(function(f) { + d.cache.set(a, f); return f; }); } - this.cache.set(a, d); + this.cache.set(a, e); } - return d; + return e; } -function U(a) { +function X(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -U.prototype.set = function(a, b) { +X.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); }; -U.prototype.get = function(a) { +X.prototype.get = function(a) { const b = this.cache.get(a); b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); return b; }; -U.prototype.remove = function(a) { +X.prototype.remove = function(a) { for (const b of this.cache) { const c = b[0]; b[1].includes(a) && this.cache.delete(c); } }; -U.prototype.clear = function() { +X.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const La = {normalize:function(a) { +const Qa = {normalize:function(a) { return a.toLowerCase(); -}, dedupe:!1}; -const Ma = 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 Na = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Oa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const Pa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const Qa = /[\x00-\x7F]+/g; -const Ra = /[\x00-\x7F]+/g; -const Sa = /[\x00-\x7F]+/g; -var Ta = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:La, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ma}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ma, matcher:Na, replacer:Oa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ma, replacer:Oa.concat([/(?!^)[aeo]/g, ""]), matcher:Na}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +}, numeric:!1, dedupe:!1}; +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"], ["pf", "f"]]), Ta = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\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}; +const Va = /[\x00-\x7F]+/g; +const Wa = /[\x00-\x7F]+/g; +const Xa = /[\x00-\x7F]+/g; +var Ya = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Qa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ra}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ra, matcher:Sa, replacer:Ta}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ra, replacer:Ta.concat([/(?!^)[aeo]/g, ""]), matcher:Sa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let d = b.charAt(0), e = Pa[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Pa[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + let e = b.charAt(0), d = Ua[e]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Ua[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = d; + a[c] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Qa, " "); + return ("" + a).replace(Va, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ra, ""); + return ("" + a).replace(Wa, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Sa, " "); + return ("" + a).replace(Xa, " "); }}}; -const Ua = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -B(); -M.prototype.add = function(a, b, c, d) { +const Za = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +N.prototype.add = function(a, b, c, e) { if (b && (a || 0 === a)) { - if (!d && !c && this.reg.has(a)) { + if (!e && !c && this.reg.has(a)) { return this.update(a, b); } b = this.encoder.encode(b); - if (d = b.length) { - const l = B(), m = B(), q = this.depth, n = this.resolution; - for (let p = 0; p < d; p++) { - let r = b[this.rtl ? d - 1 - p : p]; - var e = r.length; - if (e && (q || !m[r])) { - var f = this.score ? this.score(b, r, p, null, 0) : Va(n, d, p), g = ""; + if (e = b.length) { + const l = B(), m = B(), n = this.depth, p = this.resolution; + for (let q = 0; q < e; q++) { + let r = b[this.rtl ? e - 1 - q : q]; + var d = r.length; + if (d && (n || !m[r])) { + var f = this.score ? this.score(b, r, q, null, 0) : $a(p, e, q), g = ""; switch(this.tokenize) { case "full": - if (2 < e) { - for (f = 0; f < e; f++) { - for (var h = e; h > f; h--) { - g = r.substring(f, h); - var k = this.score ? this.score(b, r, p, g, f) : Va(n, d, p, e, f); - V(this, m, g, k, a, c); + if (2 < d) { + for (f = 0; f < d; f++) { + for (var k = d; k > f; k--) { + g = r.substring(f, k); + var h = this.score ? this.score(b, r, q, g, f) : $a(p, e, q, d, f); + Y(this, m, g, h, a, c); } } break; } case "reverse": - if (1 < e) { - for (h = e - 1; 0 < h; h--) { - g = r[h] + g, k = this.score ? this.score(b, r, p, g, h) : Va(n, d, p, e, h), V(this, m, g, k, a, c); + if (1 < d) { + for (k = d - 1; 0 < k; k--) { + g = r[k] + g, h = this.score ? this.score(b, r, q, g, k) : $a(p, e, q, d, k), Y(this, m, g, h, a, c); } g = ""; } case "forward": - if (1 < e) { - for (h = 0; h < e; h++) { - g += r[h], V(this, m, g, f, a, c); + if (1 < d) { + for (k = 0; k < d; k++) { + g += r[k], Y(this, m, g, f, a, c); } break; } default: - if (V(this, m, r, f, a, c), q && 1 < d && p < d - 1) { - for (e = B(), g = this.R, f = r, h = Math.min(q + 1, d - p), e[f] = 1, k = 1; k < h; k++) { - if ((r = b[this.rtl ? d - 1 - p - k : p + k]) && !e[r]) { - e[r] = 1; - const t = this.score ? this.score(b, f, p, r, k) : Va(g + (d / 2 > g ? 0 : 1), d, p, h - 1, k - 1), v = this.bidirectional && r > f; - V(this, l, v ? f : r, t, a, c, v ? r : f); + if (Y(this, m, r, f, a, c), n && 1 < e && q < e - 1) { + for (d = B(), g = this.U, f = r, k = Math.min(n + 1, e - q), d[f] = 1, h = 1; h < k; h++) { + if ((r = b[this.rtl ? e - 1 - q - h : q + h]) && !d[r]) { + d[r] = 1; + const u = this.score ? this.score(b, f, q, r, h) : $a(g + (e / 2 > g ? 0 : 1), e, q, k - 1, h - 1), v = this.bidirectional && r > f; + Y(this, l, v ? f : r, u, a, c, v ? r : f); } } } @@ -1497,599 +1812,157 @@ M.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && Wa(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && ab(this)); return this; }; -function V(a, b, c, d, e, f, g) { - let h = g ? a.ctx : a.map, k; - if (!b[c] || g && !(k = b[c])[g]) { - if (g ? (b = k || (b[c] = B()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { - if (h.length === 2 ** 31 - 1) { - b = new Q(h); +function Y(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] = B()), b[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : b[c] = 1, (h = k.get(c)) ? k = h : k.set(c, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { + if (k.length === 2 ** 31 - 1) { + b = new R(k); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(h) && (l[l.indexOf(h)] = b); + l.includes(k) && (l[l.indexOf(k)] = b); } } - k[d] = h = b; + h[e] = k = b; } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + k.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } } -function Va(a, b, c, d, e) { - return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; +function $a(a, b, c, e, d) { + return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; } -;function W(a, b, c, d) { - if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Xa(a) : a; +;N.prototype.search = function(a, b, c) { + c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); + let e = [], d, f, g, k = 0, h, l, m, n, p; + c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, p = (h = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : h = this.resolve; + let q = this.encoder.encode(a); + d = q.length; + b = b || (h ? 100 : 0); + if (1 === d) { + return bb.call(this, q[0], "", b, k, h, p, l); } - let e = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { - if (c) { - if (c >= h) { - c -= h; - continue; - } - c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); - } - if (e.length) { - h > b && (g = g.slice(0, b), h = g.length); - } else { - if (h >= b) { - return h > b && (g = g.slice(0, b)), d ? Xa(g) : g; - } - } - e.push(g); - b -= h; - if (!b) { - break; - } - } + f = this.depth && !1 !== f; + if (2 === d && f && !g) { + return bb.call(this, q[0], q[1], b, k, h, p, l); } - if (!e.length) { - return e; - } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? Xa(e) : e; -} -function Xa(a) { - for (let b = 0; b < a.length; b++) { - a[b] = {score:b, id:a[b]}; - } - return a; -} -;X.prototype.or = function() { - const a = this; - let b = arguments; - var c = b[0]; - if (c.then) { - return c.then(function() { - return a.or.apply(a, b); - }); - } - if (c[0] && c[0].index) { - return this.or.apply(this, c); - } - let d = []; - c = []; - let e = 0, f = 0, g, h; - for (let k = 0, l; k < b.length; k++) { - if (l = b[k]) { - e = l.limit || 0; - f = l.offset || 0; - g = l.enrich; - h = l.resolve; - let m; - if (l.constructor === X) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.and) { - m = this.and(l.and); - } else if (l.xor) { - m = this.xor(l.xor); - } else if (l.not) { - m = this.not(l.not); - } else { - continue; - } - d[k] = m; - m.then && c.push(m); - } - } - if (c.length) { - return Promise.all(c).then(function() { - a.result.length && (d = d.concat([a.result])); - a.result = Ya(d, e, f, g, h, a.F); - return h ? a.result : a; - }); - } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ya(d, e, f, g, h, this.F)); - return h ? this.result : this; -}; -function Ya(a, b, c, d, e, f) { - if (!a.length) { - return a; - } - "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : Ca(a, c, b, e, f); -} -;X.prototype.and = function() { - if (this.result.length) { - const b = this; - let c = arguments; - var a = c[0]; - if (a.then) { - return a.then(function() { - return b.and.apply(b, c); - }); - } - if (a[0] && a[0].index) { - return this.and.apply(this, a); - } - let d = []; - a = []; - let e = 0, f = 0, g, h; - for (let k = 0, l; k < c.length; k++) { - if (l = c[k]) { - e = l.limit || 0; - f = l.offset || 0; - g = l.resolve; - h = l.suggest; - let m; - if (l.constructor === X) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.or) { - m = this.or(l.or); - } else if (l.xor) { - m = this.xor(l.xor); - } else if (l.not) { - m = this.not(l.not); - } else { - continue; - } - d[k] = m; - m.then && a.push(m); - } - } - if (!d.length) { - return this.result = d, g ? this.result : this; - } - if (a.length) { - return Promise.all(a).then(function() { - d = [b.result].concat(d); - b.result = Za(d, e, f, g, b.F, h); - return g ? b.result : b; - }); - } - d = [this.result].concat(d); - this.result = Za(d, e, f, g, this.F, h); - return g ? this.result : this; - } - return this; -}; -function Za(a, b, c, d, e, f) { - if (2 > a.length) { - return []; - } - let g = []; - B(); - let h = ca(a); - return h ? Ba(a, h, b, c, f, e, d) : g; -} -;X.prototype.xor = function() { - const a = this; - let b = arguments; - var c = b[0]; - if (c.then) { - return c.then(function() { - return a.xor.apply(a, b); - }); - } - if (c[0] && c[0].index) { - return this.xor.apply(this, c); - } - let d = []; - c = []; - let e = 0, f = 0, g, h; - for (let k = 0, l; k < b.length; k++) { - if (l = b[k]) { - e = l.limit || 0; - f = l.offset || 0; - g = l.enrich; - h = l.resolve; - let m; - if (l.constructor === X) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.or) { - m = this.or(l.or); - } else if (l.and) { - m = this.and(l.and); - } else if (l.not) { - m = this.not(l.not); - } else { - continue; - } - d[k] = m; - m.then && c.push(m); - } - } - if (c.length) { - return Promise.all(c).then(function() { - a.result.length && (d = [a.result].concat(d)); - a.result = $a(d, e, f, g, !h, a.F); - return h ? a.result : a; - }); - } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = $a(d, e, f, g, !h, a.F)); - return h ? this.result : this; -}; -function $a(a, b, c, d, e, f) { - if (!a.length) { - return a; - } - if (2 > a.length) { - return e ? W(a[0], b, c, d) : a[0]; - } - d = []; - const g = B(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - for (let m = 0, q; m < l.length; m++) { - if (q = l[m]) { - h < q.length && (h = q.length); - for (let n = 0, p; n < q.length; n++) { - p = q[n], g[p] ? g[p]++ : g[p] = 1; - } - } - } - } - } - for (let k = 0, l, m = 0; k < h; k++) { - for (let q = 0, n; q < a.length; q++) { - if (n = a[q]) { - if (l = n[k]) { - for (let p = 0, r; p < l.length; p++) { - if (r = l[p], 1 === g[r]) { - if (c) { - c--; - } else { - if (e) { - if (d.push(r), d.length === b) { - return d; - } - } else { - const t = k + (q ? f : 0); - d[t] || (d[t] = []); - d[t].push(r); - if (++m === b) { - return d; - } - } - } - } - } - } - } - } - } - return d; -} -;X.prototype.not = function() { - const a = this; - let b = arguments; - var c = b[0]; - if (c.then) { - return c.then(function() { - return a.not.apply(a, b); - }); - } - if (c[0] && c[0].index) { - return this.not.apply(this, c); - } - let d = []; - c = []; - let e = 0, f = 0, g; - for (let h = 0, k; h < b.length; h++) { - if (k = b[h]) { - e = k.limit || 0; - f = k.offset || 0; - g = k.resolve; - let l; - if (k.constructor === X) { - l = k.result; - } else if (k.constructor === Array) { - l = k; - } else if (k.index) { - k.resolve = !1, l = k.index.search(k).result; - } else if (k.or) { - l = this.or(k.or); - } else if (k.and) { - l = this.and(k.and); - } else if (k.xor) { - l = this.xor(k.xor); - } else { - continue; - } - d[h] = l; - l.then && c.push(l); - } - } - if (c.length) { - return Promise.all(c).then(function() { - a.result = ab.call(a, d, e, f, g); - return g ? a.result : a; - }); - } - d.length && (this.result = ab.call(this, d, e, f, g)); - return g ? this.result : this; -}; -function ab(a, b, c, d) { - if (!a.length) { - return this.result; - } - const e = []; - a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { - if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { - if (c) { - c--; - } else { - if (d) { - if (e.push(l), e.length === b) { - return e; - } - } else { - if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { - return e; - } - } - } - } - } - } - } - return e; -} -;function X(a) { - if (!this || this.constructor !== X) { - return new X(a); - } - if (a && a.index) { - return a.resolve = !1, this.index = a.index, this.F = a.boost || 0, this.result = a.index.search(a).result, this; - } - if (a.constructor === X) { - return a; - } - this.index = null; - this.result = a || []; - this.F = 0; -} -X.prototype.limit = function(a) { - if (this.result.length) { - const b = []; - let c = 0; - for (let d = 0, e; d < this.result.length; d++) { - if (e = this.result[d], e.length + c < a) { - b[d] = e, c += e.length; - } else { - b[d] = e.slice(0, a - c); - this.result = b; - break; - } - } - } - return this; -}; -X.prototype.offset = function(a) { - if (this.result.length) { - const b = []; - let c = 0; - for (let d = 0, e; d < this.result.length; d++) { - e = this.result[d], e.length + c < a ? c += e.length : (b[d] = e.slice(a - c), c = a); - } - this.result = b; - } - return this; -}; -X.prototype.boost = function(a) { - this.F += a; - return this; -}; -X.prototype.resolve = function(a, b, c) { - bb = 1; - const d = this.result; - this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), W(d, a || 100, b, c)) : d; -}; -let bb = 1; -M.prototype.search = function(a, b, c) { - c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); - let d = [], e; - let f, g = 0, h, k, l, m, q; - if (c) { - a = c.query || a; - b = c.limit || b; - g = c.offset || 0; - var n = c.context; - f = c.suggest; - (h = bb && !1 !== c.resolve) || (bb = 0); - k = h && c.enrich; - m = c.boost; - q = c.resolution; - l = this.db && c.tag; - } else { - h = this.resolve || bb; - } - let p = this.encoder.encode(a); - e = p.length; - b || !h || (b = 100); - if (1 === e) { - return cb.call(this, p[0], "", b, g, h, k, l); - } - n = this.depth && !1 !== n; - if (2 === e && n && !f) { - return cb.call(this, p[0], p[1], b, g, h, k, l); - } - c = a = 0; - if (1 < e) { - const v = B(), x = []; - for (let E = 0, y; E < e; E++) { - if ((y = p[E]) && !v[y]) { - if (f || this.db || Y(this, y)) { - x.push(y), v[y] = 1; - } else { - return h ? d : new X(d); - } - const w = y.length; - a = Math.max(a, w); - c = c ? Math.min(c, w) : w; - } - } - p = x; - e = p.length; - } - if (!e) { - return h ? d : new X(d); - } - let r = 0, t; - if (1 === e) { - return cb.call(this, p[0], "", b, g, h, k, l); - } - if (2 === e && n && !f) { - return cb.call(this, p[0], p[1], b, g, h, k, l); - } - 1 < e && (n ? (t = p[0], r = 1) : 9 < a && 3 < a / c && p.sort(aa)); - q || 0 === q || (q = this.resolution); + let r = B(), u = 0, v; + 1 < d && f && (v = q[0], u = 1); + n || 0 === n || (n = v ? this.U : this.resolution); if (this.db) { - if (this.db.search && (n = this.db.search(this, p, b, g, f, h, k, l), !1 !== n)) { - return n; + if (this.db.search && (a = this.db.search(this, q, b, k, g, h, p, l), !1 !== a)) { + return a; } - const v = this; + const x = this; return async function() { - for (let x, E; r < e; r++) { - E = p[r]; - t ? (x = await Y(v, E, t, 0, 0, !1, !1), x = db(x, d, f, v.R), f && !1 === x && d.length || (t = E)) : (x = await Y(v, E, "", 0, 0, !1, !1), x = db(x, d, f, q)); - if (x) { - return x; - } - if (f && r === e - 1) { - let y = d.length; - if (!y) { - if (t) { - t = ""; - r = -1; - continue; - } - return d; - } - if (1 === y) { - return h ? W(d[0], b, g) : new X(d[0]); + for (let y, F; u < d; u++) { + if ((F = q[u]) && !r[F]) { + r[F] = 1; + y = await cb(x, F, v, 0, 0, !1, !1); + if (y = db(y, e, g, n)) { + e = y; + break; } + v && (g && y && e.length || (v = F)); } + g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return h ? Ba(d, q, b, g, f, m, h) : new X(d[0]); + return eb(e, n, b, k, g, m, h); }(); } - for (let v, x; r < e; r++) { - x = p[r]; - t ? (v = Y(this, x, t, 0, 0, !1, !1), v = db(v, d, f, this.R), f && !1 === v && d.length || (t = x)) : (v = Y(this, x, "", 0, 0, !1, !1), v = db(v, d, f, q)); - if (v) { - return v; - } - if (f && r === e - 1) { - n = d.length; - if (!n) { - if (t) { - t = ""; - r = -1; - continue; - } - return d; - } - if (1 === n) { - return h ? W(d[0], b, g) : new X(d[0]); + for (let x, y; u < d; u++) { + if ((y = q[u]) && !r[y]) { + r[y] = 1; + x = cb(this, y, v, 0, 0, !1, !1); + if (x = db(x, e, g, n)) { + e = x; + break; } + v && (g && x && e.length || (v = y)); } + g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - d = Ba(d, q, b, g, f, m, h); - return h ? d : new X(d); + return eb(e, n, b, k, g, m, h); }; -function cb(a, b, c, d, e, f, g) { - a = Y(this, a, b, c, d, e, f, g); - return this.db ? a.then(function(h) { - return e ? h : h && h.length ? e ? W(h, c, d) : new X(h) : e ? [] : new X([]); - }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); +function eb(a, b, c, e, d, f, g) { + let k = a.length, h = a; + if (1 < k) { + h = za(a, b, c, e, d, f, g); + } else if (1 === k) { + return g ? Ca.call(null, a[0], c, e) : new W(a[0]); + } + return g ? h : new W(h); } -function db(a, b, c, d) { - let e = []; - if (a) { - d = Math.min(a.length, d); - for (let f = 0, g; f < d; f++) { - (g = a[f]) && g && (e[f] = g); +function bb(a, b, c, e, d, f, g) { + a = cb(this, a, b, c, e, d, f, g); + return this.db ? a.then(function(k) { + return d ? k || [] : new W(k); + }) : a && a.length ? d ? Ca.call(this, a, c, e) : new W(a) : d ? [] : new W(); +} +function db(a, b, c, e) { + let d = []; + if (a && a.length) { + if (a.length <= e) { + b.push(a); + return; } - if (e.length) { - b.push(e); + for (let f = 0, g; f < e; f++) { + if (g = a[f]) { + d[f] = g; + } + } + if (d.length) { + b.push(d); return; } } - return !c && e; -} -function Y(a, b, c, d, e, f, g, h) { - let k; - c && (k = a.bidirectional && b > c); - if (a.db) { - return c ? a.db.get(k ? c : b, k ? b : c, d, e, f, g, h) : a.db.get(b, "", d, e, f, g, h); + if (!c) { + return d; } - a = c ? (a = a.ctx.get(k ? b : c)) && a.get(k ? c : b) : a.map.get(b); +} +function cb(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(b, c, e, d, f, g, k); + } + a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;M.prototype.remove = function(a, b) { +;N.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 d = 0, e; d < c.length; d++) { - if (e = c[d]) { - if (2 > e.length) { - e.pop(); + for (let e = 0, d; e < c.length; e++) { + if (d = c[e]) { + if (2 > d.length) { + d.pop(); } else { - const f = e.indexOf(a); - f === c.length - 1 ? e.pop() : e.splice(f, 1); + const f = d.indexOf(a); + f === c.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - eb(this.map, a), this.depth && eb(this.ctx, a); + fb(this.map, a), this.depth && fb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && Wa(this)); + this.db && (this.commit_task.push({del:a}), this.T && ab(this)); this.cache && this.cache.remove(a); return this; }; -function eb(a, b) { +function fb(a, b) { let c = 0; if (a.constructor === Array) { - for (let d = 0, e, f; d < a.length; d++) { - if ((e = a[d]) && e.length) { - if (f = e.indexOf(b), 0 <= f) { - 1 < e.length ? (e.splice(f, 1), c++) : delete a[d]; + for (let e = 0, d, f; e < a.length; e++) { + if ((d = a[e]) && d.length) { + if (f = d.indexOf(b), 0 <= f) { + 1 < d.length ? (d.splice(f, 1), c++) : delete a[e]; break; } else { c++; @@ -2097,39 +1970,39 @@ function eb(a, b) { } } } else { - for (let d of a) { - const e = d[0], f = eb(d[1], b); - f ? c += f : a.delete(e); + for (let e of a.entries()) { + const d = e[0], f = fb(e[1], b); + f ? c += f : a.delete(d); } } return c; } -;function M(a, b) { - if (!this || this.constructor !== M) { - return new M(a); +;function N(a, b) { + if (!this || this.constructor !== N) { + return new N(a); } if (a) { - var c = G(a) ? a : a.preset; - c && (Ua[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ua[c], a)); + var c = E(a) ? a : a.preset; + c && (Za[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Za[c], a)); } else { a = {}; } c = a.context; - const d = !0 === c ? {depth:1} : c || {}, e = G(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || La; - this.encoder = e.encode ? e : "object" === typeof e ? new K(e) : {encode:e}; + const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? Ya[a.encoder] : a.encode || a.encoder || Qa; + this.encoder = d.encode ? d : "object" === typeof d ? new L(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = c = a.tokenize || "strict"; - this.depth = "strict" === c && d.depth || 0; - this.bidirectional = !1 !== d.bidirectional; + 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 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.R = d.resolution || 3; - this.rtl = e.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new U(c); + this.map = c ? new S(c) : new Map(); + this.ctx = c ? new S(c) : new Map(); + this.reg = b || (this.fastupdate ? c ? new S(c) : new Map() : c ? new T(c) : new Set()); + this.U = e.resolution || 3; + this.rtl = d.rtl || a.rtl || !1; + this.cache = (c = a.cache || null) && new X(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); @@ -2138,26 +2011,26 @@ function eb(a, b) { this.commit_task = []; this.commit_timer = null; } -u = M.prototype; -u.mount = function(a) { +t = N.prototype; +t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -u.commit = function(a, b) { +t.commit = function(a, b) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.commit(this, a, b); }; -u.destroy = function() { +t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Wa(a) { +function ab(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 0)); } -u.clear = function() { +t.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -2165,170 +2038,171 @@ u.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -u.append = function(a, b) { +t.append = function(a, b) { return this.add(a, b, !0); }; -u.contain = function(a) { +t.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -u.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); +t.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); }; -function fb(a) { +function gb(a) { let b = 0; if (a.constructor === Array) { - for (let c = 0, d; c < a.length; c++) { - (d = a[c]) && (b += d.length); + for (let c = 0, e; c < a.length; c++) { + (e = a[c]) && (b += e.length); } } else { for (const c of a) { - const d = c[0], e = fb(c[1]); - e ? b += e : a.delete(d); + const e = c[0], d = gb(c[1]); + d ? b += d : a.delete(e); } } return b; } -u.cleanup = function() { +t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - fb(this.map); - this.depth && fb(this.ctx); + gb(this.map); + this.depth && gb(this.ctx); return this; }; -u.searchCache = Ka; -u.export = function(a, b, c, d = 0) { - let e, f; - switch(d) { +t.searchCache = Pa; +t.export = function(a, b, c = 0, e = 0) { + let d, f; + switch(e) { case 0: - e = "reg"; - f = ta(this.reg); + d = "reg"; + f = ra(this.reg); break; case 1: - e = "cfg"; + d = "cfg"; f = {}; break; case 2: - e = "map"; - f = pa(this.map, this.reg.size); + d = "map"; + f = na(this.map, this.reg.size); break; case 3: - e = "ctx"; - f = ra(this.ctx, this.reg.size); + d = "ctx"; + f = pa(this.ctx, this.reg.size); break; default: return; } - return va.call(this, a, b, e, f, c, d); + return ta.call(this, a, b, d, f, c, e); }; -u.import = function(a, b) { +t.import = function(a, b) { if (b) { - switch(G(b) && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { + switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = ua(b, this.reg); + this.reg = sa(b, this.reg); break; case "map": - this.map = qa(b, this.map); + this.map = oa(b, this.map); break; case "ctx": - this.ctx = sa(b, this.ctx); + this.ctx = qa(b, this.ctx); } } }; -u.serialize = function(a = !0) { +t.serialize = function(a = !0) { if (!this.reg.size) { return ""; } let b = "", c = ""; - for (var d of this.reg.keys()) { - c || (c = typeof d), b += (b ? "," : "") + ("string" === c ? '"' + d + '"' : d); + for (var e of this.reg.keys()) { + c || (c = typeof e), b += (b ? "," : "") + ("string" === c ? '"' + e + '"' : e); } b = "index.reg=new Set([" + b + "]);"; - d = ""; - for (var e of this.map.entries()) { - var f = e[0], g = e[1], h = ""; - for (let m = 0, q; m < g.length; m++) { - q = g[m] || [""]; - var k = ""; - for (var l = 0; l < q.length; l++) { - k += (k ? "," : "") + ("string" === c ? '"' + q[l] + '"' : q[l]); - } - k = "[" + k + "]"; - h += (h ? "," : "") + k; - } - h = '["' + f + '",[' + h + "]]"; - d += (d ? "," : "") + h; - } - d = "index.map=new Map([" + d + "]);"; e = ""; + for (var d of this.map.entries()) { + var f = d[0], g = d[1], k = ""; + for (let m = 0, n; m < g.length; m++) { + n = g[m] || [""]; + var h = ""; + for (var l = 0; l < n.length; l++) { + h += (h ? "," : "") + ("string" === c ? '"' + n[l] + '"' : n[l]); + } + h = "[" + h + "]"; + k += (k ? "," : "") + h; + } + k = '["' + f + '",[' + k + "]]"; + e += (e ? "," : "") + k; + } + e = "index.map=new Map([" + e + "]);"; + d = ""; for (const m of this.ctx.entries()) { f = m[0]; g = m[1]; - for (const q of g.entries()) { - g = q[0]; - h = q[1]; - k = ""; - for (let n = 0, p; n < h.length; n++) { - p = h[n] || [""]; + for (const n of g.entries()) { + g = n[0]; + k = n[1]; + h = ""; + for (let p = 0, q; p < k.length; p++) { + q = k[p] || [""]; l = ""; - for (let r = 0; r < p.length; r++) { - l += (l ? "," : "") + ("string" === c ? '"' + p[r] + '"' : p[r]); + for (let r = 0; r < q.length; r++) { + l += (l ? "," : "") + ("string" === c ? '"' + q[r] + '"' : q[r]); } l = "[" + l + "]"; - k += (k ? "," : "") + l; + h += (h ? "," : "") + l; } - k = 'new Map([["' + g + '",[' + k + "]]])"; - k = '["' + f + '",' + k + "]"; - e += (e ? "," : "") + k; + h = 'new Map([["' + g + '",[' + h + "]]])"; + h = '["' + f + '",' + h + "]"; + d += (d ? "," : "") + h; } } - e = "index.ctx=new Map([" + e + "]);"; - return a ? "function inject(index){" + b + d + e + "}" : b + d + e; + d = "index.ctx=new Map([" + d + "]);"; + return a ? "function inject(index){" + b + e + d + "}" : b + e + d; }; -oa(M.prototype); -const gb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), hb = ["map", "ctx", "tag", "reg", "cfg"]; -function ib(a, b = {}) { +ma(N.prototype); +const hb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ib = ["map", "ctx", "tag", "reg", "cfg"]; +function jb(a, b = {}) { if (!this) { - return new ib(a, b); + return new jb(a, b); } "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 = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.support_tag_search = !1; + this.type = b.type; + this.fastupdate = this.support_tag_search = !1; this.db = null; this.h = {}; } -u = ib.prototype; -u.mount = function(a) { +t = jb.prototype; +t.mount = function(a) { if (!a.encoder) { return a.mount(this); } a.db = this; return this.open(); }; -u.open = function() { +t.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const d = gb.open(a.id + (a.field ? ":" + a.field : ""), 1); - d.onupgradeneeded = function() { - const e = a.db = this.result; - hb.forEach(f => { - e.objectStoreNames.contains(f) || e.createObjectStore(f); + const e = hb.open(a.id + (a.field ? ":" + a.field : ""), 1); + e.onupgradeneeded = function() { + const d = a.db = this.result; + ib.forEach(f => { + d.objectStoreNames.contains(f) || d.createObjectStore(f); }); }; - d.onblocked = function(e) { - console.error("blocked", e); + e.onblocked = function(d) { + console.error("blocked", d); c(); }; - d.onerror = function(e) { - console.error(this.error, e); + e.onerror = function(d) { + console.error(this.error, d); c(); }; - d.onsuccess = function() { + e.onsuccess = function() { a.db = this.result; a.db.onversionchange = function() { a.close(); @@ -2337,56 +2211,57 @@ u.open = function() { }; }); }; -u.close = function() { +t.close = function() { this.db.close(); this.db = null; }; -u.destroy = function() { - return gb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); +t.destroy = function() { + const a = hb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Z(a); }; -u.clear = function() { - const a = this.db.transaction(hb, "readwrite"); - for (let b = 0; b < hb.length; b++) { - a.objectStore(hb[b]).clear(); +t.clear = function() { + const a = this.db.transaction(ib, "readwrite"); + for (let b = 0; b < ib.length; b++) { + a.objectStore(ib[b]).clear(); } return Z(a); }; -u.get = function(a, b, c = 0, d = 0, e = !0, f = !1) { +t.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").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 (e) { - if (!c && !d && 1 === h.length) { - return h[0]; + if (d) { + if (!c && !e && 1 === k.length) { + return k[0]; } - for (let l = 0, m; l < h.length; l++) { - if ((m = h[l]) && m.length) { - if (d >= m.length) { - d -= m.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 q = c ? d + Math.min(m.length - d, c) : m.length; - for (let n = d; n < q; n++) { - k.push(m[n]); + const n = c ? e + Math.min(m.length - e, c) : m.length; + for (let p = e; p < n; p++) { + h.push(m[p]); } - d = 0; - if (k.length === c) { + e = 0; + if (h.length === c) { break; } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; -u.tag = function(a, b = 0, c = 0, d = !1) { +t.tag = function(a, b = 0, c = 0, e = !1) { a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); - const e = this; + const d = this; return Z(a).then(function(f) { if (!f || !f.length || c >= f.length) { return []; @@ -2395,182 +2270,182 @@ u.tag = function(a, b = 0, c = 0, d = !1) { return f; } f = f.slice(c, c + b); - return d ? e.enrich(f) : f; + return e ? d.enrich(f) : f; }); }; -u.enrich = function(a) { +t.enrich = function(a) { "object" !== typeof a && (a = [a]); const b = this.db.transaction("reg", "readonly").objectStore("reg"), c = []; - for (let d = 0; d < a.length; d++) { - c[d] = Z(b.get(a[d])); + for (let e = 0; e < a.length; e++) { + c[e] = Z(b.get(a[e])); } - return Promise.all(c).then(function(d) { - for (let e = 0; e < d.length; e++) { - d[e] = {id:a[e], doc:d[e] ? JSON.parse(d[e]) : null}; + 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}; } - return d; + return e; }); }; -u.has = function(a) { +t.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); return Z(a); }; -u.search = null; -u.info = function() { +t.search = null; +t.info = function() { }; -u.transaction = function(a, b, c) { - let d = this.h[a + ":" + b]; - if (d) { - return c.call(this, d); +t.transaction = function(a, b, c) { + let e = this.h[a + ":" + b]; + if (e) { + return c.call(this, e); } - let e = this.db.transaction(a, b); - this.h[a + ":" + b] = d = e.objectStore(a); + let d = this.db.transaction(a, b); + this.h[a + ":" + b] = e = d.objectStore(a); return new Promise((f, g) => { - e.onerror = h => { + d.onerror = k => { this.h[a + ":" + b] = null; - e.abort(); - e = d = null; - g(h); + d.abort(); + d = e = null; + g(k); }; - e.oncomplete = h => { - e = d = this.h[a + ":" + b] = null; - f(h || !0); + d.oncomplete = k => { + d = e = this.h[a + ":" + b] = null; + f(k || !0); }; - return c.call(this, d); + return c.call(this, e); }); }; -u.commit = async function(a, b, c) { +t.commit = async function(a, b, c) { if (b) { await this.clear(), a.commit_task = []; } else { - let d = a.commit_task; + let e = a.commit_task; a.commit_task = []; - for (let e = 0, f; e < d.length; e++) { - if (f = d[e], f.clear) { + for (let d = 0, f; d < e.length; d++) { + if (f = e[d], f.clear) { await this.clear(); b = !0; break; } else { - d[e] = f.V; + e[d] = f.W; } } - b || (c || (d = d.concat(ba(a.reg))), d.length && await this.remove(d)); + b || (c || (e = e.concat(aa(a.reg))), e.length && await this.remove(e)); } - a.reg.size && (await this.transaction("map", "readwrite", function(d) { - for (const e of a.map) { - const f = e[0], g = e[1]; - g.length && (b ? d.put(g, f) : d.get(f).onsuccess = function() { - let h = this.result; - var k; - if (h && h.length) { - const l = Math.max(h.length, g.length); - for (let m = 0, q, n; m < l; m++) { - if ((n = g[m]) && n.length) { - if ((q = h[m]) && q.length) { - for (k = 0; k < n.length; k++) { - q.push(n[k]); + a.reg.size && (await this.transaction("map", "readwrite", function(e) { + for (const d of a.map) { + const f = d[0], g = d[1]; + g.length && (b ? e.put(g, f) : e.get(f).onsuccess = function() { + let k = this.result; + var h; + if (k && k.length) { + const l = Math.max(k.length, g.length); + for (let m = 0, n, p; m < l; m++) { + if ((p = g[m]) && p.length) { + if ((n = k[m]) && n.length) { + for (h = 0; h < p.length; h++) { + n.push(p[h]); } } else { - h[m] = n; + k[m] = p; } - k = 1; + h = 1; } } } else { - h = g, k = 1; + k = g, h = 1; } - k && d.put(h, f); + h && e.put(k, f); }); } - }), await this.transaction("ctx", "readwrite", function(d) { - for (const e of a.ctx) { - const f = e[0], g = e[1]; - for (const h of g) { - const k = h[0], l = h[1]; - l.length && (b ? d.put(l, f + ":" + k) : d.get(f + ":" + k).onsuccess = function() { + }), await this.transaction("ctx", "readwrite", function(e) { + for (const d of a.ctx) { + const f = d[0], g = d[1]; + for (const k of g) { + const h = k[0], l = k[1]; + l.length && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { let m = this.result; - var q; + var n; if (m && m.length) { - const n = Math.max(m.length, l.length); - for (let p = 0, r, t; p < n; p++) { - if ((t = l[p]) && t.length) { - if ((r = m[p]) && r.length) { - for (q = 0; q < t.length; q++) { - r.push(t[q]); + const p = Math.max(m.length, l.length); + for (let q = 0, r, u; q < p; q++) { + if ((u = l[q]) && u.length) { + if ((r = m[q]) && r.length) { + for (n = 0; n < u.length; n++) { + r.push(u[n]); } } else { - m[p] = t; + m[q] = u; } - q = 1; + n = 1; } } } else { - m = l, q = 1; + m = l, n = 1; } - q && d.put(m, f + ":" + k); + n && e.put(m, f + ":" + h); }); } } - }), a.store ? await this.transaction("reg", "readwrite", function(d) { - for (const e of a.store) { - const f = e[0], g = e[1]; - d.put("object" === typeof g ? JSON.stringify(g) : 1, f); + }), a.store ? await this.transaction("reg", "readwrite", function(e) { + for (const d of a.store) { + const f = d[0], g = d[1]; + e.put("object" === typeof g ? JSON.stringify(g) : 1, f); } - }) : a.bypass || await this.transaction("reg", "readwrite", function(d) { - for (const e of a.reg.keys()) { - d.put(1, e); + }) : a.bypass || await this.transaction("reg", "readwrite", function(e) { + for (const d of a.reg.keys()) { + e.put(1, d); } - }), a.tag && await this.transaction("tag", "readwrite", function(d) { - for (const e of a.tag) { - const f = e[0], g = e[1]; - g.length && (d.get(f).onsuccess = function() { - let h = this.result; - h = h && h.length ? h.concat(g) : g; - d.put(h, f); + }), a.tag && await this.transaction("tag", "readwrite", function(e) { + for (const d of a.tag) { + const f = d[0], g = d[1]; + g.length && (e.get(f).onsuccess = function() { + 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 kb(a, b, c) { - const d = a.value; - let e, f, g = 0; - for (let h = 0, k; h < d.length; h++) { - if (k = c ? d : d[h]) { - for (let l = 0, m, q; l < b.length; l++) { - if (q = b[l], m = k.indexOf(f ? parseInt(q, 10) : q), 0 > m && !f && "string" === typeof q && !isNaN(q) && (m = k.indexOf(parseInt(q, 10))) && (f = 1), 0 <= m) { - if (e = 1, 1 < k.length) { - k.splice(m, 1); +function lb(a, b, c) { + const e = a.value; + let d, f, g = 0; + for (let k = 0, h; k < e.length; k++) { + if (h = c ? e : e[k]) { + for (let l = 0, m, n; l < b.length; l++) { + if (n = b[l], m = h.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = h.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { + if (d = 1, 1 < h.length) { + h.splice(m, 1); } else { - d[h] = []; + e[k] = []; break; } } } - g += k.length; + g += h.length; } if (c) { break; } } - g ? e && a.update(d) : a.delete(); + g ? d && a.update(e) : a.delete(); a.continue(); } -u.remove = function(a) { +t.remove = function(a) { "object" !== typeof a && (a = [a]); return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && kb(c, a); + c && lb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && kb(c, a); + c && lb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && kb(c, a, !0); + c && lb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2590,9 +2465,9 @@ function Z(a) { a = null; }); } -;const lb = {Index:M, Charset:Ta, Encoder:K, Document:T, Worker:N, Resolver:X, IndexedDB:ib, Language:{}}, mb = self; -let nb; -(nb = mb.define) && nb.amd ? nb([], function() { - return lb; -}) : "object" === typeof mb.exports ? mb.exports = lb : mb.FlexSearch = lb; +;const mb = {Index:N, Charset:Ya, Encoder:L, Document:U, Worker:O, Resolver:W, IndexedDB:jb, Language:{}}, nb = self; +let ob; +(ob = nb.define) && ob.amd ? ob([], function() { + return mb; +}) : "object" === typeof nb.exports ? nb.exports = mb : nb.FlexSearch = mb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index f32ac4b..b08008d 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,105 +1,99 @@ /**! - * FlexSearch.js v0.8.103 (Bundle) + * FlexSearch.js v0.8.105 (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 u;function z(a,b,c){const d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)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"===e?b:a}function B(){return Object.create(null)}function aa(a,b){return b.length-a.length} -function F(a){return"string"===typeof a}function G(a){return"object"===typeof a}function ba(a){const b=[];for(const c of a.keys())b.push(c);return b}function J(a,b){if(F(b))a=a[b];else for(let c=0;a&&ca.length)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&&L(this);return this};u.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&&L(this);return this}; -u.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&L(this);return this};u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1this.stemmer.get(l)),k=1);g&&k&&(g.lengththis.matcher.get(l)));if(g&&this.replacer)for(e=0;g&&ethis.S&&(this.I.clear(),this.M=this.M/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.B&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.B=this.B/1.1|0));return c};function ka(a){a.L=null;a.H.clear();a.I.clear()};async function la(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new M(d);postMessage({id:a.id});break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let ma=0; -function N(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=B();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++ma]=function(){k(e)};e.worker.postMessage({id:ma,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==N)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;c&&(c=c.toString());const d="undefined"===typeof window,e=this,f=na(c,d,a.worker);return f.then?f.then(function(g){return b.call(e,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); -function O(a){N.prototype[a]=N.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;"function"===typeof d&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){b.h[++ma]=f;b.worker.postMessage({task:a,id:ma,args:c})});return e?(d.then(e),this):d}} -function na(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="+la.toString()],{type:"text/javascript"}))):new window.Worker(F(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"})};function oa(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}function P(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function pa(a,b=0){let c=[],d=[];b&&(b=25E4/b*5E3|0);for(const e of a.entries())d.push(e),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function qa(a,b){b||(b=new Map);for(let c=0,d;c=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} -function Q(a){if(!this)return new Q(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(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){let f=0;for(let g=0,h,k;gc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(let p=0,n;pd)d-=n.length; -else{if(n.length>c||d)n=n.slice(d,c+d),c-=n.length,d&&(d-=n.length);e.push(n);if(!c)break}k=1c||d)a=a.slice(d,d+c);e&&(a=Fa.call(this,a));return a}} -function Fa(a){const b=Array(a.length);for(let c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -U.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};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const La={normalize:function(a){return a.toLowerCase()},dedupe:!1};const Ma=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 Na=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Oa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Pa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Qa=/[\x00-\x7F]+/g;const Ra=/[\x00-\x7F]+/g;const Sa=/[\x00-\x7F]+/g;var Ta={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:La,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ma},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ma,matcher:Na,replacer:Oa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ma,replacer:Oa.concat([/(?!^)[aeo]/g,""]),matcher:Na},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=r.substring(f,h);var k=this.score?this.score(b,r,q,g,f):Va(n,d,q,e,f);V(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,q,h-1,k-1),v=this.bidirectional&&r>f;V(this,l,v?f:r,t,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.T&&Wa(this));return this};function V(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new Q(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.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 Va(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Xa(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length);else if(h>=b)return h>b&&(g=g.slice(0,b)),d?Xa(g):g;e.push(g);b-=h;if(!b)break}if(!e.length)return e;e=1a.length?e?W(a[0],b,c,d):a[0]:Ca(a,c,b,e,f)};X.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];B();let h=ca(a);return h?Ba(a,h,b,c,f,e,d):g};X.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?W(a[0],b,c,d):a[0];d=[];const g=B();let h=0;for(let k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};M.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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else eb(this.map,a),this.depth&&eb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Wa(this));this.cache&&this.cache.remove(a);return this}; -function eb(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; -function fb(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -u.close=function(){this.db.close();this.db=null};u.destroy=function(){return gb.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(hb,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const p=c?d+Math.min(m.length-d,c):m.length;for(let n=d;n=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})}; -u.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let e=0,f;em&&!f&&"string"===typeof p&&!isNaN(p)&&(m=k.indexOf(parseInt(p,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const lb={Index:M,Charset:Ta,Encoder:K,Document:T,Worker:N,Resolver:X,IndexedDB:jb,Language:{}},mb=self;let nb;(nb=mb.define)&&nb.amd?nb([],function(){return lb}):"object"===typeof mb.exports?mb.exports=lb:mb.FlexSearch=lb;}(this||self)); +["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]];const da=/[^\p{L}\p{N}]+/u,ea=/(\d{3})/g,fa=/(\D)(\d{3})/g,ha=/(\d{3})(\D)/g,ia="".normalize&&/[\u0300-\u036f]/g;function L(a){if(!this||this.constructor!==L)return new L(...arguments);for(let b=0;b"a1a".split(c).length; +this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,da)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);ia||(this.mapper=new Map(ca));this.rtl=A(a.rtl,!1,this.rtl);this.dedupe=A(a.dedupe,!1,this.dedupe);this.filter=A((c=a.filter)&&new Set(c),null,this.filter);this.matcher=A((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=A((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= +A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);if(this.cache=c=A(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};t.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&M(this);return this};t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&M(this);return this};t.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&M(this);return this};t.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&M(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(M,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ia?a.normalize("NFKD").replace(ia,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d +this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function M(a){a.H=null;a.B.clear();a.G.clear()};async function ja(a){a=a.data;var b=self._index;const c=a.args;var e=a.task;switch(e){case "init":e=a.options||{};(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new N(e);postMessage({id:a.id});break;default:a=a.id,b=b[e].apply(b,c),postMessage("search"===e?{id:a,msg:b}:{id:a})}};let ka=0; +function O(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ka]=function(){h(d)};d.worker.postMessage({id:ka,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==O)return new O(a);let c="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=la(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}P("add");P("append");P("search");P("update");P("remove"); +function P(a){O.prototype[a]=O.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.splice(c.length-1,1));e=new Promise(function(f){b.h[++ka]=f;b.worker.postMessage({task:a,id:ka,args:c})});return d?(e.then(d),this):e}} +function la(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="+ja.toString()],{type:"text/javascript"}))):new window.Worker(E(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"})};function ma(a){Q.call(a,"add");Q.call(a,"append");Q.call(a,"search");Q.call(a,"update");Q.call(a,"remove")}function Q(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);b=this[a].apply(this,b);e&&(b.then?b.then(e):e(b));return b}};function na(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function oa(a,b){b||(b=new Map);for(let c=0,e;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} +function R(a){if(!this)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;gc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= +p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?V.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Aa(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};W.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Da(this,"and",arguments);return Fa.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; +function Fa(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ba(a))return this.result=za(a,b,c,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};W.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Da(this,"xor",arguments);return Ga.call(this,a,b,c,e,d,f,g)}; +function Ga(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Ha.call(this,a,c,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Ha(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e)a=a.slice(e,e+c);d&&(a=V.call(this,a));return a}} +function V(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +X.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};X.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Qa={normalize:function(a){return a.toLowerCase()},numeric:!1,dedupe:!1};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"],["pf","f"]]),Ta=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\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};const Va=/[\x00-\x7F]+/g;const Wa=/[\x00-\x7F]+/g;const Xa=/[\x00-\x7F]+/g;var Ya={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Qa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ra},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ra,matcher:Sa,replacer:Ta},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ra,replacer:Ta.concat([/(?!^)[aeo]/g,""]),matcher:Sa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):$a(p,e,q,d,f);Y(this,m,g,h,a,c)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;Y(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&ab(this));return this};function Y(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]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new R(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} +function $a(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};N.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else fb(this.map,a),this.depth&&fb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&ab(this));this.cache&&this.cache.remove(a);return this}; +function fb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; +function gb(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +t.close=function(){this.db.close();this.db=null};t.destroy=function(){const a=hb.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(ib,"readwrite");for(let b=0;b=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +t.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{d.onerror=k=>{this.h[a+":"+b]=null;d.abort();d=e=null;g(k)};d.oncomplete=k=>{d=e=this.h[a+":"+b]=null;f(k||!0)};return c.call(this,e)})}; +t.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=h.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const mb={Index:N,Charset:Ya,Encoder:L,Document:U,Worker:O,Resolver:W,IndexedDB:kb,Language:{}},nb=self;let ob;(ob=nb.define)&&ob.amd?ob([],function(){return mb}):"object"===typeof nb.exports?nb.exports=mb:nb.FlexSearch=mb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index 57b9bef..02b8c57 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,19 +1,19 @@ /**! - * FlexSearch.js v0.8.103 (Bundle/Module/Debug) + * FlexSearch.js v0.8.105 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u; -function z(a, b, c) { - const d = typeof c, e = typeof a; - if ("undefined" !== d) { - if ("undefined" !== e) { +var t; +function A(a, b, c) { + const e = typeof c, d = typeof a; + if ("undefined" !== e) { + if ("undefined" !== d) { if (c) { - if ("function" === e && d === e) { - return function(h) { - return a(c(h)); + if ("function" === d && e === d) { + return function(k) { + return a(c(k)); }; } b = a.constructor; @@ -41,21 +41,18 @@ function z(a, b, c) { } return c; } - return "undefined" === e ? b : a; + return "undefined" === d ? b : a; } function B() { return Object.create(null); } -function aa(a, b) { - return b.length - a.length; -} -function G(a) { +function E(a) { return "string" === typeof a; } -function H(a) { +function I(a) { return "object" === typeof a; } -function ba(a) { +function aa(a) { const b = []; for (const c of a.keys()) { b.push(c); @@ -63,7 +60,7 @@ function ba(a) { return b; } function J(a, b) { - if (G(b)) { + if (E(b)) { a = a[b]; } else { for (let c = 0; a && c < b.length; c++) { @@ -72,14 +69,14 @@ function J(a, b) { } return a; } -function ca(a) { +function ba(a) { let b = 0; - for (let c = 0, d; c < a.length; c++) { - (d = a[c]) && b < d.length && (b = d.length); + for (let c = 0, e; c < a.length; c++) { + (e = a[c]) && b < e.length && (b = e.length); } return b; } -;var da = [["\u00aa", "a"], ["\u00b2", "2"], ["\u00b3", "3"], ["\u00b9", "1"], ["\u00ba", "o"], ["\u00bc", "1\u20444"], ["\u00bd", "1\u20442"], ["\u00be", "3\u20444"], ["\u00e0", "a"], ["\u00e1", "a"], ["\u00e2", "a"], ["\u00e3", "a"], ["\u00e4", "a"], ["\u00e5", "a"], ["\u00e7", "c"], ["\u00e8", "e"], ["\u00e9", "e"], ["\u00ea", "e"], ["\u00eb", "e"], ["\u00ec", "i"], ["\u00ed", "i"], ["\u00ee", "i"], ["\u00ef", "i"], ["\u00f1", "n"], ["\u00f2", "o"], ["\u00f3", "o"], ["\u00f4", "o"], ["\u00f5", +;var ca = [["\u00aa", "a"], ["\u00b2", "2"], ["\u00b3", "3"], ["\u00b9", "1"], ["\u00ba", "o"], ["\u00bc", "1\u20444"], ["\u00bd", "1\u20442"], ["\u00be", "3\u20444"], ["\u00e0", "a"], ["\u00e1", "a"], ["\u00e2", "a"], ["\u00e3", "a"], ["\u00e4", "a"], ["\u00e5", "a"], ["\u00e7", "c"], ["\u00e8", "e"], ["\u00e9", "e"], ["\u00ea", "e"], ["\u00eb", "e"], ["\u00ec", "i"], ["\u00ed", "i"], ["\u00ee", "i"], ["\u00ef", "i"], ["\u00f1", "n"], ["\u00f2", "o"], ["\u00f3", "o"], ["\u00f4", "o"], ["\u00f5", "o"], ["\u00f6", "o"], ["\u00f9", "u"], ["\u00fa", "u"], ["\u00fb", "u"], ["\u00fc", "u"], ["\u00fd", "y"], ["\u00ff", "y"], ["\u0101", "a"], ["\u0103", "a"], ["\u0105", "a"], ["\u0107", "c"], ["\u0109", "c"], ["\u010b", "c"], ["\u010d", "c"], ["\u010f", "d"], ["\u0113", "e"], ["\u0115", "e"], ["\u0117", "e"], ["\u0119", "e"], ["\u011b", "e"], ["\u011d", "g"], ["\u011f", "g"], ["\u0121", "g"], ["\u0123", "g"], ["\u0125", "h"], ["\u0129", "i"], ["\u012b", "i"], ["\u012d", "i"], ["\u012f", "i"], ["\u0133", "ij"], ["\u0135", "j"], ["\u0137", "k"], ["\u013a", "l"], ["\u013c", "l"], ["\u013e", "l"], ["\u0140", "l"], ["\u0144", "n"], ["\u0146", "n"], ["\u0148", "n"], ["\u0149", "n"], ["\u014d", "o"], ["\u014f", "o"], ["\u0151", "o"], ["\u0155", "r"], ["\u0157", "r"], ["\u0159", "r"], ["\u015b", "s"], ["\u015d", "s"], ["\u015f", "s"], ["\u0161", "s"], ["\u0163", "t"], ["\u0165", "t"], ["\u0169", "u"], ["\u016b", "u"], ["\u016d", "u"], ["\u016f", "u"], ["\u0171", "u"], ["\u0173", "u"], ["\u0175", "w"], ["\u0177", "y"], ["\u017a", "z"], ["\u017c", "z"], ["\u017e", "z"], ["\u017f", "s"], ["\u01a1", "o"], ["\u01b0", "u"], ["\u01c6", "dz"], ["\u01c9", "lj"], ["\u01cc", "nj"], ["\u01ce", "a"], ["\u01d0", "i"], ["\u01d2", "o"], ["\u01d4", "u"], ["\u01d6", "u"], ["\u01d8", "u"], ["\u01da", "u"], ["\u01dc", "u"], ["\u01df", "a"], ["\u01e1", "a"], ["\u01e3", "ae"], ["\u00e6", "ae"], ["\u01fd", "ae"], ["\u01e7", "g"], ["\u01e9", "k"], ["\u01eb", "o"], ["\u01ed", "o"], ["\u01ef", "\u0292"], ["\u01f0", "j"], ["\u01f3", @@ -87,63 +84,68 @@ function ca(a) { ["\u02b2", "j"], ["\u02b3", "r"], ["\u02b4", "\u0279"], ["\u02b5", "\u027b"], ["\u02b6", "\u0281"], ["\u02b7", "w"], ["\u02b8", "y"], ["\u02e0", "\u0263"], ["\u02e1", "l"], ["\u02e2", "s"], ["\u02e3", "x"], ["\u02e4", "\u0295"], ["\u0390", "\u03b9"], ["\u03ac", "\u03b1"], ["\u03ad", "\u03b5"], ["\u03ae", "\u03b7"], ["\u03af", "\u03b9"], ["\u03b0", "\u03c5"], ["\u03ca", "\u03b9"], ["\u03cb", "\u03c5"], ["\u03cc", "\u03bf"], ["\u03cd", "\u03c5"], ["\u03ce", "\u03c9"], ["\u03d0", "\u03b2"], ["\u03d1", "\u03b8"], ["\u03d2", "\u03a5"], ["\u03d3", "\u03a5"], ["\u03d4", "\u03a5"], ["\u03d5", "\u03c6"], ["\u03d6", "\u03c0"], ["\u03f0", "\u03ba"], ["\u03f1", "\u03c1"], ["\u03f2", "\u03c2"], ["\u03f5", "\u03b5"], ["\u0439", "\u0438"], ["\u0450", "\u0435"], ["\u0451", "\u0435"], ["\u0453", "\u0433"], ["\u0457", "\u0456"], ["\u045c", "\u043a"], ["\u045d", "\u0438"], ["\u045e", "\u0443"], ["\u0477", "\u0475"], ["\u04c2", "\u0436"], ["\u04d1", "\u0430"], ["\u04d3", "\u0430"], ["\u04d7", "\u0435"], ["\u04db", "\u04d9"], ["\u04dd", "\u0436"], ["\u04df", "\u0437"], ["\u04e3", "\u0438"], ["\u04e5", "\u0438"], ["\u04e7", "\u043e"], ["\u04eb", "\u04e9"], ["\u04ed", "\u044d"], ["\u04ef", "\u0443"], ["\u04f1", "\u0443"], ["\u04f3", "\u0443"], ["\u04f5", "\u0447"]]; -const ea = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = "".normalize && /[\u0300-\u036f]/g; -function K(a) { - if (!this || this.constructor !== K) { - return new K(...arguments); +const da = /[^\p{L}\p{N}]+/u, ea = /(\d{3})/g, fa = /(\D)(\d{3})/g, ha = /(\d{3})(\D)/g, ia = "".normalize && /[\u0300-\u036f]/g; +function L(a) { + if (!this || this.constructor !== L) { + return new L(...arguments); } for (let b = 0; b < arguments.length; b++) { this.assign(arguments[b]); } } -u = K.prototype; -u.assign = function(a) { - this.normalize = z(a.normalize, !0, this.normalize); - let b = a.include, c = b || a.exclude || a.split; - if ("object" === typeof c) { - let d = !b, e = ""; - a.include || (e += "\\p{Z}"); - c.letter && (e += "\\p{L}"); - c.number && (e += "\\p{N}", d = !!b); - c.symbol && (e += "\\p{S}"); - c.punctuation && (e += "\\p{P}"); - c.control && (e += "\\p{C}"); - if (c = c.char) { - e += "object" === typeof c ? c.join("") : c; +t = L.prototype; +t.assign = function(a) { + this.normalize = A(a.normalize, !0, this.normalize); + let b = a.include, c = b || a.exclude || a.split, e; + if (c || "" === c) { + if ("object" === typeof c && c.constructor !== RegExp) { + let d = ""; + e = !b; + b || (d += "\\p{Z}"); + c.letter && (d += "\\p{L}"); + c.number && (d += "\\p{N}", e = !!b); + c.symbol && (d += "\\p{S}"); + c.punctuation && (d += "\\p{P}"); + c.control && (d += "\\p{C}"); + if (c = c.char) { + d += "object" === typeof c ? c.join("") : c; + } + try { + this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); + } catch (f) { + console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; + } + } else { + this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } - try { - this.split = new RegExp("[" + (b ? "^" : "") + e + "]+", "u"); - } catch (f) { - this.split = /\s+/; - } - this.numeric = d; + this.numeric = A(a.numeric, e); } else { try { - this.split = z(c, ea, this.split); + this.split = A(this.split, da); } catch (d) { - this.split = /\s+/; + console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = z(this.numeric, !0); + this.numeric = A(a.numeric, A(this.numeric, !0)); } - this.prepare = z(a.prepare, null, this.prepare); - this.finalize = z(a.finalize, null, this.finalize); - ja || (this.mapper = new Map(da)); - this.rtl = a.rtl || !1; - this.dedupe = z(a.dedupe, !1, this.dedupe); - this.filter = z((c = a.filter) && new Set(c), null, this.filter); - this.matcher = z((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = z((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = z((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = z(a.replacer, null, this.replacer); - this.minlength = z(a.minlength, 1, this.minlength); - this.maxlength = z(a.maxlength, 0, this.maxlength); - if (this.cache = c = z(a.cache, !0, this.cache)) { - this.L = null, this.S = "number" === typeof c ? c : 2e5, this.H = new Map(), this.I = new Map(), this.M = this.B = 128; + this.prepare = A(a.prepare, null, this.prepare); + this.finalize = A(a.finalize, null, this.finalize); + ia || (this.mapper = new Map(ca)); + this.rtl = A(a.rtl, !1, this.rtl); + this.dedupe = A(a.dedupe, !1, this.dedupe); + this.filter = A((c = a.filter) && new Set(c), null, this.filter); + this.matcher = A((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = A((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = A((c = a.stemmer) && new Map(c), null, this.stemmer); + this.replacer = A(a.replacer, null, this.replacer); + this.minlength = A(a.minlength, 1, this.minlength); + this.maxlength = A(a.maxlength, 0, this.maxlength); + if (this.cache = c = A(a.cache, !0, this.cache)) { + this.H = null, this.S = "number" === typeof c ? c : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; - this.N = null; + this.M = null; this.A = ""; - this.O = null; + this.N = null; if (this.matcher) { for (const d of this.matcher.keys()) { this.h += (this.h ? "|" : "") + d; @@ -156,35 +158,21 @@ u.assign = function(a) { } return this; }; -u.addMatcher = function(a, b) { - if ("object" === typeof a) { - return this.addReplacer(a, b); - } - if (2 > a.length) { - 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 && L(this); - return this; -}; -u.addStemmer = function(a, b) { +t.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 && L(this); + this.N = null; + this.cache && M(this); return this; }; -u.addFilter = function(a) { +t.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); - this.cache && L(this); + this.cache && M(this); return this; }; -u.addMapper = function(a, b) { +t.addMapper = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -193,411 +181,416 @@ u.addMapper = function(a, b) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, b); - this.cache && L(this); + this.cache && M(this); return this; }; -u.addReplacer = function(a, b) { - "string" === typeof a && (a = new RegExp(a, "g")); +t.addMatcher = function(a, b) { + if ("object" === typeof a) { + return this.addReplacer(a, b); + } + if (2 > a.length && (this.dedupe || this.mapper)) { + return this.addMapper(a, b); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(a, b); + this.h += (this.h ? "|" : "") + a; + this.M = null; + this.cache && M(this); + return this; +}; +t.addReplacer = function(a, b) { + if ("string" === typeof a) { + return this.addMatcher(a, b); + } this.replacer || (this.replacer = []); - this.replacer.push(a, b || ""); - this.cache && L(this); + this.replacer.push(a, b); + this.cache && M(this); return this; }; -function L(a) { - a.H.clear(); - a.I.clear(); -} -u.encode = function(a) { - if (this.cache && a.length <= this.B) { - if (this.L) { - if (this.H.has(a)) { - return this.H.get(a); +t.encode = function(a) { + if (this.cache && a.length <= this.K) { + if (this.H) { + if (this.B.has(a)) { + return this.B.get(a); } } else { - this.L = setTimeout(ka, 50, this); + this.H = setTimeout(M, 50, this); } } - this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ia ? a.normalize("NFKD").replace(ia, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(fa, "$1 $2").replace(ha, "$1 $2").replace(ea, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let c = [], d = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, h; f < d.length; f++) { - if (!(g = h = d[f])) { - continue; - } - if (g.length < this.minlength) { - continue; - } - if (b) { - c.push(g); - continue; - } - if (this.filter && this.filter.has(g)) { - continue; - } - if (this.cache && g.length <= this.M) { - if (this.L) { - var e = this.I.get(g); - if (e || "" === e) { - e && c.push(e); - continue; - } + let c = [], e = this.split || "" === this.split ? a.split(this.split) : a; + for (let f = 0, g, k; f < e.length; f++) { + if ((g = k = e[f]) && !(g.length < this.minlength)) { + if (b) { + c.push(g); } else { - this.L = setTimeout(ka, 50, this); + if (!this.filter || !this.filter.has(g)) { + if (this.cache && g.length <= this.L) { + if (this.H) { + var d = this.G.get(g); + if (d || "" === d) { + d && c.push(d); + continue; + } + } else { + this.H = setTimeout(M, 50, this); + } + } + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + if (g && (this.mapper || this.dedupe && 1 < g.length)) { + d = ""; + for (let h = 0, l = "", m, n; h < g.length; h++) { + m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + } + g = d; + } + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); + if (g && this.replacer) { + for (d = 0; g && d < this.replacer.length; d += 2) { + g = g.replace(this.replacer[d], this.replacer[d + 1]); + } + } + this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); + g && c.push(g); + } } } - let k; - this.stemmer && 2 < g.length && (this.O || (this.O = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.O, l => this.stemmer.get(l)), k = 1); - g && k && (g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); - if (g && (this.mapper || this.dedupe && 1 < g.length)) { - e = ""; - for (let l = 0, m = "", q, n; l < g.length; l++) { - q = g.charAt(l), q === m && this.dedupe || ((n = this.mapper && this.mapper.get(q)) || "" === n ? n === m && this.dedupe || !(m = n) || (e += n) : e += m = q); - } - g = e; - } - this.matcher && 1 < g.length && (this.N || (this.N = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.N, l => this.matcher.get(l))); - if (g && this.replacer) { - for (e = 0; g && e < this.replacer.length; e += 2) { - g = g.replace(this.replacer[e], this.replacer[e + 1]); - } - } - this.cache && h.length <= this.M && (this.I.set(h, g), this.I.size > this.S && (this.I.clear(), this.M = this.M / 1.1 | 0)); - g && c.push(g); } this.finalize && (c = this.finalize(c) || c); - this.cache && a.length <= this.B && (this.H.set(a, c), this.H.size > this.S && (this.H.clear(), this.B = this.B / 1.1 | 0)); + this.cache && a.length <= this.K && (this.B.set(a, c), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); return c; }; -function ka(a) { - a.L = null; - a.H.clear(); - a.I.clear(); +function M(a) { + a.H = null; + a.B.clear(); + a.G.clear(); } -;async function la(a) { +;async function ja(a) { a = a.data; var b = self._index; const c = a.args; - var d = a.task; - switch(d) { + var e = a.task; + switch(e) { case "init": - d = a.options || {}; - (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(d), delete self.FlexSearch) : self._index = new M(d); + e = a.options || {}; + (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new N(e); postMessage({id:a.id}); break; default: - a = a.id, b = b[d].apply(b, c), postMessage("search" === d ? {id:a, msg:b} : {id:a}); + a = a.id, b = b[e].apply(b, c), postMessage("search" === e ? {id:a, msg:b} : {id:a}); } } -;let ma = 0; -function N(a = {}) { +;let ka = 0; +function O(a = {}) { function b(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && e.h[l]; - m && (m(k.msg), delete e.h[l]); + function k(h) { + h = h.data || h; + const l = h.id, m = l && d.h[l]; + m && (m(h.msg), delete d.h[l]); } this.worker = g; this.h = B(); if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { - e.h[++ma] = function() { - k(e); + return new Promise(function(h) { + d.h[++ka] = function() { + h(d); }; - e.worker.postMessage({id:ma, task:"init", factory:c, options:a}); + d.worker.postMessage({id:ka, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); return this; } } - if (!this || this.constructor !== N) { - return new N(a); + if (!this || this.constructor !== O) { + return new O(a); } let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - const d = "undefined" === typeof window, e = this, f = na(c, d, a.worker); + const e = "undefined" === typeof window, d = this, f = la(c, e, a.worker); return f.then ? f.then(function(g) { - return b.call(e, g); + return b.call(d, g); }) : b.call(this, f); } -O("add"); -O("append"); -O("search"); -O("update"); -O("remove"); -function O(a) { - N.prototype[a] = N.prototype[a + "Async"] = async function() { +P("add"); +P("append"); +P("search"); +P("update"); +P("remove"); +function P(a) { + O.prototype[a] = O.prototype[a + "Async"] = async function() { const b = this, c = [].slice.call(arguments); - var d = c[c.length - 1]; - let e; - "function" === typeof d && (e = d, c.splice(c.length - 1, 1)); - d = new Promise(function(f) { - b.h[++ma] = f; - b.worker.postMessage({task:a, id:ma, args:c}); + var e = c[c.length - 1]; + let d; + "function" === typeof e && (d = e, c.splice(c.length - 1, 1)); + e = new Promise(function(f) { + b.h[++ka] = f; + b.worker.postMessage({task:a, id:ka, args:c}); }); - return e ? (d.then(e), this) : d; + return d ? (e.then(d), this) : e; }; } -function na(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"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + la.toString()], {type:"text/javascript"}))) : new window.Worker(G(c) ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function la(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"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ja.toString()], {type:"text/javascript"}))) : new window.Worker(E(c) ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;function oa(a) { - P.call(a, "add"); - P.call(a, "append"); - P.call(a, "search"); - P.call(a, "update"); - P.call(a, "remove"); +;function ma(a) { + Q.call(a, "add"); + Q.call(a, "append"); + Q.call(a, "search"); + Q.call(a, "update"); + Q.call(a, "remove"); } -function P(a) { +function Q(a) { this[a + "Async"] = function() { var b = arguments; const c = b[b.length - 1]; - let d; - "function" === typeof c && (d = c, delete b[b.length - 1]); + let e; + "function" === typeof c && (e = c, delete b[b.length - 1]); b = this[a].apply(this, b); - d && (b.then ? b.then(d) : d(b)); + e && (b.then ? b.then(e) : e(b)); return b; }; } -;function pa(a, b = 0) { - let c = [], d = []; +;function na(a, b = 0) { + let c = [], e = []; b && (b = 250000 / b * 5000 | 0); - for (const e of a.entries()) { - d.push(e), d.length === b && (c.push(d), d = []); + for (const d of a.entries()) { + e.push(d), e.length === b && (c.push(e), e = []); } - d.length && c.push(d); + e.length && c.push(e); + return c; +} +function oa(a, b) { + b || (b = new Map()); + for (let c = 0, e; c < a.length; c++) { + e = a[c], b.set(e[0], e[1]); + } + return b; +} +function pa(a, b = 0) { + let c = [], e = []; + b && (b = 250000 / b * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], na(d[1])[0]]), e.length === b && (c.push(e), e = []); + } + e.length && c.push(e); return c; } function qa(a, b) { b || (b = new Map()); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b.set(d[0], d[1]); + for (let c = 0, e, d; c < a.length; c++) { + e = a[c], d = b.get(e[0]), b.set(e[0], oa(e[1], d)); } return b; } -function ra(a, b = 0) { - let c = [], d = []; - b && (b = 250000 / b * 1000 | 0); - for (const e of a.entries()) { - d.push([e[0], pa(e[1])[0]]), d.length === b && (c.push(d), d = []); - } - d.length && c.push(d); - return c; -} -function sa(a, b) { - b || (b = new Map()); - for (let c = 0, d, e; c < a.length; c++) { - d = a[c], e = b.get(d[0]), b.set(d[0], qa(d[1], e)); - } - return b; -} -function ta(a) { +function ra(a) { let b = [], c = []; - for (const d of a.keys()) { - c.push(d), 250000 === c.length && (b.push(c), c = []); + for (const e of a.keys()) { + c.push(e), 250000 === c.length && (b.push(c), c = []); } c.length && b.push(c); return b; } -function ua(a, b) { +function sa(a, b) { b || (b = new Set()); for (let c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function va(a, b, c, d, e, f, g = 0) { - const h = d && d.constructor === Array; - var k = h ? d.shift() : d; - if (!k) { - return this.export(a, b, e, f + 1); +function ta(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((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((h = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return va.call(l, a, b, c, h ? d : null, e, f, g + 1); + return h.then(function() { + return ta.call(l, a, b, c, k ? e : null, d, f, g + 1); }); } - return va.call(this, a, b, c, h ? d : null, e, f, g + 1); + return ta.call(this, a, b, c, k ? e : null, d, f, g + 1); } -;function wa(a, b, c, d) { - let e = []; +;function ua(a, b, c, e) { + let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { b -= g.length; } else { - b = g[d ? "splice" : "slice"](b, c); - const h = b.length; - if (h && (e = e.length ? e.concat(b) : b, c -= h, d && (a.length -= h), !c)) { + b = g[e ? "splice" : "slice"](b, c); + const k = b.length; + if (k && (d = d.length ? d.concat(b) : b, c -= k, e && (a.length -= k), !c)) { break; } b = 0; } } - return e; + return d; } -function Q(a) { +function R(a) { if (!this) { - return new Q(a); + return new R(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; const b = this; - return new Proxy([], {get(c, d) { - if ("length" === d) { + return new Proxy([], {get(c, e) { + if ("length" === e) { return b.length; } - if ("push" === d) { - return function(e) { - b.index[b.index.length - 1].push(e); + if ("push" === e) { + return function(d) { + b.index[b.index.length - 1].push(d); b.length++; }; } - if ("pop" === d) { + if ("pop" === e) { return function() { if (b.length) { return b.length--, b.index[b.index.length - 1].pop(); } }; } - if ("indexOf" === d) { - return function(e) { + if ("indexOf" === e) { + return function(d) { let f = 0; - for (let g = 0, h, k; g < b.index.length; g++) { - h = b.index[g]; - k = h.indexOf(e); - 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" === d) { - return function(e) { + if ("includes" === e) { + return function(d) { for (let f = 0; f < b.index.length; f++) { - if (b.index[f].includes(e)) { + if (b.index[f].includes(d)) { return !0; } } return !1; }; } - if ("slice" === d) { - return function(e, f) { - return wa(b, e || 0, f || b.length, !1); + if ("slice" === e) { + return function(d, f) { + return ua(b, d || 0, f || b.length, !1); }; } - if ("splice" === d) { - return function(e, f) { - return wa(b, e || 0, f || b.length, !0); + if ("splice" === e) { + return function(d, f) { + return ua(b, d || 0, f || b.length, !0); }; } - if ("constructor" === d) { + if ("constructor" === e) { return Array; } - if ("symbol" !== typeof d) { - return (c = b.index[d / 2 ** 31 | 0]) && c[d]; + if ("symbol" !== typeof e) { + return (c = b.index[e / 2 ** 31 | 0]) && c[e]; } - }, set(c, d, e) { - c = d / 2 ** 31 | 0; - (b.index[c] || (b.index[c] = []))[d] = e; + }, set(c, e, d) { + c = e / 2 ** 31 | 0; + (b.index[c] || (b.index[c] = []))[e] = d; b.length++; return !0; }}); } -Q.prototype.clear = function() { +R.prototype.clear = function() { this.index.length = 0; }; -Q.prototype.destroy = function() { +R.prototype.destroy = function() { this.proxy = this.index = null; }; -Q.prototype.push = function() { -}; -function R(a = 8) { - if (!this) { - return new R(a); - } - this.index = B(); - this.B = []; - this.size = 0; - 32 < a ? (this.h = xa, this.A = BigInt(a)) : (this.h = ya, this.A = a); -} -R.prototype.get = function(a) { - const b = this.index[this.h(a)]; - return b && b.get(a); -}; -R.prototype.set = function(a, b) { - var c = this.h(a); - let d = this.index[c]; - d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.B.push(d)); +R.prototype.push = function() { }; function S(a = 8) { if (!this) { return new S(a); } this.index = B(); - this.h = []; - 32 < a ? (this.B = xa, this.A = BigInt(a)) : (this.B = ya, this.A = a); + this.B = []; + this.size = 0; + 32 < a ? (this.h = va, this.A = BigInt(a)) : (this.h = wa, this.A = a); } -S.prototype.add = function(a) { +S.prototype.get = function(a) { + const b = this.index[this.h(a)]; + return b && b.get(a); +}; +S.prototype.set = function(a, b) { + var c = this.h(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.B.push(e)); +}; +function T(a = 8) { + if (!this) { + return new T(a); + } + this.index = B(); + this.h = []; + 32 < a ? (this.B = va, this.A = BigInt(a)) : (this.B = wa, this.A = a); +} +T.prototype.add = function(a) { var b = this.B(a); let c = this.index[b]; c ? (b = c.size, c.add(a), (b -= c.size) && this.size++) : (this.index[b] = c = new Set([a]), this.h.push(c)); }; -u = R.prototype; -u.has = S.prototype.has = function(a) { +t = S.prototype; +t.has = T.prototype.has = function(a) { const b = this.index[this.B(a)]; return b && b.has(a); }; -u.delete = S.prototype.delete = function(a) { +t.delete = T.prototype.delete = function(a) { const b = this.index[this.B(a)]; b && b.delete(a) && this.size--; }; -u.clear = S.prototype.clear = function() { +t.clear = T.prototype.clear = function() { this.index = B(); this.h = []; this.size = 0; }; -u.values = S.prototype.values = function*() { +t.values = T.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].values()) { yield b; } } }; -u.keys = S.prototype.keys = function*() { +t.keys = T.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].keys()) { yield b; } } }; -u.entries = S.prototype.entries = function*() { +t.entries = T.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].entries()) { yield b; } } }; -function ya(a) { +function wa(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; } - let c = 0, d = this.A + 1; - for (let e = 0; e < a.length; e++) { - c = (c * d ^ a.charCodeAt(e)) & b; + let c = 0, e = this.A + 1; + for (let d = 0; d < a.length; d++) { + c = (c * e ^ a.charCodeAt(d)) & b; } return 32 === this.A ? c + 2 ** 31 : c; } -function xa(a) { +function va(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -607,76 +600,76 @@ function xa(a) { return BigInt(a) & b; } c = BigInt(0); - let d = this.A + BigInt(1); - for (let e = 0; e < a.length; e++) { - c = (c * d ^ BigInt(a.charCodeAt(e))) & b; + let e = this.A + BigInt(1); + for (let d = 0; d < a.length; d++) { + c = (c * e ^ BigInt(a.charCodeAt(d))) & b; } return c; } -;T.prototype.add = function(a, b, c) { - H(a) && (b = a, a = J(b, this.key)); +;U.prototype.add = function(a, b, c) { + I(a) && (b = a, a = J(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.D[h]; - var d = this.index.get(this.field[h]); - if ("function" === typeof k) { - var e = k(b); - e && d.add(a, e, !1, !0); + for (let k = 0, h; k < this.field.length; k++) { + h = this.D[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 (e = k.J, !e || e(b)) { - k.constructor === String ? k = ["" + k] : G(k) && (k = [k]), za(b, k, this.K, 0, d, a, k[0], c); + if (d = h.I, !d || d(b)) { + h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), xa(b, h, this.J, 0, e, a, h[0], c); } } } if (this.tag) { - for (d = 0; d < this.G.length; d++) { - var f = this.G[d], g = this.P[d]; - e = this.tag.get(g); - let h = B(); + for (e = 0; e < this.F.length; e++) { + var f = this.F[e], g = this.R[e]; + d = this.tag.get(g); + let k = B(); if ("function" === typeof f) { if (f = f(b), !f) { continue; } } else { - const k = f.J; - if (k && !k(b)) { + const h = f.I; + if (h && !h(b)) { continue; } f.constructor === String && (f = "" + f); f = J(b, f); } - if (e && f) { - G(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - if (l = f[k], !h[l] && (h[l] = 1, (g = e.get(l)) ? m = g : e.set(l, m = []), !c || !m.includes(a))) { + if (d && f) { + E(f) && (f = [f]); + for (let h = 0, l, m; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !c || !m.includes(a))) { if (m.length === 2 ** 31 - 1) { - g = new Q(m); + g = new R(m); if (this.fastupdate) { - for (let q of this.reg.values()) { - q.includes(m) && (q[q.indexOf(m)] = g); + for (let n of this.reg.values()) { + n.includes(m) && (n[n.indexOf(m)] = g); } } - e.set(l, m = g); + d.set(l, m = g); } m.push(a); this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); } } } else { - e || console.warn("Tag '" + g + "' was not found"); + d || console.warn("Tag '" + g + "' was not found"); } } } if (this.store && (!c || !this.store.has(a))) { - let h; + let k; if (this.C) { - h = B(); - for (let k = 0, l; k < this.C.length; k++) { - l = this.C[k]; - if ((c = l.J) && !c(b)) { + k = B(); + for (let h = 0, l; h < this.C.length; h++) { + l = this.C[h]; + if ((c = l.I) && !c(b)) { continue; } let m; @@ -685,140 +678,142 @@ function xa(a) { if (!m) { continue; } - l = [l.U]; - } else if (G(l) || l.constructor === String) { - h[l] = b[l]; + l = [l.V]; + } else if (E(l) || l.constructor === String) { + k[l] = b[l]; continue; } - Aa(b, h, l, 0, l[0], m); + ya(b, k, l, 0, l[0], m); } } - this.store.set(a, h || b); + this.store.set(a, k || b); } } return this; }; -function Aa(a, b, c, d, e, f) { - a = a[e]; - if (d === c.length - 1) { - b[e] = f || a; +function ya(a, b, c, e, d, f) { + a = a[d]; + if (e === c.length - 1) { + b[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - Aa(a, b, c, d, e); + for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { + ya(a, b, c, e, d); } } else { - b = b[e] || (b[e] = B()), e = c[++d], Aa(a, b, c, d, e); + b = b[d] || (b[d] = B()), d = c[++e], ya(a, b, c, e, d); } } } -function za(a, b, c, d, e, f, g, h) { +function xa(a, b, c, e, d, f, g, k) { if (a = a[g]) { - if (d === b.length - 1) { + if (e === b.length - 1) { if (a.constructor === Array) { - if (c[d]) { + if (c[e]) { for (b = 0; b < a.length; b++) { - e.add(f, a[b], !0, !0); + d.add(f, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - za(a, b, c, d, e, f, g, h); + xa(a, b, c, e, d, f, g, k); } } else { - g = b[++d], za(a, b, c, d, e, f, g, h); + g = b[++e], xa(a, b, c, e, d, f, g, k); } } } else { - e.db && e.remove(f); + d.db && d.remove(f); } } -;function Ba(a, b, c, d, e, f, g) { - const h = a.length; - let k = [], l; +;function za(a, b, c, e, d, f, g) { + const k = a.length; + let h = [], l; var m; l = B(); - for (let q = 0, n, p, r, t; q < b; q++) { - for (let v = 0; v < h; v++) { - if (r = a[v], q < r.length && (n = r[q])) { - for (let x = 0; x < n.length; x++) { - p = n[x], (m = l[p]) ? l[p]++ : (m = 0, l[p] = 1), t = k[m] || (k[m] = []), g || (m = q + (v ? 0 : f || 0), t = t[m] || (t[m] = [])), t.push(p); + for (let n = 0, p, q, r, u; n < b; n++) { + for (let v = 0; v < k; v++) { + if (r = a[v], n < r.length && (p = r[n])) { + for (let x = 0; x < p.length; x++) { + q = p[x], (m = l[q]) ? l[q]++ : (m = 0, l[q] = 1), u = h[m] || (h[m] = []), g || (m = n + (v || !d ? 0 : f || 0), u = u[m] || (u[m] = [])), u.push(q); } } } } - if (a = k.length) { - if (e) { - k = 1 < k.length ? Ca(k, d, c, g, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + if (a = h.length) { + if (d) { + h = 1 < h.length ? Aa(h, c, e, g, f) : (h = h[0]).length > c || e ? h.slice(e, c + e) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; - if (c || d) { + h = h[a - 1]; + if (c || e) { if (g) { - if (k.length > c || d) { - k = k.slice(d, c + d); + if (h.length > c || e) { + h = h.slice(e, c + e); } } else { - e = []; - for (let q = 0, n; q < k.length; q++) { - if (n = k[q], n.length > d) { - d -= n.length; + d = []; + for (let n = 0, p; n < h.length; n++) { + if (p = h[n], p.length > e) { + e -= p.length; } else { - if (n.length > c || d) { - n = n.slice(d, c + d), c -= n.length, d && (d -= n.length); + if (p.length > c || e) { + p = p.slice(e, c + e), c -= p.length, e && (e -= p.length); } - e.push(n); + d.push(p); if (!c) { break; } } } - k = 1 < e.length ? [].concat.apply([], e) : e[0]; + h = 1 < d.length ? [].concat.apply([], d) : d[0]; } } } } - return k; + return h; } -function Ca(a, b, c, d, e) { +function Aa(a, b, c, e, d) { const f = [], g = B(); - let h; - var k = a.length; - let l, m = 0; - if (d) { - for (e = k - 1; 0 <= e; e--) { - for (d = a[e], l = d.length, k = 0; k < l; k++) { - if (h = d[k], !g[h]) { - if (g[h] = 1, b) { - b--; - } else { - if (f.push(h), f.length === c) { - return f; + let k; + var h = a.length; + let l; + if (e) { + for (d = h - 1; 0 <= d; d--) { + if (l = (e = a[d]) && e.length) { + for (h = 0; h < l; h++) { + if (k = e[h], !g[k]) { + if (g[k] = 1, c) { + c--; + } else { + if (f.push(k), f.length === b) { + return f; + } } } } } } } else { - let q = ca(a); - for (let n = 0; n < q; n++) { - for (let p = k - 1; 0 <= p; p--) { - if (l = (d = a[p][n]) && d.length) { + for (let m = h - 1, n, p = 0; 0 <= m; m--) { + n = a[m]; + for (let q = 0; q < n.length; q++) { + if (l = (e = n[q]) && e.length) { for (let r = 0; r < l; r++) { - if (h = d[r], !g[h]) { - if (g[h] = 1, b) { - b--; + if (k = e[r], !g[k]) { + if (g[k] = 1, c) { + c--; } else { - let t = n + (p < k - 1 ? e || 0 : 0); - (f[t] || (f[t] = [])).push(h); - if (++m === c) { + let u = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[u] || (f[u] = [])).push(k); + if (++p === b) { return f; } } @@ -830,443 +825,764 @@ function Ca(a, b, c, d, e) { } return f; } -function Da(a, b) { - const c = B(), d = []; - for (let e = 0, f; e < b.length; e++) { - f = b[e]; - for (let g = 0; g < f.length; g++) { - c[f[g]] = 1; +function Ba(a, b, c) { + const e = B(), d = []; + for (let f = 0, g; f < b.length; f++) { + g = b[f]; + for (let k = 0; k < g.length; k++) { + e[g[k]] = 1; } } - for (let e = 0, f; e < a.length; e++) { - f = a[e], 1 === c[f] && (d.push(f), c[f] = 2); + 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, 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; } -;T.prototype.search = function(a, b, c, d) { - c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); - let e = [], f = [], g; - let h; +;function Ca(a, b, c, e) { + if (!a.length) { + return a; + } + if (1 === a.length) { + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, e ? V.call(this, a) : a; + } + let d = []; + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { + if (c) { + if (c >= k) { + c -= k; + continue; + } + c < k && (g = b ? g.slice(c, c + b) : g.slice(c), k = g.length, c = 0); + } + k > b && (g = g.slice(0, b), k = b); + if (!d.length && k >= b) { + return e ? V.call(this, g) : g; + } + d.push(g); + b -= k; + if (!b) { + break; + } + } + } + d = 1 < d.length ? [].concat.apply([], d) : d[0]; + return e ? V.call(this, d) : d; +} +;function Da(a, b, c) { + var e = c[0]; + if (e.then) { + return Promise.all(c).then(function(m) { + return a[b].apply(a, m); + }); + } + if (e[0] && e[0].index) { + return a[b].apply(a, e); + } + e = []; + let d = [], f = 0, g = 0, k, h, l; + for (let m = 0, n; m < c.length; m++) { + if (n = c[m]) { + let p; + if (n.constructor === W) { + p = n.result; + } else if (n.constructor === Array) { + p = n; + } else { + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { + n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = h, n.enrich = k; + } else if (n.and) { + p = a.and(n.and); + } else if (n.or) { + p = a.or(n.or); + } else if (n.xor) { + p = a.xor(n.xor); + } else if (n.not) { + p = a.not(n.not); + } else { + continue; + } + } + if (p.then) { + d.push(p); + } else if (p.length) { + e[m] = p; + } else if (!l && ("and" === b || "xor" === b)) { + e = []; + break; + } + } + } + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; +} +;W.prototype.or = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f} = Da(this, "or", arguments); + return Ea.call(this, a, b, c, e, d, f); +}; +function Ea(a, b, c, e, d, f) { + if (b.length) { + const g = this; + return Promise.all(b).then(function(k) { + a = []; + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); + } + return Ea.call(g, a, [], c, e, d, f); + }); + } + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Aa(a, c, e, !1, this.h), e = 0)); + return f ? this.resolve(c, e, d) : this; +} +;W.prototype.and = function() { + let a = this.result.length, b, c, e, d; + if (!a) { + const f = arguments[0]; + f && (a = !!f.suggest, d = f.resolve, b = f.limit, c = f.offset, e = f.enrich && d); + } + if (a) { + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Da(this, "and", arguments); + return Fa.call(this, f, g, k, h, l, m, n); + } + return d ? this.resolve(b, c, e) : this; +}; +function Fa(a, b, c, e, d, f, g) { + if (b.length) { + const k = this; + return Promise.all(b).then(function(h) { + a = []; + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Fa.call(k, a, [], c, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + if (b = ba(a)) { + return this.result = za(a, b, c, e, g, this.h, f), f ? d ? V.call(this.index, this.result) : this.result : this; + } + this.result = []; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(c, e, d) : this; +} +;W.prototype.xor = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Da(this, "xor", arguments); + return Ga.call(this, a, b, c, e, d, f, g); +}; +function Ga(a, b, c, e, d, f, g) { + if (b.length) { + const k = this; + return Promise.all(b).then(function(h) { + a = []; + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Ga.call(k, a, [], c, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = Ha.call(this, a, c, e, f, this.h), f ? d ? V.call(this.index, this.result) : this.result : this; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(c, e, d) : this; +} +function Ha(a, b, c, e, d) { + const f = [], g = B(); + let k = 0; + for (let h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); + for (let m = 0, n; m < l.length; m++) { + if (n = l[m]) { + for (let p = 0, q; p < n.length; p++) { + q = n[p], g[q] = g[q] ? 2 : 1; + } + } + } + } + } + for (let h = 0, l, m = 0; h < k; h++) { + for (let n = 0, p; n < a.length; n++) { + if (p = a[n]) { + if (l = p[h]) { + for (let q = 0, r; q < l.length; q++) { + if (r = l[q], 1 === g[r]) { + if (c) { + c--; + } else { + if (e) { + if (f.push(r), f.length === b) { + return f; + } + } else { + const u = h + (n ? d : 0); + f[u] || (f[u] = []); + f[u].push(r); + if (++m === b) { + return f; + } + } + } + } + } + } + } + } + } + return f; +} +;W.prototype.not = function() { + const {O:a, P:b, limit:c, offset:e, enrich:d, resolve:f, suggest:g} = Da(this, "not", arguments); + return Ia.call(this, a, b, c, e, d, f, g); +}; +function Ia(a, b, c, e, d, f, g) { + if (b.length) { + const k = this; + return Promise.all(b).then(function(h) { + a = []; + for (let l = 0, m; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); + } + return Ia.call(k, a, [], c, e, d, f, g); + }); + } + if (a.length && this.result.length) { + this.result = Ja.call(this, a, c, e, f); + } else if (f) { + return this.resolve(c, e, d); + } + return f ? d ? V.call(this.index, this.result) : this.result : this; +} +function Ja(a, b, c, e) { + const d = []; + a = new Set(a.flat().flat()); + for (let f = 0, g, k = 0; f < this.result.length; f++) { + if (g = this.result[f]) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { + if (c) { + c--; + } else { + if (e) { + if (d.push(l), d.length === b) { + return d; + } + } else { + if (d[f] || (d[f] = []), d[f].push(l), ++k === b) { + return d; + } + } + } + } + } + } + } + return d; +} +;function W(a) { + if (!this || this.constructor !== W) { + return new W(a); + } + if (a && a.index) { + return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; + } + this.index = null; + this.result = a || []; + this.h = 0; +} +W.prototype.limit = function(a) { + if (this.result.length) { + const b = []; + let c = 0; + for (let e = 0, d; e < this.result.length; e++) { + if (d = this.result[e], d.length + c < a) { + b[e] = d, c += d.length; + } else { + b[e] = d.slice(0, a - c); + this.result = b; + break; + } + } + } + return this; +}; +W.prototype.offset = function(a) { + if (this.result.length) { + const b = []; + let c = 0; + for (let e = 0, d; e < this.result.length; e++) { + d = this.result[e], d.length + c < a ? c += d.length : (b[e] = d.slice(a - c), c = a); + } + this.result = b; + } + return this; +}; +W.prototype.boost = function(a) { + this.h += a; + return this; +}; +W.prototype.resolve = function(a, b, c) { + const e = this.result, d = this.index; + this.result = this.index = null; + return e.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), Ca.call(d, e, a || 100, b, c)) : e; +}; +B(); +U.prototype.search = function(a, b, c, e) { + c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); + let d = [], f = [], g; let k; - let l, m = 0, q; + let h; + let l, m = 0; + let n; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; g = c.pluck; - h = c.merge; - k = g || c.field || c.index; - var n = this.tag && c.tag; - var p = this.store && c.enrich; - var r = c.suggest; - q = c.highlight; + k = c.merge; + h = g || c.field || (h = c.index) && (h.index ? null : h); + var p = this.tag && c.tag; + var q = c.suggest; + var r = !1 !== c.resolve; + if (!r && !g) { + if (h = h || this.field) { + E(h) ? g = h : (h.constructor === Array && 1 === h.length && (h = h[0]), g = h.field || h.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."); + } + } + this.store && c.enrich && !r && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var u = this.store && c.enrich && r; + n = c.highlight && u; b = c.limit || b; l = c.offset || 0; b || (b = 100); - if (n && (!this.db || !d)) { - n.constructor !== Array && (n = [n]); - var t = []; - for (let y = 0, w; y < n.length; y++) { - w = n[y]; - if (G(w)) { + if (p && (!this.db || !e)) { + p.constructor !== Array && (p = [p]); + var v = []; + for (let z = 0, w; z < p.length; z++) { + w = p[z]; + if (E(w)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (w.field && w.tag) { - var v = w.tag; - if (v.constructor === Array) { - for (var x = 0; x < v.length; x++) { - t.push(w.field, v[x]); + var x = w.tag; + if (x.constructor === Array) { + for (var y = 0; y < x.length; y++) { + v.push(w.field, x[y]); } } else { - t.push(w.field, v); + v.push(w.field, x); } } else { - v = Object.keys(w); - for (let A = 0, I, C; A < v.length; A++) { - if (I = v[A], C = w[I], C.constructor === Array) { - for (x = 0; x < C.length; x++) { - t.push(I, C[x]); + x = Object.keys(w); + for (let D = 0, H, C; D < x.length; D++) { + if (H = x[D], C = w[H], C.constructor === Array) { + for (y = 0; y < C.length; y++) { + v.push(H, C[y]); } } else { - t.push(I, C); + v.push(H, C); } } } } - if (!t.length) { + if (!v.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - n = t; + p = v; if (!a) { - r = []; - if (t.length) { - for (n = 0; n < t.length; n += 2) { + q = []; + if (v.length) { + for (p = 0; p < v.length; p += 2) { if (this.db) { - d = this.index.get(t[n]); - if (!d) { - console.warn("Tag '" + t[n] + ":" + t[n + 1] + "' will be skipped because there is no field '" + t[n] + "'."); + r = this.index.get(v[p]); + if (!r) { + console.warn("Tag '" + v[p] + ":" + v[p + 1] + "' will be skipped because there is no field '" + v[p] + "'."); continue; } - r.push(d = d.db.tag(t[n + 1], b, l, p)); + q.push(r = r.db.tag(v[p + 1], b, l, u)); } else { - d = Ea.call(this, t[n], t[n + 1], b, l, p); + r = Ka.call(this, v[p], v[p + 1], b, l, u); } - e.push({field:t[n], tag:t[n + 1], result:d}); + d.push({field:v[p], tag:v[p + 1], result:r}); } } - return r.length ? Promise.all(r).then(function(y) { - for (let w = 0; w < y.length; w++) { - e[w].result = y[w]; + return q.length ? Promise.all(q).then(function(z) { + for (let w = 0; w < z.length; w++) { + d[w].result = z[w]; } - return e; - }) : e; + return d; + }) : d; } } - G(k) && (k = [k]); + h && h.constructor !== Array && (h = [h]); } - k || (k = this.field); - t = !d && (this.worker || this.db) && []; - let E; - for (let y = 0, w, A, I; y < k.length; y++) { - A = k[y]; - if (this.db && this.tag && !this.D[y]) { + h || (h = this.field); + v = !e && (this.worker || this.db) && []; + let F; + for (let z = 0, w, D, H; z < h.length; z++) { + D = h[z]; + if (this.db && this.tag && !this.D[z]) { continue; } let C; - G(A) || (C = A, A = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, r = C.suggest || r, p = this.store && (C.enrich || p)); - if (d) { - w = d[y]; + E(D) || (C = D, D = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, q = C.suggest || q, u = this.store && (C.enrich || u)); + if (e) { + w = e[z]; } else { - if (v = C || c, x = this.index.get(A), n && (this.db && (v.tag = n, E = x.db.support_tag_search, v.field = k), E || (v.enrich = !1)), t) { - t[y] = x.search(a, b, v); - v && p && (v.enrich = p); + if (x = C || c, y = this.index.get(D), p && (this.db && (x.tag = p, F = y.db.support_tag_search, x.field = h), F || (x.enrich = !1)), v) { + v[z] = y.search(a, b, x); + x && u && (x.enrich = u); continue; } else { - w = x.search(a, b, v), v && p && (v.enrich = p); + w = y.search(a, b, x), x && u && (x.enrich = u); } } - I = w && w.length; - if (n && I) { - v = []; - x = 0; - if (this.db && d) { - if (!E) { - for (let D = k.length; D < d.length; D++) { - let F = d[D]; - if (F && F.length) { - x++, v.push(F); - } else if (!r) { - return e; + H = w && (r ? w.length : w.result.length); + if (p && H) { + x = []; + y = 0; + if (this.db && e) { + if (!F) { + for (let G = h.length; G < e.length; G++) { + let K = e[G]; + if (K && K.length) { + y++, x.push(K); + } else if (!q) { + return r ? d : new W(d); } } } } else { - for (let D = 0, F, gb; D < n.length; D += 2) { - F = this.tag.get(n[D]); - if (!F) { - if (console.warn("Tag '" + n[D] + ":" + n[D + 1] + "' will be skipped because there is no field '" + n[D] + "'."), r) { + for (let G = 0, K, hb; G < p.length; G += 2) { + K = this.tag.get(p[G]); + if (!K) { + if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), q) { continue; } else { - return e; + return r ? d : new W(d); } } - if (gb = (F = F && F.get(n[D + 1])) && F.length) { - x++, v.push(F); - } else if (!r) { - return e; + if (hb = (K = K && K.get(p[G + 1])) && K.length) { + y++, x.push(K); + } else if (!q) { + return r ? d : new W(d); } } } - if (x) { - w = Da(w, v); - I = w.length; - if (!I && !r) { - return e; + if (y) { + w = Ba(w, x, r); + H = w.length; + if (!H && !q) { + return r ? w : new W(w); } - x--; + y--; } } - if (I) { - f[m] = A, e.push(w), m++; - } else if (1 === k.length) { - return e; + if (H) { + f[m] = D, d.push(w), m++; + } else if (1 === h.length) { + return r ? d : new W(d); } } - if (t) { - if (this.db && n && n.length && !E) { - for (p = 0; p < n.length; p += 2) { - d = this.index.get(n[p]); - if (!d) { - if (console.warn("Tag '" + n[p] + ":" + n[p + 1] + "' was not found because there is no field '" + n[p] + "'."), r) { + if (v) { + if (this.db && p && p.length && !F) { + for (u = 0; u < p.length; u += 2) { + e = this.index.get(p[u]); + if (!e) { + if (console.warn("Tag '" + p[u] + ":" + p[u + 1] + "' was not found because there is no field '" + p[u] + "'."), q) { continue; } else { - return e; + return r ? d : new W(d); } } - t.push(d.db.tag(n[p + 1], b, l, !1)); + v.push(e.db.tag(p[u + 1], b, l, !1)); } } - const y = this; - return Promise.all(t).then(function(w) { - return w.length ? y.search(a, b, c, w) : w; + const z = this; + return Promise.all(v).then(function(w) { + return w.length ? z.search(a, b, c, w) : w; }); } if (!m) { - return e; + return r ? d : new W(d); } - if (g && (!p || !this.store)) { - return e[0]; + if (g && (!u || !this.store)) { + return d[0]; } - t = []; - for (let y = 0, w; y < f.length; y++) { - w = e[y]; - p && w.length && !w[0].doc && (this.db ? t.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = Fa.call(this, w))); + v = []; + for (let z = 0, w; z < f.length; z++) { + w = d[z]; + u && w.length && !w[0].doc && (this.db ? v.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = V.call(this, w)); if (g) { - return w; + return r ? w : new W(w); } - e[y] = {field:f[y], result:w}; + d[z] = {field:f[z], result:w}; } - if (p && this.db && t.length) { - const y = this; - return Promise.all(t).then(function(w) { - for (let A = 0; A < w.length; A++) { - e[A].result = w[A]; + if (u && this.db && v.length) { + const z = this; + return Promise.all(v).then(function(w) { + for (let D = 0; D < w.length; D++) { + d[D].result = w[D]; } - return h ? Ga(e, b) : q ? Ha(e, a, y.index, y.field, y.D, q) : e; + return k ? La(d, b) : n ? Ma(d, a, z.index, z.field, z.D, n) : d; }); } - return h ? Ga(e, b) : q ? Ha(e, a, this.index, this.field, this.D, q) : e; + return k ? La(d, b) : n ? Ma(d, a, this.index, this.field, this.D, n) : d; }; -function Ha(a, b, c, d, e, f) { - let g, h, k; - for (let m = 0, q, n, p, r, t; m < a.length; m++) { - q = a[m].result; - n = a[m].field; - r = c.get(n); - p = r.encoder; - k = r.tokenize; - t = e[d.indexOf(n)]; - p !== g && (g = p, h = g.encode(b)); - for (let v = 0; v < q.length; v++) { +function Ma(a, b, c, e, d, f) { + let g, k, h; + for (let m = 0, n, p, q, r, u; m < a.length; m++) { + n = a[m].result; + p = a[m].field; + r = c.get(p); + q = r.encoder; + h = r.tokenize; + u = d[e.indexOf(p)]; + q !== g && (g = q, k = g.encode(b)); + for (let v = 0; v < n.length; v++) { let x = ""; - var l = J(q[v].doc, t); - let E = g.encode(l); + var l = J(n[v].doc, u); + let y = g.encode(l); l = l.split(g.split); - for (let y = 0, w, A; y < E.length; y++) { - w = E[y]; - A = l[y]; - let I; - for (let C = 0, D; C < h.length; C++) { - if (D = h[C], "strict" === k) { - if (w === D) { - x += (x ? " " : "") + f.replace("$1", A); - I = !0; + for (let F = 0, z, w; F < y.length; F++) { + z = y[F]; + w = l[F]; + let D; + for (let H = 0, C; H < k.length; H++) { + if (C = k[H], "strict" === h) { + if (z === C) { + x += (x ? " " : "") + f.replace("$1", w); + D = !0; break; } } else { - const F = w.indexOf(D); - if (-1 < F) { - x += (x ? " " : "") + A.substring(0, F) + f.replace("$1", A.substring(F, D.length)) + A.substring(F + D.length); - I = !0; + const G = z.indexOf(C); + if (-1 < G) { + x += (x ? " " : "") + w.substring(0, G) + f.replace("$1", w.substring(G, C.length)) + w.substring(G + C.length); + D = !0; break; } } } - I || (x += (x ? " " : "") + l[y]); + D || (x += (x ? " " : "") + l[F]); } - q[v].highlight = x; + n[v].highlight = x; } } return a; } -function Ga(a, b) { - const c = [], d = B(); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e]; +function La(a, b) { + const c = [], e = B(); + for (let d = 0, f, g; d < a.length; d++) { + f = a[d]; g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = d[k]) { + for (let k = 0, h, l, m; k < g.length; k++) { + if (l = g[k], h = l.id, m = e[h]) { m.push(f.field); } else { if (c.length === b) { return c; } - l.field = d[k] = [f.field]; + l.field = e[h] = [f.field]; c.push(l); } } } return c; } -function Ea(a, b, c, d, e) { +function Ka(a, b, c, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { - if (a > c || d) { - f = f.slice(d, d + c); + if ((a = (f = f && f.get(b)) && f.length - e) && 0 < a) { + if (a > c || e) { + f = f.slice(e, e + c); } - e && (f = Fa.call(this, f)); + d && (f = V.call(this, f)); return f; } } -function Fa(a) { +function V(a) { + if (!this || !this.store) { + return a; + } const b = Array(a.length); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b[c] = {id:d, doc:this.store.get(d)}; + for (let c = 0, e; c < a.length; c++) { + e = a[c], b[c] = {id:e, doc:this.store.get(e)}; } return b; } -;function T(a) { - if (!this || this.constructor !== T) { - return new T(a); +;function U(a) { + if (!this || this.constructor !== U) { + return new U(a); } const b = a.document || a.doc || a; - let c, d; + let c, e; this.D = []; this.field = []; - this.K = []; - this.key = (c = b.key || b.id) && Ia(c, this.K) || "id"; - (d = a.keystore || 0) && (this.keystore = d); - this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new R(d) : new Map() : d ? new S(d) : new Set(); + this.J = []; + this.key = (c = b.key || b.id) && Na(c, this.J) || "id"; + (e = a.keystore || 0) && (this.keystore = e); + this.reg = (this.fastupdate = !!a.fastupdate) ? e ? new S(e) : new Map() : e ? new T(e) : new Set(); this.C = (c = b.store || null) && c && !0 !== c && []; - this.store = c && (d ? new R(d) : new Map()); - this.cache = (c = a.cache || null) && new U(c); + this.store = c && (e ? new S(e) : new Map()); + this.cache = (c = a.cache || null) && new X(c); a.cache = !1; this.worker = a.worker; - this.index = Ja.call(this, a, b); + this.index = Oa.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { this.tag = new Map(); - this.G = []; - this.P = []; - for (let e = 0, f, g; e < c.length; e++) { - f = c[e]; + this.F = []; + this.R = []; + 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."); } - f.custom ? this.G[e] = f.custom : (this.G[e] = Ia(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].J = f.filter)); - this.P[e] = g; + f.custom ? this.F[d] = f.custom : (this.F[d] = Na(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); + this.R[d] = g; this.tag.set(g, new Map()); } } } if (this.worker) { a = []; - for (const e of this.index.values()) { - e.then && a.push(e); + for (const d of this.index.values()) { + d.then && a.push(d); } if (a.length) { - const e = this; + const d = this; return Promise.all(a).then(function(f) { let g = 0; - for (const h of e.index.entries()) { - const k = h[0]; - h[1].then && e.index.set(k, f[g++]); + for (const k of d.index.entries()) { + const h = k[0]; + k[1].then && d.index.set(h, f[g++]); } - return e; + return d; }); } } else { a.db && this.mount(a.db); } } -u = T.prototype; -u.mount = function(a) { +t = U.prototype; +t.mount = function(a) { let b = this.field; if (this.tag) { - for (let e = 0, f; e < this.P.length; e++) { - f = this.P[e]; + for (let d = 0, f; d < this.R.length; d++) { + f = this.R[d]; var c = void 0; - this.index.set(f, c = new M({}, this.reg)); + this.index.set(f, c = new N({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(f); c.tag = this.tag.get(f); } } c = []; - const d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let e = 0, f, g; e < b.length; e++) { - d.field = g = b[e]; + const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; + for (let d = 0, f, g; d < b.length; d++) { + e.field = g = b[d]; f = this.index.get(g); - const h = new a.constructor(a.id, d); - h.id = a.id; - c[e] = h.mount(f); + const k = new a.constructor(a.id, e); + k.id = a.id; + c[d] = k.mount(f); f.document = !0; - e ? f.bypass = !0 : f.store = this.store; + d ? f.bypass = !0 : f.store = this.store; } this.db = !0; return Promise.all(c); }; -u.commit = async function(a, b) { +t.commit = async function(a, b) { const c = []; - for (const d of this.index.values()) { - c.push(d.db.commit(d, a, b)); + for (const e of this.index.values()) { + c.push(e.db.commit(e, a, b)); } await Promise.all(c); this.reg.clear(); }; -u.destroy = function() { +t.destroy = function() { const a = []; for (const b of this.index.values()) { a.push(b.destroy()); } return Promise.all(a); }; -function Ja(a, b) { +function Oa(a, b) { const c = new Map(); - let d = b.index || b.field || b; - G(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e]; - G(f) || (g = f, f = f.field); - g = H(g) ? Object.assign({}, a, g) : a; + let e = b.index || b.field || b; + E(e) && (e = [e]); + for (let d = 0, f, g; d < e.length; d++) { + f = e[d]; + E(f) || (g = f, f = f.field); + g = I(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const h = new N(g); - c.set(f, h); + const k = new O(g); + c.set(f, k); } - this.worker || c.set(f, new M(g, this.reg)); - g.custom ? this.D[e] = g.custom : (this.D[e] = Ia(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].J = g.filter)); - this.field[e] = f; + this.worker || c.set(f, new N(g, this.reg)); + g.custom ? this.D[d] = g.custom : (this.D[d] = Na(f, this.J), g.filter && ("string" === typeof this.D[d] && (this.D[d] = new String(this.D[d])), this.D[d].I = g.filter)); + this.field[d] = f; } if (this.C) { a = b.store; - G(a) && (a = [a]); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ia(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].J = f.filter)); + E(a) && (a = [a]); + for (let d = 0, f, g; d < a.length; d++) { + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Na(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); } } return c; } -function Ia(a, b) { +function Na(a, b) { const c = a.split(":"); - let d = 0; - for (let e = 0; e < c.length; e++) { - a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); + let e = 0; + for (let d = 0; d < c.length; d++) { + a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); } - d < c.length && (c.length = d); - return 1 < d ? c : c[0]; + e < c.length && (c.length = e); + return 1 < e ? c : c[0]; } -u.append = function(a, b) { +t.append = function(a, b) { return this.add(a, b, !0); }; -u.update = function(a, b) { +t.update = function(a, b) { return this.remove(a).add(a, b); }; -u.remove = function(a) { - H(a) && (a = J(a, this.key)); +t.remove = function(a) { + I(a) && (a = J(a, this.key)); for (var b of this.index.values()) { b.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { for (let c of this.tag.values()) { - for (let d of c) { - b = d[0]; - const e = d[1], f = e.indexOf(a); - -1 < f && (1 < e.length ? e.splice(f, 1) : c.delete(b)); + 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) : c.delete(b)); } } } @@ -1276,7 +1592,7 @@ u.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -u.clear = function() { +t.clear = function() { for (const a of this.index.values()) { a.clear(); } @@ -1288,66 +1604,66 @@ u.clear = function() { this.store && this.store.clear(); return this; }; -u.contain = function(a) { +t.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; -u.cleanup = function() { +t.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -u.get = function(a) { +t.get = function(a) { return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { return b[0] && b[0].doc; }) : this.store.get(a); }; -u.set = function(a, b) { +t.set = function(a, b) { this.store.set(a, b); return this; }; -u.searchCache = Ka; -u.export = function(a, b, c = 0, d = 0) { +t.searchCache = Pa; +t.export = function(a, b, c = 0, e = 0) { if (c < this.field.length) { const g = this.field[c]; - if ((b = this.index.get(g).export(a, g, c, d = 1)) && b.then) { - const h = this; + if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { + const k = this; return b.then(function() { - return h.export(a, g, c + 1); + return k.export(a, g, c + 1); }); } return this.export(a, g, c + 1); } - let e, f; - switch(d) { + let d, f; + switch(e) { case 0: - e = "reg"; - f = ta(this.reg); + d = "reg"; + f = ra(this.reg); b = null; break; case 1: - e = "tag"; - f = ra(this.tag, this.reg.size); + d = "tag"; + f = pa(this.tag, this.reg.size); b = null; break; case 2: - e = "doc"; - f = pa(this.store); + d = "doc"; + f = na(this.store); b = null; break; case 3: - e = "cfg"; + d = "cfg"; f = {}; b = null; break; default: return; } - return va.call(this, a, b, e, f, c, d); + return ta.call(this, a, b, d, f, c, e); }; -u.import = function(a, b) { +t.import = function(a, b) { if (b) { - G(b) && (b = JSON.parse(b)); + "string" === typeof b && (b = JSON.parse(b)); a = a.split("."); "json" === a[a.length - 1] && a.pop(); var c = 2 < a.length ? a[0] : ""; @@ -1358,133 +1674,132 @@ u.import = function(a, b) { switch(a) { case "reg": this.fastupdate = !1; - this.reg = ua(b, this.reg); - for (let d = 0, e; d < this.field.length; d++) { - e = this.index.get(this.field[d]), e.fastupdate = !1, e.reg = this.reg; + this.reg = sa(b, this.reg); + for (let e = 0, d; e < this.field.length; e++) { + d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = sa(b, this.tag); + this.tag = qa(b, this.tag); break; case "doc": - this.store = qa(b, this.store); + this.store = oa(b, this.store); } } }; -oa(T.prototype); -function Ka(a, b, c) { +ma(U.prototype); +function Pa(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new U()); - let d = this.cache.get(a); - if (!d) { - d = this.search(a, b, c); - if (d.then) { - const e = this; - d.then(function(f) { - e.cache.set(a, f); + this.cache || (this.cache = new X()); + let e = this.cache.get(a); + if (!e) { + e = this.search(a, b, c); + if (e.then) { + const d = this; + e.then(function(f) { + d.cache.set(a, f); return f; }); } - this.cache.set(a, d); + this.cache.set(a, e); } - return d; + return e; } -function U(a) { +function X(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -U.prototype.set = function(a, b) { +X.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); }; -U.prototype.get = function(a) { +X.prototype.get = function(a) { const b = this.cache.get(a); b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); return b; }; -U.prototype.remove = function(a) { +X.prototype.remove = function(a) { for (const b of this.cache) { const c = b[0]; b[1].includes(a) && this.cache.delete(c); } }; -U.prototype.clear = function() { +X.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const La = {normalize:function(a) { +const Qa = {normalize:function(a) { return a.toLowerCase(); -}, dedupe:!1}; -const Ma = 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 Na = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Oa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const Pa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const Qa = /[\x00-\x7F]+/g; -const Ra = /[\x00-\x7F]+/g; -const Sa = /[\x00-\x7F]+/g; -var Ta = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:La, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ma}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ma, matcher:Na, replacer:Oa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ma, replacer:Oa.concat([/(?!^)[aeo]/g, ""]), matcher:Na}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +}, numeric:!1, dedupe:!1}; +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"], ["pf", "f"]]), Ta = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\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}; +const Va = /[\x00-\x7F]+/g; +const Wa = /[\x00-\x7F]+/g; +const Xa = /[\x00-\x7F]+/g; +var Ya = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Qa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ra}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ra, matcher:Sa, replacer:Ta}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ra, replacer:Ta.concat([/(?!^)[aeo]/g, ""]), matcher:Sa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let d = b.charAt(0), e = Pa[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Pa[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + let e = b.charAt(0), d = Ua[e]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Ua[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = d; + a[c] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Qa, " "); + return ("" + a).replace(Va, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ra, ""); + return ("" + a).replace(Wa, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Sa, " "); + return ("" + a).replace(Xa, " "); }}}; -const Ua = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -B(); -M.prototype.add = function(a, b, c, d) { +const Za = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +N.prototype.add = function(a, b, c, e) { if (b && (a || 0 === a)) { - if (!d && !c && this.reg.has(a)) { + if (!e && !c && this.reg.has(a)) { return this.update(a, b); } b = this.encoder.encode(b); - if (d = b.length) { - const l = B(), m = B(), q = this.depth, n = this.resolution; - for (let p = 0; p < d; p++) { - let r = b[this.rtl ? d - 1 - p : p]; - var e = r.length; - if (e && (q || !m[r])) { - var f = this.score ? this.score(b, r, p, null, 0) : Va(n, d, p), g = ""; + if (e = b.length) { + const l = B(), m = B(), n = this.depth, p = this.resolution; + for (let q = 0; q < e; q++) { + let r = b[this.rtl ? e - 1 - q : q]; + var d = r.length; + if (d && (n || !m[r])) { + var f = this.score ? this.score(b, r, q, null, 0) : $a(p, e, q), g = ""; switch(this.tokenize) { case "full": - if (2 < e) { - for (f = 0; f < e; f++) { - for (var h = e; h > f; h--) { - g = r.substring(f, h); - var k = this.score ? this.score(b, r, p, g, f) : Va(n, d, p, e, f); - V(this, m, g, k, a, c); + if (2 < d) { + for (f = 0; f < d; f++) { + for (var k = d; k > f; k--) { + g = r.substring(f, k); + var h = this.score ? this.score(b, r, q, g, f) : $a(p, e, q, d, f); + Y(this, m, g, h, a, c); } } break; } case "reverse": - if (1 < e) { - for (h = e - 1; 0 < h; h--) { - g = r[h] + g, k = this.score ? this.score(b, r, p, g, h) : Va(n, d, p, e, h), V(this, m, g, k, a, c); + if (1 < d) { + for (k = d - 1; 0 < k; k--) { + g = r[k] + g, h = this.score ? this.score(b, r, q, g, k) : $a(p, e, q, d, k), Y(this, m, g, h, a, c); } g = ""; } case "forward": - if (1 < e) { - for (h = 0; h < e; h++) { - g += r[h], V(this, m, g, f, a, c); + if (1 < d) { + for (k = 0; k < d; k++) { + g += r[k], Y(this, m, g, f, a, c); } break; } default: - if (V(this, m, r, f, a, c), q && 1 < d && p < d - 1) { - for (e = B(), g = this.R, f = r, h = Math.min(q + 1, d - p), e[f] = 1, k = 1; k < h; k++) { - if ((r = b[this.rtl ? d - 1 - p - k : p + k]) && !e[r]) { - e[r] = 1; - const t = this.score ? this.score(b, f, p, r, k) : Va(g + (d / 2 > g ? 0 : 1), d, p, h - 1, k - 1), v = this.bidirectional && r > f; - V(this, l, v ? f : r, t, a, c, v ? r : f); + if (Y(this, m, r, f, a, c), n && 1 < e && q < e - 1) { + for (d = B(), g = this.U, f = r, k = Math.min(n + 1, e - q), d[f] = 1, h = 1; h < k; h++) { + if ((r = b[this.rtl ? e - 1 - q - h : q + h]) && !d[r]) { + d[r] = 1; + const u = this.score ? this.score(b, f, q, r, h) : $a(g + (e / 2 > g ? 0 : 1), e, q, k - 1, h - 1), v = this.bidirectional && r > f; + Y(this, l, v ? f : r, u, a, c, v ? r : f); } } } @@ -1496,599 +1811,157 @@ M.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && Wa(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && ab(this)); return this; }; -function V(a, b, c, d, e, f, g) { - let h = g ? a.ctx : a.map, k; - if (!b[c] || g && !(k = b[c])[g]) { - if (g ? (b = k || (b[c] = B()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { - if (h.length === 2 ** 31 - 1) { - b = new Q(h); +function Y(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] = B()), b[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : b[c] = 1, (h = k.get(c)) ? k = h : k.set(c, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { + if (k.length === 2 ** 31 - 1) { + b = new R(k); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(h) && (l[l.indexOf(h)] = b); + l.includes(k) && (l[l.indexOf(k)] = b); } } - k[d] = h = b; + h[e] = k = b; } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + k.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } } -function Va(a, b, c, d, e) { - return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; +function $a(a, b, c, e, d) { + return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; } -;function W(a, b, c, d) { - if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Xa(a) : a; +;N.prototype.search = function(a, b, c) { + c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); + let e = [], d, f, g, k = 0, h, l, m, n, p; + c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, p = (h = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : h = this.resolve; + let q = this.encoder.encode(a); + d = q.length; + b = b || (h ? 100 : 0); + if (1 === d) { + return bb.call(this, q[0], "", b, k, h, p, l); } - let e = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { - if (c) { - if (c >= h) { - c -= h; - continue; - } - c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); - } - if (e.length) { - h > b && (g = g.slice(0, b), h = g.length); - } else { - if (h >= b) { - return h > b && (g = g.slice(0, b)), d ? Xa(g) : g; - } - } - e.push(g); - b -= h; - if (!b) { - break; - } - } + f = this.depth && !1 !== f; + if (2 === d && f && !g) { + return bb.call(this, q[0], q[1], b, k, h, p, l); } - if (!e.length) { - return e; - } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? Xa(e) : e; -} -function Xa(a) { - for (let b = 0; b < a.length; b++) { - a[b] = {score:b, id:a[b]}; - } - return a; -} -;X.prototype.or = function() { - const a = this; - let b = arguments; - var c = b[0]; - if (c.then) { - return c.then(function() { - return a.or.apply(a, b); - }); - } - if (c[0] && c[0].index) { - return this.or.apply(this, c); - } - let d = []; - c = []; - let e = 0, f = 0, g, h; - for (let k = 0, l; k < b.length; k++) { - if (l = b[k]) { - e = l.limit || 0; - f = l.offset || 0; - g = l.enrich; - h = l.resolve; - let m; - if (l.constructor === X) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.and) { - m = this.and(l.and); - } else if (l.xor) { - m = this.xor(l.xor); - } else if (l.not) { - m = this.not(l.not); - } else { - continue; - } - d[k] = m; - m.then && c.push(m); - } - } - if (c.length) { - return Promise.all(c).then(function() { - a.result.length && (d = d.concat([a.result])); - a.result = Ya(d, e, f, g, h, a.F); - return h ? a.result : a; - }); - } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ya(d, e, f, g, h, this.F)); - return h ? this.result : this; -}; -function Ya(a, b, c, d, e, f) { - if (!a.length) { - return a; - } - "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : Ca(a, c, b, e, f); -} -;X.prototype.and = function() { - if (this.result.length) { - const b = this; - let c = arguments; - var a = c[0]; - if (a.then) { - return a.then(function() { - return b.and.apply(b, c); - }); - } - if (a[0] && a[0].index) { - return this.and.apply(this, a); - } - let d = []; - a = []; - let e = 0, f = 0, g, h; - for (let k = 0, l; k < c.length; k++) { - if (l = c[k]) { - e = l.limit || 0; - f = l.offset || 0; - g = l.resolve; - h = l.suggest; - let m; - if (l.constructor === X) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.or) { - m = this.or(l.or); - } else if (l.xor) { - m = this.xor(l.xor); - } else if (l.not) { - m = this.not(l.not); - } else { - continue; - } - d[k] = m; - m.then && a.push(m); - } - } - if (!d.length) { - return this.result = d, g ? this.result : this; - } - if (a.length) { - return Promise.all(a).then(function() { - d = [b.result].concat(d); - b.result = Za(d, e, f, g, b.F, h); - return g ? b.result : b; - }); - } - d = [this.result].concat(d); - this.result = Za(d, e, f, g, this.F, h); - return g ? this.result : this; - } - return this; -}; -function Za(a, b, c, d, e, f) { - if (2 > a.length) { - return []; - } - let g = []; - B(); - let h = ca(a); - return h ? Ba(a, h, b, c, f, e, d) : g; -} -;X.prototype.xor = function() { - const a = this; - let b = arguments; - var c = b[0]; - if (c.then) { - return c.then(function() { - return a.xor.apply(a, b); - }); - } - if (c[0] && c[0].index) { - return this.xor.apply(this, c); - } - let d = []; - c = []; - let e = 0, f = 0, g, h; - for (let k = 0, l; k < b.length; k++) { - if (l = b[k]) { - e = l.limit || 0; - f = l.offset || 0; - g = l.enrich; - h = l.resolve; - let m; - if (l.constructor === X) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.or) { - m = this.or(l.or); - } else if (l.and) { - m = this.and(l.and); - } else if (l.not) { - m = this.not(l.not); - } else { - continue; - } - d[k] = m; - m.then && c.push(m); - } - } - if (c.length) { - return Promise.all(c).then(function() { - a.result.length && (d = [a.result].concat(d)); - a.result = $a(d, e, f, g, !h, a.F); - return h ? a.result : a; - }); - } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = $a(d, e, f, g, !h, a.F)); - return h ? this.result : this; -}; -function $a(a, b, c, d, e, f) { - if (!a.length) { - return a; - } - if (2 > a.length) { - return e ? W(a[0], b, c, d) : a[0]; - } - d = []; - const g = B(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - for (let m = 0, q; m < l.length; m++) { - if (q = l[m]) { - h < q.length && (h = q.length); - for (let n = 0, p; n < q.length; n++) { - p = q[n], g[p] ? g[p]++ : g[p] = 1; - } - } - } - } - } - for (let k = 0, l, m = 0; k < h; k++) { - for (let q = 0, n; q < a.length; q++) { - if (n = a[q]) { - if (l = n[k]) { - for (let p = 0, r; p < l.length; p++) { - if (r = l[p], 1 === g[r]) { - if (c) { - c--; - } else { - if (e) { - if (d.push(r), d.length === b) { - return d; - } - } else { - const t = k + (q ? f : 0); - d[t] || (d[t] = []); - d[t].push(r); - if (++m === b) { - return d; - } - } - } - } - } - } - } - } - } - return d; -} -;X.prototype.not = function() { - const a = this; - let b = arguments; - var c = b[0]; - if (c.then) { - return c.then(function() { - return a.not.apply(a, b); - }); - } - if (c[0] && c[0].index) { - return this.not.apply(this, c); - } - let d = []; - c = []; - let e = 0, f = 0, g; - for (let h = 0, k; h < b.length; h++) { - if (k = b[h]) { - e = k.limit || 0; - f = k.offset || 0; - g = k.resolve; - let l; - if (k.constructor === X) { - l = k.result; - } else if (k.constructor === Array) { - l = k; - } else if (k.index) { - k.resolve = !1, l = k.index.search(k).result; - } else if (k.or) { - l = this.or(k.or); - } else if (k.and) { - l = this.and(k.and); - } else if (k.xor) { - l = this.xor(k.xor); - } else { - continue; - } - d[h] = l; - l.then && c.push(l); - } - } - if (c.length) { - return Promise.all(c).then(function() { - a.result = ab.call(a, d, e, f, g); - return g ? a.result : a; - }); - } - d.length && (this.result = ab.call(this, d, e, f, g)); - return g ? this.result : this; -}; -function ab(a, b, c, d) { - if (!a.length) { - return this.result; - } - const e = []; - a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { - if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { - if (c) { - c--; - } else { - if (d) { - if (e.push(l), e.length === b) { - return e; - } - } else { - if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { - return e; - } - } - } - } - } - } - } - return e; -} -;function X(a) { - if (!this || this.constructor !== X) { - return new X(a); - } - if (a && a.index) { - return a.resolve = !1, this.index = a.index, this.F = a.boost || 0, this.result = a.index.search(a).result, this; - } - if (a.constructor === X) { - return a; - } - this.index = null; - this.result = a || []; - this.F = 0; -} -X.prototype.limit = function(a) { - if (this.result.length) { - const b = []; - let c = 0; - for (let d = 0, e; d < this.result.length; d++) { - if (e = this.result[d], e.length + c < a) { - b[d] = e, c += e.length; - } else { - b[d] = e.slice(0, a - c); - this.result = b; - break; - } - } - } - return this; -}; -X.prototype.offset = function(a) { - if (this.result.length) { - const b = []; - let c = 0; - for (let d = 0, e; d < this.result.length; d++) { - e = this.result[d], e.length + c < a ? c += e.length : (b[d] = e.slice(a - c), c = a); - } - this.result = b; - } - return this; -}; -X.prototype.boost = function(a) { - this.F += a; - return this; -}; -X.prototype.resolve = function(a, b, c) { - bb = 1; - const d = this.result; - this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), W(d, a || 100, b, c)) : d; -}; -let bb = 1; -M.prototype.search = function(a, b, c) { - c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); - let d = [], e; - let f, g = 0, h, k, l, m, q; - if (c) { - a = c.query || a; - b = c.limit || b; - g = c.offset || 0; - var n = c.context; - f = c.suggest; - (h = bb && !1 !== c.resolve) || (bb = 0); - k = h && c.enrich; - m = c.boost; - q = c.resolution; - l = this.db && c.tag; - } else { - h = this.resolve || bb; - } - let p = this.encoder.encode(a); - e = p.length; - b || !h || (b = 100); - if (1 === e) { - return cb.call(this, p[0], "", b, g, h, k, l); - } - n = this.depth && !1 !== n; - if (2 === e && n && !f) { - return cb.call(this, p[0], p[1], b, g, h, k, l); - } - c = a = 0; - if (1 < e) { - const v = B(), x = []; - for (let E = 0, y; E < e; E++) { - if ((y = p[E]) && !v[y]) { - if (f || this.db || Y(this, y)) { - x.push(y), v[y] = 1; - } else { - return h ? d : new X(d); - } - const w = y.length; - a = Math.max(a, w); - c = c ? Math.min(c, w) : w; - } - } - p = x; - e = p.length; - } - if (!e) { - return h ? d : new X(d); - } - let r = 0, t; - if (1 === e) { - return cb.call(this, p[0], "", b, g, h, k, l); - } - if (2 === e && n && !f) { - return cb.call(this, p[0], p[1], b, g, h, k, l); - } - 1 < e && (n ? (t = p[0], r = 1) : 9 < a && 3 < a / c && p.sort(aa)); - q || 0 === q || (q = this.resolution); + let r = B(), u = 0, v; + 1 < d && f && (v = q[0], u = 1); + n || 0 === n || (n = v ? this.U : this.resolution); if (this.db) { - if (this.db.search && (n = this.db.search(this, p, b, g, f, h, k, l), !1 !== n)) { - return n; + if (this.db.search && (a = this.db.search(this, q, b, k, g, h, p, l), !1 !== a)) { + return a; } - const v = this; + const x = this; return async function() { - for (let x, E; r < e; r++) { - E = p[r]; - t ? (x = await Y(v, E, t, 0, 0, !1, !1), x = db(x, d, f, v.R), f && !1 === x && d.length || (t = E)) : (x = await Y(v, E, "", 0, 0, !1, !1), x = db(x, d, f, q)); - if (x) { - return x; - } - if (f && r === e - 1) { - let y = d.length; - if (!y) { - if (t) { - t = ""; - r = -1; - continue; - } - return d; - } - if (1 === y) { - return h ? W(d[0], b, g) : new X(d[0]); + for (let y, F; u < d; u++) { + if ((F = q[u]) && !r[F]) { + r[F] = 1; + y = await cb(x, F, v, 0, 0, !1, !1); + if (y = db(y, e, g, n)) { + e = y; + break; } + v && (g && y && e.length || (v = F)); } + g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return h ? Ba(d, q, b, g, f, m, h) : new X(d[0]); + return eb(e, n, b, k, g, m, h); }(); } - for (let v, x; r < e; r++) { - x = p[r]; - t ? (v = Y(this, x, t, 0, 0, !1, !1), v = db(v, d, f, this.R), f && !1 === v && d.length || (t = x)) : (v = Y(this, x, "", 0, 0, !1, !1), v = db(v, d, f, q)); - if (v) { - return v; - } - if (f && r === e - 1) { - n = d.length; - if (!n) { - if (t) { - t = ""; - r = -1; - continue; - } - return d; - } - if (1 === n) { - return h ? W(d[0], b, g) : new X(d[0]); + for (let x, y; u < d; u++) { + if ((y = q[u]) && !r[y]) { + r[y] = 1; + x = cb(this, y, v, 0, 0, !1, !1); + if (x = db(x, e, g, n)) { + e = x; + break; } + v && (g && x && e.length || (v = y)); } + g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - d = Ba(d, q, b, g, f, m, h); - return h ? d : new X(d); + return eb(e, n, b, k, g, m, h); }; -function cb(a, b, c, d, e, f, g) { - a = Y(this, a, b, c, d, e, f, g); - return this.db ? a.then(function(h) { - return e ? h : h && h.length ? e ? W(h, c, d) : new X(h) : e ? [] : new X([]); - }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); +function eb(a, b, c, e, d, f, g) { + let k = a.length, h = a; + if (1 < k) { + h = za(a, b, c, e, d, f, g); + } else if (1 === k) { + return g ? Ca.call(null, a[0], c, e) : new W(a[0]); + } + return g ? h : new W(h); } -function db(a, b, c, d) { - let e = []; - if (a) { - d = Math.min(a.length, d); - for (let f = 0, g; f < d; f++) { - (g = a[f]) && g && (e[f] = g); +function bb(a, b, c, e, d, f, g) { + a = cb(this, a, b, c, e, d, f, g); + return this.db ? a.then(function(k) { + return d ? k || [] : new W(k); + }) : a && a.length ? d ? Ca.call(this, a, c, e) : new W(a) : d ? [] : new W(); +} +function db(a, b, c, e) { + let d = []; + if (a && a.length) { + if (a.length <= e) { + b.push(a); + return; } - if (e.length) { - b.push(e); + for (let f = 0, g; f < e; f++) { + if (g = a[f]) { + d[f] = g; + } + } + if (d.length) { + b.push(d); return; } } - return !c && e; -} -function Y(a, b, c, d, e, f, g, h) { - let k; - c && (k = a.bidirectional && b > c); - if (a.db) { - return c ? a.db.get(k ? c : b, k ? b : c, d, e, f, g, h) : a.db.get(b, "", d, e, f, g, h); + if (!c) { + return d; } - a = c ? (a = a.ctx.get(k ? b : c)) && a.get(k ? c : b) : a.map.get(b); +} +function cb(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(b, c, e, d, f, g, k); + } + a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;M.prototype.remove = function(a, b) { +;N.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 d = 0, e; d < c.length; d++) { - if (e = c[d]) { - if (2 > e.length) { - e.pop(); + for (let e = 0, d; e < c.length; e++) { + if (d = c[e]) { + if (2 > d.length) { + d.pop(); } else { - const f = e.indexOf(a); - f === c.length - 1 ? e.pop() : e.splice(f, 1); + const f = d.indexOf(a); + f === c.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - eb(this.map, a), this.depth && eb(this.ctx, a); + fb(this.map, a), this.depth && fb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && Wa(this)); + this.db && (this.commit_task.push({del:a}), this.T && ab(this)); this.cache && this.cache.remove(a); return this; }; -function eb(a, b) { +function fb(a, b) { let c = 0; if (a.constructor === Array) { - for (let d = 0, e, f; d < a.length; d++) { - if ((e = a[d]) && e.length) { - if (f = e.indexOf(b), 0 <= f) { - 1 < e.length ? (e.splice(f, 1), c++) : delete a[d]; + for (let e = 0, d, f; e < a.length; e++) { + if ((d = a[e]) && d.length) { + if (f = d.indexOf(b), 0 <= f) { + 1 < d.length ? (d.splice(f, 1), c++) : delete a[e]; break; } else { c++; @@ -2096,39 +1969,39 @@ function eb(a, b) { } } } else { - for (let d of a) { - const e = d[0], f = eb(d[1], b); - f ? c += f : a.delete(e); + for (let e of a.entries()) { + const d = e[0], f = fb(e[1], b); + f ? c += f : a.delete(d); } } return c; } -;function M(a, b) { - if (!this || this.constructor !== M) { - return new M(a); +;function N(a, b) { + if (!this || this.constructor !== N) { + return new N(a); } if (a) { - var c = G(a) ? a : a.preset; - c && (Ua[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ua[c], a)); + var c = E(a) ? a : a.preset; + c && (Za[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Za[c], a)); } else { a = {}; } c = a.context; - const d = !0 === c ? {depth:1} : c || {}, e = G(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || La; - this.encoder = e.encode ? e : "object" === typeof e ? new K(e) : {encode:e}; + const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? Ya[a.encoder] : a.encode || a.encoder || Qa; + this.encoder = d.encode ? d : "object" === typeof d ? new L(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = c = a.tokenize || "strict"; - this.depth = "strict" === c && d.depth || 0; - this.bidirectional = !1 !== d.bidirectional; + 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 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.R = d.resolution || 3; - this.rtl = e.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new U(c); + this.map = c ? new S(c) : new Map(); + this.ctx = c ? new S(c) : new Map(); + this.reg = b || (this.fastupdate ? c ? new S(c) : new Map() : c ? new T(c) : new Set()); + this.U = e.resolution || 3; + this.rtl = d.rtl || a.rtl || !1; + this.cache = (c = a.cache || null) && new X(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); @@ -2137,26 +2010,26 @@ function eb(a, b) { this.commit_task = []; this.commit_timer = null; } -u = M.prototype; -u.mount = function(a) { +t = N.prototype; +t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -u.commit = function(a, b) { +t.commit = function(a, b) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.commit(this, a, b); }; -u.destroy = function() { +t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Wa(a) { +function ab(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 0)); } -u.clear = function() { +t.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -2164,170 +2037,171 @@ u.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -u.append = function(a, b) { +t.append = function(a, b) { return this.add(a, b, !0); }; -u.contain = function(a) { +t.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -u.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); +t.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); }; -function fb(a) { +function gb(a) { let b = 0; if (a.constructor === Array) { - for (let c = 0, d; c < a.length; c++) { - (d = a[c]) && (b += d.length); + for (let c = 0, e; c < a.length; c++) { + (e = a[c]) && (b += e.length); } } else { for (const c of a) { - const d = c[0], e = fb(c[1]); - e ? b += e : a.delete(d); + const e = c[0], d = gb(c[1]); + d ? b += d : a.delete(e); } } return b; } -u.cleanup = function() { +t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - fb(this.map); - this.depth && fb(this.ctx); + gb(this.map); + this.depth && gb(this.ctx); return this; }; -u.searchCache = Ka; -u.export = function(a, b, c, d = 0) { - let e, f; - switch(d) { +t.searchCache = Pa; +t.export = function(a, b, c = 0, e = 0) { + let d, f; + switch(e) { case 0: - e = "reg"; - f = ta(this.reg); + d = "reg"; + f = ra(this.reg); break; case 1: - e = "cfg"; + d = "cfg"; f = {}; break; case 2: - e = "map"; - f = pa(this.map, this.reg.size); + d = "map"; + f = na(this.map, this.reg.size); break; case 3: - e = "ctx"; - f = ra(this.ctx, this.reg.size); + d = "ctx"; + f = pa(this.ctx, this.reg.size); break; default: return; } - return va.call(this, a, b, e, f, c, d); + return ta.call(this, a, b, d, f, c, e); }; -u.import = function(a, b) { +t.import = function(a, b) { if (b) { - switch(G(b) && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { + switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = ua(b, this.reg); + this.reg = sa(b, this.reg); break; case "map": - this.map = qa(b, this.map); + this.map = oa(b, this.map); break; case "ctx": - this.ctx = sa(b, this.ctx); + this.ctx = qa(b, this.ctx); } } }; -u.serialize = function(a = !0) { +t.serialize = function(a = !0) { if (!this.reg.size) { return ""; } let b = "", c = ""; - for (var d of this.reg.keys()) { - c || (c = typeof d), b += (b ? "," : "") + ("string" === c ? '"' + d + '"' : d); + for (var e of this.reg.keys()) { + c || (c = typeof e), b += (b ? "," : "") + ("string" === c ? '"' + e + '"' : e); } b = "index.reg=new Set([" + b + "]);"; - d = ""; - for (var e of this.map.entries()) { - var f = e[0], g = e[1], h = ""; - for (let m = 0, q; m < g.length; m++) { - q = g[m] || [""]; - var k = ""; - for (var l = 0; l < q.length; l++) { - k += (k ? "," : "") + ("string" === c ? '"' + q[l] + '"' : q[l]); - } - k = "[" + k + "]"; - h += (h ? "," : "") + k; - } - h = '["' + f + '",[' + h + "]]"; - d += (d ? "," : "") + h; - } - d = "index.map=new Map([" + d + "]);"; e = ""; + for (var d of this.map.entries()) { + var f = d[0], g = d[1], k = ""; + for (let m = 0, n; m < g.length; m++) { + n = g[m] || [""]; + var h = ""; + for (var l = 0; l < n.length; l++) { + h += (h ? "," : "") + ("string" === c ? '"' + n[l] + '"' : n[l]); + } + h = "[" + h + "]"; + k += (k ? "," : "") + h; + } + k = '["' + f + '",[' + k + "]]"; + e += (e ? "," : "") + k; + } + e = "index.map=new Map([" + e + "]);"; + d = ""; for (const m of this.ctx.entries()) { f = m[0]; g = m[1]; - for (const q of g.entries()) { - g = q[0]; - h = q[1]; - k = ""; - for (let n = 0, p; n < h.length; n++) { - p = h[n] || [""]; + for (const n of g.entries()) { + g = n[0]; + k = n[1]; + h = ""; + for (let p = 0, q; p < k.length; p++) { + q = k[p] || [""]; l = ""; - for (let r = 0; r < p.length; r++) { - l += (l ? "," : "") + ("string" === c ? '"' + p[r] + '"' : p[r]); + for (let r = 0; r < q.length; r++) { + l += (l ? "," : "") + ("string" === c ? '"' + q[r] + '"' : q[r]); } l = "[" + l + "]"; - k += (k ? "," : "") + l; + h += (h ? "," : "") + l; } - k = 'new Map([["' + g + '",[' + k + "]]])"; - k = '["' + f + '",' + k + "]"; - e += (e ? "," : "") + k; + h = 'new Map([["' + g + '",[' + h + "]]])"; + h = '["' + f + '",' + h + "]"; + d += (d ? "," : "") + h; } } - e = "index.ctx=new Map([" + e + "]);"; - return a ? "function inject(index){" + b + d + e + "}" : b + d + e; + d = "index.ctx=new Map([" + d + "]);"; + return a ? "function inject(index){" + b + e + d + "}" : b + e + d; }; -oa(M.prototype); -const hb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ib = ["map", "ctx", "tag", "reg", "cfg"]; -function jb(a, b = {}) { +ma(N.prototype); +const ib = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), jb = ["map", "ctx", "tag", "reg", "cfg"]; +function kb(a, b = {}) { if (!this) { - return new jb(a, b); + return new kb(a, b); } "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 = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.support_tag_search = !1; + this.type = b.type; + this.fastupdate = this.support_tag_search = !1; this.db = null; this.h = {}; } -u = jb.prototype; -u.mount = function(a) { +t = kb.prototype; +t.mount = function(a) { if (!a.encoder) { return a.mount(this); } a.db = this; return this.open(); }; -u.open = function() { +t.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const d = hb.open(a.id + (a.field ? ":" + a.field : ""), 1); - d.onupgradeneeded = function() { - const e = a.db = this.result; - ib.forEach(f => { - e.objectStoreNames.contains(f) || e.createObjectStore(f); + const e = ib.open(a.id + (a.field ? ":" + a.field : ""), 1); + e.onupgradeneeded = function() { + const d = a.db = this.result; + jb.forEach(f => { + d.objectStoreNames.contains(f) || d.createObjectStore(f); }); }; - d.onblocked = function(e) { - console.error("blocked", e); + e.onblocked = function(d) { + console.error("blocked", d); c(); }; - d.onerror = function(e) { - console.error(this.error, e); + e.onerror = function(d) { + console.error(this.error, d); c(); }; - d.onsuccess = function() { + e.onsuccess = function() { a.db = this.result; a.db.onversionchange = function() { a.close(); @@ -2336,56 +2210,57 @@ u.open = function() { }; }); }; -u.close = function() { +t.close = function() { this.db.close(); this.db = null; }; -u.destroy = function() { - return hb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); +t.destroy = function() { + const a = ib.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Z(a); }; -u.clear = function() { - const a = this.db.transaction(ib, "readwrite"); - for (let b = 0; b < ib.length; b++) { - a.objectStore(ib[b]).clear(); +t.clear = function() { + const a = this.db.transaction(jb, "readwrite"); + for (let b = 0; b < jb.length; b++) { + a.objectStore(jb[b]).clear(); } return Z(a); }; -u.get = function(a, b, c = 0, d = 0, e = !0, f = !1) { +t.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").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 (e) { - if (!c && !d && 1 === h.length) { - return h[0]; + if (d) { + if (!c && !e && 1 === k.length) { + return k[0]; } - for (let l = 0, m; l < h.length; l++) { - if ((m = h[l]) && m.length) { - if (d >= m.length) { - d -= m.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 q = c ? d + Math.min(m.length - d, c) : m.length; - for (let n = d; n < q; n++) { - k.push(m[n]); + const n = c ? e + Math.min(m.length - e, c) : m.length; + for (let p = e; p < n; p++) { + h.push(m[p]); } - d = 0; - if (k.length === c) { + e = 0; + if (h.length === c) { break; } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; -u.tag = function(a, b = 0, c = 0, d = !1) { +t.tag = function(a, b = 0, c = 0, e = !1) { a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); - const e = this; + const d = this; return Z(a).then(function(f) { if (!f || !f.length || c >= f.length) { return []; @@ -2394,182 +2269,182 @@ u.tag = function(a, b = 0, c = 0, d = !1) { return f; } f = f.slice(c, c + b); - return d ? e.enrich(f) : f; + return e ? d.enrich(f) : f; }); }; -u.enrich = function(a) { +t.enrich = function(a) { "object" !== typeof a && (a = [a]); const b = this.db.transaction("reg", "readonly").objectStore("reg"), c = []; - for (let d = 0; d < a.length; d++) { - c[d] = Z(b.get(a[d])); + for (let e = 0; e < a.length; e++) { + c[e] = Z(b.get(a[e])); } - return Promise.all(c).then(function(d) { - for (let e = 0; e < d.length; e++) { - d[e] = {id:a[e], doc:d[e] ? JSON.parse(d[e]) : null}; + 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}; } - return d; + return e; }); }; -u.has = function(a) { +t.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); return Z(a); }; -u.search = null; -u.info = function() { +t.search = null; +t.info = function() { }; -u.transaction = function(a, b, c) { - let d = this.h[a + ":" + b]; - if (d) { - return c.call(this, d); +t.transaction = function(a, b, c) { + let e = this.h[a + ":" + b]; + if (e) { + return c.call(this, e); } - let e = this.db.transaction(a, b); - this.h[a + ":" + b] = d = e.objectStore(a); + let d = this.db.transaction(a, b); + this.h[a + ":" + b] = e = d.objectStore(a); return new Promise((f, g) => { - e.onerror = h => { + d.onerror = k => { this.h[a + ":" + b] = null; - e.abort(); - e = d = null; - g(h); + d.abort(); + d = e = null; + g(k); }; - e.oncomplete = h => { - e = d = this.h[a + ":" + b] = null; - f(h || !0); + d.oncomplete = k => { + d = e = this.h[a + ":" + b] = null; + f(k || !0); }; - return c.call(this, d); + return c.call(this, e); }); }; -u.commit = async function(a, b, c) { +t.commit = async function(a, b, c) { if (b) { await this.clear(), a.commit_task = []; } else { - let d = a.commit_task; + let e = a.commit_task; a.commit_task = []; - for (let e = 0, f; e < d.length; e++) { - if (f = d[e], f.clear) { + for (let d = 0, f; d < e.length; d++) { + if (f = e[d], f.clear) { await this.clear(); b = !0; break; } else { - d[e] = f.V; + e[d] = f.W; } } - b || (c || (d = d.concat(ba(a.reg))), d.length && await this.remove(d)); + b || (c || (e = e.concat(aa(a.reg))), e.length && await this.remove(e)); } - a.reg.size && (await this.transaction("map", "readwrite", function(d) { - for (const e of a.map) { - const f = e[0], g = e[1]; - g.length && (b ? d.put(g, f) : d.get(f).onsuccess = function() { - let h = this.result; - var k; - if (h && h.length) { - const l = Math.max(h.length, g.length); - for (let m = 0, q, n; m < l; m++) { - if ((n = g[m]) && n.length) { - if ((q = h[m]) && q.length) { - for (k = 0; k < n.length; k++) { - q.push(n[k]); + a.reg.size && (await this.transaction("map", "readwrite", function(e) { + for (const d of a.map) { + const f = d[0], g = d[1]; + g.length && (b ? e.put(g, f) : e.get(f).onsuccess = function() { + let k = this.result; + var h; + if (k && k.length) { + const l = Math.max(k.length, g.length); + for (let m = 0, n, p; m < l; m++) { + if ((p = g[m]) && p.length) { + if ((n = k[m]) && n.length) { + for (h = 0; h < p.length; h++) { + n.push(p[h]); } } else { - h[m] = n; + k[m] = p; } - k = 1; + h = 1; } } } else { - h = g, k = 1; + k = g, h = 1; } - k && d.put(h, f); + h && e.put(k, f); }); } - }), await this.transaction("ctx", "readwrite", function(d) { - for (const e of a.ctx) { - const f = e[0], g = e[1]; - for (const h of g) { - const k = h[0], l = h[1]; - l.length && (b ? d.put(l, f + ":" + k) : d.get(f + ":" + k).onsuccess = function() { + }), await this.transaction("ctx", "readwrite", function(e) { + for (const d of a.ctx) { + const f = d[0], g = d[1]; + for (const k of g) { + const h = k[0], l = k[1]; + l.length && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { let m = this.result; - var q; + var n; if (m && m.length) { - const n = Math.max(m.length, l.length); - for (let p = 0, r, t; p < n; p++) { - if ((t = l[p]) && t.length) { - if ((r = m[p]) && r.length) { - for (q = 0; q < t.length; q++) { - r.push(t[q]); + const p = Math.max(m.length, l.length); + for (let q = 0, r, u; q < p; q++) { + if ((u = l[q]) && u.length) { + if ((r = m[q]) && r.length) { + for (n = 0; n < u.length; n++) { + r.push(u[n]); } } else { - m[p] = t; + m[q] = u; } - q = 1; + n = 1; } } } else { - m = l, q = 1; + m = l, n = 1; } - q && d.put(m, f + ":" + k); + n && e.put(m, f + ":" + h); }); } } - }), a.store ? await this.transaction("reg", "readwrite", function(d) { - for (const e of a.store) { - const f = e[0], g = e[1]; - d.put("object" === typeof g ? JSON.stringify(g) : 1, f); + }), a.store ? await this.transaction("reg", "readwrite", function(e) { + for (const d of a.store) { + const f = d[0], g = d[1]; + e.put("object" === typeof g ? JSON.stringify(g) : 1, f); } - }) : a.bypass || await this.transaction("reg", "readwrite", function(d) { - for (const e of a.reg.keys()) { - d.put(1, e); + }) : a.bypass || await this.transaction("reg", "readwrite", function(e) { + for (const d of a.reg.keys()) { + e.put(1, d); } - }), a.tag && await this.transaction("tag", "readwrite", function(d) { - for (const e of a.tag) { - const f = e[0], g = e[1]; - g.length && (d.get(f).onsuccess = function() { - let h = this.result; - h = h && h.length ? h.concat(g) : g; - d.put(h, f); + }), a.tag && await this.transaction("tag", "readwrite", function(e) { + for (const d of a.tag) { + const f = d[0], g = d[1]; + g.length && (e.get(f).onsuccess = function() { + 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 kb(a, b, c) { - const d = a.value; - let e, f, g = 0; - for (let h = 0, k; h < d.length; h++) { - if (k = c ? d : d[h]) { - for (let l = 0, m, q; l < b.length; l++) { - if (q = b[l], m = k.indexOf(f ? parseInt(q, 10) : q), 0 > m && !f && "string" === typeof q && !isNaN(q) && (m = k.indexOf(parseInt(q, 10))) && (f = 1), 0 <= m) { - if (e = 1, 1 < k.length) { - k.splice(m, 1); +function lb(a, b, c) { + const e = a.value; + let d, f, g = 0; + for (let k = 0, h; k < e.length; k++) { + if (h = c ? e : e[k]) { + for (let l = 0, m, n; l < b.length; l++) { + if (n = b[l], m = h.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = h.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { + if (d = 1, 1 < h.length) { + h.splice(m, 1); } else { - d[h] = []; + e[k] = []; break; } } } - g += k.length; + g += h.length; } if (c) { break; } } - g ? e && a.update(d) : a.delete(); + g ? d && a.update(e) : a.delete(); a.continue(); } -u.remove = function(a) { +t.remove = function(a) { "object" !== typeof a && (a = [a]); return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && kb(c, a); + c && lb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && kb(c, a); + c && lb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && kb(c, a, !0); + c && lb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2589,6 +2464,6 @@ function Z(a) { a = null; }); } -;export default {Index:M, Charset:Ta, Encoder:K, Document:T, Worker:N, Resolver:X, IndexedDB:jb, Language:{}}; +;export default {Index:N, Charset:Ya, Encoder:L, Document:U, Worker:O, Resolver:W, IndexedDB:kb, Language:{}}; -export const Index=M;export const Charset=Ta;export const Encoder=K;export const Document=T;export const Worker=N;export const Resolver=X;export const IndexedDB=jb;export const Language={}; \ No newline at end of file +export const Index=N;export const Charset=Ya;export const Encoder=L;export const Document=U;export const Worker=O;export const Resolver=W;export const IndexedDB=kb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 92a9fc3..9040322 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,106 +1,100 @@ /**! - * FlexSearch.js v0.8.103 (Bundle/Module) + * FlexSearch.js v0.8.105 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u;function z(a,b,c){const d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)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"===e?b:a}function B(){return Object.create(null)}function aa(a,b){return b.length-a.length} -function F(a){return"string"===typeof a}function G(a){return"object"===typeof a}function ba(a){const b=[];for(const c of a.keys())b.push(c);return b}function J(a,b){if(F(b))a=a[b];else for(let c=0;a&&ca.length)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&&L(this);return this};u.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&&L(this);return this}; -u.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&L(this);return this};u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1this.stemmer.get(l)),k=1);g&&k&&(g.lengththis.matcher.get(l)));if(g&&this.replacer)for(e=0;g&&ethis.S&&(this.I.clear(),this.M=this.M/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.B&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.B=this.B/1.1|0));return c};function ka(a){a.L=null;a.H.clear();a.I.clear()};async function la(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new M(d);postMessage({id:a.id});break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let ma=0; -function N(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=B();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++ma]=function(){k(e)};e.worker.postMessage({id:ma,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==N)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;c&&(c=c.toString());const d="undefined"===typeof window,e=this,f=na(c,d,a.worker);return f.then?f.then(function(g){return b.call(e,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); -function O(a){N.prototype[a]=N.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;"function"===typeof d&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){b.h[++ma]=f;b.worker.postMessage({task:a,id:ma,args:c})});return e?(d.then(e),this):d}} -function na(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"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+la.toString()],{type:"text/javascript"}))):new window.Worker(F(c)?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function oa(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}function P(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function pa(a,b=0){let c=[],d=[];b&&(b=25E4/b*5E3|0);for(const e of a.entries())d.push(e),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function qa(a,b){b||(b=new Map);for(let c=0,d;c=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} -function Q(a){if(!this)return new Q(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(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){let f=0;for(let g=0,h,k;gc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(let p=0,n;pd)d-=n.length; -else{if(n.length>c||d)n=n.slice(d,c+d),c-=n.length,d&&(d-=n.length);e.push(n);if(!c)break}k=1c||d)a=a.slice(d,d+c);e&&(a=Fa.call(this,a));return a}} -function Fa(a){const b=Array(a.length);for(let c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -U.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};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const La={normalize:function(a){return a.toLowerCase()},dedupe:!1};const Ma=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 Na=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Oa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Pa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Qa=/[\x00-\x7F]+/g;const Ra=/[\x00-\x7F]+/g;const Sa=/[\x00-\x7F]+/g;var Ta={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:La,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ma},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ma,matcher:Na,replacer:Oa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ma,replacer:Oa.concat([/(?!^)[aeo]/g,""]),matcher:Na},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=r.substring(f,h);var k=this.score?this.score(b,r,q,g,f):Va(n,d,q,e,f);V(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,q,h-1,k-1),v=this.bidirectional&&r>f;V(this,l,v?f:r,t,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.T&&Wa(this));return this};function V(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new Q(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.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 Va(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Xa(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length);else if(h>=b)return h>b&&(g=g.slice(0,b)),d?Xa(g):g;e.push(g);b-=h;if(!b)break}if(!e.length)return e;e=1a.length?e?W(a[0],b,c,d):a[0]:Ca(a,c,b,e,f)};X.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];B();let h=ca(a);return h?Ba(a,h,b,c,f,e,d):g};X.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?W(a[0],b,c,d):a[0];d=[];const g=B();let h=0;for(let k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};M.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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else eb(this.map,a),this.depth&&eb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Wa(this));this.cache&&this.cache.remove(a);return this}; -function eb(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; -function gb(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -u.close=function(){this.db.close();this.db=null};u.destroy=function(){return hb.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(ib,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const p=c?d+Math.min(m.length-d,c):m.length;for(let n=d;n=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})}; -u.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let e=0,f;em&&!f&&"string"===typeof p&&!isNaN(p)&&(m=k.indexOf(parseInt(p,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:M,Charset:Ta,Encoder:K,Document:T,Worker:N,Resolver:X,IndexedDB:jb,Language:{}}; -export const Index=M;export const Charset=Ta;export const Encoder=K;export const Document=T;export const Worker=N;export const Resolver=X;export const IndexedDB=jb;export const Language={}; \ No newline at end of file +["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]];const da=/[^\p{L}\p{N}]+/u,ea=/(\d{3})/g,fa=/(\D)(\d{3})/g,ha=/(\d{3})(\D)/g,ia="".normalize&&/[\u0300-\u036f]/g;function L(a){if(!this||this.constructor!==L)return new L(...arguments);for(let b=0;b"a1a".split(c).length; +this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,da)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);ia||(this.mapper=new Map(ca));this.rtl=A(a.rtl,!1,this.rtl);this.dedupe=A(a.dedupe,!1,this.dedupe);this.filter=A((c=a.filter)&&new Set(c),null,this.filter);this.matcher=A((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=A((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= +A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);if(this.cache=c=A(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof c?c:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};t.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&M(this);return this};t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&M(this);return this};t.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&M(this);return this};t.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&M(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(M,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ia?a.normalize("NFKD").replace(ia,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d +this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function M(a){a.H=null;a.B.clear();a.G.clear()};async function ja(a){a=a.data;var b=self._index;const c=a.args;var e=a.task;switch(e){case "init":e=a.options||{};(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new N(e);postMessage({id:a.id});break;default:a=a.id,b=b[e].apply(b,c),postMessage("search"===e?{id:a,msg:b}:{id:a})}};let ka=0; +function O(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ka]=function(){h(d)};d.worker.postMessage({id:ka,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==O)return new O(a);let c="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=la(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}P("add");P("append");P("search");P("update");P("remove"); +function P(a){O.prototype[a]=O.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.splice(c.length-1,1));e=new Promise(function(f){b.h[++ka]=f;b.worker.postMessage({task:a,id:ka,args:c})});return d?(e.then(d),this):e}} +function la(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"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ja.toString()],{type:"text/javascript"}))):new window.Worker(E(c)?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function ma(a){Q.call(a,"add");Q.call(a,"append");Q.call(a,"search");Q.call(a,"update");Q.call(a,"remove")}function Q(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);b=this[a].apply(this,b);e&&(b.then?b.then(e):e(b));return b}};function na(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function oa(a,b){b||(b=new Map);for(let c=0,e;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} +function R(a){if(!this)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;gc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= +p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?V.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Aa(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};W.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Da(this,"and",arguments);return Fa.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; +function Fa(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ba(a))return this.result=za(a,b,c,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};W.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Da(this,"xor",arguments);return Ga.call(this,a,b,c,e,d,f,g)}; +function Ga(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Ha.call(this,a,c,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Ha(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e)a=a.slice(e,e+c);d&&(a=V.call(this,a));return a}} +function V(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +X.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};X.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Qa={normalize:function(a){return a.toLowerCase()},numeric:!1,dedupe:!1};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"],["pf","f"]]),Ta=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\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};const Va=/[\x00-\x7F]+/g;const Wa=/[\x00-\x7F]+/g;const Xa=/[\x00-\x7F]+/g;var Ya={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Qa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ra},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ra,matcher:Sa,replacer:Ta},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ra,replacer:Ta.concat([/(?!^)[aeo]/g,""]),matcher:Sa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):$a(p,e,q,d,f);Y(this,m,g,h,a,c)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;Y(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&ab(this));return this};function Y(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]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new R(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} +function $a(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};N.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else fb(this.map,a),this.depth&&fb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&ab(this));this.cache&&this.cache.remove(a);return this}; +function fb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; +function hb(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +t.close=function(){this.db.close();this.db=null};t.destroy=function(){const a=ib.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(jb,"readwrite");for(let b=0;b=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; +t.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{d.onerror=k=>{this.h[a+":"+b]=null;d.abort();d=e=null;g(k)};d.oncomplete=k=>{d=e=this.h[a+":"+b]=null;f(k||!0)};return c.call(this,e)})}; +t.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=h.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:N,Charset:Ya,Encoder:L,Document:U,Worker:O,Resolver:W,IndexedDB:kb,Language:{}}; +export const Index=N;export const Charset=Ya;export const Encoder=L;export const Document=U;export const Worker=O;export const Resolver=W;export const IndexedDB=kb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 4d629d7..831b51b 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,36 +1,36 @@ /**! - * FlexSearch.js v0.8.103 (Bundle/Debug) + * FlexSearch.js v0.8.105 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f; -var v; -function B(a, b, c) { - const e = typeof c, d = typeof a; +(function(self){'use strict'; +var w; +function A(a, c, b) { + const e = typeof b, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { - if (c) { + if (b) { if ("function" === d && e === d) { return function(h) { - return a(c(h)); + return a(b(h)); }; } - b = a.constructor; - if (b === c.constructor) { - if (b === Array) { - return c.concat(a); + c = a.constructor; + if (c === b.constructor) { + if (c === Array) { + return b.concat(a); } - if (b === Map) { - var f = new Map(c); + if (c === Map) { + var f = new Map(b); for (var g of a) { f.set(g[0], g[1]); } return f; } - if (b === Set) { - g = new Set(c); + if (c === Set) { + g = new Set(b); for (f of a.values()) { g.add(f); } @@ -40,32 +40,36 @@ function B(a, b, c) { } return a; } - return c; + return b; } - return "undefined" === d ? b : a; + return "undefined" === d ? c : a; } function C() { return Object.create(null); } -function aa(a, b) { - return b.length - a.length; -} function E(a) { return "string" === typeof a; } -function H(a) { +function I(a) { return "object" === typeof a; } -function I(a, b) { - if (E(b)) { - a = a[b]; +function J(a, c) { + if (E(c)) { + a = a[c]; } else { - for (let c = 0; a && c < b.length; c++) { - a = a[b[c]]; + for (let b = 0; a && b < c.length; b++) { + a = a[c[b]]; } } return a; } +function aa(a) { + let c = 0; + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && c < e.length && (c = e.length); + } + return c; +} ;var ba = [["\u00aa", "a"], ["\u00b2", "2"], ["\u00b3", "3"], ["\u00b9", "1"], ["\u00ba", "o"], ["\u00bc", "1\u20444"], ["\u00bd", "1\u20442"], ["\u00be", "3\u20444"], ["\u00e0", "a"], ["\u00e1", "a"], ["\u00e2", "a"], ["\u00e3", "a"], ["\u00e4", "a"], ["\u00e5", "a"], ["\u00e7", "c"], ["\u00e8", "e"], ["\u00e9", "e"], ["\u00ea", "e"], ["\u00eb", "e"], ["\u00ec", "i"], ["\u00ed", "i"], ["\u00ee", "i"], ["\u00ef", "i"], ["\u00f1", "n"], ["\u00f2", "o"], ["\u00f3", "o"], ["\u00f4", "o"], ["\u00f5", "o"], ["\u00f6", "o"], ["\u00f9", "u"], ["\u00fa", "u"], ["\u00fb", "u"], ["\u00fc", "u"], ["\u00fd", "y"], ["\u00ff", "y"], ["\u0101", "a"], ["\u0103", "a"], ["\u0105", "a"], ["\u0107", "c"], ["\u0109", "c"], ["\u010b", "c"], ["\u010d", "c"], ["\u010f", "d"], ["\u0113", "e"], ["\u0115", "e"], ["\u0117", "e"], ["\u0119", "e"], ["\u011b", "e"], ["\u011d", "g"], ["\u011f", "g"], ["\u0121", "g"], ["\u0123", "g"], ["\u0125", "h"], ["\u0129", "i"], ["\u012b", "i"], ["\u012d", "i"], ["\u012f", "i"], ["\u0133", "ij"], ["\u0135", "j"], ["\u0137", "k"], ["\u013a", "l"], ["\u013c", "l"], ["\u013e", "l"], ["\u0140", "l"], ["\u0144", "n"], ["\u0146", "n"], ["\u0148", "n"], ["\u0149", "n"], ["\u014d", "o"], ["\u014f", "o"], ["\u0151", "o"], ["\u0155", "r"], ["\u0157", "r"], ["\u0159", "r"], ["\u015b", "s"], ["\u015d", "s"], ["\u015f", "s"], ["\u0161", "s"], ["\u0163", "t"], ["\u0165", "t"], ["\u0169", "u"], ["\u016b", "u"], ["\u016d", "u"], ["\u016f", "u"], ["\u0171", "u"], ["\u0173", "u"], ["\u0175", "w"], ["\u0177", @@ -74,195 +78,191 @@ function I(a, b) { ["\u02b2", "j"], ["\u02b3", "r"], ["\u02b4", "\u0279"], ["\u02b5", "\u027b"], ["\u02b6", "\u0281"], ["\u02b7", "w"], ["\u02b8", "y"], ["\u02e0", "\u0263"], ["\u02e1", "l"], ["\u02e2", "s"], ["\u02e3", "x"], ["\u02e4", "\u0295"], ["\u0390", "\u03b9"], ["\u03ac", "\u03b1"], ["\u03ad", "\u03b5"], ["\u03ae", "\u03b7"], ["\u03af", "\u03b9"], ["\u03b0", "\u03c5"], ["\u03ca", "\u03b9"], ["\u03cb", "\u03c5"], ["\u03cc", "\u03bf"], ["\u03cd", "\u03c5"], ["\u03ce", "\u03c9"], ["\u03d0", "\u03b2"], ["\u03d1", "\u03b8"], ["\u03d2", "\u03a5"], ["\u03d3", "\u03a5"], ["\u03d4", "\u03a5"], ["\u03d5", "\u03c6"], ["\u03d6", "\u03c0"], ["\u03f0", "\u03ba"], ["\u03f1", "\u03c1"], ["\u03f2", "\u03c2"], ["\u03f5", "\u03b5"], ["\u0439", "\u0438"], ["\u0450", "\u0435"], ["\u0451", "\u0435"], ["\u0453", "\u0433"], ["\u0457", "\u0456"], ["\u045c", "\u043a"], ["\u045d", "\u0438"], ["\u045e", "\u0443"], ["\u0477", "\u0475"], ["\u04c2", "\u0436"], ["\u04d1", "\u0430"], ["\u04d3", "\u0430"], ["\u04d7", "\u0435"], ["\u04db", "\u04d9"], ["\u04dd", "\u0436"], ["\u04df", "\u0437"], ["\u04e3", "\u0438"], ["\u04e5", "\u0438"], ["\u04e7", "\u043e"], ["\u04eb", "\u04e9"], ["\u04ed", "\u044d"], ["\u04ef", "\u0443"], ["\u04f1", "\u0443"], ["\u04f3", "\u0443"], ["\u04f5", "\u0447"]]; -const ca = /[^\p{L}\p{N}]+/u, da = /(\d{3})/g, ea = /(\D)(\d{3})/g, fa = /(\d{3})(\D)/g, J = "".normalize && /[\u0300-\u036f]/g; -function K(a) { - if (!this || this.constructor !== K) { - return new K(...arguments); +const ca = /[^\p{L}\p{N}]+/u, da = /(\d{3})/g, ea = /(\D)(\d{3})/g, fa = /(\d{3})(\D)/g, K = "".normalize && /[\u0300-\u036f]/g; +function L(a) { + if (!this || this.constructor !== L) { + return new L(...arguments); } - for (let b = 0; b < arguments.length; b++) { - this.assign(arguments[b]); + for (let c = 0; c < arguments.length; c++) { + this.assign(arguments[c]); } } -v = K.prototype; -v.assign = function(a) { - this.normalize = B(a.normalize, !0, this.normalize); - let b = a.include, c = b || a.exclude || a.split; - if ("object" === typeof c) { - let e = !b, d = ""; - a.include || (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; +w = L.prototype; +w.assign = function(a) { + this.normalize = A(a.normalize, !0, this.normalize); + let c = a.include, b = c || a.exclude || a.split, e; + if (b || "" === b) { + if ("object" === typeof b && b.constructor !== RegExp) { + let d = ""; + e = !c; + c || (d += "\\p{Z}"); + b.letter && (d += "\\p{L}"); + b.number && (d += "\\p{N}", e = !!c); + b.symbol && (d += "\\p{S}"); + b.punctuation && (d += "\\p{P}"); + b.control && (d += "\\p{C}"); + if (b = b.char) { + d += "object" === typeof b ? b.join("") : b; + } + try { + this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); + } catch (f) { + console.error("Your split configuration:", b, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; + } + } else { + this.split = b, e = !1 === b || 2 > "a1a".split(b).length; } - try { - this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); - } catch (f) { - this.split = /\s+/; - } - this.numeric = e; + this.numeric = A(a.numeric, e); } else { try { - this.split = B(c, ca, this.split); - } catch (e) { - this.split = /\s+/; + this.split = A(this.split, ca); + } catch (d) { + console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = B(this.numeric, !0); + this.numeric = A(a.numeric, A(this.numeric, !0)); } - this.prepare = B(a.prepare, null, this.prepare); - this.finalize = B(a.finalize, null, this.finalize); - J || (this.mapper = new Map(ba)); - this.rtl = a.rtl || !1; - this.dedupe = B(a.dedupe, !1, this.dedupe); - this.filter = B((c = a.filter) && new Set(c), null, this.filter); - this.matcher = B((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = B((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = B((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = B(a.replacer, null, this.replacer); - this.minlength = B(a.minlength, 1, this.minlength); - this.maxlength = B(a.maxlength, 0, this.maxlength); - if (this.cache = c = B(a.cache, !0, this.cache)) { - this.J = null, this.O = "number" === typeof c ? c : 2e5, this.F = new Map(), this.G = new Map(), this.L = this.K = 128; + this.prepare = A(a.prepare, null, this.prepare); + this.finalize = A(a.finalize, null, this.finalize); + K || (this.mapper = new Map(ba)); + this.rtl = A(a.rtl, !1, this.rtl); + this.dedupe = A(a.dedupe, !1, this.dedupe); + this.filter = A((b = a.filter) && new Set(b), null, this.filter); + this.matcher = A((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = A((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = A((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = A(a.replacer, null, this.replacer); + this.minlength = A(a.minlength, 1, this.minlength); + this.maxlength = A(a.maxlength, 0, this.maxlength); + if (this.cache = b = A(a.cache, !0, this.cache)) { + this.H = null, this.R = "number" === typeof b ? b : 2e5, this.F = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; this.M = null; this.D = ""; this.N = null; if (this.matcher) { - for (const e of this.matcher.keys()) { - this.h += (this.h ? "|" : "") + e; + for (const d of this.matcher.keys()) { + this.h += (this.h ? "|" : "") + d; } } if (this.stemmer) { - for (const e of this.stemmer.keys()) { - this.D += (this.D ? "|" : "") + e; + for (const d of this.stemmer.keys()) { + this.D += (this.D ? "|" : "") + d; } } return this; }; -v.addMatcher = function(a, b) { - if ("object" === typeof a) { - return this.addReplacer(a, b); - } - if (2 > a.length) { - return this.addMapper(a, b); - } - this.matcher || (this.matcher = new Map()); - this.matcher.set(a, b); - this.h += (this.h ? "|" : "") + a; - this.M = null; - this.cache && M(this); - return this; -}; -v.addStemmer = function(a, b) { +w.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); - this.stemmer.set(a, b); + this.stemmer.set(a, c); this.D += (this.D ? "|" : "") + a; this.N = null; this.cache && M(this); return this; }; -v.addFilter = function(a) { +w.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); this.cache && M(this); return this; }; -v.addMapper = function(a, b) { +w.addMapper = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (1 < a.length) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.mapper || (this.mapper = new Map()); - this.mapper.set(a, b); + this.mapper.set(a, c); this.cache && M(this); return this; }; -v.addReplacer = function(a, b) { - "string" === typeof a && (a = new RegExp(a, "g")); +w.addMatcher = function(a, c) { + if ("object" === typeof a) { + return this.addReplacer(a, c); + } + if (2 > a.length && (this.dedupe || this.mapper)) { + return this.addMapper(a, c); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(a, c); + this.h += (this.h ? "|" : "") + a; + this.M = null; + this.cache && M(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, b || ""); + this.replacer.push(a, c); this.cache && M(this); return this; }; -function M(a) { - a.F.clear(); - a.G.clear(); -} -v.encode = function(a) { +w.encode = function(a) { if (this.cache && a.length <= this.K) { - if (this.J) { + if (this.H) { if (this.F.has(a)) { return this.F.get(a); } } else { - this.J = setTimeout(ha, 50, this); + this.H = setTimeout(M, 50, this); } } - this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : J ? a.normalize("NFKD").replace(J, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = K ? a.normalize("NFKD").replace(K, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); - const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let c = [], e = this.split || "" === this.split ? a.split(this.split) : a; + const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; for (let f = 0, g, h; f < e.length; f++) { - if (!(g = h = e[f])) { - continue; - } - if (g.length < this.minlength) { - continue; - } - if (b) { - c.push(g); - continue; - } - if (this.filter && this.filter.has(g)) { - continue; - } - if (this.cache && g.length <= this.L) { - if (this.J) { - var d = this.G.get(g); - if (d || "" === d) { - d && c.push(d); - continue; - } + if ((g = h = e[f]) && !(g.length < this.minlength)) { + if (c) { + b.push(g); } else { - this.J = setTimeout(ha, 50, this); + if (!this.filter || !this.filter.has(g)) { + if (this.cache && g.length <= this.L) { + if (this.H) { + var d = this.G.get(g); + if (d || "" === d) { + d && b.push(d); + continue; + } + } else { + this.H = setTimeout(M, 50, this); + } + } + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, k => this.stemmer.get(k)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + if (g && (this.mapper || this.dedupe && 1 < g.length)) { + d = ""; + for (let k = 0, l = "", m, n; k < g.length; k++) { + m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + } + g = d; + } + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); + if (g && this.replacer) { + for (d = 0; g && d < this.replacer.length; d += 2) { + g = g.replace(this.replacer[d], this.replacer[d + 1]); + } + } + this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + g && b.push(g); + } } } - let k; - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, l => this.stemmer.get(l)), k = 1); - g && k && (g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); - if (g && (this.mapper || this.dedupe && 1 < g.length)) { - d = ""; - for (let l = 0, m = "", r, t; l < g.length; l++) { - r = g.charAt(l), r === m && this.dedupe || ((t = this.mapper && this.mapper.get(r)) || "" === t ? t === m && this.dedupe || !(m = t) || (d += t) : d += m = r); - } - g = d; - } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, l => this.matcher.get(l))); - if (g && this.replacer) { - for (d = 0; g && d < this.replacer.length; d += 2) { - g = g.replace(this.replacer[d], this.replacer[d + 1]); - } - } - this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.O && (this.G.clear(), this.L = this.L / 1.1 | 0)); - g && c.push(g); } - this.finalize && (c = this.finalize(c) || c); - this.cache && a.length <= this.K && (this.F.set(a, c), this.F.size > this.O && (this.F.clear(), this.K = this.K / 1.1 | 0)); - return c; + this.finalize && (b = this.finalize(b) || b); + this.cache && a.length <= this.K && (this.F.set(a, b), this.F.size > this.R && (this.F.clear(), this.K = this.K / 1.1 | 0)); + return b; }; -function ha(a) { - a.J = null; +function M(a) { + a.H = null; a.F.clear(); a.G.clear(); } -;function ia(a) { +;function ha(a) { N.call(a, "add"); N.call(a, "append"); N.call(a, "search"); @@ -271,170 +271,170 @@ function ha(a) { } function N(a) { this[a + "Async"] = function() { - var b = arguments; - const c = b[b.length - 1]; + var c = arguments; + const b = c[c.length - 1]; let e; - "function" === typeof c && (e = c, delete b[b.length - 1]); - b = this[a].apply(this, b); - e && (b.then ? b.then(e) : e(b)); - return b; + "function" === typeof b && (e = b, delete c[c.length - 1]); + c = this[a].apply(this, c); + e && (c.then ? c.then(e) : e(c)); + return c; }; } -;function O(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 5000 | 0); +;function O(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { - e.push(d), e.length === b && (c.push(e), e = []); - } - e.length && c.push(e); - return c; -} -function P(a, b) { - b || (b = new Map()); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b.set(e[0], e[1]); + e.push(d), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } -function ja(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 1000 | 0); - for (const d of a.entries()) { - e.push([d[0], O(d[1])[0]]), e.length === b && (c.push(e), e = []); +function ia(a, c) { + c || (c = new Map()); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c.set(e[0], e[1]); } - e.length && c.push(e); return c; } -function ka(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], P(e[1], d)); +function ja(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], O(d[1])[0]]), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } +function ka(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], ia(e[1], d)); + } + return c; +} function la(a) { - let b = [], c = []; + let c = [], b = []; for (const e of a.keys()) { - c.push(e), 250000 === c.length && (b.push(c), c = []); + b.push(e), 250000 === b.length && (c.push(b), b = []); } - c.length && b.push(c); - return b; + b.length && c.push(b); + return c; } -function ma(a, b) { - b || (b = new Set()); - for (let c = 0; c < a.length; c++) { - b.add(a[c]); +function ma(a, c) { + c || (c = new Set()); + for (let b = 0; b < a.length; b++) { + c.add(a[b]); } - return b; + return c; } -function Q(a, b, c, e, d, f, g = 0) { +function P(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, b, d, f + 1); + return this.export(a, c, d, f + 1); } - if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { const l = this; return k.then(function() { - return Q.call(l, a, b, c, h ? e : null, d, f, g + 1); + return P.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return Q.call(this, a, b, c, h ? e : null, d, f, g + 1); + return P.call(this, a, c, b, h ? e : null, d, f, g + 1); } -;R.prototype.add = function(a, b, c) { - H(a) && (b = a, a = I(b, this.key)); - if (b && (a || 0 === a)) { - if (!c && this.reg.has(a)) { - return this.update(a, b); +;Q.prototype.add = function(a, c, b) { + I(a) && (c = a, a = J(c, this.key)); + if (c && (a || 0 === a)) { + if (!b && this.reg.has(a)) { + return this.update(a, c); } for (let h = 0, k; h < this.field.length; h++) { k = this.C[h]; var e = this.index.get(this.field[h]); if ("function" === typeof k) { - var d = k(b); + var d = k(c); d && e.add(a, d, !1, !0); } else { - if (d = k.H, !d || d(b)) { - k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), na(b, k, this.I, 0, e, a, k[0], c); + if (d = k.I, !d || d(c)) { + k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), na(c, k, this.J, 0, e, a, k[0], b); } } } if (this.tag) { for (e = 0; e < this.B.length; e++) { - var f = this.B[e], g = this.R[e]; + var f = this.B[e], g = this.T[e]; d = this.tag.get(g); let h = C(); if ("function" === typeof f) { - if (f = f(b), !f) { + if (f = f(c), !f) { continue; } } else { - const k = f.H; - if (k && !k(b)) { + const k = f.I; + if (k && !k(c)) { continue; } f.constructor === String && (f = "" + f); - f = I(b, f); + f = J(c, f); } if (d && f) { E(f) && (f = [f]); for (let k = 0, l, m; k < f.length; k++) { - l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), c && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } } else { d || console.warn("Tag '" + g + "' was not found"); } } } - if (this.store && (!c || !this.store.has(a))) { + if (this.store && (!b || !this.store.has(a))) { let h; if (this.A) { h = C(); for (let k = 0, l; k < this.A.length; k++) { l = this.A[k]; - if ((c = l.H) && !c(b)) { + if ((b = l.I) && !b(c)) { continue; } let m; if ("function" === typeof l) { - m = l(b); + m = l(c); if (!m) { continue; } - l = [l.S]; + l = [l.U]; } else if (E(l) || l.constructor === String) { - h[l] = b[l]; + h[l] = c[l]; continue; } - oa(b, h, l, 0, l[0], m); + oa(c, h, l, 0, l[0], m); } } - this.store.set(a, h || b); + this.store.set(a, h || c); } } return this; }; -function oa(a, b, c, e, d, f) { +function oa(a, c, b, e, d, f) { a = a[d]; - if (e === c.length - 1) { - b[d] = f || a; + if (e === b.length - 1) { + c[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { - oa(a, b, c, e, d); + for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { + oa(a, c, b, e, d); } } else { - b = b[d] || (b[d] = C()), d = c[++e], oa(a, b, c, e, d); + c = c[d] || (c[d] = C()), d = b[++e], oa(a, c, b, e, d); } } } -function na(a, b, c, e, d, f, g, h) { +function na(a, c, b, e, d, f, g, h) { if (a = a[g]) { - if (e === b.length - 1) { + if (e === c.length - 1) { if (a.constructor === Array) { - if (c[e]) { - for (b = 0; b < a.length; b++) { - d.add(f, a[b], !0, !0); + if (b[e]) { + for (c = 0; c < a.length; c++) { + d.add(f, a[c], !0, !0); } return; } @@ -444,71 +444,432 @@ function na(a, b, c, e, d, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - na(a, b, c, e, d, f, g, h); + na(a, c, b, e, d, f, g, h); } } else { - g = b[++e], na(a, b, c, e, d, f, g, h); + g = c[++e], na(a, c, b, e, d, f, g, h); } } } } -;function pa(a, b) { - const c = C(), e = []; - for (let d = 0, f; d < b.length; d++) { - f = b[d]; - for (let g = 0; g < f.length; g++) { - c[f[g]] = 1; +;function pa(a, c, b, e, d) { + const f = a.length; + let g = [], h, k; + h = C(); + for (let l = 0, m, n, t, p; l < c; l++) { + for (let q = 0; q < f; q++) { + if (t = a[q], l < t.length && (m = t[l])) { + for (let y = 0; y < m.length; y++) { + n = m[y], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), p = g[k] || (g[k] = []), p.push(n); + } + } } } - for (let d = 0, f; d < a.length; d++) { - f = a[d], 1 === c[f] && (e.push(f), c[f] = 2); + if (a = g.length) { + if (d) { + g = 1 < g.length ? qa(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + } else { + if (a < f) { + return []; + } + g = g[a - 1]; + if (b || e) { + if (g.length > b || e) { + g = g.slice(e, b + e); + } + } + } + } + return g; +} +function qa(a, c, b) { + const e = [], d = C(); + let f; + var g = a.length; + let h; + for (let k = g - 1; 0 <= k; k--) { + if (h = (g = a[k]) && g.length) { + for (let l = 0; l < h; l++) { + if (f = g[l], !d[f]) { + if (d[f] = 1, b) { + b--; + } else { + if (e.push(f), e.length === c) { + return e; + } + } + } + } + } } return e; } -;R.prototype.search = function(a, b, c, e) { - c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); +function ra(a, c, b) { + const e = C(), d = []; + for (let f = 0, g; f < c.length; f++) { + g = c[f]; + for (let h = 0; h < g.length; h++) { + e[g[h]] = 1; + } + } + if (b) { + for (let f = 0, g; f < a.length; f++) { + g = a[f], e[g] && (d.push(g), e[g] = 0); + } + } else { + for (let f = 0, g, h; f < a.result.length; f++) { + for (g = a.result[f], c = 0; c < g.length; c++) { + h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); + } + } + } + return d; +} +;function sa(a, c, b, e) { + if (!a.length) { + return a; + } + if (1 === a.length) { + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? R.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; + continue; + } + b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); + } + h > c && (g = g.slice(0, c), h = c); + if (!d.length && h >= c) { + return e ? R.call(this, g) : g; + } + d.push(g); + c -= h; + if (!c) { + break; + } + } + } + d = 1 < d.length ? [].concat.apply([], d) : d[0]; + return e ? R.call(this, d) : d; +} +;function S(a, c, b) { + var e = b[0]; + if (e.then) { + return Promise.all(b).then(function(m) { + return a[c].apply(a, m); + }); + } + if (e[0] && e[0].index) { + return a[c].apply(a, e); + } + e = []; + let d = [], f = 0, g = 0, h, k, l; + for (let m = 0, n; m < b.length; m++) { + if (n = b[m]) { + let t; + if (n.constructor === T) { + t = n.result; + } else if (n.constructor === Array) { + t = n; + } else { + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = k, n.enrich = h; + } else if (n.and) { + t = a.and(n.and); + } else if (n.or) { + t = a.or(n.or); + } else if (n.xor) { + t = a.xor(n.xor); + } else if (n.not) { + t = a.not(n.not); + } else { + continue; + } + } + if (t.then) { + d.push(t); + } else if (t.length) { + e[m] = t; + } else if (!l && ("and" === c || "xor" === c)) { + e = []; + break; + } + } + } + return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; +} +;T.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = S(this, "or", arguments); + return ta.call(this, a, c, b, e, d, f); +}; +function ta(a, c, b, e, d, f) { + if (c.length) { + const g = this; + return Promise.all(c).then(function(h) { + a = []; + for (let k = 0, l; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); + } + return ta.call(g, a, [], b, e, d, f); + }); + } + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = qa(a, b, e), e = 0)); + return f ? this.resolve(b, e, d) : this; +} +;T.prototype.and = function() { + let a = this.result.length, c, b, e, d; + if (!a) { + const f = arguments[0]; + f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); + } + if (a) { + const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = S(this, "and", arguments); + return ua.call(this, f, g, h, k, l, m, n); + } + return d ? this.resolve(c, b, e) : this; +}; +function ua(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return ua.call(h, a, [], b, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + if (c = aa(a)) { + return this.result = pa(a, c, b, e, g), f ? d ? R.call(this.index, this.result) : this.result : this; + } + this.result = []; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(b, e, d) : this; +} +;T.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = S(this, "xor", arguments); + return va.call(this, a, c, b, e, d, f, g); +}; +function va(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return va.call(h, a, [], b, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = wa.call(this, a, b, e, f, this.h), f ? d ? R.call(this.index, this.result) : this.result : this; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(b, e, d) : this; +} +function wa(a, c, b, e, d) { + const f = [], g = C(); + let h = 0; + for (let k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); + for (let m = 0, n; m < l.length; m++) { + if (n = l[m]) { + for (let t = 0, p; t < n.length; t++) { + p = n[t], g[p] = g[p] ? 2 : 1; + } + } + } + } + } + for (let k = 0, l, m = 0; k < h; k++) { + for (let n = 0, t; n < a.length; n++) { + if (t = a[n]) { + if (l = t[k]) { + for (let p = 0, q; p < l.length; p++) { + if (q = l[p], 1 === g[q]) { + if (b) { + b--; + } else { + if (e) { + if (f.push(q), f.length === c) { + return f; + } + } else { + const y = k + (n ? d : 0); + f[y] || (f[y] = []); + f[y].push(q); + if (++m === c) { + return f; + } + } + } + } + } + } + } + } + } + return f; +} +;T.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = S(this, "not", arguments); + return xa.call(this, a, c, b, e, d, f, g); +}; +function xa(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return xa.call(h, a, [], b, e, d, f, g); + }); + } + if (a.length && this.result.length) { + this.result = ya.call(this, a, b, e, f); + } else if (f) { + return this.resolve(b, e, d); + } + return f ? d ? R.call(this.index, this.result) : this.result : this; +} +function ya(a, c, b, e) { + const d = []; + a = new Set(a.flat().flat()); + for (let f = 0, g, h = 0; f < this.result.length; f++) { + if (g = this.result[f]) { + for (let k = 0, l; k < g.length; k++) { + if (l = g[k], !a.has(l)) { + if (b) { + b--; + } else { + if (e) { + if (d.push(l), d.length === c) { + return d; + } + } else { + if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { + return d; + } + } + } + } + } + } + } + return d; +} +;function T(a) { + if (!this || this.constructor !== T) { + return new T(a); + } + if (a && a.index) { + return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; + } + this.index = null; + this.result = a || []; + this.h = 0; +} +T.prototype.limit = function(a) { + if (this.result.length) { + const c = []; + let b = 0; + for (let e = 0, d; e < this.result.length; e++) { + if (d = this.result[e], d.length + b < a) { + c[e] = d, b += d.length; + } else { + c[e] = d.slice(0, a - b); + this.result = c; + break; + } + } + } + return this; +}; +T.prototype.offset = function(a) { + if (this.result.length) { + const c = []; + let b = 0; + for (let e = 0, d; e < this.result.length; e++) { + d = this.result[e], d.length + b < a ? b += d.length : (c[e] = d.slice(a - b), b = a); + } + this.result = c; + } + return this; +}; +T.prototype.boost = function(a) { + this.h += a; + return this; +}; +T.prototype.resolve = function(a, c, b) { + const e = this.result, d = this.index; + this.result = this.index = null; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), sa.call(d, e, a || 100, c, b)) : e; +}; +C(); +Q.prototype.search = function(a, c, b, e) { + b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = []; var f = []; - let g, h, k, l, m, r, t = 0, p; - if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - var n = c.pluck; - h = c.merge; - l = n || c.field || c.index; - m = this.tag && c.tag; - g = this.store && c.enrich; - k = c.suggest; - p = c.highlight; - b = c.limit || b; - r = c.offset || 0; - b || (b = 100); + let g, h, k, l, m, n, t = 0, p, q; + if (b) { + b.constructor === Array && (b = {index:b}); + a = b.query || a; + var y = b.pluck; + h = b.merge; + l = y || b.field || (l = b.index) && (l.index ? null : l); + m = this.tag && b.tag; + k = b.suggest; + p = !0; + this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + g = this.store && b.enrich && p; + q = b.highlight && g; + c = b.limit || c; + n = b.offset || 0; + c || (c = 100); if (m) { m.constructor !== Array && (m = [m]); var u = []; - for (let x = 0, q; x < m.length; x++) { - q = m[x]; - if (E(q)) { + for (let x = 0, r; x < m.length; x++) { + r = m[x]; + if (E(r)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (q.field && q.tag) { - var w = q.tag; - if (w.constructor === Array) { - for (var y = 0; y < w.length; y++) { - u.push(q.field, w[y]); + if (r.field && r.tag) { + var v = r.tag; + if (v.constructor === Array) { + for (var z = 0; z < v.length; z++) { + u.push(r.field, v[z]); } } else { - u.push(q.field, w); + u.push(r.field, v); } } else { - w = Object.keys(q); - for (let D = 0, A, z; D < w.length; D++) { - if (A = w[D], z = q[A], z.constructor === Array) { - for (y = 0; y < z.length; y++) { - u.push(A, z[y]); + v = Object.keys(r); + for (let D = 0, F, B; D < v.length; D++) { + if (F = v[D], B = r[F], B.constructor === Array) { + for (z = 0; z < B.length; z++) { + u.push(F, B[z]); } } else { - u.push(A, z); + u.push(F, B); } } } @@ -521,137 +882,137 @@ function na(a, b, c, e, d, f, g, h) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - n = qa.call(this, u[f], u[f + 1], b, r, g), d.push({field:u[f], tag:u[f + 1], result:n}); + y = za.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); } } return e.length ? Promise.all(e).then(function(x) { - for (let q = 0; q < x.length; q++) { - d[q].result = x[q]; + for (let r = 0; r < x.length; r++) { + d[r].result = x[r]; } return d; }) : d; } } - E(l) && (l = [l]); + l && l.constructor !== Array && (l = [l]); } l || (l = this.field); u = !e && (this.worker || this.db) && []; - for (let x = 0, q, D, A; x < l.length; x++) { + for (let x = 0, r, D, F; x < l.length; x++) { D = l[x]; - let z; - E(D) || (z = D, D = z.field, a = z.query || a, b = z.limit || b, r = z.offset || r, k = z.suggest || k, g = this.store && (z.enrich || g)); + let B; + E(D) || (B = D, D = B.field, a = B.query || a, c = B.limit || c, n = B.offset || n, k = B.suggest || k, g = this.store && (B.enrich || g)); if (e) { - q = e[x]; + r = e[x]; } else { - if (w = z || c, y = this.index.get(D), m && (w.enrich = !1), u) { - u[x] = y.search(a, b, w); - w && g && (w.enrich = g); + if (v = B || b, z = this.index.get(D), m && (v.enrich = !1), u) { + u[x] = z.search(a, c, v); + v && g && (v.enrich = g); continue; } else { - q = y.search(a, b, w), w && g && (w.enrich = g); + r = z.search(a, c, v), v && g && (v.enrich = g); } } - A = q && q.length; - if (m && A) { - w = []; - y = 0; - for (let G = 0, F, L; G < m.length; G += 2) { - F = this.tag.get(m[G]); - if (!F) { + F = r && (p ? r.length : r.result.length); + if (m && F) { + v = []; + z = 0; + for (let G = 0, H, Oa; G < m.length; G += 2) { + H = this.tag.get(m[G]); + if (!H) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { continue; } else { - return d; + return p ? d : new T(d); } } - if (L = (F = F && F.get(m[G + 1])) && F.length) { - y++, w.push(F); + if (Oa = (H = H && H.get(m[G + 1])) && H.length) { + z++, v.push(H); } else if (!k) { - return d; + return p ? d : new T(d); } } - if (y) { - q = pa(q, w); - A = q.length; - if (!A && !k) { - return d; + if (z) { + r = ra(r, v, p); + F = r.length; + if (!F && !k) { + return p ? r : new T(r); } - y--; + z--; } } - if (A) { - f[t] = D, d.push(q), t++; + if (F) { + f[t] = D, d.push(r), t++; } else if (1 === l.length) { - return d; + return p ? d : new T(d); } } if (u) { const x = this; - return Promise.all(u).then(function(q) { - return q.length ? x.search(a, b, c, q) : q; + return Promise.all(u).then(function(r) { + return r.length ? x.search(a, c, b, r) : r; }); } if (!t) { - return d; + return p ? d : new T(d); } - if (n && (!g || !this.store)) { + if (y && (!g || !this.store)) { return d[0]; } u = []; - for (let x = 0, q; x < f.length; x++) { - q = d[x]; - g && q.length && !q[0].doc && q.length && (q = ra.call(this, q)); - if (n) { - return q; + for (let x = 0, r; x < f.length; x++) { + r = d[x]; + g && r.length && !r[0].doc && (r = R.call(this, r)); + if (y) { + return p ? r : new T(r); } - d[x] = {field:f[x], result:q}; + d[x] = {field:f[x], result:r}; } - return h ? sa(d, b) : p ? ta(d, a, this.index, this.field, this.C, p) : d; + return h ? Aa(d, c) : q ? Ba(d, a, this.index, this.field, this.C, q) : d; }; -function ta(a, b, c, e, d, f) { +function Ba(a, c, b, e, d, f) { let g, h, k; - for (let m = 0, r, t, p, n, u; m < a.length; m++) { - r = a[m].result; + for (let m = 0, n, t, p, q, y; m < a.length; m++) { + n = a[m].result; t = a[m].field; - n = c.get(t); - p = n.encoder; - k = n.tokenize; - u = d[e.indexOf(t)]; - p !== g && (g = p, h = g.encode(b)); - for (let w = 0; w < r.length; w++) { - let y = ""; - var l = I(r[w].doc, u); - let x = g.encode(l); + q = b.get(t); + p = q.encoder; + k = q.tokenize; + y = d[e.indexOf(t)]; + p !== g && (g = p, h = g.encode(c)); + for (let u = 0; u < n.length; u++) { + let v = ""; + var l = J(n[u].doc, y); + let z = g.encode(l); l = l.split(g.split); - for (let q = 0, D, A; q < x.length; q++) { - D = x[q]; - A = l[q]; - let z; - for (let G = 0, F; G < h.length; G++) { - if (F = h[G], "strict" === k) { - if (D === F) { - y += (y ? " " : "") + f.replace("$1", A); - z = !0; + for (let x = 0, r, D; x < z.length; x++) { + r = z[x]; + D = l[x]; + let F; + for (let B = 0, G; B < h.length; B++) { + if (G = h[B], "strict" === k) { + if (r === G) { + v += (v ? " " : "") + f.replace("$1", D); + F = !0; break; } } else { - const L = D.indexOf(F); - if (-1 < L) { - y += (y ? " " : "") + A.substring(0, L) + f.replace("$1", A.substring(L, F.length)) + A.substring(L + F.length); - z = !0; + const H = r.indexOf(G); + if (-1 < H) { + v += (v ? " " : "") + D.substring(0, H) + f.replace("$1", D.substring(H, G.length)) + D.substring(H + G.length); + F = !0; break; } } } - z || (y += (y ? " " : "") + l[q]); + F || (v += (v ? " " : "") + l[x]); } - r[w].highlight = y; + n[u].highlight = v; } } return a; } -function sa(a, b) { - const c = [], e = C(); +function Aa(a, c) { + const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; @@ -659,112 +1020,115 @@ function sa(a, b) { if (l = g[h], k = l.id, m = e[k]) { m.push(f.field); } else { - if (c.length === b) { - return c; + if (b.length === c) { + return b; } l.field = e[k] = [f.field]; - c.push(l); + b.push(l); } } } - return c; + return b; } -function qa(a, b, c, e, d) { +function za(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - e) && 0 < a) { - if (a > c || e) { - f = f.slice(e, e + c); + if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if (a > b || e) { + f = f.slice(e, e + b); } - d && (f = ra.call(this, f)); + d && (f = R.call(this, f)); return f; } } -function ra(a) { - const b = Array(a.length); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b[c] = {id:e, doc:this.store.get(e)}; +function R(a) { + if (!this || !this.store) { + return a; } - return b; + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; + } + return c; } -;function R(a) { - if (!this || this.constructor !== R) { - return new R(a); +;function Q(a) { + if (!this || this.constructor !== Q) { + return new Q(a); } - const b = a.document || a.doc || a; - var c; + const c = a.document || a.doc || a; + var b; this.C = []; this.field = []; - this.I = []; - this.key = (c = b.key || b.id) && S(c, this.I) || "id"; + this.J = []; + this.key = (b = c.key || c.id) && U(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); - this.A = (c = b.store || null) && c && !0 !== c && []; - this.store = c && new Map(); - this.cache = (c = a.cache || null) && new T(c); + this.A = (b = c.store || null) && b && !0 !== b && []; + this.store = b && new Map(); + this.cache = (b = a.cache || null) && new V(b); a.cache = !1; - c = new Map(); - let e = b.index || b.field || b; + b = new Map(); + let e = c.index || c.field || c; E(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], E(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, c.set(f, new U(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = S(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].H = g.filter)), this.field[d] = f; + f = e[d], E(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new W(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = U(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { - a = b.store; + a = c.store; E(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = S(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].H = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = U(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } - this.index = c; + this.index = b; this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { + if (b = c.tag) { + if ("string" === typeof b && (b = [b]), b.length) { this.tag = new Map(); this.B = []; - this.R = []; - for (let d = 0, f, g; d < c.length; d++) { - f = c[d]; + this.T = []; + for (let d = 0, f, g; d < b.length; d++) { + f = b[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = S(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].H = f.filter)); - this.R[d] = g; + f.custom ? this.B[d] = f.custom : (this.B[d] = U(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + this.T[d] = g; this.tag.set(g, new Map()); } } } } -function S(a, b) { - const c = a.split(":"); +function U(a, c) { + const b = a.split(":"); let e = 0; - for (let d = 0; d < c.length; d++) { - a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); + for (let d = 0; d < b.length; d++) { + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); } - e < c.length && (c.length = e); - return 1 < e ? c : c[0]; + e < b.length && (b.length = e); + return 1 < e ? b : b[0]; } -v = R.prototype; -v.append = function(a, b) { - return this.add(a, b, !0); +w = Q.prototype; +w.append = function(a, c) { + return this.add(a, c, !0); }; -v.update = function(a, b) { - return this.remove(a).add(a, b); +w.update = function(a, c) { + return this.remove(a).add(a, c); }; -v.remove = function(a) { - H(a) && (a = I(a, this.key)); - for (var b of this.index.values()) { - b.remove(a, !0); +w.remove = function(a) { + I(a) && (a = J(a, this.key)); + for (var c of this.index.values()) { + c.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { - for (let c of this.tag.values()) { - for (let e of c) { - b = e[0]; + for (let b of this.tag.values()) { + for (let e of b) { + c = e[0]; const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); + -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); } } } @@ -774,7 +1138,7 @@ v.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -v.clear = function() { +w.clear = function() { for (const a of this.index.values()) { a.clear(); } @@ -786,94 +1150,94 @@ v.clear = function() { this.store && this.store.clear(); return this; }; -v.contain = function(a) { +w.contain = function(a) { return this.reg.has(a); }; -v.cleanup = function() { +w.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -v.get = function(a) { +w.get = function(a) { return this.store.get(a); }; -v.set = function(a, b) { - this.store.set(a, b); +w.set = function(a, c) { + this.store.set(a, c); return this; }; -v.searchCache = ua; -v.export = function(a, b, c = 0, e = 0) { - if (c < this.field.length) { - const g = this.field[c]; - if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { +w.searchCache = Ca; +w.export = function(a, c, b = 0, e = 0) { + if (b < this.field.length) { + const g = this.field[b]; + if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { const h = this; - return b.then(function() { - return h.export(a, g, c + 1); + return c.then(function() { + return h.export(a, g, b + 1); }); } - return this.export(a, g, c + 1); + return this.export(a, g, b + 1); } let d, f; switch(e) { case 0: d = "reg"; f = la(this.reg); - b = null; + c = null; break; case 1: d = "tag"; f = ja(this.tag, this.reg.size); - b = null; + c = null; break; case 2: d = "doc"; f = O(this.store); - b = null; + c = null; break; case 3: d = "cfg"; f = {}; - b = null; + c = null; break; default: return; } - return Q.call(this, a, b, d, f, c, e); + return P.call(this, a, c, d, f, b, e); }; -v.import = function(a, b) { - if (b) { - E(b) && (b = JSON.parse(b)); +w.import = function(a, c) { + if (c) { + "string" === typeof c && (c = JSON.parse(c)); a = a.split("."); "json" === a[a.length - 1] && a.pop(); - var c = 2 < a.length ? a[0] : ""; + var b = 2 < a.length ? a[0] : ""; a = 2 < a.length ? a[2] : a[1]; - if (c) { - return this.index.get(c).import(a, b); + if (b) { + return this.index.get(b).import(a, c); } switch(a) { case "reg": this.fastupdate = !1; - this.reg = ma(b, this.reg); + this.reg = ma(c, this.reg); for (let e = 0, d; e < this.field.length; e++) { d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = ka(b, this.tag); + this.tag = ka(c, this.tag); break; case "doc": - this.store = P(b, this.store); + this.store = ia(c, this.store); } } }; -ia(R.prototype); -function ua(a, b, c) { +ha(Q.prototype); +function Ca(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new T()); + this.cache || (this.cache = new V()); let e = this.cache.get(a); if (!e) { - e = this.search(a, b, c); + e = this.search(a, c, b); if (e.then) { const d = this; e.then(function(f) { @@ -885,77 +1249,76 @@ function ua(a, b, c) { } return e; } -function T(a) { +function V(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -T.prototype.set = function(a, b) { - this.cache.set(this.h = a, b); +V.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); }; -T.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; +V.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; }; -T.prototype.remove = function(a) { - for (const b of this.cache) { - const c = b[0]; - b[1].includes(a) && this.cache.delete(c); +V.prototype.remove = function(a) { + for (const c of this.cache) { + const b = c[0]; + c[1].includes(a) && this.cache.delete(b); } }; -T.prototype.clear = function() { +V.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const va = {normalize:function(a) { +const Da = {normalize:function(a) { return a.toLowerCase(); -}, dedupe:!1}; -const wa = 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 xa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), ya = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const za = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const Aa = /[\x00-\x7F]+/g; -const Ba = /[\x00-\x7F]+/g; -const Ca = /[\x00-\x7F]+/g; -var Da = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:va, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:wa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:wa, matcher:xa, replacer:ya}, LatinExtra:{normalize:!0, dedupe:!0, mapper:wa, replacer:ya.concat([/(?!^)[aeo]/g, ""]), matcher:xa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { - for (let c = 0; c < a.length; c++) { - var b = a[c]; - let e = b.charAt(0), d = za[e]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = za[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { +}, numeric:!1, dedupe:!1}; +const Ea = 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 Fa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ga = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +const Ha = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const Ia = /[\x00-\x7F]+/g; +const Ja = /[\x00-\x7F]+/g; +const Ka = /[\x00-\x7F]+/g; +var La = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Da, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ea}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ea, matcher:Fa, replacer:Ga}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ea, replacer:Ga.concat([/(?!^)[aeo]/g, ""]), matcher:Fa}, LatinSoundex:{normalize:!0, 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 = Ha[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ha[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = e; + a[b] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Aa, " "); + return ("" + a).replace(Ia, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ba, ""); + return ("" + a).replace(Ja, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ca, " "); + return ("" + a).replace(Ka, " "); }}}; -const Ea = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -C(); -U.prototype.add = function(a, b, c, e) { - if (b && (a || 0 === a)) { - if (!e && !c && this.reg.has(a)) { - return this.update(a, b); +const Ma = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +W.prototype.add = function(a, c, b, e) { + if (c && (a || 0 === a)) { + if (!e && !b && this.reg.has(a)) { + return this.update(a, c); } - b = this.encoder.encode(b); - if (e = b.length) { - const l = C(), m = C(), r = this.depth, t = this.resolution; + c = this.encoder.encode(c); + if (e = c.length) { + const l = C(), m = C(), n = this.depth, t = this.resolution; for (let p = 0; p < e; p++) { - let n = b[this.rtl ? e - 1 - p : p]; - var d = n.length; - if (d && (r || !m[n])) { - var f = this.score ? this.score(b, n, p, null, 0) : V(t, e, p), g = ""; + let q = c[this.rtl ? e - 1 - p : p]; + var d = q.length; + if (d && (n || !m[q])) { + var f = this.score ? this.score(c, q, p, null, 0) : X(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var h = d; h > f; h--) { - g = n.substring(f, h); - var k = this.score ? this.score(b, n, p, g, f) : V(t, e, p, d, f); - W(this, m, g, k, a, c); + g = q.substring(f, h); + var k = this.score ? this.score(c, q, p, g, f) : X(t, e, p, d, f); + Y(this, m, g, k, a, b); } } break; @@ -963,24 +1326,24 @@ U.prototype.add = function(a, b, c, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - g = n[h] + g, k = this.score ? this.score(b, n, p, g, h) : V(t, e, p, d, h), W(this, m, g, k, a, c); + g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : X(t, e, p, d, h), Y(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { for (h = 0; h < d; h++) { - g += n[h], W(this, m, g, f, a, c); + g += q[h], Y(this, m, g, f, a, b); } break; } default: - if (W(this, m, n, f, a, c), r && 1 < e && p < e - 1) { - for (d = C(), g = this.P, f = n, h = Math.min(r + 1, e - p), d[f] = 1, k = 1; k < h; k++) { - if ((n = b[this.rtl ? e - 1 - p - k : p + k]) && !d[n]) { - d[n] = 1; - const u = this.score ? this.score(b, f, p, n, k) : V(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), w = this.bidirectional && n > f; - W(this, l, w ? f : n, u, a, c, w ? n : f); + if (Y(this, m, q, f, a, b), n && 1 < e && p < e - 1) { + for (d = C(), g = this.S, f = q, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { + if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { + d[q] = 1; + const y = this.score ? this.score(c, f, p, q, k) : X(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; + Y(this, l, u ? f : q, y, a, b, u ? q : f); } } } @@ -992,316 +1355,217 @@ U.prototype.add = function(a, b, c, e) { } return this; }; -function W(a, b, c, e, d, f, g) { +function Y(a, c, b, e, d, f, g) { let h = g ? a.ctx : a.map, k; - if (!b[c] || g && !(k = b[c])[g]) { - g ? (b = k || (b[c] = C()), 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 = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((b = a.reg.get(d)) ? b.push(h) : a.reg.set(d, [h]))); + if (!c[b] || g && !(k = c[b])[g]) { + g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function V(a, b, c, e, d) { - return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; +function X(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 Fa(a, b, c) { - if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a; - } - let e = []; - for (let d = 0, f, g; d < a.length; d++) { - if ((f = a[d]) && (g = f.length)) { - if (c) { - if (c >= g) { - c -= g; - continue; - } - c < g && (f = b ? f.slice(c, c + b) : f.slice(c), g = f.length, c = 0); - } - if (e.length) { - g > b && (f = f.slice(0, b), g = f.length); - } else { - if (g >= b) { - return g > b && (f = f.slice(0, b)), f; - } - } - e.push(f); - b -= g; - if (!b) { - break; - } - } - } - return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; -} -;U.prototype.search = function(a, b, c) { - c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); +;W.prototype.search = function(a, c, b) { + b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); var e = [], d = 0; - if (c) { - a = c.query || a; - b = c.limit || b; - d = c.offset || 0; - var f = c.context; - var g = c.suggest; + if (b) { + a = b.query || a; + c = b.limit || c; + d = b.offset || 0; + var f = b.context; + var g = b.suggest; var h = !0; - var k = c.resolution; + var k = b.resolution; } else { h = !0; } - c = this.encoder.encode(a); - a = c.length; - b || !h || (b = 100); + b = this.encoder.encode(a); + a = b.length; + c = c || (h ? 100 : 0); if (1 === a) { - return X.call(this, c[0], "", b, d); + return Na.call(this, b[0], "", c, d, h); } f = this.depth && !1 !== f; if (2 === a && f && !g) { - return X.call(this, c[0], c[1], b, d); + return Na.call(this, b[0], b[1], c, d, h); } - var l = h = 0; - if (1 < a) { - var m = C(); - const t = []; - for (let p = 0, n; p < a; p++) { - if ((n = c[p]) && !m[n]) { - if (g || Y(this, n)) { - t.push(n), m[n] = 1; - } else { - return e; - } - const u = n.length; - h = Math.max(h, u); - l = l ? Math.min(l, u) : u; - } - } - c = t; - a = c.length; + h = C(); + let l = 0; + if (1 < a && f) { + var m = b[0]; + l = 1; } - if (!a) { - return e; - } - m = 0; - if (1 === a) { - return X.call(this, c[0], "", b, d); - } - if (2 === a && f && !g) { - return X.call(this, c[0], c[1], b, d); - } - if (1 < a) { - if (f) { - var r = c[0]; - m = 1; - } else { - 9 < h && 3 < h / l && c.sort(aa); - } - } - k || 0 === k || (k = this.resolution); - for (let t, p; m < a; m++) { - p = c[m]; - r ? (t = Y(this, p, r), t = Ga(t, e, g, this.P), g && !1 === t && e.length || (r = p)) : (t = Y(this, p, ""), t = Ga(t, e, g, k)); - if (t) { - return t; - } - if (g && m === a - 1) { - f = e.length; - if (!f) { - if (r) { - r = ""; - m = -1; - continue; - } - return e; - } - if (1 === f) { - return Fa(e[0], b, d); - } - } - } - a: { - r = g; - f = e.length; - g = []; - a = C(); - for (let t = 0, p, n, u, w; t < k; t++) { - for (h = 0; h < f; h++) { - if (u = e[h], t < u.length && (p = u[t])) { - for (l = 0; l < p.length; l++) { - n = p[l], (c = a[n]) ? a[n]++ : (c = 0, a[n] = 1), w = g[c] || (g[c] = []), w.push(n); + k || 0 === k || (k = m ? this.S : this.resolution); + for (let q, y; l < a; l++) { + if ((y = b[l]) && !h[y]) { + h[y] = 1; + q = Pa(this, y, m); + a: { + f = q; + var n = e, t = g, p = k; + let u = []; + if (f && f.length) { + if (f.length <= p) { + n.push(f); + q = void 0; + break a; } - } - } - } - if (k = g.length) { - if (r) { - if (1 < g.length) { - b: { - for (k = [], e = C(), r = g.length, c = r - 1; 0 <= c; c--) { - for (r = g[c], a = r.length, h = 0; h < a; h++) { - if (f = r[h], !e[f]) { - if (e[f] = 1, d) { - d--; - } else { - if (k.push(f), k.length === b) { - break b; - } - } - } - } + for (let v = 0, z; v < p; v++) { + if (z = f[v]) { + u[v] = z; } } - } else { - k = (g = g[0]).length > b || d ? g.slice(d, b + d) : g; - } - g = k; - } else { - if (k < f) { - e = []; - break a; - } - g = g[k - 1]; - if (b || d) { - if (g.length > b || d) { - g = g.slice(d, b + d); + if (u.length) { + n.push(u); + q = void 0; + break a; } } + q = t ? void 0 : u; } + if (q) { + e = q; + break; + } + m && (g && q && e.length || (m = y)); } - e = g; + g && m && l === a - 1 && !e.length && (m = "", l = -1, h = C()); } - return e; + a: { + m = e.length; + a = e; + if (1 < m) { + a = pa(e, k, c, d, g); + } else if (1 === m) { + g = sa.call(null, e[0], c, d); + break a; + } + g = a; + } + return g; }; -function X(a, b, c, e) { - return (a = Y(this, a, b)) && a.length ? Fa(a, c, e) : []; +function Na(a, c, b, e, d) { + a = Pa(this, a, c); + d = !0; + return a && a.length ? d ? sa.call(this, a, b, e) : new T(a) : d ? [] : new T(); } -function Ga(a, b, c, e) { - let d = []; - if (a) { - e = Math.min(a.length, e); - for (let f = 0, g; f < e; f++) { - (g = a[f]) && g && (d[f] = g); - } - if (d.length) { - b.push(d); - return; - } - } - return !c && d; -} -function Y(a, b, c) { +function Pa(a, c, b) { let e; - c && (e = a.bidirectional && b > c); - a = c ? (a = a.ctx.get(e ? b : c)) && a.get(e ? c : b) : a.map.get(b); + b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); + a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;U.prototype.remove = function(a, b) { - const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (c) { +;W.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { if (this.fastupdate) { - for (let e = 0, d; e < c.length; e++) { - if (d = c[e]) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { if (2 > d.length) { d.pop(); } else { const f = d.indexOf(a); - f === c.length - 1 ? d.pop() : d.splice(f, 1); + f === b.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - Ha(this.map, a), this.depth && Ha(this.ctx, a); + Qa(this.map, a), this.depth && Qa(this.ctx, a); } - b || this.reg.delete(a); + c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Ha(a, b) { - let c = 0; +function Qa(a, c) { + let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { if ((d = a[e]) && d.length) { - if (f = d.indexOf(b), 0 <= f) { - 1 < d.length ? (d.splice(f, 1), c++) : delete a[e]; + if (f = d.indexOf(c), 0 <= f) { + 1 < d.length ? (d.splice(f, 1), b++) : delete a[e]; break; } else { - c++; + b++; } } } } else { - for (let e of a) { - const d = e[0], f = Ha(e[1], b); - f ? c += f : a.delete(d); + for (let e of a.entries()) { + const d = e[0], f = Qa(e[1], c); + f ? b += f : a.delete(d); } } - return c; + return b; } -;function U(a, b) { - if (!this || this.constructor !== U) { - return new U(a); +;function W(a, c) { + if (!this || this.constructor !== W) { + return new W(a); } if (a) { - var c = E(a) ? a : a.preset; - c && (Ea[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ea[c], a)); + var b = E(a) ? a : a.preset; + b && (Ma[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ma[b], a)); } else { a = {}; } - c = a.context; - const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? Da[a.encoder] : a.encode || a.encoder || va; - this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; + b = a.context; + const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? La[a.encoder] : a.encode || a.encoder || Da; + this.encoder = d.encode ? d : "object" === typeof d ? new L(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = c = a.tokenize || "strict"; - this.depth = "strict" === c && e.depth || 0; + this.tokenize = b = a.tokenize || "strict"; + this.depth = "strict" === b && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; - c = !1; + b = !1; this.map = new Map(); this.ctx = new Map(); - this.reg = b || (this.fastupdate ? new Map() : new Set()); - this.P = e.resolution || 3; + this.reg = c || (this.fastupdate ? new Map() : new Set()); + this.S = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new T(c); + this.cache = (b = a.cache || null) && new V(b); } -v = U.prototype; -v.clear = function() { +w = W.prototype; +w.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); this.cache && this.cache.clear(); return this; }; -v.append = function(a, b) { - return this.add(a, b, !0); +w.append = function(a, c) { + return this.add(a, c, !0); }; -v.contain = function(a) { +w.contain = function(a) { return this.reg.has(a); }; -v.update = function(a, b) { - const c = this, e = this.remove(a); - return e && e.then ? e.then(() => c.add(a, b)) : this.add(a, b); +w.update = function(a, c) { + const b = this, e = this.remove(a); + return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function Ia(a) { - let b = 0; +function Ra(a) { + let c = 0; if (a.constructor === Array) { - for (let c = 0, e; c < a.length; c++) { - (e = a[c]) && (b += e.length); + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && (c += e.length); } } else { - for (const c of a) { - const e = c[0], d = Ia(c[1]); - d ? b += d : a.delete(e); + for (const b of a) { + const e = b[0], d = Ra(b[1]); + d ? c += d : a.delete(e); } } - return b; + return c; } -v.cleanup = function() { +w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Ia(this.map); - this.depth && Ia(this.ctx); + Ra(this.map); + this.depth && Ra(this.ctx); return this; }; -v.searchCache = ua; -v.export = function(a, b, c, e = 0) { +w.searchCache = Ca; +w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: @@ -1323,40 +1587,40 @@ v.export = function(a, b, c, e = 0) { default: return; } - return Q.call(this, a, b, d, f, c, e); + return P.call(this, a, c, d, f, b, e); }; -v.import = function(a, b) { - if (b) { - switch(E(b) && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { +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(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = ma(b, this.reg); + this.reg = ma(c, this.reg); break; case "map": - this.map = P(b, this.map); + this.map = ia(c, this.map); break; case "ctx": - this.ctx = ka(b, this.ctx); + this.ctx = ka(c, this.ctx); } } }; -v.serialize = function(a = !0) { +w.serialize = function(a = !0) { if (!this.reg.size) { return ""; } - let b = "", c = ""; + let c = "", b = ""; for (var e of this.reg.keys()) { - c || (c = typeof e), b += (b ? "," : "") + ("string" === c ? '"' + e + '"' : e); + b || (b = typeof e), c += (c ? "," : "") + ("string" === b ? '"' + e + '"' : e); } - b = "index.reg=new Set([" + b + "]);"; + c = "index.reg=new Set([" + c + "]);"; e = ""; for (var d of this.map.entries()) { var f = d[0], g = d[1], h = ""; - for (let m = 0, r; m < g.length; m++) { - r = g[m] || [""]; + for (let m = 0, n; m < g.length; m++) { + n = g[m] || [""]; var k = ""; - for (var l = 0; l < r.length; l++) { - k += (k ? "," : "") + ("string" === c ? '"' + r[l] + '"' : r[l]); + for (var l = 0; l < n.length; l++) { + k += (k ? "," : "") + ("string" === b ? '"' + n[l] + '"' : n[l]); } k = "[" + k + "]"; h += (h ? "," : "") + k; @@ -1369,15 +1633,15 @@ v.serialize = function(a = !0) { for (const m of this.ctx.entries()) { f = m[0]; g = m[1]; - for (const r of g.entries()) { - g = r[0]; - h = r[1]; + for (const n of g.entries()) { + g = n[0]; + h = n[1]; k = ""; for (let t = 0, p; t < h.length; t++) { p = h[t] || [""]; l = ""; - for (let n = 0; n < p.length; n++) { - l += (l ? "," : "") + ("string" === c ? '"' + p[n] + '"' : p[n]); + for (let q = 0; q < p.length; q++) { + l += (l ? "," : "") + ("string" === b ? '"' + p[q] + '"' : p[q]); } l = "[" + l + "]"; k += (k ? "," : "") + l; @@ -1388,12 +1652,12 @@ v.serialize = function(a = !0) { } } d = "index.ctx=new Map([" + d + "]);"; - return a ? "function inject(index){" + b + e + d + "}" : b + e + d; + return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ia(U.prototype); -const Ja = {Index:U, Charset:Da, Encoder:K, Document:R, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Z = self; -let Ka; -(Ka = Z.define) && Ka.amd ? Ka([], function() { - return Ja; -}) : "object" === typeof Z.exports ? Z.exports = Ja : Z.FlexSearch = Ja; +ha(W.prototype); +const Sa = {Index:W, Charset:La, Encoder:L, Document:Q, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Z = self; +let Ta; +(Ta = Z.define) && Ta.amd ? Ta([], function() { + return Sa; +}) : "object" === typeof Z.exports ? Z.exports = Sa : Z.FlexSearch = Sa; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index efedfe1..2820069 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,57 +1,64 @@ /**! - * FlexSearch.js v0.8.103 (Bundle) + * FlexSearch.js v0.8.105 (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 u;function B(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 g=new Map(c);for(var f of a)g.set(f[0],f[1]);return g}if(b===Set){f=new Set(c);for(g of a.values())f.add(g);return f}}}return a}return c}return"undefined"===d?b:a}function D(){return Object.create(null)}function aa(a,b){return b.length-a.length} -function E(a){return"string"===typeof a}function G(a){return"object"===typeof a}function I(a,b){if(E(b))a=a[b];else for(let c=0;a&&ca.length)return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&M(this);return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&M(this);return this}; -u.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&M(this);return this};u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1this.stemmer.get(l)),k=1);f&&k&&(f.lengththis.matcher.get(l)));if(f&&this.replacer)for(d=0;f&&dthis.O&&(this.G.clear(),this.L=this.L/1.1|0));f&&c.push(f)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.F.set(a,c),this.F.size>this.O&&(this.F.clear(),this.K=this.K/1.1|0));return c};function ha(a){a.J=null;a.F.clear();a.G.clear()};function ia(a){N.call(a,"add");N.call(a,"append");N.call(a,"search");N.call(a,"update");N.call(a,"remove")}function N(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);b=this[a].apply(this,b);e&&(b.then?b.then(e):e(b));return b}};function O(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function P(a,b){b||(b=new Map);for(let c=0,e;cc||e)a=a.slice(e,e+c);d&&(a=ra.call(this,a));return a}} -function ra(a){const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -T.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};T.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};T.prototype.clear=function(){this.cache.clear();this.h=""};const va={normalize:function(a){return a.toLowerCase()},dedupe:!1};const wa=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 xa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),ya=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const za={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Aa=/[\x00-\x7F]+/g;const Ba=/[\x00-\x7F]+/g;const Ca=/[\x00-\x7F]+/g;var Da={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:va,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:wa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:wa,matcher:xa,replacer:ya},LatinExtra:{normalize:!0,dedupe:!0,mapper:wa,replacer:ya.concat([/(?!^)[aeo]/g,""]),matcher:xa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cg;h--){f=n.substring(g,h);var k=this.score?this.score(b,n,p,f,g):V(t,e,p,d,g);W(this,m,f,k,a,c)}break}case "reverse":if(1< -d){for(h=d-1;0f?0:1),e,p,h-1,k-1),w=this.bidirectional&&n>g;W(this,l,w?g:n,v,a,c,w?n:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function W(a,b,c,e,d,g,f){let h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])f?(b=k||(b[c]=D()),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=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((b=a.reg.get(d))?b.push(h):a.reg.set(d,[h])))}function V(a,b,c,e,d){return c&&1b?b?a.slice(c,c+b):a.slice(c):a;let e=[];for(let d=0,g,f;d=f){c-=f;continue}cb&&(g=g.slice(0,b),f=g.length);else if(f>=b)return f>b&&(g=g.slice(0,b)),g;e.push(g);b-=f;if(!b)break}return e.length?e=1b||d?f.slice(d,b+d):f;f=k}else{if(kb||d)f=f.slice(d,b+d)}e=f}return e}; -function X(a,b,c,e){return(a=Y(this,a,b))&&a.length?Fa(a,c,e):[]}function Ga(a,b,c,e){let d=[];if(a){e=Math.min(a.length,e);for(let g=0,f;gc);a=c?(a=a.ctx.get(e?b:c))&&a.get(e?c:b):a.map.get(b);return a};U.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const g=d.indexOf(a);g===c.length-1?d.pop():d.splice(g,1)}}else Ha(this.map,a),this.depth&&Ha(this.ctx,a);b||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Ha(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,g;ec.add(a,b)):this.add(a,b)}; -function Ia(a){let b=0;if(a.constructor===Array)for(let c=0,e;c"a1a".split(c).length; +this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);K||(this.mapper=new Map(ba));this.rtl=A(a.rtl,!1,this.rtl);this.dedupe=A(a.dedupe,!1,this.dedupe);this.filter=A((c=a.filter)&&new Set(c),null,this.filter);this.matcher=A((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=A((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= +A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);if(this.cache=c=A(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof c?c:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.D="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.D+= +(this.D?"|":"")+d;return this};v.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&M(this);return this};v.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&M(this);return this};v.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&M(this);return this};v.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&M(this);return this}; +v.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(M,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=K?a.normalize("NFKD").replace(K,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),g.lengththis.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.R&& +(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.F.set(a,c),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return c};function M(a){a.H=null;a.F.clear();a.G.clear()};function ha(a){N.call(a,"add");N.call(a,"append");N.call(a,"search");N.call(a,"update");N.call(a,"remove")}function N(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);b=this[a].apply(this,b);e&&(b.then?b.then(e):e(b));return b}};function O(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function ia(a,b){b||(b=new Map);for(let c=0,e;cc||e?g.slice(e,c+e):g;else{if(ac||e)g=g.slice(e,c+e)}return g} +function qa(a,b,c){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lb?b?a.slice(c,c+b):a.slice(c):a,e?R.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?R.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=qa(a,c,e),e=0));return f?this.resolve(c,e,d):this};T.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=S(this,"and",arguments);return ua.call(this,f,g,h,k,l,m,n)}return d?this.resolve(b,c,e):this}; +function ua(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=aa(a))return this.result=pa(a,b,c,e,g),f?d?R.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};T.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=S(this,"xor",arguments);return va.call(this,a,b,c,e,d,f,g)}; +function va(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=wa.call(this,a,c,e,f,this.h),f?d?R.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function wa(a,b,c,e,d){const f=[],g=C();let h=0;for(let k=0,l;kc||e)a=a.slice(e,e+c);d&&(a=R.call(this,a));return a}} +function R(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +V.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};V.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};V.prototype.clear=function(){this.cache.clear();this.h=""};const Da={normalize:function(a){return a.toLowerCase()},numeric:!1,dedupe:!1};const Ea=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 Fa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ga=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ha={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Ia=/[\x00-\x7F]+/g;const Ja=/[\x00-\x7F]+/g;const Ka=/[\x00-\x7F]+/g;var La={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Da,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ea},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ea,matcher:Fa,replacer:Ga},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ea,replacer:Ga.concat([/(?!^)[aeo]/g,""]),matcher:Fa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=q.substring(f,h);var k=this.score?this.score(b,q,p,g,f):X(t,e,p,d,f);Y(this,m,g,k,a,c)}break}case "reverse":if(1< +d){for(h=d-1;0g?0:1),e,p,h-1,k-1),w=this.bidirectional&&q>f;Y(this,l,w?f:q,y,a,c,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Y(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])g?(b=k||(b[c]=C()),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=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((b=a.reg.get(d))?b.push(h):a.reg.set(d,[h])))}function X(a,b,c,e,d){return c&&1c)&&(e=c,c=b,b=e);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};W.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else Qa(this.map,a),this.depth&&Qa(this.ctx,a);b||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Qa(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; +function Ra(a){let b=0;if(a.constructor===Array)for(let c=0,e;c "a1a".split(b).length; } - try { - this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); - } catch (f) { - this.split = /\s+/; - } - this.numeric = e; + this.numeric = A(a.numeric, e); } else { try { - this.split = B(c, ca, this.split); - } catch (e) { - this.split = /\s+/; + this.split = A(this.split, ca); + } catch (d) { + console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = B(this.numeric, !0); + this.numeric = A(a.numeric, A(this.numeric, !0)); } - this.prepare = B(a.prepare, null, this.prepare); - this.finalize = B(a.finalize, null, this.finalize); - J || (this.mapper = new Map(ba)); - this.rtl = a.rtl || !1; - this.dedupe = B(a.dedupe, !1, this.dedupe); - this.filter = B((c = a.filter) && new Set(c), null, this.filter); - this.matcher = B((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = B((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = B((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = B(a.replacer, null, this.replacer); - this.minlength = B(a.minlength, 1, this.minlength); - this.maxlength = B(a.maxlength, 0, this.maxlength); - if (this.cache = c = B(a.cache, !0, this.cache)) { - this.J = null, this.O = "number" === typeof c ? c : 2e5, this.F = new Map(), this.G = new Map(), this.L = this.K = 128; + this.prepare = A(a.prepare, null, this.prepare); + this.finalize = A(a.finalize, null, this.finalize); + K || (this.mapper = new Map(ba)); + this.rtl = A(a.rtl, !1, this.rtl); + this.dedupe = A(a.dedupe, !1, this.dedupe); + this.filter = A((b = a.filter) && new Set(b), null, this.filter); + this.matcher = A((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = A((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = A((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = A(a.replacer, null, this.replacer); + this.minlength = A(a.minlength, 1, this.minlength); + this.maxlength = A(a.maxlength, 0, this.maxlength); + if (this.cache = b = A(a.cache, !0, this.cache)) { + this.H = null, this.R = "number" === typeof b ? b : 2e5, this.F = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; this.M = null; this.D = ""; this.N = null; if (this.matcher) { - for (const e of this.matcher.keys()) { - this.h += (this.h ? "|" : "") + e; + for (const d of this.matcher.keys()) { + this.h += (this.h ? "|" : "") + d; } } if (this.stemmer) { - for (const e of this.stemmer.keys()) { - this.D += (this.D ? "|" : "") + e; + for (const d of this.stemmer.keys()) { + this.D += (this.D ? "|" : "") + d; } } return this; }; -v.addMatcher = function(a, b) { - if ("object" === typeof a) { - return this.addReplacer(a, b); - } - if (2 > a.length) { - return this.addMapper(a, b); - } - this.matcher || (this.matcher = new Map()); - this.matcher.set(a, b); - this.h += (this.h ? "|" : "") + a; - this.M = null; - this.cache && M(this); - return this; -}; -v.addStemmer = function(a, b) { +w.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); - this.stemmer.set(a, b); + this.stemmer.set(a, c); this.D += (this.D ? "|" : "") + a; this.N = null; this.cache && M(this); return this; }; -v.addFilter = function(a) { +w.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); this.cache && M(this); return this; }; -v.addMapper = function(a, b) { +w.addMapper = function(a, c) { if ("object" === typeof a) { - return this.addReplacer(a, b); + return this.addReplacer(a, c); } if (1 < a.length) { - return this.addMatcher(a, b); + return this.addMatcher(a, c); } this.mapper || (this.mapper = new Map()); - this.mapper.set(a, b); + this.mapper.set(a, c); this.cache && M(this); return this; }; -v.addReplacer = function(a, b) { - "string" === typeof a && (a = new RegExp(a, "g")); +w.addMatcher = function(a, c) { + if ("object" === typeof a) { + return this.addReplacer(a, c); + } + if (2 > a.length && (this.dedupe || this.mapper)) { + return this.addMapper(a, c); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(a, c); + this.h += (this.h ? "|" : "") + a; + this.M = null; + this.cache && M(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, b || ""); + this.replacer.push(a, c); this.cache && M(this); return this; }; -function M(a) { - a.F.clear(); - a.G.clear(); -} -v.encode = function(a) { +w.encode = function(a) { if (this.cache && a.length <= this.K) { - if (this.J) { + if (this.H) { if (this.F.has(a)) { return this.F.get(a); } } else { - this.J = setTimeout(ha, 50, this); + this.H = setTimeout(M, 50, this); } } - this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : J ? a.normalize("NFKD").replace(J, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = K ? a.normalize("NFKD").replace(K, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); - const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let c = [], e = this.split || "" === this.split ? a.split(this.split) : a; + const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; for (let f = 0, g, h; f < e.length; f++) { - if (!(g = h = e[f])) { - continue; - } - if (g.length < this.minlength) { - continue; - } - if (b) { - c.push(g); - continue; - } - if (this.filter && this.filter.has(g)) { - continue; - } - if (this.cache && g.length <= this.L) { - if (this.J) { - var d = this.G.get(g); - if (d || "" === d) { - d && c.push(d); - continue; - } + if ((g = h = e[f]) && !(g.length < this.minlength)) { + if (c) { + b.push(g); } else { - this.J = setTimeout(ha, 50, this); + if (!this.filter || !this.filter.has(g)) { + if (this.cache && g.length <= this.L) { + if (this.H) { + var d = this.G.get(g); + if (d || "" === d) { + d && b.push(d); + continue; + } + } else { + this.H = setTimeout(M, 50, this); + } + } + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, k => this.stemmer.get(k)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + if (g && (this.mapper || this.dedupe && 1 < g.length)) { + d = ""; + for (let k = 0, l = "", m, n; k < g.length; k++) { + m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + } + g = d; + } + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); + if (g && this.replacer) { + for (d = 0; g && d < this.replacer.length; d += 2) { + g = g.replace(this.replacer[d], this.replacer[d + 1]); + } + } + this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + g && b.push(g); + } } } - let k; - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), g = g.replace(this.N, l => this.stemmer.get(l)), k = 1); - g && k && (g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); - if (g && (this.mapper || this.dedupe && 1 < g.length)) { - d = ""; - for (let l = 0, m = "", r, t; l < g.length; l++) { - r = g.charAt(l), r === m && this.dedupe || ((t = this.mapper && this.mapper.get(r)) || "" === t ? t === m && this.dedupe || !(m = t) || (d += t) : d += m = r); - } - g = d; - } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, l => this.matcher.get(l))); - if (g && this.replacer) { - for (d = 0; g && d < this.replacer.length; d += 2) { - g = g.replace(this.replacer[d], this.replacer[d + 1]); - } - } - this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.O && (this.G.clear(), this.L = this.L / 1.1 | 0)); - g && c.push(g); } - this.finalize && (c = this.finalize(c) || c); - this.cache && a.length <= this.K && (this.F.set(a, c), this.F.size > this.O && (this.F.clear(), this.K = this.K / 1.1 | 0)); - return c; + this.finalize && (b = this.finalize(b) || b); + this.cache && a.length <= this.K && (this.F.set(a, b), this.F.size > this.R && (this.F.clear(), this.K = this.K / 1.1 | 0)); + return b; }; -function ha(a) { - a.J = null; +function M(a) { + a.H = null; a.F.clear(); a.G.clear(); } -;function ia(a) { +;function ha(a) { N.call(a, "add"); N.call(a, "append"); N.call(a, "search"); @@ -270,170 +270,170 @@ function ha(a) { } function N(a) { this[a + "Async"] = function() { - var b = arguments; - const c = b[b.length - 1]; + var c = arguments; + const b = c[c.length - 1]; let e; - "function" === typeof c && (e = c, delete b[b.length - 1]); - b = this[a].apply(this, b); - e && (b.then ? b.then(e) : e(b)); - return b; + "function" === typeof b && (e = b, delete c[c.length - 1]); + c = this[a].apply(this, c); + e && (c.then ? c.then(e) : e(c)); + return c; }; } -;function O(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 5000 | 0); +;function O(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { - e.push(d), e.length === b && (c.push(e), e = []); - } - e.length && c.push(e); - return c; -} -function P(a, b) { - b || (b = new Map()); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b.set(e[0], e[1]); + e.push(d), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } -function ja(a, b = 0) { - let c = [], e = []; - b && (b = 250000 / b * 1000 | 0); - for (const d of a.entries()) { - e.push([d[0], O(d[1])[0]]), e.length === b && (c.push(e), e = []); +function P(a, c) { + c || (c = new Map()); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c.set(e[0], e[1]); } - e.length && c.push(e); return c; } -function ka(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], P(e[1], d)); +function ia(a, c = 0) { + let b = [], e = []; + c && (c = 250000 / c * 1000 | 0); + for (const d of a.entries()) { + e.push([d[0], O(d[1])[0]]), e.length === c && (b.push(e), e = []); } + e.length && b.push(e); return b; } -function la(a) { - let b = [], c = []; +function ja(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], P(e[1], d)); + } + return c; +} +function ka(a) { + let c = [], b = []; for (const e of a.keys()) { - c.push(e), 250000 === c.length && (b.push(c), c = []); + b.push(e), 250000 === b.length && (c.push(b), b = []); } - c.length && b.push(c); - return b; + b.length && c.push(b); + return c; } -function ma(a, b) { - b || (b = new Set()); - for (let c = 0; c < a.length; c++) { - b.add(a[c]); +function la(a, c) { + c || (c = new Set()); + for (let b = 0; b < a.length; b++) { + c.add(a[b]); } - return b; + return c; } -function Q(a, b, c, e, d, f, g = 0) { +function Q(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, b, d, f + 1); + return this.export(a, c, d, f + 1); } - if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { const l = this; return k.then(function() { - return Q.call(l, a, b, c, h ? e : null, d, f, g + 1); + return Q.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return Q.call(this, a, b, c, h ? e : null, d, f, g + 1); + return Q.call(this, a, c, b, h ? e : null, d, f, g + 1); } -;R.prototype.add = function(a, b, c) { - H(a) && (b = a, a = I(b, this.key)); - if (b && (a || 0 === a)) { - if (!c && this.reg.has(a)) { - return this.update(a, b); +;R.prototype.add = function(a, c, b) { + I(a) && (c = a, a = J(c, this.key)); + if (c && (a || 0 === a)) { + if (!b && this.reg.has(a)) { + return this.update(a, c); } for (let h = 0, k; h < this.field.length; h++) { k = this.C[h]; var e = this.index.get(this.field[h]); if ("function" === typeof k) { - var d = k(b); + var d = k(c); d && e.add(a, d, !1, !0); } else { - if (d = k.H, !d || d(b)) { - k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), S(b, k, this.I, 0, e, a, k[0], c); + if (d = k.I, !d || d(c)) { + k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), ma(c, k, this.J, 0, e, a, k[0], b); } } } if (this.tag) { for (e = 0; e < this.B.length; e++) { - var f = this.B[e], g = this.R[e]; + var f = this.B[e], g = this.T[e]; d = this.tag.get(g); let h = C(); if ("function" === typeof f) { - if (f = f(b), !f) { + if (f = f(c), !f) { continue; } } else { - const k = f.H; - if (k && !k(b)) { + const k = f.I; + if (k && !k(c)) { continue; } f.constructor === String && (f = "" + f); - f = I(b, f); + f = J(c, f); } if (d && f) { E(f) && (f = [f]); for (let k = 0, l, m; k < f.length; k++) { - l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), c && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } } else { d || console.warn("Tag '" + g + "' was not found"); } } } - if (this.store && (!c || !this.store.has(a))) { + if (this.store && (!b || !this.store.has(a))) { let h; if (this.A) { h = C(); for (let k = 0, l; k < this.A.length; k++) { l = this.A[k]; - if ((c = l.H) && !c(b)) { + if ((b = l.I) && !b(c)) { continue; } let m; if ("function" === typeof l) { - m = l(b); + m = l(c); if (!m) { continue; } - l = [l.S]; + l = [l.U]; } else if (E(l) || l.constructor === String) { - h[l] = b[l]; + h[l] = c[l]; continue; } - na(b, h, l, 0, l[0], m); + na(c, h, l, 0, l[0], m); } } - this.store.set(a, h || b); + this.store.set(a, h || c); } } return this; }; -function na(a, b, c, e, d, f) { +function na(a, c, b, e, d, f) { a = a[d]; - if (e === c.length - 1) { - b[d] = f || a; + if (e === b.length - 1) { + c[d] = f || a; } else if (a) { if (a.constructor === Array) { - for (b = b[d] = Array(a.length), d = 0; d < a.length; d++) { - na(a, b, c, e, d); + for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { + na(a, c, b, e, d); } } else { - b = b[d] || (b[d] = C()), d = c[++e], na(a, b, c, e, d); + c = c[d] || (c[d] = C()), d = b[++e], na(a, c, b, e, d); } } } -function S(a, b, c, e, d, f, g, h) { +function ma(a, c, b, e, d, f, g, h) { if (a = a[g]) { - if (e === b.length - 1) { + if (e === c.length - 1) { if (a.constructor === Array) { - if (c[e]) { - for (b = 0; b < a.length; b++) { - d.add(f, a[b], !0, !0); + if (b[e]) { + for (c = 0; c < a.length; c++) { + d.add(f, a[c], !0, !0); } return; } @@ -443,71 +443,432 @@ function S(a, b, c, e, d, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - S(a, b, c, e, d, f, g, h); + ma(a, c, b, e, d, f, g, h); } } else { - g = b[++e], S(a, b, c, e, d, f, g, h); + g = c[++e], ma(a, c, b, e, d, f, g, h); } } } } -;function oa(a, b) { - const c = C(), e = []; - for (let d = 0, f; d < b.length; d++) { - f = b[d]; - for (let g = 0; g < f.length; g++) { - c[f[g]] = 1; +;function oa(a, c, b, e, d) { + const f = a.length; + let g = [], h, k; + h = C(); + for (let l = 0, m, n, t, p; l < c; l++) { + for (let q = 0; q < f; q++) { + if (t = a[q], l < t.length && (m = t[l])) { + for (let y = 0; y < m.length; y++) { + n = m[y], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), p = g[k] || (g[k] = []), p.push(n); + } + } } } - for (let d = 0, f; d < a.length; d++) { - f = a[d], 1 === c[f] && (e.push(f), c[f] = 2); + if (a = g.length) { + if (d) { + g = 1 < g.length ? pa(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + } else { + if (a < f) { + return []; + } + g = g[a - 1]; + if (b || e) { + if (g.length > b || e) { + g = g.slice(e, b + e); + } + } + } + } + return g; +} +function pa(a, c, b) { + const e = [], d = C(); + let f; + var g = a.length; + let h; + for (let k = g - 1; 0 <= k; k--) { + if (h = (g = a[k]) && g.length) { + for (let l = 0; l < h; l++) { + if (f = g[l], !d[f]) { + if (d[f] = 1, b) { + b--; + } else { + if (e.push(f), e.length === c) { + return e; + } + } + } + } + } } return e; } -;R.prototype.search = function(a, b, c, e) { - c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); +function qa(a, c, b) { + const e = C(), d = []; + for (let f = 0, g; f < c.length; f++) { + g = c[f]; + for (let h = 0; h < g.length; h++) { + e[g[h]] = 1; + } + } + if (b) { + for (let f = 0, g; f < a.length; f++) { + g = a[f], e[g] && (d.push(g), e[g] = 0); + } + } else { + for (let f = 0, g, h; f < a.result.length; f++) { + for (g = a.result[f], c = 0; c < g.length; c++) { + h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); + } + } + } + return d; +} +;function ra(a, c, b, e) { + if (!a.length) { + return a; + } + if (1 === a.length) { + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? S.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; + continue; + } + b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); + } + h > c && (g = g.slice(0, c), h = c); + if (!d.length && h >= c) { + return e ? S.call(this, g) : g; + } + d.push(g); + c -= h; + if (!c) { + break; + } + } + } + d = 1 < d.length ? [].concat.apply([], d) : d[0]; + return e ? S.call(this, d) : d; +} +;function T(a, c, b) { + var e = b[0]; + if (e.then) { + return Promise.all(b).then(function(m) { + return a[c].apply(a, m); + }); + } + if (e[0] && e[0].index) { + return a[c].apply(a, e); + } + e = []; + let d = [], f = 0, g = 0, h, k, l; + for (let m = 0, n; m < b.length; m++) { + if (n = b[m]) { + let t; + if (n.constructor === U) { + t = n.result; + } else if (n.constructor === Array) { + t = n; + } else { + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = k, n.enrich = h; + } else if (n.and) { + t = a.and(n.and); + } else if (n.or) { + t = a.or(n.or); + } else if (n.xor) { + t = a.xor(n.xor); + } else if (n.not) { + t = a.not(n.not); + } else { + continue; + } + } + if (t.then) { + d.push(t); + } else if (t.length) { + e[m] = t; + } else if (!l && ("and" === c || "xor" === c)) { + e = []; + break; + } + } + } + return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; +} +;U.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = T(this, "or", arguments); + return sa.call(this, a, c, b, e, d, f); +}; +function sa(a, c, b, e, d, f) { + if (c.length) { + const g = this; + return Promise.all(c).then(function(h) { + a = []; + for (let k = 0, l; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); + } + return sa.call(g, a, [], b, e, d, f); + }); + } + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = pa(a, b, e), e = 0)); + return f ? this.resolve(b, e, d) : this; +} +;U.prototype.and = function() { + let a = this.result.length, c, b, e, d; + if (!a) { + const f = arguments[0]; + f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); + } + if (a) { + const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = T(this, "and", arguments); + return ta.call(this, f, g, h, k, l, m, n); + } + return d ? this.resolve(c, b, e) : this; +}; +function ta(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return ta.call(h, a, [], b, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + if (c = aa(a)) { + return this.result = oa(a, c, b, e, g), f ? d ? S.call(this.index, this.result) : this.result : this; + } + this.result = []; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(b, e, d) : this; +} +;U.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = T(this, "xor", arguments); + return ua.call(this, a, c, b, e, d, f, g); +}; +function ua(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return ua.call(h, a, [], b, e, d, f, g); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = va.call(this, a, b, e, f, this.h), f ? d ? S.call(this.index, this.result) : this.result : this; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(b, e, d) : this; +} +function va(a, c, b, e, d) { + const f = [], g = C(); + let h = 0; + for (let k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); + for (let m = 0, n; m < l.length; m++) { + if (n = l[m]) { + for (let t = 0, p; t < n.length; t++) { + p = n[t], g[p] = g[p] ? 2 : 1; + } + } + } + } + } + for (let k = 0, l, m = 0; k < h; k++) { + for (let n = 0, t; n < a.length; n++) { + if (t = a[n]) { + if (l = t[k]) { + for (let p = 0, q; p < l.length; p++) { + if (q = l[p], 1 === g[q]) { + if (b) { + b--; + } else { + if (e) { + if (f.push(q), f.length === c) { + return f; + } + } else { + const y = k + (n ? d : 0); + f[y] || (f[y] = []); + f[y].push(q); + if (++m === c) { + return f; + } + } + } + } + } + } + } + } + } + return f; +} +;U.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = T(this, "not", arguments); + return wa.call(this, a, c, b, e, d, f, g); +}; +function wa(a, c, b, e, d, f, g) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, m; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return wa.call(h, a, [], b, e, d, f, g); + }); + } + if (a.length && this.result.length) { + this.result = xa.call(this, a, b, e, f); + } else if (f) { + return this.resolve(b, e, d); + } + return f ? d ? S.call(this.index, this.result) : this.result : this; +} +function xa(a, c, b, e) { + const d = []; + a = new Set(a.flat().flat()); + for (let f = 0, g, h = 0; f < this.result.length; f++) { + if (g = this.result[f]) { + for (let k = 0, l; k < g.length; k++) { + if (l = g[k], !a.has(l)) { + if (b) { + b--; + } else { + if (e) { + if (d.push(l), d.length === c) { + return d; + } + } else { + if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { + return d; + } + } + } + } + } + } + } + return d; +} +;function U(a) { + if (!this || this.constructor !== U) { + return new U(a); + } + if (a && a.index) { + return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; + } + this.index = null; + this.result = a || []; + this.h = 0; +} +U.prototype.limit = function(a) { + if (this.result.length) { + const c = []; + let b = 0; + for (let e = 0, d; e < this.result.length; e++) { + if (d = this.result[e], d.length + b < a) { + c[e] = d, b += d.length; + } else { + c[e] = d.slice(0, a - b); + this.result = c; + break; + } + } + } + return this; +}; +U.prototype.offset = function(a) { + if (this.result.length) { + const c = []; + let b = 0; + for (let e = 0, d; e < this.result.length; e++) { + d = this.result[e], d.length + b < a ? b += d.length : (c[e] = d.slice(a - b), b = a); + } + this.result = c; + } + return this; +}; +U.prototype.boost = function(a) { + this.h += a; + return this; +}; +U.prototype.resolve = function(a, c, b) { + const e = this.result, d = this.index; + this.result = this.index = null; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), ra.call(d, e, a || 100, c, b)) : e; +}; +C(); +R.prototype.search = function(a, c, b, e) { + b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = []; var f = []; - let g, h, k, l, m, r, t = 0, p; - if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - var n = c.pluck; - h = c.merge; - l = n || c.field || c.index; - m = this.tag && c.tag; - g = this.store && c.enrich; - k = c.suggest; - p = c.highlight; - b = c.limit || b; - r = c.offset || 0; - b || (b = 100); + let g, h, k, l, m, n, t = 0, p, q; + if (b) { + b.constructor === Array && (b = {index:b}); + a = b.query || a; + var y = b.pluck; + h = b.merge; + l = y || b.field || (l = b.index) && (l.index ? null : l); + m = this.tag && b.tag; + k = b.suggest; + p = !0; + this.store && b.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + g = this.store && b.enrich && p; + q = b.highlight && g; + c = b.limit || c; + n = b.offset || 0; + c || (c = 100); if (m) { m.constructor !== Array && (m = [m]); var u = []; - for (let x = 0, q; x < m.length; x++) { - q = m[x]; - if (E(q)) { + for (let x = 0, r; x < m.length; x++) { + r = m[x]; + if (E(r)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (q.field && q.tag) { - var w = q.tag; - if (w.constructor === Array) { - for (var y = 0; y < w.length; y++) { - u.push(q.field, w[y]); + if (r.field && r.tag) { + var v = r.tag; + if (v.constructor === Array) { + for (var z = 0; z < v.length; z++) { + u.push(r.field, v[z]); } } else { - u.push(q.field, w); + u.push(r.field, v); } } else { - w = Object.keys(q); - for (let D = 0, A, z; D < w.length; D++) { - if (A = w[D], z = q[A], z.constructor === Array) { - for (y = 0; y < z.length; y++) { - u.push(A, z[y]); + v = Object.keys(r); + for (let D = 0, F, B; D < v.length; D++) { + if (F = v[D], B = r[F], B.constructor === Array) { + for (z = 0; z < B.length; z++) { + u.push(F, B[z]); } } else { - u.push(A, z); + u.push(F, B); } } } @@ -520,137 +881,137 @@ function S(a, b, c, e, d, f, g, h) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - n = pa.call(this, u[f], u[f + 1], b, r, g), d.push({field:u[f], tag:u[f + 1], result:n}); + y = ya.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); } } return e.length ? Promise.all(e).then(function(x) { - for (let q = 0; q < x.length; q++) { - d[q].result = x[q]; + for (let r = 0; r < x.length; r++) { + d[r].result = x[r]; } return d; }) : d; } } - E(l) && (l = [l]); + l && l.constructor !== Array && (l = [l]); } l || (l = this.field); u = !e && (this.worker || this.db) && []; - for (let x = 0, q, D, A; x < l.length; x++) { + for (let x = 0, r, D, F; x < l.length; x++) { D = l[x]; - let z; - E(D) || (z = D, D = z.field, a = z.query || a, b = z.limit || b, r = z.offset || r, k = z.suggest || k, g = this.store && (z.enrich || g)); + let B; + E(D) || (B = D, D = B.field, a = B.query || a, c = B.limit || c, n = B.offset || n, k = B.suggest || k, g = this.store && (B.enrich || g)); if (e) { - q = e[x]; + r = e[x]; } else { - if (w = z || c, y = this.index.get(D), m && (w.enrich = !1), u) { - u[x] = y.search(a, b, w); - w && g && (w.enrich = g); + if (v = B || b, z = this.index.get(D), m && (v.enrich = !1), u) { + u[x] = z.search(a, c, v); + v && g && (v.enrich = g); continue; } else { - q = y.search(a, b, w), w && g && (w.enrich = g); + r = z.search(a, c, v), v && g && (v.enrich = g); } } - A = q && q.length; - if (m && A) { - w = []; - y = 0; - for (let G = 0, F, L; G < m.length; G += 2) { - F = this.tag.get(m[G]); - if (!F) { + F = r && (p ? r.length : r.result.length); + if (m && F) { + v = []; + z = 0; + for (let G = 0, H, La; G < m.length; G += 2) { + H = this.tag.get(m[G]); + if (!H) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { continue; } else { - return d; + return p ? d : new U(d); } } - if (L = (F = F && F.get(m[G + 1])) && F.length) { - y++, w.push(F); + if (La = (H = H && H.get(m[G + 1])) && H.length) { + z++, v.push(H); } else if (!k) { - return d; + return p ? d : new U(d); } } - if (y) { - q = oa(q, w); - A = q.length; - if (!A && !k) { - return d; + if (z) { + r = qa(r, v, p); + F = r.length; + if (!F && !k) { + return p ? r : new U(r); } - y--; + z--; } } - if (A) { - f[t] = D, d.push(q), t++; + if (F) { + f[t] = D, d.push(r), t++; } else if (1 === l.length) { - return d; + return p ? d : new U(d); } } if (u) { const x = this; - return Promise.all(u).then(function(q) { - return q.length ? x.search(a, b, c, q) : q; + return Promise.all(u).then(function(r) { + return r.length ? x.search(a, c, b, r) : r; }); } if (!t) { - return d; + return p ? d : new U(d); } - if (n && (!g || !this.store)) { + if (y && (!g || !this.store)) { return d[0]; } u = []; - for (let x = 0, q; x < f.length; x++) { - q = d[x]; - g && q.length && !q[0].doc && q.length && (q = qa.call(this, q)); - if (n) { - return q; + for (let x = 0, r; x < f.length; x++) { + r = d[x]; + g && r.length && !r[0].doc && (r = S.call(this, r)); + if (y) { + return p ? r : new U(r); } - d[x] = {field:f[x], result:q}; + d[x] = {field:f[x], result:r}; } - return h ? ra(d, b) : p ? sa(d, a, this.index, this.field, this.C, p) : d; + return h ? za(d, c) : q ? Aa(d, a, this.index, this.field, this.C, q) : d; }; -function sa(a, b, c, e, d, f) { +function Aa(a, c, b, e, d, f) { let g, h, k; - for (let m = 0, r, t, p, n, u; m < a.length; m++) { - r = a[m].result; + for (let m = 0, n, t, p, q, y; m < a.length; m++) { + n = a[m].result; t = a[m].field; - n = c.get(t); - p = n.encoder; - k = n.tokenize; - u = d[e.indexOf(t)]; - p !== g && (g = p, h = g.encode(b)); - for (let w = 0; w < r.length; w++) { - let y = ""; - var l = I(r[w].doc, u); - let x = g.encode(l); + q = b.get(t); + p = q.encoder; + k = q.tokenize; + y = d[e.indexOf(t)]; + p !== g && (g = p, h = g.encode(c)); + for (let u = 0; u < n.length; u++) { + let v = ""; + var l = J(n[u].doc, y); + let z = g.encode(l); l = l.split(g.split); - for (let q = 0, D, A; q < x.length; q++) { - D = x[q]; - A = l[q]; - let z; - for (let G = 0, F; G < h.length; G++) { - if (F = h[G], "strict" === k) { - if (D === F) { - y += (y ? " " : "") + f.replace("$1", A); - z = !0; + for (let x = 0, r, D; x < z.length; x++) { + r = z[x]; + D = l[x]; + let F; + for (let B = 0, G; B < h.length; B++) { + if (G = h[B], "strict" === k) { + if (r === G) { + v += (v ? " " : "") + f.replace("$1", D); + F = !0; break; } } else { - const L = D.indexOf(F); - if (-1 < L) { - y += (y ? " " : "") + A.substring(0, L) + f.replace("$1", A.substring(L, F.length)) + A.substring(L + F.length); - z = !0; + const H = r.indexOf(G); + if (-1 < H) { + v += (v ? " " : "") + D.substring(0, H) + f.replace("$1", D.substring(H, G.length)) + D.substring(H + G.length); + F = !0; break; } } } - z || (y += (y ? " " : "") + l[q]); + F || (v += (v ? " " : "") + l[x]); } - r[w].highlight = y; + n[u].highlight = v; } } return a; } -function ra(a, b) { - const c = [], e = C(); +function za(a, c) { + const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; @@ -658,112 +1019,115 @@ function ra(a, b) { if (l = g[h], k = l.id, m = e[k]) { m.push(f.field); } else { - if (c.length === b) { - return c; + if (b.length === c) { + return b; } l.field = e[k] = [f.field]; - c.push(l); + b.push(l); } } } - return c; + return b; } -function pa(a, b, c, e, d) { +function ya(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(b)) && f.length - e) && 0 < a) { - if (a > c || e) { - f = f.slice(e, e + c); + if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if (a > b || e) { + f = f.slice(e, e + b); } - d && (f = qa.call(this, f)); + d && (f = S.call(this, f)); return f; } } -function qa(a) { - const b = Array(a.length); - for (let c = 0, e; c < a.length; c++) { - e = a[c], b[c] = {id:e, doc:this.store.get(e)}; +function S(a) { + if (!this || !this.store) { + return a; } - return b; + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; + } + return c; } ;function R(a) { if (!this || this.constructor !== R) { return new R(a); } - const b = a.document || a.doc || a; - var c; + const c = a.document || a.doc || a; + var b; this.C = []; this.field = []; - this.I = []; - this.key = (c = b.key || b.id) && T(c, this.I) || "id"; + this.J = []; + this.key = (b = c.key || c.id) && V(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); - this.A = (c = b.store || null) && c && !0 !== c && []; - this.store = c && new Map(); - this.cache = (c = a.cache || null) && new U(c); + this.A = (b = c.store || null) && b && !0 !== b && []; + this.store = b && new Map(); + this.cache = (b = a.cache || null) && new W(b); a.cache = !1; - c = new Map(); - let e = b.index || b.field || b; + b = new Map(); + let e = c.index || c.field || c; E(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], E(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, c.set(f, new V(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = T(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].H = g.filter)), this.field[d] = f; + f = e[d], E(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new X(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = V(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { - a = b.store; + a = c.store; E(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = T(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].H = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = V(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } - this.index = c; + this.index = b; this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { + if (b = c.tag) { + if ("string" === typeof b && (b = [b]), b.length) { this.tag = new Map(); this.B = []; - this.R = []; - for (let d = 0, f, g; d < c.length; d++) { - f = c[d]; + this.T = []; + for (let d = 0, f, g; d < b.length; d++) { + f = b[d]; g = f.field || f; if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = T(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].H = f.filter)); - this.R[d] = g; + f.custom ? this.B[d] = f.custom : (this.B[d] = V(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + this.T[d] = g; this.tag.set(g, new Map()); } } } } -function T(a, b) { - const c = a.split(":"); +function V(a, c) { + const b = a.split(":"); let e = 0; - for (let d = 0; d < c.length; d++) { - a = c[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[e] = !0), a && (c[e++] = a); + for (let d = 0; d < b.length; d++) { + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); } - e < c.length && (c.length = e); - return 1 < e ? c : c[0]; + e < b.length && (b.length = e); + return 1 < e ? b : b[0]; } -v = R.prototype; -v.append = function(a, b) { - return this.add(a, b, !0); +w = R.prototype; +w.append = function(a, c) { + return this.add(a, c, !0); }; -v.update = function(a, b) { - return this.remove(a).add(a, b); +w.update = function(a, c) { + return this.remove(a).add(a, c); }; -v.remove = function(a) { - H(a) && (a = I(a, this.key)); - for (var b of this.index.values()) { - b.remove(a, !0); +w.remove = function(a) { + I(a) && (a = J(a, this.key)); + for (var c of this.index.values()) { + c.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { - for (let c of this.tag.values()) { - for (let e of c) { - b = e[0]; + for (let b of this.tag.values()) { + for (let e of b) { + c = e[0]; const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : c.delete(b)); + -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); } } } @@ -773,7 +1137,7 @@ v.remove = function(a) { this.cache && this.cache.remove(a); return this; }; -v.clear = function() { +w.clear = function() { for (const a of this.index.values()) { a.clear(); } @@ -785,94 +1149,94 @@ v.clear = function() { this.store && this.store.clear(); return this; }; -v.contain = function(a) { +w.contain = function(a) { return this.reg.has(a); }; -v.cleanup = function() { +w.cleanup = function() { for (const a of this.index.values()) { a.cleanup(); } return this; }; -v.get = function(a) { +w.get = function(a) { return this.store.get(a); }; -v.set = function(a, b) { - this.store.set(a, b); +w.set = function(a, c) { + this.store.set(a, c); return this; }; -v.searchCache = ta; -v.export = function(a, b, c = 0, e = 0) { - if (c < this.field.length) { - const g = this.field[c]; - if ((b = this.index.get(g).export(a, g, c, e = 1)) && b.then) { +w.searchCache = Ba; +w.export = function(a, c, b = 0, e = 0) { + if (b < this.field.length) { + const g = this.field[b]; + if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { const h = this; - return b.then(function() { - return h.export(a, g, c + 1); + return c.then(function() { + return h.export(a, g, b + 1); }); } - return this.export(a, g, c + 1); + return this.export(a, g, b + 1); } let d, f; switch(e) { case 0: d = "reg"; - f = la(this.reg); - b = null; + f = ka(this.reg); + c = null; break; case 1: d = "tag"; - f = ja(this.tag, this.reg.size); - b = null; + f = ia(this.tag, this.reg.size); + c = null; break; case 2: d = "doc"; f = O(this.store); - b = null; + c = null; break; case 3: d = "cfg"; f = {}; - b = null; + c = null; break; default: return; } - return Q.call(this, a, b, d, f, c, e); + return Q.call(this, a, c, d, f, b, e); }; -v.import = function(a, b) { - if (b) { - E(b) && (b = JSON.parse(b)); +w.import = function(a, c) { + if (c) { + "string" === typeof c && (c = JSON.parse(c)); a = a.split("."); "json" === a[a.length - 1] && a.pop(); - var c = 2 < a.length ? a[0] : ""; + var b = 2 < a.length ? a[0] : ""; a = 2 < a.length ? a[2] : a[1]; - if (c) { - return this.index.get(c).import(a, b); + if (b) { + return this.index.get(b).import(a, c); } switch(a) { case "reg": this.fastupdate = !1; - this.reg = ma(b, this.reg); + this.reg = la(c, this.reg); for (let e = 0, d; e < this.field.length; e++) { d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = ka(b, this.tag); + this.tag = ja(c, this.tag); break; case "doc": - this.store = P(b, this.store); + this.store = P(c, this.store); } } }; -ia(R.prototype); -function ta(a, b, c) { +ha(R.prototype); +function Ba(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new U()); + this.cache || (this.cache = new W()); let e = this.cache.get(a); if (!e) { - e = this.search(a, b, c); + e = this.search(a, c, b); if (e.then) { const d = this; e.then(function(f) { @@ -884,77 +1248,76 @@ function ta(a, b, c) { } return e; } -function U(a) { +function W(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -U.prototype.set = function(a, b) { - this.cache.set(this.h = a, b); +W.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); }; -U.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; +W.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; }; -U.prototype.remove = function(a) { - for (const b of this.cache) { - const c = b[0]; - b[1].includes(a) && this.cache.delete(c); +W.prototype.remove = function(a) { + for (const c of this.cache) { + const b = c[0]; + c[1].includes(a) && this.cache.delete(b); } }; -U.prototype.clear = function() { +W.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const ua = {normalize:function(a) { +const Ca = {normalize:function(a) { return a.toLowerCase(); -}, dedupe:!1}; -const va = 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 wa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), xa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const ya = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const za = /[\x00-\x7F]+/g; -const Aa = /[\x00-\x7F]+/g; -const Ba = /[\x00-\x7F]+/g; -var Ca = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:ua, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:va}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:va, matcher:wa, replacer:xa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:va, replacer:xa.concat([/(?!^)[aeo]/g, ""]), matcher:wa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { - for (let c = 0; c < a.length; c++) { - var b = a[c]; - let e = b.charAt(0), d = ya[e]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = ya[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { +}, numeric:!1, dedupe:!1}; +const Da = 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 Ea = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Fa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +const Ga = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const Ha = /[\x00-\x7F]+/g; +const Ia = /[\x00-\x7F]+/g; +const Ja = /[\x00-\x7F]+/g; +var Ka = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ca, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Da}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Da, matcher:Ea, replacer:Fa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Da, replacer:Fa.concat([/(?!^)[aeo]/g, ""]), matcher:Ea}, LatinSoundex:{normalize:!0, 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 = Ga[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ga[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } - a[c] = e; + a[b] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(za, " "); + return ("" + a).replace(Ha, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Aa, ""); + return ("" + a).replace(Ia, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ba, " "); + return ("" + a).replace(Ja, " "); }}}; -const Da = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -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); +const Ma = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +X.prototype.add = function(a, c, b, e) { + if (c && (a || 0 === a)) { + if (!e && !b && this.reg.has(a)) { + return this.update(a, c); } - b = this.encoder.encode(b); - if (e = b.length) { - const l = C(), m = C(), r = this.depth, t = this.resolution; + c = this.encoder.encode(c); + if (e = c.length) { + const l = C(), m = C(), n = this.depth, t = this.resolution; for (let p = 0; p < e; p++) { - let n = b[this.rtl ? e - 1 - p : p]; - var d = n.length; - if (d && (r || !m[n])) { - var f = this.score ? this.score(b, n, p, null, 0) : W(t, e, p), g = ""; + let q = c[this.rtl ? e - 1 - p : p]; + var d = q.length; + if (d && (n || !m[q])) { + var f = this.score ? this.score(c, q, p, null, 0) : Y(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var h = d; h > f; h--) { - g = n.substring(f, h); - var k = this.score ? this.score(b, n, p, g, f) : W(t, e, p, d, f); - X(this, m, g, k, a, c); + g = q.substring(f, h); + var k = this.score ? this.score(c, q, p, g, f) : Y(t, e, p, d, f); + Z(this, m, g, k, a, b); } } break; @@ -962,24 +1325,24 @@ V.prototype.add = function(a, b, c, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - g = n[h] + g, k = this.score ? this.score(b, n, p, g, h) : W(t, e, p, d, h), X(this, m, g, k, a, c); + g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : Y(t, e, p, d, h), Z(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { for (h = 0; h < d; h++) { - g += n[h], X(this, m, g, f, a, c); + g += q[h], Z(this, m, g, f, a, b); } break; } default: - if (X(this, m, n, f, a, c), r && 1 < e && p < e - 1) { - for (d = C(), g = this.P, f = n, h = Math.min(r + 1, e - p), d[f] = 1, k = 1; k < h; k++) { - if ((n = b[this.rtl ? e - 1 - p - k : p + k]) && !d[n]) { - d[n] = 1; - const u = this.score ? this.score(b, f, p, n, k) : W(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), w = this.bidirectional && n > f; - X(this, l, w ? f : n, u, a, c, w ? n : f); + if (Z(this, m, q, f, a, b), n && 1 < e && p < e - 1) { + for (d = C(), g = this.S, f = q, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { + if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { + d[q] = 1; + const y = this.score ? this.score(c, f, p, q, k) : Y(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; + Z(this, l, u ? f : q, y, a, b, u ? q : f); } } } @@ -991,321 +1354,222 @@ V.prototype.add = function(a, b, c, e) { } return this; }; -function X(a, b, c, e, d, f, g) { +function Z(a, c, b, e, d, f, g) { let h = g ? a.ctx : a.map, k; - if (!b[c] || g && !(k = b[c])[g]) { - g ? (b = k || (b[c] = C()), 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 = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((b = a.reg.get(d)) ? b.push(h) : a.reg.set(d, [h]))); + if (!c[b] || g && !(k = c[b])[g]) { + g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function W(a, b, c, e, d) { - return c && 1 < a ? b + (e || 0) <= a ? c + (d || 0) : (a - 1) / (b + (e || 0)) * (c + (d || 0)) + 1 | 0 : 0; +function Y(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 Ea(a, b, c) { - if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a; - } - let e = []; - for (let d = 0, f, g; d < a.length; d++) { - if ((f = a[d]) && (g = f.length)) { - if (c) { - if (c >= g) { - c -= g; - continue; - } - c < g && (f = b ? f.slice(c, c + b) : f.slice(c), g = f.length, c = 0); - } - if (e.length) { - g > b && (f = f.slice(0, b), g = f.length); - } else { - if (g >= b) { - return g > b && (f = f.slice(0, b)), f; - } - } - e.push(f); - b -= g; - if (!b) { - break; - } - } - } - return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; -} -;V.prototype.search = function(a, b, c) { - c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); +;X.prototype.search = function(a, c, b) { + b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); var e = [], d = 0; - if (c) { - a = c.query || a; - b = c.limit || b; - d = c.offset || 0; - var f = c.context; - var g = c.suggest; + if (b) { + a = b.query || a; + c = b.limit || c; + d = b.offset || 0; + var f = b.context; + var g = b.suggest; var h = !0; - var k = c.resolution; + var k = b.resolution; } else { h = !0; } - c = this.encoder.encode(a); - a = c.length; - b || !h || (b = 100); + b = this.encoder.encode(a); + a = b.length; + c = c || (h ? 100 : 0); if (1 === a) { - return Y.call(this, c[0], "", b, d); + return Na.call(this, b[0], "", c, d, h); } f = this.depth && !1 !== f; if (2 === a && f && !g) { - return Y.call(this, c[0], c[1], b, d); + return Na.call(this, b[0], b[1], c, d, h); } - var l = h = 0; - if (1 < a) { - var m = C(); - const t = []; - for (let p = 0, n; p < a; p++) { - if ((n = c[p]) && !m[n]) { - if (g || Z(this, n)) { - t.push(n), m[n] = 1; - } else { - return e; - } - const u = n.length; - h = Math.max(h, u); - l = l ? Math.min(l, u) : u; - } - } - c = t; - a = c.length; + h = C(); + let l = 0; + if (1 < a && f) { + var m = b[0]; + l = 1; } - if (!a) { - return e; - } - m = 0; - if (1 === a) { - return Y.call(this, c[0], "", b, d); - } - if (2 === a && f && !g) { - return Y.call(this, c[0], c[1], b, d); - } - if (1 < a) { - if (f) { - var r = c[0]; - m = 1; - } else { - 9 < h && 3 < h / l && c.sort(aa); - } - } - k || 0 === k || (k = this.resolution); - for (let t, p; m < a; m++) { - p = c[m]; - r ? (t = Z(this, p, r), t = Fa(t, e, g, this.P), g && !1 === t && e.length || (r = p)) : (t = Z(this, p, ""), t = Fa(t, e, g, k)); - if (t) { - return t; - } - if (g && m === a - 1) { - f = e.length; - if (!f) { - if (r) { - r = ""; - m = -1; - continue; - } - return e; - } - if (1 === f) { - return Ea(e[0], b, d); - } - } - } - a: { - r = g; - f = e.length; - g = []; - a = C(); - for (let t = 0, p, n, u, w; t < k; t++) { - for (h = 0; h < f; h++) { - if (u = e[h], t < u.length && (p = u[t])) { - for (l = 0; l < p.length; l++) { - n = p[l], (c = a[n]) ? a[n]++ : (c = 0, a[n] = 1), w = g[c] || (g[c] = []), w.push(n); + k || 0 === k || (k = m ? this.S : this.resolution); + for (let q, y; l < a; l++) { + if ((y = b[l]) && !h[y]) { + h[y] = 1; + q = Oa(this, y, m); + a: { + f = q; + var n = e, t = g, p = k; + let u = []; + if (f && f.length) { + if (f.length <= p) { + n.push(f); + q = void 0; + break a; } - } - } - } - if (k = g.length) { - if (r) { - if (1 < g.length) { - b: { - for (k = [], e = C(), r = g.length, c = r - 1; 0 <= c; c--) { - for (r = g[c], a = r.length, h = 0; h < a; h++) { - if (f = r[h], !e[f]) { - if (e[f] = 1, d) { - d--; - } else { - if (k.push(f), k.length === b) { - break b; - } - } - } - } + for (let v = 0, z; v < p; v++) { + if (z = f[v]) { + u[v] = z; } } - } else { - k = (g = g[0]).length > b || d ? g.slice(d, b + d) : g; - } - g = k; - } else { - if (k < f) { - e = []; - break a; - } - g = g[k - 1]; - if (b || d) { - if (g.length > b || d) { - g = g.slice(d, b + d); + if (u.length) { + n.push(u); + q = void 0; + break a; } } + q = t ? void 0 : u; } + if (q) { + e = q; + break; + } + m && (g && q && e.length || (m = y)); } - e = g; + g && m && l === a - 1 && !e.length && (m = "", l = -1, h = C()); } - return e; + a: { + m = e.length; + a = e; + if (1 < m) { + a = oa(e, k, c, d, g); + } else if (1 === m) { + g = ra.call(null, e[0], c, d); + break a; + } + g = a; + } + return g; }; -function Y(a, b, c, e) { - return (a = Z(this, a, b)) && a.length ? Ea(a, c, e) : []; +function Na(a, c, b, e, d) { + a = Oa(this, a, c); + d = !0; + return a && a.length ? d ? ra.call(this, a, b, e) : new U(a) : d ? [] : new U(); } -function Fa(a, b, c, e) { - let d = []; - if (a) { - e = Math.min(a.length, e); - for (let f = 0, g; f < e; f++) { - (g = a[f]) && g && (d[f] = g); - } - if (d.length) { - b.push(d); - return; - } - } - return !c && d; -} -function Z(a, b, c) { +function Oa(a, c, b) { let e; - c && (e = a.bidirectional && b > c); - a = c ? (a = a.ctx.get(e ? b : c)) && a.get(e ? c : b) : a.map.get(b); + b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); + a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;V.prototype.remove = function(a, b) { - const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); - if (c) { +;X.prototype.remove = function(a, c) { + const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); + if (b) { if (this.fastupdate) { - for (let e = 0, d; e < c.length; e++) { - if (d = c[e]) { + for (let e = 0, d; e < b.length; e++) { + if (d = b[e]) { if (2 > d.length) { d.pop(); } else { const f = d.indexOf(a); - f === c.length - 1 ? d.pop() : d.splice(f, 1); + f === b.length - 1 ? d.pop() : d.splice(f, 1); } } } } else { - Ga(this.map, a), this.depth && Ga(this.ctx, a); + Pa(this.map, a), this.depth && Pa(this.ctx, a); } - b || this.reg.delete(a); + c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Ga(a, b) { - let c = 0; +function Pa(a, c) { + let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { if ((d = a[e]) && d.length) { - if (f = d.indexOf(b), 0 <= f) { - 1 < d.length ? (d.splice(f, 1), c++) : delete a[e]; + if (f = d.indexOf(c), 0 <= f) { + 1 < d.length ? (d.splice(f, 1), b++) : delete a[e]; break; } else { - c++; + b++; } } } } else { - for (let e of a) { - const d = e[0], f = Ga(e[1], b); - f ? c += f : a.delete(d); + for (let e of a.entries()) { + const d = e[0], f = Pa(e[1], c); + f ? b += f : a.delete(d); } } - return c; + return b; } -;function V(a, b) { - if (!this || this.constructor !== V) { - return new V(a); +;function X(a, c) { + if (!this || this.constructor !== X) { + return new X(a); } if (a) { - var c = E(a) ? a : a.preset; - c && (Da[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Da[c], a)); + var b = E(a) ? a : a.preset; + b && (Ma[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Ma[b], a)); } else { a = {}; } - c = a.context; - const e = !0 === c ? {depth:1} : c || {}, d = E(a.encoder) ? Ca[a.encoder] : a.encode || a.encoder || ua; - this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; + b = a.context; + const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? Ka[a.encoder] : a.encode || a.encoder || Ca; + this.encoder = d.encode ? d : "object" === typeof d ? new L(d) : {encode:d}; this.resolution = a.resolution || 9; - this.tokenize = c = a.tokenize || "strict"; - this.depth = "strict" === c && e.depth || 0; + this.tokenize = b = a.tokenize || "strict"; + this.depth = "strict" === b && e.depth || 0; this.bidirectional = !1 !== e.bidirectional; this.fastupdate = !!a.fastupdate; this.score = a.score || null; - c = !1; + b = !1; this.map = new Map(); this.ctx = new Map(); - this.reg = b || (this.fastupdate ? new Map() : new Set()); - this.P = e.resolution || 3; + this.reg = c || (this.fastupdate ? new Map() : new Set()); + this.S = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new U(c); + this.cache = (b = a.cache || null) && new W(b); } -v = V.prototype; -v.clear = function() { +w = X.prototype; +w.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); this.cache && this.cache.clear(); return this; }; -v.append = function(a, b) { - return this.add(a, b, !0); +w.append = function(a, c) { + return this.add(a, c, !0); }; -v.contain = function(a) { +w.contain = function(a) { return this.reg.has(a); }; -v.update = function(a, b) { - const c = this, e = this.remove(a); - return e && e.then ? e.then(() => c.add(a, b)) : this.add(a, b); +w.update = function(a, c) { + const b = this, e = this.remove(a); + return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function Ha(a) { - let b = 0; +function Qa(a) { + let c = 0; if (a.constructor === Array) { - for (let c = 0, e; c < a.length; c++) { - (e = a[c]) && (b += e.length); + for (let b = 0, e; b < a.length; b++) { + (e = a[b]) && (c += e.length); } } else { - for (const c of a) { - const e = c[0], d = Ha(c[1]); - d ? b += d : a.delete(e); + for (const b of a) { + const e = b[0], d = Qa(b[1]); + d ? c += d : a.delete(e); } } - return b; + return c; } -v.cleanup = function() { +w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Ha(this.map); - this.depth && Ha(this.ctx); + Qa(this.map); + this.depth && Qa(this.ctx); return this; }; -v.searchCache = ta; -v.export = function(a, b, c, e = 0) { +w.searchCache = Ba; +w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = la(this.reg); + f = ka(this.reg); break; case 1: d = "cfg"; @@ -1317,45 +1581,45 @@ v.export = function(a, b, c, e = 0) { break; case 3: d = "ctx"; - f = ja(this.ctx, this.reg.size); + f = ia(this.ctx, this.reg.size); break; default: return; } - return Q.call(this, a, b, d, f, c, e); + return Q.call(this, a, c, d, f, b, e); }; -v.import = function(a, b) { - if (b) { - switch(E(b) && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { +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(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = ma(b, this.reg); + this.reg = la(c, this.reg); break; case "map": - this.map = P(b, this.map); + this.map = P(c, this.map); break; case "ctx": - this.ctx = ka(b, this.ctx); + this.ctx = ja(c, this.ctx); } } }; -v.serialize = function(a = !0) { +w.serialize = function(a = !0) { if (!this.reg.size) { return ""; } - let b = "", c = ""; + let c = "", b = ""; for (var e of this.reg.keys()) { - c || (c = typeof e), b += (b ? "," : "") + ("string" === c ? '"' + e + '"' : e); + b || (b = typeof e), c += (c ? "," : "") + ("string" === b ? '"' + e + '"' : e); } - b = "index.reg=new Set([" + b + "]);"; + c = "index.reg=new Set([" + c + "]);"; e = ""; for (var d of this.map.entries()) { var f = d[0], g = d[1], h = ""; - for (let m = 0, r; m < g.length; m++) { - r = g[m] || [""]; + for (let m = 0, n; m < g.length; m++) { + n = g[m] || [""]; var k = ""; - for (var l = 0; l < r.length; l++) { - k += (k ? "," : "") + ("string" === c ? '"' + r[l] + '"' : r[l]); + for (var l = 0; l < n.length; l++) { + k += (k ? "," : "") + ("string" === b ? '"' + n[l] + '"' : n[l]); } k = "[" + k + "]"; h += (h ? "," : "") + k; @@ -1368,15 +1632,15 @@ v.serialize = function(a = !0) { for (const m of this.ctx.entries()) { f = m[0]; g = m[1]; - for (const r of g.entries()) { - g = r[0]; - h = r[1]; + for (const n of g.entries()) { + g = n[0]; + h = n[1]; k = ""; for (let t = 0, p; t < h.length; t++) { p = h[t] || [""]; l = ""; - for (let n = 0; n < p.length; n++) { - l += (l ? "," : "") + ("string" === c ? '"' + p[n] + '"' : p[n]); + for (let q = 0; q < p.length; q++) { + l += (l ? "," : "") + ("string" === b ? '"' + p[q] + '"' : p[q]); } l = "[" + l + "]"; k += (k ? "," : "") + l; @@ -1387,9 +1651,9 @@ v.serialize = function(a = !0) { } } d = "index.ctx=new Map([" + d + "]);"; - return a ? "function inject(index){" + b + e + d + "}" : b + e + d; + return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ia(V.prototype); -export default {Index:V, Charset:Ca, Encoder:K, Document:R, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +ha(X.prototype); +export default {Index:X, Charset:Ka, Encoder:L, Document:R, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=V;export const Charset=Ca;export const Encoder=K;export const Document=R;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=X;export const Charset=Ka;export const Encoder=L;export const Document=R;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index 9a3cbab..57ebffe 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,58 +1,65 @@ /**! - * FlexSearch.js v0.8.103 (Bundle) + * FlexSearch.js v0.8.105 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u;function B(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 g=new Map(c);for(var f of a)g.set(f[0],f[1]);return g}if(b===Set){f=new Set(c);for(g of a.values())f.add(g);return f}}}return a}return c}return"undefined"===d?b:a}function D(){return Object.create(null)}function aa(a,b){return b.length-a.length} -function E(a){return"string"===typeof a}function G(a){return"object"===typeof a}function I(a,b){if(E(b))a=a[b];else for(let c=0;a&&ca.length)return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&M(this);return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&M(this);return this}; -u.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&M(this);return this};u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1this.stemmer.get(l)),k=1);f&&k&&(f.lengththis.matcher.get(l)));if(f&&this.replacer)for(d=0;f&&dthis.O&&(this.G.clear(),this.L=this.L/1.1|0));f&&c.push(f)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.F.set(a,c),this.F.size>this.O&&(this.F.clear(),this.K=this.K/1.1|0));return c};function ha(a){a.J=null;a.F.clear();a.G.clear()};function ia(a){N.call(a,"add");N.call(a,"append");N.call(a,"search");N.call(a,"update");N.call(a,"remove")}function N(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);b=this[a].apply(this,b);e&&(b.then?b.then(e):e(b));return b}};function O(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function P(a,b){b||(b=new Map);for(let c=0,e;cc||e)a=a.slice(e,e+c);d&&(a=qa.call(this,a));return a}} -function qa(a){const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -U.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};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const ua={normalize:function(a){return a.toLowerCase()},dedupe:!1};const va=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 wa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),xa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const ya={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const za=/[\x00-\x7F]+/g;const Aa=/[\x00-\x7F]+/g;const Ba=/[\x00-\x7F]+/g;var Ca={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ua,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:va},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:va,matcher:wa,replacer:xa},LatinExtra:{normalize:!0,dedupe:!0,mapper:va,replacer:xa.concat([/(?!^)[aeo]/g,""]),matcher:wa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cg;h--){f=n.substring(g,h);var k=this.score?this.score(b,n,p,f,g):W(t,e,p,d,g);X(this,m,f,k,a,c)}break}case "reverse":if(1< -d){for(h=d-1;0f?0:1),e,p,h-1,k-1),w=this.bidirectional&&n>g;X(this,l,w?g:n,v,a,c,w?n:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function X(a,b,c,e,d,g,f){let h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])f?(b=k||(b[c]=D()),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=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((b=a.reg.get(d))?b.push(h):a.reg.set(d,[h])))}function W(a,b,c,e,d){return c&&1b?b?a.slice(c,c+b):a.slice(c):a;let e=[];for(let d=0,g,f;d=f){c-=f;continue}cb&&(g=g.slice(0,b),f=g.length);else if(f>=b)return f>b&&(g=g.slice(0,b)),g;e.push(g);b-=f;if(!b)break}return e.length?e=1b||d?f.slice(d,b+d):f;f=k}else{if(kb||d)f=f.slice(d,b+d)}e=f}return e}; -function Y(a,b,c,e){return(a=Z(this,a,b))&&a.length?Ea(a,c,e):[]}function Fa(a,b,c,e){let d=[];if(a){e=Math.min(a.length,e);for(let g=0,f;gc);a=c?(a=a.ctx.get(e?b:c))&&a.get(e?c:b):a.map.get(b);return a};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;ed.length)d.pop();else{const g=d.indexOf(a);g===c.length-1?d.pop():d.splice(g,1)}}else Ga(this.map,a),this.depth&&Ga(this.ctx,a);b||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Ga(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,g;ec.add(a,b)):this.add(a,b)}; -function Ha(a){let b=0;if(a.constructor===Array)for(let c=0,e;c"a1a".split(c).length; +this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ca)}catch(d){this.split=/\s+/}this.numeric=A(a.numeric,A(this.numeric,!0))}this.prepare=A(a.prepare,null,this.prepare);this.finalize=A(a.finalize,null,this.finalize);K||(this.mapper=new Map(ba));this.rtl=A(a.rtl,!1,this.rtl);this.dedupe=A(a.dedupe,!1,this.dedupe);this.filter=A((c=a.filter)&&new Set(c),null,this.filter);this.matcher=A((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=A((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer= +A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,this.replacer);this.minlength=A(a.minlength,1,this.minlength);this.maxlength=A(a.maxlength,0,this.maxlength);if(this.cache=c=A(a.cache,!0,this.cache))this.H=null,this.R="number"===typeof c?c:2E5,this.F=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.D="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.D+= +(this.D?"|":"")+d;return this};v.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.D+=(this.D?"|":"")+a;this.N=null;this.cache&&M(this);return this};v.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&M(this);return this};v.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&M(this);return this};v.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&M(this);return this}; +v.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(M,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=K?a.normalize("NFKD").replace(K,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),g.lengththis.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.R&& +(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.F.set(a,c),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return c};function M(a){a.H=null;a.F.clear();a.G.clear()};function ha(a){N.call(a,"add");N.call(a,"append");N.call(a,"search");N.call(a,"update");N.call(a,"remove")}function N(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);b=this[a].apply(this,b);e&&(b.then?b.then(e):e(b));return b}};function O(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function P(a,b){b||(b=new Map);for(let c=0,e;cc||e?g.slice(e,c+e):g;else{if(ac||e)g=g.slice(e,c+e)}return g} +function pa(a,b,c){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lb?b?a.slice(c,c+b):a.slice(c):a,e?S.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?S.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=pa(a,c,e),e=0));return f?this.resolve(c,e,d):this};U.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=T(this,"and",arguments);return ta.call(this,f,g,h,k,l,m,n)}return d?this.resolve(b,c,e):this}; +function ta(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=aa(a))return this.result=oa(a,b,c,e,g),f?d?S.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};U.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=T(this,"xor",arguments);return ua.call(this,a,b,c,e,d,f,g)}; +function ua(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=va.call(this,a,c,e,f,this.h),f?d?S.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function va(a,b,c,e,d){const f=[],g=C();let h=0;for(let k=0,l;kc||e)a=a.slice(e,e+c);d&&(a=S.call(this,a));return a}} +function S(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +W.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};W.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};W.prototype.clear=function(){this.cache.clear();this.h=""};const Ca={normalize:function(a){return a.toLowerCase()},numeric:!1,dedupe:!1};const Da=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 Ea=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Fa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ga={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Ha=/[\x00-\x7F]+/g;const Ia=/[\x00-\x7F]+/g;const Ja=/[\x00-\x7F]+/g;var La={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ca,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Da},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Da,matcher:Ea,replacer:Fa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Da,replacer:Fa.concat([/(?!^)[aeo]/g,""]),matcher:Ea},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=q.substring(f,h);var k=this.score?this.score(b,q,p,g,f):Y(t,e,p,d,f);Z(this,m,g,k,a,c)}break}case "reverse":if(1< +d){for(h=d-1;0g?0:1),e,p,h-1,k-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,c,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])g?(b=k||(b[c]=C()),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=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((b=a.reg.get(d))?b.push(h):a.reg.set(d,[h])))}function Y(a,b,c,e,d){return c&&1c)&&(e=c,c=b,b=e);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};X.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else Pa(this.map,a),this.depth&&Pa(this.ctx,a);b||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Pa(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; +function Qa(a){let b=0;if(a.constructor===Array)for(let c=0,e;c>> 0) + "_", e = 0; return b; }); -F("Symbol.iterator", function(a) { +C("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 < b.length; c++) { - var d = C[b[c]]; + var d = B[b[c]]; "function" === typeof d && "function" != typeof d.prototype[a] && ba(d.prototype, a, {configurable:!0, writable:!0, value:function() { - return ta(aa(this)); + return ua(aa(this)); }}); } return a; }); -function ta(a) { +function ua(a) { a = {next:a}; a[Symbol.iterator] = function() { return this; }; return a; } -F("Promise", function(a) { - function b(f) { +C("Promise", function(a) { + function b(g) { this.A = 0; this.B = void 0; this.h = []; - this.L = !1; + this.H = !1; var h = this.C(); try { - f(h.resolve, h.reject); + g(h.resolve, h.reject); } catch (k) { h.reject(k); } @@ -263,15 +263,15 @@ F("Promise", function(a) { function c() { this.h = null; } - function d(f) { - return f instanceof b ? f : new b(function(h) { - h(f); + function d(g) { + return g instanceof b ? g : new b(function(h) { + h(g); }); } if (a) { return a; } - c.prototype.A = function(f) { + c.prototype.A = function(g) { if (null == this.h) { this.h = []; var h = this; @@ -279,19 +279,19 @@ F("Promise", function(a) { h.D(); }); } - this.h.push(f); + this.h.push(g); }; - var e = C.setTimeout; - c.prototype.B = function(f) { - e(f, 0); + var e = B.setTimeout; + c.prototype.B = function(g) { + e(g, 0); }; c.prototype.D = function() { for (; this.h && this.h.length;) { - var f = this.h; + var g = this.h; this.h = []; - for (var h = 0; h < f.length; ++h) { - var k = f[h]; - f[h] = null; + for (var h = 0; h < g.length; ++h) { + var k = g[h]; + g[h] = null; try { k(); } catch (l) { @@ -301,31 +301,31 @@ F("Promise", function(a) { } this.h = null; }; - c.prototype.C = function(f) { + c.prototype.C = function(g) { this.B(function() { - throw f; + throw g; }); }; b.prototype.C = function() { - function f(l) { + function g(l) { return function(m) { k || (k = !0, l.call(h, m)); }; } var h = this, k = !1; - return {resolve:f(this.ha), reject:f(this.D)}; + return {resolve:g(this.fa), reject:g(this.D)}; }; - b.prototype.ha = function(f) { - if (f === this) { + b.prototype.fa = function(g) { + if (g === this) { this.D(new TypeError("A Promise cannot resolve to itself")); } else { - if (f instanceof b) { - this.ja(f); + if (g instanceof b) { + this.ha(g); } else { a: { - switch(typeof f) { + switch(typeof g) { case "object": - var h = null != f; + var h = null != g; break a; case "function": h = !0; @@ -334,85 +334,85 @@ F("Promise", function(a) { h = !1; } } - h ? this.ga(f) : this.G(f); + h ? this.ea(g) : this.G(g); } } }; - b.prototype.ga = function(f) { + b.prototype.ea = function(g) { var h = void 0; try { - h = f.then; + h = g.then; } catch (k) { this.D(k); return; } - "function" == typeof h ? this.ka(h, f) : this.G(f); + "function" == typeof h ? this.ia(h, g) : this.G(g); }; - b.prototype.D = function(f) { - this.ca(2, f); + b.prototype.D = function(g) { + this.M(2, g); }; - b.prototype.G = function(f) { - this.ca(1, f); + b.prototype.G = function(g) { + this.M(1, g); }; - b.prototype.ca = function(f, h) { + b.prototype.M = function(g, h) { if (0 != this.A) { - throw Error("Cannot settle(" + f + ", " + h + "): Promise already settled in state" + this.A); + throw Error("Cannot settle(" + g + ", " + h + "): Promise already settled in state" + this.A); } - this.A = f; + this.A = g; this.B = h; - 2 === this.A && this.ia(); - this.ea(); + 2 === this.A && this.ga(); + this.N(); }; - b.prototype.ia = function() { - var f = this; + b.prototype.ga = function() { + var g = this; e(function() { - if (f.fa()) { - var h = C.console; - "undefined" !== typeof h && h.error(f.B); + if (g.T()) { + var h = B.console; + "undefined" !== typeof h && h.error(g.B); } }, 1); }; - b.prototype.fa = function() { - if (this.L) { + b.prototype.T = function() { + if (this.H) { return !1; } - var f = C.CustomEvent, h = C.Event, k = C.dispatchEvent; + var g = B.CustomEvent, h = B.Event, k = B.dispatchEvent; if ("undefined" === typeof k) { return !0; } - "function" === typeof f ? f = new f("unhandledrejection", {cancelable:!0}) : "function" === typeof h ? f = new h("unhandledrejection", {cancelable:!0}) : (f = C.document.createEvent("CustomEvent"), f.initCustomEvent("unhandledrejection", !1, !0, f)); - f.promise = this; - f.reason = this.B; - return k(f); + "function" === typeof g ? g = new g("unhandledrejection", {cancelable:!0}) : "function" === typeof h ? g = new h("unhandledrejection", {cancelable:!0}) : (g = B.document.createEvent("CustomEvent"), g.initCustomEvent("unhandledrejection", !1, !0, g)); + g.promise = this; + g.reason = this.B; + return k(g); }; - b.prototype.ea = function() { + b.prototype.N = function() { if (null != this.h) { - for (var f = 0; f < this.h.length; ++f) { - g.A(this.h[f]); + for (var g = 0; g < this.h.length; ++g) { + f.A(this.h[g]); } this.h = null; } }; - var g = new c(); - b.prototype.ja = function(f) { + var f = new c(); + b.prototype.ha = function(g) { var h = this.C(); - f.V(h.resolve, h.reject); + g.U(h.resolve, h.reject); }; - b.prototype.ka = function(f, h) { + b.prototype.ia = function(g, h) { var k = this.C(); try { - f.call(h, k.resolve, k.reject); + g.call(h, k.resolve, k.reject); } catch (l) { k.reject(l); } }; - b.prototype.then = function(f, h) { + b.prototype.then = function(g, h) { function k(p, q) { - return "function" == typeof p ? function(r) { + return "function" == typeof p ? function(t) { try { - l(p(r)); - } catch (v) { - m(v); + l(p(t)); + } catch (x) { + m(x); } } : q; } @@ -420,17 +420,17 @@ F("Promise", function(a) { l = p; m = q; }); - this.V(k(f, l), k(h, m)); + this.U(k(g, l), k(h, m)); return n; }; - b.prototype.catch = function(f) { - return this.then(void 0, f); + b.prototype.catch = function(g) { + return this.then(void 0, g); }; - b.prototype.V = function(f, h) { + b.prototype.U = function(g, h) { function k() { switch(l.A) { case 1: - f(l.B); + g(l.B); break; case 2: h(l.B); @@ -440,46 +440,46 @@ F("Promise", function(a) { } } var l = this; - null == this.h ? g.A(k) : this.h.push(k); - this.L = !0; + null == this.h ? f.A(k) : this.h.push(k); + this.H = !0; }; b.resolve = d; - b.reject = function(f) { + b.reject = function(g) { return new b(function(h, k) { - k(f); + k(g); }); }; - b.race = function(f) { + b.race = function(g) { return new b(function(h, k) { - for (var l = w(f), m = l.next(); !m.done; m = l.next()) { - d(m.value).V(h, k); + for (var l = w(g), m = l.next(); !m.done; m = l.next()) { + d(m.value).U(h, k); } }); }; - b.all = function(f) { - var h = w(f), k = h.next(); + b.all = function(g) { + var h = w(g), k = h.next(); return k.done ? d([]) : new b(function(l, m) { - function n(r) { - return function(v) { - p[r] = v; + function n(t) { + return function(x) { + p[t] = x; q--; 0 == q && l(p); }; } var p = [], q = 0; do { - p.push(void 0), q++, d(k.value).V(n(p.length - 1), m), k = h.next(); + p.push(void 0), q++, d(k.value).U(n(p.length - 1), m), k = h.next(); } while (!k.done); }); }; return b; }); -function ua(a, b) { +function va(a, b) { a instanceof String && (a += ""); var c = 0, d = !1, e = {next:function() { if (!d && c < a.length) { - var g = c++; - return {value:b(g, a[g]), done:!1}; + var f = c++; + return {value:b(f, a[f]), done:!1}; } d = !0; return {done:!0, value:void 0}; @@ -489,17 +489,17 @@ function ua(a, b) { }; return e; } -F("Array.prototype.values", function(a) { +C("Array.prototype.values", function(a) { return a ? a : function() { - return ua(this, function(b, c) { + return va(this, function(b, c) { return c; }); }; }); -function I(a, b) { +function H(a, b) { return Object.prototype.hasOwnProperty.call(a, b); } -F("WeakMap", function(a) { +C("WeakMap", function(a) { function b(k) { this.h = (h += Math.random() + 1).toString(); if (k) { @@ -516,12 +516,12 @@ F("WeakMap", function(a) { return "object" === l && null !== k || "function" === l; } function e(k) { - if (!I(k, f)) { + if (!H(k, g)) { var l = new c(); - ba(k, f, {value:l}); + ba(k, g, {value:l}); } } - function g(k) { + function f(k) { var l = Object[k]; l && (Object[k] = function(m) { if (m instanceof c) { @@ -549,41 +549,41 @@ F("WeakMap", function(a) { }()) { return a; } - var f = "$jscomp_hidden_" + Math.random(); - g("freeze"); - g("preventExtensions"); - g("seal"); + var g = "$jscomp_hidden_" + Math.random(); + f("freeze"); + f("preventExtensions"); + f("seal"); var h = 0; b.prototype.set = function(k, l) { if (!d(k)) { throw Error("Invalid WeakMap key"); } e(k); - if (!I(k, f)) { + if (!H(k, g)) { throw Error("WeakMap key fail: " + k); } - k[f][this.h] = l; + k[g][this.h] = l; return this; }; b.prototype.get = function(k) { - return d(k) && I(k, f) ? k[f][this.h] : void 0; + return d(k) && H(k, g) ? k[g][this.h] : void 0; }; b.prototype.has = function(k) { - return d(k) && I(k, f) && I(k[f], this.h); + return d(k) && H(k, g) && H(k[g], this.h); }; b.prototype.delete = function(k) { - return d(k) && I(k, f) && I(k[f], this.h) ? delete k[f][this.h] : !1; + return d(k) && H(k, g) && H(k[g], this.h) ? delete k[g][this.h] : !1; }; return b; }); -F("Map", function(a) { +C("Map", function(a) { function b() { var h = {}; return h.K = h.next = h.head = h; } function c(h, k) { var l = h[1]; - return ta(function() { + return ua(function() { if (l) { for (; l.head != h[1];) { l = l.K; @@ -598,9 +598,9 @@ F("Map", function(a) { } function d(h, k) { var l = k && typeof k; - "object" == l || "function" == l ? g.has(k) ? l = g.get(k) : (l = "" + ++f, g.set(k, l)) : l = "p_" + k; + "object" == l || "function" == l ? f.has(k) ? l = f.get(k) : (l = "" + ++g, f.set(k, l)) : l = "p_" + k; var m = h[0][l]; - if (m && I(h[0], l)) { + if (m && H(h[0], l)) { for (h = 0; h < m.length; h++) { var n = m[h]; if (k !== k && n.key !== n.key || k === n.key) { @@ -642,7 +642,7 @@ F("Map", function(a) { }()) { return a; } - var g = new WeakMap(); + var f = new WeakMap(); e.prototype.set = function(h, k) { h = 0 === h ? 0 : h; var l = d(this, h); @@ -686,17 +686,17 @@ F("Map", function(a) { } }; e.prototype[Symbol.iterator] = e.prototype.entries; - var f = 0; + var g = 0; return e; }); -F("Array.prototype.keys", function(a) { +C("Array.prototype.keys", function(a) { return a ? a : function() { - return ua(this, function(b) { + return va(this, function(b) { return b; }); }; }); -F("Set", function(a) { +C("Set", function(a) { function b(c) { this.h = new Map(); if (c) { @@ -716,13 +716,13 @@ F("Set", function(a) { if (!d.has(c) || 1 != d.size || d.add(c) != d || 1 != d.size || d.add({x:4}) != d || 2 != d.size) { return !1; } - var e = d.entries(), g = e.next(); - if (g.done || g.value[0] != c || g.value[1] != c) { + var e = d.entries(), f = e.next(); + if (f.done || f.value[0] != c || f.value[1] != c) { return !1; } - g = e.next(); - return g.done || g.value[0] == c || 4 != g.value[0].x || g.value[1] != g.value[0] ? !1 : e.next().done; - } catch (f) { + f = e.next(); + return f.done || f.value[0] == c || 4 != f.value[0].x || f.value[1] != f.value[0] ? !1 : e.next().done; + } catch (g) { return !1; } }()) { @@ -756,40 +756,40 @@ F("Set", function(a) { b.prototype[Symbol.iterator] = b.prototype.values; b.prototype.forEach = function(c, d) { var e = this; - this.h.forEach(function(g) { - return c.call(d, g, g, e); + this.h.forEach(function(f) { + return c.call(d, f, f, e); }); }; return b; }); -F("Array.prototype.entries", function(a) { +C("Array.prototype.entries", function(a) { return a ? a : function() { - return ua(this, function(b, c) { + return va(this, function(b, c) { return [b, c]; }); }; }); -F("Object.is", function(a) { +C("Object.is", function(a) { return a ? a : function(b, c) { return b === c ? 0 !== b || 1 / b === 1 / c : b !== b && c !== c; }; }); -F("Array.prototype.includes", function(a) { +C("Array.prototype.includes", function(a) { return a ? a : function(b, c) { var d = this; d instanceof String && (d = String(d)); var e = d.length; c = c || 0; for (0 > 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; } } return !1; }; }); -F("String.prototype.includes", function(a) { +C("String.prototype.includes", function(a) { return a ? a : function(b, c) { if (null == this) { throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined"); @@ -800,21 +800,7 @@ F("String.prototype.includes", function(a) { return -1 !== this.indexOf(b, c || 0); }; }); -var va = "function" == typeof Object.assign ? Object.assign : function(a, b) { - for (var c = 1; c < arguments.length; c++) { - var d = arguments[c]; - if (d) { - for (var e in d) { - I(d, e) && (a[e] = d[e]); - } - } - } - return a; -}; -F("Object.assign", function(a) { - return a || va; -}); -F("Array.prototype.flat", function(a) { +C("Array.prototype.flat", function(a) { return a ? a : function(b) { b = void 0 === b ? 1 : b; var c = []; @@ -824,14 +810,28 @@ F("Array.prototype.flat", function(a) { return c; }; }); -function J(a, b, c) { +var wa = "function" == typeof Object.assign ? Object.assign : function(a, b) { + for (var c = 1; c < arguments.length; c++) { + var d = arguments[c]; + if (d) { + for (var e in d) { + H(d, e) && (a[e] = d[e]); + } + } + } + return a; +}; +C("Object.assign", function(a) { + return a || wa; +}); +function I(a, b, c) { var d = typeof c, e = typeof a; if ("undefined" !== d) { 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; @@ -863,13 +863,10 @@ function J(a, b, c) { } return "undefined" === e ? b : a; } -function K() { +function J() { return Object.create(null); } -function wa(a, b) { - return b.length - a.length; -} -function L(a) { +function K(a) { return "string" === typeof a; } function M(a) { @@ -884,7 +881,7 @@ function xa(a) { return b; } function ya(a, b) { - if (L(b)) { + if (K(b)) { a = a[b]; } else { for (var c = 0; a && c < b.length; c++) { @@ -907,73 +904,78 @@ function za(a) { ["\u02b2", "j"], ["\u02b3", "r"], ["\u02b4", "\u0279"], ["\u02b5", "\u027b"], ["\u02b6", "\u0281"], ["\u02b7", "w"], ["\u02b8", "y"], ["\u02e0", "\u0263"], ["\u02e1", "l"], ["\u02e2", "s"], ["\u02e3", "x"], ["\u02e4", "\u0295"], ["\u0390", "\u03b9"], ["\u03ac", "\u03b1"], ["\u03ad", "\u03b5"], ["\u03ae", "\u03b7"], ["\u03af", "\u03b9"], ["\u03b0", "\u03c5"], ["\u03ca", "\u03b9"], ["\u03cb", "\u03c5"], ["\u03cc", "\u03bf"], ["\u03cd", "\u03c5"], ["\u03ce", "\u03c9"], ["\u03d0", "\u03b2"], ["\u03d1", "\u03b8"], ["\u03d2", "\u03a5"], ["\u03d3", "\u03a5"], ["\u03d4", "\u03a5"], ["\u03d5", "\u03c6"], ["\u03d6", "\u03c0"], ["\u03f0", "\u03ba"], ["\u03f1", "\u03c1"], ["\u03f2", "\u03c2"], ["\u03f5", "\u03b5"], ["\u0439", "\u0438"], ["\u0450", "\u0435"], ["\u0451", "\u0435"], ["\u0453", "\u0433"], ["\u0457", "\u0456"], ["\u045c", "\u043a"], ["\u045d", "\u0438"], ["\u045e", "\u0443"], ["\u0477", "\u0475"], ["\u04c2", "\u0436"], ["\u04d1", "\u0430"], ["\u04d3", "\u0430"], ["\u04d7", "\u0435"], ["\u04db", "\u04d9"], ["\u04dd", "\u0436"], ["\u04df", "\u0437"], ["\u04e3", "\u0438"], ["\u04e5", "\u0438"], ["\u04e7", "\u043e"], ["\u04eb", "\u04e9"], ["\u04ed", "\u044d"], ["\u04ef", "\u0443"], ["\u04f1", "\u0443"], ["\u04f3", "\u0443"], ["\u04f5", "\u0447"]]; -var Ba = /[^\p{L}\p{N}]+/u, Ca = /(\d{3})/g, Da = /(\D)(\d{3})/g, Ea = /(\d{3})(\D)/g, Fa = "".normalize && /[\u0300-\u036f]/g; -function Ga(a) { - if (!this || this.constructor !== Ga) { +var Ba = /[^\p{L}\p{N}]+/u, Ca = /(\d{3})/g, Da = /(\D)(\d{3})/g, Ga = /(\d{3})(\D)/g, Ha = "".normalize && /[\u0300-\u036f]/g; +function Ia(a) { + if (!this || this.constructor !== Ia) { 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 = w(arguments); - for (var f, h = []; !(f = g.next()).done;) { - h.push(f.value); + f = w(arguments); + for (var g, h = []; !(g = f.next()).done;) { + h.push(g.value); } - g = h; + f = h; } - return new (c.call(b, Ga, e.call(d, g)))(); + return new (c.call(b, Ia, e.call(d, f)))(); } for (b = 0; b < arguments.length; b++) { this.assign(arguments[b]); } } -t = Ga.prototype; -t.assign = function(a) { - this.normalize = J(a.normalize, !0, this.normalize); +u = Ia.prototype; +u.assign = function(a) { + this.normalize = I(a.normalize, !0, this.normalize); var b = a.include, c = b || a.exclude || a.split; - if ("object" === typeof c) { - var d = !b, e = ""; - a.include || (e += "\\p{Z}"); - c.letter && (e += "\\p{L}"); - c.number && (e += "\\p{N}", d = !!b); - c.symbol && (e += "\\p{S}"); - c.punctuation && (e += "\\p{P}"); - c.control && (e += "\\p{C}"); - if (c = c.char) { - e += "object" === typeof c ? c.join("") : c; + if (c || "" === c) { + if ("object" === typeof c && c.constructor !== RegExp) { + var d = ""; + var 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("[" + (b ? "^" : "") + d + "]+", "u"); + } catch (f) { + console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; + } + } else { + this.split = c, e = !1 === c || 2 > "a1a".split(c).length; } - try { - this.split = new RegExp("[" + (b ? "^" : "") + e + "]+", "u"); - } catch (g) { - this.split = /\s+/; - } - this.numeric = d; + this.numeric = I(a.numeric, e); } else { try { - this.split = J(c, Ba, this.split); - } catch (g) { - this.split = /\s+/; + this.split = I(this.split, Ba); + } 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 = J(this.numeric, !0); + this.numeric = I(a.numeric, I(this.numeric, !0)); } - this.prepare = J(a.prepare, null, this.prepare); - this.finalize = J(a.finalize, null, this.finalize); - Fa || (this.mapper = new Map(Aa)); - this.rtl = a.rtl || !1; - this.dedupe = J(a.dedupe, !1, this.dedupe); - this.filter = J((c = a.filter) && new Set(c), null, this.filter); - this.matcher = J((c = a.matcher) && new Map(c), null, this.matcher); - this.mapper = J((c = a.mapper) && new Map(c), null, this.mapper); - this.stemmer = J((c = a.stemmer) && new Map(c), null, this.stemmer); - this.replacer = J(a.replacer, null, this.replacer); - this.minlength = J(a.minlength, 1, this.minlength); - this.maxlength = J(a.maxlength, 0, this.maxlength); - if (this.cache = c = J(a.cache, !0, this.cache)) { - this.U = null, this.L = "number" === typeof c ? c : 2e5, this.N = new Map(), this.O = new Map(), this.C = this.B = 128; + this.prepare = I(a.prepare, null, this.prepare); + this.finalize = I(a.finalize, null, this.finalize); + Ha || (this.mapper = new Map(Aa)); + this.rtl = I(a.rtl, !1, this.rtl); + this.dedupe = I(a.dedupe, !1, this.dedupe); + this.filter = I((c = a.filter) && new Set(c), null, this.filter); + this.matcher = I((c = a.matcher) && new Map(c), null, this.matcher); + this.mapper = I((c = a.mapper) && new Map(c), null, this.mapper); + this.stemmer = I((c = a.stemmer) && new Map(c), null, this.stemmer); + this.replacer = I(a.replacer, null, this.replacer); + this.minlength = I(a.minlength, 1, this.minlength); + this.maxlength = I(a.maxlength, 0, this.maxlength); + if (this.cache = c = I(a.cache, !0, this.cache)) { + this.D = null, this.T = "number" === typeof c ? c : 2e5, this.B = new Map(), this.C = new Map(), this.H = this.G = 128; } this.h = ""; - this.D = null; + this.M = null; this.A = ""; - this.G = null; + this.N = null; if (this.matcher) { for (a = w(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { this.h += (this.h ? "|" : "") + b.value; @@ -986,35 +988,21 @@ t.assign = function(a) { } return this; }; -t.addMatcher = function(a, b) { - if ("object" === typeof a) { - return this.addReplacer(a, b); - } - if (2 > a.length) { - return this.addMapper(a, b); - } - this.matcher || (this.matcher = new Map()); - this.matcher.set(a, b); - this.h += (this.h ? "|" : "") + a; - this.D = null; - this.cache && Ia(this); - return this; -}; -t.addStemmer = function(a, b) { +u.addStemmer = function(a, b) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, b); this.A += (this.A ? "|" : "") + a; - this.G = null; - this.cache && Ia(this); + this.N = null; + this.cache && N(this); return this; }; -t.addFilter = function(a) { +u.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); - this.cache && Ia(this); + this.cache && N(this); return this; }; -t.addMapper = function(a, b) { +u.addMapper = function(a, b) { if ("object" === typeof a) { return this.addReplacer(a, b); } @@ -1023,89 +1011,99 @@ t.addMapper = function(a, b) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, b); - this.cache && Ia(this); + this.cache && N(this); return this; }; -t.addReplacer = function(a, b) { - "string" === typeof a && (a = new RegExp(a, "g")); +u.addMatcher = function(a, b) { + if ("object" === typeof a) { + return this.addReplacer(a, b); + } + if (2 > a.length && (this.dedupe || this.mapper)) { + return this.addMapper(a, b); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(a, b); + this.h += (this.h ? "|" : "") + a; + this.M = null; + this.cache && N(this); + return this; +}; +u.addReplacer = function(a, b) { + if ("string" === typeof a) { + return this.addMatcher(a, b); + } this.replacer || (this.replacer = []); - this.replacer.push(a, b || ""); - this.cache && Ia(this); + this.replacer.push(a, b); + this.cache && N(this); return this; }; -function Ia(a) { - a.N.clear(); - a.O.clear(); -} -t.encode = function(a) { +u.encode = function(a) { var b = this; - if (this.cache && a.length <= this.B) { - if (this.U) { - if (this.N.has(a)) { - return this.N.get(a); + if (this.cache && a.length <= this.G) { + if (this.D) { + if (this.B.has(a)) { + return this.B.get(a); } } else { - this.U = setTimeout(Ja, 50, this); + this.D = setTimeout(N, 50, this); } } - this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : Fa ? a.normalize("NFKD").replace(Fa, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = Ha ? a.normalize("NFKD").replace(Ha, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(Da, "$1 $2").replace(Ea, "$1 $2").replace(Ca, "$1 ")); - for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, g = 0, f = void 0, h = void 0; g < e.length; g++) { - if ((f = h = e[g]) && !(f.length < this.minlength)) { + this.numeric && 3 < a.length && (a = a.replace(Da, "$1 $2").replace(Ga, "$1 $2").replace(Ca, "$1 ")); + for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, f = 0, g = void 0, h = void 0; f < e.length; f++) { + if ((g = h = e[f]) && !(g.length < this.minlength)) { if (c) { - d.push(f); + d.push(g); } else { - if (!this.filter || !this.filter.has(f)) { - if (this.cache && f.length <= this.C) { - if (this.U) { - var k = this.O.get(f); + if (!this.filter || !this.filter.has(g)) { + if (this.cache && g.length <= this.H) { + if (this.D) { + var k = this.C.get(g); if (k || "" === k) { k && d.push(k); continue; } } else { - this.U = setTimeout(Ja, 50, this); + this.D = setTimeout(N, 50, this); } } - k = void 0; - this.stemmer && 2 < f.length && (this.G || (this.G = new RegExp("(?!^)(" + this.A + ")$")), f = f.replace(this.G, function(q) { + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, function(q) { return b.stemmer.get(q); - }), k = 1); - f && k && (f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); - if (f && (this.mapper || this.dedupe && 1 < f.length)) { + }), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + if (g && (this.mapper || this.dedupe && 1 < g.length)) { k = ""; - for (var l = 0, m = "", n = void 0, p = void 0; l < f.length; l++) { - n = f.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); + for (var l = 0, m = "", n = void 0, p = void 0; l < g.length; l++) { + n = g.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); } - f = k; + g = k; } - this.matcher && 1 < f.length && (this.D || (this.D = new RegExp("(" + this.h + ")", "g")), f = f.replace(this.D, function(q) { + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, function(q) { return b.matcher.get(q); })); - if (f && this.replacer) { - for (k = 0; f && k < this.replacer.length; k += 2) { - f = f.replace(this.replacer[k], this.replacer[k + 1]); + if (g && this.replacer) { + for (k = 0; g && k < this.replacer.length; k += 2) { + g = g.replace(this.replacer[k], this.replacer[k + 1]); } } - this.cache && h.length <= this.C && (this.O.set(h, f), this.O.size > this.L && (this.O.clear(), this.C = this.C / 1.1 | 0)); - f && d.push(f); + this.cache && h.length <= this.H && (this.C.set(h, g), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); + g && d.push(g); } } } } this.finalize && (d = this.finalize(d) || d); - this.cache && a.length <= this.B && (this.N.set(a, d), this.N.size > this.L && (this.N.clear(), this.B = this.B / 1.1 | 0)); + this.cache && a.length <= this.G && (this.B.set(a, d), this.B.size > this.T && (this.B.clear(), this.G = this.G / 1.1 | 0)); return d; }; -function Ja(a) { - a.U = null; - a.N.clear(); - a.O.clear(); +function N(a) { + a.D = null; + a.B.clear(); + a.C.clear(); } -;function Ka(a) { - var b, c, d, e, g, f, h; - return sa(function(k) { +;function Ja(a) { + var b, c, d, e, f, g, h; + return ta(function(k) { a = a.data; b = self._index; c = a.args; @@ -1113,33 +1111,33 @@ function Ja(a) { switch(d) { case "init": e = a.options || {}; - (g = a.factory) ? (Function("return " + g)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new N(e); + (f = a.factory) ? (Function("return " + f)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new O(e); postMessage({id:a.id}); break; default: - f = a.id, h = b[d].apply(b, c), postMessage("search" === d ? {id:f, msg:h} : {id:f}); + g = a.id, h = b[d].apply(b, c), postMessage("search" === d ? {id:g, msg:h} : {id:g}); } k.h = 0; }); } -;var La = 0; -function Q(a) { - function b(f) { +;var Ka = 0; +function R(a) { + function b(g) { function h(k) { k = k.data || k; var l = k.id, m = l && e.h[l]; m && (m(k.msg), delete e.h[l]); } - this.worker = f; - this.h = K(); + this.worker = g; + this.h = J(); if (this.worker) { d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { return new Promise(function(k) { - e.h[++La] = function() { + e.h[++Ka] = function() { k(e); }; - e.worker.postMessage({id:La, task:"init", factory:c, options:a}); + e.worker.postMessage({id:Ka, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); @@ -1147,49 +1145,49 @@ function Q(a) { } } a = void 0 === a ? {} : a; - if (!this || this.constructor !== Q) { - return new Q(a); + if (!this || this.constructor !== R) { + return new R(a); } var c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - var d = "undefined" === typeof window, e = this, g = Ma(c, d, a.worker); - return g.then ? g.then(function(f) { - return b.call(e, f); - }) : b.call(this, g); + var d = "undefined" === typeof window, e = this, f = La(c, d, a.worker); + return f.then ? f.then(function(g) { + return b.call(e, g); + }) : b.call(this, f); } -Na("add"); -Na("append"); -Na("search"); -Na("update"); -Na("remove"); -function Na(a) { - Q.prototype[a] = Q.prototype[a + "Async"] = function() { - var b = this, c = arguments, d, e, g, f, h; - return sa(function(k) { +Ma("add"); +Ma("append"); +Ma("search"); +Ma("update"); +Ma("remove"); +function Ma(a) { + R.prototype[a] = R.prototype[a + "Async"] = function() { + var b = this, c = arguments, d, e, f, g, h; + return ta(function(k) { d = b; e = [].slice.call(c); - g = e[e.length - 1]; - "function" === typeof g && (f = g, e.splice(e.length - 1, 1)); + f = e[e.length - 1]; + "function" === typeof f && (g = f, e.splice(e.length - 1, 1)); h = new Promise(function(l) { - d.h[++La] = l; - d.worker.postMessage({task:a, id:La, args:e}); + d.h[++Ka] = l; + d.worker.postMessage({task:a, id:Ka, args:e}); }); - return f ? (h.then(f), k.return(b)) : k.return(h); + return g ? (h.then(g), k.return(b)) : k.return(h); }); }; } -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=" + Ka.toString()], {type:"text/javascript"}))) : new window.Worker(L(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function La(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=" + Ja.toString()], {type:"text/javascript"}))) : new window.Worker(K(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"}); } -;function Oa(a) { - Pa.call(a, "add"); - Pa.call(a, "append"); - Pa.call(a, "search"); - Pa.call(a, "update"); - Pa.call(a, "remove"); +;function Na(a) { + Oa.call(a, "add"); + Oa.call(a, "append"); + Oa.call(a, "search"); + Oa.call(a, "update"); + Oa.call(a, "remove"); } -function Pa(a) { +function Oa(a) { this[a + "Async"] = function() { var b = arguments, c = b[b.length - 1]; if ("function" === typeof c) { @@ -1201,7 +1199,7 @@ function Pa(a) { return b; }; } -;function Qa(a, b) { +;function Pa(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 5000 | 0); @@ -1212,32 +1210,32 @@ function Pa(a) { d.length && c.push(d); return c; } -function Ra(a, b) { +function Qa(a, b) { b || (b = new Map()); for (var c = 0, d; c < a.length; c++) { d = a[c], b.set(d[0], d[1]); } return b; } -function Sa(a, b) { +function Ra(a, b) { b = void 0 === b ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 1000 | 0); a = w(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { - e = e.value, d.push([e[0], Qa(e[1])[0]]), d.length === b && (c.push(d), d = []); + e = e.value, d.push([e[0], Pa(e[1])[0]]), d.length === b && (c.push(d), d = []); } d.length && c.push(d); return c; } -function Ta(a, b) { +function Sa(a, b) { b || (b = new Map()); for (var c = 0, d, e; c < a.length; c++) { - d = a[c], e = b.get(d[0]), b.set(d[0], Ra(d[1], e)); + d = a[c], e = b.get(d[0]), b.set(d[0], Qa(d[1], e)); } return b; } -function Ua(a) { +function Ta(a) { var b = [], c = []; a = w(a.keys()); for (var d = a.next(); !d.done; d = a.next()) { @@ -1246,35 +1244,35 @@ function Ua(a) { c.length && b.push(c); return b; } -function Va(a, b) { +function Ua(a, b) { b || (b = new Set()); for (var c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function Wa(a, b, c, d, e, g, f) { - f = void 0 === f ? 0 : f; +function Va(a, b, c, d, e, f, g) { + g = void 0 === g ? 0 : g; var h = d && d.constructor === Array, k = h ? d.shift() : d; if (!k) { - 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) { + if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { var l = this; return k.then(function() { - return Wa.call(l, a, b, c, h ? d : null, e, g, f + 1); + return Va.call(l, a, b, c, h ? d : null, e, f, g + 1); }); } - return Wa.call(this, a, b, c, h ? d : null, e, g, f + 1); + return Va.call(this, a, b, c, h ? d : null, e, f, g + 1); } -;function Xa(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; +;function Wa(a, b, c, d) { + for (var e = [], f = 0, g; f < a.index.length; f++) { + if (g = a.index[f], b >= g.length) { + b -= g.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 = g[d ? "splice" : "slice"](b, c); + if (g = b.length) { + if (e = e.length ? e.concat(b) : b, c -= g, d && (a.length -= g), !c) { break; } } @@ -1283,9 +1281,9 @@ function Wa(a, b, c, d, e, g, f) { } return e; } -function R(a) { +function S(a) { if (!this) { - return new R(a); + return new S(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -1309,21 +1307,21 @@ function R(a) { } if ("indexOf" === d) { return function(e) { - for (var g = 0, f = 0, h, k; f < b.index.length; f++) { - h = b.index[f]; + for (var f = 0, g = 0, h, k; g < b.index.length; g++) { + h = b.index[g]; k = h.indexOf(e); if (0 <= k) { - return g + k; + return f + k; } - g += h.length; + f += h.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; } } @@ -1331,13 +1329,13 @@ function R(a) { }; } if ("slice" === d) { - return function(e, g) { - return Xa(b, e || 0, g || b.length, !1); + return function(e, f) { + return Wa(b, e || 0, f || b.length, !1); }; } if ("splice" === d) { - return function(e, g) { - return Xa(b, e || 0, g || b.length, !0); + return function(e, f) { + return Wa(b, e || 0, f || b.length, !0); }; } if ("constructor" === d) { @@ -1353,29 +1351,29 @@ function R(a) { return !0; }}); } -R.prototype.clear = function() { +S.prototype.clear = function() { this.index.length = 0; }; -R.prototype.destroy = function() { +S.prototype.destroy = function() { this.proxy = this.index = null; }; -R.prototype.push = function() { +S.prototype.push = function() { }; -function S(a) { +function T(a) { a = void 0 === a ? 8 : a; if (!this) { - return new S(a); + return new T(a); } - this.index = K(); + this.index = J(); this.B = []; this.size = 0; - 32 < a ? (this.h = Ya, this.A = BigInt(a)) : (this.h = Za, this.A = a); + 32 < a ? (this.h = Xa, this.A = BigInt(a)) : (this.h = Ya, this.A = a); } -S.prototype.get = function(a) { +T.prototype.get = function(a) { var b = this.h(a); return (b = this.index[b]) && b.get(a); }; -S.prototype.set = function(a, b) { +T.prototype.set = function(a, b) { var c = this.h(a), d = this.index[c]; d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.B.push(d)); }; @@ -1384,37 +1382,37 @@ function U(a) { if (!this) { return new U(a); } - this.index = K(); + this.index = J(); this.h = []; - 32 < a ? (this.B = Ya, this.A = BigInt(a)) : (this.B = Za, this.A = a); + 32 < a ? (this.B = Xa, this.A = BigInt(a)) : (this.B = Ya, this.A = a); } U.prototype.add = function(a) { var b = this.B(a), 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)); }; -t = S.prototype; -t.has = U.prototype.has = function(a) { +u = T.prototype; +u.has = U.prototype.has = function(a) { var b = this.B(a); return (b = this.index[b]) && b.has(a); }; -t.delete = U.prototype.delete = function(a) { +u.delete = U.prototype.delete = function(a) { var b = this.B(a); (b = this.index[b]) && b.delete(a) && this.size--; }; -t.clear = U.prototype.clear = function() { - this.index = K(); +u.clear = U.prototype.clear = function() { + this.index = J(); this.h = []; this.size = 0; }; -t.values = U.prototype.values = function $a() { - var b, c = this, d, e, g; - return qa($a, function(f) { - switch(f.h) { +u.values = U.prototype.values = function Za() { + var b, c = this, d, e, f; + return ra(Za, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + g.h = 0; break; } d = w(c.h[b].values()); @@ -1422,25 +1420,25 @@ t.values = U.prototype.values = function $a() { case 5: if (e.done) { b++; - f.h = 2; + g.h = 2; break; } - g = e.value; - return G(f, g, 6); + f = e.value; + return E(g, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), g.h = 5; } }); }; -t.keys = U.prototype.keys = function ab() { - var b, c = this, d, e, g; - return qa(ab, function(f) { - switch(f.h) { +u.keys = U.prototype.keys = function $a() { + var b, c = this, d, e, f; + return ra($a, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + g.h = 0; break; } d = w(c.h[b].keys()); @@ -1448,25 +1446,25 @@ t.keys = U.prototype.keys = function ab() { case 5: if (e.done) { b++; - f.h = 2; + g.h = 2; break; } - g = e.value; - return G(f, g, 6); + f = e.value; + return E(g, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), g.h = 5; } }); }; -t.entries = U.prototype.entries = function bb() { - var b, c = this, d, e, g; - return qa(bb, function(f) { - switch(f.h) { +u.entries = U.prototype.entries = function ab() { + var b, c = this, d, e, f; + return ra(ab, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + g.h = 0; break; } d = w(c.h[b].entries()); @@ -1474,17 +1472,17 @@ t.entries = U.prototype.entries = function bb() { case 5: if (e.done) { b++; - f.h = 2; + g.h = 2; break; } - g = e.value; - return G(f, g, 6); + f = e.value; + return E(g, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), g.h = 5; } }); }; -function Za(a) { +function Ya(a) { var b = Math.pow(2, this.A) - 1; if ("number" == typeof a) { return a & b; @@ -1494,7 +1492,7 @@ function Za(a) { } return 32 === this.A ? c + Math.pow(2, 31) : c; } -function Ya() { +function Xa() { throw Error("The keystore is limited to 32 for EcmaScript5"); } ;V.prototype.add = function(a, b, c) { @@ -1504,51 +1502,51 @@ function Ya() { return this.update(a, b); } for (var d = 0, e; d < this.field.length; d++) { - e = this.I[d]; - var g = this.index.get(this.field[d]); + e = this.J[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] : L(e) && (e = [e]), cb(b, e, this.T, 0, g, a, e[0], c); + var g = e.R; + if (!g || g(b)) { + e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), bb(b, e, this.S, 0, f, a, e[0], c); } } } if (this.tag) { - for (d = 0; d < this.M.length; d++) { - f = this.M[d]; - var h = this.$[d]; - g = this.tag.get(h); - e = K(); - if ("function" === typeof f) { - if (f = f(b), !f) { + for (d = 0; d < this.L.length; d++) { + g = this.L[d]; + var h = this.aa[d]; + f = this.tag.get(h); + e = J(); + if ("function" === typeof g) { + if (g = g(b), !g) { continue; } } else { - var k = f.S; + var k = g.R; if (k && !k(b)) { continue; } - f.constructor === String && (f = "" + f); - f = ya(b, f); + g.constructor === String && (g = "" + g); + g = ya(b, g); } - if (g && f) { - for (L(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { - var l = f[h]; + if (f && g) { + for (K(g) && (g = [g]), h = 0, k = void 0; h < g.length; h++) { + var l = g[h]; if (!e[l]) { e[l] = 1; var m; - (m = g.get(l)) ? k = m : g.set(l, k = []); + (m = f.get(l)) ? k = m : f.set(l, k = []); if (!c || !k.includes(a)) { if (k.length === Math.pow(2, 31) - 1) { - m = new R(k); + m = new S(k); if (this.fastupdate) { for (var n = w(this.reg.values()), p = n.next(); !p.done; p = n.next()) { p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); } } - g.set(l, k = m); + f.set(l, k = m); } k.push(a); this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); @@ -1556,27 +1554,27 @@ function Ya() { } } } else { - g || console.warn("Tag '" + h + "' was not found"); + f || console.warn("Tag '" + h + "' was not found"); } } } if (this.store && (!c || !this.store.has(a))) { - if (this.H) { - var q = K(); - for (c = 0; c < this.H.length; c++) { - if (d = this.H[c], g = d.S, !g || g(b)) { - g = void 0; + if (this.I) { + var q = J(); + for (c = 0; c < this.I.length; c++) { + if (d = this.I[c], f = d.R, !f || f(b)) { + f = void 0; if ("function" === typeof d) { - g = d(b); - if (!g) { + f = d(b); + if (!f) { continue; } - d = [d.la]; - } else if (L(d) || d.constructor === String) { + d = [d.ja]; + } else if (K(d) || d.constructor === String) { q[d] = b[d]; continue; } - db(b, q, d, 0, d[0], g); + cb(b, q, d, 0, d[0], f); } } } @@ -1585,59 +1583,59 @@ function Ya() { } return this; }; -function db(a, b, c, d, e, g) { +function cb(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++) { - db(a, b, c, d, e); + cb(a, b, c, d, e); } } else { - b = b[e] || (b[e] = K()), e = c[++d], db(a, b, c, d, e); + b = b[e] || (b[e] = J()), e = c[++d], cb(a, b, c, d, e); } } } -function cb(a, b, c, d, e, g, f, h) { - if (a = a[f]) { +function bb(a, b, c, d, e, f, g, h) { + if (a = a[g]) { 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, h, !0); } else { if (a.constructor === Array) { - for (f = 0; f < a.length; f++) { - cb(a, b, c, d, e, g, f, h); + for (g = 0; g < a.length; g++) { + bb(a, b, c, d, e, f, g, h); } } else { - f = b[++d], cb(a, b, c, d, e, g, f, h); + g = b[++d], bb(a, b, c, d, e, f, g, h); } } } else { - e.db && e.remove(g); + e.db && e.remove(f); } } -;function eb(a, b, c, d, e, g, f) { +;function db(a, b, c, d, e, f, g) { var h = a.length, k = [], l; - var m = K(); + var m = J(); for (var n = 0, p = void 0, q; n < b; n++) { - for (var r = 0; r < h; r++) { - if (q = a[r], n < q.length && (p = q[n])) { - for (var v = 0; v < p.length; v++) { - q = p[v]; + for (var t = 0; t < h; t++) { + if (q = a[t], n < q.length && (p = q[n])) { + for (var x = 0; x < p.length; x++) { + q = p[x]; (l = m[q]) ? m[q]++ : (l = 0, m[q] = 1); l = k[l] || (k[l] = []); - if (!f) { - var z = n + (r ? 0 : g || 0); - l = l[z] || (l[z] = []); + if (!g) { + var r = n + (t || !e ? 0 : f || 0); + l = l[r] || (l[r] = []); } l.push(q); } @@ -1646,27 +1644,27 @@ function cb(a, b, c, d, e, g, f, h) { } if (a = k.length) { if (e) { - k = 1 < k.length ? fb(k, d, c, f, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + k = 1 < k.length ? eb(k, c, d, g, f) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { if (a < h) { return []; } k = k[a - 1]; if (c || d) { - if (f) { + if (g) { if (k.length > c || d) { k = k.slice(d, c + d); } } else { e = []; for (f = 0; f < k.length; f++) { - if (h = k[f], h.length > d) { - d -= h.length; + if (g = k[f], g.length > d) { + d -= g.length; } else { - if (h.length > c || d) { - h = h.slice(d, c + d), c -= h.length, d && (d -= h.length); + if (g.length > c || d) { + g = g.slice(d, c + d), c -= g.length, d && (d -= g.length); } - e.push(h); + e.push(g); if (!c) { break; } @@ -1679,38 +1677,39 @@ function cb(a, b, c, d, e, g, f, h) { } return k; } -function fb(a, b, c, d, e) { - var g = [], f = K(), h = a.length, k = 0; +function eb(a, b, c, d, e) { + var f = [], g = J(), h = a.length, k; if (d) { for (e = h - 1; 0 <= e; e--) { - d = a[e]; - var l = d.length; - for (h = 0; h < l; h++) { - var m = d[h]; - if (!f[m]) { - if (f[m] = 1, b) { - b--; - } else { - if (g.push(m), g.length === c) { - return g; + if (k = (d = a[e]) && d.length) { + for (h = 0; h < k; h++) { + var l = d[h]; + if (!g[l]) { + if (g[l] = 1, c) { + c--; + } else { + if (f.push(l), f.length === b) { + return f; + } } } } } } } else { - for (var n = za(a), p = 0; p < n; p++) { - for (var q = h - 1; 0 <= q; q--) { - if (l = (d = a[q][p]) && d.length) { - for (var r = 0; r < l; r++) { - if (m = d[r], !f[m]) { - if (f[m] = 1, b) { - b--; + for (var m = h - 1, n, p = 0; 0 <= m; m--) { + n = a[m]; + for (var q = 0; q < n.length; q++) { + if (k = (d = n[q]) && d.length) { + for (var t = 0; t < k; t++) { + if (l = d[t], !g[l]) { + if (g[l] = 1, c) { + c--; } else { - var v = p + (q < h - 1 ? e || 0 : 0); - (g[v] || (g[v] = [])).push(m); - if (++k === c) { - return g; + var x = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; + (f[x] || (f[x] = [])).push(l); + if (++p === b) { + return f; } } } @@ -1719,917 +1718,194 @@ function fb(a, b, c, d, e) { } } } - return g; + return f; } -function gb(a, b) { - for (var c = K(), d = [], e = 0, g; e < b.length; e++) { - g = b[e]; - for (var f = 0; f < g.length; f++) { - c[g[f]] = 1; +function fb(a, b, c) { + for (var d = J(), e = [], f = 0, g; f < b.length; f++) { + g = b[f]; + for (var h = 0; h < g.length; h++) { + d[g[h]] = 1; } } - for (b = 0; b < a.length; b++) { - e = a[b], 1 === c[e] && (d.push(e), c[e] = 2); - } - return d; -} -;V.prototype.search = function(a, b, c, d) { - c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); - var e = [], g = [], f = 0; if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - var h = c.pluck; - var k = c.merge; - var l = h || c.field || c.index; - var m = this.tag && c.tag; - var n = this.store && c.enrich; - var p = c.suggest; - var q = c.highlight; - b = c.limit || b; - var r = c.offset || 0; - b || (b = 100); - if (m && (!this.db || !d)) { - m.constructor !== Array && (m = [m]); - for (var v = [], z = 0, x = void 0; z < m.length; z++) { - x = m[z]; - if (L(x)) { - throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); - } - if (x.field && x.tag) { - var u = x.tag; - if (u.constructor === Array) { - for (var y = 0; y < u.length; y++) { - v.push(x.field, u[y]); - } - } else { - v.push(x.field, u); - } - } else { - u = Object.keys(x); - y = 0; - for (var E = void 0, A = void 0; y < u.length; y++) { - if (E = u[y], A = x[E], A.constructor === Array) { - for (var B = 0; B < A.length; B++) { - v.push(E, A[B]); - } - } else { - v.push(E, A); - } - } - } - } - if (!v.length) { - throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); - } - m = v; - if (!a) { - g = []; - if (v.length) { - for (h = 0; h < v.length; h += 2) { - p = void 0; - if (this.db) { - p = this.index.get(v[h]); - if (!p) { - console.warn("Tag '" + v[h] + ":" + v[h + 1] + "' will be skipped because there is no field '" + v[h] + "'."); - continue; - } - g.push(p = p.db.tag(v[h + 1], b, r, n)); - } else { - p = hb.call(this, v[h], v[h + 1], b, r, n); - } - e.push({field:v[h], tag:v[h + 1], result:p}); - } - } - return g.length ? Promise.all(g).then(function(O) { - for (var P = 0; P < O.length; P++) { - e[P].result = O[P]; - } - return e; - }) : e; - } - } - L(l) && (l = [l]); - } - l || (l = this.field); - v = !d && (this.worker || this.db) && []; - z = 0; - for (y = x = u = void 0; z < l.length; z++) { - if (x = l[z], !this.db || !this.tag || this.I[z]) { - u = void 0; - L(x) || (u = x, x = u.field, a = u.query || a, b = u.limit || b, r = u.offset || r, p = u.suggest || p, n = this.store && (u.enrich || n)); - if (d) { - u = d[z]; - } else { - y = u || c; - u = this.index.get(x); - if (m) { - if (this.db) { - y.tag = m; - var T = u.db.support_tag_search; - y.field = l; - } - T || (y.enrich = !1); - } - if (v) { - v[z] = u.search(a, b, y); - y && n && (y.enrich = n); - continue; - } else { - u = u.search(a, b, y), y && n && (y.enrich = n); - } - } - y = u && u.length; - if (m && y) { - E = []; - A = 0; - if (this.db && d) { - if (!T) { - for (B = l.length; B < d.length; B++) { - var D = d[B]; - if (D && D.length) { - A++, E.push(D); - } else if (!p) { - return e; - } - } - } - } else { - B = 0; - for (var Pb = D = void 0; B < m.length; B += 2) { - D = this.tag.get(m[B]); - if (!D) { - if (console.warn("Tag '" + m[B] + ":" + m[B + 1] + "' will be skipped because there is no field '" + m[B] + "'."), p) { - continue; - } else { - return e; - } - } - if (Pb = (D = D && D.get(m[B + 1])) && D.length) { - A++, E.push(D); - } else if (!p) { - return e; - } - } - } - if (A) { - u = gb(u, E); - y = u.length; - if (!y && !p) { - return e; - } - A--; - } - } - if (y) { - g[f] = x, e.push(u), f++; - } else if (1 === l.length) { - return e; - } - } - } - if (v) { - if (this.db && m && m.length && !T) { - for (n = 0; n < m.length; n += 2) { - g = this.index.get(m[n]); - if (!g) { - if (console.warn("Tag '" + m[n] + ":" + m[n + 1] + "' was not found because there is no field '" + m[n] + "'."), p) { - continue; - } else { - return e; - } - } - v.push(g.db.tag(m[n + 1], b, r, !1)); - } - } - var Qb = this; - return Promise.all(v).then(function(O) { - return O.length ? Qb.search(a, b, c, O) : O; - }); - } - if (!f) { - return e; - } - if (h && (!n || !this.store)) { - return e[0]; - } - v = []; - r = 0; - for (p = void 0; r < g.length; r++) { - p = e[r]; - n && p.length && !p[0].doc && (this.db ? v.push(p = this.index.get(this.field[0]).db.enrich(p)) : p.length && (p = ib.call(this, p))); - if (h) { - return p; - } - e[r] = {field:g[r], result:p}; - } - if (n && this.db && v.length) { - var Ha = this; - return Promise.all(v).then(function(O) { - for (var P = 0; P < O.length; P++) { - e[P].result = O[P]; - } - return k ? jb(e, b) : q ? kb(e, a, Ha.index, Ha.field, Ha.I, q) : e; - }); - } - return k ? jb(e, b) : q ? kb(e, a, this.index, this.field, this.I, q) : e; -}; -function kb(a, b, c, d, e, g) { - for (var f, h, k, l = 0, m, n, p; l < a.length; l++) { - for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== f && (f = p, h = f.encode(b)), p = 0; p < m.length; p++) { - var q = "", r = ya(m[p].doc, n), v = f.encode(r); - r = r.split(f.split); - for (var z = 0, x, u; z < v.length; z++) { - x = v[z]; - u = r[z]; - for (var y = void 0, E = 0, A; E < h.length; E++) { - if (A = h[E], "strict" === k) { - if (x === A) { - q += (q ? " " : "") + g.replace("$1", u); - y = !0; - break; - } - } else { - var B = x.indexOf(A); - if (-1 < B) { - q += (q ? " " : "") + u.substring(0, B) + g.replace("$1", u.substring(B, A.length)) + u.substring(B + A.length); - y = !0; - break; - } - } - } - y || (q += (q ? " " : "") + r[z]); - } - m[p].highlight = q; - } - } - return a; -} -function jb(a, b) { - for (var c = [], d = K(), e = 0, g, f; e < a.length; e++) { - g = a[e]; - f = g.result; - for (var h = 0, k, l, m; h < f.length; h++) { - if (l = f[h], k = l.id, m = d[k]) { - m.push(g.field); - } else { - if (c.length === b) { - return c; - } - l.field = d[k] = [g.field]; - c.push(l); - } - } - } - return c; -} -function hb(a, b, c, d, e) { - var g = this.tag.get(a); - if (!g) { - return console.warn("Tag '" + a + "' was not found"), []; - } - if ((a = (g = g && g.get(b)) && g.length - d) && 0 < a) { - if (a > c || d) { - g = g.slice(d, d + c); - } - e && (g = ib.call(this, g)); - return g; - } -} -function ib(a) { - for (var b = Array(a.length), c = 0, d; c < a.length; c++) { - d = a[c], b[c] = {id:d, doc:this.store.get(d)}; - } - return b; -} -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); - } - var b = a.document || a.doc || a, c, d; - this.I = []; - this.field = []; - this.T = []; - this.key = (c = b.key || b.id) && lb(c, this.T) || "id"; - (d = a.keystore || 0) && (this.keystore = d); - this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new S(d) : new Map() : d ? new U(d) : new Set(); - this.H = (c = b.store || null) && c && !0 !== c && []; - this.store = c && (d ? new S(d) : new Map()); - this.cache = (c = a.cache || null) && new W(c); - a.cache = !1; - this.worker = a.worker; - this.index = mb.call(this, a, b); - this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { - this.tag = new Map(); - this.M = []; - this.$ = []; - b = 0; - for (var e = d = void 0; b < c.length; b++) { - d = c[b]; - e = d.field || d; - if (!e) { - throw Error("The tag field from the document descriptor is undefined."); - } - d.custom ? this.M[b] = d.custom : (this.M[b] = lb(e, this.T), d.filter && ("string" === typeof this.M[b] && (this.M[b] = new String(this.M[b])), this.M[b].S = d.filter)); - this.$[b] = e; - this.tag.set(e, new Map()); - } - } - } - if (this.worker) { - a = []; - c = w(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 = w(g.index.entries()), l = k.next(); !l.done; l = k.next()) { - l = l.value; - var m = l[0]; - l[1].then && g.index.set(m, f[h++]); - } - return g; - }); + for (b = 0; b < a.length; b++) { + c = a[b], d[c] && (e.push(c), d[c] = 0); } } else { - a.db && this.mount(a.db); - } -} -t = V.prototype; -t.mount = function(a) { - var b = this.field; - if (this.tag) { - for (var c = 0, d; c < this.$.length; c++) { - d = this.$[c]; - var e; - this.index.set(d, e = new N({}, this.reg)); - b === this.field && (b = b.slice(0)); - b.push(d); - e.tag = this.tag.get(d); - } - } - c = []; - d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - e = 0; - for (var g; 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; - } - this.db = !0; - return Promise.all(c); -}; -t.commit = function(a, b) { - var c = this, d, e, g, f; - return sa(function(h) { - if (1 == h.h) { - d = []; - e = w(c.index.values()); - for (g = e.next(); !g.done; g = e.next()) { - f = g.value, d.push(f.db.commit(f, a, b)); - } - return G(h, Promise.all(d), 2); - } - c.reg.clear(); - h.h = 0; - }); -}; -t.destroy = function() { - for (var a = [], b = w(this.index.values()), c = b.next(); !c.done; c = b.next()) { - a.push(c.value.destroy()); - } - return Promise.all(a); -}; -function mb(a, b) { - var c = new Map(), d = b.index || b.field || b; - L(d) && (d = [d]); - for (var e = 0, g, f = void 0; e < d.length; e++) { - g = d[e]; - L(g) || (f = g, g = g.field); - f = M(f) ? Object.assign({}, a, f) : a; - if (this.worker) { - var h = new Q(f); - c.set(g, h); - } - this.worker || c.set(g, new N(f, this.reg)); - f.custom ? this.I[e] = f.custom : (this.I[e] = lb(g, this.T), f.filter && ("string" === typeof this.I[e] && (this.I[e] = new String(this.I[e])), this.I[e].S = f.filter)); - this.field[e] = g; - } - if (this.H) { - for (a = b.store, L(a) && (a = [a]), b = 0; b < a.length; b++) { - d = a[b], e = d.field || d, d.custom ? (this.H[b] = d.custom, d.custom.la = e) : (this.H[b] = lb(e, this.T), d.filter && ("string" === typeof this.H[b] && (this.H[b] = new String(this.H[b])), this.H[b].S = d.filter)); - } - } - return c; -} -function lb(a, b) { - for (var c = a.split(":"), d = 0, e = 0; e < c.length; e++) { - a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); - } - d < c.length && (c.length = d); - return 1 < d ? c : c[0]; -} -t.append = function(a, b) { - return this.add(a, b, !0); -}; -t.update = function(a, b) { - return this.remove(a).add(a, b); -}; -t.remove = function(a) { - M(a) && (a = ya(a, this.key)); - for (var b = w(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 = w(this.tag.values()), c = b.next(); !c.done; c = b.next()) { - c = c.value; - for (var d = w(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 (b = 0; b < a.result.length; b++) { + for (c = a.result[b], g = 0; g < c.length; g++) { + f = c[g], d[f] && ((e[b] || (e[b] = [])).push(f), d[f] = 0); } } - this.store && this.store.delete(a); - this.reg.delete(a); } - this.cache && this.cache.remove(a); - return this; -}; -t.clear = function() { - for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { - b.value.clear(); - } - if (this.tag) { - for (a = w(this.tag.values()), b = a.next(); !b.done; b = a.next()) { - b.value.clear(); - } - } - this.store && this.store.clear(); - return this; -}; -t.contain = function(a) { - return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); -}; -t.cleanup = function() { - for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { - b.value.cleanup(); - } - return this; -}; -t.get = function(a) { - return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { - return b[0] && b[0].doc; - }) : this.store.get(a); -}; -t.set = function(a, b) { - this.store.set(a, b); - return this; -}; -t.searchCache = nb; -t.export = function(a, b, c, d) { - c = void 0 === c ? 0 : c; - d = void 0 === d ? 0 : 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; - return b.then(function() { - return g.export(a, e, c + 1); - }); - } - return this.export(a, e, c + 1); - } - switch(d) { - case 0: - var f = "reg"; - var h = Ua(this.reg); - b = null; - break; - case 1: - f = "tag"; - h = Sa(this.tag, this.reg.size); - b = null; - break; - case 2: - f = "doc"; - h = Qa(this.store); - b = null; - break; - case 3: - f = "cfg"; - h = {}; - b = null; - break; - default: - return; - } - return Wa.call(this, a, b, f, h, c, d); -}; -t.import = function(a, b) { - if (b) { - L(b) && (b = JSON.parse(b)); - a = a.split("."); - "json" === a[a.length - 1] && a.pop(); - var c = 2 < a.length ? a[0] : ""; - a = 2 < a.length ? a[2] : a[1]; - if (c) { - return this.index.get(c).import(a, b); - } - switch(a) { - case "reg": - this.fastupdate = !1; - this.reg = Va(b, this.reg); - for (b = 0; b < this.field.length; b++) { - c = this.index.get(this.field[b]), c.fastupdate = !1, c.reg = this.reg; - } - break; - case "tag": - this.tag = Ta(b, this.tag); - break; - case "doc": - this.store = Ra(b, this.store); - } - } -}; -Oa(V.prototype); -function nb(a, b, c) { - a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new W()); - var d = this.cache.get(a); - if (!d) { - d = this.search(a, b, c); - if (d.then) { - var e = this; - d.then(function(g) { - e.cache.set(a, g); - return g; - }); - } - this.cache.set(a, d); - } - return d; + return e; } -function W(a) { - this.limit = a && !0 !== a ? a : 1000; - this.cache = new Map(); - this.h = ""; -} -W.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); -}; -W.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; -}; -W.prototype.remove = function(a) { - for (var b = w(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); +;function gb(a, b, c, d) { + if (!a.length) { + return a; } -}; -W.prototype.clear = function() { - this.cache.clear(); - this.h = ""; -}; -var ob = {normalize:function(a) { - return a.toLowerCase(); -}, dedupe:!1}; -var pb = 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 qb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), rb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -var sb = {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 tb = /[\x00-\x7F]+/g; -var ub = /[\x00-\x7F]+/g; -var vb = /[\x00-\x7F]+/g; -var wb = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:ob, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:pb}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:pb, matcher:qb, replacer:rb}, LatinExtra:{normalize:!0, dedupe:!0, mapper:pb, replacer:rb.concat([/(?!^)[aeo]/g, ""]), matcher:qb}, LatinSoundex:{normalize:!0, 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 = sb[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = sb[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { - } - a[b] = d; - } -}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(tb, " "); -}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(ub, ""); -}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(vb, " "); -}}}; -var xb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -K(); -N.prototype.add = function(a, b, c, d) { - if (b && (a || 0 === a)) { - if (!d && !c && this.reg.has(a)) { - return this.update(a, b); - } - b = this.encoder.encode(b); - if (d = b.length) { - for (var e = K(), g = K(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { - var l = b[this.rtl ? d - 1 - k : k], m = l.length; - if (m && (f || !g[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : yb(h, d, k), p = ""; - switch(this.tokenize) { - case "full": - if (2 < m) { - for (n = 0; n < m; n++) { - for (var q = m; q > n; q--) { - p = l.substring(n, q); - var r = this.score ? this.score(b, l, k, p, n) : yb(h, d, k, m, n); - zb(this, g, p, r, a, c); - } - } - break; - } - case "reverse": - if (1 < m) { - for (q = m - 1; 0 < q; q--) { - p = l[q] + p, r = this.score ? this.score(b, l, k, p, q) : yb(h, d, k, m, q), zb(this, g, p, r, a, c); - } - p = ""; - } - case "forward": - if (1 < m) { - for (q = 0; q < m; q++) { - p += l[q], zb(this, g, p, n, a, c); - } - break; - } - default: - if (zb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { - for (m = K(), p = this.aa, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) { - if ((l = b[this.rtl ? d - 1 - k - r : k + r]) && !m[l]) { - m[l] = 1; - var v = this.score ? this.score(b, n, k, l, r) : yb(p + (d / 2 > p ? 0 : 1), d, k, q - 1, r - 1), z = this.bidirectional && l > n; - zb(this, e, z ? n : l, v, a, c, z ? l : n); - } - } - } - } - } - } - this.fastupdate || this.reg.add(a); - } else { - b = ""; - } - } - this.db && (b || this.commit_task.push({del:a}), this.da && Ab(this)); - return this; -}; -function zb(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] = K()), 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 R(h); - if (a.fastupdate) { - for (c = w(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 yb(a, b, c, d, e) { - return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; -} -;function X(a, b, c, d) { if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Bb(a) : a; + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? W.call(this, a) : a; } - for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { - if ((f = a[g]) && (h = f.length)) { + for (var e = [], f = 0, g = void 0, h = void 0; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { if (c) { if (c >= h) { c -= h; continue; } - c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); + c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); } - if (e.length) { - h > b && (f = f.slice(0, b), h = f.length); - } else { - if (h >= b) { - return h > b && (f = f.slice(0, b)), d ? Bb(f) : f; - } + h > b && (g = g.slice(0, b), h = b); + if (!e.length && h >= b) { + return d ? W.call(this, g) : g; } - e.push(f); + e.push(g); b -= h; if (!b) { break; } } } - if (!e.length) { - return e; - } e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? Bb(e) : e; + return d ? W.call(this, e) : e; } -function Bb(a) { - for (var b = 0; b < a.length; b++) { - a[b] = {score:b, id:a[b]}; - } - return a; -} -;Y.prototype.or = function() { - var a = this, b = arguments, c = b[0]; - if (c.then) { - return c.then(function() { - return a.or.apply(a, b); +;function hb(a, b, c) { + var d = c[0]; + if (d.then) { + return Promise.all(c).then(function(q) { + return a[b].apply(a, q); }); } - if (c[0] && c[0].index) { - return this.or.apply(this, c); + if (d[0] && d[0].index) { + return a[b].apply(a, d); } - var d = []; - c = []; - for (var e = 0, g = 0, f, h, k = 0, l = void 0; k < b.length; k++) { - if (l = b[k]) { - e = l.limit || 0; - g = l.offset || 0; - f = l.enrich; - h = l.resolve; - var m = void 0; - if (l.constructor === Y) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.and) { - m = this.and(l.and); - } else if (l.xor) { - m = this.xor(l.xor); - } else if (l.not) { - m = this.not(l.not); + d = []; + for (var e = [], f = 0, g = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { + if (n = c[m]) { + var p = void 0; + if (n.constructor === X) { + p = n.result; + } else if (n.constructor === Array) { + p = n; } else { - continue; - } - d[k] = m; - m.then && c.push(m); - } - } - if (c.length) { - return Promise.all(c).then(function() { - a.result.length && (d = d.concat([a.result])); - a.result = Cb(d, e, g, f, h, a.J); - return h ? a.result : a; - }); - } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = Cb(d, e, g, f, h, this.J)); - return h ? this.result : this; -}; -function Cb(a, b, c, d, e, g) { - if (!a.length) { - return a; - } - "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? X(a[0], b, c, d) : a[0] : fb(a, c, b, e, g); -} -;Y.prototype.and = function() { - if (this.result.length) { - var a = this, b = arguments, c = b[0]; - if (c.then) { - return c.then(function() { - return a.and.apply(a, b); - }); - } - if (c[0] && c[0].index) { - return this.and.apply(this, c); - } - var d = []; - c = []; - for (var e = 0, g = 0, f, h, k = 0, l = void 0; k < b.length; k++) { - if (l = b[k]) { - e = l.limit || 0; - g = l.offset || 0; - f = l.resolve; - h = l.suggest; - var m = void 0; - if (l.constructor === Y) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.or) { - m = this.or(l.or); - } else if (l.xor) { - m = this.xor(l.xor); - } else if (l.not) { - m = this.not(l.not); + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = k, n.enrich = h; + } else if (n.and) { + p = a.and(n.and); + } else if (n.or) { + p = a.or(n.or); + } else if (n.xor) { + p = a.xor(n.xor); + } else if (n.not) { + p = a.not(n.not); } else { continue; } - d[k] = m; - m.then && c.push(m); + } + if (p.then) { + e.push(p); + } else if (p.length) { + d[m] = p; + } else if (!l && ("and" === b || "xor" === b)) { + d = []; + break; } } - if (!d.length) { - return this.result = d, f ? this.result : this; - } - if (c.length) { - return Promise.all(c).then(function() { - d = [a.result].concat(d); - a.result = Db(d, e, g, f, a.J, h); - return f ? a.result : a; - }); - } - d = [this.result].concat(d); - this.result = Db(d, e, g, f, this.J, h); - return f ? this.result : this; } - return this; -}; -function Db(a, b, c, d, e, g) { - if (2 > a.length) { - return []; - } - var f = []; - K(); - var h = za(a); - return h ? eb(a, h, b, c, g, e, d) : f; + return {W:d, $:e, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; } -;Y.prototype.xor = function() { - var a = this, b = arguments, c = b[0]; - if (c.then) { - return c.then(function() { - return a.xor.apply(a, b); +;X.prototype.or = function() { + var a = hb(this, "or", arguments); + return ib.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve); +}; +function ib(a, b, c, d, e, f) { + if (b.length) { + var g = this; + return Promise.all(b).then(function(h) { + a = []; + for (var k = 0, l = void 0; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); + } + return ib.call(g, a, [], c, d, e, f); }); } - if (c[0] && c[0].index) { - return this.xor.apply(this, c); - } - var d = []; - c = []; - for (var e = 0, g = 0, f, h, k = 0, l = void 0; k < b.length; k++) { - if (l = b[k]) { - e = l.limit || 0; - g = l.offset || 0; - f = l.enrich; - h = l.resolve; - var m = void 0; - if (l.constructor === Y) { - m = l.result; - } else if (l.constructor === Array) { - m = l; - } else if (l.index) { - l.resolve = !1, m = l.index.search(l).result; - } else if (l.or) { - m = this.or(l.or); - } else if (l.and) { - m = this.and(l.and); - } else if (l.not) { - m = this.not(l.not); - } else { - continue; - } - d[k] = m; - m.then && c.push(m); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = eb(a, c, d, !1, this.h), d = 0)); + return f ? this.resolve(c, d, e) : this; +} +;X.prototype.and = function() { + var a = this.result.length; + if (!a) { + var b = arguments[0]; + if (b) { + a = !!b.suggest; + var c = b.resolve; + var d = b.limit; + var e = b.offset; + var f = b.enrich && c; } } - if (c.length) { - return Promise.all(c).then(function() { - a.result.length && (d = [a.result].concat(d)); - a.result = Eb(d, e, g, f, !h, a.J); - return h ? a.result : a; + return a ? (a = hb(this, "and", arguments), jb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest)) : c ? this.resolve(d, e, f) : this; +}; +function jb(a, b, c, d, e, f, g) { + if (b.length) { + var h = this; + return Promise.all(b).then(function(k) { + a = []; + for (var l = 0, m = void 0; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return jb.call(h, a, [], c, d, e, f, g); }); } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Eb(d, e, g, f, !h, a.J)); - return h ? this.result : this; + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + if (b = za(a)) { + return this.result = db(a, b, c, d, g, this.h, f), f ? e ? W.call(this.index, this.result) : this.result : this; + } + this.result = []; + } + } else { + g || (this.result = a); + } + return f ? this.resolve(c, d, e) : this; +} +;X.prototype.xor = function() { + var a = hb(this, "xor", arguments); + return kb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); }; -function Eb(a, b, c, d, e, g) { - if (!a.length) { - return a; +function kb(a, b, c, d, e, f, g) { + if (b.length) { + var h = this; + return Promise.all(b).then(function(k) { + a = []; + for (var l = 0, m = void 0; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return kb.call(h, a, [], c, d, e, f, g); + }); } - if (2 > a.length) { - return e ? X(a[0], b, c, d) : a[0]; + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = lb.call(this, a, c, d, f, this.h), f ? e ? W.call(this.index, this.result) : this.result : this; + } + } else { + g || (this.result = a); } - d = []; - for (var f = K(), h = 0, k = 0, l; k < a.length; k++) { + return f ? this.resolve(c, d, e) : this; +} +function lb(a, b, c, d, e) { + for (var f = [], g = J(), h = 0, k = 0, l; k < a.length; k++) { if (l = a[k]) { + h < l.length && (h = l.length); for (var m = 0, n; m < l.length; m++) { if (n = l[m]) { - h < n.length && (h = n.length); for (var p = 0, q; p < n.length; p++) { - q = n[p], f[q] ? f[q]++ : f[q] = 1; + q = n[p], g[q] = g[q] ? 2 : 1; } } } @@ -2640,20 +1916,20 @@ function Eb(a, b, c, d, e, g) { if (n = a[m]) { if (n = n[k]) { for (p = 0; p < n.length; p++) { - if (q = n[p], 1 === f[q]) { + if (q = n[p], 1 === g[q]) { if (c) { c--; } else { - if (e) { - if (d.push(q), d.length === b) { - return d; + if (d) { + if (f.push(q), f.length === b) { + return f; } } else { - var r = k + (m ? g : 0); - d[r] || (d[r] = []); - d[r].push(q); + var t = k + (m ? e : 0); + f[t] || (f[t] = []); + f[t].push(q); if (++l === b) { - return d; + return f; } } } @@ -2663,64 +1939,37 @@ function Eb(a, b, c, d, e, g) { } } } - return d; + return f; } -;Y.prototype.not = function() { - var a = this, b = arguments, c = b[0]; - if (c.then) { - return c.then(function() { - return a.not.apply(a, b); - }); - } - if (c[0] && c[0].index) { - return this.not.apply(this, c); - } - var d = []; - c = []; - for (var e = 0, g = 0, f, h = 0, k = void 0; h < b.length; h++) { - if (k = b[h]) { - e = k.limit || 0; - g = k.offset || 0; - f = k.resolve; - var l = void 0; - if (k.constructor === Y) { - l = k.result; - } else if (k.constructor === Array) { - l = k; - } else if (k.index) { - k.resolve = !1, l = k.index.search(k).result; - } else if (k.or) { - l = this.or(k.or); - } else if (k.and) { - l = this.and(k.and); - } else if (k.xor) { - l = this.xor(k.xor); - } else { - continue; - } - d[h] = l; - l.then && c.push(l); - } - } - if (c.length) { - return Promise.all(c).then(function() { - a.result = Fb.call(a, d, e, g, f); - return f ? a.result : a; - }); - } - d.length && (this.result = Fb.call(this, d, e, g, f)); - return f ? this.result : this; +;X.prototype.not = function() { + var a = hb(this, "not", arguments); + return mb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); }; -function Fb(a, b, c, d) { - if (!a.length) { - return this.result; +function mb(a, b, c, d, e, f, g) { + if (b.length) { + var h = this; + return Promise.all(b).then(function(k) { + a = []; + for (var l = 0, m = void 0; l < k.length; l++) { + (m = k[l]).length && (a[l] = m); + } + return mb.call(h, a, [], c, d, e, f, g); + }); } + if (a.length && this.result.length) { + this.result = nb.call(this, a, c, d, f); + } else if (f) { + return this.resolve(c, d, e); + } + return f ? e ? W.call(this.index, this.result) : this.result : this; +} +function nb(a, b, c, d) { var e = []; a = new Set(a.flat().flat()); - for (var g = 0, f, h = 0; g < this.result.length; g++) { - if (f = this.result[g]) { - for (var k = 0, l; k < f.length; k++) { - if (l = f[k], !a.has(l)) { + for (var f = 0, g, h = 0; f < this.result.length; f++) { + if (g = this.result[f]) { + for (var k = 0, l; k < g.length; k++) { + if (l = g[k], !a.has(l)) { if (c) { c--; } else { @@ -2729,7 +1978,7 @@ function Fb(a, b, c, d) { return e; } } else { - if (e[g] || (e[g] = []), e[g].push(l), ++h === b) { + if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { return e; } } @@ -2740,21 +1989,18 @@ function Fb(a, b, c, d) { } return e; } -;function Y(a) { - if (!this || this.constructor !== Y) { - return new Y(a); +;function X(a) { + if (!this || this.constructor !== X) { + return new X(a); } if (a && a.index) { - return a.resolve = !1, this.index = a.index, this.J = a.boost || 0, this.result = a.index.search(a).result, this; - } - if (a.constructor === Y) { - return a; + return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; } this.index = null; this.result = a || []; - this.J = 0; + this.h = 0; } -Y.prototype.limit = function(a) { +X.prototype.limit = function(a) { if (this.result.length) { for (var b = [], c = 0, d = 0, e; d < this.result.length; d++) { if (e = this.result[d], e.length + c < a) { @@ -2768,7 +2014,7 @@ Y.prototype.limit = function(a) { } return this; }; -Y.prototype.offset = function(a) { +X.prototype.offset = function(a) { if (this.result.length) { for (var b = [], c = 0, d = 0, e; d < this.result.length; d++) { e = this.result[d], e.length + c < a ? c += e.length : (b[d] = e.slice(a - c), c = a); @@ -2777,188 +2023,838 @@ Y.prototype.offset = function(a) { } return this; }; -Y.prototype.boost = function(a) { - this.J += a; +X.prototype.boost = function(a) { + this.h += a; return this; }; -Y.prototype.resolve = function(a, b, c) { - Gb = 1; - var d = this.result; +X.prototype.resolve = function(a, b, c) { + var d = this.result, e = this.index; this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), X(d, a || 100, b, c)) : d; + return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), gb.call(e, d, a || 100, b, c)) : d; }; -var Gb = 1; -N.prototype.search = function(a, b, c) { +J(); +V.prototype.search = function(a, b, c, d) { c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); - var d = [], e = 0, g; + var e = [], f = [], g = 0; + if (c) { + c.constructor === Array && (c = {index:c}); + a = c.query || a; + var h = c.pluck; + var k = c.merge; + var l = h || c.field || (l = c.index) && (l.index ? null : l); + var m = this.tag && c.tag; + var n = c.suggest; + var p = !1 !== c.resolve; + if (!p && !h) { + if (l = l || this.field) { + K(l) ? h = l : (l.constructor === Array && 1 === l.length && (l = l[0]), h = l.field || l.index); + } + if (!h) { + throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); + } + } + this.store && c.enrich && !p && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var q = this.store && c.enrich && p; + var t = c.highlight && q; + b = c.limit || b; + var x = c.offset || 0; + b || (b = 100); + if (m && (!this.db || !d)) { + m.constructor !== Array && (m = [m]); + for (var r = [], A = 0, z = void 0; A < m.length; A++) { + z = m[A]; + if (K(z)) { + throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); + } + if (z.field && z.tag) { + var v = z.tag; + if (v.constructor === Array) { + for (var y = 0; y < v.length; y++) { + r.push(z.field, v[y]); + } + } else { + r.push(z.field, v); + } + } else { + v = Object.keys(z); + y = 0; + for (var D = void 0, F = void 0; y < v.length; y++) { + if (D = v[y], F = z[D], F.constructor === Array) { + for (var G = 0; G < F.length; G++) { + r.push(D, F[G]); + } + } else { + r.push(D, F); + } + } + } + } + if (!r.length) { + throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); + } + m = r; + if (!a) { + p = []; + if (r.length) { + for (f = 0; f < r.length; f += 2) { + h = void 0; + if (this.db) { + h = this.index.get(r[f]); + if (!h) { + console.warn("Tag '" + r[f] + ":" + r[f + 1] + "' will be skipped because there is no field '" + r[f] + "'."); + continue; + } + p.push(h = h.db.tag(r[f + 1], b, x, q)); + } else { + h = ob.call(this, r[f], r[f + 1], b, x, q); + } + e.push({field:r[f], tag:r[f + 1], result:h}); + } + } + return p.length ? Promise.all(p).then(function(P) { + for (var Q = 0; Q < P.length; Q++) { + e[Q].result = P[Q]; + } + return e; + }) : e; + } + } + l && l.constructor !== Array && (l = [l]); + } + l || (l = this.field); + r = !d && (this.worker || this.db) && []; + A = 0; + for (y = z = v = void 0; A < l.length; A++) { + if (z = l[A], !this.db || !this.tag || this.J[A]) { + v = void 0; + K(z) || (v = z, z = v.field, a = v.query || a, b = v.limit || b, x = v.offset || x, n = v.suggest || n, q = this.store && (v.enrich || q)); + if (d) { + v = d[A]; + } else { + y = v || c; + v = this.index.get(z); + if (m) { + if (this.db) { + y.tag = m; + var Ea = v.db.support_tag_search; + y.field = l; + } + Ea || (y.enrich = !1); + } + if (r) { + r[A] = v.search(a, b, y); + y && q && (y.enrich = q); + continue; + } else { + v = v.search(a, b, y), y && q && (y.enrich = q); + } + } + y = v && (p ? v.length : v.result.length); + if (m && y) { + D = []; + F = 0; + if (this.db && d) { + if (!Ea) { + for (G = l.length; G < d.length; G++) { + var L = d[G]; + if (L && L.length) { + F++, D.push(L); + } else if (!n) { + return p ? e : new X(e); + } + } + } + } else { + G = 0; + for (var Qb = L = void 0; G < m.length; G += 2) { + L = this.tag.get(m[G]); + if (!L) { + if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), n) { + continue; + } else { + return p ? e : new X(e); + } + } + if (Qb = (L = L && L.get(m[G + 1])) && L.length) { + F++, D.push(L); + } else if (!n) { + return p ? e : new X(e); + } + } + } + if (F) { + v = fb(v, D, p); + y = v.length; + if (!y && !n) { + return p ? v : new X(v); + } + F--; + } + } + if (y) { + f[g] = z, e.push(v), g++; + } else if (1 === l.length) { + return p ? e : new X(e); + } + } + } + if (r) { + if (this.db && m && m.length && !Ea) { + for (q = 0; q < m.length; q += 2) { + f = this.index.get(m[q]); + if (!f) { + if (console.warn("Tag '" + m[q] + ":" + m[q + 1] + "' was not found because there is no field '" + m[q] + "'."), n) { + continue; + } else { + return p ? e : new X(e); + } + } + r.push(f.db.tag(m[q + 1], b, x, !1)); + } + } + var Rb = this; + return Promise.all(r).then(function(P) { + return P.length ? Rb.search(a, b, c, P) : P; + }); + } + if (!g) { + return p ? e : new X(e); + } + if (h && (!q || !this.store)) { + return e[0]; + } + r = []; + x = 0; + for (n = void 0; x < f.length; x++) { + n = e[x]; + q && n.length && !n[0].doc && (this.db ? r.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = W.call(this, n)); + if (h) { + return p ? n : new X(n); + } + e[x] = {field:f[x], result:n}; + } + if (q && this.db && r.length) { + var Fa = this; + return Promise.all(r).then(function(P) { + for (var Q = 0; Q < P.length; Q++) { + e[Q].result = P[Q]; + } + return k ? pb(e, b) : t ? qb(e, a, Fa.index, Fa.field, Fa.J, t) : e; + }); + } + return k ? pb(e, b) : t ? qb(e, a, this.index, this.field, this.J, t) : e; +}; +function qb(a, b, c, d, e, f) { + for (var g, h, k, l = 0, m, n, p; l < a.length; l++) { + for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== g && (g = p, h = g.encode(b)), p = 0; p < m.length; p++) { + var q = "", t = ya(m[p].doc, n), x = g.encode(t); + t = t.split(g.split); + for (var r = 0, A, z; r < x.length; r++) { + A = x[r]; + z = t[r]; + for (var v = void 0, y = 0, D; y < h.length; y++) { + if (D = h[y], "strict" === k) { + if (A === D) { + q += (q ? " " : "") + f.replace("$1", z); + v = !0; + break; + } + } else { + var F = A.indexOf(D); + if (-1 < F) { + q += (q ? " " : "") + z.substring(0, F) + f.replace("$1", z.substring(F, D.length)) + z.substring(F + D.length); + v = !0; + break; + } + } + } + v || (q += (q ? " " : "") + t[r]); + } + m[p].highlight = q; + } + } + return a; +} +function pb(a, b) { + for (var c = [], d = J(), e = 0, f, g; e < a.length; e++) { + f = a[e]; + g = f.result; + for (var h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], k = l.id, m = d[k]) { + m.push(f.field); + } else { + if (c.length === b) { + return c; + } + l.field = d[k] = [f.field]; + c.push(l); + } + } + } + return c; +} +function ob(a, b, c, d, e) { + var f = this.tag.get(a); + if (!f) { + return console.warn("Tag '" + a + "' was not found"), []; + } + if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { + if (a > c || d) { + f = f.slice(d, d + c); + } + e && (f = W.call(this, f)); + return f; + } +} +function W(a) { + if (!this || !this.store) { + return a; + } + for (var b = Array(a.length), c = 0, d; c < a.length; c++) { + d = a[c], b[c] = {id:d, doc:this.store.get(d)}; + } + return b; +} +;function V(a) { + if (!this || this.constructor !== V) { + return new V(a); + } + var b = a.document || a.doc || a, c, d; + this.J = []; + this.field = []; + this.S = []; + this.key = (c = b.key || b.id) && rb(c, this.S) || "id"; + (d = a.keystore || 0) && (this.keystore = d); + this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new T(d) : new Map() : d ? new U(d) : new Set(); + this.I = (c = b.store || null) && c && !0 !== c && []; + this.store = c && (d ? new T(d) : new Map()); + this.cache = (c = a.cache || null) && new Y(c); + a.cache = !1; + this.worker = a.worker; + this.index = sb.call(this, a, b); + this.tag = null; + if (c = b.tag) { + if ("string" === typeof c && (c = [c]), c.length) { + this.tag = new Map(); + this.L = []; + this.aa = []; + b = 0; + for (var e = d = void 0; b < c.length; b++) { + d = c[b]; + e = d.field || d; + if (!e) { + throw Error("The tag field from the document descriptor is undefined."); + } + d.custom ? this.L[b] = d.custom : (this.L[b] = rb(e, this.S), d.filter && ("string" === typeof this.L[b] && (this.L[b] = new String(this.L[b])), this.L[b].R = d.filter)); + this.aa[b] = e; + this.tag.set(e, new Map()); + } + } + } + if (this.worker) { + a = []; + c = w(this.index.values()); + for (b = c.next(); !b.done; b = c.next()) { + b = b.value, b.then && a.push(b); + } + if (a.length) { + var f = this; + return Promise.all(a).then(function(g) { + for (var h = 0, k = w(f.index.entries()), l = k.next(); !l.done; l = k.next()) { + l = l.value; + var m = l[0]; + l[1].then && f.index.set(m, g[h++]); + } + return f; + }); + } + } else { + a.db && this.mount(a.db); + } +} +u = V.prototype; +u.mount = function(a) { + var b = this.field; + if (this.tag) { + for (var c = 0, d; c < this.aa.length; c++) { + d = this.aa[c]; + var e; + this.index.set(d, e = new O({}, this.reg)); + b === this.field && (b = b.slice(0)); + b.push(d); + e.tag = this.tag.get(d); + } + } + c = []; + d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; + e = 0; + for (var f; e < b.length; e++) { + d.field = f = b[e]; + f = this.index.get(f); + var g = new a.constructor(a.id, d); + g.id = a.id; + c[e] = g.mount(f); + f.document = !0; + e ? f.bypass = !0 : f.store = this.store; + } + this.db = !0; + return Promise.all(c); +}; +u.commit = function(a, b) { + var c = this, d, e, f, g; + return ta(function(h) { + if (1 == h.h) { + d = []; + e = w(c.index.values()); + for (f = e.next(); !f.done; f = e.next()) { + g = f.value, d.push(g.db.commit(g, a, b)); + } + return E(h, Promise.all(d), 2); + } + c.reg.clear(); + h.h = 0; + }); +}; +u.destroy = function() { + for (var a = [], b = w(this.index.values()), c = b.next(); !c.done; c = b.next()) { + a.push(c.value.destroy()); + } + return Promise.all(a); +}; +function sb(a, b) { + var c = new Map(), d = b.index || b.field || b; + K(d) && (d = [d]); + for (var e = 0, f, g = void 0; e < d.length; e++) { + f = d[e]; + K(f) || (g = f, f = f.field); + g = M(g) ? Object.assign({}, a, g) : a; + if (this.worker) { + var h = new R(g); + c.set(f, h); + } + this.worker || c.set(f, new O(g, this.reg)); + g.custom ? this.J[e] = g.custom : (this.J[e] = rb(f, this.S), g.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = g.filter)); + this.field[e] = f; + } + if (this.I) { + for (a = b.store, K(a) && (a = [a]), b = 0; b < a.length; b++) { + d = a[b], e = d.field || d, d.custom ? (this.I[b] = d.custom, d.custom.ja = e) : (this.I[b] = rb(e, this.S), d.filter && ("string" === typeof this.I[b] && (this.I[b] = new String(this.I[b])), this.I[b].R = d.filter)); + } + } + return c; +} +function rb(a, b) { + for (var c = a.split(":"), d = 0, e = 0; e < c.length; e++) { + a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); + } + d < c.length && (c.length = d); + return 1 < d ? c : c[0]; +} +u.append = function(a, b) { + return this.add(a, b, !0); +}; +u.update = function(a, b) { + return this.remove(a).add(a, b); +}; +u.remove = function(a) { + M(a) && (a = ya(a, this.key)); + for (var b = w(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 = w(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + c = c.value; + for (var d = w(c), e = d.next(); !e.done; e = d.next()) { + var f = e.value; + e = f[0]; + f = f[1]; + var g = f.indexOf(a); + -1 < g && (1 < f.length ? f.splice(g, 1) : c.delete(e)); + } + } + } + this.store && this.store.delete(a); + this.reg.delete(a); + } + this.cache && this.cache.remove(a); + return this; +}; +u.clear = function() { + for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { + b.value.clear(); + } + if (this.tag) { + for (a = w(this.tag.values()), b = a.next(); !b.done; b = a.next()) { + b.value.clear(); + } + } + this.store && this.store.clear(); + return this; +}; +u.contain = function(a) { + return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); +}; +u.cleanup = function() { + for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { + b.value.cleanup(); + } + return this; +}; +u.get = function(a) { + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { + return b[0] && b[0].doc; + }) : this.store.get(a); +}; +u.set = function(a, b) { + this.store.set(a, b); + return this; +}; +u.searchCache = tb; +u.export = function(a, b, c, d) { + c = void 0 === c ? 0 : c; + d = void 0 === d ? 0 : 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 f = this; + return b.then(function() { + return f.export(a, e, c + 1); + }); + } + return this.export(a, e, c + 1); + } + switch(d) { + case 0: + var g = "reg"; + var h = Ta(this.reg); + b = null; + break; + case 1: + g = "tag"; + h = Ra(this.tag, this.reg.size); + b = null; + break; + case 2: + g = "doc"; + h = Pa(this.store); + b = null; + break; + case 3: + g = "cfg"; + h = {}; + b = null; + break; + default: + return; + } + return Va.call(this, a, b, g, h, c, d); +}; +u.import = function(a, b) { + if (b) { + "string" === typeof b && (b = JSON.parse(b)); + a = a.split("."); + "json" === a[a.length - 1] && a.pop(); + var c = 2 < a.length ? a[0] : ""; + a = 2 < a.length ? a[2] : a[1]; + if (c) { + return this.index.get(c).import(a, b); + } + switch(a) { + case "reg": + this.fastupdate = !1; + this.reg = Ua(b, this.reg); + for (b = 0; b < this.field.length; b++) { + c = this.index.get(this.field[b]), c.fastupdate = !1, c.reg = this.reg; + } + break; + case "tag": + this.tag = Sa(b, this.tag); + break; + case "doc": + this.store = Qa(b, this.store); + } + } +}; +Na(V.prototype); +function tb(a, b, c) { + a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); + this.cache || (this.cache = new Y()); + var d = this.cache.get(a); + if (!d) { + d = this.search(a, b, c); + if (d.then) { + var e = this; + d.then(function(f) { + e.cache.set(a, f); + return f; + }); + } + this.cache.set(a, d); + } + return d; +} +function Y(a) { + this.limit = a && !0 !== a ? a : 1000; + this.cache = new Map(); + this.h = ""; +} +Y.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); +}; +Y.prototype.get = function(a) { + var b = this.cache.get(a); + b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); + return b; +}; +Y.prototype.remove = function(a) { + for (var b = w(this.cache), c = b.next(); !c.done; c = b.next()) { + c = c.value; + var d = c[0]; + c[1].includes(a) && this.cache.delete(d); + } +}; +Y.prototype.clear = function() { + this.cache.clear(); + this.h = ""; +}; +var ub = {normalize:function(a) { + return a.toLowerCase(); +}, numeric:!1, dedupe:!1}; +var vb = 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 wb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), xb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +var yb = {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 zb = /[\x00-\x7F]+/g; +var Ab = /[\x00-\x7F]+/g; +var Bb = /[\x00-\x7F]+/g; +var Cb = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:ub, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:vb}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:vb, matcher:wb, replacer:xb}, LatinExtra:{normalize:!0, dedupe:!0, mapper:vb, replacer:xb.concat([/(?!^)[aeo]/g, ""]), matcher:wb}, LatinSoundex:{normalize:!0, 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 = yb[d], f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = yb[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + } + a[b] = d; + } +}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(zb, " "); +}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { + return ("" + a).replace(Ab, ""); +}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(Bb, " "); +}}}; +var Db = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +O.prototype.add = function(a, b, c, d) { + if (b && (a || 0 === a)) { + if (!d && !c && this.reg.has(a)) { + return this.update(a, b); + } + b = this.encoder.encode(b); + if (d = b.length) { + for (var e = J(), f = J(), g = this.depth, h = this.resolution, k = 0; k < d; k++) { + var l = b[this.rtl ? d - 1 - k : k], m = l.length; + if (m && (g || !f[l])) { + var n = this.score ? this.score(b, l, k, null, 0) : Eb(h, d, k), p = ""; + switch(this.tokenize) { + case "full": + if (2 < m) { + for (n = 0; n < m; n++) { + for (var q = m; q > n; q--) { + p = l.substring(n, q); + var t = this.score ? this.score(b, l, k, p, n) : Eb(h, d, k, m, n); + Fb(this, f, p, t, a, c); + } + } + break; + } + case "reverse": + if (1 < m) { + for (q = m - 1; 0 < q; q--) { + p = l[q] + p, t = this.score ? this.score(b, l, k, p, q) : Eb(h, d, k, m, q), Fb(this, f, p, t, a, c); + } + p = ""; + } + case "forward": + if (1 < m) { + for (q = 0; q < m; q++) { + p += l[q], Fb(this, f, p, n, a, c); + } + break; + } + default: + if (Fb(this, f, l, n, a, c), g && 1 < d && k < d - 1) { + for (m = J(), p = this.da, n = l, q = Math.min(g + 1, d - k), t = m[n] = 1; t < q; t++) { + if ((l = b[this.rtl ? d - 1 - k - t : k + t]) && !m[l]) { + m[l] = 1; + var x = this.score ? this.score(b, n, k, l, t) : Eb(p + (d / 2 > p ? 0 : 1), d, k, q - 1, t - 1), r = this.bidirectional && l > n; + Fb(this, e, r ? n : l, x, a, c, r ? l : n); + } + } + } + } + } + } + this.fastupdate || this.reg.add(a); + } else { + b = ""; + } + } + this.db && (b || this.commit_task.push({del:a}), this.ca && Gb(this)); + return this; +}; +function Fb(a, b, c, d, e, f, g) { + var h = g ? a.ctx : a.map, k; + if (!b[c] || g && !(k = b[c])[g]) { + if (g ? (b = k || (b[c] = J()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { + if (h.length === Math.pow(2, 31) - 1) { + b = new S(h); + if (a.fastupdate) { + for (c = w(a.reg.values()), f = c.next(); !f.done; f = c.next()) { + f = f.value, f.includes(h) && (f[f.indexOf(h)] = b); + } + } + k[d] = h = b; + } + h.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + } + } +} +function Eb(a, b, c, d, e) { + return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; +} +;O.prototype.search = function(a, b, c) { + c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); + var d = [], e = 0, f; if (c) { a = c.query || a; b = c.limit || b; e = c.offset || 0; - var f = c.context; + var g = c.context; var h = c.suggest; - (g = Gb && !1 !== c.resolve) || (Gb = 0); - var k = g && c.enrich; + var k = (f = !1 !== c.resolve) && c.enrich; var l = c.boost; var m = c.resolution; var n = this.db && c.tag; } else { - g = this.resolve || Gb; + f = this.resolve; } var p = this.encoder.encode(a); var q = p.length; - b || !g || (b = 100); + b = b || (f ? 100 : 0); if (1 === q) { - return Hb.call(this, p[0], "", b, e, g, k, n); + return Hb.call(this, p[0], "", b, e, f, k, n); } - f = this.depth && !1 !== f; - if (2 === q && f && !h) { - return Hb.call(this, p[0], p[1], b, e, g, k, n); + g = this.depth && !1 !== g; + if (2 === q && g && !h) { + return Hb.call(this, p[0], p[1], b, e, f, k, n); } - c = a = 0; - if (1 < q) { - for (var r = K(), v = [], z = 0, x = void 0; z < q; z++) { - if ((x = p[z]) && !r[x]) { - if (h || this.db || Z(this, x)) { - v.push(x), r[x] = 1; - } else { - return g ? d : new Y(d); - } - x = x.length; - a = Math.max(a, x); - c = c ? Math.min(c, x) : x; - } - } - p = v; - q = p.length; + var t = J(), x = 0; + if (1 < q && g) { + var r = p[0]; + x = 1; } - if (!q) { - return g ? d : new Y(d); - } - var u = 0; - if (1 === q) { - return Hb.call(this, p[0], "", b, e, g, k, n); - } - if (2 === q && f && !h) { - return Hb.call(this, p[0], p[1], b, e, g, k, n); - } - if (1 < q) { - if (f) { - var y = p[0]; - u = 1; - } else { - 9 < a && 3 < a / c && p.sort(wa); - } - } - m || 0 === m || (m = this.resolution); + m || 0 === m || (m = r ? this.da : this.resolution); if (this.db) { - if (this.db.search && (f = this.db.search(this, p, b, e, h, g, k, n), !1 !== f)) { - return f; + if (this.db.search && (a = this.db.search(this, p, b, e, h, f, k, n), !1 !== a)) { + return a; } - var E = this; + var A = this; return function() { - var A, B, T; - return sa(function(D) { - switch(D.h) { + var z, v; + return ta(function(y) { + switch(y.h) { case 1: - B = A = void 0; + v = z = void 0; case 2: - if (!(u < q)) { - D.h = 4; + if (!(x < q)) { + y.h = 4; break; } - B = p[u]; - return y ? G(D, Z(E, B, y, 0, 0, !1, !1), 8) : G(D, Z(E, B, "", 0, 0, !1, !1), 7); - case 7: - A = D.D; - A = Ib(A, d, h, m); - D.h = 6; - break; - case 8: - A = D.D, A = Ib(A, d, h, E.aa), h && !1 === A && d.length || (y = B); + v = p[x]; + if (!v || t[v]) { + y.h = 5; + break; + } + t[v] = 1; + return E(y, Ib(A, v, r, 0, 0, !1, !1), 6); case 6: - if (A) { - return D.return(A); + z = y.G; + if (z = Jb(z, d, h, m)) { + d = z; + y.h = 4; + break; } - if (h && u === q - 1) { - T = d.length; - if (!T) { - if (y) { - y = ""; - u = -1; - D.h = 3; - break; - } - return D.return(d); - } - if (1 === T) { - return D.return(g ? X(d[0], b, e) : new Y(d[0])); - } - } - case 3: - u++; - D.h = 2; + r && (h && z && d.length || (r = v)); + case 5: + h && r && x === q - 1 && !d.length && (r = "", x = -1, t = J()); + x++; + y.h = 2; break; case 4: - return D.return(g ? eb(d, m, b, e, h, l, g) : new Y(d[0])); + return y.return(Kb(d, m, b, e, h, l, f)); } }); }(); } - for (k = f = void 0; u < q; u++) { - k = p[u]; - y ? (f = Z(this, k, y, 0, 0, !1, !1), f = Ib(f, d, h, this.aa), h && !1 === f && d.length || (y = k)) : (f = Z(this, k, "", 0, 0, !1, !1), f = Ib(f, d, h, m)); - if (f) { - return f; - } - if (h && u === q - 1) { - f = d.length; - if (!f) { - if (y) { - y = ""; - u = -1; - continue; - } - return d; - } - if (1 === f) { - return g ? X(d[0], b, e) : new Y(d[0]); + for (c = a = void 0; x < q; x++) { + if ((c = p[x]) && !t[c]) { + t[c] = 1; + a = Ib(this, c, r, 0, 0, !1, !1); + if (a = Jb(a, d, h, m)) { + d = a; + break; } + r && (h && a && d.length || (r = c)); } + h && r && x === q - 1 && !d.length && (r = "", x = -1, t = J()); } - d = eb(d, m, b, e, h, l, g); - return g ? d : new Y(d); + return Kb(d, m, b, e, h, l, f); }; -function Hb(a, b, c, d, e, g, f) { - a = Z(this, a, b, c, d, e, g, f); - return this.db ? a.then(function(h) { - return e ? h : h && h.length ? e ? X(h, c, d) : new Y(h) : e ? [] : new Y([]); - }) : a && a.length ? e ? X(a, c, d) : new Y(a) : e ? [] : new Y([]); +function Kb(a, b, c, d, e, f, g) { + var h = a.length, k = a; + if (1 < h) { + k = db(a, b, c, d, e, f, g); + } else if (1 === h) { + return g ? gb.call(null, a[0], c, d) : new X(a[0]); + } + return g ? k : new X(k); } -function Ib(a, b, c, d) { +function Hb(a, b, c, d, e, f, g) { + a = Ib(this, a, b, c, d, e, f, g); + return this.db ? a.then(function(h) { + return e ? h || [] : new X(h); + }) : a && a.length ? e ? gb.call(this, a, c, d) : new X(a) : e ? [] : new X(); +} +function Jb(a, b, c, d) { var e = []; - if (a) { - d = Math.min(a.length, d); - for (var g = 0, f = void 0; g < d; g++) { - (f = a[g]) && f && (e[g] = f); + if (a && a.length) { + if (a.length <= d) { + b.push(a); + return; + } + for (var f = 0, g; f < d; f++) { + if (g = a[f]) { + e[f] = g; + } } if (e.length) { b.push(e); return; } } - return !c && e; -} -function Z(a, b, c, d, e, g, f, h) { - var k; - c && (k = a.bidirectional && b > c); - if (a.db) { - return c ? a.db.get(k ? c : b, k ? b : c, d, e, g, f, h) : a.db.get(b, "", d, e, g, f, h); + if (!c) { + return e; } - a = c ? (a = a.ctx.get(k ? b : c)) && a.get(k ? c : b) : a.map.get(b); +} +function Ib(a, b, c, d, e, f, g, h) { + 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, f, g, h); + } + a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;N.prototype.remove = function(a, b) { +;O.prototype.remove = function(a, b) { var c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { @@ -2967,27 +2863,27 @@ function Z(a, b, c, d, e, g, f, h) { if (2 > e.length) { e.pop(); } else { - var g = e.indexOf(a); - g === c.length - 1 ? e.pop() : e.splice(g, 1); + var f = e.indexOf(a); + f === c.length - 1 ? e.pop() : e.splice(f, 1); } } } } else { - Jb(this.map, a), this.depth && Jb(this.ctx, a); + Lb(this.map, a), this.depth && Lb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.da && Ab(this)); + this.db && (this.commit_task.push({del:a}), this.ca && Gb(this)); this.cache && this.cache.remove(a); return this; }; -function Jb(a, b) { +function Lb(a, b) { var c = 0; if (a.constructor === Array) { - for (var d = 0, e = void 0, g; d < a.length; d++) { + for (var d = 0, e = void 0, f; d < a.length; d++) { if ((e = a[d]) && e.length) { - if (g = e.indexOf(b), 0 <= g) { - 1 < e.length ? (e.splice(g, 1), c++) : delete a[d]; + if (f = e.indexOf(b), 0 <= f) { + 1 < e.length ? (e.splice(f, 1), c++) : delete a[d]; break; } else { c++; @@ -2995,25 +2891,25 @@ function Jb(a, b) { } } } else { - for (d = w(a), e = d.next(); !e.done; e = d.next()) { - g = e.value, e = g[0], (g = Jb(g[1], b)) ? c += g : a.delete(e); + for (d = w(a.entries()), e = d.next(); !e.done; e = d.next()) { + f = e.value, e = f[0], (f = Lb(f[1], b)) ? c += f : a.delete(e); } } return c; } -;function N(a, b) { - if (!this || this.constructor !== N) { - return new N(a); +;function O(a, b) { + if (!this || this.constructor !== O) { + return new O(a); } if (a) { - var c = L(a) ? a : a.preset; - c && (xb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, xb[c], a)); + var c = K(a) ? a : a.preset; + c && (Db[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Db[c], a)); } else { a = {}; } c = a.context; - var d = !0 === c ? {depth:1} : c || {}, e = L(a.encoder) ? wb[a.encoder] : a.encode || a.encoder || ob; - this.encoder = e.encode ? e : "object" === typeof e ? new Ga(e) : {encode:e}; + var d = !0 === c ? {depth:1} : c || {}, e = K(a.encoder) ? Cb[a.encoder] : a.encode || a.encoder || ub; + this.encoder = e.encode ? e : "object" === typeof e ? new Ia(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = c = a.tokenize || "strict"; this.depth = "strict" === c && d.depth || 0; @@ -3021,40 +2917,40 @@ function Jb(a, b) { 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 U(c) : new Set()); - this.aa = d.resolution || 3; + this.map = c ? new T(c) : new Map(); + this.ctx = c ? new T(c) : new Map(); + this.reg = b || (this.fastupdate ? c ? new T(c) : new Map() : c ? new U(c) : new Set()); + this.da = d.resolution || 3; this.rtl = e.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new W(c); + this.cache = (c = a.cache || null) && new Y(c); this.resolve = !1 !== a.resolve; if (c = a.db) { this.db = this.mount(c); } - this.da = !1 !== a.commit; + this.ca = !1 !== a.commit; this.commit_task = []; this.commit_timer = null; } -t = N.prototype; -t.mount = function(a) { +u = O.prototype; +u.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -t.commit = function(a, b) { +u.commit = function(a, b) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.commit(this, a, b); }; -t.destroy = function() { +u.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Ab(a) { +function Gb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); }, 0)); } -t.clear = function() { +u.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); @@ -3062,19 +2958,19 @@ t.clear = function() { this.db && (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [{clear:!0}]); return this; }; -t.append = function(a, b) { +u.append = function(a, b) { return this.add(a, b, !0); }; -t.contain = function(a) { +u.contain = function(a) { return this.db ? this.db.has(a) : this.reg.has(a); }; -t.update = function(a, b) { +u.update = function(a, b) { var c = this, d = this.remove(a); return d && d.then ? d.then(function() { return c.add(a, b); }) : this.add(a, b); }; -function Kb(a) { +function Mb(a) { var b = 0; if (a.constructor === Array) { for (var c = 0, d = void 0; c < a.length; c++) { @@ -3084,60 +2980,61 @@ function Kb(a) { for (c = w(a), d = c.next(); !d.done; d = c.next()) { var e = d.value; d = e[0]; - (e = Kb(e[1])) ? b += e : a.delete(d); + (e = Mb(e[1])) ? b += e : a.delete(d); } } return b; } -t.cleanup = function() { +u.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Kb(this.map); - this.depth && Kb(this.ctx); + Mb(this.map); + this.depth && Mb(this.ctx); return this; }; -t.searchCache = nb; -t.export = function(a, b, c, d) { +u.searchCache = tb; +u.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 = Ua(this.reg); + var f = Ta(this.reg); break; case 1: e = "cfg"; - g = {}; + f = {}; break; case 2: e = "map"; - g = Qa(this.map, this.reg.size); + f = Pa(this.map, this.reg.size); break; case 3: e = "ctx"; - g = Sa(this.ctx, this.reg.size); + f = Ra(this.ctx, this.reg.size); break; default: return; } - return Wa.call(this, a, b, e, g, c, d); + return Va.call(this, a, b, e, f, c, d); }; -t.import = function(a, b) { +u.import = function(a, b) { if (b) { - switch(L(b) && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { + switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = Va(b, this.reg); + this.reg = Ua(b, this.reg); break; case "map": - this.map = Ra(b, this.map); + this.map = Qa(b, this.map); break; case "ctx": - this.ctx = Ta(b, this.ctx); + this.ctx = Sa(b, this.ctx); } } }; -t.serialize = function(a) { +u.serialize = function(a) { a = void 0 === a ? !0 : a; if (!this.reg.size) { return ""; @@ -3148,26 +3045,26 @@ t.serialize = function(a) { b = "index.reg=new Set([" + b + "]);"; d = ""; e = w(this.map.entries()); - for (var g = e.next(); !g.done; g = e.next()) { - var f = g.value; - g = f[0]; - f = f[1]; - for (var h = "", k = 0, l; k < f.length; k++) { - l = f[k] || [""]; + for (var f = e.next(); !f.done; f = e.next()) { + var g = f.value; + f = g[0]; + g = g[1]; + for (var h = "", k = 0, l; k < g.length; k++) { + l = g[k] || [""]; for (var m = "", n = 0; n < l.length; n++) { m += (m ? "," : "") + ("string" === c ? '"' + l[n] + '"' : l[n]); } m = "[" + m + "]"; h += (h ? "," : "") + m; } - h = '["' + g + '",[' + h + "]]"; + h = '["' + f + '",[' + h + "]]"; d += (d ? "," : "") + h; } d = "index.map=new Map([" + d + "]);"; e = ""; - g = w(this.ctx.entries()); - for (f = g.next(); !f.done; f = g.next()) { - for (h = f.value, f = h[0], h = w(h[1].entries()), k = h.next(); !k.done; k = h.next()) { + f = w(this.ctx.entries()); + for (g = f.next(); !g.done; g = f.next()) { + for (h = g.value, g = h[0], h = w(h[1].entries()), k = h.next(); !k.done; k = h.next()) { l = k.value; k = l[0]; l = l[1]; @@ -3175,52 +3072,53 @@ t.serialize = function(a) { n = 0; for (var p; n < l.length; n++) { p = l[n] || [""]; - for (var q = "", r = 0; r < p.length; r++) { - q += (q ? "," : "") + ("string" === c ? '"' + p[r] + '"' : p[r]); + for (var q = "", t = 0; t < p.length; t++) { + q += (q ? "," : "") + ("string" === c ? '"' + p[t] + '"' : p[t]); } q = "[" + q + "]"; m += (m ? "," : "") + q; } m = 'new Map([["' + k + '",[' + m + "]]])"; - m = '["' + f + '",' + m + "]"; + m = '["' + g + '",' + m + "]"; e += (e ? "," : "") + m; } } e = "index.ctx=new Map([" + e + "]);"; return a ? "function inject(index){" + b + d + e + "}" : b + d + e; }; -Oa(N.prototype); -var Lb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Mb = ["map", "ctx", "tag", "reg", "cfg"]; -function Nb(a, b) { +Na(O.prototype); +var Nb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ob = ["map", "ctx", "tag", "reg", "cfg"]; +function Pb(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Nb(a, b); + return new Pb(a, b); } "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 = b.field ? b.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : ""; - this.support_tag_search = !1; + this.type = b.type; + this.fastupdate = this.support_tag_search = !1; this.db = null; this.h = {}; } -t = Nb.prototype; -t.mount = function(a) { +u = Pb.prototype; +u.mount = function(a) { if (!a.encoder) { return a.mount(this); } a.db = this; return this.open(); }; -t.open = function() { +u.open = function() { var a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - var d = Lb.open(a.id + (a.field ? ":" + a.field : ""), 1); + var d = Nb.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { var e = a.db = this.result; - Mb.forEach(function(g) { - e.objectStoreNames.contains(g) || e.createObjectStore(g); + Ob.forEach(function(f) { + e.objectStoreNames.contains(f) || e.createObjectStore(f); }); }; d.onblocked = function(e) { @@ -3240,27 +3138,28 @@ t.open = function() { }; }); }; -t.close = function() { +u.close = function() { this.db.close(); this.db = null; }; -t.destroy = function() { - return Lb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); +u.destroy = function() { + var a = Nb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Z(a); }; -t.clear = function() { - for (var a = this.db.transaction(Mb, "readwrite"), b = 0; b < Mb.length; b++) { - a.objectStore(Mb[b]).clear(); +u.clear = function() { + for (var a = this.db.transaction(Ob, "readwrite"), b = 0; b < Ob.length; b++) { + a.objectStore(Ob[b]).clear(); } - return Ob(a); + return Z(a); }; -t.get = function(a, b, c, d, e, g) { +u.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", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); - var f = this; - return Ob(a).then(function(h) { + var g = this; + return Z(a).then(function(h) { var k = []; if (!h || !h.length) { return k; @@ -3284,98 +3183,98 @@ t.get = function(a, b, c, d, e, g) { } } } - return g ? f.enrich(k) : k; + return f ? g.enrich(k) : k; } return h; }); }; -t.tag = function(a, b, c, d) { +u.tag = function(a, b, c, d) { b = void 0 === b ? 0 : b; c = void 0 === c ? 0 : c; d = void 0 === d ? !1 : d; a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); var e = this; - return Ob(a).then(function(g) { - if (!g || !g.length || c >= g.length) { + return Z(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; }); }; -t.enrich = function(a) { +u.enrich = function(a) { "object" !== typeof a && (a = [a]); for (var b = this.db.transaction("reg", "readonly").objectStore("reg"), c = [], d = 0; d < a.length; d++) { - c[d] = Ob(b.get(a[d])); + c[d] = Z(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; }); }; -t.has = function(a) { +u.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Ob(a); + return Z(a); }; -t.search = null; -t.info = function() { +u.search = null; +u.info = function() { }; -t.transaction = function(a, b, c) { +u.transaction = function(a, b, c) { var d = this, e = this.h[a + ":" + b]; if (e) { return c.call(this, e); } - var g = this.db.transaction(a, b); - this.h[a + ":" + b] = e = g.objectStore(a); - return new Promise(function(f, h) { - g.onerror = function(k) { + var f = this.db.transaction(a, b); + this.h[a + ":" + b] = e = f.objectStore(a); + return new Promise(function(g, h) { + f.onerror = function(k) { d.h[a + ":" + b] = null; - g.abort(); - g = e = null; + f.abort(); + f = e = null; h(k); }; - g.oncomplete = function(k) { - g = e = d.h[a + ":" + b] = null; - f(k || !0); + f.oncomplete = function(k) { + f = e = d.h[a + ":" + b] = null; + g(k || !0); }; return c.call(d, e); }); }; -t.commit = function(a, b, c) { - var d = this, e, g, f; - return sa(function(h) { +u.commit = function(a, b, c) { + var d = this, e, f, g; + return ta(function(h) { switch(h.h) { case 1: if (b) { - return G(h, d.clear(), 12); + return E(h, d.clear(), 12); } e = a.commit_task; a.commit_task = []; - g = 0; - f = void 0; + f = 0; + g = void 0; case 4: - if (!(g < e.length)) { + if (!(f < e.length)) { h.h = 6; break; } - f = e[g]; - if (!f.clear) { - e[g] = f.oa; + g = e[f]; + if (!g.clear) { + e[f] = g.ma; h.h = 5; break; } - return G(h, d.clear(), 8); + return E(h, d.clear(), 8); case 8: b = !0; h.h = 6; break; case 5: - g++; + f++; h.h = 4; break; case 6: @@ -3388,7 +3287,7 @@ t.commit = function(a, b, c) { h.h = 10; break; } - return G(h, d.remove(e), 11); + return E(h, d.remove(e), 11); case 11: case 10: h.h = 3; @@ -3396,59 +3295,59 @@ t.commit = function(a, b, c) { case 12: a.commit_task = []; case 3: - return a.reg.size ? G(h, d.transaction("map", "readwrite", function(k) { - for (var l = w(a.map), m = l.next(), n = {}; !m.done; n = {P:void 0, Y:void 0}, m = l.next()) { - m = m.value, n.Y = m[0], n.P = m[1], n.P.length && (b ? k.put(n.P, n.Y) : k.get(n.Y).onsuccess = function(p) { + return a.reg.size ? E(h, d.transaction("map", "readwrite", function(k) { + for (var l = w(a.map), m = l.next(), n = {}; !m.done; n = {O:void 0, Y:void 0}, m = l.next()) { + m = m.value, n.Y = m[0], n.O = m[1], n.O.length && (b ? k.put(n.O, n.Y) : k.get(n.Y).onsuccess = function(p) { return function() { - var q = this.result, r; + var q = this.result, t; if (q && q.length) { - for (var v = Math.max(q.length, p.P.length), z = 0, x; z < v; z++) { - if ((x = p.P[z]) && x.length) { - if ((r = q[z]) && r.length) { - for (var u = 0; u < x.length; u++) { - r.push(x[u]); + for (var x = Math.max(q.length, p.O.length), r = 0, A; r < x; r++) { + if ((A = p.O[r]) && A.length) { + if ((t = q[r]) && t.length) { + for (var z = 0; z < A.length; z++) { + t.push(A[z]); } } else { - q[z] = x; + q[r] = A; } - r = 1; + t = 1; } } } else { - q = p.P, r = 1; + q = p.O, t = 1; } - r && k.put(q, p.Y); + t && k.put(q, p.Y); }; }(n)); } }), 13) : h.return(); case 13: - return G(h, d.transaction("ctx", "readwrite", function(k) { - for (var l = w(a.ctx), m = l.next(), n = {}; !m.done; n = {W:void 0}, m = l.next()) { + return E(h, d.transaction("ctx", "readwrite", function(k) { + for (var l = w(a.ctx), m = l.next(), n = {}; !m.done; n = {V:void 0}, m = l.next()) { m = m.value; - n.W = m[0]; + n.V = m[0]; m = w(m[1]); - for (var p = m.next(), q = {}; !p.done; q = {R:void 0, Z:void 0}, p = m.next()) { - p = p.value, q.Z = p[0], q.R = p[1], q.R.length && (b ? k.put(q.R, n.W + ":" + q.Z) : k.get(n.W + ":" + q.Z).onsuccess = function(r, v) { + for (var p = m.next(), q = {}; !p.done; q = {P:void 0, Z:void 0}, p = m.next()) { + p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? k.put(q.P, n.V + ":" + q.Z) : k.get(n.V + ":" + q.Z).onsuccess = function(t, x) { return function() { - var z = this.result, x; - if (z && z.length) { - for (var u = Math.max(z.length, r.R.length), y = 0, E; y < u; y++) { - if ((E = r.R[y]) && E.length) { - if ((x = z[y]) && x.length) { - for (var A = 0; A < E.length; A++) { - x.push(E[A]); + var r = this.result, A; + if (r && r.length) { + for (var z = Math.max(r.length, t.P.length), v = 0, y; v < z; v++) { + if ((y = t.P[v]) && y.length) { + if ((A = r[v]) && A.length) { + for (var D = 0; D < y.length; D++) { + A.push(y[D]); } } else { - z[y] = E; + r[v] = y; } - x = 1; + A = 1; } } } else { - z = r.R, x = 1; + r = t.P, A = 1; } - x && k.put(z, v.W + ":" + r.Z); + A && k.put(r, x.V + ":" + t.Z); }; }(q, n)); } @@ -3456,7 +3355,7 @@ t.commit = function(a, b, c) { }), 14); case 14: if (a.store) { - return G(h, d.transaction("reg", "readwrite", function(k) { + return E(h, d.transaction("reg", "readwrite", function(k) { for (var l = w(a.store), m = l.next(); !m.done; m = l.next()) { var n = m.value; m = n[0]; @@ -3469,7 +3368,7 @@ t.commit = function(a, b, c) { h.h = 16; break; } - return G(h, d.transaction("reg", "readwrite", function(k) { + return E(h, d.transaction("reg", "readwrite", function(k) { for (var l = w(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { k.put(1, m.value); } @@ -3479,7 +3378,7 @@ t.commit = function(a, b, c) { h.h = 20; break; } - return G(h, d.transaction("tag", "readwrite", function(k) { + return E(h, d.transaction("tag", "readwrite", function(k) { for (var l = w(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) { m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (k.get(n.ba).onsuccess = function(p) { return function() { @@ -3495,11 +3394,11 @@ t.commit = function(a, b, c) { } }); }; -function Rb(a, b, c) { - for (var d = a.value, e, g, f = 0, h = 0, k; h < d.length; h++) { +function Sb(a, b, c) { + for (var d = a.value, e, f, g = 0, h = 0, k; h < d.length; h++) { if (k = c ? d : d[h]) { for (var l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = k.indexOf(g ? parseInt(n, 10) : n), 0 > m && !g && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (g = 1), 0 <= m) { + if (n = b[l], m = k.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { if (e = 1, 1 < k.length) { k.splice(m, 1); } else { @@ -3508,31 +3407,31 @@ function Rb(a, b, c) { } } } - f += k.length; + g += k.length; } if (c) { break; } } - f ? e && a.update(d) : a.delete(); + g ? e && a.update(d) : a.delete(); a.continue(); } -t.remove = function(a) { +u.remove = function(a) { "object" !== typeof a && (a = [a]); return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Rb(c, a); + c && Sb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Rb(c, a); + c && Sb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Rb(c, a, !0); + c && Sb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3540,7 +3439,7 @@ t.remove = function(a) { } })]); }; -function Ob(a) { +function Z(a) { return new Promise(function(b, c) { a.onsuccess = function() { b(this.result); @@ -3552,8 +3451,8 @@ function Ob(a) { a = null; }); } -;var Sb = {Index:N, Charset:wb, Encoder:Ga, Document:V, Worker:Q, Resolver:Y, IndexedDB:Nb, Language:{}}, Tb = self, Ub; -(Ub = Tb.define) && Ub.amd ? Ub([], function() { - return Sb; -}) : "object" === typeof Tb.exports ? Tb.exports = Sb : Tb.FlexSearch = Sb; +;var Tb = {Index:O, Charset:Cb, Encoder:Ia, Document:V, Worker:R, Resolver:X, IndexedDB:Pb, Language:{}}, Ub = self, Vb; +(Vb = Ub.define) && Vb.amd ? Vb([], function() { + return Tb; +}) : "object" === typeof Ub.exports ? Ub.exports = Tb : Ub.FlexSearch = Tb; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 4942dba..46f644b 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,139 +1,134 @@ /**! - * FlexSearch.js v0.8.103 (ES5) + * FlexSearch.js v0.8.105 (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 t;function aa(a){var b=0;return function(){return b>>0)+"_",e=0;return b}); -F("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>>0)+"_",e=0;return b}); +C("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));ca.length)return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.D=null;this.cache&&Ia(this);return this};t.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.G=null;this.cache&&Ia(this);return this}; -t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&Ia(this);return this};t.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1this.L&&(this.O.clear(),this.C=this.C/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.B&&(this.N.set(a,d),this.N.size>this.L&&(this.N.clear(),this.B=this.B/1.1|0));return d};function Ja(a){a.U=null;a.N.clear();a.O.clear()};function Ka(a){var b,c,d,e,h,f,g;return sa(function(k){a=a.data;b=self._index;c=a.args;d=a.task;switch(d){case "init":e=a.options||{};(h=a.factory)?(Function("return "+h)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new N(e);postMessage({id:a.id});break;default:f=a.id,g=b[d].apply(b,c),postMessage("search"===d?{id:f,msg:g}:{id:f})}k.h=0})};var La=0; -function Q(a){function b(f){function g(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=K();if(this.worker){d?this.worker.on("message",g):this.worker.onmessage=g;if(a.config)return new Promise(function(k){e.h[++La]=function(){k(e)};e.worker.postMessage({id:La,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(!this||this.constructor!==Q)return new Q(a);var c="undefined"!==typeof self?self._factory: -"undefined"!==typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,h=Ma(c,d,a.worker);return h.then?h.then(function(f){return b.call(e,f)}):b.call(this,h)}Na("add");Na("append");Na("search");Na("update");Na("remove"); -function Na(a){Q.prototype[a]=Q.prototype[a+"Async"]=function(){var b=this,c=arguments,d,e,h,f,g;return sa(function(k){d=b;e=[].slice.call(c);h=e[e.length-1];"function"===typeof h&&(f=h,e.splice(e.length-1,1));g=new Promise(function(l){d.h[++La]=l;d.worker.postMessage({task:a,id:La,args:e})});return f?(g.then(f),k.return(b)):k.return(g)})}} -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="+Ka.toString()],{type:"text/javascript"}))):new window.Worker(L(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"})};function Oa(a){Pa.call(a,"add");Pa.call(a,"append");Pa.call(a,"search");Pa.call(a,"update");Pa.call(a,"remove")}function Pa(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function Qa(a,b){b=void 0===b?0:b;var c=[],d=[];b&&(b=25E4/b*5E3|0);a=w(a.entries());for(var e=a.next();!e.done;e=a.next())d.push(e.value),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function Ra(a,b){b||(b=new Map);for(var c=0,d;c=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 R(a){if(!this)return new R(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 h=0,f=0,g,k;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(f=0;fd)d-=g.length; -else{if(g.length>c||d)g=g.slice(d,c+d),c-=g.length,d&&(d-=g.length);e.push(g);if(!c)break}k=1c||d)a=a.slice(d,d+c);e&&(a=ib.call(this,a));return a}} -function ib(a){for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -W.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};W.prototype.remove=function(a){for(var b=w(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)}};W.prototype.clear=function(){this.cache.clear();this.h=""};var ob={normalize:function(a){return a.toLowerCase()},dedupe:!1};var pb=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 qb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),rb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];var sb={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 tb=/[\x00-\x7F]+/g;var ub=/[\x00-\x7F]+/g;var vb=/[\x00-\x7F]+/g;var wb={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ob,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:pb},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:pb,matcher:qb,replacer:rb},LatinExtra:{normalize:!0,dedupe:!0,mapper:pb,replacer:rb.concat([/(?!^)[aeo]/g,""]),matcher:qb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bp;q--){n=l.substring(p,q);var r=this.score?this.score(b,l,k,n,p):yb(g,d,k,m,p);zb(this,h,n,r,a,c)}break}case "reverse":if(1< -m){for(q=m-1;0n?0:1),d,k,q-1,r-1),z=this.bidirectional&&l>p;zb(this,e,z?p:l,v,a,c,z?l:p)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.da&&Ab(this));return this}; -function zb(a,b,c,d,e,h,f){var g=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=K()),b[f]=1,(k=g.get(f))?g=k:g.set(f,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!h||!g.includes(e)){if(g.length===Math.pow(2,31)-1){b=new R(g);if(a.fastupdate)for(c=w(a.reg.values()),h=c.next();!h.done;h=c.next())h=h.value,h.includes(g)&&(h[h.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 yb(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Bb(a):a;for(var e=[],h=0,f=void 0,g=void 0;h=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length);else if(g>=b)return g>b&&(f=f.slice(0,b)),d?Bb(f):f;e.push(f);b-=g;if(!b)break}if(!e.length)return e;e=1a.length?e?X(a[0],b,c,d):a[0]:fb(a,c,b,e,h)};Y.prototype.and=function(){if(this.result.length){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.and.apply(a,b)});if(c[0]&&c[0].index)return this.and.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return[];var f=[];K();var g=za(a);return g?eb(a,g,b,c,h,e,d):f};Y.prototype.xor=function(){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return e?X(a[0],b,c,d):a[0];d=[];for(var f=K(),g=0,k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,h,f,g):a.db.get(b,"",d,e,h,f,g);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};N.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var h=e.indexOf(a);h===c.length-1?e.pop():e.splice(h,1)}}else Jb(this.map,a),this.depth&&Jb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.da&&Ab(this));this.cache&&this.cache.remove(a);return this}; -function Jb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,h;d=m.length)d-=m.length;else{for(var p=c?d+Math.min(m.length-d,c):m.length,n=d;n=h.length)return[];if(!b&&!c)return h;h=h.slice(c,c+b);return d?e.enrich(h):h})}; -t.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;dm&&!h&&"string"===typeof p&&!isNaN(p)&&(m=k.indexOf(parseInt(p,10)))&&(h=1),0<=m)if(e=1,1"a1a".split(c).length; +this.numeric=H(a.numeric,e)}else{try{this.split=H(this.split,Ba)}catch(g){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);Ha||(this.mapper=new Map(Aa));this.rtl=H(a.rtl,!1,this.rtl);this.dedupe=H(a.dedupe,!1,this.dedupe);this.filter=H((c=a.filter)&&new Set(c),null,this.filter);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,0,this.maxlength);if(this.cache=c=H(a.cache,!0,this.cache))this.D=null,this.T="number"===typeof c?c:2E5,this.B=new Map,this.C=new Map,this.H=this.G=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(a=w(this.matcher.keys()),b=a.next();!b.done;b=a.next())this.h+=(this.h?"|":"")+b.value;if(this.stemmer)for(a=w(this.stemmer.keys()), +b=a.next();!b.done;b=a.next())this.A+=(this.A?"|":"")+b.value;return this};u.addStemmer=function(a,b){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,b);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&N(this);return this};u.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&N(this);return this}; +u.addMapper=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&N(this);return this}; +u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&N(this);return this}; +u.encode=function(a){var b=this;if(this.cache&&a.length<=this.G)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(N,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=Ha?a.normalize("NFKD").replace(Ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};function Ja(a){var b,c,d,e,g,f,h;return ta(function(k){a=a.data;b=self._index;c=a.args;d=a.task;switch(d){case "init":e=a.options||{};(g=a.factory)?(Function("return "+g)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new O(e);postMessage({id:a.id});break;default:f=a.id,h=b[d].apply(b,c),postMessage("search"===d?{id:f,msg:h}:{id:f})}k.h=0})};var Ka=0; +function R(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=I();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Ka]=function(){k(e)};e.worker.postMessage({id:Ka,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(!this||this.constructor!==R)return new R(a);var c="undefined"!==typeof self?self._factory: +"undefined"!==typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,g=La(c,d,a.worker);return g.then?g.then(function(f){return b.call(e,f)}):b.call(this,g)}Ma("add");Ma("append");Ma("search");Ma("update");Ma("remove"); +function Ma(a){R.prototype[a]=R.prototype[a+"Async"]=function(){var b=this,c=arguments,d,e,g,f,h;return ta(function(k){d=b;e=[].slice.call(c);g=e[e.length-1];"function"===typeof g&&(f=g,e.splice(e.length-1,1));h=new Promise(function(l){d.h[++Ka]=l;d.worker.postMessage({task:a,id:Ka,args:e})});return f?(h.then(f),k.return(b)):k.return(h)})}} +function La(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="+Ja.toString()],{type:"text/javascript"}))):new window.Worker(K(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"})};function Na(a){Oa.call(a,"add");Oa.call(a,"append");Oa.call(a,"search");Oa.call(a,"update");Oa.call(a,"remove")}function Oa(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function Pa(a,b){b=void 0===b?0:b;var c=[],d=[];b&&(b=25E4/b*5E3|0);a=w(a.entries());for(var e=a.next();!e.done;e=a.next())d.push(e.value),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function Qa(a,b){b||(b=new Map);for(var c=0,d;c=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} +function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(g=0;gd)d-=f.length; +else{if(f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?W.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}cb&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?W.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=eb(a,c,d,!1,this.h),d=0));return g?this.resolve(c,d,e):this};X.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var g=b.enrich&&c}}return a?(a=hb(this,"and",arguments),jb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; +function jb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=db(a,b,c,d,f,this.h,g),g?e?W.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};X.prototype.xor=function(){var a=hb(this,"xor",arguments);return kb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; +function kb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=lb.call(this,a,c,d,g,this.h),g?e?W.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} +function lb(a,b,c,d,e){for(var g=[],f=I(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=W.call(this,a));return a}} +function W(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(var b=w(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};var ub={normalize:function(a){return a.toLowerCase()},numeric:!1,dedupe:!1};var vb=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 wb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),xb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];var yb={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 zb=/[\x00-\x7F]+/g;var Ab=/[\x00-\x7F]+/g;var Bb=/[\x00-\x7F]+/g;var Cb={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ub,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:vb},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:vb,matcher:wb,replacer:xb},LatinExtra:{normalize:!0,dedupe:!0,mapper:vb,replacer:xb.concat([/(?!^)[aeo]/g,""]),matcher:wb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):Eb(h,d,k,m,n);Fb(this,g,p,r,a,c)}break}case "reverse":if(1< +m){for(q=m-1;0p?0:1),d,k,q-1,r-1),t=this.bidirectional&&l>n;Fb(this,e,t?n:l,x,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.ca&&Gb(this));return this}; +function Fb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=I()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new S(h);if(a.fastupdate)for(c=w(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 Eb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Lb(this.map,a),this.depth&&Lb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Gb(this));this.cache&&this.cache.remove(a);return this}; +function Lb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;d=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; +u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;dm&&!g&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(g=1),0<=m)if(e=1,1 "a1a".split(b).length; } - try { - this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); - } catch (g) { - this.split = /\s+/; - } - this.numeric = e; + this.numeric = u(a.numeric, e); } else { try { - this.split = u(b, y, this.split); - } catch (e) { - this.split = /\s+/; + this.split = u(this.split, aa); + } catch (d) { + console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = u(this.numeric, !0); + this.numeric = u(a.numeric, u(this.numeric, !0)); } this.prepare = u(a.prepare, null, this.prepare); this.finalize = u(a.finalize, null, this.finalize); - this.rtl = a.rtl || !1; + this.rtl = u(a.rtl, !1, this.rtl); this.dedupe = u(a.dedupe, !1, this.dedupe); this.filter = u((b = a.filter) && new Set(b), null, this.filter); this.matcher = u((b = a.matcher) && new Map(b), null, this.matcher); @@ -100,50 +109,36 @@ t.assign = function(a) { this.minlength = u(a.minlength, 1, this.minlength); this.maxlength = u(a.maxlength, 0, this.maxlength); if (this.cache = b = u(a.cache, !0, this.cache)) { - this.l = null, this.v = "number" === typeof b ? b : 2e5, this.h = new Map(), this.j = new Map(), this.o = this.m = 128; + this.l = null, this.C = "number" === typeof b ? b : 2e5, this.i = new Map(), this.j = new Map(), this.s = this.o = 128; } this.g = ""; - this.s = null; - this.i = ""; - this.u = null; + this.v = null; + this.h = ""; + this.A = null; if (this.matcher) { - for (const e of this.matcher.keys()) { - this.g += (this.g ? "|" : "") + e; + for (const d of this.matcher.keys()) { + this.g += (this.g ? "|" : "") + d; } } if (this.stemmer) { - for (const e of this.stemmer.keys()) { - this.i += (this.i ? "|" : "") + e; + for (const d of this.stemmer.keys()) { + this.h += (this.h ? "|" : "") + d; } } return this; }; -t.addMatcher = function(a, c) { - if ("object" === typeof a) { - return this.addReplacer(a, c); - } - if (2 > a.length) { - return this.addMapper(a, c); - } - this.matcher || (this.matcher = new Map()); - this.matcher.set(a, c); - this.g += (this.g ? "|" : "") + a; - this.s = null; - this.cache && F(this); - return this; -}; t.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); - this.i += (this.i ? "|" : "") + a; - this.u = null; - this.cache && F(this); + this.h += (this.h ? "|" : "") + a; + this.A = null; + this.cache && B(this); return this; }; t.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); - this.cache && F(this); + this.cache && B(this); return this; }; t.addMapper = function(a, c) { @@ -155,138 +150,503 @@ t.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && F(this); + this.cache && B(this); + return this; +}; +t.addMatcher = function(a, c) { + if ("object" === typeof a) { + return this.addReplacer(a, c); + } + if (2 > a.length && (this.dedupe || this.mapper)) { + return this.addMapper(a, c); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(a, c); + this.g += (this.g ? "|" : "") + a; + this.v = null; + this.cache && B(this); return this; }; t.addReplacer = function(a, c) { - "string" === typeof a && (a = new RegExp(a, "g")); + if ("string" === typeof a) { + return this.addMatcher(a, c); + } this.replacer || (this.replacer = []); - this.replacer.push(a, c || ""); - this.cache && F(this); + this.replacer.push(a, c); + this.cache && B(this); return this; }; -function F(a) { - a.h.clear(); - a.j.clear(); -} t.encode = function(a) { - if (this.cache && a.length <= this.m) { + if (this.cache && a.length <= this.o) { if (this.l) { - if (this.h.has(a)) { - return this.h.get(a); + if (this.i.has(a)) { + return this.i.get(a); } } else { - this.l = setTimeout(G, 50, this); + this.l = setTimeout(B, 50, this); } } - this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : D ? a.normalize("NFKD").replace(D, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = y ? a.normalize("NFKD").replace(y, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(A, "$1 $2").replace(B, "$1 $2").replace(z, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(ca, "$1 $2").replace(da, "$1 $2").replace(ba, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; for (let g = 0, f, h; g < e.length; g++) { - if (!(f = h = e[g])) { - continue; - } - if (f.length < this.minlength) { - continue; - } - if (c) { - b.push(f); - continue; - } - if (this.filter && this.filter.has(f)) { - continue; - } - if (this.cache && f.length <= this.o) { - if (this.l) { - var d = this.j.get(f); - if (d || "" === d) { - d && b.push(d); - continue; - } + if ((f = h = e[g]) && !(f.length < this.minlength)) { + if (c) { + b.push(f); } else { - this.l = setTimeout(G, 50, this); + if (!this.filter || !this.filter.has(f)) { + if (this.cache && f.length <= this.s) { + if (this.l) { + var d = this.j.get(f); + if (d || "" === d) { + d && b.push(d); + continue; + } + } else { + this.l = setTimeout(B, 50, this); + } + } + this.stemmer && 2 < f.length && (this.A || (this.A = new RegExp("(?!^)(" + this.h + ")$")), f = f.replace(this.A, k => this.stemmer.get(k)), f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); + if (f && (this.mapper || this.dedupe && 1 < f.length)) { + d = ""; + for (let k = 0, l = "", n, m; k < f.length; k++) { + n = f.charAt(k), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (d += m) : d += l = n); + } + f = d; + } + this.matcher && 1 < f.length && (this.v || (this.v = new RegExp("(" + this.g + ")", "g")), f = f.replace(this.v, k => this.matcher.get(k))); + if (f && this.replacer) { + for (d = 0; f && d < this.replacer.length; d += 2) { + f = f.replace(this.replacer[d], this.replacer[d + 1]); + } + } + this.cache && h.length <= this.s && (this.j.set(h, f), this.j.size > this.C && (this.j.clear(), this.s = this.s / 1.1 | 0)); + f && b.push(f); + } } } - let k; - this.stemmer && 2 < f.length && (this.u || (this.u = new RegExp("(?!^)(" + this.i + ")$")), f = f.replace(this.u, r => this.stemmer.get(r)), k = 1); - f && k && (f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); - if (f && (this.mapper || this.dedupe && 1 < f.length)) { - d = ""; - for (let r = 0, q = "", p, n; r < f.length; r++) { - p = f.charAt(r), p === q && this.dedupe || ((n = this.mapper && this.mapper.get(p)) || "" === n ? n === q && this.dedupe || !(q = n) || (d += n) : d += q = p); - } - f = d; - } - this.matcher && 1 < f.length && (this.s || (this.s = new RegExp("(" + this.g + ")", "g")), f = f.replace(this.s, r => this.matcher.get(r))); - if (f && this.replacer) { - for (d = 0; f && d < this.replacer.length; d += 2) { - f = f.replace(this.replacer[d], this.replacer[d + 1]); - } - } - this.cache && h.length <= this.o && (this.j.set(h, f), this.j.size > this.v && (this.j.clear(), this.o = this.o / 1.1 | 0)); - f && b.push(f); } this.finalize && (b = this.finalize(b) || b); - this.cache && a.length <= this.m && (this.h.set(a, b), this.h.size > this.v && (this.h.clear(), this.m = this.m / 1.1 | 0)); + this.cache && a.length <= this.o && (this.i.set(a, b), this.i.size > this.C && (this.i.clear(), this.o = this.o / 1.1 | 0)); return b; }; -function G(a) { +function B(a) { a.l = null; - a.h.clear(); + a.i.clear(); a.j.clear(); } -;function H(a) { +;function C(a, c, b, e, d) { + const g = a.length; + let f = [], h, k; + h = w(); + for (let l = 0, n, m, r, q; l < c; l++) { + for (let p = 0; p < g; p++) { + if (r = a[p], l < r.length && (n = r[l])) { + for (let v = 0; v < n.length; v++) { + m = n[v], (k = h[m]) ? h[m]++ : (k = 0, h[m] = 1), q = f[k] || (f[k] = []), q.push(m); + } + } + } + } + if (a = f.length) { + if (d) { + f = 1 < f.length ? D(f, b, e) : (f = f[0]).length > b || e ? f.slice(e, b + e) : f; + } else { + if (a < g) { + return []; + } + f = f[a - 1]; + if (b || e) { + if (f.length > b || e) { + f = f.slice(e, b + e); + } + } + } + } + return f; +} +function D(a, c, b) { + const e = [], d = w(); + let g; + var f = a.length; + let h; + for (let k = f - 1; 0 <= k; k--) { + if (h = (f = a[k]) && f.length) { + for (let l = 0; l < h; l++) { + if (g = f[l], !d[g]) { + if (d[g] = 1, b) { + b--; + } else { + if (e.push(g), e.length === c) { + return e; + } + } + } + } + } + } + return e; +} +;function E(a, c, b, e) { + if (!a.length) { + return a; + } + if (1 === a.length) { + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? F.call(this, a) : a; + } + let d = []; + for (let g = 0, f, h; g < a.length; g++) { + if ((f = a[g]) && (h = f.length)) { + if (b) { + if (b >= h) { + b -= h; + continue; + } + b < h && (f = c ? f.slice(b, b + c) : f.slice(b), h = f.length, b = 0); + } + h > c && (f = f.slice(0, c), h = c); + if (!d.length && h >= c) { + return e ? F.call(this, f) : f; + } + d.push(f); + c -= h; + if (!c) { + break; + } + } + } + d = 1 < d.length ? [].concat.apply([], d) : d[0]; + return e ? F.call(this, d) : d; +} +;function G(a, c, b) { + var e = b[0]; + if (e.then) { + return Promise.all(b).then(function(n) { + return a[c].apply(a, n); + }); + } + if (e[0] && e[0].index) { + return a[c].apply(a, e); + } + e = []; + let d = [], g = 0, f = 0, h, k, l; + for (let n = 0, m; n < b.length; n++) { + if (m = b[n]) { + let r; + if (m.constructor === I) { + r = m.result; + } else if (m.constructor === Array) { + r = m; + } else { + if (g = m.limit || 0, f = m.offset || 0, l = m.suggest, k = m.resolve, h = m.enrich && k, m.index) { + m.resolve = !1, m.enrich = !1, r = m.index.search(m).result, m.resolve = k, m.enrich = h; + } else if (m.and) { + r = a.and(m.and); + } else if (m.or) { + r = a.or(m.or); + } else if (m.xor) { + r = a.xor(m.xor); + } else if (m.not) { + r = a.not(m.not); + } else { + continue; + } + } + if (r.then) { + d.push(r); + } else if (r.length) { + e[n] = r; + } else if (!l && ("and" === c || "xor" === c)) { + e = []; + break; + } + } + } + return {m:e, u:d, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; +} +;I.prototype.or = function() { + const {m:a, u:c, limit:b, offset:e, enrich:d, resolve:g} = G(this, "or", arguments); + return J.call(this, a, c, b, e, d, g); +}; +function J(a, c, b, e, d, g) { + if (c.length) { + const f = this; + return Promise.all(c).then(function(h) { + a = []; + for (let k = 0, l; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); + } + return J.call(f, a, [], b, e, d, g); + }); + } + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = D(a, b, e), e = 0)); + return g ? this.resolve(b, e, d) : this; +} +;I.prototype.and = function() { + let a = this.result.length, c, b, e, d; + if (!a) { + const g = arguments[0]; + g && (a = !!g.suggest, d = g.resolve, c = g.limit, b = g.offset, e = g.enrich && d); + } + if (a) { + const {m:g, u:f, limit:h, offset:k, enrich:l, resolve:n, suggest:m} = G(this, "and", arguments); + return K.call(this, g, f, h, k, l, n, m); + } + return d ? this.resolve(c, b, e) : this; +}; +function K(a, c, b, e, d, g, f) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, n; l < k.length; l++) { + (n = k[l]).length && (a[l] = n); + } + return K.call(h, a, [], b, e, d, g, f); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + if (c = x(a)) { + return this.result = C(a, c, b, e, f), g ? d ? F.call(this.index, this.result) : this.result : this; + } + this.result = []; + } + } else { + f || (this.result = a); + } + return g ? this.resolve(b, e, d) : this; +} +;I.prototype.xor = function() { + const {m:a, u:c, limit:b, offset:e, enrich:d, resolve:g, suggest:f} = G(this, "xor", arguments); + return L.call(this, a, c, b, e, d, g, f); +}; +function L(a, c, b, e, d, g, f) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, n; l < k.length; l++) { + (n = k[l]).length && (a[l] = n); + } + return L.call(h, a, [], b, e, d, g, f); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = ea.call(this, a, b, e, g, this.g), g ? d ? F.call(this.index, this.result) : this.result : this; + } + } else { + f || (this.result = a); + } + return g ? this.resolve(b, e, d) : this; +} +function ea(a, c, b, e, d) { + const g = [], f = w(); + let h = 0; + for (let k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); + for (let n = 0, m; n < l.length; n++) { + if (m = l[n]) { + for (let r = 0, q; r < m.length; r++) { + q = m[r], f[q] = f[q] ? 2 : 1; + } + } + } + } + } + for (let k = 0, l, n = 0; k < h; k++) { + for (let m = 0, r; m < a.length; m++) { + if (r = a[m]) { + if (l = r[k]) { + for (let q = 0, p; q < l.length; q++) { + if (p = l[q], 1 === f[p]) { + if (b) { + b--; + } else { + if (e) { + if (g.push(p), g.length === c) { + return g; + } + } else { + const v = k + (m ? d : 0); + g[v] || (g[v] = []); + g[v].push(p); + if (++n === c) { + return g; + } + } + } + } + } + } + } + } + } + return g; +} +;I.prototype.not = function() { + const {m:a, u:c, limit:b, offset:e, enrich:d, resolve:g, suggest:f} = G(this, "not", arguments); + return M.call(this, a, c, b, e, d, g, f); +}; +function M(a, c, b, e, d, g, f) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, n; l < k.length; l++) { + (n = k[l]).length && (a[l] = n); + } + return M.call(h, a, [], b, e, d, g, f); + }); + } + if (a.length && this.result.length) { + this.result = fa.call(this, a, b, e, g); + } else if (g) { + return this.resolve(b, e, d); + } + return g ? d ? F.call(this.index, this.result) : this.result : this; +} +function fa(a, c, b, e) { + const d = []; + a = new Set(a.flat().flat()); + for (let g = 0, f, h = 0; g < this.result.length; g++) { + if (f = this.result[g]) { + for (let k = 0, l; k < f.length; k++) { + if (l = f[k], !a.has(l)) { + if (b) { + b--; + } else { + if (e) { + if (d.push(l), d.length === c) { + return d; + } + } else { + if (d[g] || (d[g] = []), d[g].push(l), ++h === c) { + return d; + } + } + } + } + } + } + } + return d; +} +;function I(a) { + if (!this || this.constructor !== I) { + return new I(a); + } + if (a && a.index) { + return a.resolve = !1, this.index = a.index, this.g = a.boost || 0, this.result = a.index.search(a).result, this; + } + this.index = null; + this.result = a || []; + this.g = 0; +} +I.prototype.limit = function(a) { + if (this.result.length) { + const c = []; + let b = 0; + for (let e = 0, d; e < this.result.length; e++) { + if (d = this.result[e], d.length + b < a) { + c[e] = d, b += d.length; + } else { + c[e] = d.slice(0, a - b); + this.result = c; + break; + } + } + } + return this; +}; +I.prototype.offset = function(a) { + if (this.result.length) { + const c = []; + let b = 0; + for (let e = 0, d; e < this.result.length; e++) { + d = this.result[e], d.length + b < a ? b += d.length : (c[e] = d.slice(a - b), b = a); + } + this.result = c; + } + return this; +}; +I.prototype.boost = function(a) { + this.g += a; + return this; +}; +I.prototype.resolve = function(a, c, b) { + const e = this.result, d = this.index; + this.result = this.index = null; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), E.call(d, e, a || 100, c, b)) : e; +}; +w(); +function F(a) { + if (!this || !this.store) { + return a; + } + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; + } + return c; +} +;function N(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.g = ""; } -H.prototype.set = function(a, c) { +N.prototype.set = function(a, c) { this.cache.set(this.g = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -H.prototype.get = function(a) { +N.prototype.get = function(a) { const c = this.cache.get(a); c && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c)); return c; }; -H.prototype.remove = function(a) { +N.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -H.prototype.clear = function() { +N.prototype.clear = function() { this.cache.clear(); this.g = ""; }; -const I = {normalize:function(a) { +const ha = {normalize:function(a) { return a.toLowerCase(); -}, dedupe:!1}; -const J = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -w(); -K.prototype.add = function(a, c, b, e) { +}, numeric:!1, dedupe:!1}; +const O = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +P.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); if (e = c.length) { - const r = w(), q = w(), p = this.depth, n = this.resolution; - for (let m = 0; m < e; m++) { - let l = c[this.rtl ? e - 1 - m : m]; - var d = l.length; - if (d && (p || !q[l])) { - var g = this.score ? this.score(c, l, m, null, 0) : L(n, e, m), f = ""; + const l = w(), n = w(), m = this.depth, r = this.resolution; + for (let q = 0; q < e; q++) { + let p = c[this.rtl ? e - 1 - q : q]; + var d = p.length; + if (d && (m || !n[p])) { + var g = this.score ? this.score(c, p, q, null, 0) : Q(r, e, q), f = ""; switch(this.tokenize) { case "full": if (2 < d) { for (g = 0; g < d; g++) { for (var h = d; h > g; h--) { - f = l.substring(g, h); - var k = this.score ? this.score(c, l, m, f, g) : L(n, e, m, d, g); - M(this, q, f, k, a, b); + f = p.substring(g, h); + var k = this.score ? this.score(c, p, q, f, g) : Q(r, e, q, d, g); + R(this, n, f, k, a, b); } } break; @@ -294,24 +654,24 @@ K.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - f = l[h] + f, k = this.score ? this.score(c, l, m, f, h) : L(n, e, m, d, h), M(this, q, f, k, a, b); + f = p[h] + f, k = this.score ? this.score(c, p, q, f, h) : Q(r, e, q, d, h), R(this, n, f, k, a, b); } f = ""; } case "forward": if (1 < d) { for (h = 0; h < d; h++) { - f += l[h], M(this, q, f, g, a, b); + f += p[h], R(this, n, f, g, a, b); } break; } default: - if (M(this, q, l, g, a, b), p && 1 < e && m < e - 1) { - for (d = w(), f = this.A, g = l, h = Math.min(p + 1, e - m), d[g] = 1, k = 1; k < h; k++) { - if ((l = c[this.rtl ? e - 1 - m - k : m + k]) && !d[l]) { - d[l] = 1; - const v = this.score ? this.score(c, g, m, l, k) : L(f + (e / 2 > f ? 0 : 1), e, m, h - 1, k - 1), C = this.bidirectional && l > g; - M(this, r, C ? g : l, v, a, b, C ? l : g); + if (R(this, n, p, g, a, b), m && 1 < e && q < e - 1) { + for (d = w(), f = this.B, g = p, h = Math.min(m + 1, e - q), d[g] = 1, k = 1; k < h; k++) { + if ((p = c[this.rtl ? e - 1 - q - k : q + k]) && !d[p]) { + d[p] = 1; + const v = this.score ? this.score(c, g, q, p, k) : Q(f + (e / 2 > f ? 0 : 1), e, q, h - 1, k - 1), A = this.bidirectional && p > g; + R(this, l, A ? g : p, v, a, b, A ? p : g); } } } @@ -323,46 +683,16 @@ K.prototype.add = function(a, c, b, e) { } return this; }; -function M(a, c, b, e, d, g, f) { +function R(a, c, b, e, d, g, f) { let h = f ? a.ctx : a.map, k; if (!c[b] || f && !(k = c[b])[f]) { f ? (c = k || (c[b] = w()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), g && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function L(a, c, b, e, d) { +function Q(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 N(a, c, b) { - if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; - } - let e = []; - for (let d = 0, g, f; d < a.length; d++) { - if ((g = a[d]) && (f = g.length)) { - if (b) { - if (b >= f) { - b -= f; - continue; - } - b < f && (g = c ? g.slice(b, b + c) : g.slice(b), f = g.length, b = 0); - } - if (e.length) { - f > c && (g = g.slice(0, c), f = g.length); - } else { - if (f >= c) { - return f > c && (g = g.slice(0, c)), g; - } - } - e.push(g); - c -= f; - if (!c) { - break; - } - } - } - return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; -} -;K.prototype.search = function(a, c, b) { +;P.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); var e = [], d = 0; if (b) { @@ -378,150 +708,81 @@ function L(a, c, b, e, d) { } b = this.encoder.encode(a); a = b.length; - c || !h || (c = 100); + c = c || (h ? 100 : 0); if (1 === a) { - return O.call(this, b[0], "", c, d); + return S.call(this, b[0], "", c, d, h); } g = this.depth && !1 !== g; if (2 === a && g && !f) { - return O.call(this, b[0], b[1], c, d); + return S.call(this, b[0], b[1], c, d, h); } - var r = h = 0; - if (1 < a) { - var q = w(); - const n = []; - for (let m = 0, l; m < a; m++) { - if ((l = b[m]) && !q[l]) { - if (f || P(this, l)) { - n.push(l), q[l] = 1; - } else { - return e; - } - const v = l.length; - h = Math.max(h, v); - r = r ? Math.min(r, v) : v; - } - } - b = n; - a = b.length; + h = w(); + let l = 0; + if (1 < a && g) { + var n = b[0]; + l = 1; } - if (!a) { - return e; - } - q = 0; - if (1 === a) { - return O.call(this, b[0], "", c, d); - } - if (2 === a && g && !f) { - return O.call(this, b[0], b[1], c, d); - } - if (1 < a) { - if (g) { - var p = b[0]; - q = 1; - } else { - 9 < h && 3 < h / r && b.sort(x); - } - } - k || 0 === k || (k = this.resolution); - for (let n, m; q < a; q++) { - m = b[q]; - p ? (n = P(this, m, p), n = Q(n, e, f, this.A), f && !1 === n && e.length || (p = m)) : (n = P(this, m, ""), n = Q(n, e, f, k)); - if (n) { - return n; - } - if (f && q === a - 1) { - g = e.length; - if (!g) { - if (p) { - p = ""; - q = -1; - continue; - } - return e; - } - if (1 === g) { - return N(e[0], c, d); - } - } - } - a: { - p = f; - g = e.length; - f = []; - a = w(); - for (let n = 0, m, l, v, C; n < k; n++) { - for (h = 0; h < g; h++) { - if (v = e[h], n < v.length && (m = v[n])) { - for (r = 0; r < m.length; r++) { - l = m[r], (b = a[l]) ? a[l]++ : (b = 0, a[l] = 1), C = f[b] || (f[b] = []), C.push(l); + k || 0 === k || (k = n ? this.B : this.resolution); + for (let p, v; l < a; l++) { + if ((v = b[l]) && !h[v]) { + h[v] = 1; + p = T(this, v, n); + a: { + g = p; + var m = e, r = f, q = k; + let A = []; + if (g && g.length) { + if (g.length <= q) { + m.push(g); + p = void 0; + break a; } - } - } - } - if (k = f.length) { - if (p) { - if (1 < f.length) { - b: { - for (k = [], e = w(), p = f.length, b = p - 1; 0 <= b; b--) { - for (p = f[b], a = p.length, h = 0; h < a; h++) { - if (g = p[h], !e[g]) { - if (e[g] = 1, d) { - d--; - } else { - if (k.push(g), k.length === c) { - break b; - } - } - } - } + for (let H = 0, Y; H < q; H++) { + if (Y = g[H]) { + A[H] = Y; } } - } else { - k = (f = f[0]).length > c || d ? f.slice(d, c + d) : f; - } - f = k; - } else { - if (k < g) { - e = []; - break a; - } - f = f[k - 1]; - if (c || d) { - if (f.length > c || d) { - f = f.slice(d, c + d); + if (A.length) { + m.push(A); + p = void 0; + break a; } } + p = r ? void 0 : A; } + if (p) { + e = p; + break; + } + n && (f && p && e.length || (n = v)); } - e = f; + f && n && l === a - 1 && !e.length && (n = "", l = -1, h = w()); } - return e; + a: { + n = e.length; + a = e; + if (1 < n) { + a = C(e, k, c, d, f); + } else if (1 === n) { + f = E.call(null, e[0], c, d); + break a; + } + f = a; + } + return f; }; -function O(a, c, b, e) { - return (a = P(this, a, c)) && a.length ? N(a, b, e) : []; +function S(a, c, b, e, d) { + a = T(this, a, c); + d = !0; + return a && a.length ? d ? E.call(this, a, b, e) : new I(a) : d ? [] : new I(); } -function Q(a, c, b, e) { - let d = []; - if (a) { - e = Math.min(a.length, e); - for (let g = 0, f; g < e; g++) { - (f = a[g]) && f && (d[g] = f); - } - if (d.length) { - c.push(d); - return; - } - } - return !b && d; -} -function P(a, c, b) { +function T(a, c, b) { let e; - b && (e = a.bidirectional && c > b); - a = b ? (a = a.ctx.get(e ? c : b)) && a.get(e ? b : c) : a.map.get(c); + b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); + a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;K.prototype.remove = function(a, c) { +;P.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -536,14 +797,14 @@ function P(a, c, b) { } } } else { - R(this.map, a), this.depth && R(this.ctx, a); + U(this.map, a), this.depth && U(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function R(a, c) { +function U(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, g; e < a.length; e++) { @@ -557,26 +818,26 @@ function R(a, c) { } } } else { - for (let e of a) { - const d = e[0], g = R(e[1], c); + for (let e of a.entries()) { + const d = e[0], g = U(e[1], c); g ? b += g : a.delete(d); } } return b; } -;function K(a, c) { - if (!this || this.constructor !== K) { - return new K(a); +;function P(a, c) { + if (!this || this.constructor !== P) { + return new P(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (J[b] || console.warn("Preset not found: " + b), a = Object.assign({}, J[b], a)); + b && (O[b] || console.warn("Preset not found: " + b), a = Object.assign({}, O[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = a.encode || a.encoder || I; - this.encoder = d.encode ? d : "object" === typeof d ? new E(d) : {encode:d}; + const e = !0 === b ? {depth:1} : b || {}, d = a.encode || a.encoder || ha; + this.encoder = d.encode ? d : "object" === typeof d ? new z(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = a.tokenize || "strict"; this.depth = "strict" === b && e.depth || 0; @@ -587,11 +848,11 @@ function R(a, c) { this.map = new Map(); this.ctx = new Map(); this.reg = c || (this.fastupdate ? new Map() : new Set()); - this.A = e.resolution || 3; + this.B = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new H(b); + this.cache = (b = a.cache || null) && new N(b); } -t = K.prototype; +t = P.prototype; t.clear = function() { this.map.clear(); this.ctx.clear(); @@ -609,7 +870,7 @@ t.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function S(a) { +function V(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -617,7 +878,7 @@ function S(a) { } } else { for (const b of a) { - const e = b[0], d = S(b[1]); + const e = b[0], d = V(b[1]); d ? c += d : a.delete(e); } } @@ -627,13 +888,13 @@ t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - S(this.map); - this.depth && S(this.ctx); + V(this.map); + this.depth && V(this.ctx); return this; }; t.searchCache = function(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new H()); + this.cache || (this.cache = new N()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -648,9 +909,9 @@ t.searchCache = function(a, c, b) { } return e; }; -const T = {Index:K, Charset:null, Encoder:E, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, U = self; -let V; -(V = U.define) && V.amd ? V([], function() { - return T; -}) : "object" === typeof U.exports ? U.exports = T : U.FlexSearch = T; +const W = {Index:P, Charset:null, Encoder:z, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, X = self; +let Z; +(Z = X.define) && Z.amd ? Z([], function() { + return W; +}) : "object" === typeof X.exports ? X.exports = W : X.FlexSearch = W; }(this||self)); diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index 43024cb..92b6ffc 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -1,28 +1,34 @@ /**! - * FlexSearch.js v0.8.103 (Light) + * FlexSearch.js v0.8.105 (Light) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var t;function u(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 g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===d?c:a}function w(){return Object.create(null)}function x(a,c){return c.length-a.length};const y=/[^\p{L}\p{N}]+/u,z=/(\d{3})/g,A=/(\D)(\d{3})/g,B=/(\d{3})(\D)/g,D="".normalize&&/[\u0300-\u036f]/g;function E(a){if(!this||this.constructor!==E)return new E(...arguments);for(let c=0;ca.length)return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&F(this);return this};t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.i+=(this.i?"|":"")+a;this.u=null;this.cache&&F(this);return this}; -t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&F(this);return this};t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1this.stemmer.get(r)),k=1);f&&k&&(f.lengththis.matcher.get(r)));if(f&&this.replacer)for(d=0;f&&dthis.v&&(this.j.clear(),this.o=this.o/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.m&&(this.h.set(a,b),this.h.size>this.v&&(this.h.clear(),this.m=this.m/1.1|0));return b};function G(a){a.l=null;a.h.clear();a.j.clear()};function H(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.g=""}H.prototype.set=function(a,c){this.cache.set(this.g=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};H.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};H.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -H.prototype.clear=function(){this.cache.clear();this.g=""};const I={normalize:function(a){return a.toLowerCase()},dedupe:!1};const J={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};w();K.prototype.add=function(a,c,b,e){if(c&&(a||0===a)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(e=c.length){const r=w(),q=w(),p=this.depth,n=this.resolution;for(let m=0;mg;h--){f=l.substring(g,h);var k=this.score?this.score(c,l,m,f,g):L(n,e,m,d,g);M(this,q,f,k,a,b)}break}case "reverse":if(1< -d){for(h=d-1;0f?0:1),e,m,h-1,k-1),C=this.bidirectional&&l>g;M(this,r,C?g:l,v,a,b,C?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function M(a,c,b,e,d,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function L(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,g,f;d=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length);else if(f>=c)return f>c&&(g=g.slice(0,c)),g;e.push(g);c-=f;if(!c)break}return e.length?e=1c||d?f.slice(d,c+d):f;f=k}else{if(kc||d)f=f.slice(d, -c+d)}e=f}return e};function O(a,c,b,e){return(a=P(this,a,c))&&a.length?N(a,b,e):[]}function Q(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let g=0,f;gb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};K.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else R(this.map,a),this.depth&&R(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function R(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,g;eb.add(a,c)):this.add(a,c)}; -function S(a){let c=0;if(a.constructor===Array)for(let b=0,e;b"a1a".split(b).length; +this.numeric=u(a.numeric,e)}else{try{this.split=u(this.split,y)}catch(d){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), +null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.C="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.s=this.o=128;this.g="";this.v=null;this.h="";this.A=null;if(this.matcher)for(const d of this.matcher.keys())this.g+=(this.g?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.h+=(this.h?"|":"")+d;return this}; +t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.A=null;this.cache&&C(this);return this};t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&C(this);return this};t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.v=null;this.cache&&C(this);return this};t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&C(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.o)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(C,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=z?a.normalize("NFKD").replace(z,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),f.lengththis.matcher.get(k)));if(f&&this.replacer)for(d=0;f&&dthis.C&& +(this.j.clear(),this.s=this.s/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.o&&(this.i.set(a,b),this.i.size>this.C&&(this.i.clear(),this.o=this.o/1.1|0));return b};function C(a){a.l=null;a.i.clear();a.j.clear()};function D(a,c,b,e,d){const g=a.length;let f=[],h,k;h=w();for(let l=0,n,m,r,q;lb||e?f.slice(e,b+e):f;else{if(ab||e)f=f.slice(e,b+e)}return f} +function E(a,c,b){const e=[],d=w();let g;var f=a.length;let h;for(let k=f-1;0<=k;k--)if(h=(f=a[k])&&f.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?G.call(this,a):a;let d=[];for(let g=0,f,h;g=h){b-=h;continue}bc&&(f=f.slice(0,c),h=c);if(!d.length&&h>=c)return e?G.call(this,f):f;d.push(f);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=E(a,b,e),e=0));return g?this.resolve(b,e,d):this};J.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const g=arguments[0];g&&(a=!!g.suggest,d=g.resolve,c=g.limit,b=g.offset,e=g.enrich&&d)}if(a){const {m:g,u:f,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=I(this,"and",arguments);return L.call(this,g,f,h,k,l,n,m)}return d?this.resolve(c,b,e):this}; +function L(a,c,b,e,d,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=x(a))return this.result=D(a,c,b,e,f),g?d?G.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(b,e,d):this};J.prototype.xor=function(){const {m:a,u:c,limit:b,offset:e,enrich:d,resolve:g,suggest:f}=I(this,"xor",arguments);return M.call(this,a,c,b,e,d,g,f)}; +function M(a,c,b,e,d,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=da.call(this,a,b,e,g,this.g),g?d?G.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(b,e,d):this} +function da(a,c,b,e,d){const g=[],f=w();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)};O.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};O.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; +O.prototype.clear=function(){this.cache.clear();this.g=""};const fa={normalize:function(a){return a.toLowerCase()},numeric:!1,dedupe:!1};const ha={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};P.prototype.add=function(a,c,b,e){if(c&&(a||0===a)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(e=c.length){const l=w(),n=w(),m=this.depth,r=this.resolution;for(let q=0;qg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,q,f,g):Q(r,e,q,d,g);R(this,n,f,k,a,b)}break}case "reverse":if(1< +d){for(h=d-1;0f?0:1),e,q,h-1,k-1),A=this.bidirectional&&p>g;R(this,l,A?g:p,v,a,b,A?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function R(a,c,b,e,d,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Q(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};P.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else U(this.map,a),this.depth&&U(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function U(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,g;eb.add(a,c)):this.add(a,c)}; +function V(a){let c=0;if(a.constructor===Array)for(let b=0,e;b "a1a".split(b).length; } - try { - this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); - } catch (g) { - this.split = /\s+/; - } - this.numeric = e; + this.numeric = u(a.numeric, e); } else { try { - this.split = u(b, y, this.split); - } catch (e) { - this.split = /\s+/; + this.split = u(this.split, y); + } catch (d) { + console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = u(this.numeric, !0); + this.numeric = u(a.numeric, u(this.numeric, !0)); } this.prepare = u(a.prepare, null, this.prepare); this.finalize = u(a.finalize, null, this.finalize); - this.rtl = a.rtl || !1; + this.rtl = u(a.rtl, !1, this.rtl); this.dedupe = u(a.dedupe, !1, this.dedupe); this.filter = u((b = a.filter) && new Set(b), null, this.filter); this.matcher = u((b = a.matcher) && new Map(b), null, this.matcher); @@ -99,50 +108,36 @@ t.assign = function(a) { this.minlength = u(a.minlength, 1, this.minlength); this.maxlength = u(a.maxlength, 0, this.maxlength); if (this.cache = b = u(a.cache, !0, this.cache)) { - this.l = null, this.v = "number" === typeof b ? b : 2e5, this.h = new Map(), this.j = new Map(), this.o = this.m = 128; + this.l = null, this.C = "number" === typeof b ? b : 2e5, this.i = new Map(), this.j = new Map(), this.s = this.o = 128; } this.g = ""; - this.s = null; - this.i = ""; - this.u = null; + this.v = null; + this.h = ""; + this.A = null; if (this.matcher) { - for (const e of this.matcher.keys()) { - this.g += (this.g ? "|" : "") + e; + for (const d of this.matcher.keys()) { + this.g += (this.g ? "|" : "") + d; } } if (this.stemmer) { - for (const e of this.stemmer.keys()) { - this.i += (this.i ? "|" : "") + e; + for (const d of this.stemmer.keys()) { + this.h += (this.h ? "|" : "") + d; } } return this; }; -t.addMatcher = function(a, c) { - if ("object" === typeof a) { - return this.addReplacer(a, c); - } - if (2 > a.length) { - return this.addMapper(a, c); - } - this.matcher || (this.matcher = new Map()); - this.matcher.set(a, c); - this.g += (this.g ? "|" : "") + a; - this.s = null; - this.cache && F(this); - return this; -}; t.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); - this.i += (this.i ? "|" : "") + a; - this.u = null; - this.cache && F(this); + this.h += (this.h ? "|" : "") + a; + this.A = null; + this.cache && E(this); return this; }; t.addFilter = function(a) { this.filter || (this.filter = new Set()); this.filter.add(a); - this.cache && F(this); + this.cache && E(this); return this; }; t.addMapper = function(a, c) { @@ -154,138 +149,503 @@ t.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && F(this); + this.cache && E(this); + return this; +}; +t.addMatcher = function(a, c) { + if ("object" === typeof a) { + return this.addReplacer(a, c); + } + if (2 > a.length && (this.dedupe || this.mapper)) { + return this.addMapper(a, c); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(a, c); + this.g += (this.g ? "|" : "") + a; + this.v = null; + this.cache && E(this); return this; }; t.addReplacer = function(a, c) { - "string" === typeof a && (a = new RegExp(a, "g")); + if ("string" === typeof a) { + return this.addMatcher(a, c); + } this.replacer || (this.replacer = []); - this.replacer.push(a, c || ""); - this.cache && F(this); + this.replacer.push(a, c); + this.cache && E(this); return this; }; -function F(a) { - a.h.clear(); - a.j.clear(); -} t.encode = function(a) { - if (this.cache && a.length <= this.m) { + if (this.cache && a.length <= this.o) { if (this.l) { - if (this.h.has(a)) { - return this.h.get(a); + if (this.i.has(a)) { + return this.i.get(a); } } else { - this.l = setTimeout(G, 50, this); + this.l = setTimeout(E, 50, this); } } - this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : D ? a.normalize("NFKD").replace(D, "").toLowerCase() : a.toLowerCase()); + this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = C ? a.normalize("NFKD").replace(C, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && 3 < a.length && (a = a.replace(A, "$1 $2").replace(B, "$1 $2").replace(z, "$1 ")); + this.numeric && 3 < a.length && (a = a.replace(B, "$1 $2").replace(aa, "$1 $2").replace(z, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; for (let g = 0, f, h; g < e.length; g++) { - if (!(f = h = e[g])) { - continue; - } - if (f.length < this.minlength) { - continue; - } - if (c) { - b.push(f); - continue; - } - if (this.filter && this.filter.has(f)) { - continue; - } - if (this.cache && f.length <= this.o) { - if (this.l) { - var d = this.j.get(f); - if (d || "" === d) { - d && b.push(d); - continue; - } + if ((f = h = e[g]) && !(f.length < this.minlength)) { + if (c) { + b.push(f); } else { - this.l = setTimeout(G, 50, this); + if (!this.filter || !this.filter.has(f)) { + if (this.cache && f.length <= this.s) { + if (this.l) { + var d = this.j.get(f); + if (d || "" === d) { + d && b.push(d); + continue; + } + } else { + this.l = setTimeout(E, 50, this); + } + } + this.stemmer && 2 < f.length && (this.A || (this.A = new RegExp("(?!^)(" + this.h + ")$")), f = f.replace(this.A, k => this.stemmer.get(k)), f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); + if (f && (this.mapper || this.dedupe && 1 < f.length)) { + d = ""; + for (let k = 0, l = "", n, m; k < f.length; k++) { + n = f.charAt(k), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (d += m) : d += l = n); + } + f = d; + } + this.matcher && 1 < f.length && (this.v || (this.v = new RegExp("(" + this.g + ")", "g")), f = f.replace(this.v, k => this.matcher.get(k))); + if (f && this.replacer) { + for (d = 0; f && d < this.replacer.length; d += 2) { + f = f.replace(this.replacer[d], this.replacer[d + 1]); + } + } + this.cache && h.length <= this.s && (this.j.set(h, f), this.j.size > this.C && (this.j.clear(), this.s = this.s / 1.1 | 0)); + f && b.push(f); + } } } - let k; - this.stemmer && 2 < f.length && (this.u || (this.u = new RegExp("(?!^)(" + this.i + ")$")), f = f.replace(this.u, r => this.stemmer.get(r)), k = 1); - f && k && (f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); - if (f && (this.mapper || this.dedupe && 1 < f.length)) { - d = ""; - for (let r = 0, q = "", p, n; r < f.length; r++) { - p = f.charAt(r), p === q && this.dedupe || ((n = this.mapper && this.mapper.get(p)) || "" === n ? n === q && this.dedupe || !(q = n) || (d += n) : d += q = p); - } - f = d; - } - this.matcher && 1 < f.length && (this.s || (this.s = new RegExp("(" + this.g + ")", "g")), f = f.replace(this.s, r => this.matcher.get(r))); - if (f && this.replacer) { - for (d = 0; f && d < this.replacer.length; d += 2) { - f = f.replace(this.replacer[d], this.replacer[d + 1]); - } - } - this.cache && h.length <= this.o && (this.j.set(h, f), this.j.size > this.v && (this.j.clear(), this.o = this.o / 1.1 | 0)); - f && b.push(f); } this.finalize && (b = this.finalize(b) || b); - this.cache && a.length <= this.m && (this.h.set(a, b), this.h.size > this.v && (this.h.clear(), this.m = this.m / 1.1 | 0)); + this.cache && a.length <= this.o && (this.i.set(a, b), this.i.size > this.C && (this.i.clear(), this.o = this.o / 1.1 | 0)); return b; }; -function G(a) { +function E(a) { a.l = null; - a.h.clear(); + a.i.clear(); a.j.clear(); } -;function H(a) { +;function F(a, c, b, e, d) { + const g = a.length; + let f = [], h, k; + h = w(); + for (let l = 0, n, m, r, q; l < c; l++) { + for (let p = 0; p < g; p++) { + if (r = a[p], l < r.length && (n = r[l])) { + for (let v = 0; v < n.length; v++) { + m = n[v], (k = h[m]) ? h[m]++ : (k = 0, h[m] = 1), q = f[k] || (f[k] = []), q.push(m); + } + } + } + } + if (a = f.length) { + if (d) { + f = 1 < f.length ? G(f, b, e) : (f = f[0]).length > b || e ? f.slice(e, b + e) : f; + } else { + if (a < g) { + return []; + } + f = f[a - 1]; + if (b || e) { + if (f.length > b || e) { + f = f.slice(e, b + e); + } + } + } + } + return f; +} +function G(a, c, b) { + const e = [], d = w(); + let g; + var f = a.length; + let h; + for (let k = f - 1; 0 <= k; k--) { + if (h = (f = a[k]) && f.length) { + for (let l = 0; l < h; l++) { + if (g = f[l], !d[g]) { + if (d[g] = 1, b) { + b--; + } else { + if (e.push(g), e.length === c) { + return e; + } + } + } + } + } + } + return e; +} +;function I(a, c, b, e) { + if (!a.length) { + return a; + } + if (1 === a.length) { + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? J.call(this, a) : a; + } + let d = []; + for (let g = 0, f, h; g < a.length; g++) { + if ((f = a[g]) && (h = f.length)) { + if (b) { + if (b >= h) { + b -= h; + continue; + } + b < h && (f = c ? f.slice(b, b + c) : f.slice(b), h = f.length, b = 0); + } + h > c && (f = f.slice(0, c), h = c); + if (!d.length && h >= c) { + return e ? J.call(this, f) : f; + } + d.push(f); + c -= h; + if (!c) { + break; + } + } + } + d = 1 < d.length ? [].concat.apply([], d) : d[0]; + return e ? J.call(this, d) : d; +} +;function K(a, c, b) { + var e = b[0]; + if (e.then) { + return Promise.all(b).then(function(n) { + return a[c].apply(a, n); + }); + } + if (e[0] && e[0].index) { + return a[c].apply(a, e); + } + e = []; + let d = [], g = 0, f = 0, h, k, l; + for (let n = 0, m; n < b.length; n++) { + if (m = b[n]) { + let r; + if (m.constructor === L) { + r = m.result; + } else if (m.constructor === Array) { + r = m; + } else { + if (g = m.limit || 0, f = m.offset || 0, l = m.suggest, k = m.resolve, h = m.enrich && k, m.index) { + m.resolve = !1, m.enrich = !1, r = m.index.search(m).result, m.resolve = k, m.enrich = h; + } else if (m.and) { + r = a.and(m.and); + } else if (m.or) { + r = a.or(m.or); + } else if (m.xor) { + r = a.xor(m.xor); + } else if (m.not) { + r = a.not(m.not); + } else { + continue; + } + } + if (r.then) { + d.push(r); + } else if (r.length) { + e[n] = r; + } else if (!l && ("and" === c || "xor" === c)) { + e = []; + break; + } + } + } + return {m:e, u:d, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; +} +;L.prototype.or = function() { + const {m:a, u:c, limit:b, offset:e, enrich:d, resolve:g} = K(this, "or", arguments); + return M.call(this, a, c, b, e, d, g); +}; +function M(a, c, b, e, d, g) { + if (c.length) { + const f = this; + return Promise.all(c).then(function(h) { + a = []; + for (let k = 0, l; k < h.length; k++) { + (l = h[k]).length && (a[k] = l); + } + return M.call(f, a, [], b, e, d, g); + }); + } + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = G(a, b, e), e = 0)); + return g ? this.resolve(b, e, d) : this; +} +;L.prototype.and = function() { + let a = this.result.length, c, b, e, d; + if (!a) { + const g = arguments[0]; + g && (a = !!g.suggest, d = g.resolve, c = g.limit, b = g.offset, e = g.enrich && d); + } + if (a) { + const {m:g, u:f, limit:h, offset:k, enrich:l, resolve:n, suggest:m} = K(this, "and", arguments); + return N.call(this, g, f, h, k, l, n, m); + } + return d ? this.resolve(c, b, e) : this; +}; +function N(a, c, b, e, d, g, f) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, n; l < k.length; l++) { + (n = k[l]).length && (a[l] = n); + } + return N.call(h, a, [], b, e, d, g, f); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + if (c = x(a)) { + return this.result = F(a, c, b, e, f), g ? d ? J.call(this.index, this.result) : this.result : this; + } + this.result = []; + } + } else { + f || (this.result = a); + } + return g ? this.resolve(b, e, d) : this; +} +;L.prototype.xor = function() { + const {m:a, u:c, limit:b, offset:e, enrich:d, resolve:g, suggest:f} = K(this, "xor", arguments); + return O.call(this, a, c, b, e, d, g, f); +}; +function O(a, c, b, e, d, g, f) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, n; l < k.length; l++) { + (n = k[l]).length && (a[l] = n); + } + return O.call(h, a, [], b, e, d, g, f); + }); + } + if (a.length) { + if (this.result.length && a.unshift(this.result), 2 > a.length) { + this.result = a[0]; + } else { + return this.result = ba.call(this, a, b, e, g, this.g), g ? d ? J.call(this.index, this.result) : this.result : this; + } + } else { + f || (this.result = a); + } + return g ? this.resolve(b, e, d) : this; +} +function ba(a, c, b, e, d) { + const g = [], f = w(); + let h = 0; + for (let k = 0, l; k < a.length; k++) { + if (l = a[k]) { + h < l.length && (h = l.length); + for (let n = 0, m; n < l.length; n++) { + if (m = l[n]) { + for (let r = 0, q; r < m.length; r++) { + q = m[r], f[q] = f[q] ? 2 : 1; + } + } + } + } + } + for (let k = 0, l, n = 0; k < h; k++) { + for (let m = 0, r; m < a.length; m++) { + if (r = a[m]) { + if (l = r[k]) { + for (let q = 0, p; q < l.length; q++) { + if (p = l[q], 1 === f[p]) { + if (b) { + b--; + } else { + if (e) { + if (g.push(p), g.length === c) { + return g; + } + } else { + const v = k + (m ? d : 0); + g[v] || (g[v] = []); + g[v].push(p); + if (++n === c) { + return g; + } + } + } + } + } + } + } + } + } + return g; +} +;L.prototype.not = function() { + const {m:a, u:c, limit:b, offset:e, enrich:d, resolve:g, suggest:f} = K(this, "not", arguments); + return P.call(this, a, c, b, e, d, g, f); +}; +function P(a, c, b, e, d, g, f) { + if (c.length) { + const h = this; + return Promise.all(c).then(function(k) { + a = []; + for (let l = 0, n; l < k.length; l++) { + (n = k[l]).length && (a[l] = n); + } + return P.call(h, a, [], b, e, d, g, f); + }); + } + if (a.length && this.result.length) { + this.result = ca.call(this, a, b, e, g); + } else if (g) { + return this.resolve(b, e, d); + } + return g ? d ? J.call(this.index, this.result) : this.result : this; +} +function ca(a, c, b, e) { + const d = []; + a = new Set(a.flat().flat()); + for (let g = 0, f, h = 0; g < this.result.length; g++) { + if (f = this.result[g]) { + for (let k = 0, l; k < f.length; k++) { + if (l = f[k], !a.has(l)) { + if (b) { + b--; + } else { + if (e) { + if (d.push(l), d.length === c) { + return d; + } + } else { + if (d[g] || (d[g] = []), d[g].push(l), ++h === c) { + return d; + } + } + } + } + } + } + } + return d; +} +;function L(a) { + if (!this || this.constructor !== L) { + return new L(a); + } + if (a && a.index) { + return a.resolve = !1, this.index = a.index, this.g = a.boost || 0, this.result = a.index.search(a).result, this; + } + this.index = null; + this.result = a || []; + this.g = 0; +} +L.prototype.limit = function(a) { + if (this.result.length) { + const c = []; + let b = 0; + for (let e = 0, d; e < this.result.length; e++) { + if (d = this.result[e], d.length + b < a) { + c[e] = d, b += d.length; + } else { + c[e] = d.slice(0, a - b); + this.result = c; + break; + } + } + } + return this; +}; +L.prototype.offset = function(a) { + if (this.result.length) { + const c = []; + let b = 0; + for (let e = 0, d; e < this.result.length; e++) { + d = this.result[e], d.length + b < a ? b += d.length : (c[e] = d.slice(a - b), b = a); + } + this.result = c; + } + return this; +}; +L.prototype.boost = function(a) { + this.g += a; + return this; +}; +L.prototype.resolve = function(a, c, b) { + const e = this.result, d = this.index; + this.result = this.index = null; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), I.call(d, e, a || 100, c, b)) : e; +}; +w(); +function J(a) { + if (!this || !this.store) { + return a; + } + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; + } + return c; +} +;function Q(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.g = ""; } -H.prototype.set = function(a, c) { +Q.prototype.set = function(a, c) { this.cache.set(this.g = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -H.prototype.get = function(a) { +Q.prototype.get = function(a) { const c = this.cache.get(a); c && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c)); return c; }; -H.prototype.remove = function(a) { +Q.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -H.prototype.clear = function() { +Q.prototype.clear = function() { this.cache.clear(); this.g = ""; }; -const I = {normalize:function(a) { +const da = {normalize:function(a) { return a.toLowerCase(); -}, dedupe:!1}; -const J = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -w(); -K.prototype.add = function(a, c, b, e) { +}, numeric:!1, dedupe:!1}; +const R = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +S.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); if (e = c.length) { - const r = w(), q = w(), p = this.depth, n = this.resolution; - for (let m = 0; m < e; m++) { - let l = c[this.rtl ? e - 1 - m : m]; - var d = l.length; - if (d && (p || !q[l])) { - var g = this.score ? this.score(c, l, m, null, 0) : L(n, e, m), f = ""; + const l = w(), n = w(), m = this.depth, r = this.resolution; + for (let q = 0; q < e; q++) { + let p = c[this.rtl ? e - 1 - q : q]; + var d = p.length; + if (d && (m || !n[p])) { + var g = this.score ? this.score(c, p, q, null, 0) : T(r, e, q), f = ""; switch(this.tokenize) { case "full": if (2 < d) { for (g = 0; g < d; g++) { for (var h = d; h > g; h--) { - f = l.substring(g, h); - var k = this.score ? this.score(c, l, m, f, g) : L(n, e, m, d, g); - M(this, q, f, k, a, b); + f = p.substring(g, h); + var k = this.score ? this.score(c, p, q, f, g) : T(r, e, q, d, g); + U(this, n, f, k, a, b); } } break; @@ -293,24 +653,24 @@ K.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - f = l[h] + f, k = this.score ? this.score(c, l, m, f, h) : L(n, e, m, d, h), M(this, q, f, k, a, b); + f = p[h] + f, k = this.score ? this.score(c, p, q, f, h) : T(r, e, q, d, h), U(this, n, f, k, a, b); } f = ""; } case "forward": if (1 < d) { for (h = 0; h < d; h++) { - f += l[h], M(this, q, f, g, a, b); + f += p[h], U(this, n, f, g, a, b); } break; } default: - if (M(this, q, l, g, a, b), p && 1 < e && m < e - 1) { - for (d = w(), f = this.A, g = l, h = Math.min(p + 1, e - m), d[g] = 1, k = 1; k < h; k++) { - if ((l = c[this.rtl ? e - 1 - m - k : m + k]) && !d[l]) { - d[l] = 1; - const v = this.score ? this.score(c, g, m, l, k) : L(f + (e / 2 > f ? 0 : 1), e, m, h - 1, k - 1), C = this.bidirectional && l > g; - M(this, r, C ? g : l, v, a, b, C ? l : g); + if (U(this, n, p, g, a, b), m && 1 < e && q < e - 1) { + for (d = w(), f = this.B, g = p, h = Math.min(m + 1, e - q), d[g] = 1, k = 1; k < h; k++) { + if ((p = c[this.rtl ? e - 1 - q - k : q + k]) && !d[p]) { + d[p] = 1; + const v = this.score ? this.score(c, g, q, p, k) : T(f + (e / 2 > f ? 0 : 1), e, q, h - 1, k - 1), A = this.bidirectional && p > g; + U(this, l, A ? g : p, v, a, b, A ? p : g); } } } @@ -322,46 +682,16 @@ K.prototype.add = function(a, c, b, e) { } return this; }; -function M(a, c, b, e, d, g, f) { +function U(a, c, b, e, d, g, f) { let h = f ? a.ctx : a.map, k; if (!c[b] || f && !(k = c[b])[f]) { f ? (c = k || (c[b] = w()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), g && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function L(a, c, b, e, d) { +function T(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 N(a, c, b) { - if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; - } - let e = []; - for (let d = 0, g, f; d < a.length; d++) { - if ((g = a[d]) && (f = g.length)) { - if (b) { - if (b >= f) { - b -= f; - continue; - } - b < f && (g = c ? g.slice(b, b + c) : g.slice(b), f = g.length, b = 0); - } - if (e.length) { - f > c && (g = g.slice(0, c), f = g.length); - } else { - if (f >= c) { - return f > c && (g = g.slice(0, c)), g; - } - } - e.push(g); - c -= f; - if (!c) { - break; - } - } - } - return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; -} -;K.prototype.search = function(a, c, b) { +;S.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); var e = [], d = 0; if (b) { @@ -377,150 +707,81 @@ function L(a, c, b, e, d) { } b = this.encoder.encode(a); a = b.length; - c || !h || (c = 100); + c = c || (h ? 100 : 0); if (1 === a) { - return O.call(this, b[0], "", c, d); + return W.call(this, b[0], "", c, d, h); } g = this.depth && !1 !== g; if (2 === a && g && !f) { - return O.call(this, b[0], b[1], c, d); + return W.call(this, b[0], b[1], c, d, h); } - var r = h = 0; - if (1 < a) { - var q = w(); - const n = []; - for (let m = 0, l; m < a; m++) { - if ((l = b[m]) && !q[l]) { - if (f || P(this, l)) { - n.push(l), q[l] = 1; - } else { - return e; - } - const v = l.length; - h = Math.max(h, v); - r = r ? Math.min(r, v) : v; - } - } - b = n; - a = b.length; + h = w(); + let l = 0; + if (1 < a && g) { + var n = b[0]; + l = 1; } - if (!a) { - return e; - } - q = 0; - if (1 === a) { - return O.call(this, b[0], "", c, d); - } - if (2 === a && g && !f) { - return O.call(this, b[0], b[1], c, d); - } - if (1 < a) { - if (g) { - var p = b[0]; - q = 1; - } else { - 9 < h && 3 < h / r && b.sort(x); - } - } - k || 0 === k || (k = this.resolution); - for (let n, m; q < a; q++) { - m = b[q]; - p ? (n = P(this, m, p), n = Q(n, e, f, this.A), f && !1 === n && e.length || (p = m)) : (n = P(this, m, ""), n = Q(n, e, f, k)); - if (n) { - return n; - } - if (f && q === a - 1) { - g = e.length; - if (!g) { - if (p) { - p = ""; - q = -1; - continue; - } - return e; - } - if (1 === g) { - return N(e[0], c, d); - } - } - } - a: { - p = f; - g = e.length; - f = []; - a = w(); - for (let n = 0, m, l, v, C; n < k; n++) { - for (h = 0; h < g; h++) { - if (v = e[h], n < v.length && (m = v[n])) { - for (r = 0; r < m.length; r++) { - l = m[r], (b = a[l]) ? a[l]++ : (b = 0, a[l] = 1), C = f[b] || (f[b] = []), C.push(l); + k || 0 === k || (k = n ? this.B : this.resolution); + for (let p, v; l < a; l++) { + if ((v = b[l]) && !h[v]) { + h[v] = 1; + p = X(this, v, n); + a: { + g = p; + var m = e, r = f, q = k; + let A = []; + if (g && g.length) { + if (g.length <= q) { + m.push(g); + p = void 0; + break a; } - } - } - } - if (k = f.length) { - if (p) { - if (1 < f.length) { - b: { - for (k = [], e = w(), p = f.length, b = p - 1; 0 <= b; b--) { - for (p = f[b], a = p.length, h = 0; h < a; h++) { - if (g = p[h], !e[g]) { - if (e[g] = 1, d) { - d--; - } else { - if (k.push(g), k.length === c) { - break b; - } - } - } - } + for (let H = 0, V; H < q; H++) { + if (V = g[H]) { + A[H] = V; } } - } else { - k = (f = f[0]).length > c || d ? f.slice(d, c + d) : f; - } - f = k; - } else { - if (k < g) { - e = []; - break a; - } - f = f[k - 1]; - if (c || d) { - if (f.length > c || d) { - f = f.slice(d, c + d); + if (A.length) { + m.push(A); + p = void 0; + break a; } } + p = r ? void 0 : A; } + if (p) { + e = p; + break; + } + n && (f && p && e.length || (n = v)); } - e = f; + f && n && l === a - 1 && !e.length && (n = "", l = -1, h = w()); } - return e; + a: { + n = e.length; + a = e; + if (1 < n) { + a = F(e, k, c, d, f); + } else if (1 === n) { + f = I.call(null, e[0], c, d); + break a; + } + f = a; + } + return f; }; -function O(a, c, b, e) { - return (a = P(this, a, c)) && a.length ? N(a, b, e) : []; +function W(a, c, b, e, d) { + a = X(this, a, c); + d = !0; + return a && a.length ? d ? I.call(this, a, b, e) : new L(a) : d ? [] : new L(); } -function Q(a, c, b, e) { - let d = []; - if (a) { - e = Math.min(a.length, e); - for (let g = 0, f; g < e; g++) { - (f = a[g]) && f && (d[g] = f); - } - if (d.length) { - c.push(d); - return; - } - } - return !b && d; -} -function P(a, c, b) { +function X(a, c, b) { let e; - b && (e = a.bidirectional && c > b); - a = b ? (a = a.ctx.get(e ? c : b)) && a.get(e ? b : c) : a.map.get(c); + b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); + a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;K.prototype.remove = function(a, c) { +;S.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -535,14 +796,14 @@ function P(a, c, b) { } } } else { - R(this.map, a), this.depth && R(this.ctx, a); + Y(this.map, a), this.depth && Y(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function R(a, c) { +function Y(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, g; e < a.length; e++) { @@ -556,26 +817,26 @@ function R(a, c) { } } } else { - for (let e of a) { - const d = e[0], g = R(e[1], c); + for (let e of a.entries()) { + const d = e[0], g = Y(e[1], c); g ? b += g : a.delete(d); } } return b; } -;function K(a, c) { - if (!this || this.constructor !== K) { - return new K(a); +;function S(a, c) { + if (!this || this.constructor !== S) { + return new S(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (J[b] || console.warn("Preset not found: " + b), a = Object.assign({}, J[b], a)); + b && (R[b] || console.warn("Preset not found: " + b), a = Object.assign({}, R[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = a.encode || a.encoder || I; - this.encoder = d.encode ? d : "object" === typeof d ? new E(d) : {encode:d}; + const e = !0 === b ? {depth:1} : b || {}, d = a.encode || a.encoder || da; + this.encoder = d.encode ? d : "object" === typeof d ? new D(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = a.tokenize || "strict"; this.depth = "strict" === b && e.depth || 0; @@ -586,11 +847,11 @@ function R(a, c) { this.map = new Map(); this.ctx = new Map(); this.reg = c || (this.fastupdate ? new Map() : new Set()); - this.A = e.resolution || 3; + this.B = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new H(b); + this.cache = (b = a.cache || null) && new Q(b); } -t = K.prototype; +t = S.prototype; t.clear = function() { this.map.clear(); this.ctx.clear(); @@ -608,7 +869,7 @@ t.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function S(a) { +function Z(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -616,7 +877,7 @@ function S(a) { } } else { for (const b of a) { - const e = b[0], d = S(b[1]); + const e = b[0], d = Z(b[1]); d ? c += d : a.delete(e); } } @@ -626,13 +887,13 @@ t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - S(this.map); - this.depth && S(this.ctx); + Z(this.map); + this.depth && Z(this.ctx); return this; }; t.searchCache = function(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new H()); + this.cache || (this.cache = new Q()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -647,6 +908,6 @@ t.searchCache = function(a, c, b) { } return e; }; -export default {Index:K, Charset:null, Encoder:E, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:S, Charset:null, Encoder:D, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=K;export const Charset=null;export const Encoder=E;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=S;export const Charset=null;export const Encoder=D;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index bb8cdc4..2dbe6ac 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,29 +1,35 @@ /**! - * FlexSearch.js v0.8.103 (Bundle) + * FlexSearch.js v0.8.105 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var t;function u(a,c,b){const 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 g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===d?c:a}function w(){return Object.create(null)}function x(a,c){return c.length-a.length};const y=/[^\p{L}\p{N}]+/u,z=/(\d{3})/g,A=/(\D)(\d{3})/g,B=/(\d{3})(\D)/g,D="".normalize&&/[\u0300-\u036f]/g;function E(a){if(!this||this.constructor!==E)return new E(...arguments);for(let c=0;ca.length)return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&F(this);return this};t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.i+=(this.i?"|":"")+a;this.u=null;this.cache&&F(this);return this}; -t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&F(this);return this};t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1this.stemmer.get(r)),k=1);f&&k&&(f.lengththis.matcher.get(r)));if(f&&this.replacer)for(d=0;f&&dthis.v&&(this.j.clear(),this.o=this.o/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.m&&(this.h.set(a,b),this.h.size>this.v&&(this.h.clear(),this.m=this.m/1.1|0));return b};function G(a){a.l=null;a.h.clear();a.j.clear()};function H(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.g=""}H.prototype.set=function(a,c){this.cache.set(this.g=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};H.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};H.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -H.prototype.clear=function(){this.cache.clear();this.g=""};const I={normalize:function(a){return a.toLowerCase()},dedupe:!1};const J={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};w();K.prototype.add=function(a,c,b,e){if(c&&(a||0===a)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(e=c.length){const r=w(),q=w(),p=this.depth,n=this.resolution;for(let m=0;mg;h--){f=l.substring(g,h);var k=this.score?this.score(c,l,m,f,g):L(n,e,m,d,g);M(this,q,f,k,a,b)}break}case "reverse":if(1< -d){for(h=d-1;0f?0:1),e,m,h-1,k-1),C=this.bidirectional&&l>g;M(this,r,C?g:l,v,a,b,C?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function M(a,c,b,e,d,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function L(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,g,f;d=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length);else if(f>=c)return f>c&&(g=g.slice(0,c)),g;e.push(g);c-=f;if(!c)break}return e.length?e=1c||d?f.slice(d,c+d):f;f=k}else{if(kc||d)f=f.slice(d, -c+d)}e=f}return e};function O(a,c,b,e){return(a=P(this,a,c))&&a.length?N(a,b,e):[]}function Q(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let g=0,f;gb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};K.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else R(this.map,a),this.depth&&R(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function R(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,g;eb.add(a,c)):this.add(a,c)}; -function S(a){let c=0;if(a.constructor===Array)for(let b=0,e;b"a1a".split(b).length; +this.numeric=u(a.numeric,e)}else{try{this.split=u(this.split,y)}catch(d){this.split=/\s+/}this.numeric=u(a.numeric,u(this.numeric,!0))}this.prepare=u(a.prepare,null,this.prepare);this.finalize=u(a.finalize,null,this.finalize);this.rtl=u(a.rtl,!1,this.rtl);this.dedupe=u(a.dedupe,!1,this.dedupe);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.matcher=u((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=u((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer=u((b=a.stemmer)&&new Map(b), +null,this.stemmer);this.replacer=u(a.replacer,null,this.replacer);this.minlength=u(a.minlength,1,this.minlength);this.maxlength=u(a.maxlength,0,this.maxlength);if(this.cache=b=u(a.cache,!0,this.cache))this.l=null,this.C="number"===typeof b?b:2E5,this.i=new Map,this.j=new Map,this.s=this.o=128;this.g="";this.v=null;this.h="";this.A=null;if(this.matcher)for(const d of this.matcher.keys())this.g+=(this.g?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.h+=(this.h?"|":"")+d;return this}; +t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.A=null;this.cache&&F(this);return this};t.addFilter=function(a){this.filter||(this.filter=new Set);this.filter.add(a);this.cache&&F(this);return this};t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.v=null;this.cache&&F(this);return this};t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&F(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.o)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(F,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=D?a.normalize("NFKD").replace(D,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),f.lengththis.matcher.get(k)));if(f&&this.replacer)for(d=0;f&&dthis.C&& +(this.j.clear(),this.s=this.s/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.o&&(this.i.set(a,b),this.i.size>this.C&&(this.i.clear(),this.o=this.o/1.1|0));return b};function F(a){a.l=null;a.i.clear();a.j.clear()};function G(a,c,b,e,d){const g=a.length;let f=[],h,k;h=w();for(let l=0,n,m,r,q;lb||e?f.slice(e,b+e):f;else{if(ab||e)f=f.slice(e,b+e)}return f} +function I(a,c,b){const e=[],d=w();let g;var f=a.length;let h;for(let k=f-1;0<=k;k--)if(h=(f=a[k])&&f.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?K.call(this,a):a;let d=[];for(let g=0,f,h;g=h){b-=h;continue}bc&&(f=f.slice(0,c),h=c);if(!d.length&&h>=c)return e?K.call(this,f):f;d.push(f);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=I(a,b,e),e=0));return g?this.resolve(b,e,d):this};M.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const g=arguments[0];g&&(a=!!g.suggest,d=g.resolve,c=g.limit,b=g.offset,e=g.enrich&&d)}if(a){const {m:g,u:f,limit:h,offset:k,enrich:l,resolve:n,suggest:m}=L(this,"and",arguments);return O.call(this,g,f,h,k,l,n,m)}return d?this.resolve(c,b,e):this}; +function O(a,c,b,e,d,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=x(a))return this.result=G(a,c,b,e,f),g?d?K.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(b,e,d):this};M.prototype.xor=function(){const {m:a,u:c,limit:b,offset:e,enrich:d,resolve:g,suggest:f}=L(this,"xor",arguments);return P.call(this,a,c,b,e,d,g,f)}; +function P(a,c,b,e,d,g,f){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=aa.call(this,a,b,e,g,this.g),g?d?K.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(b,e,d):this} +function aa(a,c,b,e,d){const g=[],f=w();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)};R.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};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.g=""};const ca={normalize:function(a){return a.toLowerCase()},numeric:!1,dedupe:!1};const da={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};S.prototype.add=function(a,c,b,e){if(c&&(a||0===a)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(e=c.length){const l=w(),n=w(),m=this.depth,r=this.resolution;for(let q=0;qg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,q,f,g):T(r,e,q,d,g);V(this,n,f,k,a,b)}break}case "reverse":if(1< +d){for(h=d-1;0f?0:1),e,q,h-1,k-1),A=this.bidirectional&&p>g;V(this,l,A?g:p,v,a,b,A?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function V(a,c,b,e,d,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=w()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function T(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};S.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Y(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,g;eb.add(a,c)):this.add(a,c)}; +function Z(a){let c=0;if(a.constructor===Array)for(let b=0,e;b} + */ IdxDB.prototype.destroy = function () { - return IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const req = IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return promisfy(req); }; // IdxDB.prototype.set = function(ref, key, ctx, data){ @@ -130,6 +140,9 @@ IdxDB.prototype.destroy = function () { // return transaction;//promisfy(req, callback); // }; +/** + * @return {!Promise} + */ IdxDB.prototype.clear = function () { const transaction = this.db.transaction(fields, "readwrite"); for (let i = 0; i < fields.length; i++) { @@ -138,6 +151,15 @@ IdxDB.prototype.clear = function () { return promisfy(transaction); }; +/** + * @param {!string} key + * @param {string=} ctx + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @return {!Promise} + */ IdxDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = /* tag? */!0, enrich = !1) { const transaction = this.db.transaction(ctx ? "ctx" : "map", "readonly"), map = transaction.objectStore(ctx ? "ctx" : "map"), @@ -174,6 +196,13 @@ IdxDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = /* ta }); }; +/** + * @param {!string} tag + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} enrich + * @return {!Promise} + */ IdxDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) { const transaction = this.db.transaction("tag", "readonly"), map = transaction.objectStore("tag"), @@ -189,6 +218,10 @@ IdxDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) { }; +/** + * @param {SearchResults} ids + * @return {!Promise} + */ IdxDB.prototype.enrich = function (ids) { if ("object" != typeof ids) { ids = [ids]; @@ -211,7 +244,10 @@ IdxDB.prototype.enrich = function (ids) { }); }; - +/** + * @param {number|string} id + * @return {!Promise} + */ IdxDB.prototype.has = function (id) { const transaction = this.db.transaction("reg", "readonly"), map = transaction.objectStore("reg"), @@ -466,7 +502,7 @@ IdxDB.prototype.commit = async function (flexsearch, _replace, _append) { /** * @param {IDBCursorWithValue} cursor - * @param {Array} ids + * @param {Array} ids * @param {boolean=} _tag */ @@ -518,6 +554,10 @@ function handle(cursor, ids, _tag) { cursor.continue(); } +/** + * @param {Array} ids + * @return {!Promise} + */ IdxDB.prototype.remove = function (ids) { if ("object" != typeof ids) { diff --git a/dist/module-debug/db/interface.js b/dist/module-debug/db/interface.js index 486d2bd..5c8ef90 100644 --- a/dist/module-debug/db/interface.js +++ b/dist/module-debug/db/interface.js @@ -1,3 +1,5 @@ + + /** * @interface */ @@ -20,9 +22,22 @@ StorageInterface.prototype.destroy = async function () {}; // transfer all changes of an index to the database StorageInterface.prototype.commit = async function () {}; -// get results of a term "key" with optional context "ctx" +/** + * get results of a term "key" with optional context "ctx" + * @param {!string} key + * @param {string=} ctx + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @return {!Promise} + */ StorageInterface.prototype.get = async function () {}; -// get documents stored in index (enrich result) +/** + * get documents stored in index (enrich result) + * @param {SearchResults} ids + * @return {!Promise} + */ StorageInterface.prototype.enrich = async function () {}; // check if id exists on a specific index StorageInterface.prototype.has = async function () {}; diff --git a/dist/module-debug/document.js b/dist/module-debug/document.js index 52289ed..95f915f 100644 --- a/dist/module-debug/document.js +++ b/dist/module-debug/document.js @@ -7,6 +7,7 @@ */ import { IndexOptions, DocumentOptions, DocumentDescriptor, FieldOptions, StoreOptions } from "./type.js"; +import StorageInterface from "./db/interface.js"; import Index from "./index.js"; import WorkerIndex from "./worker.js"; import Cache, { searchCache } from "./cache.js"; @@ -21,6 +22,7 @@ import "./document/search.js"; * @constructor * @param {!DocumentOptions} options * @return {Document|Promise} + * @this {Document} */ export default function Document(options) { @@ -40,7 +42,8 @@ export default function Document(options) { keystore = options.keystore || 0; keystore && (this.keystore = keystore); this.fastupdate = !!options.fastupdate; - this.reg = this.fastupdate ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); + this.reg = this.fastupdate ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ + /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); // todo support custom filter function this.storetree = (tmp = document.store || null) && tmp && !0 !== tmp && []; @@ -49,8 +52,8 @@ export default function Document(options) { this.cache = (tmp = options.cache || null) && new Cache(tmp); // do not apply cache again for the indexes since .searchCache() // is just a wrapper over .search() - options.cache = - /* suggest */ /* append: */ /* enrich */!1; + options.cache = /* suggest */ /* append: */ + /* enrich */!1; this.worker = options.worker; @@ -60,7 +63,7 @@ export default function Document(options) { // } /** - * @type {Map} + * @type {Map} * @export */ this.index = parse_descriptor.call(this, options, document); @@ -93,6 +96,7 @@ export default function Document(options) { this.tagtree[i]._filter = params.filter; } } + // the tag fields needs to be hold by indices this.tagfield[i] = field; this.tag.set(field, new Map()); } @@ -110,7 +114,7 @@ export default function Document(options) { return Promise.all(promises).then(function (promises) { let count = 0; for (const item of self.index.entries()) { - const key = item[0], + const key = /** @type {string} */item[0], index = item[1]; index.then && self.index.set(key, promises[count++]); @@ -123,6 +127,10 @@ export default function Document(options) { } } +/** + * @param {!StorageInterface} db + * @return {Promise>} + */ Document.prototype.mount = function (db) { let fields = this.field; @@ -313,14 +321,28 @@ function parse_tree(key, marker) { return 1 < count ? tree : tree[0]; } +/** + * @param {!number|Object} id + * @param {!Object} content + * @return {Document|Promise} + */ Document.prototype.append = function (id, content) { return this.add(id, content, !0); }; +/** + * @param {!number|Object} id + * @param {!Object} content + * @return {Document|Promise} + */ Document.prototype.update = function (id, content) { return this.remove(id).add(id, content); }; +/** + * @param {!number|Object} id + * @return {Document|Promise} + */ Document.prototype.remove = function (id) { if (is_object(id)) { @@ -393,6 +415,10 @@ Document.prototype.clear = function () { :*/ }; +/** + * @param {number|string} id + * @return {boolean|Promise} + */ Document.prototype.contain = function (id) { if (this.db) { @@ -411,6 +437,10 @@ Document.prototype.cleanup = function () { return this; }; +/** + * @param {number|string} id + * @return {Object} + */ Document.prototype.get = function (id) { if (this.db) { @@ -422,9 +452,14 @@ Document.prototype.get = function (id) { return this.store.get(id); }; -Document.prototype.set = function (id, store) { +/** + * @param {number|string} id + * @param {Object} data + * @return {Document} + */ +Document.prototype.set = function (id, data) { - this.store.set(id, store); + this.store.set(id, data); return this; }; diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index 08ea788..6607b8c 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -1,17 +1,35 @@ -import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults } from "../type.js"; +import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults, EnrichedSearchResults, SearchResults, IntermediateSearchResults } from "../type.js"; import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; import { intersect_union } from "../intersect.js"; import Document from "../document.js"; - -let debug = /* suggest */ /* append: */ /* enrich */!1; +import Index from "../index.js"; +import Resolver from "../resolver.js"; +import tick from "../profiler.js"; /** * @param {!string|DocumentSearchOptions} query * @param {number|DocumentSearchOptions=} limit * @param {DocumentSearchOptions=} options - * @param {Array=} _promises For internal use only. - * @returns {DocumentSearchResults|EnrichedDocumentSearchResults|MergedDocumentSearchResults|Promise} + * @param {Array=} _promises async recursion + * @returns { + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * MergedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults| + * Resolver | + * Promise< + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * MergedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults| + * Resolver + * > + * } */ Document.prototype.search = function (query, limit, options, _promises) { @@ -26,6 +44,13 @@ Document.prototype.search = function (query, limit, options, _promises) { } } + /** @type { + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults + * } */ let result = [], result_field = [], pluck, @@ -36,6 +61,7 @@ Document.prototype.search = function (query, limit, options, _promises) { tag, offset, count = 0, + resolve, highlight; @@ -50,12 +76,36 @@ Document.prototype.search = function (query, limit, options, _promises) { query = options.query || query; pluck = options.pluck; merge = options.merge; - field = pluck || options.field || options.index; + field = pluck || options.field || (field = options.index) && (field.index ? null : field); tag = this.tag && options.tag; - enrich = this.store && options.enrich; suggest = options.suggest; - highlight = options.highlight; - //resolve = !SUPPORT_RESOLVER || (options.resolve !== false); + resolve = /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + + // upgrade pluck when missing + if (!resolve && !pluck) { + field = field || this.field; + if (field) { + if (is_string(field)) { + pluck = field; + } else { + if (is_array(field) && 1 === field.length) { + field = field[0]; + } + pluck = field.field || field.index; + } + } + if (!pluck) { + throw new Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); + } + } + + if (this.store && options.enrich && !resolve) { + console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + } + + + enrich = this.store && options.enrich && resolve; + highlight = options.highlight && enrich; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -66,6 +116,7 @@ Document.prototype.search = function (query, limit, options, _promises) { tag = [tag]; } + // ----------------------------- // Tag-Search // ----------------------------- @@ -151,7 +202,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } // extend to multi field search by default - if (is_string(field)) { + if (field && field.constructor !== Array) { field = [field]; } } @@ -211,14 +262,13 @@ Document.prototype.search = function (query, limit, options, _promises) { // just collect and continue continue; } else { - res = index.search(query, limit, opt); // restore enrich state opt && enrich && (opt.enrich = enrich); } } - len = res && res.length; + len = res && (resolve ? res.length : res.result.length); // todo when no term was matched but tag was retrieved extend suggestion to tags // every field has to intersect against all selected tag fields @@ -242,7 +292,7 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return result; + return resolve ? result : new Resolver(result); } } } @@ -258,7 +308,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return result; + return resolve ? result : new Resolver(result); } } @@ -270,17 +320,17 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return result; + return resolve ? result : new Resolver(result); } } } if (count) { - res = intersect_union(res, arr); // intersect(arr, limit, offset) + res = intersect_union(res, arr, resolve); // intersect(arr, limit, offset) len = res.length; if (!len && !suggest) { // nothing matched - return result; + return resolve ? res : new Resolver( /** @type {IntermediateSearchResults} */res); } // move counter back by 1 count--; @@ -293,7 +343,7 @@ Document.prototype.search = function (query, limit, options, _promises) { count++; } else if (1 === field.length) { // fast path: nothing matched - return result; + return resolve ? result : new Resolver(result); } } @@ -311,7 +361,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return result; + return resolve ? result : new Resolver(result); } } @@ -329,7 +379,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (!count) { - return result; + return resolve ? result : new Resolver(result); } if (pluck && (!enrich || !this.store)) { return result[0]; @@ -343,9 +393,9 @@ Document.prototype.search = function (query, limit, options, _promises) { if (enrich && res.length && !res[0].doc) { if (!this.db) { - if (res.length) { - res = apply_enrich.call(this, res); - } + // if(res.length){ + res = apply_enrich.call(this, res); + // } } else { // the documents are stored on the first field promises.push(res = this.index.get(this.field[0]).db.enrich(res)); @@ -353,7 +403,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (pluck) { - return res; + return resolve ? res : new Resolver(res); } result[i] = { @@ -508,20 +558,25 @@ function get_tag(tag, key, limit, offset) { } /** - * @this {Document} + * @param {SearchResults} ids + * @return {EnrichedSearchResults|SearchResults} + * @this {Document|Index|null} */ -function apply_enrich(res) { +export function apply_enrich(ids) { - const arr = Array(res.length); + if (!this || !this.store) return ids; - for (let x = 0, id; x < res.length; x++) { - id = res[x]; - arr[x] = { + /** @type {EnrichedSearchResults} */ + const result = Array(ids.length); + + for (let x = 0, id; x < ids.length; x++) { + id = ids[x]; + result[x] = { id: id, doc: this.store.get(id) }; } - return arr; + return result; } \ No newline at end of file diff --git a/dist/module-debug/encoder.js b/dist/module-debug/encoder.js index 333e8a3..f1f0276 100644 --- a/dist/module-debug/encoder.js +++ b/dist/module-debug/encoder.js @@ -1,5 +1,5 @@ -import { parse_option } from "./common.js"; +import { merge_option } from "./common.js"; import normalize_polyfill from "./charset/normalize.js"; import { EncoderOptions } from "./type.js"; @@ -23,21 +23,26 @@ function fixedEncoder(string){ return [string] } -Built-in Encoder (Workflow) +Built-in Encoder ---------------------------- +The main workflow follows an increasing strategy, +starting from a simple .toLowerCase() to full RegExp Pipeline: 1. apply this.normalize: charset normalization: applied on the whole input string e.g. lowercase, - will also apply on: filter, matcher, stemmer, mapper - 2. apply this.split: split input into terms (includes/excludes) - 3. apply this.filter (pre-filter) - 4. apply this.matcher (replace terms) - 5. apply this.stemmer (replace term endings) - 6. apply this.filter (post-filter) - 7. apply this.mapper (replace chars) - 8. apply this.replacer (custom regex) + everything you put later into (filter, matcher, stemmer, mapper, etc.) + has to be normalized by definition, because it won't apply to them automatically + 2. apply this.prepare (custom preparation, string in - string out) + 3 split numerics into triplets when not surrounded by a letter + 4. apply this.split: split input into terms (includes/excludes) + 5. apply this.filter (pre-filter) + 6. apply this.stemmer (replace term endings) + 7. apply this.filter (post-filter) + 8. apply this.mapper (replace chars) 9. apply this.dedupe (letter deduplication) - 10. apply this.finalize + 10. apply this.matcher (replace terms) + 11. apply this.replacer (custom regex) + 12. apply this.finalize */ const whitespace = /[^\p{L}\p{N}]+/u, @@ -62,6 +67,9 @@ const whitespace = /[^\p{L}\p{N}]+/u, export default function Encoder() { if (!this || this.constructor !== Encoder) { + // let args = Array.prototype.slice.call(arguments); + // args.unshift(Encoder); + // return new (Encoder.bind.apply(Encoder, args)); return new Encoder(...arguments); } @@ -79,8 +87,9 @@ Encoder.prototype.assign = function (options) { * pre-processing string input * @type {Function|boolean} */ - this.normalize = /** @type {Function|boolean} */parse_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ - /*await rows.hasNext()*/, this.normalize); + this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ + /* skip_update: */ + /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize); // { // letter: true, @@ -93,68 +102,78 @@ Encoder.prototype.assign = function (options) { // } let include = options.include, - tmp = include || options.exclude || options.split; + tmp = include || options.exclude || options.split, + numeric; - if ("object" == typeof tmp) { - let numeric = !include, - regex = ""; + if (tmp || "" === tmp) { + if ("object" == typeof tmp && tmp.constructor !== RegExp) { + let regex = ""; + numeric = !include; + // split on whitespace by default + include || (regex += "\\p{Z}"); + if (tmp.letter) { + regex += "\\p{L}"; + } + if (tmp.number) { + regex += "\\p{N}"; + numeric = !!include; + } + if (tmp.symbol) { + regex += "\\p{S}"; + } + if (tmp.punctuation) { + regex += "\\p{P}"; + } + if (tmp.control) { + regex += "\\p{C}"; + } + if (tmp = tmp.char) { + regex += "object" == typeof tmp ? tmp.join("") : tmp; + } - // split on whitespace by default - options.include || (regex += "\\p{Z}"); - if (tmp.letter) { - regex += "\\p{L}"; - } - if (tmp.number) { - regex += "\\p{N}"; - numeric = !!include; - } - if (tmp.symbol) { - regex += "\\p{S}"; - } - if (tmp.punctuation) { - regex += "\\p{P}"; - } - if (tmp.control) { - regex += "\\p{C}"; - } - if (tmp = tmp.char) { - regex += "object" == typeof tmp ? tmp.join("") : tmp; + try { + // https://github.com/nextapps-de/flexsearch/issues/410 + /** + * split string input into terms + * @type {string|RegExp|boolean|null} + */ + this.split = new RegExp("[" + (include ? "^" : "") + regex + "]+", "u"); + } catch (e) { + console.error("Your split configuration:", tmp, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /\s+/."); + // fallback to a simple whitespace splitter + this.split = /\s+/; + } + } else { + this.split = /** @type {string|RegExp|boolean} */tmp; + // determine numeric encoding + numeric = /* suggest */ /* append: */ /* enrich */!1 === tmp || 2 > "a1a".split(tmp).length; } - try { - // https://github.com/nextapps-de/flexsearch/issues/410 - /** - * split string input into terms - * @type {string|RegExp|boolean|null} - */ - this.split = new RegExp("[" + (include ? "^" : "") + regex + "]+", "u"); - } catch (e) { - // fallback to a simple whitespace splitter - this.split = /\s+/; - } - this.numeric = numeric; + this.numeric = merge_option(options.numeric, numeric); } else { try { // https://github.com/nextapps-de/flexsearch/issues/410 - this.split = /** @type {string|RegExp|boolean} */parse_option(tmp, whitespace, this.split); + this.split = /** @type {string|RegExp|boolean} */merge_option(this.split, whitespace); } catch (e) { + console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /\s+/."); // fallback to a simple whitespace splitter this.split = /\s+/; } - this.numeric = parse_option(this.numeric, !0); + + this.numeric = merge_option(options.numeric, merge_option(this.numeric, !0)); } /** * post-processing terms * @type {Function|null} */ - this.prepare = /** @type {Function|null} */parse_option(options.prepare, null, this.prepare); + this.prepare = /** @type {Function|null} */merge_option(options.prepare, null, this.prepare); /** * final processing * @type {Function|null} */ - this.finalize = /** @type {Function|null} */parse_option(options.finalize, null, this.finalize); + this.finalize = /** @type {Function|null} */merge_option(options.finalize, null, this.finalize); // assign the normalization fallback to the mapper if (!normalize) { @@ -164,24 +183,23 @@ Encoder.prototype.assign = function (options) { // options - this.rtl = options.rtl || /* suggest */ /* append: */ /* enrich */!1; - this.dedupe = parse_option(options.dedupe, !1, this.dedupe); - this.filter = parse_option((tmp = options.filter) && new Set(tmp), null, this.filter); - this.matcher = parse_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); - this.mapper = parse_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); - this.stemmer = parse_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); - this.replacer = parse_option(options.replacer, null, this.replacer); - this.minlength = parse_option(options.minlength, 1, this.minlength); - this.maxlength = parse_option(options.maxlength, 0, this.maxlength); + this.rtl = merge_option(options.rtl, !1, this.rtl); + this.dedupe = merge_option(options.dedupe, !1, this.dedupe); + this.filter = merge_option((tmp = options.filter) && new Set(tmp), null, this.filter); + this.matcher = merge_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); + this.mapper = merge_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); + this.stemmer = merge_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); + this.replacer = merge_option(options.replacer, null, this.replacer); + this.minlength = merge_option(options.minlength, 1, this.minlength); + this.maxlength = merge_option(options.maxlength, 0, this.maxlength); // minimum required tokenizer by this encoder //this.tokenize = options["tokenize"] || ""; // auto-balanced cache - this.cache = tmp = parse_option(options.cache, !0, this.cache); + this.cache = tmp = merge_option(options.cache, !0, this.cache); if (tmp) { - this.timer = null; - this.cache_size = "number" == typeof tmp ? tmp : 2e5; + this.timer = null;this.cache_size = "number" == typeof tmp ? tmp : 2e5; this.cache_enc = new Map(); this.cache_term = new Map(); this.cache_enc_length = 128; @@ -216,7 +234,7 @@ Encoder.prototype.assign = function (options) { } // if(SUPPORT_COMPRESSION){ - // this.compression = parse_option(options.compress || options.compression, 0, this.compression); + // this.compression = merge_option(options.compress || options.compression, 0, this.compression); // if(this.compression && !table){ // table = new Array(radix); // for(let i = 0; i < radix; i++) table[i] = i + 33; @@ -227,43 +245,33 @@ Encoder.prototype.assign = function (options) { return this; }; -Encoder.prototype.addMatcher = function (match, replace) { - // regex: - if ("object" == typeof match) { - return this.addReplacer(match, replace); - } - // a single char: - if (2 > match.length) { - return this.addMapper(match, replace); - } - this.matcher || (this.matcher = new Map()); - this.matcher.set(match, replace); - this.matcher_str += (this.matcher_str ? "|" : "") + match; - this.matcher_test = null; //new RegExp("(" + this.matcher_str + ")"); - this.cache && this.invalidate(); - return this; -}; - Encoder.prototype.addStemmer = function (match, replace) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(match, replace); this.stemmer_str += (this.stemmer_str ? "|" : "") + match; - this.stemmer_test = null; //new RegExp("(" + this.stemmer_str + ")"); - this.cache && this.invalidate(); + this.stemmer_test = null; + this.cache && clear(this); return this; }; -Encoder.prototype.addFilter = function (str) { +Encoder.prototype.addFilter = function (term) { this.filter || (this.filter = new Set()); - this.filter.add(str); - this.cache && this.invalidate(); + this.filter.add(term); + this.cache && clear(this); return this; }; +/** + * Replace a single char + * @param {string} char_match + * @param {string} char_replace + * @return {Encoder} + * @suppress {invalidCasts} + */ Encoder.prototype.addMapper = function (char_match, char_replace) { // regex: if ("object" == typeof char_match) { - return this.addReplacer(char_match, char_replace); + return this.addReplacer( /** @type {RegExp} */char_match, char_replace); } // not a char: if (1 < char_match.length) { @@ -271,24 +279,55 @@ Encoder.prototype.addMapper = function (char_match, char_replace) { } this.mapper || (this.mapper = new Map()); this.mapper.set(char_match, char_replace); - this.cache && this.invalidate(); + this.cache && clear(this); return this; }; -Encoder.prototype.addReplacer = function (match, replace) { - if ("string" == typeof match) match = new RegExp(match, "g"); +/** + * Replace a string + * @param {string} match + * @param {string} replace + * @return {Encoder} + * @suppress {invalidCasts} + */ +Encoder.prototype.addMatcher = function (match, replace) { + // regex: + if ("object" == typeof match) { + return this.addReplacer( /** @type {RegExp} */match, replace); + } + // a single char: + // only downgrade when dedupe is on or mapper already was filled + if (2 > match.length && (this.dedupe || this.mapper)) { + return this.addMapper(match, replace); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(match, replace); + this.matcher_str += (this.matcher_str ? "|" : "") + match; + this.matcher_test = null; + this.cache && clear(this); + return this; +}; + +/** + * @param {RegExp} regex + * @param {string} replace + * @return {Encoder} + * @suppress {invalidCasts} + */ +Encoder.prototype.addReplacer = function (regex, replace) { + if ("string" == typeof regex) { + return this.addMatcher( /** @type {string} */regex, replace); + } this.replacer || (this.replacer = []); - this.replacer.push(match, replace || ""); - this.cache && this.invalidate(); + this.replacer.push(regex, replace); + this.cache && clear(this); return this; }; -Encoder.prototype.invalidate = function () { - this.cache_enc.clear(); - this.cache_term.clear(); -}; - - +/** + * @param {!string} str + * @return {!Array} + */ Encoder.prototype.encode = function (str) { //if(!str) return str; @@ -304,7 +343,7 @@ Encoder.prototype.encode = function (str) { } } - // 1. apply charset normalization + // apply charset normalization if (this.normalize) { if ("function" == typeof this.normalize) { str = this.normalize(str); @@ -315,12 +354,12 @@ Encoder.prototype.encode = function (str) { } } - // 2. apply custom encoder (can replace split) + // apply custom encoder (can replace split) if (this.prepare) { str = this.prepare(str); } - // 3. split numbers into triplets + // split numbers into triplets if (this.numeric && 3 < str.length) { str = str.replace(numeric_split_prev_char, "$1 $2").replace(numeric_split_next_char, "$1 $2").replace(numeric_split_length, "$1 "); } @@ -356,7 +395,7 @@ Encoder.prototype.encode = function (str) { continue; } - // 1. pre-filter before cache + // pre-filter before cache if (this.filter && this.filter.has(word)) { continue; } @@ -364,11 +403,8 @@ Encoder.prototype.encode = function (str) { if (this.cache && word.length <= this.cache_term_length) { if (this.timer) { const tmp = this.cache_term.get(word); - //if(this.cache_term.has(word)){ if (tmp || "" === tmp) { - //word = this.cache_term.get(word); tmp && final.push(tmp); - //word ? words[i] = word : words.splice(i--, 1); continue; } } else { @@ -376,9 +412,7 @@ Encoder.prototype.encode = function (str) { } } - let postfilter; - - // 2. apply stemmer after matcher + // apply stemmer after matcher if (this.stemmer && 2 < word.length) { // for(const item of this.stemmer){ // const key = item[0]; @@ -397,18 +431,15 @@ Encoder.prototype.encode = function (str) { // } this.stemmer_test || (this.stemmer_test = new RegExp("(?!^)(" + this.stemmer_str + ")$")); word = word.replace(this.stemmer_test, match => this.stemmer.get(match)); - postfilter = 1; + + // 4. post-filter after matcher and stemmer was applied + if (word.length < this.minlength || this.filter && this.filter.has(word)) { + word = ""; + } } - // 4. post-filter after matcher and stemmer was applied - if (word && postfilter && (word.length < this.minlength || this.filter && this.filter.has(word))) { - word = ""; - } - - // 5. apply mapper and collapsing + // apply mapper and collapsing if (word && (this.mapper || this.dedupe && 1 < word.length)) { - //word = this.replace_dedupe(word); - //word = replace_deduped(word, this.mapper, true); let final = ""; for (let i = 0, prev = "", char, tmp; i < word.length; i++) { char = word.charAt(i); @@ -420,11 +451,13 @@ Encoder.prototype.encode = function (str) { word = final; } - // 3. apply matcher + // from here the input string can shrink, + // minlength should not apply + + // apply matcher if (this.matcher && 1 < word.length) { this.matcher_test || (this.matcher_test = new RegExp("(" + this.matcher_str + ")", "g")); word = word.replace(this.matcher_test, match => this.matcher.get(match)); - //postfilter = 1; } // apply custom regex @@ -439,10 +472,6 @@ Encoder.prototype.encode = function (str) { //word = word.replace(/(.)\1+/g, "$1"); //word = word.replace(/(?<=(.))\1+/g, ""); - // if(word){ - // words[i] = word; - // } - if (this.cache && base.length <= this.cache_term_length) { this.cache_term.set(base, word); if (this.cache_term.size > this.cache_size) { @@ -451,20 +480,9 @@ Encoder.prototype.encode = function (str) { } } - //word || words.splice(i--, 1); word && final.push(word); } - //words = final; - // else if(this.filter){ - // for(let i = 0, word; i < words.length; i++){ - // if((word = words[i]) && !this.filter.has(word)){ - // //filtered.push(word); - // words.splice(i--, 1); - // } - // } - // } - if (this.finalize) { final = this.finalize(final) || final; } @@ -513,6 +531,9 @@ Encoder.prototype.encode = function (str) { // return str; // } +/** + * @param {Encoder} self + */ function clear(self) { self.timer = null; self.cache_enc.clear(); diff --git a/dist/module-debug/index.js b/dist/module-debug/index.js index 72ed87e..420f860 100644 --- a/dist/module-debug/index.js +++ b/dist/module-debug/index.js @@ -133,11 +133,14 @@ Index.prototype.clear = function () { * @param {!number|string} id * @param {!string} content */ - Index.prototype.append = function (id, content) { return this.add(id, content, !0); }; +/** + * @param {number|string} id + * @return {boolean|Promise} + */ Index.prototype.contain = function (id) { return this.db ? this.db.has(id) : this.reg.has(id); }; diff --git a/dist/module-debug/index/remove.js b/dist/module-debug/index/remove.js index b79ad2c..481d4ae 100644 --- a/dist/module-debug/index/remove.js +++ b/dist/module-debug/index/remove.js @@ -1,12 +1,11 @@ -import { create_object, is_array } from "../common.js"; +import { is_array } from "../common.js"; import Index, { autoCommit } from "../index.js"; -import default_compress from "../compress.js"; /** + * @param {!number|string} id * @param {boolean=} _skip_deletion */ - Index.prototype.remove = function (id, _skip_deletion) { const refs = this.reg.size && (this.fastupdate ? this.reg.get(id) : this.reg.has(id)); @@ -15,7 +14,7 @@ Index.prototype.remove = function (id, _skip_deletion) { if (this.fastupdate) { - // fast updates did not fully cleanup the key entries + // fast updates did not fully clean up the key entries for (let i = 0, tmp; i < refs.length; i++) { if (tmp = refs[i]) { @@ -95,8 +94,8 @@ Index.prototype.remove = function (id, _skip_deletion) { }; /** - * @param map - * @param id + * @param {!Map|Array>} map + * @param {!number|string} id * @return {number} */ @@ -125,7 +124,7 @@ function remove_index(map, id) { } } } - } else for (let item of map) { + } else for (let item of map.entries()) { const key = item[0], value = item[1], tmp = remove_index(value, id); diff --git a/dist/module-debug/index/search.js b/dist/module-debug/index/search.js index 895297d..b3ab191 100644 --- a/dist/module-debug/index/search.js +++ b/dist/module-debug/index/search.js @@ -1,6 +1,6 @@ -import { SearchOptions, SearchResults, EnrichedSearchResults } from "../type.js"; +import { SearchOptions, SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; import { create_object, is_object, sort_by_length_down } from "../common.js"; import Index from "../index.js"; import default_compress from "../compress.js"; @@ -8,18 +8,21 @@ import Resolver from "../resolver.js"; import { intersect } from "../intersect.js"; import resolve_default from "../resolve/default.js"; -let global_resolve = 1; -export function set_resolve(resolve) { - global_resolve = resolve; -} +// todo remove +// let global_resolve = 1; +// export function set_resolve(resolve){ +// global_resolve = resolve; +// } /** * @param {string|SearchOptions} query * @param {number|SearchOptions=} limit * @param {SearchOptions=} options - * @returns {SearchResults|EnrichedSearchResults|Resolver|Promise} + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } */ - Index.prototype.search = function (query, limit, options) { if (!options) { @@ -32,16 +35,20 @@ Index.prototype.search = function (query, limit, options) { } } + /** @type {!Array} */ let result = [], length, context, suggest, offset = 0, resolve, - enrich, tag, boost, - resolution; + resolution, + + // enrich is internally used just + // for the persistent indexes + enrich; if (options) { @@ -50,14 +57,14 @@ Index.prototype.search = function (query, limit, options) { offset = options.offset || 0; context = options.context; suggest = options.suggest; - resolve = global_resolve && /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; - resolve || (global_resolve = 0); + resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + //resolve || (global_resolve = 0); enrich = resolve && options.enrich; boost = options.boost; resolution = options.resolution; tag = this.db && options.tag; } else { - resolve = this.resolve || global_resolve; + resolve = this.resolve; // || global_resolve; } // todo: term deduplication during encoding when context is disabled @@ -67,7 +74,7 @@ Index.prototype.search = function (query, limit, options) { /** @type {Array} */ let query_terms = this.encoder.encode(query); length = query_terms.length; - limit || !resolve || (limit = 100); + limit = /** @type {!number} */limit || (resolve ? 100 : 0); // fast path single term if (1 === length) { @@ -88,79 +95,98 @@ Index.prototype.search = function (query, limit, options) { limit, offset, resolve, enrich, tag); } - let maxlength = 0, - minlength = 0; + // let maxlength = 0; + // let minlength = 0; + // + // if(length > 1){ + // + // // term deduplication will break the context chain + // // todo add context to dupe check + // const dupes = create_object(); + // const query_new = []; + // + // // if(context){ + // // keyword = query_terms[0]; + // // dupes[keyword] = 1; + // // query_new.push(keyword); + // // maxlength = minlength = keyword.length; + // // i = 1; + // // } + // + // for(let i = 0, term; i < length; i++){ + // + // term = query_terms[i]; + // + // if(term && !dupes[term]){ + // + // // todo add keyword check + // // this fast path can't apply to persistent indexes + // if(!suggest && !(SUPPORT_PERSISTENT && this.db) && !this.get_array(term/*, keyword*/)){ + // + // // fast path "not found" + // return !SUPPORT_RESOLVER || resolve + // ? result + // : new Resolver(result); + // } + // else{ + // + // query_new.push(term); + // dupes[term] = 1; + // } + // + // const term_length = term.length; + // maxlength = Math.max(maxlength, term_length); + // minlength = minlength ? Math.min(minlength, term_length) : term_length; + // } + // // else if(term && (!this.depth || context === false)){ + // // query_new.push(term); + // // } + // } + // + // query_terms = query_new; + // length = query_terms.length; + // } + // + // // the term length could be changed after deduplication + // + // if(!length){ + // return !SUPPORT_RESOLVER || resolve + // ? result + // : new Resolver(result); + // } + // + // // fast path single term + // if(length === 1){ + // return single_term_query.call( + // this, + // query_terms[0], // term + // "", // ctx + // limit, + // offset, + // resolve, + // enrich, + // tag + // ); + // } + // + // // fast path single context + // if(length === 2 && context && !suggest){ + // return single_term_query.call( + // this, + // query_terms[0], // term + // query_terms[1], // ctx + // limit, + // offset, + // resolve, + // enrich, + // tag + // ); + // } - - if (1 < length) { - - // term deduplication will break the context chain - // todo add context to dupe check - const dupes = create_object(), - query_new = []; - - - // if(context){ - // keyword = query_terms[0]; - // dupes[keyword] = 1; - // query_new.push(keyword); - // maxlength = minlength = keyword.length; - // i = 1; - // } - - for (let i = 0, term; i < length; i++) { - - term = query_terms[i]; - - if (term && !dupes[term]) { - - // todo add keyword check - // this fast path can't apply to persistent indexes - if (!suggest && !this.db && !this.get_array(term /*, keyword*/)) { - - // fast path "not found" - return resolve ? result : new Resolver(result); - } else { - - query_new.push(term); - dupes[term] = 1; - } - - const term_length = term.length; - maxlength = Math.max(maxlength, term_length); - minlength = minlength ? Math.min(minlength, term_length) : term_length; - } - // else if(term && (!this.depth || context === false)){ - // query_new.push(term); - // } - } - - query_terms = query_new; - length = query_terms.length; - } - - // the term length could be changed after deduplication - - if (!length) { - return resolve ? result : new Resolver(result); - } - - let index = 0, + let dupes = create_object(), + index = 0, keyword; - // fast path single term - if (1 === length) { - return single_term_query.call(this, query_terms[0], // term - "", // ctx - limit, offset, resolve, enrich, tag); - } - - // fast path single context - if (2 === length && context && !suggest) { - return single_term_query.call(this, query_terms[0], // term - query_terms[1], // ctx - limit, offset, resolve, enrich, tag); - } if (1 < length) { if (context) { @@ -169,17 +195,17 @@ Index.prototype.search = function (query, limit, options) { index = 1; } // todo - else if (9 < maxlength && 3 < maxlength / minlength) { - // sorting terms will break the context chain - // bigger terms has less occurrence - // this might also reduce the intersection task - // todo check intersection order - query_terms.sort(sort_by_length_down); - } + // else if(maxlength > 9 && (maxlength / minlength) > 3){ + // // sorting terms will break the context chain + // // bigger terms has less occurrence + // // this might also reduce the intersection task + // // todo check intersection order + // query_terms.sort(sort_by_length_down); + // } } if (!resolution && 0 !== resolution) { - resolution = this.resolution; + resolution = keyword ? this.resolution_ctx : this.resolution; } // from this point there are just multi-term queries @@ -199,56 +225,40 @@ Index.prototype.search = function (query, limit, options) { term = query_terms[index]; - if (keyword) { + if (term && !dupes[term]) { + dupes[term] = 1; arr = await self.get_array(term, keyword, 0, 0, !1, !1); - arr = add_result(arr, result, suggest, self.resolution_ctx - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 2 - // /*, term, keyword*/ - ); + arr = add_result(arr, /** @type {Array} */result, suggest, resolution); - // the context is a moving window where the keyword is going forward like a cursor - // 1. when suggestion enabled just forward keyword if term was found - // 2. as long as the result is empty forward the pointer also - if (!suggest || !1 !== arr || !result.length) { - keyword = term; + if (arr) { + result = arr; + break; } - } else { - arr = await self.get_array(term, "", 0, 0, !1, !1); - arr = add_result(arr, result, suggest, resolution - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 1 - // /*, term*/ - ); - } + if (keyword) { - // limit reached - if (arr) { - return arr; - } - - // apply suggestions on last loop - if (suggest && index == length - 1) { - let length = result.length; - if (!length) { - // fallback to non-contextual search when no result was found - if (keyword) { - keyword = ""; - index = -1; - continue; + // the context is a moving window where the keyword is going forward like a cursor + // 1. when suggestion enabled just forward keyword if term was found + // 2. as long as the result is empty forward the pointer also + if (!suggest || !arr || !result.length) { + keyword = term; } - return result; - } else if (1 === length) { - return resolve ? resolve_default(result[0], /** @type {number} */limit, offset) : new Resolver(result[0]); + } + } + + // fallback to non-contextual search when no result was found + if (suggest && keyword && index == length - 1) { + if (!result.length) { + keyword = ""; + index = -1; + dupes = create_object(); } } } - return resolve ? intersect(result, resolution, /** @type {number} */limit, offset, suggest, boost, resolve) : new Resolver(result[0]); + return return_result(result, resolution, + /** @type {!number} */limit, offset, suggest, boost, resolve); }(); } @@ -256,84 +266,97 @@ Index.prototype.search = function (query, limit, options) { term = query_terms[index]; - if (keyword) { + if (term && !dupes[term]) { + dupes[term] = 1; arr = this.get_array(term, keyword, 0, 0, !1, !1); - arr = /*this.*/add_result(arr, result, suggest, this.resolution_ctx - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 2 - // /*, term, keyword*/ - ); + arr = add_result(arr, /** @type {Array} */result, suggest, resolution); - // 1. when suggestion enabled just forward keyword if term was found - // 2. as long as the result is empty forward the pointer also - if (!suggest || !1 !== arr || !result.length) { - keyword = term; + if (arr) { + result = arr; + break; } - } else { - arr = this.get_array(term, "", 0, 0, !1, !1); - arr = /*this.*/add_result(arr, result, suggest, resolution - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 1 - // /*, term*/ - ); - } + if (keyword) { - // limit reached - if (arr) { - return (/** @type {Array} */arr - ); - } - - // apply suggestions on last loop - if (suggest && index == length - 1) { - const length = result.length; - if (!length) { - // fallback to non-contextual search when no result was found - if (keyword) { - keyword = ""; - index = -1; - continue; + // the context is a moving window where the keyword is going forward like a cursor + // 1. when suggestion enabled just forward keyword if term was found + // 2. as long as the result is empty forward the pointer also + if (!suggest || !arr || !result.length) { + keyword = term; } - return result; - } else if (1 === length) { - return resolve ? resolve_default(result[0], /** @type {number} */limit, offset) : new Resolver(result[0]); + } + } + + // fallback to non-contextual search when no result was found + if (suggest && keyword && index == length - 1) { + if (!result.length) { + keyword = ""; + index = -1; + dupes = create_object(); } } } - result = intersect(result, resolution, limit, offset, suggest, boost, resolve); - - return resolve ? result : new Resolver(result); + return return_result(result, resolution, + /** @type {!number} */limit, offset, suggest, boost, resolve); }; /** - * @param term - * @param keyword - * @param limit - * @param offset - * @param resolve - * @param enrich - * @param tag + * @param {!Array} result + * @param {number} resolution + * @param {number} limit + * @param {number=} offset + * @param {boolean=} suggest + * @param {number=} boost + * @param {boolean=} resolve + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } + */ + +function return_result(result, resolution, limit, offset, suggest, boost, resolve) { + let length = result.length, + final = result; + + + if (1 < length) { + final = intersect(result, resolution, /** @type {number} */limit, offset, suggest, boost, resolve); + } else if (1 === length) { + return resolve ? resolve_default.call(null, result[0], /** @type {number} */limit, offset) : new Resolver(result[0]); + } + + return resolve ? final : new Resolver(final); +} + +/** + * @param {!string} term + * @param {string|null} keyword + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @param {string=} tag * @this {Index} - * @return {Array|Resolver} + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } */ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag); + resolve = resolve; if (this.db) { return result.then(function (result) { - if (resolve) return result; - return result && result.length ? resolve ? resolve_default(result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver([]); + return resolve ? result || [] : new Resolver(result); }); } - return result && result.length ? resolve ? resolve_default(result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver([]); + return result && result.length ? resolve ? resolve_default.call(this, /** @type {SearchResults|EnrichedSearchResults} */result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver(); } /** @@ -342,69 +365,34 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { * or returns nothing when a set was pushed successfully to the results * * @private - * @param {Array} arr - * @param {Array} result - * @param {boolean|null=} suggest + * @param {IntermediateSearchResults} arr + * @param {Array} result + * @param {boolean=} suggest * @param {number=} resolution - * @return {Array|boolean|undefined} + * @return {Array|undefined} */ -function add_result(arr, result, suggest, resolution /*, limit, offset single_term, term, keyword*/) { +function add_result(arr, result, suggest, resolution) { let word_arr = []; - //let arr;// = keyword ? this.ctx : this.map; - //arr = this.get_array(term, keyword); - if (arr) { + if (arr && arr.length) { + + // short when resolution does not exceed: + if (arr.length <= resolution) { + result.push(arr); + // return nothing will continue the query + return; + } - //const resolution = Math.min(arr.length, keyword ? this.resolution_ctx : this.resolution); // apply reduced resolution for queries - resolution = Math.min(arr.length, resolution); - for (let x = 0, tmp; x < resolution; x++) { if (tmp = arr[x]) { - - // if(offset){ - // // apply offset right here on single terms - // if(tmp && single_term){ - // if(tmp.length <= offset){ - // offset -= tmp.length; - // tmp = null; - // } - // else{ - // tmp = tmp.slice(offset); - // offset = 0; - // } - // } - // } - - if (tmp) { - - // keep score (sparse array): - word_arr[x] = tmp; - // simplified score order: - //word_arr.push(tmp); - - // if(single_term){ - // size += tmp.length; - // if(size >= limit){ - // // fast path: - // // a single term does not need to pre-collect results - // break; - // } - // } - } + word_arr[x] = tmp; } } if (word_arr.length) { - // if(single_term){ - // // fast path optimization - // // offset was already applied at this point - // // return an array will stop the query process immediately - // return resolve_default(word_arr, limit, 0); - // } - result.push(word_arr); // return nothing will continue the query return; @@ -413,15 +401,33 @@ function add_result(arr, result, suggest, resolution /*, limit, offset single_te // 1. return an empty array will stop the loop // 2. return a false value to prevent stop when using suggestions - return !suggest && word_arr; + if (!suggest) return word_arr; } +/** + * @param {!string} term + * @param {string|null} keyword + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @param {string=} tag + * @return { + * IntermediateSearchResults|EnrichedSearchResults | + * Promise + * } + */ Index.prototype.get_array = function (term, keyword, limit, offset, resolve, enrich, tag) { let arr, swap; if (keyword) { swap = this.bidirectional && term > keyword; + if (swap) { + swap = keyword; + keyword = term; + term = swap; + } } if (this.compress) { @@ -430,18 +436,15 @@ Index.prototype.get_array = function (term, keyword, limit, offset, resolve, enr } if (this.db) { - return keyword ? this.db.get(swap ? keyword : term, // term - swap ? term : keyword, // ctx - limit, offset, resolve, enrich, tag) : this.db.get(term, "", // ctx - limit, offset, resolve, enrich, tag); + return this.db.get(term, keyword, limit, offset, resolve, enrich, tag); } if (keyword) { // the frequency of the starting letter is slightly less // on the last half of the alphabet (m-z) in almost every latin language, // so we sort downwards (https://en.wikipedia.org/wiki/Letter_frequency) - arr = this.ctx.get(swap ? term : keyword); - arr = arr && arr.get(swap ? keyword : term); + arr = this.ctx.get(keyword); + arr = arr && arr.get(term); } else { arr = this.map.get(term); } diff --git a/dist/module-debug/intersect.js b/dist/module-debug/intersect.js index f6e00a4..c5110f9 100644 --- a/dist/module-debug/intersect.js +++ b/dist/module-debug/intersect.js @@ -1,5 +1,6 @@ import { create_object, concat, sort_by_length_up, get_max_len } from "./common.js"; +import { SearchResults, IntermediateSearchResults } from "./type.js"; /* @@ -13,20 +14,20 @@ import { create_object, concat, sort_by_length_up, get_max_len } from "./common. */ /** - * @param arrays + * @param {!Array} arrays * @param {number} resolution - * @param limit - * @param offset - * @param suggest + * @param {number} limit + * @param {number=} offset + * @param {boolean=} suggest * @param {number=} boost * @param {boolean=} resolve - * @returns {Array} + * @returns {SearchResults|IntermediateSearchResults} */ - export function intersect(arrays, resolution, limit, offset, suggest, boost, resolve) { const length = arrays.length; + /** @type {Array} */ let result = [], check, count; @@ -71,7 +72,7 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res if (!resolve) { // boost everything after first result - let score = y + (x ? 0 : boost || 0); + let score = y + (x || !suggest ? 0 : boost || 0); tmp = tmp[score] || (tmp[score] = []); } @@ -95,7 +96,7 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res return []; } - result = result[result_len - 1]; + result = /** @type {SearchResults|IntermediateSearchResults} */result[result_len - 1]; if (limit || offset) { if (resolve) { @@ -123,36 +124,49 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res result = 1 < final.length ? concat(final) : final[0]; } - return result; + return (/** @type {SearchResults|IntermediateSearchResults} */result + ); } } else { - result = 1 < result.length ? union(result, offset, limit, resolve, 0) : (result = result[0]).length > limit || offset ? result.slice(offset, limit + offset) : result; + result = 1 < result.length ? union(result, limit, offset, resolve, boost) : (result = result[0]).length > limit || offset ? result.slice(offset, limit + offset) : result; } } - return result; + return (/** @type {SearchResults|IntermediateSearchResults} */result + ); } -export function union(arrays, offset, limit, resolve, boost) { +/** + * @param {Array} arrays + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {number=} boost + * @returns {SearchResults|IntermediateSearchResults} + */ +export function union(arrays, limit, offset, resolve, boost) { + + /** @type {SearchResults|IntermediateSearchResults} */ const result = [], check = create_object(); let ids, id, arr_len = arrays.length, - ids_len, - count = 0; + ids_len; + + //let maxres = get_max_len(arrays); if (!resolve) { - let maxres = get_max_len(arrays); + for (let i = arr_len - 1, res, count = 0; 0 <= i; i--) { - for (let k = 0; k < maxres; k++) { + res = arrays[i]; - for (let i = arr_len - 1; 0 <= i; i--) { + for (let k = 0; k < res.length; k++) { - ids = arrays[i][k]; + ids = res[k]; ids_len = ids && ids.length; if (ids_len) for (let j = 0; j < ids_len; j++) { @@ -164,8 +178,14 @@ export function union(arrays, offset, limit, resolve, boost) { if (offset) { offset--; } else { - let score = k + (i < arr_len - 1 ? boost || 0 : 0); - const arr = result[score] || (result[score] = []); + // adjust score to reduce resolution of suggestions + // todo: instead of applying the resolve task directly it could + // be added to the chain and resolved later, that will keep + // the original score but also can't resolve early because of + // nothing was found + let score = 0 | (k + (i < arr_len - 1 ? boost || 0 : 0)) / (i + 1), + arr = result[score] || (result[score] = []); + arr.push(id); if (++count === limit) { return result; @@ -175,26 +195,23 @@ export function union(arrays, offset, limit, resolve, boost) { } } } - } else { + } else for (let i = arr_len - 1; 0 <= i; i--) { - for (let i = arr_len - 1; 0 <= i; i--) { + ids = arrays[i]; + ids_len = ids && ids.length; - ids = arrays[i]; - ids_len = ids.length; + if (ids_len) for (let j = 0; j < ids_len; j++) { - for (let j = 0; j < ids_len; j++) { + id = ids[j]; - id = ids[j]; - - if (!check[id]) { - check[id] = 1; - if (offset) { - offset--; - } else { - result.push(id); - if (result.length === limit) { - return result; - } + if (!check[id]) { + check[id] = 1; + if (offset) { + offset--; + } else { + result.push(id); + if (result.length === limit) { + return result; } } } @@ -205,28 +222,42 @@ export function union(arrays, offset, limit, resolve, boost) { } /** - * @param {Array} mandatory - * @param {Array>} arrays - * @returns {Array} + * @param {SearchResults|IntermediateSearchResults} arrays + * @param {Array} mandatory + * @param {boolean=} resolve + * @returns {SearchResults} */ - -export function intersect_union(mandatory, arrays) { +export function intersect_union(arrays, mandatory, resolve) { const check = create_object(), result = []; + /** @type {SearchResults|IntermediateSearchResults} */ - - for (let x = 0, ids; x < arrays.length; x++) { - ids = arrays[x]; + for (let x = 0, ids; x < mandatory.length; x++) { + ids = mandatory[x]; for (let i = 0; i < ids.length; i++) { check[ids[i]] = 1; } } - for (let i = 0, id; i < mandatory.length; i++) { - id = mandatory[i]; - if (1 === check[id]) { - result.push(id); - check[id] = 2; + if (resolve) { + for (let i = 0, id; i < arrays.length; i++) { + id = arrays[i]; + if (check[id]) { + result.push(id); + check[id] = 0; + } + } + } else { + for (let i = 0, ids, id; i < arrays.result.length; i++) { + ids = arrays.result[i]; + for (let j = 0; j < ids.length; j++) { + id = ids[j]; + if (check[id]) { + const arr = result[i] || (result[i] = []); + arr.push(id); + check[id] = 0; + } + } } } diff --git a/dist/module-debug/profiler.js b/dist/module-debug/profiler.js index 560c690..6be5ade 100644 --- a/dist/module-debug/profiler.js +++ b/dist/module-debug/profiler.js @@ -1,3 +1,4 @@ + import { create_object } from "./common.js"; const data = create_object(); @@ -5,11 +6,4 @@ const data = create_object(); * @param {!string} name */ -export default function tick(name) { - - /** @type {!Object} */ - const profiler = data.profiler || (data.profiler = {}); - - profiler[name] || (profiler[name] = 0); - profiler[name]++; -} \ No newline at end of file +export default function tick() {} \ No newline at end of file diff --git a/dist/module-debug/resolve/and.js b/dist/module-debug/resolve/and.js index 40e09cd..1929674 100644 --- a/dist/module-debug/resolve/and.js +++ b/dist/module-debug/resolve/and.js @@ -1,202 +1,105 @@ import Resolver from "../resolver.js"; -import { create_object, get_max_len } from "../common.js"; -import { intersect as _intersect } from "../intersect.js"; -import { ResolverOptions } from "../type.js"; +import { get_max_len } from "../common.js"; +import { intersect } from "../intersect.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, ResolverOptions } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +/** @this {Resolver} */ Resolver.prototype.and = function () { - if (this.result.length) { - - const self = this; - let args = arguments, - first_argument = args[0]; + let execute = this.result.length, + limit, + offset, + enrich, + resolve; - if (first_argument.then) { - return first_argument.then(function () { - return self.and.apply(self, args); - }); + if (!execute) { + /** @type {ResolverOptions} */ + const arg = arguments[0]; + if (arg) { + execute = !!arg.suggest; + resolve = arg.resolve; + limit = arg.limit; + offset = arg.offset; + enrich = arg.enrich && resolve; } + } - if (first_argument[0]) { - // fix false passed parameter style - if (first_argument[0].index) { - return this.and.apply(this, first_argument); - } - } + if (execute) { - let final = [], - promises = [], - limit = 0, - offset = 0, + const { + final, + promises, + limit, + offset, enrich, resolve, - suggest; + suggest + } = this.handler("and", arguments); - - for (let i = 0, query; i < args.length; i++) { - - query = /** @type {string|ResolverOptions} */args[i]; - - if (query) { - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - suggest = query.suggest; - - let result; - if (query.constructor === Resolver) { - result = query.result; - } else if (query.constructor === Array) { - result = query; - } else if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; - result = query.index.search(query).result; - } else if (query.or) { - result = this.or(query.or); - } else if (query.xor) { - result = this.xor(query.xor); - } else if (query.not) { - result = this.not(query.not); - } else { - continue; - } - - final[i] = result; - - if (result.then) { - promises.push(result); //{ query, result }; - } - } - } - - if (!final.length) { - this.result = final; - return resolve ? this.result : this; - } - - if (promises.length) { - return Promise.all(promises).then(function () { - final = [self.result].concat(final); - self.result = intersect(final, limit, offset, enrich, resolve, self.boostval, suggest); - return resolve ? self.result : self; - }); - } - - final = [this.result].concat(final); - this.result = intersect(final, limit, offset, enrich, resolve, this.boostval, suggest); - return resolve ? this.result : this; + return return_result.call(this, final, promises, limit, offset, enrich, resolve, suggest); } - return this; + + return resolve ? this.resolve(limit, offset, enrich) : this; }; /** * Aggregate the intersection of N raw results - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @param suggest - * @return {Array} + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } */ -function intersect(result, limit, offset, enrich, resolve, boost, suggest) { +function return_result(final, promises, limit, offset, enrich, resolve, suggest) { - // if(!result.length){ - // // todo remove - // console.log("Empty Result") - // return result; - // } + if (promises.length) { + const self = this; + return Promise.all(promises).then(function (result) { - if (2 > result.length) { - return []; + final = []; + for (let i = 0, tmp; i < result.length; i++) { + if ((tmp = result[i]).length) { + final[i] = tmp; + } + } + + return return_result.call(self, final, [], limit, offset, enrich, resolve, suggest); + }); } - let contain = create_object(), - maxres = get_max_len(result); + if (!final.length) { + if (!suggest) { + this.result = /** @type {SearchResults|IntermediateSearchResults} */final; + } + } else { + //final = [this.result].concat(final); + this.result.length && final.unshift(this.result); - if (!maxres) return []; + if (2 > final.length) { + this.result = final[0]; + } else { + const resolution = get_max_len(final); + if (!resolution) { + this.result = []; + } else { + this.result = intersect(final, resolution, limit, offset, suggest, this.boostval, resolve); - //console.log(result) + return resolve ? enrich ? apply_enrich.call(this.index, /** @type {SearchResults} */this.result) : this.result : this; + } + } + } - return _intersect(result, maxres, limit, offset, suggest, boost, resolve); - - // for(let j = 0, ids, res = result[0]; j < res.length; j++){ - // ids = res[j]; - // for(let k = 0; k < ids.length; k++){ - // contain[ids[k]] = 1; - // } - // } - - // for(let i = 0, res; i < result.length; i++){ - // res = result[i]; - // if(!res || !res.length) return []; - // let contain_new = create_object(); - // let match = 0; - // let last_round = i === result.length - 1; - // - // for(let j = 0, ids; j < maxres; j++){ - // ids = res[j]; - // if(!ids) continue; - // - // for(let k = 0, id, min; k < ids.length; k++){ - // id = ids[k]; - // // fill in first round - // if(!i){ - // // shift resolution +1 - // // shift resolution by boost (inverse) - // contain_new[id] = j + 1 + (i ? boost : 0); - // match = 1; - // } - // // result in last round - // else if(last_round){ - // if((min = contain[id])){ - // match = 1; - // //if(!contain_new[id]){ - // if(offset){ - // offset--; - // continue; - // } - // if(resolve){ - // final.push(id); - // } - // else{ - // // reduce resolution -1 - // min--; - // if(j < min) min = j; - // final[min] || (final[min] = []); - // final[min].push(id); - // } - // if(limit && ++count === limit){ - // //this.boost = 0; - // return final; - // } - // // shift resolution +1 - // //contain_new[id] = min + 1; - // //} - // } - // } - // // check for intersection - // else if((min = contain[id])){ - // // shift resolution +1 - // if(j + 1 < min) min = j + 1; - // contain_new[id] = min; - // match = 1; - // } - // } - // } - // - // if(!match){ - // //this.boost = 0; - // return []; - // } - // - // contain = contain_new; - // } - // - // //this.boost = 0; - // return final; + return resolve ? this.resolve(limit, offset, enrich) : this; } \ No newline at end of file diff --git a/dist/module-debug/resolve/default.js b/dist/module-debug/resolve/default.js index ae75ab0..c280c35 100644 --- a/dist/module-debug/resolve/default.js +++ b/dist/module-debug/resolve/default.js @@ -1,4 +1,8 @@ import { concat } from "../common.js"; +import { IntermediateSearchResults, SearchResults, EnrichedSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +import Document from "../document.js"; +import Index from "../index.js"; /* from -> res[score][id] @@ -7,44 +11,29 @@ import { concat } from "../common.js"; /** * Aggregate the union of a single raw result - * @param {!Array} result + * @param {IntermediateSearchResults} result * @param {!number} limit * @param {number=} offset * @param {boolean=} enrich - * @return Array + * @return {SearchResults|EnrichedSearchResults} + * @this {Document|Index} */ export default function (result, limit, offset, enrich) { + if (!result.length) { + return result; + } + // fast path: when there is just one slot in the result if (1 === result.length) { - result = result[0]; - result = offset || result.length > limit ? limit ? result.slice(offset, offset + limit) : result.slice(offset) : result; - return enrich ? enrich_result(result) : result; + let final = result[0]; + final = offset || final.length > limit ? limit ? final.slice(offset, offset + limit) : final.slice(offset) : final; + return enrich ? apply_enrich.call(this, final) : final; } let final = []; - // this is a workaround without using arr.concat.apply - - // for(let i = 0, arr, len; i < result.length; i++){ - // if((arr = result[i])){ - // if((len = arr.length)){ - // for(let j = offset; j < len; j++){ - // final.push(arr[j]); - // if(final.length === limit){ - // return enrich - // ? enrich_result(final) - // : final; - // } - // } - // if((offset -= len) < 0){ - // offset = 0; - // } - // } - // } - // } - // this is an optimized workaround instead of // just doing result = concat(result) @@ -65,52 +54,47 @@ export default function (result, limit, offset, enrich) { } } + if (len > limit) { + arr = arr.slice(0, limit); + len = limit; + } + if (!final.length) { // fast path: when limit was reached in first slot if (len >= limit) { - if (len > limit) { - arr = arr.slice(0, limit); - } - return enrich ? enrich_result(arr) : arr; - } - } else { - if (len > limit) { - arr = arr.slice(0, limit); - len = arr.length; + return enrich ? apply_enrich.call(this, arr) : arr; } } final.push(arr); limit -= len; - // todo remove - // if(limit < 0){ - // throw new Error("Impl.Error"); - // } - // break if limit was reached if (!limit) { break; } } - // todo remove - if (!final.length) { - //throw new Error("No results found"); - return final; - } - final = 1 < final.length ? concat(final) : final[0]; - return enrich ? enrich_result(final) : final; + return enrich ? apply_enrich.call(this, final) : final; } -function enrich_result(ids) { - for (let i = 0; i < ids.length; i++) { - ids[i] = { - score: i, - id: ids[i] - }; - } - return ids; -} \ No newline at end of file +// /** +// * @param {SearchResults} ids +// * @return {EnrichedSearchResults} +// */ +// +// export function enrich_result(ids){ +// // ids could be the original reference to an index value +// /** @type {EnrichedSearchResults} */ +// const result = new Array(ids.length); +// for(let i = 0, id; i < ids.length; i++){ +// id = ids[i]; +// result[i] = { +// "id": id, +// "doc": this.store.get(id) +// }; +// } +// return result; +// } \ No newline at end of file diff --git a/dist/module-debug/resolve/handler.js b/dist/module-debug/resolve/handler.js new file mode 100644 index 0000000..fff9a16 --- /dev/null +++ b/dist/module-debug/resolve/handler.js @@ -0,0 +1,99 @@ + +import Resolver from "../resolver.js"; +import { ResolverOptions, SearchResults, IntermediateSearchResults } from "../type.js"; + +/** + * @param {string} fn + * @param {Array>|Arguments} args + */ +Resolver.prototype.handler = function (fn, args) { + + /** @type {ResolverOptions|Promise} */ + let first_argument = args[0]; + + if (first_argument.then) { + const self = this; + // todo: check when this branch was taken + // instead of Promise.all the args[] array could be reduced + // by iterate recursively one by one + return Promise.all(args).then(function (args) { + return self[fn].apply(self, args); + }); + } + + if (first_argument[0]) { + // detect array parameter style + if (first_argument[0].index) { + return this[fn].apply(this, first_argument); + } + } + + /** @type {SearchResults|IntermediateSearchResults} */ + let final = [], + promises = [], + limit = 0, + offset = 0, + enrich, + resolve, + suggest; + /** @type {Array>} */ + + for (let i = 0, query; i < args.length; i++) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { + + let result; + if (query.constructor === Resolver) { + result = query.result; + } else if (query.constructor === Array) { + result = query; + } else { + + limit = query.limit || 0; + offset = query.offset || 0; + suggest = query.suggest; + resolve = query.resolve; + enrich = query.enrich && resolve; + + if (query.index) { + query.resolve = /* suggest */ /* append: */ /* enrich */!1; + query.enrich = !1; + result = query.index.search(query).result; + query.resolve = resolve; + query.enrich = enrich; + } else if (query.and) { + result = this.and(query.and); + } else if (query.or) { + result = this.or(query.or); + } else if (query.xor) { + result = this.xor(query.xor); + } else if (query.not) { + result = this.not(query.not); + } else { + continue; + } + } + + if (result.then) { + promises.push(result); + } else if (result.length) { + final[i] = result; + } else if (!suggest && ("and" === fn || "xor" === fn)) { + final = []; + break; + } + } + } + + return { + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + }; +}; \ No newline at end of file diff --git a/dist/module-debug/resolve/not.js b/dist/module-debug/resolve/not.js index 9f3839f..9466752 100644 --- a/dist/module-debug/resolve/not.js +++ b/dist/module-debug/resolve/not.js @@ -1,98 +1,83 @@ import Resolver from "../resolver.js"; -import { ResolverOptions } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +/** @this {Resolver} */ Resolver.prototype.not = function () { - const self = this; - let args = arguments, - first_argument = args[0]; + const { + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + } = this.handler("not", arguments); - if (first_argument.then) { - return first_argument.then(function () { - return self.not.apply(self, args); - }); - } - - if (first_argument[0]) { - // fix false passed parameter style - if (first_argument[0].index) { - return this.not.apply(this, first_argument); - } - } - - let final = [], - promises = [], - limit = 0, - offset = 0, - resolve; - - - for (let i = 0, query; i < args.length; i++) { - - query = /** @type {string|ResolverOptions} */args[i]; - - if (query) { - - limit = query.limit || 0; - offset = query.offset || 0; - query.enrich; - resolve = query.resolve; - - let result; - if (query.constructor === Resolver) { - result = query.result; - } else if (query.constructor === Array) { - result = query; - } else if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; - result = query.index.search(query).result; - } else if (query.or) { - result = this.or(query.or); - } else if (query.and) { - result = this.and(query.and); - } else if (query.xor) { - result = this.xor(query.xor); - } else { - continue; - } - - final[i] = result; - - if (result.then) { - promises.push(result); //{ query, result }; - } - } - } - - if (promises.length) { - return Promise.all(promises).then(function () { - self.result = exclusion.call(self, final, limit, offset, resolve); - return resolve ? self.result : self; - }); - } - - if (final.length) { - this.result = exclusion.call(this, final, limit, offset, resolve); - } - - return resolve ? this.result : this; + return return_result.call(this, final, promises, limit, offset, enrich, resolve, suggest); }; /** - * @param result - * @param limit - * @param offset - * @param resolve + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest * @this {Resolver} - * @return {Array} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } + */ + +function return_result(final, promises, limit, offset, enrich, resolve, suggest) { + + if (promises.length) { + const self = this; + return Promise.all(promises).then(function (result) { + + final = []; + for (let i = 0, tmp; i < result.length; i++) { + if ((tmp = result[i]).length) { + final[i] = tmp; + } + } + + return return_result.call(self, final, [], limit, offset, enrich, resolve, suggest); + }); + } + + if (final.length && this.result.length) { + this.result = exclusion.call(this, final, limit, offset, resolve); + } else if (resolve) { + return this.resolve(limit, offset, enrich); + } + + return resolve ? enrich ? apply_enrich.call(this.index, this.result) : this.result : this; +} + +/** + * @param {!Array} result + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @this {Resolver} + * @return {SearchResults|IntermediateSearchResults} */ function exclusion(result, limit, offset, resolve) { - if (!result.length) { - return this.result; - } + // if(!result.length){ + // return this.result; + // } + /** @type {SearchResults|IntermediateSearchResults} */ const final = [], exclude = new Set(result.flat().flat()); diff --git a/dist/module-debug/resolve/or.js b/dist/module-debug/resolve/or.js index b23a87b..13fa4e3 100644 --- a/dist/module-debug/resolve/or.js +++ b/dist/module-debug/resolve/or.js @@ -1,168 +1,73 @@ import Resolver from "../resolver.js"; -import default_resolver from "./default.js"; -import { union as _union } from "../intersect.js"; -import { ResolverOptions } from "../type.js"; +import { union } from "../intersect.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +/** @this {Resolver} */ Resolver.prototype.or = function () { - const self = this; - let args = arguments, - first_argument = args[0]; - - - if (first_argument.then) { - return first_argument.then(function () { - return self.or.apply(self, args); - }); - } - - if (first_argument[0]) { - // fix false passed parameter style - if (first_argument[0].index) { - return this.or.apply(this, first_argument); - } - } - - let final = [], - promises = [], - limit = 0, - offset = 0, + const { + final, + promises, + limit, + offset, enrich, - resolve; + resolve + } = this.handler("or", arguments); + return return_result.call(this, final, promises, limit, offset, enrich, resolve); +}; - for (let i = 0, query; i < args.length; i++) { +/** + * Aggregate the intersection of N raw results + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } + */ - query = /** @type {string|ResolverOptions} */args[i]; - - if (query) { - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - - let result; - if (query.constructor === Resolver) { - result = query.result; - } else if (query.constructor === Array) { - result = query; - } else if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; - result = query.index.search(query).result; - } else if (query.and) { - result = this.and(query.and); - } else if (query.xor) { - result = this.xor(query.xor); - } else if (query.not) { - result = this.not(query.not); - } else { - continue; - } - - final[i] = result; - - if (result.then) { - promises.push(result); //{ query, result }; - } - } - } +function return_result(final, promises, limit, offset, enrich, resolve) { if (promises.length) { - return Promise.all(promises).then(function () { - //self.result.length && (final = [self.result].concat(final)); - // the suggest-union was re-used from but there it needs reversed order - self.result.length && (final = final.concat([self.result])); - self.result = union(final, limit, offset, enrich, resolve, self.boostval); - return resolve ? self.result : self; + const self = this; + return Promise.all(promises).then(function (result) { + + final = []; + for (let i = 0, tmp; i < result.length; i++) { + if ((tmp = result[i]).length) { + final[i] = tmp; + } + } + + return return_result.call(self, final, [], limit, offset, enrich, resolve); }); } if (final.length) { - //this.result.length && (final = [this.result].concat(final)); - // the suggest-union was re-used but there it needs reversed order - this.result.length && (final = final.concat([this.result])); - this.result = union(final, limit, offset, enrich, resolve, this.boostval); - } - return resolve ? this.result : this; -}; + //this.result.length && (final = final.concat([this.result])); + this.result.length && final.push(this.result); -/** - * Aggregate the union of N raw results - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @return {Array} - */ - -function union(result, limit, offset, enrich, resolve, boost) { - - if (!result.length) { - // todo remove - //console.log("Empty Result") - return result; - } - - if ("object" == typeof limit) { - offset = limit.offset || 0; - enrich = limit.enrich || !1; - limit = limit.limit || 0; - } - - if (2 > result.length) { - // todo remove - //console.log("Single Result") - if (resolve) { - return default_resolver(result[0], limit, offset, enrich); + if (2 > final.length) { + this.result = final[0]; } else { - return result[0]; + // the suggest-union (reversed processing, resolve needs to be disabled) + this.result = union(final /*.reverse()*/ + , limit, offset, /* suggest */ /* append: */ /* enrich */ + /* resolve: */!1, this.boostval); + + // offset was already applied + offset = 0; } } - // the suggest-union - return _union(result /*.reverse()*/, offset, limit, resolve, boost); - - // let final = []; - // let count = 0; - // let dupe = create_object(); - // let maxres = get_max_len(result); - // - // for(let j = 0, ids; j < maxres; j++){ - // for(let i = 0, res; i < result.length; i++){ - // res = result[i]; - // if(!res) continue; - // ids = res[j]; - // if(!ids) continue; - // - // for(let k = 0, id; k < ids.length; k++){ - // id = ids[k]; - // if(!dupe[id]){ - // dupe[id] = 1; - // if(offset){ - // offset--; - // continue; - // } - // if(resolve){ - // final.push(id); - // } - // else{ - // // shift resolution by boost (inverse) - // const index = j + (boost || 0); - // final[index] || (final[index] = []); - // final[index].push(id); - // } - // if(limit && ++count === limit){ - // //this.boost = 0; - // return final; - // } - // } - // } - // } - // } - // - // //this.boost = 0; - // return final; + return resolve ? this.resolve(limit, offset, enrich) : this; } \ No newline at end of file diff --git a/dist/module-debug/resolve/xor.js b/dist/module-debug/resolve/xor.js index 9026feb..844bb7f 100644 --- a/dist/module-debug/resolve/xor.js +++ b/dist/module-debug/resolve/xor.js @@ -1,115 +1,96 @@ import Resolver from "../resolver.js"; import default_resolver from "./default.js"; import { create_object } from "../common.js"; -import { ResolverOptions } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +/** @this {Resolver} */ Resolver.prototype.xor = function () { - const self = this; - let args = arguments, - first_argument = args[0]; - - if (first_argument.then) { - return first_argument.then(function () { - return self.xor.apply(self, args); - }); - } - - if (first_argument[0]) { - // fix false passed parameter style - if (first_argument[0].index) { - return this.xor.apply(this, first_argument); - } - } - - let final = [], - promises = [], - limit = 0, - offset = 0, + const { + final, + promises, + limit, + offset, enrich, - resolve; + resolve, + suggest + } = this.handler("xor", arguments); - - for (let i = 0, query; i < args.length; i++) { - - query = /** @type {string|ResolverOptions} */args[i]; - - if (query) { - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - - let result; - if (query.constructor === Resolver) { - result = query.result; - } else if (query.constructor === Array) { - result = query; - } else if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; - result = query.index.search(query).result; - } else if (query.or) { - result = this.or(query.or); - } else if (query.and) { - result = this.and(query.and); - } else if (query.not) { - result = this.not(query.not); - } else { - continue; - } - - final[i] = result; - - if (result.then) { - promises.push(result); //{ query, result }; - } - } - } - - if (promises.length) { - return Promise.all(promises).then(function () { - self.result.length && (final = [self.result].concat(final)); - self.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval); - return resolve ? self.result : self; - }); - } - - if (final.length) { - this.result.length && (final = [this.result].concat(final)); - this.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval); - } - return resolve ? this.result : this; + return return_result.call(this, final, promises, limit, offset, enrich, resolve, suggest); }; /** - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @return {Array} + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } */ -function exclusive(result, limit, offset, enrich, resolve, boost) { +function return_result(final, promises, limit, offset, enrich, resolve, suggest) { - if (!result.length) { - // todo remove - //console.log("Empty Result") - return result; + if (promises.length) { + const self = this; + return Promise.all(promises).then(function (result) { + + final = []; + for (let i = 0, tmp; i < result.length; i++) { + if ((tmp = result[i]).length) { + final[i] = tmp; + } + } + + return return_result.call(self, final, [], limit, offset, enrich, resolve, suggest); + }); } - if (2 > result.length) { - // todo remove - //console.log("Single Result") - if (resolve) { - return default_resolver(result[0], limit, offset, enrich); + if (!final.length) { + if (!suggest) this.result = /** @type {SearchResults|IntermediateSearchResults} */final; + } else { + //this.result.length && (final = [this.result].concat(final)); + this.result.length && final.unshift(this.result); + + if (2 > final.length) { + this.result = final[0]; } else { - return result[0]; + this.result = exclusive.call(this, final, limit, offset, resolve, this.boostval); + + return resolve ? enrich ? apply_enrich.call(this.index, /** @type {SearchResults} */this.result) : this.result : this; } } + return resolve ? this.resolve(limit, offset, enrich) : this; +} + +/** + * Aggregate the intersection of N raw results + * @param {!Array} result + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {number=} boost + * @this {Resolver} + * @return {SearchResults|IntermediateSearchResults} + */ + +function exclusive(result, limit, offset, resolve, boost) { + + // if(!result.length){ + // return result; + // } + + /** @type {SearchResults|IntermediateSearchResults} */ const final = [], check = create_object(); @@ -119,15 +100,15 @@ function exclusive(result, limit, offset, enrich, resolve, boost) { res = result[i]; if (!res) continue; + if (maxres < res.length) maxres = res.length; + for (let j = 0, ids; j < res.length; j++) { ids = res[j]; if (!ids) continue; - if (maxres < ids.length) maxres = ids.length; - for (let k = 0, id; k < ids.length; k++) { id = ids[k]; - check[id] ? check[id]++ : check[id] = 1; + check[id] = check[id] ? 2 : 1; } } } @@ -167,6 +148,5 @@ function exclusive(result, limit, offset, enrich, resolve, boost) { } } - //this.boost = 0; return final; } \ No newline at end of file diff --git a/dist/module-debug/resolver.js b/dist/module-debug/resolver.js index 63b7eec..4f80ec8 100644 --- a/dist/module-debug/resolver.js +++ b/dist/module-debug/resolver.js @@ -1,13 +1,17 @@ +import Index from "./index.js"; import default_resolver from "./resolve/default.js"; -import { set_resolve } from "./index/search.js"; -import { ResolverOptions } from "./type.js"; +//import { set_resolve } from "./index/search.js"; +import { apply_enrich } from "./document/search.js"; +import { ResolverOptions, IntermediateSearchResults } from "./type.js"; +import "./resolve/handler.js"; import "./resolve/or.js"; import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; /** - * @param {Array|ResolverOptions=} result + * @param {IntermediateSearchResults|ResolverOptions=} result + * @return {Resolver} * @constructor */ @@ -15,23 +19,30 @@ export default function Resolver(result) { if (!this || this.constructor !== Resolver) { return new Resolver(result); } + // if(result && result.constructor === Resolver){ + // // todo test this branch + // //console.log("Resolver Loopback") + // return /** @type {Resolver} */ (result); + // } if (result && result.index) { - result.resolve = /* suggest */ /* append: */ /* enrich */!1; - this.index = result.index; + // result = /** @type {ResolverOptions} */ (result); + result.resolve = /* suggest */ /* append: */ /* enrich */ /* resolve: */!1; + this.index = /** @type {Index} */result.index; this.boostval = result.boost || 0; this.result = result.index.search(result).result; return this; } - if (result.constructor === Resolver) { - // todo test this branch - //console.log("Resolver Loopback") - return result; - } + /** @type {Index|null} */ this.index = null; - this.result = result || []; + /** @type {IntermediateSearchResults} */ + this.result = /** @type {IntermediateSearchResults} */result || []; + /** @type {number} */ this.boostval = 0; } +/** + * @param {number} limit + */ Resolver.prototype.limit = function (limit) { if (this.result.length) { const final = []; @@ -51,6 +62,9 @@ Resolver.prototype.limit = function (limit) { return this; }; +/** + * @param {number} offset + */ Resolver.prototype.offset = function (offset) { if (this.result.length) { const final = []; @@ -69,6 +83,9 @@ Resolver.prototype.offset = function (offset) { return this; }; +/** + * @param {number} boost + */ Resolver.prototype.boost = function (boost) { this.boostval += boost; return this; @@ -79,10 +96,12 @@ Resolver.prototype.boost = function (boost) { * @param {number=} offset * @param {boolean=} enrich */ - Resolver.prototype.resolve = function (limit, offset, enrich) { - set_resolve(1); - const result = this.result; + + //set_resolve(1); + const result = this.result, + index = this.index; + this.index = null; this.result = null; @@ -92,7 +111,16 @@ Resolver.prototype.resolve = function (limit, offset, enrich) { offset = limit.offset; limit = limit.limit; } - return default_resolver(result, limit || 100, offset, enrich); + // const document = this.index; + // if(document.index){ + // result = default_resolver(result, limit || 100, offset, false); + // return enrich + // ? apply_enrich.call(document, result) + // : result; + // } + // else{ + return default_resolver.call(index, result, limit || 100, offset, enrich); + // } } return result; diff --git a/dist/module-debug/serialize.js b/dist/module-debug/serialize.js index 1d807b6..67e6878 100644 --- a/dist/module-debug/serialize.js +++ b/dist/module-debug/serialize.js @@ -7,6 +7,11 @@ const chunk_size_reg = 250000, chunk_size_ctx = 1000; +/** + * @param {Map} map + * @param {number=} size + * @return {Array} + */ function map_to_json(map, size = 0) { let chunk = [], json = []; @@ -25,13 +30,19 @@ function map_to_json(map, size = 0) { return chunk; } +/** + * @param {Array} json + * @param {Map=} map + * @return {Map} + */ function json_to_map(json, map) { map || (map = new Map()); for (let i = 0, entry; i < json.length; i++) { entry = json[i]; map.set(entry[0], entry[1]); } - return map; + return (/** @type {Map} */map + ); } function ctx_to_json(ctx, size = 0) { @@ -89,9 +100,17 @@ function json_to_reg(json, reg) { } /** + * + * @param {function(string, string):Promise|void} callback + * @param {string|null|void} field + * @param {string} key + * @param {Array|null} chunk + * @param {number} index_doc + * @param {number} index_obj + * @param {number=} index_prt * @this {Index|Document} + * @return {Promise} */ - function save(callback, field, key, chunk, index_doc, index_obj, index_prt = 0) { const is_arr = chunk && chunk.constructor === Array, data = is_arr ? chunk.shift() : chunk; @@ -114,17 +133,17 @@ function save(callback, field, key, chunk, index_doc, index_obj, index_prt = 0) /** * @param {function(string,string):Promise|void} callback - * @param {string|null=} field - * @param {number=} index_doc - * @param {number=} index_obj + * @param {!string|null=} _field + * @param {number=} _index_doc + * @param {number=} _index_obj * @this {Index} */ -export function exportIndex(callback, field, index_doc, index_obj = 0) { +export function exportIndex(callback, _field, _index_doc = 0, _index_obj = 0) { let key, chunk; - switch (index_obj) { + switch (_index_obj) { case 0: @@ -156,12 +175,12 @@ export function exportIndex(callback, field, index_doc, index_obj = 0) { return; } - return save.call(this, callback, field, key, chunk, index_doc, index_obj); + return save.call(this, callback, _field, key, chunk, _index_doc, _index_obj); } /** * @param {string} key - * @param {string|*} data + * @param {string|Array} data * @this Index */ @@ -170,8 +189,8 @@ export function importIndex(key, data) { if (!data) { return; } - if (is_string(data)) { - data = JSON.parse( /** @type {string} */data); + if ("string" == typeof data) { + data = /** @type {Array} */JSON.parse( /** @type {string} */data); } const split = key.split("."); @@ -189,7 +208,7 @@ export function importIndex(key, data) { case "reg": // fast update isn't supported by export/import - this.fastupdate = /* suggest */ /* append: */ /* enrich */!1; + this.fastupdate = /* suggest */ /* append: */ /* enrich */ /* resolve: */!1; this.reg = json_to_reg(data, this.reg); break; @@ -207,60 +226,60 @@ export function importIndex(key, data) { /** * @param {function(string,string):Promise|void} callback - * @param {string|null=} field - * @param {number=} index_doc - * @param {number=} index_obj + * @param {string|null=} _field + * @param {number=} _index_doc + * @param {number=} _index_obj * @this {Document} */ -export function exportDocument(callback, field, index_doc = 0, index_obj = 0) { +export function exportDocument(callback, _field, _index_doc = 0, _index_obj = 0) { - if (index_doc < this.field.length) { - const field = this.field[index_doc], + if (_index_doc < this.field.length) { + const field = this.field[_index_doc], idx = this.index.get(field), - res = idx.export(callback, field, index_doc, index_obj = 1); + res = idx.export(callback, field, _index_doc, _index_obj = 1); // start from index 1, because document indexes does not additionally store register if (res && res.then) { const self = this; return res.then(function () { - return self.export(callback, field, index_doc + 1); + return self.export(callback, field, _index_doc + 1); }); } - return this.export(callback, field, index_doc + 1); + return this.export(callback, field, _index_doc + 1); } else { let key, chunk; - switch (index_obj) { + switch (_index_obj) { case 0: key = "reg"; chunk = reg_to_json(this.reg); - field = null; + _field = null; break; case 1: key = "tag"; chunk = ctx_to_json(this.tag, this.reg.size); - field = null; + _field = null; break; case 2: key = "doc"; chunk = map_to_json(this.store); - field = null; + _field = null; break; case 3: key = "cfg"; chunk = {}; - field = null; + _field = null; break; default: @@ -268,13 +287,13 @@ export function exportDocument(callback, field, index_doc = 0, index_obj = 0) { return; } - return save.call(this, callback, field, key, chunk, index_doc, index_obj); + return save.call(this, callback, _field, key, chunk, _index_doc, _index_obj); } } /** - * @param key - * @param {string|*} data + * @param {!string} key + * @param {string|Array} data * @this {Document} */ @@ -283,8 +302,8 @@ export function importDocument(key, data) { if (!data) { return; } - if (is_string(data)) { - data = JSON.parse( /** @type {string} */data); + if ("string" == typeof data) { + data = /** @type {Array} */JSON.parse( /** @type {string} */data); } const split = key.split("."); diff --git a/dist/module-debug/type.js b/dist/module-debug/type.js index b586bbe..9c0e2c6 100644 --- a/dist/module-debug/type.js +++ b/dist/module-debug/type.js @@ -17,7 +17,6 @@ import StorageInterface from "./db/interface.js"; * keystore: (number|undefined), * rtl: (boolean|undefined), * cache: (number|boolean|undefined), - * resolve: (boolean|undefined), * db: (StorageInterface|undefined), * commit: (boolean|undefined), * worker: (string|undefined), @@ -131,9 +130,9 @@ export let SearchOptions = {}; * suggest: (boolean|undefined), * enrich: (boolean|undefined), * tag: (Object|Array|undefined), - * field: (Array|Array|string|undefined), - * index: (Array|Array|undefined), - * pluck: (string|undefined), + * field: (Array|Array|DocumentSearchOptions|string|undefined), + * index: (Array|Array|DocumentSearchOptions|string|undefined), + * pluck: (string|DocumentSearchOptions|undefined), * merge: (boolean|undefined), * highlight: (string|undefined), * }} @@ -142,16 +141,23 @@ export let DocumentSearchOptions = {}; /** * @typedef Array + * @global */ -export let SearchResults = {}; +export let SearchResults = []; + +/** + * @typedef Array> + * @global + */ +export let IntermediateSearchResults = []; /** * @typedef Array<{ * id: (number|string), - * res: number + * doc: (Object|null) * }> */ -export let EnrichedSearchResults = {}; +export let EnrichedSearchResults = []; /** * @typedef Array<{ @@ -160,20 +166,17 @@ export let EnrichedSearchResults = {}; * result: SearchResults * }> */ -export let DocumentSearchResults = {}; +export let DocumentSearchResults = []; /** * @typedef Array<{ * field: (string|undefined), * tag: (string|undefined), * highlight: (string|undefined), - * result: Array<{ - * id: (number|string), - * doc: (Object|null) - * }> + * result: {EnrichedSearchResults} * }> */ -export let EnrichedDocumentSearchResults = {}; +export let EnrichedDocumentSearchResults = []; /** * @typedef Array<{ @@ -183,7 +186,7 @@ export let EnrichedDocumentSearchResults = {}; * tag: (Array|undefined) * }> */ -export let MergedDocumentSearchResults = {}; +export let MergedDocumentSearchResults = []; /** * @typedef {{ @@ -204,6 +207,7 @@ export let EncoderSplitOptions = {}; * include: (EncoderSplitOptions|undefined), * exclude: (EncoderSplitOptions|undefined), * split: (string|boolean|undefined), + * numeric: (boolean|undefined), * normalize: (boolean|(function(string):string)|undefined), * prepare: ((function(string):string)|undefined), * finalize: ((function(Array):(Array|void))|undefined), diff --git a/dist/module-min/bundle.js b/dist/module-min/bundle.js index 9f4fbbe..cfe2e59 100644 --- a/dist/module-min/bundle.js +++ b/dist/module-min/bundle.js @@ -1 +1 @@ -import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Index.prototype.encoder,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.worker,IndexOptions.config,FieldOptions.preset,FieldOptions.context,FieldOptions.encoder,FieldOptions.encode,FieldOptions.resolution,FieldOptions.tokenize,FieldOptions.fastupdate,FieldOptions.score,FieldOptions.keystore,FieldOptions.rtl,FieldOptions.cache,FieldOptions.db,FieldOptions.config,FieldOptions.resolve,FieldOptions.field,FieldOptions.filter,FieldOptions.custom,FieldOptions.worker,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{FlexSearch.Language={};const a=self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file +import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Index.prototype.encoder,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.worker,IndexOptions.config,FieldOptions.preset,FieldOptions.context,FieldOptions.encoder,FieldOptions.encode,FieldOptions.resolution,FieldOptions.tokenize,FieldOptions.fastupdate,FieldOptions.score,FieldOptions.keystore,FieldOptions.rtl,FieldOptions.cache,FieldOptions.db,FieldOptions.config,FieldOptions.resolve,FieldOptions.field,FieldOptions.filter,FieldOptions.custom,FieldOptions.worker,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{FlexSearch.Language={};const a=self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file diff --git a/dist/module-min/charset/latin/default.js b/dist/module-min/charset/latin/default.js index 6d6e97f..793c84b 100644 --- a/dist/module-min/charset/latin/default.js +++ b/dist/module-min/charset/latin/default.js @@ -1 +1 @@ -import{EncoderOptions}from"../../type.js";const options={normalize:function(a){return a.toLowerCase()},dedupe:!1};export default options; \ No newline at end of file +import{EncoderOptions}from"../../type.js";const options={normalize:function(a){return a.toLowerCase()},numeric:!1,dedupe:!1};export default options; \ No newline at end of file diff --git a/dist/module-min/common.js b/dist/module-min/common.js index b18cab6..fbdc6fe 100644 --- a/dist/module-min/common.js +++ b/dist/module-min/common.js @@ -1 +1 @@ -export function parse_option(a,b,c){const d=typeof c,e=typeof a;if("undefined"!=d){if("undefined"!=e){if(c){if("function"==e&&d==e)return function(b){return a(c(b))};const b=a.constructor,f=c.constructor;if(b===f){if(b===Array)return c.concat(a);if(b===Map){const b=new Map(c);for(const c of a){const a=c[0],d=c[1];b.set(a,d)}return b}if(b===Set){const b=new Set(c);for(const c of a.values())b.add(c);return b}}}return a}return c}return"undefined"==e?b:a}export function create_object_array(a){const b=Array(a);for(let c=0;c{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){return IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""))},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b(e.onerror=c=>{this.trx[a+":"+b]=null,e.abort(),e=d=null,g(c)},e.oncomplete=c=>{this.trx[a+":"+b]=null,e=d=null,f(c||!0)},c.call(this,d)))},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})} \ No newline at end of file +import{PersistentOptions,SearchResults,EnrichedSearchResults}from"../../type.js";const VERSION=1,IndexedDB="undefined"!=typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),IDBTransaction="undefined"!=typeof window&&(window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction),IDBKeyRange="undefined"!=typeof window&&(window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}export default function IdxDB(a,b={}){return this?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="flexsearch"+(a?":"+sanitize(a):""),this.field=b.field?sanitize(b.field):"",this.type=b.type,this.support_tag_search=!1,this.fastupdate=!1,this.db=null,this.trx={}):new IdxDB(a,b)}IdxDB.prototype.mount=function(a){return a.encoder?(a.db=this,this.open()):a.mount(this)},IdxDB.prototype.open=function(){let a=this;return navigator.storage&&navigator.storage.persist(),this.db||new Promise(function(b,c){const d=IndexedDB.open(a.id+(a.field?":"+a.field:""),VERSION);d.onupgradeneeded=function(){const b=a.db=this.result;fields.forEach(a=>{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){const a=IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""));return promisfy(a)},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b(e.onerror=c=>{this.trx[a+":"+b]=null,e.abort(),e=d=null,g(c)},e.oncomplete=c=>{this.trx[a+":"+b]=null,e=d=null,f(c||!0)},c.call(this,d)))},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/document.js b/dist/module-min/document.js index b7950ca..59ad0a4 100644 --- a/dist/module-min/document.js +++ b/dist/module-min/document.js @@ -1 +1 @@ -import{IndexOptions,DocumentOptions,DocumentDescriptor,FieldOptions,StoreOptions}from"./type.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Cache,{searchCache}from"./cache.js";import{is_string,is_object,parse_simple}from"./common.js";import apply_async from"./async.js";import{exportDocument,importDocument}from"./serialize.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import"./document/add.js";import"./document/search.js";export default function Document(a){if(!this||this.constructor!==Document)return new Document(a);const b=a.document||a.doc||a;let c,d;if(this.tree=[],this.field=[],this.marker=[],this.key=(c=b.key||b.id)&&parse_tree(c,this.marker)||"id",d=a.keystore||0,d&&(this.keystore=d),this.fastupdate=!!a.fastupdate,this.reg=this.fastupdate?d&&!0?new KeystoreMap(d):new Map:d&&!0?new KeystoreSet(d):new Set,this.storetree=(c=b.store||null)&&c&&!0!==c&&[],this.store=c&&(d&&!0?new KeystoreMap(d):new Map),this.cache=(c=a.cache||null)&&new Cache(c),a.cache=!1,this.worker=a.worker,this.index=parse_descriptor.call(this,a,b),(this.tag=null,(c=b.tag)&&("string"==typeof c&&(c=[c]),c.length))){this.tag=new Map,this.tagtree=[],this.tagfield=[];for(let a,b,d=0;da.length?this.addMapper(a,b):(this.matcher||(this.matcher=new Map),this.matcher.set(a,b),this.matcher_str+=(this.matcher_str?"|":"")+a,this.matcher_test=null,this.cache&&this.invalidate(),this)},Encoder.prototype.addStemmer=function(a,b){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(a,b),this.stemmer_str+=(this.stemmer_str?"|":"")+a,this.stemmer_test=null,this.cache&&this.invalidate(),this},Encoder.prototype.addFilter=function(a){return this.filter||(this.filter=new Set),this.filter.add(a),this.cache&&this.invalidate(),this},Encoder.prototype.addMapper=function(a,b){return"object"==typeof a?this.addReplacer(a,b):1this.stemmer.get(a)),a=1),e&&a&&(e.lengththis.matcher.get(a))),e&&this.replacer)for(let a=0;e&&athis.cache_size&&(this.cache_term.clear(),this.cache_term_length=0|this.cache_term_length/1.1)),e&&c.push(e)}return this.finalize&&(c=this.finalize(c)||c),this.cache&&a.length<=this.cache_enc_length&&(this.cache_enc.set(a,c),this.cache_enc.size>this.cache_size&&(this.cache_enc.clear(),this.cache_enc_length=0|this.cache_enc_length/1.1)),c};function clear(a){a.timer=null,a.cache_enc.clear(),a.cache_term.clear()} \ No newline at end of file +import{merge_option}from"./common.js";import normalize_polyfill from"./charset/normalize.js";import{EncoderOptions}from"./type.js";const whitespace=/[^\p{L}\p{N}]+/u,numeric_split_length=/(\d{3})/g,numeric_split_prev_char=/(\D)(\d{3})/g,numeric_split_next_char=/(\d{3})(\D)/g,normalize=/[\u0300-\u036f]/g;export default function Encoder(){if(!this||this.constructor!==Encoder)return new Encoder(...arguments);for(let a=0;a"a1a".split(d).length;this.numeric=merge_option(a.numeric,b)}else{try{this.split=merge_option(this.split,whitespace)}catch(a){!1,this.split=/\s+/}this.numeric=merge_option(a.numeric,merge_option(this.numeric,!0))}if(this.prepare=merge_option(a.prepare,null,this.prepare),this.finalize=merge_option(a.finalize,null,this.finalize),!normalize&&(this.mapper=new Map(normalize_polyfill)),this.rtl=merge_option(a.rtl,!1,this.rtl),this.dedupe=merge_option(a.dedupe,!1,this.dedupe),this.filter=merge_option((d=a.filter)&&new Set(d),null,this.filter),this.matcher=merge_option((d=a.matcher)&&new Map(d),null,this.matcher),this.mapper=merge_option((d=a.mapper)&&new Map(d),null,this.mapper),this.stemmer=merge_option((d=a.stemmer)&&new Map(d),null,this.stemmer),this.replacer=merge_option(a.replacer,null,this.replacer),this.minlength=merge_option(a.minlength,1,this.minlength),this.maxlength=merge_option(a.maxlength,0,this.maxlength),this.cache=d=merge_option(a.cache,!0,this.cache),d&&(this.timer=null,this.cache_size="number"==typeof d?d:2e5,this.cache_enc=new Map,this.cache_term=new Map,this.cache_enc_length=128,this.cache_term_length=128),this.matcher_str="",this.matcher_test=null,this.stemmer_str="",this.stemmer_test=null,this.matcher)for(const a of this.matcher.keys())this.matcher_str+=(this.matcher_str?"|":"")+a;if(this.stemmer)for(const a of this.stemmer.keys())this.stemmer_str+=(this.stemmer_str?"|":"")+a;return this},Encoder.prototype.addStemmer=function(a,b){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(a,b),this.stemmer_str+=(this.stemmer_str?"|":"")+a,this.stemmer_test=null,this.cache&&clear(this),this},Encoder.prototype.addFilter=function(a){return this.filter||(this.filter=new Set),this.filter.add(a),this.cache&&clear(this),this},Encoder.prototype.addMapper=function(a,b){return"object"==typeof a?this.addReplacer(a,b):1a.length&&(this.dedupe||this.mapper)?this.addMapper(a,b):(this.matcher||(this.matcher=new Map),this.matcher.set(a,b),this.matcher_str+=(this.matcher_str?"|":"")+a,this.matcher_test=null,this.cache&&clear(this),this)},Encoder.prototype.addReplacer=function(a,b){return"string"==typeof a?this.addMatcher(a,b):(this.replacer||(this.replacer=[]),this.replacer.push(a,b),this.cache&&clear(this),this)},Encoder.prototype.encode=function(a){if(this.cache&&a.length<=this.cache_enc_length)if(!this.timer)this.timer=setTimeout(clear,50,this);else if(this.cache_enc.has(a))return this.cache_enc.get(a);this.normalize&&("function"==typeof this.normalize?a=this.normalize(a):normalize?a=a.normalize("NFKD").replace(normalize,"").toLowerCase():a=a.toLowerCase()),this.prepare&&(a=this.prepare(a)),this.numeric&&3this.stemmer.get(a)),(e.lengththis.matcher.get(a))),e&&this.replacer)for(let a=0;e&&athis.cache_size&&(this.cache_term.clear(),this.cache_term_length=0|this.cache_term_length/1.1)),e&&c.push(e)}}return this.finalize&&(c=this.finalize(c)||c),this.cache&&a.length<=this.cache_enc_length&&(this.cache_enc.set(a,c),this.cache_enc.size>this.cache_size&&(this.cache_enc.clear(),this.cache_enc_length=0|this.cache_enc_length/1.1)),c};function clear(a){a.timer=null,a.cache_enc.clear(),a.cache_term.clear()} \ No newline at end of file diff --git a/dist/module-min/index/remove.js b/dist/module-min/index/remove.js index 4473084..7474a4c 100644 --- a/dist/module-min/index/remove.js +++ b/dist/module-min/index/remove.js @@ -1 +1 @@ -import{create_object,is_array}from"../common.js";import Index,{autoCommit}from"../index.js";import default_compress from"../compress.js";Index.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate){for(let b,d=0;db.length)b.pop();else{const d=b.indexOf(a);d===c.length-1?b.pop():b.splice(d,1)}}else remove_index(this.map,a),this.depth&&remove_index(this.ctx,a);b||this.reg.delete(a)}return this.db&&(this.commit_task.push({del:a}),this.commit_auto&&autoCommit(this)),this.cache&&this.cache.remove(a),this};function remove_index(a,b){let c=0;if(is_array(a)){for(let d,e,f=0;fb.length)b.pop();else{const d=b.indexOf(a);d===c.length-1?b.pop():b.splice(d,1)}}else remove_index(this.map,a),this.depth&&remove_index(this.ctx,a);b||this.reg.delete(a)}return this.db&&(this.commit_task.push({del:a}),this.commit_auto&&autoCommit(this)),this.cache&&this.cache.remove(a),this};function remove_index(a,b){let c=0;if(is_array(a)){for(let d,e,f=0;fb),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?b?this.db.get(i?b:a,i?a:b,c,d,e,f,g):this.db.get(a,"",c,d,e,f,g):(b?(h=this.ctx.get(i?a:b),h=h&&h.get(i?b:a)):h=this.map.get(a),h)}; \ No newline at end of file +import{SearchOptions,SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";import{create_object,is_object,sort_by_length_down}from"../common.js";import Index from"../index.js";import default_compress from"../compress.js";import Resolver from"../resolver.js";import{intersect}from"../intersect.js";import resolve_default from"../resolve/default.js";Index.prototype.search=function(a,b,c){c||(!b&&is_object(a)?(c=a,a=""):is_object(b)&&(c=b,b=0));let d,e,f,g,h,i,j,k,l=[],m=0;c?(a=c.query||a,b=c.limit||b,m=c.offset||0,e=c.context,f=c.suggest,g=!1!==c.resolve,k=g&&c.enrich,i=c.boost,j=c.resolution,h=this.db&&c.tag):g=this.resolve;let n=this.encoder.encode(a);if(d=n.length,b=b||(g?100:0),1===d)return single_term_query.call(this,n[0],"",b,m,g,k,h);if(e=this.depth&&!1!==e,2===d&&e&&!f)return single_term_query.call(this,n[0],n[1],b,m,g,k,h);let o,p=create_object(),q=0;if(1b,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file diff --git a/dist/module-min/intersect.js b/dist/module-min/intersect.js index fbf0b78..6477af1 100644 --- a/dist/module-min/intersect.js +++ b/dist/module-min/intersect.js @@ -1 +1 @@ -import{create_object,concat,sort_by_length_up,get_max_len}from"./common.js";export function intersect(a,b,c,d,e,f,g){const h=a.length;let i,j,k=[];i=create_object();for(let l,m,n,o,p=0;pc||d)&&(k=k.slice(d,c+d));else{const a=[];for(let b,e=0;ed){d-=b.length;continue}if((b.length>c||d)&&(b=b.slice(d,c+d),c-=b.length,d&&(d-=b.length)),a.push(b),!c)break}k=1c||d?k.slice(d,c+d):k;return k}export function union(a,b,c,d,e){const f=[],g=create_object();let h,l,m,n=a.length,o=0;if(!d){let d=get_max_len(a);for(let j=0;jc||d)&&(k=k.slice(d,c+d));else{const a=[];for(let b,e=0;ed){d-=b.length;continue}if((b.length>c||d)&&(b=b.slice(d,c+d),c-=b.length,d&&(d-=b.length)),a.push(b),!c)break}k=1c||d?k.slice(d,c+d):k;return k}export function union(a,b,c,d,e){const f=[],g=create_object();let h,l,m,n=a.length;if(!d)for(let d,j=n-1,i=0;0<=j;j--){d=a[j];for(let a=0;aa.length)return[];let h=create_object(),i=get_max_len(a);return i?_intersect(a,i,b,c,g,f,e):[]} \ No newline at end of file +import Resolver from"../resolver.js";import{get_max_len}from"../common.js";import{intersect}from"../intersect.js";import{SearchResults,EnrichedSearchResults,IntermediateSearchResults,ResolverOptions}from"../type.js";import{apply_enrich}from"../document/search.js";Resolver.prototype.and=function(){let a,b,c,d,e=this.result.length;if(!e){const f=arguments[0];f&&(e=!!f.suggest,d=f.resolve,a=f.limit,b=f.offset,c=f.enrich&&d)}if(e){const{final:a,promises:b,limit:c,offset:d,enrich:e,resolve:f,suggest:g}=this.handler("and",arguments);return return_result.call(this,a,b,c,d,e,f,g)}return d?this.resolve(a,b,c):this};function return_result(a,b,c,d,e,f,g){if(b.length){const h=this;return Promise.all(b).then(function(b){a=[];for(let c,d=0;da.length)this.result=a[0];else{const b=get_max_len(a);if(!b)this.result=[];else return this.result=intersect(a,b,c,d,g,this.boostval,f),f?e?apply_enrich.call(this.index,this.result):this.result:this}return f?this.resolve(c,d,e):this} \ No newline at end of file diff --git a/dist/module-min/resolve/default.js b/dist/module-min/resolve/default.js index ab304b4..80454d4 100644 --- a/dist/module-min/resolve/default.js +++ b/dist/module-min/resolve/default.js @@ -1 +1 @@ -import{concat}from"../common.js";export default function(a,b,c,d){if(1===a.length)return a=a[0],a=c||a.length>b?b?a.slice(c,c+b):a.slice(c):a,d?enrich_result(a):a;let e=[];for(let f,g,h=0;h=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length);else if(g>=b)return g>b&&(f=f.slice(0,b)),d?enrich_result(f):f;if(e.push(f),b-=g,!b)break}return e.length?(e=1b?b?e.slice(c,c+b):e.slice(c):e,d?apply_enrich.call(this,e):e}let e=[];for(let f,g,h=0;h=g){c-=g;continue}cb&&(f=f.slice(0,b),g=b),!e.length&&g>=b)return d?apply_enrich.call(this,f):f;if(e.push(f),b-=g,!b)break}return e=1a.length?e?default_resolver(a[0],b,c,d):a[0]:_union(a,c,b,e,f)):a} \ No newline at end of file +import Resolver from"../resolver.js";import{union}from"../intersect.js";import{SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";Resolver.prototype.or=function(){const{final:a,promises:b,limit:c,offset:d,enrich:e,resolve:f}=this.handler("or",arguments);return return_result.call(this,a,b,c,d,e,f)};function return_result(a,b,c,d,e,f){if(b.length){const g=this;return Promise.all(b).then(function(b){a=[];for(let c,d=0;da.length?this.result=a[0]:(this.result=union(a,c,d,!1,this.boostval),d=0)),f?this.resolve(c,d,e):this} \ No newline at end of file diff --git a/dist/module-min/resolve/xor.js b/dist/module-min/resolve/xor.js index 868b711..bc29c14 100644 --- a/dist/module-min/resolve/xor.js +++ b/dist/module-min/resolve/xor.js @@ -1 +1 @@ -import Resolver from"../resolver.js";import default_resolver from"./default.js";import{create_object}from"../common.js";import{ResolverOptions}from"../type.js";Resolver.prototype.xor=function(){const a=this;let b=arguments,c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d,e,f=[],g=[],h=0,j=0;for(let a,c=0;ca.length)return e?default_resolver(a[0],b,c,d):a[0];const g=[],h=create_object();let i=0;for(let g,j=0;ja.length)this.result=a[0];else return this.result=exclusive.call(this,a,c,d,f,this.boostval),f?e?apply_enrich.call(this.index,this.result):this.result:this;return f?this.resolve(c,d,e):this}function exclusive(a,b,c,d,e){const f=[],g=create_object();let h=0;for(let f,j=0;j} + */ IdxDB.prototype.destroy = function () { - return IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const req = IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return promisfy(req); }; // IdxDB.prototype.set = function(ref, key, ctx, data){ @@ -130,6 +140,9 @@ IdxDB.prototype.destroy = function () { // return transaction;//promisfy(req, callback); // }; +/** + * @return {!Promise} + */ IdxDB.prototype.clear = function () { const transaction = this.db.transaction(fields, "readwrite"); for (let i = 0; i < fields.length; i++) { @@ -138,6 +151,15 @@ IdxDB.prototype.clear = function () { return promisfy(transaction); }; +/** + * @param {!string} key + * @param {string=} ctx + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @return {!Promise} + */ IdxDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = /* tag? */!0, enrich = !1) { const transaction = this.db.transaction(ctx ? "ctx" : "map", "readonly"), map = transaction.objectStore(ctx ? "ctx" : "map"), @@ -174,6 +196,13 @@ IdxDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = /* ta }); }; +/** + * @param {!string} tag + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} enrich + * @return {!Promise} + */ IdxDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) { const transaction = this.db.transaction("tag", "readonly"), map = transaction.objectStore("tag"), @@ -189,6 +218,10 @@ IdxDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) { }; +/** + * @param {SearchResults} ids + * @return {!Promise} + */ IdxDB.prototype.enrich = function (ids) { if ("object" != typeof ids) { ids = [ids]; @@ -211,7 +244,10 @@ IdxDB.prototype.enrich = function (ids) { }); }; - +/** + * @param {number|string} id + * @return {!Promise} + */ IdxDB.prototype.has = function (id) { const transaction = this.db.transaction("reg", "readonly"), map = transaction.objectStore("reg"), @@ -466,7 +502,7 @@ IdxDB.prototype.commit = async function (flexsearch, _replace, _append) { /** * @param {IDBCursorWithValue} cursor - * @param {Array} ids + * @param {Array} ids * @param {boolean=} _tag */ @@ -518,6 +554,10 @@ function handle(cursor, ids, _tag) { cursor.continue(); } +/** + * @param {Array} ids + * @return {!Promise} + */ IdxDB.prototype.remove = function (ids) { if ("object" != typeof ids) { diff --git a/dist/module/db/interface.js b/dist/module/db/interface.js index 486d2bd..5c8ef90 100644 --- a/dist/module/db/interface.js +++ b/dist/module/db/interface.js @@ -1,3 +1,5 @@ + + /** * @interface */ @@ -20,9 +22,22 @@ StorageInterface.prototype.destroy = async function () {}; // transfer all changes of an index to the database StorageInterface.prototype.commit = async function () {}; -// get results of a term "key" with optional context "ctx" +/** + * get results of a term "key" with optional context "ctx" + * @param {!string} key + * @param {string=} ctx + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @return {!Promise} + */ StorageInterface.prototype.get = async function () {}; -// get documents stored in index (enrich result) +/** + * get documents stored in index (enrich result) + * @param {SearchResults} ids + * @return {!Promise} + */ StorageInterface.prototype.enrich = async function () {}; // check if id exists on a specific index StorageInterface.prototype.has = async function () {}; diff --git a/dist/module/document.js b/dist/module/document.js index 52289ed..95f915f 100644 --- a/dist/module/document.js +++ b/dist/module/document.js @@ -7,6 +7,7 @@ */ import { IndexOptions, DocumentOptions, DocumentDescriptor, FieldOptions, StoreOptions } from "./type.js"; +import StorageInterface from "./db/interface.js"; import Index from "./index.js"; import WorkerIndex from "./worker.js"; import Cache, { searchCache } from "./cache.js"; @@ -21,6 +22,7 @@ import "./document/search.js"; * @constructor * @param {!DocumentOptions} options * @return {Document|Promise} + * @this {Document} */ export default function Document(options) { @@ -40,7 +42,8 @@ export default function Document(options) { keystore = options.keystore || 0; keystore && (this.keystore = keystore); this.fastupdate = !!options.fastupdate; - this.reg = this.fastupdate ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); + this.reg = this.fastupdate ? keystore && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ + /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ ? new KeystoreMap(keystore) : new Map() : keystore && !0 ? new KeystoreSet(keystore) : new Set(); // todo support custom filter function this.storetree = (tmp = document.store || null) && tmp && !0 !== tmp && []; @@ -49,8 +52,8 @@ export default function Document(options) { this.cache = (tmp = options.cache || null) && new Cache(tmp); // do not apply cache again for the indexes since .searchCache() // is just a wrapper over .search() - options.cache = - /* suggest */ /* append: */ /* enrich */!1; + options.cache = /* suggest */ /* append: */ + /* enrich */!1; this.worker = options.worker; @@ -60,7 +63,7 @@ export default function Document(options) { // } /** - * @type {Map} + * @type {Map} * @export */ this.index = parse_descriptor.call(this, options, document); @@ -93,6 +96,7 @@ export default function Document(options) { this.tagtree[i]._filter = params.filter; } } + // the tag fields needs to be hold by indices this.tagfield[i] = field; this.tag.set(field, new Map()); } @@ -110,7 +114,7 @@ export default function Document(options) { return Promise.all(promises).then(function (promises) { let count = 0; for (const item of self.index.entries()) { - const key = item[0], + const key = /** @type {string} */item[0], index = item[1]; index.then && self.index.set(key, promises[count++]); @@ -123,6 +127,10 @@ export default function Document(options) { } } +/** + * @param {!StorageInterface} db + * @return {Promise>} + */ Document.prototype.mount = function (db) { let fields = this.field; @@ -313,14 +321,28 @@ function parse_tree(key, marker) { return 1 < count ? tree : tree[0]; } +/** + * @param {!number|Object} id + * @param {!Object} content + * @return {Document|Promise} + */ Document.prototype.append = function (id, content) { return this.add(id, content, !0); }; +/** + * @param {!number|Object} id + * @param {!Object} content + * @return {Document|Promise} + */ Document.prototype.update = function (id, content) { return this.remove(id).add(id, content); }; +/** + * @param {!number|Object} id + * @return {Document|Promise} + */ Document.prototype.remove = function (id) { if (is_object(id)) { @@ -393,6 +415,10 @@ Document.prototype.clear = function () { :*/ }; +/** + * @param {number|string} id + * @return {boolean|Promise} + */ Document.prototype.contain = function (id) { if (this.db) { @@ -411,6 +437,10 @@ Document.prototype.cleanup = function () { return this; }; +/** + * @param {number|string} id + * @return {Object} + */ Document.prototype.get = function (id) { if (this.db) { @@ -422,9 +452,14 @@ Document.prototype.get = function (id) { return this.store.get(id); }; -Document.prototype.set = function (id, store) { +/** + * @param {number|string} id + * @param {Object} data + * @return {Document} + */ +Document.prototype.set = function (id, data) { - this.store.set(id, store); + this.store.set(id, data); return this; }; diff --git a/dist/module/document/search.js b/dist/module/document/search.js index 607e483..fad0951 100644 --- a/dist/module/document/search.js +++ b/dist/module/document/search.js @@ -1,17 +1,35 @@ -import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults } from "../type.js"; +import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, MergedDocumentSearchResults, EnrichedSearchResults, SearchResults, IntermediateSearchResults } from "../type.js"; import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; import { intersect_union } from "../intersect.js"; import Document from "../document.js"; - -let debug = /* suggest */ /* append: */ /* enrich */!1; +import Index from "../index.js"; +import Resolver from "../resolver.js"; +import tick from "../profiler.js"; /** * @param {!string|DocumentSearchOptions} query * @param {number|DocumentSearchOptions=} limit * @param {DocumentSearchOptions=} options - * @param {Array=} _promises For internal use only. - * @returns {DocumentSearchResults|EnrichedDocumentSearchResults|MergedDocumentSearchResults|Promise} + * @param {Array=} _promises async recursion + * @returns { + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * MergedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults| + * Resolver | + * Promise< + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * MergedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults| + * Resolver + * > + * } */ Document.prototype.search = function (query, limit, options, _promises) { @@ -26,6 +44,13 @@ Document.prototype.search = function (query, limit, options, _promises) { } } + /** @type { + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults + * } */ let result = [], result_field = [], pluck, @@ -36,6 +61,7 @@ Document.prototype.search = function (query, limit, options, _promises) { tag, offset, count = 0, + resolve, highlight; @@ -50,12 +76,28 @@ Document.prototype.search = function (query, limit, options, _promises) { query = options.query || query; pluck = options.pluck; merge = options.merge; - field = pluck || options.field || options.index; + field = pluck || options.field || (field = options.index) && (field.index ? null : field); tag = this.tag && options.tag; - enrich = this.store && options.enrich; suggest = options.suggest; - highlight = options.highlight; - //resolve = !SUPPORT_RESOLVER || (options.resolve !== false); + resolve = /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + + // upgrade pluck when missing + if (!resolve && !pluck) { + field = field || this.field; + if (field) { + if (is_string(field)) { + pluck = field; + } else { + if (is_array(field) && 1 === field.length) { + field = field[0]; + } + pluck = field.field || field.index; + } + } + } + + enrich = this.store && options.enrich && resolve; + highlight = options.highlight && enrich; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); @@ -66,6 +108,7 @@ Document.prototype.search = function (query, limit, options, _promises) { tag = [tag]; } + // ----------------------------- // Tag-Search // ----------------------------- @@ -143,7 +186,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } // extend to multi field search by default - if (is_string(field)) { + if (field && field.constructor !== Array) { field = [field]; } } @@ -203,14 +246,13 @@ Document.prototype.search = function (query, limit, options, _promises) { // just collect and continue continue; } else { - res = index.search(query, limit, opt); // restore enrich state opt && enrich && (opt.enrich = enrich); } } - len = res && res.length; + len = res && (resolve ? res.length : res.result.length); // todo when no term was matched but tag was retrieved extend suggestion to tags // every field has to intersect against all selected tag fields @@ -234,7 +276,7 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return result; + return resolve ? result : new Resolver(result); } } } @@ -248,7 +290,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return result; + return resolve ? result : new Resolver(result); } } @@ -260,17 +302,17 @@ Document.prototype.search = function (query, limit, options, _promises) { arr.push(ids); } else if (!suggest) { // no tags found - return result; + return resolve ? result : new Resolver(result); } } } if (count) { - res = intersect_union(res, arr); // intersect(arr, limit, offset) + res = intersect_union(res, arr, resolve); // intersect(arr, limit, offset) len = res.length; if (!len && !suggest) { // nothing matched - return result; + return resolve ? res : new Resolver( /** @type {IntermediateSearchResults} */res); } // move counter back by 1 count--; @@ -283,7 +325,7 @@ Document.prototype.search = function (query, limit, options, _promises) { count++; } else if (1 === field.length) { // fast path: nothing matched - return result; + return resolve ? result : new Resolver(result); } } @@ -299,7 +341,7 @@ Document.prototype.search = function (query, limit, options, _promises) { if (suggest) { continue; } else { - return result; + return resolve ? result : new Resolver(result); } } @@ -317,7 +359,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (!count) { - return result; + return resolve ? result : new Resolver(result); } if (pluck && (!enrich || !this.store)) { return result[0]; @@ -331,9 +373,9 @@ Document.prototype.search = function (query, limit, options, _promises) { if (enrich && res.length && !res[0].doc) { if (!this.db) { - if (res.length) { - res = apply_enrich.call(this, res); - } + // if(res.length){ + res = apply_enrich.call(this, res); + // } } else { // the documents are stored on the first field promises.push(res = this.index.get(this.field[0]).db.enrich(res)); @@ -341,7 +383,7 @@ Document.prototype.search = function (query, limit, options, _promises) { } if (pluck) { - return res; + return resolve ? res : new Resolver(res); } result[i] = { @@ -495,20 +537,25 @@ function get_tag(tag, key, limit, offset) { } /** - * @this {Document} + * @param {SearchResults} ids + * @return {EnrichedSearchResults|SearchResults} + * @this {Document|Index|null} */ -function apply_enrich(res) { +export function apply_enrich(ids) { - const arr = Array(res.length); + if (!this || !this.store) return ids; - for (let x = 0, id; x < res.length; x++) { - id = res[x]; - arr[x] = { + /** @type {EnrichedSearchResults} */ + const result = Array(ids.length); + + for (let x = 0, id; x < ids.length; x++) { + id = ids[x]; + result[x] = { id: id, doc: this.store.get(id) }; } - return arr; + return result; } \ No newline at end of file diff --git a/dist/module/encoder.js b/dist/module/encoder.js index 333e8a3..661b1da 100644 --- a/dist/module/encoder.js +++ b/dist/module/encoder.js @@ -1,5 +1,5 @@ -import { parse_option } from "./common.js"; +import { merge_option } from "./common.js"; import normalize_polyfill from "./charset/normalize.js"; import { EncoderOptions } from "./type.js"; @@ -23,21 +23,26 @@ function fixedEncoder(string){ return [string] } -Built-in Encoder (Workflow) +Built-in Encoder ---------------------------- +The main workflow follows an increasing strategy, +starting from a simple .toLowerCase() to full RegExp Pipeline: 1. apply this.normalize: charset normalization: applied on the whole input string e.g. lowercase, - will also apply on: filter, matcher, stemmer, mapper - 2. apply this.split: split input into terms (includes/excludes) - 3. apply this.filter (pre-filter) - 4. apply this.matcher (replace terms) - 5. apply this.stemmer (replace term endings) - 6. apply this.filter (post-filter) - 7. apply this.mapper (replace chars) - 8. apply this.replacer (custom regex) + everything you put later into (filter, matcher, stemmer, mapper, etc.) + has to be normalized by definition, because it won't apply to them automatically + 2. apply this.prepare (custom preparation, string in - string out) + 3 split numerics into triplets when not surrounded by a letter + 4. apply this.split: split input into terms (includes/excludes) + 5. apply this.filter (pre-filter) + 6. apply this.stemmer (replace term endings) + 7. apply this.filter (post-filter) + 8. apply this.mapper (replace chars) 9. apply this.dedupe (letter deduplication) - 10. apply this.finalize + 10. apply this.matcher (replace terms) + 11. apply this.replacer (custom regex) + 12. apply this.finalize */ const whitespace = /[^\p{L}\p{N}]+/u, @@ -62,6 +67,9 @@ const whitespace = /[^\p{L}\p{N}]+/u, export default function Encoder() { if (!this || this.constructor !== Encoder) { + // let args = Array.prototype.slice.call(arguments); + // args.unshift(Encoder); + // return new (Encoder.bind.apply(Encoder, args)); return new Encoder(...arguments); } @@ -79,8 +87,9 @@ Encoder.prototype.assign = function (options) { * pre-processing string input * @type {Function|boolean} */ - this.normalize = /** @type {Function|boolean} */parse_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ - /*await rows.hasNext()*/, this.normalize); + this.normalize = /** @type {Function|boolean} */merge_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ + /* skip_update: */ + /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize); // { // letter: true, @@ -93,68 +102,76 @@ Encoder.prototype.assign = function (options) { // } let include = options.include, - tmp = include || options.exclude || options.split; + tmp = include || options.exclude || options.split, + numeric; - if ("object" == typeof tmp) { - let numeric = !include, - regex = ""; + if (tmp || "" === tmp) { + if ("object" == typeof tmp && tmp.constructor !== RegExp) { + let regex = ""; + numeric = !include; + // split on whitespace by default + include || (regex += "\\p{Z}"); + if (tmp.letter) { + regex += "\\p{L}"; + } + if (tmp.number) { + regex += "\\p{N}"; + numeric = !!include; + } + if (tmp.symbol) { + regex += "\\p{S}"; + } + if (tmp.punctuation) { + regex += "\\p{P}"; + } + if (tmp.control) { + regex += "\\p{C}"; + } + if (tmp = tmp.char) { + regex += "object" == typeof tmp ? tmp.join("") : tmp; + } - // split on whitespace by default - options.include || (regex += "\\p{Z}"); - if (tmp.letter) { - regex += "\\p{L}"; - } - if (tmp.number) { - regex += "\\p{N}"; - numeric = !!include; - } - if (tmp.symbol) { - regex += "\\p{S}"; - } - if (tmp.punctuation) { - regex += "\\p{P}"; - } - if (tmp.control) { - regex += "\\p{C}"; - } - if (tmp = tmp.char) { - regex += "object" == typeof tmp ? tmp.join("") : tmp; + try { + // https://github.com/nextapps-de/flexsearch/issues/410 + /** + * split string input into terms + * @type {string|RegExp|boolean|null} + */ + this.split = new RegExp("[" + (include ? "^" : "") + regex + "]+", "u"); + } catch (e) { + // fallback to a simple whitespace splitter + this.split = /\s+/; + } + } else { + this.split = /** @type {string|RegExp|boolean} */tmp; + // determine numeric encoding + numeric = /* suggest */ /* append: */ /* enrich */!1 === tmp || 2 > "a1a".split(tmp).length; } - try { - // https://github.com/nextapps-de/flexsearch/issues/410 - /** - * split string input into terms - * @type {string|RegExp|boolean|null} - */ - this.split = new RegExp("[" + (include ? "^" : "") + regex + "]+", "u"); - } catch (e) { - // fallback to a simple whitespace splitter - this.split = /\s+/; - } - this.numeric = numeric; + this.numeric = merge_option(options.numeric, numeric); } else { try { // https://github.com/nextapps-de/flexsearch/issues/410 - this.split = /** @type {string|RegExp|boolean} */parse_option(tmp, whitespace, this.split); + this.split = /** @type {string|RegExp|boolean} */merge_option(this.split, whitespace); } catch (e) { // fallback to a simple whitespace splitter this.split = /\s+/; } - this.numeric = parse_option(this.numeric, !0); + + this.numeric = merge_option(options.numeric, merge_option(this.numeric, !0)); } /** * post-processing terms * @type {Function|null} */ - this.prepare = /** @type {Function|null} */parse_option(options.prepare, null, this.prepare); + this.prepare = /** @type {Function|null} */merge_option(options.prepare, null, this.prepare); /** * final processing * @type {Function|null} */ - this.finalize = /** @type {Function|null} */parse_option(options.finalize, null, this.finalize); + this.finalize = /** @type {Function|null} */merge_option(options.finalize, null, this.finalize); // assign the normalization fallback to the mapper if (!normalize) { @@ -164,24 +181,23 @@ Encoder.prototype.assign = function (options) { // options - this.rtl = options.rtl || /* suggest */ /* append: */ /* enrich */!1; - this.dedupe = parse_option(options.dedupe, !1, this.dedupe); - this.filter = parse_option((tmp = options.filter) && new Set(tmp), null, this.filter); - this.matcher = parse_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); - this.mapper = parse_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); - this.stemmer = parse_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); - this.replacer = parse_option(options.replacer, null, this.replacer); - this.minlength = parse_option(options.minlength, 1, this.minlength); - this.maxlength = parse_option(options.maxlength, 0, this.maxlength); + this.rtl = merge_option(options.rtl, !1, this.rtl); + this.dedupe = merge_option(options.dedupe, !1, this.dedupe); + this.filter = merge_option((tmp = options.filter) && new Set(tmp), null, this.filter); + this.matcher = merge_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); + this.mapper = merge_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); + this.stemmer = merge_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); + this.replacer = merge_option(options.replacer, null, this.replacer); + this.minlength = merge_option(options.minlength, 1, this.minlength); + this.maxlength = merge_option(options.maxlength, 0, this.maxlength); // minimum required tokenizer by this encoder //this.tokenize = options["tokenize"] || ""; // auto-balanced cache - this.cache = tmp = parse_option(options.cache, !0, this.cache); + this.cache = tmp = merge_option(options.cache, !0, this.cache); if (tmp) { - this.timer = null; - this.cache_size = "number" == typeof tmp ? tmp : 2e5; + this.timer = null;this.cache_size = "number" == typeof tmp ? tmp : 2e5; this.cache_enc = new Map(); this.cache_term = new Map(); this.cache_enc_length = 128; @@ -216,7 +232,7 @@ Encoder.prototype.assign = function (options) { } // if(SUPPORT_COMPRESSION){ - // this.compression = parse_option(options.compress || options.compression, 0, this.compression); + // this.compression = merge_option(options.compress || options.compression, 0, this.compression); // if(this.compression && !table){ // table = new Array(radix); // for(let i = 0; i < radix; i++) table[i] = i + 33; @@ -227,43 +243,33 @@ Encoder.prototype.assign = function (options) { return this; }; -Encoder.prototype.addMatcher = function (match, replace) { - // regex: - if ("object" == typeof match) { - return this.addReplacer(match, replace); - } - // a single char: - if (2 > match.length) { - return this.addMapper(match, replace); - } - this.matcher || (this.matcher = new Map()); - this.matcher.set(match, replace); - this.matcher_str += (this.matcher_str ? "|" : "") + match; - this.matcher_test = null; //new RegExp("(" + this.matcher_str + ")"); - this.cache && this.invalidate(); - return this; -}; - Encoder.prototype.addStemmer = function (match, replace) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(match, replace); this.stemmer_str += (this.stemmer_str ? "|" : "") + match; - this.stemmer_test = null; //new RegExp("(" + this.stemmer_str + ")"); - this.cache && this.invalidate(); + this.stemmer_test = null; + this.cache && clear(this); return this; }; -Encoder.prototype.addFilter = function (str) { +Encoder.prototype.addFilter = function (term) { this.filter || (this.filter = new Set()); - this.filter.add(str); - this.cache && this.invalidate(); + this.filter.add(term); + this.cache && clear(this); return this; }; +/** + * Replace a single char + * @param {string} char_match + * @param {string} char_replace + * @return {Encoder} + * @suppress {invalidCasts} + */ Encoder.prototype.addMapper = function (char_match, char_replace) { // regex: if ("object" == typeof char_match) { - return this.addReplacer(char_match, char_replace); + return this.addReplacer( /** @type {RegExp} */char_match, char_replace); } // not a char: if (1 < char_match.length) { @@ -271,24 +277,55 @@ Encoder.prototype.addMapper = function (char_match, char_replace) { } this.mapper || (this.mapper = new Map()); this.mapper.set(char_match, char_replace); - this.cache && this.invalidate(); + this.cache && clear(this); return this; }; -Encoder.prototype.addReplacer = function (match, replace) { - if ("string" == typeof match) match = new RegExp(match, "g"); +/** + * Replace a string + * @param {string} match + * @param {string} replace + * @return {Encoder} + * @suppress {invalidCasts} + */ +Encoder.prototype.addMatcher = function (match, replace) { + // regex: + if ("object" == typeof match) { + return this.addReplacer( /** @type {RegExp} */match, replace); + } + // a single char: + // only downgrade when dedupe is on or mapper already was filled + if (2 > match.length && (this.dedupe || this.mapper)) { + return this.addMapper(match, replace); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(match, replace); + this.matcher_str += (this.matcher_str ? "|" : "") + match; + this.matcher_test = null; + this.cache && clear(this); + return this; +}; + +/** + * @param {RegExp} regex + * @param {string} replace + * @return {Encoder} + * @suppress {invalidCasts} + */ +Encoder.prototype.addReplacer = function (regex, replace) { + if ("string" == typeof regex) { + return this.addMatcher( /** @type {string} */regex, replace); + } this.replacer || (this.replacer = []); - this.replacer.push(match, replace || ""); - this.cache && this.invalidate(); + this.replacer.push(regex, replace); + this.cache && clear(this); return this; }; -Encoder.prototype.invalidate = function () { - this.cache_enc.clear(); - this.cache_term.clear(); -}; - - +/** + * @param {!string} str + * @return {!Array} + */ Encoder.prototype.encode = function (str) { //if(!str) return str; @@ -304,7 +341,7 @@ Encoder.prototype.encode = function (str) { } } - // 1. apply charset normalization + // apply charset normalization if (this.normalize) { if ("function" == typeof this.normalize) { str = this.normalize(str); @@ -315,12 +352,12 @@ Encoder.prototype.encode = function (str) { } } - // 2. apply custom encoder (can replace split) + // apply custom encoder (can replace split) if (this.prepare) { str = this.prepare(str); } - // 3. split numbers into triplets + // split numbers into triplets if (this.numeric && 3 < str.length) { str = str.replace(numeric_split_prev_char, "$1 $2").replace(numeric_split_next_char, "$1 $2").replace(numeric_split_length, "$1 "); } @@ -356,7 +393,7 @@ Encoder.prototype.encode = function (str) { continue; } - // 1. pre-filter before cache + // pre-filter before cache if (this.filter && this.filter.has(word)) { continue; } @@ -364,11 +401,8 @@ Encoder.prototype.encode = function (str) { if (this.cache && word.length <= this.cache_term_length) { if (this.timer) { const tmp = this.cache_term.get(word); - //if(this.cache_term.has(word)){ if (tmp || "" === tmp) { - //word = this.cache_term.get(word); tmp && final.push(tmp); - //word ? words[i] = word : words.splice(i--, 1); continue; } } else { @@ -376,9 +410,7 @@ Encoder.prototype.encode = function (str) { } } - let postfilter; - - // 2. apply stemmer after matcher + // apply stemmer after matcher if (this.stemmer && 2 < word.length) { // for(const item of this.stemmer){ // const key = item[0]; @@ -397,18 +429,15 @@ Encoder.prototype.encode = function (str) { // } this.stemmer_test || (this.stemmer_test = new RegExp("(?!^)(" + this.stemmer_str + ")$")); word = word.replace(this.stemmer_test, match => this.stemmer.get(match)); - postfilter = 1; + + // 4. post-filter after matcher and stemmer was applied + if (word.length < this.minlength || this.filter && this.filter.has(word)) { + word = ""; + } } - // 4. post-filter after matcher and stemmer was applied - if (word && postfilter && (word.length < this.minlength || this.filter && this.filter.has(word))) { - word = ""; - } - - // 5. apply mapper and collapsing + // apply mapper and collapsing if (word && (this.mapper || this.dedupe && 1 < word.length)) { - //word = this.replace_dedupe(word); - //word = replace_deduped(word, this.mapper, true); let final = ""; for (let i = 0, prev = "", char, tmp; i < word.length; i++) { char = word.charAt(i); @@ -420,11 +449,13 @@ Encoder.prototype.encode = function (str) { word = final; } - // 3. apply matcher + // from here the input string can shrink, + // minlength should not apply + + // apply matcher if (this.matcher && 1 < word.length) { this.matcher_test || (this.matcher_test = new RegExp("(" + this.matcher_str + ")", "g")); word = word.replace(this.matcher_test, match => this.matcher.get(match)); - //postfilter = 1; } // apply custom regex @@ -439,10 +470,6 @@ Encoder.prototype.encode = function (str) { //word = word.replace(/(.)\1+/g, "$1"); //word = word.replace(/(?<=(.))\1+/g, ""); - // if(word){ - // words[i] = word; - // } - if (this.cache && base.length <= this.cache_term_length) { this.cache_term.set(base, word); if (this.cache_term.size > this.cache_size) { @@ -451,20 +478,9 @@ Encoder.prototype.encode = function (str) { } } - //word || words.splice(i--, 1); word && final.push(word); } - //words = final; - // else if(this.filter){ - // for(let i = 0, word; i < words.length; i++){ - // if((word = words[i]) && !this.filter.has(word)){ - // //filtered.push(word); - // words.splice(i--, 1); - // } - // } - // } - if (this.finalize) { final = this.finalize(final) || final; } @@ -513,6 +529,9 @@ Encoder.prototype.encode = function (str) { // return str; // } +/** + * @param {Encoder} self + */ function clear(self) { self.timer = null; self.cache_enc.clear(); diff --git a/dist/module/index.js b/dist/module/index.js index 6188394..0a43890 100644 --- a/dist/module/index.js +++ b/dist/module/index.js @@ -133,11 +133,14 @@ Index.prototype.clear = function () { * @param {!number|string} id * @param {!string} content */ - Index.prototype.append = function (id, content) { return this.add(id, content, !0); }; +/** + * @param {number|string} id + * @return {boolean|Promise} + */ Index.prototype.contain = function (id) { return this.db ? this.db.has(id) : this.reg.has(id); }; diff --git a/dist/module/index/remove.js b/dist/module/index/remove.js index b79ad2c..481d4ae 100644 --- a/dist/module/index/remove.js +++ b/dist/module/index/remove.js @@ -1,12 +1,11 @@ -import { create_object, is_array } from "../common.js"; +import { is_array } from "../common.js"; import Index, { autoCommit } from "../index.js"; -import default_compress from "../compress.js"; /** + * @param {!number|string} id * @param {boolean=} _skip_deletion */ - Index.prototype.remove = function (id, _skip_deletion) { const refs = this.reg.size && (this.fastupdate ? this.reg.get(id) : this.reg.has(id)); @@ -15,7 +14,7 @@ Index.prototype.remove = function (id, _skip_deletion) { if (this.fastupdate) { - // fast updates did not fully cleanup the key entries + // fast updates did not fully clean up the key entries for (let i = 0, tmp; i < refs.length; i++) { if (tmp = refs[i]) { @@ -95,8 +94,8 @@ Index.prototype.remove = function (id, _skip_deletion) { }; /** - * @param map - * @param id + * @param {!Map|Array>} map + * @param {!number|string} id * @return {number} */ @@ -125,7 +124,7 @@ function remove_index(map, id) { } } } - } else for (let item of map) { + } else for (let item of map.entries()) { const key = item[0], value = item[1], tmp = remove_index(value, id); diff --git a/dist/module/index/search.js b/dist/module/index/search.js index 895297d..b3ab191 100644 --- a/dist/module/index/search.js +++ b/dist/module/index/search.js @@ -1,6 +1,6 @@ -import { SearchOptions, SearchResults, EnrichedSearchResults } from "../type.js"; +import { SearchOptions, SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; import { create_object, is_object, sort_by_length_down } from "../common.js"; import Index from "../index.js"; import default_compress from "../compress.js"; @@ -8,18 +8,21 @@ import Resolver from "../resolver.js"; import { intersect } from "../intersect.js"; import resolve_default from "../resolve/default.js"; -let global_resolve = 1; -export function set_resolve(resolve) { - global_resolve = resolve; -} +// todo remove +// let global_resolve = 1; +// export function set_resolve(resolve){ +// global_resolve = resolve; +// } /** * @param {string|SearchOptions} query * @param {number|SearchOptions=} limit * @param {SearchOptions=} options - * @returns {SearchResults|EnrichedSearchResults|Resolver|Promise} + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } */ - Index.prototype.search = function (query, limit, options) { if (!options) { @@ -32,16 +35,20 @@ Index.prototype.search = function (query, limit, options) { } } + /** @type {!Array} */ let result = [], length, context, suggest, offset = 0, resolve, - enrich, tag, boost, - resolution; + resolution, + + // enrich is internally used just + // for the persistent indexes + enrich; if (options) { @@ -50,14 +57,14 @@ Index.prototype.search = function (query, limit, options) { offset = options.offset || 0; context = options.context; suggest = options.suggest; - resolve = global_resolve && /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; - resolve || (global_resolve = 0); + resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + //resolve || (global_resolve = 0); enrich = resolve && options.enrich; boost = options.boost; resolution = options.resolution; tag = this.db && options.tag; } else { - resolve = this.resolve || global_resolve; + resolve = this.resolve; // || global_resolve; } // todo: term deduplication during encoding when context is disabled @@ -67,7 +74,7 @@ Index.prototype.search = function (query, limit, options) { /** @type {Array} */ let query_terms = this.encoder.encode(query); length = query_terms.length; - limit || !resolve || (limit = 100); + limit = /** @type {!number} */limit || (resolve ? 100 : 0); // fast path single term if (1 === length) { @@ -88,79 +95,98 @@ Index.prototype.search = function (query, limit, options) { limit, offset, resolve, enrich, tag); } - let maxlength = 0, - minlength = 0; + // let maxlength = 0; + // let minlength = 0; + // + // if(length > 1){ + // + // // term deduplication will break the context chain + // // todo add context to dupe check + // const dupes = create_object(); + // const query_new = []; + // + // // if(context){ + // // keyword = query_terms[0]; + // // dupes[keyword] = 1; + // // query_new.push(keyword); + // // maxlength = minlength = keyword.length; + // // i = 1; + // // } + // + // for(let i = 0, term; i < length; i++){ + // + // term = query_terms[i]; + // + // if(term && !dupes[term]){ + // + // // todo add keyword check + // // this fast path can't apply to persistent indexes + // if(!suggest && !(SUPPORT_PERSISTENT && this.db) && !this.get_array(term/*, keyword*/)){ + // + // // fast path "not found" + // return !SUPPORT_RESOLVER || resolve + // ? result + // : new Resolver(result); + // } + // else{ + // + // query_new.push(term); + // dupes[term] = 1; + // } + // + // const term_length = term.length; + // maxlength = Math.max(maxlength, term_length); + // minlength = minlength ? Math.min(minlength, term_length) : term_length; + // } + // // else if(term && (!this.depth || context === false)){ + // // query_new.push(term); + // // } + // } + // + // query_terms = query_new; + // length = query_terms.length; + // } + // + // // the term length could be changed after deduplication + // + // if(!length){ + // return !SUPPORT_RESOLVER || resolve + // ? result + // : new Resolver(result); + // } + // + // // fast path single term + // if(length === 1){ + // return single_term_query.call( + // this, + // query_terms[0], // term + // "", // ctx + // limit, + // offset, + // resolve, + // enrich, + // tag + // ); + // } + // + // // fast path single context + // if(length === 2 && context && !suggest){ + // return single_term_query.call( + // this, + // query_terms[0], // term + // query_terms[1], // ctx + // limit, + // offset, + // resolve, + // enrich, + // tag + // ); + // } - - if (1 < length) { - - // term deduplication will break the context chain - // todo add context to dupe check - const dupes = create_object(), - query_new = []; - - - // if(context){ - // keyword = query_terms[0]; - // dupes[keyword] = 1; - // query_new.push(keyword); - // maxlength = minlength = keyword.length; - // i = 1; - // } - - for (let i = 0, term; i < length; i++) { - - term = query_terms[i]; - - if (term && !dupes[term]) { - - // todo add keyword check - // this fast path can't apply to persistent indexes - if (!suggest && !this.db && !this.get_array(term /*, keyword*/)) { - - // fast path "not found" - return resolve ? result : new Resolver(result); - } else { - - query_new.push(term); - dupes[term] = 1; - } - - const term_length = term.length; - maxlength = Math.max(maxlength, term_length); - minlength = minlength ? Math.min(minlength, term_length) : term_length; - } - // else if(term && (!this.depth || context === false)){ - // query_new.push(term); - // } - } - - query_terms = query_new; - length = query_terms.length; - } - - // the term length could be changed after deduplication - - if (!length) { - return resolve ? result : new Resolver(result); - } - - let index = 0, + let dupes = create_object(), + index = 0, keyword; - // fast path single term - if (1 === length) { - return single_term_query.call(this, query_terms[0], // term - "", // ctx - limit, offset, resolve, enrich, tag); - } - - // fast path single context - if (2 === length && context && !suggest) { - return single_term_query.call(this, query_terms[0], // term - query_terms[1], // ctx - limit, offset, resolve, enrich, tag); - } if (1 < length) { if (context) { @@ -169,17 +195,17 @@ Index.prototype.search = function (query, limit, options) { index = 1; } // todo - else if (9 < maxlength && 3 < maxlength / minlength) { - // sorting terms will break the context chain - // bigger terms has less occurrence - // this might also reduce the intersection task - // todo check intersection order - query_terms.sort(sort_by_length_down); - } + // else if(maxlength > 9 && (maxlength / minlength) > 3){ + // // sorting terms will break the context chain + // // bigger terms has less occurrence + // // this might also reduce the intersection task + // // todo check intersection order + // query_terms.sort(sort_by_length_down); + // } } if (!resolution && 0 !== resolution) { - resolution = this.resolution; + resolution = keyword ? this.resolution_ctx : this.resolution; } // from this point there are just multi-term queries @@ -199,56 +225,40 @@ Index.prototype.search = function (query, limit, options) { term = query_terms[index]; - if (keyword) { + if (term && !dupes[term]) { + dupes[term] = 1; arr = await self.get_array(term, keyword, 0, 0, !1, !1); - arr = add_result(arr, result, suggest, self.resolution_ctx - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 2 - // /*, term, keyword*/ - ); + arr = add_result(arr, /** @type {Array} */result, suggest, resolution); - // the context is a moving window where the keyword is going forward like a cursor - // 1. when suggestion enabled just forward keyword if term was found - // 2. as long as the result is empty forward the pointer also - if (!suggest || !1 !== arr || !result.length) { - keyword = term; + if (arr) { + result = arr; + break; } - } else { - arr = await self.get_array(term, "", 0, 0, !1, !1); - arr = add_result(arr, result, suggest, resolution - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 1 - // /*, term*/ - ); - } + if (keyword) { - // limit reached - if (arr) { - return arr; - } - - // apply suggestions on last loop - if (suggest && index == length - 1) { - let length = result.length; - if (!length) { - // fallback to non-contextual search when no result was found - if (keyword) { - keyword = ""; - index = -1; - continue; + // the context is a moving window where the keyword is going forward like a cursor + // 1. when suggestion enabled just forward keyword if term was found + // 2. as long as the result is empty forward the pointer also + if (!suggest || !arr || !result.length) { + keyword = term; } - return result; - } else if (1 === length) { - return resolve ? resolve_default(result[0], /** @type {number} */limit, offset) : new Resolver(result[0]); + } + } + + // fallback to non-contextual search when no result was found + if (suggest && keyword && index == length - 1) { + if (!result.length) { + keyword = ""; + index = -1; + dupes = create_object(); } } } - return resolve ? intersect(result, resolution, /** @type {number} */limit, offset, suggest, boost, resolve) : new Resolver(result[0]); + return return_result(result, resolution, + /** @type {!number} */limit, offset, suggest, boost, resolve); }(); } @@ -256,84 +266,97 @@ Index.prototype.search = function (query, limit, options) { term = query_terms[index]; - if (keyword) { + if (term && !dupes[term]) { + dupes[term] = 1; arr = this.get_array(term, keyword, 0, 0, !1, !1); - arr = /*this.*/add_result(arr, result, suggest, this.resolution_ctx - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 2 - // /*, term, keyword*/ - ); + arr = add_result(arr, /** @type {Array} */result, suggest, resolution); - // 1. when suggestion enabled just forward keyword if term was found - // 2. as long as the result is empty forward the pointer also - if (!suggest || !1 !== arr || !result.length) { - keyword = term; + if (arr) { + result = arr; + break; } - } else { - arr = this.get_array(term, "", 0, 0, !1, !1); - arr = /*this.*/add_result(arr, result, suggest, resolution - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 1 - // /*, term*/ - ); - } + if (keyword) { - // limit reached - if (arr) { - return (/** @type {Array} */arr - ); - } - - // apply suggestions on last loop - if (suggest && index == length - 1) { - const length = result.length; - if (!length) { - // fallback to non-contextual search when no result was found - if (keyword) { - keyword = ""; - index = -1; - continue; + // the context is a moving window where the keyword is going forward like a cursor + // 1. when suggestion enabled just forward keyword if term was found + // 2. as long as the result is empty forward the pointer also + if (!suggest || !arr || !result.length) { + keyword = term; } - return result; - } else if (1 === length) { - return resolve ? resolve_default(result[0], /** @type {number} */limit, offset) : new Resolver(result[0]); + } + } + + // fallback to non-contextual search when no result was found + if (suggest && keyword && index == length - 1) { + if (!result.length) { + keyword = ""; + index = -1; + dupes = create_object(); } } } - result = intersect(result, resolution, limit, offset, suggest, boost, resolve); - - return resolve ? result : new Resolver(result); + return return_result(result, resolution, + /** @type {!number} */limit, offset, suggest, boost, resolve); }; /** - * @param term - * @param keyword - * @param limit - * @param offset - * @param resolve - * @param enrich - * @param tag + * @param {!Array} result + * @param {number} resolution + * @param {number} limit + * @param {number=} offset + * @param {boolean=} suggest + * @param {number=} boost + * @param {boolean=} resolve + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } + */ + +function return_result(result, resolution, limit, offset, suggest, boost, resolve) { + let length = result.length, + final = result; + + + if (1 < length) { + final = intersect(result, resolution, /** @type {number} */limit, offset, suggest, boost, resolve); + } else if (1 === length) { + return resolve ? resolve_default.call(null, result[0], /** @type {number} */limit, offset) : new Resolver(result[0]); + } + + return resolve ? final : new Resolver(final); +} + +/** + * @param {!string} term + * @param {string|null} keyword + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @param {string=} tag * @this {Index} - * @return {Array|Resolver} + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } */ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag); + resolve = resolve; if (this.db) { return result.then(function (result) { - if (resolve) return result; - return result && result.length ? resolve ? resolve_default(result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver([]); + return resolve ? result || [] : new Resolver(result); }); } - return result && result.length ? resolve ? resolve_default(result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver([]); + return result && result.length ? resolve ? resolve_default.call(this, /** @type {SearchResults|EnrichedSearchResults} */result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver(); } /** @@ -342,69 +365,34 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { * or returns nothing when a set was pushed successfully to the results * * @private - * @param {Array} arr - * @param {Array} result - * @param {boolean|null=} suggest + * @param {IntermediateSearchResults} arr + * @param {Array} result + * @param {boolean=} suggest * @param {number=} resolution - * @return {Array|boolean|undefined} + * @return {Array|undefined} */ -function add_result(arr, result, suggest, resolution /*, limit, offset single_term, term, keyword*/) { +function add_result(arr, result, suggest, resolution) { let word_arr = []; - //let arr;// = keyword ? this.ctx : this.map; - //arr = this.get_array(term, keyword); - if (arr) { + if (arr && arr.length) { + + // short when resolution does not exceed: + if (arr.length <= resolution) { + result.push(arr); + // return nothing will continue the query + return; + } - //const resolution = Math.min(arr.length, keyword ? this.resolution_ctx : this.resolution); // apply reduced resolution for queries - resolution = Math.min(arr.length, resolution); - for (let x = 0, tmp; x < resolution; x++) { if (tmp = arr[x]) { - - // if(offset){ - // // apply offset right here on single terms - // if(tmp && single_term){ - // if(tmp.length <= offset){ - // offset -= tmp.length; - // tmp = null; - // } - // else{ - // tmp = tmp.slice(offset); - // offset = 0; - // } - // } - // } - - if (tmp) { - - // keep score (sparse array): - word_arr[x] = tmp; - // simplified score order: - //word_arr.push(tmp); - - // if(single_term){ - // size += tmp.length; - // if(size >= limit){ - // // fast path: - // // a single term does not need to pre-collect results - // break; - // } - // } - } + word_arr[x] = tmp; } } if (word_arr.length) { - // if(single_term){ - // // fast path optimization - // // offset was already applied at this point - // // return an array will stop the query process immediately - // return resolve_default(word_arr, limit, 0); - // } - result.push(word_arr); // return nothing will continue the query return; @@ -413,15 +401,33 @@ function add_result(arr, result, suggest, resolution /*, limit, offset single_te // 1. return an empty array will stop the loop // 2. return a false value to prevent stop when using suggestions - return !suggest && word_arr; + if (!suggest) return word_arr; } +/** + * @param {!string} term + * @param {string|null} keyword + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @param {string=} tag + * @return { + * IntermediateSearchResults|EnrichedSearchResults | + * Promise + * } + */ Index.prototype.get_array = function (term, keyword, limit, offset, resolve, enrich, tag) { let arr, swap; if (keyword) { swap = this.bidirectional && term > keyword; + if (swap) { + swap = keyword; + keyword = term; + term = swap; + } } if (this.compress) { @@ -430,18 +436,15 @@ Index.prototype.get_array = function (term, keyword, limit, offset, resolve, enr } if (this.db) { - return keyword ? this.db.get(swap ? keyword : term, // term - swap ? term : keyword, // ctx - limit, offset, resolve, enrich, tag) : this.db.get(term, "", // ctx - limit, offset, resolve, enrich, tag); + return this.db.get(term, keyword, limit, offset, resolve, enrich, tag); } if (keyword) { // the frequency of the starting letter is slightly less // on the last half of the alphabet (m-z) in almost every latin language, // so we sort downwards (https://en.wikipedia.org/wiki/Letter_frequency) - arr = this.ctx.get(swap ? term : keyword); - arr = arr && arr.get(swap ? keyword : term); + arr = this.ctx.get(keyword); + arr = arr && arr.get(term); } else { arr = this.map.get(term); } diff --git a/dist/module/intersect.js b/dist/module/intersect.js index f6e00a4..c5110f9 100644 --- a/dist/module/intersect.js +++ b/dist/module/intersect.js @@ -1,5 +1,6 @@ import { create_object, concat, sort_by_length_up, get_max_len } from "./common.js"; +import { SearchResults, IntermediateSearchResults } from "./type.js"; /* @@ -13,20 +14,20 @@ import { create_object, concat, sort_by_length_up, get_max_len } from "./common. */ /** - * @param arrays + * @param {!Array} arrays * @param {number} resolution - * @param limit - * @param offset - * @param suggest + * @param {number} limit + * @param {number=} offset + * @param {boolean=} suggest * @param {number=} boost * @param {boolean=} resolve - * @returns {Array} + * @returns {SearchResults|IntermediateSearchResults} */ - export function intersect(arrays, resolution, limit, offset, suggest, boost, resolve) { const length = arrays.length; + /** @type {Array} */ let result = [], check, count; @@ -71,7 +72,7 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res if (!resolve) { // boost everything after first result - let score = y + (x ? 0 : boost || 0); + let score = y + (x || !suggest ? 0 : boost || 0); tmp = tmp[score] || (tmp[score] = []); } @@ -95,7 +96,7 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res return []; } - result = result[result_len - 1]; + result = /** @type {SearchResults|IntermediateSearchResults} */result[result_len - 1]; if (limit || offset) { if (resolve) { @@ -123,36 +124,49 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res result = 1 < final.length ? concat(final) : final[0]; } - return result; + return (/** @type {SearchResults|IntermediateSearchResults} */result + ); } } else { - result = 1 < result.length ? union(result, offset, limit, resolve, 0) : (result = result[0]).length > limit || offset ? result.slice(offset, limit + offset) : result; + result = 1 < result.length ? union(result, limit, offset, resolve, boost) : (result = result[0]).length > limit || offset ? result.slice(offset, limit + offset) : result; } } - return result; + return (/** @type {SearchResults|IntermediateSearchResults} */result + ); } -export function union(arrays, offset, limit, resolve, boost) { +/** + * @param {Array} arrays + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {number=} boost + * @returns {SearchResults|IntermediateSearchResults} + */ +export function union(arrays, limit, offset, resolve, boost) { + + /** @type {SearchResults|IntermediateSearchResults} */ const result = [], check = create_object(); let ids, id, arr_len = arrays.length, - ids_len, - count = 0; + ids_len; + + //let maxres = get_max_len(arrays); if (!resolve) { - let maxres = get_max_len(arrays); + for (let i = arr_len - 1, res, count = 0; 0 <= i; i--) { - for (let k = 0; k < maxres; k++) { + res = arrays[i]; - for (let i = arr_len - 1; 0 <= i; i--) { + for (let k = 0; k < res.length; k++) { - ids = arrays[i][k]; + ids = res[k]; ids_len = ids && ids.length; if (ids_len) for (let j = 0; j < ids_len; j++) { @@ -164,8 +178,14 @@ export function union(arrays, offset, limit, resolve, boost) { if (offset) { offset--; } else { - let score = k + (i < arr_len - 1 ? boost || 0 : 0); - const arr = result[score] || (result[score] = []); + // adjust score to reduce resolution of suggestions + // todo: instead of applying the resolve task directly it could + // be added to the chain and resolved later, that will keep + // the original score but also can't resolve early because of + // nothing was found + let score = 0 | (k + (i < arr_len - 1 ? boost || 0 : 0)) / (i + 1), + arr = result[score] || (result[score] = []); + arr.push(id); if (++count === limit) { return result; @@ -175,26 +195,23 @@ export function union(arrays, offset, limit, resolve, boost) { } } } - } else { + } else for (let i = arr_len - 1; 0 <= i; i--) { - for (let i = arr_len - 1; 0 <= i; i--) { + ids = arrays[i]; + ids_len = ids && ids.length; - ids = arrays[i]; - ids_len = ids.length; + if (ids_len) for (let j = 0; j < ids_len; j++) { - for (let j = 0; j < ids_len; j++) { + id = ids[j]; - id = ids[j]; - - if (!check[id]) { - check[id] = 1; - if (offset) { - offset--; - } else { - result.push(id); - if (result.length === limit) { - return result; - } + if (!check[id]) { + check[id] = 1; + if (offset) { + offset--; + } else { + result.push(id); + if (result.length === limit) { + return result; } } } @@ -205,28 +222,42 @@ export function union(arrays, offset, limit, resolve, boost) { } /** - * @param {Array} mandatory - * @param {Array>} arrays - * @returns {Array} + * @param {SearchResults|IntermediateSearchResults} arrays + * @param {Array} mandatory + * @param {boolean=} resolve + * @returns {SearchResults} */ - -export function intersect_union(mandatory, arrays) { +export function intersect_union(arrays, mandatory, resolve) { const check = create_object(), result = []; + /** @type {SearchResults|IntermediateSearchResults} */ - - for (let x = 0, ids; x < arrays.length; x++) { - ids = arrays[x]; + for (let x = 0, ids; x < mandatory.length; x++) { + ids = mandatory[x]; for (let i = 0; i < ids.length; i++) { check[ids[i]] = 1; } } - for (let i = 0, id; i < mandatory.length; i++) { - id = mandatory[i]; - if (1 === check[id]) { - result.push(id); - check[id] = 2; + if (resolve) { + for (let i = 0, id; i < arrays.length; i++) { + id = arrays[i]; + if (check[id]) { + result.push(id); + check[id] = 0; + } + } + } else { + for (let i = 0, ids, id; i < arrays.result.length; i++) { + ids = arrays.result[i]; + for (let j = 0; j < ids.length; j++) { + id = ids[j]; + if (check[id]) { + const arr = result[i] || (result[i] = []); + arr.push(id); + check[id] = 0; + } + } } } diff --git a/dist/module/profiler.js b/dist/module/profiler.js index 560c690..6be5ade 100644 --- a/dist/module/profiler.js +++ b/dist/module/profiler.js @@ -1,3 +1,4 @@ + import { create_object } from "./common.js"; const data = create_object(); @@ -5,11 +6,4 @@ const data = create_object(); * @param {!string} name */ -export default function tick(name) { - - /** @type {!Object} */ - const profiler = data.profiler || (data.profiler = {}); - - profiler[name] || (profiler[name] = 0); - profiler[name]++; -} \ No newline at end of file +export default function tick() {} \ No newline at end of file diff --git a/dist/module/resolve/and.js b/dist/module/resolve/and.js index 40e09cd..1929674 100644 --- a/dist/module/resolve/and.js +++ b/dist/module/resolve/and.js @@ -1,202 +1,105 @@ import Resolver from "../resolver.js"; -import { create_object, get_max_len } from "../common.js"; -import { intersect as _intersect } from "../intersect.js"; -import { ResolverOptions } from "../type.js"; +import { get_max_len } from "../common.js"; +import { intersect } from "../intersect.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, ResolverOptions } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +/** @this {Resolver} */ Resolver.prototype.and = function () { - if (this.result.length) { - - const self = this; - let args = arguments, - first_argument = args[0]; + let execute = this.result.length, + limit, + offset, + enrich, + resolve; - if (first_argument.then) { - return first_argument.then(function () { - return self.and.apply(self, args); - }); + if (!execute) { + /** @type {ResolverOptions} */ + const arg = arguments[0]; + if (arg) { + execute = !!arg.suggest; + resolve = arg.resolve; + limit = arg.limit; + offset = arg.offset; + enrich = arg.enrich && resolve; } + } - if (first_argument[0]) { - // fix false passed parameter style - if (first_argument[0].index) { - return this.and.apply(this, first_argument); - } - } + if (execute) { - let final = [], - promises = [], - limit = 0, - offset = 0, + const { + final, + promises, + limit, + offset, enrich, resolve, - suggest; + suggest + } = this.handler("and", arguments); - - for (let i = 0, query; i < args.length; i++) { - - query = /** @type {string|ResolverOptions} */args[i]; - - if (query) { - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - suggest = query.suggest; - - let result; - if (query.constructor === Resolver) { - result = query.result; - } else if (query.constructor === Array) { - result = query; - } else if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; - result = query.index.search(query).result; - } else if (query.or) { - result = this.or(query.or); - } else if (query.xor) { - result = this.xor(query.xor); - } else if (query.not) { - result = this.not(query.not); - } else { - continue; - } - - final[i] = result; - - if (result.then) { - promises.push(result); //{ query, result }; - } - } - } - - if (!final.length) { - this.result = final; - return resolve ? this.result : this; - } - - if (promises.length) { - return Promise.all(promises).then(function () { - final = [self.result].concat(final); - self.result = intersect(final, limit, offset, enrich, resolve, self.boostval, suggest); - return resolve ? self.result : self; - }); - } - - final = [this.result].concat(final); - this.result = intersect(final, limit, offset, enrich, resolve, this.boostval, suggest); - return resolve ? this.result : this; + return return_result.call(this, final, promises, limit, offset, enrich, resolve, suggest); } - return this; + + return resolve ? this.resolve(limit, offset, enrich) : this; }; /** * Aggregate the intersection of N raw results - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @param suggest - * @return {Array} + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } */ -function intersect(result, limit, offset, enrich, resolve, boost, suggest) { +function return_result(final, promises, limit, offset, enrich, resolve, suggest) { - // if(!result.length){ - // // todo remove - // console.log("Empty Result") - // return result; - // } + if (promises.length) { + const self = this; + return Promise.all(promises).then(function (result) { - if (2 > result.length) { - return []; + final = []; + for (let i = 0, tmp; i < result.length; i++) { + if ((tmp = result[i]).length) { + final[i] = tmp; + } + } + + return return_result.call(self, final, [], limit, offset, enrich, resolve, suggest); + }); } - let contain = create_object(), - maxres = get_max_len(result); + if (!final.length) { + if (!suggest) { + this.result = /** @type {SearchResults|IntermediateSearchResults} */final; + } + } else { + //final = [this.result].concat(final); + this.result.length && final.unshift(this.result); - if (!maxres) return []; + if (2 > final.length) { + this.result = final[0]; + } else { + const resolution = get_max_len(final); + if (!resolution) { + this.result = []; + } else { + this.result = intersect(final, resolution, limit, offset, suggest, this.boostval, resolve); - //console.log(result) + return resolve ? enrich ? apply_enrich.call(this.index, /** @type {SearchResults} */this.result) : this.result : this; + } + } + } - return _intersect(result, maxres, limit, offset, suggest, boost, resolve); - - // for(let j = 0, ids, res = result[0]; j < res.length; j++){ - // ids = res[j]; - // for(let k = 0; k < ids.length; k++){ - // contain[ids[k]] = 1; - // } - // } - - // for(let i = 0, res; i < result.length; i++){ - // res = result[i]; - // if(!res || !res.length) return []; - // let contain_new = create_object(); - // let match = 0; - // let last_round = i === result.length - 1; - // - // for(let j = 0, ids; j < maxres; j++){ - // ids = res[j]; - // if(!ids) continue; - // - // for(let k = 0, id, min; k < ids.length; k++){ - // id = ids[k]; - // // fill in first round - // if(!i){ - // // shift resolution +1 - // // shift resolution by boost (inverse) - // contain_new[id] = j + 1 + (i ? boost : 0); - // match = 1; - // } - // // result in last round - // else if(last_round){ - // if((min = contain[id])){ - // match = 1; - // //if(!contain_new[id]){ - // if(offset){ - // offset--; - // continue; - // } - // if(resolve){ - // final.push(id); - // } - // else{ - // // reduce resolution -1 - // min--; - // if(j < min) min = j; - // final[min] || (final[min] = []); - // final[min].push(id); - // } - // if(limit && ++count === limit){ - // //this.boost = 0; - // return final; - // } - // // shift resolution +1 - // //contain_new[id] = min + 1; - // //} - // } - // } - // // check for intersection - // else if((min = contain[id])){ - // // shift resolution +1 - // if(j + 1 < min) min = j + 1; - // contain_new[id] = min; - // match = 1; - // } - // } - // } - // - // if(!match){ - // //this.boost = 0; - // return []; - // } - // - // contain = contain_new; - // } - // - // //this.boost = 0; - // return final; + return resolve ? this.resolve(limit, offset, enrich) : this; } \ No newline at end of file diff --git a/dist/module/resolve/default.js b/dist/module/resolve/default.js index ae75ab0..c280c35 100644 --- a/dist/module/resolve/default.js +++ b/dist/module/resolve/default.js @@ -1,4 +1,8 @@ import { concat } from "../common.js"; +import { IntermediateSearchResults, SearchResults, EnrichedSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +import Document from "../document.js"; +import Index from "../index.js"; /* from -> res[score][id] @@ -7,44 +11,29 @@ import { concat } from "../common.js"; /** * Aggregate the union of a single raw result - * @param {!Array} result + * @param {IntermediateSearchResults} result * @param {!number} limit * @param {number=} offset * @param {boolean=} enrich - * @return Array + * @return {SearchResults|EnrichedSearchResults} + * @this {Document|Index} */ export default function (result, limit, offset, enrich) { + if (!result.length) { + return result; + } + // fast path: when there is just one slot in the result if (1 === result.length) { - result = result[0]; - result = offset || result.length > limit ? limit ? result.slice(offset, offset + limit) : result.slice(offset) : result; - return enrich ? enrich_result(result) : result; + let final = result[0]; + final = offset || final.length > limit ? limit ? final.slice(offset, offset + limit) : final.slice(offset) : final; + return enrich ? apply_enrich.call(this, final) : final; } let final = []; - // this is a workaround without using arr.concat.apply - - // for(let i = 0, arr, len; i < result.length; i++){ - // if((arr = result[i])){ - // if((len = arr.length)){ - // for(let j = offset; j < len; j++){ - // final.push(arr[j]); - // if(final.length === limit){ - // return enrich - // ? enrich_result(final) - // : final; - // } - // } - // if((offset -= len) < 0){ - // offset = 0; - // } - // } - // } - // } - // this is an optimized workaround instead of // just doing result = concat(result) @@ -65,52 +54,47 @@ export default function (result, limit, offset, enrich) { } } + if (len > limit) { + arr = arr.slice(0, limit); + len = limit; + } + if (!final.length) { // fast path: when limit was reached in first slot if (len >= limit) { - if (len > limit) { - arr = arr.slice(0, limit); - } - return enrich ? enrich_result(arr) : arr; - } - } else { - if (len > limit) { - arr = arr.slice(0, limit); - len = arr.length; + return enrich ? apply_enrich.call(this, arr) : arr; } } final.push(arr); limit -= len; - // todo remove - // if(limit < 0){ - // throw new Error("Impl.Error"); - // } - // break if limit was reached if (!limit) { break; } } - // todo remove - if (!final.length) { - //throw new Error("No results found"); - return final; - } - final = 1 < final.length ? concat(final) : final[0]; - return enrich ? enrich_result(final) : final; + return enrich ? apply_enrich.call(this, final) : final; } -function enrich_result(ids) { - for (let i = 0; i < ids.length; i++) { - ids[i] = { - score: i, - id: ids[i] - }; - } - return ids; -} \ No newline at end of file +// /** +// * @param {SearchResults} ids +// * @return {EnrichedSearchResults} +// */ +// +// export function enrich_result(ids){ +// // ids could be the original reference to an index value +// /** @type {EnrichedSearchResults} */ +// const result = new Array(ids.length); +// for(let i = 0, id; i < ids.length; i++){ +// id = ids[i]; +// result[i] = { +// "id": id, +// "doc": this.store.get(id) +// }; +// } +// return result; +// } \ No newline at end of file diff --git a/dist/module/resolve/handler.js b/dist/module/resolve/handler.js new file mode 100644 index 0000000..36d487d --- /dev/null +++ b/dist/module/resolve/handler.js @@ -0,0 +1,98 @@ + +import Resolver from "../resolver.js"; +import { ResolverOptions, SearchResults, IntermediateSearchResults } from "../type.js"; + +/** + * @param {string} fn + * @param {Array>|Arguments} args + */ +Resolver.prototype.handler = function (fn, args) { + + /** @type {ResolverOptions|Promise} */ + let first_argument = args[0]; + + if (first_argument.then) { + const self = this; + // todo: check when this branch was taken + // instead of Promise.all the args[] array could be reduced + // by iterate recursively one by one + return Promise.all(args).then(function (args) { + return self[fn].apply(self, args); + }); + } + + if (first_argument[0]) { + // detect array parameter style + if (first_argument[0].index) { + return this[fn].apply(this, first_argument); + } + } + + /** @type {SearchResults|IntermediateSearchResults} */ + let final = [], + promises = [], + limit = 0, + offset = 0, + enrich, + resolve, + suggest; + /** @type {Array>} */ + + for (let i = 0, query; i < args.length; i++) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { + + let result; + if (query.constructor === Resolver) { + result = query.result; + } else if (query.constructor === Array) { + result = query; + } else { + + limit = query.limit || 0; + offset = query.offset || 0; + suggest = query.suggest; + resolve = query.resolve; + enrich = query.enrich && resolve; + + if (query.index) { + query.resolve = /* suggest */ /* append: */ /* enrich */!1; + + result = query.index.search(query).result; + query.resolve = resolve; + } else if (query.and) { + result = this.and(query.and); + } else if (query.or) { + result = this.or(query.or); + } else if (query.xor) { + result = this.xor(query.xor); + } else if (query.not) { + result = this.not(query.not); + } else { + continue; + } + } + + if (result.then) { + promises.push(result); + } else if (result.length) { + final[i] = result; + } else if (!suggest && ("and" === fn || "xor" === fn)) { + final = []; + break; + } + } + } + + return { + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + }; +}; \ No newline at end of file diff --git a/dist/module/resolve/not.js b/dist/module/resolve/not.js index 9f3839f..9466752 100644 --- a/dist/module/resolve/not.js +++ b/dist/module/resolve/not.js @@ -1,98 +1,83 @@ import Resolver from "../resolver.js"; -import { ResolverOptions } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +/** @this {Resolver} */ Resolver.prototype.not = function () { - const self = this; - let args = arguments, - first_argument = args[0]; + const { + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + } = this.handler("not", arguments); - if (first_argument.then) { - return first_argument.then(function () { - return self.not.apply(self, args); - }); - } - - if (first_argument[0]) { - // fix false passed parameter style - if (first_argument[0].index) { - return this.not.apply(this, first_argument); - } - } - - let final = [], - promises = [], - limit = 0, - offset = 0, - resolve; - - - for (let i = 0, query; i < args.length; i++) { - - query = /** @type {string|ResolverOptions} */args[i]; - - if (query) { - - limit = query.limit || 0; - offset = query.offset || 0; - query.enrich; - resolve = query.resolve; - - let result; - if (query.constructor === Resolver) { - result = query.result; - } else if (query.constructor === Array) { - result = query; - } else if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; - result = query.index.search(query).result; - } else if (query.or) { - result = this.or(query.or); - } else if (query.and) { - result = this.and(query.and); - } else if (query.xor) { - result = this.xor(query.xor); - } else { - continue; - } - - final[i] = result; - - if (result.then) { - promises.push(result); //{ query, result }; - } - } - } - - if (promises.length) { - return Promise.all(promises).then(function () { - self.result = exclusion.call(self, final, limit, offset, resolve); - return resolve ? self.result : self; - }); - } - - if (final.length) { - this.result = exclusion.call(this, final, limit, offset, resolve); - } - - return resolve ? this.result : this; + return return_result.call(this, final, promises, limit, offset, enrich, resolve, suggest); }; /** - * @param result - * @param limit - * @param offset - * @param resolve + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest * @this {Resolver} - * @return {Array} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } + */ + +function return_result(final, promises, limit, offset, enrich, resolve, suggest) { + + if (promises.length) { + const self = this; + return Promise.all(promises).then(function (result) { + + final = []; + for (let i = 0, tmp; i < result.length; i++) { + if ((tmp = result[i]).length) { + final[i] = tmp; + } + } + + return return_result.call(self, final, [], limit, offset, enrich, resolve, suggest); + }); + } + + if (final.length && this.result.length) { + this.result = exclusion.call(this, final, limit, offset, resolve); + } else if (resolve) { + return this.resolve(limit, offset, enrich); + } + + return resolve ? enrich ? apply_enrich.call(this.index, this.result) : this.result : this; +} + +/** + * @param {!Array} result + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @this {Resolver} + * @return {SearchResults|IntermediateSearchResults} */ function exclusion(result, limit, offset, resolve) { - if (!result.length) { - return this.result; - } + // if(!result.length){ + // return this.result; + // } + /** @type {SearchResults|IntermediateSearchResults} */ const final = [], exclude = new Set(result.flat().flat()); diff --git a/dist/module/resolve/or.js b/dist/module/resolve/or.js index b23a87b..13fa4e3 100644 --- a/dist/module/resolve/or.js +++ b/dist/module/resolve/or.js @@ -1,168 +1,73 @@ import Resolver from "../resolver.js"; -import default_resolver from "./default.js"; -import { union as _union } from "../intersect.js"; -import { ResolverOptions } from "../type.js"; +import { union } from "../intersect.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +/** @this {Resolver} */ Resolver.prototype.or = function () { - const self = this; - let args = arguments, - first_argument = args[0]; - - - if (first_argument.then) { - return first_argument.then(function () { - return self.or.apply(self, args); - }); - } - - if (first_argument[0]) { - // fix false passed parameter style - if (first_argument[0].index) { - return this.or.apply(this, first_argument); - } - } - - let final = [], - promises = [], - limit = 0, - offset = 0, + const { + final, + promises, + limit, + offset, enrich, - resolve; + resolve + } = this.handler("or", arguments); + return return_result.call(this, final, promises, limit, offset, enrich, resolve); +}; - for (let i = 0, query; i < args.length; i++) { +/** + * Aggregate the intersection of N raw results + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } + */ - query = /** @type {string|ResolverOptions} */args[i]; - - if (query) { - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - - let result; - if (query.constructor === Resolver) { - result = query.result; - } else if (query.constructor === Array) { - result = query; - } else if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; - result = query.index.search(query).result; - } else if (query.and) { - result = this.and(query.and); - } else if (query.xor) { - result = this.xor(query.xor); - } else if (query.not) { - result = this.not(query.not); - } else { - continue; - } - - final[i] = result; - - if (result.then) { - promises.push(result); //{ query, result }; - } - } - } +function return_result(final, promises, limit, offset, enrich, resolve) { if (promises.length) { - return Promise.all(promises).then(function () { - //self.result.length && (final = [self.result].concat(final)); - // the suggest-union was re-used from but there it needs reversed order - self.result.length && (final = final.concat([self.result])); - self.result = union(final, limit, offset, enrich, resolve, self.boostval); - return resolve ? self.result : self; + const self = this; + return Promise.all(promises).then(function (result) { + + final = []; + for (let i = 0, tmp; i < result.length; i++) { + if ((tmp = result[i]).length) { + final[i] = tmp; + } + } + + return return_result.call(self, final, [], limit, offset, enrich, resolve); }); } if (final.length) { - //this.result.length && (final = [this.result].concat(final)); - // the suggest-union was re-used but there it needs reversed order - this.result.length && (final = final.concat([this.result])); - this.result = union(final, limit, offset, enrich, resolve, this.boostval); - } - return resolve ? this.result : this; -}; + //this.result.length && (final = final.concat([this.result])); + this.result.length && final.push(this.result); -/** - * Aggregate the union of N raw results - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @return {Array} - */ - -function union(result, limit, offset, enrich, resolve, boost) { - - if (!result.length) { - // todo remove - //console.log("Empty Result") - return result; - } - - if ("object" == typeof limit) { - offset = limit.offset || 0; - enrich = limit.enrich || !1; - limit = limit.limit || 0; - } - - if (2 > result.length) { - // todo remove - //console.log("Single Result") - if (resolve) { - return default_resolver(result[0], limit, offset, enrich); + if (2 > final.length) { + this.result = final[0]; } else { - return result[0]; + // the suggest-union (reversed processing, resolve needs to be disabled) + this.result = union(final /*.reverse()*/ + , limit, offset, /* suggest */ /* append: */ /* enrich */ + /* resolve: */!1, this.boostval); + + // offset was already applied + offset = 0; } } - // the suggest-union - return _union(result /*.reverse()*/, offset, limit, resolve, boost); - - // let final = []; - // let count = 0; - // let dupe = create_object(); - // let maxres = get_max_len(result); - // - // for(let j = 0, ids; j < maxres; j++){ - // for(let i = 0, res; i < result.length; i++){ - // res = result[i]; - // if(!res) continue; - // ids = res[j]; - // if(!ids) continue; - // - // for(let k = 0, id; k < ids.length; k++){ - // id = ids[k]; - // if(!dupe[id]){ - // dupe[id] = 1; - // if(offset){ - // offset--; - // continue; - // } - // if(resolve){ - // final.push(id); - // } - // else{ - // // shift resolution by boost (inverse) - // const index = j + (boost || 0); - // final[index] || (final[index] = []); - // final[index].push(id); - // } - // if(limit && ++count === limit){ - // //this.boost = 0; - // return final; - // } - // } - // } - // } - // } - // - // //this.boost = 0; - // return final; + return resolve ? this.resolve(limit, offset, enrich) : this; } \ No newline at end of file diff --git a/dist/module/resolve/xor.js b/dist/module/resolve/xor.js index 9026feb..844bb7f 100644 --- a/dist/module/resolve/xor.js +++ b/dist/module/resolve/xor.js @@ -1,115 +1,96 @@ import Resolver from "../resolver.js"; import default_resolver from "./default.js"; import { create_object } from "../common.js"; -import { ResolverOptions } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +/** @this {Resolver} */ Resolver.prototype.xor = function () { - const self = this; - let args = arguments, - first_argument = args[0]; - - if (first_argument.then) { - return first_argument.then(function () { - return self.xor.apply(self, args); - }); - } - - if (first_argument[0]) { - // fix false passed parameter style - if (first_argument[0].index) { - return this.xor.apply(this, first_argument); - } - } - - let final = [], - promises = [], - limit = 0, - offset = 0, + const { + final, + promises, + limit, + offset, enrich, - resolve; + resolve, + suggest + } = this.handler("xor", arguments); - - for (let i = 0, query; i < args.length; i++) { - - query = /** @type {string|ResolverOptions} */args[i]; - - if (query) { - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - - let result; - if (query.constructor === Resolver) { - result = query.result; - } else if (query.constructor === Array) { - result = query; - } else if (query.index) { - query.resolve = /* suggest */ /* append: */ /* enrich */!1; - result = query.index.search(query).result; - } else if (query.or) { - result = this.or(query.or); - } else if (query.and) { - result = this.and(query.and); - } else if (query.not) { - result = this.not(query.not); - } else { - continue; - } - - final[i] = result; - - if (result.then) { - promises.push(result); //{ query, result }; - } - } - } - - if (promises.length) { - return Promise.all(promises).then(function () { - self.result.length && (final = [self.result].concat(final)); - self.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval); - return resolve ? self.result : self; - }); - } - - if (final.length) { - this.result.length && (final = [this.result].concat(final)); - this.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval); - } - return resolve ? this.result : this; + return return_result.call(this, final, promises, limit, offset, enrich, resolve, suggest); }; /** - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @return {Array} + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } */ -function exclusive(result, limit, offset, enrich, resolve, boost) { +function return_result(final, promises, limit, offset, enrich, resolve, suggest) { - if (!result.length) { - // todo remove - //console.log("Empty Result") - return result; + if (promises.length) { + const self = this; + return Promise.all(promises).then(function (result) { + + final = []; + for (let i = 0, tmp; i < result.length; i++) { + if ((tmp = result[i]).length) { + final[i] = tmp; + } + } + + return return_result.call(self, final, [], limit, offset, enrich, resolve, suggest); + }); } - if (2 > result.length) { - // todo remove - //console.log("Single Result") - if (resolve) { - return default_resolver(result[0], limit, offset, enrich); + if (!final.length) { + if (!suggest) this.result = /** @type {SearchResults|IntermediateSearchResults} */final; + } else { + //this.result.length && (final = [this.result].concat(final)); + this.result.length && final.unshift(this.result); + + if (2 > final.length) { + this.result = final[0]; } else { - return result[0]; + this.result = exclusive.call(this, final, limit, offset, resolve, this.boostval); + + return resolve ? enrich ? apply_enrich.call(this.index, /** @type {SearchResults} */this.result) : this.result : this; } } + return resolve ? this.resolve(limit, offset, enrich) : this; +} + +/** + * Aggregate the intersection of N raw results + * @param {!Array} result + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {number=} boost + * @this {Resolver} + * @return {SearchResults|IntermediateSearchResults} + */ + +function exclusive(result, limit, offset, resolve, boost) { + + // if(!result.length){ + // return result; + // } + + /** @type {SearchResults|IntermediateSearchResults} */ const final = [], check = create_object(); @@ -119,15 +100,15 @@ function exclusive(result, limit, offset, enrich, resolve, boost) { res = result[i]; if (!res) continue; + if (maxres < res.length) maxres = res.length; + for (let j = 0, ids; j < res.length; j++) { ids = res[j]; if (!ids) continue; - if (maxres < ids.length) maxres = ids.length; - for (let k = 0, id; k < ids.length; k++) { id = ids[k]; - check[id] ? check[id]++ : check[id] = 1; + check[id] = check[id] ? 2 : 1; } } } @@ -167,6 +148,5 @@ function exclusive(result, limit, offset, enrich, resolve, boost) { } } - //this.boost = 0; return final; } \ No newline at end of file diff --git a/dist/module/resolver.js b/dist/module/resolver.js index 63b7eec..4f80ec8 100644 --- a/dist/module/resolver.js +++ b/dist/module/resolver.js @@ -1,13 +1,17 @@ +import Index from "./index.js"; import default_resolver from "./resolve/default.js"; -import { set_resolve } from "./index/search.js"; -import { ResolverOptions } from "./type.js"; +//import { set_resolve } from "./index/search.js"; +import { apply_enrich } from "./document/search.js"; +import { ResolverOptions, IntermediateSearchResults } from "./type.js"; +import "./resolve/handler.js"; import "./resolve/or.js"; import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; /** - * @param {Array|ResolverOptions=} result + * @param {IntermediateSearchResults|ResolverOptions=} result + * @return {Resolver} * @constructor */ @@ -15,23 +19,30 @@ export default function Resolver(result) { if (!this || this.constructor !== Resolver) { return new Resolver(result); } + // if(result && result.constructor === Resolver){ + // // todo test this branch + // //console.log("Resolver Loopback") + // return /** @type {Resolver} */ (result); + // } if (result && result.index) { - result.resolve = /* suggest */ /* append: */ /* enrich */!1; - this.index = result.index; + // result = /** @type {ResolverOptions} */ (result); + result.resolve = /* suggest */ /* append: */ /* enrich */ /* resolve: */!1; + this.index = /** @type {Index} */result.index; this.boostval = result.boost || 0; this.result = result.index.search(result).result; return this; } - if (result.constructor === Resolver) { - // todo test this branch - //console.log("Resolver Loopback") - return result; - } + /** @type {Index|null} */ this.index = null; - this.result = result || []; + /** @type {IntermediateSearchResults} */ + this.result = /** @type {IntermediateSearchResults} */result || []; + /** @type {number} */ this.boostval = 0; } +/** + * @param {number} limit + */ Resolver.prototype.limit = function (limit) { if (this.result.length) { const final = []; @@ -51,6 +62,9 @@ Resolver.prototype.limit = function (limit) { return this; }; +/** + * @param {number} offset + */ Resolver.prototype.offset = function (offset) { if (this.result.length) { const final = []; @@ -69,6 +83,9 @@ Resolver.prototype.offset = function (offset) { return this; }; +/** + * @param {number} boost + */ Resolver.prototype.boost = function (boost) { this.boostval += boost; return this; @@ -79,10 +96,12 @@ Resolver.prototype.boost = function (boost) { * @param {number=} offset * @param {boolean=} enrich */ - Resolver.prototype.resolve = function (limit, offset, enrich) { - set_resolve(1); - const result = this.result; + + //set_resolve(1); + const result = this.result, + index = this.index; + this.index = null; this.result = null; @@ -92,7 +111,16 @@ Resolver.prototype.resolve = function (limit, offset, enrich) { offset = limit.offset; limit = limit.limit; } - return default_resolver(result, limit || 100, offset, enrich); + // const document = this.index; + // if(document.index){ + // result = default_resolver(result, limit || 100, offset, false); + // return enrich + // ? apply_enrich.call(document, result) + // : result; + // } + // else{ + return default_resolver.call(index, result, limit || 100, offset, enrich); + // } } return result; diff --git a/dist/module/serialize.js b/dist/module/serialize.js index 1d807b6..67e6878 100644 --- a/dist/module/serialize.js +++ b/dist/module/serialize.js @@ -7,6 +7,11 @@ const chunk_size_reg = 250000, chunk_size_ctx = 1000; +/** + * @param {Map} map + * @param {number=} size + * @return {Array} + */ function map_to_json(map, size = 0) { let chunk = [], json = []; @@ -25,13 +30,19 @@ function map_to_json(map, size = 0) { return chunk; } +/** + * @param {Array} json + * @param {Map=} map + * @return {Map} + */ function json_to_map(json, map) { map || (map = new Map()); for (let i = 0, entry; i < json.length; i++) { entry = json[i]; map.set(entry[0], entry[1]); } - return map; + return (/** @type {Map} */map + ); } function ctx_to_json(ctx, size = 0) { @@ -89,9 +100,17 @@ function json_to_reg(json, reg) { } /** + * + * @param {function(string, string):Promise|void} callback + * @param {string|null|void} field + * @param {string} key + * @param {Array|null} chunk + * @param {number} index_doc + * @param {number} index_obj + * @param {number=} index_prt * @this {Index|Document} + * @return {Promise} */ - function save(callback, field, key, chunk, index_doc, index_obj, index_prt = 0) { const is_arr = chunk && chunk.constructor === Array, data = is_arr ? chunk.shift() : chunk; @@ -114,17 +133,17 @@ function save(callback, field, key, chunk, index_doc, index_obj, index_prt = 0) /** * @param {function(string,string):Promise|void} callback - * @param {string|null=} field - * @param {number=} index_doc - * @param {number=} index_obj + * @param {!string|null=} _field + * @param {number=} _index_doc + * @param {number=} _index_obj * @this {Index} */ -export function exportIndex(callback, field, index_doc, index_obj = 0) { +export function exportIndex(callback, _field, _index_doc = 0, _index_obj = 0) { let key, chunk; - switch (index_obj) { + switch (_index_obj) { case 0: @@ -156,12 +175,12 @@ export function exportIndex(callback, field, index_doc, index_obj = 0) { return; } - return save.call(this, callback, field, key, chunk, index_doc, index_obj); + return save.call(this, callback, _field, key, chunk, _index_doc, _index_obj); } /** * @param {string} key - * @param {string|*} data + * @param {string|Array} data * @this Index */ @@ -170,8 +189,8 @@ export function importIndex(key, data) { if (!data) { return; } - if (is_string(data)) { - data = JSON.parse( /** @type {string} */data); + if ("string" == typeof data) { + data = /** @type {Array} */JSON.parse( /** @type {string} */data); } const split = key.split("."); @@ -189,7 +208,7 @@ export function importIndex(key, data) { case "reg": // fast update isn't supported by export/import - this.fastupdate = /* suggest */ /* append: */ /* enrich */!1; + this.fastupdate = /* suggest */ /* append: */ /* enrich */ /* resolve: */!1; this.reg = json_to_reg(data, this.reg); break; @@ -207,60 +226,60 @@ export function importIndex(key, data) { /** * @param {function(string,string):Promise|void} callback - * @param {string|null=} field - * @param {number=} index_doc - * @param {number=} index_obj + * @param {string|null=} _field + * @param {number=} _index_doc + * @param {number=} _index_obj * @this {Document} */ -export function exportDocument(callback, field, index_doc = 0, index_obj = 0) { +export function exportDocument(callback, _field, _index_doc = 0, _index_obj = 0) { - if (index_doc < this.field.length) { - const field = this.field[index_doc], + if (_index_doc < this.field.length) { + const field = this.field[_index_doc], idx = this.index.get(field), - res = idx.export(callback, field, index_doc, index_obj = 1); + res = idx.export(callback, field, _index_doc, _index_obj = 1); // start from index 1, because document indexes does not additionally store register if (res && res.then) { const self = this; return res.then(function () { - return self.export(callback, field, index_doc + 1); + return self.export(callback, field, _index_doc + 1); }); } - return this.export(callback, field, index_doc + 1); + return this.export(callback, field, _index_doc + 1); } else { let key, chunk; - switch (index_obj) { + switch (_index_obj) { case 0: key = "reg"; chunk = reg_to_json(this.reg); - field = null; + _field = null; break; case 1: key = "tag"; chunk = ctx_to_json(this.tag, this.reg.size); - field = null; + _field = null; break; case 2: key = "doc"; chunk = map_to_json(this.store); - field = null; + _field = null; break; case 3: key = "cfg"; chunk = {}; - field = null; + _field = null; break; default: @@ -268,13 +287,13 @@ export function exportDocument(callback, field, index_doc = 0, index_obj = 0) { return; } - return save.call(this, callback, field, key, chunk, index_doc, index_obj); + return save.call(this, callback, _field, key, chunk, _index_doc, _index_obj); } } /** - * @param key - * @param {string|*} data + * @param {!string} key + * @param {string|Array} data * @this {Document} */ @@ -283,8 +302,8 @@ export function importDocument(key, data) { if (!data) { return; } - if (is_string(data)) { - data = JSON.parse( /** @type {string} */data); + if ("string" == typeof data) { + data = /** @type {Array} */JSON.parse( /** @type {string} */data); } const split = key.split("."); diff --git a/dist/module/type.js b/dist/module/type.js index b586bbe..9c0e2c6 100644 --- a/dist/module/type.js +++ b/dist/module/type.js @@ -17,7 +17,6 @@ import StorageInterface from "./db/interface.js"; * keystore: (number|undefined), * rtl: (boolean|undefined), * cache: (number|boolean|undefined), - * resolve: (boolean|undefined), * db: (StorageInterface|undefined), * commit: (boolean|undefined), * worker: (string|undefined), @@ -131,9 +130,9 @@ export let SearchOptions = {}; * suggest: (boolean|undefined), * enrich: (boolean|undefined), * tag: (Object|Array|undefined), - * field: (Array|Array|string|undefined), - * index: (Array|Array|undefined), - * pluck: (string|undefined), + * field: (Array|Array|DocumentSearchOptions|string|undefined), + * index: (Array|Array|DocumentSearchOptions|string|undefined), + * pluck: (string|DocumentSearchOptions|undefined), * merge: (boolean|undefined), * highlight: (string|undefined), * }} @@ -142,16 +141,23 @@ export let DocumentSearchOptions = {}; /** * @typedef Array + * @global */ -export let SearchResults = {}; +export let SearchResults = []; + +/** + * @typedef Array> + * @global + */ +export let IntermediateSearchResults = []; /** * @typedef Array<{ * id: (number|string), - * res: number + * doc: (Object|null) * }> */ -export let EnrichedSearchResults = {}; +export let EnrichedSearchResults = []; /** * @typedef Array<{ @@ -160,20 +166,17 @@ export let EnrichedSearchResults = {}; * result: SearchResults * }> */ -export let DocumentSearchResults = {}; +export let DocumentSearchResults = []; /** * @typedef Array<{ * field: (string|undefined), * tag: (string|undefined), * highlight: (string|undefined), - * result: Array<{ - * id: (number|string), - * doc: (Object|null) - * }> + * result: {EnrichedSearchResults} * }> */ -export let EnrichedDocumentSearchResults = {}; +export let EnrichedDocumentSearchResults = []; /** * @typedef Array<{ @@ -183,7 +186,7 @@ export let EnrichedDocumentSearchResults = {}; * tag: (Array|undefined) * }> */ -export let MergedDocumentSearchResults = {}; +export let MergedDocumentSearchResults = []; /** * @typedef {{ @@ -204,6 +207,7 @@ export let EncoderSplitOptions = {}; * include: (EncoderSplitOptions|undefined), * exclude: (EncoderSplitOptions|undefined), * split: (string|boolean|undefined), + * numeric: (boolean|undefined), * normalize: (boolean|(function(string):string)|undefined), * prepare: ((function(string):string)|undefined), * finalize: ((function(Array):(Array|void))|undefined), diff --git a/index.d.ts b/index.d.ts index c7e4d9a..70956ff 100644 --- a/index.d.ts +++ b/index.d.ts @@ -81,7 +81,6 @@ declare module "flexsearch" { resolution?: number; context?: boolean; resolve?: boolean; - enrich?: boolean; }; /** @@ -116,6 +115,7 @@ declare module "flexsearch" { include?: EncoderSplitOptions; exclude?: EncoderSplitOptions; split?: string|RegExp|""|false; + numeric?: boolean; prepare?: (str: string) => string; finalize?: (terms: string[]) => string[]; filter?: Set; @@ -171,7 +171,6 @@ declare module "flexsearch" { resolution?: number; context?: ContextOptions | boolean; keystore?: number; - resolve?: boolean; fastupdate?: boolean; score?: ( content: string[], @@ -315,7 +314,6 @@ declare module "flexsearch" { filter?: (content: string) => boolean; custom?: (content: string) => string; config?: WorkerConfigURL | WorkerConfigPath; - resolve: true; }; type TagOptions = { @@ -323,7 +321,6 @@ declare module "flexsearch" { filter?: (content: string) => boolean; custom?: (content: string) => string; db?: StorageInterface; - resolve: true; }; type StoreOptions = { @@ -331,7 +328,6 @@ declare module "flexsearch" { filter?: (content: string) => boolean; custom?: (content: string) => string; db?: StorageInterface; - resolve: true; }; /* @@ -343,7 +339,6 @@ declare module "flexsearch" { worker?: boolean | WorkerURL | WorkerPath; doc?: DocumentDescriptor | DocumentDescriptor[]; document?: DocumentDescriptor | DocumentDescriptor[]; - resolve: true; }; type DefaultDocumentSearchResults = Array<{ @@ -392,11 +387,12 @@ declare module "flexsearch" { type DocumentSearchOptions = SearchOptions & { tag?: Object | Array; - field?: Array | Array | string; - index?: Array | Array; - pluck?: FieldName; + field?: Array | DocumentSearchOptions | string[] | string; + index?: Array | DocumentSearchOptions | string[] | string; + pluck?: FieldName | DocumentSearchOptions; + enrich?: boolean; merge?: boolean; - hightlight?: TemplateResultHighlighting; + highlight?: TemplateResultHighlighting; }; type DocumentValue = @@ -552,7 +548,7 @@ declare module "flexsearch" { }; type ResolverOptions = DefaultResolve & { - index?: Index; + index?: Index | Document; resolve?: boolean; suggest?: boolean; and?: ResolverOptions | Array; diff --git a/package-lock.json b/package-lock.json index f76596f..c1594be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.103", + "version": "0.8.105", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.103", + "version": "0.8.105", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 88bc089..d794c0d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.103", + "version": "0.8.105", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", @@ -31,22 +31,25 @@ "exports": { ".": "./dist/flexsearch.bundle.min.js", "./lang/*": "./dist/lang/*.min.js", - "./lang/*.js": "./dist/lang/*.min.js", "./db/*": "./dist/db/*/index.cjs", - "./db/*/index": "./dist/db/*/index.cjs", - "./db/*/index.js": "./dist/db/*/index.cjs", "./esm": "./dist/flexsearch.bundle.module.min.js", "./esm/": "./dist/flexsearch.bundle.module.min.js", "./esm/lang/*": "./dist/module/lang/*.js", - "./esm/lang/*.js": "./dist/module/lang/*.js", "./esm/db/*": "./dist/module/db/*/index.js", - "./esm/db/*/index": "./dist/module/db/*/index.js", - "./esm/db/*/index.js": "./dist/module/db/*/index.js" + "./debug": "./dist/flexsearch.bundle.debug.js", + "./debug/lang/*": "./dist/lang/*.min.js", + "./debug/db/*": "./dist/db/*/index.cjs", + "./esm/debug": "./dist/flexsearch.bundle.module.debug.js", + "./esm/debug/": "./dist/flexsearch.bundle.module.debug.js", + "./esm/debug/lang/*": "./dist/module-debug/lang/*.js", + "./esm/debug/db/*": "./dist/module-debug/db/*/index.js" }, "module": "dist/flexsearch.bundle.module.min.js", "browser": { "dist/flexsearch.bundle.min.js": "./dist/flexsearch.bundle.min.js", "dist/flexsearch.bundle.module.min.js": "./dist/flexsearch.bundle.module.min.js", + "dist/flexsearch.bundle.debug.js": "./dist/flexsearch.bundle.debug.js", + "dist/flexsearch.bundle.module.debug.js": "./dist/flexsearch.bundle.module.debug.js", "worker_threads": false, "path": false, "clickhouse": false, @@ -67,7 +70,7 @@ "build:es5": "node task/build RELEASE=es5 DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false LANGUAGE_OUT=ECMASCRIPT5_STRICT", "build:es5:debug": "node task/build RELEASE=es5 DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=true SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT LANGUAGE_OUT=ECMASCRIPT5_STRICT", "build:lang": "node task/build RELEASE=lang", - "build:db": "npx rollup tmp/db/indexeddb/index.js --file dist/db/indexeddb/index.js --format es && npx rollup src/db/postgres/index.js --file dist/db/postgres/index.cjs --format cjs && npx rollup src/db/sqlite/index.js --file dist/db/sqlite/index.cjs --format cjs && npx rollup src/db/mongodb/index.js --file dist/db/mongodb/index.cjs --format cjs && npx rollup src/db/redis/index.js --file dist/db/redis/index.cjs --format cjs && npx rollup src/db/clickhouse/index.js --file dist/db/clickhouse/index.cjs --format cjs", + "build:db": "npx rollup tmp/db/indexeddb/index.js --file dist/db/indexeddb/index.js --format es && npx rollup tmp/db/postgres/index.js --file dist/db/postgres/index.cjs --format cjs && npx rollup tmp/db/sqlite/index.js --file dist/db/sqlite/index.cjs --format cjs && npx rollup tmp/db/mongodb/index.js --file dist/db/mongodb/index.cjs --format cjs && npx rollup tmp/db/redis/index.js --file dist/db/redis/index.cjs --format cjs && npx rollup tmp/db/clickhouse/index.js --file dist/db/clickhouse/index.cjs --format cjs", "build:module": "node task/babel && exit 0", "build:module:debug": "node task/babel DEBUG=true && exit 0", "build:module:min": "node task/babel RELEASE=min && exit 0", diff --git a/src/bundle.js b/src/bundle.js index ecbc11b..dc95714 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -118,6 +118,7 @@ if(SUPPORT_PERSISTENT){ /** @export */ StorageInterface.db; /** @export */ StorageInterface.id; /** @export */ StorageInterface.support_tag_search; +/** @export */ StorageInterface.fastupdate; /** @export */ StorageInterface.prototype.mount; /** @export */ StorageInterface.prototype.open; /** @export */ StorageInterface.prototype.close; diff --git a/src/common.js b/src/common.js index 88470f8..cbc8b2b 100644 --- a/src/common.js +++ b/src/common.js @@ -5,7 +5,7 @@ * @return {*} */ -export function parse_option(value, default_value, merge_value){ +export function merge_option(value, default_value, merge_value){ const type_merge = typeof merge_value; const type_value = typeof value; diff --git a/src/config.js b/src/config.js index 2c2c2e5..24d6904 100644 --- a/src/config.js +++ b/src/config.js @@ -8,7 +8,7 @@ export const DEBUG = true; export const PROFILER = true; /** @define {boolean} */ -export const POLYFILL = true; +export const POLYFILL = false; /** @define {boolean} */ export const SUPPORT_WORKER = true; diff --git a/src/db/indexeddb/index.js b/src/db/indexeddb/index.js index faeca18..d46e69a 100644 --- a/src/db/indexeddb/index.js +++ b/src/db/indexeddb/index.js @@ -5,7 +5,11 @@ import { SUPPORT_TAGS } from "../../config.js"; // <-- COMPILER BLOCK -import { PersistentOptions } from "../../type.js"; +import { + PersistentOptions, + SearchResults, + EnrichedSearchResults +} from "../../type.js"; const VERSION = 1; const IndexedDB = typeof window !== "undefined" && ( @@ -28,6 +32,10 @@ const fields = ["map", "ctx", "tag", "reg", "cfg"]; import StorageInterface from "../interface.js"; import { toArray } from "../../common.js"; +/** + * @param {!string} str + * @return {string} + */ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } @@ -52,7 +60,9 @@ export default function IdxDB(name, config = {}){ } this.id = "flexsearch" + (name ? ":" + sanitize(name) : ""); this.field = config.field ? sanitize(config.field) : ""; + this.type = config.type; this.support_tag_search = false; + this.fastupdate = false; this.db = null; this.trx = {}; }; @@ -132,8 +142,12 @@ IdxDB.prototype.close = function(){ this.db = null; }; +/** + * @return {!Promise} + */ IdxDB.prototype.destroy = function(){ - return IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const req = IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return promisfy(req); }; // IdxDB.prototype.set = function(ref, key, ctx, data){ @@ -150,6 +164,9 @@ IdxDB.prototype.destroy = function(){ // return transaction;//promisfy(req, callback); // }; +/** + * @return {!Promise} + */ IdxDB.prototype.clear = function(){ const transaction = this.db.transaction(fields, "readwrite"); for(let i = 0; i < fields.length; i++){ @@ -158,6 +175,15 @@ IdxDB.prototype.clear = function(){ return promisfy(transaction); }; +/** + * @param {!string} key + * @param {string=} ctx + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @return {!Promise} + */ IdxDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, enrich = false){ const transaction = this.db.transaction(ctx ? "ctx" : "map", "readonly"); const map = transaction.objectStore(ctx ? "ctx" : "map"); @@ -200,6 +226,13 @@ IdxDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, if(SUPPORT_TAGS){ + /** + * @param {!string} tag + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} enrich + * @return {!Promise} + */ IdxDB.prototype.tag = function(tag, limit = 0, offset = 0, enrich = false){ const transaction = this.db.transaction("tag", "readonly"); const map = transaction.objectStore("tag"); @@ -218,6 +251,10 @@ if(SUPPORT_TAGS){ if(SUPPORT_STORE){ + /** + * @param {SearchResults} ids + * @return {!Promise} + */ IdxDB.prototype.enrich = function(ids){ if(typeof ids !== "object"){ ids = [ids]; @@ -240,6 +277,10 @@ if(SUPPORT_STORE){ }; } +/** + * @param {number|string} id + * @return {!Promise} + */ IdxDB.prototype.has = function(id){ const transaction = this.db.transaction("reg", "readonly"); const map = transaction.objectStore("reg"); @@ -505,7 +546,7 @@ IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ /** * @param {IDBCursorWithValue} cursor - * @param {Array} ids + * @param {Array} ids * @param {boolean=} _tag */ @@ -558,6 +599,10 @@ function handle(cursor, ids, _tag){ cursor.continue(); } +/** + * @param {Array} ids + * @return {!Promise} + */ IdxDB.prototype.remove = function(ids){ if(typeof ids !== "object"){ diff --git a/src/db/interface.js b/src/db/interface.js index ea35670..35e364d 100644 --- a/src/db/interface.js +++ b/src/db/interface.js @@ -1,3 +1,5 @@ +import { PersistentOptions, SearchResults, EnrichedSearchResults } from "../type.js"; + /** * @interface */ @@ -20,9 +22,22 @@ StorageInterface.prototype.destroy = async function(){}; // transfer all changes of an index to the database StorageInterface.prototype.commit = async function(index, _replace, _append){}; -// get results of a term "key" with optional context "ctx" +/** + * get results of a term "key" with optional context "ctx" + * @param {!string} key + * @param {string=} ctx + * @param {number=} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @return {!Promise} + */ StorageInterface.prototype.get = async function(key, ctx, limit, offset, resolve, enrich){}; -// get documents stored in index (enrich result) +/** + * get documents stored in index (enrich result) + * @param {SearchResults} ids + * @return {!Promise} + */ StorageInterface.prototype.enrich = async function(ids){}; // check if id exists on a specific index StorageInterface.prototype.has = async function(id){}; diff --git a/src/document.js b/src/document.js index f485de6..b5e1c1b 100644 --- a/src/document.js +++ b/src/document.js @@ -21,6 +21,7 @@ import { // <-- COMPILER BLOCK import { IndexOptions, DocumentOptions, DocumentDescriptor, FieldOptions, StoreOptions } from "./type.js"; +import StorageInterface from "./db/interface.js"; import Index from "./index.js"; import WorkerIndex from "./worker.js"; import Cache, { searchCache } from "./cache.js"; @@ -35,6 +36,7 @@ import "./document/search.js"; * @constructor * @param {!DocumentOptions} options * @return {Document|Promise} + * @this {Document} */ export default function Document(options){ @@ -87,7 +89,7 @@ export default function Document(options){ // } /** - * @type {Map} + * @type {Map} * @export */ this.index = parse_descriptor.call(this, options, document); @@ -141,7 +143,7 @@ export default function Document(options){ return Promise.all(promises).then(function(promises){ let count = 0; for(const item of self.index.entries()){ - const key = item[0]; + const key = /** @type {string} */ (item[0]); const index = item[1]; index.then && self.index.set(key, promises[count++]); } @@ -156,6 +158,10 @@ export default function Document(options){ if(SUPPORT_PERSISTENT){ + /** + * @param {!StorageInterface} db + * @return {Promise>} + */ Document.prototype.mount = function(db){ let fields = this.field; @@ -354,14 +360,28 @@ function parse_tree(key, marker){ return count > 1 ? tree : tree[0]; } +/** + * @param {!number|Object} id + * @param {!Object} content + * @return {Document|Promise} + */ Document.prototype.append = function(id, content){ return this.add(id, content, true); }; +/** + * @param {!number|Object} id + * @param {!Object} content + * @return {Document|Promise} + */ Document.prototype.update = function(id, content){ return this.remove(id).add(id, content); }; +/** + * @param {!number|Object} id + * @return {Document|Promise} + */ Document.prototype.remove = function(id){ if(is_object(id)){ @@ -435,6 +455,10 @@ Document.prototype.clear = function(){ :*/ }; +/** + * @param {number|string} id + * @return {boolean|Promise} + */ Document.prototype.contain = function(id){ if(SUPPORT_PERSISTENT && this.db){ @@ -455,6 +479,10 @@ Document.prototype.cleanup = function(){ if(SUPPORT_STORE){ + /** + * @param {number|string} id + * @return {Object} + */ Document.prototype.get = function(id){ if(SUPPORT_PERSISTENT && this.db){ @@ -466,9 +494,14 @@ if(SUPPORT_STORE){ return this.store.get(id); }; - Document.prototype.set = function(id, store){ + /** + * @param {number|string} id + * @param {Object} data + * @return {Document} + */ + Document.prototype.set = function(id, data){ - this.store.set(id, store); + this.store.set(id, data); return this; }; } diff --git a/src/document/search.js b/src/document/search.js index 8d627b7..37c6d30 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -1,6 +1,7 @@ // COMPILER BLOCK --> import { DEBUG, + PROFILER, SUPPORT_PERSISTENT, SUPPORT_RESOLVER, SUPPORT_STORE, @@ -12,25 +13,46 @@ import { DocumentSearchOptions, DocumentSearchResults, EnrichedDocumentSearchResults, - MergedDocumentSearchResults + MergedDocumentSearchResults, + EnrichedSearchResults, + SearchResults, + IntermediateSearchResults } from "../type.js"; import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; import { intersect_union } from "../intersect.js"; import Document from "../document.js"; - -let debug = false; +import Index from "../index.js"; +import Resolver from "../resolver.js"; +import tick from "../profiler.js"; /** * @param {!string|DocumentSearchOptions} query * @param {number|DocumentSearchOptions=} limit * @param {DocumentSearchOptions=} options - * @param {Array=} _promises For internal use only. - * @returns {DocumentSearchResults|EnrichedDocumentSearchResults|MergedDocumentSearchResults|Promise} + * @param {Array=} _promises async recursion + * @returns { + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * MergedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults| + * Resolver | + * Promise< + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * MergedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults| + * Resolver + * > + * } */ Document.prototype.search = function(query, limit, options, _promises){ - debug && console.log("checkoint:search", !!_promises); + PROFILER && tick("Document.search:" + !!_promises); if(!options){ if(!limit && is_object(query)){ @@ -43,6 +65,13 @@ Document.prototype.search = function(query, limit, options, _promises){ } } + /** @type { + * DocumentSearchResults| + * EnrichedDocumentSearchResults| + * SearchResults| + * IntermediateSearchResults| + * EnrichedSearchResults + * } */ let result = []; let result_field = []; let pluck, enrich, merge, suggest; @@ -59,22 +88,49 @@ Document.prototype.search = function(query, limit, options, _promises){ query = options.query || query; pluck = options.pluck; merge = options.merge; - field = pluck || options.field || options.index; + field = pluck || options.field || ((field = options.index) && (field.index ? null : field)); tag = SUPPORT_TAGS && this.tag && options.tag; - enrich = SUPPORT_STORE && this.store && options.enrich; suggest = SUPPORT_SUGGESTION && options.suggest; - highlight = options.highlight; - //resolve = !SUPPORT_RESOLVER || (options.resolve !== false); + resolve = !SUPPORT_RESOLVER || (options.resolve !== false); + + // upgrade pluck when missing + if(SUPPORT_RESOLVER && !resolve && !pluck){ + field = field || this.field; + if(field){ + if(is_string(field)){ + pluck = field; + } + else{ + if(is_array(field) && field.length === 1){ + field = field[0]; + } + pluck = field.field || field.index; + } + } + if(DEBUG && !pluck){ + throw new Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); + } + } + + if(DEBUG){ + if(SUPPORT_STORE && this.store && options.enrich && !resolve){ + console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + } + } + + enrich = SUPPORT_STORE && this.store && options.enrich && resolve; + highlight = options.highlight && enrich; limit = options.limit || limit; offset = options.offset || 0; limit || (limit = 100); if(tag && (!SUPPORT_PERSISTENT || !this.db || !_promises)){ + // ----------------------------- // Tag-Search // ----------------------------- - debug && console.log("checkoint:search:tag"); + PROFILER && tick("Document.search:tag"); if(tag.constructor !== Array){ tag = [tag]; @@ -139,11 +195,11 @@ Document.prototype.search = function(query, limit, options, _promises){ } continue; } - debug && console.log("checkoint:search:tag:get", pairs[j + 1]); + PROFILER && tick("Document.search:tag:get:" + pairs[j + 1]); promises.push(ids = index.db.tag(pairs[j + 1], limit, offset, enrich)); } else{ - debug && console.log("checkoint:search:tag:get", pairs[j + 1]); + PROFILER && tick("Document.search:tag:get:" + pairs[j + 1]); ids = get_tag.call(this, pairs[j], pairs[j + 1], limit, offset, enrich); } result.push({ @@ -167,7 +223,7 @@ Document.prototype.search = function(query, limit, options, _promises){ } // extend to multi field search by default - if(is_string(field)){ + if(field && field.constructor !== Array){ field = [field]; } } @@ -206,7 +262,7 @@ Document.prototype.search = function(query, limit, options, _promises){ res = _promises[i]; } else{ - debug && console.log("checkoint:search:get", key); + PROFILER && tick("Document.search:get:" + key); let opt = field_options || options; let index = this.index.get(key); @@ -228,14 +284,13 @@ Document.prototype.search = function(query, limit, options, _promises){ continue; } else{ - res = index.search(query, limit, opt); // restore enrich state opt && enrich && (opt.enrich = enrich); } } - len = res && res.length; + len = res && (resolve ? res.length : res.result.length); // todo when no term was matched but tag was retrieved extend suggestion to tags // every field has to intersect against all selected tag fields @@ -260,7 +315,9 @@ Document.prototype.search = function(query, limit, options, _promises){ } else if(!suggest){ // no tags found - return result; + return resolve + ? result + : new Resolver(result) } } } @@ -270,7 +327,7 @@ Document.prototype.search = function(query, limit, options, _promises){ // tag[] are pairs at this line for(let y = 0, ids, len; y < tag.length; y+=2){ - debug && console.log("checkoint:search:tag:get", tag[y + 1]); + PROFILER && tick("Document.search:tag:get:" + tag[y + 1]); ids = this.tag.get(tag[y]); if(!ids){ @@ -281,7 +338,9 @@ Document.prototype.search = function(query, limit, options, _promises){ continue; } else{ - return result; + return resolve + ? result + : new Resolver(result) } } @@ -294,18 +353,22 @@ Document.prototype.search = function(query, limit, options, _promises){ } else if(!suggest){ // no tags found - return result; + return resolve + ? result + : new Resolver(result) } } } if(count){ - debug && console.log("checkoint:search:tag:intersect"); - res = intersect_union(res, arr); // intersect(arr, limit, offset) + PROFILER && tick("Document.search:tag:intersect"); + res = intersect_union(res, arr, resolve); // intersect(arr, limit, offset) len = res.length; if(!len && !suggest){ // nothing matched - return result; + return resolve + ? res + : new Resolver(/** @type {IntermediateSearchResults} */ (res)); } // move counter back by 1 count--; @@ -319,7 +382,9 @@ Document.prototype.search = function(query, limit, options, _promises){ } else if(field.length === 1){ // fast path: nothing matched - return result; + return resolve + ? result + : new Resolver(result); } } @@ -339,10 +404,12 @@ Document.prototype.search = function(query, limit, options, _promises){ continue; } else{ - return result; + return resolve + ? result + : new Resolver(result); } } - debug && console.log("checkoint:search:tag:get", tag[y + 1]); + PROFILER && tick("Document.search:tag:get:" + tag[y + 1]); promises.push(index.db.tag(tag[y + 1], limit, offset, /* enrich */ false)); } } @@ -359,7 +426,9 @@ Document.prototype.search = function(query, limit, options, _promises){ } if(!count){ - return result; + return resolve + ? result + : new Resolver(result); } if(pluck && (!enrich || !this.store)){ return result[0]; @@ -373,19 +442,21 @@ Document.prototype.search = function(query, limit, options, _promises){ if(enrich && res.length && !res[0].doc){ if(!SUPPORT_PERSISTENT || !this.db){ - if(res.length){ + // if(res.length){ res = apply_enrich.call(this, res); - } + // } } else{ - debug && console.log("checkoint:search:doc:get"); + PROFILER && tick("Document.search:doc:get"); // the documents are stored on the first field promises.push(res = this.index.get(this.field[0]).db.enrich(res)); } } if(pluck){ - return res; + return resolve + ? res + : new Resolver(res); } result[i] = { @@ -540,7 +611,7 @@ function merge_fields(fields, limit, offset){ function get_tag(tag, key, limit, offset, enrich){ - debug && console.log("checkoint:search:tag:get", key); + PROFILER && tick("Document.search:tag:get:" + key); let res = this.tag.get(tag); if(!res){ DEBUG && console.warn("Tag '" + tag + "' was not found"); @@ -561,20 +632,25 @@ function get_tag(tag, key, limit, offset, enrich){ } /** - * @this {Document} + * @param {SearchResults} ids + * @return {EnrichedSearchResults|SearchResults} + * @this {Document|Index|null} */ -function apply_enrich(res){ +export function apply_enrich(ids){ - const arr = new Array(res.length); + if(!this || !this.store) return ids; - for(let x = 0, id; x < res.length; x++){ - id = res[x]; - arr[x] = { + /** @type {EnrichedSearchResults} */ + const result = new Array(ids.length); + + for(let x = 0, id; x < ids.length; x++){ + id = ids[x]; + result[x] = { "id": id, "doc": this.store.get(id) }; } - return arr; + return result; } diff --git a/src/encoder.js b/src/encoder.js index 9535157..af3efe8 100644 --- a/src/encoder.js +++ b/src/encoder.js @@ -1,10 +1,11 @@ // COMPILER BLOCK --> import { + DEBUG, SUPPORT_CACHE, SUPPORT_CHARSET } from "./config.js"; // <-- COMPILER BLOCK -import { parse_option } from "./common.js"; +import { merge_option } from "./common.js"; import normalize_polyfill from "./charset/normalize.js"; import { EncoderOptions } from "./type.js"; @@ -28,21 +29,26 @@ function fixedEncoder(string){ return [string] } -Built-in Encoder (Workflow) +Built-in Encoder ---------------------------- +The main workflow follows an increasing strategy, +starting from a simple .toLowerCase() to full RegExp Pipeline: 1. apply this.normalize: charset normalization: applied on the whole input string e.g. lowercase, - will also apply on: filter, matcher, stemmer, mapper - 2. apply this.split: split input into terms (includes/excludes) - 3. apply this.filter (pre-filter) - 4. apply this.matcher (replace terms) - 5. apply this.stemmer (replace term endings) - 6. apply this.filter (post-filter) - 7. apply this.mapper (replace chars) - 8. apply this.replacer (custom regex) + everything you put later into (filter, matcher, stemmer, mapper, etc.) + has to be normalized by definition, because it won't apply to them automatically + 2. apply this.prepare (custom preparation, string in - string out) + 3 split numerics into triplets when not surrounded by a letter + 4. apply this.split: split input into terms (includes/excludes) + 5. apply this.filter (pre-filter) + 6. apply this.stemmer (replace term endings) + 7. apply this.filter (post-filter) + 8. apply this.mapper (replace chars) 9. apply this.dedupe (letter deduplication) - 10. apply this.finalize + 10. apply this.matcher (replace terms) + 11. apply this.replacer (custom regex) + 12. apply this.finalize */ const whitespace = /[^\p{L}\p{N}]+/u; // /[\p{Z}\p{S}\p{P}\p{C}]+/u; @@ -64,6 +70,9 @@ const normalize = "".normalize && /[\u0300-\u036f]/g; // '´`’ʼ., export default function Encoder(options){ if(!this || this.constructor !== Encoder){ + // let args = Array.prototype.slice.call(arguments); + // args.unshift(Encoder); + // return new (Encoder.bind.apply(Encoder, args)); return new Encoder(...arguments); } @@ -82,7 +91,7 @@ Encoder.prototype.assign = function(options){ * @type {Function|boolean} */ this.normalize = /** @type {Function|boolean} */ ( - parse_option(options.normalize, true, this.normalize) + merge_option(options.normalize, true, this.normalize) ); // { @@ -97,58 +106,78 @@ Encoder.prototype.assign = function(options){ let include = options.include; let tmp = include || options.exclude || options.split; + let numeric; - if(typeof tmp === "object"){ - let numeric = !include; - let regex = ""; - // split on whitespace by default - options.include || ( - regex += "\\p{Z}" - ); - if(tmp.letter){ - regex += "\\p{L}"; + if(tmp || tmp === ""){ + if(typeof tmp === "object" && tmp.constructor !== RegExp){ + let regex = ""; + numeric = !include; + // split on whitespace by default + include || ( + regex += "\\p{Z}" + ); + if(tmp.letter){ + regex += "\\p{L}"; + } + if(tmp.number){ + regex += "\\p{N}"; + numeric = !!include; + } + if(tmp.symbol){ + regex += "\\p{S}"; + } + if(tmp.punctuation){ + regex += "\\p{P}"; + } + if(tmp.control){ + regex += "\\p{C}"; + } + if((tmp = tmp.char)){ + regex += typeof tmp === "object" + ? tmp.join("") + : tmp; + } + + try{ + // https://github.com/nextapps-de/flexsearch/issues/410 + /** + * split string input into terms + * @type {string|RegExp|boolean|null} + */ + this.split = new RegExp("[" + (include ? "^" : "") + regex + "]+", "u"); + } + catch(e){ + if(DEBUG){ + console.error("Your split configuration:", tmp, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /\s+/."); + } + // fallback to a simple whitespace splitter + this.split = /\s+/; + } } - if(tmp.number){ - regex += "\\p{N}"; - numeric = !!include; - } - if(tmp.symbol){ - regex += "\\p{S}"; - } - if(tmp.punctuation){ - regex += "\\p{P}"; - } - if(tmp.control){ - regex += "\\p{C}"; - } - if((tmp = tmp.char)){ - regex += typeof tmp === "object" ? tmp.join("") : tmp; + else{ + this.split = /** @type {string|RegExp|boolean} */ (tmp); + // determine numeric encoding + numeric = tmp === false || "a1a".split(tmp).length < 2; } - try{ - // https://github.com/nextapps-de/flexsearch/issues/410 - /** - * split string input into terms - * @type {string|RegExp|boolean|null} - */ - this.split = new RegExp("[" + (include ? "^" : "") + regex + "]+", "u"); - } - catch(e){ - // fallback to a simple whitespace splitter - this.split = /\s+/; - } - this.numeric = numeric; + this.numeric = merge_option(options.numeric, numeric); } else{ try{ // https://github.com/nextapps-de/flexsearch/issues/410 - this.split = /** @type {string|RegExp|boolean} */ (parse_option(tmp, whitespace, this.split)); + this.split = /** @type {string|RegExp|boolean} */ ( + merge_option(this.split, whitespace) + ); } catch(e){ + if(DEBUG){ + console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /\s+/."); + } // fallback to a simple whitespace splitter this.split = /\s+/; } - this.numeric = parse_option(this.numeric, true); + + this.numeric = merge_option(options.numeric, merge_option(this.numeric, true)); } /** @@ -156,14 +185,14 @@ Encoder.prototype.assign = function(options){ * @type {Function|null} */ this.prepare = /** @type {Function|null} */ ( - parse_option(options.prepare, null, this.prepare) + merge_option(options.prepare, null, this.prepare) ); /** * final processing * @type {Function|null} */ this.finalize = /** @type {Function|null} */ ( - parse_option(options.finalize, null, this.finalize) + merge_option(options.finalize, null, this.finalize) ); // assign the normalization fallback to the mapper @@ -177,22 +206,22 @@ Encoder.prototype.assign = function(options){ // options - this.rtl = options.rtl || false; - this.dedupe = parse_option(options.dedupe, false, this.dedupe); - this.filter = parse_option((tmp = options.filter) && new Set(tmp), null, this.filter); - this.matcher = parse_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); - this.mapper = parse_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); - this.stemmer = parse_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); - this.replacer = parse_option(options.replacer, null, this.replacer); - this.minlength = parse_option(options.minlength, 1, this.minlength); - this.maxlength = parse_option(options.maxlength, 0, this.maxlength); + this.rtl = merge_option(options.rtl, false, this.rtl); + this.dedupe = merge_option(options.dedupe, false, this.dedupe); + this.filter = merge_option((tmp = options.filter) && new Set(tmp), null, this.filter); + this.matcher = merge_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); + this.mapper = merge_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); + this.stemmer = merge_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); + this.replacer = merge_option(options.replacer, null, this.replacer); + this.minlength = merge_option(options.minlength, 1, this.minlength); + this.maxlength = merge_option(options.maxlength, 0, this.maxlength); // minimum required tokenizer by this encoder //this.tokenize = options["tokenize"] || ""; // auto-balanced cache if(SUPPORT_CACHE){ - this.cache = tmp = parse_option(options.cache, true, this.cache); + this.cache = tmp = merge_option(options.cache, true, this.cache); if(tmp){ this.timer = null; this.cache_size = typeof tmp === "number" ? tmp : 2e5; @@ -231,7 +260,7 @@ Encoder.prototype.assign = function(options){ } // if(SUPPORT_COMPRESSION){ - // this.compression = parse_option(options.compress || options.compression, 0, this.compression); + // this.compression = merge_option(options.compress || options.compression, 0, this.compression); // if(this.compression && !table){ // table = new Array(radix); // for(let i = 0; i < radix; i++) table[i] = i + 33; @@ -242,43 +271,33 @@ Encoder.prototype.assign = function(options){ return this; }; -Encoder.prototype.addMatcher = function(match, replace){ - // regex: - if(typeof match === "object"){ - return this.addReplacer(match, replace); - } - // a single char: - if(match.length < 2){ - return this.addMapper(match, replace); - } - this.matcher || (this.matcher = new Map()); - this.matcher.set(match , replace); - this.matcher_str += (this.matcher_str ? "|" : "") + match; - this.matcher_test = null; //new RegExp("(" + this.matcher_str + ")"); - SUPPORT_CACHE && this.cache && this.invalidate(); - return this; -}; - Encoder.prototype.addStemmer = function(match, replace){ this.stemmer || (this.stemmer = new Map()); this.stemmer.set(match, replace); this.stemmer_str += (this.stemmer_str ? "|" : "") + match; - this.stemmer_test = null; //new RegExp("(" + this.stemmer_str + ")"); - SUPPORT_CACHE && this.cache && this.invalidate(); + this.stemmer_test = null; + SUPPORT_CACHE && this.cache && clear(this); return this; }; -Encoder.prototype.addFilter = function(str){ +Encoder.prototype.addFilter = function(term){ this.filter || (this.filter = new Set()); - this.filter.add(str); - SUPPORT_CACHE && this.cache && this.invalidate(); + this.filter.add(term); + SUPPORT_CACHE && this.cache && clear(this); return this; }; +/** + * Replace a single char + * @param {string} char_match + * @param {string} char_replace + * @return {Encoder} + * @suppress {invalidCasts} + */ Encoder.prototype.addMapper = function(char_match, char_replace){ // regex: if(typeof char_match === "object"){ - return this.addReplacer(char_match, char_replace); + return this.addReplacer(/** @type {RegExp} */ (char_match), char_replace); } // not a char: if(char_match.length > 1){ @@ -286,25 +305,55 @@ Encoder.prototype.addMapper = function(char_match, char_replace){ } this.mapper || (this.mapper = new Map()); this.mapper.set(char_match, char_replace); - SUPPORT_CACHE && this.cache && this.invalidate(); + SUPPORT_CACHE && this.cache && clear(this); return this; }; -Encoder.prototype.addReplacer = function(match, replace){ - if(typeof match === "string") match = new RegExp(match, "g"); +/** + * Replace a string + * @param {string} match + * @param {string} replace + * @return {Encoder} + * @suppress {invalidCasts} + */ +Encoder.prototype.addMatcher = function(match, replace){ + // regex: + if(typeof match === "object"){ + return this.addReplacer(/** @type {RegExp} */ (match), replace); + } + // a single char: + // only downgrade when dedupe is on or mapper already was filled + if(match.length < 2 && (this.dedupe || this.mapper)){ + return this.addMapper(match, replace); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(match , replace); + this.matcher_str += (this.matcher_str ? "|" : "") + match; + this.matcher_test = null; + SUPPORT_CACHE && this.cache && clear(this); + return this; +}; + +/** + * @param {RegExp} regex + * @param {string} replace + * @return {Encoder} + * @suppress {invalidCasts} + */ +Encoder.prototype.addReplacer = function(regex, replace){ + if(typeof regex === "string"){ + return this.addMatcher(/** @type {string} */ (regex), replace); + } this.replacer || (this.replacer = []); - this.replacer.push(match, replace || ""); - SUPPORT_CACHE && this.cache && this.invalidate(); + this.replacer.push(regex, replace); + SUPPORT_CACHE && this.cache && clear(this); return this; }; -if(SUPPORT_CACHE){ - Encoder.prototype.invalidate = function(){ - this.cache_enc.clear(); - this.cache_term.clear(); - }; -} - +/** + * @param {!string} str + * @return {!Array} + */ Encoder.prototype.encode = function(str){ //if(!str) return str; @@ -321,7 +370,7 @@ Encoder.prototype.encode = function(str){ } } - // 1. apply charset normalization + // apply charset normalization if(this.normalize){ if(typeof this.normalize === "function"){ str = this.normalize(str); @@ -334,12 +383,12 @@ Encoder.prototype.encode = function(str){ } } - // 2. apply custom encoder (can replace split) + // apply custom encoder (can replace split) if(this.prepare){ str = this.prepare(str); } - // 3. split numbers into triplets + // split numbers into triplets if(this.numeric && str.length > 3){ str = str.replace(numeric_split_prev_char, "$1 $2") .replace(numeric_split_next_char, "$1 $2") @@ -378,7 +427,7 @@ Encoder.prototype.encode = function(str){ continue; } - // 1. pre-filter before cache + // pre-filter before cache if(this.filter && this.filter.has(word)){ continue; } @@ -386,11 +435,8 @@ Encoder.prototype.encode = function(str){ if(SUPPORT_CACHE && this.cache && word.length <= this.cache_term_length){ if(this.timer){ const tmp = this.cache_term.get(word); - //if(this.cache_term.has(word)){ if(tmp || tmp === ""){ - //word = this.cache_term.get(word); tmp && final.push(tmp); - //word ? words[i] = word : words.splice(i--, 1); continue; } } @@ -399,9 +445,7 @@ Encoder.prototype.encode = function(str){ } } - let postfilter; - - // 2. apply stemmer after matcher + // apply stemmer after matcher if(this.stemmer && (word.length > 2)){ // for(const item of this.stemmer){ // const key = item[0]; @@ -422,18 +466,15 @@ Encoder.prototype.encode = function(str){ this.stemmer_test = new RegExp("(?!^)(" + this.stemmer_str + ")$") ); word = word.replace(this.stemmer_test, match => this.stemmer.get(match)); - postfilter = 1; + + // 4. post-filter after matcher and stemmer was applied + if(word.length < this.minlength || (this.filter && this.filter.has(word))){ + word = ""; + } } - // 4. post-filter after matcher and stemmer was applied - if(word && postfilter && (word.length < this.minlength || (this.filter && this.filter.has(word)))){ - word = ""; - } - - // 5. apply mapper and collapsing + // apply mapper and collapsing if(word && (this.mapper || (this.dedupe && word.length > 1))){ - //word = this.replace_dedupe(word); - //word = replace_deduped(word, this.mapper, true); let final = ""; for(let i = 0, prev = "", char, tmp; i < word.length; i++){ char = word.charAt(i); @@ -448,13 +489,15 @@ Encoder.prototype.encode = function(str){ word = final; } - // 3. apply matcher + // from here the input string can shrink, + // minlength should not apply + + // apply matcher if(this.matcher && (word.length > 1)){ this.matcher_test || ( this.matcher_test = new RegExp("(" + this.matcher_str + ")", "g") ); word = word.replace(this.matcher_test, match => this.matcher.get(match)); - //postfilter = 1; } // apply custom regex @@ -469,10 +512,6 @@ Encoder.prototype.encode = function(str){ //word = word.replace(/(.)\1+/g, "$1"); //word = word.replace(/(?<=(.))\1+/g, ""); - // if(word){ - // words[i] = word; - // } - if(SUPPORT_CACHE && this.cache && base.length <= this.cache_term_length){ this.cache_term.set(base, word); if(this.cache_term.size > this.cache_size){ @@ -481,20 +520,9 @@ Encoder.prototype.encode = function(str){ } } - //word || words.splice(i--, 1); word && final.push(word); } - //words = final; - // else if(this.filter){ - // for(let i = 0, word; i < words.length; i++){ - // if((word = words[i]) && !this.filter.has(word)){ - // //filtered.push(word); - // words.splice(i--, 1); - // } - // } - // } - if(this.finalize){ final = this.finalize(final) || final; } @@ -543,6 +571,9 @@ Encoder.prototype.encode = function(str){ // return str; // } +/** + * @param {Encoder} self + */ function clear(self){ self.timer = null; self.cache_enc.clear(); diff --git a/src/index.js b/src/index.js index 2bc040d..c048a78 100644 --- a/src/index.js +++ b/src/index.js @@ -183,11 +183,14 @@ Index.prototype.clear = function(){ * @param {!number|string} id * @param {!string} content */ - Index.prototype.append = function(id, content){ return this.add(id, content, true); }; +/** + * @param {number|string} id + * @return {boolean|Promise} + */ Index.prototype.contain = function(id){ return SUPPORT_PERSISTENT && this.db ? this.db.has(id) diff --git a/src/index/remove.js b/src/index/remove.js index 17e71cd..905f76a 100644 --- a/src/index/remove.js +++ b/src/index/remove.js @@ -1,19 +1,16 @@ // COMPILER BLOCK --> import { SUPPORT_CACHE, - SUPPORT_COMPRESSION, - SUPPORT_KEYSTORE, SUPPORT_PERSISTENT } from "../config.js"; // <-- COMPILER BLOCK -import { create_object, is_array } from "../common.js"; +import { is_array } from "../common.js"; import Index, { autoCommit } from "../index.js"; -import default_compress from "../compress.js"; /** + * @param {!number|string} id * @param {boolean=} _skip_deletion */ - Index.prototype.remove = function(id, _skip_deletion){ const refs = this.reg.size && ( @@ -26,7 +23,7 @@ Index.prototype.remove = function(id, _skip_deletion){ if(this.fastupdate){ - // fast updates did not fully cleanup the key entries + // fast updates did not fully clean up the key entries for(let i = 0, tmp; i < refs.length; i++){ if((tmp = refs[i])){ @@ -114,8 +111,8 @@ Index.prototype.remove = function(id, _skip_deletion){ }; /** - * @param map - * @param id + * @param {!Map|Array>} map + * @param {!number|string} id * @return {number} */ @@ -147,7 +144,7 @@ function remove_index(map, id){ } } } - else for(let item of map){ + else for(let item of map.entries()){ const key = item[0]; const value = item[1]; const tmp = remove_index(value, id); diff --git a/src/index/search.js b/src/index/search.js index f0413a1..fbd0eb5 100644 --- a/src/index/search.js +++ b/src/index/search.js @@ -10,7 +10,7 @@ import { } from "../config.js"; // <-- COMPILER BLOCK -import { SearchOptions, SearchResults, EnrichedSearchResults } from "../type.js"; +import { SearchOptions, SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; import { create_object, is_object, sort_by_length_down } from "../common.js"; import Index from "../index.js"; import default_compress from "../compress.js"; @@ -18,18 +18,21 @@ import Resolver from "../resolver.js"; import { intersect } from "../intersect.js"; import resolve_default from "../resolve/default.js"; -let global_resolve = 1; -export function set_resolve(resolve){ - global_resolve = resolve; -} +// todo remove +// let global_resolve = 1; +// export function set_resolve(resolve){ +// global_resolve = resolve; +// } /** * @param {string|SearchOptions} query * @param {number|SearchOptions=} limit * @param {SearchOptions=} options - * @returns {SearchResults|EnrichedSearchResults|Resolver|Promise} + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } */ - Index.prototype.search = function(query, limit, options){ if(!options){ @@ -43,9 +46,19 @@ Index.prototype.search = function(query, limit, options){ } } + /** @type {!Array} */ let result = []; let length; - let context, suggest, offset = 0, resolve, enrich, tag, cache, boost, resolution; + let context, + suggest, + offset = 0, + resolve, + tag, + boost, + resolution, + // enrich is internally used just + // for the persistent indexes + enrich; if(options){ query = options.query || query; @@ -53,15 +66,15 @@ Index.prototype.search = function(query, limit, options){ offset = options.offset || 0; context = options.context; suggest = SUPPORT_SUGGESTION && options.suggest; - resolve = !SUPPORT_RESOLVER || (global_resolve && options.resolve !== false); - resolve || (global_resolve = 0); + resolve = !SUPPORT_RESOLVER || (/*global_resolve &&*/ options.resolve !== false); + //resolve || (global_resolve = 0); enrich = resolve && options.enrich; boost = options.boost; resolution = options.resolution; tag = SUPPORT_PERSISTENT && SUPPORT_DOCUMENT && SUPPORT_TAGS && this.db && options.tag; } else{ - resolve = !SUPPORT_RESOLVER || this.resolve || global_resolve; + resolve = !SUPPORT_RESOLVER || this.resolve; // || global_resolve; } // todo: term deduplication during encoding when context is disabled @@ -71,14 +84,14 @@ Index.prototype.search = function(query, limit, options){ /** @type {Array} */ let query_terms = this.encoder.encode(query); length = query_terms.length; - limit || !resolve || (limit = 100); + limit = /** @type {!number} */ (limit || (resolve ? 100 : 0)); // fast path single term if(length === 1){ return single_term_query.call( this, query_terms[0], // term - "", // ctx + "", // ctx limit, offset, resolve, @@ -106,96 +119,97 @@ Index.prototype.search = function(query, limit, options){ ); } - let maxlength = 0; - let minlength = 0; - - if(length > 1){ - - // term deduplication will break the context chain - // todo add context to dupe check - const dupes = create_object(); - const query_new = []; - - // if(context){ - // keyword = query_terms[0]; - // dupes[keyword] = 1; - // query_new.push(keyword); - // maxlength = minlength = keyword.length; - // i = 1; - // } - - for(let i = 0, term; i < length; i++){ - - term = query_terms[i]; - - if(term && !dupes[term]){ - - // todo add keyword check - // this fast path can't apply to persistent indexes - if(!suggest && !(SUPPORT_PERSISTENT && this.db) && !this.get_array(term/*, keyword*/)){ - - // fast path "not found" - return !SUPPORT_RESOLVER || resolve - ? result - : new Resolver(result); - } - else{ - - query_new.push(term); - dupes[term] = 1; - } - - const term_length = term.length; - maxlength = Math.max(maxlength, term_length); - minlength = minlength ? Math.min(minlength, term_length) : term_length; - } - // else if(term && (!this.depth || context === false)){ - // query_new.push(term); - // } - } - - query_terms = query_new; - length = query_terms.length; - } - - // the term length could be changed after deduplication - - if(!length){ - return !SUPPORT_RESOLVER || resolve - ? result - : new Resolver(result); - } + // let maxlength = 0; + // let minlength = 0; + // + // if(length > 1){ + // + // // term deduplication will break the context chain + // // todo add context to dupe check + // const dupes = create_object(); + // const query_new = []; + // + // // if(context){ + // // keyword = query_terms[0]; + // // dupes[keyword] = 1; + // // query_new.push(keyword); + // // maxlength = minlength = keyword.length; + // // i = 1; + // // } + // + // for(let i = 0, term; i < length; i++){ + // + // term = query_terms[i]; + // + // if(term && !dupes[term]){ + // + // // todo add keyword check + // // this fast path can't apply to persistent indexes + // if(!suggest && !(SUPPORT_PERSISTENT && this.db) && !this.get_array(term/*, keyword*/)){ + // + // // fast path "not found" + // return !SUPPORT_RESOLVER || resolve + // ? result + // : new Resolver(result); + // } + // else{ + // + // query_new.push(term); + // dupes[term] = 1; + // } + // + // const term_length = term.length; + // maxlength = Math.max(maxlength, term_length); + // minlength = minlength ? Math.min(minlength, term_length) : term_length; + // } + // // else if(term && (!this.depth || context === false)){ + // // query_new.push(term); + // // } + // } + // + // query_terms = query_new; + // length = query_terms.length; + // } + // + // // the term length could be changed after deduplication + // + // if(!length){ + // return !SUPPORT_RESOLVER || resolve + // ? result + // : new Resolver(result); + // } + // + // // fast path single term + // if(length === 1){ + // return single_term_query.call( + // this, + // query_terms[0], // term + // "", // ctx + // limit, + // offset, + // resolve, + // enrich, + // tag + // ); + // } + // + // // fast path single context + // if(length === 2 && context && !suggest){ + // return single_term_query.call( + // this, + // query_terms[0], // term + // query_terms[1], // ctx + // limit, + // offset, + // resolve, + // enrich, + // tag + // ); + // } + let dupes = create_object(); let index = 0, keyword; - // fast path single term - if(length === 1){ - return single_term_query.call( - this, - query_terms[0], // term - "", // ctx - limit, - offset, - resolve, - enrich, - tag - ); - } - - // fast path single context - if(length === 2 && context && !suggest){ - return single_term_query.call( - this, - query_terms[0], // term - query_terms[1], // ctx - limit, - offset, - resolve, - enrich, - tag - ); - } - if(length > 1){ if(context){ // start with context right away @@ -203,17 +217,19 @@ Index.prototype.search = function(query, limit, options){ index = 1; } // todo - else if(maxlength > 9 && (maxlength / minlength) > 3){ - // sorting terms will break the context chain - // bigger terms has less occurrence - // this might also reduce the intersection task - // todo check intersection order - query_terms.sort(sort_by_length_down); - } + // else if(maxlength > 9 && (maxlength / minlength) > 3){ + // // sorting terms will break the context chain + // // bigger terms has less occurrence + // // this might also reduce the intersection task + // // todo check intersection order + // query_terms.sort(sort_by_length_down); + // } } if(!resolution && resolution !== 0){ - resolution = this.resolution; + resolution = keyword + ? this.resolution_ctx + : this.resolution; } // from this point there are just multi-term queries @@ -233,70 +249,47 @@ Index.prototype.search = function(query, limit, options){ term = query_terms[index]; - if(keyword){ + if(term && !dupes[term]){ + dupes[term] = 1; arr = await self.get_array(term, keyword, 0, 0, false, false); - arr = add_result( - arr, - result, - suggest, - self.resolution_ctx, - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 2 - // /*, term, keyword*/ - ); + arr = add_result(arr, /** @type {Array} */ (result), suggest, resolution); - // the context is a moving window where the keyword is going forward like a cursor - // 1. when suggestion enabled just forward keyword if term was found - // 2. as long as the result is empty forward the pointer also - if(!suggest || (arr !== false) || !result.length){ - keyword = term; + if(arr){ + result = arr; + break; } - } - else{ - arr = await self.get_array(term, "", 0, 0, false, false); - arr = add_result( - arr, - result, - suggest, - resolution, - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 1 - // /*, term*/ - ); - } + if(keyword){ - // limit reached - if(arr){ - return arr; - } - - // apply suggestions on last loop - if(suggest && (index === length - 1)){ - let length = result.length; - if(!length){ - // fallback to non-contextual search when no result was found - if(keyword){ - keyword = ""; - index = -1; - continue; + // the context is a moving window where the keyword is going forward like a cursor + // 1. when suggestion enabled just forward keyword if term was found + // 2. as long as the result is empty forward the pointer also + if(!suggest || !arr || !result.length){ + keyword = term; } - return result; } - else if(length === 1){ - return !SUPPORT_RESOLVER || resolve - ? resolve_default(result[0], /** @type {number} */ (limit), offset) - : new Resolver(result[0]); + } + + // fallback to non-contextual search when no result was found + if(suggest && keyword && (index === length - 1)){ + if(!result.length){ + keyword = ""; + index = -1; + dupes = create_object(); } } } - return !SUPPORT_RESOLVER || resolve - ? intersect(result, resolution, /** @type {number} */ (limit), offset, suggest, boost, resolve) - : new Resolver(result[0]) + return return_result( + result, + resolution, + /** @type {!number} */ (limit), + offset, + suggest, + boost, + resolve + ); }()); } @@ -304,101 +297,118 @@ Index.prototype.search = function(query, limit, options){ term = query_terms[index]; - if(keyword){ + if(term && !dupes[term]){ + dupes[term] = 1; arr = this.get_array(term, keyword, 0, 0, false, false); - arr = /*this.*/add_result( - arr, - result, - suggest, - this.resolution_ctx, - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 2 - // /*, term, keyword*/ - ); + arr = add_result(arr, /** @type {Array} */ (result), suggest, resolution); - // 1. when suggestion enabled just forward keyword if term was found - // 2. as long as the result is empty forward the pointer also - if(!suggest || (arr !== false) || !result.length){ - keyword = term; + if(arr){ + result = arr; + break; } - } - else{ - arr = this.get_array(term, "", 0, 0, false, false); - arr = /*this.*/add_result( - arr, - result, - suggest, - resolution, - // 0, // /** @type {!number} */ (limit), - // 0, // offset, - // length === 1 - // /*, term*/ - ); - } + if(keyword){ - // limit reached - if(arr){ - return /** @type {Array} */ (arr); - } - - // apply suggestions on last loop - if(suggest && (index === length - 1)){ - const length = result.length; - if(!length){ - // fallback to non-contextual search when no result was found - if(keyword){ - keyword = ""; - index = -1; - continue; + // the context is a moving window where the keyword is going forward like a cursor + // 1. when suggestion enabled just forward keyword if term was found + // 2. as long as the result is empty forward the pointer also + if(!suggest || !arr || !result.length){ + keyword = term; } - return result; } - else if(length === 1){ - return !SUPPORT_RESOLVER || resolve - ? resolve_default(result[0], /** @type {number} */ (limit), offset) - : new Resolver(result[0]); + } + + // fallback to non-contextual search when no result was found + if(suggest && keyword && (index === length - 1)){ + if(!result.length){ + keyword = ""; + index = -1; + dupes = create_object(); } } } - result = intersect(result, resolution, limit, offset, suggest, boost, resolve); - - return !SUPPORT_RESOLVER || resolve - ? result - : new Resolver(result); + return return_result( + result, + resolution, + /** @type {!number} */ (limit), + offset, + suggest, + boost, + resolve + ); }; /** - * @param term - * @param keyword - * @param limit - * @param offset - * @param resolve - * @param enrich - * @param tag + * @param {!Array} result + * @param {number} resolution + * @param {number} limit + * @param {number=} offset + * @param {boolean=} suggest + * @param {number=} boost + * @param {boolean=} resolve + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } + */ + +function return_result(result, resolution, limit, offset, suggest, boost, resolve){ + + let length = result.length; + let final = result; + + if(length > 1){ + final = intersect(result, resolution, /** @type {number} */ (limit), offset, suggest, boost, resolve); + } + else if(length === 1){ + return !SUPPORT_RESOLVER || resolve + ? resolve_default.call(null, result[0], /** @type {number} */ (limit), offset) + : new Resolver(result[0]); + } + + return !SUPPORT_RESOLVER || resolve + ? final + : new Resolver(final); +} + +/** + * @param {!string} term + * @param {string|null} keyword + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @param {string=} tag * @this {Index} - * @return {Array|Resolver} + * @return { + * SearchResults|EnrichedSearchResults|Resolver | + * Promise + * } */ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag){ const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag); + resolve = !SUPPORT_RESOLVER || resolve; if(SUPPORT_PERSISTENT && this.db){ return result.then(function(result){ - if(resolve) return result; - return result && result.length - ? (!SUPPORT_RESOLVER || resolve ? resolve_default(result, limit, offset): new Resolver(result)) - : !SUPPORT_RESOLVER || resolve ? [] : new Resolver([]); + return resolve + ? result || [] + : new Resolver(result); }); } return result && result.length - ? (!SUPPORT_RESOLVER || resolve ? resolve_default(result, limit, offset) : new Resolver(result)) - : !SUPPORT_RESOLVER || resolve ? [] : new Resolver([]); + ? (resolve + ? resolve_default.call(this, /** @type {SearchResults|EnrichedSearchResults} */ (result), limit, offset) + : new Resolver(result) + ) + : resolve + ? [] + : new Resolver(); } /** @@ -407,69 +417,34 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag){ * or returns nothing when a set was pushed successfully to the results * * @private - * @param {Array} arr - * @param {Array} result - * @param {boolean|null=} suggest + * @param {IntermediateSearchResults} arr + * @param {Array} result + * @param {boolean=} suggest * @param {number=} resolution - * @return {Array|boolean|undefined} + * @return {Array|undefined} */ -function add_result(arr, result, suggest, resolution/*, limit, offset single_term, term, keyword*/){ +function add_result(arr, result, suggest, resolution){ let word_arr = []; - //let arr;// = keyword ? this.ctx : this.map; - //arr = this.get_array(term, keyword); - if(arr){ + if(arr && arr.length){ + + // short when resolution does not exceed: + if(arr.length <= resolution){ + result.push(arr); + // return nothing will continue the query + return; + } - //const resolution = Math.min(arr.length, keyword ? this.resolution_ctx : this.resolution); // apply reduced resolution for queries - resolution = Math.min(arr.length, resolution); - - for(let x = 0, size = 0, tmp; x < resolution; x++){ + for(let x = 0, tmp; x < resolution; x++){ if((tmp = arr[x])){ - - // if(offset){ - // // apply offset right here on single terms - // if(tmp && single_term){ - // if(tmp.length <= offset){ - // offset -= tmp.length; - // tmp = null; - // } - // else{ - // tmp = tmp.slice(offset); - // offset = 0; - // } - // } - // } - - if(tmp){ - - // keep score (sparse array): - word_arr[x] = tmp; - // simplified score order: - //word_arr.push(tmp); - - // if(single_term){ - // size += tmp.length; - // if(size >= limit){ - // // fast path: - // // a single term does not need to pre-collect results - // break; - // } - // } - } + word_arr[x] = tmp; } } if(word_arr.length){ - // if(single_term){ - // // fast path optimization - // // offset was already applied at this point - // // return an array will stop the query process immediately - // return resolve_default(word_arr, limit, 0); - // } - result.push(word_arr); // return nothing will continue the query return; @@ -478,15 +453,33 @@ function add_result(arr, result, suggest, resolution/*, limit, offset single_ter // 1. return an empty array will stop the loop // 2. return a false value to prevent stop when using suggestions - return !suggest && word_arr; + if(!suggest) return word_arr; } +/** + * @param {!string} term + * @param {string|null} keyword + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {boolean=} enrich + * @param {string=} tag + * @return { + * IntermediateSearchResults|EnrichedSearchResults | + * Promise + * } + */ Index.prototype.get_array = function(term, keyword, limit, offset, resolve, enrich, tag){ let arr, swap; if(keyword){ swap = this.bidirectional && (term > keyword); + if(swap){ + swap = keyword; + keyword = term; + term = swap; + } } if(SUPPORT_COMPRESSION && this.compress){ @@ -495,33 +488,23 @@ Index.prototype.get_array = function(term, keyword, limit, offset, resolve, enri } if(SUPPORT_PERSISTENT && this.db){ - return keyword - ? this.db.get( - swap ? keyword : term, // term - swap ? term : keyword, // ctx - limit, - offset, - resolve, - enrich, - tag - ) - : this.db.get( - term, - "", // ctx - limit, - offset, - resolve, - enrich, - tag - ); + return this.db.get( + term, + keyword, + limit, + offset, + resolve, + enrich, + tag + ); } if(keyword){ // the frequency of the starting letter is slightly less // on the last half of the alphabet (m-z) in almost every latin language, // so we sort downwards (https://en.wikipedia.org/wiki/Letter_frequency) - arr = this.ctx.get(swap ? term : keyword); - arr = arr && arr.get(swap ? keyword : term); + arr = this.ctx.get(keyword); + arr = arr && arr.get(term); } else{ arr = this.map.get(term); diff --git a/src/intersect.js b/src/intersect.js index 125dfc2..62b72b4 100644 --- a/src/intersect.js +++ b/src/intersect.js @@ -2,6 +2,7 @@ import { SUPPORT_RESOLVER } from "./config.js"; // <-- COMPILER BLOCK import { create_object, concat, sort_by_length_up, get_max_len } from "./common.js"; +import { SearchResults, IntermediateSearchResults } from "./type.js"; /* @@ -15,20 +16,20 @@ import { create_object, concat, sort_by_length_up, get_max_len } from "./common. */ /** - * @param arrays + * @param {!Array} arrays * @param {number} resolution - * @param limit - * @param offset - * @param suggest + * @param {number} limit + * @param {number=} offset + * @param {boolean=} suggest * @param {number=} boost * @param {boolean=} resolve - * @returns {Array} + * @returns {SearchResults|IntermediateSearchResults} */ - export function intersect(arrays, resolution, limit, offset, suggest, boost, resolve) { const length = arrays.length; + /** @type {Array} */ let result = []; let check; let count; @@ -73,7 +74,7 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res if(SUPPORT_RESOLVER && !resolve){ // boost everything after first result - let score = y + (x ? 0 : boost || 0); + let score = y + (x || !suggest ? 0 : boost || 0); tmp = tmp[score] || (tmp[score] = []); } @@ -97,7 +98,9 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res return []; } - result = result[result_len - 1]; + result = /** @type {SearchResults|IntermediateSearchResults} */ ( + result[result_len - 1] + ); if(limit || offset){ if(!SUPPORT_RESOLVER || resolve){ @@ -128,37 +131,52 @@ export function intersect(arrays, resolution, limit, offset, suggest, boost, res : final[0]; } - return result; + return /** @type {SearchResults|IntermediateSearchResults} */ ( + result + ); } } else{ result = result.length > 1 - ? union(result, offset, limit, resolve, 0) + ? union(result, limit, offset, resolve, boost) : ((result = result[0]).length > limit) || offset ? result.slice(offset, limit + offset) : result; } } - return result; + return /** @type {SearchResults|IntermediateSearchResults} */ ( + result + ); } -export function union(arrays, offset, limit, resolve, boost){ +/** + * @param {Array} arrays + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {number=} boost + * @returns {SearchResults|IntermediateSearchResults} + */ +export function union(arrays, limit, offset, resolve, boost){ + /** @type {SearchResults|IntermediateSearchResults} */ const result = []; const check = create_object(); - let ids, id, arr_len = arrays.length, ids_len, count = 0; + let ids, id, arr_len = arrays.length, ids_len; + + //let maxres = get_max_len(arrays); if(SUPPORT_RESOLVER && !resolve){ - let maxres = get_max_len(arrays); + for(let i = arr_len - 1, res, count = 0; i >= 0; i--){ - for(let k = 0; k < maxres; k++){ + res = arrays[i]; - for(let i = arr_len - 1; i >= 0; i--){ + for(let k = 0; k < res.length; k++){ - ids = arrays[i][k]; + ids = res[k]; ids_len = ids && ids.length; if(ids_len) for(let j = 0; j < ids_len; j++){ @@ -171,8 +189,13 @@ export function union(arrays, offset, limit, resolve, boost){ offset--; } else{ - let score = k + (i < arr_len - 1 ? boost || 0 : 0); - const arr = result[score] || (result[score] = []); + // adjust score to reduce resolution of suggestions + // todo: instead of applying the resolve task directly it could + // be added to the chain and resolved later, that will keep + // the original score but also can't resolve early because of + // nothing was found + let score = (k + (i < arr_len - 1 ? boost || 0 : 0)) / (i + 1) | 0; + let arr = result[score] || (result[score] = []); arr.push(id); if(++count === limit){ return result; @@ -183,27 +206,24 @@ export function union(arrays, offset, limit, resolve, boost){ } } } - else{ + else for(let i = arr_len - 1; i >= 0; i--){ - for(let i = arr_len - 1; i >= 0; i--){ + ids = arrays[i]; + ids_len = ids && ids.length; - ids = arrays[i]; - ids_len = ids.length; + if(ids_len) for(let j = 0; j < ids_len; j++){ - for(let j = 0; j < ids_len; j++){ + id = ids[j]; - id = ids[j]; - - if(!check[id]){ - check[id] = 1; - if(offset){ - offset--; - } - else{ - result.push(id); - if(result.length === limit){ - return result; - } + if(!check[id]){ + check[id] = 1; + if(offset){ + offset--; + } + else{ + result.push(id); + if(result.length === limit){ + return result; } } } @@ -214,28 +234,44 @@ export function union(arrays, offset, limit, resolve, boost){ } /** - * @param {Array} mandatory - * @param {Array>} arrays - * @returns {Array} + * @param {SearchResults|IntermediateSearchResults} arrays + * @param {Array} mandatory + * @param {boolean=} resolve + * @returns {SearchResults} */ - -export function intersect_union(mandatory, arrays) { +export function intersect_union(arrays, mandatory, resolve) { const check = create_object(); + /** @type {SearchResults|IntermediateSearchResults} */ const result = []; - for(let x = 0, ids; x < arrays.length; x++){ - ids = arrays[x]; + for(let x = 0, ids; x < mandatory.length; x++){ + ids = mandatory[x]; for(let i = 0; i < ids.length; i++){ check[ids[i]] = 1; } } - for(let i = 0, id; i < mandatory.length; i++){ - id = mandatory[i]; - if(check[id] === 1){ - result.push(id); - check[id] = 2; + if(resolve){ + for(let i = 0, id; i < arrays.length; i++){ + id = arrays[i]; + if(check[id]){ + result.push(id); + check[id] = 0; + } + } + } + else{ + for(let i = 0, ids, id; i < arrays.result.length; i++){ + ids = arrays.result[i]; + for(let j = 0; j < ids.length; j++){ + id = ids[j]; + if(check[id]){ + const arr = result[i] || (result[i] = []); + arr.push(id); + check[id] = 0; + } + } } } diff --git a/src/profiler.js b/src/profiler.js index c4784f8..6780fca 100644 --- a/src/profiler.js +++ b/src/profiler.js @@ -1,15 +1,24 @@ +// COMPILER BLOCK --> +import { PROFILER } from "./config.js"; +// <-- COMPILER BLOCK import { create_object } from "./common.js"; const data = create_object(); +if(PROFILER){ + if(typeof window !== "undefined"){ + window.profiler = data; + } +} + /** * @param {!string} name */ export default function tick(name){ - - /** @type {!Object} */ - const profiler = data["profiler"] || (data["profiler"] = {}); - - profiler[name] || (profiler[name] = 0); - profiler[name]++; + if(PROFILER){ + /** @type {!Object} */ + const profiler = data; //data["profiler"] || (data["profiler"] = {}); + profiler[name] || (profiler[name] = 0); + profiler[name]++; + } } diff --git a/src/resolve/and.js b/src/resolve/and.js index b4a39d4..b588c58 100644 --- a/src/resolve/and.js +++ b/src/resolve/and.js @@ -1,205 +1,141 @@ import Resolver from "../resolver.js"; -import { create_object, get_max_len } from "../common.js"; -import { intersect as _intersect } from "../intersect.js"; -import { ResolverOptions } from "../type.js"; +import { get_max_len } from "../common.js"; +import { intersect } from "../intersect.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults, ResolverOptions } from "../type.js"; +import { apply_enrich } from "../document/search.js"; -Resolver.prototype.and = function(){ - if(this.result.length){ +/** @this {Resolver} */ +Resolver.prototype["and"] = function(){ - const self = this; - let args = arguments; - let first_argument = args[0]; + let execute = this.result.length; + let limit, offset, enrich; + let resolve; - if(first_argument.then){ - return first_argument.then(function(){ - return self.and.apply(self, args); - }); + if(!execute){ + /** @type {ResolverOptions} */ + const arg = arguments[0]; + if(arg){ + execute = !!arg.suggest; + resolve = arg.resolve; + limit = arg.limit; + offset = arg.offset; + enrich = arg.enrich && resolve; } - - if(first_argument[0]){ - // fix false passed parameter style - if(first_argument[0].index){ - return this.and.apply(this, first_argument); - } - } - - let final = []; - let promises = []; - let limit = 0, offset = 0, enrich, resolve, suggest; - - for(let i = 0, query; i < args.length; i++){ - - query = /** @type {string|ResolverOptions} */ ( - args[i] - ); - - if(query){ - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - suggest = query.suggest; - - let result; - if(query.constructor === Resolver){ - result = query.result; - } - else if(query.constructor === Array){ - result = query; - } - else if(query.index){ - query.resolve = false; - result = query.index.search(query).result; - } - else if(query.or){ - result = this.or(query.or); - } - else if(query.xor){ - result = this.xor(query.xor); - } - else if(query.not){ - result = this.not(query.not); - } - else{ - continue; - } - - final[i] = result; - - if(result.then){ - promises.push(result); //{ query, result }; - } - } - } - - if(!final.length){ - this.result = final; - return resolve ? this.result : this; - } - - if(promises.length){ - return Promise.all(promises).then(function(){ - final = [self.result].concat(final); - self.result = intersect(final, limit, offset, enrich, resolve, self.boostval, suggest); - return resolve ? self.result : self; - }); - } - - final = [this.result].concat(final); - this.result = intersect(final, limit, offset, enrich, resolve, this.boostval, suggest); - return resolve ? this.result : this; } - return this; + + if(execute){ + + const { + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + } = this.handler("and", arguments); + + return return_result.call(this, + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + ); + } + + return resolve + ? this.resolve(limit, offset, enrich) + : this; } /** * Aggregate the intersection of N raw results - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @param suggest - * @return {Array} + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } */ -function intersect(result, limit, offset, enrich, resolve, boost, suggest){ +function return_result(final, promises, limit, offset, enrich, resolve, suggest){ - // if(!result.length){ - // // todo remove - // console.log("Empty Result") - // return result; - // } + if(promises.length){ + const self = this; + return Promise.all(promises).then(function(result){ - if(result.length < 2){ - return []; + final = []; + for(let i = 0, tmp; i < result.length; i++){ + if((tmp = result[i]).length){ + final[i] = tmp; + } + } + + return return_result.call(self, + final, + [], + limit, + offset, + enrich, + resolve, + suggest + ); + }); } - let final = []; - let count = 0; - let contain = create_object(); - let maxres = get_max_len(result); - if(!maxres) return final; + if(!final.length){ + if(!suggest){ + this.result = /** @type {SearchResults|IntermediateSearchResults} */ ( + final + ); + } + } + else{ + //final = [this.result].concat(final); + this.result.length && final.unshift(this.result); - //console.log(result) + if(final.length < 2){ + this.result = final[0]; + } + else{ + const resolution = get_max_len(final); + if(!resolution){ + this.result = []; + } + else{ + this.result = intersect( + final, + resolution, + limit, + offset, + suggest, + this.boostval, + resolve + ); - return _intersect(result, maxres, limit, offset, suggest, boost, resolve); + return resolve + ? (enrich + ? apply_enrich.call(this.index, /** @type {SearchResults} */ (this.result)) + : this.result + ) + : this; + } + } + } - // for(let j = 0, ids, res = result[0]; j < res.length; j++){ - // ids = res[j]; - // for(let k = 0; k < ids.length; k++){ - // contain[ids[k]] = 1; - // } - // } - - // for(let i = 0, res; i < result.length; i++){ - // res = result[i]; - // if(!res || !res.length) return []; - // let contain_new = create_object(); - // let match = 0; - // let last_round = i === result.length - 1; - // - // for(let j = 0, ids; j < maxres; j++){ - // ids = res[j]; - // if(!ids) continue; - // - // for(let k = 0, id, min; k < ids.length; k++){ - // id = ids[k]; - // // fill in first round - // if(!i){ - // // shift resolution +1 - // // shift resolution by boost (inverse) - // contain_new[id] = j + 1 + (i ? boost : 0); - // match = 1; - // } - // // result in last round - // else if(last_round){ - // if((min = contain[id])){ - // match = 1; - // //if(!contain_new[id]){ - // if(offset){ - // offset--; - // continue; - // } - // if(resolve){ - // final.push(id); - // } - // else{ - // // reduce resolution -1 - // min--; - // if(j < min) min = j; - // final[min] || (final[min] = []); - // final[min].push(id); - // } - // if(limit && ++count === limit){ - // //this.boost = 0; - // return final; - // } - // // shift resolution +1 - // //contain_new[id] = min + 1; - // //} - // } - // } - // // check for intersection - // else if((min = contain[id])){ - // // shift resolution +1 - // if(j + 1 < min) min = j + 1; - // contain_new[id] = min; - // match = 1; - // } - // } - // } - // - // if(!match){ - // //this.boost = 0; - // return []; - // } - // - // contain = contain_new; - // } - // - // //this.boost = 0; - // return final; + return resolve + ? this.resolve(limit, offset, enrich) + : this; } diff --git a/src/resolve/default.js b/src/resolve/default.js index 336c420..e4f8042 100644 --- a/src/resolve/default.js +++ b/src/resolve/default.js @@ -1,4 +1,8 @@ import { concat } from "../common.js"; +import { IntermediateSearchResults, SearchResults, EnrichedSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; +import Document from "../document.js"; +import Index from "../index.js"; /* from -> res[score][id] @@ -7,51 +11,36 @@ import { concat } from "../common.js"; /** * Aggregate the union of a single raw result - * @param {!Array} result + * @param {IntermediateSearchResults} result * @param {!number} limit * @param {number=} offset * @param {boolean=} enrich - * @return Array + * @return {SearchResults|EnrichedSearchResults} + * @this {Document|Index} */ export default function(result, limit, offset, enrich){ + if(!result.length){ + return result; + } + // fast path: when there is just one slot in the result if(result.length === 1){ - result = result[0]; - result = offset || (result.length > limit) + let final = result[0]; + final = offset || (final.length > limit) ? (limit - ? result.slice(offset, offset + limit) - : result.slice(offset) + ? final.slice(offset, offset + limit) + : final.slice(offset) ) - : result; + : final; return enrich - ? enrich_result(result) - : result; + ? apply_enrich.call(this, final) + : final; } let final = []; - // this is a workaround without using arr.concat.apply - - // for(let i = 0, arr, len; i < result.length; i++){ - // if((arr = result[i])){ - // if((len = arr.length)){ - // for(let j = offset; j < len; j++){ - // final.push(arr[j]); - // if(final.length === limit){ - // return enrich - // ? enrich_result(final) - // : final; - // } - // } - // if((offset -= len) < 0){ - // offset = 0; - // } - // } - // } - // } - // this is an optimized workaround instead of // just doing result = concat(result) @@ -74,59 +63,53 @@ export default function(result, limit, offset, enrich){ } } + if(len > limit){ + arr = arr.slice(0, limit); + len = limit; + } + if(!final.length){ // fast path: when limit was reached in first slot if(len >= limit){ - if(len > limit){ - arr = arr.slice(0, limit); - } return enrich - ? enrich_result(arr) + ? apply_enrich.call(this, arr) : arr; } } - else{ - if(len > limit){ - arr = arr.slice(0, limit); - len = arr.length; - } - } final.push(arr); limit -= len; - // todo remove - // if(limit < 0){ - // throw new Error("Impl.Error"); - // } - // break if limit was reached if(!limit){ break; } } - // todo remove - if(!final.length){ - //throw new Error("No results found"); - return final; - } - final = final.length > 1 ? concat(final) : final[0]; return enrich - ? enrich_result(final) + ? apply_enrich.call(this, final) : final; } -function enrich_result(ids){ - for(let i = 0; i < ids.length; i++){ - ids[i] = { - "score": i, - "id": ids[i] - }; - } - return ids; -} +// /** +// * @param {SearchResults} ids +// * @return {EnrichedSearchResults} +// */ +// +// export function enrich_result(ids){ +// // ids could be the original reference to an index value +// /** @type {EnrichedSearchResults} */ +// const result = new Array(ids.length); +// for(let i = 0, id; i < ids.length; i++){ +// id = ids[i]; +// result[i] = { +// "id": id, +// "doc": this.store.get(id) +// }; +// } +// return result; +// } diff --git a/src/resolve/handler.js b/src/resolve/handler.js new file mode 100644 index 0000000..4347eb0 --- /dev/null +++ b/src/resolve/handler.js @@ -0,0 +1,108 @@ +// COMPILER BLOCK --> +import { DEBUG } from "../config.js"; +// <-- COMPILER BLOCK +import Resolver from "../resolver.js"; +import { ResolverOptions, SearchResults, IntermediateSearchResults } from "../type.js"; + +/** + * @param {string} fn + * @param {Array>|Arguments} args + */ +Resolver.prototype.handler = function(fn, args){ + + /** @type {ResolverOptions|Promise} */ + let first_argument = args[0]; + + if(first_argument.then){ + const self = this; + // todo: check when this branch was taken + // instead of Promise.all the args[] array could be reduced + // by iterate recursively one by one + return Promise.all(args).then(function(args){ + return self[fn].apply(self, args); + }); + } + + if(first_argument[0]){ + // detect array parameter style + if(first_argument[0].index){ + return this[fn].apply(this, first_argument); + } + } + + /** @type {SearchResults|IntermediateSearchResults} */ + let final = []; + /** @type {Array>} */ + let promises = []; + let limit = 0, offset = 0, enrich, resolve, suggest; + + for(let i = 0, query; i < args.length; i++){ + + query = /** @type {string|ResolverOptions} */ ( + args[i] + ); + + if(query){ + + let result; + if(query.constructor === Resolver){ + result = query.result; + } + else if(query.constructor === Array){ + result = query; + } + else{ + + limit = query.limit || 0; + offset = query.offset || 0; + suggest = query.suggest; + resolve = query.resolve; + enrich = query.enrich && resolve; + + if(query.index){ + query.resolve = false; + if(DEBUG) query.enrich = false; + result = query.index.search(query).result; + query.resolve = resolve; + if(DEBUG) query.enrich = enrich; + } + else if(query.and){ + result = this["and"](query.and); + } + else if(query.or){ + result = this["or"](query.or); + } + else if(query.xor){ + result = this["xor"](query.xor); + } + else if(query.not){ + result = this["not"](query.not); + } + else{ + continue; + } + } + + if(result.then){ + promises.push(result); + } + else if(result.length){ + final[i] = result; + } + else if(!suggest && (fn === "and" || fn === "xor")){ + final = []; + break; + } + } + } + + return { + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + }; +} diff --git a/src/resolve/not.js b/src/resolve/not.js index b0458b0..7dd2117 100644 --- a/src/resolve/not.js +++ b/src/resolve/not.js @@ -1,102 +1,110 @@ import Resolver from "../resolver.js"; -import { ResolverOptions } from "../type.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; -Resolver.prototype.not = function(){ - const self = this; - let args = arguments; - let first_argument = args[0]; +/** @this {Resolver} */ +Resolver.prototype["not"] = function(){ - if(first_argument.then){ - return first_argument.then(function(){ - return self.not.apply(self, args); - }); - } + const { + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + } = this.handler("not", arguments); - if(first_argument[0]){ - // fix false passed parameter style - if(first_argument[0].index){ - return this.not.apply(this, first_argument); - } - } - - let final = []; - let promises = []; - let limit = 0, offset = 0, enrich, resolve; - - for(let i = 0, query; i < args.length; i++){ - - query = /** @type {string|ResolverOptions} */ ( - args[i] - ); - - if(query){ - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - - let result; - if(query.constructor === Resolver){ - result = query.result; - } - else if(query.constructor === Array){ - result = query; - } - else if(query.index){ - query.resolve = false; - result = query.index.search(query).result; - } - else if(query.or){ - result = this.or(query.or); - } - else if(query.and){ - result = this.and(query.and); - } - else if(query.xor){ - result = this.xor(query.xor); - } - else{ - continue; - } - - final[i] = result; - - if(result.then){ - promises.push(result); //{ query, result }; - } - } - } - - if(promises.length){ - return Promise.all(promises).then(function(){ - self.result = exclusion.call(self, final, limit, offset, resolve); - return resolve ? self.result : self; - }); - } - - if(final.length){ - this.result = exclusion.call(this, final, limit, offset, resolve); - } - - return resolve ? this.result : this; + return return_result.call(this, + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + ); } /** - * @param result - * @param limit - * @param offset - * @param resolve + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest * @this {Resolver} - * @return {Array} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } + */ + +function return_result(final, promises, limit, offset, enrich, resolve, suggest){ + + if(promises.length){ + const self = this; + return Promise.all(promises).then(function(result){ + + final = []; + for(let i = 0, tmp; i < result.length; i++){ + if((tmp = result[i]).length){ + final[i] = tmp; + } + } + + return return_result.call(self, + final, + [], + limit, + offset, + enrich, + resolve, + suggest + ); + }); + } + + if(final.length && this.result.length){ + this.result = exclusion.call(this, + final, + limit, + offset, + resolve + ); + } + else if(resolve){ + return this.resolve(limit, offset, enrich); + } + + return resolve + ? (enrich + ? apply_enrich.call(this.index, this.result) + : this.result + ) + : this; +} + +/** + * @param {!Array} result + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @this {Resolver} + * @return {SearchResults|IntermediateSearchResults} */ function exclusion(result, limit, offset, resolve){ - if(!result.length){ - return this.result; - } + // if(!result.length){ + // return this.result; + // } + /** @type {SearchResults|IntermediateSearchResults} */ const final = []; const exclude = new Set(result.flat().flat()); diff --git a/src/resolve/or.js b/src/resolve/or.js index 8fd4368..9c097c5 100644 --- a/src/resolve/or.js +++ b/src/resolve/or.js @@ -1,172 +1,94 @@ import Resolver from "../resolver.js"; -import default_resolver from "./default.js"; -import { union as _union } from "../intersect.js"; -import { ResolverOptions } from "../type.js"; +import { union } from "../intersect.js"; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; -Resolver.prototype.or = function(){ +/** @this {Resolver} */ +Resolver.prototype["or"] = function(){ - const self = this; - let args = arguments; - let first_argument = args[0]; + const { + final, + promises, + limit, + offset, + enrich, + resolve, + } = this.handler("or", arguments); - if(first_argument.then){ - return first_argument.then(function(){ - return self.or.apply(self, args); - }); - } + return return_result.call(this, + final, + promises, + limit, + offset, + enrich, + resolve + ); +}; - if(first_argument[0]){ - // fix false passed parameter style - if(first_argument[0].index){ - return this.or.apply(this, first_argument); - } - } +/** + * Aggregate the intersection of N raw results + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } + */ - let final = []; - let promises = []; - let limit = 0, offset = 0, enrich, resolve; - - for(let i = 0, query; i < args.length; i++){ - - query = /** @type {string|ResolverOptions} */ ( - args[i] - ); - - if(query){ - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - - let result; - if(query.constructor === Resolver){ - result = query.result; - } - else if(query.constructor === Array){ - result = query; - } - else if(query.index){ - query.resolve = false; - result = query.index.search(query).result; - } - else if(query.and){ - result = this.and(query.and); - } - else if(query.xor){ - result = this.xor(query.xor); - } - else if(query.not){ - result = this.not(query.not); - } - else{ - continue; - } - - final[i] = result; - - if(result.then){ - promises.push(result); //{ query, result }; - } - } - } +function return_result(final, promises, limit, offset, enrich, resolve){ if(promises.length){ - return Promise.all(promises).then(function(){ - //self.result.length && (final = [self.result].concat(final)); - // the suggest-union was re-used from but there it needs reversed order - self.result.length && (final = final.concat([self.result])); - self.result = union(final, limit, offset, enrich, resolve, self.boostval); - return resolve ? self.result : self; + const self = this; + return Promise.all(promises).then(function(result){ + + final = []; + for(let i = 0, tmp; i < result.length; i++){ + if((tmp = result[i]).length){ + final[i] = tmp; + } + } + + return return_result.call(self, + final, + [], + limit, + offset, + enrich, + resolve + ); }); } if(final.length){ - //this.result.length && (final = [this.result].concat(final)); - // the suggest-union was re-used but there it needs reversed order - this.result.length && (final = final.concat([this.result])); - this.result = union(final, limit, offset, enrich, resolve, this.boostval); - } - return resolve ? this.result : this; -}; + //this.result.length && (final = final.concat([this.result])); + this.result.length && (final.push(this.result)); -/** - * Aggregate the union of N raw results - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @return {Array} - */ - -function union(result, limit, offset, enrich, resolve, boost){ - - if(!result.length){ - // todo remove - //console.log("Empty Result") - return result; - } - - if(typeof limit === "object"){ - offset = limit.offset || 0; - enrich = limit.enrich || false; - limit = limit.limit || 0; - } - - if(result.length < 2){ - // todo remove - //console.log("Single Result") - if(resolve){ - return default_resolver(result[0], limit, offset, enrich); + if(final.length < 2){ + this.result = final[0]; } else{ - return result[0]; + // the suggest-union (reversed processing, resolve needs to be disabled) + this.result = union( + final/*.reverse()*/, + limit, + offset, + /* resolve: */ false, + this.boostval + ); + + // offset was already applied + offset = 0; } } - // the suggest-union - return _union(result/*.reverse()*/, offset, limit, resolve, boost); - - // let final = []; - // let count = 0; - // let dupe = create_object(); - // let maxres = get_max_len(result); - // - // for(let j = 0, ids; j < maxres; j++){ - // for(let i = 0, res; i < result.length; i++){ - // res = result[i]; - // if(!res) continue; - // ids = res[j]; - // if(!ids) continue; - // - // for(let k = 0, id; k < ids.length; k++){ - // id = ids[k]; - // if(!dupe[id]){ - // dupe[id] = 1; - // if(offset){ - // offset--; - // continue; - // } - // if(resolve){ - // final.push(id); - // } - // else{ - // // shift resolution by boost (inverse) - // const index = j + (boost || 0); - // final[index] || (final[index] = []); - // final[index].push(id); - // } - // if(limit && ++count === limit){ - // //this.boost = 0; - // return final; - // } - // } - // } - // } - // } - // - // //this.boost = 0; - // return final; + return resolve + ? this.resolve(limit, offset, enrich) + : this; } diff --git a/src/resolve/xor.js b/src/resolve/xor.js index 63519ab..c98f4a6 100644 --- a/src/resolve/xor.js +++ b/src/resolve/xor.js @@ -1,119 +1,127 @@ import Resolver from "../resolver.js"; import default_resolver from "./default.js"; import { create_object } from "../common.js"; -import { ResolverOptions } from "../type.js";; +import { SearchResults, EnrichedSearchResults, IntermediateSearchResults } from "../type.js"; +import { apply_enrich } from "../document/search.js"; -Resolver.prototype.xor = function(){ - const self = this; - let args = arguments; - let first_argument = args[0]; +/** @this {Resolver} */ +Resolver.prototype["xor"] = function(){ - if(first_argument.then){ - return first_argument.then(function(){ - return self.xor.apply(self, args); - }); - } + const { + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + } = this.handler("xor", arguments); - if(first_argument[0]){ - // fix false passed parameter style - if(first_argument[0].index){ - return this.xor.apply(this, first_argument); - } - } - - let final = []; - let promises = []; - let limit = 0, offset = 0, enrich, resolve; - - for(let i = 0, query; i < args.length; i++){ - - query = /** @type {string|ResolverOptions} */ ( - args[i] - ); - - if(query){ - - limit = query.limit || 0; - offset = query.offset || 0; - enrich = query.enrich; - resolve = query.resolve; - - let result; - if(query.constructor === Resolver){ - result = query.result; - } - else if(query.constructor === Array){ - result = query; - } - else if(query.index){ - query.resolve = false; - result = query.index.search(query).result; - } - else if(query.or){ - result = this.or(query.or); - } - else if(query.and){ - result = this.and(query.and); - } - else if(query.not){ - result = this.not(query.not); - } - else{ - continue; - } - - final[i] = result; - - if(result.then){ - promises.push(result); //{ query, result }; - } - } - } - - if(promises.length){ - return Promise.all(promises).then(function(){ - self.result.length && (final = [self.result].concat(final)); - self.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval); - return resolve ? self.result : self; - }); - } - - if(final.length){ - this.result.length && (final = [this.result].concat(final)); - this.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval); - } - return resolve ? this.result : this; + return return_result.call(this, + final, + promises, + limit, + offset, + enrich, + resolve, + suggest + ); } /** - * @param result - * @param limit - * @param offset - * @param enrich - * @param resolve - * @param boost - * @return {Array} + * @param {!Array} final + * @param {!Array>} promises + * @param {number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @param {boolean=} resolve + * @param {boolean=} suggest + * @this {Resolver} + * @return { + * SearchResults | + * EnrichedSearchResults | + * IntermediateSearchResults | + * Promise | + * Resolver + * } */ -function exclusive(result, limit, offset, enrich, resolve, boost){ +function return_result(final, promises, limit, offset, enrich, resolve, suggest){ - if(!result.length){ - // todo remove - //console.log("Empty Result") - return result; + if(promises.length){ + const self = this; + return Promise.all(promises).then(function(result){ + + final = []; + for(let i = 0, tmp; i < result.length; i++){ + if((tmp = result[i]).length){ + final[i] = tmp; + } + } + + return return_result.call(self, + final, + [], + limit, + offset, + enrich, + resolve, + suggest + ); + }); } - if(result.length < 2){ - // todo remove - //console.log("Single Result") - if(resolve){ - return default_resolver(result[0], limit, offset, enrich); + if(!final.length){ + if(!suggest) this.result = /** @type {SearchResults|IntermediateSearchResults} */ (final); + } + else{ + //this.result.length && (final = [this.result].concat(final)); + this.result.length && final.unshift(this.result); + + if(final.length < 2){ + this.result = final[0]; } else{ - return result[0]; + this.result = exclusive.call(this, + final, + limit, + offset, + resolve, + this.boostval + ); + + return resolve + ? (enrich + ? apply_enrich.call(this.index, /** @type {SearchResults} */ (this.result)) + : this.result + ) + : this; } } + return resolve + ? this.resolve(limit, offset, enrich) + : this; +} + +/** + * Aggregate the intersection of N raw results + * @param {!Array} result + * @param {number} limit + * @param {number=} offset + * @param {boolean=} resolve + * @param {number=} boost + * @this {Resolver} + * @return {SearchResults|IntermediateSearchResults} + */ + +function exclusive(result, limit, offset, resolve, boost){ + + // if(!result.length){ + // return result; + // } + + /** @type {SearchResults|IntermediateSearchResults} */ const final = []; const check = create_object(); let maxres = 0; @@ -122,17 +130,15 @@ function exclusive(result, limit, offset, enrich, resolve, boost){ res = result[i]; if(!res) continue; + if(maxres < res.length) maxres = res.length; + for(let j = 0, ids; j < res.length; j++){ ids = res[j]; if(!ids) continue - if(maxres < ids.length) maxres = ids.length; - for(let k = 0, id; k < ids.length; k++){ id = ids[k]; - check[id] - ? check[id]++ - : check[id] = 1; + check[id] = check[id] ? 2 : 1; } } } @@ -173,6 +179,5 @@ function exclusive(result, limit, offset, enrich, resolve, boost){ } } - //this.boost = 0; return final; -} \ No newline at end of file +} diff --git a/src/resolver.js b/src/resolver.js index 75ebd5b..9580f64 100644 --- a/src/resolver.js +++ b/src/resolver.js @@ -1,13 +1,18 @@ +import Index from "./index.js"; import default_resolver from "./resolve/default.js"; -import { set_resolve } from "./index/search.js"; -import { ResolverOptions } from "./type.js"; +//import { set_resolve } from "./index/search.js"; +import { apply_enrich } from "./document/search.js"; +import { ResolverOptions, IntermediateSearchResults } from "./type.js"; +import "./resolve/handler.js"; import "./resolve/or.js"; import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; + /** - * @param {Array|ResolverOptions=} result + * @param {IntermediateSearchResults|ResolverOptions=} result + * @return {Resolver} * @constructor */ @@ -15,23 +20,30 @@ export default function Resolver(result){ if(!this || this.constructor !== Resolver){ return new Resolver(result); } + // if(result && result.constructor === Resolver){ + // // todo test this branch + // //console.log("Resolver Loopback") + // return /** @type {Resolver} */ (result); + // } if(result && result.index){ + // result = /** @type {ResolverOptions} */ (result); result.resolve = false; - this.index = result.index; + this.index = /** @type {Index} */ (result.index); this.boostval = result.boost || 0; this.result = result.index.search(result).result; return this; } - if(result.constructor === Resolver){ - // todo test this branch - //console.log("Resolver Loopback") - return result; - } + /** @type {Index|null} */ this.index = null; - this.result = result || []; + /** @type {IntermediateSearchResults} */ + this.result = /** @type {IntermediateSearchResults} */ (result) || []; + /** @type {number} */ this.boostval = 0; } +/** + * @param {number} limit + */ Resolver.prototype.limit = function(limit){ if(this.result.length){ const final = []; @@ -52,6 +64,9 @@ Resolver.prototype.limit = function(limit){ return this; }; +/** + * @param {number} offset + */ Resolver.prototype.offset = function(offset){ if(this.result.length){ const final = []; @@ -71,6 +86,9 @@ Resolver.prototype.offset = function(offset){ return this; }; +/** + * @param {number} boost + */ Resolver.prototype.boost = function(boost){ this.boostval += boost; return this; @@ -81,10 +99,11 @@ Resolver.prototype.boost = function(boost){ * @param {number=} offset * @param {boolean=} enrich */ - Resolver.prototype.resolve = function(limit, offset, enrich){ - set_resolve(1); + + //set_resolve(1); const result = this.result; + const index = this.index; this.index = null; this.result = null; @@ -94,7 +113,16 @@ Resolver.prototype.resolve = function(limit, offset, enrich){ offset = limit.offset; limit = limit.limit; } - return default_resolver(result, limit || 100, offset, enrich); + // const document = this.index; + // if(document.index){ + // result = default_resolver(result, limit || 100, offset, false); + // return enrich + // ? apply_enrich.call(document, result) + // : result; + // } + // else{ + return default_resolver.call(index, result, limit || 100, offset, enrich); + // } } return result; diff --git a/src/serialize.js b/src/serialize.js index 0d189b1..2cd8858 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -6,6 +6,11 @@ const chunk_size_reg = 250000; const chunk_size_map = 5000; const chunk_size_ctx = 1000; +/** + * @param {Map} map + * @param {number=} size + * @return {Array} + */ function map_to_json(map, size = 0){ let chunk = []; let json = []; @@ -23,13 +28,18 @@ function map_to_json(map, size = 0){ return chunk; } +/** + * @param {Array} json + * @param {Map=} map + * @return {Map} + */ function json_to_map(json, map){ map || (map = new Map()); for(let i = 0, entry; i < json.length; i++) { entry = json[i]; map.set(entry[0], entry[1]); } - return map; + return /** @type {Map} */ (map); } function ctx_to_json(ctx, size = 0){ @@ -84,9 +94,17 @@ function json_to_reg(json, reg){ } /** + * + * @param {function(string, string):Promise|void} callback + * @param {string|null|void} field + * @param {string} key + * @param {Array|null} chunk + * @param {number} index_doc + * @param {number} index_obj + * @param {number=} index_prt * @this {Index|Document} + * @return {Promise} */ - function save(callback, field, key, chunk, index_doc, index_obj, index_prt = 0){ const is_arr = chunk && chunk.constructor === Array; @@ -133,17 +151,17 @@ function save(callback, field, key, chunk, index_doc, index_obj, index_prt = 0){ /** * @param {function(string,string):Promise|void} callback - * @param {string|null=} field - * @param {number=} index_doc - * @param {number=} index_obj + * @param {!string|null=} _field + * @param {number=} _index_doc + * @param {number=} _index_obj * @this {Index} */ -export function exportIndex(callback, field, index_doc, index_obj = 0){ +export function exportIndex(callback, _field, _index_doc = 0, _index_obj = 0){ let key, chunk; - switch(index_obj){ + switch(_index_obj){ case 0: @@ -177,17 +195,17 @@ export function exportIndex(callback, field, index_doc, index_obj = 0){ return save.call(this, callback, - field, + _field, key, chunk, - index_doc, - index_obj + _index_doc, + _index_obj ); } /** * @param {string} key - * @param {string|*} data + * @param {string|Array} data * @this Index */ @@ -196,8 +214,10 @@ export function importIndex(key, data){ if(!data){ return; } - if(is_string(data)){ - data = JSON.parse(/** @type {string} */(data)); + if(typeof data === "string"){ + data = /** @type {Array} */( + JSON.parse(/** @type {string} */(data)) + ); } const split = key.split("."); @@ -233,62 +253,62 @@ export function importIndex(key, data){ /** * @param {function(string,string):Promise|void} callback - * @param {string|null=} field - * @param {number=} index_doc - * @param {number=} index_obj + * @param {string|null=} _field + * @param {number=} _index_doc + * @param {number=} _index_obj * @this {Document} */ -export function exportDocument(callback, field, index_doc = 0, index_obj = 0){ +export function exportDocument(callback, _field, _index_doc = 0, _index_obj = 0){ - if(index_doc < this.field.length){ + if(_index_doc < this.field.length){ - const field = this.field[index_doc]; + const field = this.field[_index_doc]; const idx = this.index.get(field); // start from index 1, because document indexes does not additionally store register - const res = idx.export(callback, field, index_doc, index_obj = 1); + const res = idx.export(callback, field, _index_doc, _index_obj = 1); if(res && res["then"]){ const self = this; return res["then"](function(){ - return self.export(callback, field, index_doc + 1); + return self.export(callback, field, _index_doc + 1); }); } - return this.export(callback, field, index_doc + 1); + return this.export(callback, field, _index_doc + 1); } else{ let key, chunk; - switch(index_obj){ + switch(_index_obj){ case 0: key = "reg"; chunk = reg_to_json(this.reg); - field = null; + _field = null; break; case 1: key = "tag"; chunk = ctx_to_json(this.tag, this.reg.size); - field = null; + _field = null; break; case 2: key = "doc"; chunk = map_to_json(this.store); - field = null; + _field = null; break; case 3: key = "cfg"; chunk = {}; - field = null; + _field = null; break; default: @@ -298,18 +318,18 @@ export function exportDocument(callback, field, index_doc = 0, index_obj = 0){ return save.call(this, callback, - field, + _field, key, chunk, - index_doc, - index_obj + _index_doc, + _index_obj ); } } /** - * @param key - * @param {string|*} data + * @param {!string} key + * @param {string|Array} data * @this {Document} */ @@ -318,8 +338,10 @@ export function importDocument(key, data){ if(!data){ return; } - if(is_string(data)){ - data = JSON.parse(/** @type {string} */(data)); + if(typeof data === "string"){ + data = /** @type {Array} */( + JSON.parse(/** @type {string} */(data)) + ); } const split = key.split("."); diff --git a/src/type.js b/src/type.js index a4dfe0d..9c1c98d 100644 --- a/src/type.js +++ b/src/type.js @@ -17,7 +17,6 @@ import StorageInterface from "./db/interface.js"; * keystore: (number|undefined), * rtl: (boolean|undefined), * cache: (number|boolean|undefined), - * resolve: (boolean|undefined), * db: (StorageInterface|undefined), * commit: (boolean|undefined), * worker: (string|undefined), @@ -131,9 +130,9 @@ export let SearchOptions = {}; * suggest: (boolean|undefined), * enrich: (boolean|undefined), * tag: (Object|Array|undefined), - * field: (Array|Array|string|undefined), - * index: (Array|Array|undefined), - * pluck: (string|undefined), + * field: (Array|Array|DocumentSearchOptions|string|undefined), + * index: (Array|Array|DocumentSearchOptions|string|undefined), + * pluck: (string|DocumentSearchOptions|undefined), * merge: (boolean|undefined), * highlight: (string|undefined), * }} @@ -142,16 +141,23 @@ export let DocumentSearchOptions = {}; /** * @typedef Array + * @global */ -export let SearchResults = {}; +export let SearchResults = []; + +/** + * @typedef Array> + * @global + */ +export let IntermediateSearchResults = []; /** * @typedef Array<{ * id: (number|string), - * res: number + * doc: (Object|null) * }> */ -export let EnrichedSearchResults = {}; +export let EnrichedSearchResults = []; /** * @typedef Array<{ @@ -160,20 +166,17 @@ export let EnrichedSearchResults = {}; * result: SearchResults * }> */ -export let DocumentSearchResults = {}; +export let DocumentSearchResults = []; /** * @typedef Array<{ * field: (string|undefined), * tag: (string|undefined), * highlight: (string|undefined), - * result: Array<{ - * id: (number|string), - * doc: (Object|null) - * }> + * result: {EnrichedSearchResults} * }> */ -export let EnrichedDocumentSearchResults = {}; +export let EnrichedDocumentSearchResults = []; /** * @typedef Array<{ @@ -183,7 +186,7 @@ export let EnrichedDocumentSearchResults = {}; * tag: (Array|undefined) * }> */ -export let MergedDocumentSearchResults = {}; +export let MergedDocumentSearchResults = []; /** * @typedef {{ @@ -204,6 +207,7 @@ export let EncoderSplitOptions = {}; * include: (EncoderSplitOptions|undefined), * exclude: (EncoderSplitOptions|undefined), * split: (string|boolean|undefined), + * numeric: (boolean|undefined), * normalize: (boolean|(function(string):string)|undefined), * prepare: ((function(string):string)|undefined), * finalize: ((function(Array):(Array|void))|undefined), diff --git a/task/babel.js b/task/babel.js index 2c0c79a..ddc899b 100644 --- a/task/babel.js +++ b/task/babel.js @@ -68,6 +68,11 @@ fs.existsSync("dist") || fs.mkdirSync("dist"); }); } + let content = fs.readFileSync("tmp/db/interface.js", "utf8"); + content = content.replace(/import \{([^}]+)} from "\.\.\/type\.js";/, ''); + fs.writeFileSync("tmp/db/interface.js", content); + + //fs.copyFileSync("src/db/interface.js", "tmp/db/interface.js"); fs.copyFileSync("task/babel." + (debug ? "debug": (minify ? "min" : "bundle")) + ".json", "tmp/.babelrc"); fs.existsSync("dist/module" + (debug ? "-debug" : (minify ? "-min" : ""))) && fs.rmSync("dist/module" + (debug ? "-debug" : (minify ? "-min" : "")), { recursive: true }); diff --git a/task/build.js b/task/build.js index e911fec..a67aafb 100644 --- a/task/build.js +++ b/task/build.js @@ -128,6 +128,18 @@ if(custom){ release || (options["RELEASE"] = release = "custom"); } +if(release === "custom"){ + if(typeof options["DEBUG"] === "undefined"){ + options["DEBUG"] = false; + } + if(typeof options["PROFILER"] === "undefined"){ + options["PROFILER"] = false; + } + if(typeof options["POLYFILL"] === "undefined"){ + options["POLYFILL"] = false; + } +} + if(release === "lang"){ //const charsets = Object.keys(supported_charset); @@ -161,7 +173,6 @@ if(release === "lang"){ .replace('import StorageInterface from "./db/interface.js";', ''); fs.writeFileSync("tmp/type.js", content); - fs.writeFileSync("tmp/lang.js", ` import { EncoderOptions, EncoderSplitOptions } from "./type.js"; import lang from "./lang/${lang}.js"; @@ -406,10 +417,10 @@ else (async function(){ // fix closure compiler dynamic import build = build.replace(/\(([a-z])=([a-z]).config\)&&\(([a-z])=([a-z])\)/, "($1=$2.config)&&($3=(await import($4))[\"default\"])"); - //if(release === "bundle"){ + if(options["SUPPORT_WORKER"]){ build = build.replace("(function(self){'use strict';", "(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;"); //build = build.replace("(function(self){", "(function _f(self){if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;"); - //} + } // replace the eval wrapper build = build.replace(/\(0,eval\)\('([^']+)'\)/g, "$1");