diff --git a/README.md b/README.md index 211689d..c360c0d 100644 --- a/README.md +++ b/README.md @@ -1182,7 +1182,7 @@ Returns information e.g.: ## Index Documents (Field-Search) -#### The Document Descriptor +### The Document Descriptor Assume the document is an array of data like: @@ -1252,7 +1252,7 @@ var index = new FlexSearch({ }); ``` -#### Complex Objects +### Complex Objects Assume the document array looks more complex (has nested branches etc.), e.g.: @@ -1292,7 +1292,7 @@ var index = new FlexSearch({ > __Hint:__ This is an alternative for indexing documents which has nested arrays: https://github.com/nextapps-de/flexsearch/issues/36 -#### Add/Update/Remove Documents to/from the Index +### Add/Update/Remove Documents to/from the Index Just pass the document array (or a single object) to the index: @@ -1326,7 +1326,7 @@ When the id is known, you can also simply remove by (faster): index.remove(id); ``` -#### Field-Search +### Field-Search The search gives you several options when using documents. @@ -1413,6 +1413,36 @@ var results = index.search([{ See all available field-search options. +### Configure Store + +You can define independently which fields should be indexed and which fields should be stored. This way you can index fields which should not be included in the search result. + +> When the `store` attribute was set, you have to include all fields which should be stored explicitly (acts like a whitelist). + +> When the `store` attribute was not set, the original document is stored as a fallback. + +```js +var index = new FlexSearch({ + doc: { + id: "id", + field: "body:content", // index + store: "title" // store + } +}); +``` + +Also multiple fields: + +```js +var index = new FlexSearch({ + doc: { + id: "id", + field: ["title" , "body:content"], + store: ["title" , "body:content"] + } +}); +``` + ## Logical Operators @@ -2560,7 +2590,7 @@ feeds_2018.import(localStorage.getItem("feeds_2018")); feeds_2019.import(localStorage.getItem("feeds_2019")); ``` -#### Disable Serialization +### Disable Serialization Pass a config flag to control serialization: @@ -2574,7 +2604,7 @@ Use the same config accordingly when importing data: index.import(data, {serialize: false}); ``` -#### Separate Exports (Documents) +### Separate Exports (Documents) Pass a config flag to separate index and documents from the export: diff --git a/dist/flexsearch.compact.js b/dist/flexsearch.compact.js index 022dedd..292f514 100644 --- a/dist/flexsearch.compact.js +++ b/dist/flexsearch.compact.js @@ -1,32 +1,32 @@ /* - FlexSearch v0.6.24 + FlexSearch v0.6.30 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence https://github.com/nextapps-de/flexsearch */ -'use strict';(function(x,L,O){let H;(H=O.define)&&H.amd?H([],function(){return L}):(H=O.modules)?H[x.toLowerCase()]=L:"object"===typeof exports?module.exports=L:O[x]=L})("FlexSearch",function(){function x(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:ja++;this.init(a,b);ca(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});ca(this,"length",function(){return this.index.length})}function L(a){const b=D();for(const c in a)if(a.hasOwnProperty(c)){const d= -a[c];F(d)?b[c]=d.slice(0):K(d)?b[c]=L(d):b[c]=d}return b}function O(a,b){const c=a.length,d=P(b),e=[];for(let k=0,f=0;k=f&&(a=a[h-(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 la(a,b){a=a[I];b=b[I];return ab?1:0}function ka(a,b){const c=I.length;for(let d=0;db?1:0}function Q(a,b,c){return a?{page:a, -next:b?""+b:null,result:c}:c}function da(a,b,c,d,e,k,f){let h,g=[];if(!0===c){c="0";var m=""}else m=c&&c.split(":");const n=a.length;if(1f&&(m=0),m=m||0,h=m+b,hn;z--)m=f.substring(n,z), -S(A,p,m,a,u,g,v,y-1)}break;default:if(h=S(A,p,f,a,1,g,v,y-1),r&&1=v)for(h=p._ctx[f]||(p._ctx[f]=D()),f=this.h[f]||(this.h[f]=ea(y-(v||0))),g=t-r,m=t+r+1,0>g&&(g=0),m>l&&(m=l);g=f&&(a=a[k-(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 la(a,b){a=a[K];b=b[K];return ab?1:0}function ka(a,b){const c=K.length;for(let d=0;db?1:0}function Q(a,b,c){return a?{page:a, +next:b?""+b:null,result:c}:c}function da(a,b,c,d,e,h,f){let k,g=[];if(!0===c){c="0";var l=""}else l=c&&c.split(":");const p=a.length;if(1f&&(l=0),l=l||0,k=l+b,kp;z--)l=f.substring(p,z),S(A,n,l,a,v,g,u,y-1)}break;default:if(k=S(A,n,f,a,1,g,u,y-1),q&&1=u)for(k=n._ctx[f]||(n._ctx[f]=B()),f=this.g[f]||(this.g[f]=ea(y-(u||0))),g=t-q,l=t+q+1,0>g&&(g=0),l>m&&(l=m);g= -d&&(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 K(a){var c=G(),b;for(b in a)if(a.hasOwnProperty(b)){var d=a[b];O(d)?c[b]=d.slice(0):Q(d)?c[b]=K(d):c[b]=d}return c}function ba(a,c){for(var b=a.length,d=da(c),e=[],f=0,g=0;f=g&&(a=a[k-(e+.5>>0)],a=a[b]||(a[b]=[]),a[a.length]=d);return e}function ca(a, -c){if(a)for(var b=Object.keys(a),d=0,e=b.length;d -a?1:a?-1:0}function ja(a,c){a=a[X];c=c[X];return ac?1:0}function ka(a,c){for(var b=X.length,d=0;dc?1:0}function fa(a,c,b){return a?{page:a,next:c?""+c:null,result:b}:b}function ua(a,c,b,d,e,f,g){var k=[];if(!0===b){b="0";var h=""}else h=b&&b.split(":");var q=a.length;if(1g&&(h= -0);h=h||0;var S=h+c;S=this.b.length&&(this.w=0),this.b[this.w].postMessage({add:!0,id:a,content:c}),this.f[f]=""+this.w,b&&b(),this;if(!e){if(this.async&&"function"!==typeof importScripts){var g= -this;f=new Promise(function(Y){setTimeout(function(){g.add(a,c,null,d,!0);g=null;Y()})});if(b)f.then(b);else return f;return this}if(b)return this.add(a,c,null,d,!0),b(),this}c=this.encode(c);if(!c.length)return this;b=this.g;e=da(b)?b(c):c.split(this.split);this.filter&&(e=ba(e,this.filter));var k=G();k._ctx=G();for(var h=e.length,q=this.threshold,y=this.depth,v=this.c,A=this.u,u=this.G,r=0;rx;R--)z=D.substring(x,R),I(A,k,z,a,J,C,q,v-1);break;default:if(B=I(A,k,D,a,1,C,q,v-1),y&&1=q)for(B=k._ctx[D]||(k._ctx[D]=G()),D=this.o[D]||(this.o[D]=va(v-(q||0))),C=r-y,z=r+y+1,0>C&&(C=0),z>h&&(z=h);Cf;d--)k=g[d-1],g[d]=k,e[k]=d;g[f]=c;e[c]=f}}}return b};return a}();return p}(function(){var n={},t="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(p,E,K,ba,m){K=t?URL.createObjectURL(new Blob(["("+K.toString()+")()"],{type:"text/javascript"})):p+".es5.js";p+="-"+E;n[p]||(n[p]=[]);n[p][m]=new Worker(K);n[p][m].onmessage=ba;console.log("Register Worker: "+ -p+"@"+m);return n[p][m]}}()),this); +'use strict';function ma(q){var u=0;return function(){return u= +d&&(this.D=this.i),this.D===this.i&&(this.cache&&this.u.set(c,this.A),this.H&&this.H(this.A)));return this}function K(a){var c=G(),b;for(b in a)if(a.hasOwnProperty(b)){var d=a[b];M(d)?c[b]=d.slice(0):P(d)?c[b]=K(d):c[b]=d}return c}function ba(a,c){for(var b=a.length,d=da(c),e=[],f=0,g=0;f=g&&(a=a[h-(e+.5>>0)],a=a[b]||(a[b]=[]),a[a.length]=d);return e}function ca(a, +c){if(a)for(var b=Object.keys(a),d=0,e=b.length;d +a?1:a?-1:0}function ja(a,c){a=a[X];c=c[X];return ac?1:0}function ka(a,c){for(var b=X.length,d=0;dc?1:0}function fa(a,c,b){return a?{page:a,next:c?""+c:null,result:b}:b}function ua(a,c,b,d,e,f,g){var h=[];if(!0===b){b="0";var k=""}else k=b&&b.split(":");var m=a.length;if(1g&&(k= +0);k=k||0;var S=k+c;S=this.b.length&&(this.w=0),this.b[this.w].postMessage({add:!0,id:a,content:c}), +this.f[f]=""+this.w,b&&b(),this;if(!e){if(this.async&&"function"!==typeof importScripts){var g=this;f=new Promise(function(Y){setTimeout(function(){g.add(a,c,null,d,!0);g=null;Y()})});if(b)f.then(b);else return f;return this}if(b)return this.add(a,c,null,d,!0),b(),this}c=this.encode(c);if(!c.length)return this;b=this.g;e=da(b)?b(c):c.split(this.split);this.filter&&(e=ba(e,this.filter));var h=G();h._ctx=G();for(var k=e.length,m=this.threshold,w=this.depth,z=this.c,v=this.s,p=this.G,t=0;ty;R--)A=D.substring(y,R),I(v,h,A,a,J,C,m,z-1);break;default:if(B=I(v,h,D,a,1,C,m,z-1),w&&1=m)for(B=h._ctx[D]||(h._ctx[D]=G()),D=this.o[D]||(this.o[D]=va(z-(m||0))),C=t-w,A=t+w+1,0>C&&(C=0),A>k&&(A=k);Cf;d--)h=g[d-1],g[d]=h,e[h]=d;g[f]=c;e[c]=f}}}return b};return a}();return r}(function(){var q={},u="undefined"!==typeof Blob&&"undefined"!== +typeof URL&&URL.createObjectURL;return function(r,E,K,ba,n){K=u?URL.createObjectURL(new Blob(["("+K.toString()+")()"],{type:"text/javascript"})):r+".es5.js";r+="-"+E;q[r]||(q[r]=[]);q[r][n]=new Worker(K);q[r][n].onmessage=ba;console.log("Register Worker: "+r+"@"+n);return q[r][n]}}()),this); diff --git a/dist/flexsearch.light.js b/dist/flexsearch.light.js index 6173f63..2b772fa 100644 --- a/dist/flexsearch.light.js +++ b/dist/flexsearch.light.js @@ -1,5 +1,5 @@ /* - FlexSearch v0.6.24 + FlexSearch v0.6.30 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence diff --git a/dist/flexsearch.min.js b/dist/flexsearch.min.js index f909f59..aa0d082 100644 --- a/dist/flexsearch.min.js +++ b/dist/flexsearch.min.js @@ -1,42 +1,42 @@ /* - FlexSearch v0.6.24 + FlexSearch v0.6.30 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence https://github.com/nextapps-de/flexsearch */ -'use strict';(function(J,R,w){let L;(L=w.define)&&L.amd?L([],function(){return R}):(L=w.modules)?L[J.toLowerCase()]=R:"object"===typeof exports?module.exports=R:w[J]=R})("FlexSearch",function ma(J){function w(a,c){const b=c?c.id:a&&a.id;this.id=b||0===b?b:na++;this.init(a,c);fa(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].c):Object.keys(this.c)});fa(this,"length",function(){return this.index.length})}function L(a,c,b,d){this.u!==this.g&&(this.o=this.o.concat(b),this.u++, -d&&this.o.length>=d&&(this.u=this.g),this.u===this.g&&(this.cache&&this.l.set(c,this.o),this.F&&this.F(this.o)));return this}function S(a){const c=B();for(const b in a)if(a.hasOwnProperty(b)){const d=a[b];F(d)?c[b]=d.slice(0):H(d)?c[b]=S(d):c[b]=d}return c}function W(a,c){const b=a.length,d=O(c),e=[];for(let f=0,g=0;f=g&&(a=a[k-(e+.5>>0)],a=a[b]||(a[b]=[]), -a[a.length]=d);return e}function ba(a,c){if(a){const b=Object.keys(a);for(let d=0,e=b.length;da?1:a?-1:0}function pa(a,c){a=a[M];c=c[M];return ac?1:0}function oa(a,c){const b=M.length;for(let d=0;dc?1:0}function T(a,c,b){return a?{page:a,next:c?""+c:null,result:b}:b}function ha(a,c,b,d,e,f,g){let k,h=[];if(!0===b){b="0";var m=""}else m=b&&b.split(":");const n=a.length;if(1g&&(m=0),m=m||0,k=m+c,k=d&&(this.u=this.g),this.u===this.g&&(this.cache&&this.j.set(c,this.o),this.F&&this.F(this.o)));return this}function S(a){const c=B();for(const b in a)if(a.hasOwnProperty(b)){const d=a[b];F(d)?c[b]=d.slice(0):G(d)?c[b]=S(d):c[b]=d}return c}function W(a,c){const b=a.length,d=O(c),e=[];for(let g=0,f=0;g=f&&(a=a[h-(e+.5>>0)],a=a[b]||(a[b]=[]), +a[a.length]=d);return e}function ba(a,c){if(a){const b=Object.keys(a);for(let d=0,e=b.length;da?1:a?-1:0}function pa(a,c){a=a[M];c=c[M];return ac?1:0}function oa(a,c){const b=M.length;for(let d=0;dc?1:0}function T(a,c,b){return a?{page:a,next:c?""+c:null,result:b}:b}function ha(a,c,b,d,e,g,f){let h,k=[];if(!0===b){b="0";var l=""}else l=b&&b.split(":");const n=a.length;if(1f&&(l=0),l=l||0,h=l+c,h=this.m.length&&(this.C=0),this.m[this.C].postMessage({add:!0,id:a,content:c}),this.c[f]=""+this.C,b&&b(),this;if(!e){if(this.async&&"function"!==typeof importScripts){let t= -this;f=new Promise(function(v){setTimeout(function(){t.add(a,c,null,d,!0);t=null;v()})});if(b)f.then(b);else return f;return this}if(b)return this.add(a,c,null,d,!0),b(),this}c=this.encode(c);if(!c.length)return this;b=this.f;e=O(b)?b(c):c.split(this.split);this.filter&&(e=W(e,this.filter));const p=B();p._ctx=B();const l=e.length,u=this.threshold,r=this.depth,A=this.b,z=this.j,y=this.D;for(let t=0;tn;x--)m=g.substring(n,x),V(z,p,m,a,v,h,u,A-1)}break;default:if(k=V(z,p,g,a,1,h,u,A-1),r&&1=u)for(k=p._ctx[g]||(p._ctx[g]=B()),g=this.h[g]||(this.h[g]=ia(A-(u||0))),h=t-r,m=t+r+1,0>h&&(h=0),m>l&&(m=l);hg;d--)e=k[d-1],k[d]=e,f[e]=d;k[g]=c;f[c]=g}}}return b};return a}();return w}(function(){const J={},R="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(w,L,S,W,P){S=R?URL.createObjectURL(new Blob(["("+S.toString()+")()"],{type:"text/javascript"})):w+".min.js";w+="-"+L;J[w]|| -(J[w]=[]);J[w][P]=new Worker(S);J[w][P].onmessage=W;return J[w][P]}}()),this); +c=new c(b.options))}}function ta(a,c,b,d){a=K("flexsearch","id"+a,sa,function(g){(g=g.data)&&g.result&&d(g.id,g.content,g.result,g.limit,g.where,g.cursor,g.suggest)},c);const e=ma.toString();b.id=c;a.postMessage({register:e,options:b,id:c});return a}const H={encode:"icase",f:"forward",split:/\W+/,cache:!1,async:!1,g:!1,D:!1,a:!1,b:9,threshold:0,depth:0},ja={memory:{encode:"extra",f:"strict",threshold:0,b:1},speed:{encode:"icase",f:"strict",threshold:1,b:3,depth:2},match:{encode:"extra",f:"full",threshold:1, +b:3},score:{encode:"extra",f:"strict",threshold:1,b:9,depth:4},balance:{encode:"balance",f:"strict",threshold:0,b:3,depth:3},fast:{encode:"icase",f:"strict",threshold:8,b:9,depth:1}},aa=[];let na=0;const ka={},la={};w.create=function(a,c){return new w(a,c)};w.registerMatcher=function(a){for(const c in a)a.hasOwnProperty(c)&&aa.push(r(c),a[c]);return this};w.registerEncoder=function(a,c){U[a]=c.bind(U);return this};w.registerLanguage=function(a,c){ka[a]=c.filter;la[a]=c.stemmer;return this};w.encode= +function(a,c){return U[a](c)};w.prototype.init=function(a,c){this.v=[];if(c){var b=c.preset;a=c}else a||(a=H),b=a.preset;c={};J(a)?(c=ja[a],a={}):b&&(c=ja[b]);if(b=a.worker)if("undefined"===typeof Worker)a.worker=!1,this.m=null;else{var d=parseInt(b,10)||4;this.C=-1;this.u=0;this.o=[];this.F=null;this.m=Array(d);for(var e=0;e=this.m.length&&(this.C=0),this.m[this.C].postMessage({add:!0,id:a, +content:c}),this.c[g]=""+this.C,b&&b(),this;if(!e){if(this.async&&"function"!==typeof importScripts){let t=this;g=new Promise(function(v){setTimeout(function(){t.add(a,c,null,d,!0);t=null;v()})});if(b)g.then(b);else return g;return this}if(b)return this.add(a,c,null,d,!0),b(),this}c=this.encode(c);if(!c.length)return this;b=this.f;e=O(b)?b(c):c.split(this.split);this.filter&&(e=W(e,this.filter));const p=B();p._ctx=B();const m=e.length,u=this.threshold,q=this.depth,A=this.b,z=this.i,y=this.D;for(let t= +0;tn;x--)l=f.substring(n,x),V(z,p,l,a,v,k,u,A-1)}break;default:if(h=V(z,p,f,a,1,k,u,A-1),q&&1=u)for(h=p._ctx[f]||(p._ctx[f]=B()),f=this.h[f]||(this.h[f]=ia(A-(u||0))),k=t-q,l=t+q+1,0>k&&(k=0),l> +m&&(l=m);kf;d--)e=h[d-1],h[d]=e,g[e]=d;h[f]=c;g[c]=f}}}return b};return a}();return w}(function(){const K={},R="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(w,L,S,W,P){S=R?URL.createObjectURL(new Blob(["("+S.toString()+")()"],{type:"text/javascript"})):w+".min.js";w+="-"+L;K[w]||(K[w]=[]);K[w][P]=new Worker(S);K[w][P].onmessage=W;return K[w][P]}}()),this); diff --git a/dist/flexsearch.node.js b/dist/flexsearch.node.js index 5a39dea..7bdc4f4 100644 --- a/dist/flexsearch.node.js +++ b/dist/flexsearch.node.js @@ -1,38 +1,38 @@ /* - FlexSearch v0.6.24 + FlexSearch v0.6.30 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence https://github.com/nextapps-de/flexsearch */ 'use strict';(function(w,N,Q){let K;(K=Q.define)&&K.amd?K([],function(){return N}):(K=Q.modules)?K[w.toLowerCase()]=N:"object"===typeof exports?module.exports=N:Q[w]=N})("FlexSearch",function(){function w(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:ja++;this.init(a,b);ca(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});ca(this,"length",function(){return this.index.length})}function N(a){const b=B();for(const c in a)if(a.hasOwnProperty(c)){const d= -a[c];F(d)?b[c]=d.slice(0):G(d)?b[c]=N(d):b[c]=d}return b}function Q(a,b){const c=a.length,d=O(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 Y(a,b){if(a){const c=Object.keys(a);for(let d=0,e=c.length;da?1:a?-1:0}function la(a,b){a=a[L];b=b[L];return ab?1:0}function ka(a,b){const c=L.length;for(let d=0;db?1:0}function R(a, -b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function da(a,b,c,d,e,g,f){let k,h=[];if(!0===c){c="0";var m=""}else m=c&&c.split(":");const n=a.length;if(1f&&(m=0),m=m||0,k=m+b,kn;x--)m=f.substring(n,x),T(z,p,m,a,v,h,u,A-1)}break;default:if(k=T(z,p,f,a,1,h,u,A-1),r&&1=u)for(k=p._ctx[f]||(p._ctx[f]=B()),f=this.g[f]||(this.g[f]=ea(A-(u||0))),h=t-r,m=t+r+1,0>h&&(h=0),m>l&&(m=l);hf;d--)e=k[d-1],k[d]=e,g[e]=d;k[f]=b;g[b]=f}}}return c};return a}();return w}(!1),this); +a[c];F(d)?b[c]=d.slice(0):G(d)?b[c]=N(d):b[c]=d}return b}function Q(a,b){const c=a.length,d=O(b),e=[];for(let g=0,f=0;g=f&&(a=a[h-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e}function Y(a,b){if(a){const c=Object.keys(a);for(let d=0,e=c.length;da?1:a?-1:0}function la(a,b){a=a[L];b=b[L];return ab?1:0}function ka(a,b){const c=L.length;for(let d=0;db?1:0}function R(a, +b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function da(a,b,c,d,e,g,f){let h,k=[];if(!0===c){c="0";var l=""}else l=c&&c.split(":");const p=a.length;if(1f&&(l=0),l=l||0,h=l+b,hp;x--)l=f.substring(p,x),T(z,n,l,a,v,k,u,A-1)}break;default:if(h=T(z,n,f,a,1,k,u,A-1),q&&1=u)for(h= +n._ctx[f]||(n._ctx[f]=B()),f=this.g[f]||(this.g[f]=ea(A-(u||0))),k=t-q,l=t+q+1,0>k&&(k=0),l>m&&(l=m);kf;d--)e=h[d-1],h[d]=e,g[e]=d;h[f]=b;g[b]=f}}}return c};return a}();return w}(!1),this); diff --git a/dist/flexsearch.pre.js b/dist/flexsearch.pre.js index 2e32aba..0692f17 100644 --- a/dist/flexsearch.pre.js +++ b/dist/flexsearch.pre.js @@ -1,5 +1,5 @@ /* - FlexSearch v0.6.24 + FlexSearch v0.6.30 Copyright 2019 Nextapps GmbH Author: Thomas Wilkerling Released under the Apache 2.0 Licence @@ -36,22 +36,22 @@ function Q(a, b) { const c = a.length, d = O(b), e = []; for (let g = 0, f = 0; g < c; g++) { - const k = a[g]; - if (d && b(k) || !d && !b[k]) { - e[f++] = k; + const h = a[g]; + if (d && b(h) || !d && !b[h]) { + e[f++] = h; } } return e; } - function K(a, b, c, d, e, g, f, k, h, m) { - c = da(c, f ? 0 : e, k, g, b, h, m); - let n; - k && (k = c.page, n = c.next, c = c.result); + function K(a, b, c, d, e, g, f, h, k, l) { + c = da(c, f ? 0 : e, h, g, b, k, l); + let p; + h && (h = c.page, p = c.next, c = c.result); if (f) { b = this.where(f, null, e, c); } else { b = c; - c = this.h; + c = this.i; e = b.length; g = Array(e); for (f = 0; f < e; f++) { @@ -61,14 +61,14 @@ } c = b; d && (O(d) || (L = d.split(":"), 1 < L.length ? d = ka : (L = L[0], d = la)), c.sort(d)); - c = R(k, n, c); + c = R(h, p, c); this.cache && this.j.set(a, c); return c; } function ca(a, b, c) { Object.defineProperty(a, b, {get:c}); } - function q(a) { + function r(a) { return new RegExp(a, "g"); } function P(a, b) { @@ -77,13 +77,13 @@ } return a; } - function T(a, b, c, d, e, g, f, k) { + function T(a, b, c, d, e, g, f, h) { if (b[c]) { return b[c]; } - e = e ? (k - (f || k / 1.5)) * g + (f || k / 1.5) * e : g; + e = e ? (h - (f || h / 1.5)) * g + (f || h / 1.5) * e : g; b[c] = e; - e >= f && (a = a[k - (e + 0.5 >> 0)], a = a[c] || (a[c] = []), a[a.length] = d); + e >= f && (a = a[h - (e + 0.5 >> 0)], a = a[c] || (a[c] = []), a[a.length] = d); return e; } function Y(a, b) { @@ -92,12 +92,12 @@ for (let d = 0, e = c.length; d < e; d++) { const g = c[d], f = a[g]; if (f) { - for (let k = 0, h = f.length; k < h; k++) { - if (f[k] === b) { - 1 === h ? delete a[g] : f.splice(k, 1); + for (let h = 0, k = f.length; h < k; h++) { + if (f[h] === b) { + 1 === k ? delete a[g] : f.splice(h, 1); break; } else { - G(f[k]) && Y(f[k], b); + G(f[h]) && Y(f[h], b); } } } @@ -143,45 +143,45 @@ return a ? {page:a, next:b ? "" + b : null, result:c} : c; } function da(a, b, c, d, e, g, f) { - let k, h = []; + let h, k = []; if (!0 === c) { c = "0"; - var m = ""; + var l = ""; } else { - m = c && c.split(":"); + l = c && c.split(":"); } - const n = a.length; - if (1 < n) { + const p = a.length; + if (1 < p) { const y = B(), t = []; let v, x; - var p = 0, l; + var n = 0, m; let H; var u = !0; let D, E = 0, M, aa, U, ba; - m && (2 === m.length ? (U = m, m = !1) : m = ba = parseInt(m[0], 10)); + l && (2 === l.length ? (U = l, l = !1) : l = ba = parseInt(l[0], 10)); if (f) { - for (v = B(); p < n; p++) { - if ("not" === e[p]) { - for (x = a[p], H = x.length, l = 0; l < H; l++) { - v["@" + x[l]] = 1; + for (v = B(); n < p; n++) { + if ("not" === e[n]) { + for (x = a[n], H = x.length, m = 0; m < H; m++) { + v["@" + x[m]] = 1; } } else { - aa = p + 1; + aa = n + 1; } } if (C(aa)) { - return R(c, k, h); + return R(c, h, k); } - p = 0; + n = 0; } else { - M = J(e) && e; + M = I(e) && e; } let V; - for (; p < n; p++) { - const na = p === (aa || n) - 1; - if (!M || !p) { - if ((l = M || e && e[p]) && "and" !== l) { - if ("or" === l) { + for (; n < p; n++) { + const na = n === (aa || p) - 1; + if (!M || !n) { + if ((m = M || e && e[n]) && "and" !== m) { + if ("or" === m) { V = !1; } else { continue; @@ -190,15 +190,15 @@ V = g = !0; } } - x = a[p]; + x = a[n]; if (H = x.length) { if (u) { if (D) { - var r = D.length; - for (l = 0; l < r; l++) { - u = D[l]; + var q = D.length; + for (m = 0; m < q; m++) { + u = D[m]; var A = "@" + u; - f && v[A] || (y[A] = 1, g || (h[E++] = u)); + f && v[A] || (y[A] = 1, g || (k[E++] = u)); } D = null; u = !1; @@ -208,24 +208,24 @@ } } A = !1; - for (l = 0; l < H; l++) { - r = x[l]; - var z = "@" + r; - const W = g ? y[z] || 0 : p; + for (m = 0; m < H; m++) { + q = x[m]; + var z = "@" + q; + const W = g ? y[z] || 0 : n; if (!(!W && !d || f && v[z] || !g && y[z])) { - if (W === p) { + if (W === n) { if (na) { if (!ba || --ba < E) { - if (h[E++] = r, b && E === b) { - return R(c, E + (m || 0), h); + if (k[E++] = q, b && E === b) { + return R(c, E + (l || 0), k); } } } else { - y[z] = p + 1; + y[z] = n + 1; } A = !0; } else { - d && (z = t[W] || (t[W] = []), z[z.length] = r); + d && (z = t[W] || (t[W] = []), z[z.length] = q); } } } @@ -234,40 +234,40 @@ } } else { if (V && !d) { - return R(c, k, x); + return R(c, h, x); } } } if (D) { - if (p = D.length, f) { - for (l = m ? parseInt(m, 10) : 0; l < p; l++) { - a = D[l], v["@" + a] || (h[E++] = a); + if (n = D.length, f) { + for (m = l ? parseInt(l, 10) : 0; m < n; m++) { + a = D[m], v["@" + a] || (k[E++] = a); } } else { - h = D; + k = D; } } if (d) { - for (E = h.length, U ? (p = parseInt(U[0], 10) + 1, l = parseInt(U[1], 10) + 1) : (p = t.length, l = 0); p--;) { - if (r = t[p]) { - for (H = r.length; l < H; l++) { - if (d = r[l], !f || !v["@" + d]) { - if (h[E++] = d, b && E === b) { - return R(c, p + ":" + l, h); + for (E = k.length, U ? (n = parseInt(U[0], 10) + 1, m = parseInt(U[1], 10) + 1) : (n = t.length, m = 0); n--;) { + if (q = t[n]) { + for (H = q.length; m < H; m++) { + if (d = q[m], !f || !v["@" + d]) { + if (k[E++] = d, b && E === b) { + return R(c, n + ":" + m, k); } } } - l = 0; + m = 0; } } } } else { - !n || e && "not" === e[0] || (h = a[0], m && (m = parseInt(m[0], 10))); + !p || e && "not" === e[0] || (k = a[0], l && (l = parseInt(l[0], 10))); } - b && (f = h.length, m && m > f && (m = 0), m = m || 0, k = m + b, k < f ? h = h.slice(m, k) : (k = 0, m && (h = h.slice(m)))); - return R(c, k, h); + b && (f = k.length, l && l > f && (l = 0), l = l || 0, h = l + b, h < f ? k = k.slice(l, h) : (h = 0, l && (k = k.slice(l)))); + return R(c, h, k); } - function J(a) { + function I(a) { return "string" === typeof a; } function F(a) { @@ -292,7 +292,7 @@ function B() { return Object.create(null); } - const I = {encode:"icase", c:"forward", split:/\W+/, cache:!1, async:!1, C:!1, v:!1, a:!1, b:9, threshold:0, depth:0}, fa = {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}}, X = []; + const J = {encode:"icase", c:"forward", split:/\W+/, cache:!1, async:!1, C:!1, v:!1, a:!1, b:9, threshold:0, depth:0}, fa = {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}}, X = []; let ja = 0; const ha = {}, ia = {}; w.create = function(a, b) { @@ -300,7 +300,7 @@ }; w.registerMatcher = function(a) { for (const b in a) { - a.hasOwnProperty(b) && X.push(q(b), a[b]); + a.hasOwnProperty(b) && X.push(r(b), a[b]); } return this; }; @@ -322,22 +322,22 @@ var c = b.preset; a = b; } else { - a || (a = I), c = a.preset; + a || (a = J), c = a.preset; } b = {}; - J(a) ? (b = fa[a], a = {}) : c && (b = fa[c]); - this.c = a.tokenize || b.c || this.c || I.c; - this.split = C(c = a.split) ? this.split || I.split : J(c) ? q(c) : c; - this.v = a.rtl || this.v || I.v; - this.async = "undefined" === typeof Promise || C(c = a.async) ? this.async || I.async : c; - this.threshold = C(c = a.threshold) ? b.threshold || this.threshold || I.threshold : c; - this.b = C(c = a.resolution) ? c = b.b || this.b || I.b : c; + I(a) ? (b = fa[a], a = {}) : c && (b = fa[c]); + this.c = a.tokenize || b.c || this.c || J.c; + this.split = C(c = a.split) ? this.split || J.split : I(c) ? r(c) : c; + this.v = a.rtl || this.v || J.v; + this.async = "undefined" === typeof Promise || C(c = a.async) ? this.async || J.async : c; + this.threshold = C(c = a.threshold) ? b.threshold || this.threshold || J.threshold : c; + this.b = C(c = a.resolution) ? c = b.b || this.b || J.b : c; c <= this.threshold && (this.b = this.threshold + 1); - this.depth = "strict" !== this.c || C(c = a.depth) ? b.depth || this.depth || I.depth : c; - this.o = (c = C(c = a.encode) ? b.encode || I.encode : c) && S[c] && S[c].bind(S) || (O(c) ? c : this.o || !1); + this.depth = "strict" !== this.c || C(c = a.depth) ? b.depth || this.depth || J.depth : c; + this.o = (c = C(c = a.encode) ? b.encode || J.encode : c) && S[c] && S[c].bind(S) || (O(c) ? c : this.o || !1); (c = a.matcher) && this.addMatcher(c); if (c = (b = a.lang) || a.filter) { - J(c) && (c = ha[c]); + I(c) && (c = ha[c]); if (F(c)) { var d = this.o, e = B(); for (var g = 0; g < c.length; g++) { @@ -349,37 +349,53 @@ this.filter = c; } if (c = b || a.stemmer) { - var k; - b = J(c) ? ia[c] : c; + var h; + b = I(c) ? ia[c] : c; d = this.o; e = []; - for (k in b) { - b.hasOwnProperty(k) && (g = d ? d(k) : k, e.push(q(g + "($|\\W)"), d ? d(b[k]) : b[k])); + for (h in b) { + b.hasOwnProperty(h) && (g = d ? d(h) : h, e.push(r(g + "($|\\W)"), d ? d(b[h]) : b[h])); } - this.stemmer = k = e; + this.stemmer = h = e; } - this.a = e = (c = a.doc) ? N(c) : this.a || I.a; - this.i = ea(this.b - (this.threshold || 0)); + this.a = e = (c = a.doc) ? N(c) : this.a || J.a; + this.h = ea(this.b - (this.threshold || 0)); this.g = B(); this.f = B(); if (e) { - this.h = B(); + this.i = B(); a.doc = null; - k = e.index = {}; + h = e.index = {}; b = e.keys = []; d = e.field; g = e.tag; + f = e.store; F(e.id) || (e.id = e.id.split(":")); + if (f) { + var k = B(); + if (I(f)) { + k[f] = 1; + } else { + if (F(f)) { + for (let l = 0; l < f.length; l++) { + k[f[l]] = 1; + } + } else { + G(f) && (k = f); + } + } + e.store = k; + } if (g) { this.w = B(); f = B(); if (d) { - if (J(d)) { + if (I(d)) { f[d] = a; } else { if (F(d)) { - for (let h = 0; h < d.length; h++) { - f[d[h]] = a; + for (k = 0; k < d.length; k++) { + f[d[k]] = a; } } else { G(d) && (f = d); @@ -394,15 +410,16 @@ d = f; } if (d) { - let h; - F(d) || (G(d) ? (h = d, e.field = d = Object.keys(d)) : e.field = d = [d]); + let l; + F(d) || (G(d) ? (l = d, e.field = d = Object.keys(d)) : e.field = d = [d]); for (e = 0; e < d.length; e++) { - g = d[e], F(g) || (h && (a = h[g]), b[e] = g, d[e] = g.split(":")), k[g] = new w(a), k[g].h = this.h; + g = d[e], F(g) || (l && (a = l[g]), b[e] = g, d[e] = g.split(":")), h[g] = new w(a); } } + a.doc = c; } this.u = !0; - this.j = (this.cache = c = C(c = a.cache) ? this.cache || I.cache : c) ? new oa(c) : !1; + this.j = (this.cache = c = C(c = a.cache) ? this.cache || J.cache : c) ? new oa(c) : !1; return this; }; w.prototype.encode = function(a) { @@ -412,7 +429,7 @@ w.prototype.addMatcher = function(a) { const b = this.m; for (const c in a) { - a.hasOwnProperty(c) && b.push(q(c), a[c]); + a.hasOwnProperty(c) && b.push(r(c), a[c]); } return this; }; @@ -420,7 +437,7 @@ if (this.a && G(a)) { return this.s("add", a, b); } - if (b && J(b) && (a || 0 === a)) { + if (b && I(b) && (a || 0 === a)) { var g = "@" + a; if (this.f[g] && !d) { return this.update(a, b); @@ -453,37 +470,37 @@ c = this.c; e = O(c) ? c(b) : b.split(this.split); this.filter && (e = Q(e, this.filter)); - const p = B(); - p._ctx = B(); - const l = e.length, u = this.threshold, r = this.depth, A = this.b, z = this.i, y = this.v; - for (let t = 0; t < l; t++) { + const n = B(); + n._ctx = B(); + const m = e.length, u = this.threshold, q = this.depth, A = this.b, z = this.h, y = this.v; + for (let t = 0; t < m; t++) { var f = e[t]; if (f) { - var k = f.length, h = (y ? t + 1 : l - t) / l, m = ""; + var h = f.length, k = (y ? t + 1 : m - t) / m, l = ""; switch(c) { case "reverse": case "both": - for (var n = k; --n;) { - m = f[n] + m, T(z, p, m, a, y ? 1 : (k - n) / k, h, u, A - 1); + for (var p = h; --p;) { + l = f[p] + l, T(z, n, l, a, y ? 1 : (h - p) / h, k, u, A - 1); } - m = ""; + l = ""; case "forward": - for (n = 0; n < k; n++) { - m += f[n], T(z, p, m, a, y ? (n + 1) / k : 1, h, u, A - 1); + for (p = 0; p < h; p++) { + l += f[p], T(z, n, l, a, y ? (p + 1) / h : 1, k, u, A - 1); } break; case "full": - for (n = 0; n < k; n++) { - const v = (y ? n + 1 : k - n) / k; - for (let x = k; x > n; x--) { - m = f.substring(n, x), T(z, p, m, a, v, h, u, A - 1); + for (p = 0; p < h; p++) { + const v = (y ? p + 1 : h - p) / h; + for (let x = h; x > p; x--) { + l = f.substring(p, x), T(z, n, l, a, v, k, u, A - 1); } } break; default: - if (k = T(z, p, f, a, 1, h, u, A - 1), r && 1 < l && k >= u) { - for (k = p._ctx[f] || (p._ctx[f] = B()), f = this.g[f] || (this.g[f] = ea(A - (u || 0))), h = t - r, m = t + r + 1, 0 > h && (h = 0), m > l && (m = l); h < m; h++) { - h !== t && T(f, k, e[h], a, 0, A - (h < t ? t - h : h - t), u, A - 1); + if (h = T(z, n, f, a, 1, k, u, A - 1), q && 1 < m && h >= u) { + for (h = n._ctx[f] || (n._ctx[f] = B()), f = this.g[f] || (this.g[f] = ea(A - (u || 0))), k = t - q, l = t + q + 1, 0 > k && (k = 0), l > m && (l = m); k < l; k++) { + k !== t && T(f, h, e[k], a, 0, A - (k < t ? t - k : k - t), u, A - 1); } } } @@ -496,54 +513,68 @@ }; w.prototype.s = function(a, b, c) { if (F(b)) { - for (let h = 0, m = b.length; h < m; h++) { - if (h === m - 1) { - return this.s(a, b[h], c); + var d = b.length; + if (d--) { + for (var e = 0; e < d; e++) { + this.s(a, b[e]); } - this.s(a, b[h]); + return this.s(a, b[d], c); } } else { - const h = this.a.index, m = this.a.keys; - var d = this.a.tag, e = this.a.id; - let n; - let p; - for (var g = 0; g < e.length; g++) { - n = (n || b)[e[g]]; + var g = this.a.index, f = this.a.keys, h = this.a.tag; + e = this.a.store; + var k; + var l = this.a.id; + d = b; + for (var p = 0; p < l.length; p++) { + d = d[l[p]]; } - if (d) { - for (e = 0; e < d.length; e++) { - var f = d[e]; - var k = f.split(":"); - for (g = 0; g < k.length; g++) { - p = (p || b)[k[g]]; - } - p = "@" + p; + if ("remove" === a && (delete this.i[d], l = f.length, l--)) { + for (b = 0; b < l; b++) { + g[f[b]].remove(d); } - k = this.w[f]; - k = k[p] || (k[p] = []); + return g[f[l]].remove(d, c); } - if ("remove" === a) { - delete this.h[n]; - for (let l = 0, u = m.length; l < u; l++) { - if (l === u - 1) { - return h[m[l]].remove(n, c), this; + if (h) { + for (k = 0; k < h.length; k++) { + var n = h[k]; + var m = b; + l = n.split(":"); + for (p = 0; p < l.length; p++) { + m = m[l[p]]; } - h[m[l]].remove(n); + m = "@" + m; } + k = this.w[n]; + k = k[m] || (k[m] = []); + } + l = this.a.field; + for (let u = 0, q = l.length; u < q; u++) { + n = l[u]; + h = b; + for (m = 0; m < n.length; m++) { + h = h[n[m]]; + } + n = g[f[u]]; + m = "add" === a ? n.add : n.update; + u === q - 1 ? m.call(n, d, h, c) : m.call(n, d, h); + } + if (e) { + c = Object.keys(e); + a = B(); + for (g = 0; g < c.length; g++) { + if (f = c[g], e[f]) { + f = f.split(":"); + let u, q; + for (l = 0; l < f.length; l++) { + h = f[l], q = (q || b)[h], u = (u || a)[h] = q; + } + } + } + b = a; } - e = this.a.field; k && (k[k.length] = b); - this.h[n] = b; - for (let l = 0, u = e.length; l < u; l++) { - d = e[l]; - let r; - for (f = 0; f < d.length; f++) { - r = (r || b)[d[f]]; - } - d = h[m[l]]; - f = "add" === a ? d.add : d.update; - l === u - 1 ? f.call(d, n, r, c) : f.call(d, n, r); - } + this.i[d] = b; } return this; }; @@ -551,7 +582,7 @@ if (this.a && G(a)) { return this.s("update", a, b); } - this.f["@" + a] && J(b) && (this.remove(a), this.add(a, b, c, !0)); + this.f["@" + a] && I(b) && (this.remove(a), this.add(a, b, c, !0)); return this; }; w.prototype.remove = function(a, b, c) { @@ -582,7 +613,7 @@ } } for (b = 0; b < this.b - (this.threshold || 0); b++) { - Y(this.i[b], a); + Y(this.h[b], a); } this.depth && Y(this.g, a); delete this.f[d]; @@ -606,67 +637,67 @@ b && O(b) ? (c = b, b = 1000) : b || 0 === b || (b = 1000); } let g = [], f = a; - let k, h, m; + let h, k, l; if (G(a) && !F(a)) { c || (c = a.callback) && (f.callback = null); - h = a.sort; - k = a.page; + k = a.sort; + h = a.page; b = a.limit; - var n = a.threshold; - m = a.suggest; + var p = a.threshold; + l = a.suggest; a = a.query; } if (this.a) { - n = this.a.index; + p = this.a.index; const y = f.where; - var p = f.bool || "or", l = f.field; - let t = p; + var n = f.bool || "or", m = f.field; + let t = n; let v, x; - if (l) { - F(l) || (l = [l]); + if (m) { + F(m) || (m = [m]); } else { if (F(f)) { var u = f; - l = []; + m = []; t = []; - for (var r = 0; r < f.length; r++) { - d = f[r], e = d.bool || p, l[r] = d.field, t[r] = e, "not" === e ? v = !0 : "and" === e && (x = !0); + for (var q = 0; q < f.length; q++) { + d = f[q], e = d.bool || n, m[q] = d.field, t[q] = e, "not" === e ? v = !0 : "and" === e && (x = !0); } } else { - l = this.a.keys; + m = this.a.keys; } } - p = l.length; - for (r = 0; r < p; r++) { - u && (f = u[r]), k && !J(f) && (f.page = null, f.limit = 0), g[r] = n[l[r]].search(f, 0); + n = m.length; + for (q = 0; q < n; q++) { + u && (f = u[q]), h && !I(f) && (f.page = null, f.limit = 0), g[q] = p[m[q]].search(f, 0); } if (c) { - return c(K.call(this, a, t, g, h, b, m, y, k, x, v)); + return c(K.call(this, a, t, g, k, b, l, y, h, x, v)); } if (this.async) { const H = this; return new Promise(function(D) { Promise.all(g).then(function(E) { - D(K.call(H, a, t, E, h, b, m, y, k, x, v)); + D(K.call(H, a, t, E, k, b, l, y, h, x, v)); }); }); } - return K.call(this, a, t, g, h, b, m, y, k, x, v); + return K.call(this, a, t, g, k, b, l, y, h, x, v); } - n || (n = this.threshold || 0); + p || (p = this.threshold || 0); if (!d) { if (this.async && "function" !== typeof importScripts) { let y = this; - n = new Promise(function(t) { + p = new Promise(function(t) { setTimeout(function() { t(y.search(f, b, null, !0)); y = null; }); }); if (c) { - n.then(c); + p.then(c); } else { - return n; + return p; } return this; } @@ -674,7 +705,7 @@ return c(this.search(f, b, null, !0)), this; } } - if (!a || !J(a)) { + if (!a || !I(a)) { return g; } f = a; @@ -699,26 +730,26 @@ e = []; const A = B(); let z = 0; - 1 < u && (this.depth && "strict" === this.c ? p = !0 : c.sort(ma)); - if (!p || (r = this.g)) { + 1 < u && (this.depth && "strict" === this.c ? n = !0 : c.sort(ma)); + if (!n || (q = this.g)) { const y = this.b; for (; z < u; z++) { let t = c[z]; if (t) { - if (p) { - if (!l) { - if (r[t]) { - l = t, A[t] = 1; + if (n) { + if (!m) { + if (q[t]) { + m = t, A[t] = 1; } else { - if (!m) { + if (!l) { return g; } } } - if (m && z === u - 1 && !e.length) { - p = !1, t = l || t, A[t] = 0; + if (l && z === u - 1 && !e.length) { + n = !1, t = m || t, A[t] = 0; } else { - if (!l) { + if (!m) { continue; } } @@ -726,19 +757,19 @@ if (!A[t]) { const v = []; let x = !1, H = 0; - const D = p ? r[l] : this.i; + const D = n ? q[m] : this.h; if (D) { let E; - for (let M = 0; M < y - n; M++) { + for (let M = 0; M < y - p; M++) { if (E = D[M] && D[M][t]) { v[H++] = E, x = !0; } } } if (x) { - l = t, e[e.length] = 1 < H ? v.concat.apply([], v) : v[0]; + m = t, e[e.length] = 1 < H ? v.concat.apply([], v) : v[0]; } else { - if (!m) { + if (!l) { d = !1; break; } @@ -750,7 +781,7 @@ } else { d = !1; } - d && (g = da(e, b, k, m)); + d && (g = da(e, b, h, l)); this.cache && this.j.set(a, g); return g; }; @@ -758,43 +789,43 @@ return this.where(a, b, 1)[0] || null; }; w.prototype.where = function(a, b, c, d) { - const e = this.h, g = []; + const e = this.i, g = []; let f = 0; - let k; - var h; - let m; + let h; + var k; + let l; if (G(a)) { c || (c = b); - var n = Object.keys(a); - var p = n.length; - k = !1; - if (1 === p && "id" === n[0]) { + var p = Object.keys(a); + var n = p.length; + h = !1; + if (1 === n && "id" === p[0]) { return [e[a.id]]; } - if ((h = this.B) && !d) { - for (var l = 0; l < h.length; l++) { - var u = h[l], r = a[u]; - if (!C(r)) { - m = this.w[u]["@" + r]; - if (0 === --p) { - return m; + if ((k = this.B) && !d) { + for (var m = 0; m < k.length; m++) { + var u = k[m], q = a[u]; + if (!C(q)) { + l = this.w[u]["@" + q]; + if (0 === --n) { + return l; } - n.splice(n.indexOf(u), 1); + p.splice(p.indexOf(u), 1); delete a[u]; break; } } } - h = Array(p); - for (l = 0; l < p; l++) { - h[l] = n[l].split(":"); + k = Array(n); + for (m = 0; m < n; m++) { + k[m] = p[m].split(":"); } } else { if (O(a)) { b = d || Object.keys(e); c = b.length; - for (n = 0; n < c; n++) { - p = e[b[n]], a(p) && (g[f++] = p); + for (p = 0; p < c; p++) { + n = e[b[p]], a(n) && (g[f++] = n); } return g; } @@ -804,20 +835,20 @@ if ("id" === a) { return [e[b]]; } - n = [a]; - p = 1; - h = [a.split(":")]; - k = !0; + p = [a]; + n = 1; + k = [a.split(":")]; + h = !0; } - d = m || d || Object.keys(e); - l = d.length; - for (u = 0; u < l; u++) { - r = m ? d[u] : e[d[u]]; + d = l || d || Object.keys(e); + m = d.length; + for (u = 0; u < m; u++) { + q = l ? d[u] : e[d[u]]; let A = !0; - for (let z = 0; z < p; z++) { - k || (b = a[n[z]]); - const y = h[z], t = y.length; - let v = r; + for (let z = 0; z < n; z++) { + h || (b = a[p[z]]); + const y = k[z], t = y.length; + let v = q; if (1 < t) { for (let x = 0; x < t; x++) { v = v[y[x]]; @@ -830,7 +861,7 @@ break; } } - if (A && (g[f++] = r, c && f === c)) { + if (A && (g[f++] = q, c && f === c)) { break; } } @@ -844,13 +875,13 @@ }; w.prototype.destroy = function() { this.cache && (this.j.clear(), this.j = null); - this.i = this.g = this.f = null; + this.h = this.g = this.f = null; if (this.a) { const a = this.a.keys; for (let b = 0; b < a.length; b++) { this.a.index[a[b]].destroy(); } - this.a = this.h = null; + this.a = this.i = null; } return this; }; @@ -864,12 +895,12 @@ if (c) { for (c = this.a.keys; e < c.length; e++) { const g = this.a.index[c[e]]; - a[e] = [g.i, g.g, Object.keys(g.f)]; + a[e] = [g.h, g.g, Object.keys(g.f)]; } } - d && (a[e] = this.h); + d && (a[e] = this.i); } else { - a = [this.i, this.g, Object.keys(this.f)]; + a = [this.h, this.g, Object.keys(this.f)]; } b && (a = JSON.stringify(a)); return a; @@ -888,35 +919,37 @@ c[g[e]] = 1; } for (e = 0; e < f; e++) { - g = this.a.index[b[e]], g.i = a[e][0], g.g = a[e][1], g.f = c; + g = this.a.index[b[e]]; + const h = a[e]; + h && (g.h = h[0], g.g = h[1], g.f = c); } } - d && (this.h = G(d) ? d : a[e]); + d && (this.i = G(d) ? d : a[e]); } else { d = a[2]; for (e = 0; e < d.length; e++) { c[d[e]] = 1; } - this.i = a[0]; + this.h = a[0]; this.g = a[1]; this.f = c; } }; const pa = function() { - const a = q("\\s+"), b = q("[^a-z0-9 ]"), c = [q("[-/]"), " ", b, "", a, " "]; + const a = r("\\s+"), b = r("[^a-z0-9 ]"), c = [r("[-/]"), " ", b, "", a, " "]; return function(d) { return Z(P(d.toLowerCase(), c)); }; }(), S = {icase:function(a) { return a.toLowerCase(); }, simple:function() { - const a = q("\\s+"), b = q("[^a-z0-9 ]"), c = q("[-/]"), d = q("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"), e = q("[\u00e8\u00e9\u00ea\u00eb]"), g = q("[\u00ec\u00ed\u00ee\u00ef]"), f = q("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"), k = q("[\u00f9\u00fa\u00fb\u00fc\u0171]"), h = q("[\u00fd\u0177\u00ff]"), m = q("\u00f1"), n = q("[\u00e7c]"), p = q("\u00df"), l = q(" & "), u = [d, "a", e, "e", g, "i", f, "o", k, "u", h, "y", m, "n", n, "k", p, "s", l, " and ", c, " ", b, "", a, " "]; - return function(r) { - r = P(r.toLowerCase(), u); - return " " === r ? "" : r; + const a = r("\\s+"), b = r("[^a-z0-9 ]"), c = r("[-/]"), d = r("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"), e = r("[\u00e8\u00e9\u00ea\u00eb]"), g = r("[\u00ec\u00ed\u00ee\u00ef]"), f = r("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"), h = r("[\u00f9\u00fa\u00fb\u00fc\u0171]"), k = r("[\u00fd\u0177\u00ff]"), l = r("\u00f1"), p = r("[\u00e7c]"), n = r("\u00df"), m = r(" & "), u = [d, "a", e, "e", g, "i", f, "o", h, "u", k, "y", l, "n", p, "k", n, "s", m, " and ", c, " ", b, "", a, " "]; + return function(q) { + q = P(q.toLowerCase(), u); + return " " === q ? "" : q; }; }(), advanced:function() { - const a = q("ae"), b = q("ai"), c = q("ay"), d = q("ey"), e = q("oe"), g = q("ue"), f = q("ie"), k = q("sz"), h = q("zs"), m = q("ck"), n = q("cc"), p = q("sh"), l = q("th"), u = q("dt"), r = q("ph"), A = q("pf"), z = q("ou"), y = q("uo"), t = [a, "a", b, "ei", c, "ei", d, "ei", e, "o", g, "u", f, "i", k, "s", h, "s", p, "s", m, "k", n, "k", l, "t", u, "t", r, "f", A, "f", z, "o", y, "u"]; + const a = r("ae"), b = r("ai"), c = r("ay"), d = r("ey"), e = r("oe"), g = r("ue"), f = r("ie"), h = r("sz"), k = r("zs"), l = r("ck"), p = r("cc"), n = r("sh"), m = r("th"), u = r("dt"), q = r("ph"), A = r("pf"), z = r("ou"), y = r("uo"), t = [a, "a", b, "ei", c, "ei", d, "ei", e, "o", g, "u", f, "i", h, "s", k, "s", n, "s", l, "k", p, "k", m, "t", u, "t", q, "f", A, "f", z, "o", y, "u"]; return function(v, x) { if (!v) { return v; @@ -927,22 +960,22 @@ return v; }; }(), extra:function() { - const a = q("p"), b = q("z"), c = q("[cgq]"), d = q("n"), e = q("d"), g = q("[vw]"), f = q("[aeiouy]"), k = [a, "b", b, "s", c, "k", d, "m", e, "t", g, "f", f, ""]; - return function(h) { - if (!h) { - return h; + const a = r("p"), b = r("z"), c = r("[cgq]"), d = r("n"), e = r("d"), g = r("[vw]"), f = r("[aeiouy]"), h = [a, "b", b, "s", c, "k", d, "m", e, "t", g, "f", f, ""]; + return function(k) { + if (!k) { + return k; } - h = this.advanced(h, !0); - if (1 < h.length) { - h = h.split(" "); - for (let m = 0; m < h.length; m++) { - const n = h[m]; - 1 < n.length && (h[m] = n[0] + P(n.substring(1), k)); + k = this.advanced(k, !0); + if (1 < k.length) { + k = k.split(" "); + for (let l = 0; l < k.length; l++) { + const p = k[l]; + 1 < p.length && (k[l] = p[0] + P(p.substring(1), h)); } - h = h.join(" "); - h = Z(h); + k = k.join(" "); + k = Z(k); } - return h; + return k; }; }(), balance:pa}, oa = function() { function a(b) { @@ -981,15 +1014,15 @@ const g = this.index; let f = g[b]; if (0 < f) { - const k = this.l; - for (var e = f; this.count[k[--f]] <= d && -1 !== f;) { + const h = this.l; + for (var e = f; this.count[h[--f]] <= d && -1 !== f;) { } f++; if (f !== e) { for (d = e; d > f; d--) { - e = k[d - 1], k[d] = e, g[e] = d; + e = h[d - 1], h[d] = e, g[e] = d; } - k[f] = b; + h[f] = b; g[b] = f; } } diff --git a/flexsearch.js b/flexsearch.js index f323299..7bbdb46 100644 --- a/flexsearch.js +++ b/flexsearch.js @@ -1,5 +1,5 @@ /**! - * @preserve FlexSearch v0.6.24 + * @preserve FlexSearch v0.6.30 * Copyright 2019 Nextapps GmbH * Author: Thomas Wilkerling * Released under the Apache 2.0 Licence @@ -579,7 +579,7 @@ /** @private */ this._ids = create_object(); - if(doc){ + if(SUPPORT_DOCUMENT && doc){ this._doc = create_object(); @@ -590,12 +590,36 @@ let field = doc["field"]; let tag = doc["tag"]; + let store = doc["store"]; if(!is_array(doc["id"])){ doc["id"] = doc["id"].split(":"); } + if(store){ + + let store_custom = create_object(); + + if(is_string(store)){ + + store_custom[store] = 1; + } + else if(is_array(store)){ + + for(let i = 0; i < store.length; i++){ + + store_custom[store[i]] = 1; + } + } + else if(is_object(store)){ + + store_custom = store; + } + + doc["store"] = store_custom; + } + if(SUPPORT_WHERE && tag){ this._tag = create_object(); @@ -673,7 +697,7 @@ // TODO: move fields to main index to provide pagination index[ref] = new FlexSearch(options); - index[ref]._doc = this._doc; + //index[ref]._doc = this._doc; // if(SUPPORT_WHERE && tag){ // @@ -682,6 +706,8 @@ // } } } + + options["doc"] = custom; } /** @@ -1137,16 +1163,16 @@ if(is_array(doc)){ - for(let i = 0, len = doc.length; i < len; i++){ + let len = doc.length; - if(i === len - 1){ + if(len--){ - return this.handle_docs(job, doc[i], callback); - } - else{ + for(let i = 0; i < len; i++){ this.handle_docs(job, doc[i]); } + + return this.handle_docs(job, doc[len], callback); } } else{ @@ -1154,28 +1180,58 @@ const index = this.doc.index; const keys = this.doc.keys; const tags = this.doc["tag"]; - let tree = this.doc["id"]; - let id; + const store = this.doc["store"]; + + let tree; let tag; - let tag_key; - let tag_value; + + // --------------------------------------------------------------- + + tree = this.doc["id"]; + + let id = doc; for(let i = 0; i < tree.length; i++){ - id = (id || doc)[tree[i]]; + id = id[tree[i]]; } + // --------------------------------------------------------------- + + if(job === "remove"){ + + delete this._doc[id]; + + let length = keys.length; + + if(length--){ + + for(let z = 0; z < length; z++){ + + index[keys[z]].remove(id); + } + + return index[keys[length]].remove(id, callback); + } + } + + // --------------------------------------------------------------- + if(tags){ + let tag_key; + let tag_value; + for(let i = 0; i < tags.length; i++){ tag_key = tags[i]; + tag_value = doc; const tag_split = tag_key.split(":"); for(let a = 0; a < tag_split.length; a++){ - tag_value = (tag_value || doc)[tag_split[a]]; + tag_value = tag_value[tag_split[a]]; } tag_value = "@" + tag_value; @@ -1185,41 +1241,18 @@ tag = tag[tag_value] || (tag[tag_value] = []); } - if(job === "remove"){ - - delete this._doc[id]; - - for(let z = 0, length = keys.length; z < length; z++){ - - if(z === length - 1){ - - index[keys[z]].remove(id, callback); - return this; - } - else{ - - index[keys[z]].remove(id); - } - } - } + // --------------------------------------------------------------- tree = this.doc["field"]; - if(tag){ - - tag[tag.length] = doc; // tag[tag.length] = id; - } - - this._doc[id] = doc; - for(let i = 0, len = tree.length; i < len; i++){ const branch = tree[i]; - let content; + let content = doc; for(let x = 0; x < branch.length; x++){ - content = (content || doc)[branch[x]]; + content = content[branch[x]]; } const self = index[keys[i]]; @@ -1244,6 +1277,46 @@ fn.call(self, id, content); } } + + // --------------------------------------------------------------- + + if(store){ + + const store_keys = get_keys(store); + let store_doc = create_object(); + + for(let i = 0; i < store_keys.length; i++){ + + let store_key = store_keys[i]; + + if(store[store_key]){ + + const store_split = store_key.split(":"); + + let store_value; + let store_doc_value; + + for(let a = 0; a < store_split.length; a++){ + + const store_split_key = store_split[a]; + + store_value = (store_value || doc)[store_split_key]; + store_doc_value = (store_doc_value || store_doc)[store_split_key] = store_value; + } + } + } + + doc = store_doc; + } + + // --------------------------------------------------------------- + + if(tag){ + + tag[tag.length] = doc; // tag[tag.length] = id; + } + + this._doc[id] = doc; } return this; @@ -2353,15 +2426,15 @@ for(i = 0; i < length; i++){ const idx = this.doc.index[keys[i]]; + const item = payload[i]; - idx._map = payload[i][0]; - idx._ctx = payload[i][1]; - idx._ids = ids; + if(item){ - // if(import_doc){ - // - // idx._doc = payload[length]; - // } + idx._map = item[0]; + idx._ctx = item[1]; + idx._ids = ids; + // idx._doc = payload[length]; + } } } diff --git a/package.json b/package.json index 31e9407..482c0e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flexsearch", - "version": "0.6.24", + "version": "0.6.30", "description": "Next-Generation full text search library with zero dependencies.", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/test/export_import.html b/test/export_import.html new file mode 100644 index 0000000..7427dd1 --- /dev/null +++ b/test/export_import.html @@ -0,0 +1,83 @@ + + + + + Test: Export / Import + + + + + + \ No newline at end of file