From afa4a8acb9e41355ef4d397428478ecc9f3dab3f Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Tue, 25 Mar 2025 16:13:49 +0100 Subject: [PATCH] fix indexeddb #475 --- dist/db/indexeddb/index.js | 85 +- dist/flexsearch.bundle.debug.js | 1549 ++++++++++++----------- dist/flexsearch.bundle.min.js | 183 +-- dist/flexsearch.bundle.module.debug.js | 1543 +++++++++++----------- dist/flexsearch.bundle.module.min.js | 185 +-- dist/flexsearch.compact.debug.js | 670 +++++----- dist/flexsearch.compact.min.js | 81 +- dist/flexsearch.compact.module.debug.js | 664 +++++----- dist/flexsearch.compact.module.min.js | 83 +- dist/flexsearch.es5.debug.js | 957 +++++++------- dist/flexsearch.es5.min.js | 153 +-- dist/flexsearch.light.debug.js | 5 +- dist/flexsearch.light.min.js | 4 +- dist/flexsearch.light.module.debug.js | 3 +- dist/flexsearch.light.module.min.js | 4 +- dist/module-debug/bundle.js | 14 +- dist/module-debug/common.js | 63 - dist/module-debug/db/indexeddb/index.js | 79 +- dist/module-debug/document/search.js | 8 +- dist/module-min/bundle.js | 2 +- dist/module-min/db/indexeddb/index.js | 2 +- dist/module-min/document/search.js | 2 +- dist/module/bundle.js | 14 +- dist/module/common.js | 63 - dist/module/db/indexeddb/index.js | 79 +- dist/module/document/search.js | 8 +- package-lock.json | 4 +- package.json | 2 +- src/bundle.js | 14 +- src/common.js | 63 - src/db/indexeddb/index.js | 85 +- src/document.js | 2 +- src/document/search.js | 18 +- task/build.js | 2 + test/package.json | 22 + 35 files changed, 3365 insertions(+), 3350 deletions(-) create mode 100644 test/package.json diff --git a/dist/db/indexeddb/index.js b/dist/db/indexeddb/index.js index fd14f0a..1076298 100644 --- a/dist/db/indexeddb/index.js +++ b/dist/db/indexeddb/index.js @@ -6,6 +6,10 @@ */ +function create_object(){ + return Object.create(null); +} + /** * @param {Map|Set} val * @param {boolean=} stringify @@ -39,6 +43,8 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } +const DB = create_object(); + /** * @param {string|PersistentOptions=} name * @param {PersistentOptions=} config @@ -81,10 +87,12 @@ IdxDB.prototype.open = function(){ navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function(resolve, reject){ + return this.db || (this.db = new Promise(function(resolve, reject){ - const req = IndexedDB.open(self.id + (self.field ? ":" + self.field : ""), VERSION); + DB[self.id] || (DB[self.id] = []); + DB[self.id].push(self.field); + const req = IndexedDB.open(self.id, VERSION); req.onupgradeneeded = function(event){ const db = self.db = this.result; @@ -94,12 +102,15 @@ IdxDB.prototype.open = function(){ // The schema map:key => [res][id] is currently used instead // In fact that bypass the idea of a storage solution, // IndexedDB is such a poor contribution :( - - fields.forEach(ref => { - db.objectStoreNames.contains(ref) || - db.createObjectStore(ref);//{ autoIncrement: true /*keyPath: "id"*/ } - //.createIndex("idx", "ids", { multiEntry: true, unique: false }); - }); + for(let i = 0, ref; i < fields.length; i++){ + ref = fields[i]; + for(let j = 0, field; j < DB[self.id].length; j++){ + field = DB[self.id][j]; + db.objectStoreNames.contains(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")) || + db.createObjectStore(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));//{ autoIncrement: true /*keyPath: "id"*/ } + //.createIndex("idx", "ids", { multiEntry: true, unique: false }); + } + } // switch(event.oldVersion){ // existing db version // case 0: @@ -132,7 +143,7 @@ IdxDB.prototype.open = function(){ }; resolve(self); }; - }); + })); }; IdxDB.prototype.close = function(){ @@ -144,7 +155,7 @@ IdxDB.prototype.close = function(){ * @return {!Promise} */ IdxDB.prototype.destroy = function(){ - const req = IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const req = IndexedDB.deleteDatabase(this.id); return promisfy(req); }; @@ -166,9 +177,21 @@ IdxDB.prototype.destroy = function(){ * @return {!Promise} */ IdxDB.prototype.clear = function(){ - const transaction = this.db.transaction(fields, "readwrite"); - for(let i = 0; i < fields.length; i++){ - transaction.objectStore(fields[i]).clear(); + + const stores = []; + + for(let i = 0, ref; i < fields.length; i++){ + ref = fields[i]; + for(let j = 0, field; j < DB[this.id].length; j++){ + field = DB[this.id][j]; + stores.push(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")); + } + } + + const transaction = this.db.transaction(stores, "readwrite"); + + for(let i = 0; i < stores.length; i++){ + transaction.objectStore(stores[i]).clear(); } return promisfy(transaction); }; @@ -183,8 +206,8 @@ IdxDB.prototype.clear = function(){ * @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"); + const transaction = this.db.transaction((ctx ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly"); + const map = transaction.objectStore((ctx ? "ctx" : "map") + (this.field ? ":" + this.field : "")); const req = map.get(ctx ? ctx + ":" + key : key); const self = this; return promisfy(req).then(function(res){ @@ -232,8 +255,8 @@ IdxDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, * @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"); + const transaction = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly"); + const map = transaction.objectStore("tag" + (this.field ? ":" + this.field : "")); const req = map.get(tag); const self = this; return promisfy(req).then(function(ids){ @@ -266,8 +289,8 @@ IdxDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, return Promise.all(promises).then(function(docs){ for(let i = 0; i < docs.length; i++){ docs[i] = { - id: ids[i], - doc: docs[i] ? JSON.parse(docs[i]) : null + "id": ids[i], + "doc": docs[i] ? JSON.parse(docs[i]) : null }; } return docs; @@ -309,11 +332,18 @@ IdxDB.prototype.info = function(){ IdxDB.prototype.transaction = function(ref, modifier, task){ - let store = this.trx[ref + ":" + modifier]; + const key = ref + (ref !== "reg" ? (this.field ? ":" + this.field : "") : ""); + /** + * @type {IDBObjectStore} + */ + let store = this.trx[key + ":" + modifier]; if(store) return task.call(this, store); - let transaction = this.db.transaction(ref, modifier); - this.trx[ref + ":" + modifier] = store = transaction.objectStore(ref); + let transaction = this.db.transaction(key, modifier); + /** + * @type {IDBObjectStore} + */ + this.trx[key + ":" + modifier] = store = transaction.objectStore(key); return new Promise((resolve, reject) => { transaction.onerror = (err) => { @@ -330,7 +360,7 @@ IdxDB.prototype.transaction = function(ref, modifier, task){ const promise = task.call(this, store); // transactions can just be used within the same event loop // the indexeddb is such a stupid tool :( - this.trx[ref+ ":" + modifier] = null; + this.trx[key + ":" + modifier] = null; return promise; }); }; @@ -613,19 +643,19 @@ IdxDB.prototype.remove = function(ids){ } return /** @type {!Promise} */(Promise.all([ - this.transaction("map", "readwrite", function(store){ + this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids); }; }), - this.transaction("ctx", "readwrite", function(store){ + this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids); }; }), - this.transaction("tag", "readwrite", function(store){ + this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids, /* tag? */ true); @@ -669,9 +699,8 @@ function promisfy(req, callback){ req.onsuccess = function(){ resolve(this.result); }; - /** @this {IDBRequest} */ req.oncomplete = function(){ - resolve(this.result); + resolve(); }; req.onerror = reject; req = null; diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 6f37a66..db88c9e 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.133 (Bundle/Debug) + * FlexSearch.js v0.8.135 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -7,14 +7,14 @@ */ (function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f; var t; -function A(a, c, b) { +function z(a, c, b) { const e = typeof b, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { if (b) { if ("function" === d && e === d) { - return function(h) { - return a(b(h)); + return function(k) { + return a(b(k)); }; } c = a.constructor; @@ -86,9 +86,9 @@ function ca(a) { "\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 J(a = {}) { - if (!this || this.constructor !== J) { - return new J(...arguments); +function ka(a = {}) { + if (!this || this.constructor !== ka) { + return new ka(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -98,9 +98,9 @@ function J(a = {}) { this.assign(a); } } -t = J.prototype; +t = ka.prototype; t.assign = function(a) { - this.normalize = A(a.normalize, !0, this.normalize); + this.normalize = z(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) { @@ -123,29 +123,29 @@ t.assign = function(a) { } else { this.split = b, e = !1 === b || 2 > "a1a".split(b).length; } - this.numeric = A(a.numeric, e); + this.numeric = z(a.numeric, e); } else { try { - this.split = A(this.split, ea); + this.split = z(this.split, ea); } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = A(a.numeric, A(this.numeric, !0)); + this.numeric = z(a.numeric, z(this.numeric, !0)); } - this.prepare = A(a.prepare, null, this.prepare); - this.finalize = A(a.finalize, null, this.finalize); + this.prepare = z(a.prepare, null, this.prepare); + this.finalize = z(a.finalize, null, this.finalize); ja || (this.mapper = new Map(da)); b = a.filter; - this.filter = "function" === typeof b ? b : A(b && new Set(b), null, this.filter); - this.dedupe = A(a.dedupe, !1, this.dedupe); - 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); - this.rtl = A(a.rtl, !1, this.rtl); - if (this.cache = b = A(a.cache, !0, this.cache)) { + this.filter = "function" === typeof b ? b : z(b && new Set(b), null, this.filter); + this.dedupe = z(a.dedupe, !1, this.dedupe); + this.matcher = z((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = z((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = z((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = z(a.replacer, null, this.replacer); + this.minlength = z(a.minlength, 1, this.minlength); + this.maxlength = z(a.maxlength, 0, this.maxlength); + this.rtl = z(a.rtl, !1, this.rtl); + if (this.cache = b = z(a.cache, !0, this.cache)) { this.H = null, this.S = "number" === typeof b ? b : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; @@ -169,12 +169,12 @@ t.addStemmer = function(a, c) { this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && K(this); + this.cache && J(this); return this; }; t.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && K(this); + this.cache && J(this); return this; }; t.addMapper = function(a, c) { @@ -186,7 +186,7 @@ t.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && K(this); + this.cache && J(this); return this; }; t.addMatcher = function(a, c) { @@ -200,7 +200,7 @@ t.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && K(this); + this.cache && J(this); return this; }; t.addReplacer = function(a, c) { @@ -209,7 +209,7 @@ t.addReplacer = function(a, c) { } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && K(this); + this.cache && J(this); return this; }; t.encode = function(a) { @@ -219,7 +219,7 @@ t.encode = function(a) { return this.B.get(a); } } else { - this.H = setTimeout(K, 50, this); + this.H = setTimeout(J, 50, this); } } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); @@ -227,8 +227,8 @@ t.encode = function(a) { this.numeric && 3 < a.length && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, h; f < e.length; f++) { - if ((g = h = e[f]) && !(g.length < this.minlength)) { + for (let f = 0, g, k; f < e.length; f++) { + if ((g = k = e[f]) && !(g.length < this.minlength)) { if (c) { b.push(g); } else { @@ -241,24 +241,24 @@ t.encode = function(a) { continue; } } else { - this.H = setTimeout(K, 50, this); + this.H = setTimeout(J, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), d = g, g = g.replace(this.N, k => this.stemmer.get(k)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), d = g, g = g.replace(this.N, h => this.stemmer.get(h)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let k = 0, l = "", m, n; k < g.length; k++) { - m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let h = 0, l = "", n, m; h < g.length; h++) { + n = g.charAt(h), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (d += m) : d += l = n); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); g && b.push(g); } } @@ -268,61 +268,61 @@ t.encode = function(a) { this.cache && a.length <= this.K && (this.B.set(a, b), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); return b; }; -function K(a) { +function J(a) { a.H = null; a.B.clear(); a.G.clear(); } -;let M, N; -async function ka(a) { +;let K, M; +async function la(a) { a = a.data; var c = a.task; const b = a.id; let e = a.args; switch(c) { case "init": - N = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + M = a.options || {}; + (c = a.factory) ? (Function("return " + c)()(self), K = new self.FlexSearch.Index(M), delete self.FlexSearch) : K = new N(M); postMessage({id:b}); break; default: let d; if ("export" === c) { - if (!N.export || "function" !== typeof N.export) { + if (!M.export || "function" !== typeof M.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - e[1] ? (e[0] = N.export, e[2] = 0, e[3] = 1) : e = null; + e[1] ? (e[0] = M.export, e[2] = 0, e[3] = 1) : e = null; } if ("import" === c) { - if (!N.import || "function" !== typeof N.import) { + if (!M.import || "function" !== typeof M.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - e[0] && (a = await N.import.call(M, e[0]), M.import(e[0], a)); + e[0] && (a = await M.import.call(K, e[0]), K.import(e[0], a)); } else { - (d = e && M[c].apply(M, e)) && d.then && (d = await d); + (d = e && K[c].apply(K, e)) && d.then && (d = await d); } postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } -;function la(a) { - ma.call(a, "add"); - ma.call(a, "append"); - ma.call(a, "search"); - ma.call(a, "update"); - ma.call(a, "remove"); +;function ma(a) { + na.call(a, "add"); + na.call(a, "append"); + na.call(a, "search"); + na.call(a, "update"); + na.call(a, "remove"); } -let na, oa, pa; -function qa() { - na = pa = 0; +let oa, pa, qa; +function ra() { + oa = qa = 0; } -function ma(a) { +function na(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; let e; "function" === typeof b && (e = b, delete c[c.length - 1]); - na ? pa || (pa = Date.now() - oa >= this.priority * this.priority * 3) : (na = setTimeout(qa, 0), oa = Date.now()); - if (pa) { + oa ? qa || (qa = Date.now() - pa >= this.priority * this.priority * 3) : (oa = setTimeout(ra, 0), pa = Date.now()); + if (qa) { const f = this; return new Promise(g => { setTimeout(function() { @@ -336,25 +336,25 @@ function ma(a) { return b; }; } -;let P = 0; -function Q(a = {}) { +;let O = 0; +function P(a = {}) { function c(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && d.h[l]; - m && (m(k.msg), delete d.h[l]); + function k(h) { + h = h.data || h; + const l = h.id, n = l && d.h[l]; + n && (n(h.msg), delete d.h[l]); } this.worker = g; this.h = B(); if (this.worker) { - e ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { - d.h[++P] = function() { - k(d); - 1e9 < P && (P = 0); + return new Promise(function(h) { + d.h[++O] = function() { + h(d); + 1e9 < O && (O = 0); }; - d.worker.postMessage({id:P, task:"init", factory:b, options:a}); + d.worker.postMessage({id:O, task:"init", factory:b, options:a}); }); } this.worker.postMessage({task:"init", factory:b, options:a}); @@ -362,44 +362,44 @@ function Q(a = {}) { return this; } } - if (!this || this.constructor !== Q) { - return new Q(a); + if (!this || this.constructor !== P) { + return new P(a); } let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; b && (b = b.toString()); - const e = "undefined" === typeof window, d = this, f = ra(b, e, a.worker); + const e = "undefined" === typeof window, d = this, f = sa(b, e, a.worker); return f.then ? f.then(function(g) { return c.call(d, g); }) : c.call(this, f); } -R("add"); -R("append"); -R("search"); -R("update"); -R("remove"); -R("clear"); -R("export"); -R("import"); -la(Q.prototype); -function R(a) { - Q.prototype[a] = function() { +Q("add"); +Q("append"); +Q("search"); +Q("update"); +Q("remove"); +Q("clear"); +Q("export"); +Q("import"); +ma(P.prototype); +function Q(a) { + P.prototype[a] = function() { const c = this, b = [].slice.call(arguments); var e = b[b.length - 1]; let d; "function" === typeof e && (d = e, b.pop()); e = new Promise(function(f) { "export" === a && "function" === typeof b[0] && (b[0] = null); - c.h[++P] = f; - c.worker.postMessage({task:a, id:P, args:b}); + c.h[++O] = f; + c.worker.postMessage({task:a, id:O, args:b}); }); return d ? (e.then(d), this) : e; }; } -function ra(a, c, b) { - return c ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function sa(a, c, b) { + return c ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + la.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;function sa(a, c = 0) { +;function ta(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -408,30 +408,30 @@ function ra(a, c, b) { e.length && b.push(e); return b; } -function ta(a, c) { +function ua(a, c) { c || (c = new Map()); for (let b = 0, e; b < a.length; b++) { e = a[b], c.set(e[0], e[1]); } return c; } -function ua(a, c = 0) { +function va(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], sa(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], ta(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function va(a, c) { +function wa(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], ta(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], ua(e[1], d)); } return c; } -function wa(a) { +function xa(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -439,56 +439,56 @@ function wa(a) { b.length && c.push(b); return c; } -function xa(a, c) { +function ya(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function ya(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { +function za(a, c, b, e, d, f, g = 0) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { return this.export(a, c, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return ya.call(l, a, c, b, h ? e : null, d, f, g + 1); + return h.then(function() { + return za.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return ya.call(this, a, c, b, h ? e : null, d, f, g + 1); + return za.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function za(a, c) { +function Aa(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, h; g < d.length; g++) { - h = d[g] || [""]; - let k = ""; - for (let l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === c ? '"' + h[l] + '"' : h[l]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === c ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; b += (b ? "," : "") + f; } return b; } -;function Aa(a, c, b, e) { +;function Ba(a, c, b, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], c >= g.length) { c -= g.length; } else { c = g[e ? "splice" : "slice"](c, b); - const h = c.length; - if (h && (d = d.length ? d.concat(c) : c, b -= h, e && (a.length -= h), !b)) { + const k = c.length; + if (k && (d = d.length ? d.concat(c) : c, b -= k, e && (a.length -= k), !b)) { break; } c = 0; @@ -496,9 +496,9 @@ function za(a, c) { } return d; } -function S(a) { - if (!this || this.constructor !== S) { - return new S(a); +function R(a) { + if (!this || this.constructor !== R) { + return new R(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -523,13 +523,13 @@ function S(a) { if ("indexOf" === e) { return function(d) { let f = 0; - for (let g = 0, h, k; g < c.index.length; g++) { - h = c.index[g]; - k = h.indexOf(d); - if (0 <= k) { - return f + k; + for (let g = 0, k, h; g < c.index.length; g++) { + k = c.index[g]; + h = k.indexOf(d); + if (0 <= h) { + return f + h; } - f += h.length; + f += k.length; } return -1; }; @@ -546,12 +546,12 @@ function S(a) { } if ("slice" === e) { return function(d, f) { - return Aa(c, d || 0, f || c.length, !1); + return Ba(c, d || 0, f || c.length, !1); }; } if ("splice" === e) { return function(d, f) { - return Aa(c, d || 0, f || c.length, !0); + return Ba(c, d || 0, f || c.length, !0); }; } if ("constructor" === e) { @@ -567,13 +567,31 @@ function S(a) { return !0; }}); } -S.prototype.clear = function() { +R.prototype.clear = function() { this.index.length = 0; }; -S.prototype.destroy = function() { +R.prototype.destroy = function() { this.proxy = this.index = null; }; -S.prototype.push = function() { +R.prototype.push = function() { +}; +function S(a = 8) { + if (!this || this.constructor !== S) { + return new S(a); + } + this.index = B(); + this.h = []; + this.size = 0; + 32 < a ? (this.B = Ca, this.A = BigInt(a)) : (this.B = Da, this.A = a); +} +S.prototype.get = function(a) { + const c = this.index[this.B(a)]; + return c && c.get(a); +}; +S.prototype.set = function(a, c) { + var b = this.B(a); + let e = this.index[b]; + e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++); }; function T(a = 8) { if (!this || this.constructor !== T) { @@ -582,67 +600,49 @@ function T(a = 8) { this.index = B(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.B = Ca, this.A = BigInt(a)) : (this.B = Da, this.A = a); } -T.prototype.get = function(a) { - const c = this.index[this.B(a)]; - return c && c.get(a); -}; -T.prototype.set = function(a, c) { - var b = this.B(a); - let e = this.index[b]; - e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++); -}; -function U(a = 8) { - if (!this || this.constructor !== U) { - return new U(a); - } - this.index = B(); - this.h = []; - this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); -} -U.prototype.add = function(a) { +T.prototype.add = function(a) { var c = this.B(a); let b = this.index[c]; b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.h.push(b), this.size++); }; -t = T.prototype; -t.has = U.prototype.has = function(a) { +t = S.prototype; +t.has = T.prototype.has = function(a) { const c = this.index[this.B(a)]; return c && c.has(a); }; -t.delete = U.prototype.delete = function(a) { +t.delete = T.prototype.delete = function(a) { const c = this.index[this.B(a)]; c && c.delete(a) && this.size--; }; -t.clear = U.prototype.clear = function() { +t.clear = T.prototype.clear = function() { this.index = B(); this.h = []; this.size = 0; }; -t.values = U.prototype.values = function*() { +t.values = T.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].values()) { yield c; } } }; -t.keys = U.prototype.keys = function*() { +t.keys = T.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].keys()) { yield c; } } }; -t.entries = U.prototype.entries = function*() { +t.entries = T.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].entries()) { yield c; } } }; -function Ca(a) { +function Da(a) { let c = 2 ** this.A - 1; if ("number" == typeof a) { return a & c; @@ -653,7 +653,7 @@ function Ca(a) { } return 32 === this.A ? b + 2 ** 31 : b; } -function Ba(a) { +function Ca(a) { let c = BigInt(2) ** this.A - BigInt(1); var b = typeof a; if ("bigint" === b) { @@ -669,21 +669,21 @@ function Ba(a) { } return b; } -;V.prototype.add = function(a, c, b) { +;U.prototype.add = function(a, c, b) { I(a) && (c = a, a = ba(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.D[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); + for (let k = 0, h; k < this.field.length; k++) { + h = this.D[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(c); d && e.add(a, d, !1, !0); } else { - if (d = k.I, !d || d(c)) { - k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), Da(c, k, this.J, 0, e, a, k[0], b); + if (d = h.I, !d || d(c)) { + h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Ea(c, h, this.J, 0, e, a, h[0], b); } } } @@ -691,14 +691,14 @@ function Ba(a) { for (e = 0; e < this.F.length; e++) { var f = this.F[e], g = this.R[e]; d = this.tag.get(g); - let h = B(); + let k = B(); if ("function" === typeof f) { if (f = f(c), !f) { continue; } } else { - const k = f.I; - if (k && !k(c)) { + const h = f.I; + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); @@ -706,19 +706,19 @@ function Ba(a) { } if (d && f) { E(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - if (l = f[k], !h[l] && (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !b || !m.includes(a))) { - if (m.length === 2 ** 31 - 1) { - g = new S(m); + for (let h = 0, l, n; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? n = g : d.set(l, n = []), !b || !n.includes(a))) { + if (n.length === 2 ** 31 - 1) { + g = new R(n); if (this.fastupdate) { - for (let n of this.reg.values()) { - n.includes(m) && (n[n.indexOf(m)] = g); + for (let m of this.reg.values()) { + m.includes(n) && (m[m.indexOf(n)] = g); } } - d.set(l, m = g); + d.set(l, n = g); } - m.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); + n.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])); } } } else { @@ -727,49 +727,49 @@ function Ba(a) { } } if (this.store && (!b || !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]; + k = B(); + for (let h = 0, l; h < this.C.length; h++) { + l = this.C[h]; if ((b = l.I) && !b(c)) { continue; } - let m; + let n; if ("function" === typeof l) { - m = l(c); - if (!m) { + n = l(c); + if (!n) { continue; } l = [l.V]; } else if (E(l) || l.constructor === String) { - h[l] = c[l]; + k[l] = c[l]; continue; } - Ea(c, h, l, 0, l[0], m); + Fa(c, k, l, 0, l[0], n); } } - this.store.set(a, h || c); + this.store.set(a, k || c); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Ea(a, c, b, e, d, f) { +function Fa(a, c, b, e, d, f) { a = a[d]; if (e === b.length - 1) { c[d] = f || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Ea(a, c, b, e, d); + Fa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = B()), d = b[++e], Ea(a, c, b, e, d); + c = c[d] || (c[d] = B()), d = b[++e], Fa(a, c, b, e, d); } } } -function Da(a, c, b, e, d, f, g, h) { +function Ea(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -781,60 +781,60 @@ function Da(a, c, b, e, d, f, g, h) { } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Da(a, c, b, e, d, f, g, h); + Ea(a, c, b, e, d, f, g, k); } } else { - g = c[++e], Da(a, c, b, e, d, f, g, h); + g = c[++e], Ea(a, c, b, e, d, f, g, k); } } } else { d.db && d.remove(f); } } -;function Fa(a, c, b, e, d, f, g) { - const h = a.length; - let k = [], l, m; +;function Ga(a, c, b, e, d, f, g) { + const k = a.length; + let h = [], l, n; l = B(); - for (let n = 0, q, r, p, v; n < c; n++) { - for (let u = 0; u < h; u++) { - if (p = a[u], n < p.length && (q = p[n])) { - for (let x = 0; x < q.length; x++) { - r = q[x]; - (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1); - v = k[m] || (k[m] = []); + for (let m = 0, q, p, r, u; m < c; m++) { + for (let v = 0; v < k; v++) { + if (r = a[v], m < r.length && (q = r[m])) { + for (let w = 0; w < q.length; w++) { + p = q[w]; + (n = l[p]) ? l[p]++ : (n = 0, l[p] = 1); + u = h[n] || (h[n] = []); if (!g) { - let y = n + (u || !d ? 0 : f || 0); - v = v[y] || (v[y] = []); + let y = m + (v || !d ? 0 : f || 0); + u = u[y] || (u[y] = []); } - v.push(r); - if (g && b && m === h - 1 && v.length - e === b) { - return v; + u.push(p); + if (g && b && n === k - 1 && u.length - e === b) { + return u; } } } } } - if (a = k.length) { + if (a = h.length) { if (d) { - k = 1 < k.length ? Ga(k, b, e, g, f) : (k = k[0]).length > b || e ? k.slice(e, b + e) : k; + h = 1 < h.length ? Ha(h, b, e, g, f) : (h = h[0]).length > b || e ? h.slice(e, b + e) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; + h = h[a - 1]; if (b || e) { if (g) { - if (k.length > b || e) { - k = k.slice(e, b + e); + if (h.length > b || e) { + h = h.slice(e, b + e); } } else { d = []; - for (let n = 0, q; n < k.length; n++) { - if (q = k[n], q.length > e) { + for (let m = 0, q; m < h.length; m++) { + if (q = h[m], q.length > e) { e -= q.length; } else { if (q.length > b || e) { @@ -846,27 +846,27 @@ function Da(a, c, b, e, d, f, g, h) { } } } - k = 1 < d.length ? [].concat.apply([], d) : d[0]; + h = 1 < d.length ? [].concat.apply([], d) : d[0]; } } } } - return k; + return h; } -function Ga(a, c, b, e, d) { +function Ha(a, c, b, e, d) { const f = [], g = B(); - let h; - var k = a.length; + let k; + var h = a.length; let l; if (e) { - for (d = k - 1; 0 <= d; d--) { + for (d = h - 1; 0 <= d; d--) { if (l = (e = a[d]) && e.length) { - for (k = 0; k < l; k++) { - if (h = e[k], !g[h]) { - if (g[h] = 1, b) { + for (h = 0; h < l; h++) { + if (k = e[h], !g[k]) { + if (g[k] = 1, b) { b--; } else { - if (f.push(h), f.length === c) { + if (f.push(k), f.length === c) { return f; } } @@ -875,17 +875,17 @@ function Ga(a, c, b, e, d) { } } } else { - for (let m = k - 1, n, q = 0; 0 <= m; m--) { - n = a[m]; - for (let r = 0; r < n.length; r++) { - if (l = (e = n[r]) && e.length) { - for (let p = 0; p < l; p++) { - if (h = e[p], !g[h]) { - if (g[h] = 1, b) { + for (let n = h - 1, m, q = 0; 0 <= n; n--) { + m = a[n]; + for (let p = 0; p < m.length; p++) { + if (l = (e = m[p]) && e.length) { + for (let r = 0; r < l; r++) { + if (k = e[r], !g[k]) { + if (g[k] = 1, b) { b--; } else { - let v = (r + (m < k - 1 ? d || 0 : 0)) / (m + 1) | 0; - (f[v] || (f[v] = [])).push(h); + let u = (p + (n < h - 1 ? d || 0 : 0)) / (n + 1) | 0; + (f[u] || (f[u] = [])).push(k); if (++q === c) { return f; } @@ -898,12 +898,12 @@ function Ga(a, c, b, e, d) { } return f; } -function Ha(a, c, b) { +function Ia(a, c, b) { const e = B(), d = []; for (let f = 0, g; f < c.length; f++) { g = c[f]; - for (let h = 0; h < g.length; h++) { - e[g[h]] = 1; + for (let k = 0; k < g.length; k++) { + e[g[k]] = 1; } } if (b) { @@ -911,75 +911,75 @@ function Ha(a, c, b) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, h; f < a.result.length; f++) { + for (let f = 0, g, k; 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); + k = g[c], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); } } } return d; } -;function Ia(a, c, b, e) { +;function Ja(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? V.call(this, a) : a; } let d = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { if (b) { - if (b >= h) { - b -= h; + if (b >= k) { + b -= k; continue; } - b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); + b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); } - h > c && (g = g.slice(0, c), h = c); - if (!d.length && h >= c) { - return e ? W.call(this, g) : g; + k > c && (g = g.slice(0, c), k = c); + if (!d.length && k >= c) { + return e ? V.call(this, g) : g; } d.push(g); - c -= h; + c -= k; if (!c) { break; } } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? W.call(this, d) : d; + return e ? V.call(this, d) : d; } -;function Ja(a, c, b) { +;function Ka(a, c, b) { var e = b[0]; if (e.then) { - return Promise.all(b).then(function(m) { - return a[c].apply(a, m); + 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 = [], f = 0, g = 0, h, k, l; - for (let m = 0, n; m < b.length; m++) { - if (n = b[m]) { + let d = [], f = 0, g = 0, k, h, l; + for (let n = 0, m; n < b.length; n++) { + if (m = b[n]) { let q; - if (n.constructor === X) { - q = n.result; - } else if (n.constructor === Array) { - q = n; + if (m.constructor === W) { + q = m.result; + } else if (m.constructor === Array) { + q = m; } 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, q = n.index.search(n).result, n.resolve = k, n.enrich = h; - } else if (n.and) { - q = a.and(n.and); - } else if (n.or) { - q = a.or(n.or); - } else if (n.xor) { - q = a.xor(n.xor); - } else if (n.not) { - q = a.not(n.not); + if (f = m.limit || 0, g = m.offset || 0, l = m.suggest, h = m.resolve, k = m.enrich && h, m.index) { + m.resolve = !1, m.enrich = !1, q = m.index.search(m).result, m.resolve = h, m.enrich = k; + } else if (m.and) { + q = a.and(m.and); + } else if (m.or) { + q = a.or(m.or); + } else if (m.xor) { + q = a.xor(m.xor); + } else if (m.not) { + q = a.not(m.not); } else { continue; } @@ -987,54 +987,54 @@ function Ha(a, c, b) { if (q.then) { d.push(q); } else if (q.length) { - e[m] = q; + e[n] = q; } else if (!l && ("and" === c || "xor" === c)) { e = []; break; } } } - return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } -;X.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ja(this, "or", arguments); - return Ka.call(this, a, c, b, e, d, f); +;W.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ka(this, "or", arguments); + return La.call(this, a, c, b, e, d, f); }; -function Ka(a, c, b, e, d, f) { +function La(a, c, b, e, d, f) { if (c.length) { const g = this; - return Promise.all(c).then(function(h) { + return Promise.all(c).then(function(k) { a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } - return Ka.call(g, a, [], b, e, d, f); + return La.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 = Ga(a, b, e, !1, this.h), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ha(a, b, e, !1, this.h), e = 0)); return f ? this.resolve(b, e, d) : this; } -;X.prototype.and = function() { +;W.prototype.and = function() { let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); - return La.call(this, f, g, h, k, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:n, suggest:m} = Ka(this, "and", arguments); + return Ma.call(this, f, g, k, h, l, n, m); } return d ? this.resolve(c, b, e) : this; }; -function La(a, c, b, e, d, f, g) { +function Ma(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } - return La.call(h, a, [], b, e, d, f, g); + return Ma.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -1042,7 +1042,7 @@ function La(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = ca(a)) { - return this.result = Fa(a, c, b, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Ga(a, c, b, e, g, this.h, f), f ? d ? V.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -1051,65 +1051,65 @@ function La(a, c, b, e, d, f, g) { } return f ? this.resolve(b, e, d) : this; } -;X.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "xor", arguments); - return Ma.call(this, a, c, b, e, d, f, g); +;W.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ka(this, "xor", arguments); + return Na.call(this, a, c, b, e, d, f, g); }; -function Ma(a, c, b, e, d, f, g) { +function Na(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } - return Ma.call(h, a, [], b, e, d, f, g); + return Na.call(k, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Na.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Oa.call(this, a, b, e, f, this.h), f ? d ? V.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Na(a, c, b, e, d) { +function Oa(a, c, b, e, d) { const f = [], g = B(); - 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 q = 0, r; q < n.length; q++) { - r = n[q], g[r] = g[r] ? 2 : 1; + let k = 0; + for (let h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); + for (let n = 0, m; n < l.length; n++) { + if (m = l[n]) { + for (let q = 0, p; q < m.length; q++) { + p = m[q], g[p] = g[p] ? 2 : 1; } } } } } - for (let k = 0, l, m = 0; k < h; k++) { - for (let n = 0, q; n < a.length; n++) { - if (q = a[n]) { - if (l = q[k]) { - for (let r = 0, p; r < l.length; r++) { - if (p = l[r], 1 === g[p]) { + for (let h = 0, l, n = 0; h < k; h++) { + for (let m = 0, q; m < a.length; m++) { + if (q = a[m]) { + if (l = q[h]) { + for (let p = 0, r; p < l.length; p++) { + if (r = l[p], 1 === g[r]) { if (b) { b--; } else { if (e) { - if (f.push(p), f.length === c) { + if (f.push(r), f.length === c) { return f; } } else { - const v = k + (n ? d : 0); - f[v] || (f[v] = []); - f[v].push(p); - if (++m === c) { + const u = h + (m ? d : 0); + f[u] || (f[u] = []); + f[u].push(r); + if (++n === c) { return f; } } @@ -1122,35 +1122,35 @@ function Na(a, c, b, e, d) { } return f; } -;X.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "not", arguments); - return Oa.call(this, a, c, b, e, d, f, g); +;W.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ka(this, "not", arguments); + return Pa.call(this, a, c, b, e, d, f, g); }; -function Oa(a, c, b, e, d, f, g) { +function Pa(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } - return Oa.call(h, a, [], b, e, d, f, g); + return Pa.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Pa.call(this, a, b, e, f); + this.result = Qa.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? W.call(this.index, this.result) : this.result : this; + return f ? d ? V.call(this.index, this.result) : this.result : this; } -function Pa(a, c, b, e) { +function Qa(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { + for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (b) { b--; } else { @@ -1159,7 +1159,7 @@ function Pa(a, c, b, e) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { + if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { return d; } } @@ -1170,9 +1170,9 @@ function Pa(a, c, b, e) { } return d; } -;function X(a) { - if (!this || this.constructor !== X) { - return new X(a); +;function W(a) { + if (!this || this.constructor !== W) { + return new W(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -1181,7 +1181,7 @@ function Pa(a, c, b, e) { this.result = a || []; this.h = 0; } -X.prototype.limit = function(a) { +W.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -1200,7 +1200,7 @@ X.prototype.limit = function(a) { } return this; }; -X.prototype.offset = function(a) { +W.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -1212,283 +1212,283 @@ X.prototype.offset = function(a) { } return this; }; -X.prototype.boost = function(a) { +W.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, c, b) { +W.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Ia.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Ja.call(d, e, a || 100, c, b)) : e; }; B(); -V.prototype.search = function(a, c, b, e) { +U.prototype.search = function(a, c, b, e) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); - let d = [], f = [], g; - var h; + let d = []; + var f = [], g; let k; - let l; - let m, n = 0; - var q = !0; - let r; + let h, l; + let n = 0; + var m = !0; + let q; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; - g = b.pluck; + var p = b.pluck; k = b.merge; - l = g || b.field || (l = b.index) && (l.index ? null : l); - var p = this.tag && b.tag; - var v = b.suggest; - q = !1 !== b.resolve; - if (!q && !g) { - if (l = l || this.field) { - E(l) ? g = l : (l.constructor === Array && 1 === l.length && (l = l[0]), g = l.field || l.index); + h = p || b.field || (h = b.index) && (h.index ? null : h); + l = this.tag && b.tag; + var r = b.suggest; + m = !1 !== b.resolve; + if (!m && !p) { + if (h = h || this.field) { + E(h) ? p = h : (h.constructor === Array && 1 === h.length && (h = h[0]), p = h.field || h.index); } - if (!g) { + if (!p) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - this.store && b.enrich && !q && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - r = (h = this.store && b.enrich && q) && b.highlight; + this.store && b.enrich && !m && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + q = (g = this.store && b.enrich && m) && b.highlight; c = b.limit || c; - m = b.offset || 0; + var u = b.offset || 0; c || (c = 100); - if (p && (!this.db || !e)) { - p.constructor !== Array && (p = [p]); - var u = []; - for (let z = 0, w; z < p.length; z++) { - w = p[z]; - if (E(w)) { + if (l && (!this.db || !e)) { + l.constructor !== Array && (l = [l]); + var v = []; + for (let A = 0, x; A < l.length; A++) { + x = l[A]; + if (E(x)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (w.field && w.tag) { - var x = w.tag; - if (x.constructor === Array) { - for (var y = 0; y < x.length; y++) { - u.push(w.field, x[y]); + if (x.field && x.tag) { + var w = x.tag; + if (w.constructor === Array) { + for (var y = 0; y < w.length; y++) { + v.push(x.field, w[y]); } } else { - u.push(w.field, x); + v.push(x.field, w); } } else { - x = Object.keys(w); - for (let D = 0, H, C; D < x.length; D++) { - if (H = x[D], C = w[H], C.constructor === Array) { + w = Object.keys(x); + for (let D = 0, H, C; D < w.length; D++) { + if (H = w[D], C = x[H], C.constructor === Array) { for (y = 0; y < C.length; y++) { - u.push(H, C[y]); + v.push(H, C[y]); } } else { - u.push(H, C); + v.push(H, C); } } } } - if (!u.length) { + if (!v.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - p = u; + l = v; if (!a) { - v = []; - if (u.length) { - for (p = 0; p < u.length; p += 2) { + m = []; + if (v.length) { + for (f = 0; f < v.length; f += 2) { if (this.db) { - q = this.index.get(u[p]); - if (!q) { - console.warn("Tag '" + u[p] + ":" + u[p + 1] + "' will be skipped because there is no field '" + u[p] + "'."); + p = this.index.get(v[f]); + if (!p) { + console.warn("Tag '" + v[f] + ":" + v[f + 1] + "' will be skipped because there is no field '" + v[f] + "'."); continue; } - v.push(q = q.db.tag(u[p + 1], c, m, h)); + m.push(p = p.db.tag(v[f + 1], c, u, g)); } else { - q = Qa.call(this, u[p], u[p + 1], c, m, h); + p = Ra.call(this, v[f], v[f + 1], c, u, g); } - d.push({field:u[p], tag:u[p + 1], result:q}); + d.push({field:v[f], tag:v[f + 1], result:p}); } } - return v.length ? Promise.all(v).then(function(z) { - for (let w = 0; w < z.length; w++) { - d[w].result = z[w]; + return m.length ? Promise.all(m).then(function(A) { + for (let x = 0; x < A.length; x++) { + d[x].result = A[x]; } return d; }) : d; } } - l && l.constructor !== Array && (l = [l]); + h && h.constructor !== Array && (h = [h]); } - l || (l = this.field); - u = !e && (this.worker || this.db) && []; + h || (h = this.field); + v = !e && (this.worker || this.db) && []; let F; - for (let z = 0, w, D, H; z < l.length; z++) { - D = l[z]; - if (this.db && this.tag && !this.D[z]) { + for (let A = 0, x, D, H; A < h.length; A++) { + D = h[A]; + if (this.db && this.tag && !this.D[A]) { continue; } let C; - E(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, m = C.offset || m, v = C.suggest || v, h = this.store && (C.enrich || h)); + E(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, u = C.offset || u, r = C.suggest || r, g = this.store && (C.enrich || g)); if (e) { - w = e[z]; + x = e[A]; } else { - if (x = C || b, y = this.index.get(D), p && (this.db && (x.tag = p, F = y.db.support_tag_search, x.field = l), F || (x.enrich = !1)), u) { - u[z] = y.search(a, c, x); - x && h && (x.enrich = h); + if (w = C || b, y = this.index.get(D), l && (this.db && (w.tag = l, F = y.db.support_tag_search, w.field = h), F || (w.enrich = !1)), v) { + v[A] = y.search(a, c, w); + w && g && (w.enrich = g); continue; } else { - w = y.search(a, c, x), x && h && (x.enrich = h); + x = y.search(a, c, w), w && g && (w.enrich = g); } } - H = w && (q ? w.length : w.result.length); - if (p && H) { - x = []; + H = x && (m ? x.length : x.result.length); + if (l && H) { + w = []; y = 0; if (this.db && e) { if (!F) { - for (let G = l.length; G < e.length; G++) { + for (let G = h.length; G < e.length; G++) { let L = e[G]; if (L && L.length) { - y++, x.push(L); - } else if (!v) { - return q ? d : new X(d); + y++, w.push(L); + } else if (!r) { + return m ? d : new W(d); } } } } else { - for (let G = 0, L, rb; G < p.length; G += 2) { - L = this.tag.get(p[G]); + for (let G = 0, L, sb; G < l.length; G += 2) { + L = this.tag.get(l[G]); if (!L) { - if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), v) { + if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), r) { continue; } else { - return q ? d : new X(d); + return m ? d : new W(d); } } - if (rb = (L = L && L.get(p[G + 1])) && L.length) { - y++, x.push(L); - } else if (!v) { - return q ? d : new X(d); + if (sb = (L = L && L.get(l[G + 1])) && L.length) { + y++, w.push(L); + } else if (!r) { + return m ? d : new W(d); } } } if (y) { - w = Ha(w, x, q); - H = w.length; - if (!H && !v) { - return q ? w : new X(w); + x = Ia(x, w, m); + H = x.length; + if (!H && !r) { + return m ? x : new W(x); } y--; } } if (H) { - f[n] = D, d.push(w), n++; - } else if (1 === l.length) { - return q ? d : new X(d); + f[n] = D, d.push(x), n++; + } else if (1 === h.length) { + return m ? d : new W(d); } } - if (u) { - if (this.db && p && p.length && !F) { - for (h = 0; h < p.length; h += 2) { - e = this.index.get(p[h]); - if (!e) { - if (console.warn("Tag '" + p[h] + ":" + p[h + 1] + "' was not found because there is no field '" + p[h] + "'."), v) { + if (v) { + if (this.db && l && l.length && !F) { + for (g = 0; g < l.length; g += 2) { + f = this.index.get(l[g]); + if (!f) { + if (console.warn("Tag '" + l[g] + ":" + l[g + 1] + "' was not found because there is no field '" + l[g] + "'."), r) { continue; } else { - return q ? d : new X(d); + return m ? d : new W(d); } } - u.push(e.db.tag(p[h + 1], c, m, !1)); + v.push(f.db.tag(l[g + 1], c, u, !1)); } } - const z = this; - return Promise.all(u).then(function(w) { - return w.length ? z.search(a, c, b, w) : w; + const A = this; + return Promise.all(v).then(function(x) { + return x.length ? A.search(a, c, b, x) : x; }); } if (!n) { - return q ? d : new X(d); + return m ? d : new W(d); } - if (g && (!h || !this.store)) { + if (p && (!g || !this.store)) { return d[0]; } - u = []; - for (let z = 0, w; z < f.length; z++) { - w = d[z]; - h && w.length && !w[0].doc && (this.db ? u.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = W.call(this, w)); - if (g) { - return q ? w : new X(w); + v = []; + for (u = 0; u < f.length; u++) { + r = d[u]; + g && r.length && "undefined" === typeof r[0].doc && (this.db ? v.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = V.call(this, r)); + if (p) { + return m ? r : new W(r); } - d[z] = {field:f[z], result:w}; + d[u] = {field:f[u], result:r}; } - if (h && this.db && u.length) { - const z = this; - return Promise.all(u).then(function(w) { - for (let D = 0; D < w.length; D++) { - d[D].result = w[D]; + if (g && this.db && v.length) { + const A = this; + return Promise.all(v).then(function(x) { + for (let D = 0; D < x.length; D++) { + d[D].result = x[D]; } - return k ? Ra(d, c) : r ? Sa(d, a, z.index, z.field, z.D, r) : d; + return k ? Sa(d, c) : q ? Ta(d, a, A.index, A.field, A.D, q) : d; }); } - return k ? Ra(d, c) : r ? Sa(d, a, this.index, this.field, this.D, r) : d; + return k ? Sa(d, c) : q ? Ta(d, a, this.index, this.field, this.D, q) : d; }; -function Sa(a, c, b, e, d, f) { - let g, h, k; - for (let m = 0, n, q, r, p, v; m < a.length; m++) { - n = a[m].result; - q = a[m].field; - p = b.get(q); - r = p.encoder; - k = p.tokenize; - v = d[e.indexOf(q)]; - r !== g && (g = r, h = g.encode(c)); - for (let u = 0; u < n.length; u++) { - let x = ""; - var l = ba(n[u].doc, v); +function Ta(a, c, b, e, d, f) { + let g, k, h; + for (let n = 0, m, q, p, r; n < a.length; n++) { + let u = a[n].result; + m = a[n].field; + p = b.get(m); + q = p.encoder; + h = p.tokenize; + r = d[e.indexOf(m)]; + q !== g && (g = q, k = g.encode(c)); + for (let v = 0; v < u.length; v++) { + let w = ""; + var l = ba(u[v].doc, r); let y = g.encode(l); l = l.split(g.split); - for (let F = 0, z, w; F < y.length; F++) { - z = y[F]; - w = l[F]; + for (let F = 0, A, x; F < y.length; F++) { + A = y[F]; + x = l[F]; let D; - for (let H = 0, C; H < h.length; H++) { - if (C = h[H], "strict" === k) { - if (z === C) { - x += (x ? " " : "") + f.replace("$1", w); + for (let H = 0, C; H < k.length; H++) { + if (C = k[H], "strict" === h) { + if (A === C) { + w += (w ? " " : "") + f.replace("$1", x); D = !0; break; } } else { - const G = z.indexOf(C); + const G = A.indexOf(C); if (-1 < G) { - x += (x ? " " : "") + w.substring(0, G) + f.replace("$1", w.substring(G, C.length)) + w.substring(G + C.length); + w += (w ? " " : "") + x.substring(0, G) + f.replace("$1", x.substring(G, C.length)) + x.substring(G + C.length); D = !0; break; } } } - D || (x += (x ? " " : "") + l[F]); + D || (w += (w ? " " : "") + l[F]); } - n[u].highlight = x; + u[v].highlight = w; } } return a; } -function Ra(a, c) { +function Sa(a, c) { const b = [], 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], "object" !== typeof l && (l = {id:l}), k = l.id, m = e[k]) { - m.push(f.field); + for (let k = 0, h, l, n; k < g.length; k++) { + if (l = g[k], "object" !== typeof l && (l = {id:l}), h = l.id, n = e[h]) { + n.push(f.field); } else { if (b.length === c) { return b; } - l.field = e[k] = [f.field]; + l.field = e[h] = [f.field]; b.push(l); } } } return b; } -function Qa(a, c, b, e, d) { +function Ra(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1497,11 +1497,11 @@ function Qa(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = W.call(this, f)); + d && (f = V.call(this, f)); return f; } } -function W(a) { +function V(a) { if (!this || !this.store) { return a; } @@ -1511,26 +1511,26 @@ function W(a) { } return c; } -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); +;function U(a) { + if (!this || this.constructor !== U) { + return new U(a); } const c = a.document || a.doc || a; let b, e; this.D = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && Ta(b, this.J) || "id"; + this.key = (b = c.key || c.id) && Ua(b, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; - this.reg = !this.fastupdate || a.worker || a.db ? e ? new U(e) : new Set() : e ? new T(e) : new Map(); + this.reg = !this.fastupdate || a.worker || a.db ? e ? new T(e) : new Set() : e ? new S(e) : new Map(); this.C = (b = c.store || null) && b && !0 !== b && []; - this.store = b && (e ? new T(e) : new Map()); - this.cache = (b = a.cache || null) && new Y(b); + this.store = b && (e ? new S(e) : new Map()); + this.cache = (b = a.cache || null) && new X(b); a.cache = !1; this.worker = a.worker; this.priority = a.priority || 4; - this.index = Ua.call(this, a, c); + this.index = Va.call(this, a, c); this.tag = null; if (b = c.tag) { if ("string" === typeof b && (b = [b]), b.length) { @@ -1543,7 +1543,7 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.F[d] = f.custom : (this.F[d] = Ta(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); + f.custom ? this.F[d] = f.custom : (this.F[d] = Ua(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()); } @@ -1559,9 +1559,9 @@ function W(a) { const d = this; return Promise.all(a).then(function(f) { let g = 0; - for (const h of d.index.entries()) { - const k = h[0]; - h[1].then && d.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 d; }); @@ -1570,7 +1570,7 @@ function W(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -t = V.prototype; +t = U.prototype; t.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); @@ -1580,7 +1580,7 @@ t.mount = function(a) { for (let d = 0, f; d < this.R.length; d++) { f = this.R[d]; var b = void 0; - this.index.set(f, b = new O({}, this.reg)); + this.index.set(f, b = new N({}, this.reg)); c === this.field && (c = c.slice(0)); c.push(f); b.tag = this.tag.get(f); @@ -1591,9 +1591,9 @@ t.mount = function(a) { for (let d = 0, f, g; d < c.length; d++) { e.field = g = c[d]; f = this.index.get(g); - const h = new a.constructor(a.id, e); - h.id = a.id; - b[d] = h.mount(f); + const k = new a.constructor(a.id, e); + k.id = a.id; + b[d] = k.mount(f); f.document = !0; d ? f.bypass = !0 : f.store = this.store; } @@ -1615,7 +1615,7 @@ t.destroy = function() { } return Promise.all(a); }; -function Ua(a, c) { +function Va(a, c) { const b = new Map(); let e = c.index || c.field || c; E(e) && (e = [e]); @@ -1624,23 +1624,23 @@ function Ua(a, c) { E(f) || (g = f, f = f.field); g = I(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const h = new Q(g); - b.set(f, h); + const k = new P(g); + b.set(f, k); } - this.worker || b.set(f, new O(g, this.reg)); - g.custom ? this.D[d] = g.custom : (this.D[d] = Ta(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.worker || b.set(f, new N(g, this.reg)); + g.custom ? this.D[d] = g.custom : (this.D[d] = Ua(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 = 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.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ta(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ua(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 b; } -function Ta(a, c) { +function Ua(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1709,14 +1709,14 @@ t.set = function(a, c) { this.store.set(a, c); return this; }; -t.searchCache = Va; +t.searchCache = Wa; t.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const h = this; + const k = this; return c.then(function() { - return h.export(a, g, b + 1); + return k.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -1725,23 +1725,23 @@ t.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = wa(this.reg); + f = xa(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && ua(this.tag, this.reg.size); + f = this.tag && va(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && sa(this.store); + f = this.store && ta(this.store); c = null; break; default: return; } - return ya.call(this, a, c, d, f, b, e); + return za.call(this, a, c, d, f, b, e); }; t.import = function(a, c) { var b = a.split("."); @@ -1759,7 +1759,7 @@ t.import = function(a, c) { switch(b) { case "reg": this.fastupdate = !1; - this.reg = xa(c, this.reg); + this.reg = ya(c, this.reg); for (let d = 0, f; d < this.field.length; d++) { f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } @@ -1772,17 +1772,17 @@ t.import = function(a, c) { } break; case "tag": - this.tag = va(c, this.tag); + this.tag = wa(c, this.tag); break; case "doc": - this.store = ta(c, this.store); + this.store = ua(c, this.store); } } }; -la(V.prototype); -function Va(a, c, b) { +ma(U.prototype); +function Wa(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Y()); + this.cache || (this.cache = new X()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -1797,104 +1797,104 @@ function Va(a, c, b) { } return e; } -function Y(a) { +function X(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -Y.prototype.set = function(a, c) { +X.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -Y.prototype.get = function(a) { +X.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -Y.prototype.remove = function(a) { +X.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -Y.prototype.clear = function() { +X.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Wa = {normalize:function(a) { +const Xa = {normalize:function(a) { return a.toLowerCase(); }}; -const Xa = 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 Ya = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Za = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const $a = {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 ab = /[\x00-\x7F]+/g; +const Ya = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Za = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), $a = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const ab = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; const bb = /[\x00-\x7F]+/g; const cb = /[\x00-\x7F]+/g; -var db = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Wa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Xa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Xa, matcher:Ya, replacer:Za}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Xa, replacer:Za.concat([/(?!^)[aeo]/g, ""]), matcher:Ya}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const db = /[\x00-\x7F]+/g; +var eb = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Xa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ya}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ya, matcher:Za, replacer:$a}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ya, replacer:$a.concat([/(?!^)[aeo]/g, ""]), matcher:Za}, 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 = $a[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = $a[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = ab[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = ab[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ab, " "); + return ("" + a).replace(bb, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(bb, ""); + return ("" + a).replace(cb, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(cb, " "); + return ("" + a).replace(db, " "); }}}; -const eb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -O.prototype.add = function(a, c, b, e) { +const fb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +N.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); if (e = c.length) { - const l = B(), m = B(), n = this.depth, q = this.resolution; - for (let r = 0; r < e; r++) { - let p = c[this.rtl ? e - 1 - r : r]; - var d = p.length; - if (d && (n || !m[p])) { - var f = this.score ? this.score(c, p, r, null, 0) : fb(q, e, r), g = ""; + const l = B(), n = B(), m = this.depth, q = this.resolution; + for (let p = 0; p < e; p++) { + let r = c[this.rtl ? e - 1 - p : p]; + var d = r.length; + if (d && (m || !n[r])) { + var f = this.score ? this.score(c, r, p, null, 0) : gb(q, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let v = 0, u; v < d; v++) { - for (f = d; f > v; f--) { - g = p.substring(v, f); - u = this.rtl ? d - 1 - v : v; - var h = this.score ? this.score(c, p, r, g, u) : fb(q, e, r, d, u); - gb(this, m, g, h, a, b); + for (let u = 0, v; u < d; u++) { + for (f = d; f > u; f--) { + g = r.substring(u, f); + v = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(c, r, p, g, v) : gb(q, e, p, d, v); + hb(this, n, g, k, a, b); } } break; } case "reverse": if (1 < d) { - for (h = d - 1; 0 < h; h--) { - g = p[this.rtl ? d - 1 - h : h] + g; - var k = this.score ? this.score(c, p, r, g, h) : fb(q, e, r, d, h); - gb(this, m, g, k, a, b); + for (k = d - 1; 0 < k; k--) { + g = r[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, r, p, g, k) : gb(q, e, p, d, k); + hb(this, n, g, h, a, b); } g = ""; } case "forward": if (1 < d) { - for (h = 0; h < d; h++) { - g += p[this.rtl ? d - 1 - h : h], gb(this, m, g, f, a, b); + for (k = 0; k < d; k++) { + g += r[this.rtl ? d - 1 - k : k], hb(this, n, g, f, a, b); } break; } default: - if (gb(this, m, p, f, a, b), n && 1 < e && r < e - 1) { - for (d = B(), g = this.U, f = p, h = Math.min(n + 1, this.rtl ? r + 1 : e - r), d[f] = 1, k = 1; k < h; k++) { - if ((p = c[this.rtl ? e - 1 - r - k : r + k]) && !d[p]) { - d[p] = 1; - const v = this.score ? this.score(c, f, r, p, k - 1) : fb(g + (e / 2 > g ? 0 : 1), e, r, h - 1, k - 1), u = this.bidirectional && p > f; - gb(this, l, u ? f : p, v, a, b, u ? p : f); + if (hb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { + for (d = B(), g = this.U, f = r, k = Math.min(m + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { + if ((r = c[this.rtl ? e - 1 - p - h : p + h]) && !d[r]) { + d[r] = 1; + const u = this.score ? this.score(c, f, p, r, h - 1) : gb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; + hb(this, l, v ? f : r, u, a, b, v ? r : f); } } } @@ -1906,98 +1906,98 @@ O.prototype.add = function(a, c, b, e) { c = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.T && hb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && ib(this)); return this; }; -function gb(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - if (g ? (c = k || (c[b] = B()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = k = []), h = h[e] || (h[e] = []), !f || !h.includes(d)) { - if (h.length === 2 ** 31 - 1) { - c = new S(h); +function hb(a, c, b, e, d, f, g) { + let k = g ? a.ctx : a.map, h; + if (!c[b] || g && !(h = c[b])[g]) { + if (g ? (c = h || (c[b] = B()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { + if (k.length === 2 ** 31 - 1) { + c = new R(k); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(h) && (l[l.indexOf(h)] = c); + l.includes(k) && (l[l.indexOf(k)] = c); } } - k[e] = h = c; + h[e] = k = c; } - h.push(d); - a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h])); + k.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } } -function fb(a, c, b, e, d) { +function gb(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;O.prototype.search = function(a, c, b) { +;N.prototype.search = function(a, c, b) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); - let e = [], d, f, g, h = 0, k, l, m, n, q; - b ? (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, q = (k = !1 !== b.resolve) && b.enrich, m = b.boost, n = b.resolution, l = this.db && b.tag) : k = this.resolve; - let r = this.encoder.encode(a); - d = r.length; - c = c || (k ? 100 : 0); + let e = [], d, f, g, k = 0, h, l, n, m, q; + b ? (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, q = (h = !1 !== b.resolve) && b.enrich, n = b.boost, m = b.resolution, l = this.db && b.tag) : h = this.resolve; + let p = this.encoder.encode(a); + d = p.length; + c = c || (h ? 100 : 0); if (1 === d) { - return ib.call(this, r[0], "", c, h, k, q, l); + return jb.call(this, p[0], "", c, k, h, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return ib.call(this, r[0], r[1], c, h, k, q, l); + return jb.call(this, p[0], p[1], c, k, h, q, l); } - let p = B(), v = 0, u; - 1 < d && f && (u = r[0], v = 1); - n || 0 === n || (n = u ? this.U : this.resolution); + let r = B(), u = 0, v; + 1 < d && f && (v = p[0], u = 1); + m || 0 === m || (m = v ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, r, c, h, g, k, q, l), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, c, k, g, h, q, l), !1 !== a)) { return a; } - const x = this; + const w = this; return async function() { - for (let y, F; v < d; v++) { - if ((F = r[v]) && !p[F]) { - p[F] = 1; - y = await jb(x, F, u, 0, 0, !1, !1); - if (y = kb(y, e, g, n)) { + for (let y, F; u < d; u++) { + if ((F = p[u]) && !r[F]) { + r[F] = 1; + y = await kb(w, F, v, 0, 0, !1, !1); + if (y = lb(y, e, g, m)) { e = y; break; } - u && (g && y && e.length || (u = F)); + v && (g && y && e.length || (v = F)); } - g && u && v === d - 1 && !e.length && (n = x.resolution, u = "", v = -1, p = B()); + g && v && u === d - 1 && !e.length && (m = w.resolution, v = "", u = -1, r = B()); } - return lb(e, n, c, h, g, m, k); + return mb(e, m, c, k, g, n, h); }(); } - for (let x, y; v < d; v++) { - if ((y = r[v]) && !p[y]) { - p[y] = 1; - x = jb(this, y, u, 0, 0, !1, !1); - if (x = kb(x, e, g, n)) { - e = x; + for (let w, y; u < d; u++) { + if ((y = p[u]) && !r[y]) { + r[y] = 1; + w = kb(this, y, v, 0, 0, !1, !1); + if (w = lb(w, e, g, m)) { + e = w; break; } - u && (g && x && e.length || (u = y)); + v && (g && w && e.length || (v = y)); } - g && u && v === d - 1 && !e.length && (n = this.resolution, u = "", v = -1, p = B()); + g && v && u === d - 1 && !e.length && (m = this.resolution, v = "", u = -1, r = B()); } - return lb(e, n, c, h, g, m, k); + return mb(e, m, c, k, g, n, h); }; -function lb(a, c, b, e, d, f, g) { - let h = a.length, k = a; - if (1 < h) { - k = Fa(a, c, b, e, d, f, g); - } else if (1 === h) { - return g ? Ia.call(null, a[0], b, e) : new X(a[0]); +function mb(a, c, b, e, d, f, g) { + let k = a.length, h = a; + if (1 < k) { + h = Ga(a, c, b, e, d, f, g); + } else if (1 === k) { + return g ? Ja.call(null, a[0], b, e) : new W(a[0]); } - return g ? k : new X(k); + return g ? h : new W(h); } -function ib(a, c, b, e, d, f, g) { - a = jb(this, a, c, b, e, d, f, g); - return this.db ? a.then(function(h) { - return d ? h || [] : new X(h); - }) : a && a.length ? d ? Ia.call(this, a, b, e) : new X(a) : d ? [] : new X(); +function jb(a, c, b, e, d, f, g) { + a = kb(this, a, c, b, e, d, f, g); + return this.db ? a.then(function(k) { + return d ? k || [] : new W(k); + }) : a && a.length ? d ? Ja.call(this, a, b, e) : new W(a) : d ? [] : new W(); } -function kb(a, c, b, e) { +function lb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -2018,16 +2018,16 @@ function kb(a, c, b, e) { return d; } } -function jb(a, c, b, e, d, f, g, h) { - let k; - b && (k = a.bidirectional && c > b) && (k = b, b = c, c = k); +function kb(a, c, b, e, d, f, g, k) { + let h; + b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); if (a.db) { - return a.db.get(c, b, e, d, f, g, h); + return a.db.get(c, b, e, d, f, g, k); } a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;O.prototype.remove = function(a, c) { +;N.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -2042,15 +2042,15 @@ function jb(a, c, b, e, d, f, g, h) { } } } else { - mb(this.map, a), this.depth && mb(this.ctx, a); + nb(this.map, a), this.depth && nb(this.ctx, a); } c || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && hb(this)); + this.db && (this.commit_task.push({del:a}), this.T && ib(this)); this.cache && this.cache.remove(a); return this; }; -function mb(a, c) { +function nb(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -2065,25 +2065,25 @@ function mb(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = mb(e[1], c); + const d = e[0], f = nb(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function O(a, c) { - if (!this || this.constructor !== O) { - return new O(a); +;function N(a, c) { + if (!this || this.constructor !== N) { + return new N(a); } if (a) { var b = E(a) ? a : a.preset; - b && (eb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, eb[b], a)); + b && (fb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, fb[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? db[a.encoder] : a.encode || a.encoder || Wa; - this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; + const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? eb[a.encoder] : a.encode || a.encoder || Xa; + this.encoder = d.encode ? d : "object" === typeof d ? new ka(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; this.depth = "strict" === b && e.depth || 0; @@ -2092,12 +2092,12 @@ function mb(a, c) { this.score = a.score || null; e && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); (b = a.keystore || 0) && (this.keystore = b); - this.map = b ? new T(b) : new Map(); - this.ctx = b ? new T(b) : new Map(); - this.reg = c || (this.fastupdate ? b ? new T(b) : new Map() : b ? new U(b) : new Set()); + this.map = b ? new S(b) : new Map(); + this.ctx = b ? new S(b) : new Map(); + this.reg = c || (this.fastupdate ? b ? new S(b) : new Map() : b ? new T(b) : new Set()); this.U = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new Y(b); + this.cache = (b = a.cache || null) && new X(b); this.resolve = !1 !== a.resolve; if (b = a.db) { this.db = this.mount(b); @@ -2107,7 +2107,7 @@ function mb(a, c) { this.commit_timer = null; this.priority = a.priority || 4; } -t = O.prototype; +t = N.prototype; t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -2120,7 +2120,7 @@ t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function hb(a) { +function ib(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2144,7 +2144,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 nb(a) { +function ob(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -2152,7 +2152,7 @@ function nb(a) { } } else { for (const b of a.entries()) { - const e = b[0], d = nb(b[1]); + const e = b[0], d = ob(b[1]); d ? c += d : a.delete(e); } } @@ -2162,17 +2162,17 @@ t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - nb(this.map); - this.depth && nb(this.ctx); + ob(this.map); + this.depth && ob(this.ctx); return this; }; -t.searchCache = Va; +t.searchCache = Wa; t.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = wa(this.reg); + f = xa(this.reg); break; case 1: d = "cfg"; @@ -2180,29 +2180,29 @@ t.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = sa(this.map, this.reg.size); + f = ta(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ua(this.ctx, this.reg.size); + f = va(this.ctx, this.reg.size); break; default: return; } - return ya.call(this, a, c, d, f, b, e); + return za.call(this, a, c, d, f, b, e); }; t.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = xa(c, this.reg); + this.reg = ya(c, this.reg); break; case "map": - this.map = ta(c, this.map); + this.map = ua(c, this.map); break; case "ctx": - this.ctx = va(c, this.ctx); + this.ctx = wa(c, this.ctx); } } }; @@ -2214,24 +2214,24 @@ t.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = za(this.map, f); + b = Aa(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let h = za(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + d + '",' + h + "]"; - e += (e ? "," : "") + h; + let k = Aa(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; -la(O.prototype); -const ob = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), pb = ["map", "ctx", "tag", "reg", "cfg"]; -function qb(a, c = {}) { +ma(N.prototype); +const pb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), qb = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); +function rb(a, c = {}) { if (!this) { - return new qb(a, c); + return new rb(a, c); } "object" === typeof a && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2242,7 +2242,7 @@ function qb(a, c = {}) { this.db = null; this.h = {}; } -t = qb.prototype; +t = rb.prototype; t.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2253,13 +2253,18 @@ t.mount = function(a) { t.open = function() { let a = this; navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function(c, b) { - const e = ob.open(a.id + (a.field ? ":" + a.field : ""), 1); + return this.db || (this.db = new Promise(function(c, b) { + Y[a.id] || (Y[a.id] = []); + Y[a.id].push(a.field); + const e = pb.open(a.id, 1); e.onupgradeneeded = function() { const d = a.db = this.result; - pb.forEach(f => { - d.objectStoreNames.contains(f) || d.createObjectStore(f); - }); + for (let f = 0, g; f < qb.length; f++) { + g = qb[f]; + for (let k = 0, h; k < Y[a.id].length; k++) { + h = Y[a.id][k], d.objectStoreNames.contains(g + ("reg" !== g ? h ? ":" + h : "" : "")) || d.createObjectStore(g + ("reg" !== g ? h ? ":" + h : "" : "")); + } + } }; e.onblocked = function(d) { console.error("blocked", d); @@ -2276,58 +2281,65 @@ t.open = function() { }; c(a); }; - }); + })); }; t.close = function() { this.db && this.db.close(); this.db = null; }; t.destroy = function() { - const a = ob.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const a = pb.deleteDatabase(this.id); return Z(a); }; t.clear = function() { - const a = this.db.transaction(pb, "readwrite"); - for (let c = 0; c < pb.length; c++) { - a.objectStore(pb[c]).clear(); + const a = []; + for (let b = 0, e; b < qb.length; b++) { + e = qb[b]; + for (let d = 0, f; d < Y[this.id].length; d++) { + f = Y[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); + } } - return Z(a); + const c = this.db.transaction(a, "readwrite"); + for (let b = 0; b < a.length; b++) { + c.objectStore(a[b]).clear(); + } + return Z(c); }; t.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { - a = this.db.transaction(c ? "ctx" : "map", "readonly").objectStore(c ? "ctx" : "map").get(c ? c + ":" + a : a); + a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); const g = this; - return Z(a).then(function(h) { - let k = []; - if (!h || !h.length) { - return k; + return Z(a).then(function(k) { + let h = []; + if (!k || !k.length) { + return h; } if (d) { - if (!b && !e && 1 === h.length) { - return h[0]; + if (!b && !e && 1 === k.length) { + return k[0]; } - for (let l = 0, m; l < h.length; l++) { - if ((m = h[l]) && m.length) { - if (e >= m.length) { - e -= m.length; + for (let l = 0, n; l < k.length; l++) { + if ((n = k[l]) && n.length) { + if (e >= n.length) { + e -= n.length; continue; } - const n = b ? e + Math.min(m.length - e, b) : m.length; - for (let q = e; q < n; q++) { - k.push(m[q]); + const m = b ? e + Math.min(n.length - e, b) : n.length; + for (let q = e; q < m; q++) { + h.push(n[q]); } e = 0; - if (k.length === b) { + if (h.length === b) { break; } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; t.tag = function(a, c = 0, b = 0, e = !1) { - a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); + a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); const d = this; return Z(a).then(function(f) { if (!f || !f.length || b >= f.length) { @@ -2363,24 +2375,25 @@ t.search = null; t.info = function() { }; t.transaction = function(a, c, b) { - let e = this.h[a + ":" + c]; - if (e) { - return b.call(this, e); + const e = a + ("reg" !== a ? this.field ? ":" + this.field : "" : ""); + let d = this.h[e + ":" + c]; + if (d) { + return b.call(this, d); } - let d = this.db.transaction(a, c); - this.h[a + ":" + c] = e = d.objectStore(a); - return new Promise((f, g) => { - d.onerror = k => { - d.abort(); - d = e = null; - g(k); + let f = this.db.transaction(e, c); + this.h[e + ":" + c] = d = f.objectStore(e); + return new Promise((g, k) => { + f.onerror = l => { + f.abort(); + f = d = null; + k(l); }; - d.oncomplete = k => { - d = e = null; - f(k || !0); + f.oncomplete = l => { + f = d = null; + g(l || !0); }; - const h = b.call(this, e); - this.h[a + ":" + c] = null; + const h = b.call(this, d); + this.h[e + ":" + c] = null; return h; }); }; @@ -2405,54 +2418,54 @@ t.commit = async function(a, c, b) { for (const d of a.map) { const f = d[0], g = d[1]; g.length && (c ? e.put(g, f) : e.get(f).onsuccess = function() { - let h = this.result; - var k; - if (h && h.length) { - const l = Math.max(h.length, g.length); - for (let m = 0, n, q; m < l; m++) { - if ((q = g[m]) && q.length) { - if ((n = h[m]) && n.length) { - for (k = 0; k < q.length; k++) { - n.push(q[k]); + let k = this.result; + var h; + if (k && k.length) { + const l = Math.max(k.length, g.length); + for (let n = 0, m, q; n < l; n++) { + if ((q = g[n]) && q.length) { + if ((m = k[n]) && m.length) { + for (h = 0; h < q.length; h++) { + m.push(q[h]); } } else { - h[m] = q; + k[n] = q; } - k = 1; + h = 1; } } } else { - h = g, k = 1; + k = g, h = 1; } - k && e.put(h, f); + h && e.put(k, f); }); } }), await this.transaction("ctx", "readwrite", function(e) { for (const d of a.ctx) { const f = d[0], g = d[1]; - for (const h of g) { - const k = h[0], l = h[1]; - l.length && (c ? e.put(l, f + ":" + k) : e.get(f + ":" + k).onsuccess = function() { - let m = this.result; - var n; - if (m && m.length) { - const q = Math.max(m.length, l.length); - for (let r = 0, p, v; r < q; r++) { - if ((v = l[r]) && v.length) { - if ((p = m[r]) && p.length) { - for (n = 0; n < v.length; n++) { - p.push(v[n]); + for (const k of g) { + const h = k[0], l = k[1]; + l.length && (c ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { + let n = this.result; + var m; + if (n && n.length) { + const q = Math.max(n.length, l.length); + for (let p = 0, r, u; p < q; p++) { + if ((u = l[p]) && u.length) { + if ((r = n[p]) && r.length) { + for (m = 0; m < u.length; m++) { + r.push(u[m]); } } else { - m[r] = v; + n[p] = u; } - n = 1; + m = 1; } } } else { - m = l, n = 1; + n = l, m = 1; } - n && e.put(m, f + ":" + k); + m && e.put(n, f + ":" + h); }); } } @@ -2469,29 +2482,29 @@ t.commit = async function(a, c, b) { for (const d of a.tag) { const f = d[0], g = d[1]; g.length && (e.get(f).onsuccess = function() { - let h = this.result; - h = h && h.length ? h.concat(g) : g; - e.put(h, f); + let k = this.result; + k = k && k.length ? k.concat(g) : g; + e.put(k, f); }); } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function sb(a, c, b) { +function tb(a, c, b) { const e = a.value; let d, f, g = 0; - for (let h = 0, k; h < e.length; h++) { - if (k = b ? e : e[h]) { - for (let l = 0, m, n; l < c.length; l++) { - if (n = c[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 (d = 1, 1 < k.length) { - k.splice(m, 1); + for (let k = 0, h; k < e.length; k++) { + if (h = b ? e : e[k]) { + for (let l = 0, n, m; l < c.length; l++) { + if (m = c[l], n = h.indexOf(f ? parseInt(m, 10) : m), 0 > n && !f && "string" === typeof m && !isNaN(m) && (n = h.indexOf(parseInt(m, 10))) && (f = 1), 0 <= n) { + if (d = 1, 1 < h.length) { + h.splice(n, 1); } else { - e[h] = []; + e[k] = []; break; } } } - g += k.length; + g += h.length; } if (b) { break; @@ -2502,20 +2515,20 @@ function sb(a, c, b) { } t.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map", "readwrite", function(c) { + return Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && sb(b, a); + b && tb(b, a); }; - }), this.transaction("ctx", "readwrite", function(c) { + }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && sb(b, a); + b && tb(b, a); }; - }), this.transaction("tag", "readwrite", function(c) { + }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && sb(b, a, !0); + b && tb(b, a, !0); }; }), this.transaction("reg", "readwrite", function(c) { for (let b = 0; b < a.length; b++) { @@ -2529,15 +2542,15 @@ function Z(a) { c(this.result); }; a.oncomplete = function() { - c(this.result); + c(); }; a.onerror = b; a = null; }); } -;const tb = {Index:O, Charset:db, Encoder:J, Document:V, Worker:Q, Resolver:X, IndexedDB:qb, Language:{}}, ub = self; -let vb; -(vb = ub.define) && vb.amd ? vb([], function() { - return tb; -}) : "object" === typeof ub.exports ? ub.exports = tb : ub.FlexSearch = tb; +;const ub = {Index:N, Charset:eb, Encoder:ka, Document:U, Worker:P, Resolver:W, IndexedDB:rb, Language:{}}, vb = "undefined" !== typeof global ? global : self; +let wb; +(wb = vb.define) && wb.amd ? wb([], function() { + return ub; +}) : "object" === typeof vb.exports ? vb.exports = ub : vb.FlexSearch = ub; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index 353c525..02c9dbd 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,103 +1,104 @@ /**! - * FlexSearch.js v0.8.133 (Bundle) + * FlexSearch.js v0.8.135 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var t;function A(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function B(){return Object.create(null)}function E(a){return"string"===typeof a} -function I(a){return"object"===typeof a}function aa(a){const b=[];for(const c of a.keys())b.push(c);return b}function ba(a,b){if(E(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; -this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ea)}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);ja||(this.mapper=new Map(da));c=a.filter;this.filter="function"===typeof c?c:A(c&&new Set(c),null,this.filter);this.dedupe=A(a.dedupe,!1,this.dedupe);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);this.rtl=A(a.rtl,!1,this.rtl);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&&K(this);return this};t.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; -t.addMapper=function(a,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&&K(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&&K(this);return this}; -t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(K,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==g&&this.filter&& -g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&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 K(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} -function ma(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let P=0; -function Q(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&d.h[l];m&&(m(k.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++P]=function(){k(d);1E9=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const h=b.length;if(h&&(d=d.length?d.concat(b):b,c-=h,e&&(a.length-=h),!c))break;b=0}return d} -function S(a){if(!this||this.constructor!==S)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gc||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+e)}else{d=[];for(let 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}k=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.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?W.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.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}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,m,n)}return d?this.resolve(b,c,e):this}; -function La(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; -function Ma(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function Na(a,b,c,e,d){const f=[],g=B();let h=0;for(let k=0,l;kc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.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};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=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 Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const $a={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 ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cu;f--){g=q.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(b,q,r,g,v):fb(p,e,r,d,v); -gb(this,m,g,h,a,c)}break}case "reverse":if(1g?0:1),e,r,h-1,k-1),v=this.bidirectional&& -q>f;gb(this,l,v?f:q,u,a,c,v?q:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&hb(this));return this}; -function gb(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new S(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[e]=h=b}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function fb(a,b,c,e,d){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,e,d,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&hb(this));this.cache&&this.cache.remove(a);return this}; -function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; -function nb(a){let b=0;if(a.constructor===Array)for(let c=0,e;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&&this.db.close();this.db=null};t.destroy=function(){const a=ob.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(pb,"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=>{d.abort();d=e=null;g(k)};d.oncomplete=k=>{d=e=null;f(k||!0)};const h=c.call(this,e);this.h[a+":"+b]=null;return h})}; -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=k.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 tb={Index:O,Charset:db,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:rb,Language:{}},ub=self;let vb;(vb=ub.define)&&vb.amd?vb([],function(){return tb}):"object"===typeof ub.exports?ub.exports=tb:ub.FlexSearch=tb;}(this||self)); +t.assign=function(a){this.normalize=z(a.normalize,!0,this.normalize);let c=a.include,b=c||a.exclude||a.split,e;if(b||""===b){if("object"===typeof b&&b.constructor!==RegExp){let d="";e=!c;c||(d+="\\p{Z}");b.letter&&(d+="\\p{L}");b.number&&(d+="\\p{N}",e=!!c);b.symbol&&(d+="\\p{S}");b.punctuation&&(d+="\\p{P}");b.control&&(d+="\\p{C}");if(b=b.char)d+="object"===typeof b?b.join(""):b;try{this.split=new RegExp("["+(c?"^":"")+d+"]+","u")}catch(f){this.split=/\s+/}}else this.split=b,e=!1===b||2>"a1a".split(b).length; +this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ea)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);ja||(this.mapper=new Map(da));b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= +z((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=b=z(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof b?b:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&K(this);return this};t.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; +t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&K(this);return this}; +t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&K(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(K,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&dthis.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.B.set(a,b),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return b};function K(a){a.H=null;a.B.clear();a.G.clear()};let M,ka;async function la(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ka=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ka),delete self.FlexSearch):M=new N(ka);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ka.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ka.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ma(a){na.call(a,"add");na.call(a,"append");na.call(a,"search");na.call(a,"update");na.call(a,"remove")}let oa,pa,qa;function ra(){oa=qa=0} +function na(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);oa?qa||(qa=Date.now()-pa>=this.priority*this.priority*3):(oa=setTimeout(ra,0),pa=Date.now());if(qa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let O=0; +function P(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,n=l&&d.h[l];n&&(n(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[++O]=function(){h(d);1E9=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const k=c.length;if(k&&(d=d.length?d.concat(c):c,b-=k,e&&(a.length-=k),!b))break;c=0}return d} +function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;gb||e?h.slice(e,b+e):h;else{if(ab||e)h=h.slice(e,b+e)}else{d=[];for(let m= +0,q;me)e-=q.length;else{if(q.length>b||e)q=q.slice(e,b+e),b-=q.length,e&&(e-=q.length);d.push(q);if(!b)break}h=1c?c?a.slice(b,b+c):a.slice(b):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?V.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ha(a,b,e,!1,this.h),e=0));return f?this.resolve(b,e,d):this};W.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:n,suggest:m}=Ka(this,"and",arguments);return Ma.call(this,f,g,k,h,l,n,m)}return d?this.resolve(c,b,e):this}; +function Ma(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=ca(a))return this.result=Ga(a,c,b,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ka(this,"xor",arguments);return Na.call(this,a,c,b,e,d,f,g)}; +function Na(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Oa.call(this,a,b,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Oa(a,c,b,e,d){const f=[],g=B();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +X.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Xa={normalize:function(a){return a.toLowerCase()}};const Ya=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Za=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),$a=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ab={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;const db=/[\x00-\x7F]+/g;var eb={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Xa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ya},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var k=this.score?this.score(c,r,p,g,v):gb(q,e,p,d,v); +hb(this,n,g,k,a,b)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),v=this.bidirectional&& +r>f;hb(this,l,v?f:r,u,a,b,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.T&&ib(this));return this}; +function hb(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])if(g?(c=h||(c[b]=B()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){c=new R(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=c);h[e]=k=c}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} +function gb(a,c,b,e,d){return b&&1b)&&(h=b,b=c,c=h);if(a.db)return a.db.get(c,b,e,d,f,g,k);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};N.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else nb(this.map,a),this.depth&&nb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&ib(this));this.cache&&this.cache.remove(a);return this}; +function nb(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; +function ob(a){let c=0;if(a.constructor===Array)for(let b=0,e;b=n.length){e-=n.length;continue}const m=b?e+Math.min(n.length-e,b):n.length;for(let q=e;q=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; +t.enrich=function(a){"object"!==typeof a&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e{f.onerror=l=>{f.abort();f=d=null;k(l)};f.oncomplete=l=>{f=d=null;g(l||!0)};const h=b.call(this,d);this.h[e+":"+c]=null;return h})}; +t.commit=async function(a,c,b){if(c)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dn&&!f&&"string"===typeof m&&!isNaN(m)&&(n=h.indexOf(parseInt(m,10)))&&(f=1),0<=n)if(d=1,1{a.onsuccess=function(){c(this.result)};a.oncomplete=function(){c()};a.onerror=b;a=null})};const ub={Index:N,Charset:eb,Encoder:J,Document:U,Worker:P,Resolver:W,IndexedDB:sb,Language:{}},vb="undefined"!==typeof global?global:self;let wb;(wb=vb.define)&&wb.amd?wb([],function(){return ub}):"object"===typeof vb.exports?vb.exports=ub:vb.FlexSearch=ub;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index ba3b38c..1a68b88 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,19 +1,19 @@ /**! - * FlexSearch.js v0.8.133 (Bundle/Module/Debug) + * FlexSearch.js v0.8.135 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ var t; -function A(a, c, b) { +function z(a, c, b) { const e = typeof b, d = typeof a; if ("undefined" !== e) { if ("undefined" !== d) { if (b) { if ("function" === d && e === d) { - return function(h) { - return a(b(h)); + return function(k) { + return a(b(k)); }; } c = a.constructor; @@ -85,9 +85,9 @@ function ca(a) { "\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 J(a = {}) { - if (!this || this.constructor !== J) { - return new J(...arguments); +function ka(a = {}) { + if (!this || this.constructor !== ka) { + return new ka(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -97,9 +97,9 @@ function J(a = {}) { this.assign(a); } } -t = J.prototype; +t = ka.prototype; t.assign = function(a) { - this.normalize = A(a.normalize, !0, this.normalize); + this.normalize = z(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) { @@ -122,29 +122,29 @@ t.assign = function(a) { } else { this.split = b, e = !1 === b || 2 > "a1a".split(b).length; } - this.numeric = A(a.numeric, e); + this.numeric = z(a.numeric, e); } else { try { - this.split = A(this.split, ea); + this.split = z(this.split, ea); } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } - this.numeric = A(a.numeric, A(this.numeric, !0)); + this.numeric = z(a.numeric, z(this.numeric, !0)); } - this.prepare = A(a.prepare, null, this.prepare); - this.finalize = A(a.finalize, null, this.finalize); + this.prepare = z(a.prepare, null, this.prepare); + this.finalize = z(a.finalize, null, this.finalize); ja || (this.mapper = new Map(da)); b = a.filter; - this.filter = "function" === typeof b ? b : A(b && new Set(b), null, this.filter); - this.dedupe = A(a.dedupe, !1, this.dedupe); - 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); - this.rtl = A(a.rtl, !1, this.rtl); - if (this.cache = b = A(a.cache, !0, this.cache)) { + this.filter = "function" === typeof b ? b : z(b && new Set(b), null, this.filter); + this.dedupe = z(a.dedupe, !1, this.dedupe); + this.matcher = z((b = a.matcher) && new Map(b), null, this.matcher); + this.mapper = z((b = a.mapper) && new Map(b), null, this.mapper); + this.stemmer = z((b = a.stemmer) && new Map(b), null, this.stemmer); + this.replacer = z(a.replacer, null, this.replacer); + this.minlength = z(a.minlength, 1, this.minlength); + this.maxlength = z(a.maxlength, 0, this.maxlength); + this.rtl = z(a.rtl, !1, this.rtl); + if (this.cache = b = z(a.cache, !0, this.cache)) { this.H = null, this.S = "number" === typeof b ? b : 2e5, this.B = new Map(), this.G = new Map(), this.L = this.K = 128; } this.h = ""; @@ -168,12 +168,12 @@ t.addStemmer = function(a, c) { this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.N = null; - this.cache && K(this); + this.cache && J(this); return this; }; t.addFilter = function(a) { "function" === typeof a ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && K(this); + this.cache && J(this); return this; }; t.addMapper = function(a, c) { @@ -185,7 +185,7 @@ t.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && K(this); + this.cache && J(this); return this; }; t.addMatcher = function(a, c) { @@ -199,7 +199,7 @@ t.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.M = null; - this.cache && K(this); + this.cache && J(this); return this; }; t.addReplacer = function(a, c) { @@ -208,7 +208,7 @@ t.addReplacer = function(a, c) { } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && K(this); + this.cache && J(this); return this; }; t.encode = function(a) { @@ -218,7 +218,7 @@ t.encode = function(a) { return this.B.get(a); } } else { - this.H = setTimeout(K, 50, this); + this.H = setTimeout(J, 50, this); } } this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); @@ -226,8 +226,8 @@ t.encode = function(a) { this.numeric && 3 < a.length && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, h; f < e.length; f++) { - if ((g = h = e[f]) && !(g.length < this.minlength)) { + for (let f = 0, g, k; f < e.length; f++) { + if ((g = k = e[f]) && !(g.length < this.minlength)) { if (c) { b.push(g); } else { @@ -240,24 +240,24 @@ t.encode = function(a) { continue; } } else { - this.H = setTimeout(K, 50, this); + this.H = setTimeout(J, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), d = g, g = g.replace(this.N, k => this.stemmer.get(k)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), d = g, g = g.replace(this.N, h => this.stemmer.get(h)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let k = 0, l = "", m, n; k < g.length; k++) { - m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let h = 0, l = "", n, m; h < g.length; h++) { + n = g.charAt(h), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (d += m) : d += l = n); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.S && (this.G.clear(), this.L = this.L / 1.1 | 0)); g && b.push(g); } } @@ -267,61 +267,61 @@ t.encode = function(a) { this.cache && a.length <= this.K && (this.B.set(a, b), this.B.size > this.S && (this.B.clear(), this.K = this.K / 1.1 | 0)); return b; }; -function K(a) { +function J(a) { a.H = null; a.B.clear(); a.G.clear(); } -;let M, N; -async function ka(a) { +;let K, M; +async function la(a) { a = a.data; var c = a.task; const b = a.id; let e = a.args; switch(c) { case "init": - N = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + M = a.options || {}; + (c = a.factory) ? (Function("return " + c)()(self), K = new self.FlexSearch.Index(M), delete self.FlexSearch) : K = new N(M); postMessage({id:b}); break; default: let d; if ("export" === c) { - if (!N.export || "function" !== typeof N.export) { + if (!M.export || "function" !== typeof M.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - e[1] ? (e[0] = N.export, e[2] = 0, e[3] = 1) : e = null; + e[1] ? (e[0] = M.export, e[2] = 0, e[3] = 1) : e = null; } if ("import" === c) { - if (!N.import || "function" !== typeof N.import) { + if (!M.import || "function" !== typeof M.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - e[0] && (a = await N.import.call(M, e[0]), M.import(e[0], a)); + e[0] && (a = await M.import.call(K, e[0]), K.import(e[0], a)); } else { - (d = e && M[c].apply(M, e)) && d.then && (d = await d); + (d = e && K[c].apply(K, e)) && d.then && (d = await d); } postMessage("search" === c ? {id:b, msg:d} : {id:b}); } } -;function la(a) { - ma.call(a, "add"); - ma.call(a, "append"); - ma.call(a, "search"); - ma.call(a, "update"); - ma.call(a, "remove"); +;function ma(a) { + na.call(a, "add"); + na.call(a, "append"); + na.call(a, "search"); + na.call(a, "update"); + na.call(a, "remove"); } -let na, oa, pa; -function qa() { - na = pa = 0; +let oa, pa, qa; +function ra() { + oa = qa = 0; } -function ma(a) { +function na(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; let e; "function" === typeof b && (e = b, delete c[c.length - 1]); - na ? pa || (pa = Date.now() - oa >= this.priority * this.priority * 3) : (na = setTimeout(qa, 0), oa = Date.now()); - if (pa) { + oa ? qa || (qa = Date.now() - pa >= this.priority * this.priority * 3) : (oa = setTimeout(ra, 0), pa = Date.now()); + if (qa) { const f = this; return new Promise(g => { setTimeout(function() { @@ -335,25 +335,25 @@ function ma(a) { return b; }; } -;let P = 0; -function Q(a = {}) { +;let O = 0; +function P(a = {}) { function c(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && d.h[l]; - m && (m(k.msg), delete d.h[l]); + function k(h) { + h = h.data || h; + const l = h.id, n = l && d.h[l]; + n && (n(h.msg), delete d.h[l]); } this.worker = g; this.h = B(); if (this.worker) { - e ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { - d.h[++P] = function() { - k(d); - 1e9 < P && (P = 0); + return new Promise(function(h) { + d.h[++O] = function() { + h(d); + 1e9 < O && (O = 0); }; - d.worker.postMessage({id:P, task:"init", factory:b, options:a}); + d.worker.postMessage({id:O, task:"init", factory:b, options:a}); }); } this.worker.postMessage({task:"init", factory:b, options:a}); @@ -361,44 +361,44 @@ function Q(a = {}) { return this; } } - if (!this || this.constructor !== Q) { - return new Q(a); + if (!this || this.constructor !== P) { + return new P(a); } let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; b && (b = b.toString()); - const e = "undefined" === typeof window, d = this, f = ra(b, e, a.worker); + const e = "undefined" === typeof window, d = this, f = sa(b, e, a.worker); return f.then ? f.then(function(g) { return c.call(d, g); }) : c.call(this, f); } -R("add"); -R("append"); -R("search"); -R("update"); -R("remove"); -R("clear"); -R("export"); -R("import"); -la(Q.prototype); -function R(a) { - Q.prototype[a] = function() { +Q("add"); +Q("append"); +Q("search"); +Q("update"); +Q("remove"); +Q("clear"); +Q("export"); +Q("import"); +ma(P.prototype); +function Q(a) { + P.prototype[a] = function() { const c = this, b = [].slice.call(arguments); var e = b[b.length - 1]; let d; "function" === typeof e && (d = e, b.pop()); e = new Promise(function(f) { "export" === a && "function" === typeof b[0] && (b[0] = null); - c.h[++P] = f; - c.worker.postMessage({task:a, id:P, args:b}); + c.h[++O] = f; + c.worker.postMessage({task:a, id:O, args:b}); }); return d ? (e.then(d), this) : e; }; } -function ra(a, c, b) { - return c ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function sa(a, c, b) { + return c ? "undefined" !== typeof module ? new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + la.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;function sa(a, c = 0) { +;function ta(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -407,30 +407,30 @@ function ra(a, c, b) { e.length && b.push(e); return b; } -function ta(a, c) { +function ua(a, c) { c || (c = new Map()); for (let b = 0, e; b < a.length; b++) { e = a[b], c.set(e[0], e[1]); } return c; } -function ua(a, c = 0) { +function va(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], sa(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], ta(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function va(a, c) { +function wa(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], ta(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], ua(e[1], d)); } return c; } -function wa(a) { +function xa(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -438,56 +438,56 @@ function wa(a) { b.length && c.push(b); return c; } -function xa(a, c) { +function ya(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function ya(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { +function za(a, c, b, e, d, f, g = 0) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { return this.export(a, c, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return ya.call(l, a, c, b, h ? e : null, d, f, g + 1); + return h.then(function() { + return za.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return ya.call(this, a, c, b, h ? e : null, d, f, g + 1); + return za.call(this, a, c, b, k ? e : null, d, f, g + 1); } -function za(a, c) { +function Aa(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, h; g < d.length; g++) { - h = d[g] || [""]; - let k = ""; - for (let l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === c ? '"' + h[l] + '"' : h[l]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === c ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; b += (b ? "," : "") + f; } return b; } -;function Aa(a, c, b, e) { +;function Ba(a, c, b, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], c >= g.length) { c -= g.length; } else { c = g[e ? "splice" : "slice"](c, b); - const h = c.length; - if (h && (d = d.length ? d.concat(c) : c, b -= h, e && (a.length -= h), !b)) { + const k = c.length; + if (k && (d = d.length ? d.concat(c) : c, b -= k, e && (a.length -= k), !b)) { break; } c = 0; @@ -495,9 +495,9 @@ function za(a, c) { } return d; } -function S(a) { - if (!this || this.constructor !== S) { - return new S(a); +function R(a) { + if (!this || this.constructor !== R) { + return new R(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -522,13 +522,13 @@ function S(a) { if ("indexOf" === e) { return function(d) { let f = 0; - for (let g = 0, h, k; g < c.index.length; g++) { - h = c.index[g]; - k = h.indexOf(d); - if (0 <= k) { - return f + k; + for (let g = 0, k, h; g < c.index.length; g++) { + k = c.index[g]; + h = k.indexOf(d); + if (0 <= h) { + return f + h; } - f += h.length; + f += k.length; } return -1; }; @@ -545,12 +545,12 @@ function S(a) { } if ("slice" === e) { return function(d, f) { - return Aa(c, d || 0, f || c.length, !1); + return Ba(c, d || 0, f || c.length, !1); }; } if ("splice" === e) { return function(d, f) { - return Aa(c, d || 0, f || c.length, !0); + return Ba(c, d || 0, f || c.length, !0); }; } if ("constructor" === e) { @@ -566,13 +566,31 @@ function S(a) { return !0; }}); } -S.prototype.clear = function() { +R.prototype.clear = function() { this.index.length = 0; }; -S.prototype.destroy = function() { +R.prototype.destroy = function() { this.proxy = this.index = null; }; -S.prototype.push = function() { +R.prototype.push = function() { +}; +function S(a = 8) { + if (!this || this.constructor !== S) { + return new S(a); + } + this.index = B(); + this.h = []; + this.size = 0; + 32 < a ? (this.B = Ca, this.A = BigInt(a)) : (this.B = Da, this.A = a); +} +S.prototype.get = function(a) { + const c = this.index[this.B(a)]; + return c && c.get(a); +}; +S.prototype.set = function(a, c) { + var b = this.B(a); + let e = this.index[b]; + e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++); }; function T(a = 8) { if (!this || this.constructor !== T) { @@ -581,67 +599,49 @@ function T(a = 8) { this.index = B(); this.h = []; this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); + 32 < a ? (this.B = Ca, this.A = BigInt(a)) : (this.B = Da, this.A = a); } -T.prototype.get = function(a) { - const c = this.index[this.B(a)]; - return c && c.get(a); -}; -T.prototype.set = function(a, c) { - var b = this.B(a); - let e = this.index[b]; - e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++); -}; -function U(a = 8) { - if (!this || this.constructor !== U) { - return new U(a); - } - this.index = B(); - this.h = []; - this.size = 0; - 32 < a ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); -} -U.prototype.add = function(a) { +T.prototype.add = function(a) { var c = this.B(a); let b = this.index[c]; b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.h.push(b), this.size++); }; -t = T.prototype; -t.has = U.prototype.has = function(a) { +t = S.prototype; +t.has = T.prototype.has = function(a) { const c = this.index[this.B(a)]; return c && c.has(a); }; -t.delete = U.prototype.delete = function(a) { +t.delete = T.prototype.delete = function(a) { const c = this.index[this.B(a)]; c && c.delete(a) && this.size--; }; -t.clear = U.prototype.clear = function() { +t.clear = T.prototype.clear = function() { this.index = B(); this.h = []; this.size = 0; }; -t.values = U.prototype.values = function*() { +t.values = T.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].values()) { yield c; } } }; -t.keys = U.prototype.keys = function*() { +t.keys = T.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].keys()) { yield c; } } }; -t.entries = U.prototype.entries = function*() { +t.entries = T.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let c of this.h[a].entries()) { yield c; } } }; -function Ca(a) { +function Da(a) { let c = 2 ** this.A - 1; if ("number" == typeof a) { return a & c; @@ -652,7 +652,7 @@ function Ca(a) { } return 32 === this.A ? b + 2 ** 31 : b; } -function Ba(a) { +function Ca(a) { let c = BigInt(2) ** this.A - BigInt(1); var b = typeof a; if ("bigint" === b) { @@ -668,21 +668,21 @@ function Ba(a) { } return b; } -;V.prototype.add = function(a, c, b) { +;U.prototype.add = function(a, c, b) { I(a) && (c = a, a = ba(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.D[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); + for (let k = 0, h; k < this.field.length; k++) { + h = this.D[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(c); d && e.add(a, d, !1, !0); } else { - if (d = k.I, !d || d(c)) { - k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), Da(c, k, this.J, 0, e, a, k[0], b); + if (d = h.I, !d || d(c)) { + h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), Ea(c, h, this.J, 0, e, a, h[0], b); } } } @@ -690,14 +690,14 @@ function Ba(a) { for (e = 0; e < this.F.length; e++) { var f = this.F[e], g = this.R[e]; d = this.tag.get(g); - let h = B(); + let k = B(); if ("function" === typeof f) { if (f = f(c), !f) { continue; } } else { - const k = f.I; - if (k && !k(c)) { + const h = f.I; + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); @@ -705,19 +705,19 @@ function Ba(a) { } if (d && f) { E(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - if (l = f[k], !h[l] && (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !b || !m.includes(a))) { - if (m.length === 2 ** 31 - 1) { - g = new S(m); + for (let h = 0, l, n; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? n = g : d.set(l, n = []), !b || !n.includes(a))) { + if (n.length === 2 ** 31 - 1) { + g = new R(n); if (this.fastupdate) { - for (let n of this.reg.values()) { - n.includes(m) && (n[n.indexOf(m)] = g); + for (let m of this.reg.values()) { + m.includes(n) && (m[m.indexOf(n)] = g); } } - d.set(l, m = g); + d.set(l, n = g); } - m.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); + n.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])); } } } else { @@ -726,49 +726,49 @@ function Ba(a) { } } if (this.store && (!b || !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]; + k = B(); + for (let h = 0, l; h < this.C.length; h++) { + l = this.C[h]; if ((b = l.I) && !b(c)) { continue; } - let m; + let n; if ("function" === typeof l) { - m = l(c); - if (!m) { + n = l(c); + if (!n) { continue; } l = [l.V]; } else if (E(l) || l.constructor === String) { - h[l] = c[l]; + k[l] = c[l]; continue; } - Ea(c, h, l, 0, l[0], m); + Fa(c, k, l, 0, l[0], n); } } - this.store.set(a, h || c); + this.store.set(a, k || c); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Ea(a, c, b, e, d, f) { +function Fa(a, c, b, e, d, f) { a = a[d]; if (e === b.length - 1) { c[d] = f || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Ea(a, c, b, e, d); + Fa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = B()), d = b[++e], Ea(a, c, b, e, d); + c = c[d] || (c[d] = B()), d = b[++e], Fa(a, c, b, e, d); } } } -function Da(a, c, b, e, d, f, g, h) { +function Ea(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -780,60 +780,60 @@ function Da(a, c, b, e, d, f, g, h) { } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Da(a, c, b, e, d, f, g, h); + Ea(a, c, b, e, d, f, g, k); } } else { - g = c[++e], Da(a, c, b, e, d, f, g, h); + g = c[++e], Ea(a, c, b, e, d, f, g, k); } } } else { d.db && d.remove(f); } } -;function Fa(a, c, b, e, d, f, g) { - const h = a.length; - let k = [], l, m; +;function Ga(a, c, b, e, d, f, g) { + const k = a.length; + let h = [], l, n; l = B(); - for (let n = 0, q, r, p, v; n < c; n++) { - for (let u = 0; u < h; u++) { - if (p = a[u], n < p.length && (q = p[n])) { - for (let x = 0; x < q.length; x++) { - r = q[x]; - (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1); - v = k[m] || (k[m] = []); + for (let m = 0, q, p, r, u; m < c; m++) { + for (let v = 0; v < k; v++) { + if (r = a[v], m < r.length && (q = r[m])) { + for (let w = 0; w < q.length; w++) { + p = q[w]; + (n = l[p]) ? l[p]++ : (n = 0, l[p] = 1); + u = h[n] || (h[n] = []); if (!g) { - let y = n + (u || !d ? 0 : f || 0); - v = v[y] || (v[y] = []); + let y = m + (v || !d ? 0 : f || 0); + u = u[y] || (u[y] = []); } - v.push(r); - if (g && b && m === h - 1 && v.length - e === b) { - return v; + u.push(p); + if (g && b && n === k - 1 && u.length - e === b) { + return u; } } } } } - if (a = k.length) { + if (a = h.length) { if (d) { - k = 1 < k.length ? Ga(k, b, e, g, f) : (k = k[0]).length > b || e ? k.slice(e, b + e) : k; + h = 1 < h.length ? Ha(h, b, e, g, f) : (h = h[0]).length > b || e ? h.slice(e, b + e) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; + h = h[a - 1]; if (b || e) { if (g) { - if (k.length > b || e) { - k = k.slice(e, b + e); + if (h.length > b || e) { + h = h.slice(e, b + e); } } else { d = []; - for (let n = 0, q; n < k.length; n++) { - if (q = k[n], q.length > e) { + for (let m = 0, q; m < h.length; m++) { + if (q = h[m], q.length > e) { e -= q.length; } else { if (q.length > b || e) { @@ -845,27 +845,27 @@ function Da(a, c, b, e, d, f, g, h) { } } } - k = 1 < d.length ? [].concat.apply([], d) : d[0]; + h = 1 < d.length ? [].concat.apply([], d) : d[0]; } } } } - return k; + return h; } -function Ga(a, c, b, e, d) { +function Ha(a, c, b, e, d) { const f = [], g = B(); - let h; - var k = a.length; + let k; + var h = a.length; let l; if (e) { - for (d = k - 1; 0 <= d; d--) { + for (d = h - 1; 0 <= d; d--) { if (l = (e = a[d]) && e.length) { - for (k = 0; k < l; k++) { - if (h = e[k], !g[h]) { - if (g[h] = 1, b) { + for (h = 0; h < l; h++) { + if (k = e[h], !g[k]) { + if (g[k] = 1, b) { b--; } else { - if (f.push(h), f.length === c) { + if (f.push(k), f.length === c) { return f; } } @@ -874,17 +874,17 @@ function Ga(a, c, b, e, d) { } } } else { - for (let m = k - 1, n, q = 0; 0 <= m; m--) { - n = a[m]; - for (let r = 0; r < n.length; r++) { - if (l = (e = n[r]) && e.length) { - for (let p = 0; p < l; p++) { - if (h = e[p], !g[h]) { - if (g[h] = 1, b) { + for (let n = h - 1, m, q = 0; 0 <= n; n--) { + m = a[n]; + for (let p = 0; p < m.length; p++) { + if (l = (e = m[p]) && e.length) { + for (let r = 0; r < l; r++) { + if (k = e[r], !g[k]) { + if (g[k] = 1, b) { b--; } else { - let v = (r + (m < k - 1 ? d || 0 : 0)) / (m + 1) | 0; - (f[v] || (f[v] = [])).push(h); + let u = (p + (n < h - 1 ? d || 0 : 0)) / (n + 1) | 0; + (f[u] || (f[u] = [])).push(k); if (++q === c) { return f; } @@ -897,12 +897,12 @@ function Ga(a, c, b, e, d) { } return f; } -function Ha(a, c, b) { +function Ia(a, c, b) { const e = B(), d = []; for (let f = 0, g; f < c.length; f++) { g = c[f]; - for (let h = 0; h < g.length; h++) { - e[g[h]] = 1; + for (let k = 0; k < g.length; k++) { + e[g[k]] = 1; } } if (b) { @@ -910,75 +910,75 @@ function Ha(a, c, b) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, h; f < a.result.length; f++) { + for (let f = 0, g, k; 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); + k = g[c], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); } } } return d; } -;function Ia(a, c, b, e) { +;function Ja(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? V.call(this, a) : a; } let d = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + for (let f = 0, g, k; f < a.length; f++) { + if ((g = a[f]) && (k = g.length)) { if (b) { - if (b >= h) { - b -= h; + if (b >= k) { + b -= k; continue; } - b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); + b < k && (g = c ? g.slice(b, b + c) : g.slice(b), k = g.length, b = 0); } - h > c && (g = g.slice(0, c), h = c); - if (!d.length && h >= c) { - return e ? W.call(this, g) : g; + k > c && (g = g.slice(0, c), k = c); + if (!d.length && k >= c) { + return e ? V.call(this, g) : g; } d.push(g); - c -= h; + c -= k; if (!c) { break; } } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? W.call(this, d) : d; + return e ? V.call(this, d) : d; } -;function Ja(a, c, b) { +;function Ka(a, c, b) { var e = b[0]; if (e.then) { - return Promise.all(b).then(function(m) { - return a[c].apply(a, m); + 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 = [], f = 0, g = 0, h, k, l; - for (let m = 0, n; m < b.length; m++) { - if (n = b[m]) { + let d = [], f = 0, g = 0, k, h, l; + for (let n = 0, m; n < b.length; n++) { + if (m = b[n]) { let q; - if (n.constructor === X) { - q = n.result; - } else if (n.constructor === Array) { - q = n; + if (m.constructor === W) { + q = m.result; + } else if (m.constructor === Array) { + q = m; } 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, q = n.index.search(n).result, n.resolve = k, n.enrich = h; - } else if (n.and) { - q = a.and(n.and); - } else if (n.or) { - q = a.or(n.or); - } else if (n.xor) { - q = a.xor(n.xor); - } else if (n.not) { - q = a.not(n.not); + if (f = m.limit || 0, g = m.offset || 0, l = m.suggest, h = m.resolve, k = m.enrich && h, m.index) { + m.resolve = !1, m.enrich = !1, q = m.index.search(m).result, m.resolve = h, m.enrich = k; + } else if (m.and) { + q = a.and(m.and); + } else if (m.or) { + q = a.or(m.or); + } else if (m.xor) { + q = a.xor(m.xor); + } else if (m.not) { + q = a.not(m.not); } else { continue; } @@ -986,54 +986,54 @@ function Ha(a, c, b) { if (q.then) { d.push(q); } else if (q.length) { - e[m] = q; + e[n] = q; } else if (!l && ("and" === c || "xor" === c)) { e = []; break; } } } - return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } -;X.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ja(this, "or", arguments); - return Ka.call(this, a, c, b, e, d, f); +;W.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ka(this, "or", arguments); + return La.call(this, a, c, b, e, d, f); }; -function Ka(a, c, b, e, d, f) { +function La(a, c, b, e, d, f) { if (c.length) { const g = this; - return Promise.all(c).then(function(h) { + return Promise.all(c).then(function(k) { a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } - return Ka.call(g, a, [], b, e, d, f); + return La.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 = Ga(a, b, e, !1, this.h), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = Ha(a, b, e, !1, this.h), e = 0)); return f ? this.resolve(b, e, d) : this; } -;X.prototype.and = function() { +;W.prototype.and = function() { let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); - return La.call(this, f, g, h, k, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:n, suggest:m} = Ka(this, "and", arguments); + return Ma.call(this, f, g, k, h, l, n, m); } return d ? this.resolve(c, b, e) : this; }; -function La(a, c, b, e, d, f, g) { +function Ma(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } - return La.call(h, a, [], b, e, d, f, g); + return Ma.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -1041,7 +1041,7 @@ function La(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = ca(a)) { - return this.result = Fa(a, c, b, e, g, this.h, f), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Ga(a, c, b, e, g, this.h, f), f ? d ? V.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -1050,65 +1050,65 @@ function La(a, c, b, e, d, f, g) { } return f ? this.resolve(b, e, d) : this; } -;X.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "xor", arguments); - return Ma.call(this, a, c, b, e, d, f, g); +;W.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ka(this, "xor", arguments); + return Na.call(this, a, c, b, e, d, f, g); }; -function Ma(a, c, b, e, d, f, g) { +function Na(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } - return Ma.call(h, a, [], b, e, d, f, g); + return Na.call(k, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = Na.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + return this.result = Oa.call(this, a, b, e, f, this.h), f ? d ? V.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Na(a, c, b, e, d) { +function Oa(a, c, b, e, d) { const f = [], g = B(); - 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 q = 0, r; q < n.length; q++) { - r = n[q], g[r] = g[r] ? 2 : 1; + let k = 0; + for (let h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); + for (let n = 0, m; n < l.length; n++) { + if (m = l[n]) { + for (let q = 0, p; q < m.length; q++) { + p = m[q], g[p] = g[p] ? 2 : 1; } } } } } - for (let k = 0, l, m = 0; k < h; k++) { - for (let n = 0, q; n < a.length; n++) { - if (q = a[n]) { - if (l = q[k]) { - for (let r = 0, p; r < l.length; r++) { - if (p = l[r], 1 === g[p]) { + for (let h = 0, l, n = 0; h < k; h++) { + for (let m = 0, q; m < a.length; m++) { + if (q = a[m]) { + if (l = q[h]) { + for (let p = 0, r; p < l.length; p++) { + if (r = l[p], 1 === g[r]) { if (b) { b--; } else { if (e) { - if (f.push(p), f.length === c) { + if (f.push(r), f.length === c) { return f; } } else { - const v = k + (n ? d : 0); - f[v] || (f[v] = []); - f[v].push(p); - if (++m === c) { + const u = h + (m ? d : 0); + f[u] || (f[u] = []); + f[u].push(r); + if (++n === c) { return f; } } @@ -1121,35 +1121,35 @@ function Na(a, c, b, e, d) { } return f; } -;X.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ja(this, "not", arguments); - return Oa.call(this, a, c, b, e, d, f, g); +;W.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ka(this, "not", arguments); + return Pa.call(this, a, c, b, e, d, f, g); }; -function Oa(a, c, b, e, d, f, g) { +function Pa(a, c, b, e, d, f, g) { if (c.length) { - const h = this; - return Promise.all(c).then(function(k) { + const k = this; + return Promise.all(c).then(function(h) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } - return Oa.call(h, a, [], b, e, d, f, g); + return Pa.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Pa.call(this, a, b, e, f); + this.result = Qa.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? W.call(this.index, this.result) : this.result : this; + return f ? d ? V.call(this.index, this.result) : this.result : this; } -function Pa(a, c, b, e) { +function Qa(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { + for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (b) { b--; } else { @@ -1158,7 +1158,7 @@ function Pa(a, c, b, e) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { + if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { return d; } } @@ -1169,9 +1169,9 @@ function Pa(a, c, b, e) { } return d; } -;function X(a) { - if (!this || this.constructor !== X) { - return new X(a); +;function W(a) { + if (!this || this.constructor !== W) { + return new W(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -1180,7 +1180,7 @@ function Pa(a, c, b, e) { this.result = a || []; this.h = 0; } -X.prototype.limit = function(a) { +W.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -1199,7 +1199,7 @@ X.prototype.limit = function(a) { } return this; }; -X.prototype.offset = function(a) { +W.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -1211,283 +1211,283 @@ X.prototype.offset = function(a) { } return this; }; -X.prototype.boost = function(a) { +W.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, c, b) { +W.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Ia.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Ja.call(d, e, a || 100, c, b)) : e; }; B(); -V.prototype.search = function(a, c, b, e) { +U.prototype.search = function(a, c, b, e) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); - let d = [], f = [], g; - var h; + let d = []; + var f = [], g; let k; - let l; - let m, n = 0; - var q = !0; - let r; + let h, l; + let n = 0; + var m = !0; + let q; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; - g = b.pluck; + var p = b.pluck; k = b.merge; - l = g || b.field || (l = b.index) && (l.index ? null : l); - var p = this.tag && b.tag; - var v = b.suggest; - q = !1 !== b.resolve; - if (!q && !g) { - if (l = l || this.field) { - E(l) ? g = l : (l.constructor === Array && 1 === l.length && (l = l[0]), g = l.field || l.index); + h = p || b.field || (h = b.index) && (h.index ? null : h); + l = this.tag && b.tag; + var r = b.suggest; + m = !1 !== b.resolve; + if (!m && !p) { + if (h = h || this.field) { + E(h) ? p = h : (h.constructor === Array && 1 === h.length && (h = h[0]), p = h.field || h.index); } - if (!g) { + if (!p) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - this.store && b.enrich && !q && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - r = (h = this.store && b.enrich && q) && b.highlight; + this.store && b.enrich && !m && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + q = (g = this.store && b.enrich && m) && b.highlight; c = b.limit || c; - m = b.offset || 0; + var u = b.offset || 0; c || (c = 100); - if (p && (!this.db || !e)) { - p.constructor !== Array && (p = [p]); - var u = []; - for (let z = 0, w; z < p.length; z++) { - w = p[z]; - if (E(w)) { + if (l && (!this.db || !e)) { + l.constructor !== Array && (l = [l]); + var v = []; + for (let A = 0, x; A < l.length; A++) { + x = l[A]; + if (E(x)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (w.field && w.tag) { - var x = w.tag; - if (x.constructor === Array) { - for (var y = 0; y < x.length; y++) { - u.push(w.field, x[y]); + if (x.field && x.tag) { + var w = x.tag; + if (w.constructor === Array) { + for (var y = 0; y < w.length; y++) { + v.push(x.field, w[y]); } } else { - u.push(w.field, x); + v.push(x.field, w); } } else { - x = Object.keys(w); - for (let D = 0, H, C; D < x.length; D++) { - if (H = x[D], C = w[H], C.constructor === Array) { + w = Object.keys(x); + for (let D = 0, H, C; D < w.length; D++) { + if (H = w[D], C = x[H], C.constructor === Array) { for (y = 0; y < C.length; y++) { - u.push(H, C[y]); + v.push(H, C[y]); } } else { - u.push(H, C); + v.push(H, C); } } } } - if (!u.length) { + if (!v.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - p = u; + l = v; if (!a) { - v = []; - if (u.length) { - for (p = 0; p < u.length; p += 2) { + m = []; + if (v.length) { + for (f = 0; f < v.length; f += 2) { if (this.db) { - q = this.index.get(u[p]); - if (!q) { - console.warn("Tag '" + u[p] + ":" + u[p + 1] + "' will be skipped because there is no field '" + u[p] + "'."); + p = this.index.get(v[f]); + if (!p) { + console.warn("Tag '" + v[f] + ":" + v[f + 1] + "' will be skipped because there is no field '" + v[f] + "'."); continue; } - v.push(q = q.db.tag(u[p + 1], c, m, h)); + m.push(p = p.db.tag(v[f + 1], c, u, g)); } else { - q = Qa.call(this, u[p], u[p + 1], c, m, h); + p = Ra.call(this, v[f], v[f + 1], c, u, g); } - d.push({field:u[p], tag:u[p + 1], result:q}); + d.push({field:v[f], tag:v[f + 1], result:p}); } } - return v.length ? Promise.all(v).then(function(z) { - for (let w = 0; w < z.length; w++) { - d[w].result = z[w]; + return m.length ? Promise.all(m).then(function(A) { + for (let x = 0; x < A.length; x++) { + d[x].result = A[x]; } return d; }) : d; } } - l && l.constructor !== Array && (l = [l]); + h && h.constructor !== Array && (h = [h]); } - l || (l = this.field); - u = !e && (this.worker || this.db) && []; + h || (h = this.field); + v = !e && (this.worker || this.db) && []; let F; - for (let z = 0, w, D, H; z < l.length; z++) { - D = l[z]; - if (this.db && this.tag && !this.D[z]) { + for (let A = 0, x, D, H; A < h.length; A++) { + D = h[A]; + if (this.db && this.tag && !this.D[A]) { continue; } let C; - E(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, m = C.offset || m, v = C.suggest || v, h = this.store && (C.enrich || h)); + E(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, u = C.offset || u, r = C.suggest || r, g = this.store && (C.enrich || g)); if (e) { - w = e[z]; + x = e[A]; } else { - if (x = C || b, y = this.index.get(D), p && (this.db && (x.tag = p, F = y.db.support_tag_search, x.field = l), F || (x.enrich = !1)), u) { - u[z] = y.search(a, c, x); - x && h && (x.enrich = h); + if (w = C || b, y = this.index.get(D), l && (this.db && (w.tag = l, F = y.db.support_tag_search, w.field = h), F || (w.enrich = !1)), v) { + v[A] = y.search(a, c, w); + w && g && (w.enrich = g); continue; } else { - w = y.search(a, c, x), x && h && (x.enrich = h); + x = y.search(a, c, w), w && g && (w.enrich = g); } } - H = w && (q ? w.length : w.result.length); - if (p && H) { - x = []; + H = x && (m ? x.length : x.result.length); + if (l && H) { + w = []; y = 0; if (this.db && e) { if (!F) { - for (let G = l.length; G < e.length; G++) { + for (let G = h.length; G < e.length; G++) { let L = e[G]; if (L && L.length) { - y++, x.push(L); - } else if (!v) { - return q ? d : new X(d); + y++, w.push(L); + } else if (!r) { + return m ? d : new W(d); } } } } else { - for (let G = 0, L, ob; G < p.length; G += 2) { - L = this.tag.get(p[G]); + for (let G = 0, L, pb; G < l.length; G += 2) { + L = this.tag.get(l[G]); if (!L) { - if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), v) { + if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), r) { continue; } else { - return q ? d : new X(d); + return m ? d : new W(d); } } - if (ob = (L = L && L.get(p[G + 1])) && L.length) { - y++, x.push(L); - } else if (!v) { - return q ? d : new X(d); + if (pb = (L = L && L.get(l[G + 1])) && L.length) { + y++, w.push(L); + } else if (!r) { + return m ? d : new W(d); } } } if (y) { - w = Ha(w, x, q); - H = w.length; - if (!H && !v) { - return q ? w : new X(w); + x = Ia(x, w, m); + H = x.length; + if (!H && !r) { + return m ? x : new W(x); } y--; } } if (H) { - f[n] = D, d.push(w), n++; - } else if (1 === l.length) { - return q ? d : new X(d); + f[n] = D, d.push(x), n++; + } else if (1 === h.length) { + return m ? d : new W(d); } } - if (u) { - if (this.db && p && p.length && !F) { - for (h = 0; h < p.length; h += 2) { - e = this.index.get(p[h]); - if (!e) { - if (console.warn("Tag '" + p[h] + ":" + p[h + 1] + "' was not found because there is no field '" + p[h] + "'."), v) { + if (v) { + if (this.db && l && l.length && !F) { + for (g = 0; g < l.length; g += 2) { + f = this.index.get(l[g]); + if (!f) { + if (console.warn("Tag '" + l[g] + ":" + l[g + 1] + "' was not found because there is no field '" + l[g] + "'."), r) { continue; } else { - return q ? d : new X(d); + return m ? d : new W(d); } } - u.push(e.db.tag(p[h + 1], c, m, !1)); + v.push(f.db.tag(l[g + 1], c, u, !1)); } } - const z = this; - return Promise.all(u).then(function(w) { - return w.length ? z.search(a, c, b, w) : w; + const A = this; + return Promise.all(v).then(function(x) { + return x.length ? A.search(a, c, b, x) : x; }); } if (!n) { - return q ? d : new X(d); + return m ? d : new W(d); } - if (g && (!h || !this.store)) { + if (p && (!g || !this.store)) { return d[0]; } - u = []; - for (let z = 0, w; z < f.length; z++) { - w = d[z]; - h && w.length && !w[0].doc && (this.db ? u.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = W.call(this, w)); - if (g) { - return q ? w : new X(w); + v = []; + for (u = 0; u < f.length; u++) { + r = d[u]; + g && r.length && "undefined" === typeof r[0].doc && (this.db ? v.push(r = this.index.get(this.field[0]).db.enrich(r)) : r = V.call(this, r)); + if (p) { + return m ? r : new W(r); } - d[z] = {field:f[z], result:w}; + d[u] = {field:f[u], result:r}; } - if (h && this.db && u.length) { - const z = this; - return Promise.all(u).then(function(w) { - for (let D = 0; D < w.length; D++) { - d[D].result = w[D]; + if (g && this.db && v.length) { + const A = this; + return Promise.all(v).then(function(x) { + for (let D = 0; D < x.length; D++) { + d[D].result = x[D]; } - return k ? Ra(d, c) : r ? Sa(d, a, z.index, z.field, z.D, r) : d; + return k ? Sa(d, c) : q ? Ta(d, a, A.index, A.field, A.D, q) : d; }); } - return k ? Ra(d, c) : r ? Sa(d, a, this.index, this.field, this.D, r) : d; + return k ? Sa(d, c) : q ? Ta(d, a, this.index, this.field, this.D, q) : d; }; -function Sa(a, c, b, e, d, f) { - let g, h, k; - for (let m = 0, n, q, r, p, v; m < a.length; m++) { - n = a[m].result; - q = a[m].field; - p = b.get(q); - r = p.encoder; - k = p.tokenize; - v = d[e.indexOf(q)]; - r !== g && (g = r, h = g.encode(c)); - for (let u = 0; u < n.length; u++) { - let x = ""; - var l = ba(n[u].doc, v); +function Ta(a, c, b, e, d, f) { + let g, k, h; + for (let n = 0, m, q, p, r; n < a.length; n++) { + let u = a[n].result; + m = a[n].field; + p = b.get(m); + q = p.encoder; + h = p.tokenize; + r = d[e.indexOf(m)]; + q !== g && (g = q, k = g.encode(c)); + for (let v = 0; v < u.length; v++) { + let w = ""; + var l = ba(u[v].doc, r); let y = g.encode(l); l = l.split(g.split); - for (let F = 0, z, w; F < y.length; F++) { - z = y[F]; - w = l[F]; + for (let F = 0, A, x; F < y.length; F++) { + A = y[F]; + x = l[F]; let D; - for (let H = 0, C; H < h.length; H++) { - if (C = h[H], "strict" === k) { - if (z === C) { - x += (x ? " " : "") + f.replace("$1", w); + for (let H = 0, C; H < k.length; H++) { + if (C = k[H], "strict" === h) { + if (A === C) { + w += (w ? " " : "") + f.replace("$1", x); D = !0; break; } } else { - const G = z.indexOf(C); + const G = A.indexOf(C); if (-1 < G) { - x += (x ? " " : "") + w.substring(0, G) + f.replace("$1", w.substring(G, C.length)) + w.substring(G + C.length); + w += (w ? " " : "") + x.substring(0, G) + f.replace("$1", x.substring(G, C.length)) + x.substring(G + C.length); D = !0; break; } } } - D || (x += (x ? " " : "") + l[F]); + D || (w += (w ? " " : "") + l[F]); } - n[u].highlight = x; + u[v].highlight = w; } } return a; } -function Ra(a, c) { +function Sa(a, c) { const b = [], 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], "object" !== typeof l && (l = {id:l}), k = l.id, m = e[k]) { - m.push(f.field); + for (let k = 0, h, l, n; k < g.length; k++) { + if (l = g[k], "object" !== typeof l && (l = {id:l}), h = l.id, n = e[h]) { + n.push(f.field); } else { if (b.length === c) { return b; } - l.field = e[k] = [f.field]; + l.field = e[h] = [f.field]; b.push(l); } } } return b; } -function Qa(a, c, b, e, d) { +function Ra(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1496,11 +1496,11 @@ function Qa(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = W.call(this, f)); + d && (f = V.call(this, f)); return f; } } -function W(a) { +function V(a) { if (!this || !this.store) { return a; } @@ -1510,26 +1510,26 @@ function W(a) { } return c; } -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); +;function U(a) { + if (!this || this.constructor !== U) { + return new U(a); } const c = a.document || a.doc || a; let b, e; this.D = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && Ta(b, this.J) || "id"; + this.key = (b = c.key || c.id) && Ua(b, this.J) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; - this.reg = !this.fastupdate || a.worker || a.db ? e ? new U(e) : new Set() : e ? new T(e) : new Map(); + this.reg = !this.fastupdate || a.worker || a.db ? e ? new T(e) : new Set() : e ? new S(e) : new Map(); this.C = (b = c.store || null) && b && !0 !== b && []; - this.store = b && (e ? new T(e) : new Map()); - this.cache = (b = a.cache || null) && new Y(b); + this.store = b && (e ? new S(e) : new Map()); + this.cache = (b = a.cache || null) && new X(b); a.cache = !1; this.worker = a.worker; this.priority = a.priority || 4; - this.index = Ua.call(this, a, c); + this.index = Va.call(this, a, c); this.tag = null; if (b = c.tag) { if ("string" === typeof b && (b = [b]), b.length) { @@ -1542,7 +1542,7 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.F[d] = f.custom : (this.F[d] = Ta(g, this.J), f.filter && ("string" === typeof this.F[d] && (this.F[d] = new String(this.F[d])), this.F[d].I = f.filter)); + f.custom ? this.F[d] = f.custom : (this.F[d] = Ua(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()); } @@ -1558,9 +1558,9 @@ function W(a) { const d = this; return Promise.all(a).then(function(f) { let g = 0; - for (const h of d.index.entries()) { - const k = h[0]; - h[1].then && d.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 d; }); @@ -1569,7 +1569,7 @@ function W(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -t = V.prototype; +t = U.prototype; t.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); @@ -1579,7 +1579,7 @@ t.mount = function(a) { for (let d = 0, f; d < this.R.length; d++) { f = this.R[d]; var b = void 0; - this.index.set(f, b = new O({}, this.reg)); + this.index.set(f, b = new N({}, this.reg)); c === this.field && (c = c.slice(0)); c.push(f); b.tag = this.tag.get(f); @@ -1590,9 +1590,9 @@ t.mount = function(a) { for (let d = 0, f, g; d < c.length; d++) { e.field = g = c[d]; f = this.index.get(g); - const h = new a.constructor(a.id, e); - h.id = a.id; - b[d] = h.mount(f); + const k = new a.constructor(a.id, e); + k.id = a.id; + b[d] = k.mount(f); f.document = !0; d ? f.bypass = !0 : f.store = this.store; } @@ -1614,7 +1614,7 @@ t.destroy = function() { } return Promise.all(a); }; -function Ua(a, c) { +function Va(a, c) { const b = new Map(); let e = c.index || c.field || c; E(e) && (e = [e]); @@ -1623,23 +1623,23 @@ function Ua(a, c) { E(f) || (g = f, f = f.field); g = I(g) ? Object.assign({}, a, g) : a; if (this.worker) { - const h = new Q(g); - b.set(f, h); + const k = new P(g); + b.set(f, k); } - this.worker || b.set(f, new O(g, this.reg)); - g.custom ? this.D[d] = g.custom : (this.D[d] = Ta(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.worker || b.set(f, new N(g, this.reg)); + g.custom ? this.D[d] = g.custom : (this.D[d] = Ua(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 = 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.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ta(g, this.J), f.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.C[d] = f.custom, f.custom.V = g) : (this.C[d] = Ua(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 b; } -function Ta(a, c) { +function Ua(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1708,14 +1708,14 @@ t.set = function(a, c) { this.store.set(a, c); return this; }; -t.searchCache = Va; +t.searchCache = Wa; t.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const h = this; + const k = this; return c.then(function() { - return h.export(a, g, b + 1); + return k.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -1724,23 +1724,23 @@ t.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = wa(this.reg); + f = xa(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && ua(this.tag, this.reg.size); + f = this.tag && va(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && sa(this.store); + f = this.store && ta(this.store); c = null; break; default: return; } - return ya.call(this, a, c, d, f, b, e); + return za.call(this, a, c, d, f, b, e); }; t.import = function(a, c) { var b = a.split("."); @@ -1758,7 +1758,7 @@ t.import = function(a, c) { switch(b) { case "reg": this.fastupdate = !1; - this.reg = xa(c, this.reg); + this.reg = ya(c, this.reg); for (let d = 0, f; d < this.field.length; d++) { f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } @@ -1771,17 +1771,17 @@ t.import = function(a, c) { } break; case "tag": - this.tag = va(c, this.tag); + this.tag = wa(c, this.tag); break; case "doc": - this.store = ta(c, this.store); + this.store = ua(c, this.store); } } }; -la(V.prototype); -function Va(a, c, b) { +ma(U.prototype); +function Wa(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new Y()); + this.cache || (this.cache = new X()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -1796,104 +1796,104 @@ function Va(a, c, b) { } return e; } -function Y(a) { +function X(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -Y.prototype.set = function(a, c) { +X.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -Y.prototype.get = function(a) { +X.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -Y.prototype.remove = function(a) { +X.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -Y.prototype.clear = function() { +X.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Wa = {normalize:function(a) { +const Xa = {normalize:function(a) { return a.toLowerCase(); }}; -const Xa = 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 Ya = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Za = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const $a = {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 ab = /[\x00-\x7F]+/g; +const Ya = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Za = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), $a = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const ab = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; const bb = /[\x00-\x7F]+/g; const cb = /[\x00-\x7F]+/g; -var db = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Wa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Xa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Xa, matcher:Ya, replacer:Za}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Xa, replacer:Za.concat([/(?!^)[aeo]/g, ""]), matcher:Ya}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const db = /[\x00-\x7F]+/g; +var eb = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Xa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ya}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ya, matcher:Za, replacer:$a}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ya, replacer:$a.concat([/(?!^)[aeo]/g, ""]), matcher:Za}, 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 = $a[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = $a[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = ab[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = ab[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ab, " "); + return ("" + a).replace(bb, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(bb, ""); + return ("" + a).replace(cb, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(cb, " "); + return ("" + a).replace(db, " "); }}}; -const eb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -O.prototype.add = function(a, c, b, e) { +const fb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +N.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); if (e = c.length) { - const l = B(), m = B(), n = this.depth, q = this.resolution; - for (let r = 0; r < e; r++) { - let p = c[this.rtl ? e - 1 - r : r]; - var d = p.length; - if (d && (n || !m[p])) { - var f = this.score ? this.score(c, p, r, null, 0) : fb(q, e, r), g = ""; + const l = B(), n = B(), m = this.depth, q = this.resolution; + for (let p = 0; p < e; p++) { + let r = c[this.rtl ? e - 1 - p : p]; + var d = r.length; + if (d && (m || !n[r])) { + var f = this.score ? this.score(c, r, p, null, 0) : gb(q, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let v = 0, u; v < d; v++) { - for (f = d; f > v; f--) { - g = p.substring(v, f); - u = this.rtl ? d - 1 - v : v; - var h = this.score ? this.score(c, p, r, g, u) : fb(q, e, r, d, u); - gb(this, m, g, h, a, b); + for (let u = 0, v; u < d; u++) { + for (f = d; f > u; f--) { + g = r.substring(u, f); + v = this.rtl ? d - 1 - u : u; + var k = this.score ? this.score(c, r, p, g, v) : gb(q, e, p, d, v); + hb(this, n, g, k, a, b); } } break; } case "reverse": if (1 < d) { - for (h = d - 1; 0 < h; h--) { - g = p[this.rtl ? d - 1 - h : h] + g; - var k = this.score ? this.score(c, p, r, g, h) : fb(q, e, r, d, h); - gb(this, m, g, k, a, b); + for (k = d - 1; 0 < k; k--) { + g = r[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, r, p, g, k) : gb(q, e, p, d, k); + hb(this, n, g, h, a, b); } g = ""; } case "forward": if (1 < d) { - for (h = 0; h < d; h++) { - g += p[this.rtl ? d - 1 - h : h], gb(this, m, g, f, a, b); + for (k = 0; k < d; k++) { + g += r[this.rtl ? d - 1 - k : k], hb(this, n, g, f, a, b); } break; } default: - if (gb(this, m, p, f, a, b), n && 1 < e && r < e - 1) { - for (d = B(), g = this.U, f = p, h = Math.min(n + 1, this.rtl ? r + 1 : e - r), d[f] = 1, k = 1; k < h; k++) { - if ((p = c[this.rtl ? e - 1 - r - k : r + k]) && !d[p]) { - d[p] = 1; - const v = this.score ? this.score(c, f, r, p, k - 1) : fb(g + (e / 2 > g ? 0 : 1), e, r, h - 1, k - 1), u = this.bidirectional && p > f; - gb(this, l, u ? f : p, v, a, b, u ? p : f); + if (hb(this, n, r, f, a, b), m && 1 < e && p < e - 1) { + for (d = B(), g = this.U, f = r, k = Math.min(m + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { + if ((r = c[this.rtl ? e - 1 - p - h : p + h]) && !d[r]) { + d[r] = 1; + const u = this.score ? this.score(c, f, p, r, h - 1) : gb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; + hb(this, l, v ? f : r, u, a, b, v ? r : f); } } } @@ -1905,98 +1905,98 @@ O.prototype.add = function(a, c, b, e) { c = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.T && hb(this)); + this.db && (c || this.commit_task.push({del:a}), this.T && ib(this)); return this; }; -function gb(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - if (g ? (c = k || (c[b] = B()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = k = []), h = h[e] || (h[e] = []), !f || !h.includes(d)) { - if (h.length === 2 ** 31 - 1) { - c = new S(h); +function hb(a, c, b, e, d, f, g) { + let k = g ? a.ctx : a.map, h; + if (!c[b] || g && !(h = c[b])[g]) { + if (g ? (c = h || (c[b] = B()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { + if (k.length === 2 ** 31 - 1) { + c = new R(k); if (a.fastupdate) { for (let l of a.reg.values()) { - l.includes(h) && (l[l.indexOf(h)] = c); + l.includes(k) && (l[l.indexOf(k)] = c); } } - k[e] = h = c; + h[e] = k = c; } - h.push(d); - a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h])); + k.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } } -function fb(a, c, b, e, d) { +function gb(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;O.prototype.search = function(a, c, b) { +;N.prototype.search = function(a, c, b) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); - let e = [], d, f, g, h = 0, k, l, m, n, q; - b ? (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, q = (k = !1 !== b.resolve) && b.enrich, m = b.boost, n = b.resolution, l = this.db && b.tag) : k = this.resolve; - let r = this.encoder.encode(a); - d = r.length; - c = c || (k ? 100 : 0); + let e = [], d, f, g, k = 0, h, l, n, m, q; + b ? (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, q = (h = !1 !== b.resolve) && b.enrich, n = b.boost, m = b.resolution, l = this.db && b.tag) : h = this.resolve; + let p = this.encoder.encode(a); + d = p.length; + c = c || (h ? 100 : 0); if (1 === d) { - return ib.call(this, r[0], "", c, h, k, q, l); + return jb.call(this, p[0], "", c, k, h, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return ib.call(this, r[0], r[1], c, h, k, q, l); + return jb.call(this, p[0], p[1], c, k, h, q, l); } - let p = B(), v = 0, u; - 1 < d && f && (u = r[0], v = 1); - n || 0 === n || (n = u ? this.U : this.resolution); + let r = B(), u = 0, v; + 1 < d && f && (v = p[0], u = 1); + m || 0 === m || (m = v ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, r, c, h, g, k, q, l), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, c, k, g, h, q, l), !1 !== a)) { return a; } - const x = this; + const w = this; return async function() { - for (let y, F; v < d; v++) { - if ((F = r[v]) && !p[F]) { - p[F] = 1; - y = await jb(x, F, u, 0, 0, !1, !1); - if (y = kb(y, e, g, n)) { + for (let y, F; u < d; u++) { + if ((F = p[u]) && !r[F]) { + r[F] = 1; + y = await kb(w, F, v, 0, 0, !1, !1); + if (y = lb(y, e, g, m)) { e = y; break; } - u && (g && y && e.length || (u = F)); + v && (g && y && e.length || (v = F)); } - g && u && v === d - 1 && !e.length && (n = x.resolution, u = "", v = -1, p = B()); + g && v && u === d - 1 && !e.length && (m = w.resolution, v = "", u = -1, r = B()); } - return lb(e, n, c, h, g, m, k); + return mb(e, m, c, k, g, n, h); }(); } - for (let x, y; v < d; v++) { - if ((y = r[v]) && !p[y]) { - p[y] = 1; - x = jb(this, y, u, 0, 0, !1, !1); - if (x = kb(x, e, g, n)) { - e = x; + for (let w, y; u < d; u++) { + if ((y = p[u]) && !r[y]) { + r[y] = 1; + w = kb(this, y, v, 0, 0, !1, !1); + if (w = lb(w, e, g, m)) { + e = w; break; } - u && (g && x && e.length || (u = y)); + v && (g && w && e.length || (v = y)); } - g && u && v === d - 1 && !e.length && (n = this.resolution, u = "", v = -1, p = B()); + g && v && u === d - 1 && !e.length && (m = this.resolution, v = "", u = -1, r = B()); } - return lb(e, n, c, h, g, m, k); + return mb(e, m, c, k, g, n, h); }; -function lb(a, c, b, e, d, f, g) { - let h = a.length, k = a; - if (1 < h) { - k = Fa(a, c, b, e, d, f, g); - } else if (1 === h) { - return g ? Ia.call(null, a[0], b, e) : new X(a[0]); +function mb(a, c, b, e, d, f, g) { + let k = a.length, h = a; + if (1 < k) { + h = Ga(a, c, b, e, d, f, g); + } else if (1 === k) { + return g ? Ja.call(null, a[0], b, e) : new W(a[0]); } - return g ? k : new X(k); + return g ? h : new W(h); } -function ib(a, c, b, e, d, f, g) { - a = jb(this, a, c, b, e, d, f, g); - return this.db ? a.then(function(h) { - return d ? h || [] : new X(h); - }) : a && a.length ? d ? Ia.call(this, a, b, e) : new X(a) : d ? [] : new X(); +function jb(a, c, b, e, d, f, g) { + a = kb(this, a, c, b, e, d, f, g); + return this.db ? a.then(function(k) { + return d ? k || [] : new W(k); + }) : a && a.length ? d ? Ja.call(this, a, b, e) : new W(a) : d ? [] : new W(); } -function kb(a, c, b, e) { +function lb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -2017,16 +2017,16 @@ function kb(a, c, b, e) { return d; } } -function jb(a, c, b, e, d, f, g, h) { - let k; - b && (k = a.bidirectional && c > b) && (k = b, b = c, c = k); +function kb(a, c, b, e, d, f, g, k) { + let h; + b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); if (a.db) { - return a.db.get(c, b, e, d, f, g, h); + return a.db.get(c, b, e, d, f, g, k); } a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;O.prototype.remove = function(a, c) { +;N.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -2041,15 +2041,15 @@ function jb(a, c, b, e, d, f, g, h) { } } } else { - mb(this.map, a), this.depth && mb(this.ctx, a); + nb(this.map, a), this.depth && nb(this.ctx, a); } c || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && hb(this)); + this.db && (this.commit_task.push({del:a}), this.T && ib(this)); this.cache && this.cache.remove(a); return this; }; -function mb(a, c) { +function nb(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -2064,25 +2064,25 @@ function mb(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = mb(e[1], c); + const d = e[0], f = nb(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function O(a, c) { - if (!this || this.constructor !== O) { - return new O(a); +;function N(a, c) { + if (!this || this.constructor !== N) { + return new N(a); } if (a) { var b = E(a) ? a : a.preset; - b && (eb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, eb[b], a)); + b && (fb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, fb[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? db[a.encoder] : a.encode || a.encoder || Wa; - this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; + const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? eb[a.encoder] : a.encode || a.encoder || Xa; + this.encoder = d.encode ? d : "object" === typeof d ? new ka(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; this.depth = "strict" === b && e.depth || 0; @@ -2091,12 +2091,12 @@ function mb(a, c) { this.score = a.score || null; e && "strict" !== this.tokenize && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); (b = a.keystore || 0) && (this.keystore = b); - this.map = b ? new T(b) : new Map(); - this.ctx = b ? new T(b) : new Map(); - this.reg = c || (this.fastupdate ? b ? new T(b) : new Map() : b ? new U(b) : new Set()); + this.map = b ? new S(b) : new Map(); + this.ctx = b ? new S(b) : new Map(); + this.reg = c || (this.fastupdate ? b ? new S(b) : new Map() : b ? new T(b) : new Set()); this.U = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new Y(b); + this.cache = (b = a.cache || null) && new X(b); this.resolve = !1 !== a.resolve; if (b = a.db) { this.db = this.mount(b); @@ -2106,7 +2106,7 @@ function mb(a, c) { this.commit_timer = null; this.priority = a.priority || 4; } -t = O.prototype; +t = N.prototype; t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -2119,7 +2119,7 @@ t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function hb(a) { +function ib(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2143,7 +2143,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 nb(a) { +function ob(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -2151,7 +2151,7 @@ function nb(a) { } } else { for (const b of a.entries()) { - const e = b[0], d = nb(b[1]); + const e = b[0], d = ob(b[1]); d ? c += d : a.delete(e); } } @@ -2161,17 +2161,17 @@ t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - nb(this.map); - this.depth && nb(this.ctx); + ob(this.map); + this.depth && ob(this.ctx); return this; }; -t.searchCache = Va; +t.searchCache = Wa; t.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = wa(this.reg); + f = xa(this.reg); break; case 1: d = "cfg"; @@ -2179,29 +2179,29 @@ t.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = sa(this.map, this.reg.size); + f = ta(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ua(this.ctx, this.reg.size); + f = va(this.ctx, this.reg.size); break; default: return; } - return ya.call(this, a, c, d, f, b, e); + return za.call(this, a, c, d, f, b, e); }; t.import = function(a, c) { if (c) { switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = xa(c, this.reg); + this.reg = ya(c, this.reg); break; case "map": - this.map = ta(c, this.map); + this.map = ua(c, this.map); break; case "ctx": - this.ctx = va(c, this.ctx); + this.ctx = wa(c, this.ctx); } } }; @@ -2213,24 +2213,24 @@ t.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + ("string" === f ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = za(this.map, f); + b = Aa(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let h = za(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + d + '",' + h + "]"; - e += (e ? "," : "") + h; + let k = Aa(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; -la(O.prototype); -const pb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), qb = ["map", "ctx", "tag", "reg", "cfg"]; -function rb(a, c = {}) { +ma(N.prototype); +const qb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), rb = ["map", "ctx", "tag", "reg", "cfg"], Y = B(); +function sb(a, c = {}) { if (!this) { - return new rb(a, c); + return new sb(a, c); } "object" === typeof a && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2241,7 +2241,7 @@ function rb(a, c = {}) { this.db = null; this.h = {}; } -t = rb.prototype; +t = sb.prototype; t.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2252,13 +2252,18 @@ t.mount = function(a) { t.open = function() { let a = this; navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function(c, b) { - const e = pb.open(a.id + (a.field ? ":" + a.field : ""), 1); + return this.db || (this.db = new Promise(function(c, b) { + Y[a.id] || (Y[a.id] = []); + Y[a.id].push(a.field); + const e = qb.open(a.id, 1); e.onupgradeneeded = function() { const d = a.db = this.result; - qb.forEach(f => { - d.objectStoreNames.contains(f) || d.createObjectStore(f); - }); + for (let f = 0, g; f < rb.length; f++) { + g = rb[f]; + for (let k = 0, h; k < Y[a.id].length; k++) { + h = Y[a.id][k], d.objectStoreNames.contains(g + ("reg" !== g ? h ? ":" + h : "" : "")) || d.createObjectStore(g + ("reg" !== g ? h ? ":" + h : "" : "")); + } + } }; e.onblocked = function(d) { console.error("blocked", d); @@ -2275,58 +2280,65 @@ t.open = function() { }; c(a); }; - }); + })); }; t.close = function() { this.db && this.db.close(); this.db = null; }; t.destroy = function() { - const a = pb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const a = qb.deleteDatabase(this.id); return Z(a); }; t.clear = function() { - const a = this.db.transaction(qb, "readwrite"); - for (let c = 0; c < qb.length; c++) { - a.objectStore(qb[c]).clear(); + const a = []; + for (let b = 0, e; b < rb.length; b++) { + e = rb[b]; + for (let d = 0, f; d < Y[this.id].length; d++) { + f = Y[this.id][d], a.push(e + ("reg" !== e ? f ? ":" + f : "" : "")); + } } - return Z(a); + const c = this.db.transaction(a, "readwrite"); + for (let b = 0; b < a.length; b++) { + c.objectStore(a[b]).clear(); + } + return Z(c); }; t.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { - a = this.db.transaction(c ? "ctx" : "map", "readonly").objectStore(c ? "ctx" : "map").get(c ? c + ":" + a : a); + a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); const g = this; - return Z(a).then(function(h) { - let k = []; - if (!h || !h.length) { - return k; + return Z(a).then(function(k) { + let h = []; + if (!k || !k.length) { + return h; } if (d) { - if (!b && !e && 1 === h.length) { - return h[0]; + if (!b && !e && 1 === k.length) { + return k[0]; } - for (let l = 0, m; l < h.length; l++) { - if ((m = h[l]) && m.length) { - if (e >= m.length) { - e -= m.length; + for (let l = 0, n; l < k.length; l++) { + if ((n = k[l]) && n.length) { + if (e >= n.length) { + e -= n.length; continue; } - const n = b ? e + Math.min(m.length - e, b) : m.length; - for (let q = e; q < n; q++) { - k.push(m[q]); + const m = b ? e + Math.min(n.length - e, b) : n.length; + for (let q = e; q < m; q++) { + h.push(n[q]); } e = 0; - if (k.length === b) { + if (h.length === b) { break; } } } - return f ? g.enrich(k) : k; + return f ? g.enrich(h) : h; } - return h; + return k; }); }; t.tag = function(a, c = 0, b = 0, e = !1) { - a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); + a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); const d = this; return Z(a).then(function(f) { if (!f || !f.length || b >= f.length) { @@ -2362,24 +2374,25 @@ t.search = null; t.info = function() { }; t.transaction = function(a, c, b) { - let e = this.h[a + ":" + c]; - if (e) { - return b.call(this, e); + const e = a + ("reg" !== a ? this.field ? ":" + this.field : "" : ""); + let d = this.h[e + ":" + c]; + if (d) { + return b.call(this, d); } - let d = this.db.transaction(a, c); - this.h[a + ":" + c] = e = d.objectStore(a); - return new Promise((f, g) => { - d.onerror = k => { - d.abort(); - d = e = null; - g(k); + let f = this.db.transaction(e, c); + this.h[e + ":" + c] = d = f.objectStore(e); + return new Promise((g, k) => { + f.onerror = l => { + f.abort(); + f = d = null; + k(l); }; - d.oncomplete = k => { - d = e = null; - f(k || !0); + f.oncomplete = l => { + f = d = null; + g(l || !0); }; - const h = b.call(this, e); - this.h[a + ":" + c] = null; + const h = b.call(this, d); + this.h[e + ":" + c] = null; return h; }); }; @@ -2404,54 +2417,54 @@ t.commit = async function(a, c, b) { for (const d of a.map) { const f = d[0], g = d[1]; g.length && (c ? e.put(g, f) : e.get(f).onsuccess = function() { - let h = this.result; - var k; - if (h && h.length) { - const l = Math.max(h.length, g.length); - for (let m = 0, n, q; m < l; m++) { - if ((q = g[m]) && q.length) { - if ((n = h[m]) && n.length) { - for (k = 0; k < q.length; k++) { - n.push(q[k]); + let k = this.result; + var h; + if (k && k.length) { + const l = Math.max(k.length, g.length); + for (let n = 0, m, q; n < l; n++) { + if ((q = g[n]) && q.length) { + if ((m = k[n]) && m.length) { + for (h = 0; h < q.length; h++) { + m.push(q[h]); } } else { - h[m] = q; + k[n] = q; } - k = 1; + h = 1; } } } else { - h = g, k = 1; + k = g, h = 1; } - k && e.put(h, f); + h && e.put(k, f); }); } }), await this.transaction("ctx", "readwrite", function(e) { for (const d of a.ctx) { const f = d[0], g = d[1]; - for (const h of g) { - const k = h[0], l = h[1]; - l.length && (c ? e.put(l, f + ":" + k) : e.get(f + ":" + k).onsuccess = function() { - let m = this.result; - var n; - if (m && m.length) { - const q = Math.max(m.length, l.length); - for (let r = 0, p, v; r < q; r++) { - if ((v = l[r]) && v.length) { - if ((p = m[r]) && p.length) { - for (n = 0; n < v.length; n++) { - p.push(v[n]); + for (const k of g) { + const h = k[0], l = k[1]; + l.length && (c ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { + let n = this.result; + var m; + if (n && n.length) { + const q = Math.max(n.length, l.length); + for (let p = 0, r, u; p < q; p++) { + if ((u = l[p]) && u.length) { + if ((r = n[p]) && r.length) { + for (m = 0; m < u.length; m++) { + r.push(u[m]); } } else { - m[r] = v; + n[p] = u; } - n = 1; + m = 1; } } } else { - m = l, n = 1; + n = l, m = 1; } - n && e.put(m, f + ":" + k); + m && e.put(n, f + ":" + h); }); } } @@ -2468,29 +2481,29 @@ t.commit = async function(a, c, b) { for (const d of a.tag) { const f = d[0], g = d[1]; g.length && (e.get(f).onsuccess = function() { - let h = this.result; - h = h && h.length ? h.concat(g) : g; - e.put(h, f); + let k = this.result; + k = k && k.length ? k.concat(g) : g; + e.put(k, f); }); } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function sb(a, c, b) { +function tb(a, c, b) { const e = a.value; let d, f, g = 0; - for (let h = 0, k; h < e.length; h++) { - if (k = b ? e : e[h]) { - for (let l = 0, m, n; l < c.length; l++) { - if (n = c[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 (d = 1, 1 < k.length) { - k.splice(m, 1); + for (let k = 0, h; k < e.length; k++) { + if (h = b ? e : e[k]) { + for (let l = 0, n, m; l < c.length; l++) { + if (m = c[l], n = h.indexOf(f ? parseInt(m, 10) : m), 0 > n && !f && "string" === typeof m && !isNaN(m) && (n = h.indexOf(parseInt(m, 10))) && (f = 1), 0 <= n) { + if (d = 1, 1 < h.length) { + h.splice(n, 1); } else { - e[h] = []; + e[k] = []; break; } } } - g += k.length; + g += h.length; } if (b) { break; @@ -2501,20 +2514,20 @@ function sb(a, c, b) { } t.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map", "readwrite", function(c) { + return Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && sb(b, a); + b && tb(b, a); }; - }), this.transaction("ctx", "readwrite", function(c) { + }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && sb(b, a); + b && tb(b, a); }; - }), this.transaction("tag", "readwrite", function(c) { + }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && sb(b, a, !0); + b && tb(b, a, !0); }; }), this.transaction("reg", "readwrite", function(c) { for (let b = 0; b < a.length; b++) { @@ -2528,12 +2541,12 @@ function Z(a) { c(this.result); }; a.oncomplete = function() { - c(this.result); + c(); }; a.onerror = b; a = null; }); } -;export default {Index:O, Charset:db, Encoder:J, Document:V, Worker:Q, Resolver:X, IndexedDB:rb, Language:{}}; +;export default {Index:N, Charset:eb, Encoder:ka, Document:U, Worker:P, Resolver:W, IndexedDB:sb, Language:{}}; -export const Index=O;export const Charset=db;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=rb;export const Language={}; \ No newline at end of file +export const Index=N;export const Charset=eb;export const Encoder=ka;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=sb;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 4e2b84b..5acf655 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,104 +1,105 @@ /**! - * FlexSearch.js v0.8.133 (Bundle/Module) + * FlexSearch.js v0.8.135 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var t;function A(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function B(){return Object.create(null)}function E(a){return"string"===typeof a} -function I(a){return"object"===typeof a}function aa(a){const b=[];for(const c of a.keys())b.push(c);return b}function ba(a,b){if(E(b))a=a[b];else for(let c=0;a&&c"a1a".split(c).length; -this.numeric=A(a.numeric,e)}else{try{this.split=A(this.split,ea)}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);ja||(this.mapper=new Map(da));c=a.filter;this.filter="function"===typeof c?c:A(c&&new Set(c),null,this.filter);this.dedupe=A(a.dedupe,!1,this.dedupe);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);this.rtl=A(a.rtl,!1,this.rtl);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&&K(this);return this};t.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; -t.addMapper=function(a,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&&K(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&&K(this);return this}; -t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(K,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==g&&this.filter&& -g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&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 K(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){ma.call(a,"add");ma.call(a,"append");ma.call(a,"search");ma.call(a,"update");ma.call(a,"remove")}let na,oa,pa;function qa(){na=pa=0} -function ma(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);na?pa||(pa=Date.now()-oa>=this.priority*this.priority*3):(na=setTimeout(qa,0),oa=Date.now());if(pa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let P=0; -function Q(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&d.h[l];m&&(m(k.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++P]=function(){k(d);1E9=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const h=b.length;if(h&&(d=d.length?d.concat(b):b,c-=h,e&&(a.length-=h),!c))break;b=0}return d} -function S(a){if(!this||this.constructor!==S)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if("length"===e)return b.length;if("push"===e)return function(d){b.index[b.index.length-1].push(d);b.length++};if("pop"===e)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,h,k;gc||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+e)}else{d=[];for(let 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}k=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.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?W.call(this,g):g;d.push(g);b-=h;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.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}=Ja(this,"and",arguments);return La.call(this,f,g,h,k,l,m,n)}return d?this.resolve(b,c,e):this}; -function La(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; -function Ma(a,b,c,e,d,f,g){if(b.length){const h=this;return Promise.all(b).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function Na(a,b,c,e,d){const f=[],g=B();let h=0;for(let k=0,l;kc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.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};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=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 Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const $a={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 ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cu;f--){g=q.substring(u,f);v=this.rtl?d-1-u:u;var h=this.score?this.score(b,q,r,g,v):fb(p,e,r,d,v); -gb(this,m,g,h,a,c)}break}case "reverse":if(1g?0:1),e,r,h-1,k-1),v=this.bidirectional&& -q>f;gb(this,l,v?f:q,u,a,c,v?q:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.T&&hb(this));return this}; -function gb(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new S(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[e]=h=b}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function fb(a,b,c,e,d){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,e,d,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&hb(this));this.cache&&this.cache.remove(a);return this}; -function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}; -function ob(a){let b=0;if(a.constructor===Array)for(let c=0,e;c{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&&this.db.close();this.db=null};t.destroy=function(){const a=pb.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(qb,"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=>{d.abort();d=e=null;g(k)};d.oncomplete=k=>{d=e=null;f(k||!0)};const h=c.call(this,e);this.h[a+":"+b]=null;return h})}; -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=k.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:O,Charset:db,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:rb,Language:{}}; -export const Index=O;export const Charset=db;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=rb;export const Language={}; \ No newline at end of file +t.assign=function(a){this.normalize=z(a.normalize,!0,this.normalize);let c=a.include,b=c||a.exclude||a.split,e;if(b||""===b){if("object"===typeof b&&b.constructor!==RegExp){let d="";e=!c;c||(d+="\\p{Z}");b.letter&&(d+="\\p{L}");b.number&&(d+="\\p{N}",e=!!c);b.symbol&&(d+="\\p{S}");b.punctuation&&(d+="\\p{P}");b.control&&(d+="\\p{C}");if(b=b.char)d+="object"===typeof b?b.join(""):b;try{this.split=new RegExp("["+(c?"^":"")+d+"]+","u")}catch(f){this.split=/\s+/}}else this.split=b,e=!1===b||2>"a1a".split(b).length; +this.numeric=z(a.numeric,e)}else{try{this.split=z(this.split,ea)}catch(d){this.split=/\s+/}this.numeric=z(a.numeric,z(this.numeric,!0))}this.prepare=z(a.prepare,null,this.prepare);this.finalize=z(a.finalize,null,this.finalize);ja||(this.mapper=new Map(da));b=a.filter;this.filter="function"===typeof b?b:z(b&&new Set(b),null,this.filter);this.dedupe=z(a.dedupe,!1,this.dedupe);this.matcher=z((b=a.matcher)&&new Map(b),null,this.matcher);this.mapper=z((b=a.mapper)&&new Map(b),null,this.mapper);this.stemmer= +z((b=a.stemmer)&&new Map(b),null,this.stemmer);this.replacer=z(a.replacer,null,this.replacer);this.minlength=z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);this.rtl=z(a.rtl,!1,this.rtl);if(this.cache=b=z(a.cache,!0,this.cache))this.H=null,this.S="number"===typeof b?b:2E5,this.B=new Map,this.G=new Map,this.L=this.K=128;this.h="";this.M=null;this.A="";this.N=null;if(this.matcher)for(const d of this.matcher.keys())this.h+=(this.h?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.A+= +(this.A?"|":"")+d;return this};t.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.A+=(this.A?"|":"")+a;this.N=null;this.cache&&K(this);return this};t.addFilter=function(a){"function"===typeof a?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&K(this);return this}; +t.addMapper=function(a,c){if("object"===typeof a)return this.addReplacer(a,c);if(1a.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&K(this);return this}; +t.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&K(this);return this}; +t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(K,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&dthis.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.B.set(a,b),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return b};function K(a){a.H=null;a.B.clear();a.G.clear()};let M,ka;async function la(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":ka=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(ka),delete self.FlexSearch):M=new N(ka);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=ka.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await ka.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ma(a){na.call(a,"add");na.call(a,"append");na.call(a,"search");na.call(a,"update");na.call(a,"remove")}let oa,pa,qa;function ra(){oa=qa=0} +function na(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);oa?qa||(qa=Date.now()-pa>=this.priority*this.priority*3):(oa=setTimeout(ra,0),pa=Date.now());if(qa){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let O=0; +function P(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,n=l&&d.h[l];n&&(n(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[++O]=function(){h(d);1E9=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const k=c.length;if(k&&(d=d.length?d.concat(c):c,b-=k,e&&(a.length-=k),!b))break;c=0}return d} +function R(a){if(!this||this.constructor!==R)return new R(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if("length"===e)return c.length;if("push"===e)return function(d){c.index[c.index.length-1].push(d);c.length++};if("pop"===e)return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if("indexOf"===e)return function(d){let f=0;for(let g=0,k,h;gb||e?h.slice(e,b+e):h;else{if(ab||e)h=h.slice(e,b+e)}else{d=[];for(let m= +0,q;me)e-=q.length;else{if(q.length>b||e)q=q.slice(e,b+e),b-=q.length,e&&(e-=q.length);d.push(q);if(!b)break}h=1c?c?a.slice(b,b+c):a.slice(b):a,e?V.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?V.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=Ha(a,b,e,!1,this.h),e=0));return f?this.resolve(b,e,d):this};W.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:n,suggest:m}=Ka(this,"and",arguments);return Ma.call(this,f,g,k,h,l,n,m)}return d?this.resolve(c,b,e):this}; +function Ma(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(c=ca(a))return this.result=Ga(a,c,b,e,g,this.h,f),f?d?V.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};W.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ka(this,"xor",arguments);return Na.call(this,a,c,b,e,d,f,g)}; +function Na(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Oa.call(this,a,b,e,f,this.h),f?d?V.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Oa(a,c,b,e,d){const f=[],g=B();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=V.call(this,a));return a}}function V(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +X.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Xa={normalize:function(a){return a.toLowerCase()}};const Ya=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Za=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),$a=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ab={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;const db=/[\x00-\x7F]+/g;var eb={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Xa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ya},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ya,matcher:Za,replacer:$a},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ya,replacer:$a.concat([/(?!^)[aeo]/g,""]),matcher:Za},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bu;f--){g=r.substring(u,f);v=this.rtl?d-1-u:u;var k=this.score?this.score(c,r,p,g,v):gb(q,e,p,d,v); +hb(this,n,g,k,a,b)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),v=this.bidirectional&& +r>f;hb(this,l,v?f:r,u,a,b,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else c=""}this.db&&(c||this.commit_task.push({del:a}),this.T&&ib(this));return this}; +function hb(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])if(g?(c=h||(c[b]=B()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){c=new R(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=c);h[e]=k=c}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} +function gb(a,c,b,e,d){return b&&1b)&&(h=b,b=c,c=h);if(a.db)return a.db.get(c,b,e,d,f,g,k);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};N.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else nb(this.map,a),this.depth&&nb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&ib(this));this.cache&&this.cache.remove(a);return this}; +function nb(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; +function pb(a){let c=0;if(a.constructor===Array)for(let b=0,e;b=n.length){e-=n.length;continue}const m=b?e+Math.min(n.length-e,b):n.length;for(let q=e;q=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; +t.enrich=function(a){"object"!==typeof a&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e{f.onerror=l=>{f.abort();f=d=null;k(l)};f.oncomplete=l=>{f=d=null;g(l||!0)};const h=b.call(this,d);this.h[e+":"+c]=null;return h})}; +t.commit=async function(a,c,b){if(c)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dn&&!f&&"string"===typeof m&&!isNaN(m)&&(n=h.indexOf(parseInt(m,10)))&&(f=1),0<=n)if(d=1,1{a.onsuccess=function(){c(this.result)};a.oncomplete=function(){c()};a.onerror=b;a=null})};export default {Index:N,Charset:eb,Encoder:J,Document:U,Worker:P,Resolver:W,IndexedDB:sb,Language:{}}; +export const Index=N;export const Charset=eb;export const Encoder=J;export const Document=U;export const Worker=P;export const Resolver=W;export const IndexedDB=sb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 15fa11a..50c9026 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.133 (Bundle/Debug) + * FlexSearch.js v0.8.135 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -13,8 +13,8 @@ function B(a, c, b) { if ("undefined" !== d) { if (b) { if ("function" === d && e === d) { - return function(h) { - return a(b(h)); + return function(k) { + return a(b(k)); }; } c = a.constructor; @@ -220,8 +220,8 @@ x.encode = function(a) { this.numeric && 3 < a.length && (a = a.replace(ea, "$1 $2").replace(fa, "$1 $2").replace(da, "$1 ")); const c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); let b = [], e = this.split || "" === this.split ? a.split(this.split) : a; - for (let f = 0, g, h; f < e.length; f++) { - if ((g = h = e[f]) && !(g.length < this.minlength)) { + for (let f = 0, g, k; f < e.length; f++) { + if ((g = k = e[f]) && !(g.length < this.minlength)) { if (c) { b.push(g); } else { @@ -237,21 +237,21 @@ x.encode = function(a) { this.H = setTimeout(L, 50, this); } } - this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), d = g, g = g.replace(this.N, k => this.stemmer.get(k)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), d = g, g = g.replace(this.N, h => this.stemmer.get(h)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let k = 0, l = "", m, n; k < g.length; k++) { - m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let h = 0, l = "", m, n; h < g.length; h++) { + m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); g && b.push(g); } } @@ -332,19 +332,19 @@ function P(a) { ;let R = 0; function S(a = {}) { function c(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && d.h[l]; - m && (m(k.msg), delete d.h[l]); + function k(h) { + h = h.data || h; + const l = h.id, m = l && d.h[l]; + m && (m(h.msg), delete d.h[l]); } this.worker = g; this.h = C(); if (this.worker) { - e ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { + return new Promise(function(h) { d.h[++R] = function() { - k(d); + h(d); 1e9 < R && (R = 0); }; d.worker.postMessage({id:R, task:"init", factory:b, options:a}); @@ -440,18 +440,18 @@ function ta(a, c) { return c; } function U(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { return this.export(a, c, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return U.call(l, a, c, b, h ? e : null, d, f, g + 1); + return h.then(function() { + return U.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return U.call(this, a, c, b, h ? e : null, d, f, g + 1); + return U.call(this, a, c, b, k ? e : null, d, f, g + 1); } function ua(a, c) { let b = ""; @@ -459,14 +459,14 @@ function ua(a, c) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, h; g < d.length; g++) { - h = d[g] || [""]; - let k = ""; - for (let l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === c ? '"' + h[l] + '"' : h[l]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === c ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; b += (b ? "," : "") + f; @@ -479,15 +479,15 @@ function ua(a, c) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.C[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); + for (let k = 0, h; k < this.field.length; k++) { + h = this.C[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(c); d && e.add(a, d, !1, !0); } else { - if (d = k.I, !d || d(c)) { - k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), va(c, k, this.J, 0, e, a, k[0], b); + if (d = h.I, !d || d(c)) { + h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); } } } @@ -495,14 +495,14 @@ function ua(a, c) { for (e = 0; e < this.B.length; e++) { var f = this.B[e], g = this.T[e]; d = this.tag.get(g); - let h = C(); + let k = C(); if ("function" === typeof f) { if (f = f(c), !f) { continue; } } else { - const k = f.I; - if (k && !k(c)) { + const h = f.I; + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); @@ -510,8 +510,8 @@ function ua(a, c) { } if (d && f) { D(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + for (let h = 0, l, m; h < f.length; h++) { + l = f[h], k[l] || (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -519,11 +519,11 @@ function ua(a, c) { } } if (this.store && (!b || !this.store.has(a))) { - let h; + let k; if (this.A) { - h = C(); - for (let k = 0, l; k < this.A.length; k++) { - l = this.A[k]; + k = C(); + for (let h = 0, l; h < this.A.length; h++) { + l = this.A[h]; if ((b = l.I) && !b(c)) { continue; } @@ -535,13 +535,13 @@ function ua(a, c) { } l = [l.U]; } else if (D(l) || l.constructor === String) { - h[l] = c[l]; + k[l] = c[l]; continue; } - wa(c, h, l, 0, l[0], m); + wa(c, k, l, 0, l[0], m); } } - this.store.set(a, h || c); + this.store.set(a, k || c); } } return this; @@ -560,7 +560,7 @@ function wa(a, c, b, e, d, f) { } } } -function va(a, c, b, e, d, f, g, h) { +function va(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -572,27 +572,27 @@ function va(a, c, b, e, d, f, g, h) { } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - va(a, c, b, e, d, f, g, h); + va(a, c, b, e, d, f, g, k); } } else { - g = c[++e], va(a, c, b, e, d, f, g, h); + g = c[++e], va(a, c, b, e, d, f, g, k); } } } } ;function xa(a, c, b, e, d) { const f = a.length; - let g = [], h, k; - h = C(); - for (let l = 0, m, n, t, p; l < c; l++) { + let g = [], k, h; + k = C(); + for (let l = 0, m, n, r, p; l < c; l++) { for (let q = 0; q < f; q++) { - if (t = a[q], l < t.length && (m = t[l])) { - for (let v = 0; v < m.length; v++) { - if (n = m[v], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), p = g[k] || (g[k] = []), p.push(n), b && k === f - 1 && p.length - e === b) { + if (r = a[q], l < r.length && (m = r[l])) { + for (let t = 0; t < m.length; t++) { + if (n = m[t], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n), b && h === f - 1 && p.length - e === b) { return p; } } @@ -620,10 +620,10 @@ function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; - let h; - for (let k = g - 1; 0 <= k; k--) { - if (h = (g = a[k]) && g.length) { - for (let l = 0; l < h; l++) { + let k; + for (let h = g - 1; 0 <= h; h--) { + if (k = (g = a[h]) && g.length) { + for (let l = 0; l < k; l++) { if (f = g[l], !d[f]) { if (d[f] = 1, b) { b--; @@ -651,38 +651,37 @@ function za(a, c) { } return e; } -;function Aa(a, c, b, e) { +;function W(a, c, b) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } - let d = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + let e = []; + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && (g = f.length)) { if (b) { - if (b >= h) { - b -= h; + if (b >= g) { + b -= g; continue; } - b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); + b < g && (f = c ? f.slice(b, b + c) : f.slice(b), g = f.length, b = 0); } - h > c && (g = g.slice(0, c), h = c); - if (!d.length && h >= c) { - return e ? W.call(this, g) : g; + g > c && (f = f.slice(0, c), g = c); + if (!e.length && g >= c) { + return f; } - d.push(g); - c -= h; + e.push(f); + c -= g; if (!c) { break; } } } - d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? W.call(this, d) : d; + return e = 1 < e.length ? [].concat.apply([], e) : e[0]; } -;function Ba(a, c, b) { +;function Aa(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -693,54 +692,54 @@ function za(a, c) { return a[c].apply(a, e); } e = []; - let d = [], f = 0, g = 0, h, k, l; + let d = [], f = 0, g = 0, k, h, l; for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { - let t; + let r; if (n.constructor === X) { - t = n.result; + r = n.result; } else if (n.constructor === Array) { - t = n; + r = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { - n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = k, n.enrich = h; + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { + n.resolve = !1, n.enrich = !1, r = n.index.search(n).result, n.resolve = h, n.enrich = k; } else if (n.and) { - t = a.and(n.and); + r = a.and(n.and); } else if (n.or) { - t = a.or(n.or); + r = a.or(n.or); } else if (n.xor) { - t = a.xor(n.xor); + r = a.xor(n.xor); } else if (n.not) { - t = a.not(n.not); + r = a.not(n.not); } else { continue; } } - if (t.then) { - d.push(t); - } else if (t.length) { - e[m] = t; + if (r.then) { + d.push(r); + } else if (r.length) { + e[m] = r; } else if (!l && ("and" === c || "xor" === c)) { e = []; break; } } } - return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;X.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); - return Ca.call(this, a, c, b, e, d, f); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Aa(this, "or", arguments); + return Ba.call(this, a, c, b, e, d, f); }; -function Ca(a, c, b, e, d, f) { +function Ba(a, c, b, e, d, f) { if (c.length) { const g = this; - return Promise.all(c).then(function(h) { + return Promise.all(c).then(function(k) { a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } - return Ca.call(g, a, [], b, e, d, f); + return Ba.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 = ya(a, b, e), e = 0)); @@ -753,20 +752,20 @@ function Ca(a, c, b, e, d, f) { f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); - return Da.call(this, f, g, h, k, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Aa(this, "and", arguments); + return Ca.call(this, f, g, k, h, l, m, n); } return d ? this.resolve(c, b, e) : this; }; -function Da(a, c, b, e, d, f, g) { +function Ca(a, c, b, e, d, f, g) { if (c.length) { const h = this; - return Promise.all(c).then(function(k) { + return Promise.all(c).then(function(l) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let m = 0, n; m < l.length; m++) { + (n = l[m]).length && (a[m] = n); } - return Da.call(h, a, [], b, e, d, f, g); + return Ca.call(h, a, [], b, e, d, f, g); }); } if (a.length) { @@ -774,7 +773,10 @@ function Da(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = xa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; + this.result = xa(a, c, b, e, g); + var k; + f ? d ? k = this.result : k = this.result : k = this; + return k; } this.result = []; } @@ -784,50 +786,58 @@ function Da(a, c, b, e, d, f, g) { return f ? this.resolve(b, e, d) : this; } ;X.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); - return Ea.call(this, a, c, b, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "xor", arguments); + return Da.call(this, a, c, b, e, d, f, g); }; -function Ea(a, c, b, e, d, f, g) { +function Da(a, c, b, e, d, f, g) { if (c.length) { const h = this; - return Promise.all(c).then(function(k) { + return Promise.all(c).then(function(l) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let m = 0, n; m < l.length; m++) { + (n = l[m]).length && (a[m] = n); } - return Ea.call(h, a, [], b, e, d, f, g); + return Da.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 = Fa.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + this.result = Ea.call(this, a, b, e, f, this.h); + if (f) { + var k; + d ? k = this.result : k = this.result; + c = k; + } else { + c = this; + } + return c; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Fa(a, c, b, e, d) { +function Ea(a, c, b, e, d) { const f = [], g = C(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); + let k = 0; + for (let h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); for (let m = 0, n; m < l.length; m++) { if (n = l[m]) { - for (let t = 0, p; t < n.length; t++) { - p = n[t], g[p] = g[p] ? 2 : 1; + for (let r = 0, p; r < n.length; r++) { + p = n[r], 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 h = 0, l, m = 0; h < k; h++) { + for (let n = 0, r; n < a.length; n++) { + if (r = a[n]) { + if (l = r[h]) { for (let p = 0, q; p < l.length; p++) { if (q = l[p], 1 === g[q]) { if (b) { @@ -838,9 +848,9 @@ function Fa(a, c, b, e, d) { return f; } } else { - const v = k + (n ? d : 0); - f[v] || (f[v] = []); - f[v].push(q); + const t = h + (n ? d : 0); + f[t] || (f[t] = []); + f[t].push(q); if (++m === c) { return f; } @@ -855,34 +865,41 @@ function Fa(a, c, b, e, d) { return f; } ;X.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); - return Ga.call(this, a, c, b, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "not", arguments); + return Fa.call(this, a, c, b, e, d, f, g); }; -function Ga(a, c, b, e, d, f, g) { +function Fa(a, c, b, e, d, f, g) { if (c.length) { const h = this; - return Promise.all(c).then(function(k) { + return Promise.all(c).then(function(l) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let m = 0, n; m < l.length; m++) { + (n = l[m]).length && (a[m] = n); } - return Ga.call(h, a, [], b, e, d, f, g); + return Fa.call(h, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ha.call(this, a, b, e, f); + this.result = Ga.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? W.call(this.index, this.result) : this.result : this; + if (f) { + var k; + d ? k = this.result : k = this.result; + c = k; + } else { + c = this; + } + return c; } -function Ha(a, c, b, e) { +function Ga(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { + for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (b) { b--; } else { @@ -891,7 +908,7 @@ function Ha(a, c, b, e) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { + if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { return d; } } @@ -948,52 +965,54 @@ X.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, c, b) { - const e = this.result, d = this.index; +X.prototype.resolve = function(a, c) { + const b = this.result, e = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; + return b.length ? ("object" === typeof a && (c = a.offset, a = a.limit), W.call(e, b, a || 100, c)) : b; }; C(); V.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, n, t = 0, p = !0, q; + let g; + let k, h, l; + let m = 0, n = !0, r; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; - var v = b.pluck; - h = b.merge; - l = v || b.field || (l = b.index) && (l.index ? null : l); - m = this.tag && b.tag; + var p = b.pluck; + var q = b.merge; + h = p || b.field || (h = b.index) && (h.index ? null : h); + l = 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 })"); - q = (g = this.store && b.enrich && p) && b.highlight; + n = !0; + this.store && b.enrich && !n && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + r = (g = this.store && b.enrich && n) && b.highlight; c = b.limit || c; - n = b.offset || 0; + var t = b.offset || 0; c || (c = 100); - if (m) { - m.constructor !== Array && (m = [m]); + if (l) { + l.constructor !== Array && (l = [l]); var u = []; - for (let y = 0, r; y < m.length; y++) { - r = m[y]; - if (D(r)) { + for (let y = 0, v; y < l.length; y++) { + v = l[y]; + if (D(v)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (r.field && r.tag) { - var w = r.tag; + if (v.field && v.tag) { + var w = v.tag; if (w.constructor === Array) { for (var z = 0; z < w.length; z++) { - u.push(r.field, w[z]); + u.push(v.field, w[z]); } } else { - u.push(r.field, w); + u.push(v.field, w); } } else { - w = Object.keys(r); + w = Object.keys(v); for (let E = 0, F, A; E < w.length; E++) { - if (F = w[E], A = r[F], A.constructor === Array) { + if (F = w[E], A = v[F], A.constructor === Array) { for (z = 0; z < A.length; z++) { u.push(F, A[z]); } @@ -1006,126 +1025,125 @@ V.prototype.search = function(a, c, b, e) { if (!u.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - m = u; + l = u; if (!a) { - e = []; + f = []; if (u.length) { - for (f = 0; f < u.length; f += 2) { - v = Ia.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:v}); + for (p = 0; p < u.length; p += 2) { + q = Ha.call(this, u[p], u[p + 1], c, t), d.push({field:u[p], tag:u[p + 1], result:q}); } } - return e.length ? Promise.all(e).then(function(y) { - for (let r = 0; r < y.length; r++) { - d[r].result = y[r]; + return f.length ? Promise.all(f).then(function(y) { + for (let v = 0; v < y.length; v++) { + d[v].result = y[v]; } return d; }) : d; } } - l && l.constructor !== Array && (l = [l]); + h && h.constructor !== Array && (h = [h]); } - l || (l = this.field); + h || (h = this.field); u = !e && (this.worker || this.db) && []; - for (let y = 0, r, E, F; y < l.length; y++) { - E = l[y]; + for (let y = 0, v, E, F; y < h.length; y++) { + E = h[y]; let A; - D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, k = A.suggest || k, g = this.store && (A.enrich || g)); + D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, t = A.offset || t, k = A.suggest || k, g = this.store && (A.enrich || g)); if (e) { - r = e[y]; + v = e[y]; } else { - if (w = A || b, z = this.index.get(E), m && (w.enrich = !1), u) { + if (w = A || b, z = this.index.get(E), l && (w.enrich = !1), u) { u[y] = z.search(a, c, w); w && g && (w.enrich = g); continue; } else { - r = z.search(a, c, w), w && g && (w.enrich = g); + v = z.search(a, c, w), w && g && (w.enrich = g); } } - F = r && (p ? r.length : r.result.length); - if (m && F) { + F = v && (n ? v.length : v.result.length); + if (l && F) { w = []; z = 0; - for (let G = 0, H, Za; G < m.length; G += 2) { - H = this.tag.get(m[G]); + for (let G = 0, H, Ya; G < l.length; G += 2) { + H = this.tag.get(l[G]); if (!H) { - if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { + if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), k) { continue; } else { - return p ? d : new X(d); + return n ? d : new X(d); } } - if (Za = (H = H && H.get(m[G + 1])) && H.length) { + if (Ya = (H = H && H.get(l[G + 1])) && H.length) { z++, w.push(H); } else if (!k) { - return p ? d : new X(d); + return n ? d : new X(d); } } if (z) { - r = za(r, w); - F = r.length; + v = za(v, w); + F = v.length; if (!F && !k) { - return p ? r : new X(r); + return n ? v : new X(v); } z--; } } if (F) { - f[t] = E, d.push(r), t++; - } else if (1 === l.length) { - return p ? d : new X(d); + f[m] = E, d.push(v), m++; + } else if (1 === h.length) { + return n ? d : new X(d); } } if (u) { const y = this; - return Promise.all(u).then(function(r) { - return r.length ? y.search(a, c, b, r) : r; + return Promise.all(u).then(function(v) { + return v.length ? y.search(a, c, b, v) : v; }); } - if (!t) { - return p ? d : new X(d); + if (!m) { + return n ? d : new X(d); } - if (v && (!g || !this.store)) { + if (p && (!g || !this.store)) { return d[0]; } u = []; - for (let y = 0, r; y < f.length; y++) { - r = d[y]; - g && r.length && !r[0].doc && (r = W.call(this, r)); - if (v) { - return p ? r : new X(r); + for (t = 0; t < f.length; t++) { + e = d[t]; + if (p) { + return n ? e : new X(e); } - d[y] = {field:f[y], result:r}; + d[t] = {field:f[t], result:e}; } - return h ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; + return q ? Ia(d, c) : r ? Ja(d, a, this.index, this.field, this.C, r) : d; }; -function Ka(a, c, b, e, d, f) { - let g, h, k; - for (let m = 0, n, t, p, q, v; m < a.length; m++) { - n = a[m].result; - t = a[m].field; - q = b.get(t); - p = q.encoder; - k = q.tokenize; - v = d[e.indexOf(t)]; - p !== g && (g = p, h = g.encode(c)); - for (let u = 0; u < n.length; u++) { +function Ja(a, c, b, e, d, f) { + let g, k, h; + for (let m = 0, n, r, p, q; m < a.length; m++) { + let t = a[m].result; + n = a[m].field; + p = b.get(n); + r = p.encoder; + h = p.tokenize; + q = d[e.indexOf(n)]; + r !== g && (g = r, k = g.encode(c)); + for (let u = 0; u < t.length; u++) { let w = ""; - var l = J(n[u].doc, v); + var l = J(t[u].doc, q); let z = g.encode(l); l = l.split(g.split); - for (let y = 0, r, E; y < z.length; y++) { - r = z[y]; + for (let y = 0, v, E; y < z.length; y++) { + v = z[y]; E = l[y]; let F; - for (let A = 0, G; A < h.length; A++) { - if (G = h[A], "strict" === k) { - if (r === G) { + for (let A = 0, G; A < k.length; A++) { + if (G = k[A], "strict" === h) { + if (v === G) { w += (w ? " " : "") + f.replace("$1", E); F = !0; break; } } else { - const H = r.indexOf(G); + const H = v.indexOf(G); if (-1 < H) { w += (w ? " " : "") + E.substring(0, H) + f.replace("$1", E.substring(H, G.length)) + E.substring(H + G.length); F = !0; @@ -1135,53 +1153,42 @@ function Ka(a, c, b, e, d, f) { } F || (w += (w ? " " : "") + l[y]); } - n[u].highlight = w; + t[u].highlight = w; } } return a; } -function Ja(a, c) { +function Ia(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = e[k]) { + for (let k = 0, h, l, m; k < g.length; k++) { + if (l = g[k], "object" !== typeof l && (l = {id:l}), h = l.id, m = e[h]) { m.push(f.field); } else { if (b.length === c) { return b; } - l.field = e[k] = [f.field]; + l.field = e[h] = [f.field]; b.push(l); } } } return b; } -function Ia(a, c, b, e, d) { - let f = this.tag.get(a); - if (!f) { +function Ha(a, c, b, e) { + let d = this.tag.get(a); + if (!d) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if ((a = (d = d && d.get(c)) && d.length - e) && 0 < a) { if (a > b || e) { - f = f.slice(e, e + b); + d = d.slice(e, e + b); } - d && (f = W.call(this, f)); - return f; + return d; } } -function W(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 V(a) { if (!this || this.constructor !== V) { return new V(a); @@ -1191,7 +1198,7 @@ function W(a) { this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && La(b, this.J) || "id"; + this.key = (b = c.key || c.id) && Ka(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); @@ -1202,13 +1209,13 @@ function W(a) { let e = c.index || c.field || c; D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Ka(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = Ka(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1224,14 +1231,14 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = Ka(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function La(a, c) { +function Ka(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1299,14 +1306,14 @@ x.set = function(a, c) { this.store.set(a, c); return this; }; -x.searchCache = Ma; +x.searchCache = La; x.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const h = this; + const k = this; return c.then(function() { - return h.export(a, g, b + 1); + return k.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -1360,7 +1367,7 @@ x.import = function(a, c) { } }; ja(V.prototype); -function Ma(a, c, b) { +function La(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let e = this.cache.get(a); @@ -1401,31 +1408,31 @@ Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Na = {normalize:function(a) { +const Ma = {normalize:function(a) { return a.toLowerCase(); }}; -const Oa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -const Pa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Ra = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const Na = 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 Oa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Pa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const Qa = {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 Ra = /[\x00-\x7F]+/g; const Sa = /[\x00-\x7F]+/g; const Ta = /[\x00-\x7F]+/g; -const Ua = /[\x00-\x7F]+/g; -var Va = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Na, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Oa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Oa, matcher:Pa, replacer:Qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +var Ua = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Ma, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Na}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Na, matcher:Oa, replacer:Pa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Na, replacer:Pa.concat([/(?!^)[aeo]/g, ""]), matcher:Oa}, 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 = Ra[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Qa[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Sa, " "); + return ("" + a).replace(Ra, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ta, ""); + return ("" + a).replace(Sa, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ua, " "); + return ("" + a).replace(Ta, " "); }}}; -const Wa = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +const Va = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1433,48 +1440,48 @@ O.prototype.add = function(a, c, b, e) { } c = this.encoder.encode(c); if (e = c.length) { - const l = C(), m = C(), n = this.depth, t = this.resolution; + const l = C(), m = C(), n = this.depth, r = this.resolution; for (let p = 0; p < e; p++) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Xa(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Wa(r, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let v = 0, u; v < d; v++) { - for (f = d; f > v; f--) { - g = q.substring(v, f); - u = this.rtl ? d - 1 - v : v; - var h = this.score ? this.score(c, q, p, g, u) : Xa(t, e, p, d, u); - Z(this, m, g, h, a, b); + for (let t = 0, u; t < d; t++) { + for (f = d; f > t; f--) { + g = q.substring(t, f); + u = this.rtl ? d - 1 - t : t; + var k = this.score ? this.score(c, q, p, g, u) : Wa(r, e, p, d, u); + Z(this, m, g, k, a, b); } } break; } case "reverse": if (1 < d) { - for (h = d - 1; 0 < h; h--) { - g = q[this.rtl ? d - 1 - h : h] + g; - var k = this.score ? this.score(c, q, p, g, h) : Xa(t, e, p, d, h); - Z(this, m, g, k, a, b); + for (k = d - 1; 0 < k; k--) { + g = q[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, q, p, g, k) : Wa(r, e, p, d, k); + Z(this, m, g, h, a, b); } g = ""; } case "forward": if (1 < d) { - for (h = 0; h < d; h++) { - g += q[this.rtl ? d - 1 - h : h], Z(this, m, g, f, a, b); + for (k = 0; k < d; k++) { + g += q[this.rtl ? d - 1 - k : k], Z(this, m, g, f, a, b); } break; } default: if (Z(this, m, q, f, a, b), n && 1 < e && p < e - 1) { - for (d = C(), g = this.S, f = q, h = Math.min(n + 1, this.rtl ? p + 1 : e - p), d[f] = 1, k = 1; k < h; k++) { - if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { + for (d = C(), g = this.S, f = q, k = Math.min(n + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { + if ((q = c[this.rtl ? e - 1 - p - h : p + h]) && !d[q]) { d[q] = 1; - const v = this.score ? this.score(c, f, p, q, k - 1) : Xa(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; - Z(this, l, u ? f : q, v, a, b, u ? q : f); + const t = this.score ? this.score(c, f, p, q, h - 1) : Wa(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; + Z(this, l, u ? f : q, t, a, b, u ? q : f); } } } @@ -1487,12 +1494,12 @@ O.prototype.add = function(a, c, b, e) { return this; }; function Z(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); + let k = g ? a.ctx : a.map, h; + if (!c[b] || g && !(h = c[b])[g]) { + g ? (c = h || (c[b] = C()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); } } -function Xa(a, c, b, e, d) { +function Wa(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;O.prototype.search = function(a, c, b) { @@ -1504,35 +1511,35 @@ function Xa(a, c, b, e, d) { d = b.offset || 0; var f = b.context; var g = b.suggest; - var h = !0; - var k = b.resolution; + var k = !0; + var h = b.resolution; } else { - h = !0; + k = !0; } a = this.encoder.encode(a); b = a.length; - c = c || (h ? 100 : 0); + c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Ya(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; + return g = c, (c = Xa(this, a[0], "")) && c.length ? W.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Ya(this, a[0], a[1])) && c.length ? Aa.call(this, c, g, d) : []; + return g = c, (c = Xa(this, a[0], a[1])) && c.length ? W.call(this, c, g, d) : []; } - h = C(); + k = C(); let l = 0; if (1 < b && f) { var m = a[0]; l = 1; } - k || 0 === k || (k = m ? this.S : this.resolution); - for (let q, v; l < b; l++) { - if ((v = a[l]) && !h[v]) { - h[v] = 1; - q = Ya(this, v, m); + h || 0 === h || (h = m ? this.S : this.resolution); + for (let q, t; l < b; l++) { + if ((t = a[l]) && !k[t]) { + k[t] = 1; + q = Xa(this, t, m); a: { f = q; - var n = e, t = g, p = k; + var n = e, r = g, p = h; let u = []; if (f && f.length) { if (f.length <= p) { @@ -1551,31 +1558,31 @@ function Xa(a, c, b, e, d) { break a; } } - q = t ? void 0 : u; + q = r ? void 0 : u; } if (q) { e = q; break; } - m && (g && q && e.length || (m = v)); + m && (g && q && e.length || (m = t)); } - g && m && l === b - 1 && !e.length && (k = this.resolution, m = "", l = -1, h = C()); + g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = C()); } a: { a = e; e = a.length; m = a; if (1 < e) { - m = xa(a, k, c, d, g); + m = xa(a, h, c, d, g); } else if (1 === e) { - g = Aa.call(null, a[0], c, d); + g = W.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Ya(a, c, b) { +function Xa(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); @@ -1596,14 +1603,14 @@ function Ya(a, c, b) { } } } else { - $a(this.map, a), this.depth && $a(this.ctx, a); + Za(this.map, a), this.depth && Za(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function $a(a, c) { +function Za(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1618,7 +1625,7 @@ function $a(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = $a(e[1], c); + const d = e[0], f = Za(e[1], c); f ? b += f : a.delete(d); } } @@ -1630,12 +1637,12 @@ function $a(a, c) { } if (a) { var b = D(a) ? a : a.preset; - b && (Wa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Wa[b], a)); + b && (Va[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Va[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Ua[a.encoder] : a.encode || a.encoder || Ma; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; @@ -1671,7 +1678,7 @@ x.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 ab(a) { +function $a(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1679,7 +1686,7 @@ function ab(a) { } } else { for (const b of a.entries()) { - const e = b[0], d = ab(b[1]); + const e = b[0], d = $a(b[1]); d ? c += d : a.delete(e); } } @@ -1689,11 +1696,11 @@ x.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - ab(this.map); - this.depth && ab(this.ctx); + $a(this.map); + this.depth && $a(this.ctx); return this; }; -x.searchCache = Ma; +x.searchCache = La; x.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { @@ -1745,19 +1752,20 @@ x.serialize = function(a = !0) { b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let h = ua(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + d + '",' + h + "]"; - e += (e ? "," : "") + h; + let k = ua(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; ja(O.prototype); -const bb = {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, cb = self; -let db; -(db = cb.define) && db.amd ? db([], function() { - return bb; -}) : "object" === typeof cb.exports ? cb.exports = bb : cb.FlexSearch = bb; +C(); +const ab = {Index:O, Charset:Ua, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, bb = "undefined" !== typeof global ? global : self; +let cb; +(cb = bb.define) && cb.amd ? cb([], function() { + return ab; +}) : "object" === typeof bb.exports ? bb.exports = ab : bb.FlexSearch = ab; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 761e3f8..b8aa8c2 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.133 (Bundle) + * FlexSearch.js v0.8.135 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} +(function(self){'use strict';var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(k){return a(b(k))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} function H(a){return"object"===typeof a}function I(a,c){if(D(c))a=a[c];else for(let b=0;a&&ba.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&L(this);return this}; x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; x.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ha?a.normalize("NFKD").replace(ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==g&&this.filter&& -g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ka,la,Q;function ma(){ka=Q=0} +[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,k;fthis.stemmer.get(h)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&dthis.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ka,la,Q;function ma(){ka=Q=0} function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);ka?Q||(Q=Date.now()-la>=this.priority*this.priority*3):(ka=setTimeout(ma,0),la=Date.now());if(Q){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let R=0; -function S(a={}){function c(g){function h(k){k=k.data||k;const l=k.id,m=l&&d.h[l];m&&(m(k.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++R]=function(){k(d);1E9b||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?W.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; -function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; -function Ea(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Fa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Aa(this,"and",arguments);return Ca.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; +function Ca(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(l){a=[];for(let m=0,n;ma.length)this.result=a[0];else{if(c=aa(a)){this.result=xa(a,c,b,e,g);var k;f?d?k=this.result:k=this.result:k=this;return k}this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Aa(this,"xor",arguments);return Da.call(this,a,c,b,e,d,f,g)}; +function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(l){a=[];for(let m=0,n;ma.length)this.result=a[0];else{this.result=Ea.call(this,a,b,e,f,this.h);if(f){var k;d?k=this.result:k=this.result;c=k}else c=this;return c}else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Ea(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);return a}};function V(a){if(!this||this.constructor!==V)return new V(a);const c=a.document||a.doc||a;var b;this.C=[];this.field=[];this.J=[];this.key=(b=c.key||c.id)&&Ka(b,this.J)||"id";this.reg=(this.fastupdate=!!a.fastupdate)?new Map:new Set;this.A=(b=c.store||null)&&b&&!0!==b&&[];this.store=b&&new Map;this.cache=(b=a.cache||null)&&new Y(b);a.cache=!1;this.priority=a.priority||4;b=new Map;let e=c.index||c.field||c;D(e)&&(e=[e]);for(let d=0,f,g;dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};const Oa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Pa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;const Ua=/[\x00-\x7F]+/g;var Va={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Oa,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bv;f--){g=q.substring(v,f);u=this.rtl?d-1-v:v;var h=this.score?this.score(c,q,p,g,u):Xa(t,e,p,d,u); -Z(this,m,g,h,a,b)}break}case "reverse":if(1g?0:1),e,p,h-1,k-1),u=this.bidirectional&& -q>f;Z(this,l,u?f:q,v,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=C()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Xa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else $a(this.map,a),this.depth&&$a(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function $a(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Ma={normalize:function(a){return a.toLowerCase()}};const Na=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 Oa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Pa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Qa={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 Ra=/[\x00-\x7F]+/g;const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;var Ua={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Ma,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Na},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Na,matcher:Oa,replacer:Pa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Na,replacer:Pa.concat([/(?!^)[aeo]/g,""]),matcher:Oa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bt;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Wa(r,e,p,d,u); +Z(this,m,g,k,a,b)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),u=this.bidirectional&& +q>f;Z(this,l,u?f:q,t,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Wa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else Za(this.map,a),this.depth&&Za(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Za(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function ab(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb.add(a,c)):this.add(a,c)};function $a(a){let c=0;if(a.constructor===Array)for(let b=0,e;b this.stemmer.get(k)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.D + ")$")), d = g, g = g.replace(this.N, h => this.stemmer.get(h)), d !== g && this.filter && g.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(g) : this.filter.has(g)) && (g = "")); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let k = 0, l = "", m, n; k < g.length; k++) { - m = g.charAt(k), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let h = 0, l = "", m, n; h < g.length; h++) { + m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); } g = d; } - this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, k => this.matcher.get(k))); + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, h => this.matcher.get(h))); if (g && this.replacer) { for (d = 0; g && d < this.replacer.length; d += 2) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.L && (this.G.set(h, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); + this.cache && k.length <= this.L && (this.G.set(k, g), this.G.size > this.R && (this.G.clear(), this.L = this.L / 1.1 | 0)); g && b.push(g); } } @@ -331,19 +331,19 @@ function P(a) { ;let R = 0; function S(a = {}) { function c(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && d.h[l]; - m && (m(k.msg), delete d.h[l]); + function k(h) { + h = h.data || h; + const l = h.id, m = l && d.h[l]; + m && (m(h.msg), delete d.h[l]); } this.worker = g; this.h = C(); if (this.worker) { - e ? this.worker.on("message", h) : this.worker.onmessage = h; + e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { + return new Promise(function(h) { d.h[++R] = function() { - k(d); + h(d); 1e9 < R && (R = 0); }; d.worker.postMessage({id:R, task:"init", factory:b, options:a}); @@ -439,18 +439,18 @@ function ta(a, c) { return c; } function U(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { return this.export(a, c, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; - return k.then(function() { - return U.call(l, a, c, b, h ? e : null, d, f, g + 1); + return h.then(function() { + return U.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return U.call(this, a, c, b, h ? e : null, d, f, g + 1); + return U.call(this, a, c, b, k ? e : null, d, f, g + 1); } function ua(a, c) { let b = ""; @@ -458,14 +458,14 @@ function ua(a, c) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, h; g < d.length; g++) { - h = d[g] || [""]; - let k = ""; - for (let l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === c ? '"' + h[l] + '"' : h[l]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === c ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; b += (b ? "," : "") + f; @@ -478,15 +478,15 @@ function ua(a, c) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.C[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); + for (let k = 0, h; k < this.field.length; k++) { + h = this.C[k]; + var e = this.index.get(this.field[k]); + if ("function" === typeof h) { + var d = h(c); d && e.add(a, d, !1, !0); } else { - if (d = k.I, !d || d(c)) { - k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), va(c, k, this.J, 0, e, a, k[0], b); + if (d = h.I, !d || d(c)) { + h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); } } } @@ -494,14 +494,14 @@ function ua(a, c) { for (e = 0; e < this.B.length; e++) { var f = this.B[e], g = this.T[e]; d = this.tag.get(g); - let h = C(); + let k = C(); if ("function" === typeof f) { if (f = f(c), !f) { continue; } } else { - const k = f.I; - if (k && !k(c)) { + const h = f.I; + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); @@ -509,8 +509,8 @@ function ua(a, c) { } if (d && f) { D(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + for (let h = 0, l, m; h < f.length; h++) { + l = f[h], k[l] || (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -518,11 +518,11 @@ function ua(a, c) { } } if (this.store && (!b || !this.store.has(a))) { - let h; + let k; if (this.A) { - h = C(); - for (let k = 0, l; k < this.A.length; k++) { - l = this.A[k]; + k = C(); + for (let h = 0, l; h < this.A.length; h++) { + l = this.A[h]; if ((b = l.I) && !b(c)) { continue; } @@ -534,13 +534,13 @@ function ua(a, c) { } l = [l.U]; } else if (D(l) || l.constructor === String) { - h[l] = c[l]; + k[l] = c[l]; continue; } - wa(c, h, l, 0, l[0], m); + wa(c, k, l, 0, l[0], m); } } - this.store.set(a, h || c); + this.store.set(a, k || c); } } return this; @@ -559,7 +559,7 @@ function wa(a, c, b, e, d, f) { } } } -function va(a, c, b, e, d, f, g, h) { +function va(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -571,27 +571,27 @@ function va(a, c, b, e, d, f, g, h) { } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - va(a, c, b, e, d, f, g, h); + va(a, c, b, e, d, f, g, k); } } else { - g = c[++e], va(a, c, b, e, d, f, g, h); + g = c[++e], va(a, c, b, e, d, f, g, k); } } } } ;function xa(a, c, b, e, d) { const f = a.length; - let g = [], h, k; - h = C(); - for (let l = 0, m, n, t, p; l < c; l++) { + let g = [], k, h; + k = C(); + for (let l = 0, m, n, r, p; l < c; l++) { for (let q = 0; q < f; q++) { - if (t = a[q], l < t.length && (m = t[l])) { - for (let v = 0; v < m.length; v++) { - if (n = m[v], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), p = g[k] || (g[k] = []), p.push(n), b && k === f - 1 && p.length - e === b) { + if (r = a[q], l < r.length && (m = r[l])) { + for (let t = 0; t < m.length; t++) { + if (n = m[t], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), p = g[h] || (g[h] = []), p.push(n), b && h === f - 1 && p.length - e === b) { return p; } } @@ -619,10 +619,10 @@ function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; - let h; - for (let k = g - 1; 0 <= k; k--) { - if (h = (g = a[k]) && g.length) { - for (let l = 0; l < h; l++) { + let k; + for (let h = g - 1; 0 <= h; h--) { + if (k = (g = a[h]) && g.length) { + for (let l = 0; l < k; l++) { if (f = g[l], !d[f]) { if (d[f] = 1, b) { b--; @@ -650,38 +650,37 @@ function za(a, c) { } return e; } -;function Aa(a, c, b, e) { +;function W(a, c, b) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } - let d = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { + let e = []; + for (let d = 0, f, g; d < a.length; d++) { + if ((f = a[d]) && (g = f.length)) { if (b) { - if (b >= h) { - b -= h; + if (b >= g) { + b -= g; continue; } - b < h && (g = c ? g.slice(b, b + c) : g.slice(b), h = g.length, b = 0); + b < g && (f = c ? f.slice(b, b + c) : f.slice(b), g = f.length, b = 0); } - h > c && (g = g.slice(0, c), h = c); - if (!d.length && h >= c) { - return e ? W.call(this, g) : g; + g > c && (f = f.slice(0, c), g = c); + if (!e.length && g >= c) { + return f; } - d.push(g); - c -= h; + e.push(f); + c -= g; if (!c) { break; } } } - d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? W.call(this, d) : d; + return e = 1 < e.length ? [].concat.apply([], e) : e[0]; } -;function Ba(a, c, b) { +;function Aa(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -692,54 +691,54 @@ function za(a, c) { return a[c].apply(a, e); } e = []; - let d = [], f = 0, g = 0, h, k, l; + let d = [], f = 0, g = 0, k, h, l; for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { - let t; + let r; if (n.constructor === X) { - t = n.result; + r = n.result; } else if (n.constructor === Array) { - t = n; + r = n; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { - n.resolve = !1, n.enrich = !1, t = n.index.search(n).result, n.resolve = k, n.enrich = h; + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { + n.resolve = !1, n.enrich = !1, r = n.index.search(n).result, n.resolve = h, n.enrich = k; } else if (n.and) { - t = a.and(n.and); + r = a.and(n.and); } else if (n.or) { - t = a.or(n.or); + r = a.or(n.or); } else if (n.xor) { - t = a.xor(n.xor); + r = a.xor(n.xor); } else if (n.not) { - t = a.not(n.not); + r = a.not(n.not); } else { continue; } } - if (t.then) { - d.push(t); - } else if (t.length) { - e[m] = t; + if (r.then) { + d.push(r); + } else if (r.length) { + e[m] = r; } else if (!l && ("and" === c || "xor" === c)) { e = []; break; } } } - return {O:e, P:d, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; + return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } ;X.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); - return Ca.call(this, a, c, b, e, d, f); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Aa(this, "or", arguments); + return Ba.call(this, a, c, b, e, d, f); }; -function Ca(a, c, b, e, d, f) { +function Ba(a, c, b, e, d, f) { if (c.length) { const g = this; - return Promise.all(c).then(function(h) { + return Promise.all(c).then(function(k) { a = []; - for (let k = 0, l; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); + for (let h = 0, l; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } - return Ca.call(g, a, [], b, e, d, f); + return Ba.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 = ya(a, b, e), e = 0)); @@ -752,20 +751,20 @@ function Ca(a, c, b, e, d, f) { f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:h, offset:k, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); - return Da.call(this, f, g, h, k, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Aa(this, "and", arguments); + return Ca.call(this, f, g, k, h, l, m, n); } return d ? this.resolve(c, b, e) : this; }; -function Da(a, c, b, e, d, f, g) { +function Ca(a, c, b, e, d, f, g) { if (c.length) { const h = this; - return Promise.all(c).then(function(k) { + return Promise.all(c).then(function(l) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let m = 0, n; m < l.length; m++) { + (n = l[m]).length && (a[m] = n); } - return Da.call(h, a, [], b, e, d, f, g); + return Ca.call(h, a, [], b, e, d, f, g); }); } if (a.length) { @@ -773,7 +772,10 @@ function Da(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = xa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; + this.result = xa(a, c, b, e, g); + var k; + f ? d ? k = this.result : k = this.result : k = this; + return k; } this.result = []; } @@ -783,50 +785,58 @@ function Da(a, c, b, e, d, f, g) { return f ? this.resolve(b, e, d) : this; } ;X.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); - return Ea.call(this, a, c, b, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "xor", arguments); + return Da.call(this, a, c, b, e, d, f, g); }; -function Ea(a, c, b, e, d, f, g) { +function Da(a, c, b, e, d, f, g) { if (c.length) { const h = this; - return Promise.all(c).then(function(k) { + return Promise.all(c).then(function(l) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let m = 0, n; m < l.length; m++) { + (n = l[m]).length && (a[m] = n); } - return Ea.call(h, a, [], b, e, d, f, g); + return Da.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 = Fa.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; + this.result = Ea.call(this, a, b, e, f, this.h); + if (f) { + var k; + d ? k = this.result : k = this.result; + c = k; + } else { + c = this; + } + return c; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function Fa(a, c, b, e, d) { +function Ea(a, c, b, e, d) { const f = [], g = C(); - let h = 0; - for (let k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); + let k = 0; + for (let h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); for (let m = 0, n; m < l.length; m++) { if (n = l[m]) { - for (let t = 0, p; t < n.length; t++) { - p = n[t], g[p] = g[p] ? 2 : 1; + for (let r = 0, p; r < n.length; r++) { + p = n[r], 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 h = 0, l, m = 0; h < k; h++) { + for (let n = 0, r; n < a.length; n++) { + if (r = a[n]) { + if (l = r[h]) { for (let p = 0, q; p < l.length; p++) { if (q = l[p], 1 === g[q]) { if (b) { @@ -837,9 +847,9 @@ function Fa(a, c, b, e, d) { return f; } } else { - const v = k + (n ? d : 0); - f[v] || (f[v] = []); - f[v].push(q); + const t = h + (n ? d : 0); + f[t] || (f[t] = []); + f[t].push(q); if (++m === c) { return f; } @@ -854,34 +864,41 @@ function Fa(a, c, b, e, d) { return f; } ;X.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); - return Ga.call(this, a, c, b, e, d, f, g); + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Aa(this, "not", arguments); + return Fa.call(this, a, c, b, e, d, f, g); }; -function Ga(a, c, b, e, d, f, g) { +function Fa(a, c, b, e, d, f, g) { if (c.length) { const h = this; - return Promise.all(c).then(function(k) { + return Promise.all(c).then(function(l) { a = []; - for (let l = 0, m; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (let m = 0, n; m < l.length; m++) { + (n = l[m]).length && (a[m] = n); } - return Ga.call(h, a, [], b, e, d, f, g); + return Fa.call(h, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ha.call(this, a, b, e, f); + this.result = Ga.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? W.call(this.index, this.result) : this.result : this; + if (f) { + var k; + d ? k = this.result : k = this.result; + c = k; + } else { + c = this; + } + return c; } -function Ha(a, c, b, e) { +function Ga(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); - for (let f = 0, g, h = 0; f < this.result.length; f++) { + for (let f = 0, g, k = 0; f < this.result.length; f++) { if (g = this.result[f]) { - for (let k = 0, l; k < g.length; k++) { - if (l = g[k], !a.has(l)) { + for (let h = 0, l; h < g.length; h++) { + if (l = g[h], !a.has(l)) { if (b) { b--; } else { @@ -890,7 +907,7 @@ function Ha(a, c, b, e) { return d; } } else { - if (d[f] || (d[f] = []), d[f].push(l), ++h === c) { + if (d[f] || (d[f] = []), d[f].push(l), ++k === c) { return d; } } @@ -947,52 +964,54 @@ X.prototype.boost = function(a) { this.h += a; return this; }; -X.prototype.resolve = function(a, c, b) { - const e = this.result, d = this.index; +X.prototype.resolve = function(a, c) { + const b = this.result, e = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; + return b.length ? ("object" === typeof a && (c = a.offset, a = a.limit), W.call(e, b, a || 100, c)) : b; }; C(); V.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, n, t = 0, p = !0, q; + let g; + let k, h, l; + let m = 0, n = !0, r; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; - var v = b.pluck; - h = b.merge; - l = v || b.field || (l = b.index) && (l.index ? null : l); - m = this.tag && b.tag; + var p = b.pluck; + var q = b.merge; + h = p || b.field || (h = b.index) && (h.index ? null : h); + l = 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 })"); - q = (g = this.store && b.enrich && p) && b.highlight; + n = !0; + this.store && b.enrich && !n && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + r = (g = this.store && b.enrich && n) && b.highlight; c = b.limit || c; - n = b.offset || 0; + var t = b.offset || 0; c || (c = 100); - if (m) { - m.constructor !== Array && (m = [m]); + if (l) { + l.constructor !== Array && (l = [l]); var u = []; - for (let y = 0, r; y < m.length; y++) { - r = m[y]; - if (D(r)) { + for (let y = 0, v; y < l.length; y++) { + v = l[y]; + if (D(v)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (r.field && r.tag) { - var w = r.tag; + if (v.field && v.tag) { + var w = v.tag; if (w.constructor === Array) { for (var z = 0; z < w.length; z++) { - u.push(r.field, w[z]); + u.push(v.field, w[z]); } } else { - u.push(r.field, w); + u.push(v.field, w); } } else { - w = Object.keys(r); + w = Object.keys(v); for (let E = 0, F, A; E < w.length; E++) { - if (F = w[E], A = r[F], A.constructor === Array) { + if (F = w[E], A = v[F], A.constructor === Array) { for (z = 0; z < A.length; z++) { u.push(F, A[z]); } @@ -1005,126 +1024,125 @@ V.prototype.search = function(a, c, b, e) { if (!u.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - m = u; + l = u; if (!a) { - e = []; + f = []; if (u.length) { - for (f = 0; f < u.length; f += 2) { - v = Ia.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:v}); + for (p = 0; p < u.length; p += 2) { + q = Ha.call(this, u[p], u[p + 1], c, t), d.push({field:u[p], tag:u[p + 1], result:q}); } } - return e.length ? Promise.all(e).then(function(y) { - for (let r = 0; r < y.length; r++) { - d[r].result = y[r]; + return f.length ? Promise.all(f).then(function(y) { + for (let v = 0; v < y.length; v++) { + d[v].result = y[v]; } return d; }) : d; } } - l && l.constructor !== Array && (l = [l]); + h && h.constructor !== Array && (h = [h]); } - l || (l = this.field); + h || (h = this.field); u = !e && (this.worker || this.db) && []; - for (let y = 0, r, E, F; y < l.length; y++) { - E = l[y]; + for (let y = 0, v, E, F; y < h.length; y++) { + E = h[y]; let A; - D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, k = A.suggest || k, g = this.store && (A.enrich || g)); + D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, t = A.offset || t, k = A.suggest || k, g = this.store && (A.enrich || g)); if (e) { - r = e[y]; + v = e[y]; } else { - if (w = A || b, z = this.index.get(E), m && (w.enrich = !1), u) { + if (w = A || b, z = this.index.get(E), l && (w.enrich = !1), u) { u[y] = z.search(a, c, w); w && g && (w.enrich = g); continue; } else { - r = z.search(a, c, w), w && g && (w.enrich = g); + v = z.search(a, c, w), w && g && (w.enrich = g); } } - F = r && (p ? r.length : r.result.length); - if (m && F) { + F = v && (n ? v.length : v.result.length); + if (l && F) { w = []; z = 0; - for (let G = 0, H, Wa; G < m.length; G += 2) { - H = this.tag.get(m[G]); + for (let G = 0, H, Va; G < l.length; G += 2) { + H = this.tag.get(l[G]); if (!H) { - if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { + if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), k) { continue; } else { - return p ? d : new X(d); + return n ? d : new X(d); } } - if (Wa = (H = H && H.get(m[G + 1])) && H.length) { + if (Va = (H = H && H.get(l[G + 1])) && H.length) { z++, w.push(H); } else if (!k) { - return p ? d : new X(d); + return n ? d : new X(d); } } if (z) { - r = za(r, w); - F = r.length; + v = za(v, w); + F = v.length; if (!F && !k) { - return p ? r : new X(r); + return n ? v : new X(v); } z--; } } if (F) { - f[t] = E, d.push(r), t++; - } else if (1 === l.length) { - return p ? d : new X(d); + f[m] = E, d.push(v), m++; + } else if (1 === h.length) { + return n ? d : new X(d); } } if (u) { const y = this; - return Promise.all(u).then(function(r) { - return r.length ? y.search(a, c, b, r) : r; + return Promise.all(u).then(function(v) { + return v.length ? y.search(a, c, b, v) : v; }); } - if (!t) { - return p ? d : new X(d); + if (!m) { + return n ? d : new X(d); } - if (v && (!g || !this.store)) { + if (p && (!g || !this.store)) { return d[0]; } u = []; - for (let y = 0, r; y < f.length; y++) { - r = d[y]; - g && r.length && !r[0].doc && (r = W.call(this, r)); - if (v) { - return p ? r : new X(r); + for (t = 0; t < f.length; t++) { + e = d[t]; + if (p) { + return n ? e : new X(e); } - d[y] = {field:f[y], result:r}; + d[t] = {field:f[t], result:e}; } - return h ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; + return q ? Ia(d, c) : r ? Ja(d, a, this.index, this.field, this.C, r) : d; }; -function Ka(a, c, b, e, d, f) { - let g, h, k; - for (let m = 0, n, t, p, q, v; m < a.length; m++) { - n = a[m].result; - t = a[m].field; - q = b.get(t); - p = q.encoder; - k = q.tokenize; - v = d[e.indexOf(t)]; - p !== g && (g = p, h = g.encode(c)); - for (let u = 0; u < n.length; u++) { +function Ja(a, c, b, e, d, f) { + let g, k, h; + for (let m = 0, n, r, p, q; m < a.length; m++) { + let t = a[m].result; + n = a[m].field; + p = b.get(n); + r = p.encoder; + h = p.tokenize; + q = d[e.indexOf(n)]; + r !== g && (g = r, k = g.encode(c)); + for (let u = 0; u < t.length; u++) { let w = ""; - var l = J(n[u].doc, v); + var l = J(t[u].doc, q); let z = g.encode(l); l = l.split(g.split); - for (let y = 0, r, E; y < z.length; y++) { - r = z[y]; + for (let y = 0, v, E; y < z.length; y++) { + v = z[y]; E = l[y]; let F; - for (let A = 0, G; A < h.length; A++) { - if (G = h[A], "strict" === k) { - if (r === G) { + for (let A = 0, G; A < k.length; A++) { + if (G = k[A], "strict" === h) { + if (v === G) { w += (w ? " " : "") + f.replace("$1", E); F = !0; break; } } else { - const H = r.indexOf(G); + const H = v.indexOf(G); if (-1 < H) { w += (w ? " " : "") + E.substring(0, H) + f.replace("$1", E.substring(H, G.length)) + E.substring(H + G.length); F = !0; @@ -1134,53 +1152,42 @@ function Ka(a, c, b, e, d, f) { } F || (w += (w ? " " : "") + l[y]); } - n[u].highlight = w; + t[u].highlight = w; } } return a; } -function Ja(a, c) { +function Ia(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], "object" !== typeof l && (l = {id:l}), k = l.id, m = e[k]) { + for (let k = 0, h, l, m; k < g.length; k++) { + if (l = g[k], "object" !== typeof l && (l = {id:l}), h = l.id, m = e[h]) { m.push(f.field); } else { if (b.length === c) { return b; } - l.field = e[k] = [f.field]; + l.field = e[h] = [f.field]; b.push(l); } } } return b; } -function Ia(a, c, b, e, d) { - let f = this.tag.get(a); - if (!f) { +function Ha(a, c, b, e) { + let d = this.tag.get(a); + if (!d) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if ((a = (d = d && d.get(c)) && d.length - e) && 0 < a) { if (a > b || e) { - f = f.slice(e, e + b); + d = d.slice(e, e + b); } - d && (f = W.call(this, f)); - return f; + return d; } } -function W(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 V(a) { if (!this || this.constructor !== V) { return new V(a); @@ -1190,7 +1197,7 @@ function W(a) { this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && La(b, this.J) || "id"; + this.key = (b = c.key || c.id) && Ka(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); @@ -1201,13 +1208,13 @@ function W(a) { let e = c.index || c.field || c; D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Ka(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = Ka(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1223,14 +1230,14 @@ function W(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = Ka(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function La(a, c) { +function Ka(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1298,14 +1305,14 @@ x.set = function(a, c) { this.store.set(a, c); return this; }; -x.searchCache = Ma; +x.searchCache = La; x.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const h = this; + const k = this; return c.then(function() { - return h.export(a, g, b + 1); + return k.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -1359,7 +1366,7 @@ x.import = function(a, c) { } }; ja(V.prototype); -function Ma(a, c, b) { +function La(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Y()); let e = this.cache.get(a); @@ -1400,31 +1407,31 @@ Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Na = {normalize:function(a) { +const Ma = {normalize:function(a) { return a.toLowerCase(); }}; -const Oa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -const Pa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const Ra = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const Na = 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 Oa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Pa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const Qa = {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 Ra = /[\x00-\x7F]+/g; const Sa = /[\x00-\x7F]+/g; const Ta = /[\x00-\x7F]+/g; -const Ua = /[\x00-\x7F]+/g; -var Va = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Na, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Oa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Oa, matcher:Pa, replacer:Qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +var Ua = {LatinExact:{split:/\s+/, normalize:!1}, LatinDefault:Ma, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Na}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Na, matcher:Oa, replacer:Pa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Na, replacer:Pa.concat([/(?!^)[aeo]/g, ""]), matcher:Oa}, 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 = Ra[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Qa[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Qa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Sa, " "); + return ("" + a).replace(Ra, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ta, ""); + return ("" + a).replace(Sa, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ua, " "); + return ("" + a).replace(Ta, " "); }}}; -const Xa = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +const Wa = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { @@ -1432,48 +1439,48 @@ O.prototype.add = function(a, c, b, e) { } c = this.encoder.encode(c); if (e = c.length) { - const l = C(), m = C(), n = this.depth, t = this.resolution; + const l = C(), m = C(), n = this.depth, r = this.resolution; for (let p = 0; p < e; p++) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Ya(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Xa(r, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { - for (let v = 0, u; v < d; v++) { - for (f = d; f > v; f--) { - g = q.substring(v, f); - u = this.rtl ? d - 1 - v : v; - var h = this.score ? this.score(c, q, p, g, u) : Ya(t, e, p, d, u); - Z(this, m, g, h, a, b); + for (let t = 0, u; t < d; t++) { + for (f = d; f > t; f--) { + g = q.substring(t, f); + u = this.rtl ? d - 1 - t : t; + var k = this.score ? this.score(c, q, p, g, u) : Xa(r, e, p, d, u); + Z(this, m, g, k, a, b); } } break; } case "reverse": if (1 < d) { - for (h = d - 1; 0 < h; h--) { - g = q[this.rtl ? d - 1 - h : h] + g; - var k = this.score ? this.score(c, q, p, g, h) : Ya(t, e, p, d, h); - Z(this, m, g, k, a, b); + for (k = d - 1; 0 < k; k--) { + g = q[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, q, p, g, k) : Xa(r, e, p, d, k); + Z(this, m, g, h, a, b); } g = ""; } case "forward": if (1 < d) { - for (h = 0; h < d; h++) { - g += q[this.rtl ? d - 1 - h : h], Z(this, m, g, f, a, b); + for (k = 0; k < d; k++) { + g += q[this.rtl ? d - 1 - k : k], Z(this, m, g, f, a, b); } break; } default: if (Z(this, m, q, f, a, b), n && 1 < e && p < e - 1) { - for (d = C(), g = this.S, f = q, h = Math.min(n + 1, this.rtl ? p + 1 : e - p), d[f] = 1, k = 1; k < h; k++) { - if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { + for (d = C(), g = this.S, f = q, k = Math.min(n + 1, this.rtl ? p + 1 : e - p), d[f] = 1, h = 1; h < k; h++) { + if ((q = c[this.rtl ? e - 1 - p - h : p + h]) && !d[q]) { d[q] = 1; - const v = this.score ? this.score(c, f, p, q, k - 1) : Ya(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), u = this.bidirectional && q > f; - Z(this, l, u ? f : q, v, a, b, u ? q : f); + const t = this.score ? this.score(c, f, p, q, h - 1) : Xa(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; + Z(this, l, u ? f : q, t, a, b, u ? q : f); } } } @@ -1486,12 +1493,12 @@ O.prototype.add = function(a, c, b, e) { return this; }; function Z(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); + let k = g ? a.ctx : a.map, h; + if (!c[b] || g && !(h = c[b])[g]) { + g ? (c = h || (c[b] = C()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); } } -function Ya(a, c, b, e, d) { +function Xa(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;O.prototype.search = function(a, c, b) { @@ -1503,35 +1510,35 @@ function Ya(a, c, b, e, d) { d = b.offset || 0; var f = b.context; var g = b.suggest; - var h = !0; - var k = b.resolution; + var k = !0; + var h = b.resolution; } else { - h = !0; + k = !0; } a = this.encoder.encode(a); b = a.length; - c = c || (h ? 100 : 0); + c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Za(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; + return g = c, (c = Ya(this, a[0], "")) && c.length ? W.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Za(this, a[0], a[1])) && c.length ? Aa.call(this, c, g, d) : []; + return g = c, (c = Ya(this, a[0], a[1])) && c.length ? W.call(this, c, g, d) : []; } - h = C(); + k = C(); let l = 0; if (1 < b && f) { var m = a[0]; l = 1; } - k || 0 === k || (k = m ? this.S : this.resolution); - for (let q, v; l < b; l++) { - if ((v = a[l]) && !h[v]) { - h[v] = 1; - q = Za(this, v, m); + h || 0 === h || (h = m ? this.S : this.resolution); + for (let q, t; l < b; l++) { + if ((t = a[l]) && !k[t]) { + k[t] = 1; + q = Ya(this, t, m); a: { f = q; - var n = e, t = g, p = k; + var n = e, r = g, p = h; let u = []; if (f && f.length) { if (f.length <= p) { @@ -1550,31 +1557,31 @@ function Ya(a, c, b, e, d) { break a; } } - q = t ? void 0 : u; + q = r ? void 0 : u; } if (q) { e = q; break; } - m && (g && q && e.length || (m = v)); + m && (g && q && e.length || (m = t)); } - g && m && l === b - 1 && !e.length && (k = this.resolution, m = "", l = -1, h = C()); + g && m && l === b - 1 && !e.length && (h = this.resolution, m = "", l = -1, k = C()); } a: { a = e; e = a.length; m = a; if (1 < e) { - m = xa(a, k, c, d, g); + m = xa(a, h, c, d, g); } else if (1 === e) { - g = Aa.call(null, a[0], c, d); + g = W.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Za(a, c, b) { +function Ya(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); @@ -1595,14 +1602,14 @@ function Za(a, c, b) { } } } else { - $a(this.map, a), this.depth && $a(this.ctx, a); + Za(this.map, a), this.depth && Za(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function $a(a, c) { +function Za(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1617,7 +1624,7 @@ function $a(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = $a(e[1], c); + const d = e[0], f = Za(e[1], c); f ? b += f : a.delete(d); } } @@ -1629,12 +1636,12 @@ function $a(a, c) { } if (a) { var b = D(a) ? a : a.preset; - b && (Xa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Xa[b], a)); + b && (Wa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Wa[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Ua[a.encoder] : a.encode || a.encoder || Ma; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && "default" !== b && b || "strict"; @@ -1670,7 +1677,7 @@ x.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 ab(a) { +function $a(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1678,7 +1685,7 @@ function ab(a) { } } else { for (const b of a.entries()) { - const e = b[0], d = ab(b[1]); + const e = b[0], d = $a(b[1]); d ? c += d : a.delete(e); } } @@ -1688,11 +1695,11 @@ x.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - ab(this.map); - this.depth && ab(this.ctx); + $a(this.map); + this.depth && $a(this.ctx); return this; }; -x.searchCache = Ma; +x.searchCache = La; x.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { @@ -1744,16 +1751,17 @@ x.serialize = function(a = !0) { b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let h = ua(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + d + '",' + h + "]"; - e += (e ? "," : "") + h; + let k = ua(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; ja(O.prototype); -export default {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +C(); +export default {Index:O, Charset:Ua, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=O;export const Charset=Va;export const Encoder=K;export const Document=V;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=O;export const Charset=Ua;export const Encoder=K;export const Document=V;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index e96b40e..13cc9b5 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.133 (Bundle) + * FlexSearch.js v0.8.135 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} +var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(k){return a(b(k))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function D(a){return"string"===typeof a} function H(a){return"object"===typeof a}function I(a,c){if(D(c))a=a[c];else for(let b=0;a&&ba.length&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&L(this);return this}; x.addReplacer=function(a,c){if("string"===typeof a)return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&L(this);return this}; x.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.F.has(a))return this.F.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ha?a.normalize("NFKD").replace(ha,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(k)),d!==g&&this.filter&& -g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(k)));if(g&&this.replacer)for(d=0;g&&dthis.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ka,la,Q;function ma(){ka=Q=0} +[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,k;fthis.stemmer.get(h)),d!==g&&this.filter&& +g.length>=this.minlength&&("function"===typeof this.filter?!this.filter(g):this.filter.has(g))&&(g=""));if(g&&(this.mapper||this.dedupe&&1this.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&dthis.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ka,la,Q;function ma(){ka=Q=0} function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);ka?Q||(Q=Date.now()-la>=this.priority*this.priority*3):(ka=setTimeout(ma,0),la=Date.now());if(Q){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let R=0; -function S(a={}){function c(g){function h(k){k=k.data||k;const l=k.id,m=l&&d.h[l];m&&(m(k.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){d.h[++R]=function(){k(d);1E9b||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let h;for(let k=g-1;0<=k;k--)if(h=(g=a[k])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}bc&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?W.call(this,g):g;d.push(g);c-=h;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:h,offset:k,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,h,k,l,m,n)}return d?this.resolve(c,b,e):this}; -function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; -function Ea(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(k){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function Fa(a,c,b,e,d){const f=[],g=C();let h=0;for(let k=0,l;kb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Aa(this,"and",arguments);return Ca.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; +function Ca(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(l){a=[];for(let m=0,n;ma.length)this.result=a[0];else{if(c=aa(a)){this.result=xa(a,c,b,e,g);var k;f?d?k=this.result:k=this.result:k=this;return k}this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Aa(this,"xor",arguments);return Da.call(this,a,c,b,e,d,f,g)}; +function Da(a,c,b,e,d,f,g){if(c.length){const h=this;return Promise.all(c).then(function(l){a=[];for(let m=0,n;ma.length)this.result=a[0];else{this.result=Ea.call(this,a,b,e,f,this.h);if(f){var k;d?k=this.result:k=this.result;c=k}else c=this;return c}else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Ea(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);return a}};function V(a){if(!this||this.constructor!==V)return new V(a);const c=a.document||a.doc||a;var b;this.C=[];this.field=[];this.J=[];this.key=(b=c.key||c.id)&&Ka(b,this.J)||"id";this.reg=(this.fastupdate=!!a.fastupdate)?new Map:new Set;this.A=(b=c.store||null)&&b&&!0!==b&&[];this.store=b&&new Map;this.cache=(b=a.cache||null)&&new Y(b);a.cache=!1;this.priority=a.priority||4;b=new Map;let e=c.index||c.field||c;D(e)&&(e=[e]);for(let d=0,f,g;dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -Y.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};const Oa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Pa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;const Ua=/[\x00-\x7F]+/g;var Wa={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Oa,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bv;f--){g=q.substring(v,f);u=this.rtl?d-1-v:v;var h=this.score?this.score(c,q,p,g,u):Ya(t,e,p,d,u); -Z(this,m,g,h,a,b)}break}case "reverse":if(1g?0:1),e,p,h-1,k-1),u=this.bidirectional&& -q>f;Z(this,l,u?f:q,v,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=C()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Ya(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else $a(this.map,a),this.depth&&$a(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function $a(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Ma={normalize:function(a){return a.toLowerCase()}};const Na=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 Oa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Pa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const Qa={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 Ra=/[\x00-\x7F]+/g;const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;var Va={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Ma,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Na},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Na,matcher:Oa,replacer:Pa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Na,replacer:Pa.concat([/(?!^)[aeo]/g,""]),matcher:Oa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bt;f--){g=q.substring(t,f);u=this.rtl?d-1-t:t;var k=this.score?this.score(c,q,p,g,u):Xa(r,e,p,d,u); +Z(this,m,g,k,a,b)}break}case "reverse":if(1g?0:1),e,p,k-1,h-1),u=this.bidirectional&& +q>f;Z(this,l,u?f:q,t,a,b,u?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this};function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Xa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else Za(this.map,a),this.depth&&Za(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Za(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function ab(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb.add(a,c)):this.add(a,c)};function $a(a){let c=0;if(a.constructor===Array)for(let b=0,e;b= this.minlength && ("function" === typeof this.filter ? !this.filter(f) : this.filter.has(f)) && (f = "")); + }), h !== f && this.filter && f.length >= this.minlength && ("function" === typeof this.filter ? !this.filter(f) : this.filter.has(f)) && (f = "")); if (f && (this.mapper || this.dedupe && 1 < f.length)) { - k = ""; + h = ""; 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); + n = f.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (h += p) : h += m = n); } - f = k; + f = h; } this.matcher && 1 < f.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), f = f.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]); + for (h = 0; f && h < this.replacer.length; h += 2) { + f = f.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && h.length <= this.H && (this.C.set(h, f), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); + this.cache && k.length <= this.H && (this.C.set(k, f), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); f && d.push(f); } } @@ -1109,8 +1109,8 @@ function N(a) { ;var Ha, O; function Ia(a) { var b, c, d, e, g, f; - return ta(function(h) { - switch(h.h) { + return ta(function(k) { + switch(k.h) { case 1: a = a.data; b = a.task; @@ -1123,9 +1123,9 @@ function Ia(a) { postMessage({id:c}); break; default: - h.h = 2; + k.h = 2; return; - }h.h = 0; + }k.h = 0; break; case 2: if ("export" === b) { @@ -1139,29 +1139,29 @@ function Ia(a) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } if (!d[0]) { - h.h = 5; + k.h = 5; break; } - return E(h, O.import.call(Ha, d[0]), 9); + return E(k, O.import.call(Ha, d[0]), 9); } g = d && Ha[b].apply(Ha, d); if (!g || !g.then) { - h.h = 5; + k.h = 5; break; } - return E(h, g, 7); + return E(k, g, 7); case 7: - g = h.D; - h.h = 5; + g = k.D; + k.h = 5; break; case 9: - f = h.D, Ha.import(d[0], f); + f = k.D, Ha.import(d[0], f); case 5: - postMessage("search" === b ? {id:c, msg:g} : {id:c}), h.h = 0; + postMessage("search" === b ? {id:c, msg:g} : {id:c}), k.h = 0; } }); } -;function La(a) { +;function Ja(a) { Ma.call(a, "add"); Ma.call(a, "append"); Ma.call(a, "search"); @@ -1199,19 +1199,19 @@ function Ma(a) { ;var Ra = 0; function Sa(a) { function b(f) { - function h(k) { - k = k.data || k; - var l = k.id, m = l && e.h[l]; - m && (m(k.msg), delete e.h[l]); + function k(h) { + h = h.data || h; + var l = h.id, m = l && e.h[l]; + m && (m(h.msg), delete e.h[l]); } this.worker = f; this.h = J(); if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; + d ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(k) { + return new Promise(function(h) { e.h[++Ra] = function() { - k(e); + h(e); 1e9 < Ra && (Ra = 0); }; e.worker.postMessage({id:Ra, task:"init", factory:c, options:a}); @@ -1241,7 +1241,7 @@ S("remove"); S("clear"); S("export"); S("import"); -La(Sa.prototype); +Ja(Sa.prototype); function S(a) { Sa.prototype[a] = function() { var b = this, c = [].slice.call(arguments), d = c[c.length - 1]; @@ -1315,17 +1315,17 @@ function Za(a, b) { } function $a(a, b, c, d, e, g, f) { f = void 0 === f ? 0 : f; - var h = d && d.constructor === Array, k = h ? d.shift() : d; - if (!k) { + var k = d && d.constructor === Array, h = k ? d.shift() : d; + if (!h) { return this.export(a, b, e, g + 1); } - if ((k = a((b ? b + "." : "") + (f + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((h = a((b ? b + "." : "") + (f + 1) + "." + c, JSON.stringify(h))) && h.then) { var l = this; - return k.then(function() { - return $a.call(l, a, b, c, h ? d : null, e, g, f + 1); + return h.then(function() { + return $a.call(l, a, b, c, k ? d : null, e, g, f + 1); }); } - return $a.call(this, a, b, c, h ? d : null, e, g, f + 1); + return $a.call(this, a, b, c, k ? d : null, e, g, f + 1); } function ab(a, b) { var c = ""; @@ -1334,13 +1334,13 @@ function ab(a, b) { var e = d.value; d = e[0]; e = e[1]; - for (var g = "", f = 0, h; f < e.length; f++) { - h = e[f] || [""]; - for (var k = "", l = 0; l < h.length; l++) { - k += (k ? "," : "") + ("string" === b ? '"' + h[l] + '"' : h[l]); + for (var g = "", f = 0, k; f < e.length; f++) { + k = e[f] || [""]; + for (var h = "", l = 0; l < k.length; l++) { + h += (h ? "," : "") + ("string" === b ? '"' + k[l] + '"' : k[l]); } - k = "[" + k + "]"; - g += (g ? "," : "") + k; + h = "[" + h + "]"; + g += (g ? "," : "") + h; } g = '["' + d + '",[' + g + "]]"; c += (c ? "," : "") + g; @@ -1389,13 +1389,13 @@ function T(a) { } if ("indexOf" === d) { return function(e) { - for (var g = 0, f = 0, h, k; f < b.index.length; f++) { - h = b.index[f]; - k = h.indexOf(e); - if (0 <= k) { - return g + k; + for (var g = 0, f = 0, k, h; f < b.index.length; f++) { + k = b.index[f]; + h = k.indexOf(e); + if (0 <= h) { + return g + h; } - g += h.length; + g += k.length; } return -1; }; @@ -1599,45 +1599,45 @@ function cb() { if (this.tag) { for (d = 0; d < this.L.length; d++) { f = this.L[d]; - var h = this.aa[d]; - g = this.tag.get(h); + var k = this.aa[d]; + g = this.tag.get(k); e = J(); if ("function" === typeof f) { if (f = f(b), !f) { continue; } } else { - var k = f.R; - if (k && !k(b)) { + var h = f.R; + if (h && !h(b)) { continue; } f.constructor === String && (f = "" + f); f = ya(b, f); } if (g && f) { - for (K(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { - var l = f[h]; + for (K(f) && (f = [f]), k = 0, h = void 0; k < f.length; k++) { + var l = f[k]; if (!e[l]) { e[l] = 1; var m; - (m = g.get(l)) ? k = m : g.set(l, k = []); - if (!c || !k.includes(a)) { - if (k.length === Math.pow(2, 31) - 1) { - m = new T(k); + (m = g.get(l)) ? h = m : g.set(l, h = []); + if (!c || !h.includes(a)) { + if (h.length === Math.pow(2, 31) - 1) { + m = new T(h); if (this.fastupdate) { for (var n = x(this.reg.values()), p = n.next(); !p.done; p = n.next()) { - p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); + p = p.value, p.includes(h) && (p[p.indexOf(h)] = m); } } - g.set(l, k = m); + g.set(l, h = m); } - k.push(a); - this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); + h.push(a); + this.fastupdate && ((l = this.reg.get(a)) ? l.push(h) : this.reg.set(a, [h])); } } } } else { - g || console.warn("Tag '" + h + "' was not found"); + g || console.warn("Tag '" + k + "' was not found"); } } } @@ -1681,7 +1681,7 @@ function ib(a, b, c, d, e, g) { } } } -function hb(a, b, c, d, e, g, f, h) { +function hb(a, b, c, d, e, g, f, k) { if (a = a[f]) { if (d === b.length - 1) { if (a.constructor === Array) { @@ -1693,14 +1693,14 @@ function hb(a, b, c, d, e, g, f, h) { } a = a.join(" "); } - e.add(g, a, h, !0); + e.add(g, a, k, !0); } else { if (a.constructor === Array) { for (f = 0; f < a.length; f++) { - hb(a, b, c, d, e, g, f, h); + hb(a, b, c, d, e, g, f, k); } } else { - f = b[++d], hb(a, b, c, d, e, g, f, h); + f = b[++d], hb(a, b, c, d, e, g, f, k); } } } else { @@ -1708,45 +1708,45 @@ function hb(a, b, c, d, e, g, f, h) { } } ;function jb(a, b, c, d, e, g, f) { - var h = a.length, k = []; + var k = a.length, h = []; var l = J(); for (var m = 0, n = void 0, p, q; m < b; m++) { - for (var t = 0; t < h; t++) { + for (var t = 0; t < k; t++) { var w = a[t]; if (m < w.length && (n = w[m])) { for (var r = 0; r < n.length; r++) { p = n[r]; (w = l[p]) ? l[p]++ : (w = 0, l[p] = 1); - q = k[w] || (k[w] = []); + q = h[w] || (h[w] = []); if (!f) { var A = m + (t || !e ? 0 : g || 0); q = q[A] || (q[A] = []); } q.push(p); - if (f && c && w === h - 1 && q.length - d === c) { + if (f && c && w === k - 1 && q.length - d === c) { return q; } } } } } - if (a = k.length) { + if (a = h.length) { if (e) { - k = 1 < k.length ? kb(k, c, d, f, g) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + h = 1 < h.length ? kb(h, c, d, f, g) : (h = h[0]).length > c || d ? h.slice(d, c + d) : h; } else { - if (a < h) { + if (a < k) { return []; } - k = k[a - 1]; + h = h[a - 1]; if (c || d) { if (f) { - if (k.length > c || d) { - k = k.slice(d, c + d); + if (h.length > c || d) { + h = h.slice(d, c + d); } } else { e = []; - for (g = 0; g < k.length; g++) { - if (f = k[g], f.length > d) { + for (g = 0; g < h.length; g++) { + if (f = h[g], f.length > d) { d -= f.length; } else { if (f.length > c || d) { @@ -1758,20 +1758,20 @@ function hb(a, b, c, d, e, g, f, h) { } } } - k = 1 < e.length ? [].concat.apply([], e) : e[0]; + h = 1 < e.length ? [].concat.apply([], e) : e[0]; } } } } - return k; + return h; } function kb(a, b, c, d, e) { - var g = [], f = J(), h = a.length, k; + var g = [], f = J(), k = a.length, h; if (d) { - for (e = h - 1; 0 <= e; e--) { - if (k = (d = a[e]) && d.length) { - for (h = 0; h < k; h++) { - var l = d[h]; + for (e = k - 1; 0 <= e; e--) { + if (h = (d = a[e]) && d.length) { + for (k = 0; k < h; k++) { + var l = d[k]; if (!f[l]) { if (f[l] = 1, c) { c--; @@ -1785,16 +1785,16 @@ function kb(a, b, c, d, e) { } } } else { - for (var m = h - 1, n, p = 0; 0 <= m; m--) { + for (var m = k - 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 (h = (d = n[q]) && d.length) { + for (var t = 0; t < h; t++) { if (l = d[t], !f[l]) { if (f[l] = 1, c) { c--; } else { - var w = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; + var w = (q + (m < k - 1 ? e || 0 : 0)) / (m + 1) | 0; (g[w] || (g[w] = [])).push(l); if (++p === b) { return g; @@ -1811,8 +1811,8 @@ function kb(a, b, c, d, e) { function lb(a, b, c) { for (var d = J(), e = [], g = 0, f; g < b.length; g++) { f = b[g]; - for (var h = 0; h < f.length; h++) { - d[f[h]] = 1; + for (var k = 0; k < f.length; k++) { + d[f[k]] = 1; } } if (c) { @@ -1835,21 +1835,21 @@ function lb(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, d ? X.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 = [], g = 0, f = void 0, k = void 0; g < a.length; g++) { + if ((f = a[g]) && (k = f.length)) { if (c) { - if (c >= h) { - c -= h; + if (c >= k) { + c -= k; continue; } - c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); + c < k && (f = b ? f.slice(c, c + b) : f.slice(c), k = f.length, c = 0); } - h > b && (f = f.slice(0, b), h = b); - if (!e.length && h >= b) { + k > b && (f = f.slice(0, b), k = b); + if (!e.length && k >= b) { return d ? X.call(this, f) : f; } e.push(f); - b -= h; + b -= k; if (!b) { break; } @@ -1869,7 +1869,7 @@ function lb(a, b, c) { return a[b].apply(a, d); } d = []; - for (var e = [], g = 0, f = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { + for (var e = [], g = 0, f = 0, k, h, l, m = 0, n = void 0; m < c.length; m++) { if (n = c[m]) { var p = void 0; if (n.constructor === Y) { @@ -1877,8 +1877,8 @@ function lb(a, b, c) { } else if (n.constructor === Array) { p = n; } else { - if (g = n.limit || 0, f = 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; + if (g = n.limit || 0, f = 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) { @@ -1901,7 +1901,7 @@ function lb(a, b, c) { } } } - return {W:d, $:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; + return {W:d, $:e, limit:g, offset:f, enrich:k, resolve:h, suggest:l}; } ;Y.prototype.or = function() { var a = nb(this, "or", arguments); @@ -1910,10 +1910,10 @@ function lb(a, b, c) { function ob(a, b, c, d, e, g) { if (b.length) { var f = this; - return Promise.all(b).then(function(h) { + return Promise.all(b).then(function(k) { a = []; - for (var k = 0, l = void 0; k < h.length; k++) { - (l = h[k]).length && (a[k] = l); + for (var h = 0, l = void 0; h < k.length; h++) { + (l = k[h]).length && (a[h] = l); } return ob.call(f, a, [], c, d, e, g); }); @@ -1937,13 +1937,13 @@ function ob(a, b, c, d, e, g) { }; function pb(a, b, c, d, e, g, f) { if (b.length) { - var h = this; - return Promise.all(b).then(function(k) { + var k = this; + return Promise.all(b).then(function(h) { a = []; - for (var l = 0, m = void 0; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return pb.call(h, a, [], c, d, e, g, f); + return pb.call(k, a, [], c, d, e, g, f); }); } if (a.length) { @@ -1966,13 +1966,13 @@ function pb(a, b, c, d, e, g, f) { }; function qb(a, b, c, d, e, g, f) { if (b.length) { - var h = this; - return Promise.all(b).then(function(k) { + var k = this; + return Promise.all(b).then(function(h) { a = []; - for (var l = 0, m = void 0; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return qb.call(h, a, [], c, d, e, g, f); + return qb.call(k, a, [], c, d, e, g, f); }); } if (a.length) { @@ -1987,9 +1987,9 @@ function qb(a, b, c, d, e, g, f) { return g ? this.resolve(c, d, e) : this; } function rb(a, b, c, d, e) { - for (var g = [], f = J(), h = 0, k = 0, l; k < a.length; k++) { - if (l = a[k]) { - h < l.length && (h = l.length); + for (var g = [], f = J(), k = 0, h = 0, l; h < a.length; h++) { + if (l = a[h]) { + k < l.length && (k = l.length); for (var m = 0, n; m < l.length; m++) { if (n = l[m]) { for (var p = 0, q; p < n.length; p++) { @@ -1999,10 +1999,10 @@ function rb(a, b, c, d, e) { } } } - for (l = k = 0; k < h; k++) { + for (l = h = 0; h < k; h++) { for (m = 0; m < a.length; m++) { if (n = a[m]) { - if (n = n[k]) { + if (n = n[h]) { for (p = 0; p < n.length; p++) { if (q = n[p], 1 === f[q]) { if (c) { @@ -2013,7 +2013,7 @@ function rb(a, b, c, d, e) { return g; } } else { - var t = k + (m ? e : 0); + var t = h + (m ? e : 0); g[t] || (g[t] = []); g[t].push(q); if (++l === b) { @@ -2035,13 +2035,13 @@ function rb(a, b, c, d, e) { }; function sb(a, b, c, d, e, g, f) { if (b.length) { - var h = this; - return Promise.all(b).then(function(k) { + var k = this; + return Promise.all(b).then(function(h) { a = []; - for (var l = 0, m = void 0; l < k.length; l++) { - (m = k[l]).length && (a[l] = m); + for (var l = 0, m = void 0; l < h.length; l++) { + (m = h[l]).length && (a[l] = m); } - return sb.call(h, a, [], c, d, e, g, f); + return sb.call(k, a, [], c, d, e, g, f); }); } if (a.length && this.result.length) { @@ -2054,10 +2054,10 @@ function sb(a, b, c, d, e, g, f) { function tb(a, b, c, d) { var e = []; a = new Set(a.flat().flat()); - for (var g = 0, f, h = 0; g < this.result.length; g++) { + for (var g = 0, f, k = 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 h = 0, l; h < f.length; h++) { + if (l = f[h], !a.has(l)) { if (c) { c--; } else { @@ -2066,7 +2066,7 @@ function tb(a, b, c, d) { return e; } } else { - if (e[g] || (e[g] = []), e[g].push(l), ++h === b) { + if (e[g] || (e[g] = []), e[g].push(l), ++k === b) { return e; } } @@ -2129,7 +2129,7 @@ Y.prototype.resolve = function(a, b, c) { J(); W.prototype.search = function(a, b, c, d) { c || (!b && L(a) ? (c = a, a = "") : L(b) && (c = b, b = 0)); - var e = [], g = [], f, h = 0, k = !0; + var e = [], g = [], f, k = 0, h = !0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; @@ -2138,8 +2138,8 @@ W.prototype.search = function(a, b, c, d) { var n = l || c.field || (n = c.index) && (n.index ? null : n); var p = this.tag && c.tag; var q = c.suggest; - k = !1 !== c.resolve; - if (!k && !l) { + h = !1 !== c.resolve; + if (!h && !l) { if (n = n || this.field) { K(n) ? l = n : (n.constructor === Array && 1 === n.length && (n = n[0]), l = n.field || n.index); } @@ -2147,8 +2147,8 @@ W.prototype.search = function(a, b, c, d) { 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 && !k && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var t = (f = this.store && c.enrich && k) && c.highlight; + this.store && c.enrich && !h && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var t = (f = this.store && c.enrich && h) && c.highlight; b = c.limit || b; var w = c.offset || 0; b || (b = 100); @@ -2187,7 +2187,7 @@ W.prototype.search = function(a, b, c, d) { } p = r; if (!a) { - k = []; + h = []; if (r.length) { for (g = 0; g < r.length; g += 2) { l = void 0; @@ -2197,14 +2197,14 @@ W.prototype.search = function(a, b, c, d) { console.warn("Tag '" + r[g] + ":" + r[g + 1] + "' will be skipped because there is no field '" + r[g] + "'."); continue; } - k.push(l = l.db.tag(r[g + 1], b, w, f)); + h.push(l = l.db.tag(r[g + 1], b, w, f)); } else { l = ub.call(this, r[g], r[g + 1], b, w, f); } e.push({field:r[g], tag:r[g + 1], result:l}); } } - return k.length ? Promise.all(k).then(function(Q) { + return h.length ? Promise.all(h).then(function(Q) { for (var R = 0; R < Q.length; R++) { e[R].result = Q[R]; } @@ -2229,10 +2229,10 @@ W.prototype.search = function(a, b, c, d) { if (p) { if (this.db) { y.tag = p; - var Ja = v.db.support_tag_search; + var Ka = v.db.support_tag_search; y.field = n; } - Ja || (y.enrich = !1); + Ka || (y.enrich = !1); } if (r) { r[A] = v.search(a, b, y); @@ -2242,111 +2242,117 @@ W.prototype.search = function(a, b, c, d) { v = v.search(a, b, y), y && f && (y.enrich = f); } } - y = v && (k ? v.length : v.result.length); + y = v && (h ? v.length : v.result.length); if (p && y) { D = []; G = 0; if (this.db && d) { - if (!Ja) { + if (!Ka) { for (H = n.length; H < d.length; H++) { var M = d[H]; if (M && M.length) { G++, D.push(M); } else if (!q) { - return k ? e : new Y(e); + return h ? e : new Y(e); } } } } else { H = 0; - for (var Xb = M = void 0; H < p.length; H += 2) { + for (var Yb = M = void 0; H < p.length; H += 2) { M = this.tag.get(p[H]); if (!M) { if (console.warn("Tag '" + p[H] + ":" + p[H + 1] + "' will be skipped because there is no field '" + p[H] + "'."), q) { continue; } else { - return k ? e : new Y(e); + return h ? e : new Y(e); } } - if (Xb = (M = M && M.get(p[H + 1])) && M.length) { + if (Yb = (M = M && M.get(p[H + 1])) && M.length) { G++, D.push(M); } else if (!q) { - return k ? e : new Y(e); + return h ? e : new Y(e); } } } if (G) { - v = lb(v, D, k); + v = lb(v, D, h); y = v.length; if (!y && !q) { - return k ? v : new Y(v); + return h ? v : new Y(v); } G--; } } if (y) { - g[h] = z, e.push(v), h++; + g[k] = z, e.push(v), k++; } else if (1 === n.length) { - return k ? e : new Y(e); + return h ? e : new Y(e); } } } if (r) { - if (this.db && p && p.length && !Ja) { + if (this.db && p && p.length && !Ka) { for (f = 0; f < p.length; f += 2) { g = this.index.get(p[f]); if (!g) { if (console.warn("Tag '" + p[f] + ":" + p[f + 1] + "' was not found because there is no field '" + p[f] + "'."), q) { continue; } else { - return k ? e : new Y(e); + return h ? e : new Y(e); } } r.push(g.db.tag(p[f + 1], b, w, !1)); } } - var Yb = this; + var Zb = this; return Promise.all(r).then(function(Q) { - return Q.length ? Yb.search(a, b, c, Q) : Q; + return Q.length ? Zb.search(a, b, c, Q) : Q; }); } - if (!h) { - return k ? e : new Y(e); + if (!k) { + return h ? e : new Y(e); } if (l && (!f || !this.store)) { return e[0]; } r = []; - w = 0; - for (q = void 0; w < g.length; w++) { + for (w = 0; w < g.length; w++) { q = e[w]; - f && q.length && !q[0].doc && (this.db ? r.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = X.call(this, q)); + f && q.length && "undefined" === typeof q[0].doc && (this.db ? r.push(q = this.index.get(this.field[0]).db.enrich(q)) : q = X.call(this, q)); if (l) { - return k ? q : new Y(q); + return h ? q : new Y(q); } e[w] = {field:g[w], result:q}; } if (f && this.db && r.length) { - var Ka = this; + var La = this; return Promise.all(r).then(function(Q) { for (var R = 0; R < Q.length; R++) { e[R].result = Q[R]; } - return m ? vb(e, b) : t ? wb(e, a, Ka.index, Ka.field, Ka.J, t) : e; + return m ? vb(e, b) : t ? wb(e, a, La.index, La.field, La.J, t) : e; }); } return m ? vb(e, b) : t ? wb(e, a, this.index, this.field, this.J, t) : e; }; function wb(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 = "", t = ya(m[p].doc, n), w = f.encode(t); + for (var f, k, h, l = 0, m, n; l < a.length; l++) { + var p = a[l].result; + m = a[l].field; + h = c.get(m); + n = h.encoder; + h = h.tokenize; + m = e[d.indexOf(m)]; + n !== f && (f = n, k = f.encode(b)); + for (n = 0; n < p.length; n++) { + var q = "", t = ya(p[n].doc, m), w = f.encode(t); t = t.split(f.split); for (var r = 0, A, z; r < w.length; r++) { A = w[r]; z = t[r]; - for (var v = void 0, y = 0, D; y < h.length; y++) { - if (D = h[y], "strict" === k) { + for (var v = void 0, y = 0, D; y < k.length; y++) { + if (D = k[y], "strict" === h) { if (A === D) { q += (q ? " " : "") + g.replace("$1", z); v = !0; @@ -2363,7 +2369,7 @@ function wb(a, b, c, d, e, g) { } v || (q += (q ? " " : "") + t[r]); } - m[p].highlight = q; + p[n].highlight = q; } } return a; @@ -2372,14 +2378,14 @@ function vb(a, b) { for (var c = [], d = J(), 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], "object" !== typeof l && (l = {id:l}), k = l.id, m = d[k]) { + for (var k = 0, h, l, m; k < f.length; k++) { + if (l = f[k], "object" !== typeof l && (l = {id:l}), h = l.id, m = d[h]) { m.push(g.field); } else { if (c.length === b) { return c; } - l.field = d[k] = [g.field]; + l.field = d[h] = [g.field]; c.push(l); } } @@ -2456,10 +2462,10 @@ function X(a) { if (a.length) { var g = this; return Promise.all(a).then(function(f) { - for (var h = 0, k = x(g.index.entries()), l = k.next(); !l.done; l = k.next()) { + for (var k = 0, h = x(g.index.entries()), l = h.next(); !l.done; l = h.next()) { l = l.value; var m = l[0]; - l[1].then && g.index.set(m, f[h++]); + l[1].then && g.index.set(m, f[k++]); } return g; }); @@ -2501,17 +2507,17 @@ u.mount = function(a) { }; u.commit = function(a, b) { var c = this, d, e, g, f; - return ta(function(h) { - if (1 == h.h) { + return ta(function(k) { + if (1 == k.h) { d = []; e = x(c.index.values()); for (g = e.next(); !g.done; g = e.next()) { f = g.value, d.push(f.commit(f, a, b)); } - return E(h, Promise.all(d), 2); + return E(k, Promise.all(d), 2); } c.reg.clear(); - h.h = 0; + k.h = 0; }); }; u.destroy = function() { @@ -2528,8 +2534,8 @@ function yb(a, b) { K(g) || (f = g, g = g.field); f = L(f) ? Object.assign({}, a, f) : a; if (this.worker) { - var h = new Sa(f); - c.set(g, h); + var k = new Sa(f); + c.set(g, k); } this.worker || c.set(g, new P(f, this.reg)); f.custom ? this.J[e] = f.custom : (this.J[e] = xb(g, this.S), f.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = f.filter)); @@ -2627,23 +2633,23 @@ u.export = function(a, b, c, d) { switch(d) { case 0: var f = "reg"; - var h = Ya(this.reg); + var k = Ya(this.reg); b = null; break; case 1: f = "tag"; - h = this.tag && Wa(this.tag, this.reg.size); + k = this.tag && Wa(this.tag, this.reg.size); b = null; break; case 2: f = "doc"; - h = this.store && Ua(this.store); + k = this.store && Ua(this.store); b = null; break; default: return; } - return $a.call(this, a, b, f, h, c, d); + return $a.call(this, a, b, f, k, c, d); }; u.import = function(a, b) { var c = a.split("."); @@ -2682,7 +2688,7 @@ u.import = function(a, b) { } } }; -La(W.prototype); +Ja(W.prototype); function zb(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); this.cache || (this.cache = new Z()); @@ -2755,17 +2761,17 @@ P.prototype.add = function(a, b, c, d) { } b = this.encoder.encode(b); if (d = b.length) { - for (var e = J(), g = J(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { - var l = b[this.rtl ? d - 1 - k : k], m = l.length; + for (var e = J(), g = J(), f = this.depth, k = this.resolution, h = 0; h < d; h++) { + var l = b[this.rtl ? d - 1 - h : h], m = l.length; if (m && (f || !g[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : Kb(h, d, k), p = ""; + var n = this.score ? this.score(b, l, h, null, 0) : Kb(k, d, h), p = ""; switch(this.tokenize) { case "full": if (2 < m) { n = 0; for (var q; n < m; n++) { for (var t = m; t > n; t--) { - p = l.substring(n, t), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, k, p, q) : Kb(h, d, k, m, q), Lb(this, g, p, q, a, c); + p = l.substring(n, t), q = this.rtl ? m - 1 - n : n, q = this.score ? this.score(b, l, h, p, q) : Kb(k, d, h, m, q), Lb(this, g, p, q, a, c); } } break; @@ -2773,7 +2779,7 @@ P.prototype.add = function(a, b, c, d) { case "reverse": if (1 < m) { for (t = m - 1; 0 < t; t--) { - p = l[this.rtl ? m - 1 - t : t] + p, q = this.score ? this.score(b, l, k, p, t) : Kb(h, d, k, m, t), Lb(this, g, p, q, a, c); + p = l[this.rtl ? m - 1 - t : t] + p, q = this.score ? this.score(b, l, h, p, t) : Kb(k, d, h, m, t), Lb(this, g, p, q, a, c); } p = ""; } @@ -2785,11 +2791,11 @@ P.prototype.add = function(a, b, c, d) { break; } default: - if (Lb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { - for (m = J(), p = this.da, n = l, t = Math.min(f + 1, this.rtl ? k + 1 : d - k), q = m[n] = 1; q < t; q++) { - if ((l = b[this.rtl ? d - 1 - k - q : k + q]) && !m[l]) { + if (Lb(this, g, l, n, a, c), f && 1 < d && h < d - 1) { + for (m = J(), p = this.da, n = l, t = Math.min(f + 1, this.rtl ? h + 1 : d - h), q = m[n] = 1; q < t; q++) { + if ((l = b[this.rtl ? d - 1 - h - q : h + q]) && !m[l]) { m[l] = 1; - var w = this.score ? this.score(b, n, k, l, q - 1) : Kb(p + (d / 2 > p ? 0 : 1), d, k, t - 1, q - 1), r = this.bidirectional && l > n; + var w = this.score ? this.score(b, n, h, l, q - 1) : Kb(p + (d / 2 > p ? 0 : 1), d, h, t - 1, q - 1), r = this.bidirectional && l > n; Lb(this, e, r ? n : l, w, a, c, r ? l : n); } } @@ -2806,20 +2812,20 @@ P.prototype.add = function(a, b, c, d) { return this; }; function Lb(a, b, c, d, e, g, f) { - var h = f ? a.ctx : a.map, k; - if (!b[c] || f && !(k = b[c])[f]) { - if (f ? (b = k || (b[c] = J()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { - if (h.length === Math.pow(2, 31) - 1) { - b = new T(h); + var k = f ? a.ctx : a.map, h; + if (!b[c] || f && !(h = b[c])[f]) { + if (f ? (b = h || (b[c] = J()), b[f] = 1, (h = k.get(f)) ? k = h : k.set(f, k = new Map())) : b[c] = 1, (h = k.get(c)) ? k = h : k.set(c, k = h = []), k = k[d] || (k[d] = []), !g || !k.includes(e)) { + if (k.length === Math.pow(2, 31) - 1) { + b = new T(k); if (a.fastupdate) { for (c = x(a.reg.values()), g = c.next(); !g.done; g = c.next()) { - g = g.value, g.includes(h) && (g[g.indexOf(h)] = b); + g = g.value, g.includes(k) && (g[g.indexOf(k)] = b); } } - k[d] = h = b; + h[d] = k = b; } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + k.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(k) : a.reg.set(e, [k])); } } } @@ -2834,8 +2840,8 @@ function Kb(a, b, c, d, e) { b = c.limit || b; e = c.offset || 0; var f = c.context; - var h = c.suggest; - var k = (g = !1 !== c.resolve) && c.enrich; + var k = c.suggest; + var h = (g = !1 !== c.resolve) && c.enrich; var l = c.boost; var m = c.resolution; var n = this.db && c.tag; @@ -2846,11 +2852,11 @@ function Kb(a, b, c, d, e) { var q = p.length; b = b || (g ? 100 : 0); if (1 === q) { - return Nb.call(this, p[0], "", b, e, g, k, n); + return Nb.call(this, p[0], "", b, e, g, h, n); } f = this.depth && !1 !== f; - if (2 === q && f && !h) { - return Nb.call(this, p[0], p[1], b, e, g, k, n); + if (2 === q && f && !k) { + return Nb.call(this, p[0], p[1], b, e, g, h, n); } var t = J(), w = 0; if (1 < q && f) { @@ -2859,7 +2865,7 @@ function Kb(a, b, c, d, e) { } m || 0 === m || (m = r ? this.da : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, p, b, e, h, g, k, n), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, b, e, k, g, h, n), !1 !== a)) { return a; } var A = this; @@ -2883,19 +2889,19 @@ function Kb(a, b, c, d, e) { return E(y, Ob(A, v, r, 0, 0, !1, !1), 6); case 6: z = y.D; - if (z = Pb(z, d, h, m)) { + if (z = Pb(z, d, k, m)) { d = z; y.h = 4; break; } - r && (h && z && d.length || (r = v)); + r && (k && z && d.length || (r = v)); case 5: - h && r && w === q - 1 && !d.length && (m = A.resolution, r = "", w = -1, t = J()); + k && r && w === q - 1 && !d.length && (m = A.resolution, r = "", w = -1, t = J()); w++; y.h = 2; break; case 4: - return y.return(Qb(d, m, b, e, h, l, g)); + return y.return(Qb(d, m, b, e, k, l, g)); } }); }(); @@ -2904,29 +2910,29 @@ function Kb(a, b, c, d, e) { if ((c = p[w]) && !t[c]) { t[c] = 1; a = Ob(this, c, r, 0, 0, !1, !1); - if (a = Pb(a, d, h, m)) { + if (a = Pb(a, d, k, m)) { d = a; break; } - r && (h && a && d.length || (r = c)); + r && (k && a && d.length || (r = c)); } - h && r && w === q - 1 && !d.length && (m = this.resolution, r = "", w = -1, t = J()); + k && r && w === q - 1 && !d.length && (m = this.resolution, r = "", w = -1, t = J()); } - return Qb(d, m, b, e, h, l, g); + return Qb(d, m, b, e, k, l, g); }; function Qb(a, b, c, d, e, g, f) { - var h = a.length, k = a; - if (1 < h) { - k = jb(a, b, c, d, e, g, f); - } else if (1 === h) { + var k = a.length, h = a; + if (1 < k) { + h = jb(a, b, c, d, e, g, f); + } else if (1 === k) { return f ? mb.call(null, a[0], c, d) : new Y(a[0]); } - return f ? k : new Y(k); + return f ? h : new Y(h); } function Nb(a, b, c, d, e, g, f) { a = Ob(this, a, b, c, d, e, g, f); - return this.db ? a.then(function(h) { - return e ? h || [] : new Y(h); + return this.db ? a.then(function(k) { + return e ? k || [] : new Y(k); }) : a && a.length ? e ? mb.call(this, a, c, d) : new Y(a) : e ? [] : new Y(); } function Pb(a, b, c, d) { @@ -2950,11 +2956,11 @@ function Pb(a, b, c, d) { return e; } } -function Ob(a, b, c, d, e, g, f, h) { - var k; - c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); +function Ob(a, b, c, d, e, g, f, k) { + var h; + c && (h = a.bidirectional && b > c) && (h = c, c = b, b = h); if (a.db) { - return a.db.get(b, c, d, e, g, f, h); + return a.db.get(b, c, d, e, g, f, k); } a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; @@ -3155,23 +3161,23 @@ u.serialize = function(a) { c = "index.map=new Map([" + c + "]);"; g = x(this.ctx.entries()); for (var f = g.next(); !f.done; f = g.next()) { - var h = f.value; - f = h[0]; - h = ab(h[1], e); - h = "new Map([" + h + "])"; - h = '["' + f + '",' + h + "]"; - d += (d ? "," : "") + h; + var k = f.value; + f = k[0]; + k = ab(k[1], e); + k = "new Map([" + k + "])"; + k = '["' + f + '",' + k + "]"; + d += (d ? "," : "") + k; } d = "index.ctx=new Map([" + d + "]);"; } return a ? "function inject(index){" + b + c + d + "}" : b + c + d; }; -La(P.prototype); -var Tb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ub = ["map", "ctx", "tag", "reg", "cfg"]; -function Vb(a, b) { +Ja(P.prototype); +var Tb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ub = ["map", "ctx", "tag", "reg", "cfg"], Vb = J(); +function Wb(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Vb(a, b); + return new Wb(a, b); } "object" === typeof a && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3182,7 +3188,7 @@ function Vb(a, b) { this.db = null; this.h = {}; } -u = Vb.prototype; +u = Wb.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -3193,13 +3199,17 @@ u.mount = function(a) { u.open = function() { var a = this; navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function(b, c) { - var d = Tb.open(a.id + (a.field ? ":" + a.field : ""), 1); + return this.db || (this.db = new Promise(function(b, c) { + Vb[a.id] || (Vb[a.id] = []); + Vb[a.id].push(a.field); + var d = Tb.open(a.id, 1); d.onupgradeneeded = function() { - var e = a.db = this.result; - Ub.forEach(function(g) { - e.objectStoreNames.contains(g) || e.createObjectStore(g); - }); + for (var e = a.db = this.result, g = 0, f; g < Ub.length; g++) { + f = Ub[g]; + for (var k = 0, h; k < Vb[a.id].length; k++) { + h = Vb[a.id][k], e.objectStoreNames.contains(f + ("reg" !== f ? h ? ":" + h : "" : "")) || e.createObjectStore(f + ("reg" !== f ? h ? ":" + h : "" : "")); + } + } }; d.onblocked = function(e) { console.error("blocked", e); @@ -3216,65 +3226,72 @@ u.open = function() { }; b(a); }; - }); + })); }; u.close = function() { this.db && this.db.close(); this.db = null; }; u.destroy = function() { - var a = Tb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); - return Wb(a); + var a = Tb.deleteDatabase(this.id); + return Xb(a); }; u.clear = function() { - for (var a = this.db.transaction(Ub, "readwrite"), b = 0; b < Ub.length; b++) { - a.objectStore(Ub[b]).clear(); + for (var a = [], b = 0, c; b < Ub.length; b++) { + c = Ub[b]; + for (var d = 0, e; d < Vb[this.id].length; d++) { + e = Vb[this.id][d], a.push(c + ("reg" !== c ? e ? ":" + e : "" : "")); + } } - return Wb(a); + b = this.db.transaction(a, "readwrite"); + for (c = 0; c < a.length; c++) { + b.objectStore(a[c]).clear(); + } + return Xb(b); }; u.get = function(a, b, c, d, e, g) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; e = void 0 === e ? !0 : e; g = void 0 === g ? !1 : g; - a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); + a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); var f = this; - return Wb(a).then(function(h) { - var k = []; - if (!h || !h.length) { - return k; + return Xb(a).then(function(k) { + var h = []; + if (!k || !k.length) { + return h; } if (e) { - if (!c && !d && 1 === h.length) { - return h[0]; + if (!c && !d && 1 === k.length) { + return k[0]; } - for (var l = 0, m = void 0; l < h.length; l++) { - if ((m = h[l]) && m.length) { + for (var l = 0, m = void 0; l < k.length; l++) { + if ((m = k[l]) && m.length) { if (d >= m.length) { d -= m.length; } else { for (var n = c ? d + Math.min(m.length - d, c) : m.length, p = d; p < n; p++) { - k.push(m[p]); + h.push(m[p]); } d = 0; - if (k.length === c) { + if (h.length === c) { break; } } } } - return g ? f.enrich(k) : k; + return g ? f.enrich(h) : h; } - return h; + return k; }); }; 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); + a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); var e = this; - return Wb(a).then(function(g) { + return Xb(a).then(function(g) { if (!g || !g.length || c >= g.length) { return []; } @@ -3288,7 +3305,7 @@ u.tag = function(a, b, c, d) { 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] = Wb(b.get(a[d])); + c[d] = Xb(b.get(a[d])); } return Promise.all(c).then(function(e) { for (var g = 0; g < e.length; g++) { @@ -3299,7 +3316,7 @@ u.enrich = function(a) { }; u.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Wb(a).then(function(b) { + return Xb(a).then(function(b) { return !!b; }); }; @@ -3307,34 +3324,34 @@ u.search = null; u.info = function() { }; u.transaction = function(a, b, c) { - var d = this, e = this.h[a + ":" + b]; - if (e) { - return c.call(this, e); + var d = this, e = a + ("reg" !== a ? this.field ? ":" + this.field : "" : ""), g = this.h[e + ":" + b]; + if (g) { + return c.call(this, g); } - var g = this.db.transaction(a, b); - this.h[a + ":" + b] = e = g.objectStore(a); - return new Promise(function(f, h) { - g.onerror = function(l) { - g.abort(); - g = e = null; - h(l); + var f = this.db.transaction(e, b); + this.h[e + ":" + b] = g = f.objectStore(e); + return new Promise(function(k, h) { + f.onerror = function(m) { + f.abort(); + f = g = null; + h(m); }; - g.oncomplete = function(l) { - g = e = null; - f(l || !0); + f.oncomplete = function(m) { + f = g = null; + k(m || !0); }; - var k = c.call(d, e); - d.h[a + ":" + b] = null; - return k; + var l = c.call(d, g); + d.h[e + ":" + b] = null; + return l; }); }; u.commit = function(a, b, c) { var d = this, e, g, f; - return ta(function(h) { - switch(h.h) { + return ta(function(k) { + switch(k.h) { case 1: if (b) { - return E(h, d.clear(), 12); + return E(k, d.clear(), 12); } e = a.commit_task; a.commit_task = []; @@ -3342,45 +3359,45 @@ u.commit = function(a, b, c) { f = void 0; case 4: if (!(g < e.length)) { - h.h = 6; + k.h = 6; break; } f = e[g]; if (!f.clear) { e[g] = f.del; - h.h = 5; + k.h = 5; break; } - return E(h, d.clear(), 8); + return E(k, d.clear(), 8); case 8: b = !0; - h.h = 6; + k.h = 6; break; case 5: g++; - h.h = 4; + k.h = 4; break; case 6: if (b) { - h.h = 3; + k.h = 3; break; } c || (e = e.concat(xa(a.reg))); if (!e.length) { - h.h = 10; + k.h = 10; break; } - return E(h, d.remove(e), 11); + return E(k, d.remove(e), 11); case 11: case 10: - h.h = 3; + k.h = 3; break; case 12: a.commit_task = []; case 3: - return a.reg.size ? E(h, d.transaction("map", "readwrite", function(k) { + return a.reg.size ? E(k, d.transaction("map", "readwrite", function(h) { for (var l = x(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) { + m = m.value, n.Y = m[0], n.O = m[1], n.O.length && (b ? h.put(n.O, n.Y) : h.get(n.Y).onsuccess = function(p) { return function() { var q = this.result, t; if (q && q.length) { @@ -3399,19 +3416,19 @@ u.commit = function(a, b, c) { } else { q = p.O, t = 1; } - t && k.put(q, p.Y); + t && h.put(q, p.Y); }; }(n)); } - }), 13) : h.return(); + }), 13) : k.return(); case 13: - return E(h, d.transaction("ctx", "readwrite", function(k) { + return E(k, d.transaction("ctx", "readwrite", function(h) { for (var l = x(a.ctx), m = l.next(), n = {}; !m.done; n = {V:void 0}, m = l.next()) { m = m.value; n.V = m[0]; m = x(m[1]); for (var p = m.next(), q = {}; !p.done; q = {P:void 0, Z:void 0}, p = m.next()) { - p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? k.put(q.P, n.V + ":" + q.Z) : k.get(n.V + ":" + q.Z).onsuccess = function(t, w) { + p = p.value, q.Z = p[0], q.P = p[1], q.P.length && (b ? h.put(q.P, n.V + ":" + q.Z) : h.get(n.V + ":" + q.Z).onsuccess = function(t, w) { return function() { var r = this.result, A; if (r && r.length) { @@ -3430,7 +3447,7 @@ u.commit = function(a, b, c) { } else { r = t.P, A = 1; } - A && k.put(r, w.V + ":" + t.Z); + A && h.put(r, w.V + ":" + t.Z); }; }(q, n)); } @@ -3438,59 +3455,59 @@ u.commit = function(a, b, c) { }), 14); case 14: if (a.store) { - return E(h, d.transaction("reg", "readwrite", function(k) { + return E(k, d.transaction("reg", "readwrite", function(h) { for (var l = x(a.store), m = l.next(); !m.done; m = l.next()) { var n = m.value; m = n[0]; n = n[1]; - k.put("object" === typeof n ? JSON.stringify(n) : 1, m); + h.put("object" === typeof n ? JSON.stringify(n) : 1, m); } }), 16); } if (a.bypass) { - h.h = 16; + k.h = 16; break; } - return E(h, d.transaction("reg", "readwrite", function(k) { + return E(k, d.transaction("reg", "readwrite", function(h) { for (var l = x(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { - k.put(1, m.value); + h.put(1, m.value); } }), 16); case 16: if (!a.tag) { - h.h = 20; + k.h = 20; break; } - return E(h, d.transaction("tag", "readwrite", function(k) { + return E(k, d.transaction("tag", "readwrite", function(h) { for (var l = x(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) { + m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (h.get(n.ba).onsuccess = function(p) { return function() { var q = this.result; q = q && q.length ? q.concat(p.X) : p.X; - k.put(q, p.ba); + h.put(q, p.ba); }; }(n)); } }), 20); case 20: - a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), h.h = 0; + a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), k.h = 0; } }); }; -function Zb(a, b, c) { - for (var d = a.value, e, g, f = 0, h = 0, k; h < d.length; h++) { - if (k = c ? d : d[h]) { +function $b(a, b, c) { + for (var d = a.value, e, g, f = 0, k = 0, h; k < d.length; k++) { + if (h = c ? d : d[k]) { 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 (e = 1, 1 < k.length) { - k.splice(m, 1); + if (n = b[l], m = h.indexOf(g ? parseInt(n, 10) : n), 0 > m && !g && "string" === typeof n && !isNaN(n) && (m = h.indexOf(parseInt(n, 10))) && (g = 1), 0 <= m) { + if (e = 1, 1 < h.length) { + h.splice(m, 1); } else { - d[h] = []; + d[k] = []; break; } } } - f += k.length; + f += h.length; } if (c) { break; @@ -3501,20 +3518,20 @@ function Zb(a, b, c) { } u.remove = function(a) { "object" !== typeof a && (a = [a]); - return Promise.all([this.transaction("map", "readwrite", function(b) { + return Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Zb(c, a); + c && $b(c, a); }; - }), this.transaction("ctx", "readwrite", function(b) { + }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Zb(c, a); + c && $b(c, a); }; - }), this.transaction("tag", "readwrite", function(b) { + }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Zb(c, a, !0); + c && $b(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3522,20 +3539,20 @@ u.remove = function(a) { } })]); }; -function Wb(a) { +function Xb(a) { return new Promise(function(b, c) { a.onsuccess = function() { b(this.result); }; a.oncomplete = function() { - b(this.result); + b(); }; a.onerror = c; a = null; }); } -;var $b = {Index:P, Charset:Ib, Encoder:Ga, Document:W, Worker:Sa, Resolver:Y, IndexedDB:Vb, Language:{}}, ac = self, bc; -(bc = ac.define) && bc.amd ? bc([], function() { - return $b; -}) : "object" === typeof ac.exports ? ac.exports = $b : ac.FlexSearch = $b; +;var ac = {Index:P, Charset:Ib, Encoder:Ga, Document:W, Worker:Sa, Resolver:Y, IndexedDB:Wb, Language:{}}, bc = "undefined" !== typeof global ? global : self, cc; +(cc = bc.define) && cc.amd ? cc([], function() { + return ac; +}) : "object" === typeof bc.exports ? bc.exports = ac : bc.FlexSearch = ac; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index bf8aa49..1d100c5 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.133 (ES5) + * FlexSearch.js v0.8.135 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -52,89 +52,90 @@ u.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);t 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=Fa?a.normalize("NFKD").replace(Fa,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3=this.minlength&&("function"===typeof this.filter?!this.filter(f):this.filter.has(f))&&(f=""));if(f&&(this.mapper||this.dedupe&&1this.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};var O,Ha; -function Ia(a){var b,c,d,e,g,f;return ta(function(h){switch(h.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Ha=a.options||{};(e=a.factory)?(Function("return "+e)()(self),O=new self.FlexSearch.Index(Ha),delete self.FlexSearch):O=new R(Ha);postMessage({id:c});break;default:h.h=2;return}h.h=0;break;case 2:"export"===b&&(d[1]?(d[0]=Ha.export,d[2]=0,d[3]=1):d=null);if("import"===b){if(!d[0]){h.h=5;break}return E(h,Ha.import.call(O,d[0]),9)}g=d&&O[b].apply(O,d);if(!g||!g.then){h.h=5; -break}return E(h,g,7);case 7:g=h.D;h.h=5;break;case 9:f=h.D,O.import(d[0],f);case 5:postMessage("search"===b?{id:c,msg:g}:{id:c}),h.h=0}})};function La(a){Ma.call(a,"add");Ma.call(a,"append");Ma.call(a,"search");Ma.call(a,"update");Ma.call(a,"remove")}var Na,Oa,Pa;function Qa(){Na=Pa=0} -function Ma(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}Na?Pa||(Pa=Date.now()-Oa>=this.priority*this.priority*3):(Na=setTimeout(Qa,0),Oa=Date.now());if(Pa){var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var Ra=0; -function Sa(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=J();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Ra]=function(){k(e);1E9=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} -function T(a){if(!this||this.constructor!==T)return new T(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=[]; +0;f&&kthis.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};var Ha,Ia; +function Ja(a){var b,c,d,e,g,f;return ta(function(h){switch(h.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Ia=a.options||{};(e=a.factory)?(Function("return "+e)()(self),Ha=new self.FlexSearch.Index(Ia),delete self.FlexSearch):Ha=new O(Ia);postMessage({id:c});break;default:h.h=2;return}h.h=0;break;case 2:"export"===b&&(d[1]?(d[0]=Ia.export,d[2]=0,d[3]=1):d=null);if("import"===b){if(!d[0]){h.h=5;break}return E(h,Ia.import.call(Ha,d[0]),9)}g=d&&Ha[b].apply(Ha,d);if(!g||!g.then){h.h= +5;break}return E(h,g,7);case 7:g=h.D;h.h=5;break;case 9:f=h.D,Ha.import(d[0],f);case 5:postMessage("search"===b?{id:c,msg:g}:{id:c}),h.h=0}})};function Ma(a){Na.call(a,"add");Na.call(a,"append");Na.call(a,"search");Na.call(a,"update");Na.call(a,"remove")}var Oa,Pa,Qa;function Ra(){Oa=Qa=0} +function Na(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]}Oa?Qa||(Qa=Date.now()-Pa>=this.priority*this.priority*3):(Oa=setTimeout(Ra,0),Pa=Date.now());if(Qa){var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var Sa=0; +function Ta(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=J();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Sa]=function(){k(e);1E9=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} +function S(a){if(!this||this.constructor!==S)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[]; for(g=0;gd)d-=f.length;else{if(f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?X.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?X.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=kb(a,c,d,!1,this.h),d=0));return g?this.resolve(c,d,e):this};Y.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var g=b.enrich&&c}}return a?(a=nb(this,"and",arguments),pb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; -function pb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=jb(a,b,c,d,f,this.h,g),g?e?X.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};Y.prototype.xor=function(){var a=nb(this,"xor",arguments);return qb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; -function qb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=rb.call(this,a,c,d,g,this.h),g?e?X.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} -function rb(a,b,c,d,e){for(var g=[],f=J(),h=0,k=0,l;kb?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=lb(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=ob(this,"and",arguments),qb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; +function qb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=kb(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=ob(this,"xor",arguments);return rb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; +function rb(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=sb.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 sb(a,b,c,d,e){for(var g=[],f=J(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=X.call(this,a));return a}}function X(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cc||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)}; -Z.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};Z.prototype.remove=function(a){for(var b=x(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};Z.prototype.clear=function(){this.cache.clear();this.h=""};var Ab={normalize:function(a){return a.toLowerCase()}};var Bb=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 Cb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Db=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Eb={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 Fb=/[\x00-\x7F]+/g;var Gb=/[\x00-\x7F]+/g;var Hb=/[\x00-\x7F]+/g;var Ib={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Ab,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Bb},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Bb,matcher:Cb,replacer:Db},LatinExtra:{normalize:!0,dedupe:!0,mapper:Bb,replacer:Db.concat([/(?!^)[aeo]/g,""]),matcher:Cb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;r--)p=l.substring(n,r),q=this.rtl?m-1-n:n,q=this.score?this.score(b,l,k,p,q):Kb(h,d,k,m,q),Lb(this,g,p, -q,a,c);break}case "reverse":if(1p?0:1),d,k,r-1,q-1),t=this.bidirectional&&l>n;Lb(this, -e,t?n:l,w,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ca&&Mb(this));return this}; -function Lb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=J()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new T(h);if(a.fastupdate)for(c=x(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function Kb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};R.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Rb(this.map,a),this.depth&&Rb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Mb(this));this.cache&&this.cache.remove(a);return this}; -function Rb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(var b=x(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};var Bb={normalize:function(a){return a.toLowerCase()}};var Cb=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Db=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Eb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Fb={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Gb=/[\x00-\x7F]+/g;var Hb=/[\x00-\x7F]+/g;var Ib=/[\x00-\x7F]+/g;var Jb={LatinExact:{split:/\s+/,normalize:!1},LatinDefault:Bb,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Cb},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Cb,matcher:Db,replacer:Eb},LatinExtra:{normalize:!0,dedupe:!0,mapper:Cb,replacer:Eb.concat([/(?!^)[aeo]/g,""]),matcher:Db},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;r--)p=l.substring(n,r),q=this.rtl?m-1-n:n,q=this.score?this.score(b,l,k,p,q):Lb(h,d,k,m,q),Mb(this,g,p, +q,a,c);break}case "reverse":if(1p?0:1),d,k,r-1,q-1),t=this.bidirectional&&l>n;Mb(this, +e,t?n:l,w,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.ca&&Nb(this));return this}; +function Mb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=J()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new S(h);if(a.fastupdate)for(c=x(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +function Lb(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 Sb(this.map,a),this.depth&&Sb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Nb(this));this.cache&&this.cache.remove(a);return this}; +function Sb(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;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,1m&&!g&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(g=1),0<=m)if(e=1,1b)&& function P(a,c){let b=0;if(a.constructor===Array)for(let f=0,d,g;fb.add(a,c)):this.add(a,c)}; function Q(a){let c=0;if(a.constructor===Array)for(let b=0,f;bb)&& function P(a,c){let b=0;if(a.constructor===Array)for(let f=0,d,g;fb.add(a,c)):this.add(a,c)}; function Q(a){let c=0;if(a.constructor===Array)for(let b=0,f;b} -// */ - -// export function create_object_array(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = create_object(); -// } -// -// return array; -// } - -// /** -// * @param {!number} count -// * @returns {Array} -// */ - -// export function create_map_array(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = new Map(); -// } -// -// return array; -// } - -// export function create_arrays(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = []; -// } -// -// return array; -// } -// -// /** -// * @param {!Object} obj -// * @returns {Array} -// */ - -// export function get_keys(obj){ -// return Object.keys(obj); -// } export function create_object() { return Object.create(null); @@ -122,17 +70,6 @@ export function concat(arrays) { return [].concat.apply([], arrays); } -// export function concat(arrays){ -// const final = []; -// for(let i = 0, arr; i < arrays.length; i++){ -// arr = arrays[i]; -// for(let j = 0; j < arr.length; j++){ -// final.push(arr[j]) -// } -// } -// return final; -// } - export function sort_by_length_down(a, b) { return b.length - a.length; } diff --git a/dist/module-debug/db/indexeddb/index.js b/dist/module-debug/db/indexeddb/index.js index 70a1c86..f45d054 100644 --- a/dist/module-debug/db/indexeddb/index.js +++ b/dist/module-debug/db/indexeddb/index.js @@ -8,7 +8,7 @@ const VERSION = 1, fields = ["map", "ctx", "tag", "reg", "cfg"]; import StorageInterface from "../interface.js"; -import { toArray } from "../../common.js"; +import { create_object, toArray } from "../../common.js"; /** * @param {!string} str @@ -18,6 +18,8 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } +const DB = create_object(); + /** * @param {string|PersistentOptions=} name * @param {PersistentOptions=} config @@ -60,10 +62,12 @@ IdxDB.prototype.open = function () { navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function (resolve, reject) { + return this.db || (this.db = new Promise(function (resolve, reject) { - const req = IndexedDB.open(self.id + (self.field ? ":" + self.field : ""), VERSION); + DB[self.id] || (DB[self.id] = []); + DB[self.id].push(self.field); + const req = IndexedDB.open(self.id, VERSION); req.onupgradeneeded = function () { const db = self.db = this.result; @@ -73,11 +77,14 @@ IdxDB.prototype.open = function () { // The schema map:key => [res][id] is currently used instead // In fact that bypass the idea of a storage solution, // IndexedDB is such a poor contribution :( - - fields.forEach(ref => { - db.objectStoreNames.contains(ref) || db.createObjectStore(ref); //{ autoIncrement: true /*keyPath: "id"*/ } - //.createIndex("idx", "ids", { multiEntry: true, unique: false }); - }); + for (let i = 0, ref; i < fields.length; i++) { + ref = fields[i]; + for (let j = 0, field; j < DB[self.id].length; j++) { + field = DB[self.id][j]; + db.objectStoreNames.contains(ref + ("reg" !== ref ? field ? ":" + field : "" : "")) || db.createObjectStore(ref + ("reg" !== ref ? field ? ":" + field : "" : "")); //{ autoIncrement: true /*keyPath: "id"*/ } + //.createIndex("idx", "ids", { multiEntry: true, unique: false }); + } + } // switch(event.oldVersion){ // existing db version // case 0: @@ -110,7 +117,7 @@ IdxDB.prototype.open = function () { }; resolve(self); }; - }); + })); }; IdxDB.prototype.close = function () { @@ -122,7 +129,7 @@ IdxDB.prototype.close = function () { * @return {!Promise} */ IdxDB.prototype.destroy = function () { - const req = IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const req = IndexedDB.deleteDatabase(this.id); return promisfy(req); }; @@ -144,9 +151,21 @@ IdxDB.prototype.destroy = function () { * @return {!Promise} */ IdxDB.prototype.clear = function () { - const transaction = this.db.transaction(fields, "readwrite"); - for (let i = 0; i < fields.length; i++) { - transaction.objectStore(fields[i]).clear(); + + const stores = []; + + for (let i = 0, ref; i < fields.length; i++) { + ref = fields[i]; + for (let j = 0, field; j < DB[this.id].length; j++) { + field = DB[this.id][j]; + stores.push(ref + ("reg" !== ref ? field ? ":" + field : "" : "")); + } + } + + const transaction = this.db.transaction(stores, "readwrite"); + + for (let i = 0; i < stores.length; i++) { + transaction.objectStore(stores[i]).clear(); } return promisfy(transaction); }; @@ -161,8 +180,8 @@ IdxDB.prototype.clear = function () { * @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"), + const transaction = this.db.transaction((ctx ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly"), + map = transaction.objectStore((ctx ? "ctx" : "map") + (this.field ? ":" + this.field : "")), req = map.get(ctx ? ctx + ":" + key : key), self = this; @@ -204,8 +223,8 @@ IdxDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = /* ta * @return {!Promise} */ IdxDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) { - const transaction = this.db.transaction("tag", "readonly"), - map = transaction.objectStore("tag"), + const transaction = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly"), + map = transaction.objectStore("tag" + (this.field ? ":" + this.field : "")), req = map.get(tag), self = this; @@ -279,11 +298,18 @@ IdxDB.prototype.info = function () { IdxDB.prototype.transaction = function (ref, modifier, task) { - let store = this.trx[ref + ":" + modifier]; + const key = ref + ("reg" !== ref ? this.field ? ":" + this.field : "" : ""); + /** + * @type {IDBObjectStore} + */ + let store = this.trx[key + ":" + modifier]; if (store) return task.call(this, store); - let transaction = this.db.transaction(ref, modifier); - this.trx[ref + ":" + modifier] = store = transaction.objectStore(ref); + let transaction = this.db.transaction(key, modifier); + /** + * @type {IDBObjectStore} + */ + this.trx[key + ":" + modifier] = store = transaction.objectStore(key); return new Promise((resolve, reject) => { transaction.onerror = err => { @@ -300,7 +326,7 @@ IdxDB.prototype.transaction = function (ref, modifier, task) { const promise = task.call(this, store); // transactions can just be used within the same event loop // the indexeddb is such a stupid tool :( - this.trx[ref + ":" + modifier] = null; + this.trx[key + ":" + modifier] = null; return promise; }); }; @@ -569,17 +595,17 @@ IdxDB.prototype.remove = function (ids) { ids = [ids]; } - return (/** @type {!Promise} */Promise.all([this.transaction("map", "readwrite", function (store) { + return (/** @type {!Promise} */Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids); }; - }), this.transaction("ctx", "readwrite", function (store) { + }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids); }; - }), this.transaction("tag", "readwrite", function (store) { + }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids, !0); @@ -625,10 +651,9 @@ function promisfy(req, callback) { callback && callback(this.result); resolve(this.result); }; - /** @this {IDBRequest} */ req.oncomplete = function () { - callback && callback(this.result); - resolve(this.result); + callback && callback(); + resolve(); }; req.onerror = reject; req = null; diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index 84eb916..7fb34be 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -389,9 +389,11 @@ Document.prototype.search = function (query, limit, options, _promises) { for (let i = 0, res; i < result_field.length; i++) { + /** @type {SearchResults|EnrichedSearchResults} */ res = result[i]; - if (enrich && res.length && !res[0].doc) { + + if (enrich && res.length && "undefined" == typeof res[0].doc) { if (!this.db) { // if(res.length){ res = apply_enrich.call(this, res); @@ -442,9 +444,11 @@ function highlight_fields(result, query, index, field, tree, template) { let encoder, query_enc, tokenize; - for (let i = 0, res, res_field, enc, idx, path; i < result.length; i++) { + for (let i = 0, res_field, enc, idx, path, res; i < result.length; i++) { + /** @type {SearchResults|EnrichedSearchResults} */ res = result[i].result; + res_field = result[i].field; idx = index.get(res_field); enc = idx.encoder; diff --git a/dist/module-min/bundle.js b/dist/module-min/bundle.js index 95a786a..cad799e 100644 --- a/dist/module-min/bundle.js +++ b/dist/module-min/bundle.js @@ -1 +1 @@ -import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreArray,KeystoreSet}from"./keystore.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.encoder,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Document.prototype.field,Document.prototype.index,Document.prototype.reg,Document.prototype.tag,Document.prototype.store,Document.prototype.fastupdate,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,KeystoreArray.length,KeystoreMap.size,KeystoreSet.size,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.worker,IndexOptions.config,IndexOptions.priority,IndexOptions.export,IndexOptions.import,FieldOptions.preset,FieldOptions.context,FieldOptions.encoder,FieldOptions.encode,FieldOptions.resolution,FieldOptions.tokenize,FieldOptions.fastupdate,FieldOptions.score,FieldOptions.keystore,FieldOptions.rtl,FieldOptions.cache,FieldOptions.db,FieldOptions.config,FieldOptions.resolve,FieldOptions.field,FieldOptions.filter,FieldOptions.custom,FieldOptions.worker,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,DocumentOptions.priority,DocumentOptions.export,DocumentOptions.import,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,DocumentDescriptor.id,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{const a=self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch}export default FlexSearch;export{Index,Document,Encoder,Charset,WorkerIndex as Worker,Resolver,IdxDB as IndexedDB}; \ No newline at end of file +import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,FieldOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions,ResolverOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreArray,KeystoreSet}from"./keystore.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.encoder,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Encoder.prototype.assign,Encoder.prototype.encode,Encoder.prototype.addMatcher,Encoder.prototype.addStemmer,Encoder.prototype.addFilter,Encoder.prototype.addMapper,Encoder.prototype.addReplacer,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Document.prototype.field,Document.prototype.index,Document.prototype.reg,Document.prototype.tag,Document.prototype.store,Document.prototype.fastupdate,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,Resolver.prototype.result,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.fastupdate,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,KeystoreArray.length,KeystoreMap.size,KeystoreSet.size,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.worker,IndexOptions.config,IndexOptions.priority,IndexOptions.export,IndexOptions.import,FieldOptions.preset,FieldOptions.context,FieldOptions.encoder,FieldOptions.encode,FieldOptions.resolution,FieldOptions.tokenize,FieldOptions.fastupdate,FieldOptions.score,FieldOptions.keystore,FieldOptions.rtl,FieldOptions.cache,FieldOptions.db,FieldOptions.config,FieldOptions.resolve,FieldOptions.field,FieldOptions.filter,FieldOptions.custom,FieldOptions.worker,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,DocumentOptions.priority,DocumentOptions.export,DocumentOptions.import,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,DocumentDescriptor.id,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,SearchOptions.resolution,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,DocumentSearchOptions.highlight,EncoderOptions.rtl,EncoderOptions.dedupe,EncoderOptions.split,EncoderOptions.include,EncoderOptions.exclude,EncoderOptions.prepare,EncoderOptions.finalize,EncoderOptions.filter,EncoderOptions.matcher,EncoderOptions.mapper,EncoderOptions.stemmer,EncoderOptions.replacer,EncoderOptions.minlength,EncoderOptions.maxlength,EncoderOptions.cache,EncoderSplitOptions.letter,EncoderSplitOptions.number,EncoderSplitOptions.symbol,EncoderSplitOptions.punctuation,EncoderSplitOptions.control,EncoderSplitOptions.char,PersistentOptions.name,PersistentOptions.field,PersistentOptions.type,PersistentOptions.db,ResolverOptions.index,ResolverOptions.query,ResolverOptions.limit,ResolverOptions.offset,ResolverOptions.enrich,ResolverOptions.resolve,ResolverOptions.suggest,ResolverOptions.and,ResolverOptions.or,ResolverOptions.xor,ResolverOptions.not;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{const a="undefined"==typeof global?self:global;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/db/indexeddb/index.js b/dist/module-min/db/indexeddb/index.js index 2a73367..b4daa98 100644 --- a/dist/module-min/db/indexeddb/index.js +++ b/dist/module-min/db/indexeddb/index.js @@ -1 +1 @@ -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&&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=a=>{e.abort(),e=d=null,g(a)},e.oncomplete=a=>{e=d=null,f(a||!0)};const h=c.call(this,d);return this.trx[a+":"+b]=null,h})},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{create_object,toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}const DB=create_object();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||(this.db=new Promise(function(b,c){DB[a.id]||(DB[a.id]=[]),DB[a.id].push(a.field);const d=IndexedDB.open(a.id,VERSION);d.onupgradeneeded=function(){const b=a.db=this.result;for(let c,d=0;d=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{f.onerror=a=>{f.abort(),f=e=null,g(a)},f.oncomplete=b=>{f=e=null,a(b||!0)};const h=c.call(this,e);return this.trx[d+":"+b]=null,h})},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(),c()},a.onerror=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/document/search.js b/dist/module-min/document/search.js index fc963ef..e037058 100644 --- a/dist/module-min/document/search.js +++ b/dist/module-min/document/search.js @@ -1 +1 @@ -import{DocumentSearchOptions,DocumentSearchResults,EnrichedDocumentSearchResults,MergedDocumentSearchResults,MergedDocumentSearchEntry,EnrichedSearchResults,SearchResults,IntermediateSearchResults}from"../type.js";import{create_object,is_array,is_object,is_string,parse_simple}from"../common.js";import{intersect_union}from"../intersect.js";import Document from"../document.js";import Index from"../index.js";import Resolver from"../resolver.js";import tick from"../profiler.js";Document.prototype.search=function(a,b,c,d){!1,c||(!b&&is_object(a)?(c=a,a=""):is_object(b)&&(c=b,b=0));let e,f,g,h,j,k,l,m,n=[],o=[],p=0,q=!0;if(c){if(is_array(c)&&(c={index:c}),a=c.query||a,e=c.pluck,g=c.merge,j=e||c.field||(j=c.index)&&(j.index?null:j),k=this.tag&&c.tag,h=c.suggest,q=!1!==c.resolve,(q||e||(j=j||this.field,j&&(is_string(j)?e=j:(is_array(j)&&1===j.length&&(j=j[0]),e=j.field||j.index))),!1,f=this.store&&c.enrich&&q,m=f&&c.highlight,b=c.limit||b,l=c.offset||0,b||(b=100),k&&(!this.db||!d))){!1,k.constructor!==Array&&(k=[k]);let c=[];for(let a,b=0;b} -// */ - -// export function create_object_array(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = create_object(); -// } -// -// return array; -// } - -// /** -// * @param {!number} count -// * @returns {Array} -// */ - -// export function create_map_array(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = new Map(); -// } -// -// return array; -// } - -// export function create_arrays(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = []; -// } -// -// return array; -// } -// -// /** -// * @param {!Object} obj -// * @returns {Array} -// */ - -// export function get_keys(obj){ -// return Object.keys(obj); -// } export function create_object() { return Object.create(null); @@ -122,17 +70,6 @@ export function concat(arrays) { return [].concat.apply([], arrays); } -// export function concat(arrays){ -// const final = []; -// for(let i = 0, arr; i < arrays.length; i++){ -// arr = arrays[i]; -// for(let j = 0; j < arr.length; j++){ -// final.push(arr[j]) -// } -// } -// return final; -// } - export function sort_by_length_down(a, b) { return b.length - a.length; } diff --git a/dist/module/db/indexeddb/index.js b/dist/module/db/indexeddb/index.js index 70a1c86..f45d054 100644 --- a/dist/module/db/indexeddb/index.js +++ b/dist/module/db/indexeddb/index.js @@ -8,7 +8,7 @@ const VERSION = 1, fields = ["map", "ctx", "tag", "reg", "cfg"]; import StorageInterface from "../interface.js"; -import { toArray } from "../../common.js"; +import { create_object, toArray } from "../../common.js"; /** * @param {!string} str @@ -18,6 +18,8 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } +const DB = create_object(); + /** * @param {string|PersistentOptions=} name * @param {PersistentOptions=} config @@ -60,10 +62,12 @@ IdxDB.prototype.open = function () { navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function (resolve, reject) { + return this.db || (this.db = new Promise(function (resolve, reject) { - const req = IndexedDB.open(self.id + (self.field ? ":" + self.field : ""), VERSION); + DB[self.id] || (DB[self.id] = []); + DB[self.id].push(self.field); + const req = IndexedDB.open(self.id, VERSION); req.onupgradeneeded = function () { const db = self.db = this.result; @@ -73,11 +77,14 @@ IdxDB.prototype.open = function () { // The schema map:key => [res][id] is currently used instead // In fact that bypass the idea of a storage solution, // IndexedDB is such a poor contribution :( - - fields.forEach(ref => { - db.objectStoreNames.contains(ref) || db.createObjectStore(ref); //{ autoIncrement: true /*keyPath: "id"*/ } - //.createIndex("idx", "ids", { multiEntry: true, unique: false }); - }); + for (let i = 0, ref; i < fields.length; i++) { + ref = fields[i]; + for (let j = 0, field; j < DB[self.id].length; j++) { + field = DB[self.id][j]; + db.objectStoreNames.contains(ref + ("reg" !== ref ? field ? ":" + field : "" : "")) || db.createObjectStore(ref + ("reg" !== ref ? field ? ":" + field : "" : "")); //{ autoIncrement: true /*keyPath: "id"*/ } + //.createIndex("idx", "ids", { multiEntry: true, unique: false }); + } + } // switch(event.oldVersion){ // existing db version // case 0: @@ -110,7 +117,7 @@ IdxDB.prototype.open = function () { }; resolve(self); }; - }); + })); }; IdxDB.prototype.close = function () { @@ -122,7 +129,7 @@ IdxDB.prototype.close = function () { * @return {!Promise} */ IdxDB.prototype.destroy = function () { - const req = IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const req = IndexedDB.deleteDatabase(this.id); return promisfy(req); }; @@ -144,9 +151,21 @@ IdxDB.prototype.destroy = function () { * @return {!Promise} */ IdxDB.prototype.clear = function () { - const transaction = this.db.transaction(fields, "readwrite"); - for (let i = 0; i < fields.length; i++) { - transaction.objectStore(fields[i]).clear(); + + const stores = []; + + for (let i = 0, ref; i < fields.length; i++) { + ref = fields[i]; + for (let j = 0, field; j < DB[this.id].length; j++) { + field = DB[this.id][j]; + stores.push(ref + ("reg" !== ref ? field ? ":" + field : "" : "")); + } + } + + const transaction = this.db.transaction(stores, "readwrite"); + + for (let i = 0; i < stores.length; i++) { + transaction.objectStore(stores[i]).clear(); } return promisfy(transaction); }; @@ -161,8 +180,8 @@ IdxDB.prototype.clear = function () { * @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"), + const transaction = this.db.transaction((ctx ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly"), + map = transaction.objectStore((ctx ? "ctx" : "map") + (this.field ? ":" + this.field : "")), req = map.get(ctx ? ctx + ":" + key : key), self = this; @@ -204,8 +223,8 @@ IdxDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = /* ta * @return {!Promise} */ IdxDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) { - const transaction = this.db.transaction("tag", "readonly"), - map = transaction.objectStore("tag"), + const transaction = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly"), + map = transaction.objectStore("tag" + (this.field ? ":" + this.field : "")), req = map.get(tag), self = this; @@ -279,11 +298,18 @@ IdxDB.prototype.info = function () { IdxDB.prototype.transaction = function (ref, modifier, task) { - let store = this.trx[ref + ":" + modifier]; + const key = ref + ("reg" !== ref ? this.field ? ":" + this.field : "" : ""); + /** + * @type {IDBObjectStore} + */ + let store = this.trx[key + ":" + modifier]; if (store) return task.call(this, store); - let transaction = this.db.transaction(ref, modifier); - this.trx[ref + ":" + modifier] = store = transaction.objectStore(ref); + let transaction = this.db.transaction(key, modifier); + /** + * @type {IDBObjectStore} + */ + this.trx[key + ":" + modifier] = store = transaction.objectStore(key); return new Promise((resolve, reject) => { transaction.onerror = err => { @@ -300,7 +326,7 @@ IdxDB.prototype.transaction = function (ref, modifier, task) { const promise = task.call(this, store); // transactions can just be used within the same event loop // the indexeddb is such a stupid tool :( - this.trx[ref + ":" + modifier] = null; + this.trx[key + ":" + modifier] = null; return promise; }); }; @@ -569,17 +595,17 @@ IdxDB.prototype.remove = function (ids) { ids = [ids]; } - return (/** @type {!Promise} */Promise.all([this.transaction("map", "readwrite", function (store) { + return (/** @type {!Promise} */Promise.all([this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids); }; - }), this.transaction("ctx", "readwrite", function (store) { + }), this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids); }; - }), this.transaction("tag", "readwrite", function (store) { + }), this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function (store) { store.openCursor().onsuccess = function () { const cursor = this.result; cursor && handle(cursor, ids, !0); @@ -625,10 +651,9 @@ function promisfy(req, callback) { callback && callback(this.result); resolve(this.result); }; - /** @this {IDBRequest} */ req.oncomplete = function () { - callback && callback(this.result); - resolve(this.result); + callback && callback(); + resolve(); }; req.onerror = reject; req = null; diff --git a/dist/module/document/search.js b/dist/module/document/search.js index c02a35b..fff691c 100644 --- a/dist/module/document/search.js +++ b/dist/module/document/search.js @@ -369,9 +369,11 @@ Document.prototype.search = function (query, limit, options, _promises) { for (let i = 0, res; i < result_field.length; i++) { + /** @type {SearchResults|EnrichedSearchResults} */ res = result[i]; - if (enrich && res.length && !res[0].doc) { + + if (enrich && res.length && "undefined" == typeof res[0].doc) { if (!this.db) { // if(res.length){ res = apply_enrich.call(this, res); @@ -422,9 +424,11 @@ function highlight_fields(result, query, index, field, tree, template) { let encoder, query_enc, tokenize; - for (let i = 0, res, res_field, enc, idx, path; i < result.length; i++) { + for (let i = 0, res_field, enc, idx, path, res; i < result.length; i++) { + /** @type {SearchResults|EnrichedSearchResults} */ res = result[i].result; + res_field = result[i].field; idx = index.get(res_field); enc = idx.encoder; diff --git a/package-lock.json b/package-lock.json index 417ac94..38168b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.133", + "version": "0.8.135", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.133", + "version": "0.8.135", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 9617dbc..2595deb 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.133", + "version": "0.8.135", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/src/bundle.js b/src/bundle.js index 4789dea..cdd8669 100644 --- a/src/bundle.js +++ b/src/bundle.js @@ -318,13 +318,13 @@ if(RELEASE !== "bundle.module" && RELEASE !== "compact.module" && RELEASE !== "custom.module"){ - // When it is not a module, the package is for Node.js or legacy Browser - // Here there exists this or self - // const root = typeof self !== "undefined" ? self : - // typeof global !== "undefined" ? global : - // typeof window !== "undefined" ? window : {}; - - const root = self; + // Legacy Browser: this refers to window + // ESM Browser: self refers to window + // NodeJS: global refers to the global scope + const root = typeof global !== "undefined" ? global : + //typeof window !== "undefined" ? window : + self; + //const root = self; let prop; // AMD (RequireJS) diff --git a/src/common.js b/src/common.js index 99dff3a..bad0c3f 100644 --- a/src/common.js +++ b/src/common.js @@ -63,58 +63,6 @@ export function merge_option(value, default_value, merge_value){ ? default_value : value; } -// -// /** -// * @param {!number} count -// * @returns {Array} -// */ - -// export function create_object_array(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = create_object(); -// } -// -// return array; -// } - -// /** -// * @param {!number} count -// * @returns {Array} -// */ - -// export function create_map_array(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = new Map(); -// } -// -// return array; -// } - -// export function create_arrays(count){ -// -// const array = new Array(count); -// -// for(let i = 0; i < count; i++){ -// array[i] = []; -// } -// -// return array; -// } -// -// /** -// * @param {!Object} obj -// * @returns {Array} -// */ - -// export function get_keys(obj){ -// return Object.keys(obj); -// } export function create_object(){ return Object.create(null); @@ -124,17 +72,6 @@ export function concat(arrays){ return [].concat.apply([], arrays); } -// export function concat(arrays){ -// const final = []; -// for(let i = 0, arr; i < arrays.length; i++){ -// arr = arrays[i]; -// for(let j = 0; j < arr.length; j++){ -// final.push(arr[j]) -// } -// } -// return final; -// } - export function sort_by_length_down(a, b){ return b.length - a.length; } diff --git a/src/db/indexeddb/index.js b/src/db/indexeddb/index.js index ad1dc00..bb0ff67 100644 --- a/src/db/indexeddb/index.js +++ b/src/db/indexeddb/index.js @@ -30,7 +30,7 @@ const IDBKeyRange = typeof window !== "undefined" && ( ); const fields = ["map", "ctx", "tag", "reg", "cfg"]; import StorageInterface from "../interface.js"; -import { toArray } from "../../common.js"; +import { create_object, toArray } from "../../common.js"; /** * @param {!string} str @@ -40,6 +40,8 @@ function sanitize(str) { return str.toLowerCase().replace(/[^a-z0-9_\-]/g, ""); } +const DB = create_object(); + /** * @param {string|PersistentOptions=} name * @param {PersistentOptions=} config @@ -83,10 +85,12 @@ IdxDB.prototype.open = function(){ navigator.storage && navigator.storage.persist(); - return this.db || new Promise(function(resolve, reject){ + return this.db || (this.db = new Promise(function(resolve, reject){ - const req = IndexedDB.open(self.id + (self.field ? ":" + self.field : ""), VERSION); + DB[self.id] || (DB[self.id] = []); + DB[self.id].push(self.field); + const req = IndexedDB.open(self.id, VERSION); req.onupgradeneeded = function(event){ const db = self.db = this.result; @@ -96,12 +100,15 @@ IdxDB.prototype.open = function(){ // The schema map:key => [res][id] is currently used instead // In fact that bypass the idea of a storage solution, // IndexedDB is such a poor contribution :( - - fields.forEach(ref => { - db.objectStoreNames.contains(ref) || - db.createObjectStore(ref);//{ autoIncrement: true /*keyPath: "id"*/ } - //.createIndex("idx", "ids", { multiEntry: true, unique: false }); - }); + for(let i = 0, ref; i < fields.length; i++){ + ref = fields[i]; + for(let j = 0, field; j < DB[self.id].length; j++){ + field = DB[self.id][j]; + db.objectStoreNames.contains(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")) || + db.createObjectStore(ref + (ref !== "reg" ? (field ? ":" + field : "") : ""));//{ autoIncrement: true /*keyPath: "id"*/ } + //.createIndex("idx", "ids", { multiEntry: true, unique: false }); + } + } // switch(event.oldVersion){ // existing db version // case 0: @@ -134,7 +141,7 @@ IdxDB.prototype.open = function(){ }; resolve(self); }; - }); + })); }; IdxDB.prototype.close = function(){ @@ -146,7 +153,7 @@ IdxDB.prototype.close = function(){ * @return {!Promise} */ IdxDB.prototype.destroy = function(){ - const req = IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + const req = IndexedDB.deleteDatabase(this.id); return promisfy(req); }; @@ -168,9 +175,21 @@ IdxDB.prototype.destroy = function(){ * @return {!Promise} */ IdxDB.prototype.clear = function(){ - const transaction = this.db.transaction(fields, "readwrite"); - for(let i = 0; i < fields.length; i++){ - transaction.objectStore(fields[i]).clear(); + + const stores = []; + + for(let i = 0, ref; i < fields.length; i++){ + ref = fields[i]; + for(let j = 0, field; j < DB[this.id].length; j++){ + field = DB[this.id][j]; + stores.push(ref + (ref !== "reg" ? (field ? ":" + field : "") : "")); + } + } + + const transaction = this.db.transaction(stores, "readwrite"); + + for(let i = 0; i < stores.length; i++){ + transaction.objectStore(stores[i]).clear(); } return promisfy(transaction); }; @@ -185,8 +204,8 @@ IdxDB.prototype.clear = function(){ * @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"); + const transaction = this.db.transaction((ctx ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly"); + const map = transaction.objectStore((ctx ? "ctx" : "map") + (this.field ? ":" + this.field : "")); const req = map.get(ctx ? ctx + ":" + key : key); const self = this; return promisfy(req).then(function(res){ @@ -234,8 +253,8 @@ if(SUPPORT_TAGS){ * @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"); + const transaction = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly"); + const map = transaction.objectStore("tag" + (this.field ? ":" + this.field : "")); const req = map.get(tag); const self = this; return promisfy(req).then(function(ids){ @@ -268,8 +287,8 @@ if(SUPPORT_STORE){ return Promise.all(promises).then(function(docs){ for(let i = 0; i < docs.length; i++){ docs[i] = { - id: ids[i], - doc: docs[i] ? JSON.parse(docs[i]) : null + "id": ids[i], + "doc": docs[i] ? JSON.parse(docs[i]) : null }; } return docs; @@ -311,11 +330,18 @@ IdxDB.prototype.info = function(){ IdxDB.prototype.transaction = function(ref, modifier, task){ - let store = this.trx[ref + ":" + modifier]; + const key = ref + (ref !== "reg" ? (this.field ? ":" + this.field : "") : ""); + /** + * @type {IDBObjectStore} + */ + let store = this.trx[key + ":" + modifier]; if(store) return task.call(this, store); - let transaction = this.db.transaction(ref, modifier); - this.trx[ref + ":" + modifier] = store = transaction.objectStore(ref); + let transaction = this.db.transaction(key, modifier); + /** + * @type {IDBObjectStore} + */ + this.trx[key + ":" + modifier] = store = transaction.objectStore(key); return new Promise((resolve, reject) => { transaction.onerror = (err) => { @@ -332,7 +358,7 @@ IdxDB.prototype.transaction = function(ref, modifier, task){ const promise = task.call(this, store); // transactions can just be used within the same event loop // the indexeddb is such a stupid tool :( - this.trx[ref+ ":" + modifier] = null; + this.trx[key + ":" + modifier] = null; return promise; }); }; @@ -615,19 +641,19 @@ IdxDB.prototype.remove = function(ids){ } return /** @type {!Promise} */(Promise.all([ - this.transaction("map", "readwrite", function(store){ + this.transaction("map" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids); }; }), - this.transaction("ctx", "readwrite", function(store){ + this.transaction("ctx" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids); }; }), - SUPPORT_TAGS && this.transaction("tag", "readwrite", function(store){ + SUPPORT_TAGS && this.transaction("tag" + (this.field ? ":" + this.field : ""), "readwrite", function(store){ store.openCursor().onsuccess = function(){ const cursor = this.result; cursor && handle(cursor, ids, /* tag? */ true); @@ -672,10 +698,9 @@ function promisfy(req, callback){ callback && callback(this.result); resolve(this.result); }; - /** @this {IDBRequest} */ req.oncomplete = function(){ - callback && callback(this.result); - resolve(this.result); + callback && callback(); + resolve(); }; req.onerror = reject; req = null; diff --git a/src/document.js b/src/document.js index 8bdd1c2..2c5b885 100644 --- a/src/document.js +++ b/src/document.js @@ -508,7 +508,7 @@ if(SUPPORT_STORE){ if(SUPPORT_PERSISTENT && this.db){ return this.index.get(this.field[0]).db.enrich(id).then(function(result){ - return result[0] && result[0].doc; + return result[0] && result[0]["doc"]; }); } diff --git a/src/document/search.js b/src/document/search.js index 70e0bb4..314e440 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -437,11 +437,12 @@ Document.prototype.search = function(query, limit, options, _promises){ promises = []; - for(let i = 0, res; i < result_field.length; i++){ + for(let i = 0; i < result_field.length; i++){ - res = result[i]; + /** @type {SearchResults|EnrichedSearchResults} */ + let res = result[i]; - if(enrich && res.length && !res[0].doc){ + if(enrich && res.length && typeof res[0]["doc"] === "undefined"){ if(!SUPPORT_PERSISTENT || !this.db){ // if(res.length){ res = apply_enrich.call(this, res); @@ -505,9 +506,10 @@ function highlight_fields(result, query, index, field, tree, template, limit, of let query_enc; let tokenize; - for(let i = 0, res, res_field, enc, idx, path; i < result.length; i++){ + for(let i = 0, res_field, enc, idx, path; i < result.length; i++){ - res = result[i].result; + /** @type {SearchResults|EnrichedSearchResults} */ + let res = result[i].result; res_field = result[i].field; idx = index.get(res_field); enc = idx.encoder; @@ -521,7 +523,7 @@ function highlight_fields(result, query, index, field, tree, template, limit, of for(let j = 0; j < res.length; j++){ let str = ""; - let content = parse_simple(res[j].doc, path); + let content = parse_simple(res[j]["doc"], path); let doc_enc = encoder.encode(content); let doc_org = content.split(encoder.split); @@ -595,7 +597,7 @@ function merge_fields(fields, limit, offset){ "id": entry }; } - id = entry.id; + id = entry["id"]; tmp = set[id]; if(!tmp){ // offset was already applied on field indexes @@ -653,7 +655,7 @@ function get_tag(tag, key, limit, offset, enrich){ export function apply_enrich(ids){ - if(!this || !this.store) return ids; + if(!SUPPORT_PERSISTENT || !this || !this.store) return ids; /** @type {EnrichedSearchResults} */ const result = new Array(ids.length); diff --git a/task/build.js b/task/build.js index 862661d..df5727f 100644 --- a/task/build.js +++ b/task/build.js @@ -443,6 +443,8 @@ else (async function(){ // replace the eval wrapper build = build.replace(/\(0,eval\)\('([^']+)'\)/g, "$1"); + if(build.includes("console.log")) console.warn("\n!!! Console was used in build !!!\n"); + fs.writeFileSync(filename, build); fs.existsSync("dist/node/") || fs.mkdirSync("dist/node/"); fs.copyFileSync("src/worker/node.js", "dist/node/node.js"); diff --git a/test/package.json b/test/package.json new file mode 100644 index 0000000..2d3b8d4 --- /dev/null +++ b/test/package.json @@ -0,0 +1,22 @@ +{ + "name": "flexsearch-test", + "scripts": { + "test": "mocha test/*.js --exit", + "test:coverage": "c8 -c test/.c8rc.json mocha test/*.js --exit", + "test:keystore": "set NODE_OPTIONS=--max-old-space-size=16000 && c8 -c test/.c8rc.json mocha test/keystore.js --exit", + "test:db": "c8 -c test/.c8rc.json mocha test/persistent.*.js --exit", + "test:all": "npx mocha test/*.js --exit module/bundle && npx mocha test/*.js --exit module-debug/bundle && npx mocha test/*.js --exit module-min/bundle && npx mocha test/*.js --exit flexsearch.bundle.debug && npx mocha test/*.js --exit flexsearch.bundle.min && npx mocha test/*.js --exit flexsearch.bundle.module.debug && npx mocha test/*.js --exit flexsearch.bundle.module.min && npx mocha test/*.js --exit flexsearch.compact.debug && npx mocha test/*.js --exit flexsearch.compact.min && npx mocha test/*.js --exit flexsearch.compact.module.debug && npx mocha test/*.js --exit flexsearch.compact.module.min && npx mocha test/*.js --exit flexsearch.es5.debug && npx mocha test/*.js --exit flexsearch.es5.min && npx mocha test/*.js --exit flexsearch.light.debug && npx mocha test/*.js --exit flexsearch.light.min && npx mocha test/*.js --exit flexsearch.light.module.debug && npx mocha test/*.js --exit flexsearch.light.module.min" + }, + "devDependencies": { + "c8": "^10.1.3", + "chai": "^5.2.0", + "mocha": "^11.1.0", + "flexsearch": "^0.8.117", + "pg-promise": "^11.10.2", + "redis": "^4.7.0", + "mongodb": "^6.13.0", + "rollup": "^4.35.0", + "sqlite3": "^5.1.7", + "clickhouse": "^2.6.0" + } +}