1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-19 20:31:40 +02:00

fix circular module dependencies

This commit is contained in:
Thomas Wilkerling
2021-05-20 14:04:29 +02:00
parent f5bcf34ac8
commit 66a215ad59
16 changed files with 98 additions and 74 deletions

View File

@@ -1,31 +1,31 @@
/**!
* FlexSearch.js v0.7.0-beta (Bundle)
* FlexSearch.js v0.7.0-beta
* Copyright 2019 Nextapps GmbH
* Author: Thomas Wilkerling
* Licence: Apache-2.0
* 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 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 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"===
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)};
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<
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};
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))}
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(){'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.D&&1<a.length&&(a=ca(a,this.D)),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 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",o:3,m:3,i:!1,j:"memory"},performance:{threshold:8,m:3,context:{depth:1,u:!0}},match:{charset:"latin:extra",H:"full",o:3},score:{charset:"latin:advanced",threshold:1,context:{depth:3,u:!0}},"default":{o: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({},d[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.o=e;this.threshold=f;this.s=b=d&&d.H||a.tokenize||"strict";this.depth="strict"===b&&h.depth;this.u=y(h.bidirectional,!0);this.j=g="memory"===
a.optimize;this.i=y(a.fastupdate,!0);this.m=a.minlength||1;this.map=g?da(e-f):A();e=h.resolution||e;f=h.threshold||f;f>=e&&(f=e-1);this.h=e;this.l=f;this.g=g?da(e-f):A();this.C=d&&d.C||a.rtl;this.B=(b=a.matcher||c&&c.B)&&fa(b,!1);this.D=(b=a.stemmer||c&&c.D)&&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)};
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.o-this.threshold,u=A(),m=A();for(let x=0;x<l;x++){let p=b[this.C?l-1-x:x];var c=p.length;if(p&&c>=this.m&&(r||!u[p])){var e=Math.min(this.o/l*x|0,x);if(e<q){var f="";switch(this.s){case "full":if(3<c){for(var g=0;g<c;g++){var h=g?Math.min(e/2+this.o/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.m&&P(this,u,f,h,a,d)}break}case "reverse":if(2<
c){for(g=c-1;0<g;g--)f=p[g]+f,f.length>=this.m&&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.m&&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.h-this.l,e=A(),f=p,g=Math.min(r+1,l-x),e[f]=1,h=1;h<g;h++)if((p=b[this.C?l-1-x-h:x+h])&&p.length>=this.m&&!e[p]){if(e[p]=1,k=Math.min((this.h-g)/l*x+h|0,x+(h-1)),k<c){const z=this.u&&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};
function P(a,b,d,c,e,f,g){let h=g?a.g:a.map;if(!b[d]||g&&!b[d][g])a.j&&(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.j||(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))}
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.m&&!d[m])if(this.j||g||this.map[m])l[u++]=m,d[m]=1;else return c;a=l;e=a.length}if(!e)return c;b||(b=100);d=this.o-f;f=this.h-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=
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}
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)};
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 oa(a,b,d,c,e,f,g,h){let k=[],l=h?a.g:a.map;a.j||(l=pa(l,g,h,a.u));if(l){let r=0;c=Math.min(l.length,c);for(let q=0,u=0,m;q<c&&!(m=l[q],a.j&&(m=pa(m,g,h,a.u)),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)};
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.map,a,this.o-this.threshold,this.j),this.depth&&Q(this.g,a,this.h-this.l,this.j);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 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.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 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,
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}
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.j?1:0};break;case 2:f="map";g=this.map;break;case 3:f="ctx";g=this.g;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.j=!!b.opt;break;case "reg":this.i=!1;this.register=b;break;case "map":this.map=b;break;case "ctx":this.g=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({G:"create",options:b})}S("add");S("append");S("search");S("update");S("remove");
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({G:a,I: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.F=[];this.g=[];this.s=[];this.register=A();this.key=(b=a.key)&&U(b,this.s)||"id";this.i=y(a.fastupdate,!0);this.store=(b=a.store)&&A();this.v=b&&!0!==b&&[];this.A=(b=a.tag)&&U(b,this.s);this.h=b&&A();this.cache=(b=a.cache)&&new N(b);a.cache=!1;this.l=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,
f=f.field),g=G(g)?Object.assign({},b,g):b,a[f]=this.l?new R(g):new O(g,this.register),this.F[e]=U(f,this.s),this.g[e]=f;if(this.v)for(c=b.store,E(c)&&(c=[c]),b=0;b<c.length;b++)this.v[b]=U(c[b],this.s);this.index=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}
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;
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=
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)};
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};
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.F[c],E(e)&&(e=[e]),W(b,e,this.s,0,this.index[f],a,e[0],d);if(this.A){let c=ra(b,this.A),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.v){c=
A();for(let e=0,f;e<this.v.length;e++)f=this.v[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)};
t.remove=function(a){G(a)&&(a=a[this.key]);if(this.register[a]){for(var b=0;b<this.g.length&&(this.index[this.g[b]].remove(a,!0),!this.i||this.l);b++);if(this.A&&(!this.i||this.l))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};
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));
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])&&
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}())};
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.l||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.index[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.l||c.async?x[w]:c.index[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])&&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}())};
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.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)}};
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);
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.index[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)}};
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.index[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.index[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);

View File

@@ -669,11 +669,9 @@ function add(sequential_data){
// now just use add() helper method as usual:
add([{
add([{
// sequential structured data
// take the data example above
}]);
```
@@ -879,10 +877,6 @@ index.add({
id: 0,
tag: "cat",
content: "Some content ..."
},{
id: 1,
tag: "dog",
content: "Some content ..."
});
```
@@ -890,10 +884,6 @@ Your data also can have multiple tags as an array:
```js
index.add({
id: 0,
tag: ["animal", "cat"],
content: "Some content ..."
},{
id: 1,
tag: ["animal", "dog"],
content: "Some content ..."

View File

@@ -1,5 +1,3 @@
import Index from "./index.js";
import Document from "./document.js";
import { promise as Promise } from "./polyfill.js";
import { is_function, is_object } from "./common.js";

View File

@@ -1,5 +1,4 @@
import Index from "./index.js";
import Document from "./index.js";
import { IndexInterface, DocumentInterface } from "./type.js";
import { create_object, is_object } from "./common.js";
/**
@@ -27,7 +26,7 @@ export default CacheClass;
* @param {string|Object} query
* @param {number|Object=} limit
* @param {Object=} options
* @this {Document|Index}
* @this {IndexInterface}
* @returns {Array<number|string>}
*/

