flexsearch
Advanced tools
Comparing version 0.2.45 to 0.2.46
/* | ||
FlexSearch v0.2.44 | ||
FlexSearch v0.2.46 | ||
Copyright 2018 Thomas Wilkerling | ||
@@ -7,26 +7,26 @@ Released under the Apache 2.0 Licence | ||
*/ | ||
'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"=== | ||
'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 M(q){function g(a){"string"===typeof a&&(a=F[a]);a||(a=x);this.id=a.id||N++;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); | ||
m;c=f===a.length-1?"":a[f+1];d=m}return b}function O(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 P(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 Q(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function R(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function S(a,b){var d=[],c= | ||
a.length;if(1<c){a.sort(R);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.F||(a.F=H(function(){a.F=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 T(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.H&&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=M.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=[],N=0,C={add:0,update:1,remove:2},J=e("[ -/]"),K={},L={};g.new=function(a){return new this(a)}; | ||
g.create=function(a){return g.new(a)};g.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(A[A.length]=e(b),A[A.length]=a[b]);return this};g.registerEncoder=function(a,b){z[a]=b;return this};g.registerLanguage=function(a,b){K[a]=b.filter;L[a]=b.stemmer;return this};g.encode=function(a,b){return z[a].call(z,b)};g.prototype.init=function(a){this.D=[];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.u=-1;c.m=0;c.g=[];c.A=null;c.i=Array(b);for(var f=0;f<b;f++)c.i[f]=T(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.A&&c.m===c.b&&(c.g.length?c.c="":c.c||(c.c=b),c.cache&&c.j.set(b,c.g),c.A(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.w= | ||
(b=a.encode||d.encode)&&z[b]||("function"===typeof b?b:this.w||!1);this.H=a.debug||this.H;(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.C=O(K[b]||b,this.w);if(b=a.stemmer)this.G=P(L[b]||b,this.w);this.l=[{},{},{},{},{},{},{},{},{},{}];this.o={};this.a={};this.h={};this.f=[];this.F=null;this.c="";this.v=!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.D.length&&(a=y(a,this.D));a&&this.w&&(a=this.w.call(z, | ||
a));if(a&&this.C){a=a.split(" ");for(var b=0;b<a.length;b++){var d=this.C[a[b]];d&&(a[b]=d)}a=a.join(" ")}a&&this.G&&(a=y(a,this.G));return a};g.prototype.addMatcher=function(a){var b=this.D,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.u>=this.i.length&&(this.u=0),this.i[this.u].postMessage(this.u,{add:!0,id:a,content:b}),this.a[a]= | ||
""+this.u,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.v=!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.v=!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.A=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.v)this.cache&&(this.c="",this.j.reset()),this.v=!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(Q);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=S(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.v,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.C=this.G=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.B=!0!==a&&a}a.prototype.reset=function(){this.cache={};this.count={};this.index={};this.keys=[]};a.prototype.set=function(a,d){if(this.B&&"undefined"===typeof this.cache[a]){var b=this.keys.length;if(b===this.B){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.B&&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);this.FlexSearch.registerLanguage("de",{filter:"aber als am an auch auf aus bei bin bis bist da dadurch daher darum das da\u00df dass dein deine dem den der des dessen deshalb die dies dieser dieses doch dort du durch ein eine einem einen einer eines er es euer eure f\u00fcr hatte hatten hattest hattet hier hinter ich ihr ihre im in ist ja jede jedem jeden jeder jedes jener jenes jetzt kann kannst k\u00f6nnen k\u00f6nnt machen mein meine mit mu\u00df mu\u00dft musst m\u00fcssen m\u00fc\u00dft nach nachdem nein nicht nun oder seid sein seine sich sie sind soll sollen sollst sollt sonst soweit sowie und unser unsere unter vom von vor wann warum was weiter weitere wenn wer werde werden werdet weshalb wie wieder wieso wir wird wirst wo woher wohin zu zum zur \u00fcber".split(" "), | ||
stemmer:{niss:"",isch:"",lich:"",heit:"",keit:"",end:"",ung:"",est:"",ern:"",em:"",er:"",en:"",es:"",st:"",ig:"",ik:"",e:"",s:""}}); |
{ | ||
"name": "flexsearch", | ||
"version": "0.2.45", | ||
"version": "0.2.46", | ||
"description": "Next-Generation full text search library with zero dependencies.", | ||
@@ -42,2 +42,3 @@ "homepage": "https://nextapps-de.github.io/xone/", | ||
"flexsearch.min.js", | ||
"lang/", | ||
"test/" | ||
@@ -44,0 +45,0 @@ ], |
122
README.md
@@ -1,2 +0,2 @@ | ||
<p></p> | ||
<p align="center"></p> | ||
<p align="center"> | ||
@@ -14,8 +14,9 @@ <br> | ||
</p> | ||
<h1></h1> | ||
<h3>World's fastest and most memory efficient full text search library with zero dependencies.</h3> | ||
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. | ||
It also has the <a href="#memory">most memory-efficient index</a>. | ||
<!-- | ||
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. | ||
@@ -44,12 +45,10 @@ | ||
<ul> | ||
<li><a href="#webworker">Web-Worker Support</a> (not available in Node.js)</li> | ||
<li><a href="#webworker">Web-Worker Sharding</a> (not available in Node.js)</li> | ||
<li><a href="#contextual">Contextual Indexes</a></li> | ||
<li>Partial Matching</li> | ||
<li>Multiple Words</li> | ||
<li><a href="#phonetic">Phonetic Search</a></li> | ||
<li>Multi-Phrase Search</li> | ||
<li><a href="#phonetic">Phonetic Mathching</a></li> | ||
<li>Relevance-based Scoring</li> | ||
<li>Auto-Balanced Cache by Popularity</li> | ||
<li>Limit Results</li> | ||
<li>Supports Caching</li> | ||
<li>Asynchronous Processing</li> | ||
<li>Asynchronous Processing & Concurrency Control</li> | ||
<li>Customizable: Matcher, Encoder, Tokenizer, Stemmer, Filter</li> | ||
@@ -61,3 +60,3 @@ </ul> | ||
- WebWorker | ||
- Asynchronous | ||
- Asynchronous Processing | ||
- Cache | ||
@@ -69,5 +68,5 @@ - Built-in encoders except 'balance' and 'icase' (you can still pass in customs) | ||
The light version is just available as compiled version (flexsearch.light.js). | ||
The light version is just available as compiled version (<a href="flexsearch.light.js">flexsearch.light.js</a>). | ||
> You can also make <a href="#builds">Custom Builds</a> pretty simple | ||
> It is also pretty simple to make <a href="#builds">Custom Builds</a> | ||
@@ -83,3 +82,3 @@ <a name="contextual"></a> | ||
<p align="center"> | ||
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/contextual_index.svg"> | ||
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/contextual-index.svg"> | ||
</p> | ||
@@ -435,4 +434,75 @@ | ||
``` | ||
<a name="flexsearch.stemmer"></a> | ||
#### Add language-specific stemmer and/or filter | ||
> __Stemmer:__ several linguistic mutations of the same word (e.g. "run" and "running") | ||
> __Filter:__ a blacklist of words to be filtered out from indexing at all (e.g. "and", "to" or "be") | ||
Define a private custom stemmer or filter during creation/initialization: | ||
```js | ||
var index = new FlexSearch({ | ||
stemmer: { | ||
// object {key: replacement} | ||
"ational": "ate", | ||
"tional": "tion", | ||
"enci": "ence", | ||
"ing": "" | ||
}, | ||
filter: [ | ||
// array blacklist | ||
"in", | ||
"into", | ||
"is", | ||
"isn't", | ||
"it", | ||
"it's" | ||
] | ||
}); | ||
``` | ||
Or assign stemmer/filters globally to a language: | ||
```js | ||
FlexSearch.registerLanguage('us', { | ||
stemmer: {/* ... */}, | ||
filter: [/* ... */] | ||
}); | ||
``` | ||
Or use built-in stemmer or filter of your preferred languages: | ||
```html | ||
<html> | ||
<head> | ||
<script src="js/flexsearch.min.js"></script> | ||
<script src="js/lang/en.min.js"></script> | ||
<script src="js/lang/de.min.js"></script> | ||
</head> | ||
... | ||
``` | ||
Now you can assign built-in stemmer during creation/initialization: | ||
```js | ||
var index_en = new FlexSearch({stemmer: 'en', filter: 'en'}); | ||
var index_de = new FlexSearch({stemmer: 'de', filter: [/* custom */]}); | ||
``` | ||
In Node.js you just need require the language pack files to make them available: | ||
```js | ||
require('lang/en.js'); | ||
require('lang/de.js'); | ||
``` | ||
It is also possible to <a href="#builds">compile language packs into the build</a> as follows: | ||
```bash | ||
node compile SUPPORT_LANG_EN=true SUPPORT_LANG_DE=true | ||
``` | ||
<a name="index.info"></a> | ||
#### Get info | ||
#### Get info about an index | ||
@@ -443,7 +513,7 @@ ```js | ||
Returns information about the index, e.g.: | ||
Returns information e.g.: | ||
```json | ||
{ | ||
"bytes": 3600356288, | ||
"bytes": 64000, | ||
"id": 0, | ||
@@ -494,3 +564,3 @@ "matchers": 0, | ||
#### Use WebWorker (Browser only) | ||
#### Use WebWorker Sharding (Browser only) | ||
@@ -647,5 +717,6 @@ Create index and just set the count of parallel threads: | ||
false<br> | ||
{string}<br> | ||
{function} | ||
</td> | ||
<td>Disable or pass in custom object/array.</td> | ||
<td>Disable or pass in language flag (ISO-3166) or a custom object.</td> | ||
</tr> | ||
@@ -657,5 +728,6 @@ <tr></tr> | ||
false<br> | ||
{string}<br> | ||
{function} | ||
</td> | ||
<td>Disable or pass in custom object/array.</td> | ||
<td>Disable or pass in language flag (ISO-3166) or a custom array.</td> | ||
</tr> | ||
@@ -771,3 +843,3 @@ </table> | ||
<a name="compare" id="compare"></a> | ||
#### Comparison (Matches) | ||
#### Comparison (Matching) | ||
@@ -1011,3 +1083,3 @@ > Reference String: __"Björn-Phillipp Mayer"__ | ||
threshold: 5, | ||
depth: 4 | ||
depth: 5 | ||
} | ||
@@ -1065,4 +1137,8 @@ ``` | ||
- SUPPORT_ASYNC | ||
- SUPPORT_BUILTINS (english stemmer and filter) | ||
- SUPPORT_BUILTINS (built-in encoders) | ||
Supported language flags for stemmer and filter: | ||
- SUPPORT_LANG_EN | ||
Alternatively you can also use: | ||
@@ -1069,0 +1145,0 @@ ```bash |
Sorry, the diff of this file is too big to display
1335600
11
3079
1142