mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-03 10:53:41 +02:00
2914 lines
83 KiB
JavaScript
2914 lines
83 KiB
JavaScript
/**!
|
|
* FlexSearch.js v0.8.206 (Bundle/Module/Debug)
|
|
* Author and Copyright: Thomas Wilkerling
|
|
* Licence: Apache-2.0
|
|
* Hosted by Nextapps GmbH
|
|
* https://github.com/nextapps-de/flexsearch
|
|
*/
|
|
var w;
|
|
function H(a, c, b) {
|
|
const e = typeof b, d = typeof a;
|
|
if (e !== "undefined") {
|
|
if (d !== "undefined") {
|
|
if (b) {
|
|
if (d === "function" && e === d) {
|
|
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 f = new Map(b);
|
|
for (var g of a) {
|
|
f.set(g[0], g[1]);
|
|
}
|
|
return f;
|
|
}
|
|
if (c === Set) {
|
|
g = new Set(b);
|
|
for (f of a.values()) {
|
|
g.add(f);
|
|
}
|
|
return g;
|
|
}
|
|
}
|
|
}
|
|
return a;
|
|
}
|
|
return b;
|
|
}
|
|
return d === "undefined" ? c : a;
|
|
}
|
|
function aa(a, c) {
|
|
return typeof a === "undefined" ? c : a;
|
|
}
|
|
function I() {
|
|
return Object.create(null);
|
|
}
|
|
function N(a) {
|
|
return typeof a === "string";
|
|
}
|
|
function ba(a) {
|
|
return typeof a === "object";
|
|
}
|
|
function ca(a, c) {
|
|
if (N(c)) {
|
|
a = a[c];
|
|
} else {
|
|
for (let b = 0; a && b < c.length; b++) {
|
|
a = a[c[b]];
|
|
}
|
|
}
|
|
return a;
|
|
}
|
|
;const da = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = /[\u0300-\u036f]/g;
|
|
function ka(a = {}) {
|
|
if (!this || this.constructor !== ka) {
|
|
return new ka(...arguments);
|
|
}
|
|
if (arguments.length) {
|
|
for (a = 0; a < arguments.length; a++) {
|
|
this.assign(arguments[a]);
|
|
}
|
|
} else {
|
|
this.assign(a);
|
|
}
|
|
}
|
|
w = ka.prototype;
|
|
w.assign = function(a) {
|
|
this.normalize = H(a.normalize, !0, this.normalize);
|
|
let c = a.include, b = c || a.exclude || a.split, e;
|
|
if (b || b === "") {
|
|
if (typeof b === "object" && b.constructor !== RegExp) {
|
|
let d = "";
|
|
e = !c;
|
|
c || (d += "\\p{Z}");
|
|
b.letter && (d += "\\p{L}");
|
|
b.number && (d += "\\p{N}", e = !!c);
|
|
b.symbol && (d += "\\p{S}");
|
|
b.punctuation && (d += "\\p{P}");
|
|
b.control && (d += "\\p{C}");
|
|
if (b = b.char) {
|
|
d += typeof b === "object" ? b.join("") : b;
|
|
}
|
|
try {
|
|
this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u");
|
|
} catch (f) {
|
|
console.error("Your split configuration:", b, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/;
|
|
}
|
|
} else {
|
|
this.split = b, e = b === !1 || "a1a".split(b).length < 2;
|
|
}
|
|
this.numeric = H(a.numeric, e);
|
|
} else {
|
|
try {
|
|
this.split = H(this.split, da);
|
|
} catch (d) {
|
|
console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/;
|
|
}
|
|
this.numeric = H(a.numeric, H(this.numeric, !0));
|
|
}
|
|
this.prepare = H(a.prepare, null, this.prepare);
|
|
this.finalize = H(a.finalize, null, this.finalize);
|
|
b = a.filter;
|
|
this.filter = typeof b === "function" ? b : H(b && new Set(b), null, this.filter);
|
|
this.dedupe = H(a.dedupe, !0, this.dedupe);
|
|
this.matcher = H((b = a.matcher) && new Map(b), null, this.matcher);
|
|
this.mapper = H((b = a.mapper) && new Map(b), null, this.mapper);
|
|
this.stemmer = H((b = a.stemmer) && new Map(b), null, this.stemmer);
|
|
this.replacer = H(a.replacer, null, this.replacer);
|
|
this.minlength = H(a.minlength, 1, this.minlength);
|
|
this.maxlength = H(a.maxlength, 1024, this.maxlength);
|
|
this.rtl = H(a.rtl, !1, this.rtl);
|
|
if (this.cache = b = H(a.cache, !0, this.cache)) {
|
|
this.F = null, this.L = typeof b === "number" ? b : 2e5, this.B = new Map(), this.D = new Map(), this.I = this.H = 128;
|
|
}
|
|
this.h = "";
|
|
this.J = null;
|
|
this.A = "";
|
|
this.K = null;
|
|
if (this.matcher) {
|
|
for (const d of this.matcher.keys()) {
|
|
this.h += (this.h ? "|" : "") + d;
|
|
}
|
|
}
|
|
if (this.stemmer) {
|
|
for (const d of this.stemmer.keys()) {
|
|
this.A += (this.A ? "|" : "") + d;
|
|
}
|
|
}
|
|
return this;
|
|
};
|
|
w.addStemmer = function(a, c) {
|
|
this.stemmer || (this.stemmer = new Map());
|
|
this.stemmer.set(a, c);
|
|
this.A += (this.A ? "|" : "") + a;
|
|
this.K = null;
|
|
this.cache && la(this);
|
|
return this;
|
|
};
|
|
w.addFilter = function(a) {
|
|
typeof a === "function" ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a));
|
|
this.cache && la(this);
|
|
return this;
|
|
};
|
|
w.addMapper = function(a, c) {
|
|
if (typeof a === "object") {
|
|
return this.addReplacer(a, c);
|
|
}
|
|
if (a.length > 1) {
|
|
return this.addMatcher(a, c);
|
|
}
|
|
this.mapper || (this.mapper = new Map());
|
|
this.mapper.set(a, c);
|
|
this.cache && la(this);
|
|
return this;
|
|
};
|
|
w.addMatcher = function(a, c) {
|
|
if (typeof a === "object") {
|
|
return this.addReplacer(a, c);
|
|
}
|
|
if (a.length < 2 && (this.dedupe || this.mapper)) {
|
|
return this.addMapper(a, c);
|
|
}
|
|
this.matcher || (this.matcher = new Map());
|
|
this.matcher.set(a, c);
|
|
this.h += (this.h ? "|" : "") + a;
|
|
this.J = null;
|
|
this.cache && la(this);
|
|
return this;
|
|
};
|
|
w.addReplacer = function(a, c) {
|
|
if (typeof a === "string") {
|
|
return this.addMatcher(a, c);
|
|
}
|
|
this.replacer || (this.replacer = []);
|
|
this.replacer.push(a, c);
|
|
this.cache && la(this);
|
|
return this;
|
|
};
|
|
w.encode = function(a, c) {
|
|
if (this.cache && a.length <= this.H) {
|
|
if (this.F) {
|
|
if (this.B.has(a)) {
|
|
return this.B.get(a);
|
|
}
|
|
} else {
|
|
this.F = setTimeout(la, 50, this);
|
|
}
|
|
}
|
|
this.normalize && (typeof this.normalize === "function" ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase());
|
|
this.prepare && (a = this.prepare(a));
|
|
this.numeric && a.length > 3 && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 "));
|
|
const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer);
|
|
let e = [], d = I(), f, g, h = this.split || this.split === "" ? a.split(this.split) : [a];
|
|
for (let l = 0, m, p; l < h.length; l++) {
|
|
if ((m = p = h[l]) && !(m.length < this.minlength || m.length > this.maxlength)) {
|
|
if (c) {
|
|
if (d[m]) {
|
|
continue;
|
|
}
|
|
d[m] = 1;
|
|
} else {
|
|
if (f === m) {
|
|
continue;
|
|
}
|
|
f = m;
|
|
}
|
|
if (b) {
|
|
e.push(m);
|
|
} else {
|
|
if (!this.filter || (typeof this.filter === "function" ? this.filter(m) : !this.filter.has(m))) {
|
|
if (this.cache && m.length <= this.I) {
|
|
if (this.F) {
|
|
var k = this.D.get(m);
|
|
if (k || k === "") {
|
|
k && e.push(k);
|
|
continue;
|
|
}
|
|
} else {
|
|
this.F = setTimeout(la, 50, this);
|
|
}
|
|
}
|
|
if (this.stemmer) {
|
|
this.K || (this.K = new RegExp("(?!^)(" + this.A + ")$"));
|
|
let u;
|
|
for (; u !== m && m.length > 2;) {
|
|
u = m, m = m.replace(this.K, r => this.stemmer.get(r));
|
|
}
|
|
}
|
|
if (m && (this.mapper || this.dedupe && m.length > 1)) {
|
|
k = "";
|
|
for (let u = 0, r = "", t, n; u < m.length; u++) {
|
|
t = m.charAt(u), t === r && this.dedupe || ((n = this.mapper && this.mapper.get(t)) || n === "" ? n === r && this.dedupe || !(r = n) || (k += n) : k += r = t);
|
|
}
|
|
m = k;
|
|
}
|
|
this.matcher && m.length > 1 && (this.J || (this.J = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.J, u => this.matcher.get(u)));
|
|
if (m && this.replacer) {
|
|
for (k = 0; m && k < this.replacer.length; k += 2) {
|
|
m = m.replace(this.replacer[k], this.replacer[k + 1]);
|
|
}
|
|
}
|
|
this.cache && p.length <= this.I && (this.D.set(p, m), this.D.size > this.L && (this.D.clear(), this.I = this.I / 1.1 | 0));
|
|
if (m) {
|
|
if (m !== p) {
|
|
if (c) {
|
|
if (d[m]) {
|
|
continue;
|
|
}
|
|
d[m] = 1;
|
|
} else {
|
|
if (g === m) {
|
|
continue;
|
|
}
|
|
g = m;
|
|
}
|
|
}
|
|
e.push(m);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.finalize && (e = this.finalize(e) || e);
|
|
this.cache && a.length <= this.H && (this.B.set(a, e), this.B.size > this.L && (this.B.clear(), this.H = this.H / 1.1 | 0));
|
|
return e;
|
|
};
|
|
function la(a) {
|
|
a.F = null;
|
|
a.B.clear();
|
|
a.D.clear();
|
|
}
|
|
;function ma(a, c, b) {
|
|
b || (c || typeof a !== "object" ? typeof c === "object" && (b = c, c = 0) : b = a);
|
|
b && (a = b.query || a, c = b.limit || c);
|
|
let e = "" + (c || 0);
|
|
b && (e += (b.offset || 0) + !!b.context + !!b.suggest + (b.resolve !== !1) + (b.resolution || this.resolution) + (b.boost || 0));
|
|
a = ("" + a).toLowerCase();
|
|
this.cache || (this.cache = new na());
|
|
let d = this.cache.get(a + e);
|
|
if (!d) {
|
|
const f = b && b.cache;
|
|
f && (b.cache = !1);
|
|
d = this.search(a, c, b);
|
|
f && (b.cache = f);
|
|
this.cache.set(a + e, d);
|
|
}
|
|
return d;
|
|
}
|
|
function na(a) {
|
|
this.limit = a && a !== !0 ? a : 1000;
|
|
this.cache = new Map();
|
|
this.h = "";
|
|
}
|
|
na.prototype.set = function(a, c) {
|
|
this.cache.set(this.h = a, c);
|
|
this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value);
|
|
};
|
|
na.prototype.get = function(a) {
|
|
const c = this.cache.get(a);
|
|
c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c));
|
|
return c;
|
|
};
|
|
na.prototype.remove = function(a) {
|
|
for (const c of this.cache) {
|
|
const b = c[0];
|
|
c[1].includes(a) && this.cache.delete(b);
|
|
}
|
|
};
|
|
na.prototype.clear = function() {
|
|
this.cache.clear();
|
|
this.h = "";
|
|
};
|
|
const oa = {normalize:!1, numeric:!1, dedupe:!1};
|
|
const ra = {};
|
|
const sa = 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"]]);
|
|
const ta = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ua = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"];
|
|
const va = {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};
|
|
var wa = {Exact:oa, Default:ra, Normalize:ra, LatinBalance:{mapper:sa}, LatinAdvanced:{mapper:sa, matcher:ta, replacer:ua}, LatinExtra:{mapper:sa, replacer:ua.concat([/(?!^)[aeo]/g, ""]), matcher:ta}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) {
|
|
for (let b = 0; b < a.length; b++) {
|
|
var c = a[b];
|
|
let e = c.charAt(0), d = va[e];
|
|
for (let f = 1, g; f < c.length && (g = c.charAt(f), g === "h" || g === "w" || !(g = va[g]) || g === d || (e += g, d = g, e.length !== 4)); f++) {
|
|
}
|
|
a[b] = e;
|
|
}
|
|
}}, CJK:{split:""}, LatinExact:oa, LatinDefault:ra, LatinSimple:ra};
|
|
function xa(a, c, b, e) {
|
|
let d = [];
|
|
for (let f = 0, g; f < a.index.length; f++) {
|
|
if (g = a.index[f], c >= g.length) {
|
|
c -= g.length;
|
|
} else {
|
|
c = g[e ? "splice" : "slice"](c, b);
|
|
const h = c.length;
|
|
if (h && (d = d.length ? d.concat(c) : c, b -= h, e && (a.length -= h), !b)) {
|
|
break;
|
|
}
|
|
c = 0;
|
|
}
|
|
}
|
|
return d;
|
|
}
|
|
function Aa(a) {
|
|
if (!this || this.constructor !== Aa) {
|
|
return new Aa(a);
|
|
}
|
|
this.index = a ? [a] : [];
|
|
this.length = a ? a.length : 0;
|
|
const c = this;
|
|
return new Proxy([], {get(b, e) {
|
|
if (e === "length") {
|
|
return c.length;
|
|
}
|
|
if (e === "push") {
|
|
return function(d) {
|
|
c.index[c.index.length - 1].push(d);
|
|
c.length++;
|
|
};
|
|
}
|
|
if (e === "pop") {
|
|
return function() {
|
|
if (c.length) {
|
|
return c.length--, c.index[c.index.length - 1].pop();
|
|
}
|
|
};
|
|
}
|
|
if (e === "indexOf") {
|
|
return function(d) {
|
|
let f = 0;
|
|
for (let g = 0, h, k; g < c.index.length; g++) {
|
|
h = c.index[g];
|
|
k = h.indexOf(d);
|
|
if (k >= 0) {
|
|
return f + k;
|
|
}
|
|
f += h.length;
|
|
}
|
|
return -1;
|
|
};
|
|
}
|
|
if (e === "includes") {
|
|
return function(d) {
|
|
for (let f = 0; f < c.index.length; f++) {
|
|
if (c.index[f].includes(d)) {
|
|
return !0;
|
|
}
|
|
}
|
|
return !1;
|
|
};
|
|
}
|
|
if (e === "slice") {
|
|
return function(d, f) {
|
|
return xa(c, d || 0, f || c.length, !1);
|
|
};
|
|
}
|
|
if (e === "splice") {
|
|
return function(d, f) {
|
|
return xa(c, d || 0, f || c.length, !0);
|
|
};
|
|
}
|
|
if (e === "constructor") {
|
|
return Array;
|
|
}
|
|
if (typeof e !== "symbol") {
|
|
return (b = c.index[e / 2 ** 31 | 0]) && b[e];
|
|
}
|
|
}, set(b, e, d) {
|
|
b = e / 2 ** 31 | 0;
|
|
(c.index[b] || (c.index[b] = []))[e] = d;
|
|
c.length++;
|
|
return !0;
|
|
}});
|
|
}
|
|
Aa.prototype.clear = function() {
|
|
this.index.length = 0;
|
|
};
|
|
Aa.prototype.push = function() {
|
|
};
|
|
function Q(a = 8) {
|
|
if (!this || this.constructor !== Q) {
|
|
return new Q(a);
|
|
}
|
|
this.index = I();
|
|
this.h = [];
|
|
this.size = 0;
|
|
a > 32 ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a);
|
|
}
|
|
Q.prototype.get = function(a) {
|
|
const c = this.index[this.B(a)];
|
|
return c && c.get(a);
|
|
};
|
|
Q.prototype.set = function(a, c) {
|
|
var b = this.B(a);
|
|
let e = this.index[b];
|
|
e ? (b = e.size, e.set(a, c), (b -= e.size) && this.size++) : (this.index[b] = e = new Map([[a, c]]), this.h.push(e), this.size++);
|
|
};
|
|
function R(a = 8) {
|
|
if (!this || this.constructor !== R) {
|
|
return new R(a);
|
|
}
|
|
this.index = I();
|
|
this.h = [];
|
|
this.size = 0;
|
|
a > 32 ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a);
|
|
}
|
|
R.prototype.add = function(a) {
|
|
var c = this.B(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.h.push(b), this.size++);
|
|
};
|
|
w = Q.prototype;
|
|
w.has = R.prototype.has = function(a) {
|
|
const c = this.index[this.B(a)];
|
|
return c && c.has(a);
|
|
};
|
|
w.delete = R.prototype.delete = function(a) {
|
|
const c = this.index[this.B(a)];
|
|
c && c.delete(a) && this.size--;
|
|
};
|
|
w.clear = R.prototype.clear = function() {
|
|
this.index = I();
|
|
this.h = [];
|
|
this.size = 0;
|
|
};
|
|
w.values = R.prototype.values = function*() {
|
|
for (let a = 0; a < this.h.length; a++) {
|
|
for (let c of this.h[a].values()) {
|
|
yield c;
|
|
}
|
|
}
|
|
};
|
|
w.keys = R.prototype.keys = function*() {
|
|
for (let a = 0; a < this.h.length; a++) {
|
|
for (let c of this.h[a].keys()) {
|
|
yield c;
|
|
}
|
|
}
|
|
};
|
|
w.entries = R.prototype.entries = function*() {
|
|
for (let a = 0; a < this.h.length; a++) {
|
|
for (let c of this.h[a].entries()) {
|
|
yield c;
|
|
}
|
|
}
|
|
};
|
|
function Ca(a) {
|
|
let c = 2 ** this.A - 1;
|
|
if (typeof a == "number") {
|
|
return a & c;
|
|
}
|
|
let b = 0, e = this.A + 1;
|
|
for (let d = 0; d < a.length; d++) {
|
|
b = (b * e ^ a.charCodeAt(d)) & c;
|
|
}
|
|
return this.A === 32 ? b + 2 ** 31 : b;
|
|
}
|
|
function Ba(a) {
|
|
let c = BigInt(2) ** this.A - BigInt(1);
|
|
var b = typeof a;
|
|
if (b === "bigint") {
|
|
return a & c;
|
|
}
|
|
if (b === "number") {
|
|
return BigInt(a) & c;
|
|
}
|
|
b = BigInt(0);
|
|
let e = this.A + BigInt(1);
|
|
for (let d = 0; d < a.length; d++) {
|
|
b = (b * e ^ BigInt(a.charCodeAt(d))) & c;
|
|
}
|
|
return b;
|
|
}
|
|
;let Da, S;
|
|
async function Ea(a) {
|
|
a = a.data;
|
|
var c = a.task;
|
|
const b = a.id;
|
|
let e = a.args;
|
|
switch(c) {
|
|
case "init":
|
|
S = a.options || {};
|
|
(c = a.factory) ? (Function("return " + c)()(self), Da = new self.FlexSearch.Index(S), delete self.FlexSearch) : Da = new T(S);
|
|
postMessage({id:b});
|
|
break;
|
|
default:
|
|
let d;
|
|
if (c === "export") {
|
|
if (!S.export || typeof S.export !== "function") {
|
|
throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".');
|
|
}
|
|
e[1] ? (e[0] = S.export, e[2] = 0, e[3] = 1) : e = null;
|
|
}
|
|
if (c === "import") {
|
|
if (!S.import || typeof S.import !== "function") {
|
|
throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".');
|
|
}
|
|
e[0] && (a = await S.import.call(Da, e[0]), Da.import(e[0], a));
|
|
} else {
|
|
(d = e && Da[c].apply(Da, e)) && d.then && (d = await d), d && d.await && (d = await d.await), c === "search" && d.result && (d = d.result);
|
|
}
|
|
postMessage(c === "search" ? {id:b, msg:d} : {id:b});
|
|
}
|
|
}
|
|
;function Fa(a) {
|
|
Ga.call(a, "add");
|
|
Ga.call(a, "append");
|
|
Ga.call(a, "search");
|
|
Ga.call(a, "update");
|
|
Ga.call(a, "remove");
|
|
Ga.call(a, "searchCache");
|
|
}
|
|
let Ha, Ia, Ja;
|
|
function Ka() {
|
|
Ha = Ja = 0;
|
|
}
|
|
function Ga(a) {
|
|
this[a + "Async"] = function() {
|
|
const c = arguments;
|
|
var b = c[c.length - 1];
|
|
let e;
|
|
typeof b === "function" && (e = b, delete c[c.length - 1]);
|
|
Ha ? Ja || (Ja = Date.now() - Ia >= this.priority * this.priority * 3) : (Ha = setTimeout(Ka, 0), Ia = Date.now());
|
|
if (Ja) {
|
|
const f = this;
|
|
return new Promise(g => {
|
|
setTimeout(function() {
|
|
g(f[a + "Async"].apply(f, c));
|
|
}, 0);
|
|
});
|
|
}
|
|
const d = this[a].apply(this, c);
|
|
b = d.then ? d : new Promise(f => f(d));
|
|
e && b.then(e);
|
|
return b;
|
|
};
|
|
}
|
|
;let V = 0;
|
|
function La(a = {}, c) {
|
|
function b(h) {
|
|
function k(l) {
|
|
l = l.data || l;
|
|
const m = l.id, p = m && f.h[m];
|
|
p && (p(l.msg), delete f.h[m]);
|
|
}
|
|
this.worker = h;
|
|
this.h = I();
|
|
if (this.worker) {
|
|
d ? this.worker.on("message", k) : this.worker.onmessage = k;
|
|
if (a.config) {
|
|
return new Promise(function(l) {
|
|
V > 1e9 && (V = 0);
|
|
f.h[++V] = function() {
|
|
l(f);
|
|
};
|
|
f.worker.postMessage({id:V, task:"init", factory:e, options:a});
|
|
});
|
|
}
|
|
this.priority = a.priority || 4;
|
|
this.encoder = c || null;
|
|
this.worker.postMessage({task:"init", factory:e, options:a});
|
|
return this;
|
|
}
|
|
console.warn("Worker is not available on this platform. Please report on Github: https://github.com/nextapps-de/flexsearch/issues");
|
|
}
|
|
if (!this || this.constructor !== La) {
|
|
return new La(a);
|
|
}
|
|
let e = typeof self !== "undefined" ? self._factory : typeof window !== "undefined" ? window._factory : null;
|
|
e && (e = e.toString());
|
|
const d = typeof window === "undefined", f = this, g = Ma(e, d, a.worker);
|
|
return g.then ? g.then(function(h) {
|
|
return b.call(f, h);
|
|
}) : b.call(this, g);
|
|
}
|
|
W("add");
|
|
W("append");
|
|
W("search");
|
|
W("update");
|
|
W("remove");
|
|
W("clear");
|
|
W("export");
|
|
W("import");
|
|
La.prototype.searchCache = ma;
|
|
Fa(La.prototype);
|
|
function W(a) {
|
|
La.prototype[a] = function() {
|
|
const c = this, b = [].slice.call(arguments);
|
|
var e = b[b.length - 1];
|
|
let d;
|
|
typeof e === "function" && (d = e, b.pop());
|
|
e = new Promise(function(f) {
|
|
a === "export" && typeof b[0] === "function" && (b[0] = null);
|
|
V > 1e9 && (V = 0);
|
|
c.h[++V] = f;
|
|
c.worker.postMessage({task:a, id:V, args:b});
|
|
});
|
|
return d ? (e.then(d), this) : e;
|
|
};
|
|
}
|
|
function Ma(a, c, b) {
|
|
return c ? typeof module !== "undefined" ? new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ea.toString()], {type:"text/javascript"}))) : new window.Worker(typeof b === "string" ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js",
|
|
"module/worker/worker.js"), {type:"module"});
|
|
}
|
|
;Na.prototype.add = function(a, c, b) {
|
|
ba(a) && (c = a, a = ca(c, this.key));
|
|
if (c && (a || a === 0)) {
|
|
if (!b && this.reg.has(a)) {
|
|
return this.update(a, c);
|
|
}
|
|
for (let h = 0, k; h < this.field.length; h++) {
|
|
k = this.B[h];
|
|
var e = this.index.get(this.field[h]);
|
|
if (typeof k === "function") {
|
|
var d = k(c);
|
|
d && e.add(a, d, b, !0);
|
|
} else {
|
|
if (d = k.G, !d || d(c)) {
|
|
k.constructor === String ? k = ["" + k] : N(k) && (k = [k]), Qa(c, k, this.D, 0, e, a, k[0], b);
|
|
}
|
|
}
|
|
}
|
|
if (this.tag) {
|
|
for (e = 0; e < this.A.length; e++) {
|
|
var f = this.A[e], g = this.F[e];
|
|
d = this.tag.get(g);
|
|
let h = I();
|
|
if (typeof f === "function") {
|
|
if (f = f(c), !f) {
|
|
continue;
|
|
}
|
|
} else {
|
|
const k = f.G;
|
|
if (k && !k(c)) {
|
|
continue;
|
|
}
|
|
f.constructor === String && (f = "" + f);
|
|
f = ca(c, f);
|
|
}
|
|
if (d && f) {
|
|
N(f) && (f = [f]);
|
|
for (let k = 0, l, m; k < f.length; k++) {
|
|
if (l = f[k], !h[l] && (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !b || !m.includes(a))) {
|
|
if (m.length === 2 ** 31 - 1) {
|
|
g = new Aa(m);
|
|
if (this.fastupdate) {
|
|
for (let p of this.reg.values()) {
|
|
p.includes(m) && (p[p.indexOf(m)] = g);
|
|
}
|
|
}
|
|
d.set(l, m = g);
|
|
}
|
|
m.push(a);
|
|
this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m]));
|
|
}
|
|
}
|
|
} else {
|
|
d || console.warn("Tag '" + g + "' was not found");
|
|
}
|
|
}
|
|
}
|
|
if (this.store && (!b || !this.store.has(a))) {
|
|
let h;
|
|
if (this.h) {
|
|
h = I();
|
|
for (let k = 0, l; k < this.h.length; k++) {
|
|
l = this.h[k];
|
|
if ((b = l.G) && !b(c)) {
|
|
continue;
|
|
}
|
|
let m;
|
|
if (typeof l === "function") {
|
|
m = l(c);
|
|
if (!m) {
|
|
continue;
|
|
}
|
|
l = [l.O];
|
|
} else if (N(l) || l.constructor === String) {
|
|
h[l] = c[l];
|
|
continue;
|
|
}
|
|
Ra(c, h, l, 0, l[0], m);
|
|
}
|
|
}
|
|
this.store.set(a, h || c);
|
|
}
|
|
this.worker && (this.fastupdate || this.reg.add(a));
|
|
}
|
|
return this;
|
|
};
|
|
function Ra(a, c, b, e, d, f) {
|
|
a = a[d];
|
|
if (e === b.length - 1) {
|
|
c[d] = f || a;
|
|
} else if (a) {
|
|
if (a.constructor === Array) {
|
|
for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) {
|
|
Ra(a, c, b, e, d);
|
|
}
|
|
} else {
|
|
c = c[d] || (c[d] = I()), d = b[++e], Ra(a, c, b, e, d);
|
|
}
|
|
}
|
|
}
|
|
function Qa(a, c, b, e, d, f, g, h) {
|
|
if (a = a[g]) {
|
|
if (e === c.length - 1) {
|
|
if (a.constructor === Array) {
|
|
if (b[e]) {
|
|
for (c = 0; c < a.length; c++) {
|
|
d.add(f, a[c], !0, !0);
|
|
}
|
|
return;
|
|
}
|
|
a = a.join(" ");
|
|
}
|
|
d.add(f, a, h, !0);
|
|
} else {
|
|
if (a.constructor === Array) {
|
|
for (g = 0; g < a.length; g++) {
|
|
Qa(a, c, b, e, d, f, g, h);
|
|
}
|
|
} else {
|
|
g = c[++e], Qa(a, c, b, e, d, f, g, h);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
;function Sa(a, c, b, e) {
|
|
if (!a.length) {
|
|
return a;
|
|
}
|
|
if (a.length === 1) {
|
|
return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a, e ? Ta.call(this, a) : a;
|
|
}
|
|
let d = [];
|
|
for (let f = 0, g, h; f < a.length; f++) {
|
|
if ((g = a[f]) && (h = g.length)) {
|
|
if (b) {
|
|
if (b >= h) {
|
|
b -= h;
|
|
continue;
|
|
}
|
|
g = g.slice(b, b + c);
|
|
h = g.length;
|
|
b = 0;
|
|
}
|
|
h > c && (g = g.slice(0, c), h = c);
|
|
if (!d.length && h >= c) {
|
|
return e ? Ta.call(this, g) : g;
|
|
}
|
|
d.push(g);
|
|
c -= h;
|
|
if (!c) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
d = d.length > 1 ? [].concat.apply([], d) : d[0];
|
|
return e ? Ta.call(this, d) : d;
|
|
}
|
|
;function Ua(a, c, b, e) {
|
|
var d = e[0];
|
|
if (d[0] && d[0].query) {
|
|
return a[c].apply(a, d);
|
|
}
|
|
if (!(c !== "and" && c !== "not" || a.result.length || a.await || d.suggest)) {
|
|
return e.length > 1 && (d = e[e.length - 1]), (e = d.resolve) ? a.await || a.result : a;
|
|
}
|
|
let f = [], g = 0, h = 0, k, l, m, p, u;
|
|
for (c = 0; c < e.length; c++) {
|
|
if (d = e[c]) {
|
|
var r = void 0;
|
|
if (d.constructor === X) {
|
|
r = d.await || d.result;
|
|
} else if (d.then || d.constructor === Array) {
|
|
r = d;
|
|
} else {
|
|
g = d.limit || 0;
|
|
h = d.offset || 0;
|
|
m = d.suggest;
|
|
l = d.resolve;
|
|
k = ((p = d.highlight || a.highlight) || d.enrich) && l;
|
|
r = d.queue;
|
|
let t = d.async || r, n = d.index, q = d.query;
|
|
n ? a.index || (a.index = n) : n = a.index;
|
|
if (q || d.tag) {
|
|
if (!n) {
|
|
throw Error("Resolver can't apply because the corresponding Index was never specified");
|
|
}
|
|
const x = d.field || d.pluck;
|
|
if (x) {
|
|
!q || a.query && !p || (a.query = q, a.field = x, a.highlight = p);
|
|
if (!n.index) {
|
|
throw Error("Resolver can't apply because the corresponding Document Index was not specified");
|
|
}
|
|
n = n.index.get(x);
|
|
if (!n) {
|
|
throw Error("Resolver can't apply because the specified Document Field '" + x + "' was not found");
|
|
}
|
|
}
|
|
if (r && (u || a.await)) {
|
|
u = 1;
|
|
let v;
|
|
const A = a.C.length, D = new Promise(function(G) {
|
|
v = G;
|
|
});
|
|
(function(G, E) {
|
|
D.h = function() {
|
|
E.index = null;
|
|
E.resolve = !1;
|
|
let B = t ? G.searchAsync(E) : G.search(E);
|
|
if (B.then) {
|
|
return B.then(function(z) {
|
|
a.C[A] = z = z.result || z;
|
|
v(z);
|
|
return z;
|
|
});
|
|
}
|
|
B = B.result || B;
|
|
v(B);
|
|
return B;
|
|
};
|
|
})(n, Object.assign({}, d));
|
|
a.C.push(D);
|
|
f[c] = D;
|
|
continue;
|
|
} else {
|
|
d.resolve = !1, d.index = null, r = t ? n.searchAsync(d) : n.search(d), d.resolve = l, d.index = n;
|
|
}
|
|
} else if (d.and) {
|
|
r = Va(d, "and", n);
|
|
} else if (d.or) {
|
|
r = Va(d, "or", n);
|
|
} else if (d.not) {
|
|
r = Va(d, "not", n);
|
|
} else if (d.xor) {
|
|
r = Va(d, "xor", n);
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
r.await ? (u = 1, r = r.await) : r.then ? (u = 1, r = r.then(function(t) {
|
|
return t.result || t;
|
|
})) : r = r.result || r;
|
|
f[c] = r;
|
|
}
|
|
}
|
|
u && !a.await && (a.await = new Promise(function(t) {
|
|
a.return = t;
|
|
}));
|
|
if (u) {
|
|
const t = Promise.all(f).then(function(n) {
|
|
for (let q = 0; q < a.C.length; q++) {
|
|
if (a.C[q] === t) {
|
|
a.C[q] = function() {
|
|
return b.call(a, n, g, h, k, l, m, p);
|
|
};
|
|
break;
|
|
}
|
|
}
|
|
Wa(a);
|
|
});
|
|
a.C.push(t);
|
|
} else if (a.await) {
|
|
a.C.push(function() {
|
|
return b.call(a, f, g, h, k, l, m, p);
|
|
});
|
|
} else {
|
|
return b.call(a, f, g, h, k, l, m, p);
|
|
}
|
|
return l ? a.await || a.result : a;
|
|
}
|
|
function Va(a, c, b) {
|
|
a = a[c];
|
|
const e = a[0] || a;
|
|
e.index || (e.index = b);
|
|
b = new X(e);
|
|
a.length > 1 && (b = b[c].apply(b, a.slice(1)));
|
|
return b;
|
|
}
|
|
;X.prototype.or = function() {
|
|
return Ua(this, "or", Xa, arguments);
|
|
};
|
|
function Xa(a, c, b, e, d, f, g) {
|
|
a.length && (this.result.length && a.push(this.result), a.length < 2 ? this.result = a[0] : (this.result = Ya(a, c, b, !1, this.h), b = 0));
|
|
d && (this.await = null);
|
|
return d ? this.resolve(c, b, e, g) : this;
|
|
}
|
|
;X.prototype.and = function() {
|
|
return Ua(this, "and", Za, arguments);
|
|
};
|
|
function Za(a, c, b, e, d, f, g) {
|
|
if (!f && !this.result.length) {
|
|
return d ? this.result : this;
|
|
}
|
|
let h;
|
|
if (a.length) {
|
|
if (this.result.length && a.unshift(this.result), a.length < 2) {
|
|
this.result = a[0];
|
|
} else {
|
|
let k = 0;
|
|
for (let l = 0, m, p; l < a.length; l++) {
|
|
if ((m = a[l]) && (p = m.length)) {
|
|
k < p && (k = p);
|
|
} else if (!f) {
|
|
k = 0;
|
|
break;
|
|
}
|
|
}
|
|
k ? (this.result = $a(a, k, c, b, f, this.h, d), h = !0) : this.result = [];
|
|
}
|
|
} else {
|
|
f || (this.result = a);
|
|
}
|
|
d && (this.await = null);
|
|
return d ? this.resolve(c, b, e, g, h) : this;
|
|
}
|
|
;X.prototype.xor = function() {
|
|
return Ua(this, "xor", ab, arguments);
|
|
};
|
|
function ab(a, c, b, e, d, f, g) {
|
|
if (a.length) {
|
|
if (this.result.length && a.unshift(this.result), a.length < 2) {
|
|
this.result = a[0];
|
|
} else {
|
|
a: {
|
|
f = b;
|
|
var h = this.h;
|
|
const k = [], l = I();
|
|
let m = 0;
|
|
for (let p = 0, u; p < a.length; p++) {
|
|
if (u = a[p]) {
|
|
m < u.length && (m = u.length);
|
|
for (let r = 0, t; r < u.length; r++) {
|
|
if (t = u[r]) {
|
|
for (let n = 0, q; n < t.length; n++) {
|
|
q = t[n], l[q] = l[q] ? 2 : 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (let p = 0, u, r = 0; p < m; p++) {
|
|
for (let t = 0, n; t < a.length; t++) {
|
|
if (n = a[t]) {
|
|
if (u = n[p]) {
|
|
for (let q = 0, x; q < u.length; q++) {
|
|
if (x = u[q], l[x] === 1) {
|
|
if (f) {
|
|
f--;
|
|
} else {
|
|
if (d) {
|
|
if (k.push(x), k.length === c) {
|
|
a = k;
|
|
break a;
|
|
}
|
|
} else {
|
|
const v = p + (t ? h : 0);
|
|
k[v] || (k[v] = []);
|
|
k[v].push(x);
|
|
if (++r === c) {
|
|
a = k;
|
|
break a;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
a = k;
|
|
}
|
|
this.result = a;
|
|
h = !0;
|
|
}
|
|
} else {
|
|
f || (this.result = a);
|
|
}
|
|
d && (this.await = null);
|
|
return d ? this.resolve(c, b, e, g, h) : this;
|
|
}
|
|
;X.prototype.not = function() {
|
|
return Ua(this, "not", bb, arguments);
|
|
};
|
|
function bb(a, c, b, e, d, f, g) {
|
|
if (!f && !this.result.length) {
|
|
return d ? this.result : this;
|
|
}
|
|
if (a.length && this.result.length) {
|
|
a: {
|
|
f = b;
|
|
var h = [];
|
|
a = new Set(a.flat().flat());
|
|
for (let k = 0, l, m = 0; k < this.result.length; k++) {
|
|
if (l = this.result[k]) {
|
|
for (let p = 0, u; p < l.length; p++) {
|
|
if (u = l[p], !a.has(u)) {
|
|
if (f) {
|
|
f--;
|
|
} else {
|
|
if (d) {
|
|
if (h.push(u), h.length === c) {
|
|
a = h;
|
|
break a;
|
|
}
|
|
} else {
|
|
if (h[k] || (h[k] = []), h[k].push(u), ++m === c) {
|
|
a = h;
|
|
break a;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
a = h;
|
|
}
|
|
this.result = a;
|
|
h = !0;
|
|
}
|
|
d && (this.await = null);
|
|
return d ? this.resolve(c, b, e, g, h) : this;
|
|
}
|
|
;function cb(a, c, b, e, d) {
|
|
let f, g, h;
|
|
typeof d === "string" ? (f = d, d = "") : f = d.template;
|
|
if (!f) {
|
|
throw Error('No template pattern was specified by the search option "highlight"');
|
|
}
|
|
g = f.indexOf("$1");
|
|
if (g === -1) {
|
|
throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f);
|
|
}
|
|
h = f.substring(g + 2);
|
|
g = f.substring(0, g);
|
|
let k = d && d.boundary, l = !d || d.clip !== !1, m = d && d.merge && h && g && new RegExp(h + " " + g, "g");
|
|
d = d && d.ellipsis;
|
|
var p = 0;
|
|
if (typeof d === "object") {
|
|
var u = d.template;
|
|
p = u.length - 2;
|
|
d = d.pattern;
|
|
}
|
|
typeof d !== "string" && (d = d === !1 ? "" : "...");
|
|
p && (d = u.replace("$1", d));
|
|
u = d.length - p;
|
|
let r, t;
|
|
typeof k === "object" && (r = k.before, r === 0 && (r = -1), t = k.after, t === 0 && (t = -1), k = k.total || 9e5);
|
|
p = new Map();
|
|
for (let Oa = 0, ea, db, pa; Oa < c.length; Oa++) {
|
|
let qa;
|
|
if (e) {
|
|
qa = c, pa = e;
|
|
} else {
|
|
var n = c[Oa];
|
|
pa = n.field;
|
|
if (!pa) {
|
|
continue;
|
|
}
|
|
qa = n.result;
|
|
}
|
|
db = b.get(pa);
|
|
ea = db.encoder;
|
|
n = p.get(ea);
|
|
typeof n !== "string" && (n = ea.encode(a), p.set(ea, n));
|
|
for (let ya = 0; ya < qa.length; ya++) {
|
|
var q = qa[ya].doc;
|
|
if (!q) {
|
|
continue;
|
|
}
|
|
q = ca(q, pa);
|
|
if (!q) {
|
|
continue;
|
|
}
|
|
var x = q.trim().split(/\s+/);
|
|
if (!x.length) {
|
|
continue;
|
|
}
|
|
q = "";
|
|
var v = [];
|
|
let za = [];
|
|
var A = -1, D = -1, G = 0;
|
|
for (var E = 0; E < x.length; E++) {
|
|
var B = x[E], z = ea.encode(B);
|
|
z = z.length > 1 ? z.join(" ") : z[0];
|
|
let y;
|
|
if (z && B) {
|
|
var C = B.length, K = (ea.split ? B.replace(ea.split, "") : B).length - z.length, F = "", L = 0;
|
|
for (var O = 0; O < n.length; O++) {
|
|
var P = n[O];
|
|
if (P) {
|
|
var M = P.length;
|
|
M += K;
|
|
L && M <= L || (P = z.indexOf(P), P > -1 && (F = (P ? B.substring(0, P) : "") + g + B.substring(P, P + M) + h + (P + M < C ? B.substring(P + M) : ""), L = M, y = !0));
|
|
}
|
|
}
|
|
F && (k && (A < 0 && (A = q.length + (q ? 1 : 0)), D = q.length + (q ? 1 : 0) + F.length, G += C, za.push(v.length), v.push({match:F})), q += (q ? " " : "") + F);
|
|
}
|
|
if (!y) {
|
|
B = x[E], q += (q ? " " : "") + B, k && v.push({text:B});
|
|
} else if (k && G >= k) {
|
|
break;
|
|
}
|
|
}
|
|
G = za.length * (f.length - 2);
|
|
if (r || t || k && q.length - G > k) {
|
|
if (G = k + G - u * 2, E = D - A, r > 0 && (E += r), t > 0 && (E += t), E <= G) {
|
|
x = r ? A - (r > 0 ? r : 0) : A - ((G - E) / 2 | 0), v = t ? D + (t > 0 ? t : 0) : x + G, l || (x > 0 && q.charAt(x) !== " " && q.charAt(x - 1) !== " " && (x = q.indexOf(" ", x), x < 0 && (x = 0)), v < q.length && q.charAt(v - 1) !== " " && q.charAt(v) !== " " && (v = q.lastIndexOf(" ", v), v < D ? v = D : ++v)), q = (x ? d : "") + q.substring(x, v) + (v < q.length ? d : "");
|
|
} else {
|
|
D = [];
|
|
A = {};
|
|
G = {};
|
|
E = {};
|
|
B = {};
|
|
z = {};
|
|
F = K = C = 0;
|
|
for (O = L = 1;;) {
|
|
var U = void 0;
|
|
for (let y = 0, J; y < za.length; y++) {
|
|
J = za[y];
|
|
if (F) {
|
|
if (K !== F) {
|
|
if (E[y + 1]) {
|
|
continue;
|
|
}
|
|
J += F;
|
|
if (A[J]) {
|
|
C -= u;
|
|
G[y + 1] = 1;
|
|
E[y + 1] = 1;
|
|
continue;
|
|
}
|
|
if (J >= v.length - 1) {
|
|
if (J >= v.length) {
|
|
E[y + 1] = 1;
|
|
J >= x.length && (G[y + 1] = 1);
|
|
continue;
|
|
}
|
|
C -= u;
|
|
}
|
|
q = v[J].text;
|
|
if (M = t && z[y]) {
|
|
if (M > 0) {
|
|
if (q.length > M) {
|
|
if (E[y + 1] = 1, l) {
|
|
q = q.substring(0, M);
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
(M -= q.length) || (M = -1);
|
|
z[y] = M;
|
|
} else {
|
|
E[y + 1] = 1;
|
|
continue;
|
|
}
|
|
}
|
|
if (C + q.length + 1 <= k) {
|
|
q = " " + q, D[y] += q;
|
|
} else if (l) {
|
|
U = k - C - 1, U > 0 && (q = " " + q.substring(0, U), D[y] += q), E[y + 1] = 1;
|
|
} else {
|
|
E[y + 1] = 1;
|
|
continue;
|
|
}
|
|
} else {
|
|
if (E[y]) {
|
|
continue;
|
|
}
|
|
J -= K;
|
|
if (A[J]) {
|
|
C -= u;
|
|
E[y] = 1;
|
|
G[y] = 1;
|
|
continue;
|
|
}
|
|
if (J <= 0) {
|
|
if (J < 0) {
|
|
E[y] = 1;
|
|
G[y] = 1;
|
|
continue;
|
|
}
|
|
C -= u;
|
|
}
|
|
q = v[J].text;
|
|
if (M = r && B[y]) {
|
|
if (M > 0) {
|
|
if (q.length > M) {
|
|
if (E[y] = 1, l) {
|
|
q = q.substring(q.length - M);
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
(M -= q.length) || (M = -1);
|
|
B[y] = M;
|
|
} else {
|
|
E[y] = 1;
|
|
continue;
|
|
}
|
|
}
|
|
if (C + q.length + 1 <= k) {
|
|
q += " ", D[y] = q + D[y];
|
|
} else if (l) {
|
|
U = q.length + 1 - (k - C), U >= 0 && U < q.length && (q = q.substring(U) + " ", D[y] = q + D[y]), E[y] = 1;
|
|
} else {
|
|
E[y] = 1;
|
|
continue;
|
|
}
|
|
}
|
|
} else {
|
|
q = v[J].match;
|
|
r && (B[y] = r);
|
|
t && (z[y] = t);
|
|
y && C++;
|
|
let Pa;
|
|
J ? !y && u && (C += u) : (G[y] = 1, E[y] = 1);
|
|
J >= x.length - 1 ? Pa = 1 : J < v.length - 1 && v[J + 1].match ? Pa = 1 : u && (C += u);
|
|
C -= f.length - 2;
|
|
if (!y || C + q.length <= k) {
|
|
D[y] = q;
|
|
} else {
|
|
U = L = O = G[y] = 0;
|
|
break;
|
|
}
|
|
Pa && (G[y + 1] = 1, E[y + 1] = 1);
|
|
}
|
|
C += q.length;
|
|
U = A[J] = 1;
|
|
}
|
|
if (U) {
|
|
K === F ? F++ : K++;
|
|
} else {
|
|
K === F ? L = 0 : O = 0;
|
|
if (!L && !O) {
|
|
break;
|
|
}
|
|
L ? (K++, F = K) : F++;
|
|
}
|
|
}
|
|
q = "";
|
|
for (let y = 0, J; y < D.length; y++) {
|
|
J = (G[y] ? y ? " " : "" : (y && !d ? " " : "") + d) + D[y], q += J;
|
|
}
|
|
d && !G[D.length] && (q += d);
|
|
}
|
|
}
|
|
m && (q = q.replace(m, " "));
|
|
qa[ya].highlight = q;
|
|
}
|
|
if (e) {
|
|
break;
|
|
}
|
|
}
|
|
return c;
|
|
}
|
|
;function X(a, c) {
|
|
if (!this || this.constructor !== X) {
|
|
return new X(a, c);
|
|
}
|
|
let b = 0, e, d, f, g, h, k;
|
|
if (a && a.index) {
|
|
const l = a;
|
|
c = l.index;
|
|
b = l.boost || 0;
|
|
if (d = l.query) {
|
|
f = l.field || l.pluck;
|
|
g = l.highlight;
|
|
const m = l.resolve;
|
|
a = l.async || l.queue;
|
|
l.resolve = !1;
|
|
l.index = null;
|
|
a = a ? c.searchAsync(l) : c.search(l);
|
|
l.resolve = m;
|
|
l.index = c;
|
|
a = a.result || a;
|
|
} else {
|
|
a = [];
|
|
}
|
|
}
|
|
if (a && a.then) {
|
|
const l = this;
|
|
a = a.then(function(m) {
|
|
l.C[0] = l.result = m.result || m;
|
|
Wa(l);
|
|
});
|
|
e = [a];
|
|
a = [];
|
|
h = new Promise(function(m) {
|
|
k = m;
|
|
});
|
|
}
|
|
this.index = c || null;
|
|
this.result = a || [];
|
|
this.h = b;
|
|
this.C = e || [];
|
|
this.await = h || null;
|
|
this.return = k || null;
|
|
this.highlight = g || null;
|
|
this.query = d || "";
|
|
this.field = f || "";
|
|
}
|
|
w = X.prototype;
|
|
w.limit = function(a) {
|
|
if (this.await) {
|
|
const c = this;
|
|
this.C.push(function() {
|
|
return c.limit(a).result;
|
|
});
|
|
} else {
|
|
if (this.result.length) {
|
|
const c = [];
|
|
for (let b = 0, e; b < this.result.length; b++) {
|
|
if (e = this.result[b]) {
|
|
if (e.length <= a) {
|
|
if (c[b] = e, a -= e.length, !a) {
|
|
break;
|
|
}
|
|
} else {
|
|
c[b] = e.slice(0, a);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
this.result = c;
|
|
}
|
|
}
|
|
return this;
|
|
};
|
|
w.offset = function(a) {
|
|
if (this.await) {
|
|
const c = this;
|
|
this.C.push(function() {
|
|
return c.offset(a).result;
|
|
});
|
|
} else {
|
|
if (this.result.length) {
|
|
const c = [];
|
|
for (let b = 0, e; b < this.result.length; b++) {
|
|
if (e = this.result[b]) {
|
|
e.length <= a ? a -= e.length : (c[b] = e.slice(a), a = 0);
|
|
}
|
|
}
|
|
this.result = c;
|
|
}
|
|
}
|
|
return this;
|
|
};
|
|
w.boost = function(a) {
|
|
if (this.await) {
|
|
const c = this;
|
|
this.C.push(function() {
|
|
return c.boost(a).result;
|
|
});
|
|
} else {
|
|
this.h += a;
|
|
}
|
|
return this;
|
|
};
|
|
function Wa(a, c) {
|
|
let b = a.result;
|
|
var e = a.await;
|
|
a.await = null;
|
|
for (let d = 0, f; d < a.C.length; d++) {
|
|
if (f = a.C[d]) {
|
|
if (typeof f === "function") {
|
|
b = f(), a.C[d] = b = b.result || b, d--;
|
|
} else if (f.h) {
|
|
b = f.h(), a.C[d] = b = b.result || b, d--;
|
|
} else if (f.then) {
|
|
return a.await = e;
|
|
}
|
|
}
|
|
}
|
|
e = a.return;
|
|
a.C = [];
|
|
a.return = null;
|
|
c || e(b);
|
|
return b;
|
|
}
|
|
w.resolve = function(a, c, b, e, d) {
|
|
let f = this.await ? Wa(this, !0) : this.result;
|
|
if (f.then) {
|
|
const g = this;
|
|
return f.then(function() {
|
|
return g.resolve(a, c, b, e, d);
|
|
});
|
|
}
|
|
f.length && (typeof a === "object" ? (e = a.highlight || this.highlight, b = !!e || a.enrich, c = a.offset, a = a.limit) : (e = e || this.highlight, b = !!e || b), f = d ? b ? Ta.call(this.index, f) : f : Sa.call(this.index, f, a || 100, c, b));
|
|
return this.finalize(f, e);
|
|
};
|
|
w.finalize = function(a, c) {
|
|
if (a.then) {
|
|
const e = this;
|
|
return a.then(function(d) {
|
|
return e.finalize(d, c);
|
|
});
|
|
}
|
|
c && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the highlight resolver stage like { query: "...", highlight: ... }.');
|
|
c && a.length && this.query && (a = cb(this.query, a, this.index.index, this.field, c));
|
|
const b = this.return;
|
|
this.highlight = this.index = this.result = this.C = this.await = this.return = null;
|
|
this.query = this.field = "";
|
|
b && b(a);
|
|
return a;
|
|
};
|
|
function $a(a, c, b, e, d, f, g) {
|
|
const h = a.length;
|
|
let k = [], l, m;
|
|
l = I();
|
|
for (let p = 0, u, r, t, n; p < c; p++) {
|
|
for (let q = 0; q < h; q++) {
|
|
if (t = a[q], p < t.length && (u = t[p])) {
|
|
for (let x = 0; x < u.length; x++) {
|
|
r = u[x];
|
|
(m = l[r]) ? l[r]++ : (m = 0, l[r] = 1);
|
|
n = k[m] || (k[m] = []);
|
|
if (!g) {
|
|
let v = p + (q || !d ? 0 : f || 0);
|
|
n = n[v] || (n[v] = []);
|
|
}
|
|
n.push(r);
|
|
if (g && b && m === h - 1 && n.length - e === b) {
|
|
return e ? n.slice(e) : n;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (a = k.length) {
|
|
if (d) {
|
|
k = k.length > 1 ? Ya(k, b, e, g, f) : (k = k[0]) && b && k.length > b || e ? k.slice(e, b + e) : k;
|
|
} else {
|
|
if (a < h) {
|
|
return [];
|
|
}
|
|
k = k[a - 1];
|
|
if (b || e) {
|
|
if (g) {
|
|
if (k.length > b || e) {
|
|
k = k.slice(e, b + e);
|
|
}
|
|
} else {
|
|
d = [];
|
|
for (let p = 0, u; p < k.length; p++) {
|
|
if (u = k[p]) {
|
|
if (e && u.length > e) {
|
|
e -= u.length;
|
|
} else {
|
|
if (b && u.length > b || e) {
|
|
u = u.slice(e, b + e), b -= u.length, e && (e -= u.length);
|
|
}
|
|
d.push(u);
|
|
if (!b) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
k = d;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return k;
|
|
}
|
|
function Ya(a, c, b, e, d) {
|
|
const f = [], g = I();
|
|
let h;
|
|
var k = a.length;
|
|
let l;
|
|
if (e) {
|
|
for (d = k - 1; d >= 0; d--) {
|
|
if (l = (e = a[d]) && e.length) {
|
|
for (k = 0; k < l; k++) {
|
|
if (h = e[k], !g[h]) {
|
|
if (g[h] = 1, b) {
|
|
b--;
|
|
} else {
|
|
if (f.push(h), f.length === c) {
|
|
return f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for (let m = k - 1, p, u = 0; m >= 0; m--) {
|
|
p = a[m];
|
|
for (let r = 0; r < p.length; r++) {
|
|
if (l = (e = p[r]) && e.length) {
|
|
for (let t = 0; t < l; t++) {
|
|
if (h = e[t], !g[h]) {
|
|
if (g[h] = 1, b) {
|
|
b--;
|
|
} else {
|
|
let n = (r + (m < k - 1 ? d || 0 : 0)) / (m + 1) | 0;
|
|
(f[n] || (f[n] = [])).push(h);
|
|
if (++u === c) {
|
|
return f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return f;
|
|
}
|
|
function eb(a, c, b) {
|
|
const e = I(), d = [];
|
|
for (let f = 0, g; f < c.length; f++) {
|
|
g = c[f];
|
|
for (let h = 0; h < g.length; h++) {
|
|
e[g[h]] = 1;
|
|
}
|
|
}
|
|
if (b) {
|
|
for (let f = 0, g; f < a.length; f++) {
|
|
g = a[f], e[g] && (d.push(g), e[g] = 0);
|
|
}
|
|
} else {
|
|
for (let f = 0, g, h; f < a.result.length; f++) {
|
|
for (g = a.result[f], c = 0; c < g.length; c++) {
|
|
h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0);
|
|
}
|
|
}
|
|
}
|
|
return d;
|
|
}
|
|
;I();
|
|
Na.prototype.search = function(a, c, b, e) {
|
|
b || (!c && ba(a) ? (b = a, a = "") : ba(c) && (b = c, c = 0));
|
|
let d = [];
|
|
var f = [];
|
|
let g;
|
|
let h, k, l, m, p;
|
|
let u = 0, r = !0, t;
|
|
if (b) {
|
|
b.constructor === Array && (b = {index:b});
|
|
a = b.query || a;
|
|
g = b.pluck;
|
|
h = b.merge;
|
|
l = b.boost;
|
|
p = g || b.field || (p = b.index) && (p.index ? null : p);
|
|
var n = this.tag && b.tag;
|
|
k = b.suggest;
|
|
r = b.resolve !== !1;
|
|
m = b.cache;
|
|
this.store && b.highlight && !r ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !r && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })");
|
|
t = r && this.store && b.highlight;
|
|
var q = !!t || r && this.store && b.enrich;
|
|
c = b.limit || c;
|
|
var x = b.offset || 0;
|
|
c || (c = r ? 100 : 0);
|
|
if (n && (!this.db || !e)) {
|
|
n.constructor !== Array && (n = [n]);
|
|
var v = [];
|
|
for (let B = 0, z; B < n.length; B++) {
|
|
z = n[B];
|
|
if (N(z)) {
|
|
throw Error("A tag option can't be a string, instead it needs a { field: tag } format.");
|
|
}
|
|
if (z.field && z.tag) {
|
|
var A = z.tag;
|
|
if (A.constructor === Array) {
|
|
for (var D = 0; D < A.length; D++) {
|
|
v.push(z.field, A[D]);
|
|
}
|
|
} else {
|
|
v.push(z.field, A);
|
|
}
|
|
} else {
|
|
A = Object.keys(z);
|
|
for (let C = 0, K, F; C < A.length; C++) {
|
|
if (K = A[C], F = z[K], F.constructor === Array) {
|
|
for (D = 0; D < F.length; D++) {
|
|
v.push(K, F[D]);
|
|
}
|
|
} else {
|
|
v.push(K, F);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!v.length) {
|
|
throw Error("Your tag definition within the search options is probably wrong. No valid tags found.");
|
|
}
|
|
n = v;
|
|
if (!a) {
|
|
f = [];
|
|
if (v.length) {
|
|
for (n = 0; n < v.length; n += 2) {
|
|
if (this.db) {
|
|
e = this.index.get(v[n]);
|
|
if (!e) {
|
|
console.warn("Tag '" + v[n] + ":" + v[n + 1] + "' will be skipped because there is no field '" + v[n] + "'.");
|
|
continue;
|
|
}
|
|
f.push(e = e.db.tag(v[n + 1], c, x, q));
|
|
} else {
|
|
e = fb.call(this, v[n], v[n + 1], c, x, q);
|
|
}
|
|
d.push(r ? {field:v[n], tag:v[n + 1], result:e} : [e]);
|
|
}
|
|
}
|
|
if (f.length) {
|
|
const B = this;
|
|
return Promise.all(f).then(function(z) {
|
|
for (let C = 0; C < z.length; C++) {
|
|
r ? d[C].result = z[C] : d[C] = z[C];
|
|
}
|
|
return r ? d : new X(d.length > 1 ? $a(d, 1, 0, 0, k, l) : d[0], B);
|
|
});
|
|
}
|
|
return r ? d : new X(d.length > 1 ? $a(d, 1, 0, 0, k, l) : d[0], this);
|
|
}
|
|
}
|
|
if (!r && !g) {
|
|
if (p = p || this.field) {
|
|
N(p) ? g = p : (p.constructor === Array && p.length === 1 && (p = p[0]), g = p.field || p.index);
|
|
}
|
|
if (!g) {
|
|
throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query.");
|
|
}
|
|
}
|
|
p && p.constructor !== Array && (p = [p]);
|
|
}
|
|
p || (p = this.field);
|
|
let G;
|
|
v = (this.worker || this.db) && !e && [];
|
|
for (let B = 0, z, C, K; B < p.length; B++) {
|
|
C = p[B];
|
|
if (this.db && this.tag && !this.B[B]) {
|
|
continue;
|
|
}
|
|
let F;
|
|
N(C) || (F = C, C = F.field, a = F.query || a, c = aa(F.limit, c), x = aa(F.offset, x), k = aa(F.suggest, k), t = r && this.store && aa(F.highlight, t), q = !!t || r && this.store && aa(F.enrich, q), m = aa(F.cache, m));
|
|
if (e) {
|
|
z = e[B];
|
|
} else {
|
|
A = F || b || {};
|
|
D = A.enrich;
|
|
var E = this.index.get(C);
|
|
n && (this.db && (A.tag = n, G = E.db.support_tag_search, A.field = p), !G && D && (A.enrich = !1));
|
|
z = m ? E.searchCache(a, c, A) : E.search(a, c, A);
|
|
D && (A.enrich = D);
|
|
if (v) {
|
|
v[B] = z;
|
|
continue;
|
|
}
|
|
}
|
|
K = (z = z.result || z) && z.length;
|
|
if (n && K) {
|
|
A = [];
|
|
D = 0;
|
|
if (this.db && e) {
|
|
if (!G) {
|
|
for (E = p.length; E < e.length; E++) {
|
|
let L = e[E];
|
|
if (L && L.length) {
|
|
D++, A.push(L);
|
|
} else if (!k) {
|
|
return r ? d : new X(d, this);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for (let L = 0, O, P; L < n.length; L += 2) {
|
|
O = this.tag.get(n[L]);
|
|
if (!O) {
|
|
if (console.warn("Tag '" + n[L] + ":" + n[L + 1] + "' will be skipped because there is no field '" + n[L] + "'."), k) {
|
|
continue;
|
|
} else {
|
|
return r ? d : new X(d, this);
|
|
}
|
|
}
|
|
if (P = (O = O && O.get(n[L + 1])) && O.length) {
|
|
D++, A.push(O);
|
|
} else if (!k) {
|
|
return r ? d : new X(d, this);
|
|
}
|
|
}
|
|
}
|
|
if (D) {
|
|
z = eb(z, A, r);
|
|
K = z.length;
|
|
if (!K && !k) {
|
|
return r ? z : new X(z, this);
|
|
}
|
|
D--;
|
|
}
|
|
}
|
|
if (K) {
|
|
f[u] = C, d.push(z), u++;
|
|
} else if (p.length === 1) {
|
|
return r ? d : new X(d, this);
|
|
}
|
|
}
|
|
if (v) {
|
|
if (this.db && n && n.length && !G) {
|
|
for (q = 0; q < n.length; q += 2) {
|
|
f = this.index.get(n[q]);
|
|
if (!f) {
|
|
if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), k) {
|
|
continue;
|
|
} else {
|
|
return r ? d : new X(d, this);
|
|
}
|
|
}
|
|
v.push(f.db.tag(n[q + 1], c, x, !1));
|
|
}
|
|
}
|
|
const B = this;
|
|
return Promise.all(v).then(function(z) {
|
|
b && (b.resolve = r);
|
|
z.length && (z = B.search(a, c, b, z));
|
|
return z;
|
|
});
|
|
}
|
|
if (!u) {
|
|
return r ? d : new X(d, this);
|
|
}
|
|
if (g && (!q || !this.store)) {
|
|
return d = d[0], r ? d : new X(d, this);
|
|
}
|
|
v = [];
|
|
for (x = 0; x < f.length; x++) {
|
|
n = d[x];
|
|
q && n.length && typeof n[0].doc === "undefined" && (this.db ? v.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = Ta.call(this, n));
|
|
if (g) {
|
|
return r ? t ? cb(a, n, this.index, g, t) : n : new X(n, this);
|
|
}
|
|
d[x] = {field:f[x], result:n};
|
|
}
|
|
if (q && this.db && v.length) {
|
|
const B = this;
|
|
return Promise.all(v).then(function(z) {
|
|
for (let C = 0; C < z.length; C++) {
|
|
d[C].result = z[C];
|
|
}
|
|
t && (d = cb(a, d, B.index, g, t));
|
|
return h ? gb(d) : d;
|
|
});
|
|
}
|
|
t && (d = cb(a, d, this.index, g, t));
|
|
return h ? gb(d) : d;
|
|
};
|
|
function gb(a) {
|
|
const c = [], b = I(), e = I();
|
|
for (let d = 0, f, g, h, k, l, m, p; d < a.length; d++) {
|
|
f = a[d];
|
|
g = f.field;
|
|
h = f.result;
|
|
for (let u = 0; u < h.length; u++) {
|
|
if (l = h[u], typeof l !== "object" ? l = {id:k = l} : k = l.id, (m = b[k]) ? m.push(g) : (l.field = b[k] = [g], c.push(l)), p = l.highlight) {
|
|
m = e[k], m || (e[k] = m = {}, l.highlight = m), m[g] = p;
|
|
}
|
|
}
|
|
}
|
|
return c;
|
|
}
|
|
function fb(a, c, b, e, d) {
|
|
a = this.tag.get(a);
|
|
if (!a) {
|
|
return [];
|
|
}
|
|
a = a.get(c);
|
|
if (!a) {
|
|
return [];
|
|
}
|
|
c = a.length - e;
|
|
if (c > 0) {
|
|
if (b && c > b || e) {
|
|
a = a.slice(e, e + b);
|
|
}
|
|
d && (a = Ta.call(this, a));
|
|
}
|
|
return a;
|
|
}
|
|
function Ta(a) {
|
|
if (!this || !this.store) {
|
|
return a;
|
|
}
|
|
if (this.db) {
|
|
return this.index.get(this.field[0]).db.enrich(a);
|
|
}
|
|
const c = Array(a.length);
|
|
for (let b = 0, e; b < a.length; b++) {
|
|
e = a[b], c[b] = {id:e, doc:this.store.get(e)};
|
|
}
|
|
return c;
|
|
}
|
|
;function Na(a) {
|
|
if (!this || this.constructor !== Na) {
|
|
return new Na(a);
|
|
}
|
|
const c = a.document || a.doc || a;
|
|
let b, e;
|
|
this.B = [];
|
|
this.field = [];
|
|
this.D = [];
|
|
this.key = (b = c.key || c.id) && hb(b, this.D) || "id";
|
|
(e = a.keystore || 0) && (this.keystore = e);
|
|
this.fastupdate = !!a.fastupdate;
|
|
this.reg = !this.fastupdate || a.worker || a.db ? e ? new R(e) : new Set() : e ? new Q(e) : new Map();
|
|
this.h = (b = c.store || null) && b && b !== !0 && [];
|
|
this.store = b ? e ? new Q(e) : new Map() : null;
|
|
this.cache = (b = a.cache || null) && new na(b);
|
|
a.cache = !1;
|
|
this.worker = a.worker || !1;
|
|
this.priority = a.priority || 4;
|
|
this.index = ib.call(this, a, c);
|
|
this.tag = null;
|
|
if (b = c.tag) {
|
|
if (typeof b === "string" && (b = [b]), b.length) {
|
|
this.tag = new Map();
|
|
this.A = [];
|
|
this.F = [];
|
|
for (let d = 0, f, g; d < b.length; d++) {
|
|
f = b[d];
|
|
g = f.field || f;
|
|
if (!g) {
|
|
throw Error("The tag field from the document descriptor is undefined.");
|
|
}
|
|
f.custom ? this.A[d] = f.custom : (this.A[d] = hb(g, this.D), f.filter && (typeof this.A[d] === "string" && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter));
|
|
this.F[d] = g;
|
|
this.tag.set(g, new Map());
|
|
}
|
|
}
|
|
}
|
|
if (this.worker) {
|
|
this.fastupdate = !1;
|
|
a = [];
|
|
for (const d of this.index.values()) {
|
|
d.then && a.push(d);
|
|
}
|
|
if (a.length) {
|
|
const d = this;
|
|
return Promise.all(a).then(function(f) {
|
|
let g = 0;
|
|
for (const h of d.index.entries()) {
|
|
const k = h[0];
|
|
let l = h[1];
|
|
l.then && (l = f[g], d.index.set(k, l), g++);
|
|
}
|
|
return d;
|
|
});
|
|
}
|
|
} else {
|
|
a.db && (this.fastupdate = !1, this.mount(a.db));
|
|
}
|
|
}
|
|
w = Na.prototype;
|
|
w.mount = function(a) {
|
|
if (this.worker) {
|
|
throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave).");
|
|
}
|
|
let c = this.field;
|
|
if (this.tag) {
|
|
for (let f = 0, g; f < this.F.length; f++) {
|
|
g = this.F[f];
|
|
var b = void 0;
|
|
this.index.set(g, b = new T({}, this.reg));
|
|
c === this.field && (c = c.slice(0));
|
|
c.push(g);
|
|
b.tag = this.tag.get(g);
|
|
}
|
|
}
|
|
b = [];
|
|
const e = {db:a.db, type:a.type, fastupdate:a.fastupdate};
|
|
for (let f = 0, g, h; f < c.length; f++) {
|
|
e.field = h = c[f];
|
|
g = this.index.get(h);
|
|
const k = new a.constructor(a.id, e);
|
|
k.id = a.id;
|
|
b[f] = k.mount(g);
|
|
g.document = !0;
|
|
f ? g.bypass = !0 : g.store = this.store;
|
|
}
|
|
const d = this;
|
|
return this.db = Promise.all(b).then(function() {
|
|
d.db = !0;
|
|
});
|
|
};
|
|
w.commit = async function() {
|
|
const a = [];
|
|
for (const c of this.index.values()) {
|
|
a.push(c.commit());
|
|
}
|
|
await Promise.all(a);
|
|
this.reg.clear();
|
|
};
|
|
w.destroy = function() {
|
|
const a = [];
|
|
for (const c of this.index.values()) {
|
|
a.push(c.destroy());
|
|
}
|
|
return Promise.all(a);
|
|
};
|
|
function ib(a, c) {
|
|
const b = new Map();
|
|
let e = c.index || c.field || c;
|
|
N(e) && (e = [e]);
|
|
for (let f = 0, g, h; f < e.length; f++) {
|
|
g = e[f];
|
|
N(g) || (h = g, g = g.field);
|
|
h = ba(h) ? Object.assign({}, a, h) : a;
|
|
if (this.worker) {
|
|
var d = void 0;
|
|
d = (d = h.encoder) && d.encode ? d : new ka(typeof d === "string" ? wa[d] : d || {});
|
|
d = new La(h, d);
|
|
b.set(g, d);
|
|
}
|
|
this.worker || b.set(g, new T(h, this.reg));
|
|
h.custom ? this.B[f] = h.custom : (this.B[f] = hb(g, this.D), h.filter && (typeof this.B[f] === "string" && (this.B[f] = new String(this.B[f])), this.B[f].G = h.filter));
|
|
this.field[f] = g;
|
|
}
|
|
if (this.h) {
|
|
a = c.store;
|
|
N(a) && (a = [a]);
|
|
for (let f = 0, g, h; f < a.length; f++) {
|
|
g = a[f], h = g.field || g, g.custom ? (this.h[f] = g.custom, g.custom.O = h) : (this.h[f] = hb(h, this.D), g.filter && (typeof this.h[f] === "string" && (this.h[f] = new String(this.h[f])), this.h[f].G = g.filter));
|
|
}
|
|
}
|
|
return b;
|
|
}
|
|
function hb(a, c) {
|
|
const b = a.split(":");
|
|
let e = 0;
|
|
for (let d = 0; d < b.length; d++) {
|
|
a = b[d], a[a.length - 1] === "]" && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a);
|
|
}
|
|
e < b.length && (b.length = e);
|
|
return e > 1 ? b : b[0];
|
|
}
|
|
w.append = function(a, c) {
|
|
return this.add(a, c, !0);
|
|
};
|
|
w.update = function(a, c) {
|
|
return this.remove(a).add(a, c);
|
|
};
|
|
w.remove = function(a) {
|
|
ba(a) && (a = ca(a, this.key));
|
|
for (var c of this.index.values()) {
|
|
c.remove(a, !0);
|
|
}
|
|
if (this.reg.has(a)) {
|
|
if (this.tag && !this.fastupdate) {
|
|
for (let b of this.tag.values()) {
|
|
for (let e of b) {
|
|
c = e[0];
|
|
const d = e[1], f = d.indexOf(a);
|
|
f > -1 && (d.length > 1 ? d.splice(f, 1) : b.delete(c));
|
|
}
|
|
}
|
|
}
|
|
this.store && this.store.delete(a);
|
|
this.reg.delete(a);
|
|
}
|
|
this.cache && this.cache.remove(a);
|
|
return this;
|
|
};
|
|
w.clear = function() {
|
|
const a = [];
|
|
for (const c of this.index.values()) {
|
|
const b = c.clear();
|
|
b.then && a.push(b);
|
|
}
|
|
if (this.tag) {
|
|
for (const c of this.tag.values()) {
|
|
c.clear();
|
|
}
|
|
}
|
|
this.store && this.store.clear();
|
|
this.cache && this.cache.clear();
|
|
return a.length ? Promise.all(a) : this;
|
|
};
|
|
w.contain = function(a) {
|
|
return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a);
|
|
};
|
|
w.cleanup = function() {
|
|
for (const a of this.index.values()) {
|
|
a.cleanup();
|
|
}
|
|
return this;
|
|
};
|
|
w.get = function(a) {
|
|
return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(c) {
|
|
return c[0] && c[0].doc || null;
|
|
}) : this.store.get(a) || null;
|
|
};
|
|
w.set = function(a, c) {
|
|
typeof a === "object" && (c = a, a = ca(c, this.key));
|
|
this.store.set(a, c);
|
|
return this;
|
|
};
|
|
w.searchCache = ma;
|
|
w.export = jb;
|
|
w.import = kb;
|
|
Fa(Na.prototype);
|
|
function lb(a, c = 0) {
|
|
let b = [], e = [];
|
|
c && (c = 250000 / c * 5000 | 0);
|
|
for (const d of a.entries()) {
|
|
e.push(d), e.length === c && (b.push(e), e = []);
|
|
}
|
|
e.length && b.push(e);
|
|
return b;
|
|
}
|
|
function mb(a, c) {
|
|
c || (c = new Map());
|
|
for (let b = 0, e; b < a.length; b++) {
|
|
e = a[b], c.set(e[0], e[1]);
|
|
}
|
|
return c;
|
|
}
|
|
function nb(a, c = 0) {
|
|
let b = [], e = [];
|
|
c && (c = 250000 / c * 1000 | 0);
|
|
for (const d of a.entries()) {
|
|
e.push([d[0], lb(d[1])[0]]), e.length === c && (b.push(e), e = []);
|
|
}
|
|
e.length && b.push(e);
|
|
return b;
|
|
}
|
|
function ob(a, c) {
|
|
c || (c = new Map());
|
|
for (let b = 0, e, d; b < a.length; b++) {
|
|
e = a[b], d = c.get(e[0]), c.set(e[0], mb(e[1], d));
|
|
}
|
|
return c;
|
|
}
|
|
function pb(a) {
|
|
let c = [], b = [];
|
|
for (const e of a.keys()) {
|
|
b.push(e), b.length === 250000 && (c.push(b), b = []);
|
|
}
|
|
b.length && c.push(b);
|
|
return c;
|
|
}
|
|
function qb(a, c) {
|
|
c || (c = new Set());
|
|
for (let b = 0; b < a.length; b++) {
|
|
c.add(a[b]);
|
|
}
|
|
return c;
|
|
}
|
|
function rb(a, c, b, e, d, f, g = 0) {
|
|
const h = e && e.constructor === Array;
|
|
var k = h ? e.shift() : e;
|
|
if (!k) {
|
|
return this.export(a, c, d, f + 1);
|
|
}
|
|
if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) {
|
|
const l = this;
|
|
return k.then(function() {
|
|
return rb.call(l, a, c, b, h ? e : null, d, f, g + 1);
|
|
});
|
|
}
|
|
return rb.call(this, a, c, b, h ? e : null, d, f, g + 1);
|
|
}
|
|
function jb(a, c, b = 0, e = 0) {
|
|
if (b < this.field.length) {
|
|
const g = this.field[b];
|
|
if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) {
|
|
const h = this;
|
|
return c.then(function() {
|
|
return h.export(a, g, b + 1);
|
|
});
|
|
}
|
|
return this.export(a, g, b + 1);
|
|
}
|
|
let d, f;
|
|
switch(e) {
|
|
case 0:
|
|
d = "reg";
|
|
f = pb(this.reg);
|
|
c = null;
|
|
break;
|
|
case 1:
|
|
d = "tag";
|
|
f = this.tag && nb(this.tag, this.reg.size);
|
|
c = null;
|
|
break;
|
|
case 2:
|
|
d = "doc";
|
|
f = this.store && lb(this.store);
|
|
c = null;
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
return rb.call(this, a, c, d, f || null, b, e);
|
|
}
|
|
function kb(a, c) {
|
|
var b = a.split(".");
|
|
b[b.length - 1] === "json" && b.pop();
|
|
const e = b.length > 2 ? b[0] : "";
|
|
b = b.length > 2 ? b[2] : b[1];
|
|
if (this.worker && e) {
|
|
return this.index.get(e).import(a);
|
|
}
|
|
if (c) {
|
|
typeof c === "string" && (c = JSON.parse(c));
|
|
if (e) {
|
|
return this.index.get(e).import(b, c);
|
|
}
|
|
switch(b) {
|
|
case "reg":
|
|
this.fastupdate = !1;
|
|
this.reg = qb(c, this.reg);
|
|
for (let d = 0, f; d < this.field.length; d++) {
|
|
f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg;
|
|
}
|
|
if (this.worker) {
|
|
c = [];
|
|
for (const d of this.index.values()) {
|
|
c.push(d.import(a));
|
|
}
|
|
return Promise.all(c);
|
|
}
|
|
break;
|
|
case "tag":
|
|
this.tag = ob(c, this.tag);
|
|
break;
|
|
case "doc":
|
|
this.store = mb(c, this.store);
|
|
}
|
|
}
|
|
}
|
|
function sb(a, c) {
|
|
let b = "";
|
|
for (const e of a.entries()) {
|
|
a = e[0];
|
|
const d = e[1];
|
|
let f = "";
|
|
for (let g = 0, h; g < d.length; g++) {
|
|
h = d[g] || [""];
|
|
let k = "";
|
|
for (let l = 0; l < h.length; l++) {
|
|
k += (k ? "," : "") + (c === "string" ? '"' + h[l] + '"' : h[l]);
|
|
}
|
|
k = "[" + k + "]";
|
|
f += (f ? "," : "") + k;
|
|
}
|
|
f = '["' + a + '",[' + f + "]]";
|
|
b += (b ? "," : "") + f;
|
|
}
|
|
return b;
|
|
}
|
|
;T.prototype.remove = function(a, c) {
|
|
const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a));
|
|
if (b) {
|
|
if (this.fastupdate) {
|
|
for (let e = 0, d, f; e < b.length; e++) {
|
|
if ((d = b[e]) && (f = d.length)) {
|
|
if (d[f - 1] === a) {
|
|
d.pop();
|
|
} else {
|
|
const g = d.indexOf(a);
|
|
g >= 0 && d.splice(g, 1);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
tb(this.map, a), this.depth && tb(this.ctx, a);
|
|
}
|
|
c || this.reg.delete(a);
|
|
}
|
|
this.db && (this.commit_task.push({del:a}), this.M && ub(this));
|
|
this.cache && this.cache.remove(a);
|
|
return this;
|
|
};
|
|
function tb(a, c) {
|
|
let b = 0;
|
|
var e = typeof c === "undefined";
|
|
if (a.constructor === Array) {
|
|
for (let d = 0, f, g, h; d < a.length; d++) {
|
|
if ((f = a[d]) && f.length) {
|
|
if (e) {
|
|
return 1;
|
|
}
|
|
g = f.indexOf(c);
|
|
if (g >= 0) {
|
|
if (f.length > 1) {
|
|
return f.splice(g, 1), 1;
|
|
}
|
|
delete a[d];
|
|
if (b) {
|
|
return 1;
|
|
}
|
|
h = 1;
|
|
} else {
|
|
if (h) {
|
|
return 1;
|
|
}
|
|
b++;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for (let d of a.entries()) {
|
|
e = d[0], tb(d[1], c) ? b++ : a.delete(e);
|
|
}
|
|
}
|
|
return b;
|
|
}
|
|
;const vb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}};
|
|
T.prototype.add = function(a, c, b, e) {
|
|
if (c && (a || a === 0)) {
|
|
if (!e && !b && this.reg.has(a)) {
|
|
return this.update(a, c);
|
|
}
|
|
e = this.depth;
|
|
c = this.encoder.encode(c, !e);
|
|
const l = c.length;
|
|
if (l) {
|
|
const m = I(), p = I(), u = this.resolution;
|
|
for (let r = 0; r < l; r++) {
|
|
let t = c[this.rtl ? l - 1 - r : r];
|
|
var d = t.length;
|
|
if (d && (e || !p[t])) {
|
|
var f = this.score ? this.score(c, t, r, null, 0) : wb(u, l, r), g = "";
|
|
switch(this.tokenize) {
|
|
case "tolerant":
|
|
Y(this, p, t, f, a, b);
|
|
if (d > 2) {
|
|
for (let n = 1, q, x, v, A; n < d - 1; n++) {
|
|
q = t.charAt(n), x = t.charAt(n + 1), v = t.substring(0, n) + x, A = t.substring(n + 2), g = v + q + A, Y(this, p, g, f, a, b), g = v + A, Y(this, p, g, f, a, b);
|
|
}
|
|
Y(this, p, t.substring(0, t.length - 1), f, a, b);
|
|
}
|
|
break;
|
|
case "full":
|
|
if (d > 2) {
|
|
for (let n = 0, q; n < d; n++) {
|
|
for (f = d; f > n; f--) {
|
|
g = t.substring(n, f);
|
|
q = this.rtl ? d - 1 - n : n;
|
|
var h = this.score ? this.score(c, t, r, g, q) : wb(u, l, r, d, q);
|
|
Y(this, p, g, h, a, b);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case "bidirectional":
|
|
case "reverse":
|
|
if (d > 1) {
|
|
for (h = d - 1; h > 0; h--) {
|
|
g = t[this.rtl ? d - 1 - h : h] + g;
|
|
var k = this.score ? this.score(c, t, r, g, h) : wb(u, l, r, d, h);
|
|
Y(this, p, g, k, a, b);
|
|
}
|
|
g = "";
|
|
}
|
|
case "forward":
|
|
if (d > 1) {
|
|
for (h = 0; h < d; h++) {
|
|
g += t[this.rtl ? d - 1 - h : h], Y(this, p, g, f, a, b);
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
if (Y(this, p, t, f, a, b), e && l > 1 && r < l - 1) {
|
|
for (d = this.N, g = t, f = Math.min(e + 1, this.rtl ? r + 1 : l - r), h = 1; h < f; h++) {
|
|
t = c[this.rtl ? l - 1 - r - h : r + h];
|
|
k = this.bidirectional && t > g;
|
|
const n = this.score ? this.score(c, g, r, t, h - 1) : wb(d + (l / 2 > d ? 0 : 1), l, r, f - 1, h - 1);
|
|
Y(this, m, k ? g : t, n, a, b, k ? t : g);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.fastupdate || this.reg.add(a);
|
|
}
|
|
}
|
|
this.db && (this.commit_task.push(b ? {ins:a} : {del:a}), this.M && ub(this));
|
|
return this;
|
|
};
|
|
function Y(a, c, b, e, d, f, g) {
|
|
let h, k;
|
|
if (!(h = c[b]) || g && !h[g]) {
|
|
g ? (c = h || (c[b] = I()), c[g] = 1, k = a.ctx, (h = k.get(g)) ? k = h : k.set(g, k = a.keystore ? new Q(a.keystore) : new Map())) : (k = a.map, c[b] = 1);
|
|
(h = k.get(b)) ? k = h : k.set(b, k = h = []);
|
|
if (f) {
|
|
for (let l = 0, m; l < h.length; l++) {
|
|
if ((m = h[l]) && m.includes(d)) {
|
|
if (l <= e) {
|
|
return;
|
|
}
|
|
m.splice(m.indexOf(d), 1);
|
|
a.fastupdate && (c = a.reg.get(d)) && c.splice(c.indexOf(m), 1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
k = k[e] || (k[e] = []);
|
|
k.push(d);
|
|
if (k.length === 2 ** 31 - 1) {
|
|
c = new Aa(k);
|
|
if (a.fastupdate) {
|
|
for (let l of a.reg.values()) {
|
|
l.includes(k) && (l[l.indexOf(k)] = c);
|
|
}
|
|
}
|
|
h[e] = k = c;
|
|
}
|
|
a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k]));
|
|
}
|
|
}
|
|
function wb(a, c, b, e, d) {
|
|
return b && a > 1 ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0;
|
|
}
|
|
;T.prototype.search = function(a, c, b) {
|
|
b || (c || typeof a !== "object" ? typeof c === "object" && (b = c, c = 0) : (b = a, a = ""));
|
|
if (b && b.cache) {
|
|
return b.cache = !1, a = this.searchCache(a, c, b), b.cache = !0, a;
|
|
}
|
|
let e = [], d, f, g, h = 0, k, l, m, p, u;
|
|
b && (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, u = (k = b.resolve) && b.enrich, m = b.boost, p = b.resolution, l = this.db && b.tag);
|
|
typeof k === "undefined" && (k = this.resolve);
|
|
f = this.depth && f !== !1;
|
|
let r = this.encoder.encode(a, !f);
|
|
d = r.length;
|
|
c = c || (k ? 100 : 0);
|
|
if (d === 1) {
|
|
return xb.call(this, r[0], "", c, h, k, u, l);
|
|
}
|
|
if (d === 2 && f && !g) {
|
|
return xb.call(this, r[1], r[0], c, h, k, u, l);
|
|
}
|
|
let t = I(), n = 0, q;
|
|
f && (q = r[0], n = 1);
|
|
p || p === 0 || (p = q ? this.N : this.resolution);
|
|
if (this.db) {
|
|
if (this.db.search && (b = this.db.search(this, r, c, h, g, k, u, l), b !== !1)) {
|
|
return b;
|
|
}
|
|
const x = this;
|
|
return async function() {
|
|
for (let v, A; n < d; n++) {
|
|
if ((A = r[n]) && !t[A]) {
|
|
t[A] = 1;
|
|
v = await yb(x, A, q, 0, 0, !1, !1);
|
|
if (v = zb(v, e, g, p)) {
|
|
e = v;
|
|
break;
|
|
}
|
|
q && (g && v && e.length || (q = A));
|
|
}
|
|
g && q && n === d - 1 && !e.length && (p = x.resolution, q = "", n = -1, t = I());
|
|
}
|
|
return Ab(e, p, c, h, g, m, k);
|
|
}();
|
|
}
|
|
for (let x, v; n < d; n++) {
|
|
if ((v = r[n]) && !t[v]) {
|
|
t[v] = 1;
|
|
x = yb(this, v, q, 0, 0, !1, !1);
|
|
if (x = zb(x, e, g, p)) {
|
|
e = x;
|
|
break;
|
|
}
|
|
q && (g && x && e.length || (q = v));
|
|
}
|
|
g && q && n === d - 1 && !e.length && (p = this.resolution, q = "", n = -1, t = I());
|
|
}
|
|
return Ab(e, p, c, h, g, m, k);
|
|
};
|
|
function Ab(a, c, b, e, d, f, g) {
|
|
let h = a.length, k = a;
|
|
if (h > 1) {
|
|
k = $a(a, c, b, e, d, f, g);
|
|
} else if (h === 1) {
|
|
return g ? Sa.call(null, a[0], b, e) : new X(a[0], this);
|
|
}
|
|
return g ? k : new X(k, this);
|
|
}
|
|
function xb(a, c, b, e, d, f, g) {
|
|
a = yb(this, a, c, b, e, d, f, g);
|
|
return this.db ? a.then(function(h) {
|
|
return d ? h || [] : new X(h, this);
|
|
}) : a && a.length ? d ? Sa.call(this, a, b, e) : new X(a, this) : d ? [] : new X([], this);
|
|
}
|
|
function zb(a, c, b, e) {
|
|
let d = [];
|
|
if (a && a.length) {
|
|
if (a.length <= e) {
|
|
c.push(a);
|
|
return;
|
|
}
|
|
for (let f = 0, g; f < e; f++) {
|
|
if (g = a[f]) {
|
|
d[f] = g;
|
|
}
|
|
}
|
|
if (d.length) {
|
|
c.push(d);
|
|
return;
|
|
}
|
|
}
|
|
if (!b) {
|
|
return d;
|
|
}
|
|
}
|
|
function yb(a, c, b, e, d, f, g, h) {
|
|
let k;
|
|
b && (k = a.bidirectional && c > b) && (k = b, b = c, c = k);
|
|
if (a.db) {
|
|
return a.db.get(c, b, e, d, f, g, h);
|
|
}
|
|
a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c);
|
|
return a;
|
|
}
|
|
;function T(a, c) {
|
|
if (!this || this.constructor !== T) {
|
|
return new T(a);
|
|
}
|
|
if (a) {
|
|
var b = N(a) ? a : a.preset;
|
|
b && (vb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, vb[b], a));
|
|
} else {
|
|
a = {};
|
|
}
|
|
b = a.context;
|
|
const e = b === !0 ? {depth:1} : b || {}, d = N(a.encoder) ? wa[a.encoder] : a.encode || a.encoder || {};
|
|
this.encoder = d.encode ? d : typeof d === "object" ? new ka(d) : {encode:d};
|
|
this.resolution = a.resolution || 9;
|
|
this.tokenize = b = (b = a.tokenize) && b !== "default" && b !== "exact" && b || "strict";
|
|
this.depth = b === "strict" && e.depth || 0;
|
|
this.bidirectional = e.bidirectional !== !1;
|
|
this.fastupdate = !!a.fastupdate;
|
|
this.score = a.score || null;
|
|
e && e.depth && this.tokenize !== "strict" && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".');
|
|
(b = a.keystore || 0) && (this.keystore = b);
|
|
this.map = b ? new Q(b) : new Map();
|
|
this.ctx = b ? new Q(b) : new Map();
|
|
this.reg = c || (this.fastupdate ? b ? new Q(b) : new Map() : b ? new R(b) : new Set());
|
|
this.N = e.resolution || 3;
|
|
this.rtl = d.rtl || a.rtl || !1;
|
|
this.cache = (b = a.cache || null) && new na(b);
|
|
this.resolve = a.resolve !== !1;
|
|
if (b = a.db) {
|
|
this.db = this.mount(b);
|
|
}
|
|
this.M = a.commit !== !1;
|
|
this.commit_task = [];
|
|
this.commit_timer = null;
|
|
this.priority = a.priority || 4;
|
|
}
|
|
w = T.prototype;
|
|
w.mount = function(a) {
|
|
this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
|
|
return a.mount(this);
|
|
};
|
|
w.commit = function() {
|
|
this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
|
|
return this.db.commit(this);
|
|
};
|
|
w.destroy = function() {
|
|
this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null);
|
|
return this.db.destroy();
|
|
};
|
|
function ub(a) {
|
|
a.commit_timer || (a.commit_timer = setTimeout(function() {
|
|
a.commit_timer = null;
|
|
a.db.commit(a);
|
|
}, 1));
|
|
}
|
|
w.clear = function() {
|
|
this.map.clear();
|
|
this.ctx.clear();
|
|
this.reg.clear();
|
|
this.cache && this.cache.clear();
|
|
return this.db ? (this.commit_timer && clearTimeout(this.commit_timer), this.commit_timer = null, this.commit_task = [], this.db.clear()) : this;
|
|
};
|
|
w.append = function(a, c) {
|
|
return this.add(a, c, !0);
|
|
};
|
|
w.contain = function(a) {
|
|
return this.db ? this.db.has(a) : this.reg.has(a);
|
|
};
|
|
w.update = function(a, c) {
|
|
const b = this, e = this.remove(a);
|
|
return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c);
|
|
};
|
|
w.cleanup = function() {
|
|
if (!this.fastupdate) {
|
|
return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this;
|
|
}
|
|
tb(this.map);
|
|
this.depth && tb(this.ctx);
|
|
return this;
|
|
};
|
|
w.searchCache = ma;
|
|
w.export = function(a, c, b = 0, e = 0) {
|
|
let d, f;
|
|
switch(e) {
|
|
case 0:
|
|
d = "reg";
|
|
f = pb(this.reg);
|
|
break;
|
|
case 1:
|
|
d = "cfg";
|
|
f = null;
|
|
break;
|
|
case 2:
|
|
d = "map";
|
|
f = lb(this.map, this.reg.size);
|
|
break;
|
|
case 3:
|
|
d = "ctx";
|
|
f = nb(this.ctx, this.reg.size);
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
return rb.call(this, a, c, d, f, b, e);
|
|
};
|
|
w.import = function(a, c) {
|
|
if (c) {
|
|
switch(typeof c === "string" && (c = JSON.parse(c)), a = a.split("."), a[a.length - 1] === "json" && a.pop(), a.length === 3 && a.shift(), a = a.length > 1 ? a[1] : a[0], a) {
|
|
case "reg":
|
|
this.fastupdate = !1;
|
|
this.reg = qb(c, this.reg);
|
|
break;
|
|
case "map":
|
|
this.map = mb(c, this.map);
|
|
break;
|
|
case "ctx":
|
|
this.ctx = ob(c, this.ctx);
|
|
}
|
|
}
|
|
};
|
|
w.serialize = function(a = !0) {
|
|
let c = "", b = "", e = "";
|
|
if (this.reg.size) {
|
|
let f;
|
|
for (var d of this.reg.keys()) {
|
|
f || (f = typeof d), c += (c ? "," : "") + (f === "string" ? '"' + d + '"' : d);
|
|
}
|
|
c = "index.reg=new Set([" + c + "]);";
|
|
b = sb(this.map, f);
|
|
b = "index.map=new Map([" + b + "]);";
|
|
for (const g of this.ctx.entries()) {
|
|
d = g[0];
|
|
let h = sb(g[1], f);
|
|
h = "new Map([" + h + "])";
|
|
h = '["' + d + '",' + h + "]";
|
|
e += (e ? "," : "") + h;
|
|
}
|
|
e = "index.ctx=new Map([" + e + "]);";
|
|
}
|
|
return a ? "function inject(index){" + c + b + e + "}" : c + b + e;
|
|
};
|
|
Fa(T.prototype);
|
|
const Bb = typeof window !== "undefined" && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Cb = ["map", "ctx", "tag", "reg", "cfg"], Db = I();
|
|
function Eb(a, c = {}) {
|
|
if (!this || this.constructor !== Eb) {
|
|
return new Eb(a, c);
|
|
}
|
|
typeof a === "object" && (c = a, a = a.name);
|
|
a || console.info("Default storage space was used, because a name was not passed.");
|
|
this.id = "flexsearch" + (a ? ":" + a.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : "");
|
|
this.field = c.field ? c.field.toLowerCase().replace(/[^a-z0-9_\-]/g, "") : "";
|
|
this.type = c.type;
|
|
this.fastupdate = this.support_tag_search = !1;
|
|
this.db = null;
|
|
this.h = {};
|
|
}
|
|
w = Eb.prototype;
|
|
w.mount = function(a) {
|
|
if (a.index) {
|
|
return a.mount(this);
|
|
}
|
|
a.db = this;
|
|
return this.open();
|
|
};
|
|
w.open = function() {
|
|
if (this.db) {
|
|
return this.db;
|
|
}
|
|
let a = this;
|
|
navigator.storage && navigator.storage.persist();
|
|
Db[a.id] || (Db[a.id] = []);
|
|
Db[a.id].push(a.field);
|
|
const c = Bb.open(a.id, 1);
|
|
c.onupgradeneeded = function() {
|
|
const b = a.db = this.result;
|
|
for (let e = 0, d; e < Cb.length; e++) {
|
|
d = Cb[e];
|
|
for (let f = 0, g; f < Db[a.id].length; f++) {
|
|
g = Db[a.id][f], b.objectStoreNames.contains(d + (d !== "reg" ? g ? ":" + g : "" : "")) || b.createObjectStore(d + (d !== "reg" ? g ? ":" + g : "" : ""));
|
|
}
|
|
}
|
|
};
|
|
return a.db = Z(c, function(b) {
|
|
a.db = b;
|
|
a.db.onversionchange = function() {
|
|
a.close();
|
|
};
|
|
});
|
|
};
|
|
w.close = function() {
|
|
this.db && this.db.close();
|
|
this.db = null;
|
|
};
|
|
w.destroy = function() {
|
|
const a = Bb.deleteDatabase(this.id);
|
|
return Z(a);
|
|
};
|
|
w.clear = function() {
|
|
const a = [];
|
|
for (let b = 0, e; b < Cb.length; b++) {
|
|
e = Cb[b];
|
|
for (let d = 0, f; d < Db[this.id].length; d++) {
|
|
f = Db[this.id][d], a.push(e + (e !== "reg" ? f ? ":" + f : "" : ""));
|
|
}
|
|
}
|
|
const c = this.db.transaction(a, "readwrite");
|
|
for (let b = 0; b < a.length; b++) {
|
|
c.objectStore(a[b]).clear();
|
|
}
|
|
return Z(c);
|
|
};
|
|
w.get = function(a, c, b = 0, e = 0, d = !0, f = !1) {
|
|
a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a);
|
|
const g = this;
|
|
return Z(a).then(function(h) {
|
|
let k = [];
|
|
if (!h || !h.length) {
|
|
return k;
|
|
}
|
|
if (d) {
|
|
if (!b && !e && h.length === 1) {
|
|
return h[0];
|
|
}
|
|
for (let l = 0, m; l < h.length; l++) {
|
|
if ((m = h[l]) && m.length) {
|
|
if (e >= m.length) {
|
|
e -= m.length;
|
|
continue;
|
|
}
|
|
const p = b ? e + Math.min(m.length - e, b) : m.length;
|
|
for (let u = e; u < p; u++) {
|
|
k.push(m[u]);
|
|
}
|
|
e = 0;
|
|
if (k.length === b) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return f ? g.enrich(k) : k;
|
|
}
|
|
return h;
|
|
});
|
|
};
|
|
w.tag = function(a, c = 0, b = 0, e = !1) {
|
|
a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a);
|
|
const d = this;
|
|
return Z(a).then(function(f) {
|
|
if (!f || !f.length || b >= f.length) {
|
|
return [];
|
|
}
|
|
if (!c && !b) {
|
|
return f;
|
|
}
|
|
f = f.slice(b, b + c);
|
|
return e ? d.enrich(f) : f;
|
|
});
|
|
};
|
|
w.enrich = function(a) {
|
|
typeof a !== "object" && (a = [a]);
|
|
const c = this.db.transaction("reg", "readonly").objectStore("reg"), b = [];
|
|
for (let e = 0; e < a.length; e++) {
|
|
b[e] = Z(c.get(a[e]));
|
|
}
|
|
return Promise.all(b).then(function(e) {
|
|
for (let d = 0; d < e.length; d++) {
|
|
e[d] = {id:a[d], doc:e[d] ? JSON.parse(e[d]) : null};
|
|
}
|
|
return e;
|
|
});
|
|
};
|
|
w.has = function(a) {
|
|
a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a);
|
|
return Z(a).then(function(c) {
|
|
return !!c;
|
|
});
|
|
};
|
|
w.search = null;
|
|
w.info = function() {
|
|
};
|
|
w.transaction = function(a, c, b) {
|
|
a += a !== "reg" ? this.field ? ":" + this.field : "" : "";
|
|
let e = this.h[a + ":" + c];
|
|
if (e) {
|
|
return b.call(this, e);
|
|
}
|
|
let d = this.db.transaction(a, c);
|
|
this.h[a + ":" + c] = e = d.objectStore(a);
|
|
const f = b.call(this, e);
|
|
this.h[a + ":" + c] = null;
|
|
return Z(d).finally(function() {
|
|
d = e = null;
|
|
return f;
|
|
});
|
|
};
|
|
w.commit = async function(a) {
|
|
let c = a.commit_task, b = [];
|
|
a.commit_task = [];
|
|
for (let e = 0, d; e < c.length; e++) {
|
|
d = c[e], d.del && b.push(d.del);
|
|
}
|
|
b.length && await this.remove(b);
|
|
a.reg.size && (await this.transaction("map", "readwrite", function(e) {
|
|
for (const d of a.map) {
|
|
const f = d[0], g = d[1];
|
|
g.length && (e.get(f).onsuccess = function() {
|
|
let h = this.result;
|
|
var k;
|
|
if (h && h.length) {
|
|
const l = Math.max(h.length, g.length);
|
|
for (let m = 0, p, u; m < l; m++) {
|
|
if ((u = g[m]) && u.length) {
|
|
if ((p = h[m]) && p.length) {
|
|
for (k = 0; k < u.length; k++) {
|
|
p.push(u[k]);
|
|
}
|
|
} else {
|
|
h[m] = u;
|
|
}
|
|
k = 1;
|
|
}
|
|
}
|
|
} else {
|
|
h = g, k = 1;
|
|
}
|
|
k && e.put(h, f);
|
|
});
|
|
}
|
|
}), await this.transaction("ctx", "readwrite", function(e) {
|
|
for (const d of a.ctx) {
|
|
const f = d[0], g = d[1];
|
|
for (const h of g) {
|
|
const k = h[0], l = h[1];
|
|
l.length && (e.get(f + ":" + k).onsuccess = function() {
|
|
let m = this.result;
|
|
var p;
|
|
if (m && m.length) {
|
|
const u = Math.max(m.length, l.length);
|
|
for (let r = 0, t, n; r < u; r++) {
|
|
if ((n = l[r]) && n.length) {
|
|
if ((t = m[r]) && t.length) {
|
|
for (p = 0; p < n.length; p++) {
|
|
t.push(n[p]);
|
|
}
|
|
} else {
|
|
m[r] = n;
|
|
}
|
|
p = 1;
|
|
}
|
|
}
|
|
} else {
|
|
m = l, p = 1;
|
|
}
|
|
p && e.put(m, f + ":" + k);
|
|
});
|
|
}
|
|
}
|
|
}), a.store ? await this.transaction("reg", "readwrite", function(e) {
|
|
for (const d of a.store) {
|
|
const f = d[0], g = d[1];
|
|
e.put(typeof g === "object" ? JSON.stringify(g) : 1, f);
|
|
}
|
|
}) : a.bypass || await this.transaction("reg", "readwrite", function(e) {
|
|
for (const d of a.reg.keys()) {
|
|
e.put(1, d);
|
|
}
|
|
}), a.tag && await this.transaction("tag", "readwrite", function(e) {
|
|
for (const d of a.tag) {
|
|
const f = d[0], g = d[1];
|
|
g.length && (e.get(f).onsuccess = function() {
|
|
let h = this.result;
|
|
h = h && h.length ? h.concat(g) : g;
|
|
e.put(h, f);
|
|
});
|
|
}
|
|
}), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear());
|
|
};
|
|
function Fb(a, c, b) {
|
|
const e = a.value;
|
|
let d, f = 0;
|
|
for (let g = 0, h; g < e.length; g++) {
|
|
if (h = b ? e : e[g]) {
|
|
for (let k = 0, l, m; k < c.length; k++) {
|
|
if (m = c[k], l = h.indexOf(m), l >= 0) {
|
|
if (d = 1, h.length > 1) {
|
|
h.splice(l, 1);
|
|
} else {
|
|
e[g] = [];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
f += h.length;
|
|
}
|
|
if (b) {
|
|
break;
|
|
}
|
|
}
|
|
f ? d && a.update(e) : a.delete();
|
|
a.continue();
|
|
}
|
|
w.remove = function(a) {
|
|
typeof a !== "object" && (a = [a]);
|
|
return Promise.all([this.transaction("map", "readwrite", function(c) {
|
|
c.openCursor().onsuccess = function() {
|
|
const b = this.result;
|
|
b && Fb(b, a);
|
|
};
|
|
}), this.transaction("ctx", "readwrite", function(c) {
|
|
c.openCursor().onsuccess = function() {
|
|
const b = this.result;
|
|
b && Fb(b, a);
|
|
};
|
|
}), this.transaction("tag", "readwrite", function(c) {
|
|
c.openCursor().onsuccess = function() {
|
|
const b = this.result;
|
|
b && Fb(b, a, !0);
|
|
};
|
|
}), this.transaction("reg", "readwrite", function(c) {
|
|
for (let b = 0; b < a.length; b++) {
|
|
c.delete(a[b]);
|
|
}
|
|
})]);
|
|
};
|
|
function Z(a, c) {
|
|
return new Promise((b, e) => {
|
|
a.onsuccess = a.oncomplete = function() {
|
|
c && c(this.result);
|
|
c = null;
|
|
b(this.result);
|
|
};
|
|
a.onerror = a.onblocked = e;
|
|
a = null;
|
|
});
|
|
}
|
|
;export default {Index:T, Charset:wa, Encoder:ka, Document:Na, Worker:La, Resolver:X, IndexedDB:Eb, Language:{}};
|
|
|
|
export const Index=T;export const Charset=wa;export const Encoder=ka;export const Document=Na;export const Worker=La;export const Resolver=X;export const IndexedDB=Eb;export const Language={}; |