1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-28 08:10:54 +02:00

minor refactoring

This commit is contained in:
Thomas Wilkerling
2021-05-19 19:43:30 +02:00
parent d00ab0619d
commit f5bcf34ac8
15 changed files with 322 additions and 182 deletions

View File

@@ -1,24 +1,27 @@
/**! /**!
* FlexSearch.js v0.7.0-pre-alpha (Compact) * FlexSearch.js v0.7.0-beta (Compact)
* Copyright 2019 Nextapps GmbH * Copyright 2019 Nextapps GmbH
* Author: Thomas Wilkerling * Author: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function(){var r;function t(a){for(var b=Array(a),c=0;c<a;c++)b[c]=x();return b}function x(){return Object.create(null)}function z(a,b){return b.length-a.length};var A=/[\W_]+/;function B(a){if(a=a.toLowerCase())if(a&&this.A&&(a=C(a,this.A)),this.C&&1<a.length&&(a=C(a,this.C)),a&&(A||""===A)&&(a=a.split(A),this.filter)){for(var b=this.filter,c=a.length,d=[],e=0,h=0;e<c;e++){var f=a[e];f&&!b[f]&&(d[h++]=f)}a=d}return a};function D(a,b){for(var c=Object.keys(a),d=c.length,e=[],h="",f=0,g=0,l,k;g<d;g++)l=c[g],(k=a[l])?(e[f++]=new RegExp(b?"(?!\\b)"+l+"(\\b|_)":l,"g"),e[f++]=k):h+=(h?"|":"")+l;h&&(e[f++]=new RegExp(b?"(?!\\b)("+h+")(\\b|_)":"("+h+")","g"),e[f]="");return e}function C(a,b){for(var c=0,d=b.length;c<d&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a};var E={},F={};var G=Promise;function H(a,b,c){return I.call(this,this.add,arguments)}function J(a,b,c){return I.call(this,this.append,arguments)}function K(a,b,c){return I.call(this,this.search,arguments)}function L(a,b,c){return I.call(this,this.update,arguments)}function M(a,b){return I.call(this,this.remove,arguments)}function I(a,b){for(var c,d=0;d<b.length;d++)if("function"===typeof b[d]){c=b[d];delete b[d];break}var e=this;d=new G(function(h){setTimeout(function(){h(a.apply(e,b))})});return c?(d.then(c),this):d};function N(a,b,c){var d=a.length,e=[],h=x(),f=0;c&&(c=[]);for(var g=0;g<d;g++){for(var l=a[g],k=l.length,n=x(),m=!g,p=0;p<k;p++){var q=l[p],u=q.length;if(u){c&&(c[p]=[]);for(var v=0,y=0,w;v<u;v++)if(w=q[v],!g)n[w]=1;else if(h[w]){if(g===d-1){if(e[f++]=w,f===b)return e}else c&&y<b&&(c[p][y++]=w),n[w]=1;m=!0}}}if(!m&&!c)return[];h=n}if(c)for(a=c.length-1;0<=a;a--)if(h=(d=c[a])&&d.length){if(f+h>=b)return e.concat(d.slice(0,b-f));e=e.concat(d);f+=h}return e};var O={memory:{charset:"latin:extra",m:3,j:3,u:!1,l:"memory"},performance:{threshold:8,j:3,context:{depth:1,s:!0}},match:{charset:"latin:extra",D:"full",m:3},score:{charset:"latin:advanced",threshold:1,context:{depth:3,s:!0}},"default":{m:3,threshold:0,depth:3}};function P(a,b){if(!(this instanceof P))return new P(a);var c;if(a){"string"===typeof a?a=O[a]:(c=a.preset)&&(a=Object.assign({},O[c],a));c=a.charset;var d=a.lang;"string"===typeof c&&(-1===c.indexOf(":")&&(c+=":default"),c=F[c]);"string"===typeof d&&(d=E[d])}else a={};var e,h=a.context||{};this.encode=a.encode||c&&c.encode||B;this.register=b||x();var f=a.resolution||9;var g=a.threshold||0;g>=f&&(g=f-1);this.m=f;this.threshold=g;this.v=b=c&&c.D||a.tokenize||"strict";this.depth="strict"===b&&h.depth; (function(){'use strict';var w;function aa(a){function b(c){return a.next(c)}function d(c){return a.throw(c)}return new Promise(function(c,e){function g(f){f.done?c(f.value):Promise.resolve(f.value).then(b,d).then(g,e)}g(a.next())})};const x=/[\W_]+/;function ba(a){if(a=a.toLowerCase())if(a&&this.A&&(a=y(a,this.A)),this.C&&1<a.length&&(a=y(a,this.C)),a&&(x||""===x)&&(a=a.split(x),this.filter)){var b=this.filter;const d=a.length,c=[];for(let e=0,g=0;e<d;e++){const f=a[e];f&&!b[f]&&(c[g++]=f)}a=c}return a};function A(a,b){return"undefined"!==typeof a?a:b}function E(a){const b=Array(a);for(let d=0;d<a;d++)b[d]=G();return b}function G(){return Object.create(null)}function ca(a,b){return b.length-a.length}function H(a){return"string"===typeof a}function I(a){return"object"===typeof a}function J(a){return"function"===typeof a};function da(a,b){const d=Object.keys(a),c=d.length,e=[];let g="",f=0;for(let h=0,l,k;h<c;h++)l=d[h],(k=a[l])?(e[f++]=new RegExp(b?"(?!\\b)"+l+"(\\b|_)":l,"g"),e[f++]=k):g+=(g?"|":"")+l;g&&(e[f++]=new RegExp(b?"(?!\\b)("+g+")(\\b|_)":"("+g+")","g"),e[f]="");return e}function y(a,b){for(let d=0,c=b.length;d<c&&(a=a.replace(b[d],b[d+1]),a);d+=2);return a};const ea={},fa={};let ha=Promise;function ia(a){N(a,"add");N(a,"append");N(a,"search");N(a,"update");N(a,"remove")}function N(a,b){a[b+"Async"]=function(){const d=this,c=arguments;var e=c[c.length-1];let g;J(e)&&(g=e,delete c[c.length-1]);e=new ha(function(f){setTimeout(function(){const h=d[b];h.async=!0;f(h.apply(d,c));h.async=!1})});return g?(e.then(g),this):e}};function ja(a,b,d,c){const e=a.length;let g=[],f=G(),h=0;c&&(c=[]);for(let l=0;l<e;l++){const k=a[l],r=k.length,q=G();let t=!l;for(let m=0;m<r;m++){const v=k[m],p=v.length;if(p){c&&(c[m]=[]);for(let z=0,u=0,n;z<p;z++)if(n=v[z],!l)q[n]=1;else if(f[n]){if(l===e-1)if(d)d--;else{if(g[h++]=n,h===b)return g}else c&&u<b&&(c[m][u++]=n),q[n]=1;t=!0}}}if(!t&&!c)return[];f=q}if(c)for(let l=c.length-1,k,r;0<=l;l--)if(r=(k=c[l])&&k.length){if(h+r>=b)return g.concat(k.slice(0,b-h));g=g.concat(k);h+=r}return g}
this.s=Q(h.bidirectional,!0);this.l=e="memory"===a.optimize;this.u=Q(a.fastupdate,!0);this.j=a.minlength||1;this.g=e?t(f-g):x();f=h.resolution||f;g=h.threshold||g;g>=f&&(g=f-1);this.h=f;this.o=g;this.i=e?t(f-g):x();this.B=c&&c.B||a.rtl;this.A=(b=a.matcher||d&&d.A)&&D(b,!1);this.C=(b=a.stemmer||d&&d.C)&&D(b,!0);if(a=b=a.filter||d&&d.filter){a=b;c=x();d=0;for(b=a.length;d<b;d++)c[a[d]]=1;a=c}this.filter=a}function Q(a,b){return"undefined"!==typeof a?a:b}r=P.prototype; ;const ka={memory:{charset:"latin:extra",m:3,j:3,s:!1,l:"memory"},performance:{threshold:8,j:3,context:{depth:1,u:!0}},match:{charset:"latin:extra",H:"full",m:3},score:{charset:"latin:advanced",threshold:1,context:{depth:3,u:!0}},"default":{m:3,threshold:0,depth:3}};function O(a,b){if(!(this instanceof O))return new O(a);var d;let c;a?(H(a)?a=ka[a]:(d=a.preset)&&(a=Object.assign({},ka[d],a)),d=a.charset,c=a.lang,H(d)&&(-1===d.indexOf(":")&&(d+=":default"),d=fa[d]),H(c)&&(c=ea[c])):a={};let e,g,f,h=a.context||{};this.encode=a.encode||d&&d.encode||ba;this.register=b||G();e=a.resolution||9;g=a.threshold||0;g>=e&&(g=e-1);this.m=e;this.threshold=g;this.v=b=d&&d.H||a.tokenize||"strict";this.depth="strict"===b&&h.depth;this.u=A(h.bidirectional,!0);this.l=f="memory"===
r.append=function(a,b){return this.add(a,b,!0)}; a.optimize;this.s=A(a.fastupdate,!0);this.j=a.minlength||1;this.g=f?E(e-g):G();e=h.resolution||e;g=h.threshold||g;g>=e&&(g=e-1);this.h=e;this.o=g;this.i=f?E(e-g):G();this.B=d&&d.B||a.rtl;this.A=(b=a.matcher||c&&c.A)&&da(b,!1);this.C=(b=a.stemmer||c&&c.C)&&da(b,!0);if(a=b=a.filter||c&&c.filter){a=b;d=G();for(let l=0,k=a.length;l<k;l++)d[a[l]]=1;a=d}this.filter=a}w=O.prototype;w.append=function(a,b){return this.add(a,b,!0)};
r.add=function(a,b,c){if(this.register[a]&&!c)return this.update(a,b);if(b&&(a||0===a)){b=this.encode(b);var d=b.length;if(d){for(var e=this.depth,h=this.m-this.threshold,f=x(),g=x(),l=0;l<d;l++){var k=b[this.B?d-1-l:l],n=k.length;if(k&&n>=this.j&&(e||!f[k])){var m=Math.min(this.m/d*l|0,l);if(m<h){var p="";switch(this.v){case "full":if(3<n){for(var q=0;q<n;q++){var u=q?Math.min(m/2+this.m/n*q/2|0,m+q):m;if(u<h)for(var v=n;v>q;v--)p=k.substring(q,v),p.length>=this.j&&R(this,f,p,u,a,c)}break}case "reverse":if(2< w.add=function(a,b,d){if(this.register[a]&&!d)return this.update(a,b);if(b&&(a||0===a)){b=this.encode(b);const k=b.length;if(k){const r=this.depth,q=this.m-this.threshold,t=G(),m=G();for(let v=0;v<k;v++){let p=b[this.B?k-1-v:v];var c=p.length;if(p&&c>=this.j&&(r||!t[p])){var e=Math.min(this.m/k*v|0,v);if(e<q){var g="";switch(this.v){case "full":if(3<c){for(var f=0;f<c;f++){var h=f?Math.min(e/2+this.m/c*f/2|0,e+f):e;if(h<q)for(var l=c;l>f;l--)g=p.substring(f,l),g.length>=this.j&&P(this,t,g,h,a,d)}break}case "reverse":if(2<
n){for(q=n-1;0<q;q--)p=k[q]+p,p.length>=this.j&&R(this,f,p,m,a,c);p=""}case "forward":if(1<n)for(q=0;q<n;q++)p+=k[q],p.length>=this.j&&R(this,f,p,m,a,c);break;default:if(R(this,f,k,m,a,c),e&&1<d&&l<d-1)for(n=this.h-this.o,m=x(),p=k,q=Math.min(e+1,d-l),u=m[p]=1;u<q;u++)if((k=b[this.B?d-1-l-u:l+u])&&k.length>=this.j&&!m[k]){if(m[k]=1,v=Math.min((this.h-q)/d*l+u|0,l+(u-1)),v<n){var y=this.s&&k>p;R(this,g,y?p:k,v,a,c,y?k:p)}}else q=Math.min(q+1,d-l)}}}}this.u||(this.register[a]=1)}}return this}; c){for(f=c-1;0<f;f--)g=p[f]+g,g.length>=this.j&&P(this,t,g,e,a,d);g=""}case "forward":if(1<c)for(f=0;f<c;f++)g+=p[f],g.length>=this.j&&P(this,t,g,e,a,d);break;default:if(P(this,t,p,e,a,d),r&&1<k&&v<k-1)for(c=this.h-this.o,e=G(),g=p,f=Math.min(r+1,k-v),e[g]=1,h=1;h<f;h++)if((p=b[this.B?k-1-v-h:v+h])&&p.length>=this.j&&!e[p]){if(e[p]=1,l=Math.min((this.h-f)/k*v+h|0,v+(h-1)),l<c){const z=this.u&&p>g;P(this,m,z?g:p,l,a,d,z?p:g)}}else f=Math.min(f+1,k-v)}}}}this.s||(this.register[a]=1)}}return this};
function R(a,b,c,d,e,h,f){var g=f?a.i:a.g;if(!b[c]||f&&!b[c][f])a.l&&(g=g[d]),f?(b[c]||(b[c]=x()),b[c][f]=1,g=g[f]||(g[f]=x())):b[c]=1,g=g[c]||(g[c]=[]),a.l||(g=g[d]||(g[d]=[])),h&&-1!==g.indexOf(e)||(g[g.length]=e,a.u&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=g))} function P(a,b,d,c,e,g,f){let h=f?a.i:a.g;if(!b[d]||f&&!b[d][f])a.l&&(h=h[c]),f?(b[d]||(b[d]=G()),b[d][f]=1,h=h[f]||(h[f]=G())):b[d]=1,h=h[d]||(h[d]=[]),a.l||(h=h[c]||(h[c]=[])),g&&-1!==h.indexOf(e)||(h[h.length]=e,a.s&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=h))}
r.search=function(a,b,c){"object"===typeof a?(c=a,a=c.query):"object"===typeof b&&(c=b);var d=[],e=this.threshold;if(c){b=c.limit;e=Q(c.threshold,e);var h=c.context;var f=c.suggest}if(a){a=this.encode(a);var g=a.length;if(1<g){c=x();for(var l=[],k=0,n=0,m;k<g;k++)if((m=a[k])&&m.length>=this.j&&!c[m])if(this.l||f||this.g[m])l[n++]=m,c[m]=1;else return d;a=l;g=a.length}}if(!g)return d;b||(b=100);c=this.m-e;e=this.h-e;h=this.depth&&1<g&&!1!==h;l=0;if(h){var p=a[0];l=1}else 1<g&&a.sort(z);for(;l<g;l++){n= w.search=function(a,b,d){I(a)?(d=a,a=d.query):I(b)&&(d=b);let c=[],e;var g=this.threshold;let f,h=0;if(d){b=d.limit;h=d.offset||0;g=A(d.threshold,g);var l=d.context;f=d.suggest}if(a&&(a=this.encode(a),e=a.length,1<e)){d=G();var k=[];for(let q=0,t=0,m;q<e;q++)if((m=a[q])&&m.length>=this.j&&!d[m])if(this.l||f||this.g[m])k[t++]=m,d[m]=1;else return c;a=k;e=a.length}if(!e)return c;b||(b=100);d=this.m-g;g=this.h-g;l=this.depth&&1<e&&!1!==l;k=0;let r;l?(r=a[0],k=1):1<e&&a.sort(ca);for(let q,t;k<e;k++){t=
a[l];h?(k=S(this,d,f,e,b,2===g,n,p),f&&!1===k&&d.length||(p=n)):k=S(this,d,f,c,b,1===g,n);if(k)return k;if(f&&l===g-1){k=d.length;if(!k){if(h){h=0;l=-1;continue}return d}if(1===k)return d=d[0],d=1===d.length?d[0]:[].concat.apply([],d),d.length>b?d.slice(0,b):d}}return N(d,b,f)};function T(a,b,c,d){c?(d=d&&b>c,a=(a=a[d?b:c])&&a[d?c:b]):a=a[b];return a} a[k];l?(q=la(this,c,f,g,b,2===e,t,r),f&&!1===q&&c.length||(r=t)):q=la(this,c,f,d,b,1===e,t);if(q)return q;if(f&&k===e-1){let m=c.length;if(!m){if(l){l=0;k=-1;continue}return c}if(1===m)return c=c[0],c=1===c.length?c[0]:[].concat.apply([],c),c.length>b?c.slice(0,b):c}}return ja(c,b,h,f)};function ma(a,b,d,c){d?(c=c&&b>d,a=(a=a[c?b:d])&&a[c?d:b]):a=a[b];return a}
function S(a,b,c,d,e,h,f,g){var l=[],k=g?a.i:a.g;a.l||(k=T(k,f,g,a.s));if(k){var n=0;d=Math.min(k.length,d);for(var m=0,p=0,q;m<d&&!(q=k[m],a.l&&(q=T(q,f,g,a.s)),q&&(l[n++]=q,h&&(p+=q.length,p>=e)));m++);if(n){if(h)return l=1===n?l[0]:[].concat.apply([],l),l.length>e?l.slice(0,e):l;b[b.length]=l;return}}return!c&&l}r.contain=function(a){return!!this.register[a]};r.update=function(a,b){return this.remove(a).add(a,b)}; function la(a,b,d,c,e,g,f,h){let l=[],k=h?a.i:a.g;a.l||(k=ma(k,f,h,a.u));if(k){let r=0;c=Math.min(k.length,c);for(let q=0,t=0,m;q<c&&!(m=k[q],a.l&&(m=ma(m,f,h,a.u)),m&&(l[r++]=m,g&&(t+=m.length,t>=e)));q++);if(r){if(g)return l=1===r?l[0]:[].concat.apply([],l),l.length>e?l.slice(0,e):l;b[b.length]=l;return}}return!d&&l}w.contain=function(a){return!!this.register[a]};w.update=function(a,b){return this.remove(a).add(a,b)};
r.remove=function(a,b){var c=this.register[a];if(c){if(this.u)for(var d=0,e;d<c.length;d++)e=c[d],e.splice(e.indexOf(a),1);else U(this.g,a,this.m-this.threshold,this.l),this.depth&&U(this.i,a,this.h-this.o,this.l);b||delete this.register[a]}return this}; w.remove=function(a,b){const d=this.register[a];if(d){if(this.s)for(let c=0,e;c<d.length;c++)e=d[c],e.splice(e.indexOf(a),1);else Q(this.g,a,this.m-this.threshold,this.l),this.depth&&Q(this.i,a,this.h-this.o,this.l);b||delete this.register[a]}return this};
function U(a,b,c,d,e){var 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(var f=0,g;f<e;f++)if(g=a[f])h=U(g,b,c,d,e),d||h||delete a[f]}else for(f in a)(h=U(a[f],b,c,d,e))||delete a[f];return h}r.addAsync=H;r.appendAsync=J;r.searchAsync=K;r.updateAsync=L;r.removeAsync=M;function V(a){if(!(this instanceof V))return new V(a);var b;a||(a={});this.v=[];this.g=[];this.i=[];this.register=x();this.key=(b=a.key)&&W(b,this.i)||"id";b=a.fastupdate;this.u="undefined"!==typeof b?b:!0;this.store=(b=a.store)&&x();this.h=b&&!0!==b&&[];b=a;a=x();var c=b.doc;if("string"===typeof c)c=[c];else if(c.constructor!==Array){var d=c;c=Object.keys(c)}for(var e=0,h,f;e<c.length;e++)h=c[e],d?(f=d[h],f="object"===typeof f?Object.assign({},b,f):b):f=b,a[h]=new P(f,this.register),this.v[e]=W(h, function Q(a,b,d,c,e){let 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,d);for(let f=0,h;f<e;f++)if(h=a[f])g=Q(h,b,d,c,e),c||g||delete a[f]}else for(let f in a)(g=Q(a[f],b,d,c,e))||delete a[f];return g}ia(O.prototype);let na=0;function R(a){if(I(a)){var b=a;a=0}J(b.encode)&&(b.encode=b.encode.toString());const d=this;this.id=a||na++;this.h=null;this.g=new Worker("worker.js",{type:"module"});this.g.onmessage=function(c){d.h(c.data)};this.g.postMessage({G:"create",options:b})}S("add");S("append");S("search");S("update");S("remove");
this.i),this.g[e]=h;if(this.h)for(d=b.store,"string"===typeof d&&(d=[d]),b=0;b<d.length;b++)this.h[b]=W(d[b],this.i);this.o=a}function W(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 S(a){R.prototype[a]=R.prototype[a+"Async"]=function(){const b=this,d=[].slice.call(arguments);var c=d[d.length-1];let e;J(c)&&(e=c,d.splice(d.length-1,1));c=new ha(function(g){b.g.postMessage({G:a,I:d});"search"===a?b.h=g:g()});return e?(c.then(e),this):c}};function T(a){if(!(this instanceof T))return new T(a);var b;a||(a={});this.D=[];this.g=[];this.o=[];this.register=G();this.key=(b=a.key)&&U(b,this.o)||"id";this.s=A(a.fastupdate,!0);this.store=(b=a.store)&&G();this.h=b&&!0!==b&&[];this.async=!1;b=a;a=G();let d=b.doc;if(H(d))d=[d];else if(d.constructor!==Array){var c=d;d=Object.keys(d)}for(let e=0,g,f;e<d.length;e++)g=d[e],H(g)?c&&(f=c[g]):(f=g,g=g.field),f=I(f)?Object.assign({},b,f):b,a[g]=this.v?new R(f):new O(f,this.register),this.D[e]=U(g,this.o),
function X(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++)X(a,b,c,d,e);else b=b[e]||(b[e]=x()),e=c[++d],X(a,b,c,d,e)}function Y(a,b,c,d,e,h,f,g){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);return}a=a.join(" ")}e.add(h,a,g)}else if(a)if(a.constructor===Array)for(f=0;f<a.length;f++)Y(a,b,c,d,e,h,f,g);else f=b[++d],Y(a,b,c,d,e,h,f,g)}r=V.prototype; this.g[e]=g;if(this.h)for(c=b.store,H(c)&&(c=[c]),b=0;b<c.length;b++)this.h[b]=U(c[b],this.o);this.i=a}function U(a,b){const d=a.split(":");let c=0;for(let e=0;e<d.length;e++)a=d[e],0<=a.indexOf("[]")&&(a=a.substring(0,a.length-2))&&(b[c]=!0),a&&(d[c++]=a);c<d.length&&(d.length=c);return 1<c?d:d[0]}function Y(a,b,d,c,e){a=a[e];if(c===d.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,d,c,e);else b=b[e]||(b[e]=G()),e=d[++c],Y(a,b,d,c,e)}
r.add=function(a,b,c){if("object"===typeof a){a=b=a;var d=this.key;if("string"===typeof d)a=a[d];else for(var e=0;a&&e<d.length;e++)a=a[d[e]]}if(b&&(a||0===a)){if(this.register[a])return this.update(a,b);d=0;for(var h;d<this.g.length;d++)h=this.g[d],e=this.v[d],"string"===typeof e&&(e=[e]),Y(b,e,this.i,0,this.o[h],a,e[0],c);if(this.store){if(this.h){var f=x();for(c=0;c<this.h.length;c++)d=this.h[c],"string"===typeof d?f[d]=b[d]:X(b,f,d,0,d[0])}this.store[a]=f||b}}return this}; function Z(a,b,d,c,e,g,f,h){a=a[f];if(c===b.length-1){if(a.constructor===Array){if(d[c]){for(b=0;b<a.length;b++)e.add(g,a[b],!0);return}a=a.join(" ")}e.add(g,a,h)}else if(a)if(a.constructor===Array)for(f=0;f<a.length;f++)Z(a,b,d,c,e,g,f,h);else f=b[++c],Z(a,b,d,c,e,g,f,h)}w=T.prototype;
r.append=function(a,b){return this.add(a,b,!0)};r.update=function(a,b){return this.remove(a).add(a,b)};r.remove=function(a){"object"===typeof a&&(a=a[this.key]);if(this.register[a]){for(var b=0;b<this.g.length;b++)this.o[this.g[b]].remove(a,!0);this.store&&delete this.store[a];delete this.register[a]}return this}; w.add=function(a,b,d){if(I(a)){a=b=a;var c=this.key;if(H(c))a=a[c];else for(let e=0;a&&e<c.length;e++)a=a[c[e]]}if(b&&(a||0===a)){if(this.register[a])return this.update(a,b);for(let e=0,g,f;e<this.g.length;e++)f=this.g[e],g=this.D[e],H(g)&&(g=[g]),Z(b,g,this.o,0,this.i[f],a,g[0],d);if(this.store){let e;if(this.h){e=G();for(let g=0,f;g<this.h.length;g++)f=this.h[g],H(f)?e[f]=b[f]:Y(b,e,f,0,f[0])}this.store[a]=e||b}}return this};w.append=function(a,b){return this.add(a,b,!0)};
r.search=function(a,b,c){"object"===typeof a?(c=a,a=c.query):"object"===typeof b&&(c=b);var d=[],e,h=0;if(c){var f=(e=c.pluck)||c.field;var g=c.tag;var l=c.enrich;var k="and"===c.bool;b=c.limit;if(f)if("string"===typeof f)f=[f];else if(f.constructor!==Array){var n=f;f=Object.keys(f)}}f||(f=this.g);k=k&&(1<f.length||g&&1<g.length);g=0;for(var m,p;g<f.length;g++)if(m=f[g],m=this.o[m].search(a,b,n?n[m]:c),p=m.length)d[h++]=m;else if(k)return[];if(!h)return[];if(e&&(!l||!this.store))return d[0];for(a= w.update=function(a,b){return this.remove(a).add(a,b)};w.remove=function(a){I(a)&&(a=a[this.key]);if(this.register[a]){for(let b=0;b<this.g.length&&(this.i[this.g[b]].remove(a,!0),!this.s||this.v);b++);this.store&&delete this.store[a];delete this.register[a]}return this};
0;a<f.length;a++){b=f[a];c=d[a];if(c.length&&l&&this.store){n=Array(c.length);for(k=0;k<c.length;k++)h=c[k],n[k]={key:h,doc:this.store[h]};c=n}if(e)return c;d[a]={field:b,result:c}}return d};r.contain=function(a){return!!this.register[a]};r.get=function(a){return this.store[a]};r.set=function(a,b){this.store[a]=b;return this};r.addAsync=H;r.appendAsync=J;r.searchAsync=K;r.updateAsync=L;r.removeAsync=M;window.FlexSearch={Index:P,Document:V,registerCharset:function(a,b){F[a]=b},registerLanguage:function(a,b){E[a]=b}};}).call(this); w.search=function(a,b,d){const c=this;return aa(function*(){I(a)?(d=a,a=d.query):I(b)&&(d=b,b=0);let e=[];var g=[],f;let h;let l,k,r,q,t=0;if(d)if(d.constructor===Array){var m=d;d=null}else if(m=(f=d.pluck)||d.field||d.doc,k=!1,h=c.store&&d.enrich,r="and"===d.bool,b=d.limit||100,q=d.offset||0,m&&(H(m)?m=[m]:m.constructor!==Array&&(l=m,m=Object.keys(m))),k&&(H(k)&&(k=[k]),!a)){for(let u=0,n;u<k.length;u++){g=k[u];if((m=(f=c.F[g])&&f.length-q)&&0<m){if(m>b||q)f=f.slice(q,q+b);h&&(f=oa.call(c,f));n=
{tag:g,result:f}}else n=void 0;n&&(e[e.length]=n,t++)}return t?e:[]}m||(m=c.g);r=r&&(1<m.length||k&&1<k.length);let v=[];if(c.v||c.async){for(let u=0,n;u<m.length;u++){var p=void 0;n=m[u];H(n)?l&&(p=l[n]):(p=n,n=n.field);v[u]=c.i[n].searchAsync(a,b,p||d)}v=yield Promise.all(v)}for(let u=0,n,B,K;u<m.length;u++){let V;B=m[u];H(B)?l&&(V=l[B]):(V=B,B=B.field);n=c.v||c.async?v[u]:c.i[B].search(a,b,V||d);K=n.length;if(k&&K){var z=[];p=0;r&&(z[0]=[n]);for(let F=0,L,C;F<k.length;F++)if(L=k[F],K=(C=c.F[L])&&
C.length)p++,z[z.length]=r?[C]:C;if(p){if(r)p=ja(z,b||100,q||0);else{p=n;const F=G(),L=G(),C=[];for(let D=0;D<p.length;D++)F[p[D]]=1;for(let D=0,W;D<z.length;D++){W=z[D];for(let X=0,M;X<W.length;X++)M=W[X],F[M]&&!L[M]&&(L[M]=1,C[C.length]=M)}p=C}n=p;K=n.length}}if(K)g[t]=B,e[t++]=n;else if(r)return[]}if(!t)return[];if(f&&(!h||!c.store))return e[0];for(let u=0,n;u<g.length;u++){n=e[u];n.length&&h&&(n=oa.call(c,n));if(f)return n;e[u]={field:g[u],result:n}}return e}())};
function oa(a){const b=Array(a.length);for(let d=0,c;d<a.length;d++)c=a[d],b[d]={key:c,doc:this.store[c]};return b}w.contain=function(a){return!!this.register[a]};w.get=function(a){return this.store[a]};w.set=function(a,b){this.store[a]=b;return this};ia(T.prototype);window.FlexSearch={Index:O,Document:T,registerCharset:function(a,b){fa[a]=b},registerLanguage:function(a,b){ea[a]=b}};}).call(this);

View File

@@ -1,17 +1,17 @@
/**! /**!
* FlexSearch.js v0.7.0-pre-alpha (Light) * FlexSearch.js v0.7.0-beta (Light)
* Copyright 2019 Nextapps GmbH * Copyright 2019 Nextapps GmbH
* Author: Thomas Wilkerling * Author: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function(){function r(a){for(var b=Array(a),c=0;c<a;c++)b[c]=v();return b}function v(){return Object.create(null)}function y(a,b){return b.length-a.length};var z=/[\W_]+/;function A(a){if(a=a.toLowerCase())if(a&&this.o&&(a=B(a,this.o)),this.A&&1<a.length&&(a=B(a,this.A)),a&&(z||""===z)&&(a=a.split(z),this.filter)){for(var b=this.filter,c=a.length,d=[],g=0,k=0;g<c;g++){var e=a[g];e&&!b[e]&&(d[k++]=e)}a=d}return a};function C(a,b){for(var c=Object.keys(a),d=c.length,g=[],k="",e=0,f=0,h,l;f<d;f++)h=c[f],(l=a[h])?(g[e++]=new RegExp(b?"(?!\\b)"+h+"(\\b|_)":h,"g"),g[e++]=l):k+=(k?"|":"")+h;k&&(g[e++]=new RegExp(b?"(?!\\b)("+k+")(\\b|_)":"("+k+")","g"),g[e]="");return g}function B(a,b){for(var c=0,d=b.length;c<d&&(a=a.replace(b[c],b[c+1]),a);c+=2);return a};var D={},E={};function F(a,b,c){var d=a.length,g=[],k=v(),e=0;c&&(c=[]);for(var f=0;f<d;f++){for(var h=a[f],l=h.length,p=v(),q=!f,n=0;n<l;n++){var m=h[n],t=m.length;if(t){c&&(c[n]=[]);for(var u=0,x=0,w;u<t;u++)if(w=m[u],!f)p[w]=1;else if(k[w]){if(f===d-1){if(g[e++]=w,e===b)return g}else c&&x<b&&(c[n][x++]=w),p[w]=1;q=!0}}}if(!q&&!c)return[];k=p}if(c)for(a=c.length-1;0<=a;a--)if(k=(d=c[a])&&d.length){if(e+k>=b)return g.concat(d.slice(0,b-e));g=g.concat(d);e+=k}return g};function G(a,b){if(!(this instanceof G))return new G(a);if(a){var c=a.charset;var d=a.lang;"string"===typeof c&&(-1===c.indexOf(":")&&(c+=":default"),c=E[c]);"string"===typeof d&&(d=D[d])}else a={};var g,k=a.context||{};this.encode=a.encode||c&&c.encode||A;this.register=b||v();var e=a.resolution||9;var f=a.threshold||0;f>=e&&(f=e-1);this.i=e;this.s=f;this.F=b=c&&c.G||a.tokenize||"strict";this.m="strict"===b&&k.depth;this.v=H(k.bidirectional,!0);this.g=g="memory"===a.optimize;this.C=H(a.fastupdate, (function(){'use strict';const u=/[\W_]+/;function v(a){if(a=a.toLowerCase())if(a&&this.o&&(a=y(a,this.o)),this.A&&1<a.length&&(a=y(a,this.A)),a&&(u||""===u)&&(a=a.split(u),this.filter)){var c=this.filter;const d=a.length,b=[];for(let e=0,g=0;e<d;e++){const f=a[e];f&&!c[f]&&(b[g++]=f)}a=b}return a};function z(a,c){return"undefined"!==typeof a?a:c}function A(a){const c=Array(a);for(let d=0;d<a;d++)c[d]=B();return c}function B(){return Object.create(null)}function C(a,c){return c.length-a.length};function D(a,c){const d=Object.keys(a),b=d.length,e=[];let g="",f=0;for(let h=0,k,l;h<b;h++)k=d[h],(l=a[k])?(e[f++]=new RegExp(c?"(?!\\b)"+k+"(\\b|_)":k,"g"),e[f++]=l):g+=(g?"|":"")+k;g&&(e[f++]=new RegExp(c?"(?!\\b)("+g+")(\\b|_)":"("+g+")","g"),e[f]="");return e}function y(a,c){for(let d=0,b=c.length;d<b&&(a=a.replace(c[d],c[d+1]),a);d+=2);return a};const E={},F={};function G(a,c,d,b){const e=a.length;let g=[],f=B(),h=0;b&&(b=[]);for(let k=0;k<e;k++){const l=a[k],r=l.length,n=B();let p=!k;for(let m=0;m<r;m++){const t=l[m],q=t.length;if(q){b&&(b[m]=[]);for(let w=0,H=0,x;w<q;w++)if(x=t[w],!k)n[x]=1;else if(f[x]){if(k===e-1)if(d)d--;else{if(g[h++]=x,h===c)return g}else b&&H<c&&(b[m][H++]=x),n[x]=1;p=!0}}}if(!p&&!b)return[];f=n}if(b)for(let k=b.length-1,l,r;0<=k;k--)if(r=(l=b[k])&&l.length){if(h+r>=c)return g.concat(l.slice(0,c-h));g=g.concat(l);h+=r}return g};function I(a,c){if(!(this instanceof I))return new I(a);let d;if(a){var b=a.charset;d=a.lang;"string"===typeof b&&(-1===b.indexOf(":")&&(b+=":default"),b=F[b]);"string"===typeof d&&(d=E[d])}else a={};let e,g,f,h=a.context||{};this.encode=a.encode||b&&b.encode||v;this.register=c||B();e=a.resolution||9;g=a.threshold||0;g>=e&&(g=e-1);this.i=e;this.s=g;this.F=c=b&&b.G||a.tokenize||"strict";this.m="strict"===c&&h.depth;this.v=z(h.bidirectional,!0);this.g=f="memory"===a.optimize;this.C=z(a.fastupdate,!0);
!0);this.h=a.minlength||1;this.j=g?r(e-f):v();e=k.resolution||e;f=k.threshold||f;f>=e&&(f=e-1);this.l=e;this.D=f;this.B=g?r(e-f):v();this.u=c&&c.u||a.rtl;this.o=(b=a.matcher||d&&d.o)&&C(b,!1);this.A=(b=a.stemmer||d&&d.A)&&C(b,!0);if(a=b=a.filter||d&&d.filter){a=b;c=v();d=0;for(b=a.length;d<b;d++)c[a[d]]=1;a=c}this.filter=a}function H(a,b){return"undefined"!==typeof a?a:b}G.prototype.append=function(a,b){return this.add(a,b,!0)}; this.h=a.minlength||1;this.j=f?A(e-g):B();e=h.resolution||e;g=h.threshold||g;g>=e&&(g=e-1);this.l=e;this.D=g;this.B=f?A(e-g):B();this.u=b&&b.u||a.rtl;this.o=(c=a.matcher||d&&d.o)&&D(c,!1);this.A=(c=a.stemmer||d&&d.A)&&D(c,!0);if(a=c=a.filter||d&&d.filter){a=c;b=B();for(let k=0,l=a.length;k<l;k++)b[a[k]]=1;a=b}this.filter=a}I.prototype.append=function(a,c){return this.add(a,c,!0)};
G.prototype.add=function(a,b,c){if(this.register[a]&&!c)return this.update(a,b);if(b&&(a||0===a)){b=this.encode(b);var d=b.length;if(d){for(var g=this.m,k=this.i-this.s,e=v(),f=v(),h=0;h<d;h++){var l=b[this.u?d-1-h:h],p=l.length;if(l&&p>=this.h&&(g||!e[l])){var q=Math.min(this.i/d*h|0,h);if(q<k){var n="";switch(this.F){case "full":if(3<p){for(var m=0;m<p;m++){var t=m?Math.min(q/2+this.i/p*m/2|0,q+m):q;if(t<k)for(var u=p;u>m;u--)n=l.substring(m,u),n.length>=this.h&&I(this,e,n,t,a,c)}break}case "reverse":if(2< I.prototype.add=function(a,c,d){if(this.register[a]&&!d)return this.update(a,c);if(c&&(a||0===a)){c=this.encode(c);const l=c.length;if(l){const r=this.m,n=this.i-this.s,p=B(),m=B();for(let t=0;t<l;t++){let q=c[this.u?l-1-t:t];var b=q.length;if(q&&b>=this.h&&(r||!p[q])){var e=Math.min(this.i/l*t|0,t);if(e<n){var g="";switch(this.F){case "full":if(3<b){for(var f=0;f<b;f++){var h=f?Math.min(e/2+this.i/b*f/2|0,e+f):e;if(h<n)for(var k=b;k>f;k--)g=q.substring(f,k),g.length>=this.h&&J(this,p,g,h,a,d)}break}case "reverse":if(2<
p){for(m=p-1;0<m;m--)n=l[m]+n,n.length>=this.h&&I(this,e,n,q,a,c);n=""}case "forward":if(1<p)for(m=0;m<p;m++)n+=l[m],n.length>=this.h&&I(this,e,n,q,a,c);break;default:if(I(this,e,l,q,a,c),g&&1<d&&h<d-1)for(p=this.l-this.D,q=v(),n=l,m=Math.min(g+1,d-h),t=q[n]=1;t<m;t++)if((l=b[this.u?d-1-h-t:h+t])&&l.length>=this.h&&!q[l]){if(q[l]=1,u=Math.min((this.l-m)/d*h+t|0,h+(t-1)),u<p){var x=this.v&&l>n;I(this,f,x?n:l,u,a,c,x?l:n)}}else m=Math.min(m+1,d-h)}}}}this.C||(this.register[a]=1)}}return this}; b){for(f=b-1;0<f;f--)g=q[f]+g,g.length>=this.h&&J(this,p,g,e,a,d);g=""}case "forward":if(1<b)for(f=0;f<b;f++)g+=q[f],g.length>=this.h&&J(this,p,g,e,a,d);break;default:if(J(this,p,q,e,a,d),r&&1<l&&t<l-1)for(b=this.l-this.D,e=B(),g=q,f=Math.min(r+1,l-t),e[g]=1,h=1;h<f;h++)if((q=c[this.u?l-1-t-h:t+h])&&q.length>=this.h&&!e[q]){if(e[q]=1,k=Math.min((this.l-f)/l*t+h|0,t+(h-1)),k<b){const w=this.v&&q>g;J(this,m,w?g:q,k,a,d,w?q:g)}}else f=Math.min(f+1,l-t)}}}}this.C||(this.register[a]=1)}}return this};
function I(a,b,c,d,g,k,e){var f=e?a.B:a.j;if(!b[c]||e&&!b[c][e])a.g&&(f=f[d]),e?(b[c]||(b[c]=v()),b[c][e]=1,f=f[e]||(f[e]=v())):b[c]=1,f=f[c]||(f[c]=[]),a.g||(f=f[d]||(f[d]=[])),k&&-1!==f.indexOf(g)||(f[f.length]=g,a.C&&(a=a.register[g]||(a.register[g]=[]),a[a.length]=f))} function J(a,c,d,b,e,g,f){let h=f?a.B:a.j;if(!c[d]||f&&!c[d][f])a.g&&(h=h[b]),f?(c[d]||(c[d]=B()),c[d][f]=1,h=h[f]||(h[f]=B())):c[d]=1,h=h[d]||(h[d]=[]),a.g||(h=h[b]||(h[b]=[])),g&&-1!==h.indexOf(e)||(h[h.length]=e,a.C&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=h))}
G.prototype.search=function(a,b,c){"object"===typeof a?(c=a,a=c.query):"object"===typeof b&&(c=b);var d=[],g=this.s;if(c){b=c.limit;g=H(c.threshold,g);var k=c.context;var e=!1}if(a){a=this.encode(a);var f=a.length;if(1<f){c=v();for(var h=[],l=0,p=0,q;l<f;l++)if((q=a[l])&&q.length>=this.h&&!c[q])if(this.g||e||this.j[q])h[p++]=q,c[q]=1;else return d;a=h;f=a.length}}if(!f)return d;b||(b=100);c=this.i-g;g=this.l-g;k=this.m&&1<f&&!1!==k;h=0;if(k){var n=a[0];h=1}else 1<f&&a.sort(y);for(;h<f;h++){p=a[h]; I.prototype.search=function(a,c,d){"object"===typeof a?(d=a,a=d.query):"object"===typeof c&&(d=c);let b=[],e;var g=this.s;let f,h=0;if(d){c=d.limit;h=d.offset||0;g=z(d.threshold,g);var k=d.context;f=!1}if(a&&(a=this.encode(a),e=a.length,1<e)){d=B();var l=[];for(let n=0,p=0,m;n<e;n++)if((m=a[n])&&m.length>=this.h&&!d[m])if(this.g||f||this.j[m])l[p++]=m,d[m]=1;else return b;a=l;e=a.length}if(!e)return b;c||(c=100);d=this.i-g;g=this.l-g;k=this.m&&1<e&&!1!==k;l=0;let r;k?(r=a[0],l=1):1<e&&a.sort(C);for(let n,
k?(l=J(this,d,e,g,b,2===f,p,n),e&&!1===l&&d.length||(n=p)):l=J(this,d,e,c,b,1===f,p);if(l)return l;if(e&&h===f-1){l=d.length;if(!l){if(k){k=0;h=-1;continue}return d}if(1===l)return d=d[0],d=1===d.length?d[0]:[].concat.apply([],d),d.length>b?d.slice(0,b):d}}return F(d,b,e)};function K(a,b,c,d){c?(d=d&&b>c,a=(a=a[d?b:c])&&a[d?c:b]):a=a[b];return a} p;l<e;l++){p=a[l];k?(n=K(this,b,f,g,c,2===e,p,r),f&&!1===n&&b.length||(r=p)):n=K(this,b,f,d,c,1===e,p);if(n)return n;if(f&&l===e-1){let m=b.length;if(!m){if(k){k=0;l=-1;continue}return b}if(1===m)return b=b[0],b=1===b.length?b[0]:[].concat.apply([],b),b.length>c?b.slice(0,c):b}}return G(b,c,h,f)};function L(a,c,d,b){d?(b=b&&c>d,a=(a=a[b?c:d])&&a[b?d:c]):a=a[c];return a}
function J(a,b,c,d,g,k,e,f){var h=[],l=f?a.B:a.j;a.g||(l=K(l,e,f,a.v));if(l){var p=0;d=Math.min(l.length,d);for(var q=0,n=0,m;q<d&&!(m=l[q],a.g&&(m=K(m,e,f,a.v)),m&&(h[p++]=m,k&&(n+=m.length,n>=g)));q++);if(p){if(k)return h=1===p?h[0]:[].concat.apply([],h),h.length>g?h.slice(0,g):h;b[b.length]=h;return}}return!c&&h}G.prototype.contain=function(a){return!!this.register[a]};G.prototype.update=function(a,b){return this.remove(a).add(a,b)}; function K(a,c,d,b,e,g,f,h){let k=[],l=h?a.B:a.j;a.g||(l=L(l,f,h,a.v));if(l){let r=0;b=Math.min(l.length,b);for(let n=0,p=0,m;n<b&&!(m=l[n],a.g&&(m=L(m,f,h,a.v)),m&&(k[r++]=m,g&&(p+=m.length,p>=e)));n++);if(r){if(g)return k=1===r?k[0]:[].concat.apply([],k),k.length>e?k.slice(0,e):k;c[c.length]=k;return}}return!d&&k}I.prototype.contain=function(a){return!!this.register[a]};I.prototype.update=function(a,c){return this.remove(a).add(a,c)};
G.prototype.remove=function(a,b){var c=this.register[a];if(c){if(this.C)for(var d=0,g;d<c.length;d++)g=c[d],g.splice(g.indexOf(a),1);else L(this.j,a,this.i-this.s,this.g),this.m&&L(this.B,a,this.l-this.D,this.g);b||delete this.register[a]}return this}; I.prototype.remove=function(a,c){const d=this.register[a];if(d){if(this.C)for(let b=0,e;b<d.length;b++)e=d[b],e.splice(e.indexOf(a),1);else M(this.j,a,this.i-this.s,this.g),this.m&&M(this.B,a,this.l-this.D,this.g);c||delete this.register[a]}return this};
function L(a,b,c,d,g){var k=0;if(a.constructor===Array)if(g)b=a.indexOf(b),-1!==b?1<a.length&&(a.splice(b,1),k++):k++;else{g=Math.min(a.length,c);for(var e=0,f;e<g;e++)if(f=a[e])k=L(f,b,c,d,g),d||k||delete a[e]}else for(e in a)(k=L(a[e],b,c,d,g))||delete a[e];return k};window.FlexSearch={Index:G,Document:null,registerCharset:function(a,b){E[a]=b},registerLanguage:function(a,b){D[a]=b}};}).call(this); function M(a,c,d,b,e){let g=0;if(a.constructor===Array)if(e)c=a.indexOf(c),-1!==c?1<a.length&&(a.splice(c,1),g++):g++;else{e=Math.min(a.length,d);for(let f=0,h;f<e;f++)if(h=a[f])g=M(h,c,d,b,e),b||g||delete a[f]}else for(let f in a)(g=M(a[f],c,d,b,e))||delete a[f];return g};window.FlexSearch={Index:I,Document:null,registerCharset:function(a,c){F[a]=c},registerLanguage:function(a,c){E[a]=c}};}).call(this);

View File

@@ -1,35 +1,31 @@
/**! /**!
* FlexSearch.js v0.7.0-pre-alpha * FlexSearch.js v0.7.0-beta (Bundle)
* Copyright 2019 Nextapps GmbH * Copyright 2019 Nextapps GmbH
* Author: Thomas Wilkerling * Author: Thomas Wilkerling
* Licence: Apache-2.0 * Licence: Apache-2.0
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
*/ */
(function(){'use strict';var t;function aa(a){function b(c){return a.next(c)}function d(c){return a.throw(c)}return new Promise(function(c,e){function f(g){g.done?c(g.value):Promise.resolve(g.value).then(b,d).then(f,e)}f(a.next())})};const x=/[\W_]+/;function ba(a){if(a=a.toLowerCase())if(a&&this.B&&(a=z(a,this.B)),this.F&&1<a.length&&(a=z(a,this.F)),a&&(x||""===x)&&(a=a.split(x),this.filter)){var b=this.filter;const d=a.length,c=[];for(let e=0,f=0;e<d;e++){const g=a[e];g&&!b[g]&&(c[f++]=g)}a=c}return a};function B(a){const b=Array(a);for(let d=0;d<a;d++)b[d]=E();return b}function E(){return Object.create(null)}function ca(a,b){return b.length-a.length};function F(a,b){const d=Object.keys(a),c=d.length,e=[];let f="",g=0;for(let h=0,k,l;h<c;h++)k=d[h],(l=a[k])?(e[g++]=new RegExp(b?"(?!\\b)"+k+"(\\b|_)":k,"g"),e[g++]=l):f+=(f?"|":"")+k;f&&(e[g++]=new RegExp(b?"(?!\\b)("+f+")(\\b|_)":"("+f+")","g"),e[g]="");return e}function z(a,b){for(let d=0,c=b.length;d<c&&(a=a.replace(b[d],b[d+1]),a);d+=2);return a};const G={},da={};let K=Promise;Object.assign||(Object.assign=function(){const a=arguments,b=a.length,d=a[0];for(let c=1,e,f,g;c<b;c++){e=a[c];f=Object.keys(e);g=f.length;for(let h=0,k;h<g;h++)k=f[h],d[k]=e[k]}return d});if(!K){function a(b){this.g=null;const d=this;b(function(c){d.g&&d.g(c)})}a.prototype.then=function(b){this.g=b};K=a};function ea(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 d=this,c=arguments;var e=c[c.length-1];let f;"function"===typeof e&&(f=e,delete c[c.length-1]);e=new K(function(g){setTimeout(function(){const h=d[b];h.async=!0;g(h.apply(d,c));h.async=!1})});return f?(e.then(f),this):e}};function fa(a,b,d,c){const e=a.length;let f=[],g=E(),h=0;c&&(c=[]);for(let k=0;k<e;k++){const l=a[k],u=l.length,m=E();let q=!k;for(let n=0;n<u;n++){const w=l[n],r=w.length;if(r){c&&(c[n]=[]);for(let y=0,v=0,p;y<r;y++)if(p=w[y],!k)m[p]=1;else if(g[p]){if(k===e-1)if(d)d--;else{if(f[h++]=p,h===b)return f}else c&&v<b&&(c[n][v++]=p),m[p]=1;q=!0}}}if(!q&&!c)return[];g=m}if(c)for(let k=c.length-1,l,u;0<=k;k--)if(u=(l=c[k])&&l.length){if(h+u>=b)return f.concat(l.slice(0,b-h));f=f.concat(l);h+=u}return f} (function(){'use strict';var t;function aa(a){function b(c){return a.next(c)}function d(c){return a.throw(c)}return new Promise(function(c,e){function f(g){g.done?c(g.value):Promise.resolve(g.value).then(b,d).then(f,e)}f(a.next())})};const v=/[\W_]+/;function ba(a){if(a=a.toLowerCase())if(a&&this.B&&(a=ca(a,this.B)),this.F&&1<a.length&&(a=ca(a,this.F)),a&&(v||""===v)&&(a=a.split(v),this.filter)){var b=this.filter;const d=a.length,c=[];for(let e=0,f=0;e<d;e++){const g=a[e];g&&!b[g]&&(c[f++]=g)}a=c}return a};function y(a,b){return"undefined"!==typeof a?a:b}function da(a){const b=Array(a);for(let d=0;d<a;d++)b[d]=A();return b}function A(){return Object.create(null)}function ea(a,b){return b.length-a.length}function E(a){return"string"===typeof a}function G(a){return"object"===typeof a}function H(a){return"function"===typeof a};function fa(a,b){const d=Object.keys(a),c=d.length,e=[];let f="",g=0;for(let h=0,k,l;h<c;h++)k=d[h],(l=a[k])?(e[g++]=new RegExp(b?"(?!\\b)"+k+"(\\b|_)":k,"g"),e[g++]=l):f+=(f?"|":"")+k;f&&(e[g++]=new RegExp(b?"(?!\\b)("+f+")(\\b|_)":"("+f+")","g"),e[g]="");return e}function ca(a,b){for(let d=0,c=b.length;d<c&&(a=a.replace(b[d],b[d+1]),a);d+=2);return a};const ha={},ia={};let I=Promise;Object.assign||(Object.assign=function(){const a=arguments,b=a.length,d=a[0];for(let c=1,e,f,g;c<b;c++){e=a[c];f=Object.keys(e);g=f.length;for(let h=0,k;h<g;h++)k=f[h],d[k]=e[k]}return d});if(!I){function a(b){this.g=null;const d=this;b(function(c){d.g&&d.g(c)})}a.prototype.then=function(b){this.g=b};I=a};function ja(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 d=this,c=arguments;var e=c[c.length-1];let f;H(e)&&(f=e,delete c[c.length-1]);e=new I(function(g){setTimeout(function(){const h=d[b];h.async=!0;g(h.apply(d,c));h.async=!1})});return f?(e.then(f),this):e}};function ka(a,b,d,c){const e=a.length;let f=[],g=A(),h=0;c&&(c=[]);for(let k=0;k<e;k++){const l=a[k],r=l.length,q=A();let u=!k;for(let m=0;m<r;m++){const x=l[m],p=x.length;if(p){c&&(c[m]=[]);for(let z=0,w=0,n;z<p;z++)if(n=x[z],!k)q[n]=1;else if(g[n]){if(k===e-1)if(d)d--;else{if(f[h++]=n,h===b)return f}else c&&w<b&&(c[m][w++]=n),q[n]=1;u=!0}}}if(!u&&!c)return[];g=q}if(c)for(let k=c.length-1,l,r;0<=k;k--)if(r=(l=c[k])&&l.length){if(h+r>=b)return f.concat(l.slice(0,b-h));f=f.concat(l);h+=r}return f}
;function M(a){this.h=!0!==a&&a;this.cache=E();this.g=[]}function ha(a,b,d){"object"===typeof a&&(a=a.query);let c=this.cache.get(a);c||(c=this.search(a,b,d),this.cache.set(a,c));return c}M.prototype.set=function(a,b){if(!this.cache[a]){var d=this.g.length;d===this.h?delete this.cache[this.g[d-1]]:d++;for(--d;0<d;d--)this.g[d]=this.g[d-1];this.g[0]=a}this.cache[a]=b}; ;function N(a){this.h=!0!==a&&a;this.cache=A();this.g=[]}function la(a,b,d){G(a)&&(a=a.query);let c=this.cache.get(a);c||(c=this.search(a,b,d),this.cache.set(a,c));return c}N.prototype.set=function(a,b){if(!this.cache[a]){var d=this.g.length;d===this.h?delete this.cache[this.g[d-1]]:d++;for(--d;0<d;d--)this.g[d]=this.g[d-1];this.g[0]=a}this.cache[a]=b};N.prototype.get=function(a){const b=this.cache[a];if(this.h&&b&&(a=this.g.indexOf(a))){const d=this.g[a-1];this.g[a-1]=this.g[a];this.g[a]=d}return b};const ma={memory:{charset:"latin:extra",s:3,o:3,i:!1,l:"memory"},performance:{threshold:8,o:3,context:{depth:1,v:!0}},match:{charset:"latin:extra",I:"full",s:3},score:{charset:"latin:advanced",threshold:1,context:{depth:3,v:!0}},"default":{s:3,threshold:0,depth:3}};function na(a,b,d,c,e,f){setTimeout(function(){const g=a(d,JSON.stringify(f));g&&g.then?g.then(function(){b.export(a,b,d,c,e+1)}):b.export(a,b,d,c,e+1)})};function O(a,b){if(!(this instanceof O))return new O(a);var d;if(a){E(a)?a=ma[a]:(d=a.preset)&&(a=Object.assign({},ma[d],a));d=a.charset;var c=a.lang;E(d)&&(-1===d.indexOf(":")&&(d+=":default"),d=ia[d]);E(c)&&(c=ha[c])}else a={};let e,f,g,h=a.context||{};this.encode=a.encode||d&&d.encode||ba;this.register=b||A();e=a.resolution||9;f=a.threshold||0;f>=e&&(f=e-1);this.s=e;this.threshold=f;this.u=b=d&&d.I||a.tokenize||"strict";this.depth="strict"===b&&h.depth;this.v=y(h.bidirectional,!0);this.l=g="memory"===
M.prototype.get=function(a){const b=this.cache[a];if(this.h&&b&&(a=this.g.indexOf(a))){const d=this.g[a-1];this.g[a-1]=this.g[a];this.g[a]=d}return b};const ia={memory:{charset:"latin:extra",s:3,o:3,i:!1,l:"memory"},performance:{threshold:8,o:3,context:{depth:1,v:!0}},match:{charset:"latin:extra",I:"full",s:3},score:{charset:"latin:advanced",threshold:1,context:{depth:3,v:!0}},"default":{s:3,threshold:0,depth:3}};function ja(a,b,d,c,e,f){setTimeout(function(){const g=a(d,JSON.stringify(f));g&&g.then?g.then(function(){b.export(a,b,d,c,e+1)}):b.export(a,b,d,c,e+1)})};function N(a,b){if(!(this instanceof N))return new N(a);var d;if(a){"string"===typeof a?a=ia[a]:(d=a.preset)&&(a=Object.assign({},ia[d],a));d=a.charset;var c=a.lang;"string"===typeof d&&(-1===d.indexOf(":")&&(d+=":default"),d=da[d]);"string"===typeof c&&(c=G[c])}else a={};let e,f,g,h=a.context||{};this.encode=a.encode||d&&d.encode||ba;this.register=b||E();e=a.resolution||9;f=a.threshold||0;f>=e&&(f=e-1);this.s=e;this.threshold=f;this.u=b=d&&d.I||a.tokenize||"strict";this.depth="strict"===b&&h.depth; a.optimize;this.i=y(a.fastupdate,!0);this.o=a.minlength||1;this.g=g?da(e-f):A();e=h.resolution||e;f=h.threshold||f;f>=e&&(f=e-1);this.j=e;this.m=f;this.h=g?da(e-f):A();this.D=d&&d.D||a.rtl;this.B=(b=a.matcher||c&&c.B)&&fa(b,!1);this.F=(b=a.stemmer||c&&c.F)&&fa(b,!0);if(d=b=a.filter||c&&c.filter){d=b;c=A();for(let k=0,l=d.length;k<l;k++)c[d[k]]=1;d=c}this.filter=d;this.cache=(b=a.cache)&&new N(b)}t=O.prototype;t.append=function(a,b){return this.add(a,b,!0)};
this.v=P(h.bidirectional,!0);this.l=g="memory"===a.optimize;this.i=P(a.fastupdate,!0);this.o=a.minlength||1;this.g=g?B(e-f):E();e=h.resolution||e;f=h.threshold||f;f>=e&&(f=e-1);this.j=e;this.m=f;this.h=g?B(e-f):E();this.D=d&&d.D||a.rtl;this.B=(b=a.matcher||c&&c.B)&&F(b,!1);this.F=(b=a.stemmer||c&&c.F)&&F(b,!0);if(d=b=a.filter||c&&c.filter){d=b;c=E();for(let k=0,l=d.length;k<l;k++)c[d[k]]=1;d=c}this.filter=d;this.cache=(b=a.cache)&&new M(b)}function P(a,b){return"undefined"!==typeof a?a:b}t=N.prototype; t.add=function(a,b,d){if(this.register[a]&&!d)return this.update(a,b);if(b&&(a||0===a)){b=this.encode(b);const l=b.length;if(l){const r=this.depth,q=this.s-this.threshold,u=A(),m=A();for(let x=0;x<l;x++){let p=b[this.D?l-1-x:x];var c=p.length;if(p&&c>=this.o&&(r||!u[p])){var e=Math.min(this.s/l*x|0,x);if(e<q){var f="";switch(this.u){case "full":if(3<c){for(var g=0;g<c;g++){var h=g?Math.min(e/2+this.s/c*g/2|0,e+g):e;if(h<q)for(var k=c;k>g;k--)f=p.substring(g,k),f.length>=this.o&&P(this,u,f,h,a,d)}break}case "reverse":if(2<
t.append=function(a,b){return this.add(a,b,!0)}; c){for(g=c-1;0<g;g--)f=p[g]+f,f.length>=this.o&&P(this,u,f,e,a,d);f=""}case "forward":if(1<c)for(g=0;g<c;g++)f+=p[g],f.length>=this.o&&P(this,u,f,e,a,d);break;default:if(P(this,u,p,e,a,d),r&&1<l&&x<l-1)for(c=this.j-this.m,e=A(),f=p,g=Math.min(r+1,l-x),e[f]=1,h=1;h<g;h++)if((p=b[this.D?l-1-x-h:x+h])&&p.length>=this.o&&!e[p]){if(e[p]=1,k=Math.min((this.j-g)/l*x+h|0,x+(h-1)),k<c){const z=this.v&&p>f;P(this,m,z?f:p,k,a,d,z?p:f)}}else g=Math.min(g+1,l-x)}}}}this.i||(this.register[a]=1)}}return this};
t.add=function(a,b,d){if(this.register[a]&&!d)return this.update(a,b);if(b&&(a||0===a)){b=this.encode(b);const l=b.length;if(l){const u=this.depth,m=this.s-this.threshold,q=E(),n=E();for(let w=0;w<l;w++){let r=b[this.D?l-1-w:w];var c=r.length;if(r&&c>=this.o&&(u||!q[r])){var e=Math.min(this.s/l*w|0,w);if(e<m){var f="";switch(this.u){case "full":if(3<c){for(var g=0;g<c;g++){var h=g?Math.min(e/2+this.s/c*g/2|0,e+g):e;if(h<m)for(var k=c;k>g;k--)f=r.substring(g,k),f.length>=this.o&&Q(this,q,f,h,a,d)}break}case "reverse":if(2< function P(a,b,d,c,e,f,g){let h=g?a.h:a.g;if(!b[d]||g&&!b[d][g])a.l&&(h=h[c]),g?(b[d]||(b[d]=A()),b[d][g]=1,h=h[g]||(h[g]=A())):b[d]=1,h=h[d]||(h[d]=[]),a.l||(h=h[c]||(h[c]=[])),f&&-1!==h.indexOf(e)||(h[h.length]=e,a.i&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=h))}
c){for(g=c-1;0<g;g--)f=r[g]+f,f.length>=this.o&&Q(this,q,f,e,a,d);f=""}case "forward":if(1<c)for(g=0;g<c;g++)f+=r[g],f.length>=this.o&&Q(this,q,f,e,a,d);break;default:if(Q(this,q,r,e,a,d),u&&1<l&&w<l-1)for(c=this.j-this.m,e=E(),f=r,g=Math.min(u+1,l-w),e[f]=1,h=1;h<g;h++)if((r=b[this.D?l-1-w-h:w+h])&&r.length>=this.o&&!e[r]){if(e[r]=1,k=Math.min((this.j-g)/l*w+h|0,w+(h-1)),k<c){const y=this.v&&r>f;Q(this,n,y?f:r,k,a,d,y?r:f)}}else g=Math.min(g+1,l-w)}}}}this.i||(this.register[a]=1)}}return this}; t.search=function(a,b,d){G(a)?(d=a,a=d.query):G(b)&&(d=b);let c=[],e;var f=this.threshold;let g,h=0;if(d){b=d.limit;h=d.offset||0;f=y(d.threshold,f);var k=d.context;g=d.suggest}if(a&&(a=this.encode(a),e=a.length,1<e)){d=A();var l=[];for(let q=0,u=0,m;q<e;q++)if((m=a[q])&&m.length>=this.o&&!d[m])if(this.l||g||this.g[m])l[u++]=m,d[m]=1;else return c;a=l;e=a.length}if(!e)return c;b||(b=100);d=this.s-f;f=this.j-f;k=this.depth&&1<e&&!1!==k;l=0;let r;k?(r=a[0],l=1):1<e&&a.sort(ea);for(let q,u;l<e;l++){u=
function Q(a,b,d,c,e,f,g){let h=g?a.h:a.g;if(!b[d]||g&&!b[d][g])a.l&&(h=h[c]),g?(b[d]||(b[d]=E()),b[d][g]=1,h=h[g]||(h[g]=E())):b[d]=1,h=h[d]||(h[d]=[]),a.l||(h=h[c]||(h[c]=[])),f&&-1!==h.indexOf(e)||(h[h.length]=e,a.i&&(a=a.register[e]||(a.register[e]=[]),a[a.length]=h))} a[l];k?(q=oa(this,c,g,f,b,2===e,u,r),g&&!1===q&&c.length||(r=u)):q=oa(this,c,g,d,b,1===e,u);if(q)return q;if(g&&l===e-1){let m=c.length;if(!m){if(k){k=0;l=-1;continue}return c}if(1===m)return c=c[0],c=1===c.length?c[0]:[].concat.apply([],c),c.length>b?c.slice(0,b):c}}return ka(c,b,h,g)};function pa(a,b,d,c){d?(c=c&&b>d,a=(a=a[c?b:d])&&a[c?d:b]):a=a[b];return a}
t.search=function(a,b,d){"object"===typeof a?(d=a,a=d.query):"object"===typeof b&&(d=b);let c=[],e;var f=this.threshold;let g,h=0;if(d){b=d.limit;h=d.offset||0;f=P(d.threshold,f);var k=d.context;g=d.suggest}if(a&&(a=this.encode(a),e=a.length,1<e)){d=E();var l=[];for(let m=0,q=0,n;m<e;m++)if((n=a[m])&&n.length>=this.o&&!d[n])if(this.l||g||this.g[n])l[q++]=n,d[n]=1;else return c;a=l;e=a.length}if(!e)return c;b||(b=100);d=this.s-f;f=this.j-f;k=this.depth&&1<e&&!1!==k;l=0;let u;k?(u=a[0],l=1):1<e&&a.sort(ca); function oa(a,b,d,c,e,f,g,h){let k=[],l=h?a.h:a.g;a.l||(l=pa(l,g,h,a.v));if(l){let r=0;c=Math.min(l.length,c);for(let q=0,u=0,m;q<c&&!(m=l[q],a.l&&(m=pa(m,g,h,a.v)),m&&(k[r++]=m,f&&(u+=m.length,u>=e)));q++);if(r){if(f)return k=1===r?k[0]:[].concat.apply([],k),k.length>e?k.slice(0,e):k;b[b.length]=k;return}}return!d&&k}t.contain=function(a){return!!this.register[a]};t.update=function(a,b){return this.remove(a).add(a,b)};
for(let m,q;l<e;l++){q=a[l];k?(m=ka(this,c,g,f,b,2===e,q,u),g&&!1===m&&c.length||(u=q)):m=ka(this,c,g,d,b,1===e,q);if(m)return m;if(g&&l===e-1){let n=c.length;if(!n){if(k){k=0;l=-1;continue}return c}if(1===n)return c=c[0],c=1===c.length?c[0]:[].concat.apply([],c),c.length>b?c.slice(0,b):c}}return fa(c,b,h,g)};function la(a,b,d,c){d?(c=c&&b>d,a=(a=a[c?b:d])&&a[c?d:b]):a=a[b];return a} t.remove=function(a,b){const d=this.register[a];if(d){if(this.i)for(let c=0,e;c<d.length;c++)e=d[c],e.splice(e.indexOf(a),1);else Q(this.g,a,this.s-this.threshold,this.l),this.depth&&Q(this.h,a,this.j-this.m,this.l);b||delete this.register[a];if(this.cache){b=this.cache;for(let c=0,e,f;c<b.g.length;c++)f=b.g[c],e=b.cache[f],-1!==e.indexOf(a)&&(b.g.splice(c--,1),delete b.cache[f])}}return this};
function ka(a,b,d,c,e,f,g,h){let k=[],l=h?a.h:a.g;a.l||(l=la(l,g,h,a.v));if(l){let u=0;c=Math.min(l.length,c);for(let m=0,q=0,n;m<c&&!(n=l[m],a.l&&(n=la(n,g,h,a.v)),n&&(k[u++]=n,f&&(q+=n.length,q>=e)));m++);if(u){if(f)return k=1===u?k[0]:[].concat.apply([],k),k.length>e?k.slice(0,e):k;b[b.length]=k;return}}return!d&&k}t.contain=function(a){return!!this.register[a]};t.update=function(a,b){return this.remove(a).add(a,b)}; function Q(a,b,d,c,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,d);for(let g=0,h;g<e;g++)if(h=a[g])f=Q(h,b,d,c,e),c||f||delete a[g]}else for(let g in a)(f=Q(a[g],b,d,c,e))||delete a[g];return f}t.searchCache=la;
t.remove=function(a,b){const d=this.register[a];if(d){if(this.i)for(let c=0,e;c<d.length;c++)e=d[c],e.splice(e.indexOf(a),1);else R(this.g,a,this.s-this.threshold,this.l),this.depth&&R(this.h,a,this.j-this.m,this.l);b||delete this.register[a];if(this.cache){b=this.cache;for(let c=0,e,f;c<b.g.length;c++)f=b.g[c],e=b.cache[f],-1!==e.indexOf(a)&&(b.g.splice(c--,1),delete b.cache[f])}}return this}; t.export=function(a,b,d,c,e){let f,g;switch(e||(e=0)){case 0:f="reg";if(this.i){g=A();for(let h in this.register)g[h]=1}else g=this.register;break;case 1:f="cfg";g={doc:0,opt:this.l?1:0};break;case 2:f="map";g=this.g;break;case 3:f="ctx";g=this.h;break;default:return}na(a,b||this,d?d+"."+f:f,c,e,g);return!0};t.import=function(a,b){if(b)switch(E(b)&&(b=JSON.parse(b)),a){case "cfg":this.l=!!b.opt;break;case "reg":this.i=!1;this.register=b;break;case "map":this.g=b;break;case "ctx":this.h=b}};ja(O.prototype);let qa=0;function R(a){if(G(a)){var b=a;a=0}H(b.encode)&&(b.encode=b.encode.toString());const d=this;this.id=a||qa++;this.h=null;this.g=new Worker("worker.js",{type:"module"});this.g.onmessage=function(c){d.h(c.data)};this.g.postMessage({H:"create",options:b})}S("add");S("append");S("search");S("update");S("remove");
function R(a,b,d,c,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,d);for(let g=0,h;g<e;g++)if(h=a[g])f=R(h,b,d,c,e),c||f||delete a[g]}else for(let g in a)(f=R(a[g],b,d,c,e))||delete a[g];return f}t.searchCache=ha;ea(N.prototype); function S(a){R.prototype[a]=R.prototype[a+"Async"]=function(){const b=this,d=[].slice.call(arguments);var c=d[d.length-1];let e;H(c)&&(e=c,d.splice(d.length-1,1));c=new I(function(f){b.g.postMessage({H:a,J:d});"search"===a?b.h=f:f()});return e?(c.then(e),this):c}};function T(a){if(!(this instanceof T))return new T(a);var b;a||(a={});this.G=[];this.g=[];this.u=[];this.register=A();this.key=(b=a.key)&&U(b,this.u)||"id";this.i=y(a.fastupdate,!0);this.store=(b=a.store)&&A();this.A=b&&!0!==b&&[];this.C=(b=a.tag)&&U(b,this.u);this.h=b&&A();this.cache=(b=a.cache)&&new N(b);a.cache=!1;this.m=a.worker;this.async=!1;b=a;a=A();let d=b.doc;if(E(d))d=[d];else if(d.constructor!==Array){var c=d;d=Object.keys(d)}for(let e=0,f,g;e<d.length;e++)f=d[e],E(f)?c&&(g=c[f]):(g=f,
N.prototype.export=function(a,b,d,c,e){let f,g;switch(e||(e=0)){case 0:f="reg";if(this.i){g=E();for(let h in this.register)g[h]=1}else g=this.register;break;case 1:f="cfg";g={doc:0,opt:this.l?1:0};break;case 2:f="map";g=this.g;break;case 3:f="ctx";g=this.h;break;default:return}ja(a,b||this,d?d+"."+f:f,c,e,g);return!0}; f=f.field),g=G(g)?Object.assign({},b,g):b,a[f]=this.m?new R(g):new O(g,this.register),this.G[e]=U(f,this.u),this.g[e]=f;if(this.A)for(c=b.store,E(c)&&(c=[c]),b=0;b<c.length;b++)this.A[b]=U(c[b],this.u);this.j=a}function U(a,b){const d=a.split(":");let c=0;for(let e=0;e<d.length;e++)a=d[e],0<=a.indexOf("[]")&&(a=a.substring(0,a.length-2))&&(b[c]=!0),a&&(d[c++]=a);c<d.length&&(d.length=c);return 1<c?d:d[0]}function ra(a,b){if(E(b))a=a[b];else for(let d=0;a&&d<b.length;d++)a=a[b[d]];return a}
N.prototype.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a){case "cfg":this.l=!!b.opt;break;case "reg":this.i=!1;this.register=b;break;case "map":this.g=b;break;case "ctx":this.h=b}};let ma=0;function S(a){if("object"===typeof a){var b=a;a=0}"function"===typeof b.encode&&(b.encode=b.encode.toString());const d=this;this.id=a||ma++;this.h=null;this.g=new Worker("worker.js",{type:"module"});this.g.onmessage=function(c){d.h(c.data)};this.g.postMessage({H:"create",options:b})}T("add");T("append");T("search");T("update");T("remove"); function V(a,b,d,c,e){a=a[e];if(c===d.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,d,c,e);else b=b[e]||(b[e]=A()),e=d[++c],V(a,b,d,c,e)}function W(a,b,d,c,e,f,g,h){a=a[g];if(c===b.length-1){if(a.constructor===Array){if(d[c]){for(b=0;b<a.length;b++)e.add(f,a[b],!0);return}a=a.join(" ")}e.add(f,a,h)}else if(a)if(a.constructor===Array)for(g=0;g<a.length;g++)W(a,b,d,c,e,f,g,h);else g=b[++c],W(a,b,d,c,e,f,g,h)}t=T.prototype;
function T(a){S.prototype[a]=S.prototype[a+"Async"]=function(){const b=this,d=[].slice.call(arguments);var c=d[d.length-1];let e;"function"===typeof c&&(e=c,d.splice(d.length-1,1));c=new K(function(f){b.g.postMessage({H:a,J:d});"search"===a?b.h=f:f()});return e?(c.then(e),this):c}};function W(a){if(!(this instanceof W))return new W(a);var b;a||(a={});this.G=[];this.g=[];this.m=[];this.register=E();this.key=(b=a.key)&&X(b,this.m)||"id";b=a.fastupdate;this.i="undefined"!==typeof b?b:!0;this.store=(b=a.store)&&E();this.u=b&&!0!==b&&[];this.A=(b=a.tag)&&X(b,this.m);this.h=b&&E();this.cache=(b=a.cache)&&new M(b);a.cache=!1;this.C=a.worker;this.async=!1;b=a;a=E();let d=b.doc;if("string"===typeof d)d=[d];else if(d.constructor!==Array){var c=d;d=Object.keys(d)}for(let e=0,f,g;e<d.length;e++)f= t.add=function(a,b,d){G(a)&&(b=a,a=ra(b,this.key));if(b&&(a||0===a)){if(this.register[a])return this.update(a,b);for(let c=0,e,f;c<this.g.length;c++)f=this.g[c],e=this.G[c],E(e)&&(e=[e]),W(b,e,this.u,0,this.j[f],a,e[0],d);if(this.C){let c=ra(b,this.C),e=A();E(c)&&(c=[c]);for(let f=0,g,h;f<c.length;f++)if(g=c[f],!e[g]&&(e[g]=1,h=this.h[g]||(this.h[g]=[]),!d||-1===h.indexOf(a)))if(h[h.length]=a,this.i){const k=this.register[a]||(this.register[a]=[]);k[k.length]=h}}if(this.store){let c;if(this.A){c=
d[e],c?(g=c[f],g="object"===typeof g?Object.assign({},b,g):b):g=b,a[f]=this.C?new S(g):new N(g,this.register),this.G[e]=X(f,this.m),this.g[e]=f;if(this.u)for(c=b.store,"string"===typeof c&&(c=[c]),b=0;b<c.length;b++)this.u[b]=X(c[b],this.m);this.j=a}function X(a,b){const d=a.split(":");let c=0;for(let e=0;e<d.length;e++)a=d[e],0<=a.indexOf("[]")&&(a=a.substring(0,a.length-2))&&(b[c]=!0),a&&(d[c++]=a);c<d.length&&(d.length=c);return 1<c?d:d[0]} A();for(let e=0,f;e<this.A.length;e++)f=this.A[e],E(f)?c[f]=b[f]:V(b,c,f,0,f[0])}this.store[a]=c||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 na(a,b){if("string"===typeof b)a=a[b];else for(let d=0;a&&d<b.length;d++)a=a[b[d]];return a}function Y(a,b,d,c,e){a=a[e];if(c===d.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,d,c,e);else b=b[e]||(b[e]=E()),e=d[++c],Y(a,b,d,c,e)} t.remove=function(a){G(a)&&(a=a[this.key]);if(this.register[a]){for(var b=0;b<this.g.length&&(this.j[this.g[b]].remove(a,!0),!this.i||this.m);b++);if(this.C&&(!this.i||this.m))for(let d in this.h){b=this.h[d];const c=b.indexOf(a);-1!==c&&(1<b.length?b.splice(c,1):delete this.h[d])}this.store&&delete this.store[a];delete this.register[a]}return this};
function Z(a,b,d,c,e,f,g,h){a=a[g];if(c===b.length-1){if(a.constructor===Array){if(d[c]){for(b=0;b<a.length;b++)e.add(f,a[b],!0);return}a=a.join(" ")}e.add(f,a,h)}else if(a)if(a.constructor===Array)for(g=0;g<a.length;g++)Z(a,b,d,c,e,f,g,h);else g=b[++c],Z(a,b,d,c,e,f,g,h)}t=W.prototype; t.search=function(a,b,d){const c=this;return aa(function*(){G(a)?(d=a,a=d.query):G(b)&&(d=b,b=0);let e=[];var f=[],g;let h;let k,l,r,q,u=0;if(d)if(d.constructor===Array){var m=d;d=null}else if(m=(g=d.pluck)||d.field||d.doc,l=d.tag,h=c.store&&d.enrich,r="and"===d.bool,b=d.limit||100,q=d.offset||0,m&&(E(m)?m=[m]:m.constructor!==Array&&(k=m,m=Object.keys(m))),l&&(E(l)&&(l=[l]),!a)){for(let w=0,n;w<l.length;w++){f=l[w];if((m=(g=c.h[f])&&g.length-q)&&0<m){if(m>b||q)g=g.slice(q,q+b);h&&(g=sa.call(c,g));
t.add=function(a,b,d){"object"===typeof a&&(b=a,a=na(b,this.key));if(b&&(a||0===a)){if(this.register[a])return this.update(a,b);for(let c=0,e,f;c<this.g.length;c++)f=this.g[c],e=this.G[c],"string"===typeof e&&(e=[e]),Z(b,e,this.m,0,this.j[f],a,e[0],d);if(this.A){let c=na(b,this.A),e=E();"string"===typeof c&&(c=[c]);for(let f=0,g,h;f<c.length;f++)if(g=c[f],!e[g]&&(e[g]=1,h=this.h[g]||(this.h[g]=[]),!d||-1===h.indexOf(a)))if(h[h.length]=a,this.i){const k=this.register[a]||(this.register[a]=[]);k[k.length]= n={tag:f,result:g}}else n=void 0;n&&(e[e.length]=n,u++)}return u?e:[]}m||(m=c.g);r=r&&(1<m.length||l&&1<l.length);let x=[];if(c.m||c.async){for(let w=0,n;w<m.length;w++){var p=void 0;n=m[w];E(n)?k&&(p=k[n]):(p=n,n=n.field);x[w]=c.j[n].searchAsync(a,b,p||d)}x=yield Promise.all(x)}for(let w=0,n,B,K;w<m.length;w++){let X;B=m[w];E(B)?k&&(X=k[B]):(X=B,B=B.field);n=c.m||c.async?x[w]:c.j[B].search(a,b,X||d);K=n.length;if(l&&K){var z=[];p=0;r&&(z[0]=[n]);for(let F=0,L,C;F<l.length;F++)if(L=l[F],K=(C=c.h[L])&&
h}}if(this.store){let c;if(this.u){c=E();for(let e=0,f;e<this.u.length;e++)f=this.u[e],"string"===typeof f?c[f]=b[f]:Y(b,c,f,0,f[0])}this.store[a]=c||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)}; C.length)p++,z[z.length]=r?[C]:C;if(p){if(r)p=ka(z,b||100,q||0);else{p=n;const F=A(),L=A(),C=[];for(let D=0;D<p.length;D++)F[p[D]]=1;for(let D=0,Y;D<z.length;D++){Y=z[D];for(let Z=0,M;Z<Y.length;Z++)M=Y[Z],F[M]&&!L[M]&&(L[M]=1,C[C.length]=M)}p=C}n=p;K=n.length}}if(K)f[u]=B,e[u++]=n;else if(r)return[]}if(!u)return[];if(g&&(!h||!c.store))return e[0];for(let w=0,n;w<f.length;w++){n=e[w];n.length&&h&&(n=sa.call(c,n));if(g)return n;e[w]={field:f[w],result:n}}return e}())};
t.remove=function(a){"object"===typeof a&&(a=a[this.key]);if(this.register[a]){for(var b=0;b<this.g.length&&(this.j[this.g[b]].remove(a,!0),!this.i);b++);if(this.A&&!this.i)for(let d in this.h){b=this.h[d];const c=b.indexOf(a);-1!==c&&(1<b.length?b.splice(c,1):delete this.h[d])}this.store&&delete this.store[a];delete this.register[a]}return this}; function sa(a){const b=Array(a.length);for(let d=0,c;d<a.length;d++)c=a[d],b[d]={key:c,doc:this.store[c]};return b}t.contain=function(a){return!!this.register[a]};t.get=function(a){return this.store[a]};t.set=function(a,b){this.store[a]=b;return this};t.searchCache=la;
t.search=function(a,b,d){const c=this;return aa(function*(){"object"===typeof a?(d=a,a=d.query):"object"===typeof b&&(d=b);let e=[];var f=[],g;let h;let k;let l,u=0;if(d){var m=(g=d.pluck)||d.field;k=d.tag;h=c.store&&d.enrich;var q="and"===d.bool;b=d.limit;l=d.offset;if(m)if("string"===typeof m)m=[m];else if(m.constructor!==Array){var n=m;m=Object.keys(m)}if(k&&("string"===typeof k&&(k=[k]),!a)){for(let v=0,p;v<k.length;v++){f=k[v];g=b||100;m=l||0;if((q=(n=c.h[f])&&n.length-m)&&0<q){if(q>g||m)n=n.slice(m, t.export=function(a,b,d,c,e){e||(e=0);c||(c=0);if(c<this.g.length){const f=this.g[c],g=this.j[f];b=this;setTimeout(function(){g.export(a,b,e?f.replace(":","-"):"",c,e++)||(c++,e=1,b.export(a,b,f,c,e))})}else{let f;switch(e){case 1:d="tag";f=this.h;break;case 2:d="store";f=this.store;break;default:return}na(a,this,d,c,e,f)}};
m+g);h&&(n=oa.call(c,n));p={tag:f,result:n}}else p=void 0;p&&(e[e.length]=p,u++)}return u?e:[]}}m||(m=c.g);q=q&&(1<m.length||k&&1<k.length);let w=[];if(c.C||c.async){for(let v=0,p;v<m.length;v++)p=m[v],w[v]=c.j[p][c.async?"searchAsync":"search"](a,b,n?n[p]:d);w=yield Promise.all(w)}for(let v=0,p,O,H;v<m.length;v++){O=m[v];p=c.C||c.async?w[v]:c.j[O].search(a,b,n?n[O]:d);H=p.length;if(k&&H){var r=[],y=0;q&&(r[0]=[p]);for(let D=0,I,A;D<k.length;D++)if(I=k[D],H=(A=c.h[I])&&A.length)y++,r[r.length]=q? t.import=function(a,b){if(b)switch(E(b)&&(b=JSON.parse(b)),a){case "tag":this.h=b;break;case "reg":this.i=!1;this.register=b;for(let c=0,e;c<this.g.length;c++)e=this.j[this.g[c]],e.register=b,e.i=!1;break;case "store":this.store=b;break;default:a=a.split(".");const d=a[0];a=a[1];d&&a&&this.j[d].import(a,b)}};ja(T.prototype);window.FlexSearch={Index:O,Document:T,registerCharset:function(a,b){ia[a]=b},registerLanguage:function(a,b){ha[a]=b}};}).call(this);
[A]:A;if(y){if(q)y=fa(r,b||100,l||0);else{y=p;const D=E(),I=E(),A=[];for(let C=0;C<y.length;C++)D[y[C]]=1;for(let C=0,U;C<r.length;C++){U=r[C];for(let V=0,J;V<U.length;V++)J=U[V],D[J]&&!I[J]&&(I[J]=1,A[A.length]=J)}y=A}p=y;H=p.length}}if(H)f[u]=O,e[u++]=p;else if(q)return[]}if(!u)return[];if(g&&(!h||!c.store))return e[0];for(let v=0,p;v<f.length;v++){p=e[v];p.length&&h&&(p=oa.call(c,p));if(g)return p;e[v]={field:f[v],result:p}}return e}())};
function oa(a){const b=Array(a.length);for(let d=0,c;d<a.length;d++)c=a[d],b[d]={key:c,doc:this.store[c]};return b}t.contain=function(a){return!!this.register[a]};t.get=function(a){return this.store[a]};t.set=function(a,b){this.store[a]=b;return this};t.searchCache=ha;ea(W.prototype);
W.prototype.export=function(a,b,d,c,e){e||(e=0);c||(c=0);if(c<this.g.length){const f=this.g[c],g=this.j[f];b=this;setTimeout(function(){g.export(a,b,e?f.replace(":","-"):"",c,e++)||(c++,e=1,b.export(a,b,f,c,e))})}else{let f;switch(e){case 1:d="tag";f=this.h;break;case 2:d="store";f=this.store;break;default:return}ja(a,this,d,c,e,f)}};
W.prototype.import=function(a,b){if(b)switch("string"===typeof b&&(b=JSON.parse(b)),a){case "tag":this.h=b;break;case "reg":this.i=!1;this.register=b;for(let c=0,e;c<this.g.length;c++)e=this.j[this.g[c]],e.register=b,e.i=!1;break;case "store":this.store=b;break;default:a=a.split(".");const d=a[0];a=a[1];d&&a&&this.j[d].import(a,b)}};window.FlexSearch={Index:N,Document:W,registerCharset:function(a,b){da[a]=b},registerLanguage:function(a,b){G[a]=b}};}).call(this);

