mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-08 21:20:41 +02:00
ADD custom builds
ADD stemmer and stopword filter MOD update readme
This commit is contained in:
105
README.md
105
README.md
@@ -1,6 +1,6 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<br>
|
<br>
|
||||||
<img src="http://nextapps.de/img/flexsearch.svg" alt="Search Library" width="50%">
|
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/flexsearch.svg" alt="Search Library" width="50%">
|
||||||
<br><br>
|
<br><br>
|
||||||
<a target="_blank" href="https://www.npmjs.com/package/flexsearch"><img src="https://img.shields.io/npm/v/flexsearch.svg"></a>
|
<a target="_blank" href="https://www.npmjs.com/package/flexsearch"><img src="https://img.shields.io/npm/v/flexsearch.svg"></a>
|
||||||
<img src="https://img.shields.io/badge/status-BETA-orange.svg">
|
<img src="https://img.shields.io/badge/status-BETA-orange.svg">
|
||||||
@@ -18,6 +18,8 @@ When it comes to raw search speed <a href="https://jsperf.com/compare-search-lib
|
|||||||
It also has the __most memory-efficient index__. Keep in mind that updating / 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.
|
It also has the __most memory-efficient index__. Keep in mind that updating / 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.
|
||||||
FlexSearch also provides you a non-blocking asynchronous processing model as well as web workers to perform any updates on the index as well as queries through dedicated threads.
|
FlexSearch also provides you a non-blocking asynchronous processing model as well as web workers to perform any updates on the index as well as queries through dedicated threads.
|
||||||
|
|
||||||
|
<a href="#installation">Installation Guide</a>  •  <a href="#api">API Reference</a>  •  <a href="#examples">Example Options</a>  •  <a href="#builds">Custom Builds</a>
|
||||||
|
|
||||||
Comparison:
|
Comparison:
|
||||||
- <a href="https://jsperf.com/compare-search-libraries" target="_blank">Library Benchmarks</a>
|
- <a href="https://jsperf.com/compare-search-libraries" target="_blank">Library Benchmarks</a>
|
||||||
- <a href="https://jsperf.com/flexsearch" target="_blank">BulkSearch vs. FlexSearch Benchmark</a>
|
- <a href="https://jsperf.com/flexsearch" target="_blank">BulkSearch vs. FlexSearch Benchmark</a>
|
||||||
@@ -40,14 +42,27 @@ All Features:
|
|||||||
<li>Multiple Words</li>
|
<li>Multiple Words</li>
|
||||||
<li><a href="#phonetic">Phonetic Search</a></li>
|
<li><a href="#phonetic">Phonetic Search</a></li>
|
||||||
<li>Relevance-based Scoring</li>
|
<li>Relevance-based Scoring</li>
|
||||||
<li>Contextual Indexes</li>
|
<li><a href="contextual">Contextual Indexes</a></li>
|
||||||
<li>Limit Results</li>
|
<li>Limit Results</li>
|
||||||
<li>Caching</li>
|
<li>Supports Caching</li>
|
||||||
<li>Asynchronous Mode</li>
|
<li>Asynchronous Processing</li>
|
||||||
<li>Custom Matchers</li>
|
<li>Customizable: Matcher, Encoder, Tokenizer, Stemmer, Stopword-Filter</li>
|
||||||
<li>Custom Encoders</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
This features are not available in the 50% smaller <a href="flexsearch.light.js">light version</a>:
|
||||||
|
|
||||||
|
- WebWorker
|
||||||
|
- Async handler
|
||||||
|
- Cache handler
|
||||||
|
- Built-in encoders except 'balanced' (you can still pass in customs)
|
||||||
|
- Built-in stemmers and stopword filter (you can still pass in customs)
|
||||||
|
- Debug logging
|
||||||
|
- _index.info()_ method
|
||||||
|
|
||||||
|
The light version is just available as compiled version (flexsearch.light.js).
|
||||||
|
|
||||||
|
> You can also make <a href="#builds">Custom Builds</a> pretty simple
|
||||||
|
|
||||||
<a name="contextual"></a>
|
<a name="contextual"></a>
|
||||||
#### Contextual Search
|
#### Contextual Search
|
||||||
|
|
||||||
@@ -57,7 +72,7 @@ Imagine you add a text block of some sentences to an index ID. Assuming the quer
|
|||||||
In this way contextual search <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching.html" target="_blank">also improves the results of relevance-based queries</a> on large amount of text data.
|
In this way contextual search <a href="https://rawgit.com/nextapps-de/flexsearch/master/test/matching.html" target="_blank">also improves the results of relevance-based queries</a> on large amount of text data.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/contextual_index.svg">
|
<img src="https://rawgithub.com/nextapps-de/flexsearch/master/doc/contextual_index.svg">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
__Note:__ This feature is actually not enabled by default.
|
__Note:__ This feature is actually not enabled by default.
|
||||||
@@ -93,7 +108,7 @@ __Note:__ It is slightly faster to use no web worker when the index or query isn
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Usecase</td>
|
<td>Usecase</td>
|
||||||
<td><ul><li>Limited content</li><li>Use when existing items of the index needs to be updated continously (update, remove)</li><li>Supports pagination</li></ul></td>
|
<td><ul><li>Limited content</li><li>Use when existing items of the index needs to be updated continously (update, remove)</li><li>Supports pagination</li></ul></td>
|
||||||
<td><ul><li>Fastest possible search</li><li>Existing items of the index does not need to be updated continously (update, remove)</li><li>Max out memory capabilities</li></ul></td>
|
<td><ul><li>Fastest possible search</li><li>Use when existing items of the index does not need to be updated continously (update, remove)</li><li>Max out memory capabilities</li><li>Enhanced relevance scoring</li></ul></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr></tr>
|
<tr></tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -121,6 +136,7 @@ __Note:__ It is slightly faster to use no web worker when the index or query isn
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<a name="installation"></a>
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
##### HTML / Javascript
|
##### HTML / Javascript
|
||||||
@@ -163,6 +179,7 @@ __AMD__
|
|||||||
var FlexSearch = require("./flexsearch.js");
|
var FlexSearch = require("./flexsearch.js");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<a name="api"></a>
|
||||||
## API Overview
|
## API Overview
|
||||||
|
|
||||||
Global methods:
|
Global methods:
|
||||||
@@ -381,7 +398,21 @@ FlexSearch.register('extended', function(str){
|
|||||||
return str;
|
return str;
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
<a name="flexsearch.tokenizer"></a>
|
||||||
|
#### Add custom tokenizer
|
||||||
|
|
||||||
|
Define a private custom tokenizer during creation/initialization:
|
||||||
|
```js
|
||||||
|
var index = new FlexSearch({
|
||||||
|
|
||||||
|
mode: function(str){
|
||||||
|
|
||||||
|
// split string into components, e.g.:
|
||||||
|
|
||||||
|
return str.split(/ -\//g);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
<a name="index.info"></a>
|
<a name="index.info"></a>
|
||||||
#### Get info
|
#### Get info
|
||||||
|
|
||||||
@@ -473,21 +504,23 @@ FlexSearch ist highly customizable. Make use of the the right options can really
|
|||||||
"foward"<br>
|
"foward"<br>
|
||||||
"reverse"<br>
|
"reverse"<br>
|
||||||
"ngram"<br>
|
"ngram"<br>
|
||||||
"full"
|
"full"<br>
|
||||||
|
function()
|
||||||
</td>
|
</td>
|
||||||
<td vertical-align="top">
|
<td vertical-align="top">
|
||||||
The <a href="#tokenizer">indexing mode (tokenizer)</a>.<br>
|
The <a href="#tokenizer">indexing mode (tokenizer)</a>.<br><br>Choose one of the <a href="#tokenizer">built-ins</a> or pass a <a href="#flexsearch.tokenizer">custom tokenizer function</a>.<br>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr></tr>
|
<tr></tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="top">encode<br><br><br><br><br><br></td>
|
<td align="top">encode<br><br><br><br><br><br><br></td>
|
||||||
<td>
|
<td>
|
||||||
false<br>
|
false<br>
|
||||||
"icase"<br>
|
"icase"<br>
|
||||||
"simple"<br>
|
"simple"<br>
|
||||||
"advanced"<br>
|
"advanced"<br>
|
||||||
"extra"<br>
|
"extra"<br>
|
||||||
|
"balanced"<br>
|
||||||
function()
|
function()
|
||||||
</td>
|
</td>
|
||||||
<td>The encoding type.<br><br>Choose one of the <a href="#phonetic">built-ins</a> or pass a <a href="#flexsearch.encoder">custom encoding function</a>.</td>
|
<td>The encoding type.<br><br>Choose one of the <a href="#phonetic">built-ins</a> or pass a <a href="#flexsearch.encoder">custom encoding function</a>.</td>
|
||||||
@@ -574,7 +607,7 @@ Tokenizer effects the required memory also as query time and flexibility of part
|
|||||||
<td><b>"ngram"</b> (default)</td>
|
<td><b>"ngram"</b> (default)</td>
|
||||||
<td>index words partially through phonetic n-grams</td>
|
<td>index words partially through phonetic n-grams</td>
|
||||||
<td><b>foo</b>bar<br>foo<b>bar</b></td>
|
<td><b>foo</b>bar<br>foo<b>bar</b></td>
|
||||||
<td>* n / 3.5</td>
|
<td>* n / 3</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr></tr>
|
<tr></tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -766,7 +799,7 @@ Encoding effects the required memory also as query time and phonetic matches. Tr
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<a name="memory" id="memory"></a>
|
<a name="memory"></a>
|
||||||
## Memory Usage
|
## Memory Usage
|
||||||
|
|
||||||
The required memory for the index depends on several options:
|
The required memory for the index depends on several options:
|
||||||
@@ -812,7 +845,7 @@ The required memory for the index depends on several options:
|
|||||||
<tr></tr>
|
<tr></tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>"ngram" (default)</td>
|
<td>"ngram" (default)</td>
|
||||||
<td>* n / 3.5</td>
|
<td>* n / 3</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr></tr>
|
<tr></tr>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -839,6 +872,7 @@ The required memory for the index depends on several options:
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<a name="examples"></a>
|
||||||
## Example Options
|
## Example Options
|
||||||
|
|
||||||
Memory-optimized:
|
Memory-optimized:
|
||||||
@@ -871,18 +905,51 @@ Matching-tolerant:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Balanced:
|
Well-balanced:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
encode: "simple",
|
encode: "extra",
|
||||||
mode: "ngram",
|
mode: "ngram",
|
||||||
threshold: 3,
|
threshold: 4,
|
||||||
depth: 3
|
depth: 3
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<a name="builds"></a>
|
||||||
|
## Custom Builds
|
||||||
|
|
||||||
|
Default Build:
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
Light Build:
|
||||||
|
```bash
|
||||||
|
npm run build-light
|
||||||
|
```
|
||||||
|
|
||||||
|
Custom Build:
|
||||||
|
```bash
|
||||||
|
npm run build-custom SUPPORT_WORKER=true SUPPORT_ASYNC=true
|
||||||
|
```
|
||||||
|
|
||||||
|
Supported flags:
|
||||||
|
|
||||||
|
- SUPPORT_DEBUG
|
||||||
|
- SUPPORT_WORKER
|
||||||
|
- SUPPORT_CACHE
|
||||||
|
- SUPPORT_ASYNC
|
||||||
|
- SUPPORT_BUILTINS (english stemmer and filter)
|
||||||
|
|
||||||
|
Alternatively you can also use:
|
||||||
|
```bash
|
||||||
|
node compile SUPPORT_WORKER=true
|
||||||
|
```
|
||||||
|
|
||||||
|
The custom build was saved to flexsearch.custom.js
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Author FlexSearch: Thomas Wilkerling<br>
|
Copyright 2017-2018 Thomas Wilkerling<br>
|
||||||
License: <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 License</a><br>
|
Released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 License</a><br>
|
||||||
|
88
compile.js
Normal file
88
compile.js
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
var child_process = require('child_process');
|
||||||
|
|
||||||
|
console.log("Start build .....");
|
||||||
|
|
||||||
|
var parameter = (function(opt){
|
||||||
|
|
||||||
|
var parameter = '';
|
||||||
|
|
||||||
|
for(var index in opt){
|
||||||
|
|
||||||
|
if(opt.hasOwnProperty(index)){
|
||||||
|
|
||||||
|
parameter += ' --' + index + '=' + opt[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(parameter);
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
})({
|
||||||
|
|
||||||
|
compilation_level: "ADVANCED_OPTIMIZATIONS",
|
||||||
|
use_types_for_optimization: true,
|
||||||
|
new_type_inf: true,
|
||||||
|
jscomp_warning: "newCheckTypes",
|
||||||
|
generate_exports: true,
|
||||||
|
export_local_property_definitions: true,
|
||||||
|
language_in: "ECMASCRIPT5_STRICT",
|
||||||
|
language_out: "ECMASCRIPT5_STRICT",
|
||||||
|
process_closure_primitives: true,
|
||||||
|
summary_detail_level: 3,
|
||||||
|
warning_level: "VERBOSE",
|
||||||
|
emit_use_strict: true,
|
||||||
|
output_manifest: "log/manifest.log",
|
||||||
|
output_module_dependencies: "log/module_dependencies.log",
|
||||||
|
property_renaming_report: "log/renaming_report.log"
|
||||||
|
});
|
||||||
|
|
||||||
|
var options = (function(argv){
|
||||||
|
|
||||||
|
var arr = {};
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
argv.forEach(function(val, index) {
|
||||||
|
|
||||||
|
if(++count > 2){
|
||||||
|
|
||||||
|
index = val.split('=');
|
||||||
|
val = index[1];
|
||||||
|
index = index[0];
|
||||||
|
|
||||||
|
arr[index] = val;
|
||||||
|
|
||||||
|
if(count > 3) console.log(index + ': ' + val);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('RELEASE: ' + (arr['RELEASE'] || 'custom'));
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
|
||||||
|
})(process.argv);
|
||||||
|
|
||||||
|
exec("java -jar node_modules/google-closure-compiler/compiler.jar" + parameter + " --define='SUPPORT_DEBUG=" + (options['SUPPORT_DEBUG'] || 'false') + "' --define='SUPPORT_WORKER=" + (options['SUPPORT_WORKER'] || 'false') + "' --define='SUPPORT_BUILTINS=" + (options['SUPPORT_BUILTINS'] || 'false') + "' --define='SUPPORT_CACHE=" + (options['SUPPORT_CACHE'] || 'false') + "' --define='SUPPORT_ASYNC=" + (options['SUPPORT_ASYNC'] || 'false') + "' --js='flexsearch.js' --js_output_file='flexsearch." + (options['RELEASE'] || 'custom') + ".js' && exit 0", function(){
|
||||||
|
|
||||||
|
console.log("Build Complete: flexsearch." + (options['RELEASE'] || 'custom') + ".js");
|
||||||
|
});
|
||||||
|
|
||||||
|
function exec(prompt, callback){
|
||||||
|
|
||||||
|
var child = child_process.exec(prompt, function(err, stdout, stderr){
|
||||||
|
|
||||||
|
if(err){
|
||||||
|
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
|
||||||
|
if(callback){
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
child.stdout.pipe(process.stdout);
|
||||||
|
child.stderr.pipe(process.stderr);
|
||||||
|
}
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
707
flexsearch.js
707
flexsearch.js
File diff suppressed because it is too large
Load Diff
18
flexsearch.light.js
Normal file
18
flexsearch.light.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
FlexSearch v0.2.3
|
||||||
|
Copyright 2017-2018 Thomas Wilkerling
|
||||||
|
Released under the Apache 2.0 Licence
|
||||||
|
https://github.com/nextapps-de/flexsearch
|
||||||
|
*/
|
||||||
|
'use strict';(function(h,t,l){var q;(q=l.define)&&q.amd?q([],function(){return t}):(q=l.modules)?q[h.toLowerCase()]=t:"undefined"!==typeof module?module.exports=t:l[h]=t})("FlexSearch",function(){function h(a){a||(a=y);this.id=a.id||C++;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 l(a){return new RegExp(a,"g")}function q(a,b,c){if("undefined"===typeof c){for(c=0;c<
|
||||||
|
b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}return a.replace(b,c)}function w(a,b,c,g,d,e){if("undefined"===typeof b[c]){var f=d.indexOf(c);f=3/d.length*(d.length-f)+6/(f-d.lastIndexOf(" ",f))+.5|0;b[c]=f;f>e&&(a=a[f],a=a[c]||(a[c]=[]),a[a.length]=g)}return f||b[c]}function A(a){var b=[];if(!a)return b;for(var c=0,g=0,d=0,e="",f=a.length,p=0;p<f;p++){var m=a[p];"a"===m||"e"===m||"i"===m||"o"===m||"u"===m||"y"===m?c++:g++;" "!==m&&(e+=m);if(" "===m||1<c&&1<g||2<c||2<g||p===f-1)e&&(b[d]&&2<e.length&&
|
||||||
|
d++,b[d]=b[d]?b[d]+e:e," "===m&&d++,e=""),g=c=0}return b}function D(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function E(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function F(a,b){var c=[],g=a.length;if(1<g){a.sort(E);for(var d={},e=a[0],f=e.length,p=0;p<f;)d[e[p++]]=1;for(var m,h=0,n=1;n<g;){var r=!1;e=a[n];f=e.length;for(p=0;p<f;)if(d[m=e[p++]]===n){if(n===g-1&&(c[h++]=m,b&&h===b)){r=!1;break}r=!0;d[m]=n+1}if(!r)break;n++}}else g&&(c=a[0],b&&c&&c.length>b&&(c=c.slice(0,b)));return c}var y=
|
||||||
|
{type:"integer",mode:"forward",cache:!1,async:!1,l:!1,threshold:0,depth:0,encode:"icase"},x=[],C=0,B=l("[ -/]");h.new=function(a){return new this(a)};h.create=function(a){return h.new(a)};h.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(x[x.length]=l(b),x[x.length]=a[b]);return this};h.register=function(a,b){v[a]=b;return this};h.encode=function(a,b){return v[a].call(v,b)};h.prototype.init=function(a){this.c=[];if(a&&(this.mode=a.mode||this.mode||y.mode,this.threshold=a.threshold||this.threshold||
|
||||||
|
y.threshold,this.depth=a.depth||this.depth||y.depth,this.h=a.encode&&v[a.encode]||("function"===typeof a.encode?a.encode:this.h||!1),a.matcher&&this.addMatcher(a.matcher),a.filter&&(this.i={}),a.stemmer)){a=!0===a.stemmer?null:a.stemmer;var b=this.h,c=[];if(a){var g=0,d;for(d in a)if(a.hasOwnProperty(d)){var e=b?b.call(v,d):d;c[g++]=l("(?=.{"+(e.length+3)+",})"+e+"$");c[g++]=b?b.call(v,a[d]):a[d]}}this.j=c}this.b=[{},{},{},{},{},{},{},{},{},{},{}];this.a={};this.f="";this.g=!0;return this};h.prototype.encode=
|
||||||
|
function(a){a&&x.length&&(a=q(a,x));a&&this.c.length&&(a=q(a,this.c));a&&this.h&&(a=this.h.call(v,a));if(a&&this.i){a=a.split(" ");for(var b=0;b<a.length;b++){var c=a[b];this.i[c]&&(a[b]=this.i[c])}a=a.join(" ")}a&&this.j&&(a=q(a,this.j));return a};h.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.c[this.c.length]=l(b),this.c[this.c.length]=a[b]);return this};h.prototype.add=function(a,b){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else{b=this.encode(b);
|
||||||
|
if(!b.length)return this;for(var c=this.mode,g="function"===typeof c?c(b):"ngram"===c?A(b):b.split(B),d={_ctx:{}},e=this.threshold,f=this.depth,p=this.b,m=g.length,h=0;h<m;h++){var n=g[h];if(n){var r=n.length;switch(c){case "reverse":case "both":for(var u="",k=r-1;1<=k;k--)u=n[k]+u,w(p,d,u,a,b,e);case "forward":u="";for(k=0;k<r;k++)u+=n[k],w(p,d,u,a,b,e);break;case "full":for(k=0;k<r;k++)for(var l=r;l>k;l--)u=n.substring(k,l),w(p,d,u,a,b,e);break;default:if(k=w(p,d,n,a,b,e),f&&1<m&&k>e)for(k=p[10],
|
||||||
|
r=d._ctx[n]||(d._ctx[n]={}),n=k[n]||(k[n]=[{},{},{},{},{},{},{},{},{},{}]),k=h-f,l=h+f,0>k&&(k=0),l>m-1&&(l=m-1);k<=l;k++)k!==h&&w(n,r,g[k],a,b,e)}}}this.a[a]="1";this.g=!1}return this};h.prototype.update=function(a,b){"string"===typeof b&&(a||0===a)&&this.a[a]&&(this.remove(a),b&&this.add(a,b));return this};h.prototype.remove=function(a){if(this.a[a]){for(var b=0;10>b;b++)for(var c=Object.keys(this.b[b]),g=0;g<c.length;g++){var d=c[g],e=this.b[b];if((e=e&&e[d])&&e.length)for(var f=0;f<e.length;f++)if(e[f]===
|
||||||
|
a){e.splice(f,1);break}e.length||delete this.b[b][d]}delete this.a[a];this.g=!1}return this};h.prototype.search=function(a,b,c){var g=[];if(a&&"object"===typeof a){c=a.callback||b;b=a.limit;var d=a.threshold;a=a.query}d||(d=0);"function"===typeof b?(c=b,b=1E3):b||(b=1E3);if(c){var e=this;G(function(){c(e.search(a,b));e=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return g;if(!this.g)this.g=!0;else if(this.f&&0===a.indexOf(this.f))return g;var f=this.encode(a);if(!f.length)return g;
|
||||||
|
var h=this.mode;f="function"===typeof h?h(f):"ngram"===h?A(f):f.split(B);h=f.length;var m=!0,l=[],n={};if(1<h)if(this.depth){var r=!0,u=f[0];n[u]="1"}else f.sort(D);var k;if(!r||(k=this.b[10])[u])for(var q=r?1:0;q<h;q++){var t=f[q];if(t&&!n[t]){for(var v,x=!1,w=[],y=0,z=9;z>=d;z--)if(v=(r?k[u]:this.b)[z][t])w[y++]=v,x=!0;if(x)l[l.length]=1<y?l.concat.apply([],w):w[0];else{m=!1;break}n[t]="1"}u=t}else m=!1;m&&(g=F(l,b));g.length?this.f="":this.f||(this.f=a);return g};h.prototype.reset=function(){this.destroy();
|
||||||
|
return this.init()};h.prototype.destroy=function(){this.b=this.a=null;return this};var v={icase:function(a){return a.toLowerCase()},balanced:function(){var a=[l("[-/]")," ",l("[^a-z0-9 ]"),"",l("\\s\\s+")," ",l("[aeiouy]"),""];return function(b){b=q(b.toLowerCase(),a);for(var c="",g="",d="",e=0;e<b.length;e++){var f=b[e];if(f!==g)if(e&&"h"===f){if(d="a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d,("a"===g||"e"===g||"i"===g||"o"===g||"u"===g||"y"===g)&&d||" "===g)c+=f}else c+=f;d=e===b.length-
|
||||||
|
1?"":b[e+1];g=f}return c}}()},G=null;return h}(!1),this);
|
48
flexsearch.min.js
vendored
48
flexsearch.min.js
vendored
@@ -1,25 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
|
FlexSearch v0.2.3
|
||||||
|
Copyright 2017-2018 Thomas Wilkerling
|
||||||
|
Released under the Apache 2.0 Licence
|
||||||
https://github.com/nextapps-de/flexsearch
|
https://github.com/nextapps-de/flexsearch
|
||||||
@version: 0.2.2
|
|
||||||
@license: Apache 2.0 Licence
|
|
||||||
*/
|
*/
|
||||||
'use strict';(function(l,C,e){var d;(d=e.define)&&d.amd?d([],function(){return C}):(d=e.modules)?d[l.toLowerCase()]=C:"undefined"!==typeof module?module.exports=C:e[l]=C})("FlexSearch",function H(l){function e(a){a||(a=u);this.id=a.id||I++;this.init(a);Object.defineProperty(this,"index",{get:function(){return this.a}});Object.defineProperty(this,"length",{get:function(){return Object.keys(this.a).length}})}function d(a){return new RegExp(a,"g")}function v(a,b,c){if("undefined"===typeof c){for(c=0;c<
|
'use strict';(function(n,C,f){var p;(p=f.define)&&p.amd?p([],function(){return C}):(p=f.modules)?p[n.toLowerCase()]=C:"undefined"!==typeof module?module.exports=C:f[n]=C})("FlexSearch",function K(n){function f(a){a||(a=u);this.id=a.id||L++;this.init(a);p(this,"index",function(){return this.a});p(this,"length",function(){return Object.keys(this.a).length})}function p(a,b,c){Object.defineProperty(a,b,{get:c})}function d(a){return new RegExp(a,"g")}function v(a,b,c){if("undefined"===typeof c){for(c=
|
||||||
b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}return a.replace(b,c)}function q(a,b,c,h,n,k){if("undefined"===typeof b[c]){var f=n.indexOf(c);f=3/n.length*(n.length-f)+6/(f-n.lastIndexOf(" ",f))+.5|0;b[c]=f;f>k&&(a=a[f],a=a[c]||(a[c]=[]),a[a.length]=h)}return f||b[c]}function x(a){for(var b="",c="",h="",n=0;n<a.length;n++){var k=a[n];if(k!==c)if(n&&"h"===k){if(h="a"===h||"e"===h||"i"===h||"o"===h||"u"===h||"y"===h,("a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c)&&h||" "===c)b+=k}else b+=k;
|
0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}return a.replace(b,c)}function w(a,b,c,e,h,g){if("undefined"===typeof b[c]){var k=h.indexOf(c);k=3/h.length*(h.length-k)+6/(k-h.lastIndexOf(" ",k))+.5|0;b[c]=k;k>g&&(a=a[k],a=a[c]||(a[c]=[]),a[a.length]=e)}return k||b[c]}function x(a){var b=[];if(!a)return b;for(var c=0,e=0,h=0,g="",k=a.length,B=0;B<k;B++){var d=a[B];"a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d?c++:e++;" "!==d&&(g+=d);if(" "===d||1<c&&1<e||2<c||2<e||B===k-1)g&&(b[h]&&2<g.length&&
|
||||||
h=n===a.length-1?"":a[n+1];c=k}return b}function y(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function J(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function K(a,b){var c=[],h=a.length;if(1<h){a.sort(J);for(var n={},k=a[0],f=k.length,D=0;D<f;)n[k[D++]]=1;for(var d,e=0,g=1;g<h;){var p=!1;k=a[g];f=k.length;for(D=0;D<f;)if(n[d=k[D++]]===g){if(g===h-1&&(c[e++]=d,b&&e===b)){p=!1;break}p=!0;n[d]=g+1}if(!p)break;g++}}else h&&(c=a[0],b&&c&&c.length>b&&(c=c.slice(0,b)));return c}function A(a){a.w||
|
h++,b[h]=b[h]?b[h]+g:g," "===d&&h++,g=""),e=c=0}return b}function F(a){for(var b="",c="",e="",h=0;h<a.length;h++){var g=a[h];if(g!==c)if(h&&"h"===g){if(e="a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e,("a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c)&&e||" "===c)b+=g}else b+=g;e=h===a.length-1?"":a[h+1];c=g}return b}function M(a,b){var c={};if(G)for(var e=0;e<a.length;e++){var h=b?b.call(y,a[e]):a[e];c[h]=String.fromCharCode(65E3-a.length+e)}return c}function N(a,b){var c=[];if(a){var e=
|
||||||
(a.w=E(function(){a.w=null;var b=a.async;b&&(a.async=!1);if(a.c.length){for(var c=F(),h;(h=a.c.shift())||0===h;){var d=a.h[h];switch(d[0]){case z.add:a.add(d[1],d[2]);break;case z.update:a.update(d[1],d[2]);break;case z.remove:a.remove(d[1])}a.h[h]=null;delete a.h[h];if(100<F()-c)break}a.c.length&&A(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function F(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}function L(a,b,c,h){a=l("flexsearch","id"+a,function(){var a,b;self.a=
|
0,h;for(h in a)if(a.hasOwnProperty(h)){var g=b?b.call(y,h):h;c[e++]=d("(?=.{"+(g.length+3)+",})"+g+"$");c[e++]=b?b.call(y,a[h]):a[h]}}return c}function O(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function P(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function Q(a,b){var c=[],e=a.length;if(1<e){a.sort(P);for(var h={},g=a[0],d=g.length,B=0;B<d;)h[g[B++]]=1;for(var f,q=0,m=1;m<e;){var r=!1;g=a[m];d=g.length;for(B=0;B<d;)if(h[f=g[B++]]===m){if(m===e-1&&(c[q++]=f,b&&q===b)){r=!1;break}r=!0;h[f]=
|
||||||
function(c){if(c=c.data)c.search?self.postMessage({result:b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit),id:a,content:c.content,limit:c.limit}):c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset():c.info?(c=b.info(),c.worker=a,b.A&&console.log(c)):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("}"))))(),
|
m+1}if(!r)break;m++}}else e&&(c=a[0],b&&c&&c.length>b&&(c=c.slice(0,b)));return c}function E(a){a.B||(a.B=H(function(){a.B=null;var b=a.async;b&&(a.async=!1);if(a.c.length){for(var c=I(),e;(e=a.c.shift())||0===e;){var d=a.h[e];switch(d[0]){case D.add:a.add(d[1],d[2]);break;case D.update:a.update(d[1],d[2]);break;case D.remove:a.remove(d[1])}a.h[e]=null;delete a.h[e];if(100<I()-c)break}a.c.length&&E(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function I(){return"undefined"!==typeof performance?performance.now():
|
||||||
b=new b(c.options))}},function(a){(a=a.data)&&a.result&&h(a.id,a.content,a.result,a.limit)},b);var d=H.toString();c.id=b;a.postMessage(b,{register:d,options:c,id:b});return a}var u={type:"integer",mode:"forward",cache:!1,async:!1,b:!1,threshold:0,depth:0,encode:"icase"},w=[],I=0,z={add:0,update:1,remove:2},G=d("[ -/]");e.new=function(a){return new this(a)};e.create=function(a){return e.new(a)};e.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(w[w.length]=d(b),w[w.length]=a[b]);return this};
|
(new Date).getTime()}function R(a,b,c,e){a=n("flexsearch","id"+a,function(){var a,b;self.a=function(c){if(c=c.data)c.search?self.postMessage({result:b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit),id:a,content:c.content,limit:c.limit}):c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset():c.info?(c=b.info(),c.worker=a,b.C&&console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=!0,c.options.worker=!1,b=
|
||||||
e.register=function(a,b){B[a]=b;return this};e.encode=function(a,b){return B[a].call(B,b)};e.prototype.init=function(a){this.m=[];if(a){if(a.worker)if("undefined"===typeof Worker)a.worker=!1,a.async=!0,this.j=null;else{var b=this,c=parseInt(a.worker,10)||4;b.s=-1;b.o=0;b.i=[];b.v=null;b.j=Array(c);for(var h=0;h<c;h++)b.j[h]=L(b.id,h,a||u,function(a,c,h,d){b.o!==b.b&&(b.i=b.i.concat(h),b.o++,d&&b.i.length>=d&&(b.o=b.b),b.v&&b.o===b.b&&(b.i.length?b.f="":b.f||(b.f=c),b.cache&&b.l.set(c,b.i),b.v(b.i),
|
(new Function(c.register.substring(c.register.indexOf("{")+1,c.register.lastIndexOf("}"))))(),b=new b(c.options))}},function(a){(a=a.data)&&a.result?e(a.id,a.content,a.result,a.limit):c.debug&&console.log(a)},b);var d=K.toString();c.id=b;a.postMessage(b,{register:d,options:c,id:b});return a}var u={type:"integer",mode:"forward",cache:!1,async:!1,b:!1,threshold:0,depth:0,encode:"icase"},z=[],L=0,D={add:0,update:1,remove:2},J=d("[ -/]"),S="a about above after again against all also am an and any are aren't as at be because been before being below both but by can cannot can't come could couldn't did didn't do does doesn't doing dont down during each even few first for from further get go had hadn't has hasn't have haven't having he hed her here here's hers herself hes him himself his how how's i id if ill im in into is isn't it it's itself i've just know let's like make me more most mustn't my myself new no nor not now of off on once only or other ought our our's ourselves out over own same say see shan't she she'd shell shes should shouldn't so some such than that that's the their theirs them themselves then there there's these they they'd they'll they're they've this those through time to too until up us very want was wasn't way we wed well were weren't we've what what's when when's where where's which while who whom who's why why's will with won't would wouldn't you you'd you'll your you're your's yourself yourselves you've".split(" "),
|
||||||
b.i=[]))})}this.mode=a.mode||this.mode||u.mode;this.cache=a.cache||this.cache||u.cache;this.async=a.async||this.async||u.async;this.b=a.worker||this.b||u.b;this.threshold=a.threshold||this.threshold||u.threshold;this.depth=a.depth||this.depth||u.depth;this.encoder=a.encode&&B[a.encode]||("function"===typeof a.encode?a.encode:this.encoder||!1);this.A=a.debug||this.A;a.matcher&&this.addMatcher(a.matcher)}this.g=[{},{},{},{},{},{},{},{},{},{},{}];this.a={};this.h={};this.c=[];this.w=null;this.f="";this.u=
|
G={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log",icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:"",al:"",ance:"",ence:"",er:"",ic:"",able:"",ible:"",ant:"",ement:"",ment:"",ent:"",ou:"",ism:"",ate:"",iti:"",ous:"",ive:"",ize:""};f.new=function(a){return new this(a)};f.create=function(a){return f.new(a)};
|
||||||
!0;this.l=this.cache?new M(3E4,50,!0):!1;return this};e.prototype.encode=function(a){a&&w.length&&(a=v(a,w));a&&this.m.length&&(a=v(a,this.m));a&&this.encoder&&(a=this.encoder.call(B,a));return a};e.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.m[this.m.length]=d(b),this.m[this.m.length]=a[b]);return this};e.prototype.add=function(a,b){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else{if(this.b)return++this.s>=this.j.length&&(this.s=0),this.j[this.s].postMessage(this.s,
|
f.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(z[z.length]=d(b),z[z.length]=a[b]);return this};f.register=function(a,b){y[a]=b;return this};f.encode=function(a,b){return y[a].call(y,b)};f.prototype.init=function(a){this.m=[];if(a){if(a.worker)if("undefined"===typeof Worker)a.worker=!1,a.async=!0,this.j=null;else{var b=this,c=parseInt(a.worker,10)||4;b.s=-1;b.o=0;b.i=[];b.w=null;b.j=Array(c);for(var e=0;e<c;e++)b.j[e]=R(b.id,e,a||u,function(a,c,e,d){b.o!==b.b&&(b.i=b.i.concat(e),b.o++,
|
||||||
{add:!0,id:a,content:b}),this.a[a]=""+this.s,this;if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[z.add,a,b],A(this),this;b=this.encode(b);if(!b.length)return this;if("ngram"===this.mode){var c=b;var h=[];if(c)for(var d=0,k=0,f=0,e="",r=c.length,m=0;m<r;m++){var g=c[m];"a"===g||"e"===g||"i"===g||"o"===g||"u"===g||"y"===g?d++:k++;" "!==g&&(e+=g);if(" "===g||1<d&&1<k||2<d||2<k||m===r-1)e&&(h[f]&&2<e.length&&f++,h[f]=h[f]?h[f]+e:e," "===g&&f++,e=""),k=d=0}c=h}else c=b.split(G);h=
|
d&&b.i.length>=d&&(b.o=b.b),b.w&&b.o===b.b&&(b.i.length?b.f="":b.f||(b.f=c),b.cache&&b.l.set(c,b.i),b.w(b.i),b.i=[]))})}this.mode=a.mode||this.mode||u.mode;this.cache=a.cache||this.cache||u.cache;this.async=a.async||this.async||u.async;this.b=a.worker||this.b||u.b;this.threshold=a.threshold||this.threshold||u.threshold;this.depth=a.depth||this.depth||u.depth;this.v=a.encode&&y[a.encode]||("function"===typeof a.encode?a.encode:this.v||!1);this.C=a.debug||this.C;a.matcher&&this.addMatcher(a.matcher);
|
||||||
{_ctx:{}};d=this.threshold;k=this.depth;f=this.g;e=c.length;for(r=0;r<e;r++)if(m=c[r]){var p=m.length;switch(this.mode){case "reverse":case "both":var t="";for(g=p-1;1<=g;g--)t=m[g]+t,q(f,h,t,a,b,d);case "forward":t="";for(g=0;g<p;g++)t+=m[g],q(f,h,t,a,b,d);break;case "full":for(g=0;g<p;g++)for(var l=p;l>g;l--)t=m.substring(g,l),q(f,h,t,a,b,d);break;default:if(g=q(f,h,m,a,b,d),k&&1<e&&g>d)for(g=f[10],p=h._ctx[m]||(h._ctx[m]={}),m=g[m]||(g[m]=[{},{},{},{},{},{},{},{},{},{}]),g=r-k,l=r+k,0>g&&(g=0),
|
a.filter&&(this.A=M(!0===a.filter?S:a.filter,this.v));a.stemmer&&(this.D=N(!0===a.stemmer?G:a.stemmer,this.v))}this.g=[{},{},{},{},{},{},{},{},{},{},{}];this.a={};this.h={};this.c=[];this.B=null;this.f="";this.u=!0;this.l=this.cache?new T(3E4,50,!0):!1;return this};f.prototype.encode=function(a){a&&z.length&&(a=v(a,z));a&&this.m.length&&(a=v(a,this.m));a&&this.v&&(a=this.v.call(y,a));if(a&&this.A){a=a.split(" ");for(var b=0;b<a.length;b++){var c=a[b];this.A[c]&&(a[b]=this.A[c])}a=a.join(" ")}a&&this.D&&
|
||||||
l>e-1&&(l=e-1);g<=l;g++)g!==r&&q(m,p,c[g],a,b,d)}}this.a[a]="1";this.u=!1}return this};e.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)&&this.a[a]){if(this.b){var c=parseInt(this.a[a],10);this.j[c].postMessage(c,{update:!0,id:a,content:b});return this}if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[z.update,a,b],A(this),this;this.remove(a);b&&this.add(a,b)}return this};e.prototype.remove=function(a){if(this.a[a]){if(this.b){var b=parseInt(this.a[a],10);this.j[b].postMessage(b,
|
(a=v(a,this.D));return a};f.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.m[this.m.length]=d(b),this.m[this.m.length]=a[b]);return this};f.prototype.add=function(a,b){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else{if(this.b)return++this.s>=this.j.length&&(this.s=0),this.j[this.s].postMessage(this.s,{add:!0,id:a,content:b}),this.a[a]=""+this.s,this;if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[D.add,a,b],E(this),this;b=this.encode(b);
|
||||||
{remove:!0,id:a});delete this.a[a];return this}if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[z.remove,a],A(this),this;for(b=0;10>b;b++)for(var c=Object.keys(this.g[b]),d=0;d<c.length;d++){var e=c[d],k=this.g[b];if((k=k&&k[e])&&k.length)for(var f=0;f<k.length;f++)if(k[f]===a){k.splice(f,1);break}k.length||delete this.g[b][e]}delete this.a[a];this.u=!1}return this};e.prototype.search=function(a,b,c){var d=[];if(a&&"object"===typeof a){c=a.callback||b;b=a.limit;var e=a.threshold;
|
if(!b.length)return this;for(var c=this.mode,e="function"===typeof c?c(b):"ngram"===c?x(b):b.split(J),d={_ctx:{}},g=this.threshold,k=this.depth,f=this.g,n=e.length,q=0;q<n;q++){var m=e[q];if(m){var r=m.length;switch(c){case "reverse":case "both":for(var t="",l=r-1;1<=l;l--)t=m[l]+t,w(f,d,t,a,b,g);case "forward":t="";for(l=0;l<r;l++)t+=m[l],w(f,d,t,a,b,g);break;case "full":for(l=0;l<r;l++)for(var A=r;A>l;A--)t=m.substring(l,A),w(f,d,t,a,b,g);break;default:if(l=w(f,d,m,a,b,g),k&&1<n&&l>g)for(l=f[10],
|
||||||
a=a.query}e||(e=0);"function"===typeof b?(c=b,b=1E3):b||(b=1E3);if(this.b){this.v=c;this.o=0;this.i=[];for(d=0;d<this.b;d++)this.j[d].postMessage(d,{search:!0,limit:b,threshold:e,content:a});return null}if(c){var k=this;E(function(){c(k.search(a,b));k=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return d;var f=a;if(!this.u)this.cache&&(this.f="",this.l.reset()),this.u=!0;else if(this.cache){var l=this.l.get(a);if(l)return l}else if(this.f&&0===a.indexOf(this.f))return d;f=this.encode(f);
|
r=d._ctx[m]||(d._ctx[m]={}),m=l[m]||(l[m]=[{},{},{},{},{},{},{},{},{},{}]),l=q-k,A=q+k,0>l&&(l=0),A>n-1&&(A=n-1);l<=A;l++)l!==q&&w(m,r,e[l],a,b,g)}}}this.a[a]="1";this.u=!1}return this};f.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)&&this.a[a]){if(this.b){var c=parseInt(this.a[a],10);this.j[c].postMessage(c,{update:!0,id:a,content:b});return this}if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[D.update,a,b],E(this),this;this.remove(a);b&&this.add(a,b)}return this};
|
||||||
if(!f.length)return d;f=f.constructor===Array?f:f.split(G);l=f.length;var r=!0,m=[],g={};if(1<l)if(this.depth){var p=!0,t=f[0];g[t]="1"}else f.sort(y);var u;if(!p||(u=this.g[10])[t])for(var v=p?1:0;v<l;v++){var q=f[v];if(q&&!g[q]){for(var w,z=!1,x=[],B=0,A=9;A>=e;A--)if(w=(p?u[t]:this.g)[A][q])x[B++]=w,z=!0;if(z)m[m.length]=1<B?m.concat.apply([],x):x[0];else{r=!1;break}g[q]="1"}t=q}else r=!1;r&&(d=K(m,b));d.length?this.f="":this.f||(this.f=a);this.cache&&this.l.set(a,d);return d};e.prototype.info=
|
f.prototype.remove=function(a){if(this.a[a]){if(this.b){var b=parseInt(this.a[a],10);this.j[b].postMessage(b,{remove:!0,id:a});delete this.a[a];return this}if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[D.remove,a],E(this),this;for(b=0;10>b;b++)for(var c=Object.keys(this.g[b]),d=0;d<c.length;d++){var h=c[d],g=this.g[b];if((g=g&&g[h])&&g.length)for(var k=0;k<g.length;k++)if(g[k]===a){g.splice(k,1);break}g.length||delete this.g[b][h]}delete this.a[a];this.u=!1}return this};f.prototype.search=
|
||||||
function(){if(this.b)for(var a=0;a<this.b;a++)this.j[a].postMessage(a,{info:!0,id:this.id});else{for(var b,c,d=0,e=0,k=0,f=0;10>f;f++)for(b=Object.keys(this.g[f]),a=0;a<b.length;a++)c=this.g[f][b[a]].length,d+=c+2*b[a].length+4,e+=c,k+=2*b[a].length;b=Object.keys(this.a);c=b.length;for(a=0;a<c;a++)d+=2*b[a].length+2;return{id:this.id,memory:d,items:c,sequences:e,chars:k,status:this.u,cache:this.c.length,matcher:w.length,worker:this.b}}};e.prototype.reset=function(){this.destroy();return this.init()};
|
function(a,b,c){var d=[];if(a&&"object"===typeof a){c=a.callback||b;b=a.limit;var h=a.threshold;a=a.query}h||(h=0);"function"===typeof b?(c=b,b=1E3):b||(b=1E3);if(this.b){this.w=c;this.o=0;this.i=[];for(d=0;d<this.b;d++)this.j[d].postMessage(d,{search:!0,limit:b,threshold:h,content:a});return null}if(c){var g=this;H(function(){c(g.search(a,b));g=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return d;var k=a;if(!this.u)this.cache&&(this.f="",this.l.reset()),this.u=!0;else if(this.cache){var f=
|
||||||
e.prototype.destroy=function(){this.cache&&this.l.reset();this.g=this.a=this.l=null;return this};var B={icase:function(a){return a.toLowerCase()},simple:function(){var a=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+"),
|
this.l.get(a);if(f)return f}else if(this.f&&0===a.indexOf(this.f))return d;k=this.encode(k);if(!k.length)return d;f=this.mode;k="function"===typeof f?f(k):"ngram"===f?x(k):k.split(J);f=k.length;var n=!0,q=[],m={};if(1<f)if(this.depth){var r=!0,t=k[0];m[t]="1"}else k.sort(O);var l;if(!r||(l=this.g[10])[t])for(var A=r?1:0;A<f;A++){var p=k[A];if(p&&!m[p]){for(var v,w=!1,u=[],y=0,z=9;z>=h;z--)if(v=(r?l[t]:this.g)[z][p])u[y++]=v,w=!0;if(w)q[q.length]=1<y?q.concat.apply([],u):u[0];else{n=!1;break}m[p]=
|
||||||
" "];return function(b){b=v(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){var a=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",d("cc"),"k",d("dt"),"t",d("ph"),"f",d("pf"),"f",d("ou"),"o",d("uo"),"u"];return function(b,c){if(!b)return b;b=this.simple(b);2<b.length&&(b=v(b,a));c||1<b.length&&(b=x(b));return b}}(),extra:function(){var a=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",
|
"1"}t=p}else n=!1;n&&(d=Q(q,b));d.length?this.f="":this.f||(this.f=a);this.cache&&this.l.set(a,d);return d};f.prototype.info=function(){if(this.b)for(var a=0;a<this.b;a++)this.j[a].postMessage(a,{info:!0,id:this.id});else{for(var b,c,d=0,f=0,g=0,k=0;10>k;k++)for(b=Object.keys(this.g[k]),a=0;a<b.length;a++)c=this.g[k][b[a]].length,d+=c+2*b[a].length+4,f+=c,g+=2*b[a].length;b=Object.keys(this.a);c=b.length;for(a=0;a<c;a++)d+=2*b[a].length+2;return{id:this.id,memory:d,items:c,sequences:f,chars:g,status:this.u,
|
||||||
d("[vw]"),"f",d("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var c=0;c<b.length;c++){var d=b[c];1<d.length&&(b[c]=d[0]+v(d.substring(1),a))}b=b.join(" ");b=x(b)}return b}}()},E=function(){var a={};return function(b,c,d){var e=a[d];e&&clearTimeout(e);return a[d]=setTimeout(b,c)}}(),M=function(){function a(){this.cache={}}a.prototype.reset=function(){this.cache={}};a.prototype.set=function(a,c){this.cache[a]=c};a.prototype.get=function(a){return this.cache[a]};
|
cache:this.c.length,matcher:z.length,worker:this.b}}};f.prototype.reset=function(){this.destroy();return this.init()};f.prototype.destroy=function(){this.cache&&this.l.reset();this.g=this.a=this.l=null;return this};var y={icase:function(a){return a.toLowerCase()},simple:function(){var a=[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),
|
||||||
return a}();return e}(function(){var l={},C=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(e,d,v,q,x){var y=e;e=C?URL.createObjectURL(new Blob(["("+v.toString()+")()"],{type:"text/javascript"})):"../"+y+".js";y+="-"+d;l[y]||(l[y]=[]);l[y][x]=new Worker(e);l[y][x].onmessage=q;return{postMessage:function(d,e){l[y][d].postMessage(e)}}}}()),this);
|
"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," "];return function(b){b=v(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){var a=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",d("cc"),"k",d("dt"),"t",d("ph"),"f",d("pf"),"f",d("ou"),"o",d("uo"),"u"];return function(b,c){if(!b)return b;b=this.simple(b);2<b.length&&(b=v(b,a));c||1<
|
||||||
|
b.length&&(b=F(b));return b}}(),extra:function(){var a=[d("p"),"b",d("z"),"s",d("[cgq]"),"k",d("n"),"m",d("d"),"t",d("[vw]"),"f",d("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var c=0;c<b.length;c++){var d=b[c];1<d.length&&(b[c]=d[0]+v(d.substring(1),a))}b=b.join(" ");b=F(b)}return b}}(),balanced:function(){var a=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," ",d("[aeiouy]"),""];return function(b){return F(v(b.toLowerCase(),a))}}()},H=
|
||||||
|
function(){var a={};return function(b,c,d){var e=a[d];e&&clearTimeout(e);return a[d]=setTimeout(b,c)}}(),T=function(){function a(){this.cache={}}a.prototype.reset=function(){this.cache={}};a.prototype.set=function(a,c){this.cache[a]=c};a.prototype.get=function(a){return this.cache[a]};return a}();return f}(function(){var n={},C=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(f,p,d,v,w){var x=f;f=C?URL.createObjectURL(new Blob(["("+d.toString()+")()"],{type:"text/javascript"})):
|
||||||
|
"../"+x+".js";x+="-"+p;n[x]||(n[x]=[]);n[x][w]=new Worker(f);n[x][w].onmessage=v;console.log("Register Worker: "+x+"@"+w);return{postMessage:function(d,f){n[x][d].postMessage(f)}}}}()),this);
|
||||||
|
13
package.json
13
package.json
@@ -1,23 +1,26 @@
|
|||||||
{
|
{
|
||||||
"name": "flexsearch",
|
"name": "flexsearch",
|
||||||
"version": "0.2.2",
|
"version": "0.2.3",
|
||||||
"description": "World's fastest and most memory efficient full text search library.",
|
"description": "World's fastest and most memory efficient full text search library.",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/nextapps-de/flexsearch/issues",
|
"url": "https://github.com/nextapps-de/flexsearch/issues",
|
||||||
"email": "info@nextapps.de"
|
"email": "info@nextapps.de"
|
||||||
},
|
},
|
||||||
"main": "flexsearch.js",
|
"main": "flexsearch.min.js",
|
||||||
"preferGlobal": true,
|
"preferGlobal": false,
|
||||||
"bin": {},
|
"bin": {},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/nextapps-de/flexsearch.git"
|
"url": "https://github.com/nextapps-de/flexsearch.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "java -jar -Xms256m -Xmx4096m node_modules/google-closure-compiler/compiler.jar --compilation_level=ADVANCED_OPTIMIZATIONS --use_types_for_optimization=true --new_type_inf=true --jscomp_warning=newCheckTypes --generate_exports=true --export_local_property_definitions=true --language_in=ECMASCRIPT5_STRICT --language_out=ECMASCRIPT5_STRICT --process_closure_primitives=true --summary_detail_level=3 --warning_level=VERBOSE --emit_use_strict=true --output_manifest=log/manifest.log --output_module_dependencies=log/module_dependencies.log --property_renaming_report=log/renaming_report.log --js='flexsearch.js' --js_output_file='flexsearch.min.js' && echo Build Complete. && exit 0",
|
"build": "node compile RELEASE=min SUPPORT_DEBUG=true SUPPORT_WORKER=true SUPPORT_BUILTINS=true SUPPORT_CACHE=true SUPPORT_ASYNC=true && exit 0",
|
||||||
"release": "npm version patch && npm run build && npm publish",
|
"build-light": "node compile RELEASE=light SUPPORT_DEBUG=false SUPPORT_WORKER=false SUPPORT_BUILTINS=false SUPPORT_CACHE=false SUPPORT_ASYNC=false && exit 0",
|
||||||
|
"build-custom": "node compile",
|
||||||
|
"build-all": "npm run build && npm run build-light",
|
||||||
"test-production": "nyc --reporter=html --reporter=text mocha --timeout=3000 test --exit",
|
"test-production": "nyc --reporter=html --reporter=text mocha --timeout=3000 test --exit",
|
||||||
|
"test-light": "nyc --reporter=html --reporter=text mocha --timeout=3000 test/ --exit",
|
||||||
"test-develop": "nyc --reporter=html --reporter=text mocha --timeout=3000 --exit",
|
"test-develop": "nyc --reporter=html --reporter=text mocha --timeout=3000 --exit",
|
||||||
"test-browser": "mocha-phantomjs test/index.html",
|
"test-browser": "mocha-phantomjs test/index.html",
|
||||||
"test": "npm run test-develop && npm run test-production && npm run test-browser",
|
"test": "npm run test-develop && npm run test-production && npm run test-browser",
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Matching Test</title>
|
<title>Matching Test</title>
|
||||||
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script>
|
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script><!--<script src="../flexsearch.min.js"></script>-->
|
||||||
<script src="https://rawgit.com/nextapps-de/bulksearch/master/bulksearch.min.js"></script>
|
<script src="https://rawgit.com/nextapps-de/bulksearch/master/bulksearch.min.js"></script>
|
||||||
<script src="https://cdn.rawgit.com/weixsong/elasticlunr.js/master/example/elasticlunr.min.js"></script>
|
<script src="https://cdn.rawgit.com/weixsong/elasticlunr.js/master/example/elasticlunr.min.js"></script>
|
||||||
<script src="https://unpkg.com/lunr@2.1.6/lunr.js"></script>
|
<script src="https://unpkg.com/lunr@2.1.6/lunr.js"></script>
|
||||||
@@ -68,7 +68,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
|||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="test-3">
|
<tr id="test-3">
|
||||||
<td>"i already observed"</td>
|
<td>"princes of the ambition"</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
@@ -80,7 +80,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
|||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="test-4">
|
<tr id="test-4">
|
||||||
<td>"let a of his"</td>
|
<td>"five-thousand leagues"</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
@@ -92,7 +92,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
|||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="test-5">
|
<tr id="test-5">
|
||||||
<td>"take that to the rocks"</td>
|
<td>"i already observed"</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
@@ -104,7 +104,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
|||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="test-6">
|
<tr id="test-6">
|
||||||
<td>"bignes of splaknuk"</td>
|
<td>"let a of his"</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
@@ -116,7 +116,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
|||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="test-7">
|
<tr id="test-7">
|
||||||
<td>"matematikal musikal instruments"</td>
|
<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>
|
||||||
@@ -128,6 +128,30 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
|||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="test-8">
|
<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>
|
||||||
|
<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>
|
||||||
|
<td>wait ...</td>
|
||||||
|
<td>wait ...</td>
|
||||||
|
</tr>
|
||||||
|
<tr id="test-10">
|
||||||
<td>"lalkon the camberlayhn"</td>
|
<td>"lalkon the camberlayhn"</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
<td>wait ...</td>
|
<td>wait ...</td>
|
||||||
@@ -197,6 +221,8 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
|||||||
mode: 'strict',
|
mode: 'strict',
|
||||||
threshold: 4,
|
threshold: 4,
|
||||||
depth: 3,
|
depth: 3,
|
||||||
|
filter: true,
|
||||||
|
stemmer: true,
|
||||||
async: false,
|
async: false,
|
||||||
cache: false,
|
cache: false,
|
||||||
worker: false
|
worker: false
|
||||||
@@ -297,12 +323,14 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
|||||||
|
|
||||||
do_test('test-1', 'without breach of modesty', '493');
|
do_test('test-1', 'without breach of modesty', '493');
|
||||||
do_test('test-2', 'went softly stream', '446');
|
do_test('test-2', 'went softly stream', '446');
|
||||||
do_test('test-3', 'i already observed', '458');
|
do_test('test-3', 'princes of the ambition', '72');
|
||||||
do_test('test-4', 'let a of his', '50');
|
do_test('test-4', 'five-thousand leagues', '2');
|
||||||
do_test('test-5', 'take that to the rocks', '175');
|
do_test('test-5', 'i already observed', '458');
|
||||||
do_test('test-6', 'bignes of splaknuk', '146');
|
do_test('test-6', 'let a of his', '50');
|
||||||
do_test('test-7', 'matematikal musikal instruments', '267');
|
do_test('test-7', 'take that to the rocks', '175');
|
||||||
do_test('test-8', 'lalkon the camberlayhn', '99');
|
do_test('test-8', 'bignes of splaknuk', '146');
|
||||||
|
do_test('test-9', 'matematikal musikal instruments', '267');
|
||||||
|
do_test('test-10', 'lalkon the camberlayhn', '99');
|
||||||
|
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
|
|
||||||
|
124
test/test.js
124
test/test.js
@@ -6,9 +6,9 @@ if(typeof module !== 'undefined'){
|
|||||||
URL.createObjectURL = function(val){};
|
URL.createObjectURL = function(val){};
|
||||||
Blob = function(string){};
|
Blob = function(string){};
|
||||||
|
|
||||||
var env = process.argv[3] === 'test' ? '.min' : '';
|
var env = process.argv[3] === 'test' ? 'min' : process.argv[3] === 'test/' ? 'light' : '';
|
||||||
var expect = require('chai').expect;
|
var expect = require('chai').expect;
|
||||||
var FlexSearch = require("../flexsearch" + env + ".js");
|
var FlexSearch = require("../flexsearch" + (env ? '.' + env : '') + ".js");
|
||||||
}
|
}
|
||||||
|
|
||||||
var flexsearch_default;
|
var flexsearch_default;
|
||||||
@@ -148,7 +148,11 @@ describe('Initialize', function(){
|
|||||||
expect(flexsearch_default).to.respondTo("remove");
|
expect(flexsearch_default).to.respondTo("remove");
|
||||||
expect(flexsearch_default).to.respondTo("reset");
|
expect(flexsearch_default).to.respondTo("reset");
|
||||||
expect(flexsearch_default).to.respondTo("init");
|
expect(flexsearch_default).to.respondTo("init");
|
||||||
expect(flexsearch_default).to.respondTo("info");
|
|
||||||
|
if(env !== 'light'){
|
||||||
|
|
||||||
|
expect(flexsearch_default).to.respondTo("info");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should have correct uuids', function(){
|
it('Should have correct uuids', function(){
|
||||||
@@ -168,12 +172,17 @@ describe('Initialize', function(){
|
|||||||
expect(flexsearch_default.mode).to.equal("forward");
|
expect(flexsearch_default.mode).to.equal("forward");
|
||||||
expect(flexsearch_sync.async).to.equal(false);
|
expect(flexsearch_sync.async).to.equal(false);
|
||||||
expect(flexsearch_async.async).to.equal(true);
|
expect(flexsearch_async.async).to.equal(true);
|
||||||
expect(flexsearch_custom.encoder).to.equal(test_encoder);
|
|
||||||
expect(flexsearch_strict.mode).to.equal("strict");
|
expect(flexsearch_strict.mode).to.equal("strict");
|
||||||
expect(flexsearch_forward.mode).to.equal("forward");
|
expect(flexsearch_forward.mode).to.equal("forward");
|
||||||
expect(flexsearch_reverse.mode).to.equal("reverse");
|
expect(flexsearch_reverse.mode).to.equal("reverse");
|
||||||
expect(flexsearch_full.mode).to.equal("full");
|
expect(flexsearch_full.mode).to.equal("full");
|
||||||
expect(flexsearch_ngram.mode).to.equal("ngram");
|
expect(flexsearch_ngram.mode).to.equal("ngram");
|
||||||
|
|
||||||
|
// not available in compiled version:
|
||||||
|
if(typeof flexsearch_custom.encoder !== 'undefined'){
|
||||||
|
|
||||||
|
expect(flexsearch_custom.encoder).to.equal(test_encoder);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -223,13 +232,16 @@ describe('Search (Sync)', function(){
|
|||||||
expect(flexsearch_sync.search("foo foo")).to.have.members([0, 1]);
|
expect(flexsearch_sync.search("foo foo")).to.have.members([0, 1]);
|
||||||
expect(flexsearch_sync.search("foo foo")).to.have.members([0, 1]);
|
expect(flexsearch_sync.search("foo foo")).to.have.members([0, 1]);
|
||||||
|
|
||||||
flexsearch_extra.add(4, "Thomas");
|
if(env !== 'light'){
|
||||||
flexsearch_extra.add(5, "Arithmetic");
|
|
||||||
flexsearch_extra.add(6, "Mahagoni");
|
|
||||||
|
|
||||||
expect(flexsearch_extra.search("tomass")).to.include(4);
|
flexsearch_extra.add(4, "Thomas");
|
||||||
expect(flexsearch_extra.search("arytmetik")).to.include(5);
|
flexsearch_extra.add(5, "Arithmetic");
|
||||||
expect(flexsearch_extra.search("mahagony")).to.include(6);
|
flexsearch_extra.add(6, "Mahagoni");
|
||||||
|
|
||||||
|
expect(flexsearch_extra.search("tomass")).to.include(4);
|
||||||
|
expect(flexsearch_extra.search("arytmetik")).to.include(5);
|
||||||
|
expect(flexsearch_extra.search("mahagony")).to.include(6);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should have been limited', function(){
|
it('Should have been limited', function(){
|
||||||
@@ -843,6 +855,7 @@ describe('Context', function(){
|
|||||||
expect(flexsearch_depth.search("zero three").length).to.equal(0);
|
expect(flexsearch_depth.search("zero three").length).to.equal(0);
|
||||||
expect(flexsearch_depth.search("three seven").length).to.equal(0);
|
expect(flexsearch_depth.search("three seven").length).to.equal(0);
|
||||||
expect(flexsearch_depth.search("three five seven")).to.include(0);
|
expect(flexsearch_depth.search("three five seven")).to.include(0);
|
||||||
|
expect(flexsearch_depth.search("eight six four")).to.include(0);
|
||||||
// TODO
|
// TODO
|
||||||
// expect(flexsearch_depth.search("three seven five")).to.include(0);
|
// expect(flexsearch_depth.search("three seven five")).to.include(0);
|
||||||
expect(flexsearch_depth.search("three foobar seven").length).to.equal(0);
|
expect(flexsearch_depth.search("three foobar seven").length).to.equal(0);
|
||||||
@@ -961,13 +974,14 @@ describe('Relevance', function(){
|
|||||||
|
|
||||||
index.add(0, "1 2 3 2 4 1 5 3");
|
index.add(0, "1 2 3 2 4 1 5 3");
|
||||||
index.add(1, "zero one two three four five six seven eight nine ten");
|
index.add(1, "zero one two three four five six seven eight nine ten");
|
||||||
index.add(2, "four two zero one three ten five seven eight six nine");
|
index.add(2, "five two zero one three four ten seven eight six nine");
|
||||||
|
|
||||||
expect(index.search("1 3 4")).to.have.members([0]);
|
expect(index.search("1 3 4")).to.have.members([0]);
|
||||||
expect(index.search("1 5 3 4")).to.have.members([0]);
|
expect(index.search("1 5 3 4")).to.have.members([0]);
|
||||||
expect(index.search("one")).to.have.members([1, 2]);
|
expect(index.search("one")).to.have.members([1, 2]);
|
||||||
expect(index.search("one two")).to.have.members([1, 2]);
|
expect(index.search("one three")).to.have.members([1, 2]);
|
||||||
expect(index.search("four one")).to.have.members([1, 2]);
|
expect(index.search("three one")).to.have.members([1, 2]);
|
||||||
|
expect(index.search("zero five one ten")).to.have.members([2]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1016,67 +1030,73 @@ describe('Add Matchers', function(){
|
|||||||
// Caching
|
// Caching
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
describe('Caching', function(){
|
if(env !== 'light'){
|
||||||
|
|
||||||
it('Should have been cached properly', function(){
|
describe('Caching', function(){
|
||||||
|
|
||||||
flexsearch_cache.add(0, 'foo')
|
it('Should have been cached properly', function(){
|
||||||
.add(1, 'bar')
|
|
||||||
.add(2, 'foobar');
|
|
||||||
// fetch:
|
|
||||||
|
|
||||||
expect(flexsearch_cache.search("foo")).to.have.members([0, 2]);
|
flexsearch_cache.add(0, 'foo')
|
||||||
expect(flexsearch_cache.search("bar")).to.have.members([1, 2]);
|
.add(1, 'bar')
|
||||||
expect(flexsearch_cache.search("foobar")).to.include(2);
|
.add(2, 'foobar');
|
||||||
|
// fetch:
|
||||||
|
|
||||||
// cache:
|
expect(flexsearch_cache.search("foo")).to.have.members([0, 2]);
|
||||||
|
expect(flexsearch_cache.search("bar")).to.have.members([1, 2]);
|
||||||
|
expect(flexsearch_cache.search("foobar")).to.include(2);
|
||||||
|
|
||||||
expect(flexsearch_cache.search("foo")).to.have.members([0, 2]);
|
// cache:
|
||||||
expect(flexsearch_cache.search("bar")).to.have.members([1, 2]);
|
|
||||||
expect(flexsearch_cache.search("foobar")).to.include(2);
|
|
||||||
|
|
||||||
// update:
|
expect(flexsearch_cache.search("foo")).to.have.members([0, 2]);
|
||||||
|
expect(flexsearch_cache.search("bar")).to.have.members([1, 2]);
|
||||||
|
expect(flexsearch_cache.search("foobar")).to.include(2);
|
||||||
|
|
||||||
flexsearch_cache.remove(2).update(1, 'foo').add(3, 'foobar');
|
// update:
|
||||||
|
|
||||||
// fetch:
|
flexsearch_cache.remove(2).update(1, 'foo').add(3, 'foobar');
|
||||||
|
|
||||||
expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]);
|
// fetch:
|
||||||
expect(flexsearch_cache.search("bar")).to.include(3);
|
|
||||||
expect(flexsearch_cache.search("foobar")).to.include(3);
|
|
||||||
|
|
||||||
// cache:
|
expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]);
|
||||||
|
expect(flexsearch_cache.search("bar")).to.include(3);
|
||||||
|
expect(flexsearch_cache.search("foobar")).to.include(3);
|
||||||
|
|
||||||
expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]);
|
// cache:
|
||||||
expect(flexsearch_cache.search("bar")).to.include(3);
|
|
||||||
expect(flexsearch_cache.search("foobar")).to.include(3);
|
expect(flexsearch_cache.search("foo")).to.have.members([0, 1, 3]);
|
||||||
|
expect(flexsearch_cache.search("bar")).to.include(3);
|
||||||
|
expect(flexsearch_cache.search("foobar")).to.include(3);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Debug Information
|
// Debug Information
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
describe('Debug', function(){
|
if(env !== 'light'){
|
||||||
|
|
||||||
it('Should have been debug mode activated', function(){
|
describe('Debug', function(){
|
||||||
|
|
||||||
var info = flexsearch_cache.info();
|
it('Should have been debug mode activated', function(){
|
||||||
|
|
||||||
expect(info).to.have.keys([
|
var info = flexsearch_cache.info();
|
||||||
|
|
||||||
'id',
|
expect(info).to.have.keys([
|
||||||
'chars',
|
|
||||||
'status',
|
'id',
|
||||||
'cache',
|
'chars',
|
||||||
'items',
|
'status',
|
||||||
'matcher',
|
'cache',
|
||||||
'memory',
|
'items',
|
||||||
'sequences',
|
'matcher',
|
||||||
'worker'
|
'memory',
|
||||||
]);
|
'sequences',
|
||||||
|
'worker'
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Chaining
|
// Chaining
|
||||||
|
Reference in New Issue
Block a user