bulksearch
Advanced tools
Comparing version 0.1.23 to 0.1.24
@@ -6,3 +6,3 @@ /**! | ||
* @preserve https://github.com/nextapps-de/bulksearch | ||
* @version: 0.1.2 | ||
* @version: 0.1.24 | ||
* @license: Apache 2.0 Licence | ||
@@ -54,2 +54,5 @@ */ | ||
// paginate results | ||
paginate: false, | ||
// default chunk size | ||
@@ -221,2 +224,9 @@ size: 4000, // 600 -> 2500 -> 4000 -> 5000 -> 10000 | ||
this.paginate = ( | ||
options['paginate'] || | ||
this.paginate || | ||
defaults.paginate | ||
); | ||
this.cache = ( | ||
@@ -399,4 +409,7 @@ | ||
this._chunk = ++chunk_index; | ||
if(index){ | ||
this._chunk = ++chunk_index; | ||
} | ||
index = 0; | ||
@@ -573,6 +586,6 @@ bulk[chunk_index] = ""; | ||
/** | ||
* @param {!string} query | ||
* @param {number|Function=} limit | ||
* @param {!string|Object} query | ||
* @param {number|Object|Function=} limit | ||
* @param {Function=} callback | ||
* @returns {Array} | ||
* @returns {Array|Object} | ||
* @this {BulkSearch} | ||
@@ -584,16 +597,99 @@ * @export | ||
if((typeof query !== 'string') || !query){ | ||
var initial_page = 0; | ||
var initial_index = 0; | ||
return []; | ||
if(query && (typeof query === 'object')){ | ||
// re-assign properties | ||
callback = /** @type {?Function} */ (limit); | ||
limit = /** @type {?Object} */ (query); | ||
query = query['query']; | ||
} | ||
else if(typeof limit === 'function'){ | ||
callback = limit; | ||
limit = 1000; | ||
if(limit){ | ||
if(typeof limit === 'function'){ | ||
// re-assign properties | ||
callback = limit; | ||
limit = 1000; | ||
} | ||
else if(typeof limit === 'object'){ | ||
// handle option parameters | ||
if(limit['page']){ | ||
var cmp = limit['page'].split(':'); | ||
initial_page = parseInt(cmp[0], 10); | ||
initial_index = parseInt(cmp[1], 10); | ||
} | ||
if(limit['callback']){ | ||
callback = limit['callback']; | ||
limit['callback'] = false; | ||
} | ||
limit = limit['limit']; | ||
} | ||
} | ||
limit || (limit = 1000); | ||
if(callback){ | ||
/** @type {BulkSearch} */ | ||
var self = this; | ||
if(initial_page || initial_index){ | ||
limit = { | ||
'page': initial_page + ':' + initial_index, | ||
'limit': limit | ||
}; | ||
} | ||
queue(function(){ | ||
callback(self.search(query, limit)); | ||
self = null; | ||
}, 1, 'search-' + this.id); | ||
return null; | ||
} | ||
// create pagination payload | ||
if(this.paginate){ | ||
var page = { | ||
/** @export */ | ||
page: initial_page + ':' + initial_index, | ||
/** @export */ | ||
next: null, | ||
/** @export */ | ||
results: [] | ||
}; | ||
var result = page.results; | ||
} | ||
else{ | ||
limit || (limit = 1000); | ||
var result = []; | ||
} | ||
if(!query || (typeof query !== 'string')){ | ||
return page || result; | ||
} | ||
var _query = query; | ||
@@ -630,20 +726,5 @@ | ||
return []; | ||
return page || result; | ||
} | ||
if(callback){ | ||
/** @type {BulkSearch} */ | ||
var self = this; | ||
queue(function(){ | ||
callback(self.search(query, limit)); | ||
self = null; | ||
}, 1, 'search-' + this.id); | ||
return null; | ||
} | ||
// remove trailing spaces | ||
@@ -665,3 +746,3 @@ | ||
return []; | ||
return page || result; | ||
} | ||
@@ -700,10 +781,10 @@ | ||
var result = []; | ||
for(var z = initial_page; z < this._bulk.length; z++){ | ||
for(var z = 0; z < this._bulk.length; z++){ | ||
var start = 0; | ||
var start = initial_index; | ||
var pos = 0; | ||
var bulk = this._bulk[z]; | ||
initial_index = 0; | ||
while((pos = bulk.indexOf(words[0], start)) !== -1){ | ||
@@ -766,2 +847,8 @@ | ||
// shift pointer (query was done for a specific entry) | ||
pos = max; | ||
// collect results | ||
if(matched){ | ||
@@ -771,6 +858,5 @@ | ||
//sub_bulk = sub_bulk.substring(0, this.depth); | ||
this._scores[current_id] ? this._scores[current_id]++ : this._scores[current_id] = 1; | ||
// enrich result | ||
// TODO enrich results | ||
// result[result.length] = { | ||
@@ -792,6 +878,6 @@ // | ||
} | ||
pos = max; | ||
} | ||
// update pointer (process next entry) | ||
start = pos + 1; | ||
@@ -802,2 +888,7 @@ } | ||
if(page && (z < this._bulk.length) && ((pos + 1) < this._bulk[z].length)){ | ||
page.next = z + ':' + pos; | ||
} | ||
break; | ||
@@ -820,6 +911,6 @@ } | ||
this._cache.set(query, result); | ||
this._cache.set(query, page || result); | ||
} | ||
return result; | ||
return page || result; | ||
}; | ||
@@ -888,3 +979,3 @@ | ||
// assign valid cache | ||
// re-assign valid cache | ||
@@ -896,2 +987,4 @@ if(old_cache){ | ||
// re-assign scores | ||
this._scores = old_scores; | ||
@@ -909,2 +1002,4 @@ }; | ||
var marker_length = Object.keys(this._marker).length; | ||
var fragment_length = Object.keys(this._fragment).length; | ||
var register_length = Object.keys(this._register).length; | ||
var bytes = 0; | ||
@@ -922,12 +1017,4 @@ var length = 0; | ||
bytes = ( | ||
this._index[0].constructor === Array ? | ||
32 | ||
: | ||
this._index[0].byteLength | ||
); | ||
bytes = length * 2 + marker_length * 8 * 3 + this._bulk.length * this._chunk_size * bytes; | ||
bytes = this._index[0].byteLength || (length * 32); | ||
bytes += (length * 2) + ((marker_length + fragment_length + register_length) * 8 * 3); | ||
} | ||
@@ -940,7 +1027,7 @@ | ||
'chunks': this._bulk.length, | ||
'register': Object.keys(this._register).length, | ||
'register': register_length, | ||
'depth': this.depth, | ||
'size': this._chunk_size, | ||
'bytes': bytes, | ||
'fragments': Object.keys(this._fragment).length, | ||
'fragments': fragment_length, | ||
'fragmented': fragmented, | ||
@@ -947,0 +1034,0 @@ 'status': this._status, |
/* | ||
https://github.com/nextapps-de/bulksearch | ||
@version: 0.1.2 | ||
@version: 0.1.24 | ||
@license: Apache 2.0 Licence | ||
*/ | ||
'use strict';(function(m,k,f){var l;(l=f.define)&&l.amd?l([],function(){return k}):(l=f.modules)?l[m.toLowerCase()]=k:"undefined"!==typeof module?module.exports=k:f[m]=k})("BulkSearch",function(m,k){function f(a){this.id=A++;this.init(a||h);Object.defineProperty(this,"index",{get:function(){return this.a}});Object.defineProperty(this,"length",{get:function(){return Object.keys(this.a).length}})}function l(a,b){return new (("int"===a||"integer"===a?Uint32Array:"short"===a?Uint16Array:"float"===a|| | ||
"double"===a?Float64Array:"byte"===a?Uint8Array:Array)||Array)(b)}function c(a){return new RegExp(a,"g")}function t(a,b,e){if("undefined"===typeof e){for(e=0;e<b.length;e+=2)a=a.replace(b[e],b[e+1]);return a}return a.replace(b,e)}function B(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function x(a){for(var b="",e="",d="",g=0;g<a.length;g++){var c=a[g];c!==e&&(0<g&&"h"===c?(d="a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d,"a"!==e&&"e"!==e&&"i"!==e&&"o"!==e&&"u"!==e&&"y"!==e||!d||(b+=c)):b+= | ||
c);d=g===a.length-1?"":a[g+1];e=c}return b}function y(a){var b={},e=a.split(w);a="";for(var d=0;d<e.length;d++){var g=e[d];g&&(this.encode&&(g=this.encode(g)),g&&!b[g]&&(b[g]="1",a+=g))}return a}var h={type:"integer",result:"id",separator:"~",w:!1,u:!1,j:!1,v:!1,cache:!1,encode:!1,size:4E3,depth:0},n=[],A=0;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)&&(n[n.length]=[c(b),a[b]])};f.prototype.init=function(a){a&& | ||
(this.type=a.type||this.type||h.type,this.result=a.result||this.result||h.result,this.separator=a.separator||this.separator||h.separator,this.w=a.strict||this.w||h.w,this.v=a.ordered||this.v||h.v,this.u=a.multi||this.u||h.u,this.j="or"===a["boolean"]||this.j||h.j,this.cache=a.cache||this.cache||h.cache,this.depth=a.depth||this.depth||h.depth,this.h={},this.c=1E4,this.encoder=a.encode&&u[a.encode]||this.encoder||h.encode&&u[h.encode]||a.encode,this.c=a.size||h.size);this.f=[l(this.type,this.c)];this.a= | ||
{};this.i={};this.o={};this.b=[""];this.A=0;this.s=!0;this.l=0;this.g=this.cache?new k(3E4,50,!0):!1};f.prototype.encode=function(a){this.encoder&&(a=this.encoder(a));if(n.length)for(var b=0;b<n.length;b++){var e=n[b];a=a.replace(e[0],e[1])}return a};f.prototype.add=function(a,b,e){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else if("string"===typeof e?b=e:b&&(b=y.call(this,b)),b){var d=this.b;e=this.A;var g=this.i[b.length];if(g&&g.length){this.a[a]=g=g.pop();e=g[0];var c= | ||
g[1];var f=d[e];d[e]=f.substring(0,c)+b+f.substring(g[2]);this.l-=b.length}else c=d[e].length,c+b.length>this.c&&(b.length>this.c/2&&(this.c=2*b.length),this.A=++e,c=0,d[e]="",this.f[e]=l(this.type,this.c)),this.a[a]=g=[e,c,0],d[e]+=b+this.separator;if(this.f[e].constructor===Array)for(d=0;d<b.length;d++)this.f[e][c++]=a;else this.f[e].fill(a,c,c+b.length+1),c+=b.length;g[2]=c;if(this.depth)for(d=this.depth;1<d;d--)a=b.substring(0,d),this.o[a]||(this.o[a]=[]),this.o[a].push(g);this.s=!1}};f.prototype.update= | ||
function(a,b){if("string"===typeof b&&(a||0===a)){var e=this.a[a];if(e){var d=b;b&&(b=y.call(this,b));if(!d||b){var c=e[1],f=e[2],v=f-c,z=b.length-v,h=b;for(0<z&&(b="");b.length<v;)b=(b+" ").substring(0,v);var p=this.b,m=e[0],k=p[m];p[m]=k.substring(0,c)+b+k.substring(f);if(0<z||!d)(b=this.i[v])?b=b.length:(this.i[v]=[],b=0),this.i[v][b]=e,this.l+=v,this.a[a]=null,d&&this.add(a,d,h);this.s=!1}}}};f.prototype.remove=function(a){this.a[a]&&(this.update(a, | ||
""),delete this.a[a],delete this.h[a])};var w=c("[ -/]");f.prototype.search=function(a,b,e){if("string"===typeof a&&a)"function"===typeof b?(e=b,b=1E3):b||(b=1E3);else return[];var d=a;if(!this.s)this.cache&&(this.m="",this.g.reset()),this.s=!0;else if(this.cache){var c=this.g.get(a);if(c)return c}else if(this.m&&-1!==a.indexOf(this.m))return[];if(e){var f=this;m(function(){e(f.search(a,b));f=null},1,"search-"+this.id);return null}for(c=0;" "===a[c];)c++;c&&(d=a.substring(c));if(!d)return[];d=this.u? | ||
d.split(w):[d];c=d.length;1<c&&d.sort(B);var k=Array(c);this.encode&&d[0]&&(d[0]=this.encode(d[0]));for(var h=[],l=0;l<this.b.length;l++){for(var p=0,n=0,u=this.b[l];-1!==(n=u.indexOf(d[0],p));){p=this.f[l][n];var q=this.a[p];if(q){var t=q[1];n=q[2];q=!0;if(1<c){t=u.substring(t,n);for(var r=1;r<c;r++)if(d[r])if(this.encode&&!k[r]&&(d[r]=this.encode(d[r]),k[r]=!0),-1===t.indexOf(d[r]))if(this.j)q=!1;else{q=!1;break}else if(this.j){q=!0;break}}if(q&&(this.h[p]?this.h[p]++:this.h[p]=1,h[h.length]=p, | ||
b&&h.length===b))break}p=n+1}if(b&&h.length===b)break}h.length?this.m="":this.m||(this.m=a);this.cache&&this.g.set(a,h);return h};f.prototype.optimize=function(){var a=this.b,b=this.a,e=this.g,c=this.h;this.reset();var g=Object.keys(b);g.sort(function(a,b){a=(c[b]||0)-(c[a]||0);return 0>a?-1:0<a?1:0});for(var f=0;f<g.length;f++){var h=g[f],k=b[h];k?this.add(h,a[k[0]].substring(k[1],k[2])):delete b[h]}e&&(this.g=e);this.h=c};f.prototype.info=function(){for(var a=this.l,b=Object.keys(this.a).length, | ||
c=0,d=0,f=0;f<this.b.length;f++)d+=this.b[f].length;d&&(a=(100/d*a*100|0)/100,c=this.f[0].constructor===Array?32:this.f[0].byteLength,c=2*d+24*b+this.b.length*this.c*c);return{id:this.id,length:b,chunks:this.b.length,register:Object.keys(this.o).length,depth:this.depth,size:this.c,bytes:c,fragments:Object.keys(this.i).length,fragmented:a,status:this.s,matchers:n.length}};f.prototype.reset=function(){this.destroy();this.init()};f.prototype.destroy=function(){this.cache&&this.g.reset();this.h=this.g= | ||
this.o=this.b=this.i=this.a=this.f=null};var u={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(" "),b=[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(c,d){if(!c)return c;c=u.simple(c);2<c.length&&(c=t(c,b));d||(c=c.replace(a,""),1<c.length&&(c=x(c)));return c}}(),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=u.advanced(b,!0);if(1<b.length){b=b.split(w);for(var c=0;c<b.length;c++){var d=b[c];1<d.length&&(b[c]=d[0]+t(d.substring(1),a))}b=b.join("");b=x(b)}return b}}()};return f}(function(){var m={};return function(k,f,l){var c=m[l];c&&clearTimeout(c);return m[l]=setTimeout(k,f)}}(),function(){function m(){this.cache={}}m.prototype.reset=function(){this.cache={}};m.prototype.set=function(k,f){this.cache[k]=f};m.prototype.get=function(k){return this.cache[k]};return m}()),this); | ||
'use strict';(function(l,q,d){var g;(g=d.define)&&g.amd?g([],function(){return q}):(g=d.modules)?g[l.toLowerCase()]=q:"undefined"!==typeof module?module.exports=q:d[l]=q})("BulkSearch",function(l,q){function d(a){this.id=C++;this.init(a||f);Object.defineProperty(this,"index",{get:function(){return this.a}});Object.defineProperty(this,"length",{get:function(){return Object.keys(this.a).length}})}function g(a,b){return new (("int"===a||"integer"===a?Uint32Array:"short"===a?Uint16Array:"float"===a|| | ||
"double"===a?Float64Array:"byte"===a?Uint8Array:Array)||Array)(b)}function c(a){return new RegExp(a,"g")}function x(a,b,e){if("undefined"===typeof e){for(e=0;e<b.length;e+=2)a=a.replace(b[e],b[e+1]);return a}return a.replace(b,e)}function D(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function z(a){for(var b="",e="",h="",m=0;m<a.length;m++){var c=a[m];c!==e&&(0<m&&"h"===c?(h="a"===h||"e"===h||"i"===h||"o"===h||"u"===h||"y"===h,"a"!==e&&"e"!==e&&"i"!==e&&"o"!==e&&"u"!==e&&"y"!==e||!h||(b+=c)):b+= | ||
c);h=m===a.length-1?"":a[m+1];e=c}return b}function A(a){var b={},e=a.split(y);a="";for(var h=0;h<e.length;h++){var c=e[h];c&&(this.encode&&(c=this.encode(c)),c&&!b[c]&&(b[c]="1",a+=c))}return a}var f={type:"integer",result:"id",separator:"~",A:!1,u:!1,j:!1,w:!1,cache:!1,encode:!1,v:!1,size:4E3,depth:0},r=[],C=0;d.new=function(a){return new this(a)};d.create=function(a){return d.new(a)};d.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(r[r.length]=[c(b),a[b]])};d.prototype.init=function(a){a&& | ||
(this.type=a.type||this.type||f.type,this.result=a.result||this.result||f.result,this.separator=a.separator||this.separator||f.separator,this.A=a.strict||this.A||f.A,this.w=a.ordered||this.w||f.w,this.u=a.multi||this.u||f.u,this.j="or"===a["boolean"]||this.j||f.j,this.v=a.paginate||this.v||f.v,this.cache=a.cache||this.cache||f.cache,this.depth=a.depth||this.depth||f.depth,this.h={},this.f=1E4,this.encoder=a.encode&&t[a.encode]||this.encoder||f.encode&&t[f.encode]||a.encode,this.f=a.size||f.size); | ||
this.g=[g(this.type,this.f)];this.a={};this.i={};this.o={};this.b=[""];this.B=0;this.s=!0;this.l=0;this.c=this.cache?new q(3E4,50,!0):!1};d.prototype.encode=function(a){this.encoder&&(a=this.encoder(a));if(r.length)for(var b=0;b<r.length;b++){var e=r[b];a=a.replace(e[0],e[1])}return a};d.prototype.add=function(a,b,e){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else if("string"===typeof e?b=e:b&&(b=A.call(this,b)),b){var h=this.b;e=this.B;var c=this.i[b.length];if(c&&c.length){this.a[a]= | ||
c=c.pop();e=c[0];var n=c[1];var k=h[e];h[e]=k.substring(0,n)+b+k.substring(c[2]);this.l-=b.length}else n=h[e].length,n+b.length>this.f&&(b.length>this.f/2&&(this.f=2*b.length),n&&(this.B=++e),n=0,h[e]="",this.g[e]=g(this.type,this.f)),this.a[a]=c=[e,n,0],h[e]+=b+this.separator;if(this.g[e].constructor===Array)for(h=0;h<b.length;h++)this.g[e][n++]=a;else this.g[e].fill(a,n,n+b.length+1),n+=b.length;c[2]=n;if(this.depth)for(h=this.depth;1<h;h--)a=b.substring(0,h),this.o[a]||(this.o[a]=[]),this.o[a].push(c); | ||
this.s=!1}};d.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)){var e=this.a[a];if(e){var c=b;b&&(b=A.call(this,b));if(!c||b){var m=e[1],n=e[2],k=n-m,d=b.length-k,p=b;for(0<d&&(b="");b.length<k;)b=(b+" ").substring(0,k);var B=this.b,f=e[0],l=B[f];B[f]=l.substring(0,m)+b+l.substring(n);if(0<d||!c)(b=this.i[k])?b=b.length:(this.i[k]=[],b=0),this.i[k][b]=e,this.l+=k,this.a[a]=null,c&&this.add(a,c,p);this.s=!1}}}};d.prototype.remove=function(a){this.a[a]&& | ||
(this.update(a,""),delete this.a[a],delete this.h[a])};var y=c("[ -/]");d.prototype.search=function(a,b,e){var c=0,m=0;a&&"object"===typeof a&&(e=b,b=a,a=a.query);b&&("function"===typeof b?(e=b,b=1E3):"object"===typeof b&&(b.page&&(m=b.page.split(":"),c=parseInt(m[0],10),m=parseInt(m[1],10)),b.callback&&(e=b.callback,b.callback=!1),b=b.limit));b||(b=1E3);if(e){var n=this;if(c||m)b={page:c+":"+m,limit:b};l(function(){e(n.search(a,b));n=null},1,"search-"+this.id);return null}if(this.v)var k={page:c+ | ||
":"+m,next:null,results:[]},d=k.results;else d=[];if(!a||"string"!==typeof a)return k||d;var p=a;if(!this.s)this.cache&&(this.m="",this.c.reset()),this.s=!0;else if(this.cache){var f=this.c.get(a);if(f)return f}else if(this.m&&-1!==a.indexOf(this.m))return k||d;for(f=0;" "===a[f];)f++;f&&(p=a.substring(f));if(!p)return k||d;p=this.u?p.split(y):[p];f=p.length;1<f&&p.sort(D);var q=Array(f);for(this.encode&&p[0]&&(p[0]=this.encode(p[0]));c<this.b.length;c++){var g=m,w=0,r=this.b[c];for(m=0;-1!==(w=r.indexOf(p[0], | ||
g));){g=this.g[c][w];var u=this.a[g];if(u){var t=u[1];w=u[2];u=!0;if(1<f){t=r.substring(t,w);for(var v=1;v<f;v++)if(p[v])if(this.encode&&!q[v]&&(p[v]=this.encode(p[v]),q[v]=!0),-1===t.indexOf(p[v]))if(this.j)u=!1;else{u=!1;break}else if(this.j){u=!0;break}}if(u&&(this.h[g]?this.h[g]++:this.h[g]=1,d[d.length]=g,b&&d.length===b))break}g=w+1}if(b&&d.length===b){k&&c<this.b.length&&w+1<this.b[c].length&&(k.next=c+":"+w);break}}d.length?this.m="":this.m||(this.m=a);this.cache&&this.c.set(a,k||d);return k|| | ||
d};d.prototype.optimize=function(){var a=this.b,b=this.a,c=this.c,h=this.h;this.reset();var d=Object.keys(b);d.sort(function(a,b){a=(h[b]||0)-(h[a]||0);return 0>a?-1:0<a?1:0});for(var f=0;f<d.length;f++){var k=d[f],g=b[k];g?this.add(k,a[g[0]].substring(g[1],g[2])):delete b[k]}c&&(this.c=c);this.h=h};d.prototype.info=function(){for(var a=this.l,b=Object.keys(this.a).length,c=Object.keys(this.i).length,d=Object.keys(this.o).length,f=0,g=0,k=0;k<this.b.length;k++)g+=this.b[k].length;g&&(a=(100/g*a*100| | ||
0)/100,f=this.g[0].byteLength||32*g,f+=2*g+24*(b+c+d));return{id:this.id,length:b,chunks:this.b.length,register:d,depth:this.depth,size:this.f,bytes:f,fragments:c,fragmented:a,status:this.s,matchers:r.length}};d.prototype.reset=function(){this.destroy();this.init()};d.prototype.destroy=function(){this.cache&&this.c.reset();this.h=this.c=this.o=this.b=this.i=this.a=this.g=null};var t={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 x(b.toLowerCase(),a)}}(),advanced:function(){var a=c(" "),b=[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(c,d){if(!c)return c;c=t.simple(c);2<c.length&&(c=x(c,b));d||(c=c.replace(a,""),1<c.length&&(c=z(c)));return c}}(),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=t.advanced(b,!0);if(1<b.length){b=b.split(y);for(var c=0;c<b.length;c++){var d=b[c];1<d.length&&(b[c]=d[0]+x(d.substring(1),a))}b=b.join("");b=z(b)}return b}}()}; | ||
return d}(function(){var l={};return function(q,d,g){var c=l[g];c&&clearTimeout(c);return l[g]=setTimeout(q,d)}}(),function(){function l(){this.cache={}}l.prototype.reset=function(){this.cache={}};l.prototype.set=function(l,d){this.cache[l]=d};l.prototype.get=function(l){return this.cache[l]};return l}()),this); |
{ | ||
"name": "bulksearch", | ||
"version": "0.1.23", | ||
"version": "0.1.24", | ||
"description": "Superfast, lightweight and read-write optimized full text search library.", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -9,2 +9,3 @@ if(typeof module !== 'undefined'){ | ||
var bulksearch_default; | ||
var bulksearch_pager; | ||
var bulksearch; | ||
@@ -47,4 +48,3 @@ | ||
encode: 'simple', | ||
multi: true, | ||
strict: false | ||
multi: true | ||
}); | ||
@@ -55,4 +55,3 @@ | ||
encode: 'advanced', | ||
multi: true, | ||
strict: false | ||
multi: true | ||
}); | ||
@@ -63,4 +62,3 @@ | ||
encode: 'extra', | ||
multi: true, | ||
strict: false | ||
multi: true | ||
}); | ||
@@ -71,6 +69,11 @@ | ||
encode: test_encoder, | ||
multi: true, | ||
strict: false | ||
multi: true | ||
}); | ||
bulksearch_pager = new BulkSearch({ | ||
paginate: true, | ||
multi: true | ||
}); | ||
expect(bulksearch_default).to.be.an.instanceOf(BulkSearch); | ||
@@ -142,8 +145,8 @@ expect(bulksearch).to.be.an.instanceOf(BulkSearch); | ||
expect(bulksearch.search("foo")).to.have.keys([0, 1]); | ||
expect(bulksearch.search("foo")).to.have.members([0, 1]); | ||
expect(bulksearch.search("bar")).to.include(2); | ||
expect(bulksearch.search("foobar")).to.include(1); | ||
expect(bulksearch.search("foo foo")).to.have.keys([0, 1]); | ||
expect(bulksearch.search("foo foo")).to.have.keys([0, 1]); | ||
expect(bulksearch.search("foo foo")).to.have.members([0, 1]); | ||
expect(bulksearch.search("foo foo")).to.have.members([0, 1]); | ||
}); | ||
@@ -175,4 +178,4 @@ | ||
expect(bulksearch.length).to.equal(3); | ||
expect(bulksearch.search("foo")).to.include(2, 1); | ||
expect(bulksearch.search("bar")).to.include(0, 2); | ||
expect(bulksearch.search("foo")).to.have.members([2, 1]); | ||
expect(bulksearch.search("bar")).to.have.members([0, 2]); | ||
expect(bulksearch.search("foobar")).to.include(2); | ||
@@ -194,4 +197,4 @@ }); | ||
expect(bulksearch.length).to.equal(3); | ||
expect(bulksearch.search("foo")).to.include(2, 1); | ||
expect(bulksearch.search("bar")).to.include(0, 2); | ||
expect(bulksearch.search("foo")).to.have.members([2, 1]); | ||
expect(bulksearch.search("bar")).to.have.members([0, 2]); | ||
expect(bulksearch.search("foobar")).to.include(2); | ||
@@ -230,3 +233,3 @@ }); | ||
expect(result).to.have.keys([0, 1]); | ||
expect(result).to.have.members([0, 1]); | ||
}); | ||
@@ -332,2 +335,57 @@ | ||
// ------------------------------------------------------------------------ | ||
// Pagination | ||
// ------------------------------------------------------------------------ | ||
describe('Pagination', function(){ | ||
it('Should have been paginated properly', function(){ | ||
var query = bulksearch_pager.search("foobar", 2); | ||
expect(query).to.have.keys(['page', 'next', 'results']); | ||
expect(query.results).to.have.lengthOf(0); | ||
expect(query.page).to.equal('0:0'); | ||
expect(query.next).to.equal(null); | ||
bulksearch_pager.add(0, "foobar"); | ||
bulksearch_pager.add(1, "foobar"); | ||
bulksearch_pager.add(2, "foobar"); | ||
bulksearch_pager.add(3, "foobar"); | ||
bulksearch_pager.add(4, "foobar"); | ||
bulksearch_pager.add(5, "foobar"); | ||
query = bulksearch_pager.search("foobar", 2); | ||
expect(query).to.have.keys(['page', 'next', 'results']); | ||
expect(query.results).to.have.lengthOf(2); | ||
expect(query.results).to.have.members([0, 1]); | ||
expect(query.next).not.to.equal(null); | ||
query = bulksearch_pager.search("foobar", {limit: 2}); | ||
expect(query).to.have.keys(['page', 'next', 'results']); | ||
expect(query.results).to.have.lengthOf(2); | ||
expect(query.results).to.have.members([0, 1]); | ||
expect(query.page).to.equal('0:0'); | ||
expect(query.next).not.to.equal(null); | ||
query = bulksearch_pager.search("foobar", {page: query.next, limit: 3}); | ||
expect(query).to.have.keys(['page', 'next', 'results']); | ||
expect(query.results).to.have.lengthOf(3); | ||
expect(query.results).to.have.members([2, 3, 4]); | ||
expect(query.page).not.to.equal('0:0'); | ||
expect(query.next).not.to.equal(null); | ||
query = bulksearch_pager.search("foobar", {page: query.next}); | ||
expect(query).to.have.keys(['page', 'next', 'results']); | ||
expect(query.results).to.have.lengthOf(1); | ||
expect(query.results).to.have.members([5]); | ||
expect(query.page).not.to.equal('0:0'); | ||
expect(query.next).to.equal(null); | ||
}); | ||
}); | ||
// ------------------------------------------------------------------------ | ||
// Phonetic Tests | ||
@@ -334,0 +392,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
91090
1412
699