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

MOD improve ngram sequencing

MOD improve partial scoring
This commit is contained in:
Thomas Wilkerling
2018-03-23 02:55:36 +01:00
parent 76dad715dd
commit 70596c73da
8 changed files with 278 additions and 169 deletions

View File

@@ -29,33 +29,36 @@ Supported Platforms:
- Browser
- Node.js
<!--
Supported Module Definitions:
- AMD (RequireJS)
- CommonJS (Node.js)
- Closure (Xone)
- Global (Browser)
-->
All Features:
<ul>
<li><a href="#webworker">Web-Worker Support</a> (not available in Node.js)</li>
<li><a href="#contextual">Contextual Indexes</a></li>
<li>Partial Matching</li>
<li>Multiple Words</li>
<li><a href="#phonetic">Phonetic Search</a></li>
<li>Relevance-based Scoring</li>
<li><a href="#contextual">Contextual Indexes</a></li>
<li>Auto-Balanced Cache by Popularity</li>
<li>Limit Results</li>
<li>Supports Caching</li>
<li>Asynchronous Processing</li>
<li>Customizable: Matcher, Encoder, Tokenizer, Stemmer, Stopword-Filter</li>
<li>Customizable: Matcher, Encoder, Tokenizer, Stemmer, Filter</li>
</ul>
These 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)
- Asynchronous
- Cache
- Built-in encoders except 'balance' and 'icase' (you can still pass in customs)
- Built-in stemmer and filter (you can still pass in customs)
- Debug logging
- _index.info()_ method
@@ -518,7 +521,7 @@ FlexSearch ist highly customizable. Make use of the the <a href="#profiles">righ
"fastest"
</td>
<td vertical-align="top">
The <a href="#profiles">configuration profile</a>.<br>
The <a href="#profiles">configuration profile</a>. Choose your preferation.<br>
</td>
</tr>
<tr></tr>
@@ -545,7 +548,7 @@ FlexSearch ist highly customizable. Make use of the the <a href="#profiles">righ
"simple"<br>
"advanced"<br>
"extra"<br>
"balanced"<br>
"balance"<br>
function()
</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>
@@ -572,12 +575,13 @@ FlexSearch ist highly customizable. Make use of the the <a href="#profiles">righ
-->
<tr></tr>
<tr>
<td align="top">cache<br><br></td>
<td align="top">cache<br><br><br></td>
<td>
false<br>
true<br>
false
{number}
</td>
<td>Enable/Disable caching.</td>
<td>Enable/Disable and/or set capacity of cached entries.<br><br>When passing a number as a limit the cache automatically balance stored entries related to their popularity.<br><br>Note: When just using "true" the cache has no limits and is actually 5 times faster (the balancer should not run).</td>
</tr>
<tr></tr>
<tr>
@@ -586,7 +590,7 @@ FlexSearch ist highly customizable. Make use of the the <a href="#profiles">righ
true<br>
false
</td>
<td>Enable/Disable asynchronous processing.</td>
<td>Enable/Disable asynchronous processing.<br><br>Each job will be queued for non-blocking processing. Recommended when using WebWorkers.</td>
</tr>
<tr></tr>
<tr>
@@ -606,6 +610,33 @@ FlexSearch ist highly customizable. Make use of the the <a href="#profiles">righ
</td>
<td>Enable/Disable <a href="#contextual">contextual indexing</a> and also sets relevance depth (experimental).</td>
</tr>
<tr></tr>
<tr>
<td align="top">threshold<br><br></td>
<td>
false<br>
{number}
</td>
<td>Enable/Disable the threshold of minimum relevance results should have.<br><br>Note: You can take a lower threshold for indexing and pass a higher value when calling .search(), but not other turn around.</td>
</tr>
<tr></tr>
<tr>
<td align="top">stemmer<br><br></td>
<td>
false<br>
{function}
</td>
<td>Disable or pass in custom object/array.</td>
</tr>
<tr></tr>
<tr>
<td align="top">filter<br><br></td>
<td>
false<br>
{function}
</td>
<td>Disable or pass in custom object/array.</td>
</tr>
</table>
<a name="tokenizer"></a>

