Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flexsearch

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flexsearch - npm Package Compare versions

Comparing version 0.2.125 to 0.2.451

test/matching-flexsearch.html

50

flexsearch.min.js
/*
FlexSearch v0.2.44
Copyright 2018 Thomas Wilkerling
Released under the Apache 2.0 Licence
https://github.com/nextapps-de/flexsearch
@version: 0.2.11
@license: Apache 2.0 Licence
*/
'use strict';(function(m,C,f){var d;(d=f.define)&&d.amd?d([],function(){return C}):(d=f.modules)?d[m.toLowerCase()]=C:"undefined"!==typeof module?module.exports=C:f[m]=C})("FlexSearch",function H(m){function f(a){a||(a=t);this.id=a.id||I++;this.init(a);Object.defineProperty(this,"index",{get:function(){return this.a}});Object.defineProperty(this,"length",{get:function(){return Object.keys(this.a).length}})}function d(a){return new RegExp(a,"g")}function u(a,b,c){if("undefined"===typeof c){for(c=0;c<
b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}return a.replace(b,c)}function p(a,b,c,e,l,n){if("undefined"===typeof b[c]){var g=l.indexOf(c);g=3/l.length*(l.length-g)+6/(g-l.lastIndexOf(" ",g))+.5|0;b[c]=g;g>n&&(a=a[g],a=a[c]||(a[c]=[]),a[a.length]=e)}return g||b[c]}function x(a){for(var b="",c="",e="",l=0;l<a.length;l++){var n=a[l];n!==c&&(0<l&&"h"===n?(e="a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e,"a"!==c&&"e"!==c&&"i"!==c&&"o"!==c&&"u"!==c&&"y"!==c||!e||(b+=n)):b+=n);e=l===a.length-
1?"":a[l+1];c=n}return b}function y(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function J(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function K(a,b){var c=[],e=a.length;if(1<e){a.sort(J);for(var l={},n=a[0],g=0,D=n.length;g<D;++g)l[n[g]]=1;for(var d=0,k=1;k<e;++k){var h=a[k],f=!1;g=0;for(D=h.length;g<D;++g)if(l[n=h[g]]===k){if(k===e-1&&(c[d++]=n,b&&d===b))return c;f=!0;l[n]=k+1;break}if(!f)return[]}}else e&&(c=a[0],b&&c&&c.length>b&&(c=c.slice(0,b)));return c}function z(a){a.w||(a.w=E(function(){a.w=
null;var b=a.async;b&&(a.async=!1);if(a.c.length){for(var c=F(),e;(e=a.c.shift())||0===e;){var l=a.h[e];switch(l[0]){case A.add:a.add(l[1],l[2]);break;case A.update:a.update(l[1],l[2]);break;case A.remove:a.remove(l[1])}a.h[e]=null;delete a.h[e];if(100<F()-c)break}a.c.length&&z(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function F(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}function L(a,b,c,e){a=m("flexsearch","id"+a,function(){var a,b;self.a=function(c){if(c=
c.data)c.search?self.postMessage({result:b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit),id:a,content:c.content,limit:c.limit}):c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset():c.info?(c=b.info(),c.worker=a,b.A&&console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!0,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}},
function(a){(a=a.data)&&a.result&&e(a.id,a.content,a.result,a.limit)},b);var l=H.toString();c.id=b;a.postMessage(b,{register:l,options:c,id:b});return a}var t={type:"integer",mode:"forward",cache:!1,async:!1,b:!1,threshold:0,depth:0,encode:"icase"},v=[],I=0,A={add:0,update:1,remove:2},G=d("[ -/]");f.new=function(a){return new this(a)};f.create=function(a){return f.new(a)};f.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(v[v.length]=d(b),v[v.length]=a[b]);return this};f.register=function(a,
b){B[a]=b;return this};f.encode=function(a,b){return B[a].call(B,b)};f.prototype.init=function(a){this.m=[];if(a){if(a.worker)if("undefined"===typeof Worker)a.worker=!1,a.async=!0,this.j=null;else{var b=this,c=parseInt(a.worker,10)||4;b.s=-1;b.o=0;b.i=[];b.v=null;b.j=Array(c);for(var e=0;e<c;e++)b.j[e]=L(b.id,e,a||t,function(a,c,e,d){b.o!==b.b&&(b.i=b.i.concat(e),b.o++,d&&b.i.length>=d&&(b.o=b.b),b.v&&b.o===b.b&&(b.i.length?b.f="":b.f||(b.f=c),b.cache&&b.l.set(c,b.i),b.v(b.i),b.i=[]))})}this.mode=
a.mode||this.mode||t.mode;this.cache=a.cache||this.cache||t.cache;this.async=a.async||this.async||t.async;this.b=a.worker||this.b||t.b;this.threshold=a.threshold||this.threshold||t.threshold;this.depth=a.depth||this.depth||t.depth;this.encoder=a.encode&&B[a.encode]||("function"===typeof a.encode?a.encode:this.encoder||!1);this.A=a.debug||this.A;a.matcher&&this.addMatcher(a.matcher)}this.g=[{},{},{},{},{},{},{},{},{},{},{}];this.a={};this.h={};this.c=[];this.w=null;this.f="";this.u=!0;this.l=this.cache?
new M(3E4,50,!0):!1;return this};f.prototype.encode=function(a){a&&v.length&&(a=u(a,v));a&&this.m.length&&(a=u(a,this.m));a&&this.encoder&&(a=this.encoder.call(B,a));return a};f.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.m[this.m.length]=d(b),this.m[this.m.length]=a[b]);return this};f.prototype.add=function(a,b){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else{if(this.b)return++this.s>=this.j.length&&(this.s=0),this.j[this.s].postMessage(this.s,
{add:!0,id:a,content:b}),this.a[a]=""+this.s,this;if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[A.add,a,b],z(this),this;b=this.encode(b);if(!b.length)return this;if("ngram"===this.mode){var c=b;var e=[];if(c)for(var d=0,n=0,g=-1,f="",q=c.length,k=0;k<q;k++){var h=c[k];"a"===h||"e"===h||"i"===h||"o"===h||"u"===h||"y"===h?d++:n++;" "!==h&&(f+=h);if(" "===h||2<=d&&2<=n||k===q-1)f&&(2<f.length?e[++g]=f:e[g]&&(e[g]+=f),f=""),n=d=0}c=e}else c=b.split(G);e={_ctx:{}};d=this.threshold;
n=this.depth;g=this.g;f=c.length;for(q=0;q<f;q++)if(k=c[q]){var m=k.length;switch(this.mode){case "reverse":case "both":var r="";for(h=m-1;1<=h;h--)r=k[h]+r,p(g,e,r,a,b,d);case "forward":r="";for(h=0;h<m;h++)r+=k[h],p(g,e,r,a,b,d);break;case "full":for(h=0;h<m;h++)for(var w=m;w>h;w--)r=k.substring(h,w),p(g,e,r,a,b,d);break;default:if(h=p(g,e,k,a,b,d),n&&1<f&&h>d)for(h=g[10],m=e._ctx[k]||(e._ctx[k]={}),k=h[k]||(h[k]=[{},{},{},{},{},{},{},{},{},{}]),h=q-n,w=q+n,0>h&&(h=0),w>f-1&&(w=f-1);h<=w;h++)h!==
q&&p(k,m,c[h],a,b,d)}}this.a[a]="1";this.u=!1}return this};f.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)&&this.a[a]){if(this.b){var c=parseInt(this.a[a],10);this.j[c].postMessage(c,{update:!0,id:a,content:b});return this}if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[A.update,a,b],z(this),this;this.remove(a);b&&this.add(a,b)}return this};f.prototype.remove=function(a){if(this.a[a]){if(this.b){var b=parseInt(this.a[a],10);this.j[b].postMessage(b,{remove:!0,
id:a});delete this.a[a];return this}if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[A.remove,a],z(this),this;for(b=0;10>b;b++)for(var c=Object.keys(this.g[b]),e=0;e<c.length;e++){var d=c[e],f=this.g[b];if((f=f&&f[d])&&f.length)for(var g=0;g<f.length;g++)if(f[g]===a){f.splice(g,1);break}f.length||delete this.g[b][d]}delete this.a[a];this.u=!1}return this};f.prototype.search=function(a,b,c){var e=[];if(a&&"object"===typeof a){c=a.callback||b;b=a.limit;var d=a.threshold;a=a.query}d||
(d=0);"function"===typeof b?(c=b,b=1E3):b||(b=1E3);if(this.b){this.v=c;this.o=0;this.i=[];for(e=0;e<this.b;e++)this.j[e].postMessage(e,{search:!0,limit:b,threshold:d,content:a});return null}if(c){var f=this;E(function(){c(f.search(a,b));f=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return e;var g=a;if(!this.u)this.cache&&(this.f="",this.l.reset()),this.u=!0;else if(this.cache){var m=this.l.get(a);if(m)return m}else if(this.f&&0===a.indexOf(this.f))return e;g=this.encode(g);if(!g.length)return e;
g=g.constructor===Array?g:g.split(G);m=g.length;var q=!0,k=[],h={};if(1<m)if(this.depth){var t=!0,r=g[0];h[r]="1"}else g.sort(y);var w;if(!t||(w=this.g[10])[r])for(var u=t?1:0;u<m;u++){var p=g[u];if(p&&!h[p]){for(var v,A=!1,x=[],B=0,z=9;z>=d;z--)if(v=t?w[r][z][p]:this.g[z][p])x[B++]=v,A=!0;if(A)k[k.length]=1<B?k.concat.apply([],x):x[0];else{q=!1;break}h[p]="1"}r=p}else q=!1;q&&(e=K(k,b));e.length?this.f="":this.f||(this.f=a);this.cache&&this.l.set(a,e);return e};f.prototype.info=function(){if(this.b)for(var a=
0;a<this.b;a++)this.j[a].postMessage(a,{info:!0,id:this.id});else{for(var b,c,e=0,d=0,f=0,g=0;10>g;g++)for(b=Object.keys(this.g[g]),a=0;a<b.length;a++)c=this.g[g][b[a]].length,e+=c+2*b[a].length+4,d+=c,f+=2*b[a].length;b=Object.keys(this.a);c=b.length;for(a=0;a<c;a++)e+=2*b[a].length+2;return{id:this.id,memory:e,items:c,sequences:d,chars:f,status:this.u,cache:this.c.length,matcher:v.length,worker:this.b}}};f.prototype.reset=function(){this.destroy();return this.init()};f.prototype.destroy=function(){this.cache&&
this.l.reset();this.g=this.a=this.l=null;return this};var B={icase:function(a){return a.toLowerCase()},simple:function(){var a=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d("[-/]")," ",d("[^a-z0-9 ]"),""];return function(b){return u(b.toLowerCase(),a)}}(),
advanced:function(){var a=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",d("cc"),"k",d("dt"),"t",d("ph"),"f",d("pf"),"f",d("ou"),"o",d("uo"),"u"];return function(b,c){if(!b)return b;b=this.simple(b);2<b.length&&(b=u(b,a));c||1<b.length&&(b=x(b));return b}}(),extra:function(){var a=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,
!0);if(1<b.length){b=b.split(" ");for(var c=0;c<b.length;c++){var d=b[c];1<d.length&&(b[c]=d[0]+u(d.substring(1),a))}b=b.join("");b=x(b)}return b}}()},E=function(){var a={};return function(b,c,d){var e=a[d];e&&clearTimeout(e);return a[d]=setTimeout(b,c)}}(),M=function(){function a(){this.cache={}}a.prototype.reset=function(){this.cache={}};a.prototype.set=function(a,c){this.cache[a]=c};a.prototype.get=function(a){return this.cache[a]};return a}();return f}(function(){var m={},C=!("undefined"===typeof Blob||
"undefined"===typeof URL||!URL.createObjectURL);return function(f,d,u,p,x){var y=f;f=C?URL.createObjectURL(new Blob(["("+u.toString()+")()"],{type:"text/javascript"})):"../"+y+".js";y+="-"+d;m[y]||(m[y]=[]);m[y][x]=new Worker(f);m[y][x].onmessage=p;return{postMessage:function(d,f){m[y][d].postMessage(f)}}}}()),this);
'use strict';(function(q,B,g){var t;(t=g.define)&&t.amd?t([],function(){return B}):(t=g.modules)?t[q.toLowerCase()]=B:"undefined"!==typeof module?module.exports=B:g[q]=B})("FlexSearch",function K(q){function g(a){"string"===typeof a&&(a=F[a]);a||(a=x);this.id=a.id||L++;this.init(a);t(this,"index",function(){return this.a});t(this,"length",function(){return Object.keys(this.a).length})}function t(a,b,d){Object.defineProperty(a,b,{get:d})}function e(a){return new RegExp(a,"g")}function y(a,b,d){if("undefined"===
typeof d){for(d=0;d<b.length;d+=2)a=a.replace(b[d],b[d+1]);return a}return a.replace(b,d)}function u(a,b,d,c,f,m,k){if("undefined"===typeof b[d]){var h=f?(9-(k||6))*m+(k||6)*f:m;b[d]=h;h>=k&&(a=a[h+.5|0],a=a[d]||(a[d]=[]),a[a.length]=c)}return h||b[d]}function n(a,b){if(a)for(var d=Object.keys(a),c=0,f=d.length;c<f;c++){var m=d[c],k=a[m];if(k)for(var h=0,e=k.length;h<e;h++)if(k[h]===b){1===e?delete a[m]:k.splice(h,1);break}else"object"===typeof k[h]&&n(k[h],b)}}function G(a){var b=[];if(!a)return b;
for(var d=0,c=0,f=0,m="",k=a.length,h=0;h<k;h++){var e=a[h];"a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e?d++:c++;" "!==e&&(m+=e);if(" "===e||d>=(8<k?2:1)&&2<=c||2<=d&&c>=(8<k?2:1)||h===k-1)m&&(b[f]&&2<m.length&&f++,b[f]=b[f]?b[f]+m:m," "===e&&f++,m=""),c=d=0}return b}function D(a){for(var b="",d="",c="",f=0;f<a.length;f++){var m=a[f];if(m!==d)if(f&&"h"===m){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d)&&c||" "===d)b+=m}else b+=
m;c=f===a.length-1?"":a[f+1];d=m}return b}function M(a,b){var d={};if(a)for(var c=0;c<a.length;c++){var f=b?b.call(z,a[c]):a[c];d[f]=String.fromCharCode(65E3-a.length+c)}return d}function N(a,b){var d=[];if(a){var c=0,f;for(f in a)if(a.hasOwnProperty(f)){var m=b?b.call(z,f):f;d[c++]=e("(?=.{"+(m.length+3)+",})"+m+"$");d[c++]=b?b.call(z,a[f]):a[f]}}return d}function O(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function P(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function Q(a,b){var d=[],c=
a.length;if(1<c){a.sort(P);for(var f={},m=a[0],e=m.length,h=0;h<e;)f[m[h++]]=1;for(var g,r=0,p=1;p<c;){var n=!1;m=a[p];e=m.length;for(h=0;h<e;)if(f[g=m[h++]]===p){if(p===c-1&&(d[r++]=g,b&&r===b)){n=!1;break}n=!0;f[g]=p+1}if(!n)break;p++}}else if(c&&(d=a[0],b&&d.length>b))return d.slice(0,b);return d}function E(a){a.D||(a.D=H(function(){a.D=null;var b=a.async;b&&(a.async=!1);if(a.f.length){for(var d=I(),c;(c=a.f.shift())||0===c;){var f=a.h[c];switch(f[0]){case C.add:a.add(f[1],f[2]);break;case C.update:a.update(f[1],
f[2]);break;case C.remove:a.remove(f[1])}a.h[c]=null;delete a.h[c];if(100<I()-d)break}a.f.length&&E(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function I(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}function R(a,b,d,c){a=q("flexsearch","id"+a,function(){var a,b;self.a=function(c){if(c=c.data)if(c.search){var d=b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:d})}else c.add?
b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset():c.info?(c=b.info(),c.worker=a,b.G&&console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!0,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}},function(a){(a=a.data)&&a.result?c(a.id,a.content,a.result,a.limit):d.debug&&console.log(a)},b);var f=K.toString();d.id=b;a.postMessage(b,{register:f,options:d,
id:b});return a}var x={encode:"icase",mode:"ngram",cache:!1,async:!1,b:!1,threshold:0,depth:0},F={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"ngram",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},A=[],L=0,C={add:0,update:1,remove:2},J=e("[ -/]"),S="a about above after again against all also am an and any are aren't as at be because been before being below both but by can cannot can't come could couldn't did didn't do does doesn't doing dont down during each even few first for from further get go had hadn't has hasn't have haven't having he hed her here here's hers herself hes him himself his how how's i id if ill im in into is isn't it it's itself i've just know let's like make me more most mustn't my myself new no nor not now of off on once only or other ought our our's ourselves out over own same say see shan't she she'd shell shes should shouldn't so some such than that that's the their theirs them themselves then there there's these they they'd they'll they're they've this those through time to too until up us very want was wasn't way we wed well were weren't we've what what's when when's where where's which while who whom who's why why's will with won't would wouldn't you you'd you'll your you're your's yourself yourselves you've".split(" "),
T={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log",icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:"",al:"",ance:"",ence:"",er:"",ic:"",able:"",ible:"",ant:"",ement:"",ment:"",ent:"",ou:"",ism:"",ate:"",iti:"",ous:"",ive:"",ize:""};g.new=function(a){return new this(a)};g.create=function(a){return g.new(a)};
g.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(A[A.length]=e(b),A[A.length]=a[b]);return this};g.register=function(a,b){z[a]=b;return this};g.encode=function(a,b){return z[a].call(z,b)};g.prototype.init=function(a){this.C=[];a||(a=x);var b=a.profile,d=b?F[b]:{};if(b=a.worker)if("undefined"===typeof Worker)a.worker=!1,a.async=!0,this.i=null;else{var c=this;b=parseInt(b,10)||4;c.s=-1;c.m=0;c.g=[];c.w=null;c.i=Array(b);for(var f=0;f<b;f++)c.i[f]=R(c.id,f,a||x,function(a,b,d,f){c.m!==c.b&&
(c.g=c.g.concat(d),c.m++,f&&c.g.length>=f&&(c.m=c.b),c.w&&c.m===c.b&&(c.g.length?c.c="":c.c||(c.c=b),c.cache&&c.j.set(b,c.g),c.w(c.g),c.g=[]))})}this.mode=a.mode||d.mode||this.mode||x.mode;this.async=a.async||this.async||x.async;this.b=a.worker||this.b||x.b;this.threshold=a.threshold||d.threshold||this.threshold||x.threshold;this.depth=a.depth||d.depth||this.depth||x.depth;this.v=(b=a.encode||d.encode)&&z[b]||("function"===typeof b?b:this.v||!1);this.G=a.debug||this.G;(b=a.matcher)&&this.addMatcher(b);
if(b=a.filter)this.B=M(!0===b?S:b,this.v);if(b=a.stemmer)this.F=N(!0===b?T:b,this.v);this.l=[{},{},{},{},{},{},{},{},{},{}];this.o={};this.a={};this.h={};this.f=[];this.D=null;this.c="";this.u=!0;this.j=(this.cache=b=a.cache||this.cache||x.cache)?new U(b):!1;return this};g.prototype.encode=function(a){a&&A.length&&(a=y(a,A));a&&this.C.length&&(a=y(a,this.C));a&&this.v&&(a=this.v.call(z,a));if(a&&this.B){a=a.split(" ");for(var b=0;b<a.length;b++){var d=this.B[a[b]];d&&(a[b]=d)}a=a.join(" ")}a&&this.F&&
(a=y(a,this.F));return a};g.prototype.addMatcher=function(a){var b=this.C,d;for(d in a)a.hasOwnProperty(d)&&(b[b.length]=e(d),b[b.length]=a[d]);return this};g.prototype.add=function(a,b,d){if("string"===typeof b&&b&&(a||0===a))if(this.a[a]&&!d)this.update(a,b);else{if(this.b)return++this.s>=this.i.length&&(this.s=0),this.i[this.s].postMessage(this.s,{add:!0,id:a,content:b}),this.a[a]=""+this.s,this;if(this.async)return this.h[a]||(this.f[this.f.length]=a),this.h[a]=[C.add,a,b],E(this),this;b=this.encode(b);
if(!b.length)return this;d=this.mode;b="function"===typeof d?d(b):"ngram"===d?G(b):b.split(J);for(var c={_ctx:{}},f=this.threshold,e=this.depth,k=this.l,h=b.length,g=0;g<h;g++){var r=b[g];if(r){var p=r.length,n=(h-g)/h;switch(d){case "reverse":case "both":for(var v="",l=p-1;1<=l;l--)v=r[l]+v,u(k,c,v,a,(p-l)/p,n,f);case "forward":v="";for(l=0;l<p;l++)v+=r[l],u(k,c,v,a,1,n,f);break;case "full":for(l=0;l<p;l++)for(var q=(p-l)/p,w=p;w>l;w--)v=r.substring(l,w),u(k,c,v,a,q,n,f);break;default:if(l=u(k,c,
r,a,1,n,f),e&&1<h&&l>=f)for(p=c._ctx[r]||(c._ctx[r]={}),r=this.o[r]||(this.o[r]=[{},{},{},{},{},{},{},{},{},{}]),l=g-e,w=g+e+1,0>l&&(l=0),w>h&&(w=h);l<w;l++)l!==g&&u(r,p,b[l],a,0,10-(l<g?g-l:l-g),f)}}}this.a[a]="1";this.u=!1}return this};g.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};g.prototype.remove=function(a){if(this.a[a]){if(this.b){var b=parseInt(this.a[a],10);this.i[b].postMessage(b,{remove:!0,id:a});delete this.a[a];return this}if(this.async)return this.h[a]||
(this.f[this.f.length]=a),this.h[a]=[C.remove,a],E(this),this;for(b=0;10>b;b++)n(this.l[b],a);this.depth&&n(this.o,a);delete this.a[a];this.u=!1}return this};g.prototype.search=function(a,b,d){var c=[];if(a&&"object"===typeof a){d=a.callback||b;b=a.limit;var f=a.threshold;a=a.query}f=(f||this.threshold||0)|0;"function"===typeof b?(d=b,b=1E3):b||(b=1E3);if(this.b){this.w=d;this.m=0;this.g=[];for(c=0;c<this.b;c++)this.i[c].postMessage(c,{search:!0,limit:b,threshold:f,content:a});return null}if(d){var e=
this;H(function(){d(e.search(a,b));e=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return c;var k=a;if(!this.u)this.cache&&(this.c="",this.j.reset()),this.u=!0;else if(this.cache){var h=this.j.get(a);if(h)return h}else if(this.c&&0===a.indexOf(this.c))return c;k=this.encode(k);if(!k.length)return c;h=this.mode;k="function"===typeof h?h(k):"ngram"===h?G(k):k.split(J);h=k.length;var g=!0,n=[],p={};if(1<h)if(this.depth){var q=!0,v=k[0];p[v]="1"}else k.sort(O);var l;if(!q||(l=this.o)[v])for(var t=
q?1:0;t<h;t++){var w=k[t];if(w&&!p[w]){for(var x,y=!1,u=[],z=0,A=9;A>=f;A--)if(x=(q?l[v]:this.l)[A][w])u[z++]=x,y=!0;if(y)n[n.length]=1<z?n.concat.apply([],u):u[0];else{g=!1;break}p[w]="1"}v=w}else g=!1;g&&(c=Q(n,b));c.length?this.c="":this.c||(this.c=a);this.cache&&this.j.set(a,c);return c};g.prototype.info=function(){if(this.b)for(var a=0;a<this.b;a++)this.i[a].postMessage(a,{info:!0,id:this.id});else{for(var b,d,c=0,f=0,e=0,g=0;10>g;g++)for(b=Object.keys(this.l[g]),a=0;a<b.length;a++)d=this.l[g][b[a]].length,
c+=d+2*b[a].length+4,f+=d,e+=2*b[a].length;b=Object.keys(this.a);d=b.length;for(a=0;a<d;a++)c+=2*b[a].length+2;return{id:this.id,memory:c,items:d,sequences:f,chars:e,status:this.u,cache:this.f.length,matcher:A.length,worker:this.b}}};g.prototype.reset=function(){this.destroy();return this.init()};g.prototype.destroy=function(){this.cache&&(this.j.reset(),this.j=null);this.B=this.F=this.l=this.o=this.a=this.h=this.f=null;return this};var z={icase:function(a){return a.toLowerCase()},simple:function(){var a=
[e("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",e("[\u00e8\u00e9\u00ea\u00eb]"),"e",e("[\u00ec\u00ed\u00ee\u00ef]"),"i",e("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",e("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",e("[\u00fd\u0177\u00ff]"),"y",e("\u00f1"),"n",e("\u00e7"),"c",e("\u00df"),"s",e(" & ")," and ",e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s\\s+")," "];return function(b){b=y(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){var a=[e("ae"),"a",e("ai"),"ei",e("ay"),"ei",e("ey"),"ei",e("oe"),
"o",e("ue"),"u",e("ie"),"i",e("sz"),"s",e("zs"),"s",e("sh"),"s",e("ck"),"k",e("cc"),"k",e("dt"),"t",e("ph"),"f",e("pf"),"f",e("ou"),"o",e("uo"),"u"];return function(b,d){if(!b)return b;b=this.simple(b);2<b.length&&(b=y(b,a));d||1<b.length&&(b=D(b));return b}}(),extra:function(){var a=[e("p"),"b",e("z"),"s",e("[cgq]"),"k",e("n"),"m",e("d"),"t",e("[vw]"),"f",e("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var d=0;d<b.length;d++){var c=b[d];
1<c.length&&(b[d]=c[0]+y(c.substring(1),a))}b=b.join(" ");b=D(b)}return b}}(),balance:function(){var a=[e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s\\s+")," "];return function(b){return D(y(b.toLowerCase(),a))}}()},H=function(){var a={};return function(b,d,c){var e=a[c];e&&clearTimeout(e);return a[c]=setTimeout(b,d)}}(),U=function(){function a(a){this.reset();this.A=!0!==a&&a}a.prototype.reset=function(){this.cache={};this.count={};this.index={};this.keys=[]};a.prototype.set=function(a,d){if(this.A&&"undefined"===
typeof this.cache[a]){var b=this.keys.length;if(b===this.A){b--;var e=this.keys[b];delete this.cache[e];delete this.count[e];delete this.index[e]}this.index[a]=b;this.keys[b]=a;this.count[a]=-1;this.cache[a]=d;this.get(a)}else this.cache[a]=d};a.prototype.get=function(a){var b=this.cache[a];if(this.A&&b){var c=++this.count[a],e=this.index,g=e[a];if(0<g){for(var k=this.keys,h=g;this.count[k[--g]]<=c&&-1!==g;);g++;if(g!==h){for(c=h;c>g;c--)h=k[c-1],k[c]=h,e[h]=c;k[g]=a;e[a]=g}}}return b};return a}();
return g}(function(){var q={},B=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(g,t,e,y,u){var n=g;g=B?URL.createObjectURL(new Blob(["var SUPPORT_WORKER = true;var SUPPORT_BUILTINS = true;var SUPPORT_DEBUG = true;var SUPPORT_CACHE = true;var SUPPORT_ASYNC = true;("+e.toString()+")()"],{type:"text/javascript"})):"../"+n+".js";n+="-"+t;q[n]||(q[n]=[]);q[n][u]=new Worker(g);q[n][u].onmessage=y;console.log("Register Worker: "+n+"@"+u);return{postMessage:function(e,
g){q[n][e].postMessage(g)}}}}()),this);
{
"name": "flexsearch",
"version": "0.2.125",
"description": "World's fastest and most memory efficient full text search library.",
"keywords": [],
"version": "0.2.451",
"description": "Next-Generation full text search library with zero dependencies.",
"homepage": "https://nextapps-de.github.io/xone/",
"author": "Thomas Wilkerling",
"copyright": "Nextapps GmbH",
"license": "Apache-2.0",
"keywords": [
"full text search",
"elastic search",
"fastest search",
"contextual search"
],
"bugs": {

@@ -10,4 +19,4 @@ "url": "https://github.com/nextapps-de/flexsearch/issues",

},
"main": "flexsearch.js",
"preferGlobal": true,
"main": "flexsearch.min.js",
"preferGlobal": false,
"bin": {},

@@ -19,5 +28,8 @@ "repository": {

"scripts": {
"build": "java -jar -Xms256m -Xmx4096m node_modules/google-closure-compiler/compiler.jar --compilation_level=ADVANCED_OPTIMIZATIONS --use_types_for_optimization=true --new_type_inf=true --jscomp_warning=newCheckTypes --generate_exports=true --export_local_property_definitions=true --language_in=ECMASCRIPT5_STRICT --language_out=ECMASCRIPT5_STRICT --process_closure_primitives=true --summary_detail_level=3 --warning_level=VERBOSE --emit_use_strict=true --output_manifest=log/manifest.log --output_module_dependencies=log/module_dependencies.log --property_renaming_report=log/renaming_report.log --js='flexsearch.js' --js_output_file='flexsearch.min.js' && echo Build Complete. && exit 0",
"release": "npm version patch && npm run build && npm publish",
"build": "node compile RELEASE=min SUPPORT_DEBUG=true SUPPORT_WORKER=true SUPPORT_BUILTINS=true SUPPORT_CACHE=true SUPPORT_ASYNC=true && exit 0",
"build-light": "node compile RELEASE=light SUPPORT_DEBUG=false SUPPORT_WORKER=false SUPPORT_BUILTINS=false SUPPORT_CACHE=false SUPPORT_ASYNC=false && exit 0",
"build-custom": "node compile",
"build-all": "npm run build && npm run build-light",
"test-production": "nyc --reporter=html --reporter=text mocha --timeout=3000 test --exit",
"test-light": "nyc --reporter=html --reporter=text mocha --timeout=3000 test/ --exit",
"test-develop": "nyc --reporter=html --reporter=text mocha --timeout=3000 --exit",

@@ -34,5 +46,2 @@ "test-browser": "mocha-phantomjs test/index.html",

],
"homepage": "https://nextapps-de.github.io/xone/",
"author": "Thomas Wilkerling",
"license": "Apache-2.0",
"dependencies": {},

@@ -39,0 +48,0 @@ "devDependencies": {

@@ -0,4 +1,6 @@

<p align="center"></p>
<p align="center">
<br>
<img src="http://nextapps.de/img/flexsearch.svg" alt="Search Library" width="50%">
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/flexsearch.svg" alt="Search Library" width="50%">
<br><br>

@@ -17,8 +19,13 @@ <a target="_blank" href="https://www.npmjs.com/package/flexsearch"><img src="https://img.shields.io/npm/v/flexsearch.svg"></a>

When it comes to raw search speed <a href="https://jsperf.com/compare-search-libraries" target="_blank">FlexSearch outperforms every single searching library out there</a> and also provides flexible search capabilities like multi-word matching, phonetic transformations or partial matching. It also has the __most memory-efficient index__. Keep in mind that updating existing items from the index has a significant cost. When your index needs to be updated continuously then <a href="bulksearch/" target="_blank">BulkSearch</a> may be a better choice. FlexSearch also provides you a non-blocking asynchronous processing model as well as web workers to perform any updates on the index as well as queries through dedicated threads.
When it comes to raw search speed <a href="https://jsperf.com/compare-search-libraries" target="_blank">FlexSearch outperforms every single searching library out there</a> and also provides flexible search capabilities like multi-word matching, phonetic transformations or partial matching.
It also has the __most memory-efficient index__. Keep in mind that updating / removing existing items from the index has a significant cost. When your index needs to be updated continuously then <a href="bulksearch/" target="_blank">BulkSearch</a> may be a better choice.
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.
Benchmark:
- Library Comparison: <a href="https://jsperf.com/compare-search-libraries" target="_blank">https://jsperf.com/compare-search-libraries</a>
- BulkSearch vs. FlexSearch: <a href="https://jsperf.com/flexsearch" target="_blank">https://jsperf.com/flexsearch</a>
<a href="#installation">Installation Guide</a> &ensp;&bull;&ensp; <a href="#api">API Reference</a> &ensp;&bull;&ensp; <a href="#profiles">Example Options</a> &ensp;&bull;&ensp; <a href="#builds">Custom Builds</a>
Comparison:
- <a href="https://jsperf.com/compare-search-libraries" target="_blank">Library Query Benchmarks</a>
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching.html" target="_blank">Library Relevance Scoring</a>
- <a href="#consumption">Library Memory Consumption</a>
Supported Platforms:

@@ -28,2 +35,3 @@ - Browser

<!--
Supported Module Definitions:

@@ -34,2 +42,3 @@ - AMD (RequireJS)

- Global (Browser)
-->

@@ -39,2 +48,3 @@ All Features:

<li><a href="#webworker">Web-Worker Support</a> (not available in Node.js)</li>
<li><a href="#contextual">Contextual Indexes</a></li>
<li>Partial Matching</li>

@@ -44,20 +54,33 @@ <li>Multiple Words</li>

<li>Relevance-based Scoring</li>
<li>Contextual Indexes</li>
<li>Auto-Balanced Cache by Popularity</li>
<li>Limit Results</li>
<li>Caching</li>
<li>Asynchronous Mode</li>
<li>Custom Matchers</li>
<li>Custom Encoders</li>
<li>Supports Caching</li>
<li>Asynchronous Processing</li>
<li>Customizable: Matcher, Encoder, Tokenizer, Stemmer, Filter</li>
</ul>
These features are not available in the 50% smaller <a href="flexsearch.light.js">light version</a>:
- WebWorker
- Asynchronous
- Cache
- Built-in encoders except 'balance' and 'icase' (you can still pass in customs)
- Built-in stemmer and filter (you can still pass in customs)
- Debug logging
- _index.info()_ method
The light version is just available as compiled version (flexsearch.light.js).
> You can also make <a href="#builds">Custom Builds</a> pretty simple
<a name="contextual"></a>
#### Contextual Search
FlexSearch introduce a new scoring mechanism called __Contextual Search__ which was invented by Thomas Wilkerling, the author of this library. A Contextual Search __incredibly boost up queries to a complete new level__.
FlexSearch introduce a new scoring mechanism called __Contextual Search__ which was invented by Thomas Wilkerling, the author of this library. A Contextual Search <a href="https://jsperf.com/compare-search-libraries" target="_blank">incredibly boost up queries to a complete new level</a>.
The basic idea of this concept is to limit relevance by its context instead of calculating relevance through the whole (unlimited) distance.
Imagine you add a text block of some sentences to an index ID. Assuming the query includes a combination of first and last word from this text block, are they really relevant to each other?
In this way contextual search also improves the results of relevance-based queries on large amount of text data.
In this way contextual search <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching.html" target="_blank">also improves the results of relevance-based queries</a> on large amount of text data.
<p align="center">
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/contextual_index.svg">
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/contextual_index.svg">
</p>

@@ -74,2 +97,3 @@

<!--
#### Compare BulkSearch vs. FlexSearch

@@ -99,3 +123,3 @@

<td><ul><li>Limited content</li><li>Use when existing items of the index needs to be updated continously (update, remove)</li><li>Supports pagination</li></ul></td>
<td><ul><li>Fastest possible search</li><li>Existing items of the index does not need to be updated continously (update, remove)</li><li>Max out memory capabilities</li></ul></td>
<td><ul><li>Fastest possible search</li><li>Use when existing items of the index does not need to be updated continously (update, remove)</li><li>Max out memory capabilities</li><li>Enhanced relevance scoring</li></ul></td>
</tr>

@@ -127,3 +151,5 @@ <tr></tr>

</table>
-->
<a name="installation"></a>
## Installation

@@ -171,2 +197,3 @@

<a name="api"></a>
## API Overview

@@ -208,2 +235,8 @@

##### Create a new index and choosing one of the built-in profiles
```js
var index = new FlexSearch("speed");
```
##### Create a new index with custom options

@@ -216,2 +249,3 @@

profile: "balance",
encode: "icase",

@@ -224,3 +258,4 @@ mode: "ngram",

__Read more:__ <a href="#phonetic">Phonetic Search</a>, <a href="#compare">Phonetic Comparison</a>, <a href="#memory">Improve Memory Usage</a>
<a href="#options">Read more about custom options</a>
<a name="index.add"></a>

@@ -393,3 +428,17 @@ #### Add items to an index

```
<a name="flexsearch.tokenizer"></a>
#### Add custom tokenizer
Define a private custom tokenizer during creation/initialization:
```js
var index = new FlexSearch({
mode: function(str){
// split string into components, e.g.:
return str.split(/ -\//g);
}
});
```
<a name="index.info"></a>

@@ -431,3 +480,3 @@ #### Get info

Create context-enabled index and also set the limit of relevance (depth):
Create index and just set the limit of relevance ("depth"):
```js

@@ -442,5 +491,16 @@ var index = new FlexSearch({

#### Enable Auto-Balanced Cache
Create index and just set a limit of cache entries:
```js
var index = new FlexSearch({
profile: "score",
cache: 10000
});
```
#### Use WebWorker (Browser only)
Create worker-enabled index and also set the count of parallel threads:
Create index and just set the count of parallel threads:
```js

@@ -472,3 +532,3 @@ var index = new FlexSearch({

FlexSearch ist highly customizable. Make use of the the right options can really improve your results as well as memory economy or query time.
FlexSearch ist highly customizable. Make use of the the <a href="#profiles">right options</a> can really improve your results as well as memory economy or query time.

@@ -483,4 +543,19 @@ <table>

<tr>
<td align="top">mode<br><br><br><br><br></td>
<td align="top">profile<br><br><br><br><br><br></td>
<td vertical="top" vertical-align="top">
"memory"<br>
"speed"<br>
"match"<br>
"score"<br>
"balance"<br>
"fastest"
</td>
<td vertical-align="top">
The <a href="#profiles">configuration profile</a>. Choose your preferation.<br>
</td>
</tr>
<tr></tr>
<tr>
<td align="top">mode<br><br><br><br><br><br></td>
<td vertical="top" vertical-align="top">
"strict"<br>

@@ -490,6 +565,7 @@ "foward"<br>

"ngram"<br>
"full"
"full"<br>
function()
</td>
<td vertical-align="top">
The <a href="#tokenizer">indexing mode (tokenizer)</a>.<br>
The <a href="#tokenizer">indexing mode (tokenizer)</a>.<br><br>Choose one of the <a href="#tokenizer">built-ins</a> or pass a <a href="#flexsearch.tokenizer">custom tokenizer function</a>.<br>
</td>

@@ -499,3 +575,3 @@ </tr>

<tr>
<td align="top">encode<br><br><br><br><br><br></td>
<td align="top">encode<br><br><br><br><br><br><br></td>
<td>

@@ -507,2 +583,3 @@ false<br>

"extra"<br>
"balance"<br>
function()

@@ -534,8 +611,9 @@ </td>

<tr>
<td align="top">cache<br><br></td>
<td align="top">cache<br><br><br></td>
<td>
false<br>
true<br>
false
{number}
</td>
<td>Enable/Disable caching.</td>
<td>Enable/Disable and/or set capacity of cached entries.<br><br>When passing a number as a limit the <b>cache automatically balance stored entries related to their popularity</b>.<br><br>Note: When just using "true" the cache has no limits and is actually 2-3 times faster (because the balancer do not have to run).</td>
</tr>

@@ -549,3 +627,3 @@ <tr></tr>

</td>
<td>Enable/Disable asynchronous processing.</td>
<td>Enable/Disable asynchronous processing.<br><br>Each job will be queued for non-blocking processing. Recommended when using WebWorkers.</td>
</tr>

@@ -566,6 +644,33 @@ <tr></tr>

false<br>
{number}
{number:0-9}
</td>
<td>Enable/Disable <a href="#contextual">contextual indexing</a> and also sets relevance depth (experimental).</td>
<td>Enable/Disable <a href="#contextual">contextual indexing</a> and also sets contextual distance of relevance.</td>
</tr>
<tr></tr>
<tr>
<td align="top">threshold<br><br></td>
<td>
false<br>
{number:0-9}
</td>
<td>Enable/Disable the threshold of minimum relevance all results should have.<br><br>Note: It is also possible to set a lower threshold for indexing and pass a higher value when calling <i>index.search(options)</i>.</td>
</tr>
<tr></tr>
<tr>
<td align="top">stemmer<br><br></td>
<td>
false<br>
{function}
</td>
<td>Disable or pass in custom object/array.</td>
</tr>
<tr></tr>
<tr>
<td align="top">filter<br><br></td>
<td>
false<br>
{function}
</td>
<td>Disable or pass in custom object/array.</td>
</tr>
</table>

@@ -597,3 +702,3 @@

<td><b>foo</b>bar<br>foo<b>bar</b></td>
<td>* n / 3.5</td>
<td>* n / 3</td>
</tr>

@@ -790,3 +895,3 @@ <tr></tr>

<a name="memory" id="memory"></a>
<a name="memory"></a>
## Memory Usage

@@ -837,3 +942,3 @@

<td>"ngram" (default)</td>
<td>* n / 3.5</td>
<td>* n / 3</td>
</tr>

@@ -857,29 +962,47 @@ <tr></tr>

<td align="left">Contextual Index</td>
<td align="left">Multiplied with:</td>
<td align="left">Multiply the sum above with:</td>
</tr>
<tr>
<td></td>
<td>* 2(depth + 1)</td>
<td>* (depth * 2 + 1)</td>
</tr>
</table>
## Example Options
<a name="consumption"></a>
#### Compare Memory Consumption
Memory-optimized:
The book "Gulliver's Travels" (Swift Jonathan 1726) was used for this test.
```json
<br>
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/memory-comparison.svg">
<a name="profiles"></a>
## Built-in Profiles
You can pass a built-in profile during creation/initialization. They have these following settings:
Standard profile: __"default"__
```js
{
encode: "icase",
mode: "forward"
}
```
Memory-optimized profile: __"memory"__
```js
{
encode: "extra",
mode: "strict",
threshold: 5
threshold: 7
}
```
Speed-optimized:
Speed-optimized profile: __"speed"__
```json
```js
{
encode: "icase",
mode: "strict",
threshold: 5,
threshold: 7,
depth: 2

@@ -889,5 +1012,5 @@ }

Matching-tolerant:
Matching-tolerant profile: __"match"__
```json
```js
{

@@ -899,9 +1022,20 @@ encode: "extra",

Balanced:
Relevance-optimized profile: __"score"__
```json
```js
{
encode: "simple",
encode: "extra",
mode: "strict",
threshold: 5,
depth: 4
}
```
Most-balanced profile: __"balanced"__
```js
{
encode: "balanced",
mode: "ngram",
threshold: 3,
threshold: 6,
depth: 3

@@ -911,5 +1045,52 @@ }

Absolute fastest profile: __"fastest"__
```js
{
encode: "icase",
threshold: 9,
depth: 1
}
```
Compare these options above:
- <a href="https://jsperf.com/compare-flexsearch-options" target="_blank">Benchmarks</a>
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching-flexsearch.html" target="_blank">Relevance Scoring</a>
<a name="builds"></a>
## Custom Builds
Default Build:
```bash
npm run build
```
Light Build:
```bash
npm run build-light
```
Custom Build:
```bash
npm run build-custom SUPPORT_WORKER=true SUPPORT_ASYNC=true
```
Supported flags:
- SUPPORT_DEBUG
- SUPPORT_WORKER
- SUPPORT_CACHE
- SUPPORT_ASYNC
- SUPPORT_BUILTINS (english stemmer and filter)
Alternatively you can also use:
```bash
node compile SUPPORT_WORKER=true
```
The custom build was saved to flexsearch.custom.js
---
Author FlexSearch: Thomas Wilkerling<br>
License: <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 License</a><br>
Copyright 2018 Thomas Wilkerling<br>
Released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 License</a><br>

@@ -9,5 +9,5 @@ if(typeof module !== 'undefined'){

var env = process.argv[3] === 'test' ? '.min' : '';
var env = process.argv[3] === 'test' ? 'min' : process.argv[3] === 'test/' ? 'light' : '';
var expect = require('chai').expect;
var FlexSearch = require("../flexsearch" + env + ".js");
var FlexSearch = require("../flexsearch" + (env ? '.' + env : '') + ".js");
}

@@ -45,2 +45,3 @@

mode: 'forward',
encode: false,

@@ -53,2 +54,3 @@ async: false,

mode: 'forward',
encode: false,

@@ -154,3 +156,7 @@ async: true,

expect(flexsearch_default).to.respondTo("init");
expect(flexsearch_default).to.respondTo("info");
if(env !== 'light'){
expect(flexsearch_default).to.respondTo("info");
}
});

@@ -172,6 +178,5 @@

expect(flexsearch_default.async).to.equal(false);
expect(flexsearch_default.mode).to.equal("forward");
expect(flexsearch_default.mode).to.equal("ngram");
expect(flexsearch_sync.async).to.equal(false);
expect(flexsearch_async.async).to.equal(true);
expect(flexsearch_custom.encoder).to.equal(test_encoder);
expect(flexsearch_strict.mode).to.equal("strict");

@@ -182,2 +187,8 @@ expect(flexsearch_forward.mode).to.equal("forward");

expect(flexsearch_ngram.mode).to.equal("ngram");
// not available in compiled version:
if(typeof flexsearch_custom.encoder !== 'undefined'){
expect(flexsearch_custom.encoder).to.equal(test_encoder);
}
});

@@ -218,10 +229,2 @@ });

expect(flexsearch_extra.length).to.equal(0);
flexsearch_extra.add(4, "Thomas");
flexsearch_extra.add(5, "Arithmetic");
flexsearch_extra.add(6, "Mahagoni");
expect(flexsearch_extra.search("tomass")).to.include(4);
expect(flexsearch_extra.search("arytmetik")).to.include(5);
expect(flexsearch_extra.search("mahagony")).to.include(6);
});

@@ -240,2 +243,13 @@ });

expect(flexsearch_sync.search("foo foo")).to.have.members([0, 1]);
if(env !== 'light'){
flexsearch_extra.add(4, "Thomas");
flexsearch_extra.add(5, "Arithmetic");
flexsearch_extra.add(6, "Mahagoni");
expect(flexsearch_extra.search("tomass")).to.include(4);
expect(flexsearch_extra.search("arytmetik")).to.include(5);
expect(flexsearch_extra.search("mahagony")).to.include(6);
}
});

@@ -352,7 +366,16 @@

expect(flexsearch_reverse.search("yyy").length).to.equal(1);
expect(flexsearch_reverse.search("zzz").length).to.equal(0);
expect(flexsearch_reverse.search("zzz").length).to.equal(1);
expect(flexsearch_reverse.search({query: "xxx", threshold: 2}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "xxx", threshold: 5}).length).to.equal(0);
expect(flexsearch_reverse.search({query: "yyy", threshold: 2}).length).to.equal(0);
expect(flexsearch_reverse.search({query: "zzz", threshold: 0}).length).to.equal(0);
expect(flexsearch_reverse.search({query: "xxx", threshold: 3}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "xxx", threshold: 5}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "xxx", threshold: 7}).length).to.equal(0); // <-- stop
expect(flexsearch_reverse.search({query: "yyy", threshold: 0}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "yyy", threshold: 2}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "yyy", threshold: 5}).length).to.equal(0); // <-- stop
expect(flexsearch_reverse.search({query: "zzz", threshold: 0}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "zzz", threshold: 1}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "zzz", threshold: 3}).length).to.equal(0); // <-- stop
});

@@ -576,5 +599,5 @@ });

