diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 1e152f7..17603be 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -138,12 +138,12 @@ G.prototype.assign = function(a) { this.minlength = y(a.minlength, 1, this.minlength); this.maxlength = y(a.maxlength, 0, this.maxlength); if (this.cache = c = y(a.cache, !0, this.cache)) { - this.L = null, this.T = "number" === typeof c ? c : 2e5, this.H = new Map(), this.J = new Map(), this.A = this.h = 128; + this.L = null, this.S = "number" === typeof c ? c : 2e5, this.H = new Map(), this.J = new Map(), this.A = this.h = 128; } this.B = ""; - this.P = null; + this.O = null; this.M = ""; - this.R = null; + this.P = null; if (this.matcher) { for (const d of this.matcher.keys()) { this.B += (this.B ? "|" : "") + d; @@ -197,8 +197,8 @@ G.prototype.encode = function(a) { } } let k; - this.stemmer && 2 < g.length && (this.R || (this.R = new RegExp("(?!^)(" + this.M + ")$")), g = g.replace(this.R, l => this.stemmer.get(l)), k = 1); - this.matcher && 1 < g.length && (this.P || (this.P = new RegExp("(" + this.B + ")", "g")), g = g.replace(this.P, l => this.matcher.get(l)), k = 1); + this.stemmer && 2 < g.length && (this.P || (this.P = new RegExp("(?!^)(" + this.M + ")$")), g = g.replace(this.P, l => this.stemmer.get(l)), k = 1); + this.matcher && 1 < g.length && (this.O || (this.O = new RegExp("(" + this.B + ")", "g")), g = g.replace(this.O, l => this.matcher.get(l)), k = 1); g && k && (g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); if (g && (this.mapper || this.dedupe && 1 < g.length)) { e = ""; @@ -212,11 +212,11 @@ G.prototype.encode = function(a) { g = g.replace(this.replacer[e], this.replacer[e + 1]); } } - this.cache && h.length <= this.A && (this.J.set(h, g), this.J.size > this.T && (this.J.clear(), this.A = this.A / 1.1 | 0)); + this.cache && h.length <= this.A && (this.J.set(h, g), this.J.size > this.S && (this.J.clear(), this.A = this.A / 1.1 | 0)); g && c.push(g); } this.finalize && (c = this.finalize(c) || c); - this.cache && a.length <= this.h && (this.H.set(a, c), this.H.size > this.T && (this.H.clear(), this.h = this.h / 1.1 | 0)); + this.cache && a.length <= this.h && (this.H.set(a, c), this.H.size > this.S && (this.H.clear(), this.h = this.h / 1.1 | 0)); return c; }; function la(a) { @@ -542,7 +542,7 @@ O.prototype.add = function(a, b, c, d) { } default: if (Q(this, m, p, f, a, c), n && 1 < d && r < d - 1) { - for (e = z(), g = this.S, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) { + for (e = z(), g = this.R, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) { if ((p = b[this.rtl ? d - 1 - r - k : r + k]) && !e[p]) { e[p] = 1; const t = this.score ? this.score(b, f, r, p, k) : P(g + (d / 2 > g ? 0 : 1), d, r, h - 1, k - 1), x = this.bidirectional && p > f; @@ -558,7 +558,7 @@ O.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.U && Ca(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && Ca(this)); return this; }; function Q(a, b, c, d, e, f, g) { @@ -1132,7 +1132,7 @@ O.prototype.search = function(a, b, c) { return async function() { for (let t, x; q < e; q++) { x = a[q]; - r ? (t = await V(p, x, r), t = Ka(t, d, f, p.S, b, g, 2 === e), f && !1 === t && d.length || (r = x)) : (t = await V(p, x), t = Ka(t, d, f, p.resolution, b, g, 1 === e)); + r ? (t = await V(p, x, r, 0, 0, !1, !1), t = Ka(t, d, f, p.R), f && !1 === t && d.length || (r = x)) : (t = await V(p, x, "", 0, 0, !1, !1), t = Ka(t, d, f, p.resolution)); if (t) { return t; } @@ -1156,7 +1156,7 @@ O.prototype.search = function(a, b, c) { } for (let p, t; q < e; q++) { t = a[q]; - r ? (p = V(this, t, r), p = Ka(p, d, f, this.S, b, g, 2 === e), f && !1 === p && d.length || (r = t)) : (p = V(this, t), p = Ka(p, d, f, this.resolution, b, g, 1 === e)); + r ? (p = V(this, t, r, 0, 0, !1, !1), p = Ka(p, d, f, this.R), f && !1 === p && d.length || (r = t)) : (p = V(this, t, "", 0, 0, !1, !1), p = Ka(p, d, f, this.resolution)); if (p) { return p; } @@ -1184,26 +1184,19 @@ function U(a, b, c, d, e, f, g) { return e ? h : h && h.length ? e ? R(h, c, d) : new S(h) : e ? [] : new S([]); }) : a && a.length ? e ? R(a, c, d) : new S(a) : e ? [] : new S([]); } -function Ka(a, b, c, d, e, f, g) { - let h = []; +function Ka(a, b, c, d) { + let e = []; if (a) { d = Math.min(a.length, d); - for (let k = 0, l = 0, m; k < d; k++) { - if (m = a[k]) { - if (f && m && g && (m.length <= f ? (f -= m.length, m = null) : (m = m.slice(f), f = 0)), m && (h[k] = m, g && (l += m.length, l >= e))) { - break; - } - } + for (let f = 0, g; f < d; f++) { + (g = a[f]) && g && (e[f] = g); } - if (h.length) { - if (g) { - return R(h, e, 0); - } - b.push(h); + if (e.length) { + b.push(e); return; } } - return !c && h; + return !c && e; } function V(a, b, c, d, e, f, g, h) { let k; @@ -1233,7 +1226,7 @@ function V(a, b, c, d, e, f, g, h) { } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.U && Ca(this)); + this.db && (this.commit_task.push({del:a}), this.T && Ca(this)); this.cache && this.cache.remove(a); return this; }; @@ -1269,7 +1262,7 @@ function La(a, b) { a = {}; } c = a.context || {}; - const d = a.encode || a.encoder || na; + const d = B(a.encoder) ? va[a.encoder] : a.encode || a.encoder || na; this.encoder = d.encode ? d : "object" === typeof d ? new G(d) : {encode:d}; let e; this.resolution = a.resolution || 9; @@ -1282,14 +1275,14 @@ function La(a, b) { this.map = e ? new L(e) : new Map(); this.ctx = e ? new L(e) : new Map(); this.reg = b || (this.fastupdate ? e ? new L(e) : new Map() : e ? new M(e) : new Set()); - this.S = c.resolution || 1; + this.R = c.resolution || 1; this.rtl = d.rtl || a.rtl || !1; this.cache = (e = a.cache || null) && new H(e); this.resolve = !1 !== a.resolve; if (e = a.db) { - this.db = e.mount(this); + this.db = this.mount(e); } - this.U = !1 !== a.commit; + this.T = !1 !== a.commit; this.commit_task = []; this.commit_timer = null; } @@ -1476,35 +1469,39 @@ async function Na(a) { } } ;let Oa = 0; -function W(a) { +function W(a = {}) { + function b(f) { + function g(h) { + h = h.data || h; + const k = h.id, l = k && e.h[k]; + l && (l(h.msg), delete e.h[k]); + } + this.worker = f || Pa(c, d, a.worker); + if (this.worker.then) { + return this.worker.then(b); + } + this.h = z(); + if (this.worker) { + d ? this.worker.on("message", g) : this.worker.onmessage = g; + if (a.config) { + return new Promise(function(h) { + e.h[++Oa] = function() { + h(e); + }; + e.worker.postMessage({id:Oa, task:"init", factory:c, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:c, options:a}); + return this.worker; + } + } if (!this) { return new W(a); } - a || (a = {}); - let b = "undefined" !== typeof self && (self || window)._factory; - b && (b = b.toString()); - const c = "undefined" === typeof window, d = this; - (async function() { - function e(f) { - f = f.data || f; - const g = f.id, h = g && d.N[g]; - h && (h(f.msg), delete d.N[g]); - } - this.worker = await Pa(b, c, a.worker); - this.N = z(); - if (this.worker) { - c ? this.worker.on("message", e) : this.worker.onmessage = e; - if (a.config) { - return delete a.db, new Promise(function(f) { - d.N[++Oa] = function() { - f(d); - }; - d.worker.postMessage({id:Oa, task:"init", factory:b, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:b, options:a}); - } - }).call(this); + let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + c && (c = c.toString()); + const d = "undefined" === typeof window, e = this; + this.worker = b.call(this); } X("add"); X("append"); @@ -1512,20 +1509,20 @@ X("search"); X("update"); X("remove"); function X(a) { - W.prototype[a] = W.prototype[a + "Async"] = function() { + W.prototype[a] = W.prototype[a + "Async"] = async function() { const b = this, c = [].slice.call(arguments); var d = c[c.length - 1]; let e; "function" === typeof d && (e = d, c.splice(c.length - 1, 1)); d = new Promise(function(f) { - b.N[++Oa] = f; + b.h[++Oa] = f; b.worker.postMessage({task:a, id:Oa, args:c}); }); return e ? (d.then(e), this) : d; }; } -async function Pa(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : new ((await import("worker_threads"))["Worker"])((1,eval)("import.meta.dirname") + "/node/node.mjs") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Na.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : "worker/worker.js", {type:"module"}); +function Pa(a, b, c) { + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Na.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : "worker/worker.js", {type:"module"}); } ;Y.prototype.add = function(a, b, c) { C(a) && (b = a, a = ca(b, this.key)); @@ -1547,7 +1544,7 @@ async function Pa(a, b, c) { } if (this.tag) { for (d = 0; d < this.F.length; d++) { - var f = this.F[d], g = this.O[d]; + var f = this.F[d], g = this.N[d]; e = this.tag.get(g); let h = z(); if ("function" === typeof f) { @@ -1599,7 +1596,7 @@ async function Pa(a, b, c) { if (!m) { continue; } - l = [l.V]; + l = [l.U]; } else if (B(l) || l.constructor === String) { h[l] = b[l]; continue; @@ -1884,7 +1881,7 @@ function Ta(a) { return new Y(a); } const b = a.document || a.doc || a; - var c, d; + let c, d; this.G = []; this.field = []; this.K = []; @@ -1896,36 +1893,13 @@ function Ta(a) { this.cache = (c = a.cache || null) && new H(c); a.cache = !1; this.worker = a.worker; - c = new Map(); - d = b.index || b.field || b; - B(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e]; - B(f) || (g = f, f = f.field); - g = C(g) ? Object.assign({}, a, g) : a; - if (this.worker) { - const h = new W(g); - c.set(f, h); - h.worker || (this.worker = !1); - } - this.worker || c.set(f, new O(g, this.reg)); - g.custom ? this.G[e] = g.custom : (this.G[e] = Va(f, this.K), g.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = g.filter)); - this.field[e] = f; - } - if (this.C) { - d = b.store; - B(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.V = g) : (this.C[e] = Va(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); - } - } - this.index = c; + this.index = Wa.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { this.tag = new Map(); this.F = []; - this.O = []; + this.N = []; for (let e = 0, f, g; e < c.length; e++) { f = c[e]; g = f.field || f; @@ -1933,19 +1907,32 @@ function Ta(a) { throw Error("The tag field from the document descriptor is undefined."); } f.custom ? this.F[e] = f.custom : (this.F[e] = Va(g, this.K), f.filter && ("string" === typeof this.F[e] && (this.F[e] = new String(this.F[e])), this.F[e].I = f.filter)); - this.O[e] = g; + this.N[e] = g; this.tag.set(g, new Map()); } } } - a.db && this.mount(a.db); + if (this.worker) { + a = []; + for (const e of this.index.values()) { + e.worker.then && a.push(e.worker); + } + if (a.length) { + const e = this; + return Promise.all(a).then(function() { + return e; + }); + } + } else { + a.db && this.mount(a.db); + } } u = Y.prototype; u.mount = function(a) { let b = this.field; if (this.tag) { - for (let e = 0, f; e < this.O.length; e++) { - f = this.O[e]; + for (let e = 0, f; e < this.N.length; e++) { + f = this.N[e]; var c = void 0; this.index.set(f, c = new O({}, this.reg)); b === this.field && (b = b.slice(0)); @@ -1982,6 +1969,31 @@ u.destroy = function() { } return Promise.all(a); }; +function Wa(a, b) { + const c = new Map(); + let d = b.index || b.field || b; + B(d) && (d = [d]); + for (let e = 0, f, g; e < d.length; e++) { + f = d[e]; + B(f) || (g = f, f = f.field); + g = C(g) ? Object.assign({}, a, g) : a; + if (this.worker) { + const h = new W(g); + h.worker ? c.set(f, h) : this.worker = !1; + } + this.worker || c.set(f, new O(g, this.reg)); + g.custom ? this.G[e] = g.custom : (this.G[e] = Va(f, this.K), g.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = g.filter)); + this.field[e] = f; + } + if (this.C) { + a = b.store; + B(a) && (a = [a]); + for (let e = 0, f, g; e < a.length; e++) { + f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Va(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); + } + } + return c; +} function Va(a, b) { const c = a.split(":"); let d = 0; @@ -2106,10 +2118,10 @@ u.import = function(a, b) { } }; Ba(Y.prototype); -const Wa = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Xa = ["map", "ctx", "tag", "reg", "cfg"]; -function Ya(a, b = {}) { +const Xa = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ya = ["map", "ctx", "tag", "reg", "cfg"]; +function Za(a, b = {}) { if (!this) { - return new Ya(a, b); + return new Za(a, b); } "object" === typeof a && (b = a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2119,7 +2131,7 @@ function Ya(a, b = {}) { this.db = null; this.h = {}; } -u = Ya.prototype; +u = Za.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2131,10 +2143,10 @@ u.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const d = Wa.open(a.id + (a.field ? ":" + a.field : ""), 1); + const d = Xa.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { const e = a.db = this.result; - Xa.forEach(f => { + Ya.forEach(f => { e.objectStoreNames.contains(f) || e.createObjectStore(f); }); }; @@ -2160,16 +2172,17 @@ u.close = function() { this.db = null; }; u.destroy = function() { - return Wa.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Xa.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); }; u.clear = function() { - const a = this.db.transaction(Xa, "readwrite"); - for (let b = 0; b < Xa.length; b++) { - a.objectStore(Xa[b]).clear(); + const a = this.db.transaction(Ya, "readwrite"); + for (let b = 0; b < Ya.length; b++) { + a.objectStore(Ya[b]).clear(); } return Z(a); }; u.get = function(a, b, c = 0, d = 0, e = !0, f = !1) { + console.log("!!!!!!!!!!!"); a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); const g = this; return Z(a).then(function(h) { @@ -2269,7 +2282,7 @@ u.commit = async function(a, b, c) { b = !0; break; } else { - d[e] = f.W; + d[e] = f.V; } } b || (c || (d = d.concat(ba(a.reg))), d.length && await this.remove(d)); @@ -2349,7 +2362,7 @@ u.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function Za(a, b, c) { +function $a(a, b, c) { const d = a.value; let e, f, g = 0; for (let h = 0, k; h < d.length; h++) { @@ -2378,17 +2391,17 @@ u.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && Za(c, a); + c && $a(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && Za(c, a); + c && $a(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && Za(c, a, !0); + c && $a(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2408,9 +2421,9 @@ function Z(a) { a = null; }); } -;const $a = {Index:O, Charset:va, Encoder:G, Document:Y, Worker:W, Resolver:S, IndexedDB:Ya, Language:{}}, ab = self; -let bb; -(bb = ab.define) && bb.amd ? bb([], function() { - return $a; -}) : "object" === typeof ab.exports ? ab.exports = $a : ab.FlexSearch = $a; +;const ab = {Index:O, Charset:va, Encoder:G, Document:Y, Worker:W, Resolver:S, IndexedDB:Za, Language:{}}, bb = self; +let db; +(db = bb.define) && db.amd ? db([], function() { + return ab; +}) : "object" === typeof bb.exports ? bb.exports = ab : bb.FlexSearch = ab; }(this)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index b518beb..31d5ac5 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -15,21 +15,21 @@ function B(a){return"string"===typeof a}function C(a){return"object"===typeof a} ["\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 fa=/[^\p{L}\p{N}]+/u,ha=/(\d{3})/g,ia=/(\D)(\d{3})/g,ja=/(\d{3})(\D)/g,ka="".normalize&&/[\u0300-\u036f]/g;function F(a){if(!this)return new F(...arguments);for(let b=0;bthis.stemmer.get(l)),k=1);this.matcher&& -1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.T&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.T&&(this.H.clear(),this.h=this.h/1.1|0));return c};function la(a){a.L=null;a.H.clear();a.J.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function G(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}G.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; +let c=[],d=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.stemmer.get(l)),k=1);this.matcher&& +1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function la(a){a.L=null;a.H.clear();a.J.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function G(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}G.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; G.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};G.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};G.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:function(a){return a.toLowerCase()},dedupe:!1};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([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),qa=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];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:{normalize:!1,dedupe:!1},LatinDefault:na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:oa,replacer:qa,matcher:pa},LatinExtra:{normalize:!0,dedupe:!0,mapper:oa,replacer:qa.concat([/(?!^)[aeoy]/g,""]),matcher:pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} function J(a){if(!this)return new J(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gf;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,r,g,f):P(q,d,r,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.U&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} function P(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Da(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Da(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1c||d)g=g.slice(d,c+d)}return g} function Ja(a,b){const c=z(),d=[];for(let e=0,f;e=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c: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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.U&&Ca(this));this.cache&&this.cache.remove(a);return this}; -function La(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Ca(this));this.cache&&this.cache.remove(a);return this}; +function La(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; function Ma(a){let b=0;if(a.constructor===Array)for(let c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=Ta.call(this,a));return a}} -function Ta(a){const b=Array(a.length);for(let c=0,d;c{f=k}));e||(e=0);d||(d=0);if(d{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -u.close=function(){this.db.close();this.db=null};u.destroy=function(){return Wa.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(Xa,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let q=d;q{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +u.close=function(){this.db.close();this.db=null};u.destroy=function(){return Xa.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(Ya,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let q=d;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})}; -u.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let e=0,f;em&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const $a={Index:O,Charset:va,Encoder:F,Document:Y,Worker:W,Resolver:S,IndexedDB:Ya,Language:{}},ab=self;let bb;(bb=ab.define)&&bb.amd?bb([],function(){return $a}):"object"===typeof ab.exports?ab.exports=$a:ab.FlexSearch=$a;}(this)); +function $a(a,b,c){const d=a.value;let e,f,g=0;for(let h=0,k;hm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const ab={Index:O,Charset:va,Encoder:F,Document:Y,Worker:W,Resolver:S,IndexedDB:Za,Language:{}},bb=self;let db;(db=bb.define)&&db.amd?db([],function(){return ab}):"object"===typeof bb.exports?bb.exports=ab:bb.FlexSearch=ab;}(this)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index e99d03b..233136b 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -137,12 +137,12 @@ G.prototype.assign = function(a) { this.minlength = y(a.minlength, 1, this.minlength); this.maxlength = y(a.maxlength, 0, this.maxlength); if (this.cache = c = y(a.cache, !0, this.cache)) { - this.L = null, this.T = "number" === typeof c ? c : 2e5, this.H = new Map(), this.J = new Map(), this.A = this.h = 128; + this.L = null, this.S = "number" === typeof c ? c : 2e5, this.H = new Map(), this.J = new Map(), this.A = this.h = 128; } this.B = ""; - this.P = null; + this.O = null; this.M = ""; - this.R = null; + this.P = null; if (this.matcher) { for (const d of this.matcher.keys()) { this.B += (this.B ? "|" : "") + d; @@ -196,8 +196,8 @@ G.prototype.encode = function(a) { } } let k; - this.stemmer && 2 < g.length && (this.R || (this.R = new RegExp("(?!^)(" + this.M + ")$")), g = g.replace(this.R, l => this.stemmer.get(l)), k = 1); - this.matcher && 1 < g.length && (this.P || (this.P = new RegExp("(" + this.B + ")", "g")), g = g.replace(this.P, l => this.matcher.get(l)), k = 1); + this.stemmer && 2 < g.length && (this.P || (this.P = new RegExp("(?!^)(" + this.M + ")$")), g = g.replace(this.P, l => this.stemmer.get(l)), k = 1); + this.matcher && 1 < g.length && (this.O || (this.O = new RegExp("(" + this.B + ")", "g")), g = g.replace(this.O, l => this.matcher.get(l)), k = 1); g && k && (g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); if (g && (this.mapper || this.dedupe && 1 < g.length)) { e = ""; @@ -211,11 +211,11 @@ G.prototype.encode = function(a) { g = g.replace(this.replacer[e], this.replacer[e + 1]); } } - this.cache && h.length <= this.A && (this.J.set(h, g), this.J.size > this.T && (this.J.clear(), this.A = this.A / 1.1 | 0)); + this.cache && h.length <= this.A && (this.J.set(h, g), this.J.size > this.S && (this.J.clear(), this.A = this.A / 1.1 | 0)); g && c.push(g); } this.finalize && (c = this.finalize(c) || c); - this.cache && a.length <= this.h && (this.H.set(a, c), this.H.size > this.T && (this.H.clear(), this.h = this.h / 1.1 | 0)); + this.cache && a.length <= this.h && (this.H.set(a, c), this.H.size > this.S && (this.H.clear(), this.h = this.h / 1.1 | 0)); return c; }; function la(a) { @@ -541,7 +541,7 @@ O.prototype.add = function(a, b, c, d) { } default: if (Q(this, m, p, f, a, c), n && 1 < d && r < d - 1) { - for (e = z(), g = this.S, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) { + for (e = z(), g = this.R, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) { if ((p = b[this.rtl ? d - 1 - r - k : r + k]) && !e[p]) { e[p] = 1; const t = this.score ? this.score(b, f, r, p, k) : P(g + (d / 2 > g ? 0 : 1), d, r, h - 1, k - 1), x = this.bidirectional && p > f; @@ -557,7 +557,7 @@ O.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.U && Ca(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && Ca(this)); return this; }; function Q(a, b, c, d, e, f, g) { @@ -1131,7 +1131,7 @@ O.prototype.search = function(a, b, c) { return async function() { for (let t, x; q < e; q++) { x = a[q]; - r ? (t = await V(p, x, r), t = Ka(t, d, f, p.S, b, g, 2 === e), f && !1 === t && d.length || (r = x)) : (t = await V(p, x), t = Ka(t, d, f, p.resolution, b, g, 1 === e)); + r ? (t = await V(p, x, r, 0, 0, !1, !1), t = Ka(t, d, f, p.R), f && !1 === t && d.length || (r = x)) : (t = await V(p, x, "", 0, 0, !1, !1), t = Ka(t, d, f, p.resolution)); if (t) { return t; } @@ -1155,7 +1155,7 @@ O.prototype.search = function(a, b, c) { } for (let p, t; q < e; q++) { t = a[q]; - r ? (p = V(this, t, r), p = Ka(p, d, f, this.S, b, g, 2 === e), f && !1 === p && d.length || (r = t)) : (p = V(this, t), p = Ka(p, d, f, this.resolution, b, g, 1 === e)); + r ? (p = V(this, t, r, 0, 0, !1, !1), p = Ka(p, d, f, this.R), f && !1 === p && d.length || (r = t)) : (p = V(this, t, "", 0, 0, !1, !1), p = Ka(p, d, f, this.resolution)); if (p) { return p; } @@ -1183,26 +1183,19 @@ function U(a, b, c, d, e, f, g) { return e ? h : h && h.length ? e ? R(h, c, d) : new S(h) : e ? [] : new S([]); }) : a && a.length ? e ? R(a, c, d) : new S(a) : e ? [] : new S([]); } -function Ka(a, b, c, d, e, f, g) { - let h = []; +function Ka(a, b, c, d) { + let e = []; if (a) { d = Math.min(a.length, d); - for (let k = 0, l = 0, m; k < d; k++) { - if (m = a[k]) { - if (f && m && g && (m.length <= f ? (f -= m.length, m = null) : (m = m.slice(f), f = 0)), m && (h[k] = m, g && (l += m.length, l >= e))) { - break; - } - } + for (let f = 0, g; f < d; f++) { + (g = a[f]) && g && (e[f] = g); } - if (h.length) { - if (g) { - return R(h, e, 0); - } - b.push(h); + if (e.length) { + b.push(e); return; } } - return !c && h; + return !c && e; } function V(a, b, c, d, e, f, g, h) { let k; @@ -1232,7 +1225,7 @@ function V(a, b, c, d, e, f, g, h) { } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.U && Ca(this)); + this.db && (this.commit_task.push({del:a}), this.T && Ca(this)); this.cache && this.cache.remove(a); return this; }; @@ -1268,7 +1261,7 @@ function La(a, b) { a = {}; } c = a.context || {}; - const d = a.encode || a.encoder || na; + const d = B(a.encoder) ? va[a.encoder] : a.encode || a.encoder || na; this.encoder = d.encode ? d : "object" === typeof d ? new G(d) : {encode:d}; let e; this.resolution = a.resolution || 9; @@ -1281,14 +1274,14 @@ function La(a, b) { this.map = e ? new L(e) : new Map(); this.ctx = e ? new L(e) : new Map(); this.reg = b || (this.fastupdate ? e ? new L(e) : new Map() : e ? new M(e) : new Set()); - this.S = c.resolution || 1; + this.R = c.resolution || 1; this.rtl = d.rtl || a.rtl || !1; this.cache = (e = a.cache || null) && new H(e); this.resolve = !1 !== a.resolve; if (e = a.db) { - this.db = e.mount(this); + this.db = this.mount(e); } - this.U = !1 !== a.commit; + this.T = !1 !== a.commit; this.commit_task = []; this.commit_timer = null; } @@ -1475,35 +1468,39 @@ async function Na(a) { } } ;let Oa = 0; -function W(a) { +function W(a = {}) { + function b(f) { + function g(h) { + h = h.data || h; + const k = h.id, l = k && e.h[k]; + l && (l(h.msg), delete e.h[k]); + } + this.worker = f || Pa(c, d, a.worker); + if (this.worker.then) { + return this.worker.then(b); + } + this.h = z(); + if (this.worker) { + d ? this.worker.on("message", g) : this.worker.onmessage = g; + if (a.config) { + return new Promise(function(h) { + e.h[++Oa] = function() { + h(e); + }; + e.worker.postMessage({id:Oa, task:"init", factory:c, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:c, options:a}); + return this.worker; + } + } if (!this) { return new W(a); } - a || (a = {}); - let b = "undefined" !== typeof self && (self || window)._factory; - b && (b = b.toString()); - const c = "undefined" === typeof window, d = this; - (async function() { - function e(f) { - f = f.data || f; - const g = f.id, h = g && d.N[g]; - h && (h(f.msg), delete d.N[g]); - } - this.worker = await Pa(b, c, a.worker); - this.N = z(); - if (this.worker) { - c ? this.worker.on("message", e) : this.worker.onmessage = e; - if (a.config) { - return delete a.db, new Promise(function(f) { - d.N[++Oa] = function() { - f(d); - }; - d.worker.postMessage({id:Oa, task:"init", factory:b, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:b, options:a}); - } - }).call(this); + let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + c && (c = c.toString()); + const d = "undefined" === typeof window, e = this; + this.worker = b.call(this); } X("add"); X("append"); @@ -1511,20 +1508,20 @@ X("search"); X("update"); X("remove"); function X(a) { - W.prototype[a] = W.prototype[a + "Async"] = function() { + W.prototype[a] = W.prototype[a + "Async"] = async function() { const b = this, c = [].slice.call(arguments); var d = c[c.length - 1]; let e; "function" === typeof d && (e = d, c.splice(c.length - 1, 1)); d = new Promise(function(f) { - b.N[++Oa] = f; + b.h[++Oa] = f; b.worker.postMessage({task:a, id:Oa, args:c}); }); return e ? (d.then(e), this) : d; }; } -async function Pa(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/node/node.mjs") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Na.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : "worker/worker.js", {type:"module"}); +function Pa(a, b, c) { + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]($1 + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Na.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : "worker/worker.js", {type:"module"}); } ;Y.prototype.add = function(a, b, c) { C(a) && (b = a, a = ca(b, this.key)); @@ -1546,7 +1543,7 @@ async function Pa(a, b, c) { } if (this.tag) { for (d = 0; d < this.F.length; d++) { - var f = this.F[d], g = this.O[d]; + var f = this.F[d], g = this.N[d]; e = this.tag.get(g); let h = z(); if ("function" === typeof f) { @@ -1598,7 +1595,7 @@ async function Pa(a, b, c) { if (!m) { continue; } - l = [l.V]; + l = [l.U]; } else if (B(l) || l.constructor === String) { h[l] = b[l]; continue; @@ -1883,7 +1880,7 @@ function Ta(a) { return new Y(a); } const b = a.document || a.doc || a; - var c, d; + let c, d; this.G = []; this.field = []; this.K = []; @@ -1895,36 +1892,13 @@ function Ta(a) { this.cache = (c = a.cache || null) && new H(c); a.cache = !1; this.worker = a.worker; - c = new Map(); - d = b.index || b.field || b; - B(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e]; - B(f) || (g = f, f = f.field); - g = C(g) ? Object.assign({}, a, g) : a; - if (this.worker) { - const h = new W(g); - c.set(f, h); - h.worker || (this.worker = !1); - } - this.worker || c.set(f, new O(g, this.reg)); - g.custom ? this.G[e] = g.custom : (this.G[e] = Va(f, this.K), g.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = g.filter)); - this.field[e] = f; - } - if (this.C) { - d = b.store; - B(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.V = g) : (this.C[e] = Va(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); - } - } - this.index = c; + this.index = Wa.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { this.tag = new Map(); this.F = []; - this.O = []; + this.N = []; for (let e = 0, f, g; e < c.length; e++) { f = c[e]; g = f.field || f; @@ -1932,19 +1906,32 @@ function Ta(a) { throw Error("The tag field from the document descriptor is undefined."); } f.custom ? this.F[e] = f.custom : (this.F[e] = Va(g, this.K), f.filter && ("string" === typeof this.F[e] && (this.F[e] = new String(this.F[e])), this.F[e].I = f.filter)); - this.O[e] = g; + this.N[e] = g; this.tag.set(g, new Map()); } } } - a.db && this.mount(a.db); + if (this.worker) { + a = []; + for (const e of this.index.values()) { + e.worker.then && a.push(e.worker); + } + if (a.length) { + const e = this; + return Promise.all(a).then(function() { + return e; + }); + } + } else { + a.db && this.mount(a.db); + } } u = Y.prototype; u.mount = function(a) { let b = this.field; if (this.tag) { - for (let e = 0, f; e < this.O.length; e++) { - f = this.O[e]; + for (let e = 0, f; e < this.N.length; e++) { + f = this.N[e]; var c = void 0; this.index.set(f, c = new O({}, this.reg)); b === this.field && (b = b.slice(0)); @@ -1981,6 +1968,31 @@ u.destroy = function() { } return Promise.all(a); }; +function Wa(a, b) { + const c = new Map(); + let d = b.index || b.field || b; + B(d) && (d = [d]); + for (let e = 0, f, g; e < d.length; e++) { + f = d[e]; + B(f) || (g = f, f = f.field); + g = C(g) ? Object.assign({}, a, g) : a; + if (this.worker) { + const h = new W(g); + h.worker ? c.set(f, h) : this.worker = !1; + } + this.worker || c.set(f, new O(g, this.reg)); + g.custom ? this.G[e] = g.custom : (this.G[e] = Va(f, this.K), g.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = g.filter)); + this.field[e] = f; + } + if (this.C) { + a = b.store; + B(a) && (a = [a]); + for (let e = 0, f, g; e < a.length; e++) { + f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Va(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); + } + } + return c; +} function Va(a, b) { const c = a.split(":"); let d = 0; @@ -2105,10 +2117,10 @@ u.import = function(a, b) { } }; Ba(Y.prototype); -const Wa = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Xa = ["map", "ctx", "tag", "reg", "cfg"]; -function Ya(a, b = {}) { +const Xa = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ya = ["map", "ctx", "tag", "reg", "cfg"]; +function Za(a, b = {}) { if (!this) { - return new Ya(a, b); + return new Za(a, b); } "object" === typeof a && (b = a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2118,7 +2130,7 @@ function Ya(a, b = {}) { this.db = null; this.h = {}; } -u = Ya.prototype; +u = Za.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2130,10 +2142,10 @@ u.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const d = Wa.open(a.id + (a.field ? ":" + a.field : ""), 1); + const d = Xa.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { const e = a.db = this.result; - Xa.forEach(f => { + Ya.forEach(f => { e.objectStoreNames.contains(f) || e.createObjectStore(f); }); }; @@ -2159,16 +2171,17 @@ u.close = function() { this.db = null; }; u.destroy = function() { - return Wa.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Xa.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); }; u.clear = function() { - const a = this.db.transaction(Xa, "readwrite"); - for (let b = 0; b < Xa.length; b++) { - a.objectStore(Xa[b]).clear(); + const a = this.db.transaction(Ya, "readwrite"); + for (let b = 0; b < Ya.length; b++) { + a.objectStore(Ya[b]).clear(); } return Z(a); }; u.get = function(a, b, c = 0, d = 0, e = !0, f = !1) { + console.log("!!!!!!!!!!!"); a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); const g = this; return Z(a).then(function(h) { @@ -2268,7 +2281,7 @@ u.commit = async function(a, b, c) { b = !0; break; } else { - d[e] = f.W; + d[e] = f.V; } } b || (c || (d = d.concat(ba(a.reg))), d.length && await this.remove(d)); @@ -2348,7 +2361,7 @@ u.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function Za(a, b, c) { +function ab(a, b, c) { const d = a.value; let e, f, g = 0; for (let h = 0, k; h < d.length; h++) { @@ -2377,17 +2390,17 @@ u.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && Za(c, a); + c && ab(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && Za(c, a); + c && ab(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && Za(c, a, !0); + c && ab(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2407,6 +2420,6 @@ function Z(a) { a = null; }); } -;export default {Index:O, Charset:va, Encoder:G, Document:Y, Worker:W, Resolver:S, IndexedDB:Ya, Language:{}}; +;export default {Index:O, Charset:va, Encoder:G, Document:Y, Worker:W, Resolver:S, IndexedDB:Za, Language:{}}; -export const Index=O;export const Charset=va;export const Encoder=G;export const Document=Y;export const Worker=W;export const Resolver=S;export const IndexedDB=Ya;export const Language={}; \ No newline at end of file +export const Index=O;export const Charset=va;export const Encoder=G;export const Document=Y;export const Worker=W;export const Resolver=S;export const IndexedDB=Za;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 94e3931..d12bc2a 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -15,21 +15,21 @@ function B(a){return"string"===typeof a}function C(a){return"object"===typeof a} ["\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 fa=/[^\p{L}\p{N}]+/u,ha=/(\d{3})/g,ia=/(\D)(\d{3})/g,ja=/(\d{3})(\D)/g,ka="".normalize&&/[\u0300-\u036f]/g;function F(a){if(!this)return new F(...arguments);for(let b=0;bthis.stemmer.get(l)),k=1);this.matcher&& -1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.T&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.T&&(this.H.clear(),this.h=this.h/1.1|0));return c};function la(a){a.L=null;a.H.clear();a.J.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function G(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}G.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; +let c=[],d=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;fthis.stemmer.get(l)),k=1);this.matcher&& +1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function la(a){a.L=null;a.H.clear();a.J.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function G(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}G.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; G.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};G.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};G.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:function(a){return a.toLowerCase()},dedupe:!1};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([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),qa=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];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:{normalize:!1,dedupe:!1},LatinDefault:na,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:oa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:oa,replacer:qa,matcher:pa},LatinExtra:{normalize:!0,dedupe:!0,mapper:oa,replacer:qa.concat([/(?!^)[aeoy]/g,""]),matcher:pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} function J(a){if(!this)return new J(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gf;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,r,g,f):P(q,d,r,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.U&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} function P(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Da(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Da(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1c||d)g=g.slice(d,c+d)}return g} function Ja(a,b){const c=z(),d=[];for(let e=0,f;e=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c: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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.U&&Ca(this));this.cache&&this.cache.remove(a);return this}; -function La(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Ca(this));this.cache&&this.cache.remove(a);return this}; +function La(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; function Ma(a){let b=0;if(a.constructor===Array)for(let c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=Ta.call(this,a));return a}} -function Ta(a){const b=Array(a.length);for(let c=0,d;c{f=k}));e||(e=0);d||(d=0);if(d{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -u.close=function(){this.db.close();this.db=null};u.destroy=function(){return Wa.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(Xa,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let q=d;q{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +u.close=function(){this.db.close();this.db=null};u.destroy=function(){return Xa.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(Ya,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let q=d;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})}; -u.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let e=0,f;em&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:O,Charset:va,Encoder:F,Document:Y,Worker:W,Resolver:S,IndexedDB:Ya,Language:{}}; -export const Index=O;export const Charset=va;export const Encoder=F;export const Document=Y;export const Worker=W;export const Resolver=S;export const IndexedDB=Ya;export const Language={}; \ No newline at end of file +function ab(a,b,c){const d=a.value;let e,f,g=0;for(let h=0,k;hm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:O,Charset:va,Encoder:F,Document:Y,Worker:W,Resolver:S,IndexedDB:Za,Language:{}}; +export const Index=O;export const Charset=va;export const Encoder=F;export const Document=Y;export const Worker=W;export const Resolver=S;export const IndexedDB=Za;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 77e03a0..b698147 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -363,7 +363,7 @@ function P(a, c, b, e, d, f, g) { function O(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;function Q(a, c, b) { +;function ua(a, c, b) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } @@ -393,7 +393,7 @@ function O(a, c, b, e, d) { } return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; } -;function ua(a, c) { +;function va(a, c) { const b = y(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -420,11 +420,11 @@ function O(a, c, b, e, d) { b = a.length; c || (c = 100); if (1 === b) { - return R.call(this, a[0], "", c, d); + return Q.call(this, a[0], "", c, d); } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return R.call(this, a[0], a[1], c, d); + return Q.call(this, a[0], a[1], c, d); } var h = 0, k = 0; if (1 < b) { @@ -432,7 +432,7 @@ function O(a, c, b, e, d) { const q = []; for (let t = 0, p; t < b; t++) { if ((p = a[t]) && !l[p]) { - if (g || S(this, p)) { + if (g || R(this, p)) { q.push(p), l[p] = 1; } else { return e; @@ -450,10 +450,10 @@ function O(a, c, b, e, d) { } l = 0; if (1 === b) { - return R.call(this, a[0], "", c, d); + return Q.call(this, a[0], "", c, d); } if (2 === b && f && !g) { - return R.call(this, a[0], a[1], c, d); + return Q.call(this, a[0], a[1], c, d); } if (1 < b) { if (f) { @@ -465,7 +465,7 @@ function O(a, c, b, e, d) { } for (let q, t; l < b; l++) { t = a[l]; - m ? (q = S(this, t, m), q = va(q, e, g, this.P, c, d, 2 === b), g && !1 === q && e.length || (m = t)) : (q = S(this, t), q = va(q, e, g, this.resolution, c, d, 1 === b)); + m ? (q = R(this, t, m), q = wa(q, e, g, this.P), g && !1 === q && e.length || (m = t)) : (q = R(this, t, ""), q = wa(q, e, g, this.resolution)); if (q) { return q; } @@ -480,7 +480,7 @@ function O(a, c, b, e, d) { return e; } if (1 === f) { - return Q(e[0], c, d); + return ua(e[0], c, d); } } } @@ -539,31 +539,24 @@ function O(a, c, b, e, d) { } return e; }; -function R(a, c, b, e) { - return (a = S(this, a, c)) && a.length ? Q(a, b, e) : []; +function Q(a, c, b, e) { + return (a = R(this, a, c)) && a.length ? ua(a, b, e) : []; } -function va(a, c, b, e, d, f, g) { - let h = []; +function wa(a, c, b, e) { + let d = []; if (a) { e = Math.min(a.length, e); - for (let k = 0, l = 0, m; k < e; k++) { - if (m = a[k]) { - if (f && m && g && (m.length <= f ? (f -= m.length, m = null) : (m = m.slice(f), f = 0)), m && (h[k] = m, g && (l += m.length, l >= d))) { - break; - } - } + for (let f = 0, g; f < e; f++) { + (g = a[f]) && g && (d[f] = g); } - if (h.length) { - if (g) { - return Q(h, d, 0); - } - c.push(h); + if (d.length) { + c.push(d); return; } } - return !b && h; + return !b && d; } -function S(a, c, b) { +function R(a, c, b) { let e; b && (e = a.bidirectional && c > b); a = b ? (a = a.ctx.get(e ? c : b)) && a.get(e ? b : c) : a.map.get(c); @@ -584,14 +577,14 @@ function S(a, c, b) { } } } else { - T(this.map, a), this.depth && T(this.ctx, a); + S(this.map, a), this.depth && S(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function T(a, c) { +function S(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -606,7 +599,7 @@ function T(a, c) { } } else { for (let e of a) { - const d = e[0], f = T(e[1], c); + const d = e[0], f = S(e[1], c); f ? b += f : a.delete(d); } } @@ -623,7 +616,7 @@ function T(a, c) { a = {}; } b = a.context || {}; - const e = a.encode || a.encoder || ja; + const e = z(a.encoder) ? qa[a.encoder] : a.encode || a.encoder || ja; this.encoder = e.encode ? e : "object" === typeof e ? new J(e) : {encode:e}; let d; this.resolution = a.resolution || 9; @@ -658,7 +651,7 @@ u.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 U(a) { +function T(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -666,7 +659,7 @@ function U(a) { } } else { for (const b of a) { - const e = b[0], d = U(b[1]); + const e = b[0], d = T(b[1]); d ? c += d : a.delete(e); } } @@ -676,8 +669,8 @@ u.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - U(this.map); - this.depth && U(this.ctx); + T(this.map); + this.depth && T(this.ctx); return this; }; u.searchCache = ia; @@ -787,7 +780,7 @@ u.serialize = function(a = !0) { return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; ta(N.prototype); -V.prototype.add = function(a, c, b) { +U.prototype.add = function(a, c, b) { E(a) && (c = a, a = F(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { @@ -801,7 +794,7 @@ V.prototype.add = function(a, c, b) { d && e.add(a, d, !1, !0); } else { if (d = k.G, !d || d(c)) { - k.constructor === String ? k = ["" + k] : z(k) && (k = [k]), W(c, k, this.I, 0, e, a, k[0], b); + k.constructor === String ? k = ["" + k] : z(k) && (k = [k]), V(c, k, this.I, 0, e, a, k[0], b); } } } @@ -852,7 +845,7 @@ V.prototype.add = function(a, c, b) { h[l] = c[l]; continue; } - X(c, h, l, 0, l[0], m); + W(c, h, l, 0, l[0], m); } } this.store.set(a, h || c); @@ -860,21 +853,21 @@ V.prototype.add = function(a, c, b) { } return this; }; -function X(a, c, b, e, d, f) { +function W(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++) { - X(a, c, b, e, d); + W(a, c, b, e, d); } } else { - c = c[d] || (c[d] = y()), d = b[++e], X(a, c, b, e, d); + c = c[d] || (c[d] = y()), d = b[++e], W(a, c, b, e, d); } } } -function W(a, c, b, e, d, f, g, h) { +function V(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -890,15 +883,15 @@ function W(a, c, b, e, d, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - W(a, c, b, e, d, f, g, h); + V(a, c, b, e, d, f, g, h); } } else { - g = c[++e], W(a, c, b, e, d, f, g, h); + g = c[++e], V(a, c, b, e, d, f, g, h); } } } } -;V.prototype.search = function(a, c, b, e) { +;U.prototype.search = function(a, c, b, e) { b || (!c && E(a) ? (b = a, a = "") : E(c) && (b = c, c = 0)); let d = []; var f = []; @@ -954,7 +947,7 @@ function W(a, c, b, e, d, f, g, h) { e = []; if (n.length) { for (f = 0; f < n.length; f += 2) { - t = wa.call(this, n[f], n[f + 1], c, p, g), d.push({field:n[f], tag:n[f + 1], result:t}); + t = xa.call(this, n[f], n[f + 1], c, p, g), d.push({field:n[f], tag:n[f + 1], result:t}); } } return e.length ? Promise.all(e).then(function(v) { @@ -1004,7 +997,7 @@ function W(a, c, b, e, d, f, g, h) { } } if (w) { - r = ua(r, n); + r = va(r, n); D = r.length; if (!D && !k) { return d; @@ -1033,15 +1026,15 @@ function W(a, c, b, e, d, f, g, h) { p = []; for (let v = 0, r; v < f.length; v++) { r = d[v]; - g && r.length && !r[0].doc && r.length && (r = xa.call(this, r)); + g && r.length && !r[0].doc && r.length && (r = ya.call(this, r)); if (t) { return r; } d[v] = {field:f[v], result:r}; } - return h ? ya(d, c) : d; + return h ? za(d, c) : d; }; -function ya(a, c) { +function za(a, c) { const b = [], e = y(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1060,7 +1053,7 @@ function ya(a, c) { } return b; } -function wa(a, c, b, e, d) { +function xa(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1069,27 +1062,27 @@ function wa(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = xa.call(this, f)); + d && (f = ya.call(this, f)); return f; } } -function xa(a) { +function ya(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) { +;function U(a) { if (!this) { - return new V(a); + return new U(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; this.I = []; - this.key = (b = c.key || c.id) && Y(b, this.I) || "id"; + this.key = (b = c.key || c.id) && X(b, this.I) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && !0 !== b && []; this.store = b && new Map(); @@ -1099,13 +1092,13 @@ function xa(a) { let e = c.index || c.field || c; z(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], z(f) || (g = f, f = f.field), g = E(g) ? Object.assign({}, a, g) : a, b.set(f, new N(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Y(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].G = g.filter)), this.field[d] = f; + f = e[d], z(f) || (g = f, f = f.field), g = E(g) ? Object.assign({}, a, g) : a, b.set(f, new N(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = X(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].G = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; z(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Y(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = X(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); } } this.index = b; @@ -1121,14 +1114,14 @@ function xa(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Y(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].G = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = X(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].G = f.filter)); this.R[d] = g; this.tag.set(g, new Map()); } } } } -function Y(a, c) { +function X(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1137,7 +1130,7 @@ function Y(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -u = V.prototype; +u = U.prototype; u.append = function(a, c) { return this.add(a, c, !0); }; @@ -1250,10 +1243,10 @@ u.import = function(a, c) { } } }; -ta(V.prototype); -const za = {Index:N, Charset:qa, Encoder:J, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Z = self; +ta(U.prototype); +const Y = {Index:N, Charset:qa, Encoder:J, Document:U, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Z = self; let Ba; (Ba = Z.define) && Ba.amd ? Ba([], function() { - return za; -}) : "object" === typeof Z.exports ? Z.exports = za : Z.FlexSearch = za; + return Y; +}) : "object" === typeof Z.exports ? Z.exports = Y : Z.FlexSearch = Y; }(this)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 92d5f08..7867ad6 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -23,29 +23,29 @@ this.cache&&h.length<=this.D&&(this.H.set(h,g),this.H.size>this.O&&(this.H.clear J.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};J.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};J.prototype.clear=function(){this.cache.clear();this.h=""};const ja={normalize:function(a){return a.toLowerCase()},dedupe:!1};const K=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 ka=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),la=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const ma={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=/[\x00-\x7F]+/g;const oa=/[\x00-\x7F]+/g;const pa=/[\x00-\x7F]+/g;var qa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ja,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:K},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:K,replacer:la,matcher:ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:K,replacer:la.concat([/(?!^)[aeoy]/g,""]),matcher:ka},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=n.substring(f,h);var k=this.score?this.score(c,n,p,g,f):N(t,e,p,d,f);O(this,m,g,k,a,b)}break}case "reverse":if(1< d){for(h=d-1;0g?0:1),e,p,h-1,k-1),B=this.bidirectional&&n>f;O(this,l,B?f:n,w,a,b,B?n:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function O(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=y()),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 N(a,c,b,e,d){return b&&1c?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=f.length),e.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;e=[f]}c-=g;if(!c)break}return e.length?e=1c||d)b=b.slice(d,c+d)}e=b}return e};function R(a,c,b,e){return(a=S(this,a,c))&&a.length?Q(a,b,e):[]} -function va(a,c,b,e,d,f,g){let h=[];if(a){e=Math.min(a.length,e);for(let k=0,l=0,m;k=d)))break;if(h.length){if(g)return Q(h,d,0);c.push(h);return}}return!b&&h}function S(a,c,b){let e;b&&(e=a.bidirectional&&c>b);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};M.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 T(this.map,a),this.depth&&T(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function T(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; -function U(a){let c=0;if(a.constructor===Array)for(let b=0,e;bc?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=f.length),e.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;e=[f]}c-=g;if(!c)break}return e.length?e=1c||d)b=b.slice(d,c+d)}e=b}return e};function Q(a,c,b,e){return(a=R(this,a,c))&&a.length?ua(a,b,e):[]} +function wa(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let f=0,g;fb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};M.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 S(this.map,a),this.depth&&S(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function S(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; +function T(a){let c=0;if(a.constructor===Array)for(let b=0,e;b{f=l}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}ra(a,c||this,b,h,e,d,k,f);return g}; u.import=function(a,c){if(c)switch(z(c)&&(c=JSON.parse(c)),a){case "cfg":this.h=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}}; u.serialize=function(a=!0){if(!this.reg.size)return"";let c="",b="";for(var e of this.reg.keys())b||(b=typeof e),c+=(c?",":"")+("string"===b?'"'+e+'"':e);c="index.reg=new Set(["+c+"]);";e="";for(var d of this.map.entries()){var f=d[0],g=d[1],h="";for(let m=0,q;mb||e)a=a.slice(e,e+b);d&&(a=xa.call(this,a));return a}} -function xa(a){const c=Array(a.length);for(let b=0,e;bb||e)a=a.slice(e,e+b);d&&(a=ya.call(this,a));return a}} +function ya(a){const c=Array(a.length);for(let b=0,e;b{f=k}));d||(d=0);e||(e=0);if(e e; h--) { - g = n.substring(e, h); - var k = this.score ? this.score(c, n, p, g, e) : P(t, d, p, f, e); - Q(this, l, g, k, a, b); + g = m.substring(e, h); + var k = this.score ? this.score(c, m, p, g, e) : Q(t, d, p, f, e); + R(this, n, g, k, a, b); } } break; @@ -257,24 +257,24 @@ O.prototype.add = function(a, c, b, d) { case "reverse": if (1 < f) { for (h = f - 1; 0 < h; h--) { - g = n[h] + g, k = this.score ? this.score(c, n, p, g, h) : P(t, d, p, f, h), Q(this, l, g, k, a, b); + g = m[h] + g, k = this.score ? this.score(c, m, p, g, h) : Q(t, d, p, f, h), R(this, n, g, k, a, b); } g = ""; } case "forward": if (1 < f) { for (h = 0; h < f; h++) { - g += n[h], Q(this, l, g, e, a, b); + g += m[h], R(this, n, g, e, a, b); } break; } default: - if (Q(this, l, n, e, a, b), r && 1 < d && p < d - 1) { - for (f = y(), g = this.I, e = n, h = Math.min(r + 1, d - p), f[e] = 1, k = 1; k < h; k++) { - if ((n = c[this.rtl ? d - 1 - p - k : p + k]) && !f[n]) { - f[n] = 1; - const w = this.score ? this.score(c, e, p, n, k) : P(g + (d / 2 > g ? 0 : 1), d, p, h - 1, k - 1), B = this.bidirectional && n > e; - Q(this, m, B ? e : n, w, a, b, B ? n : e); + if (R(this, n, m, e, a, b), r && 1 < d && p < d - 1) { + for (f = y(), g = this.I, e = m, h = Math.min(r + 1, d - p), f[e] = 1, k = 1; k < h; k++) { + if ((m = c[this.rtl ? d - 1 - p - k : p + k]) && !f[m]) { + f[m] = 1; + const w = this.score ? this.score(c, e, p, m, k) : Q(g + (d / 2 > g ? 0 : 1), d, p, h - 1, k - 1), B = this.bidirectional && m > e; + R(this, l, B ? e : m, w, a, b, B ? m : e); } } } @@ -286,14 +286,14 @@ O.prototype.add = function(a, c, b, d) { } return this; }; -function Q(a, c, b, d, f, e, g) { +function R(a, c, b, d, f, e, g) { let h = g ? a.ctx : a.map, k; c[b] && g && (k = c[b])[g] || (g ? (c = k || (c[b] = y()), 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[d] || (h[d] = []), e && h.includes(f) || (h.push(f), a.fastupdate && ((c = a.reg.get(f)) ? c.push(h) : a.reg.set(f, [h])))); } -function P(a, c, b, d, f) { +function Q(a, c, b, d, f) { return b && 1 < a ? c + (d || 0) <= a ? b + (f || 0) : (a - 1) / (c + (d || 0)) * (b + (f || 0)) + 1 | 0 : 0; } -;function R(a, c, b) { +;function pa(a, c, b) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } @@ -336,7 +336,7 @@ function P(a, c, b, d, f) { } return d; } -;O.prototype.search = function(a, c, b) { +;P.prototype.search = function(a, c, b) { b || (!c && E(a) ? (b = a, a = "") : E(c) && (b = c, c = 0)); var d = [], f = 0; if (b) { @@ -358,18 +358,18 @@ function P(a, c, b, d, f) { } var h = 0, k = 0; if (1 < b) { - var m = y(); + var l = y(); const r = []; for (let t = 0, p; t < b; t++) { - if ((p = a[t]) && !m[p]) { + if ((p = a[t]) && !l[p]) { if (g || T(this, p)) { - r.push(p), m[p] = 1; + r.push(p), l[p] = 1; } else { return d; } - const n = p.length; - h = Math.max(h, n); - k = k ? Math.min(k, n) : n; + const m = p.length; + h = Math.max(h, m); + k = k ? Math.min(k, m) : m; } } a = r; @@ -378,7 +378,7 @@ function P(a, c, b, d, f) { if (!b) { return d; } - m = 0; + l = 0; if (1 === b) { return S.call(this, a[0], "", c, f); } @@ -387,44 +387,44 @@ function P(a, c, b, d, f) { } if (1 < b) { if (e) { - var l = a[0]; - m = 1; + var n = a[0]; + l = 1; } else { 9 < h && 3 < h / k && a.sort(aa); } } - for (let r, t; m < b; m++) { - t = a[m]; - l ? (r = T(this, t, l), r = ra(r, d, g, this.I, c, f, 2 === b), g && !1 === r && d.length || (l = t)) : (r = T(this, t), r = ra(r, d, g, this.resolution, c, f, 1 === b)); + for (let r, t; l < b; l++) { + t = a[l]; + n ? (r = T(this, t, n), r = ra(r, d, g, this.I), g && !1 === r && d.length || (n = t)) : (r = T(this, t, ""), r = ra(r, d, g, this.resolution)); if (r) { return r; } - if (g && m === b - 1) { + if (g && l === b - 1) { e = d.length; if (!e) { - if (l) { - l = ""; - m = -1; + if (n) { + n = ""; + l = -1; continue; } return d; } if (1 === e) { - return R(d[0], c, f); + return pa(d[0], c, f); } } } a: { a = d; d = this.resolution; - l = a.length; + n = a.length; b = []; e = y(); - for (let r = 0, t, p, n, w; r < d; r++) { - for (k = 0; k < l; k++) { - if (n = a[k], r < n.length && (t = n[r])) { - for (m = 0; m < t.length; m++) { - p = t[m], (h = e[p]) ? e[p]++ : (h = 0, e[p] = 1), w = b[h] || (b[h] = []), w.push(p); + for (let r = 0, t, p, m, w; r < d; r++) { + for (k = 0; k < n; k++) { + if (m = a[k], r < m.length && (t = m[r])) { + for (l = 0; l < t.length; l++) { + p = t[l], (h = e[p]) ? e[p]++ : (h = 0, e[p] = 1), w = b[h] || (b[h] = []), w.push(p); } } } @@ -437,8 +437,8 @@ function P(a, c, b, d, f) { d = y(); e = g.length; for (k = 0; k < e; k++) { - for (l = g[k], h = l.length, m = 0; m < h; m++) { - if (b = l[m], !d[b]) { + for (n = g[k], h = n.length, l = 0; l < h; l++) { + if (b = n[l], !d[b]) { if (d[b] = 1, f) { f--; } else { @@ -455,7 +455,7 @@ function P(a, c, b, d, f) { } b = c; } else { - if (a < l) { + if (a < n) { d = []; break a; } @@ -470,28 +470,21 @@ function P(a, c, b, d, f) { return d; }; function S(a, c, b, d) { - return (a = T(this, a, c)) && a.length ? R(a, b, d) : []; + return (a = T(this, a, c)) && a.length ? pa(a, b, d) : []; } -function ra(a, c, b, d, f, e, g) { - let h = []; +function ra(a, c, b, d) { + let f = []; if (a) { d = Math.min(a.length, d); - for (let k = 0, m = 0, l; k < d; k++) { - if (l = a[k]) { - if (e && l && g && (l.length <= e ? (e -= l.length, l = null) : (l = l.slice(e), e = 0)), l && (h[k] = l, g && (m += l.length, m >= f))) { - break; - } - } + for (let e = 0, g; e < d; e++) { + (g = a[e]) && g && (f[e] = g); } - if (h.length) { - if (g) { - return R(h, f, 0); - } - c.push(h); + if (f.length) { + c.push(f); return; } } - return !b && h; + return !b && f; } function T(a, c, b) { let d; @@ -499,7 +492,7 @@ function T(a, c, b) { a = b ? (a = a.ctx.get(d ? c : b)) && a.get(d ? b : c) : a.map.get(c); return a; } -;O.prototype.remove = function(a, c) { +;P.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -541,18 +534,18 @@ function U(a, c) { } return b; } -;function O(a, c) { +;function P(a, c) { if (!this) { - return new O(a); + return new P(a); } if (a) { var b = z(a) ? a : a.preset; - b && (oa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, oa[b], a)); + b && (na[b] || console.warn("Preset not found: " + b), a = Object.assign({}, na[b], a)); } else { a = {}; } b = a.context || {}; - const d = a.encode || a.encoder || K; + const d = z(a.encoder) ? la[a.encoder] : a.encode || a.encoder || K; this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; let f; this.resolution = a.resolution || 9; @@ -567,7 +560,7 @@ function U(a, c) { this.I = b.resolution || 1; this.rtl = d.rtl || a.rtl || !1; } -u = O.prototype; +u = P.prototype; u.clear = function() { this.map.clear(); this.ctx.clear(); @@ -608,8 +601,8 @@ u.cleanup = function() { }; u.export = function(a, c, b, d, f, e) { let g = !0; - "undefined" === typeof e && (g = new Promise(m => { - e = m; + "undefined" === typeof e && (g = new Promise(l => { + e = l; })); let h, k; switch(f || (f = 0)) { @@ -617,8 +610,8 @@ u.export = function(a, c, b, d, f, e) { h = "reg"; if (this.fastupdate) { k = y(); - for (let m of this.reg.keys()) { - k[m] = 1; + for (let l of this.reg.keys()) { + k[l] = 1; } } else { k = this.reg; @@ -640,7 +633,7 @@ u.export = function(a, c, b, d, f, e) { "undefined" === typeof b && e && e(); return; } - na(a, c || this, b, h, d, f, k, e); + ma(a, c || this, b, h, d, f, k, e); return g; }; u.import = function(a, c) { @@ -673,11 +666,11 @@ u.serialize = function(a = !0) { d = ""; for (var f of this.map.entries()) { var e = f[0], g = f[1], h = ""; - for (let l = 0, r; l < g.length; l++) { - r = g[l] || [""]; + for (let n = 0, r; n < g.length; n++) { + r = g[n] || [""]; var k = ""; - for (var m = 0; m < r.length; m++) { - k += (k ? "," : "") + ("string" === b ? '"' + r[m] + '"' : r[m]); + for (var l = 0; l < r.length; l++) { + k += (k ? "," : "") + ("string" === b ? '"' + r[l] + '"' : r[l]); } k = "[" + k + "]"; h += (h ? "," : "") + k; @@ -687,21 +680,21 @@ u.serialize = function(a = !0) { } d = "index.map=new Map([" + d + "]);"; f = ""; - for (const l of this.ctx.entries()) { - e = l[0]; - g = l[1]; + for (const n of this.ctx.entries()) { + e = n[0]; + g = n[1]; for (const r of g.entries()) { g = r[0]; h = r[1]; k = ""; for (let t = 0, p; t < h.length; t++) { p = h[t] || [""]; - m = ""; - for (let n = 0; n < p.length; n++) { - m += (m ? "," : "") + ("string" === b ? '"' + p[n] + '"' : p[n]); + l = ""; + for (let m = 0; m < p.length; m++) { + l += (l ? "," : "") + ("string" === b ? '"' + p[m] + '"' : p[m]); } - m = "[" + m + "]"; - k += (k ? "," : "") + m; + l = "[" + l + "]"; + k += (k ? "," : "") + l; } k = 'new Map([["' + g + '",[' + k + "]]])"; k = '["' + e + '",' + k + "]"; @@ -711,7 +704,7 @@ u.serialize = function(a = !0) { f = "index.ctx=new Map([" + f + "]);"; return a ? "function inject(index){" + c + d + f + "}" : c + d + f; }; -pa(O.prototype); +oa(P.prototype); W.prototype.add = function(a, c, b) { E(a) && (c = a, a = F(c, this.key)); if (c && (a || 0 === a)) { @@ -800,25 +793,25 @@ function X(a, c, b, d, f, e, g, h) { b || (!c && E(a) ? (b = a, a = "") : E(c) && (b = c, c = 0)); let f = []; var e = []; - let g, h, k, m, l; + let g, h, k, l, n; let r = 0; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var t = b.pluck; h = b.merge; - m = t || b.field || b.index; - l = !1; + l = t || b.field || b.index; + n = !1; g = this.store && b.enrich; k = b.suggest; c = b.limit || c; var p = b.offset || 0; c || (c = 100); - if (l) { - l.constructor !== Array && (l = [l]); - var n = []; - for (let v = 0, q; v < l.length; v++) { - q = l[v]; + if (n) { + n.constructor !== Array && (n = [n]); + var m = []; + for (let v = 0, q; v < n.length; v++) { + q = n[v]; if (z(q)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } @@ -826,33 +819,33 @@ function X(a, c, b, d, f, e, g, h) { var w = q.tag; if (w.constructor === Array) { for (var B = 0; B < w.length; B++) { - n.push(q.field, w[B]); + m.push(q.field, w[B]); } } else { - n.push(q.field, w); + m.push(q.field, w); } } else { w = Object.keys(q); for (let C = 0, D, A; C < w.length; C++) { if (D = w[C], A = q[D], A.constructor === Array) { for (B = 0; B < A.length; B++) { - n.push(D, A[B]); + m.push(D, A[B]); } } else { - n.push(D, A); + m.push(D, A); } } } } - if (!n.length) { + if (!m.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - l = n; + n = m; if (!a) { d = []; - if (n.length) { - for (e = 0; e < n.length; e += 2) { - t = sa.call(this, n[e], n[e + 1], c, p, g), f.push({field:n[e], tag:n[e + 1], result:t}); + if (m.length) { + for (e = 0; e < m.length; e += 2) { + t = sa.call(this, m[e], m[e + 1], c, p, g), f.push({field:m[e], tag:m[e + 1], result:t}); } } return d.length ? Promise.all(d).then(function(v) { @@ -863,46 +856,46 @@ function X(a, c, b, d, f, e, g, h) { }) : f; } } - z(m) && (m = [m]); + z(l) && (l = [l]); } - m || (m = this.field); + l || (l = this.field); p = !d && (this.worker || this.db) && []; - for (let v = 0, q, C, D; v < m.length; v++) { - C = m[v]; + for (let v = 0, q, C, D; v < l.length; v++) { + C = l[v]; let A; z(C) || (A = C, C = A.field, a = A.query || a, c = A.limit || c, k = A.suggest || k); if (d) { q = d[v]; } else { - if (n = A || b, w = this.index.get(C), l && (n.enrich = !1), p) { - p[v] = w.searchAsync(a, c, n); - n && g && (n.enrich = g); + if (m = A || b, w = this.index.get(C), n && (m.enrich = !1), p) { + p[v] = w.searchAsync(a, c, m); + m && g && (m.enrich = g); continue; } else { - q = w.search(a, c, n), n && g && (n.enrich = g); + q = w.search(a, c, m), m && g && (m.enrich = g); } } D = q && q.length; - if (l && D) { - n = []; + if (n && D) { + m = []; w = 0; - for (let G = 0, H, ua; G < l.length; G += 2) { - H = this.tag.get(l[G]); + for (let G = 0, H, ua; G < n.length; G += 2) { + H = this.tag.get(n[G]); if (!H) { - if (console.warn("Tag '" + l[G] + ":" + l[G + 1] + "' will be skipped because there is no field '" + l[G] + "'."), k) { + if (console.warn("Tag '" + n[G] + ":" + n[G + 1] + "' will be skipped because there is no field '" + n[G] + "'."), k) { continue; } else { return f; } } - if (ua = (H = H && H.get(l[G + 1])) && H.length) { - w++, n.push(H); + if (ua = (H = H && H.get(n[G + 1])) && H.length) { + w++, m.push(H); } else if (!k) { return f; } } if (w) { - q = qa(q, n); + q = qa(q, m); D = q.length; if (!D && !k) { return f; @@ -912,7 +905,7 @@ function X(a, c, b, d, f, e, g, h) { } if (D) { e[r] = C, f.push(q), r++; - } else if (1 === m.length) { + } else if (1 === l.length) { return f; } } @@ -944,15 +937,15 @@ function va(a, c) { for (let f = 0, e, g; f < a.length; f++) { e = a[f]; g = e.result; - for (let h = 0, k, m, l; h < g.length; h++) { - if (m = g[h], k = m.id, l = d[k]) { - l.push(e.field); + for (let h = 0, k, l, n; h < g.length; h++) { + if (l = g[h], k = l.id, n = d[k]) { + n.push(e.field); } else { if (b.length === c) { return b; } - m.field = d[k] = [e.field]; - b.push(m); + l.field = d[k] = [e.field]; + b.push(l); } } } @@ -995,7 +988,7 @@ function ta(a) { let d = c.index || c.field || c; z(d) && (d = [d]); for (let f = 0, e, g; f < d.length; f++) { - e = d[f], z(e) || (g = e, e = e.field), g = E(g) ? Object.assign({}, a, g) : a, b.set(e, new O(g, this.reg)), g.custom ? this.A[f] = g.custom : (this.A[f] = Z(e, this.D), g.filter && ("string" === typeof this.A[f] && (this.A[f] = new String(this.A[f])), this.A[f].H = g.filter)), this.field[f] = e; + e = d[f], z(e) || (g = e, e = e.field), g = E(g) ? Object.assign({}, a, g) : a, b.set(e, new P(g, this.reg)), g.custom ? this.A[f] = g.custom : (this.A[f] = Z(e, this.D), g.filter && ("string" === typeof this.A[f] && (this.A[f] = new String(this.A[f])), this.A[f].H = g.filter)), this.field[f] = e; } if (this.h) { a = c.store; @@ -1081,7 +1074,7 @@ u.export = function(a, c, b, d, f, e) { e(); return; } - na(a, this, b, c, d, f, h, e); + ma(a, this, b, c, d, f, h, e); } return g; }; @@ -1109,7 +1102,7 @@ u.import = function(a, c) { } } }; -pa(W.prototype); -export default {Index:O, Charset:ma, Encoder:J, Document:W, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +oa(W.prototype); +export default {Index:P, Charset:la, Encoder:J, Document:W, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=O;export const Charset=ma;export const Encoder=J;export const Document=W;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=P;export const Charset=la;export const Encoder=J;export const Document=W;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 534e4be..5053cc7 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -6,7 +6,7 @@ * https://github.com/nextapps-de/flexsearch */ var u;function x(a,c,b){const d=typeof b,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(b){if("function"===e&&d===e)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"===e?c:a}function y(){return Object.create(null)}function aa(a,c){return c.length-a.length} -function A(a){return"string"===typeof a}function E(a){return"object"===typeof a}function F(a,c){if(A(c))a=a[c];else for(let b=0;a&&bthis.stemmer.get(h)),g=1);this.matcher&&1this.matcher.get(h)),g=1);f&&g&&(f.lengthf;h--){g=n.substring(f,h);var k=this.score?this.score(c,n,p,g,f):P(t,d,p,e,f);Q(this,l,g,k,a,b)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,p,h-1,k-1),B=this.bidirectional&&n>f;Q(this,m,B?f:n,w,a,b,B?n:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Q(a,c,b,d,e,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=y()),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[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function P(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,f,g;e=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),d.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;d=[f]}c-=g;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d};function S(a,c,b,d){return(a=T(this,a,c))&&a.length?R(a,b,d):[]} -function ra(a,c,b,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,m=0,l;k=e)))break;if(h.length){if(g)return R(h,e,0);c.push(h);return}}return!b&&h}function T(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b: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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===b.length-1?e.pop():e.splice(f,1)}}else U(this.map,a),this.depth&&U(this.ctx,a);c||this.reg.delete(a)}return this}; -function U(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,f;db.add(a,c)):this.add(a,c)}; +this.minlength)continue;if(c){b.push(f);continue}if(this.filter&&this.filter.has(f))continue;let g;this.stemmer&&2this.stemmer.get(h)),g=1);this.matcher&&1this.matcher.get(h)),g=1);f&&g&&(f.lengthf;h--){g=m.substring(f,h);var k=this.score?this.score(c,m,p,g,f):Q(t,d,p,e,f);R(this,n,g,k,a,b)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,p,h-1,k-1),B=this.bidirectional&&m>f;R(this,l,B?f:m,w,a,b,B?m:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function R(a,c,b,d,e,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=y()),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[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function Q(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,f,g;e=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),d.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;d=[f]}c-=g;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d};function S(a,c,b,d){return(a=T(this,a,c))&&a.length?pa(a,b,d):[]} +function ra(a,c,b,d){let e=[];if(a){d=Math.min(a.length,d);for(let f=0,g;fb);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};P.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===b.length-1?e.pop():e.splice(f,1)}}else U(this.map,a),this.depth&&U(this.ctx,a);c||this.reg.delete(a)}return this}; +function U(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,f;db.add(a,c)):this.add(a,c)}; function V(a){let c=0;if(a.constructor===Array)for(let b=0,d;b{f=m}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let m of this.reg.keys())k[m]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.C?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}na(a,c||this,b,h,d,e,k,f);return g}; -u.import=function(a,c){if(c)switch(A(c)&&(c=JSON.parse(c)),a){case "cfg":this.C=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}}; -u.serialize=function(a=!0){if(!this.reg.size)return"";let c="",b="";for(var d of this.reg.keys())b||(b=typeof d),c+=(c?",":"")+("string"===b?'"'+d+'"':d);c="index.reg=new Set(["+c+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let l=0,r;lb||d)a=a.slice(d,d+b);e&&(a=ta.call(this,a));return a}} -function ta(a){const c=Array(a.length);for(let b=0,d;b{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.C?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}ma(a,c||this,b,h,d,e,k,f);return g}; +u.import=function(a,c){if(c)switch(z(c)&&(c=JSON.parse(c)),a){case "cfg":this.C=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}}; +u.serialize=function(a=!0){if(!this.reg.size)return"";let c="",b="";for(var d of this.reg.keys())b||(b=typeof d),c+=(c?",":"")+("string"===b?'"'+d+'"':d);c="index.reg=new Set(["+c+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let n=0,r;nb||d)a=a.slice(d,d+b);e&&(a=ta.call(this,a));return a}} +function ta(a){const c=Array(a.length);for(let b=0,d;b{f=k}));e||(e=0);d||(d=0);if(d{f=k}));e||(e=0);d||(d=0);if(d c && (c = Math.max(c + e, 0)); c < e; c++) { - var g = d[c]; - if (g === b || Object.is(g, b)) { + var h = d[c]; + if (h === b || Object.is(h, b)) { return !0; } } @@ -830,8 +830,8 @@ function K(a, b, c) { if ("undefined" !== e) { if (c) { if ("function" === e && d === e) { - return function(g) { - return a(c(g)); + return function(h) { + return a(c(h)); }; } b = a.constructor; @@ -912,15 +912,15 @@ function Q(a) { if (!this) { var b = Function.prototype.bind, c = b.apply, d = [null], e = d.concat; if (arguments instanceof Array) { - var g = arguments; + var h = arguments; } else { - g = x(arguments); - for (var f, h = []; !(f = g.next()).done;) { - h.push(f.value); + h = x(arguments); + for (var f, g = []; !(f = h.next()).done;) { + g.push(f.value); } - g = h; + h = g; } - return new (c.call(b, Q, e.call(d, g)))(); + return new (c.call(b, Q, e.call(d, h)))(); } for (b = 0; b < arguments.length; b++) { this.assign(arguments[b]); @@ -942,14 +942,14 @@ Q.prototype.assign = function(a) { } try { this.split = new RegExp("[" + (b ? "^" : "") + e + "]+", "u"); - } catch (g) { + } catch (h) { this.split = /\s+/; } this.numeric = d; } else { try { this.split = K(c, Aa, this.split); - } catch (g) { + } catch (h) { this.split = /\s+/; } this.numeric = K(this.numeric, !0); @@ -970,7 +970,7 @@ Q.prototype.assign = function(a) { this.U = null, this.J = "number" === typeof c ? c : 2e5, this.N = new Map(), this.S = new Map(), this.A = this.h = 128; } this.B = ""; - this.D = null; + this.F = null; this.C = ""; this.G = null; if (this.matcher) { @@ -999,8 +999,8 @@ Q.prototype.encode = function(a) { this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : Ea ? a.normalize("NFKD").replace(Ea, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(Ca, "$1 $2").replace(Da, "$1 $2").replace(Ba, "$1 ")); - for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, g = 0, f = void 0, h = void 0; g < e.length; g++) { - if ((f = h = e[g]) && !(f.length < this.minlength)) { + for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, h = 0, f = void 0, g = void 0; h < e.length; h++) { + if ((f = g = e[h]) && !(f.length < this.minlength)) { if (c) { d.push(f); } else { @@ -1020,7 +1020,7 @@ Q.prototype.encode = function(a) { this.stemmer && 2 < f.length && (this.G || (this.G = new RegExp("(?!^)(" + this.C + ")$")), f = f.replace(this.G, function(q) { return b.stemmer.get(q); }), k = 1); - this.matcher && 1 < f.length && (this.D || (this.D = new RegExp("(" + this.B + ")", "g")), f = f.replace(this.D, function(q) { + this.matcher && 1 < f.length && (this.F || (this.F = new RegExp("(" + this.B + ")", "g")), f = f.replace(this.F, function(q) { return b.matcher.get(q); }), k = 1); f && k && (f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); @@ -1036,7 +1036,7 @@ Q.prototype.encode = function(a) { f = f.replace(this.replacer[k], this.replacer[k + 1]); } } - this.cache && h.length <= this.A && (this.S.set(h, f), this.S.size > this.J && (this.S.clear(), this.A = this.A / 1.1 | 0)); + this.cache && g.length <= this.A && (this.S.set(g, f), this.S.size > this.J && (this.S.clear(), this.A = this.A / 1.1 | 0)); f && d.push(f); } } @@ -1058,9 +1058,9 @@ function Fa(a) { d = this.search(a, b, c); if (d.then) { var e = this; - d.then(function(g) { - e.cache.set(a, g); - return g; + d.then(function(h) { + e.cache.set(a, h); + return h; }); } this.cache.set(a, d); @@ -1103,7 +1103,7 @@ var Na = /[\x00-\x7F]+/g; var Oa = /[\x00-\x7F]+/g; var Pa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ha, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ia}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ia, replacer:Ka, matcher:Ja}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ia, replacer:Ka.concat([/(?!^)[aeoy]/g, ""]), matcher:Ja}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (var b = 0; b < a.length; b++) { - for (var c = a[b], d = c.charAt(0), e = La[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = La[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { + for (var c = a[b], d = c.charAt(0), e = La[d], h = 1, f; h < c.length && (f = c.charAt(h), "h" === f || "w" === f || !(f = La[f]) || f === e || (d += f, e = f, 4 !== d.length)); h++) { } a[b] = d; } @@ -1115,8 +1115,8 @@ var Pa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ha, LatinSimple:{no return ("" + a).replace(Oa, " "); }}}; function Qa(a, b, c, d) { - for (var e = [], g = 0, f; g < a.index.length; g++) { - if (f = a.index[g], b >= f.length) { + for (var e = [], h = 0, f; h < a.index.length; h++) { + if (f = a.index[h], b >= f.length) { b -= f.length; } else { b = f[d ? "splice" : "slice"](b, c); @@ -1156,21 +1156,21 @@ function S(a) { } if ("indexOf" === d) { return function(e) { - for (var g = 0, f = 0, h, k; f < b.index.length; f++) { - h = b.index[f]; - k = h.indexOf(e); + for (var h = 0, f = 0, g, k; f < b.index.length; f++) { + g = b.index[f]; + k = g.indexOf(e); if (0 <= k) { - return g + k; + return h + k; } - g += h.length; + h += g.length; } return -1; }; } if ("includes" === d) { return function(e) { - for (var g = 0; g < b.index.length; g++) { - if (b.index[g].includes(e)) { + for (var h = 0; h < b.index.length; h++) { + if (b.index[h].includes(e)) { return !0; } } @@ -1178,13 +1178,13 @@ function S(a) { }; } if ("slice" === d) { - return function(e, g) { - return Qa(b, e || 0, g || b.length, !1); + return function(e, h) { + return Qa(b, e || 0, h || b.length, !1); }; } if ("splice" === d) { - return function(e, g) { - return Qa(b, e || 0, g || b.length, !0); + return function(e, h) { + return Qa(b, e || 0, h || b.length, !0); }; } if ("constructor" === d) { @@ -1254,7 +1254,7 @@ u.clear = U.prototype.clear = function() { this.size = 0; }; u.values = U.prototype.values = function Ta() { - var b, c = this, d, e, g; + var b, c = this, d, e, h; return qa(Ta, function(f) { switch(f.h) { case 1: @@ -1272,15 +1272,15 @@ u.values = U.prototype.values = function Ta() { f.h = 2; break; } - g = e.value; - return F(f, g, 6); + h = e.value; + return F(f, h, 6); case 6: e = d.next(), f.h = 5; } }); }; u.keys = U.prototype.keys = function Ua() { - var b, c = this, d, e, g; + var b, c = this, d, e, h; return qa(Ua, function(f) { switch(f.h) { case 1: @@ -1298,15 +1298,15 @@ u.keys = U.prototype.keys = function Ua() { f.h = 2; break; } - g = e.value; - return F(f, g, 6); + h = e.value; + return F(f, h, 6); case 6: e = d.next(), f.h = 5; } }); }; u.entries = U.prototype.entries = function Va() { - var b, c = this, d, e, g; + var b, c = this, d, e, h; return qa(Va, function(f) { switch(f.h) { case 1: @@ -1324,8 +1324,8 @@ u.entries = U.prototype.entries = function Va() { f.h = 2; break; } - g = e.value; - return F(f, g, 6); + h = e.value; + return F(f, h, 6); case 6: e = d.next(), f.h = 5; } @@ -1344,10 +1344,10 @@ function Sa(a) { function Ra() { throw Error("The keystore is limited to 32 for EcmaScript5"); } -;function Wa(a, b, c, d, e, g, f, h) { +;function Wa(a, b, c, d, e, h, f, g) { (d = a(c ? c + "." + d : d, JSON.stringify(f))) && d.then ? d.then(function() { - b.export(a, b, c, e, g + 1, h); - }) : b.export(a, b, c, e, g + 1, h); + b.export(a, b, c, e, h + 1, g); + }) : b.export(a, b, c, e, h + 1, g); } ;var Xa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; function Ya(a) { @@ -1377,18 +1377,18 @@ V.prototype.add = function(a, b, c, d) { } b = this.encoder.encode(b); if (d = b.length) { - for (var e = L(), g = L(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { + for (var e = L(), h = L(), f = this.depth, g = this.resolution, k = 0; k < d; k++) { var l = b[this.rtl ? d - 1 - k : k], m = l.length; - if (m && (f || !g[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : $a(h, d, k), p = ""; + if (m && (f || !h[l])) { + var n = this.score ? this.score(b, l, k, null, 0) : $a(g, d, k), p = ""; switch(this.tokenize) { case "full": if (2 < m) { for (n = 0; n < m; n++) { for (var q = m; q > n; q--) { p = l.substring(n, q); - var r = this.score ? this.score(b, l, k, p, n) : $a(h, d, k, m, n); - ab(this, g, p, r, a, c); + var r = this.score ? this.score(b, l, k, p, n) : $a(g, d, k, m, n); + ab(this, h, p, r, a, c); } } break; @@ -1396,20 +1396,20 @@ V.prototype.add = function(a, b, c, d) { case "reverse": if (1 < m) { for (q = m - 1; 0 < q; q--) { - p = l[q] + p, r = this.score ? this.score(b, l, k, p, q) : $a(h, d, k, m, q), ab(this, g, p, r, a, c); + p = l[q] + p, r = this.score ? this.score(b, l, k, p, q) : $a(g, d, k, m, q), ab(this, h, p, r, a, c); } p = ""; } case "forward": if (1 < m) { for (q = 0; q < m; q++) { - p += l[q], ab(this, g, p, n, a, c); + p += l[q], ab(this, h, p, n, a, c); } break; } default: - if (ab(this, g, l, n, a, c), f && 1 < d && k < d - 1) { - for (m = L(), p = this.ba, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) { + if (ab(this, h, l, n, a, c), f && 1 < d && k < d - 1) { + for (m = L(), p = this.aa, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) { if ((l = b[this.rtl ? d - 1 - k - r : k + r]) && !m[l]) { m[l] = 1; var y = this.score ? this.score(b, n, k, l, r) : $a(p + (d / 2 > p ? 0 : 1), d, k, q - 1, r - 1), v = this.bidirectional && l > n; @@ -1425,24 +1425,24 @@ V.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.ea && bb(this)); + this.db && (b || this.commit_task.push({del:a}), this.da && bb(this)); return this; }; -function ab(a, b, c, d, e, g, f) { - var h = f ? a.ctx : a.map, k; +function ab(a, b, c, d, e, h, f) { + var g = f ? a.ctx : a.map, k; if (!b[c] || !f || !(k = b[c])[f]) { - if (f ? (b = k || (b[c] = L()), 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 (f ? (b = k || (b[c] = L()), b[f] = 1, (k = g.get(f)) ? g = k : g.set(f, g = new Map())) : b[c] = 1, (k = g.get(c)) ? g = k : g.set(c, g = k = []), g = g[d] || (g[d] = []), !h || !g.includes(e)) { + if (g.length === Math.pow(2, 31) - 1) { + b = new S(g); 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); + for (c = x(a.reg.values()), h = c.next(); !h.done; h = c.next()) { + h = h.value, h.includes(g) && (h[h.indexOf(g)] = b); } } - k[d] = h = b; + k[d] = g = b; } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + g.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(g) : a.reg.set(e, [g])); } } } @@ -1453,24 +1453,24 @@ function $a(a, b, c, d, e) { if (1 === a.length) { return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? cb(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 = [], h = 0, f = void 0, g = void 0; h < a.length; h++) { + if ((f = a[h]) && (g = f.length)) { if (c) { - if (c >= h) { - c -= h; + if (c >= g) { + c -= g; continue; } - c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); + c < g && (f = b ? f.slice(c, c + b) : f.slice(c), g = f.length, c = 0); } if (e.length) { - h > b && (f = f.slice(0, b), h = f.length), e.push(f); + g > b && (f = f.slice(0, b), g = f.length), e.push(f); } else { - if (h >= b) { - return h > b && (f = f.slice(0, b)), d ? cb(f) : f; + if (g >= b) { + return g > b && (f = f.slice(0, b)), d ? cb(f) : f; } e = [f]; } - b -= h; + b -= g; if (!b) { break; } @@ -1500,7 +1500,7 @@ function cb(a) { } var d = []; c = []; - for (var e = 0, g = 0, f, h, k = 0, l = void 0; k < b.length; k++) { + for (var e = 0, h = 0, f, g, k = 0, l = void 0; k < b.length; k++) { if (l = b[k]) { var m = void 0; if (l.constructor === X) { @@ -1517,9 +1517,9 @@ function cb(a) { m = this.not(l.not); } else { e = l.limit || 0; - g = l.offset || 0; + h = l.offset || 0; f = l.enrich; - h = l.resolve; + g = l.resolve; continue; } d[k] = m; @@ -1529,15 +1529,15 @@ function cb(a) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = [a.result].concat(d)); - a.result = db(d, e, g, f, h, a.K); - return h ? a.result : a; + a.result = db(d, e, h, f, g, a.K); + return g ? a.result : a; }); } this.result.length && (d = [this.result].concat(d)); - this.result = db(d, e, g, f, h, a.K); - return h ? this.result : this; + this.result = db(d, e, h, f, g, a.K); + return g ? this.result : this; }; -function db(a, b, c, d, e, g) { +function db(a, b, c, d, e, h) { if (!a.length) { return a; } @@ -1546,19 +1546,19 @@ function db(a, b, c, d, e, g) { return e ? W(a[0], b, c, d) : a[0]; } d = []; - for (var f = 0, h = L(), k = ya(a), l = 0, m; l < k; l++) { + for (var f = 0, g = L(), k = ya(a), l = 0, m; l < k; l++) { for (var n = 0; n < a.length; n++) { if (m = a[n]) { if (m = m[l]) { for (var p = 0, q; p < m.length; p++) { - if (q = m[p], !h[q]) { - if (h[q] = 1, c) { + if (q = m[p], !g[q]) { + if (g[q] = 1, c) { c--; } else { if (e) { d.push(q); } else { - var r = l + (n ? g : 0); + var r = l + (n ? h : 0); d[r] || (d[r] = []); d[r].push(q); } @@ -1587,8 +1587,8 @@ function db(a, b, c, d, e, g) { } var d = []; c = []; - for (var e = 0, g = 0, f, h = 0, k = void 0; h < b.length; h++) { - if (k = b[h]) { + for (var e = 0, h = 0, f, g = 0, k = void 0; g < b.length; g++) { + if (k = b[g]) { var l = void 0; if (k.constructor === X) { l = k.result; @@ -1604,23 +1604,23 @@ function db(a, b, c, d, e, g) { l = this.not(k.not); } else { e = k.limit || 0; - g = k.offset || 0; + h = k.offset || 0; f = k.resolve; continue; } - d[h] = l; + d[g] = l; l.then && c.push(l); } } if (c.length) { return Promise.all(c).then(function() { d = [a.result].concat(d); - a.result = eb(d, e, g, f, a.K); + a.result = eb(d, e, h, f, a.K); return f ? a.result : a; }); } d = [this.result].concat(d); - this.result = eb(d, e, g, f, a.K); + this.result = eb(d, e, h, f, a.K); return f ? this.result : this; } return this; @@ -1629,9 +1629,9 @@ function eb(a, b, c, d, e) { if (2 > a.length) { return []; } - var g = [], f = 0, h = L(), k = ya(a); + var h = [], f = 0, g = L(), k = ya(a); if (!k) { - return g; + return h; } for (var l = 0, m; l < a.length; l++) { m = a[l]; @@ -1644,16 +1644,16 @@ function eb(a, b, c, d, e) { if (t = y[v], !l) { n[t] = r + 1 + (l ? e : 0), p = 1; } else if (q) { - if (w = h[t]) { + if (w = g[t]) { if (p = 1, c) { c--; } else { - if (d ? g.push(t) : (w--, r < w && (w = r), g[w] || (g[w] = []), g[w].push(t)), b && ++f === b) { - return g; + if (d ? h.push(t) : (w--, r < w && (w = r), h[w] || (h[w] = []), h[w].push(t)), b && ++f === b) { + return h; } } } - } else if (w = h[t]) { + } else if (w = g[t]) { r + 1 < w && (w = r + 1), n[t] = w, p = 1; } } @@ -1662,9 +1662,9 @@ function eb(a, b, c, d, e) { if (!p) { return []; } - h = n; + g = n; } - return g; + return h; } ;X.prototype.xor = function() { var a = this, b = arguments, c = b[0]; @@ -1678,7 +1678,7 @@ function eb(a, b, c, d, e) { } var d = []; c = []; - for (var e = 0, g = 0, f, h, k = 0, l = void 0; k < b.length; k++) { + for (var e = 0, h = 0, f, g, k = 0, l = void 0; k < b.length; k++) { if (l = b[k]) { var m = void 0; if (l.constructor === X) { @@ -1695,9 +1695,9 @@ function eb(a, b, c, d, e) { m = this.not(l.not); } else { e = l.limit || 0; - g = l.offset || 0; + h = l.offset || 0; f = l.enrich; - h = l.resolve; + g = l.resolve; continue; } d[k] = m; @@ -1707,15 +1707,15 @@ function eb(a, b, c, d, e) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = [a.result].concat(d)); - a.result = fb(d, e, g, f, !h, a.K); - return h ? a.result : a; + a.result = fb(d, e, h, f, !g, a.K); + return g ? a.result : a; }); } this.result.length && (d = [this.result].concat(d)); - this.result = fb(d, e, g, f, !h, a.K); - return h ? this.result : this; + this.result = fb(d, e, h, f, !g, a.K); + return g ? this.result : this; }; -function fb(a, b, c, d, e, g) { +function fb(a, b, c, d, e, h) { if (!a.length) { return a; } @@ -1727,8 +1727,8 @@ function fb(a, b, c, d, e, g) { d = 0; for (var f; d < a.length; d++) { if (f = a[d]) { - for (var h = 0, k; h < f.length; h++) { - if (k = f[h]) { + for (var g = 0, k; g < f.length; g++) { + if (k = f[g]) { for (var l = 0, m; l < k.length; l++) { m = k[l], c[m] ? c[m]++ : c[m] = 1; } @@ -1738,14 +1738,14 @@ function fb(a, b, c, d, e, g) { } for (d = 0; d < a.length; d++) { if (f = a[d]) { - for (h = 0; h < f.length; h++) { - if (k = f[h]) { + for (g = 0; g < f.length; g++) { + if (k = f[g]) { for (l = 0; l < k.length; l++) { if (m = k[l], 1 === c[m]) { if (e) { b.push(m); } else { - var n = h + (d ? g : 0); + var n = g + (d ? h : 0); b[n] || (b[n] = []); b[n].push(m); } @@ -1769,27 +1769,27 @@ function fb(a, b, c, d, e, g) { } var d = []; c = []; - for (var e, g = 0, f = void 0; g < b.length; g++) { - if (f = b[g]) { - var h = void 0; + for (var e, h = 0, f = void 0; h < b.length; h++) { + if (f = b[h]) { + var g = void 0; if (f.constructor === X) { - h = f.result; + g = f.result; } else if (f.constructor === Array) { - h = f; + g = f; } else if (f.index) { - f.resolve = !1, h = f.index.search(f).result; + f.resolve = !1, g = f.index.search(f).result; } else if (f.or) { - h = this.or(f.or); + g = this.or(f.or); } else if (f.and) { - h = this.and(f.and); + g = this.and(f.and); } else if (f.xor) { - h = this.xor(f.xor); + g = this.xor(f.xor); } else { e = f.resolve; continue; } - d[g] = h; - h.then && c.push(h); + d[h] = g; + g.then && c.push(g); } } if (c.length) { @@ -1809,8 +1809,8 @@ function gb(a, b) { a = new Set(a.flat().flat()); for (var d = 0, e; d < this.result.length; d++) { if (e = this.result[d]) { - for (var g = 0, f; g < e.length; g++) { - f = e[g], a.has(f) || (b ? c.push(f) : (c[d] || (c[d] = []), c[d].push(f))); + for (var h = 0, f; h < e.length; h++) { + f = e[h], a.has(f) || (b ? c.push(f) : (c[d] || (c[d] = []), c[d].push(f))); } } } @@ -1864,13 +1864,13 @@ X.prototype.resolve = function(a, b, c) { return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), W(d, a || 100, b, c)) : d; }; function ib(a, b, c, d, e) { - var g = a.length, f = [], h; + var h = a.length, f = [], g; var k = L(); for (var l = 0, m = void 0, n; l < b; l++) { - for (var p = 0; p < g; p++) { + for (var p = 0; p < h; p++) { if (n = a[p], l < n.length && (m = n[l])) { for (var q = 0; q < m.length; q++) { - n = m[q], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), h = f[h] || (f[h] = []), h.push(n); + n = m[q], (g = k[n]) ? k[n]++ : (g = 0, k[n] = 1), g = f[g] || (f[g] = []), g.push(n); } } } @@ -1879,7 +1879,7 @@ function ib(a, b, c, d, e) { if (e) { if (1 < f.length) { e = f; - g = []; + h = []; f = L(); k = e.length; for (m = 0; m < k; m++) { @@ -1888,20 +1888,20 @@ function ib(a, b, c, d, e) { if (f[b] = 1, d) { d--; } else { - if (g.push(b), g.length === c) { + if (h.push(b), h.length === c) { break; } } } } } - c = g; + c = h; } else { c = f[0]; } f = c; } else { - if (a < g) { + if (a < h) { return []; } f = f[a - 1]; @@ -1913,10 +1913,10 @@ function ib(a, b, c, d, e) { return f; } function jb(a, b) { - for (var c = L(), d = [], e = 0, g; e < b.length; e++) { - g = b[e]; - for (var f = 0; f < g.length; f++) { - c[g[f]] = 1; + for (var c = L(), d = [], e = 0, h; e < b.length; e++) { + h = b[e]; + for (var f = 0; f < h.length; f++) { + c[h[f]] = 1; } } for (b = 0; b < a.length; b++) { @@ -1927,37 +1927,37 @@ function jb(a, b) { ;var hb = 1; V.prototype.search = function(a, b, c) { c || (!b && N(a) ? (c = a, a = "") : N(b) && (c = b, b = 0)); - var d = [], e = 0, g; + var d = [], e = 0, h; if (c) { a = c.query || a; b = c.limit || b; e = c.offset || 0; var f = c.context; - var h = c.suggest; - (g = hb && !1 !== c.resolve) || (hb = 0); - var k = g && c.enrich; + var g = c.suggest; + (h = hb && !1 !== c.resolve) || (hb = 0); + var k = h && c.enrich; var l = this.db && c.tag; } else { - g = this.resolve || hb; + h = this.resolve || hb; } a = this.encoder.encode(a); var m = a.length; - b || !g || (b = 100); + b || !h || (b = 100); if (1 === m) { - return kb.call(this, a[0], "", b, e, g, k, l); + return kb.call(this, a[0], "", b, e, h, k, l); } f = this.depth && !1 !== f; - if (2 === m && f && !h) { - return kb.call(this, a[0], a[1], b, e, g, k, l); + if (2 === m && f && !g) { + return kb.call(this, a[0], a[1], b, e, h, k, l); } var n = c = 0; if (1 < m) { for (var p = L(), q = [], r = 0, y = void 0; r < m; r++) { if ((y = a[r]) && !p[y]) { - if (h || this.db || Y(this, y)) { + if (g || this.db || Y(this, y)) { q.push(y), p[y] = 1; } else { - return g ? d : new X(d); + return h ? d : new X(d); } y = y.length; c = Math.max(c, y); @@ -1968,14 +1968,14 @@ V.prototype.search = function(a, b, c) { m = a.length; } if (!m) { - return g ? d : new X(d); + return h ? d : new X(d); } var v = 0; if (1 === m) { - return kb.call(this, a[0], "", b, e, g, k, l); + return kb.call(this, a[0], "", b, e, h, k, l); } - if (2 === m && f && !h) { - return kb.call(this, a[0], a[1], b, e, g, k, l); + if (2 === m && f && !g) { + return kb.call(this, a[0], a[1], b, e, h, k, l); } if (1 < m) { if (f) { @@ -1986,7 +1986,7 @@ V.prototype.search = function(a, b, c) { } } if (this.db) { - if (this.db.search && (f = this.db.search(this, a, b, e, h, g, k, l), !1 !== f)) { + if (this.db.search && (f = this.db.search(this, a, b, e, g, h, k, l), !1 !== f)) { return f; } var w = this; @@ -2002,19 +2002,19 @@ V.prototype.search = function(a, b, c) { break; } D = a[v]; - return t ? F(E, Y(w, D, t), 8) : F(E, Y(w, D), 7); + return t ? F(E, Y(w, D, t, 0, 0, !1, !1), 8) : F(E, Y(w, D, "", 0, 0, !1, !1), 7); case 7: - A = E.D; - A = lb(A, d, h, w.resolution, b, e, 1 === m); + A = E.F; + A = lb(A, d, g, w.resolution); E.h = 6; break; case 8: - A = E.D, A = lb(A, d, h, w.ba, b, e, 2 === m), h && !1 === A && d.length || (t = D); + A = E.F, A = lb(A, d, g, w.aa), g && !1 === A && d.length || (t = D); case 6: if (A) { return E.return(A); } - if (h && v === m - 1) { + if (g && v === m - 1) { B = d.length; if (!B) { if (t) { @@ -2026,7 +2026,7 @@ V.prototype.search = function(a, b, c) { return E.return(d); } if (1 === B) { - return E.return(g ? W(d[0], b, e) : new X(d[0])); + return E.return(h ? W(d[0], b, e) : new X(d[0])); } } case 3: @@ -2034,18 +2034,18 @@ V.prototype.search = function(a, b, c) { E.h = 2; break; case 4: - return E.return(g ? ib(d, w.resolution, b, e, h) : new X(d[0])); + return E.return(h ? ib(d, w.resolution, b, e, g) : new X(d[0])); } }); }(); } for (k = f = void 0; v < m; v++) { k = a[v]; - t ? (f = Y(this, k, t), f = lb(f, d, h, this.ba, b, e, 2 === m), h && !1 === f && d.length || (t = k)) : (f = Y(this, k), f = lb(f, d, h, this.resolution, b, e, 1 === m)); + t ? (f = Y(this, k, t, 0, 0, !1, !1), f = lb(f, d, g, this.aa), g && !1 === f && d.length || (t = k)) : (f = Y(this, k, "", 0, 0, !1, !1), f = lb(f, d, g, this.resolution)); if (f) { return f; } - if (h && v === m - 1) { + if (g && v === m - 1) { f = d.length; if (!f) { if (t) { @@ -2056,45 +2056,38 @@ V.prototype.search = function(a, b, c) { return d; } if (1 === f) { - return g ? W(d[0], b, e) : new X(d[0]); + return h ? W(d[0], b, e) : new X(d[0]); } } } - d = ib(d, this.resolution, b, e, h); - return g ? d : new X(d); + d = ib(d, this.resolution, b, e, g); + return h ? d : new X(d); }; -function kb(a, b, c, d, e, g, f) { - a = Y(this, a, b, c, d, e, g, f); - return this.db ? a.then(function(h) { - return e ? h : h && h.length ? e ? W(h, c, d) : new X(h) : e ? [] : new X([]); +function kb(a, b, c, d, e, h, f) { + a = Y(this, a, b, c, d, e, h, f); + return this.db ? a.then(function(g) { + return e ? g : g && g.length ? e ? W(g, c, d) : new X(g) : e ? [] : new X([]); }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); } -function lb(a, b, c, d, e, g, f) { - var h = []; +function lb(a, b, c, d) { + var e = []; if (a) { d = Math.min(a.length, d); - for (var k = 0, l = 0, m; k < d; k++) { - if (m = a[k]) { - if (g && m && f && (m.length <= g ? (g -= m.length, m = null) : (m = m.slice(g), g = 0)), m && (h[k] = m, f && (l += m.length, l >= e))) { - break; - } - } + for (var h = 0, f = void 0; h < d; h++) { + (f = a[h]) && f && (e[h] = f); } - if (h.length) { - if (f) { - return W(h, e, 0); - } - b.push(h); + if (e.length) { + b.push(e); return; } } - return !c && h; + return !c && e; } -function Y(a, b, c, d, e, g, f, h) { +function Y(a, b, c, d, e, h, f, g) { var k; c && (k = a.bidirectional && b > c); if (a.db) { - return c ? a.db.get(k ? c : b, k ? b : c, d, e, g, f, h) : a.db.get(b, "", d, e, g, f, h); + return c ? a.db.get(k ? c : b, k ? b : c, d, e, h, f, g) : a.db.get(b, "", d, e, h, f, g); } a = c ? (a = a.ctx.get(k ? b : c)) && a.get(k ? c : b) : a.map.get(b); return a; @@ -2108,8 +2101,8 @@ function Y(a, b, c, d, e, g, f, h) { if (2 > e.length) { e.pop(); } else { - var g = e.indexOf(a); - g === c.length - 1 ? e.pop() : e.splice(g, 1); + var h = e.indexOf(a); + h === c.length - 1 ? e.pop() : e.splice(h, 1); } } } @@ -2118,17 +2111,17 @@ function Y(a, b, c, d, e, g, f, h) { } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.ea && bb(this)); + this.db && (this.commit_task.push({del:a}), this.da && bb(this)); this.cache && this.cache.remove(a); return this; }; function mb(a, b) { var c = 0; if (a.constructor === Array) { - for (var d = 0, e = void 0, g; d < a.length; d++) { + for (var d = 0, e = void 0, h; d < a.length; d++) { if ((e = a[d]) && e.length) { - if (g = e.indexOf(b), 0 <= g) { - 1 < e.length ? (e.splice(g, 1), c++) : delete a[d]; + if (h = e.indexOf(b), 0 <= h) { + 1 < e.length ? (e.splice(h, 1), c++) : delete a[d]; break; } else { c++; @@ -2137,7 +2130,7 @@ function mb(a, b) { } } else { for (d = x(a), e = d.next(); !e.done; e = d.next()) { - g = e.value, e = g[0], (g = mb(g[1], b)) ? c += g : a.delete(e); + h = e.value, e = h[0], (h = mb(h[1], b)) ? c += h : a.delete(e); } } return c; @@ -2153,7 +2146,7 @@ function mb(a, b) { a = {}; } c = a.context || {}; - var d = a.encode || a.encoder || Ha; + var d = M(a.encoder) ? Pa[a.encoder] : a.encode || a.encoder || Ha; this.encoder = d.encode ? d : "object" === typeof d ? new Q(d) : {encode:d}; var e; this.resolution = a.resolution || 9; @@ -2166,14 +2159,14 @@ function mb(a, b) { this.map = e ? new T(e) : new Map(); this.ctx = e ? new T(e) : new Map(); this.reg = b || (this.fastupdate ? e ? new T(e) : new Map() : e ? new U(e) : new Set()); - this.ba = c.resolution || 1; + this.aa = c.resolution || 1; this.rtl = d.rtl || a.rtl || !1; this.cache = (e = a.cache || null) && new R(e); this.resolve = !1 !== a.resolve; if (e = a.db) { - this.db = e.mount(this); + this.db = this.mount(e); } - this.ea = !1 !== a.commit; + this.da = !1 !== a.commit; this.commit_task = []; this.commit_timer = null; } @@ -2240,14 +2233,14 @@ u.cleanup = function() { return this; }; u.searchCache = Ga; -u.export = function(a, b, c, d, e, g) { +u.export = function(a, b, c, d, e, h) { var f = !0; - "undefined" === typeof g && (f = new Promise(function(n) { - g = n; + "undefined" === typeof h && (f = new Promise(function(n) { + h = n; })); switch(e || (e = 0)) { case 0: - var h = "reg"; + var g = "reg"; if (this.fastupdate) { var k = L(); for (var l = x(this.reg.keys()), m = l.next(); !m.done; m = l.next()) { @@ -2258,22 +2251,22 @@ u.export = function(a, b, c, d, e, g) { } break; case 1: - h = "cfg"; + g = "cfg"; k = {doc:0, opt:this.h ? 1 : 0}; break; case 2: - h = "map"; + g = "map"; k = this.map; break; case 3: - h = "ctx"; + g = "ctx"; k = this.ctx; break; default: - "undefined" === typeof c && g && g(); + "undefined" === typeof c && h && h(); return; } - Wa(a, b || this, c, h, d, e, k, g); + Wa(a, b || this, c, g, d, e, k, h); return f; }; u.import = function(a, b) { @@ -2305,26 +2298,26 @@ u.serialize = function(a) { b = "index.reg=new Set([" + b + "]);"; d = ""; e = x(this.map.entries()); - for (var g = e.next(); !g.done; g = e.next()) { - var f = g.value; - g = f[0]; + for (var h = e.next(); !h.done; h = e.next()) { + var f = h.value; + h = f[0]; f = f[1]; - for (var h = "", k = 0, l; k < f.length; k++) { + for (var g = "", k = 0, l; k < f.length; k++) { l = f[k] || [""]; for (var m = "", n = 0; n < l.length; n++) { m += (m ? "," : "") + ("string" === c ? '"' + l[n] + '"' : l[n]); } m = "[" + m + "]"; - h += (h ? "," : "") + m; + g += (g ? "," : "") + m; } - h = '["' + g + '",[' + h + "]]"; - d += (d ? "," : "") + h; + g = '["' + h + '",[' + g + "]]"; + d += (d ? "," : "") + g; } d = "index.map=new Map([" + d + "]);"; e = ""; - g = x(this.ctx.entries()); - for (f = g.next(); !f.done; f = g.next()) { - for (h = f.value, f = h[0], h = x(h[1].entries()), k = h.next(); !k.done; k = h.next()) { + h = x(this.ctx.entries()); + for (f = h.next(); !f.done; f = h.next()) { + for (g = f.value, f = g[0], g = x(g[1].entries()), k = g.next(); !k.done; k = g.next()) { l = k.value; k = l[0]; l = l[1]; @@ -2348,7 +2341,7 @@ u.serialize = function(a) { }; Ya(V.prototype); function ob(a) { - var b, c, d, e, g, f, h, k; + var b, c, d, e, h, f, g, k; return H(function(l) { a = a.data; b = self._index; @@ -2357,54 +2350,51 @@ function ob(a) { switch(d) { case "init": e = a.options || {}; - (g = e.config) && (e = g); + (h = e.config) && (e = h); (f = a.factory) ? (Function("return " + f)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new V(e); postMessage({id:a.id}); break; default: - h = a.id, k = b[d].apply(b, c), postMessage("search" === d ? {id:h, msg:k} : {id:h}); + g = a.id, k = b[d].apply(b, c), postMessage("search" === d ? {id:g, msg:k} : {id:g}); } l.h = 0; }); } ;var pb = 0; function qb(a) { + function b(h) { + function f(g) { + g = g.data || g; + var k = g.id, l = k && e.h[k]; + l && (l(g.msg), delete e.h[k]); + } + this.worker = h || rb(c, d, a.worker); + if (this.worker.then) { + return this.worker.then(b); + } + this.h = L(); + if (this.worker) { + d ? this.worker.on("message", f) : this.worker.onmessage = f; + if (a.config) { + return new Promise(function(g) { + e.h[++pb] = function() { + g(e); + }; + e.worker.postMessage({id:pb, task:"init", factory:c, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:c, options:a}); + return this.worker; + } + } + a = void 0 === a ? {} : a; if (!this) { return new qb(a); } - a || (a = {}); - var b = "undefined" !== typeof self && (self || window)._factory; - b && (b = b.toString()); - var c = "undefined" === typeof window, d = this; - (function() { - function e(f) { - f = f.data || f; - var h = f.id, k = h && d.$[h]; - k && (k(f.msg), delete d.$[h]); - } - var g = this; - return H(function(f) { - if (1 == f.h) { - return F(f, rb(b, c, a.worker), 2); - } - g.worker = f.D; - g.$ = L(); - if (!g.worker) { - return f.return(); - } - c ? g.worker.on("message", e) : g.worker.onmessage = e; - if (a.config) { - return delete a.db, f.return(new Promise(function(h) { - d.$[++pb] = function() { - h(d); - }; - d.worker.postMessage({id:pb, task:"init", factory:b, options:a}); - })); - } - g.worker.postMessage({task:"init", factory:b, options:a}); - f.h = 0; - }); - }).call(this); + var c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + c && (c = c.toString()); + var d = "undefined" === typeof window, e = this; + this.worker = b.call(this); } sb("add"); sb("append"); @@ -2413,24 +2403,22 @@ sb("update"); sb("remove"); function sb(a) { qb.prototype[a] = qb.prototype[a + "Async"] = function() { - var b = this, c = [].slice.call(arguments), d = c[c.length - 1]; - if ("function" === typeof d) { - var e = d; - c.splice(c.length - 1, 1); - } - d = new Promise(function(g) { - b.$[++pb] = g; - b.worker.postMessage({task:a, id:pb, args:c}); + var b = this, c = arguments, d, e, h, f, g; + return H(function(k) { + d = b; + e = [].slice.call(c); + h = e[e.length - 1]; + "function" === typeof h && (f = h, e.splice(e.length - 1, 1)); + g = new Promise(function(l) { + d.h[++pb] = l; + d.worker.postMessage({task:a, id:pb, args:e}); + }); + return f ? (g.then(f), k.return(b)) : k.return(g); }); - return e ? (d.then(e), this) : d; }; } function rb(a, b, c) { - var d; - return H(function(e) { - d = b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : new ((await import("worker_threads"))["Worker"])((1,eval)("import.meta.dirname") + "/node/node.mjs") : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ob.toString()], {type:"text/javascript"}))) : new window.Worker(M(c) ? c : "worker/worker.js", {type:"module"}); - return e.return(d); - }); + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ob.toString()], {type:"text/javascript"}))) : new window.Worker(M(c) ? c : "worker/worker.js", {type:"module"}); } ;Z.prototype.add = function(a, b, c) { N(a) && (b = a, a = xa(b, this.key)); @@ -2440,21 +2428,21 @@ function rb(a, b, c) { } for (var d = 0, e; d < this.field.length; d++) { e = this.M[d]; - var g = this.index.get(this.field[d]); + var h = this.index.get(this.field[d]); if ("function" === typeof e) { - (e = e(b)) && g.add(a, e, !1, !0); + (e = e(b)) && h.add(a, e, !1, !0); } else { var f = e.R; if (!f || f(b)) { - e.constructor === String ? e = ["" + e] : M(e) && (e = [e]), tb(b, e, this.T, 0, g, a, e[0], c); + e.constructor === String ? e = ["" + e] : M(e) && (e = [e]), tb(b, e, this.T, 0, h, a, e[0], c); } } } 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 g = this.$[d]; + h = this.tag.get(g); e = L(); if ("function" === typeof f) { if (f = f(b), !f) { @@ -2468,13 +2456,13 @@ function rb(a, b, c) { f.constructor === String && (f = "" + f); f = xa(b, f); } - if (g && f) { - for (M(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { - var l = f[h]; + if (h && f) { + for (M(f) && (f = [f]), g = 0, k = void 0; g < f.length; g++) { + var l = f[g]; if (!e[l]) { e[l] = 1; var m; - (m = g.get(l)) ? k = m : g.set(l, k = []); + (m = h.get(l)) ? k = m : h.set(l, k = []); if (!c || !k.includes(a)) { if (k.length === Math.pow(2, 31) - 1) { m = new S(k); @@ -2483,7 +2471,7 @@ function rb(a, b, c) { p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); } } - g.set(l, k = m); + h.set(l, k = m); } k.push(a); this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); @@ -2491,7 +2479,7 @@ function rb(a, b, c) { } } } else { - g || console.warn("Tag '" + h + "' was not found"); + h || console.warn("Tag '" + g + "' was not found"); } } } @@ -2499,19 +2487,19 @@ function rb(a, b, c) { if (this.H) { var q = L(); for (c = 0; c < this.H.length; c++) { - if (d = this.H[c], g = d.R, !g || g(b)) { - g = void 0; + if (d = this.H[c], h = d.R, !h || h(b)) { + h = void 0; if ("function" === typeof d) { - g = d(b); - if (!g) { + h = d(b); + if (!h) { continue; } - d = [d.ma]; + d = [d.la]; } else if (M(d) || d.constructor === String) { q[d] = b[d]; continue; } - ub(b, q, d, 0, d[0], g); + ub(b, q, d, 0, d[0], h); } } } @@ -2520,10 +2508,10 @@ function rb(a, b, c) { } return this; }; -function ub(a, b, c, d, e, g) { +function ub(a, b, c, d, e, h) { a = a[e]; if (d === c.length - 1) { - b[e] = g || a; + b[e] = h || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { @@ -2534,41 +2522,41 @@ function ub(a, b, c, d, e, g) { } } } -function tb(a, b, c, d, e, g, f, h) { +function tb(a, b, c, d, e, h, f, g) { if (a = a[f]) { if (d === b.length - 1) { if (a.constructor === Array) { if (c[d]) { for (b = 0; b < a.length; b++) { - e.add(g, a[b], !0, !0); + e.add(h, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(g, a, h, !0); + e.add(h, a, g, !0); } else { if (a.constructor === Array) { for (f = 0; f < a.length; f++) { - tb(a, b, c, d, e, g, f, h); + tb(a, b, c, d, e, h, f, g); } } else { - f = b[++d], tb(a, b, c, d, e, g, f, h); + f = b[++d], tb(a, b, c, d, e, h, f, g); } } } else { - e.db && e.remove(g); + e.db && e.remove(h); } } ;Z.prototype.search = function(a, b, c, d) { c || (!b && N(a) ? (c = a, a = "") : N(b) && (c = b, b = 0)); - var e = [], g = [], f = 0; + var e = [], h = [], f = 0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; - var h = c.pluck; + var g = c.pluck; var k = c.merge; - var l = h || c.field || c.index; + var l = g || c.field || c.index; var m = this.tag && c.tag; var n = this.store && c.enrich; var p = c.suggest; @@ -2610,24 +2598,24 @@ function tb(a, b, c, d, e, g, f, h) { } m = r; if (!a) { - g = []; + h = []; if (r.length) { - for (h = 0; h < r.length; h += 2) { + for (g = 0; g < r.length; g += 2) { p = void 0; if (this.db) { - p = this.index.get(r[h]); + p = this.index.get(r[g]); if (!p) { - console.warn("Tag '" + r[h] + ":" + r[h + 1] + "' will be skipped because there is no field '" + r[h] + "'."); + console.warn("Tag '" + r[g] + ":" + r[g + 1] + "' will be skipped because there is no field '" + r[g] + "'."); continue; } - g.push(p = p.db.tag(r[h + 1], b, q, n)); + h.push(p = p.db.tag(r[g + 1], b, q, n)); } else { - p = vb.call(this, r[h], r[h + 1], b, q, n); + p = vb.call(this, r[g], r[g + 1], b, q, n); } - e.push({field:r[h], tag:r[h + 1], result:p}); + e.push({field:r[g], tag:r[g + 1], result:p}); } } - return g.length ? Promise.all(g).then(function(O) { + return h.length ? Promise.all(h).then(function(O) { for (var P = 0; P < O.length; P++) { e[P].result = O[P]; } @@ -2708,7 +2696,7 @@ function tb(a, b, c, d, e, g, f, h) { } } if (w) { - g[f] = v, e.push(t), f++; + h[f] = v, e.push(t), f++; } else if (1 === l.length) { return e; } @@ -2717,15 +2705,15 @@ function tb(a, b, c, d, e, g, f, h) { if (r) { if (this.db && m && m.length && !E) { for (n = 0; n < m.length; n += 2) { - g = this.index.get(m[n]); - if (!g) { + h = this.index.get(m[n]); + if (!h) { if (console.warn("Tag '" + m[n] + ":" + m[n + 1] + "' was not found because there is no field '" + m[n] + "'."), p) { continue; } else { return e; } } - r.push(g.db.tag(m[n + 1], b, q, !1)); + r.push(h.db.tag(m[n + 1], b, q, !1)); } } var Ib = this; @@ -2736,18 +2724,18 @@ function tb(a, b, c, d, e, g, f, h) { if (!f) { return e; } - if (h && (!n || !this.store)) { + if (g && (!n || !this.store)) { return e[0]; } r = []; q = 0; - for (p = void 0; q < g.length; q++) { + for (p = void 0; q < h.length; q++) { p = e[q]; n && p.length && !p[0].doc && (this.db ? r.push(p = this.index.get(this.field[0]).db.enrich(p)) : p.length && (p = wb.call(this, p))); - if (h) { + if (g) { return p; } - e[q] = {field:g[q], result:p}; + e[q] = {field:h[q], result:p}; } return n && this.db && r.length ? Promise.all(r).then(function(O) { for (var P = 0; P < O.length; P++) { @@ -2757,17 +2745,17 @@ function tb(a, b, c, d, e, g, f, h) { }) : k ? xb(e, b) : e; }; function xb(a, b) { - for (var c = [], d = L(), e = 0, g, f; e < a.length; e++) { - g = a[e]; - f = g.result; - for (var h = 0, k, l, m; h < f.length; h++) { - if (l = f[h], k = l.id, m = d[k]) { - m.push(g.field); + for (var c = [], d = L(), e = 0, h, f; e < a.length; e++) { + h = a[e]; + f = h.result; + for (var g = 0, k, l, m; g < f.length; g++) { + if (l = f[g], k = l.id, m = d[k]) { + m.push(h.field); } else { if (c.length === b) { return c; } - l.field = d[k] = [g.field]; + l.field = d[k] = [h.field]; c.push(l); } } @@ -2775,16 +2763,16 @@ function xb(a, b) { return c; } function vb(a, b, c, d, e) { - var g = this.tag.get(a); - if (!g) { + var h = this.tag.get(a); + if (!h) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (g = g && g.get(b)) && g.length - d) && 0 < a) { + if ((a = (h = h && h.get(b)) && h.length - d) && 0 < a) { if (a > c || d) { - g = g.slice(d, d + c); + h = h.slice(d, d + c); } - e && (g = wb.call(this, g)); - return g; + e && (h = wb.call(this, h)); + return h; } } function wb(a) { @@ -2809,51 +2797,48 @@ function wb(a) { this.cache = (c = a.cache || null) && new R(c); a.cache = !1; this.worker = a.worker; - c = new Map(); - d = b.index || b.field || b; - M(d) && (d = [d]); - for (var e = 0, g, f = void 0; e < d.length; e++) { - g = d[e]; - M(g) || (f = g, g = g.field); - f = N(f) ? Object.assign({}, a, f) : a; - if (this.worker) { - var h = new qb(f); - c.set(g, h); - h.worker || (this.worker = !1); - } - this.worker || c.set(g, new V(f, this.reg)); - f.custom ? this.M[e] = f.custom : (this.M[e] = yb(g, this.T), f.filter && ("string" === typeof this.M[e] && (this.M[e] = new String(this.M[e])), this.M[e].R = f.filter)); - this.field[e] = g; - } - if (this.H) { - for (d = b.store, M(d) && (d = [d]), e = 0; e < d.length; e++) { - g = d[e], f = g.field || g, g.custom ? (this.H[e] = g.custom, g.custom.ma = f) : (this.H[e] = yb(f, this.T), g.filter && ("string" === typeof this.H[e] && (this.H[e] = new String(this.H[e])), this.H[e].R = g.filter)); - } - } - this.index = c; + this.index = zb.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { - for (this.tag = new Map(), this.L = [], this.aa = [], b = 0; b < c.length; b++) { + this.tag = new Map(); + this.L = []; + this.$ = []; + b = 0; + for (var e = d = void 0; b < c.length; b++) { d = c[b]; e = d.field || d; if (!e) { throw Error("The tag field from the document descriptor is undefined."); } d.custom ? this.L[b] = d.custom : (this.L[b] = yb(e, this.T), d.filter && ("string" === typeof this.L[b] && (this.L[b] = new String(this.L[b])), this.L[b].R = d.filter)); - this.aa[b] = e; + this.$[b] = e; this.tag.set(e, new Map()); } } } - a.db && this.mount(a.db); + if (this.worker) { + a = []; + c = x(this.index.values()); + for (b = c.next(); !b.done; b = c.next()) { + b = b.value, b.worker.then && a.push(b.worker); + } + if (a.length) { + var h = this; + return Promise.all(a).then(function() { + return h; + }); + } + } else { + a.db && this.mount(a.db); + } } u = Z.prototype; u.mount = function(a) { var b = this.field; if (this.tag) { - for (var c = 0, d; c < this.aa.length; c++) { - d = this.aa[c]; + for (var c = 0, d; c < this.$.length; c++) { + d = this.$[c]; var e; this.index.set(d, e = new V({}, this.reg)); b === this.field && (b = b.slice(0)); @@ -2864,31 +2849,31 @@ u.mount = function(a) { c = []; d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; e = 0; - for (var g; e < b.length; e++) { - d.field = g = b[e]; - g = this.index.get(g); + for (var h; e < b.length; e++) { + d.field = h = b[e]; + h = this.index.get(h); var f = new a.constructor(a.id, d); f.id = a.id; - c[e] = f.mount(g); - g.document = !0; - e ? g.bypass = !0 : g.store = this.store; + c[e] = f.mount(h); + h.document = !0; + e ? h.bypass = !0 : h.store = this.store; } this.db = !0; return Promise.all(c); }; u.commit = function(a, b) { - var c = this, d, e, g, f; - return H(function(h) { - if (1 == h.h) { + var c = this, d, e, h, f; + return H(function(g) { + if (1 == g.h) { d = []; e = x(c.index.values()); - for (g = e.next(); !g.done; g = e.next()) { - f = g.value, d.push(f.db.commit(f, a, b)); + for (h = e.next(); !h.done; h = e.next()) { + f = h.value, d.push(f.db.commit(f, a, b)); } - return F(h, Promise.all(d), 2); + return F(g, Promise.all(d), 2); } c.reg.clear(); - h.h = 0; + g.h = 0; }); }; u.destroy = function() { @@ -2897,6 +2882,28 @@ u.destroy = function() { } return Promise.all(a); }; +function zb(a, b) { + var c = new Map(), d = b.index || b.field || b; + M(d) && (d = [d]); + for (var e = 0, h, f = void 0; e < d.length; e++) { + h = d[e]; + M(h) || (f = h, h = h.field); + f = N(f) ? Object.assign({}, a, f) : a; + if (this.worker) { + var g = new qb(f); + g.worker ? c.set(h, g) : this.worker = !1; + } + this.worker || c.set(h, new V(f, this.reg)); + f.custom ? this.M[e] = f.custom : (this.M[e] = yb(h, this.T), f.filter && ("string" === typeof this.M[e] && (this.M[e] = new String(this.M[e])), this.M[e].R = f.filter)); + this.field[e] = h; + } + if (this.H) { + for (a = b.store, M(a) && (a = [a]), b = 0; b < a.length; b++) { + d = a[b], e = d.field || d, d.custom ? (this.H[b] = d.custom, d.custom.la = e) : (this.H[b] = yb(e, this.T), d.filter && ("string" === typeof this.H[b] && (this.H[b] = new String(this.H[b])), this.H[b].R = d.filter)); + } + } + return c; +} function yb(a, b) { for (var c = a.split(":"), d = 0, e = 0; e < c.length; e++) { a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); @@ -2920,11 +2927,11 @@ u.remove = function(a) { for (b = x(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c = c.value; for (var d = x(c), e = d.next(); !e.done; e = d.next()) { - var g = e.value; - e = g[0]; - g = g[1]; - var f = g.indexOf(a); - -1 < f && (1 < g.length ? g.splice(f, 1) : c.delete(e)); + var h = e.value; + e = h[0]; + h = h[1]; + var f = h.indexOf(a); + -1 < f && (1 < h.length ? h.splice(f, 1) : c.delete(e)); } } } @@ -2965,35 +2972,35 @@ u.set = function(a, b) { return this; }; u.searchCache = Ga; -u.export = function(a, b, c, d, e, g) { +u.export = function(a, b, c, d, e, h) { var f; - "undefined" === typeof g && (f = new Promise(function(k) { - g = k; + "undefined" === typeof h && (f = new Promise(function(k) { + h = k; })); e || (e = 0); d || (d = 0); if (d < this.field.length) { c = this.field[d]; - var h = this.index[c]; + var g = this.index[c]; b = this; - h.export(a, b, e ? c : "", d, e++, g) || (d++, b.export(a, b, c, d, 1, g)); + g.export(a, b, e ? c : "", d, e++, h) || (d++, b.export(a, b, c, d, 1, h)); } else { switch(e) { case 1: b = "tag"; - h = this.A; + g = this.A; c = null; break; case 2: b = "store"; - h = this.store; + g = this.store; c = null; break; default: - g(); + h(); return; } - Wa(a, this, c, b, d, e, h, g); + Wa(a, this, c, b, d, e, g, h); } return f; }; @@ -3020,11 +3027,11 @@ u.import = function(a, b) { } }; Ya(Z.prototype); -var zb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ab = ["map", "ctx", "tag", "reg", "cfg"]; -function Bb(a, b) { +var Ab = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Bb = ["map", "ctx", "tag", "reg", "cfg"]; +function Cb(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Bb(a, b); + return new Cb(a, b); } "object" === typeof a && (b = a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3034,7 +3041,7 @@ function Bb(a, b) { this.db = null; this.h = {}; } -u = Bb.prototype; +u = Cb.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -3046,11 +3053,11 @@ u.open = function() { var a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - var d = zb.open(a.id + (a.field ? ":" + a.field : ""), 1); + var d = Ab.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { var e = a.db = this.result; - Ab.forEach(function(g) { - e.objectStoreNames.contains(g) || e.createObjectStore(g); + Bb.forEach(function(h) { + e.objectStoreNames.contains(h) || e.createObjectStore(h); }); }; d.onblocked = function(e) { @@ -3075,32 +3082,33 @@ u.close = function() { this.db = null; }; u.destroy = function() { - return zb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Ab.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); }; u.clear = function() { - for (var a = this.db.transaction(Ab, "readwrite"), b = 0; b < Ab.length; b++) { - a.objectStore(Ab[b]).clear(); + for (var a = this.db.transaction(Bb, "readwrite"), b = 0; b < Bb.length; b++) { + a.objectStore(Bb[b]).clear(); } - return Cb(a); + return Db(a); }; -u.get = function(a, b, c, d, e, g) { +u.get = function(a, b, c, d, e, h) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; e = void 0 === e ? !0 : e; - g = void 0 === g ? !1 : g; + h = void 0 === h ? !1 : h; + console.log("!!!!!!!!!!!"); a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); var f = this; - return Cb(a).then(function(h) { + return Db(a).then(function(g) { var k = []; - if (!h || !h.length) { + if (!g || !g.length) { return k; } if (e) { - if (!c && !d && 1 === h.length) { - return h[0]; + if (!c && !d && 1 === g.length) { + return g[0]; } - for (var l = 0, m = void 0; l < h.length; l++) { - if ((m = h[l]) && m.length) { + for (var l = 0, m = void 0; l < g.length; l++) { + if ((m = g[l]) && m.length) { if (d >= m.length) { d -= m.length; } else { @@ -3114,9 +3122,9 @@ u.get = function(a, b, c, d, e, g) { } } } - return g ? f.enrich(k) : k; + return h ? f.enrich(k) : k; } - return h; + return g; }); }; u.tag = function(a, b, c, d) { @@ -3125,32 +3133,32 @@ u.tag = function(a, b, c, d) { d = void 0 === d ? !1 : d; a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); var e = this; - return Cb(a).then(function(g) { - if (!g || !g.length || c >= g.length) { + return Db(a).then(function(h) { + if (!h || !h.length || c >= h.length) { return []; } if (!b && !c) { - return g; + return h; } - g = g.slice(c, c + b); - return d ? e.enrich(g) : g; + h = h.slice(c, c + b); + return d ? e.enrich(h) : h; }); }; 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] = Cb(b.get(a[d])); + c[d] = Db(b.get(a[d])); } return Promise.all(c).then(function(e) { - for (var g = 0; g < e.length; g++) { - e[g] = {id:a[g], doc:e[g] ? JSON.parse(e[g]) : null}; + for (var h = 0; h < e.length; h++) { + e[h] = {id:a[h], doc:e[h] ? JSON.parse(e[h]) : null}; } return e; }); }; u.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Cb(a); + return Db(a); }; u.search = null; u.info = function() { @@ -3160,73 +3168,73 @@ u.transaction = function(a, b, c) { if (e) { return c.call(this, e); } - var g = this.db.transaction(a, b); - this.h[a + ":" + b] = e = g.objectStore(a); - return new Promise(function(f, h) { - g.onerror = function(k) { + var h = this.db.transaction(a, b); + this.h[a + ":" + b] = e = h.objectStore(a); + return new Promise(function(f, g) { + h.onerror = function(k) { d.h[a + ":" + b] = null; - g.abort(); - g = e = null; - h(k); + h.abort(); + h = e = null; + g(k); }; - g.oncomplete = function(k) { - g = e = d.h[a + ":" + b] = null; + h.oncomplete = function(k) { + h = e = d.h[a + ":" + b] = null; f(k || !0); }; return c.call(d, e); }); }; u.commit = function(a, b, c) { - var d = this, e, g, f; - return H(function(h) { - switch(h.h) { + var d = this, e, h, f; + return H(function(g) { + switch(g.h) { case 1: if (b) { - return F(h, d.clear(), 12); + return F(g, d.clear(), 12); } e = a.commit_task; a.commit_task = []; - g = 0; + h = 0; f = void 0; case 4: - if (!(g < e.length)) { - h.h = 6; + if (!(h < e.length)) { + g.h = 6; break; } - f = e[g]; + f = e[h]; if (!f.clear) { - e[g] = f.pa; - h.h = 5; + e[h] = f.oa; + g.h = 5; break; } - return F(h, d.clear(), 8); + return F(g, d.clear(), 8); case 8: b = !0; - h.h = 6; + g.h = 6; break; case 5: - g++; - h.h = 4; + h++; + g.h = 4; break; case 6: if (b) { - h.h = 3; + g.h = 3; break; } c || (e = e.concat(wa(a.reg))); if (!e.length) { - h.h = 10; + g.h = 10; break; } - return F(h, d.remove(e), 11); + return F(g, d.remove(e), 11); case 11: case 10: - h.h = 3; + g.h = 3; break; case 12: a.commit_task = []; case 3: - return a.reg.size ? F(h, d.transaction("map", "readwrite", function(k) { + return a.reg.size ? F(g, d.transaction("map", "readwrite", function(k) { for (var l = x(a.map), m = l.next(), n = {}; !m.done; n = {O:void 0, Y:void 0}, m = l.next()) { m = m.value, n.Y = m[0], n.O = m[1], n.O.length && (b ? k.put(n.O, n.Y) : k.get(n.Y).onsuccess = function(p) { return function() { @@ -3251,9 +3259,9 @@ u.commit = function(a, b, c) { }; }(n)); } - }), 13) : h.return(); + }), 13) : g.return(); case 13: - return F(h, d.transaction("ctx", "readwrite", function(k) { + return F(g, d.transaction("ctx", "readwrite", function(k) { for (var l = x(a.ctx), m = l.next(), n = {}; !m.done; n = {W:void 0}, m = l.next()) { m = m.value; n.W = m[0]; @@ -3286,7 +3294,7 @@ u.commit = function(a, b, c) { }), 14); case 14: if (a.store) { - return F(h, d.transaction("reg", "readwrite", function(k) { + return F(g, d.transaction("reg", "readwrite", function(k) { for (var l = x(a.store), m = l.next(); !m.done; m = l.next()) { var n = m.value; m = n[0]; @@ -3296,44 +3304,44 @@ u.commit = function(a, b, c) { }), 16); } if (a.bypass) { - h.h = 16; + g.h = 16; break; } - return F(h, d.transaction("reg", "readwrite", function(k) { + return F(g, d.transaction("reg", "readwrite", function(k) { for (var l = x(a.reg.keys()), m = l.next(); !m.done; m = l.next()) { k.put(1, m.value); } }), 16); case 16: if (!a.tag) { - h.h = 20; + g.h = 20; break; } - return F(h, d.transaction("tag", "readwrite", function(k) { - for (var l = x(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ca:void 0}, m = l.next()) { - m = m.value, n.ca = m[0], n.X = m[1], n.X.length && (k.get(n.ca).onsuccess = function(p) { + return F(g, d.transaction("tag", "readwrite", function(k) { + for (var l = x(a.tag), m = l.next(), n = {}; !m.done; n = {X:void 0, ba:void 0}, m = l.next()) { + m = m.value, n.ba = m[0], n.X = m[1], n.X.length && (k.get(n.ba).onsuccess = function(p) { return function() { var q = this.result; q = q && q.length ? q.concat(p.X) : p.X; - k.put(q, p.ca); + k.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(), g.h = 0; } }); }; -function Db(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 Eb(a, b, c) { + for (var d = a.value, e, h, f = 0, g = 0, k; g < d.length; g++) { + if (k = c ? d : d[g]) { for (var l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = k.indexOf(g ? parseInt(n, 10) : n), 0 > m && !g && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (g = 1), 0 <= m) { + if (n = b[l], m = k.indexOf(h ? parseInt(n, 10) : n), 0 > m && !h && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (h = 1), 0 <= m) { if (e = 1, 1 < k.length) { k.splice(m, 1); } else { - d[h] = []; + d[g] = []; break; } } @@ -3352,17 +3360,17 @@ u.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Db(c, a); + c && Eb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Db(c, a); + c && Eb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Db(c, a, !0); + c && Eb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3370,7 +3378,7 @@ u.remove = function(a) { } })]); }; -function Cb(a) { +function Db(a) { return new Promise(function(b, c) { a.onsuccess = function() { b(this.result); @@ -3382,8 +3390,8 @@ function Cb(a) { a = null; }); } -;var Eb = {Index:V, Charset:Pa, Encoder:Q, Document:Z, Worker:qb, Resolver:X, IndexedDB:Bb, Language:{}}, Fb = self, Gb; -(Gb = Fb.define) && Gb.amd ? Gb([], function() { - return Eb; -}) : "object" === typeof Fb.exports ? Fb.exports = Eb : Fb.FlexSearch = Eb; +;var Fb = {Index:V, Charset:Pa, Encoder:Q, Document:Z, Worker:qb, Resolver:X, IndexedDB:Cb, Language:{}}, Gb = self, Jb; +(Jb = Gb.define) && Jb.amd ? Jb([], function() { + return Fb; +}) : "object" === typeof Gb.exports ? Gb.exports = Fb : Gb.FlexSearch = Fb; }(this)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 883e3b8..2033634 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -7,119 +7,120 @@ */ (function(self){'use strict';var u;function aa(a){var b=0;return function(){return b>>0)+"_",e=0;return b}); +function ra(a){function b(d){return a.next(d)}function c(d){return a.throw(d)}return new Promise(function(d,e){function h(f){f.done?d(f.value):Promise.resolve(f.value).then(b,c).then(h,e)}h(a.next())})}function H(a){return ra(new pa(new ma(a)))} +B("Symbol",function(a){function b(h){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new c(d+(h||"")+"_"+e++,h)}function c(h,f){this.h=h;ba(this,"description",{configurable:!0,writable:!0,value:f})}if(a)return a;c.prototype.toString=function(){return this.h};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",e=0;return b}); B("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;cc&&(c=Math.max(c+e,0));cc&&(c=Math.max(c+e,0));cthis.J&&(this.S.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.h&&(this.N.set(a,d),this.N.size>this.J&&(this.N.clear(),this.h=this.h/1.1|0));return d};function Fa(a){a.U=null;a.N.clear();a.S.clear()};function Ga(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();var d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){var e=this;d.then(function(g){e.cache.set(a,g);return g})}this.cache.set(a,d)}return d}function R(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}R.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; -R.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};R.prototype.remove=function(a){for(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)}};R.prototype.clear=function(){this.cache.clear();this.h=""};var Ha={normalize:function(a){return a.toLowerCase()},dedupe:!1};var Ia=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 Ja=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Ka=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var La={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 Ma=/[\x00-\x7F]+/g;var Na=/[\x00-\x7F]+/g;var Oa=/[\x00-\x7F]+/g;var Pa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ha,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ia},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka,matcher:Ja},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka.concat([/(?!^)[aeoy]/g,""]),matcher:Ja},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;b=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} -function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fthis.J&&(this.S.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.h&&(this.N.set(a,d),this.N.size>this.J&&(this.N.clear(),this.h=this.h/1.1|0));return d};function Fa(a){a.U=null;a.N.clear();a.S.clear()};function Ga(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();var d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){var e=this;d.then(function(h){e.cache.set(a,h);return h})}this.cache.set(a,d)}return d}function R(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}R.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; +R.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};R.prototype.remove=function(a){for(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)}};R.prototype.clear=function(){this.cache.clear();this.h=""};var Ha={normalize:function(a){return a.toLowerCase()},dedupe:!1};var Ia=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 Ja=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Ka=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var La={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 Ma=/[\x00-\x7F]+/g;var Na=/[\x00-\x7F]+/g;var Oa=/[\x00-\x7F]+/g;var Pa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ha,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ia},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka,matcher:Ja},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka.concat([/(?!^)[aeoy]/g,""]),matcher:Ja},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;b=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} +function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var h=0,f=0,g,k;fn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):$a(h,d,k,m,n);ab(this,g,p,r,a,c)}break}case "reverse":if(1< -m){for(q=m-1;0p?0:1),d,k,q-1,r-1),v=this.bidirectional&&l>n;ab(this,e,v?n:l,y,a,c,v?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.ea&&bb(this));return this}; -function ab(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]=L()),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 $a(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?cb(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=f.length),e.push(f);else{if(h>=b)return h>b&&(f=f.slice(0,b)),d?cb(f):f;e=[f]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length)return e?W(a[0],b,c,d):a[0];d=[];for(var f=0,h=L(),k=ya(a),l=0,m;la.length)return[];var g=[],f=0,h=L(),k=ya(a);if(!k)return g;for(var l=0,m;la.length)return e?W(a[0],b,c,d):a[0];b=[];c=L();d=0;for(var f;dc||d)f=f.slice(d,c+d)}return f} -function jb(a,b){for(var c=L(),d=[],e=0,g;e=e)))break;if(h.length){if(f)return W(h,e,0);b.push(h);return}}return!c&&h}function Y(a,b,c,d,e,g,f,h){var k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,g,f,h):a.db.get(b,"",d,e,g,f,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};V.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 mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ea&&bb(this));this.cache&&this.cache.remove(a);return this}; -function mb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;dn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):$a(g,d,k,m,n);ab(this,h,p,r,a,c)}break}case "reverse":if(1< +m){for(q=m-1;0p?0:1),d,k,q-1,r-1),v=this.bidirectional&&l>n;ab(this,e,v?n:l,y,a,c,v?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.da&&bb(this));return this}; +function ab(a,b,c,d,e,h,f){var g=f?a.ctx:a.map,k;if(!b[c]||!f||!(k=b[c])[f])if(f?(b=k||(b[c]=L()),b[f]=1,(k=g.get(f))?g=k:g.set(f,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!h||!g.includes(e)){if(g.length===Math.pow(2,31)-1){b=new S(g);if(a.fastupdate)for(c=x(a.reg.values()),h=c.next();!h.done;h=c.next())h=h.value,h.includes(g)&&(h[h.indexOf(g)]=b);k[d]=g=b}g.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(g):a.reg.set(e,[g]))}} +function $a(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?cb(a):a;for(var e=[],h=0,f=void 0,g=void 0;h=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),d?cb(f):f;e=[f]}b-=g;if(!b)break}if(!e.length)return e;e=1a.length)return e?W(a[0],b,c,d):a[0];d=[];for(var f=0,g=L(),k=ya(a),l=0,m;la.length)return[];var h=[],f=0,g=L(),k=ya(a);if(!k)return h;for(var l=0,m;la.length)return e?W(a[0],b,c,d):a[0];b=[];c=L();d=0;for(var f;dc||d)f=f.slice(d,c+d)}return f} +function jb(a,b){for(var c=L(),d=[],e=0,h;ec);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,h,f,g):a.db.get(b,"",d,e,h,f,g);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};V.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var h=e.indexOf(a);h===c.length-1?e.pop():e.splice(h,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.da&&bb(this));this.cache&&this.cache.remove(a);return this}; +function mb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,h;dc||d)a=a.slice(d,d+c);e&&(a=wb.call(this,a));return a}}function wb(a){for(var b=Array(a.length),c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=wb.call(this,a));return a}}function wb(a){for(var b=Array(a.length),c=0,d;c=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=h.length)return[];if(!b&&!c)return h;h=h.slice(c,c+b);return d?e.enrich(h):h})}; +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&&!h&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(h=1),0<=m)if(e=1,1 g; h--) { - f = q.substring(g, h); - var k = this.score ? this.score(c, q, n, f, g) : I(r, d, n, e, g); - J(this, l, f, k, a, b); + f = p.substring(g, h); + var k = this.score ? this.score(c, p, l, f, g) : I(r, d, l, e, g); + J(this, q, f, k, a, b); } } break; @@ -241,24 +241,24 @@ H.prototype.add = function(a, c, b, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - f = q[h] + f, k = this.score ? this.score(c, q, n, f, h) : I(r, d, n, e, h), J(this, l, f, k, a, b); + f = p[h] + f, k = this.score ? this.score(c, p, l, f, h) : I(r, d, l, e, h), J(this, q, f, k, a, b); } f = ""; } case "forward": if (1 < e) { for (h = 0; h < e; h++) { - f += q[h], J(this, l, f, g, a, b); + f += p[h], J(this, q, f, g, a, b); } break; } default: - if (J(this, l, q, g, a, b), p && 1 < d && n < d - 1) { - for (e = u(), f = this.A, g = q, h = Math.min(p + 1, d - n), e[g] = 1, k = 1; k < h; k++) { - if ((q = c[this.rtl ? d - 1 - n - k : n + k]) && !e[q]) { - e[q] = 1; - const A = this.score ? this.score(c, g, n, q, k) : I(f + (d / 2 > f ? 0 : 1), d, n, h - 1, k - 1), M = this.bidirectional && q > g; - J(this, m, M ? g : q, A, a, b, M ? q : g); + if (J(this, q, p, g, a, b), n && 1 < d && l < d - 1) { + for (e = u(), f = this.A, g = p, h = Math.min(n + 1, d - l), e[g] = 1, k = 1; k < h; k++) { + if ((p = c[this.rtl ? d - 1 - l - k : l + k]) && !e[p]) { + e[p] = 1; + const A = this.score ? this.score(c, g, l, p, k) : I(f + (d / 2 > f ? 0 : 1), d, l, h - 1, k - 1), L = this.bidirectional && p > g; + J(this, m, L ? g : p, A, a, b, L ? p : g); } } } @@ -321,29 +321,29 @@ function I(a, c, b, d, e) { b = a.length; c || (c = 100); if (1 === b) { - return L.call(this, a[0], "", c, e); + return M.call(this, a[0], "", c, e); } g = this.depth && !1 !== g; if (2 === b && g && !f) { - return L.call(this, a[0], a[1], c, e); + return M.call(this, a[0], a[1], c, e); } var h = 0, k = 0; if (1 < b) { var m = u(); - const p = []; - for (let r = 0, n; r < b; r++) { - if ((n = a[r]) && !m[n]) { - if (f || N(this, n)) { - p.push(n), m[n] = 1; + const n = []; + for (let r = 0, l; r < b; r++) { + if ((l = a[r]) && !m[l]) { + if (f || N(this, l)) { + n.push(l), m[l] = 1; } else { return d; } - const q = n.length; - h = Math.max(h, q); - k = k ? Math.min(k, q) : q; + const p = l.length; + h = Math.max(h, p); + k = k ? Math.min(k, p) : p; } } - a = p; + a = n; b = a.length; } if (!b) { @@ -351,30 +351,30 @@ function I(a, c, b, d, e) { } m = 0; if (1 === b) { - return L.call(this, a[0], "", c, e); + return M.call(this, a[0], "", c, e); } if (2 === b && g && !f) { - return L.call(this, a[0], a[1], c, e); + return M.call(this, a[0], a[1], c, e); } if (1 < b) { if (g) { - var l = a[0]; + var q = a[0]; m = 1; } else { 9 < h && 3 < h / k && a.sort(v); } } - for (let p, r; m < b; m++) { + for (let n, r; m < b; m++) { r = a[m]; - l ? (p = N(this, r, l), p = O(p, d, f, this.A, c, e, 2 === b), f && !1 === p && d.length || (l = r)) : (p = N(this, r), p = O(p, d, f, this.resolution, c, e, 1 === b)); - if (p) { - return p; + q ? (n = N(this, r, q), n = O(n, d, f, this.A), f && !1 === n && d.length || (q = r)) : (n = N(this, r, ""), n = O(n, d, f, this.resolution)); + if (n) { + return n; } if (f && m === b - 1) { g = d.length; if (!g) { - if (l) { - l = ""; + if (q) { + q = ""; m = -1; continue; } @@ -388,14 +388,14 @@ function I(a, c, b, d, e) { a: { a = d; d = this.resolution; - l = a.length; + q = a.length; b = []; g = u(); - for (let p = 0, r, n, q, A; p < d; p++) { - for (k = 0; k < l; k++) { - if (q = a[k], p < q.length && (r = q[p])) { + for (let n = 0, r, l, p, A; n < d; n++) { + for (k = 0; k < q; k++) { + if (p = a[k], n < p.length && (r = p[n])) { for (m = 0; m < r.length; m++) { - n = r[m], (h = g[n]) ? g[n]++ : (h = 0, g[n] = 1), A = b[h] || (b[h] = []), A.push(n); + l = r[m], (h = g[l]) ? g[l]++ : (h = 0, g[l] = 1), A = b[h] || (b[h] = []), A.push(l); } } } @@ -408,8 +408,8 @@ function I(a, c, b, d, e) { d = u(); g = f.length; for (k = 0; k < g; k++) { - for (l = f[k], h = l.length, m = 0; m < h; m++) { - if (b = l[m], !d[b]) { + for (q = f[k], h = q.length, m = 0; m < h; m++) { + if (b = q[m], !d[b]) { if (d[b] = 1, e) { e--; } else { @@ -426,7 +426,7 @@ function I(a, c, b, d, e) { } b = c; } else { - if (a < l) { + if (a < q) { d = []; break a; } @@ -440,29 +440,22 @@ function I(a, c, b, d, e) { } return d; }; -function L(a, c, b, d) { +function M(a, c, b, d) { return (a = N(this, a, c)) && a.length ? K(a, b, d) : []; } -function O(a, c, b, d, e, g, f) { - let h = []; +function O(a, c, b, d) { + let e = []; if (a) { d = Math.min(a.length, d); - for (let k = 0, m = 0, l; k < d; k++) { - if (l = a[k]) { - if (g && l && f && (l.length <= g ? (g -= l.length, l = null) : (l = l.slice(g), g = 0)), l && (h[k] = l, f && (m += l.length, m >= e))) { - break; - } - } + for (let g = 0, f; g < d; g++) { + (f = a[g]) && f && (e[g] = f); } - if (h.length) { - if (f) { - return K(h, e, 0); - } - c.push(h); + if (e.length) { + c.push(e); return; } } - return !b && h; + return !b && e; } function N(a, c, b) { let d; diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index 942ce72..d215917 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -11,14 +11,14 @@ C.prototype.assign=function(a){this.normalize=t(a.normalize,!0,this.normalize);l this.maxlength=t(a.maxlength,0,this.maxlength);if(this.cache=b=t(a.cache,!0,this.cache))this.j=null,this.v="number"===typeof b?b:2E5,this.h=new Map,this.i=new Map,this.l=this.g=128;this.m="";this.s=null;this.o="";this.u=null;if(this.matcher)for(const d of this.matcher.keys())this.m+=(this.m?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.o+=(this.o?"|":"")+d;return this}; C.prototype.encode=function(a){if(this.cache&&a.length<=this.g)if(this.j){if(this.h.has(a))return this.h.get(a)}else this.j=setTimeout(D,0,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):B?a.normalize("NFKD").replace(B,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(m)),k=1);this.matcher&&1this.matcher.get(m)),k=1);f&&k&&(f.lengththis.matcher.get(m)),k=1);f&&k&&(f.lengththis.v&&(this.i.clear(),this.l=this.l/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.g&&(this.h.set(a,b),this.h.size>this.v&&(this.h.clear(),this.g=this.g/1.1|0));return b};function D(a){a.j=null;a.h.clear();a.i.clear()};function E(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.g=""}E.prototype.set=function(a,c){this.cache.set(this.g=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};E.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};E.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -E.prototype.clear=function(){this.cache.clear();this.g=""};const F={normalize:function(a){return a.toLowerCase()},dedupe:!1};const G={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};u();H.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const m=u(),l=u(),p=this.depth,r=this.resolution;for(let n=0;ng;h--){f=q.substring(g,h);var k=this.score?this.score(c,q,n,f,g):I(r,d,n,e,g);J(this,l,f,k,a,b)}break}case "reverse":if(1< -e){for(h=e-1;0f?0:1),d,n,h-1,k-1),L=this.bidirectional&&q>g;J(this,m,L?g:q,A,a,b,L?q:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function J(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;c[b]&&f&&(k=c[b])[f]||(f?(c=k||(c[b]=u()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function I(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d}; -function M(a,c,b,d){return(a=N(this,a,c))&&a.length?K(a,b,d):[]}function O(a,c,b,d,e,g,f){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,m=0,l;k=e)))break;if(h.length){if(f)return K(h,e,0);c.push(h);return}}return!b&&h}function N(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.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 d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +E.prototype.clear=function(){this.cache.clear();this.g=""};const F={normalize:function(a){return a.toLowerCase()},dedupe:!1};const G={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};u();H.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const m=u(),q=u(),n=this.depth,r=this.resolution;for(let l=0;lg;h--){f=p.substring(g,h);var k=this.score?this.score(c,p,l,f,g):I(r,d,l,e,g);J(this,q,f,k,a,b)}break}case "reverse":if(1< +e){for(h=e-1;0f?0:1),d,l,h-1,k-1),K=this.bidirectional&&p>g;J(this,m,K?g:p,A,a,b,K?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function J(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;c[b]&&f&&(k=c[b])[f]||(f?(c=k||(c[b]=u()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function I(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d}; +function M(a,c,b,d){return(a=N(this,a,c))&&a.length?L(a,b,d):[]}function O(a,c,b,d){let e=[];if(a){d=Math.min(a.length,d);for(let g=0,f;gb);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.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 d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; function Q(a){let c=0;if(a.constructor===Array)for(let b=0,d;b f; h--) { - g = n.substring(f, h); - var k = this.score ? this.score(c, n, l, g, f) : I(r, d, l, e, f); - K(this, m, g, k, a, b); + g = m.substring(f, h); + var k = this.score ? this.score(c, m, l, g, f) : I(r, d, l, e, f); + K(this, q, g, k, a, b); } } break; @@ -93,24 +93,24 @@ H.prototype.add = function(a, c, b, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - g = n[h] + g, k = this.score ? this.score(c, n, l, g, h) : I(r, d, l, e, h), K(this, m, g, k, a, b); + g = m[h] + g, k = this.score ? this.score(c, m, l, g, h) : I(r, d, l, e, h), K(this, q, g, k, a, b); } g = ""; } case "forward": if (1 < e) { for (h = 0; h < e; h++) { - g += n[h], K(this, m, g, f, a, b); + g += m[h], K(this, q, g, f, a, b); } break; } default: - if (K(this, m, n, f, a, b), q && 1 < d && l < d - 1) { - for (e = t(), g = this.A, f = n, h = Math.min(q + 1, d - l), e[f] = 1, k = 1; k < h; k++) { - if ((n = c[this.rtl ? d - 1 - l - k : l + k]) && !e[n]) { - e[n] = 1; - const y = this.score ? this.score(c, f, l, n, k) : I(g + (d / 2 > g ? 0 : 1), d, l, h - 1, k - 1), J = this.bidirectional && n > f; - K(this, p, J ? f : n, y, a, b, J ? n : f); + if (K(this, q, m, f, a, b), n && 1 < d && l < d - 1) { + for (e = t(), g = this.A, f = m, h = Math.min(n + 1, d - l), e[f] = 1, k = 1; k < h; k++) { + if ((m = c[this.rtl ? d - 1 - l - k : l + k]) && !e[m]) { + e[m] = 1; + const y = this.score ? this.score(c, f, l, m, k) : I(g + (d / 2 > g ? 0 : 1), d, l, h - 1, k - 1), J = this.bidirectional && m > f; + K(this, p, J ? f : m, y, a, b, J ? m : f); } } } @@ -167,7 +167,7 @@ function I(a, c, b, d, e) { c = b.limit || c; e = b.offset || 0; var f = b.context; - var g = !1; + var g = b.suggest; } a = this.encoder.encode(a); b = a.length; @@ -182,20 +182,20 @@ function I(a, c, b, d, e) { var h = 0, k = 0; if (1 < b) { var p = t(); - const q = []; + const n = []; for (let r = 0, l; r < b; r++) { if ((l = a[r]) && !p[l]) { if (g || N(this, l)) { - q.push(l), p[l] = 1; + n.push(l), p[l] = 1; } else { return d; } - const n = l.length; - h = Math.max(h, n); - k = k ? Math.min(k, n) : n; + const m = l.length; + h = Math.max(h, m); + k = k ? Math.min(k, m) : m; } } - a = q; + a = n; b = a.length; } if (!b) { @@ -210,23 +210,23 @@ function I(a, c, b, d, e) { } if (1 < b) { if (f) { - var m = a[0]; + var q = a[0]; p = 1; } else { 9 < h && 3 < h / k && a.sort(u); } } - for (let q, r; p < b; p++) { + for (let n, r; p < b; p++) { r = a[p]; - m ? (q = N(this, r, m), q = O(q, d, g, this.A, c, e, 2 === b), g && !1 === q && d.length || (m = r)) : (q = N(this, r), q = O(q, d, g, this.resolution, c, e, 1 === b)); - if (q) { - return q; + q ? (n = N(this, r, q), n = O(n, d, g, this.A), g && !1 === n && d.length || (q = r)) : (n = N(this, r, ""), n = O(n, d, g, this.resolution)); + if (n) { + return n; } if (g && p === b - 1) { f = d.length; if (!f) { - if (m) { - m = ""; + if (q) { + q = ""; p = -1; continue; } @@ -240,12 +240,12 @@ function I(a, c, b, d, e) { a: { a = d; d = this.resolution; - m = a.length; + q = a.length; b = []; f = t(); - for (let q = 0, r, l, n, y; q < d; q++) { - for (k = 0; k < m; k++) { - if (n = a[k], q < n.length && (r = n[q])) { + for (let n = 0, r, l, m, y; n < d; n++) { + for (k = 0; k < q; k++) { + if (m = a[k], n < m.length && (r = m[n])) { for (p = 0; p < r.length; p++) { l = r[p], (h = f[l]) ? f[l]++ : (h = 0, f[l] = 1), y = b[h] || (b[h] = []), y.push(l); } @@ -260,8 +260,8 @@ function I(a, c, b, d, e) { d = t(); f = g.length; for (k = 0; k < f; k++) { - for (m = g[k], h = m.length, p = 0; p < h; p++) { - if (b = m[p], !d[b]) { + for (q = g[k], h = q.length, p = 0; p < h; p++) { + if (b = q[p], !d[b]) { if (d[b] = 1, e) { e--; } else { @@ -278,7 +278,7 @@ function I(a, c, b, d, e) { } b = c; } else { - if (a < m) { + if (a < q) { d = []; break a; } @@ -295,26 +295,19 @@ function I(a, c, b, d, e) { function M(a, c, b, d) { return (a = N(this, a, c)) && a.length ? L(a, b, d) : []; } -function O(a, c, b, d, e, f, g) { - let h = []; +function O(a, c, b, d) { + let e = []; if (a) { d = Math.min(a.length, d); - for (let k = 0, p = 0, m; k < d; k++) { - if (m = a[k]) { - if (f && m && g && (m.length <= f ? (f -= m.length, m = null) : (m = m.slice(f), f = 0)), m && (h[k] = m, g && (p += m.length, p >= e))) { - break; - } - } + for (let f = 0, g; f < d; f++) { + (g = a[f]) && g && (e[f] = g); } - if (h.length) { - if (g) { - return L(h, e, 0); - } - c.push(h); + if (e.length) { + c.push(e); return; } } - return !b && h; + return !b && e; } function N(a, c, b) { let d; @@ -370,7 +363,7 @@ function P(a, c) { return new H(a); } a = a ? G(a) : {}; - const b = a.context || {}, d = a.encode || a.encoder || function(f) { + const b = a.context || {}, d = "string" === typeof a.encoder ? E[a.encoder] : a.encode || a.encoder || function(f) { return f.toLowerCase().trim().split(/\s+/); }; this.encoder = d.encode ? d : "object" === typeof d ? d : {encode:d}; diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index a81dbde..176432f 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -7,14 +7,14 @@ */ function t(){return Object.create(null)}function u(a,c){return c.length-a.length};function v(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}v.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};v.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};v.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; v.prototype.clear=function(){this.cache.clear();this.h=""};const w=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 x=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),z=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];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 B=/[\x00-\x7F]+/g;const C=/[\x00-\x7F]+/g;const D=/[\x00-\x7F]+/g;var E={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:{normalize:function(a){return a.toLowerCase()},dedupe:!1},LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:w},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:w,replacer:z,matcher:x},LatinExtra:{normalize:!0,dedupe:!0,mapper:w,replacer:z.concat([/(?!^)[aeoy]/g,""]),matcher:x},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=n.substring(f,h);var k=this.score?this.score(c,n,l,g,f):J(r,d,l,e,f);K(this,m,g,k,a,b)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,l,h-1,k-1),I=this.bidirectional&&n>f;K(this,p,I?f:n,y,a,b,I?n:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function K(a,c,b,d,e,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=t()),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[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function J(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,f,g;e=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),d.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;d=[f]}c-=g;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d}; -function M(a,c,b,d){return(a=N(this,a,c))&&a.length?L(a,b,d):[]}function O(a,c,b,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,p=0,m;k=e)))break;if(h.length){if(g)return L(h,e,0);c.push(h);return}}return!b&&h}function N(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===b.length-1?e.pop():e.splice(f,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,f;db.add(a,c)):this.add(a,c)}; +for(let f=1,g;ff;h--){g=m.substring(f,h);var k=this.score?this.score(c,m,l,g,f):J(r,d,l,e,f);K(this,q,g,k,a,b)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,l,h-1,k-1),I=this.bidirectional&&m>f;K(this,p,I?f:m,y,a,b,I?m:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function K(a,c,b,d,e,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=t()),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[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function J(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,f,g;e=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),d.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;d=[f]}c-=g;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d}; +function M(a,c,b,d){return(a=N(this,a,c))&&a.length?L(a,b,d):[]}function O(a,c,b,d){let e=[];if(a){d=Math.min(a.length,d);for(let f=0,g;fb);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.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 d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===b.length-1?e.pop():e.splice(f,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,f;db.add(a,c)):this.add(a,c)}; function Q(a){let c=0;if(a.constructor===Array)for(let b=0,d;b= limit) { - // fast path: - // a single term does not need to pre-collect results - break; - } - } + // if(single_term){ + // size += tmp.length; + // if(size >= limit){ + // // fast path: + // // a single term does not need to pre-collect results + // break; + // } + // } } } } if (word_arr.length) { - if (single_term) { - // fast path optimization - // offset was already applied at this point - // return an array will stop the query process immediately - return resolve_default(word_arr, limit, 0); - } + // if(single_term){ + // // fast path optimization + // // offset was already applied at this point + // // return an array will stop the query process immediately + // return resolve_default(word_arr, limit, 0); + // } result.push(word_arr); // return nothing will continue the query diff --git a/dist/module-debug/type.js b/dist/module-debug/type.js index 2e43ec3..24d1aa9 100644 --- a/dist/module-debug/type.js +++ b/dist/module-debug/type.js @@ -19,10 +19,11 @@ import StorageInterface from "./db/interface.js"; * resolve: [boolean=true], * db: StorageInterface|undefined, * commit: boolean=true, + * worker: boolean|string|undefined, * config: string|undefined * }} */ -export let IndexOptions; +export let IndexOptions = {}; /** * @typedef DocumentIndexOptions {{ @@ -40,13 +41,12 @@ export let IndexOptions; * db: StorageInterface|undefined, * commit: boolean=true, * config: string|undefined, - * * field: string, * filter: Function|undefined, * custom: Function|undefined * }} */ -export let DocumentIndexOptions; +export let DocumentIndexOptions = {}; /** * @typedef DocumentOptions {{ @@ -66,7 +66,7 @@ export let DocumentIndexOptions; * worker: boolean|string|undefined * }} */ -export let DocumentOptions; +export let DocumentOptions = {}; /** * @typedef ContextOptions {{ @@ -75,7 +75,7 @@ export let DocumentOptions; * resolution: number|undefined * }} */ -export let ContextOptions; +export let ContextOptions = {}; /** * @typedef DocumentDescriptor {{ @@ -86,7 +86,7 @@ export let ContextOptions; * store: StoreOptions|Array|undefined * }} */ -export let DocumentDescriptor; +export let DocumentDescriptor = {}; /** * @typedef TagOptions {{ @@ -99,7 +99,7 @@ export let DocumentDescriptor; * config: string|undefined * }} */ -export let TagOptions; +export let TagOptions = {}; /** * @typedef StoreOptions {{ @@ -109,7 +109,7 @@ export let TagOptions; * config: string|undefined * }} */ -export let StoreOptions; +export let StoreOptions = {}; /** * @typedef SearchOptions {{ @@ -122,7 +122,7 @@ export let StoreOptions; * enrich: [boolean=false], * }} */ -export let SearchOptions; +export let SearchOptions = {}; // tag: Array|undefined /** @@ -140,7 +140,7 @@ export let SearchOptions; * merge: [boolean=false] * }} */ -export let DocumentSearchOptions; +export let DocumentSearchOptions = {}; /** * @typedef EncoderOptions {{ @@ -161,7 +161,7 @@ export let DocumentSearchOptions; * cache: boolean=true, * }} */ -export let EncoderOptions; +export let EncoderOptions = {}; /** * @typedef EncoderSplitOptions {{ @@ -173,7 +173,7 @@ export let EncoderOptions; * char: string|Array|undefined, * }} */ -export let EncoderSplitOptions; +export let EncoderSplitOptions = {}; /** * @typedef PersistentOptions {{ @@ -183,4 +183,4 @@ export let EncoderSplitOptions; * db: *|undefined * }} */ -export let PersistentOptions; \ No newline at end of file +export let PersistentOptions = {}; \ No newline at end of file diff --git a/dist/module-debug/webpack.js b/dist/module-debug/webpack.js index 128e45a..e3f9974 100644 --- a/dist/module-debug/webpack.js +++ b/dist/module-debug/webpack.js @@ -44,6 +44,7 @@ import Charset from "./charset.js"; /** @export */Index.prototype.cache; /** @export */Index.prototype.bypass; /** @export */Index.prototype.document; +/** @export */Index.prototype.encoder; /** @export */Document.prototype.add; /** @export */Document.prototype.append; diff --git a/dist/module-debug/worker.js b/dist/module-debug/worker.js index 97189d3..4079eb6 100644 --- a/dist/module-debug/worker.js +++ b/dist/module-debug/worker.js @@ -1,4 +1,3 @@ -//import { promise as Promise } from "../polyfill.js"; import { IndexOptions } from "./type.js"; import { create_object, is_function, is_object, is_string } from "./common.js"; import handler from "./worker/handler.js"; @@ -10,20 +9,15 @@ let pid = 0; * @constructor */ -export default function WorkerIndex(options) { +export default function WorkerIndex(options = {}) { if (!this) { return new WorkerIndex(options); } - if (!options) { - options = {}; - } - // the factory is the outer wrapper from the build - // we use "self" as a trap for node.js - - let factory = "undefined" != typeof self && (self || window)._factory; + // it uses "self" as a trap for node.js + let factory = "undefined" != typeof self ? self._factory : "undefined" != typeof window ? window._factory : null; if (factory) { factory = factory.toString(); } @@ -31,9 +25,18 @@ export default function WorkerIndex(options) { const is_node_js = "undefined" == typeof window /*&& self["exports"]*/, _self = this; - (async function () { + /** + * @param {Worker=} _worker + * @this {WorkerIndex} + */ + function init(_worker) { + + this.worker = _worker || create(factory, is_node_js, options.worker); + + if (this.worker.then) { + return this.worker.then(init); + } - this.worker = await create(factory, is_node_js, options.worker); this.resolver = create_object(); if (!this.worker) { @@ -55,14 +58,16 @@ export default function WorkerIndex(options) { if (options.config) { - delete options.db; + //delete options.db; // when extern configuration needs to be loaded // it needs to return a promise to await for return new Promise(function (resolve) { + _self.resolver[++pid] = function () { resolve(_self); }; + _self.worker.postMessage({ id: pid, task: "init", @@ -77,7 +82,11 @@ export default function WorkerIndex(options) { factory: factory, options: options }); - }).call(this); + + return this.worker; + } + + this.worker = init.call(this); } register("add"); @@ -88,7 +97,7 @@ register("remove"); function register(key) { - WorkerIndex.prototype[key] = WorkerIndex.prototype[key + "Async"] = function () { + WorkerIndex.prototype[key] = WorkerIndex.prototype[key + "Async"] = async function () { const self = this, args = [].slice.call(arguments), arg = args[args.length - 1]; @@ -121,14 +130,16 @@ function register(key) { }; } -async function create(factory, is_node_js, worker_path) { +function create(factory, is_node_js, worker_path) { let worker = is_node_js ? // This eval will be removed when compiling, it isn't there in final build "undefined" != typeof module ? (0, eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') //: (0,eval)('new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/worker/node.mjs")') - : (0, eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")') + //: (0,eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")') + : (0, eval)('import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)(\"import.meta.dirname\") + "/node/node.mjs"); })') + //: import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/worker/node.mjs"); }) //eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') : factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker(is_string(worker_path) ? worker_path : "worker/worker.js", { type: "module" }); diff --git a/dist/module-debug/worker/handler.js b/dist/module-debug/worker/handler.js index 0ada932..f918d7d 100644 --- a/dist/module-debug/worker/handler.js +++ b/dist/module-debug/worker/handler.js @@ -3,59 +3,53 @@ import { IndexOptions } from "../type.js"; export default (async function (data) { - data = data.data; + data = data.data; - /** @type Index */ - const index = self._index, - args = data.args, - task = data.task; + /** @type Index */ + const index = self._index, + args = data.args, + task = data.task; - switch (task) { + switch (task) { - case "init": + case "init": - /** @type IndexOptions */ - let options = data.options || {}, - filepath = options.config; + /** @type IndexOptions */ + let options = data.options || {}, + filepath = options.config; - if (filepath) { - options = filepath; - // will be replaced after build with the line below because - // there is an issue with closure compiler dynamic import - //options = await import(filepath); - } - - // deprecated: - // const encode = options.encode; - // if(encode && (encode.indexOf("function") === 0)){ - // options.encode = Function("return " + encode)(); - // } - - const factory = data.factory; - - if (factory) { - - // export the FlexSearch global payload to "self" - Function("return " + factory)()(self); - - /** @type Index */ - self._index = new self.FlexSearch.Index(options); - - // destroy the exported payload - delete self.FlexSearch; - } else { - - self._index = new Index(options); - } - - postMessage({ id: data.id }); - break; - - default: - const id = data.id, - message = index[task].apply(index, args); - - postMessage("search" === task ? { id: id, msg: message } : { id: id }); + if (filepath) { + options = filepath; + // will be replaced after build with the line below because + // there is an issue with closure compiler dynamic import + //options = await import(filepath); } + + const factory = data.factory; + + if (factory) { + + // export the FlexSearch global payload to "self" + Function("return " + factory)()(self); + + /** @type Index */ + self._index = new self.FlexSearch.Index(options); + + // destroy the exported payload + delete self.FlexSearch; + } else { + + self._index = new Index(options); + } + + postMessage({ id: data.id }); + break; + + default: + const id = data.id, + message = index[task].apply(index, args); + + postMessage("search" === task ? { id: id, msg: message } : { id: id }); + } }); \ No newline at end of file diff --git a/dist/module-debug/worker/node.js b/dist/module-debug/worker/node.js index d11807a..48f0621 100644 --- a/dist/module-debug/worker/node.js +++ b/dist/module-debug/worker/node.js @@ -7,43 +7,35 @@ const { parentPort } = require("worker_threads"), let index; -parentPort.on("message", function (data) { +parentPort.on("message", async function (data) { - /** @type Index */ - const args = data.args, - task = data.task, - id = data.id; + /** @type Index */ + const args = data.args, + task = data.task, + id = data.id; - switch (task) { + switch (task) { - case "init": - let options = data.options || {}, - filepath = options.config; + case "init": + let options = data.options || {}, + filepath = options.config; + // load extern field configuration - // load extern field configuration - - // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){ - // // current working directory - // const dir = process.cwd(); - // filepath = join(dir, filepath); - // } - if (filepath) { - options = require(filepath); - } - - // deprecated: - // const encode = options["encode"]; - // if(encode && (encode.indexOf("function") === 0)){ - // options["encode"] = new Function("return " + encode)(); - // } - - index = new Index(options); - break; - - default: - - const message = index[task].apply(index, args); - parentPort.postMessage("search" === task ? { id: id, msg: message } : { id: id }); + if (filepath) { + options = Object.assign({}, options, require(filepath)); + delete options.worker; } + + index = new Index(options); + //index.db && await index.db; + parentPort.postMessage({ id: id }); + + break; + + default: + + const message = index[task].apply(index, args); + parentPort.postMessage("search" === task ? { id: id, msg: message } : { id: id }); + } }); \ 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 ccbd409..9c9ffd4 100644 --- a/dist/module-min/db/indexeddb/index.js +++ b/dist/module-min/db/indexeddb/index.js @@ -1 +1 @@ -import{PersistentOptions}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&&(a=a.name,b=a),!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.support_tag_search=!1,this.db=null,this.trx={}):new IdxDB(a,b)}IdxDB.prototype.mount=function(a){return a.encoder?(a.db=this,this.open()):a.mount(this)},IdxDB.prototype.open=function(){let a=this;return navigator.storage&&navigator.storage.persist(),this.db||new Promise(function(b,c){const d=IndexedDB.open(a.id+(a.field?":"+a.field:""),VERSION);d.onupgradeneeded=function(){const b=a.db=this.result;fields.forEach(a=>{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){return IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""))},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b(e.onerror=c=>{this.trx[a+":"+b]=null,e.abort(),e=d=null,g(c)},e.oncomplete=c=>{this.trx[a+":"+b]=null,e=d=null,f(c||!0)},c.call(this,d)))},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})} \ No newline at end of file +import{PersistentOptions}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&&(a=a.name,b=a),!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.support_tag_search=!1,this.db=null,this.trx={}):new IdxDB(a,b)}IdxDB.prototype.mount=function(a){return a.encoder?(a.db=this,this.open()):a.mount(this)},IdxDB.prototype.open=function(){let a=this;return navigator.storage&&navigator.storage.persist(),this.db||new Promise(function(b,c){const d=IndexedDB.open(a.id+(a.field?":"+a.field:""),VERSION);d.onupgradeneeded=function(){const b=a.db=this.result;fields.forEach(a=>{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){return IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""))},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b(e.onerror=c=>{this.trx[a+":"+b]=null,e.abort(),e=d=null,g(c)},e.oncomplete=c=>{this.trx[a+":"+b]=null,e=d=null,f(c||!0)},c.call(this,d)))},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/document.js b/dist/module-min/document.js index 2f4e4f8..9eccb12 100644 --- a/dist/module-min/document.js +++ b/dist/module-min/document.js @@ -1 +1 @@ -import{DocumentOptions,DocumentDescriptor,DocumentIndexOptions,StoreOptions}from"./type.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Cache,{searchCache}from"./cache.js";import{is_string,is_object,parse_simple}from"./common.js";import apply_async from"./async.js";import{exportDocument,importDocument}from"./serialize.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import"./document/add.js";import"./document/search.js";export default function Document(a){if(!this)return new Document(a);const b=a.document||a.doc||a;let c,d;if(this.tree=[],this.field=[],this.marker=[],this.key=(c=b.key||b.id)&&parse_tree(c,this.marker)||"id",d=a.keystore||0,d&&(this.keystore=d),this.fastupdate=!!a.fastupdate,this.reg=this.fastupdate?d&&!0?new KeystoreMap(d):new Map:d&&!0?new KeystoreSet(d):new Set,this.storetree=(c=b.store||null)&&!0!==c&&[],this.store=c&&(d&&!0?new KeystoreMap(d):new Map),this.cache=(c=a.cache||null)&&new Cache(c),a.cache=!1,this.worker=a.worker,this.index=parse_descriptor.call(this,a,b),(this.tag=null,(c=b.tag)&&("string"==typeof c&&(c=[c]),c.length))){this.tag=new Map,this.tagtree=[],this.tagfield=[];for(let a,b,d=0;dc.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;dc.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;d=e))));c++);if(h.length)return g?resolve_default(h,e,0):void b.push(h)}return!c&&h}Index.prototype.get_array=function(a,b,c,d,e,f,g){let h,i;return(b&&(i=this.bidirectional&&a>b),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?b?this.db.get(i?b:a,i?a:b,c,d,e,f,g):this.db.get(a,"",c,d,e,f,g):(b?(h=this.ctx.get(i?a:b),h=h&&h.get(i?b:a)):h=this.map.get(a),h)}; \ No newline at end of file +import{SearchOptions}from"../type.js";import{create_object,is_object,sort_by_length_down}from"../common.js";import Index from"../index.js";import default_compress from"../compress.js";import Resolver from"../resolver.js";import{intersect}from"../intersect.js";import resolve_default from"../resolve/default.js";let global_resolve=1;export function set_resolve(a){global_resolve=a}Index.prototype.search=function(a,b,c){c||(!b&&is_object(a)?(c=a,a=""):is_object(b)&&(c=b,b=0));let d,e,f,g,h,i,j=[],k=0;if(c?(a=c.query||a,b=c.limit||b,k=c.offset||0,e=c.context,f=c.suggest,g=global_resolve&&!1!==c.resolve,g||(global_resolve=0),h=g&&c.enrich,i=this.db&&c.tag):g=this.resolve||global_resolve,a=this.encoder.encode(a),d=a.length,b||!g||(b=100),1===d)return single_term_query.call(this,a[0],"",b,k,g,h,i);if(e=this.depth&&!1!==e,2===d&&e&&!f)return single_term_query.call(this,a[0],a[1],b,k,g,h,i);let l=0,m=0;if(1b),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?b?this.db.get(i?b:a,i?a:b,c,d,e,f,g):this.db.get(a,"",c,d,e,f,g):(b?(h=this.ctx.get(i?a:b),h=h&&h.get(i?b:a)):h=this.map.get(a),h)}; \ No newline at end of file diff --git a/dist/module-min/type.js b/dist/module-min/type.js index 48dc3f3..b3cc789 100644 --- a/dist/module-min/type.js +++ b/dist/module-min/type.js @@ -1 +1 @@ -import Encoder from"./encoder.js";import StorageInterface from"./db/interface.js";export let IndexOptions;export let DocumentIndexOptions;export let DocumentOptions;export let ContextOptions;export let DocumentDescriptor;export let TagOptions;export let StoreOptions;export let SearchOptions;export let DocumentSearchOptions;export let EncoderOptions;export let EncoderSplitOptions;export let PersistentOptions; \ No newline at end of file +import Encoder from"./encoder.js";import StorageInterface from"./db/interface.js";export let IndexOptions={};export let DocumentIndexOptions={};export let DocumentOptions={};export let ContextOptions={};export let DocumentDescriptor={};export let TagOptions={};export let StoreOptions={};export let SearchOptions={};export let DocumentSearchOptions={};export let EncoderOptions={};export let EncoderSplitOptions={};export let PersistentOptions={}; \ No newline at end of file diff --git a/dist/module-min/webpack.js b/dist/module-min/webpack.js index 2c795f3..7bf186f 100644 --- a/dist/module-min/webpack.js +++ b/dist/module-min/webpack.js @@ -1 +1 @@ -import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,DocumentIndexOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.config,DocumentIndexOptions.preset,DocumentIndexOptions.context,DocumentIndexOptions.encoder,DocumentIndexOptions.encode,DocumentIndexOptions.resolution,DocumentIndexOptions.tokenize,DocumentIndexOptions.fastupdate,DocumentIndexOptions.score,DocumentIndexOptions.keystore,DocumentIndexOptions.rtl,DocumentIndexOptions.cache,DocumentIndexOptions.db,DocumentIndexOptions.config,DocumentIndexOptions.field,DocumentIndexOptions.filter,DocumentIndexOptions.custom,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,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;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{FlexSearch.Language={};const a=self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch} \ No newline at end of file +import{SearchOptions,ContextOptions,DocumentDescriptor,DocumentSearchOptions,DocumentIndexOptions,IndexOptions,DocumentOptions,TagOptions,StoreOptions,EncoderOptions,EncoderSplitOptions,PersistentOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Document from"./document.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Resolver from"./resolver.js";import Encoder from"./encoder.js";import IdxDB from"./db/indexeddb/index.js";import Charset from"./charset.js";Index.prototype.add,Index.prototype.append,Index.prototype.search,Index.prototype.update,Index.prototype.remove,Index.prototype.contain,Index.prototype.clear,Index.prototype.cleanup,Index.prototype.searchCache,Index.prototype.addAsync,Index.prototype.appendAsync,Index.prototype.searchAsync,Index.prototype.updateAsync,Index.prototype.removeAsync,Index.prototype.export,Index.prototype.import,Index.prototype.serialize,Index.prototype.mount,Index.prototype.commit,Index.prototype.destroy,Index.prototype.reg,Index.prototype.map,Index.prototype.ctx,Index.prototype.db,Index.prototype.tag,Index.prototype.store,Index.prototype.depth,Index.prototype.bidirectional,Index.prototype.commit_task,Index.prototype.commit_timer,Index.prototype.cache,Index.prototype.bypass,Index.prototype.document,Index.prototype.encoder,Document.prototype.add,Document.prototype.append,Document.prototype.search,Document.prototype.update,Document.prototype.remove,Document.prototype.contain,Document.prototype.clear,Document.prototype.cleanup,Document.prototype.addAsync,Document.prototype.appendAsync,Document.prototype.searchAsync,Document.prototype.updateAsync,Document.prototype.removeAsync,Document.prototype.mount,Document.prototype.commit,Document.prototype.destroy,Document.prototype.export,Document.prototype.import,Document.prototype.searchCache,Document.prototype.get,Document.prototype.set,Resolver.prototype.limit,Resolver.prototype.offset,Resolver.prototype.boost,Resolver.prototype.resolve,Resolver.prototype.or,Resolver.prototype.and,Resolver.prototype.xor,Resolver.prototype.not,StorageInterface.db,StorageInterface.id,StorageInterface.support_tag_search,StorageInterface.prototype.mount,StorageInterface.prototype.open,StorageInterface.prototype.close,StorageInterface.prototype.destroy,StorageInterface.prototype.clear,StorageInterface.prototype.get,StorageInterface.prototype.tag,StorageInterface.prototype.enrich,StorageInterface.prototype.has,StorageInterface.prototype.search,StorageInterface.prototype.info,StorageInterface.prototype.commit,StorageInterface.prototype.remove,Charset.LatinExact,Charset.LatinDefault,Charset.LatinSimple,Charset.LatinBalance,Charset.LatinAdvanced,Charset.LatinExtra,Charset.LatinSoundex,Charset.ArabicDefault,Charset.CjkDefault,Charset.CyrillicDefault,IndexOptions.preset,IndexOptions.context,IndexOptions.encoder,IndexOptions.encode,IndexOptions.resolution,IndexOptions.tokenize,IndexOptions.fastupdate,IndexOptions.score,IndexOptions.keystore,IndexOptions.rtl,IndexOptions.cache,IndexOptions.resolve,IndexOptions.db,IndexOptions.config,DocumentIndexOptions.preset,DocumentIndexOptions.context,DocumentIndexOptions.encoder,DocumentIndexOptions.encode,DocumentIndexOptions.resolution,DocumentIndexOptions.tokenize,DocumentIndexOptions.fastupdate,DocumentIndexOptions.score,DocumentIndexOptions.keystore,DocumentIndexOptions.rtl,DocumentIndexOptions.cache,DocumentIndexOptions.db,DocumentIndexOptions.config,DocumentIndexOptions.field,DocumentIndexOptions.filter,DocumentIndexOptions.custom,DocumentOptions.context,DocumentOptions.encoder,DocumentOptions.encode,DocumentOptions.resolution,DocumentOptions.tokenize,DocumentOptions.fastupdate,DocumentOptions.score,DocumentOptions.keystore,DocumentOptions.rtl,DocumentOptions.cache,DocumentOptions.db,DocumentOptions.doc,DocumentOptions.document,DocumentOptions.worker,ContextOptions.depth,ContextOptions.bidirectional,ContextOptions.resolution,DocumentDescriptor.field,DocumentDescriptor.index,DocumentDescriptor.tag,DocumentDescriptor.store,TagOptions.field,TagOptions.tag,TagOptions.filter,TagOptions.custom,TagOptions.keystore,TagOptions.db,TagOptions.config,StoreOptions.field,StoreOptions.filter,StoreOptions.custom,StoreOptions.config,SearchOptions.query,SearchOptions.limit,SearchOptions.offset,SearchOptions.context,SearchOptions.suggest,SearchOptions.resolve,SearchOptions.enrich,DocumentSearchOptions.query,DocumentSearchOptions.limit,DocumentSearchOptions.offset,DocumentSearchOptions.context,DocumentSearchOptions.suggest,DocumentSearchOptions.enrich,DocumentSearchOptions.tag,DocumentSearchOptions.field,DocumentSearchOptions.index,DocumentSearchOptions.pluck,DocumentSearchOptions.merge,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;const FlexSearch={Index:Index,Charset:Charset,Encoder:Encoder,Document:Document,Worker:WorkerIndex,Resolver:Resolver,IndexedDB:IdxDB,Language:{}};{FlexSearch.Language={};const a=self;let b;(b=a.define)&&b.amd?b([],function(){return FlexSearch}):"object"==typeof a.exports?a.exports=FlexSearch:a.FlexSearch=FlexSearch} \ No newline at end of file diff --git a/dist/module-min/worker.js b/dist/module-min/worker.js index cef2831..77f6139 100644 --- a/dist/module-min/worker.js +++ b/dist/module-min/worker.js @@ -1 +1 @@ -import{IndexOptions}from"./type.js";import{create_object,is_function,is_object,is_string}from"./common.js";import handler from"./worker/handler.js";let pid=0;export default function WorkerIndex(a){if(!this)return new WorkerIndex(a);a||(a={});let b="undefined"!=typeof self&&(self||window)._factory;b&&(b=b.toString());const c="undefined"==typeof window,d=this;(async function(){function e(a){a=a.data||a;const b=a.id,c=b&&d.resolver[b];c&&(c(a.msg),delete d.resolver[b])}if(this.worker=await create(b,c,a.worker),this.resolver=create_object(),!!this.worker)return c?this.worker.on("message",e):this.worker.onmessage=e,a.config?(delete a.db,new Promise(function(c){d.resolver[++pid]=function(){c(d)},d.worker.postMessage({id:pid,task:"init",factory:b,options:a})})):void this.worker.postMessage({task:"init",factory:b,options:a})}).call(this)}register("add"),register("append"),register("search"),register("update"),register("remove");function register(a){WorkerIndex.prototype[a]=WorkerIndex.prototype[a+"Async"]=function(){const b=this,c=[].slice.call(arguments),d=c[c.length-1];let e;is_function(d)&&(e=d,c.splice(c.length-1,1));const f=new Promise(function(d){b.resolver[++pid]=d,b.worker.postMessage({task:a,id:pid,args:c})});return e?(f.then(e),this):f}}async function create(a,b,c){let d;return d=b?"undefined"==typeof module?(0,eval)("new ((await import(\"worker_threads\"))[\"Worker\"])((1,eval)(\"import.meta.dirname\") + \"/node/node.mjs\")"):(0,eval)("new (require(\"worker_threads\")[\"Worker\"])(__dirname + \"/node/node.js\")"):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+handler.toString()],{type:"text/javascript"}))):new window.Worker(is_string(c)?c:"worker/worker.js",{type:"module"}),d} \ No newline at end of file +import{IndexOptions}from"./type.js";import{create_object,is_function,is_object,is_string}from"./common.js";import handler from"./worker/handler.js";let pid=0;export default function WorkerIndex(a={}){function b(f){function g(a){a=a.data||a;const b=a.id,c=b&&e.resolver[b];c&&(c(a.msg),delete e.resolver[b])}return(this.worker=f||create(c,d,a.worker),this.worker.then)?this.worker.then(b):(this.resolver=create_object(),!!this.worker)?(d?this.worker.on("message",g):this.worker.onmessage=g,a.config)?new Promise(function(b){e.resolver[++pid]=function(){b(e)},e.worker.postMessage({id:pid,task:"init",factory:c,options:a})}):(this.worker.postMessage({task:"init",factory:c,options:a}),this.worker):void 0}if(!this)return new WorkerIndex(a);let c="undefined"==typeof self?"undefined"==typeof window?null:window._factory:self._factory;c&&(c=c.toString());const d="undefined"==typeof window,e=this;this.worker=b.call(this)}register("add"),register("append"),register("search"),register("update"),register("remove");function register(a){WorkerIndex.prototype[a]=WorkerIndex.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments),d=c[c.length-1];let e;is_function(d)&&(e=d,c.splice(c.length-1,1));const f=new Promise(function(d){b.resolver[++pid]=d,b.worker.postMessage({task:a,id:pid,args:c})});return e?(f.then(e),this):f}}function create(a,b,c){let d;return d=b?"undefined"==typeof module?(0,eval)("import(\"worker_threads\").then(function(worker){ return new worker[\"Worker\"]((1,eval)(\"import.meta.dirname\") + \"/node/node.mjs\"); })"):(0,eval)("new (require(\"worker_threads\")[\"Worker\"])(__dirname + \"/node/node.js\")"):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+handler.toString()],{type:"text/javascript"}))):new window.Worker(is_string(c)?c:"worker/worker.js",{type:"module"}),d} \ No newline at end of file diff --git a/dist/module-min/worker/node.js b/dist/module-min/worker/node.js index 4ca47bb..43d61e6 100644 --- a/dist/module-min/worker/node.js +++ b/dist/module-min/worker/node.js @@ -1 +1 @@ -const{parentPort}=require("worker_threads"),{join}=require("path"),{Index}=require("../flexsearch.bundle.min.js");let index;parentPort.on("message",function(a){const b=a.args,c=a.task,d=a.id;switch(c){case"init":let e=a.options||{},f=e.config;f&&(e=require(f)),index=new Index(e);break;default:const g=index[c].apply(index,b);parentPort.postMessage("search"===c?{id:d,msg:g}:{id:d});}}); \ No newline at end of file +const{parentPort}=require("worker_threads"),{join}=require("path"),{Index}=require("../flexsearch.bundle.min.js");let index;parentPort.on("message",async function(a){const b=a.args,c=a.task,d=a.id;switch(c){case"init":let e=a.options||{},f=e.config;f&&(e=Object.assign({},e,require(f)),delete e.worker),index=new Index(e),parentPort.postMessage({id:d});break;default:const g=index[c].apply(index,b);parentPort.postMessage("search"===c?{id:d,msg:g}:{id:d});}}); \ No newline at end of file diff --git a/dist/module/db/indexeddb/index.js b/dist/module/db/indexeddb/index.js index 5dfdc45..2fc8a26 100644 --- a/dist/module/db/indexeddb/index.js +++ b/dist/module/db/indexeddb/index.js @@ -139,6 +139,7 @@ IdxDB.prototype.clear = function () { }; IdxDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = /* tag? */!0, enrich = !1) { + console.log("!!!!!!!!!!!"); const transaction = this.db.transaction(ctx ? "ctx" : "map", "readonly"), map = transaction.objectStore(ctx ? "ctx" : "map"), req = map.get(ctx ? ctx + ":" + key : key), diff --git a/dist/module/db/postgres/index.js b/dist/module/db/postgres/index.js index 134be98..6ff096d 100644 --- a/dist/module/db/postgres/index.js +++ b/dist/module/db/postgres/index.js @@ -63,7 +63,8 @@ export default function PostgresDB(name, config = {}) { this.id = (config.schema ? sanitize(config.schema) : defaults.schema) + (name ? "_" + sanitize(name) : ""); this.field = config.field ? "_" + sanitize(config.field) : ""; this.type = config.type ? types[config.type.toLowerCase()] : "text"; - this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; + this.support_tag_search = + /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'"); this.db = DB || (DB = config.db || null); Object.assign(defaults, config); diff --git a/dist/module/document.js b/dist/module/document.js index 877f3a7..e991f2a 100644 --- a/dist/module/document.js +++ b/dist/module/document.js @@ -49,7 +49,8 @@ export default function Document(options) { this.cache = (tmp = options.cache || null) && new Cache(tmp); // do not apply cache again for the indexes since .searchCache() // is just a wrapper over .search() - options.cache = /* suggest */ /* append: */ /* enrich */!1; + options.cache = /* suggest */ /* append: */ + /* enrich */!1; this.worker = options.worker; @@ -99,7 +100,21 @@ export default function Document(options) { } } - options.db && this.mount(options.db); + + if (this.worker) { + const promises = []; + for (const index of this.index.values()) { + index.worker.then && promises.push(index.worker); + } + if (promises.length) { + const self = this; + return Promise.all(promises).then(function () { + return self; + }); + } + } else { + options.db && this.mount(options.db); + } } Document.prototype.mount = function (db) { @@ -209,8 +224,9 @@ function parse_descriptor(options, document) { if (this.worker) { const worker = new WorkerIndex(opt); - index.set(key, worker); - if (!worker.worker) { + if (worker.worker) { + index.set(key, worker); + } else { // fallback when not supported this.worker = !1; } diff --git a/dist/module/index.js b/dist/module/index.js index 77c34e2..f9eb412 100644 --- a/dist/module/index.js +++ b/dist/module/index.js @@ -37,7 +37,7 @@ export default function Index(options, _register) { /** @type ContextOptions */ const context = options.context || {}, - encoder = options.encode || options.encoder || default_encoder; + encoder = is_string(options.encoder) ? Charset[options.encoder] : options.encode || options.encoder || default_encoder; /** @type Encoder */ this.encoder = encoder.encode ? encoder : "object" == typeof encoder ? new Encoder(encoder) : { encode: encoder }; @@ -67,7 +67,7 @@ export default function Index(options, _register) { this.resolve = !1 !== options.resolve; if (tmp = options.db) { - this.db = tmp.mount(this); + this.db = this.mount(tmp); } this.commit_auto = !1 !== options.commit; this.commit_task = []; diff --git a/dist/module/index/search.js b/dist/module/index/search.js index 29b3422..d42576f 100644 --- a/dist/module/index/search.js +++ b/dist/module/index/search.js @@ -173,6 +173,8 @@ Index.prototype.search = function (query, limit, options) { } } + // from this point there are just multi-term queries + if (this.db) { if (this.db.search) { @@ -190,10 +192,12 @@ Index.prototype.search = function (query, limit, options) { if (keyword) { - arr = await self.get_array(term, keyword); - arr = add_result(arr, result, suggest, self.resolution_ctx, - /** @type {!number} */limit, offset, 2 === length - /*, term, keyword*/ + arr = await self.get_array(term, keyword, 0, 0, !1, !1); + arr = add_result(arr, result, suggest, self.resolution_ctx + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 2 + // /*, term, keyword*/ ); // the context is a moving window where the keyword is going forward like a cursor @@ -204,10 +208,12 @@ Index.prototype.search = function (query, limit, options) { } } else { - arr = await self.get_array(term); - arr = add_result(arr, result, suggest, self.resolution, - /** @type {!number} */limit, offset, 1 === length - /*, term*/ + arr = await self.get_array(term, "", 0, 0, !1, !1); + arr = add_result(arr, result, suggest, self.resolution + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 1 + // /*, term*/ ); } @@ -243,10 +249,12 @@ Index.prototype.search = function (query, limit, options) { if (keyword) { - arr = this.get_array(term, keyword); - arr = /*this.*/add_result(arr, result, suggest, this.resolution_ctx, - /** @type {!number} */limit, offset, 2 === length - /*, term, keyword*/ + arr = this.get_array(term, keyword, 0, 0, !1, !1); + arr = /*this.*/add_result(arr, result, suggest, this.resolution_ctx + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 2 + // /*, term, keyword*/ ); // 1. when suggestion enabled just forward keyword if term was found @@ -256,10 +264,12 @@ Index.prototype.search = function (query, limit, options) { } } else { - arr = this.get_array(term); - arr = /*this.*/add_result(arr, result, suggest, this.resolution, - /** @type {!number} */limit, offset, 1 === length - /*, term*/ + arr = this.get_array(term, "", 0, 0, !1, !1); + arr = /*this.*/add_result(arr, result, suggest, this.resolution + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 1 + // /*, term*/ ); } @@ -327,13 +337,10 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { * @param {Array} result * @param {Array} suggest * @param {number} resolution - * @param {number} limit - * @param {number} offset - * @param {boolean} single_term * @return {Array|boolean|undefined} */ -function add_result(arr, result, suggest, resolution, limit, offset, single_term /*, term, keyword*/) { +function add_result(arr, result, suggest, resolution /*, limit, offset single_term, term, keyword*/) { let word_arr = []; //let arr;// = keyword ? this.ctx : this.map; @@ -345,21 +352,22 @@ function add_result(arr, result, suggest, resolution, limit, offset, single_term // apply reduced resolution for queries resolution = Math.min(arr.length, resolution); - for (let x = 0, size = 0, tmp; x < resolution; x++) { + for (let x = 0, tmp; x < resolution; x++) { if (tmp = arr[x]) { - if (offset) { - // apply offset right here on single terms - if (tmp && single_term) { - if (tmp.length <= offset) { - offset -= tmp.length; - tmp = null; - } else { - tmp = tmp.slice(offset); - offset = 0; - } - } - } + // if(offset){ + // // apply offset right here on single terms + // if(tmp && single_term){ + // if(tmp.length <= offset){ + // offset -= tmp.length; + // tmp = null; + // } + // else{ + // tmp = tmp.slice(offset); + // offset = 0; + // } + // } + // } if (tmp) { @@ -368,25 +376,25 @@ function add_result(arr, result, suggest, resolution, limit, offset, single_term // simplified score order: //word_arr.push(tmp); - if (single_term) { - size += tmp.length; - if (size >= limit) { - // fast path: - // a single term does not need to pre-collect results - break; - } - } + // if(single_term){ + // size += tmp.length; + // if(size >= limit){ + // // fast path: + // // a single term does not need to pre-collect results + // break; + // } + // } } } } if (word_arr.length) { - if (single_term) { - // fast path optimization - // offset was already applied at this point - // return an array will stop the query process immediately - return resolve_default(word_arr, limit, 0); - } + // if(single_term){ + // // fast path optimization + // // offset was already applied at this point + // // return an array will stop the query process immediately + // return resolve_default(word_arr, limit, 0); + // } result.push(word_arr); // return nothing will continue the query diff --git a/dist/module/type.js b/dist/module/type.js index 2e43ec3..24d1aa9 100644 --- a/dist/module/type.js +++ b/dist/module/type.js @@ -19,10 +19,11 @@ import StorageInterface from "./db/interface.js"; * resolve: [boolean=true], * db: StorageInterface|undefined, * commit: boolean=true, + * worker: boolean|string|undefined, * config: string|undefined * }} */ -export let IndexOptions; +export let IndexOptions = {}; /** * @typedef DocumentIndexOptions {{ @@ -40,13 +41,12 @@ export let IndexOptions; * db: StorageInterface|undefined, * commit: boolean=true, * config: string|undefined, - * * field: string, * filter: Function|undefined, * custom: Function|undefined * }} */ -export let DocumentIndexOptions; +export let DocumentIndexOptions = {}; /** * @typedef DocumentOptions {{ @@ -66,7 +66,7 @@ export let DocumentIndexOptions; * worker: boolean|string|undefined * }} */ -export let DocumentOptions; +export let DocumentOptions = {}; /** * @typedef ContextOptions {{ @@ -75,7 +75,7 @@ export let DocumentOptions; * resolution: number|undefined * }} */ -export let ContextOptions; +export let ContextOptions = {}; /** * @typedef DocumentDescriptor {{ @@ -86,7 +86,7 @@ export let ContextOptions; * store: StoreOptions|Array|undefined * }} */ -export let DocumentDescriptor; +export let DocumentDescriptor = {}; /** * @typedef TagOptions {{ @@ -99,7 +99,7 @@ export let DocumentDescriptor; * config: string|undefined * }} */ -export let TagOptions; +export let TagOptions = {}; /** * @typedef StoreOptions {{ @@ -109,7 +109,7 @@ export let TagOptions; * config: string|undefined * }} */ -export let StoreOptions; +export let StoreOptions = {}; /** * @typedef SearchOptions {{ @@ -122,7 +122,7 @@ export let StoreOptions; * enrich: [boolean=false], * }} */ -export let SearchOptions; +export let SearchOptions = {}; // tag: Array|undefined /** @@ -140,7 +140,7 @@ export let SearchOptions; * merge: [boolean=false] * }} */ -export let DocumentSearchOptions; +export let DocumentSearchOptions = {}; /** * @typedef EncoderOptions {{ @@ -161,7 +161,7 @@ export let DocumentSearchOptions; * cache: boolean=true, * }} */ -export let EncoderOptions; +export let EncoderOptions = {}; /** * @typedef EncoderSplitOptions {{ @@ -173,7 +173,7 @@ export let EncoderOptions; * char: string|Array|undefined, * }} */ -export let EncoderSplitOptions; +export let EncoderSplitOptions = {}; /** * @typedef PersistentOptions {{ @@ -183,4 +183,4 @@ export let EncoderSplitOptions; * db: *|undefined * }} */ -export let PersistentOptions; \ No newline at end of file +export let PersistentOptions = {}; \ No newline at end of file diff --git a/dist/module/webpack.js b/dist/module/webpack.js index 128e45a..e3f9974 100644 --- a/dist/module/webpack.js +++ b/dist/module/webpack.js @@ -44,6 +44,7 @@ import Charset from "./charset.js"; /** @export */Index.prototype.cache; /** @export */Index.prototype.bypass; /** @export */Index.prototype.document; +/** @export */Index.prototype.encoder; /** @export */Document.prototype.add; /** @export */Document.prototype.append; diff --git a/dist/module/worker.js b/dist/module/worker.js index 97189d3..4079eb6 100644 --- a/dist/module/worker.js +++ b/dist/module/worker.js @@ -1,4 +1,3 @@ -//import { promise as Promise } from "../polyfill.js"; import { IndexOptions } from "./type.js"; import { create_object, is_function, is_object, is_string } from "./common.js"; import handler from "./worker/handler.js"; @@ -10,20 +9,15 @@ let pid = 0; * @constructor */ -export default function WorkerIndex(options) { +export default function WorkerIndex(options = {}) { if (!this) { return new WorkerIndex(options); } - if (!options) { - options = {}; - } - // the factory is the outer wrapper from the build - // we use "self" as a trap for node.js - - let factory = "undefined" != typeof self && (self || window)._factory; + // it uses "self" as a trap for node.js + let factory = "undefined" != typeof self ? self._factory : "undefined" != typeof window ? window._factory : null; if (factory) { factory = factory.toString(); } @@ -31,9 +25,18 @@ export default function WorkerIndex(options) { const is_node_js = "undefined" == typeof window /*&& self["exports"]*/, _self = this; - (async function () { + /** + * @param {Worker=} _worker + * @this {WorkerIndex} + */ + function init(_worker) { + + this.worker = _worker || create(factory, is_node_js, options.worker); + + if (this.worker.then) { + return this.worker.then(init); + } - this.worker = await create(factory, is_node_js, options.worker); this.resolver = create_object(); if (!this.worker) { @@ -55,14 +58,16 @@ export default function WorkerIndex(options) { if (options.config) { - delete options.db; + //delete options.db; // when extern configuration needs to be loaded // it needs to return a promise to await for return new Promise(function (resolve) { + _self.resolver[++pid] = function () { resolve(_self); }; + _self.worker.postMessage({ id: pid, task: "init", @@ -77,7 +82,11 @@ export default function WorkerIndex(options) { factory: factory, options: options }); - }).call(this); + + return this.worker; + } + + this.worker = init.call(this); } register("add"); @@ -88,7 +97,7 @@ register("remove"); function register(key) { - WorkerIndex.prototype[key] = WorkerIndex.prototype[key + "Async"] = function () { + WorkerIndex.prototype[key] = WorkerIndex.prototype[key + "Async"] = async function () { const self = this, args = [].slice.call(arguments), arg = args[args.length - 1]; @@ -121,14 +130,16 @@ function register(key) { }; } -async function create(factory, is_node_js, worker_path) { +function create(factory, is_node_js, worker_path) { let worker = is_node_js ? // This eval will be removed when compiling, it isn't there in final build "undefined" != typeof module ? (0, eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') //: (0,eval)('new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/worker/node.mjs")') - : (0, eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")') + //: (0,eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")') + : (0, eval)('import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)(\"import.meta.dirname\") + "/node/node.mjs"); })') + //: import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/worker/node.mjs"); }) //eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') : factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker(is_string(worker_path) ? worker_path : "worker/worker.js", { type: "module" }); diff --git a/dist/module/worker/handler.js b/dist/module/worker/handler.js index 0ada932..f918d7d 100644 --- a/dist/module/worker/handler.js +++ b/dist/module/worker/handler.js @@ -3,59 +3,53 @@ import { IndexOptions } from "../type.js"; export default (async function (data) { - data = data.data; + data = data.data; - /** @type Index */ - const index = self._index, - args = data.args, - task = data.task; + /** @type Index */ + const index = self._index, + args = data.args, + task = data.task; - switch (task) { + switch (task) { - case "init": + case "init": - /** @type IndexOptions */ - let options = data.options || {}, - filepath = options.config; + /** @type IndexOptions */ + let options = data.options || {}, + filepath = options.config; - if (filepath) { - options = filepath; - // will be replaced after build with the line below because - // there is an issue with closure compiler dynamic import - //options = await import(filepath); - } - - // deprecated: - // const encode = options.encode; - // if(encode && (encode.indexOf("function") === 0)){ - // options.encode = Function("return " + encode)(); - // } - - const factory = data.factory; - - if (factory) { - - // export the FlexSearch global payload to "self" - Function("return " + factory)()(self); - - /** @type Index */ - self._index = new self.FlexSearch.Index(options); - - // destroy the exported payload - delete self.FlexSearch; - } else { - - self._index = new Index(options); - } - - postMessage({ id: data.id }); - break; - - default: - const id = data.id, - message = index[task].apply(index, args); - - postMessage("search" === task ? { id: id, msg: message } : { id: id }); + if (filepath) { + options = filepath; + // will be replaced after build with the line below because + // there is an issue with closure compiler dynamic import + //options = await import(filepath); } + + const factory = data.factory; + + if (factory) { + + // export the FlexSearch global payload to "self" + Function("return " + factory)()(self); + + /** @type Index */ + self._index = new self.FlexSearch.Index(options); + + // destroy the exported payload + delete self.FlexSearch; + } else { + + self._index = new Index(options); + } + + postMessage({ id: data.id }); + break; + + default: + const id = data.id, + message = index[task].apply(index, args); + + postMessage("search" === task ? { id: id, msg: message } : { id: id }); + } }); \ No newline at end of file diff --git a/dist/module/worker/node.js b/dist/module/worker/node.js index d11807a..48f0621 100644 --- a/dist/module/worker/node.js +++ b/dist/module/worker/node.js @@ -7,43 +7,35 @@ const { parentPort } = require("worker_threads"), let index; -parentPort.on("message", function (data) { +parentPort.on("message", async function (data) { - /** @type Index */ - const args = data.args, - task = data.task, - id = data.id; + /** @type Index */ + const args = data.args, + task = data.task, + id = data.id; - switch (task) { + switch (task) { - case "init": - let options = data.options || {}, - filepath = options.config; + case "init": + let options = data.options || {}, + filepath = options.config; + // load extern field configuration - // load extern field configuration - - // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){ - // // current working directory - // const dir = process.cwd(); - // filepath = join(dir, filepath); - // } - if (filepath) { - options = require(filepath); - } - - // deprecated: - // const encode = options["encode"]; - // if(encode && (encode.indexOf("function") === 0)){ - // options["encode"] = new Function("return " + encode)(); - // } - - index = new Index(options); - break; - - default: - - const message = index[task].apply(index, args); - parentPort.postMessage("search" === task ? { id: id, msg: message } : { id: id }); + if (filepath) { + options = Object.assign({}, options, require(filepath)); + delete options.worker; } + + index = new Index(options); + //index.db && await index.db; + parentPort.postMessage({ id: id }); + + break; + + default: + + const message = index[task].apply(index, args); + parentPort.postMessage("search" === task ? { id: id, msg: message } : { id: id }); + } }); \ No newline at end of file diff --git a/dist/node/node.js b/dist/node/node.js index a35758d..3898b9a 100644 --- a/dist/node/node.js +++ b/dist/node/node.js @@ -6,7 +6,7 @@ const { Index } = require("../flexsearch.bundle.min.js"); let index; -parentPort.on("message", function(data){ +parentPort.on("message", async function(data){ /** @type Index */ const args = data["args"]; @@ -18,30 +18,26 @@ parentPort.on("message", function(data){ case "init": let options = data["options"] || {}; - // load extern field configuration let filepath = options["config"]; - // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){ - // // current working directory - // const dir = process.cwd(); - // filepath = join(dir, filepath); - // } if(filepath){ - options = require(filepath); + options = Object.assign({}, options, require(filepath)); + delete options.worker; } - // deprecated: - // const encode = options["encode"]; - // if(encode && (encode.indexOf("function") === 0)){ - // options["encode"] = new Function("return " + encode)(); - // } - index = new Index(options); + //index.db && await index.db; + parentPort.postMessage({ "id": id }); + break; default: const message = index[task].apply(index, args); - parentPort.postMessage(task === "search" ? { "id": id, "msg": message } : { "id": id }); + parentPort.postMessage( + task === "search" + ? { "id": id, "msg": message } + : { "id": id } + ); } }); diff --git a/package.json b/package.json index e4d6318..e2cf965 100644 --- a/package.json +++ b/package.json @@ -75,8 +75,8 @@ "build:module:bundle:debug": "node task/build RELEASE=bundle.module DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", "build:module:compact": "node task/build RELEASE=compact.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=false SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", "build:module:compact:debug": "node task/build RELEASE=compact.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=false SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:module:light": "node task/build RELEASE=light.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=false SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", - "build:module:light:debug": "node task/build RELEASE=light.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=false SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:module:light": "node task/build RELEASE=light.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", + "build:module:light:debug": "node task/build RELEASE=light.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", "build:all": "npm run build:bundle && npm run build:bundle:debug && npm run build:light && npm run build:light:debug && npm run build:compact && npm run build:compact:debug && npm run build:module && npm run build:module:debug && npm run build:module:min && npm run build:module:bundle && npm run build:module:bundle:debug && npm run build:module:light && npm run build:module:light:debug && npm run build:module:compact && npm run build:module:compact:debug && npm run build:lang && npm run build:es5 && npm run build:es5:debug", "build:custom": "node task/build RELEASE=custom", "test": "cd test && npm install && npm run test" diff --git a/src/document.js b/src/document.js index e1dc22c..88e8346 100644 --- a/src/document.js +++ b/src/document.js @@ -128,7 +128,19 @@ export default function Document(options){ } } - if(SUPPORT_PERSISTENT){ + if(SUPPORT_WORKER && this.worker){ + const promises = []; + for(const index of this.index.values()){ + index.worker.then && promises.push(index.worker); + } + if(promises.length){ + const self = this; + return Promise.all(promises).then(function(){ + return self; + }); + } + } + else if(SUPPORT_PERSISTENT){ options.db && this.mount(options.db); } } @@ -247,8 +259,10 @@ function parse_descriptor(options, document){ if(SUPPORT_WORKER && this.worker){ const worker = new WorkerIndex(opt); - index.set(key, worker); - if(!worker.worker){ + if(worker.worker){ + index.set(key, worker); + } + else{ // fallback when not supported this.worker = false; } diff --git a/src/index.js b/src/index.js index b4d5f43..497a110 100644 --- a/src/index.js +++ b/src/index.js @@ -59,10 +59,12 @@ export default function Index(options, _register){ /** @type ContextOptions */ const context = options.context || {}; - const encoder = options.encode || options.encoder || ( - SUPPORT_ENCODER ? default_encoder : function(str){ - return str.toLowerCase().trim().split(/\s+/); - } + const encoder = SUPPORT_CHARSET && is_string(options.encoder) + ? Charset[options.encoder] + : options.encode || options.encoder || ( + SUPPORT_ENCODER ? default_encoder : function(str){ + return str.toLowerCase().trim().split(/\s+/); + } ); /** @type Encoder */ this.encoder = encoder.encode @@ -109,7 +111,7 @@ export default function Index(options, _register){ if(SUPPORT_PERSISTENT){ if((tmp = options.db)){ - this.db = tmp.mount(this); + this.db = this.mount(tmp); } this.commit_auto = options.commit !== false; this.commit_task = []; diff --git a/src/index/search.js b/src/index/search.js index 75bbf4a..ec131bb 100644 --- a/src/index/search.js +++ b/src/index/search.js @@ -209,6 +209,8 @@ Index.prototype.search = function(query, limit, options){ } } + // from this point there are just multi-term queries + if(SUPPORT_PERSISTENT && this.db){ if(this.db.search){ @@ -226,16 +228,16 @@ Index.prototype.search = function(query, limit, options){ if(keyword){ - arr = await self.get_array(term, keyword); + arr = await self.get_array(term, keyword, 0, 0, false, false); arr = add_result( arr, result, suggest, self.resolution_ctx, - /** @type {!number} */ (limit), - offset, - length === 2 - /*, term, keyword*/ + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 2 + // /*, term, keyword*/ ); // the context is a moving window where the keyword is going forward like a cursor @@ -247,16 +249,16 @@ Index.prototype.search = function(query, limit, options){ } else{ - arr = await self.get_array(term); + arr = await self.get_array(term, "", 0, 0, false, false); arr = add_result( arr, result, suggest, self.resolution, - /** @type {!number} */ (limit), - offset, - length === 1 - /*, term*/ + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 1 + // /*, term*/ ); } @@ -297,16 +299,16 @@ Index.prototype.search = function(query, limit, options){ if(keyword){ - arr = this.get_array(term, keyword); + arr = this.get_array(term, keyword, 0, 0, false, false); arr = /*this.*/add_result( arr, result, suggest, this.resolution_ctx, - /** @type {!number} */ (limit), - offset, - length === 2 - /*, term, keyword*/ + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 2 + // /*, term, keyword*/ ); // 1. when suggestion enabled just forward keyword if term was found @@ -317,16 +319,16 @@ Index.prototype.search = function(query, limit, options){ } else{ - arr = this.get_array(term); + arr = this.get_array(term, "", 0, 0, false, false); arr = /*this.*/add_result( arr, result, suggest, this.resolution, - /** @type {!number} */ (limit), - offset, - length === 1 - /*, term*/ + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 1 + // /*, term*/ ); } @@ -402,13 +404,10 @@ function single_term_query(term, keyword, limit, offset, resolve, enrich, tag){ * @param {Array} result * @param {Array} suggest * @param {number} resolution - * @param {number} limit - * @param {number} offset - * @param {boolean} single_term * @return {Array|boolean|undefined} */ -function add_result(arr, result, suggest, resolution, limit, offset, single_term/*, term, keyword*/){ +function add_result(arr, result, suggest, resolution/*, limit, offset single_term, term, keyword*/){ let word_arr = []; //let arr;// = keyword ? this.ctx : this.map; @@ -423,19 +422,19 @@ function add_result(arr, result, suggest, resolution, limit, offset, single_term for(let x = 0, size = 0, tmp; x < resolution; x++){ if((tmp = arr[x])){ - if(offset){ - // apply offset right here on single terms - if(tmp && single_term){ - if(tmp.length <= offset){ - offset -= tmp.length; - tmp = null; - } - else{ - tmp = tmp.slice(offset); - offset = 0; - } - } - } + // if(offset){ + // // apply offset right here on single terms + // if(tmp && single_term){ + // if(tmp.length <= offset){ + // offset -= tmp.length; + // tmp = null; + // } + // else{ + // tmp = tmp.slice(offset); + // offset = 0; + // } + // } + // } if(tmp){ @@ -444,25 +443,25 @@ function add_result(arr, result, suggest, resolution, limit, offset, single_term // simplified score order: //word_arr.push(tmp); - if(single_term){ - size += tmp.length; - if(size >= limit){ - // fast path: - // a single term does not need to pre-collect results - break; - } - } + // if(single_term){ + // size += tmp.length; + // if(size >= limit){ + // // fast path: + // // a single term does not need to pre-collect results + // break; + // } + // } } } } if(word_arr.length){ - if(single_term){ - // fast path optimization - // offset was already applied at this point - // return an array will stop the query process immediately - return resolve_default(word_arr, limit, 0); - } + // if(single_term){ + // // fast path optimization + // // offset was already applied at this point + // // return an array will stop the query process immediately + // return resolve_default(word_arr, limit, 0); + // } result.push(word_arr); // return nothing will continue the query diff --git a/src/type.js b/src/type.js index 2e43ec3..24d1aa9 100644 --- a/src/type.js +++ b/src/type.js @@ -19,10 +19,11 @@ import StorageInterface from "./db/interface.js"; * resolve: [boolean=true], * db: StorageInterface|undefined, * commit: boolean=true, + * worker: boolean|string|undefined, * config: string|undefined * }} */ -export let IndexOptions; +export let IndexOptions = {}; /** * @typedef DocumentIndexOptions {{ @@ -40,13 +41,12 @@ export let IndexOptions; * db: StorageInterface|undefined, * commit: boolean=true, * config: string|undefined, - * * field: string, * filter: Function|undefined, * custom: Function|undefined * }} */ -export let DocumentIndexOptions; +export let DocumentIndexOptions = {}; /** * @typedef DocumentOptions {{ @@ -66,7 +66,7 @@ export let DocumentIndexOptions; * worker: boolean|string|undefined * }} */ -export let DocumentOptions; +export let DocumentOptions = {}; /** * @typedef ContextOptions {{ @@ -75,7 +75,7 @@ export let DocumentOptions; * resolution: number|undefined * }} */ -export let ContextOptions; +export let ContextOptions = {}; /** * @typedef DocumentDescriptor {{ @@ -86,7 +86,7 @@ export let ContextOptions; * store: StoreOptions|Array|undefined * }} */ -export let DocumentDescriptor; +export let DocumentDescriptor = {}; /** * @typedef TagOptions {{ @@ -99,7 +99,7 @@ export let DocumentDescriptor; * config: string|undefined * }} */ -export let TagOptions; +export let TagOptions = {}; /** * @typedef StoreOptions {{ @@ -109,7 +109,7 @@ export let TagOptions; * config: string|undefined * }} */ -export let StoreOptions; +export let StoreOptions = {}; /** * @typedef SearchOptions {{ @@ -122,7 +122,7 @@ export let StoreOptions; * enrich: [boolean=false], * }} */ -export let SearchOptions; +export let SearchOptions = {}; // tag: Array|undefined /** @@ -140,7 +140,7 @@ export let SearchOptions; * merge: [boolean=false] * }} */ -export let DocumentSearchOptions; +export let DocumentSearchOptions = {}; /** * @typedef EncoderOptions {{ @@ -161,7 +161,7 @@ export let DocumentSearchOptions; * cache: boolean=true, * }} */ -export let EncoderOptions; +export let EncoderOptions = {}; /** * @typedef EncoderSplitOptions {{ @@ -173,7 +173,7 @@ export let EncoderOptions; * char: string|Array|undefined, * }} */ -export let EncoderSplitOptions; +export let EncoderSplitOptions = {}; /** * @typedef PersistentOptions {{ @@ -183,4 +183,4 @@ export let EncoderSplitOptions; * db: *|undefined * }} */ -export let PersistentOptions; \ No newline at end of file +export let PersistentOptions = {}; \ No newline at end of file diff --git a/src/webpack.js b/src/webpack.js index 17e3ede..dd300b2 100644 --- a/src/webpack.js +++ b/src/webpack.js @@ -71,6 +71,7 @@ if(SUPPORT_PERSISTENT){ /** @export */ Index.prototype.cache; /** @export */ Index.prototype.bypass; /** @export */ Index.prototype.document; +/** @export */ Index.prototype.encoder; } /** @export */ Document.prototype.add; diff --git a/src/worker.js b/src/worker.js index b1ca593..72d5eb8 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,4 +1,3 @@ -//import { promise as Promise } from "../polyfill.js"; import { IndexOptions } from "./type.js"; import { create_object, is_function, is_object, is_string } from "./common.js"; import handler from "./worker/handler.js"; @@ -10,27 +9,19 @@ let pid = 0; * @constructor */ -export default function WorkerIndex(options){ +export default function WorkerIndex(options = {}){ if(!this) { return new WorkerIndex(options); } - if(options){ - // deprecated: - // was replaced by dynamic config loading - // if(is_function(options.encode)){ - // options.encode = options.encode.toString(); - // } - } - else{ - options = {}; - } - // the factory is the outer wrapper from the build - // we use "self" as a trap for node.js - - let factory = typeof self !== "undefined" && (self||window)["_factory"]; + // it uses "self" as a trap for node.js + let factory = typeof self !== "undefined" + ? self["_factory"] + : typeof window !== "undefined" + ? window["_factory"] + : null; if(factory){ factory = factory.toString(); } @@ -38,9 +29,18 @@ export default function WorkerIndex(options){ const is_node_js = typeof window === "undefined" /*&& self["exports"]*/; const _self = this; - (async function(){ + /** + * @param {Worker=} _worker + * @this {WorkerIndex} + */ + function init(_worker){ + + this.worker = _worker || create(factory, is_node_js, options.worker); + + if(this.worker.then){ + return this.worker.then(init); + } - this.worker = await create(factory, is_node_js, options.worker); this.resolver = create_object(); if(!this.worker){ @@ -63,14 +63,16 @@ export default function WorkerIndex(options){ if(options.config){ - delete options.db; + //delete options.db; // when extern configuration needs to be loaded // it needs to return a promise to await for return new Promise(function(resolve){ + _self.resolver[++pid] = function(){ resolve(_self); }; + _self.worker.postMessage({ "id": pid, "task": "init", @@ -86,7 +88,10 @@ export default function WorkerIndex(options){ "options": options }); - }.call(this)); + return this.worker; + } + + this.worker = init.call(this); } register("add"); @@ -98,7 +103,7 @@ register("remove"); function register(key){ WorkerIndex.prototype[key] = - WorkerIndex.prototype[key + "Async"] = function(){ + WorkerIndex.prototype[key + "Async"] = async function(){ const self = this; const args = [].slice.call(arguments); @@ -132,7 +137,7 @@ function register(key){ }; } -async function create(factory, is_node_js, worker_path){ +function create(factory, is_node_js, worker_path){ let worker @@ -142,7 +147,9 @@ async function create(factory, is_node_js, worker_path){ typeof module !== "undefined" ? (0,eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') //: (0,eval)('new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/worker/node.mjs")') - : (0,eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")') + //: (0,eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")') + : (0,eval)('import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)(\"import.meta.dirname\") + "/node/node.mjs"); })') + //: import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/worker/node.mjs"); }) //eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') :( @@ -158,4 +165,4 @@ async function create(factory, is_node_js, worker_path){ ); return worker; -} \ No newline at end of file +} diff --git a/src/worker/handler.js b/src/worker/handler.js index df9fdbd..881878c 100644 --- a/src/worker/handler.js +++ b/src/worker/handler.js @@ -24,12 +24,6 @@ export default async function(data) { //options = await import(filepath); } - // deprecated: - // const encode = options.encode; - // if(encode && (encode.indexOf("function") === 0)){ - // options.encode = Function("return " + encode)(); - // } - const factory = data["factory"]; if(factory){ @@ -55,6 +49,10 @@ export default async function(data) { const id = data["id"]; const message = index[task].apply(index, args); - postMessage(task === "search" ? { "id": id, "msg": message } : { "id": id }); + postMessage( + task === "search" + ? { "id": id, "msg": message } + : { "id": id } + ); } }; diff --git a/src/worker/node.js b/src/worker/node.js index a35758d..3898b9a 100644 --- a/src/worker/node.js +++ b/src/worker/node.js @@ -6,7 +6,7 @@ const { Index } = require("../flexsearch.bundle.min.js"); let index; -parentPort.on("message", function(data){ +parentPort.on("message", async function(data){ /** @type Index */ const args = data["args"]; @@ -18,30 +18,26 @@ parentPort.on("message", function(data){ case "init": let options = data["options"] || {}; - // load extern field configuration let filepath = options["config"]; - // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){ - // // current working directory - // const dir = process.cwd(); - // filepath = join(dir, filepath); - // } if(filepath){ - options = require(filepath); + options = Object.assign({}, options, require(filepath)); + delete options.worker; } - // deprecated: - // const encode = options["encode"]; - // if(encode && (encode.indexOf("function") === 0)){ - // options["encode"] = new Function("return " + encode)(); - // } - index = new Index(options); + //index.db && await index.db; + parentPort.postMessage({ "id": id }); + break; default: const message = index[task].apply(index, args); - parentPort.postMessage(task === "search" ? { "id": id, "msg": message } : { "id": id }); + parentPort.postMessage( + task === "search" + ? { "id": id, "msg": message } + : { "id": id } + ); } }); diff --git a/src/worker/node.mjs b/src/worker/node.mjs index 11c9e08..0248f08 100644 --- a/src/worker/node.mjs +++ b/src/worker/node.mjs @@ -1,8 +1,9 @@ import { parentPort } from "worker_threads"; import { join } from "path"; // Test Path -import { Index } from "../../dist/flexsearch.bundle.module.min.js"; -//import { Index } from "../flexsearch.bundle.module.min.js"; +//import Index from "../../src/index.js"; +//import { Index } from "../../dist/flexsearch.bundle.module.min.js"; +import { Index } from "../flexsearch.bundle.module.min.js"; let index; @@ -18,25 +19,27 @@ parentPort.on("message", async function(data){ case "init": let options = data["options"] || {}; - // load extern field configuration let filepath = options["config"]; - // if(filepath && filepath[0] !== "/" && filepath[0] !== "\\"){ - // // current working directory - // const dir = process.cwd(); - // filepath = "file:///" + join(dir, filepath); - // } if(filepath){ - filepath = "file:///" + filepath; - options = await import(filepath); + filepath = join("file://", filepath); + options = Object.assign({}, options, (await import(filepath))["default"]); + delete options.worker; } index = new Index(options); + //index.db && await index.db; + parentPort.postMessage({ "id": id }); + break; default: const message = index[task].apply(index, args); - parentPort.postMessage(task === "search" ? { "id": id, "msg": message } : { "id": id }); + parentPort.postMessage( + task === "search" + ? { "id": id, "msg": message } + : { "id": id } + ); } });