mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-03 02:42:53 +02:00
v0.3.1
This commit is contained in:
95
README.md
95
README.md
@@ -70,13 +70,31 @@ All Features:
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#webworker">Web-Worker Sharding</a> (not available in Node.js)
|
||||
<a href="#profiles">Presets</a>
|
||||
</td>
|
||||
<td>x</td>
|
||||
<td>x</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#async">Async Processing</a>
|
||||
</td>
|
||||
<td>x</td>
|
||||
<td>x</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#webworker">Web-Worker Sharding</a> (not available in Node.js)
|
||||
</td>
|
||||
<td>x</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#contextual">Contextual Indexes</a>
|
||||
@@ -115,10 +133,10 @@ All Features:
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>
|
||||
Auto-Balanced Cache by Popularity
|
||||
<a href="#cache">Auto-Balanced Cache by Popularity</a>
|
||||
</td>
|
||||
<td>x</td>
|
||||
<td>x</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
@@ -127,22 +145,13 @@ All Features:
|
||||
Suggestions (Results)
|
||||
</td>
|
||||
<td>x</td>
|
||||
<td>x</td>
|
||||
<td>-</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>
|
||||
Asynchronous Processing & Concurrency Control
|
||||
</td>
|
||||
<td>x</td>
|
||||
<td>x</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#phonetic">Phonetic Mathching</a>
|
||||
<a href="#phonetic">Phonetic Matching</a>
|
||||
</td>
|
||||
<td>x</td>
|
||||
<td>x</td>
|
||||
@@ -161,7 +170,7 @@ All Features:
|
||||
<td>File Size (gzip)</td>
|
||||
<td>6.7 kb</td>
|
||||
<td>4.5 kb</td>
|
||||
<td>1.9 kb</td>
|
||||
<td>2.1 kb</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -188,9 +197,9 @@ __Query Test: "Gulliver's Travels"__
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>FlexSearch</td>
|
||||
<td>0.3.0</td>
|
||||
<td>2.9 kb</td>
|
||||
<td><b>316336</b></td>
|
||||
<td>0.3.1</td>
|
||||
<td>2.1 kb</td>
|
||||
<td><b>327771</b></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
@@ -198,7 +207,7 @@ __Query Test: "Gulliver's Travels"__
|
||||
<td>Wade</td>
|
||||
<td>0.3.3</td>
|
||||
<td>1.6 kb</td>
|
||||
<td><b>1524</b></td>
|
||||
<td><b>1587</b></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
@@ -206,7 +215,7 @@ __Query Test: "Gulliver's Travels"__
|
||||
<td>JS Search</td>
|
||||
<td>1.4.2</td>
|
||||
<td>3.8 kb</td>
|
||||
<td><b>739</b></td>
|
||||
<td><b>771</b></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
@@ -214,7 +223,7 @@ __Query Test: "Gulliver's Travels"__
|
||||
<td>JSii</td>
|
||||
<td>1.0</td>
|
||||
<td>3.9 kb</td>
|
||||
<td><b>544</b></td>
|
||||
<td><b>584</b></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
@@ -222,7 +231,7 @@ __Query Test: "Gulliver's Travels"__
|
||||
<td>Lunr.js</td>
|
||||
<td>2.3.5</td>
|
||||
<td>8.8 kb</td>
|
||||
<td><b>310</b></td>
|
||||
<td><b>322</b></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
@@ -230,7 +239,7 @@ __Query Test: "Gulliver's Travels"__
|
||||
<td>Elasticlunr.js</td>
|
||||
<td>0.9.6</td>
|
||||
<td>5.6 kb</td>
|
||||
<td><b>286</b></td>
|
||||
<td><b>319</b></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
@@ -246,7 +255,7 @@ __Query Test: "Gulliver's Travels"__
|
||||
<td>bm25</td>
|
||||
<td>0.2</td>
|
||||
<td>3.5 kb</td>
|
||||
<td><b>72</b></td>
|
||||
<td><b>107</b></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
@@ -272,7 +281,7 @@ __Memory Test: "Gulliver's Travels"__
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>FlexSearch</td>
|
||||
<td>0.3.0</td>
|
||||
<td>0.3.1</td>
|
||||
<td>1.33 Mb</td>
|
||||
<td>20.31 kb</td>
|
||||
</tr>
|
||||
@@ -594,6 +603,27 @@ index.search("John", function(result){
|
||||
});
|
||||
```
|
||||
|
||||
Perform queries asynchronously (Promise-based):
|
||||
|
||||
> Make sure the option "async" is enabled on this instance
|
||||
|
||||
```js
|
||||
index.search("John").then(function(result){
|
||||
|
||||
// array of results
|
||||
});
|
||||
```
|
||||
|
||||
Alternatively ES6:
|
||||
|
||||
```js
|
||||
async function search(query){
|
||||
return await index.search(query);
|
||||
}
|
||||
|
||||
const result = search("John");
|
||||
```
|
||||
|
||||
Pass custom options for each query:
|
||||
|
||||
```js
|
||||
@@ -905,6 +935,7 @@ var index = new FlexSearch({
|
||||
});
|
||||
```
|
||||
|
||||
<a name="cache"></a>
|
||||
#### Enable Auto-Balanced Cache
|
||||
|
||||
Create index and just set a limit of cache entries:
|
||||
@@ -1504,7 +1535,17 @@ __Supported Build Flags__
|
||||
<td align="left">Values</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>SUPPORT_DEBUG</td>
|
||||
<td>DEBUG</td>
|
||||
<td>true, false</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>PROFILER</td>
|
||||
<td>true, false</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>SUPPORT_ENCODER (built-in encoders)</td>
|
||||
<td>true, false</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
@@ -1524,7 +1565,7 @@ __Supported Build Flags__
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>SUPPORT_BUILTINS (built-in encoders)</td>
|
||||
<td>SUPPORT_PRESETS</td>
|
||||
<td>true, false</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@@ -1,24 +1,31 @@
|
||||
/*
|
||||
FlexSearch v0.3.0
|
||||
FlexSearch v0.3.1
|
||||
Copyright 2019 Nextapps GmbH
|
||||
Author: Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(m,x,c){var r;(r=c.define)&&r.amd?r([],function(){return x}):(r=c.modules)?r[m.toLowerCase()]=x:"object"===typeof exports?module.exports=x:c[m]=x})("FlexSearch",function(){function m(b){"string"===typeof b&&(b=D[b]);b||(b=v);this.id=b.id||J++;this.init(b);x(this,"index",function(){return this.a});x(this,"length",function(){return Object.keys(this.a).length})}function x(b,a,d){Object.defineProperty(b,a,{get:d})}function c(b){return new RegExp(b,"g")}function r(b,a,d){if("undefined"===
|
||||
typeof d){for(d=0;d<a.length;d+=2)b=b.replace(a[d],a[d+1]);return b}return b.replace(a,d)}function z(b,a,d,n,g,e,c){if(a[d])return a[d];g=g?(9-(c||6))*e+(c||6)*g:e;a[d]=g;g>=c&&(b=b[g+.5>>0],b=b[d]||(b[d]=[]),b[b.length]=n);return g}function A(b,a){if(b)for(var d=Object.keys(b),n=0,g=d.length;n<g;n++){var c=d[n],k=b[c];if(k)for(var f=0,h=k.length;f<h;f++)if(k[f]===a){1===h?delete b[c]:k.splice(f,1);break}else"object"===typeof k[f]&&A(k[f],a)}}function E(b){var a=[];if(!b)return a;for(var d=0,n=0,
|
||||
c=0,e="",k=b.length,f=0;f<k;f++){var h=b[f];"a"===h||"e"===h||"i"===h||"o"===h||"u"===h||"y"===h?d++:n++;" "!==h&&(e+=h);if(" "===h||d>=(8<k?2:1)&&2<=n||2<=d&&n>=(8<k?2:1)||f===k-1)e&&(a[c]&&2<e.length&&c++,a[c]=a[c]?a[c]+e:e," "===h&&c++,e=""),n=d=0}return a}function B(b){for(var a="",d="",n="",c=0;c<b.length;c++){var e=b[c];if(e!==d)if(c&&"h"===e){if(n="a"===n||"e"===n||"i"===n||"o"===n||"u"===n||"y"===n,("a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d)&&n||" "===d)a+=e}else a+=e;n=c===b.length-
|
||||
1?"":b[c+1];d=e}return a}function K(b,a){b=b.length-a.length;return 0>b?1:b?-1:0}function L(b,a){b=b.length-a.length;return 0>b?-1:b?1:0}function F(b){for(var a=Array(b),d=0;d<b;d++)a[d]={};return a}var v={encode:"icase",mode:"forward",g:!1,cache:!1,async:!1,m:!1,threshold:0,depth:0},D={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",
|
||||
mode:"strict",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},C=[],J=0,G=c("[ -/]"),H={},I={};m.create=function(b){return new this(b)};m.registerMatcher=function(b){for(var a in b)b.hasOwnProperty(a)&&C.push(c(a),b[a]);return this};m.registerEncoder=function(b,a){y[b]=a.bind(y);return this};m.registerLanguage=function(b,a){H[b]=a.filter;I[b]=a.stemmer;return this};m.encode=function(b,a){return y[b](a)};m.prototype.init=function(b){this.j=[];b||(b=v);var a=b.profile;
|
||||
a=a?D[a]:{};this.mode=b.mode||a.mode||this.mode||v.mode;this.threshold=b.threshold||a.threshold||this.threshold||v.threshold;this.depth=b.depth||a.depth||this.depth||v.depth;this.g=b.suggest||this.g||v.g;this.f=(a=b.encode||a.encode)&&y[a]&&y[a].bind(y)||("function"===typeof a?a:this.f||!1);(a=b.matcher)&&this.addMatcher(a);if(a=b.filter){a=H[a]||a;var d=this.f,n={};if(a)for(var g=0;g<a.length;g++){var e=d?d(a[g]):a[g];n[e]=String.fromCharCode(65E3-a.length+g)}this.filter=n}if(a=b.stemmer){a=I[a]||
|
||||
a;d=this.f;n=[];if(a)for(var k in a)a.hasOwnProperty(k)&&(g=d?d(k):k,n.push(c("(?=.{"+(g.length+3)+",})"+g+"$"),d?d(a[k]):a[k]));this.stemmer=n}this.i=F(10);this.c={};this.a={};this.h=!0;this.b=(this.cache=a=b.cache||this.cache||v.cache)?new M(a):!1;return this};m.prototype.encode=function(b){b&&C.length&&(b=r(b,C));b&&this.j.length&&(b=r(b,this.j));b&&this.f&&(b=this.f(b));b&&this.stemmer&&(b=r(b,this.stemmer));return b};m.prototype.addMatcher=function(b){var a=this.j,d;for(d in b)b.hasOwnProperty(d)&&
|
||||
a.push(c(d),b[d]);return this};m.prototype.add=function(b,a,d){if(a&&"string"===typeof a&&(b||0===b))if(this.a[b]&&!d)this.update(b,a);else{a=this.encode(a);if(!a.length)return this;d=this.mode;a="function"===typeof d?d(a):"ngram"===d?E(a):a.split(G);for(var c={_ctx:{}},g=this.threshold,e=this.depth,k=this.i,f=a.length,h=0;h<f;h++){var u=a[h];if(u){var p=u.length,t=(f-h)/f,q="";switch(d){case "reverse":case "both":for(var l=p-1;1<=l;l--)q=u[l]+q,z(k,c,q,b,(p-l)/p,t,g);q="";case "forward":for(l=0;l<
|
||||
p;l++)q+=u[l],z(k,c,q,b,1,t,g);break;case "full":for(l=0;l<p;l++)for(var m=(p-l)/p,r=p;r>l;r--)q=u.substring(l,r),z(k,c,q,b,m,t,g);break;default:if(p=z(k,c,u,b,1,t,g),e&&1<f&&p>=g)for(p=c._ctx[u]||(c._ctx[u]={}),u=this.c[u]||(this.c[u]=F(10)),t=h-e,q=h+e+1,0>t&&(t=0),q>f&&(q=f);t<q;t++)t!==h&&z(u,p,a[t],b,0,10-(t<h?h-t:t-h),g)}}}this.a[b]="1";this.h=!1}return this};m.prototype.update=function(b,a){this.a[b]&&a&&"string"===typeof a&&(this.remove(b),this.add(b,a,!0));return this};m.prototype.remove=
|
||||
function(b){if(this.a[b]){for(var a=0;10>a;a++)A(this.i[a],b);this.depth&&A(this.c,b);delete this.a[b];this.h=!1}return this};m.prototype.search=function(b,a,d){var c=[];if("object"===typeof b){d=b.callback||a;a=b.limit;var g=b.threshold;b=b.query}g||(g=this.threshold||0);"function"===typeof a?(d=a,a=1E3):a||0===a||(a=1E3);if(d)d(this.search(b,a));else{if(!b||"string"!==typeof b)return c;d=b;if(this.cache)if(this.h){var e=this.b.get(b);if(e)return e}else this.b.clear(),this.h=!0;d=this.encode(d);
|
||||
if(!d.length)return c;e=this.mode;e="function"===typeof e?e(d):"ngram"===e?E(d):d.split(G);var k=e.length,f=!0;d=[];var h={};if(1<k)if(this.depth){var u=!0;var p=e[0];h[p]="1"}else e.sort(K);var t;if(!u||(t=this.c)[p])for(var q=u?1:0;q<k;q++){var l=e[q];if(l&&!h[l]){for(var m,r=!1,w=[],x=0,v=9;v>=g;v--)m=(u?t[p]:this.i)[v],m[l]&&(w[x++]=m[l],r=!0);if(r)d[d.length]=1<x?d.concat.apply([],w):w[0];else if(!this.g){f=!1;break}h[l]="1"}p=l}else f=!1;if(f)a:if(g=this.g,c=[],p=[],u=d.length,1<u){d.sort(L);
|
||||
t={};e=d[0];k=e.length;for(f=0;f<k;)t[e[f++]]=1;q=0;for(l=1;l<u;){m=!1;r=l===u-1;p=[];e=d[l];k=e.length;for(f=-1;f<k;)if(h=e[++f],t[h])if(w=t[h],w===l){if(r){if(c[q++]=h,a&&q===a)break a}else t[h]=l+1;m=!0}else g&&(w=p[w]?p[w]:p[w]=[],w[w.length]=h);if(!m&&!g)break;l++}if(g&&(q=c.length,(k=p.length)&&(!a||q<a)))for(l=k-1;0<=l;l--)if(h=p[l])for(f=0;f<h.length;f++)if(c[q++]=h[f],a&&q===a)break a}else u&&(c=d[0],a&&c.length>a&&(c=c.slice(0,a)));this.cache&&this.b.set(b,c);return c}};m.prototype.clear=
|
||||
function(){this.destroy();return this.init()};m.prototype.destroy=function(){this.cache&&(this.b.clear(),this.b=null);this.filter=this.stemmer=this.i=this.c=this.a=null;return this};var y={icase:function(b){return b.toLowerCase()},simple:function(){var b=[c("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",c("[\u00e8\u00e9\u00ea\u00eb]"),"e",c("[\u00ec\u00ed\u00ee\u00ef]"),"i",c("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",c("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",c("[\u00fd\u0177\u00ff]"),"y",c("\u00f1"),
|
||||
"n",c("\u00e7"),"c",c("\u00df"),"s",c(" & ")," and ",c("[-/]")," ",c("[^a-z0-9 ]"),"",c("\\s\\s+")," "];return function(a){a=r(a.toLowerCase(),b);return" "!==a?a:""}}(),advanced:function(){var b=[c("ae"),"a",c("ai"),"ei",c("ay"),"ei",c("ey"),"ei",c("oe"),"o",c("ue"),"u",c("ie"),"i",c("sz"),"s",c("zs"),"s",c("sh"),"s",c("ck"),"k",c("cc"),"k",c("dt"),"t",c("ph"),"f",c("pf"),"f",c("ou"),"o",c("uo"),"u"];return function(a,d){if(!a)return a;a=this.simple(a);2<a.length&&(a=r(a,b));d||1<a.length&&(a=B(a));
|
||||
return a}}(),extra:function(){var b=[c("p"),"b",c("z"),"s",c("[cgq]"),"k",c("n"),"m",c("d"),"t",c("[vw]"),"f",c("[aeiouy]"),""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(var d=0;d<a.length;d++){var c=a[d];1<c.length&&(a[d]=c[0]+r(c.substring(1),b))}a=a.join(" ");a=B(a)}return a}}(),balance:function(){var b=[c("[-/]")," ",c("[^a-z0-9 ]"),"",c("\\s\\s+")," "];return function(a){return B(r(a.toLowerCase(),b))}}()},M=function(){function b(a){this.clear();
|
||||
this.l=!0!==a&&a}b.prototype.clear=function(){this.cache={};this.count={};this.index={};this.a=[]};b.prototype.set=function(a,b){if(this.l&&"undefined"===typeof this.cache[a]){var c=this.a.length;if(c===this.l){c--;var d=this.a[c];delete this.cache[d];delete this.count[d];delete this.index[d]}this.index[a]=c;this.a[c]=a;this.count[a]=-1;this.cache[a]=b;this.get(a)}else this.cache[a]=b};b.prototype.get=function(a){var b=this.cache[a];if(this.l&&b){var c=++this.count[a],g=this.index,e=g[a];if(0<e){for(var k=
|
||||
this.a,f=e;this.count[k[--e]]<=c&&-1!==e;);e++;if(e!==f){for(c=f;c>e;c--)f=k[c-1],k[c]=f,g[f]=c;k[e]=a;g[a]=e}}}return b};return b}();return m}(!1),this);
|
||||
'use strict';function J(d){var c=0;return function(){return c<d.length?{done:!1,value:d[c++]}:{done:!0}}}function K(d){var c="undefined"!=typeof Symbol&&Symbol.iterator&&d[Symbol.iterator];return c?c.call(d):{next:J(d)}}var S="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,T="function"==typeof Object.defineProperties?Object.defineProperty:function(d,c,a){d!=Array.prototype&&d!=Object.prototype&&(d[c]=a.value)};
|
||||
function U(d,c){if(c){var a=S;d=d.split(".");for(var f=0;f<d.length-1;f++){var g=d[f];g in a||(a[g]={});a=a[g]}d=d[d.length-1];f=a[d];c=c(f);c!=f&&null!=c&&T(a,d,{configurable:!0,writable:!0,value:c})}}
|
||||
U("Promise",function(d){function c(a){this.b=0;this.g=void 0;this.a=[];var p=this.c();try{a(p.resolve,p.reject)}catch(C){p.reject(C)}}function a(){this.a=null}function f(a){return a instanceof c?a:new c(function(p){p(a)})}if(d)return d;a.prototype.b=function(a){if(null==this.a){this.a=[];var p=this;this.c(function(){p.g()})}this.a.push(a)};var g=S.setTimeout;a.prototype.c=function(a){g(a,0)};a.prototype.g=function(){for(;this.a&&this.a.length;){var a=this.a;this.a=[];for(var c=0;c<a.length;++c){var d=
|
||||
a[c];a[c]=null;try{d()}catch(z){this.f(z)}}}this.a=null};a.prototype.f=function(a){this.c(function(){throw a;})};c.prototype.c=function(){function a(a){return function(p){d||(d=!0,a.call(c,p))}}var c=this,d=!1;return{resolve:a(this.o),reject:a(this.f)}};c.prototype.o=function(a){if(a===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(a instanceof c)this.s(a);else{a:switch(typeof a){case "object":var d=null!=a;break a;case "function":d=!0;break a;default:d=!1}d?this.m(a):this.h(a)}};
|
||||
c.prototype.m=function(a){var c=void 0;try{c=a.then}catch(C){this.f(C);return}"function"==typeof c?this.u(c,a):this.h(a)};c.prototype.f=function(a){this.i(2,a)};c.prototype.h=function(a){this.i(1,a)};c.prototype.i=function(a,c){if(0!=this.b)throw Error("Cannot settle("+a+", "+c+"): Promise already settled in state"+this.b);this.b=a;this.g=c;this.j()};c.prototype.j=function(){if(null!=this.a){for(var a=0;a<this.a.length;++a)w.b(this.a[a]);this.a=null}};var w=new a;c.prototype.s=function(a){var c=this.c();
|
||||
a.l(c.resolve,c.reject)};c.prototype.u=function(a,c){var d=this.c();try{a.call(c,d.resolve,d.reject)}catch(z){d.reject(z)}};c.prototype.then=function(a,d){function f(a,c){return"function"==typeof a?function(c){try{p(a(c))}catch(E){g(E)}}:c}var p,g,B=new c(function(a,c){p=a;g=c});this.l(f(a,p),f(d,g));return B};c.prototype.catch=function(a){return this.then(void 0,a)};c.prototype.l=function(a,c){function d(){switch(f.b){case 1:a(f.g);break;case 2:c(f.g);break;default:throw Error("Unexpected state: "+
|
||||
f.b);}}var f=this;null==this.a?w.b(d):this.a.push(d)};c.resolve=f;c.reject=function(a){return new c(function(c,d){d(a)})};c.race=function(a){return new c(function(c,d){for(var p=K(a),g=p.next();!g.done;g=p.next())f(g.value).l(c,d)})};c.all=function(a){var d=K(a),g=d.next();return g.done?f([]):new c(function(a,c){function p(c){return function(d){A[c]=d;v--;0==v&&a(A)}}var A=[],v=0;do A.push(void 0),v++,f(g.value).l(p(A.length-1),c),g=d.next();while(!g.done)})};return c});
|
||||
(function(d,c,a){var f;(f=a.define)&&f.amd?f([],function(){return c}):(f=a.modules)?f[d.toLowerCase()]=c:"object"===typeof exports?module.exports=c:a[d]=c})("FlexSearch",function(){function d(b){F(b)&&(b=L[b]);b||(b=x);this.id=b.id||W++;this.init(b);c(this,"index",function(){return this.a});c(this,"length",function(){return Object.keys(this.a).length})}function c(b,e,a){Object.defineProperty(b,e,{get:a})}function a(b){return new RegExp(b,"g")}function f(b,e){for(var a=0;a<e.length;a+=2)b=b.replace(e[a],
|
||||
e[a+1]);return b}function g(b,e,a,c,d,D,l){if(e[a])return e[a];d=d?(9-(l||6))*D+(l||6)*d:D;e[a]=d;d>=l&&(b=b[d+.5>>0],b=b[a]||(b[a]=[]),b[b.length]=c);return d}function w(b,e){if(b)for(var a=Object.keys(b),c=0,d=a.length;c<d;c++){var D=a[c],l=b[D];if(l)for(var f=0,h=l.length;f<h;f++)if(l[f]===e){1===h?delete b[D]:l.splice(f,1);break}else"object"===typeof l[f]&&w(l[f],e)}}function p(b){var e=[];if(!b)return e;for(var a=0,c=0,d=0,f="",l=b.length,g=0;g<l;g++){var h=b[g];"a"===h||"e"===h||"i"===h||"o"===
|
||||
h||"u"===h||"y"===h?a++:c++;" "!==h&&(f+=h);if(" "===h||a>=(8<l?2:1)&&2<=c||2<=a&&c>=(8<l?2:1)||g===l-1)f&&(e[d]&&2<f.length&&d++,e[d]=e[d]?e[d]+f:f," "===h&&d++,f=""),c=a=0}return e}function B(b){for(var e="",a="",c="",d=0;d<b.length;d++){var f=b[d];if(f!==a)if(d&&"h"===f){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===a||"e"===a||"i"===a||"o"===a||"u"===a||"y"===a)&&c||" "===a)e+=f}else e+=f;c=d===b.length-1?"":b[d+1];a=f}return e}function C(b,e){b=b.length-e.length;return 0>b?
|
||||
1:b?-1:0}function z(b,e){b=b.length-e.length;return 0>b?-1:b?1:0}function V(b,e,a){var c=[],d=[],f=b.length;if(1<f){b.sort(z);for(var t={},g=b[0],h=g.length,q=0;q<h;)t[g[q++]]=1;for(var k,m=0,n=0;++n<f;){var r=!1,p=n===f-1;d=[];g=b[n];h=g.length;for(q=0;q<h;)if(k=g[q++],t[k]){var u=t[k];if(u===n){if(p){if(c[m++]=k,e&&m===e)return c}else t[k]=n+1;r=!0}else a&&(u=d[u]||(d[u]=[]),u[u.length]=k)}if(!r&&!a)break}if(a&&(m=c.length,(n=d.length)&&(!e||m<e)))for(;n--;)if(k=d[n])for(b=0,a=k.length;b<a;b++)if(c[m++]=
|
||||
k[b],e&&m===e)return c}else f&&(c=b[0],e&&c.length>e&&(c=c.slice(0,e)));return c}function F(b){return"string"===typeof b}function A(b){return"function"===typeof b}function v(b){return"undefined"===typeof b}function H(b){b.j||(b.j=N(function(){b.j=0;var a=b.async;a&&(b.async=!1);if(b.b.length){for(var c=Date.now(),d;(d=b.b.shift())||0===d;){var f=b.c[d];switch(f[0]){case G.add:b.add(f[1],f[2]);break;case G.remove:b.remove(f[1])}delete b.c[d];if(100<Date.now()-c)break}b.b.length&&H(b)}a&&(b.async=a)},
|
||||
1,"search-async-"+b.id))}function E(b){for(var a=Array(b),c=0;c<b;c++)a[c]={};return a}var x={encode:"icase",mode:"forward",v:!1,cache:!1,async:!1,w:!1,threshold:0,depth:0},L={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"strict",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},I=[],
|
||||
W=0,G={add:0,update:1,remove:2},O=a("[ -/]"),P={},Q={},R=function(){for(var b=Object.getOwnPropertyNames({}.__proto__),a={},c=0;c<b.length;c++)a[b[c]]=1;return a}();d.create=function(b){return new d(b)};d.registerMatcher=function(b){for(var e in b)b.hasOwnProperty(e)&&I.push(a(e),b[e]);return this};d.registerEncoder=function(b,a){y[b]=a.bind(y);return this};d.registerLanguage=function(b,a){P[b]=a.filter;Q[b]=a.stemmer;return this};d.encode=function(b,a){return R[b]?a:y[b](a)};d.prototype.init=function(b){this.i=
|
||||
[];b||(b=x);var e=b.profile,c=e?L[e]:{};this.mode=b.mode||c.mode||this.mode||x.mode;this.async=v(e=b.async)?this.async||x.async:e;this.threshold=v(e=b.threshold)?c.threshold||this.threshold||x.threshold:e;this.depth=v(e=b.depth)?c.depth||this.depth||x.depth:e;this.g=(e=v(e=b.encode)?c.encode:e)&&y[e]&&y[e].bind(y)||(A(e)?e:this.g||!1);(e=b.matcher)&&this.addMatcher(e);if(e=b.filter){e=P[e]||e;c=this.g;var d={};if(e)for(var f=0;f<e.length;f++){var g=c?c(e[f]):e[f];d[g]=String.fromCharCode(65E3-e.length+
|
||||
f)}this.filter=d}if(e=b.stemmer){b=Q[e]||e;e=this.g;c=[];if(b)for(var l in b)b.hasOwnProperty(l)&&(d=e?e(l):l,c.push(a("(?=.{"+(d.length+3)+",})"+d+"$"),e?e(b[l]):b[l]));this.stemmer=c}this.h=E(10);this.f={};this.a={};this.c={};this.b=[];this.j=0;return this};d.prototype.encode=function(b){b&&I.length&&(b=f(b,I));b&&this.i.length&&(b=f(b,this.i));b&&this.g&&(b=this.g(b));b&&this.stemmer&&(b=f(b,this.stemmer));return b};d.prototype.addMatcher=function(b){var e=this.i,c;for(c in b)b.hasOwnProperty(c)&&
|
||||
e.push(a(c),b[c]);return this};d.prototype.add=function(b,a,c){if(a&&F(a)&&(b&&!R[b]||0===b))if(this.a[b]&&!c)this.update(b,a);else{if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[G.add,b,a],H(this),this;a=this.encode(a);if(!a.length)return this;c=this.mode;a=A(c)?c(a):"ngram"===c?p(a):a.split(O);for(var e={_ctx:{}},d=this.threshold,f=this.depth,l=this.h,t=a.length,h=0;h<t;h++){var q=a[h];if(q){var k=q.length,m=(t-h)/t,n="";switch(c){case "reverse":case "both":for(var r=k-1;1<=
|
||||
r;r--)n=q[r]+n,g(l,e,n,b,(k-r)/k,m,d);n="";case "forward":for(r=0;r<k;r++)n+=q[r],g(l,e,n,b,1,m,d);break;case "full":for(r=0;r<k;r++)for(var v=(k-r)/k,u=k;u>r;u--)n=q.substring(r,u),g(l,e,n,b,v,m,d);break;default:if(k=g(l,e,q,b,1,m,d),f&&1<t&&k>=d)for(k=e._ctx[q]||(e._ctx[q]={}),q=this.f[q]||(this.f[q]=E(10)),m=h-f,n=h+f+1,0>m&&(m=0),n>t&&(n=t);m<n;m++)m!==h&&g(q,k,a[m],b,0,10-(m<h?h-m:m-h),d)}}}this.a[b]=1}return this};d.prototype.update=function(a,c){this.a[a]&&F(c)&&(this.remove(a),this.add(a,
|
||||
c,!0));return this};d.prototype.remove=function(a){if(this.a[a]){if(this.async)return this.c[a]||(this.b[this.b.length]=a),this.c[a]=[G.remove,a],H(this),this;for(var b=0;10>b;b++)w(this.h[b],a);this.depth&&w(this.f,a);delete this.a[a]}return this};d.prototype.search=function(a,c,d,f){var b=a,e=[];if("object"===typeof a){(d=a.callback||c)&&(b.callback=null);c=a.limit;var g=a.threshold;a=a.query}g||(g=this.threshold||0);A(c)?(d=c,c=1E3):c||0===c||(c=1E3);if(d){var t=this;N(function(){d(t.search(b,
|
||||
c,null,!0));t=null},1,"search-"+this.id)}else{if(!f&&this.async){var h=this;return new Promise(function(a){a(h.search(b,c,null,!0));h=null})}if(!a||!F(a))return e;b=a;b=this.encode(b);if(!b.length)return e;a=this.mode;a=A(a)?a(b):"ngram"===a?p(b):b.split(O);f=a.length;var q=!0,k=[],m={};if(1<f)if(this.depth){var n=!0;var r=a[0];m[r]=1}else a.sort(C);var v;if(!n||(v=this.f)[r])for(var u=n?1:0;u<f;u++){var w=a[u];if(w&&!m[w]){var x=void 0;x=void 0;for(var M=!1,y=[],B=0,z=9;z>=g;z--)if(x=(n?v[r]:this.h)[z],
|
||||
x=x[w])y[B++]=x,M=!0;if(M)k[k.length]=1<B?k.concat.apply([],y):y[0];else{q=!1;break}m[w]=1}r=w}else q=!1;q&&(e=V(k,c,!1));return e}};d.prototype.clear=function(){this.destroy();return this.init()};d.prototype.destroy=function(){this.filter=this.stemmer=this.h=this.f=this.a=this.c=this.b=null;return this};var y={icase:function(a){return a.toLowerCase()},simple:function(){var b=[a("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",a("[\u00e8\u00e9\u00ea\u00eb]"),"e",a("[\u00ec\u00ed\u00ee\u00ef]"),"i",a("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),
|
||||
"o",a("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",a("[\u00fd\u0177\u00ff]"),"y",a("\u00f1"),"n",a("\u00e7"),"c",a("\u00df"),"s",a(" & ")," and ",a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(a){a=f(a.toLowerCase(),b);return" "!==a?a:""}}(),advanced:function(){var b=[a("ae"),"a",a("ai"),"ei",a("ay"),"ei",a("ey"),"ei",a("oe"),"o",a("ue"),"u",a("ie"),"i",a("sz"),"s",a("zs"),"s",a("sh"),"s",a("ck"),"k",a("cc"),"k",a("dt"),"t",a("ph"),"f",a("pf"),"f",a("ou"),"o",a("uo"),"u"];return function(a,
|
||||
c){if(!a)return a;a=this.simple(a);2<a.length&&(a=f(a,b));c||1<a.length&&(a=B(a));return a}}(),extra:function(){var b=[a("p"),"b",a("z"),"s",a("[cgq]"),"k",a("n"),"m",a("d"),"t",a("[vw]"),"f",a("[aeiouy]"),""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(var c=0;c<a.length;c++){var d=a[c];1<d.length&&(a[c]=d[0]+f(d.substring(1),b))}a=a.join(" ");a=B(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(a){return B(f(a.toLowerCase(),
|
||||
b))}}()},N=function(){var a={};return function(b,c,d){var e=a[d];e&&clearTimeout(e);return a[d]=setTimeout(b,c)}}();return d}(!1),this);
|
||||
|
364
flexsearch.js
364
flexsearch.js
@@ -1,5 +1,5 @@
|
||||
;/**!
|
||||
* @preserve FlexSearch v0.3.0
|
||||
* @preserve FlexSearch v0.3.1
|
||||
* Copyright 2019 Nextapps GmbH
|
||||
* Author: Thomas Wilkerling
|
||||
* Released under the Apache 2.0 Licence
|
||||
@@ -14,6 +14,7 @@
|
||||
/** @define {boolean} */ const SUPPORT_CACHE = true;
|
||||
/** @define {boolean} */ const SUPPORT_ASYNC = true;
|
||||
/** @define {boolean} */ const SUPPORT_PRESETS = true;
|
||||
/** @define {boolean} */ const SUPPORT_SUGGESTIONS = true;
|
||||
|
||||
// noinspection ThisExpressionReferencesGlobalObjectJS
|
||||
(function(){
|
||||
@@ -23,8 +24,8 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @struct
|
||||
* @const
|
||||
* @enum {boolean|string|number}
|
||||
*/
|
||||
|
||||
const defaults = {
|
||||
@@ -121,7 +122,6 @@
|
||||
*/
|
||||
|
||||
const regex_split = regex("[ -\/]");
|
||||
|
||||
const filter = {};
|
||||
const stemmer = {};
|
||||
|
||||
@@ -140,7 +140,6 @@
|
||||
}
|
||||
|
||||
return map;
|
||||
|
||||
})();
|
||||
|
||||
/**
|
||||
@@ -161,7 +160,7 @@
|
||||
|
||||
if(DEBUG && !options){
|
||||
|
||||
console.warn("Preset not found: " + presets[options]);
|
||||
console.warn("Preset not found: " + options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +195,7 @@
|
||||
|
||||
FlexSearch.create = function(options){
|
||||
|
||||
return new this(options);
|
||||
return new FlexSearch(options);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -232,44 +231,44 @@
|
||||
|
||||
/**
|
||||
* @param {string} lang
|
||||
* @param {Object} languagePack
|
||||
* @param {Object} language_pack
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.registerLanguage = function(lang, languagePack){
|
||||
FlexSearch.registerLanguage = function(lang, language_pack){
|
||||
|
||||
/**
|
||||
* @type {Array<string>}
|
||||
*/
|
||||
|
||||
filter[lang] = languagePack["filter"];
|
||||
filter[lang] = language_pack["filter"];
|
||||
|
||||
/**
|
||||
* @type {Object<string, string>}
|
||||
*/
|
||||
|
||||
stemmer[lang] = languagePack["stemmer"];
|
||||
stemmer[lang] = language_pack["stemmer"];
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {!string} name
|
||||
* @param {?string} value
|
||||
* @param {string} name
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.encode = function(name, value){
|
||||
|
||||
// if(index_blacklist[name]){
|
||||
//
|
||||
// return value;
|
||||
// }
|
||||
// else{
|
||||
if(index_blacklist[name]){
|
||||
|
||||
return value;
|
||||
}
|
||||
else{
|
||||
|
||||
return global_encoder[name](value);
|
||||
//}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -279,7 +278,7 @@
|
||||
|
||||
FlexSearch.prototype.init = function(options){
|
||||
|
||||
/** @type {Array} */
|
||||
/** @type {Array} @private */
|
||||
this._matcher = [];
|
||||
|
||||
options || (options = defaults);
|
||||
@@ -287,6 +286,11 @@
|
||||
let custom = /** @type {?string} */ (options["profile"]);
|
||||
const profile = SUPPORT_PRESETS && custom ? presets[custom] : {};
|
||||
|
||||
if(DEBUG && !profile){
|
||||
|
||||
console.warn("Preset not found: " + custom);
|
||||
}
|
||||
|
||||
// initialize worker
|
||||
|
||||
if(SUPPORT_WORKER && (custom = options["worker"])){
|
||||
@@ -296,11 +300,16 @@
|
||||
const self = this;
|
||||
const threads = parseInt(custom, 10) || 4;
|
||||
|
||||
/** @private */
|
||||
self._current_task = -1;
|
||||
/** @private */
|
||||
self._task_completed = 0;
|
||||
/** @private */
|
||||
self._task_result = [];
|
||||
/** @private */
|
||||
self._current_callback = null;
|
||||
//self._ids_count = new Array(threads);
|
||||
/** @private */
|
||||
self._worker = new Array(threads);
|
||||
|
||||
for(let i = 0; i < threads; i++){
|
||||
@@ -344,17 +353,14 @@
|
||||
|
||||
options["worker"] = false;
|
||||
|
||||
// if(SUPPORT_ASYNC){
|
||||
//
|
||||
// options["async"] = true;
|
||||
// }
|
||||
|
||||
/** @private */
|
||||
this._worker = null;
|
||||
}
|
||||
}
|
||||
|
||||
// apply custom options
|
||||
|
||||
/** @private */
|
||||
this.mode = (
|
||||
|
||||
options["mode"] ||
|
||||
@@ -363,60 +369,77 @@
|
||||
defaults.mode
|
||||
);
|
||||
|
||||
if(SUPPORT_ASYNC) this.async = (
|
||||
if(SUPPORT_ASYNC) /** @private */ this.async = (
|
||||
|
||||
options["async"] ||
|
||||
this.async ||
|
||||
defaults.async
|
||||
is_undefined(custom = options["async"]) ?
|
||||
|
||||
this.async ||
|
||||
defaults.async
|
||||
:
|
||||
custom
|
||||
);
|
||||
|
||||
if(SUPPORT_WORKER) this.worker = (
|
||||
if(SUPPORT_WORKER) /** @private */ this.worker = (
|
||||
|
||||
options["worker"] ||
|
||||
this.worker ||
|
||||
defaults.worker
|
||||
is_undefined(custom = options["worker"]) ?
|
||||
|
||||
this.worker ||
|
||||
defaults.worker
|
||||
:
|
||||
custom
|
||||
);
|
||||
|
||||
/** @private */
|
||||
this.threshold = (
|
||||
|
||||
options["threshold"] ||
|
||||
profile.threshold ||
|
||||
this.threshold ||
|
||||
defaults.threshold
|
||||
is_undefined(custom = options["threshold"]) ?
|
||||
|
||||
profile.threshold ||
|
||||
this.threshold ||
|
||||
defaults.threshold
|
||||
:
|
||||
custom
|
||||
);
|
||||
|
||||
/** @private */
|
||||
this.depth = (
|
||||
|
||||
options["depth"] ||
|
||||
profile.depth ||
|
||||
this.depth ||
|
||||
defaults.depth
|
||||
is_undefined(custom = options["depth"]) ?
|
||||
|
||||
profile.depth ||
|
||||
this.depth ||
|
||||
defaults.depth
|
||||
:
|
||||
custom
|
||||
);
|
||||
|
||||
this.suggest = (
|
||||
if(SUPPORT_SUGGESTIONS){
|
||||
|
||||
options["suggest"] ||
|
||||
this.suggest ||
|
||||
defaults.suggest
|
||||
);
|
||||
/** @private */
|
||||
this.suggest = (
|
||||
|
||||
custom = options["encode"] || profile.encode;
|
||||
is_undefined(custom = options["suggest"]) ?
|
||||
|
||||
this.suggest ||
|
||||
defaults.suggest
|
||||
:
|
||||
custom
|
||||
);
|
||||
}
|
||||
|
||||
custom = is_undefined(custom = options["encode"]) ?
|
||||
|
||||
profile.encode
|
||||
:
|
||||
custom;
|
||||
|
||||
/** @private */
|
||||
this.encoder = (
|
||||
|
||||
(custom && global_encoder[custom] && global_encoder[custom].bind(global_encoder)) ||
|
||||
(typeof custom === "function" ? custom : this.encoder || false)
|
||||
(is_function(custom) ? custom : this.encoder || false)
|
||||
);
|
||||
|
||||
if(DEBUG){
|
||||
|
||||
this.debug = (
|
||||
|
||||
options["debug"] ||
|
||||
this.debug
|
||||
);
|
||||
}
|
||||
|
||||
if((custom = options["matcher"])) {
|
||||
|
||||
this.addMatcher(
|
||||
@@ -428,42 +451,56 @@
|
||||
|
||||
if((custom = options["filter"])) {
|
||||
|
||||
/** @private */
|
||||
this.filter = init_filter(filter[custom] || custom, this.encoder);
|
||||
}
|
||||
|
||||
if((custom = options["stemmer"])) {
|
||||
|
||||
/** @private */
|
||||
this.stemmer = init_stemmer(stemmer[custom] || custom, this.encoder);
|
||||
}
|
||||
|
||||
// initialize primary index
|
||||
|
||||
/** @private */
|
||||
this._map = create_object_array(10);
|
||||
/** @private */
|
||||
this._ctx = {};
|
||||
/** @private */
|
||||
this._ids = {};
|
||||
/** @private */
|
||||
this._stack = {};
|
||||
/** @private */
|
||||
this._stack_keys = [];
|
||||
|
||||
/**
|
||||
* @type {number|null}
|
||||
* @private
|
||||
*/
|
||||
|
||||
this._timer = 0;
|
||||
|
||||
if(SUPPORT_CACHE) {
|
||||
|
||||
/** @private */
|
||||
this._cache_status = true;
|
||||
|
||||
/** @private */
|
||||
this.cache = custom = (
|
||||
|
||||
options["cache"] ||
|
||||
this.cache ||
|
||||
defaults.cache
|
||||
is_undefined(custom = options["cache"]) ?
|
||||
|
||||
this.cache ||
|
||||
defaults.cache
|
||||
:
|
||||
custom
|
||||
);
|
||||
|
||||
/** @private */
|
||||
this._cache = custom ?
|
||||
|
||||
(new Cache(custom))
|
||||
new Cache(custom)
|
||||
:
|
||||
false;
|
||||
}
|
||||
@@ -563,7 +600,7 @@
|
||||
|
||||
/**
|
||||
* @param {number|string} id
|
||||
* @param {?string} content
|
||||
* @param {string} content
|
||||
* @param {boolean=} _skip_update
|
||||
* @this {FlexSearch}
|
||||
* @export
|
||||
@@ -571,7 +608,7 @@
|
||||
|
||||
FlexSearch.prototype.add = function(id, content, _skip_update){
|
||||
|
||||
if(content && (typeof content === "string") && ((id /*&& !index_blacklist[id]*/) || (id === 0))){
|
||||
if(content && is_string(content) && ((id && !index_blacklist[id]) || (id === 0))){
|
||||
|
||||
// check if index ID already exist
|
||||
|
||||
@@ -641,7 +678,7 @@
|
||||
|
||||
const words = (
|
||||
|
||||
typeof tokenizer === "function" ?
|
||||
is_function(tokenizer) ?
|
||||
|
||||
tokenizer(content)
|
||||
:(
|
||||
@@ -796,7 +833,7 @@
|
||||
|
||||
// update status
|
||||
|
||||
this._ids[id] = "1";
|
||||
this._ids[id] = 1;
|
||||
|
||||
if(SUPPORT_CACHE){
|
||||
|
||||
@@ -821,7 +858,7 @@
|
||||
|
||||
FlexSearch.prototype.update = function(id, content){
|
||||
|
||||
if(this._ids[id] && content && (typeof content === "string")){
|
||||
if(this._ids[id] && is_string(content)){
|
||||
|
||||
if(PROFILER){
|
||||
|
||||
@@ -847,11 +884,11 @@
|
||||
|
||||
FlexSearch.prototype.remove = function(id){
|
||||
|
||||
if(this._ids[id] /*&& !index_blacklist[id]*/){
|
||||
if(this._ids[id]){
|
||||
|
||||
if(SUPPORT_WORKER && this.worker){
|
||||
|
||||
const current_task = parseInt(this._ids[id], 10);
|
||||
const current_task = this._ids[id];
|
||||
|
||||
this._worker[current_task].postMessage(current_task, {
|
||||
|
||||
@@ -919,27 +956,38 @@
|
||||
* @param {!string} query
|
||||
* @param {number|Function=} limit
|
||||
* @param {Function=} callback
|
||||
* @returns {Array|undefined}
|
||||
* @param {boolean=} _recall
|
||||
* @returns {Array|Promise|undefined}
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.prototype.search = function(query, limit, callback){
|
||||
FlexSearch.prototype.search = function(query, limit, callback, _recall){
|
||||
|
||||
let _query = query;
|
||||
let threshold;
|
||||
let result = [];
|
||||
|
||||
if(typeof query === "object"){
|
||||
if(is_object(query)){
|
||||
|
||||
// re-assign properties
|
||||
|
||||
callback = query["callback"] || /** @type {?Function} */ (limit);
|
||||
if(SUPPORT_ASYNC){
|
||||
|
||||
callback = query["callback"] || /** @type {?Function} */ (limit);
|
||||
|
||||
if(callback) {
|
||||
|
||||
_query["callback"] = null;
|
||||
}
|
||||
}
|
||||
|
||||
limit = query["limit"];
|
||||
threshold = query["threshold"];
|
||||
query = query["query"];
|
||||
}
|
||||
|
||||
/*
|
||||
if(!index_blacklist[query]){
|
||||
if(index_blacklist[query]){
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -947,7 +995,7 @@
|
||||
|
||||
threshold || (threshold = this.threshold || 0);
|
||||
|
||||
if(typeof limit === "function"){
|
||||
if(is_function(limit)){
|
||||
|
||||
callback = limit;
|
||||
limit = 1000;
|
||||
@@ -986,31 +1034,42 @@
|
||||
|
||||
queue(function(){
|
||||
|
||||
callback(self.search(query, limit));
|
||||
callback(self.search(_query, limit, null, true));
|
||||
self = null;
|
||||
|
||||
}, 1, "search-" + this.id);
|
||||
}
|
||||
else{
|
||||
|
||||
callback(this.search(query, limit));
|
||||
callback(this.search(_query, limit, null, true));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if(SUPPORT_ASYNC && !_recall && this.async){
|
||||
|
||||
/** @type {FlexSearch} */
|
||||
let self = this;
|
||||
|
||||
return new Promise(function(resolve){
|
||||
|
||||
resolve(self.search(_query, limit, null, true));
|
||||
self = null;
|
||||
});
|
||||
}
|
||||
|
||||
if(PROFILER){
|
||||
|
||||
profile_start("search");
|
||||
}
|
||||
|
||||
if(!query || (typeof query !== "string")){
|
||||
if(!query || !is_string(query)){
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** @type {!string|Array<string>} */
|
||||
let _query = query;
|
||||
(_query = query);
|
||||
|
||||
if(SUPPORT_CACHE && this.cache){
|
||||
|
||||
@@ -1050,7 +1109,7 @@
|
||||
|
||||
const words = (
|
||||
|
||||
typeof tokenizer === "function" ?
|
||||
is_function(tokenizer) ?
|
||||
|
||||
tokenizer(_query)
|
||||
:(
|
||||
@@ -1077,8 +1136,9 @@
|
||||
if(this.depth){
|
||||
|
||||
use_contextual = true;
|
||||
// TODO: alternative roots
|
||||
ctx_root = words[0];
|
||||
check_words[ctx_root] = "1";
|
||||
check_words[ctx_root] = 1;
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -1098,6 +1158,7 @@
|
||||
if(value && !check_words[value]){
|
||||
|
||||
let map;
|
||||
let map_value;
|
||||
let map_found = false;
|
||||
const map_check = [];
|
||||
let count = 0;
|
||||
@@ -1111,25 +1172,16 @@
|
||||
ctx_map[ctx_root]
|
||||
:
|
||||
this._map
|
||||
|
||||
)[z];
|
||||
|
||||
if(map[value]){
|
||||
if((map_value = map[value])){
|
||||
|
||||
map_check[count++] = map[value];
|
||||
map_check[count++] = map_value;
|
||||
map_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!map_found){
|
||||
|
||||
if(!this.suggest){
|
||||
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(map_found){
|
||||
|
||||
// Not handled by intersection:
|
||||
|
||||
@@ -1145,10 +1197,18 @@
|
||||
|
||||
// Handled by intersection:
|
||||
|
||||
// check[check.length] = map_check;
|
||||
//check[check.length] = map_check;
|
||||
}
|
||||
else {
|
||||
|
||||
if(!SUPPORT_SUGGESTIONS || !this.suggest){
|
||||
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
check_words[value] = "1";
|
||||
check_words[value] = 1;
|
||||
}
|
||||
|
||||
ctx_root = value;
|
||||
@@ -1163,7 +1223,7 @@
|
||||
|
||||
// Not handled by intersection:
|
||||
|
||||
result = intersect(check, limit, this.suggest);
|
||||
result = intersect(check, limit, SUPPORT_SUGGESTIONS && this.suggest);
|
||||
|
||||
// Handled by intersection:
|
||||
|
||||
@@ -1332,7 +1392,6 @@
|
||||
* @dict {Function}
|
||||
* @private
|
||||
* @const
|
||||
* @final
|
||||
*/
|
||||
|
||||
const global_encoder = SUPPORT_ENCODER ? {
|
||||
@@ -1538,7 +1597,7 @@
|
||||
//"balance": global_encoder_balance
|
||||
};
|
||||
|
||||
// Xone Async Handler Fallback
|
||||
// Async Handler
|
||||
|
||||
const queue = SUPPORT_ASYNC ? (function(){
|
||||
|
||||
@@ -1569,14 +1628,19 @@
|
||||
|
||||
this.clear();
|
||||
|
||||
/** @private */
|
||||
this.limit = (limit !== true) && limit;
|
||||
}
|
||||
|
||||
Cache.prototype.clear = function(){
|
||||
|
||||
/** @private */
|
||||
this.cache = {};
|
||||
/** @private */
|
||||
this.count = {};
|
||||
/** @private */
|
||||
this.index = {};
|
||||
/** @private */
|
||||
this.ids = [];
|
||||
};
|
||||
|
||||
@@ -1727,13 +1791,12 @@
|
||||
/**
|
||||
* @param {!string} str
|
||||
* @param {RegExp|Array} regex
|
||||
* @param {string=} replacement
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
function replace(str, regex, replacement){
|
||||
function replace(str, regex/*, replacement*/){
|
||||
|
||||
if(typeof replacement === "undefined"){
|
||||
//if(is_undefined(replacement)){
|
||||
|
||||
for(let i = 0; i < /** @type {Array} */ (regex).length; i += 2){
|
||||
|
||||
@@ -1741,11 +1804,11 @@
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
else{
|
||||
|
||||
return str.replace(/** @type {!RegExp} */ (regex), replacement);
|
||||
}
|
||||
// }
|
||||
// else{
|
||||
//
|
||||
// return str.replace(/** @type {!RegExp} */ (regex), replacement || "");
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1829,7 +1892,7 @@
|
||||
|
||||
break;
|
||||
}
|
||||
else if(typeof tmp[a] === "object"){
|
||||
else if(is_object(tmp[a])){
|
||||
|
||||
remove_index(tmp[a], id);
|
||||
}
|
||||
@@ -2142,9 +2205,9 @@
|
||||
// loop through arrays
|
||||
|
||||
let tmp, count = 0;
|
||||
let z = 1;
|
||||
let z = 0; // start from 1
|
||||
|
||||
while(z < length_z){
|
||||
while(++z < length_z){
|
||||
|
||||
// get each array one by one
|
||||
|
||||
@@ -2154,11 +2217,11 @@
|
||||
suggestions = [];
|
||||
arr = arrays[z];
|
||||
length = arr.length;
|
||||
i = -1;
|
||||
i = 0;
|
||||
|
||||
while(i < length){
|
||||
|
||||
tmp = arr[++i];
|
||||
tmp = arr[i++];
|
||||
|
||||
if(check[tmp]){
|
||||
|
||||
@@ -2190,11 +2253,10 @@
|
||||
|
||||
const current_suggestion = (
|
||||
|
||||
suggestions[check_val] ?
|
||||
suggestions[check_val] || (
|
||||
|
||||
suggestions[check_val]
|
||||
:
|
||||
suggestions[check_val] = []
|
||||
)
|
||||
);
|
||||
|
||||
current_suggestion[current_suggestion.length] = tmp;
|
||||
@@ -2206,24 +2268,22 @@
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
z++;
|
||||
}
|
||||
|
||||
if(suggest){
|
||||
|
||||
count = result.length;
|
||||
length = suggestions.length;
|
||||
z = suggestions.length;
|
||||
|
||||
if(length && (!limit || (count < limit))){
|
||||
if(z && (!limit || (count < limit))){
|
||||
|
||||
for(z = length - 1; z >= 0; z--){
|
||||
while(z--){
|
||||
|
||||
tmp = suggestions[z];
|
||||
|
||||
if(tmp){
|
||||
|
||||
for(i = 0; i < tmp.length; i++){
|
||||
for(let i = 0, len = tmp.length; i < len; i++){
|
||||
|
||||
result[count++] = tmp[i];
|
||||
|
||||
@@ -2256,16 +2316,18 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Array<Array<number|string>>} arrays
|
||||
* @param {Array<Array<number|string>>|Array<number|string>} arrays
|
||||
* @param {number=} limit
|
||||
* @param {boolean=} suggest
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
/*
|
||||
function intersect_3d(arrays, limit) {
|
||||
function intersect_3d(arrays, limit, suggest) {
|
||||
|
||||
const result = [];
|
||||
let result = [];
|
||||
const length_z = arrays.length;
|
||||
const check = {};
|
||||
|
||||
if(length_z > 1){
|
||||
|
||||
@@ -2275,43 +2337,38 @@
|
||||
|
||||
const arr_tmp = arrays[0];
|
||||
|
||||
for(const a = 0; a < arr_tmp.length; a++){
|
||||
for(let a = 0, len = arr_tmp.length; a < len; a++){
|
||||
|
||||
// fill initial map
|
||||
|
||||
const check = {};
|
||||
const arr = arr_tmp[a];
|
||||
const length = arr.length;
|
||||
const i = 0;
|
||||
|
||||
while(i < length) {
|
||||
for(let i = 0, length = arr.length; i < length; i++) {
|
||||
|
||||
check[arr[i++]] = 1;
|
||||
check[arr[i]] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// loop through arrays
|
||||
|
||||
const tmp, count = 0;
|
||||
const z = 1;
|
||||
let tmp, count = 0;
|
||||
let z = 1;
|
||||
|
||||
while(z < length_z){
|
||||
|
||||
// get each array one by one
|
||||
|
||||
const found = false;
|
||||
let found = false;
|
||||
|
||||
const arr_tmp = arrays[0];
|
||||
|
||||
for(const a = 0; a < arr_tmp.length; a++){
|
||||
for(let a = 0, len = arr_tmp.length; a < len; a++){
|
||||
|
||||
arr = arr_tmp[a];
|
||||
length = arr.length;
|
||||
i = 0;
|
||||
const arr = arr_tmp[a];
|
||||
|
||||
while(i < length){
|
||||
for(let i = 0, length = arr.length; i < length; i++){
|
||||
|
||||
if((check[tmp = arr[i++]]) === z){
|
||||
if((check[tmp = arr[i]]) === z){
|
||||
|
||||
// fill in during last round
|
||||
|
||||
@@ -2436,6 +2493,16 @@
|
||||
return val.constructor === Array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} val
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
function is_function(val){
|
||||
|
||||
return typeof val === "function";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} val
|
||||
* @returns {boolean}
|
||||
@@ -2443,7 +2510,7 @@
|
||||
|
||||
function is_object(val){
|
||||
|
||||
return val.constructor === Object;
|
||||
return typeof val === "object";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2600,11 +2667,6 @@
|
||||
|
||||
if(data){
|
||||
|
||||
// if(flexsearch.debug){
|
||||
//
|
||||
// console.log("Worker Job Started: " + data["id"]);
|
||||
// }
|
||||
|
||||
if(data["search"]){
|
||||
|
||||
const results = flexsearch["search"](data["content"],
|
||||
@@ -2650,10 +2712,7 @@
|
||||
|
||||
info["worker"] = id;
|
||||
|
||||
if(flexsearch.debug){
|
||||
|
||||
console.log(info);
|
||||
}
|
||||
console.log(info);
|
||||
|
||||
/** @lends {Worker} */
|
||||
//self.postMessage(info);
|
||||
@@ -2690,13 +2749,6 @@
|
||||
|
||||
callback(data["id"], data["content"], data["result"], data["limit"]);
|
||||
}
|
||||
else{
|
||||
|
||||
if(DEBUG && options["debug"]){
|
||||
|
||||
console.log(data);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// cores:
|
||||
@@ -2717,12 +2769,12 @@
|
||||
return thread;
|
||||
}
|
||||
})(
|
||||
// Xone Worker Handler Fallback
|
||||
// Worker Handler
|
||||
|
||||
SUPPORT_WORKER ? (function register_worker(){
|
||||
|
||||
const worker_stack = Object.create(null);
|
||||
const inline_supported = !!((typeof Blob !== "undefined") && (typeof URL !== "undefined") && URL.createObjectURL);
|
||||
const inline_supported = (typeof Blob !== "undefined") && (typeof URL !== "undefined") && URL.createObjectURL;
|
||||
|
||||
return (
|
||||
|
||||
@@ -2766,7 +2818,7 @@
|
||||
:
|
||||
// Load Extern Worker (but also requires CORS)
|
||||
|
||||
"../" + name + "." + RELEASE + ".js"
|
||||
"../" + name + (RELEASE ? "." + RELEASE : "") + ".js"
|
||||
);
|
||||
|
||||
name += "-" + _id;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
FlexSearch v0.3.0
|
||||
FlexSearch v0.3.1
|
||||
Copyright 2019 Nextapps GmbH
|
||||
Author: Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(h,w,u){var r;(r=u.define)&&r.amd?r([],function(){return w}):(r=u.modules)?r[h.toLowerCase()]=w:"object"===typeof exports?module.exports=w:u[h]=w})("FlexSearch",function(){function h(a){a||(a=x);this.id=a.id||F++;this.init(a);w(this,"index",function(){return this.a});w(this,"length",function(){return Object.keys(this.a).length})}function w(a,b,c){Object.defineProperty(a,b,{get:c})}function u(a,b,c){if("undefined"===typeof c){for(c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}return a.replace(b,
|
||||
c)}function r(a,b,c,e,f,v,d){if(b[c])return b[c];f=f?(9-(d||6))*v+(d||6)*f:v;b[c]=f;f>=d&&(a=a[f+.5>>0],a=a[c]||(a[c]=[]),a[a.length]=e);return f}function z(a,b){if(a)for(var c=Object.keys(a),e=0,f=c.length;e<f;e++){var v=c[e],d=a[v];if(d)for(var k=0,n=d.length;k<n;k++)if(d[k]===b){1===n?delete a[v]:d.splice(k,1);break}else"object"===typeof d[k]&&z(d[k],b)}}function G(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function H(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function B(a){for(var b=Array(a),
|
||||
c=0;c<a;c++)b[c]={};return b}var x={encode:"icase",mode:"forward",f:!1,cache:!1,async:!1,i:!1,threshold:0,depth:0},A=[],F=0,C=/[ -/]/g,D={},E={};h.create=function(a){return new this(a)};h.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&A.push(new RegExp(b,"g"),a[b]);return this};h.registerEncoder=function(a,b){y[a]=b.bind(y);return this};h.registerLanguage=function(a,b){D[a]=b.filter;E[a]=b.stemmer;return this};h.encode=function(a,b){return y[a](b)};h.prototype.init=function(a){this.h=
|
||||
[];a||(a=x);var b={};this.mode=a.mode||b.mode||this.mode||x.mode;this.threshold=a.threshold||b.threshold||this.threshold||x.threshold;this.depth=a.depth||b.depth||this.depth||x.depth;this.f=a.suggest||this.f||x.f;this.c=(b=a.encode||b.encode)&&y[b]&&y[b].bind(y)||("function"===typeof b?b:this.c||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=D[b]||b;var c=this.c,e={};if(b)for(var f=0;f<b.length;f++){var v=c?c(b[f]):b[f];e[v]=String.fromCharCode(65E3-b.length+f)}this.filter=e}if(b=a.stemmer){a=
|
||||
E[b]||b;b=this.c;c=[];if(a)for(var d in a)a.hasOwnProperty(d)&&(e=b?b(d):d,c.push(new RegExp("(?=.{"+(e.length+3)+",})"+e+"$","g"),b?b(a[d]):a[d]));this.stemmer=c}this.g=B(10);this.b={};this.a={};return this};h.prototype.encode=function(a){a&&A.length&&(a=u(a,A));a&&this.h.length&&(a=u(a,this.h));a&&this.c&&(a=this.c(a));a&&this.stemmer&&(a=u(a,this.stemmer));return a};h.prototype.addMatcher=function(a){var b=this.h,c;for(c in a)a.hasOwnProperty(c)&&b.push(new RegExp(c,"g"),a[c]);return this};h.prototype.add=
|
||||
function(a,b,c){if(b&&"string"===typeof b&&(a||0===a))if(this.a[a]&&!c)this.update(a,b);else{b=this.encode(b);if(!b.length)return this;c=this.mode;b="function"===typeof c?c(b):b.split(C);for(var e={_ctx:{}},f=this.threshold,v=this.depth,d=this.g,k=b.length,n=0;n<k;n++){var m=b[n];if(m){var q=m.length,l=(k-n)/k,g="";switch(c){case "reverse":case "both":for(var p=q-1;1<=p;p--)g=m[p]+g,r(d,e,g,a,(q-p)/q,l,f);g="";case "forward":for(p=0;p<q;p++)g+=m[p],r(d,e,g,a,1,l,f);break;case "full":for(p=0;p<q;p++)for(var h=
|
||||
(q-p)/q,t=q;t>p;t--)g=m.substring(p,t),r(d,e,g,a,h,l,f);break;default:if(q=r(d,e,m,a,1,l,f),v&&1<k&&q>=f)for(q=e._ctx[m]||(e._ctx[m]={}),m=this.b[m]||(this.b[m]=B(10)),l=n-v,g=n+v+1,0>l&&(l=0),g>k&&(g=k);l<g;l++)l!==n&&r(m,q,b[l],a,0,10-(l<n?n-l:l-n),f)}}}this.a[a]="1"}return this};h.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};h.prototype.remove=function(a){if(this.a[a]){for(var b=0;10>b;b++)z(this.g[b],a);this.depth&&z(this.b,a);
|
||||
delete this.a[a]}return this};h.prototype.search=function(a,b,c){var e=[];if("object"===typeof a){c=a.callback||b;b=a.limit;var f=a.threshold;a=a.query}f||(f=this.threshold||0);"function"===typeof b?(c=b,b=1E3):b||0===b||(b=1E3);if(c)c(this.search(a,b));else{if(!a||"string"!==typeof a)return e;a=this.encode(a);if(!a.length)return e;c=this.mode;c="function"===typeof c?c(a):a.split(C);var h=c.length,d=!0;a=[];var k={};if(1<h)if(this.depth){var n=!0;var m=c[0];k[m]="1"}else c.sort(G);var q;if(!n||(q=
|
||||
this.b)[m])for(var l=n?1:0;l<h;l++){var g=c[l];if(g&&!k[g]){for(var p,r=!1,t=[],w=0,u=9;u>=f;u--)p=(n?q[m]:this.g)[u],p[g]&&(t[w++]=p[g],r=!0);if(r)a[a.length]=1<w?a.concat.apply([],t):t[0];else if(!this.f){d=!1;break}k[g]="1"}m=g}else d=!1;if(d)a:if(f=this.f,e=[],m=[],n=a.length,1<n){a.sort(H);q={};c=a[0];h=c.length;for(d=0;d<h;)q[c[d++]]=1;l=0;for(g=1;g<n;){p=!1;r=g===n-1;m=[];c=a[g];h=c.length;for(d=-1;d<h;)if(k=c[++d],q[k])if(t=q[k],t===g){if(r){if(e[l++]=k,b&&l===b)break a}else q[k]=g+1;p=!0}else f&&
|
||||
(t=m[t]?m[t]:m[t]=[],t[t.length]=k);if(!p&&!f)break;g++}if(f&&(l=e.length,(h=m.length)&&(!b||l<b)))for(g=h-1;0<=g;g--)if(k=m[g])for(d=0;d<k.length;d++)if(e[l++]=k[d],b&&l===b)break a}else n&&(e=a[0],b&&e.length>b&&(e=e.slice(0,b)));return e}};h.prototype.clear=function(){this.destroy();return this.init()};h.prototype.destroy=function(){this.filter=this.stemmer=this.g=this.b=this.a=null;return this};var y={icase:function(a){return a.toLowerCase()}};return h}(!1),this);
|
||||
'use strict';(function(d,t,q){var r;(r=q.define)&&r.amd?r([],function(){return t}):(r=q.modules)?r[d.toLowerCase()]=t:"object"===typeof exports?module.exports=t:q[d]=t})("FlexSearch",function(){function d(a){a||(a=v);this.id=a.id||G++;this.init(a);t(this,"index",function(){return this.a});t(this,"length",function(){return Object.keys(this.a).length})}function t(a,b,c){Object.defineProperty(a,b,{get:c})}function q(a,b){for(var c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}function r(a,b,c,
|
||||
e,f,u,g){if(b[c])return b[c];f=f?(9-(g||6))*u+(g||6)*f:u;b[c]=f;f>=g&&(a=a[f+.5>>0],a=a[c]||(a[c]=[]),a[a.length]=e);return f}function y(a,b){if(a)for(var c=Object.keys(a),e=0,f=c.length;e<f;e++){var u=c[e],g=a[u];if(g)for(var h=0,k=g.length;h<k;h++)if(g[h]===b){1===k?delete a[u]:g.splice(h,1);break}else"object"===typeof g[h]&&y(g[h],b)}}function H(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function I(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function x(a){return"function"===typeof a}function z(a){return"undefined"===
|
||||
typeof a}function B(a){for(var b=Array(a),c=0;c<a;c++)b[c]={};return b}var v={encode:"icase",mode:"forward",h:!1,cache:!1,async:!1,i:!1,threshold:0,depth:0},A=[],G=0,C=/[ -/]/g,D={},E={},F=function(){for(var a=Object.getOwnPropertyNames({}.__proto__),b={},c=0;c<a.length;c++)b[a[c]]=1;return b}();d.create=function(a){return new d(a)};d.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&A.push(new RegExp(b,"g"),a[b]);return this};d.registerEncoder=function(a,b){w[a]=b.bind(w);return this};
|
||||
d.registerLanguage=function(a,b){D[a]=b.filter;E[a]=b.stemmer;return this};d.encode=function(a,b){return F[a]?b:w[a](b)};d.prototype.init=function(a){this.g=[];a||(a=v);var b=a.profile,c={};this.mode=a.mode||c.mode||this.mode||v.mode;this.threshold=z(b=a.threshold)?c.threshold||this.threshold||v.threshold:b;this.depth=z(b=a.depth)?c.depth||this.depth||v.depth:b;this.c=(b=z(b=a.encode)?c.encode:b)&&w[b]&&w[b].bind(w)||(x(b)?b:this.c||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=D[b]||b;c=
|
||||
this.c;var e={};if(b)for(var f=0;f<b.length;f++){var u=c?c(b[f]):b[f];e[u]=String.fromCharCode(65E3-b.length+f)}this.filter=e}if(b=a.stemmer){a=E[b]||b;b=this.c;c=[];if(a)for(var g in a)a.hasOwnProperty(g)&&(e=b?b(g):g,c.push(new RegExp("(?=.{"+(e.length+3)+",})"+e+"$","g"),b?b(a[g]):a[g]));this.stemmer=c}this.f=B(10);this.b={};this.a={};return this};d.prototype.encode=function(a){a&&A.length&&(a=q(a,A));a&&this.g.length&&(a=q(a,this.g));a&&this.c&&(a=this.c(a));a&&this.stemmer&&(a=q(a,this.stemmer));
|
||||
return a};d.prototype.addMatcher=function(a){var b=this.g,c;for(c in a)a.hasOwnProperty(c)&&b.push(new RegExp(c,"g"),a[c]);return this};d.prototype.add=function(a,b,c){if(b&&"string"===typeof b&&(a&&!F[a]||0===a))if(this.a[a]&&!c)this.update(a,b);else{b=this.encode(b);if(!b.length)return this;c=this.mode;b=x(c)?c(b):b.split(C);for(var e={_ctx:{}},f=this.threshold,u=this.depth,g=this.f,h=b.length,k=0;k<h;k++){var l=b[k];if(l){var d=l.length,m=(h-k)/h,n="";switch(c){case "reverse":case "both":for(var p=
|
||||
d-1;1<=p;p--)n=l[p]+n,r(g,e,n,a,(d-p)/d,m,f);n="";case "forward":for(p=0;p<d;p++)n+=l[p],r(g,e,n,a,1,m,f);break;case "full":for(p=0;p<d;p++)for(var t=(d-p)/d,q=d;q>p;q--)n=l.substring(p,q),r(g,e,n,a,t,m,f);break;default:if(d=r(g,e,l,a,1,m,f),u&&1<h&&d>=f)for(d=e._ctx[l]||(e._ctx[l]={}),l=this.b[l]||(this.b[l]=B(10)),m=k-u,n=k+u+1,0>m&&(m=0),n>h&&(n=h);m<n;m++)m!==k&&r(l,d,b[m],a,0,10-(m<k?k-m:m-k),f)}}}this.a[a]=1}return this};d.prototype.update=function(a,b){this.a[a]&&"string"===typeof b&&(this.remove(a),
|
||||
this.add(a,b,!0));return this};d.prototype.remove=function(a){if(this.a[a]){for(var b=0;10>b;b++)y(this.f[b],a);this.depth&&y(this.b,a);delete this.a[a]}return this};d.prototype.search=function(a,b,c){var e=a,f=[];if("object"===typeof a){b=a.limit;var d=a.threshold;a=a.query}d||(d=this.threshold||0);x(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(c)c(this.search(e,b,null,!0));else{if(!a||"string"!==typeof a)return f;e=this.encode(a);if(!e.length)return f;a=this.mode;a=x(a)?a(e):e.split(C);c=a.length;var g=
|
||||
!0;e=[];var h={};if(1<c)if(this.depth){var k=!0;var l=a[0];h[l]=1}else a.sort(H);var q;if(!k||(q=this.b)[l])for(var m=k?1:0;m<c;m++){var n=a[m];if(n&&!h[n]){for(var p,r=!1,t=[],w=0,v=9;v>=d;v--)if(p=(k?q[l]:this.f)[v],p=p[n])t[w++]=p,r=!0;if(r)e[e.length]=1<w?e.concat.apply([],t):t[0];else{g=!1;break}h[n]=1}l=n}else g=!1;if(g)a:{d=[];f=e.length;if(1<f){e.sort(I);l={};k=e[0];q=k.length;for(a=0;a<q;)l[k[a++]]=1;for(h=g=0;++h<f;){m=!1;n=h===f-1;k=e[h];q=k.length;for(a=0;a<q;)if(c=k[a++],l[c]&&l[c]===
|
||||
h){if(n){if(d[g++]=c,b&&g===b){f=d;break a}}else l[c]=h+1;m=!0}if(!m)break}}else f&&(d=e[0],b&&d.length>b&&(d=d.slice(0,b)));f=d}return f}};d.prototype.clear=function(){this.destroy();return this.init()};d.prototype.destroy=function(){this.filter=this.stemmer=this.f=this.b=this.a=null;return this};var w={icase:function(a){return a.toLowerCase()}};return d}(!1),this);
|
||||
|
53
flexsearch.min.js
vendored
53
flexsearch.min.js
vendored
@@ -1,29 +1,36 @@
|
||||
/*
|
||||
FlexSearch v0.3.0
|
||||
FlexSearch v0.3.1
|
||||
Copyright 2019 Nextapps GmbH
|
||||
Author: Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(v,B,f){var w;(w=f.define)&&w.amd?w([],function(){return B}):(w=f.modules)?w[v.toLowerCase()]=B:"object"===typeof exports?module.exports=B:f[v]=B})("FlexSearch",function O(v){function f(a){"string"===typeof a&&(a=H[a]);a||(a=y);this.id=a.id||P++;this.init(a);w(this,"index",function(){return this.a});w(this,"length",function(){return Object.keys(this.a).length})}function w(a,b,e){Object.defineProperty(a,b,{get:e})}function d(a){return new RegExp(a,"g")}function x(a,b,e){if("undefined"===
|
||||
typeof e){for(e=0;e<b.length;e+=2)a=a.replace(b[e],b[e+1]);return a}return a.replace(b,e)}function z(a,b,e,c,k,u,g){if(b[e])return b[e];k=k?(9-(g||6))*u+(g||6)*k:u;b[e]=k;k>=g&&(a=a[k+.5>>0],a=a[e]||(a[e]=[]),a[a.length]=c);return k}function q(a,b){if(a)for(var e=Object.keys(a),c=0,k=e.length;c<k;c++){var u=e[c],g=a[u];if(g)for(var h=0,d=g.length;h<d;h++)if(g[h]===b){1===d?delete a[u]:g.splice(h,1);break}else"object"===typeof g[h]&&q(g[h],b)}}function I(a){var b=[];if(!a)return b;for(var e=0,c=0,
|
||||
k=0,u="",g=a.length,h=0;h<g;h++){var d=a[h];"a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d?e++:c++;" "!==d&&(u+=d);if(" "===d||e>=(8<g?2:1)&&2<=c||2<=e&&c>=(8<g?2:1)||h===g-1)u&&(b[k]&&2<u.length&&k++,b[k]=b[k]?b[k]+u:u," "===d&&k++,u=""),c=e=0}return b}function E(a){for(var b="",e="",c="",k=0;k<a.length;k++){var d=a[k];if(d!==e)if(k&&"h"===d){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e)&&c||" "===e)b+=d}else b+=d;c=k===a.length-
|
||||
1?"":a[k+1];e=d}return b}function Q(a,b){var e={};if(a)for(var c=0;c<a.length;c++){var k=b?b(a[c]):a[c];e[k]=String.fromCharCode(65E3-a.length+c)}return e}function R(a,b){var e=[];if(a)for(var c in a)if(a.hasOwnProperty(c)){var k=b?b(c):c;e.push(d("(?=.{"+(k.length+3)+",})"+k+"$"),b?b(a[c]):a[c])}return e}function S(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function T(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function U(a,b,e){var c=[],k=[],d=a.length;if(1<d){a.sort(T);for(var g={},h=a[0],C=
|
||||
h.length,m=0;m<C;)g[h[m++]]=1;for(var n,p=0,l=1;l<d;){var f=!1,q=l===d-1;k=[];h=a[l];C=h.length;for(m=-1;m<C;)if(n=h[++m],g[n]){var r=g[n];if(r===l){if(q){if(c[p++]=n,b&&p===b)return c}else g[n]=l+1;f=!0}else e&&(r=k[r]?k[r]:k[r]=[],r[r.length]=n)}if(!f&&!e)break;l++}if(e&&(p=c.length,(C=k.length)&&(!b||p<b)))for(l=C-1;0<=l;l--)if(n=k[l])for(m=0;m<n.length;m++)if(c[p++]=n[m],b&&p===b)return c}else d&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function F(a){a.C||(a.C=J(function(){a.C=0;var b=
|
||||
a.async;b&&(a.async=!1);if(a.c.length){for(var e=Date.now(),c;(c=a.c.shift())||0===c;){var d=a.f[c];switch(d[0]){case D.add:a.add(d[1],d[2]);break;case D.remove:a.remove(d[1])}delete a.f[c];if(100<Date.now()-e)break}a.c.length&&F(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function K(a){for(var b=Array(a),e=0;e<a;e++)b[e]={};return b}function V(a,b,e,c){a=v("flexsearch","id"+a,function(){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}: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.register&&(a=c.id,c.options.cache=!1,c.options.async=!0,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}},function(a){(a=a.data)&&a.result&&c(a.id,a.content,a.result,a.limit)},b);var d=O.toString();e.id=b;
|
||||
a.postMessage(b,{register:d,options:e,id:b});return a}var y={encode:"icase",mode:"forward",s:!1,cache:!1,async:!1,b:!1,threshold:0,depth:0},H={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"strict",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},G=[],P=0,D={add:0,update:1,remove:2},L=
|
||||
d("[ -/]"),M={},N={};f.create=function(a){return new this(a)};f.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&G.push(d(b),a[b]);return this};f.registerEncoder=function(a,b){A[a]=b.bind(A);return this};f.registerLanguage=function(a,b){M[a]=b.filter;N[a]=b.stemmer;return this};f.encode=function(a,b){return A[a](b)};f.prototype.init=function(a){this.B=[];a||(a=y);var b=a.profile,e=b?H[b]:{};if(b=a.worker)if(Worker){var c=this;b=parseInt(b,10)||4;c.l=-1;c.m=0;c.g=[];c.A=null;c.i=Array(b);
|
||||
for(var d=0;d<b;d++)c.i[d]=V(c.id,d,a,function(a,b,e,d){if(c.m!==c.b)return c.g=c.g.concat(e),c.m++,d&&c.g.length>=d&&(c.m=c.b),c.A&&c.m===c.b&&(c.cache&&c.h.set(b,c.g),c.A(c.g),c.g=[]),c})}else a.worker=!1,this.i=null;this.mode=a.mode||e.mode||this.mode||y.mode;this.async=a.async||this.async||y.async;this.b=a.worker||this.b||y.b;this.threshold=a.threshold||e.threshold||this.threshold||y.threshold;this.depth=a.depth||e.depth||this.depth||y.depth;this.s=a.suggest||this.s||y.s;this.o=(b=a.encode||e.encode)&&
|
||||
A[b]&&A[b].bind(A)||("function"===typeof b?b:this.o||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=Q(M[b]||b,this.o);if(b=a.stemmer)this.stemmer=R(N[b]||b,this.o);this.v=K(10);this.j={};this.a={};this.f={};this.c=[];this.C=0;this.u=!0;this.h=(this.cache=b=a.cache||this.cache||y.cache)?new W(b):!1;return this};f.prototype.encode=function(a){a&&G.length&&(a=x(a,G));a&&this.B.length&&(a=x(a,this.B));a&&this.o&&(a=this.o(a));a&&this.stemmer&&(a=x(a,this.stemmer));return a};f.prototype.addMatcher=
|
||||
function(a){var b=this.B,e;for(e in a)a.hasOwnProperty(e)&&b.push(d(e),a[e]);return this};f.prototype.add=function(a,b,e){if(b&&"string"===typeof b&&(a||0===a))if(this.a[a]&&!e)this.update(a,b);else{if(this.b)return++this.l>=this.i.length&&(this.l=0),this.i[this.l].postMessage(this.l,{add:!0,id:a,content:b}),this.a[a]=""+this.l,this;if(this.async)return this.f[a]||(this.c[this.c.length]=a),this.f[a]=[D.add,a,b],F(this),this;b=this.encode(b);if(!b.length)return this;e=this.mode;b="function"===typeof e?
|
||||
e(b):"ngram"===e?I(b):b.split(L);for(var c={_ctx:{}},d=this.threshold,u=this.depth,g=this.v,h=b.length,f=0;f<h;f++){var m=b[f];if(m){var n=m.length,p=(h-f)/h,l="";switch(e){case "reverse":case "both":for(var t=n-1;1<=t;t--)l=m[t]+l,z(g,c,l,a,(n-t)/n,p,d);l="";case "forward":for(t=0;t<n;t++)l+=m[t],z(g,c,l,a,1,p,d);break;case "full":for(t=0;t<n;t++)for(var q=(n-t)/n,r=n;r>t;r--)l=m.substring(t,r),z(g,c,l,a,q,p,d);break;default:if(n=z(g,c,m,a,1,p,d),u&&1<h&&n>=d)for(n=c._ctx[m]||(c._ctx[m]={}),m=this.j[m]||
|
||||
(this.j[m]=K(10)),p=f-u,l=f+u+1,0>p&&(p=0),l>h&&(l=h);p<l;p++)p!==f&&z(m,n,b[p],a,0,10-(p<f?f-p:p-f),d)}}}this.a[a]="1";this.u=!1}return this};f.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};f.prototype.remove=function(a){if(this.a[a]){if(this.b){var b=parseInt(this.a[a],10);this.i[b].postMessage(b,{remove:!0,id:a});delete this.a[a];return this}if(this.async)return this.f[a]||(this.c[this.c.length]=a),this.f[a]=[D.remove,a],F(this),
|
||||
this;for(b=0;10>b;b++)q(this.v[b],a);this.depth&&q(this.j,a);delete this.a[a];this.u=!1}return this};f.prototype.search=function(a,b,e){var c=[];if("object"===typeof a){e=a.callback||b;b=a.limit;var d=a.threshold;a=a.query}d||(d=this.threshold||0);"function"===typeof b?(e=b,b=1E3):b||0===b||(b=1E3);if(this.b)for(this.A=e,this.m=0,this.g=[],c=0;c<this.b;c++)this.i[c].postMessage(c,{search:!0,limit:b,threshold:d,content:a});else if(e){var f=this;J(function(){e(f.search(a,b));f=null},1,"search-"+this.id)}else{if(!a||
|
||||
"string"!==typeof a)return c;var g=a;if(this.cache)if(this.u){var h=this.h.get(a);if(h)return h}else this.h.clear(),this.u=!0;g=this.encode(g);if(!g.length)return c;h=this.mode;g="function"===typeof h?h(g):"ngram"===h?I(g):g.split(L);h=g.length;var q=!0,m=[],n={};if(1<h)if(this.depth){var p=!0;var l=g[0];n[l]="1"}else g.sort(S);var t;if(!p||(t=this.j)[l])for(var v=p?1:0;v<h;v++){var r=g[v];if(r&&!n[r]){for(var w=void 0,y=!1,x=[],z=0,A=9;A>=d;A--)w=(p?t[l]:this.v)[A],w[r]&&(x[z++]=w[r],y=!0);if(y)m[m.length]=
|
||||
1<z?m.concat.apply([],x):x[0];else if(!this.s){q=!1;break}n[r]="1"}l=r}else q=!1;q&&(c=U(m,b,this.s));this.cache&&this.h.set(a,c);return c}};f.prototype.clear=function(){this.destroy();return this.init()};f.prototype.destroy=function(){this.cache&&(this.h.clear(),this.h=null);this.filter=this.stemmer=this.v=this.j=this.a=this.f=this.c=null;return this};var A={icase:function(a){return a.toLowerCase()},simple:function(){var a=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),
|
||||
"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," "];return function(b){b=x(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){var a=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",
|
||||
d("cc"),"k",d("dt"),"t",d("ph"),"f",d("pf"),"f",d("ou"),"o",d("uo"),"u"];return function(b,d){if(!b)return b;b=this.simple(b);2<b.length&&(b=x(b,a));d||1<b.length&&(b=E(b));return b}}(),extra:function(){var a=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var d=0;d<b.length;d++){var c=b[d];1<c.length&&(b[d]=c[0]+x(c.substring(1),a))}b=b.join(" ");b=E(b)}return b}}(),
|
||||
balance:function(){var a=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," "];return function(b){return E(x(b.toLowerCase(),a))}}()},J=function(){var a={};return function(b,d,c){var e=a[c];e&&clearTimeout(e);return a[c]=setTimeout(b,d)}}(),W=function(){function a(a){this.clear();this.w=!0!==a&&a}a.prototype.clear=function(){this.cache={};this.count={};this.index={};this.a=[]};a.prototype.set=function(a,d){if(this.w&&"undefined"===typeof this.cache[a]){var b=this.a.length;if(b===this.w){b--;var e=this.a[b];
|
||||
delete this.cache[e];delete this.count[e];delete this.index[e]}this.index[a]=b;this.a[b]=a;this.count[a]=-1;this.cache[a]=d;this.get(a)}else this.cache[a]=d};a.prototype.get=function(a){var b=this.cache[a];if(this.w&&b){var c=++this.count[a],d=this.index,f=d[a];if(0<f){for(var g=this.a,h=f;this.count[g[--f]]<=c&&-1!==f;);f++;if(f!==h){for(c=h;c>f;c--)h=g[c-1],g[c]=h,d[h]=c;g[f]=a;d[a]=f}}}return b};return a}();return f}(function(){var v=Object.create(null),B=!("undefined"===typeof Blob||"undefined"===
|
||||
typeof URL||!URL.createObjectURL);return function(f,w,d,x,z){var q=f;f=B?URL.createObjectURL(new Blob(["("+d.toString()+")()"],{type:"text/javascript"})):"../"+q+".min.js";q+="-"+w;v[q]||(v[q]=[]);v[q][z]=new Worker(f);v[q][z].onmessage=x;return{postMessage:function(d,f){v[q][d].postMessage(f)}}}}()),this);
|
||||
'use strict';function J(g){var h=0;return function(){return h<g.length?{done:!1,value:g[h++]}:{done:!0}}}function K(g){var h="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return h?h.call(g):{next:J(g)}}var S="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,T="function"==typeof Object.defineProperties?Object.defineProperty:function(g,h,e){g!=Array.prototype&&g!=Object.prototype&&(g[h]=e.value)};
|
||||
function U(g,h){if(h){var e=S;g=g.split(".");for(var k=0;k<g.length-1;k++){var a=g[k];a in e||(e[a]={});e=e[a]}g=g[g.length-1];k=e[g];h=h(k);h!=k&&null!=h&&T(e,g,{configurable:!0,writable:!0,value:h})}}
|
||||
U("Promise",function(g){function h(d){this.b=0;this.g=void 0;this.a=[];var a=this.c();try{d(a.resolve,a.reject)}catch(D){a.reject(D)}}function e(){this.a=null}function k(d){return d instanceof h?d:new h(function(a){a(d)})}if(g)return g;e.prototype.b=function(d){if(null==this.a){this.a=[];var a=this;this.c(function(){a.g()})}this.a.push(d)};var a=S.setTimeout;e.prototype.c=function(d){a(d,0)};e.prototype.g=function(){for(;this.a&&this.a.length;){var d=this.a;this.a=[];for(var a=0;a<d.length;++a){var h=
|
||||
d[a];d[a]=null;try{h()}catch(v){this.f(v)}}}this.a=null};e.prototype.f=function(d){this.c(function(){throw d;})};h.prototype.c=function(){function d(d){return function(e){h||(h=!0,d.call(a,e))}}var a=this,h=!1;return{resolve:d(this.o),reject:d(this.f)}};h.prototype.o=function(d){if(d===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(d instanceof h)this.s(d);else{a:switch(typeof d){case "object":var a=null!=d;break a;case "function":a=!0;break a;default:a=!1}a?this.m(d):this.i(d)}};
|
||||
h.prototype.m=function(a){var d=void 0;try{d=a.then}catch(D){this.f(D);return}"function"==typeof d?this.u(d,a):this.i(a)};h.prototype.f=function(a){this.j(2,a)};h.prototype.i=function(a){this.j(1,a)};h.prototype.j=function(a,h){if(0!=this.b)throw Error("Cannot settle("+a+", "+h+"): Promise already settled in state"+this.b);this.b=a;this.g=h;this.l()};h.prototype.l=function(){if(null!=this.a){for(var a=0;a<this.a.length;++a)l.b(this.a[a]);this.a=null}};var l=new e;h.prototype.s=function(a){var d=this.c();
|
||||
a.w(d.resolve,d.reject)};h.prototype.u=function(a,h){var d=this.c();try{a.call(h,d.resolve,d.reject)}catch(v){d.reject(v)}};h.prototype.then=function(a,e){function d(a,d){return"function"==typeof a?function(d){try{g(a(d))}catch(E){k(E)}}:d}var g,k,m=new h(function(a,d){g=a;k=d});this.w(d(a,g),d(e,k));return m};h.prototype.catch=function(a){return this.then(void 0,a)};h.prototype.w=function(a,h){function d(){switch(e.b){case 1:a(e.g);break;case 2:h(e.g);break;default:throw Error("Unexpected state: "+
|
||||
e.b);}}var e=this;null==this.a?l.b(d):this.a.push(d)};h.resolve=k;h.reject=function(a){return new h(function(d,h){h(a)})};h.race=function(a){return new h(function(d,h){for(var e=K(a),g=e.next();!g.done;g=e.next())k(g.value).w(d,h)})};h.all=function(a){var d=K(a),e=d.next();return e.done?k([]):new h(function(a,h){function g(d){return function(h){m[d]=h;l--;0==l&&a(m)}}var m=[],l=0;do m.push(void 0),l++,k(e.value).w(g(m.length-1),h),e=d.next();while(!e.done)})};return h});
|
||||
(function(g,h,e){var k;(k=e.define)&&k.amd?k([],function(){return h}):(k=e.modules)?k[g.toLowerCase()]=h:"object"===typeof exports?module.exports=h:e[g]=h})("FlexSearch",function aa(g){function e(b){E(b)&&(b=L[b]);b||(b=w);this.id=b.id||ba++;this.init(b);k(this,"index",function(){return this.a});k(this,"length",function(){return Object.keys(this.a).length})}function k(b,c,a){Object.defineProperty(b,c,{get:a})}function a(b){return new RegExp(b,"g")}function l(b,c){for(var a=0;a<c.length;a+=2)b=b.replace(c[a],
|
||||
c[a+1]);return b}function d(b,c,a,f,A,d,e){if(c[a])return c[a];A=A?(9-(e||6))*d+(e||6)*A:d;c[a]=A;A>=e&&(b=b[A+.5>>0],b=b[a]||(b[a]=[]),b[b.length]=f);return A}function m(b,c){if(b)for(var a=Object.keys(b),f=0,A=a.length;f<A;f++){var d=a[f],e=b[d];if(e)for(var r=0,g=e.length;r<g;r++)if(e[r]===c){1===g?delete b[d]:e.splice(r,1);break}else"object"===typeof e[r]&&m(e[r],c)}}function D(b){var c=[];if(!b)return c;for(var a=0,f=0,d=0,e="",g=b.length,r=0;r<g;r++){var z=b[r];"a"===z||"e"===z||"i"===z||"o"===
|
||||
z||"u"===z||"y"===z?a++:f++;" "!==z&&(e+=z);if(" "===z||a>=(8<g?2:1)&&2<=f||2<=a&&f>=(8<g?2:1)||r===g-1)e&&(c[d]&&2<e.length&&d++,c[d]=c[d]?c[d]+e:e," "===z&&d++,e=""),f=a=0}return c}function v(b){for(var c="",a="",f="",d=0;d<b.length;d++){var e=b[d];if(e!==a)if(d&&"h"===e){if(f="a"===f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f,("a"===a||"e"===a||"i"===a||"o"===a||"u"===a||"y"===a)&&f||" "===a)c+=e}else c+=e;f=d===b.length-1?"":b[d+1];a=e}return c}function V(b,c){var a={};if(b)for(var f=0;f<b.length;f++){var d=
|
||||
c?c(b[f]):b[f];a[d]=String.fromCharCode(65E3-b.length+f)}return a}function Z(b,c){var d=[];if(b)for(var f in b)if(b.hasOwnProperty(f)){var e=c?c(f):f;d.push(a("(?=.{"+(e.length+3)+",})"+e+"$"),c?c(b[f]):b[f])}return d}function W(b,c){b=b.length-c.length;return 0>b?1:b?-1:0}function X(b,c){b=b.length-c.length;return 0>b?-1:b?1:0}function Y(b,c,a){var f=[],d=[],e=b.length;if(1<e){b.sort(X);for(var g={},r=b[0],t=r.length,k=0;k<t;)g[r[k++]]=1;for(var n,p=0,q=0;++q<e;){var u=!1,m=q===e-1;d=[];r=b[q];t=
|
||||
r.length;for(k=0;k<t;)if(n=r[k++],g[n]){var l=g[n];if(l===q){if(m){if(f[p++]=n,c&&p===c)return f}else g[n]=q+1;u=!0}else a&&(l=d[l]||(d[l]=[]),l[l.length]=n)}if(!u&&!a)break}if(a&&(p=f.length,(q=d.length)&&(!c||p<c)))for(;q--;)if(n=d[q])for(b=0,a=n.length;b<a;b++)if(f[p++]=n[b],c&&p===c)return f}else e&&(f=b[0],c&&f.length>c&&(f=f.slice(0,c)));return f}function E(b){return"string"===typeof b}function H(b){return"function"===typeof b}function x(b){return"undefined"===typeof b}function B(b){b.D||(b.D=
|
||||
M(function(){b.D=0;var c=b.async;c&&(b.async=!1);if(b.b.length){for(var a=Date.now(),f;(f=b.b.shift())||0===f;){var d=b.c[f];switch(d[0]){case C.add:b.add(d[1],d[2]);break;case C.remove:b.remove(d[1])}delete b.c[f];if(100<Date.now()-a)break}b.b.length&&B(b)}c&&(b.async=c)},1,"search-async-"+b.id))}function N(b){for(var c=Array(b),a=0;a<b;a++)c[a]={};return c}function ca(b,c,a,f){b=g("flexsearch","id"+b,function(){var b,c;self.onmessage=function(a){if(a=a.data)if(a.search){var f=c.search(a.content,
|
||||
a.threshold?{limit:a.limit,threshold:a.threshold}:a.limit);self.postMessage({id:b,content:a.content,limit:a.limit,result:f})}else a.add?c.add(a.id,a.content):a.update?c.update(a.id,a.content):a.remove?c.remove(a.id):a.clear?c.clear():a.register&&(b=a.id,a.options.cache=!1,a.options.async=!0,a.options.worker=!1,c=(new Function(a.register.substring(a.register.indexOf("{")+1,a.register.lastIndexOf("}"))))(),c=new c(a.options))}},function(b){(b=b.data)&&b.result&&f(b.id,b.content,b.result,b.limit)},c);
|
||||
var d=aa.toString();a.id=c;b.postMessage(c,{register:d,options:a,id:c});return b}var w={encode:"icase",mode:"forward",v:!1,cache:!1,async:!1,h:!1,threshold:0,depth:0},L={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"strict",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},F=[],ba=0,C=
|
||||
{add:0,update:1,remove:2},O=a("[ -/]"),P={},Q={},R=function(){for(var b=Object.getOwnPropertyNames({}.__proto__),c={},a=0;a<b.length;a++)c[b[a]]=1;return c}();e.create=function(b){return new e(b)};e.registerMatcher=function(b){for(var c in b)b.hasOwnProperty(c)&&F.push(a(c),b[c]);return this};e.registerEncoder=function(b,c){y[b]=c.bind(y);return this};e.registerLanguage=function(b,c){P[b]=c.filter;Q[b]=c.stemmer;return this};e.encode=function(b,c){return R[b]?c:y[b](c)};e.prototype.init=function(b){this.C=
|
||||
[];b||(b=w);var c=b.profile,a=c?L[c]:{};if(c=b.worker)if(Worker){var f=this,d=parseInt(c,10)||4;f.l=-1;f.m=0;f.f=[];f.B=null;f.i=Array(d);for(var e=0;e<d;e++)f.i[e]=ca(f.id,e,b,function(b,c,a,d){if(f.m!==f.h)return f.f=f.f.concat(a),f.m++,d&&f.f.length>=d&&(f.m=f.h),f.B&&f.m===f.h&&(f.cache&&f.g.set(c,f.f),f.B(f.f),f.f=[]),f})}else b.worker=!1,this.i=null;this.mode=b.mode||a.mode||this.mode||w.mode;this.async=x(c=b.async)?this.async||w.async:c;this.h=x(c=b.worker)?this.h||w.h:c;this.threshold=x(c=
|
||||
b.threshold)?a.threshold||this.threshold||w.threshold:c;this.depth=x(c=b.depth)?a.depth||this.depth||w.depth:c;this.v=x(c=b.suggest)?this.v||w.v:c;this.o=(c=x(c=b.encode)?a.encode:c)&&y[c]&&y[c].bind(y)||(H(c)?c:this.o||!1);(c=b.matcher)&&this.addMatcher(c);if(c=b.filter)this.filter=V(P[c]||c,this.o);if(c=b.stemmer)this.stemmer=Z(Q[c]||c,this.o);this.u=N(10);this.j={};this.a={};this.c={};this.b=[];this.D=0;this.s=!0;this.g=(this.cache=c=x(c=b.cache)?this.cache||w.cache:c)?new da(c):!1;return this};
|
||||
e.prototype.encode=function(b){b&&F.length&&(b=l(b,F));b&&this.C.length&&(b=l(b,this.C));b&&this.o&&(b=this.o(b));b&&this.stemmer&&(b=l(b,this.stemmer));return b};e.prototype.addMatcher=function(b){var c=this.C,d;for(d in b)b.hasOwnProperty(d)&&c.push(a(d),b[d]);return this};e.prototype.add=function(b,c,a){if(c&&E(c)&&(b&&!R[b]||0===b))if(this.a[b]&&!a)this.update(b,c);else{if(this.h)return++this.l>=this.i.length&&(this.l=0),this.i[this.l].postMessage(this.l,{add:!0,id:b,content:c}),this.a[b]=""+
|
||||
this.l,this;if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[C.add,b,c],B(this),this;c=this.encode(c);if(!c.length)return this;a=this.mode;c=H(a)?a(c):"ngram"===a?D(c):c.split(O);for(var f={_ctx:{}},e=this.threshold,g=this.depth,k=this.u,r=c.length,t=0;t<r;t++){var l=c[t];if(l){var n=l.length,p=(r-t)/r,q="";switch(a){case "reverse":case "both":for(var u=n-1;1<=u;u--)q=l[u]+q,d(k,f,q,b,(n-u)/n,p,e);q="";case "forward":for(u=0;u<n;u++)q+=l[u],d(k,f,q,b,1,p,e);break;case "full":for(u=
|
||||
0;u<n;u++)for(var m=(n-u)/n,v=n;v>u;v--)q=l.substring(u,v),d(k,f,q,b,m,p,e);break;default:if(n=d(k,f,l,b,1,p,e),g&&1<r&&n>=e)for(n=f._ctx[l]||(f._ctx[l]={}),l=this.j[l]||(this.j[l]=N(10)),p=t-g,q=t+g+1,0>p&&(p=0),q>r&&(q=r);p<q;p++)p!==t&&d(l,n,c[p],b,0,10-(p<t?t-p:p-t),e)}}}this.a[b]=1;this.s=!1}return this};e.prototype.update=function(b,c){this.a[b]&&E(c)&&(this.remove(b),this.add(b,c,!0));return this};e.prototype.remove=function(b){if(this.a[b]){if(this.h){var c=this.a[b];this.i[c].postMessage(c,
|
||||
{remove:!0,id:b});delete this.a[b];return this}if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[C.remove,b],B(this),this;for(c=0;10>c;c++)m(this.u[c],b);this.depth&&m(this.j,b);delete this.a[b];this.s=!1}return this};e.prototype.search=function(b,c,a,f){var d=b,e=[];if("object"===typeof b){(a=b.callback||c)&&(d.callback=null);c=b.limit;var g=b.threshold;b=b.query}g||(g=this.threshold||0);H(c)?(a=c,c=1E3):c||0===c||(c=1E3);if(this.h)for(this.B=a,this.m=0,this.f=[],e=0;e<this.h;e++)this.i[e].postMessage(e,
|
||||
{search:!0,limit:c,threshold:g,content:b});else if(a){var k=this;M(function(){a(k.search(d,c,null,!0));k=null},1,"search-"+this.id)}else{if(!f&&this.async){var l=this;return new Promise(function(b){b(l.search(d,c,null,!0));l=null})}if(!b||!E(b))return e;d=b;if(this.cache)if(this.s){if(f=this.g.get(b))return f}else this.g.clear(),this.s=!0;d=this.encode(d);if(!d.length)return e;f=this.mode;f=H(f)?f(d):"ngram"===f?D(d):d.split(O);var t=f.length,n=!0,p=[],q={};if(1<t)if(this.depth){var m=!0;var v=f[0];
|
||||
q[v]=1}else f.sort(W);var w;if(!m||(w=this.j)[v])for(var x=m?1:0;x<t;x++){var y=f[x];if(y&&!q[y]){var G=void 0;G=void 0;for(var C=!1,B=[],F=0,I=9;I>=g;I--)if(G=(m?w[v]:this.u)[I],G=G[y])B[F++]=G,C=!0;if(C)p[p.length]=1<F?p.concat.apply([],B):B[0];else if(!this.v){n=!1;break}q[y]=1}v=y}else n=!1;n&&(e=Y(p,c,this.v));this.cache&&this.g.set(b,e);return e}};e.prototype.clear=function(){this.destroy();return this.init()};e.prototype.destroy=function(){this.cache&&(this.g.clear(),this.g=null);this.filter=
|
||||
this.stemmer=this.u=this.j=this.a=this.c=this.b=null;return this};var y={icase:function(b){return b.toLowerCase()},simple:function(){var b=[a("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",a("[\u00e8\u00e9\u00ea\u00eb]"),"e",a("[\u00ec\u00ed\u00ee\u00ef]"),"i",a("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",a("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",a("[\u00fd\u0177\u00ff]"),"y",a("\u00f1"),"n",a("\u00e7"),"c",a("\u00df"),"s",a(" & ")," and ",a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(c){c=
|
||||
l(c.toLowerCase(),b);return" "!==c?c:""}}(),advanced:function(){var b=[a("ae"),"a",a("ai"),"ei",a("ay"),"ei",a("ey"),"ei",a("oe"),"o",a("ue"),"u",a("ie"),"i",a("sz"),"s",a("zs"),"s",a("sh"),"s",a("ck"),"k",a("cc"),"k",a("dt"),"t",a("ph"),"f",a("pf"),"f",a("ou"),"o",a("uo"),"u"];return function(c,a){if(!c)return c;c=this.simple(c);2<c.length&&(c=l(c,b));a||1<c.length&&(c=v(c));return c}}(),extra:function(){var b=[a("p"),"b",a("z"),"s",a("[cgq]"),"k",a("n"),"m",a("d"),"t",a("[vw]"),"f",a("[aeiouy]"),
|
||||
""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(var c=0;c<a.length;c++){var d=a[c];1<d.length&&(a[c]=d[0]+l(d.substring(1),b))}a=a.join(" ");a=v(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(a){return v(l(a.toLowerCase(),b))}}()},M=function(){var b={};return function(a,d,f){var c=b[f];c&&clearTimeout(c);return b[f]=setTimeout(a,d)}}(),da=function(){function a(a){this.clear();this.A=!0!==a&&
|
||||
a}a.prototype.clear=function(){this.cache={};this.count={};this.index={};this.a=[]};a.prototype.set=function(a,b){if(this.A&&x(this.cache[a])){var c=this.a.length;if(c===this.A){c--;var d=this.a[c];delete this.cache[d];delete this.count[d];delete this.index[d]}this.index[a]=c;this.a[c]=a;this.count[a]=-1;this.cache[a]=b;this.get(a)}else this.cache[a]=b};a.prototype.get=function(a){var b=this.cache[a];if(this.A&&b){var c=++this.count[a],d=this.index,e=d[a];if(0<e){for(var g=this.a,k=e;this.count[g[--e]]<=
|
||||
c&&-1!==e;);e++;if(e!==k){for(c=k;c>e;c--)k=g[c-1],g[c]=k,d[k]=c;g[e]=a;d[a]=e}}}return b};return a}();return e}(function(){var g=Object.create(null),h="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(e,k,a,l,d){var m=e;e=h?URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"})):"../"+m+".min.js";m+="-"+k;g[m]||(g[m]=[]);g[m][d]=new Worker(e);g[m][d].onmessage=l;return{postMessage:function(a,d){g[m][a].postMessage(d)}}}}()),this);
|
||||
|
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flexsearch",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"description": "Next-Generation full text search library with zero dependencies.",
|
||||
"homepage": "https://github.com/nextapps-de/flexsearch/",
|
||||
"author": "Thomas Wilkerling",
|
||||
@@ -24,10 +24,10 @@
|
||||
"url": "https://github.com/nextapps-de/flexsearch.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node compile RELEASE=min DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-light": "node compile RELEASE=light DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-compact": "node compile RELEASE=compact DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_PRESETS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-custom": "node compile RELEASE=custom DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build": "node compile RELEASE=min DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-light": "node compile RELEASE=light DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-compact": "node compile RELEASE=compact DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CACHE=false SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-custom": "node compile RELEASE=custom DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-lang": "node compile RELEASE=lang",
|
||||
"build-all": "npm run build && npm run build-light && npm run build-compact && npm run build-lang",
|
||||
"test-production": "nyc --reporter=html --reporter=text mocha --timeout=3000 test --exit",
|
||||
|
@@ -17,7 +17,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<h2>Benchmark Comparison</h2>
|
||||
<button id="btn_start" onclick="start();" disabled>Start</button>
|
||||
<!--<button id="btn_start" onclick="start();" disabled>Start</button>-->
|
||||
<h4>Indexed Text: "Gulliver's Travels" (Swift Jonathan 1726)</h4>
|
||||
<hr>
|
||||
<div id="container"></div>
|
||||
@@ -370,15 +370,23 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
target.innerHTML = html;
|
||||
}
|
||||
|
||||
var is_mobile = navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/);
|
||||
|
||||
function init_tests(index, keys){
|
||||
|
||||
var key = keys[index];
|
||||
var test = tests[key];
|
||||
|
||||
tests[key].init();
|
||||
test.init();
|
||||
|
||||
if(is_mobile && (test.loops > 1)){
|
||||
|
||||
test.loops = (test.loops / 5) >> 0;
|
||||
}
|
||||
|
||||
for(var i = 0; i < text_data.length; i++){
|
||||
|
||||
tests[key].add(i, text_data[i]);
|
||||
test.add(i, text_data[i]);
|
||||
}
|
||||
|
||||
document.getElementById("test-" + key).textContent = "ready ...";
|
||||
@@ -389,24 +397,24 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
init_tests(index, keys);
|
||||
|
||||
}, 50);
|
||||
}, 100);
|
||||
}
|
||||
else{
|
||||
|
||||
/*
|
||||
window.start = function(){
|
||||
|
||||
start_tests(0, Object.keys(tests));
|
||||
};
|
||||
|
||||
document.getElementById("btn_start").disabled = false;
|
||||
*/
|
||||
|
||||
/*
|
||||
setTimeout(function(){
|
||||
|
||||
start_tests(0, keys);
|
||||
|
||||
}, 50);
|
||||
*/
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,9 +423,9 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
var queries = text_queries;
|
||||
var len = queries.length;
|
||||
var key = keys[index];
|
||||
var current = tests[key];
|
||||
var loops = current.loops;
|
||||
var query = current.query;
|
||||
var test = tests[key];
|
||||
var loops = test.loops;
|
||||
var query = test.query;
|
||||
|
||||
var start = Date.now();
|
||||
|
||||
@@ -435,7 +443,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
console.log(key + ":", duration);
|
||||
|
||||
document.getElementById("test-" + key).textContent = format_number((1000 / duration * loops + 0.5) >> 0) + " op/s";
|
||||
document.getElementById("test-" + key).textContent = /*format_number*/((1000 / duration * loops + 0.5) >> 0) + " op/s";
|
||||
|
||||
if(++index < keys.length){
|
||||
|
||||
@@ -443,7 +451,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
start_tests(index, keys);
|
||||
|
||||
}, 50);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +461,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
init_tests(0, Object.keys(tests));
|
||||
|
||||
}, 50);
|
||||
}, 100);
|
||||
|
||||
function format_number(num){
|
||||
|
||||
@@ -462,7 +470,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
// ---------------------------------------
|
||||
|
||||
window.tests = tests;
|
||||
//window.tests = tests;
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
116
test/test.js
116
test/test.js
@@ -513,18 +513,42 @@ if(env !== "light"){
|
||||
flexsearch_async.update(1, "foo");
|
||||
|
||||
expect(flexsearch_async.length).to.equal(3);
|
||||
expect(flexsearch_async.search("foo")).to.not.have.members([2, 1]);
|
||||
expect(flexsearch_async.search("bar")).to.not.include(0);
|
||||
expect(flexsearch_async.search("bar")).to.include(2);
|
||||
expect(flexsearch_async.search("foobar")).to.not.include(2);
|
||||
|
||||
flexsearch_async.search("foo").then(function(result){
|
||||
expect(result).to.not.have.members([2, 1]);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar").then(function(result){
|
||||
expect(result).to.not.include(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar").then(function(result){
|
||||
expect(result).to.include(2);
|
||||
});
|
||||
|
||||
flexsearch_async.search("foobar").then(function(result){
|
||||
expect(result).to.not.include(2);
|
||||
});
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_async.length).to.equal(3);
|
||||
expect(flexsearch_async.search("foo")).to.have.members([2, 1]);
|
||||
expect(flexsearch_async.search("bar")).to.include(0);
|
||||
expect(flexsearch_async.search("bar")).to.not.include(2);
|
||||
expect(flexsearch_async.search("foobar")).to.include(2);
|
||||
|
||||
flexsearch_async.search("foo", function(result){
|
||||
expect(result).to.have.members([2, 1]);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar", function(result){
|
||||
expect(result).to.include(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar", function(result){
|
||||
expect(result).to.not.include(2);
|
||||
});
|
||||
|
||||
flexsearch_async.search("foobar", function(result){
|
||||
expect(result).to.include(2);
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
@@ -546,10 +570,22 @@ if(env !== "light"){
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_async.length).to.equal(3);
|
||||
expect(flexsearch_async.search("foo")).to.have.members([2, 1]);
|
||||
expect(flexsearch_async.search("bar")).to.include(0);
|
||||
expect(flexsearch_async.search("bar")).to.not.include(2);
|
||||
expect(flexsearch_async.search("foobar")).to.include(2);
|
||||
|
||||
flexsearch_async.search("foo").then(function(result){
|
||||
expect(result).to.have.members([2, 1]);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar").then(function(result){
|
||||
expect(result).to.include(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar").then(function(result){
|
||||
expect(result).to.not.include(2);
|
||||
});
|
||||
|
||||
flexsearch_async.search("foobar").then(function(result){
|
||||
expect(result).to.include(2);
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
@@ -570,9 +606,18 @@ if(env !== "light"){
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_async.length).to.equal(0);
|
||||
expect(flexsearch_async.search("foo")).to.have.lengthOf(0);
|
||||
expect(flexsearch_async.search("bar")).to.have.lengthOf(0);
|
||||
expect(flexsearch_async.search("foobar")).to.have.lengthOf(0);
|
||||
|
||||
flexsearch_async.search("foo", function(result){
|
||||
expect(result).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar", function(result){
|
||||
expect(result).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("foobar", function(result){
|
||||
expect(result).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
@@ -767,6 +812,8 @@ if(env !== "light"){
|
||||
|
||||
it("Should have been removed from the index", function(done){
|
||||
|
||||
expect(flexsearch_worker.length).to.equal(3);
|
||||
|
||||
flexsearch_worker.remove(0);
|
||||
flexsearch_worker.remove(2);
|
||||
flexsearch_worker.remove(1);
|
||||
@@ -1039,28 +1086,31 @@ describe("Relevance", function(){
|
||||
// Suggestion Tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
describe("Suggestion", function(){
|
||||
if(env !== "light"){
|
||||
|
||||
it("Should have been suggested properly by relevance", function(){
|
||||
describe("Suggestion", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
encode: "advanced",
|
||||
mode: "strict",
|
||||
suggest: true
|
||||
it("Should have been suggested properly by relevance", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
encode: "advanced",
|
||||
mode: "strict",
|
||||
suggest: true
|
||||
});
|
||||
|
||||
index.add(0, "1 2 3 2 4 1 5 3");
|
||||
index.add(1, "zero one two three four five six seven eight nine ten");
|
||||
index.add(2, "four two zero one three ten five seven eight six nine");
|
||||
|
||||
expect(index.search("1 3 4 7")).to.have.members([0]);
|
||||
expect(index.search("1 3 9 7")).to.have.members([0]);
|
||||
expect(index.search("one foobar two")).to.have.members([1, 2]);
|
||||
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
|
||||
//TODO
|
||||
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
|
||||
});
|
||||
|
||||
index.add(0, "1 2 3 2 4 1 5 3");
|
||||
index.add(1, "zero one two three four five six seven eight nine ten");
|
||||
index.add(2, "four two zero one three ten five seven eight six nine");
|
||||
|
||||
expect(index.search("1 3 4 7")).to.have.members([0]);
|
||||
expect(index.search("1 3 9 7")).to.have.members([0]);
|
||||
expect(index.search("one foobar two")).to.have.members([1, 2]);
|
||||
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
|
||||
//TODO
|
||||
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Feature Tests
|
||||
|
Reference in New Issue
Block a user