1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-09 21:50:49 +02:00
This commit is contained in:
Thomas Wilkerling
2019-01-28 02:33:58 +01:00
parent e66e98c213
commit 15a6e2b650
12 changed files with 210 additions and 174 deletions

111
README.md
View File

@@ -25,6 +25,11 @@ Supported Platforms:
- Browser
- Node.js
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>
- <a href="#consumption">Memory Consumption</a>
Get Latest (Stable Release):
<table>
@@ -170,18 +175,16 @@ All Features:
<td>File Size (gzip)</td>
<td>6.7 kb</td>
<td>4.5 kb</td>
<td>2.1 kb</td>
<td>4.1 kb</td>
</tr>
</table>
> It is also pretty simple to make <a href="#builds">Custom Builds</a>
<a name="compare" id="compare"></a>
#### Benchmark Ranking
## Benchmark Ranking
- Library Comparison: <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark.html" target="_blank">Benchmark "Gulliver's Travels"</a>
- Library Comparison: <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching.html" target="_blank">Relevance Scoring</a>
- Library Comparison: <a href="#consumption">Memory Consumption</a>
Comparison: <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark.html" target="_blank">Benchmark "Gulliver's Travels"</a>
__Query Test: "Gulliver's Travels"__
@@ -197,9 +200,9 @@ __Query Test: "Gulliver's Travels"__
<tr>
<td>1</td>
<td>FlexSearch</td>
<td>0.3.1</td>
<td>2.1 kb</td>
<td><b>327771</b></td>
<td>0.3.2</td>
<td>4.1 kb</td>
<td><b>333738</b></td>
</tr>
<tr></tr>
<tr>
@@ -296,10 +299,10 @@ __Memory Test: "Gulliver's Travels"__
<tr></tr>
<tr>
<td>3</td>
<td>JS Search</td>
<td>1.4.2</td>
<td>36.9 Mb</td>
<td>53.0 kb</td>
<td>Fuse</td>
<td>3.3.0</td>
<td>0.22 Mb</td>
<td>156.46 kb</td>
</tr>
<tr></tr>
<tr>
@@ -312,42 +315,42 @@ __Memory Test: "Gulliver's Travels"__
<tr></tr>
<tr>
<td>5</td>
<td>Lunr.js</td>
<td>2.3.5</td>
<td>16.24 Mb</td>
<td>84.73 kb</td>
</tr>
<tr></tr>
<tr>
<td>6</td>
<td>Elasticlunr.js</td>
<td>0.9.6</td>
<td>11.83 Mb</td>
<td>68.69 kb</td>
</tr>
<tr></tr>
<tr>
<td>7</td>
<td>BulkSearch</td>
<td>0.1.3</td>
<td>1.53 Mb</td>
<td>984.30 kb</td>
</tr>
<tr></tr>
<tr>
<td>8</td>
<td>bm25</td>
<td>0.2</td>
<td>6.95 Mb</td>
<td>137.88 kb</td>
</tr>
<tr></tr>
<tr>
<td>6</td>
<td>BulkSearch</td>
<td>0.1.3</td>
<td>1.53 Mb</td>
<td>984.30 kb</td>
</tr>
<tr></tr>
<tr>
<td>7</td>
<td>Elasticlunr.js</td>
<td>0.9.6</td>
<td>11.83 Mb</td>
<td>68.69 kb</td>
</tr>
<tr></tr>
<tr>
<td>8</td>
<td>Lunr.js</td>
<td>2.3.5</td>
<td>16.24 Mb</td>
<td>84.73 kb</td>
</tr>
<tr></tr>
<tr>
<td>9</td>
<td>Fuse</td>
<td>3.3.0</td>
<td>0.22 Mb</td>
<td>156.46 kb</td>
<td>JS Search</td>
<td>1.4.2</td>
<td>36.9 Mb</td>
<td>53.0 kb</td>
</tr>
</table>
@@ -418,7 +421,7 @@ __Note:__ It is slightly faster to use no web worker when the index or query isn
<tr>
<td>Weaks</td>
<td><ul><li>less powerful contextual search</li><li>less memory efficient (has to be defragmented from time to time)</li></ul></td>
<td><ul><li>updating / deleting extisting items from index is slow</li><li>adding items to the index optimized for super partial matching (mode: "full") is slow</li></ul></td>
<td><ul><li>updating / deleting extisting items from index is slow</li><li>adding items to the index optimized for super partial matching (tokenize: "full") is slow</li></ul></td>
</tr>
<tr></tr>
<tr>
@@ -563,7 +566,7 @@ var index = new FlexSearch({
profile: "balance",
encode: "icase",
mode: "ngram",
tokenize: "ngram",
async: false,
cache: false
});
@@ -810,7 +813,7 @@ Define a private custom tokenizer during creation/initialization:
```js
var index = new FlexSearch({
mode: function(str){
tokenize: function(str){
// split string into components, e.g.:
@@ -930,7 +933,7 @@ Create index and just set the limit of relevance ("depth"):
var index = new FlexSearch({
encode: "icase",
mode: "strict",
tokenize: "strict",
depth: 3
});
```
@@ -954,7 +957,7 @@ Create index and just set the count of parallel threads:
var index = new FlexSearch({
encode: "icase",
mode: "full",
tokenize: "full",
async: true,
worker: 4
});
@@ -1001,7 +1004,7 @@ FlexSearch ist highly customizable. Make use of the the <a href="#profiles">righ
</tr>
<tr></tr>
<tr>
<td align="top">mode<br><br><br><br><br><br></td>
<td align="top">tokenize<br><br><br><br><br><br></td>
<td vertical="top" vertical-align="top">
"strict"<br>
"foward"<br>
@@ -1422,7 +1425,7 @@ Standard profile: __"default"__
```js
{
encode: "icase",
mode: "forward"
tokenize: "forward"
}
```
@@ -1430,7 +1433,7 @@ Memory-optimized profile: __"memory"__
```js
{
encode: "extra",
mode: "strict",
tokenize: "strict",
threshold: 7
}
```
@@ -1440,7 +1443,7 @@ Speed-optimized profile: __"speed"__
```js
{
encode: "icase",
mode: "strict",
tokenize: "strict",
threshold: 7,
depth: 2
}
@@ -1451,7 +1454,7 @@ Matching-tolerant profile: __"match"__
```js
{
encode: "extra",
mode: "full"
tokenize: "full"
}
```
@@ -1460,7 +1463,7 @@ Relevance-optimized profile: __"score"__
```js
{
encode: "extra",
mode: "strict",
tokenize: "strict",
threshold: 5,
depth: 5
}
@@ -1471,7 +1474,7 @@ Most-balanced profile: __"balanced"__
```js
{
encode: "balanced",
mode: "ngram",
tokenize: "ngram",
threshold: 6,
depth: 3
}
@@ -1487,9 +1490,11 @@ Absolute fastest profile: __"fastest"__
}
```
<!--
Compare these options above:
- <a href="https://jsperf.com/compare-flexsearch-options" target="_blank">Benchmarks</a>
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark.html" target="_blank">Benchmarks</a>
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching-flexsearch.html" target="_blank">Relevance Scoring</a>
-->
<a name="builds"></a>
## Custom Builds

View File

