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

bulksearch

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bulksearch - npm Package Compare versions

Comparing version 0.1.22 to 0.1.23

229

bulksearch.js

@@ -72,19 +72,5 @@ /**!

var chunk_size = 10000;
/**
* @type {number}
* @private
*/
var id_counter = 0;
/**
* @type {Object<string, number>}
* @private
*/
var scores = {};
/**
* @param {Object<string, number|string|boolean>=} options

@@ -248,2 +234,16 @@ * @constructor

/**
* @type {Object<string, number>}
* @private
*/
this._scores = {};
/**
* @type {number}
* @private
*/
this._chunk_size = 10000;
/** @export */

@@ -258,3 +258,3 @@ this.encoder = (

chunk_size = /** @type {number} */ (options['size'] || defaults.size);
this._chunk_size = /** @type {number} */ (options['size'] || defaults.size);
}

@@ -264,3 +264,3 @@

this._index = [create_typed_array(this.type, chunk_size)];
this._index = [create_typed_array(this.type, this._chunk_size)];
this._marker = {};

@@ -310,2 +310,3 @@ this._fragment = {};

* @param {!string} content
* @param {!string=} encoded_content
* @this {BulkSearch}

@@ -315,3 +316,3 @@ * @export

BulkSearch.prototype.add = function(id, content){
BulkSearch.prototype.add = function(id, content, encoded_content){

@@ -328,28 +329,11 @@ if((typeof content === 'string') && content && (id || (id === 0))){

var dupes = {};
var words = content.split(' ');
if(typeof encoded_content === 'string'){
content = "";
content = encoded_content;
}
else{
for(var i = 0; i < words.length; i++){
if(content){
/** @type {string} */
var value = words[i];
if(value){
if(this.encode){
value = this.encode(value);
}
if(value){
if(!dupes[value]){
dupes[value] = "1";
content += value;
}
}
content = encodeContent.call(this, content);
}

@@ -388,11 +372,13 @@ }

marker = this._marker[id] = fragment.pop();
this._marker[id] = marker = fragment.pop();
chunk_index = marker[0];
index = /** @type {number} */ (marker[1]);
var chunk = bulk[marker[0]];
var chunk = bulk[chunk_index];
bulk[marker[0]] = (
bulk[chunk_index] = (
chunk.substring(0, index) +
content +
content + //this.separator +
chunk.substring(marker[2])

@@ -409,9 +395,11 @@ );

if((index + content.length) > chunk_size){
if((index + content.length) > this._chunk_size){
if(index < (chunk_size / 2)){
if(content.length > (this._chunk_size / 2)){
chunk_size *= 2;
this._chunk_size = content.length * 2;
}
// init new chunk
this._chunk = ++chunk_index;

@@ -421,11 +409,10 @@

bulk[chunk_index] = "";
this._index[chunk_index] = create_typed_array(this.type, chunk_size);
this._index[chunk_index] = create_typed_array(this.type, this._chunk_size);
}
// 32 bytes per marker --> Uint16Array = 8 bytes per marker
marker = this._marker[id] = [
this._marker[id] = marker = [
chunk_index,
index,
0,
0

@@ -446,4 +433,2 @@ ];

console.log(this._index[chunk_index].fill);
this._index[chunk_index].fill(id, index, index + content.length + 1);

@@ -491,7 +476,14 @@

if(content && this.encode){
var old_content = content;
content = this.encode(content);
if(content){
content = encodeContent.call(this, content);
}
if(old_content && !content){
return;
}
var min = marker[1];

@@ -501,3 +493,3 @@ var max = marker[2];

var overlap = content.length - old_length;
var old_content = content;
var encoded_content = content;

@@ -560,3 +552,3 @@ if(overlap > 0){

this.add(id, old_content);
this.add(id, old_content, encoded_content);
}

@@ -579,8 +571,12 @@ }

this.update(id, '');
if(this._marker[id]){
delete this._marker[id];
this.update(id, '');
delete this._marker[id];
delete this._scores[id];
}
};
var regex_split = regex("[ -/]");
var regex_split = regex("[ -\/]");

@@ -639,3 +635,3 @@ /**

// validate last input
// validate last query

@@ -705,3 +701,3 @@ else if(this._last_empty_query && (query.indexOf(this._last_empty_query) !== -1)){

if(this.encode){
if(this.encode && words[0]){

@@ -731,3 +727,2 @@ words[0] = this.encode(words[0]);

var matched = true;
var sub_bulk;

@@ -738,15 +733,15 @@ // check multiple word components

sub_bulk = bulk.substring(min, max);
var sub_bulk = bulk.substring(min, max);
for(var i = 1; i < length; i++){
// encode query
if(words[i]){
if(this.encode && !encoded[i]){
// encode query
words[i] = this.encode(words[i]);
encoded[i] = true;
}
if(this.encode && !encoded[i]){
if(words[i]){
words[i] = this.encode(words[i]);
encoded[i] = true;
}

@@ -785,5 +780,4 @@ if(sub_bulk.indexOf(words[i]) === -1){

sub_bulk || (sub_bulk = bulk.substring(min, max));
sub_bulk = sub_bulk.substring(0, this.depth);
scores[sub_bulk] ? scores[sub_bulk]++ : scores[sub_bulk] = 1;
//sub_bulk = sub_bulk.substring(0, this.depth);
this._scores[current_id] ? this._scores[current_id]++ : this._scores[current_id] = 1;

@@ -849,3 +843,3 @@ // enrich result

var old_cache = this._cache;
var old_register = this._register;
var old_scores = this._scores;

@@ -858,28 +852,25 @@ // reset index

// var score_keys = Object.keys(/** @type {!Object} */ (scores));
// var register_keys = Object.keys(old_register);
var marker_keys = Object.keys(old_marker);
// re-add contents
// sort keys by score
// for(var i = 0; i < score_keys.length; i++){
//
// var key = score_keys[i];
// var score = scores[key];
//
// if(score){
//
// for(var a = 0; a < register_keys.length; a++){
//
// if(score_keys[i] === register_keys[a]){
//
//
// }
// }
// }
// }
marker_keys.sort(function(a, b){
// get ids
var sum = (old_scores[b] || 0) - (old_scores[a] || 0);
var marker_keys = Object.keys(old_marker);
return (
sum < 0 ?
-1
:(
sum > 0 ?
1
:
0
)
);
});
// re-add contents

@@ -911,2 +902,4 @@

}
this._scores = old_scores;
};

@@ -944,3 +937,3 @@

bytes = length * 2 + marker_length * 8 * 3 + this._bulk.length * chunk_size * bytes;
bytes = length * 2 + marker_length * 8 * 3 + this._bulk.length * this._chunk_size * bytes;
}

@@ -955,3 +948,3 @@

'depth': this.depth,
'size': chunk_size,
'size': this._chunk_size,
'bytes': bytes,

@@ -1003,2 +996,3 @@ 'fragments': Object.keys(this._fragment).length,

this._cache = null;
this._scores = null;
};

@@ -1176,3 +1170,3 @@

str = str.split(" ");
str = str.split(regex_split);

@@ -1369,2 +1363,41 @@ for(var i = 0; i < str.length; i++){

}
/**
* @param {!string} content
* @this {BulkSearch}
* @returns {string}
*/
function encodeContent(content){
var dupes = {};
var words = content.split(regex_split);
content = "";
for(var i = 0; i < words.length; i++){
var value = words[i];
if(value){
if(this.encode){
value = this.encode(value);
}
if(value){
if(!dupes[value]){
dupes[value] = "1";
content += value;
}
}
}
}
return content;
}
})(

@@ -1437,4 +1470,2 @@ // Xone Async Handler Fallback

root || (root = this);
var prop;

@@ -1441,0 +1472,0 @@

@@ -6,15 +6,15 @@ /*

*/
'use strict';(function(m,g,d){d||(d=this);var h;(h=d.define)&&h.amd?h([],function(){return g}):(h=d.modules)?h[m.toLowerCase()]=g:"undefined"!==typeof module?module.exports=g:d[m]=g})("BulkSearch",function(m,g){function d(b){this.id=z++;this.init(b||l);Object.defineProperty(this,"index",{get:function(){return this.a}});Object.defineProperty(this,"length",{get:function(){return Object.keys(this.a).length}})}function h(b,c){return new (("int"===b||"integer"===b?Uint32Array:"short"===b?Uint16Array:"float"===
b||"double"===b?Float64Array:"byte"===b?Uint8Array:Array)||Array)(c)}function a(b){return new RegExp(b,"g")}function w(b,c,f){if("undefined"===typeof f){for(f=0;f<c.length;f+=2)b=b.replace(c[f],c[f+1]);return b}return b.replace(c,f)}function A(b,c){b=b.length-c.length;return 0>b?1:0<b?-1:0}function y(b){for(var c="",f="",k="",e=0;e<b.length;e++){var a=b[e];a!==f&&(0<e&&"h"===a?(k="a"===k||"e"===k||"i"===k||"o"===k||"u"===k||"y"===k,"a"!==f&&"e"!==f&&"i"!==f&&"o"!==f&&"u"!==f&&"y"!==f||!k||(c+=a)):
c+=a);k=e===b.length-1?"":b[e+1];f=a}return c}var l={type:"integer",result:"id",separator:"~",u:!1,o:!1,h:!1,s:!1,cache:!1,encode:!1,size:4E3,depth:0},p=[],n=1E4,z=0,x={};d.new=function(b){return new this(b)};d.create=function(b){return d.new(b)};d.addMatcher=function(b){for(var c in b)b.hasOwnProperty(c)&&(p[p.length]=[a(c),b[c]])};d.prototype.init=function(b){b&&(this.type=b.type||this.type||l.type,this.result=b.result||this.result||l.result,this.separator=b.separator||this.separator||l.separator,
this.u=b.strict||this.u||l.u,this.s=b.ordered||this.s||l.s,this.o=b.multi||this.o||l.o,this.h="or"===b["boolean"]||this.h||l.h,this.cache=b.cache||this.cache||l.cache,this.depth=b.depth||this.depth||l.depth,this.encoder=b.encode&&r[b.encode]||this.encoder||l.encode&&r[l.encode]||b.encode,n=b.size||l.size);this.c=[h(this.type,n)];this.a={};this.g={};this.l={};this.b=[""];this.v=0;this.m=!0;this.i=0;this.f=this.cache?new g(3E4,50,!0):!1};d.prototype.encode=function(b){this.encoder&&(b=this.encoder(b));
if(p.length)for(var c=0;c<p.length;c++){var f=p[c];b=b.replace(f[0],f[1])}return b};d.prototype.add=function(b,c){if("string"===typeof c&&c&&(b||0===b))if(this.a[b])this.update(b,c);else{var f={},k=c.split(" ");c="";for(var e=0;e<k.length;e++){var a=k[e];a&&(this.encode&&(a=this.encode(a)),a&&!f[a]&&(f[a]="1",c+=a))}if(c){e=this.b;f=this.v;if((k=this.g[c.length])&&k.length){k=this.a[b]=k.pop();a=k[1];var d=e[k[0]];e[k[0]]=d.substring(0,a)+c+d.substring(k[2]);this.i-=c.length}else a=e[f].length,a+
c.length>n&&(a<n/2&&(n*=2),this.v=++f,a=0,e[f]="",this.c[f]=h(this.type,n)),k=this.a[b]=[f,a,0,0],e[f]+=c+this.separator;if(this.c[f].constructor===Array)for(e=0;e<c.length;e++)this.c[f][a++]=b;else console.log(this.c[f].fill),this.c[f].fill(b,a,a+c.length+1),a+=c.length;k[2]=a;if(this.depth)for(e=this.depth;1<e;e--)b=c.substring(0,e),this.l[b]||(this.l[b]=[]),this.l[b].push(k);this.m=!1}}};d.prototype.update=function(b,c){if("string"===typeof c&&(b||0===b)){var f=this.a[b];if(f){c&&this.encode&&
(c=this.encode(c));var a=f[1],e=f[2],d=e-a,l=c.length-d,m=c;for(0<l&&(c="");c.length<d;)c=(c+" ").substring(0,d);var g=this.b,h=f[0],q=g[h];g[h]=q.substring(0,a)+c+q.substring(e);if(0<l||!m)(c=this.g[d])?c=c.length:(this.g[d]=[],c=0),this.g[d][c]=f,this.i+=d,this.a[b]=null,m&&this.add(b,m);this.m=!1}}};d.prototype.remove=function(b){this.update(b,"");delete this.a[b]};var B=a("[ -/]");d.prototype.search=function(b,c,f){if("string"===typeof b&&b)"function"===
typeof c?(f=c,c=1E3):c||(c=1E3);else return[];var a=b;if(!this.m)this.cache&&(this.j="",this.f.reset()),this.m=!0;else if(this.cache){var e=this.f.get(b);if(e)return e}else if(this.j&&-1!==b.indexOf(this.j))return[];if(f){var d=this;m(function(){f(d.search(b,c));d=null},1,"search-"+this.id);return null}for(e=0;" "===b[e];)e++;e&&(a=b.substring(e));if(!a)return[];a=this.o?a.split(B):[a];e=a.length;1<e&&a.sort(A);var l=Array(e);this.encode&&(a[0]=this.encode(a[0]));for(var g=[],h=0;h<this.b.length;h++){for(var n=
0,q=0,p=this.b[h];-1!==(q=p.indexOf(a[0],n));){n=this.c[h][q];var v=this.a[n];if(v){q=v[1];v=v[2];var r=!0;if(1<e){var t=p.substring(q,v);for(var u=1;u<e;u++)if(this.encode&&!l[u]&&(a[u]=this.encode(a[u]),l[u]=!0),a[u])if(-1===t.indexOf(a[u]))if(this.h)r=!1;else{r=!1;break}else if(this.h){r=!0;break}}if(r&&(t||(t=p.substring(q,v)),t=t.substring(0,this.depth),x[t]?x[t]++:x[t]=1,g[g.length]=n,c&&g.length===c))break;q=v}n=q+1}if(c&&g.length===c)break}g.length?this.j="":this.j||(this.j=b);this.cache&&
this.f.set(b,g);return g};d.prototype.optimize=function(){var b=this.b,c=this.a,a=this.f;this.reset();for(var d=Object.keys(c),e=0;e<d.length;e++){var g=d[e],h=c[g];h?this.add(g,b[h[0]].substring(h[1],h[2])):delete c[g]}a&&(this.f=a)};d.prototype.info=function(){for(var b=this.i,c=Object.keys(this.a).length,a=0,d=0,e=0;e<this.b.length;e++)d+=this.b[e].length;d&&(b=(100/d*b*100|0)/100,a=this.c[0].constructor===Array?32:this.c[0].byteLength,a=2*d+24*c+this.b.length*n*a);return{id:this.id,length:c,chunks:this.b.length,
register:Object.keys(this.l).length,depth:this.depth,size:n,bytes:a,fragments:Object.keys(this.g).length,fragmented:b,status:this.m,matchers:p.length}};d.prototype.reset=function(){this.destroy();this.init()};d.prototype.destroy=function(){this.cache&&this.f.reset();this.f=this.l=this.b=this.g=this.a=this.c=null};var r={icase:function(b){return b.toLowerCase()},simple:function(){var b=[a("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",a("[\u00e8\u00e9\u00ea\u00eb]"),"e",a("[\u00ec\u00ed\u00ee\u00ef]"),
"i",a("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",a("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",a("[\u00fd\u0177\u00ff]"),"y",a("\u00f1"),"n",a("\u00e7"),"c",a("\u00df"),"s",a("[-/]")," ",a("[^a-z0-9 ]"),""];return function(a){return w(a.toLowerCase(),b)}}(),advanced:function(){var b=a(" "),c=[a("ae"),"a",a("ai"),"ei",a("ay"),"ei",a("ey"),"ei",a("oe"),"o",a("ue"),"u",a("ie"),"i",a("sz"),"s",a("zs"),"s",a("sh"),"s",a("ck"),"k",a("cc"),"k",a("dt"),"t",a("ph"),"f",a("ou"),"o",a("uo"),"u"];return function(a,
d){if(!a)return a;a=r.simple(a);2<a.length&&(a=w(a,c));d||(a=a.replace(b,""),1<a.length&&(a=y(a)));return a}}(),extra:function(){var b=[a("p"),"b",a("[sz]"),"c",a("[gq]"),"k",a("[jy]"),"i",a("n"),"m",a("d"),"t",a("[vw]"),"f",a("[aeiouy]"),""];return function(a){if(!a)return a;a=r.advanced(a,!0);if(1<a.length){a=a.split(" ");for(var c=0;c<a.length;c++){var d=a[c];1<d.length&&(a[c]=d[0]+w(d.substring(1),b))}a=a.join("");a=y(a)}return a}}()};return d}(function(){var m={};return function(g,d,h){var a=
m[h];a&&clearTimeout(a);return m[h]=setTimeout(g,d)}}(),function(){function m(){this.cache={}}m.prototype.reset=function(){this.cache={}};m.prototype.set=function(g,d){this.cache[g]=d};m.prototype.get=function(g){return this.cache[g]};return m}()),this);
'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);
{
"name": "bulksearch",
"version": "0.1.22",
"version": "0.1.23",
"description": "Superfast, lightweight and read-write optimized full text search library.",

@@ -5,0 +5,0 @@ "keywords": [],

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

var bulksearch_default;
var bulksearch_sync;
var bulksearch;

@@ -28,4 +28,6 @@ var bulksearch_icase;

bulksearch_sync = new BulkSearch({
bulksearch = new BulkSearch({
type: 'short',
size: 7,
encode: false,

@@ -72,3 +74,3 @@ multi: true,

expect(bulksearch_default).to.be.an.instanceOf(BulkSearch);
expect(bulksearch_sync).to.be.an.instanceOf(BulkSearch);
expect(bulksearch).to.be.an.instanceOf(BulkSearch);
});

@@ -90,3 +92,3 @@

expect(bulksearch_default.id).to.equal(0);
expect(bulksearch_sync.id).to.equal(1);
expect(bulksearch.id).to.equal(1);
expect(bulksearch_icase.id).to.equal(2);

@@ -101,3 +103,3 @@ expect(bulksearch_simple.id).to.equal(3);

expect(bulksearch_default.type).to.equal('integer');
expect(bulksearch_sync.type).to.equal('integer');
expect(bulksearch.type).to.equal('short');
expect(bulksearch_custom.encoder).to.equal(test_encoder);

@@ -111,8 +113,8 @@ });

bulksearch_sync.add(0, "foo");
bulksearch_sync.add(2, "bar");
bulksearch_sync.add(1, "foobar");
bulksearch.add(0, "foo");
bulksearch.add(2, "bar");
bulksearch.add(1, "foobar");
expect(bulksearch_sync.length).to.equal(3);
expect(bulksearch_sync.index).to.have.keys([0, 1, 2]);
expect(bulksearch.length).to.equal(3);
expect(bulksearch.index).to.have.keys([0, 1, 2]);
});

@@ -122,14 +124,14 @@

bulksearch_sync.add("foo");
bulksearch_sync.add(3);
bulksearch_sync.add(null, "foobar");
bulksearch_sync.add(void 0, "foobar");
bulksearch_sync.add(3, null);
bulksearch_sync.add(3, false);
bulksearch_sync.add(3, []);
bulksearch_sync.add(3, {});
bulksearch_sync.add(3, function(){});
bulksearch.add("foo");
bulksearch.add(3);
bulksearch.add(null, "foobar");
bulksearch.add(void 0, "foobar");
bulksearch.add(3, null);
bulksearch.add(3, false);
bulksearch.add(3, []);
bulksearch.add(3, {});
bulksearch.add(3, function(){});
expect(bulksearch_sync.length).to.equal(3);
expect(bulksearch_sync.index).to.have.keys([0, 1, 2]);
expect(bulksearch.length).to.equal(3);
expect(bulksearch.index).to.have.keys([0, 1, 2]);
});

@@ -142,8 +144,8 @@ });

expect(bulksearch_sync.search("foo")).to.have.keys([0, 1]);
expect(bulksearch_sync.search("bar")).to.include(2);
expect(bulksearch_sync.search("foobar")).to.include(1);
expect(bulksearch.search("foo")).to.have.keys([0, 1]);
expect(bulksearch.search("bar")).to.include(2);
expect(bulksearch.search("foobar")).to.include(1);
expect(bulksearch_sync.search("foo foo")).to.have.keys([0, 1]);
expect(bulksearch_sync.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.keys([0, 1]);
});

@@ -153,4 +155,4 @@

expect(bulksearch_sync.search("foo", 1)).to.include(0);
expect(bulksearch_sync.search("foo", 1)).to.not.include(1);
expect(bulksearch.search("foo", 1)).to.include(0);
expect(bulksearch.search("foo", 1)).to.not.include(1);
});

@@ -160,6 +162,6 @@

expect(bulksearch_sync.search("barfoo")).to.have.lengthOf(0);
expect(bulksearch_sync.search("")).to.have.lengthOf(0);
expect(bulksearch_sync.search(" ")).to.have.lengthOf(0);
expect(bulksearch_sync.search(" o ")).to.have.lengthOf(2);
expect(bulksearch.search("barfoo")).to.have.lengthOf(0);
expect(bulksearch.search("")).to.have.lengthOf(0);
expect(bulksearch.search(" ")).to.have.lengthOf(0);
expect(bulksearch.search(" o ")).to.have.lengthOf(2);
});

@@ -172,10 +174,10 @@ });

bulksearch_sync.update(0, "bar");
bulksearch_sync.update(2, "foobar");
bulksearch_sync.update(1, "foo");
bulksearch.update(0, "bar");
bulksearch.update(2, "foobar");
bulksearch.update(1, "foo");
expect(bulksearch_sync.length).to.equal(3);
expect(bulksearch_sync.search("foo")).to.include(2, 1);
expect(bulksearch_sync.search("bar")).to.include(0, 2);
expect(bulksearch_sync.search("foobar")).to.include(2);
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("foobar")).to.include(2);
});

@@ -185,16 +187,16 @@

bulksearch_sync.update("foo");
bulksearch_sync.update(0);
bulksearch_sync.update(null, "foobar");
bulksearch_sync.update(void 0, "foobar");
bulksearch_sync.update(1, null);
bulksearch_sync.update(2, false);
bulksearch_sync.update(0, []);
bulksearch_sync.update(1, {});
bulksearch_sync.update(2, function(){});
bulksearch.update("foo");
bulksearch.update(0);
bulksearch.update(null, "foobar");
bulksearch.update(void 0, "foobar");
bulksearch.update(1, null);
bulksearch.update(2, false);
bulksearch.update(0, []);
bulksearch.update(1, {});
bulksearch.update(2, function(){});
expect(bulksearch_sync.length).to.equal(3);
expect(bulksearch_sync.search("foo")).to.include(2, 1);
expect(bulksearch_sync.search("bar")).to.include(0, 2);
expect(bulksearch_sync.search("foobar")).to.include(2);
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("foobar")).to.include(2);
});

@@ -207,10 +209,10 @@ });

bulksearch_sync.remove(0);
bulksearch_sync.remove(2);
bulksearch_sync.remove(1);
bulksearch.remove(0);
bulksearch.remove(2);
bulksearch.remove(1);
expect(bulksearch_sync.length).to.equal(0);
expect(bulksearch_sync.search("foo")).to.have.lengthOf(0);
expect(bulksearch_sync.search("bar")).to.have.lengthOf(0);
expect(bulksearch_sync.search("foobar")).to.have.lengthOf(0);
expect(bulksearch.length).to.equal(0);
expect(bulksearch.search("foo")).to.have.lengthOf(0);
expect(bulksearch.search("bar")).to.have.lengthOf(0);
expect(bulksearch.search("foobar")).to.have.lengthOf(0);
});

@@ -227,7 +229,7 @@ });

bulksearch_sync.add(0, "foo");
bulksearch_sync.add(2, "bar");
bulksearch_sync.add(1, "foobar");
bulksearch.add(0, "foo");
bulksearch.add(2, "bar");
bulksearch.add(1, "foobar");
bulksearch_sync.search("foo", function(result){
bulksearch.search("foo", function(result){

@@ -237,3 +239,3 @@ expect(result).to.have.keys([0, 1]);

bulksearch_sync.search("bar", function(result){
bulksearch.search("bar", function(result){

@@ -243,3 +245,3 @@ expect(result).to.include(2);

bulksearch_sync.search("foobar", function(result){
bulksearch.search("foobar", function(result){

@@ -258,6 +260,6 @@ expect(result).to.include(1);

bulksearch_sync.search("foo", 1, function(result){
bulksearch.search("foo", 1, function(result){
expect(result).to.include(0);
expect(result).to.not.include(1);
expect(result).to.not.include(2);
});

@@ -274,3 +276,3 @@

bulksearch_sync.search("barfoo", function(result){
bulksearch.search("barfoo", function(result){

@@ -280,3 +282,3 @@ expect(result).to.have.lengthOf(0);

bulksearch_sync.search("", function(result){
bulksearch.search("", function(result){

@@ -286,3 +288,3 @@ expect(result).to.have.lengthOf(0);

bulksearch_sync.search(" ", function(result){
bulksearch.search(" ", function(result){

@@ -292,3 +294,3 @@ expect(result).to.have.lengthOf(0);

bulksearch_sync.search(" o ", function(result){
bulksearch.search(" o ", function(result){

@@ -307,2 +309,37 @@ expect(result).to.have.lengthOf(2);

// ------------------------------------------------------------------------
// Fragmentation + Optimize
// ------------------------------------------------------------------------
describe('Optimize', function(){
it('Should have been fragmented', function(){
bulksearch.update(0, "foobar foobar foobar");
bulksearch.update(1, "foobar foobar foobar");
bulksearch.update(2, "foobar foobar foobar");
bulksearch.update(0, "foobar foobar foobar foobar foobar foobar");
bulksearch.update(1, "foobar foobar foobar foobar foobar foobar");
bulksearch.update(2, "foobar foobar foobar foobar foobar foobar");
expect(bulksearch.search("foobar foobar foobar foobar foobar foobar")).to.have.lengthOf(3);
expect(bulksearch.search("foobar")).to.have.lengthOf(3);
expect(bulksearch.search(" f b ")).to.have.lengthOf(3);
});
it('Should have been optimized properly', function(){
bulksearch.search("foobar");
bulksearch.search("foobar");
bulksearch.search("foobar");
bulksearch.search("foobar");
bulksearch.optimize();
expect(bulksearch.search("foobar")).to.have.lengthOf(3);
expect(bulksearch.search(" f b ")).to.have.lengthOf(3);
});
});
// ------------------------------------------------------------------------
// Phonetic Tests

@@ -309,0 +346,0 @@ // ------------------------------------------------------------------------

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