encode: false,
encode: 'icase',
mode: 'strict',
async: true,
async: false,
worker: 4

@@ -595,7 +618,9 @@ });

flexsearch_worker.search("foo", function(result){
expect(result).to.have.length(0);
});
setTimeout(function(){
expect(flexsearch_worker.length).to.equal(3);
expect(flexsearch_worker.index).to.have.keys([0, 1, 2]);
done();

@@ -645,3 +670,3 @@

expect(result).to.include(1);
expect(result).to.have.members([1]);
});

@@ -723,3 +748,3 @@

expect(results).to.include(2);
expect(results).to.have.members([2]);
});

@@ -731,3 +756,3 @@

}, 25);
}, 50);
});

@@ -860,2 +885,3 @@ });

expect(flexsearch_depth.search("three five seven")).to.include(0);
expect(flexsearch_depth.search("eight six four")).to.include(0);
// TODO

@@ -933,2 +959,60 @@ // expect(flexsearch_depth.search("three seven five")).to.include(0);

// ------------------------------------------------------------------------
// Relevance Tests
// ------------------------------------------------------------------------
describe('Relevance', function(){
it('Should have been sorted by relevance properly', function(){
var index = new FlexSearch({
encode: 'advanced',
mode: 'strict'
});
index.add(0, "1 2 3 2 4 1 5 3");
index.add(1, "zero one two three four five six seven eight nine ten");
index.add(2, "four two zero one three ten five seven eight six nine");
expect(index.search("1")).to.have.members([0]);
expect(index.search("one")).to.have.members([1, 2]);
expect(index.search("one two")).to.have.members([1, 2]);
expect(index.search("four one")).to.have.members([1, 2]);
var index = new FlexSearch({
encode: 'advanced',
mode: 'strict',
threshold: 5,
depth: 3
});
index.add(0, "1 2 3 2 4 1 5 3");
index.add(1, "zero one two three four five six seven eight nine ten");
index.add(2, "four two zero one three ten five seven eight six nine");
expect(index.search("1")).to.have.members([0]);
expect(index.search("one")).to.have.members([1, 2]);
expect(index.search("one two")).to.have.members([1, 2]);
expect(index.search("four one")).to.have.members([1, 2]);
var index = new FlexSearch({
encode: 'extra',
mode: 'ngram',
threshold: 5,
depth: 3
});
index.add(0, "1 2 3 2 4 1 5 3");
index.add(1, "zero one two three four five six seven eight nine ten");
index.add(2, "five two zero one three four ten seven eight six nine");
expect(index.search("1 3 4")).to.have.members([0]);
expect(index.search("1 5 3 4")).to.have.members([0]);
expect(index.search("one")).to.have.members([1, 2]);
expect(index.search("one three")).to.have.members([1, 2]);
expect(index.search("three one")).to.have.members([1, 2]);
expect(index.search("zero five one ten")).to.have.members([2]);
});
});
// ------------------------------------------------------------------------
// Feature Tests