@@ -71,7 +71,7 @@ var parameter = (function(opt){
generate_exports: true,
export_local_property_definitions: true,
language_in: "ECMASCRIPT6_STRICT",
language_out: language_out || "ECMASCRIPT5_STRICT",
language_out: language_out || "ECMASCRIPT6_STRICT",
process_closure_primitives: true,
summary_detail_level: 3,
warning_level: "VERBOSE",
@@ -118,12 +118,12 @@ else{
console.log("Build Complete: " + filename);
if(release === "demo"){
if(release === "es5"){
//fs.existsSync("dist/") || fs.mkdirSync("dist/");
//fs.existsSync("dist/latest") || fs.mkdirSync("dist/latest");
fs.copyFileSync(filename, "docs/" + filename);
fs.copyFileSync(filename, "test/" + filename);
//fs.copyFileSync(filename, "dist/latest/" + filename);
fs.unlinkSync(filename);
}

View File

@@ -1,31 +1,24 @@
/*
FlexSearch v0.3.1
FlexSearch v0.3.2
Copyright 2019 Nextapps GmbH
Author: Thomas Wilkerling
Released under the Apache 2.0 Licence
https://github.com/nextapps-de/flexsearch
*/
'use strict';function J(d){var c=0;return function(){return c<d.length?{done:!1,value:d[c++]}:{done:!0}}}function K(d){var c="undefined"!=typeof Symbol&&Symbol.iterator&&d[Symbol.iterator];return c?c.call(d):{next:J(d)}}var S="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,T="function"==typeof Object.defineProperties?Object.defineProperty:function(d,c,a){d!=Array.prototype&&d!=Object.prototype&&(d[c]=a.value)};
function U(d,c){if(c){var a=S;d=d.split(".");for(var f=0;f<d.length-1;f++){var g=d[f];g in a||(a[g]={});a=a[g]}d=d[d.length-1];f=a[d];c=c(f);c!=f&&null!=c&&T(a,d,{configurable:!0,writable:!0,value:c})}}
U("Promise",function(d){function c(a){this.b=0;this.g=void 0;this.a=[];var p=this.c();try{a(p.resolve,p.reject)}catch(C){p.reject(C)}}function a(){this.a=null}function f(a){return a instanceof c?a:new c(function(p){p(a)})}if(d)return d;a.prototype.b=function(a){if(null==this.a){this.a=[];var p=this;this.c(function(){p.g()})}this.a.push(a)};var g=S.setTimeout;a.prototype.c=function(a){g(a,0)};a.prototype.g=function(){for(;this.a&&this.a.length;){var a=this.a;this.a=[];for(var c=0;c<a.length;++c){var d=
a[c];a[c]=null;try{d()}catch(z){this.f(z)}}}this.a=null};a.prototype.f=function(a){this.c(function(){throw a;})};c.prototype.c=function(){function a(a){return function(p){d||(d=!0,a.call(c,p))}}var c=this,d=!1;return{resolve:a(this.o),reject:a(this.f)}};c.prototype.o=function(a){if(a===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(a instanceof c)this.s(a);else{a:switch(typeof a){case "object":var d=null!=a;break a;case "function":d=!0;break a;default:d=!1}d?this.m(a):this.h(a)}};
c.prototype.m=function(a){var c=void 0;try{c=a.then}catch(C){this.f(C);return}"function"==typeof c?this.u(c,a):this.h(a)};c.prototype.f=function(a){this.i(2,a)};c.prototype.h=function(a){this.i(1,a)};c.prototype.i=function(a,c){if(0!=this.b)throw Error("Cannot settle("+a+", "+c+"): Promise already settled in state"+this.b);this.b=a;this.g=c;this.j()};c.prototype.j=function(){if(null!=this.a){for(var a=0;a<this.a.length;++a)w.b(this.a[a]);this.a=null}};var w=new a;c.prototype.s=function(a){var c=this.c();
a.l(c.resolve,c.reject)};c.prototype.u=function(a,c){var d=this.c();try{a.call(c,d.resolve,d.reject)}catch(z){d.reject(z)}};c.prototype.then=function(a,d){function f(a,c){return"function"==typeof a?function(c){try{p(a(c))}catch(E){g(E)}}:c}var p,g,B=new c(function(a,c){p=a;g=c});this.l(f(a,p),f(d,g));return B};c.prototype.catch=function(a){return this.then(void 0,a)};c.prototype.l=function(a,c){function d(){switch(f.b){case 1:a(f.g);break;case 2:c(f.g);break;default:throw Error("Unexpected state: "+
f.b);}}var f=this;null==this.a?w.b(d):this.a.push(d)};c.resolve=f;c.reject=function(a){return new c(function(c,d){d(a)})};c.race=function(a){return new c(function(c,d){for(var p=K(a),g=p.next();!g.done;g=p.next())f(g.value).l(c,d)})};c.all=function(a){var d=K(a),g=d.next();return g.done?f([]):new c(function(a,c){function p(c){return function(d){A[c]=d;v--;0==v&&a(A)}}var A=[],v=0;do A.push(void 0),v++,f(g.value).l(p(A.length-1),c),g=d.next();while(!g.done)})};return c});
(function(d,c,a){var f;(f=a.define)&&f.amd?f([],function(){return c}):(f=a.modules)?f[d.toLowerCase()]=c:"object"===typeof exports?module.exports=c:a[d]=c})("FlexSearch",function(){function d(b){F(b)&&(b=L[b]);b||(b=x);this.id=b.id||W++;this.init(b);c(this,"index",function(){return this.a});c(this,"length",function(){return Object.keys(this.a).length})}function c(b,e,a){Object.defineProperty(b,e,{get:a})}function a(b){return new RegExp(b,"g")}function f(b,e){for(var a=0;a<e.length;a+=2)b=b.replace(e[a],
e[a+1]);return b}function g(b,e,a,c,d,D,l){if(e[a])return e[a];d=d?(9-(l||6))*D+(l||6)*d:D;e[a]=d;d>=l&&(b=b[d+.5>>0],b=b[a]||(b[a]=[]),b[b.length]=c);return d}function w(b,e){if(b)for(var a=Object.keys(b),c=0,d=a.length;c<d;c++){var D=a[c],l=b[D];if(l)for(var f=0,h=l.length;f<h;f++)if(l[f]===e){1===h?delete b[D]:l.splice(f,1);break}else"object"===typeof l[f]&&w(l[f],e)}}function p(b){var e=[];if(!b)return e;for(var a=0,c=0,d=0,f="",l=b.length,g=0;g<l;g++){var h=b[g];"a"===h||"e"===h||"i"===h||"o"===
h||"u"===h||"y"===h?a++:c++;" "!==h&&(f+=h);if(" "===h||a>=(8<l?2:1)&&2<=c||2<=a&&c>=(8<l?2:1)||g===l-1)f&&(e[d]&&2<f.length&&d++,e[d]=e[d]?e[d]+f:f," "===h&&d++,f=""),c=a=0}return e}function B(b){for(var e="",a="",c="",d=0;d<b.length;d++){var f=b[d];if(f!==a)if(d&&"h"===f){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===a||"e"===a||"i"===a||"o"===a||"u"===a||"y"===a)&&c||" "===a)e+=f}else e+=f;c=d===b.length-1?"":b[d+1];a=f}return e}function C(b,e){b=b.length-e.length;return 0>b?
1:b?-1:0}function z(b,e){b=b.length-e.length;return 0>b?-1:b?1:0}function V(b,e,a){var c=[],d=[],f=b.length;if(1<f){b.sort(z);for(var t={},g=b[0],h=g.length,q=0;q<h;)t[g[q++]]=1;for(var k,m=0,n=0;++n<f;){var r=!1,p=n===f-1;d=[];g=b[n];h=g.length;for(q=0;q<h;)if(k=g[q++],t[k]){var u=t[k];if(u===n){if(p){if(c[m++]=k,e&&m===e)return c}else t[k]=n+1;r=!0}else a&&(u=d[u]||(d[u]=[]),u[u.length]=k)}if(!r&&!a)break}if(a&&(m=c.length,(n=d.length)&&(!e||m<e)))for(;n--;)if(k=d[n])for(b=0,a=k.length;b<a;b++)if(c[m++]=
k[b],e&&m===e)return c}else f&&(c=b[0],e&&c.length>e&&(c=c.slice(0,e)));return c}function F(b){return"string"===typeof b}function A(b){return"function"===typeof b}function v(b){return"undefined"===typeof b}function H(b){b.j||(b.j=N(function(){b.j=0;var a=b.async;a&&(b.async=!1);if(b.b.length){for(var c=Date.now(),d;(d=b.b.shift())||0===d;){var f=b.c[d];switch(f[0]){case G.add:b.add(f[1],f[2]);break;case G.remove:b.remove(f[1])}delete b.c[d];if(100<Date.now()-c)break}b.b.length&&H(b)}a&&(b.async=a)},
1,"search-async-"+b.id))}function E(b){for(var a=Array(b),c=0;c<b;c++)a[c]={};return a}var x={encode:"icase",mode:"forward",v:!1,cache:!1,async:!1,w:!1,threshold:0,depth:0},L={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"strict",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},I=[],
W=0,G={add:0,update:1,remove:2},O=a("[ -/]"),P={},Q={},R=function(){for(var b=Object.getOwnPropertyNames({}.__proto__),a={},c=0;c<b.length;c++)a[b[c]]=1;return a}();d.create=function(b){return new d(b)};d.registerMatcher=function(b){for(var e in b)b.hasOwnProperty(e)&&I.push(a(e),b[e]);return this};d.registerEncoder=function(b,a){y[b]=a.bind(y);return this};d.registerLanguage=function(b,a){P[b]=a.filter;Q[b]=a.stemmer;return this};d.encode=function(b,a){return R[b]?a:y[b](a)};d.prototype.init=function(b){this.i=
[];b||(b=x);var e=b.profile,c=e?L[e]:{};this.mode=b.mode||c.mode||this.mode||x.mode;this.async=v(e=b.async)?this.async||x.async:e;this.threshold=v(e=b.threshold)?c.threshold||this.threshold||x.threshold:e;this.depth=v(e=b.depth)?c.depth||this.depth||x.depth:e;this.g=(e=v(e=b.encode)?c.encode:e)&&y[e]&&y[e].bind(y)||(A(e)?e:this.g||!1);(e=b.matcher)&&this.addMatcher(e);if(e=b.filter){e=P[e]||e;c=this.g;var d={};if(e)for(var f=0;f<e.length;f++){var g=c?c(e[f]):e[f];d[g]=String.fromCharCode(65E3-e.length+
f)}this.filter=d}if(e=b.stemmer){b=Q[e]||e;e=this.g;c=[];if(b)for(var l in b)b.hasOwnProperty(l)&&(d=e?e(l):l,c.push(a("(?=.{"+(d.length+3)+",})"+d+"$"),e?e(b[l]):b[l]));this.stemmer=c}this.h=E(10);this.f={};this.a={};this.c={};this.b=[];this.j=0;return this};d.prototype.encode=function(b){b&&I.length&&(b=f(b,I));b&&this.i.length&&(b=f(b,this.i));b&&this.g&&(b=this.g(b));b&&this.stemmer&&(b=f(b,this.stemmer));return b};d.prototype.addMatcher=function(b){var e=this.i,c;for(c in b)b.hasOwnProperty(c)&&
e.push(a(c),b[c]);return this};d.prototype.add=function(b,a,c){if(a&&F(a)&&(b&&!R[b]||0===b))if(this.a[b]&&!c)this.update(b,a);else{if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[G.add,b,a],H(this),this;a=this.encode(a);if(!a.length)return this;c=this.mode;a=A(c)?c(a):"ngram"===c?p(a):a.split(O);for(var e={_ctx:{}},d=this.threshold,f=this.depth,l=this.h,t=a.length,h=0;h<t;h++){var q=a[h];if(q){var k=q.length,m=(t-h)/t,n="";switch(c){case "reverse":case "both":for(var r=k-1;1<=
r;r--)n=q[r]+n,g(l,e,n,b,(k-r)/k,m,d);n="";case "forward":for(r=0;r<k;r++)n+=q[r],g(l,e,n,b,1,m,d);break;case "full":for(r=0;r<k;r++)for(var v=(k-r)/k,u=k;u>r;u--)n=q.substring(r,u),g(l,e,n,b,v,m,d);break;default:if(k=g(l,e,q,b,1,m,d),f&&1<t&&k>=d)for(k=e._ctx[q]||(e._ctx[q]={}),q=this.f[q]||(this.f[q]=E(10)),m=h-f,n=h+f+1,0>m&&(m=0),n>t&&(n=t);m<n;m++)m!==h&&g(q,k,a[m],b,0,10-(m<h?h-m:m-h),d)}}}this.a[b]=1}return this};d.prototype.update=function(a,c){this.a[a]&&F(c)&&(this.remove(a),this.add(a,
c,!0));return this};d.prototype.remove=function(a){if(this.a[a]){if(this.async)return this.c[a]||(this.b[this.b.length]=a),this.c[a]=[G.remove,a],H(this),this;for(var b=0;10>b;b++)w(this.h[b],a);this.depth&&w(this.f,a);delete this.a[a]}return this};d.prototype.search=function(a,c,d,f){var b=a,e=[];if("object"===typeof a){(d=a.callback||c)&&(b.callback=null);c=a.limit;var g=a.threshold;a=a.query}g||(g=this.threshold||0);A(c)?(d=c,c=1E3):c||0===c||(c=1E3);if(d){var t=this;N(function(){d(t.search(b,
c,null,!0));t=null},1,"search-"+this.id)}else{if(!f&&this.async){var h=this;return new Promise(function(a){a(h.search(b,c,null,!0));h=null})}if(!a||!F(a))return e;b=a;b=this.encode(b);if(!b.length)return e;a=this.mode;a=A(a)?a(b):"ngram"===a?p(b):b.split(O);f=a.length;var q=!0,k=[],m={};if(1<f)if(this.depth){var n=!0;var r=a[0];m[r]=1}else a.sort(C);var v;if(!n||(v=this.f)[r])for(var u=n?1:0;u<f;u++){var w=a[u];if(w&&!m[w]){var x=void 0;x=void 0;for(var M=!1,y=[],B=0,z=9;z>=g;z--)if(x=(n?v[r]:this.h)[z],
x=x[w])y[B++]=x,M=!0;if(M)k[k.length]=1<B?k.concat.apply([],y):y[0];else{q=!1;break}m[w]=1}r=w}else q=!1;q&&(e=V(k,c,!1));return e}};d.prototype.clear=function(){this.destroy();return this.init()};d.prototype.destroy=function(){this.filter=this.stemmer=this.h=this.f=this.a=this.c=this.b=null;return this};var y={icase:function(a){return a.toLowerCase()},simple:function(){var b=[a("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",a("[\u00e8\u00e9\u00ea\u00eb]"),"e",a("[\u00ec\u00ed\u00ee\u00ef]"),"i",a("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),
"o",a("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",a("[\u00fd\u0177\u00ff]"),"y",a("\u00f1"),"n",a("\u00e7"),"c",a("\u00df"),"s",a(" & ")," and ",a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(a){a=f(a.toLowerCase(),b);return" "!==a?a:""}}(),advanced:function(){var b=[a("ae"),"a",a("ai"),"ei",a("ay"),"ei",a("ey"),"ei",a("oe"),"o",a("ue"),"u",a("ie"),"i",a("sz"),"s",a("zs"),"s",a("sh"),"s",a("ck"),"k",a("cc"),"k",a("dt"),"t",a("ph"),"f",a("pf"),"f",a("ou"),"o",a("uo"),"u"];return function(a,
c){if(!a)return a;a=this.simple(a);2<a.length&&(a=f(a,b));c||1<a.length&&(a=B(a));return a}}(),extra:function(){var b=[a("p"),"b",a("z"),"s",a("[cgq]"),"k",a("n"),"m",a("d"),"t",a("[vw]"),"f",a("[aeiouy]"),""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(var c=0;c<a.length;c++){var d=a[c];1<d.length&&(a[c]=d[0]+f(d.substring(1),b))}a=a.join(" ");a=B(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(a){return B(f(a.toLowerCase(),
b))}}()},N=function(){var a={};return function(b,c,d){var e=a[d];e&&clearTimeout(e);return a[d]=setTimeout(b,c)}}();return d}(!1),this);
'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){w(a)&&(a=E[a]);a||(a=t);this.id=a.id||N++;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 v(a,b,d,f,e,l,c){if(b[d])return b[d];e=e?(9-(c||6))*l+(c||6)*e:l;b[d]=e;e>=c&&(a=a[e+.5>>0],a=a[d]||(a[d]=[]),a[a.length]=f);return e}function A(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]&&A(c[d],b)}}}function G(a){const b=[];if(!a)return b;let d=0,f=0,e=0,c="";const k=a.length;for(let l=0;l<k;l++){const n=
a[l];"a"===n||"e"===n||"i"===n||"o"===n||"u"===n||"y"===n?d++:f++;" "!==n&&(c+=n);if(" "===n||d>=(8<k?2:1)&&2<=f||2<=d&&f>=(8<k?2:1)||l===k-1)c&&(b[e]&&2<c.length&&e++,b[e]=b[e]?b[e]+c:c," "===n&&e++,c=""),f=d=0}return b}function B(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 O(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function P(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function Q(a,b,d){let c=[],e=[];const l=a.length;if(1<l){a.sort(P);const f={};let n=a[0],g=n.length,h=0;for(;h<g;)f[n[h++]]=1;let p,q=0,m=0;for(;++m<l;){let F=!1;const R=m===l-1;e=[];n=a[m];g=n.length;for(h=0;h<g;)if(p=n[h++],f[p]){var k=f[p];if(k===m){if(R){if(c[q++]=p,b&&q===b)return c}else f[p]=m+1;F=!0}else d&&(k=e[k]||(e[k]=[]),k[k.length]=p)}if(!F&&!d)break}if(d&&(q=c.length,(m=e.length)&&
(!b||q<b)))for(;m--;)if(p=e[m])for(let a=0,d=p.length;a<d;a++)if(c[q++]=p[a],b&&q===b)return c}else l&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function w(a){return"string"===typeof a}function x(a){return"function"===typeof a}function y(a){return"undefined"===typeof a}function C(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 z.add:a.add(d[1],d[2]);break;case z.remove:a.remove(d[1])}delete a.f[c];
if(100<Date.now()-b)break}a.c.length&&C(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]={};return b}const t={encode:"icase",a:"forward",m:!1,cache:!1,async:!1,o:!1,threshold:0,depth:0},E={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}},D=[];let N=0;const z={add:0,update:1,remove:2},J=c("[ -/]"),K={},L={},M=function(){const a=Object.getOwnPropertyNames({}.__proto__),b={};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)&&D.push(c(b),a[b]);return this};g.registerEncoder=function(a,b){u[a]=b.bind(u);return this};g.registerLanguage=function(a,b){K[a]=b.filter;L[a]=b.stemmer;return this};g.encode=function(a,
b){return M[a]?b:u[a](b)};g.prototype.init=function(a){this.j=[];a||(a=t);var b=a.profile,d=b?E[b]:{};this.a=a.tokenize||d.a||this.a||t.a;this.async=y(b=a.async)?this.async||t.async:b;this.threshold=y(b=a.threshold)?d.threshold||this.threshold||t.threshold:b;this.depth=y(b=a.depth)?d.depth||this.depth||t.depth:b;this.h=(b=y(b=a.encode)?d.encode:b)&&u[b]&&u[b].bind(u)||(x(b)?b:this.h||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=K[b]||b;d=this.h;var f={};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={};this.b={};this.f={};this.c=[];this.l=0;return this};g.prototype.encode=function(a){a&&D.length&&(a=h(a,D));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&&w(b)&&(a&&!M[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]=[z.add,a,b],C(this),this;b=this.encode(b);if(!b.length)return this;d=this.a;b=x(d)?d(b):"ngram"===d?G(b):b.split(J);const f={_ctx:{}},h=this.threshold,r=this.depth,p=this.i,q=b.length;for(let m=0;m<q;m++){var c=b[m];if(c){var e=c.length,
l=(q-m)/q,k="";switch(d){case "reverse":case "both":for(var g=e-1;1<=g;g--)k=c[g]+k,v(p,f,k,a,(e-g)/e,l,h);k="";case "forward":for(g=0;g<e;g++)k+=c[g],v(p,f,k,a,1,l,h);break;case "full":for(g=0;g<e;g++){const b=(e-g)/e;for(let d=e;d>g;d--)k=c.substring(g,d),v(p,f,k,a,b,l,h)}break;default:if(e=v(p,f,c,a,1,l,h),r&&1<q&&e>=h)for(e=f._ctx[c]||(f._ctx[c]={}),c=this.g[c]||(this.g[c]=I(10)),l=m-r,k=m+r+1,0>l&&(l=0),k>q&&(k=q);l<k;l++)l!==m&&v(c,e,b[l],a,0,10-(l<m?m-l:l-m),h)}}}this.b[a]=1}return this};g.prototype.update=
function(a,b){this.b[a]&&w(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]=[z.remove,a],C(this),this;for(let b=0;10>b;b++)A(this.i[b],a);this.depth&&A(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);x(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||!w(a))return k;d=a;d=this.encode(d);if(!d.length)return k;a=this.a;a=x(a)?a(d):"ngram"===a?G(d):d.split(J);f=a.length;var h=!0,n=[],r={};if(1<f)if(this.depth){var t=!0;var p=a[0];r[p]=1}else a.sort(O);var q;if(!t||(q=this.g)[p])for(let b=t?1:0;b<f;b++){const c=a[b];
if(c&&!r[c]){let a=!1;const b=[];let d=0;for(let e=9;e>=g;e--){var m=(t?q[p]:this.i)[e];if(m=m[c])b[d++]=m,a=!0}if(a)n[n.length]=1<d?n.concat.apply([],b):b[0];else{h=!1;break}r[c]=1}p=c}else h=!1;h&&(k=Q(n,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 u={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\\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=B(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=B(b)}return b}}(),balance:function(){const a=[c("[-/]")," ",c("[^a-z0-9 ]"),"",c("\\s\\s+")," "];return function(b){return B(h(b.toLowerCase(),a))}}()},H=function(){const a={};return function(b,c,f){const d=a[f];d&&clearTimeout(d);return a[f]=setTimeout(b,c)}}();return g}(!1),this);

View File

@@ -1,5 +1,5 @@
;/**!
* @preserve FlexSearch v0.3.1
* @preserve FlexSearch v0.3.2
* Copyright 2019 Nextapps GmbH
* Author: Thomas Wilkerling
* Released under the Apache 2.0 Licence
@@ -31,7 +31,7 @@
const defaults = {
encode: "icase",
mode: "forward",
tokenize: "forward",
suggest: false,
cache: false,
async: false,
@@ -53,39 +53,39 @@
"memory": {
encode: SUPPORT_ENCODER ? "extra" : "icase",
mode: "strict",
tokenize: "strict",
threshold: 7
},
"speed": {
encode: "icase",
mode: "strict",
tokenize: "strict",
threshold: 7,
depth: 2
},
"match": {
encode: SUPPORT_ENCODER ? "extra" : "icase",
mode: "full"
tokenize: "full"
},
"score": {
encode: SUPPORT_ENCODER ? "extra" : "icase",
mode: "strict",
tokenize: "strict",
threshold: 5,
depth: 4
},
"balance": {
encode: SUPPORT_ENCODER ? "balance" : "icase",
mode: "strict",
tokenize: "strict",
threshold: 6,
depth: 3
},
"fastest": {
encode: "icase",
mode: "strict",
tokenize: "strict",
threshold: 9,
depth: 1
}
@@ -361,12 +361,12 @@
// apply custom options
/** @private */
this.mode = (
this.tokenize = (
options["mode"] ||
profile.mode ||
this.mode ||
defaults.mode
options["tokenize"] ||
profile.tokenize ||
this.tokenize ||
defaults.tokenize
);
if(SUPPORT_ASYNC) /** @private */ this.async = (
@@ -674,7 +674,7 @@
return this;
}
const tokenizer = this.mode;
const tokenizer = this.tokenize;
const words = (
@@ -1046,7 +1046,7 @@
return;
}
else if(SUPPORT_ASYNC && !_recall && this.async){
else if(SUPPORT_ASYNC && !_recall && this.async && (typeof importScripts !== "function")){
/** @type {FlexSearch} */
let self = this;
@@ -1105,7 +1105,7 @@
// convert words into single components
const tokenizer = this.mode;
const tokenizer = this.tokenize;
const words = (
@@ -1136,7 +1136,7 @@
if(this.depth){
use_contextual = true;
// TODO: alternative roots
// TODO: iterate roots
ctx_root = words[0];
check_words[ctx_root] = 1;
}
@@ -1302,10 +1302,12 @@
"items": items,
"sequences": words,
"chars": chars,
//"status": this._cache_status,
"cache": this._stack_keys.length,
"matcher": global_matcher.length,
"worker": this.worker
"cache": this.cache && this.cache.ids ? this.cache.ids.length : false,
"matcher": global_matcher.length + (this._matcher ? this._matcher.length : 0),
"worker": this.worker,
"threshold": this.threshold,
"depth": this.depth,
"contextual": !!this.depth
};
};
}
@@ -2818,7 +2820,7 @@
:
// Load Extern Worker (but also requires CORS)
"../" + name + (RELEASE ? "." + RELEASE : "") + ".js"
name + (RELEASE ? "." + RELEASE : "") + ".js"
);
name += "-" + _id;

View File

@@ -1,17 +1,17 @@
/*
FlexSearch v0.3.1
FlexSearch v0.3.2
Copyright 2019 Nextapps GmbH
Author: Thomas Wilkerling
Released under the Apache 2.0 Licence
https://github.com/nextapps-de/flexsearch
*/
'use strict';(function(d,t,q){var r;(r=q.define)&&r.amd?r([],function(){return t}):(r=q.modules)?r[d.toLowerCase()]=t:"object"===typeof exports?module.exports=t:q[d]=t})("FlexSearch",function(){function d(a){a||(a=v);this.id=a.id||G++;this.init(a);t(this,"index",function(){return this.a});t(this,"length",function(){return Object.keys(this.a).length})}function t(a,b,c){Object.defineProperty(a,b,{get:c})}function q(a,b){for(var c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}function r(a,b,c,
e,f,u,g){if(b[c])return b[c];f=f?(9-(g||6))*u+(g||6)*f:u;b[c]=f;f>=g&&(a=a[f+.5>>0],a=a[c]||(a[c]=[]),a[a.length]=e);return f}function y(a,b){if(a)for(var c=Object.keys(a),e=0,f=c.length;e<f;e++){var u=c[e],g=a[u];if(g)for(var h=0,k=g.length;h<k;h++)if(g[h]===b){1===k?delete a[u]:g.splice(h,1);break}else"object"===typeof g[h]&&y(g[h],b)}}function H(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function I(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function x(a){return"function"===typeof a}function z(a){return"undefined"===
typeof a}function B(a){for(var b=Array(a),c=0;c<a;c++)b[c]={};return b}var v={encode:"icase",mode:"forward",h:!1,cache:!1,async:!1,i:!1,threshold:0,depth:0},A=[],G=0,C=/[ -/]/g,D={},E={},F=function(){for(var a=Object.getOwnPropertyNames({}.__proto__),b={},c=0;c<a.length;c++)b[a[c]]=1;return b}();d.create=function(a){return new d(a)};d.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&A.push(new RegExp(b,"g"),a[b]);return this};d.registerEncoder=function(a,b){w[a]=b.bind(w);return this};
d.registerLanguage=function(a,b){D[a]=b.filter;E[a]=b.stemmer;return this};d.encode=function(a,b){return F[a]?b:w[a](b)};d.prototype.init=function(a){this.g=[];a||(a=v);var b=a.profile,c={};this.mode=a.mode||c.mode||this.mode||v.mode;this.threshold=z(b=a.threshold)?c.threshold||this.threshold||v.threshold:b;this.depth=z(b=a.depth)?c.depth||this.depth||v.depth:b;this.c=(b=z(b=a.encode)?c.encode:b)&&w[b]&&w[b].bind(w)||(x(b)?b:this.c||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=D[b]||b;c=
this.c;var e={};if(b)for(var f=0;f<b.length;f++){var u=c?c(b[f]):b[f];e[u]=String.fromCharCode(65E3-b.length+f)}this.filter=e}if(b=a.stemmer){a=E[b]||b;b=this.c;c=[];if(a)for(var g in a)a.hasOwnProperty(g)&&(e=b?b(g):g,c.push(new RegExp("(?=.{"+(e.length+3)+",})"+e+"$","g"),b?b(a[g]):a[g]));this.stemmer=c}this.f=B(10);this.b={};this.a={};return this};d.prototype.encode=function(a){a&&A.length&&(a=q(a,A));a&&this.g.length&&(a=q(a,this.g));a&&this.c&&(a=this.c(a));a&&this.stemmer&&(a=q(a,this.stemmer));
return a};d.prototype.addMatcher=function(a){var b=this.g,c;for(c in a)a.hasOwnProperty(c)&&b.push(new RegExp(c,"g"),a[c]);return this};d.prototype.add=function(a,b,c){if(b&&"string"===typeof b&&(a&&!F[a]||0===a))if(this.a[a]&&!c)this.update(a,b);else{b=this.encode(b);if(!b.length)return this;c=this.mode;b=x(c)?c(b):b.split(C);for(var e={_ctx:{}},f=this.threshold,u=this.depth,g=this.f,h=b.length,k=0;k<h;k++){var l=b[k];if(l){var d=l.length,m=(h-k)/h,n="";switch(c){case "reverse":case "both":for(var p=
d-1;1<=p;p--)n=l[p]+n,r(g,e,n,a,(d-p)/d,m,f);n="";case "forward":for(p=0;p<d;p++)n+=l[p],r(g,e,n,a,1,m,f);break;case "full":for(p=0;p<d;p++)for(var t=(d-p)/d,q=d;q>p;q--)n=l.substring(p,q),r(g,e,n,a,t,m,f);break;default:if(d=r(g,e,l,a,1,m,f),u&&1<h&&d>=f)for(d=e._ctx[l]||(e._ctx[l]={}),l=this.b[l]||(this.b[l]=B(10)),m=k-u,n=k+u+1,0>m&&(m=0),n>h&&(n=h);m<n;m++)m!==k&&r(l,d,b[m],a,0,10-(m<k?k-m:m-k),f)}}}this.a[a]=1}return this};d.prototype.update=function(a,b){this.a[a]&&"string"===typeof b&&(this.remove(a),
this.add(a,b,!0));return this};d.prototype.remove=function(a){if(this.a[a]){for(var b=0;10>b;b++)y(this.f[b],a);this.depth&&y(this.b,a);delete this.a[a]}return this};d.prototype.search=function(a,b,c){var e=a,f=[];if("object"===typeof a){b=a.limit;var d=a.threshold;a=a.query}d||(d=this.threshold||0);x(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(c)c(this.search(e,b,null,!0));else{if(!a||"string"!==typeof a)return f;e=this.encode(a);if(!e.length)return f;a=this.mode;a=x(a)?a(e):e.split(C);c=a.length;var g=
!0;e=[];var h={};if(1<c)if(this.depth){var k=!0;var l=a[0];h[l]=1}else a.sort(H);var q;if(!k||(q=this.b)[l])for(var m=k?1:0;m<c;m++){var n=a[m];if(n&&!h[n]){for(var p,r=!1,t=[],w=0,v=9;v>=d;v--)if(p=(k?q[l]:this.f)[v],p=p[n])t[w++]=p,r=!0;if(r)e[e.length]=1<w?e.concat.apply([],t):t[0];else{g=!1;break}h[n]=1}l=n}else g=!1;if(g)a:{d=[];f=e.length;if(1<f){e.sort(I);l={};k=e[0];q=k.length;for(a=0;a<q;)l[k[a++]]=1;for(h=g=0;++h<f;){m=!1;n=h===f-1;k=e[h];q=k.length;for(a=0;a<q;)if(c=k[a++],l[c]&&l[c]===
h){if(n){if(d[g++]=c,b&&g===b){f=d;break a}}else l[c]=h+1;m=!0}if(!m)break}}else f&&(d=e[0],b&&d.length>b&&(d=d.slice(0,b)));f=d}return f}};d.prototype.clear=function(){this.destroy();return this.init()};d.prototype.destroy=function(){this.filter=this.stemmer=this.f=this.b=this.a=null;return this};var w={icase:function(a){return a.toLowerCase()}};return d}(!1),this);
'use strict';(function(f,t,u){let k;(k=u.define)&&k.amd?k([],function(){return t}):(k=u.modules)?k[f.toLowerCase()]=t:"object"===typeof exports?module.exports=t:u[f]=t})("FlexSearch",function(){function f(a){a||(a=w);this.id=a.id||G++;this.init(a);t(this,"index",function(){return this.a});t(this,"length",function(){return Object.keys(this.a).length})}function t(a,b,c){Object.defineProperty(a,b,{get:c})}function u(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 y(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]&&y(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 x(a){return"function"===typeof a}
function z(a){return"undefined"===typeof a}function B(a){const b=Array(a);for(let c=0;c<a;c++)b[c]={};return b}const w={encode:"icase",b:"forward",i:!1,cache:!1,async:!1,j:!1,threshold:0,depth:0},A=[];let G=0;const C=/[ -/]/g,D={},E={},F=function(){const a=Object.getOwnPropertyNames({}.__proto__),b={};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)&&A.push(new RegExp(b,"g"),a[b]);return this};f.registerEncoder=
function(a,b){v[a]=b.bind(v);return this};f.registerLanguage=function(a,b){D[a]=b.filter;E[a]=b.stemmer;return this};f.encode=function(a,b){return F[a]?b:v[a](b)};f.prototype.init=function(a){this.h=[];a||(a=w);var b=a.profile,c={};this.b=a.tokenize||c.b||this.b||w.b;this.threshold=z(b=a.threshold)?c.threshold||this.threshold||w.threshold:b;this.depth=z(b=a.depth)?c.depth||this.depth||w.depth:b;this.f=(b=z(b=a.encode)?c.encode:b)&&v[b]&&v[b].bind(v)||(x(b)?b:this.f||!1);(b=a.matcher)&&this.addMatcher(b);
if(b=a.filter){b=D[b]||b;c=this.f;var e={};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=E[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=B(10);this.c={};this.a={};return this};f.prototype.encode=function(a){a&&A.length&&(a=u(a,A));a&&this.h.length&&(a=u(a,this.h));a&&this.f&&(a=this.f(a));
a&&this.stemmer&&(a=u(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&&!F[a]||0===a))if(this.a[a]&&!c)this.update(a,b);else{b=this.encode(b);if(!b.length)return this;c=this.b;b=x(c)?c(b):b.split(C);const f={_ctx:{}},l=this.threshold,r=this.depth,q=this.g,n=b.length;for(let p=0;p<n;p++){var e=b[p];if(e){var d=e.length,h=(n-p)/n,
g="";switch(c){case "reverse":case "both":for(var m=d-1;1<=m;m--)g=e[m]+g,k(q,f,g,a,(d-m)/d,h,l);g="";case "forward":for(m=0;m<d;m++)g+=e[m],k(q,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(q,f,g,a,b,h,l)}break;default:if(d=k(q,f,e,a,1,h,l),r&&1<n&&d>=l)for(d=f._ctx[e]||(f._ctx[e]={}),e=this.c[e]||(this.c[e]=B(10)),h=p-r,g=p+r+1,0>h&&(h=0),g>n&&(g=n);h<g;h++)h!==p&&k(e,d,b[h],a,0,10-(h<p?p-h:h-p),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++)y(this.g[b],a);this.depth&&y(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);x(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(c)c(this.search(e,b,null,!0));else{if(!a||"string"!==typeof a)return d;e=this.encode(a);if(!e.length)return d;
a=this.b;a=x(a)?a(e):e.split(C);c=a.length;var g=!0;e=[];var f={};if(1<c)if(this.depth){var k=!0;var l=a[0];f[l]=1}else a.sort(H);var r;if(!k||(r=this.c)[l])for(var q=k?1:0;q<c;q++){var n=a[q];if(n&&!f[n]){let a=!1;const b=[];let c=0;for(let d=9;d>=h;d--){var p=(k?r[l]:this.g)[d];if(p=p[n])b[c++]=p,a=!0}if(a)e[e.length]=1<c?e.concat.apply([],b):b[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);l={};k=e[0];r=k.length;for(a=0;a<r;)l[k[a++]]=1;for(f=g=0;++f<d;){q=!1;
n=f===d-1;k=e[f];r=k.length;for(a=0;a<r;)if(c=k[a++],l[c]&&l[c]===f){if(n){if(h[g++]=c,b&&g===b){d=h;break a}}else l[c]=f+1;q=!0}if(!q)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 v={icase:function(a){return a.toLowerCase()}};return f}(!1),this);

54
flexsearch.min.js vendored
View File

@@ -1,36 +1,30 @@
/*
FlexSearch v0.3.1
FlexSearch v0.3.2
Copyright 2019 Nextapps GmbH
Author: Thomas Wilkerling
Released under the Apache 2.0 Licence
https://github.com/nextapps-de/flexsearch
*/
'use strict';function J(g){var h=0;return function(){return h<g.length?{done:!1,value:g[h++]}:{done:!0}}}function K(g){var h="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return h?h.call(g):{next:J(g)}}var S="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,T="function"==typeof Object.defineProperties?Object.defineProperty:function(g,h,e){g!=Array.prototype&&g!=Object.prototype&&(g[h]=e.value)};
function U(g,h){if(h){var e=S;g=g.split(".");for(var k=0;k<g.length-1;k++){var a=g[k];a in e||(e[a]={});e=e[a]}g=g[g.length-1];k=e[g];h=h(k);h!=k&&null!=h&&T(e,g,{configurable:!0,writable:!0,value:h})}}
U("Promise",function(g){function h(d){this.b=0;this.g=void 0;this.a=[];var a=this.c();try{d(a.resolve,a.reject)}catch(D){a.reject(D)}}function e(){this.a=null}function k(d){return d instanceof h?d:new h(function(a){a(d)})}if(g)return g;e.prototype.b=function(d){if(null==this.a){this.a=[];var a=this;this.c(function(){a.g()})}this.a.push(d)};var a=S.setTimeout;e.prototype.c=function(d){a(d,0)};e.prototype.g=function(){for(;this.a&&this.a.length;){var d=this.a;this.a=[];for(var a=0;a<d.length;++a){var h=
d[a];d[a]=null;try{h()}catch(v){this.f(v)}}}this.a=null};e.prototype.f=function(d){this.c(function(){throw d;})};h.prototype.c=function(){function d(d){return function(e){h||(h=!0,d.call(a,e))}}var a=this,h=!1;return{resolve:d(this.o),reject:d(this.f)}};h.prototype.o=function(d){if(d===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(d instanceof h)this.s(d);else{a:switch(typeof d){case "object":var a=null!=d;break a;case "function":a=!0;break a;default:a=!1}a?this.m(d):this.i(d)}};
h.prototype.m=function(a){var d=void 0;try{d=a.then}catch(D){this.f(D);return}"function"==typeof d?this.u(d,a):this.i(a)};h.prototype.f=function(a){this.j(2,a)};h.prototype.i=function(a){this.j(1,a)};h.prototype.j=function(a,h){if(0!=this.b)throw Error("Cannot settle("+a+", "+h+"): Promise already settled in state"+this.b);this.b=a;this.g=h;this.l()};h.prototype.l=function(){if(null!=this.a){for(var a=0;a<this.a.length;++a)l.b(this.a[a]);this.a=null}};var l=new e;h.prototype.s=function(a){var d=this.c();
a.w(d.resolve,d.reject)};h.prototype.u=function(a,h){var d=this.c();try{a.call(h,d.resolve,d.reject)}catch(v){d.reject(v)}};h.prototype.then=function(a,e){function d(a,d){return"function"==typeof a?function(d){try{g(a(d))}catch(E){k(E)}}:d}var g,k,m=new h(function(a,d){g=a;k=d});this.w(d(a,g),d(e,k));return m};h.prototype.catch=function(a){return this.then(void 0,a)};h.prototype.w=function(a,h){function d(){switch(e.b){case 1:a(e.g);break;case 2:h(e.g);break;default:throw Error("Unexpected state: "+
e.b);}}var e=this;null==this.a?l.b(d):this.a.push(d)};h.resolve=k;h.reject=function(a){return new h(function(d,h){h(a)})};h.race=function(a){return new h(function(d,h){for(var e=K(a),g=e.next();!g.done;g=e.next())k(g.value).w(d,h)})};h.all=function(a){var d=K(a),e=d.next();return e.done?k([]):new h(function(a,h){function g(d){return function(h){m[d]=h;l--;0==l&&a(m)}}var m=[],l=0;do m.push(void 0),l++,k(e.value).w(g(m.length-1),h),e=d.next();while(!e.done)})};return h});
(function(g,h,e){var k;(k=e.define)&&k.amd?k([],function(){return h}):(k=e.modules)?k[g.toLowerCase()]=h:"object"===typeof exports?module.exports=h:e[g]=h})("FlexSearch",function aa(g){function e(b){E(b)&&(b=L[b]);b||(b=w);this.id=b.id||ba++;this.init(b);k(this,"index",function(){return this.a});k(this,"length",function(){return Object.keys(this.a).length})}function k(b,c,a){Object.defineProperty(b,c,{get:a})}function a(b){return new RegExp(b,"g")}function l(b,c){for(var a=0;a<c.length;a+=2)b=b.replace(c[a],
c[a+1]);return b}function d(b,c,a,f,A,d,e){if(c[a])return c[a];A=A?(9-(e||6))*d+(e||6)*A:d;c[a]=A;A>=e&&(b=b[A+.5>>0],b=b[a]||(b[a]=[]),b[b.length]=f);return A}function m(b,c){if(b)for(var a=Object.keys(b),f=0,A=a.length;f<A;f++){var d=a[f],e=b[d];if(e)for(var r=0,g=e.length;r<g;r++)if(e[r]===c){1===g?delete b[d]:e.splice(r,1);break}else"object"===typeof e[r]&&m(e[r],c)}}function D(b){var c=[];if(!b)return c;for(var a=0,f=0,d=0,e="",g=b.length,r=0;r<g;r++){var z=b[r];"a"===z||"e"===z||"i"===z||"o"===
z||"u"===z||"y"===z?a++:f++;" "!==z&&(e+=z);if(" "===z||a>=(8<g?2:1)&&2<=f||2<=a&&f>=(8<g?2:1)||r===g-1)e&&(c[d]&&2<e.length&&d++,c[d]=c[d]?c[d]+e:e," "===z&&d++,e=""),f=a=0}return c}function v(b){for(var c="",a="",f="",d=0;d<b.length;d++){var e=b[d];if(e!==a)if(d&&"h"===e){if(f="a"===f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f,("a"===a||"e"===a||"i"===a||"o"===a||"u"===a||"y"===a)&&f||" "===a)c+=e}else c+=e;f=d===b.length-1?"":b[d+1];a=e}return c}function V(b,c){var a={};if(b)for(var f=0;f<b.length;f++){var d=
c?c(b[f]):b[f];a[d]=String.fromCharCode(65E3-b.length+f)}return a}function Z(b,c){var d=[];if(b)for(var f in b)if(b.hasOwnProperty(f)){var e=c?c(f):f;d.push(a("(?=.{"+(e.length+3)+",})"+e+"$"),c?c(b[f]):b[f])}return d}function W(b,c){b=b.length-c.length;return 0>b?1:b?-1:0}function X(b,c){b=b.length-c.length;return 0>b?-1:b?1:0}function Y(b,c,a){var f=[],d=[],e=b.length;if(1<e){b.sort(X);for(var g={},r=b[0],t=r.length,k=0;k<t;)g[r[k++]]=1;for(var n,p=0,q=0;++q<e;){var u=!1,m=q===e-1;d=[];r=b[q];t=
r.length;for(k=0;k<t;)if(n=r[k++],g[n]){var l=g[n];if(l===q){if(m){if(f[p++]=n,c&&p===c)return f}else g[n]=q+1;u=!0}else a&&(l=d[l]||(d[l]=[]),l[l.length]=n)}if(!u&&!a)break}if(a&&(p=f.length,(q=d.length)&&(!c||p<c)))for(;q--;)if(n=d[q])for(b=0,a=n.length;b<a;b++)if(f[p++]=n[b],c&&p===c)return f}else e&&(f=b[0],c&&f.length>c&&(f=f.slice(0,c)));return f}function E(b){return"string"===typeof b}function H(b){return"function"===typeof b}function x(b){return"undefined"===typeof b}function B(b){b.D||(b.D=
M(function(){b.D=0;var c=b.async;c&&(b.async=!1);if(b.b.length){for(var a=Date.now(),f;(f=b.b.shift())||0===f;){var d=b.c[f];switch(d[0]){case C.add:b.add(d[1],d[2]);break;case C.remove:b.remove(d[1])}delete b.c[f];if(100<Date.now()-a)break}b.b.length&&B(b)}c&&(b.async=c)},1,"search-async-"+b.id))}function N(b){for(var c=Array(b),a=0;a<b;a++)c[a]={};return c}function ca(b,c,a,f){b=g("flexsearch","id"+b,function(){var b,c;self.onmessage=function(a){if(a=a.data)if(a.search){var f=c.search(a.content,
a.threshold?{limit:a.limit,threshold:a.threshold}:a.limit);self.postMessage({id:b,content:a.content,limit:a.limit,result:f})}else a.add?c.add(a.id,a.content):a.update?c.update(a.id,a.content):a.remove?c.remove(a.id):a.clear?c.clear():a.register&&(b=a.id,a.options.cache=!1,a.options.async=!0,a.options.worker=!1,c=(new Function(a.register.substring(a.register.indexOf("{")+1,a.register.lastIndexOf("}"))))(),c=new c(a.options))}},function(b){(b=b.data)&&b.result&&f(b.id,b.content,b.result,b.limit)},c);
var d=aa.toString();a.id=c;b.postMessage(c,{register:d,options:a,id:c});return b}var w={encode:"icase",mode:"forward",v:!1,cache:!1,async:!1,h:!1,threshold:0,depth:0},L={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"strict",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},F=[],ba=0,C=
{add:0,update:1,remove:2},O=a("[ -/]"),P={},Q={},R=function(){for(var b=Object.getOwnPropertyNames({}.__proto__),c={},a=0;a<b.length;a++)c[b[a]]=1;return c}();e.create=function(b){return new e(b)};e.registerMatcher=function(b){for(var c in b)b.hasOwnProperty(c)&&F.push(a(c),b[c]);return this};e.registerEncoder=function(b,c){y[b]=c.bind(y);return this};e.registerLanguage=function(b,c){P[b]=c.filter;Q[b]=c.stemmer;return this};e.encode=function(b,c){return R[b]?c:y[b](c)};e.prototype.init=function(b){this.C=
[];b||(b=w);var c=b.profile,a=c?L[c]:{};if(c=b.worker)if(Worker){var f=this,d=parseInt(c,10)||4;f.l=-1;f.m=0;f.f=[];f.B=null;f.i=Array(d);for(var e=0;e<d;e++)f.i[e]=ca(f.id,e,b,function(b,c,a,d){if(f.m!==f.h)return f.f=f.f.concat(a),f.m++,d&&f.f.length>=d&&(f.m=f.h),f.B&&f.m===f.h&&(f.cache&&f.g.set(c,f.f),f.B(f.f),f.f=[]),f})}else b.worker=!1,this.i=null;this.mode=b.mode||a.mode||this.mode||w.mode;this.async=x(c=b.async)?this.async||w.async:c;this.h=x(c=b.worker)?this.h||w.h:c;this.threshold=x(c=
b.threshold)?a.threshold||this.threshold||w.threshold:c;this.depth=x(c=b.depth)?a.depth||this.depth||w.depth:c;this.v=x(c=b.suggest)?this.v||w.v:c;this.o=(c=x(c=b.encode)?a.encode:c)&&y[c]&&y[c].bind(y)||(H(c)?c:this.o||!1);(c=b.matcher)&&this.addMatcher(c);if(c=b.filter)this.filter=V(P[c]||c,this.o);if(c=b.stemmer)this.stemmer=Z(Q[c]||c,this.o);this.u=N(10);this.j={};this.a={};this.c={};this.b=[];this.D=0;this.s=!0;this.g=(this.cache=c=x(c=b.cache)?this.cache||w.cache:c)?new da(c):!1;return this};
e.prototype.encode=function(b){b&&F.length&&(b=l(b,F));b&&this.C.length&&(b=l(b,this.C));b&&this.o&&(b=this.o(b));b&&this.stemmer&&(b=l(b,this.stemmer));return b};e.prototype.addMatcher=function(b){var c=this.C,d;for(d in b)b.hasOwnProperty(d)&&c.push(a(d),b[d]);return this};e.prototype.add=function(b,c,a){if(c&&E(c)&&(b&&!R[b]||0===b))if(this.a[b]&&!a)this.update(b,c);else{if(this.h)return++this.l>=this.i.length&&(this.l=0),this.i[this.l].postMessage(this.l,{add:!0,id:b,content:c}),this.a[b]=""+
this.l,this;if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[C.add,b,c],B(this),this;c=this.encode(c);if(!c.length)return this;a=this.mode;c=H(a)?a(c):"ngram"===a?D(c):c.split(O);for(var f={_ctx:{}},e=this.threshold,g=this.depth,k=this.u,r=c.length,t=0;t<r;t++){var l=c[t];if(l){var n=l.length,p=(r-t)/r,q="";switch(a){case "reverse":case "both":for(var u=n-1;1<=u;u--)q=l[u]+q,d(k,f,q,b,(n-u)/n,p,e);q="";case "forward":for(u=0;u<n;u++)q+=l[u],d(k,f,q,b,1,p,e);break;case "full":for(u=
0;u<n;u++)for(var m=(n-u)/n,v=n;v>u;v--)q=l.substring(u,v),d(k,f,q,b,m,p,e);break;default:if(n=d(k,f,l,b,1,p,e),g&&1<r&&n>=e)for(n=f._ctx[l]||(f._ctx[l]={}),l=this.j[l]||(this.j[l]=N(10)),p=t-g,q=t+g+1,0>p&&(p=0),q>r&&(q=r);p<q;p++)p!==t&&d(l,n,c[p],b,0,10-(p<t?t-p:p-t),e)}}}this.a[b]=1;this.s=!1}return this};e.prototype.update=function(b,c){this.a[b]&&E(c)&&(this.remove(b),this.add(b,c,!0));return this};e.prototype.remove=function(b){if(this.a[b]){if(this.h){var c=this.a[b];this.i[c].postMessage(c,
{remove:!0,id:b});delete this.a[b];return this}if(this.async)return this.c[b]||(this.b[this.b.length]=b),this.c[b]=[C.remove,b],B(this),this;for(c=0;10>c;c++)m(this.u[c],b);this.depth&&m(this.j,b);delete this.a[b];this.s=!1}return this};e.prototype.search=function(b,c,a,f){var d=b,e=[];if("object"===typeof b){(a=b.callback||c)&&(d.callback=null);c=b.limit;var g=b.threshold;b=b.query}g||(g=this.threshold||0);H(c)?(a=c,c=1E3):c||0===c||(c=1E3);if(this.h)for(this.B=a,this.m=0,this.f=[],e=0;e<this.h;e++)this.i[e].postMessage(e,
{search:!0,limit:c,threshold:g,content:b});else if(a){var k=this;M(function(){a(k.search(d,c,null,!0));k=null},1,"search-"+this.id)}else{if(!f&&this.async){var l=this;return new Promise(function(b){b(l.search(d,c,null,!0));l=null})}if(!b||!E(b))return e;d=b;if(this.cache)if(this.s){if(f=this.g.get(b))return f}else this.g.clear(),this.s=!0;d=this.encode(d);if(!d.length)return e;f=this.mode;f=H(f)?f(d):"ngram"===f?D(d):d.split(O);var t=f.length,n=!0,p=[],q={};if(1<t)if(this.depth){var m=!0;var v=f[0];
q[v]=1}else f.sort(W);var w;if(!m||(w=this.j)[v])for(var x=m?1:0;x<t;x++){var y=f[x];if(y&&!q[y]){var G=void 0;G=void 0;for(var C=!1,B=[],F=0,I=9;I>=g;I--)if(G=(m?w[v]:this.u)[I],G=G[y])B[F++]=G,C=!0;if(C)p[p.length]=1<F?p.concat.apply([],B):B[0];else if(!this.v){n=!1;break}q[y]=1}v=y}else n=!1;n&&(e=Y(p,c,this.v));this.cache&&this.g.set(b,e);return e}};e.prototype.clear=function(){this.destroy();return this.init()};e.prototype.destroy=function(){this.cache&&(this.g.clear(),this.g=null);this.filter=
this.stemmer=this.u=this.j=this.a=this.c=this.b=null;return this};var y={icase:function(b){return b.toLowerCase()},simple:function(){var b=[a("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",a("[\u00e8\u00e9\u00ea\u00eb]"),"e",a("[\u00ec\u00ed\u00ee\u00ef]"),"i",a("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",a("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",a("[\u00fd\u0177\u00ff]"),"y",a("\u00f1"),"n",a("\u00e7"),"c",a("\u00df"),"s",a(" & ")," and ",a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(c){c=
l(c.toLowerCase(),b);return" "!==c?c:""}}(),advanced:function(){var b=[a("ae"),"a",a("ai"),"ei",a("ay"),"ei",a("ey"),"ei",a("oe"),"o",a("ue"),"u",a("ie"),"i",a("sz"),"s",a("zs"),"s",a("sh"),"s",a("ck"),"k",a("cc"),"k",a("dt"),"t",a("ph"),"f",a("pf"),"f",a("ou"),"o",a("uo"),"u"];return function(c,a){if(!c)return c;c=this.simple(c);2<c.length&&(c=l(c,b));a||1<c.length&&(c=v(c));return c}}(),extra:function(){var b=[a("p"),"b",a("z"),"s",a("[cgq]"),"k",a("n"),"m",a("d"),"t",a("[vw]"),"f",a("[aeiouy]"),
""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(var c=0;c<a.length;c++){var d=a[c];1<d.length&&(a[c]=d[0]+l(d.substring(1),b))}a=a.join(" ");a=v(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(a){return v(l(a.toLowerCase(),b))}}()},M=function(){var b={};return function(a,d,f){var c=b[f];c&&clearTimeout(c);return b[f]=setTimeout(a,d)}}(),da=function(){function a(a){this.clear();this.A=!0!==a&&
a}a.prototype.clear=function(){this.cache={};this.count={};this.index={};this.a=[]};a.prototype.set=function(a,b){if(this.A&&x(this.cache[a])){var c=this.a.length;if(c===this.A){c--;var d=this.a[c];delete this.cache[d];delete this.count[d];delete this.index[d]}this.index[a]=c;this.a[c]=a;this.count[a]=-1;this.cache[a]=b;this.get(a)}else this.cache[a]=b};a.prototype.get=function(a){var b=this.cache[a];if(this.A&&b){var c=++this.count[a],d=this.index,e=d[a];if(0<e){for(var g=this.a,k=e;this.count[g[--e]]<=
c&&-1!==e;);e++;if(e!==k){for(c=k;c>e;c--)k=g[c-1],g[c]=k,d[k]=c;g[e]=a;d[a]=e}}}return b};return a}();return e}(function(){var g=Object.create(null),h="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(e,k,a,l,d){var m=e;e=h?URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"})):"../"+m+".min.js";m+="-"+k;g[m]||(g[m]=[]);g[m][d]=new Worker(e);g[m][d].onmessage=l;return{postMessage:function(a,d){g[m][a].postMessage(d)}}}}()),this);
'use strict';(function(q,z,h){let t;(t=h.define)&&t.amd?t([],function(){return z}):(t=h.modules)?t[q.toLowerCase()]=z:"object"===typeof exports?module.exports=z:h[q]=z})("FlexSearch",function Q(q){function h(a){B(a)&&(a=H[a]);a||(a=v);this.id=a.id||R++;this.init(a);t(this,"index",function(){return this.a});t(this,"length",function(){return Object.keys(this.a).length})}function t(a,b,d){Object.defineProperty(a,b,{get:d})}function e(a){return new RegExp(a,"g")}function w(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,c,f,k,g){if(b[d])return b[d];f=f?(9-(g||6))*k+(g||6)*f:k;b[d]=f;f>=g&&(a=a[f+.5>>0],a=a[d]||(a[d]=[]),a[a.length]=c);return f}function r(a,b){if(a){const d=Object.keys(a);for(let c=0,f=d.length;c<f;c++){const f=d[c],g=a[f];if(g)for(let c=0,d=g.length;c<d;c++)if(g[c]===b){1===d?delete a[f]:g.splice(c,1);break}else"object"===typeof g[c]&&r(g[c],b)}}}function J(a){const b=[];if(!a)return b;let d=0,c=0,f=0,k="";const g=a.length;for(let l=0;l<g;l++){const e=
a[l];"a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e?d++:c++;" "!==e&&(k+=e);if(" "===e||d>=(8<g?2:1)&&2<=c||2<=d&&c>=(8<g?2:1)||l===g-1)k&&(b[f]&&2<k.length&&f++,b[f]=b[f]?b[f]+k:k," "===e&&f++,k=""),c=d=0}return b}function E(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 S(a,b){const d={};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 k=a.length;if(1<k){a.sort(V);const l={};let e=a[0],h=e.length,
u=0;for(;u<h;)l[e[u++]]=1;let n,p=0,m=0;for(;++m<k;){let I=!1;const X=m===k-1;f=[];e=a[m];h=e.length;for(u=0;u<h;)if(n=e[u++],l[n]){var g=l[n];if(g===m){if(X){if(c[p++]=n,b&&p===b)return c}else l[n]=m+1;I=!0}else d&&(g=f[g]||(f[g]=[]),g[g.length]=n)}if(!I&&!d)break}if(d&&(p=c.length,(m=f.length)&&(!b||p<b)))for(;m--;)if(n=f[m])for(let a=0,d=n.length;a<d;a++)if(c[p++]=n[a],b&&p===b)return c}else k&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function B(a){return"string"===typeof a}function C(a){return"function"===
typeof a}function y(a){return"undefined"===typeof a}function F(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 D.add:a.add(d[1],d[2]);break;case D.remove:a.remove(d[1])}delete a.g[f];if(100<Date.now()-b)break}a.f.length&&F(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]={};return b}function Y(a,b,d,c){a=q("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=Q.toString();d.id=b;a.postMessage(b,{register:f,options:d,id:b});return a}const v={encode:"icase",b:"forward",u:!1,cache:!1,async:!1,c:!1,threshold:0,depth:0},H={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}},G=[];let R=0;const D={add:0,update:1,remove:2},M=e("[ -/]"),N={},O={},P=function(){const a=Object.getOwnPropertyNames({}.__proto__),b={};for(let d=0;d<a.length;d++)b[a[d]]=1;return b}();h.create=function(a){return new h(a)};h.registerMatcher=function(a){for(let b in a)a.hasOwnProperty(b)&&G.push(e(b),a[b]);return this};h.registerEncoder=function(a,b){A[a]=b.bind(A);return this};h.registerLanguage=function(a,b){N[a]=b.filter;O[a]=b.stemmer;return this};h.encode=function(a,
b){return P[a]?b:A[a](b)};h.prototype.init=function(a){this.C=[];a||(a=v);let b=a.profile;const d=b?H[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]=Y(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||v.b;this.async=y(b=a.async)?this.async||v.async:
b;this.c=y(b=a.worker)?this.c||v.c:b;this.threshold=y(b=a.threshold)?d.threshold||this.threshold||v.threshold:b;this.depth=y(b=a.depth)?d.depth||this.depth||v.depth:b;this.u=y(b=a.suggest)?this.u||v.u:b;this.s=(b=y(b=a.encode)?d.encode:b)&&A[b]&&A[b].bind(A)||(C(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={};this.a={};this.g={};this.f=[];this.D=0;this.v=!0;this.i=(this.cache=b=y(b=
a.cache)?this.cache||v.cache:b)?new Z(b):!1;return this};h.prototype.encode=function(a){a&&G.length&&(a=w(a,G));a&&this.C.length&&(a=w(a,this.C));a&&this.s&&(a=this.s(a));a&&this.stemmer&&(a=w(a,this.stemmer));return a};h.prototype.addMatcher=function(a){const b=this.C;for(const d in a)a.hasOwnProperty(d)&&b.push(e(d),a[d]);return this};h.prototype.add=function(a,b,d){if(b&&B(b)&&(a&&!P[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]=[D.add,a,b],F(this),this;b=this.encode(b);if(!b.length)return this;d=this.b;b=C(d)?d(b):"ngram"===d?J(b):b.split(M);const k={_ctx:{}},h=this.threshold,u=this.depth,n=this.w,p=b.length;for(let m=0;m<p;m++){var c=b[m];if(c){var f=c.length,e=(p-m)/p,g="";switch(d){case "reverse":case "both":for(var l=f-1;1<=l;l--)g=c[l]+g,x(n,k,g,a,(f-l)/f,e,h);g="";case "forward":for(l=0;l<f;l++)g+=
c[l],x(n,k,g,a,1,e,h);break;case "full":for(l=0;l<f;l++){const b=(f-l)/f;for(let d=f;d>l;d--)g=c.substring(l,d),x(n,k,g,a,b,e,h)}break;default:if(f=x(n,k,c,a,1,e,h),u&&1<p&&f>=h)for(f=k._ctx[c]||(k._ctx[c]={}),c=this.l[c]||(this.l[c]=L(10)),e=m-u,g=m+u+1,0>e&&(e=0),g>p&&(g=p);e<g;e++)e!==m&&x(c,f,b[e],a,0,10-(e<m?m-e:e-m),h)}}}this.a[a]=1;this.v=!1}return this};h.prototype.update=function(a,b){this.a[a]&&B(b)&&(this.remove(a),this.add(a,b,!0));return this};h.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]=[D.remove,a],F(this),this;for(b=0;10>b;b++)r(this.w[b],a);this.depth&&r(this.l,a);delete this.a[a];this.v=!1}return this};h.prototype.search=function(a,b,d,c){let f=a,e;var g=[];"object"===typeof a&&((d=a.callback||b)&&(f.callback=null),b=a.limit,e=a.threshold,a=a.query);e||(e=this.threshold||0);C(b)?(d=b,b=1E3):b||0===b||(b=1E3);if(this.c)for(this.B=
d,this.o=0,this.h=[],g=0;g<this.c;g++)this.j[g].postMessage(g,{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||!B(a))return g;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 g;c=this.b;c=C(c)?c(f):"ngram"===
c?J(f):f.split(M);var h=c.length,r=!0,q=[],u={};if(1<h)if(this.depth){var n=!0;var p=c[0];u[p]=1}else c.sort(U);var m;if(!n||(m=this.l)[p])for(let a=n?1:0;a<h;a++){const b=c[a];if(b&&!u[b]){let a=!1;const c=[];let d=0;for(let f=9;f>=e;f--){var t=(n?m[p]:this.w)[f];if(t=t[b])c[d++]=t,a=!0}if(a)q[q.length]=1<d?q.concat.apply([],c):c[0];else if(!this.u){r=!1;break}u[b]=1}p=b}else r=!1;r&&(g=W(q,b,this.u));this.cache&&this.i.set(a,g);return g}};h.prototype.clear=function(){this.destroy();return this.init()};
h.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 A={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\\s+")," "];return function(b){b=w(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=w(b,a));d||1<b.length&&(b=E(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]+w(c.substring(1),a))}b=b.join(" ");b=E(b)}return b}}(),balance:function(){const a=[e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s\\s+")," "];return function(b){return E(w(b.toLowerCase(),a))}}()},K=function(){const a={};return function(b,d,c){const f=a[c];f&&clearTimeout(f);
return a[c]=setTimeout(b,d)}}(),Z=function(){function a(a){this.clear();this.A=!0!==a&&a}a.prototype.clear=function(){this.cache={};this.count={};this.index={};this.a=[]};a.prototype.set=function(a,d){if(this.A&&y(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 f=this.a;for(var e=d;this.count[f[--d]]<=c&&-1!==d;);d++;if(d!==e){for(c=e;c>d;c--)e=f[c-1],f[c]=e,b[e]=c;f[d]=a;b[a]=d}}}return b};return a}();return h}(function(){const q=Object.create(null),z="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(h,t,e,w,x){let r=h;h=z?URL.createObjectURL(new Blob(["("+e.toString()+")()"],{type:"text/javascript"})):r+".min.js";r+="-"+t;q[r]||(q[r]=[]);q[r][x]=
new Worker(h);q[r][x].onmessage=w;return{postMessage:function(e,h){q[r][e].postMessage(h)}}}}()),this);

View File

@@ -1,6 +1,6 @@
{
"name": "flexsearch",
"version": "0.3.1",
"version": "0.3.2",
"description": "Next-Generation full text search library with zero dependencies.",
"homepage": "https://github.com/nextapps-de/flexsearch/",
"author": "Thomas Wilkerling",
@@ -28,8 +28,9 @@
"build-light": "node compile RELEASE=light DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-compact": "node compile RELEASE=compact DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CACHE=false SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-custom": "node compile RELEASE=custom DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
"build-es5": "node compile RELEASE=es5 DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false LANGUAGE_OUT=ECMASCRIPT5_STRICT",
"build-lang": "node compile RELEASE=lang",
"build-all": "npm run build && npm run build-light && npm run build-compact && npm run build-lang",
"build-all": "npm run build && npm run build-light && npm run build-compact && npm run build-es5 && npm run build-lang",
"test-production": "nyc --reporter=html --reporter=text mocha --timeout=3000 test --exit",
"test-light": "nyc --reporter=html --reporter=text mocha --timeout=3000 test/ --exit",
"test-develop": "nyc --reporter=html --reporter=text mocha --timeout=3000 --exit",

View File

@@ -360,7 +360,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
html += "<tr>" +
"<td>" + test + "</td>" +
"<td id=\"test-" + test + "\">wait ...</td>" +
"<td id=\"test-" + test + "\">indexing ...</td>" +
"</tr>"
}
}
@@ -443,7 +443,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
console.log(key + ":", duration);
document.getElementById("test-" + key).textContent = /*format_number*/((1000 / duration * loops + 0.5) >> 0) + " op/s";
document.getElementById("test-" + key).textContent = /*format_number*/(((1000 / duration * loops * 10 + 0.5) >> 0) / 10) + " op/s";
if(++index < keys.length){

36
test/flexsearch.es5.js Normal file
View File

@@ -0,0 +1,36 @@
/*
FlexSearch v0.3.2
Copyright 2019 Nextapps GmbH
Author: Thomas Wilkerling
Released under the Apache 2.0 Licence
https://github.com/nextapps-de/flexsearch
*/
'use strict';function J(g){var h=0;return function(){return h<g.length?{done:!1,value:g[h++]}:{done:!0}}}function K(g){var h="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return h?h.call(g):{next:J(g)}}var S="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,T="function"==typeof Object.defineProperties?Object.defineProperty:function(g,h,e){g!=Array.prototype&&g!=Object.prototype&&(g[h]=e.value)};
function U(g,h){if(h){var e=S;g=g.split(".");for(var k=0;k<g.length-1;k++){var a=g[k];a in e||(e[a]={});e=e[a]}g=g[g.length-1];k=e[g];h=h(k);h!=k&&null!=h&&T(e,g,{configurable:!0,writable:!0,value:h})}}
U("Promise",function(g){function h(d){this.b=0;this.g=void 0;this.a=[];var a=this.c();try{d(a.resolve,a.reject)}catch(D){a.reject(D)}}function e(){this.a=null}function k(d){return d instanceof h?d:new h(function(a){a(d)})}if(g)return g;e.prototype.b=function(d){if(null==this.a){this.a=[];var a=this;this.c(function(){a.g()})}this.a.push(d)};var a=S.setTimeout;e.prototype.c=function(d){a(d,0)};e.prototype.g=function(){for(;this.a&&this.a.length;){var d=this.a;this.a=[];for(var a=0;a<d.length;++a){var h=
d[a];d[a]=null;try{h()}catch(v){this.f(v)}}}this.a=null};e.prototype.f=function(d){this.c(function(){throw d;})};h.prototype.c=function(){function d(d){return function(e){h||(h=!0,d.call(a,e))}}var a=this,h=!1;return{resolve:d(this.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(D){this.f(D);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(v){d.reject(v)}};h.prototype.then=function(a,e){function d(a,d){return"function"==typeof a?function(d){try{g(a(d))}catch(E){k(E)}}:d}var g,k,m=new h(function(a,d){g=a;k=d});this.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=K(a),g=e.next();!g.done;g=e.next())k(g.value).A(d,h)})};h.all=function(a){var d=K(a),e=d.next();return e.done?k([]):new h(function(a,h){function g(d){return function(h){m[d]=h;l--;0==l&&a(m)}}var m=[],l=0;do m.push(void 0),l++,k(e.value).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 aa(g){function e(b){E(b)&&(b=L[b]);b||(b=w);this.id=b.id||ba++;this.init(b);k(this,"index",function(){return this.a});k(this,"length",function(){return Object.keys(this.a).length})}function k(b,c,a){Object.defineProperty(b,c,{get:a})}function a(b){return new RegExp(b,"g")}function l(b,c){for(var a=0;a<c.length;a+=2)b=b.replace(c[a],
c[a+1]);return b}function d(b,c,a,f,A,d,e){if(c[a])return c[a];A=A?(9-(e||6))*d+(e||6)*A:d;c[a]=A;A>=e&&(b=b[A+.5>>0],b=b[a]||(b[a]=[]),b[b.length]=f);return A}function m(b,c){if(b)for(var a=Object.keys(b),f=0,A=a.length;f<A;f++){var d=a[f],e=b[d];if(e)for(var r=0,g=e.length;r<g;r++)if(e[r]===c){1===g?delete b[d]:e.splice(r,1);break}else"object"===typeof e[r]&&m(e[r],c)}}function D(b){var c=[];if(!b)return c;for(var a=0,f=0,d=0,e="",g=b.length,r=0;r<g;r++){var z=b[r];"a"===z||"e"===z||"i"===z||"o"===
z||"u"===z||"y"===z?a++:f++;" "!==z&&(e+=z);if(" "===z||a>=(8<g?2:1)&&2<=f||2<=a&&f>=(8<g?2:1)||r===g-1)e&&(c[d]&&2<e.length&&d++,c[d]=c[d]?c[d]+e:e," "===z&&d++,e=""),f=a=0}return c}function v(b){for(var c="",a="",f="",d=0;d<b.length;d++){var e=b[d];if(e!==a)if(d&&"h"===e){if(f="a"===f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f,("a"===a||"e"===a||"i"===a||"o"===a||"u"===a||"y"===a)&&f||" "===a)c+=e}else c+=e;f=d===b.length-1?"":b[d+1];a=e}return c}function V(b,c){var a={};if(b)for(var f=0;f<b.length;f++){var d=
c?c(b[f]):b[f];a[d]=String.fromCharCode(65E3-b.length+f)}return a}function Z(b,c){var d=[];if(b)for(var f in b)if(b.hasOwnProperty(f)){var e=c?c(f):f;d.push(a("(?=.{"+(e.length+3)+",})"+e+"$"),c?c(b[f]):b[f])}return d}function W(b,c){b=b.length-c.length;return 0>b?1:b?-1:0}function X(b,c){b=b.length-c.length;return 0>b?-1:b?1:0}function Y(b,c,a){var f=[],d=[],e=b.length;if(1<e){b.sort(X);for(var g={},r=b[0],t=r.length,k=0;k<t;)g[r[k++]]=1;for(var n,p=0,q=0;++q<e;){var u=!1,m=q===e-1;d=[];r=b[q];t=
r.length;for(k=0;k<t;)if(n=r[k++],g[n]){var l=g[n];if(l===q){if(m){if(f[p++]=n,c&&p===c)return f}else g[n]=q+1;u=!0}else a&&(l=d[l]||(d[l]=[]),l[l.length]=n)}if(!u&&!a)break}if(a&&(p=f.length,(q=d.length)&&(!c||p<c)))for(;q--;)if(n=d[q])for(b=0,a=n.length;b<a;b++)if(f[p++]=n[b],c&&p===c)return f}else e&&(f=b[0],c&&f.length>c&&(f=f.slice(0,c)));return f}function E(b){return"string"===typeof b}function H(b){return"function"===typeof b}function x(b){return"undefined"===typeof b}function B(b){b.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.c[f];switch(d[0]){case C.add:b.add(d[1],d[2]);break;case C.remove:b.remove(d[1])}delete b.c[f];if(100<Date.now()-a)break}b.b.length&&B(b)}c&&(b.async=c)},1,"search-async-"+b.id))}function N(b){for(var c=Array(b),a=0;a<b;a++)c[a]={};return c}function ca(b,c,a,f){b=g("flexsearch","id"+b,function(){var b,c;self.onmessage=function(a){if(a=a.data)if(a.search){var f=c.search(a.content,
a.threshold?{limit:a.limit,threshold:a.threshold}:a.limit);self.postMessage({id:b,content:a.content,limit:a.limit,result:f})}else a.add?c.add(a.id,a.content):a.update?c.update(a.id,a.content):a.remove?c.remove(a.id):a.clear?c.clear():a.register&&(b=a.id,a.options.cache=!1,a.options.async=!0,a.options.worker=!1,c=(new Function(a.register.substring(a.register.indexOf("{")+1,a.register.lastIndexOf("}"))))(),c=new c(a.options))}},function(b){(b=b.data)&&b.result&&f(b.id,b.content,b.result,b.limit)},c);
var d=aa.toString();a.id=c;b.postMessage(c,{register:d,options:a,id:c});return b}var w={encode:"icase",h:"forward",w:!1,cache:!1,async:!1,i:!1,threshold:0,depth:0},L={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}},F=[],ba=0,C={add:0,update:1,remove:2},
O=a("[ -/]"),P={},Q={},R=function(){for(var b=Object.getOwnPropertyNames({}.__proto__),c={},a=0;a<b.length;a++)c[b[a]]=1;return c}();e.create=function(b){return new e(b)};e.registerMatcher=function(b){for(var c in b)b.hasOwnProperty(c)&&F.push(a(c),b[c]);return this};e.registerEncoder=function(b,c){y[b]=c.bind(y);return this};e.registerLanguage=function(b,c){P[b]=c.filter;Q[b]=c.stemmer;return this};e.encode=function(b,c){return R[b]?c:y[b](c)};e.prototype.init=function(b){this.D=[];b||(b=w);var c=
b.profile,a=c?L[c]:{};if(c=b.worker)if(Worker){var f=this,d=parseInt(c,10)||4;f.m=-1;f.o=0;f.f=[];f.C=null;f.j=Array(d);for(var e=0;e<d;e++)f.j[e]=ca(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||w.h;this.async=x(c=b.async)?this.async||w.async:c;this.i=x(c=b.worker)?this.i||w.i:c;this.threshold=x(c=b.threshold)?a.threshold||
this.threshold||w.threshold:c;this.depth=x(c=b.depth)?a.depth||this.depth||w.depth:c;this.w=x(c=b.suggest)?this.w||w.w:c;this.s=(c=x(c=b.encode)?a.encode:c)&&y[c]&&y[c].bind(y)||(H(c)?c:this.s||!1);(c=b.matcher)&&this.addMatcher(c);if(c=b.filter)this.filter=V(P[c]||c,this.s);if(c=b.stemmer)this.stemmer=Z(Q[c]||c,this.s);this.v=N(10);this.l={};this.a={};this.c={};this.b=[];this.F=0;this.u=!0;this.g=(this.cache=c=x(c=b.cache)?this.cache||w.cache:c)?new da(c):!1;return this};e.prototype.encode=function(b){b&&
F.length&&(b=l(b,F));b&&this.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&&E(c)&&(b&&!R[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]=[C.add,b,c],B(this),this;c=this.encode(c);if(!c.length)return this;a=this.h;c=H(a)?a(c):"ngram"===a?D(c):c.split(O);for(var f={_ctx:{}},e=this.threshold,g=this.depth,k=this.v,r=c.length,t=0;t<r;t++){var l=c[t];if(l){var n=l.length,p=(r-t)/r,q="";switch(a){case "reverse":case "both":for(var u=n-1;1<=u;u--)q=l[u]+q,d(k,f,q,b,(n-u)/n,p,e);q="";case "forward":for(u=0;u<n;u++)q+=l[u],d(k,f,q,b,1,p,e);break;case "full":for(u=0;u<n;u++)for(var m=(n-u)/n,v=n;v>u;v--)q=
l.substring(u,v),d(k,f,q,b,m,p,e);break;default:if(n=d(k,f,l,b,1,p,e),g&&1<r&&n>=e)for(n=f._ctx[l]||(f._ctx[l]={}),l=this.l[l]||(this.l[l]=N(10)),p=t-g,q=t+g+1,0>p&&(p=0),q>r&&(q=r);p<q;p++)p!==t&&d(l,n,c[p],b,0,10-(p<t?t-p:p-t),e)}}}this.a[b]=1;this.u=!1}return this};e.prototype.update=function(b,c){this.a[b]&&E(c)&&(this.remove(b),this.add(b,c,!0));return this};e.prototype.remove=function(b){if(this.a[b]){if(this.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]=[C.remove,b],B(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,f){var d=b,e=[];if("object"===typeof b){(a=b.callback||c)&&(d.callback=null);c=b.limit;var g=b.threshold;b=b.query}g||(g=this.threshold||0);H(c)?(a=c,c=1E3):c||0===c||(c=1E3);if(this.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;M(function(){a(k.search(d,c,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(d,c,null,!0));l=null})}if(!b||!E(b))return e;d=b;if(this.cache)if(this.u){if(f=this.g.get(b))return f}else this.g.clear(),this.u=!0;d=this.encode(d);if(!d.length)return e;f=this.h;f=H(f)?f(d):"ngram"===f?D(d):d.split(O);var t=f.length,n=!0,p=[],q={};if(1<t)if(this.depth){var m=!0;var v=f[0];q[v]=1}else f.sort(W);var w;
if(!m||(w=this.l)[v])for(var x=m?1:0;x<t;x++){var y=f[x];if(y&&!q[y]){var G=void 0;G=void 0;for(var C=!1,B=[],F=0,I=9;I>=g;I--)if(G=(m?w[v]:this.v)[I],G=G[y])B[F++]=G,C=!0;if(C)p[p.length]=1<F?p.concat.apply([],B):B[0];else if(!this.w){n=!1;break}q[y]=1}v=y}else n=!1;n&&(e=Y(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 y={icase:function(b){return b.toLowerCase()},simple:function(){var b=[a("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",a("[\u00e8\u00e9\u00ea\u00eb]"),"e",a("[\u00ec\u00ed\u00ee\u00ef]"),"i",a("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",a("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",a("[\u00fd\u0177\u00ff]"),"y",a("\u00f1"),"n",a("\u00e7"),"c",a("\u00df"),"s",a(" & ")," and ",a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(c){c=l(c.toLowerCase(),
b);return" "!==c?c:""}}(),advanced:function(){var b=[a("ae"),"a",a("ai"),"ei",a("ay"),"ei",a("ey"),"ei",a("oe"),"o",a("ue"),"u",a("ie"),"i",a("sz"),"s",a("zs"),"s",a("sh"),"s",a("ck"),"k",a("cc"),"k",a("dt"),"t",a("ph"),"f",a("pf"),"f",a("ou"),"o",a("uo"),"u"];return function(c,a){if(!c)return c;c=this.simple(c);2<c.length&&(c=l(c,b));a||1<c.length&&(c=v(c));return c}}(),extra:function(){var b=[a("p"),"b",a("z"),"s",a("[cgq]"),"k",a("n"),"m",a("d"),"t",a("[vw]"),"f",a("[aeiouy]"),""];return function(a){if(!a)return a;
a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(var c=0;c<a.length;c++){var d=a[c];1<d.length&&(a[c]=d[0]+l(d.substring(1),b))}a=a.join(" ");a=v(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s\\s+")," "];return function(a){return v(l(a.toLowerCase(),b))}}()},M=function(){var b={};return function(a,d,f){var c=b[f];c&&clearTimeout(c);return b[f]=setTimeout(a,d)}}(),da=function(){function a(a){this.clear();this.B=!0!==a&&a}a.prototype.clear=function(){this.cache=
{};this.count={};this.index={};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=Object.create(null),h="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(e,k,a,l,d){var m=e;e=h?URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"})):m+".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);

View File

@@ -12,7 +12,7 @@
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<!--<script src="../node_modules/mocha-phantomjs-core/browser-shim.js"></script>-->
<script src="../flexsearch.min.js"></script>
<script src="flexsearch.es5.js"></script>
<script>
window.initMochaPhantomJS && initMochaPhantomJS();
mocha.ui('bdd');

View File

@@ -283,7 +283,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
flexsearch = new FlexSearch({
encode: 'extra',
mode: 'strict',
tokenize: 'strict',
threshold: 5,
depth: 3,
suggest: true,

View File

@@ -41,7 +41,7 @@ describe("Initialize", function(){
flexsearch_sync = new FlexSearch({
mode: "forward",
tokenize: "forward",
encode: false,
async: false,
worker: false
@@ -49,7 +49,7 @@ describe("Initialize", function(){
flexsearch_async = FlexSearch.create({
mode: "forward",
tokenize: "forward",
encode: false,
async: true,
worker: false
@@ -93,7 +93,7 @@ describe("Initialize", function(){
flexsearch_strict = new FlexSearch({
encode: "icase",
mode: "strict",
tokenize: "strict",
async: false,
worker: false
});
@@ -101,7 +101,7 @@ describe("Initialize", function(){
flexsearch_forward = new FlexSearch({
encode: "icase",
mode: "forward",
tokenize: "forward",
async: false,
worker: false
});
@@ -109,7 +109,7 @@ describe("Initialize", function(){
flexsearch_reverse = new FlexSearch({
encode: "icase",
mode: "reverse",
tokenize: "reverse",
async: false,
worker: false
});
@@ -117,7 +117,7 @@ describe("Initialize", function(){
flexsearch_full = new FlexSearch({
encode: "icase",
mode: "full",
tokenize: "full",
async: false,
worker: false
});
@@ -125,7 +125,7 @@ describe("Initialize", function(){
flexsearch_ngram = new FlexSearch({
encode: "advanced",
mode: "ngram",
tokenize: "ngram",
async: false,
worker: false
});
@@ -133,7 +133,7 @@ describe("Initialize", function(){
flexsearch_cache = new FlexSearch({
encode: "icase",
mode: "reverse",
tokenize: "reverse",
cache: true
});
@@ -177,12 +177,15 @@ describe("Initialize", function(){
expect(flexsearch_async.async).to.equal(true);
}
expect(flexsearch_default.mode).to.equal("forward");
expect(flexsearch_strict.mode).to.equal("strict");
expect(flexsearch_forward.mode).to.equal("forward");
expect(flexsearch_reverse.mode).to.equal("reverse");
expect(flexsearch_full.mode).to.equal("full");
expect(flexsearch_ngram.mode).to.equal("ngram");
if((env !== "light") && (env !== "min")){
expect(flexsearch_default.tokenize).to.equal("forward");
expect(flexsearch_strict.tokenize).to.equal("strict");
expect(flexsearch_forward.tokenize).to.equal("forward");
expect(flexsearch_reverse.tokenize).to.equal("reverse");
expect(flexsearch_full.tokenize).to.equal("full");
expect(flexsearch_ngram.tokenize).to.equal("ngram");
}
// not available in compiled version:
if(typeof flexsearch_custom.encoder !== "undefined"){
@@ -648,7 +651,7 @@ if(env !== "light"){
flexsearch_worker = new FlexSearch({
encode: "icase",
mode: "strict",
tokenize: "strict",
async: false,
worker: 4
});
@@ -933,7 +936,7 @@ describe("Context", function(){
var flexsearch_depth = new FlexSearch({
encode: "icase",
mode: "strict",
tokenize: "strict",
depth: 2,
async: false,
worker: false
@@ -1033,7 +1036,7 @@ describe("Relevance", function(){
var index = new FlexSearch({
encode: "advanced",
mode: "strict"
tokenize: "strict"
});
index.add(0, "1 2 3 2 4 1 5 3");
@@ -1047,7 +1050,7 @@ describe("Relevance", function(){
var index = new FlexSearch({
encode: "advanced",
mode: "strict",
tokenize: "strict",
threshold: 5,
depth: 3
});
@@ -1063,7 +1066,7 @@ describe("Relevance", function(){
var index = new FlexSearch({
encode: "extra",
mode: "ngram",
tokenize: "ngram",
threshold: 5,
depth: 3
});
@@ -1094,7 +1097,7 @@ if(env !== "light"){
var index = new FlexSearch({
encode: "advanced",
mode: "strict",
tokenize: "strict",
suggest: true
});
@@ -1207,13 +1210,15 @@ if(env !== "light" && env !== "min"){
"id",
"chars",
//"status",
"cache",
"items",
"matcher",
"memory",
"sequences",
"worker"
"worker",
"contextual",
"depth",
"threshold"
]);
});
});
@@ -1227,7 +1232,7 @@ describe("Chaining", function(){
it("Should have been chained properly", function(){
var index = FlexSearch.create({mode: "forward", encode: "icase"})
var index = FlexSearch.create({tokenize: "forward", encode: "icase"})
.addMatcher({"â": "a"})
.add(0, "foo")
.add(1, "bar");