1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-02 02:12:46 +02:00

ADD suggestions

This commit is contained in:
Thomas Wilkerling
2018-03-27 19:16:15 +02:00
parent 2b5d9ceed7
commit aae24b5e3b
8 changed files with 267 additions and 110 deletions

View File

@@ -7,17 +7,14 @@
<img src="https://img.shields.io/badge/status-BETA-orange.svg"> <img src="https://img.shields.io/badge/status-BETA-orange.svg">
<a target="_blank" href="https://travis-ci.org/nextapps-de/flexsearch"><img src="https://travis-ci.org/nextapps-de/flexsearch.svg?branch=master"></a> <a target="_blank" href="https://travis-ci.org/nextapps-de/flexsearch"><img src="https://travis-ci.org/nextapps-de/flexsearch.svg?branch=master"></a>
<a target="_blank" href="https://coveralls.io/github/nextapps-de/flexsearch?branch=master"><img src="https://coveralls.io/repos/github/nextapps-de/flexsearch/badge.svg?branch=master"></a> <a target="_blank" href="https://coveralls.io/github/nextapps-de/flexsearch?branch=master"><img src="https://coveralls.io/repos/github/nextapps-de/flexsearch/badge.svg?branch=master"></a>
<a target="_blank" href="https://github.com/nextapps-de/flexsearch/issues"><img src="https://img.shields.io/github/issues/nextapps-de/xone.svg"></a> <a target="_blank" href="https://github.com/nextapps-de/flexsearch/issues"><img src="https://img.shields.io/github/issues/nextapps-de/xone.svg"></a><!--<img src="https://badges.greenkeeper.io/nextapps-de/flexsearch.svg">-->
<img src="https://badges.greenkeeper.io/nextapps-de/flexsearch.svg">
<a target="_blank" href="https://github.com/nextapps-de/flexsearch/blob/master/LICENSE.md"><img src="https://img.shields.io/npm/l/xone.svg"></a> <a target="_blank" href="https://github.com/nextapps-de/flexsearch/blob/master/LICENSE.md"><img src="https://img.shields.io/npm/l/xone.svg"></a>
</p> </p>
<h1></h1> <h1></h1>
<h3>World's fastest and most memory efficient full text search library with zero dependencies.</h3> <h3>World's fastest and most memory efficient full text search library with zero dependencies.</h3>
When it comes to raw search speed <a href="https://jsperf.com/compare-search-libraries" 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. When it comes to raw search speed <a href="https://jsperf.com/compare-search-libraries" 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>. It also has the <a href="#memory">most memory-efficient index</a>.<!-- 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.-->
<!--
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 or queries on the index in parallel through dedicated balanced threads. 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> <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>
@@ -201,13 +198,15 @@ var FlexSearch = require("./flexsearch.js");
Global methods: Global methods:
- <a href="#flexsearch.create">FlexSearch.__create__(\<options\>)</a> - <a href="#flexsearch.create">FlexSearch.__create__(\<options\>)</a>
- <a href="#flexsearch.registerMatcher">FlexSearch.__registerMatcher__({_KEY: VALUE_})</a> - <a href="#flexsearch.addmatcher">FlexSearch.__registerMatcher__({_KEY: VALUE_})</a>
- <a href="#flexsearch.registerEncoder">FlexSearch.__registerEncoder__(name, encoder)</a> - <a href="#flexsearch.register">FlexSearch.__registerEncoder__(name, encoder)</a>
- <a href="#flexsearch.language">FlexSearch.__registerLanguage__(lang, {stemmer:{}, filter:[]})</a>
- <a href="#flexsearch.encode">FlexSearch.__encode__(name, string)</a> - <a href="#flexsearch.encode">FlexSearch.__encode__(name, string)</a>
Index methods: Index methods:
- <a href="#index.add">Index.__add__(id, string)</a> - <a href="#index.add">Index.__add__(id, string)</a>
- <a href="#index.search">Index.__search__(string, \<limit\>, \<callback\>)</a> - <a href="#index.search">Index.__search__(string, \<limit\>, \<callback\>)</a>
- <a href="#index.search">Index.__search__(\<options\>)</a>
- <a href="#index.update">Index.__update__(id, string)</a> - <a href="#index.update">Index.__update__(id, string)</a>
- <a href="#index.remove">Index.__remove__(id)</a> - <a href="#index.remove">Index.__remove__(id)</a>
- <a href="#index.reset">Index.__reset__()</a> - <a href="#index.reset">Index.__reset__()</a>
@@ -296,20 +295,38 @@ index.search({
query: "John", query: "John",
limit: 1000, limit: 1000,
threshold: 5, // >= initial threshold threshold: 5, // >= initial threshold
depth: 3 // <= initial depth depth: 3, // <= initial depth
callback: function(results){/* ... */}
}); });
``` ```
Get suggestions of a query: The same from above could also be written as:
```js
index.search("John", {
limit: 1000,
threshold: 5,
depth: 3
}, function(results){
// ....
});
```
Get also suggestions for a query:
```js ```js
index.search({ index.search({
query: "John", query: "John Doe",
suggest: true suggest: true
}); });
``` ```
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> <a name="index.update"></a>
#### Update item to the index #### Update item to the index
@@ -461,7 +478,7 @@ var index = new FlexSearch({
} }
}); });
``` ```
<a name="flexsearch.stemmer"></a> <a name="flexsearch.language"></a>
#### Add language-specific stemmer and/or filter #### Add language-specific stemmer and/or filter
> __Stemmer:__ several linguistic mutations of the same word (e.g. "run" and "running") > __Stemmer:__ several linguistic mutations of the same word (e.g. "run" and "running")

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -1,5 +1,5 @@
;/**! ;/**!
* @preserve FlexSearch v0.2.46 * @preserve FlexSearch v0.2.48
* Copyright 2018 Thomas Wilkerling * Copyright 2018 Thomas Wilkerling
* Released under the Apache 2.0 Licence * Released under the Apache 2.0 Licence
* https://github.com/nextapps-de/flexsearch * https://github.com/nextapps-de/flexsearch
@@ -37,6 +37,7 @@ var SUPPORT_ASYNC = true;
encode: 'icase', encode: 'icase',
mode: 'ngram', mode: 'ngram',
suggest: false,
cache: false, cache: false,
async: false, async: false,
worker: false, worker: false,
@@ -315,13 +316,16 @@ var SUPPORT_ASYNC = true;
if(self._current_callback && (self._task_completed === self.worker)){ if(self._current_callback && (self._task_completed === self.worker)){
if(self._task_result.length){ if(typeof self._last_empty_query !== 'undefined'){
self._last_empty_query = ""; if(self._task_result.length){
}
else{
self._last_empty_query || (self._last_empty_query = query); self._last_empty_query = "";
}
else{
self._last_empty_query || (self._last_empty_query = query);
}
} }
// store result to cache // store result to cache
@@ -379,6 +383,13 @@ var SUPPORT_ASYNC = true;
defaults.depth defaults.depth
); );
this.suggest = (
options['suggest'] ||
this.suggest ||
defaults.suggest
);
custom = options['encode'] || profile.encode; custom = options['encode'] || profile.encode;
this.encoder = ( this.encoder = (
@@ -434,9 +445,13 @@ var SUPPORT_ASYNC = true;
*/ */
this._timer = null; this._timer = null;
this._last_empty_query = "";
this._status = true; this._status = true;
if(this.mode === 'forward' || this.mode === 'reverse' || this.mode === 'both'){
this._last_empty_query = "";
}
if(SUPPORT_CACHE) { if(SUPPORT_CACHE) {
this.cache = custom = ( this.cache = custom = (
@@ -479,6 +494,8 @@ var SUPPORT_ASYNC = true;
value = this.encoder.call(global_encoder, value); value = this.encoder.call(global_encoder, value);
} }
// TODO completely filter out words actually can break the context chain
/*
if(value && this.filter){ if(value && this.filter){
var words = value.split(' '); var words = value.split(' ');
@@ -493,7 +510,6 @@ var SUPPORT_ASYNC = true;
//var length = word.length - 1; //var length = word.length - 1;
// TODO completely filter out words actually breaks the context chain
words[i] = filter; words[i] = filter;
//words[i] = word[0] + (length ? word[1] : ''); //words[i] = word[0] + (length ? word[1] : '');
//words[i] = '~' + word[0]; //words[i] = '~' + word[0];
@@ -505,6 +521,7 @@ var SUPPORT_ASYNC = true;
value = words.join(' '); // final; value = words.join(' '); // final;
} }
*/
if(value && this.stemmer){ if(value && this.stemmer){
@@ -934,7 +951,11 @@ var SUPPORT_ASYNC = true;
if(SUPPORT_CACHE && this.cache){ if(SUPPORT_CACHE && this.cache){
this._last_empty_query = ""; if(typeof this._last_empty_query !== 'undefined'){
this._last_empty_query = "";
}
this._cache.reset(); this._cache.reset();
} }
@@ -955,7 +976,7 @@ var SUPPORT_ASYNC = true;
// validate last query // validate last query
else if(this._last_empty_query && (query.indexOf(this._last_empty_query) === 0)){ else if((typeof this._last_empty_query !== 'undefined') && this._last_empty_query && (query.indexOf(this._last_empty_query) === 0)){
return result; return result;
} }
@@ -1047,10 +1068,13 @@ var SUPPORT_ASYNC = true;
if(!map_found){ if(!map_found){
found = false; if(!this.suggest){
break;
found = false;
break;
}
} }
else{ else {
// Not handled by intersection: // Not handled by intersection:
@@ -1083,20 +1107,23 @@ var SUPPORT_ASYNC = true;
// Not handled by intersection: // Not handled by intersection:
result = intersect(check, limit); result = intersect(check, limit, this.suggest);
// Handled by intersection: // Handled by intersection:
//result = intersect_3d(check, limit); //result = intersect_3d(check, limit, this.suggest);
} }
if(result.length){ if(typeof this._last_empty_query !== 'undefined'){
this._last_empty_query = ""; if(result.length){
}
else{
this._last_empty_query || (this._last_empty_query = query); this._last_empty_query = "";
}
else{
this._last_empty_query || (this._last_empty_query = query);
}
} }
// store result to cache // store result to cache
@@ -2007,12 +2034,14 @@ var SUPPORT_ASYNC = true;
/** /**
* @param {!Array<Array<number|string>>} arrays * @param {!Array<Array<number|string>>} arrays
* @param {number=} limit * @param {number=} limit
* @param {boolean=} suggest
* @returns {Array} * @returns {Array}
*/ */
function intersect(arrays, limit) { function intersect(arrays, limit, suggest) {
var result = []; var result = [];
var suggestions = [];
var length_z = arrays.length; var length_z = arrays.length;
if(length_z > 1){ if(length_z > 1){
@@ -2043,25 +2072,28 @@ var SUPPORT_ASYNC = true;
// get each array one by one // get each array one by one
var found = false; var found = false;
var is_final_loop = (z === (length_z - 1));
suggestions = [];
arr = arrays[z]; arr = arrays[z];
length = arr.length; length = arr.length;
i = 0; i = -1;
while(i < length){ while(i < length){
if((check[tmp = arr[i++]]) === z){ var check_val = check[tmp = arr[++i]];
if(check_val === z){
// fill in during last round // fill in during last round
if(z === (length_z - 1)){ if(is_final_loop){
result[count++] = tmp; result[count++] = tmp;
if(limit && (count === limit)){ if(limit && (count === limit)){
found = false; return result;
break;
} }
} }
@@ -2070,15 +2102,49 @@ var SUPPORT_ASYNC = true;
found = true; found = true;
check[tmp] = z + 1; check[tmp] = z + 1;
} }
else if(suggest){
var current_suggestion = suggestions[check_val] || (suggestions[check_val] = []);
current_suggestion[current_suggestion.length] = tmp;
}
} }
if(!found){ if(!found && !suggest){
break; break;
} }
z++; z++;
} }
if(suggest){
limit || (limit = 1000);
count = result.length;
length = suggestions.length;
if((count < limit) && length){
for(z = length - 1; z >= 0; z--){
tmp = suggestions[z];
if(tmp){
for(i = 0; i < tmp.length; i++){
result[count++] = tmp[i];
if(limit && (count === limit)){
return result;
}
}
}
}
}
}
} }
else if(length_z){ else if(length_z){
@@ -2088,7 +2154,7 @@ var SUPPORT_ASYNC = true;
// Note: do not modify the original index array! // Note: do not modify the original index array!
return result.slice(0, limit); result = result.slice(0, limit);
} }
// Note: handle references to the original index array // Note: handle references to the original index array
@@ -2285,10 +2351,10 @@ var SUPPORT_ASYNC = true;
ref.add(current[1], current[2]); ref.add(current[1], current[2]);
break; break;
case enum_task.update: // case enum_task.update:
//
ref.update(current[1], current[2]); // ref.update(current[1], current[2]);
break; // break;
case enum_task.remove: case enum_task.remove:

View File

@@ -1,19 +1,20 @@
/* /*
FlexSearch v0.2.46 FlexSearch v0.2.48
Copyright 2018 Thomas Wilkerling Copyright 2018 Thomas Wilkerling
Released under the Apache 2.0 Licence Released under the Apache 2.0 Licence
https://github.com/nextapps-de/flexsearch https://github.com/nextapps-de/flexsearch
*/ */
'use strict';(function(d,w,p){var q;(q=p.define)&&q.amd?q([],function(){return w}):(q=p.modules)?q[d.toLowerCase()]=w:"undefined"!==typeof module?module.exports=w:p[d]=w})("FlexSearch",function(){function d(a){"string"===typeof a&&(a=B[a]);a||(a=z);this.id=a.id||G++;this.init(a);w(this,"index",function(){return this.a});w(this,"length",function(){return Object.keys(this.a).length})}function w(a,b,c){Object.defineProperty(a,b,{get:c})}function p(a){return new RegExp(a,"g")}function q(a,b,c){if("undefined"=== 'use strict';(function(e,v,n){var t;(t=n.define)&&t.amd?t([],function(){return v}):(t=n.modules)?t[e.toLowerCase()]=v:"undefined"!==typeof module?module.exports=v:n[e]=v})("FlexSearch",function(){function e(a){"string"===typeof a&&(a=B[a]);a||(a=x);this.id=a.id||G++;this.init(a);v(this,"index",function(){return this.a});v(this,"length",function(){return Object.keys(this.a).length})}function v(a,b,c){Object.defineProperty(a,b,{get:c})}function n(a){return new RegExp(a,"g")}function t(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 y(a,b,c,f,g,m,e){if("undefined"===typeof b[c]){var h=g?(9-(e||6))*m+(e||6)*g:m;b[c]=h;h>=e&&(a=a[h+.5|0],a=a[c]||(a[c]=[]),a[a.length]=f)}return h||b[c]}function A(a,b){if(a)for(var c=Object.keys(a),f=0,g=c.length;f<g;f++){var m=c[f],e=a[m];if(e)for(var h=0,k=e.length;h<k;h++)if(e[h]===b){1===k?delete a[m]:e.splice(h,1);break}else"object"===typeof e[h]&&A(e[h],b)}}function C(a){var b=[];if(!a)return b; 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 z(a,b,c,d,f,p,g){if("undefined"===typeof b[c]){var h=f?(9-(g||6))*p+(g||6)*f:p;b[c]=h;h>=g&&(a=a[h+.5|0],a=a[c]||(a[c]=[]),a[a.length]=d)}return h||b[c]}function A(a,b){if(a)for(var c=Object.keys(a),d=0,f=c.length;d<f;d++){var p=c[d],g=a[p];if(g)for(var h=0,k=g.length;h<k;h++)if(g[h]===b){1===k?delete a[p]:g.splice(h,1);break}else"object"===typeof g[h]&&A(g[h],b)}}function C(a){var b=[];if(!a)return b;
for(var c=0,f=0,g=0,m="",e=a.length,h=0;h<e;h++){var k=a[h];"a"===k||"e"===k||"i"===k||"o"===k||"u"===k||"y"===k?c++:f++;" "!==k&&(m+=k);if(" "===k||c>=(8<e?2:1)&&2<=f||2<=c&&f>=(8<e?2:1)||h===e-1)m&&(b[g]&&2<m.length&&g++,b[g]=b[g]?b[g]+m:m," "===k&&g++,m=""),f=c=0}return b}function H(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function I(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function J(a,b){var c=[],f=a.length;if(1<f){a.sort(I);for(var g={},m=a[0],e=m.length,h=0;h<e;)g[m[h++]]=1;for(var k, for(var c=0,d=0,f=0,p="",g=a.length,h=0;h<g;h++){var k=a[h];"a"===k||"e"===k||"i"===k||"o"===k||"u"===k||"y"===k?c++:d++;" "!==k&&(p+=k);if(" "===k||c>=(8<g?2:1)&&2<=d||2<=c&&d>=(8<g?2:1)||h===g-1)p&&(b[f]&&2<p.length&&f++,b[f]=b[f]?b[f]+p:p," "===k&&f++,p=""),d=c=0}return b}function H(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function I(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function J(a,b,c){var d=[],f=[],p=a.length;if(1<p){a.sort(I);for(var g={},h=a[0],k=h.length,y=0;y<k;)g[h[y++]]=
d=0,n=1;n<f;){var u=!1;m=a[n];e=m.length;for(h=0;h<e;)if(g[k=m[h++]]===n){if(n===f-1&&(c[d++]=k,b&&d===b)){u=!1;break}u=!0;g[k]=n+1}if(!u)break;n++}}else if(f&&(c=a[0],b&&c.length>b))return c.slice(0,b);return c}var z={encode:"icase",mode:"ngram",cache:!1,async:!1,j:!1,threshold:0,depth:0},B={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance", 1;for(var q,e=0,m=1;m<p;){var l=!1,n=m===p-1;f=[];h=a[m];k=h.length;for(y=-1;y<k;){var r=g[q=h[++y]];if(r===m){if(n&&(d[e++]=q,b&&e===b))return d;l=!0;g[q]=m+1}else c&&(r=f[r]||(f[r]=[]),r[r.length]=q)}if(!l&&!c)break;m++}if(c&&(b||(b=1E3),e=d.length,k=f.length,e<b&&k))for(m=k-1;0<=m;m--)if(q=f[m])for(y=0;y<q.length;y++)if(d[e++]=q[y],b&&e===b)return d}else p&&(d=a[0],b&&d.length>b&&(d=d.slice(0,b)));return d}var x={encode:"icase",mode:"ngram",g:!1,cache:!1,async:!1,l:!1,threshold:0,depth:0},B={memory:{encode:"extra",
mode:"ngram",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},x=[],G=0,D=p("[ -/]"),E={},F={};d.new=function(a){return new this(a)};d.create=function(a){return d.new(a)};d.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(x[x.length]=p(b),x[x.length]=a[b]);return this};d.registerEncoder=function(a,b){v[a]=b;return this};d.registerLanguage=function(a,b){E[a]=b.filter;F[a]=b.stemmer;return this};d.encode=function(a,b){return v[a].call(v,b)};d.prototype.init= mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"ngram",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},w=[],G=0,D=n("[ -/]"),E={},F={};e.new=function(a){return new this(a)};e.create=function(a){return e.new(a)};e.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(w[w.length]=n(b),w[w.length]=a[b]);
function(a){this.i=[];a||(a=z);var b=a.profile;b=b?B[b]:{};this.mode=a.mode||b.mode||this.mode||z.mode;this.threshold=a.threshold||b.threshold||this.threshold||z.threshold;this.depth=a.depth||b.depth||this.depth||z.depth;this.f=(b=a.encode||b.encode)&&v[b]||("function"===typeof b?b:this.f||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=E[b]||b;var c=this.f,f={};if(b)for(var g=0;g<b.length;g++){var m=c?c.call(v,b[g]):b[g];f[m]=String.fromCharCode(65E3-b.length+g)}this.filter=f}if(b=a.stemmer){a= return this};e.registerEncoder=function(a,b){u[a]=b;return this};e.registerLanguage=function(a,b){E[a]=b.filter;F[a]=b.stemmer;return this};e.encode=function(a,b){return u[a].call(u,b)};e.prototype.init=function(a){this.j=[];a||(a=x);var b=a.profile;b=b?B[b]:{};this.mode=a.mode||b.mode||this.mode||x.mode;this.threshold=a.threshold||b.threshold||this.threshold||x.threshold;this.depth=a.depth||b.depth||this.depth||x.depth;this.g=a.suggest||this.g||x.g;this.f=(b=a.encode||b.encode)&&u[b]||("function"===
F[b]||b;b=this.f;c=[];if(a){f=0;for(var e in a)a.hasOwnProperty(e)&&(g=b?b.call(v,e):e,c[f++]=p("(?=.{"+(g.length+3)+",})"+g+"$"),c[f++]=b?b.call(v,a[e]):a[e])}this.stemmer=c}this.g=[{},{},{},{},{},{},{},{},{},{}];this.b={};this.a={};this.c="";this.h=!0;return this};d.prototype.encode=function(a){a&&x.length&&(a=q(a,x));a&&this.i.length&&(a=q(a,this.i));a&&this.f&&(a=this.f.call(v,a));if(a&&this.filter){a=a.split(" ");for(var b=0;b<a.length;b++){var c=this.filter[a[b]];c&&(a[b]=c)}a=a.join(" ")}a&& typeof b?b:this.f||!1);(b=a.matcher)&&this.addMatcher(b);if(b=a.filter){b=E[b]||b;var c=this.f,d={};if(b)for(var f=0;f<b.length;f++){var p=c?c.call(u,b[f]):b[f];d[p]=String.fromCharCode(65E3-b.length+f)}this.filter=d}if(b=a.stemmer){a=F[b]||b;b=this.f;c=[];if(a){d=0;for(var g in a)a.hasOwnProperty(g)&&(f=b?b.call(u,g):g,c[d++]=n("(?=.{"+(f.length+3)+",})"+f+"$"),c[d++]=b?b.call(u,a[g]):a[g])}this.stemmer=c}this.h=[{},{},{},{},{},{},{},{},{},{}];this.c={};this.a={};this.i=!0;if("forward"===this.mode||
this.stemmer&&(a=q(a,this.stemmer));return a};d.prototype.addMatcher=function(a){var b=this.i,c;for(c in a)a.hasOwnProperty(c)&&(b[b.length]=p(c),b[b.length]=a[c]);return this};d.prototype.add=function(a,b,c){if("string"===typeof b&&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.mode;b="function"===typeof c?c(b):"ngram"===c?C(b):b.split(D);for(var f={_ctx:{}},g=this.threshold,m=this.depth,e=this.g,h=b.length,k=0;k<h;k++){var d=b[k];if(d){var n= "reverse"===this.mode||"both"===this.mode)this.b="";return this};e.prototype.encode=function(a){a&&w.length&&(a=t(a,w));a&&this.j.length&&(a=t(a,this.j));a&&this.f&&(a=this.f.call(u,a));a&&this.stemmer&&(a=t(a,this.stemmer));return a};e.prototype.addMatcher=function(a){var b=this.j,c;for(c in a)a.hasOwnProperty(c)&&(b[b.length]=n(c),b[b.length]=a[c]);return this};e.prototype.add=function(a,b,c){if("string"===typeof b&&b&&(a||0===a))if(this.a[a]&&!c)this.update(a,b);else{b=this.encode(b);if(!b.length)return this;
d.length,u=(h-k)/h;switch(c){case "reverse":case "both":for(var r="",l=n-1;1<=l;l--)r=d[l]+r,y(e,f,r,a,(n-l)/n,u,g);case "forward":r="";for(l=0;l<n;l++)r+=d[l],y(e,f,r,a,1,u,g);break;case "full":for(l=0;l<n;l++)for(var p=(n-l)/n,t=n;t>l;t--)r=d.substring(l,t),y(e,f,r,a,p,u,g);break;default:if(l=y(e,f,d,a,1,u,g),m&&1<h&&l>=g)for(n=f._ctx[d]||(f._ctx[d]={}),d=this.b[d]||(this.b[d]=[{},{},{},{},{},{},{},{},{},{}]),l=k-m,t=k+m+1,0>l&&(l=0),t>h&&(t=h);l<t;l++)l!==k&&y(d,n,b[l],a,0,10-(l<k?k-l:l-k),g)}}}this.a[a]= c=this.mode;b="function"===typeof c?c(b):"ngram"===c?C(b):b.split(D);for(var d={_ctx:{}},f=this.threshold,p=this.depth,g=this.h,h=b.length,k=0;k<h;k++){var e=b[k];if(e){var q=e.length,n=(h-k)/h;switch(c){case "reverse":case "both":for(var m="",l=q-1;1<=l;l--)m=e[l]+m,z(g,d,m,a,(q-l)/q,n,f);case "forward":m="";for(l=0;l<q;l++)m+=e[l],z(g,d,m,a,1,n,f);break;case "full":for(l=0;l<q;l++)for(var t=(q-l)/q,r=q;r>l;r--)m=e.substring(l,r),z(g,d,m,a,t,n,f);break;default:if(l=z(g,d,e,a,1,n,f),p&&1<h&&l>=f)for(q=
"1";this.h=!1}return this};d.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};d.prototype.remove=function(a){if(this.a[a]){for(var b=0;10>b;b++)A(this.g[b],a);this.depth&&A(this.b,a);delete this.a[a];this.h=!1}return this};d.prototype.search=function(a,b,c){var f=[];if(a&&"object"===typeof a){c=a.callback||b;b=a.limit;var g=a.threshold;a=a.query}g=(g||this.threshold||0)|0;"function"===typeof b?(c=b,b=1E3):b||(b=1E3);if(c){var d=this; d._ctx[e]||(d._ctx[e]={}),e=this.c[e]||(this.c[e]=[{},{},{},{},{},{},{},{},{},{}]),l=k-p,r=k+p+1,0>l&&(l=0),r>h&&(r=h);l<r;l++)l!==k&&z(e,q,b[l],a,0,10-(l<k?k-l:l-k),f)}}}this.a[a]="1";this.i=!1}return this};e.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};e.prototype.remove=function(a){if(this.a[a]){for(var b=0;10>b;b++)A(this.h[b],a);this.depth&&A(this.c,a);delete this.a[a];this.i=!1}return this};e.prototype.search=function(a,b,c){var d=
K(function(){c(d.search(a,b));d=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return f;if(!this.h)this.h=!0;else if(this.c&&0===a.indexOf(this.c))return f;var e=this.encode(a);if(!e.length)return f;var h=this.mode;e="function"===typeof h?h(e):"ngram"===h?C(e):e.split(D);h=e.length;var k=!0,p=[],n={};if(1<h)if(this.depth){var u=!0,r=e[0];n[r]="1"}else e.sort(H);var l;if(!u||(l=this.b)[r])for(var q=u?1:0;q<h;q++){var t=e[q];if(t&&!n[t]){for(var v,w=!1,x=[],z=0,y=9;y>=g;y--)if(v= [];if(a&&"object"===typeof a){c=a.callback||b;b=a.limit;var f=a.threshold;a=a.query}f=(f||this.threshold||0)|0;"function"===typeof b?(c=b,b=1E3):b||(b=1E3);if(c){var e=this;K(function(){c(e.search(a,b));e=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return d;if(!this.i)this.i=!0;else if("undefined"!==typeof this.b&&this.b&&0===a.indexOf(this.b))return d;var g=this.encode(a);if(!g.length)return d;var h=this.mode;g="function"===typeof h?h(g):"ngram"===h?C(g):g.split(D);h=g.length;
(u?l[r]:this.g)[y][t])x[z++]=v,w=!0;if(w)p[p.length]=1<z?p.concat.apply([],x):x[0];else{k=!1;break}n[t]="1"}r=t}else k=!1;k&&(f=J(p,b));f.length?this.c="":this.c||(this.c=a);return f};d.prototype.reset=function(){this.destroy();return this.init()};d.prototype.destroy=function(){this.filter=this.stemmer=this.g=this.b=this.a=null;return this};var v={icase:function(a){return a.toLowerCase()},balance:function(){var a=[p("[-/]")," ",p("[^a-z0-9 ]"),"",p("\\s\\s+")," "];return function(b){b=q(b.toLowerCase(), var k=!0,n=[],q={};if(1<h)if(this.depth){var t=!0,m=g[0];q[m]="1"}else g.sort(H);var l;if(!t||(l=this.c)[m])for(var u=t?1:0;u<h;u++){var r=g[u];if(r&&!q[r]){for(var v,x=!1,w=[],z=0,A=9;A>=f;A--)if(v=(t?l[m]:this.h)[A][r])w[z++]=v,x=!0;if(x)n[n.length]=1<z?n.concat.apply([],w):w[0];else if(!this.g){k=!1;break}q[r]="1"}m=r}else k=!1;k&&(d=J(n,b,this.g));"undefined"!==typeof this.b&&(d.length?this.b="":this.b||(this.b=a));return d};e.prototype.reset=function(){this.destroy();return this.init()};e.prototype.destroy=
a);for(var c="",f="",g="",d=0;d<b.length;d++){var e=b[d];if(e!==f)if(d&&"h"===e){if(g="a"===g||"e"===g||"i"===g||"o"===g||"u"===g||"y"===g,("a"===f||"e"===f||"i"===f||"o"===f||"u"===f||"y"===f)&&g||" "===f)c+=e}else c+=e;g=d===b.length-1?"":b[d+1];f=e}return c}}()},K=null;return d}(!1),this); function(){this.filter=this.stemmer=this.h=this.c=this.a=null;return this};var u={icase:function(a){return a.toLowerCase()},balance:function(){var a=[n("[-/]")," ",n("[^a-z0-9 ]"),"",n("\\s\\s+")," "];return function(b){b=t(b.toLowerCase(),a);for(var c="",d="",f="",e=0;e<b.length;e++){var g=b[e];if(g!==d)if(e&&"h"===g){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)c+=g}else c+=g;f=e===b.length-1?"":b[e+1];d=g}return c}}()},
K=null;return e}(!1),this);

51
flexsearch.min.js vendored
View File

@@ -1,30 +1,31 @@
/* /*
FlexSearch v0.2.46 FlexSearch v0.2.48
Copyright 2018 Thomas Wilkerling Copyright 2018 Thomas Wilkerling
Released under the Apache 2.0 Licence Released under the Apache 2.0 Licence
https://github.com/nextapps-de/flexsearch https://github.com/nextapps-de/flexsearch
*/ */
'use strict';(function(q,B,g){var t;(t=g.define)&&t.amd?t([],function(){return B}):(t=g.modules)?t[q.toLowerCase()]=B:"undefined"!==typeof module?module.exports=B:g[q]=B})("FlexSearch",function M(q){function g(a){"string"===typeof a&&(a=F[a]);a||(a=x);this.id=a.id||N++;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 y(a,b,d){if("undefined"=== 'use strict';(function(v,C,f){var w;(w=f.define)&&w.amd?w([],function(){return C}):(w=f.modules)?w[v.toLowerCase()]=C:"undefined"!==typeof module?module.exports=C:f[v]=C})("FlexSearch",function N(v){function f(a){"string"===typeof a&&(a=G[a]);a||(a=x);this.id=a.id||O++;this.init(a);w(this,"index",function(){return this.b});w(this,"length",function(){return Object.keys(this.b).length})}function w(a,b,e){Object.defineProperty(a,b,{get:e})}function d(a){return new RegExp(a,"g")}function y(a,b,e){if("undefined"===
typeof d){for(d=0;d<b.length;d+=2)a=a.replace(b[d],b[d+1]);return a}return a.replace(b,d)}function u(a,b,d,c,f,m,k){if("undefined"===typeof b[d]){var h=f?(9-(k||6))*m+(k||6)*f:m;b[d]=h;h>=k&&(a=a[h+.5|0],a=a[d]||(a[d]=[]),a[a.length]=c)}return h||b[d]}function n(a,b){if(a)for(var d=Object.keys(a),c=0,f=d.length;c<f;c++){var m=d[c],k=a[m];if(k)for(var h=0,e=k.length;h<e;h++)if(k[h]===b){1===e?delete a[m]:k.splice(h,1);break}else"object"===typeof k[h]&&n(k[h],b)}}function G(a){var b=[];if(!a)return b; typeof e){for(e=0;e<b.length;e+=2)a=a.replace(b[e],b[e+1]);return a}return a.replace(b,e)}function z(a,b,e,c,k,t,g){if("undefined"===typeof b[e]){var h=k?(9-(g||6))*t+(g||6)*k:t;b[e]=h;h>=g&&(a=a[h+.5|0],a=a[e]||(a[e]=[]),a[a.length]=c)}return h||b[e]}function q(a,b){if(a)for(var e=Object.keys(a),c=0,k=e.length;c<k;c++){var t=e[c],g=a[t];if(g)for(var h=0,d=g.length;h<d;h++)if(g[h]===b){1===d?delete a[t]:g.splice(h,1);break}else"object"===typeof g[h]&&q(g[h],b)}}function H(a){var b=[];if(!a)return b;
for(var d=0,c=0,f=0,m="",k=a.length,h=0;h<k;h++){var e=a[h];"a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e?d++:c++;" "!==e&&(m+=e);if(" "===e||d>=(8<k?2:1)&&2<=c||2<=d&&c>=(8<k?2:1)||h===k-1)m&&(b[f]&&2<m.length&&f++,b[f]=b[f]?b[f]+m:m," "===e&&f++,m=""),c=d=0}return b}function D(a){for(var b="",d="",c="",f=0;f<a.length;f++){var m=a[f];if(m!==d)if(f&&"h"===m){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+=m}else b+= for(var e=0,c=0,k=0,t="",g=a.length,h=0;h<g;h++){var d=a[h];"a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d?e++:c++;" "!==d&&(t+=d);if(" "===d||e>=(8<g?2:1)&&2<=c||2<=e&&c>=(8<g?2:1)||h===g-1)t&&(b[k]&&2<t.length&&k++,b[k]=b[k]?b[k]+t:t," "===d&&k++,t=""),c=e=0}return b}function E(a){for(var b="",e="",c="",k=0;k<a.length;k++){var d=a[k];if(d!==e)if(k&&"h"===d){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e)&&c||" "===e)b+=d}else b+=
m;c=f===a.length-1?"":a[f+1];d=m}return b}function O(a,b){var d={};if(a)for(var c=0;c<a.length;c++){var f=b?b.call(z,a[c]):a[c];d[f]=String.fromCharCode(65E3-a.length+c)}return d}function P(a,b){var d=[];if(a){var c=0,f;for(f in a)if(a.hasOwnProperty(f)){var m=b?b.call(z,f):f;d[c++]=e("(?=.{"+(m.length+3)+",})"+m+"$");d[c++]=b?b.call(z,a[f]):a[f]}}return d}function Q(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function R(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function S(a,b){var d=[],c= d;c=k===a.length-1?"":a[k+1];e=d}return b}function P(a,b){var e={};if(a)for(var c=0;c<a.length;c++){var k=b?b.call(A,a[c]):a[c];e[k]=String.fromCharCode(65E3-a.length+c)}return e}function Q(a,b){var e=[];if(a){var c=0,k;for(k in a)if(a.hasOwnProperty(k)){var t=b?b.call(A,k):k;e[c++]=d("(?=.{"+(t.length+3)+",})"+t+"$");e[c++]=b?b.call(A,a[k]):a[k]}}return e}function R(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function S(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function T(a,b,e){var c=[],
a.length;if(1<c){a.sort(R);for(var f={},m=a[0],e=m.length,h=0;h<e;)f[m[h++]]=1;for(var g,r=0,p=1;p<c;){var n=!1;m=a[p];e=m.length;for(h=0;h<e;)if(f[g=m[h++]]===p){if(p===c-1&&(d[r++]=g,b&&r===b)){n=!1;break}n=!0;f[g]=p+1}if(!n)break;p++}}else if(c&&(d=a[0],b&&d.length>b))return d.slice(0,b);return d}function E(a){a.C||(a.C=H(function(){a.C=null;var b=a.async;b&&(a.async=!1);if(a.f.length){for(var d=I(),c;(c=a.f.shift())||0===c;){var f=a.h[c];switch(f[0]){case C.add:a.add(f[1],f[2]);break;case C.update:a.update(f[1], k=[],d=a.length;if(1<d){a.sort(S);for(var g={},h=a[0],f=h.length,m=0;m<f;)g[h[m++]]=1;for(var p,u=0,n=1;n<d;){var l=!1,q=n===d-1;k=[];h=a[n];f=h.length;for(m=-1;m<f;){var r=g[p=h[++m]];if(r===n){if(q&&(c[u++]=p,b&&u===b))return c;l=!0;g[p]=n+1}else e&&(r=k[r]||(k[r]=[]),r[r.length]=p)}if(!l&&!e)break;n++}if(e&&(b||(b=1E3),u=c.length,f=k.length,u<b&&f))for(n=f-1;0<=n;n--)if(p=k[n])for(m=0;m<p.length;m++)if(c[u++]=p[m],b&&u===b)return c}else d&&(c=a[0],b&&c.length>b&&(c=c.slice(0,b)));return c}function F(a){a.D||
f[2]);break;case C.remove:a.remove(f[1])}a.h[c]=null;delete a.h[c];if(100<I()-d)break}a.f.length&&E(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function I(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}function T(a,b,d,c){a=q("flexsearch","id"+a,function(){var a,b;self.a=function(c){if(c=c.data)if(c.search){var d=b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit);self.postMessage({id:a,content:c.content,limit:c.limit,result:d})}else c.add? (a.D=I(function(){a.D=null;var b=a.async;b&&(a.async=!1);if(a.f.length){for(var e=J(),c;(c=a.f.shift())||0===c;){var d=a.h[c];switch(d[0]){case D.add:a.add(d[1],d[2]);break;case D.remove:a.remove(d[1])}a.h[c]=null;delete a.h[c];if(100<J()-e)break}a.f.length&&F(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function J(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}function U(a,b,e,c){a=v("flexsearch","id"+a,function(){var a,b;self.b=function(c){if(c=c.data)if(c.search){var e=
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.D&&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("}"))))(),b=new b(c.options))}},function(a){(a=a.data)&&a.result?c(a.id,a.content,a.result,a.limit):d.debug&&console.log(a)},b);var f=M.toString();d.id=b;a.postMessage(b,{register:f,options: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:e})}else c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset():c.info?(c=b.info(),c.worker=a,b.F&&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("}"))))(),b=new b(c.options))}},function(a){(a=
id:b});return a}var x={encode:"icase",mode:"ngram",cache:!1,async:!1,b:!1,threshold:0,depth:0},F={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"ngram",threshold:6,depth:3},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},A=[],N=0,C={add:0,update:1,remove:2},J=e("[ -/]"),K={},L={};g.new=function(a){return new this(a)}; a.data)&&a.result?c(a.id,a.content,a.result,a.limit):e.debug&&console.log(a)},b);var d=N.toString();e.id=b;a.postMessage(b,{register:d,options:e,id:b});return a}var x={encode:"icase",mode:"ngram",w:!1,cache:!1,async:!1,c:!1,threshold:0,depth:0},G={memory:{encode:"extra",mode:"strict",threshold:7},speed:{encode:"icase",mode:"strict",threshold:7,depth:2},match:{encode:"extra",mode:"full"},score:{encode:"extra",mode:"strict",threshold:5,depth:4},balance:{encode:"balance",mode:"ngram",threshold:6,depth:3},
g.create=function(a){return g.new(a)};g.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(A[A.length]=e(b),A[A.length]=a[b]);return this};g.registerEncoder=function(a,b){z[a]=b;return this};g.registerLanguage=function(a,b){K[a]=b.filter;L[a]=b.stemmer;return this};g.encode=function(a,b){return z[a].call(z,b)};g.prototype.init=function(a){this.B=[];a||(a=x);var b=a.profile,d=b?F[b]:{};if(b=a.worker)if("undefined"===typeof Worker)a.worker=!1,a.async=!0,this.i=null;else{var c=this;b=parseInt(b, fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},B=[],O=0,D={add:0,update:1,remove:2},K=d("[ -/]"),L={},M={};f.new=function(a){return new this(a)};f.create=function(a){return f.new(a)};f.registerMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(B[B.length]=d(b),B[B.length]=a[b]);return this};f.registerEncoder=function(a,b){A[a]=b;return this};f.registerLanguage=function(a,b){L[a]=b.filter;M[a]=b.stemmer;return this};f.encode=function(a,b){return A[a].call(A,b)};f.prototype.init=
10)||4;c.s=-1;c.m=0;c.g=[];c.w=null;c.i=Array(b);for(var f=0;f<b;f++)c.i[f]=T(c.id,f,a||x,function(a,b,d,f){c.m!==c.b&&(c.g=c.g.concat(d),c.m++,f&&c.g.length>=f&&(c.m=c.b),c.w&&c.m===c.b&&(c.g.length?c.c="":c.c||(c.c=b),c.cache&&c.j.set(b,c.g),c.w(c.g),c.g=[]))})}this.mode=a.mode||d.mode||this.mode||x.mode;this.async=a.async||this.async||x.async;this.b=a.worker||this.b||x.b;this.threshold=a.threshold||d.threshold||this.threshold||x.threshold;this.depth=a.depth||d.depth||this.depth||x.depth;this.v= function(a){this.C=[];a||(a=x);var b=a.profile,e=b?G[b]:{};if(b=a.worker)if("undefined"===typeof Worker)a.worker=!1,a.async=!0,this.i=null;else{var c=this;b=parseInt(b,10)||4;c.s=-1;c.m=0;c.g=[];c.A=null;c.i=Array(b);for(var d=0;d<b;d++)c.i[d]=U(c.id,d,a||x,function(a,b,e,d){c.m!==c.c&&(c.g=c.g.concat(e),c.m++,d&&c.g.length>=d&&(c.m=c.c),c.A&&c.m===c.c&&("undefined"!==typeof c.a&&(c.g.length?c.a="":c.a||(c.a=b)),c.cache&&c.j.set(b,c.g),c.A(c.g),c.g=[]))})}this.mode=a.mode||e.mode||this.mode||x.mode;
(b=a.encode||d.encode)&&z[b]||("function"===typeof b?b:this.v||!1);this.D=a.debug||this.D;(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=O(K[b]||b,this.v);if(b=a.stemmer)this.stemmer=P(L[b]||b,this.v);this.l=[{},{},{},{},{},{},{},{},{},{}];this.o={};this.a={};this.h={};this.f=[];this.C=null;this.c="";this.u=!0;this.j=(this.cache=b=a.cache||this.cache||x.cache)?new U(b):!1;return this};g.prototype.encode=function(a){a&&A.length&&(a=y(a,A));a&&this.B.length&&(a=y(a,this.B));a&&this.v&& this.async=a.async||this.async||x.async;this.c=a.worker||this.c||x.c;this.threshold=a.threshold||e.threshold||this.threshold||x.threshold;this.depth=a.depth||e.depth||this.depth||x.depth;this.w=a.suggest||this.w||x.w;this.v=(b=a.encode||e.encode)&&A[b]||("function"===typeof b?b:this.v||!1);this.F=a.debug||this.F;(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.filter=P(L[b]||b,this.v);if(b=a.stemmer)this.stemmer=Q(M[b]||b,this.v);this.l=[{},{},{},{},{},{},{},{},{},{}];this.o={};this.b={};this.h=
(a=this.v.call(z,a));if(a&&this.filter){a=a.split(" ");for(var b=0;b<a.length;b++){var d=this.filter[a[b]];d&&(a[b]=d)}a=a.join(" ")}a&&this.stemmer&&(a=y(a,this.stemmer));return a};g.prototype.addMatcher=function(a){var b=this.B,d;for(d in a)a.hasOwnProperty(d)&&(b[b.length]=e(d),b[b.length]=a[d]);return this};g.prototype.add=function(a,b,d){if("string"===typeof b&&b&&(a||0===a))if(this.a[a]&&!d)this.update(a,b);else{if(this.b)return++this.s>=this.i.length&&(this.s=0),this.i[this.s].postMessage(this.s, {};this.f=[];this.D=null;this.u=!0;if("forward"===this.mode||"reverse"===this.mode||"both"===this.mode)this.a="";this.j=(this.cache=b=a.cache||this.cache||x.cache)?new V(b):!1;return this};f.prototype.encode=function(a){a&&B.length&&(a=y(a,B));a&&this.C.length&&(a=y(a,this.C));a&&this.v&&(a=this.v.call(A,a));a&&this.stemmer&&(a=y(a,this.stemmer));return a};f.prototype.addMatcher=function(a){var b=this.C,e;for(e in a)a.hasOwnProperty(e)&&(b[b.length]=d(e),b[b.length]=a[e]);return this};f.prototype.add=
{add:!0,id:a,content:b}),this.a[a]=""+this.s,this;if(this.async)return this.h[a]||(this.f[this.f.length]=a),this.h[a]=[C.add,a,b],E(this),this;b=this.encode(b);if(!b.length)return this;d=this.mode;b="function"===typeof d?d(b):"ngram"===d?G(b):b.split(J);for(var c={_ctx:{}},f=this.threshold,e=this.depth,k=this.l,h=b.length,g=0;g<h;g++){var r=b[g];if(r){var p=r.length,n=(h-g)/h;switch(d){case "reverse":case "both":for(var v="",l=p-1;1<=l;l--)v=r[l]+v,u(k,c,v,a,(p-l)/p,n,f);case "forward":v="";for(l= function(a,b,e){if("string"===typeof b&&b&&(a||0===a))if(this.b[a]&&!e)this.update(a,b);else{if(this.c)return++this.s>=this.i.length&&(this.s=0),this.i[this.s].postMessage(this.s,{add:!0,id:a,content:b}),this.b[a]=""+this.s,this;if(this.async)return this.h[a]||(this.f[this.f.length]=a),this.h[a]=[D.add,a,b],F(this),this;b=this.encode(b);if(!b.length)return this;e=this.mode;b="function"===typeof e?e(b):"ngram"===e?H(b):b.split(K);for(var c={_ctx:{}},d=this.threshold,t=this.depth,g=this.l,h=b.length,
0;l<p;l++)v+=r[l],u(k,c,v,a,1,n,f);break;case "full":for(l=0;l<p;l++)for(var q=(p-l)/p,w=p;w>l;w--)v=r.substring(l,w),u(k,c,v,a,q,n,f);break;default:if(l=u(k,c,r,a,1,n,f),e&&1<h&&l>=f)for(p=c._ctx[r]||(c._ctx[r]={}),r=this.o[r]||(this.o[r]=[{},{},{},{},{},{},{},{},{},{}]),l=g-e,w=g+e+1,0>l&&(l=0),w>h&&(w=h);l<w;l++)l!==g&&u(r,p,b[l],a,0,10-(l<g?g-l:l-g),f)}}}this.a[a]="1";this.u=!1}return this};g.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this}; f=0;f<h;f++){var m=b[f];if(m){var p=m.length,u=(h-f)/h;switch(e){case "reverse":case "both":for(var n="",l=p-1;1<=l;l--)n=m[l]+n,z(g,c,n,a,(p-l)/p,u,d);case "forward":n="";for(l=0;l<p;l++)n+=m[l],z(g,c,n,a,1,u,d);break;case "full":for(l=0;l<p;l++)for(var q=(p-l)/p,r=p;r>l;r--)n=m.substring(l,r),z(g,c,n,a,q,u,d);break;default:if(l=z(g,c,m,a,1,u,d),t&&1<h&&l>=d)for(p=c._ctx[m]||(c._ctx[m]={}),m=this.o[m]||(this.o[m]=[{},{},{},{},{},{},{},{},{},{}]),l=f-t,r=f+t+1,0>l&&(l=0),r>h&&(r=h);l<r;l++)l!==f&&
g.prototype.remove=function(a){if(this.a[a]){if(this.b){var b=parseInt(this.a[a],10);this.i[b].postMessage(b,{remove:!0,id:a});delete this.a[a];return this}if(this.async)return this.h[a]||(this.f[this.f.length]=a),this.h[a]=[C.remove,a],E(this),this;for(b=0;10>b;b++)n(this.l[b],a);this.depth&&n(this.o,a);delete this.a[a];this.u=!1}return this};g.prototype.search=function(a,b,d){var c=[];if(a&&"object"===typeof a){d=a.callback||b;b=a.limit;var f=a.threshold;a=a.query}f=(f||this.threshold||0)|0;"function"=== z(m,p,b[l],a,0,10-(l<f?f-l:l-f),d)}}}this.b[a]="1";this.u=!1}return this};f.prototype.update=function(a,b){this.b[a]&&b&&"string"===typeof b&&(this.remove(a),this.add(a,b,!0));return this};f.prototype.remove=function(a){if(this.b[a]){if(this.c){var b=parseInt(this.b[a],10);this.i[b].postMessage(b,{remove:!0,id:a});delete this.b[a];return this}if(this.async)return this.h[a]||(this.f[this.f.length]=a),this.h[a]=[D.remove,a],F(this),this;for(b=0;10>b;b++)q(this.l[b],a);this.depth&&q(this.o,a);delete this.b[a];
typeof b?(d=b,b=1E3):b||(b=1E3);if(this.b){this.w=d;this.m=0;this.g=[];for(c=0;c<this.b;c++)this.i[c].postMessage(c,{search:!0,limit:b,threshold:f,content:a});return null}if(d){var e=this;H(function(){d(e.search(a,b));e=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return c;var k=a;if(!this.u)this.cache&&(this.c="",this.j.reset()),this.u=!0;else if(this.cache){var h=this.j.get(a);if(h)return h}else if(this.c&&0===a.indexOf(this.c))return c;k=this.encode(k);if(!k.length)return c; this.u=!1}return this};f.prototype.search=function(a,b,e){var c=[];if(a&&"object"===typeof a){e=a.callback||b;b=a.limit;var d=a.threshold;a=a.query}d=(d||this.threshold||0)|0;"function"===typeof b?(e=b,b=1E3):b||(b=1E3);if(this.c){this.A=e;this.m=0;this.g=[];for(c=0;c<this.c;c++)this.i[c].postMessage(c,{search:!0,limit:b,threshold:d,content:a});return null}if(e){var f=this;I(function(){e(f.search(a,b));f=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return c;var g=a;if(!this.u)this.cache&&
h=this.mode;k="function"===typeof h?h(k):"ngram"===h?G(k):k.split(J);h=k.length;var g=!0,n=[],p={};if(1<h)if(this.depth){var q=!0,v=k[0];p[v]="1"}else k.sort(Q);var l;if(!q||(l=this.o)[v])for(var t=q?1:0;t<h;t++){var w=k[t];if(w&&!p[w]){for(var x,y=!1,u=[],z=0,A=9;A>=f;A--)if(x=(q?l[v]:this.l)[A][w])u[z++]=x,y=!0;if(y)n[n.length]=1<z?n.concat.apply([],u):u[0];else{g=!1;break}p[w]="1"}v=w}else g=!1;g&&(c=S(n,b));c.length?this.c="":this.c||(this.c=a);this.cache&&this.j.set(a,c);return c};g.prototype.info= ("undefined"!==typeof this.a&&(this.a=""),this.j.reset()),this.u=!0;else if(this.cache){var h=this.j.get(a);if(h)return h}else if("undefined"!==typeof this.a&&this.a&&0===a.indexOf(this.a))return c;g=this.encode(g);if(!g.length)return c;h=this.mode;g="function"===typeof h?h(g):"ngram"===h?H(g):g.split(K);h=g.length;var q=!0,m=[],p={};if(1<h)if(this.depth){var u=!0,n=g[0];p[n]="1"}else g.sort(R);var l;if(!u||(l=this.o)[n])for(var v=u?1:0;v<h;v++){var r=g[v];if(r&&!p[r]){for(var w,x=!1,y=[],z=0,A=9;A>=
function(){if(this.b)for(var a=0;a<this.b;a++)this.i[a].postMessage(a,{info:!0,id:this.id});else{for(var b,d,c=0,f=0,e=0,g=0;10>g;g++)for(b=Object.keys(this.l[g]),a=0;a<b.length;a++)d=this.l[g][b[a]].length,c+=d+2*b[a].length+4,f+=d,e+=2*b[a].length;b=Object.keys(this.a);d=b.length;for(a=0;a<d;a++)c+=2*b[a].length+2;return{id:this.id,memory:c,items:d,sequences:f,chars:e,status:this.u,cache:this.f.length,matcher:A.length,worker:this.b}}};g.prototype.reset=function(){this.destroy();return this.init()}; d;A--)if(w=(u?l[n]:this.l)[A][r])y[z++]=w,x=!0;if(x)m[m.length]=1<z?m.concat.apply([],y):y[0];else if(!this.w){q=!1;break}p[r]="1"}n=r}else q=!1;q&&(c=T(m,b,this.w));"undefined"!==typeof this.a&&(c.length?this.a="":this.a||(this.a=a));this.cache&&this.j.set(a,c);return c};f.prototype.info=function(){if(this.c)for(var a=0;a<this.c;a++)this.i[a].postMessage(a,{info:!0,id:this.id});else{for(var b,e,c=0,d=0,f=0,g=0;10>g;g++)for(b=Object.keys(this.l[g]),a=0;a<b.length;a++)e=this.l[g][b[a]].length,c+=e+
g.prototype.destroy=function(){this.cache&&(this.j.reset(),this.j=null);this.filter=this.stemmer=this.l=this.o=this.a=this.h=this.f=null;return this};var z={icase:function(a){return a.toLowerCase()},simple:function(){var 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"), 2*b[a].length+4,d+=e,f+=2*b[a].length;b=Object.keys(this.b);e=b.length;for(a=0;a<e;a++)c+=2*b[a].length+2;return{id:this.id,memory:c,items:e,sequences:d,chars:f,status:this.u,cache:this.f.length,matcher:B.length,worker:this.c}}};f.prototype.reset=function(){this.destroy();return this.init()};f.prototype.destroy=function(){this.cache&&(this.j.reset(),this.j=null);this.filter=this.stemmer=this.l=this.o=this.b=this.h=this.f=null;return this};var A={icase:function(a){return a.toLowerCase()},simple:function(){var a=
"s",e(" & ")," and ",e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s\\s+")," "];return function(b){b=y(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){var 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=y(b,a));d||1<b.length&&(b=D(b));return b}}(),extra: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(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," "];return function(b){b=y(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){var a=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),
[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(var d=0;d<b.length;d++){var c=b[d];1<c.length&&(b[d]=c[0]+y(c.substring(1),a))}b=b.join(" ");b=D(b)}return b}}(),balance:function(){var a=[e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s\\s+")," "];return function(b){return D(y(b.toLowerCase(),a))}}()},H=function(){var a={};return function(b,d,c){var e=a[c];e&&clearTimeout(e); "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,d){if(!b)return b;b=this.simple(b);2<b.length&&(b=y(b,a));d||1<b.length&&(b=E(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 d=0;d<b.length;d++){var c=b[d];
return a[c]=setTimeout(b,d)}}(),U=function(){function a(a){this.reset();this.A=!0!==a&&a}a.prototype.reset=function(){this.cache={};this.count={};this.index={};this.keys=[]};a.prototype.set=function(a,d){if(this.A&&"undefined"===typeof this.cache[a]){var b=this.keys.length;if(b===this.A){b--;var e=this.keys[b];delete this.cache[e];delete this.count[e];delete this.index[e]}this.index[a]=b;this.keys[b]=a;this.count[a]=-1;this.cache[a]=d;this.get(a)}else this.cache[a]=d};a.prototype.get=function(a){var b= 1<c.length&&(b[d]=c[0]+y(c.substring(1),a))}b=b.join(" ");b=E(b)}return b}}(),balance:function(){var a=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," "];return function(b){return E(y(b.toLowerCase(),a))}}()},I=function(){var a={};return function(b,d,c){var e=a[c];e&&clearTimeout(e);return a[c]=setTimeout(b,d)}}(),V=function(){function a(a){this.reset();this.B=!0!==a&&a}a.prototype.reset=function(){this.cache={};this.count={};this.index={};this.keys=[]};a.prototype.set=function(a,d){if(this.B&&"undefined"===
this.cache[a];if(this.A&&b){var c=++this.count[a],e=this.index,g=e[a];if(0<g){for(var k=this.keys,h=g;this.count[k[--g]]<=c&&-1!==g;);g++;if(g!==h){for(c=h;c>g;c--)h=k[c-1],k[c]=h,e[h]=c;k[g]=a;e[a]=g}}}return b};return a}();return g}(function(){var q={},B=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(g,t,e,y,u){var n=g;g=B?URL.createObjectURL(new Blob(["var SUPPORT_WORKER = true;var SUPPORT_BUILTINS = true;var SUPPORT_DEBUG = true;var SUPPORT_CACHE = true;var SUPPORT_ASYNC = true;("+ typeof this.cache[a]){var b=this.keys.length;if(b===this.B){b--;var e=this.keys[b];delete this.cache[e];delete this.count[e];delete this.index[e]}this.index[a]=b;this.keys[b]=a;this.count[a]=-1;this.cache[a]=d;this.get(a)}else this.cache[a]=d};a.prototype.get=function(a){var b=this.cache[a];if(this.B&&b){var c=++this.count[a],d=this.index,f=d[a];if(0<f){for(var g=this.keys,h=f;this.count[g[--f]]<=c&&-1!==f;);f++;if(f!==h){for(c=h;c>f;c--)h=g[c-1],g[c]=h,d[h]=c;g[f]=a;d[a]=f}}}return b};return a}();
e.toString()+")()"],{type:"text/javascript"})):"../"+n+".js";n+="-"+t;q[n]||(q[n]=[]);q[n][u]=new Worker(g);q[n][u].onmessage=y;console.log("Register Worker: "+n+"@"+u);return{postMessage:function(e,g){q[n][e].postMessage(g)}}}}()),this); return f}(function(){var v={},C=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(f,w,d,y,z){var q=f;f=C?URL.createObjectURL(new Blob(["var SUPPORT_WORKER = true;var SUPPORT_BUILTINS = true;var SUPPORT_DEBUG = true;var SUPPORT_CACHE = true;var SUPPORT_ASYNC = true;("+d.toString()+")()"],{type:"text/javascript"})):"../"+q+".js";q+="-"+w;v[q]||(v[q]=[]);v[q][z]=new Worker(f);v[q][z].onmessage=y;console.log("Register Worker: "+q+"@"+z);return{postMessage:function(d,
f){v[q][d].postMessage(f)}}}}()),this);

View File

@@ -1,6 +1,6 @@
{ {
"name": "flexsearch", "name": "flexsearch",
"version": "0.2.461", "version": "0.2.48",
"description": "Next-Generation full text search library with zero dependencies.", "description": "Next-Generation full text search library with zero dependencies.",
"homepage": "https://nextapps-de.github.io/xone/", "homepage": "https://nextapps-de.github.io/xone/",
"author": "Thomas Wilkerling", "author": "Thomas Wilkerling",

View File

@@ -3,8 +3,8 @@
<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="../flexsearch.js"></script>--> <script src="https://rawgit.com/nextapps-de/flexsearch/master/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="../bulksearch.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>
<script src="https://cdn.rawgit.com/kbrsh/wade/master/dist/wade.min.js"></script> <script src="https://cdn.rawgit.com/kbrsh/wade/master/dist/wade.min.js"></script>
@@ -44,7 +44,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<th>bm25</th> <th>bm25</th>
</tr> </tr>
<tr id="test-1"> <tr id="test-1">
<td style="width: 200px">"without breach of modesty"</td> <td style="width: 200px"></td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
@@ -56,7 +56,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-2"> <tr id="test-2">
<td>"went softly stream"</td> <td></td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
@@ -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>"princes of the ambition"</td> <td></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>"five-thousand leagues"</td> <td></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>"i already observed"</td> <td></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>"let a of his"</td> <td></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>"take that to the rocks"</td> <td></td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
@@ -128,7 +128,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-8"> <tr id="test-8">
<td>"bignes of splaknuk"</td> <td></td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
@@ -140,7 +140,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-9"> <tr id="test-9">
<td>"matematikal musikal instruments"</td> <td></td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
@@ -152,7 +152,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-10"> <tr id="test-10">
<td>"matical sical strument"</td> <td></td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
@@ -164,7 +164,37 @@ 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-11"> <tr id="test-11">
<td>"lalkon the camberlayhn"</td> <td></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-12">
<td></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>
<td colspan="10">
<br>
Contextual Search Test:
</td>
</tr>
<tr id="test-13">
<td style="width: 200px"></td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
<td>wait ...</td> <td>wait ...</td>
@@ -207,6 +237,12 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
} }
} }
data.push('zero one two three four five six seven eight nine ten.');
data.push('zero one two three four five six seven eight nine ten.');
data.push('four two zero one three ten five seven eight six nine.');
data.push('zero one two three four five six seven eight nine ten.');
data.push('zero one two three four five six seven eight nine ten.');
tmp = null; tmp = null;
new_data = null; new_data = null;
text_data = null; text_data = null;
@@ -225,10 +261,14 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
bulksearch = new BulkSearch({ bulksearch = new BulkSearch({
type: 'short', // this type specifies the maximum bitlength of assigned IDs! type: 'short', // this type specifies the maximum bitlength of assigned IDs!
encode: 'advanced', encode: 'extra',
multi: true, multi: true,
suggest:true,
filter: true,
stemmer: true,
async: false, async: false,
cache: false cache: false,
worker: false
}); });
console.time('bulksearch'); console.time('bulksearch');
@@ -246,6 +286,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
mode: 'strict', mode: 'strict',
threshold: 5, threshold: 5,
depth: 3, depth: 3,
suggest:true,
filter: true, filter: true,
stemmer: true, stemmer: true,
async: false, async: false,
@@ -376,12 +417,14 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
do_test('test-3', 'princes of the ambition', [72, 408]); do_test('test-3', 'princes of the ambition', [72, 408]);
do_test('test-4', 'five-thousand leagues', [2]); do_test('test-4', 'five-thousand leagues', [2]);
do_test('test-5', 'i already observed', [458, 346]); do_test('test-5', 'i already observed', [458, 346]);
do_test('test-6', 'let a of his', [50]); do_test('test-6', 'disgust the bigness', [175]);
do_test('test-7', 'take that to the rocks', [175]); do_test('test-7', 'bignes of splaknuk', [146]);
do_test('test-8', 'bignes of splaknuk', [146]); do_test('test-8', 'matematikal musikal instruments', [267]);
do_test('test-9', 'matematikal musikal instruments', [267]); do_test('test-9', 'composition of minerals gums juices vegetables', [303]);
do_test('test-10', 'matical sical strument', [267]); do_test('test-10', 'lalkon the camberlayhn', [99]);
do_test('test-11', 'lalkon the camberlayhn', [99]); do_test('test-11', 'to be at all this is', [184]);
do_test('test-12', 'matical sical strument', [267]);
do_test('test-13', 'zero one three ten', [504]);
// --------------------------------------- // ---------------------------------------
@@ -389,6 +432,8 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
var nodes = document.getElementById(id).getElementsByTagName('td'); var nodes = document.getElementById(id).getElementsByTagName('td');
nodes[0].innerHTML = query;
for(var i = 1; i < nodes.length; i++){ for(var i = 1; i < nodes.length; i++){
var results; var results;

View File

@@ -884,7 +884,7 @@ describe('Context', function(){
}); });
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Encoding Tests // Tokenizer Tests
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
describe('Options', function(){ describe('Options', function(){
@@ -991,6 +991,7 @@ describe('Relevance', function(){
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("1 3 4 7")).to.have.lengthOf(0);
expect(index.search("one")).to.have.members([1, 2]); expect(index.search("one")).to.have.members([1, 2]);
expect(index.search("one three")).to.have.members([1, 2]); expect(index.search("one three")).to.have.members([1, 2]);
expect(index.search("three one")).to.have.members([1, 2]); expect(index.search("three one")).to.have.members([1, 2]);
@@ -998,6 +999,33 @@ describe('Relevance', function(){
}); });
}); });
// ------------------------------------------------------------------------
// Suggestion Tests
// ------------------------------------------------------------------------
describe('Suggestion', function(){
it('Should have been suggested properly by relevance', function(){
var index = new FlexSearch({
encode: 'advanced',
mode: 'strict',
suggest: true
});
index.add(0, "1 2 3 2 4 1 5 3");
index.add(1, "zero one two three four five six seven eight nine ten");
index.add(2, "four two zero one three ten five seven eight six nine");
expect(index.search("1 3 4 7")).to.have.members([0]);
expect(index.search("1 3 9 7")).to.have.members([0]);
expect(index.search("one foobar two")).to.have.members([1, 2]);
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
//TODO
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
});
});
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Feature Tests // Feature Tests
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -1029,9 +1057,8 @@ describe('Add Matchers', function(){
}).addMatcher({ }).addMatcher({
'8': 'f' '8': 'f'
});
flexsearch_forward.add(0, "12345678"); }).add(0, "12345678");
expect(flexsearch_forward.search("12345678")).to.include(0); expect(flexsearch_forward.search("12345678")).to.include(0);
expect(flexsearch_forward.search("abcd")).to.include(0); expect(flexsearch_forward.search("abcd")).to.include(0);
@@ -1152,5 +1179,5 @@ describe('Chaining', function(){
function test_encoder(str){ function test_encoder(str){
return str = '-[' + str.toUpperCase() + ']-'; return '-[' + str.toUpperCase() + ']-';
} }