1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-10-01 07:36:40 +02:00

bundle pre-release

This commit is contained in:
Thomas Wilkerling
2025-03-07 17:44:10 +01:00
parent 5bcbc72dac
commit 25e4b5d712
219 changed files with 44901 additions and 16106 deletions

3816
README.md

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +1,89 @@
/**! /**!
* FlexSearch.js v0.7.41 (Bundle) * FlexSearch.js v0.8.0 (Bundle)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function _f(self){'use strict';try{if(module)self=module}catch(e){}self._factory=_f;var t;function u(a){return"undefined"!==typeof a?a:!0}function v(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=x();return b}function x(){return Object.create(null)}function aa(a,b){return b.length-a.length}function C(a){return"string"===typeof a}function D(a){return"object"===typeof a}function E(a){return"function"===typeof a};function ba(a,b){var c=ca;if(a&&(b&&(a=F(a,b)),this.H&&(a=F(a,this.H)),this.J&&1<a.length&&(a=F(a,this.J)),c||""===c)){b=a.split(c);if(this.filter){a=this.filter;c=b.length;const d=[];for(let e=0,f=0;e<c;e++){const h=b[e];h&&!a[h]&&(d[f++]=h)}a=d}else a=b;return a}return a}const ca=/[\p{Z}\p{S}\p{P}\p{C}]+/u,da=/[\u0300-\u036f]/g; (function _f(self){'use strict';try{if(module)self=module}catch(e){}self._factory=_f;var u;function y(a,b,c){const d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===e?b:a}function z(){return Object.create(null)}function aa(a,b){return b.length-a.length}
function ea(a,b){const c=Object.keys(a),d=c.length,e=[];let f="",h=0;for(let g=0,k,m;g<d;g++)k=c[g],(m=a[k])?(e[h++]=G(b?"(?!\\b)"+k+"(\\b|_)":k),e[h++]=m):f+=(f?"|":"")+k;f&&(e[h++]=G(b?"(?!\\b)("+f+")(\\b|_)":"("+f+")"),e[h]="");return e}function F(a,b){for(let c=0,d=b.length;c<d&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a}function G(a){return new RegExp(a,"g")}function fa(a){let b="",c="";for(let d=0,e=a.length,f;d<e;d++)(f=a[d])!==c&&(b+=c=f);return b};var ia={encode:ha,F:!1,G:""};function ha(a){return ba.call(this,(""+a).toLowerCase(),!1)};const ja={},I={};function ka(a){J(a,"add");J(a,"append");J(a,"search");J(a,"update");J(a,"remove")}function J(a,b){a[b+"Async"]=function(){const c=this,d=arguments;var e=d[d.length-1];let f;E(e)&&(f=e,delete d[d.length-1]);e=new Promise(function(h){setTimeout(function(){c.async=!0;const g=c[b].apply(c,d);c.async=!1;h(g)})});return f?(e.then(f),this):e}};function la(a,b,c,d){const e=a.length;let f=[],h,g,k=0;d&&(d=[]);for(let m=e-1;0<=m;m--){const n=a[m],w=n.length,q=x();let r=!h;for(let l=0;l<w;l++){const p=n[l],A=p.length;if(A)for(let B=0,z,y;B<A;B++)if(y=p[B],h){if(h[y]){if(!m)if(c)c--;else if(f[k++]=y,k===b)return f;if(m||d)q[y]=1;r=!0}if(d&&(z=(g[y]||0)+1,g[y]=z,z<e)){const H=d[z-2]||(d[z-2]=[]);H[H.length]=y}}else q[y]=1}if(d)h||(g=q);else if(!r)return[];h=q}if(d)for(let m=d.length-1,n,w;0<=m;m--){n=d[m];w=n.length;for(let q=0,r;q<w;q++)if(r= function B(a){return"string"===typeof a}function C(a){return"object"===typeof a}function ba(a){const b=[];for(const c of a.keys())b.push(c);return b}function ca(a,b){if(B(b))a=a[b];else for(let c=0;a&&c<b.length;c++)a=a[b[c]];return a}function da(a){let b=0;for(let c=0,d;c<a.length;c++)(d=a[c])&&b<d.length&&(b=d.length);return b};const ea=/[^\p{L}\p{N}]+/u,fa=/(\d{3})/g,ha=/(\D)(\d{3})/g,ia=/(\d{3})(\D)/g,ja="".normalize&&/[\u0300-\u036f]/g,ka=!ja&&new Map([["\u00aa","a"],["\u00b2","2"],["\u00b3","3"],["\u00b9","1"],["\u00ba","o"],["\u00bc","1\u20444"],["\u00bd","1\u20442"],["\u00be","3\u20444"],["\u00e0","a"],["\u00e1","a"],["\u00e2","a"],["\u00e3","a"],["\u00e4","a"],["\u00e5","a"],["\u00e7","c"],["\u00e8","e"],["\u00e9","e"],["\u00ea","e"],["\u00eb","e"],["\u00ec","i"],["\u00ed","i"],["\u00ee","i"],["\u00ef","i"],["\u00f1",
n[q],!h[r]){if(c)c--;else if(f[k++]=r,k===b)return f;h[r]=1}}return f}function ma(a,b){const c=x(),d=x(),e=[];for(let f=0;f<a.length;f++)c[a[f]]=1;for(let f=0,h;f<b.length;f++){h=b[f];for(let g=0,k;g<h.length;g++)k=h[g],c[k]&&!d[k]&&(d[k]=1,e[e.length]=k)}return e};function K(a){this.l=!0!==a&&a;this.cache=x();this.h=[]}function na(a,b,c){D(a)&&(a=a.query);let d=this.cache.get(a);d||(d=this.search(a,b,c),this.cache.set(a,d));return d}K.prototype.set=function(a,b){if(!this.cache[a]){var c=this.h.length;c===this.l?delete this.cache[this.h[c-1]]:c++;for(--c;0<c;c--)this.h[c]=this.h[c-1];this.h[0]=a}this.cache[a]=b};K.prototype.get=function(a){const b=this.cache[a];if(this.l&&b&&(a=this.h.indexOf(a))){const c=this.h[a-1];this.h[a-1]=this.h[a];this.h[a]=c}return b};const pa={memory:{charset:"latin:extra",D:3,B:4,m:!1},performance:{D:3,B:3,s:!1,context:{depth:2,D:1}},match:{charset:"latin:extra",G:"reverse"},score:{charset:"latin:advanced",D:20,B:3,context:{depth:3,D:9}},"default":{}};function qa(a,b,c,d,e,f,h,g){setTimeout(function(){const k=a(c?c+"."+d:d,JSON.stringify(h));k&&k.then?k.then(function(){b.export(a,b,c,e,f+1,g)}):b.export(a,b,c,e,f+1,g)})};function L(a,b){if(!(this instanceof L))return new L(a);var c;if(a){C(a)?a=pa[a]:(c=a.preset)&&(a=Object.assign({},c[c],a));c=a.charset;var d=a.lang;C(c)&&(-1===c.indexOf(":")&&(c+=":default"),c=I[c]);C(d)&&(d=ja[d])}else a={};let e,f,h=a.context||{};this.encode=a.encode||c&&c.encode||ha;this.register=b||x();this.D=e=a.resolution||9;this.G=b=c&&c.G||a.tokenize||"strict";this.depth="strict"===b&&h.depth;this.l=u(h.bidirectional);this.s=f=u(a.optimize);this.m=u(a.fastupdate);this.B=a.minlength||1;this.C= "n"],["\u00f2","o"],["\u00f3","o"],["\u00f4","o"],["\u00f5","o"],["\u00f6","o"],["\u00f9","u"],["\u00fa","u"],["\u00fb","u"],["\u00fc","u"],["\u00fd","y"],["\u00ff","y"],["\u0101","a"],["\u0103","a"],["\u0105","a"],["\u0107","c"],["\u0109","c"],["\u010b","c"],["\u010d","c"],["\u010f","d"],["\u0113","e"],["\u0115","e"],["\u0117","e"],["\u0119","e"],["\u011b","e"],["\u011d","g"],["\u011f","g"],["\u0121","g"],["\u0123","g"],["\u0125","h"],["\u0129","i"],["\u012b","i"],["\u012d","i"],["\u012f","i"],["\u0133",
a.boost;this.map=f?v(e):x();this.A=e=h.resolution||1;this.h=f?v(e):x();this.F=c&&c.F||a.rtl;this.H=(b=a.matcher||d&&d.H)&&ea(b,!1);this.J=(b=a.stemmer||d&&d.J)&&ea(b,!0);if(c=b=a.filter||d&&d.filter){c=b;d=x();for(let g=0,k=c.length;g<k;g++)d[c[g]]=1;c=d}this.filter=c;this.cache=(b=a.cache)&&new K(b)}t=L.prototype;t.append=function(a,b){return this.add(a,b,!0)}; "ij"],["\u0135","j"],["\u0137","k"],["\u013a","l"],["\u013c","l"],["\u013e","l"],["\u0140","l"],["\u0144","n"],["\u0146","n"],["\u0148","n"],["\u0149","n"],["\u014d","o"],["\u014f","o"],["\u0151","o"],["\u0155","r"],["\u0157","r"],["\u0159","r"],["\u015b","s"],["\u015d","s"],["\u015f","s"],["\u0161","s"],["\u0163","t"],["\u0165","t"],["\u0169","u"],["\u016b","u"],["\u016d","u"],["\u016f","u"],["\u0171","u"],["\u0173","u"],["\u0175","w"],["\u0177","y"],["\u017a","z"],["\u017c","z"],["\u017e","z"],
t.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.register[a])return this.update(a,b);b=this.encode(b);if(d=b.length){const m=x(),n=x(),w=this.depth,q=this.D;for(let r=0;r<d;r++){let l=b[this.F?d-1-r:r];var e=l.length;if(l&&e>=this.B&&(w||!n[l])){var f=M(q,d,r),h="";switch(this.G){case "full":if(2<e){for(f=0;f<e;f++)for(var g=e;g>f;g--)if(g-f>=this.B){var k=M(q,d,r,e,f);h=l.substring(f,g);N(this,n,h,k,a,c)}break}case "reverse":if(1<e){for(g=e-1;0<g;g--)h=l[g]+h,h.length>=this.B&&N(this,n, ["\u017f","s"],["\u01a1","o"],["\u01b0","u"],["\u01c6","dz"],["\u01c9","lj"],["\u01cc","nj"],["\u01ce","a"],["\u01d0","i"],["\u01d2","o"],["\u01d4","u"],["\u01d6","u"],["\u01d8","u"],["\u01da","u"],["\u01dc","u"],["\u01df","a"],["\u01e1","a"],["\u01e3","ae"],["\u00e6","ae"],["\u01fd","ae"],["\u01e7","g"],["\u01e9","k"],["\u01eb","o"],["\u01ed","o"],["\u01ef","\u0292"],["\u01f0","j"],["\u01f3","dz"],["\u01f5","g"],["\u01f9","n"],["\u01fb","a"],["\u01ff","\u00f8"],["\u0201","a"],["\u0203","a"],["\u0205",
h,M(q,d,r,e,g),a,c);h=""}case "forward":if(1<e){for(g=0;g<e;g++)h+=l[g],h.length>=this.B&&N(this,n,h,f,a,c);break}default:if(this.C&&(f=Math.min(f/this.C(b,l,r)|0,q-1)),N(this,n,l,f,a,c),w&&1<d&&r<d-1)for(e=x(),h=this.A,f=l,g=Math.min(w+1,d-r),e[f]=1,k=1;k<g;k++)if((l=b[this.F?d-1-r-k:r+k])&&l.length>=this.B&&!e[l]){e[l]=1;const p=this.l&&l>f;N(this,m,p?f:l,M(h+(d/2>h?0:1),d,r,g-1,k-1),a,c,p?l:f)}}}}this.m||(this.register[a]=1)}}return this}; "e"],["\u0207","e"],["\u0209","i"],["\u020b","i"],["\u020d","o"],["\u020f","o"],["\u0211","r"],["\u0213","r"],["\u0215","u"],["\u0217","u"],["\u0219","s"],["\u021b","t"],["\u021f","h"],["\u0227","a"],["\u0229","e"],["\u022b","o"],["\u022d","o"],["\u022f","o"],["\u0231","o"],["\u0233","y"],["\u02b0","h"],["\u02b1","h"],["\u0266","h"],["\u02b2","j"],["\u02b3","r"],["\u02b4","\u0279"],["\u02b5","\u027b"],["\u02b6","\u0281"],["\u02b7","w"],["\u02b8","y"],["\u02e0","\u0263"],["\u02e1","l"],["\u02e2","s"],
function M(a,b,c,d,e){return c&&1<a?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0}function N(a,b,c,d,e,f,h){let g=h?a.h:a.map;if(!b[c]||h&&!b[c][h])a.s&&(g=g[d]),h?(b=b[c]||(b[c]=x()),b[h]=1,g=g[h]||(g[h]=x())):b[c]=1,g=g[c]||(g[c]=[]),a.s||(g=g[d]||(g[d]=[])),f&&g.includes(e)||(g[g.length]=e,a.m&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=g))} ["\u02e3","x"],["\u02e4","\u0295"],["\u0390","\u03b9"],["\u03ac","\u03b1"],["\u03ad","\u03b5"],["\u03ae","\u03b7"],["\u03af","\u03b9"],["\u03b0","\u03c5"],["\u03ca","\u03b9"],["\u03cb","\u03c5"],["\u03cc","\u03bf"],["\u03cd","\u03c5"],["\u03ce","\u03c9"],["\u03d0","\u03b2"],["\u03d1","\u03b8"],["\u03d2","\u03a5"],["\u03d3","\u03a5"],["\u03d4","\u03a5"],["\u03d5","\u03c6"],["\u03d6","\u03c0"],["\u03f0","\u03ba"],["\u03f1","\u03c1"],["\u03f2","\u03c2"],["\u03f5","\u03b5"],["\u0439","\u0438"],["\u0450",
t.search=function(a,b,c){c||(!b&&D(a)?(c=a,a=c.query):D(b)&&(c=b));let d=[],e;let f,h=0;if(c){a=c.query||a;b=c.limit;h=c.offset||0;var g=c.context;f=c.suggest}if(a&&(a=this.encode(""+a),e=a.length,1<e)){c=x();var k=[];for(let n=0,w=0,q;n<e;n++)if((q=a[n])&&q.length>=this.B&&!c[q])if(this.s||f||this.map[q])k[w++]=q,c[q]=1;else return d;a=k;e=a.length}if(!e)return d;b||(b=100);g=this.depth&&1<e&&!1!==g;c=0;let m;g?(m=a[0],c=1):1<e&&a.sort(aa);for(let n,w;c<e;c++){w=a[c];g?(n=ra(this,d,f,b,h,2===e,w, "\u0435"],["\u0451","\u0435"],["\u0453","\u0433"],["\u0457","\u0456"],["\u045c","\u043a"],["\u045d","\u0438"],["\u045e","\u0443"],["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]]);
m),f&&!1===n&&d.length||(m=w)):n=ra(this,d,f,b,h,1===e,w);if(n)return n;if(f&&c===e-1){k=d.length;if(!k){if(g){g=0;c=-1;continue}return d}if(1===k)return sa(d[0],b,h)}}return la(d,b,h,f)}; function E(a={}){if(!(this instanceof E))return new E(...arguments);for(a=0;a<arguments.length;a++)this.assign(arguments[a])}
function ra(a,b,c,d,e,f,h,g){let k=[],m=g?a.h:a.map;a.s||(m=ta(m,h,g,a.l));if(m){let n=0;const w=Math.min(m.length,g?a.A:a.D);for(let q=0,r=0,l,p;q<w;q++)if(l=m[q])if(a.s&&(l=ta(l,h,g,a.l)),e&&l&&f&&(p=l.length,p<=e?(e-=p,l=null):(l=l.slice(e),e=0)),l&&(k[n++]=l,f&&(r+=l.length,r>=d)))break;if(n){if(f)return sa(k,d,0);b[b.length]=k;return}}return!c&&k}function sa(a,b,c){a=1===a.length?a[0]:[].concat.apply([],a);return c||a.length>b?a.slice(c,c+b):a} E.prototype.assign=function(a){this.normalize=y(a.normalize,!0,this.normalize);let b=a.ga,c=b||a.na||a.split;if("object"===typeof c){let d=!b,e="";a.ga||(e+="\\p{Z}");c.ka&&(e+="\\p{L}");c.oa&&(e+="\\p{N}",d=!!b);c.qa&&(e+="\\p{S}");c.pa&&(e+="\\p{P}");c.control&&(e+="\\p{C}");if(c=c.char)e+="object"===typeof c?c.join(""):c;this.split=new RegExp("["+(b?"^":"")+e+"]+","u");this.numeric=d}else this.split=y(c,ea,this.split),this.numeric=y(this.numeric,!0);this.$=y(a.$,null,this.$);this.V=y(a.V,null,
function ta(a,b,c,d){c?(d=d&&b>c,a=(a=a[d?b:c])&&a[d?c:b]):a=a[b];return a}t.contain=function(a){return!!this.register[a]};t.update=function(a,b){return this.remove(a).add(a,b)}; this.V);this.rtl=a.rtl||!1;this.C=y(a.C,!0,this.C);this.filter=y((c=a.filter)&&new Set(c),null,this.filter);this.J=y((c=a.J)&&new Map(c),null,this.J);this.D=y((c=a.D)&&new Map(c),null,this.D);this.N=y((c=a.N)&&new Map(c),null,this.N);this.K=y(a.K,null,this.K);this.Z=y(a.Z,1,this.Z);this.ha=y(a.ha,0,this.ha);if(this.cache=c=y(a.cache,!0,this.cache))this.X=null,this.ea="number"===typeof c?c:2E5,this.P=new Map,this.U=new Map,this.B=this.h=128;this.F="";this.ba=null;this.Y="";this.ca=null;if(this.J)for(const d of this.J.keys())this.F+=
t.remove=function(a,b){const c=this.register[a];if(c){if(this.m)for(let d=0,e;d<c.length;d++)e=c[d],e.splice(e.indexOf(a),1);else O(this.map,a,this.D,this.s),this.depth&&O(this.h,a,this.A,this.s);b||delete this.register[a];if(this.cache){b=this.cache;for(let d=0,e,f;d<b.h.length;d++)f=b.h[d],e=b.cache[f],e.includes(a)&&(b.h.splice(d--,1),delete b.cache[f])}}return this}; (this.F?"|":"")+d;if(this.N)for(const d of this.N.keys())this.Y+=(this.Y?"|":"")+d;return this};
function O(a,b,c,d,e){let f=0;if(a.constructor===Array)if(e)b=a.indexOf(b),-1!==b?1<a.length&&(a.splice(b,1),f++):f++;else{e=Math.min(a.length,c);for(let h=0,g;h<e;h++)if(g=a[h])f=O(g,b,c,d,e),d||f||delete a[h]}else for(let h in a)(f=O(a[h],b,c,d,e))||delete a[h];return f}t.searchCache=na; E.prototype.encode=function(a){if(this.cache&&a.length<=this.h)if(this.X){if(this.P.has(a))return this.P.get(a)}else this.X=setTimeout(la,0,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):ja?a=a.normalize("NFKD").replace(ja,"").toLowerCase():(a=a.toLowerCase(),this.D=this.D?new Map([...ka,...this.D]):new Map(ka)));this.$&&(a=this.$(a));this.numeric&&3<a.length&&(a=a.replace(ha,"$1 $2").replace(ia,"$1 $2").replace(fa,"$1 "));const b=!(this.C||this.D||this.filter||this.J||
t.export=function(a,b,c,d,e,f){let h=!0;"undefined"===typeof f&&(h=new Promise(m=>{f=m}));let g,k;switch(e||(e=0)){case 0:g="reg";if(this.m){k=x();for(let m in this.register)k[m]=1}else k=this.register;break;case 1:g="cfg";k={doc:0,opt:this.s?1:0};break;case 2:g="map";k=this.map;break;case 3:g="ctx";k=this.h;break;default:"undefined"===typeof c&&f&&f();return}qa(a,b||this,c,g,d,e,k,f);return h}; this.N||this.K);let c=[],d=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;f<d.length;f++){if(!(g=h=d[f]))continue;if(g.length<this.Z)continue;if(b){c.push(g);continue}if(this.filter&&this.filter.has(g))continue;if(this.cache&&g.length<=this.B)if(this.X){var e=this.U.get(g);if(e||""===e){e&&c.push(e);continue}}else this.X=setTimeout(la,0,this);let k;this.N&&2<g.length&&(this.ca||(this.ca=new RegExp("(?!^)("+this.Y+")$")),g=g.replace(this.ca,l=>this.N.get(l)),k=1);this.J&&1<g.length&&
t.import=function(a,b){if(b)switch(C(b)&&(b=JSON.parse(b)),a){case "cfg":this.s=!!b.opt;break;case "reg":this.m=!1;this.register=b;break;case "map":this.map=b;break;case "ctx":this.h=b}};ka(L.prototype);function ua(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};a=a.factory;b=d.encode;d.cache=!1;b&&0===b.indexOf("function")&&(d.encode=Function("return "+b)());a?(Function("return "+a)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new L(d);break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let va=0;function P(a){if(!(this instanceof P))return new P(a);var b;a?E(b=a.encode)&&(a.encode=b.toString()):a={};(b=(self||window)._factory)&&(b=b.toString());const c="undefined"===typeof window&&self.exports,d=this;this.o=wa(b,c,a.worker);this.h=x();if(this.o){if(c)this.o.on("message",function(e){d.h[e.id](e.msg);delete d.h[e.id]});else this.o.onmessage=function(e){e=e.data;d.h[e.id](e.msg);delete d.h[e.id]};this.o.postMessage({task:"init",factory:b,options:a})}}Q("add");Q("append");Q("search"); (this.ba||(this.ba=new RegExp("("+this.F+")","g")),g=g.replace(this.ba,l=>this.J.get(l)),k=1);g&&k&&(g.length<this.Z||this.filter&&this.filter.has(g))&&(g="");if(g&&(this.D||this.C&&1<g.length)){e="";for(let l=0,m="",n,q;l<g.length;l++)n=g.charAt(l),n===m&&this.C||((q=this.D&&this.D.get(n))||""===q?q===m&&this.C||!(m=q)||(e+=q):e+=m=n);g=e}if(g&&this.K)for(e=0;g&&e<this.K.length;e+=2)g=g.replace(this.K[e],this.K[e+1]);this.cache&&h.length<=this.B&&(this.U.set(h,g),this.U.size>this.ea&&(this.U.clear(),
Q("update");Q("remove");function Q(a){P.prototype[a]=P.prototype[a+"Async"]=function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;E(d)&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){setTimeout(function(){b.h[++va]=f;b.o.postMessage({task:a,id:va,args:c})})});return e?(d.then(e),this):d}} this.B=this.B/1.1|0));g&&c.push(g)}this.V&&(c=this.V(c)||c);this.cache&&a.length<=this.h&&(this.P.set(a,c),this.P.size>this.ea&&(this.P.clear(),this.h=this.h/1.1|0));return c};function la(a){a.X=null;a.P.clear();a.U.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d instanceof Promise){const e=this;d.then(function(f){e.cache.set(a,f)})}this.cache.set(a,d)}return d}function F(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}F.prototype.set=function(a,b){this.cache.has(a)||(this.cache.set(this.h=a,b),this.limit&&this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value))};
function wa(a,b,c){let d;try{d=b?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):a?new Worker(URL.createObjectURL(new Blob(["onmessage="+ua.toString()],{type:"text/javascript"}))):new Worker(C(c)?c:"worker/worker.js",{type:"module"})}catch(e){}return d};function S(a){if(!(this instanceof S))return new S(a);var b=a.document||a.doc||a,c;this.K=[];this.h=[];this.A=[];this.register=x();this.key=(c=b.key||b.id)&&T(c,this.A)||"id";this.m=u(a.fastupdate);this.C=(c=b.store)&&!0!==c&&[];this.store=c&&x();this.I=(c=b.tag)&&T(c,this.A);this.l=c&&x();this.cache=(c=a.cache)&&new K(c);a.cache=!1;this.o=a.worker;this.async=!1;c=x();let d=b.index||b.field||b;C(d)&&(d=[d]);for(let e=0,f,h;e<d.length;e++)f=d[e],C(f)||(h=f,f=f.field),h=D(h)?Object.assign({},a,h):a, F.prototype.get=function(a){const b=this.cache.get(a);b&&this.limit&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};F.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};F.prototype.clear=function(){this.cache.clear();this.h=""};function na(a,b,c,d){let e=[];for(let f=0,g;f<a.index.length;f++)if(g=a.index[f],b>=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e}
this.o&&(c[f]=new P(h),c[f].o||(this.o=!1)),this.o||(c[f]=new L(h,this.register)),this.K[e]=T(f,this.A),this.h[e]=f;if(this.C)for(a=b.store,C(a)&&(a=[a]),b=0;b<a.length;b++)this.C[b]=T(a[b],this.A);this.index=c}function T(a,b){const c=a.split(":");let d=0;for(let e=0;e<c.length;e++)a=c[e],0<=a.indexOf("[]")&&(a=a.substring(0,a.length-2))&&(b[d]=!0),a&&(c[d++]=a);d<c.length&&(c.length=d);return 1<d?c:c[0]}function U(a,b){if(C(b))a=a[b];else for(let c=0;a&&c<b.length;c++)a=a[b[c]];return a} function H(a){if(!(this instanceof H))return new H(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;g<b.index.length;g++){h=b.index[g];k=h.indexOf(e);if(0<=k)return f+k;f+=h.length}return-1};if("includes"===
function V(a,b,c,d,e){a=a[e];if(d===c.length-1)b[e]=a;else if(a)if(a.constructor===Array)for(b=b[e]=Array(a.length),e=0;e<a.length;e++)V(a,b,c,d,e);else b=b[e]||(b[e]=x()),e=c[++d],V(a,b,c,d,e)}function X(a,b,c,d,e,f,h,g){if(a=a[h])if(d===b.length-1){if(a.constructor===Array){if(c[d]){for(b=0;b<a.length;b++)e.add(f,a[b],!0,!0);return}a=a.join(" ")}e.add(f,a,g,!0)}else if(a.constructor===Array)for(h=0;h<a.length;h++)X(a,b,c,d,e,f,h,g);else h=b[++d],X(a,b,c,d,e,f,h,g)}t=S.prototype; d)return function(e){for(let f=0;f<b.index.length;f++)if(b.index[f].includes(e))return!0;return!1};if("slice"===d)return function(e,f){return na(b,e||0,f||b.length,!1)};if("splice"===d)return function(e,f){return na(b,e||0,f||b.length,!0)};if("constructor"===d)return Array;if("symbol"!==typeof d)return(c=b.index[d/2**31|0])&&c[d]},set(c,d,e){c=d/2**31|0;(b.index[c]||(b.index[c]=[]))[d]=e;b.length++;return!0}})}H.prototype.clear=function(){this.index.length=0};H.prototype.push=function(){};
t.add=function(a,b,c){D(a)&&(b=a,a=U(b,this.key));if(b&&(a||0===a)){if(!c&&this.register[a])return this.update(a,b);for(let d=0,e,f;d<this.h.length;d++)f=this.h[d],e=this.K[d],C(e)&&(e=[e]),X(b,e,this.A,0,this.index[f],a,e[0],c);if(this.I){let d=U(b,this.I),e=x();C(d)&&(d=[d]);for(let f=0,h,g;f<d.length;f++)if(h=d[f],!e[h]&&(e[h]=1,g=this.l[h]||(this.l[h]=[]),!c||!g.includes(a)))if(g[g.length]=a,this.m){const k=this.register[a]||(this.register[a]=[]);k[k.length]=g}}if(this.store&&(!c||!this.store[a])){let d; function K(a=8){if(!(this instanceof K))return new K(a);this.index=z();this.F=[];this.size=0;32<a?(this.h=oa,this.B=BigInt(a)):(this.h=pa,this.B=a)}K.prototype.get=function(a){const b=this.index[this.h(a)];return b&&b.get(a)};K.prototype.set=function(a,b){var c=this.h(a);let d=this.index[c];d?(c=d.size,d.set(a,b),(c-=d.size)&&this.size++):(this.index[c]=d=new Map([[a,b]]),this.F.push(d))};
if(this.C){d=x();for(let e=0,f;e<this.C.length;e++)f=this.C[e],C(f)?d[f]=b[f]:V(b,d,f,0,f[0])}this.store[a]=d||b}}return this};t.append=function(a,b){return this.add(a,b,!0)};t.update=function(a,b){return this.remove(a).add(a,b)}; function L(a=8){if(!(this instanceof L))return new L(a);this.index=z();this.h=[];32<a?(this.F=oa,this.B=BigInt(a)):(this.F=pa,this.B=a)}L.prototype.add=function(a){var b=this.F(a);let c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.h.push(c))};u=K.prototype;u.has=L.prototype.has=function(a){const b=this.index[this.F(a)];return b&&b.has(a)};u.delete=L.prototype.delete=function(a){const b=this.index[this.F(a)];b&&b.delete(a)&&this.size--};
t.remove=function(a){D(a)&&(a=U(a,this.key));if(this.register[a]){for(var b=0;b<this.h.length&&(this.index[this.h[b]].remove(a,!this.o),!this.m);b++);if(this.I&&!this.m)for(let c in this.l){b=this.l[c];const d=b.indexOf(a);-1!==d&&(1<b.length?b.splice(d,1):delete this.l[c])}this.store&&delete this.store[a];delete this.register[a]}return this}; u.clear=L.prototype.clear=function(){this.index=z();this.h=[];this.size=0};u.values=L.prototype.values=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].values())yield b};u.keys=L.prototype.keys=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].keys())yield b};u.entries=L.prototype.entries=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].entries())yield b};
t.search=function(a,b,c,d){c||(!b&&D(a)?(c=a,a=""):D(b)&&(c=b,b=0));let e=[],f=[],h,g,k,m,n,w,q=0;if(c)if(c.constructor===Array)k=c,c=null;else{a=c.query||a;k=(h=c.pluck)||c.index||c.field;m=c.tag;g=this.store&&c.enrich;n="and"===c.bool;b=c.limit||b||100;w=c.offset||0;if(m&&(C(m)&&(m=[m]),!a)){for(let l=0,p;l<m.length;l++)if(p=xa.call(this,m[l],b,w,g))e[e.length]=p,q++;return q?e:[]}C(k)&&(k=[k])}k||(k=this.h);n=n&&(1<k.length||m&&1<m.length);const r=!d&&(this.o||this.async)&&[];for(let l=0,p,A,B;l< function pa(a){let b=2**this.B-1;if("number"==typeof a)return a&b;let c=0,d=this.B+1;for(let e=0;e<a.length;e++)c=(c*d^a.charCodeAt(e))&b;return 32===this.B?c+2**31:c}function oa(a){let b=BigInt(2)**this.B-BigInt(1);var c=typeof a;if("bigint"===c)return a&b;if("number"===c)return BigInt(a)&b;c=BigInt(0);let d=this.B+BigInt(1);for(let e=0;e<a.length;e++)c=(c*d^BigInt(a.charCodeAt(e)))&b;return c};function qa(a,b,c,d,e,f,g,h){(d=a(c?c+"."+d:d,JSON.stringify(g)))&&d.then?d.then(function(){b.export(a,b,c,e,f+1,h)}):b.export(a,b,c,e,f+1,h)};const ra=z(),M=z();var sa={normalize:function(a){return a.toLowerCase()},C:!1};const ta={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};function ua(a){O.call(a,"add");O.call(a,"append");O.call(a,"search");O.call(a,"update");O.call(a,"remove")}function O(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);this.async=!0;b=this[a].apply(this,b);this.async=!1;b.then?b.then(d):d(b);return b}};z();P.prototype.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.A.has(a))return this.update(a,b);b=this.encoder.encode(b);if(d=b.length){const l=z(),m=z(),n=this.depth,q=this.resolution;for(let t=0;t<d;t++){let p=b[this.rtl?d-1-t:t];var e=p.length;if(e&&(n||!m[p])){var f=this.score?this.score(b,p,t,null,0):Q(q,d,t),g="";switch(this.tokenize){case "full":if(2<e){for(f=0;f<e;f++)for(var h=e;h>f;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,t,g,f):Q(q,d,t,e,f);R(this,m,g,k,a,c)}break}case "reverse":if(1<
k.length;l++){let z;A=k[l];C(A)||(z=A,A=z.field,a=z.query||a,b=z.limit||b,g=z.enrich||g);if(r)r[l]=this.index[A].searchAsync(a,b,z||c);else{d?p=d[l]:p=this.index[A].search(a,b,z||c);B=p&&p.length;if(m&&B){const y=[];let H=0;n&&(y[0]=[p]);for(let W=0,oa,R;W<m.length;W++)if(oa=m[W],B=(R=this.l[oa])&&R.length)H++,y[y.length]=n?[R]:R;H&&(p=n?la(y,b||100,w||0):ma(p,y),B=p.length)}if(B)f[q]=A,e[q++]=p;else if(n)return[]}}if(r){const l=this;return new Promise(function(p){Promise.all(r).then(function(A){p(l.search(a, e){for(h=e-1;0<h;h--)g=p[h]+g,k=this.score?this.score(b,p,t,g,h):Q(q,d,t,e,h),R(this,m,g,k,a,c);g=""}case "forward":if(1<e){for(h=0;h<e;h++)g+=p[h],R(this,m,g,f,a,c);break}default:if(R(this,m,p,f,a,c),n&&1<d&&t<d-1)for(e=z(),g=this.da,f=p,h=Math.min(n+1,d-t),e[f]=1,k=1;k<h;k++)if((p=b[this.rtl?d-1-t-k:t+k])&&!e[p]){e[p]=1;const r=this.score?this.score(b,f,t,p,k):Q(g+(d/2>g?0:1),d,t,h-1,k-1),x=this.bidirectional&&p>f;R(this,l,x?f:p,r,a,c,x?p:f)}}}}this.fastupdate||this.A.add(a)}else b=""}this.db&&
b,c,A))})})}if(!q)return[];if(h&&(!g||!this.store))return e[0];for(let l=0,p;l<f.length;l++){p=e[l];p.length&&g&&(p=ya.call(this,p));if(h)return p;e[l]={field:f[l],result:p}}return e};function xa(a,b,c,d){let e=this.l[a],f=e&&e.length-c;if(f&&0<f){if(f>b||c)e=e.slice(c,c+b);d&&(e=ya.call(this,e));return{tag:a,result:e}}}function ya(a){const b=Array(a.length);for(let c=0,d;c<a.length;c++)d=a[c],b[c]={id:d,doc:this.store[d]};return b}t.contain=function(a){return!!this.register[a]};t.get=function(a){return this.store[a]}; (b||this.R.push({del:a}),this.fa&&va(this));return this};function R(a,b,c,d,e,f,g){let h=g?a.I:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new H(h);if(a.fastupdate)for(let l of a.A.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.A.get(e))?d.push(h):a.A.set(e,[h]))}}
t.set=function(a,b){this.store[a]=b;return this};t.searchCache=na;t.export=function(a,b,c,d,e,f){let h;"undefined"===typeof f&&(h=new Promise(g=>{f=g}));e||(e=0);d||(d=0);if(d<this.h.length){const g=this.h[d],k=this.index[g];b=this;setTimeout(function(){k.export(a,b,e?g:"",d,e++,f)||(d++,e=1,b.export(a,b,g,d,e,f))})}else{let g,k;switch(e){case 1:g="tag";k=this.l;c=null;break;case 2:g="store";k=this.store;c=null;break;default:f();return}qa(a,this,c,g,d,e,k,f)}return h}; function Q(a,b,c,d,e){return c&&1<a?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0};function S(a,b,c,d){if(1===a.length)return a=a[0],a=c||a.length>b?b?a.slice(c,c+b):a.slice(c):a,d?wa(a):a;let e=[];for(let f=0,g,h;f<a.length;f++)if((g=a[f])&&(h=g.length)){if(c){if(c>=h){c-=h;continue}c<h&&(g=b?g.slice(c,c+b):g.slice(c),h=g.length,c=0)}if(e.length)h>b&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?wa(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1<e.length?[].concat.apply([],e):e[0];return d?wa(e):e}
t.import=function(a,b){if(b)switch(C(b)&&(b=JSON.parse(b)),a){case "tag":this.l=b;break;case "reg":this.m=!1;this.register=b;for(let d=0,e;d<this.h.length;d++)e=this.index[this.h[d]],e.register=b,e.m=!1;break;case "store":this.store=b;break;default:a=a.split(".");const c=a[0];a=a[1];c&&a&&this.index[c].import(a,b)}};ka(S.prototype);var Aa={encode:za,F:!1,G:""};const Ba=[G("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",G("[\u00e8\u00e9\u00ea\u00eb]"),"e",G("[\u00ec\u00ed\u00ee\u00ef]"),"i",G("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",G("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",G("[\u00fd\u0177\u00ff]"),"y",G("\u00f1"),"n",G("[\u00e7c]"),"k",G("\u00df"),"s",G(" & ")," and "];function za(a){var b=a=""+a;b.normalize&&(b=b.normalize("NFD").replace(da,""));return ba.call(this,b.toLowerCase(),!a.normalize&&Ba)};var Da={encode:Ca,F:!1,G:"strict"};const Ea=/[^a-z0-9]+/,Fa={b:"p",v:"f",w:"f",z:"s",x:"s","\u00df":"s",d:"t",n:"m",c:"k",g:"k",j:"k",q:"k",i:"e",y:"e",u:"o"};function Ca(a){a=za.call(this,a).join(" ");const b=[];if(a){const c=a.split(Ea),d=c.length;for(let e=0,f,h=0;e<d;e++)if((a=c[e])&&(!this.filter||!this.filter[a])){f=a[0];let g=Fa[f]||f,k=g;for(let m=1;m<a.length;m++){f=a[m];const n=Fa[f]||f;n&&n!==k&&(g+=n,k=n)}b[h++]=g}}return b};var Ha={encode:Ga,F:!1,G:""};const Ia=[G("ae"),"a",G("oe"),"o",G("sh"),"s",G("th"),"t",G("ph"),"f",G("pf"),"f",G("(?![aeo])h(?![aeo])"),"",G("(?!^[aeo])h(?!^[aeo])"),""];function Ga(a,b){a&&(a=Ca.call(this,a).join(" "),2<a.length&&(a=F(a,Ia)),b||(1<a.length&&(a=fa(a)),a&&(a=a.split(" "))));return a||[]};var Ka={encode:Ja,F:!1,G:""};const La=G("(?!\\b)[aeo]");function Ja(a){a&&(a=Ga.call(this,a,!0),1<a.length&&(a=a.replace(La,"")),1<a.length&&(a=fa(a)),a&&(a=a.split(" ")));return a||[]};I["latin:default"]=ia;I["latin:simple"]=Aa;I["latin:balance"]=Da;I["latin:advanced"]=Ha;I["latin:extra"]=Ka;const Y={Index:L,Document:S,Worker:P,registerCharset:function(a,b){I[a]=b},registerLanguage:function(a,b){ja[a]=b}};let Z;(Z=self.define)&&Z.amd?Z([],function(){return Y}):self.exports?self.exports=Y:self.FlexSearch=Y;}(this)); function wa(a){for(let b=0;b<a.length;b++)a[b]={score:b,id:a[b]};return a};T.prototype.or=function(){const a=this;let b=arguments;var c=b[0];if(c instanceof Promise)return c.then(function(){return a.or.apply(a,b)});if(c[0]&&c[0].index)return this.or.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;k<b.length;k++)if(l=b[k]){let m;if(l instanceof T)m=l.result;else if(l.constructor===Array)m=l;else if(l.index)l.resolve=!1,m=l.index.search(l).result;else if(l.and)m=this.and(l.and);else if(l.xor)m=this.xor(l.xor);else if(l.G)m=this.G(l.G);else{e=l.limit||0;f=l.offset||
0;g=l.enrich;h=l.resolve;continue}d[k]=m;m instanceof Promise&&c.push(m)}if(c.length)return Promise.all(c).then(function(){a.result.length&&(d=[a.result].concat(d));a.result=xa(d,e,f,g,h,a.O);return h?a.result:a});this.result.length&&(d=[this.result].concat(d));this.result=xa(d,e,f,g,h,a.O);return h?this.result:this};
function xa(a,b,c,d,e,f){if(!a.length)return a;"object"===typeof b&&(c=b.offset||0,d=b.enrich||!1,b=b.limit||0);if(2>a.length)return e?S(a[0],b,c,d):a[0];d=[];let g=0,h=z(),k=da(a);for(let l=0,m;l<k;l++)for(let n=0,q;n<a.length;n++)if(q=a[n])if(m=q[l])for(let t=0,p;t<m.length;t++)if(p=m[t],!h[p])if(h[p]=1,c)c--;else{if(e)d.push(p);else{const r=l+(n?f:0);d[r]||(d[r]=[]);d[r].push(p)}if(b&&++g===b)return d}return d};T.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a instanceof Promise)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g;for(let h=0,k;h<c.length;h++)if(k=c[h]){let l;if(k instanceof T)l=k.result;else if(k.constructor===Array)l=k;else if(k.index)k.resolve=!1,l=k.index.search(k).result;else if(k.or)l=this.or(k.or);else if(k.xor)l=this.xor(k.xor);else if(k.G)l=this.G(k.G);else{e=
k.limit||0;f=k.offset||0;g=k.resolve;continue}d[h]=l;l instanceof Promise&&a.push(l)}if(a.length)return Promise.all(a).then(function(){d=[b.result].concat(d);b.result=ya(d,e,f,g,b.O);return g?b.result:b});d=[this.result].concat(d);this.result=ya(d,e,f,g,b.O);return g?this.result:this}return this};
function ya(a,b,c,d,e){if(2>a.length)return[];let f=[],g=0,h=z(),k=da(a);if(!k)return f;for(let l=0,m;l<a.length;l++){m=a[l];if(!m||!m.length)return[];let n=z(),q=0,t=l===a.length-1;for(let p=0,r;p<k;p++)if(r=m[p])for(let x=0,A,w;x<r.length;x++)if(A=r[x],!l)n[A]=p+1+(l?e:0),q=1;else if(t){if(w=h[A])if(q=1,c)c--;else if(d?f.push(A):(w--,p<w&&(w=p),f[w]||(f[w]=[]),f[w].push(A)),b&&++g===b)return f}else if(w=h[A])p+1<w&&(w=p+1),n[A]=w,q=1;if(!q)return[];h=n}return f};T.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c instanceof Promise)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;k<b.length;k++)if(l=b[k]){let m;if(l instanceof T)m=l.result;else if(l.constructor===Array)m=l;else if(l.index)l.resolve=!1,m=l.index.search(l).result;else if(l.or)m=this.or(l.or);else if(l.and)m=this.and(l.and);else if(l.G)m=this.G(l.G);else{e=l.limit||0;f=l.offset||
0;g=l.enrich;h=l.resolve;continue}d[k]=m;m instanceof Promise&&c.push(m)}if(c.length)return Promise.all(c).then(function(){a.result.length&&(d=[a.result].concat(d));a.result=za(d,e,f,g,!h,a.O);return h?a.result:a});this.result.length&&(d=[this.result].concat(d));this.result=za(d,e,f,g,!h,a.O);return h?this.result:this};
function za(a,b,c,d,e,f){if(!a.length)return a;if(2>a.length)return e?S(a[0],b,c,d):a[0];b=[];c=z();for(let g=0,h;g<a.length;g++)if(h=a[g])for(let k=0,l;k<h.length;k++)if(l=h[k])for(let m=0,n;m<l.length;m++)n=l[m],c[n]?c[n]++:c[n]=1;for(let g=0,h;g<a.length;g++)if(h=a[g])for(let k=0,l;k<h.length;k++)if(l=h[k])for(let m=0,n;m<l.length;m++)n=l[m],1===c[n]&&(e?b.push(n):(d=k+(g?f:0),b[d]||(b[d]=[]),b[d].push(n)));return b};T.prototype.G=function(){const a=this;let b=arguments;var c=b[0];if(c instanceof Promise)return c.then(function(){return a.G.apply(a,b)});if(c[0]&&c[0].index)return this.G.apply(this,c);let d=[];c=[];let e;for(let f=0,g;f<b.length;f++)if(g=b[f]){let h;if(g instanceof T)h=g.result;else if(g.constructor===Array)h=g;else if(g.index)g.resolve=!1,h=g.index.search(g).result;else if(g.or)h=this.or(g.or);else if(g.and)h=this.and(g.and);else if(g.xor)h=this.xor(g.xor);else{e=g.resolve;continue}d[f]=h;h instanceof
Promise&&c.push(h)}if(c.length)return Promise.all(c).then(function(){a.result=Aa.call(a,d,e);return e?a.result:a});this.result=Aa.call(this,d,e);return e?this.result:this};function Aa(a,b){if(!a.length)return this.result;const c=[];a=new Set(a.flat().flat());for(let d=0,e;d<this.result.length;d++)if(e=this.result[d])for(let f=0,g;f<e.length;f++)g=e[f],a.has(g)||(b?c.push(g):(c[d]||(c[d]=[]),c[d].push(g)));return c};function T(a){if(a&&a.index)return a.resolve=!1,this.index=a.index,a.index.search(a);if(!(this instanceof T))return new T(a);if(a instanceof T)return a;this.index=null;this.result=a||[];this.O=0}T.prototype.limit=function(a){if(this.result.length){const b=[];let c=0;for(let d=0,e;d<this.result.length;d++)if(e=this.result[d],e.length+c<a)b[d]=e,c+=e.length;else{b[d]=e.slice(0,a-c);this.result=b;break}}return this};
T.prototype.offset=function(a){if(this.result.length){const b=[];let c=0;for(let d=0,e;d<this.result.length;d++)e=this.result[d],e.length+c<a?c+=e.length:(b[d]=e.slice(a-c),c=a);this.result=b}return this};T.prototype.resolve=function(a,b,c){U=1;const d=this.result;this.result=this.index=null;return d.length?("object"===typeof a&&(c=a.enrich,b=a.offset,a=a.limit),S(d,a||100,b,c)):d};function Ba(a,b,c,d){var e=a.length;let f=[],g=0,h,k,l;d&&(d=[]);for(let m=e-1,n;0<=m;m--){l=a[m];e=z();n=!h;for(let q=0,t;q<l.length;q++)if((t=l[q])&&t.length)for(let p=0,r;p<t.length;p++)if(r=t[p],h){if(h[r]){if(!m)if(c)c--;else if(f[g++]=r,g===b)return f;if(m||d)e[r]=1;n=!0}d&&!k[r]&&(k[r]=1,(d[q]||(d[q]=[])).push(r))}else e[r]=1;if(d)h||(k=e);else if(!n)return[];h=e}if(d)for(let m=d.length-1,n,q;0<=m;m--){n=d[m];q=n.length;for(let t=0,p;t<q;t++)if(p=n[t],!h[p]){if(c)c--;else if(f[g++]=p,g===b)return f;
h[p]=1}}return f}function Ca(a,b){const c=z(),d=z(),e=[];for(let f=0;f<a.length;f++)c[a[f]]=1;for(let f=0,g;f<b.length;f++){g=b[f];for(let h=0,k;h<g.length;h++)k=g[h],c[k]&&!d[k]&&(d[k]=1,e.push(k))}return e};let U=1;
P.prototype.search=function(a,b,c){c||(!b&&C(a)?(c=a,a=""):C(b)&&(c=b,b=0));let d=[],e;let f,g=0,h,k,l;if(c){a=c.query||a;b=c.limit||b;g=c.offset||0;var m=c.context;f=c.suggest;(h=U&&!1!==c.resolve)||(U=0);k=h&&c.enrich;l=this.db&&c.tag}else h=this.resolve||U;a=this.encoder.encode(a);e=a.length;b||!h||(b=100);if(1===e)return Da.call(this,a[0],"",b,g,h,k,l);m=this.depth&&!1!==m;if(2===e&&m&&!f)return Da.call(this,a[0],a[1],b,g,h,k,l);let n=c=0;if(1<e){const p=z(),r=[];for(let x=0,A;x<e;x++)if((A=a[x])&&
!p[A]){if(f||this.db||V(this,A))r.push(A),p[A]=1;else return h?d:new T(d);const w=A.length;c=Math.max(c,w);n=n?Math.min(n,w):w}a=r;e=a.length}if(!e)return h?d:new T(d);let q=0,t;if(1===e)return Da.call(this,a[0],"",b,g,h,k,l);if(2===e&&m&&!f)return Da.call(this,a[0],a[1],b,g,h,k,l);1<e&&(m?(t=a[0],q=1):9<c&&3<c/n&&a.sort(aa));if(this.db){if(this.db.search&&(m=this.db.search(this,a,b,g,f,h,k,l),!1!==m))return m;const p=this;return async function(){for(let r,x;q<e;q++){x=a[q];t?(r=await V(p,x,t),r=
Ea(r,d,f,p.da,b,g,2===e),f&&!1===r&&d.length||(t=x)):(r=await V(p,x),r=Ea(r,d,f,p.resolution,b,g,1===e));if(r)return r;if(f&&q===e-1){let A=d.length;if(!A){if(t){t="";q=-1;continue}return d}if(1===A)return h?S(d[0],b,g):new T(d[0])}}return h?Ba(d,b,g,f):new T(d[0])}()}for(let p,r;q<e;q++){r=a[q];t?(p=V(this,r,t),p=Ea(p,d,f,this.da,b,g,2===e),f&&!1===p&&d.length||(t=r)):(p=V(this,r),p=Ea(p,d,f,this.resolution,b,g,1===e));if(p)return p;if(f&&q===e-1){m=d.length;if(!m){if(t){t="";q=-1;continue}return d}if(1===
m)return h?S(d[0],b,g):new T(d[0])}}return h?Ba(d,b,g,f):new T(d[0])};function Da(a,b,c,d,e,f,g){a=V(this,a,b,c,d,e,f,g);return this.db?a.then(function(h){return e?h:h&&h.length?e?S(h,c,d):new T(h):e?[]:new T([])}):a&&a.length?e?S(a,c,d):new T(a):e?[]:new T([])}
function Ea(a,b,c,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,l=0,m;k<d;k++)if(m=a[k])if(f&&m&&g&&(m.length<=f?(f-=m.length,m=null):(m=m.slice(f),f=0)),m&&(h[k]=m,g&&(l+=m.length,l>=e)))break;if(h.length){if(g)return S(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.I.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};P.prototype.remove=function(a,b){const c=this.A.size&&(this.fastupdate?this.A.get(a):this.A.has(a));if(c){if(this.fastupdate)for(let d=0,e;d<c.length;d++){if(e=c[d])if(2>e.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else Fa(this.map,a),this.depth&&Fa(this.I,a);b||this.A.delete(a)}this.db&&(this.R.push({del:a}),this.fa&&va(this));this.cache&&this.cache.remove(a);return this};
function Fa(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;d<a.length;d++){if((e=a[d])&&e.length)if(f=e.indexOf(b),0<=f){1<e.length?(e.splice(f,1),c++):delete a[d];break}else c++}else for(let d of a){const e=d[0],f=Fa(d[1],b);f?c+=f:a.delete(e)}return c};function P(a,b){if(!(this instanceof P))return new P(a);if(a){var c=B(a)?a:a.preset;c&&(a=Object.assign({},ta[c],a))}else a={};c=a.context||{};const d=a.encode||a.encoder||sa;this.encoder=d.encode?d:"object"===typeof d?new E(d):{encode:d};let e;this.resolution=a.resolution||9;this.tokenize=e=a.tokenize||"strict";this.depth="strict"===e&&c.depth||0;this.bidirectional=!1!==c.bidirectional;this.fastupdate=!!a.fastupdate;this.score=a.score||null;(e=a.keystore||0)&&(this.keystore=e);this.map=e?new K(e):
new Map;this.I=e?new K(e):new Map;this.A=b||(this.fastupdate?e?new K(e):new Map:e?new L(e):new Set);this.da=c.resolution||1;this.rtl=d.rtl||a.rtl||!1;this.cache=(e=a.cache||null)&&new F(e);this.resolve=!1!==a.resolve;if(e=a.db)this.db=e.mount(this);this.fa=!1!==a.commit;this.R=[];this.h=null}u=P.prototype;u.mount=function(a){this.h&&(clearTimeout(this.h),this.h=null);return a.mount(this)};u.commit=function(a,b){this.h&&(clearTimeout(this.h),this.h=null);return this.db.commit(this,a,b)};
function va(a){a.h||(a.h=setTimeout(function(){a.h=null;a.db.commit(a,void 0,void 0)},0))}u.clear=function(){this.map.clear();this.I.clear();this.A.clear();this.cache&&this.cache.clear();this.db&&(this.h&&clearTimeout(this.h),this.h=null,this.R=[{clear:!0}]);return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.db?this.db.has(a):this.A.has(a)};
u.update=function(a,b){if(this.async){const c=this,d=this.remove(a);return d.then?d.then(()=>c.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)};function Ga(a){let b=0;if(a.constructor===Array)for(let c=0,d;c<a.length;c++)(d=a[c])&&(b+=d.length);else for(const c of a){const d=c[0],e=Ga(c[1]);e?b+=e:a.delete(d)}return b}u.cleanup=function(){if(!this.fastupdate)return this;Ga(this.map);this.depth&&Ga(this.I);return this};u.searchCache=ma;
u.export=function(a,b,c,d,e,f){let g=!0;"undefined"===typeof f&&(g=new Promise(l=>{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=z();for(let l of this.A.keys())k[l]=1}else k=this.A;break;case 1:h="cfg";k={doc:0,opt:this.B?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.I;break;default:"undefined"===typeof c&&f&&f();return}qa(a,b||this,c,h,d,e,k,f);return g};
u.import=function(a,b){if(b)switch(B(b)&&(b=JSON.parse(b)),a){case "cfg":this.B=!!b.opt;break;case "reg":this.fastupdate=!1;this.A=b;break;case "map":this.map=b;break;case "ctx":this.I=b}};ua(P.prototype);async function Ha(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};(b=d.config)&&(d=await import(b));(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new P(d);postMessage({id:a.id});break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let Ia=0;
function W(a){function b(f){f=f.data||f;const g=f.id,h=g&&e.h[g];h&&(h(f.msg),delete e.h[g])}if(!(this instanceof W))return new W(a);a||(a={});let c=(self||window)._factory;c&&(c=c.toString());const d="undefined"===typeof window&&self.exports,e=this;this.worker=Ja(c,d,a.worker);this.h=z();if(this.worker){d?this.worker.on("message",b):this.worker.onmessage=b;if(a.config)return new Promise(function(f){e.h[++Ia]=function(){f(e)};e.worker.postMessage({id:Ia,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",
factory:c,options:a})}}X("add");X("append");X("search");X("update");X("remove");function X(a){W.prototype[a]=W.prototype[a+"Async"]=function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;"function"===typeof d&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){b.h[++Ia]=f;b.worker.postMessage({task:a,id:Ia,args:c})});return e?(d.then(e),this):d}}
function Ja(a,b,c){return b?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ha.toString()],{type:"text/javascript"}))):new window.Worker(B(c)?c:"worker/worker.js",{type:"module"})};Y.prototype.add=function(a,b,c){C(a)&&(b=a,a=ca(b,this.key));if(b&&(a||0===a)){if(!c&&this.A.has(a))return this.update(a,b);for(let h=0,k;h<this.field.length;h++){k=this.M[h];var d=this.index.get(this.field[h]);if("function"===typeof k){var e=k(b);e&&d.add(a,e,!1,!0)}else if(e=k.T,!e||e(b))k instanceof String?k=[""+k]:B(k)&&(k=[k]),Ka(b,k,this.W,0,d,a,k[0],c)}if(this.tag)for(d=0;d<this.L.length;d++){var f=this.L[d];e=this.tag.get(this.aa[d]);let h=z();if("function"===typeof f){if(f=f(b),!f)continue}else{var g=
f.T;if(g&&!g(b))continue;f instanceof String&&(f=""+f);f=ca(b,f)}if(e&&f){B(f)&&(f=[f]);for(let k=0,l,m;k<f.length;k++)if(l=f[k],!h[l]&&(h[l]=1,(g=e.get(l))?m=g:e.set(l,m=[]),!c||!m.includes(a))){if(m.length===2**31-1){g=new H(m);if(this.fastupdate)for(let n of this.A.values())n.includes(m)&&(n[n.indexOf(m)]=g);e.set(l,m=g)}m.push(a);this.fastupdate&&((g=this.A.get(a))?g.push(m):this.A.set(a,[m]))}}}if(this.store&&(!c||!this.store.has(a))){let h;if(this.H){h=z();for(let k=0,l;k<this.H.length;k++){l=
this.H[k];if((c=l.T)&&!c(b))continue;let m;if("function"===typeof l){m=l(b);if(!m)continue;l=[l.ia]}else if(B(l)||l instanceof String){h[l]=b[l];continue}La(b,h,l,0,l[0],m)}}this.store.set(a,h||b)}}return this};function La(a,b,c,d,e,f){a=a[e];if(d===c.length-1)b[e]=f||a;else if(a)if(a.constructor===Array)for(b=b[e]=Array(a.length),e=0;e<a.length;e++)La(a,b,c,d,e);else b=b[e]||(b[e]=z()),e=c[++d],La(a,b,c,d,e)}
function Ka(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(f,a[b],!0,!0);return}a=a.join(" ")}e.add(f,a,h,!0)}else if(a.constructor===Array)for(g=0;g<a.length;g++)Ka(a,b,c,d,e,f,g,h);else g=b[++d],Ka(a,b,c,d,e,f,g,h);else e.db&&e.remove(f)};Y.prototype.search=function(a,b,c,d){c||(!b&&C(a)?(c=a,a=""):C(b)&&(c=b,b=0));let e=[],f=[],g;let h;let k;let l,m=0;if(c)if(c.constructor===Array)k=c,c=null;else{a=c.query||a;g=c.pluck;h=c.merge;k=g||c.field||c.index;var n=this.tag&&c.tag;var q=this.store&&c.enrich;var t=c.suggest;b=c.limit||b;l=c.offset||0;b||(b=100);if(n&&(!this.db||!d)){n.constructor!==Array&&(n=[n]);var p=[];for(let w=0,v;w<n.length;w++)if(v=n[w],v.field&&v.tag){var r=v.tag;if(r.constructor===Array)for(var x=0;x<r.length;x++)p.push(v.field,
r[x]);else p.push(v.field,r)}else{r=Object.keys(v);for(let I=0,J,D;I<r.length;I++)if(J=r[I],D=v[J],D.constructor===Array)for(x=0;x<D.length;x++)p.push(J,D[x]);else p.push(J,D)}n=p;if(!a){t=[];if(p.length)for(n=0;n<p.length;n+=2){if(this.db){d=this.index.get(p[n]);if(!d)continue;t.push(d=d.db.tag(p[n+1],b,l,q))}else d=Ma.call(this,p[n],p[n+1],b,l,q);e.push({field:p[n],tag:p[n+1],result:d})}return t.length?Promise.all(t).then(function(w){for(let v=0;v<w.length;v++)e[v].result=w[v];return e}):e}}B(k)&&
(k=[k])}k||(k=this.field);p=!d&&(this.worker||this.async)&&[];let A;for(let w=0,v,I,J;w<k.length;w++){I=k[w];if(this.db&&this.tag&&!this.M[w])continue;let D;B(I)||(D=I,I=D.field,a=D.query||a,b=D.limit||b,t=D.suggest||t);if(d)v=d[w];else if(r=D||c,x=this.index.get(I),n&&(this.db&&(r.tag=n,A=x.db.la,r.field=k),A||(r.enrich=!1)),p){p[w]=x.searchAsync(a,b,r);r&&q&&(r.enrich=q);continue}else v=x.search(a,b,r),r&&q&&(r.enrich=q);J=v&&v.length;if(n&&J){r=[];x=0;if(this.db&&d){if(!A)for(let N=k.length;N<
d.length;N++){let G=d[N];if(G&&G.length)x++,r.push(G);else if(!t)return e}}else for(let N=0,G,$a;N<n.length;N+=2){G=this.tag.get(n[N]);if(!G)if(t)continue;else return e;if($a=(G=G&&G.get(n[N+1]))&&G.length)x++,r.push(G);else if(!t)return e}if(x){v=Ca(v,r);J=v.length;if(!J&&!t)return e;x--}}if(J)f[m]=I,e.push(v),m++;else if(1===k.length)return e}if(p){if(this.db&&n&&n.length&&!A)for(q=0;q<n.length;q+=2){d=this.index.get(n[q]);if(!d)if(t)continue;else return e;p.push(d.db.tag(n[q+1],b,l,!1))}const w=
this;return Promise.all(p).then(function(v){return v.length?w.search(a,b,c,v):v})}if(!m)return e;if(g&&(!q||!this.store))return e[0];p=[];for(let w=0,v;w<f.length;w++){v=e[w];q&&v.length&&!v[0].doc&&(this.db?p.push(v=this.index.get(this.field[0]).db.enrich(v)):v.length&&(v=Na.call(this,v)));if(g)return v;e[w]={field:f[w],result:v}}return q&&this.db&&p.length?Promise.all(p).then(function(w){for(let v=0;v<w.length;v++)e[v].result=w[v];return h?Oa(e,b):e}):h?Oa(e,b):e};
function Oa(a,b){const c=[],d=z();for(let e=0,f,g;e<a.length;e++){f=a[e];g=f.result;for(let h=0,k,l,m;h<g.length;h++)if(l=g[h],k=l.id,m=d[k])m.push(f.field);else{if(c.length===b)return c;l.field=d[k]=[f.field];c.push(l)}}return c}function Ma(a,b,c,d,e){a=this.tag.get(a);if(!a)return[];if((b=(a=a&&a.get(b))&&a.length-d)&&0<b){if(b>c||d)a=a.slice(d,d+c);e&&(a=Na.call(this,a));return a}}
function Na(a){const b=Array(a.length);for(let c=0,d;c<a.length;c++)d=a[c],b[c]={id:d,doc:this.store.get(d)};return b};function Y(a){if(!(this instanceof Y))return new Y(a);const b=a.document||a.doc||a;var c,d;this.M=[];this.field=[];this.W=[];this.key=(c=b.key||b.id)&&Pa(c,this.W)||"id";(d=a.keystore||0)&&(this.keystore=d);this.A=(this.fastupdate=!!a.fastupdate)?d?new K(d):new Map:d?new L(d):new Set;this.H=(c=b.store||null)&&!0!==c&&[];this.store=c&&(d?new K(d):new Map);this.cache=(c=a.cache||null)&&new F(c);a.cache=!1;this.worker=a.worker;this.async=!1;c=new Map;d=b.index||b.field||b;B(d)&&(d=[d]);for(let e=0,f,
g;e<d.length;e++){f=d[e];B(f)||(g=f,f=f.field);g=C(g)?Object.assign({},a,g):a;if(this.worker){const h=new W(g);c.set(f,h);h.worker||(this.worker=!1)}this.worker||c.set(f,new P(g,this.A));g.S?this.M[e]=g.S:(this.M[e]=Pa(f,this.W),g.filter&&("string"===typeof this.M[e]&&(this.M[e]=new String(this.M[e])),this.M[e].T=g.filter));this.field[e]=f}if(this.H){d=b.store;B(d)&&(d=[d]);for(let e=0,f,g;e<d.length;e++)f=d[e],g=f.field||f,f.S?(this.H[e]=f.S,f.S.ia=g):(this.H[e]=Pa(g,this.W),f.filter&&("string"===
typeof this.H[e]&&(this.H[e]=new String(this.H[e])),this.H[e].T=f.filter))}this.index=c;this.tag=null;if(c=b.tag)if("string"===typeof c&&(c=[c]),c.length){this.tag=new Map;this.L=[];this.aa=[];for(let e=0,f,g;e<c.length;e++){f=c[e];g=f.field||f;if(!g)throw Error("The tag field from the document descriptor is undefined.");f.S?this.L[e]=f.S:(this.L[e]=Pa(g,this.W),f.filter&&("string"===typeof this.L[e]&&(this.L[e]=new String(this.L[e])),this.L[e].T=f.filter));this.aa[e]=g;this.tag.set(g,new Map)}}a.db&&
this.mount(a.db)}u=Y.prototype;
u.mount=function(a){let b=this.field;if(this.tag)for(let e=0,f;e<this.aa.length;e++){f=this.aa[e];var c=this.index.get(f);c||(this.index.set(f,c=new P({},this.A)),b===this.field&&(b=b.slice(0)),b.push(f));c.tag=this.tag.get(f)}c=[];const d={db:a.db,type:a.type,fastupdate:a.fastupdate};for(let e=0,f,g;e<b.length;e++){d.field=g=b[e];f=this.index.get(g);const h=new a.constructor(a.id,d);h.id=a.id;c[e]=h.mount(f);f.document=!0;e?f.ja=!0:f.store=this.store}this.db=this.async=!0;return Promise.all(c)};
u.commit=async function(a,b){const c=[];for(const d of this.index.values())c.push(d.db.commit(d,a,b));await Promise.all(c);this.A.clear()};function Pa(a,b){const c=a.split(":");let d=0;for(let e=0;e<c.length;e++)a=c[e],"]"===a[a.length-1]&&(a=a.substring(0,a.length-2))&&(b[d]=!0),a&&(c[d++]=a);d<c.length&&(c.length=d);return 1<d?c:c[0]}u.append=function(a,b){return this.add(a,b,!0)};u.update=function(a,b){return this.remove(a).add(a,b)};
u.remove=function(a){C(a)&&(a=ca(a,this.key));for(var b of this.index.values())b.remove(a,!0);if(this.A.has(a)){if(this.tag&&!this.fastupdate)for(let c of this.tag.values())for(let d of c){b=d[0];const e=d[1],f=e.indexOf(a);-1<f&&(1<e.length?e.splice(f,1):c.delete(b))}this.store&&this.store.delete(a);this.A.delete(a)}this.cache&&this.cache.remove(a);return this};
u.clear=function(){for(const a of this.index.values())a.clear();if(this.tag)for(const a of this.tag.values())a.clear();this.store&&this.store.clear();return this};u.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.A.has(a)};u.cleanup=function(){for(const a of this.index.values())a.cleanup();return this};u.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(b){return b[0]&&b[0].doc}):this.store.get(a)};
u.set=function(a,b){this.store.set(a,b);return this};u.searchCache=ma;u.export=function(a,b,c,d,e,f){let g;"undefined"===typeof f&&(g=new Promise(k=>{f=k}));e||(e=0);d||(d=0);if(d<this.field.length){c=this.field[d];var h=this.index[c];b=this;h.export(a,b,e?c:"",d,e++,f)||(d++,b.export(a,b,c,d,1,f))}else{switch(e){case 1:b="tag";h=this.h;c=null;break;case 2:b="store";h=this.store;c=null;break;default:f();return}qa(a,this,c,b,d,e,h,f)}return g};
u.import=function(a,b){if(b)switch(B(b)&&(b=JSON.parse(b)),a){case "tag":this.h=b;break;case "reg":this.fastupdate=!1;this.A=b;for(let d=0,e;d<this.field.length;d++)e=this.index[this.field[d]],e.A=b,e.fastupdate=!1;break;case "store":this.store=b;break;default:a=a.split(".");const c=a[0];a=a[1];c&&a&&this.index[c].import(a,b)}};ua(Y.prototype);const Qa="undefined"!==typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Ra=["map","ctx","tag","reg","cfg"];
function Sa(a,b={}){if(!(this instanceof Sa))return new Sa(a,b);"object"===typeof a&&(b=a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=b.field?b.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.la=!1;this.db=null;this.h={}}u=Sa.prototype;u.mount=function(a){if(a instanceof Y)return a.mount(this);a.db=this;return Ta(this)};
function Ta(a){navigator.storage&&navigator.storage.persist();return a.db||new Promise(function(b,c){const d=Qa.open(a.id+(a.field?":"+a.field:""),1);d.onupgradeneeded=function(){const e=a.db=this.result;Ra.forEach(f=>{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}
u.close=function(){this.db.close();this.db=null};u.clear=function(){const a=this.db.transaction(Ra,"readwrite");for(let b=0;b<Ra.length;b++)a.objectStore(Ra[b]).clear();return Z(a)};
u.get=function(a,b,c=0,d=0,e=!0,f=!1){a=this.db.transaction(b?"ctx":"map","readonly").objectStore(b?"ctx":"map").get(b?b+":"+a:a);const g=this;return Z(a).then(function(h){let k=[];if(!h||!h.length)return k;if(e){if(!c&&!d&&1===h.length)return h[0];for(let l=0,m;l<h.length;l++)if((m=h[l])&&m.length){if(d>=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let q=d;q<n;q++)k.push(m[q]);d=0;if(k.length===c)break}return f?g.enrich(k):k}return h})};
u.tag=function(a,b=0,c=0,d=!1){a=this.db.transaction("tag","readonly").objectStore("tag").get(a);const e=this;return Z(a).then(function(f){if(!f||!f.length||c>=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})};
u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d<a.length;d++)c[d]=Z(b.get(a[d]));return Promise.all(c).then(function(d){for(let e=0;e<d.length;e++)d[e]={id:a[e],doc:d[e]?JSON.parse(d[e]):null};return d})};u.has=function(a){a=this.db.transaction("reg","readonly").objectStore("reg").getKey(a);return Z(a)};u.search=null;u.info=function(){};
u.transaction=function(a,b,c){let d=this.h[a+":"+b];if(d)return c.call(this,d);let e=this.db.transaction(a,b);this.h[a+":"+b]=d=e.objectStore(a);return new Promise((f,g)=>{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})};
u.commit=async function(a,b,c){if(b)await this.clear(),a.R=[];else{let d=a.R;a.R=[];for(let e=0,f;e<d.length;e++)if(f=d[e],f.clear){await this.clear();b=!0;break}else d[e]=f.ma;b||(c||(d=d.concat(ba(a.A))),d.length&&await this.remove(d))}a.A.size&&(await this.transaction("map","readwrite",function(d){for(const e of a.map){const f=e[0],g=e[1];g.length&&(b?d.put(g,f):d.get(f).onsuccess=function(){let h=this.result;var k;if(h&&h.length){const l=Math.max(h.length,g.length);for(let m=0,n,q;m<l;m++)if((q=
g[m])&&q.length){if((n=h[m])&&n.length)for(k=0;k<q.length;k++)n.push(q[k]);else h[m]=q;k=1}}else h=g,k=1;k&&d.put(h,f)})}}),await this.transaction("ctx","readwrite",function(d){for(const e of a.I){const f=e[0],g=e[1];for(const h of g){const k=h[0],l=h[1];l.length&&(b?d.put(l,f+":"+k):d.get(f+":"+k).onsuccess=function(){let m=this.result;var n;if(m&&m.length){const q=Math.max(m.length,l.length);for(let t=0,p,r;t<q;t++)if((r=l[t])&&r.length){if((p=m[t])&&p.length)for(n=0;n<r.length;n++)p.push(r[n]);
else m[t]=r;n=1}}else m=l,n=1;n&&d.put(m,f+":"+k)})}}}),a.store?await this.transaction("reg","readwrite",function(d){for(const e of a.store){const f=e[0],g=e[1];d.put("object"===typeof g?JSON.stringify(g):1,f)}}):a.ja||await this.transaction("reg","readwrite",function(d){for(const e of a.A.keys())d.put(1,e)}),a.tag&&await this.transaction("tag","readwrite",function(d){for(const e of a.tag){const f=e[0],g=e[1];g.length&&(d.get(f).onsuccess=function(){let h=this.result;h=h&&h.length?h.concat(g):g;d.put(h,
f)})}}),a.map.clear(),a.I.clear(),a.tag&&a.tag.clear(),a.store&&a.store.clear(),a.document||a.A.clear())};function Ua(a,b,c){const d=a.value;let e,f,g=0;for(let h=0,k;h<d.length;h++){if(k=c?d:d[h]){for(let l=0,m,n;l<b.length;l++)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{d[h]=[];break}g+=k.length}if(c)break}g?e&&a.update(d):a.delete();a.continue()}
u.remove=function(a){"object"!==typeof a&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Ua(c,a)}}),this.transaction("ctx","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Ua(c,a)}}),this.transaction("tag","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Ua(c,a,!0)}}),this.transaction("reg","readwrite",function(b){for(let c=0;c<a.length;c++)b.delete(a[c])})])};
function Z(a){return new Promise((b,c)=>{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const Va=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Wa={normalize:!0,C:!0,D:Va};const Xa=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Ya=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var Za={normalize:!0,C:!0,D:Va,K:Ya,J:Xa};var ab={normalize:!0,C:!0,D:Va,K:Ya.concat([/(?!^)[aeoy]/g,""]),J:Xa};const bb={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};M["latin:exact"]={normalize:!1,C:!1};M["latin:default"]=sa;M["latin:simple"]={normalize:!0,C:!0};M["latin:balance"]=Wa;M["latin:advanced"]=Za;M["latin:extra"]=ab;M["latin:soundex"]={normalize:!0,C:!1,ga:{ka:!0},V:function(a){for(let c=0;c<a.length;c++){var b=a[c];let d=b.charAt(0),e=bb[d];for(let f=1,g;f<b.length&&(g=b.charAt(f),"h"===g||"w"===g||!(g=bb[g])||g===e||(d+=g,e=g,4!==d.length));f++);a[c]=d}}};
const cb={Index:P,Encoder:E,Charset:M,Language:ra,Document:Y,Worker:W,Resolver:T,IndexedDB:Sa},db=self;let eb;(eb=db.define)&&eb.amd?eb([],function(){return cb}):"object"===typeof db.exports?db.exports=cb:db.FlexSearch=cb;}(this));

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +1,89 @@
/**! /**!
* FlexSearch.js v0.7.41 (Bundle.module) * FlexSearch.js v0.8.0 (Bundle/Module)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
var t;function u(a){return"undefined"!==typeof a?a:!0}function v(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=x();return b}function x(){return Object.create(null)}function aa(a,b){return b.length-a.length}function C(a){return"string"===typeof a}function D(a){return"object"===typeof a}function E(a){return"function"===typeof a};function F(a,b){var c=ba;if(a&&(b&&(a=G(a,b)),this.H&&(a=G(a,this.H)),this.J&&1<a.length&&(a=G(a,this.J)),c||""===c)){b=a.split(c);if(this.filter){a=this.filter;c=b.length;const d=[];for(let e=0,f=0;e<c;e++){const h=b[e];h&&!a[h]&&(d[f++]=h)}a=d}else a=b;return a}return a}const ba=/[\p{Z}\p{S}\p{P}\p{C}]+/u,ca=/[\u0300-\u036f]/g; var u;function y(a,b,c){const d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===e?b:a}function z(){return Object.create(null)}function aa(a,b){return b.length-a.length}
function I(a,b){const c=Object.keys(a),d=c.length,e=[];let f="",h=0;for(let g=0,k,m;g<d;g++)k=c[g],(m=a[k])?(e[h++]=J(b?"(?!\\b)"+k+"(\\b|_)":k),e[h++]=m):f+=(f?"|":"")+k;f&&(e[h++]=J(b?"(?!\\b)("+f+")(\\b|_)":"("+f+")"),e[h]="");return e}function G(a,b){for(let c=0,d=b.length;c<d&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a}function J(a){return new RegExp(a,"g")}function da(a){let b="",c="";for(let d=0,e=a.length,f;d<e;d++)(f=a[d])!==c&&(b+=c=f);return b};var fa={encode:ea,F:!1,G:""};function ea(a){return F.call(this,(""+a).toLowerCase(),!1)};const ha={},K={};function ia(a){L(a,"add");L(a,"append");L(a,"search");L(a,"update");L(a,"remove")}function L(a,b){a[b+"Async"]=function(){const c=this,d=arguments;var e=d[d.length-1];let f;E(e)&&(f=e,delete d[d.length-1]);e=new Promise(function(h){setTimeout(function(){c.async=!0;const g=c[b].apply(c,d);c.async=!1;h(g)})});return f?(e.then(f),this):e}};function ja(a,b,c,d){const e=a.length;let f=[],h,g,k=0;d&&(d=[]);for(let m=e-1;0<=m;m--){const n=a[m],w=n.length,q=x();let r=!h;for(let l=0;l<w;l++){const p=n[l],A=p.length;if(A)for(let B=0,z,y;B<A;B++)if(y=p[B],h){if(h[y]){if(!m)if(c)c--;else if(f[k++]=y,k===b)return f;if(m||d)q[y]=1;r=!0}if(d&&(z=(g[y]||0)+1,g[y]=z,z<e)){const H=d[z-2]||(d[z-2]=[]);H[H.length]=y}}else q[y]=1}if(d)h||(g=q);else if(!r)return[];h=q}if(d)for(let m=d.length-1,n,w;0<=m;m--){n=d[m];w=n.length;for(let q=0,r;q<w;q++)if(r= function B(a){return"string"===typeof a}function C(a){return"object"===typeof a}function ba(a){const b=[];for(const c of a.keys())b.push(c);return b}function ca(a,b){if(B(b))a=a[b];else for(let c=0;a&&c<b.length;c++)a=a[b[c]];return a}function da(a){let b=0;for(let c=0,d;c<a.length;c++)(d=a[c])&&b<d.length&&(b=d.length);return b};const ea=/[^\p{L}\p{N}]+/u,fa=/(\d{3})/g,ha=/(\D)(\d{3})/g,ia=/(\d{3})(\D)/g,ja="".normalize&&/[\u0300-\u036f]/g,ka=!ja&&new Map([["\u00aa","a"],["\u00b2","2"],["\u00b3","3"],["\u00b9","1"],["\u00ba","o"],["\u00bc","1\u20444"],["\u00bd","1\u20442"],["\u00be","3\u20444"],["\u00e0","a"],["\u00e1","a"],["\u00e2","a"],["\u00e3","a"],["\u00e4","a"],["\u00e5","a"],["\u00e7","c"],["\u00e8","e"],["\u00e9","e"],["\u00ea","e"],["\u00eb","e"],["\u00ec","i"],["\u00ed","i"],["\u00ee","i"],["\u00ef","i"],["\u00f1",
n[q],!h[r]){if(c)c--;else if(f[k++]=r,k===b)return f;h[r]=1}}return f}function ka(a,b){const c=x(),d=x(),e=[];for(let f=0;f<a.length;f++)c[a[f]]=1;for(let f=0,h;f<b.length;f++){h=b[f];for(let g=0,k;g<h.length;g++)k=h[g],c[k]&&!d[k]&&(d[k]=1,e[e.length]=k)}return e};function M(a){this.l=!0!==a&&a;this.cache=x();this.h=[]}function la(a,b,c){D(a)&&(a=a.query);let d=this.cache.get(a);d||(d=this.search(a,b,c),this.cache.set(a,d));return d}M.prototype.set=function(a,b){if(!this.cache[a]){var c=this.h.length;c===this.l?delete this.cache[this.h[c-1]]:c++;for(--c;0<c;c--)this.h[c]=this.h[c-1];this.h[0]=a}this.cache[a]=b};M.prototype.get=function(a){const b=this.cache[a];if(this.l&&b&&(a=this.h.indexOf(a))){const c=this.h[a-1];this.h[a-1]=this.h[a];this.h[a]=c}return b};const na={memory:{charset:"latin:extra",D:3,B:4,m:!1},performance:{D:3,B:3,s:!1,context:{depth:2,D:1}},match:{charset:"latin:extra",G:"reverse"},score:{charset:"latin:advanced",D:20,B:3,context:{depth:3,D:9}},"default":{}};function oa(a,b,c,d,e,f,h,g){setTimeout(function(){const k=a(c?c+"."+d:d,JSON.stringify(h));k&&k.then?k.then(function(){b.export(a,b,c,e,f+1,g)}):b.export(a,b,c,e,f+1,g)})};function N(a,b){if(!(this instanceof N))return new N(a);var c;if(a){C(a)?a=na[a]:(c=a.preset)&&(a=Object.assign({},c[c],a));c=a.charset;var d=a.lang;C(c)&&(-1===c.indexOf(":")&&(c+=":default"),c=K[c]);C(d)&&(d=ha[d])}else a={};let e,f,h=a.context||{};this.encode=a.encode||c&&c.encode||ea;this.register=b||x();this.D=e=a.resolution||9;this.G=b=c&&c.G||a.tokenize||"strict";this.depth="strict"===b&&h.depth;this.l=u(h.bidirectional);this.s=f=u(a.optimize);this.m=u(a.fastupdate);this.B=a.minlength||1;this.C= "n"],["\u00f2","o"],["\u00f3","o"],["\u00f4","o"],["\u00f5","o"],["\u00f6","o"],["\u00f9","u"],["\u00fa","u"],["\u00fb","u"],["\u00fc","u"],["\u00fd","y"],["\u00ff","y"],["\u0101","a"],["\u0103","a"],["\u0105","a"],["\u0107","c"],["\u0109","c"],["\u010b","c"],["\u010d","c"],["\u010f","d"],["\u0113","e"],["\u0115","e"],["\u0117","e"],["\u0119","e"],["\u011b","e"],["\u011d","g"],["\u011f","g"],["\u0121","g"],["\u0123","g"],["\u0125","h"],["\u0129","i"],["\u012b","i"],["\u012d","i"],["\u012f","i"],["\u0133",
a.boost;this.map=f?v(e):x();this.A=e=h.resolution||1;this.h=f?v(e):x();this.F=c&&c.F||a.rtl;this.H=(b=a.matcher||d&&d.H)&&I(b,!1);this.J=(b=a.stemmer||d&&d.J)&&I(b,!0);if(c=b=a.filter||d&&d.filter){c=b;d=x();for(let g=0,k=c.length;g<k;g++)d[c[g]]=1;c=d}this.filter=c;this.cache=(b=a.cache)&&new M(b)}t=N.prototype;t.append=function(a,b){return this.add(a,b,!0)}; "ij"],["\u0135","j"],["\u0137","k"],["\u013a","l"],["\u013c","l"],["\u013e","l"],["\u0140","l"],["\u0144","n"],["\u0146","n"],["\u0148","n"],["\u0149","n"],["\u014d","o"],["\u014f","o"],["\u0151","o"],["\u0155","r"],["\u0157","r"],["\u0159","r"],["\u015b","s"],["\u015d","s"],["\u015f","s"],["\u0161","s"],["\u0163","t"],["\u0165","t"],["\u0169","u"],["\u016b","u"],["\u016d","u"],["\u016f","u"],["\u0171","u"],["\u0173","u"],["\u0175","w"],["\u0177","y"],["\u017a","z"],["\u017c","z"],["\u017e","z"],
t.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.register[a])return this.update(a,b);b=this.encode(b);if(d=b.length){const m=x(),n=x(),w=this.depth,q=this.D;for(let r=0;r<d;r++){let l=b[this.F?d-1-r:r];var e=l.length;if(l&&e>=this.B&&(w||!n[l])){var f=O(q,d,r),h="";switch(this.G){case "full":if(2<e){for(f=0;f<e;f++)for(var g=e;g>f;g--)if(g-f>=this.B){var k=O(q,d,r,e,f);h=l.substring(f,g);P(this,n,h,k,a,c)}break}case "reverse":if(1<e){for(g=e-1;0<g;g--)h=l[g]+h,h.length>=this.B&&P(this,n, ["\u017f","s"],["\u01a1","o"],["\u01b0","u"],["\u01c6","dz"],["\u01c9","lj"],["\u01cc","nj"],["\u01ce","a"],["\u01d0","i"],["\u01d2","o"],["\u01d4","u"],["\u01d6","u"],["\u01d8","u"],["\u01da","u"],["\u01dc","u"],["\u01df","a"],["\u01e1","a"],["\u01e3","ae"],["\u00e6","ae"],["\u01fd","ae"],["\u01e7","g"],["\u01e9","k"],["\u01eb","o"],["\u01ed","o"],["\u01ef","\u0292"],["\u01f0","j"],["\u01f3","dz"],["\u01f5","g"],["\u01f9","n"],["\u01fb","a"],["\u01ff","\u00f8"],["\u0201","a"],["\u0203","a"],["\u0205",
h,O(q,d,r,e,g),a,c);h=""}case "forward":if(1<e){for(g=0;g<e;g++)h+=l[g],h.length>=this.B&&P(this,n,h,f,a,c);break}default:if(this.C&&(f=Math.min(f/this.C(b,l,r)|0,q-1)),P(this,n,l,f,a,c),w&&1<d&&r<d-1)for(e=x(),h=this.A,f=l,g=Math.min(w+1,d-r),e[f]=1,k=1;k<g;k++)if((l=b[this.F?d-1-r-k:r+k])&&l.length>=this.B&&!e[l]){e[l]=1;const p=this.l&&l>f;P(this,m,p?f:l,O(h+(d/2>h?0:1),d,r,g-1,k-1),a,c,p?l:f)}}}}this.m||(this.register[a]=1)}}return this}; "e"],["\u0207","e"],["\u0209","i"],["\u020b","i"],["\u020d","o"],["\u020f","o"],["\u0211","r"],["\u0213","r"],["\u0215","u"],["\u0217","u"],["\u0219","s"],["\u021b","t"],["\u021f","h"],["\u0227","a"],["\u0229","e"],["\u022b","o"],["\u022d","o"],["\u022f","o"],["\u0231","o"],["\u0233","y"],["\u02b0","h"],["\u02b1","h"],["\u0266","h"],["\u02b2","j"],["\u02b3","r"],["\u02b4","\u0279"],["\u02b5","\u027b"],["\u02b6","\u0281"],["\u02b7","w"],["\u02b8","y"],["\u02e0","\u0263"],["\u02e1","l"],["\u02e2","s"],
function O(a,b,c,d,e){return c&&1<a?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0}function P(a,b,c,d,e,f,h){let g=h?a.h:a.map;if(!b[c]||h&&!b[c][h])a.s&&(g=g[d]),h?(b=b[c]||(b[c]=x()),b[h]=1,g=g[h]||(g[h]=x())):b[c]=1,g=g[c]||(g[c]=[]),a.s||(g=g[d]||(g[d]=[])),f&&g.includes(e)||(g[g.length]=e,a.m&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=g))} ["\u02e3","x"],["\u02e4","\u0295"],["\u0390","\u03b9"],["\u03ac","\u03b1"],["\u03ad","\u03b5"],["\u03ae","\u03b7"],["\u03af","\u03b9"],["\u03b0","\u03c5"],["\u03ca","\u03b9"],["\u03cb","\u03c5"],["\u03cc","\u03bf"],["\u03cd","\u03c5"],["\u03ce","\u03c9"],["\u03d0","\u03b2"],["\u03d1","\u03b8"],["\u03d2","\u03a5"],["\u03d3","\u03a5"],["\u03d4","\u03a5"],["\u03d5","\u03c6"],["\u03d6","\u03c0"],["\u03f0","\u03ba"],["\u03f1","\u03c1"],["\u03f2","\u03c2"],["\u03f5","\u03b5"],["\u0439","\u0438"],["\u0450",
t.search=function(a,b,c){c||(!b&&D(a)?(c=a,a=c.query):D(b)&&(c=b));let d=[],e;let f,h=0;if(c){a=c.query||a;b=c.limit;h=c.offset||0;var g=c.context;f=c.suggest}if(a&&(a=this.encode(""+a),e=a.length,1<e)){c=x();var k=[];for(let n=0,w=0,q;n<e;n++)if((q=a[n])&&q.length>=this.B&&!c[q])if(this.s||f||this.map[q])k[w++]=q,c[q]=1;else return d;a=k;e=a.length}if(!e)return d;b||(b=100);g=this.depth&&1<e&&!1!==g;c=0;let m;g?(m=a[0],c=1):1<e&&a.sort(aa);for(let n,w;c<e;c++){w=a[c];g?(n=pa(this,d,f,b,h,2===e,w, "\u0435"],["\u0451","\u0435"],["\u0453","\u0433"],["\u0457","\u0456"],["\u045c","\u043a"],["\u045d","\u0438"],["\u045e","\u0443"],["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]]);
m),f&&!1===n&&d.length||(m=w)):n=pa(this,d,f,b,h,1===e,w);if(n)return n;if(f&&c===e-1){k=d.length;if(!k){if(g){g=0;c=-1;continue}return d}if(1===k)return qa(d[0],b,h)}}return ja(d,b,h,f)}; function E(a={}){if(!(this instanceof E))return new E(...arguments);for(a=0;a<arguments.length;a++)this.assign(arguments[a])}
function pa(a,b,c,d,e,f,h,g){let k=[],m=g?a.h:a.map;a.s||(m=ra(m,h,g,a.l));if(m){let n=0;const w=Math.min(m.length,g?a.A:a.D);for(let q=0,r=0,l,p;q<w;q++)if(l=m[q])if(a.s&&(l=ra(l,h,g,a.l)),e&&l&&f&&(p=l.length,p<=e?(e-=p,l=null):(l=l.slice(e),e=0)),l&&(k[n++]=l,f&&(r+=l.length,r>=d)))break;if(n){if(f)return qa(k,d,0);b[b.length]=k;return}}return!c&&k}function qa(a,b,c){a=1===a.length?a[0]:[].concat.apply([],a);return c||a.length>b?a.slice(c,c+b):a} E.prototype.assign=function(a){this.normalize=y(a.normalize,!0,this.normalize);let b=a.ga,c=b||a.na||a.split;if("object"===typeof c){let d=!b,e="";a.ga||(e+="\\p{Z}");c.ka&&(e+="\\p{L}");c.oa&&(e+="\\p{N}",d=!!b);c.qa&&(e+="\\p{S}");c.pa&&(e+="\\p{P}");c.control&&(e+="\\p{C}");if(c=c.char)e+="object"===typeof c?c.join(""):c;this.split=new RegExp("["+(b?"^":"")+e+"]+","u");this.numeric=d}else this.split=y(c,ea,this.split),this.numeric=y(this.numeric,!0);this.$=y(a.$,null,this.$);this.V=y(a.V,null,
function ra(a,b,c,d){c?(d=d&&b>c,a=(a=a[d?b:c])&&a[d?c:b]):a=a[b];return a}t.contain=function(a){return!!this.register[a]};t.update=function(a,b){return this.remove(a).add(a,b)}; this.V);this.rtl=a.rtl||!1;this.C=y(a.C,!0,this.C);this.filter=y((c=a.filter)&&new Set(c),null,this.filter);this.J=y((c=a.J)&&new Map(c),null,this.J);this.D=y((c=a.D)&&new Map(c),null,this.D);this.N=y((c=a.N)&&new Map(c),null,this.N);this.K=y(a.K,null,this.K);this.Z=y(a.Z,1,this.Z);this.ha=y(a.ha,0,this.ha);if(this.cache=c=y(a.cache,!0,this.cache))this.X=null,this.ea="number"===typeof c?c:2E5,this.P=new Map,this.U=new Map,this.B=this.h=128;this.F="";this.ba=null;this.Y="";this.ca=null;if(this.J)for(const d of this.J.keys())this.F+=
t.remove=function(a,b){const c=this.register[a];if(c){if(this.m)for(let d=0,e;d<c.length;d++)e=c[d],e.splice(e.indexOf(a),1);else Q(this.map,a,this.D,this.s),this.depth&&Q(this.h,a,this.A,this.s);b||delete this.register[a];if(this.cache){b=this.cache;for(let d=0,e,f;d<b.h.length;d++)f=b.h[d],e=b.cache[f],e.includes(a)&&(b.h.splice(d--,1),delete b.cache[f])}}return this}; (this.F?"|":"")+d;if(this.N)for(const d of this.N.keys())this.Y+=(this.Y?"|":"")+d;return this};
function Q(a,b,c,d,e){let f=0;if(a.constructor===Array)if(e)b=a.indexOf(b),-1!==b?1<a.length&&(a.splice(b,1),f++):f++;else{e=Math.min(a.length,c);for(let h=0,g;h<e;h++)if(g=a[h])f=Q(g,b,c,d,e),d||f||delete a[h]}else for(let h in a)(f=Q(a[h],b,c,d,e))||delete a[h];return f}t.searchCache=la; E.prototype.encode=function(a){if(this.cache&&a.length<=this.h)if(this.X){if(this.P.has(a))return this.P.get(a)}else this.X=setTimeout(la,0,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):ja?a=a.normalize("NFKD").replace(ja,"").toLowerCase():(a=a.toLowerCase(),this.D=this.D?new Map([...ka,...this.D]):new Map(ka)));this.$&&(a=this.$(a));this.numeric&&3<a.length&&(a=a.replace(ha,"$1 $2").replace(ia,"$1 $2").replace(fa,"$1 "));const b=!(this.C||this.D||this.filter||this.J||
t.export=function(a,b,c,d,e,f){let h=!0;"undefined"===typeof f&&(h=new Promise(m=>{f=m}));let g,k;switch(e||(e=0)){case 0:g="reg";if(this.m){k=x();for(let m in this.register)k[m]=1}else k=this.register;break;case 1:g="cfg";k={doc:0,opt:this.s?1:0};break;case 2:g="map";k=this.map;break;case 3:g="ctx";k=this.h;break;default:"undefined"===typeof c&&f&&f();return}oa(a,b||this,c,g,d,e,k,f);return h}; this.N||this.K);let c=[],d=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;f<d.length;f++){if(!(g=h=d[f]))continue;if(g.length<this.Z)continue;if(b){c.push(g);continue}if(this.filter&&this.filter.has(g))continue;if(this.cache&&g.length<=this.B)if(this.X){var e=this.U.get(g);if(e||""===e){e&&c.push(e);continue}}else this.X=setTimeout(la,0,this);let k;this.N&&2<g.length&&(this.ca||(this.ca=new RegExp("(?!^)("+this.Y+")$")),g=g.replace(this.ca,l=>this.N.get(l)),k=1);this.J&&1<g.length&&
t.import=function(a,b){if(b)switch(C(b)&&(b=JSON.parse(b)),a){case "cfg":this.s=!!b.opt;break;case "reg":this.m=!1;this.register=b;break;case "map":this.map=b;break;case "ctx":this.h=b}};ia(N.prototype);function sa(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};a=a.factory;b=d.encode;d.cache=!1;b&&0===b.indexOf("function")&&(d.encode=Function("return "+b)());a?(Function("return "+a)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new N(d);break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let ta=0;function S(a){if(!(this instanceof S))return new S(a);var b;a?E(b=a.encode)&&(a.encode=b.toString()):a={};(b=(self||window)._factory)&&(b=b.toString());const c="undefined"===typeof window&&self.exports,d=this;this.o=ua(b,c,a.worker);this.h=x();if(this.o){if(c)this.o.on("message",function(e){d.h[e.id](e.msg);delete d.h[e.id]});else this.o.onmessage=function(e){e=e.data;d.h[e.id](e.msg);delete d.h[e.id]};this.o.postMessage({task:"init",factory:b,options:a})}}T("add");T("append");T("search"); (this.ba||(this.ba=new RegExp("("+this.F+")","g")),g=g.replace(this.ba,l=>this.J.get(l)),k=1);g&&k&&(g.length<this.Z||this.filter&&this.filter.has(g))&&(g="");if(g&&(this.D||this.C&&1<g.length)){e="";for(let l=0,m="",n,q;l<g.length;l++)n=g.charAt(l),n===m&&this.C||((q=this.D&&this.D.get(n))||""===q?q===m&&this.C||!(m=q)||(e+=q):e+=m=n);g=e}if(g&&this.K)for(e=0;g&&e<this.K.length;e+=2)g=g.replace(this.K[e],this.K[e+1]);this.cache&&h.length<=this.B&&(this.U.set(h,g),this.U.size>this.ea&&(this.U.clear(),
T("update");T("remove");function T(a){S.prototype[a]=S.prototype[a+"Async"]=function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;E(d)&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){setTimeout(function(){b.h[++ta]=f;b.o.postMessage({task:a,id:ta,args:c})})});return e?(d.then(e),this):d}} this.B=this.B/1.1|0));g&&c.push(g)}this.V&&(c=this.V(c)||c);this.cache&&a.length<=this.h&&(this.P.set(a,c),this.P.size>this.ea&&(this.P.clear(),this.h=this.h/1.1|0));return c};function la(a){a.X=null;a.P.clear();a.U.clear()};function ma(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d instanceof Promise){const e=this;d.then(function(f){e.cache.set(a,f)})}this.cache.set(a,d)}return d}function F(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}F.prototype.set=function(a,b){this.cache.has(a)||(this.cache.set(this.h=a,b),this.limit&&this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value))};
function ua(a,b,c){let d;try{d=b?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):a?new Worker(URL.createObjectURL(new Blob(["onmessage="+sa.toString()],{type:"text/javascript"}))):new Worker(C(c)?c:"worker/worker.js",{type:"module"})}catch(e){}return d};function U(a){if(!(this instanceof U))return new U(a);var b=a.document||a.doc||a,c;this.K=[];this.h=[];this.A=[];this.register=x();this.key=(c=b.key||b.id)&&V(c,this.A)||"id";this.m=u(a.fastupdate);this.C=(c=b.store)&&!0!==c&&[];this.store=c&&x();this.I=(c=b.tag)&&V(c,this.A);this.l=c&&x();this.cache=(c=a.cache)&&new M(c);a.cache=!1;this.o=a.worker;this.async=!1;c=x();let d=b.index||b.field||b;C(d)&&(d=[d]);for(let e=0,f,h;e<d.length;e++)f=d[e],C(f)||(h=f,f=f.field),h=D(h)?Object.assign({},a,h):a, F.prototype.get=function(a){const b=this.cache.get(a);b&&this.limit&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};F.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};F.prototype.clear=function(){this.cache.clear();this.h=""};function na(a,b,c,d){let e=[];for(let f=0,g;f<a.index.length;f++)if(g=a.index[f],b>=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e}
this.o&&(c[f]=new S(h),c[f].o||(this.o=!1)),this.o||(c[f]=new N(h,this.register)),this.K[e]=V(f,this.A),this.h[e]=f;if(this.C)for(a=b.store,C(a)&&(a=[a]),b=0;b<a.length;b++)this.C[b]=V(a[b],this.A);this.index=c}function V(a,b){const c=a.split(":");let d=0;for(let e=0;e<c.length;e++)a=c[e],0<=a.indexOf("[]")&&(a=a.substring(0,a.length-2))&&(b[d]=!0),a&&(c[d++]=a);d<c.length&&(c.length=d);return 1<d?c:c[0]}function X(a,b){if(C(b))a=a[b];else for(let c=0;a&&c<b.length;c++)a=a[b[c]];return a} function H(a){if(!(this instanceof H))return new H(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;g<b.index.length;g++){h=b.index[g];k=h.indexOf(e);if(0<=k)return f+k;f+=h.length}return-1};if("includes"===
function Y(a,b,c,d,e){a=a[e];if(d===c.length-1)b[e]=a;else if(a)if(a.constructor===Array)for(b=b[e]=Array(a.length),e=0;e<a.length;e++)Y(a,b,c,d,e);else b=b[e]||(b[e]=x()),e=c[++d],Y(a,b,c,d,e)}function Z(a,b,c,d,e,f,h,g){if(a=a[h])if(d===b.length-1){if(a.constructor===Array){if(c[d]){for(b=0;b<a.length;b++)e.add(f,a[b],!0,!0);return}a=a.join(" ")}e.add(f,a,g,!0)}else if(a.constructor===Array)for(h=0;h<a.length;h++)Z(a,b,c,d,e,f,h,g);else h=b[++d],Z(a,b,c,d,e,f,h,g)}t=U.prototype; d)return function(e){for(let f=0;f<b.index.length;f++)if(b.index[f].includes(e))return!0;return!1};if("slice"===d)return function(e,f){return na(b,e||0,f||b.length,!1)};if("splice"===d)return function(e,f){return na(b,e||0,f||b.length,!0)};if("constructor"===d)return Array;if("symbol"!==typeof d)return(c=b.index[d/2**31|0])&&c[d]},set(c,d,e){c=d/2**31|0;(b.index[c]||(b.index[c]=[]))[d]=e;b.length++;return!0}})}H.prototype.clear=function(){this.index.length=0};H.prototype.push=function(){};
t.add=function(a,b,c){D(a)&&(b=a,a=X(b,this.key));if(b&&(a||0===a)){if(!c&&this.register[a])return this.update(a,b);for(let d=0,e,f;d<this.h.length;d++)f=this.h[d],e=this.K[d],C(e)&&(e=[e]),Z(b,e,this.A,0,this.index[f],a,e[0],c);if(this.I){let d=X(b,this.I),e=x();C(d)&&(d=[d]);for(let f=0,h,g;f<d.length;f++)if(h=d[f],!e[h]&&(e[h]=1,g=this.l[h]||(this.l[h]=[]),!c||!g.includes(a)))if(g[g.length]=a,this.m){const k=this.register[a]||(this.register[a]=[]);k[k.length]=g}}if(this.store&&(!c||!this.store[a])){let d; function K(a=8){if(!(this instanceof K))return new K(a);this.index=z();this.F=[];this.size=0;32<a?(this.h=oa,this.B=BigInt(a)):(this.h=pa,this.B=a)}K.prototype.get=function(a){const b=this.index[this.h(a)];return b&&b.get(a)};K.prototype.set=function(a,b){var c=this.h(a);let d=this.index[c];d?(c=d.size,d.set(a,b),(c-=d.size)&&this.size++):(this.index[c]=d=new Map([[a,b]]),this.F.push(d))};
if(this.C){d=x();for(let e=0,f;e<this.C.length;e++)f=this.C[e],C(f)?d[f]=b[f]:Y(b,d,f,0,f[0])}this.store[a]=d||b}}return this};t.append=function(a,b){return this.add(a,b,!0)};t.update=function(a,b){return this.remove(a).add(a,b)}; function L(a=8){if(!(this instanceof L))return new L(a);this.index=z();this.h=[];32<a?(this.F=oa,this.B=BigInt(a)):(this.F=pa,this.B=a)}L.prototype.add=function(a){var b=this.F(a);let c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.h.push(c))};u=K.prototype;u.has=L.prototype.has=function(a){const b=this.index[this.F(a)];return b&&b.has(a)};u.delete=L.prototype.delete=function(a){const b=this.index[this.F(a)];b&&b.delete(a)&&this.size--};
t.remove=function(a){D(a)&&(a=X(a,this.key));if(this.register[a]){for(var b=0;b<this.h.length&&(this.index[this.h[b]].remove(a,!this.o),!this.m);b++);if(this.I&&!this.m)for(let c in this.l){b=this.l[c];const d=b.indexOf(a);-1!==d&&(1<b.length?b.splice(d,1):delete this.l[c])}this.store&&delete this.store[a];delete this.register[a]}return this}; u.clear=L.prototype.clear=function(){this.index=z();this.h=[];this.size=0};u.values=L.prototype.values=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].values())yield b};u.keys=L.prototype.keys=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].keys())yield b};u.entries=L.prototype.entries=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].entries())yield b};
t.search=function(a,b,c,d){c||(!b&&D(a)?(c=a,a=""):D(b)&&(c=b,b=0));let e=[],f=[],h,g,k,m,n,w,q=0;if(c)if(c.constructor===Array)k=c,c=null;else{a=c.query||a;k=(h=c.pluck)||c.index||c.field;m=c.tag;g=this.store&&c.enrich;n="and"===c.bool;b=c.limit||b||100;w=c.offset||0;if(m&&(C(m)&&(m=[m]),!a)){for(let l=0,p;l<m.length;l++)if(p=va.call(this,m[l],b,w,g))e[e.length]=p,q++;return q?e:[]}C(k)&&(k=[k])}k||(k=this.h);n=n&&(1<k.length||m&&1<m.length);const r=!d&&(this.o||this.async)&&[];for(let l=0,p,A,B;l< function pa(a){let b=2**this.B-1;if("number"==typeof a)return a&b;let c=0,d=this.B+1;for(let e=0;e<a.length;e++)c=(c*d^a.charCodeAt(e))&b;return 32===this.B?c+2**31:c}function oa(a){let b=BigInt(2)**this.B-BigInt(1);var c=typeof a;if("bigint"===c)return a&b;if("number"===c)return BigInt(a)&b;c=BigInt(0);let d=this.B+BigInt(1);for(let e=0;e<a.length;e++)c=(c*d^BigInt(a.charCodeAt(e)))&b;return c};function qa(a,b,c,d,e,f,g,h){(d=a(c?c+"."+d:d,JSON.stringify(g)))&&d.then?d.then(function(){b.export(a,b,c,e,f+1,h)}):b.export(a,b,c,e,f+1,h)};const ra=z(),M=z();var sa={normalize:function(a){return a.toLowerCase()},C:!1};const ta={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};function ua(a){O.call(a,"add");O.call(a,"append");O.call(a,"search");O.call(a,"update");O.call(a,"remove")}function O(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);this.async=!0;b=this[a].apply(this,b);this.async=!1;b.then?b.then(d):d(b);return b}};z();P.prototype.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.A.has(a))return this.update(a,b);b=this.encoder.encode(b);if(d=b.length){const l=z(),m=z(),n=this.depth,q=this.resolution;for(let t=0;t<d;t++){let p=b[this.rtl?d-1-t:t];var e=p.length;if(e&&(n||!m[p])){var f=this.score?this.score(b,p,t,null,0):Q(q,d,t),g="";switch(this.tokenize){case "full":if(2<e){for(f=0;f<e;f++)for(var h=e;h>f;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,t,g,f):Q(q,d,t,e,f);R(this,m,g,k,a,c)}break}case "reverse":if(1<
k.length;l++){let z;A=k[l];C(A)||(z=A,A=z.field,a=z.query||a,b=z.limit||b,g=z.enrich||g);if(r)r[l]=this.index[A].searchAsync(a,b,z||c);else{d?p=d[l]:p=this.index[A].search(a,b,z||c);B=p&&p.length;if(m&&B){const y=[];let H=0;n&&(y[0]=[p]);for(let W=0,ma,R;W<m.length;W++)if(ma=m[W],B=(R=this.l[ma])&&R.length)H++,y[y.length]=n?[R]:R;H&&(p=n?ja(y,b||100,w||0):ka(p,y),B=p.length)}if(B)f[q]=A,e[q++]=p;else if(n)return[]}}if(r){const l=this;return new Promise(function(p){Promise.all(r).then(function(A){p(l.search(a, e){for(h=e-1;0<h;h--)g=p[h]+g,k=this.score?this.score(b,p,t,g,h):Q(q,d,t,e,h),R(this,m,g,k,a,c);g=""}case "forward":if(1<e){for(h=0;h<e;h++)g+=p[h],R(this,m,g,f,a,c);break}default:if(R(this,m,p,f,a,c),n&&1<d&&t<d-1)for(e=z(),g=this.da,f=p,h=Math.min(n+1,d-t),e[f]=1,k=1;k<h;k++)if((p=b[this.rtl?d-1-t-k:t+k])&&!e[p]){e[p]=1;const r=this.score?this.score(b,f,t,p,k):Q(g+(d/2>g?0:1),d,t,h-1,k-1),x=this.bidirectional&&p>f;R(this,l,x?f:p,r,a,c,x?p:f)}}}}this.fastupdate||this.A.add(a)}else b=""}this.db&&
b,c,A))})})}if(!q)return[];if(h&&(!g||!this.store))return e[0];for(let l=0,p;l<f.length;l++){p=e[l];p.length&&g&&(p=wa.call(this,p));if(h)return p;e[l]={field:f[l],result:p}}return e};function va(a,b,c,d){let e=this.l[a],f=e&&e.length-c;if(f&&0<f){if(f>b||c)e=e.slice(c,c+b);d&&(e=wa.call(this,e));return{tag:a,result:e}}}function wa(a){const b=Array(a.length);for(let c=0,d;c<a.length;c++)d=a[c],b[c]={id:d,doc:this.store[d]};return b}t.contain=function(a){return!!this.register[a]};t.get=function(a){return this.store[a]}; (b||this.R.push({del:a}),this.fa&&va(this));return this};function R(a,b,c,d,e,f,g){let h=g?a.I:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new H(h);if(a.fastupdate)for(let l of a.A.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.A.get(e))?d.push(h):a.A.set(e,[h]))}}
t.set=function(a,b){this.store[a]=b;return this};t.searchCache=la;t.export=function(a,b,c,d,e,f){let h;"undefined"===typeof f&&(h=new Promise(g=>{f=g}));e||(e=0);d||(d=0);if(d<this.h.length){const g=this.h[d],k=this.index[g];b=this;setTimeout(function(){k.export(a,b,e?g:"",d,e++,f)||(d++,e=1,b.export(a,b,g,d,e,f))})}else{let g,k;switch(e){case 1:g="tag";k=this.l;c=null;break;case 2:g="store";k=this.store;c=null;break;default:f();return}oa(a,this,c,g,d,e,k,f)}return h}; function Q(a,b,c,d,e){return c&&1<a?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0};function S(a,b,c,d){if(1===a.length)return a=a[0],a=c||a.length>b?b?a.slice(c,c+b):a.slice(c):a,d?wa(a):a;let e=[];for(let f=0,g,h;f<a.length;f++)if((g=a[f])&&(h=g.length)){if(c){if(c>=h){c-=h;continue}c<h&&(g=b?g.slice(c,c+b):g.slice(c),h=g.length,c=0)}if(e.length)h>b&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?wa(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1<e.length?[].concat.apply([],e):e[0];return d?wa(e):e}
t.import=function(a,b){if(b)switch(C(b)&&(b=JSON.parse(b)),a){case "tag":this.l=b;break;case "reg":this.m=!1;this.register=b;for(let d=0,e;d<this.h.length;d++)e=this.index[this.h[d]],e.register=b,e.m=!1;break;case "store":this.store=b;break;default:a=a.split(".");const c=a[0];a=a[1];c&&a&&this.index[c].import(a,b)}};ia(U.prototype);var ya={encode:xa,F:!1,G:""};const za=[J("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",J("[\u00e8\u00e9\u00ea\u00eb]"),"e",J("[\u00ec\u00ed\u00ee\u00ef]"),"i",J("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",J("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",J("[\u00fd\u0177\u00ff]"),"y",J("\u00f1"),"n",J("[\u00e7c]"),"k",J("\u00df"),"s",J(" & ")," and "];function xa(a){var b=a=""+a;b.normalize&&(b=b.normalize("NFD").replace(ca,""));return F.call(this,b.toLowerCase(),!a.normalize&&za)};var Ba={encode:Aa,F:!1,G:"strict"};const Ca=/[^a-z0-9]+/,Da={b:"p",v:"f",w:"f",z:"s",x:"s","\u00df":"s",d:"t",n:"m",c:"k",g:"k",j:"k",q:"k",i:"e",y:"e",u:"o"};function Aa(a){a=xa.call(this,a).join(" ");const b=[];if(a){const c=a.split(Ca),d=c.length;for(let e=0,f,h=0;e<d;e++)if((a=c[e])&&(!this.filter||!this.filter[a])){f=a[0];let g=Da[f]||f,k=g;for(let m=1;m<a.length;m++){f=a[m];const n=Da[f]||f;n&&n!==k&&(g+=n,k=n)}b[h++]=g}}return b};var Fa={encode:Ea,F:!1,G:""};const Ga=[J("ae"),"a",J("oe"),"o",J("sh"),"s",J("th"),"t",J("ph"),"f",J("pf"),"f",J("(?![aeo])h(?![aeo])"),"",J("(?!^[aeo])h(?!^[aeo])"),""];function Ea(a,b){a&&(a=Aa.call(this,a).join(" "),2<a.length&&(a=G(a,Ga)),b||(1<a.length&&(a=da(a)),a&&(a=a.split(" "))));return a||[]};var Ia={encode:Ha,F:!1,G:""};const Ja=J("(?!\\b)[aeo]");function Ha(a){a&&(a=Ea.call(this,a,!0),1<a.length&&(a=a.replace(Ja,"")),1<a.length&&(a=da(a)),a&&(a=a.split(" ")));return a||[]};K["latin:default"]=fa;K["latin:simple"]=ya;K["latin:balance"]=Ba;K["latin:advanced"]=Fa;K["latin:extra"]=Ia;export default {Index:N,Document:U,Worker:S,registerCharset:function(a,b){K[a]=b},registerLanguage:function(a,b){ha[a]=b}}; function wa(a){for(let b=0;b<a.length;b++)a[b]={score:b,id:a[b]};return a};T.prototype.or=function(){const a=this;let b=arguments;var c=b[0];if(c instanceof Promise)return c.then(function(){return a.or.apply(a,b)});if(c[0]&&c[0].index)return this.or.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;k<b.length;k++)if(l=b[k]){let m;if(l instanceof T)m=l.result;else if(l.constructor===Array)m=l;else if(l.index)l.resolve=!1,m=l.index.search(l).result;else if(l.and)m=this.and(l.and);else if(l.xor)m=this.xor(l.xor);else if(l.G)m=this.G(l.G);else{e=l.limit||0;f=l.offset||
0;g=l.enrich;h=l.resolve;continue}d[k]=m;m instanceof Promise&&c.push(m)}if(c.length)return Promise.all(c).then(function(){a.result.length&&(d=[a.result].concat(d));a.result=xa(d,e,f,g,h,a.O);return h?a.result:a});this.result.length&&(d=[this.result].concat(d));this.result=xa(d,e,f,g,h,a.O);return h?this.result:this};
function xa(a,b,c,d,e,f){if(!a.length)return a;"object"===typeof b&&(c=b.offset||0,d=b.enrich||!1,b=b.limit||0);if(2>a.length)return e?S(a[0],b,c,d):a[0];d=[];let g=0,h=z(),k=da(a);for(let l=0,m;l<k;l++)for(let n=0,q;n<a.length;n++)if(q=a[n])if(m=q[l])for(let t=0,p;t<m.length;t++)if(p=m[t],!h[p])if(h[p]=1,c)c--;else{if(e)d.push(p);else{const r=l+(n?f:0);d[r]||(d[r]=[]);d[r].push(p)}if(b&&++g===b)return d}return d};T.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a instanceof Promise)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g;for(let h=0,k;h<c.length;h++)if(k=c[h]){let l;if(k instanceof T)l=k.result;else if(k.constructor===Array)l=k;else if(k.index)k.resolve=!1,l=k.index.search(k).result;else if(k.or)l=this.or(k.or);else if(k.xor)l=this.xor(k.xor);else if(k.G)l=this.G(k.G);else{e=
k.limit||0;f=k.offset||0;g=k.resolve;continue}d[h]=l;l instanceof Promise&&a.push(l)}if(a.length)return Promise.all(a).then(function(){d=[b.result].concat(d);b.result=ya(d,e,f,g,b.O);return g?b.result:b});d=[this.result].concat(d);this.result=ya(d,e,f,g,b.O);return g?this.result:this}return this};
function ya(a,b,c,d,e){if(2>a.length)return[];let f=[],g=0,h=z(),k=da(a);if(!k)return f;for(let l=0,m;l<a.length;l++){m=a[l];if(!m||!m.length)return[];let n=z(),q=0,t=l===a.length-1;for(let p=0,r;p<k;p++)if(r=m[p])for(let x=0,A,w;x<r.length;x++)if(A=r[x],!l)n[A]=p+1+(l?e:0),q=1;else if(t){if(w=h[A])if(q=1,c)c--;else if(d?f.push(A):(w--,p<w&&(w=p),f[w]||(f[w]=[]),f[w].push(A)),b&&++g===b)return f}else if(w=h[A])p+1<w&&(w=p+1),n[A]=w,q=1;if(!q)return[];h=n}return f};T.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c instanceof Promise)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;k<b.length;k++)if(l=b[k]){let m;if(l instanceof T)m=l.result;else if(l.constructor===Array)m=l;else if(l.index)l.resolve=!1,m=l.index.search(l).result;else if(l.or)m=this.or(l.or);else if(l.and)m=this.and(l.and);else if(l.G)m=this.G(l.G);else{e=l.limit||0;f=l.offset||
0;g=l.enrich;h=l.resolve;continue}d[k]=m;m instanceof Promise&&c.push(m)}if(c.length)return Promise.all(c).then(function(){a.result.length&&(d=[a.result].concat(d));a.result=za(d,e,f,g,!h,a.O);return h?a.result:a});this.result.length&&(d=[this.result].concat(d));this.result=za(d,e,f,g,!h,a.O);return h?this.result:this};
function za(a,b,c,d,e,f){if(!a.length)return a;if(2>a.length)return e?S(a[0],b,c,d):a[0];b=[];c=z();for(let g=0,h;g<a.length;g++)if(h=a[g])for(let k=0,l;k<h.length;k++)if(l=h[k])for(let m=0,n;m<l.length;m++)n=l[m],c[n]?c[n]++:c[n]=1;for(let g=0,h;g<a.length;g++)if(h=a[g])for(let k=0,l;k<h.length;k++)if(l=h[k])for(let m=0,n;m<l.length;m++)n=l[m],1===c[n]&&(e?b.push(n):(d=k+(g?f:0),b[d]||(b[d]=[]),b[d].push(n)));return b};T.prototype.G=function(){const a=this;let b=arguments;var c=b[0];if(c instanceof Promise)return c.then(function(){return a.G.apply(a,b)});if(c[0]&&c[0].index)return this.G.apply(this,c);let d=[];c=[];let e;for(let f=0,g;f<b.length;f++)if(g=b[f]){let h;if(g instanceof T)h=g.result;else if(g.constructor===Array)h=g;else if(g.index)g.resolve=!1,h=g.index.search(g).result;else if(g.or)h=this.or(g.or);else if(g.and)h=this.and(g.and);else if(g.xor)h=this.xor(g.xor);else{e=g.resolve;continue}d[f]=h;h instanceof
Promise&&c.push(h)}if(c.length)return Promise.all(c).then(function(){a.result=Aa.call(a,d,e);return e?a.result:a});this.result=Aa.call(this,d,e);return e?this.result:this};function Aa(a,b){if(!a.length)return this.result;const c=[];a=new Set(a.flat().flat());for(let d=0,e;d<this.result.length;d++)if(e=this.result[d])for(let f=0,g;f<e.length;f++)g=e[f],a.has(g)||(b?c.push(g):(c[d]||(c[d]=[]),c[d].push(g)));return c};function T(a){if(a&&a.index)return a.resolve=!1,this.index=a.index,a.index.search(a);if(!(this instanceof T))return new T(a);if(a instanceof T)return a;this.index=null;this.result=a||[];this.O=0}T.prototype.limit=function(a){if(this.result.length){const b=[];let c=0;for(let d=0,e;d<this.result.length;d++)if(e=this.result[d],e.length+c<a)b[d]=e,c+=e.length;else{b[d]=e.slice(0,a-c);this.result=b;break}}return this};
T.prototype.offset=function(a){if(this.result.length){const b=[];let c=0;for(let d=0,e;d<this.result.length;d++)e=this.result[d],e.length+c<a?c+=e.length:(b[d]=e.slice(a-c),c=a);this.result=b}return this};T.prototype.resolve=function(a,b,c){U=1;const d=this.result;this.result=this.index=null;return d.length?("object"===typeof a&&(c=a.enrich,b=a.offset,a=a.limit),S(d,a||100,b,c)):d};function Ba(a,b,c,d){var e=a.length;let f=[],g=0,h,k,l;d&&(d=[]);for(let m=e-1,n;0<=m;m--){l=a[m];e=z();n=!h;for(let q=0,t;q<l.length;q++)if((t=l[q])&&t.length)for(let p=0,r;p<t.length;p++)if(r=t[p],h){if(h[r]){if(!m)if(c)c--;else if(f[g++]=r,g===b)return f;if(m||d)e[r]=1;n=!0}d&&!k[r]&&(k[r]=1,(d[q]||(d[q]=[])).push(r))}else e[r]=1;if(d)h||(k=e);else if(!n)return[];h=e}if(d)for(let m=d.length-1,n,q;0<=m;m--){n=d[m];q=n.length;for(let t=0,p;t<q;t++)if(p=n[t],!h[p]){if(c)c--;else if(f[g++]=p,g===b)return f;
h[p]=1}}return f}function Ca(a,b){const c=z(),d=z(),e=[];for(let f=0;f<a.length;f++)c[a[f]]=1;for(let f=0,g;f<b.length;f++){g=b[f];for(let h=0,k;h<g.length;h++)k=g[h],c[k]&&!d[k]&&(d[k]=1,e.push(k))}return e};let U=1;
P.prototype.search=function(a,b,c){c||(!b&&C(a)?(c=a,a=""):C(b)&&(c=b,b=0));let d=[],e;let f,g=0,h,k,l;if(c){a=c.query||a;b=c.limit||b;g=c.offset||0;var m=c.context;f=c.suggest;(h=U&&!1!==c.resolve)||(U=0);k=h&&c.enrich;l=this.db&&c.tag}else h=this.resolve||U;a=this.encoder.encode(a);e=a.length;b||!h||(b=100);if(1===e)return Da.call(this,a[0],"",b,g,h,k,l);m=this.depth&&!1!==m;if(2===e&&m&&!f)return Da.call(this,a[0],a[1],b,g,h,k,l);let n=c=0;if(1<e){const p=z(),r=[];for(let x=0,A;x<e;x++)if((A=a[x])&&
!p[A]){if(f||this.db||V(this,A))r.push(A),p[A]=1;else return h?d:new T(d);const w=A.length;c=Math.max(c,w);n=n?Math.min(n,w):w}a=r;e=a.length}if(!e)return h?d:new T(d);let q=0,t;if(1===e)return Da.call(this,a[0],"",b,g,h,k,l);if(2===e&&m&&!f)return Da.call(this,a[0],a[1],b,g,h,k,l);1<e&&(m?(t=a[0],q=1):9<c&&3<c/n&&a.sort(aa));if(this.db){if(this.db.search&&(m=this.db.search(this,a,b,g,f,h,k,l),!1!==m))return m;const p=this;return async function(){for(let r,x;q<e;q++){x=a[q];t?(r=await V(p,x,t),r=
Ea(r,d,f,p.da,b,g,2===e),f&&!1===r&&d.length||(t=x)):(r=await V(p,x),r=Ea(r,d,f,p.resolution,b,g,1===e));if(r)return r;if(f&&q===e-1){let A=d.length;if(!A){if(t){t="";q=-1;continue}return d}if(1===A)return h?S(d[0],b,g):new T(d[0])}}return h?Ba(d,b,g,f):new T(d[0])}()}for(let p,r;q<e;q++){r=a[q];t?(p=V(this,r,t),p=Ea(p,d,f,this.da,b,g,2===e),f&&!1===p&&d.length||(t=r)):(p=V(this,r),p=Ea(p,d,f,this.resolution,b,g,1===e));if(p)return p;if(f&&q===e-1){m=d.length;if(!m){if(t){t="";q=-1;continue}return d}if(1===
m)return h?S(d[0],b,g):new T(d[0])}}return h?Ba(d,b,g,f):new T(d[0])};function Da(a,b,c,d,e,f,g){a=V(this,a,b,c,d,e,f,g);return this.db?a.then(function(h){return e?h:h&&h.length?e?S(h,c,d):new T(h):e?[]:new T([])}):a&&a.length?e?S(a,c,d):new T(a):e?[]:new T([])}
function Ea(a,b,c,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,l=0,m;k<d;k++)if(m=a[k])if(f&&m&&g&&(m.length<=f?(f-=m.length,m=null):(m=m.slice(f),f=0)),m&&(h[k]=m,g&&(l+=m.length,l>=e)))break;if(h.length){if(g)return S(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.I.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};P.prototype.remove=function(a,b){const c=this.A.size&&(this.fastupdate?this.A.get(a):this.A.has(a));if(c){if(this.fastupdate)for(let d=0,e;d<c.length;d++){if(e=c[d])if(2>e.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else Fa(this.map,a),this.depth&&Fa(this.I,a);b||this.A.delete(a)}this.db&&(this.R.push({del:a}),this.fa&&va(this));this.cache&&this.cache.remove(a);return this};
function Fa(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;d<a.length;d++){if((e=a[d])&&e.length)if(f=e.indexOf(b),0<=f){1<e.length?(e.splice(f,1),c++):delete a[d];break}else c++}else for(let d of a){const e=d[0],f=Fa(d[1],b);f?c+=f:a.delete(e)}return c};function P(a,b){if(!(this instanceof P))return new P(a);if(a){var c=B(a)?a:a.preset;c&&(a=Object.assign({},ta[c],a))}else a={};c=a.context||{};const d=a.encode||a.encoder||sa;this.encoder=d.encode?d:"object"===typeof d?new E(d):{encode:d};let e;this.resolution=a.resolution||9;this.tokenize=e=a.tokenize||"strict";this.depth="strict"===e&&c.depth||0;this.bidirectional=!1!==c.bidirectional;this.fastupdate=!!a.fastupdate;this.score=a.score||null;(e=a.keystore||0)&&(this.keystore=e);this.map=e?new K(e):
new Map;this.I=e?new K(e):new Map;this.A=b||(this.fastupdate?e?new K(e):new Map:e?new L(e):new Set);this.da=c.resolution||1;this.rtl=d.rtl||a.rtl||!1;this.cache=(e=a.cache||null)&&new F(e);this.resolve=!1!==a.resolve;if(e=a.db)this.db=e.mount(this);this.fa=!1!==a.commit;this.R=[];this.h=null}u=P.prototype;u.mount=function(a){this.h&&(clearTimeout(this.h),this.h=null);return a.mount(this)};u.commit=function(a,b){this.h&&(clearTimeout(this.h),this.h=null);return this.db.commit(this,a,b)};
function va(a){a.h||(a.h=setTimeout(function(){a.h=null;a.db.commit(a,void 0,void 0)},0))}u.clear=function(){this.map.clear();this.I.clear();this.A.clear();this.cache&&this.cache.clear();this.db&&(this.h&&clearTimeout(this.h),this.h=null,this.R=[{clear:!0}]);return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.db?this.db.has(a):this.A.has(a)};
u.update=function(a,b){if(this.async){const c=this,d=this.remove(a);return d.then?d.then(()=>c.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)};function Ga(a){let b=0;if(a.constructor===Array)for(let c=0,d;c<a.length;c++)(d=a[c])&&(b+=d.length);else for(const c of a){const d=c[0],e=Ga(c[1]);e?b+=e:a.delete(d)}return b}u.cleanup=function(){if(!this.fastupdate)return this;Ga(this.map);this.depth&&Ga(this.I);return this};u.searchCache=ma;
u.export=function(a,b,c,d,e,f){let g=!0;"undefined"===typeof f&&(g=new Promise(l=>{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=z();for(let l of this.A.keys())k[l]=1}else k=this.A;break;case 1:h="cfg";k={doc:0,opt:this.B?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.I;break;default:"undefined"===typeof c&&f&&f();return}qa(a,b||this,c,h,d,e,k,f);return g};
u.import=function(a,b){if(b)switch(B(b)&&(b=JSON.parse(b)),a){case "cfg":this.B=!!b.opt;break;case "reg":this.fastupdate=!1;this.A=b;break;case "map":this.map=b;break;case "ctx":this.I=b}};ua(P.prototype);async function Ha(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};(b=d.config)&&(d=await import(b));(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new P(d);postMessage({id:a.id});break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let Ia=0;
function W(a){function b(f){f=f.data||f;const g=f.id,h=g&&e.h[g];h&&(h(f.msg),delete e.h[g])}if(!(this instanceof W))return new W(a);a||(a={});let c=(self||window)._factory;c&&(c=c.toString());const d="undefined"===typeof window&&self.exports,e=this;this.worker=Ja(c,d,a.worker);this.h=z();if(this.worker){d?this.worker.on("message",b):this.worker.onmessage=b;if(a.config)return new Promise(function(f){e.h[++Ia]=function(){f(e)};e.worker.postMessage({id:Ia,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",
factory:c,options:a})}}X("add");X("append");X("search");X("update");X("remove");function X(a){W.prototype[a]=W.prototype[a+"Async"]=function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;"function"===typeof d&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){b.h[++Ia]=f;b.worker.postMessage({task:a,id:Ia,args:c})});return e?(d.then(e),this):d}}
function Ja(a,b,c){return b?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ha.toString()],{type:"text/javascript"}))):new window.Worker(B(c)?c:"worker/worker.js",{type:"module"})};Y.prototype.add=function(a,b,c){C(a)&&(b=a,a=ca(b,this.key));if(b&&(a||0===a)){if(!c&&this.A.has(a))return this.update(a,b);for(let h=0,k;h<this.field.length;h++){k=this.M[h];var d=this.index.get(this.field[h]);if("function"===typeof k){var e=k(b);e&&d.add(a,e,!1,!0)}else if(e=k.T,!e||e(b))k instanceof String?k=[""+k]:B(k)&&(k=[k]),Ka(b,k,this.W,0,d,a,k[0],c)}if(this.tag)for(d=0;d<this.L.length;d++){var f=this.L[d];e=this.tag.get(this.aa[d]);let h=z();if("function"===typeof f){if(f=f(b),!f)continue}else{var g=
f.T;if(g&&!g(b))continue;f instanceof String&&(f=""+f);f=ca(b,f)}if(e&&f){B(f)&&(f=[f]);for(let k=0,l,m;k<f.length;k++)if(l=f[k],!h[l]&&(h[l]=1,(g=e.get(l))?m=g:e.set(l,m=[]),!c||!m.includes(a))){if(m.length===2**31-1){g=new H(m);if(this.fastupdate)for(let n of this.A.values())n.includes(m)&&(n[n.indexOf(m)]=g);e.set(l,m=g)}m.push(a);this.fastupdate&&((g=this.A.get(a))?g.push(m):this.A.set(a,[m]))}}}if(this.store&&(!c||!this.store.has(a))){let h;if(this.H){h=z();for(let k=0,l;k<this.H.length;k++){l=
this.H[k];if((c=l.T)&&!c(b))continue;let m;if("function"===typeof l){m=l(b);if(!m)continue;l=[l.ia]}else if(B(l)||l instanceof String){h[l]=b[l];continue}La(b,h,l,0,l[0],m)}}this.store.set(a,h||b)}}return this};function La(a,b,c,d,e,f){a=a[e];if(d===c.length-1)b[e]=f||a;else if(a)if(a.constructor===Array)for(b=b[e]=Array(a.length),e=0;e<a.length;e++)La(a,b,c,d,e);else b=b[e]||(b[e]=z()),e=c[++d],La(a,b,c,d,e)}
function Ka(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(f,a[b],!0,!0);return}a=a.join(" ")}e.add(f,a,h,!0)}else if(a.constructor===Array)for(g=0;g<a.length;g++)Ka(a,b,c,d,e,f,g,h);else g=b[++d],Ka(a,b,c,d,e,f,g,h);else e.db&&e.remove(f)};Y.prototype.search=function(a,b,c,d){c||(!b&&C(a)?(c=a,a=""):C(b)&&(c=b,b=0));let e=[],f=[],g;let h;let k;let l,m=0;if(c)if(c.constructor===Array)k=c,c=null;else{a=c.query||a;g=c.pluck;h=c.merge;k=g||c.field||c.index;var n=this.tag&&c.tag;var q=this.store&&c.enrich;var t=c.suggest;b=c.limit||b;l=c.offset||0;b||(b=100);if(n&&(!this.db||!d)){n.constructor!==Array&&(n=[n]);var p=[];for(let w=0,v;w<n.length;w++)if(v=n[w],v.field&&v.tag){var r=v.tag;if(r.constructor===Array)for(var x=0;x<r.length;x++)p.push(v.field,
r[x]);else p.push(v.field,r)}else{r=Object.keys(v);for(let I=0,J,D;I<r.length;I++)if(J=r[I],D=v[J],D.constructor===Array)for(x=0;x<D.length;x++)p.push(J,D[x]);else p.push(J,D)}n=p;if(!a){t=[];if(p.length)for(n=0;n<p.length;n+=2){if(this.db){d=this.index.get(p[n]);if(!d)continue;t.push(d=d.db.tag(p[n+1],b,l,q))}else d=Ma.call(this,p[n],p[n+1],b,l,q);e.push({field:p[n],tag:p[n+1],result:d})}return t.length?Promise.all(t).then(function(w){for(let v=0;v<w.length;v++)e[v].result=w[v];return e}):e}}B(k)&&
(k=[k])}k||(k=this.field);p=!d&&(this.worker||this.async)&&[];let A;for(let w=0,v,I,J;w<k.length;w++){I=k[w];if(this.db&&this.tag&&!this.M[w])continue;let D;B(I)||(D=I,I=D.field,a=D.query||a,b=D.limit||b,t=D.suggest||t);if(d)v=d[w];else if(r=D||c,x=this.index.get(I),n&&(this.db&&(r.tag=n,A=x.db.la,r.field=k),A||(r.enrich=!1)),p){p[w]=x.searchAsync(a,b,r);r&&q&&(r.enrich=q);continue}else v=x.search(a,b,r),r&&q&&(r.enrich=q);J=v&&v.length;if(n&&J){r=[];x=0;if(this.db&&d){if(!A)for(let N=k.length;N<
d.length;N++){let G=d[N];if(G&&G.length)x++,r.push(G);else if(!t)return e}}else for(let N=0,G,Xa;N<n.length;N+=2){G=this.tag.get(n[N]);if(!G)if(t)continue;else return e;if(Xa=(G=G&&G.get(n[N+1]))&&G.length)x++,r.push(G);else if(!t)return e}if(x){v=Ca(v,r);J=v.length;if(!J&&!t)return e;x--}}if(J)f[m]=I,e.push(v),m++;else if(1===k.length)return e}if(p){if(this.db&&n&&n.length&&!A)for(q=0;q<n.length;q+=2){d=this.index.get(n[q]);if(!d)if(t)continue;else return e;p.push(d.db.tag(n[q+1],b,l,!1))}const w=
this;return Promise.all(p).then(function(v){return v.length?w.search(a,b,c,v):v})}if(!m)return e;if(g&&(!q||!this.store))return e[0];p=[];for(let w=0,v;w<f.length;w++){v=e[w];q&&v.length&&!v[0].doc&&(this.db?p.push(v=this.index.get(this.field[0]).db.enrich(v)):v.length&&(v=Na.call(this,v)));if(g)return v;e[w]={field:f[w],result:v}}return q&&this.db&&p.length?Promise.all(p).then(function(w){for(let v=0;v<w.length;v++)e[v].result=w[v];return h?Oa(e,b):e}):h?Oa(e,b):e};
function Oa(a,b){const c=[],d=z();for(let e=0,f,g;e<a.length;e++){f=a[e];g=f.result;for(let h=0,k,l,m;h<g.length;h++)if(l=g[h],k=l.id,m=d[k])m.push(f.field);else{if(c.length===b)return c;l.field=d[k]=[f.field];c.push(l)}}return c}function Ma(a,b,c,d,e){a=this.tag.get(a);if(!a)return[];if((b=(a=a&&a.get(b))&&a.length-d)&&0<b){if(b>c||d)a=a.slice(d,d+c);e&&(a=Na.call(this,a));return a}}
function Na(a){const b=Array(a.length);for(let c=0,d;c<a.length;c++)d=a[c],b[c]={id:d,doc:this.store.get(d)};return b};function Y(a){if(!(this instanceof Y))return new Y(a);const b=a.document||a.doc||a;var c,d;this.M=[];this.field=[];this.W=[];this.key=(c=b.key||b.id)&&Pa(c,this.W)||"id";(d=a.keystore||0)&&(this.keystore=d);this.A=(this.fastupdate=!!a.fastupdate)?d?new K(d):new Map:d?new L(d):new Set;this.H=(c=b.store||null)&&!0!==c&&[];this.store=c&&(d?new K(d):new Map);this.cache=(c=a.cache||null)&&new F(c);a.cache=!1;this.worker=a.worker;this.async=!1;c=new Map;d=b.index||b.field||b;B(d)&&(d=[d]);for(let e=0,f,
g;e<d.length;e++){f=d[e];B(f)||(g=f,f=f.field);g=C(g)?Object.assign({},a,g):a;if(this.worker){const h=new W(g);c.set(f,h);h.worker||(this.worker=!1)}this.worker||c.set(f,new P(g,this.A));g.S?this.M[e]=g.S:(this.M[e]=Pa(f,this.W),g.filter&&("string"===typeof this.M[e]&&(this.M[e]=new String(this.M[e])),this.M[e].T=g.filter));this.field[e]=f}if(this.H){d=b.store;B(d)&&(d=[d]);for(let e=0,f,g;e<d.length;e++)f=d[e],g=f.field||f,f.S?(this.H[e]=f.S,f.S.ia=g):(this.H[e]=Pa(g,this.W),f.filter&&("string"===
typeof this.H[e]&&(this.H[e]=new String(this.H[e])),this.H[e].T=f.filter))}this.index=c;this.tag=null;if(c=b.tag)if("string"===typeof c&&(c=[c]),c.length){this.tag=new Map;this.L=[];this.aa=[];for(let e=0,f,g;e<c.length;e++){f=c[e];g=f.field||f;if(!g)throw Error("The tag field from the document descriptor is undefined.");f.S?this.L[e]=f.S:(this.L[e]=Pa(g,this.W),f.filter&&("string"===typeof this.L[e]&&(this.L[e]=new String(this.L[e])),this.L[e].T=f.filter));this.aa[e]=g;this.tag.set(g,new Map)}}a.db&&
this.mount(a.db)}u=Y.prototype;
u.mount=function(a){let b=this.field;if(this.tag)for(let e=0,f;e<this.aa.length;e++){f=this.aa[e];var c=this.index.get(f);c||(this.index.set(f,c=new P({},this.A)),b===this.field&&(b=b.slice(0)),b.push(f));c.tag=this.tag.get(f)}c=[];const d={db:a.db,type:a.type,fastupdate:a.fastupdate};for(let e=0,f,g;e<b.length;e++){d.field=g=b[e];f=this.index.get(g);const h=new a.constructor(a.id,d);h.id=a.id;c[e]=h.mount(f);f.document=!0;e?f.ja=!0:f.store=this.store}this.db=this.async=!0;return Promise.all(c)};
u.commit=async function(a,b){const c=[];for(const d of this.index.values())c.push(d.db.commit(d,a,b));await Promise.all(c);this.A.clear()};function Pa(a,b){const c=a.split(":");let d=0;for(let e=0;e<c.length;e++)a=c[e],"]"===a[a.length-1]&&(a=a.substring(0,a.length-2))&&(b[d]=!0),a&&(c[d++]=a);d<c.length&&(c.length=d);return 1<d?c:c[0]}u.append=function(a,b){return this.add(a,b,!0)};u.update=function(a,b){return this.remove(a).add(a,b)};
u.remove=function(a){C(a)&&(a=ca(a,this.key));for(var b of this.index.values())b.remove(a,!0);if(this.A.has(a)){if(this.tag&&!this.fastupdate)for(let c of this.tag.values())for(let d of c){b=d[0];const e=d[1],f=e.indexOf(a);-1<f&&(1<e.length?e.splice(f,1):c.delete(b))}this.store&&this.store.delete(a);this.A.delete(a)}this.cache&&this.cache.remove(a);return this};
u.clear=function(){for(const a of this.index.values())a.clear();if(this.tag)for(const a of this.tag.values())a.clear();this.store&&this.store.clear();return this};u.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.A.has(a)};u.cleanup=function(){for(const a of this.index.values())a.cleanup();return this};u.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(b){return b[0]&&b[0].doc}):this.store.get(a)};
u.set=function(a,b){this.store.set(a,b);return this};u.searchCache=ma;u.export=function(a,b,c,d,e,f){let g;"undefined"===typeof f&&(g=new Promise(k=>{f=k}));e||(e=0);d||(d=0);if(d<this.field.length){c=this.field[d];var h=this.index[c];b=this;h.export(a,b,e?c:"",d,e++,f)||(d++,b.export(a,b,c,d,1,f))}else{switch(e){case 1:b="tag";h=this.h;c=null;break;case 2:b="store";h=this.store;c=null;break;default:f();return}qa(a,this,c,b,d,e,h,f)}return g};
u.import=function(a,b){if(b)switch(B(b)&&(b=JSON.parse(b)),a){case "tag":this.h=b;break;case "reg":this.fastupdate=!1;this.A=b;for(let d=0,e;d<this.field.length;d++)e=this.index[this.field[d]],e.A=b,e.fastupdate=!1;break;case "store":this.store=b;break;default:a=a.split(".");const c=a[0];a=a[1];c&&a&&this.index[c].import(a,b)}};ua(Y.prototype);const Qa="undefined"!==typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Ra=["map","ctx","tag","reg","cfg"];
function Sa(a,b={}){if(!(this instanceof Sa))return new Sa(a,b);"object"===typeof a&&(b=a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=b.field?b.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.la=!1;this.db=null;this.h={}}u=Sa.prototype;u.mount=function(a){if(a instanceof Y)return a.mount(this);a.db=this;return Ta(this)};
function Ta(a){navigator.storage&&navigator.storage.persist();return a.db||new Promise(function(b,c){const d=Qa.open(a.id+(a.field?":"+a.field:""),1);d.onupgradeneeded=function(){const e=a.db=this.result;Ra.forEach(f=>{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}
u.close=function(){this.db.close();this.db=null};u.clear=function(){const a=this.db.transaction(Ra,"readwrite");for(let b=0;b<Ra.length;b++)a.objectStore(Ra[b]).clear();return Z(a)};
u.get=function(a,b,c=0,d=0,e=!0,f=!1){a=this.db.transaction(b?"ctx":"map","readonly").objectStore(b?"ctx":"map").get(b?b+":"+a:a);const g=this;return Z(a).then(function(h){let k=[];if(!h||!h.length)return k;if(e){if(!c&&!d&&1===h.length)return h[0];for(let l=0,m;l<h.length;l++)if((m=h[l])&&m.length){if(d>=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let q=d;q<n;q++)k.push(m[q]);d=0;if(k.length===c)break}return f?g.enrich(k):k}return h})};
u.tag=function(a,b=0,c=0,d=!1){a=this.db.transaction("tag","readonly").objectStore("tag").get(a);const e=this;return Z(a).then(function(f){if(!f||!f.length||c>=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})};
u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;d<a.length;d++)c[d]=Z(b.get(a[d]));return Promise.all(c).then(function(d){for(let e=0;e<d.length;e++)d[e]={id:a[e],doc:d[e]?JSON.parse(d[e]):null};return d})};u.has=function(a){a=this.db.transaction("reg","readonly").objectStore("reg").getKey(a);return Z(a)};u.search=null;u.info=function(){};
u.transaction=function(a,b,c){let d=this.h[a+":"+b];if(d)return c.call(this,d);let e=this.db.transaction(a,b);this.h[a+":"+b]=d=e.objectStore(a);return new Promise((f,g)=>{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})};
u.commit=async function(a,b,c){if(b)await this.clear(),a.R=[];else{let d=a.R;a.R=[];for(let e=0,f;e<d.length;e++)if(f=d[e],f.clear){await this.clear();b=!0;break}else d[e]=f.ma;b||(c||(d=d.concat(ba(a.A))),d.length&&await this.remove(d))}a.A.size&&(await this.transaction("map","readwrite",function(d){for(const e of a.map){const f=e[0],g=e[1];g.length&&(b?d.put(g,f):d.get(f).onsuccess=function(){let h=this.result;var k;if(h&&h.length){const l=Math.max(h.length,g.length);for(let m=0,n,q;m<l;m++)if((q=
g[m])&&q.length){if((n=h[m])&&n.length)for(k=0;k<q.length;k++)n.push(q[k]);else h[m]=q;k=1}}else h=g,k=1;k&&d.put(h,f)})}}),await this.transaction("ctx","readwrite",function(d){for(const e of a.I){const f=e[0],g=e[1];for(const h of g){const k=h[0],l=h[1];l.length&&(b?d.put(l,f+":"+k):d.get(f+":"+k).onsuccess=function(){let m=this.result;var n;if(m&&m.length){const q=Math.max(m.length,l.length);for(let t=0,p,r;t<q;t++)if((r=l[t])&&r.length){if((p=m[t])&&p.length)for(n=0;n<r.length;n++)p.push(r[n]);
else m[t]=r;n=1}}else m=l,n=1;n&&d.put(m,f+":"+k)})}}}),a.store?await this.transaction("reg","readwrite",function(d){for(const e of a.store){const f=e[0],g=e[1];d.put("object"===typeof g?JSON.stringify(g):1,f)}}):a.ja||await this.transaction("reg","readwrite",function(d){for(const e of a.A.keys())d.put(1,e)}),a.tag&&await this.transaction("tag","readwrite",function(d){for(const e of a.tag){const f=e[0],g=e[1];g.length&&(d.get(f).onsuccess=function(){let h=this.result;h=h&&h.length?h.concat(g):g;d.put(h,
f)})}}),a.map.clear(),a.I.clear(),a.tag&&a.tag.clear(),a.store&&a.store.clear(),a.document||a.A.clear())};function Ua(a,b,c){const d=a.value;let e,f,g=0;for(let h=0,k;h<d.length;h++){if(k=c?d:d[h]){for(let l=0,m,n;l<b.length;l++)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{d[h]=[];break}g+=k.length}if(c)break}g?e&&a.update(d):a.delete();a.continue()}
u.remove=function(a){"object"!==typeof a&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Ua(c,a)}}),this.transaction("ctx","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Ua(c,a)}}),this.transaction("tag","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Ua(c,a,!0)}}),this.transaction("reg","readwrite",function(b){for(let c=0;c<a.length;c++)b.delete(a[c])})])};
function Z(a){return new Promise((b,c)=>{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const Va=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Wa={normalize:!0,C:!0,D:Va};const Ya=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Za=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var $a={normalize:!0,C:!0,D:Va,K:Za,J:Ya};var ab={normalize:!0,C:!0,D:Va,K:Za.concat([/(?!^)[aeoy]/g,""]),J:Ya};const bb={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};M["latin:exact"]={normalize:!1,C:!1};M["latin:default"]=sa;M["latin:simple"]={normalize:!0,C:!0};M["latin:balance"]=Wa;M["latin:advanced"]=$a;M["latin:extra"]=ab;M["latin:soundex"]={normalize:!0,C:!1,ga:{ka:!0},V:function(a){for(let c=0;c<a.length;c++){var b=a[c];let d=b.charAt(0),e=bb[d];for(let f=1,g;f<b.length&&(g=b.charAt(f),"h"===g||"w"===g||!(g=bb[g])||g===e||(d+=g,e=g,4!==d.length));f++);a[c]=d}}};export default {Index:P,Encoder:E,Charset:M,Language:ra,Document:Y,Worker:W,Resolver:T,IndexedDB:Sa};
export const Index=P;export const Encoder=E;export const Charset=M;export const Language=ra;export const Document=Y;export const Worker=W;export const Resolver=T;export const IndexedDB=Sa;

File diff suppressed because it is too large Load Diff

View File

@@ -1,27 +1,53 @@
/**! /**!
* FlexSearch.js v0.7.41 (Compact) * FlexSearch.js v0.8.0 (Bundle)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function(self){'use strict';var t;function v(a){return"undefined"!==typeof a?a:!0}function w(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=z();return b}function z(){return Object.create(null)}function aa(a,b){return b.length-a.length}function C(a){return"string"===typeof a}function D(a){return"object"===typeof a};function E(a,b){var c=ba;if(a&&(b&&(a=F(a,b)),this.G&&(a=F(a,this.G)),this.H&&1<a.length&&(a=F(a,this.H)),c||""===c)){b=a.split(c);if(this.filter){a=this.filter;c=b.length;const e=[];for(let d=0,f=0;d<c;d++){const g=b[d];g&&!a[g]&&(e[f++]=g)}a=e}else a=b;return a}return a}const ba=/[\p{Z}\p{S}\p{P}\p{C}]+/u,ca=/[\u0300-\u036f]/g; (function(self){'use strict';var u;function x(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function y(){return Object.create(null)}function aa(a,b){return b.length-a.length}
function H(a,b){const c=Object.keys(a),e=c.length,d=[];let f="",g=0;for(let h=0,k,m;h<e;h++)k=c[h],(m=a[k])?(d[g++]=I(b?"(?!\\b)"+k+"(\\b|_)":k),d[g++]=m):f+=(f?"|":"")+k;f&&(d[g++]=I(b?"(?!\\b)("+f+")(\\b|_)":"("+f+")"),d[g]="");return d}function F(a,b){for(let c=0,e=b.length;c<e&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a}function I(a){return new RegExp(a,"g")}function J(a){let b="",c="";for(let e=0,d=a.length,f;e<d;e++)(f=a[e])!==c&&(b+=c=f);return b};var da={encode:K,B:!1,C:""};function K(a){return E.call(this,(""+a).toLowerCase(),!1)};const L={},M={};function ea(a){O(a,"add");O(a,"append");O(a,"search");O(a,"update");O(a,"remove")}function O(a,b){a[b+"Async"]=function(){const c=this,e=arguments;var d=e[e.length-1];let f;"function"===typeof d&&(f=d,delete e[e.length-1]);d=new Promise(function(g){setTimeout(function(){c.async=!0;const h=c[b].apply(c,e);c.async=!1;g(h)})});return f?(d.then(f),this):d}};function fa(a,b,c,e){const d=a.length;let f=[],g,h,k=0;e&&(e=[]);for(let m=d-1;0<=m;m--){const n=a[m],u=n.length,q=z();let r=!g;for(let l=0;l<u;l++){const p=n[l],A=p.length;if(A)for(let B=0,y,x;B<A;B++)if(x=p[B],g){if(g[x]){if(!m)if(c)c--;else if(f[k++]=x,k===b)return f;if(m||e)q[x]=1;r=!0}if(e&&(y=(h[x]||0)+1,h[x]=y,y<d)){const G=e[y-2]||(e[y-2]=[]);G[G.length]=x}}else q[x]=1}if(e)g||(h=q);else if(!r)return[];g=q}if(e)for(let m=e.length-1,n,u;0<=m;m--){n=e[m];u=n.length;for(let q=0,r;q<u;q++)if(r= function z(a){return"string"===typeof a}function B(a){return"object"===typeof a}function F(a,b){if(z(b))a=a[b];else for(let c=0;a&&c<b.length;c++)a=a[b[c]];return a};const ba=/[^\p{L}\p{N}]+/u,ca=/(\d{3})/g,da=/(\D)(\d{3})/g,ea=/(\d{3})(\D)/g,G="".normalize&&/[\u0300-\u036f]/g,fa=!G&&new Map([["\u00aa","a"],["\u00b2","2"],["\u00b3","3"],["\u00b9","1"],["\u00ba","o"],["\u00bc","1\u20444"],["\u00bd","1\u20442"],["\u00be","3\u20444"],["\u00e0","a"],["\u00e1","a"],["\u00e2","a"],["\u00e3","a"],["\u00e4","a"],["\u00e5","a"],["\u00e7","c"],["\u00e8","e"],["\u00e9","e"],["\u00ea","e"],["\u00eb","e"],["\u00ec","i"],["\u00ed","i"],["\u00ee","i"],["\u00ef","i"],["\u00f1",
n[q],!g[r]){if(c)c--;else if(f[k++]=r,k===b)return f;g[r]=1}}return f}function ia(a,b){const c=z(),e=z(),d=[];for(let f=0;f<a.length;f++)c[a[f]]=1;for(let f=0,g;f<b.length;f++){g=b[f];for(let h=0,k;h<g.length;h++)k=g[h],c[k]&&!e[k]&&(e[k]=1,d[d.length]=k)}return d};const ja={memory:{charset:"latin:extra",A:3,m:4,D:!1},performance:{A:3,m:3,s:!1,context:{depth:2,A:1}},match:{charset:"latin:extra",C:"reverse"},score:{charset:"latin:advanced",A:20,m:3,context:{depth:3,A:9}},"default":{}};function P(a,b){if(!(this instanceof P))return new P(a);var c;let e;a?(C(a)?a=ja[a]:(c=a.preset)&&(a=Object.assign({},c[c],a)),c=a.charset,e=a.lang,C(c)&&(-1===c.indexOf(":")&&(c+=":default"),c=M[c]),C(e)&&(e=L[e])):a={};let d,f,g=a.context||{};this.encode=a.encode||c&&c.encode||K;this.register=b||z();this.A=d=a.resolution||9;this.C=b=c&&c.C||a.tokenize||"strict";this.depth="strict"===b&&g.depth;this.h=v(g.bidirectional);this.s=f=v(a.optimize);this.D=v(a.fastupdate);this.m=a.minlength||1;this.F=a.boost; "n"],["\u00f2","o"],["\u00f3","o"],["\u00f4","o"],["\u00f5","o"],["\u00f6","o"],["\u00f9","u"],["\u00fa","u"],["\u00fb","u"],["\u00fc","u"],["\u00fd","y"],["\u00ff","y"],["\u0101","a"],["\u0103","a"],["\u0105","a"],["\u0107","c"],["\u0109","c"],["\u010b","c"],["\u010d","c"],["\u010f","d"],["\u0113","e"],["\u0115","e"],["\u0117","e"],["\u0119","e"],["\u011b","e"],["\u011d","g"],["\u011f","g"],["\u0121","g"],["\u0123","g"],["\u0125","h"],["\u0129","i"],["\u012b","i"],["\u012d","i"],["\u012f","i"],["\u0133",
this.map=f?w(d):z();this.o=d=g.resolution||1;this.l=f?w(d):z();this.B=c&&c.B||a.rtl;this.G=(b=a.matcher||e&&e.G)&&H(b,!1);this.H=(b=a.stemmer||e&&e.H)&&H(b,!0);if(a=b=a.filter||e&&e.filter){a=b;c=z();for(let h=0,k=a.length;h<k;h++)c[a[h]]=1;a=c}this.filter=a}t=P.prototype;t.append=function(a,b){return this.add(a,b,!0)}; "ij"],["\u0135","j"],["\u0137","k"],["\u013a","l"],["\u013c","l"],["\u013e","l"],["\u0140","l"],["\u0144","n"],["\u0146","n"],["\u0148","n"],["\u0149","n"],["\u014d","o"],["\u014f","o"],["\u0151","o"],["\u0155","r"],["\u0157","r"],["\u0159","r"],["\u015b","s"],["\u015d","s"],["\u015f","s"],["\u0161","s"],["\u0163","t"],["\u0165","t"],["\u0169","u"],["\u016b","u"],["\u016d","u"],["\u016f","u"],["\u0171","u"],["\u0173","u"],["\u0175","w"],["\u0177","y"],["\u017a","z"],["\u017c","z"],["\u017e","z"],
t.add=function(a,b,c,e){if(b&&(a||0===a)){if(!e&&!c&&this.register[a])return this.update(a,b);b=this.encode(b);if(e=b.length){const m=z(),n=z(),u=this.depth,q=this.A;for(let r=0;r<e;r++){let l=b[this.B?e-1-r:r];var d=l.length;if(l&&d>=this.m&&(u||!n[l])){var f=Q(q,e,r),g="";switch(this.C){case "full":if(2<d){for(f=0;f<d;f++)for(var h=d;h>f;h--)if(h-f>=this.m){var k=Q(q,e,r,d,f);g=l.substring(f,h);S(this,n,g,k,a,c)}break}case "reverse":if(1<d){for(h=d-1;0<h;h--)g=l[h]+g,g.length>=this.m&&S(this,n, ["\u017f","s"],["\u01a1","o"],["\u01b0","u"],["\u01c6","dz"],["\u01c9","lj"],["\u01cc","nj"],["\u01ce","a"],["\u01d0","i"],["\u01d2","o"],["\u01d4","u"],["\u01d6","u"],["\u01d8","u"],["\u01da","u"],["\u01dc","u"],["\u01df","a"],["\u01e1","a"],["\u01e3","ae"],["\u00e6","ae"],["\u01fd","ae"],["\u01e7","g"],["\u01e9","k"],["\u01eb","o"],["\u01ed","o"],["\u01ef","\u0292"],["\u01f0","j"],["\u01f3","dz"],["\u01f5","g"],["\u01f9","n"],["\u01fb","a"],["\u01ff","\u00f8"],["\u0201","a"],["\u0203","a"],["\u0205",
g,Q(q,e,r,d,h),a,c);g=""}case "forward":if(1<d){for(h=0;h<d;h++)g+=l[h],g.length>=this.m&&S(this,n,g,f,a,c);break}default:if(this.F&&(f=Math.min(f/this.F(b,l,r)|0,q-1)),S(this,n,l,f,a,c),u&&1<e&&r<e-1)for(d=z(),g=this.o,f=l,h=Math.min(u+1,e-r),d[f]=1,k=1;k<h;k++)if((l=b[this.B?e-1-r-k:r+k])&&l.length>=this.m&&!d[l]){d[l]=1;const p=this.h&&l>f;S(this,m,p?f:l,Q(g+(e/2>g?0:1),e,r,h-1,k-1),a,c,p?l:f)}}}}this.D||(this.register[a]=1)}}return this}; "e"],["\u0207","e"],["\u0209","i"],["\u020b","i"],["\u020d","o"],["\u020f","o"],["\u0211","r"],["\u0213","r"],["\u0215","u"],["\u0217","u"],["\u0219","s"],["\u021b","t"],["\u021f","h"],["\u0227","a"],["\u0229","e"],["\u022b","o"],["\u022d","o"],["\u022f","o"],["\u0231","o"],["\u0233","y"],["\u02b0","h"],["\u02b1","h"],["\u0266","h"],["\u02b2","j"],["\u02b3","r"],["\u02b4","\u0279"],["\u02b5","\u027b"],["\u02b6","\u0281"],["\u02b7","w"],["\u02b8","y"],["\u02e0","\u0263"],["\u02e1","l"],["\u02e2","s"],
function Q(a,b,c,e,d){return c&&1<a?b+(e||0)<=a?c+(d||0):(a-1)/(b+(e||0))*(c+(d||0))+1|0:0}function S(a,b,c,e,d,f,g){let h=g?a.l:a.map;if(!b[c]||g&&!b[c][g])a.s&&(h=h[e]),g?(b=b[c]||(b[c]=z()),b[g]=1,h=h[g]||(h[g]=z())):b[c]=1,h=h[c]||(h[c]=[]),a.s||(h=h[e]||(h[e]=[])),f&&h.includes(d)||(h[h.length]=d,a.D&&(a=a.register[d]||(a.register[d]=[]),a[a.length]=h))} ["\u02e3","x"],["\u02e4","\u0295"],["\u0390","\u03b9"],["\u03ac","\u03b1"],["\u03ad","\u03b5"],["\u03ae","\u03b7"],["\u03af","\u03b9"],["\u03b0","\u03c5"],["\u03ca","\u03b9"],["\u03cb","\u03c5"],["\u03cc","\u03bf"],["\u03cd","\u03c5"],["\u03ce","\u03c9"],["\u03d0","\u03b2"],["\u03d1","\u03b8"],["\u03d2","\u03a5"],["\u03d3","\u03a5"],["\u03d4","\u03a5"],["\u03d5","\u03c6"],["\u03d6","\u03c0"],["\u03f0","\u03ba"],["\u03f1","\u03c1"],["\u03f2","\u03c2"],["\u03f5","\u03b5"],["\u0439","\u0438"],["\u0450",
t.search=function(a,b,c){c||(!b&&D(a)?(c=a,a=c.query):D(b)&&(c=b));let e=[],d;let f,g=0;if(c){a=c.query||a;b=c.limit;g=c.offset||0;var h=c.context;f=c.suggest}if(a&&(a=this.encode(""+a),d=a.length,1<d)){c=z();var k=[];for(let n=0,u=0,q;n<d;n++)if((q=a[n])&&q.length>=this.m&&!c[q])if(this.s||f||this.map[q])k[u++]=q,c[q]=1;else return e;a=k;d=a.length}if(!d)return e;b||(b=100);h=this.depth&&1<d&&!1!==h;c=0;let m;h?(m=a[0],c=1):1<d&&a.sort(aa);for(let n,u;c<d;c++){u=a[c];h?(n=ka(this,e,f,b,g,2===d,u, "\u0435"],["\u0451","\u0435"],["\u0453","\u0433"],["\u0457","\u0456"],["\u045c","\u043a"],["\u045d","\u0438"],["\u045e","\u0443"],["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]]);
m),f&&!1===n&&e.length||(m=u)):n=ka(this,e,f,b,g,1===d,u);if(n)return n;if(f&&c===d-1){k=e.length;if(!k){if(h){h=0;c=-1;continue}return e}if(1===k)return la(e[0],b,g)}}return fa(e,b,g,f)}; function H(a={}){if(!(this instanceof H))return new H(...arguments);for(a=0;a<arguments.length;a++)this.assign(arguments[a])}
function ka(a,b,c,e,d,f,g,h){let k=[],m=h?a.l:a.map;a.s||(m=ma(m,g,h,a.h));if(m){let n=0;const u=Math.min(m.length,h?a.o:a.A);for(let q=0,r=0,l,p;q<u;q++)if(l=m[q])if(a.s&&(l=ma(l,g,h,a.h)),d&&l&&f&&(p=l.length,p<=d?(d-=p,l=null):(l=l.slice(d),d=0)),l&&(k[n++]=l,f&&(r+=l.length,r>=e)))break;if(n){if(f)return la(k,e,0);b[b.length]=k;return}}return!c&&k}function la(a,b,c){a=1===a.length?a[0]:[].concat.apply([],a);return c||a.length>b?a.slice(c,c+b):a} H.prototype.assign=function(a){this.normalize=x(a.normalize,!0,this.normalize);let b=a.aa,c=b||a.ga||a.split;if("object"===typeof c){let e=!b,d="";a.aa||(d+="\\p{Z}");c.fa&&(d+="\\p{L}");c.ha&&(d+="\\p{N}",e=!!b);c.ja&&(d+="\\p{S}");c.ia&&(d+="\\p{P}");c.control&&(d+="\\p{C}");if(c=c.char)d+="object"===typeof c?c.join(""):c;this.split=new RegExp("["+(b?"^":"")+d+"]+","u");this.numeric=e}else this.split=x(c,ba,this.split),this.numeric=x(this.numeric,!0);this.X=x(a.X,null,this.X);this.S=x(a.S,null,
function ma(a,b,c,e){c?(e=e&&b>c,a=(a=a[e?b:c])&&a[e?c:b]):a=a[b];return a}t.contain=function(a){return!!this.register[a]};t.update=function(a,b){return this.remove(a).add(a,b)};t.remove=function(a,b){const c=this.register[a];if(c){if(this.D)for(let e=0,d;e<c.length;e++)d=c[e],d.splice(d.indexOf(a),1);else T(this.map,a,this.A,this.s),this.depth&&T(this.l,a,this.o,this.s);b||delete this.register[a]}return this}; this.S);this.rtl=a.rtl||!1;this.C=x(a.C,!0,this.C);this.filter=x((c=a.filter)&&new Set(c),null,this.filter);this.H=x((c=a.H)&&new Map(c),null,this.H);this.D=x((c=a.D)&&new Map(c),null,this.D);this.L=x((c=a.L)&&new Map(c),null,this.L);this.I=x(a.I,null,this.I);this.W=x(a.W,1,this.W);this.ba=x(a.ba,0,this.ba);if(this.cache=c=x(a.cache,!0,this.cache))this.U=null,this.$="number"===typeof c?c:2E5,this.N=new Map,this.R=new Map,this.B=this.h=128;this.F="";this.Y=null;this.V="";this.Z=null;if(this.H)for(const e of this.H.keys())this.F+=
function T(a,b,c,e,d){let f=0;if(a.constructor===Array)if(d)b=a.indexOf(b),-1!==b?1<a.length&&(a.splice(b,1),f++):f++;else{d=Math.min(a.length,c);for(let g=0,h;g<d;g++)if(h=a[g])f=T(h,b,c,e,d),e||f||delete a[g]}else for(let g in a)(f=T(a[g],b,c,e,d))||delete a[g];return f}ea(P.prototype);function U(a){if(!(this instanceof U))return new U(a);var b=a.document||a.doc||a,c;this.F=[];this.h=[];this.o=[];this.register=z();this.key=(c=b.key||b.id)&&V(c,this.o)||"id";this.D=v(a.fastupdate);this.l=(c=b.store)&&!0!==c&&[];this.store=c&&z();this.async=!1;c=z();let e=b.index||b.field||b;C(e)&&(e=[e]);for(let d=0,f,g;d<e.length;d++)f=e[d],C(f)||(g=f,f=f.field),g=D(g)?Object.assign({},a,g):a,this.I||(c[f]=new P(g,this.register)),this.F[d]=V(f,this.o),this.h[d]=f;if(this.l)for(a=b.store,C(a)&&(a= (this.F?"|":"")+e;if(this.L)for(const e of this.L.keys())this.V+=(this.V?"|":"")+e;return this};
[a]),b=0;b<a.length;b++)this.l[b]=V(a[b],this.o);this.index=c}function V(a,b){const c=a.split(":");let e=0;for(let d=0;d<c.length;d++)a=c[d],0<=a.indexOf("[]")&&(a=a.substring(0,a.length-2))&&(b[e]=!0),a&&(c[e++]=a);e<c.length&&(c.length=e);return 1<e?c:c[0]}function na(a,b){if(C(b))a=a[b];else for(let c=0;a&&c<b.length;c++)a=a[b[c]];return a} H.prototype.encode=function(a){if(this.cache&&a.length<=this.h)if(this.U){if(this.N.has(a))return this.N.get(a)}else this.U=setTimeout(ha,0,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):G?a=a.normalize("NFKD").replace(G,"").toLowerCase():(a=a.toLowerCase(),this.D=this.D?new Map([...fa,...this.D]):new Map(fa)));this.X&&(a=this.X(a));this.numeric&&3<a.length&&(a=a.replace(da,"$1 $2").replace(ea,"$1 $2").replace(ca,"$1 "));const b=!(this.C||this.D||this.filter||this.H||
function W(a,b,c,e,d){a=a[d];if(e===c.length-1)b[d]=a;else if(a)if(a.constructor===Array)for(b=b[d]=Array(a.length),d=0;d<a.length;d++)W(a,b,c,e,d);else b=b[d]||(b[d]=z()),d=c[++e],W(a,b,c,e,d)}function X(a,b,c,e,d,f,g,h){if(a=a[g])if(e===b.length-1){if(a.constructor===Array){if(c[e]){for(b=0;b<a.length;b++)d.add(f,a[b],!0,!0);return}a=a.join(" ")}d.add(f,a,h,!0)}else if(a.constructor===Array)for(g=0;g<a.length;g++)X(a,b,c,e,d,f,g,h);else g=b[++e],X(a,b,c,e,d,f,g,h)}t=U.prototype; this.L||this.I);let c=[],e=this.split||""===this.split?a.split(this.split):a;for(let f=0,g,h;f<e.length;f++){if(!(g=h=e[f]))continue;if(g.length<this.W)continue;if(b){c.push(g);continue}if(this.filter&&this.filter.has(g))continue;if(this.cache&&g.length<=this.B)if(this.U){var d=this.R.get(g);if(d||""===d){d&&c.push(d);continue}}else this.U=setTimeout(ha,0,this);let k;this.L&&2<g.length&&(this.Z||(this.Z=new RegExp("(?!^)("+this.V+")$")),g=g.replace(this.Z,m=>this.L.get(m)),k=1);this.H&&1<g.length&&
t.add=function(a,b,c){D(a)&&(b=a,a=na(b,this.key));if(b&&(a||0===a)){if(!c&&this.register[a])return this.update(a,b);for(let e=0,d,f;e<this.h.length;e++)f=this.h[e],d=this.F[e],C(d)&&(d=[d]),X(b,d,this.o,0,this.index[f],a,d[0],c);if(this.store&&(!c||!this.store[a])){let e;if(this.l){e=z();for(let d=0,f;d<this.l.length;d++)f=this.l[d],C(f)?e[f]=b[f]:W(b,e,f,0,f[0])}this.store[a]=e||b}}return this};t.append=function(a,b){return this.add(a,b,!0)};t.update=function(a,b){return this.remove(a).add(a,b)}; (this.Y||(this.Y=new RegExp("("+this.F+")","g")),g=g.replace(this.Y,m=>this.H.get(m)),k=1);g&&k&&(g.length<this.W||this.filter&&this.filter.has(g))&&(g="");if(g&&(this.D||this.C&&1<g.length)){d="";for(let m=0,l="",r,t;m<g.length;m++)r=g.charAt(m),r===l&&this.C||((t=this.D&&this.D.get(r))||""===t?t===l&&this.C||!(l=t)||(d+=t):d+=l=r);g=d}if(g&&this.I)for(d=0;g&&d<this.I.length;d+=2)g=g.replace(this.I[d],this.I[d+1]);this.cache&&h.length<=this.B&&(this.R.set(h,g),this.R.size>this.$&&(this.R.clear(),
t.remove=function(a){D(a)&&(a=na(a,this.key));if(this.register[a]){for(let b=0;b<this.h.length&&(this.index[this.h[b]].remove(a,!this.I),!this.D);b++);this.store&&delete this.store[a];delete this.register[a]}return this}; this.B=this.B/1.1|0));g&&c.push(g)}this.S&&(c=this.S(c)||c);this.cache&&a.length<=this.h&&(this.N.set(a,c),this.N.size>this.$&&(this.N.clear(),this.h=this.h/1.1|0));return c};function ha(a){a.U=null;a.N.clear();a.R.clear()};function ia(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let e=this.cache.get(a);if(!e){e=this.search(a,b,c);if(e instanceof Promise){const d=this;e.then(function(f){d.cache.set(a,f)})}this.cache.set(a,e)}return e}function I(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}I.prototype.set=function(a,b){this.cache.has(a)||(this.cache.set(this.h=a,b),this.limit&&this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value))};
t.search=function(a,b,c,e){c||(!b&&D(a)?(c=a,a=""):D(b)&&(c=b,b=0));let d=[],f=[],g,h,k,m,n,u,q=0;if(c)if(c.constructor===Array)k=c,c=null;else{a=c.query||a;k=(g=c.pluck)||c.index||c.field;m=!1;h=this.store&&c.enrich;n="and"===c.bool;b=c.limit||b||100;u=c.offset||0;if(m&&(C(m)&&(m=[m]),!a)){for(let l=0,p;l<m.length;l++)if(p=oa.call(this,m[l],b,u,h))d[d.length]=p,q++;return q?d:[]}C(k)&&(k=[k])}k||(k=this.h);n=n&&(1<k.length||m&&1<m.length);const r=!e&&(this.I||this.async)&&[];for(let l=0,p,A,B;l< I.prototype.get=function(a){const b=this.cache.get(a);b&&this.limit&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};I.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};I.prototype.clear=function(){this.cache.clear();this.h=""};function J(a=8){if(!(this instanceof J))return new J(a);this.index=y();this.F=[];this.size=0;32<a?(this.h=ja,this.B=BigInt(a)):(this.h=ka,this.B=a)}J.prototype.get=function(a){const b=this.index[this.h(a)];return b&&b.get(a)};J.prototype.set=function(a,b){var c=this.h(a);let e=this.index[c];e?(c=e.size,e.set(a,b),(c-=e.size)&&this.size++):(this.index[c]=e=new Map([[a,b]]),this.F.push(e))};
k.length;l++){let y;A=k[l];C(A)||(y=A,A=y.field,a=y.query||a,b=y.limit||b,h=y.enrich||h);if(r)r[l]=this.index[A].searchAsync(a,b,y||c);else{e?p=e[l]:p=this.index[A].search(a,b,y||c);B=p&&p.length;if(m&&B){const x=[];let G=0;n&&(x[0]=[p]);for(let R=0,ha,N;R<m.length;R++)if(ha=m[R],B=(N=this.J[ha])&&N.length)G++,x[x.length]=n?[N]:N;G&&(p=n?fa(x,b||100,u||0):ia(p,x),B=p.length)}if(B)f[q]=A,d[q++]=p;else if(n)return[]}}if(r){const l=this;return new Promise(function(p){Promise.all(r).then(function(A){p(l.search(a, function L(a=8){if(!(this instanceof L))return new L(a);this.index=y();this.h=[];32<a?(this.F=ja,this.B=BigInt(a)):(this.F=ka,this.B=a)}L.prototype.add=function(a){var b=this.F(a);let c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.h.push(c))};u=J.prototype;u.has=L.prototype.has=function(a){const b=this.index[this.F(a)];return b&&b.has(a)};u.delete=L.prototype.delete=function(a){const b=this.index[this.F(a)];b&&b.delete(a)&&this.size--};
b,c,A))})})}if(!q)return[];if(g&&(!h||!this.store))return d[0];for(let l=0,p;l<f.length;l++){p=d[l];p.length&&h&&(p=pa.call(this,p));if(g)return p;d[l]={field:f[l],result:p}}return d};function oa(a,b,c,e){let d=this.J[a],f=d&&d.length-c;if(f&&0<f){if(f>b||c)d=d.slice(c,c+b);e&&(d=pa.call(this,d));return{tag:a,result:d}}}function pa(a){const b=Array(a.length);for(let c=0,e;c<a.length;c++)e=a[c],b[c]={id:e,doc:this.store[e]};return b}t.contain=function(a){return!!this.register[a]};t.get=function(a){return this.store[a]}; u.clear=L.prototype.clear=function(){this.index=y();this.h=[];this.size=0};u.values=L.prototype.values=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].values())yield b};u.keys=L.prototype.keys=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].keys())yield b};u.entries=L.prototype.entries=function*(){for(let a=0;a<this.h.length;a++)for(let b of this.h[a].entries())yield b};
t.set=function(a,b){this.store[a]=b;return this};ea(U.prototype);var ra={encode:qa,B:!1,C:""};const sa=[I("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",I("[\u00e8\u00e9\u00ea\u00eb]"),"e",I("[\u00ec\u00ed\u00ee\u00ef]"),"i",I("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",I("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",I("[\u00fd\u0177\u00ff]"),"y",I("\u00f1"),"n",I("[\u00e7c]"),"k",I("\u00df"),"s",I(" & ")," and "];function qa(a){var b=a=""+a;b.normalize&&(b=b.normalize("NFD").replace(ca,""));return E.call(this,b.toLowerCase(),!a.normalize&&sa)};var ua={encode:ta,B:!1,C:"strict"};const va=/[^a-z0-9]+/,wa={b:"p",v:"f",w:"f",z:"s",x:"s","\u00df":"s",d:"t",n:"m",c:"k",g:"k",j:"k",q:"k",i:"e",y:"e",u:"o"};function ta(a){a=qa.call(this,a).join(" ");const b=[];if(a){const c=a.split(va),e=c.length;for(let d=0,f,g=0;d<e;d++)if((a=c[d])&&(!this.filter||!this.filter[a])){f=a[0];let h=wa[f]||f,k=h;for(let m=1;m<a.length;m++){f=a[m];const n=wa[f]||f;n&&n!==k&&(h+=n,k=n)}b[g++]=h}}return b};var ya={encode:xa,B:!1,C:""};const za=[I("ae"),"a",I("oe"),"o",I("sh"),"s",I("th"),"t",I("ph"),"f",I("pf"),"f",I("(?![aeo])h(?![aeo])"),"",I("(?!^[aeo])h(?!^[aeo])"),""];function xa(a,b){a&&(a=ta.call(this,a).join(" "),2<a.length&&(a=F(a,za)),b||(1<a.length&&(a=J(a)),a&&(a=a.split(" "))));return a||[]};var Ba={encode:Aa,B:!1,C:""};const Ca=I("(?!\\b)[aeo]");function Aa(a){a&&(a=xa.call(this,a,!0),1<a.length&&(a=a.replace(Ca,"")),1<a.length&&(a=J(a)),a&&(a=a.split(" ")));return a||[]};M["latin:default"]=da;M["latin:simple"]=ra;M["latin:balance"]=ua;M["latin:advanced"]=ya;M["latin:extra"]=Ba;const Y={Index:P,Document:U,Worker:null,registerCharset:function(a,b){M[a]=b},registerLanguage:function(a,b){L[a]=b}};let Z;(Z=self.define)&&Z.amd?Z([],function(){return Y}):self.exports?self.exports=Y:self.FlexSearch=Y;}(this)); function ka(a){let b=2**this.B-1;if("number"==typeof a)return a&b;let c=0,e=this.B+1;for(let d=0;d<a.length;d++)c=(c*e^a.charCodeAt(d))&b;return 32===this.B?c+2**31:c}function ja(a){let b=BigInt(2)**this.B-BigInt(1);var c=typeof a;if("bigint"===c)return a&b;if("number"===c)return BigInt(a)&b;c=BigInt(0);let e=this.B+BigInt(1);for(let d=0;d<a.length;d++)c=(c*e^BigInt(a.charCodeAt(d)))&b;return c};function la(a,b,c,e,d,f,g,h){(e=a(c?c+"."+e:e,JSON.stringify(g)))&&e.then?e.then(function(){b.export(a,b,c,d,f+1,h)}):b.export(a,b,c,d,f+1,h)};const ma=y(),M=y();var na={normalize:function(a){return a.toLowerCase()},C:!1};const oa={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};function pa(a){N.call(a,"add");N.call(a,"append");N.call(a,"search");N.call(a,"update");N.call(a,"remove")}function N(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);this.async=!0;b=this[a].apply(this,b);this.async=!1;b.then?b.then(e):e(b);return b}};y();O.prototype.add=function(a,b,c,e){if(b&&(a||0===a)){if(!e&&!c&&this.A.has(a))return this.update(a,b);b=this.encoder.encode(b);if(e=b.length){const m=y(),l=y(),r=this.depth,t=this.resolution;for(let p=0;p<e;p++){let n=b[this.rtl?e-1-p:p];var d=n.length;if(d&&(r||!l[n])){var f=this.score?this.score(b,n,p,null,0):P(t,e,p),g="";switch(this.tokenize){case "full":if(2<d){for(f=0;f<d;f++)for(var h=d;h>f;h--){g=n.substring(f,h);var k=this.score?this.score(b,n,p,g,f):P(t,e,p,d,f);Q(this,l,g,k,a,c)}break}case "reverse":if(1<
d){for(h=d-1;0<h;h--)g=n[h]+g,k=this.score?this.score(b,n,p,g,h):P(t,e,p,d,h),Q(this,l,g,k,a,c);g=""}case "forward":if(1<d){for(h=0;h<d;h++)g+=n[h],Q(this,l,g,f,a,c);break}default:if(Q(this,l,n,f,a,c),r&&1<e&&p<e-1)for(d=y(),g=this.ca,f=n,h=Math.min(r+1,e-p),d[f]=1,k=1;k<h;k++)if((n=b[this.rtl?e-1-p-k:p+k])&&!d[n]){d[n]=1;const v=this.score?this.score(b,f,p,n,k):P(g+(e/2>g?0:1),e,p,h-1,k-1),C=this.bidirectional&&n>f;Q(this,m,C?f:n,v,a,c,C?n:f)}}}}this.fastupdate||this.A.add(a)}}return this};
function Q(a,b,c,e,d,f,g){let h=g?a.K:a.map,k;b[c]&&g&&(k=b[c])[g]||(g?(b=k||(b[c]=y()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((b=a.A.get(d))?b.push(h):a.A.set(d,[h]))))}function P(a,b,c,e,d){return c&&1<a?b+(e||0)<=a?c+(d||0):(a-1)/(b+(e||0))*(c+(d||0))+1|0:0};function R(a,b,c){if(1===a.length)return a=a[0],a=c||a.length>b?b?a.slice(c,c+b):a.slice(c):a;let e=[];for(let d=0,f,g;d<a.length;d++)if((f=a[d])&&(g=f.length)){if(c){if(c>=g){c-=g;continue}c<g&&(f=b?f.slice(c,c+b):f.slice(c),g=f.length,c=0)}if(e.length)g>b&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),f;e=[f]}b-=g;if(!b)break}return e.length?e=1<e.length?[].concat.apply([],e):e[0]:e};function qa(a,b,c,e){var d=a.length;let f=[],g=0,h,k,m;e&&(e=[]);for(let l=d-1,r;0<=l;l--){m=a[l];d=y();r=!h;for(let t=0,p;t<m.length;t++)if((p=m[t])&&p.length)for(let n=0,v;n<p.length;n++)if(v=p[n],h){if(h[v]){if(!l)if(c)c--;else if(f[g++]=v,g===b)return f;if(l||e)d[v]=1;r=!0}e&&!k[v]&&(k[v]=1,(e[t]||(e[t]=[])).push(v))}else d[v]=1;if(e)h||(k=d);else if(!r)return[];h=d}if(e)for(let l=e.length-1,r,t;0<=l;l--){r=e[l];t=r.length;for(let p=0,n;p<t;p++)if(n=r[p],!h[n]){if(c)c--;else if(f[g++]=n,g===b)return f;
h[n]=1}}return f}function ra(a,b){const c=y(),e=y(),d=[];for(let f=0;f<a.length;f++)c[a[f]]=1;for(let f=0,g;f<b.length;f++){g=b[f];for(let h=0,k;h<g.length;h++)k=g[h],c[k]&&!e[k]&&(e[k]=1,d.push(k))}return d};O.prototype.search=function(a,b,c){c||(!b&&B(a)?(c=a,a=""):B(b)&&(c=b,b=0));let e=[];let d,f=0;if(c){a=c.query||a;b=c.limit||b;f=c.offset||0;var g=c.context;d=c.suggest}a=this.encoder.encode(a);c=a.length;b||(b=100);if(1===c)return T.call(this,a[0],"",b,f);g=this.depth&&!1!==g;if(2===c&&g&&!d)return T.call(this,a[0],a[1],b,f);let h=0,k=0;if(1<c){var m=y();const r=[];for(let t=0,p;t<c;t++)if((p=a[t])&&!m[p]){if(d||U(this,p))r.push(p),m[p]=1;else return e;const n=p.length;h=Math.max(h,n);k=k?Math.min(k,
n):n}a=r;c=a.length}if(!c)return e;m=0;let l;if(1===c)return T.call(this,a[0],"",b,f);if(2===c&&g&&!d)return T.call(this,a[0],a[1],b,f);1<c&&(g?(l=a[0],m=1):9<h&&3<h/k&&a.sort(aa));for(let r,t;m<c;m++){t=a[m];l?(r=U(this,t,l),r=sa(r,e,d,this.ca,b,f,2===c),d&&!1===r&&e.length||(l=t)):(r=U(this,t),r=sa(r,e,d,this.resolution,b,f,1===c));if(r)return r;if(d&&m===c-1){g=e.length;if(!g){if(l){l="";m=-1;continue}return e}if(1===g)return R(e[0],b,f)}}return qa(e,b,f,d)};
function T(a,b,c,e){return(a=U(this,a,b))&&a.length?R(a,c,e):[]}function sa(a,b,c,e,d,f,g){let h=[];if(a){e=Math.min(a.length,e);for(let k=0,m=0,l;k<e;k++)if(l=a[k])if(f&&l&&g&&(l.length<=f?(f-=l.length,l=null):(l=l.slice(f),f=0)),l&&(h[k]=l,g&&(m+=l.length,m>=d)))break;if(h.length){if(g)return R(h,d,0);b.push(h);return}}return!c&&h}function U(a,b,c){let e;c&&(e=a.bidirectional&&b>c);a=c?(a=a.K.get(e?b:c))&&a.get(e?c:b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.A.size&&(this.fastupdate?this.A.get(a):this.A.has(a));if(c){if(this.fastupdate)for(let e=0,d;e<c.length;e++){if(d=c[e])if(2>d.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else V(this.map,a),this.depth&&V(this.K,a);b||this.A.delete(a)}this.cache&&this.cache.remove(a);return this};
function V(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;e<a.length;e++){if((d=a[e])&&d.length)if(f=d.indexOf(b),0<=f){1<d.length?(d.splice(f,1),c++):delete a[e];break}else c++}else for(let e of a){const d=e[0],f=V(e[1],b);f?c+=f:a.delete(d)}return c};function O(a,b){if(!(this instanceof O))return new O(a);if(a){var c=z(a)?a:a.preset;c&&(a=Object.assign({},oa[c],a))}else a={};c=a.context||{};const e=a.encode||a.encoder||na;this.encoder=e.encode?e:"object"===typeof e?new H(e):{encode:e};let d;this.resolution=a.resolution||9;this.tokenize=d=a.tokenize||"strict";this.depth="strict"===d&&c.depth||0;this.bidirectional=!1!==c.bidirectional;this.fastupdate=!!a.fastupdate;this.score=a.score||null;this.map=(d=!1,new Map);this.K=d?new J(d):new Map;this.A=
b||(this.fastupdate?d?new J(d):new Map:d?new L(d):new Set);this.ca=c.resolution||1;this.rtl=e.rtl||a.rtl||!1;this.cache=(d=a.cache||null)&&new I(d)}u=O.prototype;u.clear=function(){this.map.clear();this.K.clear();this.A.clear();this.cache&&this.cache.clear();return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.A.has(a)};
u.update=function(a,b){if(this.async){const c=this,e=this.remove(a);return e.then?e.then(()=>c.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)};function W(a){let b=0;if(a.constructor===Array)for(let c=0,e;c<a.length;c++)(e=a[c])&&(b+=e.length);else for(const c of a){const e=c[0],d=W(c[1]);d?b+=d:a.delete(e)}return b}u.cleanup=function(){if(!this.fastupdate)return this;W(this.map);this.depth&&W(this.K);return this};u.searchCache=ia;
u.export=function(a,b,c,e,d,f){let g=!0;"undefined"===typeof f&&(g=new Promise(m=>{f=m}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let m of this.A.keys())k[m]=1}else k=this.A;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.K;break;default:"undefined"===typeof c&&f&&f();return}la(a,b||this,c,h,e,d,k,f);return g};
u.import=function(a,b){if(b)switch(z(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.A=b;break;case "map":this.map=b;break;case "ctx":this.K=b}};pa(O.prototype);X.prototype.add=function(a,b,c){B(a)&&(b=a,a=F(b,this.key));if(b&&(a||0===a)){if(!c&&this.A.has(a))return this.update(a,b);for(let h=0,k;h<this.field.length;h++){k=this.M[h];var e=this.index.get(this.field[h]);if("function"===typeof k){var d=k(b);d&&e.add(a,d,!1,!0)}else if(d=k.P,!d||d(b))k instanceof String?k=[""+k]:z(k)&&(k=[k]),ta(b,k,this.T,0,e,a,k[0],c)}if(this.tag)for(e=0;e<this.J.length;e++){var f=this.J[e];d=this.tag.get(this.da[e]);let h=y();if("function"===typeof f){if(f=f(b),!f)continue}else{var g=
f.P;if(g&&!g(b))continue;f instanceof String&&(f=""+f);f=F(b,f)}if(d&&f){z(f)&&(f=[f]);for(let k=0,m,l;k<f.length;k++)m=f[k],h[m]||(h[m]=1,(g=d.get(m))?l=g:d.set(m,l=[]),c&&l.includes(a)||(l.push(a),this.fastupdate&&((g=this.A.get(a))?g.push(l):this.A.set(a,[l]))))}}if(this.store&&(!c||!this.store.has(a))){let h;if(this.G){h=y();for(let k=0,m;k<this.G.length;k++){m=this.G[k];if((c=m.P)&&!c(b))continue;let l;if("function"===typeof m){l=m(b);if(!l)continue;m=[m.ea]}else if(z(m)||m instanceof String){h[m]=
b[m];continue}ua(b,h,m,0,m[0],l)}}this.store.set(a,h||b)}}return this};function ua(a,b,c,e,d,f){a=a[d];if(e===c.length-1)b[d]=f||a;else if(a)if(a.constructor===Array)for(b=b[d]=Array(a.length),d=0;d<a.length;d++)ua(a,b,c,e,d);else b=b[d]||(b[d]=y()),d=c[++e],ua(a,b,c,e,d)}
function ta(a,b,c,e,d,f,g,h){if(a=a[g])if(e===b.length-1){if(a.constructor===Array){if(c[e]){for(b=0;b<a.length;b++)d.add(f,a[b],!0,!0);return}a=a.join(" ")}d.add(f,a,h,!0)}else if(a.constructor===Array)for(g=0;g<a.length;g++)ta(a,b,c,e,d,f,g,h);else g=b[++e],ta(a,b,c,e,d,f,g,h)};X.prototype.search=function(a,b,c,e){c||(!b&&B(a)?(c=a,a=""):B(b)&&(c=b,b=0));let d=[];var f=[];let g,h,k,m,l;let r=0;if(c)if(c.constructor===Array)m=c,c=null;else{a=c.query||a;var t=c.pluck;h=c.merge;m=t||c.field||c.index;l=this.tag&&c.tag;g=this.store&&c.enrich;k=c.suggest;b=c.limit||b;var p=c.offset||0;b||(b=100);if(l){l.constructor!==Array&&(l=[l]);var n=[];for(let w=0,q;w<l.length;w++)if(q=l[w],q.field&&q.tag){var v=q.tag;if(v.constructor===Array)for(var C=0;C<v.length;C++)n.push(q.field,v[C]);
else n.push(q.field,v)}else{v=Object.keys(q);for(let D=0,E,A;D<v.length;D++)if(E=v[D],A=q[E],A.constructor===Array)for(C=0;C<A.length;C++)n.push(E,A[C]);else n.push(E,A)}l=n;if(!a){e=[];if(n.length)for(f=0;f<n.length;f+=2)t=va.call(this,n[f],n[f+1],b,p,g),d.push({field:n[f],tag:n[f+1],result:t});return e.length?Promise.all(e).then(function(w){for(let q=0;q<w.length;q++)d[q].result=w[q];return d}):d}}z(m)&&(m=[m])}m||(m=this.field);p=!e&&(this.worker||this.async)&&[];for(let w=0,q,D,E;w<m.length;w++){D=
m[w];let A;z(D)||(A=D,D=A.field,a=A.query||a,b=A.limit||b,k=A.suggest||k);if(e)q=e[w];else if(n=A||c,v=this.index.get(D),l&&(n.enrich=!1),p){p[w]=v.searchAsync(a,b,n);n&&g&&(n.enrich=g);continue}else q=v.search(a,b,n),n&&g&&(n.enrich=g);E=q&&q.length;if(l&&E){n=[];v=0;for(let S=0,K,Da;S<l.length;S+=2){K=this.tag.get(l[S]);if(!K)if(k)continue;else return d;if(Da=(K=K&&K.get(l[S+1]))&&K.length)v++,n.push(K);else if(!k)return d}if(v){q=ra(q,n);E=q.length;if(!E&&!k)return d;v--}}if(E)f[r]=D,d.push(q),
r++;else if(1===m.length)return d}if(p){const w=this;return Promise.all(p).then(function(q){return q.length?w.search(a,b,c,q):q})}if(!r)return d;if(t&&(!g||!this.store))return d[0];p=[];for(let w=0,q;w<f.length;w++){q=d[w];g&&q.length&&!q[0].doc&&q.length&&(q=wa.call(this,q));if(t)return q;d[w]={field:f[w],result:q}}return h?xa(d,b):d};
function xa(a,b){const c=[],e=y();for(let d=0,f,g;d<a.length;d++){f=a[d];g=f.result;for(let h=0,k,m,l;h<g.length;h++)if(m=g[h],k=m.id,l=e[k])l.push(f.field);else{if(c.length===b)return c;m.field=e[k]=[f.field];c.push(m)}}return c}function va(a,b,c,e,d){a=this.tag.get(a);if(!a)return[];if((b=(a=a&&a.get(b))&&a.length-e)&&0<b){if(b>c||e)a=a.slice(e,e+c);d&&(a=wa.call(this,a));return a}}
function wa(a){const b=Array(a.length);for(let c=0,e;c<a.length;c++)e=a[c],b[c]={id:e,doc:this.store.get(e)};return b};function X(a){if(!(this instanceof X))return new X(a);const b=a.document||a.doc||a;var c;this.M=[];this.field=[];this.T=[];this.key=(c=b.key||b.id)&&Y(c,this.T)||"id";this.A=(this.fastupdate=!!a.fastupdate)?new Map:new Set;this.G=(c=b.store||null)&&!0!==c&&[];this.store=c&&new Map;this.cache=(c=a.cache||null)&&new I(c);this.async=a.cache=!1;c=new Map;let e=b.index||b.field||b;z(e)&&(e=[e]);for(let d=0,f,g;d<e.length;d++)f=e[d],z(f)||(g=f,f=f.field),g=B(g)?Object.assign({},a,g):a,c.set(f,new O(g,this.A)),
g.O?this.M[d]=g.O:(this.M[d]=Y(f,this.T),g.filter&&("string"===typeof this.M[d]&&(this.M[d]=new String(this.M[d])),this.M[d].P=g.filter)),this.field[d]=f;if(this.G){a=b.store;z(a)&&(a=[a]);for(let d=0,f,g;d<a.length;d++)f=a[d],g=f.field||f,f.O?(this.G[d]=f.O,f.O.ea=g):(this.G[d]=Y(g,this.T),f.filter&&("string"===typeof this.G[d]&&(this.G[d]=new String(this.G[d])),this.G[d].P=f.filter))}this.index=c;this.tag=null;if(c=b.tag)if("string"===typeof c&&(c=[c]),c.length){this.tag=new Map;this.J=[];this.da=
[];for(let d=0,f,g;d<c.length;d++){f=c[d];g=f.field||f;if(!g)throw Error("The tag field from the document descriptor is undefined.");f.O?this.J[d]=f.O:(this.J[d]=Y(g,this.T),f.filter&&("string"===typeof this.J[d]&&(this.J[d]=new String(this.J[d])),this.J[d].P=f.filter));this.da[d]=g;this.tag.set(g,new Map)}}}
function Y(a,b){const c=a.split(":");let e=0;for(let d=0;d<c.length;d++)a=c[d],"]"===a[a.length-1]&&(a=a.substring(0,a.length-2))&&(b[e]=!0),a&&(c[e++]=a);e<c.length&&(c.length=e);return 1<e?c:c[0]}u=X.prototype;u.append=function(a,b){return this.add(a,b,!0)};u.update=function(a,b){return this.remove(a).add(a,b)};
u.remove=function(a){B(a)&&(a=F(a,this.key));for(var b of this.index.values())b.remove(a,!0);if(this.A.has(a)){if(this.tag&&!this.fastupdate)for(let c of this.tag.values())for(let e of c){b=e[0];const d=e[1],f=d.indexOf(a);-1<f&&(1<d.length?d.splice(f,1):c.delete(b))}this.store&&this.store.delete(a);this.A.delete(a)}this.cache&&this.cache.remove(a);return this};
u.clear=function(){for(const a of this.index.values())a.clear();if(this.tag)for(const a of this.tag.values())a.clear();this.store&&this.store.clear();return this};u.contain=function(a){return this.A.has(a)};u.cleanup=function(){for(const a of this.index.values())a.cleanup();return this};u.get=function(a){return this.store.get(a)};u.set=function(a,b){this.store.set(a,b);return this};u.searchCache=ia;
u.export=function(a,b,c,e,d,f){let g;"undefined"===typeof f&&(g=new Promise(k=>{f=k}));d||(d=0);e||(e=0);if(e<this.field.length){c=this.field[e];var h=this.index[c];b=this;h.export(a,b,d?c:"",e,d++,f)||(e++,b.export(a,b,c,e,1,f))}else{switch(d){case 1:b="tag";h=this.B;c=null;break;case 2:b="store";h=this.store;c=null;break;default:f();return}la(a,this,c,b,e,d,h,f)}return g};
u.import=function(a,b){if(b)switch(z(b)&&(b=JSON.parse(b)),a){case "tag":this.B=b;break;case "reg":this.fastupdate=!1;this.A=b;for(let e=0,d;e<this.field.length;e++)d=this.index[this.field[e]],d.A=b,d.fastupdate=!1;break;case "store":this.store=b;break;default:a=a.split(".");const c=a[0];a=a[1];c&&a&&this.index[c].import(a,b)}};pa(X.prototype);const ya=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var za={normalize:!0,C:!0,D:ya};const Aa=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Ba=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var Ca={normalize:!0,C:!0,D:ya,I:Ba,H:Aa};var Ea={normalize:!0,C:!0,D:ya,I:Ba.concat([/(?!^)[aeoy]/g,""]),H:Aa};const Fa={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};M["latin:exact"]={normalize:!1,C:!1};M["latin:default"]=na;M["latin:simple"]={normalize:!0,C:!0};M["latin:balance"]=za;M["latin:advanced"]=Ca;M["latin:extra"]=Ea;M["latin:soundex"]={normalize:!0,C:!1,aa:{fa:!0},S:function(a){for(let c=0;c<a.length;c++){var b=a[c];let e=b.charAt(0),d=Fa[e];for(let f=1,g;f<b.length&&(g=b.charAt(f),"h"===g||"w"===g||!(g=Fa[g])||g===d||(e+=g,d=g,4!==e.length));f++);a[c]=e}}};
const Ga={Index:O,Encoder:H,Charset:M,Language:ma,Document:X,Worker:null,Resolver:null,IndexedDB:null},Z=self;let Ha;(Ha=Z.define)&&Ha.amd?Ha([],function(){return Ga}):"object"===typeof Z.exports?Z.exports=Ga:Z.FlexSearch=Ga;}(this));

File diff suppressed because it is too large Load Diff

View File

@@ -1,27 +1,48 @@
/**! /**!
* FlexSearch.js v0.7.41 (Compact.module) * FlexSearch.js v0.8.0 (Bundle)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function(self){'use strict';var t;function v(a){return"undefined"!==typeof a?a:!0}function w(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=z();return b}function z(){return Object.create(null)}function aa(a,b){return b.length-a.length}function C(a){return"string"===typeof a}function D(a){return"object"===typeof a};function E(a,b){var c=ba;if(a&&(b&&(a=F(a,b)),this.G&&(a=F(a,this.G)),this.H&&1<a.length&&(a=F(a,this.H)),c||""===c)){b=a.split(c);if(this.filter){a=this.filter;c=b.length;const e=[];for(let d=0,f=0;d<c;d++){const g=b[d];g&&!a[g]&&(e[f++]=g)}a=e}else a=b;return a}return a}const ba=/[\p{Z}\p{S}\p{P}\p{C}]+/u,ca=/[\u0300-\u036f]/g; var u;function x(a,b,c){const e=typeof c,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(c){if("function"===d&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return"undefined"===d?b:a}function y(){return Object.create(null)}function aa(a,b){return b.length-a.length}
function H(a,b){const c=Object.keys(a),e=c.length,d=[];let f="",g=0;for(let h=0,k,m;h<e;h++)k=c[h],(m=a[k])?(d[g++]=I(b?"(?!\\b)"+k+"(\\b|_)":k),d[g++]=m):f+=(f?"|":"")+k;f&&(d[g++]=I(b?"(?!\\b)("+f+")(\\b|_)":"("+f+")"),d[g]="");return d}function F(a,b){for(let c=0,e=b.length;c<e&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a}function I(a){return new RegExp(a,"g")}function J(a){let b="",c="";for(let e=0,d=a.length,f;e<d;e++)(f=a[e])!==c&&(b+=c=f);return b};var da={encode:K,B:!1,C:""};function K(a){return E.call(this,(""+a).toLowerCase(),!1)};const L={},M={};function O(a){P(a,"add");P(a,"append");P(a,"search");P(a,"update");P(a,"remove")}function P(a,b){a[b+"Async"]=function(){const c=this,e=arguments;var d=e[e.length-1];let f;"function"===typeof d&&(f=d,delete e[e.length-1]);d=new Promise(function(g){setTimeout(function(){c.async=!0;const h=c[b].apply(c,e);c.async=!1;g(h)})});return f?(d.then(f),this):d}};function Q(a,b,c,e){const d=a.length;let f=[],g,h,k=0;e&&(e=[]);for(let m=d-1;0<=m;m--){const n=a[m],u=n.length,q=z();let r=!g;for(let l=0;l<u;l++){const p=n[l],A=p.length;if(A)for(let B=0,y,x;B<A;B++)if(x=p[B],g){if(g[x]){if(!m)if(c)c--;else if(f[k++]=x,k===b)return f;if(m||e)q[x]=1;r=!0}if(e&&(y=(h[x]||0)+1,h[x]=y,y<d)){const G=e[y-2]||(e[y-2]=[]);G[G.length]=x}}else q[x]=1}if(e)g||(h=q);else if(!r)return[];g=q}if(e)for(let m=e.length-1,n,u;0<=m;m--){n=e[m];u=n.length;for(let q=0,r;q<u;q++)if(r= function A(a){return"string"===typeof a}function B(a){return"object"===typeof a}function ba(a,b){if(A(b))a=a[b];else for(let c=0;a&&c<b.length;c++)a=a[b[c]];return a};const ca=/[^\p{L}\p{N}]+/u,da=/(\d{3})/g,ea=/(\D)(\d{3})/g,fa=/(\d{3})(\D)/g,F="".normalize&&/[\u0300-\u036f]/g,ha=!F&&new Map([["\u00aa","a"],["\u00b2","2"],["\u00b3","3"],["\u00b9","1"],["\u00ba","o"],["\u00bc","1\u20444"],["\u00bd","1\u20442"],["\u00be","3\u20444"],["\u00e0","a"],["\u00e1","a"],["\u00e2","a"],["\u00e3","a"],["\u00e4","a"],["\u00e5","a"],["\u00e7","c"],["\u00e8","e"],["\u00e9","e"],["\u00ea","e"],["\u00eb","e"],["\u00ec","i"],["\u00ed","i"],["\u00ee","i"],["\u00ef","i"],["\u00f1",
n[q],!g[r]){if(c)c--;else if(f[k++]=r,k===b)return f;g[r]=1}}return f}function fa(a,b){const c=z(),e=z(),d=[];for(let f=0;f<a.length;f++)c[a[f]]=1;for(let f=0,g;f<b.length;f++){g=b[f];for(let h=0,k;h<g.length;h++)k=g[h],c[k]&&!e[k]&&(e[k]=1,d[d.length]=k)}return d};const ha={memory:{charset:"latin:extra",A:3,m:4,D:!1},performance:{A:3,m:3,s:!1,context:{depth:2,A:1}},match:{charset:"latin:extra",C:"reverse"},score:{charset:"latin:advanced",A:20,m:3,context:{depth:3,A:9}},"default":{}};function S(a,b){if(!(this instanceof S))return new S(a);var c;let e;a?(C(a)?a=ha[a]:(c=a.preset)&&(a=Object.assign({},c[c],a)),c=a.charset,e=a.lang,C(c)&&(-1===c.indexOf(":")&&(c+=":default"),c=M[c]),C(e)&&(e=L[e])):a={};let d,f,g=a.context||{};this.encode=a.encode||c&&c.encode||K;this.register=b||z();this.A=d=a.resolution||9;this.C=b=c&&c.C||a.tokenize||"strict";this.depth="strict"===b&&g.depth;this.h=v(g.bidirectional);this.s=f=v(a.optimize);this.D=v(a.fastupdate);this.m=a.minlength||1;this.F=a.boost; "n"],["\u00f2","o"],["\u00f3","o"],["\u00f4","o"],["\u00f5","o"],["\u00f6","o"],["\u00f9","u"],["\u00fa","u"],["\u00fb","u"],["\u00fc","u"],["\u00fd","y"],["\u00ff","y"],["\u0101","a"],["\u0103","a"],["\u0105","a"],["\u0107","c"],["\u0109","c"],["\u010b","c"],["\u010d","c"],["\u010f","d"],["\u0113","e"],["\u0115","e"],["\u0117","e"],["\u0119","e"],["\u011b","e"],["\u011d","g"],["\u011f","g"],["\u0121","g"],["\u0123","g"],["\u0125","h"],["\u0129","i"],["\u012b","i"],["\u012d","i"],["\u012f","i"],["\u0133",
this.map=f?w(d):z();this.o=d=g.resolution||1;this.l=f?w(d):z();this.B=c&&c.B||a.rtl;this.G=(b=a.matcher||e&&e.G)&&H(b,!1);this.H=(b=a.stemmer||e&&e.H)&&H(b,!0);if(a=b=a.filter||e&&e.filter){a=b;c=z();for(let h=0,k=a.length;h<k;h++)c[a[h]]=1;a=c}this.filter=a}t=S.prototype;t.append=function(a,b){return this.add(a,b,!0)}; "ij"],["\u0135","j"],["\u0137","k"],["\u013a","l"],["\u013c","l"],["\u013e","l"],["\u0140","l"],["\u0144","n"],["\u0146","n"],["\u0148","n"],["\u0149","n"],["\u014d","o"],["\u014f","o"],["\u0151","o"],["\u0155","r"],["\u0157","r"],["\u0159","r"],["\u015b","s"],["\u015d","s"],["\u015f","s"],["\u0161","s"],["\u0163","t"],["\u0165","t"],["\u0169","u"],["\u016b","u"],["\u016d","u"],["\u016f","u"],["\u0171","u"],["\u0173","u"],["\u0175","w"],["\u0177","y"],["\u017a","z"],["\u017c","z"],["\u017e","z"],
t.add=function(a,b,c,e){if(b&&(a||0===a)){if(!e&&!c&&this.register[a])return this.update(a,b);b=this.encode(b);if(e=b.length){const m=z(),n=z(),u=this.depth,q=this.A;for(let r=0;r<e;r++){let l=b[this.B?e-1-r:r];var d=l.length;if(l&&d>=this.m&&(u||!n[l])){var f=T(q,e,r),g="";switch(this.C){case "full":if(2<d){for(f=0;f<d;f++)for(var h=d;h>f;h--)if(h-f>=this.m){var k=T(q,e,r,d,f);g=l.substring(f,h);U(this,n,g,k,a,c)}break}case "reverse":if(1<d){for(h=d-1;0<h;h--)g=l[h]+g,g.length>=this.m&&U(this,n, ["\u017f","s"],["\u01a1","o"],["\u01b0","u"],["\u01c6","dz"],["\u01c9","lj"],["\u01cc","nj"],["\u01ce","a"],["\u01d0","i"],["\u01d2","o"],["\u01d4","u"],["\u01d6","u"],["\u01d8","u"],["\u01da","u"],["\u01dc","u"],["\u01df","a"],["\u01e1","a"],["\u01e3","ae"],["\u00e6","ae"],["\u01fd","ae"],["\u01e7","g"],["\u01e9","k"],["\u01eb","o"],["\u01ed","o"],["\u01ef","\u0292"],["\u01f0","j"],["\u01f3","dz"],["\u01f5","g"],["\u01f9","n"],["\u01fb","a"],["\u01ff","\u00f8"],["\u0201","a"],["\u0203","a"],["\u0205",
g,T(q,e,r,d,h),a,c);g=""}case "forward":if(1<d){for(h=0;h<d;h++)g+=l[h],g.length>=this.m&&U(this,n,g,f,a,c);break}default:if(this.F&&(f=Math.min(f/this.F(b,l,r)|0,q-1)),U(this,n,l,f,a,c),u&&1<e&&r<e-1)for(d=z(),g=this.o,f=l,h=Math.min(u+1,e-r),d[f]=1,k=1;k<h;k++)if((l=b[this.B?e-1-r-k:r+k])&&l.length>=this.m&&!d[l]){d[l]=1;const p=this.h&&l>f;U(this,m,p?f:l,T(g+(e/2>g?0:1),e,r,h-1,k-1),a,c,p?l:f)}}}}this.D||(this.register[a]=1)}}return this}; "e"],["\u0207","e"],["\u0209","i"],["\u020b","i"],["\u020d","o"],["\u020f","o"],["\u0211","r"],["\u0213","r"],["\u0215","u"],["\u0217","u"],["\u0219","s"],["\u021b","t"],["\u021f","h"],["\u0227","a"],["\u0229","e"],["\u022b","o"],["\u022d","o"],["\u022f","o"],["\u0231","o"],["\u0233","y"],["\u02b0","h"],["\u02b1","h"],["\u0266","h"],["\u02b2","j"],["\u02b3","r"],["\u02b4","\u0279"],["\u02b5","\u027b"],["\u02b6","\u0281"],["\u02b7","w"],["\u02b8","y"],["\u02e0","\u0263"],["\u02e1","l"],["\u02e2","s"],
function T(a,b,c,e,d){return c&&1<a?b+(e||0)<=a?c+(d||0):(a-1)/(b+(e||0))*(c+(d||0))+1|0:0}function U(a,b,c,e,d,f,g){let h=g?a.l:a.map;if(!b[c]||g&&!b[c][g])a.s&&(h=h[e]),g?(b=b[c]||(b[c]=z()),b[g]=1,h=h[g]||(h[g]=z())):b[c]=1,h=h[c]||(h[c]=[]),a.s||(h=h[e]||(h[e]=[])),f&&h.includes(d)||(h[h.length]=d,a.D&&(a=a.register[d]||(a.register[d]=[]),a[a.length]=h))} ["\u02e3","x"],["\u02e4","\u0295"],["\u0390","\u03b9"],["\u03ac","\u03b1"],["\u03ad","\u03b5"],["\u03ae","\u03b7"],["\u03af","\u03b9"],["\u03b0","\u03c5"],["\u03ca","\u03b9"],["\u03cb","\u03c5"],["\u03cc","\u03bf"],["\u03cd","\u03c5"],["\u03ce","\u03c9"],["\u03d0","\u03b2"],["\u03d1","\u03b8"],["\u03d2","\u03a5"],["\u03d3","\u03a5"],["\u03d4","\u03a5"],["\u03d5","\u03c6"],["\u03d6","\u03c0"],["\u03f0","\u03ba"],["\u03f1","\u03c1"],["\u03f2","\u03c2"],["\u03f5","\u03b5"],["\u0439","\u0438"],["\u0450",
t.search=function(a,b,c){c||(!b&&D(a)?(c=a,a=c.query):D(b)&&(c=b));let e=[],d;let f,g=0;if(c){a=c.query||a;b=c.limit;g=c.offset||0;var h=c.context;f=c.suggest}if(a&&(a=this.encode(""+a),d=a.length,1<d)){c=z();var k=[];for(let n=0,u=0,q;n<d;n++)if((q=a[n])&&q.length>=this.m&&!c[q])if(this.s||f||this.map[q])k[u++]=q,c[q]=1;else return e;a=k;d=a.length}if(!d)return e;b||(b=100);h=this.depth&&1<d&&!1!==h;c=0;let m;h?(m=a[0],c=1):1<d&&a.sort(aa);for(let n,u;c<d;c++){u=a[c];h?(n=ia(this,e,f,b,g,2===d,u, "\u0435"],["\u0451","\u0435"],["\u0453","\u0433"],["\u0457","\u0456"],["\u045c","\u043a"],["\u045d","\u0438"],["\u045e","\u0443"],["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]]);
m),f&&!1===n&&e.length||(m=u)):n=ia(this,e,f,b,g,1===d,u);if(n)return n;if(f&&c===d-1){k=e.length;if(!k){if(h){h=0;c=-1;continue}return e}if(1===k)return ja(e[0],b,g)}}return Q(e,b,g,f)}; function G(a={}){if(!(this instanceof G))return new G(...arguments);for(a=0;a<arguments.length;a++)this.assign(arguments[a])}
function ia(a,b,c,e,d,f,g,h){let k=[],m=h?a.l:a.map;a.s||(m=ka(m,g,h,a.h));if(m){let n=0;const u=Math.min(m.length,h?a.o:a.A);for(let q=0,r=0,l,p;q<u;q++)if(l=m[q])if(a.s&&(l=ka(l,g,h,a.h)),d&&l&&f&&(p=l.length,p<=d?(d-=p,l=null):(l=l.slice(d),d=0)),l&&(k[n++]=l,f&&(r+=l.length,r>=e)))break;if(n){if(f)return ja(k,e,0);b[b.length]=k;return}}return!c&&k}function ja(a,b,c){a=1===a.length?a[0]:[].concat.apply([],a);return c||a.length>b?a.slice(c,c+b):a} G.prototype.assign=function(a){this.normalize=x(a.normalize,!0,this.normalize);let b=a.U,c=b||a.Z||a.split;if("object"===typeof c){let e=!b,d="";a.U||(d+="\\p{Z}");c.Y&&(d+="\\p{L}");c.$&&(d+="\\p{N}",e=!!b);c.ba&&(d+="\\p{S}");c.aa&&(d+="\\p{P}");c.control&&(d+="\\p{C}");if(c=c.char)d+="object"===typeof c?c.join(""):c;this.split=new RegExp("["+(b?"^":"")+d+"]+","u");this.numeric=e}else this.split=x(c,ca,this.split),this.numeric=x(this.numeric,!0);this.R=x(a.R,null,this.R);this.M=x(a.M,null,this.M);
function ka(a,b,c,e){c?(e=e&&b>c,a=(a=a[e?b:c])&&a[e?c:b]):a=a[b];return a}t.contain=function(a){return!!this.register[a]};t.update=function(a,b){return this.remove(a).add(a,b)};t.remove=function(a,b){const c=this.register[a];if(c){if(this.D)for(let e=0,d;e<c.length;e++)d=c[e],d.splice(d.indexOf(a),1);else V(this.map,a,this.A,this.s),this.depth&&V(this.l,a,this.o,this.s);b||delete this.register[a]}return this}; this.rtl=a.rtl||!1;this.C=x(a.C,!0,this.C);this.filter=x((c=a.filter)&&new Set(c),null,this.filter);this.H=x((c=a.H)&&new Map(c),null,this.H);this.D=x((c=a.D)&&new Map(c),null,this.D);this.K=x((c=a.K)&&new Map(c),null,this.K);this.I=x(a.I,null,this.I);this.P=x(a.P,1,this.P);this.V=x(a.V,0,this.V);this.A="";this.F=null;this.B="";this.S=null;if(this.H)for(const e of this.H.keys())this.A+=(this.A?"|":"")+e;if(this.K)for(const e of this.K.keys())this.B+=(this.B?"|":"")+e;return this};
function V(a,b,c,e,d){let f=0;if(a.constructor===Array)if(d)b=a.indexOf(b),-1!==b?1<a.length&&(a.splice(b,1),f++):f++;else{d=Math.min(a.length,c);for(let g=0,h;g<d;g++)if(h=a[g])f=V(h,b,c,e,d),e||f||delete a[g]}else for(let g in a)(f=V(a[g],b,c,e,d))||delete a[g];return f}O(S.prototype);function W(a){if(!(this instanceof W))return new W(a);var b=a.document||a.doc||a,c;this.F=[];this.h=[];this.o=[];this.register=z();this.key=(c=b.key||b.id)&&X(c,this.o)||"id";this.D=v(a.fastupdate);this.l=(c=b.store)&&!0!==c&&[];this.store=c&&z();this.async=!1;c=z();let e=b.index||b.field||b;C(e)&&(e=[e]);for(let d=0,f,g;d<e.length;d++)f=e[d],C(f)||(g=f,f=f.field),g=D(g)?Object.assign({},a,g):a,this.I||(c[f]=new S(g,this.register)),this.F[d]=X(f,this.o),this.h[d]=f;if(this.l)for(a=b.store,C(a)&&(a= G.prototype.encode=function(a){this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):F?a=a.normalize("NFKD").replace(F,"").toLowerCase():(a=a.toLowerCase(),this.D=this.D?new Map([...ha,...this.D]):new Map(ha)));this.R&&(a=this.R(a));this.numeric&&3<a.length&&(a=a.replace(ea,"$1 $2").replace(fa,"$1 $2").replace(da,"$1 "));const b=!(this.C||this.D||this.filter||this.H||this.K||this.I);let c=[];a=this.split||""===this.split?a.split(this.split):a;for(let d=0,f;d<a.length;d++){if(!(f=
[a]),b=0;b<a.length;b++)this.l[b]=X(a[b],this.o);this.index=c}function X(a,b){const c=a.split(":");let e=0;for(let d=0;d<c.length;d++)a=c[d],0<=a.indexOf("[]")&&(a=a.substring(0,a.length-2))&&(b[e]=!0),a&&(c[e++]=a);e<c.length&&(c.length=e);return 1<e?c:c[0]}function la(a,b){if(C(b))a=a[b];else for(let c=0;a&&c<b.length;c++)a=a[b[c]];return a} a[d]))continue;if(f.length<this.P)continue;if(b){c.push(f);continue}if(this.filter&&this.filter.has(f))continue;let g;this.K&&2<f.length&&(this.S||(this.S=new RegExp("(?!^)("+this.B+")$")),f=f.replace(this.S,h=>this.K.get(h)),g=1);this.H&&1<f.length&&(this.F||(this.F=new RegExp("("+this.A+")","g")),f=f.replace(this.F,h=>this.H.get(h)),g=1);f&&g&&(f.length<this.P||this.filter&&this.filter.has(f))&&(f="");if(f&&(this.D||this.C&&1<f.length)){var e="";for(let h=0,k="",n,l;h<f.length;h++)n=f.charAt(h),
function Y(a,b,c,e,d){a=a[d];if(e===c.length-1)b[d]=a;else if(a)if(a.constructor===Array)for(b=b[d]=Array(a.length),d=0;d<a.length;d++)Y(a,b,c,e,d);else b=b[d]||(b[d]=z()),d=c[++e],Y(a,b,c,e,d)}function Z(a,b,c,e,d,f,g,h){if(a=a[g])if(e===b.length-1){if(a.constructor===Array){if(c[e]){for(b=0;b<a.length;b++)d.add(f,a[b],!0,!0);return}a=a.join(" ")}d.add(f,a,h,!0)}else if(a.constructor===Array)for(g=0;g<a.length;g++)Z(a,b,c,e,d,f,g,h);else g=b[++e],Z(a,b,c,e,d,f,g,h)}t=W.prototype; n===k&&this.C||((l=this.D&&this.D.get(n))||""===l?l===k&&this.C||!(k=l)||(e+=l):e+=k=n);f=e}if(f&&this.I)for(e=0;f&&e<this.I.length;e+=2)f=f.replace(this.I[e],this.I[e+1]);f&&c.push(f)}this.M&&(c=this.M(c)||c);return c};function H(a=8){if(!(this instanceof H))return new H(a);this.index=y();this.F=[];this.size=0;32<a?(this.A=ia,this.B=BigInt(a)):(this.A=ja,this.B=a)}H.prototype.get=function(a){const b=this.index[this.A(a)];return b&&b.get(a)};H.prototype.set=function(a,b){var c=this.A(a);let e=this.index[c];e?(c=e.size,e.set(a,b),(c-=e.size)&&this.size++):(this.index[c]=e=new Map([[a,b]]),this.F.push(e))};
t.add=function(a,b,c){D(a)&&(b=a,a=la(b,this.key));if(b&&(a||0===a)){if(!c&&this.register[a])return this.update(a,b);for(let e=0,d,f;e<this.h.length;e++)f=this.h[e],d=this.F[e],C(d)&&(d=[d]),Z(b,d,this.o,0,this.index[f],a,d[0],c);if(this.store&&(!c||!this.store[a])){let e;if(this.l){e=z();for(let d=0,f;d<this.l.length;d++)f=this.l[d],C(f)?e[f]=b[f]:Y(b,e,f,0,f[0])}this.store[a]=e||b}}return this};t.append=function(a,b){return this.add(a,b,!0)};t.update=function(a,b){return this.remove(a).add(a,b)}; function I(a=8){if(!(this instanceof I))return new I(a);this.index=y();this.A=[];32<a?(this.F=ia,this.B=BigInt(a)):(this.F=ja,this.B=a)}I.prototype.add=function(a){var b=this.F(a);let c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.A.push(c))};u=H.prototype;u.has=I.prototype.has=function(a){const b=this.index[this.F(a)];return b&&b.has(a)};u.delete=I.prototype.delete=function(a){const b=this.index[this.F(a)];b&&b.delete(a)&&this.size--};
t.remove=function(a){D(a)&&(a=la(a,this.key));if(this.register[a]){for(let b=0;b<this.h.length&&(this.index[this.h[b]].remove(a,!this.I),!this.D);b++);this.store&&delete this.store[a];delete this.register[a]}return this}; u.clear=I.prototype.clear=function(){this.index=y();this.A=[];this.size=0};u.values=I.prototype.values=function*(){for(let a=0;a<this.A.length;a++)for(let b of this.A[a].values())yield b};u.keys=I.prototype.keys=function*(){for(let a=0;a<this.A.length;a++)for(let b of this.A[a].keys())yield b};u.entries=I.prototype.entries=function*(){for(let a=0;a<this.A.length;a++)for(let b of this.A[a].entries())yield b};
t.search=function(a,b,c,e){c||(!b&&D(a)?(c=a,a=""):D(b)&&(c=b,b=0));let d=[],f=[],g,h,k,m,n,u,q=0;if(c)if(c.constructor===Array)k=c,c=null;else{a=c.query||a;k=(g=c.pluck)||c.index||c.field;m=!1;h=this.store&&c.enrich;n="and"===c.bool;b=c.limit||b||100;u=c.offset||0;if(m&&(C(m)&&(m=[m]),!a)){for(let l=0,p;l<m.length;l++)if(p=ma.call(this,m[l],b,u,h))d[d.length]=p,q++;return q?d:[]}C(k)&&(k=[k])}k||(k=this.h);n=n&&(1<k.length||m&&1<m.length);const r=!e&&(this.I||this.async)&&[];for(let l=0,p,A,B;l< function ja(a){let b=2**this.B-1;if("number"==typeof a)return a&b;let c=0,e=this.B+1;for(let d=0;d<a.length;d++)c=(c*e^a.charCodeAt(d))&b;return 32===this.B?c+2**31:c}function ia(a){let b=BigInt(2)**this.B-BigInt(1);var c=typeof a;if("bigint"===c)return a&b;if("number"===c)return BigInt(a)&b;c=BigInt(0);let e=this.B+BigInt(1);for(let d=0;d<a.length;d++)c=(c*e^BigInt(a.charCodeAt(d)))&b;return c};function ka(a,b,c,e,d,f,g,h){(e=a(c?c+"."+e:e,JSON.stringify(g)))&&e.then?e.then(function(){b.export(a,b,c,d,f+1,h)}):b.export(a,b,c,d,f+1,h)};const la=y(),J=y();var ma={normalize:function(a){return a.toLowerCase()},C:!1};const na={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};function oa(a){L.call(a,"add");L.call(a,"append");L.call(a,"search");L.call(a,"update");L.call(a,"remove")}function L(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);this.async=!0;b=this[a].apply(this,b);this.async=!1;b.then?b.then(e):e(b);return b}};y();M.prototype.add=function(a,b,c,e){if(b&&(a||0===a)){if(!e&&!c&&this.h.has(a))return this.update(a,b);b=this.encoder.encode(b);if(e=b.length){const n=y(),l=y(),r=this.depth,t=this.resolution;for(let p=0;p<e;p++){let m=b[this.rtl?e-1-p:p];var d=m.length;if(d&&(r||!l[m])){var f=this.score?this.score(b,m,p,null,0):N(t,e,p),g="";switch(this.tokenize){case "full":if(2<d){for(f=0;f<d;f++)for(var h=d;h>f;h--){g=m.substring(f,h);var k=this.score?this.score(b,m,p,g,f):N(t,e,p,d,f);O(this,l,g,k,a,c)}break}case "reverse":if(1<
k.length;l++){let y;A=k[l];C(A)||(y=A,A=y.field,a=y.query||a,b=y.limit||b,h=y.enrich||h);if(r)r[l]=this.index[A].searchAsync(a,b,y||c);else{e?p=e[l]:p=this.index[A].search(a,b,y||c);B=p&&p.length;if(m&&B){const x=[];let G=0;n&&(x[0]=[p]);for(let R=0,ea,N;R<m.length;R++)if(ea=m[R],B=(N=this.J[ea])&&N.length)G++,x[x.length]=n?[N]:N;G&&(p=n?Q(x,b||100,u||0):fa(p,x),B=p.length)}if(B)f[q]=A,d[q++]=p;else if(n)return[]}}if(r){const l=this;return new Promise(function(p){Promise.all(r).then(function(A){p(l.search(a, d){for(h=d-1;0<h;h--)g=m[h]+g,k=this.score?this.score(b,m,p,g,h):N(t,e,p,d,h),O(this,l,g,k,a,c);g=""}case "forward":if(1<d){for(h=0;h<d;h++)g+=m[h],O(this,l,g,f,a,c);break}default:if(O(this,l,m,f,a,c),r&&1<e&&p<e-1)for(d=y(),g=this.W,f=m,h=Math.min(r+1,e-p),d[f]=1,k=1;k<h;k++)if((m=b[this.rtl?e-1-p-k:p+k])&&!d[m]){d[m]=1;const v=this.score?this.score(b,f,p,m,k):N(g+(e/2>g?0:1),e,p,h-1,k-1),C=this.bidirectional&&m>f;O(this,n,C?f:m,v,a,c,C?m:f)}}}}this.fastupdate||this.h.add(a)}}return this};
b,c,A))})})}if(!q)return[];if(g&&(!h||!this.store))return d[0];for(let l=0,p;l<f.length;l++){p=d[l];p.length&&h&&(p=na.call(this,p));if(g)return p;d[l]={field:f[l],result:p}}return d};function ma(a,b,c,e){let d=this.J[a],f=d&&d.length-c;if(f&&0<f){if(f>b||c)d=d.slice(c,c+b);e&&(d=na.call(this,d));return{tag:a,result:d}}}function na(a){const b=Array(a.length);for(let c=0,e;c<a.length;c++)e=a[c],b[c]={id:e,doc:this.store[e]};return b}t.contain=function(a){return!!this.register[a]};t.get=function(a){return this.store[a]}; function O(a,b,c,e,d,f,g){let h=g?a.J:a.map,k;b[c]&&g&&(k=b[c])[g]||(g?(b=k||(b[c]=y()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((b=a.h.get(d))?b.push(h):a.h.set(d,[h]))))}function N(a,b,c,e,d){return c&&1<a?b+(e||0)<=a?c+(d||0):(a-1)/(b+(e||0))*(c+(d||0))+1|0:0};function P(a,b,c){if(1===a.length)return a=a[0],a=c||a.length>b?b?a.slice(c,c+b):a.slice(c):a;let e=[];for(let d=0,f,g;d<a.length;d++)if((f=a[d])&&(g=f.length)){if(c){if(c>=g){c-=g;continue}c<g&&(f=b?f.slice(c,c+b):f.slice(c),g=f.length,c=0)}if(e.length)g>b&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),f;e=[f]}b-=g;if(!b)break}return e.length?e=1<e.length?[].concat.apply([],e):e[0]:e};function pa(a,b,c,e){var d=a.length;let f=[],g=0,h,k,n;e&&(e=[]);for(let l=d-1,r;0<=l;l--){n=a[l];d=y();r=!h;for(let t=0,p;t<n.length;t++)if((p=n[t])&&p.length)for(let m=0,v;m<p.length;m++)if(v=p[m],h){if(h[v]){if(!l)if(c)c--;else if(f[g++]=v,g===b)return f;if(l||e)d[v]=1;r=!0}e&&!k[v]&&(k[v]=1,(e[t]||(e[t]=[])).push(v))}else d[v]=1;if(e)h||(k=d);else if(!r)return[];h=d}if(e)for(let l=e.length-1,r,t;0<=l;l--){r=e[l];t=r.length;for(let p=0,m;p<t;p++)if(m=r[p],!h[m]){if(c)c--;else if(f[g++]=m,g===b)return f;
t.set=function(a,b){this.store[a]=b;return this};O(W.prototype);var pa={encode:oa,B:!1,C:""};const qa=[I("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",I("[\u00e8\u00e9\u00ea\u00eb]"),"e",I("[\u00ec\u00ed\u00ee\u00ef]"),"i",I("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",I("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",I("[\u00fd\u0177\u00ff]"),"y",I("\u00f1"),"n",I("[\u00e7c]"),"k",I("\u00df"),"s",I(" & ")," and "];function oa(a){var b=a=""+a;b.normalize&&(b=b.normalize("NFD").replace(ca,""));return E.call(this,b.toLowerCase(),!a.normalize&&qa)};var sa={encode:ra,B:!1,C:"strict"};const ta=/[^a-z0-9]+/,ua={b:"p",v:"f",w:"f",z:"s",x:"s","\u00df":"s",d:"t",n:"m",c:"k",g:"k",j:"k",q:"k",i:"e",y:"e",u:"o"};function ra(a){a=oa.call(this,a).join(" ");const b=[];if(a){const c=a.split(ta),e=c.length;for(let d=0,f,g=0;d<e;d++)if((a=c[d])&&(!this.filter||!this.filter[a])){f=a[0];let h=ua[f]||f,k=h;for(let m=1;m<a.length;m++){f=a[m];const n=ua[f]||f;n&&n!==k&&(h+=n,k=n)}b[g++]=h}}return b};var wa={encode:va,B:!1,C:""};const xa=[I("ae"),"a",I("oe"),"o",I("sh"),"s",I("th"),"t",I("ph"),"f",I("pf"),"f",I("(?![aeo])h(?![aeo])"),"",I("(?!^[aeo])h(?!^[aeo])"),""];function va(a,b){a&&(a=ra.call(this,a).join(" "),2<a.length&&(a=F(a,xa)),b||(1<a.length&&(a=J(a)),a&&(a=a.split(" "))));return a||[]};var za={encode:ya,B:!1,C:""};const Aa=I("(?!\\b)[aeo]");function ya(a){a&&(a=va.call(this,a,!0),1<a.length&&(a=a.replace(Aa,"")),1<a.length&&(a=J(a)),a&&(a=a.split(" ")));return a||[]};M["latin:default"]=da;M["latin:simple"]=pa;M["latin:balance"]=sa;M["latin:advanced"]=wa;M["latin:extra"]=za;export default {Index:S,Document:W,Worker:null,registerCharset:function(a,b){M[a]=b},registerLanguage:function(a,b){L[a]=b}};}(this)); h[m]=1}}return f}function qa(a,b){const c=y(),e=y(),d=[];for(let f=0;f<a.length;f++)c[a[f]]=1;for(let f=0,g;f<b.length;f++){g=b[f];for(let h=0,k;h<g.length;h++)k=g[h],c[k]&&!e[k]&&(e[k]=1,d.push(k))}return d};M.prototype.search=function(a,b,c){c||(!b&&B(a)?(c=a,a=""):B(b)&&(c=b,b=0));let e=[];let d,f=0;if(c){a=c.query||a;b=c.limit||b;f=c.offset||0;var g=c.context;d=c.suggest}a=this.encoder.encode(a);c=a.length;b||(b=100);if(1===c)return Q.call(this,a[0],"",b,f);g=this.depth&&!1!==g;if(2===c&&g&&!d)return Q.call(this,a[0],a[1],b,f);let h=0,k=0;if(1<c){var n=y();const r=[];for(let t=0,p;t<c;t++)if((p=a[t])&&!n[p]){if(d||S(this,p))r.push(p),n[p]=1;else return e;const m=p.length;h=Math.max(h,m);k=k?Math.min(k,
m):m}a=r;c=a.length}if(!c)return e;n=0;let l;if(1===c)return Q.call(this,a[0],"",b,f);if(2===c&&g&&!d)return Q.call(this,a[0],a[1],b,f);1<c&&(g?(l=a[0],n=1):9<h&&3<h/k&&a.sort(aa));for(let r,t;n<c;n++){t=a[n];l?(r=S(this,t,l),r=ra(r,e,d,this.W,b,f,2===c),d&&!1===r&&e.length||(l=t)):(r=S(this,t),r=ra(r,e,d,this.resolution,b,f,1===c));if(r)return r;if(d&&n===c-1){g=e.length;if(!g){if(l){l="";n=-1;continue}return e}if(1===g)return P(e[0],b,f)}}return pa(e,b,f,d)};
function Q(a,b,c,e){return(a=S(this,a,b))&&a.length?P(a,c,e):[]}function ra(a,b,c,e,d,f,g){let h=[];if(a){e=Math.min(a.length,e);for(let k=0,n=0,l;k<e;k++)if(l=a[k])if(f&&l&&g&&(l.length<=f?(f-=l.length,l=null):(l=l.slice(f),f=0)),l&&(h[k]=l,g&&(n+=l.length,n>=d)))break;if(h.length){if(g)return P(h,d,0);b.push(h);return}}return!c&&h}function S(a,b,c){let e;c&&(e=a.bidirectional&&b>c);a=c?(a=a.J.get(e?b:c))&&a.get(e?c:b):a.map.get(b);return a};M.prototype.remove=function(a,b){const c=this.h.size&&(this.fastupdate?this.h.get(a):this.h.has(a));if(c){if(this.fastupdate)for(let e=0,d;e<c.length;e++){if(d=c[e])if(2>d.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else T(this.map,a),this.depth&&T(this.J,a);b||this.h.delete(a)}return this};
function T(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;e<a.length;e++){if((d=a[e])&&d.length)if(f=d.indexOf(b),0<=f){1<d.length?(d.splice(f,1),c++):delete a[e];break}else c++}else for(let e of a){const d=e[0],f=T(e[1],b);f?c+=f:a.delete(d)}return c};function M(a,b){if(!(this instanceof M))return new M(a);if(a){var c=A(a)?a:a.preset;c&&(a=Object.assign({},na[c],a))}else a={};c=a.context||{};const e=a.encode||a.encoder||ma;this.encoder=e.encode?e:"object"===typeof e?new G(e):{encode:e};let d;this.resolution=a.resolution||9;this.tokenize=d=a.tokenize||"strict";this.depth="strict"===d&&c.depth||0;this.bidirectional=!1!==c.bidirectional;this.fastupdate=!!a.fastupdate;this.score=a.score||null;this.map=(d=!1,new Map);this.J=d?new H(d):new Map;this.h=
b||(this.fastupdate?d?new H(d):new Map:d?new I(d):new Set);this.W=c.resolution||1;this.rtl=e.rtl||a.rtl||!1}u=M.prototype;u.clear=function(){this.map.clear();this.J.clear();this.h.clear();return this};u.append=function(a,b){return this.add(a,b,!0)};u.contain=function(a){return this.h.has(a)};u.update=function(a,b){if(this.async){const c=this,e=this.remove(a);return e.then?e.then(()=>c.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)};
function U(a){let b=0;if(a.constructor===Array)for(let c=0,e;c<a.length;c++)(e=a[c])&&(b+=e.length);else for(const c of a){const e=c[0],d=U(c[1]);d?b+=d:a.delete(e)}return b}u.cleanup=function(){if(!this.fastupdate)return this;U(this.map);this.depth&&U(this.J);return this};
u.export=function(a,b,c,e,d,f){let g=!0;"undefined"===typeof f&&(g=new Promise(n=>{f=n}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let n of this.h.keys())k[n]=1}else k=this.h;break;case 1:h="cfg";k={doc:0,opt:this.A?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.J;break;default:"undefined"===typeof c&&f&&f();return}ka(a,b||this,c,h,e,d,k,f);return g};
u.import=function(a,b){if(b)switch(A(b)&&(b=JSON.parse(b)),a){case "cfg":this.A=!!b.opt;break;case "reg":this.fastupdate=!1;this.h=b;break;case "map":this.map=b;break;case "ctx":this.J=b}};oa(M.prototype);V.prototype.add=function(a,b,c){B(a)&&(b=a,a=ba(b,this.key));if(b&&(a||0===a)){if(!c&&this.h.has(a))return this.update(a,b);for(let d=0,f;d<this.field.length;d++){f=this.L[d];const g=this.index.get(this.field[d]);if("function"===typeof f){var e=f(b);e&&g.add(a,e,!1,!0)}else if(e=f.T,!e||e(b))f instanceof String?f=[""+f]:A(f)&&(f=[f]),W(b,f,this.O,0,g,a,f[0],c)}if(this.store&&(!c||!this.store.has(a))){let d;if(this.G){d=y();for(let f=0,g;f<this.G.length;f++){g=this.G[f];if((c=g.T)&&!c(b))continue;
let h;if("function"===typeof g){h=g(b);if(!h)continue;g=[g.X]}else if(A(g)||g instanceof String){d[g]=b[g];continue}X(b,d,g,0,g[0],h)}}this.store.set(a,d||b)}}return this};function X(a,b,c,e,d,f){a=a[d];if(e===c.length-1)b[d]=f||a;else if(a)if(a.constructor===Array)for(b=b[d]=Array(a.length),d=0;d<a.length;d++)X(a,b,c,e,d);else b=b[d]||(b[d]=y()),d=c[++e],X(a,b,c,e,d)}
function W(a,b,c,e,d,f,g,h){if(a=a[g])if(e===b.length-1){if(a.constructor===Array){if(c[e]){for(b=0;b<a.length;b++)d.add(f,a[b],!0,!0);return}a=a.join(" ")}d.add(f,a,h,!0)}else if(a.constructor===Array)for(g=0;g<a.length;g++)W(a,b,c,e,d,f,g,h);else g=b[++e],W(a,b,c,e,d,f,g,h)};V.prototype.search=function(a,b,c,e){c||(!b&&B(a)?(c=a,a=""):B(b)&&(c=b,b=0));let d=[];var f=[];let g,h,k,n,l;let r=0;if(c)if(c.constructor===Array)n=c,c=null;else{a=c.query||a;var t=c.pluck;h=c.merge;n=t||c.field||c.index;l=!1;g=this.store&&c.enrich;k=c.suggest;b=c.limit||b;var p=c.offset||0;b||(b=100);if(l){l.constructor!==Array&&(l=[l]);var m=[];for(let w=0,q;w<l.length;w++)if(q=l[w],q.field&&q.tag){var v=q.tag;if(v.constructor===Array)for(var C=0;C<v.length;C++)m.push(q.field,v[C]);else m.push(q.field,
v)}else{v=Object.keys(q);for(let D=0,E,z;D<v.length;D++)if(E=v[D],z=q[E],z.constructor===Array)for(C=0;C<z.length;C++)m.push(E,z[C]);else m.push(E,z)}l=m;if(!a){e=[];if(m.length)for(f=0;f<m.length;f+=2)t=sa.call(this,m[f],m[f+1],b,p,g),d.push({field:m[f],tag:m[f+1],result:t});return e.length?Promise.all(e).then(function(w){for(let q=0;q<w.length;q++)d[q].result=w[q];return d}):d}}A(n)&&(n=[n])}n||(n=this.field);p=!e&&(this.worker||this.async)&&[];for(let w=0,q,D,E;w<n.length;w++){D=n[w];let z;A(D)||
(z=D,D=z.field,a=z.query||a,b=z.limit||b,k=z.suggest||k);if(e)q=e[w];else if(m=z||c,v=this.index.get(D),l&&(m.enrich=!1),p){p[w]=v.searchAsync(a,b,m);m&&g&&(m.enrich=g);continue}else q=v.search(a,b,m),m&&g&&(m.enrich=g);E=q&&q.length;if(l&&E){m=[];v=0;for(let R=0,K,xa;R<l.length;R+=2){K=this.tag.get(l[R]);if(!K)if(k)continue;else return d;if(xa=(K=K&&K.get(l[R+1]))&&K.length)v++,m.push(K);else if(!k)return d}if(v){q=qa(q,m);E=q.length;if(!E&&!k)return d;v--}}if(E)f[r]=D,d.push(q),r++;else if(1===
n.length)return d}if(p){const w=this;return Promise.all(p).then(function(q){return q.length?w.search(a,b,c,q):q})}if(!r)return d;if(t&&(!g||!this.store))return d[0];p=[];for(let w=0,q;w<f.length;w++){q=d[w];g&&q.length&&!q[0].doc&&q.length&&(q=ta.call(this,q));if(t)return q;d[w]={field:f[w],result:q}}return h?ua(d,b):d};
function ua(a,b){const c=[],e=y();for(let d=0,f,g;d<a.length;d++){f=a[d];g=f.result;for(let h=0,k,n,l;h<g.length;h++)if(n=g[h],k=n.id,l=e[k])l.push(f.field);else{if(c.length===b)return c;n.field=e[k]=[f.field];c.push(n)}}return c}function sa(a,b,c,e,d){a=this.tag.get(a);if(!a)return[];if((b=(a=a&&a.get(b))&&a.length-e)&&0<b){if(b>c||e)a=a.slice(e,e+c);d&&(a=ta.call(this,a));return a}}
function ta(a){const b=Array(a.length);for(let c=0,e;c<a.length;c++)e=a[c],b[c]={id:e,doc:this.store.get(e)};return b};function V(a){if(!(this instanceof V))return new V(a);const b=a.document||a.doc||a;var c;this.L=[];this.field=[];this.O=[];this.key=(c=b.key||b.id)&&Y(c,this.O)||"id";this.h=(this.fastupdate=!!a.fastupdate)?new Map:new Set;this.G=(c=b.store||null)&&!0!==c&&[];this.store=c&&new Map;this.async=!1;c=new Map;let e=b.index||b.field||b;A(e)&&(e=[e]);for(let d=0,f,g;d<e.length;d++)f=e[d],A(f)||(g=f,f=f.field),g=B(g)?Object.assign({},a,g):a,c.set(f,new M(g,this.h)),g.N?this.L[d]=g.N:(this.L[d]=Y(f,this.O),
g.filter&&("string"===typeof this.L[d]&&(this.L[d]=new String(this.L[d])),this.L[d].T=g.filter)),this.field[d]=f;if(this.G){a=b.store;A(a)&&(a=[a]);for(let d=0,f,g;d<a.length;d++)f=a[d],g=f.field||f,f.N?(this.G[d]=f.N,f.N.X=g):(this.G[d]=Y(g,this.O),f.filter&&("string"===typeof this.G[d]&&(this.G[d]=new String(this.G[d])),this.G[d].T=f.filter))}this.index=c}
function Y(a,b){const c=a.split(":");let e=0;for(let d=0;d<c.length;d++)a=c[d],"]"===a[a.length-1]&&(a=a.substring(0,a.length-2))&&(b[e]=!0),a&&(c[e++]=a);e<c.length&&(c.length=e);return 1<e?c:c[0]}u=V.prototype;u.append=function(a,b){return this.add(a,b,!0)};u.update=function(a,b){return this.remove(a).add(a,b)};u.remove=function(a){B(a)&&(a=ba(a,this.key));for(const b of this.index.values())b.remove(a,!0);this.h.has(a)&&(this.store&&this.store.delete(a),this.h.delete(a));return this};
u.clear=function(){for(const a of this.index.values())a.clear();this.store&&this.store.clear();return this};u.contain=function(a){return this.h.has(a)};u.cleanup=function(){for(const a of this.index.values())a.cleanup();return this};u.get=function(a){return this.store.get(a)};u.set=function(a,b){this.store.set(a,b);return this};
u.export=function(a,b,c,e,d,f){let g;"undefined"===typeof f&&(g=new Promise(k=>{f=k}));d||(d=0);e||(e=0);if(e<this.field.length){c=this.field[e];var h=this.index[c];b=this;h.export(a,b,d?c:"",e,d++,f)||(e++,b.export(a,b,c,e,1,f))}else{switch(d){case 1:b="tag";h=this.B;c=null;break;case 2:b="store";h=this.store;c=null;break;default:f();return}ka(a,this,c,b,e,d,h,f)}return g};
u.import=function(a,b){if(b)switch(A(b)&&(b=JSON.parse(b)),a){case "tag":this.B=b;break;case "reg":this.fastupdate=!1;this.h=b;for(let e=0,d;e<this.field.length;e++)d=this.index[this.field[e]],d.h=b,d.fastupdate=!1;break;case "store":this.store=b;break;default:a=a.split(".");const c=a[0];a=a[1];c&&a&&this.index[c].import(a,b)}};oa(V.prototype);const Z=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 va={normalize:!0,C:!0,D:Z};const wa=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),ya=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var za={normalize:!0,C:!0,D:Z,I:ya,H:wa};var Aa={normalize:!0,C:!0,D:Z,I:ya.concat([/(?!^)[aeoy]/g,""]),H:wa};const Ba={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};J["latin:exact"]={normalize:!1,C:!1};J["latin:default"]=ma;J["latin:simple"]={normalize:!0,C:!0};J["latin:balance"]=va;J["latin:advanced"]=za;J["latin:extra"]=Aa;J["latin:soundex"]={normalize:!0,C:!1,U:{Y:!0},M:function(a){for(let c=0;c<a.length;c++){var b=a[c];let e=b.charAt(0),d=Ba[e];for(let f=1,g;f<b.length&&(g=b.charAt(f),"h"===g||"w"===g||!(g=Ba[g])||g===d||(e+=g,d=g,4!==e.length));f++);a[c]=e}}};
export default {Index:M,Encoder:G,Charset:J,Language:la,Document:V,Worker:null,Resolver:null,IndexedDB:null};
export const Index=M;export const Encoder=G;export const Charset=J;export const Language=la;export const Document=V;export const Worker=null;export const Resolver=null;export const IndexedDB=null;

File diff suppressed because it is too large Load Diff

View File

@@ -1,48 +1,123 @@
/**! /**!
* FlexSearch.js v0.7.41 (Es5) * FlexSearch.js v0.8.0 (ES5)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function(self){'use strict';var t;function aa(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}var v="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a}; (function(self){'use strict';var w;function aa(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}function y(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];if(b)return b.call(a);if("number"==typeof a.length)return{next:aa(a)};throw Error(String(a)+" is not an iterable or ArrayLike");}function ba(a){if(!(a instanceof Array)){a=y(a);for(var b,c=[];!(b=a.next()).done;)c.push(b.value);a=c}return a}
function ba(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var x=ba(this);function y(a,b){if(b)a:{var c=x;a=a.split(".");for(var d=0;d<a.length-1;d++){var e=a[d];if(!(e in c))break a;c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&v(c,a,{configurable:!0,writable:!0,value:b})}} var ca="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};function da(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var z=da(this);
y("Symbol",function(a){function b(g){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new c(d+(g||"")+"_"+e++,g)}function c(g,f){this.h=g;v(this,"description",{configurable:!0,writable:!0,value:f})}if(a)return a;c.prototype.toString=function(){return this.h};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",e=0;return b}); function B(a,b){if(b)a:{var c=z;a=a.split(".");for(var d=0;d<a.length-1;d++){var e=a[d];if(!(e in c))break a;c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&ca(c,a,{configurable:!0,writable:!0,value:b})}}var ea;if("function"==typeof Object.setPrototypeOf)ea=Object.setPrototypeOf;else{var fa;a:{var ha={a:!0},ia={};try{ia.__proto__=ha;fa=ia.a;break a}catch(a){}fa=!1}ea=fa?function(a,b){a.__proto__=b;if(a.__proto__!==b)throw new TypeError(a+" is not extensible");return a}:null}var ja=ea;
y("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c<b.length;c++){var d=x[b[c]];"function"===typeof d&&"function"!=typeof d.prototype[a]&&v(d.prototype,a,{configurable:!0,writable:!0,value:function(){return ca(aa(this))}})}return a});function ca(a){a={next:a};a[Symbol.iterator]=function(){return this};return a} function ka(){this.D=!1;this.A=null;this.G=void 0;this.h=1;this.R=0;this.C=null}function la(a){if(a.D)throw new TypeError("Generator is already running");a.D=!0}ka.prototype.K=function(a){this.G=a};function ma(a,b){a.C={Ca:b,Da:!0};a.h=a.R}ka.prototype.return=function(a){this.C={return:a};this.h=this.R};function F(a,b,c){a.h=c;return{value:b}}function na(a){this.h=new ka;this.A=a}
function da(a,b){a instanceof String&&(a+="");var c=0,d=!1,e={next:function(){if(!d&&c<a.length){var g=c++;return{value:b(g,a[g]),done:!1}}d=!0;return{done:!0,value:void 0}}};e[Symbol.iterator]=function(){return e};return e}y("Array.prototype.keys",function(a){return a?a:function(){return da(this,function(b){return b})}}); function oa(a,b){la(a.h);var c=a.h.A;if(c)return pa(a,"return"in c?c["return"]:function(d){return{value:d,done:!0}},b,a.h.return);a.h.return(b);return qa(a)}function pa(a,b,c,d){try{var e=b.call(a.h.A,c);if(!(e instanceof Object))throw new TypeError("Iterator result "+e+" is not an object");if(!e.done)return a.h.D=!1,e;var h=e.value}catch(f){return a.h.A=null,ma(a.h,f),qa(a)}a.h.A=null;d.call(a.h,h);return qa(a)}
function ea(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];if(b)return b.call(a);if("number"==typeof a.length)return{next:aa(a)};throw Error(String(a)+" is not an iterable or ArrayLike");} function qa(a){for(;a.h.h;)try{var b=a.A(a.h);if(b)return a.h.D=!1,{value:b.value,done:!1}}catch(c){a.h.G=void 0,ma(a.h,c)}a.h.D=!1;if(a.h.C){b=a.h.C;a.h.C=null;if(b.Da)throw b.Ca;return{value:b.return,done:!0}}return{value:void 0,done:!0}}
y("Promise",function(a){function b(f){this.l=0;this.m=void 0;this.h=[];this.M=!1;var h=this.o();try{f(h.resolve,h.reject)}catch(k){h.reject(k)}}function c(){this.h=null}function d(f){return f instanceof b?f:new b(function(h){h(f)})}if(a)return a;c.prototype.l=function(f){if(null==this.h){this.h=[];var h=this;this.m(function(){h.D()})}this.h.push(f)};var e=x.setTimeout;c.prototype.m=function(f){e(f,0)};c.prototype.D=function(){for(;this.h&&this.h.length;){var f=this.h;this.h=[];for(var h=0;h<f.length;++h){var k= function ra(a){this.next=function(b){la(a.h);a.h.A?b=pa(a,a.h.A.next,b,a.h.K):(a.h.K(b),b=qa(a));return b};this.throw=function(b){la(a.h);a.h.A?b=pa(a,a.h.A["throw"],b,a.h.K):(ma(a.h,b),b=qa(a));return b};this.return=function(b){return oa(a,b)};this[Symbol.iterator]=function(){return this}}function sa(a,b){b=new ra(new na(b));ja&&a.prototype&&ja(b,a.prototype);return b}
f[h];f[h]=null;try{k()}catch(l){this.o(l)}}}this.h=null};c.prototype.o=function(f){this.m(function(){throw f;})};b.prototype.o=function(){function f(l){return function(m){k||(k=!0,l.call(h,m))}}var h=this,k=!1;return{resolve:f(this.S),reject:f(this.D)}};b.prototype.S=function(f){if(f===this)this.D(new TypeError("A Promise cannot resolve to itself"));else if(f instanceof b)this.U(f);else{a:switch(typeof f){case "object":var h=null!=f;break a;case "function":h=!0;break a;default:h=!1}h?this.R(f):this.I(f)}}; function ta(a){function b(d){return a.next(d)}function c(d){return a.throw(d)}return new Promise(function(d,e){function h(f){f.done?d(f.value):Promise.resolve(f.value).then(b,c).then(h,e)}h(a.next())})}function ua(a){return ta(new ra(new na(a)))}
b.prototype.R=function(f){var h=void 0;try{h=f.then}catch(k){this.D(k);return}"function"==typeof h?this.V(h,f):this.I(f)};b.prototype.D=function(f){this.N(2,f)};b.prototype.I=function(f){this.N(1,f)};b.prototype.N=function(f,h){if(0!=this.l)throw Error("Cannot settle("+f+", "+h+"): Promise already settled in state"+this.l);this.l=f;this.m=h;2===this.l&&this.T();this.O()};b.prototype.T=function(){var f=this;e(function(){if(f.P()){var h=x.console;"undefined"!==typeof h&&h.error(f.m)}},1)};b.prototype.P= B("Symbol",function(a){function b(h){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new c(d+(h||"")+"_"+e++,h)}function c(h,f){this.h=h;ca(this,"description",{configurable:!0,writable:!0,value:f})}if(a)return a;c.prototype.toString=function(){return this.h};var d="jscomp_symbol_"+(1E9*Math.random()>>>0)+"_",e=0;return b});
function(){if(this.M)return!1;var f=x.CustomEvent,h=x.Event,k=x.dispatchEvent;if("undefined"===typeof k)return!0;"function"===typeof f?f=new f("unhandledrejection",{cancelable:!0}):"function"===typeof h?f=new h("unhandledrejection",{cancelable:!0}):(f=x.document.createEvent("CustomEvent"),f.initCustomEvent("unhandledrejection",!1,!0,f));f.promise=this;f.reason=this.m;return k(f)};b.prototype.O=function(){if(null!=this.h){for(var f=0;f<this.h.length;++f)g.l(this.h[f]);this.h=null}};var g=new c;b.prototype.U= B("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c<b.length;c++){var d=z[b[c]];"function"===typeof d&&"function"!=typeof d.prototype[a]&&ca(d.prototype,a,{configurable:!0,writable:!0,value:function(){return va(aa(this))}})}return a});function va(a){a={next:a};a[Symbol.iterator]=function(){return this};return a}
function(f){var h=this.o();f.J(h.resolve,h.reject)};b.prototype.V=function(f,h){var k=this.o();try{f.call(h,k.resolve,k.reject)}catch(l){k.reject(l)}};b.prototype.then=function(f,h){function k(n,q){return"function"==typeof n?function(r){try{l(n(r))}catch(u){m(u)}}:q}var l,m,p=new b(function(n,q){l=n;m=q});this.J(k(f,l),k(h,m));return p};b.prototype.catch=function(f){return this.then(void 0,f)};b.prototype.J=function(f,h){function k(){switch(l.l){case 1:f(l.m);break;case 2:h(l.m);break;default:throw Error("Unexpected state: "+ B("Promise",function(a){function b(f){this.A=0;this.C=void 0;this.h=[];this.R=!1;var g=this.D();try{f(g.resolve,g.reject)}catch(k){g.reject(k)}}function c(){this.h=null}function d(f){return f instanceof b?f:new b(function(g){g(f)})}if(a)return a;c.prototype.A=function(f){if(null==this.h){this.h=[];var g=this;this.C(function(){g.G()})}this.h.push(f)};var e=z.setTimeout;c.prototype.C=function(f){e(f,0)};c.prototype.G=function(){for(;this.h&&this.h.length;){var f=this.h;this.h=[];for(var g=0;g<f.length;++g){var k=
l.l);}}var l=this;null==this.h?g.l(k):this.h.push(k);this.M=!0};b.resolve=d;b.reject=function(f){return new b(function(h,k){k(f)})};b.race=function(f){return new b(function(h,k){for(var l=ea(f),m=l.next();!m.done;m=l.next())d(m.value).J(h,k)})};b.all=function(f){var h=ea(f),k=h.next();return k.done?d([]):new b(function(l,m){function p(r){return function(u){n[r]=u;q--;0==q&&l(n)}}var n=[],q=0;do n.push(void 0),q++,d(k.value).J(p(n.length-1),m),k=h.next();while(!k.done)})};return b}); f[g];f[g]=null;try{k()}catch(l){this.D(l)}}}this.h=null};c.prototype.D=function(f){this.C(function(){throw f;})};b.prototype.D=function(){function f(l){return function(m){k||(k=!0,l.call(g,m))}}var g=this,k=!1;return{resolve:f(this.wa),reject:f(this.G)}};b.prototype.wa=function(f){if(f===this)this.G(new TypeError("A Promise cannot resolve to itself"));else if(f instanceof b)this.ya(f);else{a:switch(typeof f){case "object":var g=null!=f;break a;case "function":g=!0;break a;default:g=!1}g?this.va(f):
y("Object.is",function(a){return a?a:function(b,c){return b===c?0!==b||1/b===1/c:b!==b&&c!==c}});y("Array.prototype.includes",function(a){return a?a:function(b,c){var d=this;d instanceof String&&(d=String(d));var e=d.length;c=c||0;for(0>c&&(c=Math.max(c+e,0));c<e;c++){var g=d[c];if(g===b||Object.is(g,b))return!0}return!1}}); this.K(f)}};b.prototype.va=function(f){var g=void 0;try{g=f.then}catch(k){this.G(k);return}"function"==typeof g?this.za(g,f):this.K(f)};b.prototype.G=function(f){this.pa(2,f)};b.prototype.K=function(f){this.pa(1,f)};b.prototype.pa=function(f,g){if(0!=this.A)throw Error("Cannot settle("+f+", "+g+"): Promise already settled in state"+this.A);this.A=f;this.C=g;2===this.A&&this.xa();this.ta()};b.prototype.xa=function(){var f=this;e(function(){if(f.ua()){var g=z.console;"undefined"!==typeof g&&g.error(f.C)}},
y("String.prototype.includes",function(a){return a?a:function(b,c){if(null==this)throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype.includes must not be a regular expression");return-1!==this.indexOf(b,c||0)}}); 1)};b.prototype.ua=function(){if(this.R)return!1;var f=z.CustomEvent,g=z.Event,k=z.dispatchEvent;if("undefined"===typeof k)return!0;"function"===typeof f?f=new f("unhandledrejection",{cancelable:!0}):"function"===typeof g?f=new g("unhandledrejection",{cancelable:!0}):(f=z.document.createEvent("CustomEvent"),f.initCustomEvent("unhandledrejection",!1,!0,f));f.promise=this;f.reason=this.C;return k(f)};b.prototype.ta=function(){if(null!=this.h){for(var f=0;f<this.h.length;++f)h.A(this.h[f]);this.h=null}};
var fa="function"==typeof Object.assign?Object.assign:function(a,b){for(var c=1;c<arguments.length;c++){var d=arguments[c];if(d)for(var e in d)Object.prototype.hasOwnProperty.call(d,e)&&(a[e]=d[e])}return a};y("Object.assign",function(a){return a||fa});function C(a){return"undefined"!==typeof a?a:!0}function ha(a){for(var b=Array(a),c=0;c<a;c++)b[c]=D();return b}function D(){return Object.create(null)}function ia(a,b){return b.length-a.length}function E(a){return"string"===typeof a}function F(a){return"object"===typeof a}function G(a){return"function"===typeof a};function ja(a,b){var c=ka;if(a&&(b&&(a=I(a,b)),this.K&&(a=I(a,this.K)),this.L&&1<a.length&&(a=I(a,this.L)),c||""===c)){a=a.split(c);if(this.filter){b=this.filter;c=a.length;for(var d=[],e=0,g=0;e<c;e++){var f=a[e];f&&!b[f]&&(d[g++]=f)}a=d}return a}return a}var ka=/[\p{Z}\p{S}\p{P}\p{C}]+/u,la=/[\u0300-\u036f]/g; var h=new c;b.prototype.ya=function(f){var g=this.D();f.fa(g.resolve,g.reject)};b.prototype.za=function(f,g){var k=this.D();try{f.call(g,k.resolve,k.reject)}catch(l){k.reject(l)}};b.prototype.then=function(f,g){function k(p,q){return"function"==typeof p?function(r){try{l(p(r))}catch(x){m(x)}}:q}var l,m,n=new b(function(p,q){l=p;m=q});this.fa(k(f,l),k(g,m));return n};b.prototype.catch=function(f){return this.then(void 0,f)};b.prototype.fa=function(f,g){function k(){switch(l.A){case 1:f(l.C);break;
function ma(a,b){for(var c=Object.keys(a),d=c.length,e=[],g="",f=0,h=0,k,l;h<d;h++)k=c[h],(l=a[k])?(e[f++]=J(b?"(?!\\b)"+k+"(\\b|_)":k),e[f++]=l):g+=(g?"|":"")+k;g&&(e[f++]=J(b?"(?!\\b)("+g+")(\\b|_)":"("+g+")"),e[f]="");return e}function I(a,b){for(var c=0,d=b.length;c<d&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a}function J(a){return new RegExp(a,"g")}function na(a){for(var b="",c="",d=0,e=a.length,g=void 0;d<e;d++)(g=a[d])!==c&&(b+=c=g);return b};var pa={encode:oa,G:!1,H:""};function oa(a){return ja.call(this,(""+a).toLowerCase(),!1)};var qa={},K={};function ra(a){L(a,"add");L(a,"append");L(a,"search");L(a,"update");L(a,"remove")}function L(a,b){a[b+"Async"]=function(){var c=this,d=arguments,e=d[d.length-1];if(G(e)){var g=e;delete d[d.length-1]}e=new Promise(function(f){setTimeout(function(){c.async=!0;var h=c[b].apply(c,d);c.async=!1;f(h)})});return g?(e.then(g),this):e}};function sa(a,b,c,d){var e=a.length,g=[],f,h=0;d&&(d=[]);for(var k=e-1;0<=k;k--){for(var l=a[k],m=l.length,p=D(),n=!B,q=0;q<m;q++){var r=l[q],u=r.length;if(u)for(var A=0,w,z;A<u;A++)if(z=r[A],B){if(B[z]){if(!k)if(c)c--;else if(g[h++]=z,h===b)return g;if(k||d)p[z]=1;n=!0}d&&(w=(f[z]||0)+1,f[z]=w,w<e&&(w=d[w-2]||(d[w-2]=[]),w[w.length]=z))}else p[z]=1}if(d)B||(f=p);else if(!n)return[];var B=p}if(d)for(a=d.length-1;0<=a;a--)for(e=d[a],f=e.length,k=0;k<f;k++)if(l=e[k],!B[l]){if(c)c--;else if(g[h++]=l, case 2:g(l.C);break;default:throw Error("Unexpected state: "+l.A);}}var l=this;null==this.h?h.A(k):this.h.push(k);this.R=!0};b.resolve=d;b.reject=function(f){return new b(function(g,k){k(f)})};b.race=function(f){return new b(function(g,k){for(var l=y(f),m=l.next();!m.done;m=l.next())d(m.value).fa(g,k)})};b.all=function(f){var g=y(f),k=g.next();return k.done?d([]):new b(function(l,m){function n(r){return function(x){p[r]=x;q--;0==q&&l(p)}}var p=[],q=0;do p.push(void 0),q++,d(k.value).fa(n(p.length-
h===b)return g;B[l]=1}return g}function ta(a,b){for(var c=D(),d=D(),e=[],g=0;g<a.length;g++)c[a[g]]=1;for(a=0;a<b.length;a++){g=b[a];for(var f=0,h;f<g.length;f++)h=g[f],c[h]&&!d[h]&&(d[h]=1,e[e.length]=h)}return e};function M(a){this.l=!0!==a&&a;this.cache=D();this.h=[]}function ua(a,b,c){F(a)&&(a=a.query);var d=this.cache.get(a);d||(d=this.search(a,b,c),this.cache.set(a,d));return d}M.prototype.set=function(a,b){if(!this.cache[a]){var c=this.h.length;c===this.l?delete this.cache[this.h[c-1]]:c++;for(--c;0<c;c--)this.h[c]=this.h[c-1];this.h[0]=a}this.cache[a]=b};M.prototype.get=function(a){var b=this.cache[a];if(this.l&&b&&(a=this.h.indexOf(a))){var c=this.h[a-1];this.h[a-1]=this.h[a];this.h[a]=c}return b};var va={memory:{charset:"latin:extra",F:3,C:4,s:!1},performance:{F:3,C:3,B:!1,context:{depth:2,F:1}},match:{charset:"latin:extra",H:"reverse"},score:{charset:"latin:advanced",F:20,C:3,context:{depth:3,F:9}},"default":{}};function wa(a,b,c,d,e,g,f,h){setTimeout(function(){var k=a(c?c+"."+d:d,JSON.stringify(f));k&&k.then?k.then(function(){b.export(a,b,c,e,g+1,h)}):b.export(a,b,c,e,g+1,h)})};function N(a,b){if(!(this instanceof N))return new N(a);var c;if(a){E(a)?a=va[a]:(c=a.preset)&&(a=Object.assign({},c[c],a));c=a.charset;var d=a.lang;E(c)&&(-1===c.indexOf(":")&&(c+=":default"),c=K[c]);E(d)&&(d=qa[d])}else a={};var e,g,f=a.context||{};this.encode=a.encode||c&&c.encode||oa;this.register=b||D();this.F=e=a.resolution||9;this.H=b=c&&c.H||a.tokenize||"strict";this.depth="strict"===b&&f.depth;this.l=C(f.bidirectional);this.B=g=C(a.optimize);this.s=C(a.fastupdate);this.C=a.minlength||1;this.o= 1),m),k=g.next();while(!k.done)})};return b});function wa(a,b){a instanceof String&&(a+="");var c=0,d=!1,e={next:function(){if(!d&&c<a.length){var h=c++;return{value:b(h,a[h]),done:!1}}d=!0;return{done:!0,value:void 0}}};e[Symbol.iterator]=function(){return e};return e}B("Array.prototype.values",function(a){return a?a:function(){return wa(this,function(b,c){return c})}});function G(a,b){return Object.prototype.hasOwnProperty.call(a,b)}
a.boost;this.map=g?ha(e):D();this.m=e=f.resolution||1;this.h=g?ha(e):D();this.G=c&&c.G||a.rtl;this.K=(b=a.matcher||d&&d.K)&&ma(b,!1);this.L=(b=a.stemmer||d&&d.L)&&ma(b,!0);if(c=b=a.filter||d&&d.filter){c=b;d=D();f=0;for(e=c.length;f<e;f++)d[c[f]]=1;c=d}this.filter=c;this.cache=(b=a.cache)&&new M(b)}t=N.prototype;t.append=function(a,b){return this.add(a,b,!0)}; B("WeakMap",function(a){function b(k){this.h=(g+=Math.random()+1).toString();if(k){k=y(k);for(var l;!(l=k.next()).done;)l=l.value,this.set(l[0],l[1])}}function c(){}function d(k){var l=typeof k;return"object"===l&&null!==k||"function"===l}function e(k){if(!G(k,f)){var l=new c;ca(k,f,{value:l})}}function h(k){var l=Object[k];l&&(Object[k]=function(m){if(m instanceof c)return m;Object.isExtensible(m)&&e(m);return l(m)})}if(function(){if(!a||!Object.seal)return!1;try{var k=Object.seal({}),l=Object.seal({}),
t.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.register[a])return this.update(a,b);b=this.encode(b);if(d=b.length){for(var e=D(),g=D(),f=this.depth,h=this.F,k=0;k<d;k++){var l=b[this.G?d-1-k:k],m=l.length;if(l&&m>=this.C&&(f||!g[l])){var p=O(h,d,k),n="";switch(this.H){case "full":if(2<m){for(p=0;p<m;p++)for(var q=m;q>p;q--)if(q-p>=this.C){var r=O(h,d,k,m,p);n=l.substring(p,q);P(this,g,n,r,a,c)}break}case "reverse":if(1<m){for(q=m-1;0<q;q--)n=l[q]+n,n.length>=this.C&&P(this,g,n,O(h,d,k, m=new a([[k,2],[l,3]]);if(2!=m.get(k)||3!=m.get(l))return!1;m.delete(k);m.set(l,4);return!m.has(k)&&4==m.get(l)}catch(n){return!1}}())return a;var f="$jscomp_hidden_"+Math.random();h("freeze");h("preventExtensions");h("seal");var g=0;b.prototype.set=function(k,l){if(!d(k))throw Error("Invalid WeakMap key");e(k);if(!G(k,f))throw Error("WeakMap key fail: "+k);k[f][this.h]=l;return this};b.prototype.get=function(k){return d(k)&&G(k,f)?k[f][this.h]:void 0};b.prototype.has=function(k){return d(k)&&G(k,
m,q),a,c);n=""}case "forward":if(1<m){for(q=0;q<m;q++)n+=l[q],n.length>=this.C&&P(this,g,n,p,a,c);break}default:if(this.o&&(p=Math.min(p/this.o(b,l,k)|0,h-1)),P(this,g,l,p,a,c),f&&1<d&&k<d-1)for(m=D(),n=this.m,p=l,q=Math.min(f+1,d-k),r=m[p]=1;r<q;r++)if((l=b[this.G?d-1-k-r:k+r])&&l.length>=this.C&&!m[l]){m[l]=1;var u=this.l&&l>p;P(this,e,u?p:l,O(n+(d/2>n?0:1),d,k,q-1,r-1),a,c,u?l:p)}}}}this.s||(this.register[a]=1)}}return this}; f)&&G(k[f],this.h)};b.prototype.delete=function(k){return d(k)&&G(k,f)&&G(k[f],this.h)?delete k[f][this.h]:!1};return b});
function O(a,b,c,d,e){return c&&1<a?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0}function P(a,b,c,d,e,g,f){var h=f?a.h:a.map;if(!b[c]||f&&!b[c][f])a.B&&(h=h[d]),f?(b=b[c]||(b[c]=D()),b[f]=1,h=h[f]||(h[f]=D())):b[c]=1,h=h[c]||(h[c]=[]),a.B||(h=h[d]||(h[d]=[])),g&&h.includes(e)||(h[h.length]=e,a.s&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=h))} B("Map",function(a){function b(){var g={};return g.O=g.next=g.head=g}function c(g,k){var l=g[1];return va(function(){if(l){for(;l.head!=g[1];)l=l.O;for(;l.next!=l.head;)return l=l.next,{done:!1,value:k(l)};l=null}return{done:!0,value:void 0}})}function d(g,k){var l=k&&typeof k;"object"==l||"function"==l?h.has(k)?l=h.get(k):(l=""+ ++f,h.set(k,l)):l="p_"+k;var m=g[0][l];if(m&&G(g[0],l))for(g=0;g<m.length;g++){var n=m[g];if(k!==k&&n.key!==n.key||k===n.key)return{id:l,list:m,index:g,F:n}}return{id:l,
t.search=function(a,b,c){c||(!b&&F(a)?(c=a,a=c.query):F(b)&&(c=b));var d=[],e=0;if(c){a=c.query||a;b=c.limit;e=c.offset||0;var g=c.context;var f=c.suggest}if(a){a=this.encode(""+a);var h=a.length;if(1<h){c=D();for(var k=[],l=0,m=0,p;l<h;l++)if((p=a[l])&&p.length>=this.C&&!c[p])if(this.B||f||this.map[p])k[m++]=p,c[p]=1;else return d;a=k;h=a.length}}if(!h)return d;b||(b=100);g=this.depth&&1<h&&!1!==g;c=0;if(g){var n=a[0];c=1}else 1<h&&a.sort(ia);for(;c<h;c++){l=a[c];g?(k=xa(this,d,f,b,e,2===h,l,n), list:m,index:-1,F:void 0}}function e(g){this[0]={};this[1]=b();this.size=0;if(g){g=y(g);for(var k;!(k=g.next()).done;)k=k.value,this.set(k[0],k[1])}}if(function(){if(!a||"function"!=typeof a||!a.prototype.entries||"function"!=typeof Object.seal)return!1;try{var g=Object.seal({x:4}),k=new a(y([[g,"s"]]));if("s"!=k.get(g)||1!=k.size||k.get({x:4})||k.set({x:4},"t")!=k||2!=k.size)return!1;var l=k.entries(),m=l.next();if(m.done||m.value[0]!=g||"s"!=m.value[1])return!1;m=l.next();return m.done||4!=m.value[0].x||
f&&!1===k&&d.length||(n=l)):k=xa(this,d,f,b,e,1===h,l);if(k)return k;if(f&&c===h-1){k=d.length;if(!k){if(g){g=0;c=-1;continue}return d}if(1===k)return ya(d[0],b,e)}}return sa(d,b,e,f)}; "t"!=m.value[1]||!l.next().done?!1:!0}catch(n){return!1}}())return a;var h=new WeakMap;e.prototype.set=function(g,k){g=0===g?0:g;var l=d(this,g);l.list||(l.list=this[0][l.id]=[]);l.F?l.F.value=k:(l.F={next:this[1],O:this[1].O,head:this[1],key:g,value:k},l.list.push(l.F),this[1].O.next=l.F,this[1].O=l.F,this.size++);return this};e.prototype.delete=function(g){g=d(this,g);return g.F&&g.list?(g.list.splice(g.index,1),g.list.length||delete this[0][g.id],g.F.O.next=g.F.next,g.F.next.O=g.F.O,g.F.head=null,
function xa(a,b,c,d,e,g,f,h){var k=[],l=h?a.h:a.map;a.B||(l=za(l,f,h,a.l));if(l){for(var m=0,p=Math.min(l.length,h?a.m:a.F),n=0,q=0,r,u;n<p;n++)if(r=l[n])if(a.B&&(r=za(r,f,h,a.l)),e&&r&&g&&(u=r.length,u<=e?(e-=u,r=null):(r=r.slice(e),e=0)),r&&(k[m++]=r,g&&(q+=r.length,q>=d)))break;if(m){if(g)return ya(k,d,0);b[b.length]=k;return}}return!c&&k}function ya(a,b,c){a=1===a.length?a[0]:[].concat.apply([],a);return c||a.length>b?a.slice(c,c+b):a} this.size--,!0):!1};e.prototype.clear=function(){this[0]={};this[1]=this[1].O=b();this.size=0};e.prototype.has=function(g){return!!d(this,g).F};e.prototype.get=function(g){return(g=d(this,g).F)&&g.value};e.prototype.entries=function(){return c(this,function(g){return[g.key,g.value]})};e.prototype.keys=function(){return c(this,function(g){return g.key})};e.prototype.values=function(){return c(this,function(g){return g.value})};e.prototype.forEach=function(g,k){for(var l=this.entries(),m;!(m=l.next()).done;)m=
function za(a,b,c,d){c?(d=d&&b>c,a=(a=a[d?b:c])&&a[d?c:b]):a=a[b];return a}t.contain=function(a){return!!this.register[a]};t.update=function(a,b){return this.remove(a).add(a,b)}; m.value,g.call(k,m[1],m[0],this)};e.prototype[Symbol.iterator]=e.prototype.entries;var f=0;return e});B("Array.prototype.keys",function(a){return a?a:function(){return wa(this,function(b){return b})}});
t.remove=function(a,b){var c=this.register[a];if(c){if(this.s)for(var d=0,e;d<c.length;d++)e=c[d],e.splice(e.indexOf(a),1);else Q(this.map,a,this.F,this.B),this.depth&&Q(this.h,a,this.m,this.B);b||delete this.register[a];if(this.cache)for(b=this.cache,c=0;c<b.h.length;c++)e=b.h[c],d=b.cache[e],d.includes(a)&&(b.h.splice(c--,1),delete b.cache[e])}return this}; B("Set",function(a){function b(c){this.h=new Map;if(c){c=y(c);for(var d;!(d=c.next()).done;)this.add(d.value)}this.size=this.h.size}if(function(){if(!a||"function"!=typeof a||!a.prototype.entries||"function"!=typeof Object.seal)return!1;try{var c=Object.seal({x:4}),d=new a(y([c]));if(!d.has(c)||1!=d.size||d.add(c)!=d||1!=d.size||d.add({x:4})!=d||2!=d.size)return!1;var e=d.entries(),h=e.next();if(h.done||h.value[0]!=c||h.value[1]!=c)return!1;h=e.next();return h.done||h.value[0]==c||4!=h.value[0].x||
function Q(a,b,c,d,e){var g=0;if(a.constructor===Array)if(e)b=a.indexOf(b),-1!==b?1<a.length&&(a.splice(b,1),g++):g++;else{e=Math.min(a.length,c);for(var f=0,h;f<e;f++)if(h=a[f])g=Q(h,b,c,d,e),d||g||delete a[f]}else for(f in a)(g=Q(a[f],b,c,d,e))||delete a[f];return g}t.searchCache=ua; h.value[1]!=h.value[0]?!1:e.next().done}catch(f){return!1}}())return a;b.prototype.add=function(c){c=0===c?0:c;this.h.set(c,c);this.size=this.h.size;return this};b.prototype.delete=function(c){c=this.h.delete(c);this.size=this.h.size;return c};b.prototype.clear=function(){this.h.clear();this.size=0};b.prototype.has=function(c){return this.h.has(c)};b.prototype.entries=function(){return this.h.entries()};b.prototype.values=function(){return this.h.values()};b.prototype.keys=b.prototype.values;b.prototype[Symbol.iterator]=
t.export=function(a,b,c,d,e,g){var f=!0;"undefined"===typeof g&&(f=new Promise(function(m){g=m}));switch(e||(e=0)){case 0:var h="reg";if(this.s){var k=D();for(var l in this.register)k[l]=1}else k=this.register;break;case 1:h="cfg";k={doc:0,opt:this.B?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.h;break;default:"undefined"===typeof c&&g&&g();return}wa(a,b||this,c,h,d,e,k,g);return f}; b.prototype.values;b.prototype.forEach=function(c,d){var e=this;this.h.forEach(function(h){return c.call(d,h,h,e)})};return b});B("Object.is",function(a){return a?a:function(b,c){return b===c?0!==b||1/b===1/c:b!==b&&c!==c}});B("Array.prototype.includes",function(a){return a?a:function(b,c){var d=this;d instanceof String&&(d=String(d));var e=d.length;c=c||0;for(0>c&&(c=Math.max(c+e,0));c<e;c++){var h=d[c];if(h===b||Object.is(h,b))return!0}return!1}});
t.import=function(a,b){if(b)switch(E(b)&&(b=JSON.parse(b)),a){case "cfg":this.B=!!b.opt;break;case "reg":this.s=!1;this.register=b;break;case "map":this.map=b;break;case "ctx":this.h=b}};ra(N.prototype);function Aa(a){a=a.data;var b=self._index,c=a.args,d=a.task;switch(d){case "init":d=a.options||{};a=a.factory;b=d.encode;d.cache=!1;b&&0===b.indexOf("function")&&(d.encode=Function("return "+b)());a?(Function("return "+a)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new N(d);break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};var Ba=0;function R(a){if(!(this instanceof R))return new R(a);var b;a?G(b=a.encode)&&(a.encode=b.toString()):a={};(b=(self||window)._factory)&&(b=b.toString());var c="undefined"===typeof window&&self.exports,d=this;this.A=Ca(b,c,a.worker);this.h=D();if(this.A){if(c)this.A.on("message",function(e){d.h[e.id](e.msg);delete d.h[e.id]});else this.A.onmessage=function(e){e=e.data;d.h[e.id](e.msg);delete d.h[e.id]};this.A.postMessage({task:"init",factory:b,options:a})}}S("add");S("append");S("search"); B("String.prototype.includes",function(a){return a?a:function(b,c){if(null==this)throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype.includes must not be a regular expression");return-1!==this.indexOf(b,c||0)}});B("Array.prototype.entries",function(a){return a?a:function(){return wa(this,function(b,c){return[b,c]})}});
S("update");S("remove");function S(a){R.prototype[a]=R.prototype[a+"Async"]=function(){var b=this,c=[].slice.call(arguments),d=c[c.length-1];if(G(d)){var e=d;c.splice(c.length-1,1)}d=new Promise(function(g){setTimeout(function(){b.h[++Ba]=g;b.A.postMessage({task:a,id:Ba,args:c})})});return e?(d.then(e),this):d}} var xa="function"==typeof Object.assign?Object.assign:function(a,b){for(var c=1;c<arguments.length;c++){var d=arguments[c];if(d)for(var e in d)G(d,e)&&(a[e]=d[e])}return a};B("Object.assign",function(a){return a||xa});B("Array.prototype.flat",function(a){return a?a:function(b){b=void 0===b?1:b;var c=[];Array.prototype.forEach.call(this,function(d){Array.isArray(d)&&0<b?(d=Array.prototype.flat.call(d,b-1),c.push.apply(c,d)):c.push(d)});return c}});function H(a,b,c){var d=typeof c,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(c){if("function"===e&&d===e)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){b=new Map(c);d=y(a);for(e=d.next();!e.done;e=d.next())e=e.value,b.set(e[0],e[1]);return b}if(b===Set){b=new Set(c);d=y(a.values());for(e=d.next();!e.done;e=d.next())b.add(e.value);return b}}}return a}return c}return"undefined"===e?b:a}
function Ca(a,b,c){try{var d=b?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):a?new Worker(URL.createObjectURL(new Blob(["onmessage="+Aa.toString()],{type:"text/javascript"}))):new Worker(E(c)?c:"worker/worker.js",{type:"module"})}catch(e){}return d};function T(a){if(!(this instanceof T))return new T(a);var b=a.document||a.doc||a,c;this.I=[];this.h=[];this.m=[];this.register=D();this.key=(c=b.key||b.id)&&U(c,this.m)||"id";this.s=C(a.fastupdate);this.o=(c=b.store)&&!0!==c&&[];this.store=c&&D();this.D=(c=b.tag)&&U(c,this.m);this.l=c&&D();this.cache=(c=a.cache)&&new M(c);a.cache=!1;this.A=a.worker;this.async=!1;c=D();var d=b.index||b.field||b;E(d)&&(d=[d]);for(var e=0,g,f=void 0;e<d.length;e++)g=d[e],E(g)||(f=g,g=g.field),f=F(f)?Object.assign({}, function I(){return Object.create(null)}function ya(a,b){return b.length-a.length}function J(a){return"string"===typeof a}function K(a){return"object"===typeof a}function za(a){var b=[];a=y(a.keys());for(var c=a.next();!c.done;c=a.next())b.push(c.value);return b}function Aa(a,b){if(J(b))a=a[b];else for(var c=0;a&&c<b.length;c++)a=a[b[c]];return a}function Ba(a){for(var b=0,c=0,d=void 0;c<a.length;c++)(d=a[c])&&b<d.length&&(b=d.length);return b};var Ca=/[^\p{L}\p{N}]+/u,Da=/(\d{3})/g,Ea=/(\D)(\d{3})/g,Fa=/(\d{3})(\D)/g,Ga="".normalize&&/[\u0300-\u036f]/g,Ha=!Ga&&new Map([["\u00aa","a"],["\u00b2","2"],["\u00b3","3"],["\u00b9","1"],["\u00ba","o"],["\u00bc","1\u20444"],["\u00bd","1\u20442"],["\u00be","3\u20444"],["\u00e0","a"],["\u00e1","a"],["\u00e2","a"],["\u00e3","a"],["\u00e4","a"],["\u00e5","a"],["\u00e7","c"],["\u00e8","e"],["\u00e9","e"],["\u00ea","e"],["\u00eb","e"],["\u00ec","i"],["\u00ed","i"],["\u00ee","i"],["\u00ef","i"],["\u00f1",
a,f):a,this.A&&(c[g]=new R(f),c[g].A||(this.A=!1)),this.A||(c[g]=new N(f,this.register)),this.I[e]=U(g,this.m),this.h[e]=g;if(this.o)for(a=b.store,E(a)&&(a=[a]),b=0;b<a.length;b++)this.o[b]=U(a[b],this.m);this.index=c}function U(a,b){for(var c=a.split(":"),d=0,e=0;e<c.length;e++)a=c[e],0<=a.indexOf("[]")&&(a=a.substring(0,a.length-2))&&(b[d]=!0),a&&(c[d++]=a);d<c.length&&(c.length=d);return 1<d?c:c[0]}function V(a,b){if(E(b))a=a[b];else for(var c=0;a&&c<b.length;c++)a=a[b[c]];return a} "n"],["\u00f2","o"],["\u00f3","o"],["\u00f4","o"],["\u00f5","o"],["\u00f6","o"],["\u00f9","u"],["\u00fa","u"],["\u00fb","u"],["\u00fc","u"],["\u00fd","y"],["\u00ff","y"],["\u0101","a"],["\u0103","a"],["\u0105","a"],["\u0107","c"],["\u0109","c"],["\u010b","c"],["\u010d","c"],["\u010f","d"],["\u0113","e"],["\u0115","e"],["\u0117","e"],["\u0119","e"],["\u011b","e"],["\u011d","g"],["\u011f","g"],["\u0121","g"],["\u0123","g"],["\u0125","h"],["\u0129","i"],["\u012b","i"],["\u012d","i"],["\u012f","i"],["\u0133",
function W(a,b,c,d,e){a=a[e];if(d===c.length-1)b[e]=a;else if(a)if(a.constructor===Array)for(b=b[e]=Array(a.length),e=0;e<a.length;e++)W(a,b,c,d,e);else b=b[e]||(b[e]=D()),e=c[++d],W(a,b,c,d,e)}function X(a,b,c,d,e,g,f,h){if(a=a[f])if(d===b.length-1){if(a.constructor===Array){if(c[d]){for(b=0;b<a.length;b++)e.add(g,a[b],!0,!0);return}a=a.join(" ")}e.add(g,a,h,!0)}else if(a.constructor===Array)for(f=0;f<a.length;f++)X(a,b,c,d,e,g,f,h);else f=b[++d],X(a,b,c,d,e,g,f,h)}t=T.prototype; "ij"],["\u0135","j"],["\u0137","k"],["\u013a","l"],["\u013c","l"],["\u013e","l"],["\u0140","l"],["\u0144","n"],["\u0146","n"],["\u0148","n"],["\u0149","n"],["\u014d","o"],["\u014f","o"],["\u0151","o"],["\u0155","r"],["\u0157","r"],["\u0159","r"],["\u015b","s"],["\u015d","s"],["\u015f","s"],["\u0161","s"],["\u0163","t"],["\u0165","t"],["\u0169","u"],["\u016b","u"],["\u016d","u"],["\u016f","u"],["\u0171","u"],["\u0173","u"],["\u0175","w"],["\u0177","y"],["\u017a","z"],["\u017c","z"],["\u017e","z"],
t.add=function(a,b,c){F(a)&&(b=a,a=V(b,this.key));if(b&&(a||0===a)){if(!c&&this.register[a])return this.update(a,b);for(var d=0,e,g;d<this.h.length;d++)g=this.h[d],e=this.I[d],E(e)&&(e=[e]),X(b,e,this.m,0,this.index[g],a,e[0],c);if(this.D){d=V(b,this.D);e=D();E(d)&&(d=[d]);g=0;for(var f;g<d.length;g++)if(f=d[g],!e[f]&&(e[f]=1,f=this.l[f]||(this.l[f]=[]),!c||!f.includes(a)))if(f[f.length]=a,this.s){var h=this.register[a]||(this.register[a]=[]);h[h.length]=f}}if(this.store&&(!c||!this.store[a])){if(this.o){var k= ["\u017f","s"],["\u01a1","o"],["\u01b0","u"],["\u01c6","dz"],["\u01c9","lj"],["\u01cc","nj"],["\u01ce","a"],["\u01d0","i"],["\u01d2","o"],["\u01d4","u"],["\u01d6","u"],["\u01d8","u"],["\u01da","u"],["\u01dc","u"],["\u01df","a"],["\u01e1","a"],["\u01e3","ae"],["\u00e6","ae"],["\u01fd","ae"],["\u01e7","g"],["\u01e9","k"],["\u01eb","o"],["\u01ed","o"],["\u01ef","\u0292"],["\u01f0","j"],["\u01f3","dz"],["\u01f5","g"],["\u01f9","n"],["\u01fb","a"],["\u01ff","\u00f8"],["\u0201","a"],["\u0203","a"],["\u0205",
D();for(c=0;c<this.o.length;c++)d=this.o[c],E(d)?k[d]=b[d]:W(b,k,d,0,d[0])}this.store[a]=k||b}}return this};t.append=function(a,b){return this.add(a,b,!0)};t.update=function(a,b){return this.remove(a).add(a,b)}; "e"],["\u0207","e"],["\u0209","i"],["\u020b","i"],["\u020d","o"],["\u020f","o"],["\u0211","r"],["\u0213","r"],["\u0215","u"],["\u0217","u"],["\u0219","s"],["\u021b","t"],["\u021f","h"],["\u0227","a"],["\u0229","e"],["\u022b","o"],["\u022d","o"],["\u022f","o"],["\u0231","o"],["\u0233","y"],["\u02b0","h"],["\u02b1","h"],["\u0266","h"],["\u02b2","j"],["\u02b3","r"],["\u02b4","\u0279"],["\u02b5","\u027b"],["\u02b6","\u0281"],["\u02b7","w"],["\u02b8","y"],["\u02e0","\u0263"],["\u02e1","l"],["\u02e2","s"],
t.remove=function(a){F(a)&&(a=V(a,this.key));if(this.register[a]){for(var b=0;b<this.h.length&&(this.index[this.h[b]].remove(a,!this.A),!this.s);b++);if(this.D&&!this.s)for(var c in this.l){b=this.l[c];var d=b.indexOf(a);-1!==d&&(1<b.length?b.splice(d,1):delete this.l[c])}this.store&&delete this.store[a];delete this.register[a]}return this}; ["\u02e3","x"],["\u02e4","\u0295"],["\u0390","\u03b9"],["\u03ac","\u03b1"],["\u03ad","\u03b5"],["\u03ae","\u03b7"],["\u03af","\u03b9"],["\u03b0","\u03c5"],["\u03ca","\u03b9"],["\u03cb","\u03c5"],["\u03cc","\u03bf"],["\u03cd","\u03c5"],["\u03ce","\u03c9"],["\u03d0","\u03b2"],["\u03d1","\u03b8"],["\u03d2","\u03a5"],["\u03d3","\u03a5"],["\u03d4","\u03a5"],["\u03d5","\u03c6"],["\u03d6","\u03c0"],["\u03f0","\u03ba"],["\u03f1","\u03c1"],["\u03f2","\u03c2"],["\u03f5","\u03b5"],["\u0439","\u0438"],["\u0450",
t.search=function(a,b,c,d){c||(!b&&F(a)?(c=a,a=""):F(b)&&(c=b,b=0));var e=[],g=[],f,h=0;if(c)if(c.constructor===Array){var k=c;c=null}else{a=c.query||a;k=(f=c.pluck)||c.index||c.field;var l=c.tag;var m=this.store&&c.enrich;var p="and"===c.bool;b=c.limit||b||100;var n=c.offset||0;if(l&&(E(l)&&(l=[l]),!a)){g=0;for(f=void 0;g<l.length;g++)if(f=Da.call(this,l[g],b,n,m))e[e.length]=f,h++;return h?e:[]}E(k)&&(k=[k])}k||(k=this.h);p=p&&(1<k.length||l&&1<l.length);for(var q=!d&&(this.A||this.async)&&[],r= "\u0435"],["\u0451","\u0435"],["\u0453","\u0433"],["\u0457","\u0456"],["\u045c","\u043a"],["\u045d","\u0438"],["\u045e","\u0443"],["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]]);
0,u=void 0,A=void 0,w=void 0;r<k.length;r++)if(w=void 0,A=k[r],E(A)||(w=A,A=w.field,a=w.query||a,b=w.limit||b,m=w.enrich||m),q)q[r]=this.index[A].searchAsync(a,b,w||c);else{d?u=d[r]:u=this.index[A].search(a,b,w||c);w=u&&u.length;if(l&&w){var z=[],B=0;p&&(z[0]=[u]);var Y=0,H=void 0;for(H=void 0;Y<l.length;Y++)if(H=l[Y],w=(H=this.l[H])&&H.length)B++,z[z.length]=p?[H]:H;B&&(u=p?sa(z,b||100,n||0):ta(u,z),w=u.length)}if(w)g[h]=A,e[h++]=u;else if(p)return[]}if(q){var Ka=this;return new Promise(function(La){Promise.all(q).then(function(Ma){La(Ka.search(a, function M(a){a=void 0===a?{}:a;if(!(this instanceof M))return new (Function.prototype.bind.apply(M,[null].concat(ba(arguments))));for(var b=0;b<arguments.length;b++)this.assign(arguments[b])}
b,c,Ma))})})}if(!h)return[];if(f&&(!m||!this.store))return e[0];l=0;for(n=void 0;l<g.length;l++){n=e[l];n.length&&m&&(n=Ea.call(this,n));if(f)return n;e[l]={field:g[l],result:n}}return e};function Da(a,b,c,d){var e=this.l[a],g=e&&e.length-c;if(g&&0<g){if(g>b||c)e=e.slice(c,c+b);d&&(e=Ea.call(this,e));return{tag:a,result:e}}}function Ea(a){for(var b=Array(a.length),c=0,d;c<a.length;c++)d=a[c],b[c]={id:d,doc:this.store[d]};return b}t.contain=function(a){return!!this.register[a]};t.get=function(a){return this.store[a]}; M.prototype.assign=function(a){this.normalize=H(a.normalize,!0,this.normalize);var b=a.ra,c=b||a.Ha||a.split;if("object"===typeof c){var d=!b,e="";a.ra||(e+="\\p{Z}");c.Ea&&(e+="\\p{L}");c.Ia&&(e+="\\p{N}",d=!!b);c.Ka&&(e+="\\p{S}");c.Ja&&(e+="\\p{P}");c.control&&(e+="\\p{C}");if(c=c.char)e+="object"===typeof c?c.join(""):c;this.split=new RegExp("["+(b?"^":"")+e+"]+","u");this.numeric=d}else this.split=H(c,Ca,this.split),this.numeric=H(this.numeric,!0);this.la=H(a.la,null,this.la);this.ca=H(a.ca,
t.set=function(a,b){this.store[a]=b;return this};t.searchCache=ua;t.export=function(a,b,c,d,e,g){var f;"undefined"===typeof g&&(f=new Promise(function(p){g=p}));e||(e=0);d||(d=0);if(d<this.h.length){var h=this.h[d],k=this.index[h];b=this;setTimeout(function(){k.export(a,b,e?h:"",d,e++,g)||(d++,e=1,b.export(a,b,h,d,e,g))})}else{switch(e){case 1:var l="tag";var m=this.l;c=null;break;case 2:l="store";m=this.store;c=null;break;default:g();return}wa(a,this,c,l,d,e,m,g)}return f}; null,this.ca);this.rtl=a.rtl||!1;this.H=H(a.H,!0,this.H);this.filter=H((c=a.filter)&&new Set(c),null,this.filter);this.N=H((c=a.N)&&new Map(c),null,this.N);this.I=H((c=a.I)&&new Map(c),null,this.I);this.U=H((c=a.U)&&new Map(c),null,this.U);this.P=H(a.P,null,this.P);this.ka=H(a.ka,1,this.ka);this.sa=H(a.sa,0,this.sa);if(this.cache=c=H(a.cache,!0,this.cache))this.ea=null,this.R="number"===typeof c?c:2E5,this.W=new Map,this.ba=new Map,this.A=this.h=128;this.C="";this.G=null;this.D="";this.K=null;if(this.N)for(a=
t.import=function(a,b){if(b)switch(E(b)&&(b=JSON.parse(b)),a){case "tag":this.l=b;break;case "reg":this.s=!1;this.register=b;a=0;for(var c;a<this.h.length;a++)c=this.index[this.h[a]],c.register=b,c.s=!1;break;case "store":this.store=b;break;default:a=a.split("."),c=a[0],a=a[1],c&&a&&this.index[c].import(a,b)}};ra(T.prototype);var Ga={encode:Fa,G:!1,H:""},Ha=[J("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",J("[\u00e8\u00e9\u00ea\u00eb]"),"e",J("[\u00ec\u00ed\u00ee\u00ef]"),"i",J("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",J("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",J("[\u00fd\u0177\u00ff]"),"y",J("\u00f1"),"n",J("[\u00e7c]"),"k",J("\u00df"),"s",J(" & ")," and "];function Fa(a){var b=a=""+a;b.normalize&&(b=b.normalize("NFD").replace(la,""));return ja.call(this,b.toLowerCase(),!a.normalize&&Ha)};var Ja={encode:Ia,G:!1,H:"strict"},Na=/[^a-z0-9]+/,Oa={b:"p",v:"f",w:"f",z:"s",x:"s","\u00df":"s",d:"t",n:"m",c:"k",g:"k",j:"k",q:"k",i:"e",y:"e",u:"o"};function Ia(a){a=Fa.call(this,a).join(" ");var b=[];if(a)for(var c=a.split(Na),d=c.length,e=0,g,f=0;e<d;e++)if((a=c[e])&&(!this.filter||!this.filter[a])){g=a[0];for(var h=Oa[g]||g,k=h,l=1;l<a.length;l++)g=a[l],(g=Oa[g]||g)&&g!==k&&(h+=g,k=g);b[f++]=h}return b};var Qa={encode:Pa,G:!1,H:""},Ra=[J("ae"),"a",J("oe"),"o",J("sh"),"s",J("th"),"t",J("ph"),"f",J("pf"),"f",J("(?![aeo])h(?![aeo])"),"",J("(?!^[aeo])h(?!^[aeo])"),""];function Pa(a,b){a&&(a=Ia.call(this,a).join(" "),2<a.length&&(a=I(a,Ra)),b||(1<a.length&&(a=na(a)),a&&(a=a.split(" "))));return a||[]};var Ta={encode:Sa,G:!1,H:""},Ua=J("(?!\\b)[aeo]");function Sa(a){a&&(a=Pa.call(this,a,!0),1<a.length&&(a=a.replace(Ua,"")),1<a.length&&(a=na(a)),a&&(a=a.split(" ")));return a||[]};K["latin:default"]=pa;K["latin:simple"]=Ga;K["latin:balance"]=Ja;K["latin:advanced"]=Qa;K["latin:extra"]=Ta;var Z={Index:N,Document:T,Worker:R,registerCharset:function(a,b){K[a]=b},registerLanguage:function(a,b){qa[a]=b}},Va;(Va=self.define)&&Va.amd?Va([],function(){return Z}):self.exports?self.exports=Z:self.FlexSearch=Z;}(this)); y(this.N.keys()),b=a.next();!b.done;b=a.next())this.C+=(this.C?"|":"")+b.value;if(this.U)for(a=y(this.U.keys()),b=a.next();!b.done;b=a.next())this.D+=(this.D?"|":"")+b.value;return this};
M.prototype.encode=function(a){var b=this;if(this.cache&&a.length<=this.h)if(this.ea){if(this.W.has(a))return this.W.get(a)}else this.ea=setTimeout(Ia,0,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):Ga?a=a.normalize("NFKD").replace(Ga,"").toLowerCase():(a=a.toLowerCase(),this.I=this.I?new Map([].concat(ba(Ha),ba(this.I))):new Map(Ha)));this.la&&(a=this.la(a));this.numeric&&3<a.length&&(a=a.replace(Ea,"$1 $2").replace(Fa,"$1 $2").replace(Da,"$1 "));for(var c=!(this.H||
this.I||this.filter||this.N||this.U||this.P),d=[],e=this.split||""===this.split?a.split(this.split):a,h=0,f=void 0,g=void 0;h<e.length;h++)if((f=g=e[h])&&!(f.length<this.ka))if(c)d.push(f);else if(!this.filter||!this.filter.has(f)){if(this.cache&&f.length<=this.A)if(this.ea){var k=this.ba.get(f);if(k||""===k){k&&d.push(k);continue}}else this.ea=setTimeout(Ia,0,this);k=void 0;this.U&&2<f.length&&(this.K||(this.K=new RegExp("(?!^)("+this.D+")$")),f=f.replace(this.K,function(q){return b.U.get(q)}),k=
1);this.N&&1<f.length&&(this.G||(this.G=new RegExp("("+this.C+")","g")),f=f.replace(this.G,function(q){return b.N.get(q)}),k=1);f&&k&&(f.length<this.ka||this.filter&&this.filter.has(f))&&(f="");if(f&&(this.I||this.H&&1<f.length)){k="";for(var l=0,m="",n=void 0,p=void 0;l<f.length;l++)n=f.charAt(l),n===m&&this.H||((p=this.I&&this.I.get(n))||""===p?p===m&&this.H||!(m=p)||(k+=p):k+=m=n);f=k}if(f&&this.P)for(k=0;f&&k<this.P.length;k+=2)f=f.replace(this.P[k],this.P[k+1]);this.cache&&g.length<=this.A&&
(this.ba.set(g,f),this.ba.size>this.R&&(this.ba.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.ca&&(d=this.ca(d)||d);this.cache&&a.length<=this.h&&(this.W.set(a,d),this.W.size>this.R&&(this.W.clear(),this.h=this.h/1.1|0));return d};function Ia(a){a.ea=null;a.W.clear();a.ba.clear()};function Ja(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();var d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d instanceof Promise){var e=this;d.then(function(h){e.cache.set(a,h)})}this.cache.set(a,d)}return d}function N(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}N.prototype.set=function(a,b){this.cache.has(a)||(this.cache.set(this.h=a,b),this.limit&&this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value))};
N.prototype.get=function(a){var b=this.cache.get(a);b&&this.limit&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};N.prototype.remove=function(a){for(var b=y(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)}};N.prototype.clear=function(){this.cache.clear();this.h=""};function Ka(a,b,c,d){for(var e=[],h=0,f;h<a.index.length;h++)if(f=a.index[h],b>=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);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 Q(a){if(!(this instanceof Q))return new Q(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var h=0,f=0,g,k;f<b.index.length;f++){g=b.index[f];k=g.indexOf(e);if(0<=k)return h+k;h+=g.length}return-1};
if("includes"===d)return function(e){for(var h=0;h<b.index.length;h++)if(b.index[h].includes(e))return!0;return!1};if("slice"===d)return function(e,h){return Ka(b,e||0,h||b.length,!1)};if("splice"===d)return function(e,h){return Ka(b,e||0,h||b.length,!0)};if("constructor"===d)return Array;if("symbol"!==typeof d)return(c=b.index[d/Math.pow(2,31)|0])&&c[d]},set:function(c,d,e){c=d/Math.pow(2,31)|0;(b.index[c]||(b.index[c]=[]))[d]=e;b.length++;return!0}})}
Q.prototype.clear=function(){this.index.length=0};Q.prototype.push=function(){};function R(a){a=void 0===a?8:a;if(!(this instanceof R))return new R(a);this.index=I();this.C=[];this.size=0;32<a?(this.h=La,this.A=BigInt(a)):(this.h=Ma,this.A=a)}R.prototype.get=function(a){var b=this.h(a);return(b=this.index[b])&&b.get(a)};R.prototype.set=function(a,b){var c=this.h(a),d=this.index[c];d?(c=d.size,d.set(a,b),(c-=d.size)&&this.size++):(this.index[c]=d=new Map([[a,b]]),this.C.push(d))};
function S(a){a=void 0===a?8:a;if(!(this instanceof S))return new S(a);this.index=I();this.h=[];32<a?(this.C=La,this.A=BigInt(a)):(this.C=Ma,this.A=a)}S.prototype.add=function(a){var b=this.C(a),c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.h.push(c))};w=R.prototype;w.has=S.prototype.has=function(a){var b=this.C(a);return(b=this.index[b])&&b.has(a)};w.delete=S.prototype.delete=function(a){var b=this.C(a);(b=this.index[b])&&b.delete(a)&&this.size--};
w.clear=S.prototype.clear=function(){this.index=I();this.h=[];this.size=0};w.values=S.prototype.values=function Na(){var b,c=this,d,e,h;return sa(Na,function(f){switch(f.h){case 1:b=0;case 2:if(!(b<c.h.length)){f.h=0;break}d=y(c.h[b].values());e=d.next();case 5:if(e.done){b++;f.h=2;break}h=e.value;return F(f,h,6);case 6:e=d.next(),f.h=5}})};
w.keys=S.prototype.keys=function Oa(){var b,c=this,d,e,h;return sa(Oa,function(f){switch(f.h){case 1:b=0;case 2:if(!(b<c.h.length)){f.h=0;break}d=y(c.h[b].keys());e=d.next();case 5:if(e.done){b++;f.h=2;break}h=e.value;return F(f,h,6);case 6:e=d.next(),f.h=5}})};
w.entries=S.prototype.entries=function Pa(){var b,c=this,d,e,h;return sa(Pa,function(f){switch(f.h){case 1:b=0;case 2:if(!(b<c.h.length)){f.h=0;break}d=y(c.h[b].entries());e=d.next();case 5:if(e.done){b++;f.h=2;break}h=e.value;return F(f,h,6);case 6:e=d.next(),f.h=5}})};function Ma(a){var b=Math.pow(2,this.A)-1;if("number"==typeof a)return a&b;for(var c=0,d=this.A+1,e=0;e<a.length;e++)c=(c*d^a.charCodeAt(e))&b;return 32===this.A?c+Math.pow(2,31):c}
function La(){throw Error("The keystore is limited to 32 for EcmaScript5");};function Qa(a,b,c,d,e,h,f,g){(d=a(c?c+"."+d:d,JSON.stringify(f)))&&d.then?d.then(function(){b.export(a,b,c,e,h+1,g)}):b.export(a,b,c,e,h+1,g)};var Ra=I(),T=I();var Sa={normalize:function(a){return a.toLowerCase()},H:!1};var Ta={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};function Ua(a){Va.call(a,"add");Va.call(a,"append");Va.call(a,"search");Va.call(a,"update");Va.call(a,"remove")}function Va(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]}this.async=!0;b=this[a].apply(this,b);this.async=!1;b.then?b.then(d):d(b);return b}};I();U.prototype.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.B.has(a))return this.update(a,b);b=this.encoder.encode(b);if(d=b.length){for(var e=I(),h=I(),f=this.depth,g=this.resolution,k=0;k<d;k++){var l=b[this.rtl?d-1-k:k],m=l.length;if(m&&(f||!h[l])){var n=this.score?this.score(b,l,k,null,0):Wa(g,d,k),p="";switch(this.tokenize){case "full":if(2<m){for(n=0;n<m;n++)for(var q=m;q>n;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):Wa(g,d,k,m,n);Xa(this,h,p,r,a,c)}break}case "reverse":if(1<
m){for(q=m-1;0<q;q--)p=l[q]+p,r=this.score?this.score(b,l,k,p,q):Wa(g,d,k,m,q),Xa(this,h,p,r,a,c);p=""}case "forward":if(1<m){for(q=0;q<m;q++)p+=l[q],Xa(this,h,p,n,a,c);break}default:if(Xa(this,h,l,n,a,c),f&&1<d&&k<d-1)for(m=I(),p=this.na,n=l,q=Math.min(f+1,d-k),r=m[n]=1;r<q;r++)if((l=b[this.rtl?d-1-k-r:k+r])&&!m[l]){m[l]=1;var x=this.score?this.score(b,n,k,l,r):Wa(p+(d/2>p?0:1),d,k,q-1,r-1),u=this.bidirectional&&l>n;Xa(this,e,u?n:l,x,a,c,u?l:n)}}}}this.fastupdate||this.B.add(a)}else b=""}this.db&&
(b||this.X.push({del:a}),this.qa&&Ya(this));return this};
function Xa(a,b,c,d,e,h,f){var g=f?a.M:a.map,k;if(!b[c]||!f||!(k=b[c])[f])if(f?(b=k||(b[c]=I()),b[f]=1,(k=g.get(f))?g=k:g.set(f,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!h||!g.includes(e)){if(g.length===Math.pow(2,31)-1){b=new Q(g);if(a.fastupdate)for(c=y(a.B.values()),h=c.next();!h.done;h=c.next())h=h.value,h.includes(g)&&(h[h.indexOf(g)]=b);k[d]=g=b}g.push(e);a.fastupdate&&((d=a.B.get(e))?d.push(g):a.B.set(e,[g]))}}
function Wa(a,b,c,d,e){return c&&1<a?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0};function V(a,b,c,d){if(1===a.length)return a=a[0],a=c||a.length>b?b?a.slice(c,c+b):a.slice(c):a,d?Za(a):a;for(var e=[],h=0,f=void 0,g=void 0;h<a.length;h++)if((f=a[h])&&(g=f.length)){if(c){if(c>=g){c-=g;continue}c<g&&(f=b?f.slice(c,c+b):f.slice(c),g=f.length,c=0)}if(e.length)g>b&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),d?Za(f):f;e=[f]}b-=g;if(!b)break}if(!e.length)return e;e=1<e.length?[].concat.apply([],e):e[0];return d?Za(e):e}
function Za(a){for(var b=0;b<a.length;b++)a[b]={score:b,id:a[b]};return a};W.prototype.or=function(){var a=this,b=arguments,c=b[0];if(c instanceof Promise)return c.then(function(){return a.or.apply(a,b)});if(c[0]&&c[0].index)return this.or.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;k<b.length;k++)if(l=b[k]){var m=void 0;if(l instanceof W)m=l.result;else if(l.constructor===Array)m=l;else if(l.index)l.resolve=!1,m=l.index.search(l).result;else if(l.and)m=this.and(l.and);else if(l.xor)m=this.xor(l.xor);else if(l.J)m=this.J(l.J);else{e=l.limit||0;h=l.offset||
0;f=l.enrich;g=l.resolve;continue}d[k]=m;m instanceof Promise&&c.push(m)}if(c.length)return Promise.all(c).then(function(){a.result.length&&(d=[a.result].concat(d));a.result=$a(d,e,h,f,g,a.V);return g?a.result:a});this.result.length&&(d=[this.result].concat(d));this.result=$a(d,e,h,f,g,a.V);return g?this.result:this};
function $a(a,b,c,d,e,h){if(!a.length)return a;"object"===typeof b&&(c=b.offset||0,d=b.enrich||!1,b=b.limit||0);if(2>a.length)return e?V(a[0],b,c,d):a[0];d=[];for(var f=0,g=I(),k=Ba(a),l=0,m;l<k;l++)for(var n=0;n<a.length;n++)if(m=a[n])if(m=m[l])for(var p=0,q;p<m.length;p++)if(q=m[p],!g[q])if(g[q]=1,c)c--;else{if(e)d.push(q);else{var r=l+(n?h:0);d[r]||(d[r]=[]);d[r].push(q)}if(b&&++f===b)return d}return d};W.prototype.and=function(){if(this.result.length){var a=this,b=arguments,c=b[0];if(c instanceof Promise)return c.then(function(){return a.and.apply(a,b)});if(c[0]&&c[0].index)return this.and.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g=0,k=void 0;g<b.length;g++)if(k=b[g]){var l=void 0;if(k instanceof W)l=k.result;else if(k.constructor===Array)l=k;else if(k.index)k.resolve=!1,l=k.index.search(k).result;else if(k.or)l=this.or(k.or);else if(k.xor)l=this.xor(k.xor);else if(k.J)l=this.J(k.J);else{e=
k.limit||0;h=k.offset||0;f=k.resolve;continue}d[g]=l;l instanceof Promise&&c.push(l)}if(c.length)return Promise.all(c).then(function(){d=[a.result].concat(d);a.result=ab(d,e,h,f,a.V);return f?a.result:a});d=[this.result].concat(d);this.result=ab(d,e,h,f,a.V);return f?this.result:this}return this};
function ab(a,b,c,d,e){if(2>a.length)return[];var h=[],f=0,g=I(),k=Ba(a);if(!k)return h;for(var l=0,m;l<a.length;l++){m=a[l];if(!m||!m.length)return[];for(var n=I(),p=0,q=l===a.length-1,r=0,x;r<k;r++)if(x=m[r])for(var u=0,t,v;u<x.length;u++)if(t=x[u],!l)n[t]=r+1+(l?e:0),p=1;else if(q){if(v=g[t])if(p=1,c)c--;else if(d?h.push(t):(v--,r<v&&(v=r),h[v]||(h[v]=[]),h[v].push(t)),b&&++f===b)return h}else if(v=g[t])r+1<v&&(v=r+1),n[t]=v,p=1;if(!p)return[];g=n}return h};W.prototype.xor=function(){var a=this,b=arguments,c=b[0];if(c instanceof Promise)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;k<b.length;k++)if(l=b[k]){var m=void 0;if(l instanceof W)m=l.result;else if(l.constructor===Array)m=l;else if(l.index)l.resolve=!1,m=l.index.search(l).result;else if(l.or)m=this.or(l.or);else if(l.and)m=this.and(l.and);else if(l.J)m=this.J(l.J);else{e=l.limit||0;h=l.offset||
0;f=l.enrich;g=l.resolve;continue}d[k]=m;m instanceof Promise&&c.push(m)}if(c.length)return Promise.all(c).then(function(){a.result.length&&(d=[a.result].concat(d));a.result=bb(d,e,h,f,!g,a.V);return g?a.result:a});this.result.length&&(d=[this.result].concat(d));this.result=bb(d,e,h,f,!g,a.V);return g?this.result:this};
function bb(a,b,c,d,e,h){if(!a.length)return a;if(2>a.length)return e?V(a[0],b,c,d):a[0];b=[];c=I();d=0;for(var f;d<a.length;d++)if(f=a[d])for(var g=0,k;g<f.length;g++)if(k=f[g])for(var l=0,m;l<k.length;l++)m=k[l],c[m]?c[m]++:c[m]=1;for(d=0;d<a.length;d++)if(f=a[d])for(g=0;g<f.length;g++)if(k=f[g])for(l=0;l<k.length;l++)if(m=k[l],1===c[m])if(e)b.push(m);else{var n=g+(d?h:0);b[n]||(b[n]=[]);b[n].push(m)}return b};W.prototype.J=function(){var a=this,b=arguments,c=b[0];if(c instanceof Promise)return c.then(function(){return a.J.apply(a,b)});if(c[0]&&c[0].index)return this.J.apply(this,c);var d=[];c=[];for(var e,h=0,f=void 0;h<b.length;h++)if(f=b[h]){var g=void 0;if(f instanceof W)g=f.result;else if(f.constructor===Array)g=f;else if(f.index)f.resolve=!1,g=f.index.search(f).result;else if(f.or)g=this.or(f.or);else if(f.and)g=this.and(f.and);else if(f.xor)g=this.xor(f.xor);else{e=f.resolve;continue}d[h]=g;g instanceof
Promise&&c.push(g)}if(c.length)return Promise.all(c).then(function(){a.result=cb.call(a,d,e);return e?a.result:a});this.result=cb.call(this,d,e);return e?this.result:this};function cb(a,b){if(!a.length)return this.result;var c=[];a=new Set(a.flat().flat());for(var d=0,e;d<this.result.length;d++)if(e=this.result[d])for(var h=0,f;h<e.length;h++)f=e[h],a.has(f)||(b?c.push(f):(c[d]||(c[d]=[]),c[d].push(f)));return c};function W(a){if(a&&a.index)return a.resolve=!1,this.index=a.index,a.index.search(a);if(!(this instanceof W))return new W(a);if(a instanceof W)return a;this.index=null;this.result=a||[];this.V=0}W.prototype.limit=function(a){if(this.result.length)for(var b=[],c=0,d=0,e;d<this.result.length;d++)if(e=this.result[d],e.length+c<a)b[d]=e,c+=e.length;else{b[d]=e.slice(0,a-c);this.result=b;break}return this};
W.prototype.offset=function(a){if(this.result.length){for(var b=[],c=0,d=0,e;d<this.result.length;d++)e=this.result[d],e.length+c<a?c+=e.length:(b[d]=e.slice(a-c),c=a);this.result=b}return this};W.prototype.resolve=function(a,b,c){db=1;var d=this.result;this.result=this.index=null;return d.length?("object"===typeof a&&(c=a.enrich,b=a.offset,a=a.limit),V(d,a||100,b,c)):d};function eb(a,b,c,d){var e=a.length,h=[],f=0,g;d&&(d=[]);for(var k=e-1,l;0<=k;k--){var m=a[k];e=I();l=!x;for(var n=0,p;n<m.length;n++)if((p=m[n])&&p.length)for(var q=0,r;q<p.length;q++)if(r=p[q],x){if(x[r]){if(!k)if(c)c--;else if(h[f++]=r,f===b)return h;if(k||d)e[r]=1;l=!0}d&&!g[r]&&(g[r]=1,(d[n]||(d[n]=[])).push(r))}else e[r]=1;if(d)x||(g=e);else if(!l)return[];var x=e}if(d)for(a=d.length-1;0<=a;a--)for(g=d[a],e=g.length,m=0;m<e;m++)if(k=g[m],!x[k]){if(c)c--;else if(h[f++]=k,f===b)return h;x[k]=
1}return h}function fb(a,b){for(var c=I(),d=I(),e=[],h=0;h<a.length;h++)c[a[h]]=1;for(a=0;a<b.length;a++){h=b[a];for(var f=0,g;f<h.length;f++)g=h[f],c[g]&&!d[g]&&(d[g]=1,e.push(g))}return e};var db=1;
U.prototype.search=function(a,b,c){c||(!b&&K(a)?(c=a,a=""):K(b)&&(c=b,b=0));var d=[],e=0,h;if(c){a=c.query||a;b=c.limit||b;e=c.offset||0;var f=c.context;var g=c.suggest;(h=db&&!1!==c.resolve)||(db=0);var k=h&&c.enrich;var l=this.db&&c.tag}else h=this.resolve||db;a=this.encoder.encode(a);var m=a.length;b||!h||(b=100);if(1===m)return gb.call(this,a[0],"",b,e,h,k,l);f=this.depth&&!1!==f;if(2===m&&f&&!g)return gb.call(this,a[0],a[1],b,e,h,k,l);var n=c=0;if(1<m){for(var p=I(),q=[],r=0,x=void 0;r<m;r++)if((x=
a[r])&&!p[x]){if(g||this.db||X(this,x))q.push(x),p[x]=1;else return h?d:new W(d);x=x.length;c=Math.max(c,x);n=n?Math.min(n,x):x}a=q;m=a.length}if(!m)return h?d:new W(d);var u=0;if(1===m)return gb.call(this,a[0],"",b,e,h,k,l);if(2===m&&f&&!g)return gb.call(this,a[0],a[1],b,e,h,k,l);if(1<m)if(f){var t=a[0];u=1}else 9<c&&3<c/n&&a.sort(ya);if(this.db){if(this.db.search&&(f=this.db.search(this,a,b,e,g,h,k,l),!1!==f))return f;var v=this;return function(){var A,C,D;return ua(function(E){switch(E.h){case 1:C=
A=void 0;case 2:if(!(u<m)){E.h=4;break}C=a[u];return t?F(E,X(v,C,t),8):F(E,X(v,C),7);case 7:A=E.G;A=hb(A,d,g,v.resolution,b,e,1===m);E.h=6;break;case 8:A=E.G,A=hb(A,d,g,v.na,b,e,2===m),g&&!1===A&&d.length||(t=C);case 6:if(A)return E.return(A);if(g&&u===m-1){D=d.length;if(!D){if(t){t="";u=-1;E.h=3;break}return E.return(d)}if(1===D)return E.return(h?V(d[0],b,e):new W(d[0]))}case 3:u++;E.h=2;break;case 4:return E.return(h?eb(d,b,e,g):new W(d[0]))}})}()}for(k=f=void 0;u<m;u++){k=a[u];t?(f=X(this,k,t),
f=hb(f,d,g,this.na,b,e,2===m),g&&!1===f&&d.length||(t=k)):(f=X(this,k),f=hb(f,d,g,this.resolution,b,e,1===m));if(f)return f;if(g&&u===m-1){f=d.length;if(!f){if(t){t="";u=-1;continue}return d}if(1===f)return h?V(d[0],b,e):new W(d[0])}}return h?eb(d,b,e,g):new W(d[0])};function gb(a,b,c,d,e,h,f){a=X(this,a,b,c,d,e,h,f);return this.db?a.then(function(g){return e?g:g&&g.length?e?V(g,c,d):new W(g):e?[]:new W([])}):a&&a.length?e?V(a,c,d):new W(a):e?[]:new W([])}
function hb(a,b,c,d,e,h,f){var g=[];if(a){d=Math.min(a.length,d);for(var k=0,l=0,m;k<d;k++)if(m=a[k])if(h&&m&&f&&(m.length<=h?(h-=m.length,m=null):(m=m.slice(h),h=0)),m&&(g[k]=m,f&&(l+=m.length,l>=e)))break;if(g.length){if(f)return V(g,e,0);b.push(g);return}}return!c&&g}function X(a,b,c,d,e,h,f,g){var k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,h,f,g):a.db.get(b,"",d,e,h,f,g);a=c?(a=a.M.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};U.prototype.remove=function(a,b){var c=this.B.size&&(this.fastupdate?this.B.get(a):this.B.has(a));if(c){if(this.fastupdate)for(var d=0,e;d<c.length;d++){if(e=c[d])if(2>e.length)e.pop();else{var h=e.indexOf(a);h===c.length-1?e.pop():e.splice(h,1)}}else ib(this.map,a),this.depth&&ib(this.M,a);b||this.B.delete(a)}this.db&&(this.X.push({del:a}),this.qa&&Ya(this));this.cache&&this.cache.remove(a);return this};
function ib(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,h;d<a.length;d++){if((e=a[d])&&e.length)if(h=e.indexOf(b),0<=h){1<e.length?(e.splice(h,1),c++):delete a[d];break}else c++}else for(d=y(a),e=d.next();!e.done;e=d.next())h=e.value,e=h[0],(h=ib(h[1],b))?c+=h:a.delete(e);return c};function U(a,b){if(!(this instanceof U))return new U(a);if(a){var c=J(a)?a:a.preset;c&&(a=Object.assign({},Ta[c],a))}else a={};c=a.context||{};var d=a.encode||a.encoder||Sa;this.encoder=d.encode?d:"object"===typeof d?new M(d):{encode:d};var e;this.resolution=a.resolution||9;this.tokenize=e=a.tokenize||"strict";this.depth="strict"===e&&c.depth||0;this.bidirectional=!1!==c.bidirectional;this.fastupdate=!!a.fastupdate;this.score=a.score||null;(e=a.keystore||0)&&(this.keystore=e);this.map=e?new R(e):
new Map;this.M=e?new R(e):new Map;this.B=b||(this.fastupdate?e?new R(e):new Map:e?new S(e):new Set);this.na=c.resolution||1;this.rtl=d.rtl||a.rtl||!1;this.cache=(e=a.cache||null)&&new N(e);this.resolve=!1!==a.resolve;if(e=a.db)this.db=e.mount(this);this.qa=!1!==a.commit;this.X=[];this.h=null}w=U.prototype;w.mount=function(a){this.h&&(clearTimeout(this.h),this.h=null);return a.mount(this)};w.commit=function(a,b){this.h&&(clearTimeout(this.h),this.h=null);return this.db.commit(this,a,b)};
function Ya(a){a.h||(a.h=setTimeout(function(){a.h=null;a.db.commit(a,void 0,void 0)},0))}w.clear=function(){this.map.clear();this.M.clear();this.B.clear();this.cache&&this.cache.clear();this.db&&(this.h&&clearTimeout(this.h),this.h=null,this.X=[{clear:!0}]);return this};w.append=function(a,b){return this.add(a,b,!0)};w.contain=function(a){return this.db?this.db.has(a):this.B.has(a)};
w.update=function(a,b){if(this.async){var c=this,d=this.remove(a);return d.then?d.then(function(){return c.add(a,b)}):this.add(a,b)}return this.remove(a).add(a,b)};function jb(a){var b=0;if(a.constructor===Array)for(var c=0,d=void 0;c<a.length;c++)(d=a[c])&&(b+=d.length);else for(c=y(a),d=c.next();!d.done;d=c.next()){var e=d.value;d=e[0];(e=jb(e[1]))?b+=e:a.delete(d)}return b}w.cleanup=function(){if(!this.fastupdate)return this;jb(this.map);this.depth&&jb(this.M);return this};w.searchCache=Ja;
w.export=function(a,b,c,d,e,h){var f=!0;"undefined"===typeof h&&(f=new Promise(function(n){h=n}));switch(e||(e=0)){case 0:var g="reg";if(this.fastupdate){var k=I();for(var l=y(this.B.keys()),m=l.next();!m.done;m=l.next())k[m.value]=1}else k=this.B;break;case 1:g="cfg";k={doc:0,opt:this.A?1:0};break;case 2:g="map";k=this.map;break;case 3:g="ctx";k=this.M;break;default:"undefined"===typeof c&&h&&h();return}Qa(a,b||this,c,g,d,e,k,h);return f};
w.import=function(a,b){if(b)switch(J(b)&&(b=JSON.parse(b)),a){case "cfg":this.A=!!b.opt;break;case "reg":this.fastupdate=!1;this.B=b;break;case "map":this.map=b;break;case "ctx":this.M=b}};Ua(U.prototype);function kb(a){var b,c,d,e,h,f,g,k;return ua(function(l){a=a.data;b=self._index;c=a.args;d=a.task;switch(d){case "init":e=a.options||{};(h=e.config)&&(e=await import(h));(f=a.factory)?(Function("return "+f)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new U(e);postMessage({id:a.id});break;default:g=a.id,k=b[d].apply(b,c),postMessage("search"===d?{id:g,msg:k}:{id:g})}l.h=0})};var lb=0;
function Y(a){function b(h){h=h.data||h;var f=h.id,g=f&&e.h[f];g&&(g(h.msg),delete e.h[f])}if(!(this instanceof Y))return new Y(a);a||(a={});var c=(self||window)._factory;c&&(c=c.toString());var d="undefined"===typeof window&&self.exports,e=this;this.worker=mb(c,d,a.worker);this.h=I();if(this.worker){d?this.worker.on("message",b):this.worker.onmessage=b;if(a.config)return new Promise(function(h){e.h[++lb]=function(){h(e)};e.worker.postMessage({id:lb,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,
options:a})}}nb("add");nb("append");nb("search");nb("update");nb("remove");function nb(a){Y.prototype[a]=Y.prototype[a+"Async"]=function(){var b=this,c=[].slice.call(arguments),d=c[c.length-1];if("function"===typeof d){var e=d;c.splice(c.length-1,1)}d=new Promise(function(h){b.h[++lb]=h;b.worker.postMessage({task:a,id:lb,args:c})});return e?(d.then(e),this):d}}
function mb(a,b,c){return b?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+kb.toString()],{type:"text/javascript"}))):new window.Worker(J(c)?c:"worker/worker.js",{type:"module"})};Z.prototype.add=function(a,b,c){K(a)&&(b=a,a=Aa(b,this.key));if(b&&(a||0===a)){if(!c&&this.B.has(a))return this.update(a,b);for(var d=0,e;d<this.field.length;d++){e=this.T[d];var h=this.index.get(this.field[d]);if("function"===typeof e)(e=e(b))&&h.add(a,e,!1,!0);else{var f=e.aa;if(!f||f(b))e instanceof String?e=[""+e]:J(e)&&(e=[e]),ob(b,e,this.da,0,h,a,e[0],c)}}if(this.tag)for(d=0;d<this.S.length;d++){f=this.S[d];h=this.tag.get(this.ma[d]);e=I();if("function"===typeof f){if(f=f(b),!f)continue}else{var g=
f.aa;if(g&&!g(b))continue;f instanceof String&&(f=""+f);f=Aa(b,f)}if(h&&f){J(f)&&(f=[f]);g=0;for(var k,l=void 0;g<f.length;g++)if(k=f[g],!e[k]){e[k]=1;var m;(m=h.get(k))?l=m:h.set(k,l=[]);if(!c||!l.includes(a)){if(l.length===Math.pow(2,31)-1){m=new Q(l);if(this.fastupdate)for(var n=y(this.B.values()),p=n.next();!p.done;p=n.next())p=p.value,p.includes(l)&&(p[p.indexOf(l)]=m);h.set(k,l=m)}l.push(a);this.fastupdate&&((k=this.B.get(a))?k.push(l):this.B.set(a,[l]))}}}}if(this.store&&(!c||!this.store.has(a))){if(this.L){var q=
I();for(c=0;c<this.L.length;c++)if(d=this.L[c],h=d.aa,!h||h(b)){h=void 0;if("function"===typeof d){h=d(b);if(!h)continue;d=[d.Aa]}else if(J(d)||d instanceof String){q[d]=b[d];continue}pb(b,q,d,0,d[0],h)}}this.store.set(a,q||b)}}return this};function pb(a,b,c,d,e,h){a=a[e];if(d===c.length-1)b[e]=h||a;else if(a)if(a.constructor===Array)for(b=b[e]=Array(a.length),e=0;e<a.length;e++)pb(a,b,c,d,e);else b=b[e]||(b[e]=I()),e=c[++d],pb(a,b,c,d,e)}
function ob(a,b,c,d,e,h,f,g){if(a=a[f])if(d===b.length-1){if(a.constructor===Array){if(c[d]){for(b=0;b<a.length;b++)e.add(h,a[b],!0,!0);return}a=a.join(" ")}e.add(h,a,g,!0)}else if(a.constructor===Array)for(f=0;f<a.length;f++)ob(a,b,c,d,e,h,f,g);else f=b[++d],ob(a,b,c,d,e,h,f,g);else e.db&&e.remove(h)};Z.prototype.search=function(a,b,c,d){c||(!b&&K(a)?(c=a,a=""):K(b)&&(c=b,b=0));var e=[],h=[],f=0;if(c)if(c.constructor===Array){var g=c;c=null}else{a=c.query||a;var k=c.pluck;var l=c.merge;g=k||c.field||c.index;var m=this.tag&&c.tag;var n=this.store&&c.enrich;var p=c.suggest;b=c.limit||b;var q=c.offset||0;b||(b=100);if(m&&(!this.db||!d)){m.constructor!==Array&&(m=[m]);for(var r=[],x=0,u=void 0;x<m.length;x++)if(u=m[x],u.field&&u.tag){var t=u.tag;if(t.constructor===Array)for(var v=0;v<t.length;v++)r.push(u.field,
t[v]);else r.push(u.field,t)}else{t=Object.keys(u);v=0;for(var A=void 0,C=void 0;v<t.length;v++)if(A=t[v],C=u[A],C.constructor===Array)for(var D=0;D<C.length;D++)r.push(A,C[D]);else r.push(A,C)}m=r;if(!a){h=[];if(r.length)for(k=0;k<r.length;k+=2){p=void 0;if(this.db){p=this.index.get(r[k]);if(!p)continue;h.push(p=p.db.tag(r[k+1],b,q,n))}else p=qb.call(this,r[k],r[k+1],b,q,n);e.push({field:r[k],tag:r[k+1],result:p})}return h.length?Promise.all(h).then(function(O){for(var P=0;P<O.length;P++)e[P].result=
O[P];return e}):e}}J(g)&&(g=[g])}g||(g=this.field);r=!d&&(this.worker||this.async)&&[];x=0;for(v=u=t=void 0;x<g.length;x++)if(u=g[x],!this.db||!this.tag||this.T[x]){t=void 0;J(u)||(t=u,u=t.field,a=t.query||a,b=t.limit||b,p=t.suggest||p);if(d)t=d[x];else{v=t||c;t=this.index.get(u);if(m){if(this.db){v.tag=m;var E=t.db.Fa;v.field=g}E||(v.enrich=!1)}if(r){r[x]=t.searchAsync(a,b,v);v&&n&&(v.enrich=n);continue}else t=t.search(a,b,v),v&&n&&(v.enrich=n)}v=t&&t.length;if(m&&v){A=[];C=0;if(this.db&&d){if(!E)for(D=
g.length;D<d.length;D++){var L=d[D];if(L&&L.length)C++,A.push(L);else if(!p)return e}}else{D=0;for(var Fb=L=void 0;D<m.length;D+=2){L=this.tag.get(m[D]);if(!L)if(p)continue;else return e;if(Fb=(L=L&&L.get(m[D+1]))&&L.length)C++,A.push(L);else if(!p)return e}}if(C){t=fb(t,A);v=t.length;if(!v&&!p)return e;C--}}if(v)h[f]=u,e.push(t),f++;else if(1===g.length)return e}if(r){if(this.db&&m&&m.length&&!E)for(n=0;n<m.length;n+=2){h=this.index.get(m[n]);if(!h)if(p)continue;else return e;r.push(h.db.tag(m[n+
1],b,q,!1))}var Gb=this;return Promise.all(r).then(function(O){return O.length?Gb.search(a,b,c,O):O})}if(!f)return e;if(k&&(!n||!this.store))return e[0];r=[];q=0;for(p=void 0;q<h.length;q++){p=e[q];n&&p.length&&!p[0].doc&&(this.db?r.push(p=this.index.get(this.field[0]).db.enrich(p)):p.length&&(p=rb.call(this,p)));if(k)return p;e[q]={field:h[q],result:p}}return n&&this.db&&r.length?Promise.all(r).then(function(O){for(var P=0;P<O.length;P++)e[P].result=O[P];return l?sb(e,b):e}):l?sb(e,b):e};
function sb(a,b){for(var c=[],d=I(),e=0,h,f;e<a.length;e++){h=a[e];f=h.result;for(var g=0,k,l,m;g<f.length;g++)if(l=f[g],k=l.id,m=d[k])m.push(h.field);else{if(c.length===b)return c;l.field=d[k]=[h.field];c.push(l)}}return c}function qb(a,b,c,d,e){a=this.tag.get(a);if(!a)return[];if((b=(a=a&&a.get(b))&&a.length-d)&&0<b){if(b>c||d)a=a.slice(d,d+c);e&&(a=rb.call(this,a));return a}}function rb(a){for(var b=Array(a.length),c=0,d;c<a.length;c++)d=a[c],b[c]={id:d,doc:this.store.get(d)};return b};function Z(a){if(!(this instanceof Z))return new Z(a);var b=a.document||a.doc||a,c,d;this.T=[];this.field=[];this.da=[];this.key=(c=b.key||b.id)&&tb(c,this.da)||"id";(d=a.keystore||0)&&(this.keystore=d);this.B=(this.fastupdate=!!a.fastupdate)?d?new R(d):new Map:d?new S(d):new Set;this.L=(c=b.store||null)&&!0!==c&&[];this.store=c&&(d?new R(d):new Map);this.cache=(c=a.cache||null)&&new N(c);a.cache=!1;this.worker=a.worker;this.async=!1;c=new Map;d=b.index||b.field||b;J(d)&&(d=[d]);for(var e=0,h,f=void 0;e<
d.length;e++){h=d[e];J(h)||(f=h,h=h.field);f=K(f)?Object.assign({},a,f):a;if(this.worker){var g=new Y(f);c.set(h,g);g.worker||(this.worker=!1)}this.worker||c.set(h,new U(f,this.B));f.Y?this.T[e]=f.Y:(this.T[e]=tb(h,this.da),f.filter&&("string"===typeof this.T[e]&&(this.T[e]=new String(this.T[e])),this.T[e].aa=f.filter));this.field[e]=h}if(this.L)for(d=b.store,J(d)&&(d=[d]),e=0;e<d.length;e++)h=d[e],f=h.field||h,h.Y?(this.L[e]=h.Y,h.Y.Aa=f):(this.L[e]=tb(f,this.da),h.filter&&("string"===typeof this.L[e]&&
(this.L[e]=new String(this.L[e])),this.L[e].aa=h.filter));this.index=c;this.tag=null;if(c=b.tag)if("string"===typeof c&&(c=[c]),c.length)for(this.tag=new Map,this.S=[],this.ma=[],b=0;b<c.length;b++){d=c[b];e=d.field||d;if(!e)throw Error("The tag field from the document descriptor is undefined.");d.Y?this.S[b]=d.Y:(this.S[b]=tb(e,this.da),d.filter&&("string"===typeof this.S[b]&&(this.S[b]=new String(this.S[b])),this.S[b].aa=d.filter));this.ma[b]=e;this.tag.set(e,new Map)}a.db&&this.mount(a.db)}w=Z.prototype;
w.mount=function(a){var b=this.field;if(this.tag)for(var c=0,d;c<this.ma.length;c++){d=this.ma[c];var e=this.index.get(d);e||(this.index.set(d,e=new U({},this.B)),b===this.field&&(b=b.slice(0)),b.push(d));e.tag=this.tag.get(d)}c=[];d={db:a.db,type:a.type,fastupdate:a.fastupdate};e=0;for(var h;e<b.length;e++){d.field=h=b[e];h=this.index.get(h);var f=new a.constructor(a.id,d);f.id=a.id;c[e]=f.mount(h);h.document=!0;e?h.Ba=!0:h.store=this.store}this.db=this.async=!0;return Promise.all(c)};
w.commit=function(a,b){var c=this,d,e,h,f;return ua(function(g){if(1==g.h){d=[];e=y(c.index.values());for(h=e.next();!h.done;h=e.next())f=h.value,d.push(f.db.commit(f,a,b));return F(g,Promise.all(d),2)}c.B.clear();g.h=0})};function tb(a,b){for(var c=a.split(":"),d=0,e=0;e<c.length;e++)a=c[e],"]"===a[a.length-1]&&(a=a.substring(0,a.length-2))&&(b[d]=!0),a&&(c[d++]=a);d<c.length&&(c.length=d);return 1<d?c:c[0]}w.append=function(a,b){return this.add(a,b,!0)};
w.update=function(a,b){return this.remove(a).add(a,b)};
w.remove=function(a){K(a)&&(a=Aa(a,this.key));for(var b=y(this.index.values()),c=b.next();!c.done;c=b.next())c.value.remove(a,!0);if(this.B.has(a)){if(this.tag&&!this.fastupdate)for(b=y(this.tag.values()),c=b.next();!c.done;c=b.next()){c=c.value;for(var d=y(c),e=d.next();!e.done;e=d.next()){var h=e.value;e=h[0];h=h[1];var f=h.indexOf(a);-1<f&&(1<h.length?h.splice(f,1):c.delete(e))}}this.store&&this.store.delete(a);this.B.delete(a)}this.cache&&this.cache.remove(a);return this};
w.clear=function(){for(var a=y(this.index.values()),b=a.next();!b.done;b=a.next())b.value.clear();if(this.tag)for(a=y(this.tag.values()),b=a.next();!b.done;b=a.next())b.value.clear();this.store&&this.store.clear();return this};w.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.B.has(a)};w.cleanup=function(){for(var a=y(this.index.values()),b=a.next();!b.done;b=a.next())b.value.cleanup();return this};
w.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(b){return b[0]&&b[0].doc}):this.store.get(a)};w.set=function(a,b){this.store.set(a,b);return this};w.searchCache=Ja;
w.export=function(a,b,c,d,e,h){var f;"undefined"===typeof h&&(f=new Promise(function(k){h=k}));e||(e=0);d||(d=0);if(d<this.field.length){c=this.field[d];var g=this.index[c];b=this;g.export(a,b,e?c:"",d,e++,h)||(d++,b.export(a,b,c,d,1,h))}else{switch(e){case 1:b="tag";g=this.h;c=null;break;case 2:b="store";g=this.store;c=null;break;default:h();return}Qa(a,this,c,b,d,e,g,h)}return f};
w.import=function(a,b){if(b)switch(J(b)&&(b=JSON.parse(b)),a){case "tag":this.h=b;break;case "reg":this.fastupdate=!1;this.B=b;a=0;for(var c;a<this.field.length;a++)c=this.index[this.field[a]],c.B=b,c.fastupdate=!1;break;case "store":this.store=b;break;default:a=a.split("."),c=a[0],a=a[1],c&&a&&this.index[c].import(a,b)}};Ua(Z.prototype);var ub="undefined"!==typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),vb=["map","ctx","tag","reg","cfg"];
function wb(a,b){b=void 0===b?{}:b;if(!(this instanceof wb))return new wb(a,b);"object"===typeof a&&(b=a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=b.field?b.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.Fa=!1;this.db=null;this.h={}}w=wb.prototype;w.mount=function(a){if(a instanceof Z)return a.mount(this);a.db=this;return xb(this)};
function xb(a){navigator.storage&&navigator.storage.persist();return a.db||new Promise(function(b,c){var d=ub.open(a.id+(a.field?":"+a.field:""),1);d.onupgradeneeded=function(){var e=a.db=this.result;vb.forEach(function(h){e.objectStoreNames.contains(h)||e.createObjectStore(h)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}
w.close=function(){this.db.close();this.db=null};w.clear=function(){for(var a=this.db.transaction(vb,"readwrite"),b=0;b<vb.length;b++)a.objectStore(vb[b]).clear();return yb(a)};
w.get=function(a,b,c,d,e,h){c=void 0===c?0:c;d=void 0===d?0:d;e=void 0===e?!0:e;h=void 0===h?!1:h;a=this.db.transaction(b?"ctx":"map","readonly").objectStore(b?"ctx":"map").get(b?b+":"+a:a);var f=this;return yb(a).then(function(g){var k=[];if(!g||!g.length)return k;if(e){if(!c&&!d&&1===g.length)return g[0];for(var l=0,m=void 0;l<g.length;l++)if((m=g[l])&&m.length)if(d>=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p<n;p++)k.push(m[p]);d=0;if(k.length===c)break}return h?
f.enrich(k):k}return g})};w.tag=function(a,b,c,d){b=void 0===b?0:b;c=void 0===c?0:c;d=void 0===d?!1:d;a=this.db.transaction("tag","readonly").objectStore("tag").get(a);var e=this;return yb(a).then(function(h){if(!h||!h.length||c>=h.length)return[];if(!b&&!c)return h;h=h.slice(c,c+b);return d?e.enrich(h):h})};
w.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d<a.length;d++)c[d]=yb(b.get(a[d]));return Promise.all(c).then(function(e){for(var h=0;h<e.length;h++)e[h]={id:a[h],doc:e[h]?JSON.parse(e[h]):null};return e})};w.has=function(a){a=this.db.transaction("reg","readonly").objectStore("reg").getKey(a);return yb(a)};w.search=null;w.info=function(){};
w.transaction=function(a,b,c){var d=this,e=this.h[a+":"+b];if(e)return c.call(this,e);var h=this.db.transaction(a,b);this.h[a+":"+b]=e=h.objectStore(a);return new Promise(function(f,g){h.onerror=function(k){d.h[a+":"+b]=null;h.abort();h=e=null;g(k)};h.oncomplete=function(k){h=e=d.h[a+":"+b]=null;f(k||!0)};return c.call(d,e)})};
w.commit=function(a,b,c){var d=this,e,h,f;return ua(function(g){switch(g.h){case 1:if(b)return F(g,d.clear(),12);e=a.X;a.X=[];h=0;f=void 0;case 4:if(!(h<e.length)){g.h=6;break}f=e[h];if(!f.clear){e[h]=f.Ga;g.h=5;break}return F(g,d.clear(),8);case 8:b=!0;g.h=6;break;case 5:h++;g.h=4;break;case 6:if(b){g.h=3;break}c||(e=e.concat(za(a.B)));if(!e.length){g.h=10;break}return F(g,d.remove(e),11);case 11:case 10:g.h=3;break;case 12:a.X=[];case 3:return a.B.size?F(g,d.transaction("map","readwrite",function(k){for(var l=
y(a.map),m=l.next(),n={};!m.done;n={Z:void 0,ia:void 0},m=l.next())m=m.value,n.ia=m[0],n.Z=m[1],n.Z.length&&(b?k.put(n.Z,n.ia):k.get(n.ia).onsuccess=function(p){return function(){var q=this.result,r;if(q&&q.length)for(var x=Math.max(q.length,p.Z.length),u=0,t;u<x;u++){if((t=p.Z[u])&&t.length){if((r=q[u])&&r.length)for(var v=0;v<t.length;v++)r.push(t[v]);else q[u]=t;r=1}}else q=p.Z,r=1;r&&k.put(q,p.ia)}}(n))}),13):g.return();case 13:return F(g,d.transaction("ctx","readwrite",function(k){for(var l=
y(a.M),m=l.next(),n={};!m.done;n={ga:void 0},m=l.next()){m=m.value;n.ga=m[0];m=y(m[1]);for(var p=m.next(),q={};!p.done;q={$:void 0,ja:void 0},p=m.next())p=p.value,q.ja=p[0],q.$=p[1],q.$.length&&(b?k.put(q.$,n.ga+":"+q.ja):k.get(n.ga+":"+q.ja).onsuccess=function(r,x){return function(){var u=this.result,t;if(u&&u.length)for(var v=Math.max(u.length,r.$.length),A=0,C;A<v;A++){if((C=r.$[A])&&C.length){if((t=u[A])&&t.length)for(var D=0;D<C.length;D++)t.push(C[D]);else u[A]=C;t=1}}else u=r.$,t=1;t&&k.put(u,
x.ga+":"+r.ja)}}(q,n))}}),14);case 14:if(a.store)return F(g,d.transaction("reg","readwrite",function(k){for(var l=y(a.store),m=l.next();!m.done;m=l.next()){var n=m.value;m=n[0];n=n[1];k.put("object"===typeof n?JSON.stringify(n):1,m)}}),16);if(a.Ba){g.h=16;break}return F(g,d.transaction("reg","readwrite",function(k){for(var l=y(a.B.keys()),m=l.next();!m.done;m=l.next())k.put(1,m.value)}),16);case 16:if(!a.tag){g.h=20;break}return F(g,d.transaction("tag","readwrite",function(k){for(var l=y(a.tag),m=
l.next(),n={};!m.done;n={ha:void 0,oa:void 0},m=l.next())m=m.value,n.oa=m[0],n.ha=m[1],n.ha.length&&(k.get(n.oa).onsuccess=function(p){return function(){var q=this.result;q=q&&q.length?q.concat(p.ha):p.ha;k.put(q,p.oa)}}(n))}),20);case 20:a.map.clear(),a.M.clear(),a.tag&&a.tag.clear(),a.store&&a.store.clear(),a.document||a.B.clear(),g.h=0}})};
function zb(a,b,c){for(var d=a.value,e,h,f=0,g=0,k;g<d.length;g++){if(k=c?d:d[g]){for(var l=0,m,n;l<b.length;l++)if(n=b[l],m=k.indexOf(h?parseInt(n,10):n),0>m&&!h&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(h=1),0<=m)if(e=1,1<k.length)k.splice(m,1);else{d[g]=[];break}f+=k.length}if(c)break}f?e&&a.update(d):a.delete();a.continue()}
w.remove=function(a){"object"!==typeof a&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&zb(c,a)}}),this.transaction("ctx","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&zb(c,a)}}),this.transaction("tag","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&zb(c,a,!0)}}),this.transaction("reg","readwrite",function(b){for(var c=0;c<a.length;c++)b.delete(a[c])})])};
function yb(a){return new Promise(function(b,c){a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};var Ab=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"]]),Bb={normalize:!0,H:!0,I:Ab};var Cb=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Db=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"],Eb={normalize:!0,H:!0,I:Ab,P:Db,N:Cb};var Hb={normalize:!0,H:!0,I:Ab,P:Db.concat([/(?!^)[aeoy]/g,""]),N:Cb};var Ib={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};T["latin:exact"]={normalize:!1,H:!1};T["latin:default"]=Sa;T["latin:simple"]={normalize:!0,H:!0};T["latin:balance"]=Bb;T["latin:advanced"]=Eb;T["latin:extra"]=Hb;T["latin:soundex"]={normalize:!0,H:!1,ra:{Ea:!0},ca:function(a){for(var b=0;b<a.length;b++){for(var c=a[b],d=c.charAt(0),e=Ib[d],h=1,f;h<c.length&&(f=c.charAt(h),"h"===f||"w"===f||!(f=Ib[f])||f===e||(d+=f,e=f,4!==d.length));h++);a[b]=d}}};
var Jb={Index:U,Encoder:M,Charset:T,Language:Ra,Document:Z,Worker:Y,Resolver:W,IndexedDB:wb},Kb=self,Lb;(Lb=Kb.define)&&Lb.amd?Lb([],function(){return Jb}):"object"===typeof Kb.exports?Kb.exports=Jb:Kb.FlexSearch=Jb;}(this));

View File

@@ -1,372 +1,694 @@
/**! /**!
* FlexSearch.js v0.7.41 (Light) * FlexSearch.js v0.8.0 (Light/Debug)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function(self){'use strict'; (function(self){'use strict';
function t(a) { var t;
return "undefined" !== typeof a ? a : !0; function u(a, c, b) {
const d = typeof b, e = typeof a;
if ("undefined" !== d) {
if ("undefined" !== e) {
if (b) {
if ("function" === e && d === e) {
return function(h) {
return a(b(h));
};
}
c = a.constructor;
if (c === b.constructor) {
if (c === Array) {
return b.concat(a);
}
if (c === Map) {
var g = new Map(b);
for (var f of a) {
g.set(f[0], f[1]);
}
return g;
}
if (c === Set) {
f = new Set(b);
for (g of a.values()) {
f.add(g);
}
return f;
}
}
}
return a;
}
return b;
}
return "undefined" === e ? c : a;
} }
function v(a) { function v() {
const b = Array(a); return Object.create(null);
for (let c = 0; c < a; c++) { }
b[c] = y(); function w(a, c) {
return c.length - a.length;
}
;const y = /[^\p{L}\p{N}]+/u, z = /(\d{3})/g, A = /(\D)(\d{3})/g, B = /(\d{3})(\D)/g, C = "".normalize && /[\u0300-\u036f]/g;
function D(a = {}) {
if (!(this instanceof D)) {
return new D(...arguments);
}
for (a = 0; a < arguments.length; a++) {
this.assign(arguments[a]);
}
}
D.prototype.assign = function(a) {
this.normalize = u(a.normalize, !0, this.normalize);
let c = a.N, b = c || a.O || a.split;
if ("object" === typeof b) {
let d = !c, e = "";
a.N || (e += "\\p{Z}");
b.P && (e += "\\p{L}");
b.R && (e += "\\p{N}", d = !!c);
b.T && (e += "\\p{S}");
b.S && (e += "\\p{P}");
b.control && (e += "\\p{C}");
if (b = b.char) {
e += "object" === typeof b ? b.join("") : b;
}
this.split = new RegExp("[" + (c ? "^" : "") + e + "]+", "u");
this.numeric = d;
} else {
this.split = u(b, y, this.split), this.numeric = u(this.numeric, !0);
}
this.H = u(a.H, null, this.H);
this.D = u(a.D, null, this.D);
this.rtl = a.rtl || !1;
this.l = u(a.l, !0, this.l);
this.filter = u((b = a.filter) && new Set(b), null, this.filter);
this.m = u((b = a.m) && new Map(b), null, this.m);
this.v = u((b = a.v) && new Map(b), null, this.v);
this.s = u((b = a.s) && new Map(b), null, this.s);
this.o = u(a.o, null, this.o);
this.G = u(a.G, 1, this.G);
this.K = u(a.K, 0, this.K);
if (this.cache = b = u(a.cache, !0, this.cache)) {
this.C = null, this.L = "number" === typeof b ? b : 2e5, this.u = new Map(), this.A = new Map(), this.h = this.g = 128;
}
this.i = "";
this.I = null;
this.F = "";
this.J = null;
if (this.m) {
for (const d of this.m.keys()) {
this.i += (this.i ? "|" : "") + d;
}
}
if (this.s) {
for (const d of this.s.keys()) {
this.F += (this.F ? "|" : "") + d;
}
}
return this;
};
D.prototype.encode = function(a) {
if (this.cache && a.length <= this.g) {
if (this.C) {
if (this.u.has(a)) {
return this.u.get(a);
}
} else {
this.C = setTimeout(E, 0, this);
}
}
this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : C ? a.normalize("NFKD").replace(C, "").toLowerCase() : a.toLowerCase());
this.H && (a = this.H(a));
this.numeric && 3 < a.length && (a = a.replace(A, "$1 $2").replace(B, "$1 $2").replace(z, "$1 "));
const c = !(this.l || this.v || this.filter || this.m || this.s || this.o);
let b = [], d = this.split || "" === this.split ? a.split(this.split) : a;
for (let g = 0, f, h; g < d.length; g++) {
if (!(f = h = d[g])) {
continue;
}
if (f.length < this.G) {
continue;
}
if (c) {
b.push(f);
continue;
}
if (this.filter && this.filter.has(f)) {
continue;
}
if (this.cache && f.length <= this.h) {
if (this.C) {
var e = this.A.get(f);
if (e || "" === e) {
e && b.push(e);
continue;
}
} else {
this.C = setTimeout(E, 0, this);
}
}
let l;
this.s && 2 < f.length && (this.J || (this.J = new RegExp("(?!^)(" + this.F + ")$")), f = f.replace(this.J, r => this.s.get(r)), l = 1);
this.m && 1 < f.length && (this.I || (this.I = new RegExp("(" + this.i + ")", "g")), f = f.replace(this.I, r => this.m.get(r)), l = 1);
f && l && (f.length < this.G || this.filter && this.filter.has(f)) && (f = "");
if (f && (this.v || this.l && 1 < f.length)) {
e = "";
for (let r = 0, k = "", p, q; r < f.length; r++) {
p = f.charAt(r), p === k && this.l || ((q = this.v && this.v.get(p)) || "" === q ? q === k && this.l || !(k = q) || (e += q) : e += k = p);
}
f = e;
}
if (f && this.o) {
for (e = 0; f && e < this.o.length; e += 2) {
f = f.replace(this.o[e], this.o[e + 1]);
}
}
this.cache && h.length <= this.h && (this.A.set(h, f), this.A.size > this.L && (this.A.clear(), this.h = this.h / 1.1 | 0));
f && b.push(f);
}
this.D && (b = this.D(b) || b);
this.cache && a.length <= this.g && (this.u.set(a, b), this.u.size > this.L && (this.u.clear(), this.g = this.g / 1.1 | 0));
return b;
};
function E(a) {
a.C = null;
a.u.clear();
a.A.clear();
}
;function F(a) {
this.limit = a && !0 !== a ? a : 1000;
this.cache = new Map();
this.g = "";
}
F.prototype.set = function(a, c) {
this.cache.has(a) || (this.cache.set(this.g = a, c), this.limit && this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value));
};
F.prototype.get = function(a) {
const c = this.cache.get(a);
c && this.limit && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c));
return c;
};
F.prototype.remove = function(a) {
for (const c of this.cache) {
const b = c[0];
c[1].includes(a) && this.cache.delete(b);
}
};
F.prototype.clear = function() {
this.cache.clear();
this.g = "";
};
function G(a = 8) {
if (!(this instanceof G)) {
return new G(a);
}
this.index = v();
this.i = [];
this.size = 0;
32 < a ? (this.g = H, this.h = BigInt(a)) : (this.g = I, this.h = a);
}
G.prototype.get = function(a) {
const c = this.index[this.g(a)];
return c && c.get(a);
};
G.prototype.set = function(a, c) {
var b = this.g(a);
let d = this.index[b];
d ? (b = d.size, d.set(a, c), (b -= d.size) && this.size++) : (this.index[b] = d = new Map([[a, c]]), this.i.push(d));
};
function J(a = 8) {
if (!(this instanceof J)) {
return new J(a);
}
this.index = v();
this.g = [];
32 < a ? (this.i = H, this.h = BigInt(a)) : (this.i = I, this.h = a);
}
J.prototype.add = function(a) {
var c = this.i(a);
let b = this.index[c];
b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.g.push(b));
};
t = G.prototype;
t.has = J.prototype.has = function(a) {
const c = this.index[this.i(a)];
return c && c.has(a);
};
t.delete = J.prototype.delete = function(a) {
const c = this.index[this.i(a)];
c && c.delete(a) && this.size--;
};
t.clear = J.prototype.clear = function() {
this.index = v();
this.g = [];
this.size = 0;
};
t.values = J.prototype.values = function*() {
for (let a = 0; a < this.g.length; a++) {
for (let c of this.g[a].values()) {
yield c;
}
}
};
t.keys = J.prototype.keys = function*() {
for (let a = 0; a < this.g.length; a++) {
for (let c of this.g[a].keys()) {
yield c;
}
}
};
t.entries = J.prototype.entries = function*() {
for (let a = 0; a < this.g.length; a++) {
for (let c of this.g[a].entries()) {
yield c;
}
}
};
function I(a) {
let c = 2 ** this.h - 1;
if ("number" == typeof a) {
return a & c;
}
let b = 0, d = this.h + 1;
for (let e = 0; e < a.length; e++) {
b = (b * d ^ a.charCodeAt(e)) & c;
}
return 32 === this.h ? b + 2 ** 31 : b;
}
function H(a) {
let c = BigInt(2) ** this.h - BigInt(1);
var b = typeof a;
if ("bigint" === b) {
return a & c;
}
if ("number" === b) {
return BigInt(a) & c;
}
b = BigInt(0);
let d = this.h + BigInt(1);
for (let e = 0; e < a.length; e++) {
b = (b * d ^ BigInt(a.charCodeAt(e))) & c;
} }
return b; return b;
} }
function y() { ;const K = v(), L = v();
return Object.create(null); var aa = {normalize:function(a) {
} return a.toLowerCase();
function z(a, b) { }, l:!1};
return b.length - a.length; const M = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}};
} v();
;const A = /[\p{Z}\p{S}\p{P}\p{C}]+/u; N.prototype.add = function(a, c, b, d) {
function B(a, b) { if (c && (a || 0 === a)) {
const c = Object.keys(a), d = c.length, e = []; if (!d && !b && this.j.has(a)) {
let h = "", f = 0; return this.update(a, c);
for (let g = 0, l, n; g < d; g++) {
l = c[g], (n = a[l]) ? (e[f++] = new RegExp(b ? "(?!\\b)" + l + "(\\b|_)" : l, "g"), e[f++] = n) : h += (h ? "|" : "") + l;
} }
h && (e[f++] = new RegExp(b ? "(?!\\b)(" + h + ")(\\b|_)" : "(" + h + ")", "g"), e[f] = ""); c = this.encoder.encode(c);
return e; if (d = c.length) {
} const r = v(), k = v(), p = this.depth, q = this.resolution;
function C(a, b) { for (let m = 0; m < d; m++) {
for (let c = 0, d = b.length; c < d && (a = a.replace(b[c], b[c + 1]), a); c += 2) { let n = c[this.rtl ? d - 1 - m : m];
} var e = n.length;
return a; if (e && (p || !k[n])) {
} var g = this.score ? this.score(c, n, m, null, 0) : O(q, d, m), f = "";
;function E(a) { switch(this.tokenize) {
if (a = ("" + a).toLowerCase()) {
if (this.o && (a = C(a, this.o)), this.A && 1 < a.length && (a = C(a, this.A)), A || "" === A) {
const b = a.split(A);
if (this.filter) {
a = this.filter;
const c = b.length, d = [];
for (let e = 0, h = 0; e < c; e++) {
const f = b[e];
f && !a[f] && (d[h++] = f);
}
a = d;
} else {
a = b;
}
}
}
return a;
}
;const F = {}, G = {};
function H(a, b, c, d) {
const e = a.length;
let h = [], f, g, l = 0;
d && (d = []);
for (let n = e - 1; 0 <= n; n--) {
const m = a[n], r = m.length, p = y();
let q = !f;
for (let k = 0; k < r; k++) {
const u = m[k], L = u.length;
if (L) {
for (let D = 0, x, w; D < L; D++) {
if (w = u[D], f) {
if (f[w]) {
if (!n) {
if (c) {
c--;
} else {
if (h[l++] = w, l === b) {
return h;
}
}
}
if (n || d) {
p[w] = 1;
}
q = !0;
}
if (d && (x = (g[w] || 0) + 1, g[w] = x, x < e)) {
const M = d[x - 2] || (d[x - 2] = []);
M[M.length] = w;
}
} else {
p[w] = 1;
}
}
}
}
if (d) {
f || (g = p);
} else if (!q) {
return [];
}
f = p;
}
if (d) {
for (let n = d.length - 1, m, r; 0 <= n; n--) {
m = d[n];
r = m.length;
for (let p = 0, q; p < r; p++) {
if (q = m[p], !f[q]) {
if (c) {
c--;
} else {
if (h[l++] = q, l === b) {
return h;
}
}
f[q] = 1;
}
}
}
}
return h;
}
;function I(a, b) {
if (!(this instanceof I)) {
return new I(a);
}
let c;
if (a) {
var d = a.charset;
c = a.lang;
"string" === typeof d && (-1 === d.indexOf(":") && (d += ":default"), d = G[d]);
"string" === typeof c && (c = F[c]);
} else {
a = {};
}
let e, h, f = a.context || {};
this.encode = a.encode || d && d.encode || E;
this.register = b || y();
this.s = e = a.resolution || 9;
this.B = b = d && d.B || a.tokenize || "strict";
this.i = "strict" === b && f.depth;
this.j = t(f.bidirectional);
this.g = h = t(a.optimize);
this.m = t(a.fastupdate);
this.h = a.minlength || 1;
this.C = a.boost;
this.map = h ? v(e) : y();
this.v = e = f.resolution || 1;
this.l = h ? v(e) : y();
this.u = d && d.u || a.rtl;
this.o = (b = a.matcher || c && c.o) && B(b, !1);
this.A = (b = a.stemmer || c && c.A) && B(b, !0);
if (a = b = a.filter || c && c.filter) {
a = b;
d = y();
for (let g = 0, l = a.length; g < l; g++) {
d[a[g]] = 1;
}
a = d;
}
this.filter = a;
}
I.prototype.append = function(a, b) {
return this.add(a, b, !0);
};
I.prototype.add = function(a, b, c, d) {
if (b && (a || 0 === a)) {
if (!d && !c && this.register[a]) {
return this.update(a, b);
}
b = this.encode(b);
if (d = b.length) {
const n = y(), m = y(), r = this.i, p = this.s;
for (let q = 0; q < d; q++) {
let k = b[this.u ? d - 1 - q : q];
var e = k.length;
if (k && e >= this.h && (r || !m[k])) {
var h = J(p, d, q), f = "";
switch(this.B) {
case "full": case "full":
if (2 < e) { if (2 < e) {
for (h = 0; h < e; h++) { for (g = 0; g < e; g++) {
for (var g = e; g > h; g--) { for (var h = e; h > g; h--) {
if (g - h >= this.h) { f = n.substring(g, h);
var l = J(p, d, q, e, h); var l = this.score ? this.score(c, n, m, f, g) : O(q, d, m, e, g);
f = k.substring(h, g); P(this, k, f, l, a, b);
K(this, m, f, l, a, c);
}
} }
} }
break; break;
} }
case "reverse": case "reverse":
if (1 < e) { if (1 < e) {
for (g = e - 1; 0 < g; g--) { for (h = e - 1; 0 < h; h--) {
f = k[g] + f, f.length >= this.h && K(this, m, f, J(p, d, q, e, g), a, c); f = n[h] + f, l = this.score ? this.score(c, n, m, f, h) : O(q, d, m, e, h), P(this, k, f, l, a, b);
} }
f = ""; f = "";
} }
case "forward": case "forward":
if (1 < e) { if (1 < e) {
for (g = 0; g < e; g++) { for (h = 0; h < e; h++) {
f += k[g], f.length >= this.h && K(this, m, f, h, a, c); f += n[h], P(this, k, f, g, a, b);
} }
break; break;
} }
default: default:
if (this.C && (h = Math.min(h / this.C(b, k, q) | 0, p - 1)), K(this, m, k, h, a, c), r && 1 < d && q < d - 1) { if (P(this, k, n, g, a, b), p && 1 < d && m < d - 1) {
for (e = y(), f = this.v, h = k, g = Math.min(r + 1, d - q), e[h] = 1, l = 1; l < g; l++) { for (e = v(), f = this.M, g = n, h = Math.min(p + 1, d - m), e[g] = 1, l = 1; l < h; l++) {
if ((k = b[this.u ? d - 1 - q - l : q + l]) && k.length >= this.h && !e[k]) { if ((n = c[this.rtl ? d - 1 - m - l : m + l]) && !e[n]) {
e[k] = 1; e[n] = 1;
const u = this.j && k > h; const x = this.score ? this.score(c, g, m, n, l) : O(f + (d / 2 > f ? 0 : 1), d, m, h - 1, l - 1), R = this.bidirectional && n > g;
K(this, n, u ? h : k, J(f + (d / 2 > f ? 0 : 1), d, q, g - 1, l - 1), a, c, u ? k : h); P(this, r, R ? g : n, x, a, b, R ? n : g);
} }
} }
} }
} }
} }
} }
this.m || (this.register[a] = 1); this.fastupdate || this.j.add(a);
} }
} }
return this; return this;
}; };
function J(a, b, c, d, e) { function P(a, c, b, d, e, g, f) {
return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; let h = f ? a.B : a.map, l;
c[b] && f && (l = c[b])[f] || (f ? (c = l || (c[b] = v()), c[f] = 1, (l = h.get(f)) ? h = l : h.set(f, h = new Map())) : c[b] = 1, (l = h.get(b)) ? h = l : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.j.get(e)) ? c.push(h) : a.j.set(e, [h]))));
} }
function K(a, b, c, d, e, h, f) { function O(a, c, b, d, e) {
let g = f ? a.l : a.map; return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0;
if (!b[c] || f && !b[c][f]) {
a.g && (g = g[d]), f ? (b = b[c] || (b[c] = y()), b[f] = 1, g = g[f] || (g[f] = y())) : b[c] = 1, g = g[c] || (g[c] = []), a.g || (g = g[d] || (g[d] = [])), h && g.includes(e) || (g[g.length] = e, a.m && (a = a.register[e] || (a.register[e] = []), a[a.length] = g));
}
} }
I.prototype.search = function(a, b, c) { ;function Q(a, c, b) {
c || (b || "object" !== typeof a ? "object" === typeof b && (c = b) : (c = a, a = c.query)); if (1 === a.length) {
let d = [], e; return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a;
let h, f = 0;
if (c) {
a = c.query || a;
b = c.limit;
f = c.offset || 0;
var g = c.context;
h = !1;
} }
if (a && (a = this.encode("" + a), e = a.length, 1 < e)) { let d = [];
c = y(); for (let e = 0, g, f; e < a.length; e++) {
var l = []; if ((g = a[e]) && (f = g.length)) {
for (let m = 0, r = 0, p; m < e; m++) { if (b) {
if ((p = a[m]) && p.length >= this.h && !c[p]) { if (b >= f) {
if (this.g || h || this.map[p]) { b -= f;
l[r++] = p, c[p] = 1;
} else {
return d;
}
}
}
a = l;
e = a.length;
}
if (!e) {
return d;
}
b || (b = 100);
g = this.i && 1 < e && !1 !== g;
c = 0;
let n;
g ? (n = a[0], c = 1) : 1 < e && a.sort(z);
for (let m, r; c < e; c++) {
r = a[c];
g ? (m = N(this, d, h, b, f, 2 === e, r, n), h && !1 === m && d.length || (n = r)) : m = N(this, d, h, b, f, 1 === e, r);
if (m) {
return m;
}
if (h && c === e - 1) {
l = d.length;
if (!l) {
if (g) {
g = 0;
c = -1;
continue; continue;
} }
return d; b < f && (g = c ? g.slice(b, b + c) : g.slice(b), f = g.length, b = 0);
} }
if (1 === l) { if (d.length) {
return O(d[0], b, f); f > c && (g = g.slice(0, c), f = g.length), d.push(g);
} else {
if (f >= c) {
return f > c && (g = g.slice(0, c)), g;
} }
d = [g];
} }
} c -= f;
return H(d, b, f, h); if (!c) {
};
function N(a, b, c, d, e, h, f, g) {
let l = [], n = g ? a.l : a.map;
a.g || (n = P(n, f, g, a.j));
if (n) {
let m = 0;
const r = Math.min(n.length, g ? a.v : a.s);
for (let p = 0, q = 0, k, u; p < r; p++) {
if (k = n[p]) {
if (a.g && (k = P(k, f, g, a.j)), e && k && h && (u = k.length, u <= e ? (e -= u, k = null) : (k = k.slice(e), e = 0)), k && (l[m++] = k, h && (q += k.length, q >= d))) {
break; break;
} }
} }
} }
if (m) { return d.length ? d = 1 < d.length ? [].concat.apply([], d) : d[0] : d;
if (h) { }
return O(l, d, 0); ;function ba(a, c, b, d) {
var e = a.length;
let g = [], f = 0, h, l, r;
d && (d = []);
for (let k = e - 1, p; 0 <= k; k--) {
r = a[k];
e = v();
p = !h;
for (let q = 0, m; q < r.length; q++) {
if ((m = r[q]) && m.length) {
for (let n = 0, x; n < m.length; n++) {
if (x = m[n], h) {
if (h[x]) {
if (!k) {
if (b) {
b--;
} else {
if (g[f++] = x, f === c) {
return g;
} }
b[b.length] = l; }
}
if (k || d) {
e[x] = 1;
}
p = !0;
}
d && !l[x] && (l[x] = 1, (d[q] || (d[q] = [])).push(x));
} else {
e[x] = 1;
}
}
}
}
if (d) {
h || (l = e);
} else if (!p) {
return [];
}
h = e;
}
if (d) {
for (let k = d.length - 1, p, q; 0 <= k; k--) {
p = d[k];
q = p.length;
for (let m = 0, n; m < q; m++) {
if (n = p[m], !h[n]) {
if (b) {
b--;
} else {
if (g[f++] = n, f === c) {
return g;
}
}
h[n] = 1;
}
}
}
}
return g;
}
;N.prototype.search = function(a, c, b) {
b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = ""));
let d = [];
let e, g = 0;
if (b) {
a = b.query || a;
c = b.limit || c;
g = b.offset || 0;
var f = b.context;
e = b.suggest;
}
a = this.encoder.encode(a);
b = a.length;
c || (c = 100);
if (1 === b) {
return S.call(this, a[0], "", c, g);
}
f = this.depth && !1 !== f;
if (2 === b && f && !e) {
return S.call(this, a[0], a[1], c, g);
}
let h = 0, l = 0;
if (1 < b) {
var r = v();
const p = [];
for (let q = 0, m; q < b; q++) {
if ((m = a[q]) && !r[m]) {
if (e || T(this, m)) {
p.push(m), r[m] = 1;
} else {
return d;
}
const n = m.length;
h = Math.max(h, n);
l = l ? Math.min(l, n) : n;
}
}
a = p;
b = a.length;
}
if (!b) {
return d;
}
r = 0;
let k;
if (1 === b) {
return S.call(this, a[0], "", c, g);
}
if (2 === b && f && !e) {
return S.call(this, a[0], a[1], c, g);
}
1 < b && (f ? (k = a[0], r = 1) : 9 < h && 3 < h / l && a.sort(w));
for (let p, q; r < b; r++) {
q = a[r];
k ? (p = T(this, q, k), p = U(p, d, e, this.M, c, g, 2 === b), e && !1 === p && d.length || (k = q)) : (p = T(this, q), p = U(p, d, e, this.resolution, c, g, 1 === b));
if (p) {
return p;
}
if (e && r === b - 1) {
f = d.length;
if (!f) {
if (k) {
k = "";
r = -1;
continue;
}
return d;
}
if (1 === f) {
return Q(d[0], c, g);
}
}
}
return ba(d, c, g, e);
};
function S(a, c, b, d) {
return (a = T(this, a, c)) && a.length ? Q(a, b, d) : [];
}
function U(a, c, b, d, e, g, f) {
let h = [];
if (a) {
d = Math.min(a.length, d);
for (let l = 0, r = 0, k; l < d; l++) {
if (k = a[l]) {
if (g && k && f && (k.length <= g ? (g -= k.length, k = null) : (k = k.slice(g), g = 0)), k && (h[l] = k, f && (r += k.length, r >= e))) {
break;
}
}
}
if (h.length) {
if (f) {
return Q(h, e, 0);
}
c.push(h);
return; return;
} }
} }
return !c && l; return !b && h;
} }
function O(a, b, c) { function T(a, c, b) {
a = 1 === a.length ? a[0] : [].concat.apply([], a); let d;
return c || a.length > b ? a.slice(c, c + b) : a; b && (d = a.bidirectional && c > b);
} a = b ? (a = a.B.get(d ? c : b)) && a.get(d ? b : c) : a.map.get(c);
function P(a, b, c, d) {
c ? (d = d && b > c, a = (a = a[d ? b : c]) && a[d ? c : b]) : a = a[b];
return a; return a;
} }
I.prototype.contain = function(a) { ;N.prototype.remove = function(a, c) {
return !!this.register[a]; const b = this.j.size && (this.fastupdate ? this.j.get(a) : this.j.has(a));
}; if (b) {
I.prototype.update = function(a, b) { if (this.fastupdate) {
return this.remove(a).add(a, b); for (let d = 0, e; d < b.length; d++) {
}; if (e = b[d]) {
I.prototype.remove = function(a, b) { if (2 > e.length) {
const c = this.register[a]; e.pop();
if (c) { } else {
if (this.m) { const g = e.indexOf(a);
for (let d = 0, e; d < c.length; d++) { g === b.length - 1 ? e.pop() : e.splice(g, 1);
e = c[d], e.splice(e.indexOf(a), 1); }
}
} }
} else { } else {
Q(this.map, a, this.s, this.g), this.i && Q(this.l, a, this.v, this.g); V(this.map, a), this.depth && V(this.B, a);
} }
b || delete this.register[a]; c || this.j.delete(a);
} }
this.cache && this.cache.remove(a);
return this; return this;
}; };
function Q(a, b, c, d, e) { function V(a, c) {
let h = 0; let b = 0;
if (a.constructor === Array) { if (a.constructor === Array) {
if (e) { for (let d = 0, e, g; d < a.length; d++) {
b = a.indexOf(b), -1 !== b ? 1 < a.length && (a.splice(b, 1), h++) : h++; if ((e = a[d]) && e.length) {
if (g = e.indexOf(c), 0 <= g) {
1 < e.length ? (e.splice(g, 1), b++) : delete a[d];
break;
} else { } else {
e = Math.min(a.length, c); b++;
for (let f = 0, g; f < e; f++) {
if (g = a[f]) {
h = Q(g, b, c, d, e), d || h || delete a[f];
} }
} }
} }
} else { } else {
for (let f in a) { for (let d of a) {
(h = Q(a[f], b, c, d, e)) || delete a[f]; const e = d[0], g = V(d[1], c);
g ? b += g : a.delete(e);
} }
} }
return h; return b;
} }
;const R = {Index:I, Document:null, Worker:null, registerCharset:function(a, b) { ;function N(a, c) {
G[a] = b; if (!(this instanceof N)) {
}, registerLanguage:function(a, b) { return new N(a);
F[a] = b; }
}}; if (a) {
let S; var b = "string" === typeof a ? a : a.preset;
(S = self.define) && S.amd ? S([], function() { b && (M[b] || console.warn("Preset not found: " + b), a = Object.assign({}, M[b], a));
return R; } else {
}) : self.exports ? self.exports = R : self.FlexSearch = R; a = {};
}
b = a.context || {};
const d = a.encode || a.encoder || aa;
this.encoder = d.encode ? d : "object" === typeof d ? new D(d) : {encode:d};
let e;
this.resolution = a.resolution || 9;
this.tokenize = e = a.tokenize || "strict";
this.depth = "strict" === e && b.depth || 0;
this.bidirectional = !1 !== b.bidirectional;
this.fastupdate = !!a.fastupdate;
this.score = a.score || null;
this.map = (e = !1, new Map());
this.B = e ? new G(e) : new Map();
this.j = c || (this.fastupdate ? e ? new G(e) : new Map() : e ? new J(e) : new Set());
this.M = b.resolution || 1;
this.rtl = d.rtl || a.rtl || !1;
this.cache = (e = a.cache || null) && new F(e);
}
t = N.prototype;
t.clear = function() {
this.map.clear();
this.B.clear();
this.j.clear();
this.cache && this.cache.clear();
return this;
};
t.append = function(a, c) {
return this.add(a, c, !0);
};
t.contain = function(a) {
return this.j.has(a);
};
t.update = function(a, c) {
if (this.async) {
const b = this, d = this.remove(a);
return d.then ? d.then(() => b.add(a, c)) : this.add(a, c);
}
return this.remove(a).add(a, c);
};
function W(a) {
let c = 0;
if (a.constructor === Array) {
for (let b = 0, d; b < a.length; b++) {
(d = a[b]) && (c += d.length);
}
} else {
for (const b of a) {
const d = b[0], e = W(b[1]);
e ? c += e : a.delete(d);
}
}
return c;
}
t.cleanup = function() {
if (!this.fastupdate) {
return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this;
}
W(this.map);
this.depth && W(this.B);
return this;
};
t.searchCache = function(a, c, b) {
a = ("object" === typeof a ? "" + a.query : a).toLowerCase();
let d = this.cache.get(a);
if (!d) {
d = this.search(a, c, b);
if (d instanceof Promise) {
const e = this;
d.then(function(g) {
e.cache.set(a, g);
});
}
this.cache.set(a, d);
}
return d;
};
const X = {Index:N, Encoder:D, Charset:L, Language:K, Document:null, Worker:null, Resolver:null, IndexedDB:null}, Y = self;
let Z;
(Z = Y.define) && Z.amd ? Z([], function() {
return X;
}) : "object" === typeof Y.exports ? Y.exports = X : Y.FlexSearch = X;
}(this)); }(this));

View File

@@ -1,18 +1,28 @@
/**! /**!
* FlexSearch.js v0.7.41 (Light) * FlexSearch.js v0.8.0 (Light)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function(self){'use strict';function t(a){return"undefined"!==typeof a?a:!0}function v(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=y();return b}function y(){return Object.create(null)}function z(a,b){return b.length-a.length};const A=/[\p{Z}\p{S}\p{P}\p{C}]+/u;function B(a,b){const c=Object.keys(a),d=c.length,e=[];let h="",f=0;for(let g=0,l,n;g<d;g++)l=c[g],(n=a[l])?(e[f++]=new RegExp(b?"(?!\\b)"+l+"(\\b|_)":l,"g"),e[f++]=n):h+=(h?"|":"")+l;h&&(e[f++]=new RegExp(b?"(?!\\b)("+h+")(\\b|_)":"("+h+")","g"),e[f]="");return e}function C(a,b){for(let c=0,d=b.length;c<d&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a};function E(a){if(a=(""+a).toLowerCase())if(this.o&&(a=C(a,this.o)),this.A&&1<a.length&&(a=C(a,this.A)),A||""===A){const b=a.split(A);if(this.filter){a=this.filter;const c=b.length,d=[];for(let e=0,h=0;e<c;e++){const f=b[e];f&&!a[f]&&(d[h++]=f)}a=d}else a=b}return a};const F={},G={};function H(a,b,c,d){const e=a.length;let h=[],f,g,l=0;d&&(d=[]);for(let n=e-1;0<=n;n--){const m=a[n],r=m.length,p=y();let q=!f;for(let k=0;k<r;k++){const u=m[k],L=u.length;if(L)for(let D=0,x,w;D<L;D++)if(w=u[D],f){if(f[w]){if(!n)if(c)c--;else if(h[l++]=w,l===b)return h;if(n||d)p[w]=1;q=!0}if(d&&(x=(g[w]||0)+1,g[w]=x,x<e)){const M=d[x-2]||(d[x-2]=[]);M[M.length]=w}}else p[w]=1}if(d)f||(g=p);else if(!q)return[];f=p}if(d)for(let n=d.length-1,m,r;0<=n;n--){m=d[n];r=m.length;for(let p=0,q;p<r;p++)if(q= (function(self){'use strict';var t;function u(a,c,b){const d=typeof b,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(b){if("function"===e&&d===e)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===e?c:a}function v(){return Object.create(null)}function w(a,c){return c.length-a.length};const y=/[^\p{L}\p{N}]+/u,z=/(\d{3})/g,A=/(\D)(\d{3})/g,B=/(\d{3})(\D)/g,C="".normalize&&/[\u0300-\u036f]/g;function D(a={}){if(!(this instanceof D))return new D(...arguments);for(a=0;a<arguments.length;a++)this.assign(arguments[a])}
m[p],!f[q]){if(c)c--;else if(h[l++]=q,l===b)return h;f[q]=1}}return h};function I(a,b){if(!(this instanceof I))return new I(a);let c;if(a){var d=a.charset;c=a.lang;"string"===typeof d&&(-1===d.indexOf(":")&&(d+=":default"),d=G[d]);"string"===typeof c&&(c=F[c])}else a={};let e,h,f=a.context||{};this.encode=a.encode||d&&d.encode||E;this.register=b||y();this.s=e=a.resolution||9;this.B=b=d&&d.B||a.tokenize||"strict";this.i="strict"===b&&f.depth;this.j=t(f.bidirectional);this.g=h=t(a.optimize);this.m=t(a.fastupdate);this.h=a.minlength||1;this.C=a.boost;this.map=h?v(e):y(); D.prototype.assign=function(a){this.normalize=u(a.normalize,!0,this.normalize);let c=a.N,b=c||a.O||a.split;if("object"===typeof b){let d=!c,e="";a.N||(e+="\\p{Z}");b.P&&(e+="\\p{L}");b.R&&(e+="\\p{N}",d=!!c);b.T&&(e+="\\p{S}");b.S&&(e+="\\p{P}");b.control&&(e+="\\p{C}");if(b=b.char)e+="object"===typeof b?b.join(""):b;this.split=new RegExp("["+(c?"^":"")+e+"]+","u");this.numeric=d}else this.split=u(b,y,this.split),this.numeric=u(this.numeric,!0);this.H=u(a.H,null,this.H);this.D=u(a.D,null,this.D);
this.v=e=f.resolution||1;this.l=h?v(e):y();this.u=d&&d.u||a.rtl;this.o=(b=a.matcher||c&&c.o)&&B(b,!1);this.A=(b=a.stemmer||c&&c.A)&&B(b,!0);if(a=b=a.filter||c&&c.filter){a=b;d=y();for(let g=0,l=a.length;g<l;g++)d[a[g]]=1;a=d}this.filter=a}I.prototype.append=function(a,b){return this.add(a,b,!0)}; this.rtl=a.rtl||!1;this.l=u(a.l,!0,this.l);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.m=u((b=a.m)&&new Map(b),null,this.m);this.v=u((b=a.v)&&new Map(b),null,this.v);this.s=u((b=a.s)&&new Map(b),null,this.s);this.o=u(a.o,null,this.o);this.G=u(a.G,1,this.G);this.K=u(a.K,0,this.K);if(this.cache=b=u(a.cache,!0,this.cache))this.C=null,this.L="number"===typeof b?b:2E5,this.u=new Map,this.A=new Map,this.h=this.g=128;this.i="";this.I=null;this.F="";this.J=null;if(this.m)for(const d of this.m.keys())this.i+=
I.prototype.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.register[a])return this.update(a,b);b=this.encode(b);if(d=b.length){const n=y(),m=y(),r=this.i,p=this.s;for(let q=0;q<d;q++){let k=b[this.u?d-1-q:q];var e=k.length;if(k&&e>=this.h&&(r||!m[k])){var h=J(p,d,q),f="";switch(this.B){case "full":if(2<e){for(h=0;h<e;h++)for(var g=e;g>h;g--)if(g-h>=this.h){var l=J(p,d,q,e,h);f=k.substring(h,g);K(this,m,f,l,a,c)}break}case "reverse":if(1<e){for(g=e-1;0<g;g--)f=k[g]+f,f.length>=this.h&&K(this, (this.i?"|":"")+d;if(this.s)for(const d of this.s.keys())this.F+=(this.F?"|":"")+d;return this};
m,f,J(p,d,q,e,g),a,c);f=""}case "forward":if(1<e){for(g=0;g<e;g++)f+=k[g],f.length>=this.h&&K(this,m,f,h,a,c);break}default:if(this.C&&(h=Math.min(h/this.C(b,k,q)|0,p-1)),K(this,m,k,h,a,c),r&&1<d&&q<d-1)for(e=y(),f=this.v,h=k,g=Math.min(r+1,d-q),e[h]=1,l=1;l<g;l++)if((k=b[this.u?d-1-q-l:q+l])&&k.length>=this.h&&!e[k]){e[k]=1;const u=this.j&&k>h;K(this,n,u?h:k,J(f+(d/2>f?0:1),d,q,g-1,l-1),a,c,u?k:h)}}}}this.m||(this.register[a]=1)}}return this}; D.prototype.encode=function(a){if(this.cache&&a.length<=this.g)if(this.C){if(this.u.has(a))return this.u.get(a)}else this.C=setTimeout(E,0,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):C?a.normalize("NFKD").replace(C,"").toLowerCase():a.toLowerCase());this.H&&(a=this.H(a));this.numeric&&3<a.length&&(a=a.replace(A,"$1 $2").replace(B,"$1 $2").replace(z,"$1 "));const c=!(this.l||this.v||this.filter||this.m||this.s||this.o);let b=[],d=this.split||""===this.split?a.split(this.split):
function J(a,b,c,d,e){return c&&1<a?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0}function K(a,b,c,d,e,h,f){let g=f?a.l:a.map;if(!b[c]||f&&!b[c][f])a.g&&(g=g[d]),f?(b=b[c]||(b[c]=y()),b[f]=1,g=g[f]||(g[f]=y())):b[c]=1,g=g[c]||(g[c]=[]),a.g||(g=g[d]||(g[d]=[])),h&&g.includes(e)||(g[g.length]=e,a.m&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=g))} a;for(let g=0,f,h;g<d.length;g++){if(!(f=h=d[g]))continue;if(f.length<this.G)continue;if(c){b.push(f);continue}if(this.filter&&this.filter.has(f))continue;if(this.cache&&f.length<=this.h)if(this.C){var e=this.A.get(f);if(e||""===e){e&&b.push(e);continue}}else this.C=setTimeout(E,0,this);let l;this.s&&2<f.length&&(this.J||(this.J=new RegExp("(?!^)("+this.F+")$")),f=f.replace(this.J,r=>this.s.get(r)),l=1);this.m&&1<f.length&&(this.I||(this.I=new RegExp("("+this.i+")","g")),f=f.replace(this.I,r=>this.m.get(r)),
I.prototype.search=function(a,b,c){c||(b||"object"!==typeof a?"object"===typeof b&&(c=b):(c=a,a=c.query));let d=[],e;let h,f=0;if(c){a=c.query||a;b=c.limit;f=c.offset||0;var g=c.context;h=!1}if(a&&(a=this.encode(""+a),e=a.length,1<e)){c=y();var l=[];for(let m=0,r=0,p;m<e;m++)if((p=a[m])&&p.length>=this.h&&!c[p])if(this.g||h||this.map[p])l[r++]=p,c[p]=1;else return d;a=l;e=a.length}if(!e)return d;b||(b=100);g=this.i&&1<e&&!1!==g;c=0;let n;g?(n=a[0],c=1):1<e&&a.sort(z);for(let m,r;c<e;c++){r=a[c];g? l=1);f&&l&&(f.length<this.G||this.filter&&this.filter.has(f))&&(f="");if(f&&(this.v||this.l&&1<f.length)){e="";for(let r=0,k="",p,q;r<f.length;r++)p=f.charAt(r),p===k&&this.l||((q=this.v&&this.v.get(p))||""===q?q===k&&this.l||!(k=q)||(e+=q):e+=k=p);f=e}if(f&&this.o)for(e=0;f&&e<this.o.length;e+=2)f=f.replace(this.o[e],this.o[e+1]);this.cache&&h.length<=this.h&&(this.A.set(h,f),this.A.size>this.L&&(this.A.clear(),this.h=this.h/1.1|0));f&&b.push(f)}this.D&&(b=this.D(b)||b);this.cache&&a.length<=this.g&&
(m=N(this,d,h,b,f,2===e,r,n),h&&!1===m&&d.length||(n=r)):m=N(this,d,h,b,f,1===e,r);if(m)return m;if(h&&c===e-1){l=d.length;if(!l){if(g){g=0;c=-1;continue}return d}if(1===l)return O(d[0],b,f)}}return H(d,b,f,h)}; (this.u.set(a,b),this.u.size>this.L&&(this.u.clear(),this.g=this.g/1.1|0));return b};function E(a){a.C=null;a.u.clear();a.A.clear()};function F(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.g=""}F.prototype.set=function(a,c){this.cache.has(a)||(this.cache.set(this.g=a,c),this.limit&&this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value))};F.prototype.get=function(a){const c=this.cache.get(a);c&&this.limit&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};F.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};
function N(a,b,c,d,e,h,f,g){let l=[],n=g?a.l:a.map;a.g||(n=P(n,f,g,a.j));if(n){let m=0;const r=Math.min(n.length,g?a.v:a.s);for(let p=0,q=0,k,u;p<r;p++)if(k=n[p])if(a.g&&(k=P(k,f,g,a.j)),e&&k&&h&&(u=k.length,u<=e?(e-=u,k=null):(k=k.slice(e),e=0)),k&&(l[m++]=k,h&&(q+=k.length,q>=d)))break;if(m){if(h)return O(l,d,0);b[b.length]=l;return}}return!c&&l}function O(a,b,c){a=1===a.length?a[0]:[].concat.apply([],a);return c||a.length>b?a.slice(c,c+b):a} F.prototype.clear=function(){this.cache.clear();this.g=""};function G(a=8){if(!(this instanceof G))return new G(a);this.index=v();this.i=[];this.size=0;32<a?(this.g=H,this.h=BigInt(a)):(this.g=I,this.h=a)}G.prototype.get=function(a){const c=this.index[this.g(a)];return c&&c.get(a)};G.prototype.set=function(a,c){var b=this.g(a);let d=this.index[b];d?(b=d.size,d.set(a,c),(b-=d.size)&&this.size++):(this.index[b]=d=new Map([[a,c]]),this.i.push(d))};
function P(a,b,c,d){c?(d=d&&b>c,a=(a=a[d?b:c])&&a[d?c:b]):a=a[b];return a}I.prototype.contain=function(a){return!!this.register[a]};I.prototype.update=function(a,b){return this.remove(a).add(a,b)};I.prototype.remove=function(a,b){const c=this.register[a];if(c){if(this.m)for(let d=0,e;d<c.length;d++)e=c[d],e.splice(e.indexOf(a),1);else Q(this.map,a,this.s,this.g),this.i&&Q(this.l,a,this.v,this.g);b||delete this.register[a]}return this}; function J(a=8){if(!(this instanceof J))return new J(a);this.index=v();this.g=[];32<a?(this.i=H,this.h=BigInt(a)):(this.i=I,this.h=a)}J.prototype.add=function(a){var c=this.i(a);let b=this.index[c];b?(c=b.size,b.add(a),(c-=b.size)&&this.size++):(this.index[c]=b=new Set([a]),this.g.push(b))};t=G.prototype;t.has=J.prototype.has=function(a){const c=this.index[this.i(a)];return c&&c.has(a)};t.delete=J.prototype.delete=function(a){const c=this.index[this.i(a)];c&&c.delete(a)&&this.size--};
function Q(a,b,c,d,e){let h=0;if(a.constructor===Array)if(e)b=a.indexOf(b),-1!==b?1<a.length&&(a.splice(b,1),h++):h++;else{e=Math.min(a.length,c);for(let f=0,g;f<e;f++)if(g=a[f])h=Q(g,b,c,d,e),d||h||delete a[f]}else for(let f in a)(h=Q(a[f],b,c,d,e))||delete a[f];return h};const R={Index:I,Document:null,Worker:null,registerCharset:function(a,b){G[a]=b},registerLanguage:function(a,b){F[a]=b}};let S;(S=self.define)&&S.amd?S([],function(){return R}):self.exports?self.exports=R:self.FlexSearch=R;}(this)); t.clear=J.prototype.clear=function(){this.index=v();this.g=[];this.size=0};t.values=J.prototype.values=function*(){for(let a=0;a<this.g.length;a++)for(let c of this.g[a].values())yield c};t.keys=J.prototype.keys=function*(){for(let a=0;a<this.g.length;a++)for(let c of this.g[a].keys())yield c};t.entries=J.prototype.entries=function*(){for(let a=0;a<this.g.length;a++)for(let c of this.g[a].entries())yield c};
function I(a){let c=2**this.h-1;if("number"==typeof a)return a&c;let b=0,d=this.h+1;for(let e=0;e<a.length;e++)b=(b*d^a.charCodeAt(e))&c;return 32===this.h?b+2**31:b}function H(a){let c=BigInt(2)**this.h-BigInt(1);var b=typeof a;if("bigint"===b)return a&c;if("number"===b)return BigInt(a)&c;b=BigInt(0);let d=this.h+BigInt(1);for(let e=0;e<a.length;e++)b=(b*d^BigInt(a.charCodeAt(e)))&c;return b};const K=v(),L=v();var M={normalize:function(a){return a.toLowerCase()},l:!1};const aa={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};v();N.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.j.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const r=v(),k=v(),p=this.depth,q=this.resolution;for(let m=0;m<d;m++){let n=c[this.rtl?d-1-m:m];var e=n.length;if(e&&(p||!k[n])){var g=this.score?this.score(c,n,m,null,0):O(q,d,m),f="";switch(this.tokenize){case "full":if(2<e){for(g=0;g<e;g++)for(var h=e;h>g;h--){f=n.substring(g,h);var l=this.score?this.score(c,n,m,f,g):O(q,d,m,e,g);P(this,k,f,l,a,b)}break}case "reverse":if(1<
e){for(h=e-1;0<h;h--)f=n[h]+f,l=this.score?this.score(c,n,m,f,h):O(q,d,m,e,h),P(this,k,f,l,a,b);f=""}case "forward":if(1<e){for(h=0;h<e;h++)f+=n[h],P(this,k,f,g,a,b);break}default:if(P(this,k,n,g,a,b),p&&1<d&&m<d-1)for(e=v(),f=this.M,g=n,h=Math.min(p+1,d-m),e[g]=1,l=1;l<h;l++)if((n=c[this.rtl?d-1-m-l:m+l])&&!e[n]){e[n]=1;const x=this.score?this.score(c,g,m,n,l):O(f+(d/2>f?0:1),d,m,h-1,l-1),Q=this.bidirectional&&n>g;P(this,r,Q?g:n,x,a,b,Q?n:g)}}}}this.fastupdate||this.j.add(a)}}return this};
function P(a,c,b,d,e,g,f){let h=f?a.B:a.map,l;c[b]&&f&&(l=c[b])[f]||(f?(c=l||(c[b]=v()),c[f]=1,(l=h.get(f))?h=l:h.set(f,h=new Map)):c[b]=1,(l=h.get(b))?h=l:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.j.get(e))?c.push(h):a.j.set(e,[h]))))}function O(a,c,b,d,e){return b&&1<a?c+(d||0)<=a?b+(e||0):(a-1)/(c+(d||0))*(b+(e||0))+1|0:0};function R(a,c,b){if(1===a.length)return a=a[0],a=b||a.length>c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e<a.length;e++)if((g=a[e])&&(f=g.length)){if(b){if(b>=f){b-=f;continue}b<f&&(g=c?g.slice(b,b+c):g.slice(b),f=g.length,b=0)}if(d.length)f>c&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1<d.length?[].concat.apply([],d):d[0]:d};function ba(a,c,b,d){var e=a.length;let g=[],f=0,h,l,r;d&&(d=[]);for(let k=e-1,p;0<=k;k--){r=a[k];e=v();p=!h;for(let q=0,m;q<r.length;q++)if((m=r[q])&&m.length)for(let n=0,x;n<m.length;n++)if(x=m[n],h){if(h[x]){if(!k)if(b)b--;else if(g[f++]=x,f===c)return g;if(k||d)e[x]=1;p=!0}d&&!l[x]&&(l[x]=1,(d[q]||(d[q]=[])).push(x))}else e[x]=1;if(d)h||(l=e);else if(!p)return[];h=e}if(d)for(let k=d.length-1,p,q;0<=k;k--){p=d[k];q=p.length;for(let m=0,n;m<q;m++)if(n=p[m],!h[n]){if(b)b--;else if(g[f++]=n,f===c)return g;
h[n]=1}}return g};N.prototype.search=function(a,c,b){b||(c||"object"!==typeof a?"object"===typeof c&&(b=c,c=0):(b=a,a=""));let d=[];let e,g=0;if(b){a=b.query||a;c=b.limit||c;g=b.offset||0;var f=b.context;e=b.suggest}a=this.encoder.encode(a);b=a.length;c||(c=100);if(1===b)return S.call(this,a[0],"",c,g);f=this.depth&&!1!==f;if(2===b&&f&&!e)return S.call(this,a[0],a[1],c,g);let h=0,l=0;if(1<b){var r=v();const p=[];for(let q=0,m;q<b;q++)if((m=a[q])&&!r[m]){if(e||T(this,m))p.push(m),r[m]=1;else return d;const n=m.length;
h=Math.max(h,n);l=l?Math.min(l,n):n}a=p;b=a.length}if(!b)return d;r=0;let k;if(1===b)return S.call(this,a[0],"",c,g);if(2===b&&f&&!e)return S.call(this,a[0],a[1],c,g);1<b&&(f?(k=a[0],r=1):9<h&&3<h/l&&a.sort(w));for(let p,q;r<b;r++){q=a[r];k?(p=T(this,q,k),p=U(p,d,e,this.M,c,g,2===b),e&&!1===p&&d.length||(k=q)):(p=T(this,q),p=U(p,d,e,this.resolution,c,g,1===b));if(p)return p;if(e&&r===b-1){f=d.length;if(!f){if(k){k="";r=-1;continue}return d}if(1===f)return R(d[0],c,g)}}return ba(d,c,g,e)};
function S(a,c,b,d){return(a=T(this,a,c))&&a.length?R(a,b,d):[]}function U(a,c,b,d,e,g,f){let h=[];if(a){d=Math.min(a.length,d);for(let l=0,r=0,k;l<d;l++)if(k=a[l])if(g&&k&&f&&(k.length<=g?(g-=k.length,k=null):(k=k.slice(g),g=0)),k&&(h[l]=k,f&&(r+=k.length,r>=e)))break;if(h.length){if(f)return R(h,e,0);c.push(h);return}}return!b&&h}function T(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.B.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};N.prototype.remove=function(a,c){const b=this.j.size&&(this.fastupdate?this.j.get(a):this.j.has(a));if(b){if(this.fastupdate)for(let d=0,e;d<b.length;d++){if(e=b[d])if(2>e.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else V(this.map,a),this.depth&&V(this.B,a);c||this.j.delete(a)}this.cache&&this.cache.remove(a);return this};
function V(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;d<a.length;d++){if((e=a[d])&&e.length)if(g=e.indexOf(c),0<=g){1<e.length?(e.splice(g,1),b++):delete a[d];break}else b++}else for(let d of a){const e=d[0],g=V(d[1],c);g?b+=g:a.delete(e)}return b};function N(a,c){if(!(this instanceof N))return new N(a);if(a){var b="string"===typeof a?a:a.preset;b&&(a=Object.assign({},aa[b],a))}else a={};b=a.context||{};const d=a.encode||a.encoder||M;this.encoder=d.encode?d:"object"===typeof d?new D(d):{encode:d};let e;this.resolution=a.resolution||9;this.tokenize=e=a.tokenize||"strict";this.depth="strict"===e&&b.depth||0;this.bidirectional=!1!==b.bidirectional;this.fastupdate=!!a.fastupdate;this.score=a.score||null;this.map=(e=!1,new Map);this.B=e?new G(e):
new Map;this.j=c||(this.fastupdate?e?new G(e):new Map:e?new J(e):new Set);this.M=b.resolution||1;this.rtl=d.rtl||a.rtl||!1;this.cache=(e=a.cache||null)&&new F(e)}t=N.prototype;t.clear=function(){this.map.clear();this.B.clear();this.j.clear();this.cache&&this.cache.clear();return this};t.append=function(a,c){return this.add(a,c,!0)};t.contain=function(a){return this.j.has(a)};
t.update=function(a,c){if(this.async){const b=this,d=this.remove(a);return d.then?d.then(()=>b.add(a,c)):this.add(a,c)}return this.remove(a).add(a,c)};function W(a){let c=0;if(a.constructor===Array)for(let b=0,d;b<a.length;b++)(d=a[b])&&(c+=d.length);else for(const b of a){const d=b[0],e=W(b[1]);e?c+=e:a.delete(d)}return c}t.cleanup=function(){if(!this.fastupdate)return this;W(this.map);this.depth&&W(this.B);return this};
t.searchCache=function(a,c,b){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,c,b);if(d instanceof Promise){const e=this;d.then(function(g){e.cache.set(a,g)})}this.cache.set(a,d)}return d};const X={Index:N,Encoder:D,Charset:L,Language:K,Document:null,Worker:null,Resolver:null,IndexedDB:null},Y=self;let Z;(Z=Y.define)&&Z.amd?Z([],function(){return X}):"object"===typeof Y.exports?Y.exports=X:Y.FlexSearch=X;}(this));

View File

@@ -1,367 +1,690 @@
/**! /**!
* FlexSearch.js v0.7.41 (Light.module) * FlexSearch.js v0.8.0 (Bundle/Debug)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
function t(a) { var t;
return "undefined" !== typeof a ? a : !0; function u(a, c, b) {
const d = typeof b, e = typeof a;
if ("undefined" !== d) {
if ("undefined" !== e) {
if (b) {
if ("function" === e && d === e) {
return function(h) {
return a(b(h));
};
}
c = a.constructor;
if (c === b.constructor) {
if (c === Array) {
return b.concat(a);
}
if (c === Map) {
var g = new Map(b);
for (var f of a) {
g.set(f[0], f[1]);
}
return g;
}
if (c === Set) {
f = new Set(b);
for (g of a.values()) {
f.add(g);
}
return f;
}
}
}
return a;
}
return b;
}
return "undefined" === e ? c : a;
} }
function v(a) { function v() {
const b = Array(a); return Object.create(null);
for (let c = 0; c < a; c++) { }
b[c] = y(); function w(a, c) {
return c.length - a.length;
}
;const y = /[^\p{L}\p{N}]+/u, z = /(\d{3})/g, A = /(\D)(\d{3})/g, B = /(\d{3})(\D)/g, C = "".normalize && /[\u0300-\u036f]/g;
function D(a = {}) {
if (!(this instanceof D)) {
return new D(...arguments);
}
for (a = 0; a < arguments.length; a++) {
this.assign(arguments[a]);
}
}
D.prototype.assign = function(a) {
this.normalize = u(a.normalize, !0, this.normalize);
let c = a.N, b = c || a.O || a.split;
if ("object" === typeof b) {
let d = !c, e = "";
a.N || (e += "\\p{Z}");
b.P && (e += "\\p{L}");
b.R && (e += "\\p{N}", d = !!c);
b.T && (e += "\\p{S}");
b.S && (e += "\\p{P}");
b.control && (e += "\\p{C}");
if (b = b.char) {
e += "object" === typeof b ? b.join("") : b;
}
this.split = new RegExp("[" + (c ? "^" : "") + e + "]+", "u");
this.numeric = d;
} else {
this.split = u(b, y, this.split), this.numeric = u(this.numeric, !0);
}
this.H = u(a.H, null, this.H);
this.D = u(a.D, null, this.D);
this.rtl = a.rtl || !1;
this.l = u(a.l, !0, this.l);
this.filter = u((b = a.filter) && new Set(b), null, this.filter);
this.m = u((b = a.m) && new Map(b), null, this.m);
this.v = u((b = a.v) && new Map(b), null, this.v);
this.s = u((b = a.s) && new Map(b), null, this.s);
this.o = u(a.o, null, this.o);
this.G = u(a.G, 1, this.G);
this.K = u(a.K, 0, this.K);
if (this.cache = b = u(a.cache, !0, this.cache)) {
this.C = null, this.L = "number" === typeof b ? b : 2e5, this.u = new Map(), this.A = new Map(), this.h = this.g = 128;
}
this.i = "";
this.I = null;
this.F = "";
this.J = null;
if (this.m) {
for (const d of this.m.keys()) {
this.i += (this.i ? "|" : "") + d;
}
}
if (this.s) {
for (const d of this.s.keys()) {
this.F += (this.F ? "|" : "") + d;
}
}
return this;
};
D.prototype.encode = function(a) {
if (this.cache && a.length <= this.g) {
if (this.C) {
if (this.u.has(a)) {
return this.u.get(a);
}
} else {
this.C = setTimeout(E, 0, this);
}
}
this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : C ? a.normalize("NFKD").replace(C, "").toLowerCase() : a.toLowerCase());
this.H && (a = this.H(a));
this.numeric && 3 < a.length && (a = a.replace(A, "$1 $2").replace(B, "$1 $2").replace(z, "$1 "));
const c = !(this.l || this.v || this.filter || this.m || this.s || this.o);
let b = [], d = this.split || "" === this.split ? a.split(this.split) : a;
for (let g = 0, f, h; g < d.length; g++) {
if (!(f = h = d[g])) {
continue;
}
if (f.length < this.G) {
continue;
}
if (c) {
b.push(f);
continue;
}
if (this.filter && this.filter.has(f)) {
continue;
}
if (this.cache && f.length <= this.h) {
if (this.C) {
var e = this.A.get(f);
if (e || "" === e) {
e && b.push(e);
continue;
}
} else {
this.C = setTimeout(E, 0, this);
}
}
let l;
this.s && 2 < f.length && (this.J || (this.J = new RegExp("(?!^)(" + this.F + ")$")), f = f.replace(this.J, r => this.s.get(r)), l = 1);
this.m && 1 < f.length && (this.I || (this.I = new RegExp("(" + this.i + ")", "g")), f = f.replace(this.I, r => this.m.get(r)), l = 1);
f && l && (f.length < this.G || this.filter && this.filter.has(f)) && (f = "");
if (f && (this.v || this.l && 1 < f.length)) {
e = "";
for (let r = 0, k = "", p, q; r < f.length; r++) {
p = f.charAt(r), p === k && this.l || ((q = this.v && this.v.get(p)) || "" === q ? q === k && this.l || !(k = q) || (e += q) : e += k = p);
}
f = e;
}
if (f && this.o) {
for (e = 0; f && e < this.o.length; e += 2) {
f = f.replace(this.o[e], this.o[e + 1]);
}
}
this.cache && h.length <= this.h && (this.A.set(h, f), this.A.size > this.L && (this.A.clear(), this.h = this.h / 1.1 | 0));
f && b.push(f);
}
this.D && (b = this.D(b) || b);
this.cache && a.length <= this.g && (this.u.set(a, b), this.u.size > this.L && (this.u.clear(), this.g = this.g / 1.1 | 0));
return b;
};
function E(a) {
a.C = null;
a.u.clear();
a.A.clear();
}
;function F(a) {
this.limit = a && !0 !== a ? a : 1000;
this.cache = new Map();
this.g = "";
}
F.prototype.set = function(a, c) {
this.cache.has(a) || (this.cache.set(this.g = a, c), this.limit && this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value));
};
F.prototype.get = function(a) {
const c = this.cache.get(a);
c && this.limit && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c));
return c;
};
F.prototype.remove = function(a) {
for (const c of this.cache) {
const b = c[0];
c[1].includes(a) && this.cache.delete(b);
}
};
F.prototype.clear = function() {
this.cache.clear();
this.g = "";
};
function G(a = 8) {
if (!(this instanceof G)) {
return new G(a);
}
this.index = v();
this.i = [];
this.size = 0;
32 < a ? (this.g = H, this.h = BigInt(a)) : (this.g = I, this.h = a);
}
G.prototype.get = function(a) {
const c = this.index[this.g(a)];
return c && c.get(a);
};
G.prototype.set = function(a, c) {
var b = this.g(a);
let d = this.index[b];
d ? (b = d.size, d.set(a, c), (b -= d.size) && this.size++) : (this.index[b] = d = new Map([[a, c]]), this.i.push(d));
};
function J(a = 8) {
if (!(this instanceof J)) {
return new J(a);
}
this.index = v();
this.g = [];
32 < a ? (this.i = H, this.h = BigInt(a)) : (this.i = I, this.h = a);
}
J.prototype.add = function(a) {
var c = this.i(a);
let b = this.index[c];
b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.g.push(b));
};
t = G.prototype;
t.has = J.prototype.has = function(a) {
const c = this.index[this.i(a)];
return c && c.has(a);
};
t.delete = J.prototype.delete = function(a) {
const c = this.index[this.i(a)];
c && c.delete(a) && this.size--;
};
t.clear = J.prototype.clear = function() {
this.index = v();
this.g = [];
this.size = 0;
};
t.values = J.prototype.values = function*() {
for (let a = 0; a < this.g.length; a++) {
for (let c of this.g[a].values()) {
yield c;
}
}
};
t.keys = J.prototype.keys = function*() {
for (let a = 0; a < this.g.length; a++) {
for (let c of this.g[a].keys()) {
yield c;
}
}
};
t.entries = J.prototype.entries = function*() {
for (let a = 0; a < this.g.length; a++) {
for (let c of this.g[a].entries()) {
yield c;
}
}
};
function I(a) {
let c = 2 ** this.h - 1;
if ("number" == typeof a) {
return a & c;
}
let b = 0, d = this.h + 1;
for (let e = 0; e < a.length; e++) {
b = (b * d ^ a.charCodeAt(e)) & c;
}
return 32 === this.h ? b + 2 ** 31 : b;
}
function H(a) {
let c = BigInt(2) ** this.h - BigInt(1);
var b = typeof a;
if ("bigint" === b) {
return a & c;
}
if ("number" === b) {
return BigInt(a) & c;
}
b = BigInt(0);
let d = this.h + BigInt(1);
for (let e = 0; e < a.length; e++) {
b = (b * d ^ BigInt(a.charCodeAt(e))) & c;
} }
return b; return b;
} }
function y() { ;const K = v(), L = v();
return Object.create(null); var M = {normalize:function(a) {
} return a.toLowerCase();
function z(a, b) { }, l:!1};
return b.length - a.length; const N = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}};
} v();
;const A = /[\p{Z}\p{S}\p{P}\p{C}]+/u; P.prototype.add = function(a, c, b, d) {
function B(a, b) { if (c && (a || 0 === a)) {
const c = Object.keys(a), d = c.length, e = []; if (!d && !b && this.j.has(a)) {
let h = "", f = 0; return this.update(a, c);
for (let g = 0, l, n; g < d; g++) {
l = c[g], (n = a[l]) ? (e[f++] = new RegExp(b ? "(?!\\b)" + l + "(\\b|_)" : l, "g"), e[f++] = n) : h += (h ? "|" : "") + l;
} }
h && (e[f++] = new RegExp(b ? "(?!\\b)(" + h + ")(\\b|_)" : "(" + h + ")", "g"), e[f] = ""); c = this.encoder.encode(c);
return e; if (d = c.length) {
} const r = v(), k = v(), p = this.depth, q = this.resolution;
function C(a, b) { for (let m = 0; m < d; m++) {
for (let c = 0, d = b.length; c < d && (a = a.replace(b[c], b[c + 1]), a); c += 2) { let n = c[this.rtl ? d - 1 - m : m];
} var e = n.length;
return a; if (e && (p || !k[n])) {
} var g = this.score ? this.score(c, n, m, null, 0) : Q(q, d, m), f = "";
;function E(a) { switch(this.tokenize) {
if (a = ("" + a).toLowerCase()) {
if (this.o && (a = C(a, this.o)), this.A && 1 < a.length && (a = C(a, this.A)), A || "" === A) {
const b = a.split(A);
if (this.filter) {
a = this.filter;
const c = b.length, d = [];
for (let e = 0, h = 0; e < c; e++) {
const f = b[e];
f && !a[f] && (d[h++] = f);
}
a = d;
} else {
a = b;
}
}
}
return a;
}
;const F = {}, G = {};
function H(a, b, c, d) {
const e = a.length;
let h = [], f, g, l = 0;
d && (d = []);
for (let n = e - 1; 0 <= n; n--) {
const m = a[n], r = m.length, p = y();
let q = !f;
for (let k = 0; k < r; k++) {
const u = m[k], J = u.length;
if (J) {
for (let D = 0, x, w; D < J; D++) {
if (w = u[D], f) {
if (f[w]) {
if (!n) {
if (c) {
c--;
} else {
if (h[l++] = w, l === b) {
return h;
}
}
}
if (n || d) {
p[w] = 1;
}
q = !0;
}
if (d && (x = (g[w] || 0) + 1, g[w] = x, x < e)) {
const K = d[x - 2] || (d[x - 2] = []);
K[K.length] = w;
}
} else {
p[w] = 1;
}
}
}
}
if (d) {
f || (g = p);
} else if (!q) {
return [];
}
f = p;
}
if (d) {
for (let n = d.length - 1, m, r; 0 <= n; n--) {
m = d[n];
r = m.length;
for (let p = 0, q; p < r; p++) {
if (q = m[p], !f[q]) {
if (c) {
c--;
} else {
if (h[l++] = q, l === b) {
return h;
}
}
f[q] = 1;
}
}
}
}
return h;
}
;function I(a, b) {
if (!(this instanceof I)) {
return new I(a);
}
let c;
if (a) {
var d = a.charset;
c = a.lang;
"string" === typeof d && (-1 === d.indexOf(":") && (d += ":default"), d = G[d]);
"string" === typeof c && (c = F[c]);
} else {
a = {};
}
let e, h, f = a.context || {};
this.encode = a.encode || d && d.encode || E;
this.register = b || y();
this.s = e = a.resolution || 9;
this.B = b = d && d.B || a.tokenize || "strict";
this.i = "strict" === b && f.depth;
this.j = t(f.bidirectional);
this.g = h = t(a.optimize);
this.m = t(a.fastupdate);
this.h = a.minlength || 1;
this.C = a.boost;
this.map = h ? v(e) : y();
this.v = e = f.resolution || 1;
this.l = h ? v(e) : y();
this.u = d && d.u || a.rtl;
this.o = (b = a.matcher || c && c.o) && B(b, !1);
this.A = (b = a.stemmer || c && c.A) && B(b, !0);
if (a = b = a.filter || c && c.filter) {
a = b;
d = y();
for (let g = 0, l = a.length; g < l; g++) {
d[a[g]] = 1;
}
a = d;
}
this.filter = a;
}
I.prototype.append = function(a, b) {
return this.add(a, b, !0);
};
I.prototype.add = function(a, b, c, d) {
if (b && (a || 0 === a)) {
if (!d && !c && this.register[a]) {
return this.update(a, b);
}
b = this.encode(b);
if (d = b.length) {
const n = y(), m = y(), r = this.i, p = this.s;
for (let q = 0; q < d; q++) {
let k = b[this.u ? d - 1 - q : q];
var e = k.length;
if (k && e >= this.h && (r || !m[k])) {
var h = L(p, d, q), f = "";
switch(this.B) {
case "full": case "full":
if (2 < e) { if (2 < e) {
for (h = 0; h < e; h++) { for (g = 0; g < e; g++) {
for (var g = e; g > h; g--) { for (var h = e; h > g; h--) {
if (g - h >= this.h) { f = n.substring(g, h);
var l = L(p, d, q, e, h); var l = this.score ? this.score(c, n, m, f, g) : Q(q, d, m, e, g);
f = k.substring(h, g); R(this, k, f, l, a, b);
M(this, m, f, l, a, c);
}
} }
} }
break; break;
} }
case "reverse": case "reverse":
if (1 < e) { if (1 < e) {
for (g = e - 1; 0 < g; g--) { for (h = e - 1; 0 < h; h--) {
f = k[g] + f, f.length >= this.h && M(this, m, f, L(p, d, q, e, g), a, c); f = n[h] + f, l = this.score ? this.score(c, n, m, f, h) : Q(q, d, m, e, h), R(this, k, f, l, a, b);
} }
f = ""; f = "";
} }
case "forward": case "forward":
if (1 < e) { if (1 < e) {
for (g = 0; g < e; g++) { for (h = 0; h < e; h++) {
f += k[g], f.length >= this.h && M(this, m, f, h, a, c); f += n[h], R(this, k, f, g, a, b);
} }
break; break;
} }
default: default:
if (this.C && (h = Math.min(h / this.C(b, k, q) | 0, p - 1)), M(this, m, k, h, a, c), r && 1 < d && q < d - 1) { if (R(this, k, n, g, a, b), p && 1 < d && m < d - 1) {
for (e = y(), f = this.v, h = k, g = Math.min(r + 1, d - q), e[h] = 1, l = 1; l < g; l++) { for (e = v(), f = this.M, g = n, h = Math.min(p + 1, d - m), e[g] = 1, l = 1; l < h; l++) {
if ((k = b[this.u ? d - 1 - q - l : q + l]) && k.length >= this.h && !e[k]) { if ((n = c[this.rtl ? d - 1 - m - l : m + l]) && !e[n]) {
e[k] = 1; e[n] = 1;
const u = this.j && k > h; const x = this.score ? this.score(c, g, m, n, l) : Q(f + (d / 2 > f ? 0 : 1), d, m, h - 1, l - 1), O = this.bidirectional && n > g;
M(this, n, u ? h : k, L(f + (d / 2 > f ? 0 : 1), d, q, g - 1, l - 1), a, c, u ? k : h); R(this, r, O ? g : n, x, a, b, O ? n : g);
} }
} }
} }
} }
} }
} }
this.m || (this.register[a] = 1); this.fastupdate || this.j.add(a);
} }
} }
return this; return this;
}; };
function L(a, b, c, d, e) { function R(a, c, b, d, e, g, f) {
return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; let h = f ? a.B : a.map, l;
c[b] && f && (l = c[b])[f] || (f ? (c = l || (c[b] = v()), c[f] = 1, (l = h.get(f)) ? h = l : h.set(f, h = new Map())) : c[b] = 1, (l = h.get(b)) ? h = l : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.j.get(e)) ? c.push(h) : a.j.set(e, [h]))));
} }
function M(a, b, c, d, e, h, f) { function Q(a, c, b, d, e) {
let g = f ? a.l : a.map; return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0;
if (!b[c] || f && !b[c][f]) {
a.g && (g = g[d]), f ? (b = b[c] || (b[c] = y()), b[f] = 1, g = g[f] || (g[f] = y())) : b[c] = 1, g = g[c] || (g[c] = []), a.g || (g = g[d] || (g[d] = [])), h && g.includes(e) || (g[g.length] = e, a.m && (a = a.register[e] || (a.register[e] = []), a[a.length] = g));
}
} }
I.prototype.search = function(a, b, c) { ;function S(a, c, b) {
c || (b || "object" !== typeof a ? "object" === typeof b && (c = b) : (c = a, a = c.query)); if (1 === a.length) {
let d = [], e; return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a;
let h, f = 0;
if (c) {
a = c.query || a;
b = c.limit;
f = c.offset || 0;
var g = c.context;
h = !1;
} }
if (a && (a = this.encode("" + a), e = a.length, 1 < e)) { let d = [];
c = y(); for (let e = 0, g, f; e < a.length; e++) {
var l = []; if ((g = a[e]) && (f = g.length)) {
for (let m = 0, r = 0, p; m < e; m++) { if (b) {
if ((p = a[m]) && p.length >= this.h && !c[p]) { if (b >= f) {
if (this.g || h || this.map[p]) { b -= f;
l[r++] = p, c[p] = 1;
} else {
return d;
}
}
}
a = l;
e = a.length;
}
if (!e) {
return d;
}
b || (b = 100);
g = this.i && 1 < e && !1 !== g;
c = 0;
let n;
g ? (n = a[0], c = 1) : 1 < e && a.sort(z);
for (let m, r; c < e; c++) {
r = a[c];
g ? (m = N(this, d, h, b, f, 2 === e, r, n), h && !1 === m && d.length || (n = r)) : m = N(this, d, h, b, f, 1 === e, r);
if (m) {
return m;
}
if (h && c === e - 1) {
l = d.length;
if (!l) {
if (g) {
g = 0;
c = -1;
continue; continue;
} }
return d; b < f && (g = c ? g.slice(b, b + c) : g.slice(b), f = g.length, b = 0);
} }
if (1 === l) { if (d.length) {
return O(d[0], b, f); f > c && (g = g.slice(0, c), f = g.length), d.push(g);
} else {
if (f >= c) {
return f > c && (g = g.slice(0, c)), g;
} }
d = [g];
} }
} c -= f;
return H(d, b, f, h); if (!c) {
};
function N(a, b, c, d, e, h, f, g) {
let l = [], n = g ? a.l : a.map;
a.g || (n = P(n, f, g, a.j));
if (n) {
let m = 0;
const r = Math.min(n.length, g ? a.v : a.s);
for (let p = 0, q = 0, k, u; p < r; p++) {
if (k = n[p]) {
if (a.g && (k = P(k, f, g, a.j)), e && k && h && (u = k.length, u <= e ? (e -= u, k = null) : (k = k.slice(e), e = 0)), k && (l[m++] = k, h && (q += k.length, q >= d))) {
break; break;
} }
} }
} }
if (m) { return d.length ? d = 1 < d.length ? [].concat.apply([], d) : d[0] : d;
if (h) { }
return O(l, d, 0); ;function T(a, c, b, d) {
var e = a.length;
let g = [], f = 0, h, l, r;
d && (d = []);
for (let k = e - 1, p; 0 <= k; k--) {
r = a[k];
e = v();
p = !h;
for (let q = 0, m; q < r.length; q++) {
if ((m = r[q]) && m.length) {
for (let n = 0, x; n < m.length; n++) {
if (x = m[n], h) {
if (h[x]) {
if (!k) {
if (b) {
b--;
} else {
if (g[f++] = x, f === c) {
return g;
} }
b[b.length] = l; }
}
if (k || d) {
e[x] = 1;
}
p = !0;
}
d && !l[x] && (l[x] = 1, (d[q] || (d[q] = [])).push(x));
} else {
e[x] = 1;
}
}
}
}
if (d) {
h || (l = e);
} else if (!p) {
return [];
}
h = e;
}
if (d) {
for (let k = d.length - 1, p, q; 0 <= k; k--) {
p = d[k];
q = p.length;
for (let m = 0, n; m < q; m++) {
if (n = p[m], !h[n]) {
if (b) {
b--;
} else {
if (g[f++] = n, f === c) {
return g;
}
}
h[n] = 1;
}
}
}
}
return g;
}
;P.prototype.search = function(a, c, b) {
b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = ""));
let d = [];
let e, g = 0;
if (b) {
a = b.query || a;
c = b.limit || c;
g = b.offset || 0;
var f = b.context;
e = !1;
}
a = this.encoder.encode(a);
b = a.length;
c || (c = 100);
if (1 === b) {
return U.call(this, a[0], "", c, g);
}
f = this.depth && !1 !== f;
if (2 === b && f && !e) {
return U.call(this, a[0], a[1], c, g);
}
let h = 0, l = 0;
if (1 < b) {
var r = v();
const p = [];
for (let q = 0, m; q < b; q++) {
if ((m = a[q]) && !r[m]) {
if (e || V(this, m)) {
p.push(m), r[m] = 1;
} else {
return d;
}
const n = m.length;
h = Math.max(h, n);
l = l ? Math.min(l, n) : n;
}
}
a = p;
b = a.length;
}
if (!b) {
return d;
}
r = 0;
let k;
if (1 === b) {
return U.call(this, a[0], "", c, g);
}
if (2 === b && f && !e) {
return U.call(this, a[0], a[1], c, g);
}
1 < b && (f ? (k = a[0], r = 1) : 9 < h && 3 < h / l && a.sort(w));
for (let p, q; r < b; r++) {
q = a[r];
k ? (p = V(this, q, k), p = W(p, d, e, this.M, c, g, 2 === b), e && !1 === p && d.length || (k = q)) : (p = V(this, q), p = W(p, d, e, this.resolution, c, g, 1 === b));
if (p) {
return p;
}
if (e && r === b - 1) {
f = d.length;
if (!f) {
if (k) {
k = "";
r = -1;
continue;
}
return d;
}
if (1 === f) {
return S(d[0], c, g);
}
}
}
return T(d, c, g, e);
};
function U(a, c, b, d) {
return (a = V(this, a, c)) && a.length ? S(a, b, d) : [];
}
function W(a, c, b, d, e, g, f) {
let h = [];
if (a) {
d = Math.min(a.length, d);
for (let l = 0, r = 0, k; l < d; l++) {
if (k = a[l]) {
if (g && k && f && (k.length <= g ? (g -= k.length, k = null) : (k = k.slice(g), g = 0)), k && (h[l] = k, f && (r += k.length, r >= e))) {
break;
}
}
}
if (h.length) {
if (f) {
return S(h, e, 0);
}
c.push(h);
return; return;
} }
} }
return !c && l; return !b && h;
} }
function O(a, b, c) { function V(a, c, b) {
a = 1 === a.length ? a[0] : [].concat.apply([], a); let d;
return c || a.length > b ? a.slice(c, c + b) : a; b && (d = a.bidirectional && c > b);
} a = b ? (a = a.B.get(d ? c : b)) && a.get(d ? b : c) : a.map.get(c);
function P(a, b, c, d) {
c ? (d = d && b > c, a = (a = a[d ? b : c]) && a[d ? c : b]) : a = a[b];
return a; return a;
} }
I.prototype.contain = function(a) { ;P.prototype.remove = function(a, c) {
return !!this.register[a]; const b = this.j.size && (this.fastupdate ? this.j.get(a) : this.j.has(a));
}; if (b) {
I.prototype.update = function(a, b) { if (this.fastupdate) {
return this.remove(a).add(a, b); for (let d = 0, e; d < b.length; d++) {
}; if (e = b[d]) {
I.prototype.remove = function(a, b) { if (2 > e.length) {
const c = this.register[a]; e.pop();
if (c) { } else {
if (this.m) { const g = e.indexOf(a);
for (let d = 0, e; d < c.length; d++) { g === b.length - 1 ? e.pop() : e.splice(g, 1);
e = c[d], e.splice(e.indexOf(a), 1); }
}
} }
} else { } else {
Q(this.map, a, this.s, this.g), this.i && Q(this.l, a, this.v, this.g); X(this.map, a), this.depth && X(this.B, a);
} }
b || delete this.register[a]; c || this.j.delete(a);
} }
this.cache && this.cache.remove(a);
return this; return this;
}; };
function Q(a, b, c, d, e) { function X(a, c) {
let h = 0; let b = 0;
if (a.constructor === Array) { if (a.constructor === Array) {
if (e) { for (let d = 0, e, g; d < a.length; d++) {
b = a.indexOf(b), -1 !== b ? 1 < a.length && (a.splice(b, 1), h++) : h++; if ((e = a[d]) && e.length) {
if (g = e.indexOf(c), 0 <= g) {
1 < e.length ? (e.splice(g, 1), b++) : delete a[d];
break;
} else { } else {
e = Math.min(a.length, c); b++;
for (let f = 0, g; f < e; f++) {
if (g = a[f]) {
h = Q(g, b, c, d, e), d || h || delete a[f];
} }
} }
} }
} else { } else {
for (let f in a) { for (let d of a) {
(h = Q(a[f], b, c, d, e)) || delete a[f]; const e = d[0], g = X(d[1], c);
g ? b += g : a.delete(e);
} }
} }
return h; return b;
} }
;export default {Index:I, Document:null, Worker:null, registerCharset:function(a, b) { ;function P(a, c) {
G[a] = b; if (!(this instanceof P)) {
}, registerLanguage:function(a, b) { return new P(a);
F[a] = b; }
}}; if (a) {
var b = "string" === typeof a ? a : a.preset;
b && (N[b] || console.warn("Preset not found: " + b), a = Object.assign({}, N[b], a));
} else {
a = {};
}
b = a.context || {};
const d = a.encode || a.encoder || M;
this.encoder = d.encode ? d : "object" === typeof d ? new D(d) : {encode:d};
let e;
this.resolution = a.resolution || 9;
this.tokenize = e = a.tokenize || "strict";
this.depth = "strict" === e && b.depth || 0;
this.bidirectional = !1 !== b.bidirectional;
this.fastupdate = !!a.fastupdate;
this.score = a.score || null;
this.map = (e = !1, new Map());
this.B = e ? new G(e) : new Map();
this.j = c || (this.fastupdate ? e ? new G(e) : new Map() : e ? new J(e) : new Set());
this.M = b.resolution || 1;
this.rtl = d.rtl || a.rtl || !1;
this.cache = (e = a.cache || null) && new F(e);
}
t = P.prototype;
t.clear = function() {
this.map.clear();
this.B.clear();
this.j.clear();
this.cache && this.cache.clear();
return this;
};
t.append = function(a, c) {
return this.add(a, c, !0);
};
t.contain = function(a) {
return this.j.has(a);
};
t.update = function(a, c) {
if (this.async) {
const b = this, d = this.remove(a);
return d.then ? d.then(() => b.add(a, c)) : this.add(a, c);
}
return this.remove(a).add(a, c);
};
function Y(a) {
let c = 0;
if (a.constructor === Array) {
for (let b = 0, d; b < a.length; b++) {
(d = a[b]) && (c += d.length);
}
} else {
for (const b of a) {
const d = b[0], e = Y(b[1]);
e ? c += e : a.delete(d);
}
}
return c;
}
t.cleanup = function() {
if (!this.fastupdate) {
return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this;
}
Y(this.map);
this.depth && Y(this.B);
return this;
};
t.searchCache = function(a, c, b) {
a = ("object" === typeof a ? "" + a.query : a).toLowerCase();
let d = this.cache.get(a);
if (!d) {
d = this.search(a, c, b);
if (d instanceof Promise) {
const e = this;
d.then(function(g) {
e.cache.set(a, g);
});
}
this.cache.set(a, d);
}
return d;
};
export default {Index:P, Encoder:D, Charset:L, Language:K, Document:null, Worker:null, Resolver:null, IndexedDB:null};
export const Index=P;export const Encoder=D;export const Charset=L;export const Language=K;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;

View File

@@ -1,18 +1,29 @@
/**! /**!
* FlexSearch.js v0.7.41 (Light.module) * FlexSearch.js v0.8.0 (Bundle)
* Author and Copyright: Thomas Wilkerling * Author and Copyright: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* Hosted by Nextapps GmbH * Hosted by Nextapps GmbH
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
function t(a){return"undefined"!==typeof a?a:!0}function v(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=y();return b}function y(){return Object.create(null)}function z(a,b){return b.length-a.length};const A=/[\p{Z}\p{S}\p{P}\p{C}]+/u;function B(a,b){const c=Object.keys(a),d=c.length,e=[];let h="",f=0;for(let g=0,l,n;g<d;g++)l=c[g],(n=a[l])?(e[f++]=new RegExp(b?"(?!\\b)"+l+"(\\b|_)":l,"g"),e[f++]=n):h+=(h?"|":"")+l;h&&(e[f++]=new RegExp(b?"(?!\\b)("+h+")(\\b|_)":"("+h+")","g"),e[f]="");return e}function C(a,b){for(let c=0,d=b.length;c<d&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a};function E(a){if(a=(""+a).toLowerCase())if(this.o&&(a=C(a,this.o)),this.A&&1<a.length&&(a=C(a,this.A)),A||""===A){const b=a.split(A);if(this.filter){a=this.filter;const c=b.length,d=[];for(let e=0,h=0;e<c;e++){const f=b[e];f&&!a[f]&&(d[h++]=f)}a=d}else a=b}return a};const F={},G={};function H(a,b,c,d){const e=a.length;let h=[],f,g,l=0;d&&(d=[]);for(let n=e-1;0<=n;n--){const m=a[n],r=m.length,p=y();let q=!f;for(let k=0;k<r;k++){const u=m[k],J=u.length;if(J)for(let D=0,x,w;D<J;D++)if(w=u[D],f){if(f[w]){if(!n)if(c)c--;else if(h[l++]=w,l===b)return h;if(n||d)p[w]=1;q=!0}if(d&&(x=(g[w]||0)+1,g[w]=x,x<e)){const K=d[x-2]||(d[x-2]=[]);K[K.length]=w}}else p[w]=1}if(d)f||(g=p);else if(!q)return[];f=p}if(d)for(let n=d.length-1,m,r;0<=n;n--){m=d[n];r=m.length;for(let p=0,q;p<r;p++)if(q= var t;function u(a,c,b){const d=typeof b,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(b){if("function"===e&&d===e)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===e?c:a}function v(){return Object.create(null)}function w(a,c){return c.length-a.length};const y=/[^\p{L}\p{N}]+/u,z=/(\d{3})/g,A=/(\D)(\d{3})/g,B=/(\d{3})(\D)/g,C="".normalize&&/[\u0300-\u036f]/g;function D(a={}){if(!(this instanceof D))return new D(...arguments);for(a=0;a<arguments.length;a++)this.assign(arguments[a])}
m[p],!f[q]){if(c)c--;else if(h[l++]=q,l===b)return h;f[q]=1}}return h};function I(a,b){if(!(this instanceof I))return new I(a);let c;if(a){var d=a.charset;c=a.lang;"string"===typeof d&&(-1===d.indexOf(":")&&(d+=":default"),d=G[d]);"string"===typeof c&&(c=F[c])}else a={};let e,h,f=a.context||{};this.encode=a.encode||d&&d.encode||E;this.register=b||y();this.s=e=a.resolution||9;this.B=b=d&&d.B||a.tokenize||"strict";this.i="strict"===b&&f.depth;this.j=t(f.bidirectional);this.g=h=t(a.optimize);this.m=t(a.fastupdate);this.h=a.minlength||1;this.C=a.boost;this.map=h?v(e):y(); D.prototype.assign=function(a){this.normalize=u(a.normalize,!0,this.normalize);let c=a.N,b=c||a.O||a.split;if("object"===typeof b){let d=!c,e="";a.N||(e+="\\p{Z}");b.P&&(e+="\\p{L}");b.R&&(e+="\\p{N}",d=!!c);b.T&&(e+="\\p{S}");b.S&&(e+="\\p{P}");b.control&&(e+="\\p{C}");if(b=b.char)e+="object"===typeof b?b.join(""):b;this.split=new RegExp("["+(c?"^":"")+e+"]+","u");this.numeric=d}else this.split=u(b,y,this.split),this.numeric=u(this.numeric,!0);this.H=u(a.H,null,this.H);this.D=u(a.D,null,this.D);
this.v=e=f.resolution||1;this.l=h?v(e):y();this.u=d&&d.u||a.rtl;this.o=(b=a.matcher||c&&c.o)&&B(b,!1);this.A=(b=a.stemmer||c&&c.A)&&B(b,!0);if(a=b=a.filter||c&&c.filter){a=b;d=y();for(let g=0,l=a.length;g<l;g++)d[a[g]]=1;a=d}this.filter=a}I.prototype.append=function(a,b){return this.add(a,b,!0)}; this.rtl=a.rtl||!1;this.l=u(a.l,!0,this.l);this.filter=u((b=a.filter)&&new Set(b),null,this.filter);this.m=u((b=a.m)&&new Map(b),null,this.m);this.v=u((b=a.v)&&new Map(b),null,this.v);this.s=u((b=a.s)&&new Map(b),null,this.s);this.o=u(a.o,null,this.o);this.G=u(a.G,1,this.G);this.K=u(a.K,0,this.K);if(this.cache=b=u(a.cache,!0,this.cache))this.C=null,this.L="number"===typeof b?b:2E5,this.u=new Map,this.A=new Map,this.h=this.g=128;this.i="";this.I=null;this.F="";this.J=null;if(this.m)for(const d of this.m.keys())this.i+=
I.prototype.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.register[a])return this.update(a,b);b=this.encode(b);if(d=b.length){const n=y(),m=y(),r=this.i,p=this.s;for(let q=0;q<d;q++){let k=b[this.u?d-1-q:q];var e=k.length;if(k&&e>=this.h&&(r||!m[k])){var h=L(p,d,q),f="";switch(this.B){case "full":if(2<e){for(h=0;h<e;h++)for(var g=e;g>h;g--)if(g-h>=this.h){var l=L(p,d,q,e,h);f=k.substring(h,g);M(this,m,f,l,a,c)}break}case "reverse":if(1<e){for(g=e-1;0<g;g--)f=k[g]+f,f.length>=this.h&&M(this, (this.i?"|":"")+d;if(this.s)for(const d of this.s.keys())this.F+=(this.F?"|":"")+d;return this};
m,f,L(p,d,q,e,g),a,c);f=""}case "forward":if(1<e){for(g=0;g<e;g++)f+=k[g],f.length>=this.h&&M(this,m,f,h,a,c);break}default:if(this.C&&(h=Math.min(h/this.C(b,k,q)|0,p-1)),M(this,m,k,h,a,c),r&&1<d&&q<d-1)for(e=y(),f=this.v,h=k,g=Math.min(r+1,d-q),e[h]=1,l=1;l<g;l++)if((k=b[this.u?d-1-q-l:q+l])&&k.length>=this.h&&!e[k]){e[k]=1;const u=this.j&&k>h;M(this,n,u?h:k,L(f+(d/2>f?0:1),d,q,g-1,l-1),a,c,u?k:h)}}}}this.m||(this.register[a]=1)}}return this}; D.prototype.encode=function(a){if(this.cache&&a.length<=this.g)if(this.C){if(this.u.has(a))return this.u.get(a)}else this.C=setTimeout(E,0,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):C?a.normalize("NFKD").replace(C,"").toLowerCase():a.toLowerCase());this.H&&(a=this.H(a));this.numeric&&3<a.length&&(a=a.replace(A,"$1 $2").replace(B,"$1 $2").replace(z,"$1 "));const c=!(this.l||this.v||this.filter||this.m||this.s||this.o);let b=[],d=this.split||""===this.split?a.split(this.split):
function L(a,b,c,d,e){return c&&1<a?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0}function M(a,b,c,d,e,h,f){let g=f?a.l:a.map;if(!b[c]||f&&!b[c][f])a.g&&(g=g[d]),f?(b=b[c]||(b[c]=y()),b[f]=1,g=g[f]||(g[f]=y())):b[c]=1,g=g[c]||(g[c]=[]),a.g||(g=g[d]||(g[d]=[])),h&&g.includes(e)||(g[g.length]=e,a.m&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=g))} a;for(let g=0,f,h;g<d.length;g++){if(!(f=h=d[g]))continue;if(f.length<this.G)continue;if(c){b.push(f);continue}if(this.filter&&this.filter.has(f))continue;if(this.cache&&f.length<=this.h)if(this.C){var e=this.A.get(f);if(e||""===e){e&&b.push(e);continue}}else this.C=setTimeout(E,0,this);let l;this.s&&2<f.length&&(this.J||(this.J=new RegExp("(?!^)("+this.F+")$")),f=f.replace(this.J,r=>this.s.get(r)),l=1);this.m&&1<f.length&&(this.I||(this.I=new RegExp("("+this.i+")","g")),f=f.replace(this.I,r=>this.m.get(r)),
I.prototype.search=function(a,b,c){c||(b||"object"!==typeof a?"object"===typeof b&&(c=b):(c=a,a=c.query));let d=[],e;let h,f=0;if(c){a=c.query||a;b=c.limit;f=c.offset||0;var g=c.context;h=!1}if(a&&(a=this.encode(""+a),e=a.length,1<e)){c=y();var l=[];for(let m=0,r=0,p;m<e;m++)if((p=a[m])&&p.length>=this.h&&!c[p])if(this.g||h||this.map[p])l[r++]=p,c[p]=1;else return d;a=l;e=a.length}if(!e)return d;b||(b=100);g=this.i&&1<e&&!1!==g;c=0;let n;g?(n=a[0],c=1):1<e&&a.sort(z);for(let m,r;c<e;c++){r=a[c];g? l=1);f&&l&&(f.length<this.G||this.filter&&this.filter.has(f))&&(f="");if(f&&(this.v||this.l&&1<f.length)){e="";for(let r=0,k="",p,q;r<f.length;r++)p=f.charAt(r),p===k&&this.l||((q=this.v&&this.v.get(p))||""===q?q===k&&this.l||!(k=q)||(e+=q):e+=k=p);f=e}if(f&&this.o)for(e=0;f&&e<this.o.length;e+=2)f=f.replace(this.o[e],this.o[e+1]);this.cache&&h.length<=this.h&&(this.A.set(h,f),this.A.size>this.L&&(this.A.clear(),this.h=this.h/1.1|0));f&&b.push(f)}this.D&&(b=this.D(b)||b);this.cache&&a.length<=this.g&&
(m=N(this,d,h,b,f,2===e,r,n),h&&!1===m&&d.length||(n=r)):m=N(this,d,h,b,f,1===e,r);if(m)return m;if(h&&c===e-1){l=d.length;if(!l){if(g){g=0;c=-1;continue}return d}if(1===l)return O(d[0],b,f)}}return H(d,b,f,h)}; (this.u.set(a,b),this.u.size>this.L&&(this.u.clear(),this.g=this.g/1.1|0));return b};function E(a){a.C=null;a.u.clear();a.A.clear()};function F(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.g=""}F.prototype.set=function(a,c){this.cache.has(a)||(this.cache.set(this.g=a,c),this.limit&&this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value))};F.prototype.get=function(a){const c=this.cache.get(a);c&&this.limit&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};F.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};
function N(a,b,c,d,e,h,f,g){let l=[],n=g?a.l:a.map;a.g||(n=P(n,f,g,a.j));if(n){let m=0;const r=Math.min(n.length,g?a.v:a.s);for(let p=0,q=0,k,u;p<r;p++)if(k=n[p])if(a.g&&(k=P(k,f,g,a.j)),e&&k&&h&&(u=k.length,u<=e?(e-=u,k=null):(k=k.slice(e),e=0)),k&&(l[m++]=k,h&&(q+=k.length,q>=d)))break;if(m){if(h)return O(l,d,0);b[b.length]=l;return}}return!c&&l}function O(a,b,c){a=1===a.length?a[0]:[].concat.apply([],a);return c||a.length>b?a.slice(c,c+b):a} F.prototype.clear=function(){this.cache.clear();this.g=""};function G(a=8){if(!(this instanceof G))return new G(a);this.index=v();this.i=[];this.size=0;32<a?(this.g=H,this.h=BigInt(a)):(this.g=I,this.h=a)}G.prototype.get=function(a){const c=this.index[this.g(a)];return c&&c.get(a)};G.prototype.set=function(a,c){var b=this.g(a);let d=this.index[b];d?(b=d.size,d.set(a,c),(b-=d.size)&&this.size++):(this.index[b]=d=new Map([[a,c]]),this.i.push(d))};
function P(a,b,c,d){c?(d=d&&b>c,a=(a=a[d?b:c])&&a[d?c:b]):a=a[b];return a}I.prototype.contain=function(a){return!!this.register[a]};I.prototype.update=function(a,b){return this.remove(a).add(a,b)};I.prototype.remove=function(a,b){const c=this.register[a];if(c){if(this.m)for(let d=0,e;d<c.length;d++)e=c[d],e.splice(e.indexOf(a),1);else Q(this.map,a,this.s,this.g),this.i&&Q(this.l,a,this.v,this.g);b||delete this.register[a]}return this}; function J(a=8){if(!(this instanceof J))return new J(a);this.index=v();this.g=[];32<a?(this.i=H,this.h=BigInt(a)):(this.i=I,this.h=a)}J.prototype.add=function(a){var c=this.i(a);let b=this.index[c];b?(c=b.size,b.add(a),(c-=b.size)&&this.size++):(this.index[c]=b=new Set([a]),this.g.push(b))};t=G.prototype;t.has=J.prototype.has=function(a){const c=this.index[this.i(a)];return c&&c.has(a)};t.delete=J.prototype.delete=function(a){const c=this.index[this.i(a)];c&&c.delete(a)&&this.size--};
function Q(a,b,c,d,e){let h=0;if(a.constructor===Array)if(e)b=a.indexOf(b),-1!==b?1<a.length&&(a.splice(b,1),h++):h++;else{e=Math.min(a.length,c);for(let f=0,g;f<e;f++)if(g=a[f])h=Q(g,b,c,d,e),d||h||delete a[f]}else for(let f in a)(h=Q(a[f],b,c,d,e))||delete a[f];return h};export default {Index:I,Document:null,Worker:null,registerCharset:function(a,b){G[a]=b},registerLanguage:function(a,b){F[a]=b}}; t.clear=J.prototype.clear=function(){this.index=v();this.g=[];this.size=0};t.values=J.prototype.values=function*(){for(let a=0;a<this.g.length;a++)for(let c of this.g[a].values())yield c};t.keys=J.prototype.keys=function*(){for(let a=0;a<this.g.length;a++)for(let c of this.g[a].keys())yield c};t.entries=J.prototype.entries=function*(){for(let a=0;a<this.g.length;a++)for(let c of this.g[a].entries())yield c};
function I(a){let c=2**this.h-1;if("number"==typeof a)return a&c;let b=0,d=this.h+1;for(let e=0;e<a.length;e++)b=(b*d^a.charCodeAt(e))&c;return 32===this.h?b+2**31:b}function H(a){let c=BigInt(2)**this.h-BigInt(1);var b=typeof a;if("bigint"===b)return a&c;if("number"===b)return BigInt(a)&c;b=BigInt(0);let d=this.h+BigInt(1);for(let e=0;e<a.length;e++)b=(b*d^BigInt(a.charCodeAt(e)))&c;return b};const K=v(),L=v();var M={normalize:function(a){return a.toLowerCase()},l:!1};const O={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};v();P.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.j.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const r=v(),k=v(),p=this.depth,q=this.resolution;for(let m=0;m<d;m++){let n=c[this.rtl?d-1-m:m];var e=n.length;if(e&&(p||!k[n])){var g=this.score?this.score(c,n,m,null,0):Q(q,d,m),f="";switch(this.tokenize){case "full":if(2<e){for(g=0;g<e;g++)for(var h=e;h>g;h--){f=n.substring(g,h);var l=this.score?this.score(c,n,m,f,g):Q(q,d,m,e,g);R(this,k,f,l,a,b)}break}case "reverse":if(1<
e){for(h=e-1;0<h;h--)f=n[h]+f,l=this.score?this.score(c,n,m,f,h):Q(q,d,m,e,h),R(this,k,f,l,a,b);f=""}case "forward":if(1<e){for(h=0;h<e;h++)f+=n[h],R(this,k,f,g,a,b);break}default:if(R(this,k,n,g,a,b),p&&1<d&&m<d-1)for(e=v(),f=this.M,g=n,h=Math.min(p+1,d-m),e[g]=1,l=1;l<h;l++)if((n=c[this.rtl?d-1-m-l:m+l])&&!e[n]){e[n]=1;const x=this.score?this.score(c,g,m,n,l):Q(f+(d/2>f?0:1),d,m,h-1,l-1),N=this.bidirectional&&n>g;R(this,r,N?g:n,x,a,b,N?n:g)}}}}this.fastupdate||this.j.add(a)}}return this};
function R(a,c,b,d,e,g,f){let h=f?a.B:a.map,l;c[b]&&f&&(l=c[b])[f]||(f?(c=l||(c[b]=v()),c[f]=1,(l=h.get(f))?h=l:h.set(f,h=new Map)):c[b]=1,(l=h.get(b))?h=l:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.j.get(e))?c.push(h):a.j.set(e,[h]))))}function Q(a,c,b,d,e){return b&&1<a?c+(d||0)<=a?b+(e||0):(a-1)/(c+(d||0))*(b+(e||0))+1|0:0};function S(a,c,b){if(1===a.length)return a=a[0],a=b||a.length>c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e<a.length;e++)if((g=a[e])&&(f=g.length)){if(b){if(b>=f){b-=f;continue}b<f&&(g=c?g.slice(b,b+c):g.slice(b),f=g.length,b=0)}if(d.length)f>c&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1<d.length?[].concat.apply([],d):d[0]:d};function T(a,c,b,d){var e=a.length;let g=[],f=0,h,l,r;d&&(d=[]);for(let k=e-1,p;0<=k;k--){r=a[k];e=v();p=!h;for(let q=0,m;q<r.length;q++)if((m=r[q])&&m.length)for(let n=0,x;n<m.length;n++)if(x=m[n],h){if(h[x]){if(!k)if(b)b--;else if(g[f++]=x,f===c)return g;if(k||d)e[x]=1;p=!0}d&&!l[x]&&(l[x]=1,(d[q]||(d[q]=[])).push(x))}else e[x]=1;if(d)h||(l=e);else if(!p)return[];h=e}if(d)for(let k=d.length-1,p,q;0<=k;k--){p=d[k];q=p.length;for(let m=0,n;m<q;m++)if(n=p[m],!h[n]){if(b)b--;else if(g[f++]=n,f===c)return g;
h[n]=1}}return g};P.prototype.search=function(a,c,b){b||(c||"object"!==typeof a?"object"===typeof c&&(b=c,c=0):(b=a,a=""));let d=[];let e,g=0;if(b){a=b.query||a;c=b.limit||c;g=b.offset||0;var f=b.context;e=!1}a=this.encoder.encode(a);b=a.length;c||(c=100);if(1===b)return U.call(this,a[0],"",c,g);f=this.depth&&!1!==f;if(2===b&&f&&!e)return U.call(this,a[0],a[1],c,g);let h=0,l=0;if(1<b){var r=v();const p=[];for(let q=0,m;q<b;q++)if((m=a[q])&&!r[m]){if(e||V(this,m))p.push(m),r[m]=1;else return d;const n=m.length;h=Math.max(h,
n);l=l?Math.min(l,n):n}a=p;b=a.length}if(!b)return d;r=0;let k;if(1===b)return U.call(this,a[0],"",c,g);if(2===b&&f&&!e)return U.call(this,a[0],a[1],c,g);1<b&&(f?(k=a[0],r=1):9<h&&3<h/l&&a.sort(w));for(let p,q;r<b;r++){q=a[r];k?(p=V(this,q,k),p=W(p,d,e,this.M,c,g,2===b),e&&!1===p&&d.length||(k=q)):(p=V(this,q),p=W(p,d,e,this.resolution,c,g,1===b));if(p)return p;if(e&&r===b-1){f=d.length;if(!f){if(k){k="";r=-1;continue}return d}if(1===f)return S(d[0],c,g)}}return T(d,c,g,e)};
function U(a,c,b,d){return(a=V(this,a,c))&&a.length?S(a,b,d):[]}function W(a,c,b,d,e,g,f){let h=[];if(a){d=Math.min(a.length,d);for(let l=0,r=0,k;l<d;l++)if(k=a[l])if(g&&k&&f&&(k.length<=g?(g-=k.length,k=null):(k=k.slice(g),g=0)),k&&(h[l]=k,f&&(r+=k.length,r>=e)))break;if(h.length){if(f)return S(h,e,0);c.push(h);return}}return!b&&h}function V(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.B.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};P.prototype.remove=function(a,c){const b=this.j.size&&(this.fastupdate?this.j.get(a):this.j.has(a));if(b){if(this.fastupdate)for(let d=0,e;d<b.length;d++){if(e=b[d])if(2>e.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else X(this.map,a),this.depth&&X(this.B,a);c||this.j.delete(a)}this.cache&&this.cache.remove(a);return this};
function X(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;d<a.length;d++){if((e=a[d])&&e.length)if(g=e.indexOf(c),0<=g){1<e.length?(e.splice(g,1),b++):delete a[d];break}else b++}else for(let d of a){const e=d[0],g=X(d[1],c);g?b+=g:a.delete(e)}return b};function P(a,c){if(!(this instanceof P))return new P(a);if(a){var b="string"===typeof a?a:a.preset;b&&(a=Object.assign({},O[b],a))}else a={};b=a.context||{};const d=a.encode||a.encoder||M;this.encoder=d.encode?d:"object"===typeof d?new D(d):{encode:d};let e;this.resolution=a.resolution||9;this.tokenize=e=a.tokenize||"strict";this.depth="strict"===e&&b.depth||0;this.bidirectional=!1!==b.bidirectional;this.fastupdate=!!a.fastupdate;this.score=a.score||null;this.map=(e=!1,new Map);this.B=e?new G(e):
new Map;this.j=c||(this.fastupdate?e?new G(e):new Map:e?new J(e):new Set);this.M=b.resolution||1;this.rtl=d.rtl||a.rtl||!1;this.cache=(e=a.cache||null)&&new F(e)}t=P.prototype;t.clear=function(){this.map.clear();this.B.clear();this.j.clear();this.cache&&this.cache.clear();return this};t.append=function(a,c){return this.add(a,c,!0)};t.contain=function(a){return this.j.has(a)};
t.update=function(a,c){if(this.async){const b=this,d=this.remove(a);return d.then?d.then(()=>b.add(a,c)):this.add(a,c)}return this.remove(a).add(a,c)};function Y(a){let c=0;if(a.constructor===Array)for(let b=0,d;b<a.length;b++)(d=a[b])&&(c+=d.length);else for(const b of a){const d=b[0],e=Y(b[1]);e?c+=e:a.delete(d)}return c}t.cleanup=function(){if(!this.fastupdate)return this;Y(this.map);this.depth&&Y(this.B);return this};
t.searchCache=function(a,c,b){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,c,b);if(d instanceof Promise){const e=this;d.then(function(g){e.cache.set(a,g)})}this.cache.set(a,d)}return d};export default {Index:P,Encoder:D,Charset:L,Language:K,Document:null,Worker:null,Resolver:null,IndexedDB:null};
export const Index=P;export const Encoder=D;export const Charset=L;export const Language=K;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;

View File

@@ -1,51 +1,71 @@
import { IndexInterface, DocumentInterface } from "./type.js"; import Document from "./document.js";
//import { promise as Promise } from "./polyfill.js"; import Index from "./index.js";
import { is_function, is_object, is_string } from "./common.js";
export default function (prototype) { export default function (prototype) {
register.call(prototype, "add");
register(prototype, "add"); register.call(prototype, "append");
register(prototype, "append"); register.call(prototype, "search");
register(prototype, "search"); register.call(prototype, "update");
register(prototype, "update"); register.call(prototype, "remove");
register(prototype, "remove");
} }
function register(prototype, key) { // let cycle;
// let budget = 0;
//
// function tick(resolve){
// cycle = null;
// budget = 0;
// resolve();
// }
prototype[key + "Async"] = function () { /**
* @param {!string} key
* @this {Index|Document}
*/
/** @type {IndexInterface|DocumentInterface} */ function register(key) {
const self = this, this[key + "Async"] = function () {
args = /*[].slice.call*/arguments,
// // prevent stack overflow of adding too much tasks to the same event loop
// // actually limit stack to 1,000,000 tasks every ~4ms
// cycle || (
// cycle = new Promise(resolve => setTimeout(tick, 0, resolve))
// );
//
// // apply different performance budgets
// if(key === "update" || key === "remove" && this.fastupdate === false){
// budget += 1000 * this.resolution;
// if(this.depth)
// budget += 1000 * this.resolution_ctx;
// }
// else if(key === "search"){
// budget++;
// }
// else{
// budget += 20 * this.resolution;
// if(this.depth)
// budget += 20 * this.resolution_ctx;
// }
//
// // wait for the event loop cycle
// if(budget >= 1e6){
// await cycle;
// }
const args = /*[].slice.call*/arguments,
arg = args[args.length - 1]; arg = args[args.length - 1];
let callback; let callback;
if (is_function(arg)) { if ("function" == typeof arg) {
callback = arg; callback = arg;
delete args[args.length - 1]; delete args[args.length - 1];
} }
const promise = new Promise(function (resolve) { this.async = !0;
const res = this[key].apply(this, args);
setTimeout(function () { this.async = !1;
res.then ? res.then(callback) : callback(res);
self.async = !0; return res;
const res = self[key].apply(self, args);
self.async = !1;
resolve(res);
});
});
if (callback) {
promise.then(callback);
return this;
} else {
return promise;
}
}; };
} }

View File

@@ -1,168 +1,77 @@
import { IndexInterface, DocumentInterface } from "./type.js"; import Index from "./index.js";
import { create_object, is_object } from "./common.js"; import Document from "./document.js";
/**
* @param {string|Object} query
* @param {number|Object=} limit
* @param {Object=} options
* @this {Index|Document}
* @returns {Array<number|string>|Promise}
*/
export function searchCache(query, limit, options) {
query = ("object" == typeof query ? "" + query.query : "" + query).toLowerCase();
//let encoded = this.encoder.encode(query).join(" ");
let cache = this.cache.get(query);
if (!cache) {
cache = this.search(query, limit, options);
if (cache instanceof Promise) {
const self = this;
cache.then(function (cache) {
self.cache.set(query, cache);
});
}
this.cache.set(query, cache);
}
return cache;
}
/** /**
* @param {boolean|number=} limit * @param {boolean|number=} limit
* @constructor * @constructor
*/ */
function CacheClass(limit) { export default function CacheClass(limit) {
/** @private */ /** @private */
this.limit = !0 !== limit && limit; this.limit = !limit || !0 === limit ? 1000 : limit;
/** @private */ /** @private */
this.cache = create_object(); this.cache = new Map();
/** @private */ /** @private */
this.queue = []; this.last = "";
//this.clear();
} }
export default CacheClass;
/**
* @param {string|Object} query
* @param {number|Object=} limit
* @param {Object=} options
* @this {IndexInterface}
* @returns {Array<number|string>}
*/
export function searchCache(query, limit, options) {
if (is_object(query)) {
query = query.query;
}
let cache = this.cache.get(query);
if (!cache) {
cache = this.search(query, limit, options);
this.cache.set(query, cache);
}
return cache;
}
// CacheClass.prototype.clear = function(){
//
// /** @private */
// this.cache = create_object();
//
// /** @private */
// this.queue = [];
// };
CacheClass.prototype.set = function (key, value) { CacheClass.prototype.set = function (key, value) {
if (!this.cache.has(key)) {
if (!this.cache[key]) { this.cache.set(this.last = key, value);
if (this.limit && this.cache.size > this.limit) {
// it is just a shame that native function array.shift() performs so bad this.cache.delete(this.cache.keys().next().value);
// const length = this.queue.length;
//
// this.queue[length] = key;
//
// if(length === this.limit){
//
// delete this.cache[this.queue.shift()];
// }
// the same bad performance
// this.queue.unshift(key);
//
// if(this.queue.length === this.limit){
//
// this.queue.pop();
// }
// fast implementation variant
// let length = this.queue.length;
//
// if(length === this.limit){
//
// length--;
//
// delete this.cache[this.queue[0]];
//
// for(let x = 0; x < length; x++){
//
// this.queue[x] = this.queue[x + 1];
// }
// }
//
// this.queue[length] = key;
// current fastest implementation variant
// theoretically that should not perform better compared to the example above
let length = this.queue.length;
if (length === this.limit) {
delete this.cache[this.queue[length - 1]];
} else {
length++;
} }
for (let x = length - 1; 0 < x; x--) {
this.queue[x] = this.queue[x - 1];
} }
this.queue[0] = key;
}
this.cache[key] = value;
}; };
CacheClass.prototype.get = function (key) { CacheClass.prototype.get = function (key) {
const cache = this.cache.get(key);
const cache = this.cache[key]; if (cache && this.limit && this.last !== key) {
this.cache.delete(key);
if (this.limit && cache) { this.cache.set(this.last = key, cache);
// probably the indexOf() method performs faster when matched content is on front (left-to-right)
// using lastIndexOf() does not help, it performs almost slower
const pos = this.queue.indexOf(key);
// if(pos < this.queue.length - 1){
//
// const tmp = this.queue[pos];
// this.queue[pos] = this.queue[pos + 1];
// this.queue[pos + 1] = tmp;
// }
if (pos) {
const tmp = this.queue[pos - 1];
this.queue[pos - 1] = this.queue[pos];
this.queue[pos] = tmp;
} }
}
return cache; return cache;
}; };
CacheClass.prototype.del = function (id) { CacheClass.prototype.remove = function (id) {
for (const item of this.cache) {
const key = item[0],
value = item[1];
for (let i = 0, item, key; i < this.queue.length; i++) { if (value.includes(id)) {
this.cache.delete(key);
key = this.queue[i];
item = this.cache[key];
if (item.includes(id)) {
this.queue.splice(i--, 1);
delete this.cache[key];
} }
} }
}; };
CacheClass.prototype.clear = function () {
this.cache.clear();
this.last = "";
};

View File

@@ -1,6 +1,65 @@
export function parse_option(value, default_value) { /**
* @param {*} value
* @param {*} default_value
* @param {*=} merge_value
* @return {*}
*/
return "undefined" != typeof value ? value : default_value; export function parse_option(value, default_value, merge_value) {
const type_merge = typeof merge_value,
type_value = typeof value;
if ("undefined" != type_merge) {
if ("undefined" != type_value) {
if (merge_value) {
if ("function" == type_value && type_merge == type_value) {
return function (str) {
return (/** @type Function */value(
/** @type Function */merge_value(str))
);
};
}
const constructor_value = value.constructor,
constructor_merge = merge_value.constructor;
if (constructor_value === constructor_merge) {
if (constructor_value === Array) {
return merge_value.concat(value);
}
if (constructor_value === Map) {
const map = new Map( /** @type !Map */merge_value);
for (const item of /** @type !Map */value) {
const key = item[0],
val = item[1];
map.set(key, val);
}
return map;
}
if (constructor_value === Set) {
const set = new Set( /** @type !Set */merge_value);
for (const val of /** @type !Set */value.values()) {
set.add(val);
}
return set;
}
}
}
return value;
} else {
return merge_value;
}
}
return "undefined" == type_value ? default_value : value;
} }
/** /**
@@ -13,19 +72,33 @@ export function create_object_array(count) {
const array = Array(count); const array = Array(count);
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
array[i] = create_object(); array[i] = create_object();
} }
return array; return array;
} }
/**
* @param {!number} count
* @returns {Array<Object>}
*/
export function create_map_array(count) {
const array = Array(count);
for (let i = 0; i < count; i++) {
array[i] = new Map();
}
return array;
}
export function create_arrays(count) { export function create_arrays(count) {
const array = Array(count); const array = Array(count);
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
array[i] = []; array[i] = [];
} }
@@ -38,41 +111,75 @@ export function create_arrays(count) {
*/ */
export function get_keys(obj) { export function get_keys(obj) {
return Object.keys(obj); return Object.keys(obj);
} }
export function create_object() { export function create_object() {
return Object.create(null); return Object.create(null);
} }
export function concat(arrays) { export function concat(arrays) {
return [].concat.apply([], arrays); return [].concat.apply([], arrays);
} }
export function sort_by_length_down(a, b) { export function sort_by_length_down(a, b) {
return b.length - a.length; return b.length - a.length;
} }
export function is_array(val) { export function sort_by_length_up(a, b) {
return a.length - b.length;
}
export function is_array(val) {
return val.constructor === Array; return val.constructor === Array;
} }
export function is_string(val) { export function is_string(val) {
return "string" == typeof val; return "string" == typeof val;
} }
export function is_object(val) { export function is_object(val) {
return "object" == typeof val; return "object" == typeof val;
} }
export function is_function(val) { export function is_function(val) {
return "function" == typeof val; return "function" == typeof val;
} }
/**
* @param {Map|Set} val
* @param {boolean=} stringify
* @return {Array}
*/
export function toArray(val, stringify) {
const result = [];
for (const key of val.keys()) {
result.push(stringify ? "" + key : key);
}
return result;
}
// TODO support generic function created from string when tree depth > 1
export function parse_simple(obj, tree) {
if (is_string(tree)) {
obj = obj[tree];
} else for (let i = 0; obj && i < tree.length; i++) {
obj = obj[tree[i]];
}
return obj;
}
export function get_max_len(arr) {
let len = 0;
for (let i = 0, res; i < arr.length; i++) {
if (res = arr[i]) {
if (len < res.length) {
len = res.length;
}
}
}
return len;
}

65
dist/module-debug/compress.js vendored Normal file
View File

@@ -0,0 +1,65 @@
let table, timer; // = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
const cache = new Map();
function toRadix(number, radix = 255) {
if (!table) {
table = Array(radix);
// the char code 0 could be a special marker
for (let i = 0; i < radix; i++) table[i] = i + 1;
table = String.fromCharCode.apply(null, table);
}
let rixit,
residual = number,
result = "";
while (!0) {
rixit = residual % radix;
result = table.charAt(rixit) + result;
residual = 0 | residual / radix;
if (!residual) break;
}
return result;
}
export default function (str) {
if (timer) {
if (cache.has(str)) {
return cache.get(str);
}
} else {
timer = setTimeout(clear);
}
/* 2 ** ((level + 1.5) * 1.6 | 0) */
const result = toRadix("number" == typeof str ? str : lcg(str));
2e5 < cache.size && cache.clear();
cache.set(str, result);
return result;
}
function lcg(str) {
let range = 4294967295;
if ("number" == typeof str) {
return str & range;
}
let crc = 0;
for (let i = 0; i < str.length; i++) {
crc = (crc * 33 ^ str.charCodeAt(i)) & range;
}
// shift up from Int32 to UInt32 range 0xFFFFFFFF
return crc + 2147483648;
}
function clear() {
timer = null;
cache.clear();
}

648
dist/module-debug/db/clickhouse/index.js vendored Normal file
View File

@@ -0,0 +1,648 @@
import { ClickHouse } from "clickhouse";
import StorageInterface from "../interface.js";
import Document from "../../document.js";
import { concat, toArray } from "../../common.js";
const defaults = {
host: "http://localhost",
port: "8123",
debug: !1,
basicAuth: null,
isUseGzip: !1,
trimQuery: !1,
usePost: !1,
format: "json",
raw: !1,
config: {
output_format_json_quote_64bit_integers: 0,
enable_http_compression: 0,
database: "default"
}
},
VERSION = 1,
fields = ["map", "ctx", "tag", "reg", "cfg"],
types = {
text: "String",
char: "String",
varchar: "String",
string: "String",
number: "Int32",
numeric: "Int32",
integer: "Int32",
smallint: "Int16",
tinyint: "Int8",
mediumint: "Int32",
int: "Int32",
int8: "Int8",
uint8: "UInt8",
int16: "Int16",
uint16: "UInt16",
int32: "Int32",
uint32: "UInt32",
int64: "Int64",
uint64: "UInt64",
bigint: "Int64"
};
function sanitize(str) {
return str.toLowerCase().replace(/[^a-z0-9_]/g, "");
}
let DB;
/**
* @constructor
* @implements StorageInterface
*/
export default function ClickhouseDB(name, config = {}) {
if (!(this instanceof ClickhouseDB)) {
return new ClickhouseDB(name, config);
}
if ("object" == typeof name) {
name = name.name;
config = name;
}
if (!name) {
console.info("Default storage space was used, because a name was not passed.");
}
//field = "Test-456";
this.id = "flexsearch" + (name ? "_" + sanitize(name) : "");
this.field = config.field ? "_" + sanitize(config.field) : "";
// Clickhouse does not support ALTER TABLE to upgrade
// the type of the ID when it is a part of the merge key
this.type = config.type ? types[config.type.toLowerCase()] : "String";
if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'");
//this.trx = false;
this.support_tag_search = !0;
this.db = DB || (DB = config.db || null);
Object.assign(defaults, config);
config.database && (defaults.config.database = config.database);
this.db && delete defaults.db;
}
ClickhouseDB.prototype.mount = function (flexsearch) {
if (flexsearch instanceof Document) {
return flexsearch.mount(this);
}
defaults.resolution = Math.max(flexsearch.resolution, flexsearch.resolution_ctx);
flexsearch.db = this;
return this.open();
};
ClickhouseDB.prototype.open = async function () {
if (!this.db) {
this.db = DB || (DB = new ClickHouse(defaults));
}
const exists = await this.db.query(`
SELECT 1 FROM system.databases WHERE name = '${this.id}';
`).toPromise();
if (!exists || !exists.length) {
await this.db.query(`
CREATE DATABASE IF NOT EXISTS ${this.id};
`).toPromise();
}
for (let i = 0; i < fields.length; i++) {
switch (fields[i]) {
case "map":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.map${this.field}(
key String,
res ${255 >= defaults.resolution ? "UInt8" : "UInt16"},
id ${this.type}
)
ENGINE = MergeTree
/*PRIMARY KEY (key)*/
ORDER BY (key, id);
`, { params: { name: this.id + ".map" + this.field } }).toPromise();
break;
case "ctx":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.ctx${this.field}(
ctx String,
key String,
res ${255 >= defaults.resolution ? "UInt8" : "UInt16"},
id ${this.type}
)
ENGINE = MergeTree
/*PRIMARY KEY (ctx, key)*/
ORDER BY (ctx, key, id);
`).toPromise();
break;
case "tag":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.tag${this.field}(
tag String,
id ${this.type}
)
ENGINE = MergeTree
/*PRIMARY KEY (ctx, key)*/
ORDER BY (tag, id);
`).toPromise();
break;
case "reg":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.reg(
id ${this.type},
doc Nullable(String)
)
ENGINE = MergeTree
ORDER BY (id);
`).toPromise();
break;
case "cfg":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.cfg${this.field}(
cfg String
)
ENGINE = TinyLog;
`).toPromise();
break;
}
}
return this.db;
};
ClickhouseDB.prototype.close = function () {
this.db.close();
this.db = null;
return this;
};
ClickhouseDB.prototype.destroy = async function () {
await Promise.all([this.db.query(`DROP TABLE ${this.id}.map${this.field};`).toPromise(), this.db.query(`DROP TABLE ${this.id}.ctx${this.field};`).toPromise(), this.db.query(`DROP TABLE ${this.id}.tag${this.field};`).toPromise(), this.db.query(`DROP TABLE ${this.id}.cfg${this.field};`).toPromise(), this.db.query(`DROP TABLE ${this.id}.reg;`).toPromise()]);
this.close();
};
ClickhouseDB.prototype.clear = function () {
return Promise.all([this.db.query(`TRUNCATE TABLE ${this.id}.map${this.field};`).toPromise(), this.db.query(`TRUNCATE TABLE ${this.id}.ctx${this.field};`).toPromise(), this.db.query(`TRUNCATE TABLE ${this.id}.tag${this.field};`).toPromise(), this.db.query(`TRUNCATE TABLE ${this.id}.cfg${this.field};`).toPromise(), this.db.query(`TRUNCATE TABLE ${this.id}.reg;`).toPromise()]);
};
function create_result(rows, resolve, enrich) {
if (resolve) {
for (let i = 0; i < rows.length; i++) {
if (enrich) {
if (rows[i].doc) {
rows[i].doc = JSON.parse(rows[i].doc);
}
} else {
rows[i] = rows[i].id;
}
}
return rows;
} else {
const arr = [];
for (let i = 0, row; i < rows.length; i++) {
row = rows[i];
arr[row.res] || (arr[row.res] = []);
arr[row.res].push(enrich ? row : row.id);
}
return arr;
}
}
ClickhouseDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = !0, enrich = !1, tags) {
let rows,
params = ctx ? { ctx, key } : { key },
table = this.id + (ctx ? ".ctx" : ".map") + this.field;
if (tags) {
for (let i = 0, count = 1; i < tags.length; i += 2) {
` AND ${table}.id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = {tag${count}:String})`;
params["tag" + count] = tags[i + 1];
count++;
}
}
if (ctx) {
rows = this.db.query(`
SELECT ${table}.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE ctx = {ctx:String} AND key = {key:String}
ORDER BY res
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, { params }).toPromise();
} else {
rows = this.db.query(`
SELECT ${table}.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE key = {key:String}
ORDER BY res
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, { params }).toPromise();
}
return rows.then(function (rows) {
return create_result(rows, resolve, enrich);
});
};
ClickhouseDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) {
const table = this.id + ".tag" + this.field,
promise = this.db.query(`
SELECT ${table}.id
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE tag = {tag:String}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, { params: { tag } }).toPromise();
enrich || promise.then(function (rows) {
return create_result(rows, !0, !1);
});
return promise;
};
ClickhouseDB.prototype.enrich = async function (ids) {
let MAXIMUM_QUERY_VARS = 1e5,
result = [];
if ("object" != typeof ids) {
ids = [ids];
}
for (let count = 0; count < ids.length;) {
const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids;
count += chunk.length;
let params = {},
stmt = "";
for (let i = 0; i < chunk.length; i++) {
stmt += (stmt ? "," : "") + "{id" + (i + 1) + ":String}";
params["id" + (i + 1)] = chunk[i];
}
const res = await this.db.query(`
SELECT id, doc
FROM ${this.id}.reg
WHERE id IN (${stmt})`, { params }).toPromise();
if (res && res.length) {
for (let i = 0, doc; i < res.length; i++) {
if (doc = res[i].doc) {
res[i].doc = JSON.parse(doc);
}
}
result.push(res);
}
}
return 1 === result.length ? result[0] : 1 < result.length ? concat(result) : result;
};
ClickhouseDB.prototype.has = function (id) {
return this.db.query(`
SELECT EXISTS(
SELECT 1
FROM ${this.id}.reg
WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}}
LIMIT 1
)`, { params: { id } }).toPromise();
};
ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !0, tags) {
let rows;
if (1 < query.length && flexsearch.depth) {
let where = "",
params = {},
keyword = query[0],
term;
for (let i = 1; i < query.length; i++) {
term = query[i];
const swap = flexsearch.bidirectional && term > keyword;
where += (where ? " OR " : "") + `(ctx = {ctx${i}:String} AND key = {key${i}:String})`;
params["ctx" + i] = swap ? term : keyword;
params["key" + i] = swap ? keyword : term;
keyword = term;
}
if (tags) {
where = "(" + where + ")";
for (let i = 0, count = 1; i < tags.length; i += 2) {
where += ` AND id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = {tag${count}:String})`;
params["tag" + count] = tags[i + 1];
count++;
}
}
rows = this.db.query(`
SELECT r.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM (
SELECT id, count(*) as count,
${suggest ? "SUM" : "MIN"}(res) as res
FROM ${this.id}.ctx${this.field}
WHERE ${where}
GROUP BY id
) as r
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = r.id
` : ""}
${suggest ? "" : "WHERE count = " + (query.length - 1)}
ORDER BY ${suggest ? "count DESC, res" : "res"}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`, { params }).toPromise();
// for(let i = 1; i < query.length; i++){
// where += (where ? " UNION ALL " : "") + `
// SELECT id, res
// FROM ${this.id}.ctx${this.field}
// WHERE ctx = {ctx${i}:String} AND key = {key${i}:String}
// `;
// term = query[i];
// const swap = flexsearch.bidirectional && (term > keyword);
// params["ctx" + i] = swap ? term : keyword;
// params["key" + i] = swap ? keyword : term;
// keyword = term;
// }
//
// rows = await this.db.query(`
// SELECT id, res
// FROM (
// SELECT id, ${suggest ? "SUM" : "MIN"}(res) as res, count(*) as count
// FROM (${where}) as t
// GROUP BY id
// ORDER BY ${suggest ? "count DESC, res" : "res"}
// LIMIT ${limit}
// OFFSET ${offset}
// ) as r
// ${suggest ? "" : "WHERE count = " + (query.length - 1)}
// `, { params }).toPromise();
} else {
let where = "",
params = {};
for (let i = 0; i < query.length; i++) {
where += (where ? "," : "") + `{key${i}:String}`;
params["key" + i] = query[i];
}
where = "key " + (1 < query.length ? "IN (" + where + ")" : "= " + where);
if (tags) {
where = "(" + where + ")";
for (let i = 0, count = 1; i < tags.length; i += 2) {
where += ` AND id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = {tag${count}:String})`;
params["tag" + count] = tags[i + 1];
count++;
}
}
rows = this.db.query(`
SELECT r.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM (
SELECT id, count(*) as count,
${suggest ? "SUM" : "MIN"}(res) as res
FROM ${this.id}.map${this.field}
WHERE ${where}
GROUP BY id
) as r
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = r.id
` : ""}
${suggest ? "" : "WHERE count = " + query.length}
ORDER BY ${suggest ? "count DESC, res" : "res"}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`, { params }).toPromise();
// for(let i = 0; i < query.length; i++){
// params["key" + i] = query[i];
// where += (where ? " UNION ALL " : "") + `
// SELECT id, res
// FROM ${ this.id }.map${ this.field }
// WHERE key = {key${i}:String}
// `;
// }
// rows = await this.db.query(`
// SELECT id, res
// FROM (
// SELECT id, ${suggest ? "SUM" : "MIN"}(res) as res, count(*) as count
// FROM (${where}) as t
// GROUP BY id
// ORDER BY ${suggest ? "count DESC, res" : "res"}
// LIMIT ${limit}
// OFFSET ${offset}
// ) as r
// ${ suggest ? "" : "WHERE count = " + query.length }
// `, { params }).toPromise();
}
return rows.then(function (rows) {
return create_result(rows, resolve, enrich);
});
};
ClickhouseDB.prototype.info = function () {
// todo
};
ClickhouseDB.prototype.transaction = function (task) {
// not supported
return task.call(this);
};
ClickhouseDB.prototype.commit = async function (flexsearch, _replace, _append) {
// process cleanup tasks
if (_replace) {
await this.clear();
// there are just removals in the task queue
flexsearch.commit_task = [];
} else {
let tasks = flexsearch.commit_task;
flexsearch.commit_task = [];
for (let i = 0, task; i < tasks.length; i++) {
task = tasks[i];
// there are just removals in the task queue
if (task.clear) {
await this.clear();
_replace = !0;
break;
} else {
tasks[i] = task.del;
}
}
if (!_replace) {
if (!_append) {
tasks = tasks.concat(toArray(flexsearch.reg));
}
tasks.length && (await this.remove(tasks));
}
}
if (!flexsearch.reg.size) {
return;
}
if (flexsearch.map.size) {
let data = [];
for (const item of flexsearch.map) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
//this.type || (this.type = typeof ids[0]);
for (let j = 0; j < ids.length; j++) {
data.push({
key: key,
res: i,
id: /*this.type === "number"
? parseInt(ids[j], 10)
:*/ids[j]
});
}
}
}
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.map${this.field} (key, res, id)`, data).toPromise();
}
}
if (flexsearch.ctx.size) {
let data = [];
for (const ctx of flexsearch.ctx) {
const ctx_key = ctx[0],
ctx_value = ctx[1];
for (const item of ctx_value) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
for (let j = 0; j < ids.length; j++) {
data.push({
ctx: ctx_key,
key: key,
res: i,
id: /*this.type === "number"
? parseInt(ids[j], 10)
:*/ids[j]
});
}
}
}
}
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.ctx${this.field} (ctx, key, res, id)`, data).toPromise();
}
}
if (flexsearch.tag) {
let data = [];
for (const item of flexsearch.tag) {
const tag = item[0],
ids = item[1];
if (!ids.length) continue;
for (let j = 0; j < ids.length; j++) {
data.push({ tag, id: ids[j] });
}
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.tag${this.field} (tag, id)`, data).toPromise();
}
}
if (flexsearch.store) {
let data = [];
for (const item of flexsearch.store.entries()) {
const id = item[0],
doc = item[1];
data.push({ id, doc: doc && JSON.stringify(doc) });
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.reg (id, doc)`, data).toPromise();
}
} else if (!flexsearch.bypass) {
let data = toArray(flexsearch.reg);
for (let i = 0; i < data.length; i++) {
data[i] = { id: data[i] };
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.reg (id)`, data).toPromise();
}
}
// TODO
// await this.db.insert(`INSERT INTO ${this.id}.cfg${this.field} (cfg)`, [{
// cfg: JSON.stringify({
// "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "",
// "charset": typeof flexsearch.charset === "string" ? flexsearch.charset : "",
// "tokenize": flexsearch.tokenize,
// "resolution": flexsearch.resolution,
// "minlength": flexsearch.minlength,
// "optimize": flexsearch.optimize,
// "fastupdate": flexsearch.fastupdate,
// "encoder": flexsearch.encoder,
// "context": {
// "depth": flexsearch.depth,
// "bidirectional": flexsearch.bidirectional,
// "resolution": flexsearch.resolution_ctx
// }
// })
// }]).toPromise();
flexsearch.map.clear();
flexsearch.ctx.clear();
flexsearch.tag && flexsearch.tag.clear();
flexsearch.store && flexsearch.store.clear();
flexsearch.document || flexsearch.reg.clear();
await Promise.all([this.db.query(`OPTIMIZE TABLE ${this.id}.map${this.field} FINAL`).toPromise(), this.db.query(`OPTIMIZE TABLE ${this.id}.ctx${this.field} FINAL`).toPromise(), this.db.query(`OPTIMIZE TABLE ${this.id}.tag${this.field} FINAL`).toPromise(), this.db.query(`OPTIMIZE TABLE ${this.id}.reg FINAL`).toPromise()]);
};
ClickhouseDB.prototype.remove = async function (ids) {
if ("object" != typeof ids) {
ids = [ids];
}
while (ids.length) {
let chunk = ids.slice(0, 1e5);
ids = ids.slice(1e5);
chunk = "String" === this.type ? "'" + chunk.join("','") + "'" : chunk.join(",");
await Promise.all([this.db.query(`
ALTER TABLE ${this.id}.map${this.field}
DELETE WHERE id IN (${chunk})
SETTINGS mutations_sync = 1;`).toPromise(), this.db.query(`
ALTER TABLE ${this.id}.ctx${this.field}
DELETE WHERE id IN (${chunk})
SETTINGS mutations_sync = 1;`).toPromise(), this.db.query(`
ALTER TABLE ${this.id}.tag${this.field}
DELETE WHERE id IN (${chunk})
SETTINGS mutations_sync = 1;`).toPromise(), this.db.query(`
ALTER TABLE ${this.id}.reg
DELETE WHERE id IN (${chunk})
SETTINGS mutations_sync = 1;`).toPromise()]);
}
};

589
dist/module-debug/db/indexeddb/index.js vendored Normal file
View File

@@ -0,0 +1,589 @@
import Document from "../../document.js";
const VERSION = 1,
IndexedDB = "undefined" != typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB),
IDBTransaction = "undefined" != typeof window && (window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction),
IDBKeyRange = "undefined" != typeof window && (window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange),
fields = ["map", "ctx", "tag", "reg", "cfg"];
import StorageInterface from "../interface.js";
import { toArray } from "../../common.js";
function sanitize(str) {
return str.toLowerCase().replace(/[^a-z0-9_\-]/g, "");
}
/**
* @constructor
* @implements StorageInterface
*/
export default function IdxDB(name, config = {}) {
if (!(this instanceof IdxDB)) {
return new IdxDB(name, config);
}
if ("object" == typeof name) {
name = name.name;
config = name;
}
if (!name) {
console.info("Default storage space was used, because a name was not passed.");
}
this.id = "flexsearch" + (name ? ":" + sanitize(name) : "");
this.field = config.field ? sanitize(config.field) : "";
this.support_tag_search = !1;
this.db = null;
this.trx = {};
}
IdxDB.prototype.mount = function (flexsearch) {
if (flexsearch instanceof Document) {
return flexsearch.mount(this);
}
flexsearch.db = this;
return this.open();
};
IdxDB.prototype.open = function () {
let self = this;
navigator.storage && navigator.storage.persist();
return this.db || new Promise(function (resolve, reject) {
const req = IndexedDB.open(self.id + (self.field ? ":" + self.field : ""), VERSION);
req.onupgradeneeded = function () {
const db = self.db = this.result;
// Using Indexes + IDBKeyRange on schema map => [key, res, id] performs
// too bad and blows up amazingly in size
// The schema map:key => [res][id] is currently used instead
// In fact that bypass the idea of a storage solution,
// IndexedDB is such a poor contribution :(
fields.forEach(ref => {
db.objectStoreNames.contains(ref) || db.createObjectStore(ref); //{ autoIncrement: true /*keyPath: "id"*/ }
//.createIndex("idx", "ids", { multiEntry: true, unique: false });
});
// switch(event.oldVersion){ // existing db version
// case 0:
// // version 0 means that the client had no database
// // perform initialization
// case 1:
// // client had version 1
// // update
// }
};
req.onblocked = function (event) {
// this event shouldn't trigger if we handle onversionchange correctly
// it means that there's another open connection to the same database
// and it wasn't closed after db.onversionchange triggered for it
console.error("blocked", event);
reject();
};
req.onerror = function (event) {
console.error(this.error, event);
reject();
};
req.onsuccess = function () {
self.db = this.result; //event.target.result;
self.db.onversionchange = function () {
//database is outdated
self.close();
};
resolve(self);
};
});
};
IdxDB.prototype.close = function () {
this.db.close();
this.db = null;
};
IdxDB.prototype.destroy = function () {
this.db && this.close();
return IndexedDB.deleteDatabase(this.id + (this.field ? ":" + this.field : ""));
};
// IdxDB.prototype.set = function(ref, key, ctx, data){
// const transaction = this.db.transaction(ref, "readwrite");
// const map = transaction.objectStore(ref);
// const req = map.put(data, ctx ? ctx + ":" + key : key);
// return transaction;//promisfy(req, callback);
// };
// IdxDB.prototype.delete = function(ref, key, ctx){
// const transaction = this.db.transaction(ref, "readwrite");
// const map = transaction.objectStore(ref);
// const req = map.delete(ctx ? ctx + ":" + key : key);
// return transaction;//promisfy(req, callback);
// };
IdxDB.prototype.clear = function () {
const transaction = this.db.transaction(fields, "readwrite");
for (let i = 0; i < fields.length; i++) {
transaction.objectStore(fields[i]).clear();
}
return promisfy(transaction);
};
IdxDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = /* tag? */!0, enrich = !1) {
const transaction = this.db.transaction(ctx ? "ctx" : "map", "readonly"),
map = transaction.objectStore(ctx ? "ctx" : "map"),
req = map.get(ctx ? ctx + ":" + key : key),
self = this;
return promisfy(req).then(function (res) {
let result = [];
if (!res || !res.length) return result;
if (resolve) {
if (!limit && !offset && 1 === res.length) {
return res[0];
}
for (let i = 0, arr; i < res.length; i++) {
if ((arr = res[i]) && arr.length) {
if (offset >= arr.length) {
offset -= arr.length;
continue;
}
const end = limit ? offset + Math.min(arr.length - offset, limit) : arr.length;
for (let j = offset; j < end; j++) {
result.push(arr[j]);
}
offset = 0;
if (result.length === limit) {
break;
}
}
}
return enrich ? self.enrich(result) : result;
} else {
return res;
}
});
};
IdxDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) {
const transaction = this.db.transaction("tag", "readonly"),
map = transaction.objectStore("tag"),
req = map.get(tag),
self = this;
return promisfy(req).then(function (ids) {
if (!ids || !ids.length || offset >= ids.length) return [];
if (!limit && !offset) return ids;
const result = ids.slice(offset, offset + limit);
return enrich ? self.enrich(result) : result;
});
};
IdxDB.prototype.enrich = function (ids) {
if ("object" != typeof ids) {
ids = [ids];
}
const transaction = this.db.transaction("reg", "readonly"),
map = transaction.objectStore("reg"),
promises = [];
for (let i = 0; i < ids.length; i++) {
promises[i] = promisfy(map.get(ids[i]));
}
return Promise.all(promises).then(function (docs) {
for (let i = 0; i < docs.length; i++) {
docs[i] = {
id: ids[i],
doc: docs[i] ? JSON.parse(docs[i]) : null
};
}
return docs;
});
};
IdxDB.prototype.has = function (id) {
const transaction = this.db.transaction("reg", "readonly"),
map = transaction.objectStore("reg"),
req = map.getKey(id);
return promisfy(req);
};
IdxDB.prototype.search = null;
// IdxDB.prototype.has = function(ref, key, ctx){
// const transaction = this.db.transaction(ref, "readonly");
// const map = transaction.objectStore(ref);
// const req = map.getKey(ctx ? ctx + ":" + key : key);
// return promisfy(req);
// };
IdxDB.prototype.info = function () {
// todo
};
/**
* @param {!string} ref
* @param {!string} modifier
* @param {!Function} task
*/
IdxDB.prototype.transaction = function (ref, modifier, task) {
let store = this.trx[ref + ":" + modifier];
if (store) return task.call(this, store);
let transaction = this.db.transaction(ref, modifier);
this.trx[ref + ":" + modifier] = store = transaction.objectStore(ref);
return new Promise((resolve, reject) => {
transaction.onerror = err => {
this.trx[ref + ":" + modifier] = null;
transaction.abort();
transaction = store = null;
reject(err);
//db.close;
};
transaction.oncomplete = res => {
this.trx[ref + ":" + modifier] = null;
transaction = store = null;
resolve(res || !0);
//db.close;
};
return task.call(this, store);
});
};
IdxDB.prototype.commit = async function (flexsearch, _replace, _append) {
// process cleanup tasks
if (_replace) {
await this.clear();
// there are just removals in the task queue
flexsearch.commit_task = [];
} else {
let tasks = flexsearch.commit_task;
flexsearch.commit_task = [];
for (let i = 0, task; i < tasks.length; i++) {
task = tasks[i];
// there are just removals in the task queue
if (task.clear) {
await this.clear();
_replace = !0;
break;
} else {
tasks[i] = task.del;
}
}
if (!_replace) {
if (!_append) {
tasks = tasks.concat(toArray(flexsearch.reg));
}
tasks.length && (await this.remove(tasks));
}
}
if (!flexsearch.reg.size) {
return;
}
await this.transaction("map", "readwrite", function (store) {
for (const item of flexsearch.map) {
const key = item[0],
value = item[1];
if (!value.length) continue;
if (_replace) {
store.put(value, key);
continue;
}
store.get(key).onsuccess = function () {
let result = this.result,
changed;
if (result && result.length) {
const maxlen = Math.max(result.length, value.length);
for (let i = 0, res, val; i < maxlen; i++) {
val = value[i];
if (val && val.length) {
res = result[i];
if (res && res.length) {
for (let j = 0; j < val.length; j++) {
res.push(val[j]);
}
changed = 1;
//result[i] = res.concat(val);
//result[i] = new Set([...result[i], ...value[i]]);
//result[i] = result[i].union(new Set(value[i]));
} else {
result[i] = val;
changed = 1;
//result[i] = new Set(value[i])
}
}
}
} else {
result = value;
changed = 1;
//result = [];
//for(let i = 0; i < value.length; i++){
// if(value[i]) result[i] = new Set(value[i]);
//}
}
changed && store.put(result, key);
};
}
});
await this.transaction("ctx", "readwrite", function (store) {
for (const ctx of flexsearch.ctx) {
const ctx_key = ctx[0],
ctx_value = ctx[1];
for (const item of ctx_value) {
const key = item[0],
value = item[1];
if (!value.length) continue;
if (_replace) {
store.put(value, ctx_key + ":" + key);
continue;
}
store.get(ctx_key + ":" + key).onsuccess = function () {
let result = this.result,
changed;
if (result && result.length) {
const maxlen = Math.max(result.length, value.length);
for (let i = 0, res, val; i < maxlen; i++) {
val = value[i];
if (val && val.length) {
res = result[i];
if (res && res.length) {
for (let j = 0; j < val.length; j++) {
res.push(val[j]);
}
//result[i] = res.concat(val);
changed = 1;
} else {
result[i] = val;
changed = 1;
}
}
}
} else {
result = value;
changed = 1;
}
changed && store.put(result, ctx_key + ":" + key);
};
}
}
});
if (flexsearch.store) {
await this.transaction("reg", "readwrite", function (store) {
for (const item of flexsearch.store) {
const id = item[0],
doc = item[1];
store.put("object" == typeof doc ? JSON.stringify(doc) : 1, id);
}
});
} else if (!flexsearch.bypass) {
await this.transaction("reg", "readwrite", function (store) {
for (const id of flexsearch.reg.keys()) {
store.put(1, id);
}
});
}
if (flexsearch.tag) {
await this.transaction("tag", "readwrite", function (store) {
for (const item of flexsearch.tag) {
const tag = item[0],
ids = item[1];
if (!ids.length) continue;
store.get(tag).onsuccess = function () {
let result = this.result;
result = result && result.length ? result.concat(ids) : ids;
store.put(result, tag);
};
}
});
}
// TODO
// await this.transaction("cfg", "readwrite", function(store){
// store.put({
// "charset": flexsearch.charset,
// "tokenize": flexsearch.tokenize,
// "resolution": flexsearch.resolution,
// "fastupdate": flexsearch.fastupdate,
// "compress": flexsearch.compress,
// "encoder": {
// "minlength": flexsearch.encoder.minlength
// },
// "context": {
// "depth": flexsearch.depth,
// "bidirectional": flexsearch.bidirectional,
// "resolution": flexsearch.resolution_ctx
// }
// }, "current");
// });
flexsearch.map.clear();
flexsearch.ctx.clear();
flexsearch.tag && flexsearch.tag.clear();
flexsearch.store && flexsearch.store.clear();
flexsearch.document || flexsearch.reg.clear();
};
/**
* @param {IDBCursorWithValue} cursor
* @param {Array} ids
* @param {boolean=} _tag
*/
function handle(cursor, ids, _tag) {
const arr = cursor.value;
let changed,
parse,
count = 0;
for (let x = 0, result; x < arr.length; x++) {
// tags has no resolution layer
if (result = _tag ? arr : arr[x]) {
for (let i = 0, pos, id; i < ids.length; i++) {
id = ids[i];
pos = result.indexOf(parse ? parseInt(id, 10) : id);
if (0 > pos && !parse && "string" == typeof id && !isNaN(id)) {
pos = result.indexOf(parseInt(id, 10));
pos && (parse = 1);
}
if (0 <= pos) {
changed = 1;
if (1 < result.length) {
result.splice(pos, 1);
} else {
arr[x] = [];
break;
}
}
}
count += result.length;
}
if (_tag) break;
}
if (!count) {
cursor.delete();
//store.delete(cursor.key);
} else if (changed) {
//await new Promise(resolve => {
cursor.update(arr); //.onsuccess = resolve;
//});
}
cursor.continue();
}
IdxDB.prototype.remove = function (ids) {
if ("object" != typeof ids) {
ids = [ids];
}
return (/** @type {!Promise<undefined>} */Promise.all([this.transaction("map", "readwrite", function (store) {
store.openCursor().onsuccess = function () {
const cursor = this.result;
cursor && handle(cursor, ids);
};
}), this.transaction("ctx", "readwrite", function (store) {
store.openCursor().onsuccess = function () {
const cursor = this.result;
cursor && handle(cursor, ids);
};
}), this.transaction("tag", "readwrite", function (store) {
store.openCursor().onsuccess = function () {
const cursor = this.result;
cursor && handle(cursor, ids, !0);
};
}),
// let filtered = [];
this.transaction("reg", "readwrite", function (store) {
for (let i = 0; i < ids.length; i++) {
store.delete(ids[i]);
}
// return new Promise(resolve => {
// store.openCursor().onsuccess = function(){
// const cursor = this.result;
// if(cursor){
// const id = cursor.value;
// if(ids.includes(id)){
// filtered.push(id);
// cursor.delete();
// }
// cursor.continue();
// }
// else{
// resolve();
// }
// };
// });
})
// ids = filtered;
])
);
};
/**
* @param {IDBRequest} req
* @param {Function=} callback
* @return {!Promise<undefined>}
*/
function promisfy(req, callback) {
return new Promise((resolve, reject) => {
/** @this IDBRequest */
req.onsuccess = function () {
callback && callback(this.result);
resolve(this.result);
};
/** @this IDBRequest */
req.oncomplete = function () {
callback && callback(this.result);
resolve(this.result);
};
req.onerror = reject;
req = null;
});
}

584
dist/module-debug/db/mongo/index.js vendored Normal file
View File

@@ -0,0 +1,584 @@
import { MongoClient } from "mongodb";
const defaults = {
host: "localhost",
port: "27017",
user: null,
pass: null
},
VERSION = 1,
fields = ["map", "ctx", "tag", "reg", "cfg"];
import StorageInterface from "../interface.js";
import Document from "../../document.js";
import { toArray } from "../../common.js";
function sanitize(str) {
return str.toLowerCase().replace(/[^a-z0-9_\-]/g, "");
}
let CLIENT,
DB = Object.create(null);
/**
* @constructor
* @implements StorageInterface
*/
export default function MongoDB(name, config = {}) {
if (!(this instanceof MongoDB)) {
return new MongoDB(name, config);
}
if ("object" == typeof name) {
name = name.name;
config = name;
}
if (!name) {
console.info("Default storage space was used, because a name was not passed.");
}
this.id = "flexsearch" + (name ? "-" + sanitize(name) : "");
this.field = config.field ? "-" + sanitize(config.field) : "";
this.type = config.type || "";
this.db = config.db || DB[this.id] || CLIENT || null;
this.trx = !1;
this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/;
Object.assign(defaults, config);
this.db && delete defaults.db;
}
// MongoDB.mount = function(flexsearch){
// return new this().mount(flexsearch);
// };
MongoDB.prototype.mount = function (flexsearch) {
if (flexsearch instanceof Document) {
return flexsearch.mount(this);
}
flexsearch.db = this;
return this.open();
};
async function createCollection(db, ref, field) {
switch (ref) {
case "map":
await db.createCollection("map" + field);
await db.collection("map" + field).createIndex({ key: 1 });
await db.collection("map" + field).createIndex({ id: 1 });
break;
case "ctx":
await db.createCollection("ctx" + field);
await db.collection("ctx" + field).createIndex({ ctx: 1, key: 1 });
await db.collection("ctx" + field).createIndex({ id: 1 });
break;
case "tag":
await db.createCollection("tag" + field);
await db.collection("tag" + field).createIndex({ tag: 1 });
await db.collection("tag" + field).createIndex({ id: 1 });
break;
case "reg":
await db.createCollection("reg");
await db.collection("reg").createIndex({ id: 1 });
break;
case "cfg":
await db.createCollection("cfg" + field);
}
}
MongoDB.prototype.open = async function () {
if (!this.db) {
if (!(this.db = DB[this.id])) {
if (!(this.db = CLIENT)) {
let url = defaults.url;
if (!url) {
url = defaults.user ? `mongodb://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}` : `mongodb://${defaults.host}:${defaults.port}`;
}
this.db = CLIENT = new MongoClient(url);
await this.db.connect();
}
}
}
if (this.db.db) {
this.db = DB[this.id] = this.db.db(this.id);
}
const collections = await this.db.listCollections().toArray();
for (let i = 0, found; i < fields.length; i++) {
found = !1;
for (let j = 0; j < collections.length; j++) {
if (collections[j].name === fields[i] + ("reg" !== fields[i] ? this.field : "")) {
found = !0;
break;
}
}
if (!found) {
await createCollection(this.db, fields[i], this.field);
}
}
return this.db;
};
MongoDB.prototype.close = function () {
this.db.close();
this.db = null;
return this;
};
MongoDB.prototype.destroy = async function () {
await Promise.all([this.db.dropCollection("map" + this.field), this.db.dropCollection("ctx" + this.field), this.db.dropCollection("tag" + this.field), this.db.dropCollection("cfg" + this.field), this.db.dropCollection("reg")]);
this.close();
};
async function clear(ref) {
await this.db.dropCollection(ref);
await createCollection(this.db, ref, this.field);
}
MongoDB.prototype.clear = function () {
return Promise.all([clear.call(this, "map" + this.field), clear.call(this, "ctx" + this.field), clear.call(this, "tag" + this.field), clear.call(this, "cfg" + this.field), clear.call(this, "reg")]);
};
function create_result(rows, resolve, enrich) {
if (resolve) {
if (!enrich) for (let i = 0; i < rows.length; i++) {
rows[i] = rows[i].id;
}
return rows;
} else {
const arr = [];
for (let i = 0, row; i < rows.length; i++) {
row = rows[i];
arr[row.res] || (arr[row.res] = []);
arr[row.res].push(enrich ? row : row.id);
}
return arr;
}
}
MongoDB.prototype.get = async function (key, ctx, limit = 0, offset = 0, resolve = !0, enrich = !1, tags) {
let rows,
params = ctx ? { ctx, key } : { key };
if (!enrich && !tags) {
rows = await this.db.collection((ctx ? "ctx" : "map") + this.field).find(params, { projection: { _id: 0, res: 1, id: 1 }, limit, skip: offset }).toArray();
} else {
const project = { _id: 0, id: 1 },
stmt = [{ $match: params }];
if (!resolve) {
project.res = 1;
}
if (enrich) {
project.doc = "$doc.doc";
stmt.push({ $lookup: {
from: "reg",
localField: "id",
foreignField: "id",
as: "doc"
} }, { $unwind: {
path: "$doc",
preserveNullAndEmptyArrays: !0
} });
}
if (tags) {
const match = {};
for (let i = 0, count = 1; i < tags.length; i += 2) {
project["tag" + count] = "$tag" + count + ".tag";
match["tag" + count] = tags[i + 1];
stmt.push({ $lookup: {
from: "tag-" + sanitize(tags[i]),
localField: "id",
foreignField: "id",
as: "tag" + count
} });
count++;
}
stmt.push({ $project: project }, { $match: match }, { $project: { id: 1, doc: 1 } });
} else {
stmt.push({ $project: project });
}
stmt.push({ $sort: { res: 1 } }, { $skip: offset }, { $limit: limit });
rows = [];
const result = await this.db.collection((ctx ? "ctx" : "map") + this.field).aggregate(stmt);
while (!0) {
const row = await result.next();
if (row) rows.push(row);else break;
}
}
return create_result(rows, resolve, enrich);
};
MongoDB.prototype.tag = async function (tag, limit = 0, offset = 0, enrich = !1) {
if (!enrich) {
const rows = await this.db.collection("tag" + this.field).find({ tag }, { projection: { _id: 0, id: 1 }, limit, skip: offset }).toArray();
return create_result(rows, !0, !1);
} else {
let rows = [];
const result = await this.db.collection("tag" + this.field).aggregate([{ $match: { tag } }, { $skip: offset }, { $limit: limit }, { $lookup: {
from: "reg",
localField: "id",
foreignField: "id",
as: "doc"
} }, { $project: { _id: 0, id: 1, doc: "$doc.doc" } }, { $unwind: {
path: "$doc",
preserveNullAndEmptyArrays: !0
} }]);
while (!0) {
const row = await result.next();
if (row) rows.push(row);else break;
}
return rows;
}
};
MongoDB.prototype.enrich = function (ids) {
if ("object" != typeof ids) {
ids = [ids];
}
return this.db.collection("reg").find({ id: { $in: ids } }, { projection: { _id: 0, id: 1, doc: 1 } }).toArray();
};
MongoDB.prototype.has = function (id) {
return this.db.collection("reg").countDocuments({ id }, { limit: 1 });
};
MongoDB.prototype.search = async function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) {
let result = [],
rows;
if (1 < query.length && flexsearch.depth) {
let params = [],
keyword = query[0],
term;
for (let i = 1; i < query.length; i++) {
term = query[i];
const swap = flexsearch.bidirectional && term > keyword;
params.push({
ctx: swap ? term : keyword,
key: swap ? keyword : term
});
keyword = term;
}
let project = resolve ? { _id: 1 } : { _id: 1, res: 1 };
const stmt = [{ $match: { $or: params } }, { $group: {
_id: "$id",
res: suggest ? { $sum: 1 } : { $min: 1 },
count: { $sum: 1 }
} }];
suggest || stmt.push({ $match: { count: query.length - 1 } });
if (enrich) {
project.doc = "$doc.doc";
stmt.push({ $lookup: {
from: "reg",
localField: "_id",
foreignField: "id",
as: "doc"
} }, { $unwind: {
path: "$doc",
preserveNullAndEmptyArrays: !0
} });
}
if (tags) {
const match = {};
for (let i = 0, count = 1; i < tags.length; i += 2) {
project["tag" + count] = "$tag" + count + ".tag";
match["tag" + count] = tags[i + 1];
stmt.push({ $lookup: {
from: "tag-" + sanitize(tags[i]),
localField: "_id",
foreignField: "id",
as: "tag" + count
} });
count++;
}
stmt.push({ $project: project }, { $match: match });
} else {
stmt.push({ $project: project });
}
stmt.push({ $sort: suggest ? { count: -1, res: 1 } : { res: 1 } }, { $skip: offset }, { $limit: limit });
if (tags) {
project = { _id: 1 };
if (!resolve) project.res = 1;
if (enrich) project.doc = 1;
stmt.push({ $project: project });
}
rows = await this.db.collection("ctx" + this.field).aggregate(stmt);
} else {
let project = resolve ? { _id: 1 } : { _id: 1, res: 1 };
const stmt = [{ $match: {
key: { $in: query }
} }, { $group: {
_id: "$id",
res: suggest ? { $sum: 1 } : { $min: 1 },
count: { $sum: 1 }
} }];
suggest || stmt.push({ $match: { count: query.length } });
if (enrich) {
project.doc = "$doc.doc";
stmt.push({ $lookup: {
from: "reg",
localField: "_id",
foreignField: "id",
as: "doc"
} }, { $unwind: {
path: "$doc",
preserveNullAndEmptyArrays: !0
} });
}
if (tags) {
const match = {};
for (let i = 0, count = 1; i < tags.length; i += 2) {
project["tag" + count] = "$tag" + count + ".tag";
match["tag" + count] = tags[i + 1];
stmt.push({ $lookup: {
from: "tag-" + sanitize(tags[i]),
localField: "_id",
foreignField: "id",
as: "tag" + count
} });
count++;
}
stmt.push({ $project: project }, { $match: match });
} else {
stmt.push({ $project: project });
}
stmt.push({ $sort: suggest ? { count: -1, res: 1 } : { res: 1 } }, { $skip: offset }, { $limit: limit });
if (tags) {
project = { _id: 1 };
if (!resolve) project.res = 1;
if (enrich) project.doc = 1;
stmt.push({ $project: project });
}
rows = await this.db.collection("map" + this.field).aggregate(stmt);
}
while (!0) {
const row = await rows.next();
if (row) {
if (resolve && !enrich) {
result.push(row._id);
} else {
row.id = row._id;
delete row._id;
result.push(row);
}
} else break;
}
if (resolve && !enrich) {
return result;
} else {
return create_result(result, resolve, enrich);
}
};
MongoDB.prototype.info = function () {
// todo
};
MongoDB.prototype.transaction = function (task) {
// not supported
return task.call(this);
};
MongoDB.prototype.commit = async function (flexsearch, _replace, _append) {
// process cleanup tasks
if (_replace) {
await this.clear();
// there are just removals in the task queue
flexsearch.commit_task = [];
} else {
let tasks = flexsearch.commit_task;
flexsearch.commit_task = [];
for (let i = 0, task; i < tasks.length; i++) {
task = tasks[i];
// there are just removals in the task queue
if (task.clear) {
await this.clear();
_replace = !0;
break;
} else {
tasks[i] = task.del;
}
}
if (!_replace) {
if (!_append) {
tasks = tasks.concat(toArray(flexsearch.reg));
}
tasks.length && (await this.remove(tasks));
}
}
if (!flexsearch.reg.size) {
return;
}
if (flexsearch.map.size) {
let data = [];
for (const item of flexsearch.map) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
this.type || (this.type = typeof ids[0]);
for (let j = 0; j < ids.length; j++) {
data.push({
key: key,
res: i,
id: ids[j]
});
}
}
}
}
if (data.length) {
await this.db.collection("map" + this.field).insertMany(data);
flexsearch.map.clear();
}
}
if (flexsearch.ctx.size) {
let data = [];
for (const ctx of flexsearch.ctx) {
const ctx_key = ctx[0],
ctx_value = ctx[1];
for (const item of ctx_value) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
for (let j = 0; j < ids.length; j++) {
data.push({
ctx: ctx_key,
key: key,
res: i,
id: ids[j]
});
}
}
}
}
}
if (data.length) {
await this.db.collection("ctx" + this.field).insertMany(data);
flexsearch.ctx.clear();
}
}
if (flexsearch.tag) {
let data = [];
if (flexsearch.tag) {
for (const item of flexsearch.tag) {
const tag = item[0],
ids = item[1];
if (!ids.length) continue;
for (let j = 0; j < ids.length; j++) {
data.push({ tag, id: ids[j] });
}
}
}
if (data.length) {
await this.db.collection("tag" + this.field).insertMany(data);
flexsearch.tag.clear();
}
}
let data = [];
if (flexsearch.store) {
for (const item of flexsearch.store.entries()) {
const id = item[0],
doc = item[1];
data.push({ id, doc });
}
} else if (!flexsearch.bypass) {
for (const id of flexsearch.reg.keys()) {
data.push({ id });
}
}
if (data.length) {
await this.db.collection("reg").insertMany(data);
flexsearch.store && flexsearch.store.clear();
flexsearch.document || flexsearch.reg.clear();
}
// TODO
// await this.db.collection("cfg" + this.field).insertOne({
// "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "",
// "charset": typeof flexsearch.charset === "string" ? flexsearch.charset : "",
// "tokenize": flexsearch.tokenize,
// "resolution": flexsearch.resolution,
// "minlength": flexsearch.minlength,
// "optimize": flexsearch.optimize,
// "fastupdate": flexsearch.fastupdate,
// "encoder": flexsearch.encoder,
// "context": {
// "depth": flexsearch.depth,
// "bidirectional": flexsearch.bidirectional,
// "resolution": flexsearch.resolution_ctx
// }
// });
};
MongoDB.prototype.remove = function (ids) {
if (!ids && 0 !== ids) return;
if ("object" != typeof ids) {
ids = [ids];
}
// if(this.type !== "string" && typeof ids[0] !== "number"){
// ids = ids.map(item => parseInt(item, 10));
// }
return Promise.all([this.db.collection("map" + this.field).deleteMany({ id: { $in: ids } }), this.db.collection("ctx" + this.field).deleteMany({ id: { $in: ids } }), this.db.collection("tag" + this.field).deleteMany({ id: { $in: ids } }), this.db.collection("reg").deleteMany({ id: { $in: ids } })]);
};

971
dist/module-debug/db/postgres/index.js vendored Normal file
View File

@@ -0,0 +1,971 @@
import pg_promise from "pg-promise";
import StorageInterface from "../interface.js";
import Document from "../../document.js";
import { concat, toArray } from "../../common.js";
const defaults = {
schema: "flexsearch",
user: "postgres",
pass: "postgres",
name: "postgres",
host: "localhost",
port: "5432"
},
pgp = pg_promise(),
VERSION = 1,
MAXIMUM_QUERY_VARS = 16000,
fields = ["map", "ctx", "reg", "tag", "cfg"],
types = {
text: "text",
char: "text",
varchar: "text",
string: "text",
number: "int",
numeric: "int",
integer: "int",
smallint: "int",
tinyint: "int",
mediumint: "int",
int: "int",
int8: "int",
uint8: "int",
int16: "int",
uint16: "int",
int32: "int",
uint32: "bigint",
int64: "bigint",
bigint: "bigint"
};
function sanitize(str) {
return str.toLowerCase().replace(/[^a-z0-9_]/g, "");
}
let DB, TRX;
/**
* @constructor
* @implements StorageInterface
*/
export default function PostgresDB(name, config = {}) {
if (!(this instanceof PostgresDB)) {
return new PostgresDB(name, config);
}
if ("object" == typeof name) {
name = name.name;
config = name;
}
if (!name) {
console.info("Default storage space was used, because a name was not passed.");
}
this.id = (config.schema ? sanitize(config.schema) : defaults.schema) + (name ? "_" + sanitize(name) : "");
this.field = config.field ? "_" + sanitize(config.field) : "";
this.type = config.type ? types[config.type.toLowerCase()] : "text";
this.support_tag_search = /* tag? */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/;
if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'");
this.db = DB || (DB = config.db || null);
Object.assign(defaults, config);
this.db && delete defaults.db;
}
PostgresDB.prototype.mount = function (flexsearch) {
if (flexsearch instanceof Document) {
return flexsearch.mount(this);
}
flexsearch.db = this;
return this.open();
};
PostgresDB.prototype.open = async function () {
if (!this.db) {
this.db = DB || (DB = pgp(`postgres://${defaults.user}:${encodeURIComponent(defaults.pass)}@${defaults.host}:${defaults.port}/${defaults.name}`));
}
const exist = await this.db.oneOrNone(`
SELECT EXISTS (
SELECT 1
FROM information_schema.schemata
WHERE schema_name = '${this.id}'
);
`);
if (!exist || !exist.exists) {
await this.db.none(`CREATE SCHEMA IF NOT EXISTS ${this.id};`);
}
for (let i = 0; i < fields.length; i++) {
const exist = await this.db.oneOrNone(`
SELECT EXISTS (
SELECT 1 FROM pg_tables
WHERE schemaname = '${this.id}' AND tablename = '${fields[i] + ("reg" !== fields[i] ? this.field : "")}'
);
`);
if (exist && exist.exists) continue;
const type = "text" === this.type ? "varchar(128)" : this.type;
switch (fields[i]) {
case "map":
await this.db.none(`
CREATE TABLE IF NOT EXISTS ${this.id}.map${this.field}(
key varchar(128) NOT NULL,
res smallint NOT NULL,
id ${type} NOT NULL
);
CREATE INDEX IF NOT EXISTS ${this.id}_map_index${this.field}
ON ${this.id}.map${this.field} (key);
CREATE INDEX IF NOT EXISTS ${this.id}_map_id${this.field}
ON ${this.id}.map${this.field} (id);
`);
break;
case "ctx":
await this.db.none(`
CREATE TABLE IF NOT EXISTS ${this.id}.ctx${this.field}(
ctx varchar(128) NOT NULL,
key varchar(128) NOT NULL,
res smallint NOT NULL,
id ${type} NOT NULL
);
CREATE INDEX IF NOT EXISTS ${this.id}_ctx_index${this.field}
ON ${this.id}.ctx${this.field} (ctx, key);
CREATE INDEX IF NOT EXISTS ${this.id}_ctx_id${this.field}
ON ${this.id}.ctx${this.field} (id);
`);
break;
case "tag":
await this.db.none(`
CREATE TABLE IF NOT EXISTS ${this.id}.tag${this.field}(
tag varchar(128) NOT NULL,
id ${type} NOT NULL
);
CREATE INDEX IF NOT EXISTS ${this.id}_tag_index${this.field}
ON ${this.id}.tag${this.field} (tag);
CREATE INDEX IF NOT EXISTS ${this.id}_tag_id${this.field}
ON ${this.id}.tag${this.field} (id);
`);
break;
case "reg":
await this.db.none(`
CREATE TABLE IF NOT EXISTS ${this.id}.reg(
id ${type} NOT NULL
CONSTRAINT ${this.id}_reg_pk
PRIMARY KEY,
doc text DEFAULT NULL
);
`).catch(() => {
// document indexes will try to create same registry table
// and the "IF NOT EXISTS" did not apply on parallel
});
break;
case "cfg":
await this.db.none(`
CREATE TABLE IF NOT EXISTS ${this.id}.cfg${this.field}(
cfg text NOT NULL
);
`);
break;
}
}
return this.db;
};
PostgresDB.prototype.close = function () {
this.db.close && this.db.close();
this.db = DB = null;
return this;
};
PostgresDB.prototype.destroy = async function () {
await this.db.none(`
DROP TABLE IF EXISTS ${this.id}.map${this.field};
DROP TABLE IF EXISTS ${this.id}.ctx${this.field};
DROP TABLE IF EXISTS ${this.id}.tag${this.field};
DROP TABLE IF EXISTS ${this.id}.cfg${this.field};
DROP TABLE IF EXISTS ${this.id}.reg;
`);
this.close();
};
PostgresDB.prototype.clear = function () {
return this.db.none(`
TRUNCATE TABLE ${this.id}.map${this.field};
TRUNCATE TABLE ${this.id}.ctx${this.field};
TRUNCATE TABLE ${this.id}.tag${this.field};
TRUNCATE TABLE ${this.id}.cfg${this.field};
TRUNCATE TABLE ${this.id}.reg;
`);
};
function create_result(rows, resolve, enrich) {
if (resolve) {
for (let i = 0; i < rows.length; i++) {
if (enrich) {
if (rows[i].doc) {
rows[i].doc = JSON.parse(rows[i].doc);
}
} else {
rows[i] = rows[i].id;
}
}
return rows;
} else {
const arr = [];
for (let i = 0, row; i < rows.length; i++) {
row = rows[i];
arr[row.res] || (arr[row.res] = []);
arr[row.res].push(enrich ? row : row.id);
}
return arr;
}
}
PostgresDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = !0, enrich = !1, tags) {
let rows,
stmt = '',
params = ctx ? [ctx, key] : [key],
table = this.id + (ctx ? ".ctx" : ".map") + this.field;
if (tags) {
for (let i = 0, count = params.length + 1; i < tags.length; i += 2) {
stmt += ` AND ${table}.id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = $${count++})`;
params.push(tags[i + 1]);
}
}
if (ctx) {
rows = this.db.any(`
SELECT ${table}.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE ctx = $1 AND key = $2 ${stmt}
ORDER BY res
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, params);
} else {
rows = this.db.any(`
SELECT ${table}.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE key = $1 ${stmt}
ORDER BY res
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, params);
}
return rows.then(function (rows) {
return create_result(rows, resolve, enrich);
});
};
PostgresDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) {
const table = this.id + ".tag" + this.field,
promise = this.db.any(`
SELECT ${table}.id
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE tag = $1
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, [tag]);
enrich || promise.then(function (rows) {
return create_result(rows, !0, !1);
});
return promise;
};
PostgresDB.prototype.enrich = async function (ids) {
let result = [];
if ("object" != typeof ids) {
ids = [ids];
}
for (let count = 0; count < ids.length;) {
const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids;
count += chunk.length;
let stmt = "";
for (let i = 1; i <= chunk.length; i++) {
stmt += (stmt ? "," : "") + "$" + i;
}
const res = await this.db.any(`
SELECT id, doc
FROM ${this.id}.reg
WHERE id IN (${stmt})`, ids);
if (res && res.length) {
for (let i = 0, doc; i < res.length; i++) {
if (doc = res[i].doc) {
res[i].doc = JSON.parse(doc);
}
}
result.push(res);
}
}
return 1 === result.length ? result[0] : 1 < result.length ? concat(result) : result;
};
PostgresDB.prototype.has = function (id) {
return this.db.oneOrNone("SELECT EXISTS(SELECT 1 FROM " + this.id + ".reg WHERE id = $1)", [id]);
};
PostgresDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) {
let rows;
if (1 < query.length && flexsearch.depth) {
let where = "",
params = [],
keyword = query[0],
term,
count = 1;
// variant new
for (let i = 1; i < query.length; i++) {
term = query[i];
const swap = flexsearch.bidirectional && term > keyword;
where += (where ? " OR " : "") + `(ctx = $${count++} AND key = $${count++})`;
params.push(swap ? term : keyword, swap ? keyword : term);
keyword = term;
}
if (tags) {
where = "(" + where + ")";
for (let i = 0; i < tags.length; i += 2) {
where += ` AND id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = $${count++})`;
params.push(tags[i + 1]);
}
}
rows = this.db.any(`
SELECT r.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM (
SELECT id, count(*) as count,
${suggest ? "SUM" : "MIN"}(res) as res
FROM ${this.id}.ctx${this.field}
WHERE ${where}
GROUP BY id
) as r
${enrich ? `
LEFT JOIN ${this.id}.reg ON ${this.id}.reg.id = r.id
` : ""}
${suggest ? "" : "WHERE count = " + (query.length - 1)}
ORDER BY ${suggest ? "count DESC, res" : "res"}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`, params);
// variant 1
// for(let i = 1, count = 1; i < query.length; i++){
// where += (where ? " UNION " : "") + `
// SELECT id, res
// FROM ${this.id}.ctx${this.field}
// WHERE ctx = $${count++} AND key = $${count++}
// `;
// term = query[i];
// const swap = flexsearch.bidirectional && (term > keyword);
// params.push(
// swap ? term : keyword,
// swap ? keyword : term
// );
// keyword = term;
// }
//
// rows = await db.any(`
// SELECT id, res
// FROM (
// SELECT id, ${suggest ? "SUM" : "MIN"}(res) as res, count(*) as count
// FROM (${where}) as t
// GROUP BY id
// ORDER BY ${suggest ? "count DESC, res" : "res"}
// LIMIT ${limit}
// OFFSET ${offset}
// ) as r
// ${suggest ? "" : "WHERE count = " + (query.length - 1)}
// `, params);
} else {
let where = "",
count = 1,
query_length = query.length;
for (let i = 0; i < query_length; i++) {
where += (where ? "," : "") + "$" + count++;
}
where = "key " + (1 < query_length ? "IN (" + where + ")" : "= " + where);
if (tags) {
where = "(" + where + ")";
for (let i = 0; i < tags.length; i += 2) {
where += ` AND id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = $${count++})`;
query.push(tags[i + 1]);
}
}
rows = this.db.any(`
SELECT r.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM (
SELECT id, count(*) as count,
${suggest ? "SUM" : "MIN"}(res) as res
FROM ${this.id}.map${this.field}
WHERE ${where}
GROUP BY id
) as r
${enrich ? `
LEFT JOIN ${this.id}.reg ON ${this.id}.reg.id = r.id
` : ""}
${suggest ? "" : "WHERE count = " + query_length}
ORDER BY ${suggest ? "count DESC, res" : "res"}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`, query);
// variant 1
// for(let i = 1; i <= query.length; i++){
// where += (where ? " UNION " : "") + `
// SELECT id, res
// FROM ${ this.id }.map${ this.field }
// WHERE key = $${i}
// `;
// }
// rows = await db.any(`
// SELECT id, res
// FROM (
// SELECT id, ${suggest ? "SUM" : "MIN"}(res) as res, count(*) as count
// FROM (${where}) as t
// GROUP BY id
// ORDER BY ${suggest ? "count DESC, res" : "res"}
// LIMIT ${limit}
// OFFSET ${offset}
// ) as r
// ${ suggest ? "" : "WHERE count = " + query.length }
// `, query);
// variant 2
// for(let i = 1; i <= query.length; i++){
// where += (where ? " AND EXISTS " : "") + `(SELECT FROM ${this.id}.map${this.field} as d WHERE d.id = t.id AND d.key = $` + i + ")";
// }
// rows = await db.any(`
// SELECT t.id, min(t.res)
// FROM ${this.id}.map${this.field} AS t
// WHERE EXISTS ${where}
// GROUP BY t.id
// LIMIT ${limit || 100}
// OFFSET ${offset || 0}
// `, query);
// variant 3
// for(let i = 1; i <= query.length; i++){
// where += (where ? " INTERSECT " : "") + `SELECT id FROM ${this.id}.map${this.field} WHERE key = $` + i;
// }
// rows = await db.any(`
// WITH filtering (id) AS(${where})
// SELECT t.id, min(t.res)
// FROM ${this.id}.map${this.field} AS t
// JOIN filtering USING (id)
// GROUP BY t.id
// LIMIT ${limit || 100}
// OFFSET ${offset || 0}
// `, query);
// variant 4
// for(let i = 1; i <= query.length; i++){
// where += (where ? " INTERSECT " : "") + `SELECT id FROM ${this.id}.map${this.field} WHERE key = $` + i;
// }
// rows = await db.any(`
// SELECT id, min(res)
// FROM ${this.id}.map${this.field}
// WHERE id IN (${where})
// GROUP BY id
// LIMIT ${limit || 100}
// OFFSET ${offset || 0}
// `, query);
}
return rows.then(function (rows) {
return create_result(rows, resolve, enrich);
});
};
PostgresDB.prototype.info = function () {
// todo
};
// PostgresDB.prototype.transaction = async function(task){
// const self = this;
// if(TRX){
// return TRX.then(function(){
// return self.transaction(task);
// //task.call(self, TRX);
// });
// }
// TRX = await this.db.tx(async function(trx){
// await task.call(self, trx);
// });
// TRX = null;
// };
PostgresDB.prototype.transaction = function (task) {
if (TRX) {
return task.call(this, TRX);
}
const self = this;
return (TRX || this.db).tx(function (trx) {
return task.call(self, TRX = trx);
}).finally(function () {
TRX = null;
});
};
PostgresDB.prototype.commit = async function (flexsearch, _replace, _append) {
// process cleanup tasks
if (_replace) {
await this.clear();
// there are just removals in the task queue
flexsearch.commit_task = [];
} else {
let tasks = flexsearch.commit_task;
flexsearch.commit_task = [];
for (let i = 0, task; i < tasks.length; i++) {
task = tasks[i];
// there are just removals in the task queue
if (task.clear) {
await this.clear();
_replace = !0;
break;
} else {
tasks[i] = task.del;
}
}
if (!_replace) {
if (!_append) {
tasks = tasks.concat(toArray(flexsearch.reg));
}
tasks.length && (await this.remove(tasks));
}
//console.log("tasks:", tasks)
}
if (!flexsearch.reg.size) {
return;
}
await this.transaction(function (trx) {
const batch = [];
// Datastore + Registry
if (flexsearch.store) {
let data = [],
stmt = new pgp.helpers.ColumnSet(["id", "doc"], {
table: this.id + ".reg"
});
for (const item of flexsearch.store.entries()) {
const id = item[0],
doc = item[1];
// const migration = checkMigration.call(this, id);
// migration && await migration;
data.push({ id, doc: doc && JSON.stringify(doc) });
if (data.length === MAXIMUM_QUERY_VARS) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
data = [];
}
}
if (data.length) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
}
// while(data.length){
// let next;
// if(data.length > MAXIMUM_QUERY_VARS){
// next = data.slice(MAXIMUM_QUERY_VARS);
// data = data.slice(0, MAXIMUM_QUERY_VARS);
// }
// let insert = pgp.helpers.insert(data, stmt);
// trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2'));
// if(next) data = next;
// else break;
// }
}
// Registry Only
else if (!flexsearch.bypass) {
let data = [],
stmt = new pgp.helpers.ColumnSet(["id"], {
table: this.id + ".reg"
});
for (const id of flexsearch.reg.keys()) {
// const migration = checkMigration.call(this, id);
// migration && await migration;
data.push({ id });
if (data.length === MAXIMUM_QUERY_VARS) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
data = [];
}
}
if (data.length) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
}
}
// Default Index
if (flexsearch.map.size) {
let data = [],
stmt = new pgp.helpers.ColumnSet(["key", "res", "id"], {
table: this.id + ".map" + this.field
});
for (const item of flexsearch.map) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
//this.type || (this.type = typeof ids[0]);
// let stmt = "($1,$2,$3)";
// let params = [key, i, ids[0]];
for (let j = 0; j < ids.length; j++) {
// stmt += ",($1,$2,$3)";
// params.push(key, i, ids[j]);
//trx.none(`INSERT INTO ${config.schema}.map${self.field} (key, res, id) VALUES ($1,$2,$3)`, [key, i, ids[j]]);
data.push({
key: key,
res: i,
id: ids[j]
});
if (data.length === MAXIMUM_QUERY_VARS) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
data = [];
}
}
}
}
}
if (data.length) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
}
}
// Context Index
if (flexsearch.ctx.size) {
let data = [],
stmt = new pgp.helpers.ColumnSet(["ctx", "key", "res", "id"], {
table: this.id + ".ctx" + this.field
});
for (const ctx of flexsearch.ctx) {
const ctx_key = ctx[0],
ctx_value = ctx[1];
for (const item of ctx_value) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
// let stmt = "(?,?,?)";
// let params = [ctx_key + ":" + key, i, ids[0]];
for (let j = 0; j < ids.length; j++) {
// stmt += ",(?,?,?)";
// params.push(ctx_key + ":" + key, i, ids[j]);
//trx.none("INSERT INTO " + config.schema + ".ctx" + self.field + " (ctx, key, res, id) VALUES ($1,$2,$3,$4)", [ctx_key, key, i, ids[j]]);
data.push({
ctx: ctx_key,
key: key,
res: i,
id: ids[j]
});
if (data.length === MAXIMUM_QUERY_VARS) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
data = [];
}
}
}
}
}
}
if (data.length) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
}
}
// Tag Index
if (flexsearch.tag) {
let data = [],
stmt = new pgp.helpers.ColumnSet(["tag", "id"], {
table: this.id + ".tag" + this.field
});
for (const item of flexsearch.tag) {
const tag = item[0],
ids = item[1];
if (!ids.length) continue;
for (let j = 0; j < ids.length; j++) {
data.push({ tag, id: ids[j] });
if (data.length === MAXIMUM_QUERY_VARS) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
data = [];
}
}
}
if (data.length) {
let insert = pgp.helpers.insert(data, stmt);
batch.push(trx.none(insert.replace(/^(insert into )"([^"]+)"/, '$1 $2')));
}
}
// Field Configuration
// TODO
// trx.none("INSERT INTO " + this.id + ".cfg" + this.field + " (cfg) VALUES ($1)", [
// JSON.stringify({
// "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "",
// "charset": typeof flexsearch.charset === "string" ? flexsearch.charset : "",
// "tokenize": flexsearch.tokenize,
// "resolution": flexsearch.resolution,
// "minlength": flexsearch.minlength,
// "optimize": flexsearch.optimize,
// "fastupdate": flexsearch.fastupdate,
// "encoder": flexsearch.encoder,
// "context": {
// "depth": flexsearch.depth,
// "bidirectional": flexsearch.bidirectional,
// "resolution": flexsearch.resolution_ctx
// }
// })
// ]);
//return Promise.all(batch);
if (batch.length) {
return trx.batch(batch);
}
});
flexsearch.map.clear();
flexsearch.ctx.clear();
flexsearch.tag && flexsearch.tag.clear();
flexsearch.store && flexsearch.store.clear();
flexsearch.document || flexsearch.reg.clear();
};
PostgresDB.prototype.remove = function (ids) {
if (!ids && 0 !== ids) {
return;
}
if ("object" != typeof ids) {
ids = [ids];
}
if (!ids.length) {
return;
}
// ids = [ids];
// return this.db.none(
// "DELETE FROM " + this.id + ".map" + this.field + " WHERE id = ANY ($1);" +
// "DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id = ANY ($1);" +
// "DELETE FROM " + this.id + ".tag" + this.field + " WHERE id = ANY ($1);" +
// "DELETE FROM " + this.id + ".reg WHERE id = ANY ($1);", [ids]
// );
// ids = [ids];
// return Promise.all([
// this.db.none({ text: "DELETE FROM " + this.id + ".map" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids),
// this.db.none({ text: "DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids),
// this.db.none({ text: "DELETE FROM " + this.id + ".tag" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids),
// this.db.none({ text: "DELETE FROM " + this.id + ".reg WHERE id = ANY ($1)", rowMode: "array" }, ids)
// ]);
return this.transaction(function (trx) {
//console.log("remove:", ids);
// ids = [ids];
// trx.none({ text: "DELETE FROM " + this.id + ".map" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids);
// trx.none({ text: "DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids);
// trx.none({ text: "DELETE FROM " + this.id + ".tag" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids);
// trx.none({ text: "DELETE FROM " + this.id + ".reg WHERE id = ANY ($1)", rowMode: "array" }, ids);
// ids = [ids];
// trx.none("DELETE FROM " + this.id + ".map" + this.field + " WHERE id = ANY ($1)", ids);
// trx.none("DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id = ANY ($1)", ids);
// trx.none("DELETE FROM " + this.id + ".tag" + this.field + " WHERE id = ANY ($1)", ids);
// trx.none("DELETE FROM " + this.id + ".reg WHERE id = ANY ($1)", ids);
// return;
// return trx.none(
// "DELETE FROM " + this.id + ".map" + this.field + " WHERE id = ANY ($1);" +
// "DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id = ANY ($1);" +
// "DELETE FROM " + this.id + ".tag" + this.field + " WHERE id = ANY ($1);" +
// "DELETE FROM " + this.id + ".reg WHERE id = ANY ($1);", [ids]
// );
// while(ids.length){
// let next;
// let stmt = "";
// let chunk = 0;
// let migration;
// for(let i = 0; i < ids.length; i++){
// stmt += (stmt ? "," : "") + "$" + (i + 1); // + "::text";
// // maximum count of variables supported
// if(++chunk === MAXIMUM_QUERY_VARS){
// next = ids.slice(MAXIMUM_QUERY_VARS);
// ids = ids.slice(0, MAXIMUM_QUERY_VARS);
// break;
// }
// }
//
// trx.batch([
// trx.none("DELETE FROM " + this.id + ".map" + this.field + " WHERE id IN (" + stmt + ")", ids),
// trx.none("DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id IN (" + stmt + ")", ids),
// trx.none("DELETE FROM " + this.id + ".tag" + this.field + " WHERE id IN (" + stmt + ")", ids),
// trx.none("DELETE FROM " + this.id + ".reg WHERE id IN (" + stmt + ")", ids)
// ]);
//
// // trx.none(
// // "DELETE FROM " + this.id + ".map" + this.field + " WHERE id IN (" + stmt + ");" +
// // "DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id IN (" + stmt + ");" +
// // "DELETE FROM " + this.id + ".tag" + this.field + " WHERE id IN (" + stmt + ");" +
// // "DELETE FROM " + this.id + ".reg WHERE id IN (" + stmt + ");", ids
// // );
//
// if(next) ids = next;
// else break;
// }
ids = [ids];
return trx.batch([trx.none({ text: "DELETE FROM " + this.id + ".map" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids), trx.none({ text: "DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids), trx.none({ text: "DELETE FROM " + this.id + ".tag" + this.field + " WHERE id = ANY ($1)", rowMode: "array" }, ids), trx.none({ text: "DELETE FROM " + this.id + ".reg WHERE id = ANY ($1)", rowMode: "array" }, ids)]);
// ids = [ids];
// return trx.batch([
// trx.none("DELETE FROM " + this.id + ".map" + this.field + " WHERE id = ANY ($1)", ids),
// trx.none("DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id = ANY ($1)", ids),
// trx.none("DELETE FROM " + this.id + ".tag" + this.field + " WHERE id = ANY ($1)", ids),
// trx.none("DELETE FROM " + this.id + ".reg WHERE id = ANY ($1)", ids)
// ]);
// return trx.batch([
// trx.none("DELETE FROM " + this.id + ".map" + this.field + " WHERE id IN ($1:csv)", [ids]),
// trx.none("DELETE FROM " + this.id + ".ctx" + this.field + " WHERE id IN ($1:csv)", [ids]),
// trx.none("DELETE FROM " + this.id + ".tag" + this.field + " WHERE id IN ($1:csv)", [ids]),
// trx.none("DELETE FROM " + this.id + ".reg WHERE id IN ($1:csv)", [ids])
// ]);
// const type = self.type === "text" ? "text" : "int";
// return trx.batch([
// trx.none("DELETE FROM " + this.id + ".map" + self.field + " WHERE id = ANY($1::" + type + "[])", [ids]),
// trx.none("DELETE FROM " + this.id + ".ctx" + self.field + " WHERE id = ANY($1::" + type + "[])", [ids]),
// trx.none("DELETE FROM " + this.id + ".reg WHERE id = ANY($1::" + type + "[])", [ids])
// ]);
// return trx.batch([
// trx.none("DELETE FROM " + this.id + ".map" + self.field + " WHERE id = ANY($1)", [ids]),
// trx.none("DELETE FROM " + this.id + ".ctx" + self.field + " WHERE id = ANY($1)", [ids]),
// trx.none("DELETE FROM " + this.id + ".reg WHERE id = ANY($1)", [ids])
// ]);
});
};
// if(this.type === "int" && typeof ids[0] === "string"){
// ids = ids.map(item => parseInt(item, 10));
// }
// if(this.type === "bigint" && typeof ids[0] === "string"){
// ids = ids.map(item => BigInt(item));
// }
// if(this.type === "string" && typeof ids[0] === "number"){
// ids = ids.map(item => item + "");
// }
// this.type !== "string" && checkMigration.call(this, ids[0]);
// function checkMigration(id){
// if(this.type !== "string"){
// if(typeof id === "object"){
// id = id[0];
// }
// if(typeof id === "string"){
// this.type = "string";
// return upgradeTextId.call(this);
// }
// if(this.type !== "bigint"){
// if(id > 2 ** 31 - 1){
// this.type = "bigint";
// return upgradeBigIntId.call(this);
// }
// }
// }
// }
//
// function upgradeTextId(){
// return this.db.none(`
// ALTER TABLE ${this.id}.map${this.field}
// ALTER COLUMN id type varchar(128)
// USING id::text;
// ALTER TABLE ${this.id}.ctx${this.field}
// ALTER COLUMN id type varchar(128)
// USING id::text;
// ALTER TABLE ${this.id}.tag${this.field}
// ALTER COLUMN id type varchar(128)
// USING id::text;
// ALTER TABLE ${this.id}.reg
// ALTER COLUMN id type varchar(128)
// USING id::text;
// `);
// }
//
// function upgradeBigIntId(){
// return this.db.none(`
// ALTER TABLE ${this.id}.map${this.field}
// ALTER COLUMN id type bigint
// USING id::bigint;
// ALTER TABLE ${this.id}.ctx${this.field}
// ALTER COLUMN id type bigint
// USING id::bigint;
// ALTER TABLE ${this.id}.tag${this.field}
// ALTER COLUMN id type bigint
// USING id::bigint;
// ALTER TABLE ${this.id}.reg
// ALTER COLUMN id type bigint
// USING id::bigint;
// `);
// }

500
dist/module-debug/db/redis/index.js vendored Normal file
View File

@@ -0,0 +1,500 @@
import { createClient } from "redis";
const defaults = {
host: "localhost",
port: "6379",
user: null,
pass: null
},
VERSION = 1,
fields = ["map", "ctx", "reg", "tag", "doc", "cfg"];
import StorageInterface from "../interface.js";
import Document from "../../document.js";
import { toArray } from "../../common.js";
function sanitize(str) {
return str.toLowerCase().replace(/[^a-z0-9_\-]/g, "");
}
let DB, TRX;
/**
* @constructor
* @implements StorageInterface
*/
export default function RedisDB(name, config = {}) {
if (!(this instanceof RedisDB)) {
return new RedisDB(name, config);
}
if ("object" == typeof name) {
name = name.name;
config = name;
}
if (!name) {
console.info("Default storage space was used, because a name was not passed.");
}
this.id = (name ? sanitize(name) : "flexsearch") + "|";
this.field = config.field ? "-" + sanitize(config.field) : "";
this.type = config.type || "";
this.fastupdate = /* tag? */ /* stringify */ /* stringify */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/;
this.db = config.db || DB || null;
this.support_tag_search = !0;
//this.trx = false;
Object.assign(defaults, config);
this.db && delete defaults.db;
}
// RedisDB.mount = function(flexsearch){
// return new this().mount(flexsearch);
// };
RedisDB.prototype.mount = function (flexsearch) {
if (flexsearch instanceof Document) {
return flexsearch.mount(this);
}
flexsearch.db = this;
// todo support
//this.fastupdate = flexsearch.fastupdate;
return this.open();
};
RedisDB.prototype.open = async function () {
if (this.db) {
return this.db;
}
let url = defaults.url;
if (!url) {
url = defaults.user ? `redis://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}` : `redis://${defaults.host}:${defaults.port}`;
}
return this.db = await createClient(url).on("error", err => console.error(err)).connect();
};
RedisDB.prototype.close = async function () {
await this.db.disconnect(); // this.db.client.disconnect();
this.db = null;
return this;
};
RedisDB.prototype.clear = function () {
return this.db.unlink([this.id + "map" + this.field, this.id + "ctx" + this.field, this.id + "tag" + this.field, this.id + "cfg" + this.field, this.id + "doc", this.id + "reg"]);
};
function create_result(range, type, resolve, enrich) {
if (resolve) {
for (let i = 0, tmp, id; i < range.length; i++) {
tmp = range[i];
id = "number" === type ? parseInt(tmp.value || tmp, 10) : tmp.value || tmp;
range[i] = /*enrich
? { id, doc: tmp.doc }
:*/id;
}
return range;
} else {
let result = [];
for (let i = 0, tmp, id, score; i < range.length; i++) {
tmp = range[i];
id = "number" === type ? parseInt(tmp.value, 10) : tmp.value;
score = tmp.score;
result[score] || (result[score] = []);
result[score].push(enrich ? { id, doc: tmp.doc } : id);
}
return result;
}
}
RedisDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = !0, enrich = /* suggest */!1, tags) {
if (tags) {
// flexsearch dummy
const query = ctx ? [ctx, key] : [key];
// keyword first
return this.search({ depth: !!ctx }, query, limit, offset, !1, resolve, enrich, tags);
}
const type = this.type,
self = this;
let result;
if (ctx) {
result = this.db[resolve ? "zRange" : "zRangeWithScores"](this.id + "ctx" + this.field + ":" + ctx + ":" + key, "" + offset, "" + (offset + limit - 1), { REV: !0 });
} else {
result = this.db[resolve ? "zRange" : "zRangeWithScores"](this.id + "map" + this.field + ":" + key, "" + offset, "" + (offset + limit - 1), { REV: !0 });
}
return result.then(async function (range) {
if (!range.length) return range;
if (enrich) range = await self.enrich(range);
return create_result(range, type, resolve, enrich);
});
};
RedisDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) {
const self = this;
return this.db.sMembers(this.id + "tag" + this.field + ":" + tag).then(function (ids) {
if (!ids || !ids.length || offset >= ids.length) return [];
if (!limit && !offset) return ids;
const result = ids.slice(offset, offset + limit);
return enrich ? self.enrich(result) : result;
});
};
RedisDB.prototype.enrich = function (ids) {
if ("object" != typeof ids) {
ids = [ids];
}
return this.db.hmGet(this.id + "doc", ids).then(function (res) {
for (let i = 0; i < res.length; i++) {
res[i] = {
id: ids[i],
doc: res[i] && JSON.parse(res[i])
};
}
return res;
});
};
RedisDB.prototype.has = function (id) {
return this.db.sIsMember(this.id + "reg", "" + id);
};
RedisDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) {
let result;
if (1 < query.length && flexsearch.depth) {
const key = this.id + "ctx" + this.field + ":";
let params = [],
keyword = query[0],
term;
for (let i = 1, swap; i < query.length; i++) {
term = query[i];
swap = flexsearch.bidirectional && term > keyword;
params.push(key + (swap ? term : keyword) + ":" + (swap ? keyword : term));
keyword = term;
}
query = params;
} else {
const key = this.id + "map" + this.field + ":";
for (let i = 0; i < query.length; i++) {
query[i] = key + query[i];
}
}
const type = this.type;
let key = this.id + "tmp:" + Math.random();
if (suggest) {
if (tags) for (let i = 0; i < tags.length; i += 2) {
query.push(this.id + "tag-" + sanitize(tags[i]) + ":" + tags[i + 1]);
}
const multi = this.db.multi().zUnionStore(key, query, { AGGREGATE: "SUM" });
// Strict Tag Intersection: it does not put tags into union, instead it calculates the
// intersection against the term match union. This was the default behavior
// of Tag-Search. But putting everything into union will also provide suggestions derived
// from tags when no term was matched.
result = multi[resolve ? "zRange" : "zRangeWithScores"](key, "" + offset, "" + (offset + limit - 1), { REV: !0 }).unlink(key).exec();
} else {
if (tags) for (let i = 0; i < tags.length; i += 2) {
query.push(this.id + "tag-" + sanitize(tags[i]) + ":" + tags[i + 1]);
}
result = this.db.multi().zInterStore(key, query, { AGGREGATE: "MIN" })[resolve ? "zRange" : "zRangeWithScores"](key, "" + offset, "" + (offset + limit - 1), { REV: !0 }).unlink(key).exec();
}
const self = this;
return result.then(async function (range) {
range = suggest && tags
// take the 3rd result from batch return
? range[2]
// take the 2nd result from batch return
: range[1];
if (!range.length) return range;
if (enrich) range = await self.enrich(range);
return create_result(range, type, resolve, enrich);
});
};
RedisDB.prototype.info = function () {
// todo
};
RedisDB.prototype.transaction = async function (task, callback) {
if (TRX) {
return task.call(this, TRX);
}
TRX = this.db.multi();
let promise1 = /*await*/task.call(this, TRX),
promise2 = TRX.exec();
TRX = null;
callback && promise.then(callback);
await Promise.all([promise1, promise2]);
};
RedisDB.prototype.commit = async function (flexsearch, _replace, _append) {
// process cleanup tasks
if (_replace) {
await this.clear();
// there are just removals in the task queue
flexsearch.commit_task = [];
} else {
let tasks = flexsearch.commit_task;
flexsearch.commit_task = [];
for (let i = 0, task; i < tasks.length; i++) {
task = tasks[i];
// there are just removals in the task queue
if (task.clear) {
await this.clear();
_replace = !0;
break;
} else {
tasks[i] = "" + task.del;
}
}
if (!_replace) {
if (!_append) {
tasks = tasks.concat(toArray(flexsearch.reg, !0));
}
tasks.length && (await this.remove(tasks));
}
}
if (!flexsearch.reg.size) {
return;
}
await this.transaction(function (trx) {
let refs = new Map();
for (const item of flexsearch.map) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
let result = [];
for (let j = 0; j < ids.length; j++) {
result.push({
score: i,
value: "" + ids[j]
});
}
if ("number" == typeof ids[0]) {
this.type = "number";
}
const ref = this.id + "map" + this.field + ":" + key;
trx.zAdd(ref, result);
// if(this.fastupdate) for(let j = 0; j < ids.length; j++){
// trx.sAdd("ref" + this.field + ":" + ids[j], ref);
// }
if (this.fastupdate) for (let j = 0, id; j < ids.length; j++) {
// Map performs bad when pushing numeric-like values as key
// id = ids[j];
// let tmp = refs.get(id);
// tmp || refs.set(id, tmp = []);
// tmp.push(ref);
id = ids[j];
let tmp = refs.get(id);
tmp || refs.set(id, tmp = []);
tmp.push(ref);
}
}
}
}
// if(this.fastupdate) for(let item of refs){
// const key = item[0];
// const value = item[1];
// trx.sAdd("ref" + this.field + ":" + key, value);
// }
if (this.fastupdate) for (const item of refs) {
const key = item[0],
value = item[1];
trx.sAdd(this.id + "ref" + this.field + ":" + key, value);
}
refs = new Map();
for (const ctx of flexsearch.ctx) {
const ctx_key = ctx[0],
ctx_value = ctx[1];
for (const item of ctx_value) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
let result = [];
for (let j = 0; j < ids.length; j++) {
result.push({ score: i, value: "" + ids[j] });
}
if ("number" == typeof ids[0]) {
this.type = "number";
}
const ref = this.id + "ctx" + this.field + ":" + ctx_key + ":" + key;
trx.zAdd(ref, result);
// if(this.fastupdate) for(let j = 0; j < ids.length; j++){
// trx.sAdd("ref" + this.field + ":" + ids[j], ref);
// }
if (this.fastupdate) for (let j = 0, id; j < ids.length; j++) {
// Map performs bad when pushing numeric-like values as key
// id = ids[j];
// let tmp = refs.get(id);
// tmp || refs.set(id, tmp = []);
// tmp.push(ref);
id = ids[j];
let tmp = refs.get(id);
tmp || refs.set(id, tmp = []);
tmp.push(ref);
}
}
}
}
}
if (this.fastupdate) for (const item of refs) {
const key = item[0],
value = item[1];
trx.sAdd(this.id + "ref" + this.field + ":" + key, value);
}
if (flexsearch.store) {
for (const item of flexsearch.store.entries()) {
const id = item[0],
doc = item[1];
doc && trx.hSet(this.id + "doc", "" + id, JSON.stringify(doc));
}
}
if (!flexsearch.bypass) {
let ids = toArray(flexsearch.reg, !0);
if (ids.length) {
trx.sAdd(this.id + "reg", ids);
}
}
if (flexsearch.tag) {
for (const item of flexsearch.tag) {
const tag = item[0],
ids = item[1];
if (!ids.length) continue;
let result = [];
// for(let i = 0; i < ids.length; i++){
// result.push({
// score: 0,
// value: "" + ids[i]
// });
// }
if ("number" == typeof ids[0]) {
for (let i = 0; i < ids.length; i++) {
result[i] = "" + ids[i];
}
} else {
result = ids;
}
trx.sAdd(this.id + "tag" + this.field + ":" + tag, result);
}
}
// TODO
// trx.set(this.id + "cfg" + this.field, JSON.stringify({
// "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "",
// "charset": typeof flexsearch.charset === "string" ? flexsearch.charset : "",
// "tokenize": flexsearch.tokenize,
// "resolution": flexsearch.resolution,
// "minlength": flexsearch.minlength,
// "optimize": flexsearch.optimize,
// "fastupdate": flexsearch.fastupdate,
// "encoder": flexsearch.encoder,
// "context": {
// "depth": flexsearch.depth,
// "bidirectional": flexsearch.bidirectional,
// "resolution": flexsearch.resolution_ctx
// }
// }));
});
flexsearch.map.clear();
flexsearch.ctx.clear();
flexsearch.tag && flexsearch.tag.clear();
flexsearch.store && flexsearch.store.clear();
flexsearch.document || flexsearch.reg.clear();
};
RedisDB.prototype.remove = function (ids) {
if (!ids && 0 !== ids) {
return;
}
if ("object" != typeof ids) {
ids = [ids];
}
if (!ids.length) {
return;
}
return this.transaction(async function (trx) {
while (ids.length) {
let next;
if (10000 < ids.length) {
next = ids.slice(10000);
ids = ids.slice(0, 10000);
}
if ("number" == typeof ids[0]) {
for (let i = 0; i < ids.length; i++) {
ids[i] = "" + ids[i];
}
}
const check = await this.db.smIsMember(this.id + "reg", ids);
for (let i = 0, id; i < ids.length; i++) {
if (!check[i]) continue;
id = "" + ids[i];
if (this.fastupdate) {
// const refs = new Map();
const ref = await this.db.sMembers(this.id + "ref" + this.field + ":" + id);
if (ref) {
for (let j = 0; j < ref.length; j++) {
// let tmp = refs.get(ref[j]);
// tmp || refs.set(ref[j], tmp = []);
// tmp.push(id);
trx.zRem(ref[j], id);
}
trx.unlink(this.id + "ref" + this.field + ":" + id);
}
// for(let item of refs){
// //console.log(item[0], item[1])
// trx.zRem(item[0], item[1]);
// }
}
trx.hDel(this.id + "doc", id);
trx.sRem(this.id + "reg", id);
}
if (next) ids = next;else break;
}
});
};

794
dist/module-debug/db/sqlite/index.js vendored Normal file
View File

@@ -0,0 +1,794 @@
//const sqlite3 = require("sqlite3").verbose();
import sqlite3 from "sqlite3";
import path from "path";
import StorageInterface from "../interface.js";
import { concat, toArray } from "../../common.js";
import Document from "../../document.js";
const VERSION = 1,
MAXIMUM_QUERY_VARS = 16000,
fields = ["map", "ctx", "reg", "tag", "cfg"],
types = {
text: "text",
char: "text",
varchar: "text",
string: "text",
number: "int",
numeric: "int",
integer: "int",
smallint: "int",
tinyint: "int",
mediumint: "int",
int: "int",
int8: "int",
uint8: "int",
int16: "int",
uint16: "int",
int32: "int",
uint32: "bigint",
int64: "bigint",
bigint: "bigint"
};
function sanitize(str) {
return str.toLowerCase().replace(/[^a-z0-9_]/g, "");
}
// global transaction to keep track of database lock
const TRX = Object.create(null),
DB = Object.create(null);
/**
* @constructor
* @implements StorageInterface
*/
export default function SqliteDB(name, config = {}) {
if (!(this instanceof SqliteDB)) {
return new SqliteDB(name, config);
}
if ("object" == typeof name) {
name = name.name;
config = name;
}
if (!name) {
console.info("Default storage space was used, because a name was not passed.");
}
//field = "Test-456";
this.id = config.path || (":memory:" === name ? name : "flexsearch" + (name ? "-" + sanitize(name) : "") + ".sqlite");
this.field = config.field ? "_" + sanitize(config.field) : "";
this.support_tag_search = /* tag? */ /* stringify */ /* stringify */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/;
this.db = config.db || DB[this.id] || null;
this.type = config.type ? types[config.type.toLowerCase()] : "string";
if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'");
}
SqliteDB.prototype.mount = function (flexsearch) {
if (flexsearch instanceof Document) {
return flexsearch.mount(this);
}
flexsearch.db = this;
return this.open();
};
SqliteDB.prototype.open = async function () {
if (!this.db) {
if (!(this.db = DB[this.id])) {
let filepath = this.id;
if (":memory:" !== filepath) {
// skip absolute path
if ("/" !== filepath[0] && "\\" !== filepath[0]) {
// current working directory
const dir = process.cwd();
filepath = path.join(dir, this.id);
}
}
this.db = DB[this.id] = new sqlite3.Database(filepath);
}
}
const db = this.db;
for (let i = 0; i < fields.length; i++) {
const exist = await this.promisfy({
method: "get",
stmt: "SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?) as exist",
params: [fields[i] + ("reg" === fields[i] ? "" : this.field)]
});
if (!exist || !exist.exist) {
let stmt, stmt_index;
switch (fields[i]) {
case "map":
stmt = `
CREATE TABLE IF NOT EXISTS main.map${this.field}(
key TEXT NOT NULL,
res INTEGER NOT NULL,
id ${this.type} NOT NULL
);
`;
stmt_index = `
CREATE INDEX IF NOT EXISTS map_key_index${this.field}
ON map${this.field} (key);
CREATE INDEX IF NOT EXISTS map_id_index${this.field}
ON map${this.field} (id);
`;
break;
case "ctx":
stmt = `
CREATE TABLE IF NOT EXISTS main.ctx${this.field}(
ctx TEXT NOT NULL,
key TEXT NOT NULL,
res INTEGER NOT NULL,
id ${this.type} NOT NULL
);
`;
stmt_index = `
CREATE INDEX IF NOT EXISTS ctx_key_index${this.field}
ON ctx${this.field} (ctx, key);
CREATE INDEX IF NOT EXISTS ctx_id_index${this.field}
ON ctx${this.field} (id);
`;
break;
case "tag":
stmt = `
CREATE TABLE IF NOT EXISTS main.tag${this.field}(
tag TEXT NOT NULL,
id ${this.type} NOT NULL
);
`;
stmt_index = `
CREATE INDEX IF NOT EXISTS tag_index${this.field}
ON tag${this.field} (tag);
CREATE INDEX IF NOT EXISTS tag_id_index${this.field}
ON tag${this.field} (id);
`;
break;
case "reg":
stmt = `
CREATE TABLE IF NOT EXISTS main.reg(
id ${this.type} NOT NULL
CONSTRAINT reg_pk${this.field}
PRIMARY KEY,
doc TEXT DEFAULT NULL
);
`;
stmt_index = `
CREATE INDEX IF NOT EXISTS reg_index
ON reg (id);
`;
break;
case "cfg":
stmt = `
CREATE TABLE IF NOT EXISTS main.cfg${this.field} (
cfg TEXT NOT NULL
);
`;
break;
}
await new Promise(function (resolve, reject) {
db.exec(stmt, function (err, rows) {
if (err) return reject(err);
stmt_index ? db.exec(stmt_index, function (err, rows) {
if (err) return reject(err);
resolve(rows);
}) : resolve(rows);
});
});
}
}
db.exec("PRAGMA optimize = 0x10002");
return db;
};
SqliteDB.prototype.close = function () {
this.db.close();
this.db = null;
return this;
};
SqliteDB.prototype.destroy = async function () {
await this.transaction(function () {
this.db.run("DROP TABLE IF EXISTS main.map" + this.field + ";");
this.db.run("DROP TABLE IF EXISTS main.ctx" + this.field + ";");
this.db.run("DROP TABLE IF EXISTS main.tag" + this.field + ";");
this.db.run("DROP TABLE IF EXISTS main.cfg" + this.field + ";");
this.db.run("DROP TABLE IF EXISTS main.reg;");
});
this.close();
};
SqliteDB.prototype.clear = function () {
return this.transaction(function () {
this.db.run("DELETE FROM main.map" + this.field + " WHERE 1;");
this.db.run("DELETE FROM main.ctx" + this.field + " WHERE 1;");
this.db.run("DELETE FROM main.tag" + this.field + " WHERE 1;");
this.db.run("DELETE FROM main.cfg" + this.field + " WHERE 1;");
this.db.run("DELETE FROM main.reg WHERE 1;");
});
};
function create_result(rows, resolve, enrich) {
if (resolve) {
for (let i = 0; i < rows.length; i++) {
if (enrich) {
if (rows[i].doc) {
rows[i].doc = JSON.parse(rows[i].doc);
}
} else {
rows[i] = rows[i].id;
}
}
return rows;
} else {
const arr = [];
for (let i = 0, row; i < rows.length; i++) {
row = rows[i];
arr[row.res] || (arr[row.res] = []);
arr[row.res].push(enrich ? row : row.id);
}
return arr;
}
}
SqliteDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = !0, enrich = /* suggest */!1, tags) {
let result,
stmt = '',
params = ctx ? [ctx, key] : [key],
table = "main." + (ctx ? "ctx" : "map") + this.field;
if (tags) {
for (let i = 0; i < tags.length; i += 2) {
stmt += ` AND ${table}.id IN (SELECT id FROM main.tag_${sanitize(tags[i])} WHERE tag = ?)`;
params.push(tags[i + 1]);
}
}
if (ctx) {
result = this.promisfy({
method: "all",
stmt: `
SELECT ${table}.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT JOIN main.reg ON main.reg.id = ${table}.id
` : ""}
WHERE ctx = ? AND key = ? ${stmt}
ORDER BY res
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`,
params
});
} else {
result = this.promisfy({
method: "all",
stmt: `
SELECT ${table}.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT JOIN main.reg ON main.reg.id = ${table}.id
` : ""}
WHERE key = ? ${stmt}
ORDER BY res
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`,
params
});
}
return result.then(function (rows) {
return create_result(rows, resolve, enrich);
});
};
SqliteDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) {
const table = "main.tag" + this.field,
promise = this.promisfy({
method: "all",
stmt: `
SELECT ${table}.id
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT JOIN main.reg ON main.reg.id = ${table}.id
` : ""}
WHERE tag = ?
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`,
params: [tag]
});
enrich || promise.then(function (rows) {
return create_result(rows, !0, !1);
});
return promise;
};
function build_params(length) {
let stmt = ",?";
for (let i = 1; i < length;) {
if (i <= length - i) {
stmt += stmt;
i *= 2;
} else {
stmt += stmt.substring(0, 2 * (length - i));
break;
}
}
return stmt.substring(1);
}
SqliteDB.prototype.enrich = function (ids) {
const result = [],
promises = [];
if ("object" != typeof ids) {
ids = [ids];
}
for (let count = 0; count < ids.length;) {
const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids;
count += chunk.length;
// let stmt = "?";
// for(let i = 1; i < chunk.length; i++){
// stmt += ",?";
// }
// 10x faster string concatenation
let stmt = build_params(chunk.length);
promises.push(this.promisfy({
method: "all",
stmt: `SELECT id, doc FROM main.reg WHERE id IN (${stmt})`,
params: chunk
}));
}
return Promise.all(promises).then(function (promises) {
for (let i = 0, res; i < promises.length; i++) {
res = promises[i];
if (res && res.length) {
for (let i = 0, doc; i < res.length; i++) {
if (doc = res[i].doc) {
res[i].doc = JSON.parse(doc);
}
}
result.push(res);
}
}
return 1 === result.length ? result[0] : 1 < result.length ? concat(result) : result;
});
};
SqliteDB.prototype.has = function (id) {
return this.promisfy({
method: "get",
stmt: `SELECT EXISTS(SELECT 1 FROM main.reg WHERE id = ?) as exist`,
params: [id]
}).then(function (result) {
return result && result.exist;
});
};
SqliteDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !1, tags) {
let rows;
if (1 < query.length && flexsearch.depth) {
let stmt = "",
params = [],
keyword = query[0],
term;
for (let i = 1; i < query.length; i++) {
term = query[i];
const swap = flexsearch.bidirectional && term > keyword;
stmt += (stmt ? " OR " : "") + `(ctx = ? AND key = ?)`;
params.push(swap ? term : keyword, swap ? keyword : term);
keyword = term;
}
if (tags) {
stmt = "(" + stmt + ")";
for (let i = 0; i < tags.length; i += 2) {
stmt += ` AND id IN (SELECT id FROM main.tag_${sanitize(tags[i])} WHERE tag = ?)`;
params.push(tags[i + 1]);
}
}
rows = this.promisfy({
method: "all",
stmt: `
SELECT r.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM (
SELECT id, count(*) as count,
${suggest ? "SUM" : "MIN"}(res) as res
FROM main.ctx${this.field}
WHERE ${stmt}
GROUP BY id
) as r
${enrich ? `
LEFT JOIN main.reg ON main.reg.id = r.id
` : ""}
${suggest ? "" : "WHERE count = " + (query.length - 1)}
ORDER BY ${suggest ? "count DESC, res" : "res"}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`,
params
});
// variant 1
// for(let i = 1; i < query.length; i++){
// stmt += (stmt ? " UNION ALL " : "") + `
// SELECT id, res
// FROM main.ctx${this.field}
// WHERE ctx = ? AND key = ?
// `;
// term = query[i];
// const swap = flexsearch.bidirectional && (term > keyword);
// params.push(swap ? term : keyword, swap ? keyword : term);
// keyword = term;
// }
//
// rows = await this.promisfy({
// method: "all",
// stmt: `
// SELECT id/*, res */
// FROM (
// SELECT id, ${suggest ? "SUM" : "MIN"}(res) as res, count(*) as count
// FROM (${stmt}) as t
// GROUP BY id
// ORDER BY ${suggest ? "count DESC, res" : "res"}
// LIMIT ${limit}
// OFFSET ${offset}
// ) as r
// ${suggest ? "" : "WHERE count = " + (query.length - 1)}
// `,
// params
// });
} else {
let stmt = "",
query_length = query.length;
for (let i = 0; i < query_length; i++) {
stmt += (stmt ? " OR " : "") + `key = ?`;
}
if (tags) {
stmt = "(" + stmt + ")";
for (let i = 0; i < tags.length; i += 2) {
stmt += ` AND id IN (SELECT id FROM main.tag_${sanitize(tags[i])} WHERE tag = ?)`;
query.push(tags[i + 1]);
}
}
rows = this.promisfy({
method: "all",
stmt: `
SELECT r.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM (
SELECT id, count(*) as count,
${suggest ? "SUM" : "MIN"}(res) as res
FROM main.map${this.field}
WHERE ${stmt}
GROUP BY id
) as r
${enrich ? `
LEFT JOIN main.reg ON main.reg.id = r.id
` : ""}
${suggest ? "" : "WHERE count = " + query_length}
ORDER BY ${suggest ? "count DESC, res" : "res"}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`,
params: query
});
// variant 1
// for(let i = 0; i < query.length; i++){
// stmt += (stmt ? " UNION ALL " : "") + `
// SELECT id, res
// FROM main.map${ this.field }
// WHERE key = ?
// `;
// }
//
// rows = await this.promisfy({
// method: "all",
// stmt: `
// SELECT id/*, res*/
// FROM (
// SELECT id, ${suggest ? "SUM" : "MIN"}(res) as res, count(*) as count
// FROM (${stmt}) as t
// GROUP BY id
// ORDER BY ${suggest ? "count DESC, res" : "res"}
// LIMIT ${limit}
// OFFSET ${offset}
// ) as r
// ${ suggest ? "" : "WHERE count = " + query.length }
// `,
// params: query
// });
}
return rows.then(function (rows) {
return create_result(rows, resolve, enrich);
});
};
SqliteDB.prototype.info = function () {
// todo
};
SqliteDB.prototype.transaction = function (task, callback) {
const self = this;
if (TRX[this.id]) {
return TRX[this.id].then(function () {
return self.transaction(task, callback);
});
}
const db = this.db;
return TRX[this.id] = new Promise(function (resolve, reject) {
db.exec("PRAGMA optimize");
db.exec('PRAGMA busy_timeout = 5000');
db.exec("BEGIN");
db.parallelize(function () {
task.call(self);
});
db.exec("COMMIT", function (err, rows) {
TRX[self.id] = null;
if (err) return reject(err);
callback && callback(rows);
resolve(rows);
db.exec("PRAGMA shrink_memory");
});
});
};
SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) {
// process cleanup tasks
if (_replace) {
await this.clear();
// there are just removals in the task queue
flexsearch.commit_task = [];
} else {
let tasks = flexsearch.commit_task;
flexsearch.commit_task = [];
for (let i = 0, task; i < tasks.length; i++) {
task = tasks[i];
// there are just removals in the task queue
if (task.clear) {
await this.clear();
_replace = !0;
break;
} else {
tasks[i] = task.del;
}
}
if (!_replace) {
if (!_append) {
tasks = tasks.concat(toArray(flexsearch.reg));
}
tasks.length && (await this.remove(tasks));
}
}
if (!flexsearch.reg.size) {
return;
}
await this.transaction(function () {
for (const item of flexsearch.map) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
let stmt = "",
params = [];
for (let j = 0; j < ids.length; j++) {
stmt += (stmt ? "," : "") + "(?,?,?)";
params.push(key, i, ids[j]);
// maximum count of variables supported
if (j === ids.length - 1 || params.length + 3 > MAXIMUM_QUERY_VARS) {
this.db.run("INSERT INTO main.map" + this.field + " (key, res, id) VALUES " + stmt, params);
stmt = "";
params = [];
}
//this.db.run("INSERT INTO map (key, res, id) VALUES (?, ?, ?) ON CONFLICT DO NOTHING", [key, i, ids[j]]);
}
}
}
}
//});
//await this.transaction(function(){
for (const ctx of flexsearch.ctx) {
const ctx_key = ctx[0],
ctx_value = ctx[1];
for (const item of ctx_value) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
let stmt = "",
params = [];
for (let j = 0; j < ids.length; j++) {
stmt += (stmt ? "," : "") + "(?,?,?,?)";
params.push(ctx_key, key, i, ids[j]);
// maximum count of variables supported
if (j === ids.length - 1 || params.length + 4 > MAXIMUM_QUERY_VARS) {
this.db.run("INSERT INTO main.ctx" + this.field + " (ctx, key, res, id) VALUES " + stmt, params);
stmt = "";
params = [];
}
}
}
}
}
}
//});
//await this.transaction(function(){
if (flexsearch.store) {
let stmt = "",
chunk = [];
for (const item of flexsearch.store.entries()) {
const id = item[0],
doc = item[1];
stmt += (stmt ? "," : "") + "(?,?)";
chunk.push(id, "object" == typeof doc ? JSON.stringify(doc) : doc || null);
if (chunk.length + 2 > MAXIMUM_QUERY_VARS) {
this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt, chunk);
stmt = "";
chunk = [];
}
}
if (chunk.length) {
this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt, chunk);
}
} else if (!flexsearch.bypass) {
let ids = toArray(flexsearch.reg);
for (let count = 0; count < ids.length;) {
const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids;
count += chunk.length;
const stmt = build_params(chunk.length);
this.db.run("INSERT INTO main.reg (id) VALUES (" + stmt + ")", chunk);
}
}
//});
//await this.transaction(function(){
if (flexsearch.tag) {
let stmt = "",
chunk = [];
for (const item of flexsearch.tag) {
const tag = item[0],
ids = item[1];
if (!ids.length) continue;
for (let i = 0; i < ids.length; i++) {
stmt += (stmt ? "," : "") + "(?,?)";
chunk.push(tag, ids[i]);
}
if (chunk.length + 2 > MAXIMUM_QUERY_VARS) {
this.db.run("INSERT INTO main.tag" + this.field + " (tag, id) VALUES " + stmt, chunk);
stmt = "";
chunk = [];
}
}
if (chunk.length) {
this.db.run("INSERT INTO main.tag" + this.field + " (tag, id) VALUES " + stmt, chunk);
}
}
});
// TODO
//await this.transaction(function(){
// this.db.run("INSERT INTO main.cfg" + this.field + " (cfg) VALUES (?)", [JSON.stringify({
// "charset": flexsearch.charset,
// "tokenize": flexsearch.tokenize,
// "resolution": flexsearch.resolution,
// "fastupdate": flexsearch.fastupdate,
// "compress": flexsearch.compress,
// "encoder": {
// "minlength": flexsearch.encoder.minlength
// },
// "context": {
// "depth": flexsearch.depth,
// "bidirectional": flexsearch.bidirectional,
// "resolution": flexsearch.resolution_ctx
// }
// })]);
//});
flexsearch.map.clear();
flexsearch.ctx.clear();
flexsearch.tag && flexsearch.tag.clear();
flexsearch.store && flexsearch.store.clear();
flexsearch.document || flexsearch.reg.clear();
};
SqliteDB.prototype.remove = function (ids) {
if ("object" != typeof ids) {
ids = [ids];
}
let next;
// maximum count of variables supported
if (ids.length > MAXIMUM_QUERY_VARS) {
next = ids.slice(MAXIMUM_QUERY_VARS);
ids = ids.slice(0, MAXIMUM_QUERY_VARS);
}
const self = this;
return this.transaction(function () {
const stmt = build_params(ids.length);
this.db.run("DELETE FROM main.map" + self.field + " WHERE id IN (" + stmt + ")", ids);
this.db.run("DELETE FROM main.ctx" + self.field + " WHERE id IN (" + stmt + ")", ids);
this.db.run("DELETE FROM main.tag" + self.field + " WHERE id IN (" + stmt + ")", ids);
this.db.run("DELETE FROM main.reg WHERE id IN (" + stmt + ")", ids);
}).then(function (res) {
return next ? self.remove(next) : res;
});
};
SqliteDB.prototype.promisfy = function (opt) {
const db = this.db;
return new Promise(function (resolve, reject) {
db[opt.method](opt.stmt, opt.params || [], function (err, rows) {
opt.callback && opt.callback(rows);
err ? reject(err) : resolve(rows);
});
});
};

View File

@@ -6,68 +6,168 @@
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
import { DocumentOptions } from "./type.js";
import Index from "./index.js"; import Index from "./index.js";
import { DocumentInterface } from "./type.js";
import Cache, { searchCache } from "./cache.js";
import { create_object, is_array, is_string, is_object, parse_option, get_keys } from "./common.js";
import apply_async from "./async.js";
import { intersect, intersect_union } from "./intersect.js";
import { exportDocument, importDocument } from "./serialize.js";
import WorkerIndex from "./worker/index.js"; import WorkerIndex from "./worker/index.js";
import Cache, { searchCache } from "./cache.js";
import { is_string, is_object, parse_simple } from "./common.js";
import apply_async from "./async.js";
import { exportDocument, importDocument } from "./serialize.js";
import { KeystoreMap, KeystoreSet } from "./keystore.js";
import "./document/add.js";
import "./document/search.js";
/** /**
* @constructor * @constructor
* @implements {DocumentInterface} * @param {DocumentOptions=} options
* @param {Object=} options
* @return {Document}
*/ */
function Document(options) { export default function Document(options) {
if (!(this instanceof Document)) { if (!(this instanceof Document)) {
return new Document(options); return new Document(options);
} }
const document = options.document || options.doc || options; const document = options.document || options.doc || options;
let opt; let tmp, keystore;
this.tree = []; this.tree = [];
this.field = []; this.field = [];
this.marker = []; this.marker = [];
this.register = create_object(); this.key = (tmp = document.key || document.id) && parse_tree(tmp, this.marker) || "id";
this.key = (opt = document.key || document.id) && parse_tree(opt, this.marker) || "id";
this.fastupdate = parse_option(options.fastupdate, /* append: */ /* skip update: */ /* skip_update: */!0);
this.storetree = (opt = document.store) && !0 !== opt && []; keystore = options.keystore || 0;
this.store = opt && create_object(); keystore && (this.keystore = keystore);
this.fastupdate = !!options.fastupdate;
this.reg = this.fastupdate ? keystore ? new KeystoreMap(keystore) : new Map() : keystore ? new KeystoreSet(keystore) : new Set();
// todo support custom filter function
this.storetree = (tmp = document.store || null) && /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ !== tmp && [];
this.store = tmp && (keystore ? new KeystoreMap(keystore) : new Map());
// TODO case-insensitive tags this.cache = (tmp = options.cache || null) && new Cache(tmp);
// do not apply cache again for the indexes since .searchCache()
this.tag = (opt = document.tag) && parse_tree(opt, this.marker); // is just a wrapper over .search()
this.tagindex = opt && create_object(); options.cache = /* suggest */ /* append: */ /* enrich */!1;
this.cache = (opt = options.cache) && new Cache(opt);
// do not apply cache again for the indexes
options.cache = !1;
this.worker = options.worker; this.worker = options.worker;
// this switch is used by recall of promise callbacks // this switch is used by recall of promise callbacks
this.async = !1; this.async = !1;
/** @export */ /** @export */
this.index = parse_descriptor.call(this, options, document); this.index = parse_descriptor.call(this, options, document);
this.tag = null;
// TODO case-insensitive tags?
if (tmp = document.tag) {
if ("string" == typeof tmp) {
tmp = [tmp];
}
if (tmp.length) {
this.tag = new Map();
this.tagtree = [];
this.tagfield = [];
for (let i = 0, params, field; i < tmp.length; i++) {
params = tmp[i];
field = params.field || params;
if (!field) {
throw new Error("The tag field from the document descriptor is undefined.");
}
if (params.custom) {
this.tagtree[i] = params.custom;
} else {
this.tagtree[i] = parse_tree(field, this.marker);
if (params.filter) {
if ("string" == typeof this.tagtree[i]) {
// it needs an object to put a property to it
this.tagtree[i] = new String(this.tagtree[i]);
}
this.tagtree[i]._filter = params.filter;
}
}
// the tag fields needs to be hold by indices
this.tagfield[i] = field;
this.tag.set(field, new Map());
}
}
}
options.db && this.mount(options.db);
} }
export default Document; Document.prototype.mount = function (db) {
let fields = this.field;
if (this.tag) {
// tag indexes are referenced by field
// move tags to their field indexes respectively
for (let i = 0, field; i < this.tagfield.length; i++) {
field = this.tagfield[i];
let index = this.index.get(field);
if (!index) {
// create raw index when not exists
this.index.set(field, index = new Index({}, this.reg));
// copy and push to the field selection
if (fields === this.field) {
fields = fields.slice(0);
}
// tag indexes also needs to be upgraded to db instances
fields.push(field);
}
// assign reference
index.tag = this.tag.get(field);
}
}
const promises = [],
config = {
db: db.db,
type: db.type,
fastupdate: db.fastupdate
};
// upgrade all indexes to db instances
for (let i = 0, index, field; i < fields.length; i++) {
config.field = field = fields[i];
index = this.index.get(field);
const dbi = new db.constructor(db.id, config);
// take over the storage id
dbi.id = db.id;
promises[i] = dbi.mount(index);
// add an identification property
index.document = !0;
if (i) {
// the register has to export just one time
// also it's needed by the index for ID contain check
index.bypass = !0;
} else {
// the datastore has to export one time
index.store = this.store;
}
}
this.async = !0;
this.db = !0;
return Promise.all(promises);
};
Document.prototype.commit = async function (replace, append) {
// parallel:
const promises = [];
for (const index of this.index.values()) {
promises.push(index.db.commit(index, replace, append));
}
await Promise.all(promises);
this.reg.clear();
// queued:
// for(const index of this.index.values()){
// await index.db.commit(index, replace, append);
// }
// this.reg.clear();
};
/** /**
* @this Document * @this Document
@@ -75,11 +175,10 @@ export default Document;
function parse_descriptor(options, document) { function parse_descriptor(options, document) {
const index = create_object(); const index = new Map();
let field = document.index || document.field || document; let field = document.index || document.field || document;
if (is_string(field)) { if (is_string(field)) {
field = [field]; field = [field];
} }
@@ -88,7 +187,6 @@ function parse_descriptor(options, document) {
key = field[i]; key = field[i];
if (!is_string(key)) { if (!is_string(key)) {
opt = key; opt = key;
key = key.field; key = key.field;
} }
@@ -96,36 +194,55 @@ function parse_descriptor(options, document) {
opt = is_object(opt) ? Object.assign({}, options, opt) : options; opt = is_object(opt) ? Object.assign({}, options, opt) : options;
if (this.worker) { if (this.worker) {
const worker = new WorkerIndex(opt);
index[key] = new WorkerIndex(opt); index.set(key, worker);
if (!worker.worker) {
if (!index[key].worker) { // fallback when not supported
this.worker = !1; this.worker = !1;
} }
} }
if (!this.worker) { if (!this.worker) {
index.set(key, new Index(opt, this.reg));
index[key] = new Index(opt, this.register);
} }
if (opt.custom) {
this.tree[i] = opt.custom;
} else {
this.tree[i] = parse_tree(key, this.marker); this.tree[i] = parse_tree(key, this.marker);
if (opt.filter) {
if ("string" == typeof this.tree[i]) {
// it needs an object to put a property to it
this.tree[i] = new String(this.tree[i]);
}
this.tree[i]._filter = opt.filter;
}
}
this.field[i] = key; this.field[i] = key;
} }
if (this.storetree) { if (this.storetree) {
let store = document.store; let stores = document.store;
if (is_string(stores)) stores = [stores];
if (is_string(store)) { for (let i = 0, store, field; i < stores.length; i++) {
store = stores[i];
store = [store]; field = store.field || store;
if (store.custom) {
this.storetree[i] = store.custom;
store.custom._field = field;
} else {
this.storetree[i] = parse_tree(field, this.marker);
if (store.filter) {
if ("string" == typeof this.storetree[i]) {
// it needs an object to put a property to it
this.storetree[i] = new String(this.storetree[i]);
}
this.storetree[i]._filter = store.filter;
}
} }
for (let i = 0; i < store.length; i++) {
this.storetree[i] = parse_tree(store[i], this.marker);
} }
} }
@@ -138,291 +255,57 @@ function parse_tree(key, marker) {
let count = 0; let count = 0;
for (let i = 0; i < tree.length; i++) { for (let i = 0; i < tree.length; i++) {
key = tree[i]; key = tree[i];
// todo apply some indexes e.g. [0], [-1], [0-2]
if (0 <= key.indexOf("[]")) { if ("]" === key[key.length - 1]) {
key = key.substring(0, key.length - 2); key = key.substring(0, key.length - 2);
if (key) { if (key) {
marker[count] = !0; marker[count] = !0;
} }
} }
if (key) { if (key) {
tree[count++] = key; tree[count++] = key;
} }
} }
if (count < tree.length) { if (count < tree.length) {
tree.length = count; tree.length = count;
} }
return 1 < count ? tree : tree[0]; return 1 < count ? tree : tree[0];
} }
// TODO support generic function created from string when tree depth > 1
function parse_simple(obj, tree) {
if (is_string(tree)) {
obj = obj[tree];
} else {
for (let i = 0; obj && i < tree.length; i++) {
obj = obj[tree[i]];
}
}
return obj;
}
// TODO support generic function created from string when tree depth > 1
function store_value(obj, store, tree, pos, key) {
obj = obj[key];
// reached target field
if (pos === tree.length - 1) {
// store target value
store[key] = obj;
} else if (obj) {
if (is_array(obj)) {
store = store[key] = Array(obj.length);
for (let i = 0; i < obj.length; i++) {
// do not increase pos (an array is not a field)
store_value(obj, store, tree, pos, i);
}
} else {
store = store[key] || (store[key] = create_object());
key = tree[++pos];
store_value(obj, store, tree, pos, key);
}
}
}
function add_index(obj, tree, marker, pos, index, id, key, _append) {
obj = obj[key];
if (obj) {
// reached target field
if (pos === tree.length - 1) {
// handle target value
if (is_array(obj)) {
// append array contents so each entry gets a new scoring context
if (marker[pos]) {
for (let i = 0; i < obj.length; i++) {
index.add(id, obj[i], !0, !0);
}
return;
}
// or join array contents and use one scoring context
obj = obj.join(" ");
}
index.add(id, obj, _append, !0);
} else {
if (is_array(obj)) {
for (let i = 0; i < obj.length; i++) {
// do not increase index, an array is not a field
add_index(obj, tree, marker, pos, index, id, i, _append);
}
} else {
key = tree[++pos];
add_index(obj, tree, marker, pos, index, id, key, _append);
}
}
}
}
/**
*
* @param id
* @param content
* @param {boolean=} _append
* @returns {Document|Promise}
*/
Document.prototype.add = function (id, content, _append) {
if (is_object(id)) {
content = id;
id = parse_simple(content, this.key);
}
if (content && (id || 0 === id)) {
if (!_append && this.register[id]) {
return this.update(id, content);
}
for (let i = 0, tree, field; i < this.field.length; i++) {
field = this.field[i];
tree = this.tree[i];
if (is_string(tree)) {
tree = [tree];
}
add_index(content, tree, this.marker, 0, this.index[field], id, tree[0], _append);
}
if (this.tag) {
let tag = parse_simple(content, this.tag),
dupes = create_object();
if (is_string(tag)) {
tag = [tag];
}
for (let i = 0, key, arr; i < tag.length; i++) {
key = tag[i];
if (!dupes[key]) {
dupes[key] = 1;
arr = this.tagindex[key] || (this.tagindex[key] = []);
if (!_append || !arr.includes(id)) {
arr[arr.length] = id;
// add a reference to the register for fast updates
if (this.fastupdate) {
const tmp = this.register[id] || (this.register[id] = []);
tmp[tmp.length] = arr;
}
}
}
}
}
// TODO: how to handle store when appending contents?
if (this.store && (!_append || !this.store[id])) {
let store;
if (this.storetree) {
store = create_object();
for (let i = 0, tree; i < this.storetree.length; i++) {
tree = this.storetree[i];
if (is_string(tree)) {
store[tree] = content[tree];
} else {
store_value(content, store, tree, 0, tree[0]);
}
}
}
this.store[id] = store || content;
}
}
return this;
};
Document.prototype.append = function (id, content) { Document.prototype.append = function (id, content) {
return this.add(id, content, !0); return this.add(id, content, !0);
}; };
Document.prototype.update = function (id, content) { Document.prototype.update = function (id, content) {
return this.remove(id).add(id, content); return this.remove(id).add(id, content);
}; };
Document.prototype.remove = function (id) { Document.prototype.remove = function (id) {
if (is_object(id)) { if (is_object(id)) {
id = parse_simple(id, this.key); id = parse_simple(id, this.key);
} }
if (this.register[id]) { for (const index of this.index.values()) {
index.remove(id, !0);
for (let i = 0; i < this.field.length; i++) {
// workers does not share the register
this.index[this.field[i]].remove(id, !this.worker);
if (this.fastupdate) {
// when fastupdate was enabled all ids are removed
break;
}
} }
if (this.reg.has(id)) {
if (this.tag) { if (this.tag) {
// when fastupdate was enabled all ids are already removed // when fastupdate was enabled all ids are already removed
if (!this.fastupdate) { if (!this.fastupdate) {
for (let field of this.tag.values()) {
for (let item of field) {
const tag = item[0],
ids = item[1],
pos = ids.indexOf(id);
for (let key in this.tagindex) { if (-1 < pos) {
const tag = this.tagindex[key], 1 < ids.length ? ids.splice(pos, 1) : field.delete(tag);
pos = tag.indexOf(id);
if (-1 !== pos) {
if (1 < tag.length) {
tag.splice(pos, 1);
} else {
delete this.tagindex[key];
} }
} }
} }
@@ -430,297 +313,84 @@ Document.prototype.remove = function (id) {
} }
if (this.store) { if (this.store) {
this.store.delete(id);
delete this.store[id];
} }
delete this.register[id]; this.reg.delete(id);
}
// the cache could be used outside the InMemory store
if (this.cache) {
this.cache.remove(id);
} }
return this; return this;
}; };
/** Document.prototype.clear = function () {
* @param {!string|Object} query
* @param {number|Object=} limit
* @param {Object=} options
* @param {Array<Array>=} _resolve For internal use only.
* @returns {Promise|Array}
*/
Document.prototype.search = function (query, limit, options, _resolve) { //const promises = [];
if (!options) { for (const index of this.index.values()) {
// db index will add clear task
index.clear();
// const promise = index.clear();
// if(promise instanceof Promise){
// promises.push(promise);
// }
}
if (!limit && is_object(query)) { if (this.tag) {
for (const tags of this.tag.values()) {
options = /** @type {Object} */query; tags.clear();
query = "";
} else if (is_object(limit)) {
options = /** @type {Object} */limit;
limit = 0;
} }
} }
let result = [], if (this.store) {
result_field = [], this.store.clear();
pluck,
enrich,
field,
tag,
bool,
offset,
count = 0;
if (options) {
if (is_array(options)) {
field = options;
options = null;
} else {
query = options.query || query;
pluck = options.pluck;
field = pluck || options.index || options.field /*|| (is_string(options) && [options])*/;
tag = options.tag;
enrich = this.store && options.enrich;
bool = "and" === options.bool;
limit = options.limit || limit || 100;
offset = options.offset || 0;
if (tag) {
if (is_string(tag)) {
tag = [tag];
} }
// when tags is used and no query was set, return this; /*promises.length
// then just return the tag indexes ? Promise.all(promises)
:*/
if (!query) {
for (let i = 0, res; i < tag.length; i++) {
res = get_tag.call(this, tag[i], limit, offset, enrich);
if (res) {
result[result.length] = res;
count++;
}
}
return count ? result : [];
}
}
if (is_string(field)) {
field = [field];
}
}
}
field || (field = this.field);
bool = bool && (1 < field.length || tag && 1 < tag.length);
const promises = !_resolve && (this.worker || this.async) && [];
// TODO solve this in one loop below
for (let i = 0, res, key, len; i < field.length; i++) {
let field_options;
key = field[i];
if (!is_string(key)) {
field_options = key;
key = field_options.field;
query = field_options.query || query;
limit = field_options.limit || limit;
enrich = field_options.enrich || enrich;
}
if (promises) {
promises[i] = this.index[key].searchAsync(query, limit, field_options || options);
// just collect and continue
continue;
} else if (_resolve) {
res = _resolve[i];
} else {
// inherit options also when search? it is just for laziness, Object.assign() has a cost
res = this.index[key].search(query, limit, field_options || options);
}
len = res && res.length;
if (tag && len) {
const arr = [];
let count = 0;
if (bool) {
// prepare for intersection
arr[0] = [res];
}
for (let y = 0, key, res; y < tag.length; y++) {
key = tag[y];
res = this.tagindex[key];
len = res && res.length;
if (len) {
count++;
arr[arr.length] = bool ? [res] : res;
}
}
if (count) {
if (bool) {
res = intersect(arr, limit || 100, offset || 0);
} else {
res = intersect_union(res, arr);
}
len = res.length;
}
}
if (len) {
result_field[count] = key;
result[count++] = res;
} else if (bool) {
return [];
}
}
if (promises) {
const self = this;
// anyone knows a better workaround of optionally having async promises?
// the promise.all() needs to be wrapped into additional promise,
// otherwise the recursive callback wouldn't run before return
return new Promise(function (resolve) {
Promise.all(promises).then(function (result) {
resolve(self.search(query, limit, options, result));
});
});
}
if (!count) {
// fast path "not found"
return [];
}
if (pluck && (!enrich || !this.store)) {
// fast path optimization
return result[0];
}
for (let i = 0, res; i < result_field.length; i++) {
res = result[i];
if (res.length) {
if (enrich) {
res = apply_enrich.call(this, res);
}
}
if (pluck) {
return res;
}
result[i] = {
field: result_field[i],
result: res
};
}
return result;
}; };
/**
* @this Document
*/
function get_tag(key, limit, offset) {
let res = this.tagindex[key],
len = res && res.length - offset;
}
/**
* @this Document
*/
function apply_enrich(res) {
const arr = Array(res.length);
for (let x = 0, id; x < res.length; x++) {
id = res[x];
arr[x] = {
id: id,
doc: this.store[id]
};
}
return arr;
}
Document.prototype.contain = function (id) { Document.prototype.contain = function (id) {
return !!this.register[id]; if (this.db) {
return this.index.get(this.field[0]).db.has(id);
}
return this.reg.has(id);
};
Document.prototype.cleanup = function () {
for (const index of this.index.values()) {
index.cleanup();
}
return this;
}; };
Document.prototype.get = function (id) { Document.prototype.get = function (id) {
return this.store[id]; if (this.db) {
return this.index.get(this.field[0]).db.enrich(id).then(function (result) {
return result[0] && result[0].doc;
});
}
return this.store.get(id);
}; };
Document.prototype.set = function (id, data) { Document.prototype.set = function (id, store) {
this.store[id] = data; this.store.set(id, store);
return this; return this;
}; };
// todo mo
Document.prototype.searchCache = searchCache; Document.prototype.searchCache = searchCache;

244
dist/module-debug/document/add.js vendored Normal file
View File

@@ -0,0 +1,244 @@
import { create_object, is_array, is_object, is_string, parse_simple } from "../common.js";
import { KeystoreArray } from "../keystore.js";
import Document from "../document.js";
/**
*
* @param id
* @param content
* @param {boolean=} _append
* @returns {Document|Promise}
*/
Document.prototype.add = function (id, content, _append) {
if (is_object(id)) {
content = id;
id = parse_simple(content, this.key);
}
if (content && (id || 0 === id)) {
if (!_append && this.reg.has(id)) {
return this.update(id, content);
}
// this.field does not include db tag indexes
for (let i = 0, tree; i < this.field.length; i++) {
tree = this.tree[i];
const index = this.index.get(this.field[i]);
if ("function" == typeof tree) {
const tmp = tree(content);
if (tmp) {
index.add(id, tmp, /* suggest */ /* append: */!1, /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/);
}
} else {
const filter = tree._filter;
if (filter && !filter(content)) {
continue;
}
if (tree instanceof String) {
tree = ["" + tree];
} else if (is_string(tree)) {
tree = [tree];
}
add_index(content, tree, this.marker, 0, index, id, tree[0], _append);
}
}
if (this.tag) {
//console.log(this.tag, this.tagtree)
for (let x = 0; x < this.tagtree.length; x++) {
let tree = this.tagtree[x],
field = this.tagfield[x],
ref = this.tag.get(field),
dupes = create_object(),
tags;
if ("function" == typeof tree) {
tags = tree(content);
if (!tags) continue;
} else {
const filter = tree._filter;
if (filter && !filter(content)) {
continue;
}
if (tree instanceof String) {
tree = "" + tree;
}
tags = parse_simple(content, tree);
}
if (!ref || !tags) {
ref || console.warn("Tag '" + field + "' was not found");
continue;
}
if (is_string(tags)) {
tags = [tags];
}
for (let i = 0, tag, arr; i < tags.length; i++) {
tag = tags[i];
//console.log(this.tag, tag, key, field)
if (!dupes[tag]) {
dupes[tag] = 1;
let tmp = ref.get(tag);
tmp ? arr = tmp : ref.set(tag, arr = []);
if (!_append || ! /** @type {!Array|KeystoreArray} */arr.includes(id)) {
// auto-upgrade to keystore array if max size exceeded
if (2147483647 === arr.length /*|| !(arr instanceof KeystoreArray)*/) {
const keystore = new KeystoreArray(arr);
if (this.fastupdate) {
for (let value of this.reg.values()) {
if (value.includes(arr)) {
value[value.indexOf(arr)] = keystore;
}
}
}
ref.set(tag, arr = keystore);
}
arr.push(id);
// add a reference to the register for fast updates
if (this.fastupdate) {
const tmp = this.reg.get(id);
tmp ? tmp.push(arr) : this.reg.set(id, [arr]);
}
}
}
}
}
}
if (this.store && (!_append || !this.store.has(id))) {
let payload;
if (this.storetree) {
payload = create_object();
for (let i = 0, tree; i < this.storetree.length; i++) {
tree = this.storetree[i];
const filter = tree._filter;
if (filter && !filter(content)) {
continue;
}
let custom;
if ("function" == typeof tree) {
custom = tree(content);
if (!custom) continue;
tree = [tree._field];
} else if (is_string(tree) || tree instanceof String) {
payload[tree] = content[tree];
continue;
}
store_value(content, payload, tree, 0, tree[0], custom);
}
}
this.store.set(id, payload || content);
}
}
return this;
};
// TODO support generic function created from string when tree depth > 1
/**
* @param obj
* @param store
* @param tree
* @param pos
* @param key
* @param {*=} custom
*/
function store_value(obj, store, tree, pos, key, custom) {
obj = obj[key];
// reached target field
if (pos === tree.length - 1) {
// store target value
store[key] = custom || obj;
} else if (obj) {
if (is_array(obj)) {
store = store[key] = Array(obj.length);
for (let i = 0; i < obj.length; i++) {
// do not increase pos (an array is not a field)
store_value(obj, store, tree, pos, i);
}
} else {
store = store[key] || (store[key] = create_object());
key = tree[++pos];
store_value(obj, store, tree, pos, key);
}
}
}
function add_index(obj, tree, marker, pos, index, id, key, _append) {
if (obj = obj[key]) {
// reached target field
if (pos === tree.length - 1) {
// handle target value
if (is_array(obj)) {
// append array contents so each entry gets a new scoring context
if (marker[pos]) {
for (let i = 0; i < obj.length; i++) {
index.add(id, obj[i], !0, !0);
}
return;
}
// or join array contents and use one scoring context
obj = obj.join(" ");
}
index.add(id, obj, _append, !0);
} else {
if (is_array(obj)) {
for (let i = 0; i < obj.length; i++) {
// do not increase index, an array is not a field
add_index(obj, tree, marker, pos, index, id, i, _append);
}
} else {
key = tree[++pos];
add_index(obj, tree, marker, pos, index, id, key, _append);
}
}
} else {
if (index.db) {
index.remove(id);
}
}
}

442
dist/module-debug/document/search.js vendored Normal file
View File

@@ -0,0 +1,442 @@
import { DocumentSearchOptions } from "../type.js";
import { create_object, is_array, is_object, is_string } from "../common.js";
import { intersect_union } from "../intersect.js";
import Document from "../document.js";
let debug = /* suggest */ /* append: */ /* enrich */!1;
/**
* @param {!string|DocumentSearchOptions} query
* @param {number|DocumentSearchOptions=} limit
* @param {DocumentSearchOptions=} options
* @param {Array<Array>=} _resolve For internal use only.
* @returns {Promise|Array}
*/
Document.prototype.search = function (query, limit, options, _resolve) {
if (!options) {
if (!limit && is_object(query)) {
options = /** @type {DocumentSearchOptions} */query;
query = "";
} else if (is_object(limit)) {
options = /** @type {DocumentSearchOptions} */limit;
limit = 0;
}
}
let result = [],
result_field = [],
pluck,
enrich,
merge,
suggest,
field,
tag,
offset,
count = 0;
if (options) {
// todo remove support?
if (is_array(options)) {
field = options;
options = null;
} else {
query = options.query || query;
pluck = options.pluck;
merge = options.merge;
field = pluck || options.field || options.index;
tag = this.tag && options.tag;
enrich = this.store && options.enrich;
suggest = options.suggest;
limit = options.limit || limit;
offset = options.offset || 0;
limit || (limit = 100);
if (tag && (!this.db || !_resolve)) {
if (tag.constructor !== Array) {
tag = [tag];
}
// Tag-Search
// -----------------------------
let pairs = [];
for (let i = 0, field; i < tag.length; i++) {
field = tag[i];
if (is_string(field)) {
throw new Error("A tag option can't be a string, instead it needs a { field: tag } format.");
}
// default array notation
if (field.field && field.tag) {
const value = field.tag;
if (value.constructor === Array) {
for (let k = 0; k < value.length; k++) {
pairs.push(field.field, value[k]);
}
} else {
pairs.push(field.field, value);
}
}
// shorter object notation
else {
const keys = Object.keys(field);
for (let j = 0, key, value; j < keys.length; j++) {
key = keys[j];
value = field[key];
if (value.constructor === Array) {
for (let k = 0; k < value.length; k++) {
pairs.push(key, value[k]);
}
} else {
pairs.push(key, value);
}
}
}
}
if (!pairs.length) {
throw new Error("Your tag definition within the search options is probably wrong. No valid tags found.");
}
// tag used as pairs from this point
tag = pairs;
// when tags is used and no query was set,
// then just return the tag indexes
if (!query) {
let promises = [];
if (pairs.length) for (let j = 0; j < pairs.length; j += 2) {
let ids;
if (this.db) {
const index = this.index.get(pairs[j]);
if (!index) {
console.warn("Tag '" + pairs[j] + ":" + pairs[j + 1] + "' will be skipped because there is no field '" + pairs[j] + "'.");
continue;
}
promises.push(ids = index.db.tag(pairs[j + 1], limit, offset, enrich));
} else {
ids = get_tag.call(this, pairs[j], pairs[j + 1], limit, offset, enrich);
}
result.push({
field: pairs[j],
tag: pairs[j + 1],
result: ids
});
}
if (promises.length) {
return Promise.all(promises).then(function (promises) {
for (let j = 0; j < promises.length; j++) {
result[j].result = promises[j];
}
return result;
});
}
return result;
}
}
// extend to multi field search by default
if (is_string(field)) {
field = [field];
}
}
}
field || (field = this.field);
let promises = !_resolve && (this.worker || this.async) && [],
db_tag_search;
// multi field search
// field could be a custom set of selected fields by this query
// db tag indexes are also included in this field list
for (let i = 0, res, key, len; i < field.length; i++) {
key = field[i];
if (this.db && this.tag) {
// tree is missing when it is a tag-only index (db)
if (!this.tree[i]) {
continue;
}
}
let field_options;
if (!is_string(key)) {
field_options = key;
key = field_options.field;
query = field_options.query || query;
limit = field_options.limit || limit;
//offset = field_options.offset || offset;
suggest = field_options.suggest || suggest;
//enrich = SUPPORT_STORE && this.store && (field_options.enrich || enrich);
}
if (_resolve) {
res = _resolve[i];
} else {
let opt = field_options || options,
index = this.index.get(key);
if (tag) {
if (this.db) {
opt.tag = tag;
db_tag_search = index.db.support_tag_search;
opt.field = field;
}
if (!db_tag_search) {
opt.enrich = !1;
}
}
if (promises) {
promises[i] = index.searchAsync(query, limit, opt);
// restore enrich state
opt && enrich && (opt.enrich = enrich);
// just collect and continue
continue;
} else {
res = index.search(query, limit, opt);
// restore enrich state
opt && enrich && (opt.enrich = enrich);
}
}
len = res && res.length;
// todo when no term was matched but tag was retrieved extend suggestion to tags
// every field has to intersect against all selected tag fields
if (tag && len) {
const arr = [];
let count = 0;
// tags are only applied in resolve phase when it's a db
if (this.db && _resolve) {
if (!db_tag_search) {
// retrieve tag results assigned to it's field
for (let y = field.length; y < _resolve.length; y++) {
let ids = _resolve[y],
len = ids && ids.length;
if (len) {
count++;
arr.push(ids);
} else if (!suggest) {
// no tags found
return result;
}
}
}
} else {
// tag[] are pairs at this line
for (let y = 0, ids, len; y < tag.length; y += 2) {
ids = this.tag.get(tag[y]);
if (!ids) {
console.warn("Tag '" + tag[y] + ":" + tag[y + 1] + "' will be skipped because there is no field '" + tag[y] + "'.");
if (suggest) {
continue;
} else {
return result;
}
}
ids = ids && ids.get(tag[y + 1]);
len = ids && ids.length;
if (len) {
count++;
arr.push(ids);
} else if (!suggest) {
// no tags found
return result;
}
}
}
if (count) {
res = intersect_union(res, arr); // intersect(arr, limit, offset)
len = res.length;
if (!len && !suggest) {
// nothing matched
return result;
}
// move counter back by 1
count--;
}
}
if (len) {
result_field[count] = key;
result.push(res);
count++;
} else if (1 === field.length) {
// fast path: nothing matched
return result;
}
}
if (promises) {
if (this.db) {
// todo when a tag index is never a search index this could be extracted
// push tag promises to the end
if (tag && tag.length && !db_tag_search) {
for (let y = 0; y < tag.length; y += 2) {
// it needs to retrieve data from tag pairs
const index = this.index.get(tag[y]);
if (!index) {
console.warn("Tag '" + tag[y] + ":" + tag[y + 1] + "' was not found because there is no field '" + tag[y] + "'.");
if (suggest) {
continue;
} else {
return result;
}
}
promises.push(index.db.tag(tag[y + 1], limit, offset, !1));
}
}
}
const self = this;
// TODO unroll this recursion
return Promise.all(promises).then(function (result) {
return result.length ? self.search(query, limit, options, /* resolve: */result) : result;
});
}
if (!count) {
return result;
}
if (pluck && (!enrich || !this.store)) {
return result[0];
}
promises = [];
for (let i = 0, res; i < result_field.length; i++) {
res = result[i];
if (enrich && res.length && !res[0].doc) {
if (!this.db) {
if (res.length) {
res = apply_enrich.call(this, res);
}
} else {
promises.push(res = this.index.get(this.field[0]).db.enrich(res));
}
}
if (pluck) {
return res;
}
result[i] = {
field: result_field[i],
result: res
};
}
if (enrich && /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ && this.db && promises.length) {
return Promise.all(promises).then(function (promises) {
for (let j = 0; j < promises.length; j++) {
result[j].result = promises[j];
}
return merge ? merge_fields(result, limit, offset) : result;
});
}
return merge ? merge_fields(result, limit, offset) : result;
};
// todo support Resolver
// todo when searching through multiple fields each term should
// be found at least by one field to get a valid match without
// using suggestion explicitly
function merge_fields(fields, limit) {
const final = [],
set = create_object();
for (let i = 0, field, res; i < fields.length; i++) {
field = fields[i];
res = field.result;
for (let j = 0, id, entry, tmp; j < res.length; j++) {
entry = res[j];
id = entry.id;
tmp = set[id];
if (!tmp) {
// offset was already applied on field indexes
// if(offset){
// offset--;
// continue;
// }
// apply limit from last round, because just fields could
// be pushed without adding new results
if (final.length === limit) {
return final;
}
entry.field = set[id] = [field.field];
final.push(entry);
} else {
tmp.push(field.field);
}
}
}
return final;
}
/**
* @this Document
*/
function get_tag(tag, key, limit, offset) {
let res = this.tag.get(tag);
if (!res) {
console.warn("Tag '" + tag + "' was not found");
return [];
}
res = res && res.get(key);
res && res.length - offset;
}
/**
* @this Document
*/
function apply_enrich(res) {
const arr = Array(res.length);
for (let x = 0, id; x < res.length; x++) {
id = res[x];
arr[x] = {
id: id,
doc: this.store.get(id)
};
}
return arr;
}

568
dist/module-debug/encoder.js vendored Normal file
View File

@@ -0,0 +1,568 @@
import { parse_option } from "./common.js";
/*
Custom Encoder
----------------
// Split a passed string into an Array of words:
function englishEncoder(string){
return string.toLowerCase().split(/[^a-z]+/)
}
// For CJK split a passed string into an Array of chars:
function chineseEncoder(string){
return string.replace(/\s+/, "").split("")
}
// Alternatively do not split the input:
function fixedEncoder(string){
return [string]
}
Built-in Encoder (Workflow)
----------------------------
Pipeline:
1. apply this.normalize: charset normalization:
applied on the whole input string e.g. lowercase,
will also apply on: filter, matcher, stemmer, mapper
2. apply this.split: split input into terms (includes/excludes)
3. apply this.filter (pre-filter)
4. apply this.matcher (replace terms)
5. apply this.stemmer (replace term endings)
6. apply this.filter (post-filter)
7. apply this.mapper (replace chars)
8. apply this.replacer (custom regex)
9. apply this.dedupe (letter deduplication)
10. apply this.finalize
*/
const whitespace = /[^\p{L}\p{N}]+/u,
numeric_split_length = /(\d{3})/g,
numeric_split_prev_char = /(\D)(\d{3})/g,
numeric_split_next_char = /(\d{3})(\D)/g,
normalize = /[\u0300-\u036f]/g,
normalize_mapper = !normalize && new Map([
// Charset Normalization
["ª", "a"], ["²", "2"], ["³", "3"], ["¹", "1"], ["º", "o"], ["¼", "14"], ["½", "12"], ["¾", "34"], ["à", "a"], ["á", "a"], ["â", "a"], ["ã", "a"], ["ä", "a"], ["å", "a"], ["ç", "c"], ["è", "e"], ["é", "e"], ["ê", "e"], ["ë", "e"], ["ì", "i"], ["í", "i"], ["î", "i"], ["ï", "i"], ["ñ", "n"], ["ò", "o"], ["ó", "o"], ["ô", "o"], ["õ", "o"], ["ö", "o"], ["ù", "u"], ["ú", "u"], ["û", "u"], ["ü", "u"], ["ý", "y"], ["ÿ", "y"], ["ā", "a"], ["ă", "a"], ["ą", "a"], ["ć", "c"], ["ĉ", "c"], ["ċ", "c"], ["č", "c"], ["ď", "d"], ["ē", "e"], ["ĕ", "e"], ["ė", "e"], ["ę", "e"], ["ě", "e"], ["ĝ", "g"], ["ğ", "g"], ["ġ", "g"], ["ģ", "g"], ["ĥ", "h"], ["ĩ", "i"], ["ī", "i"], ["ĭ", "i"], ["į", "i"], ["ij", "ij"], ["ĵ", "j"], ["ķ", "k"], ["ĺ", "l"], ["ļ", "l"], ["ľ", "l"], ["ŀ", "l"], ["ń", "n"], ["ņ", "n"], ["ň", "n"], ["ʼn", "n"], ["ō", "o"], ["ŏ", "o"], ["ő", "o"], ["ŕ", "r"], ["ŗ", "r"], ["ř", "r"], ["ś", "s"], ["ŝ", "s"], ["ş", "s"], ["š", "s"], ["ţ", "t"], ["ť", "t"], ["ũ", "u"], ["ū", "u"], ["ŭ", "u"], ["ů", "u"], ["ű", "u"], ["ų", "u"], ["ŵ", "w"], ["ŷ", "y"], ["ź", "z"], ["ż", "z"], ["ž", "z"], ["ſ", "s"], ["ơ", "o"], ["ư", "u"], ["dž", "dz"], ["lj", "lj"], ["nj", "nj"], ["ǎ", "a"], ["ǐ", "i"], ["ǒ", "o"], ["ǔ", "u"], ["ǖ", "u"], ["ǘ", "u"], ["ǚ", "u"], ["ǜ", "u"], ["ǟ", "a"], ["ǡ", "a"], ["ǣ", "ae"], ["æ", "ae"], ["ǽ", "ae"], ["ǧ", "g"], ["ǩ", "k"], ["ǫ", "o"], ["ǭ", "o"], ["ǯ", "ʒ"], ["ǰ", "j"], ["dz", "dz"], ["ǵ", "g"], ["ǹ", "n"], ["ǻ", "a"], ["ǿ", "ø"], ["ȁ", "a"], ["ȃ", "a"], ["ȅ", "e"], ["ȇ", "e"], ["ȉ", "i"], ["ȋ", "i"], ["ȍ", "o"], ["ȏ", "o"], ["ȑ", "r"], ["ȓ", "r"], ["ȕ", "u"], ["ȗ", "u"], ["ș", "s"], ["ț", "t"], ["ȟ", "h"], ["ȧ", "a"], ["ȩ", "e"], ["ȫ", "o"], ["ȭ", "o"], ["ȯ", "o"], ["ȱ", "o"], ["ȳ", "y"], ["ʰ", "h"], ["ʱ", "h"], ["ɦ", "h"], ["ʲ", "j"], ["ʳ", "r"], ["ʴ", "ɹ"], ["ʵ", "ɻ"], ["ʶ", "ʁ"], ["ʷ", "w"], ["ʸ", "y"], ["ˠ", "ɣ"], ["ˡ", "l"], ["ˢ", "s"], ["ˣ", "x"], ["ˤ", "ʕ"], ["ΐ", "ι"], ["ά", "α"], ["έ", "ε"], ["ή", "η"], ["ί", "ι"], ["ΰ", "υ"], ["ϊ", "ι"], ["ϋ", "υ"], ["ό", "ο"], ["ύ", "υ"], ["ώ", "ω"], ["ϐ", "β"], ["ϑ", "θ"], ["ϒ", "Υ"], ["ϓ", "Υ"], ["ϔ", "Υ"], ["ϕ", "φ"], ["ϖ", "π"], ["ϰ", "κ"], ["ϱ", "ρ"], ["ϲ", "ς"], ["ϵ", "ε"], ["й", "и"], ["ѐ", "е"], ["ё", "е"], ["ѓ", "г"], ["ї", "і"], ["ќ", "к"], ["ѝ", "и"], ["ў", "у"], ["ѷ", "ѵ"], ["ӂ", "ж"], ["ӑ", "а"], ["ӓ", "а"], ["ӗ", "е"], ["ӛ", "ә"], ["ӝ", "ж"], ["ӟ", "з"], ["ӣ", "и"], ["ӥ", "и"], ["ӧ", "о"], ["ӫ", "ө"], ["ӭ", "э"], ["ӯ", "у"], ["ӱ", "у"], ["ӳ", "у"], ["ӵ", "ч"]
// Term Separators
// ["'", ""], // it's -> its
// ["´", ""],
// ["`", ""],
// ["", ""],
// ["ʼ", ""],
// Numeric-Separators Chars Removal
// [",", ""],
// [".", ""]
// Non-Whitespace Separators
// already was split by default via p{P}
// ["-", " "],
// [":", " "],
// ["_", " "],
// ["|", " "],
// ["/", " "],
// ["\\", " "]
]); // /[\p{Z}\p{S}\p{P}\p{C}]+/u;
//const numeric_split = /(\d{3})/g;
//.replace(/(\d{3})/g, "$1 ")
//.replace(/([^\d])([\d])/g, "$1 $2")
//.replace(/([\d])([^\d])/g, "$1 $2")
// '´`ʼ.,
/**
* @param options
* @constructor
*/
export default function Encoder(options = {}) {
if (!(this instanceof Encoder)) {
return new Encoder(...arguments);
}
for (let i = 0; i < arguments.length; i++) {
this.assign(arguments[i]);
}
}
Encoder.prototype.assign = function (options) {
// if(options.assign){
// //options = Object.assign({}, options.assign, options);
// this.assign(options.assign);
// }
// let tmp = options["normalize"];
// if(typeof tmp === "function"){
// const old = this.normalize;
// if(typeof old === "function"){
// const current = tmp;
// tmp = function(){
// old();
// current();
// }
// }
// }
/**
* pre-processing string input
* @type {Function|boolean}
*/
this.normalize = /** @type {Function|boolean} */parse_option(options.normalize, /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, this.normalize);
// {
// letter: true,
// number: true,
// whitespace: true,
// symbol: true,
// punctuation: true,
// control: true,
// char: ""
// }
let include = options.include,
tmp = include || options.exclude || options.split;
if ("object" == typeof tmp) {
let numeric = !include,
regex = "";
// split on whitespace by default
options.include || (regex += "\\p{Z}");
if (tmp.letter) {
regex += "\\p{L}";
}
if (tmp.number) {
regex += "\\p{N}";
numeric = !!include;
}
if (tmp.symbol) {
regex += "\\p{S}";
}
if (tmp.punctuation) {
regex += "\\p{P}";
}
if (tmp.control) {
regex += "\\p{C}";
}
if (tmp = tmp.char) {
regex += "object" == typeof tmp ? tmp.join("") : tmp;
}
this.split = new RegExp("[" + (include ? "^" : "") + regex + "]+", "u");
this.numeric = numeric;
} else {
/**
* split string input into terms
* @type {string|RegExp|boolean|null}
*/
this.split = /** @type {string|RegExp|boolean} */parse_option(tmp, whitespace, this.split);
this.numeric = parse_option(this.numeric, !0);
}
/**
* post-processing terms
* @type {Function|null}
*/
this.prepare = /** @type {Function|null} */parse_option(options.prepare, null, this.prepare);
/**
* final processing
* @type {Function|null}
*/
this.finalize = /** @type {Function|null} */parse_option(options.finalize, null, this.finalize);
// options
this.rtl = options.rtl || /* suggest */ /* append: */ /* enrich */!1;
this.dedupe = parse_option(options.dedupe, !0, this.dedupe);
this.filter = parse_option((tmp = options.filter) && new Set(tmp), null, this.filter);
this.matcher = parse_option((tmp = options.matcher) && new Map(tmp), null, this.matcher);
this.mapper = parse_option((tmp = options.mapper) && new Map(tmp), null, this.mapper);
this.stemmer = parse_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer);
this.replacer = parse_option(options.replacer, null, this.replacer);
this.minlength = parse_option(options.minlength, 1, this.minlength);
this.maxlength = parse_option(options.maxlength, 0, this.maxlength);
// minimum required tokenizer by this encoder
//this.tokenize = options["tokenize"] || "";
// auto-balanced cache
this.cache = tmp = parse_option(options.cache, !0, this.cache);
if (tmp) {
this.timer = null;
this.cache_size = "number" == typeof tmp ? tmp : 2e5;
this.cache_enc = new Map();
this.cache_prt = new Map();
this.cache_enc_length = 128;
this.cache_prt_length = 128;
}
// regex temporary state
this.matcher_str = "";
this.matcher_test = null;
this.stemmer_str = "";
this.stemmer_test = null;
// prebuilt
// if(this.filter && this.split){
// for(const key of this.filter){
// const tmp = key.replace(this.split, "");
// if(key !== tmp){
// this.filter.delete(key);
// this.filter.add(tmp);
// }
// }
// }
if (this.matcher) {
for (const key of this.matcher.keys()) {
this.matcher_str += (this.matcher_str ? "|" : "") + key;
}
}
if (this.stemmer) {
for (const key of this.stemmer.keys()) {
this.stemmer_str += (this.stemmer_str ? "|" : "") + key;
}
}
// if(SUPPORT_COMPRESSION){
// this.compression = parse_option(options.compress || options.compression, 0, this.compression);
// if(this.compression && !table){
// table = new Array(radix);
// for(let i = 0; i < radix; i++) table[i] = i + 33;
// table = String.fromCharCode.apply(null, table);
// }
// }
return this;
};
Encoder.prototype.addMatcher = function (match, replace) {
// regex:
if ("object" == typeof match) {
return this.addReplacer(match, replace);
}
// a single char:
if (2 > match.length) {
return this.addMapper(match, replace);
}
this.matcher || (this.matcher = new Map());
this.matcher.set(match, replace);
this.matcher_str += (this.matcher_str ? "|" : "") + match;
this.matcher_test = null; //new RegExp("(" + this.matcher_str + ")");
this.cache && this.invalidate();
return this;
};
Encoder.prototype.addStemmer = function (match, replace) {
this.stemmer || (this.stemmer = new Map());
this.stemmer.set(match, replace);
this.stemmer_str += (this.stemmer_str ? "|" : "") + match;
this.stemmer_test = null; //new RegExp("(" + this.stemmer_str + ")");
this.cache && this.invalidate();
return this;
};
Encoder.prototype.addFilter = function (str) {
this.filter || (this.filter = new Set());
this.filter.add(str);
this.cache && this.invalidate();
return this;
};
Encoder.prototype.addMapper = function (char_match, char_replace) {
// regex:
if ("object" == typeof char_match) {
return this.addReplacer(char_match, char_replace);
}
// not a char:
if (1 < char_match.length) {
return this.addMatcher(char_match, char_replace);
}
this.mapper || (this.mapper = new Map());
this.mapper.set(char_match, char_replace);
this.cache && this.invalidate();
return this;
};
Encoder.prototype.addReplacer = function (match, replace) {
if ("string" == typeof match) match = new RegExp(match, "g");
this.replacer || (this.replacer = []);
this.replacer.push(match, replace || "");
this.cache && this.invalidate();
return this;
};
Encoder.prototype.invalidate = function () {
this.cache_enc.clear();
this.cache_prt.clear();
};
Encoder.prototype.encode = function (str) {
//if(!str) return str;
// todo remove dupe terms
if (this.cache && str.length <= this.cache_enc_length) {
if (this.timer) {
if (this.cache_enc.has(str)) {
return this.cache_enc.get(str);
}
} else {
this.timer = setTimeout(clear, 0, this);
}
}
// 1. apply charset normalization
if (this.normalize) {
if ("function" == typeof this.normalize) {
str = this.normalize(str);
} else if (normalize) {
str = str.normalize("NFKD").replace(normalize, "").toLowerCase();
} else {
str = str.toLowerCase();
this.mapper = this.mapper
// todo replace spread
? new Map([... /** @type {!Iterable} */normalize_mapper, ...this.mapper]) : new Map( /** @type {Map<string,string>} */normalize_mapper);
}
//if(!str) return str;
}
// 2. apply custom encoder (can replace split)
if (this.prepare) {
str = this.prepare(str);
}
// 3. split numbers into triplets
if (this.numeric && 3 < str.length) {
str = str.replace(numeric_split_prev_char, "$1 $2").replace(numeric_split_next_char, "$1 $2").replace(numeric_split_length, "$1 ");
}
// if(this.matcher && (str.length > 1)){
// this.matcher_test || (
// this.matcher_test = new RegExp("(" + this.matcher_str + ")", "g")
// );
// str = str.replace(this.matcher_test, match => this.matcher.get(match));
// }
// if(this.stemmer){
// this.stemmer_test || (
// this.stemmer_test = new RegExp("(?!\\b)(" + this.stemmer_str + ")(\\b|_)", "g")
// );
// str = str.replace(this.stemmer_test, match => this.stemmer.get(match));
// }
const skip = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer);
let final = [],
words = this.split || "" === this.split ? str.split( /** @type {string|RegExp} */this.split) : str;
//[str];
for (let i = 0, word, base; i < words.length; i++) {
// filter empty entries
if (!(word = base = words[i])) {
continue;
}
if (word.length < this.minlength) {
continue;
}
if (skip) {
final.push(word);
continue;
}
// 1. pre-filter before cache
if (this.filter && this.filter.has(word)) {
continue;
}
if (this.cache && word.length <= this.cache_prt_length) {
if (this.timer) {
const tmp = this.cache_prt.get(word);
//if(this.cache_prt.has(word)){
if (tmp || "" === tmp) {
//word = this.cache_prt.get(word);
tmp && final.push(tmp);
//word ? words[i] = word : words.splice(i--, 1);
continue;
}
} else {
this.timer = setTimeout(clear, 0, this);
}
}
let postfilter;
// if(this.normalize === true && normalize){
// word = word.normalize("NFKD").replace(normalize, "");
// postfilter = 1;
// }
// if(this.normalize){
// if(typeof this.normalize === "function"){
// word = this.normalize(word);
// }
// else if(normalize){
// word = word.normalize("NFKD").replace(normalize, "").toLowerCase();
// }
// else{
// word = word.toLowerCase();
// this.mapper = this.mapper
// ? new Map([...normalize_mapper, ...this.mapper])
// : new Map(/** @type {Map<string, string>} */ normalize_mapper);
// }
// postfilter = 1;
// //if(!str) return str;
// }
// 2. apply stemmer after matcher
if (this.stemmer && 2 < word.length) {
// for(const item of this.stemmer){
// const key = item[0];
// const value = item[1];
//
// if(word.length > key.length && word.endsWith(key)){
// word = word.substring(0, word.length - key.length) + value;
// break;
// }
//
// // const position = word.length - key.length;
// // if(position > 0 && word.substring(position) === key){
// // word = word.substring(0, position) + value;
// // break;
// // }
// }
this.stemmer_test || (this.stemmer_test = new RegExp("(?!^)(" + this.stemmer_str + ")$"));
word = word.replace(this.stemmer_test, match => this.stemmer.get(match));
postfilter = 1;
}
// 3. apply matcher
if (this.matcher && 1 < word.length) {
this.matcher_test || (this.matcher_test = new RegExp("(" + this.matcher_str + ")", "g"));
word = word.replace(this.matcher_test, match => this.matcher.get(match));
postfilter = 1;
}
// 4. post-filter after matcher and stemmer was applied
if (word && postfilter && (word.length < this.minlength || this.filter && this.filter.has(word))) {
word = "";
}
// 5. apply mapper and collapsing
if (word && (this.mapper || this.dedupe && 1 < word.length)) {
//word = this.replace_dedupe(word);
//word = replace_deduped(word, this.mapper, true);
let final = "";
for (let i = 0, prev = "", char, tmp; i < word.length; i++) {
char = word.charAt(i);
if (char !== prev || !this.dedupe) {
tmp = this.mapper && this.mapper.get(char);
if (!tmp && "" !== tmp) final += prev = char;else if ((tmp !== prev || !this.dedupe) && (prev = tmp)) final += tmp;
}
}
word = final;
}
// apply custom regex
if (word && this.replacer) {
for (let i = 0; word && i < this.replacer.length; i += 2) {
word = word.replace(this.replacer[i], this.replacer[i + 1]);
}
}
// slower variants for removing same chars in a row:
//word = word.replace(/([^0-9])\1+/g, "$1");
//word = word.replace(/(.)\1+/g, "$1");
//word = word.replace(/(?<=(.))\1+/g, "");
// if(word){
// words[i] = word;
// }
if (this.cache && base.length <= this.cache_prt_length) {
this.cache_prt.set(base, word);
if (this.cache_prt.size > this.cache_size) {
this.cache_prt.clear();
this.cache_prt_length = 0 | this.cache_prt_length / 1.1;
}
}
//word || words.splice(i--, 1);
word && final.push(word);
}
//words = final;
// else if(this.filter){
// for(let i = 0, word; i < words.length; i++){
// if((word = words[i]) && !this.filter.has(word)){
// //filtered.push(word);
// words.splice(i--, 1);
// }
// }
// }
if (this.finalize) {
final = this.finalize(final) || final;
}
if (this.cache && str.length <= this.cache_enc_length) {
this.cache_enc.set(str, final);
if (this.cache_enc.size > this.cache_size) {
this.cache_enc.clear();
this.cache_enc_length = 0 | this.cache_enc_length / 1.1;
}
}
return final;
};
// Encoder.prototype.compress = function(str) {
//
// //return str;
// //if(!str) return str;
//
// if(SUPPORT_CACHE && this.cache && str.length <= this.cache_prt_length){
// if(this.timer){
// if(this.cache_cmp.has(str)){
// return this.cache_cmp.get(str);
// }
// }
// else{
// this.timer = setTimeout(clear, 0, this);
// }
// }
//
// const result = typeof this.compression === "function"
// ? this.compression(str)
// : hash(str); //window.hash(str);
//
// if(SUPPORT_CACHE && this.cache && str.length <= this.cache_prt_length){
// this.cache_cmp.set(str, result);
// this.cache_cmp.size > this.cache_size &&
// this.cache_cmp.clear();
// }
//
// return result;
// };
// function hash(str){
// return str;
// }
function clear(self) {
self.timer = null;
self.cache_enc.clear();
self.cache_prt.clear();
}

View File

@@ -1,35 +0,0 @@
import { searchCache } from "./cache";
/**
* @constructor
* @abstract
*/
function Engine(index) {
//if(this.constructor === Engine){
if (this instanceof Engine) {
throw new Error("Can't instantiate abstract class!");
}
index.prototype.searchCache = searchCache;
index.prototype.addAsync = addAsync;
index.prototype.appendAsync = appendAsync;
index.prototype.searchAsync = searchAsync;
index.prototype.updateAsync = updateAsync;
index.prototype.removeAsync = removeAsync;
}
Engine.prototype.searchCache = searchCache;
Engine.prototype.addAsync = addAsync;
Engine.prototype.appendAsync = appendAsync;
Engine.prototype.searchAsync = searchAsync;
Engine.prototype.updateAsync = updateAsync;
Engine.prototype.removeAsync = removeAsync;

View File

@@ -1,5 +1,7 @@
export const global_lang = {}; import { create_object } from "./common.js";
export const global_charset = {};
export const global_lang = create_object();
export const global_charset = create_object();
/** /**
* @param {!string} name * @param {!string} name
@@ -7,7 +9,6 @@ export const global_charset = {};
*/ */
export function registerCharset(name, charset) { export function registerCharset(name, charset) {
global_charset[name] = charset; global_charset[name] = charset;
} }
@@ -17,6 +18,5 @@ export function registerCharset(name, charset) {
*/ */
export function registerLanguage(name, lang) { export function registerLanguage(name, lang) {
global_lang[name] = lang; global_lang[name] = lang;
} }

View File

@@ -6,90 +6,152 @@
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
import { IndexInterface } from "./type.js"; import { IndexOptions } from "./type.js";
import { encode as default_encoder } from "./lang/latin/default.js"; import Encoder from "./encoder.js";
import { create_object, create_object_array, concat, sort_by_length_down, is_array, is_string, is_object, parse_option } from "./common.js";
import { pipeline, init_stemmer_or_matcher, init_filter } from "./lang.js";
import { global_lang, global_charset } from "./global.js";
import apply_async from "./async.js";
import { intersect } from "./intersect.js";
import Cache, { searchCache } from "./cache.js"; import Cache, { searchCache } from "./cache.js";
import apply_preset from "./preset.js"; import { KeystoreMap, KeystoreSet } from "./keystore.js";
import { is_array, is_string } from "./common.js";
import { exportIndex, importIndex } from "./serialize.js"; import { exportIndex, importIndex } from "./serialize.js";
import { global_lang, global_charset } from "./global.js";
import default_encoder from "./lang/latin/default.js";
import apply_preset from "./preset.js";
import apply_async from "./async.js";
import tick from "./profiler.js";
import "./index/add.js";
import "./index/search.js";
import "./index/remove.js";
/** /**
* @constructor * @constructor
* @implements IndexInterface * @param {IndexOptions|string=} options
* @param {Object=} options * @param {Map|Set|KeystoreSet|KeystoreMap=} _register
* @param {Object=} _register
* @return {Index}
*/ */
function Index(options, _register) { export default function Index(options, _register) {
if (!(this instanceof Index)) { if (!(this instanceof Index)) {
return new Index(options); return new Index(options);
} }
let charset, lang, tmp;
if (options) { if (options) {
options = apply_preset(options); options = apply_preset(options);
// charset = options.charset;
// // lang = options.lang;
//
// if(is_string(charset)){
//
// if(!charset.includes(":")){
// charset += ":default";
// }
//
// charset = global_charset[charset];
// }
// if(is_string(lang)){
charset = options.charset; //
lang = options.lang; // lang = global_lang[lang];
// }
if (is_string(charset)) {
if (-1 === charset.indexOf(":")) {
charset += ":default";
}
charset = global_charset[charset];
}
if (is_string(lang)) {
lang = global_lang[lang];
}
} else { } else {
options = {}; options = {};
} }
let resolution, // let charset, lang, tmp;
optimize,
context = options.context || {};
this.encode = options.encode || charset && charset.encode || default_encoder; const context = options.context || {},
this.register = _register || create_object(); encoder = options.encode || options.encoder || default_encoder;
this.resolution = resolution = options.resolution || 9;
this.tokenize = tmp = charset && charset.tokenize || options.tokenize || "strict";
this.depth = "strict" === tmp && context.depth;
this.bidirectional = parse_option(context.bidirectional, /* append: */ /* skip update: */ /* skip_update: */!0);
this.optimize = optimize = parse_option(options.optimize, !0);
this.fastupdate = parse_option(options.fastupdate, !0);
this.minlength = options.minlength || 1;
this.boost = options.boost;
// when not using the memory strategy the score array should not pre-allocated to its full length this.encoder = encoder.encode ? encoder : "object" == typeof encoder ? new Encoder(encoder) : { encode: encoder };
this.map = optimize ? create_object_array(resolution) : create_object(); this.compress = options.compress || options.compression || /* suggest */ /* append: */ /* enrich */!1;
this.resolution_ctx = resolution = context.resolution || 1;
this.ctx = optimize ? create_object_array(resolution) : create_object();
this.rtl = charset && charset.rtl || options.rtl;
this.matcher = (tmp = options.matcher || lang && lang.matcher) && init_stemmer_or_matcher(tmp, !1);
this.stemmer = (tmp = options.stemmer || lang && lang.stemmer) && init_stemmer_or_matcher(tmp, !0);
this.filter = (tmp = options.filter || lang && lang.filter) && init_filter(tmp);
this.cache = (tmp = options.cache) && new Cache(tmp);
let tmp;
this.resolution = options.resolution || 9;
this.tokenize = tmp = options.tokenize || "strict";
this.depth = "strict" === tmp && context.depth || 0;
this.bidirectional = !1 !== context.bidirectional;
this.fastupdate = !!options.fastupdate;
this.score = options.score || null;
tmp = options.keystore || 0;
tmp && (this.keystore = tmp);
this.map = tmp ? new KeystoreMap(tmp) : new Map();
this.ctx = tmp ? new KeystoreMap(tmp) : new Map();
this.reg = _register || (this.fastupdate ? tmp ? new KeystoreMap(tmp) : new Map() : tmp ? new KeystoreSet(tmp) : new Set());
this.resolution_ctx = context.resolution || 1;
this.rtl = encoder.rtl || options.rtl || !1;
this.cache = (tmp = options.cache || null) && new Cache(tmp);
this.resolve = !1 !== options.resolve;
if (tmp = options.db) {
this.db = tmp.mount(this);
}
this.commit_auto = !1 !== options.commit;
this.commit_task = [];
this.commit_timer = null;
} }
export default Index; Index.prototype.mount = function (db) {
if (this.commit_timer) {
clearTimeout(this.commit_timer);
this.commit_timer = null;
}
return db.mount(this);
};
Index.prototype.commit = function (replace, append) {
if (this.commit_timer) {
clearTimeout(this.commit_timer);
this.commit_timer = null;
}
return this.db.commit(this, replace, append);
};
// if(SUPPORT_RESOLVER){
// Index.prototype.resolve = function(params){
// return new Resolver(params);
// };
// }
/**
* @param {!Index} self
* @param {boolean=} replace
* @param {boolean=} append
*/
export function autoCommit(self, replace, append) {
if (!self.commit_timer) {
self.commit_timer = setTimeout(function () {
self.commit_timer = null;
self.db.commit(self, replace, append);
}, 0);
}
}
Index.prototype.clear = function () {
//this.map = new Map();
//this.ctx = new Map();
//this.reg = this.fastupdate ? new Map() : new Set();
this.map.clear();
this.ctx.clear();
this.reg.clear();
this.cache && this.cache.clear();
if (this.db) {
this.commit_timer && clearTimeout(this.commit_timer);
this.commit_timer = null;
this.commit_task = [{ clear: /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ }];
//return this.db.clear();
}
return this;
};
//Index.prototype.pipeline = pipeline; //Index.prototype.pipeline = pipeline;
@@ -99,681 +161,68 @@ export default Index;
*/ */
Index.prototype.append = function (id, content) { Index.prototype.append = function (id, content) {
return this.add(id, content, !0); return this.add(id, content, !0);
}; };
// TODO:
// string + number as text
// boolean, null, undefined as ?
/**
* @param {!number|string} id
* @param {!string} content
* @param {boolean=} _append
* @param {boolean=} _skip_update
*/
Index.prototype.add = function (id, content, _append, _skip_update) {
if (content && (id || 0 === id)) {
if (!_skip_update && !_append && this.register[id]) {
return this.update(id, content);
}
content = this.encode("" + content);
const length = content.length;
if (length) {
// check context dupes to skip all contextual redundancy along a document
const dupes_ctx = create_object(),
dupes = create_object(),
depth = this.depth,
resolution = this.resolution;
for (let i = 0; i < length; i++) {
let term = content[this.rtl ? length - 1 - i : i],
term_length = term.length;
// skip dupes will break the context chain
if (term && term_length >= this.minlength && (depth || !dupes[term])) {
let score = get_score(resolution, length, i),
token = "";
switch (this.tokenize) {
case "full":
if (2 < term_length) {
for (let x = 0; x < term_length; x++) {
for (let y = term_length; y > x; y--) {
if (y - x >= this.minlength) {
const partial_score = get_score(resolution, length, i, term_length, x);
token = term.substring(x, y);
this.push_index(dupes, token, partial_score, id, _append);
}
}
}
break;
}
// fallthrough to next case when term length < 3
case "reverse":
// skip last round (this token exist already in "forward")
if (1 < term_length) {
for (let x = term_length - 1; 0 < x; x--) {
token = term[x] + token;
if (token.length >= this.minlength) {
const partial_score = get_score(resolution, length, i, term_length, x);
this.push_index(dupes, token, partial_score, id, _append);
}
}
token = "";
}
// fallthrough to next case to apply forward also
case "forward":
if (1 < term_length) {
for (let x = 0; x < term_length; x++) {
token += term[x];
if (token.length >= this.minlength) {
this.push_index(dupes, token, score, id, _append);
}
}
break;
}
// fallthrough to next case when token has a length of 1
default:
// case "strict":
if (this.boost) {
score = Math.min(0 | score / this.boost(content, term, i), resolution - 1);
}
this.push_index(dupes, term, score, id, _append);
// context is just supported by tokenizer "strict"
if (depth) {
if (1 < length && i < length - 1) {
// check inner dupes to skip repeating words in the current context
const dupes_inner = create_object(),
resolution = this.resolution_ctx,
keyword = term,
size = Math.min(depth + 1, length - i);
dupes_inner[keyword] = 1;
for (let x = 1; x < size; x++) {
term = content[this.rtl ? length - 1 - i - x : i + x];
if (term && term.length >= this.minlength && !dupes_inner[term]) {
dupes_inner[term] = 1;
const context_score = get_score(resolution + (length / 2 > resolution ? 0 : 1), length, i, size - 1, x - 1),
swap = this.bidirectional && term > keyword;
this.push_index(dupes_ctx, swap ? keyword : term, context_score, id, _append, swap ? term : keyword);
}
}
}
}
}
}
}
this.fastupdate || (this.register[id] = 1);
}
}
return this;
};
/**
* @param {number} resolution
* @param {number} length
* @param {number} i
* @param {number=} term_length
* @param {number=} x
* @returns {number}
*/
function get_score(resolution, length, i, term_length, x) {
// console.log("resolution", resolution);
// console.log("length", length);
// console.log("term_length", term_length);
// console.log("i", i);
// console.log("x", x);
// console.log((resolution - 1) / (length + (term_length || 0)) * (i + (x || 0)) + 1);
// the first resolution slot is reserved for the best match,
// when a query matches the first word(s).
// also to stretch score to the whole range of resolution, the
// calculation is shift by one and cut the floating point.
// this needs the resolution "1" to be handled additionally.
// do not stretch the resolution more than the term length will
// improve performance and memory, also it improves scoring in
// most cases between a short document and a long document
return i && 1 < resolution ? length + (term_length || 0) <= resolution ? i + (x || 0) : 0 | (resolution - 1) / (length + (term_length || 0)) * (i + (x || 0)) + 1 : 0;
}
/**
* @private
* @param dupes
* @param value
* @param score
* @param id
* @param {boolean=} append
* @param {string=} keyword
*/
Index.prototype.push_index = function (dupes, value, score, id, append, keyword) {
let arr = keyword ? this.ctx : this.map;
if (!dupes[value] || keyword && !dupes[value][keyword]) {
if (this.optimize) {
arr = arr[score];
}
if (keyword) {
dupes = dupes[value] || (dupes[value] = create_object());
dupes[keyword] = 1;
arr = arr[keyword] || (arr[keyword] = create_object());
} else {
dupes[value] = 1;
}
arr = arr[value] || (arr[value] = []);
if (!this.optimize) {
arr = arr[score] || (arr[score] = []);
}
if (!append || !arr.includes(id)) {
arr[arr.length] = id;
// add a reference to the register for fast updates
if (this.fastupdate) {
const tmp = this.register[id] || (this.register[id] = []);
tmp[tmp.length] = arr;
}
}
}
};
/**
* @param {string|Object} query
* @param {number|Object=} limit
* @param {Object=} options
* @returns {Array<number|string>}
*/
Index.prototype.search = function (query, limit, options) {
if (!options) {
if (!limit && is_object(query)) {
options = /** @type {Object} */query;
query = options.query;
} else if (is_object(limit)) {
options = /** @type {Object} */limit;
}
}
let result = [],
length,
context,
suggest,
offset = 0;
if (options) {
query = options.query || query;
limit = options.limit;
offset = options.offset || 0;
context = options.context;
suggest = options.suggest;
}
if (query) {
query = /** @type {Array} */this.encode("" + query);
length = query.length;
// TODO: solve this in one single loop below
if (1 < length) {
const dupes = create_object(),
query_new = [];
for (let i = 0, count = 0, term; i < length; i++) {
term = query[i];
if (term && term.length >= this.minlength && !dupes[term]) {
// this fast path can just apply when not in memory-optimized mode
if (!this.optimize && !suggest && !this.map[term]) {
// fast path "not found"
return result;
} else {
query_new[count++] = term;
dupes[term] = 1;
}
}
}
query = query_new;
length = query.length;
}
}
if (!length) {
return result;
}
limit || (limit = 100);
let depth = this.depth && 1 < length && !1 !== context,
index = 0,
keyword;
if (depth) {
keyword = query[0];
index = 1;
} else {
if (1 < length) {
query.sort(sort_by_length_down);
}
}
for (let arr, term; index < length; index++) {
term = query[index];
// console.log(keyword);
// console.log(term);
// console.log("");
if (depth) {
arr = this.add_result(result, suggest, limit, offset, 2 === length, term, keyword);
// console.log(arr);
// console.log(result);
// when suggestion enabled just forward keyword if term was found
// as long as the result is empty forward the pointer also
if (!suggest || !1 !== arr || !result.length) {
keyword = term;
}
} else {
arr = this.add_result(result, suggest, limit, offset, 1 === length, term);
}
if (arr) {
return (/** @type {Array<number|string>} */arr
);
}
// apply suggestions on last loop or fallback
if (suggest && index == length - 1) {
let length = result.length;
if (!length) {
if (depth) {
// fallback to non-contextual search when no result was found
depth = 0;
index = -1;
continue;
}
return result;
} else if (1 === length) {
// fast path optimization
return single_result(result[0], limit, offset);
}
}
}
return intersect(result, limit, offset, suggest);
};
/**
* Returns an array when the result is done (to stop the process immediately),
* returns false when suggestions is enabled and no result was found,
* or returns nothing when a set was pushed successfully to the results
*
* @private
* @param {Array} result
* @param {Array} suggest
* @param {number} limit
* @param {number} offset
* @param {boolean} single_term
* @param {string} term
* @param {string=} keyword
* @return {Array<Array<string|number>>|boolean|undefined}
*/
Index.prototype.add_result = function (result, suggest, limit, offset, single_term, term, keyword) {
let word_arr = [],
arr = keyword ? this.ctx : this.map;
if (!this.optimize) {
arr = get_array(arr, term, keyword, this.bidirectional);
}
if (arr) {
let count = 0;
const arr_len = Math.min(arr.length, keyword ? this.resolution_ctx : this.resolution);
// relevance:
for (let x = 0, size = 0, tmp, len; x < arr_len; x++) {
tmp = arr[x];
if (tmp) {
if (this.optimize) {
tmp = get_array(tmp, term, keyword, this.bidirectional);
}
if (offset) {
if (tmp && single_term) {
len = tmp.length;
if (len <= offset) {
offset -= len;
tmp = null;
} else {
tmp = tmp.slice(offset);
offset = 0;
}
}
}
if (tmp) {
// keep score (sparse array):
//word_arr[x] = tmp;
// simplified score order:
word_arr[count++] = tmp;
if (single_term) {
size += tmp.length;
if (size >= limit) {
// fast path optimization
break;
}
}
}
}
}
if (count) {
if (single_term) {
// fast path optimization
// offset was already applied at this point
return single_result(word_arr, limit, 0);
}
result[result.length] = word_arr;
return;
}
}
// return an empty array will stop the loop,
// to prevent stop when using suggestions return a false value
return !suggest && word_arr;
};
function single_result(result, limit, offset) {
if (1 === result.length) {
result = result[0];
} else {
result = concat(result);
}
return offset || result.length > limit ? result.slice(offset, offset + limit) : result;
}
function get_array(arr, term, keyword, bidirectional) {
if (keyword) {
// the frequency of the starting letter is slightly less
// on the last half of the alphabet (m-z) in almost every latin language,
// so we sort downwards (https://en.wikipedia.org/wiki/Letter_frequency)
const swap = bidirectional && term > keyword;
arr = arr[swap ? term : keyword];
arr = arr && arr[swap ? keyword : term];
} else {
arr = arr[term];
}
return arr;
}
Index.prototype.contain = function (id) { Index.prototype.contain = function (id) {
return !!this.register[id]; if (this.db) {
return this.db.has(id);
}
return this.reg.has(id);
}; };
Index.prototype.update = function (id, content) { Index.prototype.update = function (id, content) {
// todo check the async part
if (this.async /*|| (SUPPORT_PERSISTENT && this.db)*/) {
const self = this,
res = this.remove(id);
return res.then ? res.then(() => self.add(id, content)) : this.add(id, content);
}
return this.remove(id).add(id, content); return this.remove(id).add(id, content);
}; };
/**
* @param {boolean=} _skip_deletion
*/
Index.prototype.remove = function (id, _skip_deletion) {
const refs = this.register[id];
if (refs) {
if (this.fastupdate) {
// fast updates performs really fast but did not fully cleanup the key entries
for (let i = 0, tmp; i < refs.length; i++) {
tmp = refs[i];
tmp.splice(tmp.indexOf(id), 1);
}
} else {
remove_index(this.map, id, this.resolution, this.optimize);
if (this.depth) {
remove_index(this.ctx, id, this.resolution_ctx, this.optimize);
}
}
_skip_deletion || delete this.register[id];
if (this.cache) {
this.cache.del(id);
}
}
return this;
};
/** /**
* @param map * @param map
* @param id
* @param res
* @param optimize
* @param {number=} resolution
* @return {number} * @return {number}
*/ */
function remove_index(map, id, res, optimize, resolution) { function cleanup_index(map) {
let count = 0; let count = 0;
if (is_array(map)) { if (is_array(map)) {
for (let i = 0, arr; i < map.length; i++) {
// the first array is the score array in both strategies (arr = map[i]) && (count += arr.length);
if (!resolution) {
resolution = Math.min(map.length, res);
for (let x = 0, arr; x < resolution; x++) {
arr = map[x];
if (arr) {
count = remove_index(arr, id, res, optimize, resolution);
if (!optimize && !count) {
// when not memory optimized the score index should removed
delete map[x];
} }
} } else for (const item of map) {
} const key = item[0],
} else { value = item[1],
tmp = cleanup_index(value);
const pos = map.indexOf(id); tmp ? count += tmp : map.delete(key);
if (-1 !== pos) {
// fast path, when length is 1 or lower then the whole field gets deleted
if (1 < map.length) {
map.splice(pos, 1);
count++;
}
} else {
count++;
}
}
} else {
for (let key in map) {
count = remove_index(map[key], id, res, optimize, resolution);
if (!count) {
delete map[key];
}
}
} }
return count; return count;
} }
Index.prototype.cleanup = function () {
if (!this.fastupdate) {
console.info("Cleanup the index isn't required when not using \"fastupdate\".");
return this;
}
cleanup_index(this.map);
this.depth && cleanup_index(this.ctx);
return this;
};
Index.prototype.searchCache = searchCache; Index.prototype.searchCache = searchCache;

261
dist/module-debug/index/add.js vendored Normal file
View File

@@ -0,0 +1,261 @@
import { create_object } from "../common.js";
import Index, { autoCommit } from "../index.js";
import default_compress from "../compress.js";
import { KeystoreArray } from "../keystore.js";
// TODO:
// string + number as text
// boolean, null, undefined as ?
/**
* @param {!number|string} id
* @param {!string} content
* @param {boolean=} _append
* @param {boolean=} _skip_update
*/
Index.prototype.add = function (id, content, _append, _skip_update) {
if (content && (id || 0 === id)) {
// todo check skip_update
//_skip_update = false;
if (!_skip_update && !_append) {
if (this.reg.has(id)) {
return this.update(id, content);
}
}
// do not force a string as input
// https://github.com/nextapps-de/flexsearch/issues/432
content = this.encoder.encode(content);
const word_length = content.length;
if (word_length) {
// check context dupes to skip all contextual redundancy along a document
const dupes_ctx = create_object(),
dupes = create_object(),
depth = this.depth,
resolution = this.resolution;
for (let i = 0; i < word_length; i++) {
let term = content[this.rtl ? word_length - 1 - i : i],
term_length = term.length;
// skip dupes will break the context chain
if (term_length /*&& (term_length >= this.minlength)*/ && (depth || !dupes[term])) {
let score = this.score ? this.score(content, term, i, null, 0) : get_score(resolution, word_length, i),
token = "";
switch (this.tokenize) {
case "full":
if (2 < term_length) {
for (let x = 0; x < term_length; x++) {
for (let y = term_length; y > x; y--) {
//if((y - x) >= this.minlength){
token = term.substring(x, y);
const partial_score = this.score ? this.score(content, term, i, token, x) : get_score(resolution, word_length, i, term_length, x);
this.push_index(dupes, token, partial_score, id, _append);
//}
}
}
break;
}
// fallthrough to next case when term length < 3
case "reverse":
// skip last round (this token exist already in "forward")
if (1 < term_length) {
for (let x = term_length - 1; 0 < x; x--) {
token = term[x] + token;
//if(token.length >= this.minlength){
const partial_score = this.score ? this.score(content, term, i, token, x) : get_score(resolution, word_length, i, term_length, x);
this.push_index(dupes, token, partial_score, id, _append);
//}
}
token = "";
}
// fallthrough to next case to apply forward also
case "forward":
if (1 < term_length) {
for (let x = 0; x < term_length; x++) {
token += term[x];
//if(token.length >= this.minlength){
this.push_index(dupes, token, score, id, _append);
//}
}
break;
}
// fallthrough to next case when token has a length of 1
default:
// case "strict":
// todo move boost to search
// if(this.boost){
// score = Math.min((score / this.boost(content, term, i)) | 0, resolution - 1);
// }
this.push_index(dupes, term, score, id, _append);
// context is just supported by tokenizer "strict"
if (depth) {
if (1 < word_length && i < word_length - 1) {
// check inner dupes to skip repeating words in the current context
const dupes_inner = create_object(),
resolution = this.resolution_ctx,
keyword = term,
size = Math.min(depth + 1, word_length - i);
dupes_inner[keyword] = 1;
for (let x = 1; x < size; x++) {
term = content[this.rtl ? word_length - 1 - i - x : i + x];
if (term /*&& (term.length >= this.minlength)*/ && !dupes_inner[term]) {
dupes_inner[term] = 1;
const context_score = this.score ? this.score(content, keyword, i, term, x) : get_score(resolution + (word_length / 2 > resolution ? 0 : 1), word_length, i, size - 1, x - 1),
swap = this.bidirectional && term > keyword;
this.push_index(dupes_ctx, swap ? keyword : term, context_score, id, _append, swap ? term : keyword);
}
}
}
}
}
}
}
this.fastupdate || this.reg.add(id);
} else {
content = "";
}
}
if (this.db) {
// when the term has no valid content (e.g. empty),
// then it was not added to the ID registry for removal
content || this.commit_task.push({ del: id });
this.commit_auto && autoCommit(this);
}
return this;
};
/**
* @private
* @param dupes
* @param term
* @param score
* @param id
* @param {boolean=} append
* @param {string=} keyword
*/
Index.prototype.push_index = function (dupes, term, score, id, append, keyword) {
let arr = keyword ? this.ctx : this.map,
tmp;
if (!dupes[term] || !keyword || !(tmp = dupes[term])[keyword]) {
if (keyword) {
dupes = tmp || (dupes[term] = create_object());
dupes[keyword] = 1;
if (this.compress) {
keyword = default_compress(keyword);
}
tmp = arr.get(keyword);
tmp ? arr = tmp : arr.set(keyword, arr = new Map());
} else {
dupes[term] = 1;
}
if (this.compress) {
term = default_compress(term);
}
tmp = arr.get(term);
tmp ? arr = tmp : arr.set(term, arr = tmp = []);
// the ID array will be upgraded dynamically
arr = arr[score] || (arr[score] = []);
if (!append || !arr.includes(id)) {
// auto-upgrade to keystore array if max size exceeded
if (2147483647 === arr.length /*|| !(arr instanceof KeystoreArray)*/) {
const keystore = new KeystoreArray(arr);
if (this.fastupdate) {
for (let value of this.reg.values()) {
if (value.includes(arr)) {
value[value.indexOf(arr)] = keystore;
}
}
}
tmp[score] = arr = keystore;
}
arr.push(id);
// add a reference to the register for fast updates
if (this.fastupdate) {
const tmp = this.reg.get(id);
tmp ? tmp.push(arr) : this.reg.set(id, [arr]);
}
}
}
};
/**
* @param {number} resolution
* @param {number} length
* @param {number} i
* @param {number=} term_length
* @param {number=} x
* @returns {number}
*/
function get_score(resolution, length, i, term_length, x) {
// console.log("resolution", resolution);
// console.log("length", length);
// console.log("term_length", term_length);
// console.log("i", i);
// console.log("x", x);
// console.log((resolution - 1) / (length + (term_length || 0)) * (i + (x || 0)) + 1);
// the first resolution slot is reserved for the best match,
// when a query matches the first word(s).
// also to stretch score to the whole range of resolution, the
// calculation is shift by one and cut the floating point.
// this needs the resolution "1" to be handled additionally.
// do not stretch the resolution more than the term length will
// improve performance and memory, also it improves scoring in
// most cases between a short document and a long document
return i && 1 < resolution ? length + (term_length || 0) <= resolution ? i + (x || 0) : 0 | (resolution - 1) / (length + (term_length || 0)) * (i + (x || 0)) + 1 : 0;
}

137
dist/module-debug/index/remove.js vendored Normal file
View File

@@ -0,0 +1,137 @@
import { create_object, is_array } from "../common.js";
import Index, { autoCommit } from "../index.js";
import default_compress from "../compress.js";
/**
* @param {boolean=} _skip_deletion
*/
Index.prototype.remove = function (id, _skip_deletion) {
const refs = this.reg.size && (this.fastupdate ? this.reg.get(id) : this.reg.has(id));
if (refs) {
if (this.fastupdate) {
// fast updates did not fully cleanup the key entries
for (let i = 0, tmp; i < refs.length; i++) {
if (tmp = refs[i]) {
// todo check
//if(tmp.length < 1) throw new Error("invalid length");
//if(tmp.indexOf(id) < 0) throw new Error("invalid id");
if (2 > tmp.length) {
tmp.pop();
} else {
const index = tmp.indexOf(id);
index === refs.length - 1 ? tmp.pop() : tmp.splice(index, 1);
}
}
}
// todo variation which cleans up, requires to push [ctx, key] instead of arr to the index.reg
// for(let i = 0, arr, term, keyword; i < refs.length; i++){
// arr = refs[i];
// if(typeof arr === "string"){
// arr = this.map.get(term = arr);
// }
// else{
// arr = this.ctx.get(keyword = arr[0]);
// arr && (arr = arr.get(arr[1]));
// }
// let counter = 0, found;
// if(arr && arr.length){
// for(let j = 0, tmp; j < arr.length; j++){
// if((tmp = arr[j])){
// if(!found && tmp.length){
// const index = tmp.indexOf(id);
// if(index >= 0){
// tmp.splice(index, 1);
// // the index [ctx, key]:[res, id] is unique
// found = 1;
// }
// }
// if(tmp.length){
// counter++;
// if(found){
// break;
// }
// }
// else{
// delete arr[j];
// }
// }
// }
// }
// if(!counter){
// keyword
// ? this.ctx.delete(keyword)
// : this.map.delete(term);
// }
// }
} else {
remove_index(this.map, id /*, this.resolution*/);
this.depth && remove_index(this.ctx, id /*, this.resolution_ctx*/);
}
_skip_deletion || this.reg.delete(id);
}
if (this.db) {
this.commit_task.push({ del: id });
this.commit_auto && autoCommit(this);
//return this.db.remove(id);
}
// the cache could be used outside the InMemory store
if (this.cache) {
this.cache.remove(id);
}
return this;
};
/**
* @param map
* @param id
* @return {number}
*/
function remove_index(map, id) {
// a check counter of filled resolution slots
// to prevent removing the field
let count = 0;
if (is_array(map)) {
for (let x = 0, arr, index; x < map.length; x++) {
if ((arr = map[x]) && arr.length) {
index = arr.indexOf(id);
if (0 <= index) {
if (1 < arr.length) {
arr.splice(index, 1);
count++;
} else {
// remove resolution slot
delete map[x];
}
// the index key:[res, id] is unique
break;
} else {
count++;
}
}
}
} else for (let item of map) {
const key = item[0],
value = item[1],
tmp = remove_index(value, id);
tmp ? count += tmp : map.delete(key);
}
return count;
}

432
dist/module-debug/index/search.js vendored Normal file
View File

@@ -0,0 +1,432 @@
import { SearchOptions } from "../type.js";
import { create_object, is_object, sort_by_length_down } from "../common.js";
import Index from "../index.js";
import default_compress from "../compress.js";
import Resolver from "../resolver.js";
import { intersect } from "../intersect.js";
import resolve_default from "../resolve/default.js";
let global_resolve = 1;
export function set_resolve(resolve) {
global_resolve = resolve;
}
/**
* @param {string|SearchOptions} query
* @param {number|SearchOptions=} limit
* @param {SearchOptions=} options
* @returns {Array|Resolver|Promise<Array|Resolver>}
*/
Index.prototype.search = function (query, limit, options) {
if (!options) {
if (!limit && is_object(query)) {
options = /** @type {!SearchOptions} */query;
query = "";
} else if (is_object(limit)) {
options = /** @type {!SearchOptions} */limit;
limit = 0;
}
}
let result = [],
length,
context,
suggest,
offset = 0,
resolve,
enrich,
tag;
if (options) {
query = options.query || query;
limit = options.limit || limit;
offset = options.offset || 0;
context = options.context;
suggest = options.suggest;
resolve = global_resolve &&
/* suggest */ /* append: */ /* enrich */!1 !== options.resolve;
resolve || (global_resolve = 0);
enrich = resolve && options.enrich;
tag = this.db && options.tag;
} else {
resolve = this.resolve || global_resolve;
}
// todo: term deduplication during encoding when context is disabled
// do not force a string as input
// https://github.com/nextapps-de/flexsearch/issues/432
query = /** @type {Array<string>} */this.encoder.encode(query);
length = query.length;
limit || !resolve || (limit = 100);
// fast path single term
if (1 === length) {
return single_term_query.call(this, query[0], // term
"", // ctx
limit, offset, resolve, enrich, tag);
}
// TODO: dedupe terms within encoder?
// TODO: deduplication will break the context chain
context = this.depth && !1 !== context;
// fast path single context
if (2 === length && context && !suggest) {
return single_term_query.call(this, query[0], // term
query[1], // ctx
limit, offset, resolve, enrich, tag);
}
let maxlength = 0,
minlength = 0;
if (1 < length) {
// term deduplication will break the context chain
// todo add context to dupe check
const dupes = create_object(),
query_new = [];
// if(context){
// keyword = query[0];
// dupes[keyword] = 1;
// query_new.push(keyword);
// maxlength = minlength = keyword.length;
// i = 1;
// }
for (let i = 0, term; i < length; i++) {
term = query[i];
if (term && !dupes[term]) {
// todo add keyword check
// this fast path can't apply to persistent indexes
if (!suggest && !this.db && !this.get_array(term /*, keyword*/)) {
// fast path "not found"
return resolve ? result : new Resolver(result);
} else {
query_new.push(term);
dupes[term] = 1;
}
const term_length = term.length;
maxlength = Math.max(maxlength, term_length);
minlength = minlength ? Math.min(minlength, term_length) : term_length;
}
// else if(term && (!this.depth || context === false)){
// query_new.push(term);
// }
}
query = query_new;
length = query.length;
}
// the term length could be changed after deduplication
if (!length) {
return resolve ? result : new Resolver(result);
}
let index = 0,
keyword;
// fast path single term
if (1 === length) {
return single_term_query.call(this, query[0], // term
"", // ctx
limit, offset, resolve, enrich, tag);
}
// fast path single context
if (2 === length && context && !suggest) {
return single_term_query.call(this, query[0], // term
query[1], // ctx
limit, offset, resolve, enrich, tag);
}
if (1 < length) {
if (context) {
// start with context right away
keyword = query[0];
index = 1;
}
// todo
else if (9 < maxlength && 3 < maxlength / minlength) {
// sorting terms will break the context chain
// bigger terms has less occurrence
// this might also reduce the intersection task
// todo check intersection order
query.sort(sort_by_length_down);
}
}
if (this.db) {
if (this.db.search) {
// when the configuration is not supported it returns false
const result = this.db.search(this, query, limit, offset, suggest, resolve, enrich, tag);
if (!1 !== result) return result;
}
const self = this;
return async function () {
for (let arr, term; index < length; index++) {
term = query[index];
if (keyword) {
arr = await self.get_array(term, keyword);
arr = add_result(arr, result, suggest, self.resolution_ctx,
/** @type {!number} */limit, offset, 2 === length
/*, term, keyword*/
);
// the context is a moving window where the keyword is going forward like a cursor
// 1. when suggestion enabled just forward keyword if term was found
// 2. as long as the result is empty forward the pointer also
if (!suggest || !1 !== arr || !result.length) {
keyword = term;
}
} else {
arr = await self.get_array(term);
arr = add_result(arr, result, suggest, self.resolution,
/** @type {!number} */limit, offset, 1 === length
/*, term*/
);
}
// limit reached
if (arr) {
return arr;
}
// apply suggestions on last loop
if (suggest && index == length - 1) {
let length = result.length;
if (!length) {
// fallback to non-contextual search when no result was found
if (keyword) {
keyword = "";
index = -1;
continue;
}
return result;
} else if (1 === length) {
return resolve ? resolve_default(result[0], /** @type {number} */limit, offset) : new Resolver(result[0]);
}
}
}
return resolve ? intersect(result, /** @type {number} */limit, offset, suggest) : new Resolver(result[0]);
}();
}
for (let arr, term; index < length; index++) {
term = query[index];
if (keyword) {
arr = this.get_array(term, keyword);
arr = /*this.*/add_result(arr, result, suggest, this.resolution_ctx,
/** @type {!number} */limit, offset, 2 === length
/*, term, keyword*/
);
// 1. when suggestion enabled just forward keyword if term was found
// 2. as long as the result is empty forward the pointer also
if (!suggest || !1 !== arr || !result.length) {
keyword = term;
}
} else {
arr = this.get_array(term);
arr = /*this.*/add_result(arr, result, suggest, this.resolution,
/** @type {!number} */limit, offset, 1 === length
/*, term*/
);
}
// limit reached
if (arr) {
return (/** @type {Array} */arr
);
}
// apply suggestions on last loop
if (suggest && index == length - 1) {
const length = result.length;
if (!length) {
// fallback to non-contextual search when no result was found
if (keyword) {
keyword = "";
index = -1;
continue;
}
return result;
} else if (1 === length) {
return resolve ? resolve_default(result[0], limit, offset) : new Resolver(result[0]);
}
}
}
return resolve ? intersect(result, limit, offset, suggest) : new Resolver(result[0]);
};
/**
* @param term
* @param keyword
* @param limit
* @param offset
* @param resolve
* @param enrich
* @param tag
* @this Index
* @return {Array|Resolver}
*/
function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) {
const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag);
if (this.db) {
return result.then(function (result) {
if (resolve) return result;
return result && result.length ? resolve ? resolve_default(result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver([]);
});
}
return result && result.length ? resolve ? resolve_default(result, limit, offset) : new Resolver(result) : resolve ? [] : new Resolver([]);
}
/**
* Returns a 1-dimensional finalized array when the result is done (fast path return),
* returns false when suggestions is enabled and no result was found,
* or returns nothing when a set was pushed successfully to the results
*
* @private
* @param {Array} arr
* @param {Array} result
* @param {Array} suggest
* @param {number} resolution
* @param {number} limit
* @param {number} offset
* @param {boolean} single_term
* @return {Array|boolean|undefined}
*/
function add_result(arr, result, suggest, resolution, limit, offset, single_term /*, term, keyword*/) {
let word_arr = [];
//let arr;// = keyword ? this.ctx : this.map;
//arr = this.get_array(term, keyword);
if (arr) {
//const resolution = Math.min(arr.length, keyword ? this.resolution_ctx : this.resolution);
// apply reduced resolution for queries
resolution = Math.min(arr.length, resolution);
for (let x = 0, size = 0, tmp; x < resolution; x++) {
if (tmp = arr[x]) {
if (offset) {
// apply offset right here on single terms
if (tmp && single_term) {
if (tmp.length <= offset) {
offset -= tmp.length;
tmp = null;
} else {
tmp = tmp.slice(offset);
offset = 0;
}
}
}
if (tmp) {
// keep score (sparse array):
word_arr[x] = tmp;
// simplified score order:
//word_arr.push(tmp);
if (single_term) {
size += tmp.length;
if (size >= limit) {
// fast path:
// a single term does not need to pre-collect results
break;
}
}
}
}
}
if (word_arr.length) {
if (single_term) {
// fast path optimization
// offset was already applied at this point
// return an array will stop the query process immediately
return resolve_default(word_arr, limit, 0);
}
result.push(word_arr);
// return nothing will continue the query
return;
}
}
// 1. return an empty array will stop the loop
// 2. return a false value to prevent stop when using suggestions
return !suggest && word_arr;
}
Index.prototype.get_array = function (term, keyword, limit, offset, resolve, enrich, tag) {
let arr, swap;
if (keyword) {
swap = this.bidirectional && term > keyword;
}
if (this.compress) {
term = default_compress(term);
keyword && (keyword = default_compress(keyword));
}
if (this.db) {
return keyword ? this.db.get(swap ? keyword : term, // term
swap ? term : keyword, // ctx
limit, offset, resolve, enrich, tag) : this.db.get(term, "", // ctx
limit, offset, resolve, enrich, tag);
}
if (keyword) {
// the frequency of the starting letter is slightly less
// on the last half of the alphabet (m-z) in almost every latin language,
// so we sort downwards (https://en.wikipedia.org/wiki/Letter_frequency)
arr = this.ctx.get(swap ? term : keyword);
arr = arr && arr.get(swap ? keyword : term);
} else {
arr = this.map.get(term);
}
return arr;
};

View File

@@ -1,4 +1,231 @@
import { create_object, concat } from "./common.js"; import { create_object, concat, sort_by_length_up, get_max_len } from "./common.js";
/*
from -> result[
res[score][id],
res[score][id],
]
to -> [id]
*/
/**
* Implementation based on Object[key] provides better suggestions
* capabilities and has less performance scaling issues on large indexes.
*
* @param arrays
* @param limit
* @param offset
* @param {boolean|Array=} suggest
* @param {boolean=} resolve
* @returns {Array}
*/
export function intersect(arrays, limit, offset, suggest) {
const length = arrays.length;
// todo remove
// if(length < 2){
// throw new Error("Not optimized intersect");
// }
let result = [],
size = 0,
check,
check_suggest,
check_new,
res_arr;
if (suggest) {
suggest = [];
}
// 1. a reversed order prioritize the order of words from a query
// because it ends with the first term.
// 2. process terms in reversed order often has advantage for
// the fast path "end reached".
// alternatively the results could be sorted by length up
//arrays.sort(sort_by_length_up);
// todo the outer loop should be the res array instead of term array,
// this isn't just simple because the intersection calculation needs to reflect this
//const maxlen = get_max_len(arrays);
for (let x = length - 1, found; 0 <= x; x--) {
//for(let x = 0, found; x < length; x++){
res_arr = arrays[x];
check_new = create_object();
found = !check;
// process relevance in forward order (direction is
// important for adding IDs during the last round)
for (let y = 0, ids; y < res_arr.length; y++) {
ids = res_arr[y];
if (!ids || !ids.length) continue;
for (let z = 0, id; z < ids.length; z++) {
id = ids[z];
// check exists starting from the 2nd slot
if (check) {
if (check[id]) {
// check if in last round
if (!x) {
//if(x === length - 1){
if (offset) {
offset--;
} else {
result[size++] = id;
if (size === limit) {
// fast path "end reached"
return result; /*resolve === false
? { result, suggest }
:*/
}
}
}
if (x || suggest) {
//if((x < length - 1) || suggest){
check_new[id] = 1;
}
found = /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/;
}
if (suggest) {
if (!check_suggest[id]) {
check_suggest[id] = 1;
const arr = suggest[y] || (suggest[y] = []);
arr.push(id);
}
// OLD:
//
// check_idx = (check_suggest[id] || 0) + 1;
// check_suggest[id] = check_idx;
//
// // do not adding IDs which are already included in the result (saves one loop)
// // the first intersection match has the check index 2, so shift by -2
//
// if(check_idx < length){
//
// const tmp = suggest[check_idx - 2] || (suggest[check_idx - 2] = []);
// tmp[tmp.length] = id;
// }
}
} else {
// pre-fill in first round
check_new[id] = 1;
}
}
}
if (suggest) {
// re-use the first pre-filled check for suggestions
check || (check_suggest = check_new);
} else if (!found) {
return [];
}
check = check_new;
}
// return intermediate result
// if(resolve === false){
// return { result, suggest };
// }
if (suggest) {
// needs to iterate in reverse direction
for (let x = suggest.length - 1, ids, len; 0 <= x; x--) {
ids = suggest[x];
len = ids.length;
for (let y = 0, id; y < len; y++) {
id = ids[y];
if (!check[id]) {
if (offset) {
offset--;
} else {
result[size++] = id;
if (size === limit) {
// fast path "end reached"
return result;
}
}
check[id] = 1;
}
}
}
}
return result;
}
/**
* @param mandatory
* @param arrays
* @returns {Array}
*/
export function intersect_union(mandatory, arrays) {
const check = create_object(),
union = create_object(),
result = [];
for (let x = 0; x < mandatory.length; x++) {
check[mandatory[x]] = 1;
}
for (let x = 0, arr; x < arrays.length; x++) {
arr = arrays[x];
for (let y = 0, id; y < arr.length; y++) {
id = arr[y];
if (check[id]) {
if (!union[id]) {
union[id] = 1;
result.push(id);
}
}
}
}
return result;
}
/** /**
* Implementation based on Array.includes() provides better performance, * Implementation based on Array.includes() provides better performance,
@@ -193,202 +420,3 @@ import { create_object, concat } from "./common.js";
// //
// return result; // return result;
// } // }
/**
* Implementation based on Object[key] provides better suggestions
* capabilities and has less performance scaling issues on large indexes.
*
* @param arrays
* @param limit
* @param offset
* @param {boolean|Array=} suggest
* @returns {Array}
*/
export function intersect(arrays, limit, offset, suggest) {
const length = arrays.length;
let result = [],
check,
check_suggest,
size = 0;
if (suggest) {
suggest = [];
}
// process terms in reversed order often has advantage for the fast path "end reached".
// also a reversed order prioritize the order of words from a query.
for (let x = length - 1; 0 <= x; x--) {
const word_arr = arrays[x],
word_arr_len = word_arr.length,
check_new = create_object();
let found = !check;
// process relevance in forward order (direction is
// important for adding IDs during the last round)
for (let y = 0; y < word_arr_len; y++) {
const arr = word_arr[y],
arr_len = arr.length;
if (arr_len) {
// loop through IDs
for (let z = 0, check_idx, id; z < arr_len; z++) {
id = arr[z];
if (check) {
if (check[id]) {
// check if in last round
if (!x) {
if (offset) {
offset--;
} else {
result[size++] = id;
if (size === limit) {
// fast path "end reached"
return result;
}
}
}
if (x || suggest) {
check_new[id] = 1;
}
found = /* append: */ /* skip update: */ /* skip_update: */!0;
}
if (suggest) {
check_idx = (check_suggest[id] || 0) + 1;
check_suggest[id] = check_idx;
// do not adding IDs which are already included in the result (saves one loop)
// the first intersection match has the check index 2, so shift by -2
if (check_idx < length) {
const tmp = suggest[check_idx - 2] || (suggest[check_idx - 2] = []);
tmp[tmp.length] = id;
}
}
} else {
// pre-fill in first round
check_new[id] = 1;
}
}
}
}
if (suggest) {
// re-use the first pre-filled check for suggestions
check || (check_suggest = check_new);
} else if (!found) {
return [];
}
check = check_new;
}
if (suggest) {
// needs to iterate in reverse direction
for (let x = suggest.length - 1, arr, len; 0 <= x; x--) {
arr = suggest[x];
len = arr.length;
for (let y = 0, id; y < len; y++) {
id = arr[y];
if (!check[id]) {
if (offset) {
offset--;
} else {
result[size++] = id;
if (size === limit) {
// fast path "end reached"
return result;
}
}
check[id] = 1;
}
}
}
}
return result;
}
/**
* @param mandatory
* @param arrays
* @returns {Array}
*/
export function intersect_union(mandatory, arrays) {
const check = create_object(),
union = create_object(),
result = [];
for (let x = 0; x < mandatory.length; x++) {
check[mandatory[x]] = 1;
}
for (let x = 0, arr; x < arrays.length; x++) {
arr = arrays[x];
for (let y = 0, id; y < arr.length; y++) {
id = arr[y];
if (check[id]) {
if (!union[id]) {
union[id] = 1;
result[result.length] = id;
}
}
}
}
return result;
}

388
dist/module-debug/keystore.js vendored Normal file
View File

@@ -0,0 +1,388 @@
import { create_object } from "./common.js";
/**
* @param bitlength
* @constructor
*/
export function KeystoreObj(bitlength = 8) {
if (!(this instanceof KeystoreObj)) {
return new KeystoreObj(bitlength);
}
this.index = create_object();
this.keys = [];
if (32 < bitlength) {
this.crc = lcg64;
this.bit = BigInt(bitlength);
} else {
this.crc = lcg;
this.bit = bitlength;
}
return (/*this.proxy =*/new Proxy(this, {
get(target, key) {
const address = target.crc(key),
obj = target.index[address];
return obj && obj[key];
},
set(target, key, value) {
const address = target.crc(key);
let obj = target.index[address];
if (!obj) {
target.index[address] = obj = create_object();
target.keys.push(address);
}
obj[key] = value;
return (/* tag? */ /* stringify */
/* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */
// splice:
!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/
);
},
delete(target, key) {
const address = target.crc(key),
obj = target.index[address];
obj && delete obj[key];
return !0;
}
})
);
}
KeystoreObj.prototype.clear = function () {
this.index = create_object();
this.keys = [];
};
// KeystoreObj.prototype.destroy = function(){
// this.index = null;
// this.keys = null;
// this.proxy = null;
// };
function _slice(self, start, end, splice) {
let arr = [];
for (let i = 0, index; i < self.index.length; i++) {
index = self.index[i];
if (start >= index.length) {
start -= index.length;
} else {
const tmp = index[splice ? "splice" : "slice"](start, end),
length = tmp.length;
if (length) {
arr = arr.length ? arr.concat(tmp) : tmp;
end -= length;
if (splice) self.length -= length;
if (!end) break;
}
start = 0;
}
}
return arr;
}
/**
* @param arr
* @constructor
*/
export function KeystoreArray(arr) {
if (!(this instanceof KeystoreArray)) {
return new KeystoreArray(arr);
}
this.index = arr ? [arr] : [];
this.length = arr ? arr.length : 0;
const self = this;
return (/*this.proxy =*/new Proxy([], {
get(target, key) {
if ("length" === key) {
return self.length;
}
if ("push" === key) {
return function (value) {
self.index[self.index.length - 1].push(value);
self.length++;
};
}
if ("pop" === key) {
return function () {
if (self.length) {
self.length--;
return self.index[self.index.length - 1].pop();
}
};
}
if ("indexOf" === key) {
return function (key) {
let index = 0;
for (let i = 0, arr, tmp; i < self.index.length; i++) {
arr = self.index[i];
//if(!arr.includes(key)) continue;
tmp = arr.indexOf(key);
if (0 <= tmp) return index + tmp;
index += arr.length;
}
return -1;
};
}
if ("includes" === key) {
return function (key) {
for (let i = 0; i < self.index.length; i++) {
if (self.index[i].includes(key)) {
return !0;
}
}
return (/* suggest */ /* append: */ /* enrich */!1
);
};
}
if ("slice" === key) {
return function (start, end) {
return _slice(self, start || 0, end || self.length, !1);
};
}
if ("splice" === key) {
return function (start, end) {
return _slice(self, start || 0, end || self.length, !0);
};
}
if ("constructor" === key) {
return Array;
}
if ("symbol" == typeof key /*|| isNaN(key)*/) {
// not supported
return;
}
const arr = self.index[0 | key / 2147483648];
return arr && arr[key];
},
set(target, key, value) {
const index = 0 | key / 2147483648,
arr = self.index[index] || (self.index[index] = []);
arr[key] = value;
self.length++;
return !0;
}
})
);
}
KeystoreArray.prototype.clear = function () {
this.index.length = 0;
};
KeystoreArray.prototype.destroy = function () {
this.index = null;
this.proxy = null;
};
KeystoreArray.prototype.push = function () {};
/**
* @param bitlength
* @constructor
*/
export function KeystoreMap(bitlength = 8) {
if (!(this instanceof KeystoreMap)) {
return new KeystoreMap(bitlength);
}
this.index = create_object();
this.refs = [];
this.size = 0;
if (32 < bitlength) {
this.crc = lcg64;
this.bit = BigInt(bitlength);
} else {
this.crc = lcg;
this.bit = bitlength;
}
}
KeystoreMap.prototype.get = function (key) {
const address = this.crc(key),
map = this.index[address];
return map && map.get(key);
};
KeystoreMap.prototype.set = function (key, value) {
const address = this.crc(key);
let map = this.index[address];
if (map) {
let size = map.size;
map.set(key, value);
size -= map.size;
size && this.size++;
} else {
this.index[address] = map = new Map([[key, value]]);
this.refs.push(map);
}
};
/**
* @param bitlength
* @constructor
*/
export function KeystoreSet(bitlength = 8) {
if (!(this instanceof KeystoreSet)) {
return new KeystoreSet(bitlength);
}
// using plain Object with numeric key access
// just for max performance
this.index = create_object();
this.refs = [];
if (32 < bitlength) {
this.crc = lcg64;
this.bit = BigInt(bitlength);
} else {
this.crc = lcg;
this.bit = bitlength;
}
}
KeystoreSet.prototype.add = function (key) {
const address = this.crc(key);
let set = this.index[address];
if (set) {
let size = set.size;
set.add(key);
size -= set.size;
size && this.size++;
} else {
this.index[address] = set = new Set([key]);
this.refs.push(set);
}
};
KeystoreMap.prototype.has = KeystoreSet.prototype.has = function (key) {
const address = this.crc(key),
map_or_set = this.index[address];
return map_or_set && map_or_set.has(key);
};
/*
KeystoreMap.prototype.size =
KeystoreSet.prototype.size = function(){
let size = 0;
const values = Object.values(this.index);
for(let i = 0; i < values.length; i++){
size += values[i].size;
}
return size;
};
*/
KeystoreMap.prototype.delete = KeystoreSet.prototype.delete = function (key) {
const address = this.crc(key),
map_or_set = this.index[address];
// set && (set.size === 1
// ? this.index.delete(address)
// : set.delete(key));
map_or_set && map_or_set.delete(key) && this.size--;
};
KeystoreMap.prototype.clear = KeystoreSet.prototype.clear = function () {
this.index = create_object();
this.refs = [];
this.size = 0;
};
// KeystoreMap.prototype.destroy =
// KeystoreSet.prototype.destroy = function(){
// this.index = null;
// this.refs = null;
// this.proxy = null;
// };
KeystoreMap.prototype.values = KeystoreSet.prototype.values = function* () {
// alternatively iterate through this.keys[]
//const refs = Object.values(this.index);
for (let i = 0; i < this.refs.length; i++) {
for (let value of this.refs[i].values()) {
yield value;
}
}
};
KeystoreMap.prototype.keys = KeystoreSet.prototype.keys = function* () {
//const values = Object.values(this.index);
for (let i = 0; i < this.refs.length; i++) {
for (let key of this.refs[i].keys()) {
yield key;
}
}
};
KeystoreMap.prototype.entries = KeystoreSet.prototype.entries = function* () {
//const values = Object.values(this.index);
for (let i = 0; i < this.refs.length; i++) {
for (let entry of this.refs[i].entries()) {
yield entry;
}
}
};
/**
* Linear Congruential Generator (LCG)
* @param str
* @this {KeystoreMap|KeystoreSet}
*/
function lcg(str) {
let range = 2 ** this.bit - 1;
if ("number" == typeof str) {
return str & range;
}
let crc = 0,
bit = this.bit + 1;
for (let i = 0; i < str.length; i++) {
crc = (crc * bit ^ str.charCodeAt(i)) & range;
}
// shift Int32 to UInt32 because negative numbers
// extremely slows down key lookup
return 32 === this.bit ? crc + 2147483648 : crc; // & 0xFFFF;
}
/**
* @param str
* @this {KeystoreMap|KeystoreSet}
*/
function lcg64(str) {
let range = BigInt(2) ** /** @type {!BigInt} */this.bit - BigInt(1),
type = typeof str;
if ("bigint" == type) {
return (/** @type {!BigInt} */str & range
);
}
if ("number" == type) {
return BigInt(str) & range;
}
let crc = BigInt(0),
bit = /** @type {!BigInt} */this.bit + BigInt(1);
for (let i = 0; i < str.length; i++) {
crc = (crc * bit ^ BigInt(str.charCodeAt(i))) & range;
}
return crc; // & 0xFFFFFFFFFFFFFFFF;
}

View File

@@ -1,321 +0,0 @@
import { IndexInterface } from "./type.js";
import { create_object, get_keys } from "./common.js";
/**
* @param {!string} str
* @param {boolean|Array<string|RegExp>=} normalize
* @param {boolean|string|RegExp=} split
* @param {boolean=} _collapse
* @returns {string|Array<string>}
* @this IndexInterface
*/
export function pipeline(str, normalize, split, _collapse) {
if (str) {
if (normalize) {
str = replace(str, /** @type {Array<string|RegExp>} */normalize);
}
if (this.matcher) {
str = replace(str, this.matcher);
}
if (this.stemmer && 1 < str.length) {
str = replace(str, this.stemmer);
}
if (_collapse && 1 < str.length) {
str = collapse(str);
}
if (split || "" === split) {
const words = str.split( /** @type {string|RegExp} */split);
return this.filter ? filter(words, this.filter) : words;
}
}
return str;
}
// TODO improve normalize + remove non-delimited chars like in "I'm" + split on whitespace+
export const regex_whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u;
// https://github.com/nextapps-de/flexsearch/pull/414
//export const regex_whitespace = /[\s\xA0\u2000-\u200B\u2028\u2029\u3000\ufeff!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]/
const regex_normalize = /[\u0300-\u036f]/g;
export function normalize(str) {
if (str.normalize) {
str = str.normalize("NFD").replace(regex_normalize, "");
}
return str;
}
/**
* @param {!string} str
* @param {boolean|Array<string|RegExp>=} normalize
* @param {boolean|string|RegExp=} split
* @param {boolean=} _collapse
* @returns {string|Array<string>}
*/
// FlexSearch.prototype.pipeline = function(str, normalize, split, _collapse){
//
// if(str){
//
// if(normalize && str){
//
// str = replace(str, /** @type {Array<string|RegExp>} */ (normalize));
// }
//
// if(str && this.matcher){
//
// str = replace(str, this.matcher);
// }
//
// if(this.stemmer && str.length > 1){
//
// str = replace(str, this.stemmer);
// }
//
// if(_collapse && str.length > 1){
//
// str = collapse(str);
// }
//
// if(str){
//
// if(split || (split === "")){
//
// const words = str.split(/** @type {string|RegExp} */ (split));
//
// return this.filter ? filter(words, this.filter) : words;
// }
// }
// }
//
// return str;
// };
// export function pipeline(str, normalize, matcher, stemmer, split, _filter, _collapse){
//
// if(str){
//
// if(normalize && str){
//
// str = replace(str, normalize);
// }
//
// if(matcher && str){
//
// str = replace(str, matcher);
// }
//
// if(stemmer && str.length > 1){
//
// str = replace(str, stemmer);
// }
//
// if(_collapse && str.length > 1){
//
// str = collapse(str);
// }
//
// if(str){
//
// if(split !== false){
//
// str = str.split(split);
//
// if(_filter){
//
// str = filter(str, _filter);
// }
// }
// }
// }
//
// return str;
// }
/**
* @param {Array<string>} words
* @returns {Object<string, string>}
*/
export function init_filter(words) {
const filter = create_object();
for (let i = 0, length = words.length; i < length; i++) {
filter[words[i]] = 1;
}
return filter;
}
/**
* @param {!Object<string, string>} obj
* @param {boolean} is_stemmer
* @returns {Array}
*/
export function init_stemmer_or_matcher(obj, is_stemmer) {
const keys = get_keys(obj),
length = keys.length,
final = [];
let removal = "",
count = 0;
for (let i = 0, key, tmp; i < length; i++) {
key = keys[i];
tmp = obj[key];
if (tmp) {
final[count++] = regex(is_stemmer ? "(?!\\b)" + key + "(\\b|_)" : key);
final[count++] = tmp;
} else {
removal += (removal ? "|" : "") + key;
}
}
if (removal) {
final[count++] = regex(is_stemmer ? "(?!\\b)(" + removal + ")(\\b|_)" : "(" + removal + ")");
final[count] = "";
}
return final;
}
/**
* @param {!string} str
* @param {Array} regexp
* @returns {string}
*/
export function replace(str, regexp) {
for (let i = 0, len = regexp.length; i < len; i += 2) {
str = str.replace(regexp[i], regexp[i + 1]);
if (!str) {
break;
}
}
return str;
}
/**
* @param {!string} str
* @returns {RegExp}
*/
export function regex(str) {
return new RegExp(str, "g");
}
/**
* Regex: replace(/(?:(\w)(?:\1)*)/g, "$1")
* @param {!string} string
* @returns {string}
*/
export function collapse(string) {
let final = "",
prev = "";
for (let i = 0, len = string.length, char; i < len; i++) {
if ((char = string[i]) !== prev) {
final += prev = char;
}
}
return final;
}
// TODO using fast-swap
export function filter(words, map) {
const length = words.length,
filtered = [];
for (let i = 0, count = 0; i < length; i++) {
const word = words[i];
if (word && !map[word]) {
filtered[count++] = word;
}
}
return filtered;
}
// const chars = {a:1, e:1, i:1, o:1, u:1, y:1};
//
// function collapse_repeating_chars(string){
//
// let collapsed_string = "",
// char_prev = "",
// char_next = "";
//
// for(let i = 0; i < string.length; i++){
//
// const char = string[i];
//
// if(char !== char_prev){
//
// if(i && (char === "h")){
//
// if((chars[char_prev] && chars[char_next]) || (char_prev === " ")){
//
// collapsed_string += char;
// }
// }
// else{
//
// collapsed_string += char;
// }
// }
//
// char_next = (
//
// (i === (string.length - 1)) ?
//
// ""
// :
// string[i + 1]
// );
//
// char_prev = char;
// }
//
// return collapsed_string;
// }

View File

@@ -1,27 +0,0 @@
import { IndexInterface } from "../../type.js";
import { pipeline } from "../../lang.js";
export const rtl = /* append: */ /* skip update: */ /* skip_update: */!0;
export const tokenize = "";
export default {
encode: encode,
rtl: !0
};
const regex = /[\x00-\x7F]+/g,
split = /\s+/;
/**
* @param {string|number} str
* @this IndexInterface
*/
export function encode(str) {
return pipeline.call(this,
/* string: */("" + str).replace(regex, " "),
/* normalize: */
/* collapse: */!1,
/* split: */split, !1);
}

View File

@@ -1,41 +0,0 @@
/**
* http://www.ranks.nl/stopwords
* @type {Array<string>}
*/
export const filter = ["aber", "als", "am", "an", "auch", "auf", "aus", "bei", "bin", "bis", "bist", "da", "dadurch", "daher", "darum", "das", "daß", "dass", "dein", "deine", "dem", "den", "der", "des", "dessen", "deshalb", "die", "dies", "dieser", "dieses", "doch", "dort", "du", "durch", "ein", "eine", "einem", "einen", "einer", "eines", "er", "es", "euer", "eure", "für", "hatte", "hatten", "hattest", "hattet", "hier", "hinter", "ich", "ihr", "ihre", "im", "in", "ist", "ja", "jede", "jedem", "jeden", "jeder", "jedes", "jener", "jenes", "jetzt", "kann", "kannst", "können", "könnt", "machen", "mein", "meine", "mit", "muß", "mußt", "musst", "müssen", "müßt", "nach", "nachdem", "nein", "nicht", "nun", "oder", "seid", "sein", "seine", "sich", "sie", "sind", "soll", "sollen", "sollst", "sollt", "sonst", "soweit", "sowie", "und", "unser", "unsere", "unter", "vom", "von", "vor", "wann", "warum", "was", "weiter", "weitere", "wenn", "wer", "werde", "werden", "werdet", "weshalb", "wie", "wieder", "wieso", "wir", "wird", "wirst", "wo", "woher", "wohin", "zu", "zum", "zur", "über"];
/**
* @type {Object<string, string>}
*/
export const stemmer = {
niss: "",
isch: "",
lich: "",
heit: "",
keit: "",
end: "",
ung: "",
est: "",
ern: "",
em: "",
er: "",
en: "",
es: "",
st: "",
ig: "",
ik: "",
e: "",
s: ""
};
export const matcher = {};
export default {
filter: filter,
stemmer: stemmer,
matcher: matcher
};

View File

@@ -1,26 +0,0 @@
import { IndexInterface } from "../../type.js";
import { pipeline } from "../../lang.js";
export const rtl = /* normalize: */ /* collapse: */
/* normalize: */
/* collapse: */!1;
export const tokenize = "strict";
export default {
encode: encode,
rtl: !1,
tokenize: "strict"
};
const regex = /[\x00-\x7F]+/g;
/**
* @param {string|number} str
* @this IndexInterface
*/
export function encode(str) {
return pipeline.call(this,
/* string: */("" + str).replace(regex, ""), !1,
/* split: */"", !1);
}

View File

@@ -1,27 +0,0 @@
import { IndexInterface } from "../../type.js";
import { pipeline } from "../../lang.js";
export const rtl = /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */
/* normalize: */
/* collapse: */!1;
export const tokenize = "";
export default {
encode: encode,
rtl: !1
};
const regex = /[\x00-\x7F]+/g,
split = /\s+/;
/**
* @param {string|number} str
* @this IndexInterface
*/
export function encode(str) {
return pipeline.call(this,
/* string: */("" + str).replace(regex, " "), !1,
/* split: */split, !1);
}

View File

@@ -2,53 +2,38 @@
* Filter are also known as "stopwords", they completely filter out words from being indexed. * Filter are also known as "stopwords", they completely filter out words from being indexed.
* Source: http://www.ranks.nl/stopwords * Source: http://www.ranks.nl/stopwords
* Object Definition: Just provide an array of words. * Object Definition: Just provide an array of words.
* @type {Array<string>} * @type {Set<string>}
*/ */
export const filter = ["aber", "als", "am", "an", "auch", "auf", "aus", "bei", "bin", "bis", "bist", "da", "dadurch", "daher", "darum", "das", "daß", "dass", "dein", "deine", "dem", "den", "der", "des", "dessen", "deshalb", "die", "dies", "dieser", "dieses", "doch", "dort", "du", "durch", "ein", "eine", "einem", "einen", "einer", "eines", "er", "es", "euer", "eure", "für", "hatte", "hatten", "hattest", "hattet", "hier", "hinter", "ich", "ihr", "ihre", "im", "in", "ist", "ja", "jede", "jedem", "jeden", "jeder", "jedes", "jener", "jenes", "jetzt", "kann", "kannst", "können", "könnt", "machen", "mein", "meine", "mit", "muß", "mußt", "musst", "müssen", "müßt", "nach", "nachdem", "nein", "nicht", "nun", "oder", "seid", "sein", "seine", "sich", "sie", "sind", "soll", "sollen", "sollst", "sollt", "sonst", "soweit", "sowie", "und", "unser", "unsere", "unter", "vom", "von", "vor", "wann", "warum", "was", "weiter", "weitere", "wenn", "wer", "werde", "werden", "werdet", "weshalb", "wie", "wieder", "wieso", "wir", "wird", "wirst", "wo", "woher", "wohin", "zu", "zum", "zur", "über"]; export const filter = new Set(["aber", "als", "am", "an", "auch", "auf", "aus", "bei", "bin", "bis", "bist", "da", "dadurch", "daher", "darum", "das", "dass", "dass", "dein", "deine", "dem", "den", "der", "des", "dessen", "deshalb", "die", "dies", "dieser", "dieses", "doch", "dort", "du", "durch", "ein", "eine", "einem", "einen", "einer", "eines", "er", "es", "euer", "eure", "fuer", "hatte", "hatten", "hattest", "hattet", "hier", "hinter", "ich", "ihr", "ihre", "im", "in", "ist", "ja", "jede", "jedem", "jeden", "jeder", "jedes", "jener", "jenes", "jetzt", "ggf", "kann", "kannst", "koennen", "koennt", "machen", "mein", "meine", "mit", "muss", "musst", "musst", "muessen", "muesst", "nach", "nachdem", "nein", "nicht", "noch", "nun", "oder", "seid", "sein", "seine", "sich", "sie", "sind", "soll", "sollen", "sollst", "sollt", "sonst", "soweit", "sowie", "und", "unser", "unsere", "unter", "usw", "uvm", "vom", "von", "vor", "wann", "warum", "was", "weiter", "weitere", "wenn", "wer", "werde", "werden", "werdet", "weshalb", "wie", "wieder", "wieso", "wir", "wird", "wirst", "wo", "woher", "wohin", "zu", "zum", "zur", "ueber"]);
/** /**
* Stemmer removes word endings and is a kind of "partial normalization". A word ending just matched when the word length is bigger than the matched partial. * Stemmer removes word endings and is a kind of "partial normalization". A word ending just matched when the word length is bigger than the matched partial.
* Example: The word "correct" and "correctness" could be the same word, so you can define {"ness": ""} to normalize the ending. * Example: The word "correct" and "correctness" could be the same word, so you can define {"ness": ""} to normalize the ending.
* Object Definition: the key represents the word ending, the value contains the replacement (or empty string for removal). * Object Definition: the key represents the word ending, the value contains the replacement (or empty string for removal).
* @type {Object<string, string>} * http://snowball.tartarus.org/algorithms/german/stemmer.html
* @type {Map<string>}
*/ */
export const stemmer = { export const stemmer = new Map([["niss", ""], ["isch", ""], ["lich", ""], ["heit", ""], ["keit", ""], ["ell", ""], ["bar", ""], ["end", ""], ["ung", ""], ["est", ""], ["ern", ""], ["em", ""], ["er", ""], ["en", ""], ["es", ""], ["st", ""], ["ig", ""], ["ik", ""], ["e", ""], ["s", ""]]);
niss: "",
isch: "",
lich: "",
heit: "",
keit: "",
ell: "",
bar: "",
end: "",
ung: "",
est: "",
ern: "",
em: "",
er: "",
en: "",
es: "",
st: "",
ig: "",
ik: "",
e: "",
s: ""
};
/** /**
* Matcher replaces all occurrences of a given string regardless of its position and is also a kind of "partial normalization". * Matcher replaces all occurrences of a given string regardless of its position and is also a kind of "partial normalization".
* Object Definition: the key represents the target term, the value contains the search string which should be replaced (could also be an array of multiple terms). * Object Definition: the key represents the target term, the value contains the search string which should be replaced (could also be an array of multiple terms).
* @type {Object<string, Array<string>|string>} * @type {Map<string>}
*/ */
const map = new Map([["_", " "], ["ä", "ae"], ["ö", "oe"], ["ü", "ue"], ["ß", "ss"], ["&", " und "], ["€", " EUR "]]);
export const matcher = {};
export default { export default {
normalize: function (str) {
return str.toLowerCase();
},
prepare: function (str) {
// normalization
if (/[_äöüß&€]/.test(str)) str = str.replace(/[_äöüß&€]/g, match => map.get(match));
// street names
return str.replace(/str\b/g, "strasse").replace(/(?!\b)strasse\b/g, " strasse").replace(/\bst\b/g, "sankt");
},
filter: filter, filter: filter,
stemmer: stemmer, stemmer: stemmer
matcher: matcher
}; };

View File

@@ -1,100 +1,128 @@
/** /**
* http://www.ranks.nl/stopwords * http://www.ranks.nl/stopwords
* @type {Array<string>} * @type {Set<string>}
*/ */
export const filter = ["a", "about", "above", "after", "again", "against", "all", "also", "am", "an", "and", "any", "are", "aren't", "as", "at", // todo filter out minlength
//"back", export const filter = new Set(["a", "about", "above", "after", "again", "against", "all", "also", "am", "an", "and", "any", "are", "arent", "as", "at", "back", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "can", "cannot", "cant", "come", "could", "couldnt",
"be", "because", "been", "before", "being", "below",
//"between",
"both", "but", "by", "can", "cannot", "can't", "come", "could", "couldn't",
//"day", //"day",
"did", "didn't", "do", "does", "doesn't", "doing", "dont", "down", "during", "each", "even", "few", "first", "for", "from", "further", "get", "did", "didnt", "do", "does", "doesnt", "doing", "dont", "down", "during", "each", "even", "few",
//"first",
"for", "from", "further", "get",
//"give", //"give",
"go", "go", "good", "had", "hadnt", "has", "hasnt", "have", "havent", "having", "he", "hed",
//"good",
"had", "hadn't", "has", "hasn't", "have", "haven't", "having", "he", "hed",
//"hell", //"hell",
"her", "here", "here's", "hers", "herself", "hes", "him", "himself", "his", "how", "how's", "i", "id", "if", "ill", "im", "in", "into", "is", "isn't", "it", "it's", "itself", "i've", "just", "know", "let's", "like", "her", "here", "heres", "hers", "herself", "hes", "him", "himself", "his", "how", "hows", "i", "id", "if", "ill", "im", "in", "into", "is", "isnt", "it", "its", "itself", "ive", "just", "know", "lets", "like",
//"look", //"look",
"make", "me", "more", "most", "mustn't", "my", "myself", "new", "no", "nor", "not", "now", "of", "off", "on", "once", "lot", "make", "made", "me", "more", "most", "mustnt", "my", "myself", "new", "no", "nor", "not", "now", "of", "off", "on", "once", "one", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "people", "same", "say", "see", "shant", "she", "shed", "shell", "shes", "should", "shouldnt", "so", "some", "such", "take", "than", "that", "thats", "the", "their", "theirs", "them", "themselves", "then", "there", "theres", "these", "they", "theyd", "theyll", "theyre", "theyve", "think", "this", "those", "through", "time", "times", "to", "too",
//"one",
"only", "or", "other", "ought", "our", "our's", "ourselves", "out", "over", "own",
//"people",
"same", "say", "see", "shan't", "she", "she'd", "shell", "shes", "should", "shouldn't", "so", "some", "such",
//"take",
"than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've",
//"think",
"this", "those", "through", "time", "to", "too",
//"two", //"two",
//"under", "under", "until", "up", "us", "use", "very", "want", "was", "wasnt", "way", "we", "wed", "well", "were", "werent", "weve", "what", "whats", "when", "whens", "where", "wheres", "which", "while", "who", "whom", "whos", "why", "whys", "will", "with", "wont", "work", "would", "wouldnt",
"until", "up", "us",
//"use",
"very", "want", "was", "wasn't", "way", "we", "wed", "well", "were", "weren't", "we've", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "whom", "who's", "why", "why's", "will", "with", "won't",
//"work",
"would", "wouldn't",
//"year", //"year",
"you", "you'd", "you'll", "your", "you're", "your's", "yourself", "yourselves", "you've"]; "ya", "you", "youd", "youll", "your", "youre", "yours", "yourself", "yourselves", "youve"]);
/** /**
* @type {Object<string, string>} * @type {Object<string, string>}
*/ */
export const stemmer = { export const stemmer = new Map([["ational", ""], ["iveness", ""], ["fulness", ""], ["ousness", ""], ["ization", ""], ["tional", ""], ["biliti", ""], ["icate", ""], ["ative", ""], ["alize", ""], ["iciti", ""], ["entli", ""], ["ousli", ""], ["alism", ""], ["ation", ""], ["aliti", ""], ["iviti", ""], ["ement", ""], ["izer", ""], ["able", ""], ["alli", ""], ["ator", ""], ["logi", ""], ["ical", ""], ["ance", ""], ["ence", ""], ["ness", ""], ["ble", ""], ["ment", ""], ["eli", ""], ["bli", ""], ["ful", ""], ["ant", ""], ["ent", ""], ["ism", ""], ["ate", ""], ["iti", ""], ["ous", ""], ["ive", ""], ["ize", ""], ["ing", ""], ["ion", ""], ["al", ""], ["ou", ""], ["er", ""], ["ic", ""], ["ly", ""]]);
ational: "ate", // export const replacer = new Map([
iveness: "ive", // ["&", " and "],
fulness: "ful", // ]);
ousness: "ous",
ization: "ize",
tional: "tion",
biliti: "ble",
icate: "ic",
ative: "",
alize: "al",
iciti: "ic",
entli: "ent",
ousli: "ous",
alism: "al",
ation: "ate",
aliti: "al",
iviti: "ive",
ement: "",
enci: "ence",
anci: "ance",
izer: "ize",
alli: "al",
ator: "ate",
logi: "log",
ical: "ic",
ance: "",
ence: "",
ness: "",
able: "",
ible: "",
ment: "",
eli: "e",
bli: "ble",
ful: "",
ant: "",
ent: "",
ism: "",
ate: "",
iti: "",
ous: "",
ive: "",
ize: "",
al: "",
ou: "",
er: "",
ic: ""
};
export const matcher = {}; /*
hes (= he is / he has)
shes (= she is / she has)
Ill (= I will)
Ive (= I have)
Id (= I would / I had)
dont (= do not)
doesnt (= does not)
didnt (= did not)
isnt (= is not)
hasnt (= has not)
cant (= cannot)
wont (= will not)
*/
// const explode = new Map([
// ["^i'm$", "i am"],
// ["^can't$", "can not"],
// ["^cannot$", "can not"],
// ["^won't$", "will not"],
// ["'s$", " is has"],
// ["n't$", " not"],
// ["'ll$", " will"],
// ["'re$", " are"],
// ["'ve$", " have"],
// ["'d$", " would had"],
// ]);
// const pairs = [
// /´`ʼ/, /´`ʼ/g, "'",
// /_/, /_+/g, " ",
// /&/, /&/g, " and ",
// /\bi'm\b/, /\bi'm\b/g, "i am",
// /\b(can't|cannot)\b/, /\b(can't|cannot)\b/g, "can not",
// /\bwon't\b/, /\bwon't\b/g, "will not",
// /[a-z]n't\b/, /[a-z]n't\b/g, "$1 not",
// /[a-z]'s\b/, /([a-z])'s\b/g, "$1 is has",
// /[a-z]'ll\b/, /[a-z]'ll\b/g, "$1 will",
// /[a-z]'re\b/, /[a-z]'re\b/g, "$1 are",
// /[a-z]'ve\b/, /[a-z]'ve\b/g, "$1 have",
// /[a-z]'d\b/, /[a-z]'d\b/g, "$1 is has"
// ];
// const map = new Map([
// ["´", "'"],
// ["`", "'"],
// ["", "'"],
// ["ʼ", "'"],
// ["_", " "],
// ["&", " and "]
// ]);
export default { export default {
prepare: function (str) {
// if(/[´`ʼ_&]/.test(str))
// str = str.replace(/[´`ʼ_&]/g, match => map.get(match));
// if(/´`ʼ/.test(str))
// str = str.replace(/´`ʼ/g, "'");
// if(/_/.test(str))
// str = str.replace(/_+/g, " ");
// if(/&/.test(str))
// str = str.replace(/&/g, " and ");
// if(/\bi'm\b/.test(str))
// str = str.replace(/\bi'm\b/g, "i am");
// if(/\b(can't|cannot)\b/.test(str))
// str = str.replace(/\b(can't|cannot)\b/g, "can not");
// if(/\bwon't\b/.test(str))
// str = str.replace(/\bwon't\b/g, "will not");
// if(/[a-z]n't\b/.test(str))
// str = str.replace(/([a-z])n't\b/g, "$1 not");
// if(/[a-z]'s\b/.test(str))
// str = str.replace(/([a-z])'s\b/g, "$1 is has");
// if(/[a-z]'ll\b/.test(str))
// str = str.replace(/([a-z])'ll\b/g, "$1 will");
// if(/[a-z]'re\b/.test(str))
// str = str.replace(/([a-z])'re\b/g, "$1 are");
// if(/[a-z]'ve\b/.test(str))
// str = str.replace(/([a-z])'ve\b/g, "$1 have");
// if(/[a-z]'d\b/.test(str))
// str = str.replace(/([a-z])'d\b/g, "$1 would had");
// return str;
return str //.replace(/[´`ʼ_&]/g, match => map.get(match))
// normalization
.replace(/´`ʼ/g, "'").replace(/_+/g, " ").replace(/&/g, " and ")
//.replace(/([0-9 ]|^)\$([0-9 ]|$)/g, "$1 USD $2")
//.replace(/([0-9 ]|^)£([0-9 ]|$)/g, "$1 GBP $2")
.replace(/\$/g, " USD ").replace(/£/g, " GBP ")
// explode short forms
.replace(/([a-z])'s\b/g, "$1 is").replace(/\bi'm\b/g, "i am").replace(/\b(can't|cannot)\b/g, "can not").replace(/\bwon't\b/g, "will not").replace(/([a-z])n't\b/g, "$1 not").replace(/([a-z])'ll\b/g, "$1 will").replace(/([a-z])'re\b/g, "$1 are").replace(/([a-z])'ve\b/g, "$1 have").replace(/([a-z])'d\b/g, "$1 would");
},
filter: filter, filter: filter,
stemmer: stemmer, stemmer: stemmer
matcher: matcher
}; };

21
dist/module-debug/lang/fr.js vendored Normal file
View File

@@ -0,0 +1,21 @@
/**
* http://www.ranks.nl/stopwords
* http://snowball.tartarus.org/algorithms/french/stop.txt
* @type {Set<string>}
*/
export const filter = new Set(["au", "aux", "avec", "ce", "ces", "dans", "de", "des", "du", "elle", "en", "et", "eux", "il", "je", "la", "le", "leur", "lui", "ma", "mais", "me", "meme", "mes", "moi", "mon", "ne", "nos", "notre", "nous", "on", "ou", "par", "pas", "pour", "qu", "que", "qui", "sa", "se", "ses", "son", "sur", "ta", "te", "tes", "toi", "ton", "tu", "un", "une", "vos", "votre", "vous", "c", "d", "j", "l", "m", "n", "s", "t", "a", "y", "ete", "etee", "etees", "etes", "etant", "suis", "es", "est", "sommes", "etes", "sont", "serai", "seras", "sera", "serons", "serez", "seront", "serais", "serait", "serions", "seriez", "seraient", "etais", "etait", "etions", "etiez", "etaient", "fus", "fut", "fumes", "futes", "furent", "sois", "soit", "soyons", "soyez", "soient", "fusse", "fusses", "fut", "fussions", "fussiez", "fussent", "ayant", "eu", "eue", "eues", "eus", "ai", "as", "avons", "avez", "ont", "aurai", "auras", "aura", "aurons", "aurez", "auront", "aurais", "aurait", "aurions", "auriez", "auraient", "avais", "avait", "avions", "aviez", "avaient", "eut", "eumes", "eutes", "eurent", "aie", "aies", "ait", "ayons", "ayez", "aient", "eusse", "eusses", "eut", "eussions", "eussiez", "eussent", "ceci", "cela", "cela", "cet", "cette", "ici", "ils", "les", "leurs", "quel", "quels", "quelle", "quelles", "sans", "soi"]);
/**
* @type {Object<string, string>}
*/
export const stemmer = new Map([["lement", ""], ["ient", ""], ["nera", ""], ["ment", ""], ["ais", ""], ["ait", ""], ["ant", ""], ["ent", ""], ["iez", ""], ["ion", ""], ["nez", ""], ["ai", ""], ["es", ""], ["er", ""], ["ez", ""], ["le", ""], ["na", ""], ["ne", ""], ["a", ""], ["e", ""]]);
export default {
prepare: function (str) {
return str.replace(/´`ʼ/g, "'").replace(/_+/g, " ").replace(/&/g, " et ").replace(/€/g, " EUR ").replace(/\bl'([^\b])/g, "la le $1").replace(/\bt'([^\b])/g, "ta te $1").replace(/\bc'([^\b])/g, "ca ce $1").replace(/\bd'([^\b])/g, "da de $1").replace(/\bj'([^\b])/g, "ja je $1").replace(/\bn'([^\b])/g, "na ne $1").replace(/\bm'([^\b])/g, "ma me $1").replace(/\bs'([^\b])/g, "sa se $1").replace(/\bau\b/g, "a le").replace(/\baux\b/g, "a les").replace(/\bdu\b/g, "de le").replace(/\bdes\b/g, "de les");
},
filter: filter,
stemmer: stemmer
};

View File

@@ -1,89 +1,144 @@
import { IndexInterface } from "../../type.js"; import Encoder from "../../encoder.js";
import { regex, replace, collapse } from "../../lang.js"; import { soundex } from "./balance.js";
import { encode as encode_balance } from "./balance.js";
// const soundex = new Map([
// ["b", "p"],
// //["p", "p"],
//
// //["f", "f"],
// ["v", "f"],
// ["w", "f"],
//
// //["s", "s"],
// ["z", "s"],
// ["x", "s"],
//
// ["d", "t"],
// //["t", "t"],
//
// //["m", "m"],
// ["n", "m"],
//
// //["k", "k"],
// ["c", "k"],
// ["g", "k"],
// ["j", "k"],
// ["q", "k"],
//
// //["r", "r"],
// //["h", "h"],
// //["l", "l"],
//
// //["a", "a"],
//
// //["e", "e"],
// ["i", "e"],
// ["y", "e"],
//
// //["o", "o"],
// ["u", "o"]
// ]);
export const matcher = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]);
export const replacer = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"];
export const rtl = /* normalize: */
/* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */!1;
export const tokenize = "";
export default { export default {
encode: encode, normalize: /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice:
rtl: !1, !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/,
tokenize: "" dedupe: !0,
mapper: soundex,
replacer: replacer,
matcher: matcher
};
// Phonetic Normalization // import { regex, replace, collapse } from "../../lang.js";
// import { encode as encode_balance } from "./balance.js";
};const regex_ae = regex("ae"), //
// export const rtl = false;
//regex_ai = regex("ai"), // export const tokenize = "";
//regex_ay = regex("ay"), // export default {
//regex_ey = regex("ey"), // encode: encode,
regex_oe = regex("oe"), // rtl: rtl,
//regex_ue = regex("ue"), // tokenize: tokenize
//regex_ie = regex("ie"), // }
//regex_sz = regex("sz"), //
//regex_zs = regex("zs"), // // Phonetic Normalization
//regex_ck = regex("ck"), //
//regex_cc = regex("cc"), // const regex_ae = regex("ae"),
regex_sh = regex("sh"), // //regex_ai = regex("ai"),
regex_th = regex("th"), // //regex_ay = regex("ay"),
// //regex_ey = regex("ey"),
//regex_dt = regex("dt"), // regex_oe = regex("oe"),
regex_ph = regex("ph"), // //regex_ue = regex("ue"),
regex_pf = regex("pf"), // //regex_ie = regex("ie"),
pairs = [regex_ae, "a", // //regex_sz = regex("sz"),
// regex_ai, "ei", // //regex_zs = regex("zs"),
// regex_ay, "ei", // //regex_ck = regex("ck"),
// regex_ey, "ei", // //regex_cc = regex("cc"),
regex_oe, "o", // regex_sh = regex("sh"),
// regex_ue, "u", // regex_th = regex("th"),
// regex_ie, "i", // //regex_dt = regex("dt"),
// regex_sz, "s", // regex_ph = regex("ph"),
// regex_zs, "s", // regex_pf = regex("pf");
regex_sh, "s", // //regex_ou = regex("ou"),
// regex_ck, "k", // //regex_uo = regex("uo");
// regex_cc, "k", //
regex_th, "t", // const pairs = [
// regex_dt, "t", // regex_ae, "a",
regex_ph, "f", regex_pf, "f", // // regex_ai, "ei",
// regex_ou, "o", // // regex_ay, "ei",
// regex_uo, "u" // // regex_ey, "ei",
// regex_oe, "o",
// regex("(?![aeiouy])h(?![aeiouy])"), "", // // regex_ue, "u",
// regex("(?!^[aeiouy])h(?!^[aeiouy])"), "" // // regex_ie, "i",
regex("(?![aeo])h(?![aeo])"), "", regex("(?!^[aeo])h(?!^[aeo])"), ""]; // // regex_sz, "s",
//regex_ou = regex("ou"), // // regex_zs, "s",
//regex_uo = regex("uo"); // regex_sh, "s",
// // regex_ck, "k",
/** // // regex_cc, "k",
* @param {string|number} str // regex_th, "t",
* @param {boolean=} _skip_postprocessing // // regex_dt, "t",
* @this IndexInterface // regex_ph, "f",
*/ // regex_pf, "f",
// // regex_ou, "o",
export function encode(str, _skip_postprocessing) { // // regex_uo, "u"
//
if (str) { // // regex("(?![aeiouy])h(?![aeiouy])"), "",
// // regex("(?!^[aeiouy])h(?!^[aeiouy])"), ""
str = encode_balance.call(this, str).join(" "); // regex("(?![aeo])h(?![aeo])"), "",
// regex("(?!^[aeo])h(?!^[aeo])"), ""
if (2 < str.length) { // ];
//
str = replace(str, pairs); // /**
} // * @param {string|number} str
// * @param {boolean=} _skip_postprocessing
if (!_skip_postprocessing) { // */
//
if (1 < str.length) { // export function encode(str, _skip_postprocessing){
//
str = collapse(str); // if(str){
} //
// str = encode_balance.call(this, str).join(" ");
if (str) { //
// if(str.length > 2){
str = str.split(" "); //
} // str = replace(str, pairs);
} // }
} //
// if(!_skip_postprocessing){
return str || []; //
} // if(str.length > 1){
//
// str = collapse(str);
// }
//
// if(str){
//
// str = str.split(" ");
// }
// }
// }
//
// return str || [];
// }

View File

@@ -1,119 +1,279 @@
import { IndexInterface } from "../../type.js"; import Encoder from "../../encoder.js";
import { encode as encode_simple } from "./simple.js";
// custom soundex implementation export const soundex = new Map([["b", "p"],
//["p", "p"],
//["f", "f"],
["v", "f"], ["w", "f"],
//["s", "s"],
["z", "s"], ["x", "s"], ["d", "t"],
//["t", "t"],
//["m", "m"],
["n", "m"],
//["k", "k"],
["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"],
//["r", "r"],
//["h", "h"],
//["l", "l"],
//["a", "a"],
//["e", "e"],
["i", "e"], ["y", "e"],
//["o", "o"],
["u", "o"]]);
export const rtl = /* normalize: */ /* collapse: */
/* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */!1;
export const tokenize = "strict";
export default { export default {
encode: encode, normalize: /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice:
rtl: !1, !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/,
tokenize: "strict" dedupe: !0,
mapper: soundex
//const regex_whitespace = /[\W_]+/g;
};const regex_strip = /[^a-z0-9]+/,
soundex = {
b: "p",
//"p": "p",
//"f": "f",
v: "f", w: "f",
//"s": "s",
z: "s",
x: "s",
ß: "s",
d: "t",
//"t": "t",
//"l": "l",
//"m": "m",
n: "m",
c: "k",
g: "k",
j: "k",
//"k": "k",
q: "k",
//"r": "r",
//"h": "h",
//"a": "a",
//"e": "e",
i: "e",
y: "e",
//"o": "o",
u: "o"
}; };
// const pairs = [ // //import { encode as encode_simple } from "./simple.js";
// regex_whitespace, " ", // import { pipeline } from "../../lang.js";
// regex_strip, "" //
// ]; // // custom soundex implementation
//
// modified // export const rtl = false;
// export const tokenize = "";
/** // export default {
* @param {string|number} str // encode: encode,
* @this IndexInterface // rtl: rtl,
*/ // tokenize: tokenize
// }
export function encode(str) { //
// //const regex_whitespace = /[\W_]+/g;
str = encode_simple.call(this, str).join(" "); // const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u;
// const normalize = "".normalize && /[\u0300-\u036f]/g;
// str = this.pipeline( // //const regex_strip = /[^a-z0-9]+/;
// //
// /* string: */ normalize("" + str).toLowerCase(), // // const pairs = [
// /* normalize: */ false, // // regex_whitespace, " ",
// /* split: */ false, // // regex_strip, ""
// /* collapse: */ false // // ];
// ); //
// // modified
const result = []; // const pairs = new Map([
//
if (str) { // ["b", "p"],
const words = str.split(regex_strip), // //["p", "p"],
length = words.length; //
// //["f", "f"],
// ["v", "f"],
for (let x = 0, tmp, count = 0; x < length; x++) { // ["w", "f"],
//
if ((str = words[x]) && ( /*&& (str.length > 2)*/!this.filter || !this.filter[str])) { // //["s", "s"],
// ["ß", "s"],
tmp = str[0]; // ["z", "s"],
let code = soundex[tmp] || tmp, // ["x", "s"],
previous = code; //str[0]; //
// ["d", "t"],
//soundex[code] || code; // //["t", "t"],
//
for (let i = 1; i < str.length; i++) { // //["m", "m"],
// ["n", "m"],
tmp = str[i]; // ["ñ", "m"],
const current = soundex[tmp] || tmp; //
// //["k", "k"],
if (current && current !== previous) { // ["c", "k"],
// ["ç", "k"],
code += current; // ["g", "k"],
previous = current; // ["j", "k"],
// ["q", "k"],
// if(code.length === 7){ //
// // //["r", "r"],
// break; // //["h", "h"],
// } // //["l", "l"],
} //
} // //["a", "a"],
// ["à", "a"],
result[count++] = code; //(code + "0000").substring(0, 4); // ["á", "a"],
} // ["â", "a"],
} // ["ã", "a"],
} // ["ä", "a"],
// ["å", "a"],
return result; //
} // //["e", "e"],
// ["è", "e"],
// ["é", "e"],
// ["ê", "e"],
// ["ë", "e"],
// ["i", "e"],
// ["ì", "e"],
// ["í", "e"],
// ["î", "e"],
// ["ï", "e"],
// ["y", "e"],
// ["ý", "e"],
// ["ŷ", "e"],
// ["ÿ", "e"],
//
// //["o", "o"],
// ["ò", "o"],
// ["ó", "o"],
// ["ô", "o"],
// ["õ", "o"],
// ["ö", "o"],
// ["ő", "o"],
// ["u", "o"],
// ["ù", "o"],
// ["ú", "o"],
// ["û", "o"],
// ["ü", "o"],
// ["ű", "o"],
// ]);
//
// const map_soundex = new Map([
// ["b", "p"],
// //["p", "p"],
//
// //["f", "f"],
// ["v", "f"],
// ["w", "f"],
//
// //["s", "s"],
// ["z", "s"],
// ["x", "s"],
//
// ["d", "t"],
// //["t", "t"],
//
// //["m", "m"],
// ["n", "m"],
//
// //["k", "k"],
// ["c", "k"],
// ["g", "k"],
// ["j", "k"],
// ["q", "k"],
//
// //["r", "r"],
// //["h", "h"],
// //["l", "l"],
//
// //["a", "a"],
//
// //["e", "e"],
// ["i", "e"],
// ["y", "e"],
//
// //["o", "o"],
// ["u", "o"]
// ]);
// // const soundex = {
// //
// // "b": "p",
// // //"p": "p",
// //
// // //"f": "f",
// // "v": "f",
// // "w": "f",
// //
// // //"s": "s",
// // "z": "s",
// // "x": "s",
// // "ß": "s",
// //
// // "d": "t",
// // //"t": "t",
// //
// // //"l": "l",
// //
// // //"m": "m",
// // "n": "m",
// //
// // "c": "k",
// // "g": "k",
// // "j": "k",
// // //"k": "k",
// // "q": "k",
// //
// // //"r": "r",
// // //"h": "h",
// // //"a": "a",
// //
// // //"e": "e",
// // "i": "e",
// // "y": "e",
// //
// // //"o": "o",
// // "u": "o"
// // };
//
// /**
// * @param {string|number} str
// */
//
// export function encode(str){
//
// return pipeline.call(
// this,
// /* string: */ ("" + str).normalize("NFD").replace(normalize, "").toLowerCase(),
// /* normalize: */ map_soundex,
// /* split: */ whitespace,
// ///* collapse: */ false
// );
//
// // return pipeline.call(
// // this,
// // /* string: */ ("" + str).toLowerCase(),
// // /* normalize: */ /*pairs*/ new Map(),
// // /* split: */ whitespace,
// // ///* collapse: */ false
// // );
//
// // str = encode_simple.call(this, str).join(" ");
// //
// // // str = this.pipeline(
// // //
// // // /* string: */ normalize("" + str).toLowerCase(),
// // // /* normalize: */ false,
// // // /* split: */ false,
// // // /* collapse: */ false
// // // );
// //
// // const result = [];
// //
// // if(str){
// //
// // const words = str.split(regex_strip);
// // const length = words.length;
// //
// // for(let x = 0, tmp, count = 0; x < length; x++){
// //
// // if((str = words[x]) /*&& (str.length > 2)*/ && (!this.filter || !this.filter.has(str))){
// //
// // tmp = str[0];
// // let code = soundex[tmp] || tmp; //str[0];
// // let previous = code; //soundex[code] || code;
// //
// // for(let i = 1; i < str.length; i++){
// //
// // tmp = str[i];
// // const current = soundex[tmp] || tmp;
// //
// // if(current && (current !== previous)){
// //
// // code += current;
// // previous = current;
// //
// // // if(code.length === 7){
// // //
// // // break;
// // // }
// // }
// // }
// //
// // result[count++] = code; //(code + "0000").substring(0, 4);
// // }
// // }
// // }
// //
// // return result;
// }

View File

@@ -1,23 +1,36 @@
import { IndexInterface } from "../../type.js"; import Encoder from "../../encoder.js";
import { pipeline, normalize, regex_whitespace } from "../../lang.js";
export const rtl = /* normalize: */
/* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */
/* normalize: */
/* collapse: */!1;
export const tokenize = "";
export default { export default {
encode: encode, normalize: function (str) {
rtl: !1, return str.toLowerCase();
tokenize: "" },
dedupe: /* suggest */ /* append: */ /* enrich */!1
};
/** // import { pipeline } from "../../lang.js";
* @param {string|number} str //
* @this IndexInterface // const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u;
*/ //
// export const rtl = false;
};export function encode(str) { // export const tokenize = "";
// export default {
return pipeline.call(this, // encode: encode,
/* string: */("" + str).toLowerCase(), !1, /* split: */regex_whitespace, !1); // rtl: rtl,
} // tokenize: tokenize
// }
//
// /**
// * @param {string|number} str
// */
//
// export function encode(str){
//
// return pipeline.call(
//
// this,
// /* string: */ ("" + str).toLowerCase(),
// /* normalize: */ false,
// /* split: */ whitespace,
// /* collapse: */ false
// );
// }

4
dist/module-debug/lang/latin/exact.js vendored Normal file
View File

@@ -0,0 +1,4 @@
export default {
normalize: /* suggest */ /* append: */ /* enrich */!1,
dedupe: !1
};

View File

@@ -1,65 +1,82 @@
import { IndexInterface } from "../../type.js"; import Encoder from "../../encoder.js";
import { regex, replace, collapse } from "../../lang.js"; import { soundex } from "./balance.js";
import { encode as encode_advanced } from "./advanced.js"; import { matcher, replacer } from "./advanced.js";
export const compact = [/(?!^)[aeoy]/g, "" // old: aioy
];
export const rtl = /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */!1;
export const tokenize = "";
export default { export default {
encode: encode, normalize: /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice:
rtl: !1, !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/,
tokenize: "" dedupe: !0,
mapper: soundex,
replacer: replacer.concat(compact),
matcher: matcher
};
// Soundex Normalization // import { regex, replace, collapse } from "../../lang.js";
// import { encode as encode_advanced } from "./advanced.js";
};const prefix = "(?!\\b)", //
//soundex_b = regex(prefix + "p"), // export const rtl = false;
// soundex_s = regex(prefix + "z"), // export const tokenize = "";
// soundex_k = regex(prefix + "[cgq]"), // export default {
// soundex_m = regex(prefix + "n"), // encode: encode,
// soundex_t = regex(prefix + "d"), // rtl: rtl,
// soundex_f = regex(prefix + "[vw]"), // tokenize: tokenize
//regex_vowel = regex(prefix + "[aeiouy]"); // }
regex_vowel = regex("(?!\\b)[aeo]"), //
pairs = [ // // Soundex Normalization
//
// soundex_b, "b", // const prefix = "(?!\\b)";
// soundex_s, "s", // const //soundex_b = regex(prefix + "p"),
// soundex_k, "k", // // soundex_s = regex(prefix + "z"),
// soundex_m, "m", // // soundex_k = regex(prefix + "[cgq]"),
// soundex_t, "t", // // soundex_m = regex(prefix + "n"),
// soundex_f, "f", // // soundex_t = regex(prefix + "d"),
// regex("(?![aeiouy])h(?![aeiouy])"), "", // // soundex_f = regex(prefix + "[vw]"),
// regex("(?!^[aeiouy])h(?!^[aeiouy])"), "", // //regex_vowel = regex(prefix + "[aeiouy]");
regex_vowel, ""]; // regex_vowel = regex(prefix + "[aeo]");
//
// const pairs = [
/** //
* @param {string|number} str // // soundex_b, "b",
* @this IndexInterface // // soundex_s, "s",
*/ // // soundex_k, "k",
// // soundex_m, "m",
export function encode(str) { // // soundex_t, "t",
// // soundex_f, "f",
if (str) { // // regex("(?![aeiouy])h(?![aeiouy])"), "",
// // regex("(?!^[aeiouy])h(?!^[aeiouy])"), "",
str = encode_advanced.call(this, str, /* append: */ /* skip update: */ /* skip_update: */ /* skip post-processing: */!0); // regex_vowel, ""
// ];
if (1 < str.length) { //
// /**
//str = replace(str, pairs); // * @param {string|number} str
str = str.replace(regex_vowel, ""); // */
} //
// export function encode(str){
if (1 < str.length) { //
// if(str){
str = collapse(str); //
} // str = encode_advanced.call(this, str, /* skip post-processing: */ true);
//
if (str) { // if(str.length > 1){
//
str = str.split(" "); // //str = replace(str, pairs);
} // //str = str.replace(regex_vowel, "");
} // str = str.charAt(0) + str.substring(1).replace(regex_vowel, "");
// }
return str || []; //
} // if(str.length > 1){
//
// str = collapse(str);
// }
//
// if(str){
//
// str = str.split(" ");
// }
// }
//
// return str || [];
// }

View File

@@ -1,45 +1,343 @@
import { IndexInterface } from "../../type.js"; import Encoder from "../../encoder.js";
import { pipeline, normalize, regex_whitespace, regex } from "../../lang.js";
export const rtl = /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */
/* collapse: */!1;
export const tokenize = "";
export default { export default {
encode: encode, normalize: /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice:
rtl: !1, !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/,
tokenize: "" dedupe: !0
};
// Charset Normalization // import { pipeline, regex } from "../../lang.js";
//
};const //regex_whitespace = /\W+/, // export const rtl = false;
//regex_strip = regex("[^a-z0-9 ]"), // export const tokenize = "";
regex_a = regex("[àáâãäå]"), // export default {
regex_e = regex("[èéêë]"), // encode: encode,
regex_i = regex("[ìíîï]"), // rtl: rtl,
regex_o = regex("[òóôõöő]"), // tokenize: tokenize
regex_u = regex("[ùúûüű]"), // }
regex_y = regex("[ýŷÿ]"), //
regex_n = regex("ñ"), // // p{Z} = whitespaces
regex_c = regex("[çc]"), // // p{S} = symbols (emotes)
regex_s = regex("ß"), // // p{P} = special chars
regex_and = regex(" & "), // // p{C} = controls (linebreak, tabulator)
pairs = [regex_a, "a", regex_e, "e", regex_i, "i", regex_o, "o", regex_u, "u", regex_y, "y", regex_n, "n", regex_c, "k", regex_s, "s", regex_and, " and " // const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u;
//regex_whitespace, " " // const normalize = "".normalize && /[\u0300-\u036f]/g;
//regex_strip, "" // const pairs = !normalize && new Map([
]; //
// // Charset Normalization
// // String.normalize("NFKD").replace(/[\u0300-\u036f]/g, "")
/** //
* @param {string|number} str // ["ª","a"],
* @this IndexInterface // ["²","2"],
*/ // ["³","3"],
// ["¹","1"],
export function encode(str) { // ["º","o"],
// ["¼","14"],
str = "" + str; // ["½","12"],
// ["¾","34"],
return pipeline.call(this, // ["à","a"],
/* string: */normalize(str).toLowerCase(), // ["á","a"],
/* normalize: */!str.normalize && pairs, // ["â","a"],
/* split: */regex_whitespace, !1); // ["ã","a"],
} // ["ä","a"],
// ["å","a"],
// ["ç","c"],
// ["è","e"],
// ["é","e"],
// ["ê","e"],
// ["ë","e"],
// ["ì","i"],
// ["í","i"],
// ["î","i"],
// ["ï","i"],
// ["ñ","n"],
// ["ò","o"],
// ["ó","o"],
// ["ô","o"],
// ["õ","o"],
// ["ö","o"],
// ["ù","u"],
// ["ú","u"],
// ["û","u"],
// ["ü","u"],
// ["ý","y"],
// ["ÿ","y"],
// ["ā","a"],
// ["ă","a"],
// ["ą","a"],
// ["ć","c"],
// ["ĉ","c"],
// ["ċ","c"],
// ["č","c"],
// ["ď","d"],
// ["ē","e"],
// ["ĕ","e"],
// ["ė","e"],
// ["ę","e"],
// ["ě","e"],
// ["ĝ","g"],
// ["ğ","g"],
// ["ġ","g"],
// ["ģ","g"],
// ["ĥ","h"],
// ["ĩ","i"],
// ["ī","i"],
// ["ĭ","i"],
// ["į","i"],
// ["ij","ij"],
// ["ĵ","j"],
// ["ķ","k"],
// ["ĺ","l"],
// ["ļ","l"],
// ["ľ","l"],
// ["ŀ","l"],
// ["ń","n"],
// ["ņ","n"],
// ["ň","n"],
// ["ʼn","n"],
// ["ō","o"],
// ["ŏ","o"],
// ["ő","o"],
// ["ŕ","r"],
// ["ŗ","r"],
// ["ř","r"],
// ["ś","s"],
// ["ŝ","s"],
// ["ş","s"],
// ["š","s"],
// ["ţ","t"],
// ["ť","t"],
// ["ũ","u"],
// ["ū","u"],
// ["ŭ","u"],
// ["ů","u"],
// ["ű","u"],
// ["ų","u"],
// ["ŵ","w"],
// ["ŷ","y"],
// ["ź","z"],
// ["ż","z"],
// ["ž","z"],
// ["ſ","s"],
// ["ơ","o"],
// ["ư","u"],
// ["dž","dz"],
// ["lj","lj"],
// ["nj","nj"],
// ["ǎ","a"],
// ["ǐ","i"],
// ["ǒ","o"],
// ["ǔ","u"],
// ["ǖ","u"],
// ["ǘ","u"],
// ["ǚ","u"],
// ["ǜ","u"],
// ["ǟ","a"],
// ["ǡ","a"],
// ["ǣ","ae"],
// ["æ","ae"],
// ["ǽ","ae"],
// ["ǧ","g"],
// ["ǩ","k"],
// ["ǫ","o"],
// ["ǭ","o"],
// ["ǯ","ʒ"],
// ["ǰ","j"],
// ["dz","dz"],
// ["ǵ","g"],
// ["ǹ","n"],
// ["ǻ","a"],
// ["ǿ","ø"],
// ["ȁ","a"],
// ["ȃ","a"],
// ["ȅ","e"],
// ["ȇ","e"],
// ["ȉ","i"],
// ["ȋ","i"],
// ["ȍ","o"],
// ["ȏ","o"],
// ["ȑ","r"],
// ["ȓ","r"],
// ["ȕ","u"],
// ["ȗ","u"],
// ["ș","s"],
// ["ț","t"],
// ["ȟ","h"],
// ["ȧ","a"],
// ["ȩ","e"],
// ["ȫ","o"],
// ["ȭ","o"],
// ["ȯ","o"],
// ["ȱ","o"],
// ["ȳ","y"],
// ["ʰ","h"],
// ["ʱ","h"],
// ["ɦ","h"],
// ["ʲ","j"],
// ["ʳ","r"],
// ["ʴ","ɹ"],
// ["ʵ","ɻ"],
// ["ʶ","ʁ"],
// ["ʷ","w"],
// ["ʸ","y"],
// ["ˠ","ɣ"],
// ["ˡ","l"],
// ["ˢ","s"],
// ["ˣ","x"],
// ["ˤ","ʕ"],
// ["ΐ","ι"],
// ["ά","α"],
// ["έ","ε"],
// ["ή","η"],
// ["ί","ι"],
// ["ΰ","υ"],
// ["ϊ","ι"],
// ["ϋ","υ"],
// ["ό","ο"],
// ["ύ","υ"],
// ["ώ","ω"],
// ["ϐ","β"],
// ["ϑ","θ"],
// ["ϒ","Υ"],
// ["ϓ","Υ"],
// ["ϔ","Υ"],
// ["ϕ","φ"],
// ["ϖ","π"],
// ["ϰ","κ"],
// ["ϱ","ρ"],
// ["ϲ","ς"],
// ["ϵ","ε"],
// ["й","и"],
// ["ѐ","е"],
// ["ё","е"],
// ["ѓ","г"],
// ["ї","і"],
// ["ќ","к"],
// ["ѝ","и"],
// ["ў","у"],
// ["ѷ","ѵ"],
// ["ӂ","ж"],
// ["ӑ","а"],
// ["ӓ","а"],
// ["ӗ","е"],
// ["ӛ","ә"],
// ["ӝ","ж"],
// ["ӟ","з"],
// ["ӣ","и"],
// ["ӥ","и"],
// ["ӧ","о"],
// ["ӫ","ө"],
// ["ӭ","э"],
// ["ӯ","у"],
// ["ӱ","у"],
// ["ӳ","у"],
// ["ӵ","ч"]
//
// // Charset Normalization
//
// // ["à", "a"],
// // ["á", "a"],
// // ["â", "a"],
// // ["ã", "a"],
// // ["ä", "a"],
// // ["å", "a"],
// //
// // ["è", "e"],
// // ["é", "e"],
// // ["ê", "e"],
// // ["ë", "e"],
// //
// // ["ì", "i"],
// // ["í", "i"],
// // ["î", "i"],
// // ["ï", "i"],
// //
// // ["ò", "o"],
// // ["ó", "o"],
// // ["ô", "o"],
// // ["õ", "o"],
// // ["ö", "o"],
// // ["ő", "o"],
// //
// // ["ù", "u"],
// // ["ú", "u"],
// // ["û", "u"],
// // ["ü", "u"],
// // ["ű", "u"],
// //
// // ["ý", "y"],
// // ["ŷ", "y"],
// // ["ÿ", "y"],
// //
// // ["ñ", "n"],
// // ["ç", "c"],
// // ["ß", "s"]
//
// // Special Chars Removal
//
// // [",", ""],
// // [".", ""],
// // ["'", ""]
//
// // Non-Whitespace Separators
//
// // split by default p{P}
// // ["-", " "],
// // [":", " "],
// // ["_", " "],
// // ["|", " "],
// // ["/", " "],
// // ["\\", " "]
// ]);
//
// // let pairs;
// //
// // if(!normalize){
// //
// // // Charset Normalization
// //
// // const regex_a = regex("[àáâãäå]"),
// // regex_e = regex("[èéêë]"),
// // regex_i = regex("[ìíîï]"),
// // regex_o = regex("[òóôõöő]"),
// // regex_u = regex("[ùúûüű]"),
// // regex_y = regex("[ýŷÿ]"),
// // regex_n = regex("ñ"),
// // //regex_c = regex("[çc]"),
// // regex_c = regex("ç"),
// // regex_s = regex("ß"),
// // //regex_and = regex(" & "),
// // regex_and = regex("&");
// //
// // pairs = [
// // regex_a, "a",
// // regex_e, "e",
// // regex_i, "i",
// // regex_o, "o",
// // regex_u, "u",
// // regex_y, "y",
// // regex_n, "n",
// // //regex_c, "k",
// // regex_c, "c",
// // regex_s, "s",
// // regex_and, " and "
// // ];
// // }
//
// /**
// * @param {string|number} str
// */
//
// export function encode(str){
//
// //str = "" + str;
//
// return pipeline.call(
//
// this,
// /* string: */ (/*normalize ? str.normalize("NFD").replace(normalize, "") :*/ "" + str).toLowerCase(),
// /* normalize: */ pairs,
// /* split: */ whitespace,
// ///* collapse: */ false
// );
// }

52
dist/module-debug/lang/latin/soundex.js vendored Normal file
View File

@@ -0,0 +1,52 @@
export default {
normalize: /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice:
!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/,
dedupe: /* suggest */ /* append: */ /* enrich */!1,
include: {
letter: !0
},
finalize: function (arr) {
for (let i = 0; i < arr.length; i++) {
arr[i] = soundex(arr[i]);
}
}
};
const codes = {
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, ß: 2,
d: 3, t: 3,
l: 4,
m: 5, n: 5,
r: 6
};
function soundex(stringToEncode) {
let encodedString = stringToEncode.charAt(0),
last = codes[encodedString];
for (let i = 1, char; i < stringToEncode.length; i++) {
char = stringToEncode.charAt(i);
// Remove all occurrences of "h" and "w"
if ("h" !== char && "w" !== char) {
// Replace all consonants with digits
char = codes[char];
// Remove all occurrences of a,e,i,o,u,y except first letter
if (char) {
// Replace all adjacent same digits with one digit
if (char !== last) {
encodedString += char;
last = char;
if (4 === encodedString.length) {
break;
}
}
}
}
}
// while(encodedString.length < 4){
// encodedString += "0";
// }
return encodedString;
}

View File

@@ -1,74 +0,0 @@
export let promise = Promise;
Object.assign || (Object.assign = function () {
const args = arguments,
size = args.length,
obj = args[0];
for (let x = 1, current, keys, length; x < size; x++) {
current = args[x];
keys = Object.keys(current);
length = keys.length;
for (let i = 0, key; i < length; i++) {
key = keys[i];
obj[key] = current[key];
}
}
return obj;
});
// Object.values || (Object.values = function(obj){
//
// const keys = Object.keys(obj);
// const length = keys.length;
// const values = new Array(length);
//
// for(let x = 0; x < length; x++){
//
// values[x] = obj[keys[x]];
// }
//
// return values;
// });
if (!promise) {
/**
* @param {Function} fn
* @constructor
*/
function SimplePromise(fn) {
this.callback = null;
const self = this;
fn(function (val) {
if (self.callback) {
self.callback(val);
// self.callback = null;
// self = null;
}
});
}
/**
* @param {Function} callback
*/
SimplePromise.prototype.then = function (callback) {
this.callback = callback;
};
promise = SimplePromise;
}

View File

@@ -1,96 +1,56 @@
import { is_string } from "./common.js"; import { is_string } from "./common.js";
import { IndexOptions } from "./type.js";
/** /**
* @enum {Object} * @enum {Object}
* @const * @const
*/ */
const preset = { const presets = {
memory: { memory: {
charset: "latin:extra", resolution: 1
//tokenize: "strict",
resolution: 3,
//threshold: 0,
minlength: 4,
fastupdate: /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */
/* collapse: */
/* collapse: */!1
}, },
performance: { performance: {
//charset: "latin", resolution: 6,
//tokenize: "strict", fastupdate: /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice:
resolution: 3, !0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/,
minlength: 3,
//fastupdate: true,
optimize: !1, //fastupdate: true,
context: { context: {
depth: 2, resolution: 1 depth: 1,
//bidirectional: false resolution: 3
} }
}, },
match: { match: {
charset: "latin:extra", tokenize: "forward"
tokenize: "reverse"
//resolution: 9,
//threshold: 0
}, },
score: { score: {
charset: "latin:advanced", resolution: 9,
//tokenize: "strict",
resolution: 20,
minlength: 3,
context: { context: {
depth: 3, depth: 2,
resolution: 9 resolution: 9
//bidirectional: true
} }
},
default: {
// charset: "latin:default",
// tokenize: "strict",
// resolution: 3,
// threshold: 0,
// depth: 3
} }
// "fast": {
// //charset: "latin",
// //tokenize: "strict",
// threshold: 8,
// resolution: 9,
// depth: 1
// }
}; };
/**
*
* @param {!IndexOptions|string} options
* @return {IndexOptions}
*/
export default function apply_preset(options) { export default function apply_preset(options) {
if (is_string(options)) { const preset = is_string(options) ? options : options.preset;
if (!preset[options]) {
console.warn("Preset not found: " + options);
}
options = preset[options];
} else {
const preset = options.preset;
if (preset) { if (preset) {
if (!presets[preset]) {
if (!preset[preset]) {
console.warn("Preset not found: " + preset); console.warn("Preset not found: " + preset);
} }
options = Object.assign({}, presets[preset], /** @type {Object} */options);
options = Object.assign({}, preset[preset], /** @type {Object} */options);
}
} }
return options; return options;

242
dist/module-debug/resolve/and.js vendored Normal file
View File

@@ -0,0 +1,242 @@
import Resolver from "../resolver.js";
import default_resolver from "./default.js";
import { create_object, get_max_len } from "../common.js";
// import xor from "./xor.js";
// import or from "./or.js";
// import not from "./not.js";
Resolver.prototype.and = function () {
if (this.result.length) {
const self = this;
let args = arguments,
first_argument = args[0];
if (first_argument instanceof Promise) {
return first_argument.then(function () {
return self.and.apply(self, args);
});
}
if (first_argument[0]) {
// fix false passed parameter style
if (first_argument[0].index) {
return this.and.apply(this, first_argument);
}
}
// for(let i = 0; i < args.length; i++){
// if(args[i].result instanceof Promise){
// return;
// }
// }
// if(args.length < 2){
// if(first_argument.index){
// first_argument.resolve = false;
// return first_argument.index.search(first_argument);
// }
// }
let final = [],
promises = [],
limit = 0,
offset = 0,
enrich,
resolve;
for (let i = 0, query; i < args.length; i++) {
if (query = args[i]) {
let result;
if (query instanceof Resolver) {
result = query.result;
} else if (query.constructor === Array) {
result = query;
} else if (query.index) {
query.resolve = /* suggest */ /* append: */ /* enrich */!1;
result = query.index.search(query).result;
} else if (query.or) {
result = this.or(query.or);
} else if (query.xor) {
result = this.xor(query.xor);
} else if (query.not) {
result = this.not(query.not);
} else {
limit = query.limit || 0;
offset = query.offset || 0;
enrich = query.enrich;
resolve = query.resolve;
continue;
}
final[i] = result;
if (result instanceof Promise) {
promises.push(result); //{ query, result };
}
}
}
if (promises.length) {
return Promise.all(promises).then(function () {
final = [self.result].concat(final);
self.result = intersect(final, limit, offset, enrich, resolve, self.boostval);
return resolve ? self.result : self;
});
}
final = [this.result].concat(final);
this.result = intersect(final, limit, offset, enrich, resolve, self.boostval);
return resolve ? this.result : this;
}
return this;
};
/**
* Aggregate the intersection of N raw results
* @param result
* @param limit
* @param offset
* @param enrich
* @param resolve
* @param boost
* @return {Array}
*/
function intersect(result, limit, offset, enrich, resolve, boost) {
// if(!result.length){
// // todo remove
// console.log("Empty Result")
// return result;
// }
if (2 > result.length) {
// todo remove
//console.log("Single Result")
return [];
// if(resolve){
// return default_resolver(result[0], limit, offset, enrich);
// }
// else{
// return result[0];
// }
}
let final = [],
count = 0,
contain = create_object(),
maxres = get_max_len(result);
// fast path single slot
// if(result.length < 2){
// if(limit || offset){
// let res = result[0];
// for(let j = 0, ids; j < res.length; j++){
// ids = res[j];
// if(!ids) continue;
// for(let k = 0, id; k < ids.length; k++){
// id = ids[k];
// if(offset){
// offset--;
// continue;
// }
// if(resolve){
// final.push(id);
// }
// else{
// final[j + this.boost] || (final[j + this.boost] = []);
// final[j + this.boost].push(id);
// }
// if(limit && ++count === limit){
// this.boost = 0;
// return final;
// }
// }
// }
// }
// this.boost = 0;
// return result[0];
// }
if (!maxres) return final;
// for(let j = 0, ids, res = result[0]; j < res.length; j++){
// ids = res[j];
// for(let k = 0; k < ids.length; k++){
// contain[ids[k]] = 1;
// }
// }
for (let i = 0, res; i < result.length; i++) {
res = result[i];
if (!res || !res.length) return [];
let contain_new = create_object(),
match = 0,
last_round = i === result.length - 1;
for (let j = 0, ids; j < maxres; j++) {
ids = res[j];
if (!ids) continue;
for (let k = 0, id, min; k < ids.length; k++) {
id = ids[k];
// fill in first round
if (!i) {
// shift resolution +1
// shift resolution by boost (inverse)
contain_new[id] = j + 1 + (i ? boost : 0);
match = 1;
}
// result in last round
else if (last_round) {
if (min = contain[id]) {
match = 1;
//if(!contain_new[id]){
if (offset) {
offset--;
continue;
}
if (resolve) {
final.push(id);
} else {
// reduce resolution -1
min--;
if (j < min) min = j;
final[min] || (final[min] = []);
final[min].push(id);
}
if (limit && ++count === limit) {
//this.boost = 0;
return final;
}
// shift resolution +1
//contain_new[id] = min + 1;
//}
}
}
// check for intersection
else if (min = contain[id]) {
// shift resolution +1
if (j + 1 < min) min = j + 1;
contain_new[id] = min;
match = 1;
}
}
}
if (!match) {
//this.boost = 0;
return [];
}
contain = contain_new;
}
//this.boost = 0;
return final;
}

98
dist/module-debug/resolve/default.js vendored Normal file
View File

@@ -0,0 +1,98 @@
import { concat } from "../common.js";
/*
from -> res[score][id]
to -> [id]
*/
/**
* Aggregate the union of a single raw result
* @param {!Array} result
* @param {!number} limit
* @param {number=} offset
* @param {boolean=} enrich
* @return Array<string|number>
*/
export default function (result, limit, offset, enrich) {
// fast path: when there is just one slot in the result
if (1 === result.length) {
result = result[0];
result = offset || result.length > limit ? limit ? result.slice(offset, offset + limit) : result.slice(offset) : result;
return enrich ? enrich_result(result) : result;
}
// this is an optimized workaround instead of
// just doing result = concat(result)
let final = [];
for (let i = 0, arr, len; i < result.length; i++) {
if (!(arr = result[i]) || !(len = arr.length)) continue;
if (offset) {
// forward offset pointer
if (offset >= len) {
offset -= len;
continue;
}
// apply offset pointer when length differs
if (offset < len) {
arr = limit ? arr.slice(offset, offset + limit) : arr.slice(offset);
len = arr.length;
offset = 0;
}
}
if (!final.length) {
// fast path: when limit was reached in first slot
if (len >= limit) {
if (len > limit) {
arr = arr.slice(0, limit);
}
return enrich ? enrich_result(arr) : arr;
}
final = [arr];
} else {
if (len > limit) {
arr = arr.slice(0, limit);
len = arr.length;
}
final.push(arr);
}
// reduce limit
limit -= len;
// todo remove
// if(limit < 0){
// throw new Error("Impl.Error");
// }
// break if limit was reached
if (!limit) {
break;
}
}
// todo remove
if (!final.length) {
//throw new Error("No results found");
return final;
}
final = 1 < final.length ? concat(final) : final[0];
return enrich ? enrich_result(final) : final;
}
function enrich_result(ids) {
for (let i = 0; i < ids.length; i++) {
ids[i] = {
score: i,
id: ids[i]
};
}
return ids;
}

115
dist/module-debug/resolve/not.js vendored Normal file
View File

@@ -0,0 +1,115 @@
import Resolver from "../resolver.js";
import default_resolver from "./default.js";
import { create_object } from "../common.js";
// import or from "./or.js";
// import and from "./and.js";
// import xor from "./xor.js";
Resolver.prototype.not = function () {
const self = this;
let args = arguments,
first_argument = args[0];
if (first_argument instanceof Promise) {
return first_argument.then(function () {
return self.not.apply(self, args);
});
}
if (first_argument[0]) {
// fix false passed parameter style
if (first_argument[0].index) {
return this.not.apply(this, first_argument);
}
}
let final = [],
promises = [],
limit = 0,
offset = 0,
resolve;
for (let i = 0, query; i < args.length; i++) {
if (query = args[i]) {
let result;
if (query instanceof Resolver) {
result = query.result;
} else if (query.constructor === Array) {
result = query;
} else if (query.index) {
query.resolve = /* suggest */ /* append: */ /* enrich */!1;
result = query.index.search(query).result;
} else if (query.or) {
result = this.or(query.or);
} else if (query.and) {
result = this.and(query.and);
} else if (query.xor) {
result = this.xor(query.xor);
} else {
limit = query.limit || 0;
offset = query.offset || 0;
query.enrich;
resolve = query.resolve;
continue;
}
final[i] = result;
if (result instanceof Promise) {
promises.push(result); //{ query, result };
}
}
}
if (promises.length) {
return Promise.all(promises).then(function () {
self.result = exclusion.call(self, final, limit, offset, resolve);
return resolve ? self.result : self;
});
}
this.result = exclusion.call(this, final, limit, offset, resolve);
return resolve ? this.result : this;
};
/**
* @param result
* @param limit
* @param offset
* @param resolve
* @this Resolver
* @return {Array}
*/
function exclusion(result, limit, offset, resolve) {
if (!result.length) {
return this.result;
}
const final = [],
exclude = new Set(result.flat().flat());
for (let j = 0, ids; j < this.result.length; j++) {
ids = this.result[j];
if (!ids) continue;
for (let k = 0, id; k < ids.length; k++) {
id = ids[k];
if (!exclude.has(id)) {
if (resolve) {
final.push(id);
} else {
final[j] || (final[j] = []);
final[j].push(id);
}
}
}
}
return final;
}

182
dist/module-debug/resolve/or.js vendored Normal file
View File

@@ -0,0 +1,182 @@
import Resolver from "../resolver.js";
import default_resolver from "./default.js";
import { create_object, get_max_len } from "../common.js";
// import xor from "./xor.js";
// import and from "./and.js";
// import not from "./not.js";
Resolver.prototype.or = function () {
const self = this;
let args = arguments,
first_argument = args[0];
if (first_argument instanceof Promise) {
return first_argument.then(function () {
return self.or.apply(self, args);
});
}
if (first_argument[0]) {
// fix false passed parameter style
if (first_argument[0].index) {
return this.or.apply(this, first_argument);
}
}
// for(let i = 0; i < args.length; i++){
// if(args[i].result instanceof Promise){
// return;
// }
// }
// if(args.length < 2){
// if(first_argument.index){
// first_argument.resolve = false;
// const result = first_argument.index.search(first_argument);
// if(result instanceof Promise){
// result.then(function(result){
// final = self.result.concat(result);
// self.result = resolver(final, limit, offset, enrich, !resolve);
// return resolve ? self.result : self;
// });
// }
// else{
// final = this.result.concat(result);
// this.result = resolver(final, limit, offset, enrich, !resolve);
// return resolve ? this.result : this;
// }
// }
// }
let final = [],
promises = [],
limit = 0,
offset = 0,
enrich,
resolve;
for (let i = 0, query; i < args.length; i++) {
if (query = args[i]) {
let result;
if (query instanceof Resolver) {
result = query.result;
} else if (query.constructor === Array) {
result = query;
} else if (query.index) {
query.resolve = /* suggest */ /* append: */ /* enrich */!1;
result = query.index.search(query).result;
} else if (query.and) {
result = this.and(query.and);
} else if (query.xor) {
result = this.xor(query.xor);
} else if (query.not) {
result = this.not(query.not);
} else {
limit = query.limit || 0;
offset = query.offset || 0;
enrich = query.enrich;
resolve = query.resolve;
continue;
}
final[i] = result;
if (result instanceof Promise) {
promises.push(result); //{ query, result };
}
}
}
if (promises.length) {
return Promise.all(promises).then(function () {
self.result.length && (final = [self.result].concat(final));
self.result = resolver(final, limit, offset, enrich, resolve, self.boostval);
return resolve ? self.result : self;
});
}
this.result.length && (final = [this.result].concat(final));
this.result = resolver(final, limit, offset, enrich, resolve, self.boostval);
return resolve ? this.result : this;
};
/**
* Aggregate the union of N raw results
* @param result
* @param limit
* @param offset
* @param enrich
* @param resolve
* @param boost
* @return {Array}
*/
function resolver(result, limit, offset, enrich, resolve, boost) {
if (!result.length) {
// todo remove
//console.log("Empty Result")
return result;
}
if ("object" == typeof limit) {
offset = limit.offset || 0;
enrich = limit.enrich || !1;
limit = limit.limit || 0;
}
if (2 > result.length) {
// todo remove
//console.log("Single Result")
if (resolve) {
return default_resolver(result[0], limit, offset, enrich);
} else {
return result[0];
}
}
let final = [],
count = 0,
dupe = create_object(),
maxres = get_max_len(result);
for (let j = 0, ids; j < maxres; j++) {
for (let i = 0, res; i < result.length; i++) {
res = result[i];
if (!res) continue;
ids = res[j];
if (!ids) continue;
for (let k = 0, id; k < ids.length; k++) {
id = ids[k];
if (!dupe[id]) {
dupe[id] = 1;
if (offset) {
offset--;
continue;
}
if (resolve) {
final.push(id);
} else {
// shift resolution by boost (inverse)
const index = j + (i ? boost : 0);
final[index] || (final[index] = []);
final[index].push(id);
}
if (limit && ++count === limit) {
//this.boost = 0;
return final;
}
}
}
}
}
//this.boost = 0;
return final;
}

154
dist/module-debug/resolve/xor.js vendored Normal file
View File

@@ -0,0 +1,154 @@
import Resolver from "../resolver.js";
import default_resolver from "./default.js";
import { create_object } from "../common.js";
// import or from "./or.js";
// import and from "./and.js";
// import not from "./not.js";
Resolver.prototype.xor = function () {
const self = this;
let args = arguments,
first_argument = args[0];
if (first_argument instanceof Promise) {
return first_argument.then(function () {
return self.xor.apply(self, args);
});
}
if (first_argument[0]) {
// fix false passed parameter style
if (first_argument[0].index) {
return this.xor.apply(this, first_argument);
}
}
let final = [],
promises = [],
limit = 0,
offset = 0,
enrich,
resolve;
for (let i = 0, query; i < args.length; i++) {
if (query = args[i]) {
let result;
if (query instanceof Resolver) {
result = query.result;
} else if (query.constructor === Array) {
result = query;
} else if (query.index) {
query.resolve = /* suggest */ /* append: */ /* enrich */!1;
result = query.index.search(query).result;
} else if (query.or) {
result = this.or(query.or);
} else if (query.and) {
result = this.and(query.and);
} else if (query.not) {
result = this.not(query.not);
} else {
limit = query.limit || 0;
offset = query.offset || 0;
enrich = query.enrich;
resolve = query.resolve;
continue;
}
final[i] = result;
if (result instanceof Promise) {
promises.push(result); //{ query, result };
}
}
}
if (promises.length) {
return Promise.all(promises).then(function () {
self.result.length && (final = [self.result].concat(final));
self.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval);
return resolve ? self.result : self;
});
}
this.result.length && (final = [this.result].concat(final));
this.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval);
return resolve ? this.result : this;
};
/**
* @param result
* @param limit
* @param offset
* @param enrich
* @param resolve
* @param boost
* @return {Array}
*/
function exclusive(result, limit, offset, enrich, resolve, boost) {
if (!result.length) {
// todo remove
//console.log("Empty Result")
return result;
}
if (2 > result.length) {
// todo remove
//console.log("Single Result")
if (resolve) {
return default_resolver(result[0], limit, offset, enrich);
} else {
return result[0];
}
}
const final = [],
check = create_object();
for (let i = 0, res; i < result.length; i++) {
res = result[i];
if (!res) continue;
for (let j = 0, ids; j < res.length; j++) {
ids = res[j];
if (!ids) continue;
for (let k = 0, id; k < ids.length; k++) {
id = ids[k];
check[id] ? check[id]++ : check[id] = 1;
}
}
}
for (let i = 0, res; i < result.length; i++) {
res = result[i];
if (!res) continue;
for (let j = 0, ids; j < res.length; j++) {
ids = res[j];
if (!ids) continue;
for (let k = 0, id; k < ids.length; k++) {
id = ids[k];
if (1 === check[id]) {
if (resolve) {
final.push(id);
} else {
// shift resolution by boost (inverse)
const index = j + (i ? boost : 0);
final[index] || (final[index] = []);
final[index].push(id);
}
}
}
}
}
//this.boost = 0;
return final;
}

99
dist/module-debug/resolver.js vendored Normal file
View File

@@ -0,0 +1,99 @@
import default_resolver from "./resolve/default.js";
import { set_resolve } from "./index/search.js";
// import or from "./resolve/or.js";
// import and from "./resolve/and.js";
// import xor from "./resolve/xor.js";
// import not from "./resolve/not.js";
import "./resolve/or.js";
import "./resolve/and.js";
import "./resolve/xor.js";
import "./resolve/not.js";
/**
* @param result
* @constructor
*/
export default function Resolver(result) {
if (result && result.index) {
result.resolve = /* suggest */ /* append: */ /* enrich */!1;
this.index = result.index;
return result.index.search(result);
}
if (!(this instanceof Resolver)) {
return new Resolver(result);
}
if (result instanceof Resolver) {
// todo remove
//console.log("Resolver Loopback")
return result;
}
this.index = null;
this.result = result || [];
this.boostval = 0;
}
// Resolver.prototype.or = or;
// Resolver.prototype.and = and;
// Resolver.prototype.not = not;
// Resolver.prototype.xor = xor;
Resolver.prototype.limit = function (limit) {
if (this.result.length) {
const final = [];
let count = 0;
for (let j = 0, ids; j < this.result.length; j++) {
ids = this.result[j];
if (ids.length + count < limit) {
final[j] = ids;
count += ids.length;
} else {
final[j] = ids.slice(0, limit - count);
this.result = final;
break;
}
}
}
return this;
};
Resolver.prototype.offset = function (offset) {
if (this.result.length) {
const final = [];
let count = 0;
for (let j = 0, ids; j < this.result.length; j++) {
ids = this.result[j];
if (ids.length + count < offset) {
count += ids.length;
} else {
final[j] = ids.slice(offset - count);
count = offset;
}
}
this.result = final;
}
return this;
};
Resolver.prototype.boost = function (boost) {
this.boostval += boost;
return this;
};
Resolver.prototype.resolve = function (limit, offset, enrich) {
set_resolve(1);
const result = this.result;
this.index = null;
this.result = null;
if (result.length) {
if ("object" == typeof limit) {
enrich = limit.enrich;
offset = limit.offset;
limit = limit.limit;
}
return default_resolver(result, limit || 100, offset, enrich);
}
return result;
};

View File

@@ -1,11 +1,12 @@
// TODO return promises instead of inner await // TODO return promises instead of inner await
import { IndexInterface, DocumentInterface } from "./type.js"; import Index from "./index.js";
import Document from "./document.js";
import { create_object, is_string } from "./common.js"; import { create_object, is_string } from "./common.js";
function async(callback, self, field, key, index_doc, index, data, on_done) { function async(callback, self, field, key, index_doc, index, data, on_done) {
setTimeout(function () { //setTimeout(function(){
const res = callback(field ? field + "." + key : key, JSON.stringify(data)); const res = callback(field ? field + "." + key : key, JSON.stringify(data));
@@ -21,16 +22,23 @@ function async(callback, self, field, key, index_doc, index, data, on_done) {
self.export(callback, self, field, index_doc, index + 1, on_done); self.export(callback, self, field, index_doc, index + 1, on_done);
} }
}); //});
} }
/** /**
* @this IndexInterface * @param callback
* @param self
* @param field
* @param index_doc
* @param index
* @param on_done
* @this {Index|Document}
*/ */
export function exportIndex(callback, self, field, index_doc, index, on_done) { export function exportIndex(callback, self, field, index_doc, index, on_done) {
let return_value = /* append: */ /* skip update: */ /* skip_update: */ /* skip post-processing: */!0; let return_value = /* tag? */ /* stringify */ /* stringify */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice:
!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/;
if ('undefined' == typeof on_done) { if ('undefined' == typeof on_done) {
return_value = new Promise(resolve => { return_value = new Promise(resolve => {
on_done = resolve; on_done = resolve;
@@ -51,13 +59,13 @@ export function exportIndex(callback, self, field, index_doc, index, on_done) {
data = create_object(); data = create_object();
for (let key in this.register) { for (let key of this.reg.keys()) {
data[key] = 1; data[key] = 1;
} }
} else { } else {
data = this.register; data = this.reg;
} }
break; break;
@@ -100,7 +108,7 @@ export function exportIndex(callback, self, field, index_doc, index, on_done) {
} }
/** /**
* @this IndexInterface * @this Index
*/ */
export function importIndex(key, data) { export function importIndex(key, data) {
@@ -126,8 +134,8 @@ export function importIndex(key, data) {
// fastupdate isn't supported by import // fastupdate isn't supported by import
this.fastupdate = /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* collapse: */!1; this.fastupdate = /* suggest */ /* append: */ /* enrich */!1;
this.register = data; this.reg = data;
break; break;
case "map": case "map":
@@ -143,7 +151,7 @@ export function importIndex(key, data) {
} }
/** /**
* @this DocumentInterface * @this Document
*/ */
export function exportDocument(callback, self, field, index_doc, index, on_done) { export function exportDocument(callback, self, field, index_doc, index, on_done) {
@@ -165,7 +173,7 @@ export function exportDocument(callback, self, field, index_doc, index, on_done)
self = this; self = this;
setTimeout(function () { //setTimeout(function(){
if (!idx.export(callback, self, index ? field /*.replace(":", "-")*/ : "", index_doc, index++, on_done)) { if (!idx.export(callback, self, index ? field /*.replace(":", "-")*/ : "", index_doc, index++, on_done)) {
@@ -174,7 +182,7 @@ export function exportDocument(callback, self, field, index_doc, index, on_done)
self.export(callback, self, field, index_doc, index, on_done); self.export(callback, self, field, index_doc, index, on_done);
} }
}); //});
} else { } else {
let key, data; let key, data;
@@ -214,7 +222,7 @@ export function exportDocument(callback, self, field, index_doc, index, on_done)
} }
/** /**
* @this DocumentInterface * @this Document
*/ */
export function importDocument(key, data) { export function importDocument(key, data) {
@@ -241,12 +249,12 @@ export function importDocument(key, data) {
// fastupdate isn't supported by import // fastupdate isn't supported by import
this.fastupdate = !1; this.fastupdate = !1;
this.register = data; this.reg = data;
for (let i = 0, index; i < this.field.length; i++) { for (let i = 0, index; i < this.field.length; i++) {
index = this.index[this.field[i]]; index = this.index[this.field[i]];
index.register = data; index.reg = data;
index.fastupdate = !1; index.fastupdate = !1;
} }

View File

@@ -1,69 +1,144 @@
/** // When you are looking for type definitions which fully describes the usage take a look into the index.d.ts file.
* @interface // Some of the types here aren't supposed to be used as public, they might be defined just for internal state.
*/ import Encoder from "./encoder.js";
import StorageInterface from "./db/interface.js";
export function IndexInterface() {
this.cache = null;
this.matcher = null;
this.stemmer = null;
this.filter = null;
}
/** /**
* @param {!string} str * @typedef IndexOptions {{
* @param {boolean|Array<string|RegExp>=} normalize * preset: string|undefined,
* @param {boolean|string|RegExp=} split * context: (IndexOptions|undefined),
* @param {boolean=} collapse * encoder: Encoder|Function|Object|undefined,
* @returns {string|Array<string>} * encode: Function|undefined,
* resolution: [number=9],
* tokenize: [string="strict"],
* fastupdate: [boolean:false],
* score: Function]|undefined,
* keystore: [number=0],
* rtl: [boolean=false],
* cache: [number=null],
* resolve: [boolean=true],
* db: StorageInterface|undefined,
* config: string|undefined
* }}
*/ */
export let IndexOptions;
//IndexInterface.prototype.pipeline;
/** /**
* @param {!number|string} id * @typedef DocumentOptions {{
* @param {!string} content * context: (IndexOptions|undefined),
* encoder: Encoder|Function|Object|undefined,
* encode: Function|undefined,
* resolution: [number=9],
* tokenize: [string="strict"],
* fastupdate: [boolean:false],
* score: Function]|undefined,
* keystore: [number=0],
* rtl: [boolean=false],
* cache: [number=null],
* db: StorageInterface|undefined,
* doc: DocumentDescriptor|Array<DocumentDescriptor>|undefined,
* document: DocumentDescriptor|Array<DocumentDescriptor>|undefined,
* worker: boolean|string|undefined
* }}
*/ */
export let DocumentOptions;
IndexInterface.prototype.add;
/** /**
* @param {!number|string} id * @typedef ContextOptions {{
* @param {!string} content * depth: number,
* bidirectional: boolean|undefined,
* resolution: number|undefined
* }}
*/ */
export let ContextOptions;
IndexInterface.prototype.append;
/** /**
* @param {!string|Object} query * @typedef DocumentDescriptor {{
* @param {number|Object=} limit * field: FieldOptions|Array<FieldOptions>|undefined,
* @param {Object=} options * index: FieldOptions|Array<FieldOptions>|undefined,
* @returns {Array<number|string>} * tag: TagOptions|Array<TagOptions>|undefined,
* store: StoreOptions|Array<StoreOptions>|undefined,
* config: string|undefined
* }}
*/ */
export let DocumentDescriptor;
IndexInterface.prototype.search;
/** /**
* @param {!number|string} id * @typedef FieldOptions {{
* @param {!string} content * field: string,
* filter: Function|undefined,
* custom: Function|undefined,
* context: (IndexOptions|undefined),
* encoder: Encoder|Function|Object|undefined,
* encode: Function|undefined,
* resolution: [number=9],
* tokenize: [string="strict"],
* fastupdate: [boolean:false],
* score: Function]|undefined,
* keystore: [number=0],
* rtl: [boolean=false],
* cache: [number=null],
* db: StorageInterface|undefined,
* config: string|undefined
* }}
*/ */
export let FieldOptions;
IndexInterface.prototype.update;
/** /**
* @param {!number|string} id * @typedef TagOptions {{
* field: string,
* tag: Object<string, string|Array<string>>|Array<string>|string,
* filter: Function|undefined,
* custom: Function|undefined,
* keystore: [number=0],
* db: StorageInterface|undefined,
* config: string|undefined
* }}
*/ */
export let TagOptions;
IndexInterface.prototype.remove;
/** /**
* @interface * @typedef StoreOptions {{
* field: string,
* filter: Function|undefined,
* custom: Function|undefined,
* keystore: [number=0],
* db: StorageInterface|undefined,
* config: string|undefined
* }}
*/ */
export let StoreOptions;
export function DocumentInterface() { /**
* @typedef SearchOptions {{
* query: string=,
* limit: [number=100],
* offset: [number=0],
* context: boolean|undefined,
* suggest: [boolean=false],
* resolve: [boolean=true],
* enrich: [boolean=false],
* tag: Array|undefined
* }}
*/
export let SearchOptions;
this.field = null; /**
* @typedef DocumentSearchOptions {{
* query: string=,
* limit: [number=100],
* offset: [number=0],
* context: boolean|undefined,
* suggest: [boolean=false],
* enrich: [boolean=false],
* tag: Array|undefined,
* field: FieldOptions|Array<FieldOptions>|undefined,
* index: FieldOptions|Array<FieldOptions>|undefined,
* pluck: boolean|undefined,
* merge: [boolean=false]
* }}
*/
export let DocumentSearchOptions;
/** @type IndexInterface */ export let EncoderOptions;
this.index = null; export let ResolverOptions;
}

173
dist/module-debug/webpack.js vendored Normal file
View File

@@ -0,0 +1,173 @@
import { SearchOptions, ContextOptions, DocumentDescriptor, DocumentSearchOptions, FieldOptions, IndexOptions, DocumentOptions } from "./type.js";
import Document from "./document.js";
import Index from "./index.js";
import WorkerIndex from "./worker/index.js";
import Resolver from "./resolver.js";
import Encoder from "./encoder.js";
import IdxDB from "./db/indexeddb/index.js";
import { global_charset, global_lang } from "./global.js";
import charset_exact from "./lang/latin/exact.js";
import charset_default from "./lang/latin/default.js";
import charset_simple from "./lang/latin/simple.js";
import charset_balance from "./lang/latin/balance.js";
import charset_advanced from "./lang/latin/advanced.js";
import charset_extra from "./lang/latin/extra.js";
import charset_soundex from "./lang/latin/soundex.js";
/** @export */Index.prototype.add;
/** @export */Index.prototype.append;
/** @export */Index.prototype.search;
/** @export */Index.prototype.update;
/** @export */Index.prototype.remove;
/** @export */Index.prototype.contain;
/** @export */Index.prototype.clear;
/** @export */Index.prototype.cleanup;
/** @export */Document.prototype.add;
/** @export */Document.prototype.append;
/** @export */Document.prototype.search;
/** @export */Document.prototype.update;
/** @export */Document.prototype.remove;
/** @export */Document.prototype.contain;
/** @export */Document.prototype.clear;
/** @export */Document.prototype.cleanup;
/** @export */Document.prototype.get;
/** @export */Document.prototype.set;
/** @export */Index.prototype.searchCache;
/** @export */Document.prototype.searchCache;
/** @export */Index.prototype.addAsync;
/** @export */Index.prototype.appendAsync;
/** @export */Index.prototype.searchAsync;
/** @export */Index.prototype.updateAsync;
/** @export */Index.prototype.removeAsync;
/** @export */Document.prototype.addAsync;
/** @export */Document.prototype.appendAsync;
/** @export */Document.prototype.searchAsync;
/** @export */Document.prototype.updateAsync;
/** @export */Document.prototype.removeAsync;
/** @export */Index.prototype.export;
/** @export */Index.prototype.import;
/** @export */Document.prototype.export;
/** @export */Document.prototype.import;
/** @export */Index.prototype.mount;
/** @export */Index.prototype.commit;
/** @export */Index.db;
/** @export */Document.prototype.mount;
/** @export */Document.prototype.commit;
/** @export */Document.db;
/** @export */IndexOptions.preset;
/** @export */IndexOptions.context;
/** @export */IndexOptions.encoder;
/** @export */IndexOptions.encode;
/** @export */IndexOptions.resolution;
/** @export */IndexOptions.tokenize;
/** @export */IndexOptions.fastupdate;
/** @export */IndexOptions.score;
/** @export */IndexOptions.keystore;
/** @export */IndexOptions.rtl;
/** @export */IndexOptions.cache;
/** @export */IndexOptions.resolve;
/** @export */IndexOptions.db;
/** @export */DocumentOptions.context;
/** @export */DocumentOptions.encoder;
/** @export */DocumentOptions.encode;
/** @export */DocumentOptions.resolution;
/** @export */DocumentOptions.tokenize;
/** @export */DocumentOptions.fastupdate;
/** @export */DocumentOptions.score;
/** @export */DocumentOptions.keystore;
/** @export */DocumentOptions.rtl;
/** @export */DocumentOptions.cache;
/** @export */DocumentOptions.db;
/** @export */DocumentOptions.doc;
/** @export */DocumentOptions.document;
/** @export */DocumentOptions.worker;
/** @export */DocumentDescriptor.field;
/** @export */DocumentDescriptor.index;
/** @export */DocumentDescriptor.tag;
/** @export */DocumentDescriptor.store;
/** @export */ContextOptions.depth;
/** @export */ContextOptions.bidirectional;
/** @export */ContextOptions.resolution;
/** @export */SearchOptions.query;
/** @export */SearchOptions.limit;
/** @export */SearchOptions.offset;
/** @export */SearchOptions.context;
/** @export */SearchOptions.suggest;
/** @export */SearchOptions.resolve;
/** @export */SearchOptions.enrich;
/** @export */SearchOptions.tag;
/** @export */DocumentSearchOptions.query;
/** @export */DocumentSearchOptions.limit;
/** @export */DocumentSearchOptions.offset;
/** @export */DocumentSearchOptions.context;
/** @export */DocumentSearchOptions.suggest;
/** @export */DocumentSearchOptions.enrich;
/** @export */DocumentSearchOptions.tag;
/** @export */DocumentSearchOptions.field;
/** @export */DocumentSearchOptions.index;
/** @export */DocumentSearchOptions.pluck;
/** @export */DocumentSearchOptions.merge;
global_charset["latin:exact"] = charset_exact;
global_charset["latin:default"] = charset_default;
global_charset["latin:simple"] = charset_simple;
global_charset["latin:balance"] = charset_balance;
global_charset["latin:advanced"] = charset_advanced;
global_charset["latin:extra"] = charset_extra;
global_charset["latin:soundex"] = charset_soundex;
const FlexSearch = {
Index: Index,
Encoder: Encoder,
Charset: global_charset,
Language: global_lang,
Document: Document,
Worker: WorkerIndex,
Resolver: Resolver,
IndexedDB: IdxDB
//"registerCharset": registerCharset,
//"registerLanguage": registerLanguage
};
// Export as library (Bundle)
// --------------------------------
{
const root = self;
let prop;
// AMD (RequireJS)
if ((prop = root.define) && prop.amd) {
prop([], function () {
return FlexSearch;
});
}
// CommonJS
else if ("object" == typeof root.exports) {
root.exports = FlexSearch;
}
// Global (window)
else {
/** @export */
root.FlexSearch = FlexSearch;
}
}

View File

@@ -1,6 +1,7 @@
import Index from "../index.js"; import Index from "../index.js";
import { IndexOptions } from "../type.js";
export default function (data) { export default (async function (data) {
data = data.data; data = data.data;
@@ -13,19 +14,26 @@ export default function (data) {
switch (task) { switch (task) {
case "init": case "init":
const options = data.options || {},
factory = data.factory,
encode = options.encode;
/** @type IndexOptions */
let options = data.options || {},
filepath = options.config;
options.cache = /* normalize: */ /* collapse: */ /* normalize: */ if (filepath) {
options = filepath;
/* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* collapse: */!1; // will be replaced after build with the line below because
// there is an issue with closure compiler dynamic import
if (encode && 0 === encode.indexOf("function")) { //options = await import(filepath);
options.encode = Function("return " + encode)();
} }
// deprecated:
// const encode = options.encode;
// if(encode && (encode.indexOf("function") === 0)){
// options.encode = Function("return " + encode)();
// }
const factory = data.factory;
if (factory) { if (factory) {
// export the FlexSearch global payload to "self" // export the FlexSearch global payload to "self"
@@ -41,6 +49,7 @@ export default function (data) {
self._index = new Index(options); self._index = new Index(options);
} }
postMessage({ id: data.id });
break; break;
default: default:
@@ -49,4 +58,4 @@ export default function (data) {
postMessage("search" === task ? { id: id, msg: message } : { id: id }); postMessage("search" === task ? { id: id, msg: message } : { id: id });
} }
} });

View File

@@ -1,31 +1,22 @@
//import { promise as Promise } from "../polyfill.js"; //import { promise as Promise } from "../polyfill.js";
import { IndexOptions } from "../type.js";
import { create_object, is_function, is_object, is_string } from "../common.js"; import { create_object, is_function, is_object, is_string } from "../common.js";
import handler from "./handler.js"; import handler from "./handler.js";
let pid = 0; let pid = 0;
/** /**
* @param {Object=} options * @param {IndexOptions=} options
* @constructor * @constructor
*/ */
function WorkerIndex(options) { function WorkerIndex(options) {
if (!(this instanceof WorkerIndex)) { if (!(this instanceof WorkerIndex)) {
return new WorkerIndex(options); return new WorkerIndex(options);
} }
let opt; if (!options) {
if (options) {
if (is_function(opt = options.encode)) {
options.encode = opt.toString();
}
} else {
options = {}; options = {};
} }
@@ -33,9 +24,7 @@ function WorkerIndex(options) {
// we use "self" as a trap for node.js // we use "self" as a trap for node.js
let factory = (self || window)._factory; let factory = (self || window)._factory;
if (factory) { if (factory) {
factory = factory.toString(); factory = factory.toString();
} }
@@ -50,25 +39,37 @@ function WorkerIndex(options) {
return; return;
} }
if (is_node_js) { function onmessage(msg) {
msg = msg.data || msg;
const id = msg.id,
res = id && _self.resolver[id];
this.worker.on("message", function (msg) { if (res) {
res(msg.msg);
delete _self.resolver[id];
}
}
_self.resolver[msg.id](msg.msg); is_node_js ? this.worker.on("message", onmessage) : this.worker.onmessage = onmessage;
delete _self.resolver[msg.id];
});
} else {
this.worker.onmessage = function (msg) { if (options.config) {
msg = msg.data; // when extern configuration needs to be loaded
_self.resolver[msg.id](msg.msg); // it needs to return a promise to await for
delete _self.resolver[msg.id]; return new Promise(function (resolve) {
_self.resolver[++pid] = function () {
resolve(_self);
}; };
_self.worker.postMessage({
id: pid,
task: "init",
factory: factory,
options: options
});
});
} }
this.worker.postMessage({ this.worker.postMessage({
task: "init", task: "init",
factory: factory, factory: factory,
options: options options: options
@@ -93,27 +94,22 @@ function register(key) {
let callback; let callback;
if (is_function(arg)) { if (is_function(arg)) {
callback = arg; callback = arg;
args.splice(args.length - 1, 1); args.splice(args.length - 1, 1);
} }
const promise = new Promise(function (resolve) { const promise = new Promise(function (resolve) {
//setTimeout(function(){
setTimeout(function () {
self.resolver[++pid] = resolve; self.resolver[++pid] = resolve;
self.worker.postMessage({ self.worker.postMessage({
task: key, task: key,
id: pid, id: pid,
args: args args: args
}); });
}); //});
}); });
if (callback) { if (callback) {
promise.then(callback); promise.then(callback);
return this; return this;
} else { } else {
@@ -125,12 +121,11 @@ function register(key) {
function create(factory, is_node_js, worker_path) { function create(factory, is_node_js, worker_path) {
let worker; let worker = is_node_js ?
// This eval will be removed when compiling, it isn't there in final build
try { (0, eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
//eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")')
worker = is_node_js ? eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') : factory ? new Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new Worker(is_string(worker_path) ? worker_path : "worker/worker.js", { type: "module" }); : factory ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + handler.toString()], { type: "text/javascript" }))) : new window.Worker(is_string(worker_path) ? worker_path : "worker/worker.js", { type: "module" });
} catch (e) {}
return worker; return worker;
} }

View File

@@ -1,5 +1,10 @@
const { parentPort } = require("worker_threads"), const { parentPort } = require("worker_threads"),
{ Index } = require("../flexsearch.bundle.min.js"); { join } = require("path"),
{ Index } = require("../../dist/flexsearch.bundle.min.js");
// TODO EXCHANGE
//const { Index } = require("../flexsearch.bundle.min.js");
let index; let index;
@@ -14,16 +19,25 @@ parentPort.on("message", function (data) {
switch (task) { switch (task) {
case "init": case "init":
const options = data.options || {}, let options = data.options || {},
encode = options.encode; filepath = options.config;
// load extern field configuration
options.cache = /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* normalize: */ /* collapse: */ /* collapse: */!1; if ("/" !== filepath[0] && "\\" !== filepath[0]) {
// current working directory
if (encode && 0 === encode.indexOf("function")) { const dir = process.cwd();
filepath = join(dir, filepath);
options.encode = new Function("return " + encode)();
} }
if (filepath) {
options = require(filepath);
}
// deprecated:
// const encode = options["encode"];
// if(encode && (encode.indexOf("function") === 0)){
// options["encode"] = new Function("return " + encode)();
// }
index = new Index(options); index = new Index(options);
break; break;

View File

@@ -1 +0,0 @@
import{IndexInterface,DocumentInterface}from"./type.js";import{is_function,is_object,is_string}from"./common.js";export default function(a){register(a,"add"),register(a,"append"),register(a,"search"),register(a,"update"),register(a,"remove")}function register(a,b){a[b+"Async"]=function(){const a=this,c=arguments,d=c[c.length-1];let e;is_function(d)&&(e=d,delete c[c.length-1]);const f=new Promise(function(d){setTimeout(function(){a.async=!0;const e=a[b].apply(a,c);a.async=!1,d(e)})});return e?(f.then(e),this):f}}

View File

@@ -1 +0,0 @@
import{IndexInterface,DocumentInterface}from"./type.js";import{create_object,is_object}from"./common.js";function CacheClass(a){this.limit=!0!==a&&a,this.cache=create_object(),this.queue=[]}export default CacheClass;export function searchCache(a,b,c){is_object(a)&&(a=a.query);let d=this.cache.get(a);return d||(d=this.search(a,b,c),this.cache.set(a,d)),d}CacheClass.prototype.set=function(a,b){if(!this.cache[a]){let b=this.queue.length;b===this.limit?delete this.cache[this.queue[b-1]]:b++;for(let a=b-1;0<a;a--)this.queue[a]=this.queue[a-1];this.queue[0]=a}this.cache[a]=b},CacheClass.prototype.get=function(a){const b=this.cache[a];if(this.limit&&b){const b=this.queue.indexOf(a);if(b){const a=this.queue[b-1];this.queue[b-1]=this.queue[b],this.queue[b]=a}}return b},CacheClass.prototype.del=function(a){for(let b,c,d=0;d<this.queue.length;d++)c=this.queue[d],b=this.cache[c],b.includes(a)&&(this.queue.splice(d--,1),delete this.cache[c])};

View File

@@ -1 +0,0 @@
export function parse_option(a,b){return"undefined"==typeof a?b:a}export function create_object_array(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=create_object();return b}export function create_arrays(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=[];return b}export function get_keys(a){return Object.keys(a)}export function create_object(){return Object.create(null)}export function concat(a){return[].concat.apply([],a)}export function sort_by_length_down(c,a){return a.length-c.length}export function is_array(a){return a.constructor===Array}export function is_string(a){return"string"==typeof a}export function is_object(a){return"object"==typeof a}export function is_function(a){return"function"==typeof a}

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
import{searchCache}from"./cache";function Engine(a){a.prototype.searchCache=searchCache,a.prototype.addAsync=addAsync,a.prototype.appendAsync=appendAsync,a.prototype.searchAsync=searchAsync,a.prototype.updateAsync=updateAsync,a.prototype.removeAsync=removeAsync}Engine.prototype.searchCache=searchCache,Engine.prototype.addAsync=addAsync,Engine.prototype.appendAsync=appendAsync,Engine.prototype.searchAsync=searchAsync,Engine.prototype.updateAsync=updateAsync,Engine.prototype.removeAsync=removeAsync;

View File

@@ -1 +0,0 @@
export const global_lang={};export const global_charset={};export function registerCharset(a,b){global_charset[a]=b}export function registerLanguage(a,b){global_lang[a]=b}

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
import{create_object,concat}from"./common.js";export function intersect(a,b,c,d){const e=a.length;let f,g,h=[],i=0;d&&(d=[]);for(let j=e-1;0<=j;j--){const k=a[j],l=k.length,m=create_object();let n=!f;for(let a=0;a<l;a++){const l=k[a],o=l.length;if(o)for(let a,k,p=0;p<o;p++)if(k=l[p],f){if(f[k]){if(!j)if(c)c--;else if(h[i++]=k,i===b)return h;(j||d)&&(m[k]=1),n=!0}if(d&&(a=(g[k]||0)+1,g[k]=a,a<e)){const b=d[a-2]||(d[a-2]=[]);b[b.length]=k}}else m[k]=1}if(d)f||(g=m);else if(!n)return[];f=m}if(d)for(let a,e,g=d.length-1;0<=g;g--){a=d[g],e=a.length;for(let d,g=0;g<e;g++)if(d=a[g],!f[d]){if(c)c--;else if(h[i++]=d,i===b)return h;f[d]=1}}return h}export function intersect_union(a,b){const c=create_object(),d=create_object(),e=[];for(let d=0;d<a.length;d++)c[a[d]]=1;for(let f,g=0;g<b.length;g++){f=b[g];for(let a,b=0;b<f.length;b++)a=f[b],c[a]&&!d[a]&&(d[a]=1,e[e.length]=a)}return e}

View File

@@ -1 +0,0 @@
import{IndexInterface}from"./type.js";import{create_object,get_keys}from"./common.js";export function pipeline(a,b,c,d){if(a&&(b&&(a=replace(a,b)),this.matcher&&(a=replace(a,this.matcher)),this.stemmer&&1<a.length&&(a=replace(a,this.stemmer)),d&&1<a.length&&(a=collapse(a)),c||""===c)){const b=a.split(c);return this.filter?filter(b,this.filter):b}return a}export const regex_whitespace=/[\p{Z}\p{S}\p{P}\p{C}]+/u;const regex_normalize=/[\u0300-\u036f]/g;export function normalize(a){return a.normalize&&(a=a.normalize("NFD").replace(regex_normalize,"")),a}export function init_filter(a){const b=create_object();for(let c=0,d=a.length;c<d;c++)b[a[c]]=1;return b}export function init_stemmer_or_matcher(a,b){const c=get_keys(a),d=c.length,e=[];let f="",g=0;for(let h,j,k=0;k<d;k++)h=c[k],j=a[h],j?(e[g++]=regex(b?"(?!\\b)"+h+"(\\b|_)":h),e[g++]=j):f+=(f?"|":"")+h;return f&&(e[g++]=regex(b?"(?!\\b)("+f+")(\\b|_)":"("+f+")"),e[g]=""),e}export function replace(a,b){for(let c=0,d=b.length;c<d&&(a=a.replace(b[c],b[c+1]),!!a);c+=2);return a}export function regex(a){return new RegExp(a,"g")}export function collapse(a){let b="",c="";for(let d,e=0,f=a.length;e<f;e++)(d=a[e])!==c&&(b+=c=d);return b}export function filter(a,b){const c=a.length,d=[];for(let e=0,f=0;e<c;e++){const c=a[e];c&&!b[c]&&(d[f++]=c)}return d}

View File

@@ -1 +0,0 @@
import{IndexInterface}from"../../type.js";import{pipeline}from"../../lang.js";export const rtl=!0;export const tokenize="";export default{encode:encode,rtl:!0};const regex=/[\x00-\x7F]+/g,split=/\s+/;export function encode(a){return pipeline.call(this,(""+a).replace(regex," "),!1,split,!1)}

View File

@@ -1 +0,0 @@
export const filter=["aber","als","am","an","auch","auf","aus","bei","bin","bis","bist","da","dadurch","daher","darum","das","da\xDF","dass","dein","deine","dem","den","der","des","dessen","deshalb","die","dies","dieser","dieses","doch","dort","du","durch","ein","eine","einem","einen","einer","eines","er","es","euer","eure","f\xFCr","hatte","hatten","hattest","hattet","hier","hinter","ich","ihr","ihre","im","in","ist","ja","jede","jedem","jeden","jeder","jedes","jener","jenes","jetzt","kann","kannst","k\xF6nnen","k\xF6nnt","machen","mein","meine","mit","mu\xDF","mu\xDFt","musst","m\xFCssen","m\xFC\xDFt","nach","nachdem","nein","nicht","nun","oder","seid","sein","seine","sich","sie","sind","soll","sollen","sollst","sollt","sonst","soweit","sowie","und","unser","unsere","unter","vom","von","vor","wann","warum","was","weiter","weitere","wenn","wer","werde","werden","werdet","weshalb","wie","wieder","wieso","wir","wird","wirst","wo","woher","wohin","zu","zum","zur","\xFCber"];export const stemmer={niss:"",isch:"",lich:"",heit:"",keit:"",end:"",ung:"",est:"",ern:"",em:"",er:"",en:"",es:"",st:"",ig:"",ik:"",e:"",s:""};export const matcher={};export default{filter:filter,stemmer:stemmer,matcher:matcher};

View File

@@ -1 +0,0 @@
import{IndexInterface}from"../../type.js";import{pipeline}from"../../lang.js";export const rtl=!1;export const tokenize="strict";export default{encode:encode,rtl:!1,tokenize:"strict"};const regex=/[\x00-\x7F]+/g;export function encode(a){return pipeline.call(this,(""+a).replace(regex,""),!1,"",!1)}

View File

@@ -1 +0,0 @@
import{IndexInterface}from"../../type.js";import{pipeline}from"../../lang.js";export const rtl=!1;export const tokenize="";export default{encode:encode,rtl:!1};const regex=/[\x00-\x7F]+/g,split=/\s+/;export function encode(a){return pipeline.call(this,(""+a).replace(regex," "),!1,split,!1)}

View File

@@ -1 +0,0 @@
export const filter=["aber","als","am","an","auch","auf","aus","bei","bin","bis","bist","da","dadurch","daher","darum","das","da\xDF","dass","dein","deine","dem","den","der","des","dessen","deshalb","die","dies","dieser","dieses","doch","dort","du","durch","ein","eine","einem","einen","einer","eines","er","es","euer","eure","f\xFCr","hatte","hatten","hattest","hattet","hier","hinter","ich","ihr","ihre","im","in","ist","ja","jede","jedem","jeden","jeder","jedes","jener","jenes","jetzt","kann","kannst","k\xF6nnen","k\xF6nnt","machen","mein","meine","mit","mu\xDF","mu\xDFt","musst","m\xFCssen","m\xFC\xDFt","nach","nachdem","nein","nicht","nun","oder","seid","sein","seine","sich","sie","sind","soll","sollen","sollst","sollt","sonst","soweit","sowie","und","unser","unsere","unter","vom","von","vor","wann","warum","was","weiter","weitere","wenn","wer","werde","werden","werdet","weshalb","wie","wieder","wieso","wir","wird","wirst","wo","woher","wohin","zu","zum","zur","\xFCber"];export const stemmer={niss:"",isch:"",lich:"",heit:"",keit:"",ell:"",bar:"",end:"",ung:"",est:"",ern:"",em:"",er:"",en:"",es:"",st:"",ig:"",ik:"",e:"",s:""};export const matcher={};export default{filter:filter,stemmer:stemmer,matcher:matcher};

View File

@@ -1 +0,0 @@
export const filter=["a","about","above","after","again","against","all","also","am","an","and","any","are","aren't","as","at","be","because","been","before","being","below","both","but","by","can","cannot","can't","come","could","couldn't","did","didn't","do","does","doesn't","doing","dont","down","during","each","even","few","first","for","from","further","get","go","had","hadn't","has","hasn't","have","haven't","having","he","hed","her","here","here's","hers","herself","hes","him","himself","his","how","how's","i","id","if","ill","im","in","into","is","isn't","it","it's","itself","i've","just","know","let's","like","make","me","more","most","mustn't","my","myself","new","no","nor","not","now","of","off","on","once","only","or","other","ought","our","our's","ourselves","out","over","own","same","say","see","shan't","she","she'd","shell","shes","should","shouldn't","so","some","such","than","that","that's","the","their","theirs","them","themselves","then","there","there's","these","they","they'd","they'll","they're","they've","this","those","through","time","to","too","until","up","us","very","want","was","wasn't","way","we","wed","well","were","weren't","we've","what","what's","when","when's","where","where's","which","while","who","whom","who's","why","why's","will","with","won't","would","wouldn't","you","you'd","you'll","your","you're","your's","yourself","yourselves","you've"];export const stemmer={ational:"ate",iveness:"ive",fulness:"ful",ousness:"ous",ization:"ize",tional:"tion",biliti:"ble",icate:"ic",ative:"",alize:"al",iciti:"ic",entli:"ent",ousli:"ous",alism:"al",ation:"ate",aliti:"al",iviti:"ive",ement:"",enci:"ence",anci:"ance",izer:"ize",alli:"al",ator:"ate",logi:"log",ical:"ic",ance:"",ence:"",ness:"",able:"",ible:"",ment:"",eli:"e",bli:"ble",ful:"",ant:"",ent:"",ism:"",ate:"",iti:"",ous:"",ive:"",ize:"",al:"",ou:"",er:"",ic:""};export const matcher={};export default{filter:filter,stemmer:stemmer,matcher:matcher};

View File

@@ -1 +0,0 @@
import{IndexInterface}from"../../type.js";import{regex,replace,collapse}from"../../lang.js";import{encode as encode_balance}from"./balance.js";export const rtl=!1;export const tokenize="";export default{encode:encode,rtl:!1,tokenize:""};const regex_ae=regex("ae"),regex_oe=regex("oe"),regex_sh=regex("sh"),regex_th=regex("th"),regex_ph=regex("ph"),regex_pf=regex("pf"),pairs=[regex_ae,"a",regex_oe,"o",regex_sh,"s",regex_th,"t",regex_ph,"f",regex_pf,"f",regex("(?![aeo])h(?![aeo])"),"",regex("(?!^[aeo])h(?!^[aeo])"),""];export function encode(a,b){return a&&(a=encode_balance.call(this,a).join(" "),2<a.length&&(a=replace(a,pairs)),!b&&(1<a.length&&(a=collapse(a)),a&&(a=a.split(" ")))),a||[]}

View File

@@ -1 +0,0 @@
import{IndexInterface}from"../../type.js";import{encode as encode_simple}from"./simple.js";export const rtl=!1;export const tokenize="strict";export default{encode:encode,rtl:!1,tokenize:"strict"};const regex_strip=/[^a-z0-9]+/,soundex={b:"p",v:"f",w:"f",z:"s",x:"s",ß:"s",d:"t",n:"m",c:"k",g:"k",j:"k",q:"k",i:"e",y:"e",u:"o"};export function encode(a){a=encode_simple.call(this,a).join(" ");const b=[];if(a){const c=a.split(regex_strip),d=c.length;for(let e,f=0,g=0;f<d;f++)if((a=c[f])&&(!this.filter||!this.filter[a])){e=a[0];let c=soundex[e]||e,d=c;for(let b=1;b<a.length;b++){e=a[b];const f=soundex[e]||e;f&&f!==d&&(c+=f,d=f)}b[g++]=c}}return b}

View File

@@ -1 +0,0 @@
import{IndexInterface}from"../../type.js";import{pipeline,normalize,regex_whitespace}from"../../lang.js";export const rtl=!1;export const tokenize="";export default{encode:encode,rtl:!1,tokenize:""};export function encode(a){return pipeline.call(this,(""+a).toLowerCase(),!1,regex_whitespace,!1)}

View File

@@ -1 +0,0 @@
import{IndexInterface}from"../../type.js";import{regex,replace,collapse}from"../../lang.js";import{encode as encode_advanced}from"./advanced.js";export const rtl=!1;export const tokenize="";export default{encode:encode,rtl:!1,tokenize:""};const prefix="(?!\\b)",regex_vowel=regex("(?!\\b)[aeo]"),pairs=[regex_vowel,""];export function encode(a){return a&&(a=encode_advanced.call(this,a,!0),1<a.length&&(a=a.replace(regex_vowel,"")),1<a.length&&(a=collapse(a)),a&&(a=a.split(" "))),a||[]}

View File

@@ -1 +0,0 @@
import{IndexInterface}from"../../type.js";import{pipeline,normalize,regex_whitespace,regex}from"../../lang.js";export const rtl=!1;export const tokenize="";export default{encode:encode,rtl:!1,tokenize:""};const regex_a=regex("[\xE0\xE1\xE2\xE3\xE4\xE5]"),regex_e=regex("[\xE8\xE9\xEA\xEB]"),regex_i=regex("[\xEC\xED\xEE\xEF]"),regex_o=regex("[\xF2\xF3\xF4\xF5\xF6\u0151]"),regex_u=regex("[\xF9\xFA\xFB\xFC\u0171]"),regex_y=regex("[\xFD\u0177\xFF]"),regex_n=regex("\xF1"),regex_c=regex("[\xE7c]"),regex_s=regex("\xDF"),regex_and=regex(" & "),pairs=[regex_a,"a",regex_e,"e",regex_i,"i",regex_o,"o",regex_u,"u",regex_y,"y",regex_n,"n",regex_c,"k",regex_s,"s",regex_and," and "];export function encode(a){return a=""+a,pipeline.call(this,normalize(a).toLowerCase(),!a.normalize&&pairs,regex_whitespace,!1)}

View File

@@ -1 +0,0 @@
export const filter=["a","about","above","after","again","against","all","also","am","an","and","any","are","aren't","as","at","be","because","been","before","being","below","both","but","by","can","cannot","can't","come","could","couldn't","did","didn't","do","does","doesn't","doing","dont","down","during","each","even","few","first","for","from","further","get","go","had","hadn't","has","hasn't","have","haven't","having","he","hed","her","here","here's","hers","herself","hes","him","himself","his","how","how's","i","id","if","ill","im","in","into","is","isn't","it","it's","itself","i've","just","know","let's","like","make","me","more","most","mustn't","my","myself","new","no","nor","not","now","of","off","on","once","only","or","other","ought","our","our's","ourselves","out","over","own","same","say","see","shan't","she","she'd","shell","shes","should","shouldn't","so","some","such","than","that","that's","the","their","theirs","them","themselves","then","there","there's","these","they","they'd","they'll","they're","they've","this","those","through","time","to","too","until","up","us","very","want","was","wasn't","way","we","wed","well","were","weren't","we've","what","what's","when","when's","where","where's","which","while","who","whom","who's","why","why's","will","with","won't","would","wouldn't","you","you'd","you'll","your","you're","your's","yourself","yourselves","you've"];export const stemmer={ational:"ate",iveness:"ive",fulness:"ful",ousness:"ous",ization:"ize",tional:"tion",biliti:"ble",icate:"ic",ative:"",alize:"al",iciti:"ic",entli:"ent",ousli:"ous",alism:"al",ation:"ate",aliti:"al",iviti:"ive",ement:"",enci:"ence",anci:"ance",izer:"ize",alli:"al",ator:"ate",logi:"log",ical:"ic",ance:"",ence:"",ness:"",able:"",ible:"",ment:"",eli:"e",bli:"ble",ful:"",ant:"",ent:"",ism:"",ate:"",iti:"",ous:"",ive:"",ize:"",al:"",ou:"",er:"",ic:""};export const matcher={};export default{filter:filter,stemmer:stemmer,matcher:matcher};

View File

@@ -1 +0,0 @@
export let promise=Promise;if(Object.assign||(Object.assign=function(){const a=arguments,b=a.length,c=a[0];for(let d,e,f,g=1;g<b;g++){d=a[g],e=Object.keys(d),f=e.length;for(let a,b=0;b<f;b++)a=e[b],c[a]=d[a]}return c}),!promise){function a(a){this.callback=null;const b=this;a(function(a){b.callback&&b.callback(a)})}a.prototype.then=function(a){this.callback=a},promise=a}

View File

@@ -1 +0,0 @@
import{is_string}from"./common.js";const preset={memory:{charset:"latin:extra",resolution:3,minlength:4,fastupdate:!1},performance:{resolution:3,minlength:3,optimize:!1,context:{depth:2,resolution:1}},match:{charset:"latin:extra",tokenize:"reverse"},score:{charset:"latin:advanced",resolution:20,minlength:3,context:{depth:3,resolution:9}},default:{}};export default function apply_preset(a){if(is_string(a))!1,a=preset[a];else{const b=a.preset;b&&(!1,a=Object.assign({},b[b],a))}return a}

View File

@@ -1 +0,0 @@
import{IndexInterface,DocumentInterface}from"./type.js";import{create_object,is_string}from"./common.js";function async(a,b,c,d,e,f,g,h){setTimeout(function(){const i=a(c?c+"."+d:d,JSON.stringify(g));i&&i.then?i.then(function(){b.export(a,b,c,e,f+1,h)}):b.export(a,b,c,e,f+1,h)})}export function exportIndex(a,b,c,d,e,f){let g=!0;"undefined"==typeof f&&(g=new Promise(a=>{f=a}));let h,i;switch(e||(e=0)){case 0:if(h="reg",this.fastupdate)for(let a in i=create_object(),this.register)i[a]=1;else i=this.register;break;case 1:h="cfg",i={doc:0,opt:this.optimize?1:0};break;case 2:h="map",i=this.map;break;case 3:h="ctx",i=this.ctx;break;default:return void("undefined"==typeof c&&f&&f());}return async(a,b||this,c,h,d,e,i,f),g}export function importIndex(a,b){b&&(is_string(b)&&(b=JSON.parse(b)),"cfg"===a?this.optimize=!!b.opt:"reg"===a?(this.fastupdate=!1,this.register=b):"map"===a?this.map=b:"ctx"===a?this.ctx=b:void 0)}export function exportDocument(a,b,c,d,e,f){let g;if("undefined"==typeof f&&(g=new Promise(a=>{f=a})),e||(e=0),d||(d=0),d<this.field.length){const c=this.field[d],g=this.index[c];b=this,setTimeout(function(){g.export(a,b,e?c:"",d,e++,f)||(d++,e=1,b.export(a,b,c,d,e,f))})}else{let b,g;switch(e){case 1:b="tag",g=this.tagindex,c=null;break;case 2:b="store",g=this.store,c=null;break;default:return void f();}async(a,this,c,b,d,e,g,f)}return g}export function importDocument(a,b){if(b)switch(is_string(b)&&(b=JSON.parse(b)),a){case"tag":this.tagindex=b;break;case"reg":this.fastupdate=!1,this.register=b;for(let a,c=0;c<this.field.length;c++)a=this.index[this.field[c]],a.register=b,a.fastupdate=!1;break;case"store":this.store=b;break;default:a=a.split(".");const c=a[0];a=a[1],c&&a&&this.index[c].import(a,b);}}

View File

@@ -1 +0,0 @@
export function IndexInterface(){this.cache=null,this.matcher=null,this.stemmer=null,this.filter=null}IndexInterface.prototype.add,IndexInterface.prototype.append,IndexInterface.prototype.search,IndexInterface.prototype.update,IndexInterface.prototype.remove;export function DocumentInterface(){this.field=null,this.index=null}

View File

@@ -1 +0,0 @@
import Index from"../index.js";export default function(a){a=a.data;const b=self._index,c=a.args,d=a.task;switch(d){case"init":const e=a.options||{},f=a.factory,g=e.encode;e.cache=!1,g&&0===g.indexOf("function")&&(e.encode=Function("return "+g)()),f?(Function("return "+f)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new Index(e);break;default:const h=a.id,i=b[d].apply(b,c);postMessage("search"===d?{id:h,msg:i}:{id:h});}}

View File

@@ -1 +0,0 @@
import{create_object,is_function,is_object,is_string}from"../common.js";import handler from"./handler.js";let pid=0;function WorkerIndex(a){if(!(this instanceof WorkerIndex))return new WorkerIndex(a);let b;a?is_function(b=a.encode)&&(a.encode=b.toString()):a={};let c=(self||window)._factory;c&&(c=c.toString());const d="undefined"==typeof window&&self.exports,e=this;this.worker=create(c,d,a.worker),this.resolver=create_object();this.worker&&(d?this.worker.on("message",function(a){e.resolver[a.id](a.msg),delete e.resolver[a.id]}):this.worker.onmessage=function(a){a=a.data,e.resolver[a.id](a.msg),delete e.resolver[a.id]},this.worker.postMessage({task:"init",factory:c,options:a}))}export default WorkerIndex;register("add"),register("append"),register("search"),register("update"),register("remove");function register(a){WorkerIndex.prototype[a]=WorkerIndex.prototype[a+"Async"]=function(){const b=this,c=[].slice.call(arguments),d=c[c.length-1];let e;is_function(d)&&(e=d,c.splice(c.length-1,1));const f=new Promise(function(d){setTimeout(function(){b.resolver[++pid]=d,b.worker.postMessage({task:a,id:pid,args:c})})});return e?(f.then(e),this):f}}function create(factory,is_node_js,worker_path){let worker;try{worker=is_node_js?eval("new (require(\"worker_threads\")[\"Worker\"])(__dirname + \"/node/node.js\")"):factory?new Worker(URL.createObjectURL(new Blob(["onmessage="+handler.toString()],{type:"text/javascript"}))):new Worker(is_string(worker_path)?worker_path:"worker/worker.js",{type:"module"})}catch(a){}return worker}

View File

@@ -1 +0,0 @@
const{parentPort}=require("worker_threads"),{Index}=require("../flexsearch.bundle.min.js");let index;parentPort.on("message",function(a){const b=a.args,c=a.task,d=a.id;switch(c){case"init":const e=a.options||{},f=e.encode;e.cache=!1,f&&0===f.indexOf("function")&&(e.encode=new Function("return "+f)()),index=new Index(e);break;default:const g=index[c].apply(index,b);parentPort.postMessage("search"===c?{id:d,msg:g}:{id:d});}});

View File

@@ -1 +0,0 @@
import handler from"./handler.js";onmessage=handler;

90
dist/module/async.js vendored
View File

@@ -1,51 +1,71 @@
import { IndexInterface, DocumentInterface } from "./type.js"; import Document from "./document.js";
//import { promise as Promise } from "./polyfill.js"; import Index from "./index.js";
import { is_function, is_object, is_string } from "./common.js";
export default function (prototype) { export default function (prototype) {
register.call(prototype, "add");
register(prototype, "add"); register.call(prototype, "append");
register(prototype, "append"); register.call(prototype, "search");
register(prototype, "search"); register.call(prototype, "update");
register(prototype, "update"); register.call(prototype, "remove");
register(prototype, "remove");
} }
function register(prototype, key) { // let cycle;
// let budget = 0;
//
// function tick(resolve){
// cycle = null;
// budget = 0;
// resolve();
// }
prototype[key + "Async"] = function () { /**
* @param {!string} key
* @this {Index|Document}
*/
/** @type {IndexInterface|DocumentInterface} */ function register(key) {
const self = this, this[key + "Async"] = function () {
args = /*[].slice.call*/arguments,
// // prevent stack overflow of adding too much tasks to the same event loop
// // actually limit stack to 1,000,000 tasks every ~4ms
// cycle || (
// cycle = new Promise(resolve => setTimeout(tick, 0, resolve))
// );
//
// // apply different performance budgets
// if(key === "update" || key === "remove" && this.fastupdate === false){
// budget += 1000 * this.resolution;
// if(this.depth)
// budget += 1000 * this.resolution_ctx;
// }
// else if(key === "search"){
// budget++;
// }
// else{
// budget += 20 * this.resolution;
// if(this.depth)
// budget += 20 * this.resolution_ctx;
// }
//
// // wait for the event loop cycle
// if(budget >= 1e6){
// await cycle;
// }
const args = /*[].slice.call*/arguments,
arg = args[args.length - 1]; arg = args[args.length - 1];
let callback; let callback;
if (is_function(arg)) { if ("function" == typeof arg) {
callback = arg; callback = arg;
delete args[args.length - 1]; delete args[args.length - 1];
} }
const promise = new Promise(function (resolve) { this.async = !0;
const res = this[key].apply(this, args);
setTimeout(function () { this.async = !1;
res.then ? res.then(callback) : callback(res);
self.async = !0; return res;
const res = self[key].apply(self, args);
self.async = !1;
resolve(res);
});
});
if (callback) {
promise.then(callback);
return this;
} else {
return promise;
}
}; };
} }

195
dist/module/cache.js vendored
View File

@@ -1,168 +1,77 @@
import { IndexInterface, DocumentInterface } from "./type.js"; import Index from "./index.js";
import { create_object, is_object } from "./common.js"; import Document from "./document.js";
/**
* @param {string|Object} query
* @param {number|Object=} limit
* @param {Object=} options
* @this {Index|Document}
* @returns {Array<number|string>|Promise}
*/
export function searchCache(query, limit, options) {
query = ("object" == typeof query ? "" + query.query : "" + query).toLowerCase();
//let encoded = this.encoder.encode(query).join(" ");
let cache = this.cache.get(query);
if (!cache) {
cache = this.search(query, limit, options);
if (cache instanceof Promise) {
const self = this;
cache.then(function (cache) {
self.cache.set(query, cache);
});
}
this.cache.set(query, cache);
}
return cache;
}
/** /**
* @param {boolean|number=} limit * @param {boolean|number=} limit
* @constructor * @constructor
*/ */
function CacheClass(limit) { export default function CacheClass(limit) {
/** @private */ /** @private */
this.limit = !0 !== limit && limit; this.limit = !limit || !0 === limit ? 1000 : limit;
/** @private */ /** @private */
this.cache = create_object(); this.cache = new Map();
/** @private */ /** @private */
this.queue = []; this.last = "";
//this.clear();
} }
export default CacheClass;
/**
* @param {string|Object} query
* @param {number|Object=} limit
* @param {Object=} options
* @this {IndexInterface}
* @returns {Array<number|string>}
*/
export function searchCache(query, limit, options) {
if (is_object(query)) {
query = query.query;
}
let cache = this.cache.get(query);
if (!cache) {
cache = this.search(query, limit, options);
this.cache.set(query, cache);
}
return cache;
}
// CacheClass.prototype.clear = function(){
//
// /** @private */
// this.cache = create_object();
//
// /** @private */
// this.queue = [];
// };
CacheClass.prototype.set = function (key, value) { CacheClass.prototype.set = function (key, value) {
if (!this.cache.has(key)) {
if (!this.cache[key]) { this.cache.set(this.last = key, value);
if (this.limit && this.cache.size > this.limit) {
// it is just a shame that native function array.shift() performs so bad this.cache.delete(this.cache.keys().next().value);
// const length = this.queue.length;
//
// this.queue[length] = key;
//
// if(length === this.limit){
//
// delete this.cache[this.queue.shift()];
// }
// the same bad performance
// this.queue.unshift(key);
//
// if(this.queue.length === this.limit){
//
// this.queue.pop();
// }
// fast implementation variant
// let length = this.queue.length;
//
// if(length === this.limit){
//
// length--;
//
// delete this.cache[this.queue[0]];
//
// for(let x = 0; x < length; x++){
//
// this.queue[x] = this.queue[x + 1];
// }
// }
//
// this.queue[length] = key;
// current fastest implementation variant
// theoretically that should not perform better compared to the example above
let length = this.queue.length;
if (length === this.limit) {
delete this.cache[this.queue[length - 1]];
} else {
length++;
} }
for (let x = length - 1; 0 < x; x--) {
this.queue[x] = this.queue[x - 1];
} }
this.queue[0] = key;
}
this.cache[key] = value;
}; };
CacheClass.prototype.get = function (key) { CacheClass.prototype.get = function (key) {
const cache = this.cache.get(key);
const cache = this.cache[key]; if (cache && this.limit && this.last !== key) {
this.cache.delete(key);
if (this.limit && cache) { this.cache.set(this.last = key, cache);
// probably the indexOf() method performs faster when matched content is on front (left-to-right)
// using lastIndexOf() does not help, it performs almost slower
const pos = this.queue.indexOf(key);
// if(pos < this.queue.length - 1){
//
// const tmp = this.queue[pos];
// this.queue[pos] = this.queue[pos + 1];
// this.queue[pos + 1] = tmp;
// }
if (pos) {
const tmp = this.queue[pos - 1];
this.queue[pos - 1] = this.queue[pos];
this.queue[pos] = tmp;
} }
}
return cache; return cache;
}; };
CacheClass.prototype.del = function (id) { CacheClass.prototype.remove = function (id) {
for (const item of this.cache) {
const key = item[0],
value = item[1];
for (let i = 0, item, key; i < this.queue.length; i++) { if (value.includes(id)) {
this.cache.delete(key);
key = this.queue[i];
item = this.cache[key];
if (item.includes(id)) {
this.queue.splice(i--, 1);
delete this.cache[key];
} }
} }
}; };
CacheClass.prototype.clear = function () {
this.cache.clear();
this.last = "";
};

131
dist/module/common.js vendored
View File

@@ -1,6 +1,65 @@
export function parse_option(value, default_value) { /**
* @param {*} value
* @param {*} default_value
* @param {*=} merge_value
* @return {*}
*/
return "undefined" != typeof value ? value : default_value; export function parse_option(value, default_value, merge_value) {
const type_merge = typeof merge_value,
type_value = typeof value;
if ("undefined" != type_merge) {
if ("undefined" != type_value) {
if (merge_value) {
if ("function" == type_value && type_merge == type_value) {
return function (str) {
return (/** @type Function */value(
/** @type Function */merge_value(str))
);
};
}
const constructor_value = value.constructor,
constructor_merge = merge_value.constructor;
if (constructor_value === constructor_merge) {
if (constructor_value === Array) {
return merge_value.concat(value);
}
if (constructor_value === Map) {
const map = new Map( /** @type !Map */merge_value);
for (const item of /** @type !Map */value) {
const key = item[0],
val = item[1];
map.set(key, val);
}
return map;
}
if (constructor_value === Set) {
const set = new Set( /** @type !Set */merge_value);
for (const val of /** @type !Set */value.values()) {
set.add(val);
}
return set;
}
}
}
return value;
} else {
return merge_value;
}
}
return "undefined" == type_value ? default_value : value;
} }
/** /**
@@ -13,19 +72,33 @@ export function create_object_array(count) {
const array = Array(count); const array = Array(count);
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
array[i] = create_object(); array[i] = create_object();
} }
return array; return array;
} }
/**
* @param {!number} count
* @returns {Array<Object>}
*/
export function create_map_array(count) {
const array = Array(count);
for (let i = 0; i < count; i++) {
array[i] = new Map();
}
return array;
}
export function create_arrays(count) { export function create_arrays(count) {
const array = Array(count); const array = Array(count);
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
array[i] = []; array[i] = [];
} }
@@ -38,41 +111,75 @@ export function create_arrays(count) {
*/ */
export function get_keys(obj) { export function get_keys(obj) {
return Object.keys(obj); return Object.keys(obj);
} }
export function create_object() { export function create_object() {
return Object.create(null); return Object.create(null);
} }
export function concat(arrays) { export function concat(arrays) {
return [].concat.apply([], arrays); return [].concat.apply([], arrays);
} }
export function sort_by_length_down(a, b) { export function sort_by_length_down(a, b) {
return b.length - a.length; return b.length - a.length;
} }
export function is_array(val) { export function sort_by_length_up(a, b) {
return a.length - b.length;
}
export function is_array(val) {
return val.constructor === Array; return val.constructor === Array;
} }
export function is_string(val) { export function is_string(val) {
return "string" == typeof val; return "string" == typeof val;
} }
export function is_object(val) { export function is_object(val) {
return "object" == typeof val; return "object" == typeof val;
} }
export function is_function(val) { export function is_function(val) {
return "function" == typeof val; return "function" == typeof val;
} }
/**
* @param {Map|Set} val
* @param {boolean=} stringify
* @return {Array}
*/
export function toArray(val, stringify) {
const result = [];
for (const key of val.keys()) {
result.push(stringify ? "" + key : key);
}
return result;
}
// TODO support generic function created from string when tree depth > 1
export function parse_simple(obj, tree) {
if (is_string(tree)) {
obj = obj[tree];
} else for (let i = 0; obj && i < tree.length; i++) {
obj = obj[tree[i]];
}
return obj;
}
export function get_max_len(arr) {
let len = 0;
for (let i = 0, res; i < arr.length; i++) {
if (res = arr[i]) {
if (len < res.length) {
len = res.length;
}
}
}
return len;
}

65
dist/module/compress.js vendored Normal file
View File

@@ -0,0 +1,65 @@
let table, timer; // = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
const cache = new Map();
function toRadix(number, radix = 255) {
if (!table) {
table = Array(radix);
// the char code 0 could be a special marker
for (let i = 0; i < radix; i++) table[i] = i + 1;
table = String.fromCharCode.apply(null, table);
}
let rixit,
residual = number,
result = "";
while (!0) {
rixit = residual % radix;
result = table.charAt(rixit) + result;
residual = 0 | residual / radix;
if (!residual) break;
}
return result;
}
export default function (str) {
if (timer) {
if (cache.has(str)) {
return cache.get(str);
}
} else {
timer = setTimeout(clear);
}
/* 2 ** ((level + 1.5) * 1.6 | 0) */
const result = toRadix("number" == typeof str ? str : lcg(str));
2e5 < cache.size && cache.clear();
cache.set(str, result);
return result;
}
function lcg(str) {
let range = 4294967295;
if ("number" == typeof str) {
return str & range;
}
let crc = 0;
for (let i = 0; i < str.length; i++) {
crc = (crc * 33 ^ str.charCodeAt(i)) & range;
}
// shift up from Int32 to UInt32 range 0xFFFFFFFF
return crc + 2147483648;
}
function clear() {
timer = null;
cache.clear();
}

648
dist/module/db/clickhouse/index.js vendored Normal file
View File

@@ -0,0 +1,648 @@
import { ClickHouse } from "clickhouse";
import StorageInterface from "../interface.js";
import Document from "../../document.js";
import { concat, toArray } from "../../common.js";
const defaults = {
host: "http://localhost",
port: "8123",
debug: !1,
basicAuth: null,
isUseGzip: !1,
trimQuery: !1,
usePost: !1,
format: "json",
raw: !1,
config: {
output_format_json_quote_64bit_integers: 0,
enable_http_compression: 0,
database: "default"
}
},
VERSION = 1,
fields = ["map", "ctx", "tag", "reg", "cfg"],
types = {
text: "String",
char: "String",
varchar: "String",
string: "String",
number: "Int32",
numeric: "Int32",
integer: "Int32",
smallint: "Int16",
tinyint: "Int8",
mediumint: "Int32",
int: "Int32",
int8: "Int8",
uint8: "UInt8",
int16: "Int16",
uint16: "UInt16",
int32: "Int32",
uint32: "UInt32",
int64: "Int64",
uint64: "UInt64",
bigint: "Int64"
};
function sanitize(str) {
return str.toLowerCase().replace(/[^a-z0-9_]/g, "");
}
let DB;
/**
* @constructor
* @implements StorageInterface
*/
export default function ClickhouseDB(name, config = {}) {
if (!(this instanceof ClickhouseDB)) {
return new ClickhouseDB(name, config);
}
if ("object" == typeof name) {
name = name.name;
config = name;
}
if (!name) {
console.info("Default storage space was used, because a name was not passed.");
}
//field = "Test-456";
this.id = "flexsearch" + (name ? "_" + sanitize(name) : "");
this.field = config.field ? "_" + sanitize(config.field) : "";
// Clickhouse does not support ALTER TABLE to upgrade
// the type of the ID when it is a part of the merge key
this.type = config.type ? types[config.type.toLowerCase()] : "String";
if (!this.type) throw new Error("Unknown type of ID '" + config.type + "'");
//this.trx = false;
this.support_tag_search = !0;
this.db = DB || (DB = config.db || null);
Object.assign(defaults, config);
config.database && (defaults.config.database = config.database);
this.db && delete defaults.db;
}
ClickhouseDB.prototype.mount = function (flexsearch) {
if (flexsearch instanceof Document) {
return flexsearch.mount(this);
}
defaults.resolution = Math.max(flexsearch.resolution, flexsearch.resolution_ctx);
flexsearch.db = this;
return this.open();
};
ClickhouseDB.prototype.open = async function () {
if (!this.db) {
this.db = DB || (DB = new ClickHouse(defaults));
}
const exists = await this.db.query(`
SELECT 1 FROM system.databases WHERE name = '${this.id}';
`).toPromise();
if (!exists || !exists.length) {
await this.db.query(`
CREATE DATABASE IF NOT EXISTS ${this.id};
`).toPromise();
}
for (let i = 0; i < fields.length; i++) {
switch (fields[i]) {
case "map":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.map${this.field}(
key String,
res ${255 >= defaults.resolution ? "UInt8" : "UInt16"},
id ${this.type}
)
ENGINE = MergeTree
/*PRIMARY KEY (key)*/
ORDER BY (key, id);
`, { params: { name: this.id + ".map" + this.field } }).toPromise();
break;
case "ctx":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.ctx${this.field}(
ctx String,
key String,
res ${255 >= defaults.resolution ? "UInt8" : "UInt16"},
id ${this.type}
)
ENGINE = MergeTree
/*PRIMARY KEY (ctx, key)*/
ORDER BY (ctx, key, id);
`).toPromise();
break;
case "tag":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.tag${this.field}(
tag String,
id ${this.type}
)
ENGINE = MergeTree
/*PRIMARY KEY (ctx, key)*/
ORDER BY (tag, id);
`).toPromise();
break;
case "reg":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.reg(
id ${this.type},
doc Nullable(String)
)
ENGINE = MergeTree
ORDER BY (id);
`).toPromise();
break;
case "cfg":
await this.db.query(`
CREATE TABLE IF NOT EXISTS ${this.id}.cfg${this.field}(
cfg String
)
ENGINE = TinyLog;
`).toPromise();
break;
}
}
return this.db;
};
ClickhouseDB.prototype.close = function () {
this.db.close();
this.db = null;
return this;
};
ClickhouseDB.prototype.destroy = async function () {
await Promise.all([this.db.query(`DROP TABLE ${this.id}.map${this.field};`).toPromise(), this.db.query(`DROP TABLE ${this.id}.ctx${this.field};`).toPromise(), this.db.query(`DROP TABLE ${this.id}.tag${this.field};`).toPromise(), this.db.query(`DROP TABLE ${this.id}.cfg${this.field};`).toPromise(), this.db.query(`DROP TABLE ${this.id}.reg;`).toPromise()]);
this.close();
};
ClickhouseDB.prototype.clear = function () {
return Promise.all([this.db.query(`TRUNCATE TABLE ${this.id}.map${this.field};`).toPromise(), this.db.query(`TRUNCATE TABLE ${this.id}.ctx${this.field};`).toPromise(), this.db.query(`TRUNCATE TABLE ${this.id}.tag${this.field};`).toPromise(), this.db.query(`TRUNCATE TABLE ${this.id}.cfg${this.field};`).toPromise(), this.db.query(`TRUNCATE TABLE ${this.id}.reg;`).toPromise()]);
};
function create_result(rows, resolve, enrich) {
if (resolve) {
for (let i = 0; i < rows.length; i++) {
if (enrich) {
if (rows[i].doc) {
rows[i].doc = JSON.parse(rows[i].doc);
}
} else {
rows[i] = rows[i].id;
}
}
return rows;
} else {
const arr = [];
for (let i = 0, row; i < rows.length; i++) {
row = rows[i];
arr[row.res] || (arr[row.res] = []);
arr[row.res].push(enrich ? row : row.id);
}
return arr;
}
}
ClickhouseDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = !0, enrich = !1, tags) {
let rows,
params = ctx ? { ctx, key } : { key },
table = this.id + (ctx ? ".ctx" : ".map") + this.field;
if (tags) {
for (let i = 0, count = 1; i < tags.length; i += 2) {
` AND ${table}.id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = {tag${count}:String})`;
params["tag" + count] = tags[i + 1];
count++;
}
}
if (ctx) {
rows = this.db.query(`
SELECT ${table}.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE ctx = {ctx:String} AND key = {key:String}
ORDER BY res
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, { params }).toPromise();
} else {
rows = this.db.query(`
SELECT ${table}.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE key = {key:String}
ORDER BY res
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, { params }).toPromise();
}
return rows.then(function (rows) {
return create_result(rows, resolve, enrich);
});
};
ClickhouseDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) {
const table = this.id + ".tag" + this.field,
promise = this.db.query(`
SELECT ${table}.id
${enrich ? ", doc" : ""}
FROM ${table}
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = ${table}.id
` : ""}
WHERE tag = {tag:String}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}`, { params: { tag } }).toPromise();
enrich || promise.then(function (rows) {
return create_result(rows, !0, !1);
});
return promise;
};
ClickhouseDB.prototype.enrich = async function (ids) {
let MAXIMUM_QUERY_VARS = 1e5,
result = [];
if ("object" != typeof ids) {
ids = [ids];
}
for (let count = 0; count < ids.length;) {
const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids;
count += chunk.length;
let params = {},
stmt = "";
for (let i = 0; i < chunk.length; i++) {
stmt += (stmt ? "," : "") + "{id" + (i + 1) + ":String}";
params["id" + (i + 1)] = chunk[i];
}
const res = await this.db.query(`
SELECT id, doc
FROM ${this.id}.reg
WHERE id IN (${stmt})`, { params }).toPromise();
if (res && res.length) {
for (let i = 0, doc; i < res.length; i++) {
if (doc = res[i].doc) {
res[i].doc = JSON.parse(doc);
}
}
result.push(res);
}
}
return 1 === result.length ? result[0] : 1 < result.length ? concat(result) : result;
};
ClickhouseDB.prototype.has = function (id) {
return this.db.query(`
SELECT EXISTS(
SELECT 1
FROM ${this.id}.reg
WHERE id = {id:${this.type /*=== "number" ? "Int32" : "String"*/}}
LIMIT 1
)`, { params: { id } }).toPromise();
};
ClickhouseDB.prototype.search = function (flexsearch, query, limit = 100, offset = 0, suggest = !1, resolve = !0, enrich = !0, tags) {
let rows;
if (1 < query.length && flexsearch.depth) {
let where = "",
params = {},
keyword = query[0],
term;
for (let i = 1; i < query.length; i++) {
term = query[i];
const swap = flexsearch.bidirectional && term > keyword;
where += (where ? " OR " : "") + `(ctx = {ctx${i}:String} AND key = {key${i}:String})`;
params["ctx" + i] = swap ? term : keyword;
params["key" + i] = swap ? keyword : term;
keyword = term;
}
if (tags) {
where = "(" + where + ")";
for (let i = 0, count = 1; i < tags.length; i += 2) {
where += ` AND id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = {tag${count}:String})`;
params["tag" + count] = tags[i + 1];
count++;
}
}
rows = this.db.query(`
SELECT r.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM (
SELECT id, count(*) as count,
${suggest ? "SUM" : "MIN"}(res) as res
FROM ${this.id}.ctx${this.field}
WHERE ${where}
GROUP BY id
) as r
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = r.id
` : ""}
${suggest ? "" : "WHERE count = " + (query.length - 1)}
ORDER BY ${suggest ? "count DESC, res" : "res"}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`, { params }).toPromise();
// for(let i = 1; i < query.length; i++){
// where += (where ? " UNION ALL " : "") + `
// SELECT id, res
// FROM ${this.id}.ctx${this.field}
// WHERE ctx = {ctx${i}:String} AND key = {key${i}:String}
// `;
// term = query[i];
// const swap = flexsearch.bidirectional && (term > keyword);
// params["ctx" + i] = swap ? term : keyword;
// params["key" + i] = swap ? keyword : term;
// keyword = term;
// }
//
// rows = await this.db.query(`
// SELECT id, res
// FROM (
// SELECT id, ${suggest ? "SUM" : "MIN"}(res) as res, count(*) as count
// FROM (${where}) as t
// GROUP BY id
// ORDER BY ${suggest ? "count DESC, res" : "res"}
// LIMIT ${limit}
// OFFSET ${offset}
// ) as r
// ${suggest ? "" : "WHERE count = " + (query.length - 1)}
// `, { params }).toPromise();
} else {
let where = "",
params = {};
for (let i = 0; i < query.length; i++) {
where += (where ? "," : "") + `{key${i}:String}`;
params["key" + i] = query[i];
}
where = "key " + (1 < query.length ? "IN (" + where + ")" : "= " + where);
if (tags) {
where = "(" + where + ")";
for (let i = 0, count = 1; i < tags.length; i += 2) {
where += ` AND id IN (SELECT id FROM ${this.id}.tag_${sanitize(tags[i])} WHERE tag = {tag${count}:String})`;
params["tag" + count] = tags[i + 1];
count++;
}
}
rows = this.db.query(`
SELECT r.id
${resolve ? "" : ", res"}
${enrich ? ", doc" : ""}
FROM (
SELECT id, count(*) as count,
${suggest ? "SUM" : "MIN"}(res) as res
FROM ${this.id}.map${this.field}
WHERE ${where}
GROUP BY id
) as r
${enrich ? `
LEFT OUTER JOIN ${this.id}.reg ON ${this.id}.reg.id = r.id
` : ""}
${suggest ? "" : "WHERE count = " + query.length}
ORDER BY ${suggest ? "count DESC, res" : "res"}
${limit ? "LIMIT " + limit : ""}
${offset ? "OFFSET " + offset : ""}
`, { params }).toPromise();
// for(let i = 0; i < query.length; i++){
// params["key" + i] = query[i];
// where += (where ? " UNION ALL " : "") + `
// SELECT id, res
// FROM ${ this.id }.map${ this.field }
// WHERE key = {key${i}:String}
// `;
// }
// rows = await this.db.query(`
// SELECT id, res
// FROM (
// SELECT id, ${suggest ? "SUM" : "MIN"}(res) as res, count(*) as count
// FROM (${where}) as t
// GROUP BY id
// ORDER BY ${suggest ? "count DESC, res" : "res"}
// LIMIT ${limit}
// OFFSET ${offset}
// ) as r
// ${ suggest ? "" : "WHERE count = " + query.length }
// `, { params }).toPromise();
}
return rows.then(function (rows) {
return create_result(rows, resolve, enrich);
});
};
ClickhouseDB.prototype.info = function () {
// todo
};
ClickhouseDB.prototype.transaction = function (task) {
// not supported
return task.call(this);
};
ClickhouseDB.prototype.commit = async function (flexsearch, _replace, _append) {
// process cleanup tasks
if (_replace) {
await this.clear();
// there are just removals in the task queue
flexsearch.commit_task = [];
} else {
let tasks = flexsearch.commit_task;
flexsearch.commit_task = [];
for (let i = 0, task; i < tasks.length; i++) {
task = tasks[i];
// there are just removals in the task queue
if (task.clear) {
await this.clear();
_replace = !0;
break;
} else {
tasks[i] = task.del;
}
}
if (!_replace) {
if (!_append) {
tasks = tasks.concat(toArray(flexsearch.reg));
}
tasks.length && (await this.remove(tasks));
}
}
if (!flexsearch.reg.size) {
return;
}
if (flexsearch.map.size) {
let data = [];
for (const item of flexsearch.map) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
//this.type || (this.type = typeof ids[0]);
for (let j = 0; j < ids.length; j++) {
data.push({
key: key,
res: i,
id: /*this.type === "number"
? parseInt(ids[j], 10)
:*/ids[j]
});
}
}
}
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.map${this.field} (key, res, id)`, data).toPromise();
}
}
if (flexsearch.ctx.size) {
let data = [];
for (const ctx of flexsearch.ctx) {
const ctx_key = ctx[0],
ctx_value = ctx[1];
for (const item of ctx_value) {
const key = item[0],
arr = item[1];
for (let i = 0, ids; i < arr.length; i++) {
if ((ids = arr[i]) && ids.length) {
for (let j = 0; j < ids.length; j++) {
data.push({
ctx: ctx_key,
key: key,
res: i,
id: /*this.type === "number"
? parseInt(ids[j], 10)
:*/ids[j]
});
}
}
}
}
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.ctx${this.field} (ctx, key, res, id)`, data).toPromise();
}
}
if (flexsearch.tag) {
let data = [];
for (const item of flexsearch.tag) {
const tag = item[0],
ids = item[1];
if (!ids.length) continue;
for (let j = 0; j < ids.length; j++) {
data.push({ tag, id: ids[j] });
}
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.tag${this.field} (tag, id)`, data).toPromise();
}
}
if (flexsearch.store) {
let data = [];
for (const item of flexsearch.store.entries()) {
const id = item[0],
doc = item[1];
data.push({ id, doc: doc && JSON.stringify(doc) });
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.reg (id, doc)`, data).toPromise();
}
} else if (!flexsearch.bypass) {
let data = toArray(flexsearch.reg);
for (let i = 0; i < data.length; i++) {
data[i] = { id: data[i] };
}
if (data.length) {
await this.db.insert(`INSERT INTO ${this.id}.reg (id)`, data).toPromise();
}
}
// TODO
// await this.db.insert(`INSERT INTO ${this.id}.cfg${this.field} (cfg)`, [{
// cfg: JSON.stringify({
// "encode": typeof flexsearch.encode === "string" ? flexsearch.encode : "",
// "charset": typeof flexsearch.charset === "string" ? flexsearch.charset : "",
// "tokenize": flexsearch.tokenize,
// "resolution": flexsearch.resolution,
// "minlength": flexsearch.minlength,
// "optimize": flexsearch.optimize,
// "fastupdate": flexsearch.fastupdate,
// "encoder": flexsearch.encoder,
// "context": {
// "depth": flexsearch.depth,
// "bidirectional": flexsearch.bidirectional,
// "resolution": flexsearch.resolution_ctx
// }
// })
// }]).toPromise();
flexsearch.map.clear();
flexsearch.ctx.clear();
flexsearch.tag && flexsearch.tag.clear();
flexsearch.store && flexsearch.store.clear();
flexsearch.document || flexsearch.reg.clear();
await Promise.all([this.db.query(`OPTIMIZE TABLE ${this.id}.map${this.field} FINAL`).toPromise(), this.db.query(`OPTIMIZE TABLE ${this.id}.ctx${this.field} FINAL`).toPromise(), this.db.query(`OPTIMIZE TABLE ${this.id}.tag${this.field} FINAL`).toPromise(), this.db.query(`OPTIMIZE TABLE ${this.id}.reg FINAL`).toPromise()]);
};
ClickhouseDB.prototype.remove = async function (ids) {
if ("object" != typeof ids) {
ids = [ids];
}
while (ids.length) {
let chunk = ids.slice(0, 1e5);
ids = ids.slice(1e5);
chunk = "String" === this.type ? "'" + chunk.join("','") + "'" : chunk.join(",");
await Promise.all([this.db.query(`
ALTER TABLE ${this.id}.map${this.field}
DELETE WHERE id IN (${chunk})
SETTINGS mutations_sync = 1;`).toPromise(), this.db.query(`
ALTER TABLE ${this.id}.ctx${this.field}
DELETE WHERE id IN (${chunk})
SETTINGS mutations_sync = 1;`).toPromise(), this.db.query(`
ALTER TABLE ${this.id}.tag${this.field}
DELETE WHERE id IN (${chunk})
SETTINGS mutations_sync = 1;`).toPromise(), this.db.query(`
ALTER TABLE ${this.id}.reg
DELETE WHERE id IN (${chunk})
SETTINGS mutations_sync = 1;`).toPromise()]);
}
};

Some files were not shown because too many files have changed in this diff Show More