From 2de3f31fe62dff09ed970f433e02861b73d9f0e3 Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Mon, 25 Nov 2019 00:26:36 +0100 Subject: [PATCH] FIX tests --- bench/dist/flexsearch.light.js | 23 +- bench/dist/flexsearch.min.js | 62 +- dist/flexsearch.compact.js | 44 +- dist/flexsearch.debug.js | 322 +++++----- dist/flexsearch.es5.js | 60 +- dist/flexsearch.light.js | 23 +- dist/flexsearch.min.js | 60 +- dist/flexsearch.node.js | 55 +- dist/flexsearch.pre.js | 904 ++++++++++++++------------- dist/lang/arabic/default.min.js | 2 +- dist/lang/cjk/default.min.js | 2 +- dist/lang/cyrillic/default.min.js | 2 +- dist/lang/latin/advanced.min.js | 2 +- dist/lang/latin/extra.min.js | 2 +- dist/lang/latin/simple.min.js | 2 +- dist/module/flexsearch.js | 2 +- dist/module/lang/arabic/default.js | 2 +- dist/module/lang/cjk/default.js | 2 +- dist/module/lang/cyrillic/default.js | 2 +- dist/module/lang/latin/advanced.js | 2 +- dist/module/lang/latin/extra.js | 2 +- dist/module/lang/latin/simple.js | 2 +- dist/module/presets.js | 2 +- doc/0.7.0.md | 21 +- src/flexsearch.js | 347 +++++----- src/lang/arabic/default.js | 6 +- src/lang/cjk/default.js | 2 +- src/lang/cyrillic/default.js | 6 +- src/lang/latin/advanced.js | 4 +- src/lang/latin/extra.js | 3 +- src/lang/latin/simple.js | 5 +- src/presets.js | 22 +- test/test.js | 292 +++++---- 33 files changed, 1147 insertions(+), 1142 deletions(-) diff --git a/bench/dist/flexsearch.light.js b/bench/dist/flexsearch.light.js index d376614..4e6dd4d 100644 --- a/bench/dist/flexsearch.light.js +++ b/bench/dist/flexsearch.light.js @@ -5,15 +5,14 @@ * Licence: Apache-2.0 * https://github.com/nextapps-de/flexsearch */ -(function(){'use strict';var v;Object.assign||(Object.assign=function(){for(var a=arguments,b=a.length,c=a[0],e=1,d,h,g;ek;u--)r=q.substring(k,u),N(f,c,r,a,t,n,d,g-1);break;default:if(m=N(f,c,q,a,1,n,d,g-1),h&&1=d)for(m=c._ctx[q]||(c._ctx[q]=z()),q=this.b[q]||(this.b[q]=y(g-(d||0))),n=l-h,r=l+h+1,0>n&&(n=0),r>e&&(r=e);nx&&(f=0);A=f||0;var D=A+b;D=g&&(a=a[f-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=e);return d}function O(a,b){if(a)for(var c=Object.keys(a),e=0,d=c.length;ek;z--)l=n.substring(k,z),N(f,c,l,a,w,r,d,g-1);break;default:if(p=N(f,c,n,a,1,r,d,g-1),h&&1=d)for(p=c._ctx[n]||(c._ctx[n]=B()),n=this.c[n]||(this.c[n]=y(g-(d||0))),r=q-h,l=q+h+1,0>r&&(r=0),l>e&&(l=e);rx&&(f=0);A=f||0;var D=A+b;D=g&&(a=a[f-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=e);return d}function Q(a,b){if(a)for(var c=Object.keys(a),e=0,d=c.length;ew;I--)u=y.substring(w,I),V(t,h,u,a,B,x,n,p-1);break;default:if(v=V(t,h,y,a,1,x,n,p-1),r&&1=n)for(v= -h._ctx[y]||(h._ctx[y]=P()),y=this.h[y]||(this.h[y]=la(p-(n||0))),x=m-r,u=m+r+1,0>x&&(x=0),u>k&&(u=k);xf;d--)h=g[d-1],g[d]=h,e[h]=d;g[f]=b;e[b]=f}}}return c};return a}(); -function ja(a,b,c){Object.defineProperty(a,b,{get:c})}function A(a){return new RegExp(a,"g")}function S(a,b){for(var c=0;c=g&&(a=a[h-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e} -function W(a,b){if(a)for(var c=Object.keys(a),d=0,e=c.length;da?1:a?-1:0}function ra(a,b){a=a[X];b=b[X];return ab?1:0}function qa(a,b){for(var c=X.length,d=0;db?1:0}function Z(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c} -function oa(a,b,c,d,e,f,g){var h=[];if(!0===c){c="0";var k=""}else k=c&&c.split(":");var n=a.length;if(1g&&(k=0);k=k||0;var L=k+b;Le;c--)g=f[c-1],f[c]=g,d[g]=c;f[e]=a;d[a]=e}}}return b};var U={},da="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;function ea(a,b,c){var d=fa,e="flexsearch";d=da?URL.createObjectURL(new Blob(["("+d.toString()+")()"],{type:"text/javascript"})):e+".browser.js";e+="-"+a;U[e]||(U[e]=[]);U[e][c]=new Worker(d);U[e][c].onmessage=b;return U[e][c]} +function fa(){var a,b;self.onmessage=function(c){if(c=c.data)if(c.search){var d=b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold,where:c.where}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:d})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.info?(c=b.info(),c.worker=a,console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!1,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+ +1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}}function ha(a,b,c,d){a=ea("id"+a,function(f){(f=f.data)&&f.result&&d(f.id,f.content,f.result,f.limit,f.where,f.cursor,f.suggest)},b);var e=P.toString();c.id=b;a.postMessage({register:e,options:c,id:b});return a}P.prototype.G=function(a,b,c,d){this.s!==this.v&&(this.o=this.o.concat(c),this.s++,d&&this.o.length>=d&&(this.s=this.v),this.s===this.v&&(this.cache&&this.g.set(b,this.o),this.C&&this.C(this.o)));return this};var ia={memory:{charset:"latin:extra",threshold:0,c:1},speed:{threshold:1,c:3,depth:2},match:{charset:"latin:extra",B:"full",threshold:1,c:3},score:{charset:"latin:extra",threshold:1,c:9,depth:4},balance:{charset:"latin:balance",threshold:0,c:3,depth:3},fast:{threshold:8,c:9,depth:1}};var ka={encode:ja,h:!1},la=/[\W_]+/;function ja(a){return O(this,a.toLowerCase(),!1,la)};var ma=0,na={},V={};function P(a){if(!(this instanceof P))return new P(a);var b=a&&a.id;this.id=b||0===b?b:ma++;this.init(a);oa(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});oa(this,"length",function(){return this.index.length})}P.registerCharset=function(a,b){V[a]=b;return P};P.registerLanguage=function(a,b){na[a]=b;return P}; +P.prototype.init=function(a){var b,c;if(a)if(t(a))a=ia[a];else if(b=a.preset)a=Object.assign({},ia[b],a);a||(a={});if(b=a.worker){if("undefined"===typeof ea)a.worker=!1,this.m=null;else{var d=parseInt(b,10)||4;this.s=0;this.o=[];this.C=null;this.m=Array(d);for(var e=0;eu;B--)x=n.substring(u,B),X(r,e,x,a,A,v,k,q-1);break;default:if(w=X(r,e,n,a,1,v,k,q-1),m&&1=k)for(w=e._ctx[n]||(e._ctx[n]=G()),n=this.i[n]||(this.i[n]=aa(q-(k||0))),v=l-m, +x=l+m+1,0>v&&(v=0),x>h&&(x=h);v=g&&(a=a[h-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e} +function ra(a,b){if(a)for(var c=Object.keys(a),d=0,e=c.length;db?1:0}function ua(a,b){for(var c=Y.length,d=0;db?1:0}function Z(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c} +function ta(a,b,c,d,e,f,g){var h=[];if(!0===c){c="0";var k=""}else k=c&&c.split(":");var m=a.length;if(1g&&(k=0);k=k||0;var J=k+b;Ju;I--)t=r.substring(u,I),T(n,d,t,a,M,w,h,p-1);break;default:if(v=T(n,d,r,a,1,w,h,p-1),k&&1=h)for(v=d._ctx[r]||(d._ctx[r]=B()),r=this.h[r]||(this.h[r]=A(p-(h||0))),w=l-k,t=l+k+1,0>w&&(w=0),t>e&&(t=e);w=e&&(a=a[h-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=f);return d}function U(a,b){if(a)for(var c=Object.keys(a),f=0,d=c.length;f -n&&(h=0);h=h||0;var E=h+b;Ex;B--)v=u.substring(x,B),U(l,e,v,a,K,r,k,m-1);break;default:if(w=U(l,e,u,a,1,r,k,m-1),p&&1=k)for(w=e._ctx[u]||(e._ctx[u]=F()),u=this.g[u]||(this.g[u]=C(m-(k||0))),r=t-p,v=t+p+1,0>r&&(r=0),v>h&&(v=h);r=f&&(a=a[h-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e}function W(a,b){if(a)for(var c=Object.keys(a),d=0,e=c.length;db?1:0}function ja(a,b){for(var c=X.length,d=0;db?1:0}function Z(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c} +function ia(a,b,c,d,e,g){var f=[];if(!0===c){c="0";var h=""}else h=c&&c.split(":");var k=a.length;if(1 +m&&(h=0);h=h||0;var E=h+b;E 1) { sort = sort_by_deep_field_up$$module$src$flexsearch; } else { - field_to_sort$$module$src$flexsearch = field_to_sort$$module$src$flexsearch[0]; sort = sort_by_field_up$$module$src$flexsearch; } } @@ -1033,11 +1038,11 @@ FlexSearch$$module$src$flexsearch.prototype.search = function(query, limit, call queries = _query; field = []; bool = []; - for (var i$24 = 0; i$24 < _query.length; i$24++) { - var current = _query[i$24]; + for (var i$26 = 0; i$26 < _query.length; i$26++) { + var current = _query[i$26]; var current_bool = SUPPORT_OPERATOR && current["bool"] || bool_main; - field[i$24] = current["field"]; - bool[i$24] = current_bool; + field[i$26] = current["field"]; + bool[i$26] = current_bool; if (current_bool === "not") { has_not = true; } else { @@ -1051,24 +1056,24 @@ FlexSearch$$module$src$flexsearch.prototype.search = function(query, limit, call } } var len = field.length; - for (var i$25 = 0; i$25 < len; i$25++) { + for (var i$27 = 0; i$27 < len; i$27++) { if (queries) { - _query = queries[i$25]; + _query = queries[i$27]; } if (cursor && !is_string$$module$src$common(_query)) { _query["page"] = null; _query["limit"] = 0; } - result[i$25] = doc_idx[field[i$25]].search(_query, 0); + result[i$27] = doc_idx[field[i$27]].search(_query, 0); } if (callback) { return callback(this.merge_and_sort(query, bool, result, sort, limit, suggest, where, cursor, has_and, has_not)); } else { if (SUPPORT_ASYNC && this.async) { - var self$26 = this; + var self$28 = this; return new Promise(function(resolve) { Promise.all(result).then(function(values) { - resolve(self$26.merge_and_sort(query, bool, values, sort, limit, suggest, where, cursor, has_and, has_not)); + resolve(self$28.merge_and_sort(query, bool, values, sort, limit, suggest, where, cursor, has_and, has_not)); }); }); } else { @@ -1079,11 +1084,11 @@ FlexSearch$$module$src$flexsearch.prototype.search = function(query, limit, call threshold || (threshold = this.threshold || 0); if (!_recall) { if (SUPPORT_ASYNC && this.async && typeof importScripts !== "function") { - var self$27 = this; + var self$29 = this; var promise = new Promise(function(resolve) { setTimeout(function() { - resolve(self$27.search(_query, limit, null, true)); - self$27 = null; + resolve(self$29.search(_query, limit, null, true)); + self$29 = null; }); }); if (callback) { @@ -1262,11 +1267,11 @@ function remove_index$$module$src$flexsearch(map, id) { } } function init_filter$$module$src$flexsearch(words) { - var final = create_object$$module$src$common(); + var filter = create_object$$module$src$common(); for (var i = 0, length = words.length; i < length; i++) { - final[words[i]] = 1; + filter[words[i]] = 1; } - return final; + return filter; } function init_stemmer_or_matcher$$module$src$flexsearch(obj, is_stemmer) { var keys = get_keys$$module$src$common(obj); @@ -1293,7 +1298,9 @@ function sort_by_length_down$$module$src$flexsearch(a, b) { return b.length - a.length; } function sort_by_field_up$$module$src$flexsearch(a, b) { - return a[field_to_sort$$module$src$flexsearch] - b[field_to_sort$$module$src$flexsearch]; + a = a[field_to_sort$$module$src$flexsearch]; + b = b[field_to_sort$$module$src$flexsearch]; + return a < b ? -1 : a > b ? 1 : 0; } function sort_by_deep_field_up$$module$src$flexsearch(a, b) { var field_len = field_to_sort$$module$src$flexsearch.length; @@ -1301,7 +1308,7 @@ function sort_by_deep_field_up$$module$src$flexsearch(a, b) { a = a[field_to_sort$$module$src$flexsearch[i]]; b = b[field_to_sort$$module$src$flexsearch[i]]; } - return a - b; + return a < b ? -1 : a > b ? 1 : 0; } function create_page$$module$src$flexsearch(cursor, page, result) { return cursor ? {"page":cursor, "next":page ? "" + page : null, "result":result} : result; @@ -1416,13 +1423,13 @@ function intersect$$module$src$flexsearch(arrays, limit, cursor, suggest, bool, var found = false; for (i = 0; i < length; i++) { tmp = arr[i]; - var index$28 = "@" + tmp; - var check_val = has_and ? check[index$28] || 0 : z; + var index$30 = "@" + tmp; + var check_val = has_and ? check[index$30] || 0 : z; if (check_val || suggest) { - if (has_not && check_not[index$28]) { + if (has_not && check_not[index$30]) { continue; } - if (!has_and && check[index$28]) { + if (!has_and && check[index$30]) { continue; } if (check_val === z) { @@ -1434,7 +1441,7 @@ function intersect$$module$src$flexsearch(arrays, limit, cursor, suggest, bool, } } } else { - check[index$28] = z + 1; + check[index$30] = z + 1; } found = true; } else { @@ -1450,17 +1457,17 @@ function intersect$$module$src$flexsearch(arrays, limit, cursor, suggest, bool, } } if (first_result) { - var result_length$29 = first_result.length; + var result_length$31 = first_result.length; if (has_not) { if (pointer) { i = parseInt(pointer, 10); } else { i = 0; } - for (; i < result_length$29; i++) { - var id$30 = first_result[i]; - if (!check_not["@" + id$30]) { - result[count++] = id$30; + for (; i < result_length$31; i++) { + var id$32 = first_result[i]; + if (!check_not["@" + id$32]) { + result[count++] = id$32; } } } else { @@ -1480,9 +1487,9 @@ function intersect$$module$src$flexsearch(arrays, limit, cursor, suggest, bool, tmp = suggestions[z]; if (tmp) { for (length = tmp.length; i < length; i++) { - var id$31 = tmp[i]; - if (!has_not || !check_not["@" + id$31]) { - result[count++] = id$31; + var id$33 = tmp[i]; + if (!has_not || !check_not["@" + id$33]) { + result[count++] = id$33; if (limit && count === limit) { return create_page$$module$src$flexsearch(cursor, z + ":" + i, result); } @@ -1503,13 +1510,13 @@ function intersect$$module$src$flexsearch(arrays, limit, cursor, suggest, bool, } } if (limit) { - var length$32 = result.length; - if (pointer && pointer > length$32) { + var length$34 = result.length; + if (pointer && pointer > length$34) { pointer = 0; } var start = pointer || 0; page = start + limit; - if (page < length$32) { + if (page < length$34) { result = result.slice(start, page); } else { page = 0; @@ -1540,8 +1547,7 @@ var regex_s$$module$src$lang$latin$simple = regex$$module$src$common("\u00df"); var regex_and$$module$src$lang$latin$simple = regex$$module$src$common(" & "); var pairs$$module$src$lang$latin$simple = [regex_a$$module$src$lang$latin$simple, "a", regex_e$$module$src$lang$latin$simple, "e", regex_i$$module$src$lang$latin$simple, "i", regex_o$$module$src$lang$latin$simple, "o", regex_u$$module$src$lang$latin$simple, "u", regex_y$$module$src$lang$latin$simple, "y", regex_n$$module$src$lang$latin$simple, "n", regex_c$$module$src$lang$latin$simple, "k", regex_s$$module$src$lang$latin$simple, "s", regex_and$$module$src$lang$latin$simple, " and "]; function encode$$module$src$lang$latin$simple(str, self) { - self || (self = this); - return self.pipeline(str.toLowerCase(), pairs$$module$src$lang$latin$simple, regex_whitespace$$module$src$lang$latin$simple, false); + return (self || this).pipeline(str.toLowerCase(), pairs$$module$src$lang$latin$simple, regex_whitespace$$module$src$lang$latin$simple, false); } var module$src$lang$latin$simple = {}; module$src$lang$latin$simple.default = $jscompDefaultExport$$module$src$lang$latin$simple; @@ -1571,9 +1577,9 @@ var regex_ou$$module$src$lang$latin$advanced = regex$$module$src$common("ou"); var regex_uo$$module$src$lang$latin$advanced = regex$$module$src$common("uo"); var pairs$$module$src$lang$latin$advanced = [regex_ae$$module$src$lang$latin$advanced, "a", regex_ai$$module$src$lang$latin$advanced, "ei", regex_ay$$module$src$lang$latin$advanced, "ei", regex_ey$$module$src$lang$latin$advanced, "ei", regex_oe$$module$src$lang$latin$advanced, "o", regex_ue$$module$src$lang$latin$advanced, "u", regex_ie$$module$src$lang$latin$advanced, "i", regex_sz$$module$src$lang$latin$advanced, "s", regex_zs$$module$src$lang$latin$advanced, "s", regex_sh$$module$src$lang$latin$advanced, "s", regex_ck$$module$src$lang$latin$advanced, "k", regex_cc$$module$src$lang$latin$advanced, "k", regex_th$$module$src$lang$latin$advanced, "t", regex_dt$$module$src$lang$latin$advanced, "t", regex_ph$$module$src$lang$latin$advanced, "f", regex_pf$$module$src$lang$latin$advanced, "f", regex_ou$$module$src$lang$latin$advanced, "o", regex_uo$$module$src$lang$latin$advanced, "u"]; -function encode$$module$src$lang$latin$advanced(str, _skip_postprocessing) { +function encode$$module$src$lang$latin$advanced(str, self, _skip_postprocessing) { if (str) { - str = encode$$module$src$lang$latin$simple(str, this).join(" "); + str = encode$$module$src$lang$latin$simple(str, self || this).join(" "); if (str.length > 2) { str = replace$$module$src$common(str, pairs$$module$src$lang$latin$advanced); } @@ -1619,7 +1625,7 @@ var regex_vowel$$module$src$lang$latin$extra = regex$$module$src$common(prefix$$ var pairs$$module$src$lang$latin$extra = [soundex_b$$module$src$lang$latin$extra, "b", soundex_s$$module$src$lang$latin$extra, "s", soundex_k$$module$src$lang$latin$extra, "k", soundex_m$$module$src$lang$latin$extra, "m", soundex_t$$module$src$lang$latin$extra, "t", soundex_f$$module$src$lang$latin$extra, "f", regex_vowel$$module$src$lang$latin$extra, ""]; function encode$$module$src$lang$latin$extra(str) { if (str) { - str = encode$$module$src$lang$latin$advanced(str, true); + str = encode$$module$src$lang$latin$advanced(str, this, true); if (str.length > 1) { str = replace$$module$src$common(str, pairs$$module$src$lang$latin$extra); } @@ -1704,9 +1710,9 @@ module$src$lang$latin$soundex.tokenize = tokenize$$module$src$lang$latin$soundex var rtl$$module$src$lang$arabic$default = true; var tokenize$$module$src$lang$arabic$default = ""; var $jscompDefaultExport$$module$src$lang$arabic$default = {encode:encode$$module$src$lang$arabic$default, rtl:rtl$$module$src$lang$arabic$default}; -var split$$module$src$lang$arabic$default = /[\W_]+/; +var regex$$module$src$lang$arabic$default = /[\x00-\x7F]+/g; function encode$$module$src$lang$arabic$default(str) { - return this.pipeline(str, false, split$$module$src$lang$arabic$default, false); + return this.pipeline(str.replace(regex$$module$src$lang$arabic$default, " "), false, " ", false); } var module$src$lang$arabic$default = {}; module$src$lang$arabic$default.default = $jscompDefaultExport$$module$src$lang$arabic$default; @@ -1716,7 +1722,7 @@ module$src$lang$arabic$default.tokenize = tokenize$$module$src$lang$arabic$defau var rtl$$module$src$lang$cjk$default = false; var tokenize$$module$src$lang$cjk$default = "strict"; var $jscompDefaultExport$$module$src$lang$cjk$default = {encode:encode$$module$src$lang$cjk$default, rtl:rtl$$module$src$lang$cjk$default, tokenize:tokenize$$module$src$lang$cjk$default}; -var regex$$module$src$lang$cjk$default = /[\x00-\x7F]/g; +var regex$$module$src$lang$cjk$default = /[\x00-\x7F]+/g; function encode$$module$src$lang$cjk$default(str) { return this.pipeline(str.replace(regex$$module$src$lang$cjk$default, ""), false, "", false); } @@ -1728,9 +1734,9 @@ module$src$lang$cjk$default.tokenize = tokenize$$module$src$lang$cjk$default; var rtl$$module$src$lang$cyrillic$default = false; var tokenize$$module$src$lang$cyrillic$default = ""; var $jscompDefaultExport$$module$src$lang$cyrillic$default = {encode:encode$$module$src$lang$cyrillic$default, rtl:rtl$$module$src$lang$cyrillic$default}; -var split$$module$src$lang$cyrillic$default = /[\W_]+/; +var regex$$module$src$lang$cyrillic$default = /[\x00-\x7F]+/g; function encode$$module$src$lang$cyrillic$default(str) { - return this.pipeline(str, false, split$$module$src$lang$cyrillic$default, false); + return this.pipeline(str.replace(regex$$module$src$lang$cyrillic$default, " "), false, " ", false); } var module$src$lang$cyrillic$default = {}; module$src$lang$cyrillic$default.default = $jscompDefaultExport$$module$src$lang$cyrillic$default; diff --git a/dist/flexsearch.es5.js b/dist/flexsearch.es5.js index f62203e..8697ac3 100644 --- a/dist/flexsearch.es5.js +++ b/dist/flexsearch.es5.js @@ -5,33 +5,33 @@ * Licence: Apache-2.0 * https://github.com/nextapps-de/flexsearch */ -(function(){'use strict';Object.assign||(Object.assign=function(){for(var a=arguments,b=a.length,c=a[0],e=1,d,g,f;ed;c--)f=g[c-1],g[c]=f,e[f]=c;g[d]=a;e[a]=d}}}return b};var S={},da="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;function fa(a,b,c){var e=ha,d="flexsearch";e=da?URL.createObjectURL(new Blob(["("+e.toString()+")()"],{type:"text/javascript"})):d+".browser.js";d+="-"+a;S[d]||(S[d]=[]);S[d][c]=new Worker(e);S[d][c].onmessage=b;console.log("Register Worker: "+d+"@"+c);return S[d][c]} -function ha(){var a,b;self.onmessage=function(c){if(c=c.data)if(c.search){var e=b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold,where:c.where}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:e})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.info?(c=b.info(),c.worker=a,console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!1,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+ -1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}}function ia(a,b,c,e){a=fa("id"+a,function(g){(g=g.data)&&g.result&&e(g.id,g.content,g.result,g.limit,g.where,g.cursor,g.suggest)},b);var d=M.toString();c.id=b;a.postMessage({register:d,options:c,id:b});return a}M.prototype.G=function(a,b,c,e){this.v!==this.A&&(this.s=this.s.concat(c),this.v++,e&&this.s.length>=e&&(this.v=this.A),this.v===this.A&&(this.cache&&this.f.set(b,this.s),this.C&&this.C(this.s)));return this};var U={memory:{encode:"extra",j:"strict",threshold:0,h:1},speed:{encode:"icase",j:"strict",threshold:1,h:3,depth:2},match:{encode:"extra",j:"full",threshold:1,h:3},score:{encode:"extra",j:"strict",threshold:1,h:9,depth:4},balance:{encode:"balance",j:"strict",threshold:0,h:3,depth:3},fast:{encode:"icase",j:"strict",threshold:8,h:9,depth:1}};var ka={encode:ja,c:!1},la=/[\W_]+/;function ja(a){return L(this,a.toLowerCase(),!1,la)};var ma={encode:ja,tokenize:"strict",cache:!1,async:!1,worker:!1,rtl:!1,doc:!1,resolution:9,threshold:0,depth:0},na=0,oa={},V={};function M(a){if(!(this instanceof M))return new M(a);var b=a&&a.id;this.id=b||0===b?b:na++;this.init(a);pa(this,"index",function(){return Object.keys(this.g)});pa(this,"length",function(){return this.index.length})}M.registerCharset=function(a,b){V[a]=b;return M};M.registerLanguage=function(a,b){V[a]=b;return M}; -M.prototype.init=function(a){var b,c;if(t(a))U[a]||console.warn("Preset not found: "+a),a=U[a];else if(b=a.preset)U[b]||console.warn("Preset not found: "+b),a=Object.assign({},U[b],a);this.encode||(a?a=Object.assign({},ma,a):a=ma);if(a){if(b=a.worker){if("undefined"===typeof fa)a.worker=!1,this.D=null;else{var e=parseInt(b,10)||4;this.v=0;this.s=[];this.C=null;this.D=Array(e);for(c=0;cv;A--)u=l.substring(v,A),X(r,d,u,a,y,w,h,m-1);break;default:if(n=X(r,d,l,a,1,w,h,m-1),k&&1=h)for(n=d._ctx[l]||(d._ctx[l]=D()),l=this.i[l]||(this.i[l]=ba(m-(h||0))),w=p-k,u=p+ -k+1,0>w&&(w=0),u>f&&(u=f);w=f&&(a=a[h-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=e);return d} -function sa(a,b){if(a)for(var c=Object.keys(a),e=0,d=c.length;ef&&(k=0);k=k||0;var K=k+b;Ke;c--)g=f[c-1],f[c]=g,d[g]=c;f[e]=a;d[a]=e}}}return b};var S={},ea="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;function fa(a,b,c){var d=ha,e="flexsearch";d=ea?URL.createObjectURL(new Blob(["("+d.toString()+")()"],{type:"text/javascript"})):e+".browser.js";e+="-"+a;S[e]||(S[e]=[]);S[e][c]=new Worker(d);S[e][c].onmessage=b;console.log("Register Worker: "+e+"@"+c);return S[e][c]} +function ha(){var a,b;self.onmessage=function(c){if(c=c.data)if(c.search){var d=b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold,where:c.where}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:d})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.info?(c=b.info(),c.worker=a,console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!1,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+ +1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}}function ia(a,b,c,d){a=fa("id"+a,function(f){(f=f.data)&&f.result&&d(f.id,f.content,f.result,f.limit,f.where,f.cursor,f.suggest)},b);var e=O.toString();c.id=b;a.postMessage({register:e,options:c,id:b});return a}O.prototype.G=function(a,b,c,d){this.s!==this.v&&(this.o=this.o.concat(c),this.s++,d&&this.o.length>=d&&(this.s=this.v),this.s===this.v&&(this.cache&&this.g.set(b,this.o),this.C&&this.C(this.o)));return this};var U={memory:{charset:"latin:extra",threshold:0,c:1},speed:{threshold:1,c:3,depth:2},match:{charset:"latin:extra",B:"full",threshold:1,c:3},score:{charset:"latin:extra",threshold:1,c:9,depth:4},balance:{charset:"latin:balance",threshold:0,c:3,depth:3},fast:{threshold:8,c:9,depth:1}};var ka={encode:ja,h:!1},la=/[\W_]+/;function ja(a){return L(this,a.toLowerCase(),!1,la)};var ma=0,na={},V={};function O(a){if(!(this instanceof O))return new O(a);var b=a&&a.id;this.id=b||0===b?b:ma++;this.init(a);oa(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});oa(this,"length",function(){return this.index.length})}O.registerCharset=function(a,b){V[a]=b;return O};O.registerLanguage=function(a,b){na[a]=b;return O}; +O.prototype.init=function(a){var b,c;if(a)if(t(a))U[a]||console.warn("Preset not found: "+a),a=U[a];else if(b=a.preset)U[b]||console.warn("Preset not found: "+b),a=Object.assign({},U[b],a);a||(a={});if(b=a.worker){if("undefined"===typeof fa)a.worker=!1,this.m=null;else{var d=parseInt(b,10)||4;this.s=0;this.o=[];this.C=null;this.m=Array(d);for(var e=0;eu;B--)x=n.substring(u,B),X(r,e,x,a,A,v,k,q-1);break;default:if(w=X(r,e,n,a,1,v,k,q-1),m&&1=k)for(w=e._ctx[n]||(e._ctx[n]=F()),n=this.i[n]||(this.i[n]=ba(q-(k||0))),v=l-m, +x=l+m+1,0>v&&(v=0),x>h&&(x=h);v=g&&(a=a[h-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e} +function ra(a,b){if(a)for(var c=Object.keys(a),d=0,e=c.length;db?1:0}function ua(a,b){for(var c=Y.length,d=0;db?1:0}function Z(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c} +function ta(a,b,c,d,e,f,g){var h=[];if(!0===c){c="0";var k=""}else k=c&&c.split(":");var m=a.length;if(1g&&(k=0);k=k||0;var J=k+b;Jk;u--)r=q.substring(k,u),N(f,c,r,a,t,n,d,g-1);break;default:if(m=N(f,c,q,a,1,n,d,g-1),h&&1=d)for(m=c._ctx[q]||(c._ctx[q]=z()),q=this.b[q]||(this.b[q]=y(g-(d||0))),n=l-h,r=l+h+1,0>n&&(n=0),r>e&&(r=e);nx&&(f=0);A=f||0;var D=A+b;D=g&&(a=a[f-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=e);return d}function O(a,b){if(a)for(var c=Object.keys(a),e=0,d=c.length;ek;z--)l=n.substring(k,z),N(f,c,l,a,w,r,d,g-1);break;default:if(p=N(f,c,n,a,1,r,d,g-1),h&&1=d)for(p=c._ctx[n]||(c._ctx[n]=B()),n=this.c[n]||(this.c[n]=y(g-(d||0))),r=q-h,l=q+h+1,0>r&&(r=0),l>e&&(l=e);rx&&(f=0);A=f||0;var D=A+b;D=g&&(a=a[f-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=e);return d}function Q(a,b){if(a)for(var c=Object.keys(a),e=0,d=c.length;ed;c--)f=g[c-1],g[c]=f,e[f]=c;g[d]=a;e[a]=d}}}return b};var U={},ca="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;function ea(a,b,c){var e=fa,d="flexsearch";e=ca?URL.createObjectURL(new Blob(["("+e.toString()+")()"],{type:"text/javascript"})):d+".browser.js";d+="-"+a;U[d]||(U[d]=[]);U[d][c]=new Worker(e);U[d][c].onmessage=b;return U[d][c]} -function fa(){var a,b;self.onmessage=function(c){if(c=c.data)if(c.search){var e=b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold,where:c.where}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:e})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.info?(c=b.info(),c.worker=a,console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!1,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+ -1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}}function ha(a,b,c,e){a=ea("id"+a,function(g){(g=g.data)&&g.result&&e(g.id,g.content,g.result,g.limit,g.where,g.cursor,g.suggest)},b);var d=O.toString();c.id=b;a.postMessage({register:d,options:c,id:b});return a}O.prototype.G=function(a,b,c,e){this.v!==this.A&&(this.s=this.s.concat(c),this.v++,e&&this.s.length>=e&&(this.v=this.A),this.v===this.A&&(this.cache&&this.f.set(b,this.s),this.C&&this.C(this.s)));return this};var ia={memory:{encode:"extra",j:"strict",threshold:0,h:1},speed:{encode:"icase",j:"strict",threshold:1,h:3,depth:2},match:{encode:"extra",j:"full",threshold:1,h:3},score:{encode:"extra",j:"strict",threshold:1,h:9,depth:4},balance:{encode:"balance",j:"strict",threshold:0,h:3,depth:3},fast:{encode:"icase",j:"strict",threshold:8,h:9,depth:1}};var ka={encode:ja,c:!1},la=/[\W_]+/;function ja(a){return M(this,a.toLowerCase(),!1,la)};var ma={encode:ja,tokenize:"strict",cache:!1,async:!1,worker:!1,rtl:!1,doc:!1,resolution:9,threshold:0,depth:0},na=0,oa={},V={};function O(a){if(!(this instanceof O))return new O(a);var b=a&&a.id;this.id=b||0===b?b:na++;this.init(a);pa(this,"index",function(){return Object.keys(this.g)});pa(this,"length",function(){return this.index.length})}O.registerCharset=function(a,b){V[a]=b;return O};O.registerLanguage=function(a,b){V[a]=b;return O}; -O.prototype.init=function(a){var b,c;if(t(a))a=ia[a];else if(b=a.preset)a=Object.assign({},ia[b],a);this.encode||(a?a=Object.assign({},ma,a):a=ma);if(a){if(b=a.worker){if("undefined"===typeof ea)a.worker=!1,this.D=null;else{var e=parseInt(b,10)||4;this.v=0;this.s=[];this.C=null;this.D=Array(e);for(c=0;cv;A--)u=l.substring(v,A),X(r,d,u,a,y,w,h,m-1);break;default:if(n=X(r,d,l,a,1,w,h,m-1),k&&1=h)for(n=d._ctx[l]||(d._ctx[l]=G()),l=this.i[l]||(this.i[l]=aa(m-(h||0))),w=p-k,u=p+ -k+1,0>w&&(w=0),u>f&&(u=f);w=f&&(a=a[h-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=e);return d} -function sa(a,b){if(a)for(var c=Object.keys(a),e=0,d=c.length;ef&&(k=0);k=k||0;var K=k+b;Ke;c--)g=f[c-1],f[c]=g,d[g]=c;f[e]=a;d[a]=e}}}return b};var U={},da="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;function ea(a,b,c){var d=fa,e="flexsearch";d=da?URL.createObjectURL(new Blob(["("+d.toString()+")()"],{type:"text/javascript"})):e+".browser.js";e+="-"+a;U[e]||(U[e]=[]);U[e][c]=new Worker(d);U[e][c].onmessage=b;return U[e][c]} +function fa(){var a,b;self.onmessage=function(c){if(c=c.data)if(c.search){var d=b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold,where:c.where}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:d})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.info?(c=b.info(),c.worker=a,console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!1,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+ +1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}}function ha(a,b,c,d){a=ea("id"+a,function(f){(f=f.data)&&f.result&&d(f.id,f.content,f.result,f.limit,f.where,f.cursor,f.suggest)},b);var e=P.toString();c.id=b;a.postMessage({register:e,options:c,id:b});return a}P.prototype.G=function(a,b,c,d){this.s!==this.v&&(this.o=this.o.concat(c),this.s++,d&&this.o.length>=d&&(this.s=this.v),this.s===this.v&&(this.cache&&this.g.set(b,this.o),this.C&&this.C(this.o)));return this};var ia={memory:{charset:"latin:extra",threshold:0,c:1},speed:{threshold:1,c:3,depth:2},match:{charset:"latin:extra",B:"full",threshold:1,c:3},score:{charset:"latin:extra",threshold:1,c:9,depth:4},balance:{charset:"latin:balance",threshold:0,c:3,depth:3},fast:{threshold:8,c:9,depth:1}};var ka={encode:ja,h:!1},la=/[\W_]+/;function ja(a){return O(this,a.toLowerCase(),!1,la)};var ma=0,na={},V={};function P(a){if(!(this instanceof P))return new P(a);var b=a&&a.id;this.id=b||0===b?b:ma++;this.init(a);oa(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});oa(this,"length",function(){return this.index.length})}P.registerCharset=function(a,b){V[a]=b;return P};P.registerLanguage=function(a,b){na[a]=b;return P}; +P.prototype.init=function(a){var b,c;if(a)if(t(a))a=ia[a];else if(b=a.preset)a=Object.assign({},ia[b],a);a||(a={});if(b=a.worker){if("undefined"===typeof ea)a.worker=!1,this.m=null;else{var d=parseInt(b,10)||4;this.s=0;this.o=[];this.C=null;this.m=Array(d);for(var e=0;eu;B--)x=n.substring(u,B),X(r,e,x,a,A,v,k,q-1);break;default:if(w=X(r,e,n,a,1,v,k,q-1),m&&1=k)for(w=e._ctx[n]||(e._ctx[n]=G()),n=this.i[n]||(this.i[n]=aa(q-(k||0))),v=l-m, +x=l+m+1,0>v&&(v=0),x>h&&(x=h);v=g&&(a=a[h-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e} +function ra(a,b){if(a)for(var c=Object.keys(a),d=0,e=c.length;db?1:0}function ua(a,b){for(var c=Y.length,d=0;db?1:0}function Z(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c} +function ta(a,b,c,d,e,f,g){var h=[];if(!0===c){c="0";var k=""}else k=c&&c.split(":");var m=a.length;if(1g&&(k=0);k=k||0;var J=k+b;Jd;c--)f=h[c-1],h[c]=f,e[f]=c;h[d]=a;e[a]=d}}}return b};var da={memory:{encode:"extra",i:"strict",threshold:0,g:1},speed:{encode:"icase",i:"strict",threshold:1,g:3,depth:2},match:{encode:"extra",i:"full",threshold:1,g:3},score:{encode:"extra",i:"strict",threshold:1,g:9,depth:4},balance:{encode:"balance",i:"strict",threshold:0,g:3,depth:3},fast:{encode:"icase",i:"strict",threshold:8,g:9,depth:1}};var fa={encode:ea,c:!1},ha=/[\W_]+/;function ea(a){return M(this,a.toLowerCase(),!1,ha)};var ia={encode:ea,tokenize:"strict",cache:!1,async:!1,worker:!1,rtl:!1,doc:!1,resolution:9,threshold:0,depth:0},ja=0,U={},V={};function O(a){if(!(this instanceof O))return new O(a);var b=a&&a.id;this.id=b||0===b?b:ja++;this.init(a);ka(this,"index",function(){return Object.keys(this.f)});ka(this,"length",function(){return this.index.length})}O.registerCharset=function(a,b){V[a]=b;return O};O.registerLanguage=function(a,b){V[a]=b;return O}; -O.prototype.init=function(a){var b;if(t(a))a=da[a];else if(b=a.preset)a=Object.assign({},da[b],a);this.encode||(a?a=Object.assign({},ia,a):a=ia);if(a){this.async=a.async;var c=a.charset;var e=a.lang;this.v=(t(c)?V[c].i:c&&c.i)||a.tokenize;this.c=t(b=a.rtl||c)?V[b].c:c&&c.c||b;this.threshold=a.threshold;this.g=(b=a.resolution)<=this.threshold?this.threshold+1:b;this.depth="strict"===this.v&&a.depth||0;this.encode=t(b=a.encode||c)?V[-1===b.indexOf(":")?b+":default":b].encode:c&&c.encode||b;this.o=(b= -a.matcher||e)&&la(t(b)?U[b].o:e&&e.o||b,!1);if(c=b=a.filter||e){c=t(b)?U[b].filter:e&&e.filter||b;for(var d=G(),h=0,f=c.length;hv;A--)u=l.substring(v,A),X(r,d,u,a,x,w,g,m-1);break;default:if(n=X(r,d,l,a,1,w,g,m-1),k&&1=g)for(n=d._ctx[l]||(d._ctx[l]=G()),l=this.h[l]||(this.h[l]=aa(m-(g||0))),w=p-k,u=p+k+1,0>w&&(w=0),u>f&&(u=f);w=f&&(a=a[g-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=e);return d} -function na(a,b){if(a)for(var c=Object.keys(a),e=0,d=c.length;ef&&(k=0);k=k||0;var K=k+b;Ke;c--)g=f[c-1],f[c]=g,d[g]=c;f[e]=a;d[a]=e}}}return b};var da={memory:{charset:"latin:extra",threshold:0,c:1},speed:{threshold:1,c:3,depth:2},match:{charset:"latin:extra",u:"full",threshold:1,c:3},score:{charset:"latin:extra",threshold:1,c:9,depth:4},balance:{charset:"latin:balance",threshold:0,c:3,depth:3},fast:{threshold:8,c:9,depth:1}};var fa={encode:ea,g:!1},ha=/[\W_]+/;function ea(a){return O(this,a.toLowerCase(),!1,ha)};var ia=0,ja={},U={};function P(a){if(!(this instanceof P))return new P(a);var b=a&&a.id;this.id=b||0===b?b:ia++;this.init(a);ka(this,"index",function(){return this.a?Object.keys(this.a.index[this.a.keys[0]].f):Object.keys(this.f)});ka(this,"length",function(){return this.index.length})}P.registerCharset=function(a,b){U[a]=b;return P};P.registerLanguage=function(a,b){ja[a]=b;return P}; +P.prototype.init=function(a){var b,c;if(a)if(t(a))a=da[a];else if(b=a.preset)a=Object.assign({},da[b],a);a||(a={});this.async=a.async;var d=a.charset,e=a.lang;t(d)&&(-1===d.indexOf(":")&&(d+=":default"),d=U[d]);t(e)&&(e=ja[e]);this.v=b=d&&d.u||a.tokenize||"strict";this.depth="strict"===b&&a.depth||0;this.g=d&&d.g||a.rtl||!1;this.c=a.resolution||9;this.threshold=b=a.threshold||0;this.c<=b&&(this.c=b+1);this.encode=a.encode||d&&d.encode||ea;this.m=(b=a.matcher||e&&e.m)&&la(b,!1);this.s=(b=a.stemmer|| +e&&e.s)&&la(b,!0);if(d=b=a.filter||e&&e.filter){d=b;e=G();var f=0;for(c=d.length;fu;B--)x=n.substring(u,B),W(r,e,x,a,A,v,k,q-1);break;default:if(w=W(r,e,n,a,1,v,k,q-1),m&&1=k)for(w=e._ctx[n]||(e._ctx[n]=G()),n=this.h[n]||(this.h[n]=aa(q-(k||0))),v=l-m,x=l+m+1,0>v&&(v=0),x>h&&(x=h);v=g&&(a=a[h-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return e} +function X(a,b){if(a)for(var c=Object.keys(a),d=0,e=c.length;db?1:0}function pa(a,b){for(var c=Y.length,d=0;db?1:0}function Z(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c} +function oa(a,b,c,d,e,f,g){var h=[];if(!0===c){c="0";var k=""}else k=c&&c.split(":");var m=a.length;if(1g&&(k=0);k=k||0;var J=k+b;J d; c--) { - f = h[c - 1], h[c] = f, e[f] = c; + f = g[c - 1], g[c] = f, e[f] = c; } - h[d] = a; + g[d] = a; e[a] = d; } } } return b; }; -var ba = {memory:{encode:"extra", tokenize:"strict", threshold:0, resolution:1}, speed:{encode:"icase", tokenize:"strict", threshold:1, resolution:3, depth:2}, match:{encode:"extra", tokenize:"full", threshold:1, resolution:3}, score:{encode:"extra", tokenize:"strict", threshold:1, resolution:9, depth:4}, balance:{encode:"balance", tokenize:"strict", threshold:0, resolution:3, depth:3}, fast:{encode:"icase", tokenize:"strict", threshold:8, resolution:9, depth:1}}; +var ba = {memory:{charset:"latin:extra", threshold:0, resolution:1}, speed:{threshold:1, resolution:3, depth:2}, match:{charset:"latin:extra", tokenize:"full", threshold:1, resolution:3}, score:{charset:"latin:extra", threshold:1, resolution:9, depth:4}, balance:{charset:"latin:balance", threshold:0, resolution:3, depth:3}, fast:{threshold:8, resolution:9, depth:1}}; var da = {encode:ca, rtl:!1}, ea = /[\W_]+/; function ca(a) { return this.pipeline(a.toLowerCase(), !1, ea, !1); } -;var fa = {encode:ca, tokenize:"strict", cache:!1, async:!1, worker:!1, rtl:!1, doc:!1, resolution:9, threshold:0, depth:0}, ha = 0, U = {}, V = {}; -function O(a) { - if (!(this instanceof O)) { - return new O(a); +;var fa = 0, U = {}, V = {}; +function R(a) { + if (!(this instanceof R)) { + return new R(a); } var b = a && a.id; - this.id = b || 0 === b ? b : ha++; + this.id = b || 0 === b ? b : fa++; this.init(a); - ia(this, "index", function() { - return Object.keys(this._ids); + ha(this, "index", function() { + return this.doc ? Object.keys(this.doc.index[this.doc.keys[0]]._ids) : Object.keys(this._ids); }); - ia(this, "length", function() { + ha(this, "length", function() { return this.index.length; }); } -O.registerCharset = function(a, b) { +R.registerCharset = function(a, b) { V[a] = b; - return O; + return R; }; -O.registerLanguage = function(a, b) { - V[a] = b; - return O; +R.registerLanguage = function(a, b) { + U[a] = b; + return R; }; -O.prototype.init = function(a) { - var b; - if (q(a)) { - a = ba[a]; - } else { - if (b = a.preset) { - a = Object.assign({}, ba[b], a); - } - } - this.encode || (a = a ? Object.assign({}, fa, a) : fa); +R.prototype.init = function(a) { + var b, c; if (a) { - this.async = a.async; - this.timer = 0; - var c = a.charset; - var e = a.lang; - this.tokenizer = (q(c) ? V[c].tokenize : c && c.tokenize) || a.tokenize; - this.rtl = q(b = a.rtl || c) ? V[b].rtl : c && c.rtl || b; - this.threshold = a.threshold; - this.resolution = (b = a.resolution) <= this.threshold ? this.threshold + 1 : b; - this.depth = "strict" === this.tokenizer && a.depth || 0; - this.encode = q(b = a.encode || c) ? V[-1 === b.indexOf(":") ? b + ":default" : b].encode : c && c.encode || b; - this.matcher = (b = a.matcher || e) && ja(q(b) ? U[b].matcher : e && e.matcher || b, !1); - if (c = b = a.filter || e) { - c = q(b) ? U[b].filter : e && e.filter || b; - for (var d = F(), h = 0, f = c.length; h < f; h++) { - d[c[h]] = 1; + if (r(a)) { + a = ba[a]; + } else { + if (b = a.preset) { + a = Object.assign({}, ba[b], a); } - c = d; } - this.filter = c; - this.stemmer = (b = a.stemmer || e) && ja(q(b) ? U[b].stemmer : e && e.stemmer || b, !0); - (this.doc = c = (b = a.doc) && ka(b)) && (a.doc = null); } - this._map = aa(this.resolution - (this.threshold || 0)); - this._ctx = F(); - this._ids = {}; + a || (a = {}); + this.async = a.async; + this.timer = 0; + var e = a.charset, d = a.lang; + r(e) && (-1 === e.indexOf(":") && (e += ":default"), e = V[e]); + r(d) && (d = U[d]); + this.tokenizer = b = e && e.tokenize || a.tokenize || "strict"; + this.depth = "strict" === b && a.depth || 0; + this.rtl = e && e.rtl || a.rtl || !1; + this.resolution = a.resolution || 9; + this.threshold = b = a.threshold || 0; + this.resolution <= b && (this.resolution = b + 1); + this.encode = a.encode || e && e.encode || ca; + this.matcher = (b = a.matcher || d && d.matcher) && ia(b, !1); + this.stemmer = (b = a.stemmer || d && d.stemmer) && ia(b, !0); + if (e = b = a.filter || d && d.filter) { + e = b; + d = G(); + var g = 0; + for (c = e.length; g < c; g++) { + d[e[g]] = 1; + } + e = d; + } + this.filter = e; + (this.doc = c = (b = a.doc) && ja(b)) && (a.doc = null); + this._map = aa(this.resolution - this.threshold); + this._ctx = G(); + this._ids = G(); if (c) { - this._doc = F(); - b = c.index = {}; - e = c.keys = []; - d = c.field; - h = c.tag; - f = c.store; - x(c.id) || (c.id = c.id.split(":")); - if (f) { - var g = F(); - if (q(f)) { - g[f] = 1; + this._doc = G(); + e = c.index = {}; + d = c.keys = []; + g = c.field; + var f = c.tag, h = c.store; + y(c.id) || (c.id = c.id.split(":")); + if (h) { + var k = G(); + if (r(h)) { + k[h] = 1; } else { - if (x(f)) { - for (var k = 0; k < f.length; k++) { - g[f[k]] = 1; + if (y(h)) { + for (var m = 0; m < h.length; m++) { + k[h[m]] = 1; } } else { - B(f) && (g = f); + E(h) && (k = h); } } - c.store = g; + c.store = k; } - if (h) { - this._tag = F(); - f = F(); - if (d) { - if (q(d)) { - f[d] = a; + if (f) { + this._tag = G(); + h = G(); + if (g) { + if (r(g)) { + h[g] = a; } else { - if (x(d)) { - for (g = 0; g < d.length; g++) { - f[d[g]] = a; + if (y(g)) { + for (k = 0; k < g.length; k++) { + h[g[k]] = a; } } else { - B(d) && (f = d); + E(g) && (h = g); } } } - x(h) || (c.tag = h = [h]); - for (d = 0; d < h.length; d++) { - this._tag[h[d]] = F(); + y(f) || (c.tag = f = [f]); + for (g = 0; g < f.length; g++) { + this._tag[f[g]] = G(); } - this._tags = h; - d = f; + this._tags = f; + g = h; } - if (d) { - if (!x(d)) { - if (B(d)) { - var l = d; - c.field = d = Object.keys(d); + if (g) { + if (!y(g)) { + if (E(g)) { + var q = g; + c.field = g = Object.keys(g); } else { - c.field = d = [d]; + c.field = g = [g]; } } - for (c = 0; c < d.length; c++) { - h = d[c], x(h) || (l && (a = l[h]), e[c] = h, d[c] = h.split(":")), b[h] = new O(a); + for (c = 0; c < g.length; c++) { + f = g[c], y(f) || (q && (a = q[f]), d[c] = f, g[c] = f.split(":")), e[f] = new R(a); } } } - if (b = a.cache) { - this._cache_status = !0, this._cache = new S(b); - } + this._cache_status = !0; + this._cache = (b = a.cache) && new S(b); return this; }; -function ka(a) { - var b = F(), c; +function ja(a) { + var b = G(), c; for (c in a) { if (a.hasOwnProperty(c)) { var e = a[c]; - x(e) ? b[c] = e.slice(0) : B(e) ? b[c] = ka(e) : b[c] = e; + y(e) ? b[c] = e.slice(0) : E(e) ? b[c] = ja(e) : b[c] = e; } } return b; } -O.prototype.add = function(a, b, c, e, d) { - if (this.doc && B(a)) { +R.prototype.add = function(a, b, c, e, d) { + if (this.doc && E(a)) { return this.handle_docs("add", a, b); } - if (b && q(b) && (a || 0 === a)) { + if (b && r(b) && (a || 0 === a)) { if (this._ids[a] && !e) { return this.update(a, b); } if (!d) { if (this.async) { - var h = this; - d = new Promise(function(c) { + var g = this, f = new Promise(function(c) { setTimeout(function() { - h.add(a, b, null, e, !0); - h = null; + g.add(a, b, null, e, !0); + g = null; c(); }); }); if (c) { - d.then(c); + f.then(c); } else { - return d; + return f; } return this; } @@ -421,119 +422,121 @@ O.prototype.add = function(a, b, c, e, d) { return this; } c = b; - d = F(); - d._ctx = F(); - for (var f = c.length, g = this.threshold, k = this.depth, l = this.resolution, r = this._map, t = this.rtl, n = 0; n < f; n++) { - var m = c[n]; - if (m) { - var p = m.length, w = (t ? n + 1 : f - n) / f, u = ""; + d = G(); + d._ctx = G(); + for (var h = c.length, k = this.threshold, m = this.depth, q = this.resolution, u = this._map, p = this.rtl, l = 0; l < h; l++) { + var n = c[l]; + if (n) { + f = 1; + var w = n.length, v = (p ? l + 1 : h - l) / h, x = ""; switch(this.tokenizer) { case "reverse": case "both": - for (var v = p; --v;) { - u = m[v] + u, W(r, d, u, a, t ? 1 : (p - v) / p, w, g, l - 1); + for (var t = w; --t;) { + x = n[t] + x, W(u, d, x, a, p ? 1 : (w - t) / w, v, k, q - 1); } - u = ""; + x = ""; case "forward": - for (v = 0; v < p; v++) { - u += m[v], W(r, d, u, a, t ? (v + 1) / p : 1, w, g, l - 1); + for (t = 0; t < w; t++) { + x += n[t], W(u, d, x, a, p ? (t + 1) / w : 1, v, k, q - 1); } break; case "full": - for (v = 0; v < p; v++) { - for (var y = (t ? v + 1 : p - v) / p, A = p; A > v; A--) { - u = m.substring(v, A), W(r, d, u, a, y, w, g, l - 1); + for (t = 0; t < w; t++) { + for (var A = (p ? t + 1 : w - t) / w, B = w; B > t; B--) { + x = n.substring(t, B), W(u, d, x, a, A, v, k, q - 1); } } break; default: - if (p = W(r, d, m, a, 1, w, g, l - 1), k && 1 < f && p >= g) { - for (p = d._ctx[m] || (d._ctx[m] = F()), m = this._ctx[m] || (this._ctx[m] = aa(l - (g || 0))), w = n - k, u = n + k + 1, 0 > w && (w = 0), u > f && (u = f); w < u; w++) { - w !== n && W(m, p, c[w], a, 0, l - (w < n ? n - w : w - n), g, l - 1); + if (w = W(u, d, n, a, 1, v, k, q - 1), m && 1 < h && w >= k) { + for (w = d._ctx[n] || (d._ctx[n] = G()), n = this._ctx[n] || (this._ctx[n] = aa(q - (k || 0))), v = l - m, x = l + m + 1, 0 > v && (v = 0), x > h && (x = h); v < x; v++) { + v !== l && W(n, w, c[v], a, 0, q - (v < l ? l - v : v - l), k, q - 1); } } } } } - this._ids[a] = 1; + f && (this._ids[a] = 1); this._cache_status = !1; } return this; }; -O.prototype.handle_docs = function(a, b, c) { - if (x(b)) { +R.prototype.handle_docs = function(a, b, c) { + if (y(b)) { var e = b.length; - if (e--) { + if (e) { for (var d = 0; d < e; d++) { - this.handle_docs(a, b[d]); + this.handle_docs(a, b[d], d === e - 1 && c); } - return this.handle_docs(a, b[e], c); } } else { - var h = this.doc.index, f = this.doc.keys, g = this.doc.tag; + var g = this.doc.index, f = this.doc.keys, h = this.doc.tag; d = this.doc.store; var k; - var l = this.doc.id; + var m = this.doc.id; e = b; - for (var r = 0; r < l.length; r++) { - e = e[l[r]]; + for (var q = 0; q < m.length; q++) { + e = e[m[q]]; } - if ("remove" === a && (delete this._doc[e], l = f.length, l--)) { - for (b = 0; b < l; b++) { - h[f[b]].remove(e); - } - return h[f[l]].remove(e, c); - } - if (g) { - for (k = 0; k < g.length; k++) { - var t = g[k]; - var n = b; - l = t.split(":"); - for (r = 0; r < l.length; r++) { - n = n[l[r]]; + if ("remove" === a) { + if (delete this._doc[e], b = f.length) { + for (d = 0; d < b; d++) { + g[f[d]].remove(e, d === b - 1 && c); } - n = "@" + n; } - k = this._tag[t]; - k = k[n] || (k[n] = []); - } - l = this.doc.field; - g = 0; - for (t = l.length; g < t; g++) { - r = l[g]; - n = b; - for (var m = 0; m < r.length; m++) { - n = n[r[m]]; + } else { + if (h) { + for (k = 0; k < h.length; k++) { + var u = h[k]; + var p = b; + m = u.split(":"); + for (q = 0; q < m.length; q++) { + p = p[m[q]]; + } + p = "@" + p; + } + k = this._tag[u]; + k = k[p] || (k[p] = []); } - r = h[f[g]]; - "add" === a ? r.add(e, n, g === t - 1 && c) : r.update(e, n, g === t - 1 && c); - } - if (d) { - c = Object.keys(d); - a = F(); - for (h = 0; h < c.length; h++) { - if (f = c[h], d[f]) { - for (f = f.split(":"), g = l = void 0, t = 0; t < f.length; t++) { - n = f[t], l = (l || b)[n], g = (g || a)[n] = l; + m = this.doc.field; + h = 0; + for (u = m.length; h < u; h++) { + q = m[h]; + p = b; + for (var l = 0; l < q.length; l++) { + p = p[q[l]]; + } + q = g[f[h]]; + "add" === a ? q.add(e, p, h === u - 1 && c) : q.update(e, p, h === u - 1 && c); + } + if (d) { + c = Object.keys(d); + a = G(); + for (g = 0; g < c.length; g++) { + if (f = c[g], d[f]) { + for (f = f.split(":"), h = m = void 0, u = 0; u < f.length; u++) { + p = f[u], m = (m || b)[p], h = (h || a)[p] = m; + } } } + b = a; } - b = a; + k && (k[k.length] = b); + this._doc[e] = b; } - k && (k[k.length] = b); - this._doc[e] = b; } return this; }; -O.prototype.update = function(a, b, c) { - if (this.doc && B(a)) { +R.prototype.update = function(a, b, c) { + if (this.doc && E(a)) { return this.handle_docs("update", a, b); } - this._ids[a] && q(b) && (this.remove(a), this.add(a, b, c, !0)); + this._ids[a] && r(b) && (this.remove(a), this.add(a, b, c, !0)); return this; }; -O.prototype.remove = function(a, b, c) { - if (this.doc && B(a)) { +R.prototype.remove = function(a, b, c) { + if (this.doc && E(a)) { return this.handle_docs("remove", a, b); } if (this._ids[a]) { @@ -568,11 +571,11 @@ O.prototype.remove = function(a, b, c) { return this; }; var Y; -O.prototype.merge_and_sort = function(a, b, c, e, d, h, f, g, k, l) { - c = la(c, f ? 0 : d, g, h, b, k, l); - if (g) { - g = c.page; - var r = c.next; +R.prototype.merge_and_sort = function(a, b, c, e, d, g, f, h, k, m) { + c = ka(c, f ? 0 : d, h, g, b, k, m); + if (h) { + h = c.page; + var q = c.next; c = c.result; } if (f) { @@ -581,20 +584,20 @@ O.prototype.merge_and_sort = function(a, b, c, e, d, h, f, g, k, l) { b = c; c = this._doc; d = b.length; - h = Array(d); + g = Array(d); for (f = 0; f < d; f++) { - h[f] = c[b[f]]; + g[f] = c[b[f]]; } - c = h; + c = g; } - e && (z(e) || (Y = e.split(":"), 1 < Y.length ? e = ma : (Y = Y[0], e = na)), c.sort(e)); - c = Z(g, r, c); + e && (z(e) || (Y = e.split(":"), e = 1 < Y.length ? la : ma), c.sort(e)); + c = Z(h, q, c); this._cache && this._cache.set(a, c); return c; }; -O.prototype.search = function(a, b, c, e) { - if (B(b)) { - if (x(b)) { +R.prototype.search = function(a, b, c, e) { + if (E(b)) { + if (y(b)) { for (var d = 0; d < b.length; d++) { b[d].query = a; } @@ -606,64 +609,64 @@ O.prototype.search = function(a, b, c, e) { } else { b && z(b) ? (c = b, b = 1000) : b || 0 === b || (b = 1000); } - var h = [], f = a; - if (B(a) && !x(a)) { + var g = [], f = a; + if (E(a) && !y(a)) { c || (c = a.callback) && (f.callback = null); - var g = a.sort; + var h = a.sort; var k = a.page; b = a.limit; - var l = a.threshold; - var r = a.suggest; + var m = a.threshold; + var q = a.suggest; a = a.query; } if (this.doc) { - l = this.doc.index; - var t = f.where, n = f.bool || "or", m = f.field, p = n, w, u; - if (m) { - x(m) || (m = [m]); + m = this.doc.index; + var u = f.where, p = f.bool || "or", l = f.field, n = p, w, v; + if (l) { + y(l) || (l = [l]); } else { - if (x(f)) { - var v = f; - m = []; - p = []; - for (var y = 0; y < f.length; y++) { - e = f[y], d = e.bool || n, m[y] = e.field, p[y] = d, "not" === d ? w = !0 : "and" === d && (u = !0); + if (y(f)) { + var x = f; + l = []; + n = []; + for (var t = 0; t < f.length; t++) { + e = f[t], d = e.bool || p, l[t] = e.field, n[t] = d, "not" === d ? w = !0 : "and" === d && (v = !0); } } else { - m = this.doc.keys; + l = this.doc.keys; } } - n = m.length; - for (y = 0; y < n; y++) { - v && (f = v[y]), k && !q(f) && (f.page = null, f.limit = 0), h[y] = l[m[y]].search(f, 0); + p = l.length; + for (t = 0; t < p; t++) { + x && (f = x[t]), k && !r(f) && (f.page = null, f.limit = 0), g[t] = m[l[t]].search(f, 0); } if (c) { - return c(this.merge_and_sort(a, p, h, g, b, r, t, k, u, w)); + return c(this.merge_and_sort(a, n, g, h, b, q, u, k, v, w)); } if (this.async) { var A = this; return new Promise(function(c) { - Promise.all(h).then(function(d) { - c(A.merge_and_sort(a, p, d, g, b, r, t, k, u, w)); + Promise.all(g).then(function(d) { + c(A.merge_and_sort(a, n, d, h, b, q, u, k, v, w)); }); }); } - return this.merge_and_sort(a, p, h, g, b, r, t, k, u, w); + return this.merge_and_sort(a, n, g, h, b, q, u, k, v, w); } - l || (l = this.threshold || 0); + m || (m = this.threshold || 0); if (!e) { if (this.async && "function" !== typeof importScripts) { - var H = this; - l = new Promise(function(a) { + var B = this; + m = new Promise(function(a) { setTimeout(function() { - a(H.search(f, b, null, !0)); - H = null; + a(B.search(f, b, null, !0)); + B = null; }); }); if (c) { - l.then(c); + m.then(c); } else { - return l; + return m; } return this; } @@ -671,8 +674,8 @@ O.prototype.search = function(a, b, c, e) { return c(this.search(f, b, null, !0)), this; } } - if (!a || !q(a)) { - return h; + if (!a || !r(a)) { + return g; } f = a; if (this._cache) { @@ -686,71 +689,71 @@ O.prototype.search = function(a, b, c, e) { } f = this.encode(f); if (!f.length) { - return h; + return g; } c = f; - v = c.length; + x = c.length; e = !0; d = []; - var P = F(), Q = 0; - 1 < v && (this.depth ? n = !0 : c.sort(oa)); - if (!n || (y = this._ctx)) { - for (var T = this.resolution; Q < v; Q++) { - var D = c[Q]; - if (D) { - if (n) { - if (!m) { - if (y[D]) { - m = D, P[D] = 1; + var N = G(), P = 0; + 1 < x && (this.depth ? p = !0 : c.sort(na)); + if (!p || (t = this._ctx)) { + for (var T = this.resolution; P < x; P++) { + var C = c[P]; + if (C) { + if (p) { + if (!l) { + if (t[C]) { + l = C, N[C] = 1; } else { - if (!r) { - return h; + if (!q) { + return g; } } } - if (r && Q === v - 1 && !d.length) { - n = !1, D = m || D, P[D] = 0; + if (q && P === x - 1 && !d.length) { + p = !1, C = l || C, N[C] = 0; } else { - if (!m) { + if (!l) { continue; } } } - if (!P[D]) { - var E = [], N = !1, I = 0, J = n ? y[m] : this._map; - if (J) { - for (var R = void 0, K = 0; K < T - l; K++) { - if (R = J[K] && J[K][D]) { - E[I++] = R, N = !0; + if (!N[C]) { + var D = [], M = !1, H = 0, I = p ? t[l] : this._map; + if (I) { + for (var Q = void 0, J = 0; J < T - m; J++) { + if (Q = I[J] && I[J][C]) { + D[H++] = Q, M = !0; } } } - if (N) { - m = D, d[d.length] = 1 < I ? E.concat.apply([], E) : E[0]; + if (M) { + l = C, d[d.length] = 1 < H ? D.concat.apply([], D) : D[0]; } else { - if (!r) { + if (!q) { e = !1; break; } } - P[D] = 1; + N[C] = 1; } } } } else { e = !1; } - e && (h = la(d, b, k, r)); - this._cache && this._cache.set(a, h); - return h; + e && (g = ka(d, b, k, q)); + this._cache && this._cache.set(a, g); + return g; }; -O.prototype.info = function() { +R.prototype.info = function() { return {id:this.id, items:this.length, matcher:this.matcher.length, worker:this.worker, threshold:this.threshold, depth:this.depth, resolution:this.resolution, contextual:this.depth && "strict" === this.tokenizer}; }; -O.prototype.clear = function() { +R.prototype.clear = function() { return this.destroy().init(); }; -O.prototype.destroy = function() { +R.prototype.destroy = function() { this._cache && (this._cache.clear(), this._cache = null); this._map = this._ctx = this._ids = null; if (this.doc) { @@ -761,230 +764,231 @@ O.prototype.destroy = function() { } return this; }; -function ia(a, b, c) { +function ha(a, b, c) { Object.defineProperty(a, b, {get:c}); } -function W(a, b, c, e, d, h, f, g) { +function W(a, b, c, e, d, g, f, h) { if (b[c]) { return b[c]; } - d = d ? (g - (f || g / 1.5)) * h + (f || g / 1.5) * d : h; + d = d ? (h - (f || h / 1.5)) * g + (f || h / 1.5) * d : g; b[c] = d; - d >= f && (a = a[g - (d + 0.5 >> 0)], a = a[c] || (a[c] = []), a[a.length] = e); + d >= f && (a = a[h - (d + 0.5 >> 0)], a = a[c] || (a[c] = []), a[a.length] = e); return d; } function X(a, b) { if (a) { for (var c = Object.keys(a), e = 0, d = c.length; e < d; e++) { - var h = c[e], f = a[h]; + var g = c[e], f = a[g]; if (f) { - for (var g = 0, k = f.length; g < k; g++) { - if (f[g] === b) { - 1 === k ? delete a[h] : f.splice(g, 1); + for (var h = 0, k = f.length; h < k; h++) { + if (f[h] === b) { + 1 === k ? delete a[g] : f.splice(h, 1); break; } else { - B(f[g]) && X(f[g], b); + E(f[h]) && X(f[h], b); } } } } } } -function ja(a, b) { - for (var c = Object.keys(a), e = c.length, d = [], h = "", f = 0, g = 0, k; g < e; g++) { - var l = c[g]; - (k = a[l]) ? (d[f++] = L(b ? "(?!\\b)" + l + "(\\b|_)" : l), d[f++] = k) : h += (h ? "|" : "") + l; +function ia(a, b) { + for (var c = Object.keys(a), e = c.length, d = [], g = "", f = 0, h = 0, k; h < e; h++) { + var m = c[h]; + (k = a[m]) ? (d[f++] = L(b ? "(?!\\b)" + m + "(\\b|_)" : m), d[f++] = k) : g += (g ? "|" : "") + m; } - h && (d[f++] = L(b ? "(?!\\b)(" + h + ")(\\b|_)" : "(" + h + ")"), d[f] = ""); + g && (d[f++] = L(b ? "(?!\\b)(" + g + ")(\\b|_)" : "(" + g + ")"), d[f] = ""); return d; } -function oa(a, b) { +function na(a, b) { return b.length - a.length; } -function na(a, b) { - return a[Y] - b[Y]; -} function ma(a, b) { + a = a[Y]; + b = b[Y]; + return a < b ? -1 : a > b ? 1 : 0; +} +function la(a, b) { for (var c = Y.length, e = 0; e < c; e++) { a = a[Y[e]], b = b[Y[e]]; } - return a - b; + return a < b ? -1 : a > b ? 1 : 0; } function Z(a, b, c) { return a ? {page:a, next:b ? "" + b : null, result:c} : c; } -function la(a, b, c, e, d, h, f) { - var g = []; +function ka(a, b, c, e, d, g, f) { + var h = []; if (!0 === c) { c = "0"; var k = ""; } else { k = c && c.split(":"); } - var l = a.length; - if (1 < l) { - var r = F(), t = [], n, m = 0, p, w = !0, u = 0, v; + var m = a.length; + if (1 < m) { + var q = G(), u = [], p, l = 0, n, w = !0, v = 0, x; if (k) { if (2 === k.length) { - var y = k; + var t = k; k = !1; } else { - k = v = parseInt(k[0], 10); + k = x = parseInt(k[0], 10); } } if (f) { - for (n = F(); m < l; m++) { - if ("not" === d[m]) { - var A = a[m]; - var H = A.length; - for (p = 0; p < H; p++) { - n["@" + A[p]] = 1; + for (p = G(); l < m; l++) { + if ("not" === d[l]) { + var A = a[l]; + var B = A.length; + for (n = 0; n < B; n++) { + p["@" + A[n]] = 1; } } else { - var P = m + 1; + var N = l + 1; } } - if (C(P)) { - return Z(c, K, g); + if (F(N)) { + return Z(c, J, h); } - m = 0; + l = 0; } else { - var Q = q(d) && d; + var P = r(d) && d; } - for (var T; m < l; m++) { - var D = m === (P || l) - 1; - if (!Q || !m) { - if ((p = Q || d && d[m]) && "and" !== p) { - if ("or" === p) { + for (var T; l < m; l++) { + var C = l === (N || m) - 1; + if (!P || !l) { + if ((n = P || d && d[l]) && "and" !== n) { + if ("or" === n) { T = !1; } else { continue; } } else { - T = h = !0; + T = g = !0; } } - A = a[m]; - if (H = A.length) { + A = a[l]; + if (B = A.length) { if (w) { - if (I) { - var E = I.length; - for (p = 0; p < E; p++) { - w = I[p]; - var N = "@" + w; - f && n[N] || (r[N] = 1, h || (g[u++] = w)); + if (H) { + var D = H.length; + for (n = 0; n < D; n++) { + w = H[n]; + var M = "@" + w; + f && p[M] || (q[M] = 1, g || (h[v++] = w)); } - var I = null; + var H = null; w = !1; } else { - I = A; + H = A; continue; } } - N = !1; - for (p = 0; p < H; p++) { - E = A[p]; - var J = "@" + E, R = h ? r[J] || 0 : m; - if (!(!R && !e || f && n[J] || !h && r[J])) { - if (R === m) { - if (D) { - if (!v || --v < u) { - if (g[u++] = E, b && u === b) { - return Z(c, u + (k || 0), g); + M = !1; + for (n = 0; n < B; n++) { + D = A[n]; + var I = "@" + D, Q = g ? q[I] || 0 : l; + if (!(!Q && !e || f && p[I] || !g && q[I])) { + if (Q === l) { + if (C) { + if (!x || --x < v) { + if (h[v++] = D, b && v === b) { + return Z(c, v + (k || 0), h); } } } else { - r[J] = m + 1; + q[I] = l + 1; } - N = !0; + M = !0; } else { - e && (J = t[R] || (t[R] = []), J[J.length] = E); + e && (I = u[Q] || (u[Q] = []), I[I.length] = D); } } } - if (T && !N && !e) { + if (T && !M && !e) { break; } } else { if (T && !e) { - return Z(c, K, A); + return Z(c, J, A); } } } - if (I) { - if (m = I.length, f) { - for (p = k ? parseInt(k, 10) : 0; p < m; p++) { - a = I[p], n["@" + a] || (g[u++] = a); + if (H) { + if (l = H.length, f) { + for (n = k ? parseInt(k, 10) : 0; n < l; n++) { + a = H[n], p["@" + a] || (h[v++] = a); } } else { - g = I; + h = H; } } if (e) { - for (u = g.length, y ? (m = parseInt(y[0], 10) + 1, p = parseInt(y[1], 10) + 1) : (m = t.length, p = 0); m--;) { - if (E = t[m]) { - for (H = E.length; p < H; p++) { - if (e = E[p], !f || !n["@" + e]) { - if (g[u++] = e, b && u === b) { - return Z(c, m + ":" + p, g); + for (v = h.length, t ? (l = parseInt(t[0], 10) + 1, n = parseInt(t[1], 10) + 1) : (l = u.length, n = 0); l--;) { + if (D = u[l]) { + for (B = D.length; n < B; n++) { + if (e = D[n], !f || !p["@" + e]) { + if (h[v++] = e, b && v === b) { + return Z(c, l + ":" + n, h); } } } - p = 0; + n = 0; } } } } else { - !l || d && "not" === d[0] || (g = a[0], k && (k = parseInt(k[0], 10))); + !m || d && "not" === d[0] || (h = a[0], k && (k = parseInt(k[0], 10))); } if (b) { - f = g.length; + f = h.length; k && k > f && (k = 0); k = k || 0; - var K = k + b; - K < f ? g = g.slice(k, K) : (K = 0, k && (g = g.slice(k))); + var J = k + b; + J < f ? h = h.slice(k, J) : (J = 0, k && (h = h.slice(k))); } - return Z(c, K, g); + return Z(c, J, h); } -;var qa = {encode:pa, rtl:!1}, ra = /[\W_]+/, sa = L("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"), ta = L("[\u00e8\u00e9\u00ea\u00eb]"), ua = L("[\u00ec\u00ed\u00ee\u00ef]"), va = L("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"), wa = L("[\u00f9\u00fa\u00fb\u00fc\u0171]"), xa = L("[\u00fd\u0177\u00ff]"), ya = L("\u00f1"), za = L("[\u00e7c]"), Aa = L("\u00df"), Ba = L(" & "), Ca = [sa, "a", ta, "e", ua, "i", va, "o", wa, "u", xa, "y", ya, "n", za, "k", Aa, "s", Ba, " and "]; -function pa(a, b) { - b || (b = this); - return b.pipeline(a.toLowerCase(), Ca, ra, !1); +;var pa = {encode:oa, rtl:!1}, qa = /[\W_]+/, ra = L("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"), sa = L("[\u00e8\u00e9\u00ea\u00eb]"), ta = L("[\u00ec\u00ed\u00ee\u00ef]"), ua = L("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"), va = L("[\u00f9\u00fa\u00fb\u00fc\u0171]"), wa = L("[\u00fd\u0177\u00ff]"), xa = L("\u00f1"), ya = L("[\u00e7c]"), za = L("\u00df"), Aa = L(" & "), Ba = [ra, "a", sa, "e", ta, "i", ua, "o", va, "u", wa, "y", xa, "n", ya, "k", za, "s", Aa, " and "]; +function oa(a, b) { + return (b || this).pipeline(a.toLowerCase(), Ba, qa, !1); } -;var Ea = {encode:Da, rtl:!1}, Fa = L("ae"), Ga = L("ai"), Ha = L("ay"), Ia = L("ey"), Ja = L("oe"), Ka = L("ue"), La = L("ie"), Ma = L("sz"), Na = L("zs"), Oa = L("ck"), Pa = L("cc"), Qa = L("sh"), Ra = L("th"), Sa = L("dt"), Ta = L("ph"), Ua = L("pf"), Va = L("ou"), Wa = L("uo"), Xa = [Fa, "a", Ga, "ei", Ha, "ei", Ia, "ei", Ja, "o", Ka, "u", La, "i", Ma, "s", Na, "s", Qa, "s", Oa, "k", Pa, "k", Ra, "t", Sa, "t", Ta, "f", Ua, "f", Va, "o", Wa, "u"]; -function Da(a, b) { - a && (a = pa(a, this).join(" "), 2 < a.length && (a = G(a, Xa)), b || (1 < a.length && (a = M(a)), a && (a = a.split(" ")))); +;var Da = {encode:Ca, rtl:!1}, Ea = L("ae"), Fa = L("ai"), Ga = L("ay"), Ha = L("ey"), Ia = L("oe"), Ja = L("ue"), Ka = L("ie"), La = L("sz"), Ma = L("zs"), Na = L("ck"), Oa = L("cc"), Pa = L("sh"), Qa = L("th"), Ra = L("dt"), Sa = L("ph"), Ta = L("pf"), Ua = L("ou"), Va = L("uo"), Wa = [Ea, "a", Fa, "ei", Ga, "ei", Ha, "ei", Ia, "o", Ja, "u", Ka, "i", La, "s", Ma, "s", Pa, "s", Na, "k", Oa, "k", Qa, "t", Ra, "t", Sa, "f", Ta, "f", Ua, "o", Va, "u"]; +function Ca(a, b, c) { + a && (a = oa(a, b || this).join(" "), 2 < a.length && (a = K(a, Wa)), c || (1 < a.length && (a = O(a)), a && (a = a.split(" ")))); return a; } -;var Za = {encode:Ya, rtl:!1}, $a = /[\W_]+/; -function Ya(a) { - return this.pipeline(a.toLowerCase(), !1, $a, !1); +;var Ya = {encode:Xa, rtl:!1}, Za = /[\W_]+/; +function Xa(a) { + return this.pipeline(a.toLowerCase(), !1, Za, !1); } -;var bb = {encode:ab, rtl:!1}, cb = L("(?!\\b)p"), db = L("(?!\\b)z"), eb = L("(?!\\b)[cgq]"), fb = L("(?!\\b)n"), gb = L("(?!\\b)d"), hb = L("(?!\\b)[vw]"), ib = L("(?!\\b)[aeiouy]"), jb = [cb, "b", db, "s", eb, "k", fb, "m", gb, "t", hb, "f", ib, ""]; -function ab(a) { - a && (a = Da(a, !0), 1 < a.length && (a = G(a, jb)), 1 < a.length && (a = M(a)), a && (a = a.split(" "))); +;var ab = {encode:$a, rtl:!1}, bb = L("(?!\\b)p"), cb = L("(?!\\b)z"), db = L("(?!\\b)[cgq]"), eb = L("(?!\\b)n"), fb = L("(?!\\b)d"), gb = L("(?!\\b)[vw]"), hb = L("(?!\\b)[aeiouy]"), ib = [bb, "b", cb, "s", db, "k", eb, "m", fb, "t", gb, "f", hb, ""]; +function $a(a) { + a && (a = Ca(a, this, !0), 1 < a.length && (a = K(a, ib)), 1 < a.length && (a = O(a)), a && (a = a.split(" "))); return a; } -;var lb = {encode:kb, rtl:!1, tokenize:"strict"}, mb = /[^a-z]+/; -function kb(a) { +;var kb = {encode:jb, rtl:!1, tokenize:"strict"}, lb = /[^a-z]+/; +function jb(a) { a = this.pipeline(a.toLowerCase(), !1, !1, !1); var b = []; if (a) { - for (var c = a.split(mb), e = c.length, d = 0, h = 0; d < e; d++) { + for (var c = a.split(lb), e = c.length, d = 0, g = 0; d < e; d++) { if ((a = c[d]) && 2 < a.length && (!this.filter || !this.filter[a])) { - for (var f = a[0], g = nb(f), k = 1; k < a.length; k++) { - var l = nb(a[k]); - if (l !== g && (f += l, g = l, 4 === f.length)) { + for (var f = a[0], h = mb(f), k = 1; k < a.length; k++) { + var m = mb(a[k]); + if (m !== h && (f += m, h = m, 4 === f.length)) { break; } } - b[h++] = (f + "0000").substring(0, 4); + b[g++] = (f + "0000").substring(0, 4); } } } return b; } -function nb(a) { +function mb(a) { switch(a) { case "b": case "f": @@ -1013,27 +1017,27 @@ function nb(a) { } return ""; } -;var pb = {encode:ob, rtl:!0}, qb = /[\W_]+/; -function ob(a) { - return this.pipeline(a, !1, qb, !1); +;var ob = {encode:nb, rtl:!0}, pb = /[\x00-\x7F]+/g; +function nb(a) { + return this.pipeline(a.replace(pb, " "), !1, " ", !1); } -;var sb = {encode:rb, rtl:!1, tokenize:"strict"}, tb = /[\x00-\x7F]/g; -function rb(a) { - return this.pipeline(a.replace(tb, ""), !1, "", !1); +;var rb = {encode:qb, rtl:!1, tokenize:"strict"}, sb = /[\x00-\x7F]+/g; +function qb(a) { + return this.pipeline(a.replace(sb, ""), !1, "", !1); } -;var vb = {encode:ub, rtl:!1}, wb = /[\W_]+/; -function ub(a) { - return this.pipeline(a, !1, wb, !1); +;var ub = {encode:tb, rtl:!1}, vb = /[\x00-\x7F]+/g; +function tb(a) { + return this.pipeline(a.replace(vb, " "), !1, " ", !1); } -;V["latin:advanced"] = Ea; -V["latin:balance"] = Za; +;V["latin:advanced"] = Da; +V["latin:balance"] = Ya; V["latin:default"] = da; -V["latin:extra"] = bb; -V["latin:simple"] = qa; -V["latin:soundex"] = lb; -V["arabic:default"] = pb; -V["cjk:default"] = sb; -V["cyrillic:default"] = vb; +V["latin:extra"] = ab; +V["latin:simple"] = pa; +V["latin:soundex"] = kb; +V["arabic:default"] = ob; +V["cjk:default"] = rb; +V["cyrillic:default"] = ub; U.de = {filter:"aber als am an auch auf aus bei bin bis bist da dadurch daher darum das da\u00df dass dein deine dem den der des dessen deshalb die dies dieser dieses doch dort du durch ein eine einem einen einer eines er es euer eure f\u00fcr hatte hatten hattest hattet hier hinter ich ihr ihre im in ist ja jede jedem jeden jeder jedes jener jenes jetzt kann kannst k\u00f6nnen k\u00f6nnt machen mein meine mit mu\u00df mu\u00dft musst m\u00fcssen m\u00fc\u00dft nach nachdem nein nicht nun oder seid sein seine sich sie sind soll sollen sollst sollt sonst soweit sowie und unser unsere unter vom von vor wann warum was weiter weitere wenn wer werde werden werdet weshalb wie wieder wieso wir wird wirst wo woher wohin zu zum zur \u00fcber".split(" "), stemmer:{niss:"", isch:"", lich:"", heit:"", keit:"", ell:"", bar:"", end:"", ung:"", est:"", ern:"", em:"", er:"", en:"", es:"", st:"", ig:"", ik:"", e:"", s:""}, matcher:{}}; U.en = {filter:"a about above after again against all also am an and any are aren't as at be because been before being below both but by can cannot can't come could couldn't did didn't do does doesn't doing dont down during each even few first for from further get go had hadn't has hasn't have haven't having he hed her here here's hers herself hes him himself his how how's i id if ill im in into is isn't it it's itself i've just know let's like make me more most mustn't my myself new no nor not now of off on once only or other ought our our's ourselves out over own same say see shan't she she'd shell shes should shouldn't so some such than that that's the their theirs them themselves then there there's these they they'd they'll they're they've this those through time to too until up us very want was wasn't way we wed well were weren't we've what what's when when's where where's which while who whom who's why why's will with won't would wouldn't you you'd you'll your you're your's yourself yourselves you've".split(" "), @@ -1047,7 +1051,7 @@ matcher:{}}; (function() { var a = this || window, b; (b = a.define) && b.amd ? b([], function() { - return O; - }) : "object" === typeof a.exports ? a.module.exports = O : a.FlexSearch = O; + return R; + }) : "object" === typeof a.exports ? a.module.exports = R : a.FlexSearch = R; })(); }).call(this); diff --git a/dist/lang/arabic/default.min.js b/dist/lang/arabic/default.min.js index b592451..26a8c48 100644 --- a/dist/lang/arabic/default.min.js +++ b/dist/lang/arabic/default.min.js @@ -1 +1 @@ -(function(){'use strict';var a=/[\W_]+/;window.FlexSearch.registerCharset("arabic:default",{encode:function(b){return this.a(b,!1,a,!1)},b:!0});}).call(this); +(function(){'use strict';var a=/[\x00-\x7F]+/g;window.FlexSearch.registerCharset("arabic:default",{encode:function(b){return this.a(b.replace(a," "),!1," ",!1)},b:!0});}).call(this); diff --git a/dist/lang/cjk/default.min.js b/dist/lang/cjk/default.min.js index 4307919..d4471ee 100644 --- a/dist/lang/cjk/default.min.js +++ b/dist/lang/cjk/default.min.js @@ -1 +1 @@ -(function(){'use strict';var a=/[\x00-\x7F]/g;window.FlexSearch.registerCharset("cjk:default",{encode:function(b){return this.a(b.replace(a,""),!1,"",!1)},b:!1,c:"strict"});}).call(this); +(function(){'use strict';var a=/[\x00-\x7F]+/g;window.FlexSearch.registerCharset("cjk:default",{encode:function(b){return this.a(b.replace(a,""),!1,"",!1)},b:!1,c:"strict"});}).call(this); diff --git a/dist/lang/cyrillic/default.min.js b/dist/lang/cyrillic/default.min.js index 2bcf5d1..8ff8695 100644 --- a/dist/lang/cyrillic/default.min.js +++ b/dist/lang/cyrillic/default.min.js @@ -1 +1 @@ -(function(){'use strict';var a=/[\W_]+/;window.FlexSearch.registerCharset("cyrillic:default",{encode:function(b){return this.a(b,!1,a,!1)},b:!1});}).call(this); +(function(){'use strict';var a=/[\x00-\x7F]+/g;window.FlexSearch.registerCharset("cyrillic:default",{encode:function(b){return this.a(b.replace(a," "),!1," ",!1)},b:!1});}).call(this); diff --git a/dist/lang/latin/advanced.min.js b/dist/lang/latin/advanced.min.js index d2b4746..da44177 100644 --- a/dist/lang/latin/advanced.min.js +++ b/dist/lang/latin/advanced.min.js @@ -1 +1 @@ -(function(){'use strict';function a(b){return new RegExp(b,"g")};var f=/[\W_]+/,h=[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("[\u00e7c]"),"k",a("\u00df"),"s",a(" & ")," and "];function k(b,c){c||(c=this);return c.a(b.toLowerCase(),h,f,!1)};var l=[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("th"),"t",a("dt"),"t",a("ph"),"f",a("pf"),"f",a("ou"),"o",a("uo"),"u"];window.FlexSearch.registerCharset("latin:advanced",{encode:function(b,c){if(b){b=k(b,this).join(" ");if(2a;i--)f=c.substring(a,i),add_index(n,h,f,b,g,e,k,m-1)}break;default:const i=add_index(n,h,c,b,1,e,k,m-1);if(l&&1=k){const d=h._ctx[c]||(h._ctx[c]=create_object()),e=this._ctx[c]||(this._ctx[c]=create_object_array(m-(k||0)));let f=a-l,i=a+l+1;for(0>f&&(f=0),i>j&&(i=j);f=g){let b=a[h-(i+0.5>>0)];b=b[c]||(b[c]=[]),b[b.length]=d}return i}function remove_index(b,c){if(b){const a=get_keys(b);for(let d=0,e=a.length;da&&(j=0);const c=j||0;h=c+b,ha;h--)i=c.substring(a,h),add_index(m,g,i,b,f,e,j,l-1)}break;default:const o=add_index(m,g,c,b,1,e,j,l-1);if(k&&1=j){const d=g._ctx[c]||(g._ctx[c]=create_object()),e=this._ctx[c]||(this._ctx[c]=create_object_array(l-(j||0)));let i=a-k,m=a+k+1;for(0>i&&(i=0),m>h&&(m=h);i=g){let b=a[h-(i+0.5>>0)];b=b[c]||(b[c]=[]),b[b.length]=d}return i}function remove_index(b,c){if(b){const a=get_keys(b);for(let d=0,e=a.length;dd?1:0}function sort_by_deep_field_up(c,d){const e=field_to_sort.length;for(let a=0;ad?1:0}function create_page(a,b,c){return a?{page:a,next:b?""+b:null,result:c}:c}function intersect(a,b,c,d,e,f,g){let h,j,k=[];!0===c?(c="0",j=""):j=c&&c.split(":");const l=a.length;if(1a&&(j=0);const c=j||0;h=c+b,h Use the `charset:variant` notation to assign charset and its variants. When just passing the charset without a variant will automatically resolve as `charset:default`. -The example above is a shortcut for: - -```js -const index = FlexSearch({ - encode: "latin:soundex", - tokenize: "latin:soundex", - rtl: "latin:soundex", - stemmer: "en", - matcher: "en", - filter: "en" -}); -``` - You can also override existing definitions, e.g.: ```js @@ -206,11 +193,11 @@ It is pretty straight forward when using an encoder variant: ```js const index_advanced = FlexSearch({ - encode: "latin:advanced" + charset: "latin:advanced" }); const index_extra = FlexSearch({ - encode: "latin:extra" + charset: "latin:extra" }); ``` diff --git a/src/flexsearch.js b/src/flexsearch.js index 5d43f31..62f6be7 100644 --- a/src/flexsearch.js +++ b/src/flexsearch.js @@ -29,39 +29,39 @@ import { regex } from "./common.js"; +let id_counter = 0; +export const global_lang = {}; +export const global_charset = {}; + /** * TODO: inlining them * @const * @enum {boolean|string|number|RegExp|Function} */ -const defaults = { - - "encode": default_encoder, - "tokenize": "strict", - // split: default_split, - // enrich: true, - // clone: false, - // suggest: false, - "cache": false, - "async": false, - "worker": false, - "rtl": false, - "doc": false, - - // maximum scoring - "resolution": 9, - - // minimum scoring - "threshold": 0, - - // contextual depth - "depth": 0 -}; - -let id_counter = 0; -export const global_lang = {}; -export const global_charset = {}; +// const defaults = { +// +// "encode": default_encoder, +// "tokenize": "strict", +// // split: default_split, +// // enrich: true, +// // clone: false, +// // suggest: false, +// "cache": false, +// "async": false, +// "worker": false, +// "rtl": false, +// "doc": false, +// +// // maximum scoring +// "resolution": 9, +// +// // minimum scoring +// "threshold": 0, +// +// // contextual depth +// "depth": 0 +// }; /** * NOTE: Actually not really required when using bare objects via: Object.create(null) @@ -104,17 +104,17 @@ export default function FlexSearch(options){ register_property(this, "index", /** @this {FlexSearch} */ function(){ - // if(SUPPORT_DOCUMENT && this.doc){ - // - // return get_keys(this.doc.index[this.doc.keys[0]]._ids); - // } + if(SUPPORT_DOCUMENT && this.doc){ + + return get_keys(this.doc.index[this.doc.keys[0]]._ids); + } return get_keys(this._ids); }); register_property(this, "length", /** @this {FlexSearch} */ function(){ - return this.index.length; + return this["index"].length; }); } @@ -154,7 +154,7 @@ FlexSearch["registerCharset"] = function(name, charset){ FlexSearch["registerLanguage"] = function(name, lang){ - global_charset[name] = lang; + global_lang[name] = lang; return FlexSearch; }; @@ -194,7 +194,7 @@ FlexSearch.prototype.init = function(options){ let custom; let doc; - if(SUPPORT_PRESET){ + if(SUPPORT_PRESET && options){ if(is_string(options)){ @@ -205,33 +205,38 @@ FlexSearch.prototype.init = function(options){ options = presets[options]; } - else{ + else if((custom = options["preset"])){ - if((custom = options["preset"])){ + if(DEBUG && !presets[custom]){ - if(DEBUG && !presets[custom]){ - - console.warn("Preset not found: " + custom); - } - - options = Object.assign({}, presets[custom], /** @type {Object} */ (options)); + console.warn("Preset not found: " + custom); } + + options = Object.assign({}, presets[custom], /** @type {Object} */ (options)); } } - if(!this.encode){ + options || (options = {}); - if(options){ + // TODO reset state and rebuild index - options = Object.assign({}, defaults, /** @type {Object} */ (options)); - } - else{ + // if(this.encode){ + // + // } - options = defaults; - } - } + // if(!this.encode){ + // + // if(options){ + // + // options = Object.assign({}, defaults, /** @type {Object} */ (options)); + // } + // else{ + // + // options = defaults; + // } + // } - if(options){ + //if(options){ // initialize worker @@ -273,44 +278,50 @@ FlexSearch.prototype.init = function(options){ } if(SUPPORT_ASYNC){ + /** @private */ this.async = options["async"]; /** @private */ this.timer = 0; } - const charset = options["charset"]; - const lang = options["lang"]; + let charset = options["charset"]; + let lang = options["lang"]; + + if(is_string(charset)){ + + if(charset.indexOf(":") === -1){ + + charset += ":default"; + } + + charset = global_charset[charset]; + } + + if(is_string(lang)){ + + lang = global_lang[lang]; + } /** @private */ - this.tokenizer = (is_string(charset) ? global_charset[charset].tokenize : charset && charset.tokenize) || options["tokenize"]; + this.tokenizer = custom = (charset && charset.tokenize) || options["tokenize"] || "strict"; /** @private */ - //this.split = is_string(custom = options["split"] || charset) ? (global_charset[custom] ? global_charset[custom].split : regex(custom)) : global_charset.split || custom; + this.depth = ((custom === "strict") && options["depth"]) || 0; /** @private */ - this.rtl = is_string(custom = options["rtl"] || charset) ? global_charset[custom].rtl : charset && charset.rtl || custom; + this.rtl = (charset && charset.rtl) || options["rtl"] || false; /** @private */ - this.threshold = options["threshold"]; + this.resolution = options["resolution"] || 9; /** @private */ - this.resolution = ((custom = options["resolution"]) <= this.threshold ? this.threshold + 1 : custom); - /** @private */ - this.depth = ((this.tokenizer === "strict") && options["depth"]) || 0; + this.threshold = custom = options["threshold"] || 0; + if(this.resolution <= custom) this.resolution = custom + 1; /** @export */ - this.encode = is_string(custom = options["encode"] || charset) ? global_charset[custom.indexOf(":") === -1 ? custom + ":default" : custom].encode : charset && charset.encode || custom; //is_function(custom = options["encode"]) ? custom : (FlexSearch.Encoder[custom] /*&& global_encoder[custom].bind(global_encoder)*/); - - this.matcher = (custom = options["matcher"] || lang) && init_stemmer_or_matcher( - - is_string(custom) ? global_lang[custom].matcher : lang && lang.matcher || custom, false - ); - - this.filter = (custom = options["filter"] || lang) && init_filter( - - is_string(custom) ? global_lang[custom].filter : lang && lang.filter || custom - ); - - this.stemmer = (custom = options["stemmer"] || lang) && init_stemmer_or_matcher( - - is_string(custom) ? global_lang[custom].stemmer : lang && lang.stemmer || custom, true - ); + this.encode = options["encode"] || (charset && charset.encode) || default_encoder; + /** @private */ + this.matcher = (custom = options["matcher"] || (lang && lang.matcher)) && init_stemmer_or_matcher(custom, false); + /** @private */ + this.stemmer = (custom = options["stemmer"] || (lang && lang.stemmer)) && init_stemmer_or_matcher(custom, true); + /** @private */ + this.filter = (custom = options["filter"] || (lang && lang.filter)) && init_filter(custom); // TODO: provide boost /** @private */ @@ -326,16 +337,16 @@ FlexSearch.prototype.init = function(options){ options["doc"] = null; } } - } + //} // initialize primary index /** @private */ - this._map = create_object_array(this.resolution - (this.threshold || 0)); + this._map = create_object_array(this.resolution - this.threshold); /** @private */ this._ctx = create_object(); /** @private */ - this._ids = {}; + this._ids = create_object(); if(SUPPORT_DOCUMENT && doc){ @@ -466,13 +477,13 @@ FlexSearch.prototype.init = function(options){ //options["doc"] = custom; } - if(SUPPORT_CACHE && (custom = options["cache"])) { + if(SUPPORT_CACHE) { /** @private */ this._cache_status = true; /** @private */ - this._cache = new Cache(custom); + this._cache = (custom = options["cache"]) && new Cache(custom); } return this; @@ -524,11 +535,13 @@ FlexSearch.prototype.add = function(id, content, callback, _skip_update, _recall if(content && is_string(content) && ((id /*&& !index_blacklist[id]*/) || (id === 0))){ + //id = "" + id; + // TODO: do not mix ids as string "1" and as number 1 - const index = id; + //const index = "" + id; - if(this._ids[index] && !_skip_update){ + if(this._ids[id] && !_skip_update){ return this.update(id, content); } @@ -547,7 +560,7 @@ FlexSearch.prototype.add = function(id, content, callback, _skip_update, _recall // "content": content // }); // - // this._ids[index] = "" + this._current_task; + // this._ids[id] = "" + this._current_task; // // // TODO: provide worker auto-balancing instead of rotation // //this._ids_count[this._current_task]++; @@ -620,6 +633,8 @@ FlexSearch.prototype.add = function(id, content, callback, _skip_update, _recall const map = this._map; const rtl = this.rtl; + let has_content; + // tokenize for(let i = 0; i < word_length; i++){ @@ -629,6 +644,8 @@ FlexSearch.prototype.add = function(id, content, callback, _skip_update, _recall if(value){ + has_content = 1; + const length = value.length; const context_score = (rtl ? i + 1 : word_length - i) / word_length; @@ -759,9 +776,12 @@ FlexSearch.prototype.add = function(id, content, callback, _skip_update, _recall } } - // update status + if(has_content){ - this._ids[index] = 1; + // update status + + this._ids[id] = 1; + } if(SUPPORT_CACHE){ @@ -782,7 +802,7 @@ if(SUPPORT_DOCUMENT){ /** * @param {!string} job * @param doc - * @param {Function=} callback + * @param {Function|boolean=} callback * @returns {*} */ @@ -792,14 +812,14 @@ if(SUPPORT_DOCUMENT){ let len = doc.length; - if(len--){ + if(len){ for(let i = 0; i < len; i++){ - this.handle_docs(job, doc[i]); + this.handle_docs(job, doc[i], (i === len - 1) && callback); } - return this.handle_docs(job, doc[len], callback); + //return this.handle_docs(job, doc[len], callback); } } else{ @@ -829,110 +849,113 @@ if(SUPPORT_DOCUMENT){ delete this._doc[id]; - let length = keys.length; + let len = keys.length; - if(length--){ + if(len){ - for(let z = 0; z < length; z++){ + for(let i = 0; i < len; i++){ - index[keys[z]].remove(id); + index[keys[i]].remove(id, (i === len - 1) && callback); } - return index[keys[length]].remove(id, callback); + //return index[keys[len]].remove(id, callback); } } // --------------------------------------------------------------- - if(tags){ + else{ - let tag_key; - let tag_value; + if(tags){ - for(let i = 0; i < tags.length; i++){ + let tag_key; + let tag_value; - tag_key = tags[i]; - tag_value = doc; + for(let i = 0; i < tags.length; i++){ - const tag_split = tag_key.split(":"); + tag_key = tags[i]; + tag_value = doc; - for(let a = 0; a < tag_split.length; a++){ + const tag_split = tag_key.split(":"); - tag_value = tag_value[tag_split[a]]; + for(let a = 0; a < tag_split.length; a++){ + + tag_value = tag_value[tag_split[a]]; + } + + tag_value = "@" + tag_value; } - tag_value = "@" + tag_value; + tag = this._tag[tag_key]; + tag = tag[tag_value] || (tag[tag_value] = []); } - tag = this._tag[tag_key]; - tag = tag[tag_value] || (tag[tag_value] = []); - } + // --------------------------------------------------------------- - // --------------------------------------------------------------- + tree = this.doc["field"]; - tree = this.doc["field"]; + for(let i = 0, len = tree.length; i < len; i++){ - for(let i = 0, len = tree.length; i < len; i++){ + const branch = tree[i]; + let content = doc; - const branch = tree[i]; - let content = doc; + for(let x = 0; x < branch.length; x++){ - for(let x = 0; x < branch.length; x++){ + content = content[branch[x]]; + } - content = content[branch[x]]; + const self = index[keys[i]]; + + if(job === "add"){ + + self.add(id, content, (i === (len - 1)) && callback); + } + else{ + + self.update(id, content, (i === (len - 1)) && callback); + } } - const self = index[keys[i]]; + // --------------------------------------------------------------- - if(job === "add"){ + if(store){ - self.add(id, content, (i === (len - 1)) && callback); - } - else{ + const store_keys = get_keys(store); + let store_doc = create_object(); - self.update(id, content, (i === (len - 1)) && callback); - } - } + for(let i = 0; i < store_keys.length; i++){ - // --------------------------------------------------------------- + let store_key = store_keys[i]; - if(store){ + if(store[store_key]){ - const store_keys = get_keys(store); - let store_doc = create_object(); + const store_split = store_key.split(":"); - for(let i = 0; i < store_keys.length; i++){ + let store_value; + let store_doc_value; - let store_key = store_keys[i]; + for(let a = 0; a < store_split.length; a++){ - if(store[store_key]){ + const store_split_key = store_split[a]; - const store_split = store_key.split(":"); - - let store_value; - let store_doc_value; - - for(let a = 0; a < store_split.length; a++){ - - const store_split_key = store_split[a]; - - store_value = (store_value || doc)[store_split_key]; - store_doc_value = (store_doc_value || store_doc)[store_split_key] = store_value; + store_value = (store_value || doc)[store_split_key]; + store_doc_value = (store_doc_value || store_doc)[store_split_key] = store_value; + } } } + + doc = store_doc; } - doc = store_doc; + // --------------------------------------------------------------- + + if(tag){ + + tag[tag.length] = doc; // tag[tag.length] = id; + } + + this._doc[id] = doc; } - - // --------------------------------------------------------------- - - if(tag){ - - tag[tag.length] = doc; // tag[tag.length] = id; - } - - this._doc[id] = doc; } return this; @@ -952,9 +975,7 @@ FlexSearch.prototype.update = function(id, content, callback){ return this.handle_docs("update", id, /** @type {Function} */ (content)); } - const index = id; - - if(this._ids[index] && is_string(content)){ + if(this._ids[id] && is_string(content)){ // if(PROFILER){ // @@ -1123,10 +1144,11 @@ FlexSearch.prototype.merge_and_sort = function(query, bool, result, sort, limit, } else{ + // TODO apply during last round of intersection result = enrich_documents(result, this._doc); } - // TODO: pre-sort when indexing + // custom sort replaces the default sort by relevance if(sort){ @@ -1140,7 +1162,7 @@ FlexSearch.prototype.merge_and_sort = function(query, bool, result, sort, limit, } else{ - field_to_sort = field_to_sort[0]; + //field_to_sort = field_to_sort[0]; sort = sort_by_field_up; } } @@ -1938,14 +1960,14 @@ function remove_index(map, id){ function init_filter(words){ - const final = create_object(); + const filter = create_object(); for(let i = 0, length = words.length; i < length; i++){ - final[words[i]] = 1; + filter[words[i]] = 1; } - return final; + return filter; } /** @@ -2000,7 +2022,10 @@ function sort_by_length_down(a, b){ function sort_by_field_up(a, b){ - return a[field_to_sort] - b[field_to_sort]; + a = a[field_to_sort]; + b = b[field_to_sort]; + + return a < b ? - 1 : (a > b ? 1 : 0); } function sort_by_deep_field_up(a, b){ @@ -2013,7 +2038,7 @@ function sort_by_deep_field_up(a, b){ b = b[field_to_sort[i]]; } - return a - b; + return a < b ? - 1 : (a > b ? 1 : 0); } function create_page(cursor, page, result){ diff --git a/src/lang/arabic/default.js b/src/lang/arabic/default.js index c0ee009..a48e7dd 100644 --- a/src/lang/arabic/default.js +++ b/src/lang/arabic/default.js @@ -7,7 +7,7 @@ export default { rtl: rtl } -const split = /[\W_]+/; +const regex = /[\x00-\x7F]+/g; /** * @this FlexSearch @@ -17,9 +17,9 @@ export function encode(str){ return this.pipeline( - /* string: */ str, + /* string: */ str.replace(regex, " "), /* normalize: */ false, - /* split: */ split, + /* split: */ " ", /* collapse: */ false ); } diff --git a/src/lang/cjk/default.js b/src/lang/cjk/default.js index 280c4ec..27e4f61 100644 --- a/src/lang/cjk/default.js +++ b/src/lang/cjk/default.js @@ -8,7 +8,7 @@ export default { tokenize: tokenize } -const regex = /[\x00-\x7F]/g; +const regex = /[\x00-\x7F]+/g; /** * @this FlexSearch diff --git a/src/lang/cyrillic/default.js b/src/lang/cyrillic/default.js index db69427..0388c24 100644 --- a/src/lang/cyrillic/default.js +++ b/src/lang/cyrillic/default.js @@ -7,7 +7,7 @@ export default { rtl: rtl } -const split = /[\W_]+/; +const regex = /[\x00-\x7F]+/g; /** * @this FlexSearch @@ -17,9 +17,9 @@ export function encode(str){ return this.pipeline( - /* string: */ str, + /* string: */ str.replace(regex, " "), /* normalize: */ false, - /* split: */ split, + /* split: */ " ", /* collapse: */ false ); } diff --git a/src/lang/latin/advanced.js b/src/lang/latin/advanced.js index 0b801c7..5ff34fc 100644 --- a/src/lang/latin/advanced.js +++ b/src/lang/latin/advanced.js @@ -51,11 +51,11 @@ const pairs = [ regex_uo, "u" ]; -export function encode(str, _skip_postprocessing){ +export function encode(str, self, _skip_postprocessing){ if(str){ - str = encode_simple(str, /** @type {FlexSearch} */ (this)).join(" "); + str = encode_simple(str, /** @type {FlexSearch} */ (self || this)).join(" "); if(str.length > 2){ diff --git a/src/lang/latin/extra.js b/src/lang/latin/extra.js index a3d5510..9e118f4 100644 --- a/src/lang/latin/extra.js +++ b/src/lang/latin/extra.js @@ -1,3 +1,4 @@ +import FlexSearch from "../../flexsearch.js"; import { regex, replace, collapse } from "../../common.js"; import { encode as encode_advanced } from "./advanced.js"; @@ -34,7 +35,7 @@ export function encode(str){ if(str){ - str = encode_advanced(str, /* skip post-processing: */ true); + str = encode_advanced(str, /** @type {FlexSearch} */ (this), /* skip post-processing: */ true); if(str.length > 1){ diff --git a/src/lang/latin/simple.js b/src/lang/latin/simple.js index 6df9f47..f61a8f8 100644 --- a/src/lang/latin/simple.js +++ b/src/lang/latin/simple.js @@ -41,14 +41,11 @@ const pairs = [ /** * @param {string} str - * @param {FlexSearch} self */ export function encode(str, self){ - self || (self = this); - - return self.pipeline( + return /** @type {FlexSearch} */ (self || this).pipeline( /* string: */ str.toLowerCase(), /* normalize: */ pairs, diff --git a/src/presets.js b/src/presets.js index ad1198f..7676524 100644 --- a/src/presets.js +++ b/src/presets.js @@ -6,46 +6,46 @@ export default { "memory": { - encode: SUPPORT_ENCODER ? "extra" : "icase", - tokenize: "strict", + charset: "latin:extra", + //tokenize: "strict", threshold: 0, resolution: 1 }, "speed": { - encode: "icase", - tokenize: "strict", + //charset: "latin", + //tokenize: "strict", threshold: 1, resolution: 3, depth: 2 }, "match": { - encode: SUPPORT_ENCODER ? "extra" : "icase", + charset: "latin:extra", tokenize: "full", threshold: 1, resolution: 3 }, "score": { - encode: SUPPORT_ENCODER ? "extra" : "icase", - tokenize: "strict", + charset: "latin:extra", + //tokenize: "strict", threshold: 1, resolution: 9, depth: 4 }, "balance": { - encode: SUPPORT_ENCODER ? "balance" : "icase", - tokenize: "strict", + charset: "latin:balance", + //tokenize: "strict", threshold: 0, resolution: 3, depth: 3 }, "fast": { - encode: "icase", - tokenize: "strict", + //charset: "latin", + //tokenize: "strict", threshold: 8, resolution: 9, depth: 1 diff --git a/test/test.js b/test/test.js index 6355010..fd517b2 100644 --- a/test/test.js +++ b/test/test.js @@ -37,43 +37,43 @@ describe("Initialize", function(){ flexsearch_sync = new FlexSearch({ tokenize: "forward", - encode: false, + //encode: false, async: false, worker: false }); - flexsearch_async = FlexSearch.create({ + flexsearch_async = FlexSearch({ tokenize: "forward", - encode: false, + //encode: false, async: true, worker: false }); flexsearch_icase = new FlexSearch({ - encode: "icase", + charset: "latin:default", async: false, worker: false }); - flexsearch_simple = FlexSearch.create({ + flexsearch_simple = FlexSearch({ - encode: "simple", + charset: "latin:simple", async: false, worker: false }); flexsearch_advanced = new FlexSearch({ - encode: "advanced", + charset: "latin:advanced", async: false, worker: false }); - flexsearch_extra = FlexSearch.create({ + flexsearch_extra = FlexSearch({ - encode: "extra", + charset: "latin:extra", async: false, worker: false }); @@ -87,7 +87,7 @@ describe("Initialize", function(){ flexsearch_strict = new FlexSearch({ - encode: "icase", + charset: "latin", tokenize: "strict", async: false, worker: false @@ -95,7 +95,7 @@ describe("Initialize", function(){ flexsearch_forward = new FlexSearch({ - encode: "icase", + charset: "latin", tokenize: "forward", async: false, worker: false @@ -103,7 +103,7 @@ describe("Initialize", function(){ flexsearch_reverse = new FlexSearch({ - encode: "icase", + charset: "latin", tokenize: "reverse", resolution: 10, async: false, @@ -112,7 +112,7 @@ describe("Initialize", function(){ flexsearch_full = new FlexSearch({ - encode: "icase", + charset: "latin", tokenize: "full", async: false, worker: false @@ -120,7 +120,7 @@ describe("Initialize", function(){ flexsearch_ngram = new FlexSearch({ - encode: "advanced", + charset: "latin:advanced", tokenize: "ngram", async: false, worker: false @@ -128,7 +128,7 @@ describe("Initialize", function(){ flexsearch_cache = new FlexSearch({ - encode: "icase", + charset: "latin", tokenize: "reverse", cache: 2 }); @@ -181,8 +181,8 @@ describe("Initialize", function(){ if(env !== "light"){ - expect(flexsearch_default.async).to.equal(false); - expect(flexsearch_sync.async).to.equal(false); + expect(flexsearch_default.async).to.not.equal(true); + expect(flexsearch_sync.async).to.not.equal(true); expect(flexsearch_async.async).to.equal(true); } @@ -212,7 +212,7 @@ describe("Add (Sync)", function(){ flexsearch_sync.add(2, "bar"); flexsearch_sync.add(1, "foobar"); - expect(flexsearch_sync.index).to.have.members(["@0", "@1", "@2"]); + expect(flexsearch_sync.index).to.have.members(["0", "1", "2"]); expect(flexsearch_sync.length).to.equal(3); }); @@ -443,7 +443,7 @@ if(env !== "light"){ setTimeout(function(){ expect(flexsearch_async.length).to.equal(3); - expect(flexsearch_async.index).to.have.members(["@0", "@1", "@2"]); + expect(flexsearch_async.index).to.have.members(["0", "1", "2"]); done(); @@ -465,7 +465,7 @@ if(env !== "light"){ setTimeout(function(){ expect(flexsearch_async.length).to.equal(3); - expect(flexsearch_async.index).to.have.members(["@0", "@1", "@2"]); + expect(flexsearch_async.index).to.have.members(["0", "1", "2"]); done(); @@ -688,7 +688,7 @@ if(env !== "light"){ flexsearch_worker = new FlexSearch({ - encode: "icase", + charset: "latin:default", tokenize: "reverse", async: false, worker: 4 @@ -704,7 +704,7 @@ if(env !== "light"){ setTimeout(function(){ expect(flexsearch_worker.length).to.equal(3); - expect(flexsearch_worker.index).to.have.members(["@0", "@1", "@2"]); + expect(flexsearch_worker.index).to.have.members(["0", "1", "2"]); flexsearch_worker.search("foo", function(result){ @@ -733,7 +733,7 @@ if(env !== "light"){ setTimeout(function(){ expect(flexsearch_worker.length).to.equal(3); - expect(flexsearch_worker.index).to.have.members(["@0", "@1", "@2"]); + expect(flexsearch_worker.index).to.have.members(["0", "1", "2"]); done(); @@ -908,53 +908,50 @@ describe("Encoding", function(){ it("Should have been encoded properly: iCase", function(){ - expect(flexsearch_icase.encode("Björn-Phillipp Mayer")).to.equal(flexsearch_icase.encode("björn-phillipp mayer")); + expect(flexsearch_icase.encode("Björn-Phillipp Mayer")).to.eql(flexsearch_icase.encode("björn-phillipp mayer")); }); if(env !== "light"){ it("Should have been encoded properly: Simple", function(){ - expect(flexsearch_simple.encode("Björn-Phillipp Mayer")).to.equal(flexsearch_simple.encode("bjorn/phillipp mayer")); + expect(flexsearch_simple.encode("Björn-Phillipp Mayer")).to.eql(flexsearch_simple.encode("bjorn/phillipp mayer")); }); it("Should have been encoded properly: Advanced", function(){ - expect(flexsearch_advanced.encode("Björn-Phillipp Mayer")).to.equal(flexsearch_advanced.encode("bjoern filip mair")); + expect(flexsearch_advanced.encode("Björn-Phillipp Mayer")).to.eql(flexsearch_advanced.encode("bjoern filip mair")); }); it("Should have been encoded properly: Extra", function(){ - expect(flexsearch_extra.encode("Björn-Phillipp Mayer")).to.equal(flexsearch_extra.encode("bjorm filib mayr")); + expect(flexsearch_extra.encode("Björn-Phillipp Mayer")).to.eql(flexsearch_extra.encode("bjorm filib mayr")); }); } it("Should have been encoded properly: Custom Encoder", function(){ - expect(flexsearch_custom.encode("Björn-Phillipp Mayer")).to.equal("-[BJÖRN-PHILLIPP MAYER]-"); + expect(flexsearch_custom.encode("Björn-Phillipp Mayer")).to.eql("-[BJÖRN-PHILLIPP MAYER]-"); }); - it("Should have been encoded properly: Custom Encoder", function(){ - - FlexSearch.registerEncoder("custom", test_encoder); - - expect(FlexSearch.encode("custom", "Björn-Phillipp Mayer")).to.equal(flexsearch_custom.encode("Björn-Phillipp Mayer")); - }); + // it("Should have been encoded properly: Custom Encoder", function(){ + // + // FlexSearch.registerEncoder("custom", test_encoder); + // + // expect(FlexSearch.encode("custom", "Björn-Phillipp Mayer")).to.eql(flexsearch_custom.encode("Björn-Phillipp Mayer")); + // }); }); // ------------------------------------------------------------------------ -// CJK Word Break +// Word Break // ------------------------------------------------------------------------ describe("CJK Word Break", function(){ it("Should have been tokenized properly", function(){ - var index = FlexSearch.create({ - encode: false, - tokenize: function(str){ - return str.replace(/[\x00-\x7F]/g, "").split(""); - } + var index = FlexSearch({ + charset: "cjk" }); index.add(0, "서울시가 잠이 든 시간에 아무 말, 미뤄, 미뤄"); @@ -968,19 +965,13 @@ describe("CJK Word Break", function(){ }); }); -// ------------------------------------------------------------------------ -// Cyrillic Word Break -// ------------------------------------------------------------------------ - describe("Cyrillic Word Break", function(){ it("Should have been tokenized properly", function(){ - var index = FlexSearch.create({ - encode: false, - tokenize: function(str){ - return str.replace(/[\x00-\x7F]/g, "").split(""); - } + var index = FlexSearch({ + charset: "cyrillic", + tokenize: "reverse" }); index.add(0, "Фообар"); @@ -990,6 +981,20 @@ describe("Cyrillic Word Break", function(){ }); }); +describe("Arabic Word Break", function(){ + + it("Should have been tokenized properly", function(){ + + var index = FlexSearch({ + charset: "arabic" + }); + + index.add(0, "لكن لا بد أن أوضح لك أن كل"); + + expect(index.search("بد أن")).to.include(0); + }); +}); + // ------------------------------------------------------------------------ // Right-To-Left // ------------------------------------------------------------------------ @@ -1000,7 +1005,6 @@ describe("RTL Support", function(){ var index = new FlexSearch({ - encode: "icase", tokenize: "reverse", rtl: true }); @@ -1025,7 +1029,6 @@ describe("Context", function(){ var flexsearch_depth = new FlexSearch({ - encode: "icase", tokenize: "strict", depth: 2, async: false, @@ -1125,7 +1128,6 @@ describe("Filter", function(){ it("Should have been filtered properly", function(){ var index = new FlexSearch({ - encode: "icase", tokenize: "strict", filter: ["in", "the"] }); @@ -1138,23 +1140,23 @@ describe("Filter", function(){ expect(index.search("in the")).to.have.length(0); }); - it("Should have been filtered properly (custom function)", function(){ - - var index = new FlexSearch({ - encode: "icase", - tokenize: "strict", - filter: function(word){ - return word.length > 3; - } - }); - - index.add(0, "Today in the morning."); - - expect(index.length).to.equal(1); - expect(index.search("today in the morning.")).to.include(0); - expect(index.search("today morning")).to.include(0); - expect(index.search("in the")).to.have.length(0); - }); + // it("Should have been filtered properly (custom function)", function(){ + // + // var index = new FlexSearch({ + // + // tokenize: "strict", + // filter: function(word){ + // return word.length > 3; + // } + // }); + // + // index.add(0, "Today in the morning."); + // + // expect(index.length).to.equal(1); + // expect(index.search("today in the morning.")).to.include(0); + // expect(index.search("today morning")).to.include(0); + // expect(index.search("in the")).to.have.length(0); + // }); }); describe("Stemmer", function(){ @@ -1162,7 +1164,6 @@ describe("Stemmer", function(){ it("Should have been stemmed properly", function(){ var index = new FlexSearch({ - encode: "icase", tokenize: "reverse", stemmer: { "ization": "ize", @@ -1186,7 +1187,6 @@ describe("Stemmer", function(){ }; var index = new FlexSearch({ - encode: "icase", tokenize: "strict", stemmer: function(word){ return stems[word] || word; @@ -1207,7 +1207,8 @@ describe("Custom Language", function(){ it("Should have been applied properly", function(){ - FlexSearch.registerLanguage("custom", { + var index = new FlexSearch({ + tokenize: "reverse", filter: ["a", "an"], stemmer: { "ization": "ize", @@ -1215,13 +1216,6 @@ describe("Custom Language", function(){ } }); - var index = new FlexSearch({ - encode: "icase", - tokenize: "reverse", - filter: "custom", - stemmer: "custom" - }); - index.add(0, "Just a multinational colonization."); expect(index.length).to.equal(1); @@ -1230,8 +1224,15 @@ describe("Custom Language", function(){ expect(index.search("multinational colonization")).to.include(0); expect(index.search("tional tion")).to.have.length(0); + FlexSearch.registerLanguage("custom", { + filter: ["a", "an"], + stemmer: { + "ization": "ize", + "tional": "tion" + } + }); + index = new FlexSearch({ - encode: "icase", tokenize: "reverse", lang: "custom" }); @@ -1255,7 +1256,7 @@ describe("Relevance", function(){ it("Should have been sorted by relevance properly", function(){ var index = new FlexSearch({ - encode: "advanced", + charset: "latin:advanced", tokenize: "strict" }); @@ -1269,7 +1270,7 @@ describe("Relevance", function(){ expect(index.search("four one")).to.have.members([1, 2]); index = new FlexSearch({ - encode: "advanced", + charset: "latin:advanced", tokenize: "strict", threshold: 5, depth: 3 @@ -1285,7 +1286,7 @@ describe("Relevance", function(){ expect(index.search("four one")).to.have.members([1, 2]); index = new FlexSearch({ - encode: "extra", + charset: "latin:extra", tokenize: "strict", threshold: 5, depth: 3 @@ -1314,7 +1315,7 @@ if(env !== "light") describe("Suggestions", function(){ it("Should have been suggested properly by relevance", function(){ var index = new FlexSearch({ - encode: "advanced", + charset: "latin:advanced", tokenize: "strict" }); @@ -1335,7 +1336,7 @@ if(env !== "light") describe("Suggestions", function(){ it("Should have been suggested properly by context", function(){ var index = new FlexSearch({ - encode: "advanced", + charset: "latin:advanced", tokenize: "strict", depth: 3 }); @@ -1381,14 +1382,14 @@ if((env === "") || (env === "min") || (env === "pre")) describe("Where/Find", fu var index = new FlexSearch({ doc: { id: "id", - field: ["title"] + field: "title" } }); index.add(data); expect(index.length).to.equal(3); - expect(index.index).to.have.members(["@0", "@1", "@2"]); + expect(index.index).to.have.members(["0", "1", "2"]); expect(index.find(0)).to.equal(data[0]); expect(index.find("id", 0)).to.equal(data[0]); @@ -1436,7 +1437,7 @@ if((env === "") || (env === "min") || (env === "pre")) describe("Where/Find", fu index.add(data); expect(index.length).to.equal(3); - expect(index.index).to.have.members(["@0", "@1", "@2"]); + expect(index.index).to.have.members(["0", "1", "2"]); expect(index.where({cat: "1"})).to.have.members([data[0], data[2]]); expect(index.where("cat", "1")).to.have.members([data[0], data[2]]); @@ -1490,7 +1491,7 @@ if((env === "") || (env === "min") || (env === "pre")) describe("Where/Find", fu index.add(data); expect(index.length).to.equal(3); - expect(index.index).to.have.members(["@0", "@1", "@2"]); + expect(index.index).to.have.members(["0", "1", "2"]); expect(index.where({cat: "1"})).to.have.members([data[0], data[2]]); @@ -1729,11 +1730,11 @@ if(env !== "light") describe("Index Multi-Field Documents", function(){ id: "id", field: { "data:title": { - encode: "advanced", + charset: "latin:advanced", tokenize: "reverse" }, "data:body": { - encode: "icase", + charset: "latin:default", tokenize: "strict" } } @@ -2047,9 +2048,9 @@ if(env !== "light") describe("Index Multi-Field Documents", function(){ sort: "data:title" }); - expect(results[0]).to.equal(data[2]); - expect(results[1]).to.equal(data[1]); - expect(results[2]).to.equal(data[0]); + expect(results[0]).to.eql(data[2]); + expect(results[1]).to.eql(data[1]); + expect(results[2]).to.eql(data[0]); }); it("Should have been sorted suggested and paged", function(){ @@ -2138,7 +2139,7 @@ if(env !== "light") describe("Pagination", function(){ index.add(0, "test").add(1, "test").add(2, "test").add(3, "test").add(4, "test"); - expect(index.index).to.have.members(["@0", "@1", "@2", "@3", "@4"]); + expect(index.index).to.have.members(["0", "1", "2", "3", "4"]); expect(index.search("test")).to.have.lengthOf(5); expect(index.search("test", 2)).to.have.lengthOf(2); @@ -2182,7 +2183,7 @@ if(env !== "light") describe("Pagination", function(){ index.add(0, "foo bar").add(1, "foo bar").add(2, "foo bar test").add(3, "foo bar").add(4, "foo bar"); - expect(index.index).to.have.members(["@0", "@1", "@2", "@3", "@4"]); + expect(index.index).to.have.members(["0", "1", "2", "3", "4"]); expect(index.search("foo")).to.have.lengthOf(5); expect(index.search("foo", 2)).to.have.lengthOf(2); @@ -2271,8 +2272,8 @@ if(env !== "light") describe("Pagination", function(){ if(env === ""){ - expect(index.doc.index["title"].index).to.have.members(["@0", "@1", "@2", "@3", "@4"]); - expect(index.doc.index["body"].index).to.have.members(["@0", "@1", "@2", "@3", "@4"]); + expect(index.doc.index["title"].index).to.have.members(["0", "1", "2", "3", "4"]); + expect(index.doc.index["body"].index).to.have.members(["0", "1", "2", "3", "4"]); } expect(index.search("title")).to.have.lengthOf(5); @@ -2313,30 +2314,30 @@ if(env !== "light") describe("Pagination", function(){ }); }); -describe("Custom Split", function(){ - - it("Should have been split properly", function(){ - - var index = FlexSearch.create({ - encode: false, - split: /\s+/, - tokenize: "reverse" - }); - - index.add(0, "Фообар"); - - expect(index.search("Фообар")).to.include(0); - expect(index.search("бар")).to.include(0); - expect(index.search("Фоо")).to.include(0); - }); -}); +// describe("Custom Split", function(){ +// +// it("Should have been split properly", function(){ +// +// var index = FlexSearch({ +// encode: false, +// split: /\s+/, +// tokenize: "reverse" +// }); +// +// index.add(0, "Фообар"); +// +// expect(index.search("Фообар")).to.include(0); +// expect(index.search("бар")).to.include(0); +// expect(index.search("Фоо")).to.include(0); +// }); +// }); describe("Github Issues", function(){ if(env !== "light") it("#48", function(){ const fs = new FlexSearch({ - encode: "extra", + charset: "latin:extra", tokenize: "full", threshold: 1, depth: 4, @@ -2412,6 +2413,7 @@ if(env !== "light") describe("Operators", function(){ }]; var index = new FlexSearch({ + tokenize: "forward", doc: { id: "id", field: ["title", "body", "blacklist"] @@ -2593,7 +2595,7 @@ describe("Reserved Words", function(){ it("Should have been indexed properly", function(){ var index = new FlexSearch({ - encode: false, + encode: function(str){ return [str]; }, tokenize: "strict", threshold: 0, depth: 3 @@ -2678,7 +2680,7 @@ if(env !== "light") describe("Export / Import", function(){ it("Should have been exported properly (documents)", function(){ var index = new FlexSearch({ - encode: "icase", + tokenize: "strict", threshold: 1, resolution: 3, @@ -2728,7 +2730,7 @@ if(env !== "light") describe("Export / Import", function(){ it("Should have been imported properly (documents)", function(){ var index = new FlexSearch({ - encode: "icase", + tokenize: "strict", threshold: 1, resolution: 3, @@ -2762,21 +2764,21 @@ describe("Presets", function(){ it("Should have been properly initialized", function(){ - expect(FlexSearch.create("memory").length).to.equal(0); - expect(FlexSearch.create("speed").length).to.equal(0); - expect(FlexSearch.create("match").length).to.equal(0); - expect(FlexSearch.create("score").length).to.equal(0); - expect(FlexSearch.create("balance").length).to.equal(0); - expect(FlexSearch.create("fast").length).to.equal(0); + expect(FlexSearch("memory").length).to.equal(0); + expect(FlexSearch("speed").length).to.equal(0); + expect(FlexSearch("match").length).to.equal(0); + expect(FlexSearch("score").length).to.equal(0); + expect(FlexSearch("balance").length).to.equal(0); + expect(FlexSearch("fast").length).to.equal(0); }); it("Should have been properly extended", function(){ - var index = FlexSearch.create("fast"); + var index = FlexSearch("fast"); index.add(0, "foobar"); expect(index.search("bar")).to.have.lengthOf(0); - index = FlexSearch.create("fast", {id: "test", tokenize: "reverse"}); + index = FlexSearch({preset: "speed", id: "test", tokenize: "reverse"}); expect(index.id).to.equal("test"); index.add(0, "foobar"); expect(index.search("bar")).to.have.lengthOf(1); @@ -2792,35 +2794,24 @@ describe("Add Matchers", function(){ it("Should have been added properly", function(){ - FlexSearch.registerMatcher({ - - "1": "a", - "2": "b", - "3": "c", - "[456]": "d" - }); - flexsearch_forward.init({ - encode: false - - }).init({ - - encode: "not-found", + tokenize: "forward", matcher: { - "7": "e" + "1": "a", + "2": "b", + "3": "c", + "7": "e", + "8": "f", + "[456]": "d" } - }).addMatcher({ - - "8": "f" - }).add(0, "12345678"); expect(flexsearch_forward.search("12345678")).to.include(0); expect(flexsearch_forward.search("abcd")).to.include(0); - expect(flexsearch_forward.encode("12345678")).to.equal("abcdddef"); + expect(flexsearch_forward.encode("12345678")).to.eql(["abcdddef"]); }); }); @@ -2902,7 +2893,7 @@ describe("Destroy", function(){ it("Should have been destroyed properly", function(){ - var index = FlexSearch.create() + var index = FlexSearch() .add(0, "foo") .add(1, "bar"); @@ -2919,7 +2910,7 @@ describe("Destroy", function(){ var data = [{id: 0, title: "foo"}, {id: 1, title: "bar"}]; - var index = FlexSearch.create({doc: {id: "id", field: "title"}}) + var index = FlexSearch({doc: {id: "id", field: "title"}}) .add(data) .add(data); @@ -2941,14 +2932,13 @@ describe("Chaining", function(){ it("Should have been chained properly", function(){ - var index = FlexSearch.create({tokenize: "forward", encode: "icase"}) - .addMatcher({"â": "a"}) + var index = FlexSearch({tokenize: "forward", matcher: {"â": "a"}}) .add(0, "foo") .add(1, "bar"); expect(index.search("foo")).to.include(0); expect(index.search("bar")).to.include(1); - expect(index.encode("bâr")).to.equal("bar"); + expect(index.encode("bâr")).to.eql(["bar"]); index.remove(0).update(1, "foo").add(2, "foobâr");