From adde2a98617a7463360d0c63525637d0d936cc2e Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Fri, 21 Mar 2025 13:03:02 +0100 Subject: [PATCH] fix default resolver state, fix indexeddb transaction recycling --- dist/db/indexeddb/index.js | 8 +- dist/flexsearch.bundle.debug.js | 410 ++++++++++++------------ dist/flexsearch.bundle.min.js | 66 ++-- dist/flexsearch.bundle.module.debug.js | 410 ++++++++++++------------ dist/flexsearch.bundle.module.min.js | 66 ++-- dist/flexsearch.compact.debug.js | 4 +- dist/flexsearch.compact.min.js | 4 +- dist/flexsearch.compact.module.debug.js | 4 +- dist/flexsearch.compact.module.min.js | 4 +- dist/flexsearch.es5.debug.js | 151 ++++----- dist/flexsearch.es5.min.js | 16 +- dist/flexsearch.light.debug.js | 2 +- dist/flexsearch.light.min.js | 2 +- dist/flexsearch.light.module.debug.js | 2 +- dist/flexsearch.light.module.min.js | 2 +- dist/module-debug/db/indexeddb/index.js | 7 +- dist/module-debug/document/search.js | 4 +- dist/module-debug/index/search.js | 3 +- dist/module-min/db/indexeddb/index.js | 2 +- dist/module-min/document/search.js | 2 +- dist/module/db/indexeddb/index.js | 7 +- dist/module/document/search.js | 4 +- dist/module/index/search.js | 3 +- package-lock.json | 4 +- package.json | 2 +- src/db/indexeddb/index.js | 8 +- src/document/search.js | 2 +- 27 files changed, 606 insertions(+), 593 deletions(-) diff --git a/dist/db/indexeddb/index.js b/dist/db/indexeddb/index.js index 03d122e..c662431 100644 --- a/dist/db/indexeddb/index.js +++ b/dist/db/indexeddb/index.js @@ -315,19 +315,21 @@ IdxDB.prototype.transaction = function(ref, modifier, task){ return new Promise((resolve, reject) => { transaction.onerror = (err) => { - this.trx[ref+ ":" + modifier] = null; transaction.abort(); transaction = store = null; reject(err); //db.close; }; transaction.oncomplete = (res) => { - this.trx[ref+ ":" + modifier] = null; transaction = store = null; resolve(res || true); //db.close; }; - return task.call(this, store); + const promise = task.call(this, store); + // transactions can just be used within the same event loop + // the indexeddb is just a stupid thing + this.trx[ref+ ":" + modifier] = null; + return promise; }); }; diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 67af393..d27dbc5 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.113 (Bundle/Debug) + * FlexSearch.js v0.8.115 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -243,8 +243,8 @@ t.encode = function(a) { this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let h = 0, l = "", m, n; h < g.length; h++) { - m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let h = 0, l = "", n, m; h < g.length; h++) { + n = g.charAt(h), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (d += m) : d += l = n); } g = d; } @@ -342,8 +342,8 @@ function Q(a = {}) { function b(g) { function k(h) { h = h.data || h; - const l = h.id, m = l && d.h[l]; - m && (m(h.msg), delete d.h[l]); + const l = h.id, n = l && d.h[l]; + n && (n(h.msg), delete d.h[l]); } this.worker = g; this.h = B(); @@ -684,19 +684,19 @@ function Ba(a) { } if (d && f) { E(f) && (f = [f]); - for (let h = 0, l, m; h < f.length; h++) { - if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !c || !m.includes(a))) { - if (m.length === 2 ** 31 - 1) { - g = new S(m); + for (let h = 0, l, n; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? n = g : d.set(l, n = []), !c || !n.includes(a))) { + if (n.length === 2 ** 31 - 1) { + g = new S(n); if (this.fastupdate) { - for (let n of this.reg.values()) { - n.includes(m) && (n[n.indexOf(m)] = g); + for (let m of this.reg.values()) { + m.includes(n) && (m[m.indexOf(n)] = g); } } - d.set(l, m = g); + d.set(l, n = g); } - m.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); + n.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])); } } } else { @@ -713,10 +713,10 @@ function Ba(a) { if ((c = l.I) && !c(b)) { continue; } - let m; + let n; if ("function" === typeof l) { - m = l(b); - if (!m) { + n = l(b); + if (!n) { continue; } l = [l.V]; @@ -724,7 +724,7 @@ function Ba(a) { k[l] = b[l]; continue; } - Ea(b, k, l, 0, l[0], m); + Ea(b, k, l, 0, l[0], n); } } this.store.set(a, k || b); @@ -776,13 +776,13 @@ function Da(a, b, c, e, d, f, g, k) { ;function Fa(a, b, c, e, d, f, g) { const k = a.length; let h = [], l; - var m; + var n; l = B(); - for (let n = 0, p, q, r, u; n < b; n++) { + for (let m = 0, q, p, r, u; m < b; m++) { for (let v = 0; v < k; v++) { - if (r = a[v], n < r.length && (p = r[n])) { - for (let x = 0; x < p.length; x++) { - q = p[x], (m = l[q]) ? l[q]++ : (m = 0, l[q] = 1), u = h[m] || (h[m] = []), g || (m = n + (v || !d ? 0 : f || 0), u = u[m] || (u[m] = [])), u.push(q); + if (r = a[v], m < r.length && (q = r[m])) { + for (let x = 0; x < q.length; x++) { + p = q[x], (n = l[p]) ? l[p]++ : (n = 0, l[p] = 1), u = h[n] || (h[n] = []), g || (n = m + (v || !d ? 0 : f || 0), u = u[n] || (u[n] = [])), u.push(p); } } } @@ -802,14 +802,14 @@ function Da(a, b, c, e, d, f, g, k) { } } else { d = []; - for (let n = 0, p; n < h.length; n++) { - if (p = h[n], p.length > e) { - e -= p.length; + for (let m = 0, q; m < h.length; m++) { + if (q = h[m], q.length > e) { + e -= q.length; } else { - if (p.length > c || e) { - p = p.slice(e, c + e), c -= p.length, e && (e -= p.length); + if (q.length > c || e) { + q = q.slice(e, c + e), c -= q.length, e && (e -= q.length); } - d.push(p); + d.push(q); if (!c) { break; } @@ -844,18 +844,18 @@ function Ga(a, b, c, e, d) { } } } else { - for (let m = h - 1, n, p = 0; 0 <= m; m--) { - n = a[m]; - for (let q = 0; q < n.length; q++) { - if (l = (e = n[q]) && e.length) { + for (let n = h - 1, m, q = 0; 0 <= n; n--) { + m = a[n]; + for (let p = 0; p < m.length; p++) { + if (l = (e = m[p]) && e.length) { for (let r = 0; r < l; r++) { if (k = e[r], !g[k]) { if (g[k] = 1, c) { c--; } else { - let u = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + let u = (p + (n < h - 1 ? d || 0 : 0)) / (n + 1) | 0; (f[u] || (f[u] = [])).push(k); - if (++p === b) { + if (++q === b) { return f; } } @@ -922,8 +922,8 @@ function Ha(a, b, c) { ;function Ja(a, b, c) { var e = c[0]; if (e.then) { - return Promise.all(c).then(function(m) { - return a[b].apply(a, m); + return Promise.all(c).then(function(n) { + return a[b].apply(a, n); }); } if (e[0] && e[0].index) { @@ -931,32 +931,32 @@ function Ha(a, b, c) { } e = []; let d = [], f = 0, g = 0, k, h, l; - for (let m = 0, n; m < c.length; m++) { - if (n = c[m]) { - let p; - if (n.constructor === X) { - p = n.result; - } else if (n.constructor === Array) { - p = n; + for (let n = 0, m; n < c.length; n++) { + if (m = c[n]) { + let q; + if (m.constructor === X) { + q = m.result; + } else if (m.constructor === Array) { + q = m; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = h, n.enrich = k; - } else if (n.and) { - p = a.and(n.and); - } else if (n.or) { - p = a.or(n.or); - } else if (n.xor) { - p = a.xor(n.xor); - } else if (n.not) { - p = a.not(n.not); + if (f = m.limit || 0, g = m.offset || 0, l = m.suggest, h = m.resolve, k = m.enrich && h, m.index) { + m.resolve = !1, m.enrich = !1, q = m.index.search(m).result, m.resolve = h, m.enrich = k; + } else if (m.and) { + q = a.and(m.and); + } else if (m.or) { + q = a.or(m.or); + } else if (m.xor) { + q = a.xor(m.xor); + } else if (m.not) { + q = a.not(m.not); } else { continue; } } - if (p.then) { - d.push(p); - } else if (p.length) { - e[m] = p; + if (q.then) { + d.push(q); + } else if (q.length) { + e[n] = q; } else if (!l && ("and" === b || "xor" === b)) { e = []; break; @@ -990,8 +990,8 @@ function Ka(a, b, c, e, d, f) { f && (a = !!f.suggest, d = f.resolve, b = f.limit, c = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); - return La.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:n, suggest:m} = Ja(this, "and", arguments); + return La.call(this, f, g, k, h, l, n, m); } return d ? this.resolve(b, c, e) : this; }; @@ -1000,8 +1000,8 @@ function La(a, b, c, e, d, f, g) { const k = this; return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } return La.call(k, a, [], c, e, d, f, g); }); @@ -1029,8 +1029,8 @@ function Ma(a, b, c, e, d, f, g) { const k = this; return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } return Ma.call(k, a, [], c, e, d, f, g); }); @@ -1052,21 +1052,21 @@ function Na(a, b, c, e, d) { for (let h = 0, l; h < a.length; h++) { if (l = a[h]) { k < l.length && (k = l.length); - for (let m = 0, n; m < l.length; m++) { - if (n = l[m]) { - for (let p = 0, q; p < n.length; p++) { - q = n[p], g[q] = g[q] ? 2 : 1; + for (let n = 0, m; n < l.length; n++) { + if (m = l[n]) { + for (let q = 0, p; q < m.length; q++) { + p = m[q], g[p] = g[p] ? 2 : 1; } } } } } - for (let h = 0, l, m = 0; h < k; h++) { - for (let n = 0, p; n < a.length; n++) { - if (p = a[n]) { - if (l = p[h]) { - for (let q = 0, r; q < l.length; q++) { - if (r = l[q], 1 === g[r]) { + for (let h = 0, l, n = 0; h < k; h++) { + for (let m = 0, q; m < a.length; m++) { + if (q = a[m]) { + if (l = q[h]) { + for (let p = 0, r; p < l.length; p++) { + if (r = l[p], 1 === g[r]) { if (c) { c--; } else { @@ -1075,10 +1075,10 @@ function Na(a, b, c, e, d) { return f; } } else { - const u = h + (n ? d : 0); + const u = h + (m ? d : 0); f[u] || (f[u] = []); f[u].push(r); - if (++m === b) { + if (++n === b) { return f; } } @@ -1100,8 +1100,8 @@ function Oa(a, b, c, e, d, f, g) { const k = this; return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } return Oa.call(k, a, [], c, e, d, f, g); }); @@ -1196,8 +1196,9 @@ V.prototype.search = function(a, b, c, e) { let d = [], f = [], g; let k; let h; - let l, m = 0; - let n; + let l, n = 0; + var m = !0; + let q; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; @@ -1205,9 +1206,9 @@ V.prototype.search = function(a, b, c, e) { k = c.merge; h = g || c.field || (h = c.index) && (h.index ? null : h); var p = this.tag && c.tag; - var q = c.suggest; - var r = !1 !== c.resolve; - if (!r && !g) { + var r = c.suggest; + m = !1 !== c.resolve; + if (!m && !g) { if (h = h || this.field) { E(h) ? g = h : (h.constructor === Array && 1 === h.length && (h = h[0]), g = h.field || h.index); } @@ -1215,9 +1216,9 @@ V.prototype.search = function(a, b, c, e) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - this.store && c.enrich && !r && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var u = this.store && c.enrich && r; - n = c.highlight && u; + this.store && c.enrich && !m && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var u = this.store && c.enrich && m; + q = c.highlight && u; b = c.limit || b; l = c.offset || 0; b || (b = 100); @@ -1256,23 +1257,23 @@ V.prototype.search = function(a, b, c, e) { } p = v; if (!a) { - q = []; + r = []; if (v.length) { for (p = 0; p < v.length; p += 2) { if (this.db) { - r = this.index.get(v[p]); - if (!r) { + m = this.index.get(v[p]); + if (!m) { console.warn("Tag '" + v[p] + ":" + v[p + 1] + "' will be skipped because there is no field '" + v[p] + "'."); continue; } - q.push(r = r.db.tag(v[p + 1], b, l, u)); + r.push(m = m.db.tag(v[p + 1], b, l, u)); } else { - r = Qa.call(this, v[p], v[p + 1], b, l, u); + m = Qa.call(this, v[p], v[p + 1], b, l, u); } - d.push({field:v[p], tag:v[p + 1], result:r}); + d.push({field:v[p], tag:v[p + 1], result:m}); } } - return q.length ? Promise.all(q).then(function(z) { + return r.length ? Promise.all(r).then(function(z) { for (let w = 0; w < z.length; w++) { d[w].result = z[w]; } @@ -1291,7 +1292,7 @@ V.prototype.search = function(a, b, c, e) { continue; } let C; - E(D) || (C = D, D = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, q = C.suggest || q, u = this.store && (C.enrich || u)); + E(D) || (C = D, D = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, r = C.suggest || r, u = this.store && (C.enrich || u)); if (e) { w = e[z]; } else { @@ -1303,7 +1304,7 @@ V.prototype.search = function(a, b, c, e) { w = y.search(a, b, x), x && u && (x.enrich = u); } } - H = w && (r ? w.length : w.result.length); + H = w && (m ? w.length : w.result.length); if (p && H) { x = []; y = 0; @@ -1313,8 +1314,8 @@ V.prototype.search = function(a, b, c, e) { let K = e[G]; if (K && K.length) { y++, x.push(K); - } else if (!q) { - return r ? d : new X(d); + } else if (!r) { + return m ? d : new X(d); } } } @@ -1322,32 +1323,32 @@ V.prototype.search = function(a, b, c, e) { for (let G = 0, K, rb; G < p.length; G += 2) { K = this.tag.get(p[G]); if (!K) { - if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), q) { + if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), r) { continue; } else { - return r ? d : new X(d); + return m ? d : new X(d); } } if (rb = (K = K && K.get(p[G + 1])) && K.length) { y++, x.push(K); - } else if (!q) { - return r ? d : new X(d); + } else if (!r) { + return m ? d : new X(d); } } } if (y) { - w = Ha(w, x, r); + w = Ha(w, x, m); H = w.length; - if (!H && !q) { - return r ? w : new X(w); + if (!H && !r) { + return m ? w : new X(w); } y--; } } if (H) { - f[m] = D, d.push(w), m++; + f[n] = D, d.push(w), n++; } else if (1 === h.length) { - return r ? d : new X(d); + return m ? d : new X(d); } } if (v) { @@ -1355,10 +1356,10 @@ V.prototype.search = function(a, b, c, e) { for (u = 0; u < p.length; u += 2) { e = this.index.get(p[u]); if (!e) { - if (console.warn("Tag '" + p[u] + ":" + p[u + 1] + "' was not found because there is no field '" + p[u] + "'."), q) { + if (console.warn("Tag '" + p[u] + ":" + p[u + 1] + "' was not found because there is no field '" + p[u] + "'."), r) { continue; } else { - return r ? d : new X(d); + return m ? d : new X(d); } } v.push(e.db.tag(p[u + 1], b, l, !1)); @@ -1369,8 +1370,8 @@ V.prototype.search = function(a, b, c, e) { return w.length ? z.search(a, b, c, w) : w; }); } - if (!m) { - return r ? d : new X(d); + if (!n) { + return m ? d : new X(d); } if (g && (!u || !this.store)) { return d[0]; @@ -1380,7 +1381,7 @@ V.prototype.search = function(a, b, c, e) { w = d[z]; u && w.length && !w[0].doc && (this.db ? v.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = W.call(this, w)); if (g) { - return r ? w : new X(w); + return m ? w : new X(w); } d[z] = {field:f[z], result:w}; } @@ -1390,24 +1391,24 @@ V.prototype.search = function(a, b, c, e) { for (let D = 0; D < w.length; D++) { d[D].result = w[D]; } - return k ? Ra(d, b) : n ? Sa(d, a, z.index, z.field, z.D, n) : d; + return k ? Ra(d, b) : q ? Sa(d, a, z.index, z.field, z.D, q) : d; }); } - return k ? Ra(d, b) : n ? Sa(d, a, this.index, this.field, this.D, n) : d; + return k ? Ra(d, b) : q ? Sa(d, a, this.index, this.field, this.D, q) : d; }; function Sa(a, b, c, e, d, f) { let g, k, h; - for (let m = 0, n, p, q, r, u; m < a.length; m++) { - n = a[m].result; - p = a[m].field; - r = c.get(p); - q = r.encoder; + for (let n = 0, m, q, p, r, u; n < a.length; n++) { + m = a[n].result; + q = a[n].field; + r = c.get(q); + p = r.encoder; h = r.tokenize; - u = d[e.indexOf(p)]; - q !== g && (g = q, k = g.encode(b)); - for (let v = 0; v < n.length; v++) { + u = d[e.indexOf(q)]; + p !== g && (g = p, k = g.encode(b)); + for (let v = 0; v < m.length; v++) { let x = ""; - var l = ba(n[v].doc, u); + var l = ba(m[v].doc, u); let y = g.encode(l); l = l.split(g.split); for (let F = 0, z, w; F < y.length; F++) { @@ -1432,7 +1433,7 @@ function Sa(a, b, c, e, d, f) { } D || (x += (x ? " " : "") + l[F]); } - n[v].highlight = x; + m[v].highlight = x; } } return a; @@ -1442,9 +1443,9 @@ function Ra(a, b) { for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let k = 0, h, l, m; k < g.length; k++) { - if (l = g[k], h = l.id, m = e[h]) { - m.push(f.field); + for (let k = 0, h, l, n; k < g.length; k++) { + if (l = g[k], h = l.id, n = e[h]) { + n.push(f.field); } else { if (c.length === b) { return c; @@ -1821,20 +1822,20 @@ O.prototype.add = function(a, b, c, e) { } b = this.encoder.encode(b); if (e = b.length) { - const l = B(), m = B(), n = this.depth, p = this.resolution; - for (let q = 0; q < e; q++) { - let r = b[this.rtl ? e - 1 - q : q]; + const l = B(), n = B(), m = this.depth, q = this.resolution; + for (let p = 0; p < e; p++) { + let r = b[this.rtl ? e - 1 - p : p]; var d = r.length; - if (d && (n || !m[r])) { - var f = this.score ? this.score(b, r, q, null, 0) : fb(p, e, q), g = ""; + if (d && (m || !n[r])) { + var f = this.score ? this.score(b, r, p, null, 0) : fb(q, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var k = d; k > f; k--) { g = r.substring(f, k); - var h = this.score ? this.score(b, r, q, g, f) : fb(p, e, q, d, f); - gb(this, m, g, h, a, c); + var h = this.score ? this.score(b, r, p, g, f) : fb(q, e, p, d, f); + gb(this, n, g, h, a, c); } } break; @@ -1842,23 +1843,23 @@ O.prototype.add = function(a, b, c, e) { case "reverse": if (1 < d) { for (k = d - 1; 0 < k; k--) { - g = r[k] + g, h = this.score ? this.score(b, r, q, g, k) : fb(p, e, q, d, k), gb(this, m, g, h, a, c); + g = r[k] + g, h = this.score ? this.score(b, r, p, g, k) : fb(q, e, p, d, k), gb(this, n, g, h, a, c); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[k], gb(this, m, g, f, a, c); + g += r[k], gb(this, n, g, f, a, c); } break; } default: - if (gb(this, m, r, f, a, c), n && 1 < e && q < e - 1) { - for (d = B(), g = this.U, f = r, k = Math.min(n + 1, e - q), d[f] = 1, h = 1; h < k; h++) { - if ((r = b[this.rtl ? e - 1 - q - h : q + h]) && !d[r]) { + if (gb(this, n, r, f, a, c), m && 1 < e && p < e - 1) { + for (d = B(), g = this.U, f = r, k = Math.min(m + 1, e - p), d[f] = 1, h = 1; h < k; h++) { + if ((r = b[this.rtl ? e - 1 - p - h : p + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(b, f, q, r, h) : fb(g + (e / 2 > g ? 0 : 1), e, q, k - 1, h - 1), v = this.bidirectional && r > f; + const u = this.score ? this.score(b, f, p, r, h) : fb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; gb(this, l, v ? f : r, u, a, c, v ? r : f); } } @@ -1897,32 +1898,32 @@ function fb(a, b, c, e, d) { } ;O.prototype.search = function(a, b, c) { c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); - let e = [], d, f, g, k = 0, h, l, m, n, p; - c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, p = (h = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : h = this.resolve; - let q = this.encoder.encode(a); - d = q.length; + let e = [], d, f, g, k = 0, h, l, n, m, q; + c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, q = (h = !1 !== c.resolve) && c.enrich, n = c.boost, m = c.resolution, l = this.db && c.tag) : h = this.resolve; + let p = this.encoder.encode(a); + d = p.length; b = b || (h ? 100 : 0); if (1 === d) { - return ib.call(this, q[0], "", b, k, h, p, l); + return ib.call(this, p[0], "", b, k, h, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return ib.call(this, q[0], q[1], b, k, h, p, l); + return ib.call(this, p[0], p[1], b, k, h, q, l); } let r = B(), u = 0, v; - 1 < d && f && (v = q[0], u = 1); - n || 0 === n || (n = v ? this.U : this.resolution); + 1 < d && f && (v = p[0], u = 1); + m || 0 === m || (m = v ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, q, b, k, g, h, p, l), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, b, k, g, h, q, l), !1 !== a)) { return a; } const x = this; return async function() { for (let y, F; u < d; u++) { - if ((F = q[u]) && !r[F]) { + if ((F = p[u]) && !r[F]) { r[F] = 1; y = await jb(x, F, v, 0, 0, !1, !1); - if (y = kb(y, e, g, n)) { + if (y = kb(y, e, g, m)) { e = y; break; } @@ -1930,14 +1931,14 @@ function fb(a, b, c, e, d) { } g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return lb(e, n, b, k, g, m, h); + return lb(e, m, b, k, g, n, h); }(); } for (let x, y; u < d; u++) { - if ((y = q[u]) && !r[y]) { + if ((y = p[u]) && !r[y]) { r[y] = 1; x = jb(this, y, v, 0, 0, !1, !1); - if (x = kb(x, e, g, n)) { + if (x = kb(x, e, g, m)) { e = x; break; } @@ -1945,7 +1946,7 @@ function fb(a, b, c, e, d) { } g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return lb(e, n, b, k, g, m, h); + return lb(e, m, b, k, g, n, h); }; function lb(a, b, c, e, d, f, g) { let k = a.length, h = a; @@ -2182,11 +2183,11 @@ t.serialize = function(a = !0) { e = ""; for (var d of this.map.entries()) { var f = d[0], g = d[1], k = ""; - for (let m = 0, n; m < g.length; m++) { - n = g[m] || [""]; + for (let n = 0, m; n < g.length; n++) { + m = g[n] || [""]; var h = ""; - for (var l = 0; l < n.length; l++) { - h += (h ? "," : "") + ("string" === c ? '"' + n[l] + '"' : n[l]); + for (var l = 0; l < m.length; l++) { + h += (h ? "," : "") + ("string" === c ? '"' + m[l] + '"' : m[l]); } h = "[" + h + "]"; k += (k ? "," : "") + h; @@ -2196,18 +2197,18 @@ t.serialize = function(a = !0) { } e = "index.map=new Map([" + e + "]);"; d = ""; - for (const m of this.ctx.entries()) { - f = m[0]; - g = m[1]; - for (const n of g.entries()) { - g = n[0]; - k = n[1]; + for (const n of this.ctx.entries()) { + f = n[0]; + g = n[1]; + for (const m of g.entries()) { + g = m[0]; + k = m[1]; h = ""; - for (let p = 0, q; p < k.length; p++) { - q = k[p] || [""]; + for (let q = 0, p; q < k.length; q++) { + p = k[q] || [""]; l = ""; - for (let r = 0; r < q.length; r++) { - l += (l ? "," : "") + ("string" === c ? '"' + q[r] + '"' : q[r]); + for (let r = 0; r < p.length; r++) { + l += (l ? "," : "") + ("string" === c ? '"' + p[r] + '"' : p[r]); } l = "[" + l + "]"; h += (h ? "," : "") + l; @@ -2298,15 +2299,15 @@ t.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { if (!c && !e && 1 === k.length) { return k[0]; } - for (let l = 0, m; l < k.length; l++) { - if ((m = k[l]) && m.length) { - if (e >= m.length) { - e -= m.length; + for (let l = 0, n; l < k.length; l++) { + if ((n = k[l]) && n.length) { + if (e >= n.length) { + e -= n.length; continue; } - const n = c ? e + Math.min(m.length - e, c) : m.length; - for (let p = e; p < n; p++) { - h.push(m[p]); + const m = c ? e + Math.min(n.length - e, c) : n.length; + for (let q = e; q < m; q++) { + h.push(n[q]); } e = 0; if (h.length === c) { @@ -2361,17 +2362,18 @@ t.transaction = function(a, b, c) { let d = this.db.transaction(a, b); this.h[a + ":" + b] = e = d.objectStore(a); return new Promise((f, g) => { - d.onerror = k => { - this.h[a + ":" + b] = null; + d.onerror = h => { d.abort(); d = e = null; - g(k); + g(h); }; - d.oncomplete = k => { - d = e = this.h[a + ":" + b] = null; - f(k || !0); + d.oncomplete = h => { + d = e = null; + f(h || !0); }; - return c.call(this, e); + const k = c.call(this, e); + this.h[a + ":" + b] = null; + return k; }); }; t.commit = async function(a, b, c) { @@ -2399,14 +2401,14 @@ t.commit = async function(a, b, c) { var h; if (k && k.length) { const l = Math.max(k.length, g.length); - for (let m = 0, n, p; m < l; m++) { - if ((p = g[m]) && p.length) { - if ((n = k[m]) && n.length) { - for (h = 0; h < p.length; h++) { - n.push(p[h]); + for (let n = 0, m, q; n < l; n++) { + if ((q = g[n]) && q.length) { + if ((m = k[n]) && m.length) { + for (h = 0; h < q.length; h++) { + m.push(q[h]); } } else { - k[m] = p; + k[n] = q; } h = 1; } @@ -2423,26 +2425,26 @@ t.commit = async function(a, b, c) { for (const k of g) { const h = k[0], l = k[1]; l.length && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { - let m = this.result; - var n; - if (m && m.length) { - const p = Math.max(m.length, l.length); - for (let q = 0, r, u; q < p; q++) { - if ((u = l[q]) && u.length) { - if ((r = m[q]) && r.length) { - for (n = 0; n < u.length; n++) { - r.push(u[n]); + let n = this.result; + var m; + if (n && n.length) { + const q = Math.max(n.length, l.length); + for (let p = 0, r, u; p < q; p++) { + if ((u = l[p]) && u.length) { + if ((r = n[p]) && r.length) { + for (m = 0; m < u.length; m++) { + r.push(u[m]); } } else { - m[q] = u; + n[p] = u; } - n = 1; + m = 1; } } } else { - m = l, n = 1; + n = l, m = 1; } - n && e.put(m, f + ":" + h); + m && e.put(n, f + ":" + h); }); } } @@ -2471,10 +2473,10 @@ function sb(a, b, c) { let d, f, g = 0; for (let k = 0, h; k < e.length; k++) { if (h = c ? e : e[k]) { - for (let l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = h.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = h.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { + for (let l = 0, n, m; l < b.length; l++) { + if (m = b[l], n = h.indexOf(f ? parseInt(m, 10) : m), 0 > n && !f && "string" === typeof m && !isNaN(m) && (n = h.indexOf(parseInt(m, 10))) && (f = 1), 0 <= n) { if (d = 1, 1 < h.length) { - h.splice(m, 1); + h.splice(n, 1); } else { e[k] = []; break; diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index f0f2149..6583bf6 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.113 (Bundle) + * FlexSearch.js v0.8.115 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -20,10 +20,10 @@ A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,t t.addMatcher=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(2>a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&L(this);return this};t.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&L(this);return this}; t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d +"");if(g&&(this.mapper||this.dedupe&&1this.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ma,na;const oa={},pa={};function qa(a){ma=0;oa[a]=pa[a]} function P(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);ma||(ma=setTimeout(qa,0,a),na=Date.now());pa[a]||(pa[a]=oa[a]=1E3);if(!--oa[a]){oa[a]=pa[a]=pa[a]*this.priority*this.priority*3/(Date.now()-na)|0||1;ma=clearTimeout(ma);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let ra=0; -function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ra]=function(){h(d)};d.worker.postMessage({id:ra,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==Q)return new Q(a);let c="undefined"!==typeof self?self._factory:"undefined"!== +function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,n=l&&d.h[l];n&&(n(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ra]=function(){h(d)};d.worker.postMessage({id:ra,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==Q)return new Q(a);let c="undefined"!==typeof self?self._factory:"undefined"!== typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=sa(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}R("add");R("append");R("search");R("update");R("remove");R("clear");R("export");R("import");la(Q.prototype); function R(a){Q.prototype[a]=function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.pop());e=new Promise(function(f){"export"===a&&"function"===typeof c[0]&&(c[0]=null);b.h[++ra]=f;b.worker.postMessage({task:a,id:ra,args:c})});return d?(e.then(d),this):e}} function sa(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="+ka.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof c?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", @@ -36,25 +36,25 @@ S.prototype.push=function(){};function T(a=8){if(!this)return new T(a);this.inde function U(a=8){if(!this)return new U(a);this.index=B();this.h=[];32c||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= -p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ja(this,"and",arguments);return La.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; -function La(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; -function Ma(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function Na(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let m=0,q;me)e-= +q.length;else{if(q.length>c||e)q=q.slice(e,c+e),c-=q.length,e&&(e-=q.length);d.push(q);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:n,suggest:m}=Ja(this,"and",arguments);return La.call(this,f,g,k,h,l,n,m)}return d?this.resolve(b,c,e):this}; +function La(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; +function Ma(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Na(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; Y.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};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=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 Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const $a={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 ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):fb(p,e,q,d,f);gb(this,m,g,h,a,c)}break}case "reverse":if(1< -d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +g||"w"===g||!(g=$a[g])||g===d||(e+=g,d=g,4!==e.length));f++);a[c]=e}}},ArabicDefault:{rtl:!0,normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(ab," ")}},CjkDefault:{normalize:!1,dedupe:!0,split:"",prepare:function(a){return(""+a).replace(bb,"")}},CyrillicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(cb," ")}}};const eb={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};O.prototype.add=function(a,b,c,e){if(b&&(a||0===a)){if(!e&&!c&&this.reg.has(a))return this.update(a,b);b=this.encoder.encode(b);if(e=b.length){const l=B(),n=B(),m=this.depth,q=this.resolution;for(let p=0;pf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,p,g,f):fb(q,e,p,d,f);gb(this,n,g,h,a,c)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,p,k-1,h-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& (b||this.commit_task.push({del:a}),this.T&&hb(this));return this};function gb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new S(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function fb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.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 e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&hb(this));this.cache&&this.cache.remove(a);return this}; function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;e{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; t.close=function(){this.db.close();this.db=null};t.destroy=function(){const a=ob.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(pb,"readwrite");for(let b=0;b=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=n.length){e-=n.length;continue}const m=c?e+Math.min(n.length-e,c):n.length;for(let q=e;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; t.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{d.onerror=k=>{this.h[a+":"+b]=null;d.abort();d=e=null;g(k)};d.oncomplete=k=>{d=e=this.h[a+":"+b]=null;f(k||!0)};return c.call(this,e)})}; +t.transaction=function(a,b,c){let e=this.h[a+":"+b];if(e)return c.call(this,e);let d=this.db.transaction(a,b);this.h[a+":"+b]=e=d.objectStore(a);return new Promise((f,g)=>{d.onerror=h=>{d.abort();d=e=null;g(h)};d.oncomplete=h=>{d=e=null;f(h||!0)};const k=c.call(this,e);this.h[a+":"+b]=null;return k})}; t.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=h.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1n&&!f&&"string"===typeof m&&!isNaN(m)&&(n=h.indexOf(parseInt(m,10)))&&(f=1),0<=n)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const tb={Index:O,Charset:db,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:rb,Language:{}},ub="undefined"!==typeof self?self:"undefined"!==typeof global?global:"undefined"!==typeof window?window:{};let vb;(vb=ub.define)&&vb.amd?vb([],function(){return tb}):"object"===typeof ub.exports?ub.exports=tb:ub.FlexSearch=tb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index f4e3353..30316a2 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.113 (Bundle/Module/Debug) + * FlexSearch.js v0.8.115 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -242,8 +242,8 @@ t.encode = function(a) { this.stemmer && 2 < g.length && (this.N || (this.N = new RegExp("(?!^)(" + this.A + ")$")), g = g.replace(this.N, h => this.stemmer.get(h)), g.length < this.minlength || this.filter && this.filter.has(g)) && (g = ""); if (g && (this.mapper || this.dedupe && 1 < g.length)) { d = ""; - for (let h = 0, l = "", m, n; h < g.length; h++) { - m = g.charAt(h), m === l && this.dedupe || ((n = this.mapper && this.mapper.get(m)) || "" === n ? n === l && this.dedupe || !(l = n) || (d += n) : d += l = m); + for (let h = 0, l = "", n, m; h < g.length; h++) { + n = g.charAt(h), n === l && this.dedupe || ((m = this.mapper && this.mapper.get(n)) || "" === m ? m === l && this.dedupe || !(l = m) || (d += m) : d += l = n); } g = d; } @@ -341,8 +341,8 @@ function Q(a = {}) { function b(g) { function k(h) { h = h.data || h; - const l = h.id, m = l && d.h[l]; - m && (m(h.msg), delete d.h[l]); + const l = h.id, n = l && d.h[l]; + n && (n(h.msg), delete d.h[l]); } this.worker = g; this.h = B(); @@ -683,19 +683,19 @@ function Ba(a) { } if (d && f) { E(f) && (f = [f]); - for (let h = 0, l, m; h < f.length; h++) { - if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !c || !m.includes(a))) { - if (m.length === 2 ** 31 - 1) { - g = new S(m); + for (let h = 0, l, n; h < f.length; h++) { + if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? n = g : d.set(l, n = []), !c || !n.includes(a))) { + if (n.length === 2 ** 31 - 1) { + g = new S(n); if (this.fastupdate) { - for (let n of this.reg.values()) { - n.includes(m) && (n[n.indexOf(m)] = g); + for (let m of this.reg.values()) { + m.includes(n) && (m[m.indexOf(n)] = g); } } - d.set(l, m = g); + d.set(l, n = g); } - m.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); + n.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])); } } } else { @@ -712,10 +712,10 @@ function Ba(a) { if ((c = l.I) && !c(b)) { continue; } - let m; + let n; if ("function" === typeof l) { - m = l(b); - if (!m) { + n = l(b); + if (!n) { continue; } l = [l.V]; @@ -723,7 +723,7 @@ function Ba(a) { k[l] = b[l]; continue; } - Ea(b, k, l, 0, l[0], m); + Ea(b, k, l, 0, l[0], n); } } this.store.set(a, k || b); @@ -775,13 +775,13 @@ function Da(a, b, c, e, d, f, g, k) { ;function Fa(a, b, c, e, d, f, g) { const k = a.length; let h = [], l; - var m; + var n; l = B(); - for (let n = 0, p, q, r, u; n < b; n++) { + for (let m = 0, q, p, r, u; m < b; m++) { for (let v = 0; v < k; v++) { - if (r = a[v], n < r.length && (p = r[n])) { - for (let x = 0; x < p.length; x++) { - q = p[x], (m = l[q]) ? l[q]++ : (m = 0, l[q] = 1), u = h[m] || (h[m] = []), g || (m = n + (v || !d ? 0 : f || 0), u = u[m] || (u[m] = [])), u.push(q); + if (r = a[v], m < r.length && (q = r[m])) { + for (let x = 0; x < q.length; x++) { + p = q[x], (n = l[p]) ? l[p]++ : (n = 0, l[p] = 1), u = h[n] || (h[n] = []), g || (n = m + (v || !d ? 0 : f || 0), u = u[n] || (u[n] = [])), u.push(p); } } } @@ -801,14 +801,14 @@ function Da(a, b, c, e, d, f, g, k) { } } else { d = []; - for (let n = 0, p; n < h.length; n++) { - if (p = h[n], p.length > e) { - e -= p.length; + for (let m = 0, q; m < h.length; m++) { + if (q = h[m], q.length > e) { + e -= q.length; } else { - if (p.length > c || e) { - p = p.slice(e, c + e), c -= p.length, e && (e -= p.length); + if (q.length > c || e) { + q = q.slice(e, c + e), c -= q.length, e && (e -= q.length); } - d.push(p); + d.push(q); if (!c) { break; } @@ -843,18 +843,18 @@ function Ga(a, b, c, e, d) { } } } else { - for (let m = h - 1, n, p = 0; 0 <= m; m--) { - n = a[m]; - for (let q = 0; q < n.length; q++) { - if (l = (e = n[q]) && e.length) { + for (let n = h - 1, m, q = 0; 0 <= n; n--) { + m = a[n]; + for (let p = 0; p < m.length; p++) { + if (l = (e = m[p]) && e.length) { for (let r = 0; r < l; r++) { if (k = e[r], !g[k]) { if (g[k] = 1, c) { c--; } else { - let u = (q + (m < h - 1 ? d || 0 : 0)) / (m + 1) | 0; + let u = (p + (n < h - 1 ? d || 0 : 0)) / (n + 1) | 0; (f[u] || (f[u] = [])).push(k); - if (++p === b) { + if (++q === b) { return f; } } @@ -921,8 +921,8 @@ function Ha(a, b, c) { ;function Ja(a, b, c) { var e = c[0]; if (e.then) { - return Promise.all(c).then(function(m) { - return a[b].apply(a, m); + return Promise.all(c).then(function(n) { + return a[b].apply(a, n); }); } if (e[0] && e[0].index) { @@ -930,32 +930,32 @@ function Ha(a, b, c) { } e = []; let d = [], f = 0, g = 0, k, h, l; - for (let m = 0, n; m < c.length; m++) { - if (n = c[m]) { - let p; - if (n.constructor === X) { - p = n.result; - } else if (n.constructor === Array) { - p = n; + for (let n = 0, m; n < c.length; n++) { + if (m = c[n]) { + let q; + if (m.constructor === X) { + q = m.result; + } else if (m.constructor === Array) { + q = m; } else { - if (f = n.limit || 0, g = n.offset || 0, l = n.suggest, h = n.resolve, k = n.enrich && h, n.index) { - n.resolve = !1, n.enrich = !1, p = n.index.search(n).result, n.resolve = h, n.enrich = k; - } else if (n.and) { - p = a.and(n.and); - } else if (n.or) { - p = a.or(n.or); - } else if (n.xor) { - p = a.xor(n.xor); - } else if (n.not) { - p = a.not(n.not); + if (f = m.limit || 0, g = m.offset || 0, l = m.suggest, h = m.resolve, k = m.enrich && h, m.index) { + m.resolve = !1, m.enrich = !1, q = m.index.search(m).result, m.resolve = h, m.enrich = k; + } else if (m.and) { + q = a.and(m.and); + } else if (m.or) { + q = a.or(m.or); + } else if (m.xor) { + q = a.xor(m.xor); + } else if (m.not) { + q = a.not(m.not); } else { continue; } } - if (p.then) { - d.push(p); - } else if (p.length) { - e[m] = p; + if (q.then) { + d.push(q); + } else if (q.length) { + e[n] = q; } else if (!l && ("and" === b || "xor" === b)) { e = []; break; @@ -989,8 +989,8 @@ function Ka(a, b, c, e, d, f) { f && (a = !!f.suggest, d = f.resolve, b = f.limit, c = f.offset, e = f.enrich && d); } if (a) { - const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:m, suggest:n} = Ja(this, "and", arguments); - return La.call(this, f, g, k, h, l, m, n); + const {O:f, P:g, limit:k, offset:h, enrich:l, resolve:n, suggest:m} = Ja(this, "and", arguments); + return La.call(this, f, g, k, h, l, n, m); } return d ? this.resolve(b, c, e) : this; }; @@ -999,8 +999,8 @@ function La(a, b, c, e, d, f, g) { const k = this; return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } return La.call(k, a, [], c, e, d, f, g); }); @@ -1028,8 +1028,8 @@ function Ma(a, b, c, e, d, f, g) { const k = this; return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } return Ma.call(k, a, [], c, e, d, f, g); }); @@ -1051,21 +1051,21 @@ function Na(a, b, c, e, d) { for (let h = 0, l; h < a.length; h++) { if (l = a[h]) { k < l.length && (k = l.length); - for (let m = 0, n; m < l.length; m++) { - if (n = l[m]) { - for (let p = 0, q; p < n.length; p++) { - q = n[p], g[q] = g[q] ? 2 : 1; + for (let n = 0, m; n < l.length; n++) { + if (m = l[n]) { + for (let q = 0, p; q < m.length; q++) { + p = m[q], g[p] = g[p] ? 2 : 1; } } } } } - for (let h = 0, l, m = 0; h < k; h++) { - for (let n = 0, p; n < a.length; n++) { - if (p = a[n]) { - if (l = p[h]) { - for (let q = 0, r; q < l.length; q++) { - if (r = l[q], 1 === g[r]) { + for (let h = 0, l, n = 0; h < k; h++) { + for (let m = 0, q; m < a.length; m++) { + if (q = a[m]) { + if (l = q[h]) { + for (let p = 0, r; p < l.length; p++) { + if (r = l[p], 1 === g[r]) { if (c) { c--; } else { @@ -1074,10 +1074,10 @@ function Na(a, b, c, e, d) { return f; } } else { - const u = h + (n ? d : 0); + const u = h + (m ? d : 0); f[u] || (f[u] = []); f[u].push(r); - if (++m === b) { + if (++n === b) { return f; } } @@ -1099,8 +1099,8 @@ function Oa(a, b, c, e, d, f, g) { const k = this; return Promise.all(b).then(function(h) { a = []; - for (let l = 0, m; l < h.length; l++) { - (m = h[l]).length && (a[l] = m); + for (let l = 0, n; l < h.length; l++) { + (n = h[l]).length && (a[l] = n); } return Oa.call(k, a, [], c, e, d, f, g); }); @@ -1195,8 +1195,9 @@ V.prototype.search = function(a, b, c, e) { let d = [], f = [], g; let k; let h; - let l, m = 0; - let n; + let l, n = 0; + var m = !0; + let q; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; @@ -1204,9 +1205,9 @@ V.prototype.search = function(a, b, c, e) { k = c.merge; h = g || c.field || (h = c.index) && (h.index ? null : h); var p = this.tag && c.tag; - var q = c.suggest; - var r = !1 !== c.resolve; - if (!r && !g) { + var r = c.suggest; + m = !1 !== c.resolve; + if (!m && !g) { if (h = h || this.field) { E(h) ? g = h : (h.constructor === Array && 1 === h.length && (h = h[0]), g = h.field || h.index); } @@ -1214,9 +1215,9 @@ V.prototype.search = function(a, b, c, e) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - this.store && c.enrich && !r && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var u = this.store && c.enrich && r; - n = c.highlight && u; + this.store && c.enrich && !m && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var u = this.store && c.enrich && m; + q = c.highlight && u; b = c.limit || b; l = c.offset || 0; b || (b = 100); @@ -1255,23 +1256,23 @@ V.prototype.search = function(a, b, c, e) { } p = v; if (!a) { - q = []; + r = []; if (v.length) { for (p = 0; p < v.length; p += 2) { if (this.db) { - r = this.index.get(v[p]); - if (!r) { + m = this.index.get(v[p]); + if (!m) { console.warn("Tag '" + v[p] + ":" + v[p + 1] + "' will be skipped because there is no field '" + v[p] + "'."); continue; } - q.push(r = r.db.tag(v[p + 1], b, l, u)); + r.push(m = m.db.tag(v[p + 1], b, l, u)); } else { - r = Qa.call(this, v[p], v[p + 1], b, l, u); + m = Qa.call(this, v[p], v[p + 1], b, l, u); } - d.push({field:v[p], tag:v[p + 1], result:r}); + d.push({field:v[p], tag:v[p + 1], result:m}); } } - return q.length ? Promise.all(q).then(function(z) { + return r.length ? Promise.all(r).then(function(z) { for (let w = 0; w < z.length; w++) { d[w].result = z[w]; } @@ -1290,7 +1291,7 @@ V.prototype.search = function(a, b, c, e) { continue; } let C; - E(D) || (C = D, D = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, q = C.suggest || q, u = this.store && (C.enrich || u)); + E(D) || (C = D, D = C.field, a = C.query || a, b = C.limit || b, l = C.offset || l, r = C.suggest || r, u = this.store && (C.enrich || u)); if (e) { w = e[z]; } else { @@ -1302,7 +1303,7 @@ V.prototype.search = function(a, b, c, e) { w = y.search(a, b, x), x && u && (x.enrich = u); } } - H = w && (r ? w.length : w.result.length); + H = w && (m ? w.length : w.result.length); if (p && H) { x = []; y = 0; @@ -1312,8 +1313,8 @@ V.prototype.search = function(a, b, c, e) { let K = e[G]; if (K && K.length) { y++, x.push(K); - } else if (!q) { - return r ? d : new X(d); + } else if (!r) { + return m ? d : new X(d); } } } @@ -1321,32 +1322,32 @@ V.prototype.search = function(a, b, c, e) { for (let G = 0, K, ob; G < p.length; G += 2) { K = this.tag.get(p[G]); if (!K) { - if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), q) { + if (console.warn("Tag '" + p[G] + ":" + p[G + 1] + "' will be skipped because there is no field '" + p[G] + "'."), r) { continue; } else { - return r ? d : new X(d); + return m ? d : new X(d); } } if (ob = (K = K && K.get(p[G + 1])) && K.length) { y++, x.push(K); - } else if (!q) { - return r ? d : new X(d); + } else if (!r) { + return m ? d : new X(d); } } } if (y) { - w = Ha(w, x, r); + w = Ha(w, x, m); H = w.length; - if (!H && !q) { - return r ? w : new X(w); + if (!H && !r) { + return m ? w : new X(w); } y--; } } if (H) { - f[m] = D, d.push(w), m++; + f[n] = D, d.push(w), n++; } else if (1 === h.length) { - return r ? d : new X(d); + return m ? d : new X(d); } } if (v) { @@ -1354,10 +1355,10 @@ V.prototype.search = function(a, b, c, e) { for (u = 0; u < p.length; u += 2) { e = this.index.get(p[u]); if (!e) { - if (console.warn("Tag '" + p[u] + ":" + p[u + 1] + "' was not found because there is no field '" + p[u] + "'."), q) { + if (console.warn("Tag '" + p[u] + ":" + p[u + 1] + "' was not found because there is no field '" + p[u] + "'."), r) { continue; } else { - return r ? d : new X(d); + return m ? d : new X(d); } } v.push(e.db.tag(p[u + 1], b, l, !1)); @@ -1368,8 +1369,8 @@ V.prototype.search = function(a, b, c, e) { return w.length ? z.search(a, b, c, w) : w; }); } - if (!m) { - return r ? d : new X(d); + if (!n) { + return m ? d : new X(d); } if (g && (!u || !this.store)) { return d[0]; @@ -1379,7 +1380,7 @@ V.prototype.search = function(a, b, c, e) { w = d[z]; u && w.length && !w[0].doc && (this.db ? v.push(w = this.index.get(this.field[0]).db.enrich(w)) : w = W.call(this, w)); if (g) { - return r ? w : new X(w); + return m ? w : new X(w); } d[z] = {field:f[z], result:w}; } @@ -1389,24 +1390,24 @@ V.prototype.search = function(a, b, c, e) { for (let D = 0; D < w.length; D++) { d[D].result = w[D]; } - return k ? Ra(d, b) : n ? Sa(d, a, z.index, z.field, z.D, n) : d; + return k ? Ra(d, b) : q ? Sa(d, a, z.index, z.field, z.D, q) : d; }); } - return k ? Ra(d, b) : n ? Sa(d, a, this.index, this.field, this.D, n) : d; + return k ? Ra(d, b) : q ? Sa(d, a, this.index, this.field, this.D, q) : d; }; function Sa(a, b, c, e, d, f) { let g, k, h; - for (let m = 0, n, p, q, r, u; m < a.length; m++) { - n = a[m].result; - p = a[m].field; - r = c.get(p); - q = r.encoder; + for (let n = 0, m, q, p, r, u; n < a.length; n++) { + m = a[n].result; + q = a[n].field; + r = c.get(q); + p = r.encoder; h = r.tokenize; - u = d[e.indexOf(p)]; - q !== g && (g = q, k = g.encode(b)); - for (let v = 0; v < n.length; v++) { + u = d[e.indexOf(q)]; + p !== g && (g = p, k = g.encode(b)); + for (let v = 0; v < m.length; v++) { let x = ""; - var l = ba(n[v].doc, u); + var l = ba(m[v].doc, u); let y = g.encode(l); l = l.split(g.split); for (let F = 0, z, w; F < y.length; F++) { @@ -1431,7 +1432,7 @@ function Sa(a, b, c, e, d, f) { } D || (x += (x ? " " : "") + l[F]); } - n[v].highlight = x; + m[v].highlight = x; } } return a; @@ -1441,9 +1442,9 @@ function Ra(a, b) { for (let d = 0, f, g; d < a.length; d++) { f = a[d]; g = f.result; - for (let k = 0, h, l, m; k < g.length; k++) { - if (l = g[k], h = l.id, m = e[h]) { - m.push(f.field); + for (let k = 0, h, l, n; k < g.length; k++) { + if (l = g[k], h = l.id, n = e[h]) { + n.push(f.field); } else { if (c.length === b) { return c; @@ -1820,20 +1821,20 @@ O.prototype.add = function(a, b, c, e) { } b = this.encoder.encode(b); if (e = b.length) { - const l = B(), m = B(), n = this.depth, p = this.resolution; - for (let q = 0; q < e; q++) { - let r = b[this.rtl ? e - 1 - q : q]; + const l = B(), n = B(), m = this.depth, q = this.resolution; + for (let p = 0; p < e; p++) { + let r = b[this.rtl ? e - 1 - p : p]; var d = r.length; - if (d && (n || !m[r])) { - var f = this.score ? this.score(b, r, q, null, 0) : fb(p, e, q), g = ""; + if (d && (m || !n[r])) { + var f = this.score ? this.score(b, r, p, null, 0) : fb(q, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var k = d; k > f; k--) { g = r.substring(f, k); - var h = this.score ? this.score(b, r, q, g, f) : fb(p, e, q, d, f); - gb(this, m, g, h, a, c); + var h = this.score ? this.score(b, r, p, g, f) : fb(q, e, p, d, f); + gb(this, n, g, h, a, c); } } break; @@ -1841,23 +1842,23 @@ O.prototype.add = function(a, b, c, e) { case "reverse": if (1 < d) { for (k = d - 1; 0 < k; k--) { - g = r[k] + g, h = this.score ? this.score(b, r, q, g, k) : fb(p, e, q, d, k), gb(this, m, g, h, a, c); + g = r[k] + g, h = this.score ? this.score(b, r, p, g, k) : fb(q, e, p, d, k), gb(this, n, g, h, a, c); } g = ""; } case "forward": if (1 < d) { for (k = 0; k < d; k++) { - g += r[k], gb(this, m, g, f, a, c); + g += r[k], gb(this, n, g, f, a, c); } break; } default: - if (gb(this, m, r, f, a, c), n && 1 < e && q < e - 1) { - for (d = B(), g = this.U, f = r, k = Math.min(n + 1, e - q), d[f] = 1, h = 1; h < k; h++) { - if ((r = b[this.rtl ? e - 1 - q - h : q + h]) && !d[r]) { + if (gb(this, n, r, f, a, c), m && 1 < e && p < e - 1) { + for (d = B(), g = this.U, f = r, k = Math.min(m + 1, e - p), d[f] = 1, h = 1; h < k; h++) { + if ((r = b[this.rtl ? e - 1 - p - h : p + h]) && !d[r]) { d[r] = 1; - const u = this.score ? this.score(b, f, q, r, h) : fb(g + (e / 2 > g ? 0 : 1), e, q, k - 1, h - 1), v = this.bidirectional && r > f; + const u = this.score ? this.score(b, f, p, r, h) : fb(g + (e / 2 > g ? 0 : 1), e, p, k - 1, h - 1), v = this.bidirectional && r > f; gb(this, l, v ? f : r, u, a, c, v ? r : f); } } @@ -1896,32 +1897,32 @@ function fb(a, b, c, e, d) { } ;O.prototype.search = function(a, b, c) { c || (!b && I(a) ? (c = a, a = "") : I(b) && (c = b, b = 0)); - let e = [], d, f, g, k = 0, h, l, m, n, p; - c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, p = (h = !1 !== c.resolve) && c.enrich, m = c.boost, n = c.resolution, l = this.db && c.tag) : h = this.resolve; - let q = this.encoder.encode(a); - d = q.length; + let e = [], d, f, g, k = 0, h, l, n, m, q; + c ? (a = c.query || a, b = c.limit || b, k = c.offset || 0, f = c.context, g = c.suggest, q = (h = !1 !== c.resolve) && c.enrich, n = c.boost, m = c.resolution, l = this.db && c.tag) : h = this.resolve; + let p = this.encoder.encode(a); + d = p.length; b = b || (h ? 100 : 0); if (1 === d) { - return ib.call(this, q[0], "", b, k, h, p, l); + return ib.call(this, p[0], "", b, k, h, q, l); } f = this.depth && !1 !== f; if (2 === d && f && !g) { - return ib.call(this, q[0], q[1], b, k, h, p, l); + return ib.call(this, p[0], p[1], b, k, h, q, l); } let r = B(), u = 0, v; - 1 < d && f && (v = q[0], u = 1); - n || 0 === n || (n = v ? this.U : this.resolution); + 1 < d && f && (v = p[0], u = 1); + m || 0 === m || (m = v ? this.U : this.resolution); if (this.db) { - if (this.db.search && (a = this.db.search(this, q, b, k, g, h, p, l), !1 !== a)) { + if (this.db.search && (a = this.db.search(this, p, b, k, g, h, q, l), !1 !== a)) { return a; } const x = this; return async function() { for (let y, F; u < d; u++) { - if ((F = q[u]) && !r[F]) { + if ((F = p[u]) && !r[F]) { r[F] = 1; y = await jb(x, F, v, 0, 0, !1, !1); - if (y = kb(y, e, g, n)) { + if (y = kb(y, e, g, m)) { e = y; break; } @@ -1929,14 +1930,14 @@ function fb(a, b, c, e, d) { } g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return lb(e, n, b, k, g, m, h); + return lb(e, m, b, k, g, n, h); }(); } for (let x, y; u < d; u++) { - if ((y = q[u]) && !r[y]) { + if ((y = p[u]) && !r[y]) { r[y] = 1; x = jb(this, y, v, 0, 0, !1, !1); - if (x = kb(x, e, g, n)) { + if (x = kb(x, e, g, m)) { e = x; break; } @@ -1944,7 +1945,7 @@ function fb(a, b, c, e, d) { } g && v && u === d - 1 && !e.length && (v = "", u = -1, r = B()); } - return lb(e, n, b, k, g, m, h); + return lb(e, m, b, k, g, n, h); }; function lb(a, b, c, e, d, f, g) { let k = a.length, h = a; @@ -2181,11 +2182,11 @@ t.serialize = function(a = !0) { e = ""; for (var d of this.map.entries()) { var f = d[0], g = d[1], k = ""; - for (let m = 0, n; m < g.length; m++) { - n = g[m] || [""]; + for (let n = 0, m; n < g.length; n++) { + m = g[n] || [""]; var h = ""; - for (var l = 0; l < n.length; l++) { - h += (h ? "," : "") + ("string" === c ? '"' + n[l] + '"' : n[l]); + for (var l = 0; l < m.length; l++) { + h += (h ? "," : "") + ("string" === c ? '"' + m[l] + '"' : m[l]); } h = "[" + h + "]"; k += (k ? "," : "") + h; @@ -2195,18 +2196,18 @@ t.serialize = function(a = !0) { } e = "index.map=new Map([" + e + "]);"; d = ""; - for (const m of this.ctx.entries()) { - f = m[0]; - g = m[1]; - for (const n of g.entries()) { - g = n[0]; - k = n[1]; + for (const n of this.ctx.entries()) { + f = n[0]; + g = n[1]; + for (const m of g.entries()) { + g = m[0]; + k = m[1]; h = ""; - for (let p = 0, q; p < k.length; p++) { - q = k[p] || [""]; + for (let q = 0, p; q < k.length; q++) { + p = k[q] || [""]; l = ""; - for (let r = 0; r < q.length; r++) { - l += (l ? "," : "") + ("string" === c ? '"' + q[r] + '"' : q[r]); + for (let r = 0; r < p.length; r++) { + l += (l ? "," : "") + ("string" === c ? '"' + p[r] + '"' : p[r]); } l = "[" + l + "]"; h += (h ? "," : "") + l; @@ -2297,15 +2298,15 @@ t.get = function(a, b, c = 0, e = 0, d = !0, f = !1) { if (!c && !e && 1 === k.length) { return k[0]; } - for (let l = 0, m; l < k.length; l++) { - if ((m = k[l]) && m.length) { - if (e >= m.length) { - e -= m.length; + for (let l = 0, n; l < k.length; l++) { + if ((n = k[l]) && n.length) { + if (e >= n.length) { + e -= n.length; continue; } - const n = c ? e + Math.min(m.length - e, c) : m.length; - for (let p = e; p < n; p++) { - h.push(m[p]); + const m = c ? e + Math.min(n.length - e, c) : n.length; + for (let q = e; q < m; q++) { + h.push(n[q]); } e = 0; if (h.length === c) { @@ -2360,17 +2361,18 @@ t.transaction = function(a, b, c) { let d = this.db.transaction(a, b); this.h[a + ":" + b] = e = d.objectStore(a); return new Promise((f, g) => { - d.onerror = k => { - this.h[a + ":" + b] = null; + d.onerror = h => { d.abort(); d = e = null; - g(k); + g(h); }; - d.oncomplete = k => { - d = e = this.h[a + ":" + b] = null; - f(k || !0); + d.oncomplete = h => { + d = e = null; + f(h || !0); }; - return c.call(this, e); + const k = c.call(this, e); + this.h[a + ":" + b] = null; + return k; }); }; t.commit = async function(a, b, c) { @@ -2398,14 +2400,14 @@ t.commit = async function(a, b, c) { var h; if (k && k.length) { const l = Math.max(k.length, g.length); - for (let m = 0, n, p; m < l; m++) { - if ((p = g[m]) && p.length) { - if ((n = k[m]) && n.length) { - for (h = 0; h < p.length; h++) { - n.push(p[h]); + for (let n = 0, m, q; n < l; n++) { + if ((q = g[n]) && q.length) { + if ((m = k[n]) && m.length) { + for (h = 0; h < q.length; h++) { + m.push(q[h]); } } else { - k[m] = p; + k[n] = q; } h = 1; } @@ -2422,26 +2424,26 @@ t.commit = async function(a, b, c) { for (const k of g) { const h = k[0], l = k[1]; l.length && (b ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { - let m = this.result; - var n; - if (m && m.length) { - const p = Math.max(m.length, l.length); - for (let q = 0, r, u; q < p; q++) { - if ((u = l[q]) && u.length) { - if ((r = m[q]) && r.length) { - for (n = 0; n < u.length; n++) { - r.push(u[n]); + let n = this.result; + var m; + if (n && n.length) { + const q = Math.max(n.length, l.length); + for (let p = 0, r, u; p < q; p++) { + if ((u = l[p]) && u.length) { + if ((r = n[p]) && r.length) { + for (m = 0; m < u.length; m++) { + r.push(u[m]); } } else { - m[q] = u; + n[p] = u; } - n = 1; + m = 1; } } } else { - m = l, n = 1; + n = l, m = 1; } - n && e.put(m, f + ":" + h); + m && e.put(n, f + ":" + h); }); } } @@ -2470,10 +2472,10 @@ function sb(a, b, c) { let d, f, g = 0; for (let k = 0, h; k < e.length; k++) { if (h = c ? e : e[k]) { - for (let l = 0, m, n; l < b.length; l++) { - if (n = b[l], m = h.indexOf(f ? parseInt(n, 10) : n), 0 > m && !f && "string" === typeof n && !isNaN(n) && (m = h.indexOf(parseInt(n, 10))) && (f = 1), 0 <= m) { + for (let l = 0, n, m; l < b.length; l++) { + if (m = b[l], n = h.indexOf(f ? parseInt(m, 10) : m), 0 > n && !f && "string" === typeof m && !isNaN(m) && (n = h.indexOf(parseInt(m, 10))) && (f = 1), 0 <= n) { if (d = 1, 1 < h.length) { - h.splice(m, 1); + h.splice(n, 1); } else { e[k] = []; break; diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 1eebdc9..a9f9e06 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.113 (Bundle/Module) + * FlexSearch.js v0.8.115 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -20,10 +20,10 @@ A((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=A(a.replacer,null,t t.addMatcher=function(a,b){if("object"===typeof a)return this.addReplacer(a,b);if(2>a.length&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.M=null;this.cache&&L(this);return this};t.addReplacer=function(a,b){if("string"===typeof a)return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&L(this);return this}; t.encode=function(a){if(this.cache&&a.length<=this.K)if(this.H){if(this.B.has(a))return this.B.get(a)}else this.H=setTimeout(L,50,this);this.normalize&&("function"===typeof this.normalize?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g.lengththis.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d +"");if(g&&(this.mapper||this.dedupe&&1this.matcher.get(h)));if(g&&this.replacer)for(d=0;g&&d this.S&&(this.G.clear(),this.L=this.L/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.K&&(this.B.set(a,c),this.B.size>this.S&&(this.B.clear(),this.K=this.K/1.1|0));return c};function L(a){a.H=null;a.B.clear();a.G.clear()};let M,N;async function ka(a){a=a.data;var b=a.task;const c=a.id;let e=a.args;switch(b){case "init":N=a.options||{};(b=a.factory)?(Function("return "+b)()(self),M=new self.FlexSearch.Index(N),delete self.FlexSearch):M=new O(N);postMessage({id:c});break;default:let d;"export"===b&&(e[1]?(e[0]=N.export,e[2]=0,e[3]=1):e=null);"import"===b?e[0]&&(a=await N.import.call(M,e[0]),M.import(e[0],a)):(d=e&&M[b].apply(M,e))&&d.then&&(d=await d);postMessage("search"===b?{id:c,msg:d}:{id:c})}};function la(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}let ma,na;const oa={},pa={};function qa(a){ma=0;oa[a]=pa[a]} function P(a){this[a+"Async"]=function(){const b=arguments;var c=b[b.length-1];let e;"function"===typeof c&&(e=c,delete b[b.length-1]);ma||(ma=setTimeout(qa,0,a),na=Date.now());pa[a]||(pa[a]=oa[a]=1E3);if(!--oa[a]){oa[a]=pa[a]=pa[a]*this.priority*this.priority*3/(Date.now()-na)|0||1;ma=clearTimeout(ma);const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let ra=0; -function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,m=l&&d.h[l];m&&(m(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ra]=function(){h(d)};d.worker.postMessage({id:ra,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==Q)return new Q(a);let c="undefined"!==typeof self?self._factory:"undefined"!== +function Q(a={}){function b(g){function k(h){h=h.data||h;const l=h.id,n=l&&d.h[l];n&&(n(h.msg),delete d.h[l])}this.worker=g;this.h=B();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(h){d.h[++ra]=function(){h(d)};d.worker.postMessage({id:ra,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this||this.constructor!==Q)return new Q(a);let c="undefined"!==typeof self?self._factory:"undefined"!== typeof window?window._factory:null;c&&(c=c.toString());const e="undefined"===typeof window,d=this,f=sa(c,e,a.worker);return f.then?f.then(function(g){return b.call(d,g)}):b.call(this,f)}R("add");R("append");R("search");R("update");R("remove");R("clear");R("export");R("import");la(Q.prototype); function R(a){Q.prototype[a]=function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;"function"===typeof e&&(d=e,c.pop());e=new Promise(function(f){"export"===a&&"function"===typeof c[0]&&(c[0]=null);b.h[++ra]=f;b.worker.postMessage({task:a,id:ra,args:c})});return d?(e.then(d),this):e}} function sa(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="+ka.toString()],{type:"text/javascript"}))):new window.Worker("string"===typeof c?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", @@ -36,25 +36,25 @@ S.prototype.push=function(){};function T(a=8){if(!this)return new T(a);this.inde function U(a=8){if(!this)return new U(a);this.index=B();this.h=[];32c||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let n=0,p;ne)e-= -p.length;else{if(p.length>c||e)p=p.slice(e,c+e),c-=p.length,e&&(e-=p.length);d.push(p);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:m,suggest:n}=Ja(this,"and",arguments);return La.call(this,f,g,k,h,l,m,n)}return d?this.resolve(b,c,e):this}; -function La(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; -function Ma(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} -function Na(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e?h.slice(e,c+e):h;else{if(ac||e)h=h.slice(e,c+e)}else{d=[];for(let m=0,q;me)e-= +q.length;else{if(q.length>c||e)q=q.slice(e,c+e),c-=q.length,e&&(e-=q.length);d.push(q);if(!c)break}h=1b?b?a.slice(c,c+b):a.slice(c):a,e?W.call(this,a):a;let d=[];for(let f=0,g,k;f=k){c-=k;continue}cb&&(g=g.slice(0,b),k=b);if(!d.length&&k>=b)return e?W.call(this,g):g;d.push(g);b-=k;if(!b)break}d=1a.length?this.result=a[0]:(this.result=Ga(a,c,e,!1,this.h),e=0));return f?this.resolve(c,e,d):this};X.prototype.and=function(){let a=this.result.length,b,c,e,d;if(!a){const f=arguments[0];f&&(a=!!f.suggest,d=f.resolve,b=f.limit,c=f.offset,e=f.enrich&&d)}if(a){const {O:f,P:g,limit:k,offset:h,enrich:l,resolve:n,suggest:m}=Ja(this,"and",arguments);return La.call(this,f,g,k,h,l,n,m)}return d?this.resolve(b,c,e):this}; +function La(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else{if(b=ca(a))return this.result=Fa(a,b,c,e,g,this.h,f),f?d?W.call(this.index,this.result):this.result:this;this.result=[]}else g||(this.result=a);return f?this.resolve(c,e,d):this};X.prototype.xor=function(){const {O:a,P:b,limit:c,offset:e,enrich:d,resolve:f,suggest:g}=Ja(this,"xor",arguments);return Ma.call(this,a,b,c,e,d,f,g)}; +function Ma(a,b,c,e,d,f,g){if(b.length){const k=this;return Promise.all(b).then(function(h){a=[];for(let l=0,n;la.length)this.result=a[0];else return this.result=Na.call(this,a,c,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(c,e,d):this} +function Na(a,b,c,e,d){const f=[],g=B();let k=0;for(let h=0,l;hc||e)a=a.slice(e,e+c);d&&(a=W.call(this,a));return a}}function W(a){if(!this||!this.store)return a;const b=Array(a.length);for(let c=0,e;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; Y.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};Y.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};Y.prototype.clear=function(){this.cache.clear();this.h=""};const Wa={normalize:function(a){return a.toLowerCase()}};const Xa=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 Ya=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["pf","f"]]),Za=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/([^0-9])\1+/g,"$1"];const $a={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 ab=/[\x00-\x7F]+/g;const bb=/[\x00-\x7F]+/g;const cb=/[\x00-\x7F]+/g;var db={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Wa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Xa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Xa,matcher:Ya,replacer:Za},LatinExtra:{normalize:!0,dedupe:!0,mapper:Xa,replacer:Za.concat([/(?!^)[aeo]/g,""]),matcher:Ya},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,q,g,f):fb(p,e,q,d,f);gb(this,m,g,h,a,c)}break}case "reverse":if(1< -d){for(k=d-1;0g?0:1),e,q,k-1,h-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +g||"w"===g||!(g=$a[g])||g===d||(e+=g,d=g,4!==e.length));f++);a[c]=e}}},ArabicDefault:{rtl:!0,normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(ab," ")}},CjkDefault:{normalize:!1,dedupe:!0,split:"",prepare:function(a){return(""+a).replace(bb,"")}},CyrillicDefault:{normalize:!1,dedupe:!0,prepare:function(a){return(""+a).replace(cb," ")}}};const eb={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};O.prototype.add=function(a,b,c,e){if(b&&(a||0===a)){if(!e&&!c&&this.reg.has(a))return this.update(a,b);b=this.encoder.encode(b);if(e=b.length){const l=B(),n=B(),m=this.depth,q=this.resolution;for(let p=0;pf;k--){g=r.substring(f,k);var h=this.score?this.score(b,r,p,g,f):fb(q,e,p,d,f);gb(this,n,g,h,a,c)}break}case "reverse":if(1< +d){for(k=d-1;0g?0:1),e,p,k-1,h-1),v=this.bidirectional&&r>f;gb(this,l,v?f:r,u,a,c,v?r:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& (b||this.commit_task.push({del:a}),this.T&&hb(this));return this};function gb(a,b,c,e,d,f,g){let k=g?a.ctx:a.map,h;if(!b[c]||g&&!(h=b[c])[g])if(g?(b=h||(b[c]=B()),b[g]=1,(h=k.get(g))?k=h:k.set(g,k=new Map)):b[c]=1,(h=k.get(c))?k=h:k.set(c,k=h=[]),k=k[e]||(k[e]=[]),!f||!k.includes(d)){if(k.length===2**31-1){b=new S(k);if(a.fastupdate)for(let l of a.reg.values())l.includes(k)&&(l[l.indexOf(k)]=b);h[e]=k=b}k.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(k):a.reg.set(d,[k]))}} -function fb(a,b,c,e,d){return c&&1c)&&(h=c,c=b,b=h);if(a.db)return a.db.get(b,c,e,d,f,g,k);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};O.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 e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else mb(this.map,a),this.depth&&mb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&hb(this));this.cache&&this.cache.remove(a);return this}; function mb(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;e{d.objectStoreNames.contains(f)||d.createObjectStore(f)})};e.onblocked=function(d){console.error("blocked",d);c()};e.onerror=function(d){console.error(this.error,d);c()};e.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; t.close=function(){this.db.close();this.db=null};t.destroy=function(){const a=pb.deleteDatabase(this.id+(this.field?":"+this.field:""));return Z(a)};t.clear=function(){const a=this.db.transaction(qb,"readwrite");for(let b=0;b=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let p=e;p=n.length){e-=n.length;continue}const m=c?e+Math.min(n.length-e,c):n.length;for(let q=e;q=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; t.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e{d.onerror=k=>{this.h[a+":"+b]=null;d.abort();d=e=null;g(k)};d.oncomplete=k=>{d=e=this.h[a+":"+b]=null;f(k||!0)};return c.call(this,e)})}; +t.transaction=function(a,b,c){let e=this.h[a+":"+b];if(e)return c.call(this,e);let d=this.db.transaction(a,b);this.h[a+":"+b]=e=d.objectStore(a);return new Promise((f,g)=>{d.onerror=h=>{d.abort();d=e=null;g(h)};d.oncomplete=h=>{d=e=null;f(h||!0)};const k=c.call(this,e);this.h[a+":"+b]=null;return k})}; t.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let e=a.commit_task;a.commit_task=[];for(let d=0,f;dm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=h.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(d=1,1n&&!f&&"string"===typeof m&&!isNaN(m)&&(n=h.indexOf(parseInt(m,10)))&&(f=1),0<=n)if(d=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:O,Charset:db,Encoder:J,Document:V,Worker:Q,Resolver:X,IndexedDB:rb,Language:{}}; export const Index=O;export const Charset=db;export const Encoder=J;export const Document=V;export const Worker=Q;export const Resolver=X;export const IndexedDB=rb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index aba71aa..8f1703e 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.113 (Bundle/Debug) + * FlexSearch.js v0.8.115 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -935,7 +935,7 @@ V.prototype.search = function(a, c, b, e) { b || (!c && I(a) ? (b = a, a = "") : I(c) && (b = c, c = 0)); let d = []; var f = []; - let g, k, h, l, m, n, t = 0, p, q; + let g, k, h, l, m, n, t = 0, p = !0, q; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 1bf30ba..aa4981d 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.113 (Bundle) + * FlexSearch.js v0.8.115 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -39,7 +39,7 @@ function Da(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then( function Ea(a,c,b,e,d,f,g){if(c.length){const k=this;return Promise.all(c).then(function(h){a=[];for(let l=0,m;la.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} function Fa(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;ha.length)this.result=a[0];else return this.result=Fa.call(this,a,b,e,f,this.h),f?d?W.call(this.index,this.result):this.result:this;else g||(this.result=a);return f?this.resolve(b,e,d):this} function Fa(a,c,b,e,d){const f=[],g=C();let k=0;for(let h=0,l;ha.length)this.result=a[0];else return this.result=rb.call(this,a,c,d,g,this.h),g?e?X.call(this.index,this.result):this.result:this;else f||(this.result=a);return g?this.resolve(c,d,e):this} function rb(a,b,c,d,e){for(var g=[],f=J(),h=0,k=0,l;kc||d)a=a.slice(d,d+c);e&&(a=X.call(this,a));return a}} function X(a){if(!this||!this.store)return a;for(var b=Array(a.length),c=0,d;c=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=g.length)return[];if(!b&&!c)return g;g=g.slice(c,c+b);return d?e.enrich(g):g})}; u.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d { transaction.onerror = err => { - this.trx[ref + ":" + modifier] = null; transaction.abort(); transaction = store = null; reject(err); //db.close; }; transaction.oncomplete = res => { - this.trx[ref + ":" + modifier] = null; transaction = store = null; resolve(res || !0); //db.close; }; - return task.call(this, store); + const promise = task.call(this, store); + // + this.trx[ref + ":" + modifier] = null; + return promise; }); }; diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index 6607b8c..fc8751c 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -61,7 +61,7 @@ Document.prototype.search = function (query, limit, options, _promises) { tag, offset, count = 0, - resolve, + resolve = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, highlight; @@ -412,7 +412,7 @@ Document.prototype.search = function (query, limit, options, _promises) { }; } - if (enrich && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ && this.db && promises.length) { + if (enrich && !0 && this.db && promises.length) { const self = this; return Promise.all(promises).then(function (promises) { for (let j = 0; j < promises.length; j++) { diff --git a/dist/module-debug/index/search.js b/dist/module-debug/index/search.js index b9bb217..c03a771 100644 --- a/dist/module-debug/index/search.js +++ b/dist/module-debug/index/search.js @@ -57,7 +57,8 @@ Index.prototype.search = function (query, limit, options) { offset = options.offset || 0; context = options.context; suggest = options.suggest; - resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */ + !1 !== options.resolve; //resolve || (global_resolve = 0); enrich = resolve && options.enrich; boost = options.boost; diff --git a/dist/module-min/db/indexeddb/index.js b/dist/module-min/db/indexeddb/index.js index b9a408e..4ff1457 100644 --- a/dist/module-min/db/indexeddb/index.js +++ b/dist/module-min/db/indexeddb/index.js @@ -1 +1 @@ -import{PersistentOptions,SearchResults,EnrichedSearchResults}from"../../type.js";const VERSION=1,IndexedDB="undefined"!=typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),IDBTransaction="undefined"!=typeof window&&(window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction),IDBKeyRange="undefined"!=typeof window&&(window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}export default function IdxDB(a,b={}){return this?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?":"+sanitize(a):""),this.field=b.field?sanitize(b.field):"",this.type=b.type,this.support_tag_search=!1,this.fastupdate=!1,this.db=null,this.trx={}):new IdxDB(a,b)}IdxDB.prototype.mount=function(a){return a.encoder?(a.db=this,this.open()):a.mount(this)},IdxDB.prototype.open=function(){let a=this;return navigator.storage&&navigator.storage.persist(),this.db||new Promise(function(b,c){const d=IndexedDB.open(a.id+(a.field?":"+a.field:""),VERSION);d.onupgradeneeded=function(){const b=a.db=this.result;fields.forEach(a=>{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){const a=IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""));return promisfy(a)},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b(e.onerror=c=>{this.trx[a+":"+b]=null,e.abort(),e=d=null,g(c)},e.oncomplete=c=>{this.trx[a+":"+b]=null,e=d=null,f(c||!0)},c.call(this,d)))},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})} \ No newline at end of file +import{PersistentOptions,SearchResults,EnrichedSearchResults}from"../../type.js";const VERSION=1,IndexedDB="undefined"!=typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),IDBTransaction="undefined"!=typeof window&&(window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction),IDBKeyRange="undefined"!=typeof window&&(window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}export default function IdxDB(a,b={}){return this?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?":"+sanitize(a):""),this.field=b.field?sanitize(b.field):"",this.type=b.type,this.support_tag_search=!1,this.fastupdate=!1,this.db=null,this.trx={}):new IdxDB(a,b)}IdxDB.prototype.mount=function(a){return a.encoder?(a.db=this,this.open()):a.mount(this)},IdxDB.prototype.open=function(){let a=this;return navigator.storage&&navigator.storage.persist(),this.db||new Promise(function(b,c){const d=IndexedDB.open(a.id+(a.field?":"+a.field:""),VERSION);d.onupgradeneeded=function(){const b=a.db=this.result;fields.forEach(a=>{b.objectStoreNames.contains(a)||b.createObjectStore(a)})},d.onblocked=function(a){console.error("blocked",a),c()},d.onerror=function(a){console.error(this.error,a),c()},d.onsuccess=function(){a.db=this.result,a.db.onversionchange=function(){a.close()},b(a)}})},IdxDB.prototype.close=function(){this.db.close(),this.db=null},IdxDB.prototype.destroy=function(){const a=IndexedDB.deleteDatabase(this.id+(this.field?":"+this.field:""));return promisfy(a)},IdxDB.prototype.clear=function(){const a=this.db.transaction(fields,"readwrite");for(let b=0;b=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b{e.onerror=a=>{e.abort(),e=d=null,g(a)},e.oncomplete=a=>{e=d=null,f(a||!0)};const h=c.call(this,d);return this.trx[a+":"+b]=null,h})},IdxDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;ca)||f||"string"!=typeof c||isNaN(c)||(a=h.indexOf(parseInt(c,10)),a&&(f=1)),0<=a)if(e=1,1{a.onsuccess=function(){b&&b(this.result),c(this.result)},a.oncomplete=function(){b&&b(this.result),c(this.result)},a.onerror=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/document/search.js b/dist/module-min/document/search.js index 173bc9c..ab27dab 100644 --- a/dist/module-min/document/search.js +++ b/dist/module-min/document/search.js @@ -1 +1 @@ -import{DocumentSearchOptions,DocumentSearchResults,EnrichedDocumentSearchResults,MergedDocumentSearchResults,EnrichedSearchResults,SearchResults,IntermediateSearchResults}from"../type.js";import{create_object,is_array,is_object,is_string,parse_simple}from"../common.js";import{intersect_union}from"../intersect.js";import Document from"../document.js";import Index from"../index.js";import Resolver from"../resolver.js";import tick from"../profiler.js";Document.prototype.search=function(a,b,c,d){!1,c||(!b&&is_object(a)?(c=a,a=""):is_object(b)&&(c=b,b=0));let e,f,g,h,j,k,l,m,n,o=[],p=[],q=0;if(c){if(is_array(c)&&(c={index:c}),a=c.query||a,e=c.pluck,g=c.merge,j=e||c.field||(j=c.index)&&(j.index?null:j),k=this.tag&&c.tag,h=c.suggest,m=!1!==c.resolve,(m||e||(j=j||this.field,j&&(is_string(j)?e=j:(is_array(j)&&1===j.length&&(j=j[0]),e=j.field||j.index))),!1,f=this.store&&c.enrich&&m,n=c.highlight&&f,b=c.limit||b,l=c.offset||0,b||(b=100),k&&(!this.db||!d))){!1,k.constructor!==Array&&(k=[k]);let c=[];for(let a,b=0;b { transaction.onerror = err => { - this.trx[ref + ":" + modifier] = null; transaction.abort(); transaction = store = null; reject(err); //db.close; }; transaction.oncomplete = res => { - this.trx[ref + ":" + modifier] = null; transaction = store = null; resolve(res || !0); //db.close; }; - return task.call(this, store); + const promise = task.call(this, store); + // + this.trx[ref + ":" + modifier] = null; + return promise; }); }; diff --git a/dist/module/document/search.js b/dist/module/document/search.js index fad0951..928ed60 100644 --- a/dist/module/document/search.js +++ b/dist/module/document/search.js @@ -61,7 +61,7 @@ Document.prototype.search = function (query, limit, options, _promises) { tag, offset, count = 0, - resolve, + resolve = /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/, highlight; @@ -392,7 +392,7 @@ Document.prototype.search = function (query, limit, options, _promises) { }; } - if (enrich && /* tag? */ /* stringify */ /* stringify */ /* single param */ /* skip update: */ /* append: */ /* skip update: */ /* skip_update: */!0 /*await rows.hasNext()*/ /*await rows.hasNext()*/ /*await rows.hasNext()*/ && this.db && promises.length) { + if (enrich && !0 && this.db && promises.length) { const self = this; return Promise.all(promises).then(function (promises) { for (let j = 0; j < promises.length; j++) { diff --git a/dist/module/index/search.js b/dist/module/index/search.js index b9bb217..c03a771 100644 --- a/dist/module/index/search.js +++ b/dist/module/index/search.js @@ -57,7 +57,8 @@ Index.prototype.search = function (query, limit, options) { offset = options.offset || 0; context = options.context; suggest = options.suggest; - resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */!1 !== options.resolve; + resolve = /*global_resolve &&*/ /* suggest */ /* append: */ /* enrich */ + !1 !== options.resolve; //resolve || (global_resolve = 0); enrich = resolve && options.enrich; boost = options.boost; diff --git a/package-lock.json b/package-lock.json index 11229ab..030ac76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.113", + "version": "0.8.115", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.113", + "version": "0.8.115", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 7752e06..fd0005a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.113", + "version": "0.8.115", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/src/db/indexeddb/index.js b/src/db/indexeddb/index.js index d46e69a..5261a30 100644 --- a/src/db/indexeddb/index.js +++ b/src/db/indexeddb/index.js @@ -317,19 +317,21 @@ IdxDB.prototype.transaction = function(ref, modifier, task){ return new Promise((resolve, reject) => { transaction.onerror = (err) => { - this.trx[ref+ ":" + modifier] = null; transaction.abort(); transaction = store = null; reject(err); //db.close; }; transaction.oncomplete = (res) => { - this.trx[ref+ ":" + modifier] = null; transaction = store = null; resolve(res || true); //db.close; }; - return task.call(this, store); + const promise = task.call(this, store); + // transactions can just be used within the same event loop + // the indexeddb is such a stupid tool :( + this.trx[ref+ ":" + modifier] = null; + return promise; }); }; diff --git a/src/document/search.js b/src/document/search.js index 37c6d30..a876f9c 100644 --- a/src/document/search.js +++ b/src/document/search.js @@ -75,7 +75,7 @@ Document.prototype.search = function(query, limit, options, _promises){ let result = []; let result_field = []; let pluck, enrich, merge, suggest; - let field, tag, offset, count = 0, resolve, highlight; + let field, tag, offset, count = 0, resolve = true, highlight; if(options){