diff --git a/README.md b/README.md index 1a09421..7f83ea7 100644 --- a/README.md +++ b/README.md @@ -2269,6 +2269,56 @@ The custom build will be saved to `dist/flexsearch.custom.xxxx.min.js` or when f A formula to determine a well-balanced value for the `resolution` is: $2*floor(\sqrt{content.length})$ where content is the value pushed by `index.add()`. Here the maximum length of all contents should be used. +## Import / Export (In-Memory) + +> Persistent-Indexes and Worker-Indexes don't support Import/Export. + +Export a simple `Index` to the folder `/export/`: + +```js +import { promises as fs } from "fs"; + +await index.export(async function(key, data){ + await fs.writeFile("./export/" + key, data, "utf8"); +}); +``` + +Import from folder `/export/` into a simple `Index`: + +```js +const index = new Index({/* keep old config and place it here */}); + +const files = await fs.readdir("./export/"); +for(let i = 0; i < files.length; i++){ + const data = await fs.readFile("./export/" + files[i], "utf8"); + await index.import(files[i], data); +} +``` + +This is very similar for document indexes. + +Export a `Document-Index` to the folder `/export/`: + +```js +import { promises as fs } from "fs"; + +await index.export(async function(key, data){ + await fs.writeFile("./export/" + key, data, "utf8"); +}); +``` + +Import from folder `/export/` into a `Document-Index`: + +```js +const index = new Document({/* keep old config and place it here */}); + +const files = await fs.readdir("./export/"); +for(let i = 0; i < files.length; i++){ + const data = await fs.readFile("./export/" + files[i], "utf8"); + await index.import(files[i], data); +} +``` + ## Migration - The index option property "minlength" has moved to the Encoder Class diff --git a/dist/db/indexeddb/index.cjs b/dist/db/indexeddb/index.cjs index 34fedc3..fde7f8f 100644 --- a/dist/db/indexeddb/index.cjs +++ b/dist/db/indexeddb/index.cjs @@ -430,7 +430,7 @@ const normalize = "".normalize && /[\u0300-\u036f]/g; // '´`’ʼ., function Encoder(options){ - if(!this){ + if(this.constructor !== Encoder){ return new Encoder(...arguments); } @@ -1009,7 +1009,7 @@ let pid = 0; function WorkerIndex(options = {}){ - if(!this) { + if(this.constructor !== WorkerIndex) { return new WorkerIndex(options); } @@ -1245,111 +1245,88 @@ function register(key){ }; } -// TODO return promises instead of inner await +function map_to_json(map){ + const json = []; + for(const item of map.entries()){ + json.push(item); + } + return json; +} +function ctx_to_json(ctx){ + const json = []; + for(const item of ctx.entries()){ + json.push(map_to_json(item)); + } + return json; +} -function async(callback, self, field, key, index_doc, index, data, on_done){ +function reg_to_json(reg){ + const json = []; + for(const key of reg.keys()){ + json.push(key); + } + return json; +} - //setTimeout(function(){ +function save(callback, field, key, index_doc, index, data){ - const res = callback(field ? field + "." + key : key, JSON.stringify(data)); + const res = callback(field ? field + "." + key : key, JSON.stringify(data)); - // await isn't supported by ES5 + if(res && res["then"]){ + const self = this; + return res["then"](function(){ + return self.export(callback, field, index_doc, index + 1); + }); + } - if(res && res["then"]){ - - res["then"](function(){ - - self.export(callback, self, field, index_doc, index + 1, on_done); - }); - } - else { - - self.export(callback, self, field, index_doc, index + 1, on_done); - } - //}); + return this.export(callback, field, index_doc, index + 1); } /** * @param callback - * @param self * @param field * @param index_doc * @param index - * @param on_done * @this {Index|Document} */ -function exportIndex(callback, self, field, index_doc, index, on_done){ - - let return_value = true; - if (typeof on_done === 'undefined') { - return_value = new Promise((resolve) => { - on_done = resolve; - }); - } +function exportIndex(callback, field, index_doc, index = 0){ let key, data; - switch(index || (index = 0)){ + switch(index){ case 0: key = "reg"; - - // fastupdate isn't supported by export - - if(this.fastupdate){ - - data = create_object(); - - for(let key of this.reg.keys()){ - - data[key] = 1; - } - } - else { - - data = this.reg; - } - + data = reg_to_json(this.reg); break; case 1: key = "cfg"; - data = { - "doc": 0, - "opt": this.optimize ? 1 : 0 - }; - + data = {}; break; case 2: key = "map"; - data = this.map; + data = map_to_json(this.map); break; case 3: key = "ctx"; - data = this.ctx; + data = ctx_to_json(this.ctx); break; default: - if (typeof field === 'undefined' && on_done) { - - on_done(); - } - return; } - async(callback, self || this, field, key, index_doc, index, data, on_done); - - return return_value; + return save.call(this, callback, field, key, index_doc, index, data); } /** @@ -1359,38 +1336,32 @@ function exportIndex(callback, self, field, index_doc, index, on_done){ function importIndex(key, data){ if(!data){ - return; } - if(is_string(data)){ - data = JSON.parse(data); } switch(key){ case "cfg": - - this.optimize = !!data["opt"]; break; case "reg": - // fastupdate isn't supported by import - + // fast update isn't supported by export/import this.fastupdate = false; - this.reg = data; + this.reg = new Set(data); break; case "map": - this.map = data; + this.map = new Map(data); break; case "ctx": - this.ctx = data; + this.ctx = new Map(data); break; } } @@ -1399,35 +1370,23 @@ function importIndex(key, data){ * @this Document */ -function exportDocument(callback, self, field, index_doc, index, on_done){ - - let return_value; - if (typeof on_done === 'undefined') { - return_value = new Promise((resolve) => { - on_done = resolve; - }); - } - - index || (index = 0); - index_doc || (index_doc = 0); +function exportDocument(callback, field, index_doc = 0, index = 0){ if(index_doc < this.field.length){ const field = this.field[index_doc]; - const idx = this.index[field]; + const idx = this.index.get(field); + // start from index 1, because document indexes does not additionally store register + const res = idx.export(callback, field, index_doc, index = 1); - self = this; + if(res && res["then"]){ + const self = this; + return res["then"](function(){ + return self.export(callback, field, index_doc + 1, index = 0); + }); + } - //setTimeout(function(){ - - if(!idx.export(callback, self, index ? field/*.replace(":", "-")*/ : "", index_doc, index++, on_done)){ - - index_doc++; - index = 1; - - self.export(callback, self, field, index_doc, index, on_done); - } - //}); + return this.export(callback, field, index_doc + 1, index = 0); } else { @@ -1435,36 +1394,41 @@ function exportDocument(callback, self, field, index_doc, index, on_done){ switch(index){ + case 0: + + key = "reg"; + data = reg_to_json(this.reg); + field = null; + break; + case 1: key = "tag"; - data = this.tagindex; + data = ctx_to_json(this.tag); field = null; break; case 2: - key = "store"; - data = this.store; + key = "doc"; + data = map_to_json(this.store); field = null; break; - // case 3: - // - // key = "reg"; - // data = this.register; - // break; + case 3: + + key = "cfg"; + data = {}; + field = null; + break; default: - on_done(); return; } - async(callback, this, field, key, index_doc, index, data, on_done); + return save.call(this, callback, field, key, index_doc, index, data); } - - return return_value } /** @@ -1474,12 +1438,9 @@ function exportDocument(callback, self, field, index_doc, index, on_done){ function importDocument(key, data){ if(!data){ - return; } - if(is_string(data)){ - data = JSON.parse(data); } @@ -1487,28 +1448,26 @@ function importDocument(key, data){ case "tag": - this.tagindex = data; + this.tagindex = new Map(data); break; case "reg": - // fastupdate isn't supported by import - + // fast update isn't supported by export/import this.fastupdate = false; - this.reg = data; + this.reg = new Set(data); - for(let i = 0, index; i < this.field.length; i++){ - - index = this.index[this.field[i]]; - index.reg = data; - index.fastupdate = false; + for(let i = 0, idx; i < this.field.length; i++){ + idx = this.index.get(this.field[i]); + idx.fastupdate = false; + idx.reg = this.reg; } break; - case "store": + case "doc": - this.store = data; + this.store = new Map(data); break; default: @@ -1518,8 +1477,7 @@ function importDocument(key, data){ key = key[1]; if(field && key){ - - this.index[field].import(key, data); + this.index.get(field).import(key, data); } } } @@ -3492,7 +3450,7 @@ function apply_enrich(res){ function Document(options){ - if(!this) { + if(this.constructor !== Document) { return new Document(options); } @@ -5472,7 +5430,7 @@ function exclusion(result, limit, offset, resolve){ */ function Resolver(result){ - if(!this){ + if(this.constructor !== Resolver){ return new Resolver(result); } if(result && result.index){ @@ -6232,7 +6190,7 @@ function remove_index(map, id){ function Index(options, _register){ - if(!this){ + if(this.constructor !== Index){ return new Index(options); } diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index f12796d..2e90e31 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -90,7 +90,7 @@ function ca(a) { "\u04d9"], ["\u04dd", "\u0436"], ["\u04df", "\u0437"], ["\u04e3", "\u0438"], ["\u04e5", "\u0438"], ["\u04e7", "\u043e"], ["\u04eb", "\u04e9"], ["\u04ed", "\u044d"], ["\u04ef", "\u0443"], ["\u04f1", "\u0443"], ["\u04f3", "\u0443"], ["\u04f5", "\u0447"]]; const ea = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = "".normalize && /[\u0300-\u036f]/g; function K(a) { - if (!this) { + if (this.constructor !== K) { return new K(...arguments); } for (let b = 0; b < arguments.length; b++) { @@ -264,7 +264,7 @@ function N(a = {}) { return this; } } - if (!this) { + if (this.constructor !== N) { return new N(a); } let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; @@ -314,12 +314,37 @@ function P(a) { return b; }; } -;function oa(a, b, c, d, e, f, g, h) { - (d = a(c ? c + "." + d : d, JSON.stringify(g))) && d.then ? d.then(function() { - b.export(a, b, c, e, f + 1, h); - }) : b.export(a, b, c, e, f + 1, h); +;function oa(a) { + const b = []; + for (const c of a.entries()) { + b.push(c); + } + return b; } -;function pa(a, b, c, d) { +function pa(a) { + const b = []; + for (const c of a.entries()) { + b.push(oa(c)); + } + return b; +} +function qa(a) { + const b = []; + for (const c of a.keys()) { + b.push(c); + } + return b; +} +function ra(a, b, c, d, e, f) { + if ((c = a(b ? b + "." + c : c, JSON.stringify(f))) && c.then) { + const g = this; + return c.then(function() { + return g.export(a, b, d, e + 1); + }); + } + return this.export(a, b, d, e + 1); +} +;function sa(a, b, c, d) { let e = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { @@ -385,12 +410,12 @@ function Q(a) { } if ("slice" === d) { return function(e, f) { - return pa(b, e || 0, f || b.length, !1); + return sa(b, e || 0, f || b.length, !1); }; } if ("splice" === d) { return function(e, f) { - return pa(b, e || 0, f || b.length, !0); + return sa(b, e || 0, f || b.length, !0); }; } if ("constructor" === d) { @@ -421,7 +446,7 @@ function R(a = 8) { this.index = B(); this.B = []; this.size = 0; - 32 < a ? (this.h = qa, this.A = BigInt(a)) : (this.h = ra, this.A = a); + 32 < a ? (this.h = ta, this.A = BigInt(a)) : (this.h = ua, this.A = a); } R.prototype.get = function(a) { const b = this.index[this.h(a)]; @@ -438,7 +463,7 @@ function S(a = 8) { } this.index = B(); this.h = []; - 32 < a ? (this.B = qa, this.A = BigInt(a)) : (this.B = ra, this.A = a); + 32 < a ? (this.B = ta, this.A = BigInt(a)) : (this.B = ua, this.A = a); } S.prototype.add = function(a) { var b = this.B(a); @@ -480,7 +505,7 @@ v.entries = S.prototype.entries = function*() { } } }; -function ra(a) { +function ua(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; @@ -491,7 +516,7 @@ function ra(a) { } return 32 === this.A ? c + 2 ** 31 : c; } -function qa(a) { +function ta(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -521,7 +546,7 @@ function qa(a) { e && d.add(a, e, !1, !0); } else { if (e = k.I, !e || e(b)) { - k.constructor === String ? k = ["" + k] : G(k) && (k = [k]), sa(b, k, this.K, 0, d, a, k[0], c); + k.constructor === String ? k = ["" + k] : G(k) && (k = [k]), va(b, k, this.K, 0, d, a, k[0], c); } } } @@ -584,7 +609,7 @@ function qa(a) { h[l] = b[l]; continue; } - ta(b, h, l, 0, l[0], m); + wa(b, h, l, 0, l[0], m); } } this.store.set(a, h || b); @@ -592,21 +617,21 @@ function qa(a) { } return this; }; -function ta(a, b, c, d, e, f) { +function wa(a, b, c, d, e, f) { a = a[e]; if (d === c.length - 1) { b[e] = f || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - ta(a, b, c, d, e); + wa(a, b, c, d, e); } } else { - b = b[e] || (b[e] = B()), e = c[++d], ta(a, b, c, d, e); + b = b[e] || (b[e] = B()), e = c[++d], wa(a, b, c, d, e); } } } -function sa(a, b, c, d, e, f, g, h) { +function va(a, b, c, d, e, f, g, h) { if (a = a[g]) { if (d === b.length - 1) { if (a.constructor === Array) { @@ -622,17 +647,17 @@ function sa(a, b, c, d, e, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - sa(a, b, c, d, e, f, g, h); + va(a, b, c, d, e, f, g, h); } } else { - g = b[++d], sa(a, b, c, d, e, f, g, h); + g = b[++d], va(a, b, c, d, e, f, g, h); } } } else { e.db && e.remove(f); } } -;function ua(a, b, c, d, e, f, g) { +;function xa(a, b, c, d, e, f, g) { const h = a.length; let k = [], l; var m; @@ -648,7 +673,7 @@ function sa(a, b, c, d, e, f, g, h) { } if (a = k.length) { if (e) { - k = 1 < k.length ? va(k, d, c, g, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + k = 1 < k.length ? ya(k, d, c, g, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { if (a < h) { return []; @@ -681,7 +706,7 @@ function sa(a, b, c, d, e, f, g, h) { } return k; } -function va(a, b, c, d, e) { +function ya(a, b, c, d, e) { const f = [], g = B(); let h; var k = a.length; @@ -724,7 +749,7 @@ function va(a, b, c, d, e) { } return f; } -function wa(a, b) { +function za(a, b) { const c = B(), d = []; for (let e = 0, f; e < b.length; e++) { f = b[e]; @@ -802,7 +827,7 @@ function wa(a, b) { } t.push(d = d.db.tag(r[n + 1], b, l, q)); } else { - d = xa.call(this, r[n], r[n + 1], b, l, q); + d = Aa.call(this, r[n], r[n + 1], b, l, q); } e.push({field:r[n], tag:r[n + 1], result:d}); } @@ -854,7 +879,7 @@ function wa(a, b) { } } } else { - for (let E = 0, F, cb; E < n.length; E += 2) { + for (let E = 0, F, fb; E < n.length; E += 2) { F = this.tag.get(n[E]); if (!F) { if (console.warn("Tag '" + n[E] + ":" + n[E + 1] + "' will be skipped because there is no field '" + n[E] + "'."), t) { @@ -863,7 +888,7 @@ function wa(a, b) { return e; } } - if (cb = (F = F && F.get(n[E + 1])) && F.length) { + if (fb = (F = F && F.get(n[E + 1])) && F.length) { x++, u.push(F); } else if (!t) { return e; @@ -871,7 +896,7 @@ function wa(a, b) { } } if (x) { - w = wa(w, u); + w = za(w, u); I = w.length; if (!I && !t) { return e; @@ -913,7 +938,7 @@ function wa(a, b) { r = []; for (let y = 0, w; y < f.length; y++) { w = e[y]; - q && w.length && !w[0].doc && (this.db ? r.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = ya.call(this, w))); + q && w.length && !w[0].doc && (this.db ? r.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = Ba.call(this, w))); if (g) { return w; } @@ -925,12 +950,12 @@ function wa(a, b) { for (let A = 0; A < w.length; A++) { e[A].result = w[A]; } - return h ? za(e, b) : p ? Aa(e, a, y.index, y.field, y.D, p) : e; + return h ? Ca(e, b) : p ? Da(e, a, y.index, y.field, y.D, p) : e; }); } - return h ? za(e, b) : p ? Aa(e, a, this.index, this.field, this.D, p) : e; + return h ? Ca(e, b) : p ? Da(e, a, this.index, this.field, this.D, p) : e; }; -function Aa(a, b, c, d, e, f) { +function Da(a, b, c, d, e, f) { let g, h, k; for (let m = 0, p, n, q, t, r; m < a.length; m++) { p = a[m].result; @@ -972,7 +997,7 @@ function Aa(a, b, c, d, e, f) { } return a; } -function za(a, b) { +function Ca(a, b) { const c = [], d = B(); for (let e = 0, f, g; e < a.length; e++) { f = a[e]; @@ -991,7 +1016,7 @@ function za(a, b) { } return c; } -function xa(a, b, c, d, e) { +function Aa(a, b, c, d, e) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1000,11 +1025,11 @@ function xa(a, b, c, d, e) { if (a > c || d) { f = f.slice(d, d + c); } - e && (f = ya.call(this, f)); + e && (f = Ba.call(this, f)); return f; } } -function ya(a) { +function Ba(a) { const b = Array(a.length); for (let c = 0, d; c < a.length; c++) { d = a[c], b[c] = {id:d, doc:this.store.get(d)}; @@ -1012,7 +1037,7 @@ function ya(a) { return b; } ;function T(a) { - if (!this) { + if (this.constructor !== T) { return new T(a); } const b = a.document || a.doc || a; @@ -1020,7 +1045,7 @@ function ya(a) { this.D = []; this.field = []; this.K = []; - this.key = (c = b.key || b.id) && Ba(c, this.K) || "id"; + this.key = (c = b.key || b.id) && Ea(c, this.K) || "id"; (d = a.keystore || 0) && (this.keystore = d); this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new R(d) : new Map() : d ? new S(d) : new Set(); this.C = (c = b.store || null) && !0 !== c && []; @@ -1028,7 +1053,7 @@ function ya(a) { this.cache = (c = a.cache || null) && new U(c); a.cache = !1; this.worker = a.worker; - this.index = Ca.call(this, a, b); + this.index = Fa.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -1041,7 +1066,7 @@ function ya(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.G[e] = f.custom : (this.G[e] = Ba(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = f.filter)); + f.custom ? this.G[e] = f.custom : (this.G[e] = Ea(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = f.filter)); this.N[e] = g; this.tag.set(g, new Map()); } @@ -1109,7 +1134,7 @@ v.destroy = function() { } return Promise.all(a); }; -function Ca(a, b) { +function Fa(a, b) { const c = new Map(); let d = b.index || b.field || b; G(d) && (d = [d]); @@ -1122,19 +1147,19 @@ function Ca(a, b) { c.set(f, h); } this.worker || c.set(f, new L(g, this.reg)); - g.custom ? this.D[e] = g.custom : (this.D[e] = Ba(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = g.filter)); + g.custom ? this.D[e] = g.custom : (this.D[e] = Ea(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = g.filter)); this.field[e] = f; } if (this.C) { a = b.store; G(a) && (a = [a]); for (let e = 0, f, g; e < a.length; e++) { - f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ba(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); + f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ea(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); } } return c; } -function Ba(a, b) { +function Ea(a, b) { const c = a.split(":"); let d = 0; for (let e = 0; e < c.length; e++) { @@ -1200,65 +1225,70 @@ v.set = function(a, b) { this.store.set(a, b); return this; }; -v.searchCache = Da; -v.export = function(a, b, c, d, e, f) { - let g; - "undefined" === typeof f && (g = new Promise(k => { - f = k; - })); - e || (e = 0); - d || (d = 0); - if (d < this.field.length) { - c = this.field[d]; - var h = this.index[c]; - b = this; - h.export(a, b, e ? c : "", d, e++, f) || (d++, b.export(a, b, c, d, 1, f)); - } else { - switch(e) { - case 1: - b = "tag"; - h = this.A; - c = null; - break; - case 2: - b = "store"; - h = this.store; - c = null; - break; - default: - f(); - return; +v.searchCache = Ga; +v.export = function(a, b, c = 0, d = 0) { + if (c < this.field.length) { + const g = this.field[c]; + if ((b = this.index.get(g).export(a, g, c, d = 1)) && b.then) { + const h = this; + return b.then(function() { + return h.export(a, g, c + 1, d = 0); + }); } - oa(a, this, c, b, d, e, h, f); + return this.export(a, g, c + 1, d = 0); } - return g; + let e, f; + switch(d) { + case 0: + e = "reg"; + f = qa(this.reg); + b = null; + break; + case 1: + e = "tag"; + f = pa(this.tag); + b = null; + break; + case 2: + e = "doc"; + f = oa(this.store); + b = null; + break; + case 3: + e = "cfg"; + f = {}; + b = null; + break; + default: + return; + } + return ra.call(this, a, b, e, c, d, f); }; v.import = function(a, b) { if (b) { switch(G(b) && (b = JSON.parse(b)), a) { case "tag": - this.A = b; break; case "reg": this.fastupdate = !1; - this.reg = b; + this.reg = new Set(b); for (let d = 0, e; d < this.field.length; d++) { - e = this.index[this.field[d]], e.reg = b, e.fastupdate = !1; + e = this.index.get(this.field[d]), e.fastupdate = !1, e.reg = this.reg; } break; - case "store": - this.store = b; + case "doc": + this.store = new Map(b); break; default: a = a.split("."); const c = a[0]; a = a[1]; - c && a && this.index[c].import(a, b); + c && a && this.index.get(c).import(a, b); } } }; na(T.prototype); -function Da(a, b, c) { +function Ga(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); let d = this.cache.get(a); if (!d) { @@ -1298,31 +1328,31 @@ U.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ea = {normalize:function(a) { +const Ha = {normalize:function(a) { return a.toLowerCase(); }, dedupe:!1}; -const Fa = 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 Ga = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ha = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const Ia = {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}; -const Ja = /[\x00-\x7F]+/g; -const Ka = /[\x00-\x7F]+/g; -const La = /[\x00-\x7F]+/g; -var Ma = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ea, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Fa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Fa, matcher:Ga, replacer:Ha}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Fa, replacer:Ha.concat([/(?!^)[aeo]/g, ""]), matcher:Ga}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Ia = 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 Ja = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ka = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +const La = {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}; +const Ma = /[\x00-\x7F]+/g; +const Na = /[\x00-\x7F]+/g; +const Oa = /[\x00-\x7F]+/g; +var Pa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ha, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ia}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ia, matcher:Ja, replacer:Ka}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ia, replacer:Ka.concat([/(?!^)[aeo]/g, ""]), matcher:Ja}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let d = b.charAt(0), e = Ia[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Ia[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + let d = b.charAt(0), e = La[d]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = La[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { } a[c] = d; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ja, " "); + return ("" + a).replace(Ma, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ka, ""); + return ("" + a).replace(Na, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(La, " "); + return ("" + a).replace(Oa, " "); }}}; -const Na = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +const Qa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; B(); L.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { @@ -1336,14 +1366,14 @@ L.prototype.add = function(a, b, c, d) { let t = b[this.rtl ? d - 1 - q : q]; var e = t.length; if (e && (p || !m[t])) { - var f = this.score ? this.score(b, t, q, null, 0) : Oa(n, d, q), g = ""; + var f = this.score ? this.score(b, t, q, null, 0) : Ra(n, d, q), g = ""; switch(this.tokenize) { case "full": if (2 < e) { for (f = 0; f < e; f++) { for (var h = e; h > f; h--) { g = t.substring(f, h); - var k = this.score ? this.score(b, t, q, g, f) : Oa(n, d, q, e, f); + var k = this.score ? this.score(b, t, q, g, f) : Ra(n, d, q, e, f); V(this, m, g, k, a, c); } } @@ -1352,7 +1382,7 @@ L.prototype.add = function(a, b, c, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - g = t[h] + g, k = this.score ? this.score(b, t, q, g, h) : Oa(n, d, q, e, h), V(this, m, g, k, a, c); + g = t[h] + g, k = this.score ? this.score(b, t, q, g, h) : Ra(n, d, q, e, h), V(this, m, g, k, a, c); } g = ""; } @@ -1368,7 +1398,7 @@ L.prototype.add = function(a, b, c, d) { for (e = B(), g = this.R, f = t, h = Math.min(p + 1, d - q), e[f] = 1, k = 1; k < h; k++) { if ((t = b[this.rtl ? d - 1 - q - k : q + k]) && !e[t]) { e[t] = 1; - const r = this.score ? this.score(b, f, q, t, k) : Oa(g + (d / 2 > g ? 0 : 1), d, q, h - 1, k - 1), u = this.bidirectional && t > f; + const r = this.score ? this.score(b, f, q, t, k) : Ra(g + (d / 2 > g ? 0 : 1), d, q, h - 1, k - 1), u = this.bidirectional && t > f; V(this, l, u ? f : t, r, a, c, u ? t : f); } } @@ -1381,7 +1411,7 @@ L.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && Pa(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && Sa(this)); return this; }; function V(a, b, c, d, e, f, g) { @@ -1402,12 +1432,12 @@ function V(a, b, c, d, e, f, g) { } } } -function Oa(a, b, c, d, e) { +function Ra(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 W(a, b, c, d) { if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Qa(a) : a; + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Ta(a) : a; } let e = []; for (let f = 0, g, h; f < a.length; f++) { @@ -1423,7 +1453,7 @@ function Oa(a, b, c, d, e) { h > b && (g = g.slice(0, b), h = g.length), e.push(g); } else { if (h >= b) { - return h > b && (g = g.slice(0, b)), d ? Qa(g) : g; + return h > b && (g = g.slice(0, b)), d ? Ta(g) : g; } e = [g]; } @@ -1437,9 +1467,9 @@ function Oa(a, b, c, d, e) { return e; } e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? Qa(e) : e; + return d ? Ta(e) : e; } -function Qa(a) { +function Ta(a) { for (let b = 0; b < a.length; b++) { a[b] = {score:b, id:a[b]}; } @@ -1489,19 +1519,19 @@ function Qa(a) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = d.concat([a.result])); - a.result = Ra(d, e, f, g, h, a.F); + a.result = Ua(d, e, f, g, h, a.F); return h ? a.result : a; }); } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ra(d, e, f, g, h, this.F)); + d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ua(d, e, f, g, h, this.F)); return h ? this.result : this; }; -function Ra(a, b, c, d, e, f) { +function Ua(a, b, c, d, e, f) { if (!a.length) { return a; } "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : va(a, c, b, e, f); + return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : ya(a, c, b, e, f); } ;X.prototype.and = function() { if (this.result.length) { @@ -1551,24 +1581,24 @@ function Ra(a, b, c, d, e, f) { if (a.length) { return Promise.all(a).then(function() { d = [b.result].concat(d); - b.result = Sa(d, e, f, g, b.F, h); + b.result = Va(d, e, f, g, b.F, h); return g ? b.result : b; }); } d = [this.result].concat(d); - this.result = Sa(d, e, f, g, this.F, h); + this.result = Va(d, e, f, g, this.F, h); return g ? this.result : this; } return this; }; -function Sa(a, b, c, d, e, f) { +function Va(a, b, c, d, e, f) { if (2 > a.length) { return []; } let g = []; B(); let h = ca(a); - return h ? ua(a, h, b, c, f, e, d) : g; + return h ? xa(a, h, b, c, f, e, d) : g; } ;X.prototype.xor = function() { const a = this; @@ -1614,14 +1644,14 @@ function Sa(a, b, c, d, e, f) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = [a.result].concat(d)); - a.result = Ta(d, e, f, g, !h, a.F); + a.result = Wa(d, e, f, g, !h, a.F); return h ? a.result : a; }); } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Ta(d, e, f, g, !h, a.F)); + d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Wa(d, e, f, g, !h, a.F)); return h ? this.result : this; }; -function Ta(a, b, c, d, e, f) { +function Wa(a, b, c, d, e, f) { if (!a.length) { return a; } @@ -1715,14 +1745,14 @@ function Ta(a, b, c, d, e, f) { } if (c.length) { return Promise.all(c).then(function() { - a.result = Ua.call(a, d, e, f, g); + a.result = Xa.call(a, d, e, f, g); return g ? a.result : a; }); } - d.length && (this.result = Ua.call(this, d, e, f, g)); + d.length && (this.result = Xa.call(this, d, e, f, g)); return g ? this.result : this; }; -function Ua(a, b, c, d) { +function Xa(a, b, c, d) { if (!a.length) { return this.result; } @@ -1752,7 +1782,7 @@ function Ua(a, b, c, d) { return e; } ;function X(a) { - if (!this) { + if (this.constructor !== X) { return new X(a); } if (a && a.index) { @@ -1797,12 +1827,12 @@ X.prototype.boost = function(a) { return this; }; X.prototype.resolve = function(a, b, c) { - Va = 1; + Ya = 1; const d = this.result; this.result = this.index = null; return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), W(d, a || 100, b, c)) : d; }; -let Va = 1; +let Ya = 1; L.prototype.search = function(a, b, c) { c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); let d = [], e; @@ -1813,22 +1843,22 @@ L.prototype.search = function(a, b, c) { g = c.offset || 0; var p = c.context; f = c.suggest; - (h = Va && !1 !== c.resolve) || (Va = 0); + (h = Ya && !1 !== c.resolve) || (Ya = 0); k = h && c.enrich; m = c.boost; l = this.db && c.tag; } else { - h = this.resolve || Va; + h = this.resolve || Ya; } a = this.encoder.encode(a); e = a.length; b || !h || (b = 100); if (1 === e) { - return Wa.call(this, a[0], "", b, g, h, k, l); + return Za.call(this, a[0], "", b, g, h, k, l); } p = this.depth && !1 !== p; if (2 === e && p && !f) { - return Wa.call(this, a[0], a[1], b, g, h, k, l); + return Za.call(this, a[0], a[1], b, g, h, k, l); } let n = c = 0; if (1 < e) { @@ -1853,10 +1883,10 @@ L.prototype.search = function(a, b, c) { } let q = 0, t; if (1 === e) { - return Wa.call(this, a[0], "", b, g, h, k, l); + return Za.call(this, a[0], "", b, g, h, k, l); } if (2 === e && p && !f) { - return Wa.call(this, a[0], a[1], b, g, h, k, l); + return Za.call(this, a[0], a[1], b, g, h, k, l); } 1 < e && (p ? (t = a[0], q = 1) : 9 < c && 3 < c / n && a.sort(aa)); if (this.db) { @@ -1867,7 +1897,7 @@ L.prototype.search = function(a, b, c) { return async function() { for (let u, x; q < e; q++) { x = a[q]; - t ? (u = await Y(r, x, t, 0, 0, !1, !1), u = Xa(u, d, f, r.R), f && !1 === u && d.length || (t = x)) : (u = await Y(r, x, "", 0, 0, !1, !1), u = Xa(u, d, f, r.resolution)); + t ? (u = await Y(r, x, t, 0, 0, !1, !1), u = $a(u, d, f, r.R), f && !1 === u && d.length || (t = x)) : (u = await Y(r, x, "", 0, 0, !1, !1), u = $a(u, d, f, r.resolution)); if (u) { return u; } @@ -1886,12 +1916,12 @@ L.prototype.search = function(a, b, c) { } } } - return h ? ua(d, r.resolution, b, g, f, m, h) : new X(d[0]); + return h ? xa(d, r.resolution, b, g, f, m, h) : new X(d[0]); }(); } for (let r, u; q < e; q++) { u = a[q]; - t ? (r = Y(this, u, t, 0, 0, !1, !1), r = Xa(r, d, f, this.R), f && !1 === r && d.length || (t = u)) : (r = Y(this, u, "", 0, 0, !1, !1), r = Xa(r, d, f, this.resolution)); + t ? (r = Y(this, u, t, 0, 0, !1, !1), r = $a(r, d, f, this.R), f && !1 === r && d.length || (t = u)) : (r = Y(this, u, "", 0, 0, !1, !1), r = $a(r, d, f, this.resolution)); if (r) { return r; } @@ -1910,16 +1940,16 @@ L.prototype.search = function(a, b, c) { } } } - d = ua(d, this.resolution, b, g, f, m, h); + d = xa(d, this.resolution, b, g, f, m, h); return h ? d : new X(d); }; -function Wa(a, b, c, d, e, f, g) { +function Za(a, b, c, d, e, f, g) { a = Y(this, a, b, c, d, e, f, g); return this.db ? a.then(function(h) { return e ? h : h && h.length ? e ? W(h, c, d) : new X(h) : e ? [] : new X([]); }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); } -function Xa(a, b, c, d) { +function $a(a, b, c, d) { let e = []; if (a) { d = Math.min(a.length, d); @@ -1957,15 +1987,15 @@ function Y(a, b, c, d, e, f, g, h) { } } } else { - Ya(this.map, a), this.depth && Ya(this.ctx, a); + ab(this.map, a), this.depth && ab(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && Pa(this)); + this.db && (this.commit_task.push({del:a}), this.T && Sa(this)); this.cache && this.cache.remove(a); return this; }; -function Ya(a, b) { +function ab(a, b) { let c = 0; if (a.constructor === Array) { for (let d = 0, e, f; d < a.length; d++) { @@ -1980,24 +2010,24 @@ function Ya(a, b) { } } else { for (let d of a) { - const e = d[0], f = Ya(d[1], b); + const e = d[0], f = ab(d[1], b); f ? c += f : a.delete(e); } } return c; } ;function L(a, b) { - if (!this) { + if (this.constructor !== L) { return new L(a); } if (a) { var c = G(a) ? a : a.preset; - c && (Na[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Na[c], a)); + c && (Qa[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Qa[c], a)); } else { a = {}; } c = a.context || {}; - const d = G(a.encoder) ? Ma[a.encoder] : a.encode || a.encoder || Ea; + const d = G(a.encoder) ? Pa[a.encoder] : a.encode || a.encoder || Ha; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; let e; this.resolution = a.resolution || 9; @@ -2034,7 +2064,7 @@ v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Pa(a) { +function Sa(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2058,7 +2088,7 @@ v.update = function(a, b) { const c = this, d = this.remove(a); return d && d.then ? d.then(() => c.add(a, b)) : this.add(a, b); }; -function Za(a) { +function bb(a) { let b = 0; if (a.constructor === Array) { for (let c = 0, d; c < a.length; c++) { @@ -2066,7 +2096,7 @@ function Za(a) { } } else { for (const c of a) { - const d = c[0], e = Za(c[1]); + const d = c[0], e = bb(c[1]); e ? b += e : a.delete(d); } } @@ -2076,63 +2106,47 @@ v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Za(this.map); - this.depth && Za(this.ctx); + bb(this.map); + this.depth && bb(this.ctx); return this; }; -v.searchCache = Da; -v.export = function(a, b, c, d, e, f) { - let g = !0; - "undefined" === typeof f && (g = new Promise(l => { - f = l; - })); - let h, k; - switch(e || (e = 0)) { +v.searchCache = Ga; +v.export = function(a, b, c, d = 0) { + let e, f; + switch(d) { case 0: - h = "reg"; - if (this.fastupdate) { - k = B(); - for (let l of this.reg.keys()) { - k[l] = 1; - } - } else { - k = this.reg; - } + e = "reg"; + f = qa(this.reg); break; case 1: - h = "cfg"; - k = {doc:0, opt:this.h ? 1 : 0}; + e = "cfg"; + f = {}; break; case 2: - h = "map"; - k = this.map; + e = "map"; + f = oa(this.map); break; case 3: - h = "ctx"; - k = this.ctx; + e = "ctx"; + f = pa(this.ctx); break; default: - "undefined" === typeof c && f && f(); return; } - oa(a, b || this, c, h, d, e, k, f); - return g; + return ra.call(this, a, b, e, c, d, f); }; v.import = function(a, b) { if (b) { switch(G(b) && (b = JSON.parse(b)), a) { - case "cfg": - this.h = !!b.opt; - break; case "reg": this.fastupdate = !1; - this.reg = b; + this.reg = new Set(b); break; case "map": - this.map = b; + this.map = new Map(b); break; case "ctx": - this.ctx = b; + this.ctx = new Map(b); } } }; @@ -2187,10 +2201,10 @@ v.serialize = function(a = !0) { return a ? "function inject(index){" + b + d + e + "}" : b + d + e; }; na(L.prototype); -const $a = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ab = ["map", "ctx", "tag", "reg", "cfg"]; -function bb(a, b = {}) { +const cb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), db = ["map", "ctx", "tag", "reg", "cfg"]; +function eb(a, b = {}) { if (!this) { - return new bb(a, b); + return new eb(a, b); } "object" === typeof a && (b = a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2200,7 +2214,7 @@ function bb(a, b = {}) { this.db = null; this.h = {}; } -v = bb.prototype; +v = eb.prototype; v.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2212,10 +2226,10 @@ v.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const d = $a.open(a.id + (a.field ? ":" + a.field : ""), 1); + const d = cb.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { const e = a.db = this.result; - ab.forEach(f => { + db.forEach(f => { e.objectStoreNames.contains(f) || e.createObjectStore(f); }); }; @@ -2241,12 +2255,12 @@ v.close = function() { this.db = null; }; v.destroy = function() { - return $a.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return cb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); }; v.clear = function() { - const a = this.db.transaction(ab, "readwrite"); - for (let b = 0; b < ab.length; b++) { - a.objectStore(ab[b]).clear(); + const a = this.db.transaction(db, "readwrite"); + for (let b = 0; b < db.length; b++) { + a.objectStore(db[b]).clear(); } return Z(a); }; @@ -2430,7 +2444,7 @@ v.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function db(a, b, c) { +function gb(a, b, c) { const d = a.value; let e, f, g = 0; for (let h = 0, k; h < d.length; h++) { @@ -2459,17 +2473,17 @@ v.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && db(c, a); + c && gb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && db(c, a); + c && gb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && db(c, a, !0); + c && gb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2489,9 +2503,9 @@ function Z(a) { a = null; }); } -;const eb = {Index:L, Charset:Ma, Encoder:K, Document:T, Worker:N, Resolver:X, IndexedDB:bb, Language:{}}, fb = self; -let gb; -(gb = fb.define) && gb.amd ? gb([], function() { - return eb; -}) : "object" === typeof fb.exports ? fb.exports = eb : fb.FlexSearch = eb; +;const hb = {Index:L, Charset:Pa, Encoder:K, Document:T, Worker:N, Resolver:X, IndexedDB:eb, Language:{}}, ib = self; +let jb; +(jb = ib.define) && jb.amd ? jb([], function() { + return hb; +}) : "object" === typeof ib.exports ? ib.exports = hb : ib.FlexSearch = hb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index 78ed6e9..0264a58 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -12,7 +12,7 @@ function F(a){return"string"===typeof a}function G(a){return"object"===typeof a} "i"],["\u01d2","o"],["\u01d4","u"],["\u01d6","u"],["\u01d8","u"],["\u01da","u"],["\u01dc","u"],["\u01df","a"],["\u01e1","a"],["\u01e3","ae"],["\u00e6","ae"],["\u01fd","ae"],["\u01e7","g"],["\u01e9","k"],["\u01eb","o"],["\u01ed","o"],["\u01ef","\u0292"],["\u01f0","j"],["\u01f3","dz"],["\u01f5","g"],["\u01f9","n"],["\u01fb","a"],["\u01ff","\u00f8"],["\u0201","a"],["\u0203","a"],["\u0205","e"],["\u0207","e"],["\u0209","i"],["\u020b","i"],["\u020d","o"],["\u020f","o"],["\u0211","r"],["\u0213","r"],["\u0215", "u"],["\u0217","u"],["\u0219","s"],["\u021b","t"],["\u021f","h"],["\u0227","a"],["\u0229","e"],["\u022b","o"],["\u022d","o"],["\u022f","o"],["\u0231","o"],["\u0233","y"],["\u02b0","h"],["\u02b1","h"],["\u0266","h"],["\u02b2","j"],["\u02b3","r"],["\u02b4","\u0279"],["\u02b5","\u027b"],["\u02b6","\u0281"],["\u02b7","w"],["\u02b8","y"],["\u02e0","\u0263"],["\u02e1","l"],["\u02e2","s"],["\u02e3","x"],["\u02e4","\u0295"],["\u0390","\u03b9"],["\u03ac","\u03b1"],["\u03ad","\u03b5"],["\u03ae","\u03b7"],["\u03af", "\u03b9"],["\u03b0","\u03c5"],["\u03ca","\u03b9"],["\u03cb","\u03c5"],["\u03cc","\u03bf"],["\u03cd","\u03c5"],["\u03ce","\u03c9"],["\u03d0","\u03b2"],["\u03d1","\u03b8"],["\u03d2","\u03a5"],["\u03d3","\u03a5"],["\u03d4","\u03a5"],["\u03d5","\u03c6"],["\u03d6","\u03c0"],["\u03f0","\u03ba"],["\u03f1","\u03c1"],["\u03f2","\u03c2"],["\u03f5","\u03b5"],["\u0439","\u0438"],["\u0450","\u0435"],["\u0451","\u0435"],["\u0453","\u0433"],["\u0457","\u0456"],["\u045c","\u043a"],["\u045d","\u0438"],["\u045e","\u0443"], -["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]];const ea=/[^\p{L}\p{N}]+/u,fa=/(\d{3})/g,ha=/(\D)(\d{3})/g,ia=/(\d{3})(\D)/g,ja="".normalize&&/[\u0300-\u036f]/g;function K(a){if(!this)return new K(...arguments);for(let b=0;bthis.stemmer.get(l)),k=1);g&&k&&(g.length< this.minlength||this.filter&&this.filter.has(g))&&(g="");if(g&&(this.mapper||this.dedupe&&1this.matcher.get(l)));if(g&&this.replacer)for(e=0;g&&ethis.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function ka(a){a.L=null;a.H.clear();a.J.clear()};async function la(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};(b=d.config)&&(d=(await import(b))["default"]);(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new L(d);postMessage({id:a.id});break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let M=0; -function N(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=B();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++M]=function(){k(e)};e.worker.postMessage({id:M,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!==typeof window? -window._factory:null;c&&(c=c.toString());const d="undefined"===typeof window,e=this,f=ma(c,d,a.worker);return f.then?f.then(function(g){return b.call(e,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); +function N(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=B();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++M]=function(){k(e)};e.worker.postMessage({id:M,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(this.constructor!==N)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;c&&(c=c.toString());const d="undefined"===typeof window,e=this,f=ma(c,d,a.worker);return f.then?f.then(function(g){return b.call(e,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); function O(a){N.prototype[a]=N.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;"function"===typeof d&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){b.h[++M]=f;b.worker.postMessage({task:a,id:M,args:c})});return e?(d.then(e),this):d}} function ma(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+la.toString()],{type:"text/javascript"}))):new window.Worker(F(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function na(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}function P(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function oa(a,b,c,d,e,f,g,h){(d=a(c?c+"."+d:d,JSON.stringify(g)))&&d.then?d.then(function(){b.export(a,b,c,e,f+1,h)}):b.export(a,b,c,e,f+1,h)};function pa(a,b,c,d){let e=[];for(let f=0,g;f=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} +"module/worker/worker.js"),{type:"module"})};function na(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}function P(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function oa(a){const b=[];for(const c of a.entries())b.push(c);return b}function pa(a){const b=[];for(const c of a.entries())b.push(oa(c));return b}function qa(a){const b=[];for(const c of a.keys())b.push(c);return b}function ra(a,b,c,d,e,f){if((c=a(b?b+"."+c:c,JSON.stringify(f)))&&c.then){const g=this;return c.then(function(){return g.export(a,b,d,e+1)})}return this.export(a,b,d,e+1)};function sa(a,b,c,d){let e=[];for(let f=0,g;f=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} function Q(a){if(!this)return new Q(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(let p=0,n;pd)d-=n.length; +this.C[k];if((c=l.I)&&!c(b))continue;let m;if("function"===typeof l){m=l(b);if(!m)continue;l=[l.U]}else if(F(l)||l.constructor===String){h[l]=b[l];continue}wa(b,h,l,0,l[0],m)}}this.store.set(a,h||b)}}return this};function wa(a,b,c,d,e,f){a=a[e];if(d===c.length-1)b[e]=f||a;else if(a)if(a.constructor===Array)for(b=b[e]=Array(a.length),e=0;ec||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(let p=0,n;pd)d-=n.length; else{if(n.length>c||d)n=n.slice(d,c+d),c-=n.length,d&&(d-=n.length);e.push(n);if(!c)break}k=1c||d)a=a.slice(d,d+c);e&&(a=ya.call(this,a));return a}} -function ya(a){const b=Array(a.length);for(let c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=Ba.call(this,a));return a}} +function Ba(a){const b=Array(a.length);for(let c=0,d;c{f=k}));e||(e=0);d||(d=0);if(dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -U.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const Ea={normalize:function(a){return a.toLowerCase()},dedupe:!1};const Fa=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 Ga=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ha=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ia={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};const Ja=/[\x00-\x7F]+/g;const Ka=/[\x00-\x7F]+/g;const La=/[\x00-\x7F]+/g;var Ma={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ea,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Fa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Fa,matcher:Ga,replacer:Ha},LatinExtra:{normalize:!0,dedupe:!0,mapper:Fa,replacer:Ha.concat([/(?!^)[aeo]/g,""]),matcher:Ga},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=r.substring(f,h);var k=this.score?this.score(b,r,q,g,f):Oa(n,d,q,e,f);V(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,q,h-1,k-1),u=this.bidirectional&&r>f;V(this,l,u?f:r,t,a,c,u?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.T&&Pa(this));return this};function V(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new Q(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function Oa(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Qa(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Qa(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length?e?W(a[0],b,c,d):a[0]:va(a,c,b,e,f)};X.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];B();let h=ca(a);return h?ua(a,h,b,c,f,e,d):g};X.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?W(a[0],b,c,d):a[0];d=[];const g=B();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +U.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const Ha={normalize:function(a){return a.toLowerCase()},dedupe:!1};const Ia=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 Ja=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ka=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const La={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};const Ma=/[\x00-\x7F]+/g;const Na=/[\x00-\x7F]+/g;const Oa=/[\x00-\x7F]+/g;var Pa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ha,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ia},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ia,matcher:Ja,replacer:Ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka.concat([/(?!^)[aeo]/g,""]),matcher:Ja},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=r.substring(f,h);var k=this.score?this.score(b,r,q,g,f):Ra(n,d,q,e,f);V(this,m,g,k,a,c)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,q,h-1,k-1),u=this.bidirectional&&r>f;V(this,l,u?f:r,t,a,c,u?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&Sa(this));return this};function V(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new Q(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +function Ra(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Ta(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Ta(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length?e?W(a[0],b,c,d):a[0]:ya(a,c,b,e,f)};X.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];B();let h=ca(a);return h?xa(a,h,b,c,f,e,d):g};X.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?W(a[0],b,c,d):a[0];d=[];const g=B();let h=0;for(let k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};L.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else Ya(this.map,a),this.depth&&Ya(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Pa(this));this.cache&&this.cache.remove(a);return this}; -function Ya(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};L.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else ab(this.map,a),this.depth&&ab(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Sa(this));this.cache&&this.cache.remove(a);return this}; +function ab(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; -function Za(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=B();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof c&&f&&f();return}oa(a,b||this,c,h,d,e,k,f);return g}; -v.import=function(a,b){if(b)switch(F(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; +function bb(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -v.close=function(){this.db.close();this.db=null};v.destroy=function(){return $a.deleteDatabase(this.id+(this.field?":"+this.field:""))};v.clear=function(){const a=this.db.transaction(ab,"readwrite");for(let b=0;b{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +v.close=function(){this.db.close();this.db=null};v.destroy=function(){return cb.deleteDatabase(this.id+(this.field?":"+this.field:""))};v.clear=function(){const a=this.db.transaction(db,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const p=c?d+Math.min(m.length-d,c):m.length;for(let n=d;n=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; v.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;dm&&!f&&"string"===typeof p&&!isNaN(p)&&(m=k.indexOf(parseInt(p,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const eb={Index:L,Charset:Ma,Encoder:K,Document:T,Worker:N,Resolver:X,IndexedDB:cb,Language:{}},fb=self;let gb;(gb=fb.define)&&gb.amd?gb([],function(){return eb}):"object"===typeof fb.exports?fb.exports=eb:fb.FlexSearch=eb;}(this||self)); +function gb(a,b,c){const d=a.value;let e,f,g=0;for(let h=0,k;hm&&!f&&"string"===typeof p&&!isNaN(p)&&(m=k.indexOf(parseInt(p,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const hb={Index:L,Charset:Pa,Encoder:K,Document:T,Worker:N,Resolver:X,IndexedDB:fb,Language:{}},ib=self;let jb;(jb=ib.define)&&jb.amd?jb([],function(){return hb}):"object"===typeof ib.exports?ib.exports=hb:ib.FlexSearch=hb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index 6f3550c..a170ce0 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -89,7 +89,7 @@ function ca(a) { "\u04d9"], ["\u04dd", "\u0436"], ["\u04df", "\u0437"], ["\u04e3", "\u0438"], ["\u04e5", "\u0438"], ["\u04e7", "\u043e"], ["\u04eb", "\u04e9"], ["\u04ed", "\u044d"], ["\u04ef", "\u0443"], ["\u04f1", "\u0443"], ["\u04f3", "\u0443"], ["\u04f5", "\u0447"]]; const ea = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = "".normalize && /[\u0300-\u036f]/g; function K(a) { - if (!this) { + if (this.constructor !== K) { return new K(...arguments); } for (let b = 0; b < arguments.length; b++) { @@ -263,7 +263,7 @@ function N(a = {}) { return this; } } - if (!this) { + if (this.constructor !== N) { return new N(a); } let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; @@ -313,12 +313,37 @@ function P(a) { return b; }; } -;function oa(a, b, c, d, e, f, g, h) { - (d = a(c ? c + "." + d : d, JSON.stringify(g))) && d.then ? d.then(function() { - b.export(a, b, c, e, f + 1, h); - }) : b.export(a, b, c, e, f + 1, h); +;function oa(a) { + const b = []; + for (const c of a.entries()) { + b.push(c); + } + return b; } -;function pa(a, b, c, d) { +function pa(a) { + const b = []; + for (const c of a.entries()) { + b.push(oa(c)); + } + return b; +} +function qa(a) { + const b = []; + for (const c of a.keys()) { + b.push(c); + } + return b; +} +function ra(a, b, c, d, e, f) { + if ((c = a(b ? b + "." + c : c, JSON.stringify(f))) && c.then) { + const g = this; + return c.then(function() { + return g.export(a, b, d, e + 1); + }); + } + return this.export(a, b, d, e + 1); +} +;function sa(a, b, c, d) { let e = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { @@ -384,12 +409,12 @@ function Q(a) { } if ("slice" === d) { return function(e, f) { - return pa(b, e || 0, f || b.length, !1); + return sa(b, e || 0, f || b.length, !1); }; } if ("splice" === d) { return function(e, f) { - return pa(b, e || 0, f || b.length, !0); + return sa(b, e || 0, f || b.length, !0); }; } if ("constructor" === d) { @@ -420,7 +445,7 @@ function R(a = 8) { this.index = B(); this.B = []; this.size = 0; - 32 < a ? (this.h = qa, this.A = BigInt(a)) : (this.h = ra, this.A = a); + 32 < a ? (this.h = ta, this.A = BigInt(a)) : (this.h = ua, this.A = a); } R.prototype.get = function(a) { const b = this.index[this.h(a)]; @@ -437,7 +462,7 @@ function S(a = 8) { } this.index = B(); this.h = []; - 32 < a ? (this.B = qa, this.A = BigInt(a)) : (this.B = ra, this.A = a); + 32 < a ? (this.B = ta, this.A = BigInt(a)) : (this.B = ua, this.A = a); } S.prototype.add = function(a) { var b = this.B(a); @@ -479,7 +504,7 @@ v.entries = S.prototype.entries = function*() { } } }; -function ra(a) { +function ua(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; @@ -490,7 +515,7 @@ function ra(a) { } return 32 === this.A ? c + 2 ** 31 : c; } -function qa(a) { +function ta(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -520,7 +545,7 @@ function qa(a) { e && d.add(a, e, !1, !0); } else { if (e = k.I, !e || e(b)) { - k.constructor === String ? k = ["" + k] : G(k) && (k = [k]), sa(b, k, this.K, 0, d, a, k[0], c); + k.constructor === String ? k = ["" + k] : G(k) && (k = [k]), va(b, k, this.K, 0, d, a, k[0], c); } } } @@ -583,7 +608,7 @@ function qa(a) { h[l] = b[l]; continue; } - ta(b, h, l, 0, l[0], m); + wa(b, h, l, 0, l[0], m); } } this.store.set(a, h || b); @@ -591,21 +616,21 @@ function qa(a) { } return this; }; -function ta(a, b, c, d, e, f) { +function wa(a, b, c, d, e, f) { a = a[e]; if (d === c.length - 1) { b[e] = f || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - ta(a, b, c, d, e); + wa(a, b, c, d, e); } } else { - b = b[e] || (b[e] = B()), e = c[++d], ta(a, b, c, d, e); + b = b[e] || (b[e] = B()), e = c[++d], wa(a, b, c, d, e); } } } -function sa(a, b, c, d, e, f, g, h) { +function va(a, b, c, d, e, f, g, h) { if (a = a[g]) { if (d === b.length - 1) { if (a.constructor === Array) { @@ -621,17 +646,17 @@ function sa(a, b, c, d, e, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - sa(a, b, c, d, e, f, g, h); + va(a, b, c, d, e, f, g, h); } } else { - g = b[++d], sa(a, b, c, d, e, f, g, h); + g = b[++d], va(a, b, c, d, e, f, g, h); } } } else { e.db && e.remove(f); } } -;function ua(a, b, c, d, e, f, g) { +;function xa(a, b, c, d, e, f, g) { const h = a.length; let k = [], l; var m; @@ -647,7 +672,7 @@ function sa(a, b, c, d, e, f, g, h) { } if (a = k.length) { if (e) { - k = 1 < k.length ? va(k, d, c, g, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + k = 1 < k.length ? ya(k, d, c, g, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { if (a < h) { return []; @@ -680,7 +705,7 @@ function sa(a, b, c, d, e, f, g, h) { } return k; } -function va(a, b, c, d, e) { +function ya(a, b, c, d, e) { const f = [], g = B(); let h; var k = a.length; @@ -723,7 +748,7 @@ function va(a, b, c, d, e) { } return f; } -function wa(a, b) { +function za(a, b) { const c = B(), d = []; for (let e = 0, f; e < b.length; e++) { f = b[e]; @@ -801,7 +826,7 @@ function wa(a, b) { } t.push(d = d.db.tag(r[n + 1], b, l, q)); } else { - d = xa.call(this, r[n], r[n + 1], b, l, q); + d = Aa.call(this, r[n], r[n + 1], b, l, q); } e.push({field:r[n], tag:r[n + 1], result:d}); } @@ -853,7 +878,7 @@ function wa(a, b) { } } } else { - for (let E = 0, F, $a; E < n.length; E += 2) { + for (let E = 0, F, cb; E < n.length; E += 2) { F = this.tag.get(n[E]); if (!F) { if (console.warn("Tag '" + n[E] + ":" + n[E + 1] + "' will be skipped because there is no field '" + n[E] + "'."), t) { @@ -862,7 +887,7 @@ function wa(a, b) { return e; } } - if ($a = (F = F && F.get(n[E + 1])) && F.length) { + if (cb = (F = F && F.get(n[E + 1])) && F.length) { x++, u.push(F); } else if (!t) { return e; @@ -870,7 +895,7 @@ function wa(a, b) { } } if (x) { - w = wa(w, u); + w = za(w, u); I = w.length; if (!I && !t) { return e; @@ -912,7 +937,7 @@ function wa(a, b) { r = []; for (let y = 0, w; y < f.length; y++) { w = e[y]; - q && w.length && !w[0].doc && (this.db ? r.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = ya.call(this, w))); + q && w.length && !w[0].doc && (this.db ? r.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = Ba.call(this, w))); if (g) { return w; } @@ -924,12 +949,12 @@ function wa(a, b) { for (let A = 0; A < w.length; A++) { e[A].result = w[A]; } - return h ? za(e, b) : p ? Aa(e, a, y.index, y.field, y.D, p) : e; + return h ? Ca(e, b) : p ? Da(e, a, y.index, y.field, y.D, p) : e; }); } - return h ? za(e, b) : p ? Aa(e, a, this.index, this.field, this.D, p) : e; + return h ? Ca(e, b) : p ? Da(e, a, this.index, this.field, this.D, p) : e; }; -function Aa(a, b, c, d, e, f) { +function Da(a, b, c, d, e, f) { let g, h, k; for (let m = 0, p, n, q, t, r; m < a.length; m++) { p = a[m].result; @@ -971,7 +996,7 @@ function Aa(a, b, c, d, e, f) { } return a; } -function za(a, b) { +function Ca(a, b) { const c = [], d = B(); for (let e = 0, f, g; e < a.length; e++) { f = a[e]; @@ -990,7 +1015,7 @@ function za(a, b) { } return c; } -function xa(a, b, c, d, e) { +function Aa(a, b, c, d, e) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -999,11 +1024,11 @@ function xa(a, b, c, d, e) { if (a > c || d) { f = f.slice(d, d + c); } - e && (f = ya.call(this, f)); + e && (f = Ba.call(this, f)); return f; } } -function ya(a) { +function Ba(a) { const b = Array(a.length); for (let c = 0, d; c < a.length; c++) { d = a[c], b[c] = {id:d, doc:this.store.get(d)}; @@ -1011,7 +1036,7 @@ function ya(a) { return b; } ;function T(a) { - if (!this) { + if (this.constructor !== T) { return new T(a); } const b = a.document || a.doc || a; @@ -1019,7 +1044,7 @@ function ya(a) { this.D = []; this.field = []; this.K = []; - this.key = (c = b.key || b.id) && Ba(c, this.K) || "id"; + this.key = (c = b.key || b.id) && Ea(c, this.K) || "id"; (d = a.keystore || 0) && (this.keystore = d); this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new R(d) : new Map() : d ? new S(d) : new Set(); this.C = (c = b.store || null) && !0 !== c && []; @@ -1027,7 +1052,7 @@ function ya(a) { this.cache = (c = a.cache || null) && new U(c); a.cache = !1; this.worker = a.worker; - this.index = Ca.call(this, a, b); + this.index = Fa.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -1040,7 +1065,7 @@ function ya(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.G[e] = f.custom : (this.G[e] = Ba(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = f.filter)); + f.custom ? this.G[e] = f.custom : (this.G[e] = Ea(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = f.filter)); this.N[e] = g; this.tag.set(g, new Map()); } @@ -1108,7 +1133,7 @@ v.destroy = function() { } return Promise.all(a); }; -function Ca(a, b) { +function Fa(a, b) { const c = new Map(); let d = b.index || b.field || b; G(d) && (d = [d]); @@ -1121,19 +1146,19 @@ function Ca(a, b) { c.set(f, h); } this.worker || c.set(f, new L(g, this.reg)); - g.custom ? this.D[e] = g.custom : (this.D[e] = Ba(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = g.filter)); + g.custom ? this.D[e] = g.custom : (this.D[e] = Ea(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = g.filter)); this.field[e] = f; } if (this.C) { a = b.store; G(a) && (a = [a]); for (let e = 0, f, g; e < a.length; e++) { - f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ba(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); + f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ea(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); } } return c; } -function Ba(a, b) { +function Ea(a, b) { const c = a.split(":"); let d = 0; for (let e = 0; e < c.length; e++) { @@ -1199,65 +1224,70 @@ v.set = function(a, b) { this.store.set(a, b); return this; }; -v.searchCache = Da; -v.export = function(a, b, c, d, e, f) { - let g; - "undefined" === typeof f && (g = new Promise(k => { - f = k; - })); - e || (e = 0); - d || (d = 0); - if (d < this.field.length) { - c = this.field[d]; - var h = this.index[c]; - b = this; - h.export(a, b, e ? c : "", d, e++, f) || (d++, b.export(a, b, c, d, 1, f)); - } else { - switch(e) { - case 1: - b = "tag"; - h = this.A; - c = null; - break; - case 2: - b = "store"; - h = this.store; - c = null; - break; - default: - f(); - return; +v.searchCache = Ga; +v.export = function(a, b, c = 0, d = 0) { + if (c < this.field.length) { + const g = this.field[c]; + if ((b = this.index.get(g).export(a, g, c, d = 1)) && b.then) { + const h = this; + return b.then(function() { + return h.export(a, g, c + 1, d = 0); + }); } - oa(a, this, c, b, d, e, h, f); + return this.export(a, g, c + 1, d = 0); } - return g; + let e, f; + switch(d) { + case 0: + e = "reg"; + f = qa(this.reg); + b = null; + break; + case 1: + e = "tag"; + f = pa(this.tag); + b = null; + break; + case 2: + e = "doc"; + f = oa(this.store); + b = null; + break; + case 3: + e = "cfg"; + f = {}; + b = null; + break; + default: + return; + } + return ra.call(this, a, b, e, c, d, f); }; v.import = function(a, b) { if (b) { switch(G(b) && (b = JSON.parse(b)), a) { case "tag": - this.A = b; break; case "reg": this.fastupdate = !1; - this.reg = b; + this.reg = new Set(b); for (let d = 0, e; d < this.field.length; d++) { - e = this.index[this.field[d]], e.reg = b, e.fastupdate = !1; + e = this.index.get(this.field[d]), e.fastupdate = !1, e.reg = this.reg; } break; - case "store": - this.store = b; + case "doc": + this.store = new Map(b); break; default: a = a.split("."); const c = a[0]; a = a[1]; - c && a && this.index[c].import(a, b); + c && a && this.index.get(c).import(a, b); } } }; na(T.prototype); -function Da(a, b, c) { +function Ga(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); let d = this.cache.get(a); if (!d) { @@ -1297,31 +1327,31 @@ U.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const Ea = {normalize:function(a) { +const Ha = {normalize:function(a) { return a.toLowerCase(); }, dedupe:!1}; -const Fa = 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 Ga = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ha = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const Ia = {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}; -const Ja = /[\x00-\x7F]+/g; -const Ka = /[\x00-\x7F]+/g; -const La = /[\x00-\x7F]+/g; -var Ma = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ea, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Fa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Fa, matcher:Ga, replacer:Ha}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Fa, replacer:Ha.concat([/(?!^)[aeo]/g, ""]), matcher:Ga}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const Ia = 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 Ja = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), Ka = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +const La = {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}; +const Ma = /[\x00-\x7F]+/g; +const Na = /[\x00-\x7F]+/g; +const Oa = /[\x00-\x7F]+/g; +var Pa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ha, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ia}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ia, matcher:Ja, replacer:Ka}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ia, replacer:Ka.concat([/(?!^)[aeo]/g, ""]), matcher:Ja}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let d = b.charAt(0), e = Ia[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Ia[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + let d = b.charAt(0), e = La[d]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = La[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { } a[c] = d; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Ja, " "); + return ("" + a).replace(Ma, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Ka, ""); + return ("" + a).replace(Na, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(La, " "); + return ("" + a).replace(Oa, " "); }}}; -const Na = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +const Qa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; B(); L.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { @@ -1335,14 +1365,14 @@ L.prototype.add = function(a, b, c, d) { let t = b[this.rtl ? d - 1 - q : q]; var e = t.length; if (e && (p || !m[t])) { - var f = this.score ? this.score(b, t, q, null, 0) : Oa(n, d, q), g = ""; + var f = this.score ? this.score(b, t, q, null, 0) : Ra(n, d, q), g = ""; switch(this.tokenize) { case "full": if (2 < e) { for (f = 0; f < e; f++) { for (var h = e; h > f; h--) { g = t.substring(f, h); - var k = this.score ? this.score(b, t, q, g, f) : Oa(n, d, q, e, f); + var k = this.score ? this.score(b, t, q, g, f) : Ra(n, d, q, e, f); V(this, m, g, k, a, c); } } @@ -1351,7 +1381,7 @@ L.prototype.add = function(a, b, c, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - g = t[h] + g, k = this.score ? this.score(b, t, q, g, h) : Oa(n, d, q, e, h), V(this, m, g, k, a, c); + g = t[h] + g, k = this.score ? this.score(b, t, q, g, h) : Ra(n, d, q, e, h), V(this, m, g, k, a, c); } g = ""; } @@ -1367,7 +1397,7 @@ L.prototype.add = function(a, b, c, d) { for (e = B(), g = this.R, f = t, h = Math.min(p + 1, d - q), e[f] = 1, k = 1; k < h; k++) { if ((t = b[this.rtl ? d - 1 - q - k : q + k]) && !e[t]) { e[t] = 1; - const r = this.score ? this.score(b, f, q, t, k) : Oa(g + (d / 2 > g ? 0 : 1), d, q, h - 1, k - 1), u = this.bidirectional && t > f; + const r = this.score ? this.score(b, f, q, t, k) : Ra(g + (d / 2 > g ? 0 : 1), d, q, h - 1, k - 1), u = this.bidirectional && t > f; V(this, l, u ? f : t, r, a, c, u ? t : f); } } @@ -1380,7 +1410,7 @@ L.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.T && Pa(this)); + this.db && (b || this.commit_task.push({del:a}), this.T && Sa(this)); return this; }; function V(a, b, c, d, e, f, g) { @@ -1401,12 +1431,12 @@ function V(a, b, c, d, e, f, g) { } } } -function Oa(a, b, c, d, e) { +function Ra(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 W(a, b, c, d) { if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Qa(a) : a; + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Ta(a) : a; } let e = []; for (let f = 0, g, h; f < a.length; f++) { @@ -1422,7 +1452,7 @@ function Oa(a, b, c, d, e) { h > b && (g = g.slice(0, b), h = g.length), e.push(g); } else { if (h >= b) { - return h > b && (g = g.slice(0, b)), d ? Qa(g) : g; + return h > b && (g = g.slice(0, b)), d ? Ta(g) : g; } e = [g]; } @@ -1436,9 +1466,9 @@ function Oa(a, b, c, d, e) { return e; } e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? Qa(e) : e; + return d ? Ta(e) : e; } -function Qa(a) { +function Ta(a) { for (let b = 0; b < a.length; b++) { a[b] = {score:b, id:a[b]}; } @@ -1488,19 +1518,19 @@ function Qa(a) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = d.concat([a.result])); - a.result = Ra(d, e, f, g, h, a.F); + a.result = Ua(d, e, f, g, h, a.F); return h ? a.result : a; }); } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ra(d, e, f, g, h, this.F)); + d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ua(d, e, f, g, h, this.F)); return h ? this.result : this; }; -function Ra(a, b, c, d, e, f) { +function Ua(a, b, c, d, e, f) { if (!a.length) { return a; } "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : va(a, c, b, e, f); + return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : ya(a, c, b, e, f); } ;X.prototype.and = function() { if (this.result.length) { @@ -1550,24 +1580,24 @@ function Ra(a, b, c, d, e, f) { if (a.length) { return Promise.all(a).then(function() { d = [b.result].concat(d); - b.result = Sa(d, e, f, g, b.F, h); + b.result = Va(d, e, f, g, b.F, h); return g ? b.result : b; }); } d = [this.result].concat(d); - this.result = Sa(d, e, f, g, this.F, h); + this.result = Va(d, e, f, g, this.F, h); return g ? this.result : this; } return this; }; -function Sa(a, b, c, d, e, f) { +function Va(a, b, c, d, e, f) { if (2 > a.length) { return []; } let g = []; B(); let h = ca(a); - return h ? ua(a, h, b, c, f, e, d) : g; + return h ? xa(a, h, b, c, f, e, d) : g; } ;X.prototype.xor = function() { const a = this; @@ -1613,14 +1643,14 @@ function Sa(a, b, c, d, e, f) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = [a.result].concat(d)); - a.result = Ta(d, e, f, g, !h, a.F); + a.result = Wa(d, e, f, g, !h, a.F); return h ? a.result : a; }); } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Ta(d, e, f, g, !h, a.F)); + d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Wa(d, e, f, g, !h, a.F)); return h ? this.result : this; }; -function Ta(a, b, c, d, e, f) { +function Wa(a, b, c, d, e, f) { if (!a.length) { return a; } @@ -1714,14 +1744,14 @@ function Ta(a, b, c, d, e, f) { } if (c.length) { return Promise.all(c).then(function() { - a.result = Ua.call(a, d, e, f, g); + a.result = Xa.call(a, d, e, f, g); return g ? a.result : a; }); } - d.length && (this.result = Ua.call(this, d, e, f, g)); + d.length && (this.result = Xa.call(this, d, e, f, g)); return g ? this.result : this; }; -function Ua(a, b, c, d) { +function Xa(a, b, c, d) { if (!a.length) { return this.result; } @@ -1751,7 +1781,7 @@ function Ua(a, b, c, d) { return e; } ;function X(a) { - if (!this) { + if (this.constructor !== X) { return new X(a); } if (a && a.index) { @@ -1796,12 +1826,12 @@ X.prototype.boost = function(a) { return this; }; X.prototype.resolve = function(a, b, c) { - Va = 1; + Ya = 1; const d = this.result; this.result = this.index = null; return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), W(d, a || 100, b, c)) : d; }; -let Va = 1; +let Ya = 1; L.prototype.search = function(a, b, c) { c || (!b && H(a) ? (c = a, a = "") : H(b) && (c = b, b = 0)); let d = [], e; @@ -1812,22 +1842,22 @@ L.prototype.search = function(a, b, c) { g = c.offset || 0; var p = c.context; f = c.suggest; - (h = Va && !1 !== c.resolve) || (Va = 0); + (h = Ya && !1 !== c.resolve) || (Ya = 0); k = h && c.enrich; m = c.boost; l = this.db && c.tag; } else { - h = this.resolve || Va; + h = this.resolve || Ya; } a = this.encoder.encode(a); e = a.length; b || !h || (b = 100); if (1 === e) { - return Wa.call(this, a[0], "", b, g, h, k, l); + return Za.call(this, a[0], "", b, g, h, k, l); } p = this.depth && !1 !== p; if (2 === e && p && !f) { - return Wa.call(this, a[0], a[1], b, g, h, k, l); + return Za.call(this, a[0], a[1], b, g, h, k, l); } let n = c = 0; if (1 < e) { @@ -1852,10 +1882,10 @@ L.prototype.search = function(a, b, c) { } let q = 0, t; if (1 === e) { - return Wa.call(this, a[0], "", b, g, h, k, l); + return Za.call(this, a[0], "", b, g, h, k, l); } if (2 === e && p && !f) { - return Wa.call(this, a[0], a[1], b, g, h, k, l); + return Za.call(this, a[0], a[1], b, g, h, k, l); } 1 < e && (p ? (t = a[0], q = 1) : 9 < c && 3 < c / n && a.sort(aa)); if (this.db) { @@ -1866,7 +1896,7 @@ L.prototype.search = function(a, b, c) { return async function() { for (let u, x; q < e; q++) { x = a[q]; - t ? (u = await Y(r, x, t, 0, 0, !1, !1), u = Xa(u, d, f, r.R), f && !1 === u && d.length || (t = x)) : (u = await Y(r, x, "", 0, 0, !1, !1), u = Xa(u, d, f, r.resolution)); + t ? (u = await Y(r, x, t, 0, 0, !1, !1), u = $a(u, d, f, r.R), f && !1 === u && d.length || (t = x)) : (u = await Y(r, x, "", 0, 0, !1, !1), u = $a(u, d, f, r.resolution)); if (u) { return u; } @@ -1885,12 +1915,12 @@ L.prototype.search = function(a, b, c) { } } } - return h ? ua(d, r.resolution, b, g, f, m, h) : new X(d[0]); + return h ? xa(d, r.resolution, b, g, f, m, h) : new X(d[0]); }(); } for (let r, u; q < e; q++) { u = a[q]; - t ? (r = Y(this, u, t, 0, 0, !1, !1), r = Xa(r, d, f, this.R), f && !1 === r && d.length || (t = u)) : (r = Y(this, u, "", 0, 0, !1, !1), r = Xa(r, d, f, this.resolution)); + t ? (r = Y(this, u, t, 0, 0, !1, !1), r = $a(r, d, f, this.R), f && !1 === r && d.length || (t = u)) : (r = Y(this, u, "", 0, 0, !1, !1), r = $a(r, d, f, this.resolution)); if (r) { return r; } @@ -1909,16 +1939,16 @@ L.prototype.search = function(a, b, c) { } } } - d = ua(d, this.resolution, b, g, f, m, h); + d = xa(d, this.resolution, b, g, f, m, h); return h ? d : new X(d); }; -function Wa(a, b, c, d, e, f, g) { +function Za(a, b, c, d, e, f, g) { a = Y(this, a, b, c, d, e, f, g); return this.db ? a.then(function(h) { return e ? h : h && h.length ? e ? W(h, c, d) : new X(h) : e ? [] : new X([]); }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); } -function Xa(a, b, c, d) { +function $a(a, b, c, d) { let e = []; if (a) { d = Math.min(a.length, d); @@ -1956,15 +1986,15 @@ function Y(a, b, c, d, e, f, g, h) { } } } else { - Ya(this.map, a), this.depth && Ya(this.ctx, a); + ab(this.map, a), this.depth && ab(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && Pa(this)); + this.db && (this.commit_task.push({del:a}), this.T && Sa(this)); this.cache && this.cache.remove(a); return this; }; -function Ya(a, b) { +function ab(a, b) { let c = 0; if (a.constructor === Array) { for (let d = 0, e, f; d < a.length; d++) { @@ -1979,24 +2009,24 @@ function Ya(a, b) { } } else { for (let d of a) { - const e = d[0], f = Ya(d[1], b); + const e = d[0], f = ab(d[1], b); f ? c += f : a.delete(e); } } return c; } ;function L(a, b) { - if (!this) { + if (this.constructor !== L) { return new L(a); } if (a) { var c = G(a) ? a : a.preset; - c && (Na[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Na[c], a)); + c && (Qa[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Qa[c], a)); } else { a = {}; } c = a.context || {}; - const d = G(a.encoder) ? Ma[a.encoder] : a.encode || a.encoder || Ea; + const d = G(a.encoder) ? Pa[a.encoder] : a.encode || a.encoder || Ha; this.encoder = d.encode ? d : "object" === typeof d ? new K(d) : {encode:d}; let e; this.resolution = a.resolution || 9; @@ -2033,7 +2063,7 @@ v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Pa(a) { +function Sa(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2057,7 +2087,7 @@ v.update = function(a, b) { const c = this, d = this.remove(a); return d && d.then ? d.then(() => c.add(a, b)) : this.add(a, b); }; -function Za(a) { +function bb(a) { let b = 0; if (a.constructor === Array) { for (let c = 0, d; c < a.length; c++) { @@ -2065,7 +2095,7 @@ function Za(a) { } } else { for (const c of a) { - const d = c[0], e = Za(c[1]); + const d = c[0], e = bb(c[1]); e ? b += e : a.delete(d); } } @@ -2075,63 +2105,47 @@ v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Za(this.map); - this.depth && Za(this.ctx); + bb(this.map); + this.depth && bb(this.ctx); return this; }; -v.searchCache = Da; -v.export = function(a, b, c, d, e, f) { - let g = !0; - "undefined" === typeof f && (g = new Promise(l => { - f = l; - })); - let h, k; - switch(e || (e = 0)) { +v.searchCache = Ga; +v.export = function(a, b, c, d = 0) { + let e, f; + switch(d) { case 0: - h = "reg"; - if (this.fastupdate) { - k = B(); - for (let l of this.reg.keys()) { - k[l] = 1; - } - } else { - k = this.reg; - } + e = "reg"; + f = qa(this.reg); break; case 1: - h = "cfg"; - k = {doc:0, opt:this.h ? 1 : 0}; + e = "cfg"; + f = {}; break; case 2: - h = "map"; - k = this.map; + e = "map"; + f = oa(this.map); break; case 3: - h = "ctx"; - k = this.ctx; + e = "ctx"; + f = pa(this.ctx); break; default: - "undefined" === typeof c && f && f(); return; } - oa(a, b || this, c, h, d, e, k, f); - return g; + return ra.call(this, a, b, e, c, d, f); }; v.import = function(a, b) { if (b) { switch(G(b) && (b = JSON.parse(b)), a) { - case "cfg": - this.h = !!b.opt; - break; case "reg": this.fastupdate = !1; - this.reg = b; + this.reg = new Set(b); break; case "map": - this.map = b; + this.map = new Map(b); break; case "ctx": - this.ctx = b; + this.ctx = new Map(b); } } }; @@ -2186,10 +2200,10 @@ v.serialize = function(a = !0) { return a ? "function inject(index){" + b + d + e + "}" : b + d + e; }; na(L.prototype); -const ab = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), bb = ["map", "ctx", "tag", "reg", "cfg"]; -function cb(a, b = {}) { +const db = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), eb = ["map", "ctx", "tag", "reg", "cfg"]; +function fb(a, b = {}) { if (!this) { - return new cb(a, b); + return new fb(a, b); } "object" === typeof a && (b = a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2199,7 +2213,7 @@ function cb(a, b = {}) { this.db = null; this.h = {}; } -v = cb.prototype; +v = fb.prototype; v.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2211,10 +2225,10 @@ v.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const d = ab.open(a.id + (a.field ? ":" + a.field : ""), 1); + const d = db.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { const e = a.db = this.result; - bb.forEach(f => { + eb.forEach(f => { e.objectStoreNames.contains(f) || e.createObjectStore(f); }); }; @@ -2240,12 +2254,12 @@ v.close = function() { this.db = null; }; v.destroy = function() { - return ab.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return db.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); }; v.clear = function() { - const a = this.db.transaction(bb, "readwrite"); - for (let b = 0; b < bb.length; b++) { - a.objectStore(bb[b]).clear(); + const a = this.db.transaction(eb, "readwrite"); + for (let b = 0; b < eb.length; b++) { + a.objectStore(eb[b]).clear(); } return Z(a); }; @@ -2429,7 +2443,7 @@ v.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function db(a, b, c) { +function gb(a, b, c) { const d = a.value; let e, f, g = 0; for (let h = 0, k; h < d.length; h++) { @@ -2458,17 +2472,17 @@ v.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && db(c, a); + c && gb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && db(c, a); + c && gb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && db(c, a, !0); + c && gb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2488,6 +2502,6 @@ function Z(a) { a = null; }); } -;export default {Index:L, Charset:Ma, Encoder:K, Document:T, Worker:N, Resolver:X, IndexedDB:cb, Language:{}}; +;export default {Index:L, Charset:Pa, Encoder:K, Document:T, Worker:N, Resolver:X, IndexedDB:fb, Language:{}}; -export const Index=L;export const Charset=Ma;export const Encoder=K;export const Document=T;export const Worker=N;export const Resolver=X;export const IndexedDB=cb;export const Language={}; \ No newline at end of file +export const Index=L;export const Charset=Pa;export const Encoder=K;export const Document=T;export const Worker=N;export const Resolver=X;export const IndexedDB=fb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 75dc11d..e131e54 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -12,7 +12,7 @@ function F(a){return"string"===typeof a}function G(a){return"object"===typeof a} "i"],["\u01d2","o"],["\u01d4","u"],["\u01d6","u"],["\u01d8","u"],["\u01da","u"],["\u01dc","u"],["\u01df","a"],["\u01e1","a"],["\u01e3","ae"],["\u00e6","ae"],["\u01fd","ae"],["\u01e7","g"],["\u01e9","k"],["\u01eb","o"],["\u01ed","o"],["\u01ef","\u0292"],["\u01f0","j"],["\u01f3","dz"],["\u01f5","g"],["\u01f9","n"],["\u01fb","a"],["\u01ff","\u00f8"],["\u0201","a"],["\u0203","a"],["\u0205","e"],["\u0207","e"],["\u0209","i"],["\u020b","i"],["\u020d","o"],["\u020f","o"],["\u0211","r"],["\u0213","r"],["\u0215", "u"],["\u0217","u"],["\u0219","s"],["\u021b","t"],["\u021f","h"],["\u0227","a"],["\u0229","e"],["\u022b","o"],["\u022d","o"],["\u022f","o"],["\u0231","o"],["\u0233","y"],["\u02b0","h"],["\u02b1","h"],["\u0266","h"],["\u02b2","j"],["\u02b3","r"],["\u02b4","\u0279"],["\u02b5","\u027b"],["\u02b6","\u0281"],["\u02b7","w"],["\u02b8","y"],["\u02e0","\u0263"],["\u02e1","l"],["\u02e2","s"],["\u02e3","x"],["\u02e4","\u0295"],["\u0390","\u03b9"],["\u03ac","\u03b1"],["\u03ad","\u03b5"],["\u03ae","\u03b7"],["\u03af", "\u03b9"],["\u03b0","\u03c5"],["\u03ca","\u03b9"],["\u03cb","\u03c5"],["\u03cc","\u03bf"],["\u03cd","\u03c5"],["\u03ce","\u03c9"],["\u03d0","\u03b2"],["\u03d1","\u03b8"],["\u03d2","\u03a5"],["\u03d3","\u03a5"],["\u03d4","\u03a5"],["\u03d5","\u03c6"],["\u03d6","\u03c0"],["\u03f0","\u03ba"],["\u03f1","\u03c1"],["\u03f2","\u03c2"],["\u03f5","\u03b5"],["\u0439","\u0438"],["\u0450","\u0435"],["\u0451","\u0435"],["\u0453","\u0433"],["\u0457","\u0456"],["\u045c","\u043a"],["\u045d","\u0438"],["\u045e","\u0443"], -["\u0477","\u0475"],["\u04c2","\u0436"],["\u04d1","\u0430"],["\u04d3","\u0430"],["\u04d7","\u0435"],["\u04db","\u04d9"],["\u04dd","\u0436"],["\u04df","\u0437"],["\u04e3","\u0438"],["\u04e5","\u0438"],["\u04e7","\u043e"],["\u04eb","\u04e9"],["\u04ed","\u044d"],["\u04ef","\u0443"],["\u04f1","\u0443"],["\u04f3","\u0443"],["\u04f5","\u0447"]];const ea=/[^\p{L}\p{N}]+/u,fa=/(\d{3})/g,ha=/(\D)(\d{3})/g,ia=/(\d{3})(\D)/g,ja="".normalize&&/[\u0300-\u036f]/g;function K(a){if(!this)return new K(...arguments);for(let b=0;bthis.stemmer.get(l)),k=1);g&&k&&(g.length< this.minlength||this.filter&&this.filter.has(g))&&(g="");if(g&&(this.mapper||this.dedupe&&1this.matcher.get(l)));if(g&&this.replacer)for(e=0;g&&ethis.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function ka(a){a.L=null;a.H.clear();a.J.clear()};async function la(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};(b=d.config)&&(d=(await import(b))["default"]);(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new L(d);postMessage({id:a.id});break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let M=0; -function N(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=B();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++M]=function(){k(e)};e.worker.postMessage({id:M,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!==typeof window? -window._factory:null;c&&(c=c.toString());const d="undefined"===typeof window,e=this,f=ma(c,d,a.worker);return f.then?f.then(function(g){return b.call(e,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); +function N(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=B();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++M]=function(){k(e)};e.worker.postMessage({id:M,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(this.constructor!==N)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;c&&(c=c.toString());const d="undefined"===typeof window,e=this,f=ma(c,d,a.worker);return f.then?f.then(function(g){return b.call(e,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); function O(a){N.prototype[a]=N.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;"function"===typeof d&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){b.h[++M]=f;b.worker.postMessage({task:a,id:M,args:c})});return e?(d.then(e),this):d}} function ma(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/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="+la.toString()],{type:"text/javascript"}))):new window.Worker(F(c)?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function na(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}function P(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function oa(a,b,c,d,e,f,g,h){(d=a(c?c+"."+d:d,JSON.stringify(g)))&&d.then?d.then(function(){b.export(a,b,c,e,f+1,h)}):b.export(a,b,c,e,f+1,h)};function pa(a,b,c,d){let e=[];for(let f=0,g;f=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} +"module/worker/worker.js"),{type:"module"})};function na(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}function P(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function oa(a){const b=[];for(const c of a.entries())b.push(c);return b}function pa(a){const b=[];for(const c of a.entries())b.push(oa(c));return b}function qa(a){const b=[];for(const c of a.keys())b.push(c);return b}function ra(a,b,c,d,e,f){if((c=a(b?b+"."+c:c,JSON.stringify(f)))&&c.then){const g=this;return c.then(function(){return g.export(a,b,d,e+1)})}return this.export(a,b,d,e+1)};function sa(a,b,c,d){let e=[];for(let f=0,g;f=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} function Q(a){if(!this)return new Q(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(let p=0,n;pd)d-=n.length; +this.C[k];if((c=l.I)&&!c(b))continue;let m;if("function"===typeof l){m=l(b);if(!m)continue;l=[l.U]}else if(F(l)||l.constructor===String){h[l]=b[l];continue}wa(b,h,l,0,l[0],m)}}this.store.set(a,h||b)}}return this};function wa(a,b,c,d,e,f){a=a[e];if(d===c.length-1)b[e]=f||a;else if(a)if(a.constructor===Array)for(b=b[e]=Array(a.length),e=0;ec||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(let p=0,n;pd)d-=n.length; else{if(n.length>c||d)n=n.slice(d,c+d),c-=n.length,d&&(d-=n.length);e.push(n);if(!c)break}k=1c||d)a=a.slice(d,d+c);e&&(a=ya.call(this,a));return a}} -function ya(a){const b=Array(a.length);for(let c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=Ba.call(this,a));return a}} +function Ba(a){const b=Array(a.length);for(let c=0,d;c{f=k}));e||(e=0);d||(d=0);if(dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -U.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const Ea={normalize:function(a){return a.toLowerCase()},dedupe:!1};const Fa=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 Ga=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ha=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const Ia={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};const Ja=/[\x00-\x7F]+/g;const Ka=/[\x00-\x7F]+/g;const La=/[\x00-\x7F]+/g;var Ma={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ea,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Fa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Fa,matcher:Ga,replacer:Ha},LatinExtra:{normalize:!0,dedupe:!0,mapper:Fa,replacer:Ha.concat([/(?!^)[aeo]/g,""]),matcher:Ga},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=r.substring(f,h);var k=this.score?this.score(b,r,q,g,f):Oa(n,d,q,e,f);V(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,q,h-1,k-1),u=this.bidirectional&&r>f;V(this,l,u?f:r,t,a,c,u?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.T&&Pa(this));return this};function V(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new Q(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function Oa(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Qa(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Qa(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length?e?W(a[0],b,c,d):a[0]:va(a,c,b,e,f)};X.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];B();let h=ca(a);return h?ua(a,h,b,c,f,e,d):g};X.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?W(a[0],b,c,d):a[0];d=[];const g=B();let h=0;for(let k=0,l;kthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +U.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const Ha={normalize:function(a){return a.toLowerCase()},dedupe:!1};const Ia=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 Ja=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Ka=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const La={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};const Ma=/[\x00-\x7F]+/g;const Na=/[\x00-\x7F]+/g;const Oa=/[\x00-\x7F]+/g;var Pa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ha,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ia},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ia,matcher:Ja,replacer:Ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ia,replacer:Ka.concat([/(?!^)[aeo]/g,""]),matcher:Ja},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=r.substring(f,h);var k=this.score?this.score(b,r,q,g,f):Ra(n,d,q,e,f);V(this,m,g,k,a,c)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,q,h-1,k-1),u=this.bidirectional&&r>f;V(this,l,u?f:r,t,a,c,u?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&Sa(this));return this};function V(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=B()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new Q(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +function Ra(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Ta(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Ta(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length?e?W(a[0],b,c,d):a[0]:ya(a,c,b,e,f)};X.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];B();let h=ca(a);return h?xa(a,h,b,c,f,e,d):g};X.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?W(a[0],b,c,d):a[0];d=[];const g=B();let h=0;for(let k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};L.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else Ya(this.map,a),this.depth&&Ya(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Pa(this));this.cache&&this.cache.remove(a);return this}; -function Ya(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};L.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else ab(this.map,a),this.depth&&ab(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Sa(this));this.cache&&this.cache.remove(a);return this}; +function ab(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; -function $a(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=B();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof c&&f&&f();return}oa(a,b||this,c,h,d,e,k,f);return g}; -v.import=function(a,b){if(b)switch(F(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; +function cb(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -v.close=function(){this.db.close();this.db=null};v.destroy=function(){return ab.deleteDatabase(this.id+(this.field?":"+this.field:""))};v.clear=function(){const a=this.db.transaction(bb,"readwrite");for(let b=0;b{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +v.close=function(){this.db.close();this.db=null};v.destroy=function(){return db.deleteDatabase(this.id+(this.field?":"+this.field:""))};v.clear=function(){const a=this.db.transaction(eb,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const p=c?d+Math.min(m.length-d,c):m.length;for(let n=d;n=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; v.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;dm&&!f&&"string"===typeof p&&!isNaN(p)&&(m=k.indexOf(parseInt(p,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:L,Charset:Ma,Encoder:K,Document:T,Worker:N,Resolver:X,IndexedDB:cb,Language:{}}; -export const Index=L;export const Charset=Ma;export const Encoder=K;export const Document=T;export const Worker=N;export const Resolver=X;export const IndexedDB=cb;export const Language={}; \ No newline at end of file +function gb(a,b,c){const d=a.value;let e,f,g=0;for(let h=0,k;hm&&!f&&"string"===typeof p&&!isNaN(p)&&(m=k.indexOf(parseInt(p,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:L,Charset:Pa,Encoder:K,Document:T,Worker:N,Resolver:X,IndexedDB:fb,Language:{}}; +export const Index=L;export const Charset=Pa;export const Encoder=K;export const Document=T;export const Worker=N;export const Resolver=X;export const IndexedDB=fb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 4f6ce03..da392ff 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -50,14 +50,14 @@ function C() { function aa(a, c) { return c.length - a.length; } -function D(a) { +function E(a) { return "string" === typeof a; } function H(a) { return "object" === typeof a; } function I(a, c) { - if (D(c)) { + if (E(c)) { a = a[c]; } else { for (let b = 0; a && b < c.length; b++) { @@ -75,15 +75,15 @@ function I(a, c) { "\u03b8"], ["\u03d2", "\u03a5"], ["\u03d3", "\u03a5"], ["\u03d4", "\u03a5"], ["\u03d5", "\u03c6"], ["\u03d6", "\u03c0"], ["\u03f0", "\u03ba"], ["\u03f1", "\u03c1"], ["\u03f2", "\u03c2"], ["\u03f5", "\u03b5"], ["\u0439", "\u0438"], ["\u0450", "\u0435"], ["\u0451", "\u0435"], ["\u0453", "\u0433"], ["\u0457", "\u0456"], ["\u045c", "\u043a"], ["\u045d", "\u0438"], ["\u045e", "\u0443"], ["\u0477", "\u0475"], ["\u04c2", "\u0436"], ["\u04d1", "\u0430"], ["\u04d3", "\u0430"], ["\u04d7", "\u0435"], ["\u04db", "\u04d9"], ["\u04dd", "\u0436"], ["\u04df", "\u0437"], ["\u04e3", "\u0438"], ["\u04e5", "\u0438"], ["\u04e7", "\u043e"], ["\u04eb", "\u04e9"], ["\u04ed", "\u044d"], ["\u04ef", "\u0443"], ["\u04f1", "\u0443"], ["\u04f3", "\u0443"], ["\u04f5", "\u0447"]]; const ca = /[^\p{L}\p{N}]+/u, da = /(\d{3})/g, ea = /(\D)(\d{3})/g, fa = /(\d{3})(\D)/g, J = "".normalize && /[\u0300-\u036f]/g; -function L(a) { - if (!this) { - return new L(...arguments); +function K(a) { + if (this.constructor !== K) { + return new K(...arguments); } for (let c = 0; c < arguments.length; c++) { this.assign(arguments[c]); } } -L.prototype.assign = function(a) { +K.prototype.assign = function(a) { this.normalize = B(a.normalize, !0, this.normalize); let c = a.include, b = c || a.exclude || a.split; if ("object" === typeof b) { @@ -124,7 +124,7 @@ L.prototype.assign = function(a) { this.minlength = B(a.minlength, 1, this.minlength); this.maxlength = B(a.maxlength, 0, this.maxlength); if (this.cache = b = B(a.cache, !0, this.cache)) { - this.J = null, this.O = "number" === typeof b ? b : 2e5, this.F = new Map(), this.H = new Map(), this.D = this.h = 128; + this.I = null, this.O = "number" === typeof b ? b : 2e5, this.D = new Map(), this.G = new Map(), this.J = this.A = 128; } this.K = ""; this.M = null; @@ -142,14 +142,14 @@ L.prototype.assign = function(a) { } return this; }; -L.prototype.encode = function(a) { - if (this.cache && a.length <= this.h) { - if (this.J) { - if (this.F.has(a)) { - return this.F.get(a); +K.prototype.encode = function(a) { + if (this.cache && a.length <= this.A) { + if (this.I) { + if (this.D.has(a)) { + return this.D.get(a); } } else { - this.J = setTimeout(ha, 50, this); + this.I = setTimeout(ha, 50, this); } } this.normalize && (a = "function" === typeof this.normalize ? this.normalize(a) : J ? a.normalize("NFKD").replace(J, "").toLowerCase() : a.toLowerCase()); @@ -171,15 +171,15 @@ L.prototype.encode = function(a) { if (this.filter && this.filter.has(g)) { continue; } - if (this.cache && g.length <= this.D) { - if (this.J) { - var d = this.H.get(g); + if (this.cache && g.length <= this.J) { + if (this.I) { + var d = this.G.get(g); if (d || "" === d) { d && b.push(d); continue; } } else { - this.J = setTimeout(ha, 50, this); + this.I = setTimeout(ha, 50, this); } } let k; @@ -198,17 +198,17 @@ L.prototype.encode = function(a) { g = g.replace(this.replacer[d], this.replacer[d + 1]); } } - this.cache && h.length <= this.D && (this.H.set(h, g), this.H.size > this.O && (this.H.clear(), this.D = this.D / 1.1 | 0)); + this.cache && h.length <= this.J && (this.G.set(h, g), this.G.size > this.O && (this.G.clear(), this.J = this.J / 1.1 | 0)); g && b.push(g); } this.finalize && (b = this.finalize(b) || b); - this.cache && a.length <= this.h && (this.F.set(a, b), this.F.size > this.O && (this.F.clear(), this.h = this.h / 1.1 | 0)); + this.cache && a.length <= this.A && (this.D.set(a, b), this.D.size > this.O && (this.D.clear(), this.A = this.A / 1.1 | 0)); return b; }; function ha(a) { - a.J = null; - a.F.clear(); - a.H.clear(); + a.I = null; + a.D.clear(); + a.G.clear(); } ;function ia(a) { M.call(a, "add"); @@ -228,12 +228,37 @@ function M(a) { return c; }; } -;function ja(a, c, b, e, d, f, g, h) { - (e = a(b ? b + "." + e : e, JSON.stringify(g))) && e.then ? e.then(function() { - c.export(a, c, b, d, f + 1, h); - }) : c.export(a, c, b, d, f + 1, h); +;function N(a) { + const c = []; + for (const b of a.entries()) { + c.push(b); + } + return c; } -;N.prototype.add = function(a, c, b) { +function ja(a) { + const c = []; + for (const b of a.entries()) { + c.push(N(b)); + } + return c; +} +function ka(a) { + const c = []; + for (const b of a.keys()) { + c.push(b); + } + return c; +} +function la(a, c, b, e, d, f) { + if ((b = a(c ? c + "." + b : b, JSON.stringify(f))) && b.then) { + const g = this; + return b.then(function() { + return g.export(a, c, e, d + 1); + }); + } + return this.export(a, c, e, d + 1); +} +;O.prototype.add = function(a, c, b) { H(a) && (c = a, a = I(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { @@ -246,8 +271,8 @@ function M(a) { var d = k(c); d && e.add(a, d, !1, !0); } else { - if (d = k.G, !d || d(c)) { - k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), O(c, k, this.I, 0, e, a, k[0], b); + if (d = k.F, !d || d(c)) { + k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), P(c, k, this.H, 0, e, a, k[0], b); } } } @@ -261,7 +286,7 @@ function M(a) { continue; } } else { - const k = f.G; + const k = f.F; if (k && !k(c)) { continue; } @@ -269,7 +294,7 @@ function M(a) { f = I(c, f); } if (d && f) { - D(f) && (f = [f]); + E(f) && (f = [f]); for (let k = 0, l, m; k < f.length; k++) { l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } @@ -280,11 +305,11 @@ function M(a) { } if (this.store && (!b || !this.store.has(a))) { let h; - if (this.A) { + if (this.h) { h = C(); - for (let k = 0, l; k < this.A.length; k++) { - l = this.A[k]; - if ((b = l.G) && !b(c)) { + for (let k = 0, l; k < this.h.length; k++) { + l = this.h[k]; + if ((b = l.F) && !b(c)) { continue; } let m; @@ -294,11 +319,11 @@ function M(a) { continue; } l = [l.S]; - } else if (D(l) || l.constructor === String) { + } else if (E(l) || l.constructor === String) { h[l] = c[l]; continue; } - P(c, h, l, 0, l[0], m); + Q(c, h, l, 0, l[0], m); } } this.store.set(a, h || c); @@ -306,21 +331,21 @@ function M(a) { } return this; }; -function P(a, c, b, e, d, f) { +function Q(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++) { - P(a, c, b, e, d); + Q(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], P(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], Q(a, c, b, e, d); } } } -function O(a, c, b, e, d, f, g, h) { +function P(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -336,15 +361,15 @@ function O(a, c, b, e, d, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - O(a, c, b, e, d, f, g, h); + P(a, c, b, e, d, f, g, h); } } else { - g = c[++e], O(a, c, b, e, d, f, g, h); + g = c[++e], P(a, c, b, e, d, f, g, h); } } } } -;function ka(a, c) { +;function ma(a, c) { const b = C(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -357,7 +382,7 @@ function O(a, c, b, e, d, f, g, h) { } return e; } -;N.prototype.search = function(a, c, b, e) { +;O.prototype.search = function(a, c, b, e) { b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let d = []; var f = []; @@ -380,7 +405,7 @@ function O(a, c, b, e, d, f, g, h) { var u = []; for (let w = 0, q; w < m.length; w++) { q = m[w]; - if (D(q)) { + if (E(q)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (q.field && q.tag) { @@ -394,8 +419,8 @@ function O(a, c, b, e, d, f, g, h) { } } else { v = Object.keys(q); - for (let E = 0, A, z; E < v.length; E++) { - if (A = v[E], z = q[A], z.constructor === Array) { + for (let D = 0, A, z; D < v.length; D++) { + if (A = v[D], z = q[A], z.constructor === Array) { for (y = 0; y < z.length; y++) { u.push(A, z[y]); } @@ -413,7 +438,7 @@ function O(a, c, b, e, d, f, g, h) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - r = la.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:r}); + r = na.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:r}); } } return e.length ? Promise.all(e).then(function(w) { @@ -424,18 +449,18 @@ function O(a, c, b, e, d, f, g, h) { }) : d; } } - D(l) && (l = [l]); + E(l) && (l = [l]); } l || (l = this.field); u = !e && (this.worker || this.db) && []; - for (let w = 0, q, E, A; w < l.length; w++) { - E = l[w]; + for (let w = 0, q, D, A; w < l.length; w++) { + D = l[w]; let z; - D(E) || (z = E, E = z.field, a = z.query || a, c = z.limit || c, n = z.offset || n, k = z.suggest || k, g = this.store && (z.enrich || g)); + E(D) || (z = D, D = z.field, a = z.query || a, c = z.limit || c, n = z.offset || n, k = z.suggest || k, g = this.store && (z.enrich || g)); if (e) { q = e[w]; } else { - if (v = z || b, y = this.index.get(E), m && (v.enrich = !1), u) { + if (v = z || b, y = this.index.get(D), m && (v.enrich = !1), u) { u[w] = y.search(a, c, v); v && g && (v.enrich = g); continue; @@ -447,7 +472,7 @@ function O(a, c, b, e, d, f, g, h) { if (m && A) { v = []; y = 0; - for (let G = 0, F, K; G < m.length; G += 2) { + for (let G = 0, F, L; G < m.length; G += 2) { F = this.tag.get(m[G]); if (!F) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { @@ -456,14 +481,14 @@ function O(a, c, b, e, d, f, g, h) { return d; } } - if (K = (F = F && F.get(m[G + 1])) && F.length) { + if (L = (F = F && F.get(m[G + 1])) && F.length) { y++, v.push(F); } else if (!k) { return d; } } if (y) { - q = ka(q, v); + q = ma(q, v); A = q.length; if (!A && !k) { return d; @@ -472,7 +497,7 @@ function O(a, c, b, e, d, f, g, h) { } } if (A) { - f[t] = E, d.push(q), t++; + f[t] = D, d.push(q), t++; } else if (1 === l.length) { return d; } @@ -492,15 +517,15 @@ function O(a, c, b, e, d, f, g, h) { u = []; for (let w = 0, q; w < f.length; w++) { q = d[w]; - g && q.length && !q[0].doc && q.length && (q = ma.call(this, q)); + g && q.length && !q[0].doc && q.length && (q = oa.call(this, q)); if (r) { return q; } d[w] = {field:f[w], result:q}; } - return h ? na(d, c) : p ? oa(d, a, this.index, this.field, this.C, p) : d; + return h ? pa(d, c) : p ? qa(d, a, this.index, this.field, this.C, p) : d; }; -function oa(a, c, b, e, d, f) { +function qa(a, c, b, e, d, f) { let g, h, k; for (let m = 0, n, t, p, r, u; m < a.length; m++) { n = a[m].result; @@ -515,21 +540,21 @@ function oa(a, c, b, e, d, f) { var l = I(n[v].doc, u); let w = g.encode(l); l = l.split(g.split); - for (let q = 0, E, A; q < w.length; q++) { - E = w[q]; + for (let q = 0, D, A; q < w.length; q++) { + D = w[q]; A = l[q]; let z; for (let G = 0, F; G < h.length; G++) { if (F = h[G], "strict" === k) { - if (E === F) { + if (D === F) { y += (y ? " " : "") + f.replace("$1", A); z = !0; break; } } else { - const K = E.indexOf(F); - if (-1 < K) { - y += (y ? " " : "") + A.substring(0, K) + f.replace("$1", A.substring(K, F.length)) + A.substring(K + F.length); + const L = D.indexOf(F); + if (-1 < L) { + y += (y ? " " : "") + A.substring(0, L) + f.replace("$1", A.substring(L, F.length)) + A.substring(L + F.length); z = !0; break; } @@ -542,7 +567,7 @@ function oa(a, c, b, e, d, f) { } return a; } -function na(a, c) { +function pa(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -561,7 +586,7 @@ function na(a, c) { } return b; } -function la(a, c, b, e, d) { +function na(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -570,43 +595,43 @@ function la(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = ma.call(this, f)); + d && (f = oa.call(this, f)); return f; } } -function ma(a) { +function oa(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 N(a) { - if (!this) { - return new N(a); +;function O(a) { + if (this.constructor !== O) { + return new O(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; - this.I = []; - this.key = (b = c.key || c.id) && Q(b, this.I) || "id"; + this.H = []; + this.key = (b = c.key || c.id) && R(b, this.H) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); - this.A = (b = c.store || null) && !0 !== b && []; + this.h = (b = c.store || null) && !0 !== b && []; this.store = b && new Map(); - this.cache = (b = a.cache || null) && new R(b); + this.cache = (b = a.cache || null) && new S(b); a.cache = !1; b = new Map(); let e = c.index || c.field || c; - D(e) && (e = [e]); + E(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], D(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, b.set(f, new S(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Q(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].G = g.filter)), this.field[d] = f; + f = e[d], E(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, b.set(f, new T(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = R(f, this.H), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].F = g.filter)), this.field[d] = f; } - if (this.A) { + if (this.h) { a = c.store; - D(a) && (a = [a]); + E(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Q(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.h[d] = f.custom, f.custom.S = g) : (this.h[d] = R(g, this.H), f.filter && ("string" === typeof this.h[d] && (this.h[d] = new String(this.h[d])), this.h[d].F = f.filter)); } } this.index = b; @@ -622,14 +647,14 @@ function ma(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Q(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].G = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = R(g, this.H), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].F = f.filter)); this.R[d] = g; this.tag.set(g, new Map()); } } } } -function Q(a, c) { +function R(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -638,7 +663,7 @@ function Q(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -x = N.prototype; +x = O.prototype; x.append = function(a, c) { return this.add(a, c, !0); }; @@ -694,65 +719,70 @@ x.set = function(a, c) { this.store.set(a, c); return this; }; -x.searchCache = pa; -x.export = function(a, c, b, e, d, f) { - let g; - "undefined" === typeof f && (g = new Promise(k => { - f = k; - })); - d || (d = 0); - e || (e = 0); - if (e < this.field.length) { - b = this.field[e]; - var h = this.index[b]; - c = this; - h.export(a, c, d ? b : "", e, d++, f) || (e++, c.export(a, c, b, e, 1, f)); - } else { - switch(d) { - case 1: - c = "tag"; - h = this.D; - b = null; - break; - case 2: - c = "store"; - h = this.store; - b = null; - break; - default: - f(); - return; +x.searchCache = ra; +x.export = function(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, e = 0); + }); } - ja(a, this, b, c, e, d, h, f); + return this.export(a, g, b + 1, e = 0); } - return g; + let d, f; + switch(e) { + case 0: + d = "reg"; + f = ka(this.reg); + c = null; + break; + case 1: + d = "tag"; + f = ja(this.tag); + c = null; + break; + case 2: + d = "doc"; + f = N(this.store); + c = null; + break; + case 3: + d = "cfg"; + f = {}; + c = null; + break; + default: + return; + } + return la.call(this, a, c, d, b, e, f); }; x.import = function(a, c) { if (c) { - switch(D(c) && (c = JSON.parse(c)), a) { + switch(E(c) && (c = JSON.parse(c)), a) { case "tag": - this.D = c; break; case "reg": this.fastupdate = !1; - this.reg = c; + this.reg = new Set(c); for (let e = 0, d; e < this.field.length; e++) { - d = this.index[this.field[e]], d.reg = c, d.fastupdate = !1; + d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; - case "store": - this.store = c; + case "doc": + this.store = new Map(c); break; default: a = a.split("."); const b = a[0]; a = a[1]; - b && a && this.index[b].import(a, c); + b && a && this.index.get(b).import(a, c); } } }; -ia(N.prototype); -function pa(a, c, b) { +ia(O.prototype); +function ra(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); let e = this.cache.get(a); if (!e) { @@ -768,57 +798,57 @@ function pa(a, c, b) { } return e; } -function R(a) { +function S(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); - this.h = ""; + this.A = ""; } -R.prototype.set = function(a, c) { - this.cache.set(this.h = a, c); +S.prototype.set = function(a, c) { + this.cache.set(this.A = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -R.prototype.get = function(a) { +S.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)); + c && this.A !== a && (this.cache.delete(a), this.cache.set(this.A = a, c)); return c; }; -R.prototype.remove = function(a) { +S.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -R.prototype.clear = function() { +S.prototype.clear = function() { this.cache.clear(); - this.h = ""; + this.A = ""; }; -const qa = {normalize:function(a) { +const sa = {normalize:function(a) { return a.toLowerCase(); }, dedupe:!1}; -const T = 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 ra = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), sa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const ta = {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}; -const ua = /[\x00-\x7F]+/g; -const va = /[\x00-\x7F]+/g; +const U = 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"], ["pf", "f"]]), ua = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\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}; const wa = /[\x00-\x7F]+/g; -var xa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:qa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:T}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:T, matcher:ra, replacer:sa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:T, replacer:sa.concat([/(?!^)[aeo]/g, ""]), matcher:ra}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const xa = /[\x00-\x7F]+/g; +const ya = /[\x00-\x7F]+/g; +var za = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:sa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:U}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:U, matcher:ta, replacer:ua}, LatinExtra:{normalize:!0, dedupe:!0, mapper:U, replacer:ua.concat([/(?!^)[aeo]/g, ""]), matcher:ta}, LatinSoundex:{normalize:!0, 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 = ta[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = ta[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = va[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = va[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ua, " "); -}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(va, ""); -}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { return ("" + a).replace(wa, " "); +}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { + return ("" + a).replace(xa, ""); +}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(ya, " "); }}}; -const ya = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +const Aa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; C(); -S.prototype.add = function(a, c, b, e) { +T.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -830,15 +860,15 @@ S.prototype.add = function(a, c, b, e) { let r = c[this.rtl ? e - 1 - p : p]; var d = r.length; if (d && (n || !m[r])) { - var f = this.score ? this.score(c, r, p, null, 0) : U(t, e, p), g = ""; + var f = this.score ? this.score(c, r, p, null, 0) : V(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var h = d; h > f; h--) { g = r.substring(f, h); - var k = this.score ? this.score(c, r, p, g, f) : U(t, e, p, d, f); - V(this, m, g, k, a, b); + var k = this.score ? this.score(c, r, p, g, f) : V(t, e, p, d, f); + W(this, m, g, k, a, b); } } break; @@ -846,24 +876,24 @@ S.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - g = r[h] + g, k = this.score ? this.score(c, r, p, g, h) : U(t, e, p, d, h), V(this, m, g, k, a, b); + g = r[h] + g, k = this.score ? this.score(c, r, p, g, h) : V(t, e, p, d, h), W(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { for (h = 0; h < d; h++) { - g += r[h], V(this, m, g, f, a, b); + g += r[h], W(this, m, g, f, a, b); } break; } default: - if (V(this, m, r, f, a, b), n && 1 < e && p < e - 1) { + if (W(this, m, r, f, a, b), n && 1 < e && p < e - 1) { for (d = C(), g = this.P, f = r, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { if ((r = c[this.rtl ? e - 1 - p - k : p + k]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(c, f, p, r, k) : U(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), v = this.bidirectional && r > f; - V(this, l, v ? f : r, u, a, b, v ? r : f); + const u = this.score ? this.score(c, f, p, r, k) : V(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), v = this.bidirectional && r > f; + W(this, l, v ? f : r, u, a, b, v ? r : f); } } } @@ -875,16 +905,16 @@ S.prototype.add = function(a, c, b, e) { } return this; }; -function V(a, c, b, e, d, f, g) { +function W(a, c, b, e, d, f, g) { let h = g ? a.ctx : a.map, k; if (!c[b] || g && !(k = c[b])[g]) { g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function U(a, c, b, e, d) { +function V(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;function za(a, c, b) { +;function Ba(a, c, b) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } @@ -914,7 +944,7 @@ function U(a, c, b, e, d) { } return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; } -;S.prototype.search = function(a, c, b) { +;T.prototype.search = function(a, c, b) { b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { @@ -928,11 +958,11 @@ function U(a, c, b, e, d) { b = a.length; c || (c = 100); if (1 === b) { - return W.call(this, a[0], "", c, d); + return X.call(this, a[0], "", c, d); } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return W.call(this, a[0], a[1], c, d); + return X.call(this, a[0], a[1], c, d); } var h = 0, k = 0; if (1 < b) { @@ -940,7 +970,7 @@ function U(a, c, b, e, d) { const n = []; for (let t = 0, p; t < b; t++) { if ((p = a[t]) && !l[p]) { - if (g || X(this, p)) { + if (g || Y(this, p)) { n.push(p), l[p] = 1; } else { return e; @@ -958,10 +988,10 @@ function U(a, c, b, e, d) { } l = 0; if (1 === b) { - return W.call(this, a[0], "", c, d); + return X.call(this, a[0], "", c, d); } if (2 === b && f && !g) { - return W.call(this, a[0], a[1], c, d); + return X.call(this, a[0], a[1], c, d); } if (1 < b) { if (f) { @@ -973,7 +1003,7 @@ function U(a, c, b, e, d) { } for (let n, t; l < b; l++) { t = a[l]; - m ? (n = X(this, t, m), n = Aa(n, e, g, this.P), g && !1 === n && e.length || (m = t)) : (n = X(this, t, ""), n = Aa(n, e, g, this.resolution)); + m ? (n = Y(this, t, m), n = Ca(n, e, g, this.P), g && !1 === n && e.length || (m = t)) : (n = Y(this, t, ""), n = Ca(n, e, g, this.resolution)); if (n) { return n; } @@ -988,7 +1018,7 @@ function U(a, c, b, e, d) { return e; } if (1 === f) { - return za(e[0], c, d); + return Ba(e[0], c, d); } } } @@ -1047,10 +1077,10 @@ function U(a, c, b, e, d) { } return e; }; -function W(a, c, b, e) { - return (a = X(this, a, c)) && a.length ? za(a, b, e) : []; +function X(a, c, b, e) { + return (a = Y(this, a, c)) && a.length ? Ba(a, b, e) : []; } -function Aa(a, c, b, e) { +function Ca(a, c, b, e) { let d = []; if (a) { e = Math.min(a.length, e); @@ -1064,13 +1094,13 @@ function Aa(a, c, b, e) { } return !b && d; } -function X(a, c, b) { +function Y(a, c, b) { let e; b && (e = a.bidirectional && c > b); a = b ? (a = a.ctx.get(e ? c : b)) && a.get(e ? b : c) : a.map.get(c); return a; } -;S.prototype.remove = function(a, c) { +;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) { @@ -1085,14 +1115,14 @@ function X(a, c, b) { } } } else { - Y(this.map, a), this.depth && Y(this.ctx, a); + Da(this.map, a), this.depth && Da(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Y(a, c) { +function Da(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1107,25 +1137,25 @@ function Y(a, c) { } } else { for (let e of a) { - const d = e[0], f = Y(e[1], c); + const d = e[0], f = Da(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function S(a, c) { - if (!this) { - return new S(a); +;function T(a, c) { + if (this.constructor !== T) { + return new T(a); } if (a) { - var b = D(a) ? a : a.preset; - b && (ya[b] || console.warn("Preset not found: " + b), a = Object.assign({}, ya[b], a)); + var b = E(a) ? a : a.preset; + b && (Aa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Aa[b], a)); } else { a = {}; } b = a.context || {}; - const e = D(a.encoder) ? xa[a.encoder] : a.encode || a.encoder || qa; - this.encoder = e.encode ? e : "object" === typeof e ? new L(e) : {encode:e}; + const e = E(a.encoder) ? za[a.encoder] : a.encode || a.encoder || sa; + this.encoder = e.encode ? e : "object" === typeof e ? new K(e) : {encode:e}; let d; this.resolution = a.resolution || 9; this.tokenize = d = a.tokenize || "strict"; @@ -1139,9 +1169,9 @@ function Y(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.P = b.resolution || 1; this.rtl = e.rtl || a.rtl || !1; - this.cache = (d = a.cache || null) && new R(d); + this.cache = (d = a.cache || null) && new S(d); } -x = S.prototype; +x = T.prototype; x.clear = function() { this.map.clear(); this.ctx.clear(); @@ -1159,7 +1189,7 @@ x.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); }; -function Ba(a) { +function Ea(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1167,7 +1197,7 @@ function Ba(a) { } } else { for (const b of a) { - const e = b[0], d = Ba(b[1]); + const e = b[0], d = Ea(b[1]); d ? c += d : a.delete(e); } } @@ -1177,63 +1207,47 @@ x.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Ba(this.map); - this.depth && Ba(this.ctx); + Ea(this.map); + this.depth && Ea(this.ctx); return this; }; -x.searchCache = pa; -x.export = function(a, c, b, e, d, f) { - let g = !0; - "undefined" === typeof f && (g = new Promise(l => { - f = l; - })); - let h, k; - switch(d || (d = 0)) { +x.searchCache = ra; +x.export = function(a, c, b, e = 0) { + let d, f; + switch(e) { case 0: - h = "reg"; - if (this.fastupdate) { - k = C(); - for (let l of this.reg.keys()) { - k[l] = 1; - } - } else { - k = this.reg; - } + d = "reg"; + f = ka(this.reg); break; case 1: - h = "cfg"; - k = {doc:0, opt:this.h ? 1 : 0}; + d = "cfg"; + f = {}; break; case 2: - h = "map"; - k = this.map; + d = "map"; + f = N(this.map); break; case 3: - h = "ctx"; - k = this.ctx; + d = "ctx"; + f = ja(this.ctx); break; default: - "undefined" === typeof b && f && f(); return; } - ja(a, c || this, b, h, e, d, k, f); - return g; + return la.call(this, a, c, d, b, e, f); }; x.import = function(a, c) { if (c) { - switch(D(c) && (c = JSON.parse(c)), a) { - case "cfg": - this.h = !!c.opt; - break; + switch(E(c) && (c = JSON.parse(c)), a) { case "reg": this.fastupdate = !1; - this.reg = c; + this.reg = new Set(c); break; case "map": - this.map = c; + this.map = new Map(c); break; case "ctx": - this.ctx = c; + this.ctx = new Map(c); } } }; @@ -1287,10 +1301,10 @@ x.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ia(S.prototype); -const Ca = {Index:S, Charset:xa, Encoder:L, Document:N, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Z = self; -let Da; -(Da = Z.define) && Da.amd ? Da([], function() { - return Ca; -}) : "object" === typeof Z.exports ? Z.exports = Ca : Z.FlexSearch = Ca; +ia(T.prototype); +const Fa = {Index:T, Charset:za, Encoder:K, Document:O, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Z = self; +let Ga; +(Ga = Z.define) && Ga.amd ? Ga([], function() { + return Fa; +}) : "object" === typeof Z.exports ? Z.exports = Fa : Z.FlexSearch = Fa; }(this||self)); diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 736b2b5..5f9ec2d 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -5,48 +5,47 @@ * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&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 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"===d?c:a}function C(){return Object.create(null)}function aa(a,c){return c.length-a.length} -function E(a){return"string"===typeof a}function H(a){return"object"===typeof a}function I(a,c){if(E(c))a=a[c];else for(let b=0;a&&bthis.stemmer.get(l)),k=1);f&&k&&(f.length< +B(a.minlength,1,this.minlength);this.maxlength=B(a.maxlength,0,this.maxlength);if(this.cache=b=B(a.cache,!0,this.cache))this.I=null,this.O="number"===typeof b?b:2E5,this.D=new Map,this.G=new Map,this.J=this.A=128;this.K="";this.M=null;this.L="";this.N=null;if(this.matcher)for(const e of this.matcher.keys())this.K+=(this.K?"|":"")+e;if(this.stemmer)for(const e of this.stemmer.keys())this.L+=(this.L?"|":"")+e;return this}; +K.prototype.encode=function(a){if(this.cache&&a.length<=this.A)if(this.I){if(this.D.has(a))return this.D.get(a)}else this.I=setTimeout(ha,50,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):J?a.normalize("NFKD").replace(J,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(l)),k=1);f&&k&&(f.length< this.minlength||this.filter&&this.filter.has(f))&&(f="");if(f&&(this.mapper||this.dedupe&&1this.matcher.get(l)));if(f&&this.replacer)for(d=0;f&&dthis.O&&(this.H.clear(),this.D=this.D/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.F.set(a,b),this.F.size>this.O&&(this.F.clear(),this.h=this.h/1.1|0));return b};function ha(a){a.J=null;a.F.clear();a.H.clear()};function ia(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}function M(a){this[a+"Async"]=function(){var c=arguments;const b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);c=this[a].apply(this,c);e&&(c.then?c.then(e):e(c));return c}};function ja(a,c,b,e,d,g,f,h){(e=a(b?b+"."+e:e,JSON.stringify(f)))&&e.then?e.then(function(){c.export(a,c,b,d,g+1,h)}):c.export(a,c,b,d,g+1,h)};N.prototype.add=function(a,c,b){H(a)&&(c=a,a=I(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hb||e)a=a.slice(e,e+b);d&&(a=ma.call(this,a));return a}} -function ma(a){const c=Array(a.length);for(let b=0,e;b{g=k}));d||(d=0);e||(e=0);if(ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; -R.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};R.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};R.prototype.clear=function(){this.cache.clear();this.h=""};const qa={normalize:function(a){return a.toLowerCase()},dedupe:!1};const T=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 ra=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),sa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const ta={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};const ua=/[\x00-\x7F]+/g;const va=/[\x00-\x7F]+/g;const wa=/[\x00-\x7F]+/g;var xa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:qa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:T},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:T,matcher:ra,replacer:sa},LatinExtra:{normalize:!0,dedupe:!0,mapper:T,replacer:sa.concat([/(?!^)[aeo]/g,""]),matcher:ra},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bg;h--){f=r.substring(g,h);var k=this.score?this.score(c,r,p,f,g):U(t,e,p,d,g);V(this,m,f,k,a,b)}break}case "reverse":if(1< -d){for(h=d-1;0f?0:1),e,p,h-1,k-1),u=this.bidirectional&&r>g;V(this,l,u?g:r,v,a,b,u?r:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function V(a,c,b,e,d,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=C()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function U(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,g,f;d=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),e.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;e=[g]}c-=f;if(!c)break}return e.length?e=1c||d?f.slice(d,c+d):f;f=a}else{if(ac||d)f=f.slice(d,c+d)}e=f}return e}; -function W(a,c,b,e){return(a=X(this,a,c))&&a.length?za(a,b,e):[]}function Aa(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let g=0,f;gb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};S.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;ed.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Y(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,g;eb.add(a,c)):this.add(a,c)}; -function Ba(a){let c=0;if(a.constructor===Array)for(let b=0,e;b{g=l}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=C();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&g&&g();return}ja(a,c||this,b,h,e,d,k,g);return f}; -x.import=function(a,c){if(c)switch(E(c)&&(c=JSON.parse(c)),a){case "cfg":this.h=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}}; +h.length<=this.J&&(this.G.set(h,f),this.G.size>this.O&&(this.G.clear(),this.J=this.J/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.A&&(this.D.set(a,b),this.D.size>this.O&&(this.D.clear(),this.A=this.A/1.1|0));return b};function ha(a){a.I=null;a.D.clear();a.G.clear()};function ia(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}function M(a){this[a+"Async"]=function(){var c=arguments;const b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);c=this[a].apply(this,c);e&&(c.then?c.then(e):e(c));return c}};function N(a){const c=[];for(const b of a.entries())c.push(b);return c}function ja(a){const c=[];for(const b of a.entries())c.push(N(b));return c}function ka(a){const c=[];for(const b of a.keys())c.push(b);return c}function la(a,c,b,e,d,g){if((b=a(c?c+"."+b:b,JSON.stringify(g)))&&b.then){const f=this;return b.then(function(){return f.export(a,c,e,d+1)})}return this.export(a,c,e,d+1)};O.prototype.add=function(a,c,b){G(a)&&(c=a,a=I(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hb||e)a=a.slice(e,e+b);d&&(a=oa.call(this,a));return a}} +function oa(a){const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +S.prototype.get=function(a){const c=this.cache.get(a);c&&this.A!==a&&(this.cache.delete(a),this.cache.set(this.A=a,c));return c};S.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};S.prototype.clear=function(){this.cache.clear();this.A=""};const sa={normalize:function(a){return a.toLowerCase()},dedupe:!1};const U=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"],["pf","f"]]),ua=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\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};const wa=/[\x00-\x7F]+/g;const xa=/[\x00-\x7F]+/g;const ya=/[\x00-\x7F]+/g;var za={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:sa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:U},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:U,matcher:ta,replacer:ua},LatinExtra:{normalize:!0,dedupe:!0,mapper:U,replacer:ua.concat([/(?!^)[aeo]/g,""]),matcher:ta},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bg;h--){f=r.substring(g,h);var k=this.score?this.score(c,r,p,f,g):V(t,e,p,d,g);W(this,m,f,k,a,b)}break}case "reverse":if(1< +d){for(h=d-1;0f?0:1),e,p,h-1,k-1),u=this.bidirectional&&r>g;W(this,l,u?g:r,v,a,b,u?r:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function W(a,c,b,e,d,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=D()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function V(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,g,f;d=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),e.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;e=[g]}c-=f;if(!c)break}return e.length?e=1c||d?f.slice(d,c+d):f;f=a}else{if(ac||d)f=f.slice(d,c+d)}e=f}return e}; +function X(a,c,b,e){return(a=Y(this,a,c))&&a.length?Ba(a,b,e):[]}function Ca(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let g=0,f;gb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};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;ed.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else Da(this.map,a),this.depth&&Da(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Da(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,g;eb.add(a,c)):this.add(a,c)}; +function Ea(a){let c=0;if(a.constructor===Array)for(let b=0,e;b this.O && (this.H.clear(), this.D = this.D / 1.1 | 0)); + this.cache && h.length <= this.J && (this.G.set(h, g), this.G.size > this.O && (this.G.clear(), this.J = this.J / 1.1 | 0)); g && b.push(g); } this.finalize && (b = this.finalize(b) || b); - this.cache && a.length <= this.h && (this.F.set(a, b), this.F.size > this.O && (this.F.clear(), this.h = this.h / 1.1 | 0)); + this.cache && a.length <= this.A && (this.D.set(a, b), this.D.size > this.O && (this.D.clear(), this.A = this.A / 1.1 | 0)); return b; }; function ha(a) { - a.J = null; - a.F.clear(); - a.H.clear(); + a.I = null; + a.D.clear(); + a.G.clear(); } ;function ia(a) { M.call(a, "add"); @@ -227,12 +227,37 @@ function M(a) { return c; }; } -;function ja(a, c, b, e, d, f, g, h) { - (e = a(b ? b + "." + e : e, JSON.stringify(g))) && e.then ? e.then(function() { - c.export(a, c, b, d, f + 1, h); - }) : c.export(a, c, b, d, f + 1, h); +;function N(a) { + const c = []; + for (const b of a.entries()) { + c.push(b); + } + return c; } -;N.prototype.add = function(a, c, b) { +function ja(a) { + const c = []; + for (const b of a.entries()) { + c.push(N(b)); + } + return c; +} +function ka(a) { + const c = []; + for (const b of a.keys()) { + c.push(b); + } + return c; +} +function la(a, c, b, e, d, f) { + if ((b = a(c ? c + "." + b : b, JSON.stringify(f))) && b.then) { + const g = this; + return b.then(function() { + return g.export(a, c, e, d + 1); + }); + } + return this.export(a, c, e, d + 1); +} +;O.prototype.add = function(a, c, b) { H(a) && (c = a, a = I(c, this.key)); if (c && (a || 0 === a)) { if (!b && this.reg.has(a)) { @@ -245,8 +270,8 @@ function M(a) { var d = k(c); d && e.add(a, d, !1, !0); } else { - if (d = k.G, !d || d(c)) { - k.constructor === String ? k = ["" + k] : D(k) && (k = [k]), O(c, k, this.I, 0, e, a, k[0], b); + if (d = k.F, !d || d(c)) { + k.constructor === String ? k = ["" + k] : E(k) && (k = [k]), P(c, k, this.H, 0, e, a, k[0], b); } } } @@ -260,7 +285,7 @@ function M(a) { continue; } } else { - const k = f.G; + const k = f.F; if (k && !k(c)) { continue; } @@ -268,7 +293,7 @@ function M(a) { f = I(c, f); } if (d && f) { - D(f) && (f = [f]); + E(f) && (f = [f]); for (let k = 0, l, m; k < f.length; k++) { l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); } @@ -279,11 +304,11 @@ function M(a) { } if (this.store && (!b || !this.store.has(a))) { let h; - if (this.A) { + if (this.h) { h = C(); - for (let k = 0, l; k < this.A.length; k++) { - l = this.A[k]; - if ((b = l.G) && !b(c)) { + for (let k = 0, l; k < this.h.length; k++) { + l = this.h[k]; + if ((b = l.F) && !b(c)) { continue; } let m; @@ -293,11 +318,11 @@ function M(a) { continue; } l = [l.S]; - } else if (D(l) || l.constructor === String) { + } else if (E(l) || l.constructor === String) { h[l] = c[l]; continue; } - P(c, h, l, 0, l[0], m); + Q(c, h, l, 0, l[0], m); } } this.store.set(a, h || c); @@ -305,21 +330,21 @@ function M(a) { } return this; }; -function P(a, c, b, e, d, f) { +function Q(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++) { - P(a, c, b, e, d); + Q(a, c, b, e, d); } } else { - c = c[d] || (c[d] = C()), d = b[++e], P(a, c, b, e, d); + c = c[d] || (c[d] = C()), d = b[++e], Q(a, c, b, e, d); } } } -function O(a, c, b, e, d, f, g, h) { +function P(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -335,15 +360,15 @@ function O(a, c, b, e, d, f, g, h) { } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - O(a, c, b, e, d, f, g, h); + P(a, c, b, e, d, f, g, h); } } else { - g = c[++e], O(a, c, b, e, d, f, g, h); + g = c[++e], P(a, c, b, e, d, f, g, h); } } } } -;function ka(a, c) { +;function ma(a, c) { const b = C(), e = []; for (let d = 0, f; d < c.length; d++) { f = c[d]; @@ -356,7 +381,7 @@ function O(a, c, b, e, d, f, g, h) { } return e; } -;N.prototype.search = function(a, c, b, e) { +;O.prototype.search = function(a, c, b, e) { b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); let d = []; var f = []; @@ -379,7 +404,7 @@ function O(a, c, b, e, d, f, g, h) { var u = []; for (let w = 0, q; w < m.length; w++) { q = m[w]; - if (D(q)) { + if (E(q)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (q.field && q.tag) { @@ -393,8 +418,8 @@ function O(a, c, b, e, d, f, g, h) { } } else { v = Object.keys(q); - for (let E = 0, A, z; E < v.length; E++) { - if (A = v[E], z = q[A], z.constructor === Array) { + for (let D = 0, A, z; D < v.length; D++) { + if (A = v[D], z = q[A], z.constructor === Array) { for (y = 0; y < z.length; y++) { u.push(A, z[y]); } @@ -412,7 +437,7 @@ function O(a, c, b, e, d, f, g, h) { e = []; if (u.length) { for (f = 0; f < u.length; f += 2) { - r = la.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:r}); + r = na.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:r}); } } return e.length ? Promise.all(e).then(function(w) { @@ -423,18 +448,18 @@ function O(a, c, b, e, d, f, g, h) { }) : d; } } - D(l) && (l = [l]); + E(l) && (l = [l]); } l || (l = this.field); u = !e && (this.worker || this.db) && []; - for (let w = 0, q, E, A; w < l.length; w++) { - E = l[w]; + for (let w = 0, q, D, A; w < l.length; w++) { + D = l[w]; let z; - D(E) || (z = E, E = z.field, a = z.query || a, c = z.limit || c, n = z.offset || n, k = z.suggest || k, g = this.store && (z.enrich || g)); + E(D) || (z = D, D = z.field, a = z.query || a, c = z.limit || c, n = z.offset || n, k = z.suggest || k, g = this.store && (z.enrich || g)); if (e) { q = e[w]; } else { - if (v = z || b, y = this.index.get(E), m && (v.enrich = !1), u) { + if (v = z || b, y = this.index.get(D), m && (v.enrich = !1), u) { u[w] = y.search(a, c, v); v && g && (v.enrich = g); continue; @@ -446,7 +471,7 @@ function O(a, c, b, e, d, f, g, h) { if (m && A) { v = []; y = 0; - for (let G = 0, F, K; G < m.length; G += 2) { + for (let G = 0, F, L; G < m.length; G += 2) { F = this.tag.get(m[G]); if (!F) { if (console.warn("Tag '" + m[G] + ":" + m[G + 1] + "' will be skipped because there is no field '" + m[G] + "'."), k) { @@ -455,14 +480,14 @@ function O(a, c, b, e, d, f, g, h) { return d; } } - if (K = (F = F && F.get(m[G + 1])) && F.length) { + if (L = (F = F && F.get(m[G + 1])) && F.length) { y++, v.push(F); } else if (!k) { return d; } } if (y) { - q = ka(q, v); + q = ma(q, v); A = q.length; if (!A && !k) { return d; @@ -471,7 +496,7 @@ function O(a, c, b, e, d, f, g, h) { } } if (A) { - f[t] = E, d.push(q), t++; + f[t] = D, d.push(q), t++; } else if (1 === l.length) { return d; } @@ -491,15 +516,15 @@ function O(a, c, b, e, d, f, g, h) { u = []; for (let w = 0, q; w < f.length; w++) { q = d[w]; - g && q.length && !q[0].doc && q.length && (q = ma.call(this, q)); + g && q.length && !q[0].doc && q.length && (q = oa.call(this, q)); if (r) { return q; } d[w] = {field:f[w], result:q}; } - return h ? na(d, c) : p ? oa(d, a, this.index, this.field, this.C, p) : d; + return h ? pa(d, c) : p ? qa(d, a, this.index, this.field, this.C, p) : d; }; -function oa(a, c, b, e, d, f) { +function qa(a, c, b, e, d, f) { let g, h, k; for (let m = 0, n, t, p, r, u; m < a.length; m++) { n = a[m].result; @@ -514,21 +539,21 @@ function oa(a, c, b, e, d, f) { var l = I(n[v].doc, u); let w = g.encode(l); l = l.split(g.split); - for (let q = 0, E, A; q < w.length; q++) { - E = w[q]; + for (let q = 0, D, A; q < w.length; q++) { + D = w[q]; A = l[q]; let z; for (let G = 0, F; G < h.length; G++) { if (F = h[G], "strict" === k) { - if (E === F) { + if (D === F) { y += (y ? " " : "") + f.replace("$1", A); z = !0; break; } } else { - const K = E.indexOf(F); - if (-1 < K) { - y += (y ? " " : "") + A.substring(0, K) + f.replace("$1", A.substring(K, F.length)) + A.substring(K + F.length); + const L = D.indexOf(F); + if (-1 < L) { + y += (y ? " " : "") + A.substring(0, L) + f.replace("$1", A.substring(L, F.length)) + A.substring(L + F.length); z = !0; break; } @@ -541,7 +566,7 @@ function oa(a, c, b, e, d, f) { } return a; } -function na(a, c) { +function pa(a, c) { const b = [], e = C(); for (let d = 0, f, g; d < a.length; d++) { f = a[d]; @@ -560,7 +585,7 @@ function na(a, c) { } return b; } -function la(a, c, b, e, d) { +function na(a, c, b, e, d) { let f = this.tag.get(a); if (!f) { return console.warn("Tag '" + a + "' was not found"), []; @@ -569,43 +594,43 @@ function la(a, c, b, e, d) { if (a > b || e) { f = f.slice(e, e + b); } - d && (f = ma.call(this, f)); + d && (f = oa.call(this, f)); return f; } } -function ma(a) { +function oa(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 N(a) { - if (!this) { - return new N(a); +;function O(a) { + if (this.constructor !== O) { + return new O(a); } const c = a.document || a.doc || a; var b; this.C = []; this.field = []; - this.I = []; - this.key = (b = c.key || c.id) && Q(b, this.I) || "id"; + this.H = []; + this.key = (b = c.key || c.id) && R(b, this.H) || "id"; this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); - this.A = (b = c.store || null) && !0 !== b && []; + this.h = (b = c.store || null) && !0 !== b && []; this.store = b && new Map(); - this.cache = (b = a.cache || null) && new R(b); + this.cache = (b = a.cache || null) && new S(b); a.cache = !1; b = new Map(); let e = c.index || c.field || c; - D(e) && (e = [e]); + E(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], D(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, b.set(f, new S(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Q(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].G = g.filter)), this.field[d] = f; + f = e[d], E(f) || (g = f, f = f.field), g = H(g) ? Object.assign({}, a, g) : a, b.set(f, new T(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = R(f, this.H), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].F = g.filter)), this.field[d] = f; } - if (this.A) { + if (this.h) { a = c.store; - D(a) && (a = [a]); + E(a) && (a = [a]); for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Q(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); + f = a[d], g = f.field || f, f.custom ? (this.h[d] = f.custom, f.custom.S = g) : (this.h[d] = R(g, this.H), f.filter && ("string" === typeof this.h[d] && (this.h[d] = new String(this.h[d])), this.h[d].F = f.filter)); } } this.index = b; @@ -621,14 +646,14 @@ function ma(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.B[d] = f.custom : (this.B[d] = Q(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].G = f.filter)); + f.custom ? this.B[d] = f.custom : (this.B[d] = R(g, this.H), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].F = f.filter)); this.R[d] = g; this.tag.set(g, new Map()); } } } } -function Q(a, c) { +function R(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -637,7 +662,7 @@ function Q(a, c) { e < b.length && (b.length = e); return 1 < e ? b : b[0]; } -x = N.prototype; +x = O.prototype; x.append = function(a, c) { return this.add(a, c, !0); }; @@ -693,65 +718,70 @@ x.set = function(a, c) { this.store.set(a, c); return this; }; -x.searchCache = pa; -x.export = function(a, c, b, e, d, f) { - let g; - "undefined" === typeof f && (g = new Promise(k => { - f = k; - })); - d || (d = 0); - e || (e = 0); - if (e < this.field.length) { - b = this.field[e]; - var h = this.index[b]; - c = this; - h.export(a, c, d ? b : "", e, d++, f) || (e++, c.export(a, c, b, e, 1, f)); - } else { - switch(d) { - case 1: - c = "tag"; - h = this.D; - b = null; - break; - case 2: - c = "store"; - h = this.store; - b = null; - break; - default: - f(); - return; +x.searchCache = ra; +x.export = function(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, e = 0); + }); } - ja(a, this, b, c, e, d, h, f); + return this.export(a, g, b + 1, e = 0); } - return g; + let d, f; + switch(e) { + case 0: + d = "reg"; + f = ka(this.reg); + c = null; + break; + case 1: + d = "tag"; + f = ja(this.tag); + c = null; + break; + case 2: + d = "doc"; + f = N(this.store); + c = null; + break; + case 3: + d = "cfg"; + f = {}; + c = null; + break; + default: + return; + } + return la.call(this, a, c, d, b, e, f); }; x.import = function(a, c) { if (c) { - switch(D(c) && (c = JSON.parse(c)), a) { + switch(E(c) && (c = JSON.parse(c)), a) { case "tag": - this.D = c; break; case "reg": this.fastupdate = !1; - this.reg = c; + this.reg = new Set(c); for (let e = 0, d; e < this.field.length; e++) { - d = this.index[this.field[e]], d.reg = c, d.fastupdate = !1; + d = this.index.get(this.field[e]), d.fastupdate = !1, d.reg = this.reg; } break; - case "store": - this.store = c; + case "doc": + this.store = new Map(c); break; default: a = a.split("."); const b = a[0]; a = a[1]; - b && a && this.index[b].import(a, c); + b && a && this.index.get(b).import(a, c); } } }; -ia(N.prototype); -function pa(a, c, b) { +ia(O.prototype); +function ra(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); let e = this.cache.get(a); if (!e) { @@ -767,57 +797,57 @@ function pa(a, c, b) { } return e; } -function R(a) { +function S(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); - this.h = ""; + this.A = ""; } -R.prototype.set = function(a, c) { - this.cache.set(this.h = a, c); +S.prototype.set = function(a, c) { + this.cache.set(this.A = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -R.prototype.get = function(a) { +S.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)); + c && this.A !== a && (this.cache.delete(a), this.cache.set(this.A = a, c)); return c; }; -R.prototype.remove = function(a) { +S.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -R.prototype.clear = function() { +S.prototype.clear = function() { this.cache.clear(); - this.h = ""; + this.A = ""; }; -const qa = {normalize:function(a) { +const sa = {normalize:function(a) { return a.toLowerCase(); }, dedupe:!1}; -const T = 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 ra = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), sa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -const ta = {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}; -const ua = /[\x00-\x7F]+/g; -const va = /[\x00-\x7F]+/g; +const U = 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"], ["pf", "f"]]), ua = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\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}; const wa = /[\x00-\x7F]+/g; -var xa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:qa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:T}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:T, matcher:ra, replacer:sa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:T, replacer:sa.concat([/(?!^)[aeo]/g, ""]), matcher:ra}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const xa = /[\x00-\x7F]+/g; +const ya = /[\x00-\x7F]+/g; +var za = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:sa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:U}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:U, matcher:ta, replacer:ua}, LatinExtra:{normalize:!0, dedupe:!0, mapper:U, replacer:ua.concat([/(?!^)[aeo]/g, ""]), matcher:ta}, LatinSoundex:{normalize:!0, 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 = ta[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = ta[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = va[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = va[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ua, " "); -}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(va, ""); -}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { return ("" + a).replace(wa, " "); +}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { + return ("" + a).replace(xa, ""); +}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(ya, " "); }}}; -const ya = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +const Aa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; C(); -S.prototype.add = function(a, c, b, e) { +T.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -829,15 +859,15 @@ S.prototype.add = function(a, c, b, e) { let r = c[this.rtl ? e - 1 - p : p]; var d = r.length; if (d && (n || !m[r])) { - var f = this.score ? this.score(c, r, p, null, 0) : U(t, e, p), g = ""; + var f = this.score ? this.score(c, r, p, null, 0) : V(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var h = d; h > f; h--) { g = r.substring(f, h); - var k = this.score ? this.score(c, r, p, g, f) : U(t, e, p, d, f); - V(this, m, g, k, a, b); + var k = this.score ? this.score(c, r, p, g, f) : V(t, e, p, d, f); + W(this, m, g, k, a, b); } } break; @@ -845,24 +875,24 @@ S.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - g = r[h] + g, k = this.score ? this.score(c, r, p, g, h) : U(t, e, p, d, h), V(this, m, g, k, a, b); + g = r[h] + g, k = this.score ? this.score(c, r, p, g, h) : V(t, e, p, d, h), W(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { for (h = 0; h < d; h++) { - g += r[h], V(this, m, g, f, a, b); + g += r[h], W(this, m, g, f, a, b); } break; } default: - if (V(this, m, r, f, a, b), n && 1 < e && p < e - 1) { + if (W(this, m, r, f, a, b), n && 1 < e && p < e - 1) { for (d = C(), g = this.P, f = r, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { if ((r = c[this.rtl ? e - 1 - p - k : p + k]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(c, f, p, r, k) : U(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), v = this.bidirectional && r > f; - V(this, l, v ? f : r, u, a, b, v ? r : f); + const u = this.score ? this.score(c, f, p, r, k) : V(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), v = this.bidirectional && r > f; + W(this, l, v ? f : r, u, a, b, v ? r : f); } } } @@ -874,16 +904,16 @@ S.prototype.add = function(a, c, b, e) { } return this; }; -function V(a, c, b, e, d, f, g) { +function W(a, c, b, e, d, f, g) { let h = g ? a.ctx : a.map, k; if (!c[b] || g && !(k = c[b])[g]) { g ? (c = k || (c[b] = C()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); } } -function U(a, c, b, e, d) { +function V(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;function za(a, c, b) { +;function Ba(a, c, b) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } @@ -913,7 +943,7 @@ function U(a, c, b, e, d) { } return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; } -;S.prototype.search = function(a, c, b) { +;T.prototype.search = function(a, c, b) { b || (!c && H(a) ? (b = a, a = "") : H(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { @@ -927,11 +957,11 @@ function U(a, c, b, e, d) { b = a.length; c || (c = 100); if (1 === b) { - return W.call(this, a[0], "", c, d); + return X.call(this, a[0], "", c, d); } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return W.call(this, a[0], a[1], c, d); + return X.call(this, a[0], a[1], c, d); } var h = 0, k = 0; if (1 < b) { @@ -939,7 +969,7 @@ function U(a, c, b, e, d) { const n = []; for (let t = 0, p; t < b; t++) { if ((p = a[t]) && !l[p]) { - if (g || X(this, p)) { + if (g || Y(this, p)) { n.push(p), l[p] = 1; } else { return e; @@ -957,10 +987,10 @@ function U(a, c, b, e, d) { } l = 0; if (1 === b) { - return W.call(this, a[0], "", c, d); + return X.call(this, a[0], "", c, d); } if (2 === b && f && !g) { - return W.call(this, a[0], a[1], c, d); + return X.call(this, a[0], a[1], c, d); } if (1 < b) { if (f) { @@ -972,7 +1002,7 @@ function U(a, c, b, e, d) { } for (let n, t; l < b; l++) { t = a[l]; - m ? (n = X(this, t, m), n = Aa(n, e, g, this.P), g && !1 === n && e.length || (m = t)) : (n = X(this, t, ""), n = Aa(n, e, g, this.resolution)); + m ? (n = Y(this, t, m), n = Ca(n, e, g, this.P), g && !1 === n && e.length || (m = t)) : (n = Y(this, t, ""), n = Ca(n, e, g, this.resolution)); if (n) { return n; } @@ -987,7 +1017,7 @@ function U(a, c, b, e, d) { return e; } if (1 === f) { - return za(e[0], c, d); + return Ba(e[0], c, d); } } } @@ -1046,10 +1076,10 @@ function U(a, c, b, e, d) { } return e; }; -function W(a, c, b, e) { - return (a = X(this, a, c)) && a.length ? za(a, b, e) : []; +function X(a, c, b, e) { + return (a = Y(this, a, c)) && a.length ? Ba(a, b, e) : []; } -function Aa(a, c, b, e) { +function Ca(a, c, b, e) { let d = []; if (a) { e = Math.min(a.length, e); @@ -1063,13 +1093,13 @@ function Aa(a, c, b, e) { } return !b && d; } -function X(a, c, b) { +function Y(a, c, b) { let e; b && (e = a.bidirectional && c > b); a = b ? (a = a.ctx.get(e ? c : b)) && a.get(e ? b : c) : a.map.get(c); return a; } -;S.prototype.remove = function(a, c) { +;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) { @@ -1084,14 +1114,14 @@ function X(a, c, b) { } } } else { - Y(this.map, a), this.depth && Y(this.ctx, a); + Z(this.map, a), this.depth && Z(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function Y(a, c) { +function Z(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -1106,25 +1136,25 @@ function Y(a, c) { } } else { for (let e of a) { - const d = e[0], f = Y(e[1], c); + const d = e[0], f = Z(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function S(a, c) { - if (!this) { - return new S(a); +;function T(a, c) { + if (this.constructor !== T) { + return new T(a); } if (a) { - var b = D(a) ? a : a.preset; - b && (ya[b] || console.warn("Preset not found: " + b), a = Object.assign({}, ya[b], a)); + var b = E(a) ? a : a.preset; + b && (Aa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, Aa[b], a)); } else { a = {}; } b = a.context || {}; - const e = D(a.encoder) ? xa[a.encoder] : a.encode || a.encoder || qa; - this.encoder = e.encode ? e : "object" === typeof e ? new L(e) : {encode:e}; + const e = E(a.encoder) ? za[a.encoder] : a.encode || a.encoder || sa; + this.encoder = e.encode ? e : "object" === typeof e ? new K(e) : {encode:e}; let d; this.resolution = a.resolution || 9; this.tokenize = d = a.tokenize || "strict"; @@ -1138,9 +1168,9 @@ function Y(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.P = b.resolution || 1; this.rtl = e.rtl || a.rtl || !1; - this.cache = (d = a.cache || null) && new R(d); + this.cache = (d = a.cache || null) && new S(d); } -x = S.prototype; +x = T.prototype; x.clear = function() { this.map.clear(); this.ctx.clear(); @@ -1158,7 +1188,7 @@ x.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); }; -function Z(a) { +function Da(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -1166,7 +1196,7 @@ function Z(a) { } } else { for (const b of a) { - const e = b[0], d = Z(b[1]); + const e = b[0], d = Da(b[1]); d ? c += d : a.delete(e); } } @@ -1176,63 +1206,47 @@ x.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Z(this.map); - this.depth && Z(this.ctx); + Da(this.map); + this.depth && Da(this.ctx); return this; }; -x.searchCache = pa; -x.export = function(a, c, b, e, d, f) { - let g = !0; - "undefined" === typeof f && (g = new Promise(l => { - f = l; - })); - let h, k; - switch(d || (d = 0)) { +x.searchCache = ra; +x.export = function(a, c, b, e = 0) { + let d, f; + switch(e) { case 0: - h = "reg"; - if (this.fastupdate) { - k = C(); - for (let l of this.reg.keys()) { - k[l] = 1; - } - } else { - k = this.reg; - } + d = "reg"; + f = ka(this.reg); break; case 1: - h = "cfg"; - k = {doc:0, opt:this.h ? 1 : 0}; + d = "cfg"; + f = {}; break; case 2: - h = "map"; - k = this.map; + d = "map"; + f = N(this.map); break; case 3: - h = "ctx"; - k = this.ctx; + d = "ctx"; + f = ja(this.ctx); break; default: - "undefined" === typeof b && f && f(); return; } - ja(a, c || this, b, h, e, d, k, f); - return g; + return la.call(this, a, c, d, b, e, f); }; x.import = function(a, c) { if (c) { - switch(D(c) && (c = JSON.parse(c)), a) { - case "cfg": - this.h = !!c.opt; - break; + switch(E(c) && (c = JSON.parse(c)), a) { case "reg": this.fastupdate = !1; - this.reg = c; + this.reg = new Set(c); break; case "map": - this.map = c; + this.map = new Map(c); break; case "ctx": - this.ctx = c; + this.ctx = new Map(c); } } }; @@ -1286,7 +1300,7 @@ x.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ia(S.prototype); -export default {Index:S, Charset:xa, Encoder:L, Document:N, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +ia(T.prototype); +export default {Index:T, Charset:za, Encoder:K, Document:O, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=S;export const Charset=xa;export const Encoder=L;export const Document=N;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=T;export const Charset=za;export const Encoder=K;export const Document=O;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index b500242..04c5911 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -5,49 +5,48 @@ * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var x;function B(a,c,b){const e=typeof b,d=typeof a;if("undefined"!==e){if("undefined"!==d){if(b){if("function"===d&&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 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"===d?c:a}function C(){return Object.create(null)}function aa(a,c){return c.length-a.length} -function E(a){return"string"===typeof a}function H(a){return"object"===typeof a}function I(a,c){if(E(c))a=a[c];else for(let b=0;a&&bthis.stemmer.get(l)),k=1);f&&k&&(f.length< +B(a.minlength,1,this.minlength);this.maxlength=B(a.maxlength,0,this.maxlength);if(this.cache=b=B(a.cache,!0,this.cache))this.I=null,this.O="number"===typeof b?b:2E5,this.D=new Map,this.G=new Map,this.J=this.A=128;this.K="";this.M=null;this.L="";this.N=null;if(this.matcher)for(const e of this.matcher.keys())this.K+=(this.K?"|":"")+e;if(this.stemmer)for(const e of this.stemmer.keys())this.L+=(this.L?"|":"")+e;return this}; +K.prototype.encode=function(a){if(this.cache&&a.length<=this.A)if(this.I){if(this.D.has(a))return this.D.get(a)}else this.I=setTimeout(ha,50,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):J?a.normalize("NFKD").replace(J,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(l)),k=1);f&&k&&(f.length< this.minlength||this.filter&&this.filter.has(f))&&(f="");if(f&&(this.mapper||this.dedupe&&1this.matcher.get(l)));if(f&&this.replacer)for(d=0;f&&dthis.O&&(this.H.clear(),this.D=this.D/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.F.set(a,b),this.F.size>this.O&&(this.F.clear(),this.h=this.h/1.1|0));return b};function ha(a){a.J=null;a.F.clear();a.H.clear()};function ia(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}function M(a){this[a+"Async"]=function(){var c=arguments;const b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);c=this[a].apply(this,c);e&&(c.then?c.then(e):e(c));return c}};function ja(a,c,b,e,d,g,f,h){(e=a(b?b+"."+e:e,JSON.stringify(f)))&&e.then?e.then(function(){c.export(a,c,b,d,g+1,h)}):c.export(a,c,b,d,g+1,h)};N.prototype.add=function(a,c,b){H(a)&&(c=a,a=I(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hb||e)a=a.slice(e,e+b);d&&(a=ma.call(this,a));return a}} -function ma(a){const c=Array(a.length);for(let b=0,e;b{g=k}));d||(d=0);e||(e=0);if(ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; -R.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};R.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};R.prototype.clear=function(){this.cache.clear();this.h=""};const qa={normalize:function(a){return a.toLowerCase()},dedupe:!1};const T=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 ra=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),sa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const ta={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};const ua=/[\x00-\x7F]+/g;const va=/[\x00-\x7F]+/g;const wa=/[\x00-\x7F]+/g;var xa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:qa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:T},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:T,matcher:ra,replacer:sa},LatinExtra:{normalize:!0,dedupe:!0,mapper:T,replacer:sa.concat([/(?!^)[aeo]/g,""]),matcher:ra},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bg;h--){f=r.substring(g,h);var k=this.score?this.score(c,r,p,f,g):U(t,e,p,d,g);V(this,m,f,k,a,b)}break}case "reverse":if(1< -d){for(h=d-1;0f?0:1),e,p,h-1,k-1),u=this.bidirectional&&r>g;V(this,l,u?g:r,v,a,b,u?r:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function V(a,c,b,e,d,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=C()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function U(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,g,f;d=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),e.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;e=[g]}c-=f;if(!c)break}return e.length?e=1c||d?f.slice(d,c+d):f;f=a}else{if(ac||d)f=f.slice(d,c+d)}e=f}return e}; -function W(a,c,b,e){return(a=X(this,a,c))&&a.length?za(a,b,e):[]}function Aa(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let g=0,f;gb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};S.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;ed.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Y(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,g;eb.add(a,c)):this.add(a,c)}; -function Z(a){let c=0;if(a.constructor===Array)for(let b=0,e;b{g=l}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=C();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&g&&g();return}ja(a,c||this,b,h,e,d,k,g);return f}; -x.import=function(a,c){if(c)switch(E(c)&&(c=JSON.parse(c)),a){case "cfg":this.h=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}}; +h.length<=this.J&&(this.G.set(h,f),this.G.size>this.O&&(this.G.clear(),this.J=this.J/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.A&&(this.D.set(a,b),this.D.size>this.O&&(this.D.clear(),this.A=this.A/1.1|0));return b};function ha(a){a.I=null;a.D.clear();a.G.clear()};function ia(a){M.call(a,"add");M.call(a,"append");M.call(a,"search");M.call(a,"update");M.call(a,"remove")}function M(a){this[a+"Async"]=function(){var c=arguments;const b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);c=this[a].apply(this,c);e&&(c.then?c.then(e):e(c));return c}};function N(a){const c=[];for(const b of a.entries())c.push(b);return c}function ja(a){const c=[];for(const b of a.entries())c.push(N(b));return c}function ka(a){const c=[];for(const b of a.keys())c.push(b);return c}function la(a,c,b,e,d,g){if((b=a(c?c+"."+b:b,JSON.stringify(g)))&&b.then){const f=this;return b.then(function(){return f.export(a,c,e,d+1)})}return this.export(a,c,e,d+1)};O.prototype.add=function(a,c,b){G(a)&&(c=a,a=I(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hb||e)a=a.slice(e,e+b);d&&(a=oa.call(this,a));return a}} +function oa(a){const c=Array(a.length);for(let b=0,e;bthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +S.prototype.get=function(a){const c=this.cache.get(a);c&&this.A!==a&&(this.cache.delete(a),this.cache.set(this.A=a,c));return c};S.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};S.prototype.clear=function(){this.cache.clear();this.A=""};const sa={normalize:function(a){return a.toLowerCase()},dedupe:!1};const U=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"],["pf","f"]]),ua=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\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};const wa=/[\x00-\x7F]+/g;const xa=/[\x00-\x7F]+/g;const ya=/[\x00-\x7F]+/g;var za={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:sa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:U},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:U,matcher:ta,replacer:ua},LatinExtra:{normalize:!0,dedupe:!0,mapper:U,replacer:ua.concat([/(?!^)[aeo]/g,""]),matcher:ta},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bg;h--){f=r.substring(g,h);var k=this.score?this.score(c,r,p,f,g):V(t,e,p,d,g);W(this,m,f,k,a,b)}break}case "reverse":if(1< +d){for(h=d-1;0f?0:1),e,p,h-1,k-1),u=this.bidirectional&&r>g;W(this,l,u?g:r,v,a,b,u?r:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function W(a,c,b,e,d,g,f){let h=f?a.ctx:a.map,k;if(!c[b]||f&&!(k=c[b])[f])f?(c=k||(c[b]=D()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),g&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function V(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,g,f;d=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),e.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;e=[g]}c-=f;if(!c)break}return e.length?e=1c||d?f.slice(d,c+d):f;f=a}else{if(ac||d)f=f.slice(d,c+d)}e=f}return e}; +function X(a,c,b,e){return(a=Y(this,a,c))&&a.length?Ba(a,b,e):[]}function Ca(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let g=0,f;gb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};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;ed.length)d.pop();else{const g=d.indexOf(a);g===b.length-1?d.pop():d.splice(g,1)}}else Z(this.map,a),this.depth&&Z(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Z(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,g;eb.add(a,c)):this.add(a,c)}; +function Da(a){let c=0;if(a.constructor===Array)for(let b=0,e;b this.L && (this.N.clear(), this.h = this.h / 1.1 | 0)); return d; }; -function Ha(a) { +function Ia(a) { a.U = null; a.N.clear(); a.S.clear(); } -;function Ia(a) { +;function Ja(a) { var b, c, d, e, g, f, h, k; - return I(function(l) { + return ta(function(l) { a = a.data; b = self._index; c = a.args; @@ -1062,7 +1062,7 @@ function Ha(a) { case "init": e = a.options || {}; (g = e.config) && (e = g); - (f = a.factory) ? (Function("return " + f)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new R(e); + (f = a.factory) ? (Function("return " + f)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new O(e); postMessage({id:a.id}); break; default: @@ -1071,8 +1071,8 @@ function Ha(a) { l.h = 0; }); } -;var Ja = 0; -function Ka(a) { +;var Ka = 0; +function R(a) { function b(f) { function h(k) { k = k.data || k; @@ -1080,15 +1080,15 @@ function Ka(a) { m && (m(k.msg), delete e.h[l]); } this.worker = f; - this.h = M(); + this.h = J(); if (this.worker) { d ? this.worker.on("message", h) : this.worker.onmessage = h; if (a.config) { return new Promise(function(k) { - e.h[++Ja] = function() { + e.h[++Ka] = function() { k(e); }; - e.worker.postMessage({id:Ja, task:"init", factory:c, options:a}); + e.worker.postMessage({id:Ka, task:"init", factory:c, options:a}); }); } this.worker.postMessage({task:"init", factory:c, options:a}); @@ -1096,8 +1096,8 @@ function Ka(a) { } } a = void 0 === a ? {} : a; - if (!this) { - return new Ka(a); + if (this.constructor !== R) { + return new R(a); } var c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; c && (c = c.toString()); @@ -1112,23 +1112,23 @@ Ma("search"); Ma("update"); Ma("remove"); function Ma(a) { - Ka.prototype[a] = Ka.prototype[a + "Async"] = function() { + R.prototype[a] = R.prototype[a + "Async"] = function() { var b = this, c = arguments, d, e, g, f, h; - return I(function(k) { + return ta(function(k) { d = b; e = [].slice.call(c); g = e[e.length - 1]; "function" === typeof g && (f = g, e.splice(e.length - 1, 1)); h = new Promise(function(l) { - d.h[++Ja] = l; - d.worker.postMessage({task:a, id:Ja, args:e}); + d.h[++Ka] = l; + d.worker.postMessage({task:a, id:Ka, args:e}); }); return f ? (h.then(f), k.return(b)) : k.return(h); }); }; } function La(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ia.toString()], {type:"text/javascript"}))) : new window.Worker(N(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ja.toString()], {type:"text/javascript"}))) : new window.Worker(K(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } ;function Na(a) { @@ -1150,12 +1150,40 @@ function Oa(a) { return b; }; } -;function Pa(a, b, c, d, e, g, f, h) { - (d = a(c ? c + "." + d : d, JSON.stringify(f))) && d.then ? d.then(function() { - b.export(a, b, c, e, g + 1, h); - }) : b.export(a, b, c, e, g + 1, h); +;function Pa(a) { + var b = []; + a = y(a.entries()); + for (var c = a.next(); !c.done; c = a.next()) { + b.push(c.value); + } + return b; } -;function Qa(a, b, c, d) { +function Qa(a) { + var b = []; + a = y(a.entries()); + for (var c = a.next(); !c.done; c = a.next()) { + b.push(Pa(c.value)); + } + return b; +} +function Ra(a) { + var b = []; + a = y(a.keys()); + for (var c = a.next(); !c.done; c = a.next()) { + b.push(c.value); + } + return b; +} +function Sa(a, b, c, d, e, g) { + if ((c = a(b ? b + "." + c : c, JSON.stringify(g))) && c.then) { + var f = this; + return c.then(function() { + return f.export(a, b, d, e + 1); + }); + } + return this.export(a, b, d, e + 1); +} +;function Ta(a, b, c, d) { for (var e = [], g = 0, f; g < a.index.length; g++) { if (f = a.index[g], b >= f.length) { b -= f.length; @@ -1220,12 +1248,12 @@ function S(a) { } if ("slice" === d) { return function(e, g) { - return Qa(b, e || 0, g || b.length, !1); + return Ta(b, e || 0, g || b.length, !1); }; } if ("splice" === d) { return function(e, g) { - return Qa(b, e || 0, g || b.length, !0); + return Ta(b, e || 0, g || b.length, !0); }; } if ("constructor" === d) { @@ -1254,10 +1282,10 @@ function T(a) { if (!this) { return new T(a); } - this.index = M(); + this.index = J(); this.B = []; this.size = 0; - 32 < a ? (this.h = Ra, this.A = BigInt(a)) : (this.h = Sa, this.A = a); + 32 < a ? (this.h = Ua, this.A = BigInt(a)) : (this.h = Va, this.A = a); } T.prototype.get = function(a) { var b = this.h(a); @@ -1272,9 +1300,9 @@ function U(a) { if (!this) { return new U(a); } - this.index = M(); + this.index = J(); this.h = []; - 32 < a ? (this.B = Ra, this.A = BigInt(a)) : (this.B = Sa, this.A = a); + 32 < a ? (this.B = Ua, this.A = BigInt(a)) : (this.B = Va, this.A = a); } U.prototype.add = function(a) { var b = this.B(a), c = this.index[b]; @@ -1290,13 +1318,13 @@ v.delete = U.prototype.delete = function(a) { (b = this.index[b]) && b.delete(a) && this.size--; }; v.clear = U.prototype.clear = function() { - this.index = M(); + this.index = J(); this.h = []; this.size = 0; }; -v.values = U.prototype.values = function Ta() { +v.values = U.prototype.values = function Wa() { var b, c = this, d, e, g; - return qa(Ta, function(f) { + return ra(Wa, function(f) { switch(f.h) { case 1: b = 0; @@ -1320,9 +1348,9 @@ v.values = U.prototype.values = function Ta() { } }); }; -v.keys = U.prototype.keys = function Ua() { +v.keys = U.prototype.keys = function Xa() { var b, c = this, d, e, g; - return qa(Ua, function(f) { + return ra(Xa, function(f) { switch(f.h) { case 1: b = 0; @@ -1346,9 +1374,9 @@ v.keys = U.prototype.keys = function Ua() { } }); }; -v.entries = U.prototype.entries = function Va() { +v.entries = U.prototype.entries = function Ya() { var b, c = this, d, e, g; - return qa(Va, function(f) { + return ra(Ya, function(f) { switch(f.h) { case 1: b = 0; @@ -1372,7 +1400,7 @@ v.entries = U.prototype.entries = function Va() { } }); }; -function Sa(a) { +function Va(a) { var b = Math.pow(2, this.A) - 1; if ("number" == typeof a) { return a & b; @@ -1382,11 +1410,11 @@ function Sa(a) { } return 32 === this.A ? c + Math.pow(2, 31) : c; } -function Ra() { +function Ua() { throw Error("The keystore is limited to 32 for EcmaScript5"); } ;V.prototype.add = function(a, b, c) { - O(a) && (b = a, a = xa(b, this.key)); + M(a) && (b = a, a = za(b, this.key)); if (b && (a || 0 === a)) { if (!c && this.reg.has(a)) { return this.update(a, b); @@ -1399,7 +1427,7 @@ function Ra() { } else { var f = e.R; if (!f || f(b)) { - e.constructor === String ? e = ["" + e] : N(e) && (e = [e]), Wa(b, e, this.T, 0, g, a, e[0], c); + e.constructor === String ? e = ["" + e] : K(e) && (e = [e]), Za(b, e, this.T, 0, g, a, e[0], c); } } } @@ -1408,7 +1436,7 @@ function Ra() { f = this.M[d]; var h = this.$[d]; g = this.tag.get(h); - e = M(); + e = J(); if ("function" === typeof f) { if (f = f(b), !f) { continue; @@ -1419,10 +1447,10 @@ function Ra() { continue; } f.constructor === String && (f = "" + f); - f = xa(b, f); + f = za(b, f); } if (g && f) { - for (N(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { + for (K(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { var l = f[h]; if (!e[l]) { e[l] = 1; @@ -1450,7 +1478,7 @@ function Ra() { } if (this.store && (!c || !this.store.has(a))) { if (this.H) { - var q = M(); + var q = J(); for (c = 0; c < this.H.length; c++) { if (d = this.H[c], g = d.R, !g || g(b)) { g = void 0; @@ -1460,11 +1488,11 @@ function Ra() { continue; } d = [d.la]; - } else if (N(d) || d.constructor === String) { + } else if (K(d) || d.constructor === String) { q[d] = b[d]; continue; } - Xa(b, q, d, 0, d[0], g); + $a(b, q, d, 0, d[0], g); } } } @@ -1473,21 +1501,21 @@ function Ra() { } return this; }; -function Xa(a, b, c, d, e, g) { +function $a(a, b, c, d, e, g) { a = a[e]; if (d === c.length - 1) { b[e] = g || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - Xa(a, b, c, d, e); + $a(a, b, c, d, e); } } else { - b = b[e] || (b[e] = M()), e = c[++d], Xa(a, b, c, d, e); + b = b[e] || (b[e] = J()), e = c[++d], $a(a, b, c, d, e); } } } -function Wa(a, b, c, d, e, g, f, h) { +function Za(a, b, c, d, e, g, f, h) { if (a = a[f]) { if (d === b.length - 1) { if (a.constructor === Array) { @@ -1503,19 +1531,19 @@ function Wa(a, b, c, d, e, g, f, h) { } else { if (a.constructor === Array) { for (f = 0; f < a.length; f++) { - Wa(a, b, c, d, e, g, f, h); + Za(a, b, c, d, e, g, f, h); } } else { - f = b[++d], Wa(a, b, c, d, e, g, f, h); + f = b[++d], Za(a, b, c, d, e, g, f, h); } } } else { e.db && e.remove(g); } } -;function Ya(a, b, c, d, e, g, f) { +;function ab(a, b, c, d, e, g, f) { var h = a.length, k = [], l; - var m = M(); + var m = J(); for (var n = 0, p = void 0, q; n < b; n++) { for (var r = 0; r < h; r++) { if (q = a[r], n < q.length && (p = q[n])) { @@ -1534,7 +1562,7 @@ function Wa(a, b, c, d, e, g, f, h) { } if (a = k.length) { if (e) { - k = 1 < k.length ? Za(k, d, c, f, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; + k = 1 < k.length ? bb(k, d, c, f, 0) : (k = k[0]).length > c || d ? k.slice(d, c + d) : k; } else { if (a < h) { return []; @@ -1567,8 +1595,8 @@ function Wa(a, b, c, d, e, g, f, h) { } return k; } -function Za(a, b, c, d, e) { - var g = [], f = M(), h = a.length, k = 0; +function bb(a, b, c, d, e) { + var g = [], f = J(), h = a.length, k = 0; if (d) { for (e = h - 1; 0 <= e; e--) { d = a[e]; @@ -1587,7 +1615,7 @@ function Za(a, b, c, d, e) { } } } else { - for (var n = ya(a), p = 0; p < n; p++) { + for (var n = Aa(a), p = 0; p < n; p++) { for (var q = h - 1; 0 <= q; q--) { if (l = (d = a[q][p]) && d.length) { for (var r = 0; r < l; r++) { @@ -1609,8 +1637,8 @@ function Za(a, b, c, d, e) { } return g; } -function $a(a, b) { - for (var c = M(), d = [], e = 0, g; e < b.length; e++) { +function cb(a, b) { + for (var c = J(), d = [], e = 0, g; e < b.length; e++) { g = b[e]; for (var f = 0; f < g.length; f++) { c[g[f]] = 1; @@ -1622,7 +1650,7 @@ function $a(a, b) { return d; } ;V.prototype.search = function(a, b, c, d) { - c || (!b && O(a) ? (c = a, a = "") : O(b) && (c = b, b = 0)); + c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); var e = [], g = [], f = 0; if (c) { c.constructor === Array && (c = {index:c}); @@ -1641,7 +1669,7 @@ function $a(a, b) { m.constructor !== Array && (m = [m]); for (var u = [], w = 0, x = void 0; w < m.length; w++) { x = m[w]; - if (N(x)) { + if (K(x)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (x.field && x.tag) { @@ -1684,7 +1712,7 @@ function $a(a, b) { } g.push(p = p.db.tag(u[h + 1], b, r, n)); } else { - p = ab.call(this, u[h], u[h + 1], b, r, n); + p = db.call(this, u[h], u[h + 1], b, r, n); } e.push({field:u[h], tag:u[h + 1], result:p}); } @@ -1697,7 +1725,7 @@ function $a(a, b) { }) : e; } } - N(l) && (l = [l]); + K(l) && (l = [l]); } l || (l = this.field); u = !d && (this.worker || this.db) && []; @@ -1705,7 +1733,7 @@ function $a(a, b) { for (z = x = t = void 0; w < l.length; w++) { if (x = l[w], !this.db || !this.tag || this.I[w]) { t = void 0; - N(x) || (t = x, x = t.field, a = t.query || a, b = t.limit || b, r = t.offset || r, p = t.suggest || p, n = this.store && (t.enrich || n)); + K(x) || (t = x, x = t.field, a = t.query || a, b = t.limit || b, r = t.offset || r, p = t.suggest || p, n = this.store && (t.enrich || n)); if (d) { t = d[w]; } else { @@ -1734,9 +1762,9 @@ function $a(a, b) { if (this.db && d) { if (!F) { for (D = l.length; D < d.length; D++) { - var K = d[D]; - if (K && K.length) { - B++, A.push(K); + var L = d[D]; + if (L && L.length) { + B++, A.push(L); } else if (!p) { return e; } @@ -1744,24 +1772,24 @@ function $a(a, b) { } } else { D = 0; - for (var Ib = K = void 0; D < m.length; D += 2) { - K = this.tag.get(m[D]); - if (!K) { + for (var Lb = L = void 0; D < m.length; D += 2) { + L = this.tag.get(m[D]); + if (!L) { if (console.warn("Tag '" + m[D] + ":" + m[D + 1] + "' will be skipped because there is no field '" + m[D] + "'."), p) { continue; } else { return e; } } - if (Ib = (K = K && K.get(m[D + 1])) && K.length) { - B++, A.push(K); + if (Lb = (L = L && L.get(m[D + 1])) && L.length) { + B++, A.push(L); } else if (!p) { return e; } } } if (B) { - t = $a(t, A); + t = cb(t, A); z = t.length; if (!z && !p) { return e; @@ -1790,9 +1818,9 @@ function $a(a, b) { u.push(g.db.tag(m[n + 1], b, r, !1)); } } - var Jb = this; + var Mb = this; return Promise.all(u).then(function(P) { - return P.length ? Jb.search(a, b, c, P) : P; + return P.length ? Mb.search(a, b, c, P) : P; }); } if (!f) { @@ -1805,27 +1833,27 @@ function $a(a, b) { r = 0; for (p = void 0; r < g.length; r++) { p = e[r]; - n && p.length && !p[0].doc && (this.db ? u.push(p = this.index.get(this.field[0]).db.enrich(p)) : p.length && (p = bb.call(this, p))); + n && p.length && !p[0].doc && (this.db ? u.push(p = this.index.get(this.field[0]).db.enrich(p)) : p.length && (p = eb.call(this, p))); if (h) { return p; } e[r] = {field:g[r], result:p}; } if (n && this.db && u.length) { - var Da = this; + var Ea = this; return Promise.all(u).then(function(P) { for (var Q = 0; Q < P.length; Q++) { e[Q].result = P[Q]; } - return k ? cb(e, b) : q ? db(e, a, Da.index, Da.field, Da.I, q) : e; + return k ? fb(e, b) : q ? gb(e, a, Ea.index, Ea.field, Ea.I, q) : e; }); } - return k ? cb(e, b) : q ? db(e, a, this.index, this.field, this.I, q) : e; + return k ? fb(e, b) : q ? gb(e, a, this.index, this.field, this.I, q) : e; }; -function db(a, b, c, d, e, g) { +function gb(a, b, c, d, e, g) { for (var f, h, k, l = 0, m, n, p; l < a.length; l++) { for (m = a[l].result, n = a[l].field, k = c.get(n), p = k.encoder, k = k.tokenize, n = e[d.indexOf(n)], p !== f && (f = p, h = f.encode(b)), p = 0; p < m.length; p++) { - var q = "", r = xa(m[p].doc, n), u = f.encode(r); + var q = "", r = za(m[p].doc, n), u = f.encode(r); r = r.split(f.split); for (var w = 0, x, t; w < u.length; w++) { x = u[w]; @@ -1853,8 +1881,8 @@ function db(a, b, c, d, e, g) { } return a; } -function cb(a, b) { - for (var c = [], d = M(), e = 0, g, f; e < a.length; e++) { +function fb(a, b) { + for (var c = [], d = J(), e = 0, g, f; e < a.length; e++) { g = a[e]; f = g.result; for (var h = 0, k, l, m; h < f.length; h++) { @@ -1871,7 +1899,7 @@ function cb(a, b) { } return c; } -function ab(a, b, c, d, e) { +function db(a, b, c, d, e) { var g = this.tag.get(a); if (!g) { return console.warn("Tag '" + a + "' was not found"), []; @@ -1880,25 +1908,25 @@ function ab(a, b, c, d, e) { if (a > c || d) { g = g.slice(d, d + c); } - e && (g = bb.call(this, g)); + e && (g = eb.call(this, g)); return g; } } -function bb(a) { +function eb(a) { for (var b = Array(a.length), c = 0, d; c < a.length; c++) { d = a[c], b[c] = {id:d, doc:this.store.get(d)}; } return b; } ;function V(a) { - if (!this) { + if (this.constructor !== V) { return new V(a); } var b = a.document || a.doc || a, c, d; this.I = []; this.field = []; this.T = []; - this.key = (c = b.key || b.id) && eb(c, this.T) || "id"; + this.key = (c = b.key || b.id) && hb(c, this.T) || "id"; (d = a.keystore || 0) && (this.keystore = d); this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new T(d) : new Map() : d ? new U(d) : new Set(); this.H = (c = b.store || null) && !0 !== c && []; @@ -1906,7 +1934,7 @@ function bb(a) { this.cache = (c = a.cache || null) && new W(c); a.cache = !1; this.worker = a.worker; - this.index = fb.call(this, a, b); + this.index = ib.call(this, a, b); this.tag = null; if (c = b.tag) { if ("string" === typeof c && (c = [c]), c.length) { @@ -1920,7 +1948,7 @@ function bb(a) { if (!e) { throw Error("The tag field from the document descriptor is undefined."); } - d.custom ? this.M[b] = d.custom : (this.M[b] = eb(e, this.T), d.filter && ("string" === typeof this.M[b] && (this.M[b] = new String(this.M[b])), this.M[b].R = d.filter)); + d.custom ? this.M[b] = d.custom : (this.M[b] = hb(e, this.T), d.filter && ("string" === typeof this.M[b] && (this.M[b] = new String(this.M[b])), this.M[b].R = d.filter)); this.$[b] = e; this.tag.set(e, new Map()); } @@ -1954,7 +1982,7 @@ v.mount = function(a) { for (var c = 0, d; c < this.$.length; c++) { d = this.$[c]; var e; - this.index.set(d, e = new R({}, this.reg)); + this.index.set(d, e = new O({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(d); e.tag = this.tag.get(d); @@ -1977,7 +2005,7 @@ v.mount = function(a) { }; v.commit = function(a, b) { var c = this, d, e, g, f; - return I(function(h) { + return ta(function(h) { if (1 == h.h) { d = []; e = y(c.index.values()); @@ -1996,29 +2024,29 @@ v.destroy = function() { } return Promise.all(a); }; -function fb(a, b) { +function ib(a, b) { var c = new Map(), d = b.index || b.field || b; - N(d) && (d = [d]); + K(d) && (d = [d]); for (var e = 0, g, f = void 0; e < d.length; e++) { g = d[e]; - N(g) || (f = g, g = g.field); - f = O(f) ? Object.assign({}, a, f) : a; + K(g) || (f = g, g = g.field); + f = M(f) ? Object.assign({}, a, f) : a; if (this.worker) { - var h = new Ka(f); + var h = new R(f); c.set(g, h); } - this.worker || c.set(g, new R(f, this.reg)); - f.custom ? this.I[e] = f.custom : (this.I[e] = eb(g, this.T), f.filter && ("string" === typeof this.I[e] && (this.I[e] = new String(this.I[e])), this.I[e].R = f.filter)); + this.worker || c.set(g, new O(f, this.reg)); + f.custom ? this.I[e] = f.custom : (this.I[e] = hb(g, this.T), f.filter && ("string" === typeof this.I[e] && (this.I[e] = new String(this.I[e])), this.I[e].R = f.filter)); this.field[e] = g; } if (this.H) { - for (a = b.store, N(a) && (a = [a]), b = 0; b < a.length; b++) { - d = a[b], e = d.field || d, d.custom ? (this.H[b] = d.custom, d.custom.la = e) : (this.H[b] = eb(e, this.T), d.filter && ("string" === typeof this.H[b] && (this.H[b] = new String(this.H[b])), this.H[b].R = d.filter)); + for (a = b.store, K(a) && (a = [a]), b = 0; b < a.length; b++) { + d = a[b], e = d.field || d, d.custom ? (this.H[b] = d.custom, d.custom.la = e) : (this.H[b] = hb(e, this.T), d.filter && ("string" === typeof this.H[b] && (this.H[b] = new String(this.H[b])), this.H[b].R = d.filter)); } } return c; } -function eb(a, b) { +function hb(a, b) { for (var c = a.split(":"), d = 0, e = 0; e < c.length; e++) { a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); } @@ -2032,7 +2060,7 @@ v.update = function(a, b) { return this.remove(a).add(a, b); }; v.remove = function(a) { - O(a) && (a = xa(a, this.key)); + M(a) && (a = za(a, this.key)); for (var b = y(this.index.values()), c = b.next(); !c.done; c = b.next()) { c.value.remove(a, !0); } @@ -2085,63 +2113,71 @@ v.set = function(a, b) { this.store.set(a, b); return this; }; -v.searchCache = gb; -v.export = function(a, b, c, d, e, g) { - var f; - "undefined" === typeof g && (f = new Promise(function(k) { - g = k; - })); - e || (e = 0); - d || (d = 0); - if (d < this.field.length) { - c = this.field[d]; - var h = this.index[c]; - b = this; - h.export(a, b, e ? c : "", d, e++, g) || (d++, b.export(a, b, c, d, 1, g)); - } else { - switch(e) { - case 1: - b = "tag"; - h = this.A; - c = null; - break; - case 2: - b = "store"; - h = this.store; - c = null; - break; - default: - g(); - return; +v.searchCache = jb; +v.export = function(a, b, c, d) { + c = void 0 === c ? 0 : c; + d = void 0 === d ? 0 : d; + if (c < this.field.length) { + var e = this.field[c]; + if ((b = this.index.get(e).export(a, e, c, d = 1)) && b.then) { + var g = this; + return b.then(function() { + return g.export(a, e, c + 1, d = 0); + }); } - Pa(a, this, c, b, d, e, h, g); + return this.export(a, e, c + 1, d = 0); } - return f; + switch(d) { + case 0: + var f = "reg"; + var h = Ra(this.reg); + b = null; + break; + case 1: + f = "tag"; + h = Qa(this.tag); + b = null; + break; + case 2: + f = "doc"; + h = Pa(this.store); + b = null; + break; + case 3: + f = "cfg"; + h = {}; + b = null; + break; + default: + return; + } + return Sa.call(this, a, b, f, c, d, h); }; v.import = function(a, b) { if (b) { - switch(N(b) && (b = JSON.parse(b)), a) { + switch(K(b) && (b = JSON.parse(b)), a) { case "tag": - this.A = b; break; case "reg": this.fastupdate = !1; - this.reg = b; - a = 0; - for (var c; a < this.field.length; a++) { - c = this.index[this.field[a]], c.reg = b, c.fastupdate = !1; + this.reg = new Set(b); + for (a = 0; a < this.field.length; a++) { + b = this.index.get(this.field[a]), b.fastupdate = !1, b.reg = this.reg; } break; - case "store": - this.store = b; + case "doc": + this.store = new Map(b); break; default: - a = a.split("."), c = a[0], a = a[1], c && a && this.index[c].import(a, b); + a = a.split("."); + var c = a[0]; + a = a[1]; + c && a && this.index.get(c).import(a, b); } } }; Na(V.prototype); -function gb(a, b, c) { +function jb(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); var d = this.cache.get(a); if (!d) { @@ -2182,49 +2218,49 @@ W.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -var hb = {normalize:function(a) { +var kb = {normalize:function(a) { return a.toLowerCase(); }, dedupe:!1}; -var ib = 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 jb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), kb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; -var lb = {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 mb = /[\x00-\x7F]+/g; -var nb = /[\x00-\x7F]+/g; -var ob = /[\x00-\x7F]+/g; -var pb = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:hb, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:ib}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:ib, matcher:jb, replacer:kb}, LatinExtra:{normalize:!0, dedupe:!0, mapper:ib, replacer:kb.concat([/(?!^)[aeo]/g, ""]), matcher:jb}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +var lb = 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 mb = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["pf", "f"]]), nb = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /([^0-9])\1+/g, "$1"]; +var ob = {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 pb = /[\x00-\x7F]+/g; +var qb = /[\x00-\x7F]+/g; +var rb = /[\x00-\x7F]+/g; +var sb = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:kb, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:lb}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:lb, matcher:mb, replacer:nb}, LatinExtra:{normalize:!0, dedupe:!0, mapper:lb, replacer:nb.concat([/(?!^)[aeo]/g, ""]), matcher:mb}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (var b = 0; b < a.length; b++) { - for (var c = a[b], d = c.charAt(0), e = lb[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = lb[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { + for (var c = a[b], d = c.charAt(0), e = ob[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = ob[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { } a[b] = d; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(mb, " "); + return ("" + a).replace(pb, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(nb, ""); + return ("" + a).replace(qb, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ob, " "); + return ("" + a).replace(rb, " "); }}}; -var qb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -M(); -R.prototype.add = function(a, b, c, d) { +var tb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +J(); +O.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { if (!d && !c && this.reg.has(a)) { return this.update(a, b); } b = this.encoder.encode(b); if (d = b.length) { - for (var e = M(), g = M(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { + for (var e = J(), g = J(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { var l = b[this.rtl ? d - 1 - k : k], m = l.length; if (m && (f || !g[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : rb(h, d, k), p = ""; + var n = this.score ? this.score(b, l, k, null, 0) : ub(h, d, k), p = ""; switch(this.tokenize) { case "full": if (2 < m) { for (n = 0; n < m; n++) { for (var q = m; q > n; q--) { p = l.substring(n, q); - var r = this.score ? this.score(b, l, k, p, n) : rb(h, d, k, m, n); - sb(this, g, p, r, a, c); + var r = this.score ? this.score(b, l, k, p, n) : ub(h, d, k, m, n); + vb(this, g, p, r, a, c); } } break; @@ -2232,24 +2268,24 @@ R.prototype.add = function(a, b, c, d) { case "reverse": if (1 < m) { for (q = m - 1; 0 < q; q--) { - p = l[q] + p, r = this.score ? this.score(b, l, k, p, q) : rb(h, d, k, m, q), sb(this, g, p, r, a, c); + p = l[q] + p, r = this.score ? this.score(b, l, k, p, q) : ub(h, d, k, m, q), vb(this, g, p, r, a, c); } p = ""; } case "forward": if (1 < m) { for (q = 0; q < m; q++) { - p += l[q], sb(this, g, p, n, a, c); + p += l[q], vb(this, g, p, n, a, c); } break; } default: - if (sb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { - for (m = M(), p = this.aa, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) { + if (vb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { + for (m = J(), p = this.aa, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) { if ((l = b[this.rtl ? d - 1 - k - r : k + r]) && !m[l]) { m[l] = 1; - var u = this.score ? this.score(b, n, k, l, r) : rb(p + (d / 2 > p ? 0 : 1), d, k, q - 1, r - 1), w = this.bidirectional && l > n; - sb(this, e, w ? n : l, u, a, c, w ? l : n); + var u = this.score ? this.score(b, n, k, l, r) : ub(p + (d / 2 > p ? 0 : 1), d, k, q - 1, r - 1), w = this.bidirectional && l > n; + vb(this, e, w ? n : l, u, a, c, w ? l : n); } } } @@ -2261,13 +2297,13 @@ R.prototype.add = function(a, b, c, d) { b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.da && tb(this)); + this.db && (b || this.commit_task.push({del:a}), this.da && wb(this)); return this; }; -function sb(a, b, c, d, e, g, f) { +function vb(a, b, c, d, e, g, f) { var h = f ? a.ctx : a.map, k; if (!b[c] || f && !(k = b[c])[f]) { - if (f ? (b = k || (b[c] = M()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { + if (f ? (b = k || (b[c] = J()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { if (h.length === Math.pow(2, 31) - 1) { b = new S(h); if (a.fastupdate) { @@ -2282,12 +2318,12 @@ function sb(a, b, c, d, e, g, f) { } } } -function rb(a, b, c, d, e) { +function ub(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 X(a, b, c, d) { if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? ub(a) : a; + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? xb(a) : a; } for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { if ((f = a[g]) && (h = f.length)) { @@ -2302,7 +2338,7 @@ function rb(a, b, c, d, e) { h > b && (f = f.slice(0, b), h = f.length), e.push(f); } else { if (h >= b) { - return h > b && (f = f.slice(0, b)), d ? ub(f) : f; + return h > b && (f = f.slice(0, b)), d ? xb(f) : f; } e = [f]; } @@ -2316,9 +2352,9 @@ function rb(a, b, c, d, e) { return e; } e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? ub(e) : e; + return d ? xb(e) : e; } -function ub(a) { +function xb(a) { for (var b = 0; b < a.length; b++) { a[b] = {score:b, id:a[b]}; } @@ -2365,19 +2401,19 @@ function ub(a) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = d.concat([a.result])); - a.result = vb(d, e, g, f, h, a.J); + a.result = yb(d, e, g, f, h, a.J); return h ? a.result : a; }); } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = vb(d, e, g, f, h, this.J)); + d.length && (this.result.length && (d = d.concat([this.result])), this.result = yb(d, e, g, f, h, this.J)); return h ? this.result : this; }; -function vb(a, b, c, d, e, g) { +function yb(a, b, c, d, e, g) { if (!a.length) { return a; } "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? X(a[0], b, c, d) : a[0] : Za(a, c, b, e, g); + return 2 > a.length ? e ? X(a[0], b, c, d) : a[0] : bb(a, c, b, e, g); } ;Y.prototype.and = function() { if (this.result.length) { @@ -2424,24 +2460,24 @@ function vb(a, b, c, d, e, g) { if (c.length) { return Promise.all(c).then(function() { d = [a.result].concat(d); - a.result = wb(d, e, g, f, a.J, h); + a.result = zb(d, e, g, f, a.J, h); return f ? a.result : a; }); } d = [this.result].concat(d); - this.result = wb(d, e, g, f, this.J, h); + this.result = zb(d, e, g, f, this.J, h); return f ? this.result : this; } return this; }; -function wb(a, b, c, d, e, g) { +function zb(a, b, c, d, e, g) { if (2 > a.length) { return []; } var f = []; - M(); - var h = ya(a); - return h ? Ya(a, h, b, c, g, e, d) : f; + J(); + var h = Aa(a); + return h ? ab(a, h, b, c, g, e, d) : f; } ;Y.prototype.xor = function() { var a = this, b = arguments, c = b[0]; @@ -2484,14 +2520,14 @@ function wb(a, b, c, d, e, g) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = [a.result].concat(d)); - a.result = xb(d, e, g, f, !h, a.J); + a.result = Ab(d, e, g, f, !h, a.J); return h ? a.result : a; }); } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = xb(d, e, g, f, !h, a.J)); + d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Ab(d, e, g, f, !h, a.J)); return h ? this.result : this; }; -function xb(a, b, c, d, e, g) { +function Ab(a, b, c, d, e, g) { if (!a.length) { return a; } @@ -2499,7 +2535,7 @@ function xb(a, b, c, d, e, g) { return e ? X(a[0], b, c, d) : a[0]; } d = []; - for (var f = M(), h = 0, k = 0, l; k < a.length; k++) { + for (var f = J(), h = 0, k = 0, l; k < a.length; k++) { if (l = a[k]) { for (var m = 0, n; m < l.length; m++) { if (n = l[m]) { @@ -2580,14 +2616,14 @@ function xb(a, b, c, d, e, g) { } if (c.length) { return Promise.all(c).then(function() { - a.result = yb.call(a, d, e, g, f); + a.result = Bb.call(a, d, e, g, f); return f ? a.result : a; }); } - d.length && (this.result = yb.call(this, d, e, g, f)); + d.length && (this.result = Bb.call(this, d, e, g, f)); return f ? this.result : this; }; -function yb(a, b, c, d) { +function Bb(a, b, c, d) { if (!a.length) { return this.result; } @@ -2617,7 +2653,7 @@ function yb(a, b, c, d) { return e; } ;function Y(a) { - if (!this) { + if (this.constructor !== Y) { return new Y(a); } if (a && a.index) { @@ -2658,14 +2694,14 @@ Y.prototype.boost = function(a) { return this; }; Y.prototype.resolve = function(a, b, c) { - zb = 1; + Cb = 1; var d = this.result; this.result = this.index = null; return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), X(d, a || 100, b, c)) : d; }; -var zb = 1; -R.prototype.search = function(a, b, c) { - c || (!b && O(a) ? (c = a, a = "") : O(b) && (c = b, b = 0)); +var Cb = 1; +O.prototype.search = function(a, b, c) { + c || (!b && M(a) ? (c = a, a = "") : M(b) && (c = b, b = 0)); var d = [], e = 0, g; if (c) { a = c.query || a; @@ -2673,26 +2709,26 @@ R.prototype.search = function(a, b, c) { e = c.offset || 0; var f = c.context; var h = c.suggest; - (g = zb && !1 !== c.resolve) || (zb = 0); + (g = Cb && !1 !== c.resolve) || (Cb = 0); var k = g && c.enrich; var l = c.boost; var m = this.db && c.tag; } else { - g = this.resolve || zb; + g = this.resolve || Cb; } a = this.encoder.encode(a); var n = a.length; b || !g || (b = 100); if (1 === n) { - return Ab.call(this, a[0], "", b, e, g, k, m); + return Db.call(this, a[0], "", b, e, g, k, m); } f = this.depth && !1 !== f; if (2 === n && f && !h) { - return Ab.call(this, a[0], a[1], b, e, g, k, m); + return Db.call(this, a[0], a[1], b, e, g, k, m); } var p = c = 0; if (1 < n) { - for (var q = M(), r = [], u = 0, w = void 0; u < n; u++) { + for (var q = J(), r = [], u = 0, w = void 0; u < n; u++) { if ((w = a[u]) && !q[w]) { if (h || this.db || Z(this, w)) { r.push(w), q[w] = 1; @@ -2712,17 +2748,17 @@ R.prototype.search = function(a, b, c) { } var x = 0; if (1 === n) { - return Ab.call(this, a[0], "", b, e, g, k, m); + return Db.call(this, a[0], "", b, e, g, k, m); } if (2 === n && f && !h) { - return Ab.call(this, a[0], a[1], b, e, g, k, m); + return Db.call(this, a[0], a[1], b, e, g, k, m); } if (1 < n) { if (f) { var t = a[0]; x = 1; } else { - 9 < c && 3 < c / p && a.sort(va); + 9 < c && 3 < c / p && a.sort(xa); } } if (this.db) { @@ -2732,7 +2768,7 @@ R.prototype.search = function(a, b, c) { var z = this; return function() { var A, B, D; - return I(function(F) { + return ta(function(F) { switch(F.h) { case 1: B = A = void 0; @@ -2745,11 +2781,11 @@ R.prototype.search = function(a, b, c) { return t ? G(F, Z(z, B, t, 0, 0, !1, !1), 8) : G(F, Z(z, B, "", 0, 0, !1, !1), 7); case 7: A = F.F; - A = Bb(A, d, h, z.resolution); + A = Eb(A, d, h, z.resolution); F.h = 6; break; case 8: - A = F.F, A = Bb(A, d, h, z.aa), h && !1 === A && d.length || (t = B); + A = F.F, A = Eb(A, d, h, z.aa), h && !1 === A && d.length || (t = B); case 6: if (A) { return F.return(A); @@ -2774,14 +2810,14 @@ R.prototype.search = function(a, b, c) { F.h = 2; break; case 4: - return F.return(g ? Ya(d, z.resolution, b, e, h, l, g) : new Y(d[0])); + return F.return(g ? ab(d, z.resolution, b, e, h, l, g) : new Y(d[0])); } }); }(); } for (k = f = void 0; x < n; x++) { k = a[x]; - t ? (f = Z(this, k, t, 0, 0, !1, !1), f = Bb(f, d, h, this.aa), h && !1 === f && d.length || (t = k)) : (f = Z(this, k, "", 0, 0, !1, !1), f = Bb(f, d, h, this.resolution)); + t ? (f = Z(this, k, t, 0, 0, !1, !1), f = Eb(f, d, h, this.aa), h && !1 === f && d.length || (t = k)) : (f = Z(this, k, "", 0, 0, !1, !1), f = Eb(f, d, h, this.resolution)); if (f) { return f; } @@ -2800,16 +2836,16 @@ R.prototype.search = function(a, b, c) { } } } - d = Ya(d, this.resolution, b, e, h, l, g); + d = ab(d, this.resolution, b, e, h, l, g); return g ? d : new Y(d); }; -function Ab(a, b, c, d, e, g, f) { +function Db(a, b, c, d, e, g, f) { a = Z(this, a, b, c, d, e, g, f); return this.db ? a.then(function(h) { return e ? h : h && h.length ? e ? X(h, c, d) : new Y(h) : e ? [] : new Y([]); }) : a && a.length ? e ? X(a, c, d) : new Y(a) : e ? [] : new Y([]); } -function Bb(a, b, c, d) { +function Eb(a, b, c, d) { var e = []; if (a) { d = Math.min(a.length, d); @@ -2832,7 +2868,7 @@ function Z(a, b, c, d, e, g, f, h) { a = c ? (a = a.ctx.get(k ? b : c)) && a.get(k ? c : b) : a.map.get(b); return a; } -;R.prototype.remove = function(a, b) { +;O.prototype.remove = function(a, b) { var c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { @@ -2847,15 +2883,15 @@ function Z(a, b, c, d, e, g, f, h) { } } } else { - Cb(this.map, a), this.depth && Cb(this.ctx, a); + Fb(this.map, a), this.depth && Fb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.da && tb(this)); + this.db && (this.commit_task.push({del:a}), this.da && wb(this)); this.cache && this.cache.remove(a); return this; }; -function Cb(a, b) { +function Fb(a, b) { var c = 0; if (a.constructor === Array) { for (var d = 0, e = void 0, g; d < a.length; d++) { @@ -2870,24 +2906,24 @@ function Cb(a, b) { } } else { for (d = y(a), e = d.next(); !e.done; e = d.next()) { - g = e.value, e = g[0], (g = Cb(g[1], b)) ? c += g : a.delete(e); + g = e.value, e = g[0], (g = Fb(g[1], b)) ? c += g : a.delete(e); } } return c; } -;function R(a, b) { - if (!this) { - return new R(a); +;function O(a, b) { + if (this.constructor !== O) { + return new O(a); } if (a) { - var c = N(a) ? a : a.preset; - c && (qb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, qb[c], a)); + var c = K(a) ? a : a.preset; + c && (tb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, tb[c], a)); } else { a = {}; } c = a.context || {}; - var d = N(a.encoder) ? pb[a.encoder] : a.encode || a.encoder || hb; - this.encoder = d.encode ? d : "object" === typeof d ? new Ga(d) : {encode:d}; + var d = K(a.encoder) ? sb[a.encoder] : a.encode || a.encoder || kb; + this.encoder = d.encode ? d : "object" === typeof d ? new N(d) : {encode:d}; var e; this.resolution = a.resolution || 9; this.tokenize = e = a.tokenize || "strict"; @@ -2910,7 +2946,7 @@ function Cb(a, b) { this.commit_task = []; this.commit_timer = null; } -v = R.prototype; +v = O.prototype; v.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -2923,7 +2959,7 @@ v.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function tb(a) { +function wb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2949,7 +2985,7 @@ v.update = function(a, b) { return c.add(a, b); }) : this.add(a, b); }; -function Db(a) { +function Gb(a) { var b = 0; if (a.constructor === Array) { for (var c = 0, d = void 0; c < a.length; c++) { @@ -2959,7 +2995,7 @@ function Db(a) { for (c = y(a), d = c.next(); !d.done; d = c.next()) { var e = d.value; d = e[0]; - (e = Db(e[1])) ? b += e : a.delete(d); + (e = Gb(e[1])) ? b += e : a.delete(d); } } return b; @@ -2968,62 +3004,47 @@ v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Db(this.map); - this.depth && Db(this.ctx); + Gb(this.map); + this.depth && Gb(this.ctx); return this; }; -v.searchCache = gb; -v.export = function(a, b, c, d, e, g) { - var f = !0; - "undefined" === typeof g && (f = new Promise(function(n) { - g = n; - })); - switch(e || (e = 0)) { +v.searchCache = jb; +v.export = function(a, b, c, d) { + d = void 0 === d ? 0 : d; + switch(d) { case 0: - var h = "reg"; - if (this.fastupdate) { - var k = M(); - for (var l = y(this.reg.keys()), m = l.next(); !m.done; m = l.next()) { - k[m.value] = 1; - } - } else { - k = this.reg; - } + var e = "reg"; + var g = Ra(this.reg); break; case 1: - h = "cfg"; - k = {doc:0, opt:this.h ? 1 : 0}; + e = "cfg"; + g = {}; break; case 2: - h = "map"; - k = this.map; + e = "map"; + g = Pa(this.map); break; case 3: - h = "ctx"; - k = this.ctx; + e = "ctx"; + g = Qa(this.ctx); break; default: - "undefined" === typeof c && g && g(); return; } - Pa(a, b || this, c, h, d, e, k, g); - return f; + return Sa.call(this, a, b, e, c, d, g); }; v.import = function(a, b) { if (b) { - switch(N(b) && (b = JSON.parse(b)), a) { - case "cfg": - this.h = !!b.opt; - break; + switch(K(b) && (b = JSON.parse(b)), a) { case "reg": this.fastupdate = !1; - this.reg = b; + this.reg = new Set(b); break; case "map": - this.map = b; + this.map = new Map(b); break; case "ctx": - this.ctx = b; + this.ctx = new Map(b); } } }; @@ -3079,12 +3100,12 @@ v.serialize = function(a) { e = "index.ctx=new Map([" + e + "]);"; return a ? "function inject(index){" + b + d + e + "}" : b + d + e; }; -Na(R.prototype); -var Eb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Fb = ["map", "ctx", "tag", "reg", "cfg"]; -function Gb(a, b) { +Na(O.prototype); +var Hb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Ib = ["map", "ctx", "tag", "reg", "cfg"]; +function Jb(a, b) { b = void 0 === b ? {} : b; if (!this) { - return new Gb(a, b); + return new Jb(a, b); } "object" === typeof a && (b = a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3094,7 +3115,7 @@ function Gb(a, b) { this.db = null; this.h = {}; } -v = Gb.prototype; +v = Jb.prototype; v.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -3106,10 +3127,10 @@ v.open = function() { var a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - var d = Eb.open(a.id + (a.field ? ":" + a.field : ""), 1); + var d = Hb.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { var e = a.db = this.result; - Fb.forEach(function(g) { + Ib.forEach(function(g) { e.objectStoreNames.contains(g) || e.createObjectStore(g); }); }; @@ -3135,13 +3156,13 @@ v.close = function() { this.db = null; }; v.destroy = function() { - return Eb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return Hb.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); }; v.clear = function() { - for (var a = this.db.transaction(Fb, "readwrite"), b = 0; b < Fb.length; b++) { - a.objectStore(Fb[b]).clear(); + for (var a = this.db.transaction(Ib, "readwrite"), b = 0; b < Ib.length; b++) { + a.objectStore(Ib[b]).clear(); } - return Hb(a); + return Kb(a); }; v.get = function(a, b, c, d, e, g) { c = void 0 === c ? 0 : c; @@ -3150,7 +3171,7 @@ v.get = function(a, b, c, d, e, g) { g = void 0 === g ? !1 : g; a = this.db.transaction(b ? "ctx" : "map", "readonly").objectStore(b ? "ctx" : "map").get(b ? b + ":" + a : a); var f = this; - return Hb(a).then(function(h) { + return Kb(a).then(function(h) { var k = []; if (!h || !h.length) { return k; @@ -3185,7 +3206,7 @@ v.tag = function(a, b, c, d) { d = void 0 === d ? !1 : d; a = this.db.transaction("tag", "readonly").objectStore("tag").get(a); var e = this; - return Hb(a).then(function(g) { + return Kb(a).then(function(g) { if (!g || !g.length || c >= g.length) { return []; } @@ -3199,7 +3220,7 @@ v.tag = function(a, b, c, d) { v.enrich = function(a) { "object" !== typeof a && (a = [a]); for (var b = this.db.transaction("reg", "readonly").objectStore("reg"), c = [], d = 0; d < a.length; d++) { - c[d] = Hb(b.get(a[d])); + c[d] = Kb(b.get(a[d])); } return Promise.all(c).then(function(e) { for (var g = 0; g < e.length; g++) { @@ -3210,7 +3231,7 @@ v.enrich = function(a) { }; v.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return Hb(a); + return Kb(a); }; v.search = null; v.info = function() { @@ -3238,7 +3259,7 @@ v.transaction = function(a, b, c) { }; v.commit = function(a, b, c) { var d = this, e, g, f; - return I(function(h) { + return ta(function(h) { switch(h.h) { case 1: if (b) { @@ -3273,7 +3294,7 @@ v.commit = function(a, b, c) { h.h = 3; break; } - c || (e = e.concat(wa(a.reg))); + c || (e = e.concat(ya(a.reg))); if (!e.length) { h.h = 10; break; @@ -3385,7 +3406,7 @@ v.commit = function(a, b, c) { } }); }; -function Kb(a, b, c) { +function Nb(a, b, c) { for (var d = a.value, e, g, f = 0, h = 0, k; h < d.length; h++) { if (k = c ? d : d[h]) { for (var l = 0, m, n; l < b.length; l++) { @@ -3412,17 +3433,17 @@ v.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Kb(c, a); + c && Nb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Kb(c, a); + c && Nb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Kb(c, a, !0); + c && Nb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3430,7 +3451,7 @@ v.remove = function(a) { } })]); }; -function Hb(a) { +function Kb(a) { return new Promise(function(b, c) { a.onsuccess = function() { b(this.result); @@ -3442,8 +3463,8 @@ function Hb(a) { a = null; }); } -;var Lb = {Index:R, Charset:pb, Encoder:Ga, Document:V, Worker:Ka, Resolver:Y, IndexedDB:Gb, Language:{}}, Mb = self, Nb; -(Nb = Mb.define) && Nb.amd ? Nb([], function() { - return Lb; -}) : "object" === typeof Mb.exports ? Mb.exports = Lb : Mb.FlexSearch = Lb; +;var Ob = {Index:O, Charset:sb, Encoder:N, Document:V, Worker:R, Resolver:Y, IndexedDB:Jb, Language:{}}, Pb = self, Qb; +(Qb = Pb.define) && Qb.amd ? Qb([], function() { + return Ob; +}) : "object" === typeof Pb.exports ? Pb.exports = Ob : Pb.FlexSearch = Ob; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 00b97ea..9fdfbb8 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -5,130 +5,129 @@ * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var u;function aa(a){var b=0;return function(){return b>>0)+"_",e=0;return b}); -E("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;cc&&(c=Math.max(c+e,0));cthis.L&&(this.S.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.h&&(this.N.set(a,d),this.N.size>this.L&&(this.N.clear(),this.h=this.h/1.1|0));return d};function Ha(a){a.U=null;a.N.clear();a.S.clear()};function Ia(a){var b,c,d,e,h,f,g,k;return I(function(l){a=a.data;b=self._index;c=a.args;d=a.task;switch(d){case "init":e=a.options||{};(h=e.config)&&(e=(await import(h))["default"]);(f=a.factory)?(Function("return "+f)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new R(e);postMessage({id:a.id});break;default:g=a.id,k=b[d].apply(b,c),postMessage("search"===d?{id:g,msg:k}:{id:g})}l.h=0})};var Ja=0; -function Ka(a){function b(f){function g(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=M();if(this.worker){d?this.worker.on("message",g):this.worker.onmessage=g;if(a.config)return new Promise(function(k){e.h[++Ja]=function(){k(e)};e.worker.postMessage({id:Ja,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(!this)return new Ka(a);var c="undefined"!==typeof self?self._factory:"undefined"!== -typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,h=La(c,d,a.worker);return h.then?h.then(function(f){return b.call(e,f)}):b.call(this,h)}Ma("add");Ma("append");Ma("search");Ma("update");Ma("remove"); -function Ma(a){Ka.prototype[a]=Ka.prototype[a+"Async"]=function(){var b=this,c=arguments,d,e,h,f,g;return I(function(k){d=b;e=[].slice.call(c);h=e[e.length-1];"function"===typeof h&&(f=h,e.splice(e.length-1,1));g=new Promise(function(l){d.h[++Ja]=l;d.worker.postMessage({task:a,id:Ja,args:e})});return f?(g.then(f),k.return(b)):k.return(g)})}} -function La(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ia.toString()],{type:"text/javascript"}))):new window.Worker(N(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};function Na(a){Oa.call(a,"add");Oa.call(a,"append");Oa.call(a,"search");Oa.call(a,"update");Oa.call(a,"remove")}function Oa(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function Pa(a,b,c,d,e,h,f,g){(d=a(c?c+"."+d:d,JSON.stringify(f)))&&d.then?d.then(function(){b.export(a,b,c,e,h+1,g)}):b.export(a,b,c,e,h+1,g)};function Qa(a,b,c,d){for(var e=[],h=0,f;h=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} +this.replacer[k+1]);this.cache&&g.length<=this.A&&(this.S.set(g,f),this.S.size>this.L&&(this.S.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.h&&(this.N.set(a,d),this.N.size>this.L&&(this.N.clear(),this.h=this.h/1.1|0));return d};function Ia(a){a.U=null;a.N.clear();a.S.clear()};function Ja(a){var b,c,d,e,h,f,g,k;return ta(function(l){a=a.data;b=self._index;c=a.args;d=a.task;switch(d){case "init":e=a.options||{};(h=e.config)&&(e=(await import(h))["default"]);(f=a.factory)?(Function("return "+f)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new O(e);postMessage({id:a.id});break;default:g=a.id,k=b[d].apply(b,c),postMessage("search"===d?{id:g,msg:k}:{id:g})}l.h=0})};var Ka=0; +function R(a){function b(f){function g(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=J();if(this.worker){d?this.worker.on("message",g):this.worker.onmessage=g;if(a.config)return new Promise(function(k){e.h[++Ka]=function(){k(e)};e.worker.postMessage({id:Ka,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(this.constructor!==R)return new R(a);var c="undefined"!==typeof self?self._factory: +"undefined"!==typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,h=La(c,d,a.worker);return h.then?h.then(function(f){return b.call(e,f)}):b.call(this,h)}Ma("add");Ma("append");Ma("search");Ma("update");Ma("remove"); +function Ma(a){R.prototype[a]=R.prototype[a+"Async"]=function(){var b=this,c=arguments,d,e,h,f,g;return ta(function(k){d=b;e=[].slice.call(c);h=e[e.length-1];"function"===typeof h&&(f=h,e.splice(e.length-1,1));g=new Promise(function(l){d.h[++Ka]=l;d.worker.postMessage({task:a,id:Ka,args:e})});return f?(g.then(f),k.return(b)):k.return(g)})}} +function La(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ja.toString()],{type:"text/javascript"}))):new window.Worker(K(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function Na(a){Oa.call(a,"add");Oa.call(a,"append");Oa.call(a,"search");Oa.call(a,"update");Oa.call(a,"remove")}function Oa(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function Pa(a){var b=[];a=x(a.entries());for(var c=a.next();!c.done;c=a.next())b.push(c.value);return b}function Qa(a){var b=[];a=x(a.entries());for(var c=a.next();!c.done;c=a.next())b.push(Pa(c.value));return b}function Ra(a){var b=[];a=x(a.keys());for(var c=a.next();!c.done;c=a.next())b.push(c.value);return b}function Sa(a,b,c,d,e,h){if((c=a(b?b+"."+c:c,JSON.stringify(h)))&&c.then){var f=this;return c.then(function(){return f.export(a,b,d,e+1)})}return this.export(a,b,d,e+1)};function Ta(a,b,c,d){for(var e=[],h=0,f;h=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var h=0,f=0,g,k;fc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(f=0;fd)d-=g.length; +d)return function(e){for(var h=0;hc||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d,c+d)}else{e=[];for(f=0;fd)d-=g.length; else{if(g.length>c||d)g=g.slice(d,c+d),c-=g.length,d&&(d-=g.length);e.push(g);if(!c)break}k=1c||d)a=a.slice(d,d+c);e&&(a=bb.call(this,a));return a}} -function bb(a){for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; -W.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};W.prototype.remove=function(a){for(var b=y(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};W.prototype.clear=function(){this.cache.clear();this.h=""};var hb={normalize:function(a){return a.toLowerCase()},dedupe:!1};var ib=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 jb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),kb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];var lb={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 mb=/[\x00-\x7F]+/g;var nb=/[\x00-\x7F]+/g;var ob=/[\x00-\x7F]+/g;var pb={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:hb,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:ib},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:ib,matcher:jb,replacer:kb},LatinExtra:{normalize:!0,dedupe:!0,mapper:ib,replacer:kb.concat([/(?!^)[aeo]/g,""]),matcher:jb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):rb(g,d,k,m,n);sb(this,h,p,r,a,c)}break}case "reverse":if(1< -m){for(q=m-1;0p?0:1),d,k,q-1,r-1),w=this.bidirectional&&l>n;sb(this,e,w?n:l,v,a,c,w?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.da&&tb(this));return this}; -function sb(a,b,c,d,e,h,f){var g=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=M()),b[f]=1,(k=g.get(f))?g=k:g.set(f,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!h||!g.includes(e)){if(g.length===Math.pow(2,31)-1){b=new S(g);if(a.fastupdate)for(c=y(a.reg.values()),h=c.next();!h.done;h=c.next())h=h.value,h.includes(g)&&(h[h.indexOf(g)]=b);k[d]=g=b}g.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(g):a.reg.set(e,[g]))}} -function rb(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?ub(a):a;for(var e=[],h=0,f=void 0,g=void 0;h=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),d?ub(f):f;e=[f]}b-=g;if(!b)break}if(!e.length)return e;e=1a.length?e?X(a[0],b,c,d):a[0]:Za(a,c,b,e,h)};Y.prototype.and=function(){if(this.result.length){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.and.apply(a,b)});if(c[0]&&c[0].index)return this.and.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return[];var f=[];M();var g=ya(a);return g?Ya(a,g,b,c,h,e,d):f};Y.prototype.xor=function(){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return e?X(a[0],b,c,d):a[0];d=[];for(var f=M(),g=0,k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,h,f,g):a.db.get(b,"",d,e,h,f,g);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};R.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var h=e.indexOf(a);h===c.length-1?e.pop():e.splice(h,1)}}else Cb(this.map,a),this.depth&&Cb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.da&&tb(this));this.cache&&this.cache.remove(a);return this}; -function Cb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,h;dc||d)a=a.slice(d,d+c);e&&(a=eb.call(this,a));return a}} +function eb(a){for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +W.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};W.prototype.remove=function(a){for(var b=x(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};W.prototype.clear=function(){this.cache.clear();this.h=""};var kb={normalize:function(a){return a.toLowerCase()},dedupe:!1};var lb=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 mb=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),nb=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];var ob={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 pb=/[\x00-\x7F]+/g;var qb=/[\x00-\x7F]+/g;var rb=/[\x00-\x7F]+/g;var sb={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:kb,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:lb},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:lb,matcher:mb,replacer:nb},LatinExtra:{normalize:!0,dedupe:!0,mapper:lb,replacer:nb.concat([/(?!^)[aeo]/g,""]),matcher:mb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):ub(g,d,k,m,n);vb(this,h,p,r,a,c)}break}case "reverse":if(1< +m){for(q=m-1;0p?0:1),d,k,q-1,r-1),w=this.bidirectional&&l>n;vb(this,e,w?n:l,v,a,c,w?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.da&&wb(this));return this}; +function vb(a,b,c,d,e,h,f){var g=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=J()),b[f]=1,(k=g.get(f))?g=k:g.set(f,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!h||!g.includes(e)){if(g.length===Math.pow(2,31)-1){b=new S(g);if(a.fastupdate)for(c=x(a.reg.values()),h=c.next();!h.done;h=c.next())h=h.value,h.includes(g)&&(h[h.indexOf(g)]=b);k[d]=g=b}g.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(g):a.reg.set(e,[g]))}} +function ub(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?xb(a):a;for(var e=[],h=0,f=void 0,g=void 0;h=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),d?xb(f):f;e=[f]}b-=g;if(!b)break}if(!e.length)return e;e=1a.length?e?X(a[0],b,c,d):a[0]:bb(a,c,b,e,h)};Y.prototype.and=function(){if(this.result.length){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.and.apply(a,b)});if(c[0]&&c[0].index)return this.and.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return[];var f=[];J();var g=Aa(a);return g?ab(a,g,b,c,h,e,d):f};Y.prototype.xor=function(){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return e?X(a[0],b,c,d):a[0];d=[];for(var f=J(),g=0,k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,h,f,g):a.db.get(b,"",d,e,h,f,g);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};O.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var h=e.indexOf(a);h===c.length-1?e.pop():e.splice(h,1)}}else Fb(this.map,a),this.depth&&Fb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.da&&wb(this));this.cache&&this.cache.remove(a);return this}; +function Fb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,h;d=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=h.length)return[];if(!b&&!c)return h;h=h.slice(c,c+b);return d?e.enrich(h):h})}; -u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=h.length)return[];if(!b&&!c)return h;h=h.slice(c,c+b);return d?e.enrich(h):h})}; +u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;dm&&!h&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(h=1),0<=m)if(e=1,1m&&!h&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(h=1),0<=m)if(e=1,1c||e?f.slice(e,c+e):f;f=a}else{if(ac||e)f=f.slice(e,c+e)}d=f}return d}; function M(a,c,b,d){return(a=N(this,a,c))&&a.length?L(a,b,d):[]}function O(a,c,b,d){let e=[];if(a){d=Math.min(a.length,d);for(let g=0,f;gb);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.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 d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; +function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; function Q(a){let c=0;if(a.constructor===Array)for(let b=0,d;bc||e?f.slice(e,c+e):f;f=a}else{if(ac||e)f=f.slice(e,c+e)}d=f}return d}; function M(a,c,b,d){return(a=N(this,a,c))&&a.length?L(a,b,d):[]}function O(a,c,b,d){let e=[];if(a){d=Math.min(a.length,d);for(let g=0,f;gb);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};I.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 d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; +function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}; function Q(a){let c=0;if(a.constructor===Array)for(let b=0,d;b { - on_done = resolve; - }); - } +export function exportIndex(callback, field, index_doc, index = 0) { let key, data; - switch (index || (index = 0)) { + switch (index) { case 0: key = "reg"; - - // fastupdate isn't supported by export - - if (this.fastupdate) { - - data = create_object(); - - for (let key of this.reg.keys()) { - - data[key] = 1; - } - } else { - - data = this.reg; - } - + data = reg_to_json(this.reg); break; case 1: key = "cfg"; - data = { - doc: 0, - opt: this.optimize ? 1 : 0 - }; - + data = {}; break; case 2: key = "map"; - data = this.map; + data = map_to_json(this.map); break; case 3: key = "ctx"; - data = this.ctx; + data = ctx_to_json(this.ctx); break; default: - if ('undefined' == typeof field && on_done) { - - on_done(); - } - return; } - async(callback, self || this, field, key, index_doc, index, data, on_done); - - return return_value; + return save.call(this, callback, field, key, index_doc, index, data); } /** @@ -114,38 +93,32 @@ export function exportIndex(callback, self, field, index_doc, index, on_done) { export function importIndex(key, data) { if (!data) { - return; } - if (is_string(data)) { - data = JSON.parse(data); } switch (key) { case "cfg": - - this.optimize = !!data.opt; break; case "reg": - // fastupdate isn't supported by import - + // fast update isn't supported by export/import this.fastupdate = /* suggest */ /* append: */ /* enrich */!1; - this.reg = data; + this.reg = new Set(data); break; case "map": - this.map = data; + this.map = new Map(data); break; case "ctx": - this.ctx = data; + this.ctx = new Map(data); break; } } @@ -154,71 +127,63 @@ export function importIndex(key, data) { * @this Document */ -export function exportDocument(callback, self, field, index_doc, index, on_done) { - - let return_value; - if ('undefined' == typeof on_done) { - return_value = new Promise(resolve => { - on_done = resolve; - }); - } - - index || (index = 0); - index_doc || (index_doc = 0); +export function exportDocument(callback, field, index_doc = 0, index = 0) { if (index_doc < this.field.length) { const field = this.field[index_doc], - idx = this.index[field]; + idx = this.index.get(field), + res = idx.export(callback, field, index_doc, index = 1); + // start from index 1, because document indexes does not additionally store register - - self = this; - - //setTimeout(function(){ - - if (!idx.export(callback, self, index ? field /*.replace(":", "-")*/ : "", index_doc, index++, on_done)) { - - index_doc++; - index = 1; - - self.export(callback, self, field, index_doc, index, on_done); + if (res && res.then) { + const self = this; + return res.then(function () { + return self.export(callback, field, index_doc + 1, index = 0); + }); } - //}); + + return this.export(callback, field, index_doc + 1, index = 0); } else { let key, data; switch (index) { + case 0: + + key = "reg"; + data = reg_to_json(this.reg); + field = null; + break; + case 1: key = "tag"; - data = this.tagindex; + data = ctx_to_json(this.tag); field = null; break; case 2: - key = "store"; - data = this.store; + key = "doc"; + data = map_to_json(this.store); field = null; break; - // case 3: - // - // key = "reg"; - // data = this.register; - // break; + case 3: + + key = "cfg"; + data = {}; + field = null; + break; default: - on_done(); return; } - async(callback, this, field, key, index_doc, index, data, on_done); + return save.call(this, callback, field, key, index_doc, index, data); } - - return return_value; } /** @@ -228,12 +193,9 @@ export function exportDocument(callback, self, field, index_doc, index, on_done) export function importDocument(key, data) { if (!data) { - return; } - if (is_string(data)) { - data = JSON.parse(data); } @@ -241,28 +203,26 @@ export function importDocument(key, data) { case "tag": - this.tagindex = data; + this.tagindex = new Map(data); break; case "reg": - // fastupdate isn't supported by import - + // fast update isn't supported by export/import this.fastupdate = !1; - this.reg = data; + this.reg = new Set(data); - for (let i = 0, index; i < this.field.length; i++) { - - index = this.index[this.field[i]]; - index.reg = data; - index.fastupdate = !1; + for (let i = 0, idx; i < this.field.length; i++) { + idx = this.index.get(this.field[i]); + idx.fastupdate = !1; + idx.reg = this.reg; } break; - case "store": + case "doc": - this.store = data; + this.store = new Map(data); break; default: @@ -272,8 +232,7 @@ export function importDocument(key, data) { key = key[1]; if (field && key) { - - this.index[field].import(key, data); + this.index.get(field).import(key, data); } } } @@ -290,7 +249,8 @@ ctx: "gulliver+travel:1,2,3|4,5,6|7,8,9;" * @return {string} */ -export function serialize(withFunctionWrapper = !0) { +export function serialize(withFunctionWrapper = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice: +!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/) { if (!this.reg.size) return ""; diff --git a/dist/module-debug/worker.js b/dist/module-debug/worker.js index 601abc1..2a23bd3 100644 --- a/dist/module-debug/worker.js +++ b/dist/module-debug/worker.js @@ -11,7 +11,7 @@ let pid = 0; export default function WorkerIndex(options = {}) { - if (!this) { + if (this.constructor !== WorkerIndex) { return new WorkerIndex(options); } diff --git a/dist/module-min/document.js b/dist/module-min/document.js index da5d100..227a2f6 100644 --- a/dist/module-min/document.js +++ b/dist/module-min/document.js @@ -1 +1 @@ -import{DocumentOptions,DocumentDescriptor,DocumentIndexOptions,StoreOptions}from"./type.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Cache,{searchCache}from"./cache.js";import{is_string,is_object,parse_simple}from"./common.js";import apply_async from"./async.js";import{exportDocument,importDocument}from"./serialize.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import"./document/add.js";import"./document/search.js";export default function Document(a){if(!this)return new Document(a);const b=a.document||a.doc||a;let c,d;if(this.tree=[],this.field=[],this.marker=[],this.key=(c=b.key||b.id)&&parse_tree(c,this.marker)||"id",d=a.keystore||0,d&&(this.keystore=d),this.fastupdate=!!a.fastupdate,this.reg=this.fastupdate?d&&!0?new KeystoreMap(d):new Map:d&&!0?new KeystoreSet(d):new Set,this.storetree=(c=b.store||null)&&!0!==c&&[],this.store=c&&(d&&!0?new KeystoreMap(d):new Map),this.cache=(c=a.cache||null)&&new Cache(c),a.cache=!1,this.worker=a.worker,this.index=parse_descriptor.call(this,a,b),(this.tag=null,(c=b.tag)&&("string"==typeof c&&(c=[c]),c.length))){this.tag=new Map,this.tagtree=[],this.tagfield=[];for(let a,b,d=0;da.length?this.addMapper(a,b):(this.matcher||(this.matcher=new Map),this.matcher.set(a,b),this.matcher_str+=(this.matcher_str?"|":"")+a,this.matcher_test=null,this.cache&&this.invalidate(),this)},Encoder.prototype.addStemmer=function(a,b){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(a,b),this.stemmer_str+=(this.stemmer_str?"|":"")+a,this.stemmer_test=null,this.cache&&this.invalidate(),this},Encoder.prototype.addFilter=function(a){return this.filter||(this.filter=new Set),this.filter.add(a),this.cache&&this.invalidate(),this},Encoder.prototype.addMapper=function(a,b){return"object"==typeof a?this.addReplacer(a,b):1this.stemmer.get(a)),a=1),e&&a&&(e.lengththis.matcher.get(a))),e&&this.replacer)for(let a=0;e&&athis.cache_size&&(this.cache_term.clear(),this.cache_term_length=0|this.cache_term_length/1.1)),e&&c.push(e)}return this.finalize&&(c=this.finalize(c)||c),this.cache&&a.length<=this.cache_enc_length&&(this.cache_enc.set(a,c),this.cache_enc.size>this.cache_size&&(this.cache_enc.clear(),this.cache_enc_length=0|this.cache_enc_length/1.1)),c};function clear(a){a.timer=null,a.cache_enc.clear(),a.cache_term.clear()} \ No newline at end of file +import{parse_option}from"./common.js";import normalize_polyfill from"./charset/normalize.js";import{EncoderOptions}from"./type.js";const whitespace=/[^\p{L}\p{N}]+/u,numeric_split_length=/(\d{3})/g,numeric_split_prev_char=/(\D)(\d{3})/g,numeric_split_next_char=/(\d{3})(\D)/g,normalize=/[\u0300-\u036f]/g;export default function Encoder(){if(this.constructor!==Encoder)return new Encoder(...arguments);for(let a=0;aa.length?this.addMapper(a,b):(this.matcher||(this.matcher=new Map),this.matcher.set(a,b),this.matcher_str+=(this.matcher_str?"|":"")+a,this.matcher_test=null,this.cache&&this.invalidate(),this)},Encoder.prototype.addStemmer=function(a,b){return this.stemmer||(this.stemmer=new Map),this.stemmer.set(a,b),this.stemmer_str+=(this.stemmer_str?"|":"")+a,this.stemmer_test=null,this.cache&&this.invalidate(),this},Encoder.prototype.addFilter=function(a){return this.filter||(this.filter=new Set),this.filter.add(a),this.cache&&this.invalidate(),this},Encoder.prototype.addMapper=function(a,b){return"object"==typeof a?this.addReplacer(a,b):1this.stemmer.get(a)),a=1),e&&a&&(e.lengththis.matcher.get(a))),e&&this.replacer)for(let a=0;e&&athis.cache_size&&(this.cache_term.clear(),this.cache_term_length=0|this.cache_term_length/1.1)),e&&c.push(e)}return this.finalize&&(c=this.finalize(c)||c),this.cache&&a.length<=this.cache_enc_length&&(this.cache_enc.set(a,c),this.cache_enc.size>this.cache_size&&(this.cache_enc.clear(),this.cache_enc_length=0|this.cache_enc_length/1.1)),c};function clear(a){a.timer=null,a.cache_enc.clear(),a.cache_term.clear()} \ No newline at end of file diff --git a/dist/module-min/index.js b/dist/module-min/index.js index 9266d3e..06cc57c 100644 --- a/dist/module-min/index.js +++ b/dist/module-min/index.js @@ -1 +1 @@ -import{IndexOptions,ContextOptions}from"./type.js";import Encoder from"./encoder.js";import Cache,{searchCache}from"./cache.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import{is_array,is_string}from"./common.js";import{exportIndex,importIndex,serialize}from"./serialize.js";import default_encoder from"./charset/latin/default.js";import apply_preset from"./preset.js";import apply_async from"./async.js";import tick from"./profiler.js";import"./index/add.js";import"./index/search.js";import"./index/remove.js";export default function Index(a,b){if(!this)return new Index(a);!1,a=a?apply_preset(a):{};const c=a.context||{},d=is_string(a.encoder)?Charset[a.encoder]:a.encode||a.encoder||default_encoder;this.encoder=d.encode?d:"object"==typeof d?new Encoder(d):{encode:d},this.compress=a.compress||a.compression||!1;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=a.keystore||0,e&&(this.keystore=e),this.map=e&&!0?new KeystoreMap(e):new Map,this.ctx=e&&!0?new KeystoreMap(e):new Map,this.reg=b||(this.fastupdate?e&&!0?new KeystoreMap(e):new Map:e&&!0?new KeystoreSet(e):new Set),this.resolution_ctx=c.resolution||1,this.rtl=d.rtl||a.rtl||!1,this.cache=(e=a.cache||null)&&new Cache(e),this.resolve=!1!==a.resolve,(e=a.db)&&(this.db=this.mount(e)),this.commit_auto=!1!==a.commit,this.commit_task=[],this.commit_timer=null}Index.prototype.mount=function(a){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),a.mount(this)},Index.prototype.commit=function(a,b){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.commit(this,a,b)},Index.prototype.destroy=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.destroy()};export function autoCommit(a,b,c){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null,a.db.commit(a,b,c)},0))}Index.prototype.clear=function(){return this.map.clear(),this.ctx.clear(),this.reg.clear(),this.cache&&this.cache.clear(),this.db&&(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[{clear:!0}]),this},Index.prototype.append=function(a,b){return this.add(a,b,!0)},Index.prototype.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)},Index.prototype.update=function(a,b){const c=this,d=this.remove(a);return d&&d.then?d.then(()=>c.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;dc.add(a,b)):this.add(a,b)};function cleanup_index(a){let b=0;if(is_array(a))for(let c,d=0;d{f=a}));let h,i;switch(e||(e=0)){case 0:if(h="reg",this.fastupdate){i=create_object();for(let a of this.reg.keys())i[a]=1}else i=this.reg;break;case 1:h="cfg",i={doc:0,opt:this.optimize?1:0};break;case 2:h="map",i=this.map;break;case 3:h="ctx",i=this.ctx;break;default:return void("undefined"==typeof c&&f&&f());}return async(a,b||this,c,h,d,e,i,f),g}export function importIndex(a,b){b&&(is_string(b)&&(b=JSON.parse(b)),"cfg"===a?this.optimize=!!b.opt:"reg"===a?(this.fastupdate=!1,this.reg=b):"map"===a?this.map=b:"ctx"===a?this.ctx=b:void 0)}export function exportDocument(a,b,c,d,e,f){let g;if("undefined"==typeof f&&(g=new Promise(a=>{f=a})),e||(e=0),d||(d=0),d { - on_done = resolve; - }); - } +export function exportIndex(callback, field, index_doc, index = 0) { let key, data; - switch (index || (index = 0)) { + switch (index) { case 0: key = "reg"; - - // fastupdate isn't supported by export - - if (this.fastupdate) { - - data = create_object(); - - for (let key of this.reg.keys()) { - - data[key] = 1; - } - } else { - - data = this.reg; - } - + data = reg_to_json(this.reg); break; case 1: key = "cfg"; - data = { - doc: 0, - opt: this.optimize ? 1 : 0 - }; - + data = {}; break; case 2: key = "map"; - data = this.map; + data = map_to_json(this.map); break; case 3: key = "ctx"; - data = this.ctx; + data = ctx_to_json(this.ctx); break; default: - if ('undefined' == typeof field && on_done) { - - on_done(); - } - return; } - async(callback, self || this, field, key, index_doc, index, data, on_done); - - return return_value; + return save.call(this, callback, field, key, index_doc, index, data); } /** @@ -114,38 +93,32 @@ export function exportIndex(callback, self, field, index_doc, index, on_done) { export function importIndex(key, data) { if (!data) { - return; } - if (is_string(data)) { - data = JSON.parse(data); } switch (key) { case "cfg": - - this.optimize = !!data.opt; break; case "reg": - // fastupdate isn't supported by import - + // fast update isn't supported by export/import this.fastupdate = /* suggest */ /* append: */ /* enrich */!1; - this.reg = data; + this.reg = new Set(data); break; case "map": - this.map = data; + this.map = new Map(data); break; case "ctx": - this.ctx = data; + this.ctx = new Map(data); break; } } @@ -154,71 +127,63 @@ export function importIndex(key, data) { * @this Document */ -export function exportDocument(callback, self, field, index_doc, index, on_done) { - - let return_value; - if ('undefined' == typeof on_done) { - return_value = new Promise(resolve => { - on_done = resolve; - }); - } - - index || (index = 0); - index_doc || (index_doc = 0); +export function exportDocument(callback, field, index_doc = 0, index = 0) { if (index_doc < this.field.length) { const field = this.field[index_doc], - idx = this.index[field]; + idx = this.index.get(field), + res = idx.export(callback, field, index_doc, index = 1); + // start from index 1, because document indexes does not additionally store register - - self = this; - - //setTimeout(function(){ - - if (!idx.export(callback, self, index ? field /*.replace(":", "-")*/ : "", index_doc, index++, on_done)) { - - index_doc++; - index = 1; - - self.export(callback, self, field, index_doc, index, on_done); + if (res && res.then) { + const self = this; + return res.then(function () { + return self.export(callback, field, index_doc + 1, index = 0); + }); } - //}); + + return this.export(callback, field, index_doc + 1, index = 0); } else { let key, data; switch (index) { + case 0: + + key = "reg"; + data = reg_to_json(this.reg); + field = null; + break; + case 1: key = "tag"; - data = this.tagindex; + data = ctx_to_json(this.tag); field = null; break; case 2: - key = "store"; - data = this.store; + key = "doc"; + data = map_to_json(this.store); field = null; break; - // case 3: - // - // key = "reg"; - // data = this.register; - // break; + case 3: + + key = "cfg"; + data = {}; + field = null; + break; default: - on_done(); return; } - async(callback, this, field, key, index_doc, index, data, on_done); + return save.call(this, callback, field, key, index_doc, index, data); } - - return return_value; } /** @@ -228,12 +193,9 @@ export function exportDocument(callback, self, field, index_doc, index, on_done) export function importDocument(key, data) { if (!data) { - return; } - if (is_string(data)) { - data = JSON.parse(data); } @@ -241,28 +203,26 @@ export function importDocument(key, data) { case "tag": - this.tagindex = data; + this.tagindex = new Map(data); break; case "reg": - // fastupdate isn't supported by import - + // fast update isn't supported by export/import this.fastupdate = !1; - this.reg = data; + this.reg = new Set(data); - for (let i = 0, index; i < this.field.length; i++) { - - index = this.index[this.field[i]]; - index.reg = data; - index.fastupdate = !1; + for (let i = 0, idx; i < this.field.length; i++) { + idx = this.index.get(this.field[i]); + idx.fastupdate = !1; + idx.reg = this.reg; } break; - case "store": + case "doc": - this.store = data; + this.store = new Map(data); break; default: @@ -272,8 +232,7 @@ export function importDocument(key, data) { key = key[1]; if (field && key) { - - this.index[field].import(key, data); + this.index.get(field).import(key, data); } } } @@ -290,7 +249,8 @@ ctx: "gulliver+travel:1,2,3|4,5,6|7,8,9;" * @return {string} */ -export function serialize(withFunctionWrapper = !0) { +export function serialize(withFunctionWrapper = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */ /* skip deletion */ // splice: +!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/) { if (!this.reg.size) return ""; diff --git a/dist/module/worker.js b/dist/module/worker.js index 601abc1..2a23bd3 100644 --- a/dist/module/worker.js +++ b/dist/module/worker.js @@ -11,7 +11,7 @@ let pid = 0; export default function WorkerIndex(options = {}) { - if (!this) { + if (this.constructor !== WorkerIndex) { return new WorkerIndex(options); } diff --git a/example/nodejs-commonjs/basic-persistent/package.json b/example/nodejs-commonjs/basic-persistent/package.json index 8c1358c..19b2f61 100644 --- a/example/nodejs-commonjs/basic-persistent/package.json +++ b/example/nodejs-commonjs/basic-persistent/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-commonjs-basic-persistent", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview", "sqlite3": "^5.1.7" diff --git a/example/nodejs-commonjs/basic-resolver/package.json b/example/nodejs-commonjs/basic-resolver/package.json index 2fbc471..c947a79 100644 --- a/example/nodejs-commonjs/basic-resolver/package.json +++ b/example/nodejs-commonjs/basic-resolver/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-commonjs-basic-resolver", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" } diff --git a/example/nodejs-commonjs/basic-suggestion/package.json b/example/nodejs-commonjs/basic-suggestion/package.json index 2fbc471..4863964 100644 --- a/example/nodejs-commonjs/basic-suggestion/package.json +++ b/example/nodejs-commonjs/basic-suggestion/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-commonjs-basic-suggestion", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" } diff --git a/example/nodejs-commonjs/basic-worker-extern-config/package.json b/example/nodejs-commonjs/basic-worker-extern-config/package.json index b98f398..d7c1a89 100644 --- a/example/nodejs-commonjs/basic-worker-extern-config/package.json +++ b/example/nodejs-commonjs/basic-worker-extern-config/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-esm-document-worker", + "name": "nodejs-esm-basic-worker-extern-config", "type": "module", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" diff --git a/example/nodejs-commonjs/basic-worker/package.json b/example/nodejs-commonjs/basic-worker/package.json index b98f398..6cf6e7a 100644 --- a/example/nodejs-commonjs/basic-worker/package.json +++ b/example/nodejs-commonjs/basic-worker/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-esm-document-worker", + "name": "nodejs-esm-basic-worker", "type": "module", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" diff --git a/example/nodejs-commonjs/basic/package.json b/example/nodejs-commonjs/basic/package.json index 2fbc471..63d6f1c 100644 --- a/example/nodejs-commonjs/basic/package.json +++ b/example/nodejs-commonjs/basic/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-commonjs-basic", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" } diff --git a/example/nodejs-commonjs/language-pack/package.json b/example/nodejs-commonjs/language-pack/package.json index 2fbc471..1143c66 100644 --- a/example/nodejs-commonjs/language-pack/package.json +++ b/example/nodejs-commonjs/language-pack/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-commonjs-language-pack", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" } diff --git a/example/nodejs-esm/basic-persistent/package.json b/example/nodejs-esm/basic-persistent/package.json index 2232aed..0f3dc72 100644 --- a/example/nodejs-esm/basic-persistent/package.json +++ b/example/nodejs-esm/basic-persistent/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-esm-basic-persistent", "type": "module", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview", diff --git a/example/nodejs-esm/basic-resolver/package.json b/example/nodejs-esm/basic-resolver/package.json index 9800214..23972d1 100644 --- a/example/nodejs-esm/basic-resolver/package.json +++ b/example/nodejs-esm/basic-resolver/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-esm-basic-resolver", "type": "module", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" diff --git a/example/nodejs-esm/basic-suggestion/package.json b/example/nodejs-esm/basic-suggestion/package.json index 9800214..9daf7f5 100644 --- a/example/nodejs-esm/basic-suggestion/package.json +++ b/example/nodejs-esm/basic-suggestion/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-esm-basic-suggestion", "type": "module", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" diff --git a/example/nodejs-esm/basic-worker-extern-config/package.json b/example/nodejs-esm/basic-worker-extern-config/package.json index b98f398..d7c1a89 100644 --- a/example/nodejs-esm/basic-worker-extern-config/package.json +++ b/example/nodejs-esm/basic-worker-extern-config/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-esm-document-worker", + "name": "nodejs-esm-basic-worker-extern-config", "type": "module", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" diff --git a/example/nodejs-esm/basic-worker/package.json b/example/nodejs-esm/basic-worker/package.json index b98f398..6cf6e7a 100644 --- a/example/nodejs-esm/basic-worker/package.json +++ b/example/nodejs-esm/basic-worker/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-esm-document-worker", + "name": "nodejs-esm-basic-worker", "type": "module", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" diff --git a/example/nodejs-esm/basic/package.json b/example/nodejs-esm/basic/package.json index 9800214..7ef8fc4 100644 --- a/example/nodejs-esm/basic/package.json +++ b/example/nodejs-esm/basic/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-esm-basic", "type": "module", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" diff --git a/example/nodejs-esm/language-pack/package.json b/example/nodejs-esm/language-pack/package.json index 2fbc471..8e49be9 100644 --- a/example/nodejs-esm/language-pack/package.json +++ b/example/nodejs-esm/language-pack/package.json @@ -1,5 +1,5 @@ { - "name": "nodejs-commonjs-document", + "name": "nodejs-esm-language-pack", "dependencies": { "flexsearch": "github:nextapps-de/flexsearch#v0.8-preview" } diff --git a/package.json b/package.json index 9b5c8ff..53a3bf5 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "preferGlobal": false, "name": "flexsearch", "version": "0.8.0", - "description": "Next-Generation full text search library with zero dependencies for Browser and Node.js", + "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", "copyright": "Nextapps GmbH", diff --git a/src/document.js b/src/document.js index ff815d0..ed6cfdb 100644 --- a/src/document.js +++ b/src/document.js @@ -38,7 +38,7 @@ import "./document/search.js"; export default function Document(options){ - if(!this) { + if(this.constructor !== Document) { return new Document(options); } diff --git a/src/encoder.js b/src/encoder.js index aa92c43..b316d47 100644 --- a/src/encoder.js +++ b/src/encoder.js @@ -63,7 +63,7 @@ const normalize = "".normalize && /[\u0300-\u036f]/g; // '´`’ʼ., export default function Encoder(options){ - if(!this){ + if(this.constructor !== Encoder){ return new Encoder(...arguments); } diff --git a/src/index.js b/src/index.js index 497a110..44739d5 100644 --- a/src/index.js +++ b/src/index.js @@ -47,7 +47,7 @@ import "./index/remove.js"; export default function Index(options, _register){ - if(!this){ + if(this.constructor !== Index){ return new Index(options); } diff --git a/src/resolver.js b/src/resolver.js index 83f6a17..2078d6f 100644 --- a/src/resolver.js +++ b/src/resolver.js @@ -12,7 +12,7 @@ import "./resolve/not.js"; */ export default function Resolver(result){ - if(!this){ + if(this.constructor !== Resolver){ return new Resolver(result); } if(result && result.index){ diff --git a/src/serialize.js b/src/serialize.js index 5b74fb8..d1780ec 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -1,111 +1,89 @@ -// TODO return promises instead of inner await - import Index from "./index.js"; import Document from "./document.js"; import { create_object, is_string } from "./common.js"; -function async(callback, self, field, key, index_doc, index, data, on_done){ +function map_to_json(map){ + const json = []; + for(const item of map.entries()){ + json.push(item); + } + return json; +} - //setTimeout(function(){ +function ctx_to_json(ctx){ + const json = []; + for(const item of ctx.entries()){ + json.push(map_to_json(item)); + } + return json; +} - const res = callback(field ? field + "." + key : key, JSON.stringify(data)); +function reg_to_json(reg){ + const json = []; + for(const key of reg.keys()){ + json.push(key); + } + return json; +} - // await isn't supported by ES5 +function save(callback, field, key, index_doc, index, data){ - if(res && res["then"]){ + const res = callback(field ? field + "." + key : key, JSON.stringify(data)); - res["then"](function(){ + if(res && res["then"]){ + const self = this; + return res["then"](function(){ + return self.export(callback, field, index_doc, index + 1); + }); + } - self.export(callback, self, field, index_doc, index + 1, on_done); - }) - } - else{ - - self.export(callback, self, field, index_doc, index + 1, on_done); - } - //}); + return this.export(callback, field, index_doc, index + 1); } /** * @param callback - * @param self * @param field * @param index_doc * @param index - * @param on_done * @this {Index|Document} */ -export function exportIndex(callback, self, field, index_doc, index, on_done){ - - let return_value = true - if (typeof on_done === 'undefined') { - return_value = new Promise((resolve) => { - on_done = resolve - }) - } +export function exportIndex(callback, field, index_doc, index = 0){ let key, data; - switch(index || (index = 0)){ + switch(index){ case 0: key = "reg"; - - // fastupdate isn't supported by export - - if(this.fastupdate){ - - data = create_object(); - - for(let key of this.reg.keys()){ - - data[key] = 1; - } - } - else{ - - data = this.reg; - } - + data = reg_to_json(this.reg); break; case 1: key = "cfg"; - data = { - "doc": 0, - "opt": this.optimize ? 1 : 0 - }; - + data = {}; break; case 2: key = "map"; - data = this.map; + data = map_to_json(this.map); break; case 3: key = "ctx"; - data = this.ctx; + data = ctx_to_json(this.ctx); break; default: - if (typeof field === 'undefined' && on_done) { - - on_done(); - } - return; } - async(callback, self || this, field, key, index_doc, index, data, on_done); - - return return_value; + return save.call(this, callback, field, key, index_doc, index, data); } /** @@ -115,38 +93,32 @@ export function exportIndex(callback, self, field, index_doc, index, on_done){ export function importIndex(key, data){ if(!data){ - return; } - if(is_string(data)){ - data = JSON.parse(data); } switch(key){ case "cfg": - - this.optimize = !!data["opt"]; break; case "reg": - // fastupdate isn't supported by import - + // fast update isn't supported by export/import this.fastupdate = false; - this.reg = data; + this.reg = new Set(data); break; case "map": - this.map = data; + this.map = new Map(data); break; case "ctx": - this.ctx = data; + this.ctx = new Map(data); break; } } @@ -155,35 +127,23 @@ export function importIndex(key, data){ * @this Document */ -export function exportDocument(callback, self, field, index_doc, index, on_done){ - - let return_value - if (typeof on_done === 'undefined') { - return_value = new Promise((resolve) => { - on_done = resolve - }) - } - - index || (index = 0); - index_doc || (index_doc = 0); +export function exportDocument(callback, field, index_doc = 0, index = 0){ if(index_doc < this.field.length){ const field = this.field[index_doc]; - const idx = this.index[field]; + const idx = this.index.get(field); + // start from index 1, because document indexes does not additionally store register + const res = idx.export(callback, field, index_doc, index = 1); - self = this; + if(res && res["then"]){ + const self = this; + return res["then"](function(){ + return self.export(callback, field, index_doc + 1, index = 0); + }); + } - //setTimeout(function(){ - - if(!idx.export(callback, self, index ? field/*.replace(":", "-")*/ : "", index_doc, index++, on_done)){ - - index_doc++; - index = 1; - - self.export(callback, self, field, index_doc, index, on_done); - } - //}); + return this.export(callback, field, index_doc + 1, index = 0); } else{ @@ -191,36 +151,41 @@ export function exportDocument(callback, self, field, index_doc, index, on_done) switch(index){ + case 0: + + key = "reg"; + data = reg_to_json(this.reg); + field = null; + break; + case 1: key = "tag"; - data = this.tagindex; + data = ctx_to_json(this.tag); field = null; break; case 2: - key = "store"; - data = this.store; + key = "doc"; + data = map_to_json(this.store); field = null; break; - // case 3: - // - // key = "reg"; - // data = this.register; - // break; + case 3: + + key = "cfg"; + data = {}; + field = null; + break; default: - on_done(); return; } - async(callback, this, field, key, index_doc, index, data, on_done); + return save.call(this, callback, field, key, index_doc, index, data); } - - return return_value } /** @@ -230,12 +195,9 @@ export function exportDocument(callback, self, field, index_doc, index, on_done) export function importDocument(key, data){ if(!data){ - return; } - if(is_string(data)){ - data = JSON.parse(data); } @@ -243,28 +205,26 @@ export function importDocument(key, data){ case "tag": - this.tagindex = data; + this.tagindex = new Map(data); break; case "reg": - // fastupdate isn't supported by import - + // fast update isn't supported by export/import this.fastupdate = false; - this.reg = data; + this.reg = new Set(data); - for(let i = 0, index; i < this.field.length; i++){ - - index = this.index[this.field[i]]; - index.reg = data; - index.fastupdate = false; + for(let i = 0, idx; i < this.field.length; i++){ + idx = this.index.get(this.field[i]); + idx.fastupdate = false; + idx.reg = this.reg; } break; - case "store": + case "doc": - this.store = data; + this.store = new Map(data); break; default: @@ -274,8 +234,7 @@ export function importDocument(key, data){ key = key[1]; if(field && key){ - - this.index[field].import(key, data); + this.index.get(field).import(key, data); } } } diff --git a/src/worker.js b/src/worker.js index 314a14d..e69c36d 100644 --- a/src/worker.js +++ b/src/worker.js @@ -11,7 +11,7 @@ let pid = 0; export default function WorkerIndex(options = {}){ - if(!this) { + if(this.constructor !== WorkerIndex) { return new WorkerIndex(options); }