diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index a6d9f61..67af393 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.111 (Bundle/Debug) + * FlexSearch.js v0.8.113 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -272,12 +272,13 @@ function L(a) { ;let M, N; async function ka(a) { a = a.data; - const b = a.task, c = a.id; + var b = a.task; + const c = a.id; let e = a.args; switch(b) { case "init": N = a.options || {}; - (a = a.factory) ? (Function("return " + a)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); + (b = a.factory) ? (Function("return " + b)()(self), M = new self.FlexSearch.Index(N), delete self.FlexSearch) : M = new O(N); postMessage({id:c}); break; default: @@ -286,15 +287,15 @@ async function ka(a) { if (!N.export || "function" !== typeof N.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - e = [N.export]; + e[1] ? (e[0] = N.export, e[2] = 0, e[3] = 1) : e = null; } if ("import" === b) { if (!N.import || "function" !== typeof N.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - await N.import.call(M, M); + e[0] && (a = await N.import.call(M, e[0]), M.import(e[0], a)); } else { - d = M[b].apply(M, e), d.then && (d = await d); + (d = e && M[b].apply(M, e)) && d.then && (d = await d); } postMessage("search" === b ? {id:c, msg:d} : {id:c}); } @@ -378,13 +379,15 @@ R("remove"); R("clear"); R("export"); R("import"); +la(Q.prototype); function R(a) { - Q.prototype[a] = Q.prototype[a + "Async"] = async function() { + Q.prototype[a] = function() { const b = this, c = [].slice.call(arguments); var e = c[c.length - 1]; let d; - "function" === typeof e && (d = e, c.splice(c.length - 1, 1)); + "function" === typeof e && (d = e, c.pop()); e = new Promise(function(f) { + "export" === a && "function" === typeof c[0] && (c[0] = null); b.h[++ra] = f; b.worker.postMessage({task:a, id:ra, args:c}); }); @@ -392,7 +395,7 @@ function R(a) { }; } function sa(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker(E(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ka.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } ;function ta(a, b = 0) { @@ -726,6 +729,7 @@ function Ba(a) { } this.store.set(a, k || b); } + this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; @@ -1708,21 +1712,31 @@ t.export = function(a, b, c = 0, e = 0) { return za.call(this, a, b, d, f, c, e); }; t.import = function(a, b) { + var c = a.split("."); + "json" === c[c.length - 1] && c.pop(); + const e = 2 < c.length ? c[0] : ""; + c = 2 < c.length ? c[2] : c[1]; + if (this.worker && e) { + return this.index.get(e).import(a); + } if (b) { "string" === typeof b && (b = JSON.parse(b)); - a = a.split("."); - "json" === a[a.length - 1] && a.pop(); - var c = 2 < a.length ? a[0] : ""; - a = 2 < a.length ? a[2] : a[1]; - if (c) { - return this.index.get(c).import(a, b); + if (e) { + return this.index.get(e).import(c, b); } - switch(a) { + switch(c) { case "reg": this.fastupdate = !1; this.reg = ya(b, this.reg); - for (let e = 0, d; e < this.field.length; e++) { - d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; + for (let d = 0, f; d < this.field.length; d++) { + f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; + } + if (this.worker) { + b = []; + for (const d of this.index.values()) { + b.push(d.import(a)); + } + return Promise.all(b); } break; case "tag": @@ -2143,7 +2157,7 @@ t.export = function(a, b, c = 0, e = 0) { }; t.import = function(a, b) { if (b) { - switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { + switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; this.reg = ya(b, this.reg); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index 9d8e6af..f0f2149 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.111 (Bundle) + * FlexSearch.js v0.8.113 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -21,12 +21,12 @@ t.addMatcher=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);i t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;const b=a.task,c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(a=a.factory)?(Function("return "+a)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e=[N.export]);"import"===b?await N.import.call(M,M):(d=M[b].apply(M,e),d.then&&(d=await d));postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ma,na;const oa={},pa={};function qa(a){ma=0;oa[a]=pa[a]} +this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ma,na;const oa={},pa={};function qa(a){ma=0;oa[a]=pa[a]} function P(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);ma||(ma=setTimeout(qa,0,a),na=Date.now());pa[a]||(pa[a]=oa[a]=1E3);if(!--oa[a]){oa[a]=pa[a]=pa[a]*this.priority*this.priority*3/(Date.now()-na)|0||1;ma=clearTimeout(ma);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let ra=0; function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ra]=function(){h(d)};d.worker.postMessage({id:ra,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==Q)return new Q(a);let c="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=sa(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}R("add");R("append");R("search");R("update");R("remove");R("clear");R("export");R("import"); -function R(a){Q.prototype[a]=Q.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.splice(c.length-1,1));e=new Promise(function(f){b.h[++ra]=f;b.worker.postMessage({task:a,id:ra,args:c})});return d?(e.then(d),this):e}} -function sa(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ka.toString()],{type:"text/javascript"}))):new window.Worker(E(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=sa(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}R("add");R("append");R("search");R("update");R("remove");R("clear");R("export");R("import");la(Q.prototype); +function R(a){Q.prototype[a]=function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.pop());e=new Promise(function(f){"export"===a&&"function"===typeof c[0]&&(c[0]=null);b.h[++ra]=f;b.worker.postMessage({task:a,id:ra,args:c})});return d?(e.then(d),this):e}} +function sa(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ka.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof c?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"),{type:"module"})};function ta(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function ua(a,b){b||(b=new Map);for(let c=0,e;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} @@ -37,7 +37,7 @@ function U(a=8){if(!this)return new U(a);this.index=B();this.h=[];32c||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1this.limit&&this.cache.delete(this.cache.keys().next().value)}; +t.import=function(a,b){var c=a.split(".");"json"===c[c.length-1]&&c.pop();const e=2this.limit&&this.cache.delete(this.cache.keys().next().value)}; Y.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const $a={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):fb(p,e,q,d,f);gb(this,m,g,h,a,c)}break}case "reverse":if(1< d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& @@ -81,7 +82,7 @@ t.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.com t.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};t.append=function(a,b){return this.add(a,b,!0)};t.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};t.update=function(a,b){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; function nb(a){let b=0;if(a.constructor===Array)for(let c=0,e;cthis.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;const b=a.task,c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(a=a.factory)?(Function("return "+a)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e=[N.export]);"import"===b?await N.import.call(M,M):(d=M[b].apply(M,e),d.then&&(d=await d));postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ma,na;const oa={},pa={};function qa(a){ma=0;oa[a]=pa[a]} +this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ma,na;const oa={},pa={};function qa(a){ma=0;oa[a]=pa[a]} function P(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);ma||(ma=setTimeout(qa,0,a),na=Date.now());pa[a]||(pa[a]=oa[a]=1E3);if(!--oa[a]){oa[a]=pa[a]=pa[a]*this.priority*this.priority*3/(Date.now()-na)|0||1;ma=clearTimeout(ma);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let ra=0; function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ra]=function(){h(d)};d.worker.postMessage({id:ra,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==Q)return new Q(a);let c="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=sa(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}R("add");R("append");R("search");R("update");R("remove");R("clear");R("export");R("import"); -function R(a){Q.prototype[a]=Q.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.splice(c.length-1,1));e=new Promise(function(f){b.h[++ra]=f;b.worker.postMessage({task:a,id:ra,args:c})});return d?(e.then(d),this):e}} -function sa(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ka.toString()],{type:"text/javascript"}))):new window.Worker(E(c)?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=sa(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}R("add");R("append");R("search");R("update");R("remove");R("clear");R("export");R("import");la(Q.prototype); +function R(a){Q.prototype[a]=function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.pop());e=new Promise(function(f){"export"===a&&"function"===typeof c[0]&&(c[0]=null);b.h[++ra]=f;b.worker.postMessage({task:a,id:ra,args:c})});return d?(e.then(d),this):e}} +function sa(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ka.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof c?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"),{type:"module"})};function ta(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function ua(a,b){b||(b=new Map);for(let c=0,e;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const k=b.length;if(k&&(d=d.length?d.concat(b):b,c-=k,e&&(a.length-=k),!c))break;b=0}return d} @@ -37,7 +37,7 @@ function U(a=8){if(!this)return new U(a);this.index=B();this.h=[];32c||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1this.limit&&this.cache.delete(this.cache.keys().next().value)}; +t.import=function(a,b){var c=a.split(".");"json"===c[c.length-1]&&c.pop();const e=2this.limit&&this.cache.delete(this.cache.keys().next().value)}; Y.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const $a={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):fb(p,e,q,d,f);gb(this,m,g,h,a,c)}break}case "reverse":if(1< d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& @@ -81,7 +82,7 @@ t.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.com t.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]);return this};t.append=function(a,b){return this.add(a,b,!0)};t.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};t.update=function(a,b){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; function ob(a){let b=0;if(a.constructor===Array)for(let c=0,e;c { setTimeout(function() { @@ -299,7 +330,68 @@ function M(a) { return b; }; } -;function la(a, c = 0) { +;let T = 0; +function ma(a = {}) { + function c(g) { + function k(h) { + h = h.data || h; + const l = h.id, m = l && d.h[l]; + m && (m(h.msg), delete d.h[l]); + } + this.worker = g; + this.h = C(); + if (this.worker) { + e ? this.worker.on("message", k) : this.worker.onmessage = k; + if (a.config) { + return new Promise(function(h) { + d.h[++T] = function() { + h(d); + }; + d.worker.postMessage({id:T, task:"init", factory:b, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:b, options:a}); + return this; + } + } + if (!this || this.constructor !== ma) { + return new ma(a); + } + let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + b && (b = b.toString()); + const e = "undefined" === typeof window, d = this, f = na(b, e, a.worker); + return f.then ? f.then(function(g) { + return c.call(d, g); + }) : c.call(this, f); +} +U("add"); +U("append"); +U("search"); +U("update"); +U("remove"); +U("clear"); +U("export"); +U("import"); +ja(ma.prototype); +function U(a) { + ma.prototype[a] = function() { + const c = this, b = [].slice.call(arguments); + var e = b[b.length - 1]; + let d; + "function" === typeof e && (d = e, b.pop()); + e = new Promise(function(f) { + "export" === a && "function" === typeof b[0] && (b[0] = null); + c.h[++T] = f; + c.worker.postMessage({task:a, id:T, args:b}); + }); + return d ? (e.then(d), this) : e; + }; +} +function na(a, c, b) { + return c ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ia.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function oa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -308,30 +400,30 @@ function M(a) { e.length && b.push(e); return b; } -function ma(a, c) { +function pa(a, c) { c || (c = new Map()); for (let b = 0, e; b < a.length; b++) { e = a[b], c.set(e[0], e[1]); } return c; } -function na(a, c = 0) { +function qa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], la(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], oa(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function oa(a, c) { +function ra(a, c) { c || (c = new Map()); for (let b = 0, e, d; b < a.length; b++) { - e = a[b], d = c.get(e[0]), c.set(e[0], ma(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], pa(e[1], d)); } return c; } -function pa(a) { +function sa(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -339,14 +431,14 @@ function pa(a) { b.length && c.push(b); return c; } -function qa(a, c) { +function ta(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function Q(a, c, b, e, d, f, g = 0) { +function ua(a, c, b, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { @@ -355,12 +447,12 @@ function Q(a, c, b, e, d, f, g = 0) { if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return Q.call(l, a, c, b, k ? e : null, d, f, g + 1); + return ua.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return Q.call(this, a, c, b, k ? e : null, d, f, g + 1); + return ua.call(this, a, c, b, k ? e : null, d, f, g + 1); } -;R.prototype.add = function(a, c, b) { +;V.prototype.add = function(a, c, b) { I(a) && (c = a, a = J(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { @@ -374,7 +466,7 @@ function Q(a, c, b, e, d, f, g = 0) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), ra(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); } } } @@ -396,7 +488,7 @@ function Q(a, c, b, e, d, f, g = 0) { f = J(c, f); } if (d && f) { - E(f) && (f = [f]); + D(f) && (f = [f]); for (let h = 0, l, m; h < f.length; h++) { l = f[h], k[l] || (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } @@ -421,11 +513,11 @@ function Q(a, c, b, e, d, f, g = 0) { continue; } l = [l.U]; - } else if (E(l) || l.constructor === String) { + } else if (D(l) || l.constructor === String) { k[l] = c[l]; continue; } - sa(c, k, l, 0, l[0], m); + wa(c, k, l, 0, l[0], m); } } this.store.set(a, k || c); @@ -433,21 +525,21 @@ function Q(a, c, b, e, d, f, g = 0) { } return this; }; -function sa(a, c, b, e, d, f) { +function wa(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++) { - sa(a, c, b, e, d); + wa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], sa(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], wa(a, c, b, e, d); } } } -function ra(a, c, b, e, d, f, g, k) { +function va(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -463,15 +555,15 @@ function ra(a, c, b, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - ra(a, c, b, e, d, f, g, k); + va(a, c, b, e, d, f, g, k); } } else { - g = c[++e], ra(a, c, b, e, d, f, g, k); + g = c[++e], va(a, c, b, e, d, f, g, k); } } } } -;function ta(a, c, b, e, d) { +;function xa(a, c, b, e, d) { const f = a.length; let g = [], k, h; k = C(); @@ -486,7 +578,7 @@ function ra(a, c, b, e, d, f, g, k) { } if (a = g.length) { if (d) { - g = 1 < g.length ? ua(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -501,7 +593,7 @@ function ra(a, c, b, e, d, f, g, k) { } return g; } -function ua(a, c, b) { +function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; @@ -523,7 +615,7 @@ function ua(a, c, b) { } return e; } -function va(a, c) { +function za(a, c) { const b = C(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -536,12 +628,12 @@ function va(a, c) { } return e; } -;function S(a, c, b, e) { +;function Aa(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? T.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; } let d = []; for (let f = 0, g, k; f < a.length; f++) { @@ -555,7 +647,7 @@ function va(a, c) { } k > c && (g = g.slice(0, c), k = c); if (!d.length && k >= c) { - return e ? T.call(this, g) : g; + return e ? W.call(this, g) : g; } d.push(g); c -= k; @@ -565,9 +657,9 @@ function va(a, c) { } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? T.call(this, d) : d; + return e ? W.call(this, d) : d; } -;function U(a, c, b) { +;function Ba(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -582,7 +674,7 @@ function va(a, c) { for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { let t; - if (n.constructor === V) { + if (n.constructor === X) { t = n.result; } else if (n.constructor === Array) { t = n; @@ -613,11 +705,11 @@ function va(a, c) { } return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } -;V.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = U(this, "or", arguments); - return wa.call(this, a, c, b, e, d, f); +;X.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); + return Ca.call(this, a, c, b, e, d, f); }; -function wa(a, c, b, e, d, f) { +function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; return Promise.all(c).then(function(k) { @@ -625,25 +717,25 @@ function wa(a, c, b, e, d, f) { for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return wa.call(g, a, [], b, e, d, f); + return Ca.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ua(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ya(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } -;V.prototype.and = function() { +;X.prototype.and = function() { let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = U(this, "and", arguments); - return xa.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); + return Da.call(this, f, g, k, h, l, m, n); } return d ? this.resolve(c, b, e) : this; }; -function xa(a, c, b, e, d, f, g) { +function Da(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -651,7 +743,7 @@ function xa(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return xa.call(k, a, [], b, e, d, f, g); + return Da.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -659,7 +751,7 @@ function xa(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = ta(a, c, b, e, g), f ? d ? T.call(this.index, this.result) : this.result : this; + return this.result = xa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -668,11 +760,11 @@ function xa(a, c, b, e, d, f, g) { } return f ? this.resolve(b, e, d) : this; } -;V.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = U(this, "xor", arguments); - return ya.call(this, a, c, b, e, d, f, g); +;X.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); + return Ea.call(this, a, c, b, e, d, f, g); }; -function ya(a, c, b, e, d, f, g) { +function Ea(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -680,21 +772,21 @@ function ya(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return ya.call(k, a, [], b, e, d, f, g); + return Ea.call(k, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = za.call(this, a, b, e, f, this.h), f ? d ? T.call(this.index, this.result) : this.result : this; + return this.result = Fa.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function za(a, c, b, e, d) { +function Fa(a, c, b, e, d) { const f = [], g = C(); let k = 0; for (let h = 0, l; h < a.length; h++) { @@ -739,11 +831,11 @@ function za(a, c, b, e, d) { } return f; } -;V.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = U(this, "not", arguments); - return Aa.call(this, a, c, b, e, d, f, g); +;X.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); + return Ga.call(this, a, c, b, e, d, f, g); }; -function Aa(a, c, b, e, d, f, g) { +function Ga(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -751,17 +843,17 @@ function Aa(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Aa.call(k, a, [], b, e, d, f, g); + return Ga.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ba.call(this, a, b, e, f); + this.result = Ha.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? T.call(this.index, this.result) : this.result : this; + return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Ba(a, c, b, e) { +function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { @@ -787,9 +879,9 @@ function Ba(a, c, b, e) { } return d; } -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); +;function X(a) { + if (!this || this.constructor !== X) { + return new X(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -798,7 +890,7 @@ function Ba(a, c, b, e) { this.result = a || []; this.h = 0; } -V.prototype.limit = function(a) { +X.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -817,7 +909,7 @@ V.prototype.limit = function(a) { } return this; }; -V.prototype.offset = function(a) { +X.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -829,17 +921,17 @@ V.prototype.offset = function(a) { } return this; }; -V.prototype.boost = function(a) { +X.prototype.boost = function(a) { this.h += a; return this; }; -V.prototype.resolve = function(a, c, b) { +X.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), S.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; }; C(); -R.prototype.search = function(a, c, b, e) { +V.prototype.search = function(a, c, b, e) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = []; var f = []; @@ -864,7 +956,7 @@ R.prototype.search = function(a, c, b, e) { var u = []; for (let x = 0, r; x < m.length; x++) { r = m[x]; - if (E(r)) { + if (D(r)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (r.field && r.tag) { @@ -878,8 +970,8 @@ R.prototype.search = function(a, c, b, e) { } } else { v = Object.keys(r); - for (let D = 0, F, A; D < v.length; D++) { - if (F = v[D], A = r[F], A.constructor === Array) { + for (let E = 0, F, A; E < v.length; E++) { + if (F = v[E], A = r[F], A.constructor === Array) { for (z = 0; z < A.length; z++) { u.push(F, A[z]); } @@ -897,7 +989,7 @@ R.prototype.search = function(a, c, b, e) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - y = Ca.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); + y = Ia.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); } } return e.length ? Promise.all(e).then(function(x) { @@ -912,14 +1004,14 @@ R.prototype.search = function(a, c, b, e) { } l || (l = this.field); u = !e && (this.worker || this.db) && []; - for (let x = 0, r, D, F; x < l.length; x++) { - D = l[x]; + for (let x = 0, r, E, F; x < l.length; x++) { + E = l[x]; let A; - E(D) || (A = D, D = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, h = A.suggest || h, g = this.store && (A.enrich || g)); + D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, h = A.suggest || h, g = this.store && (A.enrich || g)); if (e) { r = e[x]; } else { - if (v = A || b, z = this.index.get(D), m && (v.enrich = !1), u) { + if (v = A || b, z = this.index.get(E), m && (v.enrich = !1), u) { u[x] = z.search(a, c, v); v && g && (v.enrich = g); continue; @@ -931,34 +1023,34 @@ R.prototype.search = function(a, c, b, e) { if (m && F) { v = []; z = 0; - for (let G = 0, H, Sa; G < m.length; G += 2) { + for (let G = 0, H, Za; G < m.length; G += 2) { H = this.tag.get(m[G]); if (!H) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), h) { continue; } else { - return p ? d : new V(d); + return p ? d : new X(d); } } - if (Sa = (H = H && H.get(m[G + 1])) && H.length) { + if (Za = (H = H && H.get(m[G + 1])) && H.length) { z++, v.push(H); } else if (!h) { - return p ? d : new V(d); + return p ? d : new X(d); } } if (z) { - r = va(r, v); + r = za(r, v); F = r.length; if (!F && !h) { - return p ? r : new V(r); + return p ? r : new X(r); } z--; } } if (F) { - f[t] = D, d.push(r), t++; + f[t] = E, d.push(r), t++; } else if (1 === l.length) { - return p ? d : new V(d); + return p ? d : new X(d); } } if (u) { @@ -968,7 +1060,7 @@ R.prototype.search = function(a, c, b, e) { }); } if (!t) { - return p ? d : new V(d); + return p ? d : new X(d); } if (y && (!g || !this.store)) { return d[0]; @@ -976,15 +1068,15 @@ R.prototype.search = function(a, c, b, e) { u = []; for (let x = 0, r; x < f.length; x++) { r = d[x]; - g && r.length && !r[0].doc && (r = T.call(this, r)); + g && r.length && !r[0].doc && (r = W.call(this, r)); if (y) { - return p ? r : new V(r); + return p ? r : new X(r); } d[x] = {field:f[x], result:r}; } - return k ? Da(d, c) : q ? Ea(d, a, this.index, this.field, this.C, q) : d; + return k ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; }; -function Ea(a, c, b, e, d, f) { +function Ka(a, c, b, e, d, f) { let g, k, h; for (let m = 0, n, t, p, q, y; m < a.length; m++) { n = a[m].result; @@ -999,21 +1091,21 @@ function Ea(a, c, b, e, d, f) { var l = J(n[u].doc, y); let z = g.encode(l); l = l.split(g.split); - for (let x = 0, r, D; x < z.length; x++) { + for (let x = 0, r, E; x < z.length; x++) { r = z[x]; - D = l[x]; + E = l[x]; let F; for (let A = 0, G; A < k.length; A++) { if (G = k[A], "strict" === h) { if (r === G) { - v += (v ? " " : "") + f.replace("$1", D); + v += (v ? " " : "") + f.replace("$1", E); F = !0; break; } } else { const H = r.indexOf(G); if (-1 < H) { - v += (v ? " " : "") + D.substring(0, H) + f.replace("$1", D.substring(H, G.length)) + D.substring(H + G.length); + v += (v ? " " : "") + E.substring(0, H) + f.replace("$1", E.substring(H, G.length)) + E.substring(H + G.length); F = !0; break; } @@ -1026,7 +1118,7 @@ function Ea(a, c, b, e, d, f) { } return a; } -function Da(a, c) { +function Ja(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1045,7 +1137,7 @@ function Da(a, c) { } return b; } -function Ca(a, c, b, e, d) { +function Ia(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1054,11 +1146,11 @@ function Ca(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = T.call(this, f)); + d && (f = W.call(this, f)); return f; } } -function T(a) { +function W(a) { if (!this || !this.store) { return a; } @@ -1068,32 +1160,32 @@ function T(a) { } return c; } -;function R(a) { - if (!this || this.constructor !== R) { - return new R(a); +;function V(a) { + if (!this || this.constructor !== V) { + return new V(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && W(b, this.J) || "id"; + this.key = (b = c.key || c.id) && La(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); - this.cache = (b = a.cache || null) && new X(b); + this.cache = (b = a.cache || null) && new Y(b); a.cache = !1; b = new Map(); let e = c.index || c.field || c; - E(e) && (e = [e]); + D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], E(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new Y(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = W(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; - E(a) && (a = [a]); + D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = W(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1109,14 +1201,14 @@ function T(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = W(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function W(a, c) { +function La(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1125,7 +1217,7 @@ function W(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -w = R.prototype; +w = V.prototype; w.append = function(a, c) { return this.add(a, c, !0); }; @@ -1181,7 +1273,7 @@ w.set = function(a, c) { this.store.set(a, c); return this; }; -w.searchCache = Fa; +w.searchCache = Ma; w.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; @@ -1197,17 +1289,17 @@ w.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = pa(this.reg); + f = sa(this.reg); c = null; break; case 1: d = "tag"; - f = na(this.tag, this.reg.size); + f = qa(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = la(this.store); + f = oa(this.store); c = null; break; case 3: @@ -1217,38 +1309,38 @@ w.export = function(a, c, b = 0, e = 0) { default: return; } - return Q.call(this, a, c, d, f, b, e); + return ua.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { + var b = a.split("."); + "json" === b[b.length - 1] && b.pop(); + a = 2 < b.length ? b[0] : ""; + b = 2 < b.length ? b[2] : b[1]; if (c) { "string" === typeof c && (c = JSON.parse(c)); - a = a.split("."); - "json" === a[a.length - 1] && a.pop(); - var b = 2 < a.length ? a[0] : ""; - a = 2 < a.length ? a[2] : a[1]; - if (b) { - return this.index.get(b).import(a, c); + if (a) { + return this.index.get(a).import(b, c); } - switch(a) { + switch(b) { case "reg": this.fastupdate = !1; - this.reg = qa(c, this.reg); + this.reg = ta(c, this.reg); for (let e = 0, d; e < this.field.length; e++) { d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = oa(c, this.tag); + this.tag = ra(c, this.tag); break; case "doc": - this.store = ma(c, this.store); + this.store = pa(c, this.store); } } }; -ia(R.prototype); -function Fa(a, c, b) { +ja(V.prototype); +function Ma(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new X()); + this.cache || (this.cache = new Y()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -1263,56 +1355,56 @@ function Fa(a, c, b) { } return e; } -function X(a) { +function Y(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -X.prototype.set = function(a, c) { +Y.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); }; -X.prototype.get = function(a) { +Y.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -X.prototype.remove = function(a) { +Y.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -X.prototype.clear = function() { +Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ga = {normalize:function(a) { +const Na = {normalize:function(a) { return a.toLowerCase(); }}; -const Ha = 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 Ia = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ja = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const Ka = {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 La = /[\x00-\x7F]+/g; -const Ma = /[\x00-\x7F]+/g; -const Na = /[\x00-\x7F]+/g; -var Oa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ga, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ha}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ha, matcher:Ia, replacer:Ja}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ha, replacer:Ja.concat([/(?!^)[aeo]/g, ""]), matcher:Ia}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Oa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Pa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +const Ra = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const Sa = /[\x00-\x7F]+/g; +const Ta = /[\x00-\x7F]+/g; +const Ua = /[\x00-\x7F]+/g; +var Va = {LatinExact:{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, matcher:Pa, replacer:Qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Ka[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ka[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Ra[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(La, " "); + return ("" + a).replace(Sa, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ma, ""); + return ("" + a).replace(Ta, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Na, " "); + return ("" + a).replace(Ua, " "); }}}; -const Pa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -Y.prototype.add = function(a, c, b, e) { +const Wa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -1324,14 +1416,14 @@ Y.prototype.add = function(a, c, b, e) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Qa(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Xa(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var k = d; k > f; k--) { g = q.substring(f, k); - var h = this.score ? this.score(c, q, p, g, f) : Qa(t, e, p, d, f); + var h = this.score ? this.score(c, q, p, g, f) : Xa(t, e, p, d, f); Z(this, m, g, h, a, b); } } @@ -1340,7 +1432,7 @@ Y.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (k = d - 1; 0 < k; k--) { - g = q[k] + g, h = this.score ? this.score(c, q, p, g, k) : Qa(t, e, p, d, k), Z(this, m, g, h, a, b); + g = q[k] + g, h = this.score ? this.score(c, q, p, g, k) : Xa(t, e, p, d, k), Z(this, m, g, h, a, b); } g = ""; } @@ -1356,7 +1448,7 @@ Y.prototype.add = function(a, c, b, e) { for (d = C(), g = this.S, f = q, k = Math.min(n + 1, e - p), d[f] = 1, h = 1; h < k; h++) { if ((q = c[this.rtl ? e - 1 - p - h : p + h]) && !d[q]) { d[q] = 1; - const y = this.score ? this.score(c, f, p, q, h) : Qa(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; + const y = this.score ? this.score(c, f, p, q, h) : Xa(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, y, a, b, u ? q : f); } } @@ -1375,10 +1467,10 @@ function Z(a, c, b, e, d, f, g) { g ? (c = h || (c[b] = C()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); } } -function Qa(a, c, b, e, d) { +function Xa(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;Y.prototype.search = function(a, c, b) { +;O.prototype.search = function(a, c, b) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { @@ -1396,11 +1488,11 @@ function Qa(a, c, b, e, d) { b = a.length; c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Ra(this, a[0], "")) && c.length ? S.call(this, c, g, d) : []; + return g = c, (c = Ya(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Ra(this, a[0], a[1])) && c.length ? S.call(this, c, g, d) : []; + return g = c, (c = Ya(this, a[0], a[1])) && c.length ? Aa.call(this, c, g, d) : []; } k = C(); let l = 0; @@ -1412,7 +1504,7 @@ function Qa(a, c, b, e, d) { for (let q, y; l < b; l++) { if ((y = a[l]) && !k[y]) { k[y] = 1; - q = Ra(this, y, m); + q = Ya(this, y, m); a: { f = q; var n = e, t = g, p = h; @@ -1449,22 +1541,22 @@ function Qa(a, c, b, e, d) { e = a.length; m = a; if (1 < e) { - m = ta(a, h, c, d, g); + m = xa(a, h, c, d, g); } else if (1 === e) { - g = S.call(null, a[0], c, d); + g = Aa.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Ra(a, c, b) { +function Ya(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;Y.prototype.remove = function(a, c) { +;O.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -1479,14 +1571,14 @@ function Ra(a, c, b) { } } } else { - Ta(this.map, a), this.depth && Ta(this.ctx, a); + $a(this.map, a), this.depth && $a(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Ta(a, c) { +function $a(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1501,24 +1593,24 @@ function Ta(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = Ta(e[1], c); + const d = e[0], f = $a(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function Y(a, c) { - if (!this || this.constructor !== Y) { - return new Y(a); +;function O(a, c) { + if (!this || this.constructor !== O) { + return new O(a); } if (a) { - var b = E(a) ? a : a.preset; - b && (Pa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Pa[b], a)); + var b = D(a) ? a : a.preset; + b && (Wa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Wa[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? Oa[a.encoder] : a.encode || a.encoder || Ga; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = (b = a.tokenize) && "default" !== b && b || "strict"; @@ -1532,10 +1624,10 @@ function Ta(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.S = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new X(b); + this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; } -w = Y.prototype; +w = O.prototype; w.clear = function() { this.map.clear(); this.ctx.clear(); @@ -1553,7 +1645,7 @@ w.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function Ua(a) { +function ab(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1561,7 +1653,7 @@ function Ua(a) { } } else { for (const b of a) { - const e = b[0], d = Ua(b[1]); + const e = b[0], d = ab(b[1]); d ? c += d : a.delete(e); } } @@ -1571,17 +1663,17 @@ w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Ua(this.map); - this.depth && Ua(this.ctx); + ab(this.map); + this.depth && ab(this.ctx); return this; }; -w.searchCache = Fa; +w.searchCache = Ma; w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = pa(this.reg); + f = sa(this.reg); break; case 1: d = "cfg"; @@ -1589,29 +1681,29 @@ w.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = la(this.map, this.reg.size); + f = oa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = na(this.ctx, this.reg.size); + f = qa(this.ctx, this.reg.size); break; default: return; } - return Q.call(this, a, c, d, f, b, e); + return ua.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { if (c) { - switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { + switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = qa(c, this.reg); + this.reg = ta(c, this.reg); break; case "map": - this.map = ma(c, this.map); + this.map = pa(c, this.map); break; case "ctx": - this.ctx = oa(c, this.ctx); + this.ctx = ra(c, this.ctx); } } }; @@ -1665,10 +1757,10 @@ w.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ia(Y.prototype); -const Va = {Index:Y, Charset:Oa, Encoder:K, Document:R, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Wa = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; -let Xa; -(Xa = Wa.define) && Xa.amd ? Xa([], function() { - return Va; -}) : "object" === typeof Wa.exports ? Wa.exports = Va : Wa.FlexSearch = Va; +ja(O.prototype); +const bb = {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, cb = "undefined" !== typeof self ? self : "undefined" !== typeof global ? global : "undefined" !== typeof window ? window : {}; +let db; +(db = cb.define) && db.amd ? db([], function() { + return bb; +}) : "object" === typeof cb.exports ? cb.exports = bb : cb.FlexSearch = bb; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 0e61967..1bf30ba 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,12 +1,12 @@ /**! - * FlexSearch.js v0.8.111 (Bundle) + * FlexSearch.js v0.8.113 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';var v;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(k){return a(b(k))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function E(a){return"string"===typeof a} -function H(a){return"object"===typeof a}function J(a,c){if(E(c))a=a[c];else for(let b=0;a&&bthis.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};function ia(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}let N,ja;const O={},P={};function ka(a){N=0;O[a]=P[a]} -function M(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);N||(N=setTimeout(ka,0,a),ja=Date.now());P[a]||(P[a]=O[a]=1E3);if(!--O[a]){O[a]=P[a]=P[a]*this.priority*this.priority*3/(Date.now()-ja)|0||1;N=clearTimeout(N);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};function la(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function ma(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function ua(a,c,b){const e=[],d=C();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?T.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?T.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ua(a,b,e),e=0));return f?this.resolve(b,e,d):this};V.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=U(this,"and",arguments);return xa.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; -function xa(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=ta(a,c,b,e,g),f?d?T.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};V.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=U(this,"xor",arguments);return ya.call(this,a,c,b,e,d,f,g)}; -function ya(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=za.call(this,a,b,e,f,this.h),f?d?T.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function za(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hthis.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let Q,ka;const R={},S={};function la(a){Q=0;R[a]=S[a]} +function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);Q||(Q=setTimeout(la,0,a),ka=Date.now());S[a]||(S[a]=R[a]=1E3);if(!--R[a]){R[a]=S[a]=S[a]*this.priority*this.priority*3/(Date.now()-ka)|0||1;Q=clearTimeout(Q);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let T=0; +function ma(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++T]=function(){h(d)};d.worker.postMessage({id:T,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==ma)return new ma(a);let b="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;b&&(b=b.toString());const e="undefined"===typeof window,d=this,f=na(b,e,a.worker);return f.then?f.then(function(g){return c.call(d,g)}):c.call(this,f)}U("add");U("append");U("search");U("update");U("remove");U("clear");U("export");U("import");ja(ma.prototype); +function U(a){ma.prototype[a]=function(){const c=this,b=[].slice.call(arguments);var e=b[b.length-1];let d;"function"===typeof e&&(d=e,b.pop());e=new Promise(function(f){"export"===a&&"function"===typeof b[0]&&(b[0]=null);c.h[++T]=f;c.worker.postMessage({task:a,id:T,args:b})});return d?(e.then(d),this):e}} +function na(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ia.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof b?b:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function oa(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function pa(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?W.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=T.call(this,a));return a}} -function T(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -X.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Ga={normalize:function(a){return a.toLowerCase()}};const Ha=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 Ia=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ja=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ka={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 La=/[\x00-\x7F]+/g;const Ma=/[\x00-\x7F]+/g;const Na=/[\x00-\x7F]+/g;var Oa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ga,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ha},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ha,matcher:Ia,replacer:Ja},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ha,replacer:Ja.concat([/(?!^)[aeo]/g,""]),matcher:Ia},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;k--){g=q.substring(f,k);var h=this.score?this.score(c,q,p,g,f):Qa(t,e,p,d,f);Z(this,m,g,h,a,b)}break}case "reverse":if(1< -d){for(k=d-1;0g?0:1),e,p,k-1,h-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Qa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};Y.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 Ta(this.map,a),this.depth&&Ta(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Ta(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function Ua(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}} +function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};const Oa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Pa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;const Ua=/[\x00-\x7F]+/g;var Va={LatinExact:{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,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;k--){g=q.substring(f,k);var h=this.score?this.score(c,q,p,g,f):Xa(t,e,p,d,f);Z(this,m,g,h,a,b)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,p,k-1,h-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Xa(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else $a(this.map,a),this.depth&&$a(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function $a(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function ab(a){let c=0;if(a.constructor===Array)for(let b=0,e;b { setTimeout(function() { @@ -298,7 +329,68 @@ function M(a) { return b; }; } -;function la(a, c = 0) { +;let T = 0; +function ma(a = {}) { + function c(g) { + function k(h) { + h = h.data || h; + const l = h.id, m = l && d.h[l]; + m && (m(h.msg), delete d.h[l]); + } + this.worker = g; + this.h = C(); + if (this.worker) { + e ? this.worker.on("message", k) : this.worker.onmessage = k; + if (a.config) { + return new Promise(function(h) { + d.h[++T] = function() { + h(d); + }; + d.worker.postMessage({id:T, task:"init", factory:b, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:b, options:a}); + return this; + } + } + if (!this || this.constructor !== ma) { + return new ma(a); + } + let b = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + b && (b = b.toString()); + const e = "undefined" === typeof window, d = this, f = na(b, e, a.worker); + return f.then ? f.then(function(g) { + return c.call(d, g); + }) : c.call(this, f); +} +U("add"); +U("append"); +U("search"); +U("update"); +U("remove"); +U("clear"); +U("export"); +U("import"); +ja(ma.prototype); +function U(a) { + ma.prototype[a] = function() { + const c = this, b = [].slice.call(arguments); + var e = b[b.length - 1]; + let d; + "function" === typeof e && (d = e, b.pop()); + e = new Promise(function(f) { + "export" === a && "function" === typeof b[0] && (b[0] = null); + c.h[++T] = f; + c.worker.postMessage({task:a, id:T, args:b}); + }); + return d ? (e.then(d), this) : e; + }; +} +function na(a, c, b) { + return c ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + ia.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof b ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function oa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -307,30 +399,30 @@ function M(a) { e.length && b.push(e); return b; } -function ma(a, c) { +function pa(a, c) { c || (c = new Map()); for (let b = 0, e; b < a.length; b++) { e = a[b], c.set(e[0], e[1]); } return c; } -function na(a, c = 0) { +function qa(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], la(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], oa(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function oa(a, c) { +function ra(a, c) { c || (c = new Map()); for (let b = 0, e, d; b < a.length; b++) { - e = a[b], d = c.get(e[0]), c.set(e[0], ma(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], pa(e[1], d)); } return c; } -function pa(a) { +function sa(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), 250000 === b.length && (c.push(b), b = []); @@ -338,14 +430,14 @@ function pa(a) { b.length && c.push(b); return c; } -function qa(a, c) { +function ta(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function Q(a, c, b, e, d, f, g = 0) { +function ua(a, c, b, e, d, f, g = 0) { const k = e && e.constructor === Array; var h = k ? e.shift() : e; if (!h) { @@ -354,12 +446,12 @@ function Q(a, c, b, e, d, f, g = 0) { if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { const l = this; return h.then(function() { - return Q.call(l, a, c, b, k ? e : null, d, f, g + 1); + return ua.call(l, a, c, b, k ? e : null, d, f, g + 1); }); } - return Q.call(this, a, c, b, k ? e : null, d, f, g + 1); + return ua.call(this, a, c, b, k ? e : null, d, f, g + 1); } -;R.prototype.add = function(a, c, b) { +;V.prototype.add = function(a, c, b) { I(a) && (c = a, a = J(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { @@ -373,7 +465,7 @@ function Q(a, c, b, e, d, f, g = 0) { d && e.add(a, d, !1, !0); } else { if (d = h.I, !d || d(c)) { - h.constructor === String ? h = ["" + h] : E(h) && (h = [h]), ra(c, h, this.J, 0, e, a, h[0], b); + h.constructor === String ? h = ["" + h] : D(h) && (h = [h]), va(c, h, this.J, 0, e, a, h[0], b); } } } @@ -395,7 +487,7 @@ function Q(a, c, b, e, d, f, g = 0) { f = J(c, f); } if (d && f) { - E(f) && (f = [f]); + D(f) && (f = [f]); for (let h = 0, l, m; h < f.length; h++) { l = f[h], k[l] || (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } @@ -420,11 +512,11 @@ function Q(a, c, b, e, d, f, g = 0) { continue; } l = [l.U]; - } else if (E(l) || l.constructor === String) { + } else if (D(l) || l.constructor === String) { k[l] = c[l]; continue; } - sa(c, k, l, 0, l[0], m); + wa(c, k, l, 0, l[0], m); } } this.store.set(a, k || c); @@ -432,21 +524,21 @@ function Q(a, c, b, e, d, f, g = 0) { } return this; }; -function sa(a, c, b, e, d, f) { +function wa(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++) { - sa(a, c, b, e, d); + wa(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], sa(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], wa(a, c, b, e, d); } } } -function ra(a, c, b, e, d, f, g, k) { +function va(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -462,15 +554,15 @@ function ra(a, c, b, e, d, f, g, k) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - ra(a, c, b, e, d, f, g, k); + va(a, c, b, e, d, f, g, k); } } else { - g = c[++e], ra(a, c, b, e, d, f, g, k); + g = c[++e], va(a, c, b, e, d, f, g, k); } } } } -;function ta(a, c, b, e, d) { +;function xa(a, c, b, e, d) { const f = a.length; let g = [], k, h; k = C(); @@ -485,7 +577,7 @@ function ra(a, c, b, e, d, f, g, k) { } if (a = g.length) { if (d) { - g = 1 < g.length ? ua(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; + g = 1 < g.length ? ya(g, b, e) : (g = g[0]).length > b || e ? g.slice(e, b + e) : g; } else { if (a < f) { return []; @@ -500,7 +592,7 @@ function ra(a, c, b, e, d, f, g, k) { } return g; } -function ua(a, c, b) { +function ya(a, c, b) { const e = [], d = C(); let f; var g = a.length; @@ -522,7 +614,7 @@ function ua(a, c, b) { } return e; } -function va(a, c) { +function za(a, c) { const b = C(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -535,12 +627,12 @@ function va(a, c) { } return e; } -;function S(a, c, b, e) { +;function Aa(a, c, b, e) { if (!a.length) { return a; } if (1 === a.length) { - return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? T.call(this, a) : a; + return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a, e ? W.call(this, a) : a; } let d = []; for (let f = 0, g, k; f < a.length; f++) { @@ -554,7 +646,7 @@ function va(a, c) { } k > c && (g = g.slice(0, c), k = c); if (!d.length && k >= c) { - return e ? T.call(this, g) : g; + return e ? W.call(this, g) : g; } d.push(g); c -= k; @@ -564,9 +656,9 @@ function va(a, c) { } } d = 1 < d.length ? [].concat.apply([], d) : d[0]; - return e ? T.call(this, d) : d; + return e ? W.call(this, d) : d; } -;function U(a, c, b) { +;function Ba(a, c, b) { var e = b[0]; if (e.then) { return Promise.all(b).then(function(m) { @@ -581,7 +673,7 @@ function va(a, c) { for (let m = 0, n; m < b.length; m++) { if (n = b[m]) { let t; - if (n.constructor === V) { + if (n.constructor === X) { t = n.result; } else if (n.constructor === Array) { t = n; @@ -612,11 +704,11 @@ function va(a, c) { } return {O:e, P:d, limit:f, offset:g, enrich:k, resolve:h, suggest:l}; } -;V.prototype.or = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = U(this, "or", arguments); - return wa.call(this, a, c, b, e, d, f); +;X.prototype.or = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f} = Ba(this, "or", arguments); + return Ca.call(this, a, c, b, e, d, f); }; -function wa(a, c, b, e, d, f) { +function Ca(a, c, b, e, d, f) { if (c.length) { const g = this; return Promise.all(c).then(function(k) { @@ -624,25 +716,25 @@ function wa(a, c, b, e, d, f) { for (let h = 0, l; h < k.length; h++) { (l = k[h]).length && (a[h] = l); } - return wa.call(g, a, [], b, e, d, f); + return Ca.call(g, a, [], b, e, d, f); }); } - a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ua(a, b, e), e = 0)); + a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = ya(a, b, e), e = 0)); return f ? this.resolve(b, e, d) : this; } -;V.prototype.and = function() { +;X.prototype.and = function() { let a = this.result.length, c, b, e, d; if (!a) { const f = arguments[0]; f && (a = !!f.suggest, d = f.resolve, c = f.limit, b = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = U(this, "and", arguments); - return xa.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ba(this, "and", arguments); + return Da.call(this, f, g, k, h, l, m, n); } return d ? this.resolve(c, b, e) : this; }; -function xa(a, c, b, e, d, f, g) { +function Da(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -650,7 +742,7 @@ function xa(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return xa.call(k, a, [], b, e, d, f, g); + return Da.call(k, a, [], b, e, d, f, g); }); } if (a.length) { @@ -658,7 +750,7 @@ function xa(a, c, b, e, d, f, g) { this.result = a[0]; } else { if (c = aa(a)) { - return this.result = ta(a, c, b, e, g), f ? d ? T.call(this.index, this.result) : this.result : this; + return this.result = xa(a, c, b, e, g), f ? d ? W.call(this.index, this.result) : this.result : this; } this.result = []; } @@ -667,11 +759,11 @@ function xa(a, c, b, e, d, f, g) { } return f ? this.resolve(b, e, d) : this; } -;V.prototype.xor = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = U(this, "xor", arguments); - return ya.call(this, a, c, b, e, d, f, g); +;X.prototype.xor = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "xor", arguments); + return Ea.call(this, a, c, b, e, d, f, g); }; -function ya(a, c, b, e, d, f, g) { +function Ea(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -679,21 +771,21 @@ function ya(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return ya.call(k, a, [], b, e, d, f, g); + return Ea.call(k, a, [], b, e, d, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = za.call(this, a, b, e, f, this.h), f ? d ? T.call(this.index, this.result) : this.result : this; + return this.result = Fa.call(this, a, b, e, f, this.h), f ? d ? W.call(this.index, this.result) : this.result : this; } } else { g || (this.result = a); } return f ? this.resolve(b, e, d) : this; } -function za(a, c, b, e, d) { +function Fa(a, c, b, e, d) { const f = [], g = C(); let k = 0; for (let h = 0, l; h < a.length; h++) { @@ -738,11 +830,11 @@ function za(a, c, b, e, d) { } return f; } -;V.prototype.not = function() { - const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = U(this, "not", arguments); - return Aa.call(this, a, c, b, e, d, f, g); +;X.prototype.not = function() { + const {O:a, P:c, limit:b, offset:e, enrich:d, resolve:f, suggest:g} = Ba(this, "not", arguments); + return Ga.call(this, a, c, b, e, d, f, g); }; -function Aa(a, c, b, e, d, f, g) { +function Ga(a, c, b, e, d, f, g) { if (c.length) { const k = this; return Promise.all(c).then(function(h) { @@ -750,17 +842,17 @@ function Aa(a, c, b, e, d, f, g) { for (let l = 0, m; l < h.length; l++) { (m = h[l]).length && (a[l] = m); } - return Aa.call(k, a, [], b, e, d, f, g); + return Ga.call(k, a, [], b, e, d, f, g); }); } if (a.length && this.result.length) { - this.result = Ba.call(this, a, b, e, f); + this.result = Ha.call(this, a, b, e, f); } else if (f) { return this.resolve(b, e, d); } - return f ? d ? T.call(this.index, this.result) : this.result : this; + return f ? d ? W.call(this.index, this.result) : this.result : this; } -function Ba(a, c, b, e) { +function Ha(a, c, b, e) { const d = []; a = new Set(a.flat().flat()); for (let f = 0, g, k = 0; f < this.result.length; f++) { @@ -786,9 +878,9 @@ function Ba(a, c, b, e) { } return d; } -;function V(a) { - if (!this || this.constructor !== V) { - return new V(a); +;function X(a) { + if (!this || this.constructor !== X) { + return new X(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.h = a.boost || 0, this.result = a.index.search(a).result, this; @@ -797,7 +889,7 @@ function Ba(a, c, b, e) { this.result = a || []; this.h = 0; } -V.prototype.limit = function(a) { +X.prototype.limit = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -816,7 +908,7 @@ V.prototype.limit = function(a) { } return this; }; -V.prototype.offset = function(a) { +X.prototype.offset = function(a) { if (this.result.length) { const c = []; for (let b = 0, e; b < this.result.length; b++) { @@ -828,17 +920,17 @@ V.prototype.offset = function(a) { } return this; }; -V.prototype.boost = function(a) { +X.prototype.boost = function(a) { this.h += a; return this; }; -V.prototype.resolve = function(a, c, b) { +X.prototype.resolve = function(a, c, b) { const e = this.result, d = this.index; this.result = this.index = null; - return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), S.call(d, e, a || 100, c, b)) : e; + return e.length ? ("object" === typeof a && (b = a.enrich, c = a.offset, a = a.limit), Aa.call(d, e, a || 100, c, b)) : e; }; C(); -R.prototype.search = function(a, c, b, e) { +V.prototype.search = function(a, c, b, e) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = []; var f = []; @@ -863,7 +955,7 @@ R.prototype.search = function(a, c, b, e) { var u = []; for (let x = 0, r; x < m.length; x++) { r = m[x]; - if (E(r)) { + if (D(r)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (r.field && r.tag) { @@ -877,8 +969,8 @@ R.prototype.search = function(a, c, b, e) { } } else { v = Object.keys(r); - for (let D = 0, F, A; D < v.length; D++) { - if (F = v[D], A = r[F], A.constructor === Array) { + for (let E = 0, F, A; E < v.length; E++) { + if (F = v[E], A = r[F], A.constructor === Array) { for (z = 0; z < A.length; z++) { u.push(F, A[z]); } @@ -896,7 +988,7 @@ R.prototype.search = function(a, c, b, e) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - y = Ca.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); + y = Ia.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:y}); } } return e.length ? Promise.all(e).then(function(x) { @@ -911,14 +1003,14 @@ R.prototype.search = function(a, c, b, e) { } l || (l = this.field); u = !e && (this.worker || this.db) && []; - for (let x = 0, r, D, F; x < l.length; x++) { - D = l[x]; + for (let x = 0, r, E, F; x < l.length; x++) { + E = l[x]; let A; - E(D) || (A = D, D = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, h = A.suggest || h, g = this.store && (A.enrich || g)); + D(E) || (A = E, E = A.field, a = A.query || a, c = A.limit || c, n = A.offset || n, h = A.suggest || h, g = this.store && (A.enrich || g)); if (e) { r = e[x]; } else { - if (v = A || b, z = this.index.get(D), m && (v.enrich = !1), u) { + if (v = A || b, z = this.index.get(E), m && (v.enrich = !1), u) { u[x] = z.search(a, c, v); v && g && (v.enrich = g); continue; @@ -930,34 +1022,34 @@ R.prototype.search = function(a, c, b, e) { if (m && F) { v = []; z = 0; - for (let G = 0, H, Pa; G < m.length; G += 2) { + for (let G = 0, H, Wa; G < m.length; G += 2) { H = this.tag.get(m[G]); if (!H) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), h) { continue; } else { - return p ? d : new V(d); + return p ? d : new X(d); } } - if (Pa = (H = H && H.get(m[G + 1])) && H.length) { + if (Wa = (H = H && H.get(m[G + 1])) && H.length) { z++, v.push(H); } else if (!h) { - return p ? d : new V(d); + return p ? d : new X(d); } } if (z) { - r = va(r, v); + r = za(r, v); F = r.length; if (!F && !h) { - return p ? r : new V(r); + return p ? r : new X(r); } z--; } } if (F) { - f[t] = D, d.push(r), t++; + f[t] = E, d.push(r), t++; } else if (1 === l.length) { - return p ? d : new V(d); + return p ? d : new X(d); } } if (u) { @@ -967,7 +1059,7 @@ R.prototype.search = function(a, c, b, e) { }); } if (!t) { - return p ? d : new V(d); + return p ? d : new X(d); } if (y && (!g || !this.store)) { return d[0]; @@ -975,15 +1067,15 @@ R.prototype.search = function(a, c, b, e) { u = []; for (let x = 0, r; x < f.length; x++) { r = d[x]; - g && r.length && !r[0].doc && (r = T.call(this, r)); + g && r.length && !r[0].doc && (r = W.call(this, r)); if (y) { - return p ? r : new V(r); + return p ? r : new X(r); } d[x] = {field:f[x], result:r}; } - return k ? Da(d, c) : q ? Ea(d, a, this.index, this.field, this.C, q) : d; + return k ? Ja(d, c) : q ? Ka(d, a, this.index, this.field, this.C, q) : d; }; -function Ea(a, c, b, e, d, f) { +function Ka(a, c, b, e, d, f) { let g, k, h; for (let m = 0, n, t, p, q, y; m < a.length; m++) { n = a[m].result; @@ -998,21 +1090,21 @@ function Ea(a, c, b, e, d, f) { var l = J(n[u].doc, y); let z = g.encode(l); l = l.split(g.split); - for (let x = 0, r, D; x < z.length; x++) { + for (let x = 0, r, E; x < z.length; x++) { r = z[x]; - D = l[x]; + E = l[x]; let F; for (let A = 0, G; A < k.length; A++) { if (G = k[A], "strict" === h) { if (r === G) { - v += (v ? " " : "") + f.replace("$1", D); + v += (v ? " " : "") + f.replace("$1", E); F = !0; break; } } else { const H = r.indexOf(G); if (-1 < H) { - v += (v ? " " : "") + D.substring(0, H) + f.replace("$1", D.substring(H, G.length)) + D.substring(H + G.length); + v += (v ? " " : "") + E.substring(0, H) + f.replace("$1", E.substring(H, G.length)) + E.substring(H + G.length); F = !0; break; } @@ -1025,7 +1117,7 @@ function Ea(a, c, b, e, d, f) { } return a; } -function Da(a, c) { +function Ja(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -1044,7 +1136,7 @@ function Da(a, c) { } return b; } -function Ca(a, c, b, e, d) { +function Ia(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1053,11 +1145,11 @@ function Ca(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = T.call(this, f)); + d && (f = W.call(this, f)); return f; } } -function T(a) { +function W(a) { if (!this || !this.store) { return a; } @@ -1067,32 +1159,32 @@ function T(a) { } return c; } -;function R(a) { - if (!this || this.constructor !== R) { - return new R(a); +;function V(a) { + if (!this || this.constructor !== V) { + return new V(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; this.J = []; - this.key = (b = c.key || c.id) && W(b, this.J) || "id"; + this.key = (b = c.key || c.id) && La(b, this.J) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); this.A = (b = c.store || null) && b && !0 !== b && []; this.store = b && new Map(); - this.cache = (b = a.cache || null) && new X(b); + this.cache = (b = a.cache || null) && new Y(b); a.cache = !1; b = new Map(); let e = c.index || c.field || c; - E(e) && (e = [e]); + D(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], E(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new Y(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = W(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; + f = e[d], D(f) || (g = f, f = f.field), g = I(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = La(f, this.J), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].I = g.filter)), this.field[d] = f; } if (this.A) { a = c.store; - E(a) && (a = [a]); + D(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = W(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.U = g) : (this.A[d] = La(g, this.J), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].I = f.filter)); } } this.index = b; @@ -1108,14 +1200,14 @@ function T(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = W(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = La(g, this.J), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].I = f.filter)); this.T[d] = g; this.tag.set(g, new Map()); } } } } -function W(a, c) { +function La(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -1124,7 +1216,7 @@ function W(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -w = R.prototype; +w = V.prototype; w.append = function(a, c) { return this.add(a, c, !0); }; @@ -1180,7 +1272,7 @@ w.set = function(a, c) { this.store.set(a, c); return this; }; -w.searchCache = Fa; +w.searchCache = Ma; w.export = function(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; @@ -1196,17 +1288,17 @@ w.export = function(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = pa(this.reg); + f = sa(this.reg); c = null; break; case 1: d = "tag"; - f = na(this.tag, this.reg.size); + f = qa(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = la(this.store); + f = oa(this.store); c = null; break; case 3: @@ -1216,38 +1308,38 @@ w.export = function(a, c, b = 0, e = 0) { default: return; } - return Q.call(this, a, c, d, f, b, e); + return ua.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { + var b = a.split("."); + "json" === b[b.length - 1] && b.pop(); + a = 2 < b.length ? b[0] : ""; + b = 2 < b.length ? b[2] : b[1]; if (c) { "string" === typeof c && (c = JSON.parse(c)); - a = a.split("."); - "json" === a[a.length - 1] && a.pop(); - var b = 2 < a.length ? a[0] : ""; - a = 2 < a.length ? a[2] : a[1]; - if (b) { - return this.index.get(b).import(a, c); + if (a) { + return this.index.get(a).import(b, c); } - switch(a) { + switch(b) { case "reg": this.fastupdate = !1; - this.reg = qa(c, this.reg); + this.reg = ta(c, this.reg); for (let e = 0, d; e < this.field.length; e++) { d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; case "tag": - this.tag = oa(c, this.tag); + this.tag = ra(c, this.tag); break; case "doc": - this.store = ma(c, this.store); + this.store = pa(c, this.store); } } }; -ia(R.prototype); -function Fa(a, c, b) { +ja(V.prototype); +function Ma(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - this.cache || (this.cache = new X()); + this.cache || (this.cache = new Y()); let e = this.cache.get(a); if (!e) { e = this.search(a, c, b); @@ -1262,56 +1354,56 @@ function Fa(a, c, b) { } return e; } -function X(a) { +function Y(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -X.prototype.set = function(a, c) { +Y.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); }; -X.prototype.get = function(a) { +Y.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -X.prototype.remove = function(a) { +Y.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -X.prototype.clear = function() { +Y.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ga = {normalize:function(a) { +const Na = {normalize:function(a) { return a.toLowerCase(); }}; -const Ha = 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 Ia = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ja = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const Ka = {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 La = /[\x00-\x7F]+/g; -const Ma = /[\x00-\x7F]+/g; -const Na = /[\x00-\x7F]+/g; -var Oa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ga, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ha}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ha, matcher:Ia, replacer:Ja}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ha, replacer:Ja.concat([/(?!^)[aeo]/g, ""]), matcher:Ia}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Oa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Pa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Qa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +const Ra = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const Sa = /[\x00-\x7F]+/g; +const Ta = /[\x00-\x7F]+/g; +const Ua = /[\x00-\x7F]+/g; +var Va = {LatinExact:{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, matcher:Pa, replacer:Qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Oa, replacer:Qa.concat([/(?!^)[aeo]/g, ""]), matcher:Pa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = Ka[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ka[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = Ra[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Ra[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(La, " "); + return ("" + a).replace(Sa, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ma, ""); + return ("" + a).replace(Ta, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Na, " "); + return ("" + a).replace(Ua, " "); }}}; -const Qa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -Y.prototype.add = function(a, c, b, e) { +const 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}}}; +O.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -1323,14 +1415,14 @@ Y.prototype.add = function(a, c, b, e) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Ra(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : Ya(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var k = d; k > f; k--) { g = q.substring(f, k); - var h = this.score ? this.score(c, q, p, g, f) : Ra(t, e, p, d, f); + var h = this.score ? this.score(c, q, p, g, f) : Ya(t, e, p, d, f); Z(this, m, g, h, a, b); } } @@ -1339,7 +1431,7 @@ Y.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (k = d - 1; 0 < k; k--) { - g = q[k] + g, h = this.score ? this.score(c, q, p, g, k) : Ra(t, e, p, d, k), Z(this, m, g, h, a, b); + g = q[k] + g, h = this.score ? this.score(c, q, p, g, k) : Ya(t, e, p, d, k), Z(this, m, g, h, a, b); } g = ""; } @@ -1355,7 +1447,7 @@ Y.prototype.add = function(a, c, b, e) { for (d = C(), g = this.S, f = q, k = Math.min(n + 1, e - p), d[f] = 1, h = 1; h < k; h++) { if ((q = c[this.rtl ? e - 1 - p - h : p + h]) && !d[q]) { d[q] = 1; - const y = this.score ? this.score(c, f, p, q, h) : Ra(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; + const y = this.score ? this.score(c, f, p, q, h) : Ya(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), u = this.bidirectional && q > f; Z(this, l, u ? f : q, y, a, b, u ? q : f); } } @@ -1374,10 +1466,10 @@ function Z(a, c, b, e, d, f, g) { g ? (c = h || (c[b] = C()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = []), k = k[e] || (k[e] = []), f && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); } } -function Ra(a, c, b, e, d) { +function Ya(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; } -;Y.prototype.search = function(a, c, b) { +;O.prototype.search = function(a, c, b) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { @@ -1395,11 +1487,11 @@ function Ra(a, c, b, e, d) { b = a.length; c = c || (k ? 100 : 0); if (1 === b) { - return g = c, (c = Sa(this, a[0], "")) && c.length ? S.call(this, c, g, d) : []; + return g = c, (c = Za(this, a[0], "")) && c.length ? Aa.call(this, c, g, d) : []; } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return g = c, (c = Sa(this, a[0], a[1])) && c.length ? S.call(this, c, g, d) : []; + return g = c, (c = Za(this, a[0], a[1])) && c.length ? Aa.call(this, c, g, d) : []; } k = C(); let l = 0; @@ -1411,7 +1503,7 @@ function Ra(a, c, b, e, d) { for (let q, y; l < b; l++) { if ((y = a[l]) && !k[y]) { k[y] = 1; - q = Sa(this, y, m); + q = Za(this, y, m); a: { f = q; var n = e, t = g, p = h; @@ -1448,22 +1540,22 @@ function Ra(a, c, b, e, d) { e = a.length; m = a; if (1 < e) { - m = ta(a, h, c, d, g); + m = xa(a, h, c, d, g); } else if (1 === e) { - g = S.call(null, a[0], c, d); + g = Aa.call(null, a[0], c, d); break a; } g = m; } return g; }; -function Sa(a, c, b) { +function Za(a, c, b) { let e; b && (e = a.bidirectional && c > b) && (e = b, b = c, c = e); a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; } -;Y.prototype.remove = function(a, c) { +;O.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -1478,14 +1570,14 @@ function Sa(a, c, b) { } } } else { - Ta(this.map, a), this.depth && Ta(this.ctx, a); + $a(this.map, a), this.depth && $a(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Ta(a, c) { +function $a(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1500,24 +1592,24 @@ function Ta(a, c) { } } else { for (let e of a.entries()) { - const d = e[0], f = Ta(e[1], c); + const d = e[0], f = $a(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function Y(a, c) { - if (!this || this.constructor !== Y) { - return new Y(a); +;function O(a, c) { + if (!this || this.constructor !== O) { + return new O(a); } if (a) { - var b = E(a) ? a : a.preset; - b && (Qa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Qa[b], a)); + var b = D(a) ? a : a.preset; + b && (Xa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Xa[b], a)); } else { a = {}; } b = a.context; - const e = !0 === b ? {depth:1} : b || {}, d = E(a.encoder) ? Oa[a.encoder] : a.encode || a.encoder || Ga; + const e = !0 === b ? {depth:1} : b || {}, d = D(a.encoder) ? Va[a.encoder] : a.encode || a.encoder || Na; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = (b = a.tokenize) && "default" !== b && b || "strict"; @@ -1531,10 +1623,10 @@ function Ta(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.S = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new X(b); + this.cache = (b = a.cache || null) && new Y(b); this.priority = a.priority || 4; } -w = Y.prototype; +w = O.prototype; w.clear = function() { this.map.clear(); this.ctx.clear(); @@ -1552,7 +1644,7 @@ w.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function Ua(a) { +function ab(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1560,7 +1652,7 @@ function Ua(a) { } } else { for (const b of a) { - const e = b[0], d = Ua(b[1]); + const e = b[0], d = ab(b[1]); d ? c += d : a.delete(e); } } @@ -1570,17 +1662,17 @@ w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Ua(this.map); - this.depth && Ua(this.ctx); + ab(this.map); + this.depth && ab(this.ctx); return this; }; -w.searchCache = Fa; +w.searchCache = Ma; w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = pa(this.reg); + f = sa(this.reg); break; case 1: d = "cfg"; @@ -1588,29 +1680,29 @@ w.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = la(this.map, this.reg.size); + f = oa(this.map, this.reg.size); break; case 3: d = "ctx"; - f = na(this.ctx, this.reg.size); + f = qa(this.ctx, this.reg.size); break; default: return; } - return Q.call(this, a, c, d, f, b, e); + return ua.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { if (c) { - switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { + switch("string" === typeof c && (c = JSON.parse(c)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = qa(c, this.reg); + this.reg = ta(c, this.reg); break; case "map": - this.map = ma(c, this.map); + this.map = pa(c, this.map); break; case "ctx": - this.ctx = oa(c, this.ctx); + this.ctx = ra(c, this.ctx); } } }; @@ -1664,7 +1756,7 @@ w.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ia(Y.prototype); -export default {Index:Y, Charset:Oa, Encoder:K, Document:R, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +ja(O.prototype); +export default {Index:O, Charset:Va, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=Y;export const Charset=Oa;export const Encoder=K;export const Document=R;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=O;export const Charset=Va;export const Encoder=K;export const Document=V;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index b473fb9..270b2ab 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,12 +1,12 @@ /**! - * FlexSearch.js v0.8.111 (Bundle) + * FlexSearch.js v0.8.113 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var v;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&e===d)return function(k){return a(b(k))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return"undefined"===d?c:a}function C(){return Object.create(null)}function E(a){return"string"===typeof a} -function H(a){return"object"===typeof a}function J(a,c){if(E(c))a=a[c];else for(let b=0;a&&bthis.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d -this.R&&(this.G.clear(),this.L=this.L/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.K&&(this.F.set(a,b),this.F.size>this.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};function ia(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}let N,ja;const O={},P={};function ka(a){N=0;O[a]=P[a]} -function M(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);N||(N=setTimeout(ka,0,a),ja=Date.now());P[a]||(P[a]=O[a]=1E3);if(!--O[a]){O[a]=P[a]=P[a]*this.priority*this.priority*3/(Date.now()-ja)|0||1;N=clearTimeout(N);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};function la(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function ma(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} -function ua(a,c,b){const e=[],d=C();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?T.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?T.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ua(a,b,e),e=0));return f?this.resolve(b,e,d):this};V.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=U(this,"and",arguments);return xa.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; -function xa(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=ta(a,c,b,e,g),f?d?T.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};V.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=U(this,"xor",arguments);return ya.call(this,a,c,b,e,d,f,g)}; -function ya(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=za.call(this,a,b,e,f,this.h),f?d?T.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} -function za(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hthis.R&&(this.F.clear(),this.K=this.K/1.1|0));return b};function L(a){a.H=null;a.F.clear();a.G.clear()};let M,N;async function ia(a){a=a.data;var c=a.task;const b=a.id;let e=a.args;switch(c){case "init":N=a.options||{};(c=a.factory)?(Function("return "+c)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:b});break;default:let d;"export"===c&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===c?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[c].apply(M,e))&&d.then&&(d=await d);postMessage("search"===c?{id:b,msg:d}:{id:b})}};function ja(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let Q,ka;const R={},S={};function la(a){Q=0;R[a]=S[a]} +function P(a){this[a+"Async"]=function(){const c=arguments;var b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);Q||(Q=setTimeout(la,0,a),ka=Date.now());S[a]||(S[a]=R[a]=1E3);if(!--R[a]){R[a]=S[a]=S[a]*this.priority*this.priority*3/(Date.now()-ka)|0||1;Q=clearTimeout(Q);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let T=0; +function ma(a={}){function c(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=C();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++T]=function(){h(d)};d.worker.postMessage({id:T,task:"init",factory:b,options:a})});this.worker.postMessage({task:"init",factory:b,options:a});return this}}if(!this||this.constructor!==ma)return new ma(a);let b="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;b&&(b=b.toString());const e="undefined"===typeof window,d=this,f=na(b,e,a.worker);return f.then?f.then(function(g){return c.call(d,g)}):c.call(this,f)}U("add");U("append");U("search");U("update");U("remove");U("clear");U("export");U("import");ja(ma.prototype); +function U(a){ma.prototype[a]=function(){const c=this,b=[].slice.call(arguments);var e=b[b.length-1];let d;"function"===typeof e&&(d=e,b.pop());e=new Promise(function(f){"export"===a&&"function"===typeof b[0]&&(b[0]=null);c.h[++T]=f;c.worker.postMessage({task:a,id:T,args:b})});return d?(e.then(d),this):e}} +function na(a,c,b){return c?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+ia.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof b?b:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function oa(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function pa(a,c){c||(c=new Map);for(let b=0,e;bb||e?g.slice(e,b+e):g;else{if(ab||e)g=g.slice(e,b+e)}return g} +function ya(a,c,b){const e=[],d=C();let f;var g=a.length;let k;for(let h=g-1;0<=h;h--)if(k=(g=a[h])&&g.length)for(let l=0;lc?c?a.slice(b,b+c):a.slice(b):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){b-=k;continue}bc&&(g=g.slice(0,c),k=c);if(!d.length&&k>=c)return e?W.call(this,g):g;d.push(g);c-=k;if(!c)break}d=1a.length?this.result=a[0]:(this.result=ya(a,b,e),e=0));return f?this.resolve(b,e,d):this};X.prototype.and=function(){let a=this.result.length,c,b,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,c=f.limit,b=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ba(this,"and",arguments);return Da.call(this,f,g,k,h,l,m,n)}return d?this.resolve(c,b,e):this}; +function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(c=aa(a))return this.result=xa(a,c,b,e,g),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(b,e,d):this};X.prototype.xor=function(){const {O:a,P:c,limit:b,offset:e,enrich:d,resolve:f,suggest:g}=Ba(this,"xor",arguments);return Ea.call(this,a,c,b,e,d,f,g)}; +function Ea(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} +function Fa(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;hb||e)a=a.slice(e,e+b);d&&(a=T.call(this,a));return a}} -function T(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -X.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};X.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};X.prototype.clear=function(){this.cache.clear();this.h=""};const Ga={normalize:function(a){return a.toLowerCase()}};const Ha=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 Ia=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ja=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ka={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 La=/[\x00-\x7F]+/g;const Ma=/[\x00-\x7F]+/g;const Na=/[\x00-\x7F]+/g;var Pa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ga,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ha},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ha,matcher:Ia,replacer:Ja},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ha,replacer:Ja.concat([/(?!^)[aeo]/g,""]),matcher:Ia},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;k--){g=q.substring(f,k);var h=this.score?this.score(c,q,p,g,f):Ra(t,e,p,d,f);Z(this,m,g,h,a,b)}break}case "reverse":if(1< -d){for(k=d-1;0g?0:1),e,p,k-1,h-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Ra(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};Y.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 Ta(this.map,a),this.depth&&Ta(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Ta(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function Ua(a){let c=0;if(a.constructor===Array)for(let b=0,e;bb||e)a=a.slice(e,e+b);d&&(a=W.call(this,a));return a}} +function W(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Y.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Y.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Na={normalize:function(a){return a.toLowerCase()}};const Oa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Pa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Qa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ra={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Sa=/[\x00-\x7F]+/g;const Ta=/[\x00-\x7F]+/g;const Ua=/[\x00-\x7F]+/g;var Wa={LatinExact:{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,matcher:Pa,replacer:Qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:Oa,replacer:Qa.concat([/(?!^)[aeo]/g,""]),matcher:Pa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;k--){g=q.substring(f,k);var h=this.score?this.score(c,q,p,g,f):Ya(t,e,p,d,f);Z(this,m,g,h,a,b)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,p,k-1,h-1),w=this.bidirectional&&q>f;Z(this,l,w?f:q,y,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,c,b,e,d,f,g){let k=g?a.ctx:a.map,h;if(!c[b]||g&&!(h=c[b])[g])g?(c=h||(c[b]=C()),c[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):c[b]=1,(h=k.get(b))?k=h:k.set(b,k=[]),k=k[e]||(k[e]=[]),f&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function Ya(a,c,b,e,d){return b&&1b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else $a(this.map,a),this.depth&&$a(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function $a(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)};function ab(a){let c=0;if(a.constructor===Array)for(let b=0,e;b c && (c = Math.max(c + e, 0)); c < e; c++) { - var g = d[c]; - if (g === b || Object.is(g, b)) { + var f = d[c]; + if (f === b || Object.is(f, b)) { return !0; } } @@ -830,8 +830,8 @@ function I(a, b, c) { if ("undefined" !== e) { if (c) { if ("function" === e && d === e) { - return function(g) { - return a(c(g)); + return function(f) { + return a(c(f)); }; } b = a.constructor; @@ -909,15 +909,15 @@ function Ga(a) { if (!this || this.constructor !== Ga) { var b = Function.prototype.bind, c = b.apply, d = [null], e = d.concat; if (arguments instanceof Array) { - var g = arguments; + var f = arguments; } else { - g = w(arguments); - for (var f, h = []; !(f = g.next()).done;) { - h.push(f.value); + f = w(arguments); + for (var g, h = []; !(g = f.next()).done;) { + h.push(g.value); } - g = h; + f = h; } - return new (c.call(b, Ga, e.call(d, g)))(); + return new (c.call(b, Ga, e.call(d, f)))(); } for (b = 0; b < arguments.length; b++) { this.assign(arguments[b]); @@ -942,7 +942,7 @@ u.assign = function(a) { } try { this.split = new RegExp("[" + (b ? "^" : "") + d + "]+", "u"); - } catch (g) { + } catch (f) { console.error("Your split configuration:", c, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { @@ -952,7 +952,7 @@ u.assign = function(a) { } else { try { this.split = I(this.split, Ba); - } catch (g) { + } catch (f) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } this.numeric = I(a.numeric, I(this.numeric, !0)); @@ -1051,15 +1051,15 @@ u.encode = function(a) { this.normalize && ("function" === typeof this.normalize ? a = this.normalize(a) : a = Fa ? a.normalize("NFKD").replace(Fa, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); this.numeric && 3 < a.length && (a = a.replace(Da, "$1 $2").replace(Ea, "$1 $2").replace(Ca, "$1 ")); - for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, g = 0, f = void 0, h = void 0; g < e.length; g++) { - if ((f = h = e[g]) && !(f.length < this.minlength)) { + for (var c = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), d = [], e = this.split || "" === this.split ? a.split(this.split) : a, f = 0, g = void 0, h = void 0; f < e.length; f++) { + if ((g = h = e[f]) && !(g.length < this.minlength)) { if (c) { - d.push(f); + d.push(g); } else { - if (!this.filter || !this.filter.has(f)) { - if (this.cache && f.length <= this.H) { + if (!this.filter || !this.filter.has(g)) { + if (this.cache && g.length <= this.H) { if (this.D) { - var k = this.C.get(f); + var k = this.C.get(g); if (k || "" === k) { k && d.push(k); continue; @@ -1068,26 +1068,26 @@ u.encode = function(a) { this.D = setTimeout(N, 50, this); } } - this.stemmer && 2 < f.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), f = f.replace(this.N, function(q) { + this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, function(q) { return b.stemmer.get(q); - }), f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); - if (f && (this.mapper || this.dedupe && 1 < f.length)) { + }), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); + if (g && (this.mapper || this.dedupe && 1 < g.length)) { k = ""; - for (var l = 0, m = "", n = void 0, p = void 0; l < f.length; l++) { - n = f.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); + for (var l = 0, m = "", n = void 0, p = void 0; l < g.length; l++) { + n = g.charAt(l), n === m && this.dedupe || ((p = this.mapper && this.mapper.get(n)) || "" === p ? p === m && this.dedupe || !(m = p) || (k += p) : k += m = n); } - f = k; + g = k; } - this.matcher && 1 < f.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), f = f.replace(this.M, function(q) { + this.matcher && 1 < g.length && (this.M || (this.M = new RegExp("(" + this.h + ")", "g")), g = g.replace(this.M, function(q) { return b.matcher.get(q); })); - if (f && this.replacer) { - for (k = 0; f && k < this.replacer.length; k += 2) { - f = f.replace(this.replacer[k], this.replacer[k + 1]); + if (g && this.replacer) { + for (k = 0; g && k < this.replacer.length; k += 2) { + g = g.replace(this.replacer[k], this.replacer[k + 1]); } } - this.cache && h.length <= this.H && (this.C.set(h, f), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); - f && d.push(f); + this.cache && h.length <= this.H && (this.C.set(h, g), this.C.size > this.T && (this.C.clear(), this.H = this.H / 1.1 | 0)); + g && d.push(g); } } } @@ -1103,9 +1103,9 @@ function N(a) { } ;var O, P; function Ha(a) { - var b, c, d, e, g; - return ta(function(f) { - switch(f.h) { + var b, c, d, e, f, g; + return ta(function(h) { + switch(h.h) { case 1: a = a.data; b = a.task; @@ -1118,51 +1118,57 @@ function Ha(a) { postMessage({id:c}); break; default: - f.h = 2; + h.h = 2; return; - }f.h = 0; + }h.h = 0; break; case 2: if ("export" === b) { if (!P.export || "function" !== typeof P.export) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - d = [P.export]; + d[1] ? (d[0] = P.export, d[2] = 0, d[3] = 1) : d = null; } if ("import" === b) { if (!P.import || "function" !== typeof P.import) { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - return E(f, P.import.call(O, O), 5); + if (!d[0]) { + h.h = 5; + break; + } + return E(h, P.import.call(O, d[0]), 9); } - g = O[b].apply(O, d); - if (!g.then) { - f.h = 5; + f = d && O[b].apply(O, d); + if (!f || !f.then) { + h.h = 5; break; } - return E(f, g, 7); + return E(h, f, 7); case 7: - g = f.D; - f.h = 5; + f = h.D; + h.h = 5; break; + case 9: + g = h.D, O.import(d[0], g); case 5: - postMessage("search" === b ? {id:c, msg:g} : {id:c}), f.h = 0; + postMessage("search" === b ? {id:c, msg:f} : {id:c}), h.h = 0; } }); } ;function Ia(a) { - La.call(a, "add"); - La.call(a, "append"); - La.call(a, "search"); - La.call(a, "update"); - La.call(a, "remove"); + Ja.call(a, "add"); + Ja.call(a, "append"); + Ja.call(a, "search"); + Ja.call(a, "update"); + Ja.call(a, "remove"); } var Ma, Na, Oa = {}, Pa = {}; function Qa(a) { Ma = 0; Oa[a] = Pa[a]; } -function La(a) { +function Ja(a) { this[a + "Async"] = function() { var b = arguments, c = b[b.length - 1]; if ("function" === typeof c) { @@ -1175,15 +1181,15 @@ function La(a) { Oa[a] = Pa[a] = Pa[a] * this.priority * this.priority * 3 / (Date.now() - Na) | 0 || 1; Ma = clearTimeout(Ma); var e = this; - return new Promise(function(f) { + return new Promise(function(g) { setTimeout(function() { - f(e[a + "Async"].apply(e, b)); + g(e[a + "Async"].apply(e, b)); }, 0); }); } - var g = this[a].apply(this, b); - c = g.then ? g : new Promise(function(f) { - return f(g); + var f = this[a].apply(this, b); + c = f.then ? f : new Promise(function(g) { + return g(f); }); d && c.then(d); return c; @@ -1191,13 +1197,13 @@ function La(a) { } ;var Ra = 0; function Sa(a) { - function b(f) { + function b(g) { function h(k) { k = k.data || k; var l = k.id, m = l && e.h[l]; m && (m(k.msg), delete e.h[l]); } - this.worker = f; + this.worker = g; this.h = J(); if (this.worker) { d ? this.worker.on("message", h) : this.worker.onmessage = h; @@ -1219,10 +1225,10 @@ function Sa(a) { } var c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); - var d = "undefined" === typeof window, e = this, g = Ta(c, d, a.worker); - return g.then ? g.then(function(f) { - return b.call(e, f); - }) : b.call(this, g); + var d = "undefined" === typeof window, e = this, f = Ta(c, d, a.worker); + return f.then ? f.then(function(g) { + return b.call(e, g); + }) : b.call(this, f); } T("add"); T("append"); @@ -1232,24 +1238,24 @@ T("remove"); T("clear"); T("export"); T("import"); +Ia(Sa.prototype); function T(a) { - Sa.prototype[a] = Sa.prototype[a + "Async"] = function() { - var b = this, c = arguments, d, e, g, f, h; - return ta(function(k) { - d = b; - e = [].slice.call(c); - g = e[e.length - 1]; - "function" === typeof g && (f = g, e.splice(e.length - 1, 1)); - h = new Promise(function(l) { - d.h[++Ra] = l; - d.worker.postMessage({task:a, id:Ra, args:e}); - }); - return f ? (h.then(f), k.return(b)) : k.return(h); + Sa.prototype[a] = function() { + var b = this, c = [].slice.call(arguments), d = c[c.length - 1]; + if ("function" === typeof d) { + var e = d; + c.pop(); + } + d = new Promise(function(f) { + "export" === a && "function" === typeof c[0] && (c[0] = null); + b.h[++Ra] = f; + b.worker.postMessage({task:a, id:Ra, args:c}); }); + return e ? (d.then(e), this) : d; }; } function Ta(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=" + Ha.toString()], {type:"text/javascript"}))) : new window.Worker(K(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + 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=" + Ha.toString()], {type:"text/javascript"}))) : new window.Worker("string" === typeof c ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } ;function Ua(a, b) { @@ -1304,28 +1310,28 @@ function Za(a, b) { } return b; } -function $a(a, b, c, d, e, g, f) { - f = void 0 === f ? 0 : f; +function $a(a, b, c, d, e, f, g) { + g = void 0 === g ? 0 : g; var h = d && d.constructor === Array, k = h ? d.shift() : d; if (!k) { - return this.export(a, b, e, g + 1); + return this.export(a, b, e, f + 1); } - if ((k = a((b ? b + "." : "") + (f + 1) + "." + c, JSON.stringify(k))) && k.then) { + if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { var l = this; return k.then(function() { - return $a.call(l, a, b, c, h ? d : null, e, g, f + 1); + return $a.call(l, a, b, c, h ? d : null, e, f, g + 1); }); } - return $a.call(this, a, b, c, h ? d : null, e, g, f + 1); + return $a.call(this, a, b, c, h ? d : null, e, f, g + 1); } ;function ab(a, b, c, d) { - for (var e = [], g = 0, f; g < a.index.length; g++) { - if (f = a.index[g], b >= f.length) { - b -= f.length; + for (var e = [], f = 0, g; f < a.index.length; f++) { + if (g = a.index[f], b >= g.length) { + b -= g.length; } else { - b = f[d ? "splice" : "slice"](b, c); - if (f = b.length) { - if (e = e.length ? e.concat(b) : b, c -= f, d && (a.length -= f), !c) { + b = g[d ? "splice" : "slice"](b, c); + if (g = b.length) { + if (e = e.length ? e.concat(b) : b, c -= g, d && (a.length -= g), !c) { break; } } @@ -1360,21 +1366,21 @@ function bb(a) { } if ("indexOf" === d) { return function(e) { - for (var g = 0, f = 0, h, k; f < b.index.length; f++) { - h = b.index[f]; + for (var f = 0, g = 0, h, k; g < b.index.length; g++) { + h = b.index[g]; k = h.indexOf(e); if (0 <= k) { - return g + k; + return f + k; } - g += h.length; + f += h.length; } return -1; }; } if ("includes" === d) { return function(e) { - for (var g = 0; g < b.index.length; g++) { - if (b.index[g].includes(e)) { + for (var f = 0; f < b.index.length; f++) { + if (b.index[f].includes(e)) { return !0; } } @@ -1382,13 +1388,13 @@ function bb(a) { }; } if ("slice" === d) { - return function(e, g) { - return ab(b, e || 0, g || b.length, !1); + return function(e, f) { + return ab(b, e || 0, f || b.length, !1); }; } if ("splice" === d) { - return function(e, g) { - return ab(b, e || 0, g || b.length, !0); + return function(e, f) { + return ab(b, e || 0, f || b.length, !0); }; } if ("constructor" === d) { @@ -1458,14 +1464,14 @@ u.clear = V.prototype.clear = function() { this.size = 0; }; u.values = V.prototype.values = function eb() { - var b, c = this, d, e, g; - return ra(eb, function(f) { - switch(f.h) { + var b, c = this, d, e, f; + return ra(eb, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + g.h = 0; break; } d = w(c.h[b].values()); @@ -1473,25 +1479,25 @@ u.values = V.prototype.values = function eb() { case 5: if (e.done) { b++; - f.h = 2; + g.h = 2; break; } - g = e.value; - return E(f, g, 6); + f = e.value; + return E(g, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), g.h = 5; } }); }; u.keys = V.prototype.keys = function fb() { - var b, c = this, d, e, g; - return ra(fb, function(f) { - switch(f.h) { + var b, c = this, d, e, f; + return ra(fb, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + g.h = 0; break; } d = w(c.h[b].keys()); @@ -1499,25 +1505,25 @@ u.keys = V.prototype.keys = function fb() { case 5: if (e.done) { b++; - f.h = 2; + g.h = 2; break; } - g = e.value; - return E(f, g, 6); + f = e.value; + return E(g, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), g.h = 5; } }); }; u.entries = V.prototype.entries = function gb() { - var b, c = this, d, e, g; - return ra(gb, function(f) { - switch(f.h) { + var b, c = this, d, e, f; + return ra(gb, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - f.h = 0; + g.h = 0; break; } d = w(c.h[b].entries()); @@ -1525,13 +1531,13 @@ u.entries = V.prototype.entries = function gb() { case 5: if (e.done) { b++; - f.h = 2; + g.h = 2; break; } - g = e.value; - return E(f, g, 6); + f = e.value; + return E(g, f, 6); case 6: - e = d.next(), f.h = 5; + e = d.next(), g.h = 5; } }); }; @@ -1556,41 +1562,41 @@ function cb() { } for (var d = 0, e; d < this.field.length; d++) { e = this.J[d]; - var g = this.index.get(this.field[d]); + var f = this.index.get(this.field[d]); if ("function" === typeof e) { - (e = e(b)) && g.add(a, e, !1, !0); + (e = e(b)) && f.add(a, e, !1, !0); } else { - var f = e.R; - if (!f || f(b)) { - e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), hb(b, e, this.S, 0, g, a, e[0], c); + var g = e.R; + if (!g || g(b)) { + e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), hb(b, e, this.S, 0, f, a, e[0], c); } } } if (this.tag) { for (d = 0; d < this.L.length; d++) { - f = this.L[d]; + g = this.L[d]; var h = this.aa[d]; - g = this.tag.get(h); + f = this.tag.get(h); e = J(); - if ("function" === typeof f) { - if (f = f(b), !f) { + if ("function" === typeof g) { + if (g = g(b), !g) { continue; } } else { - var k = f.R; + var k = g.R; if (k && !k(b)) { continue; } - f.constructor === String && (f = "" + f); - f = ya(b, f); + g.constructor === String && (g = "" + g); + g = ya(b, g); } - if (g && f) { - for (K(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { - var l = f[h]; + if (f && g) { + for (K(g) && (g = [g]), h = 0, k = void 0; h < g.length; h++) { + var l = g[h]; if (!e[l]) { e[l] = 1; var m; - (m = g.get(l)) ? k = m : g.set(l, k = []); + (m = f.get(l)) ? k = m : f.set(l, k = []); if (!c || !k.includes(a)) { if (k.length === Math.pow(2, 31) - 1) { m = new bb(k); @@ -1599,7 +1605,7 @@ function cb() { p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); } } - g.set(l, k = m); + f.set(l, k = m); } k.push(a); this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); @@ -1607,7 +1613,7 @@ function cb() { } } } else { - g || console.warn("Tag '" + h + "' was not found"); + f || console.warn("Tag '" + h + "' was not found"); } } } @@ -1615,11 +1621,11 @@ function cb() { if (this.I) { var q = J(); for (c = 0; c < this.I.length; c++) { - if (d = this.I[c], g = d.R, !g || g(b)) { - g = void 0; + if (d = this.I[c], f = d.R, !f || f(b)) { + f = void 0; if ("function" === typeof d) { - g = d(b); - if (!g) { + f = d(b); + if (!f) { continue; } d = [d.ja]; @@ -1627,19 +1633,20 @@ function cb() { q[d] = b[d]; continue; } - ib(b, q, d, 0, d[0], g); + ib(b, q, d, 0, d[0], f); } } } this.store.set(a, q || b); } + this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function ib(a, b, c, d, e, g) { +function ib(a, b, c, d, e, f) { a = a[e]; if (d === c.length - 1) { - b[e] = g || a; + b[e] = f || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { @@ -1650,33 +1657,33 @@ function ib(a, b, c, d, e, g) { } } } -function hb(a, b, c, d, e, g, f, h) { - if (a = a[f]) { +function hb(a, b, c, d, e, f, g, h) { + if (a = a[g]) { if (d === b.length - 1) { if (a.constructor === Array) { if (c[d]) { for (b = 0; b < a.length; b++) { - e.add(g, a[b], !0, !0); + e.add(f, a[b], !0, !0); } return; } a = a.join(" "); } - e.add(g, a, h, !0); + e.add(f, a, h, !0); } else { if (a.constructor === Array) { - for (f = 0; f < a.length; f++) { - hb(a, b, c, d, e, g, f, h); + for (g = 0; g < a.length; g++) { + hb(a, b, c, d, e, f, g, h); } } else { - f = b[++d], hb(a, b, c, d, e, g, f, h); + g = b[++d], hb(a, b, c, d, e, f, g, h); } } } else { - e.db && e.remove(g); + e.db && e.remove(f); } } -;function jb(a, b, c, d, e, g, f) { +;function jb(a, b, c, d, e, f, g) { var h = a.length, k = [], l; var m = J(); for (var n = 0, p = void 0, q; n < b; n++) { @@ -1686,8 +1693,8 @@ function hb(a, b, c, d, e, g, f, h) { q = p[x]; (l = m[q]) ? m[q]++ : (l = 0, m[q] = 1); l = k[l] || (k[l] = []); - if (!f) { - var r = n + (t || !e ? 0 : g || 0); + if (!g) { + var r = n + (t || !e ? 0 : f || 0); l = l[r] || (l[r] = []); } l.push(q); @@ -1697,27 +1704,27 @@ function hb(a, b, c, d, e, g, f, h) { } if (a = k.length) { if (e) { - k = 1 < k.length ? kb(k, c, d, f, g) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + k = 1 < k.length ? kb(k, c, d, g, f) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { if (a < h) { return []; } k = k[a - 1]; if (c || d) { - if (f) { + if (g) { if (k.length > c || d) { k = k.slice(d, c + d); } } else { e = []; - for (g = 0; g < k.length; g++) { - if (f = k[g], f.length > d) { - d -= f.length; + for (f = 0; f < k.length; f++) { + if (g = k[f], g.length > d) { + d -= g.length; } else { - if (f.length > c || d) { - f = f.slice(d, c + d), c -= f.length, d && (d -= f.length); + if (g.length > c || d) { + g = g.slice(d, c + d), c -= g.length, d && (d -= g.length); } - e.push(f); + e.push(g); if (!c) { break; } @@ -1731,18 +1738,18 @@ function hb(a, b, c, d, e, g, f, h) { return k; } function kb(a, b, c, d, e) { - var g = [], f = J(), h = a.length, k; + var f = [], g = J(), h = a.length, k; if (d) { for (e = h - 1; 0 <= e; e--) { if (k = (d = a[e]) && d.length) { for (h = 0; h < k; h++) { var l = d[h]; - if (!f[l]) { - if (f[l] = 1, c) { + if (!g[l]) { + if (g[l] = 1, c) { c--; } else { - if (g.push(l), g.length === b) { - return g; + if (f.push(l), f.length === b) { + return f; } } } @@ -1755,14 +1762,14 @@ function kb(a, b, c, d, e) { for (var q = 0; q < n.length; q++) { if (k = (d = n[q]) && d.length) { for (var t = 0; t < k; t++) { - if (l = d[t], !f[l]) { - if (f[l] = 1, c) { + if (l = d[t], !g[l]) { + if (g[l] = 1, c) { c--; } else { var x = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; - (g[x] || (g[x] = [])).push(l); + (f[x] || (f[x] = [])).push(l); if (++p === b) { - return g; + return f; } } } @@ -1771,13 +1778,13 @@ function kb(a, b, c, d, e) { } } } - return g; + return f; } function lb(a, b, c) { - for (var d = J(), e = [], g = 0, f; g < b.length; g++) { - f = b[g]; - for (var h = 0; h < f.length; h++) { - d[f[h]] = 1; + for (var d = J(), e = [], f = 0, g; f < b.length; f++) { + g = b[f]; + for (var h = 0; h < g.length; h++) { + d[g[h]] = 1; } } if (c) { @@ -1786,8 +1793,8 @@ function lb(a, b, c) { } } else { for (b = 0; b < a.result.length; b++) { - for (c = a.result[b], f = 0; f < c.length; f++) { - g = c[f], d[g] && ((e[b] || (e[b] = [])).push(g), d[g] = 0); + for (c = a.result[b], g = 0; g < c.length; g++) { + f = c[g], d[f] && ((e[b] || (e[b] = [])).push(f), d[f] = 0); } } } @@ -1800,20 +1807,20 @@ function lb(a, b, c) { if (1 === a.length) { return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? X.call(this, a) : a; } - for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { - if ((f = a[g]) && (h = f.length)) { + for (var e = [], f = 0, g = void 0, h = void 0; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { if (c) { if (c >= h) { c -= h; continue; } - c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); + c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); } - h > b && (f = f.slice(0, b), h = b); + h > b && (g = g.slice(0, b), h = b); if (!e.length && h >= b) { - return d ? X.call(this, f) : f; + return d ? X.call(this, g) : g; } - e.push(f); + e.push(g); b -= h; if (!b) { break; @@ -1834,7 +1841,7 @@ function lb(a, b, c) { return a[b].apply(a, d); } d = []; - for (var e = [], g = 0, f = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { + for (var e = [], f = 0, g = 0, h, k, l, m = 0, n = void 0; m < c.length; m++) { if (n = c[m]) { var p = void 0; if (n.constructor === Y) { @@ -1842,7 +1849,7 @@ function lb(a, b, c) { } else if (n.constructor === Array) { p = n; } else { - if (g = n.limit || 0, f = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { + if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, k = n.resolve, h = n.enrich && k, n.index) { n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = k, n.enrich = h; } else if (n.and) { p = a.and(n.and); @@ -1866,25 +1873,25 @@ function lb(a, b, c) { } } } - return {W:d, $:e, limit:g, offset:f, enrich:h, resolve:k, suggest:l}; + return {W:d, $:e, limit:f, offset:g, enrich:h, resolve:k, suggest:l}; } ;Y.prototype.or = function() { var a = nb(this, "or", arguments); return ob.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve); }; -function ob(a, b, c, d, e, g) { +function ob(a, b, c, d, e, f) { if (b.length) { - var f = this; + var g = this; return Promise.all(b).then(function(h) { a = []; for (var k = 0, l = void 0; k < h.length; k++) { (l = h[k]).length && (a[k] = l); } - return ob.call(f, a, [], c, d, e, g); + return ob.call(g, a, [], c, d, e, f); }); } a.length && (this.result.length && a.push(this.result), 2 > a.length ? this.result = a[0] : (this.result = kb(a, c, d, !1, this.h), d = 0)); - return g ? this.resolve(c, d, e) : this; + return f ? this.resolve(c, d, e) : this; } ;Y.prototype.and = function() { var a = this.result.length; @@ -1895,12 +1902,12 @@ function ob(a, b, c, d, e, g) { var c = b.resolve; var d = b.limit; var e = b.offset; - var g = b.enrich && c; + var f = b.enrich && c; } } - return a ? (a = nb(this, "and", arguments), pb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest)) : c ? this.resolve(d, e, g) : this; + return a ? (a = nb(this, "and", arguments), pb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest)) : c ? this.resolve(d, e, f) : this; }; -function pb(a, b, c, d, e, g, f) { +function pb(a, b, c, d, e, f, g) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -1908,7 +1915,7 @@ function pb(a, b, c, d, e, g, f) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return pb.call(h, a, [], c, d, e, g, f); + return pb.call(h, a, [], c, d, e, f, g); }); } if (a.length) { @@ -1916,20 +1923,20 @@ function pb(a, b, c, d, e, g, f) { this.result = a[0]; } else { if (b = za(a)) { - return this.result = jb(a, b, c, d, f, this.h, g), g ? e ? X.call(this.index, this.result) : this.result : this; + return this.result = jb(a, b, c, d, g, this.h, f), f ? e ? X.call(this.index, this.result) : this.result : this; } this.result = []; } } else { - f || (this.result = a); + g || (this.result = a); } - return g ? this.resolve(c, d, e) : this; + return f ? this.resolve(c, d, e) : this; } ;Y.prototype.xor = function() { var a = nb(this, "xor", arguments); return qb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); }; -function qb(a, b, c, d, e, g, f) { +function qb(a, b, c, d, e, f, g) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -1937,28 +1944,28 @@ function qb(a, b, c, d, e, g, f) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return qb.call(h, a, [], c, d, e, g, f); + return qb.call(h, a, [], c, d, e, f, g); }); } if (a.length) { if (this.result.length && a.unshift(this.result), 2 > a.length) { this.result = a[0]; } else { - return this.result = rb.call(this, a, c, d, g, this.h), g ? e ? X.call(this.index, this.result) : this.result : this; + return this.result = rb.call(this, a, c, d, f, this.h), f ? e ? X.call(this.index, this.result) : this.result : this; } } else { - f || (this.result = a); + g || (this.result = a); } - return g ? this.resolve(c, d, e) : this; + return f ? this.resolve(c, d, e) : this; } function rb(a, b, c, d, e) { - for (var g = [], f = J(), h = 0, k = 0, l; k < a.length; k++) { + for (var f = [], g = J(), h = 0, k = 0, l; k < a.length; k++) { if (l = a[k]) { h < l.length && (h = l.length); for (var m = 0, n; m < l.length; m++) { if (n = l[m]) { for (var p = 0, q; p < n.length; p++) { - q = n[p], f[q] = f[q] ? 2 : 1; + q = n[p], g[q] = g[q] ? 2 : 1; } } } @@ -1969,20 +1976,20 @@ function rb(a, b, c, d, e) { if (n = a[m]) { if (n = n[k]) { for (p = 0; p < n.length; p++) { - if (q = n[p], 1 === f[q]) { + if (q = n[p], 1 === g[q]) { if (c) { c--; } else { if (d) { - if (g.push(q), g.length === b) { - return g; + if (f.push(q), f.length === b) { + return f; } } else { var t = k + (m ? e : 0); - g[t] || (g[t] = []); - g[t].push(q); + f[t] || (f[t] = []); + f[t].push(q); if (++l === b) { - return g; + return f; } } } @@ -1992,13 +1999,13 @@ function rb(a, b, c, d, e) { } } } - return g; + return f; } ;Y.prototype.not = function() { var a = nb(this, "not", arguments); return sb.call(this, a.W, a.$, a.limit, a.offset, a.enrich, a.resolve, a.suggest); }; -function sb(a, b, c, d, e, g, f) { +function sb(a, b, c, d, e, f, g) { if (b.length) { var h = this; return Promise.all(b).then(function(k) { @@ -2006,23 +2013,23 @@ function sb(a, b, c, d, e, g, f) { for (var l = 0, m = void 0; l < k.length; l++) { (m = k[l]).length && (a[l] = m); } - return sb.call(h, a, [], c, d, e, g, f); + return sb.call(h, a, [], c, d, e, f, g); }); } if (a.length && this.result.length) { - this.result = tb.call(this, a, c, d, g); - } else if (g) { + this.result = tb.call(this, a, c, d, f); + } else if (f) { return this.resolve(c, d, e); } - return g ? e ? X.call(this.index, this.result) : this.result : this; + return f ? e ? X.call(this.index, this.result) : this.result : this; } function tb(a, b, c, d) { var e = []; a = new Set(a.flat().flat()); - for (var g = 0, f, h = 0; g < this.result.length; g++) { - if (f = this.result[g]) { - for (var k = 0, l; k < f.length; k++) { - if (l = f[k], !a.has(l)) { + for (var f = 0, g, h = 0; f < this.result.length; f++) { + if (g = this.result[f]) { + for (var k = 0, l; k < g.length; k++) { + if (l = g[k], !a.has(l)) { if (c) { c--; } else { @@ -2031,7 +2038,7 @@ function tb(a, b, c, d) { return e; } } else { - if (e[g] || (e[g] = []), e[g].push(l), ++h === b) { + if (e[f] || (e[f] = []), e[f].push(l), ++h === b) { return e; } } @@ -2094,7 +2101,7 @@ Y.prototype.resolve = function(a, b, c) { J(); W.prototype.search = function(a, b, c, d) { c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); - var e = [], g = [], f = 0; + var e = [], f = [], g = 0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; @@ -2155,19 +2162,19 @@ W.prototype.search = function(a, b, c, d) { if (!a) { p = []; if (r.length) { - for (g = 0; g < r.length; g += 2) { + for (f = 0; f < r.length; f += 2) { h = void 0; if (this.db) { - h = this.index.get(r[g]); + h = this.index.get(r[f]); if (!h) { - console.warn("Tag '" + r[g] + ":" + r[g + 1] + "' will be skipped because there is no field '" + r[g] + "'."); + console.warn("Tag '" + r[f] + ":" + r[f + 1] + "' will be skipped because there is no field '" + r[f] + "'."); continue; } - p.push(h = h.db.tag(r[g + 1], b, x, q)); + p.push(h = h.db.tag(r[f + 1], b, x, q)); } else { - h = ub.call(this, r[g], r[g + 1], b, x, q); + h = ub.call(this, r[f], r[f + 1], b, x, q); } - e.push({field:r[g], tag:r[g + 1], result:h}); + e.push({field:r[f], tag:r[f + 1], result:h}); } } return p.length ? Promise.all(p).then(function(Q) { @@ -2195,10 +2202,10 @@ W.prototype.search = function(a, b, c, d) { if (m) { if (this.db) { y.tag = m; - var Ja = v.db.support_tag_search; + var Ka = v.db.support_tag_search; y.field = l; } - Ja || (y.enrich = !1); + Ka || (y.enrich = !1); } if (r) { r[A] = v.search(a, b, y); @@ -2213,7 +2220,7 @@ W.prototype.search = function(a, b, c, d) { D = []; G = 0; if (this.db && d) { - if (!Ja) { + if (!Ka) { for (H = l.length; H < d.length; H++) { var L = d[H]; if (L && L.length) { @@ -2251,24 +2258,24 @@ W.prototype.search = function(a, b, c, d) { } } if (y) { - g[f] = z, e.push(v), f++; + f[g] = z, e.push(v), g++; } else if (1 === l.length) { return p ? e : new Y(e); } } } if (r) { - if (this.db && m && m.length && !Ja) { + if (this.db && m && m.length && !Ka) { for (q = 0; q < m.length; q += 2) { - g = this.index.get(m[q]); - if (!g) { + f = this.index.get(m[q]); + if (!f) { if (console.warn("Tag '" + m[q] + ":" + m[q + 1] + "' was not found because there is no field '" + m[q] + "'."), n) { continue; } else { return p ? e : new Y(e); } } - r.push(g.db.tag(m[q + 1], b, x, !1)); + r.push(f.db.tag(m[q + 1], b, x, !1)); } } var Yb = this; @@ -2276,7 +2283,7 @@ W.prototype.search = function(a, b, c, d) { return Q.length ? Yb.search(a, b, c, Q) : Q; }); } - if (!f) { + if (!g) { return p ? e : new Y(e); } if (h && (!q || !this.store)) { @@ -2284,44 +2291,44 @@ W.prototype.search = function(a, b, c, d) { } r = []; x = 0; - for (n = void 0; x < g.length; x++) { + for (n = void 0; x < f.length; x++) { n = e[x]; q && n.length && !n[0].doc && (this.db ? r.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = X.call(this, n)); if (h) { return p ? n : new Y(n); } - e[x] = {field:g[x], result:n}; + e[x] = {field:f[x], result:n}; } if (q && this.db && r.length) { - var Ka = this; + var La = this; return Promise.all(r).then(function(Q) { for (var R = 0; R < Q.length; R++) { e[R].result = Q[R]; } - return k ? vb(e, b) : t ? wb(e, a, Ka.index, Ka.field, Ka.J, t) : e; + return k ? vb(e, b) : t ? wb(e, a, La.index, La.field, La.J, t) : e; }); } return k ? vb(e, b) : t ? wb(e, a, this.index, this.field, this.J, t) : e; }; -function wb(a, b, c, d, e, g) { - for (var f, h, k, l = 0, m, n, p; l < a.length; l++) { - for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== f && (f = p, h = f.encode(b)), p = 0; p < m.length; p++) { - var q = "", t = ya(m[p].doc, n), x = f.encode(t); - t = t.split(f.split); +function wb(a, b, c, d, e, f) { + for (var g, h, k, l = 0, m, n, p; l < a.length; l++) { + for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== g && (g = p, h = g.encode(b)), p = 0; p < m.length; p++) { + var q = "", t = ya(m[p].doc, n), x = g.encode(t); + t = t.split(g.split); for (var r = 0, A, z; r < x.length; r++) { A = x[r]; z = t[r]; for (var v = void 0, y = 0, D; y < h.length; y++) { if (D = h[y], "strict" === k) { if (A === D) { - q += (q ? " " : "") + g.replace("$1", z); + q += (q ? " " : "") + f.replace("$1", z); v = !0; break; } } else { var G = A.indexOf(D); if (-1 < G) { - q += (q ? " " : "") + z.substring(0, G) + g.replace("$1", z.substring(G, D.length)) + z.substring(G + D.length); + q += (q ? " " : "") + z.substring(0, G) + f.replace("$1", z.substring(G, D.length)) + z.substring(G + D.length); v = !0; break; } @@ -2335,17 +2342,17 @@ function wb(a, b, c, d, e, g) { return a; } function vb(a, b) { - for (var c = [], d = J(), e = 0, g, f; e < a.length; e++) { - g = a[e]; - f = g.result; - for (var h = 0, k, l, m; h < f.length; h++) { - if (l = f[h], k = l.id, m = d[k]) { - m.push(g.field); + for (var c = [], d = J(), e = 0, f, g; e < a.length; e++) { + f = a[e]; + g = f.result; + for (var h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], k = l.id, m = d[k]) { + m.push(f.field); } else { if (c.length === b) { return c; } - l.field = d[k] = [g.field]; + l.field = d[k] = [f.field]; c.push(l); } } @@ -2353,16 +2360,16 @@ function vb(a, b) { return c; } function ub(a, b, c, d, e) { - var g = this.tag.get(a); - if (!g) { + var f = this.tag.get(a); + if (!f) { return console.warn("Tag '" + a + "' was not found"), []; } - if ((a = (g = g && g.get(b)) && g.length - d) && 0 < a) { + if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { if (a > c || d) { - g = g.slice(d, d + c); + f = f.slice(d, d + c); } - e && (g = X.call(this, g)); - return g; + e && (f = X.call(this, f)); + return f; } } function X(a) { @@ -2419,14 +2426,14 @@ function X(a) { b = b.value, b.then && a.push(b); } if (a.length) { - var g = this; - return Promise.all(a).then(function(f) { - for (var h = 0, k = w(g.index.entries()), l = k.next(); !l.done; l = k.next()) { + var f = this; + return Promise.all(a).then(function(g) { + for (var h = 0, k = w(f.index.entries()), l = k.next(); !l.done; l = k.next()) { l = l.value; var m = l[0]; - l[1].then && g.index.set(m, f[h++]); + l[1].then && f.index.set(m, g[h++]); } - return g; + return f; }); } } else { @@ -2452,26 +2459,26 @@ 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); - 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; + for (var f; e < b.length; e++) { + d.field = f = b[e]; + f = this.index.get(f); + var g = new a.constructor(a.id, d); + g.id = a.id; + c[e] = g.mount(f); + f.document = !0; + e ? f.bypass = !0 : f.store = this.store; } this.db = !0; return Promise.all(c); }; u.commit = function(a, b) { - var c = this, d, e, g, f; + var c = this, d, e, f, g; return ta(function(h) { if (1 == h.h) { d = []; e = w(c.index.values()); - for (g = e.next(); !g.done; g = e.next()) { - f = g.value, d.push(f.db.commit(f, a, b)); + for (f = e.next(); !f.done; f = e.next()) { + g = f.value, d.push(g.db.commit(g, a, b)); } return E(h, Promise.all(d), 2); } @@ -2488,17 +2495,17 @@ u.destroy = function() { function yb(a, b) { var c = new Map(), d = b.index || b.field || b; K(d) && (d = [d]); - for (var e = 0, g, f = void 0; e < d.length; e++) { - g = d[e]; - K(g) || (f = g, g = g.field); - f = M(f) ? Object.assign({}, a, f) : a; + for (var e = 0, f, g = void 0; e < d.length; e++) { + f = d[e]; + K(f) || (g = f, f = f.field); + g = M(g) ? Object.assign({}, a, g) : a; if (this.worker) { - var h = new Sa(f); - c.set(g, h); + var h = new Sa(g); + c.set(f, h); } - this.worker || c.set(g, new S(f, this.reg)); - f.custom ? this.J[e] = f.custom : (this.J[e] = xb(g, this.S), f.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = f.filter)); - this.field[e] = g; + this.worker || c.set(f, new S(g, this.reg)); + g.custom ? this.J[e] = g.custom : (this.J[e] = xb(f, this.S), g.filter && ("string" === typeof this.J[e] && (this.J[e] = new String(this.J[e])), this.J[e].R = g.filter)); + this.field[e] = f; } if (this.I) { for (a = b.store, K(a) && (a = [a]), b = 0; b < a.length; b++) { @@ -2530,11 +2537,11 @@ u.remove = function(a) { for (b = w(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c = c.value; for (var d = w(c), e = d.next(); !e.done; e = d.next()) { - var g = e.value; - e = g[0]; - g = g[1]; - var f = g.indexOf(a); - -1 < f && (1 < g.length ? g.splice(f, 1) : c.delete(e)); + var f = e.value; + e = f[0]; + f = f[1]; + var g = f.indexOf(a); + -1 < g && (1 < f.length ? f.splice(g, 1) : c.delete(e)); } } } @@ -2581,54 +2588,65 @@ u.export = function(a, b, c, d) { if (c < this.field.length) { var e = this.field[c]; if ((b = this.index.get(e).export(a, e, c, d = 1)) && b.then) { - var g = this; + var f = this; return b.then(function() { - return g.export(a, e, c + 1); + return f.export(a, e, c + 1); }); } return this.export(a, e, c + 1); } switch(d) { case 0: - var f = "reg"; + var g = "reg"; var h = Ya(this.reg); b = null; break; case 1: - f = "tag"; + g = "tag"; h = Wa(this.tag, this.reg.size); b = null; break; case 2: - f = "doc"; + g = "doc"; h = Ua(this.store); b = null; break; case 3: - f = "cfg"; + g = "cfg"; b = h = null; break; default: return; } - return $a.call(this, a, b, f, h, c, d); + return $a.call(this, a, b, g, h, c, d); }; u.import = function(a, b) { + var c = a.split("."); + "json" === c[c.length - 1] && c.pop(); + var d = 2 < c.length ? c[0] : ""; + c = 2 < c.length ? c[2] : c[1]; + if (this.worker && d) { + return this.index.get(d).import(a); + } if (b) { "string" === typeof b && (b = JSON.parse(b)); - a = a.split("."); - "json" === a[a.length - 1] && a.pop(); - var c = 2 < a.length ? a[0] : ""; - a = 2 < a.length ? a[2] : a[1]; - if (c) { - return this.index.get(c).import(a, b); + if (d) { + return this.index.get(d).import(c, b); } - switch(a) { + switch(c) { case "reg": this.fastupdate = !1; this.reg = Za(b, this.reg); for (b = 0; b < this.field.length; b++) { - c = this.index.get(this.field[b]), c.fastupdate = !1, c.reg = this.reg; + d = this.index.get(this.field[b]), d.fastupdate = !1, d.reg = this.reg; + } + if (this.worker) { + b = []; + d = w(this.index.values()); + for (c = d.next(); !c.done; c = d.next()) { + b.push(c.value.import(a)); + } + return Promise.all(b); } break; case "tag": @@ -2648,9 +2666,9 @@ function zb(a, b, c) { 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(f) { + e.cache.set(a, f); + return f; }); } this.cache.set(a, d); @@ -2693,7 +2711,7 @@ var Gb = /[\x00-\x7F]+/g; var Hb = /[\x00-\x7F]+/g; var Ib = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ab, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Bb}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Bb, matcher:Cb, replacer:Db}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Bb, replacer:Db.concat([/(?!^)[aeo]/g, ""]), matcher:Cb}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (var b = 0; b < a.length; b++) { - for (var c = a[b], d = c.charAt(0), e = Eb[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = Eb[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { + for (var c = a[b], d = c.charAt(0), e = Eb[d], f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = Eb[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { } a[b] = d; } @@ -2712,9 +2730,9 @@ S.prototype.add = function(a, b, c, d) { } b = this.encoder.encode(b); if (d = b.length) { - for (var e = J(), g = J(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { + for (var e = J(), f = J(), g = this.depth, h = this.resolution, k = 0; k < d; k++) { var l = b[this.rtl ? d - 1 - k : k], m = l.length; - if (m && (f || !g[l])) { + if (m && (g || !f[l])) { var n = this.score ? this.score(b, l, k, null, 0) : Kb(h, d, k), p = ""; switch(this.tokenize) { case "full": @@ -2723,7 +2741,7 @@ S.prototype.add = function(a, b, c, d) { for (var q = m; q > n; q--) { p = l.substring(n, q); var t = this.score ? this.score(b, l, k, p, n) : Kb(h, d, k, m, n); - Lb(this, g, p, t, a, c); + Lb(this, f, p, t, a, c); } } break; @@ -2731,20 +2749,20 @@ S.prototype.add = function(a, b, c, d) { case "reverse": if (1 < m) { for (q = m - 1; 0 < q; q--) { - p = l[q] + p, t = this.score ? this.score(b, l, k, p, q) : Kb(h, d, k, m, q), Lb(this, g, p, t, a, c); + p = l[q] + p, t = this.score ? this.score(b, l, k, p, q) : Kb(h, d, k, m, q), Lb(this, f, p, t, a, c); } p = ""; } case "forward": if (1 < m) { for (q = 0; q < m; q++) { - p += l[q], Lb(this, g, p, n, a, c); + p += l[q], Lb(this, f, p, n, a, c); } break; } default: - if (Lb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { - for (m = J(), p = this.da, n = l, q = Math.min(f + 1, d - k), t = m[n] = 1; t < q; t++) { + if (Lb(this, f, l, n, a, c), g && 1 < d && k < d - 1) { + for (m = J(), p = this.da, n = l, q = Math.min(g + 1, d - k), t = m[n] = 1; t < q; t++) { if ((l = b[this.rtl ? d - 1 - k - t : k + t]) && !m[l]) { m[l] = 1; var x = this.score ? this.score(b, n, k, l, t) : Kb(p + (d / 2 > p ? 0 : 1), d, k, q - 1, t - 1), r = this.bidirectional && l > n; @@ -2763,15 +2781,15 @@ S.prototype.add = function(a, b, c, d) { this.db && (b || this.commit_task.push({del:a}), this.ca && Mb(this)); return this; }; -function Lb(a, b, c, d, e, g, f) { - var h = f ? a.ctx : a.map, k; - if (!b[c] || f && !(k = b[c])[f]) { - if (f ? (b = k || (b[c] = J()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { +function Lb(a, b, c, d, e, f, g) { + var h = g ? a.ctx : a.map, k; + if (!b[c] || g && !(k = b[c])[g]) { + if (g ? (b = k || (b[c] = J()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { if (h.length === Math.pow(2, 31) - 1) { b = new bb(h); if (a.fastupdate) { - for (c = w(a.reg.values()), g = c.next(); !g.done; g = c.next()) { - g = g.value, g.includes(h) && (g[g.indexOf(h)] = b); + for (c = w(a.reg.values()), f = c.next(); !f.done; f = c.next()) { + f = f.value, f.includes(h) && (f[f.indexOf(h)] = b); } } k[d] = h = b; @@ -2786,38 +2804,38 @@ function Kb(a, b, c, d, e) { } ;S.prototype.search = function(a, b, c) { c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); - var d = [], e = 0, g; + var d = [], e = 0, f; if (c) { a = c.query || a; b = c.limit || b; e = c.offset || 0; - var f = c.context; + var g = c.context; var h = c.suggest; - var k = (g = !1 !== c.resolve) && c.enrich; + var k = (f = !1 !== c.resolve) && c.enrich; var l = c.boost; var m = c.resolution; var n = this.db && c.tag; } else { - g = this.resolve; + f = this.resolve; } var p = this.encoder.encode(a); var q = p.length; - b = b || (g ? 100 : 0); + b = b || (f ? 100 : 0); if (1 === q) { - return Nb.call(this, p[0], "", b, e, g, k, n); + return Nb.call(this, p[0], "", b, e, f, k, n); } - f = this.depth && !1 !== f; - if (2 === q && f && !h) { - return Nb.call(this, p[0], p[1], b, e, g, k, n); + g = this.depth && !1 !== g; + if (2 === q && g && !h) { + return Nb.call(this, p[0], p[1], b, e, f, k, n); } var t = J(), x = 0; - if (1 < q && f) { + if (1 < q && g) { var r = p[0]; x = 1; } m || 0 === m || (m = r ? this.da : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, p, b, e, h, g, k, n), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, b, e, h, f, k, n), !1 !== a)) { return a; } var A = this; @@ -2853,7 +2871,7 @@ function Kb(a, b, c, d, e) { y.h = 2; break; case 4: - return y.return(Qb(d, m, b, e, h, l, g)); + return y.return(Qb(d, m, b, e, h, l, f)); } }); }(); @@ -2870,19 +2888,19 @@ function Kb(a, b, c, d, e) { } h && r && x === q - 1 && !d.length && (r = "", x = -1, t = J()); } - return Qb(d, m, b, e, h, l, g); + return Qb(d, m, b, e, h, l, f); }; -function Qb(a, b, c, d, e, g, f) { +function Qb(a, b, c, d, e, f, g) { var h = a.length, k = a; if (1 < h) { - k = jb(a, b, c, d, e, g, f); + k = jb(a, b, c, d, e, f, g); } else if (1 === h) { - return f ? mb.call(null, a[0], c, d) : new Y(a[0]); + return g ? mb.call(null, a[0], c, d) : new Y(a[0]); } - return f ? k : new Y(k); + return g ? k : new Y(k); } -function Nb(a, b, c, d, e, g, f) { - a = Ob(this, a, b, c, d, e, g, f); +function Nb(a, b, c, d, e, f, g) { + a = Ob(this, a, b, c, d, e, f, g); return this.db ? a.then(function(h) { return e ? h || [] : new Y(h); }) : a && a.length ? e ? mb.call(this, a, c, d) : new Y(a) : e ? [] : new Y(); @@ -2894,9 +2912,9 @@ function Pb(a, b, c, d) { b.push(a); return; } - for (var g = 0, f; g < d; g++) { - if (f = a[g]) { - e[g] = f; + for (var f = 0, g; f < d; f++) { + if (g = a[f]) { + e[f] = g; } } if (e.length) { @@ -2908,11 +2926,11 @@ function Pb(a, b, c, d) { return e; } } -function Ob(a, b, c, d, e, g, f, h) { +function Ob(a, b, c, d, e, f, g, h) { var k; c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); if (a.db) { - return a.db.get(b, c, d, e, g, f, h); + return a.db.get(b, c, d, e, f, g, h); } a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; @@ -2926,8 +2944,8 @@ function Ob(a, b, c, d, e, g, f, h) { if (2 > e.length) { e.pop(); } else { - var g = e.indexOf(a); - g === c.length - 1 ? e.pop() : e.splice(g, 1); + var f = e.indexOf(a); + f === c.length - 1 ? e.pop() : e.splice(f, 1); } } } @@ -2943,10 +2961,10 @@ function Ob(a, b, c, d, e, g, f, h) { function Rb(a, b) { var c = 0; if (a.constructor === Array) { - for (var d = 0, e = void 0, g; d < a.length; d++) { + for (var d = 0, e = void 0, f; d < a.length; d++) { if ((e = a[d]) && e.length) { - if (g = e.indexOf(b), 0 <= g) { - 1 < e.length ? (e.splice(g, 1), c++) : delete a[d]; + if (f = e.indexOf(b), 0 <= f) { + 1 < e.length ? (e.splice(f, 1), c++) : delete a[d]; break; } else { c++; @@ -2955,7 +2973,7 @@ function Rb(a, b) { } } else { for (d = w(a.entries()), e = d.next(); !e.done; e = d.next()) { - g = e.value, e = g[0], (g = Rb(g[1], b)) ? c += g : a.delete(e); + f = e.value, e = f[0], (f = Rb(f[1], b)) ? c += f : a.delete(e); } } return c; @@ -3064,28 +3082,28 @@ u.export = function(a, b, c, d) { switch(d) { case 0: var e = "reg"; - var g = Ya(this.reg); + var f = Ya(this.reg); break; case 1: e = "cfg"; - g = null; + f = null; break; case 2: e = "map"; - g = Ua(this.map, this.reg.size); + f = Ua(this.map, this.reg.size); break; case 3: e = "ctx"; - g = Wa(this.ctx, this.reg.size); + f = Wa(this.ctx, this.reg.size); break; default: return; } - return $a.call(this, a, b, e, g, c, d); + return $a.call(this, a, b, e, f, c, d); }; u.import = function(a, b) { if (b) { - switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), a = 1 < a.length ? a[1] : a[0], a) { + switch("string" === typeof b && (b = JSON.parse(b)), a = a.split("."), "json" === a[a.length - 1] && a.pop(), 3 === a.length && a.shift(), a = 1 < a.length ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; this.reg = Za(b, this.reg); @@ -3109,26 +3127,26 @@ u.serialize = function(a) { b = "index.reg=new Set([" + b + "]);"; d = ""; e = w(this.map.entries()); - for (var g = e.next(); !g.done; g = e.next()) { - var f = g.value; - g = f[0]; - f = f[1]; - for (var h = "", k = 0, l; k < f.length; k++) { - l = f[k] || [""]; + for (var f = e.next(); !f.done; f = e.next()) { + var g = f.value; + f = g[0]; + g = g[1]; + for (var h = "", k = 0, l; k < g.length; k++) { + l = g[k] || [""]; for (var m = "", n = 0; n < l.length; n++) { m += (m ? "," : "") + ("string" === c ? '"' + l[n] + '"' : l[n]); } m = "[" + m + "]"; h += (h ? "," : "") + m; } - h = '["' + g + '",[' + h + "]]"; + h = '["' + f + '",[' + h + "]]"; d += (d ? "," : "") + h; } d = "index.map=new Map([" + d + "]);"; e = ""; - g = w(this.ctx.entries()); - for (f = g.next(); !f.done; f = g.next()) { - for (h = f.value, f = h[0], h = w(h[1].entries()), k = h.next(); !k.done; k = h.next()) { + f = w(this.ctx.entries()); + for (g = f.next(); !g.done; g = f.next()) { + for (h = g.value, g = h[0], h = w(h[1].entries()), k = h.next(); !k.done; k = h.next()) { l = k.value; k = l[0]; l = l[1]; @@ -3143,7 +3161,7 @@ u.serialize = function(a) { m += (m ? "," : "") + q; } m = 'new Map([["' + k + '",[' + m + "]]])"; - m = '["' + f + '",' + m + "]"; + m = '["' + g + '",' + m + "]"; e += (e ? "," : "") + m; } } @@ -3181,8 +3199,8 @@ u.open = function() { var d = Tb.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { var e = a.db = this.result; - Ub.forEach(function(g) { - e.objectStoreNames.contains(g) || e.createObjectStore(g); + Ub.forEach(function(f) { + e.objectStoreNames.contains(f) || e.createObjectStore(f); }); }; d.onblocked = function(e) { @@ -3216,13 +3234,13 @@ u.clear = function() { } return Wb(a); }; -u.get = function(a, b, c, d, e, g) { +u.get = function(a, b, c, d, e, f) { c = void 0 === c ? 0 : c; d = void 0 === d ? 0 : d; e = void 0 === e ? !0 : e; - g = void 0 === g ? !1 : g; + f = void 0 === f ? !1 : f; a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); - var f = this; + var g = this; return Wb(a).then(function(h) { var k = []; if (!h || !h.length) { @@ -3247,7 +3265,7 @@ u.get = function(a, b, c, d, e, g) { } } } - return g ? f.enrich(k) : k; + return f ? g.enrich(k) : k; } return h; }); @@ -3258,15 +3276,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 Wb(a).then(function(g) { - if (!g || !g.length || c >= g.length) { + return Wb(a).then(function(f) { + if (!f || !f.length || c >= f.length) { return []; } if (!b && !c) { - return g; + return f; } - g = g.slice(c, c + b); - return d ? e.enrich(g) : g; + f = f.slice(c, c + b); + return d ? e.enrich(f) : f; }); }; u.enrich = function(a) { @@ -3275,8 +3293,8 @@ u.enrich = function(a) { c[d] = Wb(b.get(a[d])); } return Promise.all(c).then(function(e) { - for (var g = 0; g < e.length; g++) { - e[g] = {id:a[g], doc:e[g] ? JSON.parse(e[g]) : null}; + for (var f = 0; f < e.length; f++) { + e[f] = {id:a[f], doc:e[f] ? JSON.parse(e[f]) : null}; } return e; }); @@ -3293,24 +3311,24 @@ 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 f = this.db.transaction(a, b); + this.h[a + ":" + b] = e = f.objectStore(a); + return new Promise(function(g, h) { + f.onerror = function(k) { d.h[a + ":" + b] = null; - g.abort(); - g = e = null; + f.abort(); + f = e = null; h(k); }; - g.oncomplete = function(k) { - g = e = d.h[a + ":" + b] = null; - f(k || !0); + f.oncomplete = function(k) { + f = e = d.h[a + ":" + b] = null; + g(k || !0); }; return c.call(d, e); }); }; u.commit = function(a, b, c) { - var d = this, e, g, f; + var d = this, e, f, g; return ta(function(h) { switch(h.h) { case 1: @@ -3319,16 +3337,16 @@ u.commit = function(a, b, c) { } e = a.commit_task; a.commit_task = []; - g = 0; - f = void 0; + f = 0; + g = void 0; case 4: - if (!(g < e.length)) { + if (!(f < e.length)) { h.h = 6; break; } - f = e[g]; - if (!f.clear) { - e[g] = f.ma; + g = e[f]; + if (!g.clear) { + e[f] = g.ma; h.h = 5; break; } @@ -3338,7 +3356,7 @@ u.commit = function(a, b, c) { h.h = 6; break; case 5: - g++; + f++; h.h = 4; break; case 6: @@ -3459,10 +3477,10 @@ u.commit = function(a, b, c) { }); }; function Zb(a, b, c) { - for (var d = a.value, e, g, f = 0, h = 0, k; h < d.length; h++) { + for (var d = a.value, e, f, g = 0, h = 0, k; h < d.length; h++) { if (k = c ? d : d[h]) { for (var l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = k.indexOf(g ? parseInt(n, 10) : n), 0 > m && !g && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (g = 1), 0 <= m) { + if (n = b[l], m = k.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = k.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { if (e = 1, 1 < k.length) { k.splice(m, 1); } else { @@ -3471,13 +3489,13 @@ function Zb(a, b, c) { } } } - f += k.length; + g += k.length; } if (c) { break; } } - f ? e && a.update(d) : a.delete(); + g ? e && a.update(d) : a.delete(); a.continue(); } u.remove = function(a) { diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index d218150..ffea62b 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.111 (ES5) + * FlexSearch.js v0.8.113 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -35,7 +35,7 @@ b.prototype.values;b.prototype.forEach=function(c,d){var e=this;this.h.forEach(f C("Array.prototype.includes",function(a){return a?a:function(b,c){var d=this;d instanceof String&&(d=String(d));var e=d.length;c=c||0;for(0>c&&(c=Math.max(c+e,0));cthis.T&&(this.C.clear(),this.H=this.H/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.G&&(this.B.set(a,d),this.B.size>this.T&&(this.B.clear(),this.G=this.G/1.1|0));return d};function N(a){a.D=null;a.B.clear();a.C.clear()};var O,Ha; -function Ia(a){var b,c,d,e,g;return ta(function(f){switch(f.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Ha=a.options||{};(e=a.factory)?(Function("return "+e)()(self),O=new self.FlexSearch.Index(Ha),delete self.FlexSearch):O=new R(Ha);postMessage({id:c});break;default:f.h=2;return}f.h=0;break;case 2:"export"===b&&(d=[Ha.export]);if("import"===b)return E(f,Ha.import.call(O,O),5);g=O[b].apply(O,d);if(!g.then){f.h=5;break}return E(f,g,7);case 7:g=f.D;f.h=5;break;case 5:postMessage("search"===b? -{id:c,msg:g}:{id:c}),f.h=0}})};function La(a){Ma.call(a,"add");Ma.call(a,"append");Ma.call(a,"search");Ma.call(a,"update");Ma.call(a,"remove")}var Na,Oa,Pa={},Qa={};function Ra(a){Na=0;Pa[a]=Qa[a]} +function Ia(a){var b,c,d,e,g,f;return ta(function(h){switch(h.h){case 1:a=a.data;b=a.task;c=a.id;d=a.args;switch(b){case "init":Ha=a.options||{};(e=a.factory)?(Function("return "+e)()(self),O=new self.FlexSearch.Index(Ha),delete self.FlexSearch):O=new R(Ha);postMessage({id:c});break;default:h.h=2;return}h.h=0;break;case 2:"export"===b&&(d[1]?(d[0]=Ha.export,d[2]=0,d[3]=1):d=null);if("import"===b){if(!d[0]){h.h=5;break}return E(h,Ha.import.call(O,d[0]),9)}g=d&&O[b].apply(O,d);if(!g||!g.then){h.h=5; +break}return E(h,g,7);case 7:g=h.D;h.h=5;break;case 9:f=h.D,O.import(d[0],f);case 5:postMessage("search"===b?{id:c,msg:g}:{id:c}),h.h=0}})};function Ja(a){Ma.call(a,"add");Ma.call(a,"append");Ma.call(a,"search");Ma.call(a,"update");Ma.call(a,"remove")}var Na,Oa,Pa={},Qa={};function Ra(a){Na=0;Pa[a]=Qa[a]} function Ma(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}Na||(Na=setTimeout(Ra,0,a),Oa=Date.now());Qa[a]||(Qa[a]=Pa[a]=1E3);if(!--Pa[a]){Pa[a]=Qa[a]=Qa[a]*this.priority*this.priority*3/(Date.now()-Oa)|0||1;Na=clearTimeout(Na);var e=this;return new Promise(function(f){setTimeout(function(){f(e[a+"Async"].apply(e,b))},0)})}var g=this[a].apply(this,b);c=g.then?g:new Promise(function(f){return f(g)});d&&c.then(d);return c}};var Sa=0; -function S(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=I();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Sa]=function(){k(e)};e.worker.postMessage({id:Sa,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(!this||this.constructor!==S)return new S(a);var c="undefined"!==typeof self?self._factory: -"undefined"!==typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,g=Ta(c,d,a.worker);return g.then?g.then(function(f){return b.call(e,f)}):b.call(this,g)}T("add");T("append");T("search");T("update");T("remove");T("clear");T("export");T("import"); -function T(a){S.prototype[a]=S.prototype[a+"Async"]=function(){var b=this,c=arguments,d,e,g,f,h;return ta(function(k){d=b;e=[].slice.call(c);g=e[e.length-1];"function"===typeof g&&(f=g,e.splice(e.length-1,1));h=new Promise(function(l){d.h[++Sa]=l;d.worker.postMessage({task:a,id:Sa,args:e})});return f?(h.then(f),k.return(b)):k.return(h)})}} -function Ta(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="+Ia.toString()],{type:"text/javascript"}))):new window.Worker(K(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function S(a){function b(f){function h(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=J();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++Sa]=function(){k(e)};e.worker.postMessage({id:Sa,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(!this||this.constructor!==S)return new S(a);var c="undefined"!==typeof self?self._factory: +"undefined"!==typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,g=Ta(c,d,a.worker);return g.then?g.then(function(f){return b.call(e,f)}):b.call(this,g)}T("add");T("append");T("search");T("update");T("remove");T("clear");T("export");T("import");Ja(S.prototype); +function T(a){S.prototype[a]=function(){var b=this,c=[].slice.call(arguments),d=c[c.length-1];if("function"===typeof d){var e=d;c.pop()}d=new Promise(function(g){"export"===a&&"function"===typeof c[0]&&(c[0]=null);b.h[++Sa]=g;b.worker.postMessage({task:a,id:Sa,args:c})});return e?(d.then(e),this):d}} +function Ta(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="+Ia.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof c?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"),{type:"module"})};function Ua(a,b){b=void 0===b?0:b;var c=[],d=[];b&&(b=25E4/b*5E3|0);a=w(a.entries());for(var e=a.next();!e.done;e=a.next())d.push(e.value),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function Va(a,b){b||(b=new Map);for(var c=0,d;c=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} function bb(a){if(!this)return new bb(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var g=0,f=0,h,k;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(g=0;gd)d-=f.length; +J();for(c=0;cc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(g=0;gd)d-=f.length; else{if(f.length>c||d)f=f.slice(d,c+d),c-=f.length,d&&(d-=f.length);e.push(f);if(!c)break}k=1b?b?a.slice(c,c+b):a.slice(c):a,d?X.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}cb&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?X.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1b?b?a.slice(c,c+b):a.slice(c):a,d?X.call(this,a):a;for(var e=[],g=0,f=void 0,h=void 0;g=h){c-=h;continue}cb&&(f=f.slice(0,b),h=b);if(!e.length&&h>=b)return d?X.call(this,f):f;e.push(f);b-=h;if(!b)break}e=1a.length?this.result=a[0]:(this.result=kb(a,c,d,!1,this.h),d=0));return g?this.resolve(c,d,e):this};Y.prototype.and=function(){var a=this.result.length;if(!a){var b=arguments[0];if(b){a=!!b.suggest;var c=b.resolve;var d=b.limit;var e=b.offset;var g=b.enrich&&c}}return a?(a=nb(this,"and",arguments),pb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)):c?this.resolve(d,e,g):this}; function pb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else{if(b=za(a))return this.result=jb(a,b,c,d,f,this.h,g),g?e?X.call(this.index,this.result):this.result:this;this.result=[]}else f||(this.result=a);return g?this.resolve(c,d,e):this};Y.prototype.xor=function(){var a=nb(this,"xor",arguments);return qb.call(this,a.W,a.$,a.limit,a.offset,a.enrich,a.resolve,a.suggest)}; function qb(a,b,c,d,e,g,f){if(b.length){var h=this;return Promise.all(b).then(function(k){a=[];for(var l=0,m=void 0;la.length)this.result=a[0];else return this.result=rb.call(this,a,c,d,g,this.h),g?e?X.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} -function rb(a,b,c,d,e){for(var g=[],f=I(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=X.call(this,a));return a}} +D.length))+z.substring(G+D.length);v=!0;break}}v||(q+=(q?" ":"")+r[t])}m[p].highlight=q}return a}function vb(a,b){for(var c=[],d=J(),e=0,g,f;ec||d)a=a.slice(d,d+c);e&&(a=X.call(this,a));return a}} function X(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +u.import=function(a,b){var c=a.split(".");"json"===c[c.length-1]&&c.pop();var d=2this.limit&&this.cache.delete(this.cache.keys().next().value)}; Z.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Z.prototype.remove=function(a){for(var b=w(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};Z.prototype.clear=function(){this.cache.clear();this.h=""};var Ab={normalize:function(a){return a.toLowerCase()}};var Bb=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Cb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Db=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];var Eb={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Fb=/[\x00-\x7F]+/g;var Gb=/[\x00-\x7F]+/g;var Hb=/[\x00-\x7F]+/g;var Ib={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ab,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Bb},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Bb,matcher:Cb,replacer:Db},LatinExtra:{normalize:!0,dedupe:!0,mapper:Bb,replacer:Db.concat([/(?!^)[aeo]/g,""]),matcher:Cb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):Kb(h,d,k,m,n);Lb(this,g,p,r,a,c)}break}case "reverse":if(1< -m){for(q=m-1;0p?0:1),d,k,q-1,r-1),t=this.bidirectional&&l>n;Lb(this,e,t?n:l,x,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +f||!(f=Eb[f])||f===e||(d+=f,e=f,4!==d.length));g++);a[b]=d}}},ArabicDefault:{rtl:!0,normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(Fb," ")}},CjkDefault:{normalize:!1,dedupe:!0,split:"",prepare:function(a){return(""+a).replace(Gb,"")}},CyrillicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(Hb," ")}}};var Jb={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};R.prototype.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.reg.has(a))return this.update(a,b);b=this.encoder.encode(b);if(d=b.length){for(var e=J(),g=J(),f=this.depth,h=this.resolution,k=0;kn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):Kb(h,d,k,m,n);Lb(this,g,p,r,a,c)}break}case "reverse":if(1< +m){for(q=m-1;0p?0:1),d,k,q-1,r-1),t=this.bidirectional&&l>n;Lb(this,e,t?n:l,x,a,c,t?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& (b||this.commit_task.push({del:a}),this.ca&&Mb(this));return this}; -function Lb(a,b,c,d,e,g,f){var h=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=I()),b[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!g||!h.includes(e)){if(h.length===Math.pow(2,31)-1){b=new bb(h);if(a.fastupdate)for(c=w(a.reg.values()),g=c.next();!g.done;g=c.next())g=g.value,g.includes(h)&&(g[g.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function Kb(a,b,c,d,e){return c&&1c)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,g,f,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};R.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var g=e.indexOf(a);g===c.length-1?e.pop():e.splice(g,1)}}else Rb(this.map,a),this.depth&&Rb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.ca&&Mb(this));this.cache&&this.cache.remove(a);return this}; function Rb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,g;d} reg + * @param {Set|Map>} reg * @return {Array>} */ function reg_to_json(reg) { @@ -217,6 +218,9 @@ export function importIndex(key, data) { if ("json" === split[split.length - 1]) { split.pop(); } + if (3 === split.length) { + split.shift(); + } key = 1 < split.length ? split[1] : split[0]; switch (key) { @@ -319,6 +323,19 @@ export function exportDocument(callback, _field, _index_doc = 0, _index_obj = 0) export function importDocument(key, data) { + const split = key.split("."); + if ("json" === split[split.length - 1]) { + split.pop(); + } + const field = 2 < split.length ? split[0] : "", + ref = 2 < split.length ? split[2] : split[1]; + + + // trigger the import for worker field indexes + if (this.worker && field) { + return this.index.get(field).import(key); + } + if (!data) { return; } @@ -326,16 +343,9 @@ export function importDocument(key, data) { data = /** @type {Array} */JSON.parse( /** @type {string} */data); } - const split = key.split("."); - if ("json" === split[split.length - 1]) { - split.pop(); - } - const field = 2 < split.length ? split[0] : ""; - key = 2 < split.length ? split[2] : split[1]; - if (!field) { - switch (key) { + switch (ref) { case "reg": @@ -349,6 +359,22 @@ export function importDocument(key, data) { idx.reg = this.reg; } + // trigger the import for worker field indexes + if (this.worker) { + const promises = [], + self = this; + + + for (const index of this.index.values()) { + // const ref = item[0]; + // const index = item[1]; + promises.push(index.import(key)); + //this.index.get(field).import(key); + } + + return Promise.all(promises); + } + break; case "tag": @@ -368,7 +394,7 @@ export function importDocument(key, data) { } } else { - return this.index.get(field).import(key, data); + return this.index.get(field).import(ref, data); } } diff --git a/dist/module-debug/worker.js b/dist/module-debug/worker.js index be7f1ec..1efa946 100644 --- a/dist/module-debug/worker.js +++ b/dist/module-debug/worker.js @@ -1,6 +1,6 @@ import { IndexOptions } from "./type.js"; -import { create_object, is_function, is_object, is_string } from "./common.js"; +import { create_object } from "./common.js"; import handler from "./worker/handler.js"; import apply_async from "./async.js"; @@ -81,7 +81,6 @@ export default function WorkerIndex(options = /** @type IndexOptions */{}) { } 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); @@ -96,36 +95,40 @@ register("clear"); register("export"); register("import"); +apply_async(WorkerIndex.prototype); + + function register(key) { - WorkerIndex.prototype[key] = WorkerIndex.prototype[key + "Async"] = async function () { + WorkerIndex.prototype[key] = function () { const self = this, args = [].slice.call(arguments), arg = args[args.length - 1]; let callback; - if (is_function(arg)) { + if ("function" == typeof arg) { callback = arg; - args.splice(args.length - 1, 1); + args.pop(); } const promise = new Promise(function (resolve) { - //setTimeout(function(){ + if ("export" === key && "function" == typeof args[0]) { + // remove function handler + args[0] = null; + } self.resolver[++pid] = resolve; self.worker.postMessage({ task: key, id: pid, args: args }); - //}); }); if (callback) { promise.then(callback); return this; } else { - return promise; } }; @@ -134,8 +137,7 @@ function register(key) { 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 - + // This eval will be removed when compiling "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")') @@ -143,7 +145,8 @@ 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 : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js") /*"worker/worker.js"*/, { type: "module" }); + : factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker("string" == typeof worker_path ? worker_path : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/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 cf024c7..09af4fb 100644 --- a/dist/module-debug/worker/handler.js +++ b/dist/module-debug/worker/handler.js @@ -54,18 +54,25 @@ export default (async function (data) { if (!options.export || "function" != typeof options.export) { throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); } - - args = [options.export]; + // skip non-field indexes + if (!args[1]) args = null;else { + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if ("import" === task) { if (!options.import || "function" != typeof options.import) { throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); } - await options.import.call(index, index); + if (args[0]) { + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else { - message = index[task].apply(index, args); - if (message.then) { + message = args && index[task].apply(index, args); + if (message && message.then) { message = await message; } } diff --git a/dist/module-debug/worker/node.js b/dist/module-debug/worker/node.js index 704bc49..8b8b3d8 100644 --- a/dist/module-debug/worker/node.js +++ b/dist/module-debug/worker/node.js @@ -1,3 +1,7 @@ +/* + * Node.js Worker (CommonJS) + * This file is a standalone file and isn't being a part of the build/bundle + */ const { parentPort } = require("worker_threads"), { Index } = require("flexsearch"); //const { join } = require("path"); @@ -41,16 +45,24 @@ parentPort.on("message", async function (data) { if (!options.export || "function" != typeof options.export) { throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); } - args = [options.export]; + // skip non-field indexes + if (!args[1]) args = null;else { + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if ("import" === task) { if (!options.import || "function" != typeof options.import) { throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); } - await options.import.call(index, index); + if (args[0]) { + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else { - message = index[task].apply(index, args); - if (message.then) { + message = args && index[task].apply(index, args); + if (message && message.then) { message = await message; } } diff --git a/dist/module-min/document/add.js b/dist/module-min/document/add.js index f6931ce..a13cf54 100644 --- a/dist/module-min/document/add.js +++ b/dist/module-min/document/add.js @@ -1 +1 @@ -import{create_object,is_array,is_object,is_string,parse_simple}from"../common.js";import{KeystoreArray}from"../keystore.js";import Document from"../document.js";Document.prototype.add=function(a,b,c){if(is_object(a)&&(b=a,a=parse_simple(b,this.key)),b&&(a||0===a)){if(!c&&this.reg.has(a))return this.update(a,b);for(let d,e=0;e} reg + * @param {Set|Map>} reg * @return {Array>} */ function reg_to_json(reg) { @@ -217,6 +218,9 @@ export function importIndex(key, data) { if ("json" === split[split.length - 1]) { split.pop(); } + if (3 === split.length) { + split.shift(); + } key = 1 < split.length ? split[1] : split[0]; switch (key) { @@ -319,6 +323,19 @@ export function exportDocument(callback, _field, _index_doc = 0, _index_obj = 0) export function importDocument(key, data) { + const split = key.split("."); + if ("json" === split[split.length - 1]) { + split.pop(); + } + const field = 2 < split.length ? split[0] : "", + ref = 2 < split.length ? split[2] : split[1]; + + + // trigger the import for worker field indexes + if (this.worker && field) { + return this.index.get(field).import(key); + } + if (!data) { return; } @@ -326,16 +343,9 @@ export function importDocument(key, data) { data = /** @type {Array} */JSON.parse( /** @type {string} */data); } - const split = key.split("."); - if ("json" === split[split.length - 1]) { - split.pop(); - } - const field = 2 < split.length ? split[0] : ""; - key = 2 < split.length ? split[2] : split[1]; - if (!field) { - switch (key) { + switch (ref) { case "reg": @@ -349,6 +359,22 @@ export function importDocument(key, data) { idx.reg = this.reg; } + // trigger the import for worker field indexes + if (this.worker) { + const promises = [], + self = this; + + + for (const index of this.index.values()) { + // const ref = item[0]; + // const index = item[1]; + promises.push(index.import(key)); + //this.index.get(field).import(key); + } + + return Promise.all(promises); + } + break; case "tag": @@ -368,7 +394,7 @@ export function importDocument(key, data) { } } else { - return this.index.get(field).import(key, data); + return this.index.get(field).import(ref, data); } } diff --git a/dist/module/worker.js b/dist/module/worker.js index be7f1ec..1efa946 100644 --- a/dist/module/worker.js +++ b/dist/module/worker.js @@ -1,6 +1,6 @@ import { IndexOptions } from "./type.js"; -import { create_object, is_function, is_object, is_string } from "./common.js"; +import { create_object } from "./common.js"; import handler from "./worker/handler.js"; import apply_async from "./async.js"; @@ -81,7 +81,6 @@ export default function WorkerIndex(options = /** @type IndexOptions */{}) { } 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); @@ -96,36 +95,40 @@ register("clear"); register("export"); register("import"); +apply_async(WorkerIndex.prototype); + + function register(key) { - WorkerIndex.prototype[key] = WorkerIndex.prototype[key + "Async"] = async function () { + WorkerIndex.prototype[key] = function () { const self = this, args = [].slice.call(arguments), arg = args[args.length - 1]; let callback; - if (is_function(arg)) { + if ("function" == typeof arg) { callback = arg; - args.splice(args.length - 1, 1); + args.pop(); } const promise = new Promise(function (resolve) { - //setTimeout(function(){ + if ("export" === key && "function" == typeof args[0]) { + // remove function handler + args[0] = null; + } self.resolver[++pid] = resolve; self.worker.postMessage({ task: key, id: pid, args: args }); - //}); }); if (callback) { promise.then(callback); return this; } else { - return promise; } }; @@ -134,8 +137,7 @@ function register(key) { 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 - + // This eval will be removed when compiling "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")') @@ -143,7 +145,8 @@ 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 : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js") /*"worker/worker.js"*/, { type: "module" }); + : factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker("string" == typeof worker_path ? worker_path : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/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 c21b149..2957005 100644 --- a/dist/module/worker/handler.js +++ b/dist/module/worker/handler.js @@ -51,13 +51,21 @@ export default (async function (data) { let message; if ("export" === task) { - args = [options.export]; + // skip non-field indexes + if (!args[1]) args = null;else { + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if ("import" === task) { - await options.import.call(index, index); + if (args[0]) { + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else { - message = index[task].apply(index, args); - if (message.then) { + message = args && index[task].apply(index, args); + if (message && message.then) { message = await message; } } diff --git a/dist/module/worker/node.js b/dist/module/worker/node.js index 704bc49..8b8b3d8 100644 --- a/dist/module/worker/node.js +++ b/dist/module/worker/node.js @@ -1,3 +1,7 @@ +/* + * Node.js Worker (CommonJS) + * This file is a standalone file and isn't being a part of the build/bundle + */ const { parentPort } = require("worker_threads"), { Index } = require("flexsearch"); //const { join } = require("path"); @@ -41,16 +45,24 @@ parentPort.on("message", async function (data) { if (!options.export || "function" != typeof options.export) { throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); } - args = [options.export]; + // skip non-field indexes + if (!args[1]) args = null;else { + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if ("import" === task) { if (!options.import || "function" != typeof options.import) { throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); } - await options.import.call(index, index); + if (args[0]) { + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else { - message = index[task].apply(index, args); - if (message.then) { + message = args && index[task].apply(index, args); + if (message && message.then) { message = await message; } } diff --git a/dist/node/node.js b/dist/node/node.js index 1402938..a29bff4 100644 --- a/dist/node/node.js +++ b/dist/node/node.js @@ -1,3 +1,7 @@ +/* + * Node.js Worker (CommonJS) + * This file is a standalone file and isn't being a part of the build/bundle + */ const { parentPort } = require("worker_threads"); //const { join } = require("path"); // Test Path @@ -41,17 +45,26 @@ parentPort.on("message", async function(data){ if(!options.export || typeof options.export !== "function"){ throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); } - args = [options.export]; + // skip non-field indexes + if(!args[1]) args = null; + else{ + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if(task === "import"){ if(!options.import || typeof options.import !== "function"){ throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); } - await options.import.call(index, index); + if(args[0]){ + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else{ - message = index[task].apply(index, args); - if(message.then){ + message = args && index[task].apply(index, args); + if(message && message.then){ message = await message; } } diff --git a/dist/node/node.mjs b/dist/node/node.mjs index 14a1c52..ccdb210 100644 --- a/dist/node/node.mjs +++ b/dist/node/node.mjs @@ -1,3 +1,7 @@ +/* + * Node.js Worker (Standalone, ESM) + * This file is a standalone file and isn't being a part of the build/bundle + */ import { parentPort } from "worker_threads"; import { join } from "path"; // Test Path @@ -43,17 +47,26 @@ parentPort.on("message", async function(data){ if(!options.export || typeof options.export !== "function"){ throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); } - args = [options.export]; + // skip non-field indexes + if(!args[1]) args = null; + else{ + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if(task === "import"){ if(!options.import || typeof options.import !== "function"){ throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); } - await options.import.call(index, index); + if(args[0]){ + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else{ - message = index[task].apply(index, args); - if(message.then){ + message = args && index[task].apply(index, args); + if(message && message.then){ message = await message; } } diff --git a/doc/worker.md b/doc/worker.md index 49cbc69..260848e 100644 --- a/doc/worker.md +++ b/doc/worker.md @@ -127,7 +127,169 @@ The used index configuration has 2 fields (using bidirectional context of `depth A non-Worker Document index requires 181 seconds to index all contents.
The Worker index just takes 32 seconds to index them all, by processing every field and tag in parallel. For such large content it is a quite impressive result. -### CSP-friendly Worker (Browser) +## Export / Import Worker Indexes (Node.js) + +Worker will save/load their data dedicated and does not need the message channel for the data transfer. + +### Basic Worker Index + +> This feature follows the strategy of using [Extern Worker Configuration](#extern-worker-configuration) in combination with [Basic Export Import](../example/nodejs-commonjs/basic-export-import). + +Example (CommonJS): [basic-worker-export-import](../example/nodejs-commonjs/basic-worker-export-import)
+Example (ESM): [basic-worker-export-import](../example/nodejs-esm/basic-worker-export-import) + +Provide the index configuration and keep it, because it isn't stored. Provide a parameter `config` which is including the filepath to the extern configuration file: + +```js +const dirname = import.meta.dirname; +const config = { + tokenize: "forward", + config: dirname + "/config.js" +}; +``` + +> Any changes you made to the configuration will almost require a full re-index. + +Provide the extern configuration file e.g. `/config.js` as a default export including the methods `export` and `import`: + +```js +import { promises as fs } from "fs"; + +export default { + tokenize: "forward", + export: async function(key, data){ + // like the usual export write files by key + data + await fs.writeFile("./export/" + key, data, "utf8"); + }, + import: async function(index){ + // get the file contents of the export directory + let files = await fs.readdir("./export/"); + files = await Promise.all(files); + // loop through the files and push their contents to the index + // by also passing the filename as the first parameter + for(let i = 0; i < files.length; i++){ + const data = await fs.readFile("./export/" + files[i], "utf8"); + index.import(files[i], data); + } + } +}; +``` + +Create your index by assigning the configuration file from above: + +```js +import { Worker as WorkerIndex } from "flexsearch/esm"; +const index = await new WorkerIndex(config); +// add data to the index +// ... +``` + +Export the index: + +```js +await index.export(); +``` + +Import the index: + +```js +// create the same type of index you have used by .export() +// along with the same configuration +const index = await new WorkerIndex(config); +await index.import(); +``` + +### Document Worker Index + +> This feature follows the strategy of using [Extern Worker Configuration](#extern-worker-configuration) in combination with [Document Export Import](../example/nodejs-esm/document-export-import). + +Document Worker exports all their feature including: + +- Multi-Tag Indexes +- Context-Search Indexes +- Document-Store + +Example (CommonJS): [document-worker-export-import](../example/nodejs-commonjs/document-worker-export-import)
+Example (ESM): [document-worker-export-import](../example/nodejs-esm/document-worker-export-import) + +Provide the index configuration and keep it, because it isn't stored. Provide a parameter `config` which is including the filepath to the extern configuration file: + +```js +const dirname = import.meta.dirname; +const config = { + worker: true, + document: { + id: "tconst", + store: true, + index: [{ + field: "primaryTitle", + config: dirname + "/config.primaryTitle.js" + },{ + field: "originalTitle", + config: dirname + "/config.originalTitle.js" + }], + tag: [{ + field: "startYear" + },{ + field: "genres" + }] + } +}; +``` + +> Any changes you made to the configuration will almost require a full re-index. + +Provide the extern configuration file as a default export including the methods `export` and `import`: + +```js +import { promises as fs } from "fs"; + +export default { + tokenize: "forward", + export: async function(key, data){ + // like the usual export write files by key + data + await fs.writeFile("./export/" + key, data, "utf8"); + }, + import: async function(file){ + // instead of looping you will get the filename as 2nd paramter + // just return the loaded contents as a string + return await fs.readFile("./export/" + file, "utf8"); + } +}; +``` + +Create your index by assigning the configuration file from above: + +```js +import { Document } from "flexsearch/esm"; +const document = await new Document(config); +// add data to the index +// ... +``` + +Export the index by providing a key-data handler: + +```js +await document.export(async function(key, data){ + await fs.writeFile("./export/" + key, data, "utf8"); +}); +``` + +Import the index: + +```js +const files = await fs.readdir("./export/"); +// create the same type of index you have used by .export() +// along with the same configuration +const document = await new Document(config); +await Promise.all(files.map(async file => { + const data = await fs.readFile("./export/" + file, "utf8"); + // call import (async) + await document.import(file, data); +})); +``` + +## CSP-friendly Worker (Browser) When just using worker by passing the option `worker: true`, the worker will be created by code generation under the hood. This might have issues when using strict CSP settings. diff --git a/example/nodejs-commonjs/.document-worker-persistent/index.js b/example/nodejs-commonjs/.document-worker-persistent/index.js index db28b94..913adf0 100644 --- a/example/nodejs-commonjs/.document-worker-persistent/index.js +++ b/example/nodejs-commonjs/.document-worker-persistent/index.js @@ -24,7 +24,7 @@ const data = require(__dirname + "/data.json"); config: __dirname + "/config.primaryTitle.js" },{ field: "originalTitle", - config: __dirname + "/config.primaryTitle.js" + config: __dirname + "/config.originalTitle.js" }], tag: [{ field: "startYear" diff --git a/example/nodejs-commonjs/basic-worker-export-import/index.js b/example/nodejs-commonjs/basic-worker-export-import/index.js index 966c04e..b026bb6 100644 --- a/example/nodejs-commonjs/basic-worker-export-import/index.js +++ b/example/nodejs-commonjs/basic-worker-export-import/index.js @@ -26,9 +26,9 @@ const config = { ]; // add test data - data.forEach((item, id) => { - index.add(id, item); - }); + for(let i = 0; i < data.length; i++){ + await index.addAsync(i, data[i]); + } // perform query let result = await index.search({ diff --git a/example/nodejs-commonjs/basic-worker-export-import/package.json b/example/nodejs-commonjs/basic-worker-export-import/package.json index 340dea6..df59907 100644 --- a/example/nodejs-commonjs/basic-worker-export-import/package.json +++ b/example/nodejs-commonjs/basic-worker-export-import/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-commonjs-basic-worker-extern-config", "dependencies": { - "flexsearch": "^0.8.105" + "flexsearch": "github:nextapps-de/flexsearch" } } diff --git a/example/nodejs-commonjs/document-export-import/index.js b/example/nodejs-commonjs/document-export-import/index.js index 1f5dd4c..0b89cf7 100644 --- a/example/nodejs-commonjs/document-export-import/index.js +++ b/example/nodejs-commonjs/document-export-import/index.js @@ -60,6 +60,7 @@ const fs = require("fs").promises; // ----------------------- await fs.mkdir("./export/").catch(e => {}); + // call export await document.export(async function(key, data){ await fs.writeFile("./export/" + key, data, "utf8"); }); @@ -75,7 +76,8 @@ const fs = require("fs").promises; const files = await fs.readdir("./export/"); await Promise.all(files.map(async file => { const data = await fs.readFile("./export/" + file, "utf8"); - await document.import(file, data); + // call import + document.import(file, data); })) // perform query diff --git a/example/nodejs-commonjs/document-worker-export-import/README.md b/example/nodejs-commonjs/document-worker-export-import/README.md new file mode 100644 index 0000000..24ee65e --- /dev/null +++ b/example/nodejs-commonjs/document-worker-export-import/README.md @@ -0,0 +1,7 @@ +```bash +npm install +``` + +```bash +node index.js +``` \ No newline at end of file diff --git a/example/nodejs-commonjs/document-worker-export-import/config.originalTitle.js b/example/nodejs-commonjs/document-worker-export-import/config.originalTitle.js new file mode 100644 index 0000000..7590a72 --- /dev/null +++ b/example/nodejs-commonjs/document-worker-export-import/config.originalTitle.js @@ -0,0 +1,30 @@ +const { Encoder, Charset } = require("flexsearch"); +const EnglishPreset = require("flexsearch/lang/en"); +const fs = require("fs").promises; + +(async function(){ + await fs.mkdir("./export/").catch(e => {}); +}()); + +module.exports = { + tokenize: "forward", + encoder: new Encoder( + Charset.LatinBalance, + EnglishPreset, + { + normalize: function(str){ + return str.toLowerCase(); + }, + filter: false, + minlength: 3 + } + ), + export: async function(key, data){ + + await fs.writeFile("./export/" + key, data, "utf8"); + }, + import: async function(file){ + + return await fs.readFile("./export/" + file, "utf8"); + } +}; \ No newline at end of file diff --git a/example/nodejs-commonjs/document-worker-export-import/config.primaryTitle.js b/example/nodejs-commonjs/document-worker-export-import/config.primaryTitle.js new file mode 100644 index 0000000..7590a72 --- /dev/null +++ b/example/nodejs-commonjs/document-worker-export-import/config.primaryTitle.js @@ -0,0 +1,30 @@ +const { Encoder, Charset } = require("flexsearch"); +const EnglishPreset = require("flexsearch/lang/en"); +const fs = require("fs").promises; + +(async function(){ + await fs.mkdir("./export/").catch(e => {}); +}()); + +module.exports = { + tokenize: "forward", + encoder: new Encoder( + Charset.LatinBalance, + EnglishPreset, + { + normalize: function(str){ + return str.toLowerCase(); + }, + filter: false, + minlength: 3 + } + ), + export: async function(key, data){ + + await fs.writeFile("./export/" + key, data, "utf8"); + }, + import: async function(file){ + + return await fs.readFile("./export/" + file, "utf8"); + } +}; \ No newline at end of file diff --git a/example/nodejs-commonjs/document-worker-export-import/data.json b/example/nodejs-commonjs/document-worker-export-import/data.json new file mode 100644 index 0000000..1fd5660 --- /dev/null +++ b/example/nodejs-commonjs/document-worker-export-import/data.json @@ -0,0 +1,141 @@ +[ + { + "tconst": "tt0000001", + "titleType": "short", + "primaryTitle": "Carmencita", + "originalTitle": "Carmencita", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + }, + { + "tconst": "tt0000002", + "titleType": "short", + "primaryTitle": "Le clown et ses chiens", + "originalTitle": "Le clown et ses chiens", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "5", + "genres": [ + "Animation", + "Short" + ] + }, + { + "tconst": "tt0000003", + "titleType": "short", + "primaryTitle": "Pauvre Pierrot", + "originalTitle": "Pauvre Pierrot", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "4", + "genres": [ + "Animation", + "Comedy", + "Romance" + ] + }, + { + "tconst": "tt0000004", + "titleType": "short", + "primaryTitle": "Un bon bock", + "originalTitle": "Un bon bock", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "12", + "genres": [ + "Animation", + "Short" + ] + }, + { + "tconst": "tt0000005", + "titleType": "short", + "primaryTitle": "Blacksmith Scene", + "originalTitle": "Blacksmith Scene", + "isAdult": 0, + "startYear": "1893", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Comedy", + "Short" + ] + }, + { + "tconst": "tt0000006", + "titleType": "short", + "primaryTitle": "Chinese Opium Den", + "originalTitle": "Chinese Opium Den", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Short" + ] + }, + { + "tconst": "tt0000007", + "titleType": "short", + "primaryTitle": "Corbett and Courtney Before the Kinetograph", + "originalTitle": "Corbett and Courtney Before the Kinetograph", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Short", + "Sport" + ] + }, + { + "tconst": "tt0000008", + "titleType": "short", + "primaryTitle": "Edison Kinetoscopic Record of a Sneeze", + "originalTitle": "Edison Kinetoscopic Record of a Sneeze", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + }, + { + "tconst": "tt0000009", + "titleType": "movie", + "primaryTitle": "Miss Jerry", + "originalTitle": "Miss Jerry", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "45", + "genres": [ + "Romance" + ] + }, + { + "tconst": "tt0000010", + "titleType": "short", + "primaryTitle": "Leaving the Factory", + "originalTitle": "La sortie de l'usine Lumière à Lyon", + "isAdult": 0, + "startYear": "1895", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + } +] \ No newline at end of file diff --git a/example/nodejs-commonjs/document-worker-export-import/index.js b/example/nodejs-commonjs/document-worker-export-import/index.js new file mode 100644 index 0000000..cafc93c --- /dev/null +++ b/example/nodejs-commonjs/document-worker-export-import/index.js @@ -0,0 +1,102 @@ +const { Document } = require("flexsearch"); +const { promises: fs } = require("fs"); + +// loading test data +const data = require(__dirname + "/data.json"); + +// you will need to keep the index configuration +// they will not export, also every change to the +// configuration requires a full re-index +const config = { + worker: true, + document: { + id: "tconst", + store: true, + index: [{ + field: "primaryTitle", + config: __dirname + "/config.primaryTitle.js" + },{ + field: "originalTitle", + config: __dirname + "/config.originalTitle.js" + }], + tag: [{ + field: "startYear" + },{ + field: "genres" + }] + } +}; + +(async function(){ + + // create the document and await (!) for the instance response + let document = await new Document(config); + + // add test data + for(let i = 0; i < data.length; i++){ + await document.add(data[i]); + } + + // perform a query + let result = await document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + suggest: true, + enrich: true, + merge: true + }); + + console.log(result); + + // ----------------------- + // EXPORT + // ----------------------- + + // create folders for the export + // it should be empty before export + await fs.mkdir("./export/").catch(e => {}); + + await document.export(async function(key, data){ + await fs.writeFile("./export/" + key, data, "utf8"); + }); + + // ----------------------- + // IMPORT + // ----------------------- + + // create the same type of index you have used by .export() + // along with the same configuration + document = await new Document(config); + + // load them in parallel + const files = await fs.readdir("./export/"); + await Promise.all(files.map(async file => { + const data = await fs.readFile("./export/" + file, "utf8"); + await document.import(file, data); + })); + + // perform a query + result = await document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + suggest: true, + enrich: true, + merge: true + }); + + console.log("-------------------------------------"); + console.log(result); + +}()); diff --git a/example/nodejs-commonjs/document-worker-export-import/package.json b/example/nodejs-commonjs/document-worker-export-import/package.json new file mode 100644 index 0000000..e04e4ba --- /dev/null +++ b/example/nodejs-commonjs/document-worker-export-import/package.json @@ -0,0 +1,6 @@ +{ + "name": "nodejs-commonjs-document-worker-export-import", + "dependencies": { + "flexsearch": "github:nextapps-de/flexsearch" + } +} diff --git a/example/nodejs-commonjs/document-worker-extern-config/index.js b/example/nodejs-commonjs/document-worker-extern-config/index.js index 08c5f43..55c729a 100644 --- a/example/nodejs-commonjs/document-worker-extern-config/index.js +++ b/example/nodejs-commonjs/document-worker-extern-config/index.js @@ -16,7 +16,7 @@ const data = require(__dirname + "/data.json"); config: __dirname + "/config.primaryTitle.js" },{ field: "originalTitle", - config: __dirname + "/config.primaryTitle.js" + config: __dirname + "/config.originalTitle.js" }], tag: [{ field: "startYear" diff --git a/example/nodejs-esm/basic-worker-export-import/index.js b/example/nodejs-esm/basic-worker-export-import/index.js index eafd40d..67f7ab3 100644 --- a/example/nodejs-esm/basic-worker-export-import/index.js +++ b/example/nodejs-esm/basic-worker-export-import/index.js @@ -27,9 +27,9 @@ const config = { ]; // add test data - data.forEach((item, id) => { - index.add(id, item); - }); + for(let i = 0; i < data.length; i++){ + await index.addAsync(i, data[i]); + } // perform query let result = await index.search({ @@ -45,9 +45,7 @@ const config = { // EXPORT // ----------------------- - await index.export(function(){ - // do nothing here - }); + await index.export(); // ----------------------- // IMPORT diff --git a/example/nodejs-esm/basic-worker-export-import/package.json b/example/nodejs-esm/basic-worker-export-import/package.json index c179cf9..cebffca 100644 --- a/example/nodejs-esm/basic-worker-export-import/package.json +++ b/example/nodejs-esm/basic-worker-export-import/package.json @@ -1,7 +1,7 @@ { - "name": "nodejs-esm-basic-worker-extern-config", + "name": "nodejs-esm-basic-worker-export-import", "type": "module", "dependencies": { - "flexsearch": "^0.8.105" + "flexsearch": "github:nextapps-de/flexsearch" } } diff --git a/example/nodejs-esm/document-export-import/index.js b/example/nodejs-esm/document-export-import/index.js index 8322bf5..7f4f6f2 100644 --- a/example/nodejs-esm/document-export-import/index.js +++ b/example/nodejs-esm/document-export-import/index.js @@ -59,6 +59,7 @@ console.log(result); // ----------------------- await fs.mkdir("./export/").catch(e => {}); +// call export await document.export(async function(key, data){ await fs.writeFile("./export/" + key, data, "utf8"); }); @@ -74,8 +75,9 @@ document = new Document(config); const files = await fs.readdir("./export/"); await Promise.all(files.map(async file => { const data = await fs.readFile("./export/" + file, "utf8"); - await document.import(file, data); -})) + // call import + document.import(file, data); +})); // perform query result = document.search({ diff --git a/example/nodejs-esm/document-worker-export-import/README.md b/example/nodejs-esm/document-worker-export-import/README.md new file mode 100644 index 0000000..24ee65e --- /dev/null +++ b/example/nodejs-esm/document-worker-export-import/README.md @@ -0,0 +1,7 @@ +```bash +npm install +``` + +```bash +node index.js +``` \ No newline at end of file diff --git a/example/nodejs-esm/document-worker-export-import/config.originalTitle.js b/example/nodejs-esm/document-worker-export-import/config.originalTitle.js new file mode 100644 index 0000000..e04a664 --- /dev/null +++ b/example/nodejs-esm/document-worker-export-import/config.originalTitle.js @@ -0,0 +1,30 @@ +import { Encoder, Charset } from "flexsearch/esm"; +import EnglishPreset from "flexsearch/esm/lang/en"; +import { promises as fs } from "fs"; + +(async function(){ + await fs.mkdir("./export/").catch(e => {}); +}()); + +export default { + tokenize: "forward", + encoder: new Encoder( + Charset.LatinBalance, + EnglishPreset, + { + normalize: function(str){ + return str.toLowerCase(); + }, + filter: false, + minlength: 3 + } + ), + export: async function(key, data){ + + await fs.writeFile("./export/" + key, data, "utf8"); + }, + import: async function(file){ + + return await fs.readFile("./export/" + file, "utf8"); + } +}; \ No newline at end of file diff --git a/example/nodejs-esm/document-worker-export-import/config.primaryTitle.js b/example/nodejs-esm/document-worker-export-import/config.primaryTitle.js new file mode 100644 index 0000000..e04a664 --- /dev/null +++ b/example/nodejs-esm/document-worker-export-import/config.primaryTitle.js @@ -0,0 +1,30 @@ +import { Encoder, Charset } from "flexsearch/esm"; +import EnglishPreset from "flexsearch/esm/lang/en"; +import { promises as fs } from "fs"; + +(async function(){ + await fs.mkdir("./export/").catch(e => {}); +}()); + +export default { + tokenize: "forward", + encoder: new Encoder( + Charset.LatinBalance, + EnglishPreset, + { + normalize: function(str){ + return str.toLowerCase(); + }, + filter: false, + minlength: 3 + } + ), + export: async function(key, data){ + + await fs.writeFile("./export/" + key, data, "utf8"); + }, + import: async function(file){ + + return await fs.readFile("./export/" + file, "utf8"); + } +}; \ No newline at end of file diff --git a/example/nodejs-esm/document-worker-export-import/data.json b/example/nodejs-esm/document-worker-export-import/data.json new file mode 100644 index 0000000..1fd5660 --- /dev/null +++ b/example/nodejs-esm/document-worker-export-import/data.json @@ -0,0 +1,141 @@ +[ + { + "tconst": "tt0000001", + "titleType": "short", + "primaryTitle": "Carmencita", + "originalTitle": "Carmencita", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + }, + { + "tconst": "tt0000002", + "titleType": "short", + "primaryTitle": "Le clown et ses chiens", + "originalTitle": "Le clown et ses chiens", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "5", + "genres": [ + "Animation", + "Short" + ] + }, + { + "tconst": "tt0000003", + "titleType": "short", + "primaryTitle": "Pauvre Pierrot", + "originalTitle": "Pauvre Pierrot", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "4", + "genres": [ + "Animation", + "Comedy", + "Romance" + ] + }, + { + "tconst": "tt0000004", + "titleType": "short", + "primaryTitle": "Un bon bock", + "originalTitle": "Un bon bock", + "isAdult": 0, + "startYear": "1892", + "endYear": "", + "runtimeMinutes": "12", + "genres": [ + "Animation", + "Short" + ] + }, + { + "tconst": "tt0000005", + "titleType": "short", + "primaryTitle": "Blacksmith Scene", + "originalTitle": "Blacksmith Scene", + "isAdult": 0, + "startYear": "1893", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Comedy", + "Short" + ] + }, + { + "tconst": "tt0000006", + "titleType": "short", + "primaryTitle": "Chinese Opium Den", + "originalTitle": "Chinese Opium Den", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Short" + ] + }, + { + "tconst": "tt0000007", + "titleType": "short", + "primaryTitle": "Corbett and Courtney Before the Kinetograph", + "originalTitle": "Corbett and Courtney Before the Kinetograph", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Short", + "Sport" + ] + }, + { + "tconst": "tt0000008", + "titleType": "short", + "primaryTitle": "Edison Kinetoscopic Record of a Sneeze", + "originalTitle": "Edison Kinetoscopic Record of a Sneeze", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + }, + { + "tconst": "tt0000009", + "titleType": "movie", + "primaryTitle": "Miss Jerry", + "originalTitle": "Miss Jerry", + "isAdult": 0, + "startYear": "1894", + "endYear": "", + "runtimeMinutes": "45", + "genres": [ + "Romance" + ] + }, + { + "tconst": "tt0000010", + "titleType": "short", + "primaryTitle": "Leaving the Factory", + "originalTitle": "La sortie de l'usine Lumière à Lyon", + "isAdult": 0, + "startYear": "1895", + "endYear": "", + "runtimeMinutes": "1", + "genres": [ + "Documentary", + "Short" + ] + } +] \ No newline at end of file diff --git a/example/nodejs-esm/document-worker-export-import/index.js b/example/nodejs-esm/document-worker-export-import/index.js new file mode 100644 index 0000000..d553e2e --- /dev/null +++ b/example/nodejs-esm/document-worker-export-import/index.js @@ -0,0 +1,104 @@ +import { Document } from "flexsearch/esm"; +import { promises as fs } from "fs"; +const dirname = import.meta.dirname; + +// you will need to keep the index configuration +// they will not export, also every change to the +// configuration requires a full re-index +const config = { + worker: true, + document: { + id: "tconst", + store: true, + index: [{ + field: "primaryTitle", + config: dirname + "/config.primaryTitle.js" + },{ + field: "originalTitle", + config: dirname + "/config.originalTitle.js" + }], + tag: [{ + field: "startYear" + },{ + field: "genres" + }] + } +}; + +(async function(){ + + // loading test data + const data = JSON.parse(await fs.readFile(dirname + "/data.json")); + + // create the document and await (!) for the instance response + let document = await new Document(config); + + // add test data + for(let i = 0; i < data.length; i++){ + await document.add(data[i]); + } + + // perform a query + let result = await document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + suggest: true, + enrich: true, + merge: true + }); + + console.log(result); + + // ----------------------- + // EXPORT + // ----------------------- + + // create folders for the export + // it should be empty before export + await fs.mkdir("./export/").catch(e => {}); + // call export + await document.export(async function(key, data){ + await fs.writeFile("./export/" + key, data, "utf8"); + }); + + // ----------------------- + // IMPORT + // ----------------------- + + // create the same type of index you have used by .export() + // along with the same configuration + document = await new Document(config); + + // load them in parallel + const files = await fs.readdir("./export/"); + await Promise.all(files.map(async file => { + const data = await fs.readFile("./export/" + file, "utf8"); + // call import + await document.import(file, data); + })); + + // perform a query + result = await document.search({ + query: "karmen", + tag: { + "startYear": "1894", + "genres": [ + "Documentary", + "Short" + ] + }, + suggest: true, + enrich: true, + merge: true + }); + + console.log("-------------------------------------"); + console.log(result); + +}()); diff --git a/example/nodejs-esm/document-worker-export-import/package.json b/example/nodejs-esm/document-worker-export-import/package.json new file mode 100644 index 0000000..d8a38df --- /dev/null +++ b/example/nodejs-esm/document-worker-export-import/package.json @@ -0,0 +1,7 @@ +{ + "name": "nodejs-esm-document-worker-export-import", + "type": "module", + "dependencies": { + "flexsearch": "github:nextapps-de/flexsearch" + } +} diff --git a/example/nodejs-esm/document-worker/package.json b/example/nodejs-esm/document-worker/package.json index 541bcf9..6f50823 100644 --- a/example/nodejs-esm/document-worker/package.json +++ b/example/nodejs-esm/document-worker/package.json @@ -2,6 +2,6 @@ "name": "nodejs-esm-document-worker", "type": "module", "dependencies": { - "flexsearch": "^0.8.105" + "flexsearch": "github:nextapps-de/flexsearch" } } diff --git a/package-lock.json b/package-lock.json index d1de39e..11229ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.111", + "version": "0.8.113", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.111", + "version": "0.8.113", "funding": [ { "type": "github", diff --git a/package.json b/package.json index ff8f267..7752e06 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.111", + "version": "0.8.113", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/src/document/add.js b/src/document/add.js index 6a6474d..469ca2e 100644 --- a/src/document/add.js +++ b/src/document/add.js @@ -4,7 +4,7 @@ import { SUPPORT_KEYSTORE, SUPPORT_PERSISTENT, SUPPORT_STORE, - SUPPORT_TAGS + SUPPORT_TAGS, SUPPORT_WORKER } from "../config.js"; // <-- COMPILER BLOCK import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js"; @@ -171,6 +171,10 @@ Document.prototype.add = function(id, content, _append){ this.store.set(id, payload || content); } + + if(SUPPORT_WORKER && this.worker){ + this.fastupdate || this.reg.add(id); + } } return this; diff --git a/src/serialize.js b/src/serialize.js index efff5d3..172f665 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -1,3 +1,6 @@ +// COMPILER BLOCK --> +import { SUPPORT_WORKER } from "./config.js"; +// <-- COMPILER BLOCK import Index from "./index.js"; import Document from "./document.js"; import { is_string } from "./common.js"; @@ -83,7 +86,7 @@ function json_to_ctx(json, ctx){ } /** - * @param {Set} reg + * @param {Set|Map>} reg * @return {Array>} */ function reg_to_json(reg){ @@ -244,6 +247,9 @@ export function importIndex(key, data){ if(split[split.length - 1] === "json"){ split.pop(); } + if(split.length === 3){ + split.shift(); + } key = split.length > 1 ? split[1] : split[0]; switch(key){ @@ -355,6 +361,18 @@ export function exportDocument(callback, _field, _index_doc = 0, _index_obj = 0) export function importDocument(key, data){ + const split = key.split("."); + if(split[split.length - 1] === "json"){ + split.pop(); + } + const field = split.length > 2 ? split[0] : ""; + const ref = split.length > 2 ? split[2] : split[1]; + + // trigger the import for worker field indexes + if(SUPPORT_WORKER && this.worker && field){ + return this.index.get(field).import(key); + } + if(!data){ return; } @@ -364,16 +382,9 @@ export function importDocument(key, data){ ); } - const split = key.split("."); - if(split[split.length - 1] === "json"){ - split.pop(); - } - const field = split.length > 2 ? split[0] : ""; - key = split.length > 2 ? split[2] : split[1]; - if(!field){ - switch(key){ + switch(ref){ case "reg": @@ -387,6 +398,22 @@ export function importDocument(key, data){ idx.reg = this.reg; } + // trigger the import for worker field indexes + if(SUPPORT_WORKER && this.worker){ + + const promises = []; + const self = this; + + for(const index of this.index.values()){ + // const ref = item[0]; + // const index = item[1]; + promises.push(index.import(key)); + //this.index.get(field).import(key); + } + + return Promise.all(promises); + } + break; case "tag": @@ -407,7 +434,7 @@ export function importDocument(key, data){ } else{ - return this.index.get(field).import(key, data); + return this.index.get(field).import(ref, data); } } diff --git a/src/worker.js b/src/worker.js index 14ae6bf..230f5d3 100644 --- a/src/worker.js +++ b/src/worker.js @@ -2,7 +2,7 @@ import { SUPPORT_ASYNC } from "./config.js"; // <-- COMPILER BLOCK import { IndexOptions } from "./type.js"; -import { create_object, is_function, is_object, is_string } from "./common.js"; +import { create_object } from "./common.js"; import handler from "./worker/handler.js"; import apply_async from "./async.js"; @@ -88,7 +88,6 @@ export default function WorkerIndex(options = /** @type IndexOptions */ ({})){ } const worker = create(factory, is_node_js, options.worker); - //worker.worker = true; return worker.then ? worker.then(function(worker){ return init.call(_self, worker); @@ -111,28 +110,29 @@ if(SUPPORT_ASYNC){ function register(key){ - WorkerIndex.prototype[key] = - /*WorkerIndex.prototype[key + "Async"] =*/ async function(){ + WorkerIndex.prototype[key] = function(){ const self = this; const args = [].slice.call(arguments); const arg = args[args.length - 1]; let callback; - if(is_function(arg)){ + if(typeof arg === "function"){ callback = arg; - args.splice(args.length - 1, 1); + args.pop(); } const promise = new Promise(function(resolve){ - //setTimeout(function(){ - self.resolver[++pid] = resolve; - self.worker.postMessage({ - "task": key, - "id": pid, - "args": args - }); - //}); + if(key === "export" && typeof args[0] === "function"){ + // remove function handler + args[0] = null; + } + self.resolver[++pid] = resolve; + self.worker.postMessage({ + "task": key, + "id": pid, + "args": args + }); }); if(callback){ @@ -140,7 +140,6 @@ function register(key){ return this; } else{ - return promise; } }; @@ -151,8 +150,7 @@ function create(factory, is_node_js, worker_path){ let worker worker = is_node_js ? - // This eval will be removed when compiling, it isn't there in final build - + // This eval will be removed when compiling 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")') @@ -170,7 +168,13 @@ function create(factory, is_node_js, worker_path){ ) )) : - new window.Worker(is_string(worker_path) ? worker_path : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js") /*"worker/worker.js"*/, { type: "module" }) + new window.Worker( + typeof worker_path === "string" + ? worker_path + : import.meta.url.replace("/worker.js", "/worker/worker.js") + .replace("flexsearch.bundle.module.min.js", "module/worker/worker.js") /*"worker/worker.js"*/ + , { type: "module" } + ) ); return worker; diff --git a/src/worker/handler.js b/src/worker/handler.js index 77271dc..4ab2a26 100644 --- a/src/worker/handler.js +++ b/src/worker/handler.js @@ -59,7 +59,13 @@ export default async function(data) { throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); } } - args = [options.export]; + // skip non-field indexes + if(!args[1]) args = null; + else{ + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if(task === "import"){ if(DEBUG){ @@ -67,11 +73,14 @@ export default async function(data) { throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); } } - await options.import.call(index, index); + if(args[0]){ + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else{ - message = index[task].apply(index, args); - if(message.then){ + message = args && index[task].apply(index, args); + if(message && message.then){ message = await message; } } diff --git a/src/worker/node.js b/src/worker/node.js index 1402938..a29bff4 100644 --- a/src/worker/node.js +++ b/src/worker/node.js @@ -1,3 +1,7 @@ +/* + * Node.js Worker (CommonJS) + * This file is a standalone file and isn't being a part of the build/bundle + */ const { parentPort } = require("worker_threads"); //const { join } = require("path"); // Test Path @@ -41,17 +45,26 @@ parentPort.on("message", async function(data){ if(!options.export || typeof options.export !== "function"){ throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); } - args = [options.export]; + // skip non-field indexes + if(!args[1]) args = null; + else{ + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if(task === "import"){ if(!options.import || typeof options.import !== "function"){ throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); } - await options.import.call(index, index); + if(args[0]){ + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else{ - message = index[task].apply(index, args); - if(message.then){ + message = args && index[task].apply(index, args); + if(message && message.then){ message = await message; } } diff --git a/src/worker/node.mjs b/src/worker/node.mjs index 14a1c52..ccdb210 100644 --- a/src/worker/node.mjs +++ b/src/worker/node.mjs @@ -1,3 +1,7 @@ +/* + * Node.js Worker (Standalone, ESM) + * This file is a standalone file and isn't being a part of the build/bundle + */ import { parentPort } from "worker_threads"; import { join } from "path"; // Test Path @@ -43,17 +47,26 @@ parentPort.on("message", async function(data){ if(!options.export || typeof options.export !== "function"){ throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"export\"."); } - args = [options.export]; + // skip non-field indexes + if(!args[1]) args = null; + else{ + args[0] = options.export; + args[2] = 0; + args[3] = 1; // skip reg + } } if(task === "import"){ if(!options.import || typeof options.import !== "function"){ throw new Error("Either no extern configuration provided for the Worker-Index or no method was defined on the config property \"import\"."); } - await options.import.call(index, index); + if(args[0]){ + const data = await options.import.call(index, args[0]); + index.import(args[0], data); + } } else{ - message = index[task].apply(index, args); - if(message.then){ + message = args && index[task].apply(index, args); + if(message && message.then){ message = await message; } }