mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-02 18:33:17 +02:00
v0.3.5
This commit is contained in:
58
README.md
58
README.md
@@ -1559,18 +1559,63 @@ Compare these presets:
|
|||||||
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching-presets.html" target="_blank">Relevance Scoring</a><br>
|
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching-presets.html" target="_blank">Relevance Scoring</a><br>
|
||||||
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark-presets.html" target="_blank">Benchmarks</a>
|
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark-presets.html" target="_blank">Benchmarks</a>
|
||||||
|
|
||||||
<a name="builds"></a>
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
__Split Complexity__
|
__Split Complexity__
|
||||||
|
|
||||||
Whenever you can, try to divide content by categories and add them to its own index, e.g.:
|
Whenever you can, try to divide content by categories and add them to its own index, e.g.:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var feeds_2017 = new FlexSearch();
|
var action = new FlexSearch();
|
||||||
var feeds_2018 = new FlexSearch();
|
var adventure = new FlexSearch();
|
||||||
var feeds_2019 = new FlexSearch();
|
var comedy = new FlexSearch();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This way you can also provide different settings for each category.
|
||||||
|
|
||||||
|
To make this workaround more extendable you can define a tiny helper:
|
||||||
|
```js
|
||||||
|
var settings = {};
|
||||||
|
var index = {};
|
||||||
|
|
||||||
|
function add(id, cat, content){
|
||||||
|
(index[cat] || (
|
||||||
|
index[cat] = new FlexSearch(settings[cat])
|
||||||
|
)).add(id, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
function search(cat, query){
|
||||||
|
return index[cat] ? index[cat].search(query) : [];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Provide settings optionally (or skip and use defaults):
|
||||||
|
```js
|
||||||
|
settings = {
|
||||||
|
action: "score",
|
||||||
|
adventure: "match",
|
||||||
|
comedy: {
|
||||||
|
encode: "advanced",
|
||||||
|
tokenize: "forward",
|
||||||
|
threshold: 5
|
||||||
|
}
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
Add content to the index:
|
||||||
|
```js
|
||||||
|
add(1, "action", "Movie Title");
|
||||||
|
add(2, "adventure", "Movie Title");
|
||||||
|
add(3, "comedy", "Movie Title");
|
||||||
|
```
|
||||||
|
|
||||||
|
Perform queries:
|
||||||
|
```js
|
||||||
|
var results = search("action", "movie title"); // --> [1]
|
||||||
|
```
|
||||||
|
|
||||||
|
Filter queries by categories will hugely improve performance.
|
||||||
|
|
||||||
__Use numeric IDs__
|
__Use numeric IDs__
|
||||||
|
|
||||||
It is recommended to use numeric id values as reference when adding content to the index. The byte length of passed ids influences the memory consumption significantly. If this is not possible you should consider to use a index table and map the ids with indexes, this becomes important especially when using contextual indexes on a large amount of content.
|
It is recommended to use numeric id values as reference when adding content to the index. The byte length of passed ids influences the memory consumption significantly. If this is not possible you should consider to use a index table and map the ids with indexes, this becomes important especially when using contextual indexes on a large amount of content.
|
||||||
@@ -1771,6 +1816,11 @@ __Supported Build Flags__
|
|||||||
<td>SUPPORT_PRESETS</td>
|
<td>SUPPORT_PRESETS</td>
|
||||||
<td>true, false</td>
|
<td>true, false</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr></tr>
|
||||||
|
<tr>
|
||||||
|
<td>SUPPORT_SERIALIZE</td>
|
||||||
|
<td>true, false</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><br><b>Language Flags </b>(includes stemmer and filter)</td>
|
<td><br><b>Language Flags </b>(includes stemmer and filter)</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
@@ -72,6 +72,7 @@ var parameter = (function(opt){
|
|||||||
export_local_property_definitions: true,
|
export_local_property_definitions: true,
|
||||||
language_in: "ECMASCRIPT6_STRICT",
|
language_in: "ECMASCRIPT6_STRICT",
|
||||||
language_out: language_out || "ECMASCRIPT6_STRICT",
|
language_out: language_out || "ECMASCRIPT6_STRICT",
|
||||||
|
//rewrite_polyfills: false,
|
||||||
process_closure_primitives: true,
|
process_closure_primitives: true,
|
||||||
summary_detail_level: 3,
|
summary_detail_level: 3,
|
||||||
warning_level: "VERBOSE",
|
warning_level: "VERBOSE",
|
||||||
|
@@ -1,24 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
FlexSearch v0.3.3
|
FlexSearch v0.3.5
|
||||||
Copyright 2019 Nextapps GmbH
|
Copyright 2019 Nextapps GmbH
|
||||||
Author: Thomas Wilkerling
|
Author: Thomas Wilkerling
|
||||||
Released under the Apache 2.0 Licence
|
Released under the Apache 2.0 Licence
|
||||||
https://github.com/nextapps-de/flexsearch
|
https://github.com/nextapps-de/flexsearch
|
||||||
*/
|
*/
|
||||||
'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+=
|
'use strict';(function(f,r,d){let h;(h=d.define)&&h.amd?h([],function(){return r}):(h=d.modules)?h[f.toLowerCase()]=r:"object"===typeof exports?module.exports=r:d[f]=r})("FlexSearch",function(){function f(a){z(a)&&(a=F[a]);a||(a=v);this.id=a.id||L++;this.init(a);r(this,"index",function(){return this.b});r(this,"length",function(){return Object.keys(this.b).length})}function r(a,b,c){Object.defineProperty(a,b,{get:c})}function d(a){return new RegExp(a,"g")}function h(a,b){for(let c=0;c<b.length;c+=
|
||||||
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"===
|
2)a=a.replace(b[c],b[c+1]);return a}function y(a,b,c,g,e,d,m){if(b[c])return b[c];e=e?(9-(m||6))*d+(m||6)*e:d;b[c]=e;e>=m&&(a=a[9-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=g);return e}function C(a,b){if(a){const c=Object.keys(a);for(let g=0,d=c.length;g<d;g++){const d=c[g],e=a[d];if(e)for(let c=0,g=e.length;c<g;c++)if(e[c]===b){1===g?delete a[d]:e.splice(c,1);break}else"object"===typeof e[c]&&C(e[c],b)}}}function D(a){let b="",c="";var d="";for(let e=0;e<a.length;e++){const g=a[e];if(g!==c)if(e&&"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=
|
g){if(d="a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d,("a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c)&&d||" "===c)b+=g}else b+=g;d=e===a.length-1?"":a[e+1];c=g}return b}function M(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function N(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function O(a,b,c){let d=[],e;const u=a.length;if(1<u){a.sort(N);const g=t();let l=a[0],n=l.length,k=0;for(;k<n;)g["@"+l[k++]]=1;let f,p=0,q=0;for(;++q<u;){let G=!1;const h=q===u-1;e=[];l=a[q];n=l.length;for(k=
|
||||||
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||
|
0;k<n;){f=l[k++];var m="@"+f;if(g[m]){const a=g[m];if(a===q){if(h){if(d[p++]=f,b&&p===b)return d}else g[m]=q+1;G=!0}else c&&(m=e[a]||(e[a]=[]),m[m.length]=f)}}if(!G&&!c)break}if(c&&(p=d.length,(q=e.length)&&(!b||p<b)))for(;q--;)if(f=e[q])for(let a=0,c=f.length;a<c;a++)if(d[p++]=f[a],b&&p===b)return d}else u&&(d=a[0],b&&d.length>b&&(d=d.slice(0,b)));return d}function z(a){return"string"===typeof a}function A(a){return"function"===typeof a}function B(a){return"undefined"===typeof a}function H(a){const b=
|
||||||
(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=
|
Array(a);for(let c=0;c<a;c++)b[c]=t();return b}function t(){return Object.create(null)}const v={encode:"icase",a:"forward",i:!1,cache:!1,async:!1,j:!1,threshold:0,depth:0},F={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}},E=[];let L=0;const I=d("\\W+"),
|
||||||
{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)};
|
J={},K={};(function(){const a=Object.getOwnPropertyNames({}.__proto__),b=t();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)&&E.push(d(b),a[b]);return this};f.registerEncoder=function(a,b){x[a]=b.bind(x);return this};f.registerLanguage=function(a,b){J[a]=b.filter;K[a]=b.stemmer;return this};f.encode=function(a,b){return x[a](b)};f.prototype.init=function(a){this.h=[];a||(a=v);var b=a.profile,c=
|
||||||
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?F[b]:{};this.a=a.tokenize||c.a||this.a||v.a;this.async="undefined"===typeof Promise||B(b=a.async)?this.async||v.async:b;this.threshold=B(b=a.threshold)?c.threshold||this.threshold||v.threshold:b;this.depth=B(b=a.depth)?c.depth||this.depth||v.depth:b;this.f=(b=B(b=a.encode)?c.encode:b)&&x[b]&&x[b].bind(x)||(A(b)?b:this.f||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=J[b]||b;c=this.f;var g=t();if(b)for(let a=0;a<b.length;a++){const d=c?c(b[a]):b[a];g[d]=String.fromCharCode(65E3-b.length+
|
||||||
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=
|
a)}this.filter=b=g}if(b=a.stemmer){var e;a=K[b]||b;b=this.f;c=[];if(a)for(e in a)a.hasOwnProperty(e)&&(g=b?b(e):e,c.push(d("(?=.{"+(g.length+3)+",})"+g+"$"),b?b(a[e]):a[e]));this.stemmer=e=c}this.g=H(10-(this.threshold||0));this.c=t();this.b=t();return this};f.prototype.encode=function(a){a&&E.length&&(a=h(a,E));a&&this.h.length&&(a=h(a,this.h));a&&this.f&&(a=this.f(a));a&&this.stemmer&&(a=h(a,this.stemmer));return a};f.prototype.addMatcher=function(a){const b=this.h;for(const c in a)a.hasOwnProperty(c)&&
|
||||||
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]||
|
b.push(d(c),a[c]);return this};f.prototype.add=function(a,b,c,d,e){if(b&&z(b)&&(a||0===a)){var g="@"+a;if(this.b[g]&&!d)return this.update(a,b);if(!e){if(this.async&&"function"!==typeof importScripts){let e=this;g=new Promise(function(c){setTimeout(function(){e.add(a,b,null,d,!0);e=null;c()})});if(c)g.then(c);else return g;return this}if(c)return this.add(a,b,null,d,!0),c(),this}b=this.encode(b);if(!b.length)return this;c=this.a;e=A(c)?c(b):b.split(I);const h=t();h._ctx=t();const p=this.threshold,
|
||||||
(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=
|
q=this.depth,u=this.g,w=e.length;for(let b=0;b<w;b++){var m=e[b];if(m){var f=m.length,l=(w-b)/w,n="";switch(c){case "reverse":case "both":for(var k=f-1;1<=k;k--)n=m[k]+n,y(u,h,n,a,(f-k)/f,l,p);n="";case "forward":for(k=0;k<f;k++)n+=m[k],y(u,h,n,a,1,l,p);break;case "full":for(k=0;k<f;k++){const b=(f-k)/f;for(let c=f;c>k;c--)n=m.substring(k,c),y(u,h,n,a,b,l,p)}break;default:if(f=y(u,h,m,a,1,l,p),q&&1<w&&f>=p)for(f=h._ctx[m]||(h._ctx[m]=t()),m=this.c[m]||(this.c[m]=H(10-(p||0))),l=b-q,n=b+q+1,0>l&&(l=
|
||||||
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,
|
0),n>w&&(n=w);l<n;l++)l!==b&&y(m,f,e[l],a,0,10-(l<b?b-l:l-b),p)}}}this.b[g]=1}return this};f.prototype.update=function(a,b,c){this.b["@"+a]&&z(b)&&(this.remove(a),this.add(a,b,c,!0));return this};f.prototype.remove=function(a,b,c){var d="@"+a;if(this.b[d]){if(!c){if(this.async&&"function"!==typeof importScripts){let c=this;d=new Promise(function(b){setTimeout(function(){c.remove(a,null,!0);c=null;b()})});if(b)d.then(b);else return d;return this}if(b)return this.remove(a,null,!0),b(),this}for(b=0;b<
|
||||||
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,
|
10-(this.threshold||0);b++)C(this.g[b],a);this.depth&&C(this.c,a);delete this.b[d]}return this};f.prototype.search=function(a,b,c,d){let e=a;let f=[];if("object"===typeof a){(c=a.callback||b)&&(e.callback=null);b=a.limit;var g=a.threshold;a=a.query}g||(g=this.threshold||0);A(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(!d){if(this.async&&"function"!==typeof importScripts){let a=this;g=new Promise(function(c){setTimeout(function(){c(a.search(e,b,null,!0));a=null})});if(c)g.then(c);else return g;return this}if(c)return c(this.search(e,
|
||||||
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}};
|
b,null,!0)),this}if(!a||!z(a))return f;e=a;e=this.encode(e);if(!e.length)return f;c=this.a;c=A(c)?c(e):e.split(I);a=c.length;d=!0;const h=[],l=t();let n;if(1<a)if(this.depth){n=!0;var k=c[0];l[k]=1}else c.sort(M);let r;if(!n||(r=this.c)[k])for(let b=n?1:0;b<a;b++){const a=c[b];if(a){if(!l[a]){const b=[];let c=!1,e=0;if(k=n?r[k]:this.g){let d;for(let f=0;f<10-g;f++)if(d=k[f][a])b[e++]=d,c=!0}if(c)h[h.length]=1<e?b.concat.apply([],b):b[0];else{d=!1;break}l[a]=1}k=a}}else d=!1;d&&(f=O(h,b,!1));return f};
|
||||||
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]"),
|
f.prototype.clear=function(){return this.destroy().init()};f.prototype.destroy=function(){this.g=this.c=this.b=null;return this};const x={icase:function(a){return a.toLowerCase()},simple:function(){const a=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d(" & "),
|
||||||
"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",
|
" and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(b){b=h(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){const a=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",d("cc"),"k",d("dt"),"t",d("ph"),"f",d("pf"),"f",d("ou"),"o",d("uo"),"u"];return function(b,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=[d("p"),
|
||||||
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("[-/]"),
|
"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(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=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(b){return D(h(b.toLowerCase(),a))}}()};return f}(!1),this);
|
||||||
" ",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);
|
|
||||||
|
599
flexsearch.js
599
flexsearch.js
@@ -1,5 +1,5 @@
|
|||||||
;/**!
|
;/**!
|
||||||
* @preserve FlexSearch v0.3.3
|
* @preserve FlexSearch v0.3.5
|
||||||
* Copyright 2019 Nextapps GmbH
|
* Copyright 2019 Nextapps GmbH
|
||||||
* Author: Thomas Wilkerling
|
* Author: Thomas Wilkerling
|
||||||
* Released under the Apache 2.0 Licence
|
* Released under the Apache 2.0 Licence
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
/** @define {boolean} */ const SUPPORT_ASYNC = true;
|
/** @define {boolean} */ const SUPPORT_ASYNC = true;
|
||||||
/** @define {boolean} */ const SUPPORT_PRESETS = true;
|
/** @define {boolean} */ const SUPPORT_PRESETS = true;
|
||||||
/** @define {boolean} */ const SUPPORT_SUGGESTIONS = true;
|
/** @define {boolean} */ const SUPPORT_SUGGESTIONS = true;
|
||||||
|
/** @define {boolean} */ const SUPPORT_SERIALIZE = true;
|
||||||
|
/** @define {boolean} */ const SUPPORT_INFO = true;
|
||||||
|
|
||||||
// noinspection ThisExpressionReferencesGlobalObjectJS
|
// noinspection ThisExpressionReferencesGlobalObjectJS
|
||||||
(function(){
|
(function(){
|
||||||
@@ -110,12 +112,14 @@
|
|||||||
* @enum {number}
|
* @enum {number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
const enum_task = {
|
const enum_task = {
|
||||||
|
|
||||||
add: 0,
|
add: 0,
|
||||||
update: 1,
|
update: 1,
|
||||||
remove: 2
|
remove: 2
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @const {RegExp}
|
* @const {RegExp}
|
||||||
@@ -258,7 +262,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
* @param {string} value
|
* @param {number|string} value
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
* @export
|
* @export
|
||||||
*/
|
*/
|
||||||
@@ -299,7 +303,7 @@
|
|||||||
|
|
||||||
if(SUPPORT_WORKER && (custom = options["worker"])){
|
if(SUPPORT_WORKER && (custom = options["worker"])){
|
||||||
|
|
||||||
if(Worker){
|
if(typeof Worker !== "undefined"){
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
const threads = parseInt(custom, 10) || 4;
|
const threads = parseInt(custom, 10) || 4;
|
||||||
@@ -330,6 +334,8 @@
|
|||||||
self._task_result = self._task_result.concat(result);
|
self._task_result = self._task_result.concat(result);
|
||||||
self._task_completed++;
|
self._task_completed++;
|
||||||
|
|
||||||
|
// TODO: sort results, return array of relevance [0...9] and apply in main thread
|
||||||
|
|
||||||
if(limit && (self._task_result.length >= limit)){
|
if(limit && (self._task_result.length >= limit)){
|
||||||
|
|
||||||
self._task_completed = self.worker;
|
self._task_completed = self.worker;
|
||||||
@@ -337,9 +343,6 @@
|
|||||||
|
|
||||||
if(self._current_callback && (self._task_completed === self.worker)){
|
if(self._current_callback && (self._task_completed === self.worker)){
|
||||||
|
|
||||||
// store result to cache
|
|
||||||
// TODO: add worker cache, may remove global cache
|
|
||||||
|
|
||||||
if(self.cache){
|
if(self.cache){
|
||||||
|
|
||||||
self._cache.set(query, self._task_result);
|
self._cache.set(query, self._task_result);
|
||||||
@@ -375,7 +378,7 @@
|
|||||||
|
|
||||||
if(SUPPORT_ASYNC) /** @private */ this.async = (
|
if(SUPPORT_ASYNC) /** @private */ this.async = (
|
||||||
|
|
||||||
is_undefined(custom = options["async"]) ?
|
(typeof Promise === "undefined") || is_undefined(custom = options["async"]) ?
|
||||||
|
|
||||||
this.async ||
|
this.async ||
|
||||||
defaults.async
|
defaults.async
|
||||||
@@ -474,9 +477,9 @@
|
|||||||
/** @private */
|
/** @private */
|
||||||
this._ids = create_object();
|
this._ids = create_object();
|
||||||
/** @private */
|
/** @private */
|
||||||
this._stack = create_object();
|
//this._stack = create_object();
|
||||||
/** @private */
|
/** @private */
|
||||||
this._stack_keys = [];
|
//this._stack_keys = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number|null}
|
* @type {number|null}
|
||||||
@@ -605,252 +608,274 @@
|
|||||||
/**
|
/**
|
||||||
* @param {number|string} id
|
* @param {number|string} id
|
||||||
* @param {string} content
|
* @param {string} content
|
||||||
|
* @param {Function=} callback
|
||||||
* @param {boolean=} _skip_update
|
* @param {boolean=} _skip_update
|
||||||
|
* @param {boolean=} _recall
|
||||||
* @this {FlexSearch}
|
* @this {FlexSearch}
|
||||||
* @export
|
* @export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FlexSearch.prototype.add = function(id, content, _skip_update){
|
FlexSearch.prototype.add = function(id, content, callback, _skip_update, _recall){
|
||||||
|
|
||||||
if(content && is_string(content) && ((id /*&& !index_blacklist[id]*/) || (id === 0))){
|
if(content && is_string(content) && ((id /*&& !index_blacklist[id]*/) || (id === 0))){
|
||||||
|
|
||||||
const index = "@" + id;
|
const index = "@" + id;
|
||||||
|
|
||||||
// check if index ID already exist
|
|
||||||
|
|
||||||
if(this._ids[index] && !_skip_update){
|
if(this._ids[index] && !_skip_update){
|
||||||
|
|
||||||
this.update(id, content);
|
return this.update(id, content);
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
|
|
||||||
if(SUPPORT_WORKER && this.worker){
|
if(SUPPORT_WORKER && this.worker){
|
||||||
|
|
||||||
if(++this._current_task >= this._worker.length){
|
if(++this._current_task >= this._worker.length){
|
||||||
|
|
||||||
this._current_task = 0;
|
this._current_task = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._worker[this._current_task].postMessage(this._current_task, {
|
this._worker[this._current_task].postMessage({
|
||||||
|
|
||||||
"add": true,
|
"add": true,
|
||||||
"id": id,
|
"id": id,
|
||||||
"content": content
|
"content": content
|
||||||
|
});
|
||||||
|
|
||||||
|
this._ids[index] = "" + this._current_task;
|
||||||
|
|
||||||
|
// TODO: provide worker auto-balancing instead of rotation
|
||||||
|
//this._ids_count[this._current_task]++;
|
||||||
|
|
||||||
|
if(callback){
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!_recall){
|
||||||
|
|
||||||
|
if(SUPPORT_ASYNC && this.async && (typeof importScripts !== "function")){
|
||||||
|
|
||||||
|
let self = this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fn
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
|
||||||
|
const promise = new Promise(function(resolve){
|
||||||
|
|
||||||
|
setTimeout(function(){
|
||||||
|
|
||||||
|
self.add(id, content, null, _skip_update, true);
|
||||||
|
self = null;
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this._ids[index] = "" + this._current_task;
|
if(callback){
|
||||||
|
|
||||||
// TODO: improve auto-balancing
|
promise.then(callback);
|
||||||
//this._ids_count[this._current_task]++;
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
else if(callback){
|
||||||
|
|
||||||
// collect tasks for non-blocking processing
|
this.add(id, content, null, _skip_update, true);
|
||||||
// TODO: actually auto-enabled in worker
|
callback();
|
||||||
|
|
||||||
if(SUPPORT_ASYNC && this.async){
|
|
||||||
|
|
||||||
this._stack[index] || (
|
|
||||||
|
|
||||||
this._stack_keys[this._stack_keys.length] = index
|
|
||||||
);
|
|
||||||
|
|
||||||
this._stack[index] = [
|
|
||||||
|
|
||||||
enum_task.add,
|
|
||||||
id,
|
|
||||||
content
|
|
||||||
];
|
|
||||||
|
|
||||||
register_task(this);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(PROFILER){
|
if(PROFILER){
|
||||||
|
|
||||||
profile_start("add");
|
profile_start("add");
|
||||||
}
|
}
|
||||||
|
|
||||||
content = this.encode(content);
|
content = this.encode(content);
|
||||||
|
|
||||||
if(!content.length){
|
if(!content.length){
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenizer = this.tokenize;
|
const tokenizer = this.tokenize;
|
||||||
|
|
||||||
const words = (
|
const words = (
|
||||||
|
|
||||||
is_function(tokenizer) ?
|
is_function(tokenizer) ?
|
||||||
|
|
||||||
tokenizer(content)
|
tokenizer(content)
|
||||||
:(
|
:(
|
||||||
//SUPPORT_ENCODER && (tokenizer === "ngram") ?
|
//SUPPORT_ENCODER && (tokenizer === "ngram") ?
|
||||||
|
|
||||||
/** @type {!Array<string>} */
|
/** @type {!Array<string>} */
|
||||||
//(ngram(/** @type {!string} */(content)))
|
//(ngram(/** @type {!string} */(content)))
|
||||||
//:
|
//:
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
(content).split(regex_split)
|
(content).split(regex_split)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const dupes = create_object();
|
const dupes = create_object();
|
||||||
dupes["_ctx"] = create_object();
|
dupes["_ctx"] = create_object();
|
||||||
|
|
||||||
const threshold = this.threshold;
|
const threshold = this.threshold;
|
||||||
const depth = this.depth;
|
const depth = this.depth;
|
||||||
const map = this._map;
|
const map = this._map;
|
||||||
const word_length = words.length;
|
const word_length = words.length;
|
||||||
|
|
||||||
// tokenize
|
// tokenize
|
||||||
|
|
||||||
for(let i = 0; i < word_length; i++){
|
for(let i = 0; i < word_length; i++){
|
||||||
|
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
const value = words[i];
|
const value = words[i];
|
||||||
|
|
||||||
if(value){
|
if(value){
|
||||||
|
|
||||||
const length = value.length;
|
const length = value.length;
|
||||||
const context_score = (word_length - i) / word_length;
|
const context_score = (word_length - i) / word_length;
|
||||||
|
|
||||||
let tmp = "";
|
let tmp = "";
|
||||||
|
|
||||||
switch(tokenizer){
|
switch(tokenizer){
|
||||||
|
|
||||||
case "reverse":
|
case "reverse":
|
||||||
case "both":
|
case "both":
|
||||||
|
|
||||||
for(let a = length - 1; a >= 1; a--){
|
for(let a = length - 1; a >= 1; a--){
|
||||||
|
|
||||||
tmp = value[a] + tmp;
|
tmp = value[a] + tmp;
|
||||||
|
|
||||||
add_index(
|
add_index(
|
||||||
|
|
||||||
map,
|
|
||||||
dupes,
|
|
||||||
tmp,
|
|
||||||
id,
|
|
||||||
(length - a) / length,
|
|
||||||
context_score,
|
|
||||||
threshold
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = "";
|
|
||||||
|
|
||||||
// Note: no break here, fallthrough to next case
|
|
||||||
|
|
||||||
case "forward":
|
|
||||||
|
|
||||||
for(let a = 0; a < length; a++){
|
|
||||||
|
|
||||||
tmp += value[a];
|
|
||||||
|
|
||||||
add_index(
|
|
||||||
|
|
||||||
map,
|
|
||||||
dupes,
|
|
||||||
tmp,
|
|
||||||
id,
|
|
||||||
1,
|
|
||||||
context_score,
|
|
||||||
threshold
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "full":
|
|
||||||
|
|
||||||
for(let x = 0; x < length; x++){
|
|
||||||
|
|
||||||
const partial_score = (length - x) / length;
|
|
||||||
|
|
||||||
for(let y = length; y > x; y--){
|
|
||||||
|
|
||||||
tmp = value.substring(x, y);
|
|
||||||
|
|
||||||
add_index(
|
|
||||||
|
|
||||||
map,
|
|
||||||
dupes,
|
|
||||||
tmp,
|
|
||||||
id,
|
|
||||||
partial_score,
|
|
||||||
context_score,
|
|
||||||
threshold
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
//case "strict":
|
|
||||||
//case "ngram":
|
|
||||||
default:
|
|
||||||
|
|
||||||
const score = add_index(
|
|
||||||
|
|
||||||
map,
|
map,
|
||||||
dupes,
|
dupes,
|
||||||
value,
|
tmp,
|
||||||
|
id,
|
||||||
|
(length - a) / length,
|
||||||
|
context_score,
|
||||||
|
threshold
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = "";
|
||||||
|
|
||||||
|
// Note: no break here, fallthrough to next case
|
||||||
|
|
||||||
|
case "forward":
|
||||||
|
|
||||||
|
for(let a = 0; a < length; a++){
|
||||||
|
|
||||||
|
tmp += value[a];
|
||||||
|
|
||||||
|
add_index(
|
||||||
|
|
||||||
|
map,
|
||||||
|
dupes,
|
||||||
|
tmp,
|
||||||
id,
|
id,
|
||||||
// Note: ngrams has partial scoring (sequence->word) and contextual scoring (word->context)
|
|
||||||
// TODO compute and pass distance of ngram sequences as the initial score for each word
|
|
||||||
1,
|
1,
|
||||||
context_score,
|
context_score,
|
||||||
threshold
|
threshold
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if(depth && (word_length > 1) && (score >= threshold)){
|
break;
|
||||||
|
|
||||||
const ctxDupes = dupes["_ctx"][value] || (dupes["_ctx"][value] = create_object());
|
case "full":
|
||||||
const ctxTmp = this._ctx[value] || (this._ctx[value] = create_object_array(10 - (threshold || 0)));
|
|
||||||
|
|
||||||
let x = i - depth;
|
for(let x = 0; x < length; x++){
|
||||||
let y = i + depth + 1;
|
|
||||||
|
|
||||||
if(x < 0) x = 0;
|
const partial_score = (length - x) / length;
|
||||||
if(y > word_length) y = word_length;
|
|
||||||
|
|
||||||
for(; x < y; x++){
|
for(let y = length; y > x; y--){
|
||||||
|
|
||||||
if(x !== i) add_index(
|
tmp = value.substring(x, y);
|
||||||
|
|
||||||
ctxTmp,
|
add_index(
|
||||||
ctxDupes,
|
|
||||||
words[x],
|
map,
|
||||||
id,
|
dupes,
|
||||||
0,
|
tmp,
|
||||||
10 - (x < i ? i - x : x - i),
|
id,
|
||||||
threshold
|
partial_score,
|
||||||
);
|
context_score,
|
||||||
}
|
threshold
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
//case "strict":
|
||||||
|
//case "ngram":
|
||||||
|
default:
|
||||||
|
|
||||||
|
const score = add_index(
|
||||||
|
|
||||||
|
map,
|
||||||
|
dupes,
|
||||||
|
value,
|
||||||
|
id,
|
||||||
|
// Note: ngrams has partial scoring (sequence->word) and contextual scoring (word->context)
|
||||||
|
// TODO compute and pass distance of ngram sequences as the initial score for each word
|
||||||
|
1,
|
||||||
|
context_score,
|
||||||
|
threshold
|
||||||
|
);
|
||||||
|
|
||||||
|
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 - (threshold || 0)));
|
||||||
|
|
||||||
|
let x = i - depth;
|
||||||
|
let y = i + depth + 1;
|
||||||
|
|
||||||
|
if(x < 0) x = 0;
|
||||||
|
if(y > word_length) y = word_length;
|
||||||
|
|
||||||
|
for(; x < y; x++){
|
||||||
|
|
||||||
|
if(x !== i) add_index(
|
||||||
|
|
||||||
|
ctxTmp,
|
||||||
|
ctxDupes,
|
||||||
|
words[x],
|
||||||
|
id,
|
||||||
|
0,
|
||||||
|
10 - (x < i ? i - x : x - i),
|
||||||
|
threshold
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update status
|
// update status
|
||||||
|
|
||||||
this._ids[index] = 1;
|
this._ids[index] = 1;
|
||||||
|
|
||||||
if(SUPPORT_CACHE){
|
if(SUPPORT_CACHE){
|
||||||
|
|
||||||
this._cache_status = false;
|
this._cache_status = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(PROFILER){
|
if(PROFILER){
|
||||||
|
|
||||||
profile_end("add");
|
profile_end("add");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,12 +883,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id
|
* @param {number|string} id
|
||||||
* @param content
|
* @param {string} content
|
||||||
|
* @param {Function=} callback
|
||||||
* @export
|
* @export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FlexSearch.prototype.update = function(id, content){
|
FlexSearch.prototype.update = function(id, content, callback){
|
||||||
|
|
||||||
const index = "@" + id;
|
const index = "@" + id;
|
||||||
|
|
||||||
@@ -875,7 +901,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.remove(id);
|
this.remove(id);
|
||||||
this.add(id, content, /* skip_update: */ true);
|
this.add(id, content, callback, /* skip_update: */ true);
|
||||||
|
|
||||||
if(PROFILER){
|
if(PROFILER){
|
||||||
|
|
||||||
@@ -887,11 +913,13 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id
|
* @param {number|string} id
|
||||||
|
* @param {Function=} callback
|
||||||
|
* @param {boolean=} _recall
|
||||||
* @export
|
* @export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
FlexSearch.prototype.remove = function(id){
|
FlexSearch.prototype.remove = function(id, callback, _recall){
|
||||||
|
|
||||||
const index = "@" + id;
|
const index = "@" + id;
|
||||||
|
|
||||||
@@ -901,7 +929,7 @@
|
|||||||
|
|
||||||
const current_task = this._ids[index];
|
const current_task = this._ids[index];
|
||||||
|
|
||||||
this._worker[current_task].postMessage(current_task, {
|
this._worker[current_task].postMessage({
|
||||||
|
|
||||||
"remove": true,
|
"remove": true,
|
||||||
"id": id
|
"id": id
|
||||||
@@ -911,25 +939,48 @@
|
|||||||
|
|
||||||
delete this._ids[index];
|
delete this._ids[index];
|
||||||
|
|
||||||
|
if(callback){
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SUPPORT_ASYNC && this.async){
|
if(!_recall){
|
||||||
|
|
||||||
this._stack[index] || (
|
if(SUPPORT_ASYNC && this.async && (typeof importScripts !== "function")){
|
||||||
|
|
||||||
this._stack_keys[this._stack_keys.length] = index
|
let self = this;
|
||||||
);
|
|
||||||
|
|
||||||
this._stack[index] = [
|
const promise = new Promise(function(resolve){
|
||||||
|
|
||||||
enum_task.remove,
|
setTimeout(function(){
|
||||||
id
|
|
||||||
];
|
|
||||||
|
|
||||||
register_task(this);
|
self.remove(id, null, true);
|
||||||
|
self = null;
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return this;
|
if(callback){
|
||||||
|
|
||||||
|
promise.then(callback);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
else if(callback){
|
||||||
|
|
||||||
|
this.remove(id, null, true);
|
||||||
|
callback();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(PROFILER){
|
if(PROFILER){
|
||||||
@@ -968,7 +1019,7 @@
|
|||||||
* @param {number|Function=} limit
|
* @param {number|Function=} limit
|
||||||
* @param {Function=} callback
|
* @param {Function=} callback
|
||||||
* @param {boolean=} _recall
|
* @param {boolean=} _recall
|
||||||
* @returns {Array|Promise|undefined}
|
* @returns {FlexSearch|Array|Promise|undefined}
|
||||||
* @export
|
* @export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -1024,7 +1075,7 @@
|
|||||||
|
|
||||||
for(let i = 0; i < this.worker; i++){
|
for(let i = 0; i < this.worker; i++){
|
||||||
|
|
||||||
this._worker[i].postMessage(i, {
|
this._worker[i].postMessage({
|
||||||
|
|
||||||
"search": true,
|
"search": true,
|
||||||
"limit": limit,
|
"limit": limit,
|
||||||
@@ -1036,37 +1087,38 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(callback){
|
if(!_recall){
|
||||||
|
|
||||||
if(SUPPORT_ASYNC){
|
if(SUPPORT_ASYNC && this.async && (typeof importScripts !== "function")){
|
||||||
|
|
||||||
/** @type {FlexSearch} */
|
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
queue(function(){
|
const promise = new Promise(function(resolve){
|
||||||
|
|
||||||
callback(self.search(_query, limit, null, true));
|
setTimeout(function(){
|
||||||
self = null;
|
|
||||||
|
|
||||||
}, 1, "search-" + this.id);
|
resolve(self.search(_query, limit, null, true));
|
||||||
|
self = null;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if(callback){
|
||||||
|
|
||||||
|
promise.then(callback);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
else{
|
else if(callback){
|
||||||
|
|
||||||
callback(this.search(_query, limit, null, true));
|
callback(this.search(_query, limit, null, true));
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if(SUPPORT_ASYNC && !_recall && this.async && (typeof importScripts !== "function")){
|
|
||||||
|
|
||||||
/** @type {FlexSearch} */
|
|
||||||
let self = this;
|
|
||||||
|
|
||||||
return new Promise(function(resolve){
|
|
||||||
|
|
||||||
resolve(self.search(_query, limit, null, true));
|
|
||||||
self = null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(PROFILER){
|
if(PROFILER){
|
||||||
@@ -1258,7 +1310,7 @@
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(DEBUG){
|
if(SUPPORT_INFO){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @export
|
* @export
|
||||||
@@ -1268,7 +1320,7 @@
|
|||||||
|
|
||||||
if(SUPPORT_WORKER && this.worker){
|
if(SUPPORT_WORKER && this.worker){
|
||||||
|
|
||||||
for(let i = 0; i < this.worker; i++) this._worker[i].postMessage(i, {
|
for(let i = 0; i < this.worker; i++) this._worker[i].postMessage({
|
||||||
|
|
||||||
"info": true,
|
"info": true,
|
||||||
"id": this.id
|
"id": this.id
|
||||||
@@ -1331,13 +1383,9 @@
|
|||||||
|
|
||||||
FlexSearch.prototype.clear = function(){
|
FlexSearch.prototype.clear = function(){
|
||||||
|
|
||||||
// destroy index
|
// destroy + initialize index
|
||||||
|
|
||||||
this.destroy();
|
return this.destroy().init();
|
||||||
|
|
||||||
// initialize index
|
|
||||||
|
|
||||||
return this.init();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1356,44 +1404,47 @@
|
|||||||
|
|
||||||
// release references
|
// release references
|
||||||
|
|
||||||
this.filter =
|
//this.filter =
|
||||||
this.stemmer =
|
//this.stemmer =
|
||||||
this._scores =
|
//this._scores =
|
||||||
this._map =
|
this._map =
|
||||||
this._ctx =
|
this._ctx =
|
||||||
this._ids =
|
this._ids =
|
||||||
this._stack =
|
/*this._stack =
|
||||||
this._stack_keys = null;
|
this._stack_keys =*/ null;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
if(SUPPORT_SERIALIZE){
|
||||||
* @export
|
|
||||||
*/
|
|
||||||
|
|
||||||
FlexSearch.prototype.export = function(){
|
/**
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
|
||||||
return JSON.stringify([
|
FlexSearch.prototype.export = function(){
|
||||||
|
|
||||||
this._map,
|
return JSON.stringify([
|
||||||
this._ctx,
|
|
||||||
this._ids
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
this._map,
|
||||||
* @export
|
this._ctx,
|
||||||
*/
|
this._ids
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
FlexSearch.prototype.import = function(payload){
|
/**
|
||||||
|
* @export
|
||||||
|
*/
|
||||||
|
|
||||||
payload = JSON.parse(payload);
|
FlexSearch.prototype.import = function(payload){
|
||||||
|
|
||||||
this._map = payload[0];
|
payload = JSON.parse(payload);
|
||||||
this._ctx = payload[1];
|
|
||||||
this._ids = payload[2];
|
this._map = payload[0];
|
||||||
};
|
this._ctx = payload[1];
|
||||||
|
this._ids = payload[2];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/** @const */
|
/** @const */
|
||||||
|
|
||||||
@@ -1641,6 +1692,7 @@
|
|||||||
|
|
||||||
// Async Handler
|
// Async Handler
|
||||||
|
|
||||||
|
/*
|
||||||
const queue = SUPPORT_ASYNC ? (function(){
|
const queue = SUPPORT_ASYNC ? (function(){
|
||||||
|
|
||||||
const stack = create_object();
|
const stack = create_object();
|
||||||
@@ -1661,6 +1713,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
})() : null;
|
})() : null;
|
||||||
|
*/
|
||||||
|
|
||||||
// Flexi-Cache
|
// Flexi-Cache
|
||||||
|
|
||||||
@@ -2578,6 +2631,7 @@
|
|||||||
* @param {FlexSearch} ref
|
* @param {FlexSearch} ref
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
function runner(ref){
|
function runner(ref){
|
||||||
|
|
||||||
const async = ref.async;
|
const async = ref.async;
|
||||||
@@ -2637,11 +2691,13 @@
|
|||||||
ref.async = async;
|
ref.async = async;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {FlexSearch} ref
|
* @param {FlexSearch} ref
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
function register_task(ref){
|
function register_task(ref){
|
||||||
|
|
||||||
ref._timer || (
|
ref._timer || (
|
||||||
@@ -2655,6 +2711,7 @@
|
|||||||
}, 1, "@" + ref.id)
|
}, 1, "@" + ref.id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
@@ -2704,7 +2761,7 @@
|
|||||||
let id;
|
let id;
|
||||||
|
|
||||||
/** @type {FlexSearch} */
|
/** @type {FlexSearch} */
|
||||||
let flexsearch;
|
let FlexSearchWorker;
|
||||||
|
|
||||||
/** @lends {Worker} */
|
/** @lends {Worker} */
|
||||||
self.onmessage = function(event){
|
self.onmessage = function(event){
|
||||||
@@ -2715,7 +2772,7 @@
|
|||||||
|
|
||||||
if(data["search"]){
|
if(data["search"]){
|
||||||
|
|
||||||
const results = flexsearch["search"](data["content"],
|
const results = FlexSearchWorker["search"](data["content"],
|
||||||
|
|
||||||
data["threshold"] ?
|
data["threshold"] ?
|
||||||
|
|
||||||
@@ -2738,23 +2795,23 @@
|
|||||||
}
|
}
|
||||||
else if(data["add"]){
|
else if(data["add"]){
|
||||||
|
|
||||||
flexsearch["add"](data["id"], data["content"]);
|
FlexSearchWorker["add"](data["id"], data["content"]);
|
||||||
}
|
}
|
||||||
else if(data["update"]){
|
else if(data["update"]){
|
||||||
|
|
||||||
flexsearch["update"](data["id"], data["content"]);
|
FlexSearchWorker["update"](data["id"], data["content"]);
|
||||||
}
|
}
|
||||||
else if(data["remove"]){
|
else if(data["remove"]){
|
||||||
|
|
||||||
flexsearch["remove"](data["id"]);
|
FlexSearchWorker["remove"](data["id"]);
|
||||||
}
|
}
|
||||||
else if(data["clear"]){
|
else if(data["clear"]){
|
||||||
|
|
||||||
flexsearch["clear"]();
|
FlexSearchWorker["clear"]();
|
||||||
}
|
}
|
||||||
else if(DEBUG && data["info"]){
|
else if(SUPPORT_INFO && data["info"]){
|
||||||
|
|
||||||
const info = flexsearch["info"]();
|
const info = FlexSearchWorker["info"]();
|
||||||
|
|
||||||
info["worker"] = id;
|
info["worker"] = id;
|
||||||
|
|
||||||
@@ -2768,10 +2825,10 @@
|
|||||||
id = data["id"];
|
id = data["id"];
|
||||||
|
|
||||||
data["options"]["cache"] = false;
|
data["options"]["cache"] = false;
|
||||||
data["options"]["async"] = true;
|
data["options"]["async"] = false;
|
||||||
data["options"]["worker"] = false;
|
data["options"]["worker"] = false;
|
||||||
|
|
||||||
flexsearch = new Function(
|
FlexSearchWorker = new Function(
|
||||||
|
|
||||||
data["register"].substring(
|
data["register"].substring(
|
||||||
|
|
||||||
@@ -2780,7 +2837,7 @@
|
|||||||
)
|
)
|
||||||
)();
|
)();
|
||||||
|
|
||||||
flexsearch = new flexsearch(data["options"]);
|
FlexSearchWorker = new FlexSearchWorker(data["options"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2805,7 +2862,7 @@
|
|||||||
|
|
||||||
options["id"] = core;
|
options["id"] = core;
|
||||||
|
|
||||||
thread.postMessage(core, {
|
thread.postMessage({
|
||||||
|
|
||||||
"register": fnStr,
|
"register": fnStr,
|
||||||
"options": options,
|
"options": options,
|
||||||
@@ -2814,7 +2871,7 @@
|
|||||||
|
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
})(
|
}(
|
||||||
// Worker Handler
|
// Worker Handler
|
||||||
|
|
||||||
SUPPORT_WORKER ? (function register_worker(){
|
SUPPORT_WORKER ? (function register_worker(){
|
||||||
@@ -2857,6 +2914,8 @@
|
|||||||
"var SUPPORT_ENCODER = " + (SUPPORT_ENCODER ? "true" : "false") + ";" +
|
"var SUPPORT_ENCODER = " + (SUPPORT_ENCODER ? "true" : "false") + ";" +
|
||||||
"var SUPPORT_CACHE = " + (SUPPORT_CACHE ? "true" : "false") + ";" +
|
"var SUPPORT_CACHE = " + (SUPPORT_CACHE ? "true" : "false") + ";" +
|
||||||
"var SUPPORT_ASYNC = " + (SUPPORT_ASYNC ? "true" : "false") + ";" +
|
"var SUPPORT_ASYNC = " + (SUPPORT_ASYNC ? "true" : "false") + ";" +
|
||||||
|
"var SUPPORT_SERIALIZE = " + (SUPPORT_SERIALIZE ? "true" : "false") + ";" +
|
||||||
|
"var SUPPORT_INFO = " + (SUPPORT_INFO ? "true" : "false") + ";" +
|
||||||
"var SUPPORT_WORKER = true;"
|
"var SUPPORT_WORKER = true;"
|
||||||
|
|
||||||
) + "(" + _worker.toString() + ")()"
|
) + "(" + _worker.toString() + ")()"
|
||||||
@@ -2881,18 +2940,12 @@
|
|||||||
console.log("Register Worker: " + name + "@" + _core);
|
console.log("Register Worker: " + name + "@" + _core);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return worker_stack[name][_core];
|
||||||
|
|
||||||
"postMessage": function(id, data){
|
|
||||||
|
|
||||||
worker_stack[name][id]["postMessage"](data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
})() : false
|
}()) : false
|
||||||
|
|
||||||
), this);
|
)), this);
|
||||||
|
|
||||||
/** --------------------------------------------------------------------------------------
|
/** --------------------------------------------------------------------------------------
|
||||||
* UMD Wrapper for Browser and Node.js
|
* UMD Wrapper for Browser and Node.js
|
||||||
|
@@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
FlexSearch v0.3.3
|
FlexSearch v0.3.5
|
||||||
Copyright 2019 Nextapps GmbH
|
Copyright 2019 Nextapps GmbH
|
||||||
Author: Thomas Wilkerling
|
Author: Thomas Wilkerling
|
||||||
Released under the Apache 2.0 Licence
|
Released under the Apache 2.0 Licence
|
||||||
https://github.com/nextapps-de/flexsearch
|
https://github.com/nextapps-de/flexsearch
|
||||||
*/
|
*/
|
||||||
'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,
|
'use strict';(function(e,u,v){let m;(m=v.define)&&m.amd?m([],function(){return u}):(m=v.modules)?m[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 m(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}
|
f,d,n,g){if(b[c])return b[c];d=d?(9-(g||6))*n+(g||6)*d:n;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,
|
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",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=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||
|
"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.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.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,
|
!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=E[b]||b;c=this.f;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.f;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.g=C(10-(this.threshold||0));this.c=r();this.a=r();return this};e.prototype.encode=function(a){a&&B.length&&(a=v(a,B));
|
||||||
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,
|
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};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,f,d){if(b&&"string"===typeof b&&(a||0===a)){const e="@"+a;if(this.a[e]&&!f)return this.update(a,b);if(!d&&c)return this.add(a,b,null,f,!0),c(),this;b=this.encode(b);if(!b.length)return this;c=this.b;b=y(c)?c(b):b.split(D);f=r();f._ctx=
|
||||||
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=
|
r();d=this.threshold;const t=this.depth,q=this.g,p=b.length;for(let e=0;e<p;e++){var n=b[e];if(n){var g=n.length,k=(p-e)/p,l="";switch(c){case "reverse":case "both":for(var h=g-1;1<=h;h--)l=n[h]+l,m(q,f,l,a,(g-h)/g,k,d);l="";case "forward":for(h=0;h<g;h++)l+=n[h],m(q,f,l,a,1,k,d);break;case "full":for(h=0;h<g;h++){const b=(g-h)/g;for(let c=g;c>h;c--)l=n.substring(h,c),m(q,f,l,a,b,k,d)}break;default:if(g=m(q,f,n,a,1,k,d),t&&1<p&&g>=d)for(g=f._ctx[n]||(f._ctx[n]=r()),n=this.c[n]||(this.c[n]=C(10-(d||
|
||||||
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);
|
0))),k=e-t,l=e+t+1,0>k&&(k=0),l>p&&(l=p);k<l;k++)k!==e&&m(n,g,b[k],a,0,10-(k<e?e-k:k-e),d)}}}this.a[e]=1}return this};e.prototype.update=function(a,b,c){this.a["@"+a]&&"string"===typeof b&&(this.remove(a),this.add(a,b,c,!0));return this};e.prototype.remove=function(a,b,c){const f="@"+a;if(this.a[f]){if(!c&&b)return this.remove(a,null,!0),b(),this;for(b=0;b<10-(this.threshold||0);b++)z(this.g[b],a);this.depth&&z(this.c,a);delete this.a[f]}return this};e.prototype.search=function(a,b,c,f){var d=a,e=
|
||||||
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];
|
[];if("object"===typeof a){b=a.limit;var g=a.threshold;a=a.query}g||(g=this.threshold||0);y(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(!f&&c)return c(this.search(d,b,null,!0)),this;if(!a||"string"!==typeof a)return e;d=this.encode(a);if(!d.length)return e;a=this.b;a=y(a)?a(d):d.split(D);c=a.length;f=!0;d=[];var k=r();if(1<c)if(this.depth){var l=!0;var h=a[0];k[h]=1}else a.sort(H);var m;if(!l||(m=this.c)[h])for(var t=l?1:0;t<c;t++){var q=a[t];if(q){if(!k[q]){var p=[];let a=!1,b=0;if(h=l?m[h]:this.g){let c;
|
||||||
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=
|
for(let d=0;d<10-g;d++)if(c=h[d][q])p[b++]=c,a=!0}if(a)d[d.length]=1<b?p.concat.apply([],p):p[0];else{f=!1;break}k[q]=1}h=q}}else f=!1;if(f)a:{g=[];e=d.length;if(1<e){d.sort(I);l=r();m=d[0];h=m.length;for(a=0;a<h;)l["@"+m[a++]]=1;for(k=f=0;++k<e;){t=!1;q=k===e-1;m=d[k];h=m.length;for(a=0;a<h;)if(c=m[a++],p="@"+c,l[p]&&l[p]===k){if(q){if(g[f++]=c,b&&f===b){e=g;break a}}else l[p]=k+1;t=!0}if(!t)break}}else e&&(g=d[0],b&&g.length>b&&(g=g.slice(0,b)));e=g}return e};e.prototype.clear=function(){return this.destroy().init()};
|
||||||
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);
|
e.prototype.destroy=function(){this.g=this.c=this.a=null;return this};const w={icase:function(a){return a.toLowerCase()}};return e}(!1),this);
|
||||||
|
49
flexsearch.min.js
vendored
49
flexsearch.min.js
vendored
@@ -1,30 +1,31 @@
|
|||||||
/*
|
/*
|
||||||
FlexSearch v0.3.3
|
FlexSearch v0.3.5
|
||||||
Copyright 2019 Nextapps GmbH
|
Copyright 2019 Nextapps GmbH
|
||||||
Author: Thomas Wilkerling
|
Author: Thomas Wilkerling
|
||||||
Released under the Apache 2.0 Licence
|
Released under the Apache 2.0 Licence
|
||||||
https://github.com/nextapps-de/flexsearch
|
https://github.com/nextapps-de/flexsearch
|
||||||
*/
|
*/
|
||||||
'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+=
|
'use strict';(function(u,B,g){let v;(v=g.define)&&v.amd?v([],function(){return B}):(v=g.modules)?v[u.toLowerCase()]=B:"object"===typeof exports?module.exports=B:g[u]=B})("FlexSearch",function O(u){function g(a){E(a)&&(a=J[a]);a||(a=w);this.id=a.id||P++;this.init(a);v(this,"index",function(){return this.a});v(this,"length",function(){return Object.keys(this.a).length})}function v(a,b,c){Object.defineProperty(a,b,{get:c})}function e(a){return new RegExp(a,"g")}function x(a,b){for(let c=0;c<b.length;c+=
|
||||||
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"===
|
2)a=a.replace(b[c],b[c+1]);return a}function y(a,b,c,d,f,l,h){if(b[c])return b[c];f=f?(9-(h||6))*l+(h||6)*f:l;b[c]=f;f>=h&&(a=a[9-(f+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return f}function H(a,b){if(a){const c=Object.keys(a);for(let d=0,f=c.length;d<f;d++){const f=c[d],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]&&H(h[c],b)}}}function I(a){let b="",c="";var d="";for(let f=0;f<a.length;f++){const l=a[f];if(l!==c)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-
|
l){if(d="a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d,("a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c)&&d||" "===c)b+=l}else b+=l;d=f===a.length-1?"":a[f+1];c=l}return b}function Q(a,b){const c=r();if(a)for(let d=0;d<a.length;d++){const f=b?b(a[d]):a[d];c[f]=String.fromCharCode(65E3-a.length+d)}return c}function R(a,b){const c=[];if(a)for(const d in a)if(a.hasOwnProperty(d)){const f=b?b(d):d;c.push(e("(?=.{"+(f.length+3)+",})"+f+"$"),b?b(a[d]):a[d])}return c}function S(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.length;return 0>a?1:a?-1:0}function T(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function U(a,b,c){let d=[],f;const l=a.length;if(1<l){a.sort(T);const z=r();let e=a[0],g=e.length,k=0;for(;k<g;)z["@"+e[k++]]=1;let q,p=0,t=0;for(;++t<l;){let m=!1;const n=t===l-1;f=[];e=a[t];g=e.length;for(k=0;k<g;){q=e[k++];var h="@"+q;if(z[h]){const a=z[h];if(a===t){if(n){if(d[p++]=q,b&&p===b)return d}else z[h]=t+1;m=!0}else c&&(h=f[a]||(f[a]=[]),h[h.length]=q)}}if(!m&&!c)break}if(c&&(p=d.length,(t=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];
|
(!b||p<b)))for(;t--;)if(q=f[t])for(let a=0,c=q.length;a<c;a++)if(d[p++]=q[a],b&&p===b)return d}else l&&(d=a[0],b&&d.length>b&&(d=d.slice(0,b)));return d}function E(a){return"string"===typeof a}function F(a){return"function"===typeof a}function A(a){return"undefined"===typeof a}function K(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=r();return b}function r(){return Object.create(null)}function V(a,b,c,d){a=u("flexsearch","id"+a,function(){let a,b;self.onmessage=function(c){if(c=c.data)if(c.search){const d=
|
||||||
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,
|
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.info?(c=b.info(),c.worker=a,console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!1,c.options.worker=!1,b=(new Function(c.register.substring(c.register.indexOf("{")+1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}},function(a){(a=
|
||||||
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",
|
a.data)&&a.result&&d(a.id,a.content,a.result,a.limit)},b);const f=O.toString();c.id=b;a.postMessage({register:f,options:c,id:b});return a}const w={encode:"icase",b:"forward",u:!1,cache:!1,async:!1,c:!1,threshold:0,depth:0},J={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",
|
||||||
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)};
|
threshold:9,depth:1}},G=[];let P=0;const L=e("\\W+"),M={},N={};(function(){const a=Object.getOwnPropertyNames({}.__proto__),b=r();for(let c=0;c<a.length;c++)b[a[c]]=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(e(b),a[b]);return this};g.registerEncoder=function(a,b){D[a]=b.bind(D);return this};g.registerLanguage=function(a,b){M[a]=b.filter;N[a]=b.stemmer;return this};g.encode=function(a,b){return D[a](b)};g.prototype.init=
|
||||||
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,
|
function(a){this.m=[];a||(a=w);let b=a.profile;const c=b?J[b]:{};if(b=a.worker)if("undefined"!==typeof Worker){const c=this,f=parseInt(b,10)||4;c.w=-1;c.o=0;c.h=[];c.B=null;c.i=Array(f);for(let b=0;b<f;b++)c.i[b]=V(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.j.set(b,c.h),c.B(c.h),c.h=[]),c})}else a.worker=!1,this.i=null;this.b=a.tokenize||c.b||this.b||w.b;this.async="undefined"===typeof Promise||A(b=a.async)?this.async||
|
||||||
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)||
|
w.async:b;this.c=A(b=a.worker)?this.c||w.c:b;this.threshold=A(b=a.threshold)?c.threshold||this.threshold||w.threshold:b;this.depth=A(b=a.depth)?c.depth||this.depth||w.depth:b;this.u=A(b=a.suggest)?this.u||w.u:b;this.s=(b=A(b=a.encode)?c.encode:b)&&D[b]&&D[b].bind(D)||(F(b)?b:this.s||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=Q(M[b]||b,this.s);if(b=a.stemmer)this.stemmer=R(N[b]||b,this.s);this.f=K(10-(this.threshold||0));this.g=r();this.a=r();this.v=!0;this.j=(this.cache=b=A(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=
|
a.cache)?this.cache||w.cache:b)?new W(b):!1;return this};g.prototype.encode=function(a){a&&G.length&&(a=x(a,G));a&&this.m.length&&(a=x(a,this.m));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.m;for(const c in a)a.hasOwnProperty(c)&&b.push(e(c),a[c]);return this};g.prototype.add=function(a,b,c,d,f){if(b&&E(b)&&(a||0===a)){var e="@"+a;if(this.a[e]&&!d)return this.update(a,b);if(this.c)return++this.w>=this.i.length&&(this.w=
|
||||||
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);
|
0),this.i[this.w].postMessage({add:!0,id:a,content:b}),this.a[e]=""+this.w,c&&c(),this;if(!f){if(this.async&&"function"!==typeof importScripts){let f=this;e=new Promise(function(c){setTimeout(function(){f.add(a,b,null,d,!0);f=null;c()})});if(c)e.then(c);else return e;return this}if(c)return this.add(a,b,null,d,!0),c(),this}b=this.encode(b);if(!b.length)return this;c=this.b;f=F(c)?c(b):b.split(L);const l=r();l._ctx=r();const p=this.threshold,t=this.depth,z=this.f,C=f.length;for(let b=0;b<C;b++){var h=
|
||||||
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]||
|
f[b];if(h){var g=h.length,m=(C-b)/C,n="";switch(c){case "reverse":case "both":for(var k=g-1;1<=k;k--)n=h[k]+n,y(z,l,n,a,(g-k)/g,m,p);n="";case "forward":for(k=0;k<g;k++)n+=h[k],y(z,l,n,a,1,m,p);break;case "full":for(k=0;k<g;k++){const b=(g-k)/g;for(let c=g;c>k;c--)n=h.substring(k,c),y(z,l,n,a,b,m,p)}break;default:if(g=y(z,l,h,a,1,m,p),t&&1<C&&g>=p)for(g=l._ctx[h]||(l._ctx[h]=r()),h=this.g[h]||(this.g[h]=K(10-(p||0))),m=b-t,n=b+t+1,0>m&&(m=0),n>C&&(n=C);m<n;m++)m!==b&&y(h,g,f[m],a,0,10-(m<b?b-m:m-
|
||||||
(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;
|
b),p)}}}this.a[e]=1;this.v=!1}return this};g.prototype.update=function(a,b,c){this.a["@"+a]&&E(b)&&(this.remove(a),this.add(a,b,c,!0));return this};g.prototype.remove=function(a,b,c){var d="@"+a;if(this.a[d]){if(this.c)return this.i[this.a[d]].postMessage({remove:!0,id:a}),delete this.a[d],b&&b(),this;if(!c){if(this.async&&"function"!==typeof importScripts){let c=this;d=new Promise(function(b){setTimeout(function(){c.remove(a,null,!0);c=null;b()})});if(b)d.then(b);else return d;return this}if(b)return this.remove(a,
|
||||||
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,
|
null,!0),b(),this}for(b=0;b<10-(this.threshold||0);b++)H(this.f[b],a);this.depth&&H(this.g,a);delete this.a[d];this.v=!1}return this};g.prototype.search=function(a,b,c,d){let f=a,e;var h=[];"object"===typeof a&&((c=a.callback||b)&&(f.callback=null),b=a.limit,e=a.threshold,a=a.query);e||(e=this.threshold||0);F(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(this.c)for(this.B=c,this.o=0,this.h=[],h=0;h<this.c;h++)this.i[h].postMessage({search:!0,limit:b,threshold:e,content:a});else{if(!d){if(this.async&&"function"!==
|
||||||
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=
|
typeof importScripts){let d=this;a=new Promise(function(a){setTimeout(function(){a(d.search(f,b,null,!0));d=null})});if(c)a.then(c);else return a;return this}if(c)return c(this.search(f,b,null,!0)),this}if(!a||!E(a))return h;f=a;if(this.cache)if(this.v){if(c=this.j.get(a))return c}else this.j.clear(),this.v=!0;f=this.encode(f);if(!f.length)return h;c=this.b;c=F(c)?c(f):f.split(L);d=c.length;var g=!0,m=[],n=r();if(1<d)if(this.depth){var k=!0;var q=c[0];n[q]=1}else c.sort(S);var p;if(!k||(p=this.g)[q])for(let a=
|
||||||
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=
|
k?1:0;a<d;a++){const b=c[a];if(b){if(!n[b]){const a=[];let c=!1,d=0;if(q=k?p[q]:this.f){let f;for(let h=0;h<10-e;h++)if(f=q[h][b])a[d++]=f,c=!0}if(c)m[m.length]=1<d?a.concat.apply([],a):a[0];else if(!this.u){g=!1;break}n[b]=1}q=b}}else g=!1;g&&(h=U(m,b,this.u));this.cache&&this.j.set(a,h);return h}};g.prototype.info=function(){if(this.c)for(var a=0;a<this.c;a++)this.i[a].postMessage({info:!0,id:this.id});else{var b=0,c=0,d=0;for(var f=0;f<10-(this.threshold||0);f++){a=Object.keys(this.f[f]);for(let h=
|
||||||
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"),
|
0;h<a.length;h++){var e=this.f[f][a[h]].length;b+=1*e+2*a[h].length+4;c+=e;d+=2*a[h].length}}a=Object.keys(this.a);e=a.length;for(f=0;f<e;f++)b+=2*a[f].length+2;return{id:this.id,memory:b,items:e,sequences:c,chars:d,cache:this.cache&&this.cache.l?this.cache.l.length:!1,matcher:G.length+(this.m?this.m.length:0),worker:this.c,threshold:this.threshold,depth:this.depth,contextual:this.depth&&"strict"===this.b}}};g.prototype.clear=function(){return this.destroy().init()};g.prototype.destroy=function(){this.cache&&
|
||||||
"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=
|
(this.j.clear(),this.j=null);this.f=this.g=this.a=null;return this};g.prototype.export=function(){return JSON.stringify([this.f,this.g,this.a])};g.prototype.import=function(a){a=JSON.parse(a);this.f=a[0];this.g=a[1];this.a=a[2]};const D={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]"),
|
||||||
[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);
|
"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,c){if(!b)return b;b=this.simple(b);
|
||||||
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&&
|
2<b.length&&(b=x(b,a));c||1<b.length&&(b=I(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 c=0;c<b.length;c++){const d=b[c];1<d.length&&(b[c]=d[0]+x(d.substring(1),a))}b=b.join(" ");b=I(b)}return b}}(),balance:function(){const a=[e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s+")," "];return function(b){return I(x(b.toLowerCase(),
|
||||||
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=
|
a))}}()},W=function(){function a(a){this.clear();this.A=!0!==a&&a}a.prototype.clear=function(){this.cache=r();this.count=r();this.index=r();this.l=[]};a.prototype.set=function(a,c){if(this.A&&A(this.cache[a])){let b=this.l.length;if(b===this.A){b--;const a=this.l[b];delete this.cache[a];delete this.count[a];delete this.index[a]}this.index[a]=b;this.l[b]=a;this.count[a]=-1;this.cache[a]=c;this.get(a)}else this.cache[a]=c};a.prototype.get=function(a){const b=this.cache[a];if(this.A&&b){var d=++this.count[a];
|
||||||
x;return{postMessage:function(e,g){t[q][e].postMessage(g)}}}}()),this);
|
const b=this.index;let c=b[a];if(0<c){const e=this.l;for(var f=c;this.count[e[--c]]<=d&&-1!==c;);c++;if(c!==f){for(d=f;d>c;d--)f=e[d-1],e[d]=f,b[f]=d;e[c]=a;b[a]=c}}}return b};return a}();return g}(function(){const u={},B="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(g,v,e,x,y){e=B?URL.createObjectURL(new Blob(["("+e.toString()+")()"],{type:"text/javascript"})):g+".min.js";g+="-"+v;u[g]||(u[g]=[]);u[g][y]=new Worker(e);u[g][y].onmessage=x;return u[g][y]}}()),
|
||||||
|
this);
|
||||||
|
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flexsearch",
|
"name": "flexsearch",
|
||||||
"version": "0.3.3",
|
"version": "0.3.5",
|
||||||
"description": "Next-Generation full text search library with zero dependencies.",
|
"description": "Next-Generation full text search library with zero dependencies.",
|
||||||
"homepage": "https://github.com/nextapps-de/flexsearch/",
|
"homepage": "https://github.com/nextapps-de/flexsearch/",
|
||||||
"author": "Thomas Wilkerling",
|
"author": "Thomas Wilkerling",
|
||||||
@@ -25,11 +25,11 @@
|
|||||||
"url": "https://github.com/nextapps-de/flexsearch.git"
|
"url": "https://github.com/nextapps-de/flexsearch.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node compile RELEASE=min DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
"build": "node compile RELEASE=min DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=true SUPPORT_SERIALIZE=true SUPPORT_INFO=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||||
"build-light": "node compile RELEASE=light DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_SUGGESTIONS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
"build-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_SERIALIZE=false SUPPORT_INFO=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-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_SERIALIZE=false SUPPORT_INFO=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-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_SERIALIZE=false SUPPORT_INFO=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-es5": "node compile RELEASE=es5 DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=true SUPPORT_SERIALIZE=true SUPPORT_INFO=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false LANGUAGE_OUT=ECMASCRIPT5_STRICT",
|
||||||
"build-lang": "node compile RELEASE=lang",
|
"build-lang": "node compile RELEASE=lang",
|
||||||
"build-all": "npm run build && npm run build-light && npm run build-compact && npm run build-es5 && 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-production": "nyc --reporter=html --reporter=text mocha --timeout=3000 test --exit",
|
||||||
@@ -42,7 +42,6 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"flexsearch.js",
|
"flexsearch.js",
|
||||||
"flexsearch.min.js",
|
|
||||||
"lang/",
|
"lang/",
|
||||||
"test/",
|
"test/",
|
||||||
"compile.js",
|
"compile.js",
|
||||||
|
@@ -1,36 +1,37 @@
|
|||||||
/*
|
/*
|
||||||
FlexSearch v0.3.3
|
FlexSearch v0.3.5
|
||||||
Copyright 2019 Nextapps GmbH
|
Copyright 2019 Nextapps GmbH
|
||||||
Author: Thomas Wilkerling
|
Author: Thomas Wilkerling
|
||||||
Released under the Apache 2.0 Licence
|
Released under the Apache 2.0 Licence
|
||||||
https://github.com/nextapps-de/flexsearch
|
https://github.com/nextapps-de/flexsearch
|
||||||
*/
|
*/
|
||||||
'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)};
|
'use strict';function I(g){var k=0;return function(){return k<g.length?{done:!1,value:g[k++]}:{done:!0}}}function J(g){var k="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return k?k.call(g):{next:I(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,k,e){g!=Array.prototype&&g!=Object.prototype&&(g[k]=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})}}
|
function S(g,k){if(k){var e=Q;g=g.split(".");for(var h=0;h<g.length-1;h++){var a=g[h];a in e||(e[a]={});e=e[a]}g=g[g.length-1];h=e[g];k=k(h);k!=h&&null!=k&&R(e,g,{configurable:!0,writable:!0,value:k})}}
|
||||||
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=
|
S("Promise",function(g){function k(d){this.b=0;this.g=void 0;this.a=[];var a=this.c();try{d(a.resolve,a.reject)}catch(q){a.reject(q)}}function e(){this.a=null}function h(d){return d instanceof k?d:new k(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 e=
|
||||||
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)}};
|
d[a];d[a]=null;try{e()}catch(D){this.f(D)}}}this.a=null};e.prototype.f=function(d){this.c(function(){throw d;})};k.prototype.c=function(){function d(d){return function(k){e||(e=!0,d.call(a,k))}}var a=this,e=!1;return{resolve:d(this.u),reject:d(this.f)}};k.prototype.u=function(d){if(d===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(d instanceof k)this.v(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();
|
k.prototype.o=function(a){var d=void 0;try{d=a.then}catch(q){this.f(q);return}"function"==typeof d?this.w(d,a):this.j(a)};k.prototype.f=function(a){this.l(2,a)};k.prototype.j=function(a){this.l(1,a)};k.prototype.l=function(a,e){if(0!=this.b)throw Error("Cannot settle("+a+", "+e+"): Promise already settled in state"+this.b);this.b=a;this.g=e;this.m()};k.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;k.prototype.v=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: "+
|
a.B(d.resolve,d.reject)};k.prototype.w=function(a,e){var d=this.c();try{a.call(e,d.resolve,d.reject)}catch(D){d.reject(D)}};k.prototype.then=function(a,e){function d(a,d){return"function"==typeof a?function(d){try{g(a(d))}catch(C){h(C)}}:d}var g,h,l=new k(function(a,d){g=a;h=d});this.B(d(a,g),d(e,h));return l};k.prototype.catch=function(a){return this.then(void 0,a)};k.prototype.B=function(a,e){function d(){switch(k.b){case 1:a(k.g);break;case 2:e(k.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});
|
k.b);}}var k=this;null==this.a?l.b(d):this.a.push(d)};k.resolve=h;k.reject=function(a){return new k(function(d,e){e(a)})};k.race=function(a){return new k(function(d,e){for(var k=J(a),g=k.next();!g.done;g=k.next())h(g.value).B(d,e)})};k.all=function(a){var e=J(a),d=e.next();return d.done?h([]):new k(function(a,k){function g(d){return function(e){l[d]=e;q--;0==q&&a(l)}}var l=[],q=0;do l.push(void 0),q++,h(d.value).B(g(l.length-1),k),d=e.next();while(!d.done)})};return k});
|
||||||
(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],
|
(function(g,k,e){var h;(h=e.define)&&h.amd?h([],function(){return k}):(h=e.modules)?h[g.toLowerCase()]=k:"object"===typeof exports?module.exports=k:e[g]=k})("FlexSearch",function X(g){function e(b){E(b)&&((b=K[b])||console.warn("Preset not found: "+b));b||(b=x);this.id=b.id||Y++;this.init(b);h(this,"index",function(){return this.a});h(this,"length",function(){return Object.keys(this.a).length})}function h(b,c,a){Object.defineProperty(b,c,{get:a})}function a(b){return new RegExp(b,"g")}function l(b,
|
||||||
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||
|
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 G(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,h=g.length;A<h;A++)if(g[A]===c){1===h?delete b[e]:g.splice(A,1);break}else"object"===typeof g[A]&&G(g[A],c)}}function q(b){for(var c="",a="",f="",d=0;d<b.length;d++){var e=b[d];if(e!==
|
||||||
"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=
|
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 D(b,c){var a=y();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-
|
||||||
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++]=
|
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=b.length;if(1<d){b.sort(U);for(var e=y(),z=b[0],A=z.length,g=0;g<A;)e["@"+z[g++]]=1;for(var h,l=0,t=0;++t<d;){var r=!1,u=t===d-1;var n=[];z=b[t];A=z.length;for(g=0;g<A;){h=z[g++];var m="@"+h;if(e[m]){var p=e[m];if(p===t){if(u){if(f[l++]=h,c&&l===c)return f}else e[m]=t+1;r=!0}else a&&(m=n[p]||(n[p]=[]),m[m.length]=h)}}if(!r&&!a)break}if(a&&(l=f.length,(t=n.length)&&(!c||l<c)))for(;t--;)if(h=
|
||||||
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)},
|
n[t])for(b=0,a=h.length;b<a;b++)if(f[l++]=h[b],c&&l===c)return f}else d&&(f=b[0],c&&f.length>c&&(f=f.slice(0,c)));return f}function E(b){return"string"===typeof b}function C(b){return"function"===typeof b}function w(b){return"undefined"===typeof b}function M(b){for(var c=Array(b),a=0;a<b;a++)c[a]=y();return c}function y(){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?
|
||||||
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&&
|
{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.info?(a=c.info(),a.worker=b,console.log(a)):a.register&&(b=a.id,a.options.cache=!1,a.options.async=!1,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=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",
|
b.content,b.result,b.limit)},c);var d=X.toString();a.id=c;b.postMessage({register:d,options:a,id:c});return b}var x={encode:"icase",h:"forward",A:!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}},F=[],
|
||||||
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),
|
Y=0,N=a("\\W+"),O={},P={};(function(){for(var b=Object.getOwnPropertyNames({}.__proto__),c=y(),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){B[b]=c.bind(B);return this};e.registerLanguage=function(b,c){O[b]=c.filter;P[b]=c.stemmer;return this};e.encode=function(b,c){return B[b](c)};e.prototype.init=function(b){this.l=[];b||(b=x);var c=b.profile,
|
||||||
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&&
|
a=c?K[c]:{};a||console.warn("Preset not found: "+c);if(c=b.worker)if("undefined"!==typeof Worker){var f=this,d=parseInt(c,10)||4;f.v=-1;f.m=0;f.f=[];f.w=null;f.g=Array(d);for(var e=0;e<d;e++)f.g[e]=Z(f.id,e,b,function(b,c,a,d){if(f.m!==f.i)return f.f=f.f.concat(a),f.m++,d&&f.f.length>=d&&(f.m=f.i),f.w&&f.m===f.i&&(f.cache&&f.j.set(c,f.f),f.w(f.f),f.f=[]),f})}else b.worker=!1,this.g=null;this.h=b.tokenize||a.h||this.h||x.h;this.async="undefined"===typeof Promise||w(c=b.async)?this.async||x.async: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=
|
this.i=w(c=b.worker)?this.i||x.i:c;this.threshold=w(c=b.threshold)?a.threshold||this.threshold||x.threshold:c;this.depth=w(c=b.depth)?a.depth||this.depth||x.depth:c;this.A=w(c=b.suggest)?this.A||x.A:c;this.o=(c=w(c=b.encode)?a.encode:c)&&B[c]&&B[c].bind(B)||(C(c)?c:this.o||!1);(c=b.matcher)&&this.addMatcher(c);if(c=b.filter)this.filter=D(O[c]||c,this.o);if(c=b.stemmer)this.stemmer=T(P[c]||c,this.o);this.b=M(10-(this.threshold||0));this.c=y();this.a=y();this.u=!0;this.j=(this.cache=c=w(c=b.cache)?
|
||||||
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]);
|
this.cache||x.cache:c)?new aa(c):!1;return this};e.prototype.encode=function(b){b&&F.length&&(b=l(b,F));b&&this.l.length&&(b=l(b,this.l));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.l,d;for(d in b)b.hasOwnProperty(d)&&c.push(a(d),b[d]);return this};e.prototype.add=function(b,c,a,f,e){if(c&&E(c)&&(b||0===b)){var g="@"+b;if(this.a[g]&&!f)return this.update(b,c);if(this.i)return++this.v>=this.g.length&&(this.v=0),this.g[this.v].postMessage({add:!0,
|
||||||
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,
|
id:b,content:c}),this.a[g]=""+this.v,a&&a(),this;if(!e){if(this.async&&"function"!==typeof importScripts){var z=this;g=new Promise(function(a){setTimeout(function(){z.add(b,c,null,f,!0);z=null;a()})});if(a)g.then(a);else return g;return this}if(a)return this.add(b,c,null,f,!0),a(),this}c=this.encode(c);if(!c.length)return this;a=this.h;e=C(a)?a(c):c.split(N);var h=y();h._ctx=y();for(var l=this.threshold,H=this.depth,q=this.b,t=e.length,r=0;r<t;r++){var u=e[r];if(u){var n=u.length,m=(t-r)/t,p="";switch(a){case "reverse":case "both":for(var v=
|
||||||
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-
|
n-1;1<=v;v--)p=u[v]+p,d(q,h,p,b,(n-v)/n,m,l);p="";case "forward":for(v=0;v<n;v++)p+=u[v],d(q,h,p,b,1,m,l);break;case "full":for(v=0;v<n;v++)for(var x=(n-v)/n,w=n;w>v;w--)p=u.substring(v,w),d(q,h,p,b,x,m,l);break;default:if(n=d(q,h,u,b,1,m,l),H&&1<t&&n>=l)for(n=h._ctx[u]||(h._ctx[u]=y()),u=this.c[u]||(this.c[u]=M(10-(l||0))),m=r-H,p=r+H+1,0>m&&(m=0),p>t&&(p=t);m<p;m++)m!==r&&d(u,n,e[m],b,0,10-(m<r?r-m:m-r),l)}}}this.a[g]=1;this.u=!1}return this};e.prototype.update=function(b,a,d){this.a["@"+b]&&E(a)&&
|
||||||
(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=
|
(this.remove(b),this.add(b,a,d,!0));return this};e.prototype.remove=function(b,a,d){var c="@"+b;if(this.a[c]){if(this.i)return this.g[this.a[c]].postMessage({remove:!0,id:b}),delete this.a[c],a&&a(),this;if(!d){if(this.async&&"function"!==typeof importScripts){var e=this;c=new Promise(function(a){setTimeout(function(){e.remove(b,null,!0);e=null;a()})});if(a)c.then(a);else return c;return this}if(a)return this.remove(b,null,!0),a(),this}for(a=0;a<10-(this.threshold||0);a++)G(this.b[a],b);this.depth&&
|
||||||
!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=
|
G(this.c,b);delete this.a[c];this.u=!1}return this};e.prototype.search=function(a,c,d,e){var b=a,f=[];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);C(c)?(d=c,c=1E3):c||0===c||(c=1E3);if(this.i)for(this.w=d,this.m=0,this.f=[],f=0;f<this.i;f++)this.g[f].postMessage({search:!0,limit:c,threshold:g,content:a});else{if(!e){if(this.async&&"function"!==typeof importScripts){var h=this;a=new Promise(function(a){setTimeout(function(){a(h.search(b,
|
||||||
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++]=
|
c,null,!0));h=null})});if(d)a.then(d);else return a;return this}if(d)return d(this.search(b,c,null,!0)),this}if(!a||!E(a))return f;b=a;if(this.cache)if(this.u){if(d=this.j.get(a))return d}else this.j.clear(),this.u=!0;b=this.encode(b);if(!b.length)return f;d=this.h;d=C(d)?d(b):b.split(N);e=d.length;var l=!0,z=[],q=y();if(1<e)if(this.depth){var t=!0;var r=d[0];q[r]=1}else d.sort(W);var u;if(!t||(u=this.c)[r])for(var n=t?1:0;n<e;n++){var m=d[n];if(m){if(!q[m]){var p=[],v=!1,w=0;if(r=t?u[r]:this.b)for(var x=
|
||||||
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);
|
void 0,B=0;B<10-g;B++)if(x=r[B][m])p[w++]=x,v=!0;if(v)z[z.length]=1<w?p.concat.apply([],p):p[0];else if(!this.A){l=!1;break}q[m]=1}r=m}}else l=!1;l&&(f=V(z,c,this.A));this.cache&&this.j.set(a,f);return f}};e.prototype.info=function(){if(this.i)for(var a=0;a<this.i;a++)this.g[a].postMessage({info:!0,id:this.id});else{for(var c,d=0,e=0,g=0,h=0;h<10-(this.threshold||0);h++){a=Object.keys(this.b[h]);for(var l=0;l<a.length;l++)c=this.b[h][a[l]].length,d+=1*c+2*a[l].length+4,e+=c,g+=2*a[l].length}a=Object.keys(this.a);
|
||||||
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(),
|
c=a.length;for(h=0;h<c;h++)d+=2*a[h].length+2;return{id:this.id,memory:d,items:c,sequences:e,chars:g,cache:this.cache&&this.cache.s?this.cache.s.length:!1,matcher:F.length+(this.l?this.l.length:0),worker:this.i,threshold:this.threshold,depth:this.depth,contextual:this.depth&&"strict"===this.h}}};e.prototype.clear=function(){return this.destroy().init()};e.prototype.destroy=function(){this.cache&&(this.j.clear(),this.j=null);this.b=this.c=this.a=null;return this};e.prototype.export=function(){return JSON.stringify([this.b,
|
||||||
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;
|
this.c,this.a])};e.prototype.import=function(a){a=JSON.parse(a);this.b=a[0];this.c=a[1];this.a=a[2]};var B={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=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=
|
"",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=q(a));return a}}(),extra:function(){var b=[a("p"),"b",a("z"),"s",a("[cgq]"),"k",a("n"),"m",
|
||||||
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=
|
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=q(a)}return a}}(),balance:function(){var b=[a("[-/]")," ",a("[^a-z0-9 ]"),"",a("\\s+")," "];return function(a){return q(l(a.toLowerCase(),b))}}()},aa=function(){function a(a){this.clear();this.C=!0!==a&&a}a.prototype.clear=function(){this.cache=y();this.count=y();this.index=
|
||||||
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);
|
y();this.s=[]};a.prototype.set=function(a,b){if(this.C&&w(this.cache[a])){var c=this.s.length;if(c===this.C){c--;var d=this.s[c];delete this.cache[d];delete this.count[d];delete this.index[d]}this.index[a]=c;this.s[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.C&&b){var c=++this.count[a],d=this.index,e=d[a];if(0<e){for(var g=this.s,h=e;this.count[g[--e]]<=c&&-1!==e;);e++;if(e!==h){for(c=h;c>e;c--)h=g[c-1],g[c]=h,d[h]=
|
||||||
|
c;g[e]=a;d[a]=e}}}return b};return a}();return e}(function(){var g={},k="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(e,h,a,l,d){a=k?URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"})):e+".es5.js";e+="-"+h;g[e]||(g[e]=[]);g[e][d]=new Worker(a);g[e][d].onmessage=l;console.log("Register Worker: "+e+"@"+d);return g[e][d]}}()),this);
|
||||||
|
391
test/test.js
391
test/test.js
@@ -396,6 +396,8 @@ if(env !== "light"){
|
|||||||
|
|
||||||
it("Should have been added to the index", function(done){
|
it("Should have been added to the index", function(done){
|
||||||
|
|
||||||
|
expect(flexsearch_async.length).to.equal(0);
|
||||||
|
|
||||||
flexsearch_async.add(0, "foo");
|
flexsearch_async.add(0, "foo");
|
||||||
flexsearch_async.add(2, "bar");
|
flexsearch_async.add(2, "bar");
|
||||||
flexsearch_async.add(1, "foobar");
|
flexsearch_async.add(1, "foobar");
|
||||||
@@ -422,8 +424,7 @@ if(env !== "light"){
|
|||||||
flexsearch_async.add(3, false);
|
flexsearch_async.add(3, false);
|
||||||
flexsearch_async.add(3, []);
|
flexsearch_async.add(3, []);
|
||||||
flexsearch_async.add(3, {});
|
flexsearch_async.add(3, {});
|
||||||
flexsearch_async.add(3, function(){
|
flexsearch_async.add(3, function(){});
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
|
|
||||||
@@ -453,14 +454,9 @@ if(env !== "light"){
|
|||||||
flexsearch_async.search("foobar", function(result){
|
flexsearch_async.search("foobar", function(result){
|
||||||
|
|
||||||
expect(result).to.include(1);
|
expect(result).to.include(1);
|
||||||
|
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
// (async function(){
|
|
||||||
//
|
|
||||||
// expect(await flexsearch_async.search("foo")).to.have.members([0, 1]);
|
|
||||||
// })();
|
|
||||||
|
|
||||||
setTimeout(done, 25);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have been limited", function(done){
|
it("Should have been limited", function(done){
|
||||||
@@ -469,9 +465,9 @@ if(env !== "light"){
|
|||||||
|
|
||||||
expect(result).to.include(0);
|
expect(result).to.include(0);
|
||||||
expect(result).to.not.include(1);
|
expect(result).to.not.include(1);
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(done, 25);
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not have been matched from index", function(done){
|
it("Should not have been matched from index", function(done){
|
||||||
@@ -494,9 +490,9 @@ if(env !== "light"){
|
|||||||
flexsearch_async.search(" o ", function(result){
|
flexsearch_async.search(" o ", function(result){
|
||||||
|
|
||||||
expect(result).to.have.lengthOf(0);
|
expect(result).to.have.lengthOf(0);
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(done, 25);
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -508,24 +504,6 @@ if(env !== "light"){
|
|||||||
flexsearch_async.update(2, "foobar");
|
flexsearch_async.update(2, "foobar");
|
||||||
flexsearch_async.update(1, "foo");
|
flexsearch_async.update(1, "foo");
|
||||||
|
|
||||||
expect(flexsearch_async.length).to.equal(3);
|
|
||||||
|
|
||||||
flexsearch_async.search("foo").then(function(result){
|
|
||||||
expect(result).to.not.have.members([2, 1]);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_async.search("bar").then(function(result){
|
|
||||||
expect(result).to.not.include(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_async.search("bar").then(function(result){
|
|
||||||
expect(result).to.include(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_async.search("foobar").then(function(result){
|
|
||||||
expect(result).to.not.include(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
|
|
||||||
expect(flexsearch_async.length).to.equal(3);
|
expect(flexsearch_async.length).to.equal(3);
|
||||||
@@ -544,9 +522,9 @@ if(env !== "light"){
|
|||||||
|
|
||||||
flexsearch_async.search("foobar", function(result){
|
flexsearch_async.search("foobar", function(result){
|
||||||
expect(result).to.include(2);
|
expect(result).to.include(2);
|
||||||
});
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
}, 25);
|
}, 25);
|
||||||
});
|
});
|
||||||
@@ -581,9 +559,9 @@ if(env !== "light"){
|
|||||||
|
|
||||||
flexsearch_async.search("foobar").then(function(result){
|
flexsearch_async.search("foobar").then(function(result){
|
||||||
expect(result).to.include(2);
|
expect(result).to.include(2);
|
||||||
});
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
}, 25);
|
}, 25);
|
||||||
});
|
});
|
||||||
@@ -595,29 +573,25 @@ if(env !== "light"){
|
|||||||
|
|
||||||
flexsearch_async.remove(0);
|
flexsearch_async.remove(0);
|
||||||
flexsearch_async.remove(2);
|
flexsearch_async.remove(2);
|
||||||
flexsearch_async.remove(1);
|
flexsearch_async.remove(1).then(function(){
|
||||||
|
expect(flexsearch_async.length).to.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
expect(flexsearch_async.length).to.equal(3);
|
expect(flexsearch_async.length).to.equal(3);
|
||||||
|
|
||||||
setTimeout(function(){
|
flexsearch_async.search("foo", function(result){
|
||||||
|
expect(result).to.have.lengthOf(0);
|
||||||
|
});
|
||||||
|
|
||||||
expect(flexsearch_async.length).to.equal(0);
|
flexsearch_async.search("bar", function(result){
|
||||||
|
expect(result).to.have.lengthOf(0);
|
||||||
|
});
|
||||||
|
|
||||||
flexsearch_async.search("foo", function(result){
|
flexsearch_async.search("foobar", function(result){
|
||||||
expect(result).to.have.lengthOf(0);
|
expect(result).to.have.lengthOf(0);
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_async.search("bar", function(result){
|
|
||||||
expect(result).to.have.lengthOf(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_async.search("foobar", function(result){
|
|
||||||
expect(result).to.have.lengthOf(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
}, 25);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -625,176 +599,169 @@ if(env !== "light"){
|
|||||||
// Worker Tests
|
// Worker Tests
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
describe("Add (Worker)", function(){
|
if(typeof Worker !== "undefined" && !this._phantom){
|
||||||
|
|
||||||
it("Should support worker", function(){
|
describe("Add (Worker)", function(){
|
||||||
|
|
||||||
if(typeof Worker === "undefined"){
|
it("Should support worker", function(){
|
||||||
|
|
||||||
Worker = function(){};
|
flexsearch_worker = new FlexSearch({
|
||||||
|
|
||||||
Worker.prototype.postMessage = function(val){
|
encode: "icase",
|
||||||
this.onmessage(val);
|
tokenize: "reverse",
|
||||||
};
|
async: false,
|
||||||
Worker.prototype.onmessage = function(val){
|
worker: 4
|
||||||
return val;
|
});
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
flexsearch_worker = new FlexSearch({
|
it("Should have been added to the index", function(done){
|
||||||
|
|
||||||
encode: "icase",
|
flexsearch_worker.add(0, "foo");
|
||||||
tokenize: "strict",
|
flexsearch_worker.add(2, "bar");
|
||||||
async: false,
|
flexsearch_worker.add(1, "foobar");
|
||||||
worker: 4
|
|
||||||
|
setTimeout(function(){
|
||||||
|
|
||||||
|
expect(flexsearch_worker.length).to.equal(3);
|
||||||
|
expect(flexsearch_worker.index).to.have.keys(["@0", "@1", "@2"]);
|
||||||
|
|
||||||
|
flexsearch_worker.search("foo", function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.length(2);
|
||||||
|
expect(result).to.have.members([0, 1]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
}, 25);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should not have been added to the index", function(done){
|
||||||
|
|
||||||
|
flexsearch_worker.add("foo");
|
||||||
|
flexsearch_worker.add(3);
|
||||||
|
flexsearch_worker.add(null, "foobar");
|
||||||
|
flexsearch_worker.add(void 0, "foobar");
|
||||||
|
flexsearch_worker.add(4, null);
|
||||||
|
flexsearch_worker.add(5, false);
|
||||||
|
flexsearch_worker.add(6, []);
|
||||||
|
flexsearch_worker.add(7, {});
|
||||||
|
flexsearch_worker.add(8, function(){
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function(){
|
||||||
|
|
||||||
|
expect(flexsearch_worker.length).to.equal(3);
|
||||||
|
expect(flexsearch_worker.index).to.have.keys(["@0", "@1", "@2"]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
|
||||||
|
}, 25);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have been added to the index", function(done){
|
describe("Search (Worker)", function(){
|
||||||
|
|
||||||
flexsearch_worker.add(0, "foo");
|
it("Should have been matched from index", function(done){
|
||||||
flexsearch_worker.add(2, "bar");
|
|
||||||
flexsearch_worker.add(1, "foobar");
|
|
||||||
|
|
||||||
expect(flexsearch_worker.length).to.equal(3);
|
flexsearch_worker.search("foo", function(result){
|
||||||
expect(flexsearch_worker.index).to.have.keys(["@0", "@1", "@2"]);
|
|
||||||
|
|
||||||
flexsearch_worker.search("foo", function(result){
|
expect(result).to.have.lengthOf(2);
|
||||||
|
|
||||||
expect(result).to.have.length(0);
|
flexsearch_worker.search("bar", function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.lengthOf(2);
|
||||||
|
|
||||||
|
flexsearch_worker.search("foobar", function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.lengthOf(1);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(done, 25);
|
it("Should have been limited", function(done){
|
||||||
|
|
||||||
|
flexsearch_worker.search("foo", 1, function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.lengthOf(1);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should not have been matched from index", function(done){
|
||||||
|
|
||||||
|
flexsearch_worker.search("barfoo", function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.lengthOf(0);
|
||||||
|
|
||||||
|
flexsearch_worker.search("", function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.lengthOf(0);
|
||||||
|
|
||||||
|
flexsearch_worker.search(" ", function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.lengthOf(0);
|
||||||
|
|
||||||
|
flexsearch_worker.search(" o ", function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.lengthOf(1);
|
||||||
|
|
||||||
|
flexsearch_worker.search(" fob ", function(result){
|
||||||
|
|
||||||
|
expect(result).to.have.lengthOf(0);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not have been added to the index", function(done){
|
describe("Update (Worker)", function(){
|
||||||
|
|
||||||
flexsearch_worker.add("foo");
|
it("Should have been updated to the index", function(done){
|
||||||
flexsearch_worker.add(3);
|
|
||||||
flexsearch_worker.add(null, "foobar");
|
|
||||||
flexsearch_worker.add(void 0, "foobar");
|
|
||||||
flexsearch_worker.add(4, null);
|
|
||||||
flexsearch_worker.add(5, false);
|
|
||||||
flexsearch_worker.add(6, []);
|
|
||||||
flexsearch_worker.add(7, {});
|
|
||||||
flexsearch_worker.add(8, function(){});
|
|
||||||
|
|
||||||
setTimeout(function(){
|
flexsearch_worker.update(0, "bar");
|
||||||
|
flexsearch_worker.update(2, "foobar");
|
||||||
|
flexsearch_worker.update(1, "foo", function(){
|
||||||
|
|
||||||
expect(flexsearch_worker.length).to.equal(3);
|
expect(flexsearch_worker.length).to.equal(3);
|
||||||
expect(flexsearch_worker.index).to.have.keys(["@0", "@1", "@2"]);
|
|
||||||
|
|
||||||
done();
|
flexsearch_worker.search("foo", function(results){
|
||||||
|
|
||||||
}, 25);
|
expect(results).to.have.members([2, 1]);
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Search (Worker)", function(){
|
flexsearch_worker.search("bar", function(results){
|
||||||
|
|
||||||
it("Should have been matched from index", function(done){
|
expect(results).to.have.members([0, 2]);
|
||||||
|
|
||||||
flexsearch_worker.search("foo", function(result){
|
flexsearch_worker.search("foobar", function(results){
|
||||||
|
|
||||||
expect(result).to.have.lengthOf(2);
|
expect(results).to.have.members([2]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
flexsearch_worker.search("bar", function(result){
|
|
||||||
|
|
||||||
expect(result).to.have.lengthOf(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_worker.search("foobar", function(result){
|
|
||||||
|
|
||||||
expect(result).to.have.lengthOf(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(done, 25);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should have been limited", function(done){
|
describe("Remove (Worker)", function(){
|
||||||
|
|
||||||
flexsearch_worker.search("foo", 1, function(result){
|
it("Should have been removed from the index", function(done){
|
||||||
|
|
||||||
expect(result).to.include(0);
|
|
||||||
expect(result).to.not.include(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(done, 25);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Should not have been matched from index", function(done){
|
|
||||||
|
|
||||||
flexsearch_worker.search("barfoo", function(result){
|
|
||||||
|
|
||||||
expect(result).to.have.lengthOf(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_worker.search("", function(result){
|
|
||||||
|
|
||||||
expect(result).to.have.lengthOf(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_worker.search(" ", function(result){
|
|
||||||
|
|
||||||
expect(result).to.have.lengthOf(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_worker.search(" o ", function(result){
|
|
||||||
|
|
||||||
expect(result).to.have.lengthOf(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(done, 25);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
/*
|
|
||||||
describe("Update (Worker)", function(){
|
|
||||||
|
|
||||||
it("Should have been updated to the index", function(done){
|
|
||||||
|
|
||||||
flexsearch_worker.update(0, "bar");
|
|
||||||
flexsearch_worker.update(2, "foobar");
|
|
||||||
flexsearch_worker.update(1, "foo");
|
|
||||||
|
|
||||||
setTimeout(function(){
|
|
||||||
|
|
||||||
expect(flexsearch_worker.length).to.equal(3);
|
expect(flexsearch_worker.length).to.equal(3);
|
||||||
|
|
||||||
flexsearch_worker.search("foo", function(results){
|
flexsearch_worker.remove(0);
|
||||||
|
flexsearch_worker.remove(2);
|
||||||
expect(results).to.have.members([2, 1]);
|
flexsearch_worker.remove(1);
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_worker.search("bar", function(results){
|
|
||||||
|
|
||||||
expect(results).to.have.members([0, 2]);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_worker.search("foobar", function(results){
|
|
||||||
|
|
||||||
expect(results).to.have.members([2]);
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(done, 25);
|
|
||||||
}, 25);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe("Remove (Worker)", function(){
|
|
||||||
|
|
||||||
it("Should have been removed from the index", function(done){
|
|
||||||
|
|
||||||
expect(flexsearch_worker.length).to.equal(3);
|
|
||||||
|
|
||||||
flexsearch_worker.remove(0);
|
|
||||||
flexsearch_worker.remove(2);
|
|
||||||
flexsearch_worker.remove(1);
|
|
||||||
|
|
||||||
setTimeout(function(){
|
|
||||||
|
|
||||||
expect(flexsearch_worker.length).to.equal(0);
|
expect(flexsearch_worker.length).to.equal(0);
|
||||||
|
|
||||||
@@ -802,31 +769,31 @@ if(env !== "light"){
|
|||||||
|
|
||||||
expect(results).to.not.include(1);
|
expect(results).to.not.include(1);
|
||||||
expect(results).to.not.include(2);
|
expect(results).to.not.include(2);
|
||||||
|
|
||||||
|
flexsearch_worker.search("bar", function(results){
|
||||||
|
|
||||||
|
expect(results).to.not.include(0);
|
||||||
|
expect(results).to.not.include(2);
|
||||||
|
|
||||||
|
flexsearch_worker.search("foobar", function(results){
|
||||||
|
|
||||||
|
expect(results).to.not.include(2);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
flexsearch_worker.search("bar", function(results){
|
|
||||||
|
|
||||||
expect(results).to.not.include(0);
|
|
||||||
expect(results).to.not.include(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
flexsearch_worker.search("foobar", function(results){
|
|
||||||
|
|
||||||
expect(results).to.not.include(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(done, 25);
|
|
||||||
}, 25);
|
|
||||||
});
|
|
||||||
|
|
||||||
if(env !== "light" && env !== "min"){
|
|
||||||
|
|
||||||
it("Should have been debug mode activated", function(){
|
|
||||||
|
|
||||||
flexsearch_worker.info();
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
if(env !== "light" && env !== "min"){
|
||||||
|
|
||||||
|
it("Should have been debug mode activated", function(){
|
||||||
|
|
||||||
|
flexsearch_worker.info();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe("Worker Not Supported", function(){
|
describe("Worker Not Supported", function(){
|
||||||
|
|
||||||
@@ -840,7 +807,7 @@ if(env !== "light"){
|
|||||||
flexsearch_worker = new FlexSearch({
|
flexsearch_worker = new FlexSearch({
|
||||||
|
|
||||||
encode: false,
|
encode: false,
|
||||||
async: true,
|
async: false,
|
||||||
worker: 4
|
worker: 4
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user