flexsearch
Advanced tools
Comparing version 0.1.26 to 0.1.27
@@ -6,3 +6,3 @@ /**! | ||
* @preserve https://github.com/nextapps-de/flexsearch | ||
* @version: 0.1.26 | ||
* @version: 0.1.27 | ||
* @license: Apache 2.0 Licence | ||
@@ -906,3 +906,3 @@ */ | ||
check.concat.apply([], map_check) | ||
[].concat.apply([], map_check) | ||
: | ||
@@ -1261,3 +1261,3 @@ map_check[0] | ||
* @param {!string} value | ||
* @returns {Array<string>} | ||
* @returns {Array<?string>} | ||
*/ | ||
@@ -1267,15 +1267,20 @@ | ||
var parts = []; | ||
if(!value){ | ||
return [value || ""]; | ||
return parts; | ||
} | ||
// perform advanced encoding | ||
value = global_encoder['advanced'](value, /* skip post processing? */ true); | ||
value = global_encoder['advanced'](value); | ||
var parts = []; | ||
var count = 0; | ||
if(!value){ | ||
return parts; | ||
} | ||
var count_vowels = 0, | ||
count_literal = 0; | ||
count_literal = 0, | ||
count_parts = -1; | ||
@@ -1289,3 +1294,2 @@ var tmp = ""; | ||
var char = value[i]; | ||
var char_is_vowel = ( | ||
@@ -1319,13 +1323,13 @@ | ||
if((char === ' ') || ((count_vowels >= 1) && (count_literal >= 1)) || (i === length - 1)){ | ||
if((char === ' ') || ((count_vowels >= 2) && (count_literal >= 2)) || (i === length - 1)){ | ||
if(tmp){ | ||
if((tmp.length > 1) || (last_whitespace === (i - tmp.length))){ | ||
if(tmp.length > 2 || (last_whitespace === (i - tmp.length))){ | ||
parts[count++] = tmp; | ||
parts[++count_parts] = tmp; | ||
} | ||
else{ | ||
else if(parts[count_parts]){ | ||
parts[count] += tmp; | ||
parts[count_parts] += tmp; | ||
} | ||
@@ -1332,0 +1336,0 @@ |
/* | ||
https://github.com/nextapps-de/flexsearch | ||
@version: 0.1.26 | ||
@version: 0.1.27 | ||
@license: Apache 2.0 Licence | ||
*/ | ||
'use strict';(function(p,y,e){var c;(c=e.define)&&c.amd?c([],function(){return y}):(c=e.modules)?c[p.toLowerCase()]=y:"undefined"!==typeof module?module.exports=y:e[p]=y})("FlexSearch",function F(p){function e(a){a||(a=n);this.id=a.id||G++;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 c(a){return new RegExp(a,"g")}function t(a,b,d){if("undefined"===typeof d){for(d=0;d< | ||
'use strict';(function(p,y,e){var c;(c=e.define)&&c.amd?c([],function(){return y}):(c=e.modules)?c[p.toLowerCase()]=y:"undefined"!==typeof module?module.exports=y:e[p]=y})("FlexSearch",function F(p){function e(a){a||(a=m);this.id=a.id||G++;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 c(a){return new RegExp(a,"g")}function t(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,g,c){b[d]||(b[d]="1",b=c.indexOf(d),a=a[3/c.length*(c.length-b)+6/(b-c.lastIndexOf(" ",b))+.5|0],a=a[d]||(a[d]=[]),a[a.length]=g)}function A(a){for(var b="",d="",g="",c=0;c<a.length;c++){var f=a[c];f!==d&&(0<c&&" "!==f&&"h"===f?(g="a"===g||"e"===g||"i"===g||"o"===g||"u"===g||"y"===g,"a"!==d&&"e"!==d&&"i"!==d&&"o"!==d&&"u"!==d&&"y"!==d||!g||(b+=f)):b+=f);g=c===a.length-1?"":a[c+1];d=f}return b}function v(a,b){a= | ||
a.length-b.length;return 0>a?1:0<a?-1:0}function H(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function I(a,b,d){var g=a.length,c=b.length,f=[];if(g&&c)for(var h=0,k=0;k<g;k++)for(var e=a[k],m=0;m<c;m++)if(b[m]===e){f[h++]=e;if(d&&h===d)return f;break}return f}function B(a){a.v||(a.v=C(function(){a.v=null;var b=a.async;b&&(a.async=!1);if(a.c.length){for(var d=D(),g;(g=a.c.shift())||0===g;){var c=a.g[g];switch(c[0]){case z.add:a.add(c[1],c[2]);break;case z.update:a.update(c[1],c[2]);break;case z.remove:a.remove(c[1])}a.g[g]= | ||
a.length-b.length;return 0>a?1:0<a?-1:0}function H(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function I(a,b,d){var g=a.length,c=b.length,f=[];if(g&&c)for(var h=0,k=0;k<g;k++)for(var e=a[k],n=0;n<c;n++)if(b[n]===e){f[h++]=e;if(d&&h===d)return f;break}return f}function B(a){a.v||(a.v=C(function(){a.v=null;var b=a.async;b&&(a.async=!1);if(a.c.length){for(var d=D(),g;(g=a.c.shift())||0===g;){var c=a.g[g];switch(c[0]){case z.add:a.add(c[1],c[2]);break;case z.update:a.update(c[1],c[2]);break;case z.remove:a.remove(c[1])}a.g[g]= | ||
null;delete a.g[g];if(100<D()-d)break}a.c.length&&B(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function D(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}function J(a,b,d,c){a=p("flexsearch","id"+a,function(){var a,b;self.a=function(d){if(d=d.data)b.debug&&console.log("Worker Job Started: "+d.id),d.search?self.postMessage({result:b.search(d.content,d.limit),id:a,content:d.content,limit:d.limit}):d.add?b.add(d.id,d.content):d.update?b.update(d.id,d.content):d.remove? | ||
b.remove(d.id):d.reset?b.reset():d.info?(d=b.info(),d.worker=a,b.debug&&console.log(d)):d.register&&(a=d.id,d.options.cache=!1,d.options.async=!0,d.options.worker=!1,b=(new Function(d.register.substring(d.register.indexOf("{")+1,d.register.lastIndexOf("}"))))(d.options))}},function(a){(a=a.data)&&a.result?c(a.id,a.content,a.result,a.limit):d.debug&&console.log(a)},b);var g=F.toString();d.id=b;a.postMessage(b,{register:g,options:d,id:b});return a}var n={type:"integer",mode:"forward",boolean:!1,cache:!1, | ||
b.remove(d.id):d.reset?b.reset():d.info?(d=b.info(),d.worker=a,b.debug&&console.log(d)):d.register&&(a=d.id,d.options.cache=!1,d.options.async=!0,d.options.worker=!1,b=(new Function(d.register.substring(d.register.indexOf("{")+1,d.register.lastIndexOf("}"))))(d.options))}},function(a){(a=a.data)&&a.result?c(a.id,a.content,a.result,a.limit):d.debug&&console.log(a)},b);var g=F.toString();d.id=b;a.postMessage(b,{register:g,options:d,id:b});return a}var m={type:"integer",mode:"forward",boolean:!1,cache:!1, | ||
async:!1,worker:!1,encode:!1,debug:!0},q=[],G=0,z={add:0,update:1,remove:2},E=c("[ -/]");e.new=function(a){return new this(a)};e.create=function(a){return e.new(a)};e.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(q[q.length]=c(b),q[q.length]=a[b])};e.register=function(a,b){w[a]=b};e.encode=function(a,b){return w[a](b)};e.prototype.init=function(a){this.l=[];if(a){if(a.worker)if("undefined"===typeof Worker)a.worker=!1,this.i=null;else{var b=this,d=parseInt(a.worker,10)||4;b.o=-1;b.m= | ||
0;b.h=[];b.u=null;b.i=Array(d);for(var c=0;c<d;c++)b.i[c]=J(b.id,c,a||n,function(a,d,c,g){b.m!==b.worker&&(b.h=b.h.concat(c),b.m++,g&&b.h.length>=g&&(b.m=b.worker),b.u&&b.m===b.worker&&(b.h.length?b.f="":b.f||(b.f=d),b.cache&&b.j.set(d,b.h),b.u(b.h),b.h=[]))})}this.mode=a.mode||this.mode||n.mode;this.boolean="or"===a["boolean"]||this.boolean||n.boolean;this.cache=a.cache||this.cache||n.cache;this.async=a.async||this.async||n.async;this.worker=a.worker||this.worker||n.worker;this.encoder=a.encode&& | ||
w[a.encode]||this.encoder||n.encode&&w[n.encode]||a.encode;this.debug=a.debug||this.debug||n.debug;a.matcher&&this.addMatcher(a.matcher)}this.b=[{},{},{},{},{},{},{},{},{},{}];this.a={};this.g={};this.c=[];this.v=null;this.f="";this.s=!0;this.j=this.cache?new K(3E4,50,!0):!1};e.prototype.encode=function(a){this.encoder&&(a=this.encoder(a));q.length&&(a=t(a,q));this.l.length&&(a=t(a,this.l));return a};e.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.l[this.l.length]=c(b), | ||
0;b.h=[];b.u=null;b.i=Array(d);for(var c=0;c<d;c++)b.i[c]=J(b.id,c,a||m,function(a,d,c,g){b.m!==b.worker&&(b.h=b.h.concat(c),b.m++,g&&b.h.length>=g&&(b.m=b.worker),b.u&&b.m===b.worker&&(b.h.length?b.f="":b.f||(b.f=d),b.cache&&b.j.set(d,b.h),b.u(b.h),b.h=[]))})}this.mode=a.mode||this.mode||m.mode;this.boolean="or"===a["boolean"]||this.boolean||m.boolean;this.cache=a.cache||this.cache||m.cache;this.async=a.async||this.async||m.async;this.worker=a.worker||this.worker||m.worker;this.encoder=a.encode&& | ||
w[a.encode]||this.encoder||m.encode&&w[m.encode]||a.encode;this.debug=a.debug||this.debug||m.debug;a.matcher&&this.addMatcher(a.matcher)}this.b=[{},{},{},{},{},{},{},{},{},{}];this.a={};this.g={};this.c=[];this.v=null;this.f="";this.s=!0;this.j=this.cache?new K(3E4,50,!0):!1};e.prototype.encode=function(a){this.encoder&&(a=this.encoder(a));q.length&&(a=t(a,q));this.l.length&&(a=t(a,this.l));return a};e.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.l[this.l.length]=c(b), | ||
this.l[this.l.length]=a[b])};e.prototype.add=function(a,b){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else if(this.worker)++this.o>=this.i.length&&(this.o=0),this.i[this.o].postMessage(this.o,{add:!0,id:a,content:b}),this.a[a]=""+this.o;else if(this.async)this.g[a]||(this.c[this.c.length]=a),this.g[a]=[z.add,a,b],B(this);else if(b&&this.encode&&(b=this.encode(b)),b){for(var d={},c=this.encoder===w.ngram?b:b.split(E),e=0;e<c.length;e++){var f=c[e];if(f){var h=f.length;switch(this.mode){case "inverse":case "both":for(var k= | ||
"",l=h-1;1<=l;l--)k=f[l]+k,u(this.b,d,k,a,b);case "forward":k="";for(l=0;l<h;l++)k+=f[l],u(this.b,d,k,a,b);break;case "full":for(l=0;l<h;l++)for(var m=h;m>l;m--)k=f.substring(l,m),u(this.b,d,k,a,b);break;default:u(this.b,d,f,a,b)}}}this.a[a]="1";this.s=!1}};e.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)&&this.a[a])if(this.worker){var d=parseInt(this.a[a],10);this.i[d].postMessage(d,{update:!0,id:a,content:b})}else this.async?(this.g[a]||(this.c[this.c.length]=a),this.g[a]=[z.update, | ||
"",l=h-1;1<=l;l--)k=f[l]+k,u(this.b,d,k,a,b);case "forward":k="";for(l=0;l<h;l++)k+=f[l],u(this.b,d,k,a,b);break;case "full":for(l=0;l<h;l++)for(var n=h;n>l;n--)k=f.substring(l,n),u(this.b,d,k,a,b);break;default:u(this.b,d,f,a,b)}}}this.a[a]="1";this.s=!1}};e.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)&&this.a[a])if(this.worker){var d=parseInt(this.a[a],10);this.i[d].postMessage(d,{update:!0,id:a,content:b})}else this.async?(this.g[a]||(this.c[this.c.length]=a),this.g[a]=[z.update, | ||
a,b],B(this)):(this.remove(a),b&&this.add(a,b))};e.prototype.remove=function(a){if(this.a[a])if(this.worker){var b=parseInt(this.a[a],10);this.i[b].postMessage(b,{remove:!0,id:a});delete this.a[a]}else if(this.async)this.g[a]||(this.c[this.c.length]=a),this.g[a]=[z.remove,a],B(this);else{for(b=0;10>b;b++)for(var d=Object.keys(this.b[b]),c=0;c<d.length;c++){var e=d[c],f=this.b[b];if((f=f&&f[e])&&f.length)for(var h=0;h<f.length;h++)if(f[h]===a){f.splice(h,1);break}f.length||delete this.b[b][e]}delete this.a[a]; | ||
this.s=!1}};e.prototype.search=function(a,b,d){a&&"object"===typeof a&&(d=a.callback||b,b=a.limit,a=a.query);"function"===typeof b?(d=b,b=1E3):b||(b=1E3);if(this.worker){this.u=d;this.m=0;this.h=[];for(var c=0;c<this.worker;c++)this.i[c].postMessage(c,{search:!0,limit:b,content:a});return null}if(d){var e=this;C(function(){d(e.search(a,b));e=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return[];c=a;if(!this.s)this.cache&&(this.f="",this.j.reset()),this.s=!0;else if(this.cache){var f= | ||
this.j.get(a);if(f)return f}else if(this.f&&-1!==a.indexOf(this.f))return[];c&&this.encode&&(c=this.encode(c));if(!c.length)return[];var h=this.encoder===w.ngram?c:c.split(E);c=h.length;1<c&&h.sort(v);var k=[],l=!0;f=[];for(var m={},p=0;p<c;p++){var n=h[p];if(n&&!m[n]){for(var r,t=!1,q=[],x=0,u=9;0<=u;u--)(r=this.b[u][n])&&r.length&&(q[x++]=r,t=!0);if(t)f[f.length]=1<x?f.concat.apply([],q):q[0];else{l=!1;break}m[n]="1"}}if(l&&(c=f.length,1<c&&f.sort(H),x=0,r=f[x++])){for(;r.length&&x<c;)k=f[x++], | ||
this.j.get(a);if(f)return f}else if(this.f&&-1!==a.indexOf(this.f))return[];c&&this.encode&&(c=this.encode(c));if(!c.length)return[];var h=this.encoder===w.ngram?c:c.split(E);c=h.length;1<c&&h.sort(v);var k=[],l=!0;f=[];for(var n={},p=0;p<c;p++){var m=h[p];if(m&&!n[m]){for(var r,t=!1,q=[],x=0,u=9;0<=u;u--)(r=this.b[u][m])&&r.length&&(q[x++]=r,t=!0);if(t)f[f.length]=1<x?[].concat.apply([],q):q[0];else{l=!1;break}n[m]="1"}}if(l&&(c=f.length,1<c&&f.sort(H),x=0,r=f[x++])){for(;r.length&&x<c;)k=f[x++], | ||
r=I(r,k,x===c?b:0);b&&r.length>b&&r.splice(b,r.length-b);k=r}k.length?this.f="":this.f||(this.f=a);this.cache&&this.j.set(a,k);return k};e.prototype.info=function(){if(this.worker)for(var a=0;a<this.worker;a++)this.i[a].postMessage(a,{info:!0,id:this.id});else{for(var b,d,c=0,e=0,f=0,h=0;10>h;h++)for(b=Object.keys(this.b[h]),a=0;a<b.length;a++)d=this.b[h][b[a]].length,c+=d+2*b[a].length+4,e+=d,f+=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:e,chars:f,status:this.s,cache:this.c.length,matchers:q.length}}};e.prototype.reset=function(){this.destroy();this.init()};e.prototype.destroy=function(){this.cache&&this.j.reset();this.j=this.a=this.b=null};var w={icase:function(a){return a.toLowerCase()},simple:function(){var a=[c("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",c("[\u00e8\u00e9\u00ea\u00eb]"),"e",c("[\u00ec\u00ed\u00ee\u00ef]"),"i",c("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",c("[\u00f9\u00fa\u00fb\u00fc\u0171]"), | ||
"u",c("[\u00fd\u0177\u00ff]"),"y",c("\u00f1"),"n",c("\u00e7"),"c",c("\u00df"),"s",c("[-/]")," ",c("[^a-z0-9 ]"),""];return function(b){return t(b.toLowerCase(),a)}}(),advanced:function(){var a=[c("ae"),"a",c("ai"),"ei",c("ay"),"ei",c("ey"),"ei",c("oe"),"o",c("ue"),"u",c("ie"),"i",c("sz"),"s",c("zs"),"s",c("sh"),"s",c("ck"),"k",c("cc"),"k",c("dt"),"t",c("ph"),"f",c("ou"),"o",c("uo"),"u"];return function(b,c){if(!b)return b;b=w.simple(b);2<b.length&&(b=t(b,a));c||1<b.length&&(b=A(b));return b}}(),extra:function(){var a= | ||
[c("p"),"b",c("[sz]"),"c",c("[gq]"),"k",c("[jy]"),"i",c("n"),"m",c("d"),"t",c("[vw]"),"f",c("[aeiouy]"),""];return function(b){if(!b)return b;b=w.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var c=0;c<b.length;c++){var e=b[c];1<e.length&&(b[c]=e[0]+t(e.substring(1),a))}b=b.join("");b=A(b)}return b}}(),ngram:function(a){if(!a)return[a||""];a=w.advanced(a,!0);for(var b=[],c=0,e=0,n=0,f="",h=a.length,k=0,l=0;l<h;l++){var m=a[l];"a"===m||"e"===m||"i"===m||"o"===m||"u"===m||"y"===m?e++:n++;" "!==m? | ||
f+=m:k=l;if(" "===m||1<=e&&1<=n||l===h-1)f&&(1<f.length||k===l-f.length?b[c++]=f:b[c]+=f,f=""),n=e=0}return b}},C=function(){var a={};return function(b,c,e){var d=a[e];d&&clearTimeout(d);return a[e]=setTimeout(b,c)}}(),K=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 e}(function(){var p={},y=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL); | ||
return function(e,c,t,u,A){var v=e;e=y?URL.createObjectURL(new Blob(["("+t.toString()+")()"],{type:"text/javascript"})):"js/worker/"+v+".js";v+="-"+c;p[v]||(p[v]=[]);p[v][A]=new Worker(e);p[v][A].onmessage=u;return{postMessage:function(c,e){p[v][c].postMessage(e)}}}}()),this); | ||
[c("p"),"b",c("[sz]"),"c",c("[gq]"),"k",c("[jy]"),"i",c("n"),"m",c("d"),"t",c("[vw]"),"f",c("[aeiouy]"),""];return function(b){if(!b)return b;b=w.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var c=0;c<b.length;c++){var e=b[c];1<e.length&&(b[c]=e[0]+t(e.substring(1),a))}b=b.join("");b=A(b)}return b}}(),ngram:function(a){var b=[];if(!a)return b;a=w.advanced(a);if(!a)return b;for(var c=0,e=0,m=-1,f="",h=a.length,k=0,l=0;l<h;l++){var n=a[l];"a"===n||"e"===n||"i"===n||"o"===n||"u"===n||"y"===n?c++: | ||
e++;" "!==n?f+=n:k=l;if(" "===n||2<=c&&2<=e||l===h-1)f&&(2<f.length||k===l-f.length?b[++m]=f:b[m]&&(b[m]+=f),f=""),e=c=0}return b}},C=function(){var a={};return function(b,c,e){var d=a[e];d&&clearTimeout(d);return a[e]=setTimeout(b,c)}}(),K=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 e}(function(){var p={},y=!("undefined"===typeof Blob||"undefined"=== | ||
typeof URL||!URL.createObjectURL);return function(e,c,t,u,A){var v=e;e=y?URL.createObjectURL(new Blob(["("+t.toString()+")()"],{type:"text/javascript"})):"js/worker/"+v+".js";v+="-"+c;p[v]||(p[v]=[]);p[v][A]=new Worker(e);p[v][A].onmessage=u;return{postMessage:function(c,e){p[v][c].postMessage(e)}}}}()),this); |
{ | ||
"name": "flexsearch", | ||
"version": "0.1.26", | ||
"version": "0.1.27", | ||
"description": "Superfast, lightweight and memory efficient full text search library.", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -567,9 +567,11 @@ if(typeof module !== 'undefined'){ | ||
flexsearch_ngram.add(0, "björn phillipp mayer"); | ||
flexsearch_ngram.add(0, "björn-phillipp mayer"); | ||
expect(flexsearch_ngram.length).to.equal(1); | ||
expect(flexsearch_ngram.search("bjö phil me")).to.have.lengthOf(1); | ||
expect(flexsearch_ngram.search("bjö phil me")).to.include(0); | ||
expect(flexsearch_ngram.search("mayer")).to.have.lengthOf(1); | ||
expect(flexsearch_ngram.search("philip meier")).to.have.lengthOf(1); | ||
expect(flexsearch_ngram.search("philip meier")).to.include(0); | ||
expect(flexsearch_ngram.search("björn meier")).to.have.lengthOf(1); | ||
expect(flexsearch_ngram.search("björn meier")).to.include(0); | ||
expect(flexsearch_ngram.search("björn-peter mayer")).to.have.lengthOf(0); | ||
}); | ||
@@ -576,0 +578,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108709
1833