View File

@@ -364,6 +364,33 @@ const index = new Document({
}); });
``` ```
Or when you did not like to assign field names as object keys you can also use an array of objects which haves the property "field" additionally:
```js
const index = new Document({
key: "id",
doc: [{
field: "title",
tokenize: "forward",
optimize: "memory",
resolution: 9,
threshold: 0
},{
field: "content",
tokenize: "strict",
optimize: "memory",
resolution: 9,
threshold: 3,
minlength: 3,
context: {
depth: 1,
resolution: 3,
threshold: 0
}
}]
});
```
Field options gets inherited when also global options was passed, e.g.: Field options gets inherited when also global options was passed, e.g.:
```js ```js
@@ -447,11 +474,21 @@ index.search(query, {
"record:title", "record:title",
"record:content:header", "record:content:header",
"record:content:footer" "record:content:footer"
], ]
}); });
``` ```
or also: Same as:
```js
index.search(query, [
"record:title",
"record:content:header",
"record:content:footer"
]);
```
Using field-specific options:
```js ```js
index.search({ index.search({
@@ -469,6 +506,26 @@ index.search({
}); });
``` ```
When you did not like to assign field names as object keys then you can also use an array of objects which haves the property "field":
```js
index.search([{
field: "record:title",
query: "some query",
limit: 100,
suggest: true
},{
field: "record:title",
query: "some other query",
limit: 100,
suggest: true
}]);
```
One advantage here is you can perform a search through the same field with different query.
> When passing field-specific options you need to provide the full configuration for each field. They get not inherited like the document descriptor.
#### Complex Documents #### Complex Documents
You need to follow 2 rules for your documents: You need to follow 2 rules for your documents:
@@ -652,16 +709,22 @@ Search through a given set of fields:
index.search(query, { field: ["title", "content"] }); index.search(query, { field: ["title", "content"] });
``` ```
Same as:
```js
index.search(query, ["title", "content"]);
```
Pass custom modifiers to each field: Pass custom modifiers to each field:
```js ```js
index.search(query, { index.search(query, {
field: { field: {
title: { "title": {
threshold: 0, threshold: 0,
limit: 50 limit: 50
}, },
content: { "content": {
threshold: 3, threshold: 3,
limit: 100, limit: 100,
suggest: true suggest: true
@@ -675,12 +738,12 @@ Or pass custom query to each field:
```js ```js
index.search({ index.search({
field: { field: {
title: { "title": {
query: "some title", query: "some title",
threshold: 0, threshold: 0,
limit: 50 limit: 50
}, },
content: { "content": {
query: "some content", query: "some content",
threshold: 3, threshold: 3,
limit: 100, limit: 100,
@@ -690,6 +753,24 @@ index.search({
}); });
``` ```
Or as array notation along a "field" property:
```js
index.search([{
field: "content",
query: "some query",
limit: 100,
suggest: true
},{
field: "content",
query: "some other query",
limit: 100,
suggest: true
}]);
```
One advantage here is you can perform a search through the same field with different queries.
### New Result Set ### New Result Set
One of the few breaking changes which needs migration of your old implementation is the result set. I was thinking a long time about it and came to the conclusion, that this new structure might look weird on the first time, but also comes with some nice new capabilities. One of the few breaking changes which needs migration of your old implementation is the result set. I was thinking a long time about it and came to the conclusion, that this new structure might look weird on the first time, but also comes with some nice new capabilities.

View File

@@ -1,6 +1,6 @@
{ {
"name": "flexsearch", "name": "flexsearch",
"version": "0.7.0-pre-alpha", "version": "0.7.0-beta",
"description": "Next-Generation full text search library with zero dependencies.", "description": "Next-Generation full text search library with zero dependencies.",
"homepage": "https://github.com/nextapps-de/flexsearch/", "homepage": "https://github.com/nextapps-de/flexsearch/",
"author": "Thomas Wilkerling", "author": "Thomas Wilkerling",

View File

@@ -1,4 +1,5 @@
import { promise as Promise } from "./polyfill.js"; import { promise as Promise } from "./polyfill.js";
import { is_function, is_object } from "./common.js";
let counter = 0; let counter = 0;
@@ -10,13 +11,13 @@ let counter = 0;
function WorkerAdapter(id, options){ function WorkerAdapter(id, options){
if(typeof id === "object"){ if(is_object(id)){
options = id; options = /** @type {Object} */ (id);
id = 0; id = 0;
} }
if(typeof options["encode"] === "function"){ if(is_function(options["encode"])){
options["encode"] = options["encode"].toString(); options["encode"] = options["encode"].toString();
} }
@@ -48,7 +49,7 @@ function register(key){
const arg = args[args.length - 1]; const arg = args[args.length - 1];
let callback; let callback;
if(typeof arg === "function"){ if(is_function(arg)){
callback = arg; callback = arg;
args.splice(args.length - 1, 1); args.splice(args.length - 1, 1);

View File

@@ -1,6 +1,7 @@
import Index from "./index.js"; import Index from "./index.js";
import Document from "./document.js"; import Document from "./document.js";
import { promise as Promise } from "./polyfill.js"; import { promise as Promise } from "./polyfill.js";
import { is_function, is_object } from "./common.js";
export default function(prototype){ export default function(prototype){
@@ -20,7 +21,7 @@ function register(prototype, key){
const arg = args[args.length - 1]; const arg = args[args.length - 1];
let callback; let callback;
if(typeof arg === "function"){ if(is_function(arg)){
callback = arg; callback = arg;
delete args[args.length - 1]; delete args[args.length - 1];

View File

@@ -1,6 +1,6 @@
import Index from "./index.js"; import Index from "./index.js";
import Document from "./index.js"; import Document from "./index.js";
import { create_object } from "./common.js"; import { create_object, is_object } from "./common.js";
/** /**
* @param {boolean|number=} limit * @param {boolean|number=} limit
@@ -24,7 +24,7 @@ function CacheClass(limit){
export default CacheClass; export default CacheClass;
/** /**
* @param {!string} query * @param {string|Object} query
* @param {number|Object=} limit * @param {number|Object=} limit
* @param {Object=} options * @param {Object=} options
* @this {Document|Index} * @this {Document|Index}
@@ -33,7 +33,7 @@ export default CacheClass;
export function searchCache(query, limit, options){ export function searchCache(query, limit, options){
if(typeof query === "object"){ if(is_object(query)){
query = query["query"]; query = query["query"];
} }

View File

@@ -1,4 +1,7 @@
//import FlexSearch from "./flexsearch.js"; export function parse_option(value, default_value){
return typeof value !== "undefined" ? value : default_value;
}
/** /**
* @param {!Object} obj * @param {!Object} obj
@@ -53,3 +56,23 @@ export function sort_by_length_down(a, b){
return b.length - a.length; return b.length - a.length;
} }
export function is_array(val){
return val.constructor === Array;
}
export function is_string(val){
return typeof val === "string";
}
export function is_object(val){
return typeof val === "object";
}
export function is_function(val){
return typeof val === "function";
}

View File

@@ -19,7 +19,7 @@ import {
import Index from "./index.js"; import Index from "./index.js";
import Cache, { searchCache } from "./cache.js"; import Cache, { searchCache } from "./cache.js";
import { create_object } from "./common.js"; import { create_object, is_array, is_string, is_object, parse_option } from "./common.js";
import apply_async from "./async.js"; import apply_async from "./async.js";
import { intersect, intersect_union } from "./intersect.js"; import { intersect, intersect_union } from "./intersect.js";
import { exportDocument, importDocument } from "./serialize.js"; import { exportDocument, importDocument } from "./serialize.js";
@@ -82,11 +82,6 @@ function Document(options){
export default Document; export default Document;
function parse_option(value, default_value){
return typeof value !== "undefined" ? value : default_value;
}
/** /**
* @this Document * @this Document
*/ */
@@ -97,38 +92,37 @@ function parse_descriptor(options){
let field = options["doc"]; let field = options["doc"];
let field_options; let field_options;
if(typeof field === "string"){ if(is_string(field)){
field = [field]; field = [field];
} }
else if(field.constructor !== Array){ else if(!is_array(field)){
field_options = field; field_options = field;
field = Object.keys(field); field = Object.keys(field);
} }
for(let i = 0, key, item; i < field.length; i++){ for(let i = 0, key, opt; i < field.length; i++){
key = field[i]; key = field[i];
if(field_options){ if(!is_string(key)){
item = field_options[key]; opt = key;
item = typeof item === "object" ? Object.assign({}, options, item) : options; key = key["field"];
} }
else{ else if(field_options){
item = options; opt = field_options[key];
} }
if(this.worker){ opt = is_object(opt) ? Object.assign({}, options, opt) : options;
index[key] = new WorkerAdapter(item); index[key] = this.worker ?
}
else{
index[key] = new Index(item, this.register); new WorkerAdapter(opt)
} :
new Index(opt, this.register);
this.tree[i] = parse_tree(key, this.marker); this.tree[i] = parse_tree(key, this.marker);
this.field[i] = key; this.field[i] = key;
@@ -138,7 +132,7 @@ function parse_descriptor(options){
let store = options["store"]; let store = options["store"];
if(typeof store === "string"){ if(is_string(store)){
store = [store]; store = [store];
} }
@@ -187,7 +181,7 @@ function parse_tree(key, marker){
function parse_simple(obj, tree){ function parse_simple(obj, tree){
if(typeof tree === "string"){ if(is_string(tree)){
obj = obj[tree]; obj = obj[tree];
} }
@@ -216,7 +210,7 @@ function store_value(obj, store, tree, pos, key){
} }
else if(obj){ else if(obj){
if(obj.constructor === Array){ if(is_array(obj)){
store = store[key] = new Array(obj.length); store = store[key] = new Array(obj.length);
@@ -246,7 +240,7 @@ function add_index(obj, tree, marker, pos, index, id, key, _append){
// handle target value // handle target value
if(obj.constructor === Array){ if(is_array(obj)){
if(marker[pos]){ if(marker[pos]){
@@ -265,7 +259,7 @@ function add_index(obj, tree, marker, pos, index, id, key, _append){
} }
else if(obj){ else if(obj){
if(obj.constructor === Array){ if(is_array(obj)){
for(let i = 0; i < obj.length; i++){ for(let i = 0; i < obj.length; i++){
@@ -292,7 +286,7 @@ function add_index(obj, tree, marker, pos, index, id, key, _append){
Document.prototype.add = function(id, content, _append){ Document.prototype.add = function(id, content, _append){
if(typeof id === "object"){ if(is_object(id)){
content = id; content = id;
id = parse_simple(content, this.key); id = parse_simple(content, this.key);
@@ -310,7 +304,7 @@ Document.prototype.add = function(id, content, _append){
field = this.field[i]; field = this.field[i];
tree = this.tree[i]; tree = this.tree[i];
if(typeof tree === "string"){ if(is_string(tree)){
tree = [tree]; tree = [tree];
} }
@@ -323,7 +317,7 @@ Document.prototype.add = function(id, content, _append){
let tag = parse_simple(content, this.tag); let tag = parse_simple(content, this.tag);
let dupes = create_object(); let dupes = create_object();
if(typeof tag === "string"){ if(is_string(tag)){
tag = [tag]; tag = [tag];
} }
@@ -365,7 +359,7 @@ Document.prototype.add = function(id, content, _append){
tree = this.storetree[i]; tree = this.storetree[i];
if(typeof tree === "string"){ if(is_string(tree)){
store[tree] = content[tree]; store[tree] = content[tree];
} }
@@ -396,7 +390,7 @@ Document.prototype.update = function(id, content){
Document.prototype.remove = function(id){ Document.prototype.remove = function(id){
if(typeof id === "object"){ if(is_object(id)){
id = id[this.key]; id = id[this.key];
} }
@@ -407,7 +401,9 @@ Document.prototype.remove = function(id){
this.index[this.field[i]].remove(id, true); this.index[this.field[i]].remove(id, true);
if(this.fastupdate){ // workers does not share the register
if(this.fastupdate && !this.worker){
// when fastupdate was enabled all ids will // when fastupdate was enabled all ids will
// be already cleanup after the first loop // be already cleanup after the first loop
@@ -421,7 +417,7 @@ Document.prototype.remove = function(id){
// when fastupdate was enabled the id will // when fastupdate was enabled the id will
// be already cleanup by the index // be already cleanup by the index
if(!this.fastupdate){ if(!this.fastupdate || this.worker){
for(let key in this.tagindex){ for(let key in this.tagindex){
@@ -456,14 +452,15 @@ Document.prototype.remove = function(id){
Document.prototype.search = async function(query, limit, options){ Document.prototype.search = async function(query, limit, options){
if(typeof query === "object"){ if(is_object(query)){
options = query; options = query;
query = options["query"]; query = options["query"];
} }
else if(typeof limit === "object"){ else if(is_object(limit)){
options = limit; options = limit;
limit = 0;
} }
let result = [], result_field = []; let result = [], result_field = [];
@@ -472,51 +469,64 @@ Document.prototype.search = async function(query, limit, options){
if(options){ if(options){
pluck = options["pluck"]; if(is_array(options)){
field = pluck || options["field"];
tag = SUPPORT_TAGS && options["tag"];
enrich = SUPPORT_STORE && this.store && options["enrich"];
bool = options["bool"] === "and";
limit = options["limit"];
offset = options["offset"];
if(field){ field = options;
options = null;
if(typeof field === "string"){
field = [field];
}
else if(field.constructor !== Array){
field_options = field;
field = Object.keys(field);
}
} }
// else if(is_string(options)){
//
// field = [options];
// options = null;
// }
else{
if(tag){ pluck = options["pluck"];
field = pluck || options["field"] || options["doc"];
tag = SUPPORT_TAGS && options["tag"];
enrich = SUPPORT_STORE && this.store && options["enrich"];
bool = options["bool"] === "and";
limit = options["limit"] || 100;
offset = options["offset"] || 0;
if(typeof tag === "string"){ if(field){
tag = [tag]; if(is_string(field)){
field = [field];
}
else if(!is_array(field)){
field_options = field;
field = Object.keys(field);
}
} }
// when tags is used and no query was set, if(tag){
// then just return the tag indexes
if(!query){ if(is_string(tag)){
for(let i = 0, res; i < tag.length; i++){ tag = [tag];
res = get_tag.call(this, tag[i], limit || 100, offset || 0, enrich);
if(res){
result[result.length] = res;
count++;
}
} }
return count ? result : []; // when tags is used and no query was set,
// then just return the tag indexes
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 : [];
}
} }
} }
} }
@@ -532,8 +542,21 @@ Document.prototype.search = async function(query, limit, options){
for(let i = 0, key; i < field.length; i++){ for(let i = 0, key; i < field.length; i++){
let opt;
key = field[i]; key = field[i];
async_res[i] = this.index[key][this.async ? "searchAsync" : "search"](query, limit, field_options ? field_options[key] : options);
if(!is_string(key)){
opt = key;
key = key["field"];
}
else if(field_options){
opt = field_options[key];
}
async_res[i] = this.index[key].searchAsync(query, limit, opt || options);
} }
async_res = await Promise.all(async_res); async_res = await Promise.all(async_res);
@@ -543,8 +566,20 @@ Document.prototype.search = async function(query, limit, options){
for(let i = 0, res, key, len; i < field.length; i++){ for(let i = 0, res, key, len; i < field.length; i++){
let opt;
key = field[i]; key = field[i];
if(!is_string(key)){
opt = key;
key = key["field"];
}
else if(field_options){
opt = field_options[key];
}
if(this.worker || this.async){ if(this.worker || this.async){
res = async_res[i]; res = async_res[i];
@@ -553,7 +588,7 @@ Document.prototype.search = async function(query, limit, options){
// inherit options also when search? it is just for laziness, Object.assign() has a cost // inherit options also when search? it is just for laziness, Object.assign() has a cost
res = this.index[key].search(query, limit, field_options ? field_options[key] : options); res = this.index[key].search(query, limit, opt || options);
} }
len = res.length; len = res.length;
@@ -725,13 +760,13 @@ if(SUPPORT_CACHE){
Document.prototype.searchCache = searchCache; Document.prototype.searchCache = searchCache;
} }
if(SUPPORT_ASYNC){
apply_async(Document.prototype);
}
if(SUPPORT_SERIALIZE){ if(SUPPORT_SERIALIZE){
Document.prototype.export = exportDocument; Document.prototype.export = exportDocument;
Document.prototype.import = importDocument; Document.prototype.import = importDocument;
} }
if(SUPPORT_ASYNC){
apply_async(Document.prototype);
}

View File

@@ -12,7 +12,8 @@ function Engine(index){
if(DEBUG){ if(DEBUG){
if(this.constructor === Engine){ //if(this.constructor === Engine){
if(this instanceof Engine){
throw new Error("Can't instantiate abstract class!"); throw new Error("Can't instantiate abstract class!");
} }

View File

@@ -17,7 +17,7 @@ import {
} from "./config.js"; } from "./config.js";
import { encode as default_encoder } from "./lang/latin/default.js"; import { encode as default_encoder } from "./lang/latin/default.js";
import { create_object, create_object_array, concat, sort_by_length_down } from "./common.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 { pipeline, init_stemmer_or_matcher, init_filter } from "./lang.js";
import { global_lang, global_charset } from "./global.js"; import { global_lang, global_charset } from "./global.js";
import apply_async from "./async.js"; import apply_async from "./async.js";
@@ -52,7 +52,7 @@ function Index(options, _register){
charset = options["charset"]; charset = options["charset"];
lang = options["lang"]; lang = options["lang"];
if(typeof charset === "string"){ if(is_string(charset)){
if(charset.indexOf(":") === -1){ if(charset.indexOf(":") === -1){
@@ -62,7 +62,7 @@ function Index(options, _register){
charset = global_charset[charset]; charset = global_charset[charset];
} }
if(typeof lang === "string"){ if(is_string(lang)){
lang = global_lang[lang]; lang = global_lang[lang];
} }
@@ -122,11 +122,6 @@ function Index(options, _register){
export default Index; export default Index;
function parse_option(value, default_value){
return typeof value !== "undefined" ? value : default_value;
}
Index.prototype.pipeline = pipeline; Index.prototype.pipeline = pipeline;
/** /**
@@ -355,7 +350,7 @@ Index.prototype.push_index = function(dupes, value, score, id, append, keyword){
} }
/** /**
* @param {!string|Object} query * @param {string|Object} query
* @param {number|Object=} limit * @param {number|Object=} limit
* @param {Object=} options * @param {Object=} options
* @returns {Array<number|string>} * @returns {Array<number|string>}
@@ -363,14 +358,14 @@ Index.prototype.push_index = function(dupes, value, score, id, append, keyword){
Index.prototype.search = function(query, limit, options){ Index.prototype.search = function(query, limit, options){
if(typeof query === "object"){ if(is_object(query)){
options = query; options = /** @type {Object} */ (query);
query = options["query"]; query = options["query"];
} }
else if(typeof limit === "object"){ else if(is_object(limit)){
options = limit; options = /** @type {Object} */ (limit);
} }
let result = []; let result = [];
@@ -697,7 +692,7 @@ function remove_index(map, id, res, optimize, resolution){
let count = 0; let count = 0;
if(map.constructor === Array){ if(is_array(map)){
// the first array is the score array in both strategies // the first array is the score array in both strategies
@@ -763,13 +758,13 @@ if(SUPPORT_CACHE){
Index.prototype.searchCache = searchCache; Index.prototype.searchCache = searchCache;
} }
if(SUPPORT_ASYNC){
apply_async(Index.prototype);
}
if(SUPPORT_SERIALIZE){ if(SUPPORT_SERIALIZE){
Index.prototype.export = exportIndex; Index.prototype.export = exportIndex;
Index.prototype.import = importIndex; Index.prototype.import = importIndex;
} }
if(SUPPORT_ASYNC){
apply_async(Index.prototype);
}

View File

@@ -1,4 +1,5 @@
import { DEBUG } from "./config.js"; import { DEBUG } from "./config.js";
import { is_string } from "./common.js";
/** /**
* @enum {Object} * @enum {Object}
@@ -67,7 +68,7 @@ const presets = {
export default function apply_preset(options){ export default function apply_preset(options){
if(typeof options === "string"){ if(is_string(options)){
if(DEBUG && !presets[options]){ if(DEBUG && !presets[options]){

View File

@@ -1,6 +1,6 @@
import Index from "./index.js"; import Index from "./index.js";
import Document from "./document.js"; import Document from "./document.js";
import { create_object } from "./common.js"; import { create_object, is_string } from "./common.js";
function async(callback, self, key, index_doc, index, data){ function async(callback, self, key, index_doc, index, data){
@@ -99,7 +99,7 @@ export function importIndex(key, data){
return; return;
} }
if(typeof data === "string"){ if(is_string(data)){
data = JSON.parse(data); data = JSON.parse(data);
} }
@@ -202,7 +202,7 @@ export function importDocument(key, data){
return; return;
} }
if(typeof data === "string"){ if(is_string(data)){
data = JSON.parse(data); data = JSON.parse(data);
} }

View File

@@ -1,23 +1,26 @@
import Index from "./index.js"; import Index from "./index.js";
import { is_string, is_object } from "./common.js";
let index, id; let index, id;
onmessage = function(event) { onmessage = function(event) {
const data = event.data; const data = event.data;
const args = data["args"];
switch(data["task"]){ switch(data["task"]){
case "create": case "create":
const options = data["options"] || {}; const options = data["options"] || {};
const encode = options["encode"];
options["cache"] = false; options["cache"] = false;
id = data["id"]; id = data["id"];
if(typeof options["encode"] === "string"){ if(is_string(encode)){
options["encode"] = Function(options["encode"]); options["encode"] = new Function("return " + encode)();
} }
index = new Index(options); index = new Index(options);
@@ -25,29 +28,29 @@ onmessage = function(event) {
case "add": case "add":
index.add.apply(index, data["args"]); index.add.apply(index, args);
break; break;
case "append": case "append":
index.append.apply(index, data["args"]); index.append.apply(index, args);
break; break;
case "search": case "search":
const results = index.search.apply(index, data["args"]); const results = index.search.apply(index, args);
//postMessage({ id: id, results: results }); //postMessage({ id: id, results: results });
postMessage(results); postMessage(results);
break; break;
case "update": case "update":
index.update.apply(index, data["args"]); index.update.apply(index, args);
break; break;
case "remove": case "remove":
index.remove.apply(index, data["args"]); index.remove.apply(index, args);
break; break;
} }
}; };