diff --git a/README.md b/README.md index 0a37e60..6ee33ca 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@

Web's fastest and most memory-flexible full-text search library with zero dependencies.

When it comes to raw search speed FlexSearch outperforms every single searching library out there and also provides flexible search capabilities like multi-field search, phonetic transformations or partial matching. -Depending on the used options it also provides the most memory-efficient index. FlexSearch introduce a new scoring algorithm called "contextual index" based on a pre-scored lexical dictionary architecture which actually performs queries up to 100,000 times faster than other libraries. +Depending on the used options it also provides the most memory-efficient index. FlexSearch introduce a new scoring algorithm called "contextual index" based on a pre-scored lexical dictionary architecture which actually performs queries up to 1,000,000 times faster compared to other libraries. FlexSearch also provides you a non-blocking asynchronous processing model as well as web workers to perform any updates or queries on the index in parallel through dedicated balanced threads. FlexSearch Server is available here: https://github.com/nextapps-de/flexsearch-server. diff --git a/dist/flexsearch.compact.js b/dist/flexsearch.compact.js index 1f089f6..1650ddc 100644 --- a/dist/flexsearch.compact.js +++ b/dist/flexsearch.compact.js @@ -1,31 +1,31 @@ /* - FlexSearch v0.6.2 + FlexSearch v0.6.21 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence https://github.com/nextapps-de/flexsearch */ -'use strict';(function(n,y,G){let z;(z=G.define)&&z.amd?z([],function(){return y}):(z=G.modules)?z[n.toLowerCase()]=y:"object"===typeof exports?module.exports=y:G[n]=y})("FlexSearch",function(){function n(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:aa++;this.init(a,b);z(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});z(this,"length",function(){return this.index.length})}function y(a,b){const c=a.length,d=J(b),f=[];for(let k=0,g=0;k=g&&(a=a[p-(f+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return f}function S(a,b){if(a){const c=Object.keys(a);for(let d=0,f=c.length;da?1:a?-1:0}function ca(a,b){a=a[x];b=b[x];return ab?1:0}function ba(a,b){const c=x.length;for(let d=0;db?1:0}function K(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function V(a,b,c,d,f,k,g){let p,q=[];if(!0===c){c="0";var l=""}else l=c&&c.split(":"); -const e=a.length;if(1g&&(l=0),l=l||0,p=l+b,pr;c--)l=g.substring(r,c),Q(v,m,l,a,b,q,p,n-1)}break;default:if(e=Q(v,m,g,a,1,q,p,n-1),t&&1=p)for(e=m._ctx[g]||(m._ctx[g]=A()),g=this.h[g]||(this.h[g]= -W(n-(p||0))),q=b-t,l=b+t+1,0>q&&(q=0),l>h&&(l=h);q=g&&(a=a[p-(f+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return f}function S(a,b){if(a){const c=Object.keys(a);for(let d=0,f=c.length;da?1:a?-1:0}function da(a,b){a=a[z];b=b[z];return ab?1:0}function ca(a,b){const c=z.length;for(let d=0;db?1:0}function K(a,b,c){return a?{page:a, +next:b?""+b:null,result:c}:c}function W(a,b,c,d,f,k,g){let p,q=[];if(!0===c){c="0";var l=""}else l=c&&c.split(":");const e=a.length;if(1g&&(l=0),l=l||0,p=l+b,pr;c--)l=g.substring(r,c),Q(v,m,l,a,b,q,p,n-1)}break;default:if(e= +Q(v,m,g,a,1,q,p,n-1),t&&1=p)for(e=m._ctx[g]||(m._ctx[g]=A()),g=this.h[g]||(this.h[g]=X(n-(p||0))),q=b-t,l=b+t+1,0>q&&(q=0),l>h&&(l=h);q= -h&&(this.D=this.i),this.D===this.i&&(this.cache&&this.v.set(b,this.A),this.H&&this.H(this.A)));return this}function n(a,b){for(var c=a.length,h=V(b),t=[],q=0,e=0;q=e&&(a=a[d-(t+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=h);return t}function Z(a,b){if(a)for(var c=Object.keys(a),h=0,t=c.length;ha?1:a?-1:0}function ra(a,b){a=a[F];b=b[F];return ab?1:0}function sa(a,b){for(var c=F.length,h=0;hb?1:0}function L(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function ia(a,b,c,h,t,q,e){var d=[];if(!0===c){c="0";var f=""}else f=c&&c.split(":");var g=a.length;if(1e&&(f=0);f=f||0;var N=f+b;N=this.b.length&&(this.w=0),this.b[this.w].postMessage({add:!0,id:a,content:b}),this.f[h]=""+this.w,c&&c(),this;if(!e){if(this.async&&"function"!==typeof importScripts){var f=this;h=new Promise(function(c){setTimeout(function(){f.add(a,b,null,d,!0);f=null;c()})});if(c)h.then(c);else return h;return this}if(c)return this.add(a,b,null,d,!0),c(),this}b= -this.encode(b);if(!b.length)return this;c=this.g;e=V(c)?c(b):b.split(this.split);this.filter&&(e=n(e,this.filter));var t=H();t._ctx=H();for(var g=e.length,k=this.threshold,ba=this.depth,r=this.c,A=this.u,m=this.G,p=0;px;B--)u=z.substring(x,B),G(A,t,u,a,w,y,k,r-1);break;default:if(v=G(A,t,z,a,1,y,k,r-1),ba&&1=k)for(v=t._ctx[z]||(t._ctx[z]=H()),z=this.s[z]||(this.s[z]=ja(r-(k||0))),y=p-ba,u=p+ba+1,0>y&&(y=0),u>g&&(u=g);yf;d--)k=g[d-1],g[d]=k,e[k]=d;g[f]=a;e[a]=f}}}return b};return a}();return f}(function(){var d={},l="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(f,k,n,T,g){n=l?URL.createObjectURL(new Blob(["("+n.toString()+")()"],{type:"text/javascript"})):f+".es5.js";f+="-"+k;d[f]||(d[f]=[]);d[f][g]=new Worker(n);d[f][g].onmessage=T;console.log("Register Worker: "+f+"@"+g);return d[f][g]}}()),this); +'use strict';function ca(b){var m=0;return function(){return m= +g&&(this.D=this.i),this.D===this.i&&(this.cache&&this.v.set(c,this.A),this.H&&this.H(this.A)));return this}function l(a){var c=D(),d;for(d in a)if(a.hasOwnProperty(d)){var g=a[d];c[d]=H(g)?g.slice(0):F(g)?l(g):g}return c}function U(a,c){for(var d=a.length,g=V(c),b=[],k=0,e=0;k=e&&(a=a[t-(b+.5>>0)],a=a[d]||(a[d]=[]),a[a.length]=g);return b}function ba(a,c){if(a)for(var d= +Object.keys(a),g=0,b=d.length;ga?1:a?-1:0}function sa(a, +c){a=a[E];c=c[E];return ac?1:0}function aa(a,c){for(var d=E.length,g=0;gc?1:0}function T(a,c,d){return a?{page:a,next:c?""+c:null,result:d}:d}function ja(a,c,d,g,b,e,f){var k=[];if(!0===d){d="0";var n=""}else n=d&&d.split(":");var K=a.length;if(1f&&(n=0);n=n||0;var L=n+c;L=this.b.length&&(this.w=0),this.b[this.w].postMessage({add:!0,id:a,content:c}),this.f[g]=""+this.w,d&&d(),this;if(!e){if(this.async&&"function"!==typeof importScripts){var n=this;g=new Promise(function(d){setTimeout(function(){n.add(a, +c,null,b,!0);n=null;d()})});if(d)g.then(d);else return g;return this}if(d)return this.add(a,c,null,b,!0),d(),this}c=this.encode(c);if(!c.length)return this;d=this.g;e=V(d)?d(c):c.split(this.split);this.filter&&(e=U(e,this.filter));var f=D();f._ctx=D();for(var v=e.length,O=this.threshold,h=this.depth,u=this.c,q=this.u,p=this.G,r=0;ry;A--)w=l.substring(y,A),S(q,f,w,a,B,z,O,u-1);break;default:if(x=S(q,f,l,a,1,z,O,u-1),h&&1=O)for(x=f._ctx[l]||(f._ctx[l]=D()),l=this.s[l]||(this.s[l]=ka(u-(O||0))),z=r-h,w=r+h+1,0>z&&(z=0),w>v&&(w=v);zf;c--)l=h[c-1],h[c]=l,e[l]=c;h[f]=a;e[a]=f}}}return b};return a}();return e}(function(){var b={},m="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(e,h,l,U,q){l=m?URL.createObjectURL(new Blob(["("+l.toString()+")()"],{type:"text/javascript"})):e+".es5.js";e+="-"+h;b[e]||(b[e]=[]);b[e][q]=new Worker(l);b[e][q].onmessage=U;console.log("Register Worker: "+e+ +"@"+q);return b[e][q]}}()),this); diff --git a/dist/flexsearch.light.js b/dist/flexsearch.light.js index 2a23b30..4892ce5 100644 --- a/dist/flexsearch.light.js +++ b/dist/flexsearch.light.js @@ -1,19 +1,19 @@ /* - FlexSearch v0.6.2 + FlexSearch v0.6.21 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence https://github.com/nextapps-de/flexsearch */ -'use strict';(function(e,A,w){let n;(n=w.define)&&n.amd?n([],function(){return A}):(n=w.modules)?n[e.toLowerCase()]=A:"object"===typeof exports?module.exports=A:w[e]=A})("FlexSearch",function(){function e(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:M++;this.init(a,b);w(this,"index",function(){return Object.keys(this.c)});w(this,"length",function(){return this.index.length})}function A(a,b){const c=a.length,f=C(b),d=[];for(let k=0,h=0;k=h&&(a=a[g-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=f);return d}function G(a,b){if(a){const c=Object.keys(a);for(let f=0,d=c.length;f=h&&(a=a[g-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=f);return d}function G(a,b){if(a){const c=Object.keys(a);for(let f=0,d=c.length;fa?1:a?-1:0}function H(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function E(a){return"string"===typeof a}function C(a){return"function"===typeof a}function F(a){return"undefined"===typeof a}function J(a){const b=Array(a);for(let c=0;cl;c--)m=k.substring(l,c),D(p,f,m,a,b,g,r,v-1)}break;default:if(h=D(p,f,k,a,1,g,r,v-1),u&&1=r)for(h=f._ctx[k]||(f._ctx[k]=x()),k=this.f[k]||(this.f[k]=J(v-(r||0))),g=e-u,m=e+u+1,0>g&&(g=0),m>d&&(m=d);gl;c--)m=k.substring(l,c),D(q,f,m,a,b,g,r,v-1)}break;default:if(h=D(q,f,k,a,1,g,r,v-1),u&&1=r)for(h=f._ctx[k]||(f._ctx[k]=x()),k=this.f[k]||(this.f[k]=J(v-(r||0))),g=e-u,m=e+u+1,0>g&&(g=0),m>d&&(m=d);gy&&(g=0),z=g||0,k=z+b,ky&&(g=0),z=g||0,k=z+b,k=d&&(this.u=this.g),this.u===this.g&&(this.cache&&this.l.set(b,this.o),this.F&&this.F(this.o)));return this}function N(a,b){const c=a.length,d=J(b),e=[];for(let g=0,f=0;g=f&&(a=a[l-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e}function W(a,b){if(a){const c=Object.keys(a);for(let d=0,e=c.length;da?1:a?-1:0}function ha(a,b){a=a[A];b=b[A];return ab?1:0}function fa(a, -b){const c=A.length;for(let d=0;db?1:0}function O(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function Y(a,b,c,d,e,g,f){let l,r=[];if(!0===c){c="0";var p=""}else p=c&&c.split(":");const q=a.length;if(1f&&(p=0),p=p||0,l=p+b,l=this.m.length&&(this.C=0),this.m[this.C].postMessage({add:!0,id:a,content:b}),this.c[g]=""+this.C,c&&c(),this;if(!e){if(this.async&&"function"!==typeof importScripts){let e=this;g=new Promise(function(c){setTimeout(function(){e.add(a,b,null,d,!0);e=null;c()})});if(c)g.then(c);else return g;return this}if(c)return this.add(a,b,null,d,!0), -c(),this}b=this.encode(b);if(!b.length)return this;c=this.f;e=J(c)?c(b):b.split(this.split);this.filter&&(e=N(e,this.filter));const n=w();n._ctx=w();const k=e.length,h=this.threshold,m=this.depth,u=this.b,v=this.j,T=this.D;for(let b=0;bq;c--)p=f.substring(q,c),S(v,n,p,a,b,r,h,u-1)}break;default:if(l=S(v,n,f,a,1,r,h,u-1),m&&1=h)for(l=n._ctx[f]||(n._ctx[f]=w()),f=this.i[f]||(this.i[f]=Z(u-(h||0))),r=b-m,p=b+m+1,0>r&&(r=0),p>k&&(p=k);rc;d--)e=f[d-1],f[d]=e,b[e]=d;f[c]=a;b[a]=c}}}return b};return a}();return m}(function(){const y={},L="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(m,B,N,R,M){N=L?URL.createObjectURL(new Blob(["("+N.toString()+")()"],{type:"text/javascript"})):m+".min.js";m+="-"+B;y[m]||(y[m]=[]);y[m][M]=new Worker(N);y[m][M].onmessage=R;return y[m][M]}}()), -this); +'use strict';(function(z,M,m){let A;(A=m.define)&&A.amd?A([],function(){return M}):(A=m.modules)?A[z.toLowerCase()]=M:"object"===typeof exports?module.exports=M:m[z]=M})("FlexSearch",function ea(z){function m(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:fa++;this.init(a,b);Y(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].c):Object.keys(this.c)});Y(this,"length",function(){return this.index.length})}function A(a,b,c,d){this.u!==this.g&&(this.o=this.o.concat(c),this.u++, +d&&this.o.length>=d&&(this.u=this.g),this.u===this.g&&(this.cache&&this.l.set(b,this.o),this.F&&this.F(this.o)));return this}function N(a){const b=w();for(const c in a)if(a.hasOwnProperty(c)){const d=a[c];b[c]=x(d)?d.slice(0):B(d)?N(d):d}return b}function S(a,b){const c=a.length,d=J(b),e=[];for(let g=0,f=0;g=f&&(a=a[l-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]= +d);return e}function W(a,b){if(a){const c=Object.keys(a);for(let d=0,e=c.length;da?1:a?-1:0}function ia(a,b){a=a[E];b=b[E];return ab?1:0}function ha(a,b){const c=E.length;for(let d=0;db?1:0}function O(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function Z(a,b,c,d,e,g,f){let l,r=[];if(!0===c){c="0";var p=""}else p=c&&c.split(":");const q=a.length;if(1f&&(p=0),p=p||0,l=p+b,l=this.m.length&&(this.C=0),this.m[this.C].postMessage({add:!0,id:a,content:b}),this.c[g]=""+this.C,c&&c(),this;if(!e){if(this.async&&"function"!==typeof importScripts){let e=this;g=new Promise(function(c){setTimeout(function(){e.add(a, +b,null,d,!0);e=null;c()})});if(c)g.then(c);else return g;return this}if(c)return this.add(a,b,null,d,!0),c(),this}b=this.encode(b);if(!b.length)return this;c=this.f;e=J(c)?c(b):b.split(this.split);this.filter&&(e=S(e,this.filter));const n=w();n._ctx=w();const k=e.length,h=this.threshold,m=this.depth,u=this.b,v=this.j,T=this.D;for(let b=0;bq;c--)p=f.substring(q,c),R(v,n,p,a,b,r,h,u-1)}break;default:if(l=R(v,n,f,a,1,r,h,u-1),m&&1=h)for(l=n._ctx[f]||(n._ctx[f]=w()),f=this.i[f]||(this.i[f]=aa(u-(h||0))),r=b-m,p=b+m+1,0>r&&(r=0),p>k&&(p=k);rc;d--)e=f[d-1],f[d]=e,b[e]=d;f[c]=a;b[a]=c}}}return b};return a}();return m}(function(){const z={},M="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(m,A,N,S,K){N=M?URL.createObjectURL(new Blob(["("+ +N.toString()+")()"],{type:"text/javascript"})):m+".min.js";m+="-"+A;z[m]||(z[m]=[]);z[m][K]=new Worker(N);z[m][K].onmessage=S;return z[m][K]}}()),this); diff --git a/dist/flexsearch.node.js b/dist/flexsearch.node.js index dc57691..e99ba14 100644 --- a/dist/flexsearch.node.js +++ b/dist/flexsearch.node.js @@ -1,36 +1,37 @@ /* - FlexSearch v0.6.2 + FlexSearch v0.6.21 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence https://github.com/nextapps-de/flexsearch */ -'use strict';(function(m,H,I){let z;(z=I.define)&&z.amd?z([],function(){return H}):(z=I.modules)?z[m.toLowerCase()]=H:"object"===typeof exports?module.exports=H:I[m]=H})("FlexSearch",function(){function m(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:aa++;this.init(a,b);z(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});z(this,"length",function(){return this.index.length})}function H(a,b){const c=a.length,d=J(b),e=[];for(let g=0,f=0;g=f&&(a=a[k-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e}function T(a,b){if(a){const c=Object.keys(a);for(let d=0,e=c.length;da?1:a?-1:0}function ca(a,b){a=a[y];b=b[y];return ab?1:0}function ba(a,b){const c=y.length;for(let d=0;db?1:0}function L(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function V(a,b,c,d,e,g,f){let k,r=[];if(!0===c){c="0";var p= -""}else p=c&&c.split(":");const q=a.length;if(1f&&(p=0),p=p||0,k=p+b,kq;c--)p=f.substring(q,c),P(v,n,p,a,b,r,h,m-1)}break;default:if(k=P(v,n,f,a,1,r,h,m-1),t&&1=h)for(k=n._ctx[f]||(n._ctx[f]=u()),f=this.h[f]||(this.h[f]=W(m-(h||0))),r=b-t,p=b+t+1,0>r&&(r=0),p>l&&(p=l);rc;d--)e=f[d-1],f[d]=e,b[e]=d;f[c]=a;b[a]=c}}}return b};return a}();return m}(!1),this); +'use strict';(function(m,H,K){let A;(A=K.define)&&A.amd?A([],function(){return H}):(A=K.modules)?A[m.toLowerCase()]=H:"object"===typeof exports?module.exports=H:K[m]=H})("FlexSearch",function(){function m(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:ba++;this.init(a,b);V(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});V(this,"length",function(){return this.index.length})}function H(a){const b=u();for(const c in a)if(a.hasOwnProperty(c)){const d= +a[c];b[c]=x(d)?d.slice(0):y(d)?H(d):d}return b}function K(a,b){const c=a.length,d=I(b),e=[];for(let g=0,f=0;g=f&&(a=a[k-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e}function T(a,b){if(a){const c=Object.keys(a);for(let d=0,e=c.length;da?1:a?-1:0}function da(a,b){a=a[z];b=b[z];return ab?1:0}function ca(a,b){const c=z.length;for(let d=0;db?1:0}function L(a, +b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function W(a,b,c,d,e,g,f){let k,r=[];if(!0===c){c="0";var p=""}else p=c&&c.split(":");const q=a.length;if(1f&&(p=0),p=p||0,k=p+b,kq;c--)p=f.substring(q,c),P(v,n,p,a,b,r,h,m-1)}break;default:if(k=P(v,n,f,a,1,r,h,m-1),t&&1=h)for(k=n._ctx[f]||(n._ctx[f]=u()),f=this.h[f]||(this.h[f]=X(m-(h||0))),r=b-t,p=b+t+1,0>r&&(r=0),p>l&&(p=l);rc;d--)e=f[d-1],f[d]=e,b[e]=d;f[c]=a;b[a]=c}}}return b};return a}();return m}(!1),this); diff --git a/dist/flexsearch.pre.js b/dist/flexsearch.pre.js index 7a3b396..a57d5e0 100644 --- a/dist/flexsearch.pre.js +++ b/dist/flexsearch.pre.js @@ -1,30 +1,40 @@ /* - FlexSearch v0.6.2 + FlexSearch v0.6.21 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence https://github.com/nextapps-de/flexsearch */ 'use strict'; -(function(m, H, I) { - let z; - (z = I.define) && z.amd ? z([], function() { +(function(m, H, K) { + let A; + (A = K.define) && A.amd ? A([], function() { return H; - }) : (z = I.modules) ? z[m.toLowerCase()] = H : "object" === typeof exports ? module.exports = H : I[m] = H; + }) : (A = K.modules) ? A[m.toLowerCase()] = H : "object" === typeof exports ? module.exports = H : K[m] = H; })("FlexSearch", function() { function m(a, b) { const c = b ? b.id : a && a.id; - this.id = c || 0 === c ? c : aa++; + this.id = c || 0 === c ? c : ba++; this.init(a, b); - z(this, "index", function() { + V(this, "index", function() { return this.a ? Object.keys(this.a.index[this.a.keys[0]].f) : Object.keys(this.f); }); - z(this, "length", function() { + V(this, "length", function() { return this.index.length; }); } - function H(a, b) { - const c = a.length, d = J(b), e = []; + function H(a) { + const b = u(); + for (const c in a) { + if (a.hasOwnProperty(c)) { + const d = a[c]; + b[c] = x(d) ? d.slice(0) : y(d) ? H(d) : d; + } + } + return b; + } + function K(a, b) { + const c = a.length, d = I(b), e = []; for (let g = 0, f = 0; g < c; g++) { const c = a[g]; if (d && b(c) || !d && !b[c]) { @@ -33,8 +43,8 @@ } return e; } - function I(a, b, c, d, e, g, f, k, r, p) { - c = V(c, f ? 0 : e, k, g, b, r, p); + function A(a, b, c, d, e, g, f, k, r, p) { + c = W(c, f ? 0 : e, k, g, b, r, p); let q; k && (k = c.page, q = c.next, c = c.result); if (f) { @@ -50,18 +60,18 @@ b = g; } c = b; - d && (J(d) || (y = d.split(":"), 1 < y.length ? d = ba : (y = y[0], d = ca)), c.sort(d)); + d && (I(d) || (z = d.split(":"), 1 < z.length ? d = ca : (z = z[0], d = da)), c.sort(d)); c = L(k, q, c); this.cache && this.j.set(a, c); return c; } - function z(a, b, c) { + function V(a, b, c) { Object.defineProperty(a, b, {get:c}); } function h(a) { return new RegExp(a, "g"); } - function K(a, b) { + function J(a, b) { for (let c = 0; c < b.length; c += 2) { a = a.replace(b[c], b[c + 1]); } @@ -87,7 +97,7 @@ 1 === d ? delete a[e] : f.splice(c, 1); break; } else { - A(f[c]) && T(f[c], b); + y(f[c]) && T(f[c], b); } } } @@ -113,26 +123,26 @@ } return b; } - function da(a, b) { + function ea(a, b) { a = a.length - b.length; return 0 > a ? 1 : a ? -1 : 0; } - function ca(a, b) { - a = a[y]; - b = b[y]; + function da(a, b) { + a = a[z]; + b = b[z]; return a < b ? -1 : a > b ? 1 : 0; } - function ba(a, b) { - const c = y.length; + function ca(a, b) { + const c = z.length; for (let d = 0; d < c; d++) { - a = a[y[d]], b = b[y[d]]; + a = a[z[d]], b = b[z[d]]; } return a < b ? -1 : a > b ? 1 : 0; } function L(a, b, c) { return a ? {page:a, next:b ? "" + b : null, result:c} : c; } - function V(a, b, c, d, e, g, f) { + function W(a, b, c, d, e, g, f) { let k, r = []; if (!0 === c) { c = "0"; @@ -142,8 +152,8 @@ } const q = a.length; if (1 < q) { - const R = u(); - let B = [], M, G; + const R = u(), B = []; + let M, G; var n = 0, l; let N; var h = !0; @@ -263,16 +273,16 @@ function x(a) { return a.constructor === Array; } - function J(a) { + function I(a) { return "function" === typeof a; } - function A(a) { + function y(a) { return "object" === typeof a; } function C(a) { return "undefined" === typeof a; } - function W(a) { + function X(a) { const b = Array(a); for (let c = 0; c < a; c++) { b[c] = u(); @@ -282,9 +292,9 @@ function u() { return Object.create(null); } - const w = {encode:"icase", c:"forward", split:/\W+/, cache:!1, async:!1, C:!1, v:!1, a:!1, b:9, threshold:0, depth:0}, X = {memory:{encode:"extra", c:"strict", threshold:0, b:1}, speed:{encode:"icase", c:"strict", threshold:1, b:3, depth:2}, match:{encode:"extra", c:"full", threshold:1, b:3}, score:{encode:"extra", c:"strict", threshold:1, b:9, depth:4}, balance:{encode:"balance", c:"strict", threshold:0, b:3, depth:3}, fast:{encode:"icase", c:"strict", threshold:8, b:9, depth:1}}, S = []; - let aa = 0; - const Y = {}, Z = {}; + const w = {encode:"icase", c:"forward", split:/\W+/, cache:!1, async:!1, C:!1, v:!1, a:!1, b:9, threshold:0, depth:0}, Y = {memory:{encode:"extra", c:"strict", threshold:0, b:1}, speed:{encode:"icase", c:"strict", threshold:1, b:3, depth:2}, match:{encode:"extra", c:"full", threshold:1, b:3}, score:{encode:"extra", c:"strict", threshold:1, b:9, depth:4}, balance:{encode:"balance", c:"strict", threshold:0, b:3, depth:3}, fast:{encode:"icase", c:"strict", threshold:8, b:9, depth:1}}, S = []; + let ba = 0; + const Z = {}, aa = {}; m.create = function(a, b) { return new m(a, b); }; @@ -299,8 +309,8 @@ return this; }; m.registerLanguage = function(a, b) { - Y[a] = b.filter; - Z[a] = b.stemmer; + Z[a] = b.filter; + aa[a] = b.stemmer; return this; }; m.encode = function(a, b) { @@ -315,7 +325,7 @@ a || (a = w), c = a.preset; } b = {}; - F(a) ? (b = X[a], a = {}) : c && (b = X[c]); + F(a) ? (b = Y[a], a = {}) : c && (b = Y[c]); this.c = a.tokenize || b.c || this.c || w.c; this.split = a.split || this.split || w.split; this.v = a.rtl || this.v || w.v; @@ -324,10 +334,10 @@ this.b = C(c = a.resolution) ? c = b.b || this.b || w.b : c; c <= this.threshold && (this.b = this.threshold + 1); this.depth = "strict" !== this.c || C(c = a.depth) ? b.depth || this.depth || w.depth : c; - this.o = (c = C(c = a.encode) ? b.encode || w.encode : c) && O[c] && O[c].bind(O) || (J(c) ? c : this.o || !1); + this.o = (c = C(c = a.encode) ? b.encode || w.encode : c) && O[c] && O[c].bind(O) || (I(c) ? c : this.o || !1); (c = a.matcher) && this.addMatcher(c); if (c = (b = a.lang) || a.filter) { - F(c) && (c = Y[c]); + F(c) && (c = Z[c]); if (x(c)) { var d = this.o, e = u(); for (var g = 0; g < c.length; g++) { @@ -340,7 +350,7 @@ } if (c = b || a.stemmer) { var k; - b = F(c) ? Z[c] : c; + b = F(c) ? aa[c] : c; d = this.o; e = []; for (k in b) { @@ -348,8 +358,8 @@ } this.stemmer = k = e; } - this.a = e = (c = a.doc) ? c : this.a || w.a; - this.i = W(this.b - (this.threshold || 0)); + this.a = e = (c = a.doc) ? H(c) : this.a || w.a; + this.i = X(this.b - (this.threshold || 0)); this.h = u(); this.f = u(); if (e) { @@ -372,7 +382,7 @@ f[d[b]] = a; } } else { - A(d) && (f = d); + y(d) && (f = d); } } } @@ -385,21 +395,21 @@ } if (d) { let c; - x(d) || (A(d) ? (c = d, e.field = d = Object.keys(d)) : e.field = d = [d]); + x(d) || (y(d) ? (c = d, e.field = d = Object.keys(d)) : e.field = d = [d]); for (e = 0; e < d.length; e++) { g = d[e], x(g) || (c && (a = c[g]), b[e] = g, d[e] = g.split(":")), k[g] = new m(a), k[g].g = this.g; } } } this.u = !0; - this.j = (this.cache = c = C(c = a.cache) ? this.cache || w.cache : c) ? new ea(c) : !1; + this.j = (this.cache = c = C(c = a.cache) ? this.cache || w.cache : c) ? new fa(c) : !1; return this; }; m.prototype.encode = function(a) { - a && S.length && (a = K(a, S)); - a && this.m.length && (a = K(a, this.m)); + a && S.length && (a = J(a, S)); + a && this.m.length && (a = J(a, this.m)); a && this.o && (a = this.o(a)); - a && this.stemmer && (a = K(a, this.stemmer)); + a && this.stemmer && (a = J(a, this.stemmer)); return a; }; m.prototype.addMatcher = function(a) { @@ -410,7 +420,7 @@ return this; }; m.prototype.add = function(a, b, c, d, e) { - if (this.a && A(a)) { + if (this.a && y(a)) { return this.s("add", a, b); } if (b && F(b) && (a || 0 === a)) { @@ -444,8 +454,8 @@ return this; } c = this.c; - e = J(c) ? c(b) : b.split(this.split); - this.filter && (e = H(e, this.filter)); + e = I(c) ? c(b) : b.split(this.split); + this.filter && (e = K(e, this.filter)); const n = u(); n._ctx = u(); const l = e.length, h = this.threshold, t = this.depth, m = this.b, v = this.i, Q = this.v; @@ -475,7 +485,7 @@ break; default: if (k = P(v, n, f, a, 1, r, h, m - 1), t && 1 < l && k >= h) { - for (k = n._ctx[f] || (n._ctx[f] = u()), f = this.h[f] || (this.h[f] = W(m - (h || 0))), r = b - t, p = b + t + 1, 0 > r && (r = 0), p > l && (p = l); r < p; r++) { + for (k = n._ctx[f] || (n._ctx[f] = u()), f = this.h[f] || (this.h[f] = X(m - (h || 0))), r = b - t, p = b + t + 1, 0 > r && (r = 0), p > l && (p = l); r < p; r++) { r !== b && P(f, k, e[r], a, 0, m - (r < b ? b - r : r - b), h, m - 1); } } @@ -541,14 +551,14 @@ return this; }; m.prototype.update = function(a, b, c) { - if (this.a && A(a)) { + if (this.a && y(a)) { return this.s("update", a, b); } this.f["@" + a] && F(b) && (this.remove(a), this.add(a, b, c, !0)); return this; }; m.prototype.remove = function(a, b, c) { - if (this.a && A(a)) { + if (this.a && y(a)) { return this.s("remove", a, b); } var d = "@" + a; @@ -583,9 +593,9 @@ } return this; }; - let y; + let z; m.prototype.search = function(a, b, c, d) { - if (A(b)) { + if (y(b)) { if (x(b)) { for (var e = 0; e < b.length; e++) { b[e].query = a; @@ -596,11 +606,11 @@ a = b; b = 1000; } else { - b && J(b) ? (c = b, b = 1000) : b || 0 === b || (b = 1000); + b && I(b) ? (c = b, b = 1000) : b || 0 === b || (b = 1000); } let g = [], f = a; let k, h, p; - if (A(a) && !x(a)) { + if (y(a) && !x(a)) { c || (c = a.callback) && (f.callback = null); h = a.sort; k = a.page; @@ -634,17 +644,17 @@ m && (f = m[t]), k && !F(f) && (f.page = null, f.limit = 0), g[t] = q[l[t]].search(f, 0); } if (c) { - return c(I.call(this, a, B, g, h, b, p, r, k, u, v)); + return c(A.call(this, a, B, g, h, b, p, r, k, u, v)); } if (this.async) { const c = this; return new Promise(function(d) { Promise.all(g).then(function(e) { - d(I.call(c, a, B, e, h, b, p, r, k, u, v)); + d(A.call(c, a, B, e, h, b, p, r, k, u, v)); }); }); } - return I.call(this, a, B, g, h, b, p, r, k, u, v); + return A.call(this, a, B, g, h, b, p, r, k, u, v); } q || (q = this.threshold || 0); if (!d) { @@ -685,14 +695,14 @@ return g; } c = this.c; - c = J(c) ? c(f) : f.split(this.split); - this.filter && (c = H(c, this.filter)); + c = I(c) ? c(f) : f.split(this.split); + this.filter && (c = K(c, this.filter)); m = c.length; d = !0; e = []; const w = u(); let v = 0; - 1 < m && (this.depth && "strict" === this.c ? n = !0 : c.sort(da)); + 1 < m && (this.depth && "strict" === this.c ? n = !0 : c.sort(ea)); if (!n || (t = this.h)) { const b = this.b; for (; v < m; v++) { @@ -723,7 +733,7 @@ if (k) { let d; for (let e = 0; e < b - q; e++) { - if (d = k[e][a]) { + if (d = k[e] && k[e][a]) { c[g++] = d, f = !0; } } @@ -743,7 +753,7 @@ } else { d = !1; } - d && (g = V(e, b, k, p)); + d && (g = W(e, b, k, p)); this.cache && this.j.set(a, g); return g; }; @@ -756,7 +766,7 @@ let k; var h; let p; - if (A(a)) { + if (y(a)) { c || (c = b); var q = Object.keys(a); var n = q.length; @@ -783,7 +793,7 @@ h[l] = q[l].split(":"); } } else { - if (J(a)) { + if (I(a)) { b = d || Object.keys(e); c = b.length; for (q = 0; q < c; q++) { @@ -890,7 +900,7 @@ }, simple:function() { const a = [h("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"), "a", h("[\u00e8\u00e9\u00ea\u00eb]"), "e", h("[\u00ec\u00ed\u00ee\u00ef]"), "i", h("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"), "o", h("[\u00f9\u00fa\u00fb\u00fc\u0171]"), "u", h("[\u00fd\u0177\u00ff]"), "y", h("\u00f1"), "n", h("\u00e7"), "c", h("\u00df"), "s", h(" & "), " and ", h("[-/]"), " ", h("[^a-z0-9 ]"), "", h("\\s+"), " "]; return function(b) { - b = K(b.toLowerCase(), a); + b = J(b.toLowerCase(), a); return " " === b ? "" : b; }; }(), advanced:function() { @@ -900,7 +910,7 @@ return b; } b = this.simple(b); - 2 < b.length && (b = K(b, a)); + 2 < b.length && (b = J(b, a)); c || 1 < b.length && (b = U(b)); return b; }; @@ -915,7 +925,7 @@ b = b.split(" "); for (let c = 0; c < b.length; c++) { const d = b[c]; - 1 < d.length && (b[c] = d[0] + K(d.substring(1), a)); + 1 < d.length && (b[c] = d[0] + J(d.substring(1), a)); } b = b.join(" "); b = U(b); @@ -925,9 +935,9 @@ }(), balance:function() { const a = [h("[-/]"), " ", h("[^a-z0-9 ]"), "", h("\\s+"), " "]; return function(b) { - return U(K(b.toLowerCase(), a)); + return U(J(b.toLowerCase(), a)); }; - }()}, ea = function() { + }()}, fa = function() { function a(a) { this.clear(); this.A = !0 !== a && a; diff --git a/flexsearch.js b/flexsearch.js index 8ea54ed..8d2815c 100644 --- a/flexsearch.js +++ b/flexsearch.js @@ -1,5 +1,5 @@ /**! - * @preserve FlexSearch v0.6.2 + * @preserve FlexSearch v0.6.21 * Copyright 2019 Nextapps GmbH * Author: Thomas Wilkerling * Released under the Apache 2.0 Licence @@ -556,7 +556,7 @@ (custom = options["doc"]) ? - custom + clone_object(custom) : this.doc || defaults.doc ); @@ -622,7 +622,6 @@ //TODO: delegate tag indexes to intersection //field_custom[tag[i]] = tag_options; - this._tag[tag[i]] = create_object(); } @@ -772,6 +771,34 @@ return this; }; + function clone_object(obj){ + + const clone = create_object(); + + for(const key in obj){ + + if(obj.hasOwnProperty(key)){ + + const value = obj[key]; + + if(is_array(value)){ + + clone[key] = value.slice(0); + } + else if(is_object(value)){ + + clone[key] = clone_object(value); + } + else{ + + clone[key] = value; + } + } + } + + return clone; + } + function filter_words(words, fn_or_map){ const length = words.length; diff --git a/package.json b/package.json index a13529b..9453148 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flexsearch", - "version": "0.6.2", + "version": "0.6.21", "description": "Next-Generation full text search library with zero dependencies.", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling",