flexsearch
Advanced tools
Comparing version 0.1.22 to 0.1.23
/**! | ||
* FlexSearch - Superfast lightweight full text search engine | ||
* ---------------------------------------------------------- | ||
* https://github.com/nextapps-de/flexsearch | ||
* @preserve https://github.com/nextapps-de/flexsearch | ||
* @version: 0.1.2 | ||
@@ -10,5 +10,5 @@ * @author: Thomas Wilkerling | ||
(function(){ | ||
;(function(){ | ||
register('FlexSearch', (function factory(register_worker){ | ||
provide('FlexSearch', (function factory(register_worker){ | ||
@@ -18,3 +18,3 @@ "use strict"; | ||
/** | ||
* @enum {number|string|boolean} | ||
* @struct | ||
* @private | ||
@@ -93,2 +93,3 @@ * @const | ||
/** @export */ | ||
this.id = options['id'] || id_counter++; | ||
@@ -99,2 +100,28 @@ | ||
this.init(options); | ||
// define functional properties | ||
Object.defineProperty(this, 'index', { | ||
/** | ||
* @this {FlexSearch} | ||
*/ | ||
get: function(){ | ||
return this._ids; | ||
} | ||
}); | ||
Object.defineProperty(this, 'length', { | ||
/** | ||
* @this {FlexSearch} | ||
*/ | ||
get: function(){ | ||
return Object.keys(this._ids).length; | ||
} | ||
}); | ||
} | ||
@@ -104,2 +131,3 @@ | ||
* @param {Object<string, number|string|boolean>=} options | ||
* @export | ||
*/ | ||
@@ -109,2 +137,12 @@ | ||
return FlexSearch.new(options); | ||
}; | ||
/** | ||
* @param {Object<string, number|string|boolean>=} options | ||
* @export | ||
*/ | ||
FlexSearch.new = function(options){ | ||
return new this(options); | ||
@@ -115,2 +153,3 @@ }; | ||
* @param {Object<string, string>} matcher | ||
* @export | ||
*/ | ||
@@ -148,2 +187,3 @@ | ||
options['worker'] = false; | ||
this._worker = null; | ||
} | ||
@@ -153,3 +193,3 @@ else{ | ||
var self = this; | ||
var threads = options['threads'] || defaults['threads']; | ||
var threads = options['threads'] || defaults.threads; | ||
@@ -207,2 +247,3 @@ self._current_task = -1; | ||
/** @export */ | ||
this.mode = ( | ||
@@ -215,2 +256,3 @@ | ||
/** @export */ | ||
this.boolean = ( | ||
@@ -223,2 +265,3 @@ | ||
/** @export */ | ||
this.cache = ( | ||
@@ -231,2 +274,3 @@ | ||
/** @export */ | ||
this.async = ( | ||
@@ -239,2 +283,3 @@ | ||
/** @export */ | ||
this.worker = ( | ||
@@ -247,2 +292,3 @@ | ||
/** @export */ | ||
this.threads = ( | ||
@@ -255,2 +301,3 @@ | ||
/** @export */ | ||
this.encoder = ( | ||
@@ -264,2 +311,3 @@ | ||
/** @export */ | ||
this.debug = ( | ||
@@ -306,3 +354,4 @@ | ||
* @param {!string} value | ||
* @returns {*} | ||
* @returns {string} | ||
* @export | ||
*/ | ||
@@ -333,2 +382,3 @@ | ||
* @param {!string} content | ||
* @this {FlexSearch} | ||
* @export | ||
@@ -389,2 +439,3 @@ */ | ||
/** @type {string} */ | ||
var value = words[i]; | ||
@@ -412,3 +463,3 @@ | ||
addIndex(this._map, dupes, tmp); | ||
addIndex(this._map, dupes, tmp, id); | ||
} | ||
@@ -426,3 +477,3 @@ | ||
addIndex(this._map, dupes, tmp); | ||
addIndex(this._map, dupes, tmp, id); | ||
} | ||
@@ -442,3 +493,3 @@ | ||
addIndex(this._map, dupes, tmp); | ||
addIndex(this._map, dupes, tmp, id); | ||
} | ||
@@ -452,3 +503,3 @@ } | ||
addIndex(this._map, dupes, value); | ||
addIndex(this._map, dupes, value, id); | ||
@@ -607,4 +658,4 @@ break; | ||
/** | ||
* @param {string} query | ||
* @param {number|Function} limit | ||
* @param {!string} query | ||
* @param {number|Function=} limit | ||
* @param {Function=} callback | ||
@@ -686,2 +737,3 @@ * @returns {Array} | ||
/** @type {FlexSearch} */ | ||
var self = this; | ||
@@ -916,3 +968,3 @@ | ||
* Phonetic Encoders | ||
* @enum {Function|boolean} | ||
* @enum {Function} | ||
* @private | ||
@@ -1143,2 +1195,3 @@ * @const | ||
/** @this {Cache} */ | ||
function Cache(){ | ||
@@ -1149,2 +1202,3 @@ | ||
/** @this {Cache} */ | ||
Cache.prototype.reset = function(){ | ||
@@ -1155,2 +1209,3 @@ | ||
/** @this {Cache} */ | ||
Cache.prototype.set = function(id, value){ | ||
@@ -1161,2 +1216,3 @@ | ||
/** @this {Cache} */ | ||
Cache.prototype.get = function(id){ | ||
@@ -1187,5 +1243,5 @@ | ||
* @param {!string} str | ||
* @param {RegExp|Array<RegExp, string>} regex | ||
* @param {RegExp|Array} regex | ||
* @param {string=} replacement | ||
* @returns {*} | ||
* @returns {string} | ||
*/ | ||
@@ -1197,3 +1253,3 @@ | ||
for(var i = 0; i < regex.length; i += 2){ | ||
for(var i = 0; i < /** @type {Array} */ (regex).length; i += 2){ | ||
@@ -1211,3 +1267,3 @@ str = str.replace(regex[i], regex[i + 1]); | ||
function addIndex(map, dupes, tmp){ | ||
function addIndex(map, dupes, tmp, id){ | ||
@@ -1575,4 +1631,8 @@ if(!dupes[tmp]){ | ||
flexsearch = Function( | ||
data['options']['cache'] = false; | ||
data['options']['async'] = true; | ||
data['options']['worker'] = false; | ||
flexsearch = new Function( | ||
data['register'].substring( | ||
@@ -1583,9 +1643,4 @@ | ||
) | ||
)(); | ||
data['options']['cache'] = false; | ||
data['options']['async'] = true; | ||
data['options']['worker'] = false; | ||
flexsearch = new flexsearch(data['options']); | ||
)(data['options']); | ||
} | ||
@@ -1638,3 +1693,3 @@ } | ||
var worker_stack = {}; | ||
var inline_is_supported = !!((typeof Blob !== 'undefined') && URL && URL.createObjectURL); | ||
var inline_is_supported = !!((typeof Blob !== 'undefined') && (typeof URL !== 'undefined') && URL.createObjectURL); | ||
@@ -1707,4 +1762,5 @@ return ( | ||
})() | ||
)); | ||
), this); | ||
/** -------------------------------------------------------------------------------------- | ||
@@ -1715,20 +1771,16 @@ * UMD Wrapper for Browser and Node.js | ||
* @param {!Function|Object=} root | ||
* @suppress {checkVars} | ||
* @const | ||
*/ | ||
function register(name, factory, root){ | ||
function provide(name, factory, root){ | ||
root || (root = this); | ||
var define = root['define']; | ||
var modules = root['module']; | ||
var prop; | ||
// CommonJS (Browser) | ||
if(modules && modules['exports']){ | ||
modules['exports'] = factory; | ||
} | ||
// AMD (RequireJS) | ||
else if(define && define['amd']){ | ||
if((prop = root['define']) && prop['amd']){ | ||
define([], function(){ | ||
prop([], function(){ | ||
@@ -1738,6 +1790,6 @@ return factory; | ||
} | ||
// Universal (Xone) | ||
else if((modules = root['modules'])){ | ||
// Closure (Xone) | ||
else if((prop = root['modules'])){ | ||
modules[name.toLowerCase()] = factory; | ||
prop[name.toLowerCase()] = factory; | ||
} | ||
@@ -1747,2 +1799,3 @@ // CommonJS (Node.js) | ||
/** @export */ | ||
module.exports = factory; | ||
@@ -1757,4 +1810,2 @@ } | ||
// Note: May this workaround is more Node-compatible: | ||
// https://github.com/efacilitation/commonjs-require | ||
})(); | ||
}).call(this); |
@@ -1,25 +0,24 @@ | ||
/**! | ||
* FlexSearch - Superfast lightweight full text search engine | ||
* ---------------------------------------------------------- | ||
* https://github.com/nextapps-de/flexsearch | ||
* @version: 0.1.2 | ||
* @author: Thomas Wilkerling | ||
* @license: Apache 2.0 Licence | ||
*/ | ||
(function(l,r,f){f||(f=this);var d=f.define,m=f.module;m&&m.exports?m.exports=r:d&&d.amd?d([],function(){return r}):(m=f.modules)?m[l.toLowerCase()]=r:"undefined"!==typeof module?module.G=r:f[l]=r})("FlexSearch",function A(l){function f(a){a||(a=p);this.id=a.id||B++;this.C(a)}function d(a){return new RegExp(a,"g")}function m(a,b,c){if("undefined"===typeof c){for(c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}return a.replace(b,c)}function q(a,b,c){b[c]||(b[c]="1",a=a[c[0]]||(a[c[0]]={}),a[c]? | ||
a=a[c]:a[c]=a=[],a[a.length]=id)}function x(a){for(var b="",c="",e="",n=0;n<a.length;n++){var k=a[n];k!==c&&(0<n&&"h"===k?(e="a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e,"a"!==c&&"e"!==c&&"i"!==c&&"o"!==c&&"u"!==c&&"y"!==c||!e||(b+=k)):b+=k);e=n===a.length-1?"":a[n+1];c=k}return b}function C(a,b){var c=a.length-b.length;return 0>c?1:0<c?-1:0}function D(a,b){var c=a.length-b.length;return 0>c?-1:0<c?1:0}function E(a,b,c){var e=a.length,n=b.length,k=[];if(e&&n)for(var g=0,h=0;h<e;h++)for(var d= | ||
a[h],f=0;f<n;f++)if(b[f]===d){k[g++]=d;if(c&&g===c)return k;break}return k}function v(a){a.w||(a.w=y(function(){a.w=null;var b=a.async;b&&(a.async=!1);if(a.c.length){for(var c=z(),e;(e=a.c.shift())||0===e;){var n=a.g[e];switch(n[0]){case t.add:a.add(n[1],n[2]);break;case t.update:a.update(n[1],n[2]);break;case t.remove:a.remove(n[1])}a.g[e]=null;delete a.g[e];if(100<z()-c)break}a.c.length&&v(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function z(){return"undefined"!==typeof performance?performance.now(): | ||
(new Date).getTime()}function F(a,b,c,e){a=l("flexsearch-"+a,function(){var a,b;self.onmessage=function(c){if(c=c.data)b.debug&&console.log("Worker Job Started: "+c.id),c.search?self.postMessage({result:b.search(c.content,c.limit),id:a,content:c.content,limit:c.limit}):c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset():c.info?(c=b.info(),c.worker=a,b.debug&&console.log(c)):c.register&&(a=c.id,b=Function(c.register.substring(c.register.indexOf("{")+ | ||
1,c.register.lastIndexOf("}")))(),c.options.cache=!1,c.options.async=!0,c.options.worker=!1,b=new b(c.options))}},function(a){(a=a.data)&&a.result?e(a.id,a.content,a.result,a.limit):c.debug&&console.log(a)},b);var n=A.toString();c.id=b;a.postMessage(b,{register:n,options:c,id:b});return a}var p={type:"integer",mode:"forward",A:!1,cache:!1,async:!1,j:!1,encode:!1,i:4,debug:!0},u=[],B=0,t={add:0,update:1,remove:2};f.create=function(a){return new this(a)};f.F=function(a){for(var b in a)a.hasOwnProperty(b)&& | ||
(u[u.length]=[d(b),a[b]])};f.prototype.C=function(a){if(a){if(a.worker)if("undefined"===typeof Worker)a.worker=!1;else{var b=this,c=a.threads||p.threads;b.o=-1;b.u=0;b.h=[];b.v=null;b.l=Array(c);for(var e=0;e<c;e++)b.l[e]=F(b.id,e,a||p,function(a,c,e,d){b.u!==b.i&&(b.h=b.h.concat(e),b.u++,d&&b.h.length>=d&&(b.u=b.i),b.v&&b.u===b.i&&(b.h.length?b.f="":b.f||(b.f=c),b.cache&&b.m.set(c,b.h),b.v(b.h),b.h=[]))})}this.mode=a.mode||this.mode||p.mode;this.A="or"===a["boolean"]||this.A||p.A;this.cache=a.cache|| | ||
this.cache||p.cache;this.async=a.async||this.async||p.async;this.j=a.worker||this.j||p.j;this.i=a.threads||this.i||p.i;this.B=a.encode&&w[a.encode]||this.B||p.encode&&w[p.encode]||a.encode;this.debug=a.debug||this.debug||p.debug}this.a={};this.b={};this.g={};this.c=[];this.w=null;this.f="";this.s=!0;this.m=this.cache?new G(3E4,50,!0):!1};f.prototype.encode=function(a){this.B&&(a=this.B(a));if(u.length)for(var b=0;b<u.length;b++){var c=u[b];a=a.replace(c[0],c[1])}return a};f.prototype.add=function(a, | ||
b){if("string"===typeof b&&b&&(a||0===a))if(this.b[a])this.update(a,b);else if(this.j)++this.o>=this.l.length&&(this.o=0),this.l[this.o].postMessage(this.o,{add:!0,id:a,content:b}),this.b[a]=""+this.o;else if(this.async)this.g[a]||(this.c[this.c.length]=a),this.g[a]=[t.add,a,b],v(this);else{for(var c={},e=b.split(" "),d=0;d<e.length;d++){var k=e[d];if(k&&(this.encode&&(k=this.encode(k)),k))switch(this.mode){case "inverse":case "both":for(var g="",h=k.length-1;1<=h;h--)g=k[h]+g,q(this.a,c,g);case "forward":g= | ||
"";for(h=0;h<k.length;h++)g+=k[h],q(this.a,c,g);break;case "full":for(h=0;h<k.length;h++)for(var f=k.length;f>h;f--)g=k.substring(h,f),q(this.a,c,g);break;default:q(this.a,c,k)}}this.b[a]="1";this.s=!1}};f.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)&&this.b[a])if(this.j){var c=parseInt(this.b[a],10);this.l[c].postMessage(c,{update:!0,id:a,content:b})}else this.async?(this.g[a]||(this.c[this.c.length]=a),this.g[a]=[t.update,a,b],v(this)):(this.remove(a),b&&this.add(a,b))};f.prototype.remove= | ||
function(a){if(this.b[a])if(this.j){var b=parseInt(this.b[a],10);this.l[b].postMessage(b,{remove:!0,id:a});delete this.b[a]}else if(this.async)this.g[a]||(this.c[this.c.length]=a),this.g[a]=[t.remove,a],v(this);else{b=Object.keys(this.a);for(var c=0;c<b.length;c++)for(var e=Object.keys(this.a[b[c]]),d=0;d<e.length;d++){var f=e[d],g=this.a[b[c]];if((g=g&&g[f])&&g.length)for(var h=0;h<g.length;h++)if(g[h]===a){g.splice(h,1);break}g.length||delete this.a[b[c]][f]}delete this.b[a];this.s=!1}};var H=d("[ -/]"); | ||
f.prototype.search=function(a,b,c){if("string"===typeof a&&a)"function"===typeof b?(c=b,b=1E3):b||(b=1E3);else return[];var e=a;if(!this.s)this.cache&&(this.f="",this.m.reset()),this.s=!0;else if(this.cache){var d=this.m.get(a);if(d)return d}else if(this.f&&-1!==a.indexOf(this.f))return[];if(this.j){this.v=c;this.u=0;this.h=[];for(e=0;e<this.i;e++)this.l[e].postMessage(e,{search:!0,limit:b,content:a});return null}if(c){var f=this;y(function(){c(f.search(a,b));f=null},1,"search-"+this.id);return null}for(d= | ||
0;" "===a[d];)d++;d&&(e=a.substring(d));if(!e)return[];var g=e.split(H);1<g.length&&g.sort(C);d=[];var h=!0;e=[];for(var p={},m=0;m<g.length;m++){var l=g[m];if(!p[l]&&(l&&this.encode&&(l=this.encode(l)),l)){var q=this.a[l[0]];if((q=q&&q[l])&&q.length)e[e.length]=q;else{h=!1;break}p[g[m]]="1"}}if(h&&(1<e.length&&e.sort(D),g=0,h=e[g++])){for(d=e.length;h.length&&g<d;)p=e[g++],h=E(h,p,g===d?b:0);b&&h.length>b&&(h=h.slice(0,b));d=h}d.length?this.f="":this.f||(this.f=a);this.cache&&this.m.set(a,d);return d}; | ||
f.prototype.info=function(){if(this.j)for(var a=0;a<this.i;a++)this.l[a].postMessage(a,{info:!0,id:this.id});else{var b=0,c=0,d=0;var f=Object.keys(this.a);for(a=0;a<f.length;a++){var k=""+f[a];var g=this.a[k].length;b+=1*g+2*k.length;c+=g;d+=g*k.length}f=Object.keys(this.b);g=f.length;for(a=0;a<g;a++)b+=2*f[a].length+2;return{id:this.id,memory:b,items:g,sequences:c,chars:d,status:this.s,cache:this.c.length,matchers:u.length}}};f.prototype.reset=function(){this.D();this.C()};f.prototype.D=function(){this.cache&& | ||
this.m.reset();this.m=this.b=this.a=null};var w={icase:function(a){return a.toLowerCase()},simple:function(){var a=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d("[-/]")," ",d("[^a-z0-9 ]"),""];return function(b){return m(b.toLowerCase(),a)}}(),advanced:function(){var a= | ||
d(" "),b=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",d("cc"),"k",d("dt"),"t",d("ph"),"f",d("ou"),"o",d("uo"),"u"];return function(c,d){if(!c)return c;c=w.simple(c);2<c.length&&(c=m(c,b));d||(c=c.replace(a,""),1<c.length&&(c=x(c)));return c}}(),extra:function(){var a=[d("p"),"b",d("[sz]"),"c",d("[gq]"),"k",d("[jy]"),"i",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[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 d=b[c];1<d.length&&(b[c]=d[0]+m(d.substring(1),a))}b=b.join("");b=x(b)}return b}}()},y=function(){var a={};return function(b,c,d){var e=a[d];e&&clearTimeout(e);return a[d]=setTimeout(b,c)}}(),G=function(){function a(){this.cache={}}a.prototype.reset=function(){this.cache={}};a.prototype.set=function(a,c){this.cache[a]=c};a.prototype.get=function(a){return this.cache[a]};return a}();return f}(function(){var l={},r=!("undefined"=== | ||
typeof Blob||!URL||!URL.createObjectURL);return function(f,d,m,q){d=r?URL.createObjectURL(new Blob(["("+d.toString()+")()"],{type:"text/javascript"})):"js/worker/"+f+".js";l[f]||(l[f]=[]);l[f][q]=new Worker(d);l[f][q].onmessage=m;console.log("Register Worker@"+f);return{postMessage:function(d,m){l[f][d].postMessage(m)}}}}())); | ||
/* | ||
https://github.com/nextapps-de/flexsearch | ||
@version: 0.1.2 | ||
@author: Thomas Wilkerling | ||
@license: Apache 2.0 Licence | ||
*/ | ||
'use strict';(function(n,q,e){e||(e=this);var d;(d=e.define)&&d.amd?d([],function(){return q}):(d=e.modules)?d[n.toLowerCase()]=q:"undefined"!==typeof module?module.exports=q:e[n]=q})("FlexSearch",function z(n){function e(a){a||(a=l);this.id=a.id||A++;this.init(a);Object.defineProperty(this,"index",{get:function(){return this.a}});Object.defineProperty(this,"length",{get:function(){return Object.keys(this.a).length}})}function d(a){return new RegExp(a,"g")}function t(a,b,c){if("undefined"===typeof c){for(c= | ||
0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}return a.replace(b,c)}function m(a,b,c,h){b[c]||(b[c]="1",a=a[c[0]]||(a[c[0]]={}),a[c]?a=a[c]:a[c]=a=[],a[a.length]=h)}function w(a){for(var b="",c="",h="",f=0;f<a.length;f++){var d=a[f];d!==c&&(0<f&&"h"===d?(h="a"===h||"e"===h||"i"===h||"o"===h||"u"===h||"y"===h,"a"!==c&&"e"!==c&&"i"!==c&&"o"!==c&&"u"!==c&&"y"!==c||!h||(b+=d)):b+=d);h=f===a.length-1?"":a[f+1];c=d}return b}function B(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function C(a,b){a= | ||
a.length-b.length;return 0>a?-1:0<a?1:0}function D(a,b,c){var h=a.length,f=b.length,d=[];if(h&&f)for(var g=0,k=0;k<h;k++)for(var e=a[k],l=0;l<f;l++)if(b[l]===e){d[g++]=e;if(c&&g===c)return d;break}return d}function u(a){a.u||(a.u=x(function(){a.u=null;var b=a.async;b&&(a.async=!1);if(a.c.length){for(var c=y(),h;(h=a.c.shift())||0===h;){var f=a.g[h];switch(f[0]){case p.add:a.add(f[1],f[2]);break;case p.update:a.update(f[1],f[2]);break;case p.remove:a.remove(f[1])}a.g[h]=null;delete a.g[h];if(100<y()- | ||
c)break}a.c.length&&u(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function y(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}function E(a,b,c,h){a=n("flexsearch-"+a,function(){var a,b;self.a=function(c){if(c=c.data)b.debug&&console.log("Worker Job Started: "+c.id),c.search?self.postMessage({result:b.search(c.content,c.limit),id:a,content:c.content,limit:c.limit}):c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset(): | ||
c.info?(c=b.info(),c.worker=a,b.debug&&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("}"))))(c.options))}},function(a){(a=a.data)&&a.result?h(a.id,a.content,a.result,a.limit):c.debug&&console.log(a)},b);var f=z.toString();c.id=b;a.postMessage(b,{register:f,options:c,id:b});return a}var l={type:"integer",mode:"forward",boolean:!1,cache:!1,async:!1,worker:!1,encode:!1, | ||
threads:4,debug:!0},r=[],A=0,p={add:0,update:1,remove:2};e.create=function(a){return e.new(a)};e.new=function(a){return new this(a)};e.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(r[r.length]=[d(b),a[b]])};e.prototype.init=function(a){if(a){if(a.worker)if("undefined"===typeof Worker)a.worker=!1,this.i=null;else{var b=this,c=a.threads||l.threads;b.m=-1;b.l=0;b.h=[];b.s=null;b.i=Array(c);for(var h=0;h<c;h++)b.i[h]=E(b.id,h,a||l,function(a,c,h,d){b.l!==b.threads&&(b.h=b.h.concat(h),b.l++, | ||
d&&b.h.length>=d&&(b.l=b.threads),b.s&&b.l===b.threads&&(b.h.length?b.f="":b.f||(b.f=c),b.cache&&b.j.set(c,b.h),b.s(b.h),b.h=[]))})}this.mode=a.mode||this.mode||l.mode;this.boolean="or"===a["boolean"]||this.boolean||l.boolean;this.cache=a.cache||this.cache||l.cache;this.async=a.async||this.async||l.async;this.worker=a.worker||this.worker||l.worker;this.threads=a.threads||this.threads||l.threads;this.encoder=a.encode&&v[a.encode]||this.encoder||l.encode&&v[l.encode]||a.encode;this.debug=a.debug||this.debug|| | ||
l.debug}this.b={};this.a={};this.g={};this.c=[];this.u=null;this.f="";this.o=!0;this.j=this.cache?new F(3E4,50,!0):!1};e.prototype.encode=function(a){this.encoder&&(a=this.encoder(a));if(r.length)for(var b=0;b<r.length;b++){var c=r[b];a=a.replace(c[0],c[1])}return a};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.m>=this.i.length&&(this.m=0),this.i[this.m].postMessage(this.m,{add:!0,id:a,content:b}),this.a[a]=""+this.m; | ||
else if(this.async)this.g[a]||(this.c[this.c.length]=a),this.g[a]=[p.add,a,b],u(this);else{var c={};b=b.split(" ");for(var h=0;h<b.length;h++){var d=b[h];if(d&&(this.encode&&(d=this.encode(d)),d))switch(this.mode){case "inverse":case "both":for(var e="",g=d.length-1;1<=g;g--)e=d[g]+e,m(this.b,c,e,a);case "forward":e="";for(g=0;g<d.length;g++)e+=d[g],m(this.b,c,e,a);break;case "full":for(g=0;g<d.length;g++)for(var k=d.length;k>g;k--)e=d.substring(g,k),m(this.b,c,e,a);break;default:m(this.b,c,d,a)}}this.a[a]= | ||
"1";this.o=!1}};e.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)&&this.a[a])if(this.worker){var c=parseInt(this.a[a],10);this.i[c].postMessage(c,{update:!0,id:a,content:b})}else this.async?(this.g[a]||(this.c[this.c.length]=a),this.g[a]=[p.update,a,b],u(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]=[p.remove,a],u(this);else{b=Object.keys(this.b);for(var c=0;c<b.length;c++)for(var d=Object.keys(this.b[b[c]]),f=0;f<d.length;f++){var e=d[f],g=this.b[b[c]];if((g=g&&g[e])&&g.length)for(var k=0;k<g.length;k++)if(g[k]===a){g.splice(k,1);break}g.length||delete this.b[b[c]][e]}delete this.a[a];this.o=!1}};var G=d("[ -/]");e.prototype.search=function(a,b,c){if("string"===typeof a&&a)"function"===typeof b?(c=b,b=1E3):b||(b=1E3);else return[];var d=a;if(!this.o)this.cache&&(this.f="",this.j.reset()), | ||
this.o=!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[];if(this.worker){this.s=c;this.l=0;this.h=[];for(d=0;d<this.threads;d++)this.i[d].postMessage(d,{search:!0,limit:b,content:a});return null}if(c){var e=this;x(function(){c(e.search(a,b));e=null},1,"search-"+this.id);return null}for(f=0;" "===a[f];)f++;f&&(d=a.substring(f));if(!d)return[];var g=d.split(G);1<g.length&&g.sort(B);f=[];var k=!0;d=[];for(var l={},n=0;n<g.length;n++){var m=g[n]; | ||
if(!l[m]&&(m&&this.encode&&(m=this.encode(m)),m)){var p=this.b[m[0]];if((p=p&&p[m])&&p.length)d[d.length]=p;else{k=!1;break}l[g[n]]="1"}}if(k&&(1<d.length&&d.sort(C),g=0,k=d[g++])){for(f=d.length;k.length&&g<f;)l=d[g++],k=D(k,l,g===f?b:0);b&&k.length>b&&(k=k.slice(0,b));f=k}f.length?this.f="":this.f||(this.f=a);this.cache&&this.j.set(a,f);return f};e.prototype.info=function(){if(this.worker)for(var a=0;a<this.threads;a++)this.i[a].postMessage(a,{info:!0,id:this.id});else{var b=0,c=0,d=0;var f=Object.keys(this.b); | ||
for(a=0;a<f.length;a++){var e=f[a];var g=this.b[e].length;b+=g+2*e.length;c+=g;d+=g*e.length}f=Object.keys(this.a);g=f.length;for(a=0;a<g;a++)b+=2*f[a].length+2;return{id:this.id,memory:b,items:g,sequences:c,chars:d,status:this.o,cache:this.c.length,matchers:r.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 v={icase:function(a){return a.toLowerCase()},simple:function(){var a=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"), | ||
"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d("[-/]")," ",d("[^a-z0-9 ]"),""];return function(b){return t(b.toLowerCase(),a)}}(),advanced:function(){var a=d(" "),b=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",d("cc"), | ||
"k",d("dt"),"t",d("ph"),"f",d("ou"),"o",d("uo"),"u"];return function(c,d){if(!c)return c;c=v.simple(c);2<c.length&&(c=t(c,b));d||(c=c.replace(a,""),1<c.length&&(c=w(c)));return c}}(),extra:function(){var a=[d("p"),"b",d("[sz]"),"c",d("[gq]"),"k",d("[jy]"),"i",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),""];return function(b){if(!b)return b;b=v.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var c=0;c<b.length;c++){var d=b[c];1<d.length&&(b[c]=d[0]+t(d.substring(1),a))}b=b.join("");b=w(b)}return b}}()}, | ||
x=function(){var a={};return function(b,c,d){var e=a[d];e&&clearTimeout(e);return a[d]=setTimeout(b,c)}}(),F=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 n={},q=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(e,d,t,m){d=q?URL.createObjectURL(new Blob(["("+d.toString()+")()"],{type:"text/javascript"})): | ||
"js/worker/"+e+".js";n[e]||(n[e]=[]);n[e][m]=new Worker(d);n[e][m].onmessage=t;console.log("Register Worker@"+e);return{postMessage:function(d,m){n[e][d].postMessage(m)}}}}()),this); |
{ | ||
"name": "flexsearch", | ||
"version": "0.1.22", | ||
"version": "0.1.23", | ||
"description": "Superfast, lightweight and memory efficient full text search library.", | ||
@@ -18,3 +18,7 @@ "keywords": [], | ||
"scripts": { | ||
"test": "nyc --reporter=html --reporter=text mocha --timeout=3000", | ||
"build": "java -jar -Xms256m -Xmx4096m node_modules/google-closure-compiler/compiler.jar --compilation_level=ADVANCED_OPTIMIZATIONS --use_types_for_optimization=true --new_type_inf=true --jscomp_warning=newCheckTypes --generate_exports=true --export_local_property_definitions=true --language_in=ECMASCRIPT5_STRICT --language_out=ECMASCRIPT5_STRICT --process_closure_primitives=true --summary_detail_level=3 --warning_level=VERBOSE --emit_use_strict=true --output_manifest=log/manifest.log --output_module_dependencies=log/module_dependencies.log --property_renaming_report=log/renaming_report.log --js='flexsearch.js' --js_output_file='flexsearch.min.js' && echo Build Complete. && exit 0", | ||
"test-production": "nyc --reporter=html --reporter=text mocha --timeout=3000 test --exit", | ||
"test-develop": "nyc --reporter=html --reporter=text mocha --timeout=3000 --exit", | ||
"test-browser": "mocha-phantomjs test/index.html", | ||
"test": "npm run test-develop && npm run test-production && npm run test-browser", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls" | ||
@@ -34,5 +38,7 @@ }, | ||
"coveralls": "^3.0.0", | ||
"mocha": "^5.0.1", | ||
"google-closure-compiler": "^20180204.0.0", | ||
"mocha": "^5.0.4", | ||
"mocha-phantomjs": "^4.1.0", | ||
"nyc": "^11.5.0" | ||
} | ||
} |
@@ -15,3 +15,4 @@ # FlexSearch | ||
- AMD (RequireJS, Xone) | ||
- CommonJS (Node.js, Xone) | ||
- CommonJS (Node.js) | ||
- Closure (Xone) | ||
- Global (window) | ||
@@ -18,0 +19,0 @@ |
@@ -1,4 +0,8 @@ | ||
var expect = require('chai').expect; | ||
var FlexSearch = require("../flexsearch.js"); | ||
if(typeof module !== 'undefined'){ | ||
var env = process.argv[3] === 'test' ? '.min' : ''; | ||
var expect = require('chai').expect; | ||
var FlexSearch = require("../flexsearch" + env + ".js"); | ||
} | ||
var flexsearch_default; | ||
@@ -19,3 +23,2 @@ var flexsearch_sync; | ||
// ------------------------------------------------------------------------ | ||
@@ -161,4 +164,4 @@ // Acceptance Tests | ||
expect(flexsearch_sync._ids).to.have.keys([0, 1, 2]); | ||
expect(Object.keys(flexsearch_sync._ids).length).to.equal(3); | ||
expect(flexsearch_sync.index).to.have.keys([0, 1, 2]); | ||
expect(flexsearch_sync.length).to.equal(3); | ||
}); | ||
@@ -178,3 +181,3 @@ | ||
expect(Object.keys(flexsearch_sync._ids).length).to.equal(3); | ||
expect(flexsearch_sync.length).to.equal(3); | ||
}); | ||
@@ -218,3 +221,3 @@ }); | ||
expect(Object.keys(flexsearch_sync._ids).length).to.equal(3); | ||
expect(flexsearch_sync.length).to.equal(3); | ||
expect(flexsearch_sync.search("foo")).to.include(2, 1); | ||
@@ -238,3 +241,3 @@ expect(flexsearch_sync.search("bar")).to.include(0); | ||
expect(Object.keys(flexsearch_sync._ids).length).to.equal(3); | ||
expect(flexsearch_sync.length).to.equal(3); | ||
expect(flexsearch_sync.search("foo")).to.include(2, 1); | ||
@@ -255,3 +258,3 @@ expect(flexsearch_sync.search("bar")).to.include(0); | ||
expect(Object.keys(flexsearch_sync._ids).length).to.equal(0); | ||
expect(flexsearch_sync.length).to.equal(0); | ||
expect(flexsearch_sync.search("foo")).to.have.lengthOf(0); | ||
@@ -275,8 +278,8 @@ expect(flexsearch_sync.search("bar")).to.have.lengthOf(0); | ||
expect(Object.keys(flexsearch_async._ids)).to.have.lengthOf(0); | ||
expect(flexsearch_async.length).to.equal(0); | ||
setTimeout(function(){ | ||
expect(Object.keys(flexsearch_async._ids).length).to.equal(3); | ||
expect(flexsearch_async._ids).to.have.keys([0, 1, 2]); | ||
expect(flexsearch_async.length).to.equal(3); | ||
expect(flexsearch_async.index).to.have.keys([0, 1, 2]); | ||
@@ -302,4 +305,4 @@ done(); | ||
expect(Object.keys(flexsearch_async._ids).length).to.equal(3); | ||
expect(flexsearch_async._ids).to.have.keys([0, 1, 2]); | ||
expect(flexsearch_async.length).to.equal(3); | ||
expect(flexsearch_async.index).to.have.keys([0, 1, 2]); | ||
@@ -391,3 +394,3 @@ done(); | ||
expect(Object.keys(flexsearch_async._ids).length).to.equal(3); | ||
expect(flexsearch_async.length).to.equal(3); | ||
expect(flexsearch_async.search("foo")).to.not.include(2, 1); | ||
@@ -400,3 +403,3 @@ expect(flexsearch_async.search("bar")).to.not.include(0); | ||
expect(Object.keys(flexsearch_async._ids).length).to.equal(3); | ||
expect(flexsearch_async.length).to.equal(3); | ||
expect(flexsearch_async.search("foo")).to.include(2, 1); | ||
@@ -426,3 +429,3 @@ expect(flexsearch_async.search("bar")).to.include(0); | ||
expect(Object.keys(flexsearch_async._ids).length).to.equal(3); | ||
expect(flexsearch_async.length).to.equal(3); | ||
expect(flexsearch_async.search("foo")).to.include(2, 1); | ||
@@ -447,7 +450,7 @@ expect(flexsearch_async.search("bar")).to.include(0); | ||
expect(Object.keys(flexsearch_async._ids).length).to.equal(3); | ||
expect(flexsearch_async.length).to.equal(3); | ||
setTimeout(function(){ | ||
expect(Object.keys(flexsearch_async._ids).length).to.equal(0); | ||
expect(flexsearch_async.length).to.equal(0); | ||
expect(flexsearch_async.search("foo")).to.have.lengthOf(0); | ||
@@ -505,3 +508,3 @@ expect(flexsearch_async.search("bar")).to.have.lengthOf(0); | ||
expect(Object.keys(flexsearch_strict._ids).length).to.equal(1); | ||
expect(flexsearch_strict.length).to.equal(1); | ||
expect(flexsearch_strict.search("björn phillipp")).to.include(0); | ||
@@ -515,3 +518,3 @@ expect(flexsearch_strict.search("björn mayer")).to.include(0); | ||
expect(Object.keys(flexsearch_forward._ids).length).to.equal(1); | ||
expect(flexsearch_forward.length).to.equal(1); | ||
expect(flexsearch_forward.search("bjö phil may")).to.have.lengthOf(1); | ||
@@ -525,3 +528,3 @@ expect(flexsearch_forward.search("bjö phil may")).to.include(0); | ||
expect(Object.keys(flexsearch_inverse._ids).length).to.equal(1); | ||
expect(flexsearch_inverse.length).to.equal(1); | ||
expect(flexsearch_inverse.search("jörn phil yer")).to.have.lengthOf(1); | ||
@@ -535,3 +538,3 @@ expect(flexsearch_inverse.search("jörn phil yer")).to.include(0); | ||
expect(Object.keys(flexsearch_full._ids).length).to.equal(1); | ||
expect(flexsearch_full.length).to.equal(1); | ||
expect(flexsearch_full.search("jör illi may")).to.have.lengthOf(1); | ||
@@ -538,0 +541,0 @@ expect(flexsearch_full.search("jör illi may")).to.include(0); |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
95871
7
1634
568
0
6
1