diff --git a/README.md b/README.md index 7ca2dc4..d44b4ad 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,12 @@ Search Library

- + - + + +

diff --git a/flexsearch.js b/flexsearch.js index 50d0d0f..e982234 100644 --- a/flexsearch.js +++ b/flexsearch.js @@ -1,5 +1,5 @@ ;/**! - * @preserve FlexSearch v0.2.66 + * @preserve FlexSearch v0.2.67 * Copyright 2018 Thomas Wilkerling * Released under the Apache 2.0 Licence * https://github.com/nextapps-de/flexsearch @@ -126,9 +126,9 @@ var SUPPORT_ASYNC = true; /** @const {RegExp} */ var regexSplit = regex("[ -\/]"); - var filter = {}; + var filter = Object.create(null); - var stemmer = {}; + var stemmer = Object.create(null); /** * @param {string|Object=} options @@ -268,7 +268,7 @@ var SUPPORT_ASYNC = true; options || (options = defaults); var custom = options["profile"]; - var profile = custom ? profiles[custom] : {}; + var profile = custom && profiles.hasOwnProperty(custom) ? profiles[custom] : Object.create(null); // initialize worker @@ -424,13 +424,21 @@ var SUPPORT_ASYNC = true; this._map = [ - {/* 0 */}, {/* 1 */}, {/* 2 */}, {/* 3 */}, {/* 4 */}, - {/* 5 */}, {/* 6 */}, {/* 7 */}, {/* 8 */}, {/* 9 */} + Object.create(null/* 0 */), + Object.create(null/* 1 */), + Object.create(null/* 2 */), + Object.create(null/* 3 */), + Object.create(null/* 4 */), + Object.create(null/* 5 */), + Object.create(null/* 6 */), + Object.create(null/* 7 */), + Object.create(null/* 8 */), + Object.create(null/* 9 */) ]; - this._ctx = {}; - this._ids = {}; - this._stack = {}; + this._ctx = Object.create(null); + this._ids = Object.create(null); + this._stack = Object.create(null); this._stackKeys = []; /** @@ -632,7 +640,7 @@ var SUPPORT_ASYNC = true; var dupes = { - "_ctx": {} + "_ctx": Object.create(null) }; var threshold = this.threshold; @@ -745,11 +753,19 @@ var SUPPORT_ASYNC = true; if(depth && (wordLength > 1) && (score >= threshold)){ - var ctxDupes = dupes["_ctx"][value] || (dupes["_ctx"][value] = {}); + var ctxDupes = dupes["_ctx"][value] || (dupes["_ctx"][value] = Object.create(null)); var ctxTmp = this._ctx[value] || (this._ctx[value] = [ - {/* 0 */}, {/* 1 */}, {/* 2 */}, {/* 3 */}, {/* 4 */}, - {/* 5 */}, {/* 6 */}, {/* 7 */}, {/* 8 */}, {/* 9 */} + Object.create(null/* 0 */), + Object.create(null/* 1 */), + Object.create(null/* 2 */), + Object.create(null/* 3 */), + Object.create(null/* 4 */), + Object.create(null/* 5 */), + Object.create(null/* 6 */), + Object.create(null/* 7 */), + Object.create(null/* 8 */), + Object.create(null/* 9 */) ]); var x = i - depth; @@ -1007,7 +1023,7 @@ var SUPPORT_ASYNC = true; var length = words.length; var found = true; var check = []; - var checkWords = {}; + var checkWords = Object.create(null); if(length > 1){ @@ -1266,7 +1282,7 @@ var SUPPORT_ASYNC = true; * @final */ - var globalEncoder = SUPPORT_BUILTINS ? { + var globalEncoder = Object.create(SUPPORT_BUILTINS ? { // case insensitive search @@ -1467,13 +1483,13 @@ var SUPPORT_ASYNC = true; "icase": globalEncoderIcase, "balance": globalEncoderBalance - }; + }); // Xone Async Handler Fallback var queue = SUPPORT_ASYNC ? (function(){ - var stack = {}; + var stack = Object.create(null); return function(fn, delay, id){ @@ -1507,9 +1523,9 @@ var SUPPORT_ASYNC = true; /** @this {Cache} */ Cache.prototype.reset = function(){ - this.cache = {}; - this.count = {}; - this.index = {}; + this.cache = Object.create(null); + this.count = Object.create(null); + this.index = Object.create(null); this.ids = []; }; @@ -1919,7 +1935,7 @@ var SUPPORT_ASYNC = true; function initFilter(words, encoder){ - var final = {}; + var final = Object.create(null); if(words){ @@ -2034,7 +2050,7 @@ var SUPPORT_ASYNC = true; // fill initial map - var check = {}; + var check = Object.create(null); var arr = arrays[0]; var length = arr.length; var i = 0; @@ -2549,7 +2565,7 @@ var SUPPORT_ASYNC = true; SUPPORT_WORKER ? (function registerWorker(){ - var workerStack = {}; + var workerStack = Object.create(null); var inlineSupported = !!((typeof Blob !== "undefined") && (typeof URL !== "undefined") && URL.createObjectURL); return ( diff --git a/flexsearch.light.js b/flexsearch.light.js index 08d805f..e527a93 100644 --- a/flexsearch.light.js +++ b/flexsearch.light.js @@ -1,19 +1,20 @@ /* - FlexSearch v0.2.66 + FlexSearch v0.2.67 Copyright 2018 Thomas Wilkerling Released under the Apache 2.0 Licence https://github.com/nextapps-de/flexsearch */ -'use strict';(function(d,v,n){var t;(t=n.define)&&t.amd?t([],function(){return v}):(t=n.modules)?t[d.toLowerCase()]=v:"undefined"!==typeof module?module.exports=v:n[d]=v})("FlexSearch",function(){function d(a){"string"===typeof a&&A.hasOwnProperty(a)&&(a=A[a]);a||(a=w);this.id=a.id||G++;this.init(a);v(this,"index",function(){return this.a});v(this,"length",function(){return Object.keys(this.a).length})}function v(a,b,c){Object.defineProperty(a,b,{get:c})}function n(a){return new RegExp(a,"g")}function t(a, -b,c){if("undefined"===typeof c){for(c=0;c=g&&(a=a[h+.5|0],a=a[c]||(a[c]=[]),a[a.length]=e)}return h||b[c]}function z(a,b){if(a)for(var c=Object.keys(a),e=0,f=c.length;e=(8=(8a?1:0a?-1:0b&&(e=e.slice(0,b)));return e}var w={encode:"icase",mode:"forward",f:!1,cache:!1,async:!1,i:!1,threshold:0, -depth:0},A={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"ngram",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},B=[],G=0,D=n("[ -/]"),E={},F={};d.new=function(a){return new this(a)};d.create=function(a){return d.new(a)};d.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&& -B.push(n(b),a[b]);return this};d.registerEncoder=function(a,b){u[a]=b;return this};d.registerLanguage=function(a,b){E[a]=b.filter;F[a]=b.stemmer;return this};d.encode=function(a,b){return u[a].call(u,b)};d.prototype.init=function(a){this.h=[];a||(a=w);var b=a.profile;b=b?A[b]:{};this.mode=a.mode||b.mode||this.mode||w.mode;this.threshold=a.threshold||b.threshold||this.threshold||w.threshold;this.depth=a.depth||b.depth||this.depth||w.depth;this.f=a.suggest||this.f||w.f;this.c=(b=a.encode||b.encode)&& -u[b]||("function"===typeof b?b:this.c||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=E[b]||b;var c=this.c,e={};if(b)for(var f=0;fl;r--)m=d.substring(l,r),x(g,e,m,a,t,n,f);break;default:if(l=x(g,e,d,a,1,n,f),p&&1=f)for(q=e._ctx[d]||(e._ctx[d]={}),d=this.b[d]||(this.b[d]= -[{},{},{},{},{},{},{},{},{},{}]),l=k-p,r=k+p+1,0>l&&(l=0),r>h&&(r=h);lb;b++)z(this.g[b],a);this.depth&&z(this.b,a);delete this.a[a]}return this};d.prototype.search=function(a,b,c){var e=[];if(a&&"object"===typeof a){c=a.callback||b;b=a.limit;var f= -a.threshold;a=a.query}f=(f||this.threshold||0)|0;"function"===typeof b?(c=b,b=1E3):b||(b=1E3);if(c){var d=this;K(function(){c(d.search(a,b));d=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return e;var g=this.encode(a);if(!g.length)return e;var h=this.mode;g="function"===typeof h?h(g):"ngram"===h?C(g):g.split(D);h=g.length;var k=!0,n=[],q={};if(1=f;z--)if(v=(t?l[m]:this.g)[z][r])x[A++]=v,w=!0;if(w)n[n.length]=1=g&&(a=a[h+.5|0],a=a[c]||(a[c]=[]),a[a.length]=e)}return h||b[c]}function A(a,b){if(a)for(var c=Object.keys(a),e=0,f=c.length;e=(8=(8a?1:0a?-1:0b&&(e=e.slice(0,b)));return e}var w={encode:"icase",mode:"forward",f:!1,cache:!1, +async:!1,i:!1,threshold:0,depth:0},z={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"ngram",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},B=[],G=0,D=n("[ -/]"),E=Object.create(null),F=Object.create(null);d.new=function(a){return new this(a)};d.create=function(a){return d.new(a)};d.registerMatcher= +function(a){for(var b in a)a.hasOwnProperty(b)&&B.push(n(b),a[b]);return this};d.registerEncoder=function(a,b){u[a]=b;return this};d.registerLanguage=function(a,b){E[a]=b.filter;F[a]=b.stemmer;return this};d.encode=function(a,b){return u[a].call(u,b)};d.prototype.init=function(a){this.h=[];a||(a=w);var b=a.profile;b=b&&z.hasOwnProperty(b)?z[b]:Object.create(null);this.mode=a.mode||b.mode||this.mode||w.mode;this.threshold=a.threshold||b.threshold||this.threshold||w.threshold;this.depth=a.depth||b.depth|| +this.depth||w.depth;this.f=a.suggest||this.f||w.f;this.c=(b=a.encode||b.encode)&&u[b]||("function"===typeof b?b:this.c||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=E[b]||b;var c=this.c,e=Object.create(null);if(b)for(var f=0;fl;r--)m=d.substring(l,r),x(g,e,m,a,t,n,f);break;default:if(l=x(g,e,d,a,1,n,f),p&&1=f)for(q=e._ctx[d]||(e._ctx[d]=Object.create(null)),d=this.b[d]||(this.b[d]=[Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null), +Object.create(null)]),l=k-p,r=k+p+1,0>l&&(l=0),r>h&&(r=h);lb;b++)A(this.g[b],a);this.depth&&A(this.b,a);delete this.a[a]}return this};d.prototype.search=function(a,b,c){var e=[];if(a&&"object"===typeof a){c=a.callback||b;b=a.limit;var f=a.threshold; +a=a.query}f=(f||this.threshold||0)|0;"function"===typeof b?(c=b,b=1E3):b||(b=1E3);if(c){var d=this;K(function(){c(d.search(a,b));d=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return e;var g=this.encode(a);if(!g.length)return e;var h=this.mode;g="function"===typeof h?h(g):"ngram"===h?C(g):g.split(D);h=g.length;var k=!0,n=[],q=Object.create(null);if(1=f;A--)if(v=(t?l[m]:this.g)[A][r])x[z++]=v,w=!0;if(w)n[n.length]=1=g&&(a=a[h+.5|0],a=a[e]||(a[e]=[]),a[a.length]=c)}return h||b[e]}function q(a,b){if(a)for(var e=Object.keys(a),c=0,k=e.length;c=(8=(8a?1:0 -a?-1:0 -b&&(c=c.slice(0,b)));return c}function G(a){a.B||(a.B=I(function(){a.B=null;var b=a.async;b&&(a.async=!1);if(a.b.length){for(var e=J(),c;(c=a.b.shift())||0===c;){var d=a.f[c];switch(d[0]){case C.add:a.add(d[1],d[2]);break;case C.remove:a.remove(d[1])}a.f[c]=null;delete a.f[c];if(100=d&&(c.o=c.c),c.w&&c.o===c.c&&(c.cache&&c.i.set(b,c.g),c.w(c.g),c.g=[]),c})}this.mode=a.mode||e.mode||this.mode||y.mode;this.async=a.async|| -this.async||y.async;this.c=a.worker||this.c||y.c;this.threshold=a.threshold||e.threshold||this.threshold||y.threshold;this.depth=a.depth||e.depth||this.depth||y.depth;this.u=a.suggest||this.u||y.u;this.s=(b=a.encode||e.encode)&&A[b]||("function"===typeof b?b:this.s||!1);this.debug=a.debug||this.debug;(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=P(L[b]||b,this.s);if(b=a.stemmer)this.stemmer=Q(M[b]||b,this.s);this.j=[{},{},{},{},{},{},{},{},{},{}];this.l={};this.a={};this.f={};this.b= -[];this.B=null;this.v=!0;this.i=(this.cache=b=a.cache||this.cache||y.cache)?new V(b):!1;return this};f.prototype.encode=function(a){a&&D.length&&(a=x(a,D));a&&this.A.length&&(a=x(a,this.A));a&&this.s&&(a=this.s.call(A,a));a&&this.stemmer&&(a=x(a,this.stemmer));return a};f.prototype.addMatcher=function(a){var b=this.A,e;for(e in a)a.hasOwnProperty(e)&&(b[b.length]=d(e),b[b.length]=a[e]);return this};f.prototype.add=function(a,b,e){if("string"===typeof b&&b&&(a||0===a))if(this.a[a]&&!e)this.update(a, -b);else{if(this.c)return++this.m>=this.h.length&&(this.m=0),this.h[this.m].postMessage(this.m,{add:!0,id:a,content:b}),this.a[a]=""+this.m,this;if(this.async)return this.f[a]||(this.b[this.b.length]=a),this.f[a]=[C.add,a,b],G(this),this;b=this.encode(b);if(!b.length)return this;e=this.mode;b="function"===typeof e?e(b):"ngram"===e?H(b):b.split(K);for(var c={_ctx:{}},d=this.threshold,t=this.depth,g=this.j,h=b.length,f=0;fl;r--)n=m.substring(l,r),z(g,c,n,a,q,u,d);break;default:if(l=z(g,c,m,a,1,u,d),t&&1=d)for(p=c._ctx[m]||(c._ctx[m]={}),m=this.l[m]||(this.l[m]=[{},{},{},{},{},{},{},{},{},{}]),l=f-t,r=f+t+1,0>l&&(l=0),r>h&&(r=h);lb;b++)q(this.j[b],a);this.depth&&q(this.l,a);delete this.a[a];this.v=!1}return this};f.prototype.search=function(a,b,e){var c=[];if(a&&"object"===typeof a){e= -a.callback||b;b=a.limit;var d=a.threshold;a=a.query}d=(d||this.threshold||0)|0;"function"===typeof b?(e=b,b=1E3):b||(b=1E3);if(this.c){this.w=e;this.o=0;this.g=[];for(c=0;c=d;A--)if(w=(u?l[n]:this.j)[A][r])x[z++]=w,y=!0;if(y)m[m.length]=1g;g++)for(b=Object.keys(this.j[g]),a=0;af;c--)h=g[c-1],g[c]=h,d[h]=c;g[f]=a;d[a]=f}}}return b};return a}();return f}(function(){var v={},B=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(f,w,d,x,z){var q=f;f=B?URL.createObjectURL(new Blob(["var SUPPORT_WORKER = true;var SUPPORT_BUILTINS = true;var SUPPORT_DEBUG = true;var SUPPORT_CACHE = true;var SUPPORT_ASYNC = true;("+ +"u"===e||"y"===e)&&c||" "===e)b+=d}else b+=d;c=k===a.length-1?"":a[k+1];e=d}return b}function P(a,b){var e=Object.create(null);if(a)for(var c=0;ca?1:0a?-1:0b&&(c=c.slice(0,b)));return c}function G(a){a.B||(a.B=I(function(){a.B=null;var b=a.async;b&&(a.async=!1);if(a.b.length){for(var e=J(),c;(c=a.b.shift())||0===c;){var d=a.f[c];switch(d[0]){case D.add:a.add(d[1],d[2]);break;case D.remove:a.remove(d[1])}a.f[c]=null;delete a.f[c];if(100=d&&(c.o=c.c),c.w&&c.o===c.c&&(c.cache&&c.i.set(b,c.g),c.w(c.g),c.g= +[]),c})}this.mode=a.mode||e.mode||this.mode||y.mode;this.async=a.async||this.async||y.async;this.c=a.worker||this.c||y.c;this.threshold=a.threshold||e.threshold||this.threshold||y.threshold;this.depth=a.depth||e.depth||this.depth||y.depth;this.u=a.suggest||this.u||y.u;this.s=(b=a.encode||e.encode)&&A[b]||("function"===typeof b?b:this.s||!1);this.debug=a.debug||this.debug;(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=P(L[b]||b,this.s);if(b=a.stemmer)this.stemmer=Q(M[b]||b,this.s);this.j= +[Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null)];this.l=Object.create(null);this.a=Object.create(null);this.f=Object.create(null);this.b=[];this.B=null;this.v=!0;this.i=(this.cache=b=a.cache||this.cache||y.cache)?new V(b):!1;return this};f.prototype.encode=function(a){a&&E.length&&(a=x(a,E));a&&this.A.length&&(a=x(a,this.A));a&&this.s&&(a=this.s.call(A, +a));a&&this.stemmer&&(a=x(a,this.stemmer));return a};f.prototype.addMatcher=function(a){var b=this.A,e;for(e in a)a.hasOwnProperty(e)&&(b[b.length]=d(e),b[b.length]=a[e]);return this};f.prototype.add=function(a,b,e){if("string"===typeof b&&b&&(a||0===a))if(this.a[a]&&!e)this.update(a,b);else{if(this.c)return++this.m>=this.h.length&&(this.m=0),this.h[this.m].postMessage(this.m,{add:!0,id:a,content:b}),this.a[a]=""+this.m,this;if(this.async)return this.f[a]||(this.b[this.b.length]=a),this.f[a]=[D.add, +a,b],G(this),this;b=this.encode(b);if(!b.length)return this;e=this.mode;b="function"===typeof e?e(b):"ngram"===e?H(b):b.split(K);for(var c={_ctx:Object.create(null)},d=this.threshold,t=this.depth,g=this.j,h=b.length,f=0;fl;r--)n=m.substring(l, +r),z(g,c,n,a,q,u,d);break;default:if(l=z(g,c,m,a,1,u,d),t&&1=d)for(p=c._ctx[m]||(c._ctx[m]=Object.create(null)),m=this.l[m]||(this.l[m]=[Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null),Object.create(null)]),l=f-t,r=f+t+1,0>l&&(l=0),r>h&&(r=h);lb;b++)q(this.j[b],a);this.depth&&q(this.l,a);delete this.a[a];this.v=!1}return this};f.prototype.search=function(a,b,e){var c=[];if(a&&"object"===typeof a){e=a.callback|| +b;b=a.limit;var d=a.threshold;a=a.query}d=(d||this.threshold||0)|0;"function"===typeof b?(e=b,b=1E3):b||(b=1E3);if(this.c){this.w=e;this.o=0;this.g=[];for(c=0;c=d;A--)if(w=(u?l[n]:this.j)[A][r])x[z++]=w,y=!0;if(y)m[m.length]=1g;g++)for(b=Object.keys(this.j[g]),a=0;af;c--)h=g[c-1],g[c]=h,d[h]=c;g[f]=a;d[a]=f}}}return b};return a}();return f}(function(){var v=Object.create(null),B=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(f,w,d,x,z){var q=f;f=B?URL.createObjectURL(new Blob(["var SUPPORT_WORKER = true;var SUPPORT_BUILTINS = true;var SUPPORT_DEBUG = true;var SUPPORT_CACHE = true;var SUPPORT_ASYNC = true;("+ d.toString()+")()"],{type:"text/javascript"})):"../"+q+".js";q+="-"+w;v[q]||(v[q]=[]);v[q][z]=new Worker(f);v[q][z].onmessage=x;console.log("Register Worker: "+q+"@"+z);return{postMessage:function(d,f){v[q][d].postMessage(f)}}}}()),this); diff --git a/package.json b/package.json index 530b846..4af1cdc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flexsearch", - "version": "0.2.66", + "version": "0.2.67", "description": "Next-Generation full text search library with zero dependencies.", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", @@ -47,11 +47,10 @@ "LICENSE" ], "readme": "README.md", - "dependencies": { - "codacy-coverage": "^2.1.1" - }, + "dependencies": {}, "devDependencies": { "chai": "^4.1.2", + "codacy-coverage": "^2.1.1", "coveralls": "^3.0.0", "google-closure-compiler": "^20180402.0.0", "mocha": "^5.1.1",