From 4b9900560a715e7b0049f28c96006a17af2afcc4 Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Wed, 12 Mar 2025 21:58:21 +0100 Subject: [PATCH] improve bundle compatibility --- dist/flexsearch.bundle.debug.js | 44 +- dist/flexsearch.bundle.min.js | 18 +- dist/flexsearch.bundle.module.debug.js | 44 +- dist/flexsearch.bundle.module.min.js | 18 +- dist/flexsearch.es5.debug.js | 956 ++++++++++++------------ dist/flexsearch.es5.min.js | 22 +- dist/module-debug/db/indexeddb/index.js | 1 - dist/module-debug/db/postgres/index.js | 3 +- dist/module-debug/document.js | 28 +- dist/module-debug/encoder.js | 5 +- dist/module-debug/worker.js | 23 +- dist/module-debug/worker/handler.js | 2 +- dist/module-min/db/indexeddb/index.js | 2 +- dist/module-min/document.js | 2 +- dist/module-min/worker.js | 2 +- dist/module/db/indexeddb/index.js | 1 - dist/module/db/postgres/index.js | 3 +- dist/module/document.js | 28 +- dist/module/encoder.js | 5 +- dist/module/worker.js | 23 +- dist/module/worker/handler.js | 2 +- src/document.js | 15 +- src/worker.js | 24 +- src/worker/handler.js | 2 +- task/babel.js | 60 +- task/build.js | 21 +- 26 files changed, 712 insertions(+), 642 deletions(-) diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 17603be..cf9e343 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1470,29 +1470,26 @@ async function Na(a) { } ;let Oa = 0; 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); + function b(g) { + function h(k) { + k = k.data || k; + const l = k.id, m = l && e.h[l]; + m && (m(k.msg), delete e.h[l]); } + this.worker = g; this.h = z(); if (this.worker) { - d ? this.worker.on("message", g) : this.worker.onmessage = g; + d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(h) { + return new Promise(function(k) { e.h[++Oa] = function() { - h(e); + k(e); }; e.worker.postMessage({id:Oa, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); - return this.worker; + return this; } } if (!this) { @@ -1500,8 +1497,11 @@ function W(a = {}) { } let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - const d = "undefined" === typeof window, e = this; - this.worker = b.call(this); + const d = "undefined" === typeof window, e = this, f = Pa(c, d, a.worker); + f.worker = !0; + return f.then ? f.then(function(g) { + return b.call(e, g); + }) : b.call(this, f); } X("add"); X("append"); @@ -1522,7 +1522,7 @@ function X(a) { }; } 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"}); + 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 : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js"), {type:"module"}); } ;Y.prototype.add = function(a, b, c) { C(a) && (b = a, a = ca(b, this.key)); @@ -1915,11 +1915,16 @@ function Ta(a) { if (this.worker) { a = []; for (const e of this.index.values()) { - e.worker.then && a.push(e.worker); + e.then && a.push(e); } if (a.length) { const e = this; - return Promise.all(a).then(function() { + return Promise.all(a).then(function(f) { + let g = 0; + for (const h of e.index.entries()) { + const k = h[0]; + h[1].then && e.index.set(k, f[g++]); + } return e; }); } @@ -1979,7 +1984,7 @@ function Wa(a, b) { 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; + c.set(f, h); } 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)); @@ -2182,7 +2187,6 @@ u.clear = function() { 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) { diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index f5a03e2..53aaf64 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -54,11 +54,12 @@ function Ma(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=z();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 c&&f&&f();return}za(a,b||this,c,h,d,e,k,f);return g}; u.import=function(a,b){if(b)switch(B(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; u.serialize=function(a=!0){if(!this.reg.size)return"";let b="",c="";for(var d of this.reg.keys())c||(c=typeof d),b+=(b?",":"")+("string"===c?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let m=0,n;mc||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{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=z();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 c&&f&&f();return}za(a,b||this,c,h,d,e,k,f);return g}; u.import=function(a,b){if(b)switch(B(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; u.serialize=function(a=!0){if(!this.reg.size)return"";let b="",c="";for(var d of this.reg.keys())c||(c=typeof d),b+=(b?",":"")+("string"===c?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let m=0,n;mc||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 c && (c = Math.max(c + e, 0)); c < e; c++) { - var h = d[c]; - if (h === b || Object.is(h, b)) { + var g = d[c]; + if (g === b || Object.is(g, b)) { return !0; } } @@ -830,8 +830,8 @@ function K(a, b, c) { if ("undefined" !== e) { if (c) { if ("function" === e && d === e) { - return function(h) { - return a(c(h)); + return function(g) { + return a(c(g)); }; } 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 h = arguments; + var g = arguments; } else { - h = x(arguments); - for (var f, g = []; !(f = h.next()).done;) { - g.push(f.value); + g = x(arguments); + for (var f, h = []; !(f = g.next()).done;) { + h.push(f.value); } - h = g; + g = h; } - return new (c.call(b, Q, e.call(d, h)))(); + return new (c.call(b, Q, e.call(d, g)))(); } 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 (h) { + } catch (g) { this.split = /\s+/; } this.numeric = d; } else { try { this.split = K(c, Aa, this.split); - } catch (h) { + } catch (g) { this.split = /\s+/; } this.numeric = K(this.numeric, !0); @@ -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, h = 0, f = void 0, g = void 0; h < e.length; h++) { - if ((f = g = e[h]) && !(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, g = 0, f = void 0, h = void 0; g < e.length; g++) { + if ((f = h = e[g]) && !(f.length < this.minlength)) { if (c) { d.push(f); } else { @@ -1036,7 +1036,7 @@ Q.prototype.encode = function(a) { f = f.replace(this.replacer[k], this.replacer[k + 1]); } } - 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)); + 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)); 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(h) { - e.cache.set(a, h); - return h; + d.then(function(g) { + e.cache.set(a, g); + return g; }); } 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], 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++) { + 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++) { } 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 = [], h = 0, f; h < a.index.length; h++) { - if (f = a.index[h], b >= f.length) { + for (var e = [], g = 0, f; g < a.index.length; g++) { + if (f = a.index[g], 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 h = 0, f = 0, g, k; f < b.index.length; f++) { - g = b.index[f]; - k = g.indexOf(e); + for (var g = 0, f = 0, h, k; f < b.index.length; f++) { + h = b.index[f]; + k = h.indexOf(e); if (0 <= k) { - return h + k; + return g + k; } - h += g.length; + g += h.length; } return -1; }; } if ("includes" === d) { return function(e) { - for (var h = 0; h < b.index.length; h++) { - if (b.index[h].includes(e)) { + for (var g = 0; g < b.index.length; g++) { + if (b.index[g].includes(e)) { return !0; } } @@ -1178,13 +1178,13 @@ function S(a) { }; } if ("slice" === d) { - return function(e, h) { - return Qa(b, e || 0, h || b.length, !1); + return function(e, g) { + return Qa(b, e || 0, g || b.length, !1); }; } if ("splice" === d) { - return function(e, h) { - return Qa(b, e || 0, h || b.length, !0); + return function(e, g) { + return Qa(b, e || 0, g || 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, h; + var b, c = this, d, e, g; 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; } - h = e.value; - return F(f, h, 6); + g = e.value; + return F(f, g, 6); case 6: e = d.next(), f.h = 5; } }); }; u.keys = U.prototype.keys = function Ua() { - var b, c = this, d, e, h; + var b, c = this, d, e, g; 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; } - h = e.value; - return F(f, h, 6); + g = e.value; + return F(f, g, 6); case 6: e = d.next(), f.h = 5; } }); }; u.entries = U.prototype.entries = function Va() { - var b, c = this, d, e, h; + var b, c = this, d, e, g; 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; } - h = e.value; - return F(f, h, 6); + g = e.value; + return F(f, g, 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, h, f, g) { +;function Wa(a, b, c, d, e, g, f, h) { (d = a(c ? c + "." + d : d, JSON.stringify(f))) && d.then ? d.then(function() { - b.export(a, b, c, e, h + 1, g); - }) : b.export(a, b, c, e, h + 1, g); + b.export(a, b, c, e, g + 1, h); + }) : b.export(a, b, c, e, g + 1, h); } ;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(), h = L(), f = this.depth, g = this.resolution, k = 0; k < d; k++) { + for (var e = L(), g = L(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { var l = b[this.rtl ? d - 1 - k : k], m = l.length; - if (m && (f || !h[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : $a(g, d, k), p = ""; + if (m && (f || !g[l])) { + var n = this.score ? this.score(b, l, k, null, 0) : $a(h, d, k), p = ""; switch(this.tokenize) { case "full": if (2 < m) { for (n = 0; n < m; n++) { for (var q = m; q > n; q--) { p = l.substring(n, q); - var r = this.score ? this.score(b, l, k, p, n) : $a(g, d, k, m, n); - ab(this, h, p, r, a, c); + 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; @@ -1396,19 +1396,19 @@ 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(g, d, k, m, q), ab(this, h, p, r, a, c); + 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 = ""; } case "forward": if (1 < m) { for (q = 0; q < m; q++) { - p += l[q], ab(this, h, p, n, a, c); + p += l[q], ab(this, g, p, n, a, c); } break; } default: - if (ab(this, h, l, n, a, c), f && 1 < d && k < d - 1) { + if (ab(this, g, 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; @@ -1428,21 +1428,21 @@ V.prototype.add = function(a, b, c, d) { 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; +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 = 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 (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()), h = c.next(); !h.done; h = c.next()) { - h = h.value, h.includes(g) && (h[h.indexOf(g)] = b); + 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] = g = b; + k[d] = h = b; } - g.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(g) : a.reg.set(e, [g])); + h.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); } } } @@ -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 = [], h = 0, f = void 0, g = void 0; h < a.length; h++) { - if ((f = a[h]) && (g = f.length)) { + for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { + if ((f = a[g]) && (h = f.length)) { if (c) { - if (c >= g) { - c -= g; + if (c >= h) { + c -= h; continue; } - c < g && (f = b ? f.slice(c, c + b) : f.slice(c), g = f.length, c = 0); + c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); } if (e.length) { - g > b && (f = f.slice(0, b), g = f.length), e.push(f); + h > b && (f = f.slice(0, b), h = f.length), e.push(f); } else { - if (g >= b) { - return g > b && (f = f.slice(0, b)), d ? cb(f) : f; + if (h >= b) { + return h > b && (f = f.slice(0, b)), d ? cb(f) : f; } e = [f]; } - b -= g; + b -= h; if (!b) { break; } @@ -1500,7 +1500,7 @@ function cb(a) { } var d = []; c = []; - for (var e = 0, h = 0, f, g, k = 0, l = void 0; k < b.length; k++) { + for (var e = 0, g = 0, f, h, 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; - h = l.offset || 0; + g = l.offset || 0; f = l.enrich; - g = l.resolve; + h = 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, h, f, g, a.K); - return g ? a.result : a; + a.result = db(d, e, g, f, h, a.K); + return h ? a.result : a; }); } this.result.length && (d = [this.result].concat(d)); - this.result = db(d, e, h, f, g, a.K); - return g ? this.result : this; + this.result = db(d, e, g, f, h, a.K); + return h ? this.result : this; }; -function db(a, b, c, d, e, h) { +function db(a, b, c, d, e, g) { if (!a.length) { return a; } @@ -1546,19 +1546,19 @@ function db(a, b, c, d, e, h) { return e ? W(a[0], b, c, d) : a[0]; } d = []; - for (var f = 0, g = L(), k = ya(a), l = 0, m; l < k; l++) { + for (var f = 0, h = 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], !g[q]) { - if (g[q] = 1, c) { + if (q = m[p], !h[q]) { + if (h[q] = 1, c) { c--; } else { if (e) { d.push(q); } else { - var r = l + (n ? h : 0); + var r = l + (n ? g : 0); d[r] || (d[r] = []); d[r].push(q); } @@ -1587,8 +1587,8 @@ function db(a, b, c, d, e, h) { } var d = []; c = []; - for (var e = 0, h = 0, f, g = 0, k = void 0; g < b.length; g++) { - if (k = b[g]) { + for (var e = 0, g = 0, f, h = 0, k = void 0; h < b.length; h++) { + if (k = b[h]) { var l = void 0; if (k.constructor === X) { l = k.result; @@ -1604,23 +1604,23 @@ function db(a, b, c, d, e, h) { l = this.not(k.not); } else { e = k.limit || 0; - h = k.offset || 0; + g = k.offset || 0; f = k.resolve; continue; } - d[g] = l; + d[h] = 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, h, f, a.K); + a.result = eb(d, e, g, f, a.K); return f ? a.result : a; }); } d = [this.result].concat(d); - this.result = eb(d, e, h, f, a.K); + this.result = eb(d, e, g, 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 h = [], f = 0, g = L(), k = ya(a); + var g = [], f = 0, h = L(), k = ya(a); if (!k) { - return h; + return g; } 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 = g[t]) { + if (w = h[t]) { if (p = 1, c) { c--; } else { - if (d ? h.push(t) : (w--, r < w && (w = r), h[w] || (h[w] = []), h[w].push(t)), b && ++f === b) { - return h; + if (d ? g.push(t) : (w--, r < w && (w = r), g[w] || (g[w] = []), g[w].push(t)), b && ++f === b) { + return g; } } } - } else if (w = g[t]) { + } else if (w = h[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 []; } - g = n; + h = n; } - return h; + return g; } ;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, h = 0, f, g, k = 0, l = void 0; k < b.length; k++) { + for (var e = 0, g = 0, f, h, 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; - h = l.offset || 0; + g = l.offset || 0; f = l.enrich; - g = l.resolve; + h = 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, h, f, !g, a.K); - return g ? a.result : a; + a.result = fb(d, e, g, f, !h, a.K); + return h ? a.result : a; }); } this.result.length && (d = [this.result].concat(d)); - this.result = fb(d, e, h, f, !g, a.K); - return g ? this.result : this; + this.result = fb(d, e, g, f, !h, a.K); + return h ? this.result : this; }; -function fb(a, b, c, d, e, h) { +function fb(a, b, c, d, e, g) { if (!a.length) { return a; } @@ -1727,8 +1727,8 @@ function fb(a, b, c, d, e, h) { d = 0; for (var f; d < a.length; d++) { if (f = a[d]) { - for (var g = 0, k; g < f.length; g++) { - if (k = f[g]) { + for (var h = 0, k; h < f.length; h++) { + if (k = f[h]) { 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, h) { } for (d = 0; d < a.length; d++) { if (f = a[d]) { - for (g = 0; g < f.length; g++) { - if (k = f[g]) { + for (h = 0; h < f.length; h++) { + if (k = f[h]) { for (l = 0; l < k.length; l++) { if (m = k[l], 1 === c[m]) { if (e) { b.push(m); } else { - var n = g + (d ? h : 0); + var n = h + (d ? g : 0); b[n] || (b[n] = []); b[n].push(m); } @@ -1769,27 +1769,27 @@ function fb(a, b, c, d, e, h) { } var d = []; c = []; - for (var e, h = 0, f = void 0; h < b.length; h++) { - if (f = b[h]) { - var g = void 0; + for (var e, g = 0, f = void 0; g < b.length; g++) { + if (f = b[g]) { + var h = void 0; if (f.constructor === X) { - g = f.result; + h = f.result; } else if (f.constructor === Array) { - g = f; + h = f; } else if (f.index) { - f.resolve = !1, g = f.index.search(f).result; + f.resolve = !1, h = f.index.search(f).result; } else if (f.or) { - g = this.or(f.or); + h = this.or(f.or); } else if (f.and) { - g = this.and(f.and); + h = this.and(f.and); } else if (f.xor) { - g = this.xor(f.xor); + h = this.xor(f.xor); } else { e = f.resolve; continue; } - d[h] = g; - g.then && c.push(g); + d[g] = h; + h.then && c.push(h); } } 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 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))); + 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))); } } } @@ -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 h = a.length, f = [], g; + var g = a.length, f = [], h; var k = L(); for (var l = 0, m = void 0, n; l < b; l++) { - for (var p = 0; p < h; p++) { + for (var p = 0; p < g; p++) { if (n = a[p], l < n.length && (m = n[l])) { for (var q = 0; q < m.length; q++) { - n = m[q], (g = k[n]) ? k[n]++ : (g = 0, k[n] = 1), g = f[g] || (f[g] = []), g.push(n); + n = m[q], (h = k[n]) ? k[n]++ : (h = 0, k[n] = 1), h = f[h] || (f[h] = []), h.push(n); } } } @@ -1879,7 +1879,7 @@ function ib(a, b, c, d, e) { if (e) { if (1 < f.length) { e = f; - h = []; + g = []; 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 (h.push(b), h.length === c) { + if (g.push(b), g.length === c) { break; } } } } } - c = h; + c = g; } else { c = f[0]; } f = c; } else { - if (a < h) { + if (a < g) { 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, h; e < b.length; e++) { - h = b[e]; - for (var f = 0; f < h.length; f++) { - c[h[f]] = 1; + 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 (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, h; + var d = [], e = 0, g; if (c) { a = c.query || a; b = c.limit || b; e = c.offset || 0; var f = c.context; - var g = c.suggest; - (h = hb && !1 !== c.resolve) || (hb = 0); - var k = h && c.enrich; + var h = c.suggest; + (g = hb && !1 !== c.resolve) || (hb = 0); + var k = g && c.enrich; var l = this.db && c.tag; } else { - h = this.resolve || hb; + g = this.resolve || hb; } a = this.encoder.encode(a); var m = a.length; - b || !h || (b = 100); + b || !g || (b = 100); if (1 === m) { - return kb.call(this, a[0], "", b, e, h, k, l); + return kb.call(this, a[0], "", b, e, g, k, l); } f = this.depth && !1 !== f; - if (2 === m && f && !g) { - return kb.call(this, a[0], a[1], b, e, h, k, l); + if (2 === m && f && !h) { + return kb.call(this, a[0], a[1], b, e, g, 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 (g || this.db || Y(this, y)) { + if (h || this.db || Y(this, y)) { q.push(y), p[y] = 1; } else { - return h ? d : new X(d); + return g ? 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 h ? d : new X(d); + return g ? d : new X(d); } var v = 0; if (1 === m) { - return kb.call(this, a[0], "", b, e, h, k, l); + return kb.call(this, a[0], "", b, e, g, k, l); } - if (2 === m && f && !g) { - return kb.call(this, a[0], a[1], b, e, h, k, l); + if (2 === m && f && !h) { + return kb.call(this, a[0], a[1], b, e, g, 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, g, h, k, l), !1 !== f)) { + if (this.db.search && (f = this.db.search(this, a, b, e, h, g, k, l), !1 !== f)) { return f; } var w = this; @@ -2005,16 +2005,16 @@ V.prototype.search = function(a, b, c) { 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.F; - A = lb(A, d, g, w.resolution); + A = lb(A, d, h, w.resolution); E.h = 6; break; case 8: - A = E.F, A = lb(A, d, g, w.aa), g && !1 === A && d.length || (t = D); + A = E.F, A = lb(A, d, h, w.aa), h && !1 === A && d.length || (t = D); case 6: if (A) { return E.return(A); } - if (g && v === m - 1) { + if (h && 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(h ? W(d[0], b, e) : new X(d[0])); + return E.return(g ? 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(h ? ib(d, w.resolution, b, e, g) : new X(d[0])); + return E.return(g ? ib(d, w.resolution, b, e, h) : new X(d[0])); } }); }(); } for (k = f = void 0; v < m; v++) { k = a[v]; - 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)); + t ? (f = Y(this, k, t, 0, 0, !1, !1), f = lb(f, d, h, this.aa), h && !1 === f && d.length || (t = k)) : (f = Y(this, k, "", 0, 0, !1, !1), f = lb(f, d, h, this.resolution)); if (f) { return f; } - if (g && v === m - 1) { + if (h && v === m - 1) { f = d.length; if (!f) { if (t) { @@ -2056,25 +2056,25 @@ V.prototype.search = function(a, b, c) { return d; } if (1 === f) { - return h ? W(d[0], b, e) : new X(d[0]); + return g ? W(d[0], b, e) : new X(d[0]); } } } - d = ib(d, this.resolution, b, e, g); - return h ? d : new X(d); + d = ib(d, this.resolution, b, e, h); + return g ? d : new X(d); }; -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([]); +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([]); }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); } function lb(a, b, c, d) { var e = []; if (a) { d = Math.min(a.length, d); - for (var h = 0, f = void 0; h < d; h++) { - (f = a[h]) && f && (e[h] = f); + for (var g = 0, f = void 0; g < d; g++) { + (f = a[g]) && f && (e[g] = f); } if (e.length) { b.push(e); @@ -2083,11 +2083,11 @@ function lb(a, b, c, d) { } return !c && e; } -function Y(a, b, c, d, e, h, f, g) { +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, h, f, g) : a.db.get(b, "", d, e, h, f, g); + 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; @@ -2101,8 +2101,8 @@ function Y(a, b, c, d, e, h, f, g) { if (2 > e.length) { e.pop(); } else { - var h = e.indexOf(a); - h === c.length - 1 ? e.pop() : e.splice(h, 1); + var g = e.indexOf(a); + g === c.length - 1 ? e.pop() : e.splice(g, 1); } } } @@ -2118,10 +2118,10 @@ function Y(a, b, c, d, e, h, f, g) { function mb(a, b) { var c = 0; if (a.constructor === Array) { - for (var d = 0, e = void 0, h; d < a.length; d++) { + for (var d = 0, e = void 0, g; d < a.length; d++) { if ((e = a[d]) && e.length) { - if (h = e.indexOf(b), 0 <= h) { - 1 < e.length ? (e.splice(h, 1), c++) : delete a[d]; + if (g = e.indexOf(b), 0 <= g) { + 1 < e.length ? (e.splice(g, 1), c++) : delete a[d]; break; } else { c++; @@ -2130,7 +2130,7 @@ function mb(a, b) { } } else { for (d = x(a), e = d.next(); !e.done; e = d.next()) { - h = e.value, e = h[0], (h = mb(h[1], b)) ? c += h : a.delete(e); + g = e.value, e = g[0], (g = mb(g[1], b)) ? c += g : a.delete(e); } } return c; @@ -2233,14 +2233,14 @@ u.cleanup = function() { return this; }; u.searchCache = Ga; -u.export = function(a, b, c, d, e, h) { +u.export = function(a, b, c, d, e, g) { var f = !0; - "undefined" === typeof h && (f = new Promise(function(n) { - h = n; + "undefined" === typeof g && (f = new Promise(function(n) { + g = n; })); switch(e || (e = 0)) { case 0: - var g = "reg"; + var h = "reg"; if (this.fastupdate) { var k = L(); for (var l = x(this.reg.keys()), m = l.next(); !m.done; m = l.next()) { @@ -2251,22 +2251,22 @@ u.export = function(a, b, c, d, e, h) { } break; case 1: - g = "cfg"; + h = "cfg"; k = {doc:0, opt:this.h ? 1 : 0}; break; case 2: - g = "map"; + h = "map"; k = this.map; break; case 3: - g = "ctx"; + h = "ctx"; k = this.ctx; break; default: - "undefined" === typeof c && h && h(); + "undefined" === typeof c && g && g(); return; } - Wa(a, b || this, c, g, d, e, k, h); + Wa(a, b || this, c, h, d, e, k, g); return f; }; u.import = function(a, b) { @@ -2298,26 +2298,26 @@ u.serialize = function(a) { b = "index.reg=new Set([" + b + "]);"; d = ""; e = x(this.map.entries()); - for (var h = e.next(); !h.done; h = e.next()) { - var f = h.value; - h = f[0]; + for (var g = e.next(); !g.done; g = e.next()) { + var f = g.value; + g = f[0]; f = f[1]; - for (var g = "", k = 0, l; k < f.length; k++) { + for (var h = "", 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 + "]"; - g += (g ? "," : "") + m; + h += (h ? "," : "") + m; } - g = '["' + h + '",[' + g + "]]"; - d += (d ? "," : "") + g; + h = '["' + g + '",[' + h + "]]"; + d += (d ? "," : "") + h; } d = "index.map=new Map([" + d + "]);"; e = ""; - 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()) { + 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()) { l = k.value; k = l[0]; l = l[1]; @@ -2341,7 +2341,7 @@ u.serialize = function(a) { }; Ya(V.prototype); function ob(a) { - var b, c, d, e, h, f, g, k; + var b, c, d, e, g, f, h, k; return H(function(l) { a = a.data; b = self._index; @@ -2350,41 +2350,38 @@ function ob(a) { switch(d) { case "init": e = a.options || {}; - (h = e.config) && (e = h); + (g = e.config) && (e = g); (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: - g = a.id, k = b[d].apply(b, c), postMessage("search" === d ? {id:g, msg:k} : {id:g}); + h = a.id, k = b[d].apply(b, c), postMessage("search" === d ? {id:h, msg:k} : {id:h}); } 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); + function b(f) { + function h(k) { + k = k.data || k; + var l = k.id, m = l && e.h[l]; + m && (m(k.msg), delete e.h[l]); } + this.worker = f; this.h = L(); if (this.worker) { - d ? this.worker.on("message", f) : this.worker.onmessage = f; + d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { - return new Promise(function(g) { + return new Promise(function(k) { e.h[++pb] = function() { - g(e); + k(e); }; e.worker.postMessage({id:pb, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); - return this.worker; + return this; } } a = void 0 === a ? {} : a; @@ -2393,8 +2390,11 @@ function qb(a) { } var c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - var d = "undefined" === typeof window, e = this; - this.worker = b.call(this); + var d = "undefined" === typeof window, e = this, g = rb(c, d, a.worker); + g.worker = !0; + return g.then ? g.then(function(f) { + return b.call(e, f); + }) : b.call(this, g); } sb("add"); sb("append"); @@ -2403,22 +2403,22 @@ sb("update"); sb("remove"); function sb(a) { qb.prototype[a] = qb.prototype[a + "Async"] = function() { - var b = this, c = arguments, d, e, h, f, g; + var b = this, c = arguments, d, e, g, f, h; 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) { + g = e[e.length - 1]; + "function" === typeof g && (f = g, e.splice(e.length - 1, 1)); + h = 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 f ? (h.then(f), k.return(b)) : k.return(h); }); }; } function rb(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=" + ob.toString()], {type:"text/javascript"}))) : new window.Worker(M(c) ? c : "worker/worker.js", {type:"module"}); + 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 : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js"), {type:"module"}); } ;Z.prototype.add = function(a, b, c) { N(a) && (b = a, a = xa(b, this.key)); @@ -2428,21 +2428,21 @@ function rb(a, b, c) { } for (var d = 0, e; d < this.field.length; d++) { e = this.M[d]; - var h = this.index.get(this.field[d]); + var g = this.index.get(this.field[d]); if ("function" === typeof e) { - (e = e(b)) && h.add(a, e, !1, !0); + (e = e(b)) && g.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, h, a, e[0], c); + e.constructor === String ? e = ["" + e] : M(e) && (e = [e]), tb(b, e, this.T, 0, g, a, e[0], c); } } } if (this.tag) { for (d = 0; d < this.L.length; d++) { f = this.L[d]; - var g = this.$[d]; - h = this.tag.get(g); + var h = this.$[d]; + g = this.tag.get(h); e = L(); if ("function" === typeof f) { if (f = f(b), !f) { @@ -2456,13 +2456,13 @@ function rb(a, b, c) { f.constructor === String && (f = "" + f); f = xa(b, f); } - if (h && f) { - for (M(f) && (f = [f]), g = 0, k = void 0; g < f.length; g++) { - var l = f[g]; + if (g && f) { + for (M(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { + var l = f[h]; if (!e[l]) { e[l] = 1; var m; - (m = h.get(l)) ? k = m : h.set(l, k = []); + (m = g.get(l)) ? k = m : g.set(l, k = []); if (!c || !k.includes(a)) { if (k.length === Math.pow(2, 31) - 1) { m = new S(k); @@ -2471,7 +2471,7 @@ function rb(a, b, c) { p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); } } - h.set(l, k = m); + g.set(l, k = m); } k.push(a); this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); @@ -2479,7 +2479,7 @@ function rb(a, b, c) { } } } else { - h || console.warn("Tag '" + g + "' was not found"); + g || console.warn("Tag '" + h + "' was not found"); } } } @@ -2487,11 +2487,11 @@ function rb(a, b, c) { if (this.H) { var q = L(); for (c = 0; c < this.H.length; c++) { - if (d = this.H[c], h = d.R, !h || h(b)) { - h = void 0; + if (d = this.H[c], g = d.R, !g || g(b)) { + g = void 0; if ("function" === typeof d) { - h = d(b); - if (!h) { + g = d(b); + if (!g) { continue; } d = [d.la]; @@ -2499,7 +2499,7 @@ function rb(a, b, c) { q[d] = b[d]; continue; } - ub(b, q, d, 0, d[0], h); + ub(b, q, d, 0, d[0], g); } } } @@ -2508,10 +2508,10 @@ function rb(a, b, c) { } return this; }; -function ub(a, b, c, d, e, h) { +function ub(a, b, c, d, e, g) { a = a[e]; if (d === c.length - 1) { - b[e] = h || a; + b[e] = g || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { @@ -2522,41 +2522,41 @@ function ub(a, b, c, d, e, h) { } } } -function tb(a, b, c, d, e, h, f, g) { +function tb(a, b, c, d, e, g, f, h) { 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(h, a[b], !0, !0); + e.add(g, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(h, a, g, !0); + e.add(g, a, h, !0); } else { if (a.constructor === Array) { for (f = 0; f < a.length; f++) { - tb(a, b, c, d, e, h, f, g); + tb(a, b, c, d, e, g, f, h); } } else { - f = b[++d], tb(a, b, c, d, e, h, f, g); + f = b[++d], tb(a, b, c, d, e, g, f, h); } } } else { - e.db && e.remove(h); + e.db && e.remove(g); } } ;Z.prototype.search = function(a, b, c, d) { c || (!b && N(a) ? (c = a, a = "") : N(b) && (c = b, b = 0)); - var e = [], h = [], f = 0; + var e = [], g = [], f = 0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; - var g = c.pluck; + var h = c.pluck; var k = c.merge; - var l = g || c.field || c.index; + var l = h || c.field || c.index; var m = this.tag && c.tag; var n = this.store && c.enrich; var p = c.suggest; @@ -2598,24 +2598,24 @@ function tb(a, b, c, d, e, h, f, g) { } m = r; if (!a) { - h = []; + g = []; if (r.length) { - for (g = 0; g < r.length; g += 2) { + for (h = 0; h < r.length; h += 2) { p = void 0; if (this.db) { - p = this.index.get(r[g]); + p = this.index.get(r[h]); if (!p) { - console.warn("Tag '" + r[g] + ":" + r[g + 1] + "' will be skipped because there is no field '" + r[g] + "'."); + console.warn("Tag '" + r[h] + ":" + r[h + 1] + "' will be skipped because there is no field '" + r[h] + "'."); continue; } - h.push(p = p.db.tag(r[g + 1], b, q, n)); + g.push(p = p.db.tag(r[h + 1], b, q, n)); } else { - p = vb.call(this, r[g], r[g + 1], b, q, n); + p = vb.call(this, r[h], r[h + 1], b, q, n); } - e.push({field:r[g], tag:r[g + 1], result:p}); + e.push({field:r[h], tag:r[h + 1], result:p}); } } - return h.length ? Promise.all(h).then(function(O) { + return g.length ? Promise.all(g).then(function(O) { for (var P = 0; P < O.length; P++) { e[P].result = O[P]; } @@ -2696,7 +2696,7 @@ function tb(a, b, c, d, e, h, f, g) { } } if (w) { - h[f] = v, e.push(t), f++; + g[f] = v, e.push(t), f++; } else if (1 === l.length) { return e; } @@ -2705,15 +2705,15 @@ function tb(a, b, c, d, e, h, f, g) { if (r) { if (this.db && m && m.length && !E) { for (n = 0; n < m.length; n += 2) { - h = this.index.get(m[n]); - if (!h) { + g = this.index.get(m[n]); + if (!g) { if (console.warn("Tag '" + m[n] + ":" + m[n + 1] + "' was not found because there is no field '" + m[n] + "'."), p) { continue; } else { return e; } } - r.push(h.db.tag(m[n + 1], b, q, !1)); + r.push(g.db.tag(m[n + 1], b, q, !1)); } } var Ib = this; @@ -2724,18 +2724,18 @@ function tb(a, b, c, d, e, h, f, g) { if (!f) { return e; } - if (g && (!n || !this.store)) { + if (h && (!n || !this.store)) { return e[0]; } r = []; q = 0; - for (p = void 0; q < h.length; q++) { + for (p = void 0; q < g.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 (g) { + if (h) { return p; } - e[q] = {field:h[q], result:p}; + e[q] = {field:g[q], result:p}; } return n && this.db && r.length ? Promise.all(r).then(function(O) { for (var P = 0; P < O.length; P++) { @@ -2745,17 +2745,17 @@ function tb(a, b, c, d, e, h, f, g) { }) : k ? xb(e, b) : e; }; function xb(a, b) { - 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); + 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); } else { if (c.length === b) { return c; } - l.field = d[k] = [h.field]; + l.field = d[k] = [g.field]; c.push(l); } } @@ -2763,16 +2763,16 @@ function xb(a, b) { return c; } function vb(a, b, c, d, e) { - var h = this.tag.get(a); - if (!h) { + var g = this.tag.get(a); + if (!g) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (h = h && h.get(b)) && h.length - d) && 0 < a) { + if ((a = (g = g && g.get(b)) && g.length - d) && 0 < a) { if (a > c || d) { - h = h.slice(d, d + c); + g = g.slice(d, d + c); } - e && (h = wb.call(this, h)); - return h; + e && (g = wb.call(this, g)); + return g; } } function wb(a) { @@ -2821,12 +2821,17 @@ function wb(a) { 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); + b = b.value, b.then && a.push(b); } if (a.length) { - var h = this; - return Promise.all(a).then(function() { - return h; + var g = this; + return Promise.all(a).then(function(f) { + for (var h = 0, k = x(g.index.entries()), l = k.next(); !l.done; l = k.next()) { + l = l.value; + var m = l[0]; + l[1].then && g.index.set(m, f[h++]); + } + return g; }); } } else { @@ -2849,31 +2854,31 @@ u.mount = function(a) { c = []; d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; e = 0; - for (var h; e < b.length; e++) { - d.field = h = b[e]; - h = this.index.get(h); + for (var g; e < b.length; e++) { + d.field = g = b[e]; + g = this.index.get(g); var f = new a.constructor(a.id, d); f.id = a.id; - c[e] = f.mount(h); - h.document = !0; - e ? h.bypass = !0 : h.store = this.store; + c[e] = f.mount(g); + g.document = !0; + e ? g.bypass = !0 : g.store = this.store; } this.db = !0; return Promise.all(c); }; u.commit = function(a, b) { - var c = this, d, e, h, f; - return H(function(g) { - if (1 == g.h) { + var c = this, d, e, g, f; + return H(function(h) { + if (1 == h.h) { d = []; e = x(c.index.values()); - for (h = e.next(); !h.done; h = e.next()) { - f = h.value, d.push(f.db.commit(f, a, b)); + for (g = e.next(); !g.done; g = e.next()) { + f = g.value, d.push(f.db.commit(f, a, b)); } - return F(g, Promise.all(d), 2); + return F(h, Promise.all(d), 2); } c.reg.clear(); - g.h = 0; + h.h = 0; }); }; u.destroy = function() { @@ -2885,17 +2890,17 @@ u.destroy = function() { 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); + 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 g = new qb(f); - g.worker ? c.set(h, g) : this.worker = !1; + var h = new qb(f); + c.set(g, h); } - 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; + 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 (a = b.store, M(a) && (a = [a]), b = 0; b < a.length; b++) { @@ -2927,11 +2932,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 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)); + 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)); } } } @@ -2972,35 +2977,35 @@ u.set = function(a, b) { return this; }; u.searchCache = Ga; -u.export = function(a, b, c, d, e, h) { +u.export = function(a, b, c, d, e, g) { var f; - "undefined" === typeof h && (f = new Promise(function(k) { - h = k; + "undefined" === typeof g && (f = new Promise(function(k) { + g = k; })); e || (e = 0); d || (d = 0); if (d < this.field.length) { c = this.field[d]; - var g = this.index[c]; + var h = this.index[c]; b = this; - g.export(a, b, e ? c : "", d, e++, h) || (d++, b.export(a, b, c, d, 1, h)); + h.export(a, b, e ? c : "", d, e++, g) || (d++, b.export(a, b, c, d, 1, g)); } else { switch(e) { case 1: b = "tag"; - g = this.A; + h = this.A; c = null; break; case 2: b = "store"; - g = this.store; + h = this.store; c = null; break; default: - h(); + g(); return; } - Wa(a, this, c, b, d, e, g, h); + Wa(a, this, c, b, d, e, h, g); } return f; }; @@ -3056,8 +3061,8 @@ u.open = function() { var d = Ab.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { var e = a.db = this.result; - Bb.forEach(function(h) { - e.objectStoreNames.contains(h) || e.createObjectStore(h); + Bb.forEach(function(g) { + e.objectStoreNames.contains(g) || e.createObjectStore(g); }); }; d.onblocked = function(e) { @@ -3090,25 +3095,24 @@ u.clear = function() { } return Db(a); }; -u.get = function(a, b, c, d, e, h) { +u.get = function(a, b, c, d, e, g) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; e = void 0 === e ? !0 : e; - h = void 0 === h ? !1 : h; - console.log("!!!!!!!!!!!"); + g = void 0 === g ? !1 : g; a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); var f = this; - return Db(a).then(function(g) { + return Db(a).then(function(h) { var k = []; - if (!g || !g.length) { + if (!h || !h.length) { return k; } if (e) { - if (!c && !d && 1 === g.length) { - return g[0]; + if (!c && !d && 1 === h.length) { + return h[0]; } - for (var l = 0, m = void 0; l < g.length; l++) { - if ((m = g[l]) && m.length) { + for (var l = 0, m = void 0; l < h.length; l++) { + if ((m = h[l]) && m.length) { if (d >= m.length) { d -= m.length; } else { @@ -3122,9 +3126,9 @@ u.get = function(a, b, c, d, e, h) { } } } - return h ? f.enrich(k) : k; + return g ? f.enrich(k) : k; } - return g; + return h; }); }; u.tag = function(a, b, c, d) { @@ -3133,15 +3137,15 @@ 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 Db(a).then(function(h) { - if (!h || !h.length || c >= h.length) { + return Db(a).then(function(g) { + if (!g || !g.length || c >= g.length) { return []; } if (!b && !c) { - return h; + return g; } - h = h.slice(c, c + b); - return d ? e.enrich(h) : h; + g = g.slice(c, c + b); + return d ? e.enrich(g) : g; }); }; u.enrich = function(a) { @@ -3150,8 +3154,8 @@ u.enrich = function(a) { c[d] = Db(b.get(a[d])); } return Promise.all(c).then(function(e) { - for (var h = 0; h < e.length; h++) { - e[h] = {id:a[h], doc:e[h] ? JSON.parse(e[h]) : null}; + for (var g = 0; g < e.length; g++) { + e[g] = {id:a[g], doc:e[g] ? JSON.parse(e[g]) : null}; } return e; }); @@ -3168,73 +3172,73 @@ u.transaction = function(a, b, c) { if (e) { return c.call(this, e); } - 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) { + 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) { d.h[a + ":" + b] = null; - h.abort(); - h = e = null; - g(k); + g.abort(); + g = e = null; + h(k); }; - h.oncomplete = function(k) { - h = e = d.h[a + ":" + b] = null; + g.oncomplete = function(k) { + g = e = d.h[a + ":" + b] = null; f(k || !0); }; return c.call(d, e); }); }; u.commit = function(a, b, c) { - var d = this, e, h, f; - return H(function(g) { - switch(g.h) { + var d = this, e, g, f; + return H(function(h) { + switch(h.h) { case 1: if (b) { - return F(g, d.clear(), 12); + return F(h, d.clear(), 12); } e = a.commit_task; a.commit_task = []; - h = 0; + g = 0; f = void 0; case 4: - if (!(h < e.length)) { - g.h = 6; + if (!(g < e.length)) { + h.h = 6; break; } - f = e[h]; + f = e[g]; if (!f.clear) { - e[h] = f.oa; - g.h = 5; + e[g] = f.oa; + h.h = 5; break; } - return F(g, d.clear(), 8); + return F(h, d.clear(), 8); case 8: b = !0; - g.h = 6; + h.h = 6; break; case 5: - h++; - g.h = 4; + g++; + h.h = 4; break; case 6: if (b) { - g.h = 3; + h.h = 3; break; } c || (e = e.concat(wa(a.reg))); if (!e.length) { - g.h = 10; + h.h = 10; break; } - return F(g, d.remove(e), 11); + return F(h, d.remove(e), 11); case 11: case 10: - g.h = 3; + h.h = 3; break; case 12: a.commit_task = []; case 3: - return a.reg.size ? F(g, d.transaction("map", "readwrite", function(k) { + return a.reg.size ? F(h, 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() { @@ -3259,9 +3263,9 @@ u.commit = function(a, b, c) { }; }(n)); } - }), 13) : g.return(); + }), 13) : h.return(); case 13: - return F(g, d.transaction("ctx", "readwrite", function(k) { + return F(h, 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]; @@ -3294,7 +3298,7 @@ u.commit = function(a, b, c) { }), 14); case 14: if (a.store) { - return F(g, d.transaction("reg", "readwrite", function(k) { + return F(h, 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]; @@ -3304,20 +3308,20 @@ u.commit = function(a, b, c) { }), 16); } if (a.bypass) { - g.h = 16; + h.h = 16; break; } - return F(g, d.transaction("reg", "readwrite", function(k) { + return F(h, 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) { - g.h = 20; + h.h = 20; break; } - return F(g, d.transaction("tag", "readwrite", function(k) { + 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, 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() { @@ -3329,19 +3333,19 @@ u.commit = function(a, b, c) { } }), 20); case 20: - a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), g.h = 0; + a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), h.h = 0; } }); }; 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 d = a.value, e, g, f = 0, h = 0, k; h < d.length; h++) { + if (k = c ? d : d[h]) { for (var l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = k.indexOf(h ? parseInt(n, 10) : n), 0 > m && !h && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (h = 1), 0 <= m) { + if (n = b[l], m = k.indexOf(g ? parseInt(n, 10) : n), 0 > m && !g && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (g = 1), 0 <= m) { if (e = 1, 1 < k.length) { k.splice(m, 1); } else { - d[g] = []; + d[h] = []; break; } } diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 2033634..712e849 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -86,11 +86,12 @@ u.export=function(a,b,c,d,e,h){var f=!0;"undefined"===typeof h&&(f=new Promise(f u.import=function(a,b){if(b)switch(M(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; u.serialize=function(a){a=void 0===a?!0:a;if(!this.reg.size)return"";for(var b="",c="",d=x(this.reg.keys()),e=d.next();!e.done;e=d.next())e=e.value,c||(c=typeof e),b+=(b?",":"")+("string"===c?'"'+e+'"':e);b="index.reg=new Set(["+b+"]);";d="";e=x(this.map.entries());for(var h=e.next();!h.done;h=e.next()){var f=h.value;h=f[0];f=f[1];for(var g="",k=0,l;kc||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=h.length)return[];if(!b&&!c)return h;h=h.slice(c,c+b);return d?e.enrich(h):h})}; +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;h=void 0===h?!1:h;a=this.db.transaction(b?"ctx":"map","readonly").objectStore(b?"ctx":"map").get(b?b+":"+a:a);var f=this;return Db(a).then(function(g){var k=[];if(!g||!g.length)return k;if(e){if(!c&&!d&&1===g.length)return g[0];for(var l=0,m=void 0;l=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;d this.matcher.get(match)); - // } + // if(this.stemmer){ // this.stemmer_test || ( // this.stemmer_test = new RegExp("(?!\\b)(" + this.stemmer_str + ")(\\b|_)", "g") diff --git a/dist/module-debug/worker.js b/dist/module-debug/worker.js index 4079eb6..3a9d658 100644 --- a/dist/module-debug/worker.js +++ b/dist/module-debug/worker.js @@ -26,17 +26,11 @@ export default function WorkerIndex(options = {}) { _self = this; /** - * @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); - } + function init(worker) { + this.worker = worker; this.resolver = create_object(); if (!this.worker) { @@ -58,8 +52,6 @@ export default function WorkerIndex(options = {}) { if (options.config) { - //delete options.db; - // when extern configuration needs to be loaded // it needs to return a promise to await for return new Promise(function (resolve) { @@ -83,10 +75,15 @@ export default function WorkerIndex(options = {}) { options: options }); - return this.worker; + return this; } - this.worker = init.call(this); + const worker = create(factory, is_node_js, options.worker); + worker.worker = /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice: + !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; + return worker.then ? worker.then(function (worker) { + return init.call(_self, worker); + }) : init.call(this, worker); } register("add"); @@ -142,7 +139,7 @@ function create(factory, is_node_js, worker_path) { //: 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" }); + : factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker(is_string(worker_path) ? worker_path : import.meta.url.replace("/worker.js", "/worker/worker.js") /*"worker/worker.js"*/, { type: "module" }); return worker; } \ No newline at end of file diff --git a/dist/module-debug/worker/handler.js b/dist/module-debug/worker/handler.js index f918d7d..8bc5fc1 100644 --- a/dist/module-debug/worker/handler.js +++ b/dist/module-debug/worker/handler.js @@ -23,7 +23,7 @@ export default (async function (data) { 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); + options = (await import(filepath))["default"]; } const factory = data.factory; diff --git a/dist/module-min/db/indexeddb/index.js b/dist/module-min/db/indexeddb/index.js index 9c9ffd4..ccbd409 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 9eccb12..da5d100 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;d this.matcher.get(match)); - // } + // if(this.stemmer){ // this.stemmer_test || ( // this.stemmer_test = new RegExp("(?!\\b)(" + this.stemmer_str + ")(\\b|_)", "g") diff --git a/dist/module/worker.js b/dist/module/worker.js index 4079eb6..3a9d658 100644 --- a/dist/module/worker.js +++ b/dist/module/worker.js @@ -26,17 +26,11 @@ export default function WorkerIndex(options = {}) { _self = this; /** - * @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); - } + function init(worker) { + this.worker = worker; this.resolver = create_object(); if (!this.worker) { @@ -58,8 +52,6 @@ export default function WorkerIndex(options = {}) { if (options.config) { - //delete options.db; - // when extern configuration needs to be loaded // it needs to return a promise to await for return new Promise(function (resolve) { @@ -83,10 +75,15 @@ export default function WorkerIndex(options = {}) { options: options }); - return this.worker; + return this; } - this.worker = init.call(this); + const worker = create(factory, is_node_js, options.worker); + worker.worker = /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice: + !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/; + return worker.then ? worker.then(function (worker) { + return init.call(_self, worker); + }) : init.call(this, worker); } register("add"); @@ -142,7 +139,7 @@ function create(factory, is_node_js, worker_path) { //: 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" }); + : factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker(is_string(worker_path) ? worker_path : import.meta.url.replace("/worker.js", "/worker/worker.js") /*"worker/worker.js"*/, { type: "module" }); return worker; } \ No newline at end of file diff --git a/dist/module/worker/handler.js b/dist/module/worker/handler.js index f918d7d..8bc5fc1 100644 --- a/dist/module/worker/handler.js +++ b/dist/module/worker/handler.js @@ -23,7 +23,7 @@ export default (async function (data) { 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); + options = (await import(filepath))["default"]; } const factory = data.factory; diff --git a/src/document.js b/src/document.js index 88e8346..ff815d0 100644 --- a/src/document.js +++ b/src/document.js @@ -128,14 +128,21 @@ export default function Document(options){ } } + // resolve worker promises and swap instances if(SUPPORT_WORKER && this.worker){ const promises = []; for(const index of this.index.values()){ - index.worker.then && promises.push(index.worker); + index.then && promises.push(index); } if(promises.length){ const self = this; - return Promise.all(promises).then(function(){ + return Promise.all(promises).then(function(promises){ + let count = 0; + for(const item of self.index.entries()){ + const key = item[0]; + const index = item[1]; + index.then && self.index.set(key, promises[count++]); + } return self; }); } @@ -259,7 +266,9 @@ function parse_descriptor(options, document){ if(SUPPORT_WORKER && this.worker){ const worker = new WorkerIndex(opt); - if(worker.worker){ + if(worker){ + // worker could be a promise + // it needs to be resolved and swapped later index.set(key, worker); } else{ diff --git a/src/worker.js b/src/worker.js index 72d5eb8..b5c640d 100644 --- a/src/worker.js +++ b/src/worker.js @@ -30,17 +30,11 @@ export default function WorkerIndex(options = {}){ const _self = this; /** - * @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); - } + function init(worker){ + this.worker = worker; this.resolver = create_object(); if(!this.worker){ @@ -63,8 +57,6 @@ export default function WorkerIndex(options = {}){ if(options.config){ - //delete options.db; - // when extern configuration needs to be loaded // it needs to return a promise to await for return new Promise(function(resolve){ @@ -88,10 +80,16 @@ export default function WorkerIndex(options = {}){ "options": options }); - return this.worker; + return this; } - this.worker = init.call(this); + const worker = create(factory, is_node_js, options.worker); + worker.worker = true; + return worker.then + ? worker.then(function(worker){ + return init.call(_self, worker); + }) + : init.call(this, worker); } register("add"); @@ -161,7 +159,7 @@ function create(factory, is_node_js, worker_path){ ) )) : - new window.Worker(is_string(worker_path) ? worker_path : "worker/worker.js", { type: "module" }) + new window.Worker(is_string(worker_path) ? worker_path : import.meta.url.replace("/worker.js", "/worker/worker.js") /*"worker/worker.js"*/, { type: "module" }) ); return worker; diff --git a/src/worker/handler.js b/src/worker/handler.js index 881878c..da2922b 100644 --- a/src/worker/handler.js +++ b/src/worker/handler.js @@ -21,7 +21,7 @@ export default async function(data) { 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); + options = (await import(filepath))["default"]; } const factory = data["factory"]; diff --git a/task/babel.js b/task/babel.js index 644d9b0..2c0c79a 100644 --- a/task/babel.js +++ b/task/babel.js @@ -17,6 +17,10 @@ fs.existsSync("dist") || fs.mkdirSync("dist"); if(file.endsWith(".js")){ let src = fs.readFileSync("src/" + file, "utf8"); src = src.replace(/\/\/ COMPILER BLOCK -->(.*)<-- COMPILER BLOCK/gs, ""); + if(file === "worker.js"){ + // add the eval wrapper + src = src.replace("import.meta.url", '(1,eval)("import.meta.url")'); + } fs.writeFileSync("tmp/" + file, src); } }); @@ -25,24 +29,28 @@ fs.existsSync("dist") || fs.mkdirSync("dist"); fs.existsSync("./tmp/lang") || fs.mkdirSync("./tmp/lang/"); fs.existsSync("./tmp/charset") || fs.mkdirSync("./tmp/charset/"); - ["db/", - "db/clickhouse", - "db/indexeddb", - "db/mongodb", - "db/postgres", - "db/redis", - "db/sqlite", - "document", - "index", - "resolve", - "worker", - "lang", - "charset/", - "charset/latin", - "charset/arabic", - "charset/cjk", - "charset/cyrillic" - ].forEach(await async function(path){ + const dirs = [ + "db/", + "db/clickhouse", + "db/indexeddb", + "db/mongodb", + "db/postgres", + "db/redis", + "db/sqlite", + "document", + "index", + "resolve", + "worker", + "lang", + "charset/", + "charset/latin", + "charset/arabic", + "charset/cjk", + "charset/cyrillic" + ]; + + for(let i = 0, path; i < dirs.length; i++){ + path = dirs[i]; fs.existsSync("./tmp/" + path + "/") || fs.mkdirSync("./tmp/" + path + "/"); files = await fs.promises.readdir("./src/" + path + "/"); files.forEach(function(file){ @@ -51,10 +59,14 @@ fs.existsSync("dist") || fs.mkdirSync("dist"); if(file.endsWith(".js")){ let src = fs.readFileSync("src/" + path + "/" + file, "utf8"); src = src.replace(/\/\/ COMPILER BLOCK -->(.*)<-- COMPILER BLOCK/gs, ""); + if(file === "handler.js"){ + // add the eval wrapper + src = src.replace('options = (await import(filepath))["default"];', '//options = (await import(filepath))["default"];'); + } fs.writeFileSync("tmp/" + path + "/" + file, src); } }); - }); + } //fs.copyFileSync("src/db/interface.js", "tmp/db/interface.js"); fs.copyFileSync("task/babel." + (debug ? "debug": (minify ? "min" : "bundle")) + ".json", "tmp/.babelrc"); @@ -63,6 +75,16 @@ fs.existsSync("dist") || fs.mkdirSync("dist"); exec("npx babel tmp -d dist/module" + (debug ? "-debug" : (minify ? "-min --minified --compact true" : "")) + " --config-file tmp/.babelrc && exit 0", function(){ console.log("Build Complete."); + + // fix babel compiler dynamic import + let content = fs.readFileSync("dist/module" + (debug ? "-debug" : (minify ? "-min" : "")) + "/worker/handler.js", "utf8"); + content = content.replace('//options = (await import(filepath))["default"];', 'options = (await import(filepath))["default"];'); + fs.writeFileSync("dist/module" + (debug ? "-debug" : (minify ? "-min" : "")) + "/worker/handler.js", content); + + // fix babel compiler dynamic import + content = fs.readFileSync("dist/module" + (debug ? "-debug" : (minify ? "-min" : "")) + "/worker.js", "utf8"); + content = content.replace('(1, eval)("import.meta.url")', 'import.meta.url'); + fs.writeFileSync("dist/module" + (debug ? "-debug" : (minify ? "-min" : "")) + "/worker.js", content); }); }()); diff --git a/task/build.js b/task/build.js index b89c9c2..9ccc2e0 100644 --- a/task/build.js +++ b/task/build.js @@ -274,8 +274,8 @@ else (async function(){ if(file.endsWith(".js")){ if(language_out === "ECMASCRIPT5_STRICT" && file === "keystore.js"){ - let content = fs.readFileSync("src/" + file, "utf8"); + let content = fs.readFileSync("src/" + file, "utf8"); content = content.substring(0, content.indexOf("function lcg64")); content += "function lcg64(str){ throw new Error('The keystore is limited to 32 for EcmaScript5'); }"; fs.writeFileSync("tmp/keystore.js", @@ -285,7 +285,15 @@ else (async function(){ // "/** @constructor */ export function KeystoreArray(arg){}; KeystoreArray.prototype.push = function(arg){};" ); } + else if(file === "worker.js"){ + + let content = fs.readFileSync("src/" + file, "utf8"); + // add the eval wrapper + content = content.replace("import.meta.url", '(1,eval)("import.meta.url")'); + fs.writeFileSync("tmp/worker.js", content); + } else{ + fs.copyFileSync("src/" + file, "tmp/" + file); } } @@ -302,6 +310,11 @@ else (async function(){ fs.cpSync("src/resolve/", "tmp/resolve/", { recursive: true }); fs.cpSync("src/charset/", "tmp/charset/", { recursive: true }); + // add the eval wrapper + let content = fs.readFileSync("tmp/worker/handler.js", "utf8"); + content = content.replace('options = (await import(filepath))["default"];', '//options = (await import(filepath))["default"];'); + fs.writeFileSync("tmp/worker/handler.js", content); + const filename = "dist/flexsearch." + (release + (custom ? "." + custom : "")) + (options["DEBUG"] ? ".debug" : ".min") + ".js"; const executable = process.platform === "win32" ? "\"node_modules/google-closure-compiler-windows/compiler.exe\"" : process.platform === "darwin" ? "\"node_modules/google-closure-compiler-osx/compiler\"" : @@ -357,11 +370,13 @@ else (async function(){ //build = build.replace(/self\.FlexSearch(\s+)?=(\s+)?/, "export default "); // replace the eval wrapper - build = build.replace('(1,eval)("import.meta.dirname")', "import.meta.dirname"); + build = build.replace(/\(1,eval\)\('([^']+)'\)/g, "import.meta.dirname"); + build = build.replace('(0,eval)("import.meta.url")', 'import.meta.url'); + build = build.replace('(1,eval)("import.meta.dirname")', 'import.meta.dirname'); } // fix closure compiler dynamic import - build = build.replace(/\(([a-z])=([a-z]).config\)&&\(([a-z])=([a-z])\)/, "($1=$2.config)&&($3=await import($4))"); + build = build.replace(/\(([a-z])=([a-z]).config\)&&\(([a-z])=([a-z])\)/, "($1=$2.config)&&($3=(await import($4))[\"default\"])"); if(release === "bundle"){ build = build.replace("(function(self){'use strict';", "(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;");