@@ -978,38 +1062,41 @@ // ------------------------------------------------------------------------

describe('Caching', function(){
if(env !== 'light'){
it('Should have been cached properly', function(){
describe('Caching', function(){
flexsearch_cache.add(0, 'foo')
.add(1, 'bar')
.add(2, 'foobar');
// fetch:
it('Should have been cached properly', function(){
expect(flexsearch_cache.search("foo")).to.have.members([0, 2]);
expect(flexsearch_cache.search("bar")).to.have.members([1, 2]);
expect(flexsearch_cache.search("foobar")).to.include(2);
flexsearch_cache.add(0, 'foo')
.add(1, 'bar')
.add(2, 'foobar');
// fetch:
// cache:
expect(flexsearch_cache.search("foo")).to.have.members([0, 2]);
expect(flexsearch_cache.search("bar")).to.have.members([1, 2]);
expect(flexsearch_cache.search("foobar")).to.include(2);
expect(flexsearch_cache.search("foo")).to.have.members([0, 2]);
expect(flexsearch_cache.search("bar")).to.have.members([1, 2]);
expect(flexsearch_cache.search("foobar")).to.include(2);
// cache:
// update:
expect(flexsearch_cache.search("foo")).to.have.members([0, 2]);
expect(flexsearch_cache.search("bar")).to.have.members([1, 2]);
expect(flexsearch_cache.search("foobar")).to.include(2);
flexsearch_cache.remove(2).update(1, 'foo').add(3, 'foobar');
// update:
// fetch:
flexsearch_cache.remove(2).update(1, 'foo').add(3, 'foobar');
expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]);
expect(flexsearch_cache.search("bar")).to.include(3);
expect(flexsearch_cache.search("foobar")).to.include(3);
// fetch:
// cache:
expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]);
expect(flexsearch_cache.search("bar")).to.include(3);
expect(flexsearch_cache.search("foobar")).to.include(3);
expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]);
expect(flexsearch_cache.search("bar")).to.include(3);
expect(flexsearch_cache.search("foobar")).to.include(3);
// cache:
expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]);
expect(flexsearch_cache.search("bar")).to.include(3);
expect(flexsearch_cache.search("foobar")).to.include(3);
});
});
});
}

@@ -1020,22 +1107,25 @@ // ------------------------------------------------------------------------

describe('Debug', function(){
if(env !== 'light'){
it('Should have been debug mode activated', function(){
describe('Debug', function(){
var info = flexsearch_cache.info();
it('Should have been debug mode activated', function(){
expect(info).to.have.keys([
var info = flexsearch_cache.info();
'id',
'chars',
'status',
'cache',
'items',
'matcher',
'memory',
'sequences',
'worker'
]);
expect(info).to.have.keys([
'id',
'chars',
'status',
'cache',
'items',
'matcher',
'memory',
'sequences',
'worker'
]);
});
});
});
}

@@ -1042,0 +1132,0 @@ // ------------------------------------------------------------------------

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc