mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-01 18:03:56 +02:00
v0.3.4
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@
|
||||
coverage
|
||||
perf
|
||||
node_modules
|
||||
server
|
||||
!*.keep
|
||||
src
|
||||
tmp
|
||||
|
46
README.md
46
README.md
@@ -7,9 +7,9 @@
|
||||
<a target="_blank" href="https://travis-ci.org/nextapps-de/flexsearch"><img src="https://travis-ci.org/nextapps-de/flexsearch.svg?branch=master"></a>
|
||||
<a target="_blank" href="https://coveralls.io/github/nextapps-de/flexsearch?branch=master"><img src="https://coveralls.io/repos/github/nextapps-de/flexsearch/badge.svg?branch=master"></a>
|
||||
<a target="_blank" href="https://www.codacy.com/app/ts-thomas/FlexSearch?utm_source=github.com&utm_medium=referral&utm_content=nextapps-de/flexsearch&utm_campaign=Badge_Grade"><img src="https://api.codacy.com/project/badge/Grade/a896e010f6b4429aa7bc9a89550320a7"/></a>
|
||||
<a target="_blank" href="https://github.com/nextapps-de/flexsearch/issues"><img src="https://img.shields.io/github/issues/nextapps-de/xone.svg"></a>
|
||||
<a target="_blank" href="https://github.com/nextapps-de/flexsearch/issues"><img src="https://img.shields.io/github/issues/nextapps-de/flexsearch.svg"></a>
|
||||
<!--<img src="https://badges.greenkeeper.io/nextapps-de/flexsearch.svg">-->
|
||||
<a target="_blank" href="https://github.com/nextapps-de/flexsearch/blob/master/LICENSE.md"><img src="https://img.shields.io/npm/l/xone.svg"></a>
|
||||
<a target="_blank" href="https://github.com/nextapps-de/flexsearch/blob/master/LICENSE.md"><img src="https://img.shields.io/npm/l/flexsearch.svg"></a>
|
||||
</p>
|
||||
|
||||
<h1></h1>
|
||||
@@ -19,12 +19,14 @@ When it comes to raw search speed <a href="https://rawgit.com/nextapps-de/flexse
|
||||
Depending on the used options it also providing the <a href="#memory">most memory-efficient index</a>. Keep in mind that updating and/or removing existing items from the index has a significant cost. When your index needs to be updated very often then <a href="bulksearch/" target="_blank">BulkSearch</a> may be a better choice.
|
||||
FlexSearch also provides you a non-blocking asynchronous processing model as well as web workers to perform any updates or queries on the index in parallel through dedicated balanced threads.
|
||||
|
||||
<a href="#installation">Installation Guide</a>  •  <a href="#api">API Reference</a>  •  <a href="#profiles">Example Options</a>  •  <a href="#builds">Custom Builds</a>
|
||||
<a href="#installation">Installation Guide</a>  •  <a href="#api">API Reference</a>  •  <a href="#profiles">Example Options</a>  •  <a href="#builds">Custom Builds</a>  •  <a target="_blank" href="https://github.com/nextapps-de/flexsearch-server">Flexsearch Server</a>
|
||||
|
||||
Supported Platforms:
|
||||
- Browser
|
||||
- Node.js
|
||||
|
||||
> FlexSearch Server is also available here: <a target="_blank" href="https://github.com/nextapps-de/flexsearch-server">https://github.com/nextapps-de/flexsearch-server</a>
|
||||
|
||||
Library Comparison:
|
||||
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark.html" target="_blank">Benchmark "Gulliver's Travels"</a>
|
||||
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching.html" target="_blank">Relevance Scoring</a>
|
||||
@@ -201,10 +203,10 @@ __Query Test: "Gulliver's Travels"__
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>FlexSearch <a href="#notes">***</a></td>
|
||||
<td>0.3.2</td>
|
||||
<td><b>342040</b></td>
|
||||
<td><b>178456</b></td>
|
||||
<td><b>1527778</b></td>
|
||||
<td>0.3.3</td>
|
||||
<td><b>363757</b></td>
|
||||
<td><b>182603</b></td>
|
||||
<td><b>1627219</b></td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
@@ -543,6 +545,8 @@ Index methods:
|
||||
- <a href="#index.info">Index.__info__()</a>
|
||||
- <a href="#index.addmatcher">Index.__addMatcher__({_KEY: VALUE_})</a>
|
||||
- <a href="#index.encode">Index.__encode__(string)</a>
|
||||
- <a href="#index.export">Index.__export__()</a>
|
||||
- <a href="#index.import">Index.__import__(string)</a>
|
||||
|
||||
## Usage
|
||||
<a name="flexsearch.create"></a>
|
||||
@@ -1589,6 +1593,34 @@ index.add(index_table["fdf12cad-8779-47ab-b614-4dbbd649178b"], "content");
|
||||
|
||||
It is planned to provide a built-in feature which should replace this workaround.
|
||||
|
||||
<a name="export"></a>
|
||||
## Export/Import Index
|
||||
|
||||
> index.export() returns a serialized dump as a string.
|
||||
|
||||
> index.import(string) takes a serialized dump as a string and load it to the index.
|
||||
|
||||
Assuming you have one or several indexes:
|
||||
```js
|
||||
var feeds_2017 = new FlexSearch();
|
||||
var feeds_2018 = new FlexSearch();
|
||||
var feeds_2019 = new FlexSearch();
|
||||
```
|
||||
|
||||
Export indexes, e.g. to the local storage:
|
||||
```js
|
||||
localStorage.setItem("feeds_2017", feeds_2017.export());
|
||||
localStorage.setItem("feeds_2018", feeds_2018.export());
|
||||
localStorage.setItem("feeds_2019", feeds_2019.export());
|
||||
```
|
||||
|
||||
Import indexes, e.g. from the local storage:
|
||||
```js
|
||||
feeds_2017.import(localStorage.getItem("feeds_2017"));
|
||||
feeds_2018.import(localStorage.getItem("feeds_2018"));
|
||||
feeds_2019.import(localStorage.getItem("feeds_2019"));
|
||||
```
|
||||
|
||||
<a name="debug"></a>
|
||||
## Debug
|
||||
|
||||
|
@@ -5,20 +5,20 @@
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(g,r,c){let h;(h=c.define)&&h.amd?h([],function(){return r}):(h=c.modules)?h[g.toLowerCase()]=r:"object"===typeof exports?module.exports=r:c[g]=r})("FlexSearch",function(){function g(a){y(a)&&(a=G[a]);a||(a=t);this.id=a.id||M++;this.init(a);r(this,"index",function(){return this.b});r(this,"length",function(){return Object.keys(this.b).length})}function r(a,b,d){Object.defineProperty(a,b,{get:d})}function c(a){return new RegExp(a,"g")}function h(a,b){for(let d=0;d<b.length;d+=
|
||||
2)a=a.replace(b[d],b[d+1]);return a}function x(a,b,d,f,e,c,k){if(b[d])return b[d];e=e?(9-(k||6))*c+(k||6)*e:c;b[d]=e;e>=k&&(a=a[e+.5>>0],a=a[d]||(a[d]=[]),a[a.length]=f);return e}function C(a,b){if(a){const d=Object.keys(a);for(let f=0,e=d.length;f<e;f++){const e=d[f],c=a[e];if(c)for(let d=0,f=c.length;d<f;d++)if(c[d]===b){1===f?delete a[e]:c.splice(d,1);break}else"object"===typeof c[d]&&C(c[d],b)}}}function D(a){let b="",d="";var f="";for(let e=0;e<a.length;e++){const c=a[e];if(c!==d)if(e&&"h"===
|
||||
c){if(f="a"===f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f,("a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d)&&f||" "===d)b+=c}else b+=c;f=e===a.length-1?"":a[e+1];d=c}return b}function N(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function O(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function P(a,b,d){let c=[],e=[];const u=a.length;if(1<u){a.sort(O);const f=q();let g=a[0],v=g.length,h=0;for(;h<v;)f[g[h++]]=1;let l,p=0,m=0;for(;++m<u;){let n=!1;const q=m===u-1;e=[];g=a[m];v=g.length;for(h=
|
||||
0;h<v;)if(l=g[h++],f[l]){var k=f[l];if(k===m){if(q){if(c[p++]=l,b&&p===b)return c}else f[l]=m+1;n=!0}else d&&(k=e[k]||(e[k]=[]),k[k.length]=l)}if(!n&&!d)break}if(d&&(p=c.length,(m=e.length)&&(!b||p<b)))for(;m--;)if(l=e[m])for(let a=0,d=l.length;a<d;a++)if(c[p++]=l[a],b&&p===b)return c}else u&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function y(a){return"string"===typeof a}function z(a){return"function"===typeof a}function A(a){return"undefined"===typeof a}function E(a){a.l||(a.l=H(function(){a.l=
|
||||
0;{const b=a.async;let d;b&&(a.async=!1);if(a.c.length){const b=Date.now();let c;for(;(c=a.c.shift())||0===c;){d=a.f[c];switch(d[0]){case B.add:a.add(d[1],d[2]);break;case B.remove:a.remove(d[1])}delete a.f[c];if(100<Date.now()-b)break}a.c.length&&E(a)}b&&(a.async=b)}},1,"search-async-"+a.id))}function I(a){const b=Array(a);for(let d=0;d<a;d++)b[d]=q();return b}function q(){return Object.create(null)}const t={encode:"icase",a:"forward",m:!1,cache:!1,async:!1,o:!1,threshold:0,depth:0},G={memory:{encode:"extra",
|
||||
a:"strict",threshold:7},speed:{encode:"icase",a:"strict",threshold:7,depth:2},match:{encode:"extra",a:"full"},score:{encode:"extra",a:"strict",threshold:5,depth:4},balance:{encode:"balance",a:"strict",threshold:6,depth:3},fastest:{encode:"icase",a:"strict",threshold:9,depth:1}},F=[];let M=0;const B={add:0,update:1,remove:2},J=c("\\W+"),K={},L={};(function(){const a=Object.getOwnPropertyNames({}.__proto__),b=q();for(let d=0;d<a.length;d++)b[a[d]]=1;return b})();g.create=function(a){return new g(a)};
|
||||
g.registerMatcher=function(a){for(let b in a)a.hasOwnProperty(b)&&F.push(c(b),a[b]);return this};g.registerEncoder=function(a,b){w[a]=b.bind(w);return this};g.registerLanguage=function(a,b){K[a]=b.filter;L[a]=b.stemmer;return this};g.encode=function(a,b){return w[a](b)};g.prototype.init=function(a){this.j=[];a||(a=t);var b=a.profile,d=b?G[b]:{};this.a=a.tokenize||d.a||this.a||t.a;this.async=A(b=a.async)?this.async||t.async:b;this.threshold=A(b=a.threshold)?d.threshold||this.threshold||t.threshold:
|
||||
b;this.depth=A(b=a.depth)?d.depth||this.depth||t.depth:b;this.h=(b=A(b=a.encode)?d.encode:b)&&w[b]&&w[b].bind(w)||(z(b)?b:this.h||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=K[b]||b;d=this.h;var f=q();if(b)for(let a=0;a<b.length;a++){const c=d?d(b[a]):b[a];f[c]=String.fromCharCode(65E3-b.length+a)}this.filter=b=f}if(b=a.stemmer){var e;a=L[b]||b;b=this.h;d=[];if(a)for(e in a)a.hasOwnProperty(e)&&(f=b?b(e):e,d.push(c("(?=.{"+(f.length+3)+",})"+f+"$"),b?b(a[e]):a[e]));this.stemmer=e=d}this.i=
|
||||
I(10);this.g=q();this.b=q();this.f=q();this.c=[];this.l=0;return this};g.prototype.encode=function(a){a&&F.length&&(a=h(a,F));a&&this.j.length&&(a=h(a,this.j));a&&this.h&&(a=this.h(a));a&&this.stemmer&&(a=h(a,this.stemmer));return a};g.prototype.addMatcher=function(a){const b=this.j;for(const d in a)a.hasOwnProperty(d)&&b.push(c(d),a[d]);return this};g.prototype.add=function(a,b,d){if(b&&y(b)&&(a||0===a))if(this.b[a]&&!d)this.update(a,b);else{if(this.async)return this.f[a]||(this.c[this.c.length]=
|
||||
a),this.f[a]=[B.add,a,b],E(this),this;b=this.encode(b);if(!b.length)return this;d=this.a;b=z(d)?d(b):b.split(J);const f=q();f._ctx=q();const h=this.threshold,u=this.depth,l=this.i,p=b.length;for(let m=0;m<p;m++){var c=b[m];if(c){var e=c.length,g=(p-m)/p,k="";switch(d){case "reverse":case "both":for(var n=e-1;1<=n;n--)k=c[n]+k,x(l,f,k,a,(e-n)/e,g,h);k="";case "forward":for(n=0;n<e;n++)k+=c[n],x(l,f,k,a,1,g,h);break;case "full":for(n=0;n<e;n++){const b=(e-n)/e;for(let d=e;d>n;d--)k=c.substring(n,d),
|
||||
x(l,f,k,a,b,g,h)}break;default:if(e=x(l,f,c,a,1,g,h),u&&1<p&&e>=h)for(e=f._ctx[c]||(f._ctx[c]=q()),c=this.g[c]||(this.g[c]=I(10)),g=m-u,k=m+u+1,0>g&&(g=0),k>p&&(k=p);g<k;g++)g!==m&&x(c,e,b[g],a,0,10-(g<m?m-g:g-m),h)}}}this.b[a]=1}return this};g.prototype.update=function(a,b){this.b[a]&&y(b)&&(this.remove(a),this.add(a,b,!0));return this};g.prototype.remove=function(a){if(this.b[a]){if(this.async)return this.f[a]||(this.c[this.c.length]=a),this.f[a]=[B.remove,a],E(this),this;for(let b=0;10>b;b++)C(this.i[b],
|
||||
a);this.depth&&C(this.g,a);delete this.b[a]}return this};g.prototype.search=function(a,b,c,f){let d=a,g,k=[];"object"===typeof a&&((c=a.callback||b)&&(d.callback=null),b=a.limit,g=a.threshold,a=a.query);g||(g=this.threshold||0);z(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(c){{let a=this;H(function(){c(a.search(d,b,null,!0));a=null},1,"search-"+this.id)}}else{if(!f&&this.async&&"function"!==typeof importScripts){let a=this;return new Promise(function(c){c(a.search(d,b,null,!0));a=null})}if(!a||!y(a))return k;
|
||||
d=a;d=this.encode(d);if(!d.length)return k;a=this.a;a=z(a)?a(d):d.split(J);f=a.length;var h=!0,r=[],v=q();if(1<f)if(this.depth){var t=!0;var l=a[0];v[l]=1}else a.sort(N);var p;if(!t||(p=this.g)[l])for(let b=t?1:0;b<f;b++){const c=a[b];if(c){if(!v[c]){const a=[];let b=!1,d=0;if(l=t?p[l]:this.i){let f;for(let e=9;e>=g;e--)if(f=l[e][c])a[d++]=f,b=!0}if(b)r[r.length]=1<d?a.concat.apply([],a):a[0];else{h=!1;break}v[c]=1}l=c}}else h=!1;h&&(k=P(r,b,!1));return k}};g.prototype.clear=function(){this.destroy();
|
||||
return this.init()};g.prototype.destroy=function(){this.filter=this.stemmer=this.i=this.g=this.b=this.f=this.c=null;return this};const w={icase:function(a){return a.toLowerCase()},simple:function(){const a=[c("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",c("[\u00e8\u00e9\u00ea\u00eb]"),"e",c("[\u00ec\u00ed\u00ee\u00ef]"),"i",c("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",c("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",c("[\u00fd\u0177\u00ff]"),"y",c("\u00f1"),"n",c("\u00e7"),"c",c("\u00df"),"s",c(" & "),
|
||||
" and ",c("[-/]")," ",c("[^a-z0-9 ]"),"",c("\\s+")," "];return function(b){b=h(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){const a=[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(b,c){if(!b)return b;b=this.simple(b);2<b.length&&(b=h(b,a));c||1<b.length&&(b=D(b));return b}}(),extra:function(){const a=[c("p"),
|
||||
"b",c("z"),"s",c("[cgq]"),"k",c("n"),"m",c("d"),"t",c("[vw]"),"f",c("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(let c=0;c<b.length;c++){const d=b[c];1<d.length&&(b[c]=d[0]+h(d.substring(1),a))}b=b.join(" ");b=D(b)}return b}}(),balance:function(){const a=[c("[-/]")," ",c("[^a-z0-9 ]"),"",c("\\s+")," "];return function(b){return D(h(b.toLowerCase(),a))}}()},H=function(){const a=q();return function(b,c,f){const d=a[f];d&&clearTimeout(d);return a[f]=
|
||||
setTimeout(b,c)}}();return g}(!1),this);
|
||||
'use strict';(function(g,u,c){let m;(m=c.define)&&m.amd?m([],function(){return u}):(m=c.modules)?m[g.toLowerCase()]=u:"object"===typeof exports?module.exports=u:c[g]=u})("FlexSearch",function(){function g(a){y(a)&&(a=H[a]);a||(a=v);this.id=a.id||O++;this.init(a);u(this,"index",function(){return this.b});u(this,"length",function(){return Object.keys(this.b).length})}function u(a,b,d){Object.defineProperty(a,b,{get:d})}function c(a){return new RegExp(a,"g")}function m(a,b){for(let d=0;d<b.length;d+=
|
||||
2)a=a.replace(b[d],b[d+1]);return a}function x(a,b,d,e,f,c,h){if(b[d])return b[d];f=f?(9-(h||6))*c+(h||6)*f:c;b[d]=f;f>=h&&(a=a[9-(f+.5>>0)],a=a[d]||(a[d]=[]),a[a.length]=e);return f}function D(a,b){if(a){const d=Object.keys(a);for(let e=0,f=d.length;e<f;e++){const f=d[e],c=a[f];if(c)for(let d=0,e=c.length;d<e;d++)if(c[d]===b){1===e?delete a[f]:c.splice(d,1);break}else"object"===typeof c[d]&&D(c[d],b)}}}function E(a){let b="",d="";var e="";for(let f=0;f<a.length;f++){const c=a[f];if(c!==d)if(f&&"h"===
|
||||
c){if(e="a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e,("a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d)&&e||" "===d)b+=c}else b+=c;e=f===a.length-1?"":a[f+1];d=c}return b}function P(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function Q(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function R(a,b,d){let c=[],f;const z=a.length;if(1<z){a.sort(Q);const e=t();let g=a[0],p=g.length,n=0;for(;n<p;)e["@"+g[n++]]=1;let l,r=0,q=0;for(;++q<z;){let I=!1;const k=q===z-1;f=[];g=a[q];p=g.length;for(n=
|
||||
0;n<p;){l=g[n++];var h="@"+l;if(e[h]){const a=e[h];if(a===q){if(k){if(c[r++]=l,b&&r===b)return c}else e[h]=q+1;I=!0}else d&&(h=f[a]||(f[a]=[]),h[h.length]=l)}}if(!I&&!d)break}if(d&&(r=c.length,(q=f.length)&&(!b||r<b)))for(;q--;)if(l=f[q])for(let a=0,d=l.length;a<d;a++)if(c[r++]=l[a],b&&r===b)return c}else z&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function y(a){return"string"===typeof a}function A(a){return"function"===typeof a}function B(a){return"undefined"===typeof a}function F(a){a.l||
|
||||
(a.l=J(function(){a.l=0;{const b=a.async;let d;b&&(a.async=!1);if(a.c.length){const b=Date.now();let c;for(;(c=a.c.shift())||0===c;){d=a.g[c];switch(d[0]){case C.add:a.add(d[1],d[2]);break;case C.remove:a.remove(d[1])}delete a.g[c];if(100<Date.now()-b)break}a.c.length&&F(a)}b&&(a.async=b)}},1,"@"+a.id))}function K(a){const b=Array(a);for(let d=0;d<a;d++)b[d]=t();return b}function t(){return Object.create(null)}const v={encode:"icase",a:"forward",m:!1,cache:!1,async:!1,o:!1,threshold:0,depth:0},H=
|
||||
{memory:{encode:"extra",a:"strict",threshold:7},speed:{encode:"icase",a:"strict",threshold:7,depth:2},match:{encode:"extra",a:"full"},score:{encode:"extra",a:"strict",threshold:5,depth:4},balance:{encode:"balance",a:"strict",threshold:6,depth:3},fastest:{encode:"icase",a:"strict",threshold:9,depth:1}},G=[];let O=0;const C={add:0,update:1,remove:2},L=c("\\W+"),M={},N={};(function(){const a=Object.getOwnPropertyNames({}.__proto__),b=t();for(let d=0;d<a.length;d++)b[a[d]]=1;return b})();g.create=function(a){return new g(a)};
|
||||
g.registerMatcher=function(a){for(let b in a)a.hasOwnProperty(b)&&G.push(c(b),a[b]);return this};g.registerEncoder=function(a,b){w[a]=b.bind(w);return this};g.registerLanguage=function(a,b){M[a]=b.filter;N[a]=b.stemmer;return this};g.encode=function(a,b){return w[a](b)};g.prototype.init=function(a){this.j=[];a||(a=v);var b=a.profile,d=b?H[b]:{};this.a=a.tokenize||d.a||this.a||v.a;this.async=B(b=a.async)?this.async||v.async:b;this.threshold=B(b=a.threshold)?d.threshold||this.threshold||v.threshold:
|
||||
b;this.depth=B(b=a.depth)?d.depth||this.depth||v.depth:b;this.i=(b=B(b=a.encode)?d.encode:b)&&w[b]&&w[b].bind(w)||(A(b)?b:this.i||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=M[b]||b;d=this.i;var e=t();if(b)for(let a=0;a<b.length;a++){const c=d?d(b[a]):b[a];e[c]=String.fromCharCode(65E3-b.length+a)}this.filter=b=e}if(b=a.stemmer){var f;a=N[b]||b;b=this.i;d=[];if(a)for(f in a)a.hasOwnProperty(f)&&(e=b?b(f):f,d.push(c("(?=.{"+(e.length+3)+",})"+e+"$"),b?b(a[f]):a[f]));this.stemmer=f=d}this.h=
|
||||
K(10-(this.threshold||0));this.f=t();this.b=t();this.g=t();this.c=[];this.l=0;return this};g.prototype.encode=function(a){a&&G.length&&(a=m(a,G));a&&this.j.length&&(a=m(a,this.j));a&&this.i&&(a=this.i(a));a&&this.stemmer&&(a=m(a,this.stemmer));return a};g.prototype.addMatcher=function(a){const b=this.j;for(const d in a)a.hasOwnProperty(d)&&b.push(c(d),a[d]);return this};g.prototype.add=function(a,b,d){if(b&&y(b)&&(a||0===a)){const e="@"+a;if(this.b[e]&&!d)this.update(a,b);else{if(this.async)return this.g[e]||
|
||||
(this.c[this.c.length]=e),this.g[e]=[C.add,a,b],F(this),this;b=this.encode(b);if(!b.length)return this;d=this.a;b=A(d)?d(b):b.split(L);const p=t();p._ctx=t();const n=this.threshold,l=this.depth,r=this.h,q=b.length;for(let e=0;e<q;e++){var c=b[e];if(c){var f=c.length,g=(q-e)/q,h="";switch(d){case "reverse":case "both":for(var k=f-1;1<=k;k--)h=c[k]+h,x(r,p,h,a,(f-k)/f,g,n);h="";case "forward":for(k=0;k<f;k++)h+=c[k],x(r,p,h,a,1,g,n);break;case "full":for(k=0;k<f;k++){const b=(f-k)/f;for(let d=f;d>k;d--)h=
|
||||
c.substring(k,d),x(r,p,h,a,b,g,n)}break;default:if(f=x(r,p,c,a,1,g,n),l&&1<q&&f>=n)for(f=p._ctx[c]||(p._ctx[c]=t()),c=this.f[c]||(this.f[c]=K(10-(n||0))),g=e-l,h=e+l+1,0>g&&(g=0),h>q&&(h=q);g<h;g++)g!==e&&x(c,f,b[g],a,0,10-(g<e?e-g:g-e),n)}}}this.b[e]=1}}return this};g.prototype.update=function(a,b){this.b["@"+a]&&y(b)&&(this.remove(a),this.add(a,b,!0));return this};g.prototype.remove=function(a){const b="@"+a;if(this.b[b]){if(this.async)return this.g[b]||(this.c[this.c.length]=b),this.g[b]=[C.remove,
|
||||
a],F(this),this;for(let b=0;b<10-(this.threshold||0);b++)D(this.h[b],a);this.depth&&D(this.f,a);delete this.b[b]}return this};g.prototype.search=function(a,b,c,e){let d=a,g,h=[];"object"===typeof a&&((c=a.callback||b)&&(d.callback=null),b=a.limit,g=a.threshold,a=a.query);g||(g=this.threshold||0);A(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(c){{let a=this;J(function(){c(a.search(d,b,null,!0));a=null},1,"search-"+this.id)}}else{if(!e&&this.async&&"function"!==typeof importScripts){let a=this;return new Promise(function(c){c(a.search(d,
|
||||
b,null,!0));a=null})}if(!a||!y(a))return h;d=a;d=this.encode(d);if(!d.length)return h;a=this.a;a=A(a)?a(d):d.split(L);e=a.length;var k=!0,m=[],p=t();if(1<e)if(this.depth){var n=!0;var l=a[0];p[l]=1}else a.sort(P);var r;if(!n||(r=this.f)[l])for(let b=n?1:0;b<e;b++){const c=a[b];if(c){if(!p[c]){const a=[];let b=!1,d=0;if(l=n?r[l]:this.h){let e;for(let f=0;f<10-g;f++)if(e=l[f][c])a[d++]=e,b=!0}if(b)m[m.length]=1<d?a.concat.apply([],a):a[0];else{k=!1;break}p[c]=1}l=c}}else k=!1;k&&(h=R(m,b,!1));return h}};
|
||||
g.prototype.clear=function(){this.destroy();return this.init()};g.prototype.destroy=function(){this.filter=this.stemmer=this.h=this.f=this.b=this.g=this.c=null;return this};g.prototype.export=function(){return JSON.stringify([this.h,this.f,this.b])};g.prototype.import=function(a){a=JSON.parse(a);this.h=a[0];this.f=a[1];this.b=a[2]};const w={icase:function(a){return a.toLowerCase()},simple:function(){const a=[c("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",c("[\u00e8\u00e9\u00ea\u00eb]"),"e",c("[\u00ec\u00ed\u00ee\u00ef]"),
|
||||
"i",c("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",c("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",c("[\u00fd\u0177\u00ff]"),"y",c("\u00f1"),"n",c("\u00e7"),"c",c("\u00df"),"s",c(" & ")," and ",c("[-/]")," ",c("[^a-z0-9 ]"),"",c("\\s+")," "];return function(b){b=m(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){const a=[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(b,c){if(!b)return b;b=this.simple(b);2<b.length&&(b=m(b,a));c||1<b.length&&(b=E(b));return b}}(),extra:function(){const a=[c("p"),"b",c("z"),"s",c("[cgq]"),"k",c("n"),"m",c("d"),"t",c("[vw]"),"f",c("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(let c=0;c<b.length;c++){const d=b[c];1<d.length&&(b[c]=d[0]+m(d.substring(1),a))}b=b.join(" ");b=E(b)}return b}}(),balance:function(){const a=[c("[-/]"),
|
||||
" ",c("[^a-z0-9 ]"),"",c("\\s+")," "];return function(b){return E(m(b.toLowerCase(),a))}}()},J=function(){const a=t();return function(b,c,e){const d=a[e];d&&clearTimeout(d);return a[e]=setTimeout(b,c)}}();return g}(!1),this);
|
||||
|
138
flexsearch.js
138
flexsearch.js
@@ -468,7 +468,7 @@
|
||||
// initialize primary index
|
||||
|
||||
/** @private */
|
||||
this._map = create_object_array(10);
|
||||
this._map = create_object_array(10 - (this.threshold || 0));
|
||||
/** @private */
|
||||
this._ctx = create_object();
|
||||
/** @private */
|
||||
@@ -614,9 +614,11 @@
|
||||
|
||||
if(content && is_string(content) && ((id /*&& !index_blacklist[id]*/) || (id === 0))){
|
||||
|
||||
const index = "@" + id;
|
||||
|
||||
// check if index ID already exist
|
||||
|
||||
if(this._ids[id] && !_skip_update){
|
||||
if(this._ids[index] && !_skip_update){
|
||||
|
||||
this.update(id, content);
|
||||
}
|
||||
@@ -636,7 +638,7 @@
|
||||
"content": content
|
||||
});
|
||||
|
||||
this._ids[id] = "" + this._current_task;
|
||||
this._ids[index] = "" + this._current_task;
|
||||
|
||||
// TODO: improve auto-balancing
|
||||
//this._ids_count[this._current_task]++;
|
||||
@@ -649,12 +651,12 @@
|
||||
|
||||
if(SUPPORT_ASYNC && this.async){
|
||||
|
||||
this._stack[id] || (
|
||||
this._stack[index] || (
|
||||
|
||||
this._stack_keys[this._stack_keys.length] = id
|
||||
this._stack_keys[this._stack_keys.length] = index
|
||||
);
|
||||
|
||||
this._stack[id] = [
|
||||
this._stack[index] = [
|
||||
|
||||
enum_task.add,
|
||||
id,
|
||||
@@ -808,7 +810,7 @@
|
||||
if(depth && (word_length > 1) && (score >= threshold)){
|
||||
|
||||
const ctxDupes = dupes["_ctx"][value] || (dupes["_ctx"][value] = create_object());
|
||||
const ctxTmp = this._ctx[value] || (this._ctx[value] = create_object_array(10));
|
||||
const ctxTmp = this._ctx[value] || (this._ctx[value] = create_object_array(10 - (threshold || 0)));
|
||||
|
||||
let x = i - depth;
|
||||
let y = i + depth + 1;
|
||||
@@ -838,7 +840,7 @@
|
||||
|
||||
// update status
|
||||
|
||||
this._ids[id] = 1;
|
||||
this._ids[index] = 1;
|
||||
|
||||
if(SUPPORT_CACHE){
|
||||
|
||||
@@ -863,7 +865,9 @@
|
||||
|
||||
FlexSearch.prototype.update = function(id, content){
|
||||
|
||||
if(this._ids[id] && is_string(content)){
|
||||
const index = "@" + id;
|
||||
|
||||
if(this._ids[index] && is_string(content)){
|
||||
|
||||
if(PROFILER){
|
||||
|
||||
@@ -889,11 +893,13 @@
|
||||
|
||||
FlexSearch.prototype.remove = function(id){
|
||||
|
||||
if(this._ids[id]){
|
||||
const index = "@" + id;
|
||||
|
||||
if(this._ids[index]){
|
||||
|
||||
if(SUPPORT_WORKER && this.worker){
|
||||
|
||||
const current_task = this._ids[id];
|
||||
const current_task = this._ids[index];
|
||||
|
||||
this._worker[current_task].postMessage(current_task, {
|
||||
|
||||
@@ -903,19 +909,19 @@
|
||||
|
||||
//this._ids_count[current_task]--;
|
||||
|
||||
delete this._ids[id];
|
||||
delete this._ids[index];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
if(SUPPORT_ASYNC && this.async){
|
||||
|
||||
this._stack[id] || (
|
||||
this._stack[index] || (
|
||||
|
||||
this._stack_keys[this._stack_keys.length] = id
|
||||
this._stack_keys[this._stack_keys.length] = index
|
||||
);
|
||||
|
||||
this._stack[id] = [
|
||||
this._stack[index] = [
|
||||
|
||||
enum_task.remove,
|
||||
id
|
||||
@@ -931,7 +937,7 @@
|
||||
profile_start("remove");
|
||||
}
|
||||
|
||||
for(let z = 0; z < 10; z++){
|
||||
for(let z = 0; z < (10 - (this.threshold || 0)); z++){
|
||||
|
||||
remove_index(this._map[z], id);
|
||||
}
|
||||
@@ -941,7 +947,7 @@
|
||||
remove_index(this._ctx, id);
|
||||
}
|
||||
|
||||
delete this._ids[id];
|
||||
delete this._ids[index];
|
||||
|
||||
if(SUPPORT_CACHE){
|
||||
|
||||
@@ -1177,7 +1183,7 @@
|
||||
|
||||
let map_value;
|
||||
|
||||
for(let z = 9; z >= threshold; z--){
|
||||
for(let z = 0; z < (10 - threshold); z++){
|
||||
|
||||
if((map_value = map[z][value])){
|
||||
|
||||
@@ -1278,7 +1284,7 @@
|
||||
words = 0,
|
||||
chars = 0;
|
||||
|
||||
for(let z = 0; z < 10; z++){
|
||||
for(let z = 0; z < (10 - (this.threshold || 0)); z++){
|
||||
|
||||
keys = get_keys(this._map[z]);
|
||||
|
||||
@@ -1314,7 +1320,7 @@
|
||||
"worker": this.worker,
|
||||
"threshold": this.threshold,
|
||||
"depth": this.depth,
|
||||
"contextual": !!this.depth
|
||||
"contextual": this.depth && (this.tokenize === "strict")
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1362,6 +1368,33 @@
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.prototype.export = function(){
|
||||
|
||||
return JSON.stringify([
|
||||
|
||||
this._map,
|
||||
this._ctx,
|
||||
this._ids
|
||||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.prototype.import = function(payload){
|
||||
|
||||
payload = JSON.parse(payload);
|
||||
|
||||
this._map = payload[0];
|
||||
this._ctx = payload[1];
|
||||
this._ids = payload[2];
|
||||
};
|
||||
|
||||
/** @const */
|
||||
|
||||
const global_encoder_balance = (function(){
|
||||
@@ -1612,9 +1645,9 @@
|
||||
|
||||
const stack = create_object();
|
||||
|
||||
return function(fn, delay, id){
|
||||
return function(fn, delay, key){
|
||||
|
||||
const timer = stack[id];
|
||||
const timer = stack[key];
|
||||
|
||||
if(timer){
|
||||
|
||||
@@ -1623,7 +1656,7 @@
|
||||
|
||||
return (
|
||||
|
||||
stack[id] = setTimeout(fn, delay)
|
||||
stack[key] = setTimeout(fn, delay)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1653,9 +1686,9 @@
|
||||
this.ids = [];
|
||||
};
|
||||
|
||||
Cache.prototype.set = function(id, value){
|
||||
Cache.prototype.set = function(key, value){
|
||||
|
||||
if(this.limit && is_undefined(this.cache[id])){
|
||||
if(this.limit && is_undefined(this.cache[key])){
|
||||
|
||||
let length = this.ids.length;
|
||||
|
||||
@@ -1670,18 +1703,18 @@
|
||||
delete this.index[last_id];
|
||||
}
|
||||
|
||||
this.index[id] = length;
|
||||
this.ids[length] = id;
|
||||
this.count[id] = -1;
|
||||
this.cache[id] = value;
|
||||
this.index[key] = length;
|
||||
this.ids[length] = key;
|
||||
this.count[key] = -1;
|
||||
this.cache[key] = value;
|
||||
|
||||
// shift up counter +1
|
||||
|
||||
this.get(id);
|
||||
this.get(key);
|
||||
}
|
||||
else{
|
||||
|
||||
this.cache[id] = value;
|
||||
this.cache[key] = value;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1689,15 +1722,15 @@
|
||||
* Note: It is better to have the complexity when fetching the cache:
|
||||
*/
|
||||
|
||||
Cache.prototype.get = function(id){
|
||||
Cache.prototype.get = function(key){
|
||||
|
||||
const cache = this.cache[id];
|
||||
const cache = this.cache[key];
|
||||
|
||||
if(this.limit && cache){
|
||||
|
||||
const count = ++this.count[id];
|
||||
const count = ++this.count[key];
|
||||
const index = this.index;
|
||||
let current_index = index[id];
|
||||
let current_index = index[key];
|
||||
|
||||
if(current_index > 0){
|
||||
|
||||
@@ -1728,8 +1761,8 @@
|
||||
}
|
||||
|
||||
// push new value on top
|
||||
ids[current_index] = id;
|
||||
index[id] = current_index;
|
||||
ids[current_index] = key;
|
||||
index[key] = current_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1858,7 +1891,7 @@
|
||||
|
||||
if(score >= threshold){
|
||||
|
||||
let arr = map[((score + 0.5) >> 0)];
|
||||
let arr = map[9 - ((score + 0.5) >> 0)];
|
||||
arr = arr[value] || (arr[value] = []);
|
||||
|
||||
arr[arr.length] = id;
|
||||
@@ -2187,7 +2220,7 @@
|
||||
function intersect(arrays, limit, suggest) {
|
||||
|
||||
let result = [];
|
||||
let suggestions = [];
|
||||
let suggestions;
|
||||
const length_z = arrays.length;
|
||||
|
||||
if(length_z > 1){
|
||||
@@ -2205,7 +2238,7 @@
|
||||
|
||||
while(i < length) {
|
||||
|
||||
check[arr[i++]] = 1;
|
||||
check["@" + arr[i++]] = 1;
|
||||
}
|
||||
|
||||
// loop through arrays
|
||||
@@ -2229,9 +2262,11 @@
|
||||
|
||||
tmp = arr[i++];
|
||||
|
||||
if(check[tmp]){
|
||||
const index = "@" + tmp;
|
||||
|
||||
const check_val = check[tmp];
|
||||
if(check[index]){
|
||||
|
||||
const check_val = check[index];
|
||||
|
||||
if(check_val === z){
|
||||
|
||||
@@ -2248,7 +2283,7 @@
|
||||
}
|
||||
else{
|
||||
|
||||
check[tmp] = z + 1;
|
||||
check[index] = z + 1;
|
||||
}
|
||||
|
||||
// apply count status
|
||||
@@ -2617,7 +2652,7 @@
|
||||
|
||||
runner(ref);
|
||||
|
||||
}, 1, "search-async-" + ref.id)
|
||||
}, 1, "@" + ref.id)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2814,12 +2849,15 @@
|
||||
|
||||
""
|
||||
:
|
||||
"const SUPPORT_WORKER = true;" +
|
||||
"const DEBUG = " + (DEBUG ? "true" : "false") + ";" +
|
||||
"const PROFILER = " + (PROFILER ? "true" : "false") + ";" +
|
||||
"const SUPPORT_ENCODER = " + (SUPPORT_ENCODER ? "true" : "false") + ";" +
|
||||
"const SUPPORT_CACHE = " + (SUPPORT_CACHE ? "true" : "false") + ";" +
|
||||
"const SUPPORT_ASYNC = " + (SUPPORT_ASYNC ? "true" : "false") + ";"
|
||||
"var RELEASE = '" + RELEASE + "';" +
|
||||
"var DEBUG = " + (DEBUG ? "true" : "false") + ";" +
|
||||
"var PROFILER = " + (PROFILER ? "true" : "false") + ";" +
|
||||
"var SUPPORT_PRESETS = " + (SUPPORT_PRESETS ? "true" : "false") + ";" +
|
||||
"var SUPPORT_SUGGESTIONS = " + (SUPPORT_SUGGESTIONS ? "true" : "false") + ";" +
|
||||
"var SUPPORT_ENCODER = " + (SUPPORT_ENCODER ? "true" : "false") + ";" +
|
||||
"var SUPPORT_CACHE = " + (SUPPORT_CACHE ? "true" : "false") + ";" +
|
||||
"var SUPPORT_ASYNC = " + (SUPPORT_ASYNC ? "true" : "false") + ";" +
|
||||
"var SUPPORT_WORKER = true;"
|
||||
|
||||
) + "(" + _worker.toString() + ")()"
|
||||
],{
|
||||
|
@@ -5,13 +5,14 @@
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(f,u,v){let k;(k=v.define)&&k.amd?k([],function(){return u}):(k=v.modules)?k[f.toLowerCase()]=u:"object"===typeof exports?module.exports=u:v[f]=u})("FlexSearch",function(){function f(a){a||(a=x);this.id=a.id||G++;this.init(a);u(this,"index",function(){return this.a});u(this,"length",function(){return Object.keys(this.a).length})}function u(a,b,c){Object.defineProperty(a,b,{get:c})}function v(a,b){for(let c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}function k(a,b,c,
|
||||
e,d,h,g){if(b[c])return b[c];d=d?(9-(g||6))*h+(g||6)*d:h;b[c]=d;d>=g&&(a=a[d+.5>>0],a=a[c]||(a[c]=[]),a[a.length]=e);return d}function z(a,b){if(a){const c=Object.keys(a);for(let e=0,d=c.length;e<d;e++){const d=c[e],g=a[d];if(g)for(let c=0,e=g.length;c<e;c++)if(g[c]===b){1===e?delete a[d]:g.splice(c,1);break}else"object"===typeof g[c]&&z(g[c],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 y(a){return"function"===typeof a}
|
||||
function A(a){return"undefined"===typeof a}function C(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=q();return b}function q(){return Object.create(null)}const x={encode:"icase",b:"forward",i:!1,cache:!1,async:!1,j:!1,threshold:0,depth:0},B=[];let G=0;const D=/\W+/g,E={},F={};(function(){const a=Object.getOwnPropertyNames({}.__proto__),b=q();for(let c=0;c<a.length;c++)b[a[c]]=1;return b})();f.create=function(a){return new f(a)};f.registerMatcher=function(a){for(let b in a)a.hasOwnProperty(b)&&B.push(new RegExp(b,
|
||||
"g"),a[b]);return this};f.registerEncoder=function(a,b){w[a]=b.bind(w);return this};f.registerLanguage=function(a,b){E[a]=b.filter;F[a]=b.stemmer;return this};f.encode=function(a,b){return w[a](b)};f.prototype.init=function(a){this.h=[];a||(a=x);var b=a.profile,c={};this.b=a.tokenize||c.b||this.b||x.b;this.threshold=A(b=a.threshold)?c.threshold||this.threshold||x.threshold:b;this.depth=A(b=a.depth)?c.depth||this.depth||x.depth:b;this.f=(b=A(b=a.encode)?c.encode:b)&&w[b]&&w[b].bind(w)||(y(b)?b:this.f||
|
||||
!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=E[b]||b;c=this.f;var e=q();if(b)for(let a=0;a<b.length;a++){const d=c?c(b[a]):b[a];e[d]=String.fromCharCode(65E3-b.length+a)}this.filter=b=e}if(b=a.stemmer){var d;a=F[b]||b;b=this.f;c=[];if(a)for(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=d=c}this.g=C(10);this.c=q();this.a=q();q();return this};f.prototype.encode=function(a){a&&B.length&&(a=v(a,B));a&&this.h.length&&
|
||||
(a=v(a,this.h));a&&this.f&&(a=this.f(a));a&&this.stemmer&&(a=v(a,this.stemmer));return a};f.prototype.addMatcher=function(a){const b=this.h;for(const c in a)a.hasOwnProperty(c)&&b.push(new RegExp(c,"g"),a[c]);return this};f.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.b;b=y(c)?c(b):b.split(D);const f=q();f._ctx=q();const l=this.threshold,p=this.depth,r=this.g,n=b.length;for(let t=0;t<n;t++){var e=
|
||||
b[t];if(e){var d=e.length,h=(n-t)/n,g="";switch(c){case "reverse":case "both":for(var m=d-1;1<=m;m--)g=e[m]+g,k(r,f,g,a,(d-m)/d,h,l);g="";case "forward":for(m=0;m<d;m++)g+=e[m],k(r,f,g,a,1,h,l);break;case "full":for(m=0;m<d;m++){const b=(d-m)/d;for(let c=d;c>m;c--)g=e.substring(m,c),k(r,f,g,a,b,h,l)}break;default:if(d=k(r,f,e,a,1,h,l),p&&1<n&&d>=l)for(d=f._ctx[e]||(f._ctx[e]=q()),e=this.c[e]||(this.c[e]=C(10)),h=t-p,g=t+p+1,0>h&&(h=0),g>n&&(g=n);h<g;h++)h!==t&&k(e,d,b[h],a,0,10-(h<t?t-h:h-t),l)}}}this.a[a]=
|
||||
1}return this};f.prototype.update=function(a,b){this.a[a]&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};f.prototype.remove=function(a){if(this.a[a]){for(let b=0;10>b;b++)z(this.g[b],a);this.depth&&z(this.c,a);delete this.a[a]}return this};f.prototype.search=function(a,b,c){var e=a,d=[];if("object"===typeof a){b=a.limit;var h=a.threshold;a=a.query}h||(h=this.threshold||0);y(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 d;
|
||||
e=this.encode(a);if(!e.length)return d;a=this.b;a=y(a)?a(e):e.split(D);c=a.length;var g=!0;e=[];var f=q();if(1<c)if(this.depth){var k=!0;var l=a[0];f[l]=1}else a.sort(H);var p;if(!k||(p=this.c)[l])for(var r=k?1:0;r<c;r++){var n=a[r];if(n){if(!f[n]){const a=[];let b=!1,c=0;if(l=k?p[l]:this.g){let d;for(let e=9;e>=h;e--)if(d=l[e][n])a[c++]=d,b=!0}if(b)e[e.length]=1<c?a.concat.apply([],a):a[0];else{g=!1;break}f[n]=1}l=n}}else g=!1;if(g)a:{h=[];d=e.length;if(1<d){e.sort(I);k=q();p=e[0];l=p.length;for(a=
|
||||
0;a<l;)k[p[a++]]=1;for(f=g=0;++f<d;){r=!1;n=f===d-1;p=e[f];l=p.length;for(a=0;a<l;)if(c=p[a++],k[c]&&k[c]===f){if(n){if(h[g++]=c,b&&g===b){d=h;break a}}else k[c]=f+1;r=!0}if(!r)break}}else d&&(h=e[0],b&&h.length>b&&(h=h.slice(0,b)));d=h}return d}};f.prototype.clear=function(){this.destroy();return this.init()};f.prototype.destroy=function(){this.filter=this.stemmer=this.g=this.c=this.a=null;return this};const w={icase:function(a){return a.toLowerCase()}};return f}(!1),this);
|
||||
'use strict';(function(e,u,v){let k;(k=v.define)&&k.amd?k([],function(){return u}):(k=v.modules)?k[e.toLowerCase()]=u:"object"===typeof exports?module.exports=u:v[e]=u})("FlexSearch",function(){function e(a){a||(a=x);this.id=a.id||G++;this.init(a);u(this,"index",function(){return this.a});u(this,"length",function(){return Object.keys(this.a).length})}function u(a,b,c){Object.defineProperty(a,b,{get:c})}function v(a,b){for(let c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}function k(a,b,c,
|
||||
f,d,m,g){if(b[c])return b[c];d=d?(9-(g||6))*m+(g||6)*d:m;b[c]=d;d>=g&&(a=a[9-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=f);return d}function z(a,b){if(a){const c=Object.keys(a);for(let f=0,d=c.length;f<d;f++){const d=c[f],g=a[d];if(g)for(let c=0,f=g.length;c<f;c++)if(g[c]===b){1===f?delete a[d]:g.splice(c,1);break}else"object"===typeof g[c]&&z(g[c],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 y(a){return"function"===typeof a}
|
||||
function A(a){return"undefined"===typeof a}function C(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=r();return b}function r(){return Object.create(null)}const x={encode:"icase",f:"forward",i:!1,cache:!1,async:!1,j:!1,threshold:0,depth:0},B=[];let G=0;const D=/\W+/g,E={},F={};(function(){const a=Object.getOwnPropertyNames({}.__proto__),b=r();for(let c=0;c<a.length;c++)b[a[c]]=1;return b})();e.create=function(a){return new e(a)};e.registerMatcher=function(a){for(let b in a)a.hasOwnProperty(b)&&B.push(new RegExp(b,
|
||||
"g"),a[b]);return this};e.registerEncoder=function(a,b){w[a]=b.bind(w);return this};e.registerLanguage=function(a,b){E[a]=b.filter;F[a]=b.stemmer;return this};e.encode=function(a,b){return w[a](b)};e.prototype.init=function(a){this.h=[];a||(a=x);var b=a.profile,c={};this.f=a.tokenize||c.f||this.f||x.f;this.threshold=A(b=a.threshold)?c.threshold||this.threshold||x.threshold:b;this.depth=A(b=a.depth)?c.depth||this.depth||x.depth:b;this.g=(b=A(b=a.encode)?c.encode:b)&&w[b]&&w[b].bind(w)||(y(b)?b:this.g||
|
||||
!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=E[b]||b;c=this.g;var f=r();if(b)for(let a=0;a<b.length;a++){const d=c?c(b[a]):b[a];f[d]=String.fromCharCode(65E3-b.length+a)}this.filter=b=f}if(b=a.stemmer){var d;a=F[b]||b;b=this.g;c=[];if(a)for(d in a)a.hasOwnProperty(d)&&(f=b?b(d):d,c.push(new RegExp("(?=.{"+(f.length+3)+",})"+f+"$","g"),b?b(a[d]):a[d]));this.stemmer=d=c}this.c=C(10-(this.threshold||0));this.b=r();this.a=r();r();return this};e.prototype.encode=function(a){a&&B.length&&(a=v(a,
|
||||
B));a&&this.h.length&&(a=v(a,this.h));a&&this.g&&(a=this.g(a));a&&this.stemmer&&(a=v(a,this.stemmer));return a};e.prototype.addMatcher=function(a){const b=this.h;for(const c in a)a.hasOwnProperty(c)&&b.push(new RegExp(c,"g"),a[c]);return this};e.prototype.add=function(a,b,c){if(b&&"string"===typeof b&&(a||0===a)){const e="@"+a;if(this.a[e]&&!c)this.update(a,b);else{b=this.encode(b);if(!b.length)return this;c=this.f;b=y(c)?c(b):b.split(D);const l=r();l._ctx=r();const n=this.threshold,t=this.depth,
|
||||
q=this.c,p=b.length;for(let e=0;e<p;e++){var f=b[e];if(f){var d=f.length,m=(p-e)/p,g="";switch(c){case "reverse":case "both":for(var h=d-1;1<=h;h--)g=f[h]+g,k(q,l,g,a,(d-h)/d,m,n);g="";case "forward":for(h=0;h<d;h++)g+=f[h],k(q,l,g,a,1,m,n);break;case "full":for(h=0;h<d;h++){const b=(d-h)/d;for(let c=d;c>h;c--)g=f.substring(h,c),k(q,l,g,a,b,m,n)}break;default:if(d=k(q,l,f,a,1,m,n),t&&1<p&&d>=n)for(d=l._ctx[f]||(l._ctx[f]=r()),f=this.b[f]||(this.b[f]=C(10-(n||0))),m=e-t,g=e+t+1,0>m&&(m=0),g>p&&(g=
|
||||
p);m<g;m++)m!==e&&k(f,d,b[m],a,0,10-(m<e?e-m:m-e),n)}}}this.a[e]=1}}return this};e.prototype.update=function(a,b){this.a["@"+a]&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};e.prototype.remove=function(a){const b="@"+a;if(this.a[b]){for(let b=0;b<10-(this.threshold||0);b++)z(this.c[b],a);this.depth&&z(this.b,a);delete this.a[b]}return this};e.prototype.search=function(a,b,c){var f=a,d=[];if("object"===typeof a){b=a.limit;var e=a.threshold;a=a.query}e||(e=this.threshold||0);
|
||||
y(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(c)c(this.search(f,b,null,!0));else{if(!a||"string"!==typeof a)return d;f=this.encode(a);if(!f.length)return d;a=this.f;a=y(a)?a(f):f.split(D);c=a.length;var g=!0;f=[];var h=r();if(1<c)if(this.depth){var k=!0;var l=a[0];h[l]=1}else a.sort(H);var n;if(!k||(n=this.b)[l])for(var t=k?1:0;t<c;t++){var q=a[t];if(q){if(!h[q]){var p=[];let a=!1,b=0;if(l=k?n[l]:this.c){let c;for(let d=0;d<10-e;d++)if(c=l[d][q])p[b++]=c,a=!0}if(a)f[f.length]=1<b?p.concat.apply([],p):p[0];
|
||||
else{g=!1;break}h[q]=1}l=q}}else g=!1;if(g)a:{e=[];d=f.length;if(1<d){f.sort(I);k=r();n=f[0];l=n.length;for(a=0;a<l;)k["@"+n[a++]]=1;for(h=g=0;++h<d;){t=!1;q=h===d-1;n=f[h];l=n.length;for(a=0;a<l;)if(c=n[a++],p="@"+c,k[p]&&k[p]===h){if(q){if(e[g++]=c,b&&g===b){d=e;break a}}else k[p]=h+1;t=!0}if(!t)break}}else d&&(e=f[0],b&&e.length>b&&(e=e.slice(0,b)));d=e}return d}};e.prototype.clear=function(){this.destroy();return this.init()};e.prototype.destroy=function(){this.filter=this.stemmer=this.c=this.b=
|
||||
this.a=null;return this};e.prototype.export=function(){return JSON.stringify([this.c,this.b,this.a])};e.prototype.import=function(a){a=JSON.parse(a);this.c=a[0];this.b=a[1];this.a=a[2]};const w={icase:function(a){return a.toLowerCase()}};return e}(!1),this);
|
||||
|
45
flexsearch.min.js
vendored
45
flexsearch.min.js
vendored
@@ -5,25 +5,26 @@
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(r,A,g){let v;(v=g.define)&&v.amd?v([],function(){return A}):(v=g.modules)?v[r.toLowerCase()]=A:"object"===typeof exports?module.exports=A:g[r]=A})("FlexSearch",function P(r){function g(a){C(a)&&(a=I[a]);a||(a=w);this.id=a.id||Q++;this.init(a);v(this,"index",function(){return this.a});v(this,"length",function(){return Object.keys(this.a).length})}function v(a,b,d){Object.defineProperty(a,b,{get:d})}function e(a){return new RegExp(a,"g")}function x(a,b){for(let d=0;d<b.length;d+=
|
||||
2)a=a.replace(b[d],b[d+1]);return a}function y(a,b,d,c,f,l,h){if(b[d])return b[d];f=f?(9-(h||6))*l+(h||6)*f:l;b[d]=f;f>=h&&(a=a[f+.5>>0],a=a[d]||(a[d]=[]),a[a.length]=c);return f}function p(a,b){if(a){const d=Object.keys(a);for(let c=0,f=d.length;c<f;c++){const f=d[c],h=a[f];if(h)for(let c=0,d=h.length;c<d;c++)if(h[c]===b){1===d?delete a[f]:h.splice(c,1);break}else"object"===typeof h[c]&&p(h[c],b)}}}function F(a){let b="",d="";var c="";for(let f=0;f<a.length;f++){const l=a[f];if(l!==d)if(f&&"h"===
|
||||
l){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d)&&c||" "===d)b+=l}else b+=l;c=f===a.length-1?"":a[f+1];d=l}return b}function S(a,b){const d=q();if(a)for(let c=0;c<a.length;c++){const f=b?b(a[c]):a[c];d[f]=String.fromCharCode(65E3-a.length+c)}return d}function T(a,b){const d=[];if(a)for(const c in a)if(a.hasOwnProperty(c)){const f=b?b(c):c;d.push(e("(?=.{"+(f.length+3)+",})"+f+"$"),b?b(a[c]):a[c])}return d}function U(a,b){a=a.length-
|
||||
b.length;return 0>a?1:a?-1:0}function V(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function W(a,b,d){let c=[],f=[];const l=a.length;if(1<l){a.sort(V);const u=q();let e=a[0],g=e.length,t=0;for(;t<g;)u[e[t++]]=1;let n,m=0,k=0;for(;++k<l;){let J=!1;const R=k===l-1;f=[];e=a[k];g=e.length;for(t=0;t<g;)if(n=e[t++],u[n]){var h=u[n];if(h===k){if(R){if(c[m++]=n,b&&m===b)return c}else u[n]=k+1;J=!0}else d&&(h=f[h]||(f[h]=[]),h[h.length]=n)}if(!J&&!d)break}if(d&&(m=c.length,(k=f.length)&&(!b||m<b)))for(;k--;)if(n=
|
||||
f[k])for(let a=0,d=n.length;a<d;a++)if(c[m++]=n[a],b&&m===b)return c}else l&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function C(a){return"string"===typeof a}function D(a){return"function"===typeof a}function z(a){return"undefined"===typeof a}function G(a){a.D||(a.D=K(function(){a.D=0;{const b=a.async;let d;b&&(a.async=!1);if(a.f.length){const b=Date.now();let f;for(;(f=a.f.shift())||0===f;){d=a.g[f];switch(d[0]){case E.add:a.add(d[1],d[2]);break;case E.remove:a.remove(d[1])}delete a.g[f];
|
||||
if(100<Date.now()-b)break}a.f.length&&G(a)}b&&(a.async=b)}},1,"search-async-"+a.id))}function L(a){const b=Array(a);for(let d=0;d<a;d++)b[d]=q();return b}function q(){return Object.create(null)}function X(a,b,d,c){a=r("flexsearch","id"+a,function(){let a,b;self.onmessage=function(c){if(c=c.data)if(c.search){const d=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:d})}else c.add?b.add(c.id,c.content):c.update?
|
||||
b.update(c.id,c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.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);const f=P.toString();d.id=b;a.postMessage(b,{register:f,options:d,id:b});return a}const w={encode:"icase",b:"forward",u:!1,cache:!1,async:!1,c:!1,threshold:0,depth:0},
|
||||
I={memory:{encode:"extra",b:"strict",threshold:7},speed:{encode:"icase",b:"strict",threshold:7,depth:2},match:{encode:"extra",b:"full"},score:{encode:"extra",b:"strict",threshold:5,depth:4},balance:{encode:"balance",b:"strict",threshold:6,depth:3},fastest:{encode:"icase",b:"strict",threshold:9,depth:1}},H=[];let Q=0;const E={add:0,update:1,remove:2},M=e("\\W+"),N={},O={};(function(){const a=Object.getOwnPropertyNames({}.__proto__),b=q();for(let d=0;d<a.length;d++)b[a[d]]=1;return b})();g.create=function(a){return new g(a)};
|
||||
g.registerMatcher=function(a){for(let b in a)a.hasOwnProperty(b)&&H.push(e(b),a[b]);return this};g.registerEncoder=function(a,b){B[a]=b.bind(B);return this};g.registerLanguage=function(a,b){N[a]=b.filter;O[a]=b.stemmer;return this};g.encode=function(a,b){return B[a](b)};g.prototype.init=function(a){this.C=[];a||(a=w);let b=a.profile;const d=b?I[b]:{};if(b=a.worker)if(Worker){const c=this,d=parseInt(b,10)||4;c.m=-1;c.o=0;c.h=[];c.B=null;c.j=Array(d);for(let b=0;b<d;b++)c.j[b]=X(c.id,b,a,function(a,
|
||||
b,d,f){if(c.o!==c.c)return c.h=c.h.concat(d),c.o++,f&&c.h.length>=f&&(c.o=c.c),c.B&&c.o===c.c&&(c.cache&&c.i.set(b,c.h),c.B(c.h),c.h=[]),c})}else a.worker=!1,this.j=null;this.b=a.tokenize||d.b||this.b||w.b;this.async=z(b=a.async)?this.async||w.async:b;this.c=z(b=a.worker)?this.c||w.c:b;this.threshold=z(b=a.threshold)?d.threshold||this.threshold||w.threshold:b;this.depth=z(b=a.depth)?d.depth||this.depth||w.depth:b;this.u=z(b=a.suggest)?this.u||w.u:b;this.s=(b=z(b=a.encode)?d.encode:b)&&B[b]&&B[b].bind(B)||
|
||||
(D(b)?b:this.s||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=S(N[b]||b,this.s);if(b=a.stemmer)this.stemmer=T(O[b]||b,this.s);this.w=L(10);this.l=q();this.a=q();this.g=q();this.f=[];this.D=0;this.v=!0;this.i=(this.cache=b=z(b=a.cache)?this.cache||w.cache:b)?new Y(b):!1;return this};g.prototype.encode=function(a){a&&H.length&&(a=x(a,H));a&&this.C.length&&(a=x(a,this.C));a&&this.s&&(a=this.s(a));a&&this.stemmer&&(a=x(a,this.stemmer));return a};g.prototype.addMatcher=function(a){const b=
|
||||
this.C;for(const d in a)a.hasOwnProperty(d)&&b.push(e(d),a[d]);return this};g.prototype.add=function(a,b,d){if(b&&C(b)&&(a||0===a))if(this.a[a]&&!d)this.update(a,b);else{if(this.c)return++this.m>=this.j.length&&(this.m=0),this.j[this.m].postMessage(this.m,{add:!0,id:a,content:b}),this.a[a]=""+this.m,this;if(this.async)return this.g[a]||(this.f[this.f.length]=a),this.g[a]=[E.add,a,b],G(this),this;b=this.encode(b);if(!b.length)return this;d=this.b;b=D(d)?d(b):b.split(M);const l=q();l._ctx=q();const u=
|
||||
this.threshold,t=this.depth,n=this.w,m=b.length;for(let k=0;k<m;k++){var c=b[k];if(c){var f=c.length,e=(m-k)/m,h="";switch(d){case "reverse":case "both":for(var g=f-1;1<=g;g--)h=c[g]+h,y(n,l,h,a,(f-g)/f,e,u);h="";case "forward":for(g=0;g<f;g++)h+=c[g],y(n,l,h,a,1,e,u);break;case "full":for(g=0;g<f;g++){const b=(f-g)/f;for(let d=f;d>g;d--)h=c.substring(g,d),y(n,l,h,a,b,e,u)}break;default:if(f=y(n,l,c,a,1,e,u),t&&1<m&&f>=u)for(f=l._ctx[c]||(l._ctx[c]=q()),c=this.l[c]||(this.l[c]=L(10)),e=k-t,h=k+t+
|
||||
1,0>e&&(e=0),h>m&&(h=m);e<h;e++)e!==k&&y(c,f,b[e],a,0,10-(e<k?k-e:e-k),u)}}}this.a[a]=1;this.v=!1}return this};g.prototype.update=function(a,b){this.a[a]&&C(b)&&(this.remove(a),this.add(a,b,!0));return this};g.prototype.remove=function(a){if(this.a[a]){if(this.c){var b=this.a[a];this.j[b].postMessage(b,{remove:!0,id:a});delete this.a[a];return this}if(this.async)return this.g[a]||(this.f[this.f.length]=a),this.g[a]=[E.remove,a],G(this),this;for(b=0;10>b;b++)p(this.w[b],a);this.depth&&p(this.l,a);
|
||||
delete this.a[a];this.v=!1}return this};g.prototype.search=function(a,b,d,c){let f=a,e;var h=[];"object"===typeof a&&((d=a.callback||b)&&(f.callback=null),b=a.limit,e=a.threshold,a=a.query);e||(e=this.threshold||0);D(b)?(d=b,b=1E3):b||0===b||(b=1E3);if(this.c)for(this.B=d,this.o=0,this.h=[],h=0;h<this.c;h++)this.j[h].postMessage(h,{search:!0,limit:b,threshold:e,content:a});else if(d){{let a=this;K(function(){d(a.search(f,b,null,!0));a=null},1,"search-"+this.id)}}else{if(!c&&this.async&&"function"!==
|
||||
typeof importScripts){let a=this;return new Promise(function(c){c(a.search(f,b,null,!0));a=null})}if(!a||!C(a))return h;f=a;if(this.cache)if(this.v){if(c=this.i.get(a))return c}else this.i.clear(),this.v=!0;f=this.encode(f);if(!f.length)return h;c=this.b;c=D(c)?c(f):f.split(M);var g=c.length,p=!0,r=[],t=q();if(1<g)if(this.depth){var n=!0;var m=c[0];t[m]=1}else c.sort(U);var k;if(!n||(k=this.l)[m])for(let a=n?1:0;a<g;a++){const b=c[a];if(b){if(!t[b]){const a=[];let c=!1,d=0;if(m=n?k[m]:this.w){let f;
|
||||
for(let h=9;h>=e;h--)if(f=m[h][b])a[d++]=f,c=!0}if(c)r[r.length]=1<d?a.concat.apply([],a):a[0];else if(!this.u){p=!1;break}t[b]=1}m=b}}else p=!1;p&&(h=W(r,b,this.u));this.cache&&this.i.set(a,h);return h}};g.prototype.clear=function(){this.destroy();return this.init()};g.prototype.destroy=function(){this.cache&&(this.i.clear(),this.i=null);this.filter=this.stemmer=this.w=this.l=this.a=this.g=this.f=null;return this};const B={icase:function(a){return a.toLowerCase()},simple:function(){const a=[e("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),
|
||||
"a",e("[\u00e8\u00e9\u00ea\u00eb]"),"e",e("[\u00ec\u00ed\u00ee\u00ef]"),"i",e("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",e("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",e("[\u00fd\u0177\u00ff]"),"y",e("\u00f1"),"n",e("\u00e7"),"c",e("\u00df"),"s",e(" & ")," and ",e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s+")," "];return function(b){b=x(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){const a=[e("ae"),"a",e("ai"),"ei",e("ay"),"ei",e("ey"),"ei",e("oe"),"o",e("ue"),"u",e("ie"),"i",e("sz"),"s",
|
||||
e("zs"),"s",e("sh"),"s",e("ck"),"k",e("cc"),"k",e("dt"),"t",e("ph"),"f",e("pf"),"f",e("ou"),"o",e("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=F(b));return b}}(),extra:function(){const a=[e("p"),"b",e("z"),"s",e("[cgq]"),"k",e("n"),"m",e("d"),"t",e("[vw]"),"f",e("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(let d=0;d<b.length;d++){const c=b[d];1<c.length&&(b[d]=c[0]+x(c.substring(1),
|
||||
a))}b=b.join(" ");b=F(b)}return b}}(),balance:function(){const a=[e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s+")," "];return function(b){return F(x(b.toLowerCase(),a))}}()},K=function(){const a=q();return function(b,d,c){const f=a[c];f&&clearTimeout(f);return a[c]=setTimeout(b,d)}}(),Y=function(){function a(a){this.clear();this.A=!0!==a&&a}a.prototype.clear=function(){this.cache=q();this.count=q();this.index=q();this.a=[]};a.prototype.set=function(a,d){if(this.A&&z(this.cache[a])){let b=this.a.length;
|
||||
if(b===this.A){b--;const a=this.a[b];delete this.cache[a];delete this.count[a];delete this.index[a]}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){const b=this.cache[a];if(this.A&&b){var c=++this.count[a];const b=this.index;let d=b[a];if(0<d){const e=this.a;for(var f=d;this.count[e[--d]]<=c&&-1!==d;);d++;if(d!==f){for(c=f;c>d;c--)f=e[c-1],e[c]=f,b[f]=c;e[d]=a;b[a]=d}}}return b};return a}();return g}(function(){const r={},
|
||||
A="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(g,v,e,x,y){let p=g;g=A?URL.createObjectURL(new Blob(["("+e.toString()+")()"],{type:"text/javascript"})):p+".min.js";p+="-"+v;r[p]||(r[p]=[]);r[p][y]=new Worker(g);r[p][y].onmessage=x;return{postMessage:function(e,g){r[p][e].postMessage(g)}}}}()),this);
|
||||
'use strict';(function(t,A,g){let v;(v=g.define)&&v.amd?v([],function(){return A}):(v=g.modules)?v[t.toLowerCase()]=A:"object"===typeof exports?module.exports=A:g[t]=A})("FlexSearch",function P(t){function g(a){C(a)&&(a=I[a]);a||(a=w);this.id=a.id||Q++;this.init(a);v(this,"index",function(){return this.a});v(this,"length",function(){return Object.keys(this.a).length})}function v(a,b,d){Object.defineProperty(a,b,{get:d})}function e(a){return new RegExp(a,"g")}function x(a,b){for(let d=0;d<b.length;d+=
|
||||
2)a=a.replace(b[d],b[d+1]);return a}function y(a,b,d,c,f,k,h){if(b[d])return b[d];f=f?(9-(h||6))*k+(h||6)*f:k;b[d]=f;f>=h&&(a=a[9-(f+.5>>0)],a=a[d]||(a[d]=[]),a[a.length]=c);return f}function q(a,b){if(a){const d=Object.keys(a);for(let c=0,f=d.length;c<f;c++){const f=d[c],h=a[f];if(h)for(let c=0,d=h.length;c<d;c++)if(h[c]===b){1===d?delete a[f]:h.splice(c,1);break}else"object"===typeof h[c]&&q(h[c],b)}}}function F(a){let b="",d="";var c="";for(let f=0;f<a.length;f++){const k=a[f];if(k!==d)if(f&&"h"===
|
||||
k){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d)&&c||" "===d)b+=k}else b+=k;c=f===a.length-1?"":a[f+1];d=k}return b}function R(a,b){const d=n();if(a)for(let c=0;c<a.length;c++){const f=b?b(a[c]):a[c];d[f]=String.fromCharCode(65E3-a.length+c)}return d}function S(a,b){const d=[];if(a)for(const c in a)if(a.hasOwnProperty(c)){const f=b?b(c):c;d.push(e("(?=.{"+(f.length+3)+",})"+f+"$"),b?b(a[c]):a[c])}return d}function T(a,b){a=a.length-
|
||||
b.length;return 0>a?1:a?-1:0}function U(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function V(a,b,d){let c=[],f;const k=a.length;if(1<k){a.sort(U);const u=n();let e=a[0],g=e.length,p=0;for(;p<g;)u["@"+e[p++]]=1;let r,l=0,m=0;for(;++m<k;){let J=!1;const n=m===k-1;f=[];e=a[m];g=e.length;for(p=0;p<g;){r=e[p++];var h="@"+r;if(u[h]){const a=u[h];if(a===m){if(n){if(c[l++]=r,b&&l===b)return c}else u[h]=m+1;J=!0}else d&&(h=f[a]||(f[a]=[]),h[h.length]=r)}}if(!J&&!d)break}if(d&&(l=c.length,(m=f.length)&&
|
||||
(!b||l<b)))for(;m--;)if(r=f[m])for(let a=0,d=r.length;a<d;a++)if(c[l++]=r[a],b&&l===b)return c}else k&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function C(a){return"string"===typeof a}function D(a){return"function"===typeof a}function z(a){return"undefined"===typeof a}function G(a){a.D||(a.D=K(function(){a.D=0;{const b=a.async;let d;b&&(a.async=!1);if(a.f.length){const b=Date.now();let f;for(;(f=a.f.shift())||0===f;){d=a.h[f];switch(d[0]){case E.add:a.add(d[1],d[2]);break;case E.remove:a.remove(d[1])}delete a.h[f];
|
||||
if(100<Date.now()-b)break}a.f.length&&G(a)}b&&(a.async=b)}},1,"@"+a.id))}function L(a){const b=Array(a);for(let d=0;d<a;d++)b[d]=n();return b}function n(){return Object.create(null)}function W(a,b,d,c){a=t("flexsearch","id"+a,function(){let a,b;self.onmessage=function(c){if(c=c.data)if(c.search){const d=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:d})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,
|
||||
c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.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);const f=P.toString();d.id=b;a.postMessage(b,{register:f,options:d,id:b});return a}const w={encode:"icase",b:"forward",v:!1,cache:!1,async:!1,c:!1,threshold:0,depth:0},I={memory:{encode:"extra",
|
||||
b:"strict",threshold:7},speed:{encode:"icase",b:"strict",threshold:7,depth:2},match:{encode:"extra",b:"full"},score:{encode:"extra",b:"strict",threshold:5,depth:4},balance:{encode:"balance",b:"strict",threshold:6,depth:3},fastest:{encode:"icase",b:"strict",threshold:9,depth:1}},H=[];let Q=0;const E={add:0,update:1,remove:2},M=e("\\W+"),N={},O={};(function(){const a=Object.getOwnPropertyNames({}.__proto__),b=n();for(let d=0;d<a.length;d++)b[a[d]]=1;return b})();g.create=function(a){return new g(a)};
|
||||
g.registerMatcher=function(a){for(let b in a)a.hasOwnProperty(b)&&H.push(e(b),a[b]);return this};g.registerEncoder=function(a,b){B[a]=b.bind(B);return this};g.registerLanguage=function(a,b){N[a]=b.filter;O[a]=b.stemmer;return this};g.encode=function(a,b){return B[a](b)};g.prototype.init=function(a){this.C=[];a||(a=w);let b=a.profile;const d=b?I[b]:{};if(b=a.worker)if(Worker){const c=this,d=parseInt(b,10)||4;c.o=-1;c.s=0;c.i=[];c.B=null;c.m=Array(d);for(let b=0;b<d;b++)c.m[b]=W(c.id,b,a,function(a,
|
||||
b,d,f){if(c.s!==c.c)return c.i=c.i.concat(d),c.s++,f&&c.i.length>=f&&(c.s=c.c),c.B&&c.s===c.c&&(c.cache&&c.j.set(b,c.i),c.B(c.i),c.i=[]),c})}else a.worker=!1,this.m=null;this.b=a.tokenize||d.b||this.b||w.b;this.async=z(b=a.async)?this.async||w.async:b;this.c=z(b=a.worker)?this.c||w.c:b;this.threshold=z(b=a.threshold)?d.threshold||this.threshold||w.threshold:b;this.depth=z(b=a.depth)?d.depth||this.depth||w.depth:b;this.v=z(b=a.suggest)?this.v||w.v:b;this.u=(b=z(b=a.encode)?d.encode:b)&&B[b]&&B[b].bind(B)||
|
||||
(D(b)?b:this.u||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=R(N[b]||b,this.u);if(b=a.stemmer)this.stemmer=S(O[b]||b,this.u);this.l=L(10-(this.threshold||0));this.g=n();this.a=n();this.h=n();this.f=[];this.D=0;this.w=!0;this.j=(this.cache=b=z(b=a.cache)?this.cache||w.cache:b)?new X(b):!1;return this};g.prototype.encode=function(a){a&&H.length&&(a=x(a,H));a&&this.C.length&&(a=x(a,this.C));a&&this.u&&(a=this.u(a));a&&this.stemmer&&(a=x(a,this.stemmer));return a};g.prototype.addMatcher=
|
||||
function(a){const b=this.C;for(const d in a)a.hasOwnProperty(d)&&b.push(e(d),a[d]);return this};g.prototype.add=function(a,b,d){if(b&&C(b)&&(a||0===a)){const k="@"+a;if(this.a[k]&&!d)this.update(a,b);else{if(this.c)return++this.o>=this.m.length&&(this.o=0),this.m[this.o].postMessage(this.o,{add:!0,id:a,content:b}),this.a[k]=""+this.o,this;if(this.async)return this.h[k]||(this.f[this.f.length]=k),this.h[k]=[E.add,a,b],G(this),this;b=this.encode(b);if(!b.length)return this;d=this.b;b=D(d)?d(b):b.split(M);
|
||||
const u=n();u._ctx=n();const p=this.threshold,r=this.depth,l=this.l,m=b.length;for(let k=0;k<m;k++){var c=b[k];if(c){var f=c.length,e=(m-k)/m,h="";switch(d){case "reverse":case "both":for(var g=f-1;1<=g;g--)h=c[g]+h,y(l,u,h,a,(f-g)/f,e,p);h="";case "forward":for(g=0;g<f;g++)h+=c[g],y(l,u,h,a,1,e,p);break;case "full":for(g=0;g<f;g++){const b=(f-g)/f;for(let d=f;d>g;d--)h=c.substring(g,d),y(l,u,h,a,b,e,p)}break;default:if(f=y(l,u,c,a,1,e,p),r&&1<m&&f>=p)for(f=u._ctx[c]||(u._ctx[c]=n()),c=this.g[c]||
|
||||
(this.g[c]=L(10-(p||0))),e=k-r,h=k+r+1,0>e&&(e=0),h>m&&(h=m);e<h;e++)e!==k&&y(c,f,b[e],a,0,10-(e<k?k-e:e-k),p)}}}this.a[k]=1;this.w=!1}}return this};g.prototype.update=function(a,b){this.a["@"+a]&&C(b)&&(this.remove(a),this.add(a,b,!0));return this};g.prototype.remove=function(a){const b="@"+a;if(this.a[b]){if(this.c){var d=this.a[b];this.m[d].postMessage(d,{remove:!0,id:a});delete this.a[b];return this}if(this.async)return this.h[b]||(this.f[this.f.length]=b),this.h[b]=[E.remove,a],G(this),this;
|
||||
for(d=0;d<10-(this.threshold||0);d++)q(this.l[d],a);this.depth&&q(this.g,a);delete this.a[b];this.w=!1}return this};g.prototype.search=function(a,b,d,c){let f=a,e;var h=[];"object"===typeof a&&((d=a.callback||b)&&(f.callback=null),b=a.limit,e=a.threshold,a=a.query);e||(e=this.threshold||0);D(b)?(d=b,b=1E3):b||0===b||(b=1E3);if(this.c)for(this.B=d,this.s=0,this.i=[],h=0;h<this.c;h++)this.m[h].postMessage(h,{search:!0,limit:b,threshold:e,content:a});else if(d){{let a=this;K(function(){d(a.search(f,
|
||||
b,null,!0));a=null},1,"search-"+this.id)}}else{if(!c&&this.async&&"function"!==typeof importScripts){let a=this;return new Promise(function(c){c(a.search(f,b,null,!0));a=null})}if(!a||!C(a))return h;f=a;if(this.cache)if(this.w){if(c=this.j.get(a))return c}else this.j.clear(),this.w=!0;f=this.encode(f);if(!f.length)return h;c=this.b;c=D(c)?c(f):f.split(M);var g=c.length,q=!0,t=[],p=n();if(1<g)if(this.depth){var r=!0;var l=c[0];p[l]=1}else c.sort(T);var m;if(!r||(m=this.g)[l])for(let a=r?1:0;a<g;a++){const b=
|
||||
c[a];if(b){if(!p[b]){const a=[];let c=!1,d=0;if(l=r?m[l]:this.l){let f;for(let h=0;h<10-e;h++)if(f=l[h][b])a[d++]=f,c=!0}if(c)t[t.length]=1<d?a.concat.apply([],a):a[0];else if(!this.v){q=!1;break}p[b]=1}l=b}}else q=!1;q&&(h=V(t,b,this.v));this.cache&&this.j.set(a,h);return h}};g.prototype.clear=function(){this.destroy();return this.init()};g.prototype.destroy=function(){this.cache&&(this.j.clear(),this.j=null);this.filter=this.stemmer=this.l=this.g=this.a=this.h=this.f=null;return this};g.prototype.export=
|
||||
function(){return JSON.stringify([this.l,this.g,this.a])};g.prototype.import=function(a){a=JSON.parse(a);this.l=a[0];this.g=a[1];this.a=a[2]};const B={icase:function(a){return a.toLowerCase()},simple:function(){const a=[e("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",e("[\u00e8\u00e9\u00ea\u00eb]"),"e",e("[\u00ec\u00ed\u00ee\u00ef]"),"i",e("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",e("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",e("[\u00fd\u0177\u00ff]"),"y",e("\u00f1"),"n",e("\u00e7"),"c",e("\u00df"),
|
||||
"s",e(" & ")," and ",e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s+")," "];return function(b){b=x(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){const a=[e("ae"),"a",e("ai"),"ei",e("ay"),"ei",e("ey"),"ei",e("oe"),"o",e("ue"),"u",e("ie"),"i",e("sz"),"s",e("zs"),"s",e("sh"),"s",e("ck"),"k",e("cc"),"k",e("dt"),"t",e("ph"),"f",e("pf"),"f",e("ou"),"o",e("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=F(b));return b}}(),extra:function(){const a=
|
||||
[e("p"),"b",e("z"),"s",e("[cgq]"),"k",e("n"),"m",e("d"),"t",e("[vw]"),"f",e("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(let d=0;d<b.length;d++){const c=b[d];1<c.length&&(b[d]=c[0]+x(c.substring(1),a))}b=b.join(" ");b=F(b)}return b}}(),balance:function(){const a=[e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s+")," "];return function(b){return F(x(b.toLowerCase(),a))}}()},K=function(){const a=n();return function(b,d,c){const f=a[c];f&&clearTimeout(f);
|
||||
return a[c]=setTimeout(b,d)}}(),X=function(){function a(a){this.clear();this.A=!0!==a&&a}a.prototype.clear=function(){this.cache=n();this.count=n();this.index=n();this.a=[]};a.prototype.set=function(a,d){if(this.A&&z(this.cache[a])){let b=this.a.length;if(b===this.A){b--;const a=this.a[b];delete this.cache[a];delete this.count[a];delete this.index[a]}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){const b=this.cache[a];if(this.A&&
|
||||
b){var c=++this.count[a];const b=this.index;let d=b[a];if(0<d){const e=this.a;for(var f=d;this.count[e[--d]]<=c&&-1!==d;);d++;if(d!==f){for(c=f;c>d;c--)f=e[c-1],e[c]=f,b[f]=c;e[d]=a;b[a]=d}}}return b};return a}();return g}(function(){const t={},A="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(g,v,e,x,y){let q=g;g=A?URL.createObjectURL(new Blob(["("+e.toString()+")()"],{type:"text/javascript"})):q+".min.js";q+="-"+v;t[q]||(t[q]=[]);t[q][y]=new Worker(g);t[q][y].onmessage=
|
||||
x;return{postMessage:function(e,g){t[q][e].postMessage(g)}}}}()),this);
|
||||
|
@@ -22,7 +22,7 @@
|
||||
<hr>
|
||||
<div id="container"></div>
|
||||
<hr>
|
||||
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.compact.js"></script>
|
||||
<script src="../flexsearch.compact.js"></script>
|
||||
<script src="../data/gulliver.js"></script>
|
||||
<script>
|
||||
|
||||
|
@@ -23,7 +23,7 @@
|
||||
<div id="container"></div>
|
||||
<hr>
|
||||
Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least 7 matches for the query "gulliver", 4. result should be ordered by relevance
|
||||
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.light.js"></script>
|
||||
<script src="../flexsearch.light.js"></script>
|
||||
<script src="https://rawgit.com/nextapps-de/bulksearch/master/bulksearch.light.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/elasticlunr/0.9.6/elasticlunr.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/olivernn/lunr.js@2.3.5/lunr.min.js"></script>
|
||||
@@ -346,7 +346,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
"<th>Library </th>" +
|
||||
"<th>Benchmark (Single Phrase) </th>" +
|
||||
"<th>Benchmark (Multi Phrase) </th>" +
|
||||
"<th>Benchmark (Mixed Not Found) </th>" +
|
||||
"<th>Benchmark (Not Found) </th>" +
|
||||
"</tr>";
|
||||
|
||||
for(var test in tests){
|
||||
|
@@ -5,32 +5,32 @@
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';function H(g){var h=0;return function(){return h<g.length?{done:!1,value:g[h++]}:{done:!0}}}function I(g){var h="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return h?h.call(g):{next:H(g)}}var Q="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,R="function"==typeof Object.defineProperties?Object.defineProperty:function(g,h,e){g!=Array.prototype&&g!=Object.prototype&&(g[h]=e.value)};
|
||||
function S(g,h){if(h){var e=Q;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&&R(e,g,{configurable:!0,writable:!0,value:h})}}
|
||||
S("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(t){a.reject(t)}}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=Q.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(z){this.f(z)}}}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.s),reject:d(this.f)}};h.prototype.s=function(d){if(d===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(d instanceof h)this.u(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.o(d):this.j(d)}};
|
||||
h.prototype.o=function(a){var d=void 0;try{d=a.then}catch(t){this.f(t);return}"function"==typeof d?this.v(d,a):this.j(a)};h.prototype.f=function(a){this.l(2,a)};h.prototype.j=function(a){this.l(1,a)};h.prototype.l=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.m()};h.prototype.m=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.u=function(a){var d=this.c();
|
||||
a.A(d.resolve,d.reject)};h.prototype.v=function(a,h){var d=this.c();try{a.call(h,d.resolve,d.reject)}catch(z){d.reject(z)}};h.prototype.then=function(a,e){function d(a,d){return"function"==typeof a?function(d){try{g(a(d))}catch(C){k(C)}}:d}var g,k,m=new h(function(a,d){g=a;k=d});this.A(d(a,g),d(e,k));return m};h.prototype.catch=function(a){return this.then(void 0,a)};h.prototype.A=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=I(a),g=e.next();!g.done;g=e.next())k(g.value).A(d,h)})};h.all=function(a){var d=I(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).A(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 X(g){function e(b){F(b)&&(b=J[b]);b||(b=x);this.id=b.id||Y++;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,d,K,e){if(c[a])return c[a];d=d?(9-(e||6))*K+(e||6)*d:K;c[a]=d;d>=e&&(b=b[d+.5>>0],b=b[a]||(b[a]=[]),b[b.length]=f);return d}function m(b,c){if(b)for(var a=Object.keys(b),f=0,d=a.length;f<d;f++){var e=a[f],g=b[e];if(g)for(var r=0,k=g.length;r<k;r++)if(g[r]===c){1===k?delete b[e]:g.splice(r,1);break}else"object"===typeof g[r]&&m(g[r],c)}}function t(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 z(b,c){var a=w();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 T(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 U(b,c){b=b.length-
|
||||
c.length;return 0>b?-1:b?1:0}function V(b,c,a){var f=[],d=[],e=b.length;if(1<e){b.sort(U);for(var g=w(),r=b[0],u=r.length,k=0;k<u;)g[r[k++]]=1;for(var n,p=0,q=0;++q<e;){var v=!1,m=q===e-1;d=[];r=b[q];u=r.length;for(k=0;k<u;)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;v=!0}else a&&(l=d[l]||(d[l]=[]),l[l.length]=n)}if(!v&&!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 F(b){return"string"===typeof b}function C(b){return"function"===typeof b}function y(b){return"undefined"===typeof b}function D(b){b.F||(b.F=L(function(){b.F=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 B.add:b.add(d[1],d[2]);break;case B.remove:b.remove(d[1])}delete b.c[f];if(100<Date.now()-a)break}b.b.length&&D(b)}c&&(b.async=c)},1,"search-async-"+b.id))}function M(b){for(var c=
|
||||
Array(b),a=0;a<b;a++)c[a]=w();return c}function w(){return Object.create(null)}function Z(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=X.toString();a.id=c;b.postMessage(c,{register:d,options:a,id:c});return b}var x={encode:"icase",h:"forward",w:!1,cache:!1,async:!1,i:!1,threshold:0,depth:0},J={memory:{encode:"extra",h:"strict",threshold:7},speed:{encode:"icase",h:"strict",threshold:7,depth:2},match:{encode:"extra",
|
||||
h:"full"},score:{encode:"extra",h:"strict",threshold:5,depth:4},balance:{encode:"balance",h:"strict",threshold:6,depth:3},fastest:{encode:"icase",h:"strict",threshold:9,depth:1}},E=[],Y=0,B={add:0,update:1,remove:2},N=a("\\W+"),O={},P={};(function(){for(var b=Object.getOwnPropertyNames({}.__proto__),c=w(),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)&&E.push(a(c),b[c]);return this};e.registerEncoder=
|
||||
function(b,c){A[b]=c.bind(A);return this};e.registerLanguage=function(b,c){O[b]=c.filter;P[b]=c.stemmer;return this};e.encode=function(b,c){return A[b](c)};e.prototype.init=function(b){this.D=[];b||(b=x);var c=b.profile,a=c?J[c]:{};if(c=b.worker)if(Worker){var f=this,d=parseInt(c,10)||4;f.m=-1;f.o=0;f.f=[];f.C=null;f.j=Array(d);for(var e=0;e<d;e++)f.j[e]=Z(f.id,e,b,function(b,c,a,d){if(f.o!==f.i)return f.f=f.f.concat(a),f.o++,d&&f.f.length>=d&&(f.o=f.i),f.C&&f.o===f.i&&(f.cache&&f.g.set(c,f.f),f.C(f.f),
|
||||
f.f=[]),f})}else b.worker=!1,this.j=null;this.h=b.tokenize||a.h||this.h||x.h;this.async=y(c=b.async)?this.async||x.async:c;this.i=y(c=b.worker)?this.i||x.i:c;this.threshold=y(c=b.threshold)?a.threshold||this.threshold||x.threshold:c;this.depth=y(c=b.depth)?a.depth||this.depth||x.depth:c;this.w=y(c=b.suggest)?this.w||x.w:c;this.s=(c=y(c=b.encode)?a.encode:c)&&A[c]&&A[c].bind(A)||(C(c)?c:this.s||!1);(c=b.matcher)&&this.addMatcher(c);if(c=b.filter)this.filter=z(O[c]||c,this.s);if(c=b.stemmer)this.stemmer=
|
||||
T(P[c]||c,this.s);this.v=M(10);this.l=w();this.a=w();this.c=w();this.b=[];this.F=0;this.u=!0;this.g=(this.cache=c=y(c=b.cache)?this.cache||x.cache:c)?new aa(c):!1;return this};e.prototype.encode=function(b){b&&E.length&&(b=l(b,E));b&&this.D.length&&(b=l(b,this.D));b&&this.s&&(b=this.s(b));b&&this.stemmer&&(b=l(b,this.stemmer));return b};e.prototype.addMatcher=function(b){var c=this.D,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&&F(c)&&(b||0===
|
||||
b))if(this.a[b]&&!a)this.update(b,c);else{if(this.i)return++this.m>=this.j.length&&(this.m=0),this.j[this.m].postMessage(this.m,{add:!0,id:b,content:c}),this.a[b]=""+this.m,this;if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[B.add,b,c],D(this),this;c=this.encode(c);if(!c.length)return this;a=this.h;c=C(a)?a(c):c.split(N);var f=w();f._ctx=w();for(var e=this.threshold,g=this.depth,k=this.v,r=c.length,u=0;u<r;u++){var l=c[u];if(l){var n=l.length,p=(r-u)/r,q="";switch(a){case "reverse":case "both":for(var v=
|
||||
n-1;1<=v;v--)q=l[v]+q,d(k,f,q,b,(n-v)/n,p,e);q="";case "forward":for(v=0;v<n;v++)q+=l[v],d(k,f,q,b,1,p,e);break;case "full":for(v=0;v<n;v++)for(var m=(n-v)/n,t=n;t>v;t--)q=l.substring(v,t),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]=w()),l=this.l[l]||(this.l[l]=M(10)),p=u-g,q=u+g+1,0>p&&(p=0),q>r&&(q=r);p<q;p++)p!==u&&d(l,n,c[p],b,0,10-(p<u?u-p:p-u),e)}}}this.a[b]=1;this.u=!1}return this};e.prototype.update=function(b,c){this.a[b]&&F(c)&&(this.remove(b),
|
||||
this.add(b,c,!0));return this};e.prototype.remove=function(b){if(this.a[b]){if(this.i){var c=this.a[b];this.j[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]=[B.remove,b],D(this),this;for(c=0;10>c;c++)m(this.v[c],b);this.depth&&m(this.l,b);delete this.a[b];this.u=!1}return this};e.prototype.search=function(b,c,a,d){var f=b,e=[];if("object"===typeof b){(a=b.callback||c)&&(f.callback=null);c=b.limit;var g=b.threshold;
|
||||
b=b.query}g||(g=this.threshold||0);C(c)?(a=c,c=1E3):c||0===c||(c=1E3);if(this.i)for(this.C=a,this.o=0,this.f=[],e=0;e<this.i;e++)this.j[e].postMessage(e,{search:!0,limit:c,threshold:g,content:b});else if(a){var k=this;L(function(){a(k.search(f,c,null,!0));k=null},1,"search-"+this.id)}else{if(!d&&this.async&&"function"!==typeof importScripts){var l=this;return new Promise(function(b){b(l.search(f,c,null,!0));l=null})}if(!b||!F(b))return e;f=b;if(this.cache)if(this.u){if(d=this.g.get(b))return d}else this.g.clear(),
|
||||
this.u=!0;f=this.encode(f);if(!f.length)return e;d=this.h;d=C(d)?d(f):f.split(N);var u=d.length,n=!0,p=[],q=w();if(1<u)if(this.depth){var m=!0;var t=d[0];q[t]=1}else d.sort(W);var x;if(!m||(x=this.l)[t])for(var y=m?1:0;y<u;y++){var z=d[y];if(z){if(!q[z]){var A=[],B=!1,D=0;if(t=m?x[t]:this.v)for(var E=void 0,G=9;G>=g;G--)if(E=t[G][z])A[D++]=E,B=!0;if(B)p[p.length]=1<D?A.concat.apply([],A):A[0];else if(!this.w){n=!1;break}q[z]=1}t=z}}else n=!1;n&&(e=V(p,c,this.w));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.v=this.l=this.a=this.c=this.b=null;return this};var A={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+")," "];return function(a){a=l(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,d){if(!a)return a;a=this.simple(a);2<a.length&&(a=l(a,b));d||1<a.length&&
|
||||
(a=t(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]+l(d.substring(1),b))}a=a.join(" ");a=t(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s+")," "];return function(a){return t(l(a.toLowerCase(),b))}}()},L=function(){var a=w();return function(b,
|
||||
d,f){var c=a[f];c&&clearTimeout(c);return a[f]=setTimeout(b,d)}}(),aa=function(){function a(a){this.clear();this.B=!0!==a&&a}a.prototype.clear=function(){this.cache=w();this.count=w();this.index=w();this.a=[]};a.prototype.set=function(a,b){if(this.B&&y(this.cache[a])){var c=this.a.length;if(c===this.B){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.B&&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={},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+".es5.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);
|
||||
'use strict';function I(g){var h=0;return function(){return h<g.length?{done:!1,value:g[h++]}:{done:!0}}}function J(g){var h="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return h?h.call(g):{next:I(g)}}var R="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,S="function"==typeof Object.defineProperties?Object.defineProperty:function(g,h,e){g!=Array.prototype&&g!=Object.prototype&&(g[h]=e.value)};
|
||||
function T(g,h){if(h){var e=R;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&&S(e,g,{configurable:!0,writable:!0,value:h})}}
|
||||
T("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(y){a.reject(y)}}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=R.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(C){this.f(C)}}}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.s),reject:d(this.f)}};h.prototype.s=function(d){if(d===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(d instanceof h)this.u(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.o(d):this.j(d)}};
|
||||
h.prototype.o=function(a){var d=void 0;try{d=a.then}catch(y){this.f(y);return}"function"==typeof d?this.v(d,a):this.j(a)};h.prototype.f=function(a){this.l(2,a)};h.prototype.j=function(a){this.l(1,a)};h.prototype.l=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.m()};h.prototype.m=function(){if(null!=this.a){for(var a=0;a<this.a.length;++a)m.b(this.a[a]);this.a=null}};var m=new e;h.prototype.u=function(a){var d=this.c();
|
||||
a.A(d.resolve,d.reject)};h.prototype.v=function(a,h){var d=this.c();try{a.call(h,d.resolve,d.reject)}catch(C){d.reject(C)}};h.prototype.then=function(a,e){function d(a,d){return"function"==typeof a?function(d){try{g(a(d))}catch(F){k(F)}}:d}var g,k,l=new h(function(a,d){g=a;k=d});this.A(d(a,g),d(e,k));return l};h.prototype.catch=function(a){return this.then(void 0,a)};h.prototype.A=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?m.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=J(a),g=e.next();!g.done;g=e.next())k(g.value).A(d,h)})};h.all=function(a){var d=J(a),e=d.next();return e.done?k([]):new h(function(a,h){function g(d){return function(h){l[d]=h;m--;0==m&&a(l)}}var l=[],m=0;do l.push(void 0),m++,k(e.value).A(g(l.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 Y(g){function e(b){G(b)&&(b=K[b]);b||(b=u);this.id=b.id||Z++;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 m(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,d,L,e){if(c[a])return c[a];d=d?(9-(e||6))*L+(e||6)*d:L;c[a]=d;d>=e&&(b=b[9-(d+.5>>0)],b=b[a]||(b[a]=[]),b[b.length]=f);return d}function l(b,c){if(b)for(var a=Object.keys(b),f=0,d=a.length;f<d;f++){var e=a[f],g=b[e];if(g)for(var A=0,k=g.length;A<k;A++)if(g[A]===c){1===k?delete b[e]:g.splice(A,1);break}else"object"===typeof g[A]&&l(g[A],c)}}function y(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 C(b,c){var a=v();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 U(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 X(b,c){b=b.length-c.length;return 0>b?1:b?-1:0}function V(b,c){b=
|
||||
b.length-c.length;return 0>b?-1:b?1:0}function W(b,c,a){var f=[],d=b.length;if(1<d){b.sort(V);for(var e=v(),w=b[0],A=w.length,g=0;g<A;)e["@"+w[g++]]=1;for(var k,r=0,p=0;++p<d;){var q=!1,l=p===d-1;var n=[];w=b[p];A=w.length;for(g=0;g<A;){k=w[g++];var m="@"+k;if(e[m]){var z=e[m];if(z===p){if(l){if(f[r++]=k,c&&r===c)return f}else e[m]=p+1;q=!0}else a&&(m=n[z]||(n[z]=[]),m[m.length]=k)}}if(!q&&!a)break}if(a&&(r=f.length,(p=n.length)&&(!c||r<c)))for(;p--;)if(k=n[p])for(b=0,a=k.length;b<a;b++)if(f[r++]=
|
||||
k[b],c&&r===c)return f}else d&&(f=b[0],c&&f.length>c&&(f=f.slice(0,c)));return f}function G(b){return"string"===typeof b}function F(b){return"function"===typeof b}function x(b){return"undefined"===typeof b}function D(b){b.F||(b.F=M(function(){b.F=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.f[f];switch(d[0]){case E.add:b.add(d[1],d[2]);break;case E.remove:b.remove(d[1])}delete b.f[f];if(100<Date.now()-a)break}b.b.length&&D(b)}c&&(b.async=c)},
|
||||
1,"@"+b.id))}function N(b){for(var c=Array(b),a=0;a<b;a++)c[a]=v();return c}function v(){return Object.create(null)}function aa(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=Y.toString();a.id=c;b.postMessage(c,{register:d,options:a,id:c});return b}var u={encode:"icase",h:"forward",w:!1,cache:!1,async:!1,i:!1,threshold:0,depth:0},K={memory:{encode:"extra",h:"strict",threshold:7},speed:{encode:"icase",h:"strict",
|
||||
threshold:7,depth:2},match:{encode:"extra",h:"full"},score:{encode:"extra",h:"strict",threshold:5,depth:4},balance:{encode:"balance",h:"strict",threshold:6,depth:3},fastest:{encode:"icase",h:"strict",threshold:9,depth:1}},H=[],Z=0,E={add:0,update:1,remove:2},O=a("\\W+"),P={},Q={};(function(){for(var b=Object.getOwnPropertyNames({}.__proto__),c=v(),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)&&H.push(a(c),
|
||||
b[c]);return this};e.registerEncoder=function(b,c){B[b]=c.bind(B);return this};e.registerLanguage=function(b,c){P[b]=c.filter;Q[b]=c.stemmer;return this};e.encode=function(b,c){return B[b](c)};e.prototype.init=function(b){this.D=[];b||(b=u);var c=b.profile,a=c?K[c]:{};if(c=b.worker)if(Worker){var f=this,d=parseInt(c,10)||4;f.o=-1;f.s=0;f.g=[];f.C=null;f.m=Array(d);for(var e=0;e<d;e++)f.m[e]=aa(f.id,e,b,function(b,c,a,d){if(f.s!==f.i)return f.g=f.g.concat(a),f.s++,d&&f.g.length>=d&&(f.s=f.i),f.C&&
|
||||
f.s===f.i&&(f.cache&&f.j.set(c,f.g),f.C(f.g),f.g=[]),f})}else b.worker=!1,this.m=null;this.h=b.tokenize||a.h||this.h||u.h;this.async=x(c=b.async)?this.async||u.async:c;this.i=x(c=b.worker)?this.i||u.i:c;this.threshold=x(c=b.threshold)?a.threshold||this.threshold||u.threshold:c;this.depth=x(c=b.depth)?a.depth||this.depth||u.depth:c;this.w=x(c=b.suggest)?this.w||u.w:c;this.u=(c=x(c=b.encode)?a.encode:c)&&B[c]&&B[c].bind(B)||(F(c)?c:this.u||!1);(c=b.matcher)&&this.addMatcher(c);if(c=b.filter)this.filter=
|
||||
C(P[c]||c,this.u);if(c=b.stemmer)this.stemmer=U(Q[c]||c,this.u);this.l=N(10-(this.threshold||0));this.c=v();this.a=v();this.f=v();this.b=[];this.F=0;this.v=!0;this.j=(this.cache=c=x(c=b.cache)?this.cache||u.cache:c)?new ba(c):!1;return this};e.prototype.encode=function(b){b&&H.length&&(b=m(b,H));b&&this.D.length&&(b=m(b,this.D));b&&this.u&&(b=this.u(b));b&&this.stemmer&&(b=m(b,this.stemmer));return b};e.prototype.addMatcher=function(b){var c=this.D,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&&G(c)&&(b||0===b)){var f="@"+b;if(this.a[f]&&!a)this.update(b,c);else{if(this.i)return++this.o>=this.m.length&&(this.o=0),this.m[this.o].postMessage(this.o,{add:!0,id:b,content:c}),this.a[f]=""+this.o,this;if(this.async)return this.f[f]||(this.b[this.b.length]=f),this.f[f]=[E.add,b,c],D(this),this;c=this.encode(c);if(!c.length)return this;a=this.h;c=F(a)?a(c):c.split(O);var e=v();e._ctx=v();for(var g=this.threshold,k=this.depth,w=this.l,m=c.length,
|
||||
l=0;l<m;l++){var r=c[l];if(r){var p=r.length,q=(m-l)/m,t="";switch(a){case "reverse":case "both":for(var n=p-1;1<=n;n--)t=r[n]+t,d(w,e,t,b,(p-n)/p,q,g);t="";case "forward":for(n=0;n<p;n++)t+=r[n],d(w,e,t,b,1,q,g);break;case "full":for(n=0;n<p;n++)for(var y=(p-n)/p,z=p;z>n;z--)t=r.substring(n,z),d(w,e,t,b,y,q,g);break;default:if(p=d(w,e,r,b,1,q,g),k&&1<m&&p>=g)for(p=e._ctx[r]||(e._ctx[r]=v()),r=this.c[r]||(this.c[r]=N(10-(g||0))),q=l-k,t=l+k+1,0>q&&(q=0),t>m&&(t=m);q<t;q++)q!==l&&d(r,p,c[q],b,0,10-
|
||||
(q<l?l-q:q-l),g)}}}this.a[f]=1;this.v=!1}}return this};e.prototype.update=function(b,c){this.a["@"+b]&&G(c)&&(this.remove(b),this.add(b,c,!0));return this};e.prototype.remove=function(b){var c="@"+b;if(this.a[c]){if(this.i){var a=this.a[c];this.m[a].postMessage(a,{remove:!0,id:b});delete this.a[c];return this}if(this.async)return this.f[c]||(this.b[this.b.length]=c),this.f[c]=[E.remove,b],D(this),this;for(a=0;a<10-(this.threshold||0);a++)l(this.l[a],b);this.depth&&l(this.c,b);delete this.a[c];this.v=
|
||||
!1}return this};e.prototype.search=function(b,a,d,f){var c=b,e=[];if("object"===typeof b){(d=b.callback||a)&&(c.callback=null);a=b.limit;var g=b.threshold;b=b.query}g||(g=this.threshold||0);F(a)?(d=a,a=1E3):a||0===a||(a=1E3);if(this.i)for(this.C=d,this.s=0,this.g=[],e=0;e<this.i;e++)this.m[e].postMessage(e,{search:!0,limit:a,threshold:g,content:b});else if(d){var k=this;M(function(){d(k.search(c,a,null,!0));k=null},1,"search-"+this.id)}else{if(!f&&this.async&&"function"!==typeof importScripts){var l=
|
||||
this;return new Promise(function(b){b(l.search(c,a,null,!0));l=null})}if(!b||!G(b))return e;c=b;if(this.cache)if(this.v){if(f=this.j.get(b))return f}else this.j.clear(),this.v=!0;c=this.encode(c);if(!c.length)return e;f=this.h;f=F(f)?f(c):c.split(O);var m=f.length,w=!0,p=[],q=v();if(1<m)if(this.depth){var t=!0;var n=f[0];q[n]=1}else f.sort(X);var y;if(!t||(y=this.c)[n])for(var z=t?1:0;z<m;z++){var u=f[z];if(u){if(!q[u]){var x=[],C=!1,B=0;if(n=t?y[n]:this.l)for(var E=void 0,D=0;D<10-g;D++)if(E=n[D][u])x[B++]=
|
||||
E,C=!0;if(C)p[p.length]=1<B?x.concat.apply([],x):x[0];else if(!this.w){w=!1;break}q[u]=1}n=u}}else w=!1;w&&(e=W(p,a,this.w));this.cache&&this.j.set(b,e);return e}};e.prototype.clear=function(){this.destroy();return this.init()};e.prototype.destroy=function(){this.cache&&(this.j.clear(),this.j=null);this.filter=this.stemmer=this.l=this.c=this.a=this.f=this.b=null;return this};e.prototype.export=function(){return JSON.stringify([this.l,this.c,this.a])};e.prototype.import=function(b){b=JSON.parse(b);
|
||||
this.l=b[0];this.c=b[1];this.a=b[2]};var B={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+")," "];return function(a){a=m(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,d){if(!a)return a;a=this.simple(a);2<a.length&&(a=m(a,b));d||1<a.length&&(a=y(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]+m(d.substring(1),b))}a=a.join(" ");a=y(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s+")," "];return function(a){return y(m(a.toLowerCase(),b))}}()},M=function(){var a=v();return function(b,d,f){var c=a[f];c&&clearTimeout(c);return a[f]=setTimeout(b,d)}}(),ba=function(){function a(a){this.clear();this.B=!0!==a&&a}a.prototype.clear=function(){this.cache=
|
||||
v();this.count=v();this.index=v();this.a=[]};a.prototype.set=function(a,b){if(this.B&&x(this.cache[a])){var c=this.a.length;if(c===this.B){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.B&&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={},h="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(e,k,a,m,d){var l=e;e=h?URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"})):l+".es5.js";l+="-"+k;g[l]||(g[l]=[]);g[l][d]=new Worker(e);g[l][d].onmessage=m;return{postMessage:function(a,d){g[l][a].postMessage(d)}}}}()),this);
|
||||
|
@@ -16,7 +16,7 @@
|
||||
<h2>Presets Relevance Scoring Comparison</h2>
|
||||
<h4>Indexed Text: "Gulliver's Travels" (Swift Jonathan 1726)</h4>
|
||||
<hr>
|
||||
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script>
|
||||
<script src="../flexsearch.min.js"></script>
|
||||
<script src="../data/gulliver.js"></script>
|
||||
<div id="container">
|
||||
<table>
|
||||
|
@@ -201,7 +201,7 @@
|
||||
<div style="display:inline-block; width:16px; height:16px; background: #0a0"></div> Most relevant results was successfully found in the first place.<br>
|
||||
<b>Note:</b> Open console and type e.g. <i>data[493]</i>
|
||||
</div>
|
||||
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script>
|
||||
<script src="../flexsearch.min.js"></script>
|
||||
<script src="https://rawgit.com/nextapps-de/bulksearch/master/bulksearch.min.js"></script>
|
||||
<script src="https://cdn.rawgit.com/weixsong/elasticlunr.js/master/example/elasticlunr.min.js"></script>
|
||||
<script src="https://unpkg.com/lunr@2.1.6/lunr.js"></script>
|
||||
|
10
test/test.js
10
test/test.js
@@ -203,7 +203,7 @@ describe("Add (Sync)", function(){
|
||||
flexsearch_sync.add(2, "bar");
|
||||
flexsearch_sync.add(1, "foobar");
|
||||
|
||||
expect(flexsearch_sync.index).to.have.keys([0, 1, 2]);
|
||||
expect(flexsearch_sync.index).to.have.keys(["@0", "@1", "@2"]);
|
||||
expect(flexsearch_sync.length).to.equal(3);
|
||||
});
|
||||
|
||||
@@ -405,7 +405,7 @@ if(env !== "light"){
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_async.length).to.equal(3);
|
||||
expect(flexsearch_async.index).to.have.keys([0, 1, 2]);
|
||||
expect(flexsearch_async.index).to.have.keys(["@0", "@1", "@2"]);
|
||||
|
||||
done();
|
||||
|
||||
@@ -428,7 +428,7 @@ if(env !== "light"){
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_async.length).to.equal(3);
|
||||
expect(flexsearch_async.index).to.have.keys([0, 1, 2]);
|
||||
expect(flexsearch_async.index).to.have.keys(["@0", "@1", "@2"]);
|
||||
|
||||
done();
|
||||
|
||||
@@ -657,7 +657,7 @@ if(env !== "light"){
|
||||
flexsearch_worker.add(1, "foobar");
|
||||
|
||||
expect(flexsearch_worker.length).to.equal(3);
|
||||
expect(flexsearch_worker.index).to.have.keys([0, 1, 2]);
|
||||
expect(flexsearch_worker.index).to.have.keys(["@0", "@1", "@2"]);
|
||||
|
||||
flexsearch_worker.search("foo", function(result){
|
||||
|
||||
@@ -682,7 +682,7 @@ if(env !== "light"){
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_worker.length).to.equal(3);
|
||||
expect(flexsearch_worker.index).to.have.keys([0, 1, 2]);
|
||||
expect(flexsearch_worker.index).to.have.keys(["@0", "@1", "@2"]);
|
||||
|
||||
done();
|
||||
|
||||
|
Reference in New Issue
Block a user