View File

@@ -1,5 +1,5 @@
;/**!
* @preserve FlexSearch v0.2.42
* @preserve FlexSearch v0.2.44
* Copyright 2018 Thomas Wilkerling
* Released under the Apache 2.0 Licence
* https://github.com/nextapps-de/flexsearch
@@ -504,7 +504,9 @@ var SUPPORT_ASYNC = true;
/** @type {Array} */
this._matcher = [];
if(options){
//if(options){
options || (options = defaults);
var custom = options['profile'];
var profile = custom ? profiles[custom] : {};
@@ -588,13 +590,6 @@ var SUPPORT_ASYNC = true;
defaults.mode
);
if(SUPPORT_CACHE) this.cache = (
options['cache'] ||
this.cache ||
defaults.cache
);
if(SUPPORT_ASYNC) this.async = (
options['async'] ||
@@ -678,7 +673,7 @@ var SUPPORT_ASYNC = true;
), this.encoder);
}
}
//}
// initialize primary index
@@ -689,19 +684,8 @@ var SUPPORT_ASYNC = true;
];
this._ctx = {};
this._ids = {};
/**
* @type {Object<string|number, Array>}
*/
this._stack = {};
/**
* @type {Array<string|number>}
*/
this._stack_keys = [];
/**
@@ -712,11 +696,21 @@ var SUPPORT_ASYNC = true;
this._last_empty_query = "";
this._status = true;
if(SUPPORT_CACHE) this._cache = this.cache ?
if(SUPPORT_CACHE) {
(new cache(30 * 1000, 50, true))
this.cache = custom = (
options['cache'] ||
this.cache ||
defaults.cache
);
this._cache = custom ?
(new cache(custom))
:
false;
}
return this;
};
@@ -900,6 +894,7 @@ var SUPPORT_ASYNC = true;
if(value){
var length = value.length;
var context_score = (word_length - i) / word_length;
switch(tokenizer){
@@ -918,9 +913,8 @@ var SUPPORT_ASYNC = true;
dupes,
tmp,
id,
/** @type {string} */
(content),
0,
(length - a) / length,
context_score,
threshold
);
}
@@ -941,9 +935,8 @@ var SUPPORT_ASYNC = true;
dupes,
tmp,
id,
/** @type {string} */
(content),
0,
1,
context_score,
threshold
);
}
@@ -956,6 +949,8 @@ var SUPPORT_ASYNC = true;
for(var x = 0; x < length; x++){
var partial_score = (length - x) / length;
for(var y = length; y > x; y--){
tmp = value.substring(x, y);
@@ -966,9 +961,8 @@ var SUPPORT_ASYNC = true;
dupes,
tmp,
id,
/** @type {string} */
(content),
0,
partial_score,
context_score,
threshold
);
}
@@ -986,9 +980,10 @@ var SUPPORT_ASYNC = true;
dupes,
value,
id,
/** @type {string} */
(content),
depth ? 1 : 0,
// Note: ngrams has partial scoring (sequence->word) and contextual scoring (word->context)
// TODO compute and pass distance of ngram sequences as the initial score for each word
1,
context_score,
threshold
);
@@ -1015,9 +1010,8 @@ var SUPPORT_ASYNC = true;
ctx_dupes,
words[x],
id,
/** @type {string} */
(content),
(x < i ? i - x : x - i),
0,
10 - (x < i ? i - x : x - i),
threshold
);
}
@@ -1465,6 +1459,7 @@ var SUPPORT_ASYNC = true;
if(SUPPORT_CACHE && this.cache){
this._cache.reset();
this._cache = null;
}
// release references
@@ -1476,8 +1471,7 @@ var SUPPORT_ASYNC = true;
this._ctx =
this._ids =
this._stack =
this._stack_keys =
this._cache = null;
this._stack_keys = null;
return this;
};
@@ -1496,8 +1490,8 @@ var SUPPORT_ASYNC = true;
regex_space, ' ',
regex_strip, '',
regex_whitespace, ' ',
regex_vowel, ''
regex_whitespace, ' '
//regex_vowel, ''
];
return function(value){
@@ -1747,7 +1741,7 @@ var SUPPORT_ASYNC = true;
})() : null;
// Xone Flexi-Cache Handler Fallback
// Flexi-Cache
var cache = SUPPORT_CACHE ? (function(){
@@ -1755,7 +1749,8 @@ var SUPPORT_ASYNC = true;
function Cache(limit){
this.reset();
this.limit = limit || 1000;
this.limit = (limit !== true) && limit;
}
/** @this {Cache} */
@@ -1770,7 +1765,7 @@ var SUPPORT_ASYNC = true;
/** @this {Cache} */
Cache.prototype.set = function(id, value){
if(!this.count[id]){
if(this.limit && (typeof this.cache[id] === 'undefined')){
var length = this.keys.length;
@@ -1787,25 +1782,29 @@ var SUPPORT_ASYNC = true;
this.index[id] = length;
this.keys[length] = id;
this.count[id] = 1;
}
this.count[id] = -1;
this.cache[id] = value;
// shift up counter +1
this.get(id);
}
else{
this.cache[id] = value;
}
};
/**
* Note: It is a lot better to have the complexity when fetching the cache:
* Note: It is better to have the complexity when fetching the cache:
* @this {Cache}
*/
Cache.prototype.get = function(id){
var cache = this.cache[id];
if(cache){
if(this.limit && cache){
var count = ++this.count[id];
var index = this.index;
@@ -1816,18 +1815,32 @@ var SUPPORT_ASYNC = true;
var keys = this.keys;
var old_index = current_index;
while(current_index && this.count[keys[current_index--]] <= count){}
// forward pointer
while(this.count[keys[--current_index]] <= count){
if(current_index >= 0 && ((current_index + 1) !== old_index)){
if(current_index === -1){
var tmp = keys[current_index];
break;
}
}
// TODO splice is too slow
// move pointer back
current_index++;
if(current_index !== old_index){
// copy values from predecessors
for(var i = old_index; i > current_index; i--) {
var key = keys[i - 1];
keys[i] = key;
index[key] = i;
}
// push new value on top
keys[current_index] = id;
index[id] = current_index;
keys.splice(current_index, 1, id);
index[tmp] = old_index;
keys.splice(old_index, 1, tmp);
}
}
}
@@ -1893,16 +1906,24 @@ var SUPPORT_ASYNC = true;
* @param {Object} dupes
* @param {string} tmp
* @param {string|number} id
* @param {string} content
* @param {number} context
* @param {number} partial_score
* @param {number} context_score
* @param {number} threshold
*/
function addIndex(map, dupes, tmp, id, content, context, threshold){
function addIndex(map, dupes, tmp, id, partial_score, context_score, threshold){
if(typeof dupes[tmp] === 'undefined'){
var score = context ? (10 - context) : calcScore(tmp, content);
var score = (
partial_score ?
((9 - (threshold || 6)) * context_score) + ((threshold || 6) * partial_score)
// calcScore(tmp, content)
:
context_score
);
dupes[tmp] = score;
@@ -1918,6 +1939,23 @@ var SUPPORT_ASYNC = true;
return score || dupes[tmp];
}
/**
* @param {!string} part
* @param {!string} ref
* @returns {number}
*/
function calcScore(part, ref){
var context_index = ref.indexOf(part);
var partial_index = context_index - ref.lastIndexOf(" ", context_index);
return (
(3 / ref.length * (ref.length - context_index)) + (6 / partial_index)
);
}
/**
* @param {Object} map
* @param {string|number} id
@@ -1961,23 +1999,6 @@ var SUPPORT_ASYNC = true;
}
}
/**
* @param {!string} part
* @param {!string} ref
* @returns {number}
*/
function calcScore(part, ref){
var context_index = ref.indexOf(part);
var partial_index = context_index - ref.lastIndexOf(" ", context_index);
return (
(3 / ref.length * (ref.length - context_index)) + (6 / partial_index)
);
}
/**
* @param {!string} value
* @this {global_encoder}
@@ -2027,9 +2048,21 @@ var SUPPORT_ASYNC = true;
tmp += char;
}
//console.log(tmp);
// dynamic n-gram sequences
if((char === ' ') || ((count_vowels > 1) && (count_literal > 1)) || (count_vowels > 2) || (count_literal > 2) || (i === length - 1)){
if((char === ' ') || (
(count_vowels >= (length > 8 ? 2 : 1)) &&
(count_literal >= 2)
) || (
(count_vowels >= 2) &&
(count_literal >= (length > 8 ? 2 : 1))
) || (i === length - 1)){
if(tmp){

View File

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

48
flexsearch.min.js vendored
View File

@@ -1,31 +1,31 @@
/*
FlexSearch v0.2.42
FlexSearch v0.2.44
Copyright 2018 Thomas Wilkerling
Released under the Apache 2.0 Licence
https://github.com/nextapps-de/flexsearch
*/
'use strict';(function(r,B,g){var q;(q=g.define)&&q.amd?q([],function(){return B}):(q=g.modules)?q[r.toLowerCase()]=B:"undefined"!==typeof module?module.exports=B:g[r]=B})("FlexSearch",function K(r){function g(a){"string"===typeof a&&(a=F[a]);a||(a=v);this.id=a.id||L++;this.init(a);q(this,"index",function(){return this.a});q(this,"length",function(){return Object.keys(this.a).length})}function q(a,b,d){Object.defineProperty(a,b,{get:d})}function e(a){return new RegExp(a,"g")}function w(a,b,d){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 x(a,b,d,c,f,l,k){if("undefined"===typeof b[d]){if(l)f=10-l;else{var h=f.indexOf(d);f=3/f.length*(f.length-h)+6/(h-f.lastIndexOf(" ",h))}h=f;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 l=d[c],k=a[l];if(k)for(var h=0,e=k.length;h<e;h++)if(k[h]===b){1===e?delete a[l]:k.splice(h,1);break}else"object"===
typeof k[h]&&n(k[h],b)}}function G(a){var b=[];if(!a)return b;for(var d=0,c=0,f=0,l="",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&&(l+=e);if(" "===e||1<d&&1<c||2<d||2<c||h===k-1)l&&(b[f]&&2<l.length&&f++,b[f]=b[f]?b[f]+l:l," "===e&&f++,l=""),c=d=0}return b}function D(a){for(var b="",d="",c="",f=0;f<a.length;f++){var l=a[f];if(l!==d)if(f&&"h"===l){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===d||"e"===d||"i"===d||"o"===
d||"u"===d||"y"===d)&&c||" "===d)b+=l}else b+=l;c=f===a.length-1?"":a[f+1];d=l}return b}function M(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 N(a,b){var d=[];if(a){var c=0,f;for(f in a)if(a.hasOwnProperty(f)){var l=b?b.call(z,f):f;d[c++]=e("(?=.{"+(l.length+3)+",})"+l+"$");d[c++]=b?b.call(z,a[f]):a[f]}}return d}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 d=[],c=a.length;if(1<c){a.sort(P);for(var f={},l=a[0],e=l.length,h=0;h<e;)f[l[h++]]=1;for(var g,y=0,p=1;p<c;){var t=!1;l=a[p];e=l.length;for(h=0;h<e;)if(f[g=l[h++]]===p){if(p===c-1&&(d[y++]=g,b&&y===b)){t=!1;break}t=!0;f[g]=p+1}if(!t)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],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 R(a,b,d,c){a=r("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?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=a.data)&&a.result?c(a.id,a.content,a.result,a.limit):d.debug&&console.log(a)},b);var f=K.toString();d.id=
b;a.postMessage(b,{register:f,options:d,id:b});return a}var v={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=[],L=0,C={add:0,update:1,remove:2},J=e("[ -/]"),
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(" "),
'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 K(q){function g(a){"string"===typeof a&&(a=F[a]);a||(a=x);this.id=a.id||L++;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"===
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;
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+=
m;c=f===a.length-1?"":a[f+1];d=m}return b}function M(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 N(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 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 d=[],c=
a.length;if(1<c){a.sort(P);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.D||(a.D=H(function(){a.D=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],
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 R(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?
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.G&&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=K.toString();d.id=b;a.postMessage(b,{register:f,options:d,
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=[],L=0,C={add:0,update:1,remove:2},J=e("[ -/]"),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(" "),
T={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:""};g.new=function(a){return new this(a)};g.create=function(a){return g.new(a)};
g.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(A[A.length]=e(b),A[A.length]=a[b]);return this};g.register=function(a,b){z[a]=b;return this};g.encode=function(a,b){return z[a].call(z,b)};g.prototype.init=function(a){this.B=[];if(a){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,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]=R(c.id,f,a||v,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||v.mode;this.cache=a.cache||this.cache||v.cache;this.async=a.async||this.async||v.async;this.b=a.worker||this.b||v.b;this.threshold=a.threshold||d.threshold||this.threshold||v.threshold;this.depth=a.depth||d.depth||this.depth||v.depth;this.v=(b=a.encode||d.encode)&&z[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.A=M(!0===b?S:b,this.v);if(b=a.stemmer)this.D=N(!0===b?T: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?new U(3E4,50,!0):!1;return this};g.prototype.encode=function(a){a&&A.length&&(a=w(a,A));a&&this.B.length&&(a=w(a,this.B));a&&this.v&&(a=this.v.call(z,a));if(a&&this.A){a=a.split(" ");for(var b=0;b<a.length;b++){var d=this.A[a[b]];d&&(a[b]=d)}a=a.join(" ")}a&&
this.D&&(a=w(a,this.D));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,{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;for(var c="function"===typeof d?d(b):"ngram"===d?G(b):b.split(J),f={_ctx:{}},e=this.threshold,k=this.depth,h=this.l,g=c.length,y=0;y<g;y++){var p=c[y];if(p){var t=p.length;switch(d){case "reverse":case "both":for(var u="",m=t-1;1<=m;m--)u=p[m]+u,x(h,f,u,a,b,0,e);case "forward":u="";for(m=0;m<t;m++)u+=p[m],x(h,f,u,a,b,0,e);break;case "full":for(m=0;m<t;m++)for(var n=t;n>m;n--)u=p.substring(m,n),x(h,f,u,a,b,0,e);break;default:if(m=x(h,f,p,a,b,k?
1:0,e),k&&1<g&&m>=e)for(t=f._ctx[p]||(f._ctx[p]={}),p=this.o[p]||(this.o[p]=[{},{},{},{},{},{},{},{},{},{}]),m=y-k,n=y+k+1,0>m&&(m=0),n>g&&(n=g);m<n;m++)m!==y&&x(p,t,c[m],a,b,m<y?y-m:m-y,e)}}}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};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]||
g.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(A[A.length]=e(b),A[A.length]=a[b]);return this};g.register=function(a,b){z[a]=b;return this};g.encode=function(a,b){return z[a].call(z,b)};g.prototype.init=function(a){this.C=[];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,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]=R(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=(b=a.encode||d.encode)&&z[b]||("function"===typeof b?b:this.v||!1);this.G=a.debug||this.G;(b=a.matcher)&&this.addMatcher(b);
if(b=a.filter)this.B=M(!0===b?S:b,this.v);if(b=a.stemmer)this.F=N(!0===b?T:b,this.v);this.l=[{},{},{},{},{},{},{},{},{},{}];this.o={};this.a={};this.h={};this.f=[];this.D=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.C.length&&(a=y(a,this.C));a&&this.v&&(a=this.v.call(z,a));if(a&&this.B){a=a.split(" ");for(var b=0;b<a.length;b++){var d=this.B[a[b]];d&&(a[b]=d)}a=a.join(" ")}a&&this.F&&
(a=y(a,this.F));return a};g.prototype.addMatcher=function(a){var b=this.C,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,{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=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};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"===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;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 t=!0,u=k[0];p[u]="1"}else k.sort(O);var m;if(!t||(m=this.o)[u])for(var r=
t?1:0;r<h;r++){var q=k[r];if(q&&!p[q]){for(var w,x=!1,v=[],z=0,A=9;A>=f;A--)if(w=(t?m[u]:this.l)[A][q])v[z++]=w,x=!0;if(x)n[n.length]=1<z?n.concat.apply([],v):v[0];else{g=!1;break}p[q]="1"}u=q}else g=!1;g&&(c=Q(n,b));c.length?this.c="":this.c||(this.c=a);this.cache&&this.j.set(a,c);return c};g.prototype.info=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()};g.prototype.destroy=function(){this.cache&&this.j.reset();this.A=this.D=this.l=this.o=this.a=this.h=this.f=this.j=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"),"s",e(" & ")," and ",e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s\\s+")," "];return function(b){b=w(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=w(b,a));d||1<b.length&&(b=D(b));return b}}(),extra:function(){var a=[e("p"),"b",e("z"),"s",e("[cgq]"),"k",e("n"),"m",e("d"),"t",e("[vw]"),"f",e("[aeiouy]"),""];return function(b){if(!b)return b;b=this.advanced(b,!0);if(1<b.length){b=b.split(" ");for(var d=0;d<b.length;d++){var c=b[d];
1<c.length&&(b[d]=c[0]+w(c.substring(1),a))}b=b.join(" ");b=D(b)}return b}}(),balance:function(){var a=[e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s\\s+")," ",e("[aeiouy]"),""];return function(b){return D(w(b.toLowerCase(),a))}}()},H=function(){var a={};return function(b,d,c){var f=a[c];f&&clearTimeout(f);return a[c]=setTimeout(b,d)}}(),U=function(){function a(a){this.reset();this.G=a||1E3}a.prototype.reset=function(){this.cache={};this.count={};this.index={};this.keys=[]};a.prototype.set=function(a,d){if(!this.count[a]){var b=
this.keys.length;if(b===this.G){b--;var f=this.keys[b];delete this.cache[f];delete this.count[f];delete this.index[f]}this.index[a]=b;this.keys[b]=a;this.count[a]=1}this.cache[a]=d;this.get(a)};a.prototype.get=function(a){var b=this.cache[a];if(b){var c=++this.count[a],f=this.index,e=f[a];if(0<e){for(var g=this.keys,h=e;e&&this.count[g[e--]]<=c;);0<=e&&e+1!==h&&(c=g[e],f[a]=e,g.splice(e,1,a),f[c]=h,g.splice(h,1,c))}}return b};return a}();return g}(function(){var r={},B=!("undefined"===typeof Blob||
"undefined"===typeof URL||!URL.createObjectURL);return function(g,q,e,w,x){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;("+e.toString()+")()"],{type:"text/javascript"})):"../"+n+".js";n+="-"+q;r[n]||(r[n]=[]);r[n][x]=new Worker(g);r[n][x].onmessage=w;console.log("Register Worker: "+n+"@"+x);return{postMessage:function(e,g){r[n][e].postMessage(g)}}}}()),this);
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;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(O);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=Q(n,b));c.length?this.c="":this.c||(this.c=a);this.cache&&this.j.set(a,c);return c};g.prototype.info=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()};g.prototype.destroy=function(){this.cache&&(this.j.reset(),this.j=null);this.B=this.F=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"),"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=[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);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=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;("+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);

View File

@@ -1,7 +1,7 @@
{
"name": "FlexSearch",
"version": "0.2.42",
"description": "World's fastest and most memory efficient full text search library.",
"name": "flexsearch",
"version": "0.2.44",
"description": "Next-Generation full text search library with zero dependencies.",
"homepage": "https://nextapps-de.github.io/xone/",
"author": "Thomas Wilkerling",
"copyright": "Nextapps GmbH",

View File

@@ -238,17 +238,19 @@ 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-2', 'went softly stream', '446');
do_test('test-3', 'princes of the ambition', '72');
do_test('test-4', 'five-thousand leagues', '2');
do_test('test-5', 'i already observed', '458');
do_test('test-6', 'let a of his', '50');
do_test('test-7', 'take that to the rocks', '175');
do_test('test-8', 'bignes of splaknuk', '146');
do_test('test-9', 'matematikal musikal instruments', '267');
do_test('test-10', 'matical sical strument', '267');
do_test('test-11', 'lalkon the camberlayhn', '99');
do_test('test-1', 'without breach of modesty', [493]);
do_test('test-2', 'went softly stream', [446]);
do_test('test-3', 'princes of the ambition', [72, 408]);
do_test('test-4', 'five-thousand leagues', [2]);
do_test('test-5', 'i already observed', [458, 346]);
do_test('test-6', 'let a of his', [50]);
do_test('test-7', 'take that to the rocks', [175]);
do_test('test-8', 'bignes of splaknuk', [146]);
do_test('test-9', 'matematikal musikal instruments', [267]);
do_test('test-10', 'matical sical strument', [267]);
do_test('test-11', 'lalkon the camberlayhn', [99]);
// ---------------------------------------
// ---------------------------------------
@@ -256,30 +258,65 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
var nodes = document.getElementById(id).getElementsByTagName('td');
nodes[1].innerHTML = flexsearch_default.search(query).slice(0, 1).join('<br>') || '-';
nodes[2].innerHTML = flexsearch_memory.search(query).slice(0, 1).join('<br>') || '-';
nodes[3].innerHTML = flexsearch_speed.search(query).slice(0, 1).join('<br>') || '-';
nodes[4].innerHTML = flexsearch_match.search(query).slice(0, 1).join('<br>') || '-';
nodes[5].innerHTML = flexsearch_score.search(query).slice(0, 1).join('<br>') || '-';
nodes[6].innerHTML = flexsearch_balance.search(query).slice(0, 1).join('<br>') || '-';
nodes[7].innerHTML = flexsearch_fastest.search(query).slice(0, 1).join('<br>') || '-';
for(var i = 1; i < nodes.length; i++){
if(nodes[i].innerHTML === '-'){
var results;
switch(i){
case 1:
results = flexsearch_default.search(query);
break;
case 2:
results = flexsearch_memory.search(query);
break;
case 3:
results = flexsearch_speed.search(query);
break;
case 4:
results = flexsearch_match.search(query);
break;
case 5:
results = flexsearch_score.search(query);
break;
case 6:
results = flexsearch_balance.search(query);
break;
case 7:
results = flexsearch_fastest.search(query);
break;
}
for(var a = 0; a < ref.length; a++){
var current = ref[a];
nodes[i].innerHTML = results[0] || '-';
nodes[i].style.color = '#fff';
if((results[0] === current) || (results[0] === String(current))){
nodes[i].style.backgroundColor = '#0a0';
break;
}
else if(!results.length || ((results.indexOf(current) === -1) && (results.indexOf(String(current)) === -1))){
if(nodes[i].style.backgroundColor !== 'orange'){
nodes[i].style.backgroundColor = '#f00';
}
else if(nodes[i].innerHTML === ref){
nodes[i].style.backgroundColor = '#0a0';
}
else{
nodes[i].style.backgroundColor = 'orange';
}
nodes[i].style.color = '#fff';
}
}
}

View File

@@ -459,7 +459,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
}
}
}, 100);
}, 50);
</script>
</body>

View File

@@ -356,11 +356,19 @@ describe('Apply Sort by Scoring', function(){
expect(flexsearch_reverse.search("xxx").length).to.equal(1);
expect(flexsearch_reverse.search("yyy").length).to.equal(1);
expect(flexsearch_reverse.search("zzz").length).to.equal(1);
expect(flexsearch_reverse.search({query: "xxx", threshold: 2}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "xxx", threshold: 5}).length).to.equal(0);
expect(flexsearch_reverse.search({query: "yyy", threshold: 2}).length).to.equal(0);
expect(flexsearch_reverse.search({query: "zzz", threshold: 1}).length).to.equal(0);
expect(flexsearch_reverse.search({query: "xxx", threshold: 3}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "xxx", threshold: 5}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "xxx", threshold: 7}).length).to.equal(0); // <-- stop
expect(flexsearch_reverse.search({query: "yyy", threshold: 0}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "yyy", threshold: 2}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "yyy", threshold: 5}).length).to.equal(0); // <-- stop
expect(flexsearch_reverse.search({query: "zzz", threshold: 0}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "zzz", threshold: 1}).length).to.equal(1);
expect(flexsearch_reverse.search({query: "zzz", threshold: 3}).length).to.equal(0); // <-- stop
});
});