1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-01 01:51:57 +02:00
This commit is contained in:
Thomas Wilkerling
2019-01-28 17:46:58 +01:00
parent cdfe44c6fa
commit 91802edf8e
14 changed files with 1219 additions and 779 deletions

461
README.md
View File

@@ -13,10 +13,10 @@
</p>
<h1></h1>
<h3>World's fastest and most memory efficient full text search library with zero dependencies.</h3>
<h3>Web's fastest and most memory-flexible full-text search library with zero dependencies.</h3>
When it comes to raw search speed <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark.html" target="_blank">FlexSearch outperforms every single searching library out there</a> and also provides flexible search capabilities like multi-word matching, phonetic transformations or partial matching.
It also has the <a href="#memory">most memory-efficient index</a>. Keep in mind that updating and/or removing existing items from the index has a significant cost. When your index needs to be updated continuously then <a href="bulksearch/" target="_blank">BulkSearch</a> may be a better choice.
Depending on the used options it also providing the <a href="#memory">most memory-efficient index</a>. Keep in mind that updating and/or removing existing items from the index has a significant cost. When your index needs to be updated very often then <a href="bulksearch/" target="_blank">BulkSearch</a> may be a better choice.
FlexSearch also provides you a non-blocking asynchronous processing model as well as web workers to perform any updates or queries on the index in parallel through dedicated balanced threads.
<a href="#installation">Installation Guide</a> &ensp;&bull;&ensp; <a href="#api">API Reference</a> &ensp;&bull;&ensp; <a href="#profiles">Example Options</a> &ensp;&bull;&ensp; <a href="#builds">Custom Builds</a>
@@ -173,9 +173,9 @@ All Features:
</tr>
<tr>
<td>File Size (gzip)</td>
<td>6.7 kb</td>
<td>4.5 kb</td>
<td>4.1 kb</td>
<td>5.0 kb</td>
<td>3.9 kb</td>
<td>2.7 kb</td>
</tr>
</table>
@@ -194,79 +194,89 @@ __Query Test: "Gulliver's Travels"__
<td align="left">Rank</td>
<td align="left">Library Name</td>
<td align="left">Library Version</td>
<td align="left">Library Size</td>
<td align="left">Operations per second</td>
<td align="left">Single Phrase (op/s)</td>
<td align="left">Multi Phrase (op/s)</td>
<td align="left">Not Found (op/s)</td>
</tr>
<tr>
<td>1</td>
<td>FlexSearch</td>
<td>FlexSearch <a href="#notes">***</a></td>
<td>0.3.2</td>
<td>4.1 kb</td>
<td><b>333738</b></td>
<td><b>342040</b></td>
<td><b>178456</b></td>
<td><b>1527778</b></td>
</tr>
<tr></tr>
<tr>
<td>2</td>
<td>Wade</td>
<td>0.3.3</td>
<td>1.6 kb</td>
<td><b>1587</b></td>
<td><b>899</b></td>
<td><b>6098</b></td>
<td><b>214286</b></td>
</tr>
<tr></tr>
<tr>
<td>3</td>
<td>JS Search</td>
<td>1.4.2</td>
<td>3.8 kb</td>
<td><b>771</b></td>
<td><b>735</b></td>
<td><b>8889</b></td>
<td><b>800000</b></td>
</tr>
<tr></tr>
<tr>
<td>4</td>
<td>JSii</td>
<td>1.0</td>
<td>3.9 kb</td>
<td><b>584</b></td>
<td><b>551</b></td>
<td><b>9970</b></td>
<td><b>75000</b></td>
</tr>
<tr></tr>
<tr>
<td>5</td>
<td>Lunr.js</td>
<td>2.3.5</td>
<td>8.8 kb</td>
<td><b>322</b></td>
<td><b>355</b></td>
<td><b>1051</b></td>
<td><b>25000</b></td>
</tr>
<tr></tr>
<tr>
<td>6</td>
<td>Elasticlunr.js</td>
<td>0.9.6</td>
<td>5.6 kb</td>
<td><b>319</b></td>
<td><b>327</b></td>
<td><b>781</b></td>
<td><b>6667</b></td>
</tr>
<tr></tr>
<tr>
<td>7</td>
<td>BulkSearch</td>
<td>0.1.3</td>
<td>3.1 kb</td>
<td><b>265</b></td>
<td><b>535</b></td>
<td><b>2778</b></td>
</tr>
<tr></tr>
<tr>
<td>8</td>
<td>bm25</td>
<td>0.2</td>
<td>3.5 kb</td>
<td><b>107</b></td>
<td><b>71</b></td>
<td><b>116</b></td>
<td><b>2065</b></td>
</tr>
<tr></tr>
<tr>
<td>9</td>
<td>Fuse</td>
<td>3.3.0</td>
<td>3.7 kb</td>
<td><b>1</b></td>
<td><b>0.5</b></td>
<td><b>0.4</b></td>
<td><b>0.7</b></td>
</tr>
</table>
@@ -283,7 +293,7 @@ __Memory Test: "Gulliver's Travels"__
</tr>
<tr>
<td>1</td>
<td>FlexSearch</td>
<td>FlexSearch <a href="#notes">****</a></td>
<td>0.3.1</td>
<td>1.33 Mb</td>
<td>20.31 kb</td>
@@ -356,12 +366,16 @@ __Memory Test: "Gulliver's Travels"__
<a name="notes" id="notes"></a>
_* Index Size: The size of memory the index requires_<br>
_** Memory Allocation: The amount of memory which was additionally allocated during a row of 10 queries_
_** Memory Allocation: The amount of memory which was additionally allocated during a row of 10 queries_<br>
_*** The preset "fastest" was used for this test_ <br>
_**** The preset "memory" was used for this test_
Library Comparison: <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark.html" target="_blank">Benchmark "Gulliver's Travels"</a>
<a name="contextual"></a>
#### Contextual Search
## Contextual Search
> "TF-IDF and all kinds of variations (like BM25) is a big mistake in searching algorithms today. They don't provide neither: a meaningful relevance of a term nor the importance of it! Like many pseudo-intelligent algorithms this is also just an example of mathematical stupidity." — Thomas Wilkerling, _Contextual-based Scoring_, 2018
FlexSearch introduce a new scoring mechanism called __Contextual Search__ which was invented by Thomas Wilkerling, the author of this library. A Contextual Search <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark.html" target="_blank">incredibly boost up queries to a complete new level</a> but also requires a lot of additionally memory.
The basic idea of this concept is to limit relevance by its context instead of calculating relevance through the whole (unlimited) distance.
@@ -372,27 +386,16 @@ In this way contextual search <a href="https://rawgit.com/nextapps-de/flexsearch
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/contextual-index.svg">
</p>
__Note:__ This feature is actually not enabled by default.
###### TF-IDF / BM25?
> "TF-IDF and all kinds of variations (like BM25) is a big mistake in searching algorithms today. They don't provide neither: a meaningful relevance of a term nor the importance of it! Like many pseudo-intelligent algorithms this is also just an example of mathematical stupidity." — Thomas Wilkerling, _Contextual-based Scoring_, 2018
<a name="webworker"></a>
#### Web-Worker Support
Workers get its own dedicated memory. 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.
__Note:__ It is slightly faster to use no web worker when the index or query isn't too big (index < 500,000 words, query < 25 words).
__Note:__ This feature is actually not enabled by default. Read <a href="contextual_enable">here</a> how to enable.
#### Compare BulkSearch vs. FlexSearch
<table>
<tr></tr>
<tr>
<td align="left">Description</th>
<td align="left">BulkSearch</th>
<td align="left">FlexSearch</th>
<td align="left"></th>
<td align="left"><b>BulkSearch</b></th>
<td align="left"><b>FlexSearch</b></th>
</tr>
<tr>
<td>Access</td>
@@ -414,7 +417,7 @@ __Note:__ It is slightly faster to use no web worker when the index or query isn
<tr></tr>
<tr>
<td>Strength</td>
<td><ul><li>fast adds / fast updates / fast removals</li></ul></td>
<td><ul><li>fast adds</li><li>fast updates</li><li>fast removals</li></ul></td>
<td><ul><li>fast queries</li><li>memory-efficient index</li></ul></td>
</tr>
<tr></tr>
@@ -472,7 +475,9 @@ __Note:__ It is slightly faster to use no web worker when the index or query isn
<a name="installation"></a>
## Installation
##### HTML / Javascript
#### HTML / Javascript
> Use _flexsearch.min.js_ for production and _flexsearch.js_ for development.
```html
<html>
@@ -481,14 +486,24 @@ __Note:__ It is slightly faster to use no web worker when the index or query isn
</head>
...
```
__Note:__ Use _flexsearch.min.js_ for production and _flexsearch.js_ for development.
Use latest from CDN:
```html
<script src="https://cdn.rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script>
```
##### Node.js
Or a specific version:
```html
<script src="https://cdn.rawgit.com/nextapps-de/flexsearch/0.3.2/flexsearch.min.js"></script>
```
__AMD__
```javascript
var FlexSearch = require("./flexsearch.js");
```
#### Node.js
```npm
npm install flexsearch
@@ -506,12 +521,6 @@ Or pass in options when requiring:
var index = require("flexsearch").create({/* options */});
```
__AMD__
```javascript
var FlexSearch = require("./flexsearch.js");
```
<a name="api"></a>
## API Overview
@@ -551,23 +560,23 @@ alternatively you can also use:
var index = FlexSearch.create();
```
##### Create a new index and choosing one of the built-in profiles
Create a new index and choosing one of the built-in profiles:
```js
var index = new FlexSearch("speed");
```
##### Create a new index with custom options
Create a new index with custom options:
```js
var index = new FlexSearch({
// default values:
profile: "balance",
encode: "icase",
tokenize: "ngram",
encode: "balance",
tokenize: "forward",
async: false,
worker: false,
cache: false
});
```
@@ -577,7 +586,7 @@ var index = new FlexSearch({
<a name="index.add"></a>
#### Add items to an index
> Index.__add___(id, string)
> Index.__add(id, string)__
```js
index.add(10025, "John Doe");
@@ -585,7 +594,7 @@ index.add(10025, "John Doe");
<a name="index.search"></a>
#### Search items
> Index.__search(string|options, \<limit\>, \<callback\>)__
> Index.__search(string | options, \<limit\>, \<callback\>)__
```js
index.search("John");
@@ -597,6 +606,7 @@ Limit the result:
index.search("John", 10);
```
#### Async Search
Perform queries asynchronously:
```js
@@ -606,6 +616,8 @@ index.search("John", function(result){
});
```
> Passing a callback always will perform as asynchronous even if the "async" option was not set.
Perform queries asynchronously (Promise-based):
> Make sure the option "async" is enabled on this instance
@@ -621,12 +633,12 @@ Alternatively ES6:
```js
async function search(query){
return await index.search(query);
const result = await index.search(query);
}
const result = search("John");
```
#### Custom Search
Pass custom options for each query:
```js
@@ -655,6 +667,7 @@ index.search("John", {
});
```
#### Suggestions
Get also suggestions for a query:
```js
@@ -668,9 +681,9 @@ index.search({
When suggestion is enabled all results will be filled up (until limit, default 1000) with similar matches ordered by relevance.
<a name="index.update"></a>
#### Update item to the index
#### Update item of an index
> Index.__update__(id, string)
> Index.__update(id, string)__
```js
index.update(10025, "Road Runner");
@@ -679,7 +692,7 @@ index.update(10025, "Road Runner");
<a name="index.remove"></a>
#### Remove item to the index
> Index.__remove__(id)
> Index.__remove(id)__
```js
index.remove(10025);
@@ -699,12 +712,10 @@ index.destroy();
```
<a name="index.init"></a>
#### Re-Initialize index
#### Re-Initialize the index
> Index.__init(\<options\>)__
__Note:__ Re-initialization will also destroy the old index!
Initialize (with same options):
```js
index.init();
@@ -717,6 +728,9 @@ index.init({
/* options */
});
```
> Re-initialization will also destroy the old index.
<a name="flexsearch.addmatcher"></a>
#### Add custom matcher
@@ -731,6 +745,7 @@ FlexSearch.registerMatcher({
'[ûúù]': 'u' // replaces multiple
});
```
<a name="index.addmatcher"></a>
Add private matchers for a specific instance:
```js
@@ -741,10 +756,11 @@ index.addMatcher({
'[ûúù]': 'u' // replaces multiple
});
```
<a name="flexsearch.encoder"></a>
#### Add custom encoder
Define a private custom encoder during creation/initialization:
Assign a custom encoder by passing a function during index creation/initialization:
```js
var index = new FlexSearch({
@@ -756,71 +772,66 @@ var index = new FlexSearch({
}
});
```
<a name="flexsearch.register"></a>
##### Register a global encoder to be used by all instances
> FlexSearch.__registerEncoder(name, encoder)__
```js
FlexSearch.registerEncoder('whitespace', function(str){
return str.replace(/ /g, '');
});
```
Use global encoders:
```js
var index = new FlexSearch({ encode: 'whitespace' });
```
<a name="index.encode"></a>
##### Call encoders directly
Private encoder:
Call a custom encoder directly:
```js
var encoded = index.encode("sample text");
```
<a name="flexsearch.encode"></a>
Global encoder:
<a name="flexsearch.register"></a>
#### Register a global encoder
> FlexSearch.__registerEncoder(name, encoder)__
Global encoders can be shared/used by all instances.
```js
FlexSearch.registerEncoder("whitespace", function(str){
return str.replace(/\s/g, "");
});
```
Initialize index and assign a global encoder:
```js
var index = new FlexSearch({ encode: "whitespace" });
```
Call a global encoder directly:
```js
var encoded = FlexSearch.encode("whitespace", "sample text");
```
##### Mixup/Extend multiple encoders
#### Mix/Extend multiple encoders
```js
FlexSearch.registerEncoder('mixed', function(str){
str = this.encode("icase", str); // built-in
str = this.encode("icase", str); // built-in
str = this.encode("whitespace", str); // custom
return str;
});
```
```js
FlexSearch.registerEncoder('extended', function(str){
str = this.encode("custom", str);
// do something additional with str ...
// do something additional with str ...
return str;
});
```
<a name="flexsearch.tokenizer"></a>
#### Add custom tokenizer
> A tokenizer split words into components or chunks.
Define a private custom tokenizer during creation/initialization:
```js
var index = new FlexSearch({
tokenize: function(str){
// split string into components, e.g.:
return str.split(/ -\//g);
return str.split(/\s-\//g);
}
});
```
<a name="flexsearch.language"></a>
#### Add language-specific stemmer and/or filter
@@ -828,7 +839,7 @@ var index = new FlexSearch({
> __Filter:__ a blacklist of words to be filtered out from indexing at all (e.g. "and", "to" or "be")
Define a private custom stemmer or filter during creation/initialization:
Assign a private custom stemmer or filter during creation/initialization:
```js
var index = new FlexSearch({
@@ -854,15 +865,18 @@ var index = new FlexSearch({
```
Or assign stemmer/filters globally to a language:
```js
FlexSearch.registerLanguage('us', {
stemmer: {/* ... */},
filter: [/* ... */]
> Stemmer are passed as a object (key-value-pair), filter as an array.
```js
FlexSearch.registerLanguage("us", {
stemmer: { /* ... */ },
filter: [ /* ... */ ]
});
```
Or use built-in stemmer or filter of your preferred languages:
Or use some pre-defined stemmer or filter of your preferred languages:
```html
<html>
<head>
@@ -875,15 +889,23 @@ Or use built-in stemmer or filter of your preferred languages:
Now you can assign built-in stemmer during creation/initialization:
```js
var index_en = new FlexSearch({stemmer: 'en', filter: 'en'});
var index_de = new FlexSearch({stemmer: 'de', filter: [/* custom */]});
var index_en = new FlexSearch({
stemmer: "en",
filter: "en"
});
var index_de = new FlexSearch({
stemmer: "de",
filter: [ /* custom */ ]
});
```
In Node.js you just need require the language pack files to make them available:
In Node.js you just have to require the language pack files to make them available:
```js
require('lang/en.js');
require('lang/de.js');
require("flexsearch.js");
require("lang/en.js");
require("lang/de.js");
```
It is also possible to <a href="#builds">compile language packs into the build</a> as follows:
@@ -893,7 +915,9 @@ node compile SUPPORT_LANG_EN=true SUPPORT_LANG_DE=true
```
<a name="index.info"></a>
#### Get info about an index
### Get info about an index
> This feature is available in _DEBUG_ mode.
```js
index.info();
@@ -903,15 +927,22 @@ Returns information e.g.:
```json
{
"bytes": 64000,
"id": 0,
"memory": 10000,
"items": 500,
"sequences": 3000,
"matchers": 0,
"size": 10000,
"status": false
"chars": 3500,
"cache": false,
"matcher": 0,
"worker": false,
"threshold": 7,
"depth": 3,
"contextual": true
}
```
<a name="chaining"></a>
#### Chaining
### Chaining
Simply chain methods like:
@@ -926,20 +957,28 @@ var index = FlexSearch.create()
index.remove(0).update(1, 'foo').add(2, 'foobar');
```
#### Enable Contextual Index
<a name="contextual_enable"></a>
### Enable Contextual Scoring
Create index and just set the limit of relevance ("depth"):
Create an index and just set the limit of relevance as "depth":
```js
var index = new FlexSearch({
encode: "icase",
tokenize: "strict",
threshold: 7,
depth: 3
});
```
> Only the tokenizer "strict" is actually supported by the contextual index.
> The contextual index requires <a href="#memory">additional amount of memory</a> depending on depth.
> 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
@@ -950,7 +989,16 @@ var index = new FlexSearch({
});
```
#### Use WebWorker Sharding (Browser only)
> When passing a number as a limit the cache automatically balance stored entries related to their popularity.
> 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)
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.-->
> When the index isn't big enough it is faster to use no web worker.
Create index and just set the count of parallel threads:
```js
@@ -976,6 +1024,14 @@ index.search("John Doe", function(results){
});
```
Or use promises accordingly:
```js
index.search("John Doe").then(function(results){
// do something with array of results
});
```
<a name="options"></a>
## Options
@@ -1004,12 +1060,12 @@ FlexSearch ist highly customizable. Make use of the the <a href="#profiles">righ
</tr>
<tr></tr>
<tr>
<td align="top">tokenize<br><br><br><br><br><br></td>
<td align="top">tokenize<br><br><br><br><br><!--<br>--></td>
<td vertical="top" vertical-align="top">
"strict"<br>
"foward"<br>
"reverse"<br>
"ngram"<br>
<!--"ngram"<br>-->
"full"<br>
function()
</td>
@@ -1139,6 +1195,7 @@ Tokenizer effects the required memory also as query time and flexibility of part
<td>* 1</td>
</tr>
<tr></tr>
<!--
<tr>
<td><b>"ngram"</b> (default)</td>
<td>index words partially through phonetic n-grams</td>
@@ -1146,6 +1203,7 @@ Tokenizer effects the required memory also as query time and flexibility of part
<td>* n / 3</td>
</tr>
<tr></tr>
-->
<tr>
<td><b>"foward"</b></td>
<td>incrementally index words in forward direction</td>
@@ -1234,10 +1292,10 @@ Encoding effects the required memory also as query time and phonetic matches. Tr
<tr></tr>
<tr>
<td align="left">Query</td>
<td align="left">iCase</td>
<td align="left">Simple</td>
<td align="left">Advanced</td>
<td align="left">Extra</td>
<td align="left">icase</td>
<td align="left">simple</td>
<td align="left">advanced</td>
<td align="left">extra</td>
</tr>
<tr>
<td>björn</td>
@@ -1378,11 +1436,13 @@ The required memory for the index depends on several options:
<td>"strict"</td>
<td>* 1</td>
</tr>
<!--
<tr></tr>
<tr>
<td>"ngram" (default)</td>
<td>* n / 3</td>
</tr>
-->
<tr></tr>
<tr>
<td>"forward"</td>
@@ -1417,11 +1477,11 @@ The book "Gulliver's Travels" (Swift Jonathan 1726) was used for this test.
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/memory-comparison.svg">
<a name="profiles"></a>
## Built-in Profiles
## Presets
You can pass a built-in profile during creation/initialization. They have these following settings:
You can pass a preset during creation/initialization. They represents these following settings:
Standard profile: __"default"__
__"default"__: Standard profile
```js
{
encode: "icase",
@@ -1429,7 +1489,7 @@ Standard profile: __"default"__
}
```
Memory-optimized profile: __"memory"__
__"memory"__: Memory-optimized profile
```js
{
encode: "extra",
@@ -1438,7 +1498,7 @@ Memory-optimized profile: __"memory"__
}
```
Speed-optimized profile: __"speed"__
__"speed"__: Speed-optimized profile
```js
{
@@ -1449,7 +1509,7 @@ Speed-optimized profile: __"speed"__
}
```
Matching-tolerant profile: __"match"__
__"match"__: Matching-tolerant profile
```js
{
@@ -1458,7 +1518,7 @@ Matching-tolerant profile: __"match"__
}
```
Relevance-optimized profile: __"score"__
__"score"__: Relevance-optimized profile
```js
{
@@ -1469,18 +1529,18 @@ Relevance-optimized profile: __"score"__
}
```
Most-balanced profile: __"balanced"__
__"balance"__: Most-balanced profile
```js
{
encode: "balanced",
tokenize: "ngram",
encode: "balance",
tokenize: "strict",
threshold: 6,
depth: 3
}
```
Absolute fastest profile: __"fastest"__
__"fastest"__: Absolute fastest profile
```js
{
@@ -1490,11 +1550,116 @@ Absolute fastest profile: __"fastest"__
}
```
<!--
Compare these options above:
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark.html" target="_blank">Benchmarks</a>
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching-flexsearch.html" target="_blank">Relevance Scoring</a>
-->
Compare these presets:
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching-presets.html" target="_blank">Relevance Scoring</a><br>
- <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/benchmark-presets.html" target="_blank">Benchmarks</a>
<a name="builds"></a>
## Best Practices
__Split Complexity__
Whenenver you can, try to divide content by categories and add them to its own index, e.g.:
```js
var feeds_2017 = new FlexSearch();
var feeds_2018 = new FlexSearch();
var feeds_2019 = new FlexSearch();
```
__Use numeric IDs__
It is recommended to use numeric id values as reference when adding content to the index. The byte length of passed ids influences the memory consumption significantly. If this is not possible you should consider to use a index table and map the ids with indexes, this becomes important especially when using contextual indexes on a large amount of content.
e.g. instead of this:
```js
index.add("fdf12cad-8779-47ab-b614-4dbbd649178b", "content");
```
you should probably use this:
```js
var index_table = {
"fdf12cad-8779-47ab-b614-4dbbd649178b": 0,
"48b3041c-a243-4a52-b1ed-225041847366": 1,
"7236c8b5-86e1-451a-842f-d9aba9642e4d": 2,
// ....
};
index.add(index_table["fdf12cad-8779-47ab-b614-4dbbd649178b"], "content");
```
It is planned to provide a built-in feature which should replace this workaround.
<a name="debug"></a>
## Debug
> Do not use DEBUG in production builds.
If you get issues, you can temporary set the _DEBUG_ flag to _true_ on top of _flexsearch.js_:
```js
DEBUG = true;
```
This enables console logging of several processes. Just open the browsers console to make this information visible.
<a name="profile"></a>
## Profiler Stats
> Do not use PROFILER in production builds.
To collect some performance statistics of your indexes you need to temporary set the _PROFILER_ flag to _true_ on top of _flexsearch.js_:
```js
PROFILER = true;
```
This enables profiling of several processes.
An array of all profiles is available on:
```js
window.stats;
```
You can also just open the browsers console and enter this line to get stats.
> The index of the array corresponds to the _index.id_.
Get stats from a specific index:
```js
index.stats;
```
The returning stats payload is divided into several categories. Each of these category provides its own statistic values.
__Profiler Stats Properties__
<table>
<tr></tr>
<tr>
<td>Property</td>
<td>Description</td>
</tr>
<tr>
<td>time</td>
<td>The sum of time (ms) the process takes (lower is better)</td>
</tr>
<tr></tr>
<tr>
<td>count</td>
<td>How often the process was called</td>
</tr>
<tr></tr>
<tr>
<td>ops</td>
<td>Average operations per seconds (higher is better)</td>
</tr>
<tr></tr>
<tr>
<td>nano</td>
<td>Average cost (ns) per operation/call (lower is better)</td>
</tr>
</table>
<a name="builds"></a>
## Custom Builds

File diff suppressed because one or more lines are too long

View File

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

View File

@@ -1,5 +1,5 @@
;/**!
* @preserve FlexSearch v0.3.21
* @preserve FlexSearch v0.3.3
* Copyright 2019 Nextapps GmbH
* Author: Thomas Wilkerling
* Released under the Apache 2.0 Licence
@@ -121,7 +121,7 @@
* @const {RegExp}
*/
const regex_split = regex("[\\s/-]");
const regex_split = regex("\\W+"); // regex("[\\s/-_]");
const filter = {};
const stemmer = {};
@@ -133,7 +133,7 @@
const index_blacklist = (function(){
const array = Object.getOwnPropertyNames(/** @type {!Array} */ (({}).__proto__));
const map = {};
const map = create_object();
for(let i = 0; i < array.length; i++){
@@ -152,7 +152,10 @@
if(PROFILER){
this["stats"] = profile = profiles[id_counter] || (profiles[id_counter] = {});
profile = profiles[id_counter] || (profiles[id_counter] = {});
/** @export */
this.stats = profile;
}
if(SUPPORT_PRESETS && is_string(options)){
@@ -262,14 +265,14 @@
FlexSearch.encode = function(name, value){
if(index_blacklist[name]){
return value;
}
else{
// if(index_blacklist[name]){
//
// return value;
// }
// else{
return global_encoder[name](value);
}
// }
};
/**
@@ -467,11 +470,11 @@
/** @private */
this._map = create_object_array(10);
/** @private */
this._ctx = {};
this._ctx = create_object();
/** @private */
this._ids = {};
this._ids = create_object();
/** @private */
this._stack = {};
this._stack = create_object();
/** @private */
this._stack_keys = [];
@@ -609,7 +612,7 @@
FlexSearch.prototype.add = function(id, content, _skip_update){
if(content && is_string(content) && ((id && !index_blacklist[id]) || (id === 0))){
if(content && is_string(content) && ((id /*&& !index_blacklist[id]*/) || (id === 0))){
// check if index ID already exist
@@ -683,17 +686,18 @@
tokenizer(content)
:(
SUPPORT_ENCODER && (tokenizer === "ngram") ?
//SUPPORT_ENCODER && (tokenizer === "ngram") ?
/** @type {!Array<string>} */
(ngram(/** @type {!string} */(content)))
:
//(ngram(/** @type {!string} */(content)))
//:
/** @type {string} */
(content).split(regex_split)
)
);
const dupes = { "_ctx": {} };
const dupes = create_object();
dupes["_ctx"] = create_object();
const threshold = this.threshold;
const depth = this.depth;
@@ -803,7 +807,7 @@
if(depth && (word_length > 1) && (score >= threshold)){
const ctxDupes = dupes["_ctx"][value] || (dupes["_ctx"][value] = {});
const ctxDupes = dupes["_ctx"][value] || (dupes["_ctx"][value] = create_object());
const ctxTmp = this._ctx[value] || (this._ctx[value] = create_object_array(10));
let x = i - depth;
@@ -1114,11 +1118,11 @@
tokenizer(_query)
:(
SUPPORT_ENCODER && (tokenizer === "ngram") ?
//SUPPORT_ENCODER && (tokenizer === "ngram") ?
/** @type {!Array<string>} */
(ngram(_query))
:
//(ngram(_query))
//:
/** @type {string} */
(_query).split(regex_split)
)
@@ -1127,7 +1131,7 @@
const length = words.length;
let found = true;
const check = [];
const check_words = {};
const check_words = create_object();
let ctx_root;
let use_contextual;
@@ -1137,8 +1141,7 @@
if(this.depth){
use_contextual = true;
// TODO: iterate roots
ctx_root = words[0];
ctx_root = words[0]; // TODO: iterate roots?
check_words[ctx_root] = 1;
}
else{
@@ -1156,63 +1159,66 @@
const value = words[a];
if(value && !check_words[value]){
if(value){
let map;
let map_value;
let map_found = false;
const map_check = [];
let count = 0;
if(!check_words[value]){
for(let z = 9; z >= threshold; z--){
const map_check = [];
let map_found = false;
let count = 0;
map = (
const map = use_contextual ?
use_contextual ?
ctx_map[ctx_root]
:
this._map;
ctx_map[ctx_root]
:
this._map
)[z];
if(map){
if((map_value = map[value])){
let map_value;
map_check[count++] = map_value;
map_found = true;
for(let z = 9; z >= threshold; z--){
if((map_value = map[z][value])){
map_check[count++] = map_value;
map_found = true;
}
}
}
}
if(map_found){
if(map_found){
// Not handled by intersection:
// not handled by intersection:
check[check.length] = (
check[check.length] = (
count > 1 ?
count > 1 ?
// https://jsperf.com/merge-arrays-comparison
check.concat.apply([], map_check)
:
map_check[0]
);
// https://jsperf.com/merge-arrays-comparison
map_check.concat.apply([], map_check)
:
map_check[0]
);
// Handled by intersection:
// handled by intersection:
//check[check.length] = map_check;
}
else {
if(!SUPPORT_SUGGESTIONS || !this.suggest){
found = false;
break;
//check[check.length] = map_check;
}
else{
if(!SUPPORT_SUGGESTIONS || !this.suggest){
found = false;
break;
}
}
check_words[value] = 1;
}
check_words[value] = 1;
ctx_root = value;
}
ctx_root = value;
}
}
else{
@@ -1604,7 +1610,7 @@
const queue = SUPPORT_ASYNC ? (function(){
const stack = {};
const stack = create_object();
return function(fn, delay, id){
@@ -1638,11 +1644,11 @@
Cache.prototype.clear = function(){
/** @private */
this.cache = {};
this.cache = create_object();
/** @private */
this.count = {};
this.count = create_object();
/** @private */
this.index = {};
this.index = create_object();
/** @private */
this.ids = [];
};
@@ -1817,25 +1823,25 @@
/**
* @param {Array} map
* @param {Object} dupes
* @param {string} tmp
* @param {string} value
* @param {string|number} id
* @param {number} partial_score
* @param {number} context_score
* @param {number} threshold
*/
function add_index(map, dupes, tmp, id, partial_score, context_score, threshold){
function add_index(map, dupes, value, id, partial_score, context_score, threshold){
/*
if(index_blacklist[tmp]){
if(index_blacklist[value]){
return 0;
}
*/
if(dupes[tmp]){
if(dupes[value]){
return dupes[tmp];
return dupes[value];
}
else{
@@ -1848,12 +1854,12 @@
context_score
);
dupes[tmp] = score;
dupes[value] = score;
if(score >= threshold){
let arr = map[((score + 0.5) >> 0)];
arr = arr[tmp] || (arr[tmp] = []);
arr = arr[value] || (arr[value] = []);
arr[arr.length] = id;
}
@@ -1929,65 +1935,62 @@
for(let i = 0; i < length; i++){
const char = value[i];
const char_is_vowel = (
const char_is_whitespace = (char === " ");
(char === "a") ||
(char === "e") ||
(char === "i") ||
(char === "o") ||
(char === "u") ||
(char === "y")
);
if(!char_is_whitespace){
if(char_is_vowel){
if((char === "a") ||
(char === "e") ||
(char === "i") ||
(char === "o") ||
(char === "u") ||
(char === "y")){
count_vowels++;
}
else{
count_vowels++;
}
else{
count_literal++;
}
if(char !== " ") {
count_literal++;
}
tmp += char;
}
//console.log(tmp);
// dynamic n-gram sequences
if((char === " ") || (
if(char_is_whitespace || (
(count_vowels >= (length > 8 ? 2 : 1)) &&
(count_literal >= 2)
(count_vowels > (length > 7 ? 1 : 0)) &&
(count_literal > 1)
) || (
(count_vowels >= 2) &&
(count_literal >= (length > 8 ? 2 : 1))
(count_vowels > 1) &&
(count_literal > (length > 7 ? 1 : 0))
) || (i === length - 1)){
if(tmp){
if(parts[count_parts] && (tmp.length > 2)){
if(char_is_whitespace){
count_parts++;
}
if(parts[count_parts]){
parts[count_parts] += tmp;
}
else{
parts[count_parts] = tmp;
}
if(parts[count_parts] && (tmp.length > 2)){
if(char === " "){
count_parts++;
}
count_parts++;
if(parts[count_parts]){
parts[count_parts] += tmp;
}
else{
parts[count_parts] = tmp;
}
}
tmp = "";
@@ -2074,7 +2077,7 @@
function init_filter(words, encoder){
const final = {};
const final = create_object();
if(words){
@@ -2195,7 +2198,7 @@
// fill initial map
const check = {};
const check = create_object();
let arr = arrays[0];
let length = arr.length;
let i = 0;
@@ -2639,12 +2642,17 @@
for(let i = 0; i < count; i++){
array[i] = {};
array[i] = create_object();
}
return array;
}
function create_object(){
return Object.create(null);
}
function addWorker(id, core, options, callback){
const thread = register_worker(
@@ -2776,7 +2784,7 @@
SUPPORT_WORKER ? (function register_worker(){
const worker_stack = Object.create(null);
const worker_stack = {};
const inline_supported = (typeof Blob !== "undefined") && (typeof URL !== "undefined") && URL.createObjectURL;
return (

View File

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

47
flexsearch.min.js vendored
View File

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

View File

@@ -1,16 +1,17 @@
{
"name": "flexsearch",
"version": "0.3.21",
"version": "0.3.3",
"description": "Next-Generation full text search library with zero dependencies.",
"homepage": "https://github.com/nextapps-de/flexsearch/",
"author": "Thomas Wilkerling",
"copyright": "Nextapps GmbH",
"license": "Apache-2.0",
"keywords": [
"full text search",
"fulltext search",
"elastic search",
"fastest search",
"contextual search"
"contextual search",
"fuzzy search"
],
"bugs": {
"url": "https://github.com/nextapps-de/flexsearch/issues",

287
test/benchmark-presets.html Normal file
View File

@@ -0,0 +1,287 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Benchmark Presets</title>
<style>
body{
font-family: sans-serif;
}
table td{
padding: 1em 2em;
}
button{
padding: 5px 10px;
}
</style>
</head>
<body>
<h2>Presets Benchmark Comparison</h2>
<!--<button id="btn_start" onclick="start();" disabled>Start</button>-->
<h4>Indexed Text: "Gulliver's Travels" (Swift Jonathan 1726)</h4>
<hr>
<div id="container"></div>
<hr>
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.compact.js"></script>
<script src="../data/gulliver.js"></script>
<script>
//var data = [];
(function(){
var flexsearch_default = new FlexSearch();
var flexsearch_memory = new FlexSearch("memory");
var flexsearch_speed = new FlexSearch("speed");
var flexsearch_fastest = new FlexSearch("fastest");
var flexsearch_match = new FlexSearch("match");
var flexsearch_score = new FlexSearch("score");
var flexsearch_balance = new FlexSearch("balance");
var tests = {
"fastest": {
init: function(){},
add: function(index, content){
flexsearch_fastest.add(index, content);
},
query: function(query){
return flexsearch_fastest.search(query);
},
loops: 250000
},
"speed": {
init: function(){},
add: function(index, content){
flexsearch_speed.add(index, content);
},
query: function(query){
return flexsearch_speed.search(query);
},
loops: 150000
},
"default": {
init: function(){},
add: function(index, content){
flexsearch_default.add(index, content);
},
query: function(query){
return flexsearch_default.search(query);
},
loops: 100000
},
"balance": {
init: function(){},
add: function(index, content){
flexsearch_balance.add(index, content);
},
query: function(query){
return flexsearch_balance.search(query);
},
loops: 75000
},
"memory": {
init: function(){},
add: function(index, content){
flexsearch_memory.add(index, content);
},
query: function(query){
return flexsearch_memory.search(query);
},
loops: 20000
},
"match": {
init: function(){},
add: function(index, content){
flexsearch_match.add(index, content);
},
query: function(query){
return flexsearch_match.search(query);
},
loops: 20000
},
"score": {
init: function(){},
add: function(index, content){
flexsearch_score.add(index, content);
},
query: function(query){
return flexsearch_score.search(query);
},
loops: 30000
}
};
function init_container(target){
var html = "<table>" +
"<tr>" +
"<th>Preset&emsp;</th>" +
"<th>Benchmark (Single Phrase)&emsp;</th>" +
"<th>Benchmark (Multi Phrase)&emsp;</th>" +
"<th>Benchmark (Mixed Not Found)&emsp;</th>" +
"</tr>";
for(var test in tests){
if(tests.hasOwnProperty(test)){
html += "<tr>" +
"<td>" + test + "</td>" +
"<td id=\"test-" + test + "\">indexing ...</td>" +
"<td id=\"test-multi-" + test + "\"></td>" +
"<td id=\"test-notfound-" + test + "\"></td>" +
"</tr>"
}
}
html += "</table>";
target.innerHTML = html;
}
var is_mobile = navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/);
function init_tests(index, keys){
var key = keys[index];
var test = tests[key];
test.init();
if(is_mobile && (test.loops > 1)){
test.loops = (test.loops / 5) >> 0;
}
for(var i = 0; i < text_data.length; i++){
test.add(i, text_data[i]);
}
document.getElementById("test-" + key).textContent = "ready ...";
if(++index < keys.length){
setTimeout(function(){
init_tests(index, keys);
}, 100);
}
else{
/*
window.start = function(){
start_tests(0, Object.keys(tests));
};
document.getElementById("btn_start").disabled = false;
*/
setTimeout(function(){
start_tests(0, 0, keys);
}, 1000);
}
}
var text_queries_notfound = [
"undefined1 undefined2 undefined3",
"undefined"
];
function start_tests(suite, index, keys){
var queries = suite === 0 ? text_queries : (suite === 1 ? text_queries_multi : text_queries_notfound);
var len = queries.length;
var key = keys[index];
var test = tests[key];
var loops = test.loops;
var query = test.query;
var start = Date.now();
for(var i = 0; i < len; i++){
var phrase = queries[i];
for(var x = 0; x < loops; x++){
query(phrase);
}
}
var duration = Date.now() - start;
console.log("[Suite " + suite + "] " + key + ":", duration);
document.getElementById("test-" + (suite === 1 ? "multi-" : (suite === 2 ? "notfound-" : "")) + key).textContent = format_number(((1000 / duration * loops * 10 + 0.5) >> 0) / 10) + " op/s";
if(++index >= keys.length){
if(++suite < 3){
index = 0;
}
}
if(index < keys.length){
setTimeout(function(){
start_tests(suite, index, keys);
}, 1000);
}
}
init_container(document.getElementById("container"));
setTimeout(function(){
init_tests(0, Object.keys(tests));
}, 100);
function format_number(num){
return ("" + num).replace(/(\d)(?=(\d{3})+\b)/g, '$1,');
}
// ---------------------------------------
window.tests = tests;
})();
</script>
</body>
</html>

View File

@@ -22,7 +22,7 @@
<hr>
<div id="container"></div>
<hr>
Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least 7 entries for the query "Gulliver".
Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least 7 matches for the query "gulliver", 4. result should be ordered by relevance
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.light.js"></script>
<script src="https://rawgit.com/nextapps-de/bulksearch/master/bulksearch.light.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/elasticlunr/0.9.6/elasticlunr.min.js"></script>
@@ -62,9 +62,9 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
flexsearch = new FlexSearch({
encode: "icase",
mode: "strict",
tokenize: "strict",
threshold: 9,
depth: 0,
depth: 1,
async: false,
cache: false,
worker: false
@@ -88,7 +88,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
flexsearch_cache = new FlexSearch({
encode: "icase",
mode: "strict",
tokenize: "strict",
threshold: 9,
depth: 1,
async: false,
@@ -115,7 +115,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
flexsearch_cache_scale = new FlexSearch({
encode: "icase",
mode: "strict",
tokenize: "strict",
threshold: 9,
depth: 1,
async: false,
@@ -142,7 +142,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
flexsearch_worker = new FlexSearch({
encode: "icase",
mode: "strict",
tokenize: "strict",
threshold: 9,
depth: 1,
async: true,
@@ -233,21 +233,17 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
init: function(){
// wadesearch = function(query){
// return wade(query)/*.sort(sort_by_score_down)*/;
// };
//
// function sort_by_score_down(a, b){
// var sum = a.score - b.score;
// return sum < 0 ? 1 : sum > 0 ? -1 : 0;
// }
wade = Wade(text_data.slice(0));
},
sort: function(a, b){
var sum = a.score - b.score;
return sum < 0 ? 1 : sum ? -1 : 0;
},
add: function(index, content){},
query: function(query){
return wade(query)/*.map(function(val){return val.index})*/;
return wade(query).sort(this.sort)/*.map(function(val){return val.index})*/;
},
loops: 1500
},
@@ -266,12 +262,9 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
keys: ["content"],
id: "id",
shouldSort: true,
threshold: 0.6,
location: 0,
distance: 100,
findAllMatches: true,
maxPatternLength: 32,
minMatchCharLength: 1
tokenize: true,
matchAllTokens: true,
threshold: 0.2
});
},
add: function(index, content){},
@@ -350,8 +343,10 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
var html = "<table>" +
"<tr>" +
"<th>Library</th>" +
"<th>Benchmark</th>" +
"<th>Library&emsp;</th>" +
"<th>Benchmark (Single Phrase)&emsp;</th>" +
"<th>Benchmark (Multi Phrase)&emsp;</th>" +
"<th>Benchmark (Mixed Not Found)&emsp;</th>" +
"</tr>";
for(var test in tests){
@@ -361,6 +356,8 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
html += "<tr>" +
"<td>" + test + "</td>" +
"<td id=\"test-" + test + "\">indexing ...</td>" +
"<td id=\"test-multi-" + test + "\"></td>" +
"<td id=\"test-notfound-" + test + "\"></td>" +
"</tr>"
}
}
@@ -412,44 +409,57 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
setTimeout(function(){
start_tests(0, keys);
start_tests(0, 0, keys);
}, 1000);
}
}
function start_tests(index, keys){
var text_queries_notfound = [
var queries = text_queries;
"undefined1 undefined2 undefined3",
"undefined"
];
function start_tests(suite, index, keys){
var queries = suite === 0 ? text_queries : (suite === 1 ? text_queries_multi : text_queries_notfound);
var len = queries.length;
var key = keys[index];
var test = tests[key];
var loops = test.loops;
var query = test.query;
var start = Date.now();
for(var i = 0; i < len; i++){
var tmp = queries[i];
var phrase = queries[i];
for(var x = 0; x < loops; x++){
query(tmp);
query(phrase);
}
}
var duration = Date.now() - start;
console.log(key + ":", duration);
console.log("[Suite " + suite + "] " + key + ":", duration);
document.getElementById("test-" + key).textContent = /*format_number*/(((1000 / duration * loops * 10 + 0.5) >> 0) / 10) + " op/s";
document.getElementById("test-" + (suite === 1 ? "multi-" : (suite === 2 ? "notfound-" : "")) + key).textContent = format_number(((1000 / duration * loops * 10 + 0.5) >> 0) / 10) + " op/s";
if(++index < keys.length){
if(++index >= keys.length){
if(++suite < 3){
index = 0;
}
}
if(index < keys.length){
setTimeout(function(){
start_tests(index, keys);
start_tests(suite, index, keys);
}, 1000);
}
@@ -470,7 +480,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
// ---------------------------------------
//window.tests = tests;
window.tests = tests;
})();
</script>
</body>

View File

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

File diff suppressed because one or more lines are too long

339
test/matching-presets.html Normal file
View File

@@ -0,0 +1,339 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Presets Matching Test</title>
<style>
body{
font-family: sans-serif;
}
table td{
padding: 1em 2em;
}
</style>
</head>
<body>
<h2>Presets Relevance Scoring Comparison</h2>
<h4>Indexed Text: "Gulliver's Travels" (Swift Jonathan 1726)</h4>
<hr>
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script>
<script src="../data/gulliver.js"></script>
<div id="container">
<table>
<tr>
<th><b>Query</b></th>
<th>default</th>
<th>memory</th>
<th>speed</th>
<th>matching</th>
<th>scoring</th>
<th>balanced</th>
<th>fastest</th>
</tr>
<tr id="test-1">
<td style="width: 200px">"without breach of modesty"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-2">
<td>"went softly stream"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-3">
<td>"princes of the ambition"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-4">
<td>"five-thousand leagues"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-5">
<td>"i already observed"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-6">
<td>"let a of his"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-7">
<td>"take that to the rocks"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-8">
<td>"bignes of splaknuk"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-9">
<td>"matematikal musikal instruments"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-10">
<td>"matical sical strument"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-11">
<td>"lalkon the camberlayhn"</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
</table>
</div>
<hr>
<div style="line-height: 2em">
<div style="display:inline-block; width:16px; height:16px; background: #f00"></div> Either no results or relevant content was not included in results.<br>
<div style="display:inline-block; width:16px; height:16px; background: orange"></div> Most relevant results was not found in the first place.<br>
<div style="display:inline-block; width:16px; height:16px; background: #0a0"></div> Most relevant results was successfully found in the first place.<br>
<b>Note:</b> Open console and type e.g. <i>data[493]</i>
</div>
<script>
var data = [];
setTimeout(function(){
var new_data = text_data;
var tmp = '';
for(var i = 0; i < new_data.length; i++){
if(new_data[i].length > 2) {
tmp += new_data[i] + '. ';
if((tmp.length > 1000) || (i === new_data.length - 1)){
data.push(tmp.replace(/{[^}]*}/g, ''));
tmp = '';
}
}
}
var flexsearch_default = new FlexSearch();
var flexsearch_memory = new FlexSearch("memory");
var flexsearch_speed = new FlexSearch("speed");
var flexsearch_fastest = new FlexSearch("fastest");
var flexsearch_match = new FlexSearch("match");
var flexsearch_score = new FlexSearch("score");
var flexsearch_balance = new FlexSearch("balance");
// ---------------------------------------
console.time('flexsearch_default');
for(var i = 0; i < data.length; i++){
flexsearch_default.add(i, data[i]);
}
console.timeEnd('flexsearch_default');
// ---------------------------------------
console.time('flexsearch_memory');
for(var i = 0; i < data.length; i++){
flexsearch_memory.add(i, data[i]);
}
console.timeEnd('flexsearch_memory');
// ---------------------------------------
console.time('flexsearch_speed');
for(var i = 0; i < data.length; i++){
flexsearch_speed.add(i, data[i]);
}
console.timeEnd('flexsearch_speed');
// ---------------------------------------
console.time('flexsearch_match');
for(var i = 0; i < data.length; i++){
flexsearch_match.add(i, data[i]);
}
console.timeEnd('flexsearch_match');
// ---------------------------------------
console.time('flexsearch_score');
for(var i = 0; i < data.length; i++){
flexsearch_score.add(i, data[i]);
}
console.timeEnd('flexsearch_score');
// ---------------------------------------
console.time('flexsearch_balance');
for(var i = 0; i < data.length; i++){
flexsearch_balance.add(i, data[i]);
}
console.timeEnd('flexsearch_balance');
// ---------------------------------------
console.time('flexsearch_fastest');
for(var i = 0; i < data.length; i++){
flexsearch_fastest.add(i, data[i]);
}
console.timeEnd('flexsearch_fastest');
// ---------------------------------------
do_test('test-1', 'without breach of modesty', [493]);
do_test('test-2', 'went softly stream', [446]);
do_test('test-3', 'princes of the ambition', [72, 408]);
do_test('test-4', 'five-thousand leagues', [2]);
do_test('test-5', 'i already observed', [458, 346]);
do_test('test-6', 'let a of his', [50]);
do_test('test-7', 'take that to the rocks', [175]);
do_test('test-8', 'bignes of splaknuk', [146]);
do_test('test-9', 'matematikal musikal instruments', [267]);
do_test('test-10', 'matical sical strument', [267]);
do_test('test-11', 'lalkon the camberlayhn', [99]);
// ---------------------------------------
function do_test(id, query, ref){
var nodes = document.getElementById(id).getElementsByTagName('td');
for(var i = 1; i < nodes.length; i++){
var results;
switch(i){
case 1:
results = flexsearch_default.search(query);
break;
case 2:
results = flexsearch_memory.search(query);
break;
case 3:
results = flexsearch_speed.search(query);
break;
case 4:
results = flexsearch_match.search(query);
break;
case 5:
results = flexsearch_score.search(query);
break;
case 6:
results = flexsearch_balance.search(query);
break;
case 7:
results = flexsearch_fastest.search(query);
break;
}
for(var a = 0; a < ref.length; a++){
var current = ref[a];
nodes[i].innerHTML = results[0] || '-';
nodes[i].style.color = '#fff';
if((results[0] === current) || (results[0] === String(current))){
nodes[i].style.backgroundColor = '#0a0';
break;
}
else if(!results.length || ((results.indexOf(current) === -1) && (results.indexOf(String(current)) === -1))){
if(nodes[i].style.backgroundColor !== 'orange'){
nodes[i].style.backgroundColor = '#f00';
}
}
else{
nodes[i].style.backgroundColor = 'orange';
}
}
}
}
}, 50);
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -455,11 +455,12 @@ if(env !== "light"){
expect(result).to.include(1);
});
setTimeout(function(){
// (async function(){
//
// expect(await flexsearch_async.search("foo")).to.have.members([0, 1]);
// })();
done();
}, 25);
setTimeout(done, 25);
});
it("Should have been limited", function(done){
@@ -470,11 +471,7 @@ if(env !== "light"){
expect(result).to.not.include(1);
});
setTimeout(function(){
done();
}, 25);
setTimeout(done, 25);
});
it("Should not have been matched from index", function(done){
@@ -499,11 +496,7 @@ if(env !== "light"){
expect(result).to.have.lengthOf(0);
});
setTimeout(function(){
done();
}, 25);
setTimeout(done, 25);
});
});
@@ -671,11 +664,7 @@ if(env !== "light"){
expect(result).to.have.length(0);
});
setTimeout(function(){
done();
}, 25);
setTimeout(done, 25);
});
it("Should not have been added to the index", function(done){
@@ -720,11 +709,7 @@ if(env !== "light"){
expect(result).to.have.lengthOf(1);
});
setTimeout(function(){
done();
}, 25);
setTimeout(done, 25);
});
it("Should have been limited", function(done){
@@ -735,11 +720,7 @@ if(env !== "light"){
expect(result).to.not.include(1);
});
setTimeout(function(){
done();
}, 25);
setTimeout(done, 25);
});
it("Should not have been matched from index", function(done){
@@ -764,11 +745,7 @@ if(env !== "light"){
expect(result).to.have.lengthOf(0);
});
setTimeout(function(){
done();
}, 25);
setTimeout(done, 25);
});
});
@@ -801,11 +778,7 @@ if(env !== "light"){
expect(results).to.have.members([2]);
});
setTimeout(function(){
done();
}, 25);
setTimeout(done, 25);
}, 25);
});
});
@@ -842,11 +815,7 @@ if(env !== "light"){
expect(results).to.not.include(2);
});
setTimeout(function(){
done();
}, 25);
setTimeout(done, 25);
}, 25);
});