diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index 1cb5654..42e27c7 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -499,18 +499,18 @@ O.prototype.add = function(a, b, c, d) { b = this.encoder.encode(b); if (d = b.length) { const l = z(), m = z(), n = this.depth, q = this.resolution; - for (let t = 0; t < d; t++) { - let p = b[this.rtl ? d - 1 - t : t]; + for (let r = 0; r < d; r++) { + let p = b[this.rtl ? d - 1 - r : r]; var e = p.length; if (e && (n || !m[p])) { - var f = this.score ? this.score(b, p, t, null, 0) : P(q, d, t), g = ""; + var f = this.score ? this.score(b, p, r, null, 0) : P(q, d, r), g = ""; switch(this.tokenize) { case "full": if (2 < e) { for (f = 0; f < e; f++) { for (var h = e; h > f; h--) { g = p.substring(f, h); - var k = this.score ? this.score(b, p, t, g, f) : P(q, d, t, e, f); + var k = this.score ? this.score(b, p, r, g, f) : P(q, d, r, e, f); Q(this, m, g, k, a, c); } } @@ -519,7 +519,7 @@ O.prototype.add = function(a, b, c, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - g = p[h] + g, k = this.score ? this.score(b, p, t, g, h) : P(q, d, t, e, h), Q(this, m, g, k, a, c); + g = p[h] + g, k = this.score ? this.score(b, p, r, g, h) : P(q, d, r, e, h), Q(this, m, g, k, a, c); } g = ""; } @@ -531,12 +531,12 @@ O.prototype.add = function(a, b, c, d) { break; } default: - if (Q(this, m, p, f, a, c), n && 1 < d && t < d - 1) { - for (e = z(), g = this.U, f = p, h = Math.min(n + 1, d - t), e[f] = 1, k = 1; k < h; k++) { - if ((p = b[this.rtl ? d - 1 - t - k : t + k]) && !e[p]) { + if (Q(this, m, p, f, a, c), n && 1 < d && r < d - 1) { + for (e = z(), g = this.U, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) { + if ((p = b[this.rtl ? d - 1 - r - k : r + k]) && !e[p]) { e[p] = 1; - const r = this.score ? this.score(b, f, t, p, k) : P(g + (d / 2 > g ? 0 : 1), d, t, h - 1, k - 1), x = this.bidirectional && p > f; - Q(this, l, x ? f : p, r, a, c, x ? p : f); + const t = this.score ? this.score(b, f, r, p, k) : P(g + (d / 2 > g ? 0 : 1), d, r, h - 1, k - 1), x = this.bidirectional && p > f; + Q(this, l, x ? f : p, t, a, c, x ? p : f); } } } @@ -678,17 +678,17 @@ function Ea(a, b, c, d, e, f) { for (let n = 0, q; n < a.length; n++) { if (q = a[n]) { if (m = q[l]) { - for (let t = 0, p; t < m.length; t++) { - if (p = m[t], !h[p]) { + for (let r = 0, p; r < m.length; r++) { + if (p = m[r], !h[p]) { if (h[p] = 1, c) { c--; } else { if (e) { d.push(p); } else { - const r = l + (n ? f : 0); - d[r] || (d[r] = []); - d[r].push(p); + const t = l + (n ? f : 0); + d[t] || (d[t] = []); + d[t].push(p); } if (b && ++g === b) { return d; @@ -769,13 +769,13 @@ function Fa(a, b, c, d, e) { if (!m || !m.length) { return []; } - let n = z(), q = 0, t = l === a.length - 1; - for (let p = 0, r; p < k; p++) { - if (r = m[p]) { - for (let x = 0, A, w; x < r.length; x++) { - if (A = r[x], !l) { + let n = z(), q = 0, r = l === a.length - 1; + for (let p = 0, t; p < k; p++) { + if (t = m[p]) { + for (let x = 0, A, w; x < t.length; x++) { + if (A = t[x], !l) { n[A] = p + 1 + (l ? e : 0), q = 1; - } else if (t) { + } else if (r) { if (w = h[A]) { if (q = 1, c) { c--; @@ -997,14 +997,13 @@ S.prototype.resolve = function(a, b, c) { return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), R(d, a || 100, b, c)) : d; }; function Ia(a, b, c, d, e) { - const f = a.length; - let g = [], h, k; - h = z(); - for (let l = 0, m, n, q, t; l < b; l++) { - for (let p = 0; p < f; p++) { - if (q = a[p], l < q.length && (m = q[l])) { - for (let r = 0; r < m.length; r++) { - n = m[r], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), t = g[k] || (g[k] = []), t.push(n); + var f = a.length, g = [], h; + var k = z(); + for (let n = 0, q, r, p, t; n < b; n++) { + for (var l = 0; l < f; l++) { + if (p = a[l], n < p.length && (q = p[n])) { + for (var m = 0; m < q.length; m++) { + r = q[m], (h = k[r]) ? k[r]++ : (h = 0, k[r] = 1), t = g[h] || (g[h] = []), t.push(r); } } } @@ -1012,21 +1011,43 @@ function Ia(a, b, c, d, e) { if (a = g.length) { if (e) { e = []; - for (let l = a - 1, m = 0, n, q; 0 <= l; l--) { - if (n = g[l], q = n.length, d >= q) { - d -= q; + for (let n = a - 1, q = 0, r, p; 0 <= n; n--) { + if (r = g[n], p = r.length, d >= p) { + d -= p; } else { - if (q + m > c || d) { - n = n.slice(d, c - m + d), q = n.length; + if (p + q > c || d) { + r = r.slice(d, c - q + d), p = r.length; } - e.push(n); - m += q; - if (c === m) { + e.push(r); + q += p; + if (c === q) { break; } } } - g = 1 < e.length ? [].concat.apply([], e) : e[0]; + if (1 < e.length) { + g = e; + e = []; + f = z(); + k = g.length; + for (l = 0; l < k; l++) { + for (a = g[l], h = a.length, m = 0; m < h; m++) { + if (b = a[m], !f[b]) { + if (f[b] = 1, d) { + d--; + } else { + if (e.push(b), e.length === c) { + break; + } + } + } + } + } + c = e; + } else { + c = e[0]; + } + g = c; } else { if (a < f) { return []; @@ -1081,11 +1102,11 @@ O.prototype.search = function(a, b, c) { } let n = c = 0; if (1 < e) { - const p = z(), r = []; + const p = z(), t = []; for (let x = 0, A; x < e; x++) { if ((A = a[x]) && !p[A]) { if (f || this.db || V(this, A)) { - r.push(A), p[A] = 1; + t.push(A), p[A] = 1; } else { return h ? d : new S(d); } @@ -1094,37 +1115,37 @@ O.prototype.search = function(a, b, c) { n = n ? Math.min(n, w) : w; } } - a = r; + a = t; e = a.length; } if (!e) { return h ? d : new S(d); } - let q = 0, t; + let q = 0, r; if (1 === e) { return U.call(this, a[0], "", b, g, h, k, l); } if (2 === e && m && !f) { return U.call(this, a[0], a[1], b, g, h, k, l); } - 1 < e && (m ? (t = a[0], q = 1) : 9 < c && 3 < c / n && a.sort(aa)); + 1 < e && (m ? (r = a[0], q = 1) : 9 < c && 3 < c / n && a.sort(aa)); if (this.db) { if (this.db.search && (m = this.db.search(this, a, b, g, f, h, k, l), !1 !== m)) { return m; } const p = this; return async function() { - for (let r, x; q < e; q++) { + for (let t, x; q < e; q++) { x = a[q]; - t ? (r = await V(p, x, t), r = Ka(r, d, f, p.U, b, g, 2 === e), f && !1 === r && d.length || (t = x)) : (r = await V(p, x), r = Ka(r, d, f, p.resolution, b, g, 1 === e)); - if (r) { - return r; + r ? (t = await V(p, x, r), t = Ka(t, d, f, p.U, b, g, 2 === e), f && !1 === t && d.length || (r = x)) : (t = await V(p, x), t = Ka(t, d, f, p.resolution, b, g, 1 === e)); + if (t) { + return t; } if (f && q === e - 1) { let A = d.length; if (!A) { - if (t) { - t = ""; + if (r) { + r = ""; q = -1; continue; } @@ -1138,17 +1159,17 @@ O.prototype.search = function(a, b, c) { return h ? Ia(d, p.resolution, b, g, f) : new S(d[0]); }(); } - for (let p, r; q < e; q++) { - r = a[q]; - t ? (p = V(this, r, t), p = Ka(p, d, f, this.U, b, g, 2 === e), f && !1 === p && d.length || (t = r)) : (p = V(this, r), p = Ka(p, d, f, this.resolution, b, g, 1 === e)); + for (let p, t; q < e; q++) { + t = a[q]; + r ? (p = V(this, t, r), p = Ka(p, d, f, this.U, b, g, 2 === e), f && !1 === p && d.length || (r = t)) : (p = V(this, t), p = Ka(p, d, f, this.resolution, b, g, 1 === e)); if (p) { return p; } if (f && q === e - 1) { m = d.length; if (!m) { - if (t) { - t = ""; + if (r) { + r = ""; q = -1; continue; } @@ -1597,7 +1618,7 @@ function Qa(a, b, c, d, e, f, g, h) { k = g || c.field || c.index; var n = this.tag && c.tag; var q = this.store && c.enrich; - var t = c.suggest; + var r = c.suggest; b = c.limit || b; l = c.offset || 0; b || (b = 100); @@ -1610,18 +1631,18 @@ function Qa(a, b, c, d, e, f, g, h) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (v.field && v.tag) { - var r = v.tag; - if (r.constructor === Array) { - for (var x = 0; x < r.length; x++) { - p.push(v.field, r[x]); + var t = v.tag; + if (t.constructor === Array) { + for (var x = 0; x < t.length; x++) { + p.push(v.field, t[x]); } } else { - p.push(v.field, r); + p.push(v.field, t); } } else { - r = Object.keys(v); - for (let I = 0, J, D; I < r.length; I++) { - if (J = r[I], D = v[J], D.constructor === Array) { + t = Object.keys(v); + for (let I = 0, J, D; I < t.length; I++) { + if (J = t[I], D = v[J], D.constructor === Array) { for (x = 0; x < D.length; x++) { p.push(J, D[x]); } @@ -1636,7 +1657,7 @@ function Qa(a, b, c, d, e, f, g, h) { } n = p; if (!a) { - t = []; + r = []; if (p.length) { for (n = 0; n < p.length; n += 2) { if (this.db) { @@ -1645,14 +1666,14 @@ function Qa(a, b, c, d, e, f, g, h) { console.warn("Tag '" + p[n] + ":" + p[n + 1] + "' will be skipped because there is no field '" + p[n] + "'."); continue; } - t.push(d = d.db.tag(p[n + 1], b, l, q)); + r.push(d = d.db.tag(p[n + 1], b, l, q)); } else { d = Sa.call(this, p[n], p[n + 1], b, l, q); } e.push({field:p[n], tag:p[n + 1], result:d}); } } - return t.length ? Promise.all(t).then(function(w) { + return r.length ? Promise.all(r).then(function(w) { for (let v = 0; v < w.length; v++) { e[v].result = w[v]; } @@ -1671,29 +1692,29 @@ function Qa(a, b, c, d, e, f, g, h) { continue; } let D; - B(I) || (D = I, I = D.field, a = D.query || a, b = D.limit || b, t = D.suggest || t); + B(I) || (D = I, I = D.field, a = D.query || a, b = D.limit || b, r = D.suggest || r); if (d) { v = d[w]; } else { - if (r = D || c, x = this.index.get(I), n && (this.db && (r.tag = n, A = x.db.Z, r.field = k), A || (r.enrich = !1)), p) { - p[w] = x.searchAsync(a, b, r); - r && q && (r.enrich = q); + if (t = D || c, x = this.index.get(I), n && (this.db && (t.tag = n, A = x.db.Z, t.field = k), A || (t.enrich = !1)), p) { + p[w] = x.searchAsync(a, b, t); + t && q && (t.enrich = q); continue; } else { - v = x.search(a, b, r), r && q && (r.enrich = q); + v = x.search(a, b, t), t && q && (t.enrich = q); } } J = v && v.length; if (n && J) { - r = []; + t = []; x = 0; if (this.db && d) { if (!A) { for (let E = k.length; E < d.length; E++) { let F = d[E]; if (F && F.length) { - x++, r.push(F); - } else if (!t) { + x++, t.push(F); + } else if (!r) { return e; } } @@ -1702,23 +1723,23 @@ function Qa(a, b, c, d, e, f, g, h) { for (let E = 0, F, bb; E < n.length; E += 2) { F = this.tag.get(n[E]); if (!F) { - if (console.warn("Tag '" + n[E] + ":" + n[E + 1] + "' will be skipped because there is no field '" + n[E] + "'."), t) { + if (console.warn("Tag '" + n[E] + ":" + n[E + 1] + "' will be skipped because there is no field '" + n[E] + "'."), r) { continue; } else { return e; } } if (bb = (F = F && F.get(n[E + 1])) && F.length) { - x++, r.push(F); - } else if (!t) { + x++, t.push(F); + } else if (!r) { return e; } } } if (x) { - v = Ja(v, r); + v = Ja(v, t); J = v.length; - if (!J && !t) { + if (!J && !r) { return e; } x--; @@ -1735,7 +1756,7 @@ function Qa(a, b, c, d, e, f, g, h) { for (q = 0; q < n.length; q += 2) { d = this.index.get(n[q]); if (!d) { - if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), t) { + if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), r) { continue; } else { return e; @@ -2229,14 +2250,14 @@ u.commit = async function(a, b, c) { var n; if (m && m.length) { const q = Math.max(m.length, l.length); - for (let t = 0, p, r; t < q; t++) { - if ((r = l[t]) && r.length) { - if ((p = m[t]) && p.length) { - for (n = 0; n < r.length; n++) { - p.push(r[n]); + for (let r = 0, p, t; r < q; r++) { + if ((t = l[r]) && t.length) { + if ((p = m[r]) && p.length) { + for (n = 0; n < t.length; n++) { + p.push(t[n]); } } else { - m[t] = r; + m[r] = t; } n = 1; } diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index d016782..47ac4b5 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -27,23 +27,23 @@ function J(a){if(!this)return new J(a);this.index=a?[a]:[];this.length=a?a.lengt function K(a=8){if(!this)return new K(a);this.index=z();this.C=[];this.size=0;32f;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,t,g,f):P(q,d,t,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,t,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,r,a,c,x?p:f)}}}}this.fastupdate||this.A.add(a)}else b=""}this.db&&(b|| +function xa(a){let b=BigInt(2)**this.B-BigInt(1);var c=typeof a;if("bigint"===c)return a&b;if("number"===c)return BigInt(a)&b;c=BigInt(0);let d=this.B+BigInt(1);for(let e=0;ef;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,r,g,f):P(q,d,r,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.A.add(a)}else b=""}this.db&&(b|| this.K.push({del:a}),this.W&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.F:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.A.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.A.get(e))?d.push(h):a.A.set(e,[h]))}} function P(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Da(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Da(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length)return e?R(a[0],b,c,d):a[0];d=[];let g=0,h=z(),k=da(a);for(let l=0,m;la.length)return e?R(a[0],b,c,d):a[0];d=[];let g=0,h=z(),k=da(a);for(let l=0,m;la.length)return[];let f=[],g=0,h=z(),k=da(a);if(!k)return f;for(let l=0,m;la.length)return[];let f=[],g=0,h=z(),k=da(a);if(!k)return f;for(let l=0,m;la.length)return e?R(a[0],b,c,d):a[0];b=[];c=z();for(let g=0,h;g=q)d-=q;else{if(q+m>c||d)n=n.slice(d,c-m+d),q=n.length;e.push(n);m+=q;if(c===m)break}g=1c||d)g=g.slice(d,c+d)}return g} -function Ja(a,b){const c=z(),d=z(),e=[];for(let f=0;f=p)d-=p;else{if(p+q>c||d)r=r.slice(d,c-q+d),p=r.length;e.push(r);q+=p;if(c===q)break}if(1c||d)g=g.slice(d,c+d)}return g}function Ja(a,b){const c=z(),d=z(),e=[];for(let f=0;f=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.F.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.A.size&&(this.fastupdate?this.A.get(a):this.A.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.F,a);b||this.A.delete(a)}this.db&&(this.K.push({del:a}),this.W&&Ca(this));this.cache&&this.cache.remove(a);return this}; function La(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc||d)a=a.slice(d,d+c);e&&(a=Ta.call(this,a));return a}} function Ta(a){const b=Array(a.length);for(let c=0,d;c{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})}; u.commit=async function(a,b,c){if(b)await this.clear(),a.K=[];else{let d=a.K;a.K=[];for(let e=0,f;em&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const ab={Index:O,Charset:va,Encoder:F,Document:Y,Worker:W,Resolver:S,IndexedDB:Ya,Language:{}},cb=self;let db;(db=cb.define)&&db.amd?db([],function(){return ab}):"object"===typeof cb.exports?cb.exports=ab:cb.FlexSearch=ab;}(this)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index 39707d1..387f2a4 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -498,18 +498,18 @@ O.prototype.add = function(a, b, c, d) { b = this.encoder.encode(b); if (d = b.length) { const l = z(), m = z(), n = this.depth, q = this.resolution; - for (let t = 0; t < d; t++) { - let p = b[this.rtl ? d - 1 - t : t]; + for (let r = 0; r < d; r++) { + let p = b[this.rtl ? d - 1 - r : r]; var e = p.length; if (e && (n || !m[p])) { - var f = this.score ? this.score(b, p, t, null, 0) : P(q, d, t), g = ""; + var f = this.score ? this.score(b, p, r, null, 0) : P(q, d, r), g = ""; switch(this.tokenize) { case "full": if (2 < e) { for (f = 0; f < e; f++) { for (var h = e; h > f; h--) { g = p.substring(f, h); - var k = this.score ? this.score(b, p, t, g, f) : P(q, d, t, e, f); + var k = this.score ? this.score(b, p, r, g, f) : P(q, d, r, e, f); Q(this, m, g, k, a, c); } } @@ -518,7 +518,7 @@ O.prototype.add = function(a, b, c, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - g = p[h] + g, k = this.score ? this.score(b, p, t, g, h) : P(q, d, t, e, h), Q(this, m, g, k, a, c); + g = p[h] + g, k = this.score ? this.score(b, p, r, g, h) : P(q, d, r, e, h), Q(this, m, g, k, a, c); } g = ""; } @@ -530,12 +530,12 @@ O.prototype.add = function(a, b, c, d) { break; } default: - if (Q(this, m, p, f, a, c), n && 1 < d && t < d - 1) { - for (e = z(), g = this.U, f = p, h = Math.min(n + 1, d - t), e[f] = 1, k = 1; k < h; k++) { - if ((p = b[this.rtl ? d - 1 - t - k : t + k]) && !e[p]) { + if (Q(this, m, p, f, a, c), n && 1 < d && r < d - 1) { + for (e = z(), g = this.U, f = p, h = Math.min(n + 1, d - r), e[f] = 1, k = 1; k < h; k++) { + if ((p = b[this.rtl ? d - 1 - r - k : r + k]) && !e[p]) { e[p] = 1; - const r = this.score ? this.score(b, f, t, p, k) : P(g + (d / 2 > g ? 0 : 1), d, t, h - 1, k - 1), x = this.bidirectional && p > f; - Q(this, l, x ? f : p, r, a, c, x ? p : f); + const t = this.score ? this.score(b, f, r, p, k) : P(g + (d / 2 > g ? 0 : 1), d, r, h - 1, k - 1), x = this.bidirectional && p > f; + Q(this, l, x ? f : p, t, a, c, x ? p : f); } } } @@ -677,17 +677,17 @@ function Ea(a, b, c, d, e, f) { for (let n = 0, q; n < a.length; n++) { if (q = a[n]) { if (m = q[l]) { - for (let t = 0, p; t < m.length; t++) { - if (p = m[t], !h[p]) { + for (let r = 0, p; r < m.length; r++) { + if (p = m[r], !h[p]) { if (h[p] = 1, c) { c--; } else { if (e) { d.push(p); } else { - const r = l + (n ? f : 0); - d[r] || (d[r] = []); - d[r].push(p); + const t = l + (n ? f : 0); + d[t] || (d[t] = []); + d[t].push(p); } if (b && ++g === b) { return d; @@ -768,13 +768,13 @@ function Fa(a, b, c, d, e) { if (!m || !m.length) { return []; } - let n = z(), q = 0, t = l === a.length - 1; - for (let p = 0, r; p < k; p++) { - if (r = m[p]) { - for (let x = 0, A, w; x < r.length; x++) { - if (A = r[x], !l) { + let n = z(), q = 0, r = l === a.length - 1; + for (let p = 0, t; p < k; p++) { + if (t = m[p]) { + for (let x = 0, A, w; x < t.length; x++) { + if (A = t[x], !l) { n[A] = p + 1 + (l ? e : 0), q = 1; - } else if (t) { + } else if (r) { if (w = h[A]) { if (q = 1, c) { c--; @@ -996,14 +996,13 @@ S.prototype.resolve = function(a, b, c) { return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), R(d, a || 100, b, c)) : d; }; function Ia(a, b, c, d, e) { - const f = a.length; - let g = [], h, k; - h = z(); - for (let l = 0, m, n, q, t; l < b; l++) { - for (let p = 0; p < f; p++) { - if (q = a[p], l < q.length && (m = q[l])) { - for (let r = 0; r < m.length; r++) { - n = m[r], (k = h[n]) ? h[n]++ : (k = 0, h[n] = 1), t = g[k] || (g[k] = []), t.push(n); + var f = a.length, g = [], h; + var k = z(); + for (let n = 0, q, r, p, t; n < b; n++) { + for (var l = 0; l < f; l++) { + if (p = a[l], n < p.length && (q = p[n])) { + for (var m = 0; m < q.length; m++) { + r = q[m], (h = k[r]) ? k[r]++ : (h = 0, k[r] = 1), t = g[h] || (g[h] = []), t.push(r); } } } @@ -1011,21 +1010,43 @@ function Ia(a, b, c, d, e) { if (a = g.length) { if (e) { e = []; - for (let l = a - 1, m = 0, n, q; 0 <= l; l--) { - if (n = g[l], q = n.length, d >= q) { - d -= q; + for (let n = a - 1, q = 0, r, p; 0 <= n; n--) { + if (r = g[n], p = r.length, d >= p) { + d -= p; } else { - if (q + m > c || d) { - n = n.slice(d, c - m + d), q = n.length; + if (p + q > c || d) { + r = r.slice(d, c - q + d), p = r.length; } - e.push(n); - m += q; - if (c === m) { + e.push(r); + q += p; + if (c === q) { break; } } } - g = 1 < e.length ? [].concat.apply([], e) : e[0]; + if (1 < e.length) { + g = e; + e = []; + f = z(); + k = g.length; + for (l = 0; l < k; l++) { + for (a = g[l], h = a.length, m = 0; m < h; m++) { + if (b = a[m], !f[b]) { + if (f[b] = 1, d) { + d--; + } else { + if (e.push(b), e.length === c) { + break; + } + } + } + } + } + c = e; + } else { + c = e[0]; + } + g = c; } else { if (a < f) { return []; @@ -1080,11 +1101,11 @@ O.prototype.search = function(a, b, c) { } let n = c = 0; if (1 < e) { - const p = z(), r = []; + const p = z(), t = []; for (let x = 0, A; x < e; x++) { if ((A = a[x]) && !p[A]) { if (f || this.db || V(this, A)) { - r.push(A), p[A] = 1; + t.push(A), p[A] = 1; } else { return h ? d : new S(d); } @@ -1093,37 +1114,37 @@ O.prototype.search = function(a, b, c) { n = n ? Math.min(n, w) : w; } } - a = r; + a = t; e = a.length; } if (!e) { return h ? d : new S(d); } - let q = 0, t; + let q = 0, r; if (1 === e) { return U.call(this, a[0], "", b, g, h, k, l); } if (2 === e && m && !f) { return U.call(this, a[0], a[1], b, g, h, k, l); } - 1 < e && (m ? (t = a[0], q = 1) : 9 < c && 3 < c / n && a.sort(aa)); + 1 < e && (m ? (r = a[0], q = 1) : 9 < c && 3 < c / n && a.sort(aa)); if (this.db) { if (this.db.search && (m = this.db.search(this, a, b, g, f, h, k, l), !1 !== m)) { return m; } const p = this; return async function() { - for (let r, x; q < e; q++) { + for (let t, x; q < e; q++) { x = a[q]; - t ? (r = await V(p, x, t), r = Ka(r, d, f, p.U, b, g, 2 === e), f && !1 === r && d.length || (t = x)) : (r = await V(p, x), r = Ka(r, d, f, p.resolution, b, g, 1 === e)); - if (r) { - return r; + r ? (t = await V(p, x, r), t = Ka(t, d, f, p.U, b, g, 2 === e), f && !1 === t && d.length || (r = x)) : (t = await V(p, x), t = Ka(t, d, f, p.resolution, b, g, 1 === e)); + if (t) { + return t; } if (f && q === e - 1) { let A = d.length; if (!A) { - if (t) { - t = ""; + if (r) { + r = ""; q = -1; continue; } @@ -1137,17 +1158,17 @@ O.prototype.search = function(a, b, c) { return h ? Ia(d, p.resolution, b, g, f) : new S(d[0]); }(); } - for (let p, r; q < e; q++) { - r = a[q]; - t ? (p = V(this, r, t), p = Ka(p, d, f, this.U, b, g, 2 === e), f && !1 === p && d.length || (t = r)) : (p = V(this, r), p = Ka(p, d, f, this.resolution, b, g, 1 === e)); + for (let p, t; q < e; q++) { + t = a[q]; + r ? (p = V(this, t, r), p = Ka(p, d, f, this.U, b, g, 2 === e), f && !1 === p && d.length || (r = t)) : (p = V(this, t), p = Ka(p, d, f, this.resolution, b, g, 1 === e)); if (p) { return p; } if (f && q === e - 1) { m = d.length; if (!m) { - if (t) { - t = ""; + if (r) { + r = ""; q = -1; continue; } @@ -1596,7 +1617,7 @@ function Qa(a, b, c, d, e, f, g, h) { k = g || c.field || c.index; var n = this.tag && c.tag; var q = this.store && c.enrich; - var t = c.suggest; + var r = c.suggest; b = c.limit || b; l = c.offset || 0; b || (b = 100); @@ -1609,18 +1630,18 @@ function Qa(a, b, c, d, e, f, g, h) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (v.field && v.tag) { - var r = v.tag; - if (r.constructor === Array) { - for (var x = 0; x < r.length; x++) { - p.push(v.field, r[x]); + var t = v.tag; + if (t.constructor === Array) { + for (var x = 0; x < t.length; x++) { + p.push(v.field, t[x]); } } else { - p.push(v.field, r); + p.push(v.field, t); } } else { - r = Object.keys(v); - for (let I = 0, J, D; I < r.length; I++) { - if (J = r[I], D = v[J], D.constructor === Array) { + t = Object.keys(v); + for (let I = 0, J, D; I < t.length; I++) { + if (J = t[I], D = v[J], D.constructor === Array) { for (x = 0; x < D.length; x++) { p.push(J, D[x]); } @@ -1635,7 +1656,7 @@ function Qa(a, b, c, d, e, f, g, h) { } n = p; if (!a) { - t = []; + r = []; if (p.length) { for (n = 0; n < p.length; n += 2) { if (this.db) { @@ -1644,14 +1665,14 @@ function Qa(a, b, c, d, e, f, g, h) { console.warn("Tag '" + p[n] + ":" + p[n + 1] + "' will be skipped because there is no field '" + p[n] + "'."); continue; } - t.push(d = d.db.tag(p[n + 1], b, l, q)); + r.push(d = d.db.tag(p[n + 1], b, l, q)); } else { d = Sa.call(this, p[n], p[n + 1], b, l, q); } e.push({field:p[n], tag:p[n + 1], result:d}); } } - return t.length ? Promise.all(t).then(function(w) { + return r.length ? Promise.all(r).then(function(w) { for (let v = 0; v < w.length; v++) { e[v].result = w[v]; } @@ -1670,29 +1691,29 @@ function Qa(a, b, c, d, e, f, g, h) { continue; } let D; - B(I) || (D = I, I = D.field, a = D.query || a, b = D.limit || b, t = D.suggest || t); + B(I) || (D = I, I = D.field, a = D.query || a, b = D.limit || b, r = D.suggest || r); if (d) { v = d[w]; } else { - if (r = D || c, x = this.index.get(I), n && (this.db && (r.tag = n, A = x.db.Z, r.field = k), A || (r.enrich = !1)), p) { - p[w] = x.searchAsync(a, b, r); - r && q && (r.enrich = q); + if (t = D || c, x = this.index.get(I), n && (this.db && (t.tag = n, A = x.db.Z, t.field = k), A || (t.enrich = !1)), p) { + p[w] = x.searchAsync(a, b, t); + t && q && (t.enrich = q); continue; } else { - v = x.search(a, b, r), r && q && (r.enrich = q); + v = x.search(a, b, t), t && q && (t.enrich = q); } } J = v && v.length; if (n && J) { - r = []; + t = []; x = 0; if (this.db && d) { if (!A) { for (let E = k.length; E < d.length; E++) { let F = d[E]; if (F && F.length) { - x++, r.push(F); - } else if (!t) { + x++, t.push(F); + } else if (!r) { return e; } } @@ -1701,23 +1722,23 @@ function Qa(a, b, c, d, e, f, g, h) { for (let E = 0, F, Za; E < n.length; E += 2) { F = this.tag.get(n[E]); if (!F) { - if (console.warn("Tag '" + n[E] + ":" + n[E + 1] + "' will be skipped because there is no field '" + n[E] + "'."), t) { + if (console.warn("Tag '" + n[E] + ":" + n[E + 1] + "' will be skipped because there is no field '" + n[E] + "'."), r) { continue; } else { return e; } } if (Za = (F = F && F.get(n[E + 1])) && F.length) { - x++, r.push(F); - } else if (!t) { + x++, t.push(F); + } else if (!r) { return e; } } } if (x) { - v = Ja(v, r); + v = Ja(v, t); J = v.length; - if (!J && !t) { + if (!J && !r) { return e; } x--; @@ -1734,7 +1755,7 @@ function Qa(a, b, c, d, e, f, g, h) { for (q = 0; q < n.length; q += 2) { d = this.index.get(n[q]); if (!d) { - if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), t) { + if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), r) { continue; } else { return e; @@ -2228,14 +2249,14 @@ u.commit = async function(a, b, c) { var n; if (m && m.length) { const q = Math.max(m.length, l.length); - for (let t = 0, p, r; t < q; t++) { - if ((r = l[t]) && r.length) { - if ((p = m[t]) && p.length) { - for (n = 0; n < r.length; n++) { - p.push(r[n]); + for (let r = 0, p, t; r < q; r++) { + if ((t = l[r]) && t.length) { + if ((p = m[r]) && p.length) { + for (n = 0; n < t.length; n++) { + p.push(t[n]); } } else { - m[t] = r; + m[r] = t; } n = 1; } diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index a21d42b..b4eeeb8 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -27,23 +27,23 @@ function J(a){if(!this)return new J(a);this.index=a?[a]:[];this.length=a?a.lengt function K(a=8){if(!this)return new K(a);this.index=z();this.C=[];this.size=0;32f;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,t,g,f):P(q,d,t,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,t,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,r,a,c,x?p:f)}}}}this.fastupdate||this.A.add(a)}else b=""}this.db&&(b|| +function xa(a){let b=BigInt(2)**this.B-BigInt(1);var c=typeof a;if("bigint"===c)return a&b;if("number"===c)return BigInt(a)&b;c=BigInt(0);let d=this.B+BigInt(1);for(let e=0;ef;h--){g=p.substring(f,h);var k=this.score?this.score(b,p,r,g,f):P(q,d,r,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,r,h-1,k-1),x=this.bidirectional&&p>f;Q(this,l,x?f:p,t,a,c,x?p:f)}}}}this.fastupdate||this.A.add(a)}else b=""}this.db&&(b|| this.K.push({del:a}),this.W&&Ca(this));return this};function Q(a,b,c,d,e,f,g){let h=g?a.F:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=z()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new J(h);if(a.fastupdate)for(let l of a.A.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.A.get(e))?d.push(h):a.A.set(e,[h]))}} function P(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Da(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Da(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length)return e?R(a[0],b,c,d):a[0];d=[];let g=0,h=z(),k=da(a);for(let l=0,m;la.length)return e?R(a[0],b,c,d):a[0];d=[];let g=0,h=z(),k=da(a);for(let l=0,m;la.length)return[];let f=[],g=0,h=z(),k=da(a);if(!k)return f;for(let l=0,m;la.length)return[];let f=[],g=0,h=z(),k=da(a);if(!k)return f;for(let l=0,m;la.length)return e?R(a[0],b,c,d):a[0];b=[];c=z();for(let g=0,h;g=q)d-=q;else{if(q+m>c||d)n=n.slice(d,c-m+d),q=n.length;e.push(n);m+=q;if(c===m)break}g=1c||d)g=g.slice(d,c+d)}return g} -function Ja(a,b){const c=z(),d=z(),e=[];for(let f=0;f=p)d-=p;else{if(p+q>c||d)r=r.slice(d,c-q+d),p=r.length;e.push(r);q+=p;if(c===q)break}if(1c||d)g=g.slice(d,c+d)}return g}function Ja(a,b){const c=z(),d=z(),e=[];for(let f=0;f=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function V(a,b,c,d,e,f,g,h){let k;c&&(k=a.bidirectional&&b>c);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.F.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};O.prototype.remove=function(a,b){const c=this.A.size&&(this.fastupdate?this.A.get(a):this.A.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else La(this.map,a),this.depth&&La(this.F,a);b||this.A.delete(a)}this.db&&(this.K.push({del:a}),this.W&&Ca(this));this.cache&&this.cache.remove(a);return this}; function La(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc||d)a=a.slice(d,d+c);e&&(a=Ta.call(this,a));return a}} function Ta(a){const b=Array(a.length);for(let c=0,d;c{e.onerror=h=>{this.h[a+":"+b]=null;e.abort();e=d=null;g(h)};e.oncomplete=h=>{e=d=this.h[a+":"+b]=null;f(h||!0)};return c.call(this,d)})}; u.commit=async function(a,b,c){if(b)await this.clear(),a.K=[];else{let d=a.K;a.K=[];for(let e=0,f;em&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:O,Charset:va,Encoder:F,Document:Y,Worker:W,Resolver:S,IndexedDB:Ya,Language:{}}; diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 62785f9..a029b8c 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -510,7 +510,29 @@ function O(a, c, b, e, d) { } } } - g = 1 < e.length ? [].concat.apply([], e) : e[0]; + if (1 < e.length) { + g = e; + a = []; + e = y(); + f = g.length; + for (k = 0; k < f; k++) { + for (m = g[k], h = m.length, l = 0; l < h; l++) { + if (b = m[l], !e[b]) { + if (e[b] = 1, d) { + d--; + } else { + if (a.push(b), a.length === c) { + break; + } + } + } + } + } + c = a; + } else { + c = e[0]; + } + g = c; } else { if (a < b) { e = []; diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 50c1a5b..f947a83 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -25,8 +25,9 @@ g||"w"===g||!(g=ma[g])||g===d||(e+=g,d=g,4!==e.length));f++);a[c]=e}}},ArabicDef d){for(h=d-1;0g?0:1),e,p,h-1,k-1),B=this.bidirectional&&n>f;O(this,l,B?f:n,w,a,c,B?n:f)}}}}this.fastupdate||this.h.add(a)}}return this}; function O(a,b,c,e,d,f,g){let h=g?a.D:a.map,k;b[c]&&g&&(k=b[c])[g]||(g?(b=k||(b[c]=y()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((b=a.h.get(d))?b.push(h):a.h.set(d,[h]))))}function N(a,b,c,e,d){return c&&1b?b?a.slice(c,c+b):a.slice(c):a;let e=[];for(let d=0,f,g;d=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),f;e=[f]}b-=g;if(!b)break}return e.length?e=1=n)d-=n;else{if(n+t>b||d)p=p.slice(d,b-t+d),n=p.length;e.push(p);t+=n;if(b===t)break}g=1b||d)g=g.slice(d,b+d)}e=g}return e}; -function R(a,b,c,e){return(a=S(this,a,b))&&a.length?Q(a,c,e):[]}function va(a,b,c,e,d,f,g){let h=[];if(a){e=Math.min(a.length,e);for(let k=0,l=0,m;k=d)))break;if(h.length){if(g)return Q(h,d,0);b.push(h);return}}return!c&&h}function S(a,b,c){let e;c&&(e=a.bidirectional&&b>c);a=c?(a=a.D.get(e?b:c))&&a.get(e?c:b):a.map.get(b);return a};M.prototype.remove=function(a,b){const c=this.h.size&&(this.fastupdate?this.h.get(a):this.h.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else T(this.map,a),this.depth&&T(this.D,a);b||this.h.delete(a)}this.cache&&this.cache.remove(a);return this}; +for(let r=0,t,p,n,w;r=n)d-=n;else{if(n+t>b||d)p=p.slice(d,b-t+d),n=p.length;e.push(p);t+=n;if(b===t)break}if(1b||d)g=g.slice(d,b+d)}e=g}return e};function R(a,b,c,e){return(a=S(this,a,b))&&a.length?Q(a,c,e):[]}function va(a,b,c,e,d,f,g){let h=[];if(a){e=Math.min(a.length,e);for(let k=0,l=0,m;k=d)))break;if(h.length){if(g)return Q(h,d,0);b.push(h);return}}return!c&&h} +function S(a,b,c){let e;c&&(e=a.bidirectional&&b>c);a=c?(a=a.D.get(e?b:c))&&a.get(e?c:b):a.map.get(b);return a};M.prototype.remove=function(a,b){const c=this.h.size&&(this.fastupdate?this.h.get(a):this.h.has(a));if(c){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===c.length-1?d.pop():d.splice(f,1)}}else T(this.map,a),this.depth&&T(this.D,a);b||this.h.delete(a)}this.cache&&this.cache.remove(a);return this}; function T(a,b){let c=0;if(a.constructor===Array)for(let e=0,d,f;ec.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)}; function U(a){let b=0;if(a.constructor===Array)for(let c=0,e;c d; h--) { g = l.substring(d, h); - var k = this.score ? this.score(b, l, n, g, d) : P(t, e, n, f, d); + var k = this.score ? this.score(b, l, p, g, d) : P(t, e, p, f, d); Q(this, m, g, k, a, c); } } @@ -250,7 +250,7 @@ O.prototype.add = function(a, b, c, e) { case "reverse": if (1 < f) { for (h = f - 1; 0 < h; h--) { - g = l[h] + g, k = this.score ? this.score(b, l, n, g, h) : P(t, e, n, f, h), Q(this, m, g, k, a, c); + g = l[h] + g, k = this.score ? this.score(b, l, p, g, h) : P(t, e, p, f, h), Q(this, m, g, k, a, c); } g = ""; } @@ -262,12 +262,12 @@ O.prototype.add = function(a, b, c, e) { break; } default: - if (Q(this, m, l, d, a, c), r && 1 < e && n < e - 1) { - for (f = y(), g = this.K, d = l, h = Math.min(r + 1, e - n), f[d] = 1, k = 1; k < h; k++) { - if ((l = b[this.rtl ? e - 1 - n - k : n + k]) && !f[l]) { + if (Q(this, m, l, d, a, c), r && 1 < e && p < e - 1) { + for (f = y(), g = this.K, d = l, h = Math.min(r + 1, e - p), f[d] = 1, k = 1; k < h; k++) { + if ((l = b[this.rtl ? e - 1 - p - k : p + k]) && !f[l]) { f[l] = 1; - const w = this.score ? this.score(b, d, n, l, k) : P(g + (e / 2 > g ? 0 : 1), e, n, h - 1, k - 1), B = this.bidirectional && l > d; - Q(this, p, B ? d : l, w, a, c, B ? l : d); + const w = this.score ? this.score(b, d, p, l, k) : P(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), B = this.bidirectional && l > d; + Q(this, n, B ? d : l, w, a, c, B ? l : d); } } } @@ -351,16 +351,16 @@ function P(a, b, c, e, f) { } var h = 0, k = 0; if (1 < c) { - var p = y(); + var n = y(); const r = []; - for (let t = 0, n; t < c; t++) { - if ((n = a[t]) && !p[n]) { - if (g || T(this, n)) { - r.push(n), p[n] = 1; + for (let t = 0, p; t < c; t++) { + if ((p = a[t]) && !n[p]) { + if (g || T(this, p)) { + r.push(p), n[p] = 1; } else { return e; } - const l = n.length; + const l = p.length; h = Math.max(h, l); k = k ? Math.min(k, l) : l; } @@ -371,7 +371,7 @@ function P(a, b, c, e, f) { if (!c) { return e; } - p = 0; + n = 0; if (1 === c) { return S.call(this, a[0], "", b, f); } @@ -381,23 +381,23 @@ function P(a, b, c, e, f) { if (1 < c) { if (d) { var m = a[0]; - p = 1; + n = 1; } else { 9 < h && 3 < h / k && a.sort(aa); } } - for (let r, t; p < c; p++) { - t = a[p]; + for (let r, t; n < c; n++) { + t = a[n]; m ? (r = T(this, t, m), r = ra(r, e, g, this.K, b, f, 2 === c), g && !1 === r && e.length || (m = t)) : (r = T(this, t), r = ra(r, e, g, this.resolution, b, f, 1 === c)); if (r) { return r; } - if (g && p === c - 1) { + if (g && n === c - 1) { d = e.length; if (!d) { if (m) { m = ""; - p = -1; + n = -1; continue; } return e; @@ -414,11 +414,11 @@ function P(a, b, c, e, f) { c = a.length; g = []; d = y(); - for (let r = 0, t, n, l, w; r < e; r++) { + for (let r = 0, t, p, l, w; r < e; r++) { for (k = 0; k < c; k++) { if (l = a[k], r < l.length && (t = l[r])) { - for (p = 0; p < t.length; p++) { - n = t[p], (h = d[n]) ? d[n]++ : (h = 0, d[n] = 1), w = g[h] || (g[h] = []), w.push(n); + for (n = 0; n < t.length; n++) { + p = t[n], (h = d[p]) ? d[p]++ : (h = 0, d[p] = 1), w = g[h] || (g[h] = []), w.push(p); } } } @@ -426,21 +426,43 @@ function P(a, b, c, e, f) { if (a = g.length) { if (m) { e = []; - for (let r = a - 1, t = 0, n, l; 0 <= r; r--) { - if (n = g[r], l = n.length, f >= l) { + for (let r = a - 1, t = 0, p, l; 0 <= r; r--) { + if (p = g[r], l = p.length, f >= l) { f -= l; } else { if (l + t > b || f) { - n = n.slice(f, b - t + f), l = n.length; + p = p.slice(f, b - t + f), l = p.length; } - e.push(n); + e.push(p); t += l; if (b === t) { break; } } } - g = 1 < e.length ? [].concat.apply([], e) : e[0]; + if (1 < e.length) { + g = e; + a = []; + e = y(); + d = g.length; + for (k = 0; k < d; k++) { + for (m = g[k], h = m.length, n = 0; n < h; n++) { + if (c = m[n], !e[c]) { + if (e[c] = 1, f) { + f--; + } else { + if (a.push(c), a.length === b) { + break; + } + } + } + } + } + b = a; + } else { + b = e[0]; + } + g = b; } else { if (a < c) { e = []; @@ -463,9 +485,9 @@ function ra(a, b, c, e, f, d, g) { let h = []; if (a) { e = Math.min(a.length, e); - for (let k = 0, p = 0, m; k < e; k++) { + for (let k = 0, n = 0, m; k < e; k++) { if (m = a[k]) { - if (d && m && g && (m.length <= d ? (d -= m.length, m = null) : (m = m.slice(d), d = 0)), m && (h[k] = m, g && (p += m.length, p >= f))) { + if (d && m && g && (m.length <= d ? (d -= m.length, m = null) : (m = m.slice(d), d = 0)), m && (h[k] = m, g && (n += m.length, n >= f))) { break; } } @@ -598,8 +620,8 @@ v.cleanup = function() { }; v.export = function(a, b, c, e, f, d) { let g = !0; - "undefined" === typeof d && (g = new Promise(p => { - d = p; + "undefined" === typeof d && (g = new Promise(n => { + d = n; })); let h, k; switch(f || (f = 0)) { @@ -607,8 +629,8 @@ v.export = function(a, b, c, e, f, d) { h = "reg"; if (this.fastupdate) { k = y(); - for (let p of this.h.keys()) { - k[p] = 1; + for (let n of this.h.keys()) { + k[n] = 1; } } else { k = this.h; @@ -740,19 +762,19 @@ function X(a, b, c, e, f, d, g, h) { c || (!b && E(a) ? (c = a, a = "") : E(b) && (c = b, b = 0)); let f = []; var d = []; - let g, h, k, p, m; + let g, h, k, n, m; let r = 0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; var t = c.pluck; h = c.merge; - p = t || c.field || c.index; + n = t || c.field || c.index; m = !1; g = this.store && c.enrich; k = c.suggest; b = c.limit || b; - var n = c.offset || 0; + var p = c.offset || 0; b || (b = 100); if (m) { m.constructor !== Array && (m = [m]); @@ -792,7 +814,7 @@ function X(a, b, c, e, f, d, g, h) { e = []; if (l.length) { for (d = 0; d < l.length; d += 2) { - t = sa.call(this, l[d], l[d + 1], b, n, g), f.push({field:l[d], tag:l[d + 1], result:t}); + t = sa.call(this, l[d], l[d + 1], b, p, g), f.push({field:l[d], tag:l[d + 1], result:t}); } } return e.length ? Promise.all(e).then(function(u) { @@ -803,19 +825,19 @@ function X(a, b, c, e, f, d, g, h) { }) : f; } } - z(p) && (p = [p]); + z(n) && (n = [n]); } - p || (p = this.field); - n = !e && (this.worker || this.async) && []; - for (let u = 0, q, C, D; u < p.length; u++) { - C = p[u]; + n || (n = this.field); + p = !e && (this.worker || this.async) && []; + for (let u = 0, q, C, D; u < n.length; u++) { + C = n[u]; let A; z(C) || (A = C, C = A.field, a = A.query || a, b = A.limit || b, k = A.suggest || k); if (e) { q = e[u]; } else { - if (l = A || c, w = this.index.get(C), m && (l.enrich = !1), n) { - n[u] = w.searchAsync(a, b, l); + if (l = A || c, w = this.index.get(C), m && (l.enrich = !1), p) { + p[u] = w.searchAsync(a, b, l); l && g && (l.enrich = g); continue; } else { @@ -852,13 +874,13 @@ function X(a, b, c, e, f, d, g, h) { } if (D) { d[r] = C, f.push(q), r++; - } else if (1 === p.length) { + } else if (1 === n.length) { return f; } } - if (n) { + if (p) { const u = this; - return Promise.all(n).then(function(q) { + return Promise.all(p).then(function(q) { return q.length ? u.search(a, b, c, q) : q; }); } @@ -868,7 +890,7 @@ function X(a, b, c, e, f, d, g, h) { if (t && (!g || !this.store)) { return f[0]; } - n = []; + p = []; for (let u = 0, q; u < d.length; u++) { q = f[u]; g && q.length && !q[0].doc && q.length && (q = ta.call(this, q)); @@ -884,15 +906,15 @@ function va(a, b) { for (let f = 0, d, g; f < a.length; f++) { d = a[f]; g = d.result; - for (let h = 0, k, p, m; h < g.length; h++) { - if (p = g[h], k = p.id, m = e[k]) { + for (let h = 0, k, n, m; h < g.length; h++) { + if (n = g[h], k = n.id, m = e[k]) { m.push(d.field); } else { if (c.length === b) { return c; } - p.field = e[k] = [d.field]; - c.push(p); + n.field = e[k] = [d.field]; + c.push(n); } } } diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index f2f83ac..3c8e7bf 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -17,25 +17,26 @@ I.prototype.assign=function(a){this.normalize=x(a.normalize,!0,this.normalize);l x(a.prepare,null,this.prepare);this.finalize=x(a.finalize,null,this.finalize);H||(this.mapper=new Map(ba));this.rtl=a.rtl||!1;this.dedupe=x(a.dedupe,!0,this.dedupe);this.filter=x((c=a.filter)&&new Set(c),null,this.filter);this.matcher=x((c=a.matcher)&&new Map(c),null,this.matcher);this.mapper=x((c=a.mapper)&&new Map(c),null,this.mapper);this.stemmer=x((c=a.stemmer)&&new Map(c),null,this.stemmer);this.replacer=x(a.replacer,null,this.replacer);this.minlength=x(a.minlength,1,this.minlength);this.maxlength= x(a.maxlength,0,this.maxlength);this.F="";this.H=null;this.D="";this.I=null;if(this.matcher)for(const d of this.matcher.keys())this.F+=(this.F?"|":"")+d;if(this.stemmer)for(const d of this.stemmer.keys())this.D+=(this.D?"|":"")+d;return this}; I.prototype.encode=function(a){this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):H?a.normalize("NFKD").replace(H,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(h)),g=1);this.matcher&&1this.matcher.get(h)),g=1);f&&g&&(f.lengthf;h--){g=l.substring(f,h);var k=this.score?this.score(b,l,n,g,f):P(t,d,n,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,n,h-1,k-1),B=this.bidirectional&&l>f;Q(this,p,B?f:l,w,a,c,B?l:f)}}}}this.fastupdate||this.h.add(a)}}return this}; -function Q(a,b,c,d,e,f,g){let h=g?a.B:a.map,k;b[c]&&g&&(k=b[c])[g]||(g?(b=k||(b[c]=y()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=[]),h=h[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((b=a.h.get(e))?b.push(h):a.h.set(e,[h]))))}function P(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a;let d=[];for(let e=0,f,g;e=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),d.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),f;d=[f]}b-=g;if(!b)break}return d.length?d=1=l)e-=l;else{if(l+t>b||e)n=n.slice(e,b-t+e),l=n.length;d.push(n);t+=l;if(b===t)break}g=1b||e)g=g.slice(e,b+e)}d=g}return d}; -function S(a,b,c,d){return(a=T(this,a,b))&&a.length?R(a,c,d):[]}function ra(a,b,c,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,p=0,m;k=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h}function T(a,b,c){let d;c&&(d=a.bidirectional&&b>c);a=c?(a=a.B.get(d?b:c))&&a.get(d?c:b):a.map.get(b);return a};N.prototype.remove=function(a,b){const c=this.h.size&&(this.fastupdate?this.h.get(a):this.h.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else U(this.map,a),this.depth&&U(this.B,a);b||this.h.delete(a)}return this}; +this.minlength)continue;if(b){c.push(f);continue}if(this.filter&&this.filter.has(f))continue;let g;this.stemmer&&2this.stemmer.get(h)),g=1);this.matcher&&1this.matcher.get(h)),g=1);f&&g&&(f.lengthf;h--){g=l.substring(f,h);var k=this.score?this.score(b,l,p,g,f):P(t,d,p,e,f);Q(this,m,g,k,a,c)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,p,h-1,k-1),B=this.bidirectional&&l>f;Q(this,n,B?f:l,w,a,c,B?l:f)}}}}this.fastupdate||this.h.add(a)}}return this}; +function Q(a,b,c,d,e,f,g){let h=g?a.B:a.map,k;b[c]&&g&&(k=b[c])[g]||(g?(b=k||(b[c]=y()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=[]),h=h[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((b=a.h.get(e))?b.push(h):a.h.set(e,[h]))))}function P(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a;let d=[];for(let e=0,f,g;e=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),d.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),f;d=[f]}b-=g;if(!b)break}return d.length?d=1=l)e-=l;else{if(l+t>b||e)p=p.slice(e,b-t+e),l=p.length;d.push(p);t+=l;if(b===t)break}if(1b||e)g=g.slice(e,b+e)}d=g}return d};function S(a,b,c,d){return(a=T(this,a,b))&&a.length?R(a,c,d):[]}function ra(a,b,c,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,n=0,m;k=e)))break;if(h.length){if(g)return R(h,e,0);b.push(h);return}}return!c&&h} +function T(a,b,c){let d;c&&(d=a.bidirectional&&b>c);a=c?(a=a.B.get(d?b:c))&&a.get(d?c:b):a.map.get(b);return a};N.prototype.remove=function(a,b){const c=this.h.size&&(this.fastupdate?this.h.get(a):this.h.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else U(this.map,a),this.depth&&U(this.B,a);b||this.h.delete(a)}return this}; function U(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)}; function V(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=p}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let p of this.h.keys())k[p]=1}else k=this.h;break;case 1:h="cfg";k={doc:0,opt:this.F?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.B;break;default:"undefined"===typeof c&&f&&f();return}na(a,b||this,c,h,d,e,k,f);return g}; +v.export=function(a,b,c,d,e,f){let g=!0;"undefined"===typeof f&&(g=new Promise(n=>{f=n}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=y();for(let n of this.h.keys())k[n]=1}else k=this.h;break;case 1:h="cfg";k={doc:0,opt:this.F?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.B;break;default:"undefined"===typeof c&&f&&f();return}na(a,b||this,c,h,d,e,k,f);return g}; v.import=function(a,b){if(b)switch(A(b)&&(b=JSON.parse(b)),a){case "cfg":this.F=!!b.opt;break;case "reg":this.fastupdate=!1;this.h=b;break;case "map":this.map=b;break;case "ctx":this.B=b}};pa(N.prototype);W.prototype.add=function(a,b,c){E(a)&&(b=a,a=F(b,this.key));if(b&&(a||0===a)){if(!c&&this.h.has(a))return this.update(a,b);for(let e=0,f;ec||d)a=a.slice(d,d+c);e&&(a=ta.call(this,a));return a}} +function X(a,b,c,d,e,f,g,h){if(a=a[g])if(d===b.length-1){if(a.constructor===Array){if(c[d]){for(b=0;bc||d)a=a.slice(d,d+c);e&&(a=ta.call(this,a));return a}} function ta(a){const b=Array(a.length);for(let c=0,d;c>> 0) + "_", e = 0; return b; }); -C("Symbol.iterator", function(a) { +B("Symbol.iterator", function(a) { if (a) { return a; } @@ -247,7 +247,7 @@ function ta(a) { }; return a; } -C("Promise", function(a) { +B("Promise", function(a) { function b(f) { this.A = 0; this.C = void 0; @@ -489,7 +489,7 @@ function ua(a, b) { }; return e; } -C("Array.prototype.values", function(a) { +B("Array.prototype.values", function(a) { return a ? a : function() { return ua(this, function(b, c) { return c; @@ -499,7 +499,7 @@ C("Array.prototype.values", function(a) { function H(a, b) { return Object.prototype.hasOwnProperty.call(a, b); } -C("WeakMap", function(a) { +B("WeakMap", function(a) { function b(k) { this.h = (h += Math.random() + 1).toString(); if (k) { @@ -576,7 +576,7 @@ C("WeakMap", function(a) { }; return b; }); -C("Map", function(a) { +B("Map", function(a) { function b() { var h = {}; return h.K = h.next = h.head = h; @@ -689,14 +689,14 @@ C("Map", function(a) { var f = 0; return e; }); -C("Array.prototype.keys", function(a) { +B("Array.prototype.keys", function(a) { return a ? a : function() { return ua(this, function(b) { return b; }); }; }); -C("Set", function(a) { +B("Set", function(a) { function b(c) { this.h = new Map(); if (c) { @@ -762,12 +762,12 @@ C("Set", function(a) { }; return b; }); -C("Object.is", function(a) { +B("Object.is", function(a) { return a ? a : function(b, c) { return b === c ? 0 !== b || 1 / b === 1 / c : b !== b && c !== c; }; }); -C("Array.prototype.includes", function(a) { +B("Array.prototype.includes", function(a) { return a ? a : function(b, c) { var d = this; d instanceof String && (d = String(d)); @@ -782,7 +782,7 @@ C("Array.prototype.includes", function(a) { return !1; }; }); -C("String.prototype.includes", function(a) { +B("String.prototype.includes", function(a) { return a ? a : function(b, c) { if (null == this) { throw new TypeError("The 'this' value for String.prototype.includes must not be null or undefined"); @@ -793,7 +793,7 @@ C("String.prototype.includes", function(a) { return -1 !== this.indexOf(b, c || 0); }; }); -C("Array.prototype.entries", function(a) { +B("Array.prototype.entries", function(a) { return a ? a : function() { return ua(this, function(b, c) { return [b, c]; @@ -811,10 +811,10 @@ var va = "function" == typeof Object.assign ? Object.assign : function(a, b) { } return a; }; -C("Object.assign", function(a) { +B("Object.assign", function(a) { return a || va; }); -C("Array.prototype.flat", function(a) { +B("Array.prototype.flat", function(a) { return a ? a : function(b) { b = void 0 === b ? 1 : b; var c = []; @@ -1883,7 +1883,28 @@ function ib(a, b, c, d, e) { } } } - f = 1 < e.length ? [].concat.apply([], e) : e[0]; + if (1 < e.length) { + f = []; + g = K(); + k = e.length; + for (m = 0; m < k; m++) { + for (a = e[m], l = a.length, p = 0; p < l; p++) { + if (b = a[p], !g[b]) { + if (g[b] = 1, d) { + d--; + } else { + if (f.push(b), f.length === c) { + break; + } + } + } + } + } + c = f; + } else { + c = e[0]; + } + f = c; } else { if (a < g) { return []; @@ -1975,7 +1996,7 @@ V.prototype.search = function(a, b, c) { } var v = this; return function() { - var A, D, B; + var A, D, C; return sa(function(E) { switch(E.h) { case 1: @@ -1999,8 +2020,8 @@ V.prototype.search = function(a, b, c) { return E.return(A); } if (h && u === m - 1) { - B = d.length; - if (!B) { + C = d.length; + if (!C) { if (t) { t = ""; u = -1; @@ -2009,7 +2030,7 @@ V.prototype.search = function(a, b, c) { } return E.return(d); } - if (1 === B) { + if (1 === C) { return E.return(g ? W(d[0], b, e) : new X(d[0])); } } @@ -2513,8 +2534,8 @@ function tb(a, b, c, d, e, g, f, h) { v = 0; for (var A = void 0, D = void 0; v < t.length; v++) { if (A = t[v], D = u[A], D.constructor === Array) { - for (var B = 0; B < D.length; B++) { - r.push(A, D[B]); + for (var C = 0; C < D.length; C++) { + r.push(A, D[C]); } } else { r.push(A, D); @@ -2588,8 +2609,8 @@ function tb(a, b, c, d, e, g, f, h) { D = 0; if (this.db && d) { if (!E) { - for (B = l.length; B < d.length; B++) { - var J = d[B]; + for (C = l.length; C < d.length; C++) { + var J = d[C]; if (J && J.length) { D++, A.push(J); } else if (!p) { @@ -2598,17 +2619,17 @@ function tb(a, b, c, d, e, g, f, h) { } } } else { - B = 0; - for (var Gb = J = void 0; B < m.length; B += 2) { - J = this.tag.get(m[B]); + C = 0; + for (var Gb = J = void 0; C < m.length; C += 2) { + J = this.tag.get(m[C]); if (!J) { - if (console.warn("Tag '" + m[B] + ":" + m[B + 1] + "' will be skipped because there is no field '" + m[B] + "'."), p) { + if (console.warn("Tag '" + m[C] + ":" + m[C + 1] + "' will be skipped because there is no field '" + m[C] + "'."), p) { continue; } else { return e; } } - if (Gb = (J = J && J.get(m[B + 1])) && J.length) { + if (Gb = (J = J && J.get(m[C + 1])) && J.length) { D++, A.push(J); } else if (!p) { return e; @@ -3172,8 +3193,8 @@ w.commit = function(a, b, c) { for (var v = Math.max(u.length, r.T.length), A = 0, D; A < v; A++) { if ((D = r.T[A]) && D.length) { if ((t = u[A]) && t.length) { - for (var B = 0; B < D.length; B++) { - t.push(D[B]); + for (var C = 0; C < D.length; C++) { + t.push(D[C]); } } else { u[A] = D; diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 6b00621..5dc68ab 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -70,8 +70,8 @@ function eb(a,b,c,d,e){if(2>a.length)return[];var g=[],f=0,h=K(),k=za(a);if(!k)r f=l.enrich;h=l.resolve;continue}d[k]=m;m.then&&c.push(m)}if(c.length)return Promise.all(c).then(function(){a.result.length&&(d=[a.result].concat(d));a.result=fb(d,e,g,f,!h,a.M);return h?a.result:a});this.result.length&&(d=[this.result].concat(d));this.result=fb(d,e,g,f,!h,a.M);return h?this.result:this}; function fb(a,b,c,d,e,g){if(!a.length)return a;if(2>a.length)return e?W(a[0],b,c,d):a[0];b=[];c=K();d=0;for(var f;d=k)d-=k;else{if(k+a>c||d)b=b.slice(d,c-a+d),k=b.length;e.push(b);a+=k;if(c===a)break}f=1c||d)f=f.slice(d,c+d)}return f} -function jb(a,b){for(var c=K(),d=K(),e=[],g=0;g=k)d-=k;else{if(k+a>c||d)b=b.slice(d,c-a+d),k=b.length;e.push(b);a+=k;if(c===a)break}if(1c||d)f=f.slice(d,c+d)}return f}function jb(a,b){for(var c=K(),d=K(),e=[],g=0;g this.stemmer.get(r)), l = 1); - this.matcher && 1 < f.length && (this.v || (this.v = new RegExp("(" + this.s + ")", "g")), f = f.replace(this.v, r => this.matcher.get(r)), l = 1); - f && l && (f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); + let k; + this.stemmer && 2 < f.length && (this.A || (this.A = new RegExp("(?!^)(" + this.u + ")$")), f = f.replace(this.A, p => this.stemmer.get(p)), k = 1); + this.matcher && 1 < f.length && (this.v || (this.v = new RegExp("(" + this.s + ")", "g")), f = f.replace(this.v, p => this.matcher.get(p)), k = 1); + f && k && (f.length < this.minlength || this.filter && this.filter.has(f)) && (f = ""); if (f && (this.mapper || this.dedupe && 1 < f.length)) { e = ""; - for (let r = 0, p = "", n, q; r < f.length; r++) { - n = f.charAt(r), n === p && this.dedupe || ((q = this.mapper && this.mapper.get(n)) || "" === q ? q === p && this.dedupe || !(p = q) || (e += q) : e += p = n); + for (let p = 0, m = "", q, r; p < f.length; p++) { + q = f.charAt(p), q === m && this.dedupe || ((r = this.mapper && this.mapper.get(q)) || "" === r ? r === m && this.dedupe || !(m = r) || (e += r) : e += m = q); } f = e; } @@ -167,61 +170,61 @@ B.prototype.encode = function(a) { this.cache && a.length <= this.h && (this.i.set(a, b), this.i.size > this.B && (this.i.clear(), this.h = this.h / 1.1 | 0)); return b; }; -function C(a) { +function D(a) { a.m = null; a.i.clear(); a.j.clear(); } -;function D(a) { +;function E(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -D.prototype.set = function(a, c) { +E.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -D.prototype.get = function(a) { +E.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -D.prototype.remove = function(a) { +E.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -D.prototype.clear = function() { +E.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const E = {normalize:function(a) { +const F = {normalize:function(a) { return a.toLowerCase(); }, dedupe:!1}; -const F = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -Object.create(null); -G.prototype.add = function(a, c, b, d) { +const G = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +u(); +H.prototype.add = function(a, c, b, d) { if (c && (a || 0 === a)) { if (!d && !b && this.g.has(a)) { return this.update(a, c); } c = this.encoder.encode(c); if (d = c.length) { - const r = Object.create(null), p = Object.create(null), n = this.depth, q = this.resolution; - for (let k = 0; k < d; k++) { - let m = c[this.rtl ? d - 1 - k : k]; - var e = m.length; - if (e && (n || !p[m])) { - var g = this.score ? this.score(c, m, k, null, 0) : H(q, d, k), f = ""; + const p = u(), m = u(), q = this.depth, r = this.resolution; + for (let l = 0; l < d; l++) { + let n = c[this.rtl ? d - 1 - l : l]; + var e = n.length; + if (e && (q || !m[n])) { + var g = this.score ? this.score(c, n, l, null, 0) : I(r, d, l), f = ""; switch(this.tokenize) { case "full": if (2 < e) { for (g = 0; g < e; g++) { for (var h = e; h > g; h--) { - f = m.substring(g, h); - var l = this.score ? this.score(c, m, k, f, g) : H(q, d, k, e, g); - I(this, p, f, l, a, b); + f = n.substring(g, h); + var k = this.score ? this.score(c, n, l, f, g) : I(r, d, l, e, g); + J(this, m, f, k, a, b); } } break; @@ -229,24 +232,24 @@ G.prototype.add = function(a, c, b, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - f = m[h] + f, l = this.score ? this.score(c, m, k, f, h) : H(q, d, k, e, h), I(this, p, f, l, a, b); + f = n[h] + f, k = this.score ? this.score(c, n, l, f, h) : I(r, d, l, e, h), J(this, m, f, k, a, b); } f = ""; } case "forward": if (1 < e) { for (h = 0; h < e; h++) { - f += m[h], I(this, p, f, g, a, b); + f += n[h], J(this, m, f, g, a, b); } break; } default: - if (I(this, p, m, g, a, b), n && 1 < d && k < d - 1) { - for (e = Object.create(null), f = this.C, g = m, h = Math.min(n + 1, d - k), e[g] = 1, l = 1; l < h; l++) { - if ((m = c[this.rtl ? d - 1 - k - l : k + l]) && !e[m]) { - e[m] = 1; - const z = this.score ? this.score(c, g, k, m, l) : H(f + (d / 2 > f ? 0 : 1), d, k, h - 1, l - 1), L = this.bidirectional && m > g; - I(this, r, L ? g : m, z, a, b, L ? m : g); + if (J(this, m, n, g, a, b), q && 1 < d && l < d - 1) { + for (e = u(), f = this.C, g = n, h = Math.min(q + 1, d - l), e[g] = 1, k = 1; k < h; k++) { + if ((n = c[this.rtl ? d - 1 - l - k : l + k]) && !e[n]) { + e[n] = 1; + const A = this.score ? this.score(c, g, l, n, k) : I(f + (d / 2 > f ? 0 : 1), d, l, h - 1, k - 1), M = this.bidirectional && n > g; + J(this, p, M ? g : n, A, a, b, M ? n : g); } } } @@ -258,14 +261,14 @@ G.prototype.add = function(a, c, b, d) { } return this; }; -function I(a, c, b, d, e, g, f) { - let h = f ? a.l : a.map, l; - c[b] && f && (l = c[b])[f] || (f ? (c = l || (c[b] = Object.create(null)), c[f] = 1, (l = h.get(f)) ? h = l : h.set(f, h = new Map())) : c[b] = 1, (l = h.get(b)) ? h = l : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.g.get(e)) ? c.push(h) : a.g.set(e, [h])))); +function J(a, c, b, d, e, g, f) { + let h = f ? a.l : a.map, k; + c[b] && f && (k = c[b])[f] || (f ? (c = k || (c[b] = u()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.g.get(e)) ? c.push(h) : a.g.set(e, [h])))); } -function H(a, c, b, d, e) { +function I(a, c, b, d, e) { return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0; } -;function J(a, c, b) { +;function K(a, c, b) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } @@ -295,7 +298,7 @@ function H(a, c, b, d, e) { } return d.length ? d = 1 < d.length ? [].concat.apply([], d) : d[0] : d; } -;G.prototype.search = function(a, c, b) { +;H.prototype.search = function(a, c, b) { b || (c || "object" !== typeof a ? "object" === typeof c && (b = c, c = 0) : (b = a, a = "")); var d = [], e = 0; if (b) { @@ -309,104 +312,126 @@ function H(a, c, b, d, e) { b = a.length; c || (c = 100); if (1 === b) { - return K.call(this, a[0], "", c, e); + return L.call(this, a[0], "", c, e); } g = this.depth && !1 !== g; if (2 === b && g && !f) { - return K.call(this, a[0], a[1], c, e); + return L.call(this, a[0], a[1], c, e); } - var h = 0, l = 0; + var h = 0, k = 0; if (1 < b) { - var r = Object.create(null); - const n = []; - for (let q = 0, k; q < b; q++) { - if ((k = a[q]) && !r[k]) { - if (f || M(this, k)) { - n.push(k), r[k] = 1; + var p = u(); + const q = []; + for (let r = 0, l; r < b; r++) { + if ((l = a[r]) && !p[l]) { + if (f || N(this, l)) { + q.push(l), p[l] = 1; } else { return d; } - const m = k.length; - h = Math.max(h, m); - l = l ? Math.min(l, m) : m; + const n = l.length; + h = Math.max(h, n); + k = k ? Math.min(k, n) : n; } } - a = n; + a = q; b = a.length; } if (!b) { return d; } - r = 0; + p = 0; if (1 === b) { - return K.call(this, a[0], "", c, e); + return L.call(this, a[0], "", c, e); } if (2 === b && g && !f) { - return K.call(this, a[0], a[1], c, e); + return L.call(this, a[0], a[1], c, e); } if (1 < b) { if (g) { - var p = a[0]; - r = 1; + var m = a[0]; + p = 1; } else { - 9 < h && 3 < h / l && a.sort(u); + 9 < h && 3 < h / k && a.sort(v); } } - for (let n, q; r < b; r++) { - q = a[r]; - p ? (n = M(this, q, p), n = N(n, d, f, this.C, c, e, 2 === b), f && !1 === n && d.length || (p = q)) : (n = M(this, q), n = N(n, d, f, this.resolution, c, e, 1 === b)); - if (n) { - return n; + for (let q, r; p < b; p++) { + r = a[p]; + m ? (q = N(this, r, m), q = O(q, d, f, this.C, c, e, 2 === b), f && !1 === q && d.length || (m = r)) : (q = N(this, r), q = O(q, d, f, this.resolution, c, e, 1 === b)); + if (q) { + return q; } - if (f && r === b - 1) { + if (f && p === b - 1) { g = d.length; if (!g) { - if (p) { - p = ""; - r = -1; + if (m) { + m = ""; + p = -1; continue; } return d; } if (1 === g) { - return J(d[0], c, e); + return K(d[0], c, e); } } } a: { a = d; d = this.resolution; - p = f; + m = f; b = a.length; f = []; - g = Object.create(null); - for (let n = 0, q, k, m, z; n < d; n++) { - for (l = 0; l < b; l++) { - if (m = a[l], n < m.length && (q = m[n])) { - for (r = 0; r < q.length; r++) { - k = q[r], (h = g[k]) ? g[k]++ : (h = 0, g[k] = 1), z = f[h] || (f[h] = []), z.push(k); + g = u(); + for (let q = 0, r, l, n, A; q < d; q++) { + for (k = 0; k < b; k++) { + if (n = a[k], q < n.length && (r = n[q])) { + for (p = 0; p < r.length; p++) { + l = r[p], (h = g[l]) ? g[l]++ : (h = 0, g[l] = 1), A = f[h] || (f[h] = []), A.push(l); } } } } if (a = f.length) { - if (p) { + if (m) { d = []; - for (let n = a - 1, q = 0, k, m; 0 <= n; n--) { - if (k = f[n], m = k.length, e >= m) { - e -= m; + for (let q = a - 1, r = 0, l, n; 0 <= q; q--) { + if (l = f[q], n = l.length, e >= n) { + e -= n; } else { - if (m + q > c || e) { - k = k.slice(e, c - q + e), m = k.length; + if (n + r > c || e) { + l = l.slice(e, c - r + e), n = l.length; } - d.push(k); - q += m; - if (c === q) { + d.push(l); + r += n; + if (c === r) { break; } } } - f = 1 < d.length ? [].concat.apply([], d) : d[0]; + if (1 < d.length) { + f = d; + a = []; + d = u(); + g = f.length; + for (k = 0; k < g; k++) { + for (m = f[k], h = m.length, p = 0; p < h; p++) { + if (b = m[p], !d[b]) { + if (d[b] = 1, e) { + e--; + } else { + if (a.push(b), a.length === c) { + break; + } + } + } + } + } + c = a; + } else { + c = d[0]; + } + f = c; } else { if (a < b) { d = []; @@ -422,23 +447,23 @@ function H(a, c, b, d, e) { } return d; }; -function K(a, c, b, d) { - return (a = M(this, a, c)) && a.length ? J(a, b, d) : []; +function L(a, c, b, d) { + return (a = N(this, a, c)) && a.length ? K(a, b, d) : []; } -function N(a, c, b, d, e, g, f) { +function O(a, c, b, d, e, g, f) { let h = []; if (a) { d = Math.min(a.length, d); - for (let l = 0, r = 0, p; l < d; l++) { - if (p = a[l]) { - if (g && p && f && (p.length <= g ? (g -= p.length, p = null) : (p = p.slice(g), g = 0)), p && (h[l] = p, f && (r += p.length, r >= e))) { + for (let k = 0, p = 0, m; k < d; k++) { + if (m = a[k]) { + if (g && m && f && (m.length <= g ? (g -= m.length, m = null) : (m = m.slice(g), g = 0)), m && (h[k] = m, f && (p += m.length, p >= e))) { break; } } } if (h.length) { if (f) { - return J(h, e, 0); + return K(h, e, 0); } c.push(h); return; @@ -446,13 +471,13 @@ function N(a, c, b, d, e, g, f) { } return !b && h; } -function M(a, c, b) { +function N(a, c, b) { let d; b && (d = a.bidirectional && c > b); a = b ? (a = a.l.get(d ? c : b)) && a.get(d ? b : c) : a.map.get(c); return a; } -;G.prototype.remove = function(a, c) { +;H.prototype.remove = function(a, c) { const b = this.g.size && (this.fastupdate ? this.g.get(a) : this.g.has(a)); if (b) { if (this.fastupdate) { @@ -467,14 +492,14 @@ function M(a, c, b) { } } } else { - O(this.map, a), this.depth && O(this.l, a); + P(this.map, a), this.depth && P(this.l, a); } c || this.g.delete(a); } this.cache && this.cache.remove(a); return this; }; -function O(a, c) { +function P(a, c) { let b = 0; if (a.constructor === Array) { for (let d = 0, e, g; d < a.length; d++) { @@ -489,25 +514,25 @@ function O(a, c) { } } else { for (let d of a) { - const e = d[0], g = O(d[1], c); + const e = d[0], g = P(d[1], c); g ? b += g : a.delete(e); } } return b; } -;function G(a, c) { +;function H(a, c) { if (!this) { - return new G(a); + return new H(a); } if (a) { var b = "string" === typeof a ? a : a.preset; - b && (F[b] || console.warn("Preset not found: " + b), a = Object.assign({}, F[b], a)); + b && (G[b] || console.warn("Preset not found: " + b), a = Object.assign({}, G[b], a)); } else { a = {}; } b = a.context || {}; - const d = a.encode || a.encoder || E; - this.encoder = d.encode ? d : "object" === typeof d ? new B(d) : {encode:d}; + const d = a.encode || a.encoder || F; + this.encoder = d.encode ? d : "object" === typeof d ? new C(d) : {encode:d}; let e; this.resolution = a.resolution || 9; this.tokenize = e = a.tokenize || "strict"; @@ -521,29 +546,29 @@ function O(a, c) { this.g = c || (this.fastupdate ? new Map() : new Set()); this.C = b.resolution || 1; this.rtl = d.rtl || a.rtl || !1; - this.cache = (e = a.cache || null) && new D(e); + this.cache = (e = a.cache || null) && new E(e); } -G.prototype.clear = function() { +H.prototype.clear = function() { this.map.clear(); this.l.clear(); this.g.clear(); this.cache && this.cache.clear(); return this; }; -G.prototype.append = function(a, c) { +H.prototype.append = function(a, c) { return this.add(a, c, !0); }; -G.prototype.contain = function(a) { +H.prototype.contain = function(a) { return this.g.has(a); }; -G.prototype.update = function(a, c) { +H.prototype.update = function(a, c) { if (this.async) { const b = this, d = this.remove(a); return d.then ? d.then(() => b.add(a, c)) : this.add(a, c); } return this.remove(a).add(a, c); }; -function P(a) { +function Q(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, d; b < a.length; b++) { @@ -551,21 +576,21 @@ function P(a) { } } else { for (const b of a) { - const d = b[0], e = P(b[1]); + const d = b[0], e = Q(b[1]); e ? c += e : a.delete(d); } } return c; } -G.prototype.cleanup = function() { +H.prototype.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - P(this.map); - this.depth && P(this.l); + Q(this.map); + this.depth && Q(this.l); return this; }; -G.prototype.searchCache = function(a, c, b) { +H.prototype.searchCache = function(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); let d = this.cache.get(a); if (!d) { @@ -581,9 +606,9 @@ G.prototype.searchCache = function(a, c, b) { } return d; }; -const Q = {Index:G, Charset:null, Encoder:B, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, R = self; -let S; -(S = R.define) && S.amd ? S([], function() { - return Q; -}) : "object" === typeof R.exports ? R.exports = Q : R.FlexSearch = Q; +const R = {Index:H, Charset:null, Encoder:C, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, S = self; +let T; +(T = S.define) && T.amd ? T([], function() { + return R; +}) : "object" === typeof S.exports ? S.exports = R : S.FlexSearch = R; }(this)); diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index 5737577..f11af35 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -5,21 +5,22 @@ * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';function t(a,c,b){const d=typeof b,e=typeof a;if("undefined"!==d){if("undefined"!==e){if(b){if("function"===e&&d===e)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var f of a)g.set(f[0],f[1]);return g}if(c===Set){f=new Set(b);for(g of a.values())f.add(g);return f}}}return a}return b}return"undefined"===e?c:a}function u(a,c){return c.length-a.length};const v=/[^\p{L}\p{N}]+/u,w=/(\d{3})/g,x=/(\D)(\d{3})/g,y=/(\d{3})(\D)/g,A="".normalize&&/[\u0300-\u036f]/g;function B(a){if(!this)return new B(...arguments);for(let c=0;cthis.stemmer.get(r)),l=1);this.matcher&&1this.matcher.get(r)),l=1);f&&l&&(f.lengththis.B&&(this.j.clear(),this.o=this.o/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.i.set(a,b),this.i.size>this.B&&(this.i.clear(),this.h=this.h/1.1|0));return b};function C(a){a.m=null;a.i.clear();a.j.clear()};function D(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}D.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};D.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};D.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; -D.prototype.clear=function(){this.cache.clear();this.h=""};const E={normalize:function(a){return a.toLowerCase()},dedupe:!1};const F={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};Object.create(null);G.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.g.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const r=Object.create(null),p=Object.create(null),n=this.depth,q=this.resolution;for(let k=0;kg;h--){f=m.substring(g,h);var l=this.score?this.score(c,m,k,f,g):H(q,d, -k,e,g);I(this,p,f,l,a,b)}break}case "reverse":if(1f?0:1),d,k,h-1,l-1),K=this.bidirectional&&m>g;I(this,r,K?g:m, -z,a,b,K?m:g)}}}}this.fastupdate||this.g.add(a)}}return this};function I(a,c,b,d,e,g,f){let h=f?a.l:a.map,l;c[b]&&f&&(l=c[b])[f]||(f?(c=l||(c[b]=Object.create(null)),c[f]=1,(l=h.get(f))?h=l:h.set(f,h=new Map)):c[b]=1,(l=h.get(b))?h=l:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.g.get(e))?c.push(h):a.g.set(e,[h]))))}function H(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1=m)e-=m;else{if(m+q>c||e)k=k.slice(e,c-q+e),m=k.length;d.push(k);q+=m;if(c===q)break}f=1c||e)f=f.slice(e,c+e)}d=f}return d}; -function L(a,c,b,d){return(a=M(this,a,c))&&a.length?J(a,b,d):[]}function N(a,c,b,d,e,g,f){let h=[];if(a){d=Math.min(a.length,d);for(let l=0,r=0,p;l=e)))break;if(h.length){if(f)return J(h,e,0);c.push(h);return}}return!b&&h}function M(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.l.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};G.prototype.remove=function(a,c){const b=this.g.size&&(this.fastupdate?this.g.get(a):this.g.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else O(this.map,a),this.depth&&O(this.l,a);c||this.g.delete(a)}this.cache&&this.cache.remove(a);return this}; -function O(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}return this.remove(a).add(a,c)}; -function P(a){let c=0;if(a.constructor===Array)for(let b=0,d;bthis.stemmer.get(p)),k=1);this.matcher&&1this.matcher.get(p)),k=1);f&&k&&(f.lengththis.B&&(this.j.clear(),this.o=this.o/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.i.set(a,b),this.i.size>this.B&&(this.i.clear(),this.h=this.h/1.1|0));return b};function D(a){a.m=null;a.i.clear();a.j.clear()};function E(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}E.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};E.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};E.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; +E.prototype.clear=function(){this.cache.clear();this.h=""};const F={normalize:function(a){return a.toLowerCase()},dedupe:!1};const G={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};u();H.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.g.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const p=u(),m=u(),q=this.depth,r=this.resolution;for(let l=0;lg;h--){f=n.substring(g,h);var k=this.score?this.score(c,n,l,f,g):I(r,d,l,e,g);J(this,m,f,k,a,b)}break}case "reverse":if(1< +e){for(h=e-1;0f?0:1),d,l,h-1,k-1),L=this.bidirectional&&n>g;J(this,p,L?g:n,A,a,b,L?n:g)}}}}this.fastupdate||this.g.add(a)}}return this}; +function J(a,c,b,d,e,g,f){let h=f?a.l:a.map,k;c[b]&&f&&(k=c[b])[f]||(f?(c=k||(c[b]=u()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.g.get(e))?c.push(h):a.g.set(e,[h]))))}function I(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1=n)e-=n;else{if(n+r>c||e)l=l.slice(e,c-r+e),n=l.length;d.push(l);r+=n;if(c===r)break}if(1c||e)f=f.slice(e,c+e)}d=f}return d};function M(a,c,b,d){return(a=N(this,a,c))&&a.length?K(a,b,d):[]}function O(a,c,b,d,e,g,f){let h=[];if(a){d=Math.min(a.length,d);for(let k=0,p=0,m;k=e)))break;if(h.length){if(f)return K(h,e,0);c.push(h);return}}return!b&&h} +function N(a,c,b){let d;b&&(d=a.bidirectional&&c>b);a=b?(a=a.l.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.prototype.remove=function(a,c){const b=this.g.size&&(this.fastupdate?this.g.get(a):this.g.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else P(this.map,a),this.depth&&P(this.l,a);c||this.g.delete(a)}this.cache&&this.cache.remove(a);return this}; +function P(a,c){let b=0;if(a.constructor===Array)for(let d=0,e,g;db.add(a,c)):this.add(a,c)}return this.remove(a).add(a,c)}; +function Q(a){let c=0;if(a.constructor===Array)for(let b=0,d;b this.limit && this.cache.delete(this.cache.keys().next().value); }; -u.prototype.get = function(a) { +v.prototype.get = function(a) { const b = this.cache.get(a); b && this.B !== a && (this.cache.delete(a), this.cache.set(this.B = a, b)); return b; }; -u.prototype.remove = function(a) { +v.prototype.remove = function(a) { for (const b of this.cache) { const c = b[0]; b[1].includes(a) && this.cache.delete(c); } }; -u.prototype.clear = function() { +v.prototype.clear = function() { this.cache.clear(); this.B = ""; }; -const v = 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 w = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), y = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; -const z = {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 A = /[\x00-\x7F]+/g; +const w = 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 x = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), z = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; +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 B = /[\x00-\x7F]+/g; const C = /[\x00-\x7F]+/g; -var D = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:{normalize:function(a) { +const D = /[\x00-\x7F]+/g; +var E = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:{normalize:function(a) { return a.toLowerCase(); -}, dedupe:!1}, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:v}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:v, replacer:y, matcher:w}, LatinExtra:{normalize:!0, dedupe:!0, mapper:v, replacer:y.concat([/(?!^)[aeoy]/g, ""]), matcher:w}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +}, dedupe:!1}, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:w}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:w, replacer:z, matcher:x}, LatinExtra:{normalize:!0, dedupe:!0, mapper:w, replacer:z.concat([/(?!^)[aeoy]/g, ""]), matcher:x}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let c = 0; c < a.length; c++) { var b = a[c]; - let d = b.charAt(0), e = z[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = z[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + let d = b.charAt(0), e = A[d]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = A[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { } a[c] = d; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(A, " "); + return ("" + a).replace(B, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(B, ""); + return ("" + a).replace(C, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(C, " "); + return ("" + a).replace(D, " "); }}}; -const E = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -function F(a) { +const F = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +function G(a) { const b = "string" === typeof a ? a : a.preset; - b && (E[b] || console.warn("Preset not found: " + b), a = Object.assign({}, E[b], a)); + b && (F[b] || console.warn("Preset not found: " + b), a = Object.assign({}, F[b], a)); return a; } -;Object.create(null); -G.prototype.add = function(a, b, c, d) { +;t(); +H.prototype.add = function(a, b, c, d) { if (b && (a || 0 === a)) { if (!d && !c && this.h.has(a)) { return this.update(a, b); } b = this.encoder.encode(b); if (d = b.length) { - const r = Object.create(null), p = Object.create(null), n = this.depth, q = this.resolution; + const q = t(), n = t(), p = this.depth, r = this.resolution; for (let k = 0; k < d; k++) { - let l = b[this.rtl ? d - 1 - k : k]; - var e = l.length; - if (e && (n || !p[l])) { - var f = this.score ? this.score(b, l, k, null, 0) : H(q, d, k), g = ""; + let m = b[this.rtl ? d - 1 - k : k]; + var e = m.length; + if (e && (p || !n[m])) { + var f = this.score ? this.score(b, m, k, null, 0) : I(r, d, k), g = ""; switch(this.tokenize) { case "full": if (2 < e) { for (f = 0; f < e; f++) { for (var h = e; h > f; h--) { - g = l.substring(f, h); - var m = this.score ? this.score(b, l, k, g, f) : H(q, d, k, e, f); - J(this, p, g, m, a, c); + g = m.substring(f, h); + var l = this.score ? this.score(b, m, k, g, f) : I(r, d, k, e, f); + K(this, n, g, l, a, c); } } break; @@ -90,24 +93,24 @@ G.prototype.add = function(a, b, c, d) { case "reverse": if (1 < e) { for (h = e - 1; 0 < h; h--) { - g = l[h] + g, m = this.score ? this.score(b, l, k, g, h) : H(q, d, k, e, h), J(this, p, g, m, a, c); + g = m[h] + g, l = this.score ? this.score(b, m, k, g, h) : I(r, d, k, e, h), K(this, n, g, l, a, c); } g = ""; } case "forward": if (1 < e) { for (h = 0; h < e; h++) { - g += l[h], J(this, p, g, f, a, c); + g += m[h], K(this, n, g, f, a, c); } break; } default: - if (J(this, p, l, f, a, c), n && 1 < d && k < d - 1) { - for (e = Object.create(null), g = this.C, f = l, h = Math.min(n + 1, d - k), e[f] = 1, m = 1; m < h; m++) { - if ((l = b[this.rtl ? d - 1 - k - m : k + m]) && !e[l]) { - e[l] = 1; - const x = this.score ? this.score(b, f, k, l, m) : H(g + (d / 2 > g ? 0 : 1), d, k, h - 1, m - 1), I = this.bidirectional && l > f; - J(this, r, I ? f : l, x, a, c, I ? l : f); + if (K(this, n, m, f, a, c), p && 1 < d && k < d - 1) { + for (e = t(), g = this.C, f = m, h = Math.min(p + 1, d - k), e[f] = 1, l = 1; l < h; l++) { + if ((m = b[this.rtl ? d - 1 - k - l : k + l]) && !e[m]) { + e[m] = 1; + const y = this.score ? this.score(b, f, k, m, l) : I(g + (d / 2 > g ? 0 : 1), d, k, h - 1, l - 1), J = this.bidirectional && m > f; + K(this, q, J ? f : m, y, a, c, J ? m : f); } } } @@ -119,14 +122,14 @@ G.prototype.add = function(a, b, c, d) { } return this; }; -function J(a, b, c, d, e, f, g) { - let h = g ? a.A : a.map, m; - b[c] && g && (m = b[c])[g] || (g ? (b = m || (b[c] = Object.create(null)), b[g] = 1, (m = h.get(g)) ? h = m : h.set(g, h = new Map())) : b[c] = 1, (m = h.get(c)) ? h = m : h.set(c, h = []), h = h[d] || (h[d] = []), f && h.includes(e) || (h.push(e), a.fastupdate && ((b = a.h.get(e)) ? b.push(h) : a.h.set(e, [h])))); +function K(a, b, c, d, e, f, g) { + let h = g ? a.A : a.map, l; + b[c] && g && (l = b[c])[g] || (g ? (b = l || (b[c] = t()), b[g] = 1, (l = h.get(g)) ? h = l : h.set(g, h = new Map())) : b[c] = 1, (l = h.get(c)) ? h = l : h.set(c, h = []), h = h[d] || (h[d] = []), f && h.includes(e) || (h.push(e), a.fastupdate && ((b = a.h.get(e)) ? b.push(h) : a.h.set(e, [h])))); } -function H(a, b, c, d, e) { +function I(a, b, c, d, e) { return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; } -;function K(a, b, c) { +;function L(a, b, c) { if (1 === a.length) { return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a; } @@ -156,7 +159,7 @@ function H(a, b, c, d, e) { } return d.length ? d = 1 < d.length ? [].concat.apply([], d) : d[0] : d; } -;G.prototype.search = function(a, b, c) { +;H.prototype.search = function(a, b, c) { c || (b || "object" !== typeof a ? "object" === typeof b && (c = b, b = 0) : (c = a, a = "")); var d = [], e = 0; if (c) { @@ -170,104 +173,126 @@ function H(a, b, c, d, e) { c = a.length; b || (b = 100); if (1 === c) { - return L.call(this, a[0], "", b, e); + return M.call(this, a[0], "", b, e); } f = this.depth && !1 !== f; if (2 === c && f && !g) { - return L.call(this, a[0], a[1], b, e); + return M.call(this, a[0], a[1], b, e); } - var h = 0, m = 0; + var h = 0, l = 0; if (1 < c) { - var r = Object.create(null); - const n = []; - for (let q = 0, k; q < c; q++) { - if ((k = a[q]) && !r[k]) { - if (g || M(this, k)) { - n.push(k), r[k] = 1; + var q = t(); + const p = []; + for (let r = 0, k; r < c; r++) { + if ((k = a[r]) && !q[k]) { + if (g || N(this, k)) { + p.push(k), q[k] = 1; } else { return d; } - const l = k.length; - h = Math.max(h, l); - m = m ? Math.min(m, l) : l; + const m = k.length; + h = Math.max(h, m); + l = l ? Math.min(l, m) : m; } } - a = n; + a = p; c = a.length; } if (!c) { return d; } - r = 0; + q = 0; if (1 === c) { - return L.call(this, a[0], "", b, e); + return M.call(this, a[0], "", b, e); } if (2 === c && f && !g) { - return L.call(this, a[0], a[1], b, e); + return M.call(this, a[0], a[1], b, e); } if (1 < c) { if (f) { - var p = a[0]; - r = 1; + var n = a[0]; + q = 1; } else { - 9 < h && 3 < h / m && a.sort(t); + 9 < h && 3 < h / l && a.sort(u); } } - for (let n, q; r < c; r++) { - q = a[r]; - p ? (n = M(this, q, p), n = N(n, d, g, this.C, b, e, 2 === c), g && !1 === n && d.length || (p = q)) : (n = M(this, q), n = N(n, d, g, this.resolution, b, e, 1 === c)); - if (n) { - return n; + for (let p, r; q < c; q++) { + r = a[q]; + n ? (p = N(this, r, n), p = O(p, d, g, this.C, b, e, 2 === c), g && !1 === p && d.length || (n = r)) : (p = N(this, r), p = O(p, d, g, this.resolution, b, e, 1 === c)); + if (p) { + return p; } - if (g && r === c - 1) { + if (g && q === c - 1) { f = d.length; if (!f) { - if (p) { - p = ""; - r = -1; + if (n) { + n = ""; + q = -1; continue; } return d; } if (1 === f) { - return K(d[0], b, e); + return L(d[0], b, e); } } } a: { a = d; d = this.resolution; - p = g; + n = g; c = a.length; g = []; - f = Object.create(null); - for (let n = 0, q, k, l, x; n < d; n++) { - for (m = 0; m < c; m++) { - if (l = a[m], n < l.length && (q = l[n])) { - for (r = 0; r < q.length; r++) { - k = q[r], (h = f[k]) ? f[k]++ : (h = 0, f[k] = 1), x = g[h] || (g[h] = []), x.push(k); + f = t(); + for (let p = 0, r, k, m, y; p < d; p++) { + for (l = 0; l < c; l++) { + if (m = a[l], p < m.length && (r = m[p])) { + for (q = 0; q < r.length; q++) { + k = r[q], (h = f[k]) ? f[k]++ : (h = 0, f[k] = 1), y = g[h] || (g[h] = []), y.push(k); } } } } if (a = g.length) { - if (p) { + if (n) { d = []; - for (let n = a - 1, q = 0, k, l; 0 <= n; n--) { - if (k = g[n], l = k.length, e >= l) { - e -= l; + for (let p = a - 1, r = 0, k, m; 0 <= p; p--) { + if (k = g[p], m = k.length, e >= m) { + e -= m; } else { - if (l + q > b || e) { - k = k.slice(e, b - q + e), l = k.length; + if (m + r > b || e) { + k = k.slice(e, b - r + e), m = k.length; } d.push(k); - q += l; - if (b === q) { + r += m; + if (b === r) { break; } } } - g = 1 < d.length ? [].concat.apply([], d) : d[0]; + if (1 < d.length) { + g = d; + a = []; + d = t(); + f = g.length; + for (l = 0; l < f; l++) { + for (n = g[l], h = n.length, q = 0; q < h; q++) { + if (c = n[q], !d[c]) { + if (d[c] = 1, e) { + e--; + } else { + if (a.push(c), a.length === b) { + break; + } + } + } + } + } + b = a; + } else { + b = d[0]; + } + g = b; } else { if (a < c) { d = []; @@ -283,23 +308,23 @@ function H(a, b, c, d, e) { } return d; }; -function L(a, b, c, d) { - return (a = M(this, a, b)) && a.length ? K(a, c, d) : []; +function M(a, b, c, d) { + return (a = N(this, a, b)) && a.length ? L(a, c, d) : []; } -function N(a, b, c, d, e, f, g) { +function O(a, b, c, d, e, f, g) { let h = []; if (a) { d = Math.min(a.length, d); - for (let m = 0, r = 0, p; m < d; m++) { - if (p = a[m]) { - if (f && p && g && (p.length <= f ? (f -= p.length, p = null) : (p = p.slice(f), f = 0)), p && (h[m] = p, g && (r += p.length, r >= e))) { + for (let l = 0, q = 0, n; l < d; l++) { + if (n = a[l]) { + if (f && n && g && (n.length <= f ? (f -= n.length, n = null) : (n = n.slice(f), f = 0)), n && (h[l] = n, g && (q += n.length, q >= e))) { break; } } } if (h.length) { if (g) { - return K(h, e, 0); + return L(h, e, 0); } b.push(h); return; @@ -307,13 +332,13 @@ function N(a, b, c, d, e, f, g) { } return !c && h; } -function M(a, b, c) { +function N(a, b, c) { let d; c && (d = a.bidirectional && b > c); a = c ? (a = a.A.get(d ? b : c)) && a.get(d ? c : b) : a.map.get(b); return a; } -;G.prototype.remove = function(a, b) { +;H.prototype.remove = function(a, b) { const c = this.h.size && (this.fastupdate ? this.h.get(a) : this.h.has(a)); if (c) { if (this.fastupdate) { @@ -328,14 +353,14 @@ function M(a, b, c) { } } } else { - O(this.map, a), this.depth && O(this.A, a); + P(this.map, a), this.depth && P(this.A, a); } b || this.h.delete(a); } this.cache && this.cache.remove(a); return this; }; -function O(a, b) { +function P(a, b) { let c = 0; if (a.constructor === Array) { for (let d = 0, e, f; d < a.length; d++) { @@ -350,17 +375,17 @@ function O(a, b) { } } else { for (let d of a) { - const e = d[0], f = O(d[1], b); + const e = d[0], f = P(d[1], b); f ? c += f : a.delete(e); } } return c; } -;function G(a, b) { +;function H(a, b) { if (!this) { - return new G(a); + return new H(a); } - a = a ? F(a) : {}; + a = a ? G(a) : {}; const c = a.context || {}, d = a.encode || a.encoder || function(f) { return f.toLowerCase().trim().split(/\s+/); }; @@ -378,29 +403,29 @@ function O(a, b) { this.h = b || (this.fastupdate ? new Map() : new Set()); this.C = c.resolution || 1; this.rtl = d.rtl || a.rtl || !1; - this.cache = (e = a.cache || null) && new u(e); + this.cache = (e = a.cache || null) && new v(e); } -G.prototype.clear = function() { +H.prototype.clear = function() { this.map.clear(); this.A.clear(); this.h.clear(); this.cache && this.cache.clear(); return this; }; -G.prototype.append = function(a, b) { +H.prototype.append = function(a, b) { return this.add(a, b, !0); }; -G.prototype.contain = function(a) { +H.prototype.contain = function(a) { return this.h.has(a); }; -G.prototype.update = function(a, b) { +H.prototype.update = function(a, b) { if (this.async) { const c = this, d = this.remove(a); return d.then ? d.then(() => c.add(a, b)) : this.add(a, b); } return this.remove(a).add(a, b); }; -function P(a) { +function Q(a) { let b = 0; if (a.constructor === Array) { for (let c = 0, d; c < a.length; c++) { @@ -408,21 +433,21 @@ function P(a) { } } else { for (const c of a) { - const d = c[0], e = P(c[1]); + const d = c[0], e = Q(c[1]); e ? b += e : a.delete(d); } } return b; } -G.prototype.cleanup = function() { +H.prototype.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - P(this.map); - this.depth && P(this.A); + Q(this.map); + this.depth && Q(this.A); return this; }; -G.prototype.searchCache = function(a, b, c) { +H.prototype.searchCache = function(a, b, c) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); let d = this.cache.get(a); if (!d) { @@ -438,6 +463,6 @@ G.prototype.searchCache = function(a, b, c) { } return d; }; -export default {Index:G, Charset:D, Encoder:null, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +export default {Index:H, Charset:E, Encoder:null, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=G;export const Charset=D;export const Encoder=null;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=H;export const Charset=E;export const Encoder=null;export const Document=null;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index d616298..6ba238c 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -5,16 +5,17 @@ * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -function t(a,b){return b.length-a.length};function u(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.B=""}u.prototype.set=function(a,b){this.cache.set(this.B=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};u.prototype.get=function(a){const b=this.cache.get(a);b&&this.B!==a&&(this.cache.delete(a),this.cache.set(this.B=a,b));return b};u.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}}; -u.prototype.clear=function(){this.cache.clear();this.B=""};const v=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 w=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),y=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const z={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 A=/[\x00-\x7F]+/g;const B=/[\x00-\x7F]+/g;const C=/[\x00-\x7F]+/g;var D={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:{normalize:function(a){return a.toLowerCase()},dedupe:!1},LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:v},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:v,replacer:y,matcher:w},LatinExtra:{normalize:!0,dedupe:!0,mapper:v,replacer:y.concat([/(?!^)[aeoy]/g,""]),matcher:w},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=l.substring(f,h);var m=this.score?this.score(b,l,k,g,f):I(q,d, -k,e,f);J(this,p,g,m,a,c)}break}case "reverse":if(1g?0:1),d,k,h-1,m-1),H=this.bidirectional&&l>f;J(this,r,H?f:l, -x,a,c,H?l:f)}}}}this.fastupdate||this.h.add(a)}}return this};function J(a,b,c,d,e,f,g){let h=g?a.A:a.map,m;b[c]&&g&&(m=b[c])[g]||(g?(b=m||(b[c]=Object.create(null)),b[g]=1,(m=h.get(g))?h=m:h.set(g,h=new Map)):b[c]=1,(m=h.get(c))?h=m:h.set(c,h=[]),h=h[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((b=a.h.get(e))?b.push(h):a.h.set(e,[h]))))}function I(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a;let d=[];for(let e=0,f,g;e=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),d.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),f;d=[f]}b-=g;if(!b)break}return d.length?d=1=l)e-=l;else{if(l+q>b||e)k=k.slice(e,b-q+e),l=k.length;d.push(k);q+=l;if(b===q)break}g=1b||e)g=g.slice(e,b+e)}d=g}return d}; -function L(a,b,c,d){return(a=M(this,a,b))&&a.length?K(a,c,d):[]}function N(a,b,c,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let m=0,r=0,p;m=e)))break;if(h.length){if(g)return K(h,e,0);b.push(h);return}}return!c&&h}function M(a,b,c){let d;c&&(d=a.bidirectional&&b>c);a=c?(a=a.A.get(d?b:c))&&a.get(d?c:b):a.map.get(b);return a};G.prototype.remove=function(a,b){const c=this.h.size&&(this.fastupdate?this.h.get(a):this.h.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else O(this.map,a),this.depth&&O(this.A,a);b||this.h.delete(a)}this.cache&&this.cache.remove(a);return this}; -function O(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)}; -function P(a){let b=0;if(a.constructor===Array)for(let c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)};v.prototype.get=function(a){const b=this.cache.get(a);b&&this.B!==a&&(this.cache.delete(a),this.cache.set(this.B=a,b));return b};v.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}}; +v.prototype.clear=function(){this.cache.clear();this.B=""};const w=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 x=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),z=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];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 B=/[\x00-\x7F]+/g;const C=/[\x00-\x7F]+/g;const D=/[\x00-\x7F]+/g;var E={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:{normalize:function(a){return a.toLowerCase()},dedupe:!1},LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:w},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:w,replacer:z,matcher:x},LatinExtra:{normalize:!0,dedupe:!0,mapper:w,replacer:z.concat([/(?!^)[aeoy]/g,""]),matcher:x},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=m.substring(f,h);var l=this.score?this.score(b,m,k,g,f):J(r,d,k,e,f);K(this,n,g,l,a,c)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,k,h-1,l-1),I=this.bidirectional&&m>f;K(this,q,I?f:m,y,a,c,I?m:f)}}}}this.fastupdate||this.h.add(a)}}return this}; +function K(a,b,c,d,e,f,g){let h=g?a.A:a.map,l;b[c]&&g&&(l=b[c])[g]||(g?(b=l||(b[c]=t()),b[g]=1,(l=h.get(g))?h=l:h.set(g,h=new Map)):b[c]=1,(l=h.get(c))?h=l:h.set(c,h=[]),h=h[d]||(h[d]=[]),f&&h.includes(e)||(h.push(e),a.fastupdate&&((b=a.h.get(e))?b.push(h):a.h.set(e,[h]))))}function J(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a;let d=[];for(let e=0,f,g;e=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),d.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),f;d=[f]}b-=g;if(!b)break}return d.length?d=1=m)e-=m;else{if(m+r>b||e)k=k.slice(e,b-r+e),m=k.length;d.push(k);r+=m;if(b===r)break}if(1b||e)g=g.slice(e,b+e)}d=g}return d};function M(a,b,c,d){return(a=N(this,a,b))&&a.length?L(a,c,d):[]}function O(a,b,c,d,e,f,g){let h=[];if(a){d=Math.min(a.length,d);for(let l=0,q=0,n;l=e)))break;if(h.length){if(g)return L(h,e,0);b.push(h);return}}return!c&&h} +function N(a,b,c){let d;c&&(d=a.bidirectional&&b>c);a=c?(a=a.A.get(d?b:c))&&a.get(d?c:b):a.map.get(b);return a};H.prototype.remove=function(a,b){const c=this.h.size&&(this.fastupdate?this.h.get(a):this.h.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else P(this.map,a),this.depth&&P(this.A,a);b||this.h.delete(a)}this.cache&&this.cache.remove(a);return this}; +function P(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}return this.remove(a).add(a,b)}; +function Q(a){let b=0;if(a.constructor===Array)for(let c=0,d;cc||d)&&(j=j.slice(d,c+d))}else{const a=[];for(let b,e,f=k-1,g=0;0<=f;f--){if(b=j[f],e=b.length,d>=e){d-=e;continue}if((e+g>c||d)&&(b=b.slice(d,c-g+d),e=b.length),a.push(b),g+=e,c===g)break}j=1c||d)&&(j=j.slice(d,c+d))}else{const a=[];for(let b,e,f=k-1,g=0;0<=f;f--){if(b=j[f],e=b.length,d>=e){d-=e;continue}if((e+g>c||d)&&(b=b.slice(d,c-g+d),e=b.length),a.push(b),g+=e,c===g)break}j=1 1 - ? concat(final) + ? union(final, offset, limit) : final[0]; } } @@ -130,6 +126,37 @@ export function intersect(arrays, resolution, limit, offset, suggest) { return result; } +function union(arrays, offset, limit){ + + const result = []; + const check = create_object(); + let ids, id, arr_len = arrays.length, ids_len; + + for(let i = 0; i < arr_len; i++){ + + ids = arrays[i]; + ids_len = ids.length; + + for(let j = 0; j < ids_len; j++){ + id = ids[j]; + if(!check[id]){ + check[id] = 1; + if(offset){ + offset--; + } + else{ + result.push(id); + if(result.length === limit){ + break; + } + } + } + } + } + + return result; +} + // // /** // * Implementation based on Object[key] provides better suggestions