View File

@@ -18,6 +18,7 @@ import {
} from "./config.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 } from "./common.js";
import apply_async from "./async.js";
@@ -26,9 +27,10 @@ import { exportDocument, importDocument } from "./serialize.js";
import WorkerAdapter from "./adapter.js";
/**
* @constructor
* @implements DocumentInterface
* @param {Object=} options
* @return {Document}
* @constructor
*/
function Document(options){

View File

@@ -1,5 +1,3 @@
import { addAsync, appendAsync, removeAsync, searchAsync, updateAsync } from "./async.js";
import Document from "./document";
import { DEBUG, SUPPORT_ASYNC, SUPPORT_CACHE } from "./config";
import { searchCache } from "./cache";

View File

@@ -16,6 +16,7 @@ import {
} from "./config.js";
import { IndexInterface } from "./type.js";
import { encode as default_encoder } from "./lang/latin/default.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";
@@ -23,14 +24,15 @@ 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 apply_preset from "./presets.js";
import apply_preset from "./preset.js";
import { exportIndex, importIndex } from "./serialize.js";
/**
* @constructor
* @implements IndexInterface
* @param {Object=} options
* @param {Object=} _register
* @return {Index}
* @constructor
*/
function Index(options, _register){

View File

@@ -1,4 +1,4 @@
import Index from "./index.js";
import { IndexInterface, DocumentInterface } from "./type.js";
import { create_object } from "./common.js";
/**
@@ -7,7 +7,7 @@ import { create_object } from "./common.js";
* @param {boolean|string|RegExp=} split
* @param {boolean=} _collapse
* @returns {string|Array<string>}
* @this Index
* @this IndexInterface
*/
export function pipeline(str, normalize, split, _collapse){

View File

@@ -1,5 +1,3 @@
import Document from "../../flexsearch.js";
export const rtl = true;
export const tokenize = "";
export default {
@@ -9,10 +7,6 @@ export default {
const regex = /[\x00-\x7F]+/g;
/**
* @this Document
*/
export function encode(str){
return this.pipeline(

View File

@@ -1,5 +1,3 @@
import Document from "../../flexsearch.js";
export const rtl = false;
export const tokenize = "strict";
export default {
@@ -10,10 +8,6 @@ export default {
const regex = /[\x00-\x7F]+/g;
/**
* @this Document
*/
export function encode(str){
return this.pipeline(

View File

@@ -1,5 +1,3 @@
import Document from "../../flexsearch.js";
export const rtl = false;
export const tokenize = "";
export default {
@@ -9,10 +7,6 @@ export default {
const regex = /[\x00-\x7F]+/g;
/**
* @this Document
*/
export function encode(str){
return this.pipeline(

View File

@@ -54,7 +54,7 @@ export function encode(str, self, _skip_postprocessing){
if(str){
str = encode_simple(str, /** @type {Document} */ (self || this)).join(" ");
str = encode_simple(str, self || this).join(" ");
if(str.length > 2){

View File

@@ -34,7 +34,7 @@ export function encode(str){
if(str){
str = encode_advanced(str, /** @type {Document} */ (this), /* skip post-processing: */ true);
str = encode_advanced(str, this, /* skip post-processing: */ true);
if(str.length > 1){

View File

@@ -6,7 +6,7 @@ import { is_string } from "./common.js";
* @const
*/
const presets = {
const preset = {
"memory": {
charset: "latin:extra",
@@ -70,12 +70,12 @@ export default function apply_preset(options){
if(is_string(options)){
if(DEBUG && !presets[options]){
if(DEBUG && !preset[options]){
console.warn("Preset not found: " + options);
}
options = presets[options];
options = preset[options];
}
else{
@@ -83,12 +83,12 @@ export default function apply_preset(options){
if(preset){
if(DEBUG && !presets[preset]){
if(DEBUG && !preset[preset]){
console.warn("Preset not found: " + preset);
}
options = Object.assign({}, presets[preset], /** @type {Object} */ (options));
options = Object.assign({}, preset[preset], /** @type {Object} */ (options));
}
}

View File

@@ -1,5 +1,4 @@
import Index from "./index.js";
import Document from "./document.js";
import { IndexInterface, DocumentInterface } from "./type.js";
import { create_object, is_string } from "./common.js";
function async(callback, self, key, index_doc, index, data){
@@ -25,7 +24,7 @@ function async(callback, self, key, index_doc, index, data){
}
/**
* @this Index
* @this IndexInterface
*/
export function exportIndex(callback, self, field, index_doc, index){
@@ -89,7 +88,7 @@ export function exportIndex(callback, self, field, index_doc, index){
}
/**
* @this Index
* @this IndexInterface
*/
export function importIndex(key, data){
@@ -132,7 +131,7 @@ export function importIndex(key, data){
}
/**
* @this Document
* @this DocumentInterface
*/
export function exportDocument(callback, self, field, index_doc, index){
@@ -192,7 +191,7 @@ export function exportDocument(callback, self, field, index_doc, index){
}
/**
* @this Document
* @this DocumentInterface
*/
export function importDocument(key, data){

54
src/type.js Normal file
View File

@@ -0,0 +1,54 @@
/**
* @interface
*/
export function IndexInterface(){
this.cache = null;
}
/**
* @param {!number|string} id
* @param {!string} content
*/
IndexInterface.prototype.add;
/**
* @param {!number|string} id
* @param {!string} content
*/
IndexInterface.prototype.append;
/**
* @param {!string|Object} query
* @param {number|Object=} limit
* @param {Object=} options
* @returns {Array<number|string>}
*/
IndexInterface.prototype.search;
/**
* @param {!number|string} id
* @param {!string} content
*/
IndexInterface.prototype.update;
/**
* @param {!number|string} id
*/
IndexInterface.prototype.remove;
/**
* @interface
*/
export function DocumentInterface(){
this.field = null;
this.index = null;
}