mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-25 04:51:29 +02:00
refactoring and cleanup
This commit is contained in:
742
dist/flexsearch.light.module.debug.js
vendored
742
dist/flexsearch.light.module.debug.js
vendored
@@ -5,319 +5,63 @@
|
||||
* Hosted by Nextapps GmbH
|
||||
* https://github.com/nextapps-de/flexsearch
|
||||
*/
|
||||
var t;
|
||||
function u(a, c, b) {
|
||||
const d = typeof b, e = typeof a;
|
||||
if ("undefined" !== d) {
|
||||
if ("undefined" !== e) {
|
||||
if (b) {
|
||||
if ("function" === e && d === e) {
|
||||
return function(h) {
|
||||
return a(b(h));
|
||||
};
|
||||
}
|
||||
c = a.constructor;
|
||||
if (c === b.constructor) {
|
||||
if (c === Array) {
|
||||
return b.concat(a);
|
||||
}
|
||||
if (c === Map) {
|
||||
var g = new Map(b);
|
||||
for (var f of a) {
|
||||
g.set(f[0], f[1]);
|
||||
}
|
||||
return g;
|
||||
}
|
||||
if (c === Set) {
|
||||
f = new Set(b);
|
||||
for (g of a.values()) {
|
||||
f.add(g);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
return "undefined" === e ? c : a;
|
||||
}
|
||||
function v() {
|
||||
function t() {
|
||||
return Object.create(null);
|
||||
}
|
||||
function w(a, c) {
|
||||
return c.length - a.length;
|
||||
function v(a, b) {
|
||||
return b.length - a.length;
|
||||
}
|
||||
;const y = /[^\p{L}\p{N}]+/u, z = /(\d{3})/g, A = /(\D)(\d{3})/g, B = /(\d{3})(\D)/g, C = "".normalize && /[\u0300-\u036f]/g;
|
||||
function D(a = {}) {
|
||||
if (!(this instanceof D)) {
|
||||
return new D(...arguments);
|
||||
}
|
||||
for (a = 0; a < arguments.length; a++) {
|
||||
this.assign(arguments[a]);
|
||||
}
|
||||
}
|
||||
D.prototype.assign = function(a) {
|
||||
this.normalize = u(a.normalize, !0, this.normalize);
|
||||
let c = a.N, b = c || a.O || a.split;
|
||||
if ("object" === typeof b) {
|
||||
let d = !c, e = "";
|
||||
a.N || (e += "\\p{Z}");
|
||||
b.P && (e += "\\p{L}");
|
||||
b.R && (e += "\\p{N}", d = !!c);
|
||||
b.T && (e += "\\p{S}");
|
||||
b.S && (e += "\\p{P}");
|
||||
b.control && (e += "\\p{C}");
|
||||
if (b = b.char) {
|
||||
e += "object" === typeof b ? b.join("") : b;
|
||||
}
|
||||
this.split = new RegExp("[" + (c ? "^" : "") + e + "]+", "u");
|
||||
this.numeric = d;
|
||||
} else {
|
||||
this.split = u(b, y, this.split), this.numeric = u(this.numeric, !0);
|
||||
}
|
||||
this.H = u(a.H, null, this.H);
|
||||
this.D = u(a.D, null, this.D);
|
||||
this.rtl = a.rtl || !1;
|
||||
this.l = u(a.l, !0, this.l);
|
||||
this.filter = u((b = a.filter) && new Set(b), null, this.filter);
|
||||
this.m = u((b = a.m) && new Map(b), null, this.m);
|
||||
this.v = u((b = a.v) && new Map(b), null, this.v);
|
||||
this.s = u((b = a.s) && new Map(b), null, this.s);
|
||||
this.o = u(a.o, null, this.o);
|
||||
this.G = u(a.G, 1, this.G);
|
||||
this.K = u(a.K, 0, this.K);
|
||||
if (this.cache = b = u(a.cache, !0, this.cache)) {
|
||||
this.C = null, this.L = "number" === typeof b ? b : 2e5, this.u = new Map(), this.A = new Map(), this.h = this.g = 128;
|
||||
}
|
||||
this.i = "";
|
||||
this.I = null;
|
||||
this.F = "";
|
||||
this.J = null;
|
||||
if (this.m) {
|
||||
for (const d of this.m.keys()) {
|
||||
this.i += (this.i ? "|" : "") + d;
|
||||
}
|
||||
}
|
||||
if (this.s) {
|
||||
for (const d of this.s.keys()) {
|
||||
this.F += (this.F ? "|" : "") + d;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
D.prototype.encode = function(a) {
|
||||
if (this.cache && a.length <= this.g) {
|
||||
if (this.C) {
|
||||
if (this.u.has(a)) {
|
||||
return this.u.get(a);
|
||||
}
|
||||
} else {
|
||||
this.C = setTimeout(E, 0, this);
|
||||
}
|
||||
}
|
||||
this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : C ? a.normalize("NFKD").replace(C, "").toLowerCase() : a.toLowerCase());
|
||||
this.H && (a = this.H(a));
|
||||
this.numeric && 3 < a.length && (a = a.replace(A, "$1 $2").replace(B, "$1 $2").replace(z, "$1 "));
|
||||
const c = !(this.l || this.v || this.filter || this.m || this.s || this.o);
|
||||
let b = [], d = this.split || "" === this.split ? a.split(this.split) : a;
|
||||
for (let g = 0, f, h; g < d.length; g++) {
|
||||
if (!(f = h = d[g])) {
|
||||
continue;
|
||||
}
|
||||
if (f.length < this.G) {
|
||||
continue;
|
||||
}
|
||||
if (c) {
|
||||
b.push(f);
|
||||
continue;
|
||||
}
|
||||
if (this.filter && this.filter.has(f)) {
|
||||
continue;
|
||||
}
|
||||
if (this.cache && f.length <= this.h) {
|
||||
if (this.C) {
|
||||
var e = this.A.get(f);
|
||||
if (e || "" === e) {
|
||||
e && b.push(e);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
this.C = setTimeout(E, 0, this);
|
||||
}
|
||||
}
|
||||
let l;
|
||||
this.s && 2 < f.length && (this.J || (this.J = new RegExp("(?!^)(" + this.F + ")$")), f = f.replace(this.J, r => this.s.get(r)), l = 1);
|
||||
this.m && 1 < f.length && (this.I || (this.I = new RegExp("(" + this.i + ")", "g")), f = f.replace(this.I, r => this.m.get(r)), l = 1);
|
||||
f && l && (f.length < this.G || this.filter && this.filter.has(f)) && (f = "");
|
||||
if (f && (this.v || this.l && 1 < f.length)) {
|
||||
e = "";
|
||||
for (let r = 0, k = "", p, q; r < f.length; r++) {
|
||||
p = f.charAt(r), p === k && this.l || ((q = this.v && this.v.get(p)) || "" === q ? q === k && this.l || !(k = q) || (e += q) : e += k = p);
|
||||
}
|
||||
f = e;
|
||||
}
|
||||
if (f && this.o) {
|
||||
for (e = 0; f && e < this.o.length; e += 2) {
|
||||
f = f.replace(this.o[e], this.o[e + 1]);
|
||||
}
|
||||
}
|
||||
this.cache && h.length <= this.h && (this.A.set(h, f), this.A.size > this.L && (this.A.clear(), this.h = this.h / 1.1 | 0));
|
||||
f && b.push(f);
|
||||
}
|
||||
this.D && (b = this.D(b) || b);
|
||||
this.cache && a.length <= this.g && (this.u.set(a, b), this.u.size > this.L && (this.u.clear(), this.g = this.g / 1.1 | 0));
|
||||
return b;
|
||||
};
|
||||
function E(a) {
|
||||
a.C = null;
|
||||
a.u.clear();
|
||||
a.A.clear();
|
||||
}
|
||||
;function F(a) {
|
||||
;function w(a) {
|
||||
this.limit = a && !0 !== a ? a : 1000;
|
||||
this.cache = new Map();
|
||||
this.g = "";
|
||||
this.C = "";
|
||||
}
|
||||
F.prototype.set = function(a, c) {
|
||||
this.cache.has(a) || (this.cache.set(this.g = a, c), this.limit && this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value));
|
||||
w.prototype.set = function(a, b) {
|
||||
this.cache.has(a) || (this.cache.set(this.C = a, b), this.limit && this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value));
|
||||
};
|
||||
F.prototype.get = function(a) {
|
||||
const c = this.cache.get(a);
|
||||
c && this.limit && this.g !== a && (this.cache.delete(a), this.cache.set(this.g = a, c));
|
||||
return c;
|
||||
};
|
||||
F.prototype.remove = function(a) {
|
||||
for (const c of this.cache) {
|
||||
const b = c[0];
|
||||
c[1].includes(a) && this.cache.delete(b);
|
||||
}
|
||||
};
|
||||
F.prototype.clear = function() {
|
||||
this.cache.clear();
|
||||
this.g = "";
|
||||
};
|
||||
function G(a = 8) {
|
||||
if (!(this instanceof G)) {
|
||||
return new G(a);
|
||||
}
|
||||
this.index = v();
|
||||
this.i = [];
|
||||
this.size = 0;
|
||||
32 < a ? (this.g = H, this.h = BigInt(a)) : (this.g = I, this.h = a);
|
||||
}
|
||||
G.prototype.get = function(a) {
|
||||
const c = this.index[this.g(a)];
|
||||
return c && c.get(a);
|
||||
};
|
||||
G.prototype.set = function(a, c) {
|
||||
var b = this.g(a);
|
||||
let d = this.index[b];
|
||||
d ? (b = d.size, d.set(a, c), (b -= d.size) && this.size++) : (this.index[b] = d = new Map([[a, c]]), this.i.push(d));
|
||||
};
|
||||
function J(a = 8) {
|
||||
if (!(this instanceof J)) {
|
||||
return new J(a);
|
||||
}
|
||||
this.index = v();
|
||||
this.g = [];
|
||||
32 < a ? (this.i = H, this.h = BigInt(a)) : (this.i = I, this.h = a);
|
||||
}
|
||||
J.prototype.add = function(a) {
|
||||
var c = this.i(a);
|
||||
let b = this.index[c];
|
||||
b ? (c = b.size, b.add(a), (c -= b.size) && this.size++) : (this.index[c] = b = new Set([a]), this.g.push(b));
|
||||
};
|
||||
t = G.prototype;
|
||||
t.has = J.prototype.has = function(a) {
|
||||
const c = this.index[this.i(a)];
|
||||
return c && c.has(a);
|
||||
};
|
||||
t.delete = J.prototype.delete = function(a) {
|
||||
const c = this.index[this.i(a)];
|
||||
c && c.delete(a) && this.size--;
|
||||
};
|
||||
t.clear = J.prototype.clear = function() {
|
||||
this.index = v();
|
||||
this.g = [];
|
||||
this.size = 0;
|
||||
};
|
||||
t.values = J.prototype.values = function*() {
|
||||
for (let a = 0; a < this.g.length; a++) {
|
||||
for (let c of this.g[a].values()) {
|
||||
yield c;
|
||||
}
|
||||
}
|
||||
};
|
||||
t.keys = J.prototype.keys = function*() {
|
||||
for (let a = 0; a < this.g.length; a++) {
|
||||
for (let c of this.g[a].keys()) {
|
||||
yield c;
|
||||
}
|
||||
}
|
||||
};
|
||||
t.entries = J.prototype.entries = function*() {
|
||||
for (let a = 0; a < this.g.length; a++) {
|
||||
for (let c of this.g[a].entries()) {
|
||||
yield c;
|
||||
}
|
||||
}
|
||||
};
|
||||
function I(a) {
|
||||
let c = 2 ** this.h - 1;
|
||||
if ("number" == typeof a) {
|
||||
return a & c;
|
||||
}
|
||||
let b = 0, d = this.h + 1;
|
||||
for (let e = 0; e < a.length; e++) {
|
||||
b = (b * d ^ a.charCodeAt(e)) & c;
|
||||
}
|
||||
return 32 === this.h ? b + 2 ** 31 : b;
|
||||
}
|
||||
function H(a) {
|
||||
let c = BigInt(2) ** this.h - BigInt(1);
|
||||
var b = typeof a;
|
||||
if ("bigint" === b) {
|
||||
return a & c;
|
||||
}
|
||||
if ("number" === b) {
|
||||
return BigInt(a) & c;
|
||||
}
|
||||
b = BigInt(0);
|
||||
let d = this.h + BigInt(1);
|
||||
for (let e = 0; e < a.length; e++) {
|
||||
b = (b * d ^ BigInt(a.charCodeAt(e))) & c;
|
||||
}
|
||||
w.prototype.get = function(a) {
|
||||
const b = this.cache.get(a);
|
||||
b && this.limit && this.C !== a && (this.cache.delete(a), this.cache.set(this.C = a, b));
|
||||
return b;
|
||||
};
|
||||
w.prototype.remove = function(a) {
|
||||
for (const b of this.cache) {
|
||||
const c = b[0];
|
||||
b[1].includes(a) && this.cache.delete(c);
|
||||
}
|
||||
};
|
||||
w.prototype.clear = function() {
|
||||
this.cache.clear();
|
||||
this.C = "";
|
||||
};
|
||||
const x = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}};
|
||||
function y(a) {
|
||||
const b = "string" === typeof a ? a : a.preset;
|
||||
b && (x[b] || console.warn("Preset not found: " + b), a = Object.assign({}, x[b], a));
|
||||
return a;
|
||||
}
|
||||
;const K = v(), L = v();
|
||||
var M = {normalize:function(a) {
|
||||
return a.toLowerCase();
|
||||
}, l:!1};
|
||||
const N = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}};
|
||||
v();
|
||||
P.prototype.add = function(a, c, b, d) {
|
||||
if (c && (a || 0 === a)) {
|
||||
if (!d && !b && this.j.has(a)) {
|
||||
return this.update(a, c);
|
||||
;t();
|
||||
z.prototype.add = function(a, b, c, d) {
|
||||
if (b && (a || 0 === a)) {
|
||||
if (!d && !c && this.h.has(a)) {
|
||||
return this.update(a, b);
|
||||
}
|
||||
c = this.encoder.encode(c);
|
||||
if (d = c.length) {
|
||||
const r = v(), k = v(), p = this.depth, q = this.resolution;
|
||||
for (let m = 0; m < d; m++) {
|
||||
let n = c[this.rtl ? d - 1 - m : m];
|
||||
b = this.encoder.encode(b);
|
||||
if (d = b.length) {
|
||||
const r = t(), k = t(), p = this.depth, q = this.resolution;
|
||||
for (let l = 0; l < d; l++) {
|
||||
let n = b[this.rtl ? d - 1 - l : l];
|
||||
var e = n.length;
|
||||
if (e && (p || !k[n])) {
|
||||
var g = this.score ? this.score(c, n, m, null, 0) : Q(q, d, m), f = "";
|
||||
var f = this.score ? this.score(b, n, l, null, 0) : A(q, d, l), g = "";
|
||||
switch(this.tokenize) {
|
||||
case "full":
|
||||
if (2 < e) {
|
||||
for (g = 0; g < e; g++) {
|
||||
for (var h = e; h > g; h--) {
|
||||
f = n.substring(g, h);
|
||||
var l = this.score ? this.score(c, n, m, f, g) : Q(q, d, m, e, g);
|
||||
R(this, k, f, l, a, b);
|
||||
for (f = 0; f < e; f++) {
|
||||
for (var h = e; h > f; h--) {
|
||||
g = n.substring(f, h);
|
||||
var m = this.score ? this.score(b, n, l, g, f) : A(q, d, l, e, f);
|
||||
B(this, k, g, m, a, c);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -325,108 +69,108 @@ P.prototype.add = function(a, c, b, d) {
|
||||
case "reverse":
|
||||
if (1 < e) {
|
||||
for (h = e - 1; 0 < h; h--) {
|
||||
f = n[h] + f, l = this.score ? this.score(c, n, m, f, h) : Q(q, d, m, e, h), R(this, k, f, l, a, b);
|
||||
g = n[h] + g, m = this.score ? this.score(b, n, l, g, h) : A(q, d, l, e, h), B(this, k, g, m, a, c);
|
||||
}
|
||||
f = "";
|
||||
g = "";
|
||||
}
|
||||
case "forward":
|
||||
if (1 < e) {
|
||||
for (h = 0; h < e; h++) {
|
||||
f += n[h], R(this, k, f, g, a, b);
|
||||
g += n[h], B(this, k, g, f, a, c);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (R(this, k, n, g, a, b), p && 1 < d && m < d - 1) {
|
||||
for (e = v(), f = this.M, g = n, h = Math.min(p + 1, d - m), e[g] = 1, l = 1; l < h; l++) {
|
||||
if ((n = c[this.rtl ? d - 1 - m - l : m + l]) && !e[n]) {
|
||||
if (B(this, k, n, f, a, c), p && 1 < d && l < d - 1) {
|
||||
for (e = t(), g = this.F, f = n, h = Math.min(p + 1, d - l), e[f] = 1, m = 1; m < h; m++) {
|
||||
if ((n = b[this.rtl ? d - 1 - l - m : l + m]) && !e[n]) {
|
||||
e[n] = 1;
|
||||
const x = this.score ? this.score(c, g, m, n, l) : Q(f + (d / 2 > f ? 0 : 1), d, m, h - 1, l - 1), O = this.bidirectional && n > g;
|
||||
R(this, r, O ? g : n, x, a, b, O ? n : g);
|
||||
const u = this.score ? this.score(b, f, l, n, m) : A(g + (d / 2 > g ? 0 : 1), d, l, h - 1, m - 1), H = this.bidirectional && n > f;
|
||||
B(this, r, H ? f : n, u, a, c, H ? n : f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.fastupdate || this.j.add(a);
|
||||
this.fastupdate || this.h.add(a);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
function R(a, c, b, d, e, g, f) {
|
||||
let h = f ? a.B : a.map, l;
|
||||
c[b] && f && (l = c[b])[f] || (f ? (c = l || (c[b] = v()), c[f] = 1, (l = h.get(f)) ? h = l : h.set(f, h = new Map())) : c[b] = 1, (l = h.get(b)) ? h = l : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.j.get(e)) ? c.push(h) : a.j.set(e, [h]))));
|
||||
function B(a, b, c, d, e, f, g) {
|
||||
let h = g ? a.B : a.map, m;
|
||||
b[c] && g && (m = b[c])[g] || (g ? (b = m || (b[c] = t()), b[g] = 1, (m = h.get(g)) ? h = m : h.set(g, h = new Map())) : b[c] = 1, (m = h.get(c)) ? h = m : h.set(c, h = []), h = h[d] || (h[d] = []), f && h.includes(e) || (h.push(e), a.fastupdate && ((b = a.h.get(e)) ? b.push(h) : a.h.set(e, [h]))));
|
||||
}
|
||||
function Q(a, c, b, d, e) {
|
||||
return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0;
|
||||
function A(a, b, c, d, e) {
|
||||
return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0;
|
||||
}
|
||||
;function S(a, c, b) {
|
||||
;function C(a, b, c) {
|
||||
if (1 === a.length) {
|
||||
return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a;
|
||||
return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a;
|
||||
}
|
||||
let d = [];
|
||||
for (let e = 0, g, f; e < a.length; e++) {
|
||||
if ((g = a[e]) && (f = g.length)) {
|
||||
if (b) {
|
||||
if (b >= f) {
|
||||
b -= f;
|
||||
for (let e = 0, f, g; e < a.length; e++) {
|
||||
if ((f = a[e]) && (g = f.length)) {
|
||||
if (c) {
|
||||
if (c >= g) {
|
||||
c -= g;
|
||||
continue;
|
||||
}
|
||||
b < f && (g = c ? g.slice(b, b + c) : g.slice(b), f = g.length, b = 0);
|
||||
c < g && (f = b ? f.slice(c, c + b) : f.slice(c), g = f.length, c = 0);
|
||||
}
|
||||
if (d.length) {
|
||||
f > c && (g = g.slice(0, c), f = g.length), d.push(g);
|
||||
g > b && (f = f.slice(0, b), g = f.length), d.push(f);
|
||||
} else {
|
||||
if (f >= c) {
|
||||
return f > c && (g = g.slice(0, c)), g;
|
||||
if (g >= b) {
|
||||
return g > b && (f = f.slice(0, b)), f;
|
||||
}
|
||||
d = [g];
|
||||
d = [f];
|
||||
}
|
||||
c -= f;
|
||||
if (!c) {
|
||||
b -= g;
|
||||
if (!b) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return d.length ? d = 1 < d.length ? [].concat.apply([], d) : d[0] : d;
|
||||
}
|
||||
;function T(a, c, b, d) {
|
||||
;function D(a, b, c, d) {
|
||||
var e = a.length;
|
||||
let g = [], f = 0, h, l, r;
|
||||
let f = [], g = 0, h, m, r;
|
||||
d && (d = []);
|
||||
for (let k = e - 1, p; 0 <= k; k--) {
|
||||
r = a[k];
|
||||
e = v();
|
||||
e = t();
|
||||
p = !h;
|
||||
for (let q = 0, m; q < r.length; q++) {
|
||||
if ((m = r[q]) && m.length) {
|
||||
for (let n = 0, x; n < m.length; n++) {
|
||||
if (x = m[n], h) {
|
||||
if (h[x]) {
|
||||
for (let q = 0, l; q < r.length; q++) {
|
||||
if ((l = r[q]) && l.length) {
|
||||
for (let n = 0, u; n < l.length; n++) {
|
||||
if (u = l[n], h) {
|
||||
if (h[u]) {
|
||||
if (!k) {
|
||||
if (b) {
|
||||
b--;
|
||||
if (c) {
|
||||
c--;
|
||||
} else {
|
||||
if (g[f++] = x, f === c) {
|
||||
return g;
|
||||
if (f[g++] = u, g === b) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (k || d) {
|
||||
e[x] = 1;
|
||||
e[u] = 1;
|
||||
}
|
||||
p = !0;
|
||||
}
|
||||
d && !l[x] && (l[x] = 1, (d[q] || (d[q] = [])).push(x));
|
||||
d && !m[u] && (m[u] = 1, (d[q] || (d[q] = [])).push(u));
|
||||
} else {
|
||||
e[x] = 1;
|
||||
e[u] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (d) {
|
||||
h || (l = e);
|
||||
h || (m = e);
|
||||
} else if (!p) {
|
||||
return [];
|
||||
}
|
||||
@@ -436,13 +180,13 @@ function Q(a, c, b, d, e) {
|
||||
for (let k = d.length - 1, p, q; 0 <= k; k--) {
|
||||
p = d[k];
|
||||
q = p.length;
|
||||
for (let m = 0, n; m < q; m++) {
|
||||
if (n = p[m], !h[n]) {
|
||||
if (b) {
|
||||
b--;
|
||||
for (let l = 0, n; l < q; l++) {
|
||||
if (n = p[l], !h[n]) {
|
||||
if (c) {
|
||||
c--;
|
||||
} else {
|
||||
if (g[f++] = n, f === c) {
|
||||
return g;
|
||||
if (f[g++] = n, g === b) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
h[n] = 1;
|
||||
@@ -450,69 +194,69 @@ function Q(a, c, b, d, e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return g;
|
||||
return f;
|
||||
}
|
||||
;P.prototype.search = function(a, c, b) {
|
||||
b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = ""));
|
||||
;z.prototype.search = function(a, b, c) {
|
||||
c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = ""));
|
||||
let d = [];
|
||||
let e, g = 0;
|
||||
if (b) {
|
||||
a = b.query || a;
|
||||
c = b.limit || c;
|
||||
g = b.offset || 0;
|
||||
var f = b.context;
|
||||
let e, f = 0;
|
||||
if (c) {
|
||||
a = c.query || a;
|
||||
b = c.limit || b;
|
||||
f = c.offset || 0;
|
||||
var g = c.context;
|
||||
e = !1;
|
||||
}
|
||||
a = this.encoder.encode(a);
|
||||
b = a.length;
|
||||
c || (c = 100);
|
||||
if (1 === b) {
|
||||
return U.call(this, a[0], "", c, g);
|
||||
c = a.length;
|
||||
b || (b = 100);
|
||||
if (1 === c) {
|
||||
return E.call(this, a[0], "", b, f);
|
||||
}
|
||||
f = this.depth && !1 !== f;
|
||||
if (2 === b && f && !e) {
|
||||
return U.call(this, a[0], a[1], c, g);
|
||||
g = this.depth && !1 !== g;
|
||||
if (2 === c && g && !e) {
|
||||
return E.call(this, a[0], a[1], b, f);
|
||||
}
|
||||
let h = 0, l = 0;
|
||||
if (1 < b) {
|
||||
var r = v();
|
||||
let h = 0, m = 0;
|
||||
if (1 < c) {
|
||||
var r = t();
|
||||
const p = [];
|
||||
for (let q = 0, m; q < b; q++) {
|
||||
if ((m = a[q]) && !r[m]) {
|
||||
if (e || V(this, m)) {
|
||||
p.push(m), r[m] = 1;
|
||||
for (let q = 0, l; q < c; q++) {
|
||||
if ((l = a[q]) && !r[l]) {
|
||||
if (e || F(this, l)) {
|
||||
p.push(l), r[l] = 1;
|
||||
} else {
|
||||
return d;
|
||||
}
|
||||
const n = m.length;
|
||||
const n = l.length;
|
||||
h = Math.max(h, n);
|
||||
l = l ? Math.min(l, n) : n;
|
||||
m = m ? Math.min(m, n) : n;
|
||||
}
|
||||
}
|
||||
a = p;
|
||||
b = a.length;
|
||||
c = a.length;
|
||||
}
|
||||
if (!b) {
|
||||
if (!c) {
|
||||
return d;
|
||||
}
|
||||
r = 0;
|
||||
let k;
|
||||
if (1 === b) {
|
||||
return U.call(this, a[0], "", c, g);
|
||||
if (1 === c) {
|
||||
return E.call(this, a[0], "", b, f);
|
||||
}
|
||||
if (2 === b && f && !e) {
|
||||
return U.call(this, a[0], a[1], c, g);
|
||||
if (2 === c && g && !e) {
|
||||
return E.call(this, a[0], a[1], b, f);
|
||||
}
|
||||
1 < b && (f ? (k = a[0], r = 1) : 9 < h && 3 < h / l && a.sort(w));
|
||||
for (let p, q; r < b; r++) {
|
||||
1 < c && (g ? (k = a[0], r = 1) : 9 < h && 3 < h / m && a.sort(v));
|
||||
for (let p, q; r < c; r++) {
|
||||
q = a[r];
|
||||
k ? (p = V(this, q, k), p = W(p, d, e, this.M, c, g, 2 === b), e && !1 === p && d.length || (k = q)) : (p = V(this, q), p = W(p, d, e, this.resolution, c, g, 1 === b));
|
||||
k ? (p = F(this, q, k), p = G(p, d, e, this.F, b, f, 2 === c), e && !1 === p && d.length || (k = q)) : (p = F(this, q), p = G(p, d, e, this.resolution, b, f, 1 === c));
|
||||
if (p) {
|
||||
return p;
|
||||
}
|
||||
if (e && r === b - 1) {
|
||||
f = d.length;
|
||||
if (!f) {
|
||||
if (e && r === c - 1) {
|
||||
g = d.length;
|
||||
if (!g) {
|
||||
if (k) {
|
||||
k = "";
|
||||
r = -1;
|
||||
@@ -520,171 +264,191 @@ function Q(a, c, b, d, e) {
|
||||
}
|
||||
return d;
|
||||
}
|
||||
if (1 === f) {
|
||||
return S(d[0], c, g);
|
||||
if (1 === g) {
|
||||
return C(d[0], b, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
return T(d, c, g, e);
|
||||
return D(d, b, f, e);
|
||||
};
|
||||
function U(a, c, b, d) {
|
||||
return (a = V(this, a, c)) && a.length ? S(a, b, d) : [];
|
||||
function E(a, b, c, d) {
|
||||
return (a = F(this, a, b)) && a.length ? C(a, c, d) : [];
|
||||
}
|
||||
function W(a, c, b, d, e, g, f) {
|
||||
function G(a, b, c, d, e, f, g) {
|
||||
let h = [];
|
||||
if (a) {
|
||||
d = Math.min(a.length, d);
|
||||
for (let l = 0, r = 0, k; l < d; l++) {
|
||||
if (k = a[l]) {
|
||||
if (g && k && f && (k.length <= g ? (g -= k.length, k = null) : (k = k.slice(g), g = 0)), k && (h[l] = k, f && (r += k.length, r >= e))) {
|
||||
for (let m = 0, r = 0, k; m < d; m++) {
|
||||
if (k = a[m]) {
|
||||
if (f && k && g && (k.length <= f ? (f -= k.length, k = null) : (k = k.slice(f), f = 0)), k && (h[m] = k, g && (r += k.length, r >= e))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (h.length) {
|
||||
if (f) {
|
||||
return S(h, e, 0);
|
||||
if (g) {
|
||||
return C(h, e, 0);
|
||||
}
|
||||
c.push(h);
|
||||
b.push(h);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return !b && h;
|
||||
return !c && h;
|
||||
}
|
||||
function V(a, c, b) {
|
||||
function F(a, b, c) {
|
||||
let d;
|
||||
b && (d = a.bidirectional && c > b);
|
||||
a = b ? (a = a.B.get(d ? c : b)) && a.get(d ? b : c) : a.map.get(c);
|
||||
c && (d = a.bidirectional && b > c);
|
||||
a = c ? (a = a.B.get(d ? b : c)) && a.get(d ? c : b) : a.map.get(b);
|
||||
return a;
|
||||
}
|
||||
;P.prototype.remove = function(a, c) {
|
||||
const b = this.j.size && (this.fastupdate ? this.j.get(a) : this.j.has(a));
|
||||
if (b) {
|
||||
;z.prototype.remove = function(a, b) {
|
||||
const c = this.h.size && (this.fastupdate ? this.h.get(a) : this.h.has(a));
|
||||
if (c) {
|
||||
if (this.fastupdate) {
|
||||
for (let d = 0, e; d < b.length; d++) {
|
||||
if (e = b[d]) {
|
||||
for (let d = 0, e; d < c.length; d++) {
|
||||
if (e = c[d]) {
|
||||
if (2 > e.length) {
|
||||
e.pop();
|
||||
} else {
|
||||
const g = e.indexOf(a);
|
||||
g === b.length - 1 ? e.pop() : e.splice(g, 1);
|
||||
const f = e.indexOf(a);
|
||||
f === c.length - 1 ? e.pop() : e.splice(f, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
X(this.map, a), this.depth && X(this.B, a);
|
||||
I(this.map, a), this.depth && I(this.B, a);
|
||||
}
|
||||
c || this.j.delete(a);
|
||||
b || this.h.delete(a);
|
||||
}
|
||||
this.cache && this.cache.remove(a);
|
||||
return this;
|
||||
};
|
||||
function X(a, c) {
|
||||
let b = 0;
|
||||
function I(a, b) {
|
||||
let c = 0;
|
||||
if (a.constructor === Array) {
|
||||
for (let d = 0, e, g; d < a.length; d++) {
|
||||
for (let d = 0, e, f; d < a.length; d++) {
|
||||
if ((e = a[d]) && e.length) {
|
||||
if (g = e.indexOf(c), 0 <= g) {
|
||||
1 < e.length ? (e.splice(g, 1), b++) : delete a[d];
|
||||
if (f = e.indexOf(b), 0 <= f) {
|
||||
1 < e.length ? (e.splice(f, 1), c++) : delete a[d];
|
||||
break;
|
||||
} else {
|
||||
b++;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let d of a) {
|
||||
const e = d[0], g = X(d[1], c);
|
||||
g ? b += g : a.delete(e);
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
;function P(a, c) {
|
||||
if (!(this instanceof P)) {
|
||||
return new P(a);
|
||||
}
|
||||
if (a) {
|
||||
var b = "string" === typeof a ? a : a.preset;
|
||||
b && (N[b] || console.warn("Preset not found: " + b), a = Object.assign({}, N[b], a));
|
||||
} else {
|
||||
a = {};
|
||||
}
|
||||
b = a.context || {};
|
||||
const d = a.encode || a.encoder || M;
|
||||
this.encoder = d.encode ? d : "object" === typeof d ? new D(d) : {encode:d};
|
||||
let e;
|
||||
this.resolution = a.resolution || 9;
|
||||
this.tokenize = e = a.tokenize || "strict";
|
||||
this.depth = "strict" === e && b.depth || 0;
|
||||
this.bidirectional = !1 !== b.bidirectional;
|
||||
this.fastupdate = !!a.fastupdate;
|
||||
this.score = a.score || null;
|
||||
this.map = (e = !1, new Map());
|
||||
this.B = e ? new G(e) : new Map();
|
||||
this.j = c || (this.fastupdate ? e ? new G(e) : new Map() : e ? new J(e) : new Set());
|
||||
this.M = b.resolution || 1;
|
||||
this.rtl = d.rtl || a.rtl || !1;
|
||||
this.cache = (e = a.cache || null) && new F(e);
|
||||
}
|
||||
t = P.prototype;
|
||||
t.clear = function() {
|
||||
this.map.clear();
|
||||
this.B.clear();
|
||||
this.j.clear();
|
||||
this.cache && this.cache.clear();
|
||||
return this;
|
||||
};
|
||||
t.append = function(a, c) {
|
||||
return this.add(a, c, !0);
|
||||
};
|
||||
t.contain = function(a) {
|
||||
return this.j.has(a);
|
||||
};
|
||||
t.update = function(a, c) {
|
||||
if (this.async) {
|
||||
const b = this, d = this.remove(a);
|
||||
return d.then ? d.then(() => b.add(a, c)) : this.add(a, c);
|
||||
}
|
||||
return this.remove(a).add(a, c);
|
||||
};
|
||||
function Y(a) {
|
||||
let c = 0;
|
||||
if (a.constructor === Array) {
|
||||
for (let b = 0, d; b < a.length; b++) {
|
||||
(d = a[b]) && (c += d.length);
|
||||
}
|
||||
} else {
|
||||
for (const b of a) {
|
||||
const d = b[0], e = Y(b[1]);
|
||||
e ? c += e : a.delete(d);
|
||||
const e = d[0], f = I(d[1], b);
|
||||
f ? c += f : a.delete(e);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
t.cleanup = function() {
|
||||
;function z(a, b) {
|
||||
if (!(this instanceof z)) {
|
||||
return new z(a);
|
||||
}
|
||||
a = a ? y(a) : {};
|
||||
const c = a.context || {}, d = a.encode || a.encoder || function(f) {
|
||||
return f.toLowerCase().trim().split(/\s+/);
|
||||
};
|
||||
this.encoder = d.encode ? d : "object" === typeof d ? d : {encode:d};
|
||||
let e;
|
||||
this.resolution = a.resolution || 9;
|
||||
this.tokenize = e = a.tokenize || "strict";
|
||||
this.depth = "strict" === e && c.depth || 0;
|
||||
this.bidirectional = !1 !== c.bidirectional;
|
||||
this.fastupdate = !!a.fastupdate;
|
||||
this.score = a.score || null;
|
||||
e = !1;
|
||||
this.map = new Map();
|
||||
this.B = new Map();
|
||||
this.h = b || (this.fastupdate ? new Map() : new Set());
|
||||
this.F = c.resolution || 1;
|
||||
this.rtl = d.rtl || a.rtl || !1;
|
||||
this.cache = (e = a.cache || null) && new w(e);
|
||||
}
|
||||
z.prototype.clear = function() {
|
||||
this.map.clear();
|
||||
this.B.clear();
|
||||
this.h.clear();
|
||||
this.cache && this.cache.clear();
|
||||
return this;
|
||||
};
|
||||
z.prototype.append = function(a, b) {
|
||||
return this.add(a, b, !0);
|
||||
};
|
||||
z.prototype.contain = function(a) {
|
||||
return this.h.has(a);
|
||||
};
|
||||
z.prototype.update = function(a, b) {
|
||||
if (this.async) {
|
||||
const c = this, d = this.remove(a);
|
||||
return d.then ? d.then(() => c.add(a, b)) : this.add(a, b);
|
||||
}
|
||||
return this.remove(a).add(a, b);
|
||||
};
|
||||
function J(a) {
|
||||
let b = 0;
|
||||
if (a.constructor === Array) {
|
||||
for (let c = 0, d; c < a.length; c++) {
|
||||
(d = a[c]) && (b += d.length);
|
||||
}
|
||||
} else {
|
||||
for (const c of a) {
|
||||
const d = c[0], e = J(c[1]);
|
||||
e ? b += e : a.delete(d);
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
z.prototype.cleanup = function() {
|
||||
if (!this.fastupdate) {
|
||||
return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this;
|
||||
}
|
||||
Y(this.map);
|
||||
this.depth && Y(this.B);
|
||||
J(this.map);
|
||||
this.depth && J(this.B);
|
||||
return this;
|
||||
};
|
||||
t.searchCache = function(a, c, b) {
|
||||
z.prototype.searchCache = function(a, b, c) {
|
||||
a = ("object" === typeof a ? "" + a.query : a).toLowerCase();
|
||||
let d = this.cache.get(a);
|
||||
if (!d) {
|
||||
d = this.search(a, c, b);
|
||||
d = this.search(a, b, c);
|
||||
if (d instanceof Promise) {
|
||||
const e = this;
|
||||
d.then(function(g) {
|
||||
e.cache.set(a, g);
|
||||
d.then(function(f) {
|
||||
e.cache.set(a, f);
|
||||
});
|
||||
}
|
||||
this.cache.set(a, d);
|
||||
}
|
||||
return d;
|
||||
};
|
||||
export default {Index:P, Encoder:D, Charset:L, Language:K, Document:null, Worker:null, Resolver:null, IndexedDB:null};
|
||||
const K = t();
|
||||
const L = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]);
|
||||
var M = {normalize:!0, A:!0, D:L};
|
||||
const N = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), O = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"];
|
||||
var P = {normalize:!0, A:!0, D:L, H:O, G:N};
|
||||
var Q = {normalize:!0, A:!0, D:L, H:O.concat([/(?!^)[aeoy]/g, ""]), G:N};
|
||||
const R = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6};
|
||||
K["latin:exact"] = {normalize:!1, A:!1};
|
||||
K["latin:default"] = {normalize:function(a) {
|
||||
return a.toLowerCase();
|
||||
}, A:!1};
|
||||
K["latin:simple"] = {normalize:!0, A:!0};
|
||||
K["latin:balance"] = M;
|
||||
K["latin:advanced"] = P;
|
||||
K["latin:extra"] = Q;
|
||||
K["latin:soundex"] = {normalize:!0, A:!1, J:{K:!0}, I:function(a) {
|
||||
for (let c = 0; c < a.length; c++) {
|
||||
var b = a[c];
|
||||
let d = b.charAt(0), e = R[d];
|
||||
for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = R[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) {
|
||||
}
|
||||
a[c] = d;
|
||||
}
|
||||
}};
|
||||
export default {Index:z, Charset:K, Encoder:null, Document:null, Worker:null, Resolver:null, IndexedDB:null};
|
||||
|
||||
export const Index=P;export const Encoder=D;export const Charset=L;export const Language=K;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;
|
||||
export const Index=z;export const Charset=K;export const Encoder=null;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;
|
Reference in New Issue
Block a user