1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-30 01:00:11 +02:00

added tags to the document

This commit is contained in:
Thomas Wilkerling
2021-05-17 19:02:41 +02:00
parent 4dd44d2f6b
commit 3e89963192
12 changed files with 641 additions and 147 deletions

24
dist/flexsearch.compact.js vendored Normal file
View File

@@ -0,0 +1,24 @@
/**!
* FlexSearch.js v0.7.0-pre-alpha (Compact)
* Copyright 2019 Nextapps GmbH
* Author: Thomas Wilkerling
* Licence: Apache-2.0
* 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;
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;
r.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<
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};
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))}
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=
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}
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)};
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};
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,
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 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;
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};
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};
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=
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);

17
dist/flexsearch.light.js vendored Normal file
View File

@@ -0,0 +1,17 @@
/**!
* FlexSearch.js v0.7.0-pre-alpha (Light)
* Copyright 2019 Nextapps GmbH
* Author: Thomas Wilkerling
* Licence: Apache-2.0
* 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,
!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)};
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<
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};
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))}
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];
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}
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)};
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};
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);

View File

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

View File

@@ -19,6 +19,25 @@ In a document every index can have its own configuration, except the `encoder`.
You can use an instance of Index directly (very much like the old FlexSearch when not indexing documents, instead just ID and text contents).
### Basic Usage
Load the library via the ES6 module system:
```js
import Index from "./index.js";
import Document from "./document.js";
var index = new Index(options);
var document = new Document(options);
```
Or load one of the builds from the folder `dist` to your html as a script and use as follows:
```js
var index = new FlexSearch.Index(options);
var document = new FlexSearch.Document(options);
```
The method signature stays almost unchanged:
```js
@@ -463,7 +482,7 @@ You need to follow 2 rules for your documents:
```js
{
"records": [ // <-- not allowed when id lives inside!
"records": [ // <-- not allowed when ID or tag lives inside!
{
"id": 0,
"title": "title"
@@ -529,7 +548,7 @@ This example breaks both rules from above:
[ // <-- not allowed as document start!
{
"tag": "cat",
"records": [ // <-- not allowed when id lives inside!
"records": [ // <-- not allowed when ID or tag lives inside!
{
"id": 0,
"body": {
@@ -577,8 +596,8 @@ function add(sequential_data){
record = data.records[y];
index.add({
tag: data.tag,
id: record.id,
tag: data.tag,
record: record
});
}
@@ -725,7 +744,7 @@ Ok, but why? These change is basically based on "boolean search". Instead of app
> A field search will apply a query with the boolean "or" logic by default. Each field has its own result to the given query.
There is only one situation where the `bool` property is still supported. When you like to switch the default "or" logic from the field search into "and", e.g.:
There is one situation where the `bool` property is still supported. When you like to switch the default "or" logic from the field search into "and", e.g.:
```js
index.search(query, {
@@ -754,7 +773,103 @@ index.search({
}
}
});
```
```
### Tags
Like the `key` for the ID just define the path to the tag:
```js
const index = new Document({
key: "id",
tag: "tag",
doc: "content"
});
```
```js
index.add({
id: 0,
tag: "cat",
content: "Some content ..."
},{
id: 1,
tag: "dog",
content: "Some content ..."
});
```
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 ..."
});
```
You can perform a tag-specific search by:
```js
index.search(query, {
field: "content",
tag: "animal"
});
```
This just gives you result which was tagged with the given tag.
Use multiple tags when searching:
```js
index.search(query, {
field: "content",
tag: ["cat", "dog"]
});
```
This gives you result which are tagged with one of the given tag.
> Multiple tags will apply as the boolean "or" by default. It just needs one of the tags to be existing.
This is another situation where the `bool` property is still supported. When you like to switch the default "or" logic from the tag search into "and", e.g.:
```js
index.search(query, {
field: "content",
tag: ["dog", "animal"],
bool: "and"
});
```
You will just get results which contains both tags (in this example there is just one records which has the tag "dog" and "animal").
### Tag Search
You can also fetch results from one or more tags when no query was passed:
```js
index.search({ tag: ["cat", "dog"] });
```
In this case the result-set looks like:
```js
[{
tag: "cat",
result: [ /* all cats */ ]
},{
tag: "dog",
result: [ /* all dogs */ ]
}]
```
> By default, every query is limited to 100 entries. Unbounded queries leads into issues. You need to set the limit as an option to adjust the size.
## Document Stores
@@ -1355,6 +1470,22 @@ FlexSearch provides you many parameters you can use to adjust the optimal balanc
<td>0</td>
</tr>
<tr></tr>
<tr>
<td>document index</td>
<td>+3 (per field)</td>
<td>-1 (per field)</td>
<td>0</td>
<td>0</td>
</tr>
<tr></tr>
<tr>
<td>document tags</td>
<td>+1 (per tag)</td>
<td>-1 (per tag)</td>
<td>0</td>
<td>0</td>
</tr>
<tr></tr>
<tr>
<td>store: true</td>
<td>+5 (per document)</td>

View File

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

View File

@@ -2,10 +2,7 @@
export const RELEASE = "browser";
/** @define {boolean} */
export const DEBUG = true;
/** @define {boolean} */
export const PROFILER = false;
export const DEBUG = false;
/** @define {boolean} */
export const POLYFILL = true;
@@ -28,26 +25,20 @@ export const SUPPORT_ASYNC = true;
/** @define {boolean} */
export const SUPPORT_PRESET = true;
/** @define {boolean} */
export const SUPPORT_STORE = true;
/** @define {boolean} */
export const SUPPORT_TAGS = true;
/** @define {boolean} */
export const SUPPORT_SUGGESTION = true;
/** @define {boolean} */
export const SUPPORT_SERIALIZE = true;
/** @define {boolean} */
export const SUPPORT_INFO = true;
/** @define {boolean} */
export const SUPPORT_DOCUMENT = true;
/** @define {boolean} */
export const SUPPORT_WHERE = true;
/** @define {boolean} */
export const SUPPORT_PAGINATION = true;
/** @define {boolean} */
export const SUPPORT_OPERATOR = true;
/** @define {boolean} */
export const SUPPORT_CALLBACK = true;

44
src/config/bundle.js Normal file
View File

@@ -0,0 +1,44 @@
/** @define {string} */
export const RELEASE = "browser";
/** @define {boolean} */
export const DEBUG = false;
/** @define {boolean} */
export const POLYFILL = true;
/** @define {boolean} */
export const SUPPORT_WORKER = true;
/** @define {boolean|string} */
export const SUPPORT_ENCODER = true;
/** @define {boolean|string} */
export const SUPPORT_LANG = true;
/** @define {boolean} */
export const SUPPORT_CACHE = true;
/** @define {boolean} */
export const SUPPORT_ASYNC = true;
/** @define {boolean} */
export const SUPPORT_PRESET = true;
/** @define {boolean} */
export const SUPPORT_STORE = true;
/** @define {boolean} */
export const SUPPORT_TAGS = true;
/** @define {boolean} */
export const SUPPORT_SUGGESTION = true;
/** @define {boolean} */
export const SUPPORT_SERIALIZE = true;
/** @define {boolean} */
export const SUPPORT_DOCUMENT = true;
/** @define {boolean} */
export const SUPPORT_PAGINATION = true;

44
src/config/compact.js Normal file
View File

@@ -0,0 +1,44 @@
/** @define {string} */
export const RELEASE = "browser";
/** @define {boolean} */
export const DEBUG = false;
/** @define {boolean} */
export const POLYFILL = false;
/** @define {boolean} */
export const SUPPORT_WORKER = false;
/** @define {boolean|string} */
export const SUPPORT_ENCODER = true;
/** @define {boolean|string} */
export const SUPPORT_LANG = false;
/** @define {boolean} */
export const SUPPORT_CACHE = false;
/** @define {boolean} */
export const SUPPORT_ASYNC = true;
/** @define {boolean} */
export const SUPPORT_PRESET = true;
/** @define {boolean} */
export const SUPPORT_STORE = true;
/** @define {boolean} */
export const SUPPORT_TAGS = false;
/** @define {boolean} */
export const SUPPORT_SUGGESTION = true;
/** @define {boolean} */
export const SUPPORT_SERIALIZE = false;
/** @define {boolean} */
export const SUPPORT_DOCUMENT = true;
/** @define {boolean} */
export const SUPPORT_PAGINATION = false;

44
src/config/light.js Normal file
View File

@@ -0,0 +1,44 @@
/** @define {string} */
export const RELEASE = "browser";
/** @define {boolean} */
export const DEBUG = false;
/** @define {boolean} */
export const POLYFILL = false;
/** @define {boolean} */
export const SUPPORT_WORKER = false;
/** @define {boolean|string} */
export const SUPPORT_ENCODER = false;
/** @define {boolean|string} */
export const SUPPORT_LANG = false;
/** @define {boolean} */
export const SUPPORT_CACHE = false;
/** @define {boolean} */
export const SUPPORT_ASYNC = false;
/** @define {boolean} */
export const SUPPORT_PRESET = false;
/** @define {boolean} */
export const SUPPORT_STORE = false;
/** @define {boolean} */
export const SUPPORT_TAGS = false;
/** @define {boolean} */
export const SUPPORT_SUGGESTION = false;
/** @define {boolean} */
export const SUPPORT_SERIALIZE = false;
/** @define {boolean} */
export const SUPPORT_DOCUMENT = false;
/** @define {boolean} */
export const SUPPORT_PAGINATION = false;

View File

@@ -6,11 +6,12 @@
* https://github.com/nextapps-de/flexsearch
*/
import { SUPPORT_ASYNC, SUPPORT_CACHE } from "./config.js";
import { create_object } from "./common.js";
import { SUPPORT_ASYNC, SUPPORT_CACHE, SUPPORT_STORE, SUPPORT_TAGS } from "./config.js";
import Index from "./index.js";
import { addAsync, appendAsync, removeAsync, searchAsync, updateAsync } from "./async.js";
import Cache, { searchCache } from "./cache.js";
import { create_object } from "./common.js";
import { addAsync, appendAsync, removeAsync, searchAsync, updateAsync } from "./async.js";
import { intersect, intersect_union } from "./intersect.js";
/**
* @param {Object=} options
@@ -29,13 +30,24 @@ function Document(options){
options || (options = {});
this.register = create_object();
this.store = (opt = options["store"]) && create_object();
this.storetree = opt && (opt !== true) && [];
this.markup = [];
this.key = ((opt = options["key"]) && parse_tree(opt, this.markup)) || "id";
this.tree = [];
this.field = [];
this.marker = [];
this.register = create_object();
this.key = ((opt = options["key"]) && parse_tree(opt, this.marker)) || "id";
this.fastupdate = parse_option(options["fastupdate"], true);
if(SUPPORT_STORE){
this.store = (opt = options["store"]) && create_object();
this.storetree = opt && (opt !== true) && [];
}
if(SUPPORT_TAGS){
this.tag = ((opt = options["tag"]) && parse_tree(opt, this.marker));
this.tagindex = opt && create_object();
}
if(SUPPORT_CACHE){
@@ -49,6 +61,11 @@ function Document(options){
export default Document;
function parse_option(value, default_value){
return typeof value !== "undefined" ? value : default_value;
}
/**
* @this Document
*/
@@ -84,11 +101,11 @@ function parse_descriptor(options){
}
index[key] = new Index(item, this.register);
this.tree[i] = parse_tree(key, this.markup);
this.tree[i] = parse_tree(key, this.marker);
this.field[i] = key;
}
if(this.storetree){
if(SUPPORT_STORE && this.storetree){
let store = options["store"];
@@ -99,14 +116,14 @@ function parse_descriptor(options){
for(let i = 0; i < store.length; i++){
this.storetree[i] = parse_tree(store[i], this.markup);
this.storetree[i] = parse_tree(store[i], this.marker);
}
}
return index;
}
function parse_tree(key, markup){
function parse_tree(key, marker){
const tree = key.split(":");
let count = 0;
@@ -121,7 +138,7 @@ function parse_tree(key, markup){
if(key){
markup[count] = true;
marker[count] = true;
}
}
@@ -139,7 +156,7 @@ function parse_tree(key, markup){
return count > 1 ? tree : tree[0];
}
function get_id(obj, tree){
function parse_simple(obj, tree){
if(typeof tree === "string"){
@@ -190,7 +207,7 @@ function store_value(obj, store, tree, pos, key){
}
}
function add_index(obj, tree, markup, pos, index, id, key, _append){
function add_index(obj, tree, marker, pos, index, id, key, _append){
obj = obj[key];
@@ -202,7 +219,7 @@ function add_index(obj, tree, markup, pos, index, id, key, _append){
if(obj.constructor === Array){
if(markup[pos]){
if(marker[pos]){
for(let i = 0; i < obj.length; i++){
@@ -224,14 +241,14 @@ function add_index(obj, tree, markup, pos, index, id, key, _append){
for(let i = 0; i < obj.length; i++){
// do not increase index, an array is not a field
add_index(obj, tree, markup, pos, index, id, i, _append);
add_index(obj, tree, marker, pos, index, id, i, _append);
}
}
else{
key = tree[++pos];
add_index(obj, tree, markup, pos, index, id, key, _append);
add_index(obj, tree, marker, pos, index, id, key, _append);
}
}
}
@@ -249,7 +266,7 @@ Document.prototype.add = function(id, content, _append){
if(typeof id === "object"){
content = id;
id = get_id(content, this.key);
id = parse_simple(content, this.key);
}
if(content && (id || (id === 0))){
@@ -269,10 +286,45 @@ Document.prototype.add = function(id, content, _append){
tree = [tree];
}
add_index(content, tree, this.markup, 0, this.index[field], id, tree[0], _append);
add_index(content, tree, this.marker, 0, this.index[field], id, tree[0], _append);
}
if(this.store){
if(SUPPORT_TAGS && this.tag){
let tag = parse_simple(content, this.tag);
let dupes = create_object();
if(typeof tag === "string"){
tag = [tag];
}
for(let i = 0, key, arr; i < tag.length; i++){
key = tag[i];
if(!dupes[key]){
dupes[key] = 1;
arr = this.tagindex[key] || (this.tagindex[key] = []);
if(!_append || (arr.indexOf(id) === -1)){
arr[arr.length] = id;
// add a reference to the register for fast updates
if(this.fastupdate){
const tmp = this.register[id] || (this.register[id] = []);
tmp[tmp.length] = arr;
}
}
}
}
}
if(SUPPORT_STORE && this.store){
let store;
@@ -297,6 +349,7 @@ Document.prototype.add = function(id, content, _append){
this.store[id] = store || content;
}
}
return this;
@@ -326,7 +379,33 @@ Document.prototype.remove = function(id){
this.index[this.field[i]].remove(id, true);
}
if(this.store){
if(SUPPORT_TAGS && this.tag){
// when fastupdate was enabled the id will be already cleanup by the index
if(!this.fastupdate){
for(let key in this.tagindex){
const tag = this.tagindex[key];
const pos = tag.indexOf(id);
if(pos !== -1){
if(tag.length > 1){
tag.splice(pos, 1);
}
else{
delete this.tagindex[key];
}
}
}
}
}
if(SUPPORT_STORE && this.store){
delete this.store[id];
}
@@ -351,75 +430,145 @@ Document.prototype.search = function(query, limit, options){
let result = [];
let pluck, enrich;
let field, field_options, bool, count = 0;
let field, field_options, tag, bool, count = 0;
if(options){
pluck = options["pluck"];
field = pluck || options["field"];
enrich = options["enrich"];
tag = SUPPORT_TAGS && options["tag"];
enrich = SUPPORT_STORE && this.store && options["enrich"];
bool = options["bool"] === "and";
limit = options["limit"];
}
if(field){
if(field){
if(typeof field === "string"){
if(typeof field === "string"){
field = [field];
field = [field];
}
else if(field.constructor !== Array){
field_options = field;
field = Object.keys(field);
}
}
else if(field.constructor !== Array){
field_options = field;
field = Object.keys(field);
if(tag){
if(typeof tag === "string"){
tag = [tag];
}
// 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 || 100, enrich);
if(res){
result[result.length] = res;
count++;
}
}
return count ? result : [];
}
}
}
else{
field = this.field;
}
field || (field = this.field);
bool = bool && ((field.length > 1) || (tag && (tag.length > 1)));
bool = bool && (field.length > 1);
let found_tag = [];
for(let i = 0, res, key, item; i < field.length; i++){
// TODO solve this in one loop below
for(let i = 0, res, key, item, len; i < field.length; i++){
key = field[i];
if(field_options){
// if(field_options){
//
// item = field_options[key];
//
// // inherit options also when search? it is just for laziness, Object.assign() has a cost
// //item = typeof item === "object" ? Object.assign({}, options, item) : options;
// }
// else{
//
// item = options;
// }
item = field_options[key];
res = this.index[key].search(query, limit, field_options ? field_options[key] : options);
len = res.length;
// inherit options?
//item = typeof item === "object" ? Object.assign({}, options, item) : options;
}
else{
if(tag && len){
item = options;
const field_tag = found_tag[i] = [];
const arr = [];
let count = 0;
if(bool){
// prepare for intersection
arr[0] = [res];
}
for(let y = 0, key, res; y < tag.length; y++){
key = tag[y];
res = this.tagindex[key];
len = res && res.length;
if(len){
arr[arr.length] = bool ? [res] : res;
field_tag[count++] = key;
}
}
if(count){
if(bool){
res = intersect(arr, limit || 100);
}
else{
res = intersect_union(res, arr);
}
len = res.length;
}
}
res = this.index[key].search(query, limit, item);
if(len){
if(bool){
result[count++] = res;
}
else if(bool){
if(!res.length){
// fast path optimization
//if(!len){
return [];
}
//}
// add a pseudo relevance index for the intersection
// used when squash the results on boolean "and"
//res = [res];
}
count += res.length;
result[i] = res;
}
if(!count){
// fast path optimization
// fast path "not found"
return [];
}
@@ -450,9 +599,12 @@ Document.prototype.search = function(query, limit, options){
key = field[i];
res = result[i];
if(enrich && this.store){
if(res.length){
res = apply_enrich.call(this, res);
if(enrich){
res = apply_enrich.call(this, res);
}
}
if(pluck){
@@ -460,16 +612,50 @@ Document.prototype.search = function(query, limit, options){
return res;
}
result[i] = {
result[i] = res = {
"field": key,
"result": res
};
if(tag){
res["tag"] = found_tag[i];
}
}
return result;
};
/**
* @this Document
*/
function get_tag(key, limit, enrich){
let res = this.tagindex[key];
let len = res && res.length;
if(len){
if(len > limit){
res = res.slice(0, limit);
}
if(enrich){
res = apply_enrich.call(this, res);
}
return {
"tag": key,
"result": res
};
}
}
/**
* @this Document
*/
@@ -492,22 +678,25 @@ function apply_enrich(res){
return arr;
}
Document.prototype.get = function(id){
return this.store[id];
};
Document.prototype.set = function(id, data){
this.store[id] = data;
return this;
};
Document.prototype.contain = function(id){
return !!this.register[id];
};
if(SUPPORT_STORE){
Document.prototype.get = function(id){
return this.store[id];
};
Document.prototype.set = function(id, data){
this.store[id] = data;
return this;
};
}
if(SUPPORT_CACHE){
Document.prototype.searchCache = searchCache;

View File

@@ -6,15 +6,15 @@
* https://github.com/nextapps-de/flexsearch
*/
import { SUPPORT_PRESET, SUPPORT_CACHE, SUPPORT_ASYNC, SUPPORT_WORKER } from "./config.js";
import { SUPPORT_PRESET, SUPPORT_CACHE, SUPPORT_ASYNC, SUPPORT_WORKER, SUPPORT_SUGGESTION } from "./config.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 { pipeline, init_stemmer_or_matcher, init_filter } from "./lang.js";
import { global_lang, global_charset } from "./global.js";
import { addAsync, appendAsync, removeAsync, searchAsync, updateAsync } from "./async.js";
import { intersect } from "./intersect.js";
import Cache, { searchCache } from "./cache.js";
import apply_preset from "./presets.js";
import intersect from "./intersect.js";
/**
* @param {Object=} options
@@ -349,16 +349,8 @@ Index.prototype.push_index = function(dupes, value, score, id, append, keyword){
if(this.fastupdate){
const tmp = this.register[id];
if(tmp){
tmp[tmp.length] = arr;
}
else{
this.register[id] = [arr];
}
const tmp = this.register[id] || (this.register[id] = []);
tmp[tmp.length] = arr;
}
}
}
@@ -392,7 +384,7 @@ Index.prototype.search = function(query, limit, options){
limit = options["limit"];
threshold = parse_option(options["threshold"], threshold);
context = options["context"];
suggest = options["suggest"];
suggest = SUPPORT_SUGGESTION && options["suggest"];
}
if(query){
@@ -569,18 +561,6 @@ Index.prototype.add_result = function(result, suggest, resolution, limit, just_o
if(!this.optimize){
arr = get_array(arr, term, keyword, this.bidirectional);
// if(keyword){
//
// const swap = this.bidirectional && (term > keyword);
//
// arr = arr[swap ? term : keyword];
// arr = arr && arr[swap ? keyword : term];
// }
// else{
//
// arr = arr[term];
// }
}
if(arr){
@@ -595,18 +575,6 @@ Index.prototype.add_result = function(result, suggest, resolution, limit, just_o
if(this.optimize){
tmp = get_array(tmp, term, keyword, this.bidirectional);
// if(keyword){
//
// const swap = this.bidirectional && (term > keyword);
//
// tmp = tmp[swap ? term : keyword];
// tmp = tmp && tmp[swap ? keyword : term];
// }
// else{
//
// tmp = tmp[term];
// }
}
if(tmp){
@@ -682,7 +650,7 @@ Index.prototype.remove = function(id, _skip_deletion){
if(this.fastupdate){
// fast updates performs really fast but did not cleanup the key entries
// fast updates performs really fast but did not fully cleanup the key entries
for(let i = 0, tmp; i < refs.length; i++){

View File

@@ -7,7 +7,7 @@ import { create_object, concat } from "./common.js";
* @returns {Array}
*/
export default function(arrays, limit, suggest) {
export function intersect(arrays, limit, suggest) {
const length = arrays.length;
let result = [];
@@ -135,3 +135,42 @@ export default function(arrays, limit, suggest) {
return result;
}
/**
* @param mandatory
* @param arrays
* @returns {Array}
*/
export function intersect_union(mandatory, arrays) {
const check = create_object();
const union = create_object();
const result = [];
for(let x = 0; x < mandatory.length; x++){
check[mandatory[x]] = 1;
}
for(let x = 0, arr; x < arrays.length; x++){
arr = arrays[x];
for(let y = 0, id; y < arr.length; y++){
id = arr[y];
if(check[id]){
if(!union[id]){
union[id] = 1;
result[result.length] = id;
}
}
}
}
return result;
}