mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-08-29 16:50:13 +02:00
MOD refactoring
FIX remove from contextual index
This commit is contained in:
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
293
flexsearch.js
293
flexsearch.js
@@ -1,5 +1,5 @@
|
||||
;/**!
|
||||
* @preserve FlexSearch v0.2.32
|
||||
* @preserve FlexSearch v0.2.4
|
||||
* Copyright 2017-2018 Thomas Wilkerling
|
||||
* Released under the Apache 2.0 Licence
|
||||
* https://github.com/nextapps-de/flexsearch
|
||||
@@ -35,20 +35,10 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
var defaults = {
|
||||
|
||||
// use on of built-in functions
|
||||
// or pass custom encoding algorithm
|
||||
encode: 'icase',
|
||||
|
||||
// type of information
|
||||
mode: 'forward',
|
||||
|
||||
// use flexible cache (scales automatically)
|
||||
mode: 'ngram',
|
||||
cache: false,
|
||||
|
||||
// use flexible cache (scales automatically)
|
||||
async: false,
|
||||
|
||||
// use flexible cache (scales automatically)
|
||||
worker: false,
|
||||
|
||||
// minimum scoring (0 - 9)
|
||||
@@ -60,6 +50,7 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @enum {Object}
|
||||
* @const
|
||||
* @final
|
||||
*/
|
||||
@@ -653,7 +644,11 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
if(custom = options['matcher']) {
|
||||
|
||||
this.addMatcher(/** @type {Object<string, string>} */ (custom));
|
||||
this.addMatcher(
|
||||
|
||||
/** @type {Object<string, string>} */
|
||||
(custom)
|
||||
);
|
||||
}
|
||||
|
||||
if(SUPPORT_BUILTINS && (custom = options['filter'])) {
|
||||
@@ -664,7 +659,8 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
filter
|
||||
:
|
||||
/** @type {Array<string>} */ (custom)
|
||||
/** @type {Array<string>} */
|
||||
(custom)
|
||||
|
||||
), this.encoder);
|
||||
}
|
||||
@@ -677,29 +673,23 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
stemmer
|
||||
:
|
||||
/** @type {Object<string, string>} */ (custom)
|
||||
/** @type {Object<string, string>} */
|
||||
(custom)
|
||||
|
||||
), this.encoder);
|
||||
}
|
||||
}
|
||||
|
||||
// initialize index
|
||||
// initialize primary index
|
||||
|
||||
this._map = [
|
||||
|
||||
{/* 0 */},
|
||||
{/* 1 */},
|
||||
{/* 2 */},
|
||||
{/* 3 */},
|
||||
{/* 4 */},
|
||||
{/* 5 */},
|
||||
{/* 6 */},
|
||||
{/* 7 */},
|
||||
{/* 8 */},
|
||||
{/* 9 */},
|
||||
{/* ctx */}
|
||||
{/* 0 */}, {/* 1 */}, {/* 2 */}, {/* 3 */}, {/* 4 */},
|
||||
{/* 5 */}, {/* 6 */}, {/* 7 */}, {/* 8 */}, {/* 9 */}
|
||||
];
|
||||
|
||||
this._ctx = {};
|
||||
|
||||
this._ids = {};
|
||||
|
||||
/**
|
||||
@@ -757,18 +747,19 @@ var SUPPORT_ASYNC = true;
|
||||
if(value && this.filter){
|
||||
|
||||
var words = value.split(' ');
|
||||
var final = "";
|
||||
//var final = "";
|
||||
|
||||
for(var i = 0; i < words.length; i++){
|
||||
|
||||
var word = words[i];
|
||||
var filter = this.filter[word];
|
||||
|
||||
if(this.filter[word]){
|
||||
if(filter){
|
||||
|
||||
//var length = word.length - 1;
|
||||
|
||||
// TODO completely filter out words actually breaks the context chain
|
||||
words[i] = this.filter[word];
|
||||
words[i] = filter;
|
||||
//words[i] = word[0] + (length ? word[1] : '');
|
||||
//words[i] = '~' + word[0];
|
||||
//words.splice(i, 1);
|
||||
@@ -789,18 +780,20 @@ var SUPPORT_ASYNC = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object<string, string>} matcher
|
||||
* @param {Object<string, string>} custom
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.prototype.addMatcher = function(matcher){
|
||||
FlexSearch.prototype.addMatcher = function(custom){
|
||||
|
||||
for(var key in matcher){
|
||||
var matcher = this._matcher;
|
||||
|
||||
if(matcher.hasOwnProperty(key)){
|
||||
for(var key in custom){
|
||||
|
||||
this._matcher[this._matcher.length] = regex(key);
|
||||
this._matcher[this._matcher.length] = matcher[key];
|
||||
if(custom.hasOwnProperty(key)){
|
||||
|
||||
matcher[matcher.length] = regex(key);
|
||||
matcher[matcher.length] = custom[key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -810,17 +803,18 @@ var SUPPORT_ASYNC = true;
|
||||
/**
|
||||
* @param {?number|string} id
|
||||
* @param {?string} content
|
||||
* @param {boolean=} _skip_update
|
||||
* @this {FlexSearch}
|
||||
* @export
|
||||
*/
|
||||
|
||||
FlexSearch.prototype.add = function(id, content){
|
||||
FlexSearch.prototype.add = function(id, content, _skip_update){
|
||||
|
||||
if((typeof content === 'string') && content && (id || (id === 0))){
|
||||
|
||||
// check if index ID already exist
|
||||
|
||||
if(this._ids[id]){
|
||||
if(this._ids[id] && !_skip_update){
|
||||
|
||||
this.update(id, content);
|
||||
}
|
||||
@@ -878,9 +872,11 @@ var SUPPORT_ASYNC = true;
|
||||
:(
|
||||
tokenizer === 'ngram' ?
|
||||
|
||||
/** @type {!Array<string>} */ (ngram(content))
|
||||
/** @type {!Array<string>} */
|
||||
(ngram(content))
|
||||
:
|
||||
/** @type {string} */ (content).split(regex_split)
|
||||
/** @type {string} */
|
||||
(content).split(regex_split)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -922,7 +918,8 @@ var SUPPORT_ASYNC = true;
|
||||
dupes,
|
||||
tmp,
|
||||
id,
|
||||
/** @type {string} */ (content),
|
||||
/** @type {string} */
|
||||
(content),
|
||||
threshold
|
||||
);
|
||||
}
|
||||
@@ -943,7 +940,8 @@ var SUPPORT_ASYNC = true;
|
||||
dupes,
|
||||
tmp,
|
||||
id,
|
||||
/** @type {string} */ (content),
|
||||
/** @type {string} */
|
||||
(content),
|
||||
threshold
|
||||
);
|
||||
}
|
||||
@@ -966,7 +964,8 @@ var SUPPORT_ASYNC = true;
|
||||
dupes,
|
||||
tmp,
|
||||
id,
|
||||
/** @type {string} */ (content),
|
||||
/** @type {string} */
|
||||
(content),
|
||||
threshold
|
||||
);
|
||||
}
|
||||
@@ -984,37 +983,27 @@ var SUPPORT_ASYNC = true;
|
||||
dupes,
|
||||
value,
|
||||
id,
|
||||
/** @type {string} */ (content),
|
||||
/** @type {string} */
|
||||
(content),
|
||||
threshold
|
||||
);
|
||||
|
||||
if(depth && (word_length > 1) && (score >= threshold)){
|
||||
|
||||
var ctx_map = map[10];
|
||||
var ctx_dupes = dupes['_ctx'][value] || (dupes['_ctx'][value] = {});
|
||||
var ctx_tmp = ctx_map[value] || (ctx_map[value] = [
|
||||
var ctx_tmp = this._ctx[value] || (this._ctx[value] = [
|
||||
|
||||
{/* 0 */},
|
||||
{/* 1 */},
|
||||
{/* 2 */},
|
||||
{/* 3 */},
|
||||
{/* 4 */},
|
||||
{/* 5 */},
|
||||
{/* 6 */},
|
||||
{/* 7 */},
|
||||
{/* 8 */},
|
||||
{/* 9 */}
|
||||
// TODO test concept of deep trees instead of flat ones
|
||||
//{/* ctx */}
|
||||
{/* 0 */}, {/* 1 */}, {/* 2 */}, {/* 3 */}, {/* 4 */},
|
||||
{/* 5 */}, {/* 6 */}, {/* 7 */}, {/* 8 */}, {/* 9 */}
|
||||
]);
|
||||
|
||||
var x = i - depth;
|
||||
var y = i + depth;
|
||||
var y = i + depth + 1;
|
||||
|
||||
if(x < 0) x = 0;
|
||||
if(y > word_length - 1) y = word_length - 1;
|
||||
if(y > word_length) y = word_length;
|
||||
|
||||
for(; x <= y; x++){
|
||||
for(; x < y; x++){
|
||||
|
||||
if(x !== i) addIndex(
|
||||
|
||||
@@ -1022,7 +1011,8 @@ var SUPPORT_ASYNC = true;
|
||||
ctx_dupes,
|
||||
words[x],
|
||||
id,
|
||||
/** @type {string} */ (content),
|
||||
/** @type {string} */
|
||||
(content),
|
||||
threshold
|
||||
);
|
||||
}
|
||||
@@ -1051,50 +1041,10 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
FlexSearch.prototype.update = function(id, content){
|
||||
|
||||
if((typeof content === 'string') && (id || (id === 0))){
|
||||
if(this._ids[id] && content && (typeof content === 'string')){
|
||||
|
||||
if(this._ids[id]){
|
||||
|
||||
if(SUPPORT_WORKER && this.worker){
|
||||
|
||||
var int = parseInt(this._ids[id], 10);
|
||||
|
||||
this._worker[int].postMessage(int, {
|
||||
|
||||
'update': true,
|
||||
'id': id,
|
||||
'content': content
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
if(SUPPORT_ASYNC && this.async){
|
||||
|
||||
this._stack[id] || (
|
||||
|
||||
this._stack_keys[this._stack_keys.length] = id
|
||||
);
|
||||
|
||||
this._stack[id] = [
|
||||
|
||||
enum_task.update,
|
||||
id,
|
||||
content
|
||||
];
|
||||
|
||||
register_task(this);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
this.remove(id);
|
||||
|
||||
if(content){
|
||||
|
||||
this.add(id, content);
|
||||
}
|
||||
}
|
||||
this.remove(id);
|
||||
this.add(id, content, /* skip_update: */ true);
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -1144,32 +1094,12 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
for(var z = 0; z < 10; z++){
|
||||
|
||||
var keys = Object.keys(this._map[z]);
|
||||
removeIndex(this._map[z], id);
|
||||
}
|
||||
|
||||
for(var i = 0; i < keys.length; i++){
|
||||
if(this.depth){
|
||||
|
||||
var key = keys[i];
|
||||
var tmp = this._map[z];
|
||||
tmp = tmp && tmp[key];
|
||||
|
||||
if(tmp && tmp.length){
|
||||
|
||||
for(var a = 0; a < tmp.length; a++){
|
||||
|
||||
if(tmp[a] === id){
|
||||
|
||||
tmp.splice(a, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!tmp.length){
|
||||
|
||||
delete this._map[z][key];
|
||||
}
|
||||
}
|
||||
removeIndex(this._ctx, id);
|
||||
}
|
||||
|
||||
delete this._ids[id];
|
||||
@@ -1311,9 +1241,11 @@ var SUPPORT_ASYNC = true;
|
||||
:(
|
||||
tokenizer === 'ngram' ?
|
||||
|
||||
/** @type {!Array<string>} */ (ngram(_query))
|
||||
/** @type {!Array<string>} */
|
||||
(ngram(_query))
|
||||
:
|
||||
/** @type {string} */ (_query).split(regex_split)
|
||||
/** @type {string} */
|
||||
(_query).split(regex_split)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1341,7 +1273,7 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
var ctx_map;
|
||||
|
||||
if(!use_contextual || (ctx_map = this._map[10])[ctx_root]){
|
||||
if(!use_contextual || (ctx_map = this._ctx)[ctx_root]){
|
||||
|
||||
for(var a = use_contextual ? 1 : 0; a < length; a++){
|
||||
|
||||
@@ -1522,9 +1454,14 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
// release references
|
||||
|
||||
this.filter =
|
||||
this.stemmer =
|
||||
this._scores =
|
||||
this._map =
|
||||
this._ctx =
|
||||
this._ids =
|
||||
this._stack =
|
||||
this._stack_keys =
|
||||
this._cache = null;
|
||||
|
||||
return this;
|
||||
@@ -1554,6 +1491,13 @@ var SUPPORT_ASYNC = true;
|
||||
}
|
||||
})();
|
||||
|
||||
/** @const */
|
||||
|
||||
var global_encoder_icase = function(value){
|
||||
|
||||
return value.toLowerCase();
|
||||
};
|
||||
|
||||
/**
|
||||
* Phonetic Encoders
|
||||
* @dict {Function}
|
||||
@@ -1566,12 +1510,9 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
// case insensitive search
|
||||
|
||||
'icase': function(value){
|
||||
'icase': global_encoder_icase,
|
||||
|
||||
return value.toLowerCase();
|
||||
},
|
||||
|
||||
// simple phonetic normalization (latin)
|
||||
// literal normalization
|
||||
|
||||
'simple': (function(){
|
||||
|
||||
@@ -1618,7 +1559,7 @@ var SUPPORT_ASYNC = true;
|
||||
};
|
||||
}()),
|
||||
|
||||
// advanced phonetic transformation (latin)
|
||||
// literal transformation
|
||||
|
||||
'advanced': (function(){
|
||||
|
||||
@@ -1698,6 +1639,8 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
})(),
|
||||
|
||||
// phonetic transformation
|
||||
|
||||
'extra': (function(){
|
||||
|
||||
var soundex_b = regex('p'),
|
||||
@@ -1762,13 +1705,7 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
} : {
|
||||
|
||||
// case insensitive search
|
||||
|
||||
'icase': function(value){
|
||||
|
||||
return value.toLowerCase();
|
||||
},
|
||||
|
||||
'icase': global_encoder_icase,
|
||||
'balance': global_encoder_balance
|
||||
};
|
||||
|
||||
@@ -1895,15 +1832,59 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
if(score >= threshold){
|
||||
|
||||
var arr = map[(score + 0.5) | 0];
|
||||
var arr = map[((score + 0.5) | 0)];
|
||||
arr = arr[tmp] || (arr[tmp] = []);
|
||||
arr[arr.length] = id;
|
||||
|
||||
arr[arr.length] = id;
|
||||
}
|
||||
}
|
||||
|
||||
return score || dupes[tmp];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} map
|
||||
* @param {string|number} id
|
||||
*/
|
||||
|
||||
function removeIndex(map, id){
|
||||
|
||||
if(map){
|
||||
|
||||
var keys = Object.keys(map);
|
||||
|
||||
for(var i = 0, length_keys = keys.length; i < length_keys; i++){
|
||||
|
||||
var key = keys[i];
|
||||
var tmp = map[key];
|
||||
|
||||
if(tmp){
|
||||
|
||||
for(var a = 0, length_map = tmp.length; a < length_map; a++){
|
||||
|
||||
if(tmp[a] === id){
|
||||
|
||||
if(length_map === 1){
|
||||
|
||||
delete map[key];
|
||||
}
|
||||
else{
|
||||
|
||||
tmp.splice(a, 1);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else if(typeof tmp[a] === 'object'){
|
||||
|
||||
removeIndex(tmp[a], id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!string} part
|
||||
* @param {!string} ref
|
||||
@@ -1912,6 +1893,8 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
function calcScore(part, ref){
|
||||
|
||||
// TODO: use word distance further than char distance
|
||||
|
||||
var context_index = ref.indexOf(part);
|
||||
var partial_index = context_index - ref.lastIndexOf(" ", context_index);
|
||||
|
||||
@@ -2446,13 +2429,25 @@ var SUPPORT_ASYNC = true;
|
||||
|
||||
if(data['search']){
|
||||
|
||||
var results = flexsearch['search'](data['content'],
|
||||
|
||||
data['threshold'] ?
|
||||
|
||||
{
|
||||
'limit': data['limit'],
|
||||
'threshold': data['threshold']
|
||||
}
|
||||
:
|
||||
data['limit']
|
||||
);
|
||||
|
||||
/** @lends {Worker} */
|
||||
self.postMessage({
|
||||
|
||||
'result': flexsearch['search'](data['content'], data['threshold'] ? {'limit': data['limit'], 'threshold': data['threshold']} : data['limit']),
|
||||
'id': id,
|
||||
'content': data['content'],
|
||||
'limit': data['limit']
|
||||
'limit': data['limit'],
|
||||
'result':results
|
||||
});
|
||||
}
|
||||
else if(data['add']){
|
||||
|
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
FlexSearch v0.2.32
|
||||
FlexSearch v0.2.4
|
||||
Copyright 2017-2018 Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(d,t,l){var q;(q=l.define)&&q.amd?q([],function(){return t}):(q=l.modules)?q[d.toLowerCase()]=t:"undefined"!==typeof module?module.exports=t:l[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 l(a){return new RegExp(a,"g")}function q(a,b,c){if("undefined"===
|
||||
typeof c){for(c=0;c<b.length;c+=2)a=a.replace(b[c],b[c+1]);return a}return a.replace(b,c)}function x(a,b,c,k,g,e){if("undefined"===typeof b[c]){var f=g.indexOf(c);f=3/g.length*(g.length-f)+6/(f-g.lastIndexOf(" ",f));b[c]=f;f>=e&&(a=a[f+.5|0],a=a[c]||(a[c]=[]),a[a.length]=k)}return f||b[c]}function B(a){var b=[];if(!a)return b;for(var c=0,k=0,g=0,e="",f=a.length,p=0;p<f;p++){var m=a[p];"a"===m||"e"===m||"i"===m||"o"===m||"u"===m||"y"===m?c++:k++;" "!==m&&(e+=m);if(" "===m||1<c&&1<k||2<c||2<k||p===
|
||||
f-1)e&&(b[g]&&2<e.length&&g++,b[g]=b[g]?b[g]+e:e," "===m&&g++,e=""),k=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=[],k=a.length;if(1<k){a.sort(F);for(var g={},e=a[0],f=e.length,p=0;p<f;)g[e[p++]]=1;for(var m,d=0,n=1;n<k;){var r=!1;e=a[n];f=e.length;for(p=0;p<f;)if(g[m=e[p++]]===n){if(n===k-1&&(c[d++]=m,b&&d===b)){r=!1;break}r=!0;g[m]=n+1}if(!r)break;n++}}else k&&(c=a[0],b&&c&&c.length>b&&(c=
|
||||
c.slice(0,b)));return c}var y={encode:"icase",mode:"forward",cache:!1,async:!1,l:!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=l("[ -/]");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]=l(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.c=[];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.h=(b=a.encode||b.encode)&&w[b]||("function"===typeof b?b:this.h||
|
||||
!1);(b=a.matcher)&&this.addMatcher(b)}this.b=[{},{},{},{},{},{},{},{},{},{},{}];this.a={};this.f="";this.g=!0;return this};d.prototype.encode=function(a){a&&v.length&&(a=q(a,v));a&&this.c.length&&(a=q(a,this.c));a&&this.h&&(a=this.h.call(w,a));if(a&&this.i){a=a.split(" ");for(var b=0;b<a.length;b++){var c=a[b];this.i[c]&&(a[b]=this.i[c])}a=a.join(" ")}a&&this.j&&(a=q(a,this.j));return a};d.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.c[this.c.length]=l(b),this.c[this.c.length]=
|
||||
a[b]);return this};d.prototype.add=function(a,b){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else{b=this.encode(b);if(!b.length)return this;for(var c=this.mode,k="function"===typeof c?c(b):"ngram"===c?B(b):b.split(C),g={_ctx:{}},e=this.threshold,f=this.depth,p=this.b,m=k.length,d=0;d<m;d++){var n=k[d];if(n){var r=n.length;switch(c){case "reverse":case "both":for(var u="",h=r-1;1<=h;h--)u=n[h]+u,x(p,g,u,a,b,e);case "forward":u="";for(h=0;h<r;h++)u+=n[h],x(p,g,u,a,b,e);break;
|
||||
case "full":for(h=0;h<r;h++)for(var l=r;l>h;l--)u=n.substring(h,l),x(p,g,u,a,b,e);break;default:if(h=x(p,g,n,a,b,e),f&&1<m&&h>=e)for(h=p[10],r=g._ctx[n]||(g._ctx[n]={}),n=h[n]||(h[n]=[{},{},{},{},{},{},{},{},{},{}]),h=d-f,l=d+f,0>h&&(h=0),l>m-1&&(l=m-1);h<=l;h++)h!==d&&x(n,r,k[h],a,b,e)}}}this.a[a]="1";this.g=!1}return this};d.prototype.update=function(a,b){"string"===typeof b&&(a||0===a)&&this.a[a]&&(this.remove(a),b&&this.add(a,b));return this};d.prototype.remove=function(a){if(this.a[a]){for(var b=
|
||||
0;10>b;b++)for(var c=Object.keys(this.b[b]),k=0;k<c.length;k++){var g=c[k],e=this.b[b];if((e=e&&e[g])&&e.length)for(var f=0;f<e.length;f++)if(e[f]===a){e.splice(f,1);break}e.length||delete this.b[b][g]}delete this.a[a];this.g=!1}return this};d.prototype.search=function(a,b,c){var k=[];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 e=this;H(function(){c(e.search(a,b));e=null},1,"search-"+
|
||||
this.id);return null}if(!a||"string"!==typeof a)return k;if(!this.g)this.g=!0;else if(this.f&&0===a.indexOf(this.f))return k;var f=this.encode(a);if(!f.length)return k;var d=this.mode;f="function"===typeof d?d(f):"ngram"===d?B(f):f.split(C);d=f.length;var m=!0,l=[],n={};if(1<d)if(this.depth){var r=!0,u=f[0];n[u]="1"}else f.sort(E);var h;if(!r||(h=this.b[10])[u])for(var q=r?1:0;q<d;q++){var t=f[q];if(t&&!n[t]){for(var v,x=!1,w=[],y=0,z=9;z>=g;z--)if(v=(r?h[u]:this.b)[z][t])w[y++]=v,x=!0;if(x)l[l.length]=
|
||||
1<y?l.concat.apply([],w):w[0];else{m=!1;break}n[t]="1"}u=t}else m=!1;m&&(k=G(l,b));k.length?this.f="":this.f||(this.f=a);return k};d.prototype.reset=function(){this.destroy();return this.init()};d.prototype.destroy=function(){this.b=this.a=null;return this};var w={icase:function(a){return a.toLowerCase()},balance:function(){var a=[l("[-/]")," ",l("[^a-z0-9 ]"),"",l("\\s\\s+")," ",l("[aeiouy]"),""];return function(b){b=q(b.toLowerCase(),a);for(var c="",d="",g="",e=0;e<b.length;e++){var f=b[e];if(f!==
|
||||
d)if(e&&"h"===f){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+=f}else c+=f;g=e===b.length-1?"":b[e+1];d=f}return c}}()},H=null;return d}(!1),this);
|
||||
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,h,f,g){if("undefined"===typeof b[c]){var e=f.indexOf(c);e=3/f.length*(f.length-e)+6/(e-f.lastIndexOf(" ",e));b[c]=e;e>=g&&(a=a[e+.5|0],a=a[c]||(a[c]=[]),a[a.length]=h)}return e||b[c]}function z(a,b){if(a)for(var c=Object.keys(a),h=0,f=c.length;h<f;h++){var g=c[h],e=a[g];if(e)for(var p=0,k=e.length;p<k;p++)if(e[p]===b){1===k?delete a[g]:e.splice(p,1);break}else"object"===typeof e[p]&&z(e[p],b)}}
|
||||
function B(a){var b=[];if(!a)return b;for(var c=0,h=0,f=0,g="",e=a.length,p=0;p<e;p++){var k=a[p];"a"===k||"e"===k||"i"===k||"o"===k||"u"===k||"y"===k?c++:h++;" "!==k&&(g+=k);if(" "===k||1<c&&1<h||2<c||2<h||p===e-1)g&&(b[f]&&2<g.length&&f++,b[f]=b[f]?b[f]+g:g," "===k&&f++,g=""),h=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=[],h=a.length;if(1<h){a.sort(F);for(var f={},g=a[0],e=g.length,p=0;p<
|
||||
e;)f[g[p++]]=1;for(var k,d=0,n=1;n<h;){var r=!1;g=a[n];e=g.length;for(p=0;p<e;)if(f[k=g[p++]]===n){if(n===h-1&&(c[d++]=k,b&&d===b)){r=!1;break}r=!0;f[k]=n+1}if(!r)break;n++}}else h&&(c=a[0],b&&c&&c.length>b&&(c=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=l("[ -/]");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]=l(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.b=[];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.j=(b=a.encode||b.encode)&&w[b]||("function"===typeof b?b:this.j||!1);(b=a.matcher)&&this.addMatcher(b)}this.g=[{},{},{},{},{},{},{},{},{},{}];this.c={};this.a={};this.f="";this.h=!0;return this};d.prototype.encode=function(a){a&&v.length&&(a=q(a,v));a&&this.b.length&&(a=q(a,this.b));a&&this.j&&(a=this.j.call(w,a));if(a&&this.i){a=a.split(" ");
|
||||
for(var b=0;b<a.length;b++){var c=a[b];this.i[c]&&(a[b]=this.i[c])}a=a.join(" ")}a&&this.l&&(a=q(a,this.l));return a};d.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.b[this.b.length]=l(b),this.b[this.b.length]=a[b]);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 h="function"===typeof c?c(b):"ngram"===c?B(b):b.split(C),f={_ctx:{}},g=this.threshold,
|
||||
e=this.depth,p=this.g,k=h.length,d=0;d<k;d++){var n=h[d];if(n){var r=n.length;switch(c){case "reverse":case "both":for(var u="",m=r-1;1<=m;m--)u=n[m]+u,x(p,f,u,a,b,g);case "forward":u="";for(m=0;m<r;m++)u+=n[m],x(p,f,u,a,b,g);break;case "full":for(m=0;m<r;m++)for(var l=r;l>m;l--)u=n.substring(m,l),x(p,f,u,a,b,g);break;default:if(m=x(p,f,n,a,b,g),e&&1<k&&m>=g)for(r=f._ctx[n]||(f._ctx[n]={}),n=this.c[n]||(this.c[n]=[{},{},{},{},{},{},{},{},{},{}]),m=d-e,l=d+e,0>m&&(m=0),l>k-1&&(l=k-1);m<=l;m++)m!==
|
||||
d&&x(n,r,h[m],a,b,g)}}}this.a[a]="1";this.h=!1}return this};d.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),b&&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.g[b],a);this.depth&&z(this.c,a);delete this.a[a];this.h=!1}return this};d.prototype.search=function(a,b,c){var h=[];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 g=this;H(function(){c(g.search(a,b));g=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return h;if(!this.h)this.h=!0;else if(this.f&&0===a.indexOf(this.f))return h;var e=this.encode(a);if(!e.length)return h;var d=this.mode;e="function"===typeof d?d(e):"ngram"===d?B(e):e.split(C);d=e.length;var k=!0,l=[],n={};if(1<d)if(this.depth){var r=!0,u=e[0];n[u]="1"}else e.sort(E);var m;if(!r||(m=this.c)[u])for(var q=r?1:0;q<d;q++){var t=e[q];if(t&&!n[t]){for(var v,
|
||||
x=!1,w=[],y=0,z=9;z>=f;z--)if(v=(r?m[u]:this.g)[z][t])w[y++]=v,x=!0;if(x)l[l.length]=1<y?l.concat.apply([],w):w[0];else{k=!1;break}n[t]="1"}u=t}else k=!1;k&&(h=G(l,b));h.length?this.f="":this.f||(this.f=a);return h};d.prototype.reset=function(){this.destroy();return this.init()};d.prototype.destroy=function(){this.i=this.l=this.g=this.c=this.a=null;return this};var w={icase:function(a){return a.toLowerCase()},balance:function(){var a=[l("[-/]")," ",l("[^a-z0-9 ]"),"",l("\\s\\s+")," ",l("[aeiouy]"),
|
||||
""];return function(b){b=q(b.toLowerCase(),a);for(var c="",d="",f="",g=0;g<b.length;g++){var e=b[g];if(e!==d)if(g&&"h"===e){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+=e}else c+=e;f=g===b.length-1?"":b[g+1];d=e}return c}}()},H=null;return d}(!1),this);
|
||||
|
48
flexsearch.min.js
vendored
48
flexsearch.min.js
vendored
@@ -1,30 +1,30 @@
|
||||
/*
|
||||
FlexSearch v0.2.32
|
||||
FlexSearch v0.2.4
|
||||
Copyright 2017-2018 Thomas Wilkerling
|
||||
Released under the Apache 2.0 Licence
|
||||
https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
'use strict';(function(n,C,g){var p;(p=g.define)&&p.amd?p([],function(){return C}):(p=g.modules)?p[n.toLowerCase()]=C:"undefined"!==typeof module?module.exports=C:g[n]=C})("FlexSearch",function L(n){function g(a){"string"===typeof a&&(a=G[a]);a||(a=u);this.id=a.id||M++;this.init(a);p(this,"index",function(){return this.a});p(this,"length",function(){return Object.keys(this.a).length})}function p(a,b,d){Object.defineProperty(a,b,{get:d})}function e(a){return new RegExp(a,"g")}function v(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 w(a,b,d,c,f,k){if("undefined"===typeof b[d]){var h=f.indexOf(d);h=3/f.length*(f.length-h)+6/(h-f.lastIndexOf(" ",h));b[d]=h;h>=k&&(a=a[h+.5|0],a=a[d]||(a[d]=[]),a[a.length]=c)}return h||b[d]}function x(a){var b=[];if(!a)return b;for(var d=0,c=0,f=0,k="",h=a.length,B=0;B<h;B++){var e=a[B];"a"===e||"e"===e||"i"===e||"o"===e||"u"===e||"y"===e?d++:c++;" "!==e&&(k+=e);if(" "===e||1<d&&1<c||2<d||2<c||B===
|
||||
h-1)k&&(b[f]&&2<k.length&&f++,b[f]=b[f]?b[f]+k:k," "===e&&f++,k=""),c=d=0}return b}function F(a){for(var b="",d="",c="",f=0;f<a.length;f++){var k=a[f];if(k!==d)if(f&&"h"===k){if(c="a"===c||"e"===c||"i"===c||"o"===c||"u"===c||"y"===c,("a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d)&&c||" "===d)b+=k}else b+=k;c=f===a.length-1?"":a[f+1];d=k}return b}function N(a,b){var d={};if(H)for(var c=0;c<a.length;c++){var f=b?b.call(y,a[c]):a[c];d[f]=String.fromCharCode(65E3-a.length+c)}return d}function O(a,
|
||||
b){var d=[];if(a){var c=0,f;for(f in a)if(a.hasOwnProperty(f)){var k=b?b.call(y,f):f;d[c++]=e("(?=.{"+(k.length+3)+",})"+k+"$");d[c++]=b?b.call(y,a[f]):a[f]}}return d}function P(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function Q(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function R(a,b){var d=[],c=a.length;if(1<c){a.sort(Q);for(var f={},k=a[0],e=k.length,B=0;B<e;)f[k[B++]]=1;for(var g,q=0,m=1;m<c;){var r=!1;k=a[m];e=k.length;for(B=0;B<e;)if(f[g=k[B++]]===m){if(m===c-1&&(d[q++]=g,b&&q===
|
||||
b)){r=!1;break}r=!0;f[g]=m+1}if(!r)break;m++}}else c&&(d=a[0],b&&d&&d.length>b&&(d=d.slice(0,b)));return d}function E(a){a.B||(a.B=I(function(){a.B=null;var b=a.async;b&&(a.async=!1);if(a.c.length){for(var d=J(),c;(c=a.c.shift())||0===c;){var f=a.h[c];switch(f[0]){case D.add:a.add(f[1],f[2]);break;case D.update:a.update(f[1],f[2]);break;case D.remove:a.remove(f[1])}a.h[c]=null;delete a.h[c];if(100<J()-d)break}a.c.length&&E(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function J(){return"undefined"!==
|
||||
typeof performance?performance.now():(new Date).getTime()}function S(a,b,d,c){a=n("flexsearch","id"+a,function(){var a,b;self.a=function(c){if(c=c.data)c.search?self.postMessage({result:b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit),id:a,content:c.content,limit:c.limit}):c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset():c.info?(c=b.info(),c.worker=a,b.C&&console.log(c)):c.register&&(a=c.id,c.options.cache=!1,c.options.async=
|
||||
!0,c.options.worker=!1,b=(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=L.toString();d.id=b;a.postMessage(b,{register:f,options:d,id:b});return a}var u={encode:"icase",mode:"forward",cache:!1,async:!1,b:!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},fastest:{encode:"icase",mode:"strict",threshold:9,depth:1}},z=[],M=0,D={add:0,update:1,remove:2},K=e("[ -/]"),T="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(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 L(r){function g(a){"string"===typeof a&&(a=F[a]);a||(a=w);this.id=a.id||M++;this.init(a);q(this,"index",function(){return this.a});q(this,"length",function(){return Object.keys(this.a).length})}function q(a,b,e){Object.defineProperty(a,b,{get:e})}function d(a){return new RegExp(a,"g")}function x(a,b,e){if("undefined"===
|
||||
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 y(a,b,e,c,l,k){if("undefined"===typeof b[e]){var f=l.indexOf(e);f=3/l.length*(l.length-f)+6/(f-l.lastIndexOf(" ",f));b[e]=f;f>=k&&(a=a[f+.5|0],a=a[e]||(a[e]=[]),a[a.length]=c)}return f||b[e]}function m(a,b){if(a)for(var e=Object.keys(a),c=0,l=e.length;c<l;c++){var k=e[c],f=a[k];if(f)for(var h=0,d=f.length;h<d;h++)if(f[h]===b){1===d?delete a[k]:f.splice(h,1);break}else"object"===typeof f[h]&&m(f[h],b)}}
|
||||
function G(a){var b=[];if(!a)return b;for(var e=0,c=0,l=0,k="",f=a.length,h=0;h<f;h++){var d=a[h];"a"===d||"e"===d||"i"===d||"o"===d||"u"===d||"y"===d?e++:c++;" "!==d&&(k+=d);if(" "===d||1<e&&1<c||2<e||2<c||h===f-1)k&&(b[l]&&2<k.length&&l++,b[l]=b[l]?b[l]+k:k," "===d&&l++,k=""),c=e=0}return b}function D(a){for(var b="",e="",c="",l=0;l<a.length;l++){var d=a[l];if(d!==e)if(l&&"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+=d;c=l===a.length-1?"":a[l+1];e=d}return b}function N(a,b){var e={};if(H)for(var c=0;c<a.length;c++){var d=b?b.call(z,a[c]):a[c];e[d]=String.fromCharCode(65E3-a.length+c)}return e}function O(a,b){var e=[];if(a){var c=0,l;for(l in a)if(a.hasOwnProperty(l)){var k=b?b.call(z,l):l;e[c++]=d("(?=.{"+(k.length+3)+",})"+k+"$");e[c++]=b?b.call(z,a[l]):a[l]}}return e}function P(a,b){a=a.length-b.length;return 0>a?1:0<a?-1:0}function Q(a,b){a=a.length-b.length;return 0>a?-1:0<a?1:0}function R(a,
|
||||
b){var e=[],c=a.length;if(1<c){a.sort(Q);for(var d={},k=a[0],f=k.length,h=0;h<f;)d[k[h++]]=1;for(var g,t=0,p=1;p<c;){var u=!1;k=a[p];f=k.length;for(h=0;h<f;)if(d[g=k[h++]]===p){if(p===c-1&&(e[t++]=g,b&&t===b)){u=!1;break}u=!0;d[g]=p+1}if(!u)break;p++}}else c&&(e=a[0],b&&e&&e.length>b&&(e=e.slice(0,b)));return e}function E(a){a.C||(a.C=I(function(){a.C=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 C.add:a.add(d[1],d[2]);break;
|
||||
case C.update:a.update(d[1],d[2]);break;case C.remove:a.remove(d[1])}a.h[c]=null;delete a.h[c];if(100<J()-e)break}a.f.length&&E(a)}b&&(a.async=b)},1,"search-async-"+a.id))}function J(){return"undefined"!==typeof performance?performance.now():(new Date).getTime()}function S(a,b,e,c){a=r("flexsearch","id"+a,function(){var a,b;self.a=function(c){if(c=c.data)c.search?self.postMessage({result:b.search(c.content,c.threshold?{limit:c.limit,threshold:c.threshold}:c.limit),id:a,content:c.content,limit:c.limit}):
|
||||
c.add?b.add(c.id,c.content):c.update?b.update(c.id,c.content):c.remove?b.remove(c.id):c.reset?b.reset():c.info?(c=b.info(),c.worker=a,b.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):e.debug&&console.log(a)},b);var d=L.toString();e.id=b;a.postMessage(b,{register:d,
|
||||
options:e,id:b});return a}var w={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=[],M=0,C={add:0,update:1,remove:2},K=d("[ -/]"),T="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(" "),
|
||||
H={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)&&(z[z.length]=e(b),z[z.length]=a[b]);return this};g.register=function(a,b){y[a]=b;return this};g.encode=function(a,b){return y[a].call(y,b)};g.prototype.init=function(a){this.m=[];if(a){var b=a.profile,d=b?G[b]:{};if(b=a.worker)if("undefined"===typeof Worker)a.worker=!1,a.async=!0,this.j=null;else{var c=this;b=parseInt(b,10)||4;c.s=-1;c.o=0;c.i=[];c.w=null;c.j=Array(b);for(var f=0;f<b;f++)c.j[f]=S(c.id,f,a||u,function(a,b,d,f){c.o!==c.b&&
|
||||
(c.i=c.i.concat(d),c.o++,f&&c.i.length>=f&&(c.o=c.b),c.w&&c.o===c.b&&(c.i.length?c.f="":c.f||(c.f=b),c.cache&&c.l.set(b,c.i),c.w(c.i),c.i=[]))})}this.mode=a.mode||d.mode||this.mode||u.mode;this.cache=a.cache||this.cache||u.cache;this.async=a.async||this.async||u.async;this.b=a.worker||this.b||u.b;this.threshold=a.threshold||d.threshold||this.threshold||u.threshold;this.depth=a.depth||d.depth||this.depth||u.depth;this.v=(b=a.encode||d.encode)&&y[b]||("function"===typeof b?b:this.v||!1);this.C=a.debug||
|
||||
this.C;(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.A=N(!0===b?T:b,this.v);if(b=a.stemmer)this.D=O(!0===b?H:b,this.v)}this.g=[{},{},{},{},{},{},{},{},{},{},{}];this.a={};this.h={};this.c=[];this.B=null;this.f="";this.u=!0;this.l=this.cache?new U(3E4,50,!0):!1;return this};g.prototype.encode=function(a){a&&z.length&&(a=v(a,z));a&&this.m.length&&(a=v(a,this.m));a&&this.v&&(a=this.v.call(y,a));if(a&&this.A){a=a.split(" ");for(var b=0;b<a.length;b++){var d=a[b];this.A[d]&&(a[b]=this.A[d])}a=a.join(" ")}a&&
|
||||
this.D&&(a=v(a,this.D));return a};g.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.m[this.m.length]=e(b),this.m[this.m.length]=a[b]);return this};g.prototype.add=function(a,b){if("string"===typeof b&&b&&(a||0===a))if(this.a[a])this.update(a,b);else{if(this.b)return++this.s>=this.j.length&&(this.s=0),this.j[this.s].postMessage(this.s,{add:!0,id:a,content:b}),this.a[a]=""+this.s,this;if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[D.add,a,b],E(this),
|
||||
this;b=this.encode(b);if(!b.length)return this;for(var d=this.mode,c="function"===typeof d?d(b):"ngram"===d?x(b):b.split(K),f={_ctx:{}},e=this.threshold,h=this.depth,g=this.g,n=c.length,q=0;q<n;q++){var m=c[q];if(m){var r=m.length;switch(d){case "reverse":case "both":for(var t="",l=r-1;1<=l;l--)t=m[l]+t,w(g,f,t,a,b,e);case "forward":t="";for(l=0;l<r;l++)t+=m[l],w(g,f,t,a,b,e);break;case "full":for(l=0;l<r;l++)for(var A=r;A>l;A--)t=m.substring(l,A),w(g,f,t,a,b,e);break;default:if(l=w(g,f,m,a,b,e),
|
||||
h&&1<n&&l>=e)for(l=g[10],r=f._ctx[m]||(f._ctx[m]={}),m=l[m]||(l[m]=[{},{},{},{},{},{},{},{},{},{}]),l=q-h,A=q+h,0>l&&(l=0),A>n-1&&(A=n-1);l<=A;l++)l!==q&&w(m,r,c[l],a,b,e)}}}this.a[a]="1";this.u=!1}return this};g.prototype.update=function(a,b){if("string"===typeof b&&(a||0===a)&&this.a[a]){if(this.b){var d=parseInt(this.a[a],10);this.j[d].postMessage(d,{update:!0,id:a,content:b});return this}if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[D.update,a,b],E(this),this;this.remove(a);
|
||||
b&&this.add(a,b)}return this};g.prototype.remove=function(a){if(this.a[a]){if(this.b){var b=parseInt(this.a[a],10);this.j[b].postMessage(b,{remove:!0,id:a});delete this.a[a];return this}if(this.async)return this.h[a]||(this.c[this.c.length]=a),this.h[a]=[D.remove,a],E(this),this;for(b=0;10>b;b++)for(var d=Object.keys(this.g[b]),c=0;c<d.length;c++){var e=d[c],k=this.g[b];if((k=k&&k[e])&&k.length)for(var h=0;h<k.length;h++)if(k[h]===a){k.splice(h,1);break}k.length||delete this.g[b][e]}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 e=a.threshold;a=a.query}e=(e||this.threshold||0)|0;"function"===typeof b?(d=b,b=1E3):b||(b=1E3);if(this.b){this.w=d;this.o=0;this.i=[];for(c=0;c<this.b;c++)this.j[c].postMessage(c,{search:!0,limit:b,threshold:e,content:a});return null}if(d){var k=this;I(function(){d(k.search(a,b));k=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return c;var h=a;if(!this.u)this.cache&&
|
||||
(this.f="",this.l.reset()),this.u=!0;else if(this.cache){var g=this.l.get(a);if(g)return g}else if(this.f&&0===a.indexOf(this.f))return c;h=this.encode(h);if(!h.length)return c;g=this.mode;h="function"===typeof g?g(h):"ngram"===g?x(h):h.split(K);g=h.length;var n=!0,q=[],m={};if(1<g)if(this.depth){var r=!0,t=h[0];m[t]="1"}else h.sort(P);var l;if(!r||(l=this.g[10])[t])for(var A=r?1:0;A<g;A++){var p=h[A];if(p&&!m[p]){for(var v,w=!1,u=[],y=0,z=9;z>=e;z--)if(v=(r?l[t]:this.g)[z][p])u[y++]=v,w=!0;if(w)q[q.length]=
|
||||
1<y?q.concat.apply([],u):u[0];else{n=!1;break}m[p]="1"}t=p}else n=!1;n&&(c=R(q,b));c.length?this.f="":this.f||(this.f=a);this.cache&&this.l.set(a,c);return c};g.prototype.info=function(){if(this.b)for(var a=0;a<this.b;a++)this.j[a].postMessage(a,{info:!0,id:this.id});else{for(var b,d,c=0,e=0,g=0,h=0;10>h;h++)for(b=Object.keys(this.g[h]),a=0;a<b.length;a++)d=this.g[h][b[a]].length,c+=d+2*b[a].length+4,e+=d,g+=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:e,chars:g,status:this.u,cache:this.c.length,matcher:z.length,worker:this.b}}};g.prototype.reset=function(){this.destroy();return this.init()};g.prototype.destroy=function(){this.cache&&this.l.reset();this.g=this.a=this.l=null;return this};var y={icase:function(a){return a.toLowerCase()},simple:function(){var a=[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=v(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=v(b,a));d||1<b.length&&(b=F(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]+v(c.substring(1),a))}b=b.join(" ");b=F(b)}return b}}(),balance:function(){var a=[e("[-/]")," ",e("[^a-z0-9 ]"),"",e("\\s\\s+")," ",e("[aeiouy]"),
|
||||
""];return function(b){return F(v(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)}}(),U=function(){function a(){this.cache={}}a.prototype.reset=function(){this.cache={}};a.prototype.set=function(a,d){this.cache[a]=d};a.prototype.get=function(a){return this.cache[a]};return a}();return g}(function(){var n={},C=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(g,p,e,v,w){var x=
|
||||
g;g=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;("+e.toString()+")()"],{type:"text/javascript"})):"../"+x+".js";x+="-"+p;n[x]||(n[x]=[]);n[x][w]=new Worker(g);n[x][w].onmessage=v;console.log("Register Worker: "+x+"@"+w);return{postMessage:function(e,g){n[x][e].postMessage(g)}}}}()),this);
|
||||
g.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(A[A.length]=d(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.m=[];if(a){var b=a.profile,e=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.u=-1;c.o=0;c.g=[];c.B=null;c.i=Array(b);for(var d=0;d<b;d++)c.i[d]=S(c.id,d,a||w,function(a,b,e,d){c.o!==c.b&&
|
||||
(c.g=c.g.concat(e),c.o++,d&&c.g.length>=d&&(c.o=c.b),c.B&&c.o===c.b&&(c.g.length?c.c="":c.c||(c.c=b),c.cache&&c.j.set(b,c.g),c.B(c.g),c.g=[]))})}this.mode=a.mode||e.mode||this.mode||w.mode;this.cache=a.cache||this.cache||w.cache;this.async=a.async||this.async||w.async;this.b=a.worker||this.b||w.b;this.threshold=a.threshold||e.threshold||this.threshold||w.threshold;this.depth=a.depth||e.depth||this.depth||w.depth;this.w=(b=a.encode||e.encode)&&z[b]||("function"===typeof b?b:this.w||!1);this.F=a.debug||
|
||||
this.F;(b=a.matcher)&&this.addMatcher(b);if(b=a.filter)this.A=N(!0===b?T:b,this.w);if(b=a.stemmer)this.D=O(!0===b?H:b,this.w)}this.l=[{},{},{},{},{},{},{},{},{},{}];this.s={};this.a={};this.h={};this.f=[];this.C=null;this.c="";this.v=!0;this.j=this.cache?new U(3E4,50,!0):!1;return this};g.prototype.encode=function(a){a&&A.length&&(a=x(a,A));a&&this.m.length&&(a=x(a,this.m));a&&this.w&&(a=this.w.call(z,a));if(a&&this.A){a=a.split(" ");for(var b=0;b<a.length;b++){var e=a[b];this.A[e]&&(a[b]=this.A[e])}a=
|
||||
a.join(" ")}a&&this.D&&(a=x(a,this.D));return a};g.prototype.addMatcher=function(a){for(var b in a)a.hasOwnProperty(b)&&(this.m[this.m.length]=d(b),this.m[this.m.length]=a[b]);return this};g.prototype.add=function(a,b,e){if("string"===typeof b&&b&&(a||0===a))if(this.a[a]&&!e)this.update(a,b);else{if(this.b)return++this.u>=this.i.length&&(this.u=0),this.i[this.u].postMessage(this.u,{add:!0,id:a,content:b}),this.a[a]=""+this.u,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;e=this.mode;for(var c="function"===typeof e?e(b):"ngram"===e?G(b):b.split(K),d={_ctx:{}},k=this.threshold,f=this.depth,h=this.l,g=c.length,t=0;t<g;t++){var p=c[t];if(p){var u=p.length;switch(e){case "reverse":case "both":for(var v="",n=u-1;1<=n;n--)v=p[n]+v,y(h,d,v,a,b,k);case "forward":v="";for(n=0;n<u;n++)v+=p[n],y(h,d,v,a,b,k);break;case "full":for(n=0;n<u;n++)for(var m=u;m>n;m--)v=p.substring(n,m),y(h,d,v,a,b,k);break;default:if(n=
|
||||
y(h,d,p,a,b,k),f&&1<g&&n>=k)for(u=d._ctx[p]||(d._ctx[p]={}),p=this.s[p]||(this.s[p]=[{},{},{},{},{},{},{},{},{},{}]),n=t-f,m=t+f,0>n&&(n=0),m>g-1&&(m=g-1);n<=m;n++)n!==t&&y(p,u,c[n],a,b,k)}}}this.a[a]="1";this.v=!1}return this};g.prototype.update=function(a,b){this.a[a]&&b&&"string"===typeof b&&(this.remove(a),b&&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++)m(this.l[b],a);this.depth&&m(this.s,a);delete this.a[a];this.v=!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 e=a.threshold;a=a.query}e=(e||this.threshold||0)|0;"function"===typeof b?(d=b,b=1E3):b||(b=1E3);if(this.b){this.B=d;this.o=0;this.g=[];for(c=0;c<this.b;c++)this.i[c].postMessage(c,{search:!0,limit:b,threshold:e,content:a});return null}if(d){var g=
|
||||
this;I(function(){d(g.search(a,b));g=null},1,"search-"+this.id);return null}if(!a||"string"!==typeof a)return c;var f=a;if(!this.v)this.cache&&(this.c="",this.j.reset()),this.v=!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;f=this.encode(f);if(!f.length)return c;h=this.mode;f="function"===typeof h?h(f):"ngram"===h?G(f):f.split(K);h=f.length;var m=!0,t=[],p={};if(1<h)if(this.depth){var u=!0,v=f[0];p[v]="1"}else f.sort(P);var n;if(!u||(n=this.s)[v])for(var r=
|
||||
u?1:0;r<h;r++){var q=f[r];if(q&&!p[q]){for(var x,y=!1,w=[],z=0,A=9;A>=e;A--)if(x=(u?n[v]:this.l)[A][q])w[z++]=x,y=!0;if(y)t[t.length]=1<z?t.concat.apply([],w):w[0];else{m=!1;break}p[q]="1"}v=q}else m=!1;m&&(c=R(t,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,g=0,k=0,f=0;10>f;f++)for(b=Object.keys(this.l[f]),a=0;a<b.length;a++)d=this.l[f][b[a]].length,
|
||||
c+=d+2*b[a].length+4,g+=d,k+=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:g,chars:k,status:this.v,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.s=this.a=this.h=this.f=this.j=null;return this};var z={icase:function(a){return a.toLowerCase()},simple:function(){var a=
|
||||
[d("[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]"),"a",d("[\u00e8\u00e9\u00ea\u00eb]"),"e",d("[\u00ec\u00ed\u00ee\u00ef]"),"i",d("[\u00f2\u00f3\u00f4\u00f5\u00f6\u0151]"),"o",d("[\u00f9\u00fa\u00fb\u00fc\u0171]"),"u",d("[\u00fd\u0177\u00ff]"),"y",d("\u00f1"),"n",d("\u00e7"),"c",d("\u00df"),"s",d(" & ")," and ",d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," "];return function(b){b=x(b.toLowerCase(),a);return" "!==b?b:""}}(),advanced:function(){var a=[d("ae"),"a",d("ai"),"ei",d("ay"),"ei",d("ey"),"ei",d("oe"),
|
||||
"o",d("ue"),"u",d("ie"),"i",d("sz"),"s",d("zs"),"s",d("sh"),"s",d("ck"),"k",d("cc"),"k",d("dt"),"t",d("ph"),"f",d("pf"),"f",d("ou"),"o",d("uo"),"u"];return function(b,d){if(!b)return b;b=this.simple(b);2<b.length&&(b=x(b,a));d||1<b.length&&(b=D(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];
|
||||
1<c.length&&(b[d]=c[0]+x(c.substring(1),a))}b=b.join(" ");b=D(b)}return b}}(),balance:function(){var a=[d("[-/]")," ",d("[^a-z0-9 ]"),"",d("\\s\\s+")," ",d("[aeiouy]"),""];return function(b){return D(x(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)}}(),U=function(){function a(){this.cache={}}a.prototype.reset=function(){this.cache={}};a.prototype.set=function(a,d){this.cache[a]=d};a.prototype.get=function(a){return this.cache[a]};
|
||||
return a}();return g}(function(){var r={},B=!("undefined"===typeof Blob||"undefined"===typeof URL||!URL.createObjectURL);return function(g,q,d,x,y){var m=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;("+d.toString()+")()"],{type:"text/javascript"})):"../"+m+".js";m+="-"+q;r[m]||(r[m]=[]);r[m][y]=new Worker(g);r[m][y].onmessage=x;console.log("Register Worker: "+m+"@"+y);return{postMessage:function(d,
|
||||
g){r[m][d].postMessage(g)}}}}()),this);
|
||||
|
18
package.json
18
package.json
@@ -1,8 +1,17 @@
|
||||
{
|
||||
"name": "flexsearch",
|
||||
"version": "0.2.32",
|
||||
"name": "FlexSearch",
|
||||
"version": "0.2.4",
|
||||
"description": "World's fastest and most memory efficient full text search library.",
|
||||
"keywords": [],
|
||||
"homepage": "https://nextapps-de.github.io/xone/",
|
||||
"author": "Thomas Wilkerling",
|
||||
"copyright": "Nextapps GmbH",
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"full text search",
|
||||
"elastic search",
|
||||
"fastest search",
|
||||
"contextual search"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/nextapps-de/flexsearch/issues",
|
||||
"email": "info@nextapps.de"
|
||||
@@ -32,9 +41,6 @@
|
||||
"flexsearch.min.js",
|
||||
"test/"
|
||||
],
|
||||
"homepage": "https://nextapps-de.github.io/xone/",
|
||||
"author": "Thomas Wilkerling",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"chai": "^4.1.2",
|
||||
|
@@ -12,7 +12,7 @@
|
||||
<script src="../node_modules/mocha/mocha.js"></script>
|
||||
<script src="../node_modules/chai/chai.js"></script>
|
||||
<!--<script src="../node_modules/mocha-phantomjs-core/browser-shim.js"></script>-->
|
||||
<script src="../flexsearch.min.js"></script>
|
||||
<script src="../flexsearch.js"></script>
|
||||
<script>
|
||||
window.initMochaPhantomJS && initMochaPhantomJS();
|
||||
mocha.ui('bdd');
|
||||
|
@@ -177,18 +177,19 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<br>
|
||||
<b>Red:</b> No results.<br>
|
||||
<b>Yellow:</b> Most relevant result is not on the first place.<br>
|
||||
<b>Green:</b> Most relevant result was was successfully found on the first place.<br><br>
|
||||
<b>Note:</b> Open console and type e.g. <i>data[493]</i>
|
||||
<hr>
|
||||
<div style="line-height: 2em">
|
||||
<div style="display:inline-block; width:16px; height:16px; background: #f00"></div> Either no results or relevant content was not included in results.<br>
|
||||
<div style="display:inline-block; width:16px; height:16px; background: orange"></div> Most relevant result was not found in the first place.<br>
|
||||
<div style="display:inline-block; width:16px; height:16px; background: #0a0"></div> Most relevant result was successfully found in the first place.<br>
|
||||
<b>Note:</b> Open console and type e.g. <i>data[493]</i>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
var data = [];
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
var start = 0;
|
||||
var new_data = text_data.split('. ');
|
||||
var tmp = '';
|
||||
|
||||
@@ -206,7 +207,23 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
||||
}
|
||||
}
|
||||
|
||||
var bulksearch = new BulkSearch({
|
||||
tmp = null;
|
||||
new_data = null;
|
||||
text_data = null;
|
||||
|
||||
var bulksearch;
|
||||
var flexsearch;
|
||||
var elasticsearch;
|
||||
var lunrsearch;
|
||||
var wade;
|
||||
var fuse;
|
||||
var jssearch;
|
||||
var jsii;
|
||||
var bm25;
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
bulksearch = new BulkSearch({
|
||||
type: 'short', // this type specifies the maximum bitlength of assigned IDs!
|
||||
encode: 'advanced',
|
||||
multi: true,
|
||||
@@ -222,7 +239,9 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
||||
|
||||
console.timeEnd('bulksearch');
|
||||
|
||||
var flexsearch = new FlexSearch({
|
||||
// -----------------------------------------------------------
|
||||
|
||||
flexsearch = new FlexSearch({
|
||||
encode: 'extra',
|
||||
mode: 'strict',
|
||||
threshold: 5,
|
||||
@@ -242,7 +261,9 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
||||
|
||||
console.timeEnd('flexsearch');
|
||||
|
||||
var elasticsearch = elasticlunr(function () {
|
||||
// -----------------------------------------------------------
|
||||
|
||||
elasticsearch = elasticlunr(function () {
|
||||
this.setRef('id');
|
||||
this.addField('content');
|
||||
});
|
||||
@@ -255,9 +276,11 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
||||
|
||||
console.timeEnd('elasticsearch');
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
console.time('lunr');
|
||||
|
||||
var lunrsearch = lunr(function(){
|
||||
lunrsearch = lunr(function(){
|
||||
this.ref('id');
|
||||
this.field('content');
|
||||
for(var i = 0; i < data.length; i++){
|
||||
@@ -267,9 +290,8 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
||||
|
||||
console.timeEnd('lunr');
|
||||
|
||||
console.time('wade');
|
||||
var wade = Wade(data.slice(0));
|
||||
console.timeEnd('wade');
|
||||
// -----------------------------------------------------------
|
||||
|
||||
var wadesearch = function(query){
|
||||
return wade(query).sort(sort_by_score_down);
|
||||
};
|
||||
@@ -279,6 +301,12 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
||||
return sum < 0 ? 1 : sum > 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
console.time('wade');
|
||||
wade = Wade(data.slice(0));
|
||||
console.timeEnd('wade');
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
var payload = [];
|
||||
|
||||
for(var i = 0; i < data.length; i++){
|
||||
@@ -288,56 +316,72 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
|
||||
// Note: fuse adds async?
|
||||
console.time('fuse');
|
||||
|
||||
var fuse = new Fuse(payload.slice(0), {
|
||||
keys: ['id', 'content'],
|
||||
id: 'id'
|
||||
fuse = new Fuse(payload.slice(0), {
|
||||
keys: ['content'],
|
||||
id: 'id',
|
||||
shouldSort: true,
|
||||
threshold: 0.6,
|
||||
location: 0,
|
||||
distance: 100,
|
||||
findAllMatches: true,
|
||||
maxPatternLength: 32,
|
||||
minMatchCharLength: 1
|
||||
});
|
||||
|
||||
console.timeEnd('fuse');
|
||||
|
||||
var jssearch = new JsSearch.Search('id');
|
||||
// payload = null;
|
||||
// data = null;
|
||||
// return;
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
jssearch = new JsSearch.Search('id');
|
||||
jssearch.addIndex('content');
|
||||
console.time('jssearch');
|
||||
jssearch.addDocuments(payload.slice(0));
|
||||
console.timeEnd('jssearch');
|
||||
|
||||
// -----------------------------------------------------------
|
||||
|
||||
var payload = [];
|
||||
|
||||
for(var i = 0; i < data.length; i++){
|
||||
payload[i] = {id: i, text: data[i]};
|
||||
}
|
||||
|
||||
var jsii = new JSii();
|
||||
jsii = new JSii();
|
||||
|
||||
console.time('jsii');
|
||||
jsii.feedDocs(payload.slice(0));
|
||||
console.timeEnd('jsii');
|
||||
|
||||
var bm25 = new BM25();
|
||||
// -----------------------------------------------------------
|
||||
|
||||
bm25 = new BM25();
|
||||
|
||||
console.time('bm25');
|
||||
for(var i = 0; i < data.length; i++){
|
||||
bm25.addDocument({id: i, body: data[i]});
|
||||
}
|
||||
console.timeEnd('bm25');
|
||||
|
||||
bm25.updateIdf();
|
||||
console.timeEnd('bm25');
|
||||
|
||||
payload = null;
|
||||
|
||||
// ---------------------------------------
|
||||
// -----------------------------------------------------------
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
// ---------------------------------------
|
||||
|
||||
@@ -345,36 +389,68 @@ 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.search(query).slice(0, 1).join('<br>') || '-';
|
||||
nodes[2].innerHTML = bulksearch.search(query).slice(0, 1).join('<br>') || '-';
|
||||
nodes[3].innerHTML = elasticsearch.search(query).slice(0, 1).map(function(val){return val.ref}).join('<br>') || '-';
|
||||
nodes[4].innerHTML = lunrsearch.search(query).slice(0, 1).map(function(val){return val.ref}).join('<br>') || '-';
|
||||
nodes[5].innerHTML = wadesearch(query).slice(0, 1).map(function(val){return val.index}).join('<br>') || '-';
|
||||
nodes[6].innerHTML = fuse.search(query).slice(0, 1).join('<br>') || '-';
|
||||
nodes[7].innerHTML = jssearch.search(query).slice(0, 1).map(function(val){return val.id}).join('<br>') || '-';
|
||||
nodes[8].innerHTML = jsii.search(query).docs.slice(0, 1).map(function(val){return val.id}).join('<br>') || '-';
|
||||
nodes[9].innerHTML = bm25.search(query).slice(0, 1).map(function(val){return val.id}).join('<br>') || '-';
|
||||
|
||||
for(var i = 1; i < nodes.length; i++){
|
||||
|
||||
if(nodes[i].innerHTML === '-'){
|
||||
var results;
|
||||
|
||||
nodes[i].style.backgroundColor = '#f00';
|
||||
switch(i){
|
||||
|
||||
case 1:
|
||||
results = flexsearch.search(query);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
results = bulksearch.search(query);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
results = elasticsearch.search(query).map(function(val){return val.ref});
|
||||
break;
|
||||
|
||||
case 4:
|
||||
results = lunrsearch.search(query).map(function(val){return val.ref});
|
||||
break;
|
||||
|
||||
case 5:
|
||||
results = wadesearch(query).map(function(val){return val.index});
|
||||
break;
|
||||
|
||||
case 6:
|
||||
results = fuse.search(query);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
results = jssearch.search(query).map(function(val){return val.id});
|
||||
break;
|
||||
|
||||
case 8:
|
||||
results = jsii.search(query).docs.map(function(val){return val.id});
|
||||
break;
|
||||
|
||||
case 9:
|
||||
results = bm25.search(query).map(function(val){return val.id});
|
||||
break;
|
||||
}
|
||||
else if(nodes[i].innerHTML === ref){
|
||||
|
||||
if((results[0] === ref) || (results[0] === String(ref))){
|
||||
|
||||
nodes[i].style.backgroundColor = '#0a0';
|
||||
}
|
||||
else if(!results.length || ((results.indexOf(ref) === -1) && (results.indexOf(String(ref)) === -1))){
|
||||
|
||||
nodes[i].style.backgroundColor = '#f00';
|
||||
}
|
||||
else{
|
||||
|
||||
nodes[i].style.backgroundColor = 'orange';
|
||||
}
|
||||
|
||||
nodes[i].innerHTML = results[0] || '-';
|
||||
nodes[i].style.color = '#fff';
|
||||
}
|
||||
}
|
||||
|
||||
}, 50);
|
||||
}, 100);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
@@ -41,6 +41,7 @@ describe('Initialize', function(){
|
||||
|
||||
flexsearch_sync = new FlexSearch({
|
||||
|
||||
mode: 'forward',
|
||||
encode: false,
|
||||
async: false,
|
||||
worker: false
|
||||
@@ -48,6 +49,7 @@ describe('Initialize', function(){
|
||||
|
||||
flexsearch_async = FlexSearch.create({
|
||||
|
||||
mode: 'forward',
|
||||
encode: false,
|
||||
async: true,
|
||||
worker: false
|
||||
@@ -169,7 +171,7 @@ describe('Initialize', function(){
|
||||
it('Should have the correct options', function(){
|
||||
|
||||
expect(flexsearch_default.async).to.equal(false);
|
||||
expect(flexsearch_default.mode).to.equal("forward");
|
||||
expect(flexsearch_default.mode).to.equal("ngram");
|
||||
expect(flexsearch_sync.async).to.equal(false);
|
||||
expect(flexsearch_async.async).to.equal(true);
|
||||
expect(flexsearch_strict.mode).to.equal("strict");
|
||||
@@ -579,7 +581,7 @@ describe('Add (Worker)', function(){
|
||||
|
||||
encode: 'icase',
|
||||
mode: 'strict',
|
||||
async: true,
|
||||
async: false,
|
||||
worker: 4
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user