mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-02 18:33:17 +02:00
v0.4.0
This commit is contained in:
22
CHANGELOG.md
Normal file
22
CHANGELOG.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Changelog
|
||||
|
||||
#### v0.4.0
|
||||
|
||||
- Index Documents (Field-Search)
|
||||
|
||||
#### v0.3.6
|
||||
|
||||
- Right-To-Left Support
|
||||
- CJK Word Splitting Support
|
||||
|
||||
#### v0.3.5
|
||||
|
||||
- Promise Support
|
||||
|
||||
#### v0.3.4
|
||||
|
||||
- Export / Import Indexes (Serialize)
|
||||
|
||||
#### v0.3.0
|
||||
|
||||
- Profiler Support
|
214
README.md
214
README.md
@@ -21,7 +21,7 @@ FlexSearch also provides you a non-blocking asynchronous processing model as wel
|
||||
|
||||
FlexSearch Server is also available here: <a target="_blank" href="https://github.com/nextapps-de/flexsearch-server">https://github.com/nextapps-de/flexsearch-server</a>.
|
||||
|
||||
<a href="#installation">Installation Guide</a>  •  <a href="#api">API Reference</a>  •  <a href="#profiles">Example Options</a>  •  <a href="#builds">Custom Builds</a>  •  <a target="_blank" href="https://github.com/nextapps-de/flexsearch-server">Flexsearch Server</a>
|
||||
<a href="#installation">Installation Guide</a>  •  <a href="#api">API Reference</a>  •  <a href="#profiles">Example Options</a>  •  <a href="#builds">Custom Builds</a>  •  <a target="_blank" href="https://github.com/nextapps-de/flexsearch-server">Flexsearch Server</a>  •  <a href="CHANGELOG.md">Changelog</a>
|
||||
|
||||
Supported Platforms:
|
||||
- Browser
|
||||
@@ -114,6 +114,15 @@ All Features:
|
||||
<td>✔</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#docs">Index Documents (Field-Search)</a>
|
||||
</td>
|
||||
<td>✔</td>
|
||||
<td>✔</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr></tr>
|
||||
<tr>
|
||||
<td>
|
||||
Partial Matching
|
||||
@@ -994,6 +1003,201 @@ Returns information e.g.:
|
||||
"contextual": true
|
||||
}
|
||||
```
|
||||
|
||||
<a name="docs"></a>
|
||||
## Index Documents (Field-Search)
|
||||
|
||||
#### The Document Descriptor
|
||||
|
||||
Assume the document is an array of data like:
|
||||
|
||||
```js
|
||||
var docs = [{
|
||||
id: 0,
|
||||
title: "Title",
|
||||
cat: "Category",
|
||||
content: "Body"
|
||||
},{
|
||||
id: 1,
|
||||
title: "Title",
|
||||
cat: "Category",
|
||||
content: "Body"
|
||||
}];
|
||||
```
|
||||
|
||||
Provide a document descriptor ___doc___ when initializing a new index, e.g. related to the example above:
|
||||
|
||||
```js
|
||||
var index = new FlexSearch({
|
||||
tokenize: "strict",
|
||||
depth: 3,
|
||||
doc: {
|
||||
id: "id",
|
||||
field: "content"
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The above example will index one field ("content"), to index multiple fields just pass an array:
|
||||
|
||||
```js
|
||||
var index = new FlexSearch({
|
||||
doc: {
|
||||
id: "id",
|
||||
field: [
|
||||
"title",
|
||||
"cat",
|
||||
"content"
|
||||
]
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
#### Complex Objects
|
||||
|
||||
Assume the document array looks more complex (has nested branches etc.), e.g.:
|
||||
|
||||
```js
|
||||
var docs = [{
|
||||
data:{
|
||||
id: 0,
|
||||
title: "Title",
|
||||
body: {
|
||||
content: "Body"
|
||||
}
|
||||
}
|
||||
},{
|
||||
data:{
|
||||
id: 1,
|
||||
title: "Title",
|
||||
body: {
|
||||
content: "Body"
|
||||
}
|
||||
}
|
||||
}];
|
||||
```
|
||||
|
||||
Then use the colon separated notation ___"root:child"___ to define hierarchy within the document descriptor:
|
||||
|
||||
```js
|
||||
var index = new FlexSearch({
|
||||
doc: {
|
||||
id: "data:id",
|
||||
field: [
|
||||
"data:title",
|
||||
"data:content:body"
|
||||
]
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
#### Add/Update/Remove Documents to the Index
|
||||
|
||||
Just pass the document array (or one single object) to the index:
|
||||
```js
|
||||
index.add(docs);
|
||||
```
|
||||
|
||||
Update (single object or array of objects):
|
||||
```js
|
||||
index.update({
|
||||
data:{
|
||||
id: 0,
|
||||
title: "Foo",
|
||||
body: {
|
||||
content: "Bar"
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Remove (single object or array of objects):
|
||||
```js
|
||||
index.remove(docs);
|
||||
```
|
||||
|
||||
When you know the id, you can also simply remove by:
|
||||
```js
|
||||
index.remove(id);
|
||||
```
|
||||
|
||||
#### Field-Search
|
||||
|
||||
When searching you have several options when using documents.
|
||||
|
||||
This will search through all indexed fields:
|
||||
```js
|
||||
var results = index.search("body");
|
||||
```
|
||||
|
||||
This will search on a specific field):
|
||||
|
||||
```js
|
||||
var results = index.search({
|
||||
field: "title",
|
||||
query: "title"
|
||||
});
|
||||
```
|
||||
|
||||
The colon notation also has to be applied for the searching respectively, e.g.:
|
||||
|
||||
```js
|
||||
var results = index.search({
|
||||
field: "data:body",
|
||||
query: "body"
|
||||
});
|
||||
```
|
||||
|
||||
This could also be written as:
|
||||
```js
|
||||
var results = index.search("body", {
|
||||
field: "data:body",
|
||||
});
|
||||
```
|
||||
|
||||
Search the same query on multiple fields:
|
||||
|
||||
```js
|
||||
var results = index.search({
|
||||
query: "title",
|
||||
field: ["title", "body"]
|
||||
});
|
||||
```
|
||||
|
||||
Could also be written as:
|
||||
|
||||
```js
|
||||
var results = index.search("title", {
|
||||
field: ["title", "body"]
|
||||
});
|
||||
```
|
||||
|
||||
Search different queries on multiple fields:
|
||||
|
||||
```js
|
||||
var results = index.search([{
|
||||
field: "title",
|
||||
query: "title"
|
||||
},{
|
||||
field: "body",
|
||||
query: "body"
|
||||
}]);
|
||||
```
|
||||
|
||||
Boost scoring on specific fields:
|
||||
|
||||
```js
|
||||
var results = index.search([{
|
||||
field: "title",
|
||||
query: "title",
|
||||
boost: 2
|
||||
},{
|
||||
field: "body",
|
||||
query: "body",
|
||||
boost: 0.5
|
||||
}]);
|
||||
```
|
||||
|
||||
<a name="chaining"></a>
|
||||
### Chaining
|
||||
|
||||
@@ -1011,7 +1215,7 @@ index.remove(0).update(1, 'foo').add(2, 'foobar');
|
||||
```
|
||||
|
||||
<a name="contextual_enable"></a>
|
||||
### Enable Contextual Scoring
|
||||
## Enable Contextual Scoring
|
||||
|
||||
Create an index and just set the limit of relevance as "depth":
|
||||
```js
|
||||
@@ -1031,7 +1235,7 @@ var index = new FlexSearch({
|
||||
> Try to use the __lowest depth__ and __highest threshold__ which fits your needs.
|
||||
|
||||
<a name="cache"></a>
|
||||
### Enable Auto-Balanced Cache
|
||||
## Enable Auto-Balanced Cache
|
||||
|
||||
Create index and just set a limit of cache entries:
|
||||
```js
|
||||
@@ -1047,7 +1251,7 @@ var index = new FlexSearch({
|
||||
> When just using "true" the cache is unbounded and perform actually 2-3 times faster (because the balancer do not have to run).
|
||||
|
||||
<a name="webworker"></a>
|
||||
### WebWorker Sharding (Browser only)
|
||||
## WebWorker Sharding (Browser only)
|
||||
|
||||
Worker get its own dedicated memory and also run in their own dedicated thread without blocking the UI while processing. Especially for larger indexes, web worker improves speed and available memory a lot. FlexSearch index was tested with a 250 Mb text file including 10 Million words. <!--The indexing was done silently in background by multiple parallel running workers in about 7 minutes. The final index reserves ~ 8.2 Mb memory/space. The search result took ~ 0.25 ms.-->
|
||||
|
||||
@@ -1901,6 +2105,8 @@ node compile SUPPORT_WORKER=true
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<a href="CHANGELOG.md">Changelog</a>
|
||||
|
||||
---
|
||||
|
||||
Copyright 2019 Nextapps GmbH<br>
|
||||
|
@@ -4,61 +4,75 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1, maximum-scale=1.0, user-scalable=no">
|
||||
<title>Demo: Auto-Complete</title>
|
||||
<script src="../dist/flexsearch.min.js"></script>
|
||||
<script src="../dist/flexsearch.compact.js"></script>
|
||||
<script src="../data/movies.js"></script>
|
||||
<style>
|
||||
body{
|
||||
padding:0;
|
||||
margin:0 10px;
|
||||
}
|
||||
table{
|
||||
width: 500px;
|
||||
width: 300px;
|
||||
table-layout: fixed;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
padding-top: 10px;
|
||||
background-color: #fff;
|
||||
z-index: 1;
|
||||
}
|
||||
td, tr{
|
||||
width: 500px;
|
||||
width: 300px;
|
||||
border: none;
|
||||
}
|
||||
input{
|
||||
width: 500px;
|
||||
width: 300px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 3px;
|
||||
border-radius: 4px;
|
||||
outline: none;
|
||||
background-color: transparent;
|
||||
position: relative;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
position: absolute;
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
#autocomplete{
|
||||
color: #999;
|
||||
background-color: #f5f5f5;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
input, div{
|
||||
padding:5px 5px;
|
||||
input{
|
||||
padding:7px 5px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
#suggestions{
|
||||
position: relative;
|
||||
top: 35px;
|
||||
}
|
||||
#suggestions div{
|
||||
padding: 10px 0;
|
||||
margin: 0 8px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
table,
|
||||
td,
|
||||
tr,
|
||||
input{
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<td style="position: relative">
|
||||
<input type="text" id="autocomplete">
|
||||
<input type="text" id="userinput" placeholder="Search by movie title ...">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div id="suggestions"></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="suggestions"></div>
|
||||
<script>
|
||||
(function(){
|
||||
|
||||
@@ -79,12 +93,13 @@
|
||||
}
|
||||
|
||||
userinput.addEventListener("input", show_results, true);
|
||||
userinput.addEventListener("keyup", accept_result, true);
|
||||
userinput.addEventListener("keyup", accept_autocomplete, true);
|
||||
suggestions.addEventListener("click", accept_suggestion, true);
|
||||
|
||||
function show_results(){
|
||||
|
||||
var value = this.value;
|
||||
var results = index.search(value, 10);
|
||||
var results = index.search(value, 20);
|
||||
var entry, childs = suggestions.childNodes;
|
||||
var i = 0, len = results.length;
|
||||
|
||||
@@ -121,7 +136,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function accept_result(event){
|
||||
function accept_autocomplete(event){
|
||||
|
||||
if((event || window.event).keyCode === 13) {
|
||||
|
||||
@@ -129,6 +144,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
function accept_suggestion(event){
|
||||
|
||||
var target = (event || window.event).target;
|
||||
|
||||
userinput.value = autocomplete.value = target.textContent;
|
||||
|
||||
while(suggestions.lastChild){
|
||||
|
||||
suggestions.removeChild(suggestions.lastChild);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
|
38
dist/flexsearch.compact.js
vendored
38
dist/flexsearch.compact.js
vendored
@@ -1,23 +1,27 @@
|
||||
/*
|
||||
FlexSearch v0.3.62
|
||||
FlexSearch v0.4.0
|
||||
Copyright 2019 Nextapps GmbH
|
||||
Author: Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(f,p,d){let k;(k=d.define)&&k.amd?k([],function(){return p}):(k=d.modules)?k[f.toLowerCase()]=p:"object"===typeof exports?module.exports=p:d[f]=p})("FlexSearch",function(){function f(b){this.id=b&&!y(b.id)?b.id:L++;this.init(b);p(this,"index",function(){return this.b});p(this,"length",function(){return Object.keys(this.b).length})}function p(b,a,c){Object.defineProperty(b,a,{get:c})}function d(b){return new RegExp(b,"g")}function k(b,a){for(let c=0;c<a.length;c+=2)b=b.replace(a[c],
|
||||
a[c+1]);return b}function z(b,a,c,g,e,d,m){if(a[c])return a[c];e=e?(9-(m||6))*d+(m||6)*e:d;a[c]=e;e>=m&&(b=b[9-(e+.5>>0)],b=b[c]||(b[c]=[]),b[b.length]=g);return e}function C(b,a){if(b){const c=Object.keys(b);for(let g=0,d=c.length;g<d;g++){const d=c[g],e=b[d];if(e)for(let c=0,g=e.length;c<g;c++)if(e[c]===a){1===g?delete b[d]:e.splice(c,1);break}else"object"===typeof e[c]&&C(e[c],a)}}}function D(b){let a="",c="";var d="";for(let e=0;e<b.length;e++){const g=b[e];if(g!==c)if(e&&"h"===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)a+=g}else a+=g;d=e===b.length-1?"":b[e+1];c=g}return a}function M(b,a){b=b.length-a.length;return 0>b?1:b?-1:0}function N(b,a){b=b.length-a.length;return 0>b?-1:b?1:0}function O(b,a,c){let d=[],e;const t=b.length;if(1<t){b.sort(N);const g=u();let l=b[0],n=l.length,h=0;for(;h<n;)g["@"+l[h++]]=1;let f,q=0,r=0;for(;++r<t;){let F=!1;const k=r===t-1;e=[];l=b[r];n=l.length;for(h=0;h<n;){f=l[h++];
|
||||
var m="@"+f;if(g[m]){const b=g[m];if(b===r){if(k){if(d[q++]=f,a&&q===a)return d}else g[m]=r+1;F=!0}else c&&(m=e[b]||(e[b]=[]),m[m.length]=f)}}if(!F&&!c)break}if(c&&(q=d.length,(r=e.length)&&(!a||q<a)))for(;r--;)if(f=e[r])for(h=0,n=f.length;h<n;h++)if(d[q++]=f[h],a&&q===a)return d}else t&&(d=b[0],a&&d.length>a&&(d=d.slice(0,a)));return d}function A(b){return"string"===typeof b}function B(b){return"function"===typeof b}function y(b){return"undefined"===typeof b}function G(b){const a=Array(b);for(let c=
|
||||
0;c<b;c++)a[c]=u();return a}function u(){return Object.create(null)}const w={encode:"icase",a:"forward",j:!1,cache:!1,async:!1,l:!1,h:!1,threshold:0,depth:0},H={memory:{encode:"extra",a:"strict",threshold:7},speed:{encode:"icase",a:"strict",threshold:7,depth:2},match:{encode:"extra",a:"full"},score:{encode:"extra",a:"strict",threshold:5,depth:4},balance:{encode:"balance",a:"strict",threshold:6,depth:3},fastest:{encode:"icase",a:"strict",threshold:9,depth:1}},E=[];let L=0;const I=d("\\W+"),J={},K=
|
||||
{};f.create=function(b){return new f(b)};f.registerMatcher=function(b){for(const a in b)b.hasOwnProperty(a)&&E.push(d(a),b[a]);return this};f.registerEncoder=function(b,a){x[b]=a.bind(x);return this};f.registerLanguage=function(b,a){J[b]=a.filter;K[b]=a.stemmer;return this};f.encode=function(b,a){return x[b](a)};f.prototype.init=function(b){this.i=[];b||(b=w);var a=b.preset,c={};A(b)?(c=H[b],b={}):a&&(c=H[a]);this.a=b.tokenize||c.a||this.a||w.a;this.h=b.rtl||this.h||w.h;this.async="undefined"===typeof Promise||
|
||||
y(a=b.async)?this.async||w.async:a;this.threshold=y(a=b.threshold)?c.threshold||this.threshold||w.threshold:a;this.depth=y(a=b.depth)?c.depth||this.depth||w.depth:a;this.f=(a=y(a=b.encode)?c.encode:a)&&x[a]&&x[a].bind(x)||(B(a)?a:this.f||!1);(a=b.matcher)&&this.addMatcher(a);if(a=b.filter){a=J[a]||a;c=this.f;var g=u();if(a)for(let b=0;b<a.length;b++){const d=c?c(a[b]):a[b];g[d]=String.fromCharCode(65E3-a.length+b)}this.filter=a=g}if(a=b.stemmer){var e;b=K[a]||a;a=this.f;c=[];if(b)for(e in b)b.hasOwnProperty(e)&&
|
||||
(g=a?a(e):e,c.push(d("(?=.{"+(g.length+3)+",})"+g+"$"),a?a(b[e]):b[e]));this.stemmer=e=c}this.g=G(10-(this.threshold||0));this.c=u();this.b=u();return this};f.prototype.encode=function(b){b&&E.length&&(b=k(b,E));b&&this.i.length&&(b=k(b,this.i));b&&this.f&&(b=this.f(b));b&&this.stemmer&&(b=k(b,this.stemmer));return b};f.prototype.addMatcher=function(b){const a=this.i;for(const c in b)b.hasOwnProperty(c)&&a.push(d(c),b[c]);return this};f.prototype.add=function(b,a,c,d,e){if(a&&A(a)&&(b||0===b)){var g=
|
||||
"@"+b;if(this.b[g]&&!d)return this.update(b,a);if(!e){if(this.async&&"function"!==typeof importScripts){let e=this;g=new Promise(function(c){setTimeout(function(){e.add(b,a,null,d,!0);e=null;c()})});if(c)g.then(c);else return g;return this}if(c)return this.add(b,a,null,d,!0),c(),this}a=this.encode(a);if(!a.length)return this;c=this.a;e=B(c)?c(a):a.split(I);const k=u();k._ctx=u();const q=this.threshold,r=this.depth,t=this.g,v=e.length,p=this.h;for(let a=0;a<v;a++){var m=e[a];if(m){var f=m.length,l=
|
||||
(p?a+1:v-a)/v,n="";switch(c){case "reverse":case "both":for(var h=f;--h;)n=m[h]+n,z(t,k,n,b,p?1:(f-h)/f,l,q);n="";case "forward":for(h=0;h<f;h++)n+=m[h],z(t,k,n,b,p?(h+1)/f:1,l,q);break;case "full":for(h=0;h<f;h++){const a=(p?h+1:f-h)/f;for(let c=f;c>h;c--)n=m.substring(h,c),z(t,k,n,b,a,l,q)}break;default:if(f=z(t,k,m,b,1,l,q),r&&1<v&&f>=q)for(f=k._ctx[m]||(k._ctx[m]=u()),m=this.c[m]||(this.c[m]=G(10-(q||0))),l=a-r,n=a+r+1,0>l&&(l=0),n>v&&(n=v);l<n;l++)l!==a&&z(m,f,e[l],b,0,10-(l<a?a-l:l-a),q)}}}this.b[g]=
|
||||
1}return this};f.prototype.update=function(b,a,c){this.b["@"+b]&&A(a)&&(this.remove(b),this.add(b,a,c,!0));return this};f.prototype.remove=function(b,a,c){var d="@"+b;if(this.b[d]){if(!c){if(this.async&&"function"!==typeof importScripts){let c=this;d=new Promise(function(a){setTimeout(function(){c.remove(b,null,!0);c=null;a()})});if(a)d.then(a);else return d;return this}if(a)return this.remove(b,null,!0),a(),this}for(a=0;a<10-(this.threshold||0);a++)C(this.g[a],b);this.depth&&C(this.c,b);delete this.b[d]}return this};
|
||||
f.prototype.search=function(b,a,c,d){let e=b;let f=[];if("object"===typeof b){(c=b.callback||a)&&(e.callback=null);a=b.limit;var g=b.threshold;b=b.query}g||(g=this.threshold||0);B(a)?(c=a,a=1E3):a||0===a||(a=1E3);if(!d){if(this.async&&"function"!==typeof importScripts){let b=this;g=new Promise(function(c){setTimeout(function(){c(b.search(e,a,null,!0));b=null})});if(c)g.then(c);else return g;return this}if(c)return c(this.search(e,a,null,!0)),this}if(!b||!A(b))return f;e=b;e=this.encode(e);if(!e.length)return f;
|
||||
c=this.a;c=B(c)?c(e):e.split(I);b=c.length;d=!0;const k=[],l=u();let n;if(1<b)if(this.depth){n=!0;var h=c[0];l[h]=1}else c.sort(M);let p;if(!n||(p=this.c)[h])for(let a=n?1:0;a<b;a++){const b=c[a];if(b){if(!l[b]){const a=[];let c=!1,e=0;if(h=n?p[h]:this.g){let d;for(let f=0;f<10-g;f++)if(d=h[f][b])a[e++]=d,c=!0}if(c)k[k.length]=1<e?a.concat.apply([],a):a[0];else{d=!1;break}l[b]=1}h=b}}else d=!1;d&&(f=O(k,a,!1));return f};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(b){return b.toLowerCase()},simple:function(){const b=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(a){a=
|
||||
k(a.toLowerCase(),b);return" "===a?"":a}}(),advanced:function(){const b=[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(a,c){if(!a)return a;a=this.simple(a);2<a.length&&(a=k(a,b));c||1<a.length&&(a=D(a));return a}}(),extra:function(){const b=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),
|
||||
""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(let c=0;c<a.length;c++){const d=a[c];1<d.length&&(a[c]=d[0]+k(d.substring(1),b))}a=a.join(" ");a=D(a)}return a}}(),balance:function(){const b=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(a){return D(k(a.toLowerCase(),b))}}()};return f}(!1),this);
|
||||
'use strict';(function(f,x,d){let p;(p=d.define)&&p.amd?p([],function(){return x}):(p=d.modules)?p[f.toLowerCase()]=x:"object"===typeof exports?module.exports=x:d[f]=x})("FlexSearch",function(){function f(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:M++;this.init(a,b);x(this,"index",function(){return this.c});x(this,"length",function(){return Object.keys(this.c).length})}function x(a,b,c){Object.defineProperty(a,b,{get:c})}function d(a){return new RegExp(a,"g")}function p(a,b){for(let c=0;c<b.length;c+=
|
||||
2)a=a.replace(b[c],b[c+1]);return a}function A(a,b,c,h,g,l,e){if(b[c])return b[c];g=g?(9-(e||6))*l+(e||6)*g:l;b[c]=g;g>=e&&(a=a[9-(g+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=h);return g}function E(a,b){if(a){const c=Object.keys(a);for(let h=0,g=c.length;h<g;h++){const g=c[h],e=a[g];if(e)for(let c=0,h=e.length;c<h;c++)if(e[c]===b){1===h?delete a[g]:e.splice(c,1);break}else y(e[c])&&E(e[c],b)}}}function F(a){let b="",c="";var h="";for(let g=0;g<a.length;g++){const l=a[g];if(l!==c)if(g&&"h"===l){if(h="a"===
|
||||
h||"e"===h||"i"===h||"o"===h||"u"===h||"y"===h,("a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c)&&h||" "===c)b+=l}else b+=l;h=g===a.length-1?"":a[g+1];c=l}return b}function N(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function O(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function P(a,b,c,h){let g=[],l;const e=a.length;if(1<e){a.sort(O);const n=v();let q=a[0],k=q.length,r=0;for(;r<k;)n["@"+q[r++]]=1;let m,f=0,t=0;for(;++t<e;){let w=!1;const p=t===e-1;l=[];q=a[t];k=q.length;for(r=0;r<k;){m=
|
||||
q[r++];var d="@"+m;if(n[d]){const a=n[d];if(a===t){if(p){if(g[f++]=c?c[d]:m,b&&f===b)return g}else n[d]=t+1;w=!0}else h&&(d=l[a]||(l[a]=[]),d[d.length]=m)}}if(!w&&!h)break}if(h&&(f=g.length,(t=l.length)&&(!b||f<b)))for(;t--;)if(m=l[t])for(r=0,k=m.length;r<k;r++)if(g[f++]=c?c["@"+m[r]]:m[r],b&&f===b)return g}else if(e)if(c)for(a=a[0],h=a.length,b&&b<h&&(h=b),g=Array(h),b=0;b<h;b++)g[b]=c["@"+a[b]];else g=a[0],b&&g.length>b&&(g=g.slice(0,b));return g}function B(a){return"string"===typeof a}function C(a){return"function"===
|
||||
typeof a}function y(a){return"object"===typeof a}function D(a){return"undefined"===typeof a}function H(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=v();return b}function v(){return Object.create(null)}const u={encode:"icase",b:"forward",o:!1,cache:!1,async:!1,s:!1,l:!1,threshold:0,depth:0,a:!1},I={memory:{encode:"extra",b:"strict",threshold:7},speed:{encode:"icase",b:"strict",threshold:7,depth:2},match:{encode:"extra",b:"full"},score:{encode:"extra",b:"strict",threshold:5,depth:4},balance:{encode:"balance",
|
||||
b:"strict",threshold:6,depth:3},fastest:{encode:"icase",b:"strict",threshold:9,depth:1}},G=[];let M=0;const J=d("\\W+"),K={},L={};f.create=function(a){return new f(a)};f.registerMatcher=function(a){for(const b in a)a.hasOwnProperty(b)&&G.push(d(b),a[b]);return this};f.registerEncoder=function(a,b){z[a]=b.bind(z);return this};f.registerLanguage=function(a,b){K[a]=b.filter;L[a]=b.stemmer;return this};f.encode=function(a,b){return z[a](b)};f.prototype.init=function(a,b){this.m=[];if(b){var c=b.preset;
|
||||
a=b}else a||(a=u),c=a.preset;b={};B(a)?(b=I[a],a={}):c&&(b=I[c]);this.b=a.tokenize||b.b||this.b||u.b;this.l=a.rtl||this.l||u.l;this.async="undefined"===typeof Promise||D(c=a.async)?this.async||u.async:c;this.threshold=D(c=a.threshold)?b.threshold||this.threshold||u.threshold:c;this.depth=D(c=a.depth)?b.depth||this.depth||u.depth:c;this.h=(c=D(c=a.encode)?b.encode||u.encode:c)&&z[c]&&z[c].bind(z)||(C(c)?c:this.h||!1);(c=a.matcher)&&this.addMatcher(c);if(c=a.filter){c=K[c]||c;b=this.h;var h=v();if(c)for(var g=
|
||||
0;g<c.length;g++){var l=b?b(c[g]):c[g];h[l]=String.fromCharCode(65E3-c.length+g)}this.filter=c=h}if(c=a.stemmer){var e;b=L[c]||c;h=this.h;g=[];if(b)for(e in b)b.hasOwnProperty(e)&&(l=h?h(e):e,g.push(d("(?=.{"+(l.length+3)+",})"+l+"$"),h?h(b[e]):b[e]));this.stemmer=e=g}this.a=e=(c=a.doc)?c:this.a||u.a;this.j=H(10-(this.threshold||0));this.g=v();this.c=v();this.f=e&&v();if(e)if(a.doc=null,c=e.field,b=e.index=[],h=e.ref={},e.id=e.id.split(":"),c.constructor===Array)for(e=0;e<c.length;e++)h[c[e]]=e,c[e]=
|
||||
c[e].split(":"),b[e]=new f(a),b[e].f=this.f;else h[c]=0,e.field=[c.split(":")],b[0]=new f(a),b[0].f=this.f;return this};f.prototype.encode=function(a){a&&G.length&&(a=p(a,G));a&&this.m.length&&(a=p(a,this.m));a&&this.h&&(a=this.h(a));a&&this.stemmer&&(a=p(a,this.stemmer));return a};f.prototype.addMatcher=function(a){const b=this.m;for(const c in a)a.hasOwnProperty(c)&&b.push(d(c),a[c]);return this};f.prototype.add=function(a,b,c,h,g){if(this.a&&y(a))return this.i("add",a,b);if(b&&B(b)&&(a||0===a)){var l=
|
||||
"@"+a;if(this.c[l]&&!h)return this.update(a,b);if(!g){if(this.async&&"function"!==typeof importScripts){let e=this;l=new Promise(function(c){setTimeout(function(){e.add(a,b,null,h,!0);e=null;c()})});if(c)l.then(c);else return l;return this}if(c)return this.add(a,b,null,h,!0),c(),this}b=this.encode(b);if(!b.length)return this;c=this.b;g=C(c)?c(b):b.split(J);const q=v();q._ctx=v();const m=this.threshold,p=this.depth,t=this.j,w=g.length,u=this.l;for(let b=0;b<w;b++){var e=g[b];if(e){var d=e.length,n=
|
||||
(u?b+1:w-b)/w,f="";switch(c){case "reverse":case "both":for(var k=d;--k;)f=e[k]+f,A(t,q,f,a,u?1:(d-k)/d,n,m);f="";case "forward":for(k=0;k<d;k++)f+=e[k],A(t,q,f,a,u?(k+1)/d:1,n,m);break;case "full":for(k=0;k<d;k++){const b=(u?k+1:d-k)/d;for(let c=d;c>k;c--)f=e.substring(k,c),A(t,q,f,a,b,n,m)}break;default:if(d=A(t,q,e,a,1,n,m),p&&1<w&&d>=m)for(d=q._ctx[e]||(q._ctx[e]=v()),e=this.g[e]||(this.g[e]=H(10-(m||0))),n=b-p,f=b+p+1,0>n&&(n=0),f>w&&(f=w);n<f;n++)n!==b&&A(e,d,g[n],a,0,10-(n<b?b-n:n-b),m)}}}this.c[l]=
|
||||
1}return this};f.prototype.i=function(a,b,c){if(b.constructor===Array)for(let d=0,e=b.length;d<e;d++){if(d===e-1)return this.i(a,b[d],c);this.i(a,b[d])}else{const h=this.a.index;let e=this.a.id,f;for(var d=0;d<e.length;d++)f=(f||b)[e[d]];if("remove"===a){delete this.f["@"+f];for(let a=0,b=h.length;a<b;a++){if(a===b-1)return h[a].remove(f,c);h[a].remove(f)}}e=this.a.field;for(let l=0,q=e.length;l<q;l++){d=e[l];let k;for(var g=0;g<d.length;g++)k=(k||b)[d[g]];this.f["@"+f]=b;d=h[l];g="add"===a?d.add:
|
||||
d.update;if(l===q-1)return g.call(d,f,k,c);g.call(d,f,k)}}};f.prototype.update=function(a,b,c){if(this.a&&y(a))return this.i("update",a,b);this.c["@"+a]&&B(b)&&(this.remove(a),this.add(a,b,c,!0));return this};f.prototype.remove=function(a,b,c){if(this.a&&y(a))return this.i("remove",a,b);var d="@"+a;if(this.c[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<10-(this.threshold||0);b++)E(this.j[b],a);this.depth&&E(this.g,a);delete this.c[d]}return this};f.prototype.search=function(a,b,c,d){if(y(b)){if(b.constructor===Array)for(var g=0;g<b.length;g++)b[g].query=a;else b.query=a;a=b;b=0}let f=a;let e=[];if(y(a)&&a.constructor!==Array){(c=a.callback||b)&&(f.callback=null);b=a.limit;var h=a.threshold;var n=a.boost;a=a.query}if(this.a){h=this.a.ref;var p=this.a.index,k=f.field;if(k)f.field=null;else if(f.constructor===Array){var r=
|
||||
f;k=[];for(var m=0;m<f.length;m++)k[m]=f[m].field}else k=Object.keys(h);if(y(k)){k.constructor===Array||(k=[k]);m=k.length;for(a=0;a<m;a++)r&&(f=r[a]),e[a]=p[h[k[a]]].search(f);return c?c(e.concat.apply([],e)):this.async?new Promise(function(a){Promise.all(e).then(function(b){a(b.concat.apply([],b))})}):e.concat.apply([],e)}return p[h[k]].search(f,c)}h||(h=this.threshold||0);C(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(!d){if(this.async&&"function"!==typeof importScripts){let a=this;h=new Promise(function(c){setTimeout(function(){c(a.search(f,
|
||||
b,null,!0));a=null})});if(c)h.then(c);else return h;return this}if(c)return c(this.search(f,b,null,!0)),this}if(!a||!B(a))return e;f=a;f=this.encode(f);if(!f.length)return e;c=this.b;c=C(c)?c(f):f.split(J);r=c.length;a=!0;d=[];g=v();1<r&&(this.depth?(p=!0,m=c[0],g[m]=1):c.sort(N));if(!p||(k=this.g)[m]){let b=0;n&&(h=(h||1)/n,0>n&&(b=h));for(n=p?1:0;n<r;n++){const e=c[n];if(e){if(!g[e]){const c=[];let f=!1,l=0;if(m=p?k[m]:this.j){let a;for(let d=b;d<10-h;d++)if(a=m[d][e])c[l++]=a,f=!0}if(f)d[d.length]=
|
||||
1<l?c.concat.apply([],c):c[0];else{a=!1;break}g[e]=1}m=e}}}else a=!1;a&&(e=P(d,b,this.f,!1));return e};f.prototype.clear=function(){return this.destroy().init()};f.prototype.destroy=function(){this.j=this.g=this.c=null;return this};const z={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(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(b){b=p(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=p(b,a));c||1<b.length&&(b=F(b));return b}}(),extra:function(){const a=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(let c=0;c<b.length;c++){const d=b[c];1<d.length&&(b[c]=d[0]+p(d.substring(1),a))}b=b.join(" ");b=F(b)}return b}}(),balance:function(){const a=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(b){return F(p(b.toLowerCase(),
|
||||
a))}}()};return f}(!1),this);
|
||||
|
66
dist/flexsearch.es5.js
vendored
66
dist/flexsearch.es5.js
vendored
@@ -1,37 +1,41 @@
|
||||
/*
|
||||
FlexSearch v0.3.62
|
||||
FlexSearch v0.4.0
|
||||
Copyright 2019 Nextapps GmbH
|
||||
Author: Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';function K(g){var k=0;return function(){return k<g.length?{done:!1,value:g[k++]}:{done:!0}}}function L(g){var k="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return k?k.call(g):{next:K(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,k,e){g!=Array.prototype&&g!=Object.prototype&&(g[k]=e.value)};
|
||||
function T(g,k){if(k){var e=R;g=g.split(".");for(var h=0;h<g.length-1;h++){var l=g[h];l in e||(e[l]={});e=e[l]}g=g[g.length-1];h=e[g];k=k(h);k!=h&&null!=k&&S(e,g,{configurable:!0,writable:!0,value:k})}}
|
||||
T("Promise",function(g){function k(d){this.b=0;this.i=void 0;this.a=[];var c=this.c();try{d(c.resolve,c.reject)}catch(D){c.reject(D)}}function e(){this.a=null}function h(d){return d instanceof k?d:new k(function(c){c(d)})}if(g)return g;e.prototype.b=function(d){if(null==this.a){this.a=[];var c=this;this.c(function(){c.i()})}this.a.push(d)};var l=R.setTimeout;e.prototype.c=function(d){l(d,0)};e.prototype.i=function(){for(;this.a&&this.a.length;){var d=this.a;this.a=[];for(var c=0;c<d.length;++c){var e=
|
||||
d[c];d[c]=null;try{e()}catch(E){this.f(E)}}}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(c,k))}}var c=this,e=!1;return{resolve:d(this.G),reject:d(this.f)}};k.prototype.G=function(d){if(d===this)this.f(new TypeError("A Promise cannot resolve to itself"));else if(d instanceof k)this.H(d);else{a:switch(typeof d){case "object":var c=null!=d;break a;case "function":c=!0;break a;default:c=!1}c?this.F(d):this.j(d)}};
|
||||
k.prototype.F=function(d){var c=void 0;try{c=d.then}catch(D){this.f(D);return}"function"==typeof c?this.I(c,d):this.j(d)};k.prototype.f=function(c){this.m(2,c)};k.prototype.j=function(c){this.m(1,c)};k.prototype.m=function(c,e){if(0!=this.b)throw Error("Cannot settle("+c+", "+e+"): Promise already settled in state"+this.b);this.b=c;this.i=e;this.u()};k.prototype.u=function(){if(null!=this.a){for(var d=0;d<this.a.length;++d)c.b(this.a[d]);this.a=null}};var c=new e;k.prototype.H=function(c){var d=this.c();
|
||||
c.A(d.resolve,d.reject)};k.prototype.I=function(c,e){var d=this.c();try{c.call(e,d.resolve,d.reject)}catch(E){d.reject(E)}};k.prototype.then=function(c,e){function d(c,d){return"function"==typeof c?function(d){try{g(c(d))}catch(t){h(t)}}:d}var g,h,A=new k(function(c,d){g=c;h=d});this.A(d(c,g),d(e,h));return A};k.prototype.catch=function(c){return this.then(void 0,c)};k.prototype.A=function(d,e){function k(){switch(g.b){case 1:d(g.i);break;case 2:e(g.i);break;default:throw Error("Unexpected state: "+
|
||||
g.b);}}var g=this;null==this.a?c.b(k):this.a.push(k)};k.resolve=h;k.reject=function(c){return new k(function(d,e){e(c)})};k.race=function(c){return new k(function(d,e){for(var k=L(c),g=k.next();!g.done;g=k.next())h(g.value).A(d,e)})};k.all=function(c){var d=L(c),e=d.next();return e.done?h([]):new k(function(c,k){function g(d){return function(e){l[d]=e;C--;0==C&&c(l)}}var l=[],C=0;do l.push(void 0),C++,h(e.value).A(g(l.length-1),k),e=d.next();while(!e.done)})};return k});
|
||||
(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){this.id=b&&!t(b.id)?b.id:Y++;this.init(b);l(this,"index",function(){return this.a});l(this,"length",function(){return Object.keys(this.a).length})}function h(b,a,f,c){this.v!==this.h&&(this.l=this.l.concat(f),this.v++,c&&this.l.length>=c&&(this.v=this.h),this.C&&this.v===this.h&&(this.cache&&this.o.set(a,
|
||||
this.l),this.C(this.l),this.l=[]));return this}function l(b,a,f){Object.defineProperty(b,a,{get:f})}function c(b){return new RegExp(b,"g")}function d(b,a){for(var f=0;f<a.length;f+=2)b=b.replace(a[f],a[f+1]);return b}function A(b,a,f,c,d,e,g){if(a[f])return a[f];d=d?(9-(g||6))*e+(g||6)*d:e;a[f]=d;d>=g&&(b=b[9-(d+.5>>0)],b=b[f]||(b[f]=[]),b[b.length]=c);return d}function D(b,a){if(b)for(var f=Object.keys(b),c=0,d=f.length;c<d;c++){var e=f[c],g=b[e];if(g)for(var y=0,h=g.length;y<h;y++)if(g[y]===a){1===
|
||||
h?delete b[e]:g.splice(y,1);break}else"object"===typeof g[y]&&D(g[y],a)}}function E(b){for(var a="",f="",c="",d=0;d<b.length;d++){var e=b[d];if(e!==f)if(d&&"h"===e){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f)&&c||" "===f)a+=e}else a+=e;c=d===b.length-1?"":b[d+1];f=e}return a}function U(b,a){b=b.length-a.length;return 0>b?1:b?-1:0}function W(b,a){b=b.length-a.length;return 0>b?-1:b?1:0}function V(b,a,f){var c=[],d=b.length;if(1<d){b.sort(W);
|
||||
for(var e=z(),g=b[0],y=g.length,h=0;h<y;)e["@"+g[h++]]=1;for(var l,F=0,q=0;++q<d;){var x=!1,u=q===d-1;var p=[];g=b[q];y=g.length;for(h=0;h<y;){l=g[h++];var m="@"+l;if(e[m]){var n=e[m];if(n===q){if(u){if(c[F++]=l,a&&F===a)return c}else e[m]=q+1;x=!0}else f&&(m=p[n]||(p[n]=[]),m[m.length]=l)}}if(!x&&!f)break}if(f&&(F=c.length,(q=p.length)&&(!a||F<a)))for(;q--;)if(l=p[q])for(h=0,y=l.length;h<y;h++)if(c[F++]=l[h],a&&F===a)return c}else d&&(c=b[0],a&&c.length>a&&(c=c.slice(0,a)));return c}function C(b){return"string"===
|
||||
typeof b}function H(b){return"function"===typeof b}function t(b){return"undefined"===typeof b}function M(b){for(var a=Array(b),f=0;f<b;f++)a[f]=z();return a}function z(){return Object.create(null)}function Z(){var b,a;self.onmessage=function(f){if(f=f.data)if(f.search){var c=a.search(f.content,f.threshold?{limit:f.limit,threshold:f.threshold}:f.limit);self.postMessage({id:b,content:f.content,limit:f.limit,result:c})}else f.add?a.add(f.id,f.content):f.update?a.update(f.id,f.content):f.remove?a.remove(f.id):
|
||||
f.clear?a.clear():f.info?(f=a.info(),f.worker=b,console.log(f)):f.register&&(b=f.id,f.options.cache=!1,f.options.async=!1,f.options.worker=!1,a=(new Function(f.register.substring(f.register.indexOf("{")+1,f.register.lastIndexOf("}"))))(),a=new a(f.options))}}function aa(b,a,f,c){b=g("flexsearch","id"+b,Z,function(a){(a=a.data)&&a.result&&c(a.id,a.content,a.result,a.limit)},a);var d=X.toString();f.id=a;b.postMessage({register:d,options:f,id:a});return b}var v={encode:"icase",g:"forward",w:!1,cache:!1,
|
||||
async:!1,h:!1,B:!1,threshold:0,depth:0},N={memory:{encode:"extra",g:"strict",threshold:7},speed:{encode:"icase",g:"strict",threshold:7,depth:2},match:{encode:"extra",g:"full"},score:{encode:"extra",g:"strict",threshold:5,depth:4},balance:{encode:"balance",g:"strict",threshold:6,depth:3},fastest:{encode:"icase",g:"strict",threshold:9,depth:1}},J=[],Y=0,O=c("\\W+"),P={},Q={};e.create=function(b){return new e(b)};e.registerMatcher=function(b){for(var a in b)b.hasOwnProperty(a)&&J.push(c(a),b[a]);return this};
|
||||
e.registerEncoder=function(b,a){G[b]=a.bind(G);return this};e.registerLanguage=function(b,a){P[b]=a.filter;Q[b]=a.stemmer;return this};e.encode=function(b,a){return G[b](a)};e.prototype.init=function(b){this.i=[];b||(b=v);var a=b.preset,f={};C(b)?((f=N[b])||console.warn("Preset not found: "+b),b={}):a&&((f=N[a])||console.warn("Preset not found: "+a));if(a=b.worker)if("undefined"===typeof Worker)b.worker=!1,this.f=null;else{var d=parseInt(a,10)||4;this.u=-1;this.v=0;this.l=[];this.C=null;this.f=Array(d);
|
||||
for(var e=0;e<d;e++)this.f[e]=aa(this.id,e,b,h.bind(this))}this.g=b.tokenize||f.g||this.g||v.g;this.B=b.rtl||this.B||v.B;this.async="undefined"===typeof Promise||t(a=b.async)?this.async||v.async:a;this.h=t(a=b.worker)?this.h||v.h:a;this.threshold=t(a=b.threshold)?f.threshold||this.threshold||v.threshold:a;this.depth=t(a=b.depth)?f.depth||this.depth||v.depth:a;this.w=t(a=b.suggest)?this.w||v.w:a;this.j=(a=t(a=b.encode)?f.encode:a)&&G[a]&&G[a].bind(G)||(H(a)?a:this.j||!1);(a=b.matcher)&&this.addMatcher(a);
|
||||
if(a=b.filter){a=P[a]||a;f=this.j;d=z();if(a)for(e=0;e<a.length;e++){var g=f?f(a[e]):a[e];d[g]=String.fromCharCode(65E3-a.length+e)}this.filter=d}if(a=b.stemmer){f=Q[a]||a;d=this.j;e=[];if(f)for(var l in f)f.hasOwnProperty(l)&&(g=d?d(l):l,e.push(c("(?=.{"+(g.length+3)+",})"+g+"$"),d?d(f[l]):f[l]));this.stemmer=e}this.b=M(10-(this.threshold||0));this.c=z();this.a=z();this.m=!0;this.o=(this.cache=a=t(a=b.cache)?this.cache||v.cache:a)?new ba(a):!1;return this};e.prototype.encode=function(b){b&&J.length&&
|
||||
(b=d(b,J));b&&this.i.length&&(b=d(b,this.i));b&&this.j&&(b=this.j(b));b&&this.stemmer&&(b=d(b,this.stemmer));return b};e.prototype.addMatcher=function(b){var a=this.i,f;for(f in b)b.hasOwnProperty(f)&&a.push(c(f),b[f]);return this};e.prototype.add=function(b,a,f,c,d){if(a&&C(a)&&(b||0===b)){var e="@"+b;if(this.a[e]&&!c)return this.update(b,a);if(this.h)return++this.u>=this.f.length&&(this.u=0),this.f[this.u].postMessage({add:!0,id:b,content:a}),this.a[e]=""+this.u,f&&f(),this;if(!d){if(this.async&&
|
||||
"function"!==typeof importScripts){var g=this;e=new Promise(function(f){setTimeout(function(){g.add(b,a,null,c,!0);g=null;f()})});if(f)e.then(f);else return e;return this}if(f)return this.add(b,a,null,c,!0),f(),this}a=this.encode(a);if(!a.length)return this;f=this.g;d=H(f)?f(a):a.split(O);var h=z();h._ctx=z();for(var B=this.threshold,l=this.depth,I=this.b,q=d.length,x=this.B,u=0;u<q;u++){var p=d[u];if(p){var m=p.length,n=(x?u+1:q-u)/q,w="";switch(f){case "reverse":case "both":for(var r=m;--r;)w=p[r]+
|
||||
w,A(I,h,w,b,x?1:(m-r)/m,n,B);w="";case "forward":for(r=0;r<m;r++)w+=p[r],A(I,h,w,b,x?(r+1)/m:1,n,B);break;case "full":for(r=0;r<m;r++)for(var t=(x?r+1:m-r)/m,v=m;v>r;v--)w=p.substring(r,v),A(I,h,w,b,t,n,B);break;default:if(m=A(I,h,p,b,1,n,B),l&&1<q&&m>=B)for(m=h._ctx[p]||(h._ctx[p]=z()),p=this.c[p]||(this.c[p]=M(10-(B||0))),n=u-l,w=u+l+1,0>n&&(n=0),w>q&&(w=q);n<w;n++)n!==u&&A(p,m,d[n],b,0,10-(n<u?u-n:n-u),B)}}}this.a[e]=1;this.m=!1}return this};e.prototype.update=function(b,a,f){this.a["@"+b]&&C(a)&&
|
||||
(this.remove(b),this.add(b,a,f,!0));return this};e.prototype.remove=function(b,a,f){var c="@"+b;if(this.a[c]){if(this.h)return this.f[this.a[c]].postMessage({remove:!0,id:b}),delete this.a[c],a&&a(),this;if(!f){if(this.async&&"function"!==typeof importScripts){var d=this;c=new Promise(function(a){setTimeout(function(){d.remove(b,null,!0);d=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++)D(this.b[a],b);this.depth&&
|
||||
D(this.c,b);delete this.a[c];this.m=!1}return this};e.prototype.search=function(b,a,c,d){var f=b,e=[];if("object"===typeof b){(c=b.callback||a)&&(f.callback=null);a=b.limit;var g=b.threshold;b=b.query}g||(g=this.threshold||0);H(a)?(c=a,a=1E3):a||0===a||(a=1E3);if(this.h)for(this.C=c,this.v=0,this.l=[],e=0;e<this.h;e++)this.f[e].postMessage({search:!0,limit:a,threshold:g,content:b});else{if(!d){if(this.async&&"function"!==typeof importScripts){var h=this;b=new Promise(function(b){setTimeout(function(){b(h.search(f,
|
||||
a,null,!0));h=null})});if(c)b.then(c);else return b;return this}if(c)return c(this.search(f,a,null,!0)),this}if(!b||!C(b))return e;f=b;if(this.cache)if(this.m){if(c=this.o.get(b))return c}else this.o.clear(),this.m=!0;f=this.encode(f);if(!f.length)return e;c=this.g;c=H(c)?c(f):f.split(O);d=c.length;var l=!0,B=[],t=z();if(1<d)if(this.depth){var q=!0;var x=c[0];t[x]=1}else c.sort(U);var u;if(!q||(u=this.c)[x])for(var p=q?1:0;p<d;p++){var m=c[p];if(m){if(!t[m]){var n=[],w=!1,r=0;if(x=q?u[x]:this.b)for(var v=
|
||||
void 0,A=0;A<10-g;A++)if(v=x[A][m])n[r++]=v,w=!0;if(w)B[B.length]=1<r?n.concat.apply([],n):n[0];else if(!this.w){l=!1;break}t[m]=1}x=m}}else l=!1;l&&(e=V(B,a,this.w));this.cache&&this.o.set(b,e);return e}};e.prototype.info=function(){if(this.h)for(var b=0;b<this.h;b++)this.f[b].postMessage({info:!0,id:this.id});else{for(var a,c=0,d=0,e=0,g=0;g<10-(this.threshold||0);g++){b=Object.keys(this.b[g]);for(var h=0;h<b.length;h++)a=this.b[g][b[h]].length,c+=1*a+2*b[h].length+4,d+=a,e+=2*b[h].length}b=Object.keys(this.a);
|
||||
a=b.length;for(g=0;g<a;g++)c+=2*b[g].length+2;return{id:this.id,memory:c,items:a,sequences:d,chars:e,cache:this.cache&&this.cache.s?this.cache.s.length:!1,matcher:J.length+(this.i?this.i.length:0),worker:this.h,threshold:this.threshold,depth:this.depth,contextual:this.depth&&"strict"===this.g}}};e.prototype.clear=function(){return this.destroy().init()};e.prototype.destroy=function(){this.cache&&(this.o.clear(),this.o=null);this.b=this.c=this.a=null;return this};e.prototype.export=function(){return JSON.stringify([this.b,
|
||||
this.c,this.a])};e.prototype.import=function(b){b=JSON.parse(b);this.b=b[0];this.c=b[1];this.a=b[2]};var G={icase:function(b){return b.toLowerCase()},simple:function(){var b=[c("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",c("[\u00e8\u00e9\u00ea\u00eb]"),"e",c("[\u00ec\u00ed\u00ee\u00ef]"),"i",c("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",c("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",c("[\u00fd\u0177\u00ff]"),"y",c("\u00f1"),"n",c("\u00e7"),"c",c("\u00df"),"s",c(" & ")," and ",c("[-/]")," ",c("[^a-z0-9 ]"),
|
||||
"",c("\\s+")," "];return function(a){a=d(a.toLowerCase(),b);return" "===a?"":a}}(),advanced:function(){var b=[c("ae"),"a",c("ai"),"ei",c("ay"),"ei",c("ey"),"ei",c("oe"),"o",c("ue"),"u",c("ie"),"i",c("sz"),"s",c("zs"),"s",c("sh"),"s",c("ck"),"k",c("cc"),"k",c("dt"),"t",c("ph"),"f",c("pf"),"f",c("ou"),"o",c("uo"),"u"];return function(a,c){if(!a)return a;a=this.simple(a);2<a.length&&(a=d(a,b));c||1<a.length&&(a=E(a));return a}}(),extra:function(){var b=[c("p"),"b",c("z"),"s",c("[cgq]"),"k",c("n"),"m",
|
||||
c("d"),"t",c("[vw]"),"f",c("[aeiouy]"),""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(var c=0;c<a.length;c++){var e=a[c];1<e.length&&(a[c]=e[0]+d(e.substring(1),b))}a=a.join(" ");a=E(a)}return a}}(),balance:function(){var b=[c("[-/]")," ",c("[^a-z0-9 ]"),"",c("\\s+")," "];return function(a){return E(d(a.toLowerCase(),b))}}()},ba=function(){function b(a){this.clear();this.D=!0!==a&&a}b.prototype.clear=function(){this.cache=z();this.count=z();this.index=
|
||||
z();this.s=[]};b.prototype.set=function(a,b){if(this.D&&t(this.cache[a])){var c=this.s.length;if(c===this.D){c--;var e=this.s[c];delete this.cache[e];delete this.count[e];delete this.index[e]}this.index[a]=c;this.s[c]=a;this.count[a]=-1;this.cache[a]=b;this.get(a)}else this.cache[a]=b};b.prototype.get=function(a){var b=this.cache[a];if(this.D&&b){var c=++this.count[a],e=this.index,d=e[a];if(0<d){for(var g=this.s,h=d;this.count[g[--d]]<=c&&-1!==d;);d++;if(d!==h){for(c=h;c>d;c--)h=g[c-1],g[c]=h,e[h]=
|
||||
c;g[d]=a;e[a]=d}}}return b};return b}();return e}(function(){var g={},k="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(e,h,l,c,d){l=k?URL.createObjectURL(new Blob(["("+l.toString()+")()"],{type:"text/javascript"})):e+".es5.js";e+="-"+h;g[e]||(g[e]=[]);g[e][d]=new Worker(l);g[e][d].onmessage=c;console.log("Register Worker: "+e+"@"+d);return g[e][d]}}()),this);
|
||||
'use strict';function L(g){var l=0;return function(){return l<g.length?{done:!1,value:g[l++]}:{done:!0}}}function M(g){var l="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return l?l.call(g):{next:L(g)}}var S="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,T="function"==typeof Object.defineProperties?Object.defineProperty:function(g,l,d){g!=Array.prototype&&g!=Object.prototype&&(g[l]=d.value)};
|
||||
function U(g,l){if(l){var d=S;g=g.split(".");for(var m=0;m<g.length-1;m++){var k=g[m];k in d||(d[k]={});d=d[k]}g=g[g.length-1];m=d[g];l=l(m);l!=m&&null!=l&&T(d,g,{configurable:!0,writable:!0,value:l})}}
|
||||
U("Promise",function(g){function l(e){this.f=0;this.o=void 0;this.a=[];var d=this.i();try{e(d.resolve,d.reject)}catch(C){d.reject(C)}}function d(){this.a=null}function m(e){return e instanceof l?e:new l(function(d){d(e)})}if(g)return g;d.prototype.f=function(e){if(null==this.a){this.a=[];var d=this;this.i(function(){d.o()})}this.a.push(e)};var k=S.setTimeout;d.prototype.i=function(e){k(e,0)};d.prototype.o=function(){for(;this.a&&this.a.length;){var e=this.a;this.a=[];for(var d=0;d<e.length;++d){var f=
|
||||
e[d];e[d]=null;try{f()}catch(G){this.l(G)}}}this.a=null};d.prototype.l=function(e){this.i(function(){throw e;})};l.prototype.i=function(){function e(e){return function(l){f||(f=!0,e.call(d,l))}}var d=this,f=!1;return{resolve:e(this.L),reject:e(this.l)}};l.prototype.L=function(e){if(e===this)this.l(new TypeError("A Promise cannot resolve to itself"));else if(e instanceof l)this.M(e);else{a:switch(typeof e){case "object":var d=null!=e;break a;case "function":d=!0;break a;default:d=!1}d?this.K(e):this.v(e)}};
|
||||
l.prototype.K=function(e){var d=void 0;try{d=e.then}catch(C){this.l(C);return}"function"==typeof d?this.N(d,e):this.v(e)};l.prototype.l=function(d){this.I(2,d)};l.prototype.v=function(d){this.I(1,d)};l.prototype.I=function(d,f){if(0!=this.f)throw Error("Cannot settle("+d+", "+f+"): Promise already settled in state"+this.f);this.f=d;this.o=f;this.J()};l.prototype.J=function(){if(null!=this.a){for(var d=0;d<this.a.length;++d)f.f(this.a[d]);this.a=null}};var f=new d;l.prototype.M=function(d){var e=this.i();
|
||||
d.D(e.resolve,e.reject)};l.prototype.N=function(d,f){var e=this.i();try{d.call(f,e.resolve,e.reject)}catch(G){e.reject(G)}};l.prototype.then=function(d,f){function e(d,e){return"function"==typeof d?function(e){try{g(d(e))}catch(E){m(E)}}:e}var g,m,D=new l(function(d,e){g=d;m=e});this.D(e(d,g),e(f,m));return D};l.prototype.catch=function(d){return this.then(void 0,d)};l.prototype.D=function(d,l){function e(){switch(g.f){case 1:d(g.o);break;case 2:l(g.o);break;default:throw Error("Unexpected state: "+
|
||||
g.f);}}var g=this;null==this.a?f.f(e):this.a.push(e)};l.resolve=m;l.reject=function(d){return new l(function(e,f){f(d)})};l.race=function(d){return new l(function(e,f){for(var l=M(d),g=l.next();!g.done;g=l.next())m(g.value).D(e,f)})};l.all=function(d){var e=M(d),f=e.next();return f.done?m([]):new l(function(d,l){function g(e){return function(f){k[e]=f;F--;0==F&&d(k)}}var k=[],F=0;do k.push(void 0),F++,m(f.value).D(g(k.length-1),l),f=e.next();while(!f.done)})};return l});
|
||||
(function(g,l,d){var m;(m=d.define)&&m.amd?m([],function(){return l}):(m=d.modules)?m[g.toLowerCase()]=l:"object"===typeof exports?module.exports=l:d[g]=l})("FlexSearch",function Y(g){function d(a,b){var c=b?b.id:a&&a.id;this.id=c||0===c?c:Z++;this.init(a,b);k(this,"index",function(){return this.b});k(this,"length",function(){return Object.keys(this.b).length})}function m(a,b,c,d){this.B!==this.h&&(this.u=this.u.concat(c),this.B++,d&&this.u.length>=d&&(this.B=this.h),this.G&&this.B===this.h&&(this.cache&&
|
||||
this.w.set(b,this.u),this.G(this.u),this.u=[]));return this}function k(a,b,c){Object.defineProperty(a,b,{get:c})}function f(a){return new RegExp(a,"g")}function e(a,b){for(var c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}function D(a,b,c,d,h,u,e){if(b[c])return b[c];h=h?(9-(e||6))*u+(e||6)*h:u;b[c]=h;h>=e&&(a=a[9-(h+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=d);return h}function C(a,b){if(a)for(var c=Object.keys(a),d=0,h=c.length;d<h;d++){var u=c[d],e=a[u];if(e)for(var f=0,g=e.length;f<g;f++)if(e[f]===
|
||||
b){1===g?delete a[u]:e.splice(f,1);break}else E(e[f])&&C(e[f],b)}}function G(a){for(var b="",c="",d="",h=0;h<a.length;h++){var u=a[h];if(u!==c)if(h&&"h"===u){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+=u}else b+=u;d=h===a.length-1?"":a[h+1];c=u}return b}function V(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function X(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function W(a,b,c,d){var h=[],u=a.length;if(1<u){a.sort(X);
|
||||
for(var e=B(),f=a[0],r=f.length,g=0;g<r;)e["@"+f[g++]]=1;for(var p,m=0,q=0;++q<u;){var k=!1,x=q===u-1;var v=[];f=a[q];r=f.length;for(g=0;g<r;){p=f[g++];var n="@"+p;if(e[n]){var w=e[n];if(w===q){if(x){if(h[m++]=c?c[n]:p,b&&m===b)return h}else e[n]=q+1;k=!0}else d&&(n=v[w]||(v[w]=[]),n[n.length]=p)}}if(!k&&!d)break}if(d&&(m=h.length,(q=v.length)&&(!b||m<b)))for(;q--;)if(p=v[q])for(g=0,r=p.length;g<r;g++)if(h[m++]=c?c["@"+p[g]]:p[g],b&&m===b)return h}else if(u)if(c)for(a=a[0],d=a.length,b&&b<d&&(d=b),
|
||||
h=Array(d),b=0;b<d;b++)h[b]=c["@"+a[b]];else h=a[0],b&&h.length>b&&(h=h.slice(0,b));return h}function F(a){return"string"===typeof a}function I(a){return"function"===typeof a}function E(a){return"object"===typeof a}function z(a){return"undefined"===typeof a}function N(a){for(var b=Array(a),c=0;c<a;c++)b[c]=B();return b}function B(){return Object.create(null)}function aa(){var a,b;self.onmessage=function(c){if(c=c.data)if(c.search){var d=b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:
|
||||
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 ba(a,b,c,d){a=g("flexsearch","id"+a,aa,function(a){(a=a.data)&&a.result&&
|
||||
d(a.id,a.content,a.result,a.limit)},b);var h=Y.toString();c.id=b;a.postMessage({register:h,options:c,id:b});return a}var t={encode:"icase",g:"forward",C:!1,cache:!1,async:!1,h:!1,F:!1,threshold:0,depth:0,c:!1},O={memory:{encode:"extra",g:"strict",threshold:7},speed:{encode:"icase",g:"strict",threshold:7,depth:2},match:{encode:"extra",g:"full"},score:{encode:"extra",g:"strict",threshold:5,depth:4},balance:{encode:"balance",g:"strict",threshold:6,depth:3},fastest:{encode:"icase",g:"strict",threshold:9,
|
||||
depth:1}},K=[],Z=0,P=f("\\W+"),Q={},R={};d.create=function(a){return new d(a)};d.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&K.push(f(b),a[b]);return this};d.registerEncoder=function(a,b){H[a]=b.bind(H);return this};d.registerLanguage=function(a,b){Q[a]=b.filter;R[a]=b.stemmer;return this};d.encode=function(a,b){return H[a](b)};d.prototype.init=function(a,b){this.f=[];if(b){var c=b.preset;a=b}else a||(a=t),c=a.preset;b={};F(a)?((b=O[a])||console.warn("Preset not found: "+a),a=
|
||||
{}):c&&((b=O[c])||console.warn("Preset not found: "+c));if(c=a.worker)if("undefined"===typeof Worker)a.worker=!1,this.a=null;else{var e=parseInt(c,10)||4;this.v=-1;this.B=0;this.u=[];this.G=null;this.a=Array(e);for(var h=0;h<e;h++)this.a[h]=ba(this.id,h,a,m.bind(this))}this.g=a.tokenize||b.g||this.g||t.g;this.F=a.rtl||this.F||t.F;this.async="undefined"===typeof Promise||z(c=a.async)?this.async||t.async:c;this.h=z(c=a.worker)?this.h||t.h:c;this.threshold=z(c=a.threshold)?b.threshold||this.threshold||
|
||||
t.threshold:c;this.depth=z(c=a.depth)?b.depth||this.depth||t.depth:c;this.C=z(c=a.suggest)?this.C||t.C:c;this.i=(c=z(c=a.encode)?b.encode||t.encode:c)&&H[c]&&H[c].bind(H)||(I(c)?c:this.i||!1);(c=a.matcher)&&this.addMatcher(c);if(c=a.filter){c=Q[c]||c;b=this.i;e=B();if(c)for(h=0;h<c.length;h++){var u=b?b(c[h]):c[h];e[u]=String.fromCharCode(65E3-c.length+h)}this.filter=e}if(c=a.stemmer){b=R[c]||c;e=this.i;h=[];if(b)for(var g in b)b.hasOwnProperty(g)&&(u=e?e(g):g,h.push(f("(?=.{"+(u.length+3)+",})"+
|
||||
u+"$"),e?e(b[g]):b[g]));this.stemmer=h}this.c=h=(c=a.doc)?c:this.c||t.c;this.m=N(10-(this.threshold||0));this.s=B();this.b=B();this.j=h&&B();if(h)if(a.doc=null,g=h.field,b=h.index=[],e=h.ref={},h.id=h.id.split(":"),g.constructor===Array)for(h=0;h<g.length;h++)e[g[h]]=h,g[h]=g[h].split(":"),b[h]=new d(a),b[h].j=this.j;else e[g]=0,h.field=[g.split(":")],b[0]=new d(a),b[0].j=this.j;this.o=!0;this.w=(this.cache=c=z(c=a.cache)?this.cache||t.cache:c)?new ca(c):!1;return this};d.prototype.encode=function(a){a&&
|
||||
K.length&&(a=e(a,K));a&&this.f.length&&(a=e(a,this.f));a&&this.i&&(a=this.i(a));a&&this.stemmer&&(a=e(a,this.stemmer));return a};d.prototype.addMatcher=function(a){var b=this.f,c;for(c in a)a.hasOwnProperty(c)&&b.push(f(c),a[c]);return this};d.prototype.add=function(a,b,c,d,h){if(this.c&&E(a))return this.l("add",a,b);if(b&&F(b)&&(a||0===a)){var e="@"+a;if(this.b[e]&&!d)return this.update(a,b);if(this.h)return++this.v>=this.a.length&&(this.v=0),this.a[this.v].postMessage({add:!0,id:a,content:b}),this.b[e]=
|
||||
""+this.v,c&&c(),this;if(!h){if(this.async&&"function"!==typeof importScripts){var 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.g;h=I(c)?c(b):b.split(P);var g=B();g._ctx=B();for(var r=this.threshold,m=this.depth,p=this.m,k=h.length,q=this.F,A=0;A<k;A++){var x=h[A];if(x){var v=x.length,n=(q?A+1:k-A)/k,w="";switch(c){case "reverse":case "both":for(var y=
|
||||
v;--y;)w=x[y]+w,D(p,g,w,a,q?1:(v-y)/v,n,r);w="";case "forward":for(y=0;y<v;y++)w+=x[y],D(p,g,w,a,q?(y+1)/v:1,n,r);break;case "full":for(y=0;y<v;y++)for(var t=(q?y+1:v-y)/v,z=v;z>y;z--)w=x.substring(y,z),D(p,g,w,a,t,n,r);break;default:if(v=D(p,g,x,a,1,n,r),m&&1<k&&v>=r)for(v=g._ctx[x]||(g._ctx[x]=B()),x=this.s[x]||(this.s[x]=N(10-(r||0))),n=A-m,w=A+m+1,0>n&&(n=0),w>k&&(w=k);n<w;n++)n!==A&&D(x,v,h[n],a,0,10-(n<A?A-n:n-A),r)}}}this.b[e]=1;this.o=!1}return this};d.prototype.l=function(a,b,c){if(b.constructor===
|
||||
Array)for(var d=0,e=b.length;d<e;d++){if(d===e-1)return this.l(a,b[d],c);this.l(a,b[d])}else{d=this.c.index;for(var f=this.c.id,g=0;g<f.length;g++)e=(e||b)[f[g]];if("remove"===a)for(delete this.j["@"+e],f=0,g=d.length;f<g;f++){if(f===g-1)return d[f].remove(e,c);d[f].remove(e)}f=this.c.field;g=0;for(var m=f.length;g<m;g++){for(var k=f[g],J=void 0,p=0;p<k.length;p++)J=(J||b)[k[p]];this.j["@"+e]=b;k=d[g];p="add"===a?k.add:k.update;if(g===m-1)return p.call(k,e,J,c);p.call(k,e,J)}}};d.prototype.update=
|
||||
function(a,b,c){if(this.c&&E(a))return this.l("update",a,b);this.b["@"+a]&&F(b)&&(this.remove(a),this.add(a,b,c,!0));return this};d.prototype.remove=function(a,b,c){if(this.c&&E(a))return this.l("remove",a,b);var d="@"+a;if(this.b[d]){if(this.h)return this.a[this.b[d]].postMessage({remove:!0,id:a}),delete this.b[d],b&&b(),this;if(!c){if(this.async&&"function"!==typeof importScripts){var e=this;d=new Promise(function(b){setTimeout(function(){e.remove(a,null,!0);e=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<10-(this.threshold||0);b++)C(this.m[b],a);this.depth&&C(this.s,a);delete this.b[d];this.o=!1}return this};d.prototype.search=function(a,b,c,d){if(E(b)){if(b.constructor===Array)for(var e=0;e<b.length;e++)b[e].query=a;else b.query=a;a=b;b=0}var f=a,g=[];if(E(a)&&a.constructor!==Array){(c=a.callback||b)&&(f.callback=null);b=a.limit;var r=a.threshold;var m=a.boost;a=a.query}if(this.c){a=this.c.ref;r=this.c.index;var k=f.field;if(k)f.field=
|
||||
null;else if(f.constructor===Array){var p=f;k=[];for(var t=0;t<f.length;t++)k[t]=f[t].field}else k=Object.keys(a);if(E(k)){k.constructor===Array||(k=[k]);t=k.length;for(var q=0;q<t;q++)p&&(f=p[q]),g[q]=r[a[k[q]]].search(f);return c?c(g.concat.apply([],g)):this.async?new Promise(function(a){Promise.all(g).then(function(b){a(b.concat.apply([],b))})}):g.concat.apply([],g)}return r[a[k]].search(f,c)}r||(r=this.threshold||0);I(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(this.h)for(this.G=c,this.B=0,this.u=[],
|
||||
k=0;k<this.h;k++)this.a[k].postMessage({search:!0,limit:b,threshold:r,content:a});else{if(!d){if(this.async&&"function"!==typeof importScripts){var A=this;a=new Promise(function(a){setTimeout(function(){a(A.search(f,b,null,!0));A=null})});if(c)a.then(c);else return a;return this}if(c)return c(this.search(f,b,null,!0)),this}if(!a||!F(a))return g;f=a;if(this.cache)if(this.o){if(c=this.w.get(a))return c}else this.w.clear(),this.o=!0;f=this.encode(f);if(!f.length)return g;c=this.g;c=I(c)?c(f):f.split(P);
|
||||
p=c.length;d=!0;e=[];var x=B();1<p&&(this.depth?(k=!0,q=c[0],x[q]=1):c.sort(V));if(!k||(t=this.s)[q]){var v=0;m&&(r=(r||1)/m,0>m&&(v=r));for(m=k?1:0;m<p;m++){var n=c[m];if(n){if(!x[n]){var w=[],y=!1,z=0;if(q=k?t[q]:this.m)for(var D=void 0,C=v;C<10-r;C++)if(D=q[C][n])w[z++]=D,y=!0;if(y)e[e.length]=1<z?w.concat.apply([],w):w[0];else if(!this.C){d=!1;break}x[n]=1}q=n}}}else d=!1;d&&(g=W(e,b,this.j,this.C));this.cache&&this.w.set(a,g);return g}};d.prototype.info=function(){if(this.h)for(var a=0;a<this.h;a++)this.a[a].postMessage({info:!0,
|
||||
id:this.id});else{for(var b,c=0,d=0,e=0,f=0;f<10-(this.threshold||0);f++){a=Object.keys(this.m[f]);for(var g=0;g<a.length;g++)b=this.m[f][a[g]].length,c+=1*b+2*a[g].length+4,d+=b,e+=2*a[g].length}a=Object.keys(this.b);b=a.length;for(f=0;f<b;f++)c+=2*a[f].length+2;return{id:this.id,memory:c,items:b,sequences:d,chars:e,cache:this.cache&&this.cache.A?this.cache.A.length:!1,matcher:K.length+(this.f?this.f.length:0),worker:this.h,threshold:this.threshold,depth:this.depth,contextual:this.depth&&"strict"===
|
||||
this.g}}};d.prototype.clear=function(){return this.destroy().init()};d.prototype.destroy=function(){this.cache&&(this.w.clear(),this.w=null);this.m=this.s=this.b=null;return this};d.prototype.export=function(){if(this.c){for(var a=this.c.index,b=Array(a.length+1),c=0;c<a.length;c++)b[c]=[a[c].m,a[c].s,a[c].b];b[c]=this.j;return JSON.stringify(b)}return JSON.stringify([this.m,this.s,this.b])};d.prototype.import=function(a){a=JSON.parse(a);if(this.c){for(var b=this.c.index,c=b.length,d=0;d<c;d++){var e=
|
||||
b[d];e.m=a[d][0];e.s=a[d][1];e.b=a[d][2];e.j=a[c]}this.j=a[c]}else this.m=a[0],this.s=a[1],this.b=a[2],this.j=a[3]};var H={icase:function(a){return a.toLowerCase()},simple:function(){var a=[f("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",f("[\u00e8\u00e9\u00ea\u00eb]"),"e",f("[\u00ec\u00ed\u00ee\u00ef]"),"i",f("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",f("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",f("[\u00fd\u0177\u00ff]"),"y",f("\u00f1"),"n",f("\u00e7"),"c",f("\u00df"),"s",f(" & ")," and ",f("[-/]"),
|
||||
" ",f("[^a-z0-9 ]"),"",f("\\s+")," "];return function(b){b=e(b.toLowerCase(),a);return" "===b?"":b}}(),advanced:function(){var a=[f("ae"),"a",f("ai"),"ei",f("ay"),"ei",f("ey"),"ei",f("oe"),"o",f("ue"),"u",f("ie"),"i",f("sz"),"s",f("zs"),"s",f("sh"),"s",f("ck"),"k",f("cc"),"k",f("dt"),"t",f("ph"),"f",f("pf"),"f",f("ou"),"o",f("uo"),"u"];return function(b,c){if(!b)return b;b=this.simple(b);2<b.length&&(b=e(b,a));c||1<b.length&&(b=G(b));return b}}(),extra:function(){var a=[f("p"),"b",f("z"),"s",f("[cgq]"),
|
||||
"k",f("n"),"m",f("d"),"t",f("[vw]"),"f",f("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var c=0;c<b.length;c++){var d=b[c];1<d.length&&(b[c]=d[0]+e(d.substring(1),a))}b=b.join(" ");b=G(b)}return b}}(),balance:function(){var a=[f("[-/]")," ",f("[^a-z0-9 ]"),"",f("\\s+")," "];return function(b){return G(e(b.toLowerCase(),a))}}()},ca=function(){function a(a){this.clear();this.H=!0!==a&&a}a.prototype.clear=function(){this.cache=B();this.count=
|
||||
B();this.index=B();this.A=[]};a.prototype.set=function(a,c){if(this.H&&z(this.cache[a])){var b=this.A.length;if(b===this.H){b--;var d=this.A[b];delete this.cache[d];delete this.count[d];delete this.index[d]}this.index[a]=b;this.A[b]=a;this.count[a]=-1;this.cache[a]=c;this.get(a)}else this.cache[a]=c};a.prototype.get=function(a){var b=this.cache[a];if(this.H&&b){var d=++this.count[a],e=this.index,f=e[a];if(0<f){for(var g=this.A,k=f;this.count[g[--f]]<=d&&-1!==f;);f++;if(f!==k){for(d=k;d>f;d--)k=g[d-
|
||||
1],g[d]=k,e[k]=d;g[f]=a;e[a]=f}}}return b};return a}();return d}(function(){var g={},l="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(d,m,k,f,e){k=l?URL.createObjectURL(new Blob(["("+k.toString()+")()"],{type:"text/javascript"})):d+".es5.js";d+="-"+m;g[d]||(g[d]=[]);g[d][e]=new Worker(k);g[d][e].onmessage=f;console.log("Register Worker: "+d+"@"+e);return g[d][e]}}()),this);
|
||||
|
24
dist/flexsearch.light.js
vendored
24
dist/flexsearch.light.js
vendored
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
FlexSearch v0.3.62
|
||||
FlexSearch v0.4.0
|
||||
Copyright 2019 Nextapps GmbH
|
||||
Author: Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(e,l,u){let n;(n=u.define)&&n.amd?n([],function(){return l}):(n=u.modules)?n[e.toLowerCase()]=l:"object"===typeof exports?module.exports=l:u[e]=l})("FlexSearch",function(){function e(a){this.id=a&&!x(a.id)?a.id:G++;this.init(a);l(this,"index",function(){return this.a});l(this,"length",function(){return Object.keys(this.a).length})}function l(a,b,c){Object.defineProperty(a,b,{get:c})}function u(a,b){for(let c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}function n(a,b,
|
||||
c,f,d,p,g){if(b[c])return b[c];d=d?(9-(g||6))*p+(g||6)*d:p;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 x(a){return"undefined"===typeof a}function C(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=t();return b}function t(){return Object.create(null)}const w={encode:"icase",b:"forward",j:!1,cache:!1,async:!1,l:!1,h:!1,threshold:0,depth:0},A=[];let G=0;const D=/\W+/g,E={},F={};e.create=function(a){return new e(a)};e.registerMatcher=function(a){for(const b in a)a.hasOwnProperty(b)&&A.push(new RegExp(b,"g"),a[b]);return this};e.registerEncoder=function(a,b){v[a]=b.bind(v);return this};e.registerLanguage=
|
||||
function(a,b){E[a]=b.filter;F[a]=b.stemmer;return this};e.encode=function(a,b){return v[a](b)};e.prototype.init=function(a){this.i=[];a||(a=w);var b=a.preset,c={};this.b=a.tokenize||c.b||this.b||w.b;this.h=a.rtl||this.h||w.h;this.threshold=x(b=a.threshold)?c.threshold||this.threshold||w.threshold:b;this.depth=x(b=a.depth)?c.depth||this.depth||w.depth:b;this.f=(b=x(b=a.encode)?c.encode:b)&&v[b]&&v[b].bind(v)||(y(b)?b:this.f||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=E[b]||b;c=this.f;var f=
|
||||
t();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=t();this.a=t();return this};e.prototype.encode=function(a){a&&A.length&&(a=u(a,A));a&&this.i.length&&(a=u(a,this.i));a&&this.f&&(a=this.f(a));a&&this.stemmer&&
|
||||
(a=u(a,this.stemmer));return a};e.prototype.addMatcher=function(a){const b=this.i;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=t();f._ctx=t();d=this.threshold;const B=this.depth,r=this.g,q=b.length,l=this.h;for(let e=
|
||||
0;e<q;e++){var p=b[e];if(p){var g=p.length,k=(l?e+1:q-e)/q,m="";switch(c){case "reverse":case "both":for(var h=g;--h;)m=p[h]+m,n(r,f,m,a,l?1:(g-h)/g,k,d);m="";case "forward":for(h=0;h<g;h++)m+=p[h],n(r,f,m,a,l?(h+1)/g:1,k,d);break;case "full":for(h=0;h<g;h++){const b=(l?h+1:g-h)/g;for(let c=g;c>h;c--)m=p.substring(h,c),n(r,f,m,a,b,k,d)}break;default:if(g=n(r,f,p,a,1,k,d),B&&1<q&&g>=d)for(g=f._ctx[p]||(f._ctx[p]=t()),p=this.c[p]||(this.c[p]=C(10-(d||0))),k=e-B,m=e+B+1,0>k&&(k=0),m>q&&(m=q);k<m;k++)k!==
|
||||
e&&n(p,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=[];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=t();if(1<c)if(this.depth){var m=!0;var h=a[0];k[h]=1}else a.sort(H);var l;if(!m||(l=this.c)[h])for(var n=m?1:0;n<c;n++){var r=a[n];if(r){if(!k[r]){var q=[];let a=!1,b=0;if(h=m?l[h]:this.g){let c;for(let d=0;d<10-g;d++)if(c=h[d][r])q[b++]=c,a=!0}if(a)d[d.length]=
|
||||
1<b?q.concat.apply([],q):q[0];else{f=!1;break}k[r]=1}h=r}}else f=!1;if(f)a:{g=[];e=d.length;if(1<e){d.sort(I);m=t();l=d[0];h=l.length;for(a=0;a<h;)m["@"+l[a++]]=1;for(k=f=0;++k<e;){n=!1;r=k===e-1;l=d[k];h=l.length;for(a=0;a<h;)if(c=l[a++],q="@"+c,m[q]&&m[q]===k){if(r){if(g[f++]=c,b&&f===b){e=g;break a}}else m[q]=k+1;n=!0}if(!n)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()};e.prototype.destroy=function(){this.g=this.c=
|
||||
this.a=null;return this};const v={icase:function(a){return a.toLowerCase()}};return e}(!1),this);
|
||||
'use strict';(function(e,l,u){let n;(n=u.define)&&n.amd?n([],function(){return l}):(n=u.modules)?n[e.toLowerCase()]=l:"object"===typeof exports?module.exports=l:u[e]=l})("FlexSearch",function(){function e(a,c){const b=c?c.id:a&&a.id;this.id=b||0===b?b:G++;this.init(a,c);l(this,"index",function(){return this.a});l(this,"length",function(){return Object.keys(this.a).length})}function l(a,c,b){Object.defineProperty(a,c,{get:b})}function u(a,c){for(let b=0;b<c.length;b+=2)a=a.replace(c[b],c[b+1]);return a}
|
||||
function n(a,c,b,f,d,p,g){if(c[b])return c[b];d=d?(9-(g||6))*p+(g||6)*d:p;c[b]=d;d>=g&&(a=a[9-(d+.5>>0)],a=a[b]||(a[b]=[]),a[a.length]=f);return d}function y(a,c){if(a){const b=Object.keys(a);for(let f=0,d=b.length;f<d;f++){const d=b[f],g=a[d];if(g)for(let b=0,f=g.length;b<f;b++)if(g[b]===c){1===f?delete a[d]:g.splice(b,1);break}else"object"===typeof g[b]&&y(g[b],c)}}}function H(a,c){a=a.length-c.length;return 0>a?1:a?-1:0}function I(a,c){a=a.length-c.length;return 0>a?-1:a?1:0}function x(a){return"function"===
|
||||
typeof a}function z(a){return"undefined"===typeof a}function C(a){const c=Array(a);for(let b=0;b<a;b++)c[b]=t();return c}function t(){return Object.create(null)}const v={encode:"icase",b:"forward",l:!1,cache:!1,async:!1,m:!1,h:!1,threshold:0,depth:0,j:!1},A=[];let G=0;const D=/\W+/g,E={},F={};e.create=function(a){return new e(a)};e.registerMatcher=function(a){for(const c in a)a.hasOwnProperty(c)&&A.push(new RegExp(c,"g"),a[c]);return this};e.registerEncoder=function(a,c){w[a]=c.bind(w);return this};
|
||||
e.registerLanguage=function(a,c){E[a]=c.filter;F[a]=c.stemmer;return this};e.encode=function(a,c){return w[a](c)};e.prototype.init=function(a,c){this.i=[];if(c){var b=c.preset;a=c}else a||(a=v),b=a.preset;c={};this.b=a.tokenize||c.b||this.b||v.b;this.h=a.rtl||this.h||v.h;this.threshold=z(b=a.threshold)?c.threshold||this.threshold||v.threshold:b;this.depth=z(b=a.depth)?c.depth||this.depth||v.depth:b;this.f=(b=z(b=a.encode)?c.encode||v.encode:b)&&w[b]&&w[b].bind(w)||(x(b)?b:this.f||!1);(b=a.matcher)&&
|
||||
this.addMatcher(b);if(b=a.filter){b=E[b]||b;c=this.f;var f=t();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=t();this.a=t();return this};e.prototype.encode=function(a){a&&A.length&&(a=u(a,A));a&&this.i.length&&
|
||||
(a=u(a,this.i));a&&this.f&&(a=this.f(a));a&&this.stemmer&&(a=u(a,this.stemmer));return a};e.prototype.addMatcher=function(a){const c=this.i;for(const b in a)a.hasOwnProperty(b)&&c.push(new RegExp(b,"g"),a[b]);return this};e.prototype.add=function(a,c,b,f,d){if(c&&"string"===typeof c&&(a||0===a)){const e="@"+a;if(this.a[e]&&!f)return this.update(a,c);if(!d&&b)return this.add(a,c,null,f,!0),b(),this;c=this.encode(c);if(!c.length)return this;b=this.b;c=x(b)?b(c):c.split(D);f=t();f._ctx=t();d=this.threshold;
|
||||
const B=this.depth,r=this.g,q=c.length,l=this.h;for(let e=0;e<q;e++){var p=c[e];if(p){var g=p.length,k=(l?e+1:q-e)/q,m="";switch(b){case "reverse":case "both":for(var h=g;--h;)m=p[h]+m,n(r,f,m,a,l?1:(g-h)/g,k,d);m="";case "forward":for(h=0;h<g;h++)m+=p[h],n(r,f,m,a,l?(h+1)/g:1,k,d);break;case "full":for(h=0;h<g;h++){const c=(l?h+1:g-h)/g;for(let b=g;b>h;b--)m=p.substring(h,b),n(r,f,m,a,c,k,d)}break;default:if(g=n(r,f,p,a,1,k,d),B&&1<q&&g>=d)for(g=f._ctx[p]||(f._ctx[p]=t()),p=this.c[p]||(this.c[p]=
|
||||
C(10-(d||0))),k=e-B,m=e+B+1,0>k&&(k=0),m>q&&(m=q);k<m;k++)k!==e&&n(p,g,c[k],a,0,10-(k<e?e-k:k-e),d)}}}this.a[e]=1}return this};e.prototype.update=function(a,c,b){this.a["@"+a]&&"string"===typeof c&&(this.remove(a),this.add(a,c,b,!0));return this};e.prototype.remove=function(a,c,b){const f="@"+a;if(this.a[f]){if(!b&&c)return this.remove(a,null,!0),c(),this;for(c=0;c<10-(this.threshold||0);c++)y(this.g[c],a);this.depth&&y(this.c,a);delete this.a[f]}return this};e.prototype.search=function(a,c,b,f){var d=
|
||||
a,e=[];if("object"===typeof a){c=a.limit;var g=a.threshold;a=a.query}g||(g=this.threshold||0);x(c)?(b=c,c=1E3):c||0===c||(c=1E3);if(!f&&b)return b(this.search(d,c,null,!0)),this;if(!a||"string"!==typeof a)return e;d=this.encode(a);if(!d.length)return e;a=this.b;a=x(a)?a(d):d.split(D);b=a.length;f=!0;d=[];var k=t();if(1<b)if(this.depth){var m=!0;var h=a[0];k[h]=1}else a.sort(H);var l;if(!m||(l=this.c)[h])for(var n=m?1:0;n<b;n++){var r=a[n];if(r){if(!k[r]){var q=[];let a=!1,b=0;if(h=m?l[h]:this.g){let c;
|
||||
for(let d=0;d<10-g;d++)if(c=h[d][r])q[b++]=c,a=!0}if(a)d[d.length]=1<b?q.concat.apply([],q):q[0];else{f=!1;break}k[r]=1}h=r}}else f=!1;if(f)a:{g=[];e=d.length;if(1<e){d.sort(I);m=t();l=d[0];h=l.length;for(a=0;a<h;)m["@"+l[a++]]=1;for(k=f=0;++k<e;){n=!1;r=k===e-1;l=d[k];h=l.length;for(a=0;a<h;)if(b=l[a++],q="@"+b,m[q]&&m[q]===k){if(r){if(g[f++]=b,c&&f===c){e=g;break a}}else m[q]=k+1;n=!0}if(!n)break}}else e&&(g=d[0],c&&g.length>c&&(g=g.slice(0,c)));e=g}return e};e.prototype.clear=function(){return this.destroy().init()};
|
||||
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);
|
||||
|
53
dist/flexsearch.min.js
vendored
53
dist/flexsearch.min.js
vendored
@@ -1,30 +1,35 @@
|
||||
/*
|
||||
FlexSearch v0.3.62
|
||||
FlexSearch v0.4.0
|
||||
Copyright 2019 Nextapps GmbH
|
||||
Author: Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(u,A,h){let v;(v=h.define)&&v.amd?v([],function(){return A}):(v=h.modules)?v[u.toLowerCase()]=A:"object"===typeof exports?module.exports=A:h[u]=A})("FlexSearch",function P(u){function h(b){this.id=b&&!w(b.id)?b.id:Q++;this.init(b);B(this,"index",function(){return this.a});B(this,"length",function(){return Object.keys(this.a).length})}function v(b,a,c,d){this.m!==this.c&&(this.g=this.g.concat(c),this.m++,d&&this.g.length>=d&&(this.m=this.c),this.B&&this.m===this.c&&(this.cache&&
|
||||
this.j.set(a,this.g),this.B(this.g),this.g=[]));return this}function B(b,a,c){Object.defineProperty(b,a,{get:c})}function f(b){return new RegExp(b,"g")}function m(b,a){for(let c=0;c<a.length;c+=2)b=b.replace(a[c],a[c+1]);return b}function D(b,a,c,d,e,l,g){if(a[c])return a[c];e=e?(9-(g||6))*l+(g||6)*e:l;a[c]=e;e>=g&&(b=b[9-(e+.5>>0)],b=b[c]||(b[c]=[]),b[b.length]=d);return e}function I(b,a){if(b){const c=Object.keys(b);for(let d=0,e=c.length;d<e;d++){const e=c[d],g=b[e];if(g)for(let c=0,d=g.length;c<
|
||||
d;c++)if(g[c]===a){1===d?delete b[e]:g.splice(c,1);break}else"object"===typeof g[c]&&I(g[c],a)}}}function J(b){let a="",c="";var d="";for(let e=0;e<b.length;e++){const l=b[e];if(l!==c)if(e&&"h"===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)a+=l}else a+=l;d=e===b.length-1?"":b[e+1];c=l}return a}function R(b,a){b=b.length-a.length;return 0>b?1:b?-1:0}function S(b,a){b=b.length-a.length;return 0>b?-1:b?1:0}function T(b,
|
||||
a,c){let d=[],e;const l=b.length;if(1<l){b.sort(S);const f=r();let h=b[0],n=h.length,k=0;for(;k<n;)f["@"+h[k++]]=1;let z,q=0,t=0;for(;++t<l;){let y=!1;const p=t===l-1;e=[];h=b[t];n=h.length;for(k=0;k<n;){z=h[k++];var g="@"+z;if(f[g]){const b=f[g];if(b===t){if(p){if(d[q++]=z,a&&q===a)return d}else f[g]=t+1;y=!0}else c&&(g=e[b]||(e[b]=[]),g[g.length]=z)}}if(!y&&!c)break}if(c&&(q=d.length,(t=e.length)&&(!a||q<a)))for(;t--;)if(z=e[t])for(k=0,n=z.length;k<n;k++)if(d[q++]=z[k],a&&q===a)return d}else l&&
|
||||
(d=b[0],a&&d.length>a&&(d=d.slice(0,a)));return d}function F(b){return"string"===typeof b}function G(b){return"function"===typeof b}function w(b){return"undefined"===typeof b}function K(b){const a=Array(b);for(let c=0;c<b;c++)a[c]=r();return a}function r(){return Object.create(null)}function U(){let b,a;self.onmessage=function(c){if(c=c.data)if(c.search){const d=a.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit);self.postMessage({id:b,content:c.content,limit:c.limit,result:d})}else c.add?
|
||||
a.add(c.id,c.content):c.update?a.update(c.id,c.content):c.remove?a.remove(c.id):c.clear?a.clear():c.info?(c=a.info(),c.worker=b,console.log(c)):c.register&&(b=c.id,c.options.cache=!1,c.options.async=!1,c.options.worker=!1,a=(new Function(c.register.substring(c.register.indexOf("{")+1,c.register.lastIndexOf("}"))))(),a=new a(c.options))}}function V(b,a,c,d){b=u("flexsearch","id"+b,U,function(a){(a=a.data)&&a.result&&d(a.id,a.content,a.result,a.limit)},a);const e=P.toString();c.id=a;b.postMessage({register:e,
|
||||
options:c,id:a});return b}const x={encode:"icase",b:"forward",u:!1,cache:!1,async:!1,c:!1,A:!1,threshold:0,depth:0},L={memory:{encode:"extra",b:"strict",threshold:7},speed:{encode:"icase",b:"strict",threshold:7,depth:2},match:{encode:"extra",b:"full"},score:{encode:"extra",b:"strict",threshold:5,depth:4},balance:{encode:"balance",b:"strict",threshold:6,depth:3},fastest:{encode:"icase",b:"strict",threshold:9,depth:1}},H=[];let Q=0;const M=f("\\W+"),N={},O={};h.create=function(b){return new h(b)};h.registerMatcher=
|
||||
function(b){for(const a in b)b.hasOwnProperty(a)&&H.push(f(a),b[a]);return this};h.registerEncoder=function(b,a){C[b]=a.bind(C);return this};h.registerLanguage=function(b,a){N[b]=a.filter;O[b]=a.stemmer;return this};h.encode=function(b,a){return C[b](a)};h.prototype.init=function(b){this.o=[];b||(b=x);var a=b.preset,c={};F(b)?(c=L[b],b={}):a&&(c=L[a]);if(a=b.worker)if("undefined"===typeof Worker)b.worker=!1,this.i=null;else{var d=parseInt(a,10)||4;this.w=-1;this.m=0;this.g=[];this.B=null;this.i=Array(d);
|
||||
for(var e=0;e<d;e++)this.i[e]=V(this.id,e,b,v.bind(this))}this.b=b.tokenize||c.b||this.b||x.b;this.A=b.rtl||this.A||x.A;this.async="undefined"===typeof Promise||w(a=b.async)?this.async||x.async:a;this.c=w(a=b.worker)?this.c||x.c:a;this.threshold=w(a=b.threshold)?c.threshold||this.threshold||x.threshold:a;this.depth=w(a=b.depth)?c.depth||this.depth||x.depth:a;this.u=w(a=b.suggest)?this.u||x.u:a;this.s=(a=w(a=b.encode)?c.encode:a)&&C[a]&&C[a].bind(C)||(G(a)?a:this.s||!1);(a=b.matcher)&&this.addMatcher(a);
|
||||
if(a=b.filter){a=N[a]||a;c=this.s;d=r();if(a)for(e=0;e<a.length;e++){var l=c?c(a[e]):a[e];d[l]=String.fromCharCode(65E3-a.length+e)}this.filter=a=d}if(a=b.stemmer){var g;c=O[a]||a;d=this.s;e=[];if(c)for(g in c)c.hasOwnProperty(g)&&(l=d?d(g):g,e.push(f("(?=.{"+(l.length+3)+",})"+l+"$"),d?d(c[g]):c[g]));this.stemmer=g=e}this.f=K(10-(this.threshold||0));this.h=r();this.a=r();this.v=!0;this.j=(this.cache=a=w(a=b.cache)?this.cache||x.cache:a)?new W(a):!1;return this};h.prototype.encode=function(b){b&&
|
||||
H.length&&(b=m(b,H));b&&this.o.length&&(b=m(b,this.o));b&&this.s&&(b=this.s(b));b&&this.stemmer&&(b=m(b,this.stemmer));return b};h.prototype.addMatcher=function(b){const a=this.o;for(const c in b)b.hasOwnProperty(c)&&a.push(f(c),b[c]);return this};h.prototype.add=function(b,a,c,d,e){if(a&&F(a)&&(b||0===b)){var f="@"+b;if(this.a[f]&&!d)return this.update(b,a);if(this.c)return++this.w>=this.i.length&&(this.w=0),this.i[this.w].postMessage({add:!0,id:b,content:a}),this.a[f]=""+this.w,c&&c(),this;if(!e){if(this.async&&
|
||||
"function"!==typeof importScripts){let e=this;f=new Promise(function(c){setTimeout(function(){e.add(b,a,null,d,!0);e=null;c()})});if(c)f.then(c);else return f;return this}if(c)return this.add(b,a,null,d,!0),c(),this}a=this.encode(a);if(!a.length)return this;c=this.b;e=G(c)?c(a):a.split(M);const l=r();l._ctx=r();const q=this.threshold,t=this.depth,E=this.f,m=e.length,y=this.A;for(let a=0;a<m;a++){var g=e[a];if(g){var h=g.length,p=(y?a+1:m-a)/m,n="";switch(c){case "reverse":case "both":for(var k=h;--k;)n=
|
||||
g[k]+n,D(E,l,n,b,y?1:(h-k)/h,p,q);n="";case "forward":for(k=0;k<h;k++)n+=g[k],D(E,l,n,b,y?(k+1)/h:1,p,q);break;case "full":for(k=0;k<h;k++){const a=(y?k+1:h-k)/h;for(let c=h;c>k;c--)n=g.substring(k,c),D(E,l,n,b,a,p,q)}break;default:if(h=D(E,l,g,b,1,p,q),t&&1<m&&h>=q)for(h=l._ctx[g]||(l._ctx[g]=r()),g=this.h[g]||(this.h[g]=K(10-(q||0))),p=a-t,n=a+t+1,0>p&&(p=0),n>m&&(n=m);p<n;p++)p!==a&&D(g,h,e[p],b,0,10-(p<a?a-p:p-a),q)}}}this.a[f]=1;this.v=!1}return this};h.prototype.update=function(b,a,c){this.a["@"+
|
||||
b]&&F(a)&&(this.remove(b),this.add(b,a,c,!0));return this};h.prototype.remove=function(b,a,c){var d="@"+b;if(this.a[d]){if(this.c)return this.i[this.a[d]].postMessage({remove:!0,id:b}),delete this.a[d],a&&a(),this;if(!c){if(this.async&&"function"!==typeof importScripts){let c=this;d=new Promise(function(a){setTimeout(function(){c.remove(b,null,!0);c=null;a()})});if(a)d.then(a);else return d;return this}if(a)return this.remove(b,null,!0),a(),this}for(a=0;a<10-(this.threshold||0);a++)I(this.f[a],b);
|
||||
this.depth&&I(this.h,b);delete this.a[d];this.v=!1}return this};h.prototype.search=function(b,a,c,d){let e=b,f;var g=[];"object"===typeof b&&((c=b.callback||a)&&(e.callback=null),a=b.limit,f=b.threshold,b=b.query);f||(f=this.threshold||0);G(a)?(c=a,a=1E3):a||0===a||(a=1E3);if(this.c)for(this.B=c,this.m=0,this.g=[],g=0;g<this.c;g++)this.i[g].postMessage({search:!0,limit:a,threshold:f,content:b});else{if(!d){if(this.async&&"function"!==typeof importScripts){let d=this;b=new Promise(function(b){setTimeout(function(){b(d.search(e,
|
||||
a,null,!0));d=null})});if(c)b.then(c);else return b;return this}if(c)return c(this.search(e,a,null,!0)),this}if(!b||!F(b))return g;e=b;if(this.cache)if(this.v){if(c=this.j.get(b))return c}else this.j.clear(),this.v=!0;e=this.encode(e);if(!e.length)return g;c=this.b;c=G(c)?c(e):e.split(M);d=c.length;var h=!0,p=[],n=r();if(1<d)if(this.depth){var k=!0;var m=c[0];n[m]=1}else c.sort(R);var q;if(!k||(q=this.h)[m])for(let a=k?1:0;a<d;a++){const b=c[a];if(b){if(!n[b]){const a=[];let c=!1,d=0;if(m=k?q[m]:
|
||||
this.f){let e;for(let g=0;g<10-f;g++)if(e=m[g][b])a[d++]=e,c=!0}if(c)p[p.length]=1<d?a.concat.apply([],a):a[0];else if(!this.u){h=!1;break}n[b]=1}m=b}}else h=!1;h&&(g=T(p,a,this.u));this.cache&&this.j.set(b,g);return g}};h.prototype.info=function(){if(this.c)for(var b=0;b<this.c;b++)this.i[b].postMessage({info:!0,id:this.id});else{var a=0,c=0,d=0;for(var e=0;e<10-(this.threshold||0);e++){b=Object.keys(this.f[e]);for(let g=0;g<b.length;g++){var f=this.f[e][b[g]].length;a+=1*f+2*b[g].length+4;c+=f;
|
||||
d+=2*b[g].length}}b=Object.keys(this.a);f=b.length;for(e=0;e<f;e++)a+=2*b[e].length+2;return{id:this.id,memory:a,items:f,sequences:c,chars:d,cache:this.cache&&this.cache.l?this.cache.l.length:!1,matcher:H.length+(this.o?this.o.length:0),worker:this.c,threshold:this.threshold,depth:this.depth,contextual:this.depth&&"strict"===this.b}}};h.prototype.clear=function(){return this.destroy().init()};h.prototype.destroy=function(){this.cache&&(this.j.clear(),this.j=null);this.f=this.h=this.a=null;return this};
|
||||
h.prototype.export=function(){return JSON.stringify([this.f,this.h,this.a])};h.prototype.import=function(b){b=JSON.parse(b);this.f=b[0];this.h=b[1];this.a=b[2]};const C={icase:function(b){return b.toLowerCase()},simple:function(){const b=[f("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",f("[\u00e8\u00e9\u00ea\u00eb]"),"e",f("[\u00ec\u00ed\u00ee\u00ef]"),"i",f("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",f("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",f("[\u00fd\u0177\u00ff]"),"y",f("\u00f1"),"n",f("\u00e7"),
|
||||
"c",f("\u00df"),"s",f(" & ")," and ",f("[-/]")," ",f("[^a-z0-9 ]"),"",f("\\s+")," "];return function(a){a=m(a.toLowerCase(),b);return" "===a?"":a}}(),advanced:function(){const b=[f("ae"),"a",f("ai"),"ei",f("ay"),"ei",f("ey"),"ei",f("oe"),"o",f("ue"),"u",f("ie"),"i",f("sz"),"s",f("zs"),"s",f("sh"),"s",f("ck"),"k",f("cc"),"k",f("dt"),"t",f("ph"),"f",f("pf"),"f",f("ou"),"o",f("uo"),"u"];return function(a,c){if(!a)return a;a=this.simple(a);2<a.length&&(a=m(a,b));c||1<a.length&&(a=J(a));return a}}(),extra:function(){const b=
|
||||
[f("p"),"b",f("z"),"s",f("[cgq]"),"k",f("n"),"m",f("d"),"t",f("[vw]"),"f",f("[aeiouy]"),""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(let c=0;c<a.length;c++){const d=a[c];1<d.length&&(a[c]=d[0]+m(d.substring(1),b))}a=a.join(" ");a=J(a)}return a}}(),balance:function(){const b=[f("[-/]")," ",f("[^a-z0-9 ]"),"",f("\\s+")," "];return function(a){return J(m(a.toLowerCase(),b))}}()},W=function(){function b(a){this.clear();this.C=!0!==a&&a}b.prototype.clear=
|
||||
function(){this.cache=r();this.count=r();this.index=r();this.l=[]};b.prototype.set=function(a,b){if(this.C&&w(this.cache[a])){let c=this.l.length;if(c===this.C){c--;const a=this.l[c];delete this.cache[a];delete this.count[a];delete this.index[a]}this.index[a]=c;this.l[c]=a;this.count[a]=-1;this.cache[a]=b;this.get(a)}else this.cache[a]=b};b.prototype.get=function(a){const b=this.cache[a];if(this.C&&b){var d=++this.count[a];const b=this.index;let c=b[a];if(0<c){const f=this.l;for(var e=c;this.count[f[--c]]<=
|
||||
d&&-1!==c;);c++;if(c!==e){for(d=e;d>c;d--)e=f[d-1],f[d]=e,b[e]=d;f[c]=a;b[a]=c}}}return b};return b}();return h}(function(){const u={},A="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(h,v,B,f,m){B=A?URL.createObjectURL(new Blob(["("+B.toString()+")()"],{type:"text/javascript"})):h+".min.js";h+="-"+v;u[h]||(u[h]=[]);u[h][m]=new Worker(B);u[h][m].onmessage=f;return u[h][m]}}()),this);
|
||||
'use strict';(function(t,A,g){let w;(w=g.define)&&w.amd?w([],function(){return A}):(w=g.modules)?w[t.toLowerCase()]=A:"object"===typeof exports?module.exports=A:g[t]=A})("FlexSearch",function Q(t){function g(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:R++;this.init(a,b);B(this,"index",function(){return this.a});B(this,"length",function(){return Object.keys(this.a).length})}function w(a,b,c,e){this.s!==this.f&&(this.j=this.j.concat(c),this.s++,e&&this.j.length>=e&&(this.s=this.f),this.F&&this.s===
|
||||
this.f&&(this.cache&&this.m.set(b,this.j),this.F(this.j),this.j=[]));return this}function B(a,b,c){Object.defineProperty(a,b,{get:c})}function f(a){return new RegExp(a,"g")}function n(a,b){for(let c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}function F(a,b,c,e,d,l,h){if(b[c])return b[c];d=d?(9-(h||6))*l+(h||6)*d:l;b[c]=d;d>=h&&(a=a[9-(d+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=e);return d}function J(a,b){if(a){const c=Object.keys(a);for(let e=0,d=c.length;e<d;e++){const d=c[e],h=a[d];if(h)for(let c=
|
||||
0,e=h.length;c<e;c++)if(h[c]===b){1===e?delete a[d]:h.splice(c,1);break}else z(h[c])&&J(h[c],b)}}}function K(a){let b="",c="";var e="";for(let d=0;d<a.length;d++){const l=a[d];if(l!==c)if(d&&"h"===l){if(e="a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e,("a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c)&&e||" "===c)b+=l}else b+=l;e=d===a.length-1?"":a[d+1];c=l}return b}function S(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function T(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function U(a,
|
||||
b,c,e){let d=[],l;const h=a.length;if(1<h){a.sort(T);const x=u();let k=a[0],r=k.length,g=0;for(;g<r;)x["@"+k[g++]]=1;let m,C=0,v=0;for(;++v<h;){let p=!1;const V=v===h-1;l=[];k=a[v];r=k.length;for(g=0;g<r;){m=k[g++];var f="@"+m;if(x[f]){const a=x[f];if(a===v){if(V){if(d[C++]=c?c[f]:m,b&&C===b)return d}else x[f]=v+1;p=!0}else e&&(f=l[a]||(l[a]=[]),f[f.length]=m)}}if(!p&&!e)break}if(e&&(C=d.length,(v=l.length)&&(!b||C<b)))for(;v--;)if(m=l[v])for(g=0,r=m.length;g<r;g++)if(d[C++]=c?c["@"+m[g]]:m[g],b&&
|
||||
C===b)return d}else if(h)if(c)for(a=a[0],e=a.length,b&&b<e&&(e=b),d=Array(e),b=0;b<e;b++)d[b]=c["@"+a[b]];else d=a[0],b&&d.length>b&&(d=d.slice(0,b));return d}function G(a){return"string"===typeof a}function H(a){return"function"===typeof a}function z(a){return"object"===typeof a}function y(a){return"undefined"===typeof a}function L(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=u();return b}function u(){return Object.create(null)}function W(){let a,b;self.onmessage=function(c){if(c=c.data)if(c.search){const e=
|
||||
b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:e})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.clear?b.clear():c.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 X(a,
|
||||
b,c,e){a=t("flexsearch","id"+a,W,function(a){(a=a.data)&&a.result&&e(a.id,a.content,a.result,a.limit)},b);const d=Q.toString();c.id=b;a.postMessage({register:d,options:c,id:b});return a}const q={encode:"icase",c:"forward",A:!1,cache:!1,async:!1,f:!1,D:!1,threshold:0,depth:0,b:!1},M={memory:{encode:"extra",c:"strict",threshold:7},speed:{encode:"icase",c:"strict",threshold:7,depth:2},match:{encode:"extra",c:"full"},score:{encode:"extra",c:"strict",threshold:5,depth:4},balance:{encode:"balance",c:"strict",
|
||||
threshold:6,depth:3},fastest:{encode:"icase",c:"strict",threshold:9,depth:1}},I=[];let R=0;const N=f("\\W+"),O={},P={};g.create=function(a){return new g(a)};g.registerMatcher=function(a){for(const b in a)a.hasOwnProperty(b)&&I.push(f(b),a[b]);return this};g.registerEncoder=function(a,b){E[a]=b.bind(E);return this};g.registerLanguage=function(a,b){O[a]=b.filter;P[a]=b.stemmer;return this};g.encode=function(a,b){return E[a](b)};g.prototype.init=function(a,b){this.u=[];if(b){var c=b.preset;a=b}else a||
|
||||
(a=q),c=a.preset;b={};G(a)?(b=M[a],a={}):c&&(b=M[c]);if(c=a.worker)if("undefined"===typeof Worker)a.worker=!1,this.l=null;else{var e=parseInt(c,10)||4;this.C=-1;this.s=0;this.j=[];this.F=null;this.l=Array(e);for(var d=0;d<e;d++)this.l[d]=X(this.id,d,a,w.bind(this))}this.c=a.tokenize||b.c||this.c||q.c;this.D=a.rtl||this.D||q.D;this.async="undefined"===typeof Promise||y(c=a.async)?this.async||q.async:c;this.f=y(c=a.worker)?this.f||q.f:c;this.threshold=y(c=a.threshold)?b.threshold||this.threshold||q.threshold:
|
||||
c;this.depth=y(c=a.depth)?b.depth||this.depth||q.depth:c;this.A=y(c=a.suggest)?this.A||q.A:c;this.v=(c=y(c=a.encode)?b.encode||q.encode:c)&&E[c]&&E[c].bind(E)||(H(c)?c:this.v||!1);(c=a.matcher)&&this.addMatcher(c);if(c=a.filter){c=O[c]||c;b=this.v;e=u();if(c)for(d=0;d<c.length;d++){var l=b?b(c[d]):c[d];e[l]=String.fromCharCode(65E3-c.length+d)}this.filter=c=e}if(c=a.stemmer){var h;b=P[c]||c;e=this.v;d=[];if(b)for(h in b)b.hasOwnProperty(h)&&(l=e?e(h):h,d.push(f("(?=.{"+(l.length+3)+",})"+l+"$"),e?
|
||||
e(b[h]):b[h]));this.stemmer=h=d}this.b=d=(c=a.doc)?c:this.b||q.b;this.h=L(10-(this.threshold||0));this.i=u();this.a=u();this.g=d&&u();if(d)if(a.doc=null,h=d.field,b=d.index=[],e=d.ref={},d.id=d.id.split(":"),h.constructor===Array)for(d=0;d<h.length;d++)e[h[d]]=d,h[d]=h[d].split(":"),b[d]=new g(a),b[d].g=this.g;else e[h]=0,d.field=[h.split(":")],b[0]=new g(a),b[0].g=this.g;this.B=!0;this.m=(this.cache=c=y(c=a.cache)?this.cache||q.cache:c)?new Y(c):!1;return this};g.prototype.encode=function(a){a&&
|
||||
I.length&&(a=n(a,I));a&&this.u.length&&(a=n(a,this.u));a&&this.v&&(a=this.v(a));a&&this.stemmer&&(a=n(a,this.stemmer));return a};g.prototype.addMatcher=function(a){const b=this.u;for(const c in a)a.hasOwnProperty(c)&&b.push(f(c),a[c]);return this};g.prototype.add=function(a,b,c,e,d){if(this.b&&z(a))return this.w("add",a,b);if(b&&G(b)&&(a||0===a)){var l="@"+a;if(this.a[l]&&!e)return this.update(a,b);if(this.f)return++this.C>=this.l.length&&(this.C=0),this.l[this.C].postMessage({add:!0,id:a,content:b}),
|
||||
this.a[l]=""+this.C,c&&c(),this;if(!d){if(this.async&&"function"!==typeof importScripts){let d=this;l=new Promise(function(c){setTimeout(function(){d.add(a,b,null,e,!0);d=null;c()})});if(c)l.then(c);else return l;return this}if(c)return this.add(a,b,null,e,!0),c(),this}b=this.encode(b);if(!b.length)return this;c=this.c;d=H(c)?c(b):b.split(N);const r=u();r._ctx=u();const m=this.threshold,x=this.depth,v=this.h,D=d.length,n=this.D;for(let b=0;b<D;b++){var h=d[b];if(h){var f=h.length,g=(n?b+1:D-b)/D,
|
||||
k="";switch(c){case "reverse":case "both":for(var p=f;--p;)k=h[p]+k,F(v,r,k,a,n?1:(f-p)/f,g,m);k="";case "forward":for(p=0;p<f;p++)k+=h[p],F(v,r,k,a,n?(p+1)/f:1,g,m);break;case "full":for(p=0;p<f;p++){const b=(n?p+1:f-p)/f;for(let c=f;c>p;c--)k=h.substring(p,c),F(v,r,k,a,b,g,m)}break;default:if(f=F(v,r,h,a,1,g,m),x&&1<D&&f>=m)for(f=r._ctx[h]||(r._ctx[h]=u()),h=this.i[h]||(this.i[h]=L(10-(m||0))),g=b-x,k=b+x+1,0>g&&(g=0),k>D&&(k=D);g<k;g++)g!==b&&F(h,f,d[g],a,0,10-(g<b?b-g:g-b),m)}}}this.a[l]=1;this.B=
|
||||
!1}return this};g.prototype.w=function(a,b,c){if(b.constructor===Array)for(let d=0,e=b.length;d<e;d++){if(d===e-1)return this.w(a,b[d],c);this.w(a,b[d])}else{const f=this.b.index;let h=this.b.id,g;for(var e=0;e<h.length;e++)g=(g||b)[h[e]];if("remove"===a){delete this.g["@"+g];for(let a=0,b=f.length;a<b;a++){if(a===b-1)return f[a].remove(g,c);f[a].remove(g)}}h=this.b.field;for(let l=0,k=h.length;l<k;l++){e=h[l];let r;for(var d=0;d<e.length;d++)r=(r||b)[e[d]];this.g["@"+g]=b;e=f[l];d="add"===a?e.add:
|
||||
e.update;if(l===k-1)return d.call(e,g,r,c);d.call(e,g,r)}}};g.prototype.update=function(a,b,c){if(this.b&&z(a))return this.w("update",a,b);this.a["@"+a]&&G(b)&&(this.remove(a),this.add(a,b,c,!0));return this};g.prototype.remove=function(a,b,c){if(this.b&&z(a))return this.w("remove",a,b);var e="@"+a;if(this.a[e]){if(this.f)return this.l[this.a[e]].postMessage({remove:!0,id:a}),delete this.a[e],b&&b(),this;if(!c){if(this.async&&"function"!==typeof importScripts){let c=this;e=new Promise(function(b){setTimeout(function(){c.remove(a,
|
||||
null,!0);c=null;b()})});if(b)e.then(b);else return e;return this}if(b)return this.remove(a,null,!0),b(),this}for(b=0;b<10-(this.threshold||0);b++)J(this.h[b],a);this.depth&&J(this.i,a);delete this.a[e];this.B=!1}return this};g.prototype.search=function(a,b,c,e){if(z(b)){if(b.constructor===Array)for(var d=0;d<b.length;d++)b[d].query=a;else b.query=a;a=b;b=0}let f=a;let h=[];if(z(a)&&a.constructor!==Array){(c=a.callback||b)&&(f.callback=null);b=a.limit;var g=a.threshold;var n=a.boost;a=a.query}if(this.b){a=
|
||||
this.b.ref;g=this.b.index;var k=f.field;if(k)f.field=null;else if(f.constructor===Array){var p=f;k=[];for(var q=0;q<f.length;q++)k[q]=f[q].field}else k=Object.keys(a);if(z(k)){k.constructor===Array||(k=[k]);q=k.length;for(var m=0;m<q;m++)p&&(f=p[m]),h[m]=g[a[k[m]]].search(f);return c?c(h.concat.apply([],h)):this.async?new Promise(function(a){Promise.all(h).then(function(b){a(b.concat.apply([],b))})}):h.concat.apply([],h)}return g[a[k]].search(f,c)}g||(g=this.threshold||0);H(b)?(c=b,b=1E3):b||0===
|
||||
b||(b=1E3);if(this.f)for(this.F=c,this.s=0,this.j=[],k=0;k<this.f;k++)this.l[k].postMessage({search:!0,limit:b,threshold:g,content:a});else{if(!e){if(this.async&&"function"!==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||!G(a))return h;f=a;if(this.cache)if(this.B){if(c=this.m.get(a))return c}else this.m.clear(),this.B=!0;f=this.encode(f);
|
||||
if(!f.length)return h;c=this.c;c=H(c)?c(f):f.split(N);p=c.length;e=!0;d=[];var t=u();1<p&&(this.depth?(k=!0,m=c[0],t[m]=1):c.sort(S));if(!k||(q=this.i)[m]){let a=0;n&&(g=(g||1)/n,0>n&&(a=g));for(n=k?1:0;n<p;n++){const b=c[n];if(b){if(!t[b]){const c=[];let f=!1,h=0;if(m=k?q[m]:this.h){let d;for(let e=a;e<10-g;e++)if(d=m[e][b])c[h++]=d,f=!0}if(f)d[d.length]=1<h?c.concat.apply([],c):c[0];else if(!this.A){e=!1;break}t[b]=1}m=b}}}else e=!1;e&&(h=U(d,b,this.g,this.A));this.cache&&this.m.set(a,h);return h}};
|
||||
g.prototype.info=function(){if(this.f)for(var a=0;a<this.f;a++)this.l[a].postMessage({info:!0,id:this.id});else{var b=0,c=0,e=0;for(var d=0;d<10-(this.threshold||0);d++){a=Object.keys(this.h[d]);for(let h=0;h<a.length;h++){var f=this.h[d][a[h]].length;b+=1*f+2*a[h].length+4;c+=f;e+=2*a[h].length}}a=Object.keys(this.a);f=a.length;for(d=0;d<f;d++)b+=2*a[d].length+2;return{id:this.id,memory:b,items:f,sequences:c,chars:e,cache:this.cache&&this.cache.o?this.cache.o.length:!1,matcher:I.length+(this.u?this.u.length:
|
||||
0),worker:this.f,threshold:this.threshold,depth:this.depth,contextual:this.depth&&"strict"===this.c}}};g.prototype.clear=function(){return this.destroy().init()};g.prototype.destroy=function(){this.cache&&(this.m.clear(),this.m=null);this.h=this.i=this.a=null;return this};g.prototype.export=function(){if(this.b){const a=this.b.index,b=Array(a.length+1);let c=0;for(;c<a.length;c++)b[c]=[a[c].h,a[c].i,a[c].a];b[c]=this.g;return JSON.stringify(b)}return JSON.stringify([this.h,this.i,this.a])};g.prototype.import=
|
||||
function(a){a=JSON.parse(a);if(this.b){const b=this.b.index,c=b.length;for(let e=0;e<c;e++){const d=b[e];d.h=a[e][0];d.i=a[e][1];d.a=a[e][2];d.g=a[c]}this.g=a[c]}else this.h=a[0],this.i=a[1],this.a=a[2],this.g=a[3]};const E={icase:function(a){return a.toLowerCase()},simple:function(){const a=[f("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",f("[\u00e8\u00e9\u00ea\u00eb]"),"e",f("[\u00ec\u00ed\u00ee\u00ef]"),"i",f("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",f("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",
|
||||
f("[\u00fd\u0177\u00ff]"),"y",f("\u00f1"),"n",f("\u00e7"),"c",f("\u00df"),"s",f(" & ")," and ",f("[-/]")," ",f("[^a-z0-9 ]"),"",f("\\s+")," "];return function(b){b=n(b.toLowerCase(),a);return" "===b?"":b}}(),advanced:function(){const a=[f("ae"),"a",f("ai"),"ei",f("ay"),"ei",f("ey"),"ei",f("oe"),"o",f("ue"),"u",f("ie"),"i",f("sz"),"s",f("zs"),"s",f("sh"),"s",f("ck"),"k",f("cc"),"k",f("dt"),"t",f("ph"),"f",f("pf"),"f",f("ou"),"o",f("uo"),"u"];return function(b,c){if(!b)return b;b=this.simple(b);2<b.length&&
|
||||
(b=n(b,a));c||1<b.length&&(b=K(b));return b}}(),extra:function(){const a=[f("p"),"b",f("z"),"s",f("[cgq]"),"k",f("n"),"m",f("d"),"t",f("[vw]"),"f",f("[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 e=b[c];1<e.length&&(b[c]=e[0]+n(e.substring(1),a))}b=b.join(" ");b=K(b)}return b}}(),balance:function(){const a=[f("[-/]")," ",f("[^a-z0-9 ]"),"",f("\\s+")," "];return function(b){return K(n(b.toLowerCase(),a))}}()},
|
||||
Y=function(){function a(a){this.clear();this.G=!0!==a&&a}a.prototype.clear=function(){this.cache=u();this.count=u();this.index=u();this.o=[]};a.prototype.set=function(a,c){if(this.G&&y(this.cache[a])){let b=this.o.length;if(b===this.G){b--;const a=this.o[b];delete this.cache[a];delete this.count[a];delete this.index[a]}this.index[a]=b;this.o[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.G&&b){var e=++this.count[a];
|
||||
const b=this.index;let c=b[a];if(0<c){const f=this.o;for(var d=c;this.count[f[--c]]<=e&&-1!==c;);c++;if(c!==d){for(e=d;e>c;e--)d=f[e-1],f[e]=d,b[d]=e;f[c]=a;b[a]=c}}}return b};return a}();return g}(function(){const t={},A="undefined"!==typeof Blob&&"undefined"!==typeof URL&&URL.createObjectURL;return function(g,w,B,f,n){B=A?URL.createObjectURL(new Blob(["("+B.toString()+")()"],{type:"text/javascript"})):g+".min.js";g+="-"+w;t[g]||(t[g]=[]);t[g][n]=new Worker(B);t[g][n].onmessage=f;return t[g][n]}}()),
|
||||
this);
|
||||
|
46
dist/flexsearch.node.js
vendored
46
dist/flexsearch.node.js
vendored
@@ -1,27 +1,31 @@
|
||||
/*
|
||||
FlexSearch v0.3.62
|
||||
FlexSearch v0.4.0
|
||||
Copyright 2019 Nextapps GmbH
|
||||
Author: Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(g,y,d){let m;(m=d.define)&&m.amd?m([],function(){return y}):(m=d.modules)?m[g.toLowerCase()]=y:"object"===typeof exports?module.exports=y:d[g]=y})("FlexSearch",function(){function g(b){this.id=b&&!t(b.id)?b.id:L++;this.init(b);y(this,"index",function(){return this.b});y(this,"length",function(){return Object.keys(this.b).length})}function y(b,a,c){Object.defineProperty(b,a,{get:c})}function d(b){return new RegExp(b,"g")}function m(b,a){for(let c=0;c<a.length;c+=2)b=b.replace(a[c],
|
||||
a[c+1]);return b}function A(b,a,c,f,e,d,h){if(a[c])return a[c];e=e?(9-(h||6))*d+(h||6)*e:d;a[c]=e;e>=h&&(b=b[9-(e+.5>>0)],b=b[c]||(b[c]=[]),b[b.length]=f);return e}function E(b,a){if(b){const c=Object.keys(b);for(let f=0,e=c.length;f<e;f++){const e=c[f],h=b[e];if(h)for(let c=0,f=h.length;c<f;c++)if(h[c]===a){1===f?delete b[e]:h.splice(c,1);break}else"object"===typeof h[c]&&E(h[c],a)}}}function F(b){let a="",c="";var f="";for(let e=0;e<b.length;e++){const d=b[e];if(d!==c)if(e&&"h"===d){if(f="a"===
|
||||
f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f,("a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c)&&f||" "===c)a+=d}else a+=d;f=e===b.length-1?"":b[e+1];c=d}return a}function M(b,a){b=b.length-a.length;return 0>b?1:b?-1:0}function N(b,a){b=b.length-a.length;return 0>b?-1:b?1:0}function O(b,a,c){let f=[],e;const d=b.length;if(1<d){b.sort(N);const n=u();let l=b[0],g=l.length,k=0;for(;k<g;)n["@"+l[k++]]=1;let r,p=0,v=0;for(;++v<d;){let w=!1;const q=v===d-1;e=[];l=b[v];g=l.length;for(k=0;k<g;){r=l[k++];
|
||||
var h="@"+r;if(n[h]){const b=n[h];if(b===v){if(q){if(f[p++]=r,a&&p===a)return f}else n[h]=v+1;w=!0}else c&&(h=e[b]||(e[b]=[]),h[h.length]=r)}}if(!w&&!c)break}if(c&&(p=f.length,(v=e.length)&&(!a||p<a)))for(;v--;)if(r=e[v])for(k=0,g=r.length;k<g;k++)if(f[p++]=r[k],a&&p===a)return f}else d&&(f=b[0],a&&f.length>a&&(f=f.slice(0,a)));return f}function B(b){return"string"===typeof b}function C(b){return"function"===typeof b}function t(b){return"undefined"===typeof b}function G(b){const a=Array(b);for(let c=
|
||||
0;c<b;c++)a[c]=u();return a}function u(){return Object.create(null)}const x={encode:"icase",a:"forward",l:!1,cache:!1,async:!1,u:!1,o:!1,threshold:0,depth:0},H={memory:{encode:"extra",a:"strict",threshold:7},speed:{encode:"icase",a:"strict",threshold:7,depth:2},match:{encode:"extra",a:"full"},score:{encode:"extra",a:"strict",threshold:5,depth:4},balance:{encode:"balance",a:"strict",threshold:6,depth:3},fastest:{encode:"icase",a:"strict",threshold:9,depth:1}},D=[];let L=0;const I=d("\\W+"),J={},K=
|
||||
{};g.create=function(b){return new g(b)};g.registerMatcher=function(b){for(const a in b)b.hasOwnProperty(a)&&D.push(d(a),b[a]);return this};g.registerEncoder=function(b,a){z[b]=a.bind(z);return this};g.registerLanguage=function(b,a){J[b]=a.filter;K[b]=a.stemmer;return this};g.encode=function(b,a){return z[b](a)};g.prototype.init=function(b){this.i=[];b||(b=x);var a=b.preset,c={};B(b)?(c=H[b],b={}):a&&(c=H[a]);this.a=b.tokenize||c.a||this.a||x.a;this.o=b.rtl||this.o||x.o;this.async="undefined"===typeof Promise||
|
||||
t(a=b.async)?this.async||x.async:a;this.threshold=t(a=b.threshold)?c.threshold||this.threshold||x.threshold:a;this.depth=t(a=b.depth)?c.depth||this.depth||x.depth:a;this.l=t(a=b.suggest)?this.l||x.l:a;this.j=(a=t(a=b.encode)?c.encode:a)&&z[a]&&z[a].bind(z)||(C(a)?a:this.j||!1);(a=b.matcher)&&this.addMatcher(a);if(a=b.filter){a=J[a]||a;c=this.j;var f=u();if(a)for(var e=0;e<a.length;e++){var n=c?c(a[e]):a[e];f[n]=String.fromCharCode(65E3-a.length+e)}this.filter=a=f}if(a=b.stemmer){var h;c=K[a]||a;f=
|
||||
this.j;e=[];if(c)for(h in c)c.hasOwnProperty(h)&&(n=f?f(h):h,e.push(d("(?=.{"+(n.length+3)+",})"+n+"$"),f?f(c[h]):c[h]));this.stemmer=h=e}this.c=G(10-(this.threshold||0));this.f=u();this.b=u();this.m=!0;this.h=(this.cache=a=t(a=b.cache)?this.cache||x.cache:a)?new P(a):!1;return this};g.prototype.encode=function(b){b&&D.length&&(b=m(b,D));b&&this.i.length&&(b=m(b,this.i));b&&this.j&&(b=this.j(b));b&&this.stemmer&&(b=m(b,this.stemmer));return b};g.prototype.addMatcher=function(b){const a=this.i;for(const c in b)b.hasOwnProperty(c)&&
|
||||
a.push(d(c),b[c]);return this};g.prototype.add=function(b,a,c,f,e){if(a&&B(a)&&(b||0===b)){var d="@"+b;if(this.b[d]&&!f)return this.update(b,a);if(!e){if(this.async&&"function"!==typeof importScripts){let e=this;d=new Promise(function(c){setTimeout(function(){e.add(b,a,null,f,!0);e=null;c()})});if(c)d.then(c);else return d;return this}if(c)return this.add(b,a,null,f,!0),c(),this}a=this.encode(a);if(!a.length)return this;c=this.a;e=C(c)?c(a):a.split(I);const n=u();n._ctx=u();const p=this.threshold,
|
||||
v=this.depth,m=this.c,w=e.length,t=this.o;for(let a=0;a<w;a++){var h=e[a];if(h){var g=h.length,l=(t?a+1:w-a)/w,q="";switch(c){case "reverse":case "both":for(var k=g;--k;)q=h[k]+q,A(m,n,q,b,t?1:(g-k)/g,l,p);q="";case "forward":for(k=0;k<g;k++)q+=h[k],A(m,n,q,b,t?(k+1)/g:1,l,p);break;case "full":for(k=0;k<g;k++){const a=(t?k+1:g-k)/g;for(let c=g;c>k;c--)q=h.substring(k,c),A(m,n,q,b,a,l,p)}break;default:if(g=A(m,n,h,b,1,l,p),v&&1<w&&g>=p)for(g=n._ctx[h]||(n._ctx[h]=u()),h=this.f[h]||(this.f[h]=G(10-
|
||||
(p||0))),l=a-v,q=a+v+1,0>l&&(l=0),q>w&&(q=w);l<q;l++)l!==a&&A(h,g,e[l],b,0,10-(l<a?a-l:l-a),p)}}}this.b[d]=1;this.m=!1}return this};g.prototype.update=function(b,a,c){this.b["@"+b]&&B(a)&&(this.remove(b),this.add(b,a,c,!0));return this};g.prototype.remove=function(b,a,c){var f="@"+b;if(this.b[f]){if(!c){if(this.async&&"function"!==typeof importScripts){let c=this;f=new Promise(function(a){setTimeout(function(){c.remove(b,null,!0);c=null;a()})});if(a)f.then(a);else return f;return this}if(a)return this.remove(b,
|
||||
null,!0),a(),this}for(a=0;a<10-(this.threshold||0);a++)E(this.c[a],b);this.depth&&E(this.f,b);delete this.b[f];this.m=!1}return this};g.prototype.search=function(b,a,c,f){let e=b,d,h=[];"object"===typeof b&&((c=b.callback||a)&&(e.callback=null),a=b.limit,d=b.threshold,b=b.query);d||(d=this.threshold||0);C(a)?(c=a,a=1E3):a||0===a||(a=1E3);if(!f){if(this.async&&"function"!==typeof importScripts){let d=this;b=new Promise(function(b){setTimeout(function(){b(d.search(e,a,null,!0));d=null})});if(c)b.then(c);
|
||||
else return b;return this}if(c)return c(this.search(e,a,null,!0)),this}if(!b||!B(b))return h;e=b;if(this.cache)if(this.m){if(c=this.h.get(b))return c}else this.h.clear(),this.m=!0;e=this.encode(e);if(!e.length)return h;c=this.a;c=C(c)?c(e):e.split(I);f=c.length;let g=!0;const l=[],m=u();let k;if(1<f)if(this.depth){k=!0;var r=c[0];m[r]=1}else c.sort(M);let p;if(!k||(p=this.f)[r])for(let a=k?1:0;a<f;a++){const b=c[a];if(b){if(!m[b]){const a=[];let c=!1,f=0;if(r=k?p[r]:this.c){let e;for(let h=0;h<10-
|
||||
d;h++)if(e=r[h][b])a[f++]=e,c=!0}if(c)l[l.length]=1<f?a.concat.apply([],a):a[0];else if(!this.l){g=!1;break}m[b]=1}r=b}}else g=!1;g&&(h=O(l,a,this.l));this.cache&&this.h.set(b,h);return h};g.prototype.info=function(){let b;let a=0,c=0,d=0;for(var e=0;e<10-(this.threshold||0);e++){b=Object.keys(this.c[e]);for(let f=0;f<b.length;f++){var g=this.c[e][b[f]].length;a+=1*g+2*b[f].length+4;c+=g;d+=2*b[f].length}}b=Object.keys(this.b);g=b.length;for(e=0;e<g;e++)a+=2*b[e].length+2;return{id:this.id,memory:a,
|
||||
items:g,sequences:c,chars:d,cache:this.cache&&this.cache.g?this.cache.g.length:!1,matcher:D.length+(this.i?this.i.length:0),worker:this.u,threshold:this.threshold,depth:this.depth,contextual:this.depth&&"strict"===this.a}};g.prototype.clear=function(){return this.destroy().init()};g.prototype.destroy=function(){this.cache&&(this.h.clear(),this.h=null);this.c=this.f=this.b=null;return this};g.prototype.export=function(){return JSON.stringify([this.c,this.f,this.b])};g.prototype.import=function(b){b=
|
||||
JSON.parse(b);this.c=b[0];this.f=b[1];this.b=b[2]};const z={icase:function(b){return b.toLowerCase()},simple:function(){const b=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(a){a=
|
||||
m(a.toLowerCase(),b);return" "===a?"":a}}(),advanced:function(){const b=[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(a,c){if(!a)return a;a=this.simple(a);2<a.length&&(a=m(a,b));c||1<a.length&&(a=F(a));return a}}(),extra:function(){const b=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),
|
||||
""];return function(a){if(!a)return a;a=this.advanced(a,!0);if(1<a.length){a=a.split(" ");for(let c=0;c<a.length;c++){const d=a[c];1<d.length&&(a[c]=d[0]+m(d.substring(1),b))}a=a.join(" ");a=F(a)}return a}}(),balance:function(){const b=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(a){return F(m(a.toLowerCase(),b))}}()},P=function(){function b(a){this.clear();this.s=!0!==a&&a}b.prototype.clear=function(){this.cache=u();this.count=u();this.index=u();this.g=[]};b.prototype.set=function(a,
|
||||
b){if(this.s&&t(this.cache[a])){let c=this.g.length;if(c===this.s){c--;const a=this.g[c];delete this.cache[a];delete this.count[a];delete this.index[a]}this.index[a]=c;this.g[c]=a;this.count[a]=-1;this.cache[a]=b;this.get(a)}else this.cache[a]=b};b.prototype.get=function(a){const b=this.cache[a];if(this.s&&b){var d=++this.count[a];const b=this.index;let c=b[a];if(0<c){const f=this.g;for(var e=c;this.count[f[--c]]<=d&&-1!==c;);c++;if(c!==e){for(d=e;d>c;d--)e=f[d-1],f[d]=e,b[e]=d;f[c]=a;b[a]=c}}}return b};
|
||||
return b}();return g}(!1),this);
|
||||
'use strict';(function(h,w,d){let p;(p=d.define)&&p.amd?p([],function(){return w}):(p=d.modules)?p[h.toLowerCase()]=w:"object"===typeof exports?module.exports=w:d[h]=w})("FlexSearch",function(){function h(a,b){const c=b?b.id:a&&a.id;this.id=c||0===c?c:N++;this.init(a,b);w(this,"index",function(){return this.b});w(this,"length",function(){return Object.keys(this.b).length})}function w(a,b,c){Object.defineProperty(a,b,{get:c})}function d(a){return new RegExp(a,"g")}function p(a,b){for(let c=0;c<b.length;c+=
|
||||
2)a=a.replace(b[c],b[c+1]);return a}function C(a,b,c,f,e,l,g){if(b[c])return b[c];e=e?(9-(g||6))*l+(g||6)*e:l;b[c]=e;e>=g&&(a=a[9-(e+.5>>0)],a=a[c]||(a[c]=[]),a[a.length]=f);return e}function G(a,b){if(a){const c=Object.keys(a);for(let f=0,e=c.length;f<e;f++){const e=c[f],g=a[e];if(g)for(let c=0,f=g.length;c<f;c++)if(g[c]===b){1===f?delete a[e]:g.splice(c,1);break}else x(g[c])&&G(g[c],b)}}}function H(a){let b="",c="";var f="";for(let e=0;e<a.length;e++){const l=a[e];if(l!==c)if(e&&"h"===l){if(f="a"===
|
||||
f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f,("a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c)&&f||" "===c)b+=l}else b+=l;f=e===a.length-1?"":a[e+1];c=l}return b}function O(a,b){a=a.length-b.length;return 0>a?1:a?-1:0}function P(a,b){a=a.length-b.length;return 0>a?-1:a?1:0}function Q(a,b,c,f){let e=[],l;const g=a.length;if(1<g){a.sort(P);const n=u();let k=a[0],r=k.length,q=0;for(;q<r;)n["@"+k[q++]]=1;let m,h=0,v=0;for(;++v<g;){let y=!1;const p=v===g-1;l=[];k=a[v];r=k.length;for(q=0;q<r;){m=
|
||||
k[q++];var d="@"+m;if(n[d]){const a=n[d];if(a===v){if(p){if(e[h++]=c?c[d]:m,b&&h===b)return e}else n[d]=v+1;y=!0}else f&&(d=l[a]||(l[a]=[]),d[d.length]=m)}}if(!y&&!f)break}if(f&&(h=e.length,(v=l.length)&&(!b||h<b)))for(;v--;)if(m=l[v])for(q=0,r=m.length;q<r;q++)if(e[h++]=c?c["@"+m[q]]:m[q],b&&h===b)return e}else if(g)if(c)for(a=a[0],f=a.length,b&&b<f&&(f=b),e=Array(f),b=0;b<f;b++)e[b]=c["@"+a[b]];else e=a[0],b&&e.length>b&&(e=e.slice(0,b));return e}function D(a){return"string"===typeof a}function E(a){return"function"===
|
||||
typeof a}function x(a){return"object"===typeof a}function z(a){return"undefined"===typeof a}function I(a){const b=Array(a);for(let c=0;c<a;c++)b[c]=u();return b}function u(){return Object.create(null)}const t={encode:"icase",c:"forward",s:!1,cache:!1,async:!1,A:!1,v:!1,threshold:0,depth:0,a:!1},J={memory:{encode:"extra",c:"strict",threshold:7},speed:{encode:"icase",c:"strict",threshold:7,depth:2},match:{encode:"extra",c:"full"},score:{encode:"extra",c:"strict",threshold:5,depth:4},balance:{encode:"balance",
|
||||
c:"strict",threshold:6,depth:3},fastest:{encode:"icase",c:"strict",threshold:9,depth:1}},F=[];let N=0;const K=d("\\W+"),L={},M={};h.create=function(a){return new h(a)};h.registerMatcher=function(a){for(const b in a)a.hasOwnProperty(b)&&F.push(d(b),a[b]);return this};h.registerEncoder=function(a,b){B[a]=b.bind(B);return this};h.registerLanguage=function(a,b){L[a]=b.filter;M[a]=b.stemmer;return this};h.encode=function(a,b){return B[a](b)};h.prototype.init=function(a,b){this.l=[];if(b){var c=b.preset;
|
||||
a=b}else a||(a=t),c=a.preset;b={};D(a)?(b=J[a],a={}):c&&(b=J[c]);this.c=a.tokenize||b.c||this.c||t.c;this.v=a.rtl||this.v||t.v;this.async="undefined"===typeof Promise||z(c=a.async)?this.async||t.async:c;this.threshold=z(c=a.threshold)?b.threshold||this.threshold||t.threshold:c;this.depth=z(c=a.depth)?b.depth||this.depth||t.depth:c;this.s=z(c=a.suggest)?this.s||t.s:c;this.m=(c=z(c=a.encode)?b.encode||t.encode:c)&&B[c]&&B[c].bind(B)||(E(c)?c:this.m||!1);(c=a.matcher)&&this.addMatcher(c);if(c=a.filter){c=
|
||||
L[c]||c;b=this.m;var f=u();if(c)for(var e=0;e<c.length;e++){var l=b?b(c[e]):c[e];f[l]=String.fromCharCode(65E3-c.length+e)}this.filter=c=f}if(c=a.stemmer){var g;b=M[c]||c;f=this.m;e=[];if(b)for(g in b)b.hasOwnProperty(g)&&(l=f?f(g):g,e.push(d("(?=.{"+(l.length+3)+",})"+l+"$"),f?f(b[g]):b[g]));this.stemmer=g=e}this.a=e=(c=a.doc)?c:this.a||t.a;this.g=I(10-(this.threshold||0));this.h=u();this.b=u();this.f=e&&u();if(e)if(a.doc=null,g=e.field,b=e.index=[],f=e.ref={},e.id=e.id.split(":"),g.constructor===
|
||||
Array)for(e=0;e<g.length;e++)f[g[e]]=e,g[e]=g[e].split(":"),b[e]=new h(a),b[e].f=this.f;else f[g]=0,e.field=[g.split(":")],b[0]=new h(a),b[0].f=this.f;this.u=!0;this.j=(this.cache=c=z(c=a.cache)?this.cache||t.cache:c)?new R(c):!1;return this};h.prototype.encode=function(a){a&&F.length&&(a=p(a,F));a&&this.l.length&&(a=p(a,this.l));a&&this.m&&(a=this.m(a));a&&this.stemmer&&(a=p(a,this.stemmer));return a};h.prototype.addMatcher=function(a){const b=this.l;for(const c in a)a.hasOwnProperty(c)&&b.push(d(c),
|
||||
a[c]);return this};h.prototype.add=function(a,b,c,f,e){if(this.a&&x(a))return this.o("add",a,b);if(b&&D(b)&&(a||0===a)){var l="@"+a;if(this.b[l]&&!f)return this.update(a,b);if(!e){if(this.async&&"function"!==typeof importScripts){let e=this;l=new Promise(function(c){setTimeout(function(){e.add(a,b,null,f,!0);e=null;c()})});if(c)l.then(c);else return l;return this}if(c)return this.add(a,b,null,f,!0),c(),this}b=this.encode(b);if(!b.length)return this;c=this.c;e=E(c)?c(b):b.split(K);const r=u();r._ctx=
|
||||
u();const m=this.threshold,p=this.depth,v=this.g,A=e.length,y=this.v;for(let b=0;b<A;b++){var g=e[b];if(g){var d=g.length,n=(y?b+1:A-b)/A,k="";switch(c){case "reverse":case "both":for(var h=d;--h;)k=g[h]+k,C(v,r,k,a,y?1:(d-h)/d,n,m);k="";case "forward":for(h=0;h<d;h++)k+=g[h],C(v,r,k,a,y?(h+1)/d:1,n,m);break;case "full":for(h=0;h<d;h++){const b=(y?h+1:d-h)/d;for(let c=d;c>h;c--)k=g.substring(h,c),C(v,r,k,a,b,n,m)}break;default:if(d=C(v,r,g,a,1,n,m),p&&1<A&&d>=m)for(d=r._ctx[g]||(r._ctx[g]=u()),g=
|
||||
this.h[g]||(this.h[g]=I(10-(m||0))),n=b-p,k=b+p+1,0>n&&(n=0),k>A&&(k=A);n<k;n++)n!==b&&C(g,d,e[n],a,0,10-(n<b?b-n:n-b),m)}}}this.b[l]=1;this.u=!1}return this};h.prototype.o=function(a,b,c){if(b.constructor===Array)for(let e=0,f=b.length;e<f;e++){if(e===f-1)return this.o(a,b[e],c);this.o(a,b[e])}else{const d=this.a.index;let g=this.a.id,h;for(var f=0;f<g.length;f++)h=(h||b)[g[f]];if("remove"===a){delete this.f["@"+h];for(let a=0,b=d.length;a<b;a++){if(a===b-1)return d[a].remove(h,c);d[a].remove(h)}}g=
|
||||
this.a.field;for(let l=0,k=g.length;l<k;l++){f=g[l];let r;for(var e=0;e<f.length;e++)r=(r||b)[f[e]];this.f["@"+h]=b;f=d[l];e="add"===a?f.add:f.update;if(l===k-1)return e.call(f,h,r,c);e.call(f,h,r)}}};h.prototype.update=function(a,b,c){if(this.a&&x(a))return this.o("update",a,b);this.b["@"+a]&&D(b)&&(this.remove(a),this.add(a,b,c,!0));return this};h.prototype.remove=function(a,b,c){if(this.a&&x(a))return this.o("remove",a,b);var f="@"+a;if(this.b[f]){if(!c){if(this.async&&"function"!==typeof importScripts){let c=
|
||||
this;f=new Promise(function(b){setTimeout(function(){c.remove(a,null,!0);c=null;b()})});if(b)f.then(b);else return f;return this}if(b)return this.remove(a,null,!0),b(),this}for(b=0;b<10-(this.threshold||0);b++)G(this.g[b],a);this.depth&&G(this.h,a);delete this.b[f];this.u=!1}return this};h.prototype.search=function(a,b,c,f){if(x(b)){if(b.constructor===Array)for(var e=0;e<b.length;e++)b[e].query=a;else b.query=a;a=b;b=0}let d=a;let g=[];if(x(a)&&a.constructor!==Array){(c=a.callback||b)&&(d.callback=
|
||||
null);b=a.limit;var h=a.threshold;var n=a.boost;a=a.query}if(this.a){a=this.a.ref;h=this.a.index;var k=d.field;if(k)d.field=null;else if(d.constructor===Array){var p=d;k=[];for(var q=0;q<d.length;q++)k[q]=d[q].field}else k=Object.keys(a);if(x(k)){k.constructor===Array||(k=[k]);q=k.length;for(var m=0;m<q;m++)p&&(d=p[m]),g[m]=h[a[k[m]]].search(d);return c?c(g.concat.apply([],g)):this.async?new Promise(function(a){Promise.all(g).then(function(b){a(b.concat.apply([],b))})}):g.concat.apply([],g)}return h[a[k]].search(d,
|
||||
c)}h||(h=this.threshold||0);E(b)?(c=b,b=1E3):b||0===b||(b=1E3);if(!f){if(this.async&&"function"!==typeof importScripts){let e=this;a=new Promise(function(a){setTimeout(function(){a(e.search(d,b,null,!0));e=null})});if(c)a.then(c);else return a;return this}if(c)return c(this.search(d,b,null,!0)),this}if(!a||!D(a))return g;d=a;if(this.cache)if(this.u){if(c=this.j.get(a))return c}else this.j.clear(),this.u=!0;d=this.encode(d);if(!d.length)return g;c=this.c;c=E(c)?c(d):d.split(K);p=c.length;f=!0;e=[];
|
||||
const t=u();1<p&&(this.depth?(k=!0,m=c[0],t[m]=1):c.sort(O));if(!k||(q=this.h)[m]){let a=0;n&&(h=(h||1)/n,0>n&&(a=h));for(n=k?1:0;n<p;n++){const b=c[n];if(b){if(!t[b]){const c=[];let d=!1,g=0;if(m=k?q[m]:this.g){let e;for(let f=a;f<10-h;f++)if(e=m[f][b])c[g++]=e,d=!0}if(d)e[e.length]=1<g?c.concat.apply([],c):c[0];else if(!this.s){f=!1;break}t[b]=1}m=b}}}else f=!1;f&&(g=Q(e,b,this.f,this.s));this.cache&&this.j.set(a,g);return g};h.prototype.info=function(){let a;let b=0,c=0,f=0;for(var e=0;e<10-(this.threshold||
|
||||
0);e++){a=Object.keys(this.g[e]);for(let g=0;g<a.length;g++){var d=this.g[e][a[g]].length;b+=1*d+2*a[g].length+4;c+=d;f+=2*a[g].length}}a=Object.keys(this.b);d=a.length;for(e=0;e<d;e++)b+=2*a[e].length+2;return{id:this.id,memory:b,items:d,sequences:c,chars:f,cache:this.cache&&this.cache.i?this.cache.i.length:!1,matcher:F.length+(this.l?this.l.length:0),worker:this.A,threshold:this.threshold,depth:this.depth,contextual:this.depth&&"strict"===this.c}};h.prototype.clear=function(){return this.destroy().init()};
|
||||
h.prototype.destroy=function(){this.cache&&(this.j.clear(),this.j=null);this.g=this.h=this.b=null;return this};h.prototype.export=function(){if(this.a){const a=this.a.index,b=Array(a.length+1);let c=0;for(;c<a.length;c++)b[c]=[a[c].g,a[c].h,a[c].b];b[c]=this.f;return JSON.stringify(b)}return JSON.stringify([this.g,this.h,this.b])};h.prototype.import=function(a){a=JSON.parse(a);if(this.a){const b=this.a.index,c=b.length;for(let d=0;d<c;d++){const e=b[d];e.g=a[d][0];e.h=a[d][1];e.b=a[d][2];e.f=a[c]}this.f=
|
||||
a[c]}else this.g=a[0],this.h=a[1],this.b=a[2],this.f=a[3]};const B={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(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(b){b=
|
||||
p(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=p(b,a));c||1<b.length&&(b=H(b));return b}}(),extra:function(){const a=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),
|
||||
""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(let c=0;c<b.length;c++){const d=b[c];1<d.length&&(b[c]=d[0]+p(d.substring(1),a))}b=b.join(" ");b=H(b)}return b}}(),balance:function(){const a=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s+")," "];return function(b){return H(p(b.toLowerCase(),a))}}()},R=function(){function a(a){this.clear();this.w=!0!==a&&a}a.prototype.clear=function(){this.cache=u();this.count=u();this.index=u();this.i=[]};a.prototype.set=function(a,
|
||||
c){if(this.w&&z(this.cache[a])){let b=this.i.length;if(b===this.w){b--;const a=this.i[b];delete this.cache[a];delete this.count[a];delete this.index[a]}this.index[a]=b;this.i[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.w&&b){var d=++this.count[a];const b=this.index;let c=b[a];if(0<c){const f=this.i;for(var e=c;this.count[f[--c]]<=d&&-1!==c;);c++;if(c!==e){for(d=e;d>c;d--)e=f[d-1],f[d]=e,b[e]=d;f[c]=a;b[a]=c}}}return b};
|
||||
return a}();return h}(!1),this);
|
||||
|
455
flexsearch.js
455
flexsearch.js
@@ -1,5 +1,5 @@
|
||||
/**!
|
||||
* @preserve FlexSearch v0.3.62
|
||||
* @preserve FlexSearch v0.4.0
|
||||
* Copyright 2019 Nextapps GmbH
|
||||
* Author: Thomas Wilkerling
|
||||
* Released under the Apache 2.0 Licence
|
||||
@@ -17,6 +17,7 @@
|
||||
/** @define {boolean} */ const SUPPORT_SUGGESTIONS = true;
|
||||
/** @define {boolean} */ const SUPPORT_SERIALIZE = true;
|
||||
/** @define {boolean} */ const SUPPORT_INFO = true;
|
||||
/** @define {boolean} */ const SUPPORT_DOCUMENTS = true;
|
||||
|
||||
// noinspection ThisExpressionReferencesGlobalObjectJS
|
||||
(function(){
|
||||
@@ -44,7 +45,10 @@
|
||||
threshold: 0,
|
||||
|
||||
// contextual depth
|
||||
depth: 0
|
||||
depth: 0,
|
||||
|
||||
// multi-field documents
|
||||
doc: false
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -152,10 +156,11 @@
|
||||
|
||||
/**
|
||||
* @param {string|Object<string, number|string|boolean|Object|function(string):string>=} options
|
||||
* @param {Object<string, number|string|boolean>=} settings
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
function FlexSearch(options){
|
||||
function FlexSearch(options, settings){
|
||||
|
||||
if(PROFILER){
|
||||
|
||||
@@ -165,28 +170,11 @@
|
||||
this.stats = profile;
|
||||
}
|
||||
|
||||
/*
|
||||
if(SUPPORT_PRESETS && is_string(options)){
|
||||
|
||||
options = presets[options];
|
||||
|
||||
if(DEBUG && !options){
|
||||
|
||||
console.warn("Preset not found: " + options);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//options || (options = defaults);
|
||||
|
||||
// generate UID
|
||||
const id = settings ? settings["id"] : options && options["id"];
|
||||
|
||||
/** @export */
|
||||
this.id = options && !is_undefined(options["id"]) ? options["id"] : id_counter++;
|
||||
|
||||
// initialize index
|
||||
|
||||
this.init(options);
|
||||
this.id = id || (id === 0) ? id : id_counter++;
|
||||
this.init(options, settings);
|
||||
|
||||
// define functional properties
|
||||
|
||||
@@ -274,14 +262,7 @@
|
||||
|
||||
FlexSearch.encode = function(name, value){
|
||||
|
||||
// if(index_blacklist[name]){
|
||||
//
|
||||
// return value;
|
||||
// }
|
||||
// else{
|
||||
|
||||
return global_encoder[name](value);
|
||||
// }
|
||||
return global_encoder[name](value);
|
||||
};
|
||||
|
||||
function worker_handler(id, query, result, limit){
|
||||
@@ -315,17 +296,28 @@
|
||||
|
||||
/**
|
||||
* @param {Object<string, number|string|boolean|Object|function(string):string>|string=} options
|
||||
* @param {Object<string, number|string|boolean>=} settings
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.prototype.init = function(options){
|
||||
FlexSearch.prototype.init = function(options, settings){
|
||||
|
||||
/** @type {Array} @private */
|
||||
this._matcher = [];
|
||||
|
||||
options || (options = defaults);
|
||||
let custom;
|
||||
|
||||
if(settings){
|
||||
|
||||
custom = /** @type {?string} */ (settings["preset"]);
|
||||
options = settings;
|
||||
}
|
||||
else{
|
||||
|
||||
options || (options = defaults);
|
||||
custom = /** @type {?string} */ (options["preset"]);
|
||||
}
|
||||
|
||||
let custom = /** @type {?string} */ (options["preset"]);
|
||||
let preset = {};
|
||||
|
||||
if(SUPPORT_PRESETS){
|
||||
@@ -467,7 +459,8 @@
|
||||
|
||||
custom = is_undefined(custom = options["encode"]) ?
|
||||
|
||||
preset.encode
|
||||
preset.encode ||
|
||||
defaults.encode
|
||||
:
|
||||
custom;
|
||||
|
||||
@@ -499,6 +492,17 @@
|
||||
this.stemmer = init_stemmer(stemmer[custom] || custom, this.encoder);
|
||||
}
|
||||
|
||||
let doc;
|
||||
|
||||
if(SUPPORT_DOCUMENTS) /** @private */ this.doc = doc = (
|
||||
|
||||
(custom = options["doc"]) ?
|
||||
|
||||
custom
|
||||
:
|
||||
this.doc || defaults.doc
|
||||
);
|
||||
|
||||
// initialize primary index
|
||||
|
||||
/** @private */
|
||||
@@ -507,11 +511,47 @@
|
||||
this._ctx = create_object();
|
||||
/** @private */
|
||||
this._ids = create_object();
|
||||
|
||||
if(SUPPORT_DOCUMENTS){
|
||||
|
||||
/** @private */
|
||||
this._doc = doc && create_object();
|
||||
}
|
||||
|
||||
/** @private */
|
||||
//this._stack = create_object();
|
||||
/** @private */
|
||||
//this._stack_keys = [];
|
||||
|
||||
if(doc){
|
||||
|
||||
options["doc"] = null;
|
||||
|
||||
const field = doc["field"];
|
||||
const index = doc["index"] = [];
|
||||
const ref = doc["ref"] = {};
|
||||
|
||||
doc["id"] = doc["id"].split(":");
|
||||
|
||||
if(is_array(field)){
|
||||
|
||||
for(let i = 0; i < field.length; i++){
|
||||
|
||||
ref[field[i]] = i;
|
||||
field[i] = field[i].split(":");
|
||||
index[i] = new FlexSearch(options);
|
||||
index[i]._doc = this._doc;
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
ref[field] = 0;
|
||||
doc["field"] = [field.split(":")];
|
||||
index[0] = new FlexSearch(options);
|
||||
index[0]._doc = this._doc;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {number|null}
|
||||
* @private
|
||||
@@ -638,7 +678,7 @@
|
||||
|
||||
/**
|
||||
* @param {number|string} id
|
||||
* @param {string} content
|
||||
* @param {string|Function} content
|
||||
* @param {Function=} callback
|
||||
* @param {boolean=} _skip_update
|
||||
* @param {boolean=} _recall
|
||||
@@ -648,6 +688,11 @@
|
||||
|
||||
FlexSearch.prototype.add = function(id, content, callback, _skip_update, _recall){
|
||||
|
||||
if(SUPPORT_DOCUMENTS && this.doc && is_object(id)){
|
||||
|
||||
return this.handle_docs("add", id, /** @type {Function} */ (content));
|
||||
}
|
||||
|
||||
if(content && is_string(content) && ((id /*&& !index_blacklist[id]*/) || (id === 0))){
|
||||
|
||||
// TODO: do not mix ids as string "1" and as number 1
|
||||
@@ -733,7 +778,7 @@
|
||||
profile_start("add");
|
||||
}
|
||||
|
||||
content = this.encode(content);
|
||||
content = this.encode(/** @type {string} */ (content));
|
||||
|
||||
if(!content.length){
|
||||
|
||||
@@ -919,15 +964,110 @@
|
||||
return this;
|
||||
};
|
||||
|
||||
if(SUPPORT_DOCUMENTS){
|
||||
|
||||
/**
|
||||
* @param {!string} job
|
||||
* @param docs
|
||||
* @param {Function=} callback
|
||||
* @returns {*}
|
||||
*/
|
||||
|
||||
FlexSearch.prototype.handle_docs = function(job, docs, callback){
|
||||
|
||||
if(is_array(docs)){
|
||||
|
||||
for(let i = 0, len = docs.length; i < len; i++){
|
||||
|
||||
if(i === len - 1){
|
||||
|
||||
return this.handle_docs(job, docs[i], callback);
|
||||
}
|
||||
else{
|
||||
|
||||
this.handle_docs(job, docs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
const index = this.doc["index"];
|
||||
let tree = this.doc["id"];
|
||||
let id;
|
||||
|
||||
for(let i = 0; i < tree.length; i++){
|
||||
|
||||
id = (id || docs)[tree[i]];
|
||||
}
|
||||
|
||||
if(job === "remove"){
|
||||
|
||||
delete this._doc["@" + id];
|
||||
|
||||
for(let z = 0, length = index.length; z < length; z++){
|
||||
|
||||
if(z === length - 1){
|
||||
|
||||
return index[z].remove(id, callback);
|
||||
}
|
||||
else{
|
||||
|
||||
index[z].remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tree = this.doc["field"];
|
||||
|
||||
for(let i = 0, len = tree.length; i < len; i++){
|
||||
|
||||
const branch = tree[i];
|
||||
let content;
|
||||
|
||||
for(let x = 0; x < branch.length; x++){
|
||||
|
||||
content = (content || docs)[branch[x]];
|
||||
}
|
||||
|
||||
this._doc["@" + id] = docs;
|
||||
|
||||
const self = index[i];
|
||||
const fn = (
|
||||
|
||||
job === "add" ?
|
||||
|
||||
self.add
|
||||
:
|
||||
self.update
|
||||
);
|
||||
|
||||
if(i === len - 1){
|
||||
|
||||
return fn.call(self, id, content, callback);
|
||||
}
|
||||
else{
|
||||
|
||||
fn.call(self, id, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number|string} id
|
||||
* @param {string} content
|
||||
* @param {string|Function} content
|
||||
* @param {Function=} callback
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.prototype.update = function(id, content, callback){
|
||||
|
||||
if(SUPPORT_DOCUMENTS && this.doc && is_object(id)){
|
||||
|
||||
return this.handle_docs("update", id, /** @type {Function} */ (content));
|
||||
}
|
||||
|
||||
const index = "@" + id;
|
||||
|
||||
if(this._ids[index] && is_string(content)){
|
||||
@@ -958,6 +1098,11 @@
|
||||
|
||||
FlexSearch.prototype.remove = function(id, callback, _recall){
|
||||
|
||||
if(SUPPORT_DOCUMENTS && this.doc && is_object(id)){
|
||||
|
||||
return this.handle_docs("remove", id, callback);
|
||||
}
|
||||
|
||||
const index = "@" + id;
|
||||
|
||||
if(this._ids[index]){
|
||||
@@ -1053,7 +1198,7 @@
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {!string} query
|
||||
* @param {!string|Object|Array<Object>} query
|
||||
* @param {number|Function=} limit
|
||||
* @param {Function=} callback
|
||||
* @param {boolean=} _recall
|
||||
@@ -1063,11 +1208,30 @@
|
||||
|
||||
FlexSearch.prototype.search = function(query, limit, callback, _recall){
|
||||
|
||||
if(SUPPORT_DOCUMENTS && is_object(limit)){
|
||||
|
||||
if(is_array(limit)){
|
||||
|
||||
for(let i = 0; i < limit.length; i++){
|
||||
|
||||
limit[i]["query"] = query;
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
limit["query"] = query;
|
||||
}
|
||||
|
||||
query = /** @type {Object} */ (limit);
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
let _query = query;
|
||||
let threshold;
|
||||
let boost;
|
||||
let result = [];
|
||||
|
||||
if(is_object(query)){
|
||||
if(is_object(query) && (!SUPPORT_DOCUMENTS || !is_array(query))){
|
||||
|
||||
// re-assign properties
|
||||
|
||||
@@ -1083,15 +1247,86 @@
|
||||
|
||||
limit = query["limit"];
|
||||
threshold = query["threshold"];
|
||||
boost = query["boost"];
|
||||
query = query["query"];
|
||||
}
|
||||
|
||||
/*
|
||||
if(index_blacklist[query]){
|
||||
if(SUPPORT_DOCUMENTS && this.doc){
|
||||
|
||||
return result;
|
||||
const doc_ref = this.doc["ref"];
|
||||
const doc_idx = this.doc["index"];
|
||||
|
||||
let queries;
|
||||
let field = _query["field"];
|
||||
|
||||
if(field){
|
||||
|
||||
_query["field"] = null;
|
||||
}
|
||||
else if(is_array(_query)){
|
||||
|
||||
queries = _query;
|
||||
field = [];
|
||||
|
||||
for(let i = 0; i < _query.length; i++){
|
||||
|
||||
field[i] = _query[i]["field"];
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
field = get_keys(doc_ref);
|
||||
}
|
||||
|
||||
if(is_object(field)){
|
||||
|
||||
if(!is_array(field)){
|
||||
|
||||
field = [field];
|
||||
}
|
||||
|
||||
const len = field.length;
|
||||
|
||||
for(let i = 0; i < len; i++){
|
||||
|
||||
if(queries){
|
||||
|
||||
_query = queries[i];
|
||||
}
|
||||
|
||||
const ref = doc_ref[field[i]];
|
||||
|
||||
// TODO: Support Field-Merging (return array before intersection and apply here)
|
||||
|
||||
result[i] = doc_idx[ref].search(_query);
|
||||
}
|
||||
|
||||
if(SUPPORT_ASYNC && callback){
|
||||
|
||||
return callback(result.concat.apply([], result));
|
||||
}
|
||||
else if(SUPPORT_ASYNC && this.async){
|
||||
|
||||
return new Promise(function(resolve){
|
||||
|
||||
Promise.all(/** @type {!Iterable<Promise>} */ (result)).then(function(values){
|
||||
|
||||
resolve(values.concat.apply([], values));
|
||||
});
|
||||
});
|
||||
}
|
||||
else{
|
||||
|
||||
return result.concat.apply([], result);
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
const ref = doc_ref[field];
|
||||
|
||||
return doc_idx[ref].search(_query, callback);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
threshold || (threshold = this.threshold || 0);
|
||||
|
||||
@@ -1215,6 +1450,7 @@
|
||||
|
||||
tokenizer(_query)
|
||||
:(
|
||||
// NOTE: ngram matches inconsistently, research or remove
|
||||
//SUPPORT_ENCODER && (tokenizer === "ngram") ?
|
||||
|
||||
/** @type {!Array<string>} */
|
||||
@@ -1238,7 +1474,7 @@
|
||||
if(this.depth){
|
||||
|
||||
use_contextual = true;
|
||||
ctx_root = words[0]; // TODO: iterate roots?
|
||||
ctx_root = words[0]; // TODO: iterate roots
|
||||
check_words[ctx_root] = 1;
|
||||
}
|
||||
else{
|
||||
@@ -1252,6 +1488,18 @@
|
||||
|
||||
if(!use_contextual || (ctx_map = this._ctx)[ctx_root]){
|
||||
|
||||
let initial_z = 0;
|
||||
|
||||
if(SUPPORT_DOCUMENTS && boost){
|
||||
|
||||
threshold = (threshold || 1) / boost;
|
||||
|
||||
if(boost < 0){
|
||||
|
||||
initial_z = threshold;
|
||||
}
|
||||
}
|
||||
|
||||
for(let a = (use_contextual ? 1 : 0); a < length; a++){
|
||||
|
||||
const value = words[a];
|
||||
@@ -1274,7 +1522,7 @@
|
||||
|
||||
let map_value;
|
||||
|
||||
for(let z = 0; z < (10 - threshold); z++){
|
||||
for(let z = initial_z; z < (10 - threshold); z++){
|
||||
|
||||
if((map_value = map[z][value])){
|
||||
|
||||
@@ -1324,7 +1572,7 @@
|
||||
|
||||
// Not handled by intersection:
|
||||
|
||||
result = intersect(check, limit, SUPPORT_SUGGESTIONS && this.suggest);
|
||||
result = intersect(check, limit, SUPPORT_DOCUMENTS && this._doc, SUPPORT_SUGGESTIONS && this.suggest);
|
||||
|
||||
// Handled by intersection:
|
||||
|
||||
@@ -1380,7 +1628,7 @@
|
||||
|
||||
length = this._map[z][keys[i]].length;
|
||||
|
||||
// Note: 1 char values allocates 1 byte "Map (OneByteInternalizedString)"
|
||||
// TODO: Proof if 1 char values allocates 1 byte "Map (OneByteInternalizedString)"
|
||||
bytes += length * 1 + keys[i].length * 2 + 4;
|
||||
words += length;
|
||||
chars += keys[i].length * 2;
|
||||
@@ -1419,8 +1667,6 @@
|
||||
|
||||
FlexSearch.prototype.clear = function(){
|
||||
|
||||
// destroy + initialize index
|
||||
|
||||
return this.destroy().init();
|
||||
};
|
||||
|
||||
@@ -1430,24 +1676,27 @@
|
||||
|
||||
FlexSearch.prototype.destroy = function(){
|
||||
|
||||
// cleanup cache
|
||||
|
||||
if(SUPPORT_CACHE && this.cache){
|
||||
|
||||
this._cache.clear();
|
||||
this._cache = null;
|
||||
}
|
||||
|
||||
// release references
|
||||
|
||||
//this.filter =
|
||||
//this.stemmer =
|
||||
//this._scores =
|
||||
this._map =
|
||||
this._ctx =
|
||||
this._ids =
|
||||
/*this._stack =
|
||||
this._stack_keys =*/ null;
|
||||
this._ids = null;
|
||||
|
||||
if(SUPPORT_DOCUMENTS && this.doc){
|
||||
|
||||
const index = this._doc["index"];
|
||||
|
||||
for(let i = 0; i < index.length; i++){
|
||||
|
||||
index.destroy();
|
||||
}
|
||||
|
||||
this._doc = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
@@ -1460,6 +1709,29 @@
|
||||
|
||||
FlexSearch.prototype.export = function(){
|
||||
|
||||
if(SUPPORT_DOCUMENTS && this.doc){
|
||||
|
||||
const index = this.doc["index"];
|
||||
const length = index.length;
|
||||
const payload = new Array(length + 1);
|
||||
|
||||
let i = 0;
|
||||
|
||||
for(; i < index.length; i++){
|
||||
|
||||
payload[i] = [
|
||||
|
||||
index[i]._map,
|
||||
index[i]._ctx,
|
||||
index[i]._ids
|
||||
];
|
||||
}
|
||||
|
||||
payload[i] = this._doc;
|
||||
|
||||
return JSON.stringify(payload);
|
||||
}
|
||||
|
||||
return JSON.stringify([
|
||||
|
||||
this._map,
|
||||
@@ -1476,9 +1748,30 @@
|
||||
|
||||
payload = JSON.parse(payload);
|
||||
|
||||
this._map = payload[0];
|
||||
this._ctx = payload[1];
|
||||
this._ids = payload[2];
|
||||
if(SUPPORT_DOCUMENTS && this.doc){
|
||||
|
||||
const index = this.doc["index"];
|
||||
const length = index.length;
|
||||
|
||||
for(let i = 0; i < length; i++){
|
||||
|
||||
const idx = index[i];
|
||||
|
||||
idx._map = payload[i][0];
|
||||
idx._ctx = payload[i][1];
|
||||
idx._ids = payload[i][2];
|
||||
idx._doc = payload[length];
|
||||
}
|
||||
|
||||
this._doc = payload[length];
|
||||
}
|
||||
else{
|
||||
|
||||
this._map = payload[0];
|
||||
this._ctx = payload[1];
|
||||
this._ids = payload[2];
|
||||
this._doc = payload[3];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2302,11 +2595,12 @@
|
||||
/**
|
||||
* @param {!Array<Array<number|string>>} arrays
|
||||
* @param {number=} limit
|
||||
* @param {Object=} docs
|
||||
* @param {boolean=} suggest
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
function intersect(arrays, limit, suggest) {
|
||||
function intersect(arrays, limit, docs, suggest) {
|
||||
|
||||
let result = [];
|
||||
let suggestions;
|
||||
@@ -2363,7 +2657,7 @@
|
||||
|
||||
if(is_final_loop){
|
||||
|
||||
result[count++] = tmp;
|
||||
result[count++] = docs ? docs[index] : tmp;
|
||||
|
||||
if(limit && (count === limit)){
|
||||
|
||||
@@ -2415,7 +2709,7 @@
|
||||
|
||||
for(i = 0, length = tmp.length; i < length; i++){
|
||||
|
||||
result[count++] = tmp[i];
|
||||
result[count++] = docs ? docs["@" + tmp[i]] : tmp[i];
|
||||
|
||||
if(limit && (count === limit)){
|
||||
|
||||
@@ -2429,13 +2723,33 @@
|
||||
}
|
||||
else if(length_z){
|
||||
|
||||
result = arrays[0];
|
||||
if(docs){
|
||||
|
||||
if(limit && /*result &&*/ (result.length > limit)){
|
||||
const arr = arrays[0];
|
||||
let length = arr.length;
|
||||
|
||||
// Note: do not modify the original index array!
|
||||
if(limit && (limit < length)){
|
||||
|
||||
result = result.slice(0, limit);
|
||||
length = limit;
|
||||
}
|
||||
|
||||
result = new Array(length);
|
||||
|
||||
for(let i = 0; i < length; i++){
|
||||
|
||||
result[i] = docs["@" + arr[i]];
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
result = arrays[0];
|
||||
|
||||
if(limit && /*result &&*/ (result.length > limit)){
|
||||
|
||||
// Note: do not modify the original index array!
|
||||
|
||||
result = result.slice(0, limit);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: handle references to the original index array
|
||||
@@ -2954,6 +3268,7 @@
|
||||
"var SUPPORT_ASYNC = " + (SUPPORT_ASYNC ? "true" : "false") + ";" +
|
||||
"var SUPPORT_SERIALIZE = " + (SUPPORT_SERIALIZE ? "true" : "false") + ";" +
|
||||
"var SUPPORT_INFO = " + (SUPPORT_INFO ? "true" : "false") + ";" +
|
||||
"var SUPPORT_DOCUMENTS = " + (SUPPORT_DOCUMENTS ? "true" : "false") + ";" +
|
||||
"var SUPPORT_WORKER = true;"
|
||||
|
||||
) + "(" + _worker.toString() + ")()"
|
||||
|
15
package.json
15
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flexsearch",
|
||||
"version": "0.3.62",
|
||||
"version": "0.4.0",
|
||||
"description": "Next-Generation full text search library with zero dependencies.",
|
||||
"homepage": "https://github.com/nextapps-de/flexsearch/",
|
||||
"author": "Thomas Wilkerling",
|
||||
@@ -26,12 +26,12 @@
|
||||
"url": "https://github.com/nextapps-de/flexsearch.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node compile RELEASE=min DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_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_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_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_SERIALIZE=false SUPPORT_INFO=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"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-node": "node compile RELEASE=node DEBUG=false PROFILER=false SUPPORT_WORKER=false 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": "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_DOCUMENTS=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_SERIALIZE=false SUPPORT_INFO=false SUPPORT_DOCUMENTS=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_DOCUMENTS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-custom": "node compile RELEASE=custom DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CACHE=false SUPPORT_ASYNC=false SUPPORT_PRESETS=false SUPPORT_SUGGESTIONS=false SUPPORT_SERIALIZE=false SUPPORT_INFO=false SUPPORT_DOCUMENTS=false SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"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_DOCUMENTS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false LANGUAGE_OUT=ECMASCRIPT5_STRICT",
|
||||
"build-node": "node compile RELEASE=node DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_PRESETS=true SUPPORT_SUGGESTIONS=true SUPPORT_SERIALIZE=true SUPPORT_INFO=true SUPPORT_DOCUMENTS=true SUPPORT_LANG_DE=false SUPPORT_LANG_EN=false",
|
||||
"build-lang": "node compile RELEASE=lang",
|
||||
"build-all": "npm run build && npm run build-light && npm run build-compact && npm run build-es5 && npm run build-node && npm run build-lang",
|
||||
"test-production": "nyc --reporter=html --reporter=text mocha --timeout=3000 test --exit",
|
||||
@@ -49,6 +49,7 @@
|
||||
"test/",
|
||||
"compile.js",
|
||||
"README.md",
|
||||
"CHANGELOG.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"readme": "README.md",
|
||||
|
353
test/test.es6.js
Normal file
353
test/test.es6.js
Normal file
@@ -0,0 +1,353 @@
|
||||
if(typeof module !== "undefined"){
|
||||
|
||||
var expect = require("chai").expect;
|
||||
}
|
||||
|
||||
module.exports = function(FlexSearch, env){
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Multi-Field Documents
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if(env === "") describe("Index Multi-Field Documents", function(){
|
||||
|
||||
var data = [{
|
||||
|
||||
data:{
|
||||
id: 0,
|
||||
title: "Title 1",
|
||||
body: "Body 1"
|
||||
}
|
||||
},{
|
||||
data:{
|
||||
id: 1,
|
||||
title: "Title 2",
|
||||
body: "Body 2"
|
||||
}
|
||||
},{
|
||||
data:{
|
||||
id: 2,
|
||||
title: "Title 3",
|
||||
body: "Body 3"
|
||||
}
|
||||
}];
|
||||
|
||||
var update = [{
|
||||
|
||||
data:{
|
||||
id: 0,
|
||||
title: "Foo 1",
|
||||
body: "Bar 1"
|
||||
}
|
||||
},{
|
||||
data:{
|
||||
id: 1,
|
||||
title: "Foo 2",
|
||||
body: "Bar 2"
|
||||
}
|
||||
},{
|
||||
data:{
|
||||
id: 2,
|
||||
title: "Foo 3",
|
||||
body: "Bar 3"
|
||||
}
|
||||
}];
|
||||
|
||||
it("Should have been indexed properly", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
|
||||
doc: {
|
||||
|
||||
id: "data:id",
|
||||
field: [
|
||||
"data:title",
|
||||
"data:body"
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
index.add(data);
|
||||
|
||||
expect(index.doc.index[0].length).to.equal(3);
|
||||
expect(index.doc.index[1].length).to.equal(3);
|
||||
|
||||
expect(index.search({field: "data:body", query: "body"})).to.have.members(data);
|
||||
expect(index.search({field: "data:title", query: "title"})).to.have.members(data);
|
||||
|
||||
expect(index.search({field: "data:body", query: "title"})).to.have.lengthOf(0);
|
||||
expect(index.search({field: "data:title", query: "body"})).to.have.lengthOf(0);
|
||||
|
||||
expect(index.search({field: ["data:title", "data:body"], query: "body"})).to.have.members(data);
|
||||
expect(index.search({field: ["data:body", "data:title"], query: "title"})).to.have.members(data);
|
||||
|
||||
expect(index.search({query: "body"})).to.have.members(data);
|
||||
expect(index.search("title")).to.have.members(data);
|
||||
|
||||
expect(index.search({
|
||||
|
||||
field: "data:title",
|
||||
query: "title",
|
||||
boost: 2
|
||||
|
||||
})).to.have.members(data);
|
||||
|
||||
expect(index.search([{
|
||||
|
||||
field: "data:title",
|
||||
query: "body",
|
||||
boost: 2
|
||||
},{
|
||||
field: "data:body",
|
||||
query: "body",
|
||||
boost: 2
|
||||
|
||||
}])).to.have.members(data);
|
||||
|
||||
expect(index.search("title", {
|
||||
|
||||
field: "data:title",
|
||||
boost: 2
|
||||
|
||||
})).to.have.members(data);
|
||||
|
||||
expect(index.search("title", {
|
||||
|
||||
field: "data:body",
|
||||
boost: 2
|
||||
|
||||
})).to.have.lengthOf(0);
|
||||
|
||||
expect(index.search("body", [{
|
||||
|
||||
field: "data:title",
|
||||
boost: 2
|
||||
},{
|
||||
field: "data:body",
|
||||
boost: 2
|
||||
|
||||
}])).to.have.members(data);
|
||||
|
||||
index.update(update);
|
||||
|
||||
expect(index.search("foo")).not.to.have.members(data);
|
||||
expect(index.search("bar")).not.to.have.members(data);
|
||||
expect(index.search("foo")).to.have.members(update);
|
||||
expect(index.search("bar")).to.have.members(update);
|
||||
|
||||
index.remove(update);
|
||||
|
||||
expect(index.doc.index[0].length).to.equal(0);
|
||||
expect(index.doc.index[1].length).to.equal(0);
|
||||
});
|
||||
|
||||
it("Should have been boosted properly", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
|
||||
tokenize: "strict",
|
||||
depth: 3,
|
||||
doc: {
|
||||
id: "id",
|
||||
field: ["title", "body"]
|
||||
}
|
||||
});
|
||||
|
||||
index.add([{
|
||||
|
||||
id: 0,
|
||||
title: "1 2 3 4 5",
|
||||
body: "1 2 3 4 5"
|
||||
},{
|
||||
id: 1,
|
||||
title: "1 2 3 4 5",
|
||||
body: "1 2 5 4 3" // <-- body
|
||||
},{
|
||||
id: 2,
|
||||
title: "1 2 5 4 3", // <-- title
|
||||
body: "1 2 3 4 5"
|
||||
}]);
|
||||
|
||||
expect(index.search([{
|
||||
|
||||
field: "title",
|
||||
query: "5",
|
||||
boost: 0.1
|
||||
},{
|
||||
field: "body",
|
||||
query: "5",
|
||||
boost: 9
|
||||
|
||||
}])[0].id).to.equal(1);
|
||||
|
||||
expect(index.search([{
|
||||
|
||||
field: "title",
|
||||
query: "5",
|
||||
boost: 9
|
||||
},{
|
||||
field: "body",
|
||||
query: "5",
|
||||
boost: 0.1
|
||||
|
||||
}])[0].id).to.equal(2);
|
||||
});
|
||||
|
||||
it("Should have been indexed properly (Async)", async function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
|
||||
async: true,
|
||||
doc: {
|
||||
|
||||
id: "data:id",
|
||||
field: [
|
||||
"data:title",
|
||||
"data:body"
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
await index.add(data);
|
||||
|
||||
expect(index.doc.index[0].length).to.equal(3);
|
||||
expect(index.doc.index[1].length).to.equal(3);
|
||||
|
||||
expect(await index.search({field: "data:body", query: "body"})).to.have.members(data);
|
||||
expect(await index.search({field: "data:title", query: "title"})).to.have.members(data);
|
||||
|
||||
expect(await index.search({field: "data:body", query: "title"})).to.have.lengthOf(0);
|
||||
expect(await index.search({field: "data:title", query: "body"})).to.have.lengthOf(0);
|
||||
|
||||
expect(await index.search({field: ["data:title", "data:body"], query: "body"})).to.have.members(data);
|
||||
expect(await index.search({field: ["data:body", "data:title"], query: "title"})).to.have.members(data);
|
||||
|
||||
expect(await index.search({query: "body"})).to.have.members(data);
|
||||
expect(await index.search("title")).to.have.members(data);
|
||||
|
||||
await index.update(update);
|
||||
|
||||
expect(await index.search("foo")).not.to.have.members(data);
|
||||
expect(await index.search("bar")).not.to.have.members(data);
|
||||
expect(await index.search("foo")).to.have.members(update);
|
||||
expect(await index.search("bar")).to.have.members(update);
|
||||
|
||||
await index.remove(update);
|
||||
|
||||
expect(await index.doc.index[0].length).to.equal(0);
|
||||
expect(await index.doc.index[1].length).to.equal(0);
|
||||
});
|
||||
|
||||
it("Should have been indexed properly (Worker)", async function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
|
||||
worker: 4,
|
||||
async: true,
|
||||
doc: {
|
||||
|
||||
id: "data:id",
|
||||
field: [
|
||||
"data:title",
|
||||
"data:body"
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
await index.add(data);
|
||||
|
||||
expect(index.doc.index[0].length).to.equal(3);
|
||||
expect(index.doc.index[1].length).to.equal(3);
|
||||
|
||||
expect(await index.search({field: "data:body", query: "body"})).to.have.members(data);
|
||||
expect(await index.search({field: "data:title", query: "title"})).to.have.members(data);
|
||||
|
||||
expect(await index.search({field: "data:body", query: "title"})).to.have.lengthOf(0);
|
||||
expect(await index.search({field: "data:title", query: "body"})).to.have.lengthOf(0);
|
||||
|
||||
expect(await index.search({field: ["data:title", "data:body"], query: "body"})).to.have.members(data);
|
||||
expect(await index.search({field: ["data:body", "data:title"], query: "title"})).to.have.members(data);
|
||||
|
||||
expect(await index.search({query: "body"})).to.have.members(data);
|
||||
expect(await index.search("title")).to.have.members(data);
|
||||
|
||||
await index.update(update);
|
||||
|
||||
expect(await index.search("foo")).not.to.have.members(data);
|
||||
expect(await index.search("bar")).not.to.have.members(data);
|
||||
expect(await index.search("foo")).to.have.members(update);
|
||||
expect(await index.search("bar")).to.have.members(update);
|
||||
|
||||
await index.remove(update);
|
||||
|
||||
expect(await index.doc.index[0].length).to.equal(0);
|
||||
expect(await index.doc.index[1].length).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Export / Import
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if(env !== "light") describe("Export / Import", function(){
|
||||
|
||||
var data;
|
||||
|
||||
it("Should have been exported properly", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
tokenize: "reverse",
|
||||
doc: {
|
||||
id: "id",
|
||||
field: "title"
|
||||
}
|
||||
});
|
||||
|
||||
index.add({id: 0, title: "foo"});
|
||||
index.add({id: 1, title: "bar"});
|
||||
index.add({id: 2, title: "foobar"});
|
||||
|
||||
if(env === ""){
|
||||
|
||||
expect(index.doc.index[0].length).to.equal(3);
|
||||
|
||||
data = index.export();
|
||||
|
||||
expect(data).to.equal(JSON.stringify([
|
||||
[
|
||||
index.doc.index[0]._map,
|
||||
index.doc.index[0]._ctx,
|
||||
index.doc.index[0]._ids
|
||||
],
|
||||
index._doc
|
||||
]));
|
||||
}
|
||||
else{
|
||||
|
||||
data = index.export();
|
||||
}
|
||||
});
|
||||
|
||||
it("Should have been imported properly", function(){
|
||||
|
||||
var index = new FlexSearch("score", {
|
||||
doc: {
|
||||
id: "id",
|
||||
field: "title"
|
||||
}
|
||||
});
|
||||
|
||||
index.import(data);
|
||||
|
||||
if(env === ""){
|
||||
|
||||
expect(index.doc.index[0].length).to.equal(3);
|
||||
}
|
||||
|
||||
expect(index.search("foo")).to.have.lengthOf(2);
|
||||
expect(index.search("bar")).to.have.lengthOf(2);
|
||||
expect(index.search("foobar")).to.have.lengthOf(1);
|
||||
expect(index.search("foobar")[0].id).to.equal(2);
|
||||
});
|
||||
});
|
||||
};
|
112
test/test.js
112
test/test.js
@@ -1077,32 +1077,104 @@ describe("Relevance", function(){
|
||||
// Suggestion Tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if(env !== "light"){
|
||||
if(env !== "light") describe("Suggestion", function(){
|
||||
|
||||
describe("Suggestion", function(){
|
||||
it("Should have been suggested properly by relevance", function(){
|
||||
|
||||
it("Should have been suggested properly by relevance", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
encode: "advanced",
|
||||
tokenize: "strict",
|
||||
suggest: true
|
||||
});
|
||||
|
||||
index.add(0, "1 2 3 2 4 1 5 3");
|
||||
index.add(1, "zero one two three four five six seven eight nine ten");
|
||||
index.add(2, "four two zero one three ten five seven eight six nine");
|
||||
|
||||
expect(index.search("1 3 4 7")).to.have.members([0]);
|
||||
expect(index.search("1 3 9 7")).to.have.members([0]);
|
||||
expect(index.search("one foobar two")).to.have.members([1, 2]);
|
||||
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
|
||||
//TODO
|
||||
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
|
||||
var index = new FlexSearch({
|
||||
encode: "advanced",
|
||||
tokenize: "strict",
|
||||
suggest: true
|
||||
});
|
||||
|
||||
index.add(0, "1 2 3 2 4 1 5 3");
|
||||
index.add(1, "zero one two three four five six seven eight nine ten");
|
||||
index.add(2, "four two zero one three ten five seven eight six nine");
|
||||
|
||||
expect(index.search("1 3 4 7")).to.have.members([0]);
|
||||
expect(index.search("1 3 9 7")).to.have.members([0]);
|
||||
expect(index.search("one foobar two")).to.have.members([1, 2]);
|
||||
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
|
||||
//TODO
|
||||
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Multi-Field Documents
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if(!this._phantom){
|
||||
|
||||
require("./test.es6.js")(FlexSearch, env);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Export / Import
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if(env !== "light") describe("Export / Import", function(){
|
||||
|
||||
var data;
|
||||
|
||||
it("Should have been exported properly", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
tokenize: "reverse",
|
||||
doc: {
|
||||
id: "id",
|
||||
field: "title"
|
||||
}
|
||||
});
|
||||
|
||||
index.add({id: 0, title: "foo"});
|
||||
index.add({id: 1, title: "bar"});
|
||||
index.add({id: 2, title: "foobar"});
|
||||
|
||||
if(env === ""){
|
||||
|
||||
expect(index.doc.index[0].length).to.equal(3);
|
||||
|
||||
data = index.export();
|
||||
|
||||
expect(data).to.equal(JSON.stringify([
|
||||
[
|
||||
index.doc.index[0]._map,
|
||||
index.doc.index[0]._ctx,
|
||||
index.doc.index[0]._ids
|
||||
],
|
||||
index._doc
|
||||
]));
|
||||
}
|
||||
else{
|
||||
|
||||
data = index.export();
|
||||
}
|
||||
});
|
||||
|
||||
it("Should have been imported properly", function(){
|
||||
|
||||
var index = new FlexSearch("score", {
|
||||
doc: {
|
||||
id: "id",
|
||||
field: "title"
|
||||
}
|
||||
});
|
||||
|
||||
index.import(data);
|
||||
|
||||
if(env === ""){
|
||||
|
||||
expect(index.doc.index[0].length).to.equal(3);
|
||||
}
|
||||
|
||||
expect(index.search("foo")).to.have.lengthOf(2);
|
||||
expect(index.search("bar")).to.have.lengthOf(2);
|
||||
expect(index.search("foobar")).to.have.lengthOf(1);
|
||||
expect(index.search("foobar")[0].id).to.equal(2);
|
||||
});
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Feature Tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user