diff --git a/README.md b/README.md index c157c35..88d6b29 100644 --- a/README.md +++ b/README.md @@ -910,7 +910,7 @@ Global Members: ## - _async_ index.[**mount**](doc/persistent.md)(db) -- _async_ index.[**commit**](doc/persistent.md)(boolean) +- _async_ index.[**commit**](doc/persistent.md)() - _async_ index.[**destroy**](doc/persistent.md#delete-store--migration)() --- @@ -939,7 +939,7 @@ Global Members: ## - _async_ document.[**mount**](doc/persistent.md)(db) -- _async_ document.[**commit**](doc/persistent.md)(boolean) +- _async_ document.[**commit**](doc/persistent.md)() - _async_ document.[**destroy**](doc/persistent.md#delete-store--migration)() `Document` Properties: @@ -955,6 +955,7 @@ Async Equivalents (Non-Blocking Balanced): - _async_ [**.updateAsync**](doc/async.md)( ... , \) - _async_ [**.removeAsync**](doc/async.md)( ... , \) - _async_ [**.searchAsync**](doc/async.md)( ... , \) +- _async_ [**.searchCacheAsync**](doc/async.md)( ... , \) Async methods will return a `Promise`, additionally you can pass a callback function as the last parameter. @@ -988,6 +989,7 @@ Methods `.export()` and also `.import()` are always async as well as every metho `Resolver` Properties: - resolver.[**result**](doc/resolver.md) +- resolver.[**await**](doc/resolver.md) (Async) --- @@ -998,6 +1000,7 @@ Methods `.export()` and also `.import()` are always async as well as every metho - _async_ db.[**close**](doc/persistent.md)() - _async_ db.[**destroy**](doc/persistent.md)() - _async_ db.[**clear**](doc/persistent.md)() +- _async_ db.[**commit**](doc/persistent.md)(index) --- diff --git a/dist/db/clickhouse/index.cjs b/dist/db/clickhouse/index.cjs index acd2f7e..457ce8e 100644 --- a/dist/db/clickhouse/index.cjs +++ b/dist/db/clickhouse/index.cjs @@ -519,36 +519,25 @@ ClickhouseDB.prototype.transaction = function(task){ return task.call(this); }; -ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ +ClickhouseDB.prototype.commit = async function(flexsearch){ - - if(_replace){ - await this.clear(); - - flexsearch.commit_task = []; - } - else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else { - tasks[i] = task.del; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); } + else if(task["ins"]); } + + if(removals.length){ + await this.remove(removals); + } + if(!flexsearch.reg.size){ return; } diff --git a/dist/db/indexeddb/index.cjs b/dist/db/indexeddb/index.cjs index 25fe192..14af091 100644 --- a/dist/db/indexeddb/index.cjs +++ b/dist/db/indexeddb/index.cjs @@ -9,20 +9,6 @@ function create_object(){ return Object.create(null); -} - -/** - * @param {Map|Set} val - * @param {boolean=} stringify - * @return {Array} - */ - -function toArray(val, stringify){ - const result = []; - for(const key of val.keys()){ - result.push(key); - } - return result; } const VERSION = 1; @@ -363,36 +349,25 @@ IdxDB.prototype.transaction = function(ref, modifier, task){ }; -IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ +IdxDB.prototype.commit = async function(flexsearch){ - - if(_replace){ - await this.clear(); + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); + } + + - flexsearch.commit_task = []; } - else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - /** @dict */ - task = tasks[i]; - - if(task["clear"]){ - await this.clear(); - _replace = true; - break; - } - else { - tasks[i] = task["del"]; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); - } + + if(removals.length){ + await this.remove(removals); } if(!flexsearch.reg.size){ @@ -407,10 +382,10 @@ IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ const value = item[1]; if(!value.length) continue; - if(_replace){ - store.put(value, key); - continue; - } + + + + store.get(key).onsuccess = function(){ let result = this.result; @@ -464,10 +439,10 @@ IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ const value = item[1]; if(!value.length) continue; - if(_replace){ - store.put(value, ctx_key + ":" + key); - continue; - } + + + + store.get(ctx_key + ":" + key).onsuccess = function(){ let result = this.result; diff --git a/dist/db/mongodb/index.cjs b/dist/db/mongodb/index.cjs index eb6e5b2..c0df5ad 100644 --- a/dist/db/mongodb/index.cjs +++ b/dist/db/mongodb/index.cjs @@ -2,27 +2,6 @@ var mongodb = require('mongodb'); -/** - * @param {*} value - * @param {*} default_value - * @param {*=} merge_value - * @return {*} - */ - -/** - * @param {Map|Set} val - * @param {boolean=} stringify - * @return {Array} - */ - -function toArray(val, stringify){ - const result = []; - for(const key of val.keys()){ - result.push(key); - } - return result; -} - const defaults = { host: "localhost", port: "27017", @@ -565,35 +544,23 @@ MongoDB.prototype.transaction = function(task){ return task.call(this); }; -MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ +MongoDB.prototype.commit = async function(flexsearch){ - - if(_replace){ - await this.clear(); - - flexsearch.commit_task = []; + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); + } + else if(task["ins"]); } - else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else { - tasks[i] = task.del; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); - } + + if(removals.length){ + await this.remove(removals); } if(!flexsearch.reg.size){ diff --git a/dist/db/postgres/index.cjs b/dist/db/postgres/index.cjs index ba7a078..7641aee 100644 --- a/dist/db/postgres/index.cjs +++ b/dist/db/postgres/index.cjs @@ -11,20 +11,6 @@ var pg_promise = require('pg-promise'); function concat(arrays){ return [].concat.apply([], arrays); -} - -/** - * @param {Map|Set} val - * @param {boolean=} stringify - * @return {Array} - */ - -function toArray(val, stringify){ - const result = []; - for(const key of val.keys()){ - result.push(key); - } - return result; } const defaults = { @@ -565,37 +551,23 @@ PostgresDB.prototype.transaction = function(task){ }; -PostgresDB.prototype.commit = async function(flexsearch, _replace, _append){ +PostgresDB.prototype.commit = async function(flexsearch){ - - if(_replace){ - await this.clear(); - - flexsearch.commit_task = []; + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); + } + else if(task["ins"]); } - else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else { - tasks[i] = task.del; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); - } - + if(removals.length){ + await this.remove(removals); } if(!flexsearch.reg.size){ diff --git a/dist/db/redis/index.cjs b/dist/db/redis/index.cjs index 5b39f02..3cb8241 100644 --- a/dist/db/redis/index.cjs +++ b/dist/db/redis/index.cjs @@ -342,35 +342,23 @@ RedisDB.prototype.transaction = function(task, callback){ }); }; -RedisDB.prototype.commit = async function(flexsearch, _replace, _append){ +RedisDB.prototype.commit = async function(flexsearch){ - - if(_replace){ - await this.clear(); - - flexsearch.commit_task = []; + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); + } + else if(task["ins"]); } - else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else { - tasks[i] = "" + task.del; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); - } + + if(removals.length){ + await this.remove(removals); } if(!flexsearch.reg.size){ diff --git a/dist/db/sqlite/index.cjs b/dist/db/sqlite/index.cjs index 541953e..ee06546 100644 --- a/dist/db/sqlite/index.cjs +++ b/dist/db/sqlite/index.cjs @@ -276,10 +276,12 @@ function create_result(rows, resolve, enrich){ } SqliteDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = true, enrich = false, tags){ + let result; let stmt = ''; let params = ctx ? [ctx, key] : [key]; let table = "main." + (ctx ? "ctx" : "map") + this.field; + if(tags){ for(let i = 0; i < tags.length; i+=2){ stmt += ` AND ${ table }.id IN (SELECT id FROM main.tag_${ sanitize(tags[i]) } WHERE tag = ?)`; @@ -324,12 +326,14 @@ SqliteDB.prototype.get = function(key, ctx, limit = 0, offset = 0, resolve = tru params }); } + return result.then(function(rows){ return create_result(rows, resolve, enrich); }); }; SqliteDB.prototype.tag = function(tag, limit = 0, offset = 0, enrich = false){ + const table = "main.tag" + this.field; const promise = this.promisfy({ method: "all", @@ -346,17 +350,25 @@ SqliteDB.prototype.tag = function(tag, limit = 0, offset = 0, enrich = false){ `, params: [tag] }); + enrich || promise.then(function(rows){ return create_result(rows, true, false); }); + return promise; }; function build_params(length, single_param){ + + + + + let stmt = single_param ? ",(?)" : ",?"; + for(let i = 1; i < length;){ if(i <= (length - i)){ stmt += stmt; @@ -367,6 +379,7 @@ function build_params(length, single_param){ break; } } + return stmt.substring(1); } @@ -383,16 +396,9 @@ SqliteDB.prototype.enrich = function(ids){ const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids; + const stmt = build_params(chunk.length); count += chunk.length; - - - - - - - let stmt = build_params(chunk.length); - promises.push(this.promisfy({ method: "all", stmt: `SELECT id, doc FROM main.reg WHERE id IN (${stmt})`, @@ -615,37 +621,29 @@ SqliteDB.prototype.transaction = async function(task, callback){ }); }; -SqliteDB.prototype.commit = async function(flexsearch, _replace, _append){ +SqliteDB.prototype.commit = async function(flexsearch){ + let tasks = flexsearch.commit_task; + let removals = []; + let inserts = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + task = tasks[i]; + if(typeof task["del"] !== "undefined"){ + removals.push(task["del"]); + } + else if(typeof task["ins"] !== "undefined"){ + inserts.push(task["ins"]); + } + } + + if(removals.length){ + await this.remove(removals); + } + + - if(_replace){ - await this.clear(); - - flexsearch.commit_task = []; - } - else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else { - tasks[i] = task.del; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); - } - } - if(!flexsearch.reg.size){ return; } @@ -666,7 +664,11 @@ SqliteDB.prototype.commit = async function(flexsearch, _replace, _append){ params.push(key, i, ids[j]); if((j === ids.length - 1) || (params.length + 3 > MAXIMUM_QUERY_VARS)){ - this.db.run("INSERT INTO main.map" + this.field + " (key, res, id) VALUES " + stmt, params); + this.db.run( + "INSERT INTO main.map" + this.field + " (key, res, id) VALUES " + stmt + + + , params); stmt = ""; params = []; } @@ -721,13 +723,13 @@ SqliteDB.prototype.commit = async function(flexsearch, _replace, _append){ : doc || null ); if(chunk.length + 2 > MAXIMUM_QUERY_VARS){ - this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); stmt = ""; chunk = []; } } if(chunk.length){ - this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); } } else if(!flexsearch.bypass){ @@ -738,7 +740,7 @@ SqliteDB.prototype.commit = async function(flexsearch, _replace, _append){ : count ? ids.slice(count) : ids; count += chunk.length; const stmt = build_params(chunk.length, true); - this.db.run("INSERT INTO main.reg (id) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); } } @@ -767,6 +769,10 @@ SqliteDB.prototype.commit = async function(flexsearch, _replace, _append){ } }); + if(inserts.length){ + await this.cleanup(); + } + @@ -823,6 +829,34 @@ SqliteDB.prototype.remove = function(ids){ }); }; +SqliteDB.prototype.cleanup = function(){ + return this.transaction(function(){ + this.db.run( + "DELETE FROM main.map" + this.field + " " + + "WHERE ROWID IN (" + + "SELECT ROWID FROM (" + + "SELECT ROWID, row_number() OVER dupes AS count " + + "FROM main.map" + this.field + " _t " + + "WINDOW dupes AS (PARTITION BY id, key ORDER BY res) " + + ") " + + "WHERE count > 1" + + ")" + + ); + this.db.run( + "DELETE FROM main.ctx" + this.field + " " + + "WHERE ROWID IN (" + + "SELECT ROWID FROM (" + + "SELECT ROWID, row_number() OVER dupes AS count " + + "FROM main.ctx" + this.field + " _t " + + "WINDOW dupes AS (PARTITION BY id, ctx, key ORDER BY res) " + + ") " + + "WHERE count > 1" + + ")" + ); + }); +}; + SqliteDB.prototype.promisfy = function(opt){ const db = this.db; return new Promise(function(resolve, reject){ diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index d1eff5b..b2d972e 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.203 (Bundle/Debug) + * FlexSearch.js v0.8.205 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -13,8 +13,8 @@ function H(a, c, b) { if (d !== "undefined") { if (b) { if (d === "function" && e === d) { - return function(k) { - return a(b(k)); + return function(h) { + return a(b(h)); }; } c = a.constructor; @@ -56,14 +56,7 @@ function N(a) { function ba(a) { return typeof a === "object"; } -function ca(a) { - const c = []; - for (const b of a.keys()) { - c.push(b); - } - return c; -} -function da(a, c) { +function ca(a, c) { if (N(c)) { a = a[c]; } else { @@ -73,10 +66,10 @@ function da(a, c) { } return a; } -;const fa = /[^\p{L}\p{N}]+/u, ha = /(\d{3})/g, ia = /(\D)(\d{3})/g, ja = /(\d{3})(\D)/g, ka = /[\u0300-\u036f]/g; -function la(a = {}) { - if (!this || this.constructor !== la) { - return new la(...arguments); +;const da = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = /[\u0300-\u036f]/g; +function ka(a = {}) { + if (!this || this.constructor !== ka) { + return new ka(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -86,7 +79,7 @@ function la(a = {}) { this.assign(a); } } -w = la.prototype; +w = ka.prototype; w.assign = function(a) { this.normalize = H(a.normalize, !0, this.normalize); let c = a.include, b = c || a.exclude || a.split, e; @@ -114,7 +107,7 @@ w.assign = function(a) { this.numeric = H(a.numeric, e); } else { try { - this.split = H(this.split, fa); + this.split = H(this.split, da); } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } @@ -156,12 +149,12 @@ w.addStemmer = function(a, c) { this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.K = null; - this.cache && ma(this); + this.cache && la(this); return this; }; w.addFilter = function(a) { typeof a === "function" ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && ma(this); + this.cache && la(this); return this; }; w.addMapper = function(a, c) { @@ -173,7 +166,7 @@ w.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && ma(this); + this.cache && la(this); return this; }; w.addMatcher = function(a, c) { @@ -187,7 +180,7 @@ w.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.J = null; - this.cache && ma(this); + this.cache && la(this); return this; }; w.addReplacer = function(a, c) { @@ -196,7 +189,7 @@ w.addReplacer = function(a, c) { } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && ma(this); + this.cache && la(this); return this; }; w.encode = function(a, c) { @@ -206,78 +199,78 @@ w.encode = function(a, c) { return this.B.get(a); } } else { - this.F = setTimeout(ma, 50, this); + this.F = setTimeout(la, 50, this); } } - this.normalize && (typeof this.normalize === "function" ? a = this.normalize(a) : a = ka ? a.normalize("NFKD").replace(ka, "").toLowerCase() : a.toLowerCase()); + this.normalize && (typeof this.normalize === "function" ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && a.length > 3 && (a = a.replace(ia, "$1 $2").replace(ja, "$1 $2").replace(ha, "$1 ")); + this.numeric && a.length > 3 && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = I(), f, g, k = this.split || this.split === "" ? a.split(this.split) : [a]; - for (let l = 0, n, q; l < k.length; l++) { - if ((n = q = k[l]) && !(n.length < this.minlength || n.length > this.maxlength)) { + let e = [], d = I(), f, g, h = this.split || this.split === "" ? a.split(this.split) : [a]; + for (let l = 0, m, p; l < h.length; l++) { + if ((m = p = h[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (c) { - if (d[n]) { + if (d[m]) { continue; } - d[n] = 1; + d[m] = 1; } else { - if (f === n) { + if (f === m) { continue; } - f = n; + f = m; } if (b) { - e.push(n); + e.push(m); } else { - if (!this.filter || (typeof this.filter === "function" ? this.filter(n) : !this.filter.has(n))) { - if (this.cache && n.length <= this.I) { + if (!this.filter || (typeof this.filter === "function" ? this.filter(m) : !this.filter.has(m))) { + if (this.cache && m.length <= this.I) { if (this.F) { - var h = this.D.get(n); - if (h || h === "") { - h && e.push(h); + var k = this.D.get(m); + if (k || k === "") { + k && e.push(k); continue; } } else { - this.F = setTimeout(ma, 50, this); + this.F = setTimeout(la, 50, this); } } if (this.stemmer) { this.K || (this.K = new RegExp("(?!^)(" + this.A + ")$")); let u; - for (; u !== n && n.length > 2;) { - u = n, n = n.replace(this.K, r => this.stemmer.get(r)); + for (; u !== m && m.length > 2;) { + u = m, m = m.replace(this.K, r => this.stemmer.get(r)); } } - if (n && (this.mapper || this.dedupe && n.length > 1)) { - h = ""; - for (let u = 0, r = "", t, m; u < n.length; u++) { - t = n.charAt(u), t === r && this.dedupe || ((m = this.mapper && this.mapper.get(t)) || m === "" ? m === r && this.dedupe || !(r = m) || (h += m) : h += r = t); + if (m && (this.mapper || this.dedupe && m.length > 1)) { + k = ""; + for (let u = 0, r = "", t, n; u < m.length; u++) { + t = m.charAt(u), t === r && this.dedupe || ((n = this.mapper && this.mapper.get(t)) || n === "" ? n === r && this.dedupe || !(r = n) || (k += n) : k += r = t); } - n = h; + m = k; } - this.matcher && n.length > 1 && (this.J || (this.J = new RegExp("(" + this.h + ")", "g")), n = n.replace(this.J, u => this.matcher.get(u))); - if (n && this.replacer) { - for (h = 0; n && h < this.replacer.length; h += 2) { - n = n.replace(this.replacer[h], this.replacer[h + 1]); + this.matcher && m.length > 1 && (this.J || (this.J = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.J, u => this.matcher.get(u))); + if (m && this.replacer) { + for (k = 0; m && k < this.replacer.length; k += 2) { + m = m.replace(this.replacer[k], this.replacer[k + 1]); } } - this.cache && q.length <= this.I && (this.D.set(q, n), this.D.size > this.L && (this.D.clear(), this.I = this.I / 1.1 | 0)); - if (n) { - if (n !== q) { + this.cache && p.length <= this.I && (this.D.set(p, m), this.D.size > this.L && (this.D.clear(), this.I = this.I / 1.1 | 0)); + if (m) { + if (m !== p) { if (c) { - if (d[n]) { + if (d[m]) { continue; } - d[n] = 1; + d[m] = 1; } else { - if (g === n) { + if (g === m) { continue; } - g = n; + g = m; } } - e.push(n); + e.push(m); } } } @@ -287,18 +280,18 @@ w.encode = function(a, c) { this.cache && a.length <= this.H && (this.B.set(a, e), this.B.size > this.L && (this.B.clear(), this.H = this.H / 1.1 | 0)); return e; }; -function ma(a) { +function la(a) { a.F = null; a.B.clear(); a.D.clear(); } -;function na(a, c, b) { +;function ma(a, c, b) { b || (c || typeof a !== "object" ? typeof c === "object" && (b = c, c = 0) : b = a); b && (a = b.query || a, c = b.limit || c); let e = "" + (c || 0); b && (e += (b.offset || 0) + !!b.context + !!b.suggest + (b.resolve !== !1) + (b.resolution || this.resolution) + (b.boost || 0)); a = ("" + a).toLowerCase(); - this.cache || (this.cache = new oa()); + this.cache || (this.cache = new na()); let d = this.cache.get(a + e); if (!d) { const f = b && b.cache; @@ -309,53 +302,53 @@ function ma(a) { } return d; } -function oa(a) { +function na(a) { this.limit = a && a !== !0 ? a : 1000; this.cache = new Map(); this.h = ""; } -oa.prototype.set = function(a, c) { +na.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -oa.prototype.get = function(a) { +na.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -oa.prototype.remove = function(a) { +na.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -oa.prototype.clear = function() { +na.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const ra = {normalize:!1, numeric:!1, dedupe:!1}; -const sa = {}; -const ta = 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 ua = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), va = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const wa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -var xa = {Exact:ra, Default:sa, Normalize:sa, LatinBalance:{mapper:ta}, LatinAdvanced:{mapper:ta, matcher:ua, replacer:va}, LatinExtra:{mapper:ta, replacer:va.concat([/(?!^)[aeo]/g, ""]), matcher:ua}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +const oa = {normalize:!1, numeric:!1, dedupe:!1}; +const ra = {}; +const sa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const ta = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ua = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const va = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +var wa = {Exact:oa, Default:ra, Normalize:ra, LatinBalance:{mapper:sa}, LatinAdvanced:{mapper:sa, matcher:ta, replacer:ua}, LatinExtra:{mapper:sa, replacer:ua.concat([/(?!^)[aeo]/g, ""]), matcher:ta}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = wa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), g === "h" || g === "w" || !(g = wa[g]) || g === d || (e += g, d = g, e.length !== 4)); f++) { + let e = c.charAt(0), d = va[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), g === "h" || g === "w" || !(g = va[g]) || g === d || (e += g, d = g, e.length !== 4)); f++) { } a[b] = e; } -}}, CJK:{split:""}, LatinExact:ra, LatinDefault:sa, LatinSimple:sa}; -function Aa(a, c, b, e) { +}}, CJK:{split:""}, LatinExact:oa, LatinDefault:ra, LatinSimple:ra}; +function xa(a, c, b, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], c >= g.length) { c -= g.length; } else { c = g[e ? "splice" : "slice"](c, b); - const k = c.length; - if (k && (d = d.length ? d.concat(c) : c, b -= k, e && (a.length -= k), !b)) { + const h = c.length; + if (h && (d = d.length ? d.concat(c) : c, b -= h, e && (a.length -= h), !b)) { break; } c = 0; @@ -363,9 +356,9 @@ function Aa(a, c, b, e) { } return d; } -function Ba(a) { - if (!this || this.constructor !== Ba) { - return new Ba(a); +function Aa(a) { + if (!this || this.constructor !== Aa) { + return new Aa(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -390,13 +383,13 @@ function Ba(a) { if (e === "indexOf") { return function(d) { let f = 0; - for (let g = 0, k, h; g < c.index.length; g++) { - k = c.index[g]; - h = k.indexOf(d); - if (h >= 0) { - return f + h; + for (let g = 0, h, k; g < c.index.length; g++) { + h = c.index[g]; + k = h.indexOf(d); + if (k >= 0) { + return f + k; } - f += k.length; + f += h.length; } return -1; }; @@ -413,12 +406,12 @@ function Ba(a) { } if (e === "slice") { return function(d, f) { - return Aa(c, d || 0, f || c.length, !1); + return xa(c, d || 0, f || c.length, !1); }; } if (e === "splice") { return function(d, f) { - return Aa(c, d || 0, f || c.length, !0); + return xa(c, d || 0, f || c.length, !0); }; } if (e === "constructor") { @@ -434,10 +427,10 @@ function Ba(a) { return !0; }}); } -Ba.prototype.clear = function() { +Aa.prototype.clear = function() { this.index.length = 0; }; -Ba.prototype.push = function() { +Aa.prototype.push = function() { }; function Q(a = 8) { if (!this || this.constructor !== Q) { @@ -446,7 +439,7 @@ function Q(a = 8) { this.index = I(); this.h = []; this.size = 0; - a > 32 ? (this.B = Ca, this.A = BigInt(a)) : (this.B = Da, this.A = a); + a > 32 ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } Q.prototype.get = function(a) { const c = this.index[this.B(a)]; @@ -464,7 +457,7 @@ function R(a = 8) { this.index = I(); this.h = []; this.size = 0; - a > 32 ? (this.B = Ca, this.A = BigInt(a)) : (this.B = Da, this.A = a); + a > 32 ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } R.prototype.add = function(a) { var c = this.B(a); @@ -506,7 +499,7 @@ w.entries = R.prototype.entries = function*() { } } }; -function Da(a) { +function Ca(a) { let c = 2 ** this.A - 1; if (typeof a == "number") { return a & c; @@ -517,7 +510,7 @@ function Da(a) { } return this.A === 32 ? b + 2 ** 31 : b; } -function Ca(a) { +function Ba(a) { let c = BigInt(2) ** this.A - BigInt(1); var b = typeof a; if (b === "bigint") { @@ -533,8 +526,8 @@ function Ca(a) { } return b; } -;let Ea, S; -async function Fa(a) { +;let Da, S; +async function Ea(a) { a = a.data; var c = a.task; const b = a.id; @@ -542,7 +535,7 @@ async function Fa(a) { switch(c) { case "init": S = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), Ea = new self.FlexSearch.Index(S), delete self.FlexSearch) : Ea = new T(S); + (c = a.factory) ? (Function("return " + c)()(self), Da = new self.FlexSearch.Index(S), delete self.FlexSearch) : Da = new T(S); postMessage({id:b}); break; default: @@ -557,33 +550,33 @@ async function Fa(a) { if (!S.import || typeof S.import !== "function") { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - e[0] && (a = await S.import.call(Ea, e[0]), Ea.import(e[0], a)); + e[0] && (a = await S.import.call(Da, e[0]), Da.import(e[0], a)); } else { - (d = e && Ea[c].apply(Ea, e)) && d.then && (d = await d), d && d.await && (d = await d.await), c === "search" && d.result && (d = d.result); + (d = e && Da[c].apply(Da, e)) && d.then && (d = await d), d && d.await && (d = await d.await), c === "search" && d.result && (d = d.result); } postMessage(c === "search" ? {id:b, msg:d} : {id:b}); } } -;function Ga(a) { - Ha.call(a, "add"); - Ha.call(a, "append"); - Ha.call(a, "search"); - Ha.call(a, "update"); - Ha.call(a, "remove"); - Ha.call(a, "searchCache"); +;function Fa(a) { + Ga.call(a, "add"); + Ga.call(a, "append"); + Ga.call(a, "search"); + Ga.call(a, "update"); + Ga.call(a, "remove"); + Ga.call(a, "searchCache"); } -let Ia, Ja, Ka; -function La() { - Ia = Ka = 0; +let Ha, Ia, Ja; +function Ka() { + Ha = Ja = 0; } -function Ha(a) { +function Ga(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; let e; typeof b === "function" && (e = b, delete c[c.length - 1]); - Ia ? Ka || (Ka = Date.now() - Ja >= this.priority * this.priority * 3) : (Ia = setTimeout(La, 0), Ja = Date.now()); - if (Ka) { + Ha ? Ja || (Ja = Date.now() - Ia >= this.priority * this.priority * 3) : (Ha = setTimeout(Ka, 0), Ia = Date.now()); + if (Ja) { const f = this; return new Promise(g => { setTimeout(function() { @@ -598,17 +591,17 @@ function Ha(a) { }; } ;let V = 0; -function Ma(a = {}, c) { - function b(k) { - function h(l) { +function La(a = {}, c) { + function b(h) { + function k(l) { l = l.data || l; - const n = l.id, q = n && f.h[n]; - q && (q(l.msg), delete f.h[n]); + const m = l.id, p = m && f.h[m]; + p && (p(l.msg), delete f.h[m]); } - this.worker = k; + this.worker = h; this.h = I(); if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; + d ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { return new Promise(function(l) { V > 1e9 && (V = 0); @@ -625,14 +618,14 @@ function Ma(a = {}, c) { } console.warn("Worker is not available on this platform. Please report on Github: https://github.com/nextapps-de/flexsearch/issues"); } - if (!this || this.constructor !== Ma) { - return new Ma(a); + if (!this || this.constructor !== La) { + return new La(a); } let e = typeof self !== "undefined" ? self._factory : typeof window !== "undefined" ? window._factory : null; e && (e = e.toString()); - const d = typeof window === "undefined", f = this, g = Na(e, d, a.worker); - return g.then ? g.then(function(k) { - return b.call(f, k); + const d = typeof window === "undefined", f = this, g = Ma(e, d, a.worker); + return g.then ? g.then(function(h) { + return b.call(f, h); }) : b.call(this, g); } W("add"); @@ -643,10 +636,10 @@ W("remove"); W("clear"); W("export"); W("import"); -Ma.prototype.searchCache = na; -Ga(Ma.prototype); +La.prototype.searchCache = ma; +Fa(La.prototype); function W(a) { - Ma.prototype[a] = function() { + La.prototype[a] = function() { const c = this, b = [].slice.call(arguments); var e = b[b.length - 1]; let d; @@ -660,25 +653,25 @@ function W(a) { return d ? (e.then(d), this) : e; }; } -function Na(a, c, b) { - return c ? typeof module !== "undefined" ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Fa.toString()], {type:"text/javascript"}))) : new window.Worker(typeof b === "string" ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ma(a, c, b) { + return c ? typeof module !== "undefined" ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ea.toString()], {type:"text/javascript"}))) : new window.Worker(typeof b === "string" ? b : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;Oa.prototype.add = function(a, c, b) { - ba(a) && (c = a, a = da(c, this.key)); +;Na.prototype.add = function(a, c, b) { + ba(a) && (c = a, a = ca(c, this.key)); if (c && (a || a === 0)) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let k = 0, h; k < this.field.length; k++) { - h = this.B[k]; - var e = this.index.get(this.field[k]); - if (typeof h === "function") { - var d = h(c); - d && e.add(a, d, !1, !0); + for (let h = 0, k; h < this.field.length; h++) { + k = this.B[h]; + var e = this.index.get(this.field[h]); + if (typeof k === "function") { + var d = k(c); + d && e.add(a, d, b, !0); } else { - if (d = h.G, !d || d(c)) { - h.constructor === String ? h = ["" + h] : N(h) && (h = [h]), Ra(c, h, this.D, 0, e, a, h[0], b); + if (d = k.G, !d || d(c)) { + k.constructor === String ? k = ["" + k] : N(k) && (k = [k]), Oa(c, k, this.D, 0, e, a, k[0], b); } } } @@ -686,34 +679,34 @@ function Na(a, c, b) { for (e = 0; e < this.A.length; e++) { var f = this.A[e], g = this.F[e]; d = this.tag.get(g); - let k = I(); + let h = I(); if (typeof f === "function") { if (f = f(c), !f) { continue; } } else { - const h = f.G; - if (h && !h(c)) { + const k = f.G; + if (k && !k(c)) { continue; } f.constructor === String && (f = "" + f); - f = da(c, f); + f = ca(c, f); } if (d && f) { N(f) && (f = [f]); - for (let h = 0, l, n; h < f.length; h++) { - if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? n = g : d.set(l, n = []), !b || !n.includes(a))) { - if (n.length === 2 ** 31 - 1) { - g = new Ba(n); + for (let k = 0, l, m; k < f.length; k++) { + if (l = f[k], !h[l] && (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !b || !m.includes(a))) { + if (m.length === 2 ** 31 - 1) { + g = new Aa(m); if (this.fastupdate) { - for (let q of this.reg.values()) { - q.includes(n) && (q[q.indexOf(n)] = g); + for (let p of this.reg.values()) { + p.includes(m) && (p[p.indexOf(m)] = g); } } - d.set(l, n = g); + d.set(l, m = g); } - n.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])); + m.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); } } } else { @@ -722,49 +715,49 @@ function Na(a, c, b) { } } if (this.store && (!b || !this.store.has(a))) { - let k; + let h; if (this.h) { - k = I(); - for (let h = 0, l; h < this.h.length; h++) { - l = this.h[h]; + h = I(); + for (let k = 0, l; k < this.h.length; k++) { + l = this.h[k]; if ((b = l.G) && !b(c)) { continue; } - let n; + let m; if (typeof l === "function") { - n = l(c); - if (!n) { + m = l(c); + if (!m) { continue; } l = [l.O]; } else if (N(l) || l.constructor === String) { - k[l] = c[l]; + h[l] = c[l]; continue; } - Sa(c, k, l, 0, l[0], n); + Ra(c, h, l, 0, l[0], m); } } - this.store.set(a, k || c); + this.store.set(a, h || c); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Sa(a, c, b, e, d, f) { +function Ra(a, c, b, e, d, f) { a = a[d]; if (e === b.length - 1) { c[d] = f || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Sa(a, c, b, e, d); + Ra(a, c, b, e, d); } } else { - c = c[d] || (c[d] = I()), d = b[++e], Sa(a, c, b, e, d); + c = c[d] || (c[d] = I()), d = b[++e], Ra(a, c, b, e, d); } } } -function Ra(a, c, b, e, d, f, g, k) { +function Oa(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -776,52 +769,52 @@ function Ra(a, c, b, e, d, f, g, k) { } a = a.join(" "); } - d.add(f, a, k, !0); + d.add(f, a, h, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ra(a, c, b, e, d, f, g, k); + Oa(a, c, b, e, d, f, g, h); } } else { - g = c[++e], Ra(a, c, b, e, d, f, g, k); + g = c[++e], Oa(a, c, b, e, d, f, g, h); } } } } -;function Ta(a, c, b, e) { +;function Sa(a, c, b, e) { if (!a.length) { return a; } if (a.length === 1) { - return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a, e ? Ua.call(this, a) : a; + return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a, e ? Ta.call(this, a) : a; } let d = []; - for (let f = 0, g, k; f < a.length; f++) { - if ((g = a[f]) && (k = g.length)) { + for (let f = 0, g, h; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { if (b) { - if (b >= k) { - b -= k; + if (b >= h) { + b -= h; continue; } g = g.slice(b, b + c); - k = g.length; + h = g.length; b = 0; } - k > c && (g = g.slice(0, c), k = c); - if (!d.length && k >= c) { - return e ? Ua.call(this, g) : g; + h > c && (g = g.slice(0, c), h = c); + if (!d.length && h >= c) { + return e ? Ta.call(this, g) : g; } d.push(g); - c -= k; + c -= h; if (!c) { break; } } } d = d.length > 1 ? [].concat.apply([], d) : d[0]; - return e ? Ua.call(this, d) : d; + return e ? Ta.call(this, d) : d; } -;function Va(a, c, b, e) { +;function Ua(a, c, b, e) { var d = e[0]; if (d[0] && d[0].query) { return a[c].apply(a, d); @@ -829,7 +822,7 @@ function Ra(a, c, b, e, d, f, g, k) { if (!(c !== "and" && c !== "not" || a.result.length || a.await || d.suggest)) { return e.length > 1 && (d = e[e.length - 1]), (e = d.resolve) ? a.await || a.result : a; } - let f = [], g = 0, k = 0, h, l, n, q, u; + let f = [], g = 0, h = 0, k, l, m, p, u; for (c = 0; c < e.length; c++) { if (d = e[c]) { var r = void 0; @@ -839,64 +832,65 @@ function Ra(a, c, b, e, d, f, g, k) { r = d; } else { g = d.limit || 0; - k = d.offset || 0; - n = d.suggest; - h = ((q = (l = d.resolve) && d.highlight) || d.enrich) && l; + h = d.offset || 0; + m = d.suggest; + l = d.resolve; + k = ((p = d.highlight || a.highlight) || d.enrich) && l; r = d.queue; - let t = d.async || r, m = d.index; - m ? a.index || (a.index = m) : m = a.index; - if (d.query || d.tag) { - if (!m) { + let t = d.async || r, n = d.index, q = d.query; + n ? a.index || (a.index = n) : n = a.index; + if (q || d.tag) { + if (!n) { throw Error("Resolver can't apply because the corresponding Index was never specified"); } - const p = d.field || d.pluck; - if (p) { - d.query && (a.query = d.query, a.field = p); - if (!m.index) { + const x = d.field || d.pluck; + if (x) { + !q || a.query && !p || (a.query = q, a.field = x, a.highlight = p); + if (!n.index) { throw Error("Resolver can't apply because the corresponding Document Index was not specified"); } - m = m.index.get(p); - if (!m) { - throw Error("Resolver can't apply because the specified Document Field '" + p + "' was not found"); + n = n.index.get(x); + if (!n) { + throw Error("Resolver can't apply because the specified Document Field '" + x + "' was not found"); } } if (r && (u || a.await)) { u = 1; - let x; - const v = a.C.length, A = new Promise(function(C) { - x = C; + let v; + const A = a.C.length, D = new Promise(function(G) { + v = G; }); - (function(C, G) { - A.h = function() { - G.index = null; - G.resolve = !1; - let B = t ? C.searchAsync(G) : C.search(G); + (function(G, E) { + D.h = function() { + E.index = null; + E.resolve = !1; + let B = t ? G.searchAsync(E) : G.search(E); if (B.then) { - return B.then(function(E) { - a.C[v] = E = E.result || E; - x(E); - return E; + return B.then(function(z) { + a.C[A] = z = z.result || z; + v(z); + return z; }); } B = B.result || B; - x(B); + v(B); return B; }; - })(m, Object.assign({}, d)); - a.C.push(A); - f[c] = A; + })(n, Object.assign({}, d)); + a.C.push(D); + f[c] = D; continue; } else { - d.resolve = !1, d.index = null, r = t ? m.searchAsync(d) : m.search(d), d.resolve = l, d.index = m; + d.resolve = !1, d.index = null, r = t ? n.searchAsync(d) : n.search(d), d.resolve = l, d.index = n; } } else if (d.and) { - r = Wa(d, "and", m); + r = Va(d, "and", n); } else if (d.or) { - r = Wa(d, "or", m); + r = Va(d, "or", n); } else if (d.not) { - r = Wa(d, "not", m); + r = Va(d, "not", n); } else if (d.xor) { - r = Wa(d, "xor", m); + r = Va(d, "xor", n); } else { continue; } @@ -911,28 +905,28 @@ function Ra(a, c, b, e, d, f, g, k) { a.return = t; })); if (u) { - const t = Promise.all(f).then(function(m) { - for (let p = 0; p < a.C.length; p++) { - if (a.C[p] === t) { - a.C[p] = function() { - return b.call(a, m, g, k, h, l, n, q); + const t = Promise.all(f).then(function(n) { + for (let q = 0; q < a.C.length; q++) { + if (a.C[q] === t) { + a.C[q] = function() { + return b.call(a, n, g, h, k, l, m, p); }; break; } } - Xa(a); + Wa(a); }); a.C.push(t); } else if (a.await) { a.C.push(function() { - return b.call(a, f, g, k, h, l, n, q); + return b.call(a, f, g, h, k, l, m, p); }); } else { - return b.call(a, f, g, k, h, l, n, q); + return b.call(a, f, g, h, k, l, m, p); } return l ? a.await || a.result : a; } -function Wa(a, c, b) { +function Va(a, c, b) { a = a[c]; const e = a[0] || a; e.index || (e.index = b); @@ -941,87 +935,87 @@ function Wa(a, c, b) { return b; } ;X.prototype.or = function() { - return Va(this, "or", Ya, arguments); + return Ua(this, "or", Xa, arguments); }; -function Ya(a, c, b, e, d, f, g) { - a.length && (this.result.length && a.push(this.result), a.length < 2 ? this.result = a[0] : (this.result = Za(a, c, b, !1, this.h), b = 0)); +function Xa(a, c, b, e, d, f, g) { + a.length && (this.result.length && a.push(this.result), a.length < 2 ? this.result = a[0] : (this.result = Ya(a, c, b, !1, this.h), b = 0)); d && (this.await = null); return d ? this.resolve(c, b, e, g) : this; } ;X.prototype.and = function() { - return Va(this, "and", $a, arguments); + return Ua(this, "and", Za, arguments); }; -function $a(a, c, b, e, d, f, g) { +function Za(a, c, b, e, d, f, g) { if (!f && !this.result.length) { return d ? this.result : this; } - let k; + let h; if (a.length) { if (this.result.length && a.unshift(this.result), a.length < 2) { this.result = a[0]; } else { - let h = 0; - for (let l = 0, n, q; l < a.length; l++) { - if ((n = a[l]) && (q = n.length)) { - h < q && (h = q); + let k = 0; + for (let l = 0, m, p; l < a.length; l++) { + if ((m = a[l]) && (p = m.length)) { + k < p && (k = p); } else if (!f) { - h = 0; + k = 0; break; } } - h ? (this.result = ab(a, h, c, b, f, this.h, d), k = !0) : this.result = []; + k ? (this.result = $a(a, k, c, b, f, this.h, d), h = !0) : this.result = []; } } else { f || (this.result = a); } d && (this.await = null); - return d ? this.resolve(c, b, e, g, k) : this; + return d ? this.resolve(c, b, e, g, h) : this; } ;X.prototype.xor = function() { - return Va(this, "xor", bb, arguments); + return Ua(this, "xor", ab, arguments); }; -function bb(a, c, b, e, d, f, g) { +function ab(a, c, b, e, d, f, g) { if (a.length) { if (this.result.length && a.unshift(this.result), a.length < 2) { this.result = a[0]; } else { a: { f = b; - var k = this.h; - const h = [], l = I(); - let n = 0; - for (let q = 0, u; q < a.length; q++) { - if (u = a[q]) { - n < u.length && (n = u.length); + var h = this.h; + const k = [], l = I(); + let m = 0; + for (let p = 0, u; p < a.length; p++) { + if (u = a[p]) { + m < u.length && (m = u.length); for (let r = 0, t; r < u.length; r++) { if (t = u[r]) { - for (let m = 0, p; m < t.length; m++) { - p = t[m], l[p] = l[p] ? 2 : 1; + for (let n = 0, q; n < t.length; n++) { + q = t[n], l[q] = l[q] ? 2 : 1; } } } } } - for (let q = 0, u, r = 0; q < n; q++) { - for (let t = 0, m; t < a.length; t++) { - if (m = a[t]) { - if (u = m[q]) { - for (let p = 0, x; p < u.length; p++) { - if (x = u[p], l[x] === 1) { + for (let p = 0, u, r = 0; p < m; p++) { + for (let t = 0, n; t < a.length; t++) { + if (n = a[t]) { + if (u = n[p]) { + for (let q = 0, x; q < u.length; q++) { + if (x = u[q], l[x] === 1) { if (f) { f--; } else { if (d) { - if (h.push(x), h.length === c) { - a = h; + if (k.push(x), k.length === c) { + a = k; break a; } } else { - const v = q + (t ? k : 0); - h[v] || (h[v] = []); - h[v].push(x); + const v = p + (t ? h : 0); + k[v] || (k[v] = []); + k[v].push(x); if (++r === c) { - a = h; + a = k; break a; } } @@ -1032,44 +1026,44 @@ function bb(a, c, b, e, d, f, g) { } } } - a = h; + a = k; } this.result = a; - k = !0; + h = !0; } } else { f || (this.result = a); } d && (this.await = null); - return d ? this.resolve(c, b, e, g, k) : this; + return d ? this.resolve(c, b, e, g, h) : this; } ;X.prototype.not = function() { - return Va(this, "not", cb, arguments); + return Ua(this, "not", bb, arguments); }; -function cb(a, c, b, e, d, f, g) { +function bb(a, c, b, e, d, f, g) { if (!f && !this.result.length) { return d ? this.result : this; } if (a.length && this.result.length) { a: { f = b; - var k = []; + var h = []; a = new Set(a.flat().flat()); - for (let h = 0, l, n = 0; h < this.result.length; h++) { - if (l = this.result[h]) { - for (let q = 0, u; q < l.length; q++) { - if (u = l[q], !a.has(u)) { + for (let k = 0, l, m = 0; k < this.result.length; k++) { + if (l = this.result[k]) { + for (let p = 0, u; p < l.length; p++) { + if (u = l[p], !a.has(u)) { if (f) { f--; } else { if (d) { - if (k.push(u), k.length === c) { - a = k; + if (h.push(u), h.length === c) { + a = h; break a; } } else { - if (k[h] || (k[h] = []), k[h].push(u), ++n === c) { - a = k; + if (h[k] || (h[k] = []), h[k].push(u), ++m === c) { + a = h; break a; } } @@ -1078,16 +1072,16 @@ function cb(a, c, b, e, d, f, g) { } } } - a = k; + a = h; } this.result = a; - k = !0; + h = !0; } d && (this.await = null); - return d ? this.resolve(c, b, e, g, k) : this; + return d ? this.resolve(c, b, e, g, h) : this; } -;function db(a, c, b, e, d) { - let f, g, k; +;function cb(a, c, b, e, d) { + let f, g, h; typeof d === "string" ? (f = d, d = "") : f = d.template; if (!f) { throw Error('No template pattern was specified by the search option "highlight"'); @@ -1096,201 +1090,201 @@ function cb(a, c, b, e, d, f, g) { if (g === -1) { throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); } - k = f.substring(g + 2); + h = f.substring(g + 2); g = f.substring(0, g); - let h = d && d.boundary, l = !d || d.clip !== !1, n = d && d.merge && k && g && new RegExp(k + " " + g, "g"); + let k = d && d.boundary, l = !d || d.clip !== !1, m = d && d.merge && h && g && new RegExp(h + " " + g, "g"); d = d && d.ellipsis; - var q = 0; + var p = 0; if (typeof d === "object") { var u = d.template; - q = u.length - 2; + p = u.length - 2; d = d.pattern; } typeof d !== "string" && (d = d === !1 ? "" : "..."); - q && (d = u.replace("$1", d)); - u = d.length - q; + p && (d = u.replace("$1", d)); + u = d.length - p; let r, t; - typeof h === "object" && (r = h.before, r === 0 && (r = -1), t = h.after, t === 0 && (t = -1), h = h.total || 9e5); - q = new Map(); + typeof k === "object" && (r = k.before, r === 0 && (r = -1), t = k.after, t === 0 && (t = -1), k = k.total || 9e5); + p = new Map(); for (let Pa = 0, ea, gb, pa; Pa < c.length; Pa++) { let qa; if (e) { qa = c, pa = e; } else { - var m = c[Pa]; - pa = m.field; + var n = c[Pa]; + pa = n.field; if (!pa) { continue; } - qa = m.result; + qa = n.result; } gb = b.get(pa); ea = gb.encoder; - m = q.get(ea); - typeof m !== "string" && (m = ea.encode(a), q.set(ea, m)); + n = p.get(ea); + typeof n !== "string" && (n = ea.encode(a), p.set(ea, n)); for (let ya = 0; ya < qa.length; ya++) { - var p = qa[ya].doc; - if (!p) { + var q = qa[ya].doc; + if (!q) { continue; } - p = da(p, pa); - if (!p) { + q = ca(q, pa); + if (!q) { continue; } - var x = p.trim().split(/\s+/); + var x = q.trim().split(/\s+/); if (!x.length) { continue; } - p = ""; + q = ""; var v = []; let za = []; - var A = -1, C = -1, G = 0; - for (var B = 0; B < x.length; B++) { - var E = x[B], z = ea.encode(E); + var A = -1, D = -1, G = 0; + for (var E = 0; E < x.length; E++) { + var B = x[E], z = ea.encode(B); z = z.length > 1 ? z.join(" ") : z[0]; let y; - if (z && E) { - var D = E.length, K = (ea.split ? E.replace(ea.split, "") : E).length - z.length, F = "", L = 0; - for (var O = 0; O < m.length; O++) { - var P = m[O]; + if (z && B) { + var C = B.length, K = (ea.split ? B.replace(ea.split, "") : B).length - z.length, F = "", L = 0; + for (var O = 0; O < n.length; O++) { + var P = n[O]; if (P) { var M = P.length; M += K; - L && M <= L || (P = z.indexOf(P), P > -1 && (F = (P ? E.substring(0, P) : "") + g + E.substring(P, P + M) + k + (P + M < D ? E.substring(P + M) : ""), L = M, y = !0)); + L && M <= L || (P = z.indexOf(P), P > -1 && (F = (P ? B.substring(0, P) : "") + g + B.substring(P, P + M) + h + (P + M < C ? B.substring(P + M) : ""), L = M, y = !0)); } } - F && (h && (A < 0 && (A = p.length + (p ? 1 : 0)), C = p.length + (p ? 1 : 0) + F.length, G += D, za.push(v.length), v.push({match:F})), p += (p ? " " : "") + F); + F && (k && (A < 0 && (A = q.length + (q ? 1 : 0)), D = q.length + (q ? 1 : 0) + F.length, G += C, za.push(v.length), v.push({match:F})), q += (q ? " " : "") + F); } if (!y) { - E = x[B], p += (p ? " " : "") + E, h && v.push({text:E}); - } else if (h && G >= h) { + B = x[E], q += (q ? " " : "") + B, k && v.push({text:B}); + } else if (k && G >= k) { break; } } G = za.length * (f.length - 2); - if (r || t || h && p.length - G > h) { - if (G = h + G - u * 2, B = C - A, r > 0 && (B += r), t > 0 && (B += t), B <= G) { - x = r ? A - (r > 0 ? r : 0) : A - ((G - B) / 2 | 0), v = t ? C + (t > 0 ? t : 0) : x + G, l || (x > 0 && p.charAt(x) !== " " && p.charAt(x - 1) !== " " && (x = p.indexOf(" ", x), x < 0 && (x = 0)), v < p.length && p.charAt(v - 1) !== " " && p.charAt(v) !== " " && (v = p.lastIndexOf(" ", v), v < C ? v = C : ++v)), p = (x ? d : "") + p.substring(x, v) + (v < p.length ? d : ""); + if (r || t || k && q.length - G > k) { + if (G = k + G - u * 2, E = D - A, r > 0 && (E += r), t > 0 && (E += t), E <= G) { + x = r ? A - (r > 0 ? r : 0) : A - ((G - E) / 2 | 0), v = t ? D + (t > 0 ? t : 0) : x + G, l || (x > 0 && q.charAt(x) !== " " && q.charAt(x - 1) !== " " && (x = q.indexOf(" ", x), x < 0 && (x = 0)), v < q.length && q.charAt(v - 1) !== " " && q.charAt(v) !== " " && (v = q.lastIndexOf(" ", v), v < D ? v = D : ++v)), q = (x ? d : "") + q.substring(x, v) + (v < q.length ? d : ""); } else { - C = []; + D = []; A = {}; G = {}; - B = {}; E = {}; + B = {}; z = {}; - F = K = D = 0; + F = K = C = 0; for (O = L = 1;;) { var U = void 0; for (let y = 0, J; y < za.length; y++) { J = za[y]; if (F) { if (K !== F) { - if (B[y + 1]) { + if (E[y + 1]) { continue; } J += F; if (A[J]) { - D -= u; + C -= u; G[y + 1] = 1; - B[y + 1] = 1; + E[y + 1] = 1; continue; } if (J >= v.length - 1) { if (J >= v.length) { - B[y + 1] = 1; + E[y + 1] = 1; J >= x.length && (G[y + 1] = 1); continue; } - D -= u; + C -= u; } - p = v[J].text; + q = v[J].text; if (M = t && z[y]) { if (M > 0) { - if (p.length > M) { - if (B[y + 1] = 1, l) { - p = p.substring(0, M); + if (q.length > M) { + if (E[y + 1] = 1, l) { + q = q.substring(0, M); } else { continue; } } - (M -= p.length) || (M = -1); + (M -= q.length) || (M = -1); z[y] = M; } else { - B[y + 1] = 1; + E[y + 1] = 1; continue; } } - if (D + p.length + 1 <= h) { - p = " " + p, C[y] += p; + if (C + q.length + 1 <= k) { + q = " " + q, D[y] += q; } else if (l) { - U = h - D - 1, U > 0 && (p = " " + p.substring(0, U), C[y] += p), B[y + 1] = 1; + U = k - C - 1, U > 0 && (q = " " + q.substring(0, U), D[y] += q), E[y + 1] = 1; } else { - B[y + 1] = 1; + E[y + 1] = 1; continue; } } else { - if (B[y]) { + if (E[y]) { continue; } J -= K; if (A[J]) { - D -= u; - B[y] = 1; + C -= u; + E[y] = 1; G[y] = 1; continue; } if (J <= 0) { if (J < 0) { - B[y] = 1; + E[y] = 1; G[y] = 1; continue; } - D -= u; + C -= u; } - p = v[J].text; - if (M = r && E[y]) { + q = v[J].text; + if (M = r && B[y]) { if (M > 0) { - if (p.length > M) { - if (B[y] = 1, l) { - p = p.substring(p.length - M); + if (q.length > M) { + if (E[y] = 1, l) { + q = q.substring(q.length - M); } else { continue; } } - (M -= p.length) || (M = -1); - E[y] = M; + (M -= q.length) || (M = -1); + B[y] = M; } else { - B[y] = 1; + E[y] = 1; continue; } } - if (D + p.length + 1 <= h) { - p += " ", C[y] = p + C[y]; + if (C + q.length + 1 <= k) { + q += " ", D[y] = q + D[y]; } else if (l) { - U = p.length + 1 - (h - D), U >= 0 && U < p.length && (p = p.substring(U) + " ", C[y] = p + C[y]), B[y] = 1; + U = q.length + 1 - (k - C), U >= 0 && U < q.length && (q = q.substring(U) + " ", D[y] = q + D[y]), E[y] = 1; } else { - B[y] = 1; + E[y] = 1; continue; } } } else { - p = v[J].match; - r && (E[y] = r); + q = v[J].match; + r && (B[y] = r); t && (z[y] = t); - y && D++; + y && C++; let Qa; - J ? !y && u && (D += u) : (G[y] = 1, B[y] = 1); - J >= x.length - 1 ? Qa = 1 : J < v.length - 1 && v[J + 1].match ? Qa = 1 : u && (D += u); - D -= f.length - 2; - if (!y || D + p.length <= h) { - C[y] = p; + J ? !y && u && (C += u) : (G[y] = 1, E[y] = 1); + J >= x.length - 1 ? Qa = 1 : J < v.length - 1 && v[J + 1].match ? Qa = 1 : u && (C += u); + C -= f.length - 2; + if (!y || C + q.length <= k) { + D[y] = q; } else { U = L = O = G[y] = 0; break; } - Qa && (G[y + 1] = 1, B[y + 1] = 1); + Qa && (G[y + 1] = 1, E[y + 1] = 1); } - D += p.length; + C += q.length; U = A[J] = 1; } if (U) { @@ -1303,15 +1297,15 @@ function cb(a, c, b, e, d, f, g) { L ? (K++, F = K) : F++; } } - p = ""; - for (let y = 0, J; y < C.length; y++) { - J = (y && G[y] ? " " : (y && !d ? " " : "") + d) + C[y], p += J; + q = ""; + for (let y = 0, J; y < D.length; y++) { + J = (y && G[y] ? " " : (y && !d ? " " : "") + d) + D[y], q += J; } - d && !G[C.length] && (p += d); + d && !G[D.length] && (q += d); } } - n && (p = p.replace(n, " ")); - qa[ya].highlight = p; + m && (q = q.replace(m, " ")); + qa[ya].highlight = q; } if (e) { break; @@ -1323,43 +1317,45 @@ function cb(a, c, b, e, d, f, g) { if (!this || this.constructor !== X) { return new X(a, c); } - let b = 0, e, d, f, g, k; + let b = 0, e, d, f, g, h, k; if (a && a.index) { - const h = a; - c = h.index; - b = h.boost || 0; - if (d = h.query) { - f = h.field || h.pluck; - const l = h.resolve; - a = h.async || h.queue; - h.resolve = !1; - h.index = null; - a = a ? c.searchAsync(h) : c.search(h); - h.resolve = l; - h.index = c; + const l = a; + c = l.index; + b = l.boost || 0; + if (d = l.query) { + f = l.field || l.pluck; + g = l.highlight; + const m = l.resolve; + a = l.async || l.queue; + l.resolve = !1; + l.index = null; + a = a ? c.searchAsync(l) : c.search(l); + l.resolve = m; + l.index = c; a = a.result || a; } else { a = []; } } if (a && a.then) { - const h = this; - a = a.then(function(l) { - h.C[0] = h.result = l.result || l; - Xa(h); + const l = this; + a = a.then(function(m) { + l.C[0] = l.result = m.result || m; + Wa(l); }); e = [a]; a = []; - g = new Promise(function(l) { - k = l; + h = new Promise(function(m) { + k = m; }); } this.index = c || null; this.result = a || []; this.h = b; this.C = e || []; - this.await = g || null; + this.await = h || null; this.return = k || null; + this.highlight = g || null; this.query = d || ""; this.field = f || ""; } @@ -1368,8 +1364,7 @@ w.limit = function(a) { if (this.await) { const c = this; this.C.push(function() { - c.limit(a); - return c.result; + return c.limit(a).result; }); } else { if (this.result.length) { @@ -1395,8 +1390,7 @@ w.offset = function(a) { if (this.await) { const c = this; this.C.push(function() { - c.offset(a); - return c.result; + return c.offset(a).result; }); } else { if (this.result.length) { @@ -1415,15 +1409,14 @@ w.boost = function(a) { if (this.await) { const c = this; this.C.push(function() { - c.boost(a); - return c.result; + return c.boost(a).result; }); } else { this.h += a; } return this; }; -function Xa(a, c) { +function Wa(a, c) { let b = a.result; var e = a.await; a.await = null; @@ -1445,14 +1438,14 @@ function Xa(a, c) { return b; } w.resolve = function(a, c, b, e, d) { - let f = this.await ? Xa(this, !0) : this.result; + let f = this.await ? Wa(this, !0) : this.result; if (f.then) { const g = this; return f.then(function() { return g.resolve(a, c, b, e, d); }); } - f.length && (typeof a === "object" ? (e = a.highlight, b = !!e || a.enrich, c = a.offset, a = a.limit) : b = !!e || b, f = d ? b ? Ua.call(this.index, f) : f : Ta.call(this.index, f, a || 100, c, b)); + f.length && (typeof a === "object" ? (e = a.highlight || this.highlight, b = !!e || a.enrich, c = a.offset, a = a.limit) : (e = e || this.highlight, b = !!e || b), f = d ? b ? Ta.call(this.index, f) : f : Sa.call(this.index, f, a || 100, c, b)); return this.finalize(f, e); }; w.finalize = function(a, c) { @@ -1462,54 +1455,54 @@ w.finalize = function(a, c) { return e.finalize(d, c); }); } - c && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); - c && a.length && this.query && (a = db(this.query, a, this.index.index, this.field, c)); + c && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the highlight resolver stage like { query: "...", highlight: ... }.'); + c && a.length && this.query && (a = cb(this.query, a, this.index.index, this.field, c)); const b = this.return; - this.index = this.result = this.C = this.await = this.return = null; + this.highlight = this.index = this.result = this.C = this.await = this.return = null; this.query = this.field = ""; b && b(a); return a; }; -function ab(a, c, b, e, d, f, g) { - const k = a.length; - let h = [], l, n; +function $a(a, c, b, e, d, f, g) { + const h = a.length; + let k = [], l, m; l = I(); - for (let q = 0, u, r, t, m; q < c; q++) { - for (let p = 0; p < k; p++) { - if (t = a[p], q < t.length && (u = t[q])) { + for (let p = 0, u, r, t, n; p < c; p++) { + for (let q = 0; q < h; q++) { + if (t = a[q], p < t.length && (u = t[p])) { for (let x = 0; x < u.length; x++) { r = u[x]; - (n = l[r]) ? l[r]++ : (n = 0, l[r] = 1); - m = h[n] || (h[n] = []); + (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1); + n = k[m] || (k[m] = []); if (!g) { - let v = q + (p || !d ? 0 : f || 0); - m = m[v] || (m[v] = []); + let v = p + (q || !d ? 0 : f || 0); + n = n[v] || (n[v] = []); } - m.push(r); - if (g && b && n === k - 1 && m.length - e === b) { - return e ? m.slice(e) : m; + n.push(r); + if (g && b && m === h - 1 && n.length - e === b) { + return e ? n.slice(e) : n; } } } } } - if (a = h.length) { + if (a = k.length) { if (d) { - h = h.length > 1 ? Za(h, b, e, g, f) : (h = h[0]) && b && h.length > b || e ? h.slice(e, b + e) : h; + k = k.length > 1 ? Ya(k, b, e, g, f) : (k = k[0]) && b && k.length > b || e ? k.slice(e, b + e) : k; } else { - if (a < k) { + if (a < h) { return []; } - h = h[a - 1]; + k = k[a - 1]; if (b || e) { if (g) { - if (h.length > b || e) { - h = h.slice(e, b + e); + if (k.length > b || e) { + k = k.slice(e, b + e); } } else { d = []; - for (let q = 0, u; q < h.length; q++) { - if (u = h[q]) { + for (let p = 0, u; p < k.length; p++) { + if (u = k[p]) { if (e && u.length > e) { e -= u.length; } else { @@ -1523,27 +1516,27 @@ function ab(a, c, b, e, d, f, g) { } } } - h = d; + k = d; } } } } - return h; + return k; } -function Za(a, c, b, e, d) { +function Ya(a, c, b, e, d) { const f = [], g = I(); - let k; - var h = a.length; + let h; + var k = a.length; let l; if (e) { - for (d = h - 1; d >= 0; d--) { + for (d = k - 1; d >= 0; d--) { if (l = (e = a[d]) && e.length) { - for (h = 0; h < l; h++) { - if (k = e[h], !g[k]) { - if (g[k] = 1, b) { + for (k = 0; k < l; k++) { + if (h = e[k], !g[h]) { + if (g[h] = 1, b) { b--; } else { - if (f.push(k), f.length === c) { + if (f.push(h), f.length === c) { return f; } } @@ -1552,17 +1545,17 @@ function Za(a, c, b, e, d) { } } } else { - for (let n = h - 1, q, u = 0; n >= 0; n--) { - q = a[n]; - for (let r = 0; r < q.length; r++) { - if (l = (e = q[r]) && e.length) { + for (let m = k - 1, p, u = 0; m >= 0; m--) { + p = a[m]; + for (let r = 0; r < p.length; r++) { + if (l = (e = p[r]) && e.length) { for (let t = 0; t < l; t++) { - if (k = e[t], !g[k]) { - if (g[k] = 1, b) { + if (h = e[t], !g[h]) { + if (g[h] = 1, b) { b--; } else { - let m = (r + (n < h - 1 ? d || 0 : 0)) / (n + 1) | 0; - (f[m] || (f[m] = [])).push(k); + let n = (r + (m < k - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[n] || (f[n] = [])).push(h); if (++u === c) { return f; } @@ -1575,12 +1568,12 @@ function Za(a, c, b, e, d) { } return f; } -function eb(a, c, b) { +function db(a, c, b) { const e = I(), d = []; for (let f = 0, g; f < c.length; f++) { g = c[f]; - for (let k = 0; k < g.length; k++) { - e[g[k]] = 1; + for (let h = 0; h < g.length; h++) { + e[g[h]] = 1; } } if (b) { @@ -1588,62 +1581,62 @@ function eb(a, c, b) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, k; f < a.result.length; f++) { + for (let f = 0, g, h; f < a.result.length; f++) { for (g = a.result[f], c = 0; c < g.length; c++) { - k = g[c], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); + h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); } } } return d; } ;I(); -Oa.prototype.search = function(a, c, b, e) { +Na.prototype.search = function(a, c, b, e) { b || (!c && ba(a) ? (b = a, a = "") : ba(c) && (b = c, c = 0)); let d = []; var f = []; let g; - let k, h, l, n, q; + let h, k, l, m, p; let u = 0, r = !0, t; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; g = b.pluck; - k = b.merge; + h = b.merge; l = b.boost; - q = g || b.field || (q = b.index) && (q.index ? null : q); - var m = this.tag && b.tag; - h = b.suggest; + p = g || b.field || (p = b.index) && (p.index ? null : p); + var n = this.tag && b.tag; + k = b.suggest; r = b.resolve !== !1; - n = b.cache; + m = b.cache; this.store && b.highlight && !r ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !r && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); t = r && this.store && b.highlight; - var p = !!t || r && this.store && b.enrich; + var q = !!t || r && this.store && b.enrich; c = b.limit || c; var x = b.offset || 0; c || (c = r ? 100 : 0); - if (m && (!this.db || !e)) { - m.constructor !== Array && (m = [m]); + if (n && (!this.db || !e)) { + n.constructor !== Array && (n = [n]); var v = []; - for (let E = 0, z; E < m.length; E++) { - z = m[E]; + for (let B = 0, z; B < n.length; B++) { + z = n[B]; if (N(z)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (z.field && z.tag) { var A = z.tag; if (A.constructor === Array) { - for (var C = 0; C < A.length; C++) { - v.push(z.field, A[C]); + for (var D = 0; D < A.length; D++) { + v.push(z.field, A[D]); } } else { v.push(z.field, A); } } else { A = Object.keys(z); - for (let D = 0, K, F; D < A.length; D++) { - if (K = A[D], F = z[K], F.constructor === Array) { - for (C = 0; C < F.length; C++) { - v.push(K, F[C]); + for (let C = 0, K, F; C < A.length; C++) { + if (K = A[C], F = z[K], F.constructor === Array) { + for (D = 0; D < F.length; D++) { + v.push(K, F[D]); } } else { v.push(K, F); @@ -1654,181 +1647,181 @@ Oa.prototype.search = function(a, c, b, e) { if (!v.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - m = v; + n = v; if (!a) { f = []; if (v.length) { - for (m = 0; m < v.length; m += 2) { + for (n = 0; n < v.length; n += 2) { if (this.db) { - e = this.index.get(v[m]); + e = this.index.get(v[n]); if (!e) { - console.warn("Tag '" + v[m] + ":" + v[m + 1] + "' will be skipped because there is no field '" + v[m] + "'."); + console.warn("Tag '" + v[n] + ":" + v[n + 1] + "' will be skipped because there is no field '" + v[n] + "'."); continue; } - f.push(e = e.db.tag(v[m + 1], c, x, p)); + f.push(e = e.db.tag(v[n + 1], c, x, q)); } else { - e = fb.call(this, v[m], v[m + 1], c, x, p); + e = eb.call(this, v[n], v[n + 1], c, x, q); } - d.push(r ? {field:v[m], tag:v[m + 1], result:e} : [e]); + d.push(r ? {field:v[n], tag:v[n + 1], result:e} : [e]); } } if (f.length) { - const E = this; + const B = this; return Promise.all(f).then(function(z) { - for (let D = 0; D < z.length; D++) { - r ? d[D].result = z[D] : d[D] = z[D]; + for (let C = 0; C < z.length; C++) { + r ? d[C].result = z[C] : d[C] = z[C]; } - return r ? d : new X(d.length > 1 ? ab(d, 1, 0, 0, h, l) : d[0], E); + return r ? d : new X(d.length > 1 ? $a(d, 1, 0, 0, k, l) : d[0], B); }); } - return r ? d : new X(d.length > 1 ? ab(d, 1, 0, 0, h, l) : d[0], this); + return r ? d : new X(d.length > 1 ? $a(d, 1, 0, 0, k, l) : d[0], this); } } if (!r && !g) { - if (q = q || this.field) { - N(q) ? g = q : (q.constructor === Array && q.length === 1 && (q = q[0]), g = q.field || q.index); + if (p = p || this.field) { + N(p) ? g = p : (p.constructor === Array && p.length === 1 && (p = p[0]), g = p.field || p.index); } if (!g) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - q && q.constructor !== Array && (q = [q]); + p && p.constructor !== Array && (p = [p]); } - q || (q = this.field); + p || (p = this.field); let G; v = (this.worker || this.db) && !e && []; - for (let E = 0, z, D, K; E < q.length; E++) { - D = q[E]; - if (this.db && this.tag && !this.B[E]) { + for (let B = 0, z, C, K; B < p.length; B++) { + C = p[B]; + if (this.db && this.tag && !this.B[B]) { continue; } let F; - N(D) || (F = D, D = F.field, a = F.query || a, c = aa(F.limit, c), x = aa(F.offset, x), h = aa(F.suggest, h), t = r && this.store && aa(F.highlight, t), p = !!t || r && this.store && aa(F.enrich, p), n = aa(F.cache, n)); + N(C) || (F = C, C = F.field, a = F.query || a, c = aa(F.limit, c), x = aa(F.offset, x), k = aa(F.suggest, k), t = r && this.store && aa(F.highlight, t), q = !!t || r && this.store && aa(F.enrich, q), m = aa(F.cache, m)); if (e) { - z = e[E]; + z = e[B]; } else { A = F || b || {}; - C = A.enrich; - var B = this.index.get(D); - m && (this.db && (A.tag = m, G = B.db.support_tag_search, A.field = q), !G && C && (A.enrich = !1)); - z = n ? B.searchCache(a, c, A) : B.search(a, c, A); - C && (A.enrich = C); + D = A.enrich; + var E = this.index.get(C); + n && (this.db && (A.tag = n, G = E.db.support_tag_search, A.field = p), !G && D && (A.enrich = !1)); + z = m ? E.searchCache(a, c, A) : E.search(a, c, A); + D && (A.enrich = D); if (v) { - v[E] = z; + v[B] = z; continue; } } K = (z = z.result || z) && z.length; - if (m && K) { + if (n && K) { A = []; - C = 0; + D = 0; if (this.db && e) { if (!G) { - for (B = q.length; B < e.length; B++) { - let L = e[B]; + for (E = p.length; E < e.length; E++) { + let L = e[E]; if (L && L.length) { - C++, A.push(L); - } else if (!h) { + D++, A.push(L); + } else if (!k) { return r ? d : new X(d, this); } } } } else { - for (let L = 0, O, P; L < m.length; L += 2) { - O = this.tag.get(m[L]); + for (let L = 0, O, P; L < n.length; L += 2) { + O = this.tag.get(n[L]); if (!O) { - if (console.warn("Tag '" + m[L] + ":" + m[L + 1] + "' will be skipped because there is no field '" + m[L] + "'."), h) { + if (console.warn("Tag '" + n[L] + ":" + n[L + 1] + "' will be skipped because there is no field '" + n[L] + "'."), k) { continue; } else { return r ? d : new X(d, this); } } - if (P = (O = O && O.get(m[L + 1])) && O.length) { - C++, A.push(O); - } else if (!h) { + if (P = (O = O && O.get(n[L + 1])) && O.length) { + D++, A.push(O); + } else if (!k) { return r ? d : new X(d, this); } } } - if (C) { - z = eb(z, A, r); + if (D) { + z = db(z, A, r); K = z.length; - if (!K && !h) { + if (!K && !k) { return r ? z : new X(z, this); } - C--; + D--; } } if (K) { - f[u] = D, d.push(z), u++; - } else if (q.length === 1) { + f[u] = C, d.push(z), u++; + } else if (p.length === 1) { return r ? d : new X(d, this); } } if (v) { - if (this.db && m && m.length && !G) { - for (p = 0; p < m.length; p += 2) { - f = this.index.get(m[p]); + if (this.db && n && n.length && !G) { + for (q = 0; q < n.length; q += 2) { + f = this.index.get(n[q]); if (!f) { - if (console.warn("Tag '" + m[p] + ":" + m[p + 1] + "' was not found because there is no field '" + m[p] + "'."), h) { + if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), k) { continue; } else { return r ? d : new X(d, this); } } - v.push(f.db.tag(m[p + 1], c, x, !1)); + v.push(f.db.tag(n[q + 1], c, x, !1)); } } - const E = this; + const B = this; return Promise.all(v).then(function(z) { b && (b.resolve = r); - z.length && (z = E.search(a, c, b, z)); + z.length && (z = B.search(a, c, b, z)); return z; }); } if (!u) { return r ? d : new X(d, this); } - if (g && (!p || !this.store)) { + if (g && (!q || !this.store)) { return d = d[0], r ? d : new X(d, this); } v = []; for (x = 0; x < f.length; x++) { - m = d[x]; - p && m.length && typeof m[0].doc === "undefined" && (this.db ? v.push(m = this.index.get(this.field[0]).db.enrich(m)) : m = Ua.call(this, m)); + n = d[x]; + q && n.length && typeof n[0].doc === "undefined" && (this.db ? v.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = Ta.call(this, n)); if (g) { - return r ? t ? db(a, m, this.index, g, t) : m : new X(m, this); + return r ? t ? cb(a, n, this.index, g, t) : n : new X(n, this); } - d[x] = {field:f[x], result:m}; + d[x] = {field:f[x], result:n}; } - if (p && this.db && v.length) { - const E = this; + if (q && this.db && v.length) { + const B = this; return Promise.all(v).then(function(z) { - for (let D = 0; D < z.length; D++) { - d[D].result = z[D]; + for (let C = 0; C < z.length; C++) { + d[C].result = z[C]; } - t && (d = db(a, d, E.index, g, t)); - return k ? hb(d) : d; + t && (d = cb(a, d, B.index, g, t)); + return h ? fb(d) : d; }); } - t && (d = db(a, d, this.index, g, t)); - return k ? hb(d) : d; + t && (d = cb(a, d, this.index, g, t)); + return h ? fb(d) : d; }; -function hb(a) { +function fb(a) { const c = [], b = I(), e = I(); - for (let d = 0, f, g, k, h, l, n, q; d < a.length; d++) { + for (let d = 0, f, g, h, k, l, m, p; d < a.length; d++) { f = a[d]; g = f.field; - k = f.result; - for (let u = 0; u < k.length; u++) { - if (l = k[u], typeof l !== "object" ? l = {id:h = l} : h = l.id, (n = b[h]) ? n.push(g) : (l.field = b[h] = [g], c.push(l)), q = l.highlight) { - n = e[h], n || (e[h] = n = {}, l.highlight = n), n[g] = q; + h = f.result; + for (let u = 0; u < h.length; u++) { + if (l = h[u], typeof l !== "object" ? l = {id:k = l} : k = l.id, (m = b[k]) ? m.push(g) : (l.field = b[k] = [g], c.push(l)), p = l.highlight) { + m = e[k], m || (e[k] = m = {}, l.highlight = m), m[g] = p; } } } return c; } -function fb(a, c, b, e, d) { +function eb(a, c, b, e, d) { a = this.tag.get(a); if (!a) { return []; @@ -1842,11 +1835,11 @@ function fb(a, c, b, e, d) { if (b && c > b || e) { a = a.slice(e, e + b); } - d && (a = Ua.call(this, a)); + d && (a = Ta.call(this, a)); } return a; } -function Ua(a) { +function Ta(a) { if (!this || !this.store) { return a; } @@ -1859,26 +1852,26 @@ function Ua(a) { } return c; } -;function Oa(a) { - if (!this || this.constructor !== Oa) { - return new Oa(a); +;function Na(a) { + if (!this || this.constructor !== Na) { + return new Na(a); } const c = a.document || a.doc || a; let b, e; this.B = []; this.field = []; this.D = []; - this.key = (b = c.key || c.id) && ib(b, this.D) || "id"; + this.key = (b = c.key || c.id) && hb(b, this.D) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; this.reg = !this.fastupdate || a.worker || a.db ? e ? new R(e) : new Set() : e ? new Q(e) : new Map(); this.h = (b = c.store || null) && b && b !== !0 && []; this.store = b ? e ? new Q(e) : new Map() : null; - this.cache = (b = a.cache || null) && new oa(b); + this.cache = (b = a.cache || null) && new na(b); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = jb.call(this, a, c); + this.index = ib.call(this, a, c); this.tag = null; if (b = c.tag) { if (typeof b === "string" && (b = [b]), b.length) { @@ -1891,7 +1884,7 @@ function Ua(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.A[d] = f.custom : (this.A[d] = ib(g, this.D), f.filter && (typeof this.A[d] === "string" && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); + f.custom ? this.A[d] = f.custom : (this.A[d] = hb(g, this.D), f.filter && (typeof this.A[d] === "string" && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); this.F[d] = g; this.tag.set(g, new Map()); } @@ -1907,10 +1900,10 @@ function Ua(a) { const d = this; return Promise.all(a).then(function(f) { let g = 0; - for (const k of d.index.entries()) { - const h = k[0]; - let l = k[1]; - l.then && (l = f[g], d.index.set(h, l), g++); + for (const h of d.index.entries()) { + const k = h[0]; + let l = h[1]; + l.then && (l = f[g], d.index.set(k, l), g++); } return d; }); @@ -1919,7 +1912,7 @@ function Ua(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -w = Oa.prototype; +w = Na.prototype; w.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); @@ -1937,12 +1930,12 @@ w.mount = function(a) { } b = []; const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let f = 0, g, k; f < c.length; f++) { - e.field = k = c[f]; - g = this.index.get(k); - const h = new a.constructor(a.id, e); - h.id = a.id; - b[f] = h.mount(g); + for (let f = 0, g, h; f < c.length; f++) { + e.field = h = c[f]; + g = this.index.get(h); + const k = new a.constructor(a.id, e); + k.id = a.id; + b[f] = k.mount(g); g.document = !0; f ? g.bypass = !0 : g.store = this.store; } @@ -1951,12 +1944,12 @@ w.mount = function(a) { d.db = !0; }); }; -w.commit = async function(a, c) { - const b = []; - for (const e of this.index.values()) { - b.push(e.commit(a, c)); +w.commit = async function() { + const a = []; + for (const c of this.index.values()) { + a.push(c.commit()); } - await Promise.all(b); + await Promise.all(a); this.reg.clear(); }; w.destroy = function() { @@ -1966,34 +1959,34 @@ w.destroy = function() { } return Promise.all(a); }; -function jb(a, c) { +function ib(a, c) { const b = new Map(); let e = c.index || c.field || c; N(e) && (e = [e]); - for (let f = 0, g, k; f < e.length; f++) { + for (let f = 0, g, h; f < e.length; f++) { g = e[f]; - N(g) || (k = g, g = g.field); - k = ba(k) ? Object.assign({}, a, k) : a; + N(g) || (h = g, g = g.field); + h = ba(h) ? Object.assign({}, a, h) : a; if (this.worker) { var d = void 0; - d = (d = k.encoder) && d.encode ? d : new la(typeof d === "string" ? xa[d] : d || {}); - d = new Ma(k, d); + d = (d = h.encoder) && d.encode ? d : new ka(typeof d === "string" ? wa[d] : d || {}); + d = new La(h, d); b.set(g, d); } - this.worker || b.set(g, new T(k, this.reg)); - k.custom ? this.B[f] = k.custom : (this.B[f] = ib(g, this.D), k.filter && (typeof this.B[f] === "string" && (this.B[f] = new String(this.B[f])), this.B[f].G = k.filter)); + this.worker || b.set(g, new T(h, this.reg)); + h.custom ? this.B[f] = h.custom : (this.B[f] = hb(g, this.D), h.filter && (typeof this.B[f] === "string" && (this.B[f] = new String(this.B[f])), this.B[f].G = h.filter)); this.field[f] = g; } if (this.h) { a = c.store; N(a) && (a = [a]); - for (let f = 0, g, k; f < a.length; f++) { - g = a[f], k = g.field || g, g.custom ? (this.h[f] = g.custom, g.custom.O = k) : (this.h[f] = ib(k, this.D), g.filter && (typeof this.h[f] === "string" && (this.h[f] = new String(this.h[f])), this.h[f].G = g.filter)); + for (let f = 0, g, h; f < a.length; f++) { + g = a[f], h = g.field || g, g.custom ? (this.h[f] = g.custom, g.custom.O = h) : (this.h[f] = hb(h, this.D), g.filter && (typeof this.h[f] === "string" && (this.h[f] = new String(this.h[f])), this.h[f].G = g.filter)); } } return b; } -function ib(a, c) { +function hb(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -2009,7 +2002,7 @@ w.update = function(a, c) { return this.remove(a).add(a, c); }; w.remove = function(a) { - ba(a) && (a = da(a, this.key)); + ba(a) && (a = ca(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -2059,15 +2052,15 @@ w.get = function(a) { }) : this.store.get(a) || null; }; w.set = function(a, c) { - typeof a === "object" && (c = a, a = da(c, this.key)); + typeof a === "object" && (c = a, a = ca(c, this.key)); this.store.set(a, c); return this; }; -w.searchCache = na; -w.export = kb; -w.import = lb; -Ga(Oa.prototype); -function mb(a, c = 0) { +w.searchCache = ma; +w.export = jb; +w.import = kb; +Fa(Na.prototype); +function lb(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -2076,30 +2069,30 @@ function mb(a, c = 0) { e.length && b.push(e); return b; } -function nb(a, c) { +function mb(a, c) { c || (c = new Map()); for (let b = 0, e; b < a.length; b++) { e = a[b], c.set(e[0], e[1]); } return c; } -function ob(a, c = 0) { +function nb(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], mb(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], lb(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function pb(a, c) { +function ob(a, c) { c || (c = new Map()); for (let b = 0, e, d; b < a.length; b++) { - e = a[b], d = c.get(e[0]), c.set(e[0], nb(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], mb(e[1], d)); } return c; } -function qb(a) { +function pb(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), b.length === 250000 && (c.push(b), b = []); @@ -2107,34 +2100,34 @@ function qb(a) { b.length && c.push(b); return c; } -function rb(a, c) { +function qb(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function sb(a, c, b, e, d, f, g = 0) { - const k = e && e.constructor === Array; - var h = k ? e.shift() : e; - if (!h) { +function rb(a, c, b, e, d, f, g = 0) { + const h = e && e.constructor === Array; + var k = h ? e.shift() : e; + if (!k) { return this.export(a, c, d, f + 1); } - if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { + if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { const l = this; - return h.then(function() { - return sb.call(l, a, c, b, k ? e : null, d, f, g + 1); + return k.then(function() { + return rb.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return sb.call(this, a, c, b, k ? e : null, d, f, g + 1); + return rb.call(this, a, c, b, h ? e : null, d, f, g + 1); } -function kb(a, c, b = 0, e = 0) { +function jb(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const k = this; + const h = this; return c.then(function() { - return k.export(a, g, b + 1); + return h.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -2143,25 +2136,25 @@ function kb(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = qb(this.reg); + f = pb(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && ob(this.tag, this.reg.size); + f = this.tag && nb(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && mb(this.store); + f = this.store && lb(this.store); c = null; break; default: return; } - return sb.call(this, a, c, d, f || null, b, e); + return rb.call(this, a, c, d, f || null, b, e); } -function lb(a, c) { +function kb(a, c) { var b = a.split("."); b[b.length - 1] === "json" && b.pop(); const e = b.length > 2 ? b[0] : ""; @@ -2177,7 +2170,7 @@ function lb(a, c) { switch(b) { case "reg": this.fastupdate = !1; - this.reg = rb(c, this.reg); + this.reg = qb(c, this.reg); for (let d = 0, f; d < this.field.length; d++) { f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } @@ -2190,27 +2183,27 @@ function lb(a, c) { } break; case "tag": - this.tag = pb(c, this.tag); + this.tag = ob(c, this.tag); break; case "doc": - this.store = nb(c, this.store); + this.store = mb(c, this.store); } } } -function tb(a, c) { +function sb(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, k; g < d.length; g++) { - k = d[g] || [""]; - let h = ""; - for (let l = 0; l < k.length; l++) { - h += (h ? "," : "") + (c === "string" ? '"' + k[l] + '"' : k[l]); + for (let g = 0, h; g < d.length; g++) { + h = d[g] || [""]; + let k = ""; + for (let l = 0; l < h.length; l++) { + k += (k ? "," : "") + (c === "string" ? '"' + h[l] + '"' : h[l]); } - h = "[" + h + "]"; - f += (f ? "," : "") + h; + k = "[" + k + "]"; + f += (f ? "," : "") + k; } f = '["' + a + '",[' + f + "]]"; b += (b ? "," : "") + f; @@ -2232,19 +2225,19 @@ function tb(a, c) { } } } else { - ub(this.map, a), this.depth && ub(this.ctx, a); + tb(this.map, a), this.depth && tb(this.ctx, a); } c || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.M && vb(this)); + this.db && (this.commit_task.push({del:a}), this.M && ub(this)); this.cache && this.cache.remove(a); return this; }; -function ub(a, c) { +function tb(a, c) { let b = 0; var e = typeof c === "undefined"; if (a.constructor === Array) { - for (let d = 0, f, g, k; d < a.length; d++) { + for (let d = 0, f, g, h; d < a.length; d++) { if ((f = a[d]) && f.length) { if (e) { return 1; @@ -2258,9 +2251,9 @@ function ub(a, c) { if (b) { return 1; } - k = 1; + h = 1; } else { - if (k) { + if (h) { return 1; } b++; @@ -2269,12 +2262,12 @@ function ub(a, c) { } } else { for (let d of a.entries()) { - e = d[0], ub(d[1], c) ? b++ : a.delete(e); + e = d[0], tb(d[1], c) ? b++ : a.delete(e); } } return b; } -;const wb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +;const vb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; T.prototype.add = function(a, c, b, e) { if (c && (a || a === 0)) { if (!e && !b && this.reg.has(a)) { @@ -2284,30 +2277,30 @@ T.prototype.add = function(a, c, b, e) { c = this.encoder.encode(c, !e); const l = c.length; if (l) { - const n = I(), q = I(), u = this.resolution; + const m = I(), p = I(), u = this.resolution; for (let r = 0; r < l; r++) { let t = c[this.rtl ? l - 1 - r : r]; var d = t.length; - if (d && (e || !q[t])) { - var f = this.score ? this.score(c, t, r, null, 0) : xb(u, l, r), g = ""; + if (d && (e || !p[t])) { + var f = this.score ? this.score(c, t, r, null, 0) : wb(u, l, r), g = ""; switch(this.tokenize) { case "tolerant": - Y(this, q, t, f, a, b); + Y(this, p, t, f, a, b); if (d > 2) { - for (let m = 1, p, x, v, A; m < d - 1; m++) { - p = t.charAt(m), x = t.charAt(m + 1), v = t.substring(0, m) + x, A = t.substring(m + 2), g = v + p + A, q[g] || Y(this, q, g, f, a, b), g = v + A, q[g] || Y(this, q, g, f, a, b); + for (let n = 1, q, x, v, A; n < d - 1; n++) { + q = t.charAt(n), x = t.charAt(n + 1), v = t.substring(0, n) + x, A = t.substring(n + 2), g = v + q + A, Y(this, p, g, f, a, b), g = v + A, Y(this, p, g, f, a, b); } + Y(this, p, t.substring(0, t.length - 1), f, a, b); } break; case "full": if (d > 2) { - for (let m = 0, p; m < d; m++) { - for (f = d; f > m; f--) { - if (g = t.substring(m, f), !q[g]) { - p = this.rtl ? d - 1 - m : m; - var k = this.score ? this.score(c, t, r, g, p) : xb(u, l, r, d, p); - Y(this, q, g, k, a, b); - } + for (let n = 0, q; n < d; n++) { + for (f = d; f > n; f--) { + g = t.substring(n, f); + q = this.rtl ? d - 1 - n : n; + var h = this.score ? this.score(c, t, r, g, q) : wb(u, l, r, d, q); + Y(this, p, g, h, a, b); } } break; @@ -2315,61 +2308,70 @@ T.prototype.add = function(a, c, b, e) { case "bidirectional": case "reverse": if (d > 1) { - for (k = d - 1; k > 0; k--) { - if (g = t[this.rtl ? d - 1 - k : k] + g, !q[g]) { - var h = this.score ? this.score(c, t, r, g, k) : xb(u, l, r, d, k); - Y(this, q, g, h, a, b); - } + for (h = d - 1; h > 0; h--) { + g = t[this.rtl ? d - 1 - h : h] + g; + var k = this.score ? this.score(c, t, r, g, h) : wb(u, l, r, d, h); + Y(this, p, g, k, a, b); } g = ""; } case "forward": if (d > 1) { - for (k = 0; k < d; k++) { - g += t[this.rtl ? d - 1 - k : k], q[g] || Y(this, q, g, f, a, b); + for (h = 0; h < d; h++) { + g += t[this.rtl ? d - 1 - h : h], Y(this, p, g, f, a, b); } break; } default: - if (Y(this, q, t, f, a, b), e && l > 1 && r < l - 1) { - for (d = I(), g = this.N, f = t, k = Math.min(e + 1, this.rtl ? r + 1 : l - r), d[f] = 1, h = 1; h < k; h++) { - if ((t = c[this.rtl ? l - 1 - r - h : r + h]) && !d[t]) { - d[t] = 1; - const m = this.score ? this.score(c, f, r, t, h - 1) : xb(g + (l / 2 > g ? 0 : 1), l, r, k - 1, h - 1), p = this.bidirectional && t > f; - Y(this, n, p ? f : t, m, a, b, p ? t : f); - } + if (Y(this, p, t, f, a, b), e && l > 1 && r < l - 1) { + for (d = this.N, g = t, f = Math.min(e + 1, this.rtl ? r + 1 : l - r), h = 1; h < f; h++) { + t = c[this.rtl ? l - 1 - r - h : r + h]; + k = this.bidirectional && t > g; + const n = this.score ? this.score(c, g, r, t, h - 1) : wb(d + (l / 2 > d ? 0 : 1), l, r, f - 1, h - 1); + Y(this, m, k ? g : t, n, a, b, k ? t : g); } } } } } this.fastupdate || this.reg.add(a); - } else { - c = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.M && vb(this)); + this.db && (this.commit_task.push(b ? {ins:a} : {del:a}), this.M && ub(this)); return this; }; function Y(a, c, b, e, d, f, g) { - let k = g ? a.ctx : a.map, h; - if (!c[b] || g && !(h = c[b])[g]) { - if (g ? (c = h || (c[b] = I()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { - if (k.length === 2 ** 31 - 1) { - c = new Ba(k); - if (a.fastupdate) { - for (let l of a.reg.values()) { - l.includes(k) && (l[l.indexOf(k)] = c); + let h, k; + if (!(h = c[b]) || g && !h[g]) { + g ? (c = h || (c[b] = I()), c[g] = 1, k = a.ctx, (h = k.get(g)) ? k = h : k.set(g, k = a.keystore ? new Q(a.keystore) : new Map())) : (k = a.map, c[b] = 1); + (h = k.get(b)) ? k = h : k.set(b, k = h = []); + if (f) { + for (let l = 0, m; l < h.length; l++) { + if ((m = h[l]) && m.includes(d)) { + if (l <= e) { + return; } + m.splice(m.indexOf(d), 1); + a.fastupdate && (c = a.reg.get(d)) && c.splice(c.indexOf(m), 1); + break; } - h[e] = k = c; } - k.push(d); - a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } + k = k[e] || (k[e] = []); + k.push(d); + if (k.length === 2 ** 31 - 1) { + c = new Aa(k); + if (a.fastupdate) { + for (let l of a.reg.values()) { + l.includes(k) && (l[l.indexOf(k)] = c); + } + } + h[e] = k = c; + } + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } -function xb(a, c, b, e, d) { +function wb(a, c, b, e, d) { return b && a > 1 ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;T.prototype.search = function(a, c, b) { @@ -2377,73 +2379,73 @@ function xb(a, c, b, e, d) { if (b && b.cache) { return b.cache = !1, a = this.searchCache(a, c, b), b.cache = !0, a; } - let e = [], d, f, g, k = 0, h, l, n, q, u; - b && (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, u = (h = b.resolve) && b.enrich, n = b.boost, q = b.resolution, l = this.db && b.tag); - typeof h === "undefined" && (h = this.resolve); + let e = [], d, f, g, h = 0, k, l, m, p, u; + b && (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, u = (k = b.resolve) && b.enrich, m = b.boost, p = b.resolution, l = this.db && b.tag); + typeof k === "undefined" && (k = this.resolve); f = this.depth && f !== !1; let r = this.encoder.encode(a, !f); d = r.length; - c = c || (h ? 100 : 0); + c = c || (k ? 100 : 0); if (d === 1) { - return yb.call(this, r[0], "", c, k, h, u, l); + return xb.call(this, r[0], "", c, h, k, u, l); } if (d === 2 && f && !g) { - return yb.call(this, r[1], r[0], c, k, h, u, l); + return xb.call(this, r[1], r[0], c, h, k, u, l); } - let t = I(), m = 0, p; - f && (p = r[0], m = 1); - q || q === 0 || (q = p ? this.N : this.resolution); + let t = I(), n = 0, q; + f && (q = r[0], n = 1); + p || p === 0 || (p = q ? this.N : this.resolution); if (this.db) { - if (this.db.search && (b = this.db.search(this, r, c, k, g, h, u, l), b !== !1)) { + if (this.db.search && (b = this.db.search(this, r, c, h, g, k, u, l), b !== !1)) { return b; } const x = this; return async function() { - for (let v, A; m < d; m++) { - if ((A = r[m]) && !t[A]) { + for (let v, A; n < d; n++) { + if ((A = r[n]) && !t[A]) { t[A] = 1; - v = await zb(x, A, p, 0, 0, !1, !1); - if (v = Ab(v, e, g, q)) { + v = await yb(x, A, q, 0, 0, !1, !1); + if (v = zb(v, e, g, p)) { e = v; break; } - p && (g && v && e.length || (p = A)); + q && (g && v && e.length || (q = A)); } - g && p && m === d - 1 && !e.length && (q = x.resolution, p = "", m = -1, t = I()); + g && q && n === d - 1 && !e.length && (p = x.resolution, q = "", n = -1, t = I()); } - return Bb(e, q, c, k, g, n, h); + return Ab(e, p, c, h, g, m, k); }(); } - for (let x, v; m < d; m++) { - if ((v = r[m]) && !t[v]) { + for (let x, v; n < d; n++) { + if ((v = r[n]) && !t[v]) { t[v] = 1; - x = zb(this, v, p, 0, 0, !1, !1); - if (x = Ab(x, e, g, q)) { + x = yb(this, v, q, 0, 0, !1, !1); + if (x = zb(x, e, g, p)) { e = x; break; } - p && (g && x && e.length || (p = v)); + q && (g && x && e.length || (q = v)); } - g && p && m === d - 1 && !e.length && (q = this.resolution, p = "", m = -1, t = I()); + g && q && n === d - 1 && !e.length && (p = this.resolution, q = "", n = -1, t = I()); } - return Bb(e, q, c, k, g, n, h); + return Ab(e, p, c, h, g, m, k); }; -function Bb(a, c, b, e, d, f, g) { - let k = a.length, h = a; - if (k > 1) { - h = ab(a, c, b, e, d, f, g); - } else if (k === 1) { - return g ? Ta.call(null, a[0], b, e) : new X(a[0], this); +function Ab(a, c, b, e, d, f, g) { + let h = a.length, k = a; + if (h > 1) { + k = $a(a, c, b, e, d, f, g); + } else if (h === 1) { + return g ? Sa.call(null, a[0], b, e) : new X(a[0], this); } - return g ? h : new X(h, this); + return g ? k : new X(k, this); } -function yb(a, c, b, e, d, f, g) { - a = zb(this, a, c, b, e, d, f, g); - return this.db ? a.then(function(k) { - return d ? k || [] : new X(k, this); - }) : a && a.length ? d ? Ta.call(this, a, b, e) : new X(a, this) : d ? [] : new X([], this); +function xb(a, c, b, e, d, f, g) { + a = yb(this, a, c, b, e, d, f, g); + return this.db ? a.then(function(h) { + return d ? h || [] : new X(h, this); + }) : a && a.length ? d ? Sa.call(this, a, b, e) : new X(a, this) : d ? [] : new X([], this); } -function Ab(a, c, b, e) { +function zb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -2464,11 +2466,11 @@ function Ab(a, c, b, e) { return d; } } -function zb(a, c, b, e, d, f, g, k) { - let h; - b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); +function yb(a, c, b, e, d, f, g, h) { + let k; + b && (k = a.bidirectional && c > b) && (k = b, b = c, c = k); if (a.db) { - return a.db.get(c, b, e, d, f, g, k); + return a.db.get(c, b, e, d, f, g, h); } a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; @@ -2479,13 +2481,13 @@ function zb(a, c, b, e, d, f, g, k) { } if (a) { var b = N(a) ? a : a.preset; - b && (wb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, wb[b], a)); + b && (vb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, vb[b], a)); } else { a = {}; } b = a.context; - const e = b === !0 ? {depth:1} : b || {}, d = N(a.encoder) ? xa[a.encoder] : a.encode || a.encoder || {}; - this.encoder = d.encode ? d : typeof d === "object" ? new la(d) : {encode:d}; + const e = b === !0 ? {depth:1} : b || {}, d = N(a.encoder) ? wa[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : typeof d === "object" ? new ka(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && b !== "default" && b !== "exact" && b || "strict"; this.depth = b === "strict" && e.depth || 0; @@ -2499,7 +2501,7 @@ function zb(a, c, b, e, d, f, g, k) { this.reg = c || (this.fastupdate ? b ? new Q(b) : new Map() : b ? new R(b) : new Set()); this.N = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new oa(b); + this.cache = (b = a.cache || null) && new na(b); this.resolve = a.resolve !== !1; if (b = a.db) { this.db = this.mount(b); @@ -2514,18 +2516,18 @@ w.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -w.commit = function(a, c) { +w.commit = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, c); + return this.db.commit(this); }; w.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function vb(a) { +function ub(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; - a.db.commit(a, void 0, void 0); + a.db.commit(a); }, 1)); } w.clear = function() { @@ -2549,17 +2551,17 @@ w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - ub(this.map); - this.depth && ub(this.ctx); + tb(this.map); + this.depth && tb(this.ctx); return this; }; -w.searchCache = na; +w.searchCache = ma; w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = qb(this.reg); + f = pb(this.reg); break; case 1: d = "cfg"; @@ -2567,29 +2569,29 @@ w.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = mb(this.map, this.reg.size); + f = lb(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ob(this.ctx, this.reg.size); + f = nb(this.ctx, this.reg.size); break; default: return; } - return sb.call(this, a, c, d, f, b, e); + return rb.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { if (c) { switch(typeof c === "string" && (c = JSON.parse(c)), a = a.split("."), a[a.length - 1] === "json" && a.pop(), a.length === 3 && a.shift(), a = a.length > 1 ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = rb(c, this.reg); + this.reg = qb(c, this.reg); break; case "map": - this.map = nb(c, this.map); + this.map = mb(c, this.map); break; case "ctx": - this.ctx = pb(c, this.ctx); + this.ctx = ob(c, this.ctx); } } }; @@ -2601,24 +2603,24 @@ w.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + (f === "string" ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = tb(this.map, f); + b = sb(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = tb(g[1], f); - k = "new Map([" + k + "])"; - k = '["' + d + '",' + k + "]"; - e += (e ? "," : "") + k; + let h = sb(g[1], f); + h = "new Map([" + h + "])"; + h = '["' + d + '",' + h + "]"; + e += (e ? "," : "") + h; } e = "index.ctx=new Map([" + e + "]);"; } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; -Ga(T.prototype); -const Cb = typeof window !== "undefined" && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Db = ["map", "ctx", "tag", "reg", "cfg"], Eb = I(); -function Fb(a, c = {}) { - if (!this || this.constructor !== Fb) { - return new Fb(a, c); +Fa(T.prototype); +const Bb = typeof window !== "undefined" && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Cb = ["map", "ctx", "tag", "reg", "cfg"], Db = I(); +function Eb(a, c = {}) { + if (!this || this.constructor !== Eb) { + return new Eb(a, c); } typeof a === "object" && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2629,7 +2631,7 @@ function Fb(a, c = {}) { this.db = null; this.h = {}; } -w = Fb.prototype; +w = Eb.prototype; w.mount = function(a) { if (a.index) { return a.mount(this); @@ -2643,15 +2645,15 @@ w.open = function() { } let a = this; navigator.storage && navigator.storage.persist(); - Eb[a.id] || (Eb[a.id] = []); - Eb[a.id].push(a.field); - const c = Cb.open(a.id, 1); + Db[a.id] || (Db[a.id] = []); + Db[a.id].push(a.field); + const c = Bb.open(a.id, 1); c.onupgradeneeded = function() { const b = a.db = this.result; - for (let e = 0, d; e < Db.length; e++) { - d = Db[e]; - for (let f = 0, g; f < Eb[a.id].length; f++) { - g = Eb[a.id][f], b.objectStoreNames.contains(d + (d !== "reg" ? g ? ":" + g : "" : "")) || b.createObjectStore(d + (d !== "reg" ? g ? ":" + g : "" : "")); + for (let e = 0, d; e < Cb.length; e++) { + d = Cb[e]; + for (let f = 0, g; f < Db[a.id].length; f++) { + g = Db[a.id][f], b.objectStoreNames.contains(d + (d !== "reg" ? g ? ":" + g : "" : "")) || b.createObjectStore(d + (d !== "reg" ? g ? ":" + g : "" : "")); } } }; @@ -2667,15 +2669,15 @@ w.close = function() { this.db = null; }; w.destroy = function() { - const a = Cb.deleteDatabase(this.id); + const a = Bb.deleteDatabase(this.id); return Z(a); }; w.clear = function() { const a = []; - for (let b = 0, e; b < Db.length; b++) { - e = Db[b]; - for (let d = 0, f; d < Eb[this.id].length; d++) { - f = Eb[this.id][d], a.push(e + (e !== "reg" ? f ? ":" + f : "" : "")); + for (let b = 0, e; b < Cb.length; b++) { + e = Cb[b]; + for (let d = 0, f; d < Db[this.id].length; d++) { + f = Db[this.id][d], a.push(e + (e !== "reg" ? f ? ":" + f : "" : "")); } } const c = this.db.transaction(a, "readwrite"); @@ -2687,34 +2689,34 @@ w.clear = function() { w.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); const g = this; - return Z(a).then(function(k) { - let h = []; - if (!k || !k.length) { - return h; + return Z(a).then(function(h) { + let k = []; + if (!h || !h.length) { + return k; } if (d) { - if (!b && !e && k.length === 1) { - return k[0]; + if (!b && !e && h.length === 1) { + return h[0]; } - for (let l = 0, n; l < k.length; l++) { - if ((n = k[l]) && n.length) { - if (e >= n.length) { - e -= n.length; + for (let l = 0, m; l < h.length; l++) { + if ((m = h[l]) && m.length) { + if (e >= m.length) { + e -= m.length; continue; } - const q = b ? e + Math.min(n.length - e, b) : n.length; - for (let u = e; u < q; u++) { - h.push(n[u]); + const p = b ? e + Math.min(m.length - e, b) : m.length; + for (let u = e; u < p; u++) { + k.push(m[u]); } e = 0; - if (h.length === b) { + if (k.length === b) { break; } } } - return f ? g.enrich(h) : h; + return f ? g.enrich(k) : k; } - return k; + return h; }); }; w.tag = function(a, c = 0, b = 0, e = !1) { @@ -2768,75 +2770,65 @@ w.transaction = function(a, c, b) { return f; }); }; -w.commit = async function(a, c, b) { - if (c) { - await this.clear(), a.commit_task = []; - } else { - let e = a.commit_task; - a.commit_task = []; - for (let d = 0, f; d < e.length; d++) { - if (f = e[d], f.clear) { - await this.clear(); - c = !0; - break; - } else { - e[d] = f.del; - } - } - c || (b || (e = e.concat(ca(a.reg))), e.length && await this.remove(e)); +w.commit = async function(a) { + let c = a.commit_task, b = []; + a.commit_task = []; + for (let e = 0, d; e < c.length; e++) { + d = c[e], d.del && b.push(d.del); } + b.length && await this.remove(b); a.reg.size && (await this.transaction("map", "readwrite", function(e) { for (const d of a.map) { const f = d[0], g = d[1]; - g.length && (c ? e.put(g, f) : e.get(f).onsuccess = function() { - let k = this.result; - var h; - if (k && k.length) { - const l = Math.max(k.length, g.length); - for (let n = 0, q, u; n < l; n++) { - if ((u = g[n]) && u.length) { - if ((q = k[n]) && q.length) { - for (h = 0; h < u.length; h++) { - q.push(u[h]); + g.length && (e.get(f).onsuccess = function() { + let h = this.result; + var k; + if (h && h.length) { + const l = Math.max(h.length, g.length); + for (let m = 0, p, u; m < l; m++) { + if ((u = g[m]) && u.length) { + if ((p = h[m]) && p.length) { + for (k = 0; k < u.length; k++) { + p.push(u[k]); } } else { - k[n] = u; + h[m] = u; } - h = 1; + k = 1; } } } else { - k = g, h = 1; + h = g, k = 1; } - h && e.put(k, f); + k && e.put(h, f); }); } }), await this.transaction("ctx", "readwrite", function(e) { for (const d of a.ctx) { const f = d[0], g = d[1]; - for (const k of g) { - const h = k[0], l = k[1]; - l.length && (c ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { - let n = this.result; - var q; - if (n && n.length) { - const u = Math.max(n.length, l.length); - for (let r = 0, t, m; r < u; r++) { - if ((m = l[r]) && m.length) { - if ((t = n[r]) && t.length) { - for (q = 0; q < m.length; q++) { - t.push(m[q]); + for (const h of g) { + const k = h[0], l = h[1]; + l.length && (e.get(f + ":" + k).onsuccess = function() { + let m = this.result; + var p; + if (m && m.length) { + const u = Math.max(m.length, l.length); + for (let r = 0, t, n; r < u; r++) { + if ((n = l[r]) && n.length) { + if ((t = m[r]) && t.length) { + for (p = 0; p < n.length; p++) { + t.push(n[p]); } } else { - n[r] = m; + m[r] = n; } - q = 1; + p = 1; } } } else { - n = l, q = 1; + m = l, p = 1; } - q && e.put(n, f + ":" + h); + p && e.put(m, f + ":" + k); }); } } @@ -2853,29 +2845,29 @@ w.commit = async function(a, c, b) { for (const d of a.tag) { const f = d[0], g = d[1]; g.length && (e.get(f).onsuccess = function() { - let k = this.result; - k = k && k.length ? k.concat(g) : g; - e.put(k, f); + let h = this.result; + h = h && h.length ? h.concat(g) : g; + e.put(h, f); }); } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function Gb(a, c, b) { +function Fb(a, c, b) { const e = a.value; let d, f = 0; - for (let g = 0, k; g < e.length; g++) { - if (k = b ? e : e[g]) { - for (let h = 0, l, n; h < c.length; h++) { - if (n = c[h], l = k.indexOf(n), l >= 0) { - if (d = 1, k.length > 1) { - k.splice(l, 1); + for (let g = 0, h; g < e.length; g++) { + if (h = b ? e : e[g]) { + for (let k = 0, l, m; k < c.length; k++) { + if (m = c[k], l = h.indexOf(m), l >= 0) { + if (d = 1, h.length > 1) { + h.splice(l, 1); } else { e[g] = []; break; } } } - f += k.length; + f += h.length; } if (b) { break; @@ -2889,17 +2881,17 @@ w.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && Gb(b, a); + b && Fb(b, a); }; }), this.transaction("ctx", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && Gb(b, a); + b && Fb(b, a); }; }), this.transaction("tag", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && Gb(b, a, !0); + b && Fb(b, a, !0); }; }), this.transaction("reg", "readwrite", function(c) { for (let b = 0; b < a.length; b++) { @@ -2918,9 +2910,9 @@ function Z(a, c) { a = null; }); } -;const Hb = {Index:T, Charset:xa, Encoder:la, Document:Oa, Worker:Ma, Resolver:X, IndexedDB:Fb, Language:{}}, Ib = typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : self; -let Jb; -(Jb = Ib.define) && Jb.amd ? Jb([], function() { - return Hb; -}) : typeof Ib.exports === "object" ? Ib.exports = Hb : Ib.FlexSearch = Hb; +;const Gb = {Index:T, Charset:wa, Encoder:ka, Document:Na, Worker:La, Resolver:X, IndexedDB:Eb, Language:{}}, Hb = typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : self; +let Ib; +(Ib = Hb.define) && Ib.amd ? Ib([], function() { + return Gb; +}) : typeof Hb.exports === "object" ? Hb.exports = Gb : Hb.FlexSearch = Gb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index de92a60..87c4fc4 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -1,107 +1,107 @@ /**! - * FlexSearch.js v0.8.203 (Bundle) + * FlexSearch.js v0.8.205 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var w;function H(a,b,c){const e=typeof c,d=typeof a;if(e!=="undefined"){if(d!=="undefined"){if(c){if(d==="function"&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return d==="undefined"?b:a}function aa(a,b){return typeof a==="undefined"?b:a}function I(){return Object.create(null)} -function M(a){return typeof a==="string"}function ba(a){return typeof a==="object"}function ca(a){const b=[];for(const c of a.keys())b.push(c);return b}function ea(a,b){if(M(b))a=a[b];else for(let c=0;a&&c1)return this.addMatcher(a,b);this.mapper||(this.mapper=new Map);this.mapper.set(a,b);this.cache&&Q(this);return this};w.addMatcher=function(a,b){if(typeof a==="object")return this.addReplacer(a,b);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.J=null;this.cache&&Q(this);return this}; -w.addReplacer=function(a,b){if(typeof a==="string")return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&Q(this);return this}; -w.encode=function(a,b){if(this.cache&&a.length<=this.H)if(this.F){if(this.B.has(a))return this.B.get(a)}else this.F=setTimeout(Q,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=ka?a.normalize("NFKD").replace(ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(ia,"$1 $2").replace(ja,"$1 $2").replace(ha,"$1 "));const c=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let e= -[],d=I(),f,g,h=this.split||this.split===""?a.split(this.split):[a];for(let l=0,m,n;lthis.maxlength)){if(b){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(c)e.push(m);else if(!this.filter||(typeof this.filter==="function"?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.I)if(this.F){var k=this.D.get(m);if(k||k===""){k&&e.push(k);continue}}else this.F=setTimeout(Q,50,this);if(this.stemmer){this.K||(this.K=new RegExp("(?!^)("+ -this.A+")$"));let u;for(;u!==m&&m.length>2;)u=m,m=m.replace(this.K,r=>this.stemmer.get(r))}if(m&&(this.mapper||this.dedupe&&m.length>1)){k="";for(let u=0,r="",t,p;u1&&(this.J||(this.J=new RegExp("("+this.h+")","g")),m=m.replace(this.J,u=>this.matcher.get(u)));if(m&&this.replacer)for(k=0;m&&kthis.L&&(this.D.clear(),this.I=this.I/1.1|0));if(m){if(m!==n)if(b){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.H&&(this.B.set(a,e),this.B.size>this.L&&(this.B.clear(),this.H=this.H/1.1|0));return e};function Q(a){a.F=null;a.B.clear();a.D.clear()};function ma(a,b,c){c||(b||typeof a!=="object"?typeof b==="object"&&(c=b,b=0):c=a);c&&(a=c.query||a,b=c.limit||b);let e=""+(b||0);c&&(e+=(c.offset||0)+!!c.context+!!c.suggest+(c.resolve!==!1)+(c.resolution||this.resolution)+(c.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new na);let d=this.cache.get(a+e);if(!d){const f=c&&c.cache;f&&(c.cache=!1);d=this.search(a,b,c);f&&(c.cache=f);this.cache.set(a+e,d)}return d}function na(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""} -na.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};na.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};na.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};na.prototype.clear=function(){this.cache.clear();this.h=""};const oa={normalize:!1,numeric:!1,dedupe:!1};const ra={};const sa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const ta=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ua=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const va={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var wa={Exact:oa,Default:ra,Normalize:ra,LatinBalance:{mapper:sa},LatinAdvanced:{mapper:sa,matcher:ta,replacer:ua},LatinExtra:{mapper:sa,replacer:ua.concat([/(?!^)[aeo]/g,""]),matcher:ta},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const h=b.length;if(h&&(d=d.length?d.concat(b):b,c-=h,e&&(a.length-=h),!c))break;b=0}return d} -function Aa(a){if(!this||this.constructor!==Aa)return new Aa(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if(e==="length")return b.length;if(e==="push")return function(d){b.index[b.index.length-1].push(d);b.length++};if(e==="pop")return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if(e==="indexOf")return function(d){let f=0;for(let g=0,h,k;g=0)return f+k;f+=h.length}return-1}; -if(e==="includes")return function(d){for(let f=0;f32?(this.B=Ba,this.A=BigInt(a)):(this.B=Ca,this.A=a)}R.prototype.get=function(a){const b=this.index[this.B(a)];return b&&b.get(a)};R.prototype.set=function(a,b){var c=this.B(a);let e=this.index[c];e?(c=e.size,e.set(a,b),(c-=e.size)&&this.size++):(this.index[c]=e=new Map([[a,b]]),this.h.push(e),this.size++)}; -function S(a=8){if(!this||this.constructor!==S)return new S(a);this.index=I();this.h=[];this.size=0;a>32?(this.B=Ba,this.A=BigInt(a)):(this.B=Ca,this.A=a)}S.prototype.add=function(a){var b=this.B(a);let c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.h.push(c),this.size++)};w=R.prototype;w.has=S.prototype.has=function(a){const b=this.index[this.B(a)];return b&&b.has(a)}; -w.delete=S.prototype.delete=function(a){const b=this.index[this.B(a)];b&&b.delete(a)&&this.size--};w.clear=S.prototype.clear=function(){this.index=I();this.h=[];this.size=0};w.values=S.prototype.values=function*(){for(let a=0;a=this.priority*this.priority*3):(Ia=setTimeout(La,0),Ja=Date.now());if(Ka){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let V=0; -function Ma(a={},b){function c(h){function k(l){l=l.data||l;const m=l.id,n=m&&f.h[m];n&&(n(l.msg),delete f.h[m])}this.worker=h;this.h=I();if(this.worker){d?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(l){V>1E9&&(V=0);f.h[++V]=function(){l(f)};f.worker.postMessage({id:V,task:"init",factory:e,options:a})});this.priority=a.priority||4;this.encoder=b||null;this.worker.postMessage({task:"init",factory:e,options:a});return this}}if(!this||this.constructor!==Ma)return new Ma(a); -let e=typeof self!=="undefined"?self._factory:typeof window!=="undefined"?window._factory:null;e&&(e=e.toString());const d=typeof window==="undefined",f=this,g=Na(e,d,a.worker);return g.then?g.then(function(h){return c.call(f,h)}):c.call(this,g)}W("add");W("append");W("search");W("update");W("remove");W("clear");W("export");W("import");Ma.prototype.searchCache=ma;Ga(Ma.prototype); -function W(a){Ma.prototype[a]=function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;typeof e==="function"&&(d=e,c.pop());e=new Promise(function(f){a==="export"&&typeof c[0]==="function"&&(c[0]=null);V>1E9&&(V=0);b.h[++V]=f;b.worker.postMessage({task:a,id:V,args:c})});return d?(e.then(d),this):e}} -function Na(a,b,c){return b?typeof module!=="undefined"?new(require("worker_threads")["Worker"])(__dirname+"/node/node.js"):import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Fa.toString()],{type:"text/javascript"}))):new window.Worker(typeof c==="string"?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};Oa.prototype.add=function(a,b,c){ba(a)&&(b=a,a=ea(b,this.key));if(b&&(a||a===0)){if(!c&&this.reg.has(a))return this.update(a,b);for(let h=0,k;hb?a.slice(c,c+b):a,e?Ua.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}g=g.slice(c,c+b);h=g.length;c=0}h>b&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?Ua.call(this,g):g;d.push(g);b-=h;if(!b)break}d=d.length>1?[].concat.apply([],d):d[0];return e?Ua.call(this,d):d};function Va(a,b,c,e){var d=e[0];if(d[0]&&d[0].query)return a[b].apply(a,d);if(!(b!=="and"&&b!=="not"||a.result.length||a.await||d.suggest))return e.length>1&&(d=e[e.length-1]),(e=d.resolve)?a.await||a.result:a;let f=[],g=0,h=0,k,l,m,n,u;for(b=0;b1&&(c=c[b].apply(c,a.slice(1)));return c};X.prototype.or=function(){return Va(this,"or",Ya,arguments)};function Ya(a,b,c,e,d,f,g){a.length&&(this.result.length&&a.push(this.result),a.length<2?this.result=a[0]:(this.result=Za(a,b,c,!1,this.h),c=0));d&&(this.await=null);return d?this.resolve(b,c,e,g):this};X.prototype.and=function(){return Va(this,"and",$a,arguments)};function $a(a,b,c,e,d,f,g){if(!f&&!this.result.length)return d?this.result:this;let h;if(a.length)if(this.result.length&&a.unshift(this.result),a.length<2)this.result=a[0];else{let k=0;for(let l=0,m,n;l1?z.join(" "):z[0];let y;if(z&&E){var D=E.length,K=(da.split? -E.replace(da.split,""):E).length-z.length,F="",N=0;for(var O=0;O-1&&(F=(P?E.substring(0,P):"")+g+E.substring(P,P+L)+h+(P+L=k)break}G=za.length*(f.length-2);if(r||t||k&&q.length-G>k)if(G=k+G-u*2,B=C-A,r>0&& -(B+=r),t>0&&(B+=t),B<=G)x=r?A-(r>0?r:0):A-((G-B)/2|0),v=t?C+(t>0?t:0):x+G,l||(x>0&&q.charAt(x)!==" "&&q.charAt(x-1)!==" "&&(x=q.indexOf(" ",x),x<0&&(x=0)),v=v.length-1){if(J>= -v.length){B[y+1]=1;J>=x.length&&(G[y+1]=1);continue}D-=u}q=v[J].text;if(L=t&&z[y])if(L>0){if(q.length>L)if(B[y+1]=1,l)q=q.substring(0,L);else continue;(L-=q.length)||(L=-1);z[y]=L}else{B[y+1]=1;continue}if(D+q.length+1<=k)q=" "+q,C[y]+=q;else if(l)U=k-D-1,U>0&&(q=" "+q.substring(0,U),C[y]+=q),B[y+1]=1;else{B[y+1]=1;continue}}else{if(B[y])continue;J-=K;if(A[J]){D-=u;B[y]=1;G[y]=1;continue}if(J<=0){if(J<0){B[y]=1;G[y]=1;continue}D-=u}q=v[J].text;if(L=r&&E[y])if(L>0){if(q.length>L)if(B[y]=1,l)q=q.substring(q.length- -L);else continue;(L-=q.length)||(L=-1);E[y]=L}else{B[y]=1;continue}if(D+q.length+1<=k)q+=" ",C[y]=q+C[y];else if(l)U=q.length+1-(k-D),U>=0&&U=x.length-1?Qa=1:J1?Za(k,c,e,g,f):(k=k[0])&&c&&k.length>c||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+ -e)}else{d=[];for(let n=0,u;ne)e-=u.length;else{if(c&&u.length>c||e)u=u.slice(e,c+e),c-=u.length,e&&(e-=u.length);d.push(u);if(!c)break}k=d}}return k} -function Za(a,b,c,e,d){const f=[],g=I();let h;var k=a.length;let l;if(e)for(d=k-1;d>=0;d--){if(l=(e=a[d])&&e.length)for(k=0;k=0;m--){n=a[m];for(let r=0;r1?ab(d,1,0,0,k,l):d[0],E)})}return r?d:new X(d.length>1?ab(d,1,0,0,k,l):d[0],this)}}r||g||!(n=n||this.field)||(M(n)?g=n:(n.constructor===Array&&n.length===1&&(n=n[0]),g=n.field||n.index));n&&n.constructor!==Array&&(n=[n])}n||(n=this.field);let G;v=(this.worker||this.db)&&!e&&[];for(let E=0,z,D,K;E0){if(c&&b>c||e)a=a.slice(e,e+c);d&&(a=Ua.call(this,a))}return a} -function Ua(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);const b=Array(a.length);for(let c=0,e;c1?c:c[0]}w.append=function(a,b){return this.add(a,b,!0)}; -w.update=function(a,b){return this.remove(a).add(a,b)};w.remove=function(a){ba(a)&&(a=ea(a,this.key));for(var b of this.index.values())b.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(let c of this.tag.values())for(let e of c){b=e[0];const d=e[1],f=d.indexOf(a);f>-1&&(d.length>1?d.splice(f,1):c.delete(b))}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -w.clear=function(){const a=[];for(const b of this.index.values()){const c=b.clear();c.then&&a.push(c)}if(this.tag)for(const b of this.tag.values())b.clear();this.store&&this.store.clear();this.cache&&this.cache.clear();return a.length?Promise.all(a):this};w.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.reg.has(a)};w.cleanup=function(){for(const a of this.index.values())a.cleanup();return this}; -w.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(b){return b[0]&&b[0].doc||null}):this.store.get(a)||null};w.set=function(a,b){typeof a==="object"&&(b=a,a=ea(b,this.key));this.store.set(a,b);return this};w.searchCache=ma;w.export=kb;w.import=lb;Ga(Oa.prototype);function mb(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function nb(a,b){b||(b=new Map);for(let c=0,e;c2?c[0]:"";c=c.length>2?c[2]:c[1];if(this.worker&&e)return this.index.get(e).import(a);if(b){typeof b==="string"&&(b=JSON.parse(b));if(e)return this.index.get(e).import(c,b);switch(c){case "reg":this.fastupdate=!1;this.reg=rb(b,this.reg);for(let d=0,f;d=0&&d.splice(g,1)}}else ub(this.map,a),this.depth&&ub(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.M&&vb(this));this.cache&&this.cache.remove(a);return this}; -function ub(a,b){let c=0;var e=typeof b==="undefined";if(a.constructor===Array)for(let d=0,f,g,h;d=0){if(f.length>1)return f.splice(g,1),1;delete a[d];if(c)return 1;h=1}else{if(h)return 1;c++}}}else for(let d of a.entries())e=d[0],ub(d[1],b)?c++:a.delete(e);return c};const wb={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};T.prototype.add=function(a,b,c,e){if(b&&(a||a===0)){if(!e&&!c&&this.reg.has(a))return this.update(a,b);e=this.depth;b=this.encoder.encode(b,!e);const l=b.length;if(l){const m=I(),n=I(),u=this.resolution;for(let r=0;r2)for(let p=1,q,x,v,A;p2){for(let p=0,q;pp;f--)if(g=t.substring(p,f),!n[g]){q=this.rtl?d-1-p:p;var h=this.score?this.score(b,t,r,g,q):xb(u,l,r,d,q);Y(this,n,g,h,a,c)}break}case "bidirectional":case "reverse":if(d>1){for(h=d-1;h>0;h--)if(g=t[this.rtl?d-1-h:h]+g,!n[g]){var k=this.score?this.score(b,t,r,g,h):xb(u,l,r,d,h);Y(this,n,g,k,a,c)}g=""}case "forward":if(d>1){for(h=0;h1&&rg?0:1),l,r,h-1,k-1),q=this.bidirectional&&t>f;Y(this,m,q?f:t,p,a,c,q?t:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.M&&vb(this));return this}; -function Y(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=I()),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[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new Aa(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[e]=h=b}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function xb(a,b,c,e,d){return c&&a>1?b+(e||0)<=a?c+(d||0):(a-1)/(b+(e||0))*(c+(d||0))+1|0:0};T.prototype.search=function(a,b,c){c||(b||typeof a!=="object"?typeof b==="object"&&(c=b,b=0):(c=a,a=""));if(c&&c.cache)return c.cache=!1,a=this.searchCache(a,b,c),c.cache=!0,a;let e=[],d,f,g,h=0,k,l,m,n,u;c&&(a=c.query||a,b=c.limit||b,h=c.offset||0,f=c.context,g=c.suggest,u=(k=c.resolve)&&c.enrich,m=c.boost,n=c.resolution,l=this.db&&c.tag);typeof k==="undefined"&&(k=this.resolve);f=this.depth&&f!==!1;let r=this.encoder.encode(a,!f);d=r.length;b=b||(k?100:0);if(d===1)return yb.call(this,r[0],"",b, -h,k,u,l);if(d===2&&f&&!g)return yb.call(this,r[1],r[0],b,h,k,u,l);let t=I(),p=0,q;f&&(q=r[0],p=1);n||n===0||(n=q?this.N:this.resolution);if(this.db){if(this.db.search&&(c=this.db.search(this,r,b,h,g,k,u,l),c!==!1))return c;const x=this;return async function(){for(let v,A;p1)k=ab(a,b,c,e,d,f,g);else if(h===1)return g?Ta.call(null,a[0],c,e):new X(a[0],this);return g?k:new X(k,this)} -function yb(a,b,c,e,d,f,g){a=zb(this,a,b,c,e,d,f,g);return this.db?a.then(function(h){return d?h||[]:new X(h,this)}):a&&a.length?d?Ta.call(this,a,c,e):new X(a,this):d?[]:new X([],this)}function Ab(a,b,c,e){let d=[];if(a&&a.length){if(a.length<=e){b.push(a);return}for(let f=0,g;fc)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,e,d,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function T(a,b){if(!this||this.constructor!==T)return new T(a);if(a){var c=M(a)?a:a.preset;c&&(a=Object.assign({},wb[c],a))}else a={};c=a.context;const e=c===!0?{depth:1}:c||{},d=M(a.encoder)?wa[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new la(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&c!=="default"&&c!=="exact"&&c||"strict";this.depth=c==="strict"&&e.depth||0;this.bidirectional=e.bidirectional!==!1;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new R(c):new Map;this.ctx=c?new R(c):new Map;this.reg=b||(this.fastupdate?c?new R(c):new Map:c?new S(c):new Set);this.N=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new na(c);this.resolve=a.resolve!==!1;if(c=a.db)this.db=this.mount(c);this.M=a.commit!==!1;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=T.prototype; -w.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};w.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};w.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function vb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} -w.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this};w.append=function(a,b){return this.add(a,b,!0)};w.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};w.update=function(a,b){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; -w.cleanup=function(){if(!this.fastupdate)return this;ub(this.map);this.depth&&ub(this.ctx);return this};w.searchCache=ma;w.export=function(a,b,c=0,e=0){let d,f;switch(e){case 0:d="reg";f=qb(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=mb(this.map,this.reg.size);break;case 3:d="ctx";f=ob(this.ctx,this.reg.size);break;default:return}return sb.call(this,a,b,d,f,c,e)}; -w.import=function(a,b){if(b)switch(typeof b==="string"&&(b=JSON.parse(b)),a=a.split("."),a[a.length-1]==="json"&&a.pop(),a.length===3&&a.shift(),a=a.length>1?a[1]:a[0],a){case "reg":this.fastupdate=!1;this.reg=rb(b,this.reg);break;case "map":this.map=nb(b,this.map);break;case "ctx":this.ctx=pb(b,this.ctx)}}; -w.serialize=function(a=!0){let b="",c="",e="";if(this.reg.size){let f;for(var d of this.reg.keys())f||(f=typeof d),b+=(b?",":"")+(f==="string"?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";c=tb(this.map,f);c="index.map=new Map(["+c+"]);";for(const g of this.ctx.entries()){d=g[0];let h=tb(g[1],f);h="new Map(["+h+"])";h='["'+d+'",'+h+"]";e+=(e?",":"")+h}e="index.ctx=new Map(["+e+"]);"}return a?"function inject(index){"+b+c+e+"}":b+c+e};Ga(T.prototype);const Cb=typeof window!=="undefined"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Db=["map","ctx","tag","reg","cfg"],Eb=I(); -function Fb(a,b={}){if(!this||this.constructor!==Fb)return new Fb(a,b);typeof a==="object"&&(b=a,a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=b.field?b.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.type=b.type;this.fastupdate=this.support_tag_search=!1;this.db=null;this.h={}}w=Fb.prototype;w.mount=function(a){if(a.index)return a.mount(this);a.db=this;return this.open()}; -w.open=function(){if(this.db)return this.db;let a=this;navigator.storage&&navigator.storage.persist();Eb[a.id]||(Eb[a.id]=[]);Eb[a.id].push(a.field);const b=Cb.open(a.id,1);b.onupgradeneeded=function(){const c=a.db=this.result;for(let e=0,d;e=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let u=e;u=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; -w.enrich=function(a){typeof a!=="object"&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e=0)if(d=1,h.length>1)h.splice(l,1);else{e[g]=[];break}f+=h.length}if(c)break}f?d&&a.update(e):a.delete();a.continue()} -w.remove=function(a){typeof a!=="object"&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Gb(c,a)}}),this.transaction("ctx","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Gb(c,a)}}),this.transaction("tag","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Gb(c,a,!0)}}),this.transaction("reg","readwrite",function(b){for(let c=0;c{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};const Hb={Index:T,Charset:wa,Encoder:la,Document:Oa,Worker:Ma,Resolver:X,IndexedDB:Fb,Language:{}},Ib=typeof self!=="undefined"?self:typeof global!=="undefined"?global:self;let Jb;(Jb=Ib.define)&&Jb.amd?Jb([],function(){return Hb}):typeof Ib.exports==="object"?Ib.exports=Hb:Ib.FlexSearch=Hb;}(this||self)); +(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var w;function H(a,c,b){const e=typeof b,d=typeof a;if(e!=="undefined"){if(d!=="undefined"){if(b){if(d==="function"&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return d==="undefined"?c:a}function aa(a,c){return typeof a==="undefined"?c:a}function I(){return Object.create(null)} +function M(a){return typeof a==="string"}function ba(a){return typeof a==="object"}function ca(a,c){if(M(c))a=a[c];else for(let b=0;a&&b1)return this.addMatcher(a,c);this.mapper||(this.mapper=new Map);this.mapper.set(a,c);this.cache&&Q(this);return this};w.addMatcher=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.J=null;this.cache&&Q(this);return this}; +w.addReplacer=function(a,c){if(typeof a==="string")return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&Q(this);return this}; +w.encode=function(a,c){if(this.cache&&a.length<=this.H)if(this.F){if(this.B.has(a))return this.B.get(a)}else this.F=setTimeout(Q,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(ha,"$1 $2").replace(ia,"$1 $2").replace(fa,"$1 "));const b=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let e= +[],d=I(),f,g,h=this.split||this.split===""?a.split(this.split):[a];for(let l=0,m,p;lthis.maxlength)){if(c){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(b)e.push(m);else if(!this.filter||(typeof this.filter==="function"?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.I)if(this.F){var k=this.D.get(m);if(k||k===""){k&&e.push(k);continue}}else this.F=setTimeout(Q,50,this);if(this.stemmer){this.K||(this.K=new RegExp("(?!^)("+ +this.A+")$"));let u;for(;u!==m&&m.length>2;)u=m,m=m.replace(this.K,r=>this.stemmer.get(r))}if(m&&(this.mapper||this.dedupe&&m.length>1)){k="";for(let u=0,r="",t,n;u1&&(this.J||(this.J=new RegExp("("+this.h+")","g")),m=m.replace(this.J,u=>this.matcher.get(u)));if(m&&this.replacer)for(k=0;m&&kthis.L&&(this.D.clear(),this.I=this.I/1.1|0));if(m){if(m!==p)if(c){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.H&&(this.B.set(a,e),this.B.size>this.L&&(this.B.clear(),this.H=this.H/1.1|0));return e};function Q(a){a.F=null;a.B.clear();a.D.clear()};function la(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):b=a);b&&(a=b.query||a,c=b.limit||c);let e=""+(c||0);b&&(e+=(b.offset||0)+!!b.context+!!b.suggest+(b.resolve!==!1)+(b.resolution||this.resolution)+(b.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new ma);let d=this.cache.get(a+e);if(!d){const f=b&&b.cache;f&&(b.cache=!1);d=this.search(a,c,b);f&&(b.cache=f);this.cache.set(a+e,d)}return d}function ma(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""} +ma.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)};ma.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};ma.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};ma.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:!1,numeric:!1,dedupe:!1};const oa={};const ra=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 sa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ta=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ua={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var va={Exact:na,Default:oa,Normalize:oa,LatinBalance:{mapper:ra},LatinAdvanced:{mapper:ra,matcher:sa,replacer:ta},LatinExtra:{mapper:ra,replacer:ta.concat([/(?!^)[aeo]/g,""]),matcher:sa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;b=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const h=c.length;if(h&&(d=d.length?d.concat(c):c,b-=h,e&&(a.length-=h),!b))break;c=0}return d} +function xa(a){if(!this||this.constructor!==xa)return new xa(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if(e==="length")return c.length;if(e==="push")return function(d){c.index[c.index.length-1].push(d);c.length++};if(e==="pop")return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if(e==="indexOf")return function(d){let f=0;for(let g=0,h,k;g=0)return f+k;f+=h.length}return-1}; +if(e==="includes")return function(d){for(let f=0;f32?(this.B=Aa,this.A=BigInt(a)):(this.B=Ba,this.A=a)}R.prototype.get=function(a){const c=this.index[this.B(a)];return c&&c.get(a)};R.prototype.set=function(a,c){var b=this.B(a);let e=this.index[b];e?(b=e.size,e.set(a,c),(b-=e.size)&&this.size++):(this.index[b]=e=new Map([[a,c]]),this.h.push(e),this.size++)}; +function S(a=8){if(!this||this.constructor!==S)return new S(a);this.index=I();this.h=[];this.size=0;a>32?(this.B=Aa,this.A=BigInt(a)):(this.B=Ba,this.A=a)}S.prototype.add=function(a){var c=this.B(a);let b=this.index[c];b?(c=b.size,b.add(a),(c-=b.size)&&this.size++):(this.index[c]=b=new Set([a]),this.h.push(b),this.size++)};w=R.prototype;w.has=S.prototype.has=function(a){const c=this.index[this.B(a)];return c&&c.has(a)}; +w.delete=S.prototype.delete=function(a){const c=this.index[this.B(a)];c&&c.delete(a)&&this.size--};w.clear=S.prototype.clear=function(){this.index=I();this.h=[];this.size=0};w.values=S.prototype.values=function*(){for(let a=0;a=this.priority*this.priority*3):(Ha=setTimeout(Ka,0),Ia=Date.now());if(Ja){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let V=0; +function La(a={},c){function b(h){function k(l){l=l.data||l;const m=l.id,p=m&&f.h[m];p&&(p(l.msg),delete f.h[m])}this.worker=h;this.h=I();if(this.worker){d?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(l){V>1E9&&(V=0);f.h[++V]=function(){l(f)};f.worker.postMessage({id:V,task:"init",factory:e,options:a})});this.priority=a.priority||4;this.encoder=c||null;this.worker.postMessage({task:"init",factory:e,options:a});return this}}if(!this||this.constructor!==La)return new La(a); +let e=typeof self!=="undefined"?self._factory:typeof window!=="undefined"?window._factory:null;e&&(e=e.toString());const d=typeof window==="undefined",f=this,g=Ma(e,d,a.worker);return g.then?g.then(function(h){return b.call(f,h)}):b.call(this,g)}W("add");W("append");W("search");W("update");W("remove");W("clear");W("export");W("import");La.prototype.searchCache=la;Fa(La.prototype); +function W(a){La.prototype[a]=function(){const c=this,b=[].slice.call(arguments);var e=b[b.length-1];let d;typeof e==="function"&&(d=e,b.pop());e=new Promise(function(f){a==="export"&&typeof b[0]==="function"&&(b[0]=null);V>1E9&&(V=0);c.h[++V]=f;c.worker.postMessage({task:a,id:V,args:b})});return d?(e.then(d),this):e}} +function Ma(a,c,b){return c?typeof module!=="undefined"?new(require("worker_threads")["Worker"])(__dirname+"/node/node.js"):import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ea.toString()],{type:"text/javascript"}))):new window.Worker(typeof b==="string"?b:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};Na.prototype.add=function(a,c,b){ba(a)&&(c=a,a=ca(c,this.key));if(c&&(a||a===0)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hc?a.slice(b,b+c):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}g=g.slice(b,b+c);h=g.length;b=0}h>c&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?Ta.call(this,g):g;d.push(g);c-=h;if(!c)break}d=d.length>1?[].concat.apply([],d):d[0];return e?Ta.call(this,d):d};function Ua(a,c,b,e){var d=e[0];if(d[0]&&d[0].query)return a[c].apply(a,d);if(!(c!=="and"&&c!=="not"||a.result.length||a.await||d.suggest))return e.length>1&&(d=e[e.length-1]),(e=d.resolve)?a.await||a.result:a;let f=[],g=0,h=0,k,l,m,p,u;for(c=0;c1&&(b=b[c].apply(b,a.slice(1)));return b};X.prototype.or=function(){return Ua(this,"or",Xa,arguments)};function Xa(a,c,b,e,d,f,g){a.length&&(this.result.length&&a.push(this.result),a.length<2?this.result=a[0]:(this.result=Ya(a,c,b,!1,this.h),b=0));d&&(this.await=null);return d?this.resolve(c,b,e,g):this};X.prototype.and=function(){return Ua(this,"and",Za,arguments)};function Za(a,c,b,e,d,f,g){if(!f&&!this.result.length)return d?this.result:this;let h;if(a.length)if(this.result.length&&a.unshift(this.result),a.length<2)this.result=a[0];else{let k=0;for(let l=0,m,p;l1?z.join(" "):z[0];let y;if(z&&B){var C=B.length,K=(da.split? +B.replace(da.split,""):B).length-z.length,F="",N=0;for(var O=0;O-1&&(F=(P?B.substring(0,P):"")+g+B.substring(P,P+L)+h+(P+L=k)break}G=za.length*(f.length-2);if(r||t||k&&q.length-G>k)if(G=k+G-u*2,E=D-A,r>0&& +(E+=r),t>0&&(E+=t),E<=G)x=r?A-(r>0?r:0):A-((G-E)/2|0),v=t?D+(t>0?t:0):x+G,l||(x>0&&q.charAt(x)!==" "&&q.charAt(x-1)!==" "&&(x=q.indexOf(" ",x),x<0&&(x=0)),v=v.length-1){if(J>= +v.length){E[y+1]=1;J>=x.length&&(G[y+1]=1);continue}C-=u}q=v[J].text;if(L=t&&z[y])if(L>0){if(q.length>L)if(E[y+1]=1,l)q=q.substring(0,L);else continue;(L-=q.length)||(L=-1);z[y]=L}else{E[y+1]=1;continue}if(C+q.length+1<=k)q=" "+q,D[y]+=q;else if(l)U=k-C-1,U>0&&(q=" "+q.substring(0,U),D[y]+=q),E[y+1]=1;else{E[y+1]=1;continue}}else{if(E[y])continue;J-=K;if(A[J]){C-=u;E[y]=1;G[y]=1;continue}if(J<=0){if(J<0){E[y]=1;G[y]=1;continue}C-=u}q=v[J].text;if(L=r&&B[y])if(L>0){if(q.length>L)if(E[y]=1,l)q=q.substring(q.length- +L);else continue;(L-=q.length)||(L=-1);B[y]=L}else{E[y]=1;continue}if(C+q.length+1<=k)q+=" ",D[y]=q+D[y];else if(l)U=q.length+1-(k-C),U>=0&&U=x.length-1?Qa=1:J1?Ya(k,b,e,g,f):(k=k[0])&&b&&k.length>b||e?k.slice(e,b+e):k;else{if(ab||e)k=k.slice(e,b+ +e)}else{d=[];for(let p=0,u;pe)e-=u.length;else{if(b&&u.length>b||e)u=u.slice(e,b+e),b-=u.length,e&&(e-=u.length);d.push(u);if(!b)break}k=d}}return k} +function Ya(a,c,b,e,d){const f=[],g=I();let h;var k=a.length;let l;if(e)for(d=k-1;d>=0;d--){if(l=(e=a[d])&&e.length)for(k=0;k=0;m--){p=a[m];for(let r=0;r1?$a(d,1,0,0,k,l):d[0],B)})}return r?d:new X(d.length>1?$a(d,1,0,0,k,l):d[0],this)}}r||g||!(p=p||this.field)||(M(p)?g=p:(p.constructor===Array&&p.length===1&&(p=p[0]),g=p.field||p.index));p&&p.constructor!==Array&&(p=[p])}p||(p=this.field);let G;v=(this.worker||this.db)&&!e&&[];for(let B=0,z,C,K;B0){if(b&&c>b||e)a=a.slice(e,e+b);d&&(a=Ta.call(this,a))}return a} +function Ta(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);const c=Array(a.length);for(let b=0,e;b1?b:b[0]}w.append=function(a,c){return this.add(a,c,!0)}; +w.update=function(a,c){return this.remove(a).add(a,c)};w.remove=function(a){ba(a)&&(a=ca(a,this.key));for(var c of this.index.values())c.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(let b of this.tag.values())for(let e of b){c=e[0];const d=e[1],f=d.indexOf(a);f>-1&&(d.length>1?d.splice(f,1):b.delete(c))}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +w.clear=function(){const a=[];for(const c of this.index.values()){const b=c.clear();b.then&&a.push(b)}if(this.tag)for(const c of this.tag.values())c.clear();this.store&&this.store.clear();this.cache&&this.cache.clear();return a.length?Promise.all(a):this};w.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.reg.has(a)};w.cleanup=function(){for(const a of this.index.values())a.cleanup();return this}; +w.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(c){return c[0]&&c[0].doc||null}):this.store.get(a)||null};w.set=function(a,c){typeof a==="object"&&(c=a,a=ca(c,this.key));this.store.set(a,c);return this};w.searchCache=la;w.export=jb;w.import=kb;Fa(Na.prototype);function lb(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function mb(a,c){c||(c=new Map);for(let b=0,e;b2?b[0]:"";b=b.length>2?b[2]:b[1];if(this.worker&&e)return this.index.get(e).import(a);if(c){typeof c==="string"&&(c=JSON.parse(c));if(e)return this.index.get(e).import(b,c);switch(b){case "reg":this.fastupdate=!1;this.reg=qb(c,this.reg);for(let d=0,f;d=0&&d.splice(g,1)}}else tb(this.map,a),this.depth&&tb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.M&&ub(this));this.cache&&this.cache.remove(a);return this}; +function tb(a,c){let b=0;var e=typeof c==="undefined";if(a.constructor===Array)for(let d=0,f,g,h;d=0){if(f.length>1)return f.splice(g,1),1;delete a[d];if(b)return 1;h=1}else{if(h)return 1;b++}}}else for(let d of a.entries())e=d[0],tb(d[1],c)?b++:a.delete(e);return b};const vb={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};T.prototype.add=function(a,c,b,e){if(c&&(a||a===0)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);e=this.depth;c=this.encoder.encode(c,!e);const l=c.length;if(l){const m=I(),p=I(),u=this.resolution;for(let r=0;r2){for(let n=1,q,x,v,A;n2){for(let n=0,q;nn;f--){g=t.substring(n,f);q=this.rtl?d-1-n:n;var h=this.score?this.score(c,t,r,g,q):wb(u,l,r,d,q);Y(this,p,g,h,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(h=d-1;h>0;h--){g=t[this.rtl?d-1-h:h]+g;var k=this.score?this.score(c,t,r,g,h):wb(u,l,r,d,h);Y(this,p,g,k,a,b)}g=""}case "forward":if(d>1){for(h=0;h1&&rg;const n=this.score?this.score(c,g,r,t,h-1):wb(d+(l/2>d?0:1),l,r,f-1,h-1);Y(this,m,k?g:t,n,a,b,k?t:g)}}}}this.fastupdate||this.reg.add(a)}}this.db&&(this.commit_task.push(b?{ins:a}:{del:a}),this.M&&ub(this));return this}; +function Y(a,c,b,e,d,f,g){let h,k;if(!(h=c[b])||g&&!h[g]){g?(c=h||(c[b]=I()),c[g]=1,k=a.ctx,(h=k.get(g))?k=h:k.set(g,k=a.keystore?new R(a.keystore):new Map)):(k=a.map,c[b]=1);(h=k.get(b))?k=h:k.set(b,k=h=[]);if(f)for(let l=0,m;l1?c+(e||0)<=a?b+(d||0):(a-1)/(c+(e||0))*(b+(d||0))+1|0:0};T.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));if(b&&b.cache)return b.cache=!1,a=this.searchCache(a,c,b),b.cache=!0,a;let e=[],d,f,g,h=0,k,l,m,p,u;b&&(a=b.query||a,c=b.limit||c,h=b.offset||0,f=b.context,g=b.suggest,u=(k=b.resolve)&&b.enrich,m=b.boost,p=b.resolution,l=this.db&&b.tag);typeof k==="undefined"&&(k=this.resolve);f=this.depth&&f!==!1;let r=this.encoder.encode(a,!f);d=r.length;c=c||(k?100:0);if(d===1)return xb.call(this,r[0],"",c, +h,k,u,l);if(d===2&&f&&!g)return xb.call(this,r[1],r[0],c,h,k,u,l);let t=I(),n=0,q;f&&(q=r[0],n=1);p||p===0||(p=q?this.N:this.resolution);if(this.db){if(this.db.search&&(b=this.db.search(this,r,c,h,g,k,u,l),b!==!1))return b;const x=this;return async function(){for(let v,A;n1)k=$a(a,c,b,e,d,f,g);else if(h===1)return g?Sa.call(null,a[0],b,e):new X(a[0],this);return g?k:new X(k,this)} +function xb(a,c,b,e,d,f,g){a=yb(this,a,c,b,e,d,f,g);return this.db?a.then(function(h){return d?h||[]:new X(h,this)}):a&&a.length?d?Sa.call(this,a,b,e):new X(a,this):d?[]:new X([],this)}function zb(a,c,b,e){let d=[];if(a&&a.length){if(a.length<=e){c.push(a);return}for(let f=0,g;fb)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function T(a,c){if(!this||this.constructor!==T)return new T(a);if(a){var b=M(a)?a:a.preset;b&&(a=Object.assign({},vb[b],a))}else a={};b=a.context;const e=b===!0?{depth:1}:b||{},d=M(a.encoder)?va[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new ka(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&b!=="default"&&b!=="exact"&&b||"strict";this.depth=b==="strict"&&e.depth||0;this.bidirectional=e.bidirectional!==!1;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;(b=a.keystore||0)&&(this.keystore=b);this.map=b?new R(b):new Map;this.ctx=b?new R(b):new Map;this.reg=c||(this.fastupdate?b?new R(b):new Map:b?new S(b):new Set);this.N=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(b=a.cache||null)&&new ma(b);this.resolve=a.resolve!==!1;if(b=a.db)this.db=this.mount(b);this.M=a.commit!==!1;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=T.prototype; +w.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};w.commit=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this)};w.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function ub(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a)},1))} +w.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this};w.append=function(a,c){return this.add(a,c,!0)};w.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};w.update=function(a,c){const b=this,e=this.remove(a);return e&&e.then?e.then(()=>b.add(a,c)):this.add(a,c)}; +w.cleanup=function(){if(!this.fastupdate)return this;tb(this.map);this.depth&&tb(this.ctx);return this};w.searchCache=la;w.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=pb(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=lb(this.map,this.reg.size);break;case 3:d="ctx";f=nb(this.ctx,this.reg.size);break;default:return}return rb.call(this,a,c,d,f,b,e)}; +w.import=function(a,c){if(c)switch(typeof c==="string"&&(c=JSON.parse(c)),a=a.split("."),a[a.length-1]==="json"&&a.pop(),a.length===3&&a.shift(),a=a.length>1?a[1]:a[0],a){case "reg":this.fastupdate=!1;this.reg=qb(c,this.reg);break;case "map":this.map=mb(c,this.map);break;case "ctx":this.ctx=ob(c,this.ctx)}}; +w.serialize=function(a=!0){let c="",b="",e="";if(this.reg.size){let f;for(var d of this.reg.keys())f||(f=typeof d),c+=(c?",":"")+(f==="string"?'"'+d+'"':d);c="index.reg=new Set(["+c+"]);";b=sb(this.map,f);b="index.map=new Map(["+b+"]);";for(const g of this.ctx.entries()){d=g[0];let h=sb(g[1],f);h="new Map(["+h+"])";h='["'+d+'",'+h+"]";e+=(e?",":"")+h}e="index.ctx=new Map(["+e+"]);"}return a?"function inject(index){"+c+b+e+"}":c+b+e};Fa(T.prototype);const Bb=typeof window!=="undefined"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Cb=["map","ctx","tag","reg","cfg"],Db=I(); +function Eb(a,c={}){if(!this||this.constructor!==Eb)return new Eb(a,c);typeof a==="object"&&(c=a,a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=c.field?c.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.type=c.type;this.fastupdate=this.support_tag_search=!1;this.db=null;this.h={}}w=Eb.prototype;w.mount=function(a){if(a.index)return a.mount(this);a.db=this;return this.open()}; +w.open=function(){if(this.db)return this.db;let a=this;navigator.storage&&navigator.storage.persist();Db[a.id]||(Db[a.id]=[]);Db[a.id].push(a.field);const c=Bb.open(a.id,1);c.onupgradeneeded=function(){const b=a.db=this.result;for(let e=0,d;e=m.length){e-=m.length;continue}const p=b?e+Math.min(m.length-e,b):m.length;for(let u=e;u=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; +w.enrich=function(a){typeof a!=="object"&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e=0)if(d=1,h.length>1)h.splice(l,1);else{e[g]=[];break}f+=h.length}if(b)break}f?d&&a.update(e):a.delete();a.continue()} +w.remove=function(a){typeof a!=="object"&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(c){c.openCursor().onsuccess=function(){const b=this.result;b&&Fb(b,a)}}),this.transaction("ctx","readwrite",function(c){c.openCursor().onsuccess=function(){const b=this.result;b&&Fb(b,a)}}),this.transaction("tag","readwrite",function(c){c.openCursor().onsuccess=function(){const b=this.result;b&&Fb(b,a,!0)}}),this.transaction("reg","readwrite",function(c){for(let b=0;b{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};const Gb={Index:T,Charset:va,Encoder:ka,Document:Na,Worker:La,Resolver:X,IndexedDB:Eb,Language:{}},Hb=typeof self!=="undefined"?self:typeof global!=="undefined"?global:self;let Ib;(Ib=Hb.define)&&Ib.amd?Ib([],function(){return Gb}):typeof Hb.exports==="object"?Hb.exports=Gb:Hb.FlexSearch=Gb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index 0fc284b..adb7edc 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.203 (Bundle/Module/Debug) + * FlexSearch.js v0.8.205 (Bundle/Module/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -12,8 +12,8 @@ function H(a, c, b) { if (d !== "undefined") { if (b) { if (d === "function" && e === d) { - return function(k) { - return a(b(k)); + return function(h) { + return a(b(h)); }; } c = a.constructor; @@ -55,14 +55,7 @@ function N(a) { function ba(a) { return typeof a === "object"; } -function ca(a) { - const c = []; - for (const b of a.keys()) { - c.push(b); - } - return c; -} -function da(a, c) { +function ca(a, c) { if (N(c)) { a = a[c]; } else { @@ -72,10 +65,10 @@ function da(a, c) { } return a; } -;const fa = /[^\p{L}\p{N}]+/u, ha = /(\d{3})/g, ia = /(\D)(\d{3})/g, ja = /(\d{3})(\D)/g, ka = /[\u0300-\u036f]/g; -function la(a = {}) { - if (!this || this.constructor !== la) { - return new la(...arguments); +;const da = /[^\p{L}\p{N}]+/u, fa = /(\d{3})/g, ha = /(\D)(\d{3})/g, ia = /(\d{3})(\D)/g, ja = /[\u0300-\u036f]/g; +function ka(a = {}) { + if (!this || this.constructor !== ka) { + return new ka(...arguments); } if (arguments.length) { for (a = 0; a < arguments.length; a++) { @@ -85,7 +78,7 @@ function la(a = {}) { this.assign(a); } } -w = la.prototype; +w = ka.prototype; w.assign = function(a) { this.normalize = H(a.normalize, !0, this.normalize); let c = a.include, b = c || a.exclude || a.split, e; @@ -113,7 +106,7 @@ w.assign = function(a) { this.numeric = H(a.numeric, e); } else { try { - this.split = H(this.split, fa); + this.split = H(this.split, da); } catch (d) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } @@ -155,12 +148,12 @@ w.addStemmer = function(a, c) { this.stemmer.set(a, c); this.A += (this.A ? "|" : "") + a; this.K = null; - this.cache && ma(this); + this.cache && la(this); return this; }; w.addFilter = function(a) { typeof a === "function" ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && ma(this); + this.cache && la(this); return this; }; w.addMapper = function(a, c) { @@ -172,7 +165,7 @@ w.addMapper = function(a, c) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, c); - this.cache && ma(this); + this.cache && la(this); return this; }; w.addMatcher = function(a, c) { @@ -186,7 +179,7 @@ w.addMatcher = function(a, c) { this.matcher.set(a, c); this.h += (this.h ? "|" : "") + a; this.J = null; - this.cache && ma(this); + this.cache && la(this); return this; }; w.addReplacer = function(a, c) { @@ -195,7 +188,7 @@ w.addReplacer = function(a, c) { } this.replacer || (this.replacer = []); this.replacer.push(a, c); - this.cache && ma(this); + this.cache && la(this); return this; }; w.encode = function(a, c) { @@ -205,78 +198,78 @@ w.encode = function(a, c) { return this.B.get(a); } } else { - this.F = setTimeout(ma, 50, this); + this.F = setTimeout(la, 50, this); } } - this.normalize && (typeof this.normalize === "function" ? a = this.normalize(a) : a = ka ? a.normalize("NFKD").replace(ka, "").toLowerCase() : a.toLowerCase()); + this.normalize && (typeof this.normalize === "function" ? a = this.normalize(a) : a = ja ? a.normalize("NFKD").replace(ja, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && a.length > 3 && (a = a.replace(ia, "$1 $2").replace(ja, "$1 $2").replace(ha, "$1 ")); + this.numeric && a.length > 3 && (a = a.replace(ha, "$1 $2").replace(ia, "$1 $2").replace(fa, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = I(), f, g, k = this.split || this.split === "" ? a.split(this.split) : [a]; - for (let l = 0, n, q; l < k.length; l++) { - if ((n = q = k[l]) && !(n.length < this.minlength || n.length > this.maxlength)) { + let e = [], d = I(), f, g, h = this.split || this.split === "" ? a.split(this.split) : [a]; + for (let l = 0, m, p; l < h.length; l++) { + if ((m = p = h[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (c) { - if (d[n]) { + if (d[m]) { continue; } - d[n] = 1; + d[m] = 1; } else { - if (f === n) { + if (f === m) { continue; } - f = n; + f = m; } if (b) { - e.push(n); + e.push(m); } else { - if (!this.filter || (typeof this.filter === "function" ? this.filter(n) : !this.filter.has(n))) { - if (this.cache && n.length <= this.I) { + if (!this.filter || (typeof this.filter === "function" ? this.filter(m) : !this.filter.has(m))) { + if (this.cache && m.length <= this.I) { if (this.F) { - var h = this.D.get(n); - if (h || h === "") { - h && e.push(h); + var k = this.D.get(m); + if (k || k === "") { + k && e.push(k); continue; } } else { - this.F = setTimeout(ma, 50, this); + this.F = setTimeout(la, 50, this); } } if (this.stemmer) { this.K || (this.K = new RegExp("(?!^)(" + this.A + ")$")); let u; - for (; u !== n && n.length > 2;) { - u = n, n = n.replace(this.K, r => this.stemmer.get(r)); + for (; u !== m && m.length > 2;) { + u = m, m = m.replace(this.K, r => this.stemmer.get(r)); } } - if (n && (this.mapper || this.dedupe && n.length > 1)) { - h = ""; - for (let u = 0, r = "", t, m; u < n.length; u++) { - t = n.charAt(u), t === r && this.dedupe || ((m = this.mapper && this.mapper.get(t)) || m === "" ? m === r && this.dedupe || !(r = m) || (h += m) : h += r = t); + if (m && (this.mapper || this.dedupe && m.length > 1)) { + k = ""; + for (let u = 0, r = "", t, n; u < m.length; u++) { + t = m.charAt(u), t === r && this.dedupe || ((n = this.mapper && this.mapper.get(t)) || n === "" ? n === r && this.dedupe || !(r = n) || (k += n) : k += r = t); } - n = h; + m = k; } - this.matcher && n.length > 1 && (this.J || (this.J = new RegExp("(" + this.h + ")", "g")), n = n.replace(this.J, u => this.matcher.get(u))); - if (n && this.replacer) { - for (h = 0; n && h < this.replacer.length; h += 2) { - n = n.replace(this.replacer[h], this.replacer[h + 1]); + this.matcher && m.length > 1 && (this.J || (this.J = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.J, u => this.matcher.get(u))); + if (m && this.replacer) { + for (k = 0; m && k < this.replacer.length; k += 2) { + m = m.replace(this.replacer[k], this.replacer[k + 1]); } } - this.cache && q.length <= this.I && (this.D.set(q, n), this.D.size > this.L && (this.D.clear(), this.I = this.I / 1.1 | 0)); - if (n) { - if (n !== q) { + this.cache && p.length <= this.I && (this.D.set(p, m), this.D.size > this.L && (this.D.clear(), this.I = this.I / 1.1 | 0)); + if (m) { + if (m !== p) { if (c) { - if (d[n]) { + if (d[m]) { continue; } - d[n] = 1; + d[m] = 1; } else { - if (g === n) { + if (g === m) { continue; } - g = n; + g = m; } } - e.push(n); + e.push(m); } } } @@ -286,18 +279,18 @@ w.encode = function(a, c) { this.cache && a.length <= this.H && (this.B.set(a, e), this.B.size > this.L && (this.B.clear(), this.H = this.H / 1.1 | 0)); return e; }; -function ma(a) { +function la(a) { a.F = null; a.B.clear(); a.D.clear(); } -;function na(a, c, b) { +;function ma(a, c, b) { b || (c || typeof a !== "object" ? typeof c === "object" && (b = c, c = 0) : b = a); b && (a = b.query || a, c = b.limit || c); let e = "" + (c || 0); b && (e += (b.offset || 0) + !!b.context + !!b.suggest + (b.resolve !== !1) + (b.resolution || this.resolution) + (b.boost || 0)); a = ("" + a).toLowerCase(); - this.cache || (this.cache = new oa()); + this.cache || (this.cache = new na()); let d = this.cache.get(a + e); if (!d) { const f = b && b.cache; @@ -308,53 +301,53 @@ function ma(a) { } return d; } -function oa(a) { +function na(a) { this.limit = a && a !== !0 ? a : 1000; this.cache = new Map(); this.h = ""; } -oa.prototype.set = function(a, c) { +na.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -oa.prototype.get = function(a) { +na.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -oa.prototype.remove = function(a) { +na.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -oa.prototype.clear = function() { +na.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const ra = {normalize:!1, numeric:!1, dedupe:!1}; -const sa = {}; -const ta = 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 ua = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), va = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -const wa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -var xa = {Exact:ra, Default:sa, Normalize:sa, LatinBalance:{mapper:ta}, LatinAdvanced:{mapper:ta, matcher:ua, replacer:va}, LatinExtra:{mapper:ta, replacer:va.concat([/(?!^)[aeo]/g, ""]), matcher:ua}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +const oa = {normalize:!1, numeric:!1, dedupe:!1}; +const ra = {}; +const sa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const ta = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ua = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +const va = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +var wa = {Exact:oa, Default:ra, Normalize:ra, LatinBalance:{mapper:sa}, LatinAdvanced:{mapper:sa, matcher:ta, replacer:ua}, LatinExtra:{mapper:sa, replacer:ua.concat([/(?!^)[aeo]/g, ""]), matcher:ta}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = wa[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), g === "h" || g === "w" || !(g = wa[g]) || g === d || (e += g, d = g, e.length !== 4)); f++) { + let e = c.charAt(0), d = va[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), g === "h" || g === "w" || !(g = va[g]) || g === d || (e += g, d = g, e.length !== 4)); f++) { } a[b] = e; } -}}, CJK:{split:""}, LatinExact:ra, LatinDefault:sa, LatinSimple:sa}; -function Aa(a, c, b, e) { +}}, CJK:{split:""}, LatinExact:oa, LatinDefault:ra, LatinSimple:ra}; +function xa(a, c, b, e) { let d = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], c >= g.length) { c -= g.length; } else { c = g[e ? "splice" : "slice"](c, b); - const k = c.length; - if (k && (d = d.length ? d.concat(c) : c, b -= k, e && (a.length -= k), !b)) { + const h = c.length; + if (h && (d = d.length ? d.concat(c) : c, b -= h, e && (a.length -= h), !b)) { break; } c = 0; @@ -362,9 +355,9 @@ function Aa(a, c, b, e) { } return d; } -function Ba(a) { - if (!this || this.constructor !== Ba) { - return new Ba(a); +function Aa(a) { + if (!this || this.constructor !== Aa) { + return new Aa(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -389,13 +382,13 @@ function Ba(a) { if (e === "indexOf") { return function(d) { let f = 0; - for (let g = 0, k, h; g < c.index.length; g++) { - k = c.index[g]; - h = k.indexOf(d); - if (h >= 0) { - return f + h; + for (let g = 0, h, k; g < c.index.length; g++) { + h = c.index[g]; + k = h.indexOf(d); + if (k >= 0) { + return f + k; } - f += k.length; + f += h.length; } return -1; }; @@ -412,12 +405,12 @@ function Ba(a) { } if (e === "slice") { return function(d, f) { - return Aa(c, d || 0, f || c.length, !1); + return xa(c, d || 0, f || c.length, !1); }; } if (e === "splice") { return function(d, f) { - return Aa(c, d || 0, f || c.length, !0); + return xa(c, d || 0, f || c.length, !0); }; } if (e === "constructor") { @@ -433,10 +426,10 @@ function Ba(a) { return !0; }}); } -Ba.prototype.clear = function() { +Aa.prototype.clear = function() { this.index.length = 0; }; -Ba.prototype.push = function() { +Aa.prototype.push = function() { }; function Q(a = 8) { if (!this || this.constructor !== Q) { @@ -445,7 +438,7 @@ function Q(a = 8) { this.index = I(); this.h = []; this.size = 0; - a > 32 ? (this.B = Ca, this.A = BigInt(a)) : (this.B = Da, this.A = a); + a > 32 ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } Q.prototype.get = function(a) { const c = this.index[this.B(a)]; @@ -463,7 +456,7 @@ function R(a = 8) { this.index = I(); this.h = []; this.size = 0; - a > 32 ? (this.B = Ca, this.A = BigInt(a)) : (this.B = Da, this.A = a); + a > 32 ? (this.B = Ba, this.A = BigInt(a)) : (this.B = Ca, this.A = a); } R.prototype.add = function(a) { var c = this.B(a); @@ -505,7 +498,7 @@ w.entries = R.prototype.entries = function*() { } } }; -function Da(a) { +function Ca(a) { let c = 2 ** this.A - 1; if (typeof a == "number") { return a & c; @@ -516,7 +509,7 @@ function Da(a) { } return this.A === 32 ? b + 2 ** 31 : b; } -function Ca(a) { +function Ba(a) { let c = BigInt(2) ** this.A - BigInt(1); var b = typeof a; if (b === "bigint") { @@ -532,8 +525,8 @@ function Ca(a) { } return b; } -;let Ea, S; -async function Fa(a) { +;let Da, S; +async function Ea(a) { a = a.data; var c = a.task; const b = a.id; @@ -541,7 +534,7 @@ async function Fa(a) { switch(c) { case "init": S = a.options || {}; - (c = a.factory) ? (Function("return " + c)()(self), Ea = new self.FlexSearch.Index(S), delete self.FlexSearch) : Ea = new T(S); + (c = a.factory) ? (Function("return " + c)()(self), Da = new self.FlexSearch.Index(S), delete self.FlexSearch) : Da = new T(S); postMessage({id:b}); break; default: @@ -556,33 +549,33 @@ async function Fa(a) { if (!S.import || typeof S.import !== "function") { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } - e[0] && (a = await S.import.call(Ea, e[0]), Ea.import(e[0], a)); + e[0] && (a = await S.import.call(Da, e[0]), Da.import(e[0], a)); } else { - (d = e && Ea[c].apply(Ea, e)) && d.then && (d = await d), d && d.await && (d = await d.await), c === "search" && d.result && (d = d.result); + (d = e && Da[c].apply(Da, e)) && d.then && (d = await d), d && d.await && (d = await d.await), c === "search" && d.result && (d = d.result); } postMessage(c === "search" ? {id:b, msg:d} : {id:b}); } } -;function Ga(a) { - Ha.call(a, "add"); - Ha.call(a, "append"); - Ha.call(a, "search"); - Ha.call(a, "update"); - Ha.call(a, "remove"); - Ha.call(a, "searchCache"); +;function Fa(a) { + Ga.call(a, "add"); + Ga.call(a, "append"); + Ga.call(a, "search"); + Ga.call(a, "update"); + Ga.call(a, "remove"); + Ga.call(a, "searchCache"); } -let Ia, Ja, Ka; -function La() { - Ia = Ka = 0; +let Ha, Ia, Ja; +function Ka() { + Ha = Ja = 0; } -function Ha(a) { +function Ga(a) { this[a + "Async"] = function() { const c = arguments; var b = c[c.length - 1]; let e; typeof b === "function" && (e = b, delete c[c.length - 1]); - Ia ? Ka || (Ka = Date.now() - Ja >= this.priority * this.priority * 3) : (Ia = setTimeout(La, 0), Ja = Date.now()); - if (Ka) { + Ha ? Ja || (Ja = Date.now() - Ia >= this.priority * this.priority * 3) : (Ha = setTimeout(Ka, 0), Ia = Date.now()); + if (Ja) { const f = this; return new Promise(g => { setTimeout(function() { @@ -597,17 +590,17 @@ function Ha(a) { }; } ;let V = 0; -function Ma(a = {}, c) { - function b(k) { - function h(l) { +function La(a = {}, c) { + function b(h) { + function k(l) { l = l.data || l; - const n = l.id, q = n && f.h[n]; - q && (q(l.msg), delete f.h[n]); + const m = l.id, p = m && f.h[m]; + p && (p(l.msg), delete f.h[m]); } - this.worker = k; + this.worker = h; this.h = I(); if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; + d ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { return new Promise(function(l) { V > 1e9 && (V = 0); @@ -624,14 +617,14 @@ function Ma(a = {}, c) { } console.warn("Worker is not available on this platform. Please report on Github: https://github.com/nextapps-de/flexsearch/issues"); } - if (!this || this.constructor !== Ma) { - return new Ma(a); + if (!this || this.constructor !== La) { + return new La(a); } let e = typeof self !== "undefined" ? self._factory : typeof window !== "undefined" ? window._factory : null; e && (e = e.toString()); - const d = typeof window === "undefined", f = this, g = Na(e, d, a.worker); - return g.then ? g.then(function(k) { - return b.call(f, k); + const d = typeof window === "undefined", f = this, g = Ma(e, d, a.worker); + return g.then ? g.then(function(h) { + return b.call(f, h); }) : b.call(this, g); } W("add"); @@ -642,10 +635,10 @@ W("remove"); W("clear"); W("export"); W("import"); -Ma.prototype.searchCache = na; -Ga(Ma.prototype); +La.prototype.searchCache = ma; +Fa(La.prototype); function W(a) { - Ma.prototype[a] = function() { + La.prototype[a] = function() { const c = this, b = [].slice.call(arguments); var e = b[b.length - 1]; let d; @@ -659,25 +652,25 @@ function W(a) { return d ? (e.then(d), this) : e; }; } -function Na(a, c, b) { - return c ? typeof module !== "undefined" ? new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Fa.toString()], {type:"text/javascript"}))) : new window.Worker(typeof b === "string" ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function Ma(a, c, b) { + return c ? typeof module !== "undefined" ? new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Ea.toString()], {type:"text/javascript"}))) : new window.Worker(typeof b === "string" ? b : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;Qa.prototype.add = function(a, c, b) { - ba(a) && (c = a, a = da(c, this.key)); +;Na.prototype.add = function(a, c, b) { + ba(a) && (c = a, a = ca(c, this.key)); if (c && (a || a === 0)) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let k = 0, h; k < this.field.length; k++) { - h = this.B[k]; - var e = this.index.get(this.field[k]); - if (typeof h === "function") { - var d = h(c); - d && e.add(a, d, !1, !0); + for (let h = 0, k; h < this.field.length; h++) { + k = this.B[h]; + var e = this.index.get(this.field[h]); + if (typeof k === "function") { + var d = k(c); + d && e.add(a, d, b, !0); } else { - if (d = h.G, !d || d(c)) { - h.constructor === String ? h = ["" + h] : N(h) && (h = [h]), Ra(c, h, this.D, 0, e, a, h[0], b); + if (d = k.G, !d || d(c)) { + k.constructor === String ? k = ["" + k] : N(k) && (k = [k]), Qa(c, k, this.D, 0, e, a, k[0], b); } } } @@ -685,34 +678,34 @@ function Na(a, c, b) { for (e = 0; e < this.A.length; e++) { var f = this.A[e], g = this.F[e]; d = this.tag.get(g); - let k = I(); + let h = I(); if (typeof f === "function") { if (f = f(c), !f) { continue; } } else { - const h = f.G; - if (h && !h(c)) { + const k = f.G; + if (k && !k(c)) { continue; } f.constructor === String && (f = "" + f); - f = da(c, f); + f = ca(c, f); } if (d && f) { N(f) && (f = [f]); - for (let h = 0, l, n; h < f.length; h++) { - if (l = f[h], !k[l] && (k[l] = 1, (g = d.get(l)) ? n = g : d.set(l, n = []), !b || !n.includes(a))) { - if (n.length === 2 ** 31 - 1) { - g = new Ba(n); + for (let k = 0, l, m; k < f.length; k++) { + if (l = f[k], !h[l] && (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), !b || !m.includes(a))) { + if (m.length === 2 ** 31 - 1) { + g = new Aa(m); if (this.fastupdate) { - for (let q of this.reg.values()) { - q.includes(n) && (q[q.indexOf(n)] = g); + for (let p of this.reg.values()) { + p.includes(m) && (p[p.indexOf(m)] = g); } } - d.set(l, n = g); + d.set(l, m = g); } - n.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(n) : this.reg.set(a, [n])); + m.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); } } } else { @@ -721,49 +714,49 @@ function Na(a, c, b) { } } if (this.store && (!b || !this.store.has(a))) { - let k; + let h; if (this.h) { - k = I(); - for (let h = 0, l; h < this.h.length; h++) { - l = this.h[h]; + h = I(); + for (let k = 0, l; k < this.h.length; k++) { + l = this.h[k]; if ((b = l.G) && !b(c)) { continue; } - let n; + let m; if (typeof l === "function") { - n = l(c); - if (!n) { + m = l(c); + if (!m) { continue; } l = [l.O]; } else if (N(l) || l.constructor === String) { - k[l] = c[l]; + h[l] = c[l]; continue; } - Sa(c, k, l, 0, l[0], n); + Ra(c, h, l, 0, l[0], m); } } - this.store.set(a, k || c); + this.store.set(a, h || c); } this.worker && (this.fastupdate || this.reg.add(a)); } return this; }; -function Sa(a, c, b, e, d, f) { +function Ra(a, c, b, e, d, f) { a = a[d]; if (e === b.length - 1) { c[d] = f || a; } else if (a) { if (a.constructor === Array) { for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Sa(a, c, b, e, d); + Ra(a, c, b, e, d); } } else { - c = c[d] || (c[d] = I()), d = b[++e], Sa(a, c, b, e, d); + c = c[d] || (c[d] = I()), d = b[++e], Ra(a, c, b, e, d); } } } -function Ra(a, c, b, e, d, f, g, k) { +function Qa(a, c, b, e, d, f, g, h) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -775,52 +768,52 @@ function Ra(a, c, b, e, d, f, g, k) { } a = a.join(" "); } - d.add(f, a, k, !0); + d.add(f, a, h, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ra(a, c, b, e, d, f, g, k); + Qa(a, c, b, e, d, f, g, h); } } else { - g = c[++e], Ra(a, c, b, e, d, f, g, k); + g = c[++e], Qa(a, c, b, e, d, f, g, h); } } } } -;function Ta(a, c, b, e) { +;function Sa(a, c, b, e) { if (!a.length) { return a; } if (a.length === 1) { - return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a, e ? Ua.call(this, a) : a; + return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a, e ? Ta.call(this, a) : a; } let d = []; - for (let f = 0, g, k; f < a.length; f++) { - if ((g = a[f]) && (k = g.length)) { + for (let f = 0, g, h; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { if (b) { - if (b >= k) { - b -= k; + if (b >= h) { + b -= h; continue; } g = g.slice(b, b + c); - k = g.length; + h = g.length; b = 0; } - k > c && (g = g.slice(0, c), k = c); - if (!d.length && k >= c) { - return e ? Ua.call(this, g) : g; + h > c && (g = g.slice(0, c), h = c); + if (!d.length && h >= c) { + return e ? Ta.call(this, g) : g; } d.push(g); - c -= k; + c -= h; if (!c) { break; } } } d = d.length > 1 ? [].concat.apply([], d) : d[0]; - return e ? Ua.call(this, d) : d; + return e ? Ta.call(this, d) : d; } -;function Va(a, c, b, e) { +;function Ua(a, c, b, e) { var d = e[0]; if (d[0] && d[0].query) { return a[c].apply(a, d); @@ -828,7 +821,7 @@ function Ra(a, c, b, e, d, f, g, k) { if (!(c !== "and" && c !== "not" || a.result.length || a.await || d.suggest)) { return e.length > 1 && (d = e[e.length - 1]), (e = d.resolve) ? a.await || a.result : a; } - let f = [], g = 0, k = 0, h, l, n, q, u; + let f = [], g = 0, h = 0, k, l, m, p, u; for (c = 0; c < e.length; c++) { if (d = e[c]) { var r = void 0; @@ -838,64 +831,65 @@ function Ra(a, c, b, e, d, f, g, k) { r = d; } else { g = d.limit || 0; - k = d.offset || 0; - n = d.suggest; - h = ((q = (l = d.resolve) && d.highlight) || d.enrich) && l; + h = d.offset || 0; + m = d.suggest; + l = d.resolve; + k = ((p = d.highlight || a.highlight) || d.enrich) && l; r = d.queue; - let t = d.async || r, m = d.index; - m ? a.index || (a.index = m) : m = a.index; - if (d.query || d.tag) { - if (!m) { + let t = d.async || r, n = d.index, q = d.query; + n ? a.index || (a.index = n) : n = a.index; + if (q || d.tag) { + if (!n) { throw Error("Resolver can't apply because the corresponding Index was never specified"); } - const p = d.field || d.pluck; - if (p) { - d.query && (a.query = d.query, a.field = p); - if (!m.index) { + const x = d.field || d.pluck; + if (x) { + !q || a.query && !p || (a.query = q, a.field = x, a.highlight = p); + if (!n.index) { throw Error("Resolver can't apply because the corresponding Document Index was not specified"); } - m = m.index.get(p); - if (!m) { - throw Error("Resolver can't apply because the specified Document Field '" + p + "' was not found"); + n = n.index.get(x); + if (!n) { + throw Error("Resolver can't apply because the specified Document Field '" + x + "' was not found"); } } if (r && (u || a.await)) { u = 1; - let x; - const v = a.C.length, A = new Promise(function(C) { - x = C; + let v; + const A = a.C.length, D = new Promise(function(G) { + v = G; }); - (function(C, G) { - A.h = function() { - G.index = null; - G.resolve = !1; - let B = t ? C.searchAsync(G) : C.search(G); + (function(G, E) { + D.h = function() { + E.index = null; + E.resolve = !1; + let B = t ? G.searchAsync(E) : G.search(E); if (B.then) { - return B.then(function(E) { - a.C[v] = E = E.result || E; - x(E); - return E; + return B.then(function(z) { + a.C[A] = z = z.result || z; + v(z); + return z; }); } B = B.result || B; - x(B); + v(B); return B; }; - })(m, Object.assign({}, d)); - a.C.push(A); - f[c] = A; + })(n, Object.assign({}, d)); + a.C.push(D); + f[c] = D; continue; } else { - d.resolve = !1, d.index = null, r = t ? m.searchAsync(d) : m.search(d), d.resolve = l, d.index = m; + d.resolve = !1, d.index = null, r = t ? n.searchAsync(d) : n.search(d), d.resolve = l, d.index = n; } } else if (d.and) { - r = Wa(d, "and", m); + r = Va(d, "and", n); } else if (d.or) { - r = Wa(d, "or", m); + r = Va(d, "or", n); } else if (d.not) { - r = Wa(d, "not", m); + r = Va(d, "not", n); } else if (d.xor) { - r = Wa(d, "xor", m); + r = Va(d, "xor", n); } else { continue; } @@ -910,28 +904,28 @@ function Ra(a, c, b, e, d, f, g, k) { a.return = t; })); if (u) { - const t = Promise.all(f).then(function(m) { - for (let p = 0; p < a.C.length; p++) { - if (a.C[p] === t) { - a.C[p] = function() { - return b.call(a, m, g, k, h, l, n, q); + const t = Promise.all(f).then(function(n) { + for (let q = 0; q < a.C.length; q++) { + if (a.C[q] === t) { + a.C[q] = function() { + return b.call(a, n, g, h, k, l, m, p); }; break; } } - Xa(a); + Wa(a); }); a.C.push(t); } else if (a.await) { a.C.push(function() { - return b.call(a, f, g, k, h, l, n, q); + return b.call(a, f, g, h, k, l, m, p); }); } else { - return b.call(a, f, g, k, h, l, n, q); + return b.call(a, f, g, h, k, l, m, p); } return l ? a.await || a.result : a; } -function Wa(a, c, b) { +function Va(a, c, b) { a = a[c]; const e = a[0] || a; e.index || (e.index = b); @@ -940,87 +934,87 @@ function Wa(a, c, b) { return b; } ;X.prototype.or = function() { - return Va(this, "or", Ya, arguments); + return Ua(this, "or", Xa, arguments); }; -function Ya(a, c, b, e, d, f, g) { - a.length && (this.result.length && a.push(this.result), a.length < 2 ? this.result = a[0] : (this.result = Za(a, c, b, !1, this.h), b = 0)); +function Xa(a, c, b, e, d, f, g) { + a.length && (this.result.length && a.push(this.result), a.length < 2 ? this.result = a[0] : (this.result = Ya(a, c, b, !1, this.h), b = 0)); d && (this.await = null); return d ? this.resolve(c, b, e, g) : this; } ;X.prototype.and = function() { - return Va(this, "and", $a, arguments); + return Ua(this, "and", Za, arguments); }; -function $a(a, c, b, e, d, f, g) { +function Za(a, c, b, e, d, f, g) { if (!f && !this.result.length) { return d ? this.result : this; } - let k; + let h; if (a.length) { if (this.result.length && a.unshift(this.result), a.length < 2) { this.result = a[0]; } else { - let h = 0; - for (let l = 0, n, q; l < a.length; l++) { - if ((n = a[l]) && (q = n.length)) { - h < q && (h = q); + let k = 0; + for (let l = 0, m, p; l < a.length; l++) { + if ((m = a[l]) && (p = m.length)) { + k < p && (k = p); } else if (!f) { - h = 0; + k = 0; break; } } - h ? (this.result = ab(a, h, c, b, f, this.h, d), k = !0) : this.result = []; + k ? (this.result = $a(a, k, c, b, f, this.h, d), h = !0) : this.result = []; } } else { f || (this.result = a); } d && (this.await = null); - return d ? this.resolve(c, b, e, g, k) : this; + return d ? this.resolve(c, b, e, g, h) : this; } ;X.prototype.xor = function() { - return Va(this, "xor", bb, arguments); + return Ua(this, "xor", ab, arguments); }; -function bb(a, c, b, e, d, f, g) { +function ab(a, c, b, e, d, f, g) { if (a.length) { if (this.result.length && a.unshift(this.result), a.length < 2) { this.result = a[0]; } else { a: { f = b; - var k = this.h; - const h = [], l = I(); - let n = 0; - for (let q = 0, u; q < a.length; q++) { - if (u = a[q]) { - n < u.length && (n = u.length); + var h = this.h; + const k = [], l = I(); + let m = 0; + for (let p = 0, u; p < a.length; p++) { + if (u = a[p]) { + m < u.length && (m = u.length); for (let r = 0, t; r < u.length; r++) { if (t = u[r]) { - for (let m = 0, p; m < t.length; m++) { - p = t[m], l[p] = l[p] ? 2 : 1; + for (let n = 0, q; n < t.length; n++) { + q = t[n], l[q] = l[q] ? 2 : 1; } } } } } - for (let q = 0, u, r = 0; q < n; q++) { - for (let t = 0, m; t < a.length; t++) { - if (m = a[t]) { - if (u = m[q]) { - for (let p = 0, x; p < u.length; p++) { - if (x = u[p], l[x] === 1) { + for (let p = 0, u, r = 0; p < m; p++) { + for (let t = 0, n; t < a.length; t++) { + if (n = a[t]) { + if (u = n[p]) { + for (let q = 0, x; q < u.length; q++) { + if (x = u[q], l[x] === 1) { if (f) { f--; } else { if (d) { - if (h.push(x), h.length === c) { - a = h; + if (k.push(x), k.length === c) { + a = k; break a; } } else { - const v = q + (t ? k : 0); - h[v] || (h[v] = []); - h[v].push(x); + const v = p + (t ? h : 0); + k[v] || (k[v] = []); + k[v].push(x); if (++r === c) { - a = h; + a = k; break a; } } @@ -1031,44 +1025,44 @@ function bb(a, c, b, e, d, f, g) { } } } - a = h; + a = k; } this.result = a; - k = !0; + h = !0; } } else { f || (this.result = a); } d && (this.await = null); - return d ? this.resolve(c, b, e, g, k) : this; + return d ? this.resolve(c, b, e, g, h) : this; } ;X.prototype.not = function() { - return Va(this, "not", cb, arguments); + return Ua(this, "not", bb, arguments); }; -function cb(a, c, b, e, d, f, g) { +function bb(a, c, b, e, d, f, g) { if (!f && !this.result.length) { return d ? this.result : this; } if (a.length && this.result.length) { a: { f = b; - var k = []; + var h = []; a = new Set(a.flat().flat()); - for (let h = 0, l, n = 0; h < this.result.length; h++) { - if (l = this.result[h]) { - for (let q = 0, u; q < l.length; q++) { - if (u = l[q], !a.has(u)) { + for (let k = 0, l, m = 0; k < this.result.length; k++) { + if (l = this.result[k]) { + for (let p = 0, u; p < l.length; p++) { + if (u = l[p], !a.has(u)) { if (f) { f--; } else { if (d) { - if (k.push(u), k.length === c) { - a = k; + if (h.push(u), h.length === c) { + a = h; break a; } } else { - if (k[h] || (k[h] = []), k[h].push(u), ++n === c) { - a = k; + if (h[k] || (h[k] = []), h[k].push(u), ++m === c) { + a = h; break a; } } @@ -1077,16 +1071,16 @@ function cb(a, c, b, e, d, f, g) { } } } - a = k; + a = h; } this.result = a; - k = !0; + h = !0; } d && (this.await = null); - return d ? this.resolve(c, b, e, g, k) : this; + return d ? this.resolve(c, b, e, g, h) : this; } -;function eb(a, c, b, e, d) { - let f, g, k; +;function cb(a, c, b, e, d) { + let f, g, h; typeof d === "string" ? (f = d, d = "") : f = d.template; if (!f) { throw Error('No template pattern was specified by the search option "highlight"'); @@ -1095,201 +1089,201 @@ function cb(a, c, b, e, d, f, g) { if (g === -1) { throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); } - k = f.substring(g + 2); + h = f.substring(g + 2); g = f.substring(0, g); - let h = d && d.boundary, l = !d || d.clip !== !1, n = d && d.merge && k && g && new RegExp(k + " " + g, "g"); + let k = d && d.boundary, l = !d || d.clip !== !1, m = d && d.merge && h && g && new RegExp(h + " " + g, "g"); d = d && d.ellipsis; - var q = 0; + var p = 0; if (typeof d === "object") { var u = d.template; - q = u.length - 2; + p = u.length - 2; d = d.pattern; } typeof d !== "string" && (d = d === !1 ? "" : "..."); - q && (d = u.replace("$1", d)); - u = d.length - q; + p && (d = u.replace("$1", d)); + u = d.length - p; let r, t; - typeof h === "object" && (r = h.before, r === 0 && (r = -1), t = h.after, t === 0 && (t = -1), h = h.total || 9e5); - q = new Map(); + typeof k === "object" && (r = k.before, r === 0 && (r = -1), t = k.after, t === 0 && (t = -1), k = k.total || 9e5); + p = new Map(); for (let Oa = 0, ea, db, pa; Oa < c.length; Oa++) { let qa; if (e) { qa = c, pa = e; } else { - var m = c[Oa]; - pa = m.field; + var n = c[Oa]; + pa = n.field; if (!pa) { continue; } - qa = m.result; + qa = n.result; } db = b.get(pa); ea = db.encoder; - m = q.get(ea); - typeof m !== "string" && (m = ea.encode(a), q.set(ea, m)); + n = p.get(ea); + typeof n !== "string" && (n = ea.encode(a), p.set(ea, n)); for (let ya = 0; ya < qa.length; ya++) { - var p = qa[ya].doc; - if (!p) { + var q = qa[ya].doc; + if (!q) { continue; } - p = da(p, pa); - if (!p) { + q = ca(q, pa); + if (!q) { continue; } - var x = p.trim().split(/\s+/); + var x = q.trim().split(/\s+/); if (!x.length) { continue; } - p = ""; + q = ""; var v = []; let za = []; - var A = -1, C = -1, G = 0; - for (var B = 0; B < x.length; B++) { - var E = x[B], z = ea.encode(E); + var A = -1, D = -1, G = 0; + for (var E = 0; E < x.length; E++) { + var B = x[E], z = ea.encode(B); z = z.length > 1 ? z.join(" ") : z[0]; let y; - if (z && E) { - var D = E.length, K = (ea.split ? E.replace(ea.split, "") : E).length - z.length, F = "", L = 0; - for (var O = 0; O < m.length; O++) { - var P = m[O]; + if (z && B) { + var C = B.length, K = (ea.split ? B.replace(ea.split, "") : B).length - z.length, F = "", L = 0; + for (var O = 0; O < n.length; O++) { + var P = n[O]; if (P) { var M = P.length; M += K; - L && M <= L || (P = z.indexOf(P), P > -1 && (F = (P ? E.substring(0, P) : "") + g + E.substring(P, P + M) + k + (P + M < D ? E.substring(P + M) : ""), L = M, y = !0)); + L && M <= L || (P = z.indexOf(P), P > -1 && (F = (P ? B.substring(0, P) : "") + g + B.substring(P, P + M) + h + (P + M < C ? B.substring(P + M) : ""), L = M, y = !0)); } } - F && (h && (A < 0 && (A = p.length + (p ? 1 : 0)), C = p.length + (p ? 1 : 0) + F.length, G += D, za.push(v.length), v.push({match:F})), p += (p ? " " : "") + F); + F && (k && (A < 0 && (A = q.length + (q ? 1 : 0)), D = q.length + (q ? 1 : 0) + F.length, G += C, za.push(v.length), v.push({match:F})), q += (q ? " " : "") + F); } if (!y) { - E = x[B], p += (p ? " " : "") + E, h && v.push({text:E}); - } else if (h && G >= h) { + B = x[E], q += (q ? " " : "") + B, k && v.push({text:B}); + } else if (k && G >= k) { break; } } G = za.length * (f.length - 2); - if (r || t || h && p.length - G > h) { - if (G = h + G - u * 2, B = C - A, r > 0 && (B += r), t > 0 && (B += t), B <= G) { - x = r ? A - (r > 0 ? r : 0) : A - ((G - B) / 2 | 0), v = t ? C + (t > 0 ? t : 0) : x + G, l || (x > 0 && p.charAt(x) !== " " && p.charAt(x - 1) !== " " && (x = p.indexOf(" ", x), x < 0 && (x = 0)), v < p.length && p.charAt(v - 1) !== " " && p.charAt(v) !== " " && (v = p.lastIndexOf(" ", v), v < C ? v = C : ++v)), p = (x ? d : "") + p.substring(x, v) + (v < p.length ? d : ""); + if (r || t || k && q.length - G > k) { + if (G = k + G - u * 2, E = D - A, r > 0 && (E += r), t > 0 && (E += t), E <= G) { + x = r ? A - (r > 0 ? r : 0) : A - ((G - E) / 2 | 0), v = t ? D + (t > 0 ? t : 0) : x + G, l || (x > 0 && q.charAt(x) !== " " && q.charAt(x - 1) !== " " && (x = q.indexOf(" ", x), x < 0 && (x = 0)), v < q.length && q.charAt(v - 1) !== " " && q.charAt(v) !== " " && (v = q.lastIndexOf(" ", v), v < D ? v = D : ++v)), q = (x ? d : "") + q.substring(x, v) + (v < q.length ? d : ""); } else { - C = []; + D = []; A = {}; G = {}; - B = {}; E = {}; + B = {}; z = {}; - F = K = D = 0; + F = K = C = 0; for (O = L = 1;;) { var U = void 0; for (let y = 0, J; y < za.length; y++) { J = za[y]; if (F) { if (K !== F) { - if (B[y + 1]) { + if (E[y + 1]) { continue; } J += F; if (A[J]) { - D -= u; + C -= u; G[y + 1] = 1; - B[y + 1] = 1; + E[y + 1] = 1; continue; } if (J >= v.length - 1) { if (J >= v.length) { - B[y + 1] = 1; + E[y + 1] = 1; J >= x.length && (G[y + 1] = 1); continue; } - D -= u; + C -= u; } - p = v[J].text; + q = v[J].text; if (M = t && z[y]) { if (M > 0) { - if (p.length > M) { - if (B[y + 1] = 1, l) { - p = p.substring(0, M); + if (q.length > M) { + if (E[y + 1] = 1, l) { + q = q.substring(0, M); } else { continue; } } - (M -= p.length) || (M = -1); + (M -= q.length) || (M = -1); z[y] = M; } else { - B[y + 1] = 1; + E[y + 1] = 1; continue; } } - if (D + p.length + 1 <= h) { - p = " " + p, C[y] += p; + if (C + q.length + 1 <= k) { + q = " " + q, D[y] += q; } else if (l) { - U = h - D - 1, U > 0 && (p = " " + p.substring(0, U), C[y] += p), B[y + 1] = 1; + U = k - C - 1, U > 0 && (q = " " + q.substring(0, U), D[y] += q), E[y + 1] = 1; } else { - B[y + 1] = 1; + E[y + 1] = 1; continue; } } else { - if (B[y]) { + if (E[y]) { continue; } J -= K; if (A[J]) { - D -= u; - B[y] = 1; + C -= u; + E[y] = 1; G[y] = 1; continue; } if (J <= 0) { if (J < 0) { - B[y] = 1; + E[y] = 1; G[y] = 1; continue; } - D -= u; + C -= u; } - p = v[J].text; - if (M = r && E[y]) { + q = v[J].text; + if (M = r && B[y]) { if (M > 0) { - if (p.length > M) { - if (B[y] = 1, l) { - p = p.substring(p.length - M); + if (q.length > M) { + if (E[y] = 1, l) { + q = q.substring(q.length - M); } else { continue; } } - (M -= p.length) || (M = -1); - E[y] = M; + (M -= q.length) || (M = -1); + B[y] = M; } else { - B[y] = 1; + E[y] = 1; continue; } } - if (D + p.length + 1 <= h) { - p += " ", C[y] = p + C[y]; + if (C + q.length + 1 <= k) { + q += " ", D[y] = q + D[y]; } else if (l) { - U = p.length + 1 - (h - D), U >= 0 && U < p.length && (p = p.substring(U) + " ", C[y] = p + C[y]), B[y] = 1; + U = q.length + 1 - (k - C), U >= 0 && U < q.length && (q = q.substring(U) + " ", D[y] = q + D[y]), E[y] = 1; } else { - B[y] = 1; + E[y] = 1; continue; } } } else { - p = v[J].match; - r && (E[y] = r); + q = v[J].match; + r && (B[y] = r); t && (z[y] = t); - y && D++; + y && C++; let Pa; - J ? !y && u && (D += u) : (G[y] = 1, B[y] = 1); - J >= x.length - 1 ? Pa = 1 : J < v.length - 1 && v[J + 1].match ? Pa = 1 : u && (D += u); - D -= f.length - 2; - if (!y || D + p.length <= h) { - C[y] = p; + J ? !y && u && (C += u) : (G[y] = 1, E[y] = 1); + J >= x.length - 1 ? Pa = 1 : J < v.length - 1 && v[J + 1].match ? Pa = 1 : u && (C += u); + C -= f.length - 2; + if (!y || C + q.length <= k) { + D[y] = q; } else { U = L = O = G[y] = 0; break; } - Pa && (G[y + 1] = 1, B[y + 1] = 1); + Pa && (G[y + 1] = 1, E[y + 1] = 1); } - D += p.length; + C += q.length; U = A[J] = 1; } if (U) { @@ -1302,15 +1296,15 @@ function cb(a, c, b, e, d, f, g) { L ? (K++, F = K) : F++; } } - p = ""; - for (let y = 0, J; y < C.length; y++) { - J = (y && G[y] ? " " : (y && !d ? " " : "") + d) + C[y], p += J; + q = ""; + for (let y = 0, J; y < D.length; y++) { + J = (y && G[y] ? " " : (y && !d ? " " : "") + d) + D[y], q += J; } - d && !G[C.length] && (p += d); + d && !G[D.length] && (q += d); } } - n && (p = p.replace(n, " ")); - qa[ya].highlight = p; + m && (q = q.replace(m, " ")); + qa[ya].highlight = q; } if (e) { break; @@ -1322,43 +1316,45 @@ function cb(a, c, b, e, d, f, g) { if (!this || this.constructor !== X) { return new X(a, c); } - let b = 0, e, d, f, g, k; + let b = 0, e, d, f, g, h, k; if (a && a.index) { - const h = a; - c = h.index; - b = h.boost || 0; - if (d = h.query) { - f = h.field || h.pluck; - const l = h.resolve; - a = h.async || h.queue; - h.resolve = !1; - h.index = null; - a = a ? c.searchAsync(h) : c.search(h); - h.resolve = l; - h.index = c; + const l = a; + c = l.index; + b = l.boost || 0; + if (d = l.query) { + f = l.field || l.pluck; + g = l.highlight; + const m = l.resolve; + a = l.async || l.queue; + l.resolve = !1; + l.index = null; + a = a ? c.searchAsync(l) : c.search(l); + l.resolve = m; + l.index = c; a = a.result || a; } else { a = []; } } if (a && a.then) { - const h = this; - a = a.then(function(l) { - h.C[0] = h.result = l.result || l; - Xa(h); + const l = this; + a = a.then(function(m) { + l.C[0] = l.result = m.result || m; + Wa(l); }); e = [a]; a = []; - g = new Promise(function(l) { - k = l; + h = new Promise(function(m) { + k = m; }); } this.index = c || null; this.result = a || []; this.h = b; this.C = e || []; - this.await = g || null; + this.await = h || null; this.return = k || null; + this.highlight = g || null; this.query = d || ""; this.field = f || ""; } @@ -1367,8 +1363,7 @@ w.limit = function(a) { if (this.await) { const c = this; this.C.push(function() { - c.limit(a); - return c.result; + return c.limit(a).result; }); } else { if (this.result.length) { @@ -1394,8 +1389,7 @@ w.offset = function(a) { if (this.await) { const c = this; this.C.push(function() { - c.offset(a); - return c.result; + return c.offset(a).result; }); } else { if (this.result.length) { @@ -1414,15 +1408,14 @@ w.boost = function(a) { if (this.await) { const c = this; this.C.push(function() { - c.boost(a); - return c.result; + return c.boost(a).result; }); } else { this.h += a; } return this; }; -function Xa(a, c) { +function Wa(a, c) { let b = a.result; var e = a.await; a.await = null; @@ -1444,14 +1437,14 @@ function Xa(a, c) { return b; } w.resolve = function(a, c, b, e, d) { - let f = this.await ? Xa(this, !0) : this.result; + let f = this.await ? Wa(this, !0) : this.result; if (f.then) { const g = this; return f.then(function() { return g.resolve(a, c, b, e, d); }); } - f.length && (typeof a === "object" ? (e = a.highlight, b = !!e || a.enrich, c = a.offset, a = a.limit) : b = !!e || b, f = d ? b ? Ua.call(this.index, f) : f : Ta.call(this.index, f, a || 100, c, b)); + f.length && (typeof a === "object" ? (e = a.highlight || this.highlight, b = !!e || a.enrich, c = a.offset, a = a.limit) : (e = e || this.highlight, b = !!e || b), f = d ? b ? Ta.call(this.index, f) : f : Sa.call(this.index, f, a || 100, c, b)); return this.finalize(f, e); }; w.finalize = function(a, c) { @@ -1461,54 +1454,54 @@ w.finalize = function(a, c) { return e.finalize(d, c); }); } - c && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); - c && a.length && this.query && (a = eb(this.query, a, this.index.index, this.field, c)); + c && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the highlight resolver stage like { query: "...", highlight: ... }.'); + c && a.length && this.query && (a = cb(this.query, a, this.index.index, this.field, c)); const b = this.return; - this.index = this.result = this.C = this.await = this.return = null; + this.highlight = this.index = this.result = this.C = this.await = this.return = null; this.query = this.field = ""; b && b(a); return a; }; -function ab(a, c, b, e, d, f, g) { - const k = a.length; - let h = [], l, n; +function $a(a, c, b, e, d, f, g) { + const h = a.length; + let k = [], l, m; l = I(); - for (let q = 0, u, r, t, m; q < c; q++) { - for (let p = 0; p < k; p++) { - if (t = a[p], q < t.length && (u = t[q])) { + for (let p = 0, u, r, t, n; p < c; p++) { + for (let q = 0; q < h; q++) { + if (t = a[q], p < t.length && (u = t[p])) { for (let x = 0; x < u.length; x++) { r = u[x]; - (n = l[r]) ? l[r]++ : (n = 0, l[r] = 1); - m = h[n] || (h[n] = []); + (m = l[r]) ? l[r]++ : (m = 0, l[r] = 1); + n = k[m] || (k[m] = []); if (!g) { - let v = q + (p || !d ? 0 : f || 0); - m = m[v] || (m[v] = []); + let v = p + (q || !d ? 0 : f || 0); + n = n[v] || (n[v] = []); } - m.push(r); - if (g && b && n === k - 1 && m.length - e === b) { - return e ? m.slice(e) : m; + n.push(r); + if (g && b && m === h - 1 && n.length - e === b) { + return e ? n.slice(e) : n; } } } } } - if (a = h.length) { + if (a = k.length) { if (d) { - h = h.length > 1 ? Za(h, b, e, g, f) : (h = h[0]) && b && h.length > b || e ? h.slice(e, b + e) : h; + k = k.length > 1 ? Ya(k, b, e, g, f) : (k = k[0]) && b && k.length > b || e ? k.slice(e, b + e) : k; } else { - if (a < k) { + if (a < h) { return []; } - h = h[a - 1]; + k = k[a - 1]; if (b || e) { if (g) { - if (h.length > b || e) { - h = h.slice(e, b + e); + if (k.length > b || e) { + k = k.slice(e, b + e); } } else { d = []; - for (let q = 0, u; q < h.length; q++) { - if (u = h[q]) { + for (let p = 0, u; p < k.length; p++) { + if (u = k[p]) { if (e && u.length > e) { e -= u.length; } else { @@ -1522,27 +1515,27 @@ function ab(a, c, b, e, d, f, g) { } } } - h = d; + k = d; } } } } - return h; + return k; } -function Za(a, c, b, e, d) { +function Ya(a, c, b, e, d) { const f = [], g = I(); - let k; - var h = a.length; + let h; + var k = a.length; let l; if (e) { - for (d = h - 1; d >= 0; d--) { + for (d = k - 1; d >= 0; d--) { if (l = (e = a[d]) && e.length) { - for (h = 0; h < l; h++) { - if (k = e[h], !g[k]) { - if (g[k] = 1, b) { + for (k = 0; k < l; k++) { + if (h = e[k], !g[h]) { + if (g[h] = 1, b) { b--; } else { - if (f.push(k), f.length === c) { + if (f.push(h), f.length === c) { return f; } } @@ -1551,17 +1544,17 @@ function Za(a, c, b, e, d) { } } } else { - for (let n = h - 1, q, u = 0; n >= 0; n--) { - q = a[n]; - for (let r = 0; r < q.length; r++) { - if (l = (e = q[r]) && e.length) { + for (let m = k - 1, p, u = 0; m >= 0; m--) { + p = a[m]; + for (let r = 0; r < p.length; r++) { + if (l = (e = p[r]) && e.length) { for (let t = 0; t < l; t++) { - if (k = e[t], !g[k]) { - if (g[k] = 1, b) { + if (h = e[t], !g[h]) { + if (g[h] = 1, b) { b--; } else { - let m = (r + (n < h - 1 ? d || 0 : 0)) / (n + 1) | 0; - (f[m] || (f[m] = [])).push(k); + let n = (r + (m < k - 1 ? d || 0 : 0)) / (m + 1) | 0; + (f[n] || (f[n] = [])).push(h); if (++u === c) { return f; } @@ -1574,12 +1567,12 @@ function Za(a, c, b, e, d) { } return f; } -function fb(a, c, b) { +function eb(a, c, b) { const e = I(), d = []; for (let f = 0, g; f < c.length; f++) { g = c[f]; - for (let k = 0; k < g.length; k++) { - e[g[k]] = 1; + for (let h = 0; h < g.length; h++) { + e[g[h]] = 1; } } if (b) { @@ -1587,62 +1580,62 @@ function fb(a, c, b) { g = a[f], e[g] && (d.push(g), e[g] = 0); } } else { - for (let f = 0, g, k; f < a.result.length; f++) { + for (let f = 0, g, h; f < a.result.length; f++) { for (g = a.result[f], c = 0; c < g.length; c++) { - k = g[c], e[k] && ((d[f] || (d[f] = [])).push(k), e[k] = 0); + h = g[c], e[h] && ((d[f] || (d[f] = [])).push(h), e[h] = 0); } } } return d; } ;I(); -Qa.prototype.search = function(a, c, b, e) { +Na.prototype.search = function(a, c, b, e) { b || (!c && ba(a) ? (b = a, a = "") : ba(c) && (b = c, c = 0)); let d = []; var f = []; let g; - let k, h, l, n, q; + let h, k, l, m, p; let u = 0, r = !0, t; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; g = b.pluck; - k = b.merge; + h = b.merge; l = b.boost; - q = g || b.field || (q = b.index) && (q.index ? null : q); - var m = this.tag && b.tag; - h = b.suggest; + p = g || b.field || (p = b.index) && (p.index ? null : p); + var n = this.tag && b.tag; + k = b.suggest; r = b.resolve !== !1; - n = b.cache; + m = b.cache; this.store && b.highlight && !r ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !r && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); t = r && this.store && b.highlight; - var p = !!t || r && this.store && b.enrich; + var q = !!t || r && this.store && b.enrich; c = b.limit || c; var x = b.offset || 0; c || (c = r ? 100 : 0); - if (m && (!this.db || !e)) { - m.constructor !== Array && (m = [m]); + if (n && (!this.db || !e)) { + n.constructor !== Array && (n = [n]); var v = []; - for (let E = 0, z; E < m.length; E++) { - z = m[E]; + for (let B = 0, z; B < n.length; B++) { + z = n[B]; if (N(z)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } if (z.field && z.tag) { var A = z.tag; if (A.constructor === Array) { - for (var C = 0; C < A.length; C++) { - v.push(z.field, A[C]); + for (var D = 0; D < A.length; D++) { + v.push(z.field, A[D]); } } else { v.push(z.field, A); } } else { A = Object.keys(z); - for (let D = 0, K, F; D < A.length; D++) { - if (K = A[D], F = z[K], F.constructor === Array) { - for (C = 0; C < F.length; C++) { - v.push(K, F[C]); + for (let C = 0, K, F; C < A.length; C++) { + if (K = A[C], F = z[K], F.constructor === Array) { + for (D = 0; D < F.length; D++) { + v.push(K, F[D]); } } else { v.push(K, F); @@ -1653,181 +1646,181 @@ Qa.prototype.search = function(a, c, b, e) { if (!v.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - m = v; + n = v; if (!a) { f = []; if (v.length) { - for (m = 0; m < v.length; m += 2) { + for (n = 0; n < v.length; n += 2) { if (this.db) { - e = this.index.get(v[m]); + e = this.index.get(v[n]); if (!e) { - console.warn("Tag '" + v[m] + ":" + v[m + 1] + "' will be skipped because there is no field '" + v[m] + "'."); + console.warn("Tag '" + v[n] + ":" + v[n + 1] + "' will be skipped because there is no field '" + v[n] + "'."); continue; } - f.push(e = e.db.tag(v[m + 1], c, x, p)); + f.push(e = e.db.tag(v[n + 1], c, x, q)); } else { - e = gb.call(this, v[m], v[m + 1], c, x, p); + e = fb.call(this, v[n], v[n + 1], c, x, q); } - d.push(r ? {field:v[m], tag:v[m + 1], result:e} : [e]); + d.push(r ? {field:v[n], tag:v[n + 1], result:e} : [e]); } } if (f.length) { - const E = this; + const B = this; return Promise.all(f).then(function(z) { - for (let D = 0; D < z.length; D++) { - r ? d[D].result = z[D] : d[D] = z[D]; + for (let C = 0; C < z.length; C++) { + r ? d[C].result = z[C] : d[C] = z[C]; } - return r ? d : new X(d.length > 1 ? ab(d, 1, 0, 0, h, l) : d[0], E); + return r ? d : new X(d.length > 1 ? $a(d, 1, 0, 0, k, l) : d[0], B); }); } - return r ? d : new X(d.length > 1 ? ab(d, 1, 0, 0, h, l) : d[0], this); + return r ? d : new X(d.length > 1 ? $a(d, 1, 0, 0, k, l) : d[0], this); } } if (!r && !g) { - if (q = q || this.field) { - N(q) ? g = q : (q.constructor === Array && q.length === 1 && (q = q[0]), g = q.field || q.index); + if (p = p || this.field) { + N(p) ? g = p : (p.constructor === Array && p.length === 1 && (p = p[0]), g = p.field || p.index); } if (!g) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); } } - q && q.constructor !== Array && (q = [q]); + p && p.constructor !== Array && (p = [p]); } - q || (q = this.field); + p || (p = this.field); let G; v = (this.worker || this.db) && !e && []; - for (let E = 0, z, D, K; E < q.length; E++) { - D = q[E]; - if (this.db && this.tag && !this.B[E]) { + for (let B = 0, z, C, K; B < p.length; B++) { + C = p[B]; + if (this.db && this.tag && !this.B[B]) { continue; } let F; - N(D) || (F = D, D = F.field, a = F.query || a, c = aa(F.limit, c), x = aa(F.offset, x), h = aa(F.suggest, h), t = r && this.store && aa(F.highlight, t), p = !!t || r && this.store && aa(F.enrich, p), n = aa(F.cache, n)); + N(C) || (F = C, C = F.field, a = F.query || a, c = aa(F.limit, c), x = aa(F.offset, x), k = aa(F.suggest, k), t = r && this.store && aa(F.highlight, t), q = !!t || r && this.store && aa(F.enrich, q), m = aa(F.cache, m)); if (e) { - z = e[E]; + z = e[B]; } else { A = F || b || {}; - C = A.enrich; - var B = this.index.get(D); - m && (this.db && (A.tag = m, G = B.db.support_tag_search, A.field = q), !G && C && (A.enrich = !1)); - z = n ? B.searchCache(a, c, A) : B.search(a, c, A); - C && (A.enrich = C); + D = A.enrich; + var E = this.index.get(C); + n && (this.db && (A.tag = n, G = E.db.support_tag_search, A.field = p), !G && D && (A.enrich = !1)); + z = m ? E.searchCache(a, c, A) : E.search(a, c, A); + D && (A.enrich = D); if (v) { - v[E] = z; + v[B] = z; continue; } } K = (z = z.result || z) && z.length; - if (m && K) { + if (n && K) { A = []; - C = 0; + D = 0; if (this.db && e) { if (!G) { - for (B = q.length; B < e.length; B++) { - let L = e[B]; + for (E = p.length; E < e.length; E++) { + let L = e[E]; if (L && L.length) { - C++, A.push(L); - } else if (!h) { + D++, A.push(L); + } else if (!k) { return r ? d : new X(d, this); } } } } else { - for (let L = 0, O, P; L < m.length; L += 2) { - O = this.tag.get(m[L]); + for (let L = 0, O, P; L < n.length; L += 2) { + O = this.tag.get(n[L]); if (!O) { - if (console.warn("Tag '" + m[L] + ":" + m[L + 1] + "' will be skipped because there is no field '" + m[L] + "'."), h) { + if (console.warn("Tag '" + n[L] + ":" + n[L + 1] + "' will be skipped because there is no field '" + n[L] + "'."), k) { continue; } else { return r ? d : new X(d, this); } } - if (P = (O = O && O.get(m[L + 1])) && O.length) { - C++, A.push(O); - } else if (!h) { + if (P = (O = O && O.get(n[L + 1])) && O.length) { + D++, A.push(O); + } else if (!k) { return r ? d : new X(d, this); } } } - if (C) { - z = fb(z, A, r); + if (D) { + z = eb(z, A, r); K = z.length; - if (!K && !h) { + if (!K && !k) { return r ? z : new X(z, this); } - C--; + D--; } } if (K) { - f[u] = D, d.push(z), u++; - } else if (q.length === 1) { + f[u] = C, d.push(z), u++; + } else if (p.length === 1) { return r ? d : new X(d, this); } } if (v) { - if (this.db && m && m.length && !G) { - for (p = 0; p < m.length; p += 2) { - f = this.index.get(m[p]); + if (this.db && n && n.length && !G) { + for (q = 0; q < n.length; q += 2) { + f = this.index.get(n[q]); if (!f) { - if (console.warn("Tag '" + m[p] + ":" + m[p + 1] + "' was not found because there is no field '" + m[p] + "'."), h) { + if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), k) { continue; } else { return r ? d : new X(d, this); } } - v.push(f.db.tag(m[p + 1], c, x, !1)); + v.push(f.db.tag(n[q + 1], c, x, !1)); } } - const E = this; + const B = this; return Promise.all(v).then(function(z) { b && (b.resolve = r); - z.length && (z = E.search(a, c, b, z)); + z.length && (z = B.search(a, c, b, z)); return z; }); } if (!u) { return r ? d : new X(d, this); } - if (g && (!p || !this.store)) { + if (g && (!q || !this.store)) { return d = d[0], r ? d : new X(d, this); } v = []; for (x = 0; x < f.length; x++) { - m = d[x]; - p && m.length && typeof m[0].doc === "undefined" && (this.db ? v.push(m = this.index.get(this.field[0]).db.enrich(m)) : m = Ua.call(this, m)); + n = d[x]; + q && n.length && typeof n[0].doc === "undefined" && (this.db ? v.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = Ta.call(this, n)); if (g) { - return r ? t ? eb(a, m, this.index, g, t) : m : new X(m, this); + return r ? t ? cb(a, n, this.index, g, t) : n : new X(n, this); } - d[x] = {field:f[x], result:m}; + d[x] = {field:f[x], result:n}; } - if (p && this.db && v.length) { - const E = this; + if (q && this.db && v.length) { + const B = this; return Promise.all(v).then(function(z) { - for (let D = 0; D < z.length; D++) { - d[D].result = z[D]; + for (let C = 0; C < z.length; C++) { + d[C].result = z[C]; } - t && (d = eb(a, d, E.index, g, t)); - return k ? hb(d) : d; + t && (d = cb(a, d, B.index, g, t)); + return h ? gb(d) : d; }); } - t && (d = eb(a, d, this.index, g, t)); - return k ? hb(d) : d; + t && (d = cb(a, d, this.index, g, t)); + return h ? gb(d) : d; }; -function hb(a) { +function gb(a) { const c = [], b = I(), e = I(); - for (let d = 0, f, g, k, h, l, n, q; d < a.length; d++) { + for (let d = 0, f, g, h, k, l, m, p; d < a.length; d++) { f = a[d]; g = f.field; - k = f.result; - for (let u = 0; u < k.length; u++) { - if (l = k[u], typeof l !== "object" ? l = {id:h = l} : h = l.id, (n = b[h]) ? n.push(g) : (l.field = b[h] = [g], c.push(l)), q = l.highlight) { - n = e[h], n || (e[h] = n = {}, l.highlight = n), n[g] = q; + h = f.result; + for (let u = 0; u < h.length; u++) { + if (l = h[u], typeof l !== "object" ? l = {id:k = l} : k = l.id, (m = b[k]) ? m.push(g) : (l.field = b[k] = [g], c.push(l)), p = l.highlight) { + m = e[k], m || (e[k] = m = {}, l.highlight = m), m[g] = p; } } } return c; } -function gb(a, c, b, e, d) { +function fb(a, c, b, e, d) { a = this.tag.get(a); if (!a) { return []; @@ -1841,11 +1834,11 @@ function gb(a, c, b, e, d) { if (b && c > b || e) { a = a.slice(e, e + b); } - d && (a = Ua.call(this, a)); + d && (a = Ta.call(this, a)); } return a; } -function Ua(a) { +function Ta(a) { if (!this || !this.store) { return a; } @@ -1858,26 +1851,26 @@ function Ua(a) { } return c; } -;function Qa(a) { - if (!this || this.constructor !== Qa) { - return new Qa(a); +;function Na(a) { + if (!this || this.constructor !== Na) { + return new Na(a); } const c = a.document || a.doc || a; let b, e; this.B = []; this.field = []; this.D = []; - this.key = (b = c.key || c.id) && ib(b, this.D) || "id"; + this.key = (b = c.key || c.id) && hb(b, this.D) || "id"; (e = a.keystore || 0) && (this.keystore = e); this.fastupdate = !!a.fastupdate; this.reg = !this.fastupdate || a.worker || a.db ? e ? new R(e) : new Set() : e ? new Q(e) : new Map(); this.h = (b = c.store || null) && b && b !== !0 && []; this.store = b ? e ? new Q(e) : new Map() : null; - this.cache = (b = a.cache || null) && new oa(b); + this.cache = (b = a.cache || null) && new na(b); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = jb.call(this, a, c); + this.index = ib.call(this, a, c); this.tag = null; if (b = c.tag) { if (typeof b === "string" && (b = [b]), b.length) { @@ -1890,7 +1883,7 @@ function Ua(a) { if (!g) { throw Error("The tag field from the document descriptor is undefined."); } - f.custom ? this.A[d] = f.custom : (this.A[d] = ib(g, this.D), f.filter && (typeof this.A[d] === "string" && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); + f.custom ? this.A[d] = f.custom : (this.A[d] = hb(g, this.D), f.filter && (typeof this.A[d] === "string" && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); this.F[d] = g; this.tag.set(g, new Map()); } @@ -1906,10 +1899,10 @@ function Ua(a) { const d = this; return Promise.all(a).then(function(f) { let g = 0; - for (const k of d.index.entries()) { - const h = k[0]; - let l = k[1]; - l.then && (l = f[g], d.index.set(h, l), g++); + for (const h of d.index.entries()) { + const k = h[0]; + let l = h[1]; + l.then && (l = f[g], d.index.set(k, l), g++); } return d; }); @@ -1918,7 +1911,7 @@ function Ua(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -w = Qa.prototype; +w = Na.prototype; w.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); @@ -1936,12 +1929,12 @@ w.mount = function(a) { } b = []; const e = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let f = 0, g, k; f < c.length; f++) { - e.field = k = c[f]; - g = this.index.get(k); - const h = new a.constructor(a.id, e); - h.id = a.id; - b[f] = h.mount(g); + for (let f = 0, g, h; f < c.length; f++) { + e.field = h = c[f]; + g = this.index.get(h); + const k = new a.constructor(a.id, e); + k.id = a.id; + b[f] = k.mount(g); g.document = !0; f ? g.bypass = !0 : g.store = this.store; } @@ -1950,12 +1943,12 @@ w.mount = function(a) { d.db = !0; }); }; -w.commit = async function(a, c) { - const b = []; - for (const e of this.index.values()) { - b.push(e.commit(a, c)); +w.commit = async function() { + const a = []; + for (const c of this.index.values()) { + a.push(c.commit()); } - await Promise.all(b); + await Promise.all(a); this.reg.clear(); }; w.destroy = function() { @@ -1965,34 +1958,34 @@ w.destroy = function() { } return Promise.all(a); }; -function jb(a, c) { +function ib(a, c) { const b = new Map(); let e = c.index || c.field || c; N(e) && (e = [e]); - for (let f = 0, g, k; f < e.length; f++) { + for (let f = 0, g, h; f < e.length; f++) { g = e[f]; - N(g) || (k = g, g = g.field); - k = ba(k) ? Object.assign({}, a, k) : a; + N(g) || (h = g, g = g.field); + h = ba(h) ? Object.assign({}, a, h) : a; if (this.worker) { var d = void 0; - d = (d = k.encoder) && d.encode ? d : new la(typeof d === "string" ? xa[d] : d || {}); - d = new Ma(k, d); + d = (d = h.encoder) && d.encode ? d : new ka(typeof d === "string" ? wa[d] : d || {}); + d = new La(h, d); b.set(g, d); } - this.worker || b.set(g, new T(k, this.reg)); - k.custom ? this.B[f] = k.custom : (this.B[f] = ib(g, this.D), k.filter && (typeof this.B[f] === "string" && (this.B[f] = new String(this.B[f])), this.B[f].G = k.filter)); + this.worker || b.set(g, new T(h, this.reg)); + h.custom ? this.B[f] = h.custom : (this.B[f] = hb(g, this.D), h.filter && (typeof this.B[f] === "string" && (this.B[f] = new String(this.B[f])), this.B[f].G = h.filter)); this.field[f] = g; } if (this.h) { a = c.store; N(a) && (a = [a]); - for (let f = 0, g, k; f < a.length; f++) { - g = a[f], k = g.field || g, g.custom ? (this.h[f] = g.custom, g.custom.O = k) : (this.h[f] = ib(k, this.D), g.filter && (typeof this.h[f] === "string" && (this.h[f] = new String(this.h[f])), this.h[f].G = g.filter)); + for (let f = 0, g, h; f < a.length; f++) { + g = a[f], h = g.field || g, g.custom ? (this.h[f] = g.custom, g.custom.O = h) : (this.h[f] = hb(h, this.D), g.filter && (typeof this.h[f] === "string" && (this.h[f] = new String(this.h[f])), this.h[f].G = g.filter)); } } return b; } -function ib(a, c) { +function hb(a, c) { const b = a.split(":"); let e = 0; for (let d = 0; d < b.length; d++) { @@ -2008,7 +2001,7 @@ w.update = function(a, c) { return this.remove(a).add(a, c); }; w.remove = function(a) { - ba(a) && (a = da(a, this.key)); + ba(a) && (a = ca(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -2058,15 +2051,15 @@ w.get = function(a) { }) : this.store.get(a) || null; }; w.set = function(a, c) { - typeof a === "object" && (c = a, a = da(c, this.key)); + typeof a === "object" && (c = a, a = ca(c, this.key)); this.store.set(a, c); return this; }; -w.searchCache = na; -w.export = kb; -w.import = lb; -Ga(Qa.prototype); -function mb(a, c = 0) { +w.searchCache = ma; +w.export = jb; +w.import = kb; +Fa(Na.prototype); +function lb(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 5000 | 0); for (const d of a.entries()) { @@ -2075,30 +2068,30 @@ function mb(a, c = 0) { e.length && b.push(e); return b; } -function nb(a, c) { +function mb(a, c) { c || (c = new Map()); for (let b = 0, e; b < a.length; b++) { e = a[b], c.set(e[0], e[1]); } return c; } -function ob(a, c = 0) { +function nb(a, c = 0) { let b = [], e = []; c && (c = 250000 / c * 1000 | 0); for (const d of a.entries()) { - e.push([d[0], mb(d[1])[0]]), e.length === c && (b.push(e), e = []); + e.push([d[0], lb(d[1])[0]]), e.length === c && (b.push(e), e = []); } e.length && b.push(e); return b; } -function pb(a, c) { +function ob(a, c) { c || (c = new Map()); for (let b = 0, e, d; b < a.length; b++) { - e = a[b], d = c.get(e[0]), c.set(e[0], nb(e[1], d)); + e = a[b], d = c.get(e[0]), c.set(e[0], mb(e[1], d)); } return c; } -function qb(a) { +function pb(a) { let c = [], b = []; for (const e of a.keys()) { b.push(e), b.length === 250000 && (c.push(b), b = []); @@ -2106,34 +2099,34 @@ function qb(a) { b.length && c.push(b); return c; } -function rb(a, c) { +function qb(a, c) { c || (c = new Set()); for (let b = 0; b < a.length; b++) { c.add(a[b]); } return c; } -function sb(a, c, b, e, d, f, g = 0) { - const k = e && e.constructor === Array; - var h = k ? e.shift() : e; - if (!h) { +function rb(a, c, b, e, d, f, g = 0) { + const h = e && e.constructor === Array; + var k = h ? e.shift() : e; + if (!k) { return this.export(a, c, d, f + 1); } - if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { + if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { const l = this; - return h.then(function() { - return sb.call(l, a, c, b, k ? e : null, d, f, g + 1); + return k.then(function() { + return rb.call(l, a, c, b, h ? e : null, d, f, g + 1); }); } - return sb.call(this, a, c, b, k ? e : null, d, f, g + 1); + return rb.call(this, a, c, b, h ? e : null, d, f, g + 1); } -function kb(a, c, b = 0, e = 0) { +function jb(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const k = this; + const h = this; return c.then(function() { - return k.export(a, g, b + 1); + return h.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -2142,25 +2135,25 @@ function kb(a, c, b = 0, e = 0) { switch(e) { case 0: d = "reg"; - f = qb(this.reg); + f = pb(this.reg); c = null; break; case 1: d = "tag"; - f = this.tag && ob(this.tag, this.reg.size); + f = this.tag && nb(this.tag, this.reg.size); c = null; break; case 2: d = "doc"; - f = this.store && mb(this.store); + f = this.store && lb(this.store); c = null; break; default: return; } - return sb.call(this, a, c, d, f || null, b, e); + return rb.call(this, a, c, d, f || null, b, e); } -function lb(a, c) { +function kb(a, c) { var b = a.split("."); b[b.length - 1] === "json" && b.pop(); const e = b.length > 2 ? b[0] : ""; @@ -2176,7 +2169,7 @@ function lb(a, c) { switch(b) { case "reg": this.fastupdate = !1; - this.reg = rb(c, this.reg); + this.reg = qb(c, this.reg); for (let d = 0, f; d < this.field.length; d++) { f = this.index.get(this.field[d]), f.fastupdate = !1, f.reg = this.reg; } @@ -2189,27 +2182,27 @@ function lb(a, c) { } break; case "tag": - this.tag = pb(c, this.tag); + this.tag = ob(c, this.tag); break; case "doc": - this.store = nb(c, this.store); + this.store = mb(c, this.store); } } } -function tb(a, c) { +function sb(a, c) { let b = ""; for (const e of a.entries()) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, k; g < d.length; g++) { - k = d[g] || [""]; - let h = ""; - for (let l = 0; l < k.length; l++) { - h += (h ? "," : "") + (c === "string" ? '"' + k[l] + '"' : k[l]); + for (let g = 0, h; g < d.length; g++) { + h = d[g] || [""]; + let k = ""; + for (let l = 0; l < h.length; l++) { + k += (k ? "," : "") + (c === "string" ? '"' + h[l] + '"' : h[l]); } - h = "[" + h + "]"; - f += (f ? "," : "") + h; + k = "[" + k + "]"; + f += (f ? "," : "") + k; } f = '["' + a + '",[' + f + "]]"; b += (b ? "," : "") + f; @@ -2231,19 +2224,19 @@ function tb(a, c) { } } } else { - ub(this.map, a), this.depth && ub(this.ctx, a); + tb(this.map, a), this.depth && tb(this.ctx, a); } c || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.M && vb(this)); + this.db && (this.commit_task.push({del:a}), this.M && ub(this)); this.cache && this.cache.remove(a); return this; }; -function ub(a, c) { +function tb(a, c) { let b = 0; var e = typeof c === "undefined"; if (a.constructor === Array) { - for (let d = 0, f, g, k; d < a.length; d++) { + for (let d = 0, f, g, h; d < a.length; d++) { if ((f = a[d]) && f.length) { if (e) { return 1; @@ -2257,9 +2250,9 @@ function ub(a, c) { if (b) { return 1; } - k = 1; + h = 1; } else { - if (k) { + if (h) { return 1; } b++; @@ -2268,12 +2261,12 @@ function ub(a, c) { } } else { for (let d of a.entries()) { - e = d[0], ub(d[1], c) ? b++ : a.delete(e); + e = d[0], tb(d[1], c) ? b++ : a.delete(e); } } return b; } -;const wb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +;const vb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; T.prototype.add = function(a, c, b, e) { if (c && (a || a === 0)) { if (!e && !b && this.reg.has(a)) { @@ -2283,30 +2276,30 @@ T.prototype.add = function(a, c, b, e) { c = this.encoder.encode(c, !e); const l = c.length; if (l) { - const n = I(), q = I(), u = this.resolution; + const m = I(), p = I(), u = this.resolution; for (let r = 0; r < l; r++) { let t = c[this.rtl ? l - 1 - r : r]; var d = t.length; - if (d && (e || !q[t])) { - var f = this.score ? this.score(c, t, r, null, 0) : xb(u, l, r), g = ""; + if (d && (e || !p[t])) { + var f = this.score ? this.score(c, t, r, null, 0) : wb(u, l, r), g = ""; switch(this.tokenize) { case "tolerant": - Y(this, q, t, f, a, b); + Y(this, p, t, f, a, b); if (d > 2) { - for (let m = 1, p, x, v, A; m < d - 1; m++) { - p = t.charAt(m), x = t.charAt(m + 1), v = t.substring(0, m) + x, A = t.substring(m + 2), g = v + p + A, q[g] || Y(this, q, g, f, a, b), g = v + A, q[g] || Y(this, q, g, f, a, b); + for (let n = 1, q, x, v, A; n < d - 1; n++) { + q = t.charAt(n), x = t.charAt(n + 1), v = t.substring(0, n) + x, A = t.substring(n + 2), g = v + q + A, Y(this, p, g, f, a, b), g = v + A, Y(this, p, g, f, a, b); } + Y(this, p, t.substring(0, t.length - 1), f, a, b); } break; case "full": if (d > 2) { - for (let m = 0, p; m < d; m++) { - for (f = d; f > m; f--) { - if (g = t.substring(m, f), !q[g]) { - p = this.rtl ? d - 1 - m : m; - var k = this.score ? this.score(c, t, r, g, p) : xb(u, l, r, d, p); - Y(this, q, g, k, a, b); - } + for (let n = 0, q; n < d; n++) { + for (f = d; f > n; f--) { + g = t.substring(n, f); + q = this.rtl ? d - 1 - n : n; + var h = this.score ? this.score(c, t, r, g, q) : wb(u, l, r, d, q); + Y(this, p, g, h, a, b); } } break; @@ -2314,61 +2307,70 @@ T.prototype.add = function(a, c, b, e) { case "bidirectional": case "reverse": if (d > 1) { - for (k = d - 1; k > 0; k--) { - if (g = t[this.rtl ? d - 1 - k : k] + g, !q[g]) { - var h = this.score ? this.score(c, t, r, g, k) : xb(u, l, r, d, k); - Y(this, q, g, h, a, b); - } + for (h = d - 1; h > 0; h--) { + g = t[this.rtl ? d - 1 - h : h] + g; + var k = this.score ? this.score(c, t, r, g, h) : wb(u, l, r, d, h); + Y(this, p, g, k, a, b); } g = ""; } case "forward": if (d > 1) { - for (k = 0; k < d; k++) { - g += t[this.rtl ? d - 1 - k : k], q[g] || Y(this, q, g, f, a, b); + for (h = 0; h < d; h++) { + g += t[this.rtl ? d - 1 - h : h], Y(this, p, g, f, a, b); } break; } default: - if (Y(this, q, t, f, a, b), e && l > 1 && r < l - 1) { - for (d = I(), g = this.N, f = t, k = Math.min(e + 1, this.rtl ? r + 1 : l - r), d[f] = 1, h = 1; h < k; h++) { - if ((t = c[this.rtl ? l - 1 - r - h : r + h]) && !d[t]) { - d[t] = 1; - const m = this.score ? this.score(c, f, r, t, h - 1) : xb(g + (l / 2 > g ? 0 : 1), l, r, k - 1, h - 1), p = this.bidirectional && t > f; - Y(this, n, p ? f : t, m, a, b, p ? t : f); - } + if (Y(this, p, t, f, a, b), e && l > 1 && r < l - 1) { + for (d = this.N, g = t, f = Math.min(e + 1, this.rtl ? r + 1 : l - r), h = 1; h < f; h++) { + t = c[this.rtl ? l - 1 - r - h : r + h]; + k = this.bidirectional && t > g; + const n = this.score ? this.score(c, g, r, t, h - 1) : wb(d + (l / 2 > d ? 0 : 1), l, r, f - 1, h - 1); + Y(this, m, k ? g : t, n, a, b, k ? t : g); } } } } } this.fastupdate || this.reg.add(a); - } else { - c = ""; } } - this.db && (c || this.commit_task.push({del:a}), this.M && vb(this)); + this.db && (this.commit_task.push(b ? {ins:a} : {del:a}), this.M && ub(this)); return this; }; function Y(a, c, b, e, d, f, g) { - let k = g ? a.ctx : a.map, h; - if (!c[b] || g && !(h = c[b])[g]) { - if (g ? (c = h || (c[b] = I()), c[g] = 1, (h = k.get(g)) ? k = h : k.set(g, k = new Map())) : c[b] = 1, (h = k.get(b)) ? k = h : k.set(b, k = h = []), k = k[e] || (k[e] = []), !f || !k.includes(d)) { - if (k.length === 2 ** 31 - 1) { - c = new Ba(k); - if (a.fastupdate) { - for (let l of a.reg.values()) { - l.includes(k) && (l[l.indexOf(k)] = c); + let h, k; + if (!(h = c[b]) || g && !h[g]) { + g ? (c = h || (c[b] = I()), c[g] = 1, k = a.ctx, (h = k.get(g)) ? k = h : k.set(g, k = a.keystore ? new Q(a.keystore) : new Map())) : (k = a.map, c[b] = 1); + (h = k.get(b)) ? k = h : k.set(b, k = h = []); + if (f) { + for (let l = 0, m; l < h.length; l++) { + if ((m = h[l]) && m.includes(d)) { + if (l <= e) { + return; } + m.splice(m.indexOf(d), 1); + a.fastupdate && (c = a.reg.get(d)) && c.splice(c.indexOf(m), 1); + break; } - h[e] = k = c; } - k.push(d); - a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } + k = k[e] || (k[e] = []); + k.push(d); + if (k.length === 2 ** 31 - 1) { + c = new Aa(k); + if (a.fastupdate) { + for (let l of a.reg.values()) { + l.includes(k) && (l[l.indexOf(k)] = c); + } + } + h[e] = k = c; + } + a.fastupdate && ((e = a.reg.get(d)) ? e.push(k) : a.reg.set(d, [k])); } } -function xb(a, c, b, e, d) { +function wb(a, c, b, e, d) { return b && a > 1 ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } ;T.prototype.search = function(a, c, b) { @@ -2376,73 +2378,73 @@ function xb(a, c, b, e, d) { if (b && b.cache) { return b.cache = !1, a = this.searchCache(a, c, b), b.cache = !0, a; } - let e = [], d, f, g, k = 0, h, l, n, q, u; - b && (a = b.query || a, c = b.limit || c, k = b.offset || 0, f = b.context, g = b.suggest, u = (h = b.resolve) && b.enrich, n = b.boost, q = b.resolution, l = this.db && b.tag); - typeof h === "undefined" && (h = this.resolve); + let e = [], d, f, g, h = 0, k, l, m, p, u; + b && (a = b.query || a, c = b.limit || c, h = b.offset || 0, f = b.context, g = b.suggest, u = (k = b.resolve) && b.enrich, m = b.boost, p = b.resolution, l = this.db && b.tag); + typeof k === "undefined" && (k = this.resolve); f = this.depth && f !== !1; let r = this.encoder.encode(a, !f); d = r.length; - c = c || (h ? 100 : 0); + c = c || (k ? 100 : 0); if (d === 1) { - return yb.call(this, r[0], "", c, k, h, u, l); + return xb.call(this, r[0], "", c, h, k, u, l); } if (d === 2 && f && !g) { - return yb.call(this, r[1], r[0], c, k, h, u, l); + return xb.call(this, r[1], r[0], c, h, k, u, l); } - let t = I(), m = 0, p; - f && (p = r[0], m = 1); - q || q === 0 || (q = p ? this.N : this.resolution); + let t = I(), n = 0, q; + f && (q = r[0], n = 1); + p || p === 0 || (p = q ? this.N : this.resolution); if (this.db) { - if (this.db.search && (b = this.db.search(this, r, c, k, g, h, u, l), b !== !1)) { + if (this.db.search && (b = this.db.search(this, r, c, h, g, k, u, l), b !== !1)) { return b; } const x = this; return async function() { - for (let v, A; m < d; m++) { - if ((A = r[m]) && !t[A]) { + for (let v, A; n < d; n++) { + if ((A = r[n]) && !t[A]) { t[A] = 1; - v = await zb(x, A, p, 0, 0, !1, !1); - if (v = Ab(v, e, g, q)) { + v = await yb(x, A, q, 0, 0, !1, !1); + if (v = zb(v, e, g, p)) { e = v; break; } - p && (g && v && e.length || (p = A)); + q && (g && v && e.length || (q = A)); } - g && p && m === d - 1 && !e.length && (q = x.resolution, p = "", m = -1, t = I()); + g && q && n === d - 1 && !e.length && (p = x.resolution, q = "", n = -1, t = I()); } - return Bb(e, q, c, k, g, n, h); + return Ab(e, p, c, h, g, m, k); }(); } - for (let x, v; m < d; m++) { - if ((v = r[m]) && !t[v]) { + for (let x, v; n < d; n++) { + if ((v = r[n]) && !t[v]) { t[v] = 1; - x = zb(this, v, p, 0, 0, !1, !1); - if (x = Ab(x, e, g, q)) { + x = yb(this, v, q, 0, 0, !1, !1); + if (x = zb(x, e, g, p)) { e = x; break; } - p && (g && x && e.length || (p = v)); + q && (g && x && e.length || (q = v)); } - g && p && m === d - 1 && !e.length && (q = this.resolution, p = "", m = -1, t = I()); + g && q && n === d - 1 && !e.length && (p = this.resolution, q = "", n = -1, t = I()); } - return Bb(e, q, c, k, g, n, h); + return Ab(e, p, c, h, g, m, k); }; -function Bb(a, c, b, e, d, f, g) { - let k = a.length, h = a; - if (k > 1) { - h = ab(a, c, b, e, d, f, g); - } else if (k === 1) { - return g ? Ta.call(null, a[0], b, e) : new X(a[0], this); +function Ab(a, c, b, e, d, f, g) { + let h = a.length, k = a; + if (h > 1) { + k = $a(a, c, b, e, d, f, g); + } else if (h === 1) { + return g ? Sa.call(null, a[0], b, e) : new X(a[0], this); } - return g ? h : new X(h, this); + return g ? k : new X(k, this); } -function yb(a, c, b, e, d, f, g) { - a = zb(this, a, c, b, e, d, f, g); - return this.db ? a.then(function(k) { - return d ? k || [] : new X(k, this); - }) : a && a.length ? d ? Ta.call(this, a, b, e) : new X(a, this) : d ? [] : new X([], this); +function xb(a, c, b, e, d, f, g) { + a = yb(this, a, c, b, e, d, f, g); + return this.db ? a.then(function(h) { + return d ? h || [] : new X(h, this); + }) : a && a.length ? d ? Sa.call(this, a, b, e) : new X(a, this) : d ? [] : new X([], this); } -function Ab(a, c, b, e) { +function zb(a, c, b, e) { let d = []; if (a && a.length) { if (a.length <= e) { @@ -2463,11 +2465,11 @@ function Ab(a, c, b, e) { return d; } } -function zb(a, c, b, e, d, f, g, k) { - let h; - b && (h = a.bidirectional && c > b) && (h = b, b = c, c = h); +function yb(a, c, b, e, d, f, g, h) { + let k; + b && (k = a.bidirectional && c > b) && (k = b, b = c, c = k); if (a.db) { - return a.db.get(c, b, e, d, f, g, k); + return a.db.get(c, b, e, d, f, g, h); } a = b ? (a = a.ctx.get(b)) && a.get(c) : a.map.get(c); return a; @@ -2478,13 +2480,13 @@ function zb(a, c, b, e, d, f, g, k) { } if (a) { var b = N(a) ? a : a.preset; - b && (wb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, wb[b], a)); + b && (vb[b] || console.warn("Preset not found: " + b), a = Object.assign({}, vb[b], a)); } else { a = {}; } b = a.context; - const e = b === !0 ? {depth:1} : b || {}, d = N(a.encoder) ? xa[a.encoder] : a.encode || a.encoder || {}; - this.encoder = d.encode ? d : typeof d === "object" ? new la(d) : {encode:d}; + const e = b === !0 ? {depth:1} : b || {}, d = N(a.encoder) ? wa[a.encoder] : a.encode || a.encoder || {}; + this.encoder = d.encode ? d : typeof d === "object" ? new ka(d) : {encode:d}; this.resolution = a.resolution || 9; this.tokenize = b = (b = a.tokenize) && b !== "default" && b !== "exact" && b || "strict"; this.depth = b === "strict" && e.depth || 0; @@ -2498,7 +2500,7 @@ function zb(a, c, b, e, d, f, g, k) { this.reg = c || (this.fastupdate ? b ? new Q(b) : new Map() : b ? new R(b) : new Set()); this.N = e.resolution || 3; this.rtl = d.rtl || a.rtl || !1; - this.cache = (b = a.cache || null) && new oa(b); + this.cache = (b = a.cache || null) && new na(b); this.resolve = a.resolve !== !1; if (b = a.db) { this.db = this.mount(b); @@ -2513,18 +2515,18 @@ w.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -w.commit = function(a, c) { +w.commit = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, c); + return this.db.commit(this); }; w.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function vb(a) { +function ub(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; - a.db.commit(a, void 0, void 0); + a.db.commit(a); }, 1)); } w.clear = function() { @@ -2548,17 +2550,17 @@ w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - ub(this.map); - this.depth && ub(this.ctx); + tb(this.map); + this.depth && tb(this.ctx); return this; }; -w.searchCache = na; +w.searchCache = ma; w.export = function(a, c, b = 0, e = 0) { let d, f; switch(e) { case 0: d = "reg"; - f = qb(this.reg); + f = pb(this.reg); break; case 1: d = "cfg"; @@ -2566,29 +2568,29 @@ w.export = function(a, c, b = 0, e = 0) { break; case 2: d = "map"; - f = mb(this.map, this.reg.size); + f = lb(this.map, this.reg.size); break; case 3: d = "ctx"; - f = ob(this.ctx, this.reg.size); + f = nb(this.ctx, this.reg.size); break; default: return; } - return sb.call(this, a, c, d, f, b, e); + return rb.call(this, a, c, d, f, b, e); }; w.import = function(a, c) { if (c) { switch(typeof c === "string" && (c = JSON.parse(c)), a = a.split("."), a[a.length - 1] === "json" && a.pop(), a.length === 3 && a.shift(), a = a.length > 1 ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = rb(c, this.reg); + this.reg = qb(c, this.reg); break; case "map": - this.map = nb(c, this.map); + this.map = mb(c, this.map); break; case "ctx": - this.ctx = pb(c, this.ctx); + this.ctx = ob(c, this.ctx); } } }; @@ -2600,24 +2602,24 @@ w.serialize = function(a = !0) { f || (f = typeof d), c += (c ? "," : "") + (f === "string" ? '"' + d + '"' : d); } c = "index.reg=new Set([" + c + "]);"; - b = tb(this.map, f); + b = sb(this.map, f); b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let k = tb(g[1], f); - k = "new Map([" + k + "])"; - k = '["' + d + '",' + k + "]"; - e += (e ? "," : "") + k; + let h = sb(g[1], f); + h = "new Map([" + h + "])"; + h = '["' + d + '",' + h + "]"; + e += (e ? "," : "") + h; } e = "index.ctx=new Map([" + e + "]);"; } return a ? "function inject(index){" + c + b + e + "}" : c + b + e; }; -Ga(T.prototype); -const Cb = typeof window !== "undefined" && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Db = ["map", "ctx", "tag", "reg", "cfg"], Eb = I(); -function Fb(a, c = {}) { - if (!this || this.constructor !== Fb) { - return new Fb(a, c); +Fa(T.prototype); +const Bb = typeof window !== "undefined" && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Cb = ["map", "ctx", "tag", "reg", "cfg"], Db = I(); +function Eb(a, c = {}) { + if (!this || this.constructor !== Eb) { + return new Eb(a, c); } typeof a === "object" && (c = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2628,7 +2630,7 @@ function Fb(a, c = {}) { this.db = null; this.h = {}; } -w = Fb.prototype; +w = Eb.prototype; w.mount = function(a) { if (a.index) { return a.mount(this); @@ -2642,15 +2644,15 @@ w.open = function() { } let a = this; navigator.storage && navigator.storage.persist(); - Eb[a.id] || (Eb[a.id] = []); - Eb[a.id].push(a.field); - const c = Cb.open(a.id, 1); + Db[a.id] || (Db[a.id] = []); + Db[a.id].push(a.field); + const c = Bb.open(a.id, 1); c.onupgradeneeded = function() { const b = a.db = this.result; - for (let e = 0, d; e < Db.length; e++) { - d = Db[e]; - for (let f = 0, g; f < Eb[a.id].length; f++) { - g = Eb[a.id][f], b.objectStoreNames.contains(d + (d !== "reg" ? g ? ":" + g : "" : "")) || b.createObjectStore(d + (d !== "reg" ? g ? ":" + g : "" : "")); + for (let e = 0, d; e < Cb.length; e++) { + d = Cb[e]; + for (let f = 0, g; f < Db[a.id].length; f++) { + g = Db[a.id][f], b.objectStoreNames.contains(d + (d !== "reg" ? g ? ":" + g : "" : "")) || b.createObjectStore(d + (d !== "reg" ? g ? ":" + g : "" : "")); } } }; @@ -2666,15 +2668,15 @@ w.close = function() { this.db = null; }; w.destroy = function() { - const a = Cb.deleteDatabase(this.id); + const a = Bb.deleteDatabase(this.id); return Z(a); }; w.clear = function() { const a = []; - for (let b = 0, e; b < Db.length; b++) { - e = Db[b]; - for (let d = 0, f; d < Eb[this.id].length; d++) { - f = Eb[this.id][d], a.push(e + (e !== "reg" ? f ? ":" + f : "" : "")); + for (let b = 0, e; b < Cb.length; b++) { + e = Cb[b]; + for (let d = 0, f; d < Db[this.id].length; d++) { + f = Db[this.id][d], a.push(e + (e !== "reg" ? f ? ":" + f : "" : "")); } } const c = this.db.transaction(a, "readwrite"); @@ -2686,34 +2688,34 @@ w.clear = function() { w.get = function(a, c, b = 0, e = 0, d = !0, f = !1) { a = this.db.transaction((c ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((c ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(c ? c + ":" + a : a); const g = this; - return Z(a).then(function(k) { - let h = []; - if (!k || !k.length) { - return h; + return Z(a).then(function(h) { + let k = []; + if (!h || !h.length) { + return k; } if (d) { - if (!b && !e && k.length === 1) { - return k[0]; + if (!b && !e && h.length === 1) { + return h[0]; } - for (let l = 0, n; l < k.length; l++) { - if ((n = k[l]) && n.length) { - if (e >= n.length) { - e -= n.length; + for (let l = 0, m; l < h.length; l++) { + if ((m = h[l]) && m.length) { + if (e >= m.length) { + e -= m.length; continue; } - const q = b ? e + Math.min(n.length - e, b) : n.length; - for (let u = e; u < q; u++) { - h.push(n[u]); + const p = b ? e + Math.min(m.length - e, b) : m.length; + for (let u = e; u < p; u++) { + k.push(m[u]); } e = 0; - if (h.length === b) { + if (k.length === b) { break; } } } - return f ? g.enrich(h) : h; + return f ? g.enrich(k) : k; } - return k; + return h; }); }; w.tag = function(a, c = 0, b = 0, e = !1) { @@ -2767,75 +2769,65 @@ w.transaction = function(a, c, b) { return f; }); }; -w.commit = async function(a, c, b) { - if (c) { - await this.clear(), a.commit_task = []; - } else { - let e = a.commit_task; - a.commit_task = []; - for (let d = 0, f; d < e.length; d++) { - if (f = e[d], f.clear) { - await this.clear(); - c = !0; - break; - } else { - e[d] = f.del; - } - } - c || (b || (e = e.concat(ca(a.reg))), e.length && await this.remove(e)); +w.commit = async function(a) { + let c = a.commit_task, b = []; + a.commit_task = []; + for (let e = 0, d; e < c.length; e++) { + d = c[e], d.del && b.push(d.del); } + b.length && await this.remove(b); a.reg.size && (await this.transaction("map", "readwrite", function(e) { for (const d of a.map) { const f = d[0], g = d[1]; - g.length && (c ? e.put(g, f) : e.get(f).onsuccess = function() { - let k = this.result; - var h; - if (k && k.length) { - const l = Math.max(k.length, g.length); - for (let n = 0, q, u; n < l; n++) { - if ((u = g[n]) && u.length) { - if ((q = k[n]) && q.length) { - for (h = 0; h < u.length; h++) { - q.push(u[h]); + g.length && (e.get(f).onsuccess = function() { + let h = this.result; + var k; + if (h && h.length) { + const l = Math.max(h.length, g.length); + for (let m = 0, p, u; m < l; m++) { + if ((u = g[m]) && u.length) { + if ((p = h[m]) && p.length) { + for (k = 0; k < u.length; k++) { + p.push(u[k]); } } else { - k[n] = u; + h[m] = u; } - h = 1; + k = 1; } } } else { - k = g, h = 1; + h = g, k = 1; } - h && e.put(k, f); + k && e.put(h, f); }); } }), await this.transaction("ctx", "readwrite", function(e) { for (const d of a.ctx) { const f = d[0], g = d[1]; - for (const k of g) { - const h = k[0], l = k[1]; - l.length && (c ? e.put(l, f + ":" + h) : e.get(f + ":" + h).onsuccess = function() { - let n = this.result; - var q; - if (n && n.length) { - const u = Math.max(n.length, l.length); - for (let r = 0, t, m; r < u; r++) { - if ((m = l[r]) && m.length) { - if ((t = n[r]) && t.length) { - for (q = 0; q < m.length; q++) { - t.push(m[q]); + for (const h of g) { + const k = h[0], l = h[1]; + l.length && (e.get(f + ":" + k).onsuccess = function() { + let m = this.result; + var p; + if (m && m.length) { + const u = Math.max(m.length, l.length); + for (let r = 0, t, n; r < u; r++) { + if ((n = l[r]) && n.length) { + if ((t = m[r]) && t.length) { + for (p = 0; p < n.length; p++) { + t.push(n[p]); } } else { - n[r] = m; + m[r] = n; } - q = 1; + p = 1; } } } else { - n = l, q = 1; + m = l, p = 1; } - q && e.put(n, f + ":" + h); + p && e.put(m, f + ":" + k); }); } } @@ -2852,29 +2844,29 @@ w.commit = async function(a, c, b) { for (const d of a.tag) { const f = d[0], g = d[1]; g.length && (e.get(f).onsuccess = function() { - let k = this.result; - k = k && k.length ? k.concat(g) : g; - e.put(k, f); + let h = this.result; + h = h && h.length ? h.concat(g) : g; + e.put(h, f); }); } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function Gb(a, c, b) { +function Fb(a, c, b) { const e = a.value; let d, f = 0; - for (let g = 0, k; g < e.length; g++) { - if (k = b ? e : e[g]) { - for (let h = 0, l, n; h < c.length; h++) { - if (n = c[h], l = k.indexOf(n), l >= 0) { - if (d = 1, k.length > 1) { - k.splice(l, 1); + for (let g = 0, h; g < e.length; g++) { + if (h = b ? e : e[g]) { + for (let k = 0, l, m; k < c.length; k++) { + if (m = c[k], l = h.indexOf(m), l >= 0) { + if (d = 1, h.length > 1) { + h.splice(l, 1); } else { e[g] = []; break; } } } - f += k.length; + f += h.length; } if (b) { break; @@ -2888,17 +2880,17 @@ w.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && Gb(b, a); + b && Fb(b, a); }; }), this.transaction("ctx", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && Gb(b, a); + b && Fb(b, a); }; }), this.transaction("tag", "readwrite", function(c) { c.openCursor().onsuccess = function() { const b = this.result; - b && Gb(b, a, !0); + b && Fb(b, a, !0); }; }), this.transaction("reg", "readwrite", function(c) { for (let b = 0; b < a.length; b++) { @@ -2917,6 +2909,6 @@ function Z(a, c) { a = null; }); } -;export default {Index:T, Charset:xa, Encoder:la, Document:Qa, Worker:Ma, Resolver:X, IndexedDB:Fb, Language:{}}; +;export default {Index:T, Charset:wa, Encoder:ka, Document:Na, Worker:La, Resolver:X, IndexedDB:Eb, Language:{}}; -export const Index=T;export const Charset=xa;export const Encoder=la;export const Document=Qa;export const Worker=Ma;export const Resolver=X;export const IndexedDB=Fb;export const Language={}; \ No newline at end of file +export const Index=T;export const Charset=wa;export const Encoder=ka;export const Document=Na;export const Worker=La;export const Resolver=X;export const IndexedDB=Eb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 99712ba..cc03144 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -1,108 +1,108 @@ /**! - * FlexSearch.js v0.8.203 (Bundle/Module) + * FlexSearch.js v0.8.205 (Bundle/Module) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var w;function H(a,b,c){const e=typeof c,d=typeof a;if(e!=="undefined"){if(d!=="undefined"){if(c){if(d==="function"&&e===d)return function(h){return a(c(h))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){var f=new Map(c);for(var g of a)f.set(g[0],g[1]);return f}if(b===Set){g=new Set(c);for(f of a.values())g.add(f);return g}}}return a}return c}return d==="undefined"?b:a}function aa(a,b){return typeof a==="undefined"?b:a}function I(){return Object.create(null)} -function M(a){return typeof a==="string"}function ba(a){return typeof a==="object"}function ca(a){const b=[];for(const c of a.keys())b.push(c);return b}function ea(a,b){if(M(b))a=a[b];else for(let c=0;a&&c1)return this.addMatcher(a,b);this.mapper||(this.mapper=new Map);this.mapper.set(a,b);this.cache&&Q(this);return this};w.addMatcher=function(a,b){if(typeof a==="object")return this.addReplacer(a,b);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.J=null;this.cache&&Q(this);return this}; -w.addReplacer=function(a,b){if(typeof a==="string")return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&Q(this);return this}; -w.encode=function(a,b){if(this.cache&&a.length<=this.H)if(this.F){if(this.B.has(a))return this.B.get(a)}else this.F=setTimeout(Q,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=ka?a.normalize("NFKD").replace(ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(ia,"$1 $2").replace(ja,"$1 $2").replace(ha,"$1 "));const c=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let e= -[],d=I(),f,g,h=this.split||this.split===""?a.split(this.split):[a];for(let l=0,m,n;lthis.maxlength)){if(b){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(c)e.push(m);else if(!this.filter||(typeof this.filter==="function"?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.I)if(this.F){var k=this.D.get(m);if(k||k===""){k&&e.push(k);continue}}else this.F=setTimeout(Q,50,this);if(this.stemmer){this.K||(this.K=new RegExp("(?!^)("+ -this.A+")$"));let u;for(;u!==m&&m.length>2;)u=m,m=m.replace(this.K,r=>this.stemmer.get(r))}if(m&&(this.mapper||this.dedupe&&m.length>1)){k="";for(let u=0,r="",t,p;u1&&(this.J||(this.J=new RegExp("("+this.h+")","g")),m=m.replace(this.J,u=>this.matcher.get(u)));if(m&&this.replacer)for(k=0;m&&kthis.L&&(this.D.clear(),this.I=this.I/1.1|0));if(m){if(m!==n)if(b){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.H&&(this.B.set(a,e),this.B.size>this.L&&(this.B.clear(),this.H=this.H/1.1|0));return e};function Q(a){a.F=null;a.B.clear();a.D.clear()};function ma(a,b,c){c||(b||typeof a!=="object"?typeof b==="object"&&(c=b,b=0):c=a);c&&(a=c.query||a,b=c.limit||b);let e=""+(b||0);c&&(e+=(c.offset||0)+!!c.context+!!c.suggest+(c.resolve!==!1)+(c.resolution||this.resolution)+(c.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new na);let d=this.cache.get(a+e);if(!d){const f=c&&c.cache;f&&(c.cache=!1);d=this.search(a,b,c);f&&(c.cache=f);this.cache.set(a+e,d)}return d}function na(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""} -na.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};na.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};na.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};na.prototype.clear=function(){this.cache.clear();this.h=""};const oa={normalize:!1,numeric:!1,dedupe:!1};const ra={};const sa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const ta=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ua=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const va={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var wa={Exact:oa,Default:ra,Normalize:ra,LatinBalance:{mapper:sa},LatinAdvanced:{mapper:sa,matcher:ta,replacer:ua},LatinExtra:{mapper:sa,replacer:ua.concat([/(?!^)[aeo]/g,""]),matcher:ta},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[e?"splice":"slice"](b,c);const h=b.length;if(h&&(d=d.length?d.concat(b):b,c-=h,e&&(a.length-=h),!c))break;b=0}return d} -function Aa(a){if(!this||this.constructor!==Aa)return new Aa(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,e){if(e==="length")return b.length;if(e==="push")return function(d){b.index[b.index.length-1].push(d);b.length++};if(e==="pop")return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if(e==="indexOf")return function(d){let f=0;for(let g=0,h,k;g=0)return f+k;f+=h.length}return-1}; -if(e==="includes")return function(d){for(let f=0;f32?(this.B=Ba,this.A=BigInt(a)):(this.B=Ca,this.A=a)}R.prototype.get=function(a){const b=this.index[this.B(a)];return b&&b.get(a)};R.prototype.set=function(a,b){var c=this.B(a);let e=this.index[c];e?(c=e.size,e.set(a,b),(c-=e.size)&&this.size++):(this.index[c]=e=new Map([[a,b]]),this.h.push(e),this.size++)}; -function S(a=8){if(!this||this.constructor!==S)return new S(a);this.index=I();this.h=[];this.size=0;a>32?(this.B=Ba,this.A=BigInt(a)):(this.B=Ca,this.A=a)}S.prototype.add=function(a){var b=this.B(a);let c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.h.push(c),this.size++)};w=R.prototype;w.has=S.prototype.has=function(a){const b=this.index[this.B(a)];return b&&b.has(a)}; -w.delete=S.prototype.delete=function(a){const b=this.index[this.B(a)];b&&b.delete(a)&&this.size--};w.clear=S.prototype.clear=function(){this.index=I();this.h=[];this.size=0};w.values=S.prototype.values=function*(){for(let a=0;a=this.priority*this.priority*3):(Ia=setTimeout(La,0),Ja=Date.now());if(Ka){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,b))},0)})}const d=this[a].apply(this,b);c=d.then?d:new Promise(f=>f(d));e&&c.then(e);return c}};let V=0; -function Ma(a={},b){function c(h){function k(l){l=l.data||l;const m=l.id,n=m&&f.h[m];n&&(n(l.msg),delete f.h[m])}this.worker=h;this.h=I();if(this.worker){d?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(l){V>1E9&&(V=0);f.h[++V]=function(){l(f)};f.worker.postMessage({id:V,task:"init",factory:e,options:a})});this.priority=a.priority||4;this.encoder=b||null;this.worker.postMessage({task:"init",factory:e,options:a});return this}}if(!this||this.constructor!==Ma)return new Ma(a); -let e=typeof self!=="undefined"?self._factory:typeof window!=="undefined"?window._factory:null;e&&(e=e.toString());const d=typeof window==="undefined",f=this,g=Na(e,d,a.worker);return g.then?g.then(function(h){return c.call(f,h)}):c.call(this,g)}W("add");W("append");W("search");W("update");W("remove");W("clear");W("export");W("import");Ma.prototype.searchCache=ma;Ga(Ma.prototype); -function W(a){Ma.prototype[a]=function(){const b=this,c=[].slice.call(arguments);var e=c[c.length-1];let d;typeof e==="function"&&(d=e,c.pop());e=new Promise(function(f){a==="export"&&typeof c[0]==="function"&&(c[0]=null);V>1E9&&(V=0);b.h[++V]=f;b.worker.postMessage({task:a,id:V,args:c})});return d?(e.then(d),this):e}} -function Na(a,b,c){return b?typeof module!=="undefined"?new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js"):import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Fa.toString()],{type:"text/javascript"}))):new window.Worker(typeof c==="string"?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};Qa.prototype.add=function(a,b,c){ba(a)&&(b=a,a=ea(b,this.key));if(b&&(a||a===0)){if(!c&&this.reg.has(a))return this.update(a,b);for(let h=0,k;hb?a.slice(c,c+b):a,e?Ua.call(this,a):a;let d=[];for(let f=0,g,h;f=h){c-=h;continue}g=g.slice(c,c+b);h=g.length;c=0}h>b&&(g=g.slice(0,b),h=b);if(!d.length&&h>=b)return e?Ua.call(this,g):g;d.push(g);b-=h;if(!b)break}d=d.length>1?[].concat.apply([],d):d[0];return e?Ua.call(this,d):d};function Va(a,b,c,e){var d=e[0];if(d[0]&&d[0].query)return a[b].apply(a,d);if(!(b!=="and"&&b!=="not"||a.result.length||a.await||d.suggest))return e.length>1&&(d=e[e.length-1]),(e=d.resolve)?a.await||a.result:a;let f=[],g=0,h=0,k,l,m,n,u;for(b=0;b1&&(c=c[b].apply(c,a.slice(1)));return c};X.prototype.or=function(){return Va(this,"or",Ya,arguments)};function Ya(a,b,c,e,d,f,g){a.length&&(this.result.length&&a.push(this.result),a.length<2?this.result=a[0]:(this.result=Za(a,b,c,!1,this.h),c=0));d&&(this.await=null);return d?this.resolve(b,c,e,g):this};X.prototype.and=function(){return Va(this,"and",$a,arguments)};function $a(a,b,c,e,d,f,g){if(!f&&!this.result.length)return d?this.result:this;let h;if(a.length)if(this.result.length&&a.unshift(this.result),a.length<2)this.result=a[0];else{let k=0;for(let l=0,m,n;l1?z.join(" "):z[0];let y;if(z&&E){var D=E.length,K=(da.split? -E.replace(da.split,""):E).length-z.length,F="",N=0;for(var O=0;O-1&&(F=(P?E.substring(0,P):"")+g+E.substring(P,P+L)+h+(P+L=k)break}G=za.length*(f.length-2);if(r||t||k&&q.length-G>k)if(G=k+G-u*2,B=C-A,r>0&& -(B+=r),t>0&&(B+=t),B<=G)x=r?A-(r>0?r:0):A-((G-B)/2|0),v=t?C+(t>0?t:0):x+G,l||(x>0&&q.charAt(x)!==" "&&q.charAt(x-1)!==" "&&(x=q.indexOf(" ",x),x<0&&(x=0)),v=v.length-1){if(J>= -v.length){B[y+1]=1;J>=x.length&&(G[y+1]=1);continue}D-=u}q=v[J].text;if(L=t&&z[y])if(L>0){if(q.length>L)if(B[y+1]=1,l)q=q.substring(0,L);else continue;(L-=q.length)||(L=-1);z[y]=L}else{B[y+1]=1;continue}if(D+q.length+1<=k)q=" "+q,C[y]+=q;else if(l)U=k-D-1,U>0&&(q=" "+q.substring(0,U),C[y]+=q),B[y+1]=1;else{B[y+1]=1;continue}}else{if(B[y])continue;J-=K;if(A[J]){D-=u;B[y]=1;G[y]=1;continue}if(J<=0){if(J<0){B[y]=1;G[y]=1;continue}D-=u}q=v[J].text;if(L=r&&E[y])if(L>0){if(q.length>L)if(B[y]=1,l)q=q.substring(q.length- -L);else continue;(L-=q.length)||(L=-1);E[y]=L}else{B[y]=1;continue}if(D+q.length+1<=k)q+=" ",C[y]=q+C[y];else if(l)U=q.length+1-(k-D),U>=0&&U=x.length-1?Pa=1:J1?Za(k,c,e,g,f):(k=k[0])&&c&&k.length>c||e?k.slice(e,c+e):k;else{if(ac||e)k=k.slice(e,c+ -e)}else{d=[];for(let n=0,u;ne)e-=u.length;else{if(c&&u.length>c||e)u=u.slice(e,c+e),c-=u.length,e&&(e-=u.length);d.push(u);if(!c)break}k=d}}return k} -function Za(a,b,c,e,d){const f=[],g=I();let h;var k=a.length;let l;if(e)for(d=k-1;d>=0;d--){if(l=(e=a[d])&&e.length)for(k=0;k=0;m--){n=a[m];for(let r=0;r1?ab(d,1,0,0,k,l):d[0],E)})}return r?d:new X(d.length>1?ab(d,1,0,0,k,l):d[0],this)}}r||g||!(n=n||this.field)||(M(n)?g=n:(n.constructor===Array&&n.length===1&&(n=n[0]),g=n.field||n.index));n&&n.constructor!==Array&&(n=[n])}n||(n=this.field);let G;v=(this.worker||this.db)&&!e&&[];for(let E=0,z,D,K;E0){if(c&&b>c||e)a=a.slice(e,e+c);d&&(a=Ua.call(this,a))}return a} -function Ua(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);const b=Array(a.length);for(let c=0,e;c1?c:c[0]}w.append=function(a,b){return this.add(a,b,!0)}; -w.update=function(a,b){return this.remove(a).add(a,b)};w.remove=function(a){ba(a)&&(a=ea(a,this.key));for(var b of this.index.values())b.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(let c of this.tag.values())for(let e of c){b=e[0];const d=e[1],f=d.indexOf(a);f>-1&&(d.length>1?d.splice(f,1):c.delete(b))}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -w.clear=function(){const a=[];for(const b of this.index.values()){const c=b.clear();c.then&&a.push(c)}if(this.tag)for(const b of this.tag.values())b.clear();this.store&&this.store.clear();this.cache&&this.cache.clear();return a.length?Promise.all(a):this};w.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.reg.has(a)};w.cleanup=function(){for(const a of this.index.values())a.cleanup();return this}; -w.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(b){return b[0]&&b[0].doc||null}):this.store.get(a)||null};w.set=function(a,b){typeof a==="object"&&(b=a,a=ea(b,this.key));this.store.set(a,b);return this};w.searchCache=ma;w.export=kb;w.import=lb;Ga(Qa.prototype);function mb(a,b=0){let c=[],e=[];b&&(b=25E4/b*5E3|0);for(const d of a.entries())e.push(d),e.length===b&&(c.push(e),e=[]);e.length&&c.push(e);return c}function nb(a,b){b||(b=new Map);for(let c=0,e;c2?c[0]:"";c=c.length>2?c[2]:c[1];if(this.worker&&e)return this.index.get(e).import(a);if(b){typeof b==="string"&&(b=JSON.parse(b));if(e)return this.index.get(e).import(c,b);switch(c){case "reg":this.fastupdate=!1;this.reg=rb(b,this.reg);for(let d=0,f;d=0&&d.splice(g,1)}}else ub(this.map,a),this.depth&&ub(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.M&&vb(this));this.cache&&this.cache.remove(a);return this}; -function ub(a,b){let c=0;var e=typeof b==="undefined";if(a.constructor===Array)for(let d=0,f,g,h;d=0){if(f.length>1)return f.splice(g,1),1;delete a[d];if(c)return 1;h=1}else{if(h)return 1;c++}}}else for(let d of a.entries())e=d[0],ub(d[1],b)?c++:a.delete(e);return c};const wb={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};T.prototype.add=function(a,b,c,e){if(b&&(a||a===0)){if(!e&&!c&&this.reg.has(a))return this.update(a,b);e=this.depth;b=this.encoder.encode(b,!e);const l=b.length;if(l){const m=I(),n=I(),u=this.resolution;for(let r=0;r2)for(let p=1,q,x,v,A;p2){for(let p=0,q;pp;f--)if(g=t.substring(p,f),!n[g]){q=this.rtl?d-1-p:p;var h=this.score?this.score(b,t,r,g,q):xb(u,l,r,d,q);Y(this,n,g,h,a,c)}break}case "bidirectional":case "reverse":if(d>1){for(h=d-1;h>0;h--)if(g=t[this.rtl?d-1-h:h]+g,!n[g]){var k=this.score?this.score(b,t,r,g,h):xb(u,l,r,d,h);Y(this,n,g,k,a,c)}g=""}case "forward":if(d>1){for(h=0;h1&&rg?0:1),l,r,h-1,k-1),q=this.bidirectional&&t>f;Y(this,m,q?f:t,p,a,c,q?t:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.M&&vb(this));return this}; -function Y(a,b,c,e,d,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=I()),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[e]||(h[e]=[]),!f||!h.includes(d)){if(h.length===2**31-1){b=new Aa(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[e]=h=b}h.push(d);a.fastupdate&&((e=a.reg.get(d))?e.push(h):a.reg.set(d,[h]))}} -function xb(a,b,c,e,d){return c&&a>1?b+(e||0)<=a?c+(d||0):(a-1)/(b+(e||0))*(c+(d||0))+1|0:0};T.prototype.search=function(a,b,c){c||(b||typeof a!=="object"?typeof b==="object"&&(c=b,b=0):(c=a,a=""));if(c&&c.cache)return c.cache=!1,a=this.searchCache(a,b,c),c.cache=!0,a;let e=[],d,f,g,h=0,k,l,m,n,u;c&&(a=c.query||a,b=c.limit||b,h=c.offset||0,f=c.context,g=c.suggest,u=(k=c.resolve)&&c.enrich,m=c.boost,n=c.resolution,l=this.db&&c.tag);typeof k==="undefined"&&(k=this.resolve);f=this.depth&&f!==!1;let r=this.encoder.encode(a,!f);d=r.length;b=b||(k?100:0);if(d===1)return yb.call(this,r[0],"",b, -h,k,u,l);if(d===2&&f&&!g)return yb.call(this,r[1],r[0],b,h,k,u,l);let t=I(),p=0,q;f&&(q=r[0],p=1);n||n===0||(n=q?this.N:this.resolution);if(this.db){if(this.db.search&&(c=this.db.search(this,r,b,h,g,k,u,l),c!==!1))return c;const x=this;return async function(){for(let v,A;p1)k=ab(a,b,c,e,d,f,g);else if(h===1)return g?Ta.call(null,a[0],c,e):new X(a[0],this);return g?k:new X(k,this)} -function yb(a,b,c,e,d,f,g){a=zb(this,a,b,c,e,d,f,g);return this.db?a.then(function(h){return d?h||[]:new X(h,this)}):a&&a.length?d?Ta.call(this,a,c,e):new X(a,this):d?[]:new X([],this)}function Ab(a,b,c,e){let d=[];if(a&&a.length){if(a.length<=e){b.push(a);return}for(let f=0,g;fc)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,e,d,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function T(a,b){if(!this||this.constructor!==T)return new T(a);if(a){var c=M(a)?a:a.preset;c&&(a=Object.assign({},wb[c],a))}else a={};c=a.context;const e=c===!0?{depth:1}:c||{},d=M(a.encoder)?wa[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new la(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&c!=="default"&&c!=="exact"&&c||"strict";this.depth=c==="strict"&&e.depth||0;this.bidirectional=e.bidirectional!==!1;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new R(c):new Map;this.ctx=c?new R(c):new Map;this.reg=b||(this.fastupdate?c?new R(c):new Map:c?new S(c):new Set);this.N=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new na(c);this.resolve=a.resolve!==!1;if(c=a.db)this.db=this.mount(c);this.M=a.commit!==!1;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=T.prototype; -w.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};w.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};w.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function vb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} -w.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this};w.append=function(a,b){return this.add(a,b,!0)};w.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};w.update=function(a,b){const c=this,e=this.remove(a);return e&&e.then?e.then(()=>c.add(a,b)):this.add(a,b)}; -w.cleanup=function(){if(!this.fastupdate)return this;ub(this.map);this.depth&&ub(this.ctx);return this};w.searchCache=ma;w.export=function(a,b,c=0,e=0){let d,f;switch(e){case 0:d="reg";f=qb(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=mb(this.map,this.reg.size);break;case 3:d="ctx";f=ob(this.ctx,this.reg.size);break;default:return}return sb.call(this,a,b,d,f,c,e)}; -w.import=function(a,b){if(b)switch(typeof b==="string"&&(b=JSON.parse(b)),a=a.split("."),a[a.length-1]==="json"&&a.pop(),a.length===3&&a.shift(),a=a.length>1?a[1]:a[0],a){case "reg":this.fastupdate=!1;this.reg=rb(b,this.reg);break;case "map":this.map=nb(b,this.map);break;case "ctx":this.ctx=pb(b,this.ctx)}}; -w.serialize=function(a=!0){let b="",c="",e="";if(this.reg.size){let f;for(var d of this.reg.keys())f||(f=typeof d),b+=(b?",":"")+(f==="string"?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";c=tb(this.map,f);c="index.map=new Map(["+c+"]);";for(const g of this.ctx.entries()){d=g[0];let h=tb(g[1],f);h="new Map(["+h+"])";h='["'+d+'",'+h+"]";e+=(e?",":"")+h}e="index.ctx=new Map(["+e+"]);"}return a?"function inject(index){"+b+c+e+"}":b+c+e};Ga(T.prototype);const Cb=typeof window!=="undefined"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Db=["map","ctx","tag","reg","cfg"],Eb=I(); -function Fb(a,b={}){if(!this||this.constructor!==Fb)return new Fb(a,b);typeof a==="object"&&(b=a,a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=b.field?b.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.type=b.type;this.fastupdate=this.support_tag_search=!1;this.db=null;this.h={}}w=Fb.prototype;w.mount=function(a){if(a.index)return a.mount(this);a.db=this;return this.open()}; -w.open=function(){if(this.db)return this.db;let a=this;navigator.storage&&navigator.storage.persist();Eb[a.id]||(Eb[a.id]=[]);Eb[a.id].push(a.field);const b=Cb.open(a.id,1);b.onupgradeneeded=function(){const c=a.db=this.result;for(let e=0,d;e=m.length){e-=m.length;continue}const n=c?e+Math.min(m.length-e,c):m.length;for(let u=e;u=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return e?d.enrich(f):f})}; -w.enrich=function(a){typeof a!=="object"&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let e=0;e=0)if(d=1,h.length>1)h.splice(l,1);else{e[g]=[];break}f+=h.length}if(c)break}f?d&&a.update(e):a.delete();a.continue()} -w.remove=function(a){typeof a!=="object"&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Gb(c,a)}}),this.transaction("ctx","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Gb(c,a)}}),this.transaction("tag","readwrite",function(b){b.openCursor().onsuccess=function(){const c=this.result;c&&Gb(c,a,!0)}}),this.transaction("reg","readwrite",function(b){for(let c=0;c{a.onsuccess=a.oncomplete=function(){b&&b(this.result);b=null;c(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:T,Charset:wa,Encoder:la,Document:Qa,Worker:Ma,Resolver:X,IndexedDB:Fb,Language:{}}; -export const Index=T;export const Charset=wa;export const Encoder=la;export const Document=Qa;export const Worker=Ma;export const Resolver=X;export const IndexedDB=Fb;export const Language={}; \ No newline at end of file +var w;function H(a,c,b){const e=typeof b,d=typeof a;if(e!=="undefined"){if(d!=="undefined"){if(b){if(d==="function"&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return d==="undefined"?c:a}function aa(a,c){return typeof a==="undefined"?c:a}function I(){return Object.create(null)} +function M(a){return typeof a==="string"}function ba(a){return typeof a==="object"}function ca(a,c){if(M(c))a=a[c];else for(let b=0;a&&b1)return this.addMatcher(a,c);this.mapper||(this.mapper=new Map);this.mapper.set(a,c);this.cache&&Q(this);return this};w.addMatcher=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.J=null;this.cache&&Q(this);return this}; +w.addReplacer=function(a,c){if(typeof a==="string")return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&Q(this);return this}; +w.encode=function(a,c){if(this.cache&&a.length<=this.H)if(this.F){if(this.B.has(a))return this.B.get(a)}else this.F=setTimeout(Q,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(ha,"$1 $2").replace(ia,"$1 $2").replace(fa,"$1 "));const b=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let e= +[],d=I(),f,g,h=this.split||this.split===""?a.split(this.split):[a];for(let l=0,m,p;lthis.maxlength)){if(c){if(d[m])continue;d[m]=1}else{if(f===m)continue;f=m}if(b)e.push(m);else if(!this.filter||(typeof this.filter==="function"?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.I)if(this.F){var k=this.D.get(m);if(k||k===""){k&&e.push(k);continue}}else this.F=setTimeout(Q,50,this);if(this.stemmer){this.K||(this.K=new RegExp("(?!^)("+ +this.A+")$"));let u;for(;u!==m&&m.length>2;)u=m,m=m.replace(this.K,r=>this.stemmer.get(r))}if(m&&(this.mapper||this.dedupe&&m.length>1)){k="";for(let u=0,r="",t,n;u1&&(this.J||(this.J=new RegExp("("+this.h+")","g")),m=m.replace(this.J,u=>this.matcher.get(u)));if(m&&this.replacer)for(k=0;m&&kthis.L&&(this.D.clear(),this.I=this.I/1.1|0));if(m){if(m!==p)if(c){if(d[m])continue;d[m]=1}else{if(g===m)continue;g=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.H&&(this.B.set(a,e),this.B.size>this.L&&(this.B.clear(),this.H=this.H/1.1|0));return e};function Q(a){a.F=null;a.B.clear();a.D.clear()};function la(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):b=a);b&&(a=b.query||a,c=b.limit||c);let e=""+(c||0);b&&(e+=(b.offset||0)+!!b.context+!!b.suggest+(b.resolve!==!1)+(b.resolution||this.resolution)+(b.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new ma);let d=this.cache.get(a+e);if(!d){const f=b&&b.cache;f&&(b.cache=!1);d=this.search(a,c,b);f&&(b.cache=f);this.cache.set(a+e,d)}return d}function ma(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""} +ma.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)};ma.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};ma.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};ma.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:!1,numeric:!1,dedupe:!1};const oa={};const ra=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 sa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ta=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ua={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var va={Exact:na,Default:oa,Normalize:oa,LatinBalance:{mapper:ra},LatinAdvanced:{mapper:ra,matcher:sa,replacer:ta},LatinExtra:{mapper:ra,replacer:ta.concat([/(?!^)[aeo]/g,""]),matcher:sa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;b=g.length)c-=g.length;else{c=g[e?"splice":"slice"](c,b);const h=c.length;if(h&&(d=d.length?d.concat(c):c,b-=h,e&&(a.length-=h),!b))break;c=0}return d} +function xa(a){if(!this||this.constructor!==xa)return new xa(a);this.index=a?[a]:[];this.length=a?a.length:0;const c=this;return new Proxy([],{get(b,e){if(e==="length")return c.length;if(e==="push")return function(d){c.index[c.index.length-1].push(d);c.length++};if(e==="pop")return function(){if(c.length)return c.length--,c.index[c.index.length-1].pop()};if(e==="indexOf")return function(d){let f=0;for(let g=0,h,k;g=0)return f+k;f+=h.length}return-1}; +if(e==="includes")return function(d){for(let f=0;f32?(this.B=Aa,this.A=BigInt(a)):(this.B=Ba,this.A=a)}R.prototype.get=function(a){const c=this.index[this.B(a)];return c&&c.get(a)};R.prototype.set=function(a,c){var b=this.B(a);let e=this.index[b];e?(b=e.size,e.set(a,c),(b-=e.size)&&this.size++):(this.index[b]=e=new Map([[a,c]]),this.h.push(e),this.size++)}; +function S(a=8){if(!this||this.constructor!==S)return new S(a);this.index=I();this.h=[];this.size=0;a>32?(this.B=Aa,this.A=BigInt(a)):(this.B=Ba,this.A=a)}S.prototype.add=function(a){var c=this.B(a);let b=this.index[c];b?(c=b.size,b.add(a),(c-=b.size)&&this.size++):(this.index[c]=b=new Set([a]),this.h.push(b),this.size++)};w=R.prototype;w.has=S.prototype.has=function(a){const c=this.index[this.B(a)];return c&&c.has(a)}; +w.delete=S.prototype.delete=function(a){const c=this.index[this.B(a)];c&&c.delete(a)&&this.size--};w.clear=S.prototype.clear=function(){this.index=I();this.h=[];this.size=0};w.values=S.prototype.values=function*(){for(let a=0;a=this.priority*this.priority*3):(Ha=setTimeout(Ka,0),Ia=Date.now());if(Ja){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};let V=0; +function La(a={},c){function b(h){function k(l){l=l.data||l;const m=l.id,p=m&&f.h[m];p&&(p(l.msg),delete f.h[m])}this.worker=h;this.h=I();if(this.worker){d?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(l){V>1E9&&(V=0);f.h[++V]=function(){l(f)};f.worker.postMessage({id:V,task:"init",factory:e,options:a})});this.priority=a.priority||4;this.encoder=c||null;this.worker.postMessage({task:"init",factory:e,options:a});return this}}if(!this||this.constructor!==La)return new La(a); +let e=typeof self!=="undefined"?self._factory:typeof window!=="undefined"?window._factory:null;e&&(e=e.toString());const d=typeof window==="undefined",f=this,g=Ma(e,d,a.worker);return g.then?g.then(function(h){return b.call(f,h)}):b.call(this,g)}W("add");W("append");W("search");W("update");W("remove");W("clear");W("export");W("import");La.prototype.searchCache=la;Fa(La.prototype); +function W(a){La.prototype[a]=function(){const c=this,b=[].slice.call(arguments);var e=b[b.length-1];let d;typeof e==="function"&&(d=e,b.pop());e=new Promise(function(f){a==="export"&&typeof b[0]==="function"&&(b[0]=null);V>1E9&&(V=0);c.h[++V]=f;c.worker.postMessage({task:a,id:V,args:b})});return d?(e.then(d),this):e}} +function Ma(a,c,b){return c?typeof module!=="undefined"?new(require("worker_threads")["Worker"])(__dirname+"/worker/node.js"):import("worker_threads").then(function(worker){return new worker["Worker"](import.meta.dirname+"/node/node.mjs")}):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ea.toString()],{type:"text/javascript"}))):new window.Worker(typeof b==="string"?b:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};Na.prototype.add=function(a,c,b){ba(a)&&(c=a,a=ca(c,this.key));if(c&&(a||a===0)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hc?a.slice(b,b+c):a,e?Ta.call(this,a):a;let d=[];for(let f=0,g,h;f=h){b-=h;continue}g=g.slice(b,b+c);h=g.length;b=0}h>c&&(g=g.slice(0,c),h=c);if(!d.length&&h>=c)return e?Ta.call(this,g):g;d.push(g);c-=h;if(!c)break}d=d.length>1?[].concat.apply([],d):d[0];return e?Ta.call(this,d):d};function Ua(a,c,b,e){var d=e[0];if(d[0]&&d[0].query)return a[c].apply(a,d);if(!(c!=="and"&&c!=="not"||a.result.length||a.await||d.suggest))return e.length>1&&(d=e[e.length-1]),(e=d.resolve)?a.await||a.result:a;let f=[],g=0,h=0,k,l,m,p,u;for(c=0;c1&&(b=b[c].apply(b,a.slice(1)));return b};X.prototype.or=function(){return Ua(this,"or",Xa,arguments)};function Xa(a,c,b,e,d,f,g){a.length&&(this.result.length&&a.push(this.result),a.length<2?this.result=a[0]:(this.result=Ya(a,c,b,!1,this.h),b=0));d&&(this.await=null);return d?this.resolve(c,b,e,g):this};X.prototype.and=function(){return Ua(this,"and",Za,arguments)};function Za(a,c,b,e,d,f,g){if(!f&&!this.result.length)return d?this.result:this;let h;if(a.length)if(this.result.length&&a.unshift(this.result),a.length<2)this.result=a[0];else{let k=0;for(let l=0,m,p;l1?z.join(" "):z[0];let y;if(z&&B){var C=B.length,K=(da.split? +B.replace(da.split,""):B).length-z.length,F="",N=0;for(var O=0;O-1&&(F=(P?B.substring(0,P):"")+g+B.substring(P,P+L)+h+(P+L=k)break}G=za.length*(f.length-2);if(r||t||k&&q.length-G>k)if(G=k+G-u*2,E=D-A,r>0&& +(E+=r),t>0&&(E+=t),E<=G)x=r?A-(r>0?r:0):A-((G-E)/2|0),v=t?D+(t>0?t:0):x+G,l||(x>0&&q.charAt(x)!==" "&&q.charAt(x-1)!==" "&&(x=q.indexOf(" ",x),x<0&&(x=0)),v=v.length-1){if(J>= +v.length){E[y+1]=1;J>=x.length&&(G[y+1]=1);continue}C-=u}q=v[J].text;if(L=t&&z[y])if(L>0){if(q.length>L)if(E[y+1]=1,l)q=q.substring(0,L);else continue;(L-=q.length)||(L=-1);z[y]=L}else{E[y+1]=1;continue}if(C+q.length+1<=k)q=" "+q,D[y]+=q;else if(l)U=k-C-1,U>0&&(q=" "+q.substring(0,U),D[y]+=q),E[y+1]=1;else{E[y+1]=1;continue}}else{if(E[y])continue;J-=K;if(A[J]){C-=u;E[y]=1;G[y]=1;continue}if(J<=0){if(J<0){E[y]=1;G[y]=1;continue}C-=u}q=v[J].text;if(L=r&&B[y])if(L>0){if(q.length>L)if(E[y]=1,l)q=q.substring(q.length- +L);else continue;(L-=q.length)||(L=-1);B[y]=L}else{E[y]=1;continue}if(C+q.length+1<=k)q+=" ",D[y]=q+D[y];else if(l)U=q.length+1-(k-C),U>=0&&U=x.length-1?Pa=1:J1?Ya(k,b,e,g,f):(k=k[0])&&b&&k.length>b||e?k.slice(e,b+e):k;else{if(ab||e)k=k.slice(e,b+ +e)}else{d=[];for(let p=0,u;pe)e-=u.length;else{if(b&&u.length>b||e)u=u.slice(e,b+e),b-=u.length,e&&(e-=u.length);d.push(u);if(!b)break}k=d}}return k} +function Ya(a,c,b,e,d){const f=[],g=I();let h;var k=a.length;let l;if(e)for(d=k-1;d>=0;d--){if(l=(e=a[d])&&e.length)for(k=0;k=0;m--){p=a[m];for(let r=0;r1?$a(d,1,0,0,k,l):d[0],B)})}return r?d:new X(d.length>1?$a(d,1,0,0,k,l):d[0],this)}}r||g||!(p=p||this.field)||(M(p)?g=p:(p.constructor===Array&&p.length===1&&(p=p[0]),g=p.field||p.index));p&&p.constructor!==Array&&(p=[p])}p||(p=this.field);let G;v=(this.worker||this.db)&&!e&&[];for(let B=0,z,C,K;B0){if(b&&c>b||e)a=a.slice(e,e+b);d&&(a=Ta.call(this,a))}return a} +function Ta(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);const c=Array(a.length);for(let b=0,e;b1?b:b[0]}w.append=function(a,c){return this.add(a,c,!0)}; +w.update=function(a,c){return this.remove(a).add(a,c)};w.remove=function(a){ba(a)&&(a=ca(a,this.key));for(var c of this.index.values())c.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(let b of this.tag.values())for(let e of b){c=e[0];const d=e[1],f=d.indexOf(a);f>-1&&(d.length>1?d.splice(f,1):b.delete(c))}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +w.clear=function(){const a=[];for(const c of this.index.values()){const b=c.clear();b.then&&a.push(b)}if(this.tag)for(const c of this.tag.values())c.clear();this.store&&this.store.clear();this.cache&&this.cache.clear();return a.length?Promise.all(a):this};w.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.reg.has(a)};w.cleanup=function(){for(const a of this.index.values())a.cleanup();return this}; +w.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(c){return c[0]&&c[0].doc||null}):this.store.get(a)||null};w.set=function(a,c){typeof a==="object"&&(c=a,a=ca(c,this.key));this.store.set(a,c);return this};w.searchCache=la;w.export=jb;w.import=kb;Fa(Na.prototype);function lb(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function mb(a,c){c||(c=new Map);for(let b=0,e;b2?b[0]:"";b=b.length>2?b[2]:b[1];if(this.worker&&e)return this.index.get(e).import(a);if(c){typeof c==="string"&&(c=JSON.parse(c));if(e)return this.index.get(e).import(b,c);switch(b){case "reg":this.fastupdate=!1;this.reg=qb(c,this.reg);for(let d=0,f;d=0&&d.splice(g,1)}}else tb(this.map,a),this.depth&&tb(this.ctx,a);c||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.M&&ub(this));this.cache&&this.cache.remove(a);return this}; +function tb(a,c){let b=0;var e=typeof c==="undefined";if(a.constructor===Array)for(let d=0,f,g,h;d=0){if(f.length>1)return f.splice(g,1),1;delete a[d];if(b)return 1;h=1}else{if(h)return 1;b++}}}else for(let d of a.entries())e=d[0],tb(d[1],c)?b++:a.delete(e);return b};const vb={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};T.prototype.add=function(a,c,b,e){if(c&&(a||a===0)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);e=this.depth;c=this.encoder.encode(c,!e);const l=c.length;if(l){const m=I(),p=I(),u=this.resolution;for(let r=0;r2){for(let n=1,q,x,v,A;n2){for(let n=0,q;nn;f--){g=t.substring(n,f);q=this.rtl?d-1-n:n;var h=this.score?this.score(c,t,r,g,q):wb(u,l,r,d,q);Y(this,p,g,h,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(h=d-1;h>0;h--){g=t[this.rtl?d-1-h:h]+g;var k=this.score?this.score(c,t,r,g,h):wb(u,l,r,d,h);Y(this,p,g,k,a,b)}g=""}case "forward":if(d>1){for(h=0;h1&&rg;const n=this.score?this.score(c,g,r,t,h-1):wb(d+(l/2>d?0:1),l,r,f-1,h-1);Y(this,m,k?g:t,n,a,b,k?t:g)}}}}this.fastupdate||this.reg.add(a)}}this.db&&(this.commit_task.push(b?{ins:a}:{del:a}),this.M&&ub(this));return this}; +function Y(a,c,b,e,d,f,g){let h,k;if(!(h=c[b])||g&&!h[g]){g?(c=h||(c[b]=I()),c[g]=1,k=a.ctx,(h=k.get(g))?k=h:k.set(g,k=a.keystore?new R(a.keystore):new Map)):(k=a.map,c[b]=1);(h=k.get(b))?k=h:k.set(b,k=h=[]);if(f)for(let l=0,m;l1?c+(e||0)<=a?b+(d||0):(a-1)/(c+(e||0))*(b+(d||0))+1|0:0};T.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));if(b&&b.cache)return b.cache=!1,a=this.searchCache(a,c,b),b.cache=!0,a;let e=[],d,f,g,h=0,k,l,m,p,u;b&&(a=b.query||a,c=b.limit||c,h=b.offset||0,f=b.context,g=b.suggest,u=(k=b.resolve)&&b.enrich,m=b.boost,p=b.resolution,l=this.db&&b.tag);typeof k==="undefined"&&(k=this.resolve);f=this.depth&&f!==!1;let r=this.encoder.encode(a,!f);d=r.length;c=c||(k?100:0);if(d===1)return xb.call(this,r[0],"",c, +h,k,u,l);if(d===2&&f&&!g)return xb.call(this,r[1],r[0],c,h,k,u,l);let t=I(),n=0,q;f&&(q=r[0],n=1);p||p===0||(p=q?this.N:this.resolution);if(this.db){if(this.db.search&&(b=this.db.search(this,r,c,h,g,k,u,l),b!==!1))return b;const x=this;return async function(){for(let v,A;n1)k=$a(a,c,b,e,d,f,g);else if(h===1)return g?Sa.call(null,a[0],b,e):new X(a[0],this);return g?k:new X(k,this)} +function xb(a,c,b,e,d,f,g){a=yb(this,a,c,b,e,d,f,g);return this.db?a.then(function(h){return d?h||[]:new X(h,this)}):a&&a.length?d?Sa.call(this,a,b,e):new X(a,this):d?[]:new X([],this)}function zb(a,c,b,e){let d=[];if(a&&a.length){if(a.length<=e){c.push(a);return}for(let f=0,g;fb)&&(k=b,b=c,c=k);if(a.db)return a.db.get(c,b,e,d,f,g,h);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function T(a,c){if(!this||this.constructor!==T)return new T(a);if(a){var b=M(a)?a:a.preset;b&&(a=Object.assign({},vb[b],a))}else a={};b=a.context;const e=b===!0?{depth:1}:b||{},d=M(a.encoder)?va[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new ka(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&b!=="default"&&b!=="exact"&&b||"strict";this.depth=b==="strict"&&e.depth||0;this.bidirectional=e.bidirectional!==!1;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;(b=a.keystore||0)&&(this.keystore=b);this.map=b?new R(b):new Map;this.ctx=b?new R(b):new Map;this.reg=c||(this.fastupdate?b?new R(b):new Map:b?new S(b):new Set);this.N=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(b=a.cache||null)&&new ma(b);this.resolve=a.resolve!==!1;if(b=a.db)this.db=this.mount(b);this.M=a.commit!==!1;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=T.prototype; +w.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};w.commit=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this)};w.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function ub(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a)},1))} +w.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this};w.append=function(a,c){return this.add(a,c,!0)};w.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};w.update=function(a,c){const b=this,e=this.remove(a);return e&&e.then?e.then(()=>b.add(a,c)):this.add(a,c)}; +w.cleanup=function(){if(!this.fastupdate)return this;tb(this.map);this.depth&&tb(this.ctx);return this};w.searchCache=la;w.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=pb(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=lb(this.map,this.reg.size);break;case 3:d="ctx";f=nb(this.ctx,this.reg.size);break;default:return}return rb.call(this,a,c,d,f,b,e)}; +w.import=function(a,c){if(c)switch(typeof c==="string"&&(c=JSON.parse(c)),a=a.split("."),a[a.length-1]==="json"&&a.pop(),a.length===3&&a.shift(),a=a.length>1?a[1]:a[0],a){case "reg":this.fastupdate=!1;this.reg=qb(c,this.reg);break;case "map":this.map=mb(c,this.map);break;case "ctx":this.ctx=ob(c,this.ctx)}}; +w.serialize=function(a=!0){let c="",b="",e="";if(this.reg.size){let f;for(var d of this.reg.keys())f||(f=typeof d),c+=(c?",":"")+(f==="string"?'"'+d+'"':d);c="index.reg=new Set(["+c+"]);";b=sb(this.map,f);b="index.map=new Map(["+b+"]);";for(const g of this.ctx.entries()){d=g[0];let h=sb(g[1],f);h="new Map(["+h+"])";h='["'+d+'",'+h+"]";e+=(e?",":"")+h}e="index.ctx=new Map(["+e+"]);"}return a?"function inject(index){"+c+b+e+"}":c+b+e};Fa(T.prototype);const Bb=typeof window!=="undefined"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),Cb=["map","ctx","tag","reg","cfg"],Db=I(); +function Eb(a,c={}){if(!this||this.constructor!==Eb)return new Eb(a,c);typeof a==="object"&&(c=a,a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=c.field?c.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.type=c.type;this.fastupdate=this.support_tag_search=!1;this.db=null;this.h={}}w=Eb.prototype;w.mount=function(a){if(a.index)return a.mount(this);a.db=this;return this.open()}; +w.open=function(){if(this.db)return this.db;let a=this;navigator.storage&&navigator.storage.persist();Db[a.id]||(Db[a.id]=[]);Db[a.id].push(a.field);const c=Bb.open(a.id,1);c.onupgradeneeded=function(){const b=a.db=this.result;for(let e=0,d;e=m.length){e-=m.length;continue}const p=b?e+Math.min(m.length-e,b):m.length;for(let u=e;u=f.length)return[];if(!c&&!b)return f;f=f.slice(b,b+c);return e?d.enrich(f):f})}; +w.enrich=function(a){typeof a!=="object"&&(a=[a]);const c=this.db.transaction("reg","readonly").objectStore("reg"),b=[];for(let e=0;e=0)if(d=1,h.length>1)h.splice(l,1);else{e[g]=[];break}f+=h.length}if(b)break}f?d&&a.update(e):a.delete();a.continue()} +w.remove=function(a){typeof a!=="object"&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(c){c.openCursor().onsuccess=function(){const b=this.result;b&&Fb(b,a)}}),this.transaction("ctx","readwrite",function(c){c.openCursor().onsuccess=function(){const b=this.result;b&&Fb(b,a)}}),this.transaction("tag","readwrite",function(c){c.openCursor().onsuccess=function(){const b=this.result;b&&Fb(b,a,!0)}}),this.transaction("reg","readwrite",function(c){for(let b=0;b{a.onsuccess=a.oncomplete=function(){c&&c(this.result);c=null;b(this.result)};a.onerror=a.onblocked=e;a=null})};export default {Index:T,Charset:va,Encoder:ka,Document:Na,Worker:La,Resolver:X,IndexedDB:Eb,Language:{}}; +export const Index=T;export const Charset=va;export const Encoder=ka;export const Document=Na;export const Worker=La;export const Resolver=X;export const IndexedDB=Eb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 0821941..50d6c81 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.203 (Bundle/Debug) + * FlexSearch.js v0.8.205 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -13,8 +13,8 @@ function I(a, c, b) { if (d !== "undefined") { if (b) { if (d === "function" && e === d) { - return function(h) { - return a(b(h)); + return function(k) { + return a(b(k)); }; } c = a.constructor; @@ -44,7 +44,7 @@ function I(a, c, b) { } return d === "undefined" ? c : a; } -function J(a, c) { +function K(a, c) { return typeof a === "undefined" ? c : a; } function M() { @@ -53,7 +53,7 @@ function M() { function P(a) { return typeof a === "string"; } -function R(a) { +function Q(a) { return typeof a === "object"; } function aa(a, c) { @@ -206,9 +206,9 @@ B.encode = function(a, c) { this.prepare && (a = this.prepare(a)); this.numeric && a.length > 3 && (a = a.replace(fa, "$1 $2").replace(ha, "$1 $2").replace(ea, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = M(), f, g, h = this.split || this.split === "" ? a.split(this.split) : [a]; - for (let n = 0, l, z; n < h.length; n++) { - if ((l = z = h[n]) && !(l.length < this.minlength || l.length > this.maxlength)) { + let e = [], d = M(), f, g, k = this.split || this.split === "" ? a.split(this.split) : [a]; + for (let m = 0, l, A; m < k.length; m++) { + if ((l = A = k[m]) && !(l.length < this.minlength || l.length > this.maxlength)) { if (c) { if (d[l]) { continue; @@ -226,9 +226,9 @@ B.encode = function(a, c) { if (!this.filter || (typeof this.filter === "function" ? this.filter(l) : !this.filter.has(l))) { if (this.cache && l.length <= this.H) { if (this.D) { - var k = this.C.get(l); - if (k || k === "") { - k && e.push(k); + var h = this.C.get(l); + if (h || h === "") { + h && e.push(h); continue; } } else { @@ -243,21 +243,21 @@ B.encode = function(a, c) { } } if (l && (this.mapper || this.dedupe && l.length > 1)) { - k = ""; + h = ""; for (let x = 0, u = "", p, w; x < l.length; x++) { - p = l.charAt(x), p === u && this.dedupe || ((w = this.mapper && this.mapper.get(p)) || w === "" ? w === u && this.dedupe || !(u = w) || (k += w) : k += u = p); + p = l.charAt(x), p === u && this.dedupe || ((w = this.mapper && this.mapper.get(p)) || w === "" ? w === u && this.dedupe || !(u = w) || (h += w) : h += u = p); } - l = k; + l = h; } this.matcher && l.length > 1 && (this.I || (this.I = new RegExp("(" + this.h + ")", "g")), l = l.replace(this.I, x => this.matcher.get(x))); if (l && this.replacer) { - for (k = 0; l && k < this.replacer.length; k += 2) { - l = l.replace(this.replacer[k], this.replacer[k + 1]); + for (h = 0; l && h < this.replacer.length; h += 2) { + l = l.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && z.length <= this.H && (this.C.set(z, l), this.C.size > this.K && (this.C.clear(), this.H = this.H / 1.1 | 0)); + this.cache && A.length <= this.H && (this.C.set(A, l), this.C.size > this.K && (this.C.clear(), this.H = this.H / 1.1 | 0)); if (l) { - if (l !== z) { + if (l !== A) { if (c) { if (d[l]) { continue; @@ -374,20 +374,20 @@ function U(a) { }; } ;X.prototype.add = function(a, c, b) { - R(a) && (c = a, a = aa(c, this.key)); + Q(a) && (c = a, a = aa(c, this.key)); if (c && (a || a === 0)) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.B[h]; - var e = this.index.get(this.field[h]); - if (typeof k === "function") { - var d = k(c); - d && e.add(a, d, !1, !0); + for (let k = 0, h; k < this.field.length; k++) { + h = this.B[k]; + var e = this.index.get(this.field[k]); + if (typeof h === "function") { + var d = h(c); + d && e.add(a, d, b, !0); } else { - if (d = k.F, !d || d(c)) { - k.constructor === String ? k = ["" + k] : P(k) && (k = [k]), Ba(c, k, this.C, 0, e, a, k[0], b); + if (d = h.F, !d || d(c)) { + h.constructor === String ? h = ["" + h] : P(h) && (h = [h]), Ba(c, h, this.C, 0, e, a, h[0], b); } } } @@ -395,14 +395,14 @@ function U(a) { for (e = 0; e < this.A.length; e++) { var f = this.A[e], g = this.D[e]; d = this.tag.get(g); - let h = M(); + let k = M(); if (typeof f === "function") { if (f = f(c), !f) { continue; } } else { - const k = f.F; - if (k && !k(c)) { + const h = f.F; + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); @@ -410,8 +410,8 @@ function U(a) { } if (d && f) { P(f) && (f = [f]); - for (let k = 0, n, l; k < f.length; k++) { - n = f[k], h[n] || (h[n] = 1, (g = d.get(n)) ? l = g : d.set(n, l = []), b && l.includes(a) || (l.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(l) : this.reg.set(a, [l])))); + for (let h = 0, m, l; h < f.length; h++) { + m = f[h], k[m] || (k[m] = 1, (g = d.get(m)) ? l = g : d.set(m, l = []), b && l.includes(a) || (l.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(l) : this.reg.set(a, [l])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -419,29 +419,29 @@ function U(a) { } } if (this.store && (!b || !this.store.has(a))) { - let h; + let k; if (this.h) { - h = M(); - for (let k = 0, n; k < this.h.length; k++) { - n = this.h[k]; - if ((b = n.F) && !b(c)) { + k = M(); + for (let h = 0, m; h < this.h.length; h++) { + m = this.h[h]; + if ((b = m.F) && !b(c)) { continue; } let l; - if (typeof n === "function") { - l = n(c); + if (typeof m === "function") { + l = m(c); if (!l) { continue; } - n = [n.M]; - } else if (P(n) || n.constructor === String) { - h[n] = c[n]; + m = [m.M]; + } else if (P(m) || m.constructor === String) { + k[m] = c[m]; continue; } - Ca(c, h, n, 0, n[0], l); + Ca(c, k, m, 0, m[0], l); } } - this.store.set(a, h || c); + this.store.set(a, k || c); } } return this; @@ -460,7 +460,7 @@ function Ca(a, c, b, e, d, f) { } } } -function Ba(a, c, b, e, d, f, g, h) { +function Ba(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -472,14 +472,14 @@ function Ba(a, c, b, e, d, f, g, h) { } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ba(a, c, b, e, d, f, g, h); + Ba(a, c, b, e, d, f, g, k); } } else { - g = c[++e], Ba(a, c, b, e, d, f, g, h); + g = c[++e], Ba(a, c, b, e, d, f, g, k); } } } @@ -517,7 +517,7 @@ function Ba(a, c, b, e, d, f, g, h) { return e = e.length > 1 ? [].concat.apply([], e) : e[0]; } ;function Ea(a, c, b, e, d) { - let f, g, h; + let f, g, k; typeof d === "string" ? (f = d, d = "") : f = d.template; if (!f) { throw Error('No template pattern was specified by the search option "highlight"'); @@ -526,22 +526,22 @@ function Ba(a, c, b, e, d, f, g, h) { if (g === -1) { throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); } - h = f.substring(g + 2); + k = f.substring(g + 2); g = f.substring(0, g); - let k = d && d.boundary, n = !d || d.clip !== !1, l = d && d.merge && h && g && new RegExp(h + " " + g, "g"); + let h = d && d.boundary, m = !d || d.clip !== !1, l = d && d.merge && k && g && new RegExp(k + " " + g, "g"); d = d && d.ellipsis; - var z = 0; + var A = 0; if (typeof d === "object") { var x = d.template; - z = x.length - 2; + A = x.length - 2; d = d.pattern; } typeof d !== "string" && (d = d === !1 ? "" : "..."); - z && (d = x.replace("$1", d)); - x = d.length - z; + A && (d = x.replace("$1", d)); + x = d.length - A; let u, p; - typeof k === "object" && (u = k.before, u === 0 && (u = -1), p = k.after, p === 0 && (p = -1), k = k.total || 9e5); - z = new Map(); + typeof h === "object" && (u = h.before, u === 0 && (u = -1), p = h.after, p === 0 && (p = -1), h = h.total || 9e5); + A = new Map(); for (let ta = 0, V, Ka, ca; ta < c.length; ta++) { let da; if (e) { @@ -556,65 +556,65 @@ function Ba(a, c, b, e, d, f, g, h) { } Ka = b.get(ca); V = Ka.encoder; - w = z.get(V); - typeof w !== "string" && (w = V.encode(a), z.set(V, w)); + w = A.get(V); + typeof w !== "string" && (w = V.encode(a), A.set(V, w)); for (let ia = 0; ia < da.length; ia++) { - var m = da[ia].doc; - if (!m) { + var n = da[ia].doc; + if (!n) { continue; } - m = aa(m, ca); - if (!m) { + n = aa(n, ca); + if (!n) { continue; } - var v = m.trim().split(/\s+/); + var v = n.trim().split(/\s+/); if (!v.length) { continue; } - m = ""; + n = ""; var t = []; let ja = []; - var C = -1, A = -1, r = 0; + var C = -1, z = -1, r = 0; for (var y = 0; y < v.length; y++) { var F = v[y], D = V.encode(F); D = D.length > 1 ? D.join(" ") : D[0]; let q; if (D && F) { - var E = F.length, K = (V.split ? F.replace(V.split, "") : F).length - D.length, L = "", Q = 0; + var E = F.length, J = (V.split ? F.replace(V.split, "") : F).length - D.length, L = "", R = 0; for (var W = 0; W < w.length; W++) { var N = w[W]; if (N) { var H = N.length; - H += K; - Q && H <= Q || (N = D.indexOf(N), N > -1 && (L = (N ? F.substring(0, N) : "") + g + F.substring(N, N + H) + h + (N + H < E ? F.substring(N + H) : ""), Q = H, q = !0)); + H += J; + R && H <= R || (N = D.indexOf(N), N > -1 && (L = (N ? F.substring(0, N) : "") + g + F.substring(N, N + H) + k + (N + H < E ? F.substring(N + H) : ""), R = H, q = !0)); } } - L && (k && (C < 0 && (C = m.length + (m ? 1 : 0)), A = m.length + (m ? 1 : 0) + L.length, r += E, ja.push(t.length), t.push({match:L})), m += (m ? " " : "") + L); + L && (h && (C < 0 && (C = n.length + (n ? 1 : 0)), z = n.length + (n ? 1 : 0) + L.length, r += E, ja.push(t.length), t.push({match:L})), n += (n ? " " : "") + L); } if (!q) { - F = v[y], m += (m ? " " : "") + F, k && t.push({text:F}); - } else if (k && r >= k) { + F = v[y], n += (n ? " " : "") + F, h && t.push({text:F}); + } else if (h && r >= h) { break; } } r = ja.length * (f.length - 2); - if (u || p || k && m.length - r > k) { - if (r = k + r - x * 2, y = A - C, u > 0 && (y += u), p > 0 && (y += p), y <= r) { - v = u ? C - (u > 0 ? u : 0) : C - ((r - y) / 2 | 0), t = p ? A + (p > 0 ? p : 0) : v + r, n || (v > 0 && m.charAt(v) !== " " && m.charAt(v - 1) !== " " && (v = m.indexOf(" ", v), v < 0 && (v = 0)), t < m.length && m.charAt(t - 1) !== " " && m.charAt(t) !== " " && (t = m.lastIndexOf(" ", t), t < A ? t = A : ++t)), m = (v ? d : "") + m.substring(v, t) + (t < m.length ? d : ""); + if (u || p || h && n.length - r > h) { + if (r = h + r - x * 2, y = z - C, u > 0 && (y += u), p > 0 && (y += p), y <= r) { + v = u ? C - (u > 0 ? u : 0) : C - ((r - y) / 2 | 0), t = p ? z + (p > 0 ? p : 0) : v + r, m || (v > 0 && n.charAt(v) !== " " && n.charAt(v - 1) !== " " && (v = n.indexOf(" ", v), v < 0 && (v = 0)), t < n.length && n.charAt(t - 1) !== " " && n.charAt(t) !== " " && (t = n.lastIndexOf(" ", t), t < z ? t = z : ++t)), n = (v ? d : "") + n.substring(v, t) + (t < n.length ? d : ""); } else { - A = []; + z = []; C = {}; r = {}; y = {}; F = {}; D = {}; - L = K = E = 0; - for (W = Q = 1;;) { + L = J = E = 0; + for (W = R = 1;;) { var O = void 0; for (let q = 0, G; q < ja.length; q++) { G = ja[q]; if (L) { - if (K !== L) { + if (J !== L) { if (y[q + 1]) { continue; } @@ -633,27 +633,27 @@ function Ba(a, c, b, e, d, f, g, h) { } E -= x; } - m = t[G].text; + n = t[G].text; if (H = p && D[q]) { if (H > 0) { - if (m.length > H) { - if (y[q + 1] = 1, n) { - m = m.substring(0, H); + if (n.length > H) { + if (y[q + 1] = 1, m) { + n = n.substring(0, H); } else { continue; } } - (H -= m.length) || (H = -1); + (H -= n.length) || (H = -1); D[q] = H; } else { y[q + 1] = 1; continue; } } - if (E + m.length + 1 <= k) { - m = " " + m, A[q] += m; - } else if (n) { - O = k - E - 1, O > 0 && (m = " " + m.substring(0, O), A[q] += m), y[q + 1] = 1; + if (E + n.length + 1 <= h) { + n = " " + n, z[q] += n; + } else if (m) { + O = h - E - 1, O > 0 && (n = " " + n.substring(0, O), z[q] += n), y[q + 1] = 1; } else { y[q + 1] = 1; continue; @@ -662,7 +662,7 @@ function Ba(a, c, b, e, d, f, g, h) { if (y[q]) { continue; } - G -= K; + G -= J; if (C[G]) { E -= x; y[q] = 1; @@ -677,34 +677,34 @@ function Ba(a, c, b, e, d, f, g, h) { } E -= x; } - m = t[G].text; + n = t[G].text; if (H = u && F[q]) { if (H > 0) { - if (m.length > H) { - if (y[q] = 1, n) { - m = m.substring(m.length - H); + if (n.length > H) { + if (y[q] = 1, m) { + n = n.substring(n.length - H); } else { continue; } } - (H -= m.length) || (H = -1); + (H -= n.length) || (H = -1); F[q] = H; } else { y[q] = 1; continue; } } - if (E + m.length + 1 <= k) { - m += " ", A[q] = m + A[q]; - } else if (n) { - O = m.length + 1 - (k - E), O >= 0 && O < m.length && (m = m.substring(O) + " ", A[q] = m + A[q]), y[q] = 1; + if (E + n.length + 1 <= h) { + n += " ", z[q] = n + z[q]; + } else if (m) { + O = n.length + 1 - (h - E), O >= 0 && O < n.length && (n = n.substring(O) + " ", z[q] = n + z[q]), y[q] = 1; } else { y[q] = 1; continue; } } } else { - m = t[G].match; + n = t[G].match; u && (F[q] = u); p && (D[q] = p); q && E++; @@ -712,36 +712,36 @@ function Ba(a, c, b, e, d, f, g, h) { G ? !q && x && (E += x) : (r[q] = 1, y[q] = 1); G >= v.length - 1 ? ua = 1 : G < t.length - 1 && t[G + 1].match ? ua = 1 : x && (E += x); E -= f.length - 2; - if (!q || E + m.length <= k) { - A[q] = m; + if (!q || E + n.length <= h) { + z[q] = n; } else { - O = Q = W = r[q] = 0; + O = R = W = r[q] = 0; break; } ua && (r[q + 1] = 1, y[q + 1] = 1); } - E += m.length; + E += n.length; O = C[G] = 1; } if (O) { - K === L ? L++ : K++; + J === L ? L++ : J++; } else { - K === L ? Q = 0 : W = 0; - if (!Q && !W) { + J === L ? R = 0 : W = 0; + if (!R && !W) { break; } - Q ? (K++, L = K) : L++; + R ? (J++, L = J) : L++; } } - m = ""; - for (let q = 0, G; q < A.length; q++) { - G = (q && r[q] ? " " : (q && !d ? " " : "") + d) + A[q], m += G; + n = ""; + for (let q = 0, G; q < z.length; q++) { + G = (q && r[q] ? " " : (q && !d ? " " : "") + d) + z[q], n += G; } - d && !r[A.length] && (m += d); + d && !r[z.length] && (n += d); } } - l && (m = m.replace(l, " ")); - da[ia].highlight = m; + l && (n = n.replace(l, " ")); + da[ia].highlight = n; } if (e) { break; @@ -764,33 +764,33 @@ function Ba(a, c, b, e, d, f, g, h) { } ;M(); X.prototype.search = function(a, c, b, e) { - b || (!c && R(a) ? (b = a, a = "") : R(c) && (b = c, c = 0)); + b || (!c && Q(a) ? (b = a, a = "") : Q(c) && (b = c, c = 0)); let d = []; var f = []; let g; - let h, k, n, l; - let z = 0, x = !0, u; + let k, h, m, l; + let A = 0, x = !0, u; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var p = b.pluck; var w = b.merge; - n = p || b.field || (n = b.index) && (n.index ? null : n); + m = p || b.field || (m = b.index) && (m.index ? null : m); l = this.tag && b.tag; - h = b.suggest; + k = b.suggest; x = !0; - k = b.cache; + h = b.cache; this.store && b.highlight && !x ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !x && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); u = x && this.store && b.highlight; g = !!u || x && this.store && b.enrich; c = b.limit || c; - var m = b.offset || 0; + var n = b.offset || 0; c || (c = x ? 100 : 0); if (l) { l.constructor !== Array && (l = [l]); var v = []; - for (let A = 0, r; A < l.length; A++) { - r = l[A]; + for (let z = 0, r; z < l.length; z++) { + r = l[z]; if (P(r)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } @@ -824,36 +824,36 @@ X.prototype.search = function(a, c, b, e) { f = []; if (v.length) { for (p = 0; p < v.length; p += 2) { - w = Ga.call(this, v[p], v[p + 1], c, m, g), d.push({field:v[p], tag:v[p + 1], result:w}); + w = Ga.call(this, v[p], v[p + 1], c, n, g), d.push({field:v[p], tag:v[p + 1], result:w}); } } - return f.length ? Promise.all(f).then(function(A) { - for (let r = 0; r < A.length; r++) { - d[r].result = A[r]; + return f.length ? Promise.all(f).then(function(z) { + for (let r = 0; r < z.length; r++) { + d[r].result = z[r]; } return d; }) : d; } } - n && n.constructor !== Array && (n = [n]); + m && m.constructor !== Array && (m = [m]); } - n || (n = this.field); + m || (m = this.field); v = !1; - for (let A = 0, r, y, F; A < n.length; A++) { - y = n[A]; + for (let z = 0, r, y, F; z < m.length; z++) { + y = m[z]; let D; - P(y) || (D = y, y = D.field, a = D.query || a, c = J(D.limit, c), m = J(D.offset, m), h = J(D.suggest, h), u = x && this.store && J(D.highlight, u), g = !!u || x && this.store && J(D.enrich, g), k = J(D.cache, k)); + P(y) || (D = y, y = D.field, a = D.query || a, c = K(D.limit, c), n = K(D.offset, n), k = K(D.suggest, k), u = x && this.store && K(D.highlight, u), g = !!u || x && this.store && K(D.enrich, g), h = K(D.cache, h)); if (e) { - r = e[A]; + r = e[z]; } else { t = D || b || {}; C = t.enrich; const E = this.index.get(y); l && C && (t.enrich = !1); - r = k ? E.searchCache(a, c, t) : E.search(a, c, t); + r = h ? E.searchCache(a, c, t) : E.search(a, c, t); C && (t.enrich = C); if (v) { - v[A] = r; + v[z] = r; continue; } } @@ -861,71 +861,71 @@ X.prototype.search = function(a, c, b, e) { if (l && F) { t = []; C = 0; - for (let E = 0, K, L; E < l.length; E += 2) { - K = this.tag.get(l[E]); - if (!K) { - if (console.warn("Tag '" + l[E] + ":" + l[E + 1] + "' will be skipped because there is no field '" + l[E] + "'."), h) { + for (let E = 0, J, L; E < l.length; E += 2) { + J = this.tag.get(l[E]); + if (!J) { + if (console.warn("Tag '" + l[E] + ":" + l[E + 1] + "' will be skipped because there is no field '" + l[E] + "'."), k) { continue; } else { return d; } } - if (L = (K = K && K.get(l[E + 1])) && K.length) { - C++, t.push(K); - } else if (!h) { + if (L = (J = J && J.get(l[E + 1])) && J.length) { + C++, t.push(J); + } else if (!k) { return d; } } if (C) { r = Fa(r, t); F = r.length; - if (!F && !h) { + if (!F && !k) { return r; } C--; } } if (F) { - f[z] = y, d.push(r), z++; - } else if (n.length === 1) { + f[A] = y, d.push(r), A++; + } else if (m.length === 1) { return d; } } if (v) { - const A = this; + const z = this; return Promise.all(v).then(function(r) { b && (b.resolve = x); - r.length && (r = A.search(a, c, b, r)); + r.length && (r = z.search(a, c, b, r)); return r; }); } - if (!z) { + if (!A) { return d; } if (p && (!g || !this.store)) { return d = d[0]; } v = []; - for (m = 0; m < f.length; m++) { - e = d[m]; + for (n = 0; n < f.length; n++) { + e = d[n]; g && e.length && typeof e[0].doc === "undefined" && (e = Ha.call(this, e)); if (p) { return u ? Ea(a, e, this.index, p, u) : e; } - d[m] = {field:f[m], result:e}; + d[n] = {field:f[n], result:e}; } u && (d = Ea(a, d, this.index, p, u)); return w ? Ia(d) : d; }; function Ia(a) { const c = [], b = M(), e = M(); - for (let d = 0, f, g, h, k, n, l, z; d < a.length; d++) { + for (let d = 0, f, g, k, h, m, l, A; d < a.length; d++) { f = a[d]; g = f.field; - h = f.result; - for (let x = 0; x < h.length; x++) { - if (n = h[x], typeof n !== "object" ? n = {id:k = n} : k = n.id, (l = b[k]) ? l.push(g) : (n.field = b[k] = [g], c.push(n)), z = n.highlight) { - l = e[k], l || (e[k] = l = {}, n.highlight = l), l[g] = z; + k = f.result; + for (let x = 0; x < k.length; x++) { + if (m = k[x], typeof m !== "object" ? m = {id:h = m} : h = m.id, (l = b[h]) ? l.push(g) : (m.field = b[h] = [g], c.push(m)), A = m.highlight) { + l = e[h], l || (e[h] = l = {}, m.highlight = l), l[g] = A; } } } @@ -979,7 +979,7 @@ function Ha(a) { let e = c.index || c.field || c; P(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], P(f) || (g = f, f = f.field), g = R(g) ? Object.assign({}, a, g) : a, b.set(f, new Y(g, this.reg)), g.custom ? this.B[d] = g.custom : (this.B[d] = Ja(f, this.C), g.filter && (typeof this.B[d] === "string" && (this.B[d] = new String(this.B[d])), this.B[d].F = g.filter)), this.field[d] = f; + f = e[d], P(f) || (g = f, f = f.field), g = Q(g) ? Object.assign({}, a, g) : a, b.set(f, new Y(g, this.reg)), g.custom ? this.B[d] = g.custom : (this.B[d] = Ja(f, this.C), g.filter && (typeof this.B[d] === "string" && (this.B[d] = new String(this.B[d])), this.B[d].F = g.filter)), this.field[d] = f; } if (this.h) { a = c.store; @@ -1025,7 +1025,7 @@ B.update = function(a, c) { return this.remove(a).add(a, c); }; B.remove = function(a) { - R(a) && (a = aa(a, this.key)); + Q(a) && (a = aa(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1129,26 +1129,26 @@ function Sa(a, c) { return c; } function Ta(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { return this.export(a, c, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { - const n = this; - return k.then(function() { - return Ta.call(n, a, c, b, h ? e : null, d, f, g + 1); + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { + const m = this; + return h.then(function() { + return Ta.call(m, a, c, b, k ? e : null, d, f, g + 1); }); } - return Ta.call(this, a, c, b, h ? e : null, d, f, g + 1); + return Ta.call(this, a, c, b, k ? e : null, d, f, g + 1); } function La(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const h = this; + const k = this; return c.then(function() { - return h.export(a, g, b + 1); + return k.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -1207,14 +1207,14 @@ function Ua(a, c) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, h; g < d.length; g++) { - h = d[g] || [""]; - let k = ""; - for (let n = 0; n < h.length; n++) { - k += (k ? "," : "") + (c === "string" ? '"' + h[n] + '"' : h[n]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let m = 0; m < k.length; m++) { + h += (h ? "," : "") + (c === "string" ? '"' + k[m] + '"' : k[m]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; b += (b ? "," : "") + f; @@ -1247,7 +1247,7 @@ function Va(a, c) { let b = 0; var e = typeof c === "undefined"; if (a.constructor === Array) { - for (let d = 0, f, g, h; d < a.length; d++) { + for (let d = 0, f, g, k; d < a.length; d++) { if ((f = a[d]) && f.length) { if (e) { return 1; @@ -1261,9 +1261,9 @@ function Va(a, c) { if (b) { return 1; } - h = 1; + k = 1; } else { - if (h) { + if (k) { return 1; } b++; @@ -1285,32 +1285,32 @@ Y.prototype.add = function(a, c, b, e) { } e = this.depth; c = this.encoder.encode(c, !e); - const n = c.length; - if (n) { - const l = M(), z = M(), x = this.resolution; - for (let u = 0; u < n; u++) { - let p = c[this.rtl ? n - 1 - u : u]; + const m = c.length; + if (m) { + const l = M(), A = M(), x = this.resolution; + for (let u = 0; u < m; u++) { + let p = c[this.rtl ? m - 1 - u : u]; var d = p.length; - if (d && (e || !z[p])) { - var f = this.score ? this.score(c, p, u, null, 0) : Xa(x, n, u), g = ""; + if (d && (e || !A[p])) { + var f = this.score ? this.score(c, p, u, null, 0) : Xa(x, m, u), g = ""; switch(this.tokenize) { case "tolerant": - Z(this, z, p, f, a, b); + Z(this, A, p, f, a, b); if (d > 2) { - for (let w = 1, m, v, t, C; w < d - 1; w++) { - m = p.charAt(w), v = p.charAt(w + 1), t = p.substring(0, w) + v, C = p.substring(w + 2), g = t + m + C, z[g] || Z(this, z, g, f, a, b), g = t + C, z[g] || Z(this, z, g, f, a, b); + for (let w = 1, n, v, t, C; w < d - 1; w++) { + n = p.charAt(w), v = p.charAt(w + 1), t = p.substring(0, w) + v, C = p.substring(w + 2), g = t + n + C, Z(this, A, g, f, a, b), g = t + C, Z(this, A, g, f, a, b); } + Z(this, A, p.substring(0, p.length - 1), f, a, b); } break; case "full": if (d > 2) { - for (let w = 0, m; w < d; w++) { + for (let w = 0, n; w < d; w++) { for (f = d; f > w; f--) { - if (g = p.substring(w, f), !z[g]) { - m = this.rtl ? d - 1 - w : w; - var h = this.score ? this.score(c, p, u, g, m) : Xa(x, n, u, d, m); - Z(this, z, g, h, a, b); - } + g = p.substring(w, f); + n = this.rtl ? d - 1 - w : w; + var k = this.score ? this.score(c, p, u, g, n) : Xa(x, m, u, d, n); + Z(this, A, g, k, a, b); } } break; @@ -1318,29 +1318,27 @@ Y.prototype.add = function(a, c, b, e) { case "bidirectional": case "reverse": if (d > 1) { - for (h = d - 1; h > 0; h--) { - if (g = p[this.rtl ? d - 1 - h : h] + g, !z[g]) { - var k = this.score ? this.score(c, p, u, g, h) : Xa(x, n, u, d, h); - Z(this, z, g, k, a, b); - } + for (k = d - 1; k > 0; k--) { + g = p[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, p, u, g, k) : Xa(x, m, u, d, k); + Z(this, A, g, h, a, b); } g = ""; } case "forward": if (d > 1) { - for (h = 0; h < d; h++) { - g += p[this.rtl ? d - 1 - h : h], z[g] || Z(this, z, g, f, a, b); + for (k = 0; k < d; k++) { + g += p[this.rtl ? d - 1 - k : k], Z(this, A, g, f, a, b); } break; } default: - if (Z(this, z, p, f, a, b), e && n > 1 && u < n - 1) { - for (d = M(), g = this.L, f = p, h = Math.min(e + 1, this.rtl ? u + 1 : n - u), d[f] = 1, k = 1; k < h; k++) { - if ((p = c[this.rtl ? n - 1 - u - k : u + k]) && !d[p]) { - d[p] = 1; - const w = this.score ? this.score(c, f, u, p, k - 1) : Xa(g + (n / 2 > g ? 0 : 1), n, u, h - 1, k - 1), m = this.bidirectional && p > f; - Z(this, l, m ? f : p, w, a, b, m ? p : f); - } + if (Z(this, A, p, f, a, b), e && m > 1 && u < m - 1) { + for (d = this.L, g = p, f = Math.min(e + 1, this.rtl ? u + 1 : m - u), k = 1; k < f; k++) { + p = c[this.rtl ? m - 1 - u - k : u + k]; + h = this.bidirectional && p > g; + const w = this.score ? this.score(c, g, u, p, k - 1) : Xa(d + (m / 2 > d ? 0 : 1), m, u, f - 1, k - 1); + Z(this, l, h ? g : p, w, a, b, h ? p : g); } } } @@ -1352,9 +1350,25 @@ Y.prototype.add = function(a, c, b, e) { return this; }; function Z(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - g ? (c = k || (c[b] = M()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); + let k, h; + if (!(k = c[b]) || g && !k[g]) { + g ? (c = k || (c[b] = M()), c[g] = 1, h = a.ctx, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : (h = a.map, c[b] = 1); + (k = h.get(b)) ? h = k : h.set(b, h = k = []); + if (f) { + for (let m = 0, l; m < k.length; m++) { + if ((l = k[m]) && l.includes(d)) { + if (m <= e) { + return; + } + l.splice(l.indexOf(d), 1); + a.fastupdate && (c = a.reg.get(d)) && c.splice(c.indexOf(l), 1); + break; + } + } + } + h = h[e] || (h[e] = []); + h.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h])); } } function Xa(a, c, b, e, d) { @@ -1372,53 +1386,53 @@ function Xa(a, c, b, e, d) { d = b.offset || 0; var f = b.context; var g = b.suggest; - var h = !0; - var k = b.resolution; + var k = !0; + var h = b.resolution; } - typeof h === "undefined" && (h = !0); + typeof k === "undefined" && (k = !0); f = this.depth && f !== !1; b = this.encoder.encode(a, !f); a = b.length; - c = c || (h ? 100 : 0); + c = c || (k ? 100 : 0); if (a === 1) { return g = d, (d = Ya(this, b[0], "")) && d.length ? Da.call(this, d, c, g) : []; } if (a === 2 && f && !g) { return g = d, (d = Ya(this, b[1], b[0])) && d.length ? Da.call(this, d, c, g) : []; } - h = M(); - var n = 0; + k = M(); + var m = 0; if (f) { var l = b[0]; - n = 1; + m = 1; } - k || k === 0 || (k = l ? this.L : this.resolution); - for (let p, w; n < a; n++) { - if ((w = b[n]) && !h[w]) { - h[w] = 1; + h || h === 0 || (h = l ? this.L : this.resolution); + for (let p, w; m < a; m++) { + if ((w = b[m]) && !k[w]) { + k[w] = 1; p = Ya(this, w, l); a: { f = p; - var z = e, x = g, u = k; - let m = []; + var A = e, x = g, u = h; + let n = []; if (f && f.length) { if (f.length <= u) { - z.push(f); + A.push(f); p = void 0; break a; } for (let v = 0, t; v < u; v++) { if (t = f[v]) { - m[v] = t; + n[v] = t; } } - if (m.length) { - z.push(m); + if (n.length) { + A.push(n); p = void 0; break a; } } - p = x ? void 0 : m; + p = x ? void 0 : n; } if (p) { e = p; @@ -1426,7 +1440,7 @@ function Xa(a, c, b, e, d) { } l && (g && p && e.length || (l = w)); } - g && l && n === a - 1 && !e.length && (k = this.resolution, l = "", n = -1, h = M()); + g && l && m === a - 1 && !e.length && (h = this.resolution, l = "", m = -1, k = M()); } a: { b = e; @@ -1438,11 +1452,11 @@ function Xa(a, c, b, e, d) { l = b.length; g = []; a = M(); - for (let p = 0, w, m, v, t; p < k; p++) { - for (n = 0; n < l; n++) { - if (v = b[n], p < v.length && (w = v[p])) { + for (let p = 0, w, n, v, t; p < h; p++) { + for (m = 0; m < l; m++) { + if (v = b[m], p < v.length && (w = v[p])) { for (f = 0; f < w.length; f++) { - if (m = w[f], (h = a[m]) ? a[m]++ : (h = 0, a[m] = 1), t = g[h] || (g[h] = []), t.push(m), c && h === l - 1 && t.length - d === c) { + if (n = w[f], (k = a[n]) ? a[n]++ : (k = 0, a[n] = 1), t = g[k] || (g[k] = []), t.push(n), c && k === l - 1 && t.length - d === c) { l = d ? t.slice(d) : t; break b; } @@ -1454,11 +1468,11 @@ function Xa(a, c, b, e, d) { if (e) { if (g.length > 1) { c: { - for (b = [], k = M(), e = g.length, h = e - 1; h >= 0; h--) { - if (a = (e = g[h]) && e.length) { - for (n = 0; n < a; n++) { - if (l = e[n], !k[l]) { - if (k[l] = 1, d) { + for (b = [], h = M(), e = g.length, k = e - 1; k >= 0; k--) { + if (a = (e = g[k]) && e.length) { + for (m = 0; m < a; m++) { + if (l = e[m], !h[l]) { + if (h[l] = 1, d) { d--; } else { if (b.push(l), b.length === c) { @@ -1610,10 +1624,10 @@ B.serialize = function(a = !0) { b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let h = Ua(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + d + '",' + h + "]"; - e += (e ? "," : "") + h; + let k = Ua(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index 9c5bd02..7affa1b 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -1,12 +1,12 @@ /**! - * FlexSearch.js v0.8.203 (Bundle) + * FlexSearch.js v0.8.205 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';var B;function I(a,c,b){const e=typeof b,d=typeof a;if(e!=="undefined"){if(d!=="undefined"){if(b){if(d==="function"&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return d==="undefined"?c:a}function J(a,c){return typeof a==="undefined"?c:a}function N(){return Object.create(null)} -function P(a){return typeof a==="string"}function R(a){return typeof a==="object"}function aa(a,c){if(P(c))a=a[c];else for(let b=0;a&&b1)return this.addMatcher(a,c);this.mapper||(this.mapper=new Map);this.mapper.set(a,c);this.cache&&S(this);return this};B.addMatcher=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.I=null;this.cache&&S(this);return this}; B.addReplacer=function(a,c){if(typeof a==="string")return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&S(this);return this}; B.encode=function(a,c){if(this.cache&&a.length<=this.G)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(S,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=ka?a.normalize("NFKD").replace(ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(fa,"$1 $2").replace(ha,"$1 $2").replace(ea,"$1 "));const b=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let e= -[],d=N(),f,g,h=this.split||this.split===""?a.split(this.split):[a];for(let n=0,l,z;nthis.maxlength)){if(c){if(d[l])continue;d[l]=1}else{if(f===l)continue;f=l}if(b)e.push(l);else if(!this.filter||(typeof this.filter==="function"?this.filter(l):!this.filter.has(l))){if(this.cache&&l.length<=this.H)if(this.D){var k=this.C.get(l);if(k||k===""){k&&e.push(k);continue}}else this.D=setTimeout(S,50,this);if(this.stemmer){this.J||(this.J=new RegExp("(?!^)("+ -this.A+")$"));let x;for(;x!==l&&l.length>2;)x=l,l=l.replace(this.J,u=>this.stemmer.get(u))}if(l&&(this.mapper||this.dedupe&&l.length>1)){k="";for(let x=0,u="",p,w;x1&&(this.I||(this.I=new RegExp("("+this.h+")","g")),l=l.replace(this.I,x=>this.matcher.get(x)));if(l&&this.replacer)for(k=0;l&&kthis.K&&(this.C.clear(),this.H=this.H/1.1|0));if(l){if(l!==z)if(c){if(d[l])continue;d[l]=1}else{if(g===l)continue;g=l}e.push(l)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.G&&(this.B.set(a,e),this.B.size>this.K&&(this.B.clear(),this.G=this.G/1.1|0));return e};function S(a){a.D=null;a.B.clear();a.C.clear()};function ma(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):b=a);b&&(a=b.query||a,c=b.limit||c);let e=""+(c||0);b&&(e+=(b.offset||0)+!!b.context+!!b.suggest+(b.resolve!==!1)+(b.resolution||this.resolution)+(b.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new T);let d=this.cache.get(a+e);if(!d){const f=b&&b.cache;f&&(b.cache=!1);d=this.search(a,c,b);f&&(b.cache=f);this.cache.set(a+e,d)}return d}function T(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""} +[],d=N(),f,g,k=this.split||this.split===""?a.split(this.split):[a];for(let m=0,l,A;mthis.maxlength)){if(c){if(d[l])continue;d[l]=1}else{if(f===l)continue;f=l}if(b)e.push(l);else if(!this.filter||(typeof this.filter==="function"?this.filter(l):!this.filter.has(l))){if(this.cache&&l.length<=this.H)if(this.D){var h=this.C.get(l);if(h||h===""){h&&e.push(h);continue}}else this.D=setTimeout(S,50,this);if(this.stemmer){this.J||(this.J=new RegExp("(?!^)("+ +this.A+")$"));let x;for(;x!==l&&l.length>2;)x=l,l=l.replace(this.J,u=>this.stemmer.get(u))}if(l&&(this.mapper||this.dedupe&&l.length>1)){h="";for(let x=0,u="",p,w;x1&&(this.I||(this.I=new RegExp("("+this.h+")","g")),l=l.replace(this.I,x=>this.matcher.get(x)));if(l&&this.replacer)for(h=0;l&&hthis.K&&(this.C.clear(),this.H=this.H/1.1|0));if(l){if(l!==A)if(c){if(d[l])continue;d[l]=1}else{if(g===l)continue;g=l}e.push(l)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.G&&(this.B.set(a,e),this.B.size>this.K&&(this.B.clear(),this.G=this.G/1.1|0));return e};function S(a){a.D=null;a.B.clear();a.C.clear()};function ma(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):b=a);b&&(a=b.query||a,c=b.limit||c);let e=""+(c||0);b&&(e+=(b.offset||0)+!!b.context+!!b.suggest+(b.resolve!==!1)+(b.resolution||this.resolution)+(b.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new T);let d=this.cache.get(a+e);if(!d){const f=b&&b.cache;f&&(b.cache=!1);d=this.search(a,c,b);f&&(b.cache=f);this.cache.set(a+e,d)}return d}function T(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""} T.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)};T.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};T.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};T.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:!1,numeric:!1,dedupe:!1};const oa={};const pa=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 qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const sa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var va={Exact:na,Default:oa,Normalize:oa,LatinBalance:{mapper:pa},LatinAdvanced:{mapper:pa,matcher:qa,replacer:ra},LatinExtra:{mapper:pa,replacer:ra.concat([/(?!^)[aeo]/g,""]),matcher:qa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;b=this.priority*this.priority*3):(xa=setTimeout(Aa,0),ya=Date.now());if(za){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};X.prototype.add=function(a,c,b){R(a)&&(c=a,a=aa(c,this.key));if(c&&(a||a===0)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hc?a.slice(b,b+c):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}f=f.slice(b,b+c);g=f.length;b=0}g>c&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=e.length>1?[].concat.apply([],e):e[0]};function Ea(a,c,b,e,d){let f,g,h;typeof d==="string"?(f=d,d=""):f=d.template;g=f.indexOf("$1");h=f.substring(g+2);g=f.substring(0,g);let k=d&&d.boundary,n=!d||d.clip!==!1,l=d&&d.merge&&h&&g&&new RegExp(h+" "+g,"g");d=d&&d.ellipsis;var z=0;if(typeof d==="object"){var x=d.template;z=x.length-2;d=d.pattern}typeof d!=="string"&&(d=d===!1?"":"...");z&&(d=x.replace("$1",d));x=d.length-z;let u,p;typeof k==="object"&&(u=k.before,u===0&&(u=-1),p=k.after,p===0&&(p=-1),k=k.total||9E5);z=new Map;for(let ta=0, -V,Ka,ca;ta1?D.join(" "):D[0];let q;if(D&&E){var F=E.length,K=(V.split?E.replace(V.split, -""):E).length-D.length,L="",Q=0;for(var W=0;W-1&&(L=(M?E.substring(0,M):"")+g+E.substring(M,M+H)+h+(M+H=k)break}t=ja.length*(f.length-2);if(u||p||k&&m.length-t>k)if(t=k+t-x*2,y=A-C,u>0&&(y+=u),p>0&&(y+=p), -y<=t)v=u?C-(u>0?u:0):C-((t-y)/2|0),r=p?A+(p>0?p:0):v+t,n||(v>0&&m.charAt(v)!==" "&&m.charAt(v-1)!==" "&&(v=m.indexOf(" ",v),v<0&&(v=0)),r=r.length-1){if(G>=r.length){y[q+1]= -1;G>=v.length&&(t[q+1]=1);continue}F-=x}m=r[G].text;if(H=p&&D[q])if(H>0){if(m.length>H)if(y[q+1]=1,n)m=m.substring(0,H);else continue;(H-=m.length)||(H=-1);D[q]=H}else{y[q+1]=1;continue}if(F+m.length+1<=k)m=" "+m,A[q]+=m;else if(n)O=k-F-1,O>0&&(m=" "+m.substring(0,O),A[q]+=m),y[q+1]=1;else{y[q+1]=1;continue}}else{if(y[q])continue;G-=K;if(C[G]){F-=x;y[q]=1;t[q]=1;continue}if(G<=0){if(G<0){y[q]=1;t[q]=1;continue}F-=x}m=r[G].text;if(H=u&&E[q])if(H>0){if(m.length>H)if(y[q]=1,n)m=m.substring(m.length- -H);else continue;(H-=m.length)||(H=-1);E[q]=H}else{y[q]=1;continue}if(F+m.length+1<=k)m+=" ",A[q]=m+A[q];else if(n)O=m.length+1-(k-F),O>=0&&O=v.length-1?ua=1:G0){if(b&&c>b||e)a=a.slice(e,e+b);d&&(a=Ha.call(this,a))}return a}function Ha(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;b=this.priority*this.priority*3):(xa=setTimeout(Aa,0),ya=Date.now());if(za){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};X.prototype.add=function(a,c,b){Q(a)&&(c=a,a=aa(c,this.key));if(c&&(a||a===0)){if(!b&&this.reg.has(a))return this.update(a,c);for(let k=0,h;kc?a.slice(b,b+c):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}f=f.slice(b,b+c);g=f.length;b=0}g>c&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=e.length>1?[].concat.apply([],e):e[0]};function Ea(a,c,b,e,d){let f,g,k;typeof d==="string"?(f=d,d=""):f=d.template;g=f.indexOf("$1");k=f.substring(g+2);g=f.substring(0,g);let h=d&&d.boundary,m=!d||d.clip!==!1,l=d&&d.merge&&k&&g&&new RegExp(k+" "+g,"g");d=d&&d.ellipsis;var A=0;if(typeof d==="object"){var x=d.template;A=x.length-2;d=d.pattern}typeof d!=="string"&&(d=d===!1?"":"...");A&&(d=x.replace("$1",d));x=d.length-A;let u,p;typeof h==="object"&&(u=h.before,u===0&&(u=-1),p=h.after,p===0&&(p=-1),h=h.total||9E5);A=new Map;for(let ta=0, +V,Ka,ca;ta1?D.join(" "):D[0];let q;if(D&&E){var F=E.length,J=(V.split?E.replace(V.split, +""):E).length-D.length,L="",R=0;for(var W=0;W-1&&(L=(M?E.substring(0,M):"")+g+E.substring(M,M+H)+k+(M+H=h)break}t=ja.length*(f.length-2);if(u||p||h&&n.length-t>h)if(t=h+t-x*2,y=z-C,u>0&&(y+=u),p>0&&(y+=p), +y<=t)v=u?C-(u>0?u:0):C-((t-y)/2|0),r=p?z+(p>0?p:0):v+t,m||(v>0&&n.charAt(v)!==" "&&n.charAt(v-1)!==" "&&(v=n.indexOf(" ",v),v<0&&(v=0)),r=r.length-1){if(G>=r.length){y[q+1]= +1;G>=v.length&&(t[q+1]=1);continue}F-=x}n=r[G].text;if(H=p&&D[q])if(H>0){if(n.length>H)if(y[q+1]=1,m)n=n.substring(0,H);else continue;(H-=n.length)||(H=-1);D[q]=H}else{y[q+1]=1;continue}if(F+n.length+1<=h)n=" "+n,z[q]+=n;else if(m)O=h-F-1,O>0&&(n=" "+n.substring(0,O),z[q]+=n),y[q+1]=1;else{y[q+1]=1;continue}}else{if(y[q])continue;G-=J;if(C[G]){F-=x;y[q]=1;t[q]=1;continue}if(G<=0){if(G<0){y[q]=1;t[q]=1;continue}F-=x}n=r[G].text;if(H=u&&E[q])if(H>0){if(n.length>H)if(y[q]=1,m)n=n.substring(n.length- +H);else continue;(H-=n.length)||(H=-1);E[q]=H}else{y[q]=1;continue}if(F+n.length+1<=h)n+=" ",z[q]=n+z[q];else if(m)O=n.length+1-(h-F),O>=0&&O=v.length-1?ua=1:G0){if(b&&c>b||e)a=a.slice(e,e+b);d&&(a=Ha.call(this,a))}return a}function Ha(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;b1?b:b[0]}B=X.prototype;B.append=function(a,c){return this.add(a,c,!0)};B.update=function(a,c){return this.remove(a).add(a,c)}; -B.remove=function(a){R(a)&&(a=aa(a,this.key));for(var c of this.index.values())c.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(let b of this.tag.values())for(let e of b){c=e[0];const d=e[1],f=d.indexOf(a);f>-1&&(d.length>1?d.splice(f,1):b.delete(c))}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +B.remove=function(a){Q(a)&&(a=aa(a,this.key));for(var c of this.index.values())c.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(let b of this.tag.values())for(let e of b){c=e[0];const d=e[1],f=d.indexOf(a);f>-1&&(d.length>1?d.splice(f,1):b.delete(c))}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; B.clear=function(){const a=[];for(const c of this.index.values()){const b=c.clear();b.then&&a.push(b)}if(this.tag)for(const c of this.tag.values())c.clear();this.store&&this.store.clear();this.cache&&this.cache.clear();return a.length?Promise.all(a):this};B.contain=function(a){return this.reg.has(a)};B.cleanup=function(){for(const a of this.index.values())a.cleanup();return this};B.get=function(a){return this.store.get(a)||null}; B.set=function(a,c){typeof a==="object"&&(c=a,a=aa(c,this.key));this.store.set(a,c);return this};B.searchCache=ma;B.export=La;B.import=Ma;wa(X.prototype);function Na(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function Oa(a,c){c||(c=new Map);for(let b=0,e;b2?b[0]:"";b=b.length>2?b[2]:b[1];if(c){typeof c==="string"&&(c=JSON.parse(c));if(a)return this.index.get(a).import(b,c);switch(b){case "reg":this.fastupdate=!1;this.reg=Sa(c,this.reg);for(let e=0,d;e=0&&d.splice(g,1)}}else Va(this.map,a),this.depth&&Va(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Va(a,c){let b=0;var e=typeof c==="undefined";if(a.constructor===Array)for(let d=0,f,g,h;d=0){if(f.length>1)return f.splice(g,1),1;delete a[d];if(b)return 1;h=1}else{if(h)return 1;b++}}}else for(let d of a.entries())e=d[0],Va(d[1],c)?b++:a.delete(e);return b};const Wa={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};Y.prototype.add=function(a,c,b,e){if(c&&(a||a===0)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);e=this.depth;c=this.encoder.encode(c,!e);const n=c.length;if(n){const l=N(),z=N(),x=this.resolution;for(let u=0;u2)for(let w=1,m,v,r,C;w2){for(let w=0,m;ww;f--)if(g=p.substring(w,f),!z[g]){m=this.rtl?d-1-w:w;var h=this.score?this.score(c,p,u,g,m):Xa(x,n,u,d,m);Z(this,z,g,h,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(h=d-1;h>0;h--)if(g=p[this.rtl?d-1-h:h]+g,!z[g]){var k=this.score?this.score(c,p,u,g,h):Xa(x,n,u,d,h);Z(this,z,g,k,a,b)}g=""}case "forward":if(d>1){for(h=0;h1&&ug?0:1),n,u,h-1,k-1),m=this.bidirectional&&p>f;Z(this,l,m?f:p,w,a,b,m?p:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=N()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Xa(a,c,b,e,d){return b&&a>1?c+(e||0)<=a?b+(d||0):(a-1)/(c+(e||0))*(b+(d||0))+1|0:0};Y.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));if(b&&b.cache)return b.cache=!1,c=this.searchCache(a,c,b),b.cache=!0,c;var e=[],d=0;if(b){a=b.query||a;c=b.limit||c;d=b.offset||0;var f=b.context;var g=b.suggest;var h=!0;var k=b.resolution}typeof h==="undefined"&&(h=!0);f=this.depth&&f!==!1;b=this.encoder.encode(a,!f);a=b.length;c=c||(h?100:0);if(a===1)return g=d,(d=Ya(this,b[0],""))&&d.length?Da.call(this,d,c,g):[];if(a===2&&f&&!g)return g=d, -(d=Ya(this,b[1],b[0]))&&d.length?Da.call(this,d,c,g):[];h=N();var n=0;if(f){var l=b[0];n=1}k||k===0||(k=l?this.L:this.resolution);for(let p,w;n1)b:{e=g;l=b.length;g=[];a=N();for(let p=0,w,m,v,r;p1)c:for(b=[],k=N(),e=g.length,h=e-1;h>=0;h--){if(a=(e=g[h])&&e.length)for(n=0;nc||d?g.slice(d,c+d):g;g=b}else{if(b< +function Ua(a,c){let b="";for(const e of a.entries()){a=e[0];const d=e[1];let f="";for(let g=0,k;g=0&&d.splice(g,1)}}else Va(this.map,a),this.depth&&Va(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Va(a,c){let b=0;var e=typeof c==="undefined";if(a.constructor===Array)for(let d=0,f,g,k;d=0){if(f.length>1)return f.splice(g,1),1;delete a[d];if(b)return 1;k=1}else{if(k)return 1;b++}}}else for(let d of a.entries())e=d[0],Va(d[1],c)?b++:a.delete(e);return b};const Wa={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};Y.prototype.add=function(a,c,b,e){if(c&&(a||a===0)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);e=this.depth;c=this.encoder.encode(c,!e);const m=c.length;if(m){const l=N(),A=N(),x=this.resolution;for(let u=0;u2){for(let w=1,n,v,r,C;w2){for(let w=0,n;ww;f--){g=p.substring(w,f);n=this.rtl?d-1-w:w;var k=this.score?this.score(c,p,u,g,n):Xa(x,m,u,d,n);Z(this,A,g,k,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(k=d-1;k>0;k--){g=p[this.rtl?d-1-k:k]+g;var h=this.score?this.score(c,p,u,g,k):Xa(x,m,u,d,k);Z(this,A,g,h,a,b)}g=""}case "forward":if(d>1){for(k=0;k1&&ug;const w=this.score?this.score(c,g,u,p,k-1):Xa(d+(m/2>d?0:1),m,u,f-1,k-1);Z(this,l,h?g:p,w,a,b,h?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,c,b,e,d,f,g){let k,h;if(!(k=c[b])||g&&!k[g]){g?(c=k||(c[b]=N()),c[g]=1,h=a.ctx,(k=h.get(g))?h=k:h.set(g,h=new Map)):(h=a.map,c[b]=1);(k=h.get(b))?h=k:h.set(b,h=k=[]);if(f)for(let m=0,l;m1?c+(e||0)<=a?b+(d||0):(a-1)/(c+(e||0))*(b+(d||0))+1|0:0};Y.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));if(b&&b.cache)return b.cache=!1,c=this.searchCache(a,c,b),b.cache=!0,c;var e=[],d=0;if(b){a=b.query||a;c=b.limit||c;d=b.offset||0;var f=b.context;var g=b.suggest;var k=!0;var h=b.resolution}typeof k==="undefined"&&(k=!0);f=this.depth&&f!==!1;b=this.encoder.encode(a,!f);a=b.length;c=c||(k?100:0);if(a===1)return g=d,(d=Ya(this,b[0],""))&&d.length?Da.call(this,d,c,g):[];if(a===2&&f&&!g)return g=d, +(d=Ya(this,b[1],b[0]))&&d.length?Da.call(this,d,c,g):[];k=N();var m=0;if(f){var l=b[0];m=1}h||h===0||(h=l?this.L:this.resolution);for(let p,w;m1)b:{e=g;l=b.length;g=[];a=N();for(let p=0,w,n,v,r;p1)c:for(b=[],h=N(),e=g.length,k=e-1;k>=0;k--){if(a=(e=g[k])&&e.length)for(m=0;mc||d?g.slice(d,c+d):g;g=b}else{if(b< l){l=[];break b}g=g[b-1];if(c||d)if(g.length>c||d)g=g.slice(d,c+d)}l=g}else if(e===1){c=Da.call(null,b[0],c,d);break a}c=l}return c};function Ya(a,c,b){let e;b&&(e=a.bidirectional&&c>b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function Y(a,c){if(!this||this.constructor!==Y)return new Y(a);if(a){var b=P(a)?a:a.preset;b&&(a=Object.assign({},Wa[b],a))}else a={};b=a.context;const e=b===!0?{depth:1}:b||{},d=P(a.encoder)?va[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new la(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&b!=="default"&&b!=="exact"&&b||"strict";this.depth=b==="strict"&&e.depth||0;this.bidirectional=e.bidirectional!==!1;this.fastupdate=!!a.fastupdate; this.score=a.score||null;b=!1;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.L=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(b=a.cache||null)&&new T(b);this.priority=a.priority||4}B=Y.prototype;B.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};B.append=function(a,c){return this.add(a,c,!0)};B.contain=function(a){return this.reg.has(a)}; B.update=function(a,c){const b=this,e=this.remove(a);return e&&e.then?e.then(()=>b.add(a,c)):this.add(a,c)};B.cleanup=function(){if(!this.fastupdate)return this;Va(this.map);this.depth&&Va(this.ctx);return this};B.searchCache=ma;B.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=Ra(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=Na(this.map,this.reg.size);break;case 3:d="ctx";f=Pa(this.ctx,this.reg.size);break;default:return}return Ta.call(this,a,c,d,f,b,e)}; B.import=function(a,c){if(c)switch(typeof c==="string"&&(c=JSON.parse(c)),a=a.split("."),a[a.length-1]==="json"&&a.pop(),a.length===3&&a.shift(),a=a.length>1?a[1]:a[0],a){case "reg":this.fastupdate=!1;this.reg=Sa(c,this.reg);break;case "map":this.map=Oa(c,this.map);break;case "ctx":this.ctx=Qa(c,this.ctx)}}; -B.serialize=function(a=!0){let c="",b="",e="";if(this.reg.size){let f;for(var d of this.reg.keys())f||(f=typeof d),c+=(c?",":"")+(f==="string"?'"'+d+'"':d);c="index.reg=new Set(["+c+"]);";b=Ua(this.map,f);b="index.map=new Map(["+b+"]);";for(const g of this.ctx.entries()){d=g[0];let h=Ua(g[1],f);h="new Map(["+h+"])";h='["'+d+'",'+h+"]";e+=(e?",":"")+h}e="index.ctx=new Map(["+e+"]);"}return a?"function inject(index){"+c+b+e+"}":c+b+e};wa(Y.prototype);N();const Za={Index:Y,Charset:va,Encoder:la,Document:X,Worker:null,Resolver:null,IndexedDB:null,Language:{}},$a=typeof self!=="undefined"?self:typeof global!=="undefined"?global:self;let ab;(ab=$a.define)&&ab.amd?ab([],function(){return Za}):typeof $a.exports==="object"?$a.exports=Za:$a.FlexSearch=Za;}(this||self)); +B.serialize=function(a=!0){let c="",b="",e="";if(this.reg.size){let f;for(var d of this.reg.keys())f||(f=typeof d),c+=(c?",":"")+(f==="string"?'"'+d+'"':d);c="index.reg=new Set(["+c+"]);";b=Ua(this.map,f);b="index.map=new Map(["+b+"]);";for(const g of this.ctx.entries()){d=g[0];let k=Ua(g[1],f);k="new Map(["+k+"])";k='["'+d+'",'+k+"]";e+=(e?",":"")+k}e="index.ctx=new Map(["+e+"]);"}return a?"function inject(index){"+c+b+e+"}":c+b+e};wa(Y.prototype);N();const Za={Index:Y,Charset:va,Encoder:la,Document:X,Worker:null,Resolver:null,IndexedDB:null,Language:{}},$a=typeof self!=="undefined"?self:typeof global!=="undefined"?global:self;let ab;(ab=$a.define)&&ab.amd?ab([],function(){return Za}):typeof $a.exports==="object"?$a.exports=Za:$a.FlexSearch=Za;}(this||self)); diff --git a/dist/flexsearch.compact.module.debug.js b/dist/flexsearch.compact.module.debug.js index bed5378..a6ed412 100644 --- a/dist/flexsearch.compact.module.debug.js +++ b/dist/flexsearch.compact.module.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.203 (Bundle/Debug) + * FlexSearch.js v0.8.205 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -12,8 +12,8 @@ function I(a, c, b) { if (d !== "undefined") { if (b) { if (d === "function" && e === d) { - return function(h) { - return a(b(h)); + return function(k) { + return a(b(k)); }; } c = a.constructor; @@ -43,7 +43,7 @@ function I(a, c, b) { } return d === "undefined" ? c : a; } -function J(a, c) { +function K(a, c) { return typeof a === "undefined" ? c : a; } function M() { @@ -52,7 +52,7 @@ function M() { function P(a) { return typeof a === "string"; } -function R(a) { +function Q(a) { return typeof a === "object"; } function aa(a, c) { @@ -205,9 +205,9 @@ B.encode = function(a, c) { this.prepare && (a = this.prepare(a)); this.numeric && a.length > 3 && (a = a.replace(fa, "$1 $2").replace(ha, "$1 $2").replace(ea, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let e = [], d = M(), f, g, h = this.split || this.split === "" ? a.split(this.split) : [a]; - for (let n = 0, l, z; n < h.length; n++) { - if ((l = z = h[n]) && !(l.length < this.minlength || l.length > this.maxlength)) { + let e = [], d = M(), f, g, k = this.split || this.split === "" ? a.split(this.split) : [a]; + for (let m = 0, l, A; m < k.length; m++) { + if ((l = A = k[m]) && !(l.length < this.minlength || l.length > this.maxlength)) { if (c) { if (d[l]) { continue; @@ -225,9 +225,9 @@ B.encode = function(a, c) { if (!this.filter || (typeof this.filter === "function" ? this.filter(l) : !this.filter.has(l))) { if (this.cache && l.length <= this.H) { if (this.D) { - var k = this.C.get(l); - if (k || k === "") { - k && e.push(k); + var h = this.C.get(l); + if (h || h === "") { + h && e.push(h); continue; } } else { @@ -242,21 +242,21 @@ B.encode = function(a, c) { } } if (l && (this.mapper || this.dedupe && l.length > 1)) { - k = ""; + h = ""; for (let x = 0, u = "", p, w; x < l.length; x++) { - p = l.charAt(x), p === u && this.dedupe || ((w = this.mapper && this.mapper.get(p)) || w === "" ? w === u && this.dedupe || !(u = w) || (k += w) : k += u = p); + p = l.charAt(x), p === u && this.dedupe || ((w = this.mapper && this.mapper.get(p)) || w === "" ? w === u && this.dedupe || !(u = w) || (h += w) : h += u = p); } - l = k; + l = h; } this.matcher && l.length > 1 && (this.I || (this.I = new RegExp("(" + this.h + ")", "g")), l = l.replace(this.I, x => this.matcher.get(x))); if (l && this.replacer) { - for (k = 0; l && k < this.replacer.length; k += 2) { - l = l.replace(this.replacer[k], this.replacer[k + 1]); + for (h = 0; l && h < this.replacer.length; h += 2) { + l = l.replace(this.replacer[h], this.replacer[h + 1]); } } - this.cache && z.length <= this.H && (this.C.set(z, l), this.C.size > this.K && (this.C.clear(), this.H = this.H / 1.1 | 0)); + this.cache && A.length <= this.H && (this.C.set(A, l), this.C.size > this.K && (this.C.clear(), this.H = this.H / 1.1 | 0)); if (l) { - if (l !== z) { + if (l !== A) { if (c) { if (d[l]) { continue; @@ -373,20 +373,20 @@ function U(a) { }; } ;X.prototype.add = function(a, c, b) { - R(a) && (c = a, a = aa(c, this.key)); + Q(a) && (c = a, a = aa(c, this.key)); if (c && (a || a === 0)) { if (!b && this.reg.has(a)) { return this.update(a, c); } - for (let h = 0, k; h < this.field.length; h++) { - k = this.B[h]; - var e = this.index.get(this.field[h]); - if (typeof k === "function") { - var d = k(c); - d && e.add(a, d, !1, !0); + for (let k = 0, h; k < this.field.length; k++) { + h = this.B[k]; + var e = this.index.get(this.field[k]); + if (typeof h === "function") { + var d = h(c); + d && e.add(a, d, b, !0); } else { - if (d = k.F, !d || d(c)) { - k.constructor === String ? k = ["" + k] : P(k) && (k = [k]), Ba(c, k, this.C, 0, e, a, k[0], b); + if (d = h.F, !d || d(c)) { + h.constructor === String ? h = ["" + h] : P(h) && (h = [h]), Ba(c, h, this.C, 0, e, a, h[0], b); } } } @@ -394,14 +394,14 @@ function U(a) { for (e = 0; e < this.A.length; e++) { var f = this.A[e], g = this.D[e]; d = this.tag.get(g); - let h = M(); + let k = M(); if (typeof f === "function") { if (f = f(c), !f) { continue; } } else { - const k = f.F; - if (k && !k(c)) { + const h = f.F; + if (h && !h(c)) { continue; } f.constructor === String && (f = "" + f); @@ -409,8 +409,8 @@ function U(a) { } if (d && f) { P(f) && (f = [f]); - for (let k = 0, n, l; k < f.length; k++) { - n = f[k], h[n] || (h[n] = 1, (g = d.get(n)) ? l = g : d.set(n, l = []), b && l.includes(a) || (l.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(l) : this.reg.set(a, [l])))); + for (let h = 0, m, l; h < f.length; h++) { + m = f[h], k[m] || (k[m] = 1, (g = d.get(m)) ? l = g : d.set(m, l = []), b && l.includes(a) || (l.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(l) : this.reg.set(a, [l])))); } } else { d || console.warn("Tag '" + g + "' was not found"); @@ -418,29 +418,29 @@ function U(a) { } } if (this.store && (!b || !this.store.has(a))) { - let h; + let k; if (this.h) { - h = M(); - for (let k = 0, n; k < this.h.length; k++) { - n = this.h[k]; - if ((b = n.F) && !b(c)) { + k = M(); + for (let h = 0, m; h < this.h.length; h++) { + m = this.h[h]; + if ((b = m.F) && !b(c)) { continue; } let l; - if (typeof n === "function") { - l = n(c); + if (typeof m === "function") { + l = m(c); if (!l) { continue; } - n = [n.M]; - } else if (P(n) || n.constructor === String) { - h[n] = c[n]; + m = [m.M]; + } else if (P(m) || m.constructor === String) { + k[m] = c[m]; continue; } - Ca(c, h, n, 0, n[0], l); + Ca(c, k, m, 0, m[0], l); } } - this.store.set(a, h || c); + this.store.set(a, k || c); } } return this; @@ -459,7 +459,7 @@ function Ca(a, c, b, e, d, f) { } } } -function Ba(a, c, b, e, d, f, g, h) { +function Ba(a, c, b, e, d, f, g, k) { if (a = a[g]) { if (e === c.length - 1) { if (a.constructor === Array) { @@ -471,14 +471,14 @@ function Ba(a, c, b, e, d, f, g, h) { } a = a.join(" "); } - d.add(f, a, h, !0); + d.add(f, a, k, !0); } else { if (a.constructor === Array) { for (g = 0; g < a.length; g++) { - Ba(a, c, b, e, d, f, g, h); + Ba(a, c, b, e, d, f, g, k); } } else { - g = c[++e], Ba(a, c, b, e, d, f, g, h); + g = c[++e], Ba(a, c, b, e, d, f, g, k); } } } @@ -516,7 +516,7 @@ function Ba(a, c, b, e, d, f, g, h) { return e = e.length > 1 ? [].concat.apply([], e) : e[0]; } ;function Ea(a, c, b, e, d) { - let f, g, h; + let f, g, k; typeof d === "string" ? (f = d, d = "") : f = d.template; if (!f) { throw Error('No template pattern was specified by the search option "highlight"'); @@ -525,22 +525,22 @@ function Ba(a, c, b, e, d, f, g, h) { if (g === -1) { throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); } - h = f.substring(g + 2); + k = f.substring(g + 2); g = f.substring(0, g); - let k = d && d.boundary, n = !d || d.clip !== !1, l = d && d.merge && h && g && new RegExp(h + " " + g, "g"); + let h = d && d.boundary, m = !d || d.clip !== !1, l = d && d.merge && k && g && new RegExp(k + " " + g, "g"); d = d && d.ellipsis; - var z = 0; + var A = 0; if (typeof d === "object") { var x = d.template; - z = x.length - 2; + A = x.length - 2; d = d.pattern; } typeof d !== "string" && (d = d === !1 ? "" : "..."); - z && (d = x.replace("$1", d)); - x = d.length - z; + A && (d = x.replace("$1", d)); + x = d.length - A; let u, p; - typeof k === "object" && (u = k.before, u === 0 && (u = -1), p = k.after, p === 0 && (p = -1), k = k.total || 9e5); - z = new Map(); + typeof h === "object" && (u = h.before, u === 0 && (u = -1), p = h.after, p === 0 && (p = -1), h = h.total || 9e5); + A = new Map(); for (let sa = 0, V, Ha, ca; sa < c.length; sa++) { let da; if (e) { @@ -555,65 +555,65 @@ function Ba(a, c, b, e, d, f, g, h) { } Ha = b.get(ca); V = Ha.encoder; - w = z.get(V); - typeof w !== "string" && (w = V.encode(a), z.set(V, w)); + w = A.get(V); + typeof w !== "string" && (w = V.encode(a), A.set(V, w)); for (let ia = 0; ia < da.length; ia++) { - var m = da[ia].doc; - if (!m) { + var n = da[ia].doc; + if (!n) { continue; } - m = aa(m, ca); - if (!m) { + n = aa(n, ca); + if (!n) { continue; } - var v = m.trim().split(/\s+/); + var v = n.trim().split(/\s+/); if (!v.length) { continue; } - m = ""; + n = ""; var t = []; let ja = []; - var C = -1, A = -1, r = 0; + var C = -1, z = -1, r = 0; for (var y = 0; y < v.length; y++) { var F = v[y], D = V.encode(F); D = D.length > 1 ? D.join(" ") : D[0]; let q; if (D && F) { - var E = F.length, K = (V.split ? F.replace(V.split, "") : F).length - D.length, L = "", Q = 0; + var E = F.length, J = (V.split ? F.replace(V.split, "") : F).length - D.length, L = "", R = 0; for (var W = 0; W < w.length; W++) { var N = w[W]; if (N) { var H = N.length; - H += K; - Q && H <= Q || (N = D.indexOf(N), N > -1 && (L = (N ? F.substring(0, N) : "") + g + F.substring(N, N + H) + h + (N + H < E ? F.substring(N + H) : ""), Q = H, q = !0)); + H += J; + R && H <= R || (N = D.indexOf(N), N > -1 && (L = (N ? F.substring(0, N) : "") + g + F.substring(N, N + H) + k + (N + H < E ? F.substring(N + H) : ""), R = H, q = !0)); } } - L && (k && (C < 0 && (C = m.length + (m ? 1 : 0)), A = m.length + (m ? 1 : 0) + L.length, r += E, ja.push(t.length), t.push({match:L})), m += (m ? " " : "") + L); + L && (h && (C < 0 && (C = n.length + (n ? 1 : 0)), z = n.length + (n ? 1 : 0) + L.length, r += E, ja.push(t.length), t.push({match:L})), n += (n ? " " : "") + L); } if (!q) { - F = v[y], m += (m ? " " : "") + F, k && t.push({text:F}); - } else if (k && r >= k) { + F = v[y], n += (n ? " " : "") + F, h && t.push({text:F}); + } else if (h && r >= h) { break; } } r = ja.length * (f.length - 2); - if (u || p || k && m.length - r > k) { - if (r = k + r - x * 2, y = A - C, u > 0 && (y += u), p > 0 && (y += p), y <= r) { - v = u ? C - (u > 0 ? u : 0) : C - ((r - y) / 2 | 0), t = p ? A + (p > 0 ? p : 0) : v + r, n || (v > 0 && m.charAt(v) !== " " && m.charAt(v - 1) !== " " && (v = m.indexOf(" ", v), v < 0 && (v = 0)), t < m.length && m.charAt(t - 1) !== " " && m.charAt(t) !== " " && (t = m.lastIndexOf(" ", t), t < A ? t = A : ++t)), m = (v ? d : "") + m.substring(v, t) + (t < m.length ? d : ""); + if (u || p || h && n.length - r > h) { + if (r = h + r - x * 2, y = z - C, u > 0 && (y += u), p > 0 && (y += p), y <= r) { + v = u ? C - (u > 0 ? u : 0) : C - ((r - y) / 2 | 0), t = p ? z + (p > 0 ? p : 0) : v + r, m || (v > 0 && n.charAt(v) !== " " && n.charAt(v - 1) !== " " && (v = n.indexOf(" ", v), v < 0 && (v = 0)), t < n.length && n.charAt(t - 1) !== " " && n.charAt(t) !== " " && (t = n.lastIndexOf(" ", t), t < z ? t = z : ++t)), n = (v ? d : "") + n.substring(v, t) + (t < n.length ? d : ""); } else { - A = []; + z = []; C = {}; r = {}; y = {}; F = {}; D = {}; - L = K = E = 0; - for (W = Q = 1;;) { + L = J = E = 0; + for (W = R = 1;;) { var O = void 0; for (let q = 0, G; q < ja.length; q++) { G = ja[q]; if (L) { - if (K !== L) { + if (J !== L) { if (y[q + 1]) { continue; } @@ -632,27 +632,27 @@ function Ba(a, c, b, e, d, f, g, h) { } E -= x; } - m = t[G].text; + n = t[G].text; if (H = p && D[q]) { if (H > 0) { - if (m.length > H) { - if (y[q + 1] = 1, n) { - m = m.substring(0, H); + if (n.length > H) { + if (y[q + 1] = 1, m) { + n = n.substring(0, H); } else { continue; } } - (H -= m.length) || (H = -1); + (H -= n.length) || (H = -1); D[q] = H; } else { y[q + 1] = 1; continue; } } - if (E + m.length + 1 <= k) { - m = " " + m, A[q] += m; - } else if (n) { - O = k - E - 1, O > 0 && (m = " " + m.substring(0, O), A[q] += m), y[q + 1] = 1; + if (E + n.length + 1 <= h) { + n = " " + n, z[q] += n; + } else if (m) { + O = h - E - 1, O > 0 && (n = " " + n.substring(0, O), z[q] += n), y[q + 1] = 1; } else { y[q + 1] = 1; continue; @@ -661,7 +661,7 @@ function Ba(a, c, b, e, d, f, g, h) { if (y[q]) { continue; } - G -= K; + G -= J; if (C[G]) { E -= x; y[q] = 1; @@ -676,34 +676,34 @@ function Ba(a, c, b, e, d, f, g, h) { } E -= x; } - m = t[G].text; + n = t[G].text; if (H = u && F[q]) { if (H > 0) { - if (m.length > H) { - if (y[q] = 1, n) { - m = m.substring(m.length - H); + if (n.length > H) { + if (y[q] = 1, m) { + n = n.substring(n.length - H); } else { continue; } } - (H -= m.length) || (H = -1); + (H -= n.length) || (H = -1); F[q] = H; } else { y[q] = 1; continue; } } - if (E + m.length + 1 <= k) { - m += " ", A[q] = m + A[q]; - } else if (n) { - O = m.length + 1 - (k - E), O >= 0 && O < m.length && (m = m.substring(O) + " ", A[q] = m + A[q]), y[q] = 1; + if (E + n.length + 1 <= h) { + n += " ", z[q] = n + z[q]; + } else if (m) { + O = n.length + 1 - (h - E), O >= 0 && O < n.length && (n = n.substring(O) + " ", z[q] = n + z[q]), y[q] = 1; } else { y[q] = 1; continue; } } } else { - m = t[G].match; + n = t[G].match; u && (F[q] = u); p && (D[q] = p); q && E++; @@ -711,36 +711,36 @@ function Ba(a, c, b, e, d, f, g, h) { G ? !q && x && (E += x) : (r[q] = 1, y[q] = 1); G >= v.length - 1 ? ta = 1 : G < t.length - 1 && t[G + 1].match ? ta = 1 : x && (E += x); E -= f.length - 2; - if (!q || E + m.length <= k) { - A[q] = m; + if (!q || E + n.length <= h) { + z[q] = n; } else { - O = Q = W = r[q] = 0; + O = R = W = r[q] = 0; break; } ta && (r[q + 1] = 1, y[q + 1] = 1); } - E += m.length; + E += n.length; O = C[G] = 1; } if (O) { - K === L ? L++ : K++; + J === L ? L++ : J++; } else { - K === L ? Q = 0 : W = 0; - if (!Q && !W) { + J === L ? R = 0 : W = 0; + if (!R && !W) { break; } - Q ? (K++, L = K) : L++; + R ? (J++, L = J) : L++; } } - m = ""; - for (let q = 0, G; q < A.length; q++) { - G = (q && r[q] ? " " : (q && !d ? " " : "") + d) + A[q], m += G; + n = ""; + for (let q = 0, G; q < z.length; q++) { + G = (q && r[q] ? " " : (q && !d ? " " : "") + d) + z[q], n += G; } - d && !r[A.length] && (m += d); + d && !r[z.length] && (n += d); } } - l && (m = m.replace(l, " ")); - da[ia].highlight = m; + l && (n = n.replace(l, " ")); + da[ia].highlight = n; } if (e) { break; @@ -763,33 +763,33 @@ function Ba(a, c, b, e, d, f, g, h) { } ;M(); X.prototype.search = function(a, c, b, e) { - b || (!c && R(a) ? (b = a, a = "") : R(c) && (b = c, c = 0)); + b || (!c && Q(a) ? (b = a, a = "") : Q(c) && (b = c, c = 0)); let d = []; var f = []; let g; - let h, k, n, l; - let z = 0, x = !0, u; + let k, h, m, l; + let A = 0, x = !0, u; if (b) { b.constructor === Array && (b = {index:b}); a = b.query || a; var p = b.pluck; var w = b.merge; - n = p || b.field || (n = b.index) && (n.index ? null : n); + m = p || b.field || (m = b.index) && (m.index ? null : m); l = this.tag && b.tag; - h = b.suggest; + k = b.suggest; x = !0; - k = b.cache; + h = b.cache; this.store && b.highlight && !x ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && b.enrich && !x && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); u = x && this.store && b.highlight; g = !!u || x && this.store && b.enrich; c = b.limit || c; - var m = b.offset || 0; + var n = b.offset || 0; c || (c = x ? 100 : 0); if (l) { l.constructor !== Array && (l = [l]); var v = []; - for (let A = 0, r; A < l.length; A++) { - r = l[A]; + for (let z = 0, r; z < l.length; z++) { + r = l[z]; if (P(r)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } @@ -823,36 +823,36 @@ X.prototype.search = function(a, c, b, e) { f = []; if (v.length) { for (p = 0; p < v.length; p += 2) { - w = Ga.call(this, v[p], v[p + 1], c, m, g), d.push({field:v[p], tag:v[p + 1], result:w}); + w = Ga.call(this, v[p], v[p + 1], c, n, g), d.push({field:v[p], tag:v[p + 1], result:w}); } } - return f.length ? Promise.all(f).then(function(A) { - for (let r = 0; r < A.length; r++) { - d[r].result = A[r]; + return f.length ? Promise.all(f).then(function(z) { + for (let r = 0; r < z.length; r++) { + d[r].result = z[r]; } return d; }) : d; } } - n && n.constructor !== Array && (n = [n]); + m && m.constructor !== Array && (m = [m]); } - n || (n = this.field); + m || (m = this.field); v = !1; - for (let A = 0, r, y, F; A < n.length; A++) { - y = n[A]; + for (let z = 0, r, y, F; z < m.length; z++) { + y = m[z]; let D; - P(y) || (D = y, y = D.field, a = D.query || a, c = J(D.limit, c), m = J(D.offset, m), h = J(D.suggest, h), u = x && this.store && J(D.highlight, u), g = !!u || x && this.store && J(D.enrich, g), k = J(D.cache, k)); + P(y) || (D = y, y = D.field, a = D.query || a, c = K(D.limit, c), n = K(D.offset, n), k = K(D.suggest, k), u = x && this.store && K(D.highlight, u), g = !!u || x && this.store && K(D.enrich, g), h = K(D.cache, h)); if (e) { - r = e[A]; + r = e[z]; } else { t = D || b || {}; C = t.enrich; const E = this.index.get(y); l && C && (t.enrich = !1); - r = k ? E.searchCache(a, c, t) : E.search(a, c, t); + r = h ? E.searchCache(a, c, t) : E.search(a, c, t); C && (t.enrich = C); if (v) { - v[A] = r; + v[z] = r; continue; } } @@ -860,71 +860,71 @@ X.prototype.search = function(a, c, b, e) { if (l && F) { t = []; C = 0; - for (let E = 0, K, L; E < l.length; E += 2) { - K = this.tag.get(l[E]); - if (!K) { - if (console.warn("Tag '" + l[E] + ":" + l[E + 1] + "' will be skipped because there is no field '" + l[E] + "'."), h) { + for (let E = 0, J, L; E < l.length; E += 2) { + J = this.tag.get(l[E]); + if (!J) { + if (console.warn("Tag '" + l[E] + ":" + l[E + 1] + "' will be skipped because there is no field '" + l[E] + "'."), k) { continue; } else { return d; } } - if (L = (K = K && K.get(l[E + 1])) && K.length) { - C++, t.push(K); - } else if (!h) { + if (L = (J = J && J.get(l[E + 1])) && J.length) { + C++, t.push(J); + } else if (!k) { return d; } } if (C) { r = Fa(r, t); F = r.length; - if (!F && !h) { + if (!F && !k) { return r; } C--; } } if (F) { - f[z] = y, d.push(r), z++; - } else if (n.length === 1) { + f[A] = y, d.push(r), A++; + } else if (m.length === 1) { return d; } } if (v) { - const A = this; + const z = this; return Promise.all(v).then(function(r) { b && (b.resolve = x); - r.length && (r = A.search(a, c, b, r)); + r.length && (r = z.search(a, c, b, r)); return r; }); } - if (!z) { + if (!A) { return d; } if (p && (!g || !this.store)) { return d = d[0]; } v = []; - for (m = 0; m < f.length; m++) { - e = d[m]; + for (n = 0; n < f.length; n++) { + e = d[n]; g && e.length && typeof e[0].doc === "undefined" && (e = Ia.call(this, e)); if (p) { return u ? Ea(a, e, this.index, p, u) : e; } - d[m] = {field:f[m], result:e}; + d[n] = {field:f[n], result:e}; } u && (d = Ea(a, d, this.index, p, u)); return w ? Ja(d) : d; }; function Ja(a) { const c = [], b = M(), e = M(); - for (let d = 0, f, g, h, k, n, l, z; d < a.length; d++) { + for (let d = 0, f, g, k, h, m, l, A; d < a.length; d++) { f = a[d]; g = f.field; - h = f.result; - for (let x = 0; x < h.length; x++) { - if (n = h[x], typeof n !== "object" ? n = {id:k = n} : k = n.id, (l = b[k]) ? l.push(g) : (n.field = b[k] = [g], c.push(n)), z = n.highlight) { - l = e[k], l || (e[k] = l = {}, n.highlight = l), l[g] = z; + k = f.result; + for (let x = 0; x < k.length; x++) { + if (m = k[x], typeof m !== "object" ? m = {id:h = m} : h = m.id, (l = b[h]) ? l.push(g) : (m.field = b[h] = [g], c.push(m)), A = m.highlight) { + l = e[h], l || (e[h] = l = {}, m.highlight = l), l[g] = A; } } } @@ -978,7 +978,7 @@ function Ia(a) { let e = c.index || c.field || c; P(e) && (e = [e]); for (let d = 0, f, g; d < e.length; d++) { - f = e[d], P(f) || (g = f, f = f.field), g = R(g) ? Object.assign({}, a, g) : a, b.set(f, new Y(g, this.reg)), g.custom ? this.B[d] = g.custom : (this.B[d] = Ka(f, this.C), g.filter && (typeof this.B[d] === "string" && (this.B[d] = new String(this.B[d])), this.B[d].F = g.filter)), this.field[d] = f; + f = e[d], P(f) || (g = f, f = f.field), g = Q(g) ? Object.assign({}, a, g) : a, b.set(f, new Y(g, this.reg)), g.custom ? this.B[d] = g.custom : (this.B[d] = Ka(f, this.C), g.filter && (typeof this.B[d] === "string" && (this.B[d] = new String(this.B[d])), this.B[d].F = g.filter)), this.field[d] = f; } if (this.h) { a = c.store; @@ -1024,7 +1024,7 @@ B.update = function(a, c) { return this.remove(a).add(a, c); }; B.remove = function(a) { - R(a) && (a = aa(a, this.key)); + Q(a) && (a = aa(a, this.key)); for (var c of this.index.values()) { c.remove(a, !0); } @@ -1128,26 +1128,26 @@ function Sa(a, c) { return c; } function Ta(a, c, b, e, d, f, g = 0) { - const h = e && e.constructor === Array; - var k = h ? e.shift() : e; - if (!k) { + const k = e && e.constructor === Array; + var h = k ? e.shift() : e; + if (!h) { return this.export(a, c, d, f + 1); } - if ((k = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(k))) && k.then) { - const n = this; - return k.then(function() { - return Ta.call(n, a, c, b, h ? e : null, d, f, g + 1); + if ((h = a((c ? c + "." : "") + (g + 1) + "." + b, JSON.stringify(h))) && h.then) { + const m = this; + return h.then(function() { + return Ta.call(m, a, c, b, k ? e : null, d, f, g + 1); }); } - return Ta.call(this, a, c, b, h ? e : null, d, f, g + 1); + return Ta.call(this, a, c, b, k ? e : null, d, f, g + 1); } function La(a, c, b = 0, e = 0) { if (b < this.field.length) { const g = this.field[b]; if ((c = this.index.get(g).export(a, g, b, e = 1)) && c.then) { - const h = this; + const k = this; return c.then(function() { - return h.export(a, g, b + 1); + return k.export(a, g, b + 1); }); } return this.export(a, g, b + 1); @@ -1206,14 +1206,14 @@ function Ua(a, c) { a = e[0]; const d = e[1]; let f = ""; - for (let g = 0, h; g < d.length; g++) { - h = d[g] || [""]; - let k = ""; - for (let n = 0; n < h.length; n++) { - k += (k ? "," : "") + (c === "string" ? '"' + h[n] + '"' : h[n]); + for (let g = 0, k; g < d.length; g++) { + k = d[g] || [""]; + let h = ""; + for (let m = 0; m < k.length; m++) { + h += (h ? "," : "") + (c === "string" ? '"' + k[m] + '"' : k[m]); } - k = "[" + k + "]"; - f += (f ? "," : "") + k; + h = "[" + h + "]"; + f += (f ? "," : "") + h; } f = '["' + a + '",[' + f + "]]"; b += (b ? "," : "") + f; @@ -1246,7 +1246,7 @@ function Va(a, c) { let b = 0; var e = typeof c === "undefined"; if (a.constructor === Array) { - for (let d = 0, f, g, h; d < a.length; d++) { + for (let d = 0, f, g, k; d < a.length; d++) { if ((f = a[d]) && f.length) { if (e) { return 1; @@ -1260,9 +1260,9 @@ function Va(a, c) { if (b) { return 1; } - h = 1; + k = 1; } else { - if (h) { + if (k) { return 1; } b++; @@ -1284,32 +1284,32 @@ Y.prototype.add = function(a, c, b, e) { } e = this.depth; c = this.encoder.encode(c, !e); - const n = c.length; - if (n) { - const l = M(), z = M(), x = this.resolution; - for (let u = 0; u < n; u++) { - let p = c[this.rtl ? n - 1 - u : u]; + const m = c.length; + if (m) { + const l = M(), A = M(), x = this.resolution; + for (let u = 0; u < m; u++) { + let p = c[this.rtl ? m - 1 - u : u]; var d = p.length; - if (d && (e || !z[p])) { - var f = this.score ? this.score(c, p, u, null, 0) : Xa(x, n, u), g = ""; + if (d && (e || !A[p])) { + var f = this.score ? this.score(c, p, u, null, 0) : Xa(x, m, u), g = ""; switch(this.tokenize) { case "tolerant": - Z(this, z, p, f, a, b); + Z(this, A, p, f, a, b); if (d > 2) { - for (let w = 1, m, v, t, C; w < d - 1; w++) { - m = p.charAt(w), v = p.charAt(w + 1), t = p.substring(0, w) + v, C = p.substring(w + 2), g = t + m + C, z[g] || Z(this, z, g, f, a, b), g = t + C, z[g] || Z(this, z, g, f, a, b); + for (let w = 1, n, v, t, C; w < d - 1; w++) { + n = p.charAt(w), v = p.charAt(w + 1), t = p.substring(0, w) + v, C = p.substring(w + 2), g = t + n + C, Z(this, A, g, f, a, b), g = t + C, Z(this, A, g, f, a, b); } + Z(this, A, p.substring(0, p.length - 1), f, a, b); } break; case "full": if (d > 2) { - for (let w = 0, m; w < d; w++) { + for (let w = 0, n; w < d; w++) { for (f = d; f > w; f--) { - if (g = p.substring(w, f), !z[g]) { - m = this.rtl ? d - 1 - w : w; - var h = this.score ? this.score(c, p, u, g, m) : Xa(x, n, u, d, m); - Z(this, z, g, h, a, b); - } + g = p.substring(w, f); + n = this.rtl ? d - 1 - w : w; + var k = this.score ? this.score(c, p, u, g, n) : Xa(x, m, u, d, n); + Z(this, A, g, k, a, b); } } break; @@ -1317,29 +1317,27 @@ Y.prototype.add = function(a, c, b, e) { case "bidirectional": case "reverse": if (d > 1) { - for (h = d - 1; h > 0; h--) { - if (g = p[this.rtl ? d - 1 - h : h] + g, !z[g]) { - var k = this.score ? this.score(c, p, u, g, h) : Xa(x, n, u, d, h); - Z(this, z, g, k, a, b); - } + for (k = d - 1; k > 0; k--) { + g = p[this.rtl ? d - 1 - k : k] + g; + var h = this.score ? this.score(c, p, u, g, k) : Xa(x, m, u, d, k); + Z(this, A, g, h, a, b); } g = ""; } case "forward": if (d > 1) { - for (h = 0; h < d; h++) { - g += p[this.rtl ? d - 1 - h : h], z[g] || Z(this, z, g, f, a, b); + for (k = 0; k < d; k++) { + g += p[this.rtl ? d - 1 - k : k], Z(this, A, g, f, a, b); } break; } default: - if (Z(this, z, p, f, a, b), e && n > 1 && u < n - 1) { - for (d = M(), g = this.L, f = p, h = Math.min(e + 1, this.rtl ? u + 1 : n - u), d[f] = 1, k = 1; k < h; k++) { - if ((p = c[this.rtl ? n - 1 - u - k : u + k]) && !d[p]) { - d[p] = 1; - const w = this.score ? this.score(c, f, u, p, k - 1) : Xa(g + (n / 2 > g ? 0 : 1), n, u, h - 1, k - 1), m = this.bidirectional && p > f; - Z(this, l, m ? f : p, w, a, b, m ? p : f); - } + if (Z(this, A, p, f, a, b), e && m > 1 && u < m - 1) { + for (d = this.L, g = p, f = Math.min(e + 1, this.rtl ? u + 1 : m - u), k = 1; k < f; k++) { + p = c[this.rtl ? m - 1 - u - k : u + k]; + h = this.bidirectional && p > g; + const w = this.score ? this.score(c, g, u, p, k - 1) : Xa(d + (m / 2 > d ? 0 : 1), m, u, f - 1, k - 1); + Z(this, l, h ? g : p, w, a, b, h ? p : g); } } } @@ -1351,9 +1349,25 @@ Y.prototype.add = function(a, c, b, e) { return this; }; function Z(a, c, b, e, d, f, g) { - let h = g ? a.ctx : a.map, k; - if (!c[b] || g && !(k = c[b])[g]) { - g ? (c = k || (c[b] = M()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); + let k, h; + if (!(k = c[b]) || g && !k[g]) { + g ? (c = k || (c[b] = M()), c[g] = 1, h = a.ctx, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : (h = a.map, c[b] = 1); + (k = h.get(b)) ? h = k : h.set(b, h = k = []); + if (f) { + for (let m = 0, l; m < k.length; m++) { + if ((l = k[m]) && l.includes(d)) { + if (m <= e) { + return; + } + l.splice(l.indexOf(d), 1); + a.fastupdate && (c = a.reg.get(d)) && c.splice(c.indexOf(l), 1); + break; + } + } + } + h = h[e] || (h[e] = []); + h.push(d); + a.fastupdate && ((e = a.reg.get(d)) ? e.push(h) : a.reg.set(d, [h])); } } function Xa(a, c, b, e, d) { @@ -1371,53 +1385,53 @@ function Xa(a, c, b, e, d) { d = b.offset || 0; var f = b.context; var g = b.suggest; - var h = !0; - var k = b.resolution; + var k = !0; + var h = b.resolution; } - typeof h === "undefined" && (h = !0); + typeof k === "undefined" && (k = !0); f = this.depth && f !== !1; b = this.encoder.encode(a, !f); a = b.length; - c = c || (h ? 100 : 0); + c = c || (k ? 100 : 0); if (a === 1) { return g = d, (d = Ya(this, b[0], "")) && d.length ? Da.call(this, d, c, g) : []; } if (a === 2 && f && !g) { return g = d, (d = Ya(this, b[1], b[0])) && d.length ? Da.call(this, d, c, g) : []; } - h = M(); - var n = 0; + k = M(); + var m = 0; if (f) { var l = b[0]; - n = 1; + m = 1; } - k || k === 0 || (k = l ? this.L : this.resolution); - for (let p, w; n < a; n++) { - if ((w = b[n]) && !h[w]) { - h[w] = 1; + h || h === 0 || (h = l ? this.L : this.resolution); + for (let p, w; m < a; m++) { + if ((w = b[m]) && !k[w]) { + k[w] = 1; p = Ya(this, w, l); a: { f = p; - var z = e, x = g, u = k; - let m = []; + var A = e, x = g, u = h; + let n = []; if (f && f.length) { if (f.length <= u) { - z.push(f); + A.push(f); p = void 0; break a; } for (let v = 0, t; v < u; v++) { if (t = f[v]) { - m[v] = t; + n[v] = t; } } - if (m.length) { - z.push(m); + if (n.length) { + A.push(n); p = void 0; break a; } } - p = x ? void 0 : m; + p = x ? void 0 : n; } if (p) { e = p; @@ -1425,7 +1439,7 @@ function Xa(a, c, b, e, d) { } l && (g && p && e.length || (l = w)); } - g && l && n === a - 1 && !e.length && (k = this.resolution, l = "", n = -1, h = M()); + g && l && m === a - 1 && !e.length && (h = this.resolution, l = "", m = -1, k = M()); } a: { b = e; @@ -1437,11 +1451,11 @@ function Xa(a, c, b, e, d) { l = b.length; g = []; a = M(); - for (let p = 0, w, m, v, t; p < k; p++) { - for (n = 0; n < l; n++) { - if (v = b[n], p < v.length && (w = v[p])) { + for (let p = 0, w, n, v, t; p < h; p++) { + for (m = 0; m < l; m++) { + if (v = b[m], p < v.length && (w = v[p])) { for (f = 0; f < w.length; f++) { - if (m = w[f], (h = a[m]) ? a[m]++ : (h = 0, a[m] = 1), t = g[h] || (g[h] = []), t.push(m), c && h === l - 1 && t.length - d === c) { + if (n = w[f], (k = a[n]) ? a[n]++ : (k = 0, a[n] = 1), t = g[k] || (g[k] = []), t.push(n), c && k === l - 1 && t.length - d === c) { l = d ? t.slice(d) : t; break b; } @@ -1453,11 +1467,11 @@ function Xa(a, c, b, e, d) { if (e) { if (g.length > 1) { c: { - for (b = [], k = M(), e = g.length, h = e - 1; h >= 0; h--) { - if (a = (e = g[h]) && e.length) { - for (n = 0; n < a; n++) { - if (l = e[n], !k[l]) { - if (k[l] = 1, d) { + for (b = [], h = M(), e = g.length, k = e - 1; k >= 0; k--) { + if (a = (e = g[k]) && e.length) { + for (m = 0; m < a; m++) { + if (l = e[m], !h[l]) { + if (h[l] = 1, d) { d--; } else { if (b.push(l), b.length === c) { @@ -1609,10 +1623,10 @@ B.serialize = function(a = !0) { b = "index.map=new Map([" + b + "]);"; for (const g of this.ctx.entries()) { d = g[0]; - let h = Ua(g[1], f); - h = "new Map([" + h + "])"; - h = '["' + d + '",' + h + "]"; - e += (e ? "," : "") + h; + let k = Ua(g[1], f); + k = "new Map([" + k + "])"; + k = '["' + d + '",' + k + "]"; + e += (e ? "," : "") + k; } e = "index.ctx=new Map([" + e + "]);"; } diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index 68fc78b..2525cc0 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -1,12 +1,12 @@ /**! - * FlexSearch.js v0.8.203 (Bundle) + * FlexSearch.js v0.8.205 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var B;function I(a,c,b){const e=typeof b,d=typeof a;if(e!=="undefined"){if(d!=="undefined"){if(b){if(d==="function"&&e===d)return function(h){return a(b(h))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var f=new Map(b);for(var g of a)f.set(g[0],g[1]);return f}if(c===Set){g=new Set(b);for(f of a.values())g.add(f);return g}}}return a}return b}return d==="undefined"?c:a}function J(a,c){return typeof a==="undefined"?c:a}function N(){return Object.create(null)} -function P(a){return typeof a==="string"}function R(a){return typeof a==="object"}function aa(a,c){if(P(c))a=a[c];else for(let b=0;a&&b1)return this.addMatcher(a,c);this.mapper||(this.mapper=new Map);this.mapper.set(a,c);this.cache&&S(this);return this};B.addMatcher=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.h+=(this.h?"|":"")+a;this.I=null;this.cache&&S(this);return this}; B.addReplacer=function(a,c){if(typeof a==="string")return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&S(this);return this}; B.encode=function(a,c){if(this.cache&&a.length<=this.G)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(S,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=ka?a.normalize("NFKD").replace(ka,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(fa,"$1 $2").replace(ha,"$1 $2").replace(ea,"$1 "));const b=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let e= -[],d=N(),f,g,h=this.split||this.split===""?a.split(this.split):[a];for(let n=0,l,z;nthis.maxlength)){if(c){if(d[l])continue;d[l]=1}else{if(f===l)continue;f=l}if(b)e.push(l);else if(!this.filter||(typeof this.filter==="function"?this.filter(l):!this.filter.has(l))){if(this.cache&&l.length<=this.H)if(this.D){var k=this.C.get(l);if(k||k===""){k&&e.push(k);continue}}else this.D=setTimeout(S,50,this);if(this.stemmer){this.J||(this.J=new RegExp("(?!^)("+ -this.A+")$"));let x;for(;x!==l&&l.length>2;)x=l,l=l.replace(this.J,u=>this.stemmer.get(u))}if(l&&(this.mapper||this.dedupe&&l.length>1)){k="";for(let x=0,u="",p,w;x1&&(this.I||(this.I=new RegExp("("+this.h+")","g")),l=l.replace(this.I,x=>this.matcher.get(x)));if(l&&this.replacer)for(k=0;l&&kthis.K&&(this.C.clear(),this.H=this.H/1.1|0));if(l){if(l!==z)if(c){if(d[l])continue;d[l]=1}else{if(g===l)continue;g=l}e.push(l)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.G&&(this.B.set(a,e),this.B.size>this.K&&(this.B.clear(),this.G=this.G/1.1|0));return e};function S(a){a.D=null;a.B.clear();a.C.clear()};function ma(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):b=a);b&&(a=b.query||a,c=b.limit||c);let e=""+(c||0);b&&(e+=(b.offset||0)+!!b.context+!!b.suggest+(b.resolve!==!1)+(b.resolution||this.resolution)+(b.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new T);let d=this.cache.get(a+e);if(!d){const f=b&&b.cache;f&&(b.cache=!1);d=this.search(a,c,b);f&&(b.cache=f);this.cache.set(a+e,d)}return d}function T(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""} +[],d=N(),f,g,k=this.split||this.split===""?a.split(this.split):[a];for(let m=0,l,A;mthis.maxlength)){if(c){if(d[l])continue;d[l]=1}else{if(f===l)continue;f=l}if(b)e.push(l);else if(!this.filter||(typeof this.filter==="function"?this.filter(l):!this.filter.has(l))){if(this.cache&&l.length<=this.H)if(this.D){var h=this.C.get(l);if(h||h===""){h&&e.push(h);continue}}else this.D=setTimeout(S,50,this);if(this.stemmer){this.J||(this.J=new RegExp("(?!^)("+ +this.A+")$"));let x;for(;x!==l&&l.length>2;)x=l,l=l.replace(this.J,u=>this.stemmer.get(u))}if(l&&(this.mapper||this.dedupe&&l.length>1)){h="";for(let x=0,u="",p,w;x1&&(this.I||(this.I=new RegExp("("+this.h+")","g")),l=l.replace(this.I,x=>this.matcher.get(x)));if(l&&this.replacer)for(h=0;l&&hthis.K&&(this.C.clear(),this.H=this.H/1.1|0));if(l){if(l!==A)if(c){if(d[l])continue;d[l]=1}else{if(g===l)continue;g=l}e.push(l)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.G&&(this.B.set(a,e),this.B.size>this.K&&(this.B.clear(),this.G=this.G/1.1|0));return e};function S(a){a.D=null;a.B.clear();a.C.clear()};function ma(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):b=a);b&&(a=b.query||a,c=b.limit||c);let e=""+(c||0);b&&(e+=(b.offset||0)+!!b.context+!!b.suggest+(b.resolve!==!1)+(b.resolution||this.resolution)+(b.boost||0));a=(""+a).toLowerCase();this.cache||(this.cache=new T);let d=this.cache.get(a+e);if(!d){const f=b&&b.cache;f&&(b.cache=!1);d=this.search(a,c,b);f&&(b.cache=f);this.cache.set(a+e,d)}return d}function T(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""} T.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)};T.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};T.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};T.prototype.clear=function(){this.cache.clear();this.h=""};const na={normalize:!1,numeric:!1,dedupe:!1};const oa={};const pa=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 qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];const ua={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var va={Exact:na,Default:oa,Normalize:oa,LatinBalance:{mapper:pa},LatinAdvanced:{mapper:pa,matcher:qa,replacer:ra},LatinExtra:{mapper:pa,replacer:ra.concat([/(?!^)[aeo]/g,""]),matcher:qa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;b=this.priority*this.priority*3):(xa=setTimeout(Aa,0),ya=Date.now());if(za){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};X.prototype.add=function(a,c,b){R(a)&&(c=a,a=aa(c,this.key));if(c&&(a||a===0)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hc?a.slice(b,b+c):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}f=f.slice(b,b+c);g=f.length;b=0}g>c&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=e.length>1?[].concat.apply([],e):e[0]};function Ea(a,c,b,e,d){let f,g,h;typeof d==="string"?(f=d,d=""):f=d.template;g=f.indexOf("$1");h=f.substring(g+2);g=f.substring(0,g);let k=d&&d.boundary,n=!d||d.clip!==!1,l=d&&d.merge&&h&&g&&new RegExp(h+" "+g,"g");d=d&&d.ellipsis;var z=0;if(typeof d==="object"){var x=d.template;z=x.length-2;d=d.pattern}typeof d!=="string"&&(d=d===!1?"":"...");z&&(d=x.replace("$1",d));x=d.length-z;let u,p;typeof k==="object"&&(u=k.before,u===0&&(u=-1),p=k.after,p===0&&(p=-1),k=k.total||9E5);z=new Map;for(let sa=0, -V,Ha,ca;sa1?D.join(" "):D[0];let q;if(D&&E){var F=E.length,K=(V.split?E.replace(V.split, -""):E).length-D.length,L="",Q=0;for(var W=0;W-1&&(L=(M?E.substring(0,M):"")+g+E.substring(M,M+H)+h+(M+H=k)break}t=ja.length*(f.length-2);if(u||p||k&&m.length-t>k)if(t=k+t-x*2,y=A-C,u>0&&(y+=u),p>0&&(y+=p), -y<=t)v=u?C-(u>0?u:0):C-((t-y)/2|0),r=p?A+(p>0?p:0):v+t,n||(v>0&&m.charAt(v)!==" "&&m.charAt(v-1)!==" "&&(v=m.indexOf(" ",v),v<0&&(v=0)),r=r.length-1){if(G>=r.length){y[q+1]= -1;G>=v.length&&(t[q+1]=1);continue}F-=x}m=r[G].text;if(H=p&&D[q])if(H>0){if(m.length>H)if(y[q+1]=1,n)m=m.substring(0,H);else continue;(H-=m.length)||(H=-1);D[q]=H}else{y[q+1]=1;continue}if(F+m.length+1<=k)m=" "+m,A[q]+=m;else if(n)O=k-F-1,O>0&&(m=" "+m.substring(0,O),A[q]+=m),y[q+1]=1;else{y[q+1]=1;continue}}else{if(y[q])continue;G-=K;if(C[G]){F-=x;y[q]=1;t[q]=1;continue}if(G<=0){if(G<0){y[q]=1;t[q]=1;continue}F-=x}m=r[G].text;if(H=u&&E[q])if(H>0){if(m.length>H)if(y[q]=1,n)m=m.substring(m.length- -H);else continue;(H-=m.length)||(H=-1);E[q]=H}else{y[q]=1;continue}if(F+m.length+1<=k)m+=" ",A[q]=m+A[q];else if(n)O=m.length+1-(k-F),O>=0&&O=v.length-1?ta=1:G0){if(b&&c>b||e)a=a.slice(e,e+b);d&&(a=Ia.call(this,a))}return a}function Ia(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;b=this.priority*this.priority*3):(xa=setTimeout(Aa,0),ya=Date.now());if(za){const f=this;return new Promise(g=>{setTimeout(function(){g(f[a+"Async"].apply(f,c))},0)})}const d=this[a].apply(this,c);b=d.then?d:new Promise(f=>f(d));e&&b.then(e);return b}};X.prototype.add=function(a,c,b){Q(a)&&(c=a,a=aa(c,this.key));if(c&&(a||a===0)){if(!b&&this.reg.has(a))return this.update(a,c);for(let k=0,h;kc?a.slice(b,b+c):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}f=f.slice(b,b+c);g=f.length;b=0}g>c&&(f=f.slice(0,c),g=c);if(!e.length&&g>=c)return f;e.push(f);c-=g;if(!c)break}return e=e.length>1?[].concat.apply([],e):e[0]};function Ea(a,c,b,e,d){let f,g,k;typeof d==="string"?(f=d,d=""):f=d.template;g=f.indexOf("$1");k=f.substring(g+2);g=f.substring(0,g);let h=d&&d.boundary,m=!d||d.clip!==!1,l=d&&d.merge&&k&&g&&new RegExp(k+" "+g,"g");d=d&&d.ellipsis;var A=0;if(typeof d==="object"){var x=d.template;A=x.length-2;d=d.pattern}typeof d!=="string"&&(d=d===!1?"":"...");A&&(d=x.replace("$1",d));x=d.length-A;let u,p;typeof h==="object"&&(u=h.before,u===0&&(u=-1),p=h.after,p===0&&(p=-1),h=h.total||9E5);A=new Map;for(let sa=0, +V,Ha,ca;sa1?D.join(" "):D[0];let q;if(D&&E){var F=E.length,J=(V.split?E.replace(V.split, +""):E).length-D.length,L="",R=0;for(var W=0;W-1&&(L=(M?E.substring(0,M):"")+g+E.substring(M,M+H)+k+(M+H=h)break}t=ja.length*(f.length-2);if(u||p||h&&n.length-t>h)if(t=h+t-x*2,y=z-C,u>0&&(y+=u),p>0&&(y+=p), +y<=t)v=u?C-(u>0?u:0):C-((t-y)/2|0),r=p?z+(p>0?p:0):v+t,m||(v>0&&n.charAt(v)!==" "&&n.charAt(v-1)!==" "&&(v=n.indexOf(" ",v),v<0&&(v=0)),r=r.length-1){if(G>=r.length){y[q+1]= +1;G>=v.length&&(t[q+1]=1);continue}F-=x}n=r[G].text;if(H=p&&D[q])if(H>0){if(n.length>H)if(y[q+1]=1,m)n=n.substring(0,H);else continue;(H-=n.length)||(H=-1);D[q]=H}else{y[q+1]=1;continue}if(F+n.length+1<=h)n=" "+n,z[q]+=n;else if(m)O=h-F-1,O>0&&(n=" "+n.substring(0,O),z[q]+=n),y[q+1]=1;else{y[q+1]=1;continue}}else{if(y[q])continue;G-=J;if(C[G]){F-=x;y[q]=1;t[q]=1;continue}if(G<=0){if(G<0){y[q]=1;t[q]=1;continue}F-=x}n=r[G].text;if(H=u&&E[q])if(H>0){if(n.length>H)if(y[q]=1,m)n=n.substring(n.length- +H);else continue;(H-=n.length)||(H=-1);E[q]=H}else{y[q]=1;continue}if(F+n.length+1<=h)n+=" ",z[q]=n+z[q];else if(m)O=n.length+1-(h-F),O>=0&&O=v.length-1?ta=1:G0){if(b&&c>b||e)a=a.slice(e,e+b);d&&(a=Ia.call(this,a))}return a}function Ia(a){if(!this||!this.store)return a;const c=Array(a.length);for(let b=0,e;b1?b:b[0]}B=X.prototype;B.append=function(a,c){return this.add(a,c,!0)};B.update=function(a,c){return this.remove(a).add(a,c)}; -B.remove=function(a){R(a)&&(a=aa(a,this.key));for(var c of this.index.values())c.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(let b of this.tag.values())for(let e of b){c=e[0];const d=e[1],f=d.indexOf(a);f>-1&&(d.length>1?d.splice(f,1):b.delete(c))}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +B.remove=function(a){Q(a)&&(a=aa(a,this.key));for(var c of this.index.values())c.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(let b of this.tag.values())for(let e of b){c=e[0];const d=e[1],f=d.indexOf(a);f>-1&&(d.length>1?d.splice(f,1):b.delete(c))}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; B.clear=function(){const a=[];for(const c of this.index.values()){const b=c.clear();b.then&&a.push(b)}if(this.tag)for(const c of this.tag.values())c.clear();this.store&&this.store.clear();this.cache&&this.cache.clear();return a.length?Promise.all(a):this};B.contain=function(a){return this.reg.has(a)};B.cleanup=function(){for(const a of this.index.values())a.cleanup();return this};B.get=function(a){return this.store.get(a)||null}; B.set=function(a,c){typeof a==="object"&&(c=a,a=aa(c,this.key));this.store.set(a,c);return this};B.searchCache=ma;B.export=La;B.import=Ma;wa(X.prototype);function Na(a,c=0){let b=[],e=[];c&&(c=25E4/c*5E3|0);for(const d of a.entries())e.push(d),e.length===c&&(b.push(e),e=[]);e.length&&b.push(e);return b}function Oa(a,c){c||(c=new Map);for(let b=0,e;b2?b[0]:"";b=b.length>2?b[2]:b[1];if(c){typeof c==="string"&&(c=JSON.parse(c));if(a)return this.index.get(a).import(b,c);switch(b){case "reg":this.fastupdate=!1;this.reg=Sa(c,this.reg);for(let e=0,d;e=0&&d.splice(g,1)}}else Va(this.map,a),this.depth&&Va(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function Va(a,c){let b=0;var e=typeof c==="undefined";if(a.constructor===Array)for(let d=0,f,g,h;d=0){if(f.length>1)return f.splice(g,1),1;delete a[d];if(b)return 1;h=1}else{if(h)return 1;b++}}}else for(let d of a.entries())e=d[0],Va(d[1],c)?b++:a.delete(e);return b};const Wa={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};Y.prototype.add=function(a,c,b,e){if(c&&(a||a===0)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);e=this.depth;c=this.encoder.encode(c,!e);const n=c.length;if(n){const l=N(),z=N(),x=this.resolution;for(let u=0;u2)for(let w=1,m,v,r,C;w2){for(let w=0,m;ww;f--)if(g=p.substring(w,f),!z[g]){m=this.rtl?d-1-w:w;var h=this.score?this.score(c,p,u,g,m):Xa(x,n,u,d,m);Z(this,z,g,h,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(h=d-1;h>0;h--)if(g=p[this.rtl?d-1-h:h]+g,!z[g]){var k=this.score?this.score(c,p,u,g,h):Xa(x,n,u,d,h);Z(this,z,g,k,a,b)}g=""}case "forward":if(d>1){for(h=0;h1&&ug?0:1),n,u,h-1,k-1),m=this.bidirectional&&p>f;Z(this,l,m?f:p,w,a,b,m?p:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Z(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=N()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function Xa(a,c,b,e,d){return b&&a>1?c+(e||0)<=a?b+(d||0):(a-1)/(c+(e||0))*(b+(d||0))+1|0:0};Y.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));if(b&&b.cache)return b.cache=!1,c=this.searchCache(a,c,b),b.cache=!0,c;var e=[],d=0;if(b){a=b.query||a;c=b.limit||c;d=b.offset||0;var f=b.context;var g=b.suggest;var h=!0;var k=b.resolution}typeof h==="undefined"&&(h=!0);f=this.depth&&f!==!1;b=this.encoder.encode(a,!f);a=b.length;c=c||(h?100:0);if(a===1)return g=d,(d=Ya(this,b[0],""))&&d.length?Da.call(this,d,c,g):[];if(a===2&&f&&!g)return g=d, -(d=Ya(this,b[1],b[0]))&&d.length?Da.call(this,d,c,g):[];h=N();var n=0;if(f){var l=b[0];n=1}k||k===0||(k=l?this.L:this.resolution);for(let p,w;n1)b:{e=g;l=b.length;g=[];a=N();for(let p=0,w,m,v,r;p1)c:for(b=[],k=N(),e=g.length,h=e-1;h>=0;h--){if(a=(e=g[h])&&e.length)for(n=0;nc||d?g.slice(d,c+d):g;g=b}else{if(b< +function Ua(a,c){let b="";for(const e of a.entries()){a=e[0];const d=e[1];let f="";for(let g=0,k;g=0&&d.splice(g,1)}}else Va(this.map,a),this.depth&&Va(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Va(a,c){let b=0;var e=typeof c==="undefined";if(a.constructor===Array)for(let d=0,f,g,k;d=0){if(f.length>1)return f.splice(g,1),1;delete a[d];if(b)return 1;k=1}else{if(k)return 1;b++}}}else for(let d of a.entries())e=d[0],Va(d[1],c)?b++:a.delete(e);return b};const Wa={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};Y.prototype.add=function(a,c,b,e){if(c&&(a||a===0)){if(!e&&!b&&this.reg.has(a))return this.update(a,c);e=this.depth;c=this.encoder.encode(c,!e);const m=c.length;if(m){const l=N(),A=N(),x=this.resolution;for(let u=0;u2){for(let w=1,n,v,r,C;w2){for(let w=0,n;ww;f--){g=p.substring(w,f);n=this.rtl?d-1-w:w;var k=this.score?this.score(c,p,u,g,n):Xa(x,m,u,d,n);Z(this,A,g,k,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(k=d-1;k>0;k--){g=p[this.rtl?d-1-k:k]+g;var h=this.score?this.score(c,p,u,g,k):Xa(x,m,u,d,k);Z(this,A,g,h,a,b)}g=""}case "forward":if(d>1){for(k=0;k1&&ug;const w=this.score?this.score(c,g,u,p,k-1):Xa(d+(m/2>d?0:1),m,u,f-1,k-1);Z(this,l,h?g:p,w,a,b,h?p:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function Z(a,c,b,e,d,f,g){let k,h;if(!(k=c[b])||g&&!k[g]){g?(c=k||(c[b]=N()),c[g]=1,h=a.ctx,(k=h.get(g))?h=k:h.set(g,h=new Map)):(h=a.map,c[b]=1);(k=h.get(b))?h=k:h.set(b,h=k=[]);if(f)for(let m=0,l;m1?c+(e||0)<=a?b+(d||0):(a-1)/(c+(e||0))*(b+(d||0))+1|0:0};Y.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));if(b&&b.cache)return b.cache=!1,c=this.searchCache(a,c,b),b.cache=!0,c;var e=[],d=0;if(b){a=b.query||a;c=b.limit||c;d=b.offset||0;var f=b.context;var g=b.suggest;var k=!0;var h=b.resolution}typeof k==="undefined"&&(k=!0);f=this.depth&&f!==!1;b=this.encoder.encode(a,!f);a=b.length;c=c||(k?100:0);if(a===1)return g=d,(d=Ya(this,b[0],""))&&d.length?Da.call(this,d,c,g):[];if(a===2&&f&&!g)return g=d, +(d=Ya(this,b[1],b[0]))&&d.length?Da.call(this,d,c,g):[];k=N();var m=0;if(f){var l=b[0];m=1}h||h===0||(h=l?this.L:this.resolution);for(let p,w;m1)b:{e=g;l=b.length;g=[];a=N();for(let p=0,w,n,v,r;p1)c:for(b=[],h=N(),e=g.length,k=e-1;k>=0;k--){if(a=(e=g[k])&&e.length)for(m=0;mc||d?g.slice(d,c+d):g;g=b}else{if(b< l){l=[];break b}g=g[b-1];if(c||d)if(g.length>c||d)g=g.slice(d,c+d)}l=g}else if(e===1){c=Da.call(null,b[0],c,d);break a}c=l}return c};function Ya(a,c,b){let e;b&&(e=a.bidirectional&&c>b)&&(e=b,b=c,c=e);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function Y(a,c){if(!this||this.constructor!==Y)return new Y(a);if(a){var b=P(a)?a:a.preset;b&&(a=Object.assign({},Wa[b],a))}else a={};b=a.context;const e=b===!0?{depth:1}:b||{},d=P(a.encoder)?va[a.encoder]:a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new la(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&b!=="default"&&b!=="exact"&&b||"strict";this.depth=b==="strict"&&e.depth||0;this.bidirectional=e.bidirectional!==!1;this.fastupdate=!!a.fastupdate; this.score=a.score||null;b=!1;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.L=e.resolution||3;this.rtl=d.rtl||a.rtl||!1;this.cache=(b=a.cache||null)&&new T(b);this.priority=a.priority||4}B=Y.prototype;B.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this};B.append=function(a,c){return this.add(a,c,!0)};B.contain=function(a){return this.reg.has(a)}; B.update=function(a,c){const b=this,e=this.remove(a);return e&&e.then?e.then(()=>b.add(a,c)):this.add(a,c)};B.cleanup=function(){if(!this.fastupdate)return this;Va(this.map);this.depth&&Va(this.ctx);return this};B.searchCache=ma;B.export=function(a,c,b=0,e=0){let d,f;switch(e){case 0:d="reg";f=Ra(this.reg);break;case 1:d="cfg";f=null;break;case 2:d="map";f=Na(this.map,this.reg.size);break;case 3:d="ctx";f=Pa(this.ctx,this.reg.size);break;default:return}return Ta.call(this,a,c,d,f,b,e)}; B.import=function(a,c){if(c)switch(typeof c==="string"&&(c=JSON.parse(c)),a=a.split("."),a[a.length-1]==="json"&&a.pop(),a.length===3&&a.shift(),a=a.length>1?a[1]:a[0],a){case "reg":this.fastupdate=!1;this.reg=Sa(c,this.reg);break;case "map":this.map=Oa(c,this.map);break;case "ctx":this.ctx=Qa(c,this.ctx)}}; -B.serialize=function(a=!0){let c="",b="",e="";if(this.reg.size){let f;for(var d of this.reg.keys())f||(f=typeof d),c+=(c?",":"")+(f==="string"?'"'+d+'"':d);c="index.reg=new Set(["+c+"]);";b=Ua(this.map,f);b="index.map=new Map(["+b+"]);";for(const g of this.ctx.entries()){d=g[0];let h=Ua(g[1],f);h="new Map(["+h+"])";h='["'+d+'",'+h+"]";e+=(e?",":"")+h}e="index.ctx=new Map(["+e+"]);"}return a?"function inject(index){"+c+b+e+"}":c+b+e};wa(Y.prototype);N();export default {Index:Y,Charset:va,Encoder:la,Document:X,Worker:null,Resolver:null,IndexedDB:null,Language:{}}; +B.serialize=function(a=!0){let c="",b="",e="";if(this.reg.size){let f;for(var d of this.reg.keys())f||(f=typeof d),c+=(c?",":"")+(f==="string"?'"'+d+'"':d);c="index.reg=new Set(["+c+"]);";b=Ua(this.map,f);b="index.map=new Map(["+b+"]);";for(const g of this.ctx.entries()){d=g[0];let k=Ua(g[1],f);k="new Map(["+k+"])";k='["'+d+'",'+k+"]";e+=(e?",":"")+k}e="index.ctx=new Map(["+e+"]);"}return a?"function inject(index){"+c+b+e+"}":c+b+e};wa(Y.prototype);N();export default {Index:Y,Charset:va,Encoder:la,Document:X,Worker:null,Resolver:null,IndexedDB:null,Language:{}}; export const Index=Y;export const Charset=va;export const Encoder=la;export const Document=X;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.es5.debug.js b/dist/flexsearch.es5.debug.js index c693486..30531f4 100644 --- a/dist/flexsearch.es5.debug.js +++ b/dist/flexsearch.es5.debug.js @@ -1,5 +1,5 @@ /**! - * FlexSearch.js v0.8.203 (ES5/Debug) + * FlexSearch.js v0.8.205 (ES5/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH @@ -13,7 +13,7 @@ function aa(a) { return b < a.length ? {done:!1, value:a[b++]} : {done:!0}; }; } -function B(a) { +function D(a) { var b = typeof Symbol != "undefined" && Symbol.iterator && a[Symbol.iterator]; if (b) { return b.call(a); @@ -138,8 +138,8 @@ function ra(a, b, c, d) { return a.h.D = !1, e; } var f = e.value; - } catch (h) { - return a.h.A = null, na(a.h, h), sa(a); + } catch (g) { + return a.h.A = null, na(a.h, g), sa(a); } a.h.A = null; d.call(a.h, f); @@ -198,8 +198,8 @@ function va(a) { return a.throw(d); } return new Promise(function(d, e) { - function f(h) { - h.done ? d(h.value) : Promise.resolve(h.value).then(b, c).then(f, e); + function f(g) { + g.done ? d(g.value) : Promise.resolve(g.value).then(b, c).then(f, e); } f(a.next()); }); @@ -214,9 +214,9 @@ H("Symbol", function(a) { } return new c(d + (f || "") + "_" + e++, f); } - function c(f, h) { + function c(f, g) { this.h = f; - ca(this, "description", {configurable:!0, writable:!0, value:h}); + ca(this, "description", {configurable:!0, writable:!0, value:g}); } if (a) { return a; @@ -248,127 +248,127 @@ function xa(a) { return a; } H("Promise", function(a) { - function b(h) { + function b(g) { this.A = 0; this.B = void 0; this.h = []; this.K = !1; - var g = this.C(); + var h = this.C(); try { - h(g.resolve, g.reject); + g(h.resolve, h.reject); } catch (k) { - g.reject(k); + h.reject(k); } } function c() { this.h = null; } - function d(h) { - return h instanceof b ? h : new b(function(g) { - g(h); + function d(g) { + return g instanceof b ? g : new b(function(h) { + h(g); }); } if (a) { return a; } - c.prototype.A = function(h) { + c.prototype.A = function(g) { if (this.h == null) { this.h = []; - var g = this; + var h = this; this.B(function() { - g.D(); + h.D(); }); } - this.h.push(h); + this.h.push(g); }; var e = ea.setTimeout; - c.prototype.B = function(h) { - e(h, 0); + c.prototype.B = function(g) { + e(g, 0); }; c.prototype.D = function() { for (; this.h && this.h.length;) { - var h = this.h; + var g = this.h; this.h = []; - for (var g = 0; g < h.length; ++g) { - var k = h[g]; - h[g] = null; + for (var h = 0; h < g.length; ++h) { + var k = g[h]; + g[h] = null; try { k(); - } catch (m) { - this.C(m); + } catch (l) { + this.C(l); } } } this.h = null; }; - c.prototype.C = function(h) { + c.prototype.C = function(g) { this.B(function() { - throw h; + throw g; }); }; b.prototype.C = function() { - function h(m) { - return function(l) { - k || (k = !0, m.call(g, l)); + function g(l) { + return function(m) { + k || (k = !0, l.call(h, m)); }; } - var g = this, k = !1; - return {resolve:h(this.ea), reject:h(this.D)}; + var h = this, k = !1; + return {resolve:g(this.ea), reject:g(this.D)}; }; - b.prototype.ea = function(h) { - if (h === this) { + b.prototype.ea = function(g) { + if (g === this) { this.D(new TypeError("A Promise cannot resolve to itself")); } else { - if (h instanceof b) { - this.ga(h); + if (g instanceof b) { + this.ga(g); } else { a: { - switch(typeof h) { + switch(typeof g) { case "object": - var g = h != null; + var h = g != null; break a; case "function": - g = !0; + h = !0; break a; default: - g = !1; + h = !1; } } - g ? this.da(h) : this.I(h); + h ? this.da(g) : this.I(g); } } }; - b.prototype.da = function(h) { - var g = void 0; + b.prototype.da = function(g) { + var h = void 0; try { - g = h.then; + h = g.then; } catch (k) { this.D(k); return; } - typeof g == "function" ? this.ha(g, h) : this.I(h); + typeof h == "function" ? this.ha(h, g) : this.I(g); }; - b.prototype.D = function(h) { - this.L(2, h); + b.prototype.D = function(g) { + this.L(2, g); }; - b.prototype.I = function(h) { - this.L(1, h); + b.prototype.I = function(g) { + this.L(1, g); }; - b.prototype.L = function(h, g) { + b.prototype.L = function(g, h) { if (this.A != 0) { - throw Error("Cannot settle(" + h + ", " + g + "): Promise already settled in state" + this.A); + throw Error("Cannot settle(" + g + ", " + h + "): Promise already settled in state" + this.A); } - this.A = h; - this.B = g; + this.A = g; + this.B = h; this.A === 2 && this.fa(); this.P(); }; b.prototype.fa = function() { - var h = this; + var g = this; e(function() { - if (h.ca()) { - var g = ea.console; - typeof g !== "undefined" && g.error(h.B); + if (g.ca()) { + var h = ea.console; + typeof h !== "undefined" && h.error(g.B); } }, 1); }; @@ -376,99 +376,99 @@ H("Promise", function(a) { if (this.K) { return !1; } - var h = ea.CustomEvent, g = ea.Event, k = ea.dispatchEvent; + var g = ea.CustomEvent, h = ea.Event, k = ea.dispatchEvent; if (typeof k === "undefined") { return !0; } - typeof h === "function" ? h = new h("unhandledrejection", {cancelable:!0}) : typeof g === "function" ? h = new g("unhandledrejection", {cancelable:!0}) : (h = ea.document.createEvent("CustomEvent"), h.initCustomEvent("unhandledrejection", !1, !0, h)); - h.promise = this; - h.reason = this.B; - return k(h); + typeof g === "function" ? g = new g("unhandledrejection", {cancelable:!0}) : typeof h === "function" ? g = new h("unhandledrejection", {cancelable:!0}) : (g = ea.document.createEvent("CustomEvent"), g.initCustomEvent("unhandledrejection", !1, !0, g)); + g.promise = this; + g.reason = this.B; + return k(g); }; b.prototype.P = function() { if (this.h != null) { - for (var h = 0; h < this.h.length; ++h) { - f.A(this.h[h]); + for (var g = 0; g < this.h.length; ++g) { + f.A(this.h[g]); } this.h = null; } }; var f = new c(); - b.prototype.ga = function(h) { - var g = this.C(); - h.R(g.resolve, g.reject); + b.prototype.ga = function(g) { + var h = this.C(); + g.R(h.resolve, h.reject); }; - b.prototype.ha = function(h, g) { + b.prototype.ha = function(g, h) { var k = this.C(); try { - h.call(g, k.resolve, k.reject); - } catch (m) { - k.reject(m); + g.call(h, k.resolve, k.reject); + } catch (l) { + k.reject(l); } }; - b.prototype.then = function(h, g) { + b.prototype.then = function(g, h) { function k(n, q) { return typeof n == "function" ? function(t) { try { - m(n(t)); + l(n(t)); } catch (u) { - l(u); + m(u); } } : q; } - var m, l, p = new b(function(n, q) { - m = n; - l = q; + var l, m, p = new b(function(n, q) { + l = n; + m = q; }); - this.R(k(h, m), k(g, l)); + this.R(k(g, l), k(h, m)); return p; }; - b.prototype.catch = function(h) { - return this.then(void 0, h); + b.prototype.catch = function(g) { + return this.then(void 0, g); }; - b.prototype.R = function(h, g) { + b.prototype.R = function(g, h) { function k() { - switch(m.A) { + switch(l.A) { case 1: - h(m.B); + g(l.B); break; case 2: - g(m.B); + h(l.B); break; default: - throw Error("Unexpected state: " + m.A); + throw Error("Unexpected state: " + l.A); } } - var m = this; + var l = this; this.h == null ? f.A(k) : this.h.push(k); this.K = !0; }; b.resolve = d; - b.reject = function(h) { - return new b(function(g, k) { - k(h); + b.reject = function(g) { + return new b(function(h, k) { + k(g); }); }; - b.race = function(h) { - return new b(function(g, k) { - for (var m = B(h), l = m.next(); !l.done; l = m.next()) { - d(l.value).R(g, k); + b.race = function(g) { + return new b(function(h, k) { + for (var l = D(g), m = l.next(); !m.done; m = l.next()) { + d(m.value).R(h, k); } }); }; - b.all = function(h) { - var g = B(h), k = g.next(); - return k.done ? d([]) : new b(function(m, l) { + b.all = function(g) { + var h = D(g), k = h.next(); + return k.done ? d([]) : new b(function(l, m) { function p(t) { return function(u) { n[t] = u; q--; - q == 0 && m(n); + q == 0 && l(n); }; } var n = [], q = 0; do { - n.push(void 0), q++, d(k.value).R(p(n.length - 1), l), k = g.next(); + n.push(void 0), q++, d(k.value).R(p(n.length - 1), m), k = h.next(); } while (!k.done); }); }; @@ -508,34 +508,34 @@ function za(a, b) { } H("WeakMap", function(a) { function b(k) { - this.h = (g += Math.random() + 1).toString(); + this.h = (h += Math.random() + 1).toString(); if (k) { - k = B(k); - for (var m; !(m = k.next()).done;) { - m = m.value, this.set(m[0], m[1]); + k = D(k); + for (var l; !(l = k.next()).done;) { + l = l.value, this.set(l[0], l[1]); } } } function c() { } function d(k) { - var m = typeof k; - return m === "object" && k !== null || m === "function"; + var l = typeof k; + return l === "object" && k !== null || l === "function"; } function e(k) { - if (!za(k, h)) { - var m = new c(); - ca(k, h, {value:m}); + if (!za(k, g)) { + var l = new c(); + ca(k, g, {value:l}); } } function f(k) { - var m = Object[k]; - m && (Object[k] = function(l) { - if (l instanceof c) { - return l; + var l = Object[k]; + l && (Object[k] = function(m) { + if (m instanceof c) { + return m; } - Object.isExtensible(l) && e(l); - return m(l); + Object.isExtensible(m) && e(m); + return l(m); }); } if (function() { @@ -543,87 +543,87 @@ H("WeakMap", function(a) { return !1; } try { - var k = Object.seal({}), m = Object.seal({}), l = new a([[k, 2], [m, 3]]); - if (l.get(k) != 2 || l.get(m) != 3) { + var k = Object.seal({}), l = Object.seal({}), m = new a([[k, 2], [l, 3]]); + if (m.get(k) != 2 || m.get(l) != 3) { return !1; } - l.delete(k); - l.set(m, 4); - return !l.has(k) && l.get(m) == 4; + m.delete(k); + m.set(l, 4); + return !m.has(k) && m.get(l) == 4; } catch (p) { return !1; } }()) { return a; } - var h = "$jscomp_hidden_" + Math.random(); + var g = "$jscomp_hidden_" + Math.random(); f("freeze"); f("preventExtensions"); f("seal"); - var g = 0; - b.prototype.set = function(k, m) { + var h = 0; + b.prototype.set = function(k, l) { if (!d(k)) { throw Error("Invalid WeakMap key"); } e(k); - if (!za(k, h)) { + if (!za(k, g)) { throw Error("WeakMap key fail: " + k); } - k[h][this.h] = m; + k[g][this.h] = l; return this; }; b.prototype.get = function(k) { - return d(k) && za(k, h) ? k[h][this.h] : void 0; + return d(k) && za(k, g) ? k[g][this.h] : void 0; }; b.prototype.has = function(k) { - return d(k) && za(k, h) && za(k[h], this.h); + return d(k) && za(k, g) && za(k[g], this.h); }; b.prototype.delete = function(k) { - return d(k) && za(k, h) && za(k[h], this.h) ? delete k[h][this.h] : !1; + return d(k) && za(k, g) && za(k[g], this.h) ? delete k[g][this.h] : !1; }; return b; }); H("Map", function(a) { function b() { - var g = {}; - return g.J = g.next = g.head = g; + var h = {}; + return h.J = h.next = h.head = h; } - function c(g, k) { - var m = g[1]; + function c(h, k) { + var l = h[1]; return xa(function() { - if (m) { - for (; m.head != g[1];) { - m = m.J; + if (l) { + for (; l.head != h[1];) { + l = l.J; } - for (; m.next != m.head;) { - return m = m.next, {done:!1, value:k(m)}; + for (; l.next != l.head;) { + return l = l.next, {done:!1, value:k(l)}; } - m = null; + l = null; } return {done:!0, value:void 0}; }); } - function d(g, k) { - var m = k && typeof k; - m == "object" || m == "function" ? f.has(k) ? m = f.get(k) : (m = "" + ++h, f.set(k, m)) : m = "p_" + k; - var l = g[0][m]; - if (l && za(g[0], m)) { - for (g = 0; g < l.length; g++) { - var p = l[g]; + function d(h, k) { + var l = k && typeof k; + l == "object" || l == "function" ? f.has(k) ? l = f.get(k) : (l = "" + ++g, f.set(k, l)) : l = "p_" + k; + var m = h[0][l]; + if (m && za(h[0], l)) { + for (h = 0; h < m.length; h++) { + var p = m[h]; if (k !== k && p.key !== p.key || k === p.key) { - return {id:m, list:l, index:g, G:p}; + return {id:l, list:m, index:h, G:p}; } } } - return {id:m, list:l, index:-1, G:void 0}; + return {id:l, list:m, index:-1, G:void 0}; } - function e(g) { + function e(h) { this[0] = {}; this[1] = b(); this.size = 0; - if (g) { - g = B(g); - for (var k; !(k = g.next()).done;) { + if (h) { + h = D(h); + for (var k; !(k = h.next()).done;) { k = k.value, this.set(k[0], k[1]); } } @@ -633,16 +633,16 @@ H("Map", function(a) { return !1; } try { - var g = Object.seal({x:4}), k = new a(B([[g, "s"]])); - if (k.get(g) != "s" || k.size != 1 || k.get({x:4}) || k.set({x:4}, "t") != k || k.size != 2) { + var h = Object.seal({x:4}), k = new a(D([[h, "s"]])); + if (k.get(h) != "s" || k.size != 1 || k.get({x:4}) || k.set({x:4}, "t") != k || k.size != 2) { return !1; } - var m = k.entries(), l = m.next(); - if (l.done || l.value[0] != g || l.value[1] != "s") { + var l = k.entries(), m = l.next(); + if (m.done || m.value[0] != h || m.value[1] != "s") { return !1; } - l = m.next(); - return l.done || l.value[0].x != 4 || l.value[1] != "t" || !m.next().done ? !1 : !0; + m = l.next(); + return m.done || m.value[0].x != 4 || m.value[1] != "t" || !l.next().done ? !1 : !0; } catch (p) { return !1; } @@ -650,57 +650,57 @@ H("Map", function(a) { return a; } var f = new WeakMap(); - e.prototype.set = function(g, k) { - g = g === 0 ? 0 : g; - var m = d(this, g); - m.list || (m.list = this[0][m.id] = []); - m.G ? m.G.value = k : (m.G = {next:this[1], J:this[1].J, head:this[1], key:g, value:k}, m.list.push(m.G), this[1].J.next = m.G, this[1].J = m.G, this.size++); + e.prototype.set = function(h, k) { + h = h === 0 ? 0 : h; + var l = d(this, h); + l.list || (l.list = this[0][l.id] = []); + l.G ? l.G.value = k : (l.G = {next:this[1], J:this[1].J, head:this[1], key:h, value:k}, l.list.push(l.G), this[1].J.next = l.G, this[1].J = l.G, this.size++); return this; }; - e.prototype.delete = function(g) { - g = d(this, g); - return g.G && g.list ? (g.list.splice(g.index, 1), g.list.length || delete this[0][g.id], g.G.J.next = g.G.next, g.G.next.J = g.G.J, g.G.head = null, this.size--, !0) : !1; + e.prototype.delete = function(h) { + h = d(this, h); + return h.G && h.list ? (h.list.splice(h.index, 1), h.list.length || delete this[0][h.id], h.G.J.next = h.G.next, h.G.next.J = h.G.J, h.G.head = null, this.size--, !0) : !1; }; e.prototype.clear = function() { this[0] = {}; this[1] = this[1].J = b(); this.size = 0; }; - e.prototype.has = function(g) { - return !!d(this, g).G; + e.prototype.has = function(h) { + return !!d(this, h).G; }; - e.prototype.get = function(g) { - return (g = d(this, g).G) && g.value; + e.prototype.get = function(h) { + return (h = d(this, h).G) && h.value; }; e.prototype.entries = function() { - return c(this, function(g) { - return [g.key, g.value]; + return c(this, function(h) { + return [h.key, h.value]; }); }; e.prototype.keys = function() { - return c(this, function(g) { - return g.key; + return c(this, function(h) { + return h.key; }); }; e.prototype.values = function() { - return c(this, function(g) { - return g.value; + return c(this, function(h) { + return h.value; }); }; - e.prototype.forEach = function(g, k) { - for (var m = this.entries(), l; !(l = m.next()).done;) { - l = l.value, g.call(k, l[1], l[0], this); + e.prototype.forEach = function(h, k) { + for (var l = this.entries(), m; !(m = l.next()).done;) { + m = m.value, h.call(k, m[1], m[0], this); } }; e.prototype[Symbol.iterator] = e.prototype.entries; - var h = 0; + var g = 0; return e; }); H("Set", function(a) { function b(c) { this.h = new Map(); if (c) { - c = B(c); + c = D(c); for (var d; !(d = c.next()).done;) { this.add(d.value); } @@ -712,7 +712,7 @@ H("Set", function(a) { return !1; } try { - var c = Object.seal({x:4}), d = new a(B([c])); + var c = Object.seal({x:4}), d = new a(D([c])); if (!d.has(c) || d.size != 1 || d.add(c) != d || d.size != 1 || d.add({x:4}) != d || d.size != 2) { return !1; } @@ -722,7 +722,7 @@ H("Set", function(a) { } f = e.next(); return f.done || f.value[0] == c || f.value[0].x != 4 || f.value[1] != f.value[0] ? !1 : e.next().done; - } catch (h) { + } catch (g) { return !1; } }()) { @@ -854,7 +854,7 @@ function P(a, b, c) { } if (b === Map) { b = new Map(c); - d = B(a); + d = D(a); for (e = d.next(); !e.done; e = d.next()) { e = e.value, b.set(e[0], e[1]); } @@ -862,7 +862,7 @@ function P(a, b, c) { } if (b === Set) { b = new Set(c); - d = B(a.values()); + d = D(a.values()); for (e = d.next(); !e.done; e = d.next()) { b.add(e.value); } @@ -882,22 +882,14 @@ function Ba(a, b) { function S() { return Object.create(null); } -function T(a) { +function U(a) { return typeof a === "string"; } function Ca(a) { return typeof a === "object"; } -function Da(a) { - var b = []; - a = B(a.keys()); - for (var c = a.next(); !c.done; c = a.next()) { - b.push(c.value); - } - return b; -} -function Ea(a, b) { - if (T(b)) { +function Da(a, b) { + if (U(b)) { a = a[b]; } else { for (var c = 0; a && c < b.length; c++) { @@ -906,21 +898,21 @@ function Ea(a, b) { } return a; } -;var Fa = /[^\p{L}\p{N}]+/u, Ga = /(\d{3})/g, Ha = /(\D)(\d{3})/g, Ia = /(\d{3})(\D)/g, Ja = /[\u0300-\u036f]/g; -function Ka(a) { +;var Ea = /[^\p{L}\p{N}]+/u, Fa = /(\d{3})/g, Ga = /(\D)(\d{3})/g, Ha = /(\d{3})(\D)/g, Ia = /[\u0300-\u036f]/g; +function Ja(a) { a = a === void 0 ? {} : a; - if (!this || this.constructor !== Ka) { + if (!this || this.constructor !== Ja) { var b = Function.prototype.bind, c = b.apply, d = [null], e = d.concat; if (arguments instanceof Array) { var f = arguments; } else { - f = B(arguments); - for (var h, g = []; !(h = f.next()).done;) { - g.push(h.value); + f = D(arguments); + for (var g, h = []; !(g = f.next()).done;) { + h.push(g.value); } - f = g; + f = h; } - return new (c.call(b, Ka, e.call(d, f)))(); + return new (c.call(b, Ja, e.call(d, f)))(); } if (arguments.length) { for (b = 0; b < arguments.length; b++) { @@ -930,7 +922,7 @@ function Ka(a) { this.assign(a); } } -w = Ka.prototype; +w = Ja.prototype; w.assign = function(a) { this.normalize = P(a.normalize, !0, this.normalize); var b = a.include, c = b || a.exclude || a.split; @@ -958,7 +950,7 @@ w.assign = function(a) { this.numeric = P(a.numeric, e); } else { try { - this.split = P(this.split, Fa); + this.split = P(this.split, Ea); } catch (f) { console.warn("This platform does not support unicode regex. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } @@ -984,12 +976,12 @@ w.assign = function(a) { this.A = ""; this.L = null; if (this.matcher) { - for (a = B(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { + for (a = D(this.matcher.keys()), b = a.next(); !b.done; b = a.next()) { this.h += (this.h ? "|" : "") + b.value; } } if (this.stemmer) { - for (a = B(this.stemmer.keys()), b = a.next(); !b.done; b = a.next()) { + for (a = D(this.stemmer.keys()), b = a.next(); !b.done; b = a.next()) { this.A += (this.A ? "|" : "") + b.value; } } @@ -1000,12 +992,12 @@ w.addStemmer = function(a, b) { this.stemmer.set(a, b); this.A += (this.A ? "|" : "") + a; this.L = null; - this.cache && La(this); + this.cache && Ka(this); return this; }; w.addFilter = function(a) { typeof a === "function" ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); - this.cache && La(this); + this.cache && Ka(this); return this; }; w.addMapper = function(a, b) { @@ -1017,7 +1009,7 @@ w.addMapper = function(a, b) { } this.mapper || (this.mapper = new Map()); this.mapper.set(a, b); - this.cache && La(this); + this.cache && Ka(this); return this; }; w.addMatcher = function(a, b) { @@ -1031,7 +1023,7 @@ w.addMatcher = function(a, b) { this.matcher.set(a, b); this.h += (this.h ? "|" : "") + a; this.K = null; - this.cache && La(this); + this.cache && Ka(this); return this; }; w.addReplacer = function(a, b) { @@ -1040,7 +1032,7 @@ w.addReplacer = function(a, b) { } this.replacer || (this.replacer = []); this.replacer.push(a, b); - this.cache && La(this); + this.cache && Ka(this); return this; }; w.encode = function(a, b) { @@ -1051,78 +1043,78 @@ w.encode = function(a, b) { return this.B.get(a); } } else { - this.D = setTimeout(La, 50, this); + this.D = setTimeout(Ka, 50, this); } } - this.normalize && (typeof this.normalize === "function" ? a = this.normalize(a) : a = Ja ? a.normalize("NFKD").replace(Ja, "").toLowerCase() : a.toLowerCase()); + this.normalize && (typeof this.normalize === "function" ? a = this.normalize(a) : a = Ia ? a.normalize("NFKD").replace(Ia, "").toLowerCase() : a.toLowerCase()); this.prepare && (a = this.prepare(a)); - this.numeric && a.length > 3 && (a = a.replace(Ha, "$1 $2").replace(Ia, "$1 $2").replace(Ga, "$1 ")); - for (var d = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), e = [], f = S(), h, g, k = this.split || this.split === "" ? a.split(this.split) : [a], m = 0, l = void 0, p = void 0; m < k.length; m++) { - if ((l = p = k[m]) && !(l.length < this.minlength || l.length > this.maxlength)) { + this.numeric && a.length > 3 && (a = a.replace(Ga, "$1 $2").replace(Ha, "$1 $2").replace(Fa, "$1 ")); + for (var d = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer), e = [], f = S(), g, h, k = this.split || this.split === "" ? a.split(this.split) : [a], l = 0, m = void 0, p = void 0; l < k.length; l++) { + if ((m = p = k[l]) && !(m.length < this.minlength || m.length > this.maxlength)) { if (b) { - if (f[l]) { + if (f[m]) { continue; } - f[l] = 1; + f[m] = 1; } else { - if (h === l) { + if (g === m) { continue; } - h = l; + g = m; } if (d) { - e.push(l); + e.push(m); } else { - if (!this.filter || (typeof this.filter === "function" ? this.filter(l) : !this.filter.has(l))) { - if (this.cache && l.length <= this.I) { + if (!this.filter || (typeof this.filter === "function" ? this.filter(m) : !this.filter.has(m))) { + if (this.cache && m.length <= this.I) { if (this.D) { - var n = this.C.get(l); + var n = this.C.get(m); if (n || n === "") { n && e.push(n); continue; } } else { - this.D = setTimeout(La, 50, this); + this.D = setTimeout(Ka, 50, this); } } if (this.stemmer) { - for (this.L || (this.L = new RegExp("(?!^)(" + this.A + ")$")), n = void 0; n !== l && l.length > 2;) { - n = l, l = l.replace(this.L, function(z) { - return c.stemmer.get(z); + for (this.L || (this.L = new RegExp("(?!^)(" + this.A + ")$")), n = void 0; n !== m && m.length > 2;) { + n = m, m = m.replace(this.L, function(B) { + return c.stemmer.get(B); }); } } - if (l && (this.mapper || this.dedupe && l.length > 1)) { + if (m && (this.mapper || this.dedupe && m.length > 1)) { n = ""; - for (var q = 0, t = "", u = void 0, v = void 0; q < l.length; q++) { - u = l.charAt(q), u === t && this.dedupe || ((v = this.mapper && this.mapper.get(u)) || v === "" ? v === t && this.dedupe || !(t = v) || (n += v) : n += t = u); + for (var q = 0, t = "", u = void 0, v = void 0; q < m.length; q++) { + u = m.charAt(q), u === t && this.dedupe || ((v = this.mapper && this.mapper.get(u)) || v === "" ? v === t && this.dedupe || !(t = v) || (n += v) : n += t = u); } - l = n; + m = n; } - this.matcher && l.length > 1 && (this.K || (this.K = new RegExp("(" + this.h + ")", "g")), l = l.replace(this.K, function(z) { - return c.matcher.get(z); + this.matcher && m.length > 1 && (this.K || (this.K = new RegExp("(" + this.h + ")", "g")), m = m.replace(this.K, function(B) { + return c.matcher.get(B); })); - if (l && this.replacer) { - for (n = 0; l && n < this.replacer.length; n += 2) { - l = l.replace(this.replacer[n], this.replacer[n + 1]); + if (m && this.replacer) { + for (n = 0; m && n < this.replacer.length; n += 2) { + m = m.replace(this.replacer[n], this.replacer[n + 1]); } } - this.cache && p.length <= this.I && (this.C.set(p, l), this.C.size > this.P && (this.C.clear(), this.I = this.I / 1.1 | 0)); - if (l) { - if (l !== p) { + this.cache && p.length <= this.I && (this.C.set(p, m), this.C.size > this.P && (this.C.clear(), this.I = this.I / 1.1 | 0)); + if (m) { + if (m !== p) { if (b) { - if (f[l]) { + if (f[m]) { continue; } - f[l] = 1; + f[m] = 1; } else { - if (g === l) { + if (h === m) { continue; } - g = l; + h = m; } } - e.push(l); + e.push(m); } } } @@ -1132,12 +1124,12 @@ w.encode = function(a, b) { this.cache && a.length <= this.H && (this.B.set(a, e), this.B.size > this.P && (this.B.clear(), this.H = this.H / 1.1 | 0)); return e; }; -function La(a) { +function Ka(a) { a.D = null; a.B.clear(); a.C.clear(); } -;function Ma(a, b, c) { +;function La(a, b, c) { c || (b || typeof a !== "object" ? typeof b === "object" && (c = b, b = 0) : c = a); c && (a = c.query || a, b = c.limit || b); var d = "" + (b || 0); @@ -1146,7 +1138,7 @@ function La(a) { d += (e.offset || 0) + !!e.context + !!e.suggest + (e.resolve !== !1) + (e.resolution || this.resolution) + (e.boost || 0); } a = ("" + a).toLowerCase(); - this.cache || (this.cache = new Na()); + this.cache || (this.cache = new Ma()); e = this.cache.get(a + d); if (!e) { var f = c && c.cache; @@ -1157,51 +1149,51 @@ function La(a) { } return e; } -function Na(a) { +function Ma(a) { this.limit = a && a !== !0 ? a : 1000; this.cache = new Map(); this.h = ""; } -Na.prototype.set = function(a, b) { +Ma.prototype.set = function(a, b) { this.cache.set(this.h = a, b); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -Na.prototype.get = function(a) { +Ma.prototype.get = function(a) { var b = this.cache.get(a); b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); return b; }; -Na.prototype.remove = function(a) { - for (var b = B(this.cache), c = b.next(); !c.done; c = b.next()) { +Ma.prototype.remove = function(a) { + for (var b = D(this.cache), c = b.next(); !c.done; c = b.next()) { c = c.value; var d = c[0]; c[1].includes(a) && this.cache.delete(d); } }; -Na.prototype.clear = function() { +Ma.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -var Oa = {normalize:!1, numeric:!1, dedupe:!1}; -var Pa = {}; -var Qa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -var Ra = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Sa = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; -var Ta = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -var Ua = {Exact:Oa, Default:Pa, Normalize:Pa, LatinBalance:{mapper:Qa}, LatinAdvanced:{mapper:Qa, matcher:Ra, replacer:Sa}, LatinExtra:{mapper:Qa, replacer:Sa.concat([/(?!^)[aeo]/g, ""]), matcher:Ra}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { +var Na = {normalize:!1, numeric:!1, dedupe:!1}; +var Oa = {}; +var Pa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +var Qa = new Map([["ae", "a"], ["oe", "o"], ["sh", "s"], ["kh", "k"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ra = [/([^aeo])h(.)/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2", /(.)\1+/g, "$1"]; +var Sa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +var Ta = {Exact:Na, Default:Oa, Normalize:Oa, LatinBalance:{mapper:Pa}, LatinAdvanced:{mapper:Pa, matcher:Qa, replacer:Ra}, LatinExtra:{mapper:Pa, replacer:Ra.concat([/(?!^)[aeo]/g, ""]), matcher:Qa}, LatinSoundex:{dedupe:!1, include:{letter:!0}, finalize:function(a) { for (var b = 0; b < a.length; b++) { - for (var c = a[b], d = c.charAt(0), e = Ta[d], f = 1, h; f < c.length && (h = c.charAt(f), h === "h" || h === "w" || !(h = Ta[h]) || h === e || (d += h, e = h, d.length !== 4)); f++) { + for (var c = a[b], d = c.charAt(0), e = Sa[d], f = 1, g; f < c.length && (g = c.charAt(f), g === "h" || g === "w" || !(g = Sa[g]) || g === e || (d += g, e = g, d.length !== 4)); f++) { } a[b] = d; } -}}, CJK:{split:""}, LatinExact:Oa, LatinDefault:Pa, LatinSimple:Pa}; -function Va(a, b, c, d) { - for (var e = [], f = 0, h; f < a.index.length; f++) { - if (h = a.index[f], b >= h.length) { - b -= h.length; +}}, CJK:{split:""}, LatinExact:Na, LatinDefault:Oa, LatinSimple:Oa}; +function Ua(a, b, c, d) { + for (var e = [], f = 0, g; f < a.index.length; f++) { + if (g = a.index[f], b >= g.length) { + b -= g.length; } else { - b = h[d ? "splice" : "slice"](b, c); - if (h = b.length) { - if (e = e.length ? e.concat(b) : b, c -= h, d && (a.length -= h), !c) { + b = g[d ? "splice" : "slice"](b, c); + if (g = b.length) { + if (e = e.length ? e.concat(b) : b, c -= g, d && (a.length -= g), !c) { break; } } @@ -1210,9 +1202,9 @@ function Va(a, b, c, d) { } return e; } -function Wa(a) { - if (!this || this.constructor !== Wa) { - return new Wa(a); +function Va(a) { + if (!this || this.constructor !== Va) { + return new Va(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -1236,13 +1228,13 @@ function Wa(a) { } if (d === "indexOf") { return function(e) { - for (var f = 0, h = 0, g, k; h < b.index.length; h++) { - g = b.index[h]; - k = g.indexOf(e); + for (var f = 0, g = 0, h, k; g < b.index.length; g++) { + h = b.index[g]; + k = h.indexOf(e); if (k >= 0) { return f + k; } - f += g.length; + f += h.length; } return -1; }; @@ -1259,12 +1251,12 @@ function Wa(a) { } if (d === "slice") { return function(e, f) { - return Va(b, e || 0, f || b.length, !1); + return Ua(b, e || 0, f || b.length, !1); }; } if (d === "splice") { return function(e, f) { - return Va(b, e || 0, f || b.length, !0); + return Ua(b, e || 0, f || b.length, !0); }; } if (d === "constructor") { @@ -1280,28 +1272,10 @@ function Wa(a) { return !0; }}); } -Wa.prototype.clear = function() { +Va.prototype.clear = function() { this.index.length = 0; }; -Wa.prototype.push = function() { -}; -function Xa(a) { - a = a === void 0 ? 8 : a; - if (!this || this.constructor !== Xa) { - return new Xa(a); - } - this.index = S(); - this.h = []; - this.size = 0; - a > 32 ? (this.A = Ya, this.B = BigInt(a)) : (this.A = Za, this.B = a); -} -Xa.prototype.get = function(a) { - var b = this.A(a); - return (b = this.index[b]) && b.get(a); -}; -Xa.prototype.set = function(a, b) { - var c = this.A(a), d = this.index[c]; - d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.h.push(d), this.size++); +Va.prototype.push = function() { }; function X(a) { a = a === void 0 ? 8 : a; @@ -1311,105 +1285,123 @@ function X(a) { this.index = S(); this.h = []; this.size = 0; - a > 32 ? (this.A = Ya, this.B = BigInt(a)) : (this.A = Za, this.B = a); + a > 32 ? (this.A = Wa, this.B = BigInt(a)) : (this.A = Xa, this.B = a); } -X.prototype.add = function(a) { +X.prototype.get = function(a) { + var b = this.A(a); + return (b = this.index[b]) && b.get(a); +}; +X.prototype.set = function(a, b) { + var c = this.A(a), d = this.index[c]; + d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.h.push(d), this.size++); +}; +function Y(a) { + a = a === void 0 ? 8 : a; + if (!this || this.constructor !== Y) { + return new Y(a); + } + this.index = S(); + this.h = []; + this.size = 0; + a > 32 ? (this.A = Wa, this.B = BigInt(a)) : (this.A = Xa, this.B = a); +} +Y.prototype.add = function(a) { var b = this.A(a), c = this.index[b]; c ? (b = c.size, c.add(a), (b -= c.size) && this.size++) : (this.index[b] = c = new Set([a]), this.h.push(c), this.size++); }; -w = Xa.prototype; -w.has = X.prototype.has = function(a) { +w = X.prototype; +w.has = Y.prototype.has = function(a) { var b = this.A(a); return (b = this.index[b]) && b.has(a); }; -w.delete = X.prototype.delete = function(a) { +w.delete = Y.prototype.delete = function(a) { var b = this.A(a); (b = this.index[b]) && b.delete(a) && this.size--; }; -w.clear = X.prototype.clear = function() { +w.clear = Y.prototype.clear = function() { this.index = S(); this.h = []; this.size = 0; }; -w.values = X.prototype.values = function $a() { +w.values = Y.prototype.values = function Ya() { var b, c = this, d, e, f; - return ua($a, function(h) { - switch(h.h) { + return ua(Ya, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - h.h = 0; + g.h = 0; break; } - d = B(c.h[b].values()); + d = D(c.h[b].values()); e = d.next(); case 5: if (e.done) { b++; - h.h = 2; + g.h = 2; break; } f = e.value; - return K(h, f, 6); + return K(g, f, 6); case 6: - e = d.next(), h.h = 5; + e = d.next(), g.h = 5; } }); }; -w.keys = X.prototype.keys = function ab() { +w.keys = Y.prototype.keys = function Za() { var b, c = this, d, e, f; - return ua(ab, function(h) { - switch(h.h) { + return ua(Za, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - h.h = 0; + g.h = 0; break; } - d = B(c.h[b].keys()); + d = D(c.h[b].keys()); e = d.next(); case 5: if (e.done) { b++; - h.h = 2; + g.h = 2; break; } f = e.value; - return K(h, f, 6); + return K(g, f, 6); case 6: - e = d.next(), h.h = 5; + e = d.next(), g.h = 5; } }); }; -w.entries = X.prototype.entries = function bb() { +w.entries = Y.prototype.entries = function $a() { var b, c = this, d, e, f; - return ua(bb, function(h) { - switch(h.h) { + return ua($a, function(g) { + switch(g.h) { case 1: b = 0; case 2: if (!(b < c.h.length)) { - h.h = 0; + g.h = 0; break; } - d = B(c.h[b].entries()); + d = D(c.h[b].entries()); e = d.next(); case 5: if (e.done) { b++; - h.h = 2; + g.h = 2; break; } f = e.value; - return K(h, f, 6); + return K(g, f, 6); case 6: - e = d.next(), h.h = 5; + e = d.next(), g.h = 5; } }); }; -function Za(a) { +function Xa(a) { var b = Math.pow(2, this.B) - 1; if (typeof a == "number") { return a & b; @@ -1419,14 +1411,14 @@ function Za(a) { } return this.B === 32 ? c + 2147483648 : c; } -function Ya() { +function Wa() { throw Error("The keystore is limited to 32 for EcmaScript5"); } -;var cb, db; -function eb(a) { - var b, c, d, e, f, h; - return wa(function(g) { - switch(g.h) { +;var ab, bb; +function cb(a) { + var b, c, d, e, f, g; + return wa(function(h) { + switch(h.h) { case 1: a = a.data; b = a.task; @@ -1434,114 +1426,114 @@ function eb(a) { d = a.args; switch(b) { case "init": - db = a.options || {}; - (e = a.factory) ? (Function("return " + e)()(self), cb = new self.FlexSearch.Index(db), delete self.FlexSearch) : cb = new Y(db); + bb = a.options || {}; + (e = a.factory) ? (Function("return " + e)()(self), ab = new self.FlexSearch.Index(bb), delete self.FlexSearch) : ab = new db(bb); postMessage({id:c}); break; default: - g.h = 2; + h.h = 2; return; - }g.h = 0; + }h.h = 0; break; case 2: if (b === "export") { - if (!db.export || typeof db.export !== "function") { + if (!bb.export || typeof bb.export !== "function") { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "export".'); } - d[1] ? (d[0] = db.export, d[2] = 0, d[3] = 1) : d = null; + d[1] ? (d[0] = bb.export, d[2] = 0, d[3] = 1) : d = null; } if (b === "import") { - if (!db.import || typeof db.import !== "function") { + if (!bb.import || typeof bb.import !== "function") { throw Error('Either no extern configuration provided for the Worker-Index or no method was defined on the config property "import".'); } if (!d[0]) { - g.h = 5; + h.h = 5; break; } - return K(g, db.import.call(cb, d[0]), 11); + return K(h, bb.import.call(ab, d[0]), 11); } - f = d && cb[b].apply(cb, d); + f = d && ab[b].apply(ab, d); if (!f || !f.then) { - g.h = 6; + h.h = 6; break; } - return K(g, f, 7); + return K(h, f, 7); case 7: - f = g.B; + f = h.B; case 6: if (!f || !f.await) { - g.h = 8; + h.h = 8; break; } - return K(g, f.await, 9); + return K(h, f.await, 9); case 9: - f = g.B; + f = h.B; case 8: b === "search" && f.result && (f = f.result); - g.h = 5; + h.h = 5; break; case 11: - h = g.B, cb.import(d[0], h); + g = h.B, ab.import(d[0], g); case 5: - postMessage(b === "search" ? {id:c, msg:f} : {id:c}), g.h = 0; + postMessage(b === "search" ? {id:c, msg:f} : {id:c}), h.h = 0; } }); } -;function fb(a) { - gb.call(a, "add"); - gb.call(a, "append"); - gb.call(a, "search"); - gb.call(a, "update"); - gb.call(a, "remove"); - gb.call(a, "searchCache"); +;function eb(a) { + fb.call(a, "add"); + fb.call(a, "append"); + fb.call(a, "search"); + fb.call(a, "update"); + fb.call(a, "remove"); + fb.call(a, "searchCache"); } -var hb, ib, jb; -function kb() { - hb = jb = 0; +var gb, hb, ib; +function jb() { + gb = ib = 0; } -function gb(a) { +function fb(a) { this[a + "Async"] = function() { var b = arguments, c = b[b.length - 1]; if (typeof c === "function") { var d = c; delete b[b.length - 1]; } - hb ? jb || (jb = Date.now() - ib >= this.priority * this.priority * 3) : (hb = setTimeout(kb, 0), ib = Date.now()); - if (jb) { + gb ? ib || (ib = Date.now() - hb >= this.priority * this.priority * 3) : (gb = setTimeout(jb, 0), hb = Date.now()); + if (ib) { var e = this; - return new Promise(function(h) { + return new Promise(function(g) { setTimeout(function() { - h(e[a + "Async"].apply(e, b)); + g(e[a + "Async"].apply(e, b)); }, 0); }); } var f = this[a].apply(this, b); - c = f.then ? f : new Promise(function(h) { - return h(f); + c = f.then ? f : new Promise(function(g) { + return g(f); }); d && c.then(d); return c; }; } -;var lb = 0; -function mb(a, b) { - function c(g) { - function k(m) { - m = m.data || m; - var l = m.id, p = l && f.h[l]; - p && (p(m.msg), delete f.h[l]); +;var kb = 0; +function lb(a, b) { + function c(h) { + function k(l) { + l = l.data || l; + var m = l.id, p = m && f.h[m]; + p && (p(l.msg), delete f.h[m]); } - this.worker = g; + this.worker = h; this.h = S(); if (this.worker) { e ? this.worker.on("message", k) : this.worker.onmessage = k; if (a.config) { - return new Promise(function(m) { - lb > 1e9 && (lb = 0); - f.h[++lb] = function() { - m(f); + return new Promise(function(l) { + kb > 1e9 && (kb = 0); + f.h[++kb] = function() { + l(f); }; - f.worker.postMessage({id:lb, task:"init", factory:d, options:a}); + f.worker.postMessage({id:kb, task:"init", factory:d, options:a}); }); } this.priority = a.priority || 4; @@ -1552,28 +1544,28 @@ function mb(a, b) { console.warn("Worker is not available on this platform. Please report on Github: https://github.com/nextapps-de/flexsearch/issues"); } a = a === void 0 ? {} : a; - if (!this || this.constructor !== mb) { - return new mb(a); + if (!this || this.constructor !== lb) { + return new lb(a); } var d = typeof self !== "undefined" ? self._factory : typeof window !== "undefined" ? window._factory : null; d && (d = d.toString()); - var e = typeof window === "undefined", f = this, h = nb(d, e, a.worker); - return h.then ? h.then(function(g) { - return c.call(f, g); - }) : c.call(this, h); + var e = typeof window === "undefined", f = this, g = mb(d, e, a.worker); + return g.then ? g.then(function(h) { + return c.call(f, h); + }) : c.call(this, g); } -ob("add"); -ob("append"); -ob("search"); -ob("update"); -ob("remove"); -ob("clear"); -ob("export"); -ob("import"); -mb.prototype.searchCache = Ma; -fb(mb.prototype); -function ob(a) { - mb.prototype[a] = function() { +nb("add"); +nb("append"); +nb("search"); +nb("update"); +nb("remove"); +nb("clear"); +nb("export"); +nb("import"); +lb.prototype.searchCache = La; +eb(lb.prototype); +function nb(a) { + lb.prototype[a] = function() { var b = this, c = [].slice.call(arguments), d = c[c.length - 1]; if (typeof d === "function") { var e = d; @@ -1581,19 +1573,19 @@ function ob(a) { } d = new Promise(function(f) { a === "export" && typeof c[0] === "function" && (c[0] = null); - lb > 1e9 && (lb = 0); - b.h[++lb] = f; - b.worker.postMessage({task:a, id:lb, args:c}); + kb > 1e9 && (kb = 0); + b.h[++kb] = f; + b.worker.postMessage({task:a, id:kb, args:c}); }); return e ? (d.then(e), this) : d; }; } -function nb(a, b, c) { - return b ? typeof module !== "undefined" ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + eb.toString()], {type:"text/javascript"}))) : new window.Worker(typeof c === "string" ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", +function mb(a, b, c) { + return b ? typeof module !== "undefined" ? new(require("worker_threads")["Worker"])(__dirname+"/node/node.js") : import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + cb.toString()], {type:"text/javascript"}))) : new window.Worker(typeof c === "string" ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js"), {type:"module"}); } -;pb.prototype.add = function(a, b, c) { - Ca(a) && (b = a, a = Ea(b, this.key)); +;ob.prototype.add = function(a, b, c) { + Ca(a) && (b = a, a = Da(b, this.key)); if (b && (a || a === 0)) { if (!c && this.reg.has(a)) { return this.update(a, b); @@ -1602,56 +1594,56 @@ function nb(a, b, c) { e = this.B[d]; var f = this.index.get(this.field[d]); if (typeof e === "function") { - (e = e(b)) && f.add(a, e, !1, !0); + (e = e(b)) && f.add(a, e, c, !0); } else { - var h = e.O; - if (!h || h(b)) { - e.constructor === String ? e = ["" + e] : T(e) && (e = [e]), qb(b, e, this.C, 0, f, a, e[0], c); + var g = e.M; + if (!g || g(b)) { + e.constructor === String ? e = ["" + e] : U(e) && (e = [e]), pb(b, e, this.C, 0, f, a, e[0], c); } } } if (this.tag) { for (d = 0; d < this.A.length; d++) { - h = this.A[d]; - var g = this.D[d]; - f = this.tag.get(g); + g = this.A[d]; + var h = this.D[d]; + f = this.tag.get(h); e = S(); - if (typeof h === "function") { - if (h = h(b), !h) { + if (typeof g === "function") { + if (g = g(b), !g) { continue; } } else { - var k = h.O; + var k = g.M; if (k && !k(b)) { continue; } - h.constructor === String && (h = "" + h); - h = Ea(b, h); + g.constructor === String && (g = "" + g); + g = Da(b, g); } - if (f && h) { - for (T(h) && (h = [h]), g = 0, k = void 0; g < h.length; g++) { - var m = h[g]; - if (!e[m]) { - e[m] = 1; - var l; - (l = f.get(m)) ? k = l : f.set(m, k = []); + if (f && g) { + for (U(g) && (g = [g]), h = 0, k = void 0; h < g.length; h++) { + var l = g[h]; + if (!e[l]) { + e[l] = 1; + var m; + (m = f.get(l)) ? k = m : f.set(l, k = []); if (!c || !k.includes(a)) { if (k.length === 2147483647) { - l = new Wa(k); + m = new Va(k); if (this.fastupdate) { - for (var p = B(this.reg.values()), n = p.next(); !n.done; n = p.next()) { - n = n.value, n.includes(k) && (n[n.indexOf(k)] = l); + for (var p = D(this.reg.values()), n = p.next(); !n.done; n = p.next()) { + n = n.value, n.includes(k) && (n[n.indexOf(k)] = m); } } - f.set(m, k = l); + f.set(l, k = m); } k.push(a); - this.fastupdate && ((m = this.reg.get(a)) ? m.push(k) : this.reg.set(a, [k])); + this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); } } } } else { - f || console.warn("Tag '" + g + "' was not found"); + f || console.warn("Tag '" + h + "' was not found"); } } } @@ -1659,7 +1651,7 @@ function nb(a, b, c) { if (this.h) { var q = S(); for (c = 0; c < this.h.length; c++) { - if (d = this.h[c], f = d.O, !f || f(b)) { + if (d = this.h[c], f = d.M, !f || f(b)) { f = void 0; if (typeof d === "function") { f = d(b); @@ -1667,11 +1659,11 @@ function nb(a, b, c) { continue; } d = [d.ia]; - } else if (T(d) || d.constructor === String) { + } else if (U(d) || d.constructor === String) { q[d] = b[d]; continue; } - rb(b, q, d, 0, d[0], f); + qb(b, q, d, 0, d[0], f); } } } @@ -1681,22 +1673,22 @@ function nb(a, b, c) { } return this; }; -function rb(a, b, c, d, e, f) { +function qb(a, b, c, d, e, f) { a = a[e]; if (d === c.length - 1) { b[e] = f || a; } else if (a) { if (a.constructor === Array) { for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - rb(a, b, c, d, e); + qb(a, b, c, d, e); } } else { - b = b[e] || (b[e] = S()), e = c[++d], rb(a, b, c, d, e); + b = b[e] || (b[e] = S()), e = c[++d], qb(a, b, c, d, e); } } } -function qb(a, b, c, d, e, f, h, g) { - if (a = a[h]) { +function pb(a, b, c, d, e, f, g, h) { + if (a = a[g]) { if (d === b.length - 1) { if (a.constructor === Array) { if (c[d]) { @@ -1707,51 +1699,51 @@ function qb(a, b, c, d, e, f, h, g) { } a = a.join(" "); } - e.add(f, a, g, !0); + e.add(f, a, h, !0); } else { if (a.constructor === Array) { - for (h = 0; h < a.length; h++) { - qb(a, b, c, d, e, f, h, g); + for (g = 0; g < a.length; g++) { + pb(a, b, c, d, e, f, g, h); } } else { - h = b[++d], qb(a, b, c, d, e, f, h, g); + g = b[++d], pb(a, b, c, d, e, f, g, h); } } } } -;function sb(a, b, c, d) { +;function rb(a, b, c, d) { if (!a.length) { return a; } if (a.length === 1) { - return a = a[0], a = c || a.length > b ? a.slice(c, c + b) : a, d ? tb.call(this, a) : a; + return a = a[0], a = c || a.length > b ? a.slice(c, c + b) : a, d ? sb.call(this, a) : a; } - for (var e = [], f = 0, h = void 0, g = void 0; f < a.length; f++) { - if ((h = a[f]) && (g = h.length)) { + for (var e = [], f = 0, g = void 0, h = void 0; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { if (c) { - if (c >= g) { - c -= g; + if (c >= h) { + c -= h; continue; } - h = h.slice(c, c + b); - g = h.length; + g = g.slice(c, c + b); + h = g.length; c = 0; } - g > b && (h = h.slice(0, b), g = b); - if (!e.length && g >= b) { - return d ? tb.call(this, h) : h; + h > b && (g = g.slice(0, b), h = b); + if (!e.length && h >= b) { + return d ? sb.call(this, g) : g; } - e.push(h); - b -= g; + e.push(g); + b -= h; if (!b) { break; } } } e = e.length > 1 ? [].concat.apply([], e) : e[0]; - return d ? tb.call(this, e) : e; + return d ? sb.call(this, e) : e; } -;function ub(a, b, c, d) { +;function tb(a, b, c, d) { var e = d[0]; if (e[0] && e[0].query) { return a[b].apply(a, e); @@ -1759,118 +1751,119 @@ function qb(a, b, c, d, e, f, h, g) { if (!(b !== "and" && b !== "not" || a.result.length || a.await || e.suggest)) { return d.length > 1 && (e = d[d.length - 1]), (d = e.resolve) ? a.await || a.result : a; } - var f = [], h = 0, g = 0, k, m; + var f = [], g = 0, h = 0, k; b = {}; - for (e = 0; e < d.length; b = {X:void 0, W:void 0, Y:void 0, aa:void 0}, e++) { + for (e = 0; e < d.length; b = {U:void 0, T:void 0, Y:void 0, aa:void 0}, e++) { var l = d[e]; if (l) { - var p = void 0; + var m = void 0; if (l.constructor === Z) { - p = l.await || l.result; + m = l.await || l.result; } else if (l.then || l.constructor === Array) { - p = l; + m = l; } else { - h = l.limit || 0; - g = l.offset || 0; - var n = l.suggest; - var q = ((m = (k = l.resolve) && l.highlight) || l.enrich) && k; - p = l.queue; - b.Y = l.async || p; - var t = l.index; + g = l.limit || 0; + h = l.offset || 0; + var p = l.suggest; + var n = l.resolve; + var q = ((k = l.highlight || a.highlight) || l.enrich) && n; + m = l.queue; + b.Y = l.async || m; + var t = l.index, u = l.query; t ? a.index || (a.index = t) : t = a.index; - if (l.query || l.tag) { + if (u || l.tag) { if (!t) { throw Error("Resolver can't apply because the corresponding Index was never specified"); } - var u = l.field || l.pluck; - if (u) { - l.query && (a.query = l.query, a.field = u); + var v = l.field || l.pluck; + if (v) { + !u || a.query && !k || (a.query = u, a.field = v, a.highlight = k); if (!t.index) { throw Error("Resolver can't apply because the corresponding Document Index was not specified"); } - t = t.index.get(u); + t = t.index.get(v); if (!t) { - throw Error("Resolver can't apply because the specified Document Field '" + u + "' was not found"); + throw Error("Resolver can't apply because the specified Document Field '" + v + "' was not found"); } } - if (p && (v || a.await)) { - var v = 1; - b.X = void 0; + if (m && (B || a.await)) { + var B = 1; + b.U = void 0; b.aa = a.F.length; - b.W = new Promise(function(x) { + b.T = new Promise(function(A) { return function(C) { - x.X = C; + A.U = C; }; }(b)); - (function(x) { - return function(C, D) { - x.W.H = function() { - D.index = null; - D.resolve = !1; - var r = x.Y ? C.searchAsync(D) : C.search(D); - if (r.then) { - return r.then(function(y) { - a.F[x.aa] = y = y.result || y; - (0,x.X)(y); - return y; + (function(A) { + return function(C, r) { + A.T.H = function() { + r.index = null; + r.resolve = !1; + var x = A.Y ? C.searchAsync(r) : C.search(r); + if (x.then) { + return x.then(function(E) { + a.F[A.aa] = E = E.result || E; + (0,A.U)(E); + return E; }); } - r = r.result || r; - (0,x.X)(r); - return r; + x = x.result || x; + (0,A.U)(x); + return x; }; }; })(b)(t, Object.assign({}, l)); - a.F.push(b.W); - f[e] = b.W; + a.F.push(b.T); + f[e] = b.T; continue; } else { - l.resolve = !1, l.index = null, p = b.Y ? t.searchAsync(l) : t.search(l), l.resolve = k, l.index = t; + l.resolve = !1, l.index = null, m = b.Y ? t.searchAsync(l) : t.search(l), l.resolve = n, l.index = t; } } else if (l.and) { - p = vb(l, "and", t); + m = ub(l, "and", t); } else if (l.or) { - p = vb(l, "or", t); + m = ub(l, "or", t); } else if (l.not) { - p = vb(l, "not", t); + m = ub(l, "not", t); } else if (l.xor) { - p = vb(l, "xor", t); + m = ub(l, "xor", t); } else { continue; } } - p.await ? (v = 1, p = p.await) : p.then ? (v = 1, p = p.then(function(x) { - return x.result || x; - })) : p = p.result || p; - f[e] = p; + m.await ? (B = 1, m = m.await) : m.then ? (B = 1, m = m.then(function(A) { + return A.result || A; + })) : m = m.result || m; + f[e] = m; } } - v && !a.await && (a.await = new Promise(function(x) { - a.return = x; + B && !a.await && (a.await = new Promise(function(A) { + a.return = A; })); - if (v) { - var z = Promise.all(f).then(function(x) { + if (B) { + var y = Promise.all(f).then(function(A) { for (var C = 0; C < a.F.length; C++) { - if (a.F[C] === z) { + if (a.F[C] === y) { a.F[C] = function() { - return c.call(a, x, h, g, q, k, n, m); + return c.call(a, A, g, h, q, n, p, k); }; break; } } - wb(a); + vb(a); }); - a.F.push(z); + a.F.push(y); } else if (a.await) { a.F.push(function() { - return c.call(a, f, h, g, q, k, n, m); + return c.call(a, f, g, h, q, n, p, k); }); } else { - return c.call(a, f, h, g, q, k, n, m); + return c.call(a, f, g, h, q, n, p, k); } - return k ? a.await || a.result : a; + return n ? a.await || a.result : a; } -function vb(a, b, c) { +function ub(a, b, c) { a = a[b]; var d = a[0] || a; d.index || (d.index = c); @@ -1879,17 +1872,17 @@ function vb(a, b, c) { return c; } ;Z.prototype.or = function() { - return ub(this, "or", xb, arguments); + return tb(this, "or", wb, arguments); }; -function xb(a, b, c, d, e, f, h) { - a.length && (this.result.length && a.push(this.result), a.length < 2 ? this.result = a[0] : (this.result = yb(a, b, c, !1, this.h), c = 0)); +function wb(a, b, c, d, e, f, g) { + a.length && (this.result.length && a.push(this.result), a.length < 2 ? this.result = a[0] : (this.result = xb(a, b, c, !1, this.h), c = 0)); e && (this.await = null); - return e ? this.resolve(b, c, d, h) : this; + return e ? this.resolve(b, c, d, g) : this; } ;Z.prototype.and = function() { - return ub(this, "and", zb, arguments); + return tb(this, "and", yb, arguments); }; -function zb(a, b, c, d, e, f, h) { +function yb(a, b, c, d, e, f, g) { if (!f && !this.result.length) { return e ? this.result : this; } @@ -1897,16 +1890,16 @@ function zb(a, b, c, d, e, f, h) { if (this.result.length && a.unshift(this.result), a.length < 2) { this.result = a[0]; } else { - for (var g = 0, k = 0, m = void 0, l = void 0; k < a.length; k++) { - if ((m = a[k]) && (l = m.length)) { - g < l && (g = l); + for (var h = 0, k = 0, l = void 0, m = void 0; k < a.length; k++) { + if ((l = a[k]) && (m = l.length)) { + h < m && (h = m); } else if (!f) { - g = 0; + h = 0; break; } } - if (g) { - this.result = Ab(a, g, b, c, f, this.h, e); + if (h) { + this.result = zb(a, h, b, c, f, this.h, e); var p = !0; } else { this.result = []; @@ -1916,37 +1909,37 @@ function zb(a, b, c, d, e, f, h) { f || (this.result = a); } e && (this.await = null); - return e ? this.resolve(b, c, d, h, p) : this; + return e ? this.resolve(b, c, d, g, p) : this; } ;Z.prototype.xor = function() { - return ub(this, "xor", Bb, arguments); + return tb(this, "xor", Ab, arguments); }; -function Bb(a, b, c, d, e, f, h) { +function Ab(a, b, c, d, e, f, g) { if (a.length) { if (this.result.length && a.unshift(this.result), a.length < 2) { this.result = a[0]; } else { a: { f = c; - var g = this.h; - for (var k = [], m = S(), l = 0, p = 0, n; p < a.length; p++) { + var h = this.h; + for (var k = [], l = S(), m = 0, p = 0, n; p < a.length; p++) { if (n = a[p]) { - l < n.length && (l = n.length); + m < n.length && (m = n.length); for (var q = 0, t; q < n.length; q++) { if (t = n[q]) { for (var u = 0, v; u < t.length; u++) { - v = t[u], m[v] = m[v] ? 2 : 1; + v = t[u], l[v] = l[v] ? 2 : 1; } } } } } - for (n = p = 0; p < l; p++) { + for (n = p = 0; p < m; p++) { for (q = 0; q < a.length; q++) { if (t = a[q]) { if (t = t[p]) { for (u = 0; u < t.length; u++) { - if (v = t[u], m[v] === 1) { + if (v = t[u], l[v] === 1) { if (f) { f--; } else { @@ -1956,9 +1949,9 @@ function Bb(a, b, c, d, e, f, h) { break a; } } else { - var z = p + (q ? g : 0); - k[z] || (k[z] = []); - k[z].push(v); + var B = p + (q ? h : 0); + k[B] || (k[B] = []); + k[B].push(v); if (++n === b) { a = k; break a; @@ -1974,41 +1967,41 @@ function Bb(a, b, c, d, e, f, h) { a = k; } this.result = a; - g = !0; + h = !0; } } else { f || (this.result = a); } e && (this.await = null); - return e ? this.resolve(b, c, d, h, g) : this; + return e ? this.resolve(b, c, d, g, h) : this; } ;Z.prototype.not = function() { - return ub(this, "not", Cb, arguments); + return tb(this, "not", Bb, arguments); }; -function Cb(a, b, c, d, e, f, h) { +function Bb(a, b, c, d, e, f, g) { if (!f && !this.result.length) { return e ? this.result : this; } if (a.length && this.result.length) { a: { f = c; - var g = []; + var h = []; a = new Set(a.flat().flat()); - for (var k = 0, m, l = 0; k < this.result.length; k++) { - if (m = this.result[k]) { - for (var p = 0, n; p < m.length; p++) { - if (n = m[p], !a.has(n)) { + for (var k = 0, l, m = 0; k < this.result.length; k++) { + if (l = this.result[k]) { + for (var p = 0, n; p < l.length; p++) { + if (n = l[p], !a.has(n)) { if (f) { f--; } else { if (e) { - if (g.push(n), g.length === b) { - f = g; + if (h.push(n), h.length === b) { + f = h; break a; } } else { - if (g[k] || (g[k] = []), g[k].push(n), ++l === b) { - f = g; + if (h[k] || (h[k] = []), h[k].push(n), ++m === b) { + f = h; break a; } } @@ -2017,15 +2010,15 @@ function Cb(a, b, c, d, e, f, h) { } } } - f = g; + f = h; } this.result = f; - g = !0; + h = !0; } e && (this.await = null); - return e ? this.resolve(b, c, d, h, g) : this; + return e ? this.resolve(b, c, d, g, h) : this; } -;function Db(a, b, c, d, e) { +;function Cb(a, b, c, d, e) { if (typeof e === "string") { var f = e; e = ""; @@ -2035,13 +2028,13 @@ function Cb(a, b, c, d, e, f, h) { if (!f) { throw Error('No template pattern was specified by the search option "highlight"'); } - var h = f.indexOf("$1"); - if (h === -1) { + var g = f.indexOf("$1"); + if (g === -1) { throw Error('Invalid highlight template. The replacement pattern "$1" was not found in template: ' + f); } - var g = f.substring(h + 2); - h = f.substring(0, h); - var k = e && e.boundary, m = !e || e.clip !== !1, l = e && e.merge && g && h && new RegExp(g + " " + h, "g"); + var h = f.substring(g + 2); + g = f.substring(0, g); + var k = e && e.boundary, l = !e || e.clip !== !1, m = e && e.merge && h && g && new RegExp(h + " " + g, "g"); e = e && e.ellipsis; var p = 0; if (typeof e === "object") { @@ -2060,172 +2053,172 @@ function Cb(a, b, c, d, e, f, h) { k = k.total || 9e5; } p = new Map(); - for (var u, v = 0, z, x; v < b.length; v++) { + for (var u, v = 0, B, y; v < b.length; v++) { if (d) { - var C = b; - x = d; + var A = b; + y = d; } else { - C = b[v]; - x = C.field; - if (!x) { + A = b[v]; + y = A.field; + if (!y) { continue; } - C = C.result; + A = A.result; } - u = c.get(x); - z = u.encoder; - u = p.get(z); - typeof u !== "string" && (u = z.encode(a), p.set(z, u)); - for (var D = 0; D < C.length; D++) { - var r = C[D].doc; - if (r && (r = Ea(r, x))) { - var y = r.trim().split(/\s+/); - if (y.length) { + u = c.get(y); + B = u.encoder; + u = p.get(B); + typeof u !== "string" && (u = B.encode(a), p.set(B, u)); + for (var C = 0; C < A.length; C++) { + var r = A[C].doc; + if (r && (r = Da(r, y))) { + var x = r.trim().split(/\s+/); + if (x.length) { r = ""; - for (var F = [], U = [], G = -1, N = -1, Q = 0, E = 0; E < y.length; E++) { - var R = y[E], W = z.encode(R); + for (var E = [], T = [], G = -1, N = -1, Q = 0, F = 0; F < x.length; F++) { + var R = x[F], W = B.encode(R); W = W.length > 1 ? W.join(" ") : W[0]; var O = void 0; if (W && R) { - for (var L = R.length, M = (z.split ? R.replace(z.split, "") : R).length - W.length, ba = "", oa = 0, A = 0; A < u.length; A++) { - var I = u[A]; + for (var L = R.length, M = (B.split ? R.replace(B.split, "") : R).length - W.length, ba = "", oa = 0, z = 0; z < u.length; z++) { + var I = u[z]; if (I) { var J = I.length; J += M; - oa && J <= oa || (I = W.indexOf(I), I > -1 && (ba = (I ? R.substring(0, I) : "") + h + R.substring(I, I + J) + g + (I + J < L ? R.substring(I + J) : ""), oa = J, O = !0)); + oa && J <= oa || (I = W.indexOf(I), I > -1 && (ba = (I ? R.substring(0, I) : "") + g + R.substring(I, I + J) + h + (I + J < L ? R.substring(I + J) : ""), oa = J, O = !0)); } } - ba && (k && (G < 0 && (G = r.length + (r ? 1 : 0)), N = r.length + (r ? 1 : 0) + ba.length, Q += L, U.push(F.length), F.push({match:ba})), r += (r ? " " : "") + ba); + ba && (k && (G < 0 && (G = r.length + (r ? 1 : 0)), N = r.length + (r ? 1 : 0) + ba.length, Q += L, T.push(E.length), E.push({match:ba})), r += (r ? " " : "") + ba); } if (!O) { - R = y[E], r += (r ? " " : "") + R, k && F.push({text:R}); + R = x[F], r += (r ? " " : "") + R, k && E.push({text:R}); } else if (k && Q >= k) { break; } } - Q = U.length * (f.length - 2); + Q = T.length * (f.length - 2); if (q || t || k && r.length - Q > k) { - if (Q = k + Q - n * 2, E = N - G, q > 0 && (E += q), t > 0 && (E += t), E <= Q) { - y = q ? G - (q > 0 ? q : 0) : G - ((Q - E) / 2 | 0), F = t ? N + (t > 0 ? t : 0) : y + Q, m || (y > 0 && r.charAt(y) !== " " && r.charAt(y - 1) !== " " && (y = r.indexOf(" ", y), y < 0 && (y = 0)), F < r.length && r.charAt(F - 1) !== " " && r.charAt(F) !== " " && (F = r.lastIndexOf(" ", F), F < N ? F = N : ++F)), r = (y ? e : "") + r.substring(y, F) + (F < r.length ? e : ""); + if (Q = k + Q - n * 2, F = N - G, q > 0 && (F += q), t > 0 && (F += t), F <= Q) { + x = q ? G - (q > 0 ? q : 0) : G - ((Q - F) / 2 | 0), E = t ? N + (t > 0 ? t : 0) : x + Q, l || (x > 0 && r.charAt(x) !== " " && r.charAt(x - 1) !== " " && (x = r.indexOf(" ", x), x < 0 && (x = 0)), E < r.length && r.charAt(E - 1) !== " " && r.charAt(E) !== " " && (E = r.lastIndexOf(" ", E), E < N ? E = N : ++E)), r = (x ? e : "") + r.substring(x, E) + (E < r.length ? e : ""); } else { N = []; Q = {}; G = {}; - E = {}; + F = {}; R = {}; W = {}; M = L = O = 0; for (oa = ba = 1;;) { I = void 0; - for (A = 0; A < U.length; A++) { - J = U[A]; + for (z = 0; z < T.length; z++) { + J = T[z]; if (M) { if (L !== M) { - if (E[A + 1]) { + if (F[z + 1]) { continue; } J += M; if (Q[J]) { O -= n; - G[A + 1] = 1; - E[A + 1] = 1; + G[z + 1] = 1; + F[z + 1] = 1; continue; } - if (J >= F.length - 1) { - if (J >= F.length) { - E[A + 1] = 1; - J >= y.length && (G[A + 1] = 1); + if (J >= E.length - 1) { + if (J >= E.length) { + F[z + 1] = 1; + J >= x.length && (G[z + 1] = 1); continue; } O -= n; } - r = F[J].text; - var V = t && W[A]; + r = E[J].text; + var V = t && W[z]; if (V) { if (V > 0) { if (r.length > V) { - if (E[A + 1] = 1, m) { + if (F[z + 1] = 1, l) { r = r.substring(0, V); } else { continue; } } (V -= r.length) || (V = -1); - W[A] = V; + W[z] = V; } else { - E[A + 1] = 1; + F[z + 1] = 1; continue; } } if (O + r.length + 1 <= k) { - r = " " + r, N[A] += r; - } else if (m) { - I = k - O - 1, I > 0 && (r = " " + r.substring(0, I), N[A] += r), E[A + 1] = 1; + r = " " + r, N[z] += r; + } else if (l) { + I = k - O - 1, I > 0 && (r = " " + r.substring(0, I), N[z] += r), F[z + 1] = 1; } else { - E[A + 1] = 1; + F[z + 1] = 1; continue; } } else { - if (E[A]) { + if (F[z]) { continue; } J -= L; if (Q[J]) { O -= n; - E[A] = 1; - G[A] = 1; + F[z] = 1; + G[z] = 1; continue; } if (J <= 0) { if (J < 0) { - E[A] = 1; - G[A] = 1; + F[z] = 1; + G[z] = 1; continue; } O -= n; } - r = F[J].text; - if (V = q && R[A]) { + r = E[J].text; + if (V = q && R[z]) { if (V > 0) { if (r.length > V) { - if (E[A] = 1, m) { + if (F[z] = 1, l) { r = r.substring(r.length - V); } else { continue; } } (V -= r.length) || (V = -1); - R[A] = V; + R[z] = V; } else { - E[A] = 1; + F[z] = 1; continue; } } if (O + r.length + 1 <= k) { - r += " ", N[A] = r + N[A]; - } else if (m) { - I = r.length + 1 - (k - O), I >= 0 && I < r.length && (r = r.substring(I) + " ", N[A] = r + N[A]), E[A] = 1; + r += " ", N[z] = r + N[z]; + } else if (l) { + I = r.length + 1 - (k - O), I >= 0 && I < r.length && (r = r.substring(I) + " ", N[z] = r + N[z]), F[z] = 1; } else { - E[A] = 1; + F[z] = 1; continue; } } } else { - r = F[J].match; - q && (R[A] = q); - t && (W[A] = t); - A && O++; + r = E[J].match; + q && (R[z] = q); + t && (W[z] = t); + z && O++; I = void 0; - J ? !A && n && (O += n) : (G[A] = 1, E[A] = 1); - J >= y.length - 1 ? I = 1 : J < F.length - 1 && F[J + 1].match ? I = 1 : n && (O += n); + J ? !z && n && (O += n) : (G[z] = 1, F[z] = 1); + J >= x.length - 1 ? I = 1 : J < E.length - 1 && E[J + 1].match ? I = 1 : n && (O += n); O -= f.length - 2; - if (!A || O + r.length <= k) { - N[A] = r; + if (!z || O + r.length <= k) { + N[z] = r; } else { - I = ba = oa = G[A] = 0; + I = ba = oa = G[z] = 0; break; } - I && (G[A + 1] = 1, E[A + 1] = 1); + I && (G[z + 1] = 1, F[z + 1] = 1); } O += r.length; I = Q[J] = 1; @@ -2241,14 +2234,14 @@ function Cb(a, b, c, d, e, f, h) { } } r = ""; - for (y = 0; y < N.length; y++) { - F = (y && G[y] ? " " : (y && !e ? " " : "") + e) + N[y], r += F; + for (x = 0; x < N.length; x++) { + E = (x && G[x] ? " " : (x && !e ? " " : "") + e) + N[x], r += E; } e && !G[N.length] && (r += e); } } - l && (r = r.replace(l, " ")); - C[D].highlight = r; + m && (r = r.replace(m, " ")); + A[C].highlight = r; } } } @@ -2268,13 +2261,14 @@ function Cb(a, b, c, d, e, f, h) { b = f.index; c = f.boost || 0; if (d = f.query) { - var h = f.field || f.pluck; - var g = f.resolve; + var g = f.field || f.pluck; + var h = f.highlight; + var k = f.resolve; a = f.async || f.queue; f.resolve = !1; f.index = null; a = a ? b.searchAsync(f) : b.search(f); - f.resolve = g; + f.resolve = k; f.index = b; a = a.result || a; } else { @@ -2282,33 +2276,33 @@ function Cb(a, b, c, d, e, f, h) { } } if (a && a.then) { - var k = this; - a = a.then(function(p) { - k.F[0] = k.result = p.result || p; - wb(k); + var l = this; + a = a.then(function(n) { + l.F[0] = l.result = n.result || n; + vb(l); }); var m = [a]; a = []; - var l = new Promise(function(p) { - e = p; + var p = new Promise(function(n) { + e = n; }); } this.index = b || null; this.result = a || []; this.h = c; this.F = m || []; - this.await = l || null; + this.await = p || null; this.return = e || null; + this.highlight = h || null; this.query = d || ""; - this.field = h || ""; + this.field = g || ""; } w = Z.prototype; w.limit = function(a) { if (this.await) { var b = this; this.F.push(function() { - b.limit(a); - return b.result; + return b.limit(a).result; }); } else { if (this.result.length) { @@ -2333,8 +2327,7 @@ w.offset = function(a) { if (this.await) { var b = this; this.F.push(function() { - b.offset(a); - return b.result; + return b.offset(a).result; }); } else { if (this.result.length) { @@ -2352,15 +2345,14 @@ w.boost = function(a) { if (this.await) { var b = this; this.F.push(function() { - b.boost(a); - return b.result; + return b.boost(a).result; }); } else { this.h += a; } return this; }; -function wb(a, b) { +function vb(a, b) { var c = a.result, d = a.await; a.await = null; for (var e = 0, f; e < a.F.length; e++) { @@ -2381,14 +2373,14 @@ function wb(a, b) { return c; } w.resolve = function(a, b, c, d, e) { - var f = this.await ? wb(this, !0) : this.result; + var f = this.await ? vb(this, !0) : this.result; if (f.then) { - var h = this; + var g = this; return f.then(function() { - return h.resolve(a, b, c, d, e); + return g.resolve(a, b, c, d, e); }); } - f.length && (typeof a === "object" ? (d = a.highlight, c = !!d || a.enrich, b = a.offset, a = a.limit) : c = !!d || c, f = e ? c ? tb.call(this.index, f) : f : sb.call(this.index, f, a || 100, b, c)); + f.length && (typeof a === "object" ? (d = a.highlight || this.highlight, c = !!d || a.enrich, b = a.offset, a = a.limit) : (d = d || this.highlight, c = !!d || c), f = e ? c ? sb.call(this.index, f) : f : rb.call(this.index, f, a || 100, b, c)); return this.finalize(f, d); }; w.finalize = function(a, b) { @@ -2398,31 +2390,31 @@ w.finalize = function(a, b) { return c.finalize(e, b); }); } - b && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); - b && a.length && this.query && (a = Db(this.query, a, this.index.index, this.field, b)); + b && !this.query && console.warn('There was no query specified for highlighting. Please specify a query within the highlight resolver stage like { query: "...", highlight: ... }.'); + b && a.length && this.query && (a = Cb(this.query, a, this.index.index, this.field, b)); var d = this.return; - this.index = this.result = this.F = this.await = this.return = null; + this.highlight = this.index = this.result = this.F = this.await = this.return = null; this.query = this.field = ""; d && d(a); return a; }; -function Ab(a, b, c, d, e, f, h) { - var g = a.length, k = []; - var m = S(); - for (var l = 0, p = void 0, n, q; l < b; l++) { - for (var t = 0; t < g; t++) { +function zb(a, b, c, d, e, f, g) { + var h = a.length, k = []; + var l = S(); + for (var m = 0, p = void 0, n, q; m < b; m++) { + for (var t = 0; t < h; t++) { var u = a[t]; - if (l < u.length && (p = u[l])) { + if (m < u.length && (p = u[m])) { for (var v = 0; v < p.length; v++) { n = p[v]; - (u = m[n]) ? m[n]++ : (u = 0, m[n] = 1); + (u = l[n]) ? l[n]++ : (u = 0, l[n] = 1); q = k[u] || (k[u] = []); - if (!h) { - var z = l + (t || !e ? 0 : f || 0); - q = q[z] || (q[z] = []); + if (!g) { + var B = m + (t || !e ? 0 : f || 0); + q = q[B] || (q[B] = []); } q.push(n); - if (h && c && u === g - 1 && q.length - d === c) { + if (g && c && u === h - 1 && q.length - d === c) { return d ? q.slice(d) : q; } } @@ -2431,28 +2423,28 @@ function Ab(a, b, c, d, e, f, h) { } if (a = k.length) { if (e) { - k = k.length > 1 ? yb(k, c, d, h, f) : (k = k[0]) && c && k.length > c || d ? k.slice(d, c + d) : k; + k = k.length > 1 ? xb(k, c, d, g, f) : (k = k[0]) && c && k.length > c || d ? k.slice(d, c + d) : k; } else { - if (a < g) { + if (a < h) { return []; } k = k[a - 1]; if (c || d) { - if (h) { + if (g) { if (k.length > c || d) { k = k.slice(d, c + d); } } else { e = []; for (f = 0; f < k.length; f++) { - if (h = k[f]) { - if (d && h.length > d) { - d -= h.length; + if (g = k[f]) { + if (d && g.length > d) { + d -= g.length; } else { - if (c && h.length > c || d) { - h = h.slice(d, c + d), c -= h.length, d && (d -= h.length); + if (c && g.length > c || d) { + g = g.slice(d, c + d), c -= g.length, d && (d -= g.length); } - e.push(h); + e.push(g); if (!c) { break; } @@ -2466,18 +2458,18 @@ function Ab(a, b, c, d, e, f, h) { } return k; } -function yb(a, b, c, d, e) { - var f = [], h = S(), g = a.length, k; +function xb(a, b, c, d, e) { + var f = [], g = S(), h = a.length, k; if (d) { - for (e = g - 1; e >= 0; e--) { + for (e = h - 1; e >= 0; e--) { if (k = (d = a[e]) && d.length) { - for (g = 0; g < k; g++) { - var m = d[g]; - if (!h[m]) { - if (h[m] = 1, c) { + for (h = 0; h < k; h++) { + var l = d[h]; + if (!g[l]) { + if (g[l] = 1, c) { c--; } else { - if (f.push(m), f.length === b) { + if (f.push(l), f.length === b) { return f; } } @@ -2486,17 +2478,17 @@ function yb(a, b, c, d, e) { } } } else { - for (var l = g - 1, p, n = 0; l >= 0; l--) { - p = a[l]; + for (var m = h - 1, p, n = 0; m >= 0; m--) { + p = a[m]; for (var q = 0; q < p.length; q++) { if (k = (d = p[q]) && d.length) { for (var t = 0; t < k; t++) { - if (m = d[t], !h[m]) { - if (h[m] = 1, c) { + if (l = d[t], !g[l]) { + if (g[l] = 1, c) { c--; } else { - var u = (q + (l < g - 1 ? e || 0 : 0)) / (l + 1) | 0; - (f[u] || (f[u] = [])).push(m); + var u = (q + (m < h - 1 ? e || 0 : 0)) / (m + 1) | 0; + (f[u] || (f[u] = [])).push(l); if (++n === b) { return f; } @@ -2509,11 +2501,11 @@ function yb(a, b, c, d, e) { } return f; } -function Eb(a, b, c) { - for (var d = S(), e = [], f = 0, h; f < b.length; f++) { - h = b[f]; - for (var g = 0; g < h.length; g++) { - d[h[g]] = 1; +function Db(a, b, c) { + for (var d = S(), e = [], f = 0, g; f < b.length; f++) { + g = b[f]; + for (var h = 0; h < g.length; h++) { + d[g[h]] = 1; } } if (c) { @@ -2522,101 +2514,101 @@ function Eb(a, b, c) { } } else { for (b = 0; b < a.result.length; b++) { - for (c = a.result[b], h = 0; h < c.length; h++) { - f = c[h], d[f] && ((e[b] || (e[b] = [])).push(f), d[f] = 0); + for (c = a.result[b], g = 0; g < c.length; g++) { + f = c[g], d[f] && ((e[b] || (e[b] = [])).push(f), d[f] = 0); } } } return e; } ;S(); -pb.prototype.search = function(a, b, c, d) { +ob.prototype.search = function(a, b, c, d) { c || (!b && Ca(a) ? (c = a, a = "") : Ca(b) && (c = b, b = 0)); - var e = [], f = [], h = 0, g = !0; + var e = [], f = [], g = 0, h = !0; if (c) { c.constructor === Array && (c = {index:c}); a = c.query || a; var k = c.pluck; - var m = c.merge; - var l = c.boost; + var l = c.merge; + var m = c.boost; var p = k || c.field || (p = c.index) && (p.index ? null : p); var n = this.tag && c.tag; var q = c.suggest; - g = c.resolve !== !1; + h = c.resolve !== !1; var t = c.cache; - this.store && c.highlight && !g ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && c.enrich && !g && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); - var u = g && this.store && c.highlight; - var v = !!u || g && this.store && c.enrich; + this.store && c.highlight && !h ? console.warn("Highlighting results can only be done on a final resolver task or when calling .resolve({ highlight: ... })") : this.store && c.enrich && !h && console.warn("Enrich results can only be done on a final resolver task or when calling .resolve({ enrich: true })"); + var u = h && this.store && c.highlight; + var v = !!u || h && this.store && c.enrich; b = c.limit || b; - var z = c.offset || 0; - b || (b = g ? 100 : 0); + var B = c.offset || 0; + b || (b = h ? 100 : 0); if (n && (!this.db || !d)) { n.constructor !== Array && (n = [n]); - for (var x = [], C = 0, D = void 0; C < n.length; C++) { - D = n[C]; - if (T(D)) { + for (var y = [], A = 0, C = void 0; A < n.length; A++) { + C = n[A]; + if (U(C)) { throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); } - if (D.field && D.tag) { - var r = D.tag; + if (C.field && C.tag) { + var r = C.tag; if (r.constructor === Array) { - for (var y = 0; y < r.length; y++) { - x.push(D.field, r[y]); + for (var x = 0; x < r.length; x++) { + y.push(C.field, r[x]); } } else { - x.push(D.field, r); + y.push(C.field, r); } } else { - r = Object.keys(D); - y = 0; - for (var F = void 0, U = void 0; y < r.length; y++) { - if (F = r[y], U = D[F], U.constructor === Array) { - for (var G = 0; G < U.length; G++) { - x.push(F, U[G]); + r = Object.keys(C); + x = 0; + for (var E = void 0, T = void 0; x < r.length; x++) { + if (E = r[x], T = C[E], T.constructor === Array) { + for (var G = 0; G < T.length; G++) { + y.push(E, T[G]); } } else { - x.push(F, U); + y.push(E, T); } } } } - if (!x.length) { + if (!y.length) { throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); } - n = x; + n = y; if (!a) { f = []; - if (x.length) { - for (n = 0; n < x.length; n += 2) { + if (y.length) { + for (n = 0; n < y.length; n += 2) { d = void 0; if (this.db) { - d = this.index.get(x[n]); + d = this.index.get(y[n]); if (!d) { - console.warn("Tag '" + x[n] + ":" + x[n + 1] + "' will be skipped because there is no field '" + x[n] + "'."); + console.warn("Tag '" + y[n] + ":" + y[n + 1] + "' will be skipped because there is no field '" + y[n] + "'."); continue; } - f.push(d = d.db.tag(x[n + 1], b, z, v)); + f.push(d = d.db.tag(y[n + 1], b, B, v)); } else { - d = Fb.call(this, x[n], x[n + 1], b, z, v); + d = Eb.call(this, y[n], y[n + 1], b, B, v); } - e.push(g ? {field:x[n], tag:x[n + 1], result:d} : [d]); + e.push(h ? {field:y[n], tag:y[n + 1], result:d} : [d]); } } if (f.length) { var N = this; return Promise.all(f).then(function(L) { for (var M = 0; M < L.length; M++) { - g ? e[M].result = L[M] : e[M] = L[M]; + h ? e[M].result = L[M] : e[M] = L[M]; } - return g ? e : new Z(e.length > 1 ? Ab(e, 1, 0, 0, q, l) : e[0], N); + return h ? e : new Z(e.length > 1 ? zb(e, 1, 0, 0, q, m) : e[0], N); }); } - return g ? e : new Z(e.length > 1 ? Ab(e, 1, 0, 0, q, l) : e[0], this); + return h ? e : new Z(e.length > 1 ? zb(e, 1, 0, 0, q, m) : e[0], this); } } - if (!g && !k) { + if (!h && !k) { if (p = p || this.field) { - T(p) ? k = p : (p.constructor === Array && p.length === 1 && (p = p[0]), k = p.field || p.index); + U(p) ? k = p : (p.constructor === Array && p.length === 1 && (p = p[0]), k = p.field || p.index); } if (!k) { throw Error("Apply resolver on document search requires either the option 'pluck' to be set or just select a single field name in your query."); @@ -2625,83 +2617,83 @@ pb.prototype.search = function(a, b, c, d) { p && p.constructor !== Array && (p = [p]); } p || (p = this.field); - x = (this.worker || this.db) && !d && []; - C = 0; - for (y = D = r = void 0; C < p.length; C++) { - if (D = p[C], !this.db || !this.tag || this.B[C]) { + y = (this.worker || this.db) && !d && []; + A = 0; + for (x = C = r = void 0; A < p.length; A++) { + if (C = p[A], !this.db || !this.tag || this.B[A]) { r = void 0; - T(D) || (r = D, D = r.field, a = r.query || a, b = Ba(r.limit, b), z = Ba(r.offset, z), q = Ba(r.suggest, q), u = g && this.store && Ba(r.highlight, u), v = !!u || g && this.store && Ba(r.enrich, v), t = Ba(r.cache, t)); + U(C) || (r = C, C = r.field, a = r.query || a, b = Ba(r.limit, b), B = Ba(r.offset, B), q = Ba(r.suggest, q), u = h && this.store && Ba(r.highlight, u), v = !!u || h && this.store && Ba(r.enrich, v), t = Ba(r.cache, t)); if (d) { - r = d[C]; + r = d[A]; } else { - y = r || c || {}; - F = y.enrich; - r = this.index.get(D); + x = r || c || {}; + E = x.enrich; + r = this.index.get(C); if (n) { if (this.db) { - y.tag = n; + x.tag = n; var Q = r.db.support_tag_search; - y.field = p; + x.field = p; } - !Q && F && (y.enrich = !1); + !Q && E && (x.enrich = !1); } - r = t ? r.searchCache(a, b, y) : r.search(a, b, y); - F && (y.enrich = F); - if (x) { - x[C] = r; + r = t ? r.searchCache(a, b, x) : r.search(a, b, x); + E && (x.enrich = E); + if (y) { + y[A] = r; continue; } } - y = (r = r.result || r) && r.length; - if (n && y) { - F = []; - U = 0; + x = (r = r.result || r) && r.length; + if (n && x) { + E = []; + T = 0; if (this.db && d) { if (!Q) { for (G = p.length; G < d.length; G++) { - var E = d[G]; - if (E && E.length) { - U++, F.push(E); + var F = d[G]; + if (F && F.length) { + T++, E.push(F); } else if (!q) { - return g ? e : new Z(e, this); + return h ? e : new Z(e, this); } } } } else { G = 0; - for (var R = E = void 0; G < n.length; G += 2) { - E = this.tag.get(n[G]); - if (!E) { + for (var R = F = void 0; G < n.length; G += 2) { + F = this.tag.get(n[G]); + if (!F) { if (console.warn("Tag '" + n[G] + ":" + n[G + 1] + "' will be skipped because there is no field '" + n[G] + "'."), q) { continue; } else { - return g ? e : new Z(e, this); + return h ? e : new Z(e, this); } } - if (R = (E = E && E.get(n[G + 1])) && E.length) { - U++, F.push(E); + if (R = (F = F && F.get(n[G + 1])) && F.length) { + T++, E.push(F); } else if (!q) { - return g ? e : new Z(e, this); + return h ? e : new Z(e, this); } } } - if (U) { - r = Eb(r, F, g); - y = r.length; - if (!y && !q) { - return g ? r : new Z(r, this); + if (T) { + r = Db(r, E, h); + x = r.length; + if (!x && !q) { + return h ? r : new Z(r, this); } - U--; + T--; } } - if (y) { - f[h] = D, e.push(r), h++; + if (x) { + f[g] = C, e.push(r), g++; } else if (p.length === 1) { - return g ? e : new Z(e, this); + return h ? e : new Z(e, this); } } } - if (x) { + if (y) { if (this.db && n && n.length && !Q) { for (v = 0; v < n.length; v += 2) { f = this.index.get(n[v]); @@ -2709,61 +2701,61 @@ pb.prototype.search = function(a, b, c, d) { if (console.warn("Tag '" + n[v] + ":" + n[v + 1] + "' was not found because there is no field '" + n[v] + "'."), q) { continue; } else { - return g ? e : new Z(e, this); + return h ? e : new Z(e, this); } } - x.push(f.db.tag(n[v + 1], b, z, !1)); + y.push(f.db.tag(n[v + 1], b, B, !1)); } } var W = this; - return Promise.all(x).then(function(L) { - c && (c.resolve = g); + return Promise.all(y).then(function(L) { + c && (c.resolve = h); L.length && (L = W.search(a, b, c, L)); return L; }); } - if (!h) { - return g ? e : new Z(e, this); + if (!g) { + return h ? e : new Z(e, this); } if (k && (!v || !this.store)) { - return e = e[0], g ? e : new Z(e, this); + return e = e[0], h ? e : new Z(e, this); } - x = []; - for (z = 0; z < f.length; z++) { - n = e[z]; - v && n.length && typeof n[0].doc === "undefined" && (this.db ? x.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = tb.call(this, n)); + y = []; + for (B = 0; B < f.length; B++) { + n = e[B]; + v && n.length && typeof n[0].doc === "undefined" && (this.db ? y.push(n = this.index.get(this.field[0]).db.enrich(n)) : n = sb.call(this, n)); if (k) { - return g ? u ? Db(a, n, this.index, k, u) : n : new Z(n, this); + return h ? u ? Cb(a, n, this.index, k, u) : n : new Z(n, this); } - e[z] = {field:f[z], result:n}; + e[B] = {field:f[B], result:n}; } - if (v && this.db && x.length) { + if (v && this.db && y.length) { var O = this; - return Promise.all(x).then(function(L) { + return Promise.all(y).then(function(L) { for (var M = 0; M < L.length; M++) { e[M].result = L[M]; } - u && (e = Db(a, e, O.index, k, u)); - return m ? Gb(e) : e; + u && (e = Cb(a, e, O.index, k, u)); + return l ? Fb(e) : e; }); } - u && (e = Db(a, e, this.index, k, u)); - return m ? Gb(e) : e; + u && (e = Cb(a, e, this.index, k, u)); + return l ? Fb(e) : e; }; -function Gb(a) { - for (var b = [], c = S(), d = S(), e = 0, f, h, g = void 0, k, m, l; e < a.length; e++) { +function Fb(a) { + for (var b = [], c = S(), d = S(), e = 0, f, g, h = void 0, k, l, m; e < a.length; e++) { f = a[e]; - h = f.field; + g = f.field; f = f.result; for (var p = 0; p < f.length; p++) { - if (k = f[p], typeof k !== "object" ? k = {id:g = k} : g = k.id, (m = c[g]) ? m.push(h) : (k.field = c[g] = [h], b.push(k)), l = k.highlight) { - m = d[g], m || (d[g] = m = {}, k.highlight = m), m[h] = l; + if (k = f[p], typeof k !== "object" ? k = {id:h = k} : h = k.id, (l = c[h]) ? l.push(g) : (k.field = c[h] = [g], b.push(k)), m = k.highlight) { + l = d[h], l || (d[h] = l = {}, k.highlight = l), l[g] = m; } } } return b; } -function Fb(a, b, c, d, e) { +function Eb(a, b, c, d, e) { a = this.tag.get(a); if (!a) { return []; @@ -2777,11 +2769,11 @@ function Fb(a, b, c, d, e) { if (c && b > c || d) { a = a.slice(d, d + c); } - e && (a = tb.call(this, a)); + e && (a = sb.call(this, a)); } return a; } -function tb(a) { +function sb(a) { if (!this || !this.store) { return a; } @@ -2793,25 +2785,25 @@ function tb(a) { } return b; } -;function pb(a) { - if (!this || this.constructor !== pb) { - return new pb(a); +;function ob(a) { + if (!this || this.constructor !== ob) { + return new ob(a); } var b = a.document || a.doc || a, c, d; this.B = []; this.field = []; this.C = []; - this.key = (c = b.key || b.id) && Hb(c, this.C) || "id"; + this.key = (c = b.key || b.id) && Gb(c, this.C) || "id"; (d = a.keystore || 0) && (this.keystore = d); this.fastupdate = !!a.fastupdate; - this.reg = !this.fastupdate || a.worker || a.db ? d ? new X(d) : new Set() : d ? new Xa(d) : new Map(); + this.reg = !this.fastupdate || a.worker || a.db ? d ? new Y(d) : new Set() : d ? new X(d) : new Map(); this.h = (c = b.store || null) && c && c !== !0 && []; - this.store = c ? d ? new Xa(d) : new Map() : null; - this.cache = (c = a.cache || null) && new Na(c); + this.store = c ? d ? new X(d) : new Map() : null; + this.cache = (c = a.cache || null) && new Ma(c); a.cache = !1; this.worker = a.worker || !1; this.priority = a.priority || 4; - this.index = Ib.call(this, a, b); + this.index = Hb.call(this, a, b); this.tag = null; if (c = b.tag) { if (typeof c === "string" && (c = [c]), c.length) { @@ -2825,7 +2817,7 @@ function tb(a) { if (!e) { throw Error("The tag field from the document descriptor is undefined."); } - d.custom ? this.A[b] = d.custom : (this.A[b] = Hb(e, this.C), d.filter && (typeof this.A[b] === "string" && (this.A[b] = new String(this.A[b])), this.A[b].O = d.filter)); + d.custom ? this.A[b] = d.custom : (this.A[b] = Gb(e, this.C), d.filter && (typeof this.A[b] === "string" && (this.A[b] = new String(this.A[b])), this.A[b].M = d.filter)); this.D[b] = e; this.tag.set(e, new Map()); } @@ -2834,18 +2826,18 @@ function tb(a) { if (this.worker) { this.fastupdate = !1; a = []; - c = B(this.index.values()); + c = D(this.index.values()); for (b = c.next(); !b.done; b = c.next()) { b = b.value, b.then && a.push(b); } if (a.length) { var f = this; - return Promise.all(a).then(function(h) { - for (var g = 0, k = B(f.index.entries()), m = k.next(); !m.done; m = k.next()) { - var l = m.value; - m = l[0]; - l = l[1]; - l.then && (l = h[g], f.index.set(m, l), g++); + return Promise.all(a).then(function(g) { + for (var h = 0, k = D(f.index.entries()), l = k.next(); !l.done; l = k.next()) { + var m = l.value; + l = m[0]; + m = m[1]; + m.then && (m = g[h], f.index.set(l, m), h++); } return f; }); @@ -2854,7 +2846,7 @@ function tb(a) { a.db && (this.fastupdate = !1, this.mount(a.db)); } } -w = pb.prototype; +w = ob.prototype; w.mount = function(a) { if (this.worker) { throw Error("You can't use Worker-Indexes on a persistent model. That would be useless, since each of the persistent model acts like Worker-Index by default (Master/Slave)."); @@ -2864,7 +2856,7 @@ w.mount = function(a) { for (var c = 0, d = void 0; c < this.D.length; c++) { d = this.D[c]; var e = void 0; - this.index.set(d, e = new Y({}, this.reg)); + this.index.set(d, e = new db({}, this.reg)); b === this.field && (b = b.slice(0)); b.push(d); e.tag = this.tag.get(d); @@ -2877,62 +2869,62 @@ w.mount = function(a) { for (f = void 0; e < b.length; e++) { d.field = f = b[e]; f = this.index.get(f); - var h = new a.constructor(a.id, d); - h.id = a.id; - c[e] = h.mount(f); + var g = new a.constructor(a.id, d); + g.id = a.id; + c[e] = g.mount(f); f.document = !0; e ? f.bypass = !0 : f.store = this.store; } - var g = this; + var h = this; return this.db = Promise.all(c).then(function() { - g.db = !0; + h.db = !0; }); }; -w.commit = function(a, b) { - var c = this, d, e, f, h; - return wa(function(g) { - if (g.h == 1) { - d = []; - e = B(c.index.values()); - for (f = e.next(); !f.done; f = e.next()) { - h = f.value, d.push(h.commit(a, b)); +w.commit = function() { + var a = this, b, c, d, e; + return wa(function(f) { + if (f.h == 1) { + b = []; + c = D(a.index.values()); + for (d = c.next(); !d.done; d = c.next()) { + e = d.value, b.push(e.commit()); } - return K(g, Promise.all(d), 2); + return K(f, Promise.all(b), 2); } - c.reg.clear(); - g.h = 0; + a.reg.clear(); + f.h = 0; }); }; w.destroy = function() { - for (var a = [], b = B(this.index.values()), c = b.next(); !c.done; c = b.next()) { + for (var a = [], b = D(this.index.values()), c = b.next(); !c.done; c = b.next()) { a.push(c.value.destroy()); } return Promise.all(a); }; -function Ib(a, b) { +function Hb(a, b) { var c = new Map(), d = b.index || b.field || b; - T(d) && (d = [d]); - for (var e = 0, f, h = void 0; e < d.length; e++) { + U(d) && (d = [d]); + for (var e = 0, f, g = void 0; e < d.length; e++) { f = d[e]; - T(f) || (h = f, f = f.field); - h = Ca(h) ? Object.assign({}, a, h) : a; + U(f) || (g = f, f = f.field); + g = Ca(g) ? Object.assign({}, a, g) : a; if (this.worker) { - var g = (g = h.encoder) && g.encode ? g : new Ka(typeof g === "string" ? Ua[g] : g || {}); - g = new mb(h, g); - c.set(f, g); + var h = (h = g.encoder) && h.encode ? h : new Ja(typeof h === "string" ? Ta[h] : h || {}); + h = new lb(g, h); + c.set(f, h); } - this.worker || c.set(f, new Y(h, this.reg)); - h.custom ? this.B[e] = h.custom : (this.B[e] = Hb(f, this.C), h.filter && (typeof this.B[e] === "string" && (this.B[e] = new String(this.B[e])), this.B[e].O = h.filter)); + this.worker || c.set(f, new db(g, this.reg)); + g.custom ? this.B[e] = g.custom : (this.B[e] = Gb(f, this.C), g.filter && (typeof this.B[e] === "string" && (this.B[e] = new String(this.B[e])), this.B[e].M = g.filter)); this.field[e] = f; } if (this.h) { - for (a = b.store, T(a) && (a = [a]), b = 0; b < a.length; b++) { - d = a[b], e = d.field || d, d.custom ? (this.h[b] = d.custom, d.custom.ia = e) : (this.h[b] = Hb(e, this.C), d.filter && (typeof this.h[b] === "string" && (this.h[b] = new String(this.h[b])), this.h[b].O = d.filter)); + for (a = b.store, U(a) && (a = [a]), b = 0; b < a.length; b++) { + d = a[b], e = d.field || d, d.custom ? (this.h[b] = d.custom, d.custom.ia = e) : (this.h[b] = Gb(e, this.C), d.filter && (typeof this.h[b] === "string" && (this.h[b] = new String(this.h[b])), this.h[b].M = d.filter)); } } return c; } -function Hb(a, b) { +function Gb(a, b) { for (var c = a.split(":"), d = 0, e = 0; e < c.length; e++) { a = c[e], a[a.length - 1] === "]" && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); } @@ -2946,20 +2938,20 @@ w.update = function(a, b) { return this.remove(a).add(a, b); }; w.remove = function(a) { - Ca(a) && (a = Ea(a, this.key)); - for (var b = B(this.index.values()), c = b.next(); !c.done; c = b.next()) { + Ca(a) && (a = Da(a, this.key)); + for (var b = D(this.index.values()), c = b.next(); !c.done; c = b.next()) { c.value.remove(a, !0); } if (this.reg.has(a)) { if (this.tag && !this.fastupdate) { - for (b = B(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = D(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c = c.value; - for (var d = B(c), e = d.next(); !e.done; e = d.next()) { + for (var d = D(c), e = d.next(); !e.done; e = d.next()) { var f = e.value; e = f[0]; f = f[1]; - var h = f.indexOf(a); - h > -1 && (f.length > 1 ? f.splice(h, 1) : c.delete(e)); + var g = f.indexOf(a); + g > -1 && (f.length > 1 ? f.splice(g, 1) : c.delete(e)); } } } @@ -2970,11 +2962,11 @@ w.remove = function(a) { return this; }; w.clear = function() { - for (var a = [], b = B(this.index.values()), c = b.next(); !c.done; c = b.next()) { + for (var a = [], b = D(this.index.values()), c = b.next(); !c.done; c = b.next()) { c = c.value.clear(), c.then && a.push(c); } if (this.tag) { - for (b = B(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + for (b = D(this.tag.values()), c = b.next(); !c.done; c = b.next()) { c.value.clear(); } } @@ -2986,7 +2978,7 @@ w.contain = function(a) { return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); }; w.cleanup = function() { - for (var a = B(this.index.values()), b = a.next(); !b.done; b = a.next()) { + for (var a = D(this.index.values()), b = a.next(); !b.done; b = a.next()) { b.value.cleanup(); } return this; @@ -2997,81 +2989,81 @@ w.get = function(a) { }) : this.store.get(a) || null; }; w.set = function(a, b) { - typeof a === "object" && (b = a, a = Ea(b, this.key)); + typeof a === "object" && (b = a, a = Da(b, this.key)); this.store.set(a, b); return this; }; -w.searchCache = Ma; -w.export = Jb; -w.import = Kb; -fb(pb.prototype); -function Lb(a, b) { +w.searchCache = La; +w.export = Ib; +w.import = Jb; +eb(ob.prototype); +function Kb(a, b) { b = b === void 0 ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 5000 | 0); - a = B(a.entries()); + a = D(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { d.push(e.value), d.length === b && (c.push(d), d = []); } d.length && c.push(d); return c; } -function Mb(a, b) { +function Lb(a, b) { b || (b = new Map()); for (var c = 0, d; c < a.length; c++) { d = a[c], b.set(d[0], d[1]); } return b; } -function Nb(a, b) { +function Mb(a, b) { b = b === void 0 ? 0 : b; var c = [], d = []; b && (b = 250000 / b * 1000 | 0); - a = B(a.entries()); + a = D(a.entries()); for (var e = a.next(); !e.done; e = a.next()) { - e = e.value, d.push([e[0], Lb(e[1])[0]]), d.length === b && (c.push(d), d = []); + e = e.value, d.push([e[0], Kb(e[1])[0]]), d.length === b && (c.push(d), d = []); } d.length && c.push(d); return c; } -function Ob(a, b) { +function Nb(a, b) { b || (b = new Map()); for (var c = 0, d, e; c < a.length; c++) { - d = a[c], e = b.get(d[0]), b.set(d[0], Mb(d[1], e)); + d = a[c], e = b.get(d[0]), b.set(d[0], Lb(d[1], e)); } return b; } -function Pb(a) { +function Ob(a) { var b = [], c = []; - a = B(a.keys()); + a = D(a.keys()); for (var d = a.next(); !d.done; d = a.next()) { c.push(d.value), c.length === 250000 && (b.push(c), c = []); } c.length && b.push(c); return b; } -function Qb(a, b) { +function Pb(a, b) { b || (b = new Set()); for (var c = 0; c < a.length; c++) { b.add(a[c]); } return b; } -function Rb(a, b, c, d, e, f, h) { - h = h === void 0 ? 0 : h; - var g = d && d.constructor === Array, k = g ? d.shift() : d; +function Qb(a, b, c, d, e, f, g) { + g = g === void 0 ? 0 : g; + var h = d && d.constructor === Array, k = h ? d.shift() : d; if (!k) { return this.export(a, b, e, f + 1); } - if ((k = a((b ? b + "." : "") + (h + 1) + "." + c, JSON.stringify(k))) && k.then) { - var m = this; + if ((k = a((b ? b + "." : "") + (g + 1) + "." + c, JSON.stringify(k))) && k.then) { + var l = this; return k.then(function() { - return Rb.call(m, a, b, c, g ? d : null, e, f, h + 1); + return Qb.call(l, a, b, c, h ? d : null, e, f, g + 1); }); } - return Rb.call(this, a, b, c, g ? d : null, e, f, h + 1); + return Qb.call(this, a, b, c, h ? d : null, e, f, g + 1); } -function Jb(a, b, c, d) { +function Ib(a, b, c, d) { c = c === void 0 ? 0 : c; d = d === void 0 ? 0 : d; if (c < this.field.length) { @@ -3086,26 +3078,26 @@ function Jb(a, b, c, d) { } switch(d) { case 0: - var h = "reg"; - var g = Pb(this.reg); + var g = "reg"; + var h = Ob(this.reg); b = null; break; case 1: - h = "tag"; - g = this.tag && Nb(this.tag, this.reg.size); + g = "tag"; + h = this.tag && Mb(this.tag, this.reg.size); b = null; break; case 2: - h = "doc"; - g = this.store && Lb(this.store); + g = "doc"; + h = this.store && Kb(this.store); b = null; break; default: return; } - return Rb.call(this, a, b, h, g || null, c, d); + return Qb.call(this, a, b, g, h || null, c, d); } -function Kb(a, b) { +function Jb(a, b) { var c = a.split("."); c[c.length - 1] === "json" && c.pop(); var d = c.length > 2 ? c[0] : ""; @@ -3121,13 +3113,13 @@ function Kb(a, b) { switch(c) { case "reg": this.fastupdate = !1; - this.reg = Qb(b, this.reg); + this.reg = Pb(b, this.reg); for (b = 0; b < this.field.length; b++) { d = this.index.get(this.field[b]), d.fastupdate = !1, d.reg = this.reg; } if (this.worker) { b = []; - d = B(this.index.values()); + d = D(this.index.values()); for (c = d.next(); !c.done; c = d.next()) { b.push(c.value.import(a)); } @@ -3135,24 +3127,24 @@ function Kb(a, b) { } break; case "tag": - this.tag = Ob(b, this.tag); + this.tag = Nb(b, this.tag); break; case "doc": - this.store = Mb(b, this.store); + this.store = Lb(b, this.store); } } } -function Sb(a, b) { +function Rb(a, b) { var c = ""; - a = B(a.entries()); + a = D(a.entries()); for (var d = a.next(); !d.done; d = a.next()) { var e = d.value; d = e[0]; e = e[1]; - for (var f = "", h = 0, g; h < e.length; h++) { - g = e[h] || [""]; - for (var k = "", m = 0; m < g.length; m++) { - k += (k ? "," : "") + (b === "string" ? '"' + g[m] + '"' : g[m]); + for (var f = "", g = 0, h; g < e.length; g++) { + h = e[g] || [""]; + for (var k = "", l = 0; l < h.length; l++) { + k += (k ? "," : "") + (b === "string" ? '"' + h[l] + '"' : h[l]); } k = "[" + k + "]"; f += (f ? "," : "") + k; @@ -3162,7 +3154,7 @@ function Sb(a, b) { } return c; } -;Y.prototype.remove = function(a, b) { +;db.prototype.remove = function(a, b) { var c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { @@ -3171,40 +3163,40 @@ function Sb(a, b) { if (e[f - 1] === a) { e.pop(); } else { - var h = e.indexOf(a); - h >= 0 && e.splice(h, 1); + var g = e.indexOf(a); + g >= 0 && e.splice(g, 1); } } } } else { - Tb(this.map, a), this.depth && Tb(this.ctx, a); + Sb(this.map, a), this.depth && Sb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.$ && Ub(this)); + this.db && (this.commit_task.push({del:a}), this.$ && Tb(this)); this.cache && this.cache.remove(a); return this; }; -function Tb(a, b) { +function Sb(a, b) { var c = 0, d = typeof b === "undefined"; if (a.constructor === Array) { - for (var e = 0, f = void 0, h, g = void 0; e < a.length; e++) { + for (var e = 0, f = void 0, g, h = void 0; e < a.length; e++) { if ((f = a[e]) && f.length) { if (d) { return 1; } - h = f.indexOf(b); - if (h >= 0) { + g = f.indexOf(b); + if (g >= 0) { if (f.length > 1) { - return f.splice(h, 1), 1; + return f.splice(g, 1), 1; } delete a[e]; if (c) { return 1; } - g = 1; + h = 1; } else { - if (g) { + if (h) { return 1; } c++; @@ -3212,14 +3204,14 @@ function Tb(a, b) { } } } else { - for (d = B(a.entries()), e = d.next(); !e.done; e = d.next()) { - e = e.value, f = e[0], Tb(e[1], b) ? c++ : a.delete(f); + for (d = D(a.entries()), e = d.next(); !e.done; e = d.next()) { + e = e.value, f = e[0], Sb(e[1], b) ? c++ : a.delete(f); } } return c; } -;var Vb = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; -Y.prototype.add = function(a, b, c, d) { +;var Ub = {memory:{resolution:1}, performance:{resolution:3, fastupdate:!0, context:{depth:1, resolution:1}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:3}}}; +db.prototype.add = function(a, b, c, d) { if (b && (a || a === 0)) { if (!d && !c && this.reg.has(a)) { return this.update(a, b); @@ -3228,87 +3220,101 @@ Y.prototype.add = function(a, b, c, d) { b = this.encoder.encode(b, !d); var e = b.length; if (e) { - for (var f = S(), h = S(), g = this.resolution, k = 0; k < e; k++) { - var m = b[this.rtl ? e - 1 - k : k], l = m.length; - if (l && (d || !h[m])) { - var p = this.score ? this.score(b, m, k, null, 0) : Wb(g, e, k), n = ""; + for (var f = S(), g = S(), h = this.resolution, k = 0; k < e; k++) { + var l = b[this.rtl ? e - 1 - k : k], m = l.length; + if (m && (d || !g[l])) { + var p = this.score ? this.score(b, l, k, null, 0) : Vb(h, e, k), n = ""; switch(this.tokenize) { case "tolerant": - Xb(this, h, m, p, a, c); - if (l > 2) { - for (var q = 1, t, u; q < l - 1; q++) { - n = m.charAt(q), t = m.charAt(q + 1), t = m.substring(0, q) + t, u = m.substring(q + 2), n = t + n + u, h[n] || Xb(this, h, n, p, a, c), n = t + u, h[n] || Xb(this, h, n, p, a, c); + Wb(this, g, l, p, a, c); + if (m > 2) { + for (var q = 1, t, u; q < m - 1; q++) { + n = l.charAt(q), t = l.charAt(q + 1), t = l.substring(0, q) + t, u = l.substring(q + 2), n = t + n + u, Wb(this, g, n, p, a, c), n = t + u, Wb(this, g, n, p, a, c); } + Wb(this, g, l.substring(0, l.length - 1), p, a, c); } break; case "full": - if (l > 2) { - for (p = 0; p < l; p++) { - for (q = l; q > p; q--) { - n = m.substring(p, q), h[n] || (t = this.rtl ? l - 1 - p : p, t = this.score ? this.score(b, m, k, n, t) : Wb(g, e, k, l, t), Xb(this, h, n, t, a, c)); + if (m > 2) { + for (p = 0; p < m; p++) { + for (q = m; q > p; q--) { + n = l.substring(p, q), t = this.rtl ? m - 1 - p : p, t = this.score ? this.score(b, l, k, n, t) : Vb(h, e, k, m, t), Wb(this, g, n, t, a, c); } } break; } case "bidirectional": case "reverse": - if (l > 1) { - for (q = l - 1; q > 0; q--) { - n = m[this.rtl ? l - 1 - q : q] + n, h[n] || (t = this.score ? this.score(b, m, k, n, q) : Wb(g, e, k, l, q), Xb(this, h, n, t, a, c)); + if (m > 1) { + for (q = m - 1; q > 0; q--) { + n = l[this.rtl ? m - 1 - q : q] + n, t = this.score ? this.score(b, l, k, n, q) : Vb(h, e, k, m, q), Wb(this, g, n, t, a, c); } n = ""; } case "forward": - if (l > 1) { - for (q = 0; q < l; q++) { - n += m[this.rtl ? l - 1 - q : q], h[n] || Xb(this, h, n, p, a, c); + if (m > 1) { + for (q = 0; q < m; q++) { + n += l[this.rtl ? m - 1 - q : q], Wb(this, g, n, p, a, c); } break; } default: - if (Xb(this, h, m, p, a, c), d && e > 1 && k < e - 1) { - for (l = S(), n = this.ba, p = m, q = Math.min(d + 1, this.rtl ? k + 1 : e - k), t = l[p] = 1; t < q; t++) { - if ((m = b[this.rtl ? e - 1 - k - t : k + t]) && !l[m]) { - l[m] = 1; - u = this.score ? this.score(b, p, k, m, t - 1) : Wb(n + (e / 2 > n ? 0 : 1), e, k, q - 1, t - 1); - var v = this.bidirectional && m > p; - Xb(this, f, v ? p : m, u, a, c, v ? m : p); - } + if (Wb(this, g, l, p, a, c), d && e > 1 && k < e - 1) { + for (m = this.ba, n = l, p = Math.min(d + 1, this.rtl ? k + 1 : e - k), q = 1; q < p; q++) { + l = b[this.rtl ? e - 1 - k - q : k + q], t = this.bidirectional && l > n, u = this.score ? this.score(b, n, k, l, q - 1) : Vb(m + (e / 2 > m ? 0 : 1), e, k, p - 1, q - 1), Wb(this, f, t ? n : l, u, a, c, t ? l : n); } } } } } this.fastupdate || this.reg.add(a); - } else { - b = ""; } } - this.db && (b || this.commit_task.push({del:a}), this.$ && Ub(this)); + this.db && (this.commit_task.push(c ? {ins:a} : {del:a}), this.$ && Tb(this)); return this; }; -function Xb(a, b, c, d, e, f, h) { - var g = h ? a.ctx : a.map, k; - if (!b[c] || h && !(k = b[c])[h]) { - if (h ? (b = k || (b[c] = S()), b[h] = 1, (k = g.get(h)) ? g = k : g.set(h, g = new Map())) : b[c] = 1, (k = g.get(c)) ? g = k : g.set(c, g = k = []), g = g[d] || (g[d] = []), !f || !g.includes(e)) { - if (g.length === 2147483647) { - b = new Wa(g); - if (a.fastupdate) { - for (c = B(a.reg.values()), f = c.next(); !f.done; f = c.next()) { - f = f.value, f.includes(g) && (f[f.indexOf(g)] = b); - } - } - k[d] = g = b; - } - g.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(g) : a.reg.set(e, [g])); +function Wb(a, b, c, d, e, f, g) { + var h; + if (!(h = b[c]) || g && !h[g]) { + if (g) { + b = h || (b[c] = S()); + b[g] = 1; + var k = a.ctx; + (h = k.get(g)) ? k = h : k.set(g, k = a.keystore ? new X(a.keystore) : new Map()); + } else { + k = a.map, b[c] = 1; } + (h = k.get(c)) ? k = h : k.set(c, k = h = []); + if (f) { + for (c = 0; c < h.length; c++) { + if ((b = h[c]) && b.includes(e)) { + if (c <= d) { + return; + } + b.splice(b.indexOf(e), 1); + a.fastupdate && (c = a.reg.get(e)) && c.splice(c.indexOf(b), 1); + break; + } + } + } + k = k[d] || (k[d] = []); + k.push(e); + if (k.length === 2147483647) { + b = new Va(k); + if (a.fastupdate) { + for (c = D(a.reg.values()), f = c.next(); !f.done; f = c.next()) { + f = f.value, f.includes(k) && (f[f.indexOf(k)] = b); + } + } + h[d] = k = b; + } + a.fastupdate && ((d = a.reg.get(e)) ? d.push(k) : a.reg.set(e, [k])); } } -function Wb(a, b, c, d, e) { +function Vb(a, b, c, d, e) { return c && a > 1 ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; } -;Y.prototype.search = function(a, b, c) { +;db.prototype.search = function(a, b, c) { c || (b || typeof a !== "object" ? typeof b === "object" && (c = b, b = 0) : (c = a, a = "")); if (c && c.cache) { return c.cache = !1, a = this.searchCache(a, b, c), c.cache = !0, a; @@ -3318,68 +3324,68 @@ function Wb(a, b, c, d, e) { a = c.query || a; b = c.limit || b; e = c.offset || 0; - var h = c.context; - var g = c.suggest; + var g = c.context; + var h = c.suggest; var k = (f = c.resolve) && c.enrich; - var m = c.boost; - var l = c.resolution; + var l = c.boost; + var m = c.resolution; var p = this.db && c.tag; } typeof f === "undefined" && (f = this.resolve); - h = this.depth && h !== !1; - var n = this.encoder.encode(a, !h); + g = this.depth && g !== !1; + var n = this.encoder.encode(a, !g); var q = n.length; b = b || (f ? 100 : 0); if (q === 1) { - return Yb.call(this, n[0], "", b, e, f, k, p); + return Xb.call(this, n[0], "", b, e, f, k, p); } - if (q === 2 && h && !g) { - return Yb.call(this, n[1], n[0], b, e, f, k, p); + if (q === 2 && g && !h) { + return Xb.call(this, n[1], n[0], b, e, f, k, p); } var t = S(), u = 0; - if (h) { + if (g) { var v = n[0]; u = 1; } - l || l === 0 || (l = v ? this.ba : this.resolution); + m || m === 0 || (m = v ? this.ba : this.resolution); if (this.db) { - if (this.db.search && (c = this.db.search(this, n, b, e, g, f, k, p), c !== !1)) { + if (this.db.search && (c = this.db.search(this, n, b, e, h, f, k, p), c !== !1)) { return c; } - var z = this; + var B = this; return function() { - var x, C; - return wa(function(D) { - switch(D.h) { + var y, A; + return wa(function(C) { + switch(C.h) { case 1: - C = x = void 0; + A = y = void 0; case 2: if (!(u < q)) { - D.h = 4; + C.h = 4; break; } - C = n[u]; - if (!C || t[C]) { - D.h = 5; + A = n[u]; + if (!A || t[A]) { + C.h = 5; break; } - t[C] = 1; - return K(D, Zb(z, C, v, 0, 0, !1, !1), 6); + t[A] = 1; + return K(C, Yb(B, A, v, 0, 0, !1, !1), 6); case 6: - x = D.B; - if (x = $b(x, d, g, l)) { - d = x; - D.h = 4; + y = C.B; + if (y = Zb(y, d, h, m)) { + d = y; + C.h = 4; break; } - v && (g && x && d.length || (v = C)); + v && (h && y && d.length || (v = A)); case 5: - g && v && u === q - 1 && !d.length && (l = z.resolution, v = "", u = -1, t = S()); + h && v && u === q - 1 && !d.length && (m = B.resolution, v = "", u = -1, t = S()); u++; - D.h = 2; + C.h = 2; break; case 4: - return D.return(ac(d, l, b, e, g, m, f)); + return C.return($b(d, m, b, e, h, l, f)); } }); }(); @@ -3387,42 +3393,42 @@ function Wb(a, b, c, d, e) { for (a = c = void 0; u < q; u++) { if ((a = n[u]) && !t[a]) { t[a] = 1; - c = Zb(this, a, v, 0, 0, !1, !1); - if (c = $b(c, d, g, l)) { + c = Yb(this, a, v, 0, 0, !1, !1); + if (c = Zb(c, d, h, m)) { d = c; break; } - v && (g && c && d.length || (v = a)); + v && (h && c && d.length || (v = a)); } - g && v && u === q - 1 && !d.length && (l = this.resolution, v = "", u = -1, t = S()); + h && v && u === q - 1 && !d.length && (m = this.resolution, v = "", u = -1, t = S()); } - return ac(d, l, b, e, g, m, f); + return $b(d, m, b, e, h, l, f); }; -function ac(a, b, c, d, e, f, h) { - var g = a.length, k = a; - if (g > 1) { - k = Ab(a, b, c, d, e, f, h); - } else if (g === 1) { - return h ? sb.call(null, a[0], c, d) : new Z(a[0], this); +function $b(a, b, c, d, e, f, g) { + var h = a.length, k = a; + if (h > 1) { + k = zb(a, b, c, d, e, f, g); + } else if (h === 1) { + return g ? rb.call(null, a[0], c, d) : new Z(a[0], this); } - return h ? k : new Z(k, this); + return g ? k : new Z(k, this); } -function Yb(a, b, c, d, e, f, h) { - a = Zb(this, a, b, c, d, e, f, h); - return this.db ? a.then(function(g) { - return e ? g || [] : new Z(g, this); - }) : a && a.length ? e ? sb.call(this, a, c, d) : new Z(a, this) : e ? [] : new Z([], this); +function Xb(a, b, c, d, e, f, g) { + a = Yb(this, a, b, c, d, e, f, g); + return this.db ? a.then(function(h) { + return e ? h || [] : new Z(h, this); + }) : a && a.length ? e ? rb.call(this, a, c, d) : new Z(a, this) : e ? [] : new Z([], this); } -function $b(a, b, c, d) { +function Zb(a, b, c, d) { var e = []; if (a && a.length) { if (a.length <= d) { b.push(a); return; } - for (var f = 0, h; f < d; f++) { - if (h = a[f]) { - e[f] = h; + for (var f = 0, g; f < d; f++) { + if (g = a[f]) { + e[f] = g; } } if (e.length) { @@ -3434,28 +3440,28 @@ function $b(a, b, c, d) { return e; } } -function Zb(a, b, c, d, e, f, h, g) { +function Yb(a, b, c, d, e, f, g, h) { var k; c && (k = a.bidirectional && b > c) && (k = c, c = b, b = k); if (a.db) { - return a.db.get(b, c, d, e, f, h, g); + return a.db.get(b, c, d, e, f, g, h); } a = c ? (a = a.ctx.get(c)) && a.get(b) : a.map.get(b); return a; } -;function Y(a, b) { - if (!this || this.constructor !== Y) { - return new Y(a); +;function db(a, b) { + if (!this || this.constructor !== db) { + return new db(a); } if (a) { - var c = T(a) ? a : a.preset; - c && (Vb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Vb[c], a)); + var c = U(a) ? a : a.preset; + c && (Ub[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ub[c], a)); } else { a = {}; } c = a.context; - var d = c === !0 ? {depth:1} : c || {}, e = T(a.encoder) ? Ua[a.encoder] : a.encode || a.encoder || {}; - this.encoder = e.encode ? e : typeof e === "object" ? new Ka(e) : {encode:e}; + var d = c === !0 ? {depth:1} : c || {}, e = U(a.encoder) ? Ta[a.encoder] : a.encode || a.encoder || {}; + this.encoder = e.encode ? e : typeof e === "object" ? new Ja(e) : {encode:e}; this.resolution = a.resolution || 9; this.tokenize = c = (c = a.tokenize) && c !== "default" && c !== "exact" && c || "strict"; this.depth = c === "strict" && d.depth || 0; @@ -3464,12 +3470,12 @@ function Zb(a, b, c, d, e, f, h, g) { this.score = a.score || null; d && d.depth && this.tokenize !== "strict" && console.warn('Context-Search could not applied, because it is just supported when using the tokenizer "strict".'); (c = a.keystore || 0) && (this.keystore = c); - this.map = c ? new Xa(c) : new Map(); - this.ctx = c ? new Xa(c) : new Map(); - this.reg = b || (this.fastupdate ? c ? new Xa(c) : new Map() : c ? new X(c) : new Set()); + this.map = c ? new X(c) : new Map(); + this.ctx = c ? new X(c) : new Map(); + this.reg = b || (this.fastupdate ? c ? new X(c) : new Map() : c ? new Y(c) : new Set()); this.ba = d.resolution || 3; this.rtl = e.rtl || a.rtl || !1; - this.cache = (c = a.cache || null) && new Na(c); + this.cache = (c = a.cache || null) && new Ma(c); this.resolve = a.resolve !== !1; if (c = a.db) { this.db = this.mount(c); @@ -3479,23 +3485,23 @@ function Zb(a, b, c, d, e, f, h, g) { this.commit_timer = null; this.priority = a.priority || 4; } -w = Y.prototype; +w = db.prototype; w.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); }; -w.commit = function(a, b) { +w.commit = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); - return this.db.commit(this, a, b); + return this.db.commit(this); }; w.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Ub(a) { +function Tb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; - a.db.commit(a, void 0, void 0); + a.db.commit(a); }, 1)); } w.clear = function() { @@ -3521,18 +3527,18 @@ w.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Tb(this.map); - this.depth && Tb(this.ctx); + Sb(this.map); + this.depth && Sb(this.ctx); return this; }; -w.searchCache = Ma; +w.searchCache = La; w.export = function(a, b, c, d) { c = c === void 0 ? 0 : c; d = d === void 0 ? 0 : d; switch(d) { case 0: var e = "reg"; - var f = Pb(this.reg); + var f = Ob(this.reg); break; case 1: e = "cfg"; @@ -3540,29 +3546,29 @@ w.export = function(a, b, c, d) { break; case 2: e = "map"; - f = Lb(this.map, this.reg.size); + f = Kb(this.map, this.reg.size); break; case 3: e = "ctx"; - f = Nb(this.ctx, this.reg.size); + f = Mb(this.ctx, this.reg.size); break; default: return; } - return Rb.call(this, a, b, e, f, c, d); + return Qb.call(this, a, b, e, f, c, d); }; w.import = function(a, b) { if (b) { switch(typeof b === "string" && (b = JSON.parse(b)), a = a.split("."), a[a.length - 1] === "json" && a.pop(), a.length === 3 && a.shift(), a = a.length > 1 ? a[1] : a[0], a) { case "reg": this.fastupdate = !1; - this.reg = Qb(b, this.reg); + this.reg = Pb(b, this.reg); break; case "map": - this.map = Mb(b, this.map); + this.map = Lb(b, this.map); break; case "ctx": - this.ctx = Ob(b, this.ctx); + this.ctx = Nb(b, this.ctx); } } }; @@ -3571,32 +3577,32 @@ w.serialize = function(a) { var b = "", c = "", d = ""; if (this.reg.size) { var e; - c = B(this.reg.keys()); + c = D(this.reg.keys()); for (var f = c.next(); !f.done; f = c.next()) { f = f.value, e || (e = typeof f), b += (b ? "," : "") + (e === "string" ? '"' + f + '"' : f); } b = "index.reg=new Set([" + b + "]);"; - c = Sb(this.map, e); + c = Rb(this.map, e); c = "index.map=new Map([" + c + "]);"; - f = B(this.ctx.entries()); - for (var h = f.next(); !h.done; h = f.next()) { - var g = h.value; - h = g[0]; - g = Sb(g[1], e); - g = "new Map([" + g + "])"; - g = '["' + h + '",' + g + "]"; - d += (d ? "," : "") + g; + f = D(this.ctx.entries()); + for (var g = f.next(); !g.done; g = f.next()) { + var h = g.value; + g = h[0]; + h = Rb(h[1], e); + h = "new Map([" + h + "])"; + h = '["' + g + '",' + h + "]"; + d += (d ? "," : "") + h; } d = "index.ctx=new Map([" + d + "]);"; } return a ? "function inject(index){" + b + c + d + "}" : b + c + d; }; -fb(Y.prototype); -var bc = typeof window !== "undefined" && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), cc = ["map", "ctx", "tag", "reg", "cfg"], dc = S(); -function ec(a, b) { +eb(db.prototype); +var ac = typeof window !== "undefined" && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), bc = ["map", "ctx", "tag", "reg", "cfg"], cc = S(); +function dc(a, b) { b = b === void 0 ? {} : b; - if (!this || this.constructor !== ec) { - return new ec(a, b); + if (!this || this.constructor !== dc) { + return new dc(a, b); } typeof a === "object" && (b = a, a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -3607,7 +3613,7 @@ function ec(a, b) { this.db = null; this.h = {}; } -w = ec.prototype; +w = dc.prototype; w.mount = function(a) { if (a.index) { return a.mount(this); @@ -3621,18 +3627,18 @@ w.open = function() { } var a = this; navigator.storage && navigator.storage.persist(); - dc[a.id] || (dc[a.id] = []); - dc[a.id].push(a.field); - var b = bc.open(a.id, 1); + cc[a.id] || (cc[a.id] = []); + cc[a.id].push(a.field); + var b = ac.open(a.id, 1); b.onupgradeneeded = function() { - for (var c = a.db = this.result, d = 0, e; d < cc.length; d++) { - e = cc[d]; - for (var f = 0, h; f < dc[a.id].length; f++) { - h = dc[a.id][f], c.objectStoreNames.contains(e + (e !== "reg" ? h ? ":" + h : "" : "")) || c.createObjectStore(e + (e !== "reg" ? h ? ":" + h : "" : "")); + for (var c = a.db = this.result, d = 0, e; d < bc.length; d++) { + e = bc[d]; + for (var f = 0, g; f < cc[a.id].length; f++) { + g = cc[a.id][f], c.objectStoreNames.contains(e + (e !== "reg" ? g ? ":" + g : "" : "")) || c.createObjectStore(e + (e !== "reg" ? g ? ":" + g : "" : "")); } } }; - return a.db = fc(b, function(c) { + return a.db = ec(b, function(c) { a.db = c; a.db.onversionchange = function() { a.close(); @@ -3644,21 +3650,21 @@ w.close = function() { this.db = null; }; w.destroy = function() { - var a = bc.deleteDatabase(this.id); - return fc(a); + var a = ac.deleteDatabase(this.id); + return ec(a); }; w.clear = function() { - for (var a = [], b = 0, c; b < cc.length; b++) { - c = cc[b]; - for (var d = 0, e; d < dc[this.id].length; d++) { - e = dc[this.id][d], a.push(c + (c !== "reg" ? e ? ":" + e : "" : "")); + for (var a = [], b = 0, c; b < bc.length; b++) { + c = bc[b]; + for (var d = 0, e; d < cc[this.id].length; d++) { + e = cc[this.id][d], a.push(c + (c !== "reg" ? e ? ":" + e : "" : "")); } } b = this.db.transaction(a, "readwrite"); for (c = 0; c < a.length; c++) { b.objectStore(a[c]).clear(); } - return fc(b); + return ec(b); }; w.get = function(a, b, c, d, e, f) { c = c === void 0 ? 0 : c; @@ -3666,23 +3672,23 @@ w.get = function(a, b, c, d, e, f) { e = e === void 0 ? !0 : e; f = f === void 0 ? !1 : f; a = this.db.transaction((b ? "ctx" : "map") + (this.field ? ":" + this.field : ""), "readonly").objectStore((b ? "ctx" : "map") + (this.field ? ":" + this.field : "")).get(b ? b + ":" + a : a); - var h = this; - return fc(a).then(function(g) { + var g = this; + return ec(a).then(function(h) { var k = []; - if (!g || !g.length) { + if (!h || !h.length) { return k; } if (e) { - if (!c && !d && g.length === 1) { - return g[0]; + if (!c && !d && h.length === 1) { + return h[0]; } - for (var m = 0, l = void 0; m < g.length; m++) { - if ((l = g[m]) && l.length) { - if (d >= l.length) { - d -= l.length; + for (var l = 0, m = void 0; l < h.length; l++) { + if ((m = h[l]) && m.length) { + if (d >= m.length) { + d -= m.length; } else { - for (var p = c ? d + Math.min(l.length - d, c) : l.length, n = d; n < p; n++) { - k.push(l[n]); + for (var p = c ? d + Math.min(m.length - d, c) : m.length, n = d; n < p; n++) { + k.push(m[n]); } d = 0; if (k.length === c) { @@ -3691,9 +3697,9 @@ w.get = function(a, b, c, d, e, f) { } } } - return f ? h.enrich(k) : k; + return f ? g.enrich(k) : k; } - return g; + return h; }); }; w.tag = function(a, b, c, d) { @@ -3702,7 +3708,7 @@ w.tag = function(a, b, c, d) { d = d === void 0 ? !1 : d; a = this.db.transaction("tag" + (this.field ? ":" + this.field : ""), "readonly").objectStore("tag" + (this.field ? ":" + this.field : "")).get(a); var e = this; - return fc(a).then(function(f) { + return ec(a).then(function(f) { if (!f || !f.length || c >= f.length) { return []; } @@ -3716,7 +3722,7 @@ w.tag = function(a, b, c, d) { w.enrich = function(a) { typeof a !== "object" && (a = [a]); for (var b = this.db.transaction("reg", "readonly").objectStore("reg"), c = [], d = 0; d < a.length; d++) { - c[d] = fc(b.get(a[d])); + c[d] = ec(b.get(a[d])); } return Promise.all(c).then(function(e) { for (var f = 0; f < e.length; f++) { @@ -3727,7 +3733,7 @@ w.enrich = function(a) { }; w.has = function(a) { a = this.db.transaction("reg", "readonly").objectStore("reg").getKey(a); - return fc(a).then(function(b) { + return ec(a).then(function(b) { return !!b; }); }; @@ -3744,174 +3750,142 @@ w.transaction = function(a, b, c) { this.h[a + ":" + b] = d = e.objectStore(a); var f = c.call(this, d); this.h[a + ":" + b] = null; - return fc(e).finally(function() { + return ec(e).finally(function() { e = d = null; return f; }); }; -w.commit = function(a, b, c) { - var d = this, e, f, h; +w.commit = function(a) { + var b = this, c, d, e, f; return wa(function(g) { switch(g.h) { case 1: - if (b) { - return K(g, d.clear(), 12); - } - e = a.commit_task; + c = a.commit_task; + d = []; a.commit_task = []; - f = 0; - h = void 0; - case 4: - if (!(f < e.length)) { - g.h = 6; + e = 0; + for (f = void 0; e < c.length; e++) { + f = c[e], f.del && d.push(f.del); + } + if (!d.length) { + g.h = 2; break; } - h = e[f]; - if (!h.clear) { - e[f] = h.del; - g.h = 5; - break; - } - return K(g, d.clear(), 8); - case 8: - b = !0; - g.h = 6; - break; - case 5: - f++; - g.h = 4; - break; - case 6: - if (b) { - g.h = 3; - break; - } - c || (e = e.concat(Da(a.reg))); - if (!e.length) { - g.h = 10; - break; - } - return K(g, d.remove(e), 11); - case 11: - case 10: - g.h = 3; - break; - case 12: - a.commit_task = []; - case 3: - return a.reg.size ? K(g, d.transaction("map", "readwrite", function(k) { - for (var m = B(a.map), l = m.next(), p = {}; !l.done; p = {M:void 0, U:void 0}, l = m.next()) { - l = l.value, p.U = l[0], p.M = l[1], p.M.length && (b ? k.put(p.M, p.U) : k.get(p.U).onsuccess = function(n) { + return K(g, b.remove(d), 2); + case 2: + return a.reg.size ? K(g, b.transaction("map", "readwrite", function(h) { + for (var k = D(a.map), l = k.next(), m = {}; !l.done; m = {N:void 0, W:void 0}, l = k.next()) { + l = l.value, m.W = l[0], m.N = l[1], m.N.length && (h.get(m.W).onsuccess = function(p) { return function() { - var q = this.result, t; - if (q && q.length) { - for (var u = Math.max(q.length, n.M.length), v = 0, z; v < u; v++) { - if ((z = n.M[v]) && z.length) { - if ((t = q[v]) && t.length) { - for (var x = 0; x < z.length; x++) { - t.push(z[x]); + var n = this.result, q; + if (n && n.length) { + for (var t = Math.max(n.length, p.N.length), u = 0, v; u < t; u++) { + if ((v = p.N[u]) && v.length) { + if ((q = n[u]) && q.length) { + for (var B = 0; B < v.length; B++) { + q.push(v[B]); } } else { - q[v] = z; + n[u] = v; } - t = 1; + q = 1; } } } else { - q = n.M, t = 1; + n = p.N, q = 1; } - t && k.put(q, n.U); + q && h.put(n, p.W); }; - }(p)); + }(m)); } - }), 13) : g.return(); - case 13: - return K(g, d.transaction("ctx", "readwrite", function(k) { - for (var m = B(a.ctx), l = m.next(), p = {}; !l.done; p = {S:void 0}, l = m.next()) { + }), 4) : g.return(); + case 4: + return K(g, b.transaction("ctx", "readwrite", function(h) { + for (var k = D(a.ctx), l = k.next(), m = {}; !l.done; m = {V:void 0}, l = k.next()) { l = l.value; - p.S = l[0]; - l = B(l[1]); - for (var n = l.next(), q = {}; !n.done; q = {N:void 0, V:void 0}, n = l.next()) { - n = n.value, q.V = n[0], q.N = n[1], q.N.length && (b ? k.put(q.N, p.S + ":" + q.V) : k.get(p.S + ":" + q.V).onsuccess = function(t, u) { + m.V = l[0]; + l = D(l[1]); + for (var p = l.next(), n = {}; !p.done; n = {O:void 0, X:void 0}, p = l.next()) { + p = p.value, n.X = p[0], n.O = p[1], n.O.length && (h.get(m.V + ":" + n.X).onsuccess = function(q, t) { return function() { - var v = this.result, z; - if (v && v.length) { - for (var x = Math.max(v.length, t.N.length), C = 0, D; C < x; C++) { - if ((D = t.N[C]) && D.length) { - if ((z = v[C]) && z.length) { - for (var r = 0; r < D.length; r++) { - z.push(D[r]); + var u = this.result, v; + if (u && u.length) { + for (var B = Math.max(u.length, q.O.length), y = 0, A; y < B; y++) { + if ((A = q.O[y]) && A.length) { + if ((v = u[y]) && v.length) { + for (var C = 0; C < A.length; C++) { + v.push(A[C]); } } else { - v[C] = D; + u[y] = A; } - z = 1; + v = 1; } } } else { - v = t.N, z = 1; + u = q.O, v = 1; } - z && k.put(v, u.S + ":" + t.V); + v && h.put(u, t.V + ":" + q.X); }; - }(q, p)); + }(n, m)); } } - }), 14); - case 14: + }), 5); + case 5: if (a.store) { - return K(g, d.transaction("reg", "readwrite", function(k) { - for (var m = B(a.store), l = m.next(); !l.done; l = m.next()) { - var p = l.value; - l = p[0]; - p = p[1]; - k.put(typeof p === "object" ? JSON.stringify(p) : 1, l); + return K(g, b.transaction("reg", "readwrite", function(h) { + for (var k = D(a.store), l = k.next(); !l.done; l = k.next()) { + var m = l.value; + l = m[0]; + m = m[1]; + h.put(typeof m === "object" ? JSON.stringify(m) : 1, l); } - }), 16); + }), 7); } if (a.bypass) { - g.h = 16; + g.h = 7; break; } - return K(g, d.transaction("reg", "readwrite", function(k) { - for (var m = B(a.reg.keys()), l = m.next(); !l.done; l = m.next()) { - k.put(1, l.value); + return K(g, b.transaction("reg", "readwrite", function(h) { + for (var k = D(a.reg.keys()), l = k.next(); !l.done; l = k.next()) { + h.put(1, l.value); } - }), 16); - case 16: + }), 7); + case 7: if (!a.tag) { - g.h = 20; + g.h = 11; break; } - return K(g, d.transaction("tag", "readwrite", function(k) { - for (var m = B(a.tag), l = m.next(), p = {}; !l.done; p = {T:void 0, Z:void 0}, l = m.next()) { - l = l.value, p.Z = l[0], p.T = l[1], p.T.length && (k.get(p.Z).onsuccess = function(n) { + return K(g, b.transaction("tag", "readwrite", function(h) { + for (var k = D(a.tag), l = k.next(), m = {}; !l.done; m = {S:void 0, Z:void 0}, l = k.next()) { + l = l.value, m.Z = l[0], m.S = l[1], m.S.length && (h.get(m.Z).onsuccess = function(p) { return function() { - var q = this.result; - q = q && q.length ? q.concat(n.T) : n.T; - k.put(q, n.Z); + var n = this.result; + n = n && n.length ? n.concat(p.S) : p.S; + h.put(n, p.Z); }; - }(p)); + }(m)); } - }), 20); - case 20: + }), 11); + case 11: a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear(), g.h = 0; } }); }; -function hc(a, b, c) { - for (var d = a.value, e, f = 0, h = 0, g; h < d.length; h++) { - if (g = c ? d : d[h]) { - for (var k = 0, m; k < b.length; k++) { - if (m = b[k], m = g.indexOf(m), m >= 0) { - if (e = 1, g.length > 1) { - g.splice(m, 1); +function fc(a, b, c) { + for (var d = a.value, e, f = 0, g = 0, h; g < d.length; g++) { + if (h = c ? d : d[g]) { + for (var k = 0, l; k < b.length; k++) { + if (l = b[k], l = h.indexOf(l), l >= 0) { + if (e = 1, h.length > 1) { + h.splice(l, 1); } else { - d[h] = []; + d[g] = []; break; } } } - f += g.length; + f += h.length; } if (c) { break; @@ -3925,17 +3899,17 @@ w.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && hc(c, a); + c && fc(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && hc(c, a); + c && fc(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && hc(c, a, !0); + c && fc(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3943,7 +3917,7 @@ w.remove = function(a) { } })]); }; -function fc(a, b) { +function ec(a, b) { return new Promise(function(c, d) { a.onsuccess = a.oncomplete = function() { b && b(this.result); @@ -3954,8 +3928,8 @@ function fc(a, b) { a = null; }); } -;var ic = {Index:Y, Charset:Ua, Encoder:Ka, Document:pb, Worker:mb, Resolver:Z, IndexedDB:ec, Language:{}}, jc = typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : self, kc; -(kc = jc.define) && kc.amd ? kc([], function() { - return ic; -}) : typeof jc.exports === "object" ? jc.exports = ic : jc.FlexSearch = ic; +;var hc = {Index:db, Charset:Ta, Encoder:Ja, Document:ob, Worker:lb, Resolver:Z, IndexedDB:dc, Language:{}}, ic = typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : self, jc; +(jc = ic.define) && jc.amd ? jc([], function() { + return hc; +}) : typeof ic.exports === "object" ? ic.exports = hc : ic.FlexSearch = hc; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index b1d1466..3852273 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -1,145 +1,144 @@ /**! - * FlexSearch.js v0.8.203 (ES5) + * FlexSearch.js v0.8.205 (ES5) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var w;function aa(a){var b=0;return function(){return b>>0)+"_",e=0;return b}); +function va(a){function b(d){return a.next(d)}function c(d){return a.throw(d)}return new Promise(function(d,e){function f(g){g.done?d(g.value):Promise.resolve(g.value).then(b,c).then(f,e)}f(a.next())})}function wa(a){return va(new ta(new pa(a)))} +H("Symbol",function(a){function b(f){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new c(d+(f||"")+"_"+e++,f)}function c(f,g){this.h=f;ca(this,"description",{configurable:!0,writable:!0,value:g})}if(a)return a;c.prototype.toString=function(){return this.h};var d="jscomp_symbol_"+(Math.random()*1E9>>>0)+"_",e=0;return b}); H("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;c0?(d=Array.prototype.flat.call(d,b-1),c.push.apply(c,d)):c.push(d)});return c}}); -H("Promise.prototype.finally",function(a){return a?a:function(b){return this.then(function(c){return Promise.resolve(b()).then(function(){return c})},function(c){return Promise.resolve(b()).then(function(){throw c;})})}});function P(a,b,c){var d=typeof c,e=typeof a;if(d!=="undefined"){if(e!=="undefined"){if(c){if(e==="function"&&d===e)return function(f){return a(c(f))};b=a.constructor;if(b===c.constructor){if(b===Array)return c.concat(a);if(b===Map){b=new Map(c);d=B(a);for(e=d.next();!e.done;e=d.next())e=e.value,b.set(e[0],e[1]);return b}if(b===Set){b=new Set(c);d=B(a.values());for(e=d.next();!e.done;e=d.next())b.add(e.value);return b}}}return a}return c}return e==="undefined"?b:a} -function Ba(a,b){return typeof a==="undefined"?b:a}function S(){return Object.create(null)}function T(a){return typeof a==="string"}function Ca(a){return typeof a==="object"}function Da(a){var b=[];a=B(a.keys());for(var c=a.next();!c.done;c=a.next())b.push(c.value);return b}function Ea(a,b){if(T(b))a=a[b];else for(var c=0;a&&c1)return this.addMatcher(a,b);this.mapper||(this.mapper=new Map);this.mapper.set(a,b);this.cache&&La(this);return this};w.addMatcher=function(a,b){if(typeof a==="object")return this.addReplacer(a,b);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.K=null;this.cache&&La(this);return this}; -w.addReplacer=function(a,b){if(typeof a==="string")return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&La(this);return this}; -w.encode=function(a,b){var c=this;if(this.cache&&a.length<=this.H)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(La,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=Ja?a.normalize("NFKD").replace(Ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(Ha,"$1 $2").replace(Ia,"$1 $2").replace(Ga,"$1 "));for(var d=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer), -e=[],f=S(),h,g,k=this.split||this.split===""?a.split(this.split):[a],m=0,l=void 0,p=void 0;mthis.maxlength)){if(b){if(f[l])continue;f[l]=1}else{if(h===l)continue;h=l}if(d)e.push(l);else if(!this.filter||(typeof this.filter==="function"?this.filter(l):!this.filter.has(l))){if(this.cache&&l.length<=this.I)if(this.D){var n=this.C.get(l);if(n||n===""){n&&e.push(n);continue}}else this.D=setTimeout(La,50,this);if(this.stemmer)for(this.L|| -(this.L=new RegExp("(?!^)("+this.A+")$")),n=void 0;n!==l&&l.length>2;)n=l,l=l.replace(this.L,function(z){return c.stemmer.get(z)});if(l&&(this.mapper||this.dedupe&&l.length>1)){n="";for(var q=0,t="",u=void 0,v=void 0;q1&&(this.K||(this.K=new RegExp("("+this.h+")","g")),l=l.replace(this.K,function(z){return c.matcher.get(z)}));if(l&&this.replacer)for(n= -0;l&&nthis.P&&(this.C.clear(),this.I=this.I/1.1|0));if(l){if(l!==p)if(b){if(f[l])continue;f[l]=1}else{if(g===l)continue;g=l}e.push(l)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.H&&(this.B.set(a,e),this.B.size>this.P&&(this.B.clear(),this.H=this.H/1.1|0));return e};function La(a){a.D=null;a.B.clear();a.C.clear()};function Ma(a,b,c){c||(b||typeof a!=="object"?typeof b==="object"&&(c=b,b=0):c=a);c&&(a=c.query||a,b=c.limit||b);var d=""+(b||0);if(c){var e=c;d+=(e.offset||0)+!!e.context+!!e.suggest+(e.resolve!==!1)+(e.resolution||this.resolution)+(e.boost||0)}a=(""+a).toLowerCase();this.cache||(this.cache=new Na);e=this.cache.get(a+d);if(!e){var f=c&&c.cache;f&&(c.cache=!1);e=this.search(a,b,c);f&&(c.cache=f);this.cache.set(a+d,e)}return e} -function Na(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""}Na.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};Na.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Na.prototype.remove=function(a){for(var b=B(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}}; -Na.prototype.clear=function(){this.cache.clear();this.h=""};var Oa={normalize:!1,numeric:!1,dedupe:!1};var Pa={};var Qa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Ra=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Sa=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Ta={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Ua={Exact:Oa,Default:Pa,Normalize:Pa,LatinBalance:{mapper:Qa},LatinAdvanced:{mapper:Qa,matcher:Ra,replacer:Sa},LatinExtra:{mapper:Qa,replacer:Sa.concat([/(?!^)[aeo]/g,""]),matcher:Ra},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;b=h.length)b-=h.length;else{b=h[d?"splice":"slice"](b,c);if(h=b.length)if(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c)break;b=0}return e} -function Wa(a){if(!this||this.constructor!==Wa)return new Wa(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if(d==="length")return b.length;if(d==="push")return function(e){b.index[b.index.length-1].push(e);b.length++};if(d==="pop")return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if(d==="indexOf")return function(e){for(var f=0,h=0,g,k;h=0)return f+k;f+=g.length}return-1}; -if(d==="includes")return function(e){for(var f=0;f32?(this.A=Ya,this.B=BigInt(a)):(this.A=Za,this.B=a)}Xa.prototype.get=function(a){var b=this.A(a);return(b=this.index[b])&&b.get(a)};Xa.prototype.set=function(a,b){var c=this.A(a),d=this.index[c];d?(c=d.size,d.set(a,b),(c-=d.size)&&this.size++):(this.index[c]=d=new Map([[a,b]]),this.h.push(d),this.size++)}; -function X(a){a=a===void 0?8:a;if(!this||this.constructor!==X)return new X(a);this.index=S();this.h=[];this.size=0;a>32?(this.A=Ya,this.B=BigInt(a)):(this.A=Za,this.B=a)}X.prototype.add=function(a){var b=this.A(a),c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.h.push(c),this.size++)};w=Xa.prototype;w.has=X.prototype.has=function(a){var b=this.A(a);return(b=this.index[b])&&b.has(a)}; -w.delete=X.prototype.delete=function(a){var b=this.A(a);(b=this.index[b])&&b.delete(a)&&this.size--};w.clear=X.prototype.clear=function(){this.index=S();this.h=[];this.size=0};w.values=X.prototype.values=function $a(){var b,c=this,d,e,f;return ua($a,function(h){switch(h.h){case 1:b=0;case 2:if(!(b=this.priority*this.priority*3):(hb=setTimeout(kb,0),ib=Date.now());if(jb){var e=this;return new Promise(function(h){setTimeout(function(){h(e[a+"Async"].apply(e,b))},0)})}var f=this[a].apply(this,b);c=f.then?f:new Promise(function(h){return h(f)});d&&c.then(d);return c}};var lb=0; -function mb(a,b){function c(g){function k(m){m=m.data||m;var l=m.id,p=l&&f.h[l];p&&(p(m.msg),delete f.h[l])}this.worker=g;this.h=S();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(m){lb>1E9&&(lb=0);f.h[++lb]=function(){m(f)};f.worker.postMessage({id:lb,task:"init",factory:d,options:a})});this.priority=a.priority||4;this.encoder=b||null;this.worker.postMessage({task:"init",factory:d,options:a});return this}}a=a===void 0?{}:a;if(!this||this.constructor!== -mb)return new mb(a);var d=typeof self!=="undefined"?self._factory:typeof window!=="undefined"?window._factory:null;d&&(d=d.toString());var e=typeof window==="undefined",f=this,h=nb(d,e,a.worker);return h.then?h.then(function(g){return c.call(f,g)}):c.call(this,h)}ob("add");ob("append");ob("search");ob("update");ob("remove");ob("clear");ob("export");ob("import");mb.prototype.searchCache=Ma;fb(mb.prototype); -function ob(a){mb.prototype[a]=function(){var b=this,c=[].slice.call(arguments),d=c[c.length-1];if(typeof d==="function"){var e=d;c.pop()}d=new Promise(function(f){a==="export"&&typeof c[0]==="function"&&(c[0]=null);lb>1E9&&(lb=0);b.h[++lb]=f;b.worker.postMessage({task:a,id:lb,args:c})});return e?(d.then(e),this):d}} -function nb(a,b,c){return b?typeof module!=="undefined"?new(require("worker_threads")["Worker"])(__dirname+"/node/node.js"):import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+eb.toString()],{type:"text/javascript"}))):new window.Worker(typeof c==="string"?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", -"module/worker/worker.js"),{type:"module"})};pb.prototype.add=function(a,b,c){Ca(a)&&(b=a,a=Ea(b,this.key));if(b&&(a||a===0)){if(!c&&this.reg.has(a))return this.update(a,b);for(var d=0,e;db?a.slice(c,c+b):a,d?tb.call(this,a):a;for(var e=[],f=0,h=void 0,g=void 0;f=g){c-=g;continue}h=h.slice(c,c+b);g=h.length;c=0}g>b&&(h=h.slice(0,b),g=b);if(!e.length&&g>=b)return d?tb.call(this,h):h;e.push(h);b-=g;if(!b)break}e=e.length>1?[].concat.apply([],e):e[0];return d?tb.call(this,e):e};function ub(a,b,c,d){var e=d[0];if(e[0]&&e[0].query)return a[b].apply(a,e);if(!(b!=="and"&&b!=="not"||a.result.length||a.await||e.suggest))return d.length>1&&(e=d[d.length-1]),(d=e.resolve)?a.await||a.result:a;var f=[],h=0,g=0,k,m;b={};for(e=0;e1&&(c=c[b].apply(c,a.slice(1)));return c};Z.prototype.or=function(){return ub(this,"or",xb,arguments)};function xb(a,b,c,d,e,f,h){a.length&&(this.result.length&&a.push(this.result),a.length<2?this.result=a[0]:(this.result=yb(a,b,c,!1,this.h),c=0));e&&(this.await=null);return e?this.resolve(b,c,d,h):this};Z.prototype.and=function(){return ub(this,"and",zb,arguments)};function zb(a,b,c,d,e,f,h){if(!f&&!this.result.length)return e?this.result:this;if(a.length)if(this.result.length&&a.unshift(this.result),a.length<2)this.result=a[0];else{for(var g=0,k=0,m=void 0,l=void 0;k1?W.join(" "):W[0];var O=void 0;if(W&&R){for(var L=R.length,M=(z.split?R.replace(z.split,""):R).length-W.length,ba="",na=0,A=0;A-1&&(ba=(I?R.substring(0,I):"")+h+R.substring(I,I+J)+g+(I+J=k)break}Q=U.length*(f.length-2);if(q||t||k&&r.length-Q>k)if(Q=k+Q-n*2,E=N-G,q>0&&(E+=q),t>0&&(E+=t),E<=Q)y=q?G-(q>0?q:0):G-((Q-E)/2|0),F=t?N+(t>0?t:0):y+Q,m|| -(y>0&&r.charAt(y)!==" "&&r.charAt(y-1)!==" "&&(y=r.indexOf(" ",y),y<0&&(y=0)),F=F.length-1){if(J>=F.length){E[A+1]=1;J>=y.length&&(G[A+1]=1);continue}O-=n}r=F[J].text;var V=t&&W[A];if(V)if(V> -0){if(r.length>V)if(E[A+1]=1,m)r=r.substring(0,V);else continue;(V-=r.length)||(V=-1);W[A]=V}else{E[A+1]=1;continue}if(O+r.length+1<=k)r=" "+r,N[A]+=r;else if(m)I=k-O-1,I>0&&(r=" "+r.substring(0,I),N[A]+=r),E[A+1]=1;else{E[A+1]=1;continue}}else{if(E[A])continue;J-=L;if(Q[J]){O-=n;E[A]=1;G[A]=1;continue}if(J<=0){if(J<0){E[A]=1;G[A]=1;continue}O-=n}r=F[J].text;if(V=q&&R[A])if(V>0){if(r.length>V)if(E[A]=1,m)r=r.substring(r.length-V);else continue;(V-=r.length)||(V=-1);R[A]=V}else{E[A]=1;continue}if(O+ -r.length+1<=k)r+=" ",N[A]=r+N[A];else if(m)I=r.length+1-(k-O),I>=0&&I=y.length-1?I=1:J1?yb(k,c,d,h,f):(k=k[0])&&c&&k.length>c||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d, -c+d)}else{e=[];for(f=0;fd)d-=h.length;else{if(c&&h.length>c||d)h=h.slice(d,c+d),c-=h.length,d&&(d-=h.length);e.push(h);if(!c)break}k=e}}return k} -function yb(a,b,c,d,e){var f=[],h=S(),g=a.length,k;if(d)for(e=g-1;e>=0;e--){if(k=(d=a[e])&&d.length)for(g=0;g=0;l--){p=a[l];for(var q=0;q1?Ab(e,1,0,0,q,l):e[0],N)})}return g?e:new Z(e.length>1?Ab(e,1,0,0,q,l):e[0],this)}}g||k||!(p=p||this.field)||(T(p)?k=p:(p.constructor===Array&&p.length===1&&(p=p[0]),k=p.field||p.index));p&&p.constructor!==Array&&(p=[p])}p||(p=this.field);x=(this.worker||this.db)&&!d&&[];C=0;for(y=D=r=void 0;C0){if(c&&b>c||d)a=a.slice(d,d+c);e&&(a=tb.call(this,a))}return a} -function tb(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);for(var b=Array(a.length),c=0,d;c1?c:c[0]}w.append=function(a,b){return this.add(a,b,!0)}; -w.update=function(a,b){return this.remove(a).add(a,b)}; -w.remove=function(a){Ca(a)&&(a=Ea(a,this.key));for(var b=B(this.index.values()),c=b.next();!c.done;c=b.next())c.value.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(b=B(this.tag.values()),c=b.next();!c.done;c=b.next()){c=c.value;for(var d=B(c),e=d.next();!e.done;e=d.next()){var f=e.value;e=f[0];f=f[1];var h=f.indexOf(a);h>-1&&(f.length>1?f.splice(h,1):c.delete(e))}}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -w.clear=function(){for(var a=[],b=B(this.index.values()),c=b.next();!c.done;c=b.next())c=c.value.clear(),c.then&&a.push(c);if(this.tag)for(b=B(this.tag.values()),c=b.next();!c.done;c=b.next())c.value.clear();this.store&&this.store.clear();this.cache&&this.cache.clear();return a.length?Promise.all(a):this};w.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.reg.has(a)}; -w.cleanup=function(){for(var a=B(this.index.values()),b=a.next();!b.done;b=a.next())b.value.cleanup();return this};w.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(b){return b[0]&&b[0].doc||null}):this.store.get(a)||null};w.set=function(a,b){typeof a==="object"&&(b=a,a=Ea(b,this.key));this.store.set(a,b);return this};w.searchCache=Ma;w.export=Jb;w.import=Kb;fb(pb.prototype);function Lb(a,b){b=b===void 0?0:b;var c=[],d=[];b&&(b=25E4/b*5E3|0);a=B(a.entries());for(var e=a.next();!e.done;e=a.next())d.push(e.value),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function Mb(a,b){b||(b=new Map);for(var c=0,d;c2?c[0]:"";c=c.length>2?c[2]:c[1];if(this.worker&&d)return this.index.get(d).import(a);if(b){typeof b==="string"&&(b=JSON.parse(b));if(d)return this.index.get(d).import(c,b);switch(c){case "reg":this.fastupdate=!1;this.reg=Qb(b,this.reg);for(b=0;b=0&&e.splice(h,1)}}else Tb(this.map,a),this.depth&&Tb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.$&&Ub(this));this.cache&&this.cache.remove(a);return this}; -function Tb(a,b){var c=0,d=typeof b==="undefined";if(a.constructor===Array)for(var e=0,f=void 0,h,g=void 0;e=0){if(f.length>1)return f.splice(h,1),1;delete a[e];if(c)return 1;g=1}else{if(g)return 1;c++}}}else for(d=B(a.entries()),e=d.next();!e.done;e=d.next())e=e.value,f=e[0],Tb(e[1],b)?c++:a.delete(f);return c};var Vb={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};Y.prototype.add=function(a,b,c,d){if(b&&(a||a===0)){if(!d&&!c&&this.reg.has(a))return this.update(a,b);d=this.depth;b=this.encoder.encode(b,!d);var e=b.length;if(e){for(var f=S(),h=S(),g=this.resolution,k=0;k2)for(var q=1,t,u;q2){for(p=0;pp;q--)n=m.substring(p,q),h[n]||(t=this.rtl?l-1-p:p,t=this.score?this.score(b,m,k,n,t):Wb(g,e,k,l,t),Xb(this,h,n,t,a,c));break}case "bidirectional":case "reverse":if(l>1){for(q=l-1;q>0;q--)n=m[this.rtl?l-1-q:q]+n,h[n]||(t=this.score?this.score(b,m,k,n,q):Wb(g,e,k,l,q),Xb(this,h,n,t,a,c));n=""}case "forward":if(l>1){for(q=0;q1&&kn?0:1),e,k,q-1,t-1);var v=this.bidirectional&&m>p;Xb(this,f,v?p:m,u,a,c,v?m:p)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&&(b||this.commit_task.push({del:a}),this.$&&Ub(this));return this}; -function Xb(a,b,c,d,e,f,h){var g=h?a.ctx:a.map,k;if(!b[c]||h&&!(k=b[c])[h])if(h?(b=k||(b[c]=S()),b[h]=1,(k=g.get(h))?g=k:g.set(h,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!f||!g.includes(e)){if(g.length===2147483647){b=new Wa(g);if(a.fastupdate)for(c=B(a.reg.values()),f=c.next();!f.done;f=c.next())f=f.value,f.includes(g)&&(f[f.indexOf(g)]=b);k[d]=g=b}g.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(g):a.reg.set(e,[g]))}} -function Wb(a,b,c,d,e){return c&&a>1?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0};Y.prototype.search=function(a,b,c){c||(b||typeof a!=="object"?typeof b==="object"&&(c=b,b=0):(c=a,a=""));if(c&&c.cache)return c.cache=!1,a=this.searchCache(a,b,c),c.cache=!0,a;var d=[],e=0,f;if(c){a=c.query||a;b=c.limit||b;e=c.offset||0;var h=c.context;var g=c.suggest;var k=(f=c.resolve)&&c.enrich;var m=c.boost;var l=c.resolution;var p=this.db&&c.tag}typeof f==="undefined"&&(f=this.resolve);h=this.depth&&h!==!1;var n=this.encoder.encode(a,!h);var q=n.length;b=b||(f?100:0);if(q===1)return Yb.call(this, -n[0],"",b,e,f,k,p);if(q===2&&h&&!g)return Yb.call(this,n[1],n[0],b,e,f,k,p);var t=S(),u=0;if(h){var v=n[0];u=1}l||l===0||(l=v?this.ba:this.resolution);if(this.db){if(this.db.search&&(c=this.db.search(this,n,b,e,g,f,k,p),c!==!1))return c;var z=this;return function(){var x,C;return wa(function(D){switch(D.h){case 1:C=x=void 0;case 2:if(!(u1)k=Ab(a,b,c,d,e,f,h);else if(g===1)return h?sb.call(null,a[0],c,d):new Z(a[0],this);return h?k:new Z(k,this)}function Yb(a,b,c,d,e,f,h){a=Zb(this,a,b,c,d,e,f,h);return this.db?a.then(function(g){return e?g||[]:new Z(g,this)}):a&&a.length?e?sb.call(this,a,c,d):new Z(a,this):e?[]:new Z([],this)} -function $b(a,b,c,d){var e=[];if(a&&a.length){if(a.length<=d){b.push(a);return}for(var f=0,h;fc)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,f,h,g);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function Y(a,b){if(!this||this.constructor!==Y)return new Y(a);if(a){var c=T(a)?a:a.preset;c&&(a=Object.assign({},Vb[c],a))}else a={};c=a.context;var d=c===!0?{depth:1}:c||{},e=T(a.encoder)?Ua[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:typeof e==="object"?new Ka(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&c!=="default"&&c!=="exact"&&c||"strict";this.depth=c==="strict"&&d.depth||0;this.bidirectional=d.bidirectional!==!1;this.fastupdate=!!a.fastupdate; -this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new Xa(c):new Map;this.ctx=c?new Xa(c):new Map;this.reg=b||(this.fastupdate?c?new Xa(c):new Map:c?new X(c):new Set);this.ba=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new Na(c);this.resolve=a.resolve!==!1;if(c=a.db)this.db=this.mount(c);this.$=a.commit!==!1;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}w=Y.prototype; -w.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};w.commit=function(a,b){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this,a,b)};w.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function Ub(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a,void 0,void 0)},1))} -w.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this};w.append=function(a,b){return this.add(a,b,!0)};w.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};w.update=function(a,b){var c=this,d=this.remove(a);return d&&d.then?d.then(function(){return c.add(a,b)}):this.add(a,b)}; -w.cleanup=function(){if(!this.fastupdate)return this;Tb(this.map);this.depth&&Tb(this.ctx);return this};w.searchCache=Ma;w.export=function(a,b,c,d){c=c===void 0?0:c;d=d===void 0?0:d;switch(d){case 0:var e="reg";var f=Pb(this.reg);break;case 1:e="cfg";f=null;break;case 2:e="map";f=Lb(this.map,this.reg.size);break;case 3:e="ctx";f=Nb(this.ctx,this.reg.size);break;default:return}return Rb.call(this,a,b,e,f,c,d)}; -w.import=function(a,b){if(b)switch(typeof b==="string"&&(b=JSON.parse(b)),a=a.split("."),a[a.length-1]==="json"&&a.pop(),a.length===3&&a.shift(),a=a.length>1?a[1]:a[0],a){case "reg":this.fastupdate=!1;this.reg=Qb(b,this.reg);break;case "map":this.map=Mb(b,this.map);break;case "ctx":this.ctx=Ob(b,this.ctx)}}; -w.serialize=function(a){a=a===void 0?!0:a;var b="",c="",d="";if(this.reg.size){var e;c=B(this.reg.keys());for(var f=c.next();!f.done;f=c.next())f=f.value,e||(e=typeof f),b+=(b?",":"")+(e==="string"?'"'+f+'"':f);b="index.reg=new Set(["+b+"]);";c=Sb(this.map,e);c="index.map=new Map(["+c+"]);";f=B(this.ctx.entries());for(var h=f.next();!h.done;h=f.next()){var g=h.value;h=g[0];g=Sb(g[1],e);g="new Map(["+g+"])";g='["'+h+'",'+g+"]";d+=(d?",":"")+g}d="index.ctx=new Map(["+d+"]);"}return a?"function inject(index){"+ -b+c+d+"}":b+c+d};fb(Y.prototype);var bc=typeof window!=="undefined"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),cc=["map","ctx","tag","reg","cfg"],dc=S(); -function ec(a,b){b=b===void 0?{}:b;if(!this||this.constructor!==ec)return new ec(a,b);typeof a==="object"&&(b=a,a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=b.field?b.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.type=b.type;this.fastupdate=this.support_tag_search=!1;this.db=null;this.h={}}w=ec.prototype; -w.mount=function(a){if(a.index)return a.mount(this);a.db=this;return this.open()}; -w.open=function(){if(this.db)return this.db;var a=this;navigator.storage&&navigator.storage.persist();dc[a.id]||(dc[a.id]=[]);dc[a.id].push(a.field);var b=bc.open(a.id,1);b.onupgradeneeded=function(){for(var c=a.db=this.result,d=0,e;d=l.length)d-=l.length;else{for(var p=c?d+Math.min(l.length-d,c): -l.length,n=d;n=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; -w.enrich=function(a){typeof a!=="object"&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d=0)if(e=1,g.length>1)g.splice(m,1);else{d[h]=[];break}f+=g.length}if(c)break}f?e&&a.update(d):a.delete();a.continue()} -w.remove=function(a){typeof a!=="object"&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&hc(c,a)}}),this.transaction("ctx","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&hc(c,a)}}),this.transaction("tag","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&hc(c,a,!0)}}),this.transaction("reg","readwrite",function(b){for(var c=0;c1)return this.addMatcher(a,b);this.mapper||(this.mapper=new Map);this.mapper.set(a,b);this.cache&&Ka(this);return this};v.addMatcher=function(a,b){if(typeof a==="object")return this.addReplacer(a,b);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,b);this.matcher||(this.matcher=new Map);this.matcher.set(a,b);this.h+=(this.h?"|":"")+a;this.K=null;this.cache&&Ka(this);return this}; +v.addReplacer=function(a,b){if(typeof a==="string")return this.addMatcher(a,b);this.replacer||(this.replacer=[]);this.replacer.push(a,b);this.cache&&Ka(this);return this}; +v.encode=function(a,b){var c=this;if(this.cache&&a.length<=this.H)if(this.D){if(this.B.has(a))return this.B.get(a)}else this.D=setTimeout(Ka,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=Ia?a.normalize("NFKD").replace(Ia,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(Ga,"$1 $2").replace(Ha,"$1 $2").replace(Fa,"$1 "));for(var d=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer), +e=[],f=S(),g,h,k=this.split||this.split===""?a.split(this.split):[a],l=0,m=void 0,p=void 0;lthis.maxlength)){if(b){if(f[m])continue;f[m]=1}else{if(g===m)continue;g=m}if(d)e.push(m);else if(!this.filter||(typeof this.filter==="function"?this.filter(m):!this.filter.has(m))){if(this.cache&&m.length<=this.I)if(this.D){var n=this.C.get(m);if(n||n===""){n&&e.push(n);continue}}else this.D=setTimeout(Ka,50,this);if(this.stemmer)for(this.L|| +(this.L=new RegExp("(?!^)("+this.A+")$")),n=void 0;n!==m&&m.length>2;)n=m,m=m.replace(this.L,function(A){return c.stemmer.get(A)});if(m&&(this.mapper||this.dedupe&&m.length>1)){n="";for(var q=0,t="",u=void 0,w=void 0;q1&&(this.K||(this.K=new RegExp("("+this.h+")","g")),m=m.replace(this.K,function(A){return c.matcher.get(A)}));if(m&&this.replacer)for(n= +0;m&&nthis.P&&(this.C.clear(),this.I=this.I/1.1|0));if(m){if(m!==p)if(b){if(f[m])continue;f[m]=1}else{if(h===m)continue;h=m}e.push(m)}}}this.finalize&&(e=this.finalize(e)||e);this.cache&&a.length<=this.H&&(this.B.set(a,e),this.B.size>this.P&&(this.B.clear(),this.H=this.H/1.1|0));return e};function Ka(a){a.D=null;a.B.clear();a.C.clear()};function La(a,b,c){c||(b||typeof a!=="object"?typeof b==="object"&&(c=b,b=0):c=a);c&&(a=c.query||a,b=c.limit||b);var d=""+(b||0);if(c){var e=c;d+=(e.offset||0)+!!e.context+!!e.suggest+(e.resolve!==!1)+(e.resolution||this.resolution)+(e.boost||0)}a=(""+a).toLowerCase();this.cache||(this.cache=new Ma);e=this.cache.get(a+d);if(!e){var f=c&&c.cache;f&&(c.cache=!1);e=this.search(a,b,c);f&&(c.cache=f);this.cache.set(a+d,e)}return e} +function Ma(a){this.limit=a&&a!==!0?a:1E3;this.cache=new Map;this.h=""}Ma.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};Ma.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};Ma.prototype.remove=function(a){for(var b=D(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}}; +Ma.prototype.clear=function(){this.cache.clear();this.h=""};var Na={normalize:!1,numeric:!1,dedupe:!1};var Oa={};var Pa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Qa=new Map([["ae","a"],["oe","o"],["sh","s"],["kh","k"],["th","t"],["ph","f"],["pf","f"]]),Ra=[/([^aeo])h(.)/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2",/(.)\1+/g,"$1"];var Sa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Ta={Exact:Na,Default:Oa,Normalize:Oa,LatinBalance:{mapper:Pa},LatinAdvanced:{mapper:Pa,matcher:Qa,replacer:Ra},LatinExtra:{mapper:Pa,replacer:Ra.concat([/(?!^)[aeo]/g,""]),matcher:Qa},LatinSoundex:{dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;b=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);if(g=b.length)if(e=e.length?e.concat(b):b,c-=g,d&&(a.length-=g),!c)break;b=0}return e} +function Va(a){if(!this||this.constructor!==Va)return new Va(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if(d==="length")return b.length;if(d==="push")return function(e){b.index[b.index.length-1].push(e);b.length++};if(d==="pop")return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if(d==="indexOf")return function(e){for(var f=0,g=0,h,k;g=0)return f+k;f+=h.length}return-1}; +if(d==="includes")return function(e){for(var f=0;f32?(this.A=Wa,this.B=BigInt(a)):(this.A=Xa,this.B=a)}X.prototype.get=function(a){var b=this.A(a);return(b=this.index[b])&&b.get(a)};X.prototype.set=function(a,b){var c=this.A(a),d=this.index[c];d?(c=d.size,d.set(a,b),(c-=d.size)&&this.size++):(this.index[c]=d=new Map([[a,b]]),this.h.push(d),this.size++)}; +function Y(a){a=a===void 0?8:a;if(!this||this.constructor!==Y)return new Y(a);this.index=S();this.h=[];this.size=0;a>32?(this.A=Wa,this.B=BigInt(a)):(this.A=Xa,this.B=a)}Y.prototype.add=function(a){var b=this.A(a),c=this.index[b];c?(b=c.size,c.add(a),(b-=c.size)&&this.size++):(this.index[b]=c=new Set([a]),this.h.push(c),this.size++)};v=X.prototype;v.has=Y.prototype.has=function(a){var b=this.A(a);return(b=this.index[b])&&b.has(a)}; +v.delete=Y.prototype.delete=function(a){var b=this.A(a);(b=this.index[b])&&b.delete(a)&&this.size--};v.clear=Y.prototype.clear=function(){this.index=S();this.h=[];this.size=0};v.values=Y.prototype.values=function Ya(){var b,c=this,d,e,f;return ua(Ya,function(g){switch(g.h){case 1:b=0;case 2:if(!(b=this.priority*this.priority*3):(gb=setTimeout(jb,0),hb=Date.now());if(ib){var e=this;return new Promise(function(g){setTimeout(function(){g(e[a+"Async"].apply(e,b))},0)})}var f=this[a].apply(this,b);c=f.then?f:new Promise(function(g){return g(f)});d&&c.then(d);return c}};var kb=0; +function lb(a,b){function c(h){function k(l){l=l.data||l;var m=l.id,p=m&&f.h[m];p&&(p(l.msg),delete f.h[m])}this.worker=h;this.h=S();if(this.worker){e?this.worker.on("message",k):this.worker.onmessage=k;if(a.config)return new Promise(function(l){kb>1E9&&(kb=0);f.h[++kb]=function(){l(f)};f.worker.postMessage({id:kb,task:"init",factory:d,options:a})});this.priority=a.priority||4;this.encoder=b||null;this.worker.postMessage({task:"init",factory:d,options:a});return this}}a=a===void 0?{}:a;if(!this||this.constructor!== +lb)return new lb(a);var d=typeof self!=="undefined"?self._factory:typeof window!=="undefined"?window._factory:null;d&&(d=d.toString());var e=typeof window==="undefined",f=this,g=mb(d,e,a.worker);return g.then?g.then(function(h){return c.call(f,h)}):c.call(this,g)}nb("add");nb("append");nb("search");nb("update");nb("remove");nb("clear");nb("export");nb("import");lb.prototype.searchCache=La;eb(lb.prototype); +function nb(a){lb.prototype[a]=function(){var b=this,c=[].slice.call(arguments),d=c[c.length-1];if(typeof d==="function"){var e=d;c.pop()}d=new Promise(function(f){a==="export"&&typeof c[0]==="function"&&(c[0]=null);kb>1E9&&(kb=0);b.h[++kb]=f;b.worker.postMessage({task:a,id:kb,args:c})});return e?(d.then(e),this):d}} +function mb(a,b,c){return b?typeof module!=="undefined"?new(require("worker_threads")["Worker"])(__dirname+"/node/node.js"):import("worker_threads").then(function(worker){return new worker["Worker"]((1,eval)("import.meta.dirname")+"/node/node.mjs")}):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+cb.toString()],{type:"text/javascript"}))):new window.Worker(typeof c==="string"?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};ob.prototype.add=function(a,b,c){Ca(a)&&(b=a,a=Da(b,this.key));if(b&&(a||a===0)){if(!c&&this.reg.has(a))return this.update(a,b);for(var d=0,e;db?a.slice(c,c+b):a,d?sb.call(this,a):a;for(var e=[],f=0,g=void 0,h=void 0;f=h){c-=h;continue}g=g.slice(c,c+b);h=g.length;c=0}h>b&&(g=g.slice(0,b),h=b);if(!e.length&&h>=b)return d?sb.call(this,g):g;e.push(g);b-=h;if(!b)break}e=e.length>1?[].concat.apply([],e):e[0];return d?sb.call(this,e):e};function tb(a,b,c,d){var e=d[0];if(e[0]&&e[0].query)return a[b].apply(a,e);if(!(b!=="and"&&b!=="not"||a.result.length||a.await||e.suggest))return d.length>1&&(e=d[d.length-1]),(d=e.resolve)?a.await||a.result:a;var f=[],g=0,h=0,k;b={};for(e=0;e1&&(c=c[b].apply(c,a.slice(1)));return c};Z.prototype.or=function(){return tb(this,"or",wb,arguments)};function wb(a,b,c,d,e,f,g){a.length&&(this.result.length&&a.push(this.result),a.length<2?this.result=a[0]:(this.result=xb(a,b,c,!1,this.h),c=0));e&&(this.await=null);return e?this.resolve(b,c,d,g):this};Z.prototype.and=function(){return tb(this,"and",yb,arguments)};function yb(a,b,c,d,e,f,g){if(!f&&!this.result.length)return e?this.result:this;if(a.length)if(this.result.length&&a.unshift(this.result),a.length<2)this.result=a[0];else{for(var h=0,k=0,l=void 0,m=void 0;k1?W.join(" "):W[0];var O=void 0;if(W&&R){for(var L=R.length,M=(A.split?R.replace(A.split,""):R).length-W.length,ba="",na=0,y=0;y-1&&(ba=(I?R.substring(0,I):"")+g+R.substring(I,I+J)+h+(I+J=k)break}Q=T.length*(f.length-2);if(q||t||k&&r.length-Q>k)if(Q=k+Q-n*2,F=N-G,q>0&&(F+=q),t>0&&(F+=t),F<=Q)x=q?G-(q>0?q:0):G-((Q-F)/2|0),E=t?N+(t>0?t:0):x+Q,l|| +(x>0&&r.charAt(x)!==" "&&r.charAt(x-1)!==" "&&(x=r.indexOf(" ",x),x<0&&(x=0)),E=E.length-1){if(J>=E.length){F[y+1]=1;J>=x.length&&(G[y+1]=1);continue}O-=n}r=E[J].text;var V=t&&W[y];if(V)if(V> +0){if(r.length>V)if(F[y+1]=1,l)r=r.substring(0,V);else continue;(V-=r.length)||(V=-1);W[y]=V}else{F[y+1]=1;continue}if(O+r.length+1<=k)r=" "+r,N[y]+=r;else if(l)I=k-O-1,I>0&&(r=" "+r.substring(0,I),N[y]+=r),F[y+1]=1;else{F[y+1]=1;continue}}else{if(F[y])continue;J-=L;if(Q[J]){O-=n;F[y]=1;G[y]=1;continue}if(J<=0){if(J<0){F[y]=1;G[y]=1;continue}O-=n}r=E[J].text;if(V=q&&R[y])if(V>0){if(r.length>V)if(F[y]=1,l)r=r.substring(r.length-V);else continue;(V-=r.length)||(V=-1);R[y]=V}else{F[y]=1;continue}if(O+ +r.length+1<=k)r+=" ",N[y]=r+N[y];else if(l)I=r.length+1-(k-O),I>=0&&I=x.length-1?I=1:J1?xb(k,c,d,g,f):(k=k[0])&&c&&k.length>c||d?k.slice(d,c+d):k;else{if(ac||d)k=k.slice(d, +c+d)}else{e=[];for(f=0;fd)d-=g.length;else{if(c&&g.length>c||d)g=g.slice(d,c+d),c-=g.length,d&&(d-=g.length);e.push(g);if(!c)break}k=e}}return k} +function xb(a,b,c,d,e){var f=[],g=S(),h=a.length,k;if(d)for(e=h-1;e>=0;e--){if(k=(d=a[e])&&d.length)for(h=0;h=0;m--){p=a[m];for(var q=0;q1?zb(e,1,0,0,q,m):e[0],N)})}return h?e:new Z(e.length>1?zb(e,1,0,0,q,m):e[0],this)}}h||k||!(p=p||this.field)||(U(p)?k=p:(p.constructor===Array&&p.length===1&&(p=p[0]),k=p.field||p.index));p&&p.constructor!==Array&&(p=[p])}p||(p=this.field);B=(this.worker||this.db)&&!d&&[];z=0;for(x=C=r=void 0;z0){if(c&&b>c||d)a=a.slice(d,d+c);e&&(a=sb.call(this,a))}return a} +function sb(a){if(!this||!this.store)return a;if(this.db)return this.index.get(this.field[0]).db.enrich(a);for(var b=Array(a.length),c=0,d;c1?c:c[0]}v.append=function(a,b){return this.add(a,b,!0)}; +v.update=function(a,b){return this.remove(a).add(a,b)}; +v.remove=function(a){Ca(a)&&(a=Da(a,this.key));for(var b=D(this.index.values()),c=b.next();!c.done;c=b.next())c.value.remove(a,!0);if(this.reg.has(a)){if(this.tag&&!this.fastupdate)for(b=D(this.tag.values()),c=b.next();!c.done;c=b.next()){c=c.value;for(var d=D(c),e=d.next();!e.done;e=d.next()){var f=e.value;e=f[0];f=f[1];var g=f.indexOf(a);g>-1&&(f.length>1?f.splice(g,1):c.delete(e))}}this.store&&this.store.delete(a);this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +v.clear=function(){for(var a=[],b=D(this.index.values()),c=b.next();!c.done;c=b.next())c=c.value.clear(),c.then&&a.push(c);if(this.tag)for(b=D(this.tag.values()),c=b.next();!c.done;c=b.next())c.value.clear();this.store&&this.store.clear();this.cache&&this.cache.clear();return a.length?Promise.all(a):this};v.contain=function(a){return this.db?this.index.get(this.field[0]).db.has(a):this.reg.has(a)}; +v.cleanup=function(){for(var a=D(this.index.values()),b=a.next();!b.done;b=a.next())b.value.cleanup();return this};v.get=function(a){return this.db?this.index.get(this.field[0]).db.enrich(a).then(function(b){return b[0]&&b[0].doc||null}):this.store.get(a)||null};v.set=function(a,b){typeof a==="object"&&(b=a,a=Da(b,this.key));this.store.set(a,b);return this};v.searchCache=La;v.export=Ib;v.import=Jb;eb(ob.prototype);function Kb(a,b){b=b===void 0?0:b;var c=[],d=[];b&&(b=25E4/b*5E3|0);a=D(a.entries());for(var e=a.next();!e.done;e=a.next())d.push(e.value),d.length===b&&(c.push(d),d=[]);d.length&&c.push(d);return c}function Lb(a,b){b||(b=new Map);for(var c=0,d;c2?c[0]:"";c=c.length>2?c[2]:c[1];if(this.worker&&d)return this.index.get(d).import(a);if(b){typeof b==="string"&&(b=JSON.parse(b));if(d)return this.index.get(d).import(c,b);switch(c){case "reg":this.fastupdate=!1;this.reg=Pb(b,this.reg);for(b=0;b=0&&e.splice(g,1)}}else Sb(this.map,a),this.depth&&Sb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.$&&Tb(this));this.cache&&this.cache.remove(a);return this}; +function Sb(a,b){var c=0,d=typeof b==="undefined";if(a.constructor===Array)for(var e=0,f=void 0,g,h=void 0;e=0){if(f.length>1)return f.splice(g,1),1;delete a[e];if(c)return 1;h=1}else{if(h)return 1;c++}}}else for(d=D(a.entries()),e=d.next();!e.done;e=d.next())e=e.value,f=e[0],Sb(e[1],b)?c++:a.delete(f);return c};var Ub={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};db.prototype.add=function(a,b,c,d){if(b&&(a||a===0)){if(!d&&!c&&this.reg.has(a))return this.update(a,b);d=this.depth;b=this.encoder.encode(b,!d);var e=b.length;if(e){for(var f=S(),g=S(),h=this.resolution,k=0;k2){for(var q=1,t,u;q2){for(p=0;pp;q--)n=l.substring(p,q),t=this.rtl?m-1-p:p,t=this.score?this.score(b,l,k,n,t):Vb(h,e,k,m,t),Wb(this,g,n,t,a,c);break}case "bidirectional":case "reverse":if(m>1){for(q=m-1;q>0;q--)n=l[this.rtl?m-1-q:q]+n,t=this.score?this.score(b,l,k,n,q):Vb(h,e,k,m,q),Wb(this,g,n,t,a,c);n=""}case "forward":if(m>1){for(q=0;q1&&kn,u=this.score?this.score(b,n,k,l,q-1):Vb(m+(e/2>m?0:1),e,k,p-1,q-1),Wb(this,f,t?n:l,u,a,c,t?l:n)}}}this.fastupdate||this.reg.add(a)}}this.db&&(this.commit_task.push(c?{ins:a}:{del:a}),this.$&&Tb(this));return this}; +function Wb(a,b,c,d,e,f,g){var h;if(!(h=b[c])||g&&!h[g]){if(g){b=h||(b[c]=S());b[g]=1;var k=a.ctx;(h=k.get(g))?k=h:k.set(g,k=a.keystore?new X(a.keystore):new Map)}else k=a.map,b[c]=1;(h=k.get(c))?k=h:k.set(c,k=h=[]);if(f)for(c=0;c1?b+(d||0)<=a?c+(e||0):(a-1)/(b+(d||0))*(c+(e||0))+1|0:0};db.prototype.search=function(a,b,c){c||(b||typeof a!=="object"?typeof b==="object"&&(c=b,b=0):(c=a,a=""));if(c&&c.cache)return c.cache=!1,a=this.searchCache(a,b,c),c.cache=!0,a;var d=[],e=0,f;if(c){a=c.query||a;b=c.limit||b;e=c.offset||0;var g=c.context;var h=c.suggest;var k=(f=c.resolve)&&c.enrich;var l=c.boost;var m=c.resolution;var p=this.db&&c.tag}typeof f==="undefined"&&(f=this.resolve);g=this.depth&&g!==!1;var n=this.encoder.encode(a,!g);var q=n.length;b=b||(f?100:0);if(q===1)return Xb.call(this, +n[0],"",b,e,f,k,p);if(q===2&&g&&!h)return Xb.call(this,n[1],n[0],b,e,f,k,p);var t=S(),u=0;if(g){var w=n[0];u=1}m||m===0||(m=w?this.ba:this.resolution);if(this.db){if(this.db.search&&(c=this.db.search(this,n,b,e,h,f,k,p),c!==!1))return c;var A=this;return function(){var B,z;return wa(function(C){switch(C.h){case 1:z=B=void 0;case 2:if(!(u1)k=zb(a,b,c,d,e,f,g);else if(h===1)return g?rb.call(null,a[0],c,d):new Z(a[0],this);return g?k:new Z(k,this)}function Xb(a,b,c,d,e,f,g){a=Yb(this,a,b,c,d,e,f,g);return this.db?a.then(function(h){return e?h||[]:new Z(h,this)}):a&&a.length?e?rb.call(this,a,c,d):new Z(a,this):e?[]:new Z([],this)} +function Zb(a,b,c,d){var e=[];if(a&&a.length){if(a.length<=d){b.push(a);return}for(var f=0,g;fc)&&(k=c,c=b,b=k);if(a.db)return a.db.get(b,c,d,e,f,g,h);a=c?(a=a.ctx.get(c))&&a.get(b):a.map.get(b);return a};function db(a,b){if(!this||this.constructor!==db)return new db(a);if(a){var c=U(a)?a:a.preset;c&&(a=Object.assign({},Ub[c],a))}else a={};c=a.context;var d=c===!0?{depth:1}:c||{},e=U(a.encoder)?Ta[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:typeof e==="object"?new Ja(e):{encode:e};this.resolution=a.resolution||9;this.tokenize=c=(c=a.tokenize)&&c!=="default"&&c!=="exact"&&c||"strict";this.depth=c==="strict"&&d.depth||0;this.bidirectional=d.bidirectional!==!1;this.fastupdate=!!a.fastupdate; +this.score=a.score||null;(c=a.keystore||0)&&(this.keystore=c);this.map=c?new X(c):new Map;this.ctx=c?new X(c):new Map;this.reg=b||(this.fastupdate?c?new X(c):new Map:c?new Y(c):new Set);this.ba=d.resolution||3;this.rtl=e.rtl||a.rtl||!1;this.cache=(c=a.cache||null)&&new Ma(c);this.resolve=a.resolve!==!1;if(c=a.db)this.db=this.mount(c);this.$=a.commit!==!1;this.commit_task=[];this.commit_timer=null;this.priority=a.priority||4}v=db.prototype; +v.mount=function(a){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return a.mount(this)};v.commit=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.commit(this)};v.destroy=function(){this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null);return this.db.destroy()};function Tb(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null;a.db.commit(a)},1))} +v.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();this.cache&&this.cache.clear();return this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this};v.append=function(a,b){return this.add(a,b,!0)};v.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)};v.update=function(a,b){var c=this,d=this.remove(a);return d&&d.then?d.then(function(){return c.add(a,b)}):this.add(a,b)}; +v.cleanup=function(){if(!this.fastupdate)return this;Sb(this.map);this.depth&&Sb(this.ctx);return this};v.searchCache=La;v.export=function(a,b,c,d){c=c===void 0?0:c;d=d===void 0?0:d;switch(d){case 0:var e="reg";var f=Ob(this.reg);break;case 1:e="cfg";f=null;break;case 2:e="map";f=Kb(this.map,this.reg.size);break;case 3:e="ctx";f=Mb(this.ctx,this.reg.size);break;default:return}return Qb.call(this,a,b,e,f,c,d)}; +v.import=function(a,b){if(b)switch(typeof b==="string"&&(b=JSON.parse(b)),a=a.split("."),a[a.length-1]==="json"&&a.pop(),a.length===3&&a.shift(),a=a.length>1?a[1]:a[0],a){case "reg":this.fastupdate=!1;this.reg=Pb(b,this.reg);break;case "map":this.map=Lb(b,this.map);break;case "ctx":this.ctx=Nb(b,this.ctx)}}; +v.serialize=function(a){a=a===void 0?!0:a;var b="",c="",d="";if(this.reg.size){var e;c=D(this.reg.keys());for(var f=c.next();!f.done;f=c.next())f=f.value,e||(e=typeof f),b+=(b?",":"")+(e==="string"?'"'+f+'"':f);b="index.reg=new Set(["+b+"]);";c=Rb(this.map,e);c="index.map=new Map(["+c+"]);";f=D(this.ctx.entries());for(var g=f.next();!g.done;g=f.next()){var h=g.value;g=h[0];h=Rb(h[1],e);h="new Map(["+h+"])";h='["'+g+'",'+h+"]";d+=(d?",":"")+h}d="index.ctx=new Map(["+d+"]);"}return a?"function inject(index){"+ +b+c+d+"}":b+c+d};eb(db.prototype);var ac=typeof window!=="undefined"&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),bc=["map","ctx","tag","reg","cfg"],cc=S(); +function dc(a,b){b=b===void 0?{}:b;if(!this||this.constructor!==dc)return new dc(a,b);typeof a==="object"&&(b=a,a=a.name);a||console.info("Default storage space was used, because a name was not passed.");this.id="flexsearch"+(a?":"+a.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"");this.field=b.field?b.field.toLowerCase().replace(/[^a-z0-9_\-]/g,""):"";this.type=b.type;this.fastupdate=this.support_tag_search=!1;this.db=null;this.h={}}v=dc.prototype; +v.mount=function(a){if(a.index)return a.mount(this);a.db=this;return this.open()}; +v.open=function(){if(this.db)return this.db;var a=this;navigator.storage&&navigator.storage.persist();cc[a.id]||(cc[a.id]=[]);cc[a.id].push(a.field);var b=ac.open(a.id,1);b.onupgradeneeded=function(){for(var c=a.db=this.result,d=0,e;d=m.length)d-=m.length;else{for(var p=c?d+Math.min(m.length-d,c): +m.length,n=d;n=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; +v.enrich=function(a){typeof a!=="object"&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d=0)if(e=1,h.length>1)h.splice(l,1);else{d[g]=[];break}f+=h.length}if(c)break}f?e&&a.update(d):a.delete();a.continue()} +v.remove=function(a){typeof a!=="object"&&(a=[a]);return Promise.all([this.transaction("map","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&fc(c,a)}}),this.transaction("ctx","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&fc(c,a)}}),this.transaction("tag","readwrite",function(b){b.openCursor().onsuccess=function(){var c=this.result;c&&fc(c,a,!0)}}),this.transaction("reg","readwrite",function(b){for(var c=0;c 3 && (a = a.replace(C, "$1 $2").replace(D, "$1 $2").replace(B, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let f = [], d = y(), g, e, k = this.split || this.split === "" ? a.split(this.split) : [a]; - for (let n = 0, h, r; n < k.length; n++) { - if ((h = r = k[n]) && !(h.length < this.minlength || h.length > this.maxlength)) { + let f = [], d = z(), h, e, k = this.split || this.split === "" ? a.split(this.split) : [a]; + for (let n = 0, g, t; n < k.length; n++) { + if ((g = t = k[n]) && !(g.length < this.minlength || g.length > this.maxlength)) { if (c) { - if (d[h]) { + if (d[g]) { continue; } - d[h] = 1; + d[g] = 1; } else { - if (g === h) { + if (h === g) { continue; } - g = h; + h = g; } if (b) { - f.push(h); + f.push(g); } else { - if (!this.filter || (typeof this.filter === "function" ? this.filter(h) : !this.filter.has(h))) { - if (this.cache && h.length <= this.o) { + if (!this.filter || (typeof this.filter === "function" ? this.filter(g) : !this.filter.has(g))) { + if (this.cache && g.length <= this.o) { if (this.l) { - var m = this.j.get(h); - if (m || m === "") { - m && f.push(m); + var l = this.j.get(g); + if (l || l === "") { + l && f.push(l); continue; } } else { @@ -219,39 +219,39 @@ u.encode = function(a, c) { if (this.stemmer) { this.u || (this.u = new RegExp("(?!^)(" + this.h + ")$")); let w; - for (; w !== h && h.length > 2;) { - w = h, h = h.replace(this.u, q => this.stemmer.get(q)); + for (; w !== g && g.length > 2;) { + w = g, g = g.replace(this.u, q => this.stemmer.get(q)); } } - if (h && (this.mapper || this.dedupe && h.length > 1)) { - m = ""; - for (let w = 0, q = "", l, p; w < h.length; w++) { - l = h.charAt(w), l === q && this.dedupe || ((p = this.mapper && this.mapper.get(l)) || p === "" ? p === q && this.dedupe || !(q = p) || (m += p) : m += q = l); + if (g && (this.mapper || this.dedupe && g.length > 1)) { + l = ""; + for (let w = 0, q = "", m, p; w < g.length; w++) { + m = g.charAt(w), m === q && this.dedupe || ((p = this.mapper && this.mapper.get(m)) || p === "" ? p === q && this.dedupe || !(q = p) || (l += p) : l += q = m); } - h = m; + g = l; } - this.matcher && h.length > 1 && (this.s || (this.s = new RegExp("(" + this.g + ")", "g")), h = h.replace(this.s, w => this.matcher.get(w))); - if (h && this.replacer) { - for (m = 0; h && m < this.replacer.length; m += 2) { - h = h.replace(this.replacer[m], this.replacer[m + 1]); + this.matcher && g.length > 1 && (this.s || (this.s = new RegExp("(" + this.g + ")", "g")), g = g.replace(this.s, w => this.matcher.get(w))); + if (g && this.replacer) { + for (l = 0; g && l < this.replacer.length; l += 2) { + g = g.replace(this.replacer[l], this.replacer[l + 1]); } } - this.cache && r.length <= this.o && (this.j.set(r, h), this.j.size > this.A && (this.j.clear(), this.o = this.o / 1.1 | 0)); - if (h) { - if (h !== r) { + this.cache && t.length <= this.o && (this.j.set(t, g), this.j.size > this.A && (this.j.clear(), this.o = this.o / 1.1 | 0)); + if (g) { + if (g !== t) { if (c) { - if (d[h]) { + if (d[g]) { continue; } - d[h] = 1; + d[g] = 1; } else { - if (e === h) { + if (e === g) { continue; } - e = h; + e = g; } } - f.push(h); + f.push(g); } } } @@ -274,22 +274,22 @@ function G(a) { return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a; } let f = []; - for (let d = 0, g, e; d < a.length; d++) { - if ((g = a[d]) && (e = g.length)) { + for (let d = 0, h, e; d < a.length; d++) { + if ((h = a[d]) && (e = h.length)) { if (b) { if (b >= e) { b -= e; continue; } - g = g.slice(b, b + c); - e = g.length; + h = h.slice(b, b + c); + e = h.length; b = 0; } - e > c && (g = g.slice(0, c), e = c); + e > c && (h = h.slice(0, c), e = c); if (!f.length && e >= c) { - return g; + return h; } - f.push(g); + f.push(h); c -= e; if (!c) { break; @@ -298,14 +298,14 @@ function G(a) { } return f = f.length > 1 ? [].concat.apply([], f) : f[0]; } -;y(); +;z(); J.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { - for (let f = 0, d, g; f < b.length; f++) { - if ((d = b[f]) && (g = d.length)) { - if (d[g - 1] === a) { + for (let f = 0, d, h; f < b.length; f++) { + if ((d = b[f]) && (h = d.length)) { + if (d[h - 1] === a) { d.pop(); } else { const e = d.indexOf(a); @@ -324,15 +324,15 @@ function K(a, c) { let b = 0; var f = typeof c === "undefined"; if (a.constructor === Array) { - for (let d = 0, g, e, k; d < a.length; d++) { - if ((g = a[d]) && g.length) { + for (let d = 0, h, e, k; d < a.length; d++) { + if ((h = a[d]) && h.length) { if (f) { return 1; } - e = g.indexOf(c); + e = h.indexOf(c); if (e >= 0) { - if (g.length > 1) { - return g.splice(e, 1), 1; + if (h.length > 1) { + return h.splice(e, 1), 1; } delete a[d]; if (b) { @@ -364,30 +364,30 @@ J.prototype.add = function(a, c, b, f) { c = this.encoder.encode(c, !f); const n = c.length; if (n) { - const h = y(), r = y(), w = this.resolution; + const g = z(), t = z(), w = this.resolution; for (let q = 0; q < n; q++) { - let l = c[this.rtl ? n - 1 - q : q]; - var d = l.length; - if (d && (f || !r[l])) { - var g = this.score ? this.score(c, l, q, null, 0) : M(w, n, q), e = ""; + let m = c[this.rtl ? n - 1 - q : q]; + var d = m.length; + if (d && (f || !t[m])) { + var h = this.score ? this.score(c, m, q, null, 0) : M(w, n, q), e = ""; switch(this.tokenize) { case "tolerant": - N(this, r, l, g, a, b); + N(this, t, m, h, a, b); if (d > 2) { - for (let p = 1, t, z, x, I; p < d - 1; p++) { - t = l.charAt(p), z = l.charAt(p + 1), x = l.substring(0, p) + z, I = l.substring(p + 2), e = x + t + I, r[e] || N(this, r, e, g, a, b), e = x + I, r[e] || N(this, r, e, g, a, b); + for (let p = 1, u, y, x, I; p < d - 1; p++) { + u = m.charAt(p), y = m.charAt(p + 1), x = m.substring(0, p) + y, I = m.substring(p + 2), e = x + u + I, N(this, t, e, h, a, b), e = x + I, N(this, t, e, h, a, b); } + N(this, t, m.substring(0, m.length - 1), h, a, b); } break; case "full": if (d > 2) { - for (let p = 0, t; p < d; p++) { - for (g = d; g > p; g--) { - if (e = l.substring(p, g), !r[e]) { - t = this.rtl ? d - 1 - p : p; - var k = this.score ? this.score(c, l, q, e, t) : M(w, n, q, d, t); - N(this, r, e, k, a, b); - } + for (let p = 0, u; p < d; p++) { + for (h = d; h > p; h--) { + e = m.substring(p, h); + u = this.rtl ? d - 1 - p : p; + var k = this.score ? this.score(c, m, q, e, u) : M(w, n, q, d, u); + N(this, t, e, k, a, b); } } break; @@ -396,28 +396,26 @@ J.prototype.add = function(a, c, b, f) { case "reverse": if (d > 1) { for (k = d - 1; k > 0; k--) { - if (e = l[this.rtl ? d - 1 - k : k] + e, !r[e]) { - var m = this.score ? this.score(c, l, q, e, k) : M(w, n, q, d, k); - N(this, r, e, m, a, b); - } + e = m[this.rtl ? d - 1 - k : k] + e; + var l = this.score ? this.score(c, m, q, e, k) : M(w, n, q, d, k); + N(this, t, e, l, a, b); } e = ""; } case "forward": if (d > 1) { for (k = 0; k < d; k++) { - e += l[this.rtl ? d - 1 - k : k], r[e] || N(this, r, e, g, a, b); + e += m[this.rtl ? d - 1 - k : k], N(this, t, e, h, a, b); } break; } default: - if (N(this, r, l, g, a, b), f && n > 1 && q < n - 1) { - for (d = y(), e = this.v, g = l, k = Math.min(f + 1, this.rtl ? q + 1 : n - q), d[g] = 1, m = 1; m < k; m++) { - if ((l = c[this.rtl ? n - 1 - q - m : q + m]) && !d[l]) { - d[l] = 1; - const p = this.score ? this.score(c, g, q, l, m - 1) : M(e + (n / 2 > e ? 0 : 1), n, q, k - 1, m - 1), t = this.bidirectional && l > g; - N(this, h, t ? g : l, p, a, b, t ? l : g); - } + if (N(this, t, m, h, a, b), f && n > 1 && q < n - 1) { + for (d = this.v, e = m, h = Math.min(f + 1, this.rtl ? q + 1 : n - q), k = 1; k < h; k++) { + m = c[this.rtl ? n - 1 - q - k : q + k]; + l = this.bidirectional && m > e; + const p = this.score ? this.score(c, e, q, m, k - 1) : M(d + (n / 2 > d ? 0 : 1), n, q, h - 1, k - 1); + N(this, g, l ? e : m, p, a, b, l ? m : e); } } } @@ -428,10 +426,26 @@ J.prototype.add = function(a, c, b, f) { } return this; }; -function N(a, c, b, f, d, g, e) { - let k = e ? a.ctx : a.map, m; - if (!c[b] || e && !(m = c[b])[e]) { - e ? (c = m || (c[b] = y()), c[e] = 1, (m = k.get(e)) ? k = m : k.set(e, k = new Map())) : c[b] = 1, (m = k.get(b)) ? k = m : k.set(b, k = []), k = k[f] || (k[f] = []), g && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); +function N(a, c, b, f, d, h, e) { + let k, l; + if (!(k = c[b]) || e && !k[e]) { + e ? (c = k || (c[b] = z()), c[e] = 1, l = a.ctx, (k = l.get(e)) ? l = k : l.set(e, l = new Map())) : (l = a.map, c[b] = 1); + (k = l.get(b)) ? l = k : l.set(b, l = k = []); + if (h) { + for (let n = 0, g; n < k.length; n++) { + if ((g = k[n]) && g.includes(d)) { + if (n <= f) { + return; + } + g.splice(g.indexOf(d), 1); + a.fastupdate && (c = a.reg.get(d)) && c.splice(c.indexOf(g), 1); + break; + } + } + } + l = l[f] || (l[f] = []); + l.push(d); + a.fastupdate && ((f = a.reg.get(d)) ? f.push(l) : a.reg.set(d, [l])); } } function M(a, c, b, f, d) { @@ -444,80 +458,80 @@ function M(a, c, b, f, d) { a = b.query || a; c = b.limit || c; d = b.offset || 0; - var g = b.context; + var h = b.context; var e = b.suggest; var k = !0; - var m = b.resolution; + var l = b.resolution; } typeof k === "undefined" && (k = !0); - g = this.depth && g !== !1; - a = this.encoder.encode(a, !g); + h = this.depth && h !== !1; + a = this.encoder.encode(a, !h); b = a.length; c = c || (k ? 100 : 0); if (b === 1) { return e = d, (d = O(this, a[0], "")) && d.length ? H.call(this, d, c, e) : []; } - if (b === 2 && g && !e) { + if (b === 2 && h && !e) { return e = d, (d = O(this, a[1], a[0])) && d.length ? H.call(this, d, c, e) : []; } - k = y(); + k = z(); var n = 0; - if (g) { - var h = a[0]; + if (h) { + var g = a[0]; n = 1; } - m || m === 0 || (m = h ? this.v : this.resolution); - for (let l, p; n < b; n++) { + l || l === 0 || (l = g ? this.v : this.resolution); + for (let m, p; n < b; n++) { if ((p = a[n]) && !k[p]) { k[p] = 1; - l = O(this, p, h); + m = O(this, p, g); a: { - g = l; - var r = f, w = e, q = m; - let t = []; - if (g && g.length) { - if (g.length <= q) { - r.push(g); - l = void 0; + h = m; + var t = f, w = e, q = l; + let u = []; + if (h && h.length) { + if (h.length <= q) { + t.push(h); + m = void 0; break a; } - for (let z = 0, x; z < q; z++) { - if (x = g[z]) { - t[z] = x; + for (let y = 0, x; y < q; y++) { + if (x = h[y]) { + u[y] = x; } } - if (t.length) { - r.push(t); - l = void 0; + if (u.length) { + t.push(u); + m = void 0; break a; } } - l = w ? void 0 : t; + m = w ? void 0 : u; } - if (l) { - f = l; + if (m) { + f = m; break; } - h && (e && l && f.length || (h = p)); + g && (e && m && f.length || (g = p)); } - e && h && n === b - 1 && !f.length && (m = this.resolution, h = "", n = -1, k = y()); + e && g && n === b - 1 && !f.length && (l = this.resolution, g = "", n = -1, k = z()); } a: { a = f; f = a.length; - h = a; + g = a; if (f > 1) { b: { f = e; - h = a.length; + g = a.length; e = []; - b = y(); - for (let l = 0, p, t, z, x; l < m; l++) { - for (n = 0; n < h; n++) { - if (z = a[n], l < z.length && (p = z[l])) { - for (g = 0; g < p.length; g++) { - if (t = p[g], (k = b[t]) ? b[t]++ : (k = 0, b[t] = 1), x = e[k] || (e[k] = []), x.push(t), c && k === h - 1 && x.length - d === c) { - h = d ? x.slice(d) : x; + b = z(); + for (let m = 0, p, u, y, x; m < l; m++) { + for (n = 0; n < g; n++) { + if (y = a[n], m < y.length && (p = y[m])) { + for (h = 0; h < p.length; h++) { + if (u = p[h], (k = b[u]) ? b[u]++ : (k = 0, b[u] = 1), x = e[k] || (e[k] = []), x.push(u), c && k === g - 1 && x.length - d === c) { + g = d ? x.slice(d) : x; break b; } } @@ -528,14 +542,14 @@ function M(a, c, b, f, d) { if (f) { if (e.length > 1) { c: { - for (a = [], m = y(), f = e.length, k = f - 1; k >= 0; k--) { + for (a = [], l = z(), f = e.length, k = f - 1; k >= 0; k--) { if (b = (f = e[k]) && f.length) { for (n = 0; n < b; n++) { - if (h = f[n], !m[h]) { - if (m[h] = 1, d) { + if (g = f[n], !l[g]) { + if (l[g] = 1, d) { d--; } else { - if (a.push(h), a.length === c) { + if (a.push(g), a.length === c) { break c; } } @@ -549,8 +563,8 @@ function M(a, c, b, f, d) { } e = a; } else { - if (a < h) { - h = []; + if (a < g) { + g = []; break b; } e = e[a - 1]; @@ -561,13 +575,13 @@ function M(a, c, b, f, d) { } } } - h = e; + g = e; } } else if (f === 1) { c = H.call(null, a[0], c, d); break a; } - c = h; + c = g; } return c; }; @@ -603,24 +617,24 @@ function O(a, c, b) { this.v = f.resolution || 3; this.rtl = d.rtl || a.rtl || !1; } -u = J.prototype; -u.clear = function() { +r = J.prototype; +r.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); return this; }; -u.append = function(a, c) { +r.append = function(a, c) { return this.add(a, c, !0); }; -u.contain = function(a) { +r.contain = function(a) { return this.reg.has(a); }; -u.update = function(a, c) { +r.update = function(a, c) { const b = this, f = this.remove(a); return f && f.then ? f.then(() => b.add(a, c)) : this.add(a, c); }; -u.cleanup = function() { +r.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } @@ -628,7 +642,7 @@ u.cleanup = function() { this.depth && K(this.ctx); return this; }; -y(); +z(); const P = {Index:J, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Q = typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : self; let R; (R = Q.define) && R.amd ? R([], function() { diff --git a/dist/flexsearch.light.min.js b/dist/flexsearch.light.min.js index 4cc624d..2ef1bba 100644 --- a/dist/flexsearch.light.min.js +++ b/dist/flexsearch.light.min.js @@ -1,27 +1,28 @@ /**! - * FlexSearch.js v0.8.203 (Light) + * FlexSearch.js v0.8.205 (Light) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -(function(self){'use strict';var u;function v(a,c,b){const f=typeof b,d=typeof a;if(f!=="undefined"){if(d!=="undefined"){if(b){if(d==="function"&&f===d)return function(k){return a(b(k))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var e of a)g.set(e[0],e[1]);return g}if(c===Set){e=new Set(b);for(g of a.values())e.add(g);return e}}}return a}return b}return d==="undefined"?c:a}function y(){return Object.create(null)};const A=/[^\p{L}\p{N}]+/u,B=/(\d{3})/g,C=/(\D)(\d{3})/g,D=/(\d{3})(\D)/g,E=/[\u0300-\u036f]/g;function F(a={}){if(!this||this.constructor!==F)return new F(...arguments);if(arguments.length)for(a=0;a1)return this.addMatcher(a,c);this.mapper||(this.mapper=new Map);this.mapper.set(a,c);this.cache&&G(this);return this};u.addMatcher=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&G(this);return this}; -u.addReplacer=function(a,c){if(typeof a==="string")return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; -u.encode=function(a,c){if(this.cache&&a.length<=this.m)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(G,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=E?a.normalize("NFKD").replace(E,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(C,"$1 $2").replace(D,"$1 $2").replace(B,"$1 "));const b=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let f=[], -d=y(),g,e,k=this.split||this.split===""?a.split(this.split):[a];for(let n=0,h,r;nthis.maxlength)){if(c){if(d[h])continue;d[h]=1}else{if(g===h)continue;g=h}if(b)f.push(h);else if(!this.filter||(typeof this.filter==="function"?this.filter(h):!this.filter.has(h))){if(this.cache&&h.length<=this.o)if(this.l){var m=this.j.get(h);if(m||m===""){m&&f.push(m);continue}}else this.l=setTimeout(G,50,this);if(this.stemmer){this.u||(this.u=new RegExp("(?!^)("+ -this.h+")$"));let w;for(;w!==h&&h.length>2;)w=h,h=h.replace(this.u,q=>this.stemmer.get(q))}if(h&&(this.mapper||this.dedupe&&h.length>1)){m="";for(let w=0,q="",l,p;w1&&(this.s||(this.s=new RegExp("("+this.g+")","g")),h=h.replace(this.s,w=>this.matcher.get(w)));if(h&&this.replacer)for(m=0;h&&mthis.A&&(this.j.clear(),this.o=this.o/1.1|0));if(h){if(h!==r)if(c){if(d[h])continue;d[h]=1}else{if(e===h)continue;e=h}f.push(h)}}}this.finalize&&(f=this.finalize(f)||f);this.cache&&a.length<=this.m&&(this.i.set(a,f),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return f};function G(a){a.l=null;a.i.clear();a.j.clear()};function H(a,c,b){if(!a.length)return a;if(a.length===1)return a=a[0],a=b||a.length>c?a.slice(b,b+c):a;let f=[];for(let d=0,g,e;d=e){b-=e;continue}g=g.slice(b,b+c);e=g.length;b=0}e>c&&(g=g.slice(0,c),e=c);if(!f.length&&e>=c)return g;f.push(g);c-=e;if(!c)break}return f=f.length>1?[].concat.apply([],f):f[0]};y();J.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,d,g;f=0&&d.splice(e,1)}}else K(this.map,a),this.depth&&K(this.ctx,a);c||this.reg.delete(a)}return this}; -function K(a,c){let b=0;var f=typeof c==="undefined";if(a.constructor===Array)for(let d=0,g,e,k;d=0){if(g.length>1)return g.splice(e,1),1;delete a[d];if(b)return 1;k=1}else{if(k)return 1;b++}}}else for(let d of a.entries())f=d[0],K(d[1],c)?b++:a.delete(f);return b};const L={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};J.prototype.add=function(a,c,b,f){if(c&&(a||a===0)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);f=this.depth;c=this.encoder.encode(c,!f);const n=c.length;if(n){const h=y(),r=y(),w=this.resolution;for(let q=0;q2)for(let p=1,t,z,x,I;p2){for(let p=0,t;pp;g--)if(e=l.substring(p,g),!r[e]){t=this.rtl?d-1-p:p;var k=this.score?this.score(c,l,q,e,t):M(w,n,q,d,t);N(this,r,e,k,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(k=d-1;k>0;k--)if(e=l[this.rtl?d-1-k:k]+e,!r[e]){var m=this.score?this.score(c,l,q,e,k):M(w,n,q,d,k);N(this,r,e,m,a,b)}e=""}case "forward":if(d>1){for(k=0;k1&&qe?0:1),n,q,k-1,m-1),t=this.bidirectional&&l>g;N(this,h,t?g:l,p,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function N(a,c,b,f,d,g,e){let k=e?a.ctx:a.map,m;if(!c[b]||e&&!(m=c[b])[e])e?(c=m||(c[b]=y()),c[e]=1,(m=k.get(e))?k=m:k.set(e,k=new Map)):c[b]=1,(m=k.get(b))?k=m:k.set(b,k=[]),k=k[f]||(k[f]=[]),g&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function M(a,c,b,f,d){return b&&a>1?c+(f||0)<=a?b+(d||0):(a-1)/(c+(f||0))*(b+(d||0))+1|0:0};J.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));var f=[],d=0;if(b){a=b.query||a;c=b.limit||c;d=b.offset||0;var g=b.context;var e=b.suggest;var k=!0;var m=b.resolution}typeof k==="undefined"&&(k=!0);g=this.depth&&g!==!1;a=this.encoder.encode(a,!g);b=a.length;c=c||(k?100:0);if(b===1)return e=d,(d=O(this,a[0],""))&&d.length?H.call(this,d,c,e):[];if(b===2&&g&&!e)return e=d,(d=O(this,a[1],a[0]))&&d.length?H.call(this,d,c,e):[];k=y();var n=0;if(g){var h= -a[0];n=1}m||m===0||(m=h?this.v:this.resolution);for(let l,p;n1)b:{f=e;h=a.length;e=[];b=y();for(let l=0,p,t,z,x;l1)c:for(a=[],m=y(),f=e.length,k=f-1;k>=0;k--){if(b=(f=e[k])&&f.length)for(n=0;nc||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}h=e}else if(f=== -1){c=H.call(null,a[0],c,d);break a}c=h}return c};function O(a,c,b){let f;b&&(f=a.bidirectional&&c>b)&&(f=b,b=c,c=f);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function J(a,c){if(!this||this.constructor!==J)return new J(a);if(a){var b=typeof a==="string"?a:a.preset;b&&(a=Object.assign({},L[b],a))}else a={};b=a.context;const f=b===!0?{depth:1}:b||{},d=a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new F(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&b!=="default"&&b!=="exact"&&b||"strict";this.depth=b==="strict"&&f.depth||0;this.bidirectional=f.bidirectional!==!1;this.fastupdate=!!a.fastupdate;this.score= -a.score||null;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.v=f.resolution||3;this.rtl=d.rtl||a.rtl||!1}u=J.prototype;u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};u.append=function(a,c){return this.add(a,c,!0)};u.contain=function(a){return this.reg.has(a)};u.update=function(a,c){const b=this,f=this.remove(a);return f&&f.then?f.then(()=>b.add(a,c)):this.add(a,c)}; -u.cleanup=function(){if(!this.fastupdate)return this;K(this.map);this.depth&&K(this.ctx);return this};y();const P={Index:J,Charset:null,Encoder:F,Document:null,Worker:null,Resolver:null,IndexedDB:null,Language:{}},Q=typeof self!=="undefined"?self:typeof global!=="undefined"?global:self;let R;(R=Q.define)&&R.amd?R([],function(){return P}):typeof Q.exports==="object"?Q.exports=P:Q.FlexSearch=P;}(this||self)); +(this.h?"|":"")+d;return this};r.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.u=null;this.cache&&G(this);return this};r.addFilter=function(a){typeof a==="function"?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&G(this);return this}; +r.addMapper=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length>1)return this.addMatcher(a,c);this.mapper||(this.mapper=new Map);this.mapper.set(a,c);this.cache&&G(this);return this};r.addMatcher=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&G(this);return this}; +r.addReplacer=function(a,c){if(typeof a==="string")return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; +r.encode=function(a,c){if(this.cache&&a.length<=this.m)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(G,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=E?a.normalize("NFKD").replace(E,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(C,"$1 $2").replace(D,"$1 $2").replace(B,"$1 "));const b=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let f=[], +d=z(),h,e,k=this.split||this.split===""?a.split(this.split):[a];for(let n=0,g,t;nthis.maxlength)){if(c){if(d[g])continue;d[g]=1}else{if(h===g)continue;h=g}if(b)f.push(g);else if(!this.filter||(typeof this.filter==="function"?this.filter(g):!this.filter.has(g))){if(this.cache&&g.length<=this.o)if(this.l){var l=this.j.get(g);if(l||l===""){l&&f.push(l);continue}}else this.l=setTimeout(G,50,this);if(this.stemmer){this.u||(this.u=new RegExp("(?!^)("+ +this.h+")$"));let w;for(;w!==g&&g.length>2;)w=g,g=g.replace(this.u,q=>this.stemmer.get(q))}if(g&&(this.mapper||this.dedupe&&g.length>1)){l="";for(let w=0,q="",m,p;w1&&(this.s||(this.s=new RegExp("("+this.g+")","g")),g=g.replace(this.s,w=>this.matcher.get(w)));if(g&&this.replacer)for(l=0;g&&lthis.A&&(this.j.clear(),this.o=this.o/1.1|0));if(g){if(g!==t)if(c){if(d[g])continue;d[g]=1}else{if(e===g)continue;e=g}f.push(g)}}}this.finalize&&(f=this.finalize(f)||f);this.cache&&a.length<=this.m&&(this.i.set(a,f),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return f};function G(a){a.l=null;a.i.clear();a.j.clear()};function H(a,c,b){if(!a.length)return a;if(a.length===1)return a=a[0],a=b||a.length>c?a.slice(b,b+c):a;let f=[];for(let d=0,h,e;d=e){b-=e;continue}h=h.slice(b,b+c);e=h.length;b=0}e>c&&(h=h.slice(0,c),e=c);if(!f.length&&e>=c)return h;f.push(h);c-=e;if(!c)break}return f=f.length>1?[].concat.apply([],f):f[0]};z();J.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,d,h;f=0&&d.splice(e,1)}}else K(this.map,a),this.depth&&K(this.ctx,a);c||this.reg.delete(a)}return this}; +function K(a,c){let b=0;var f=typeof c==="undefined";if(a.constructor===Array)for(let d=0,h,e,k;d=0){if(h.length>1)return h.splice(e,1),1;delete a[d];if(b)return 1;k=1}else{if(k)return 1;b++}}}else for(let d of a.entries())f=d[0],K(d[1],c)?b++:a.delete(f);return b};const L={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};J.prototype.add=function(a,c,b,f){if(c&&(a||a===0)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);f=this.depth;c=this.encoder.encode(c,!f);const n=c.length;if(n){const g=z(),t=z(),w=this.resolution;for(let q=0;q2){for(let p=1,u,y,x,I;p2){for(let p=0,u;pp;h--){e=m.substring(p,h);u=this.rtl?d-1-p:p;var k=this.score?this.score(c,m,q,e,u):M(w,n,q,d,u);N(this,t,e,k,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(k=d-1;k>0;k--){e=m[this.rtl?d-1-k:k]+e;var l=this.score?this.score(c,m,q,e,k):M(w,n,q,d,k);N(this,t,e,l,a,b)}e=""}case "forward":if(d>1){for(k=0;k1&&qe;const p=this.score?this.score(c,e,q,m,k-1):M(d+(n/2>d?0:1),n,q,h-1,k-1);N(this,g,l?e:m,p,a,b,l?m:e)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function N(a,c,b,f,d,h,e){let k,l;if(!(k=c[b])||e&&!k[e]){e?(c=k||(c[b]=z()),c[e]=1,l=a.ctx,(k=l.get(e))?l=k:l.set(e,l=new Map)):(l=a.map,c[b]=1);(k=l.get(b))?l=k:l.set(b,l=k=[]);if(h)for(let n=0,g;n1?c+(f||0)<=a?b+(d||0):(a-1)/(c+(f||0))*(b+(d||0))+1|0:0};J.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));var f=[],d=0;if(b){a=b.query||a;c=b.limit||c;d=b.offset||0;var h=b.context;var e=b.suggest;var k=!0;var l=b.resolution}typeof k==="undefined"&&(k=!0);h=this.depth&&h!==!1;a=this.encoder.encode(a,!h);b=a.length;c=c||(k?100:0);if(b===1)return e=d,(d=O(this,a[0],""))&&d.length?H.call(this,d,c,e):[];if(b===2&&h&&!e)return e=d,(d=O(this,a[1],a[0]))&&d.length?H.call(this,d,c,e):[];k=z();var n=0;if(h){var g= +a[0];n=1}l||l===0||(l=g?this.v:this.resolution);for(let m,p;n1)b:{f=e;g=a.length;e=[];b=z();for(let m=0,p,u,y,x;m1)c:for(a=[],l=z(),f=e.length,k=f-1;k>=0;k--){if(b=(f=e[k])&&f.length)for(n=0;nc||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}g=e}else if(f=== +1){c=H.call(null,a[0],c,d);break a}c=g}return c};function O(a,c,b){let f;b&&(f=a.bidirectional&&c>b)&&(f=b,b=c,c=f);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function J(a,c){if(!this||this.constructor!==J)return new J(a);if(a){var b=typeof a==="string"?a:a.preset;b&&(a=Object.assign({},L[b],a))}else a={};b=a.context;const f=b===!0?{depth:1}:b||{},d=a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new F(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&b!=="default"&&b!=="exact"&&b||"strict";this.depth=b==="strict"&&f.depth||0;this.bidirectional=f.bidirectional!==!1;this.fastupdate=!!a.fastupdate;this.score= +a.score||null;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.v=f.resolution||3;this.rtl=d.rtl||a.rtl||!1}r=J.prototype;r.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};r.append=function(a,c){return this.add(a,c,!0)};r.contain=function(a){return this.reg.has(a)};r.update=function(a,c){const b=this,f=this.remove(a);return f&&f.then?f.then(()=>b.add(a,c)):this.add(a,c)}; +r.cleanup=function(){if(!this.fastupdate)return this;K(this.map);this.depth&&K(this.ctx);return this};z();const P={Index:J,Charset:null,Encoder:F,Document:null,Worker:null,Resolver:null,IndexedDB:null,Language:{}},Q=typeof self!=="undefined"?self:typeof global!=="undefined"?global:self;let R;(R=Q.define)&&R.amd?R([],function(){return P}):typeof Q.exports==="object"?Q.exports=P:Q.FlexSearch=P;}(this||self)); diff --git a/dist/flexsearch.light.module.debug.js b/dist/flexsearch.light.module.debug.js index cefe36e..52fddd2 100644 --- a/dist/flexsearch.light.module.debug.js +++ b/dist/flexsearch.light.module.debug.js @@ -1,11 +1,11 @@ /**! - * FlexSearch.js v0.8.203 (Bundle/Debug) + * FlexSearch.js v0.8.205 (Bundle/Debug) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u; +var r; function v(a, c, b) { const f = typeof b, d = typeof a; if (f !== "undefined") { @@ -22,16 +22,16 @@ function v(a, c, b) { return b.concat(a); } if (c === Map) { - var g = new Map(b); + var h = new Map(b); for (var e of a) { - g.set(e[0], e[1]); + h.set(e[0], e[1]); } - return g; + return h; } if (c === Set) { e = new Set(b); - for (g of a.values()) { - e.add(g); + for (h of a.values()) { + e.add(h); } return e; } @@ -43,7 +43,7 @@ function v(a, c, b) { } return d === "undefined" ? c : a; } -function y() { +function z() { return Object.create(null); } ;const A = /[^\p{L}\p{N}]+/u, B = /(\d{3})/g, C = /(\D)(\d{3})/g, D = /(\d{3})(\D)/g, E = /[\u0300-\u036f]/g; @@ -59,8 +59,8 @@ function F(a = {}) { this.assign(a); } } -u = F.prototype; -u.assign = function(a) { +r = F.prototype; +r.assign = function(a) { this.normalize = v(a.normalize, !0, this.normalize); let c = a.include, b = c || a.exclude || a.split, f; if (b || b === "") { @@ -78,7 +78,7 @@ u.assign = function(a) { } try { this.split = new RegExp("[" + (c ? "^" : "") + d + "]+", "u"); - } catch (g) { + } catch (h) { console.error("Your split configuration:", b, "is not supported on this platform. It falls back to using simple whitespace splitter instead: /s+/."), this.split = /\s+/; } } else { @@ -124,7 +124,7 @@ u.assign = function(a) { } return this; }; -u.addStemmer = function(a, c) { +r.addStemmer = function(a, c) { this.stemmer || (this.stemmer = new Map()); this.stemmer.set(a, c); this.h += (this.h ? "|" : "") + a; @@ -132,12 +132,12 @@ u.addStemmer = function(a, c) { this.cache && G(this); return this; }; -u.addFilter = function(a) { +r.addFilter = function(a) { typeof a === "function" ? this.filter = a : (this.filter || (this.filter = new Set()), this.filter.add(a)); this.cache && G(this); return this; }; -u.addMapper = function(a, c) { +r.addMapper = function(a, c) { if (typeof a === "object") { return this.addReplacer(a, c); } @@ -149,7 +149,7 @@ u.addMapper = function(a, c) { this.cache && G(this); return this; }; -u.addMatcher = function(a, c) { +r.addMatcher = function(a, c) { if (typeof a === "object") { return this.addReplacer(a, c); } @@ -163,7 +163,7 @@ u.addMatcher = function(a, c) { this.cache && G(this); return this; }; -u.addReplacer = function(a, c) { +r.addReplacer = function(a, c) { if (typeof a === "string") { return this.addMatcher(a, c); } @@ -172,7 +172,7 @@ u.addReplacer = function(a, c) { this.cache && G(this); return this; }; -u.encode = function(a, c) { +r.encode = function(a, c) { if (this.cache && a.length <= this.m) { if (this.l) { if (this.i.has(a)) { @@ -186,29 +186,29 @@ u.encode = function(a, c) { this.prepare && (a = this.prepare(a)); this.numeric && a.length > 3 && (a = a.replace(C, "$1 $2").replace(D, "$1 $2").replace(B, "$1 ")); const b = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); - let f = [], d = y(), g, e, k = this.split || this.split === "" ? a.split(this.split) : [a]; - for (let n = 0, h, r; n < k.length; n++) { - if ((h = r = k[n]) && !(h.length < this.minlength || h.length > this.maxlength)) { + let f = [], d = z(), h, e, k = this.split || this.split === "" ? a.split(this.split) : [a]; + for (let n = 0, g, t; n < k.length; n++) { + if ((g = t = k[n]) && !(g.length < this.minlength || g.length > this.maxlength)) { if (c) { - if (d[h]) { + if (d[g]) { continue; } - d[h] = 1; + d[g] = 1; } else { - if (g === h) { + if (h === g) { continue; } - g = h; + h = g; } if (b) { - f.push(h); + f.push(g); } else { - if (!this.filter || (typeof this.filter === "function" ? this.filter(h) : !this.filter.has(h))) { - if (this.cache && h.length <= this.o) { + if (!this.filter || (typeof this.filter === "function" ? this.filter(g) : !this.filter.has(g))) { + if (this.cache && g.length <= this.o) { if (this.l) { - var m = this.j.get(h); - if (m || m === "") { - m && f.push(m); + var l = this.j.get(g); + if (l || l === "") { + l && f.push(l); continue; } } else { @@ -218,39 +218,39 @@ u.encode = function(a, c) { if (this.stemmer) { this.u || (this.u = new RegExp("(?!^)(" + this.h + ")$")); let w; - for (; w !== h && h.length > 2;) { - w = h, h = h.replace(this.u, q => this.stemmer.get(q)); + for (; w !== g && g.length > 2;) { + w = g, g = g.replace(this.u, q => this.stemmer.get(q)); } } - if (h && (this.mapper || this.dedupe && h.length > 1)) { - m = ""; - for (let w = 0, q = "", l, p; w < h.length; w++) { - l = h.charAt(w), l === q && this.dedupe || ((p = this.mapper && this.mapper.get(l)) || p === "" ? p === q && this.dedupe || !(q = p) || (m += p) : m += q = l); + if (g && (this.mapper || this.dedupe && g.length > 1)) { + l = ""; + for (let w = 0, q = "", m, p; w < g.length; w++) { + m = g.charAt(w), m === q && this.dedupe || ((p = this.mapper && this.mapper.get(m)) || p === "" ? p === q && this.dedupe || !(q = p) || (l += p) : l += q = m); } - h = m; + g = l; } - this.matcher && h.length > 1 && (this.s || (this.s = new RegExp("(" + this.g + ")", "g")), h = h.replace(this.s, w => this.matcher.get(w))); - if (h && this.replacer) { - for (m = 0; h && m < this.replacer.length; m += 2) { - h = h.replace(this.replacer[m], this.replacer[m + 1]); + this.matcher && g.length > 1 && (this.s || (this.s = new RegExp("(" + this.g + ")", "g")), g = g.replace(this.s, w => this.matcher.get(w))); + if (g && this.replacer) { + for (l = 0; g && l < this.replacer.length; l += 2) { + g = g.replace(this.replacer[l], this.replacer[l + 1]); } } - this.cache && r.length <= this.o && (this.j.set(r, h), this.j.size > this.A && (this.j.clear(), this.o = this.o / 1.1 | 0)); - if (h) { - if (h !== r) { + this.cache && t.length <= this.o && (this.j.set(t, g), this.j.size > this.A && (this.j.clear(), this.o = this.o / 1.1 | 0)); + if (g) { + if (g !== t) { if (c) { - if (d[h]) { + if (d[g]) { continue; } - d[h] = 1; + d[g] = 1; } else { - if (e === h) { + if (e === g) { continue; } - e = h; + e = g; } } - f.push(h); + f.push(g); } } } @@ -273,22 +273,22 @@ function G(a) { return a = a[0], a = b || a.length > c ? a.slice(b, b + c) : a; } let f = []; - for (let d = 0, g, e; d < a.length; d++) { - if ((g = a[d]) && (e = g.length)) { + for (let d = 0, h, e; d < a.length; d++) { + if ((h = a[d]) && (e = h.length)) { if (b) { if (b >= e) { b -= e; continue; } - g = g.slice(b, b + c); - e = g.length; + h = h.slice(b, b + c); + e = h.length; b = 0; } - e > c && (g = g.slice(0, c), e = c); + e > c && (h = h.slice(0, c), e = c); if (!f.length && e >= c) { - return g; + return h; } - f.push(g); + f.push(h); c -= e; if (!c) { break; @@ -297,14 +297,14 @@ function G(a) { } return f = f.length > 1 ? [].concat.apply([], f) : f[0]; } -;y(); +;z(); J.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { - for (let f = 0, d, g; f < b.length; f++) { - if ((d = b[f]) && (g = d.length)) { - if (d[g - 1] === a) { + for (let f = 0, d, h; f < b.length; f++) { + if ((d = b[f]) && (h = d.length)) { + if (d[h - 1] === a) { d.pop(); } else { const e = d.indexOf(a); @@ -323,15 +323,15 @@ function K(a, c) { let b = 0; var f = typeof c === "undefined"; if (a.constructor === Array) { - for (let d = 0, g, e, k; d < a.length; d++) { - if ((g = a[d]) && g.length) { + for (let d = 0, h, e, k; d < a.length; d++) { + if ((h = a[d]) && h.length) { if (f) { return 1; } - e = g.indexOf(c); + e = h.indexOf(c); if (e >= 0) { - if (g.length > 1) { - return g.splice(e, 1), 1; + if (h.length > 1) { + return h.splice(e, 1), 1; } delete a[d]; if (b) { @@ -363,30 +363,30 @@ J.prototype.add = function(a, c, b, f) { c = this.encoder.encode(c, !f); const n = c.length; if (n) { - const h = y(), r = y(), w = this.resolution; + const g = z(), t = z(), w = this.resolution; for (let q = 0; q < n; q++) { - let l = c[this.rtl ? n - 1 - q : q]; - var d = l.length; - if (d && (f || !r[l])) { - var g = this.score ? this.score(c, l, q, null, 0) : M(w, n, q), e = ""; + let m = c[this.rtl ? n - 1 - q : q]; + var d = m.length; + if (d && (f || !t[m])) { + var h = this.score ? this.score(c, m, q, null, 0) : M(w, n, q), e = ""; switch(this.tokenize) { case "tolerant": - N(this, r, l, g, a, b); + N(this, t, m, h, a, b); if (d > 2) { - for (let p = 1, t, z, x, H; p < d - 1; p++) { - t = l.charAt(p), z = l.charAt(p + 1), x = l.substring(0, p) + z, H = l.substring(p + 2), e = x + t + H, r[e] || N(this, r, e, g, a, b), e = x + H, r[e] || N(this, r, e, g, a, b); + for (let p = 1, u, y, x, H; p < d - 1; p++) { + u = m.charAt(p), y = m.charAt(p + 1), x = m.substring(0, p) + y, H = m.substring(p + 2), e = x + u + H, N(this, t, e, h, a, b), e = x + H, N(this, t, e, h, a, b); } + N(this, t, m.substring(0, m.length - 1), h, a, b); } break; case "full": if (d > 2) { - for (let p = 0, t; p < d; p++) { - for (g = d; g > p; g--) { - if (e = l.substring(p, g), !r[e]) { - t = this.rtl ? d - 1 - p : p; - var k = this.score ? this.score(c, l, q, e, t) : M(w, n, q, d, t); - N(this, r, e, k, a, b); - } + for (let p = 0, u; p < d; p++) { + for (h = d; h > p; h--) { + e = m.substring(p, h); + u = this.rtl ? d - 1 - p : p; + var k = this.score ? this.score(c, m, q, e, u) : M(w, n, q, d, u); + N(this, t, e, k, a, b); } } break; @@ -395,28 +395,26 @@ J.prototype.add = function(a, c, b, f) { case "reverse": if (d > 1) { for (k = d - 1; k > 0; k--) { - if (e = l[this.rtl ? d - 1 - k : k] + e, !r[e]) { - var m = this.score ? this.score(c, l, q, e, k) : M(w, n, q, d, k); - N(this, r, e, m, a, b); - } + e = m[this.rtl ? d - 1 - k : k] + e; + var l = this.score ? this.score(c, m, q, e, k) : M(w, n, q, d, k); + N(this, t, e, l, a, b); } e = ""; } case "forward": if (d > 1) { for (k = 0; k < d; k++) { - e += l[this.rtl ? d - 1 - k : k], r[e] || N(this, r, e, g, a, b); + e += m[this.rtl ? d - 1 - k : k], N(this, t, e, h, a, b); } break; } default: - if (N(this, r, l, g, a, b), f && n > 1 && q < n - 1) { - for (d = y(), e = this.v, g = l, k = Math.min(f + 1, this.rtl ? q + 1 : n - q), d[g] = 1, m = 1; m < k; m++) { - if ((l = c[this.rtl ? n - 1 - q - m : q + m]) && !d[l]) { - d[l] = 1; - const p = this.score ? this.score(c, g, q, l, m - 1) : M(e + (n / 2 > e ? 0 : 1), n, q, k - 1, m - 1), t = this.bidirectional && l > g; - N(this, h, t ? g : l, p, a, b, t ? l : g); - } + if (N(this, t, m, h, a, b), f && n > 1 && q < n - 1) { + for (d = this.v, e = m, h = Math.min(f + 1, this.rtl ? q + 1 : n - q), k = 1; k < h; k++) { + m = c[this.rtl ? n - 1 - q - k : q + k]; + l = this.bidirectional && m > e; + const p = this.score ? this.score(c, e, q, m, k - 1) : M(d + (n / 2 > d ? 0 : 1), n, q, h - 1, k - 1); + N(this, g, l ? e : m, p, a, b, l ? m : e); } } } @@ -427,10 +425,26 @@ J.prototype.add = function(a, c, b, f) { } return this; }; -function N(a, c, b, f, d, g, e) { - let k = e ? a.ctx : a.map, m; - if (!c[b] || e && !(m = c[b])[e]) { - e ? (c = m || (c[b] = y()), c[e] = 1, (m = k.get(e)) ? k = m : k.set(e, k = new Map())) : c[b] = 1, (m = k.get(b)) ? k = m : k.set(b, k = []), k = k[f] || (k[f] = []), g && k.includes(d) || (k.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(k) : a.reg.set(d, [k]))); +function N(a, c, b, f, d, h, e) { + let k, l; + if (!(k = c[b]) || e && !k[e]) { + e ? (c = k || (c[b] = z()), c[e] = 1, l = a.ctx, (k = l.get(e)) ? l = k : l.set(e, l = new Map())) : (l = a.map, c[b] = 1); + (k = l.get(b)) ? l = k : l.set(b, l = k = []); + if (h) { + for (let n = 0, g; n < k.length; n++) { + if ((g = k[n]) && g.includes(d)) { + if (n <= f) { + return; + } + g.splice(g.indexOf(d), 1); + a.fastupdate && (c = a.reg.get(d)) && c.splice(c.indexOf(g), 1); + break; + } + } + } + l = l[f] || (l[f] = []); + l.push(d); + a.fastupdate && ((f = a.reg.get(d)) ? f.push(l) : a.reg.set(d, [l])); } } function M(a, c, b, f, d) { @@ -443,80 +457,80 @@ function M(a, c, b, f, d) { a = b.query || a; c = b.limit || c; d = b.offset || 0; - var g = b.context; + var h = b.context; var e = b.suggest; var k = !0; - var m = b.resolution; + var l = b.resolution; } typeof k === "undefined" && (k = !0); - g = this.depth && g !== !1; - a = this.encoder.encode(a, !g); + h = this.depth && h !== !1; + a = this.encoder.encode(a, !h); b = a.length; c = c || (k ? 100 : 0); if (b === 1) { return e = d, (d = O(this, a[0], "")) && d.length ? I.call(this, d, c, e) : []; } - if (b === 2 && g && !e) { + if (b === 2 && h && !e) { return e = d, (d = O(this, a[1], a[0])) && d.length ? I.call(this, d, c, e) : []; } - k = y(); + k = z(); var n = 0; - if (g) { - var h = a[0]; + if (h) { + var g = a[0]; n = 1; } - m || m === 0 || (m = h ? this.v : this.resolution); - for (let l, p; n < b; n++) { + l || l === 0 || (l = g ? this.v : this.resolution); + for (let m, p; n < b; n++) { if ((p = a[n]) && !k[p]) { k[p] = 1; - l = O(this, p, h); + m = O(this, p, g); a: { - g = l; - var r = f, w = e, q = m; - let t = []; - if (g && g.length) { - if (g.length <= q) { - r.push(g); - l = void 0; + h = m; + var t = f, w = e, q = l; + let u = []; + if (h && h.length) { + if (h.length <= q) { + t.push(h); + m = void 0; break a; } - for (let z = 0, x; z < q; z++) { - if (x = g[z]) { - t[z] = x; + for (let y = 0, x; y < q; y++) { + if (x = h[y]) { + u[y] = x; } } - if (t.length) { - r.push(t); - l = void 0; + if (u.length) { + t.push(u); + m = void 0; break a; } } - l = w ? void 0 : t; + m = w ? void 0 : u; } - if (l) { - f = l; + if (m) { + f = m; break; } - h && (e && l && f.length || (h = p)); + g && (e && m && f.length || (g = p)); } - e && h && n === b - 1 && !f.length && (m = this.resolution, h = "", n = -1, k = y()); + e && g && n === b - 1 && !f.length && (l = this.resolution, g = "", n = -1, k = z()); } a: { a = f; f = a.length; - h = a; + g = a; if (f > 1) { b: { f = e; - h = a.length; + g = a.length; e = []; - b = y(); - for (let l = 0, p, t, z, x; l < m; l++) { - for (n = 0; n < h; n++) { - if (z = a[n], l < z.length && (p = z[l])) { - for (g = 0; g < p.length; g++) { - if (t = p[g], (k = b[t]) ? b[t]++ : (k = 0, b[t] = 1), x = e[k] || (e[k] = []), x.push(t), c && k === h - 1 && x.length - d === c) { - h = d ? x.slice(d) : x; + b = z(); + for (let m = 0, p, u, y, x; m < l; m++) { + for (n = 0; n < g; n++) { + if (y = a[n], m < y.length && (p = y[m])) { + for (h = 0; h < p.length; h++) { + if (u = p[h], (k = b[u]) ? b[u]++ : (k = 0, b[u] = 1), x = e[k] || (e[k] = []), x.push(u), c && k === g - 1 && x.length - d === c) { + g = d ? x.slice(d) : x; break b; } } @@ -527,14 +541,14 @@ function M(a, c, b, f, d) { if (f) { if (e.length > 1) { c: { - for (a = [], m = y(), f = e.length, k = f - 1; k >= 0; k--) { + for (a = [], l = z(), f = e.length, k = f - 1; k >= 0; k--) { if (b = (f = e[k]) && f.length) { for (n = 0; n < b; n++) { - if (h = f[n], !m[h]) { - if (m[h] = 1, d) { + if (g = f[n], !l[g]) { + if (l[g] = 1, d) { d--; } else { - if (a.push(h), a.length === c) { + if (a.push(g), a.length === c) { break c; } } @@ -548,8 +562,8 @@ function M(a, c, b, f, d) { } e = a; } else { - if (a < h) { - h = []; + if (a < g) { + g = []; break b; } e = e[a - 1]; @@ -560,13 +574,13 @@ function M(a, c, b, f, d) { } } } - h = e; + g = e; } } else if (f === 1) { c = I.call(null, a[0], c, d); break a; } - c = h; + c = g; } return c; }; @@ -602,24 +616,24 @@ function O(a, c, b) { this.v = f.resolution || 3; this.rtl = d.rtl || a.rtl || !1; } -u = J.prototype; -u.clear = function() { +r = J.prototype; +r.clear = function() { this.map.clear(); this.ctx.clear(); this.reg.clear(); return this; }; -u.append = function(a, c) { +r.append = function(a, c) { return this.add(a, c, !0); }; -u.contain = function(a) { +r.contain = function(a) { return this.reg.has(a); }; -u.update = function(a, c) { +r.update = function(a, c) { const b = this, f = this.remove(a); return f && f.then ? f.then(() => b.add(a, c)) : this.add(a, c); }; -u.cleanup = function() { +r.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } @@ -627,7 +641,7 @@ u.cleanup = function() { this.depth && K(this.ctx); return this; }; -y(); +z(); export default {Index:J, Charset:null, Encoder:F, Document:null, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; export const Index=J;export const Charset=null;export const Encoder=F;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 d751ed7..4cecb69 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -1,28 +1,29 @@ /**! - * FlexSearch.js v0.8.203 (Bundle) + * FlexSearch.js v0.8.205 (Bundle) * Author and Copyright: Thomas Wilkerling * Licence: Apache-2.0 * Hosted by Nextapps GmbH * https://github.com/nextapps-de/flexsearch */ -var u;function v(a,c,b){const f=typeof b,d=typeof a;if(f!=="undefined"){if(d!=="undefined"){if(b){if(d==="function"&&f===d)return function(k){return a(b(k))};c=a.constructor;if(c===b.constructor){if(c===Array)return b.concat(a);if(c===Map){var g=new Map(b);for(var e of a)g.set(e[0],e[1]);return g}if(c===Set){e=new Set(b);for(g of a.values())e.add(g);return e}}}return a}return b}return d==="undefined"?c:a}function y(){return Object.create(null)};const A=/[^\p{L}\p{N}]+/u,B=/(\d{3})/g,C=/(\D)(\d{3})/g,D=/(\d{3})(\D)/g,E=/[\u0300-\u036f]/g;function F(a={}){if(!this||this.constructor!==F)return new F(...arguments);if(arguments.length)for(a=0;a1)return this.addMatcher(a,c);this.mapper||(this.mapper=new Map);this.mapper.set(a,c);this.cache&&G(this);return this};u.addMatcher=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&G(this);return this}; -u.addReplacer=function(a,c){if(typeof a==="string")return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; -u.encode=function(a,c){if(this.cache&&a.length<=this.m)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(G,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=E?a.normalize("NFKD").replace(E,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(C,"$1 $2").replace(D,"$1 $2").replace(B,"$1 "));const b=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let f=[], -d=y(),g,e,k=this.split||this.split===""?a.split(this.split):[a];for(let n=0,h,r;nthis.maxlength)){if(c){if(d[h])continue;d[h]=1}else{if(g===h)continue;g=h}if(b)f.push(h);else if(!this.filter||(typeof this.filter==="function"?this.filter(h):!this.filter.has(h))){if(this.cache&&h.length<=this.o)if(this.l){var m=this.j.get(h);if(m||m===""){m&&f.push(m);continue}}else this.l=setTimeout(G,50,this);if(this.stemmer){this.u||(this.u=new RegExp("(?!^)("+ -this.h+")$"));let w;for(;w!==h&&h.length>2;)w=h,h=h.replace(this.u,q=>this.stemmer.get(q))}if(h&&(this.mapper||this.dedupe&&h.length>1)){m="";for(let w=0,q="",l,p;w1&&(this.s||(this.s=new RegExp("("+this.g+")","g")),h=h.replace(this.s,w=>this.matcher.get(w)));if(h&&this.replacer)for(m=0;h&&mthis.A&&(this.j.clear(),this.o=this.o/1.1|0));if(h){if(h!==r)if(c){if(d[h])continue;d[h]=1}else{if(e===h)continue;e=h}f.push(h)}}}this.finalize&&(f=this.finalize(f)||f);this.cache&&a.length<=this.m&&(this.i.set(a,f),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return f};function G(a){a.l=null;a.i.clear();a.j.clear()};function I(a,c,b){if(!a.length)return a;if(a.length===1)return a=a[0],a=b||a.length>c?a.slice(b,b+c):a;let f=[];for(let d=0,g,e;d=e){b-=e;continue}g=g.slice(b,b+c);e=g.length;b=0}e>c&&(g=g.slice(0,c),e=c);if(!f.length&&e>=c)return g;f.push(g);c-=e;if(!c)break}return f=f.length>1?[].concat.apply([],f):f[0]};y();J.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,d,g;f=0&&d.splice(e,1)}}else K(this.map,a),this.depth&&K(this.ctx,a);c||this.reg.delete(a)}return this}; -function K(a,c){let b=0;var f=typeof c==="undefined";if(a.constructor===Array)for(let d=0,g,e,k;d=0){if(g.length>1)return g.splice(e,1),1;delete a[d];if(b)return 1;k=1}else{if(k)return 1;b++}}}else for(let d of a.entries())f=d[0],K(d[1],c)?b++:a.delete(f);return b};const L={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};J.prototype.add=function(a,c,b,f){if(c&&(a||a===0)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);f=this.depth;c=this.encoder.encode(c,!f);const n=c.length;if(n){const h=y(),r=y(),w=this.resolution;for(let q=0;q2)for(let p=1,t,z,x,H;p2){for(let p=0,t;pp;g--)if(e=l.substring(p,g),!r[e]){t=this.rtl?d-1-p:p;var k=this.score?this.score(c,l,q,e,t):M(w,n,q,d,t);N(this,r,e,k,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(k=d-1;k>0;k--)if(e=l[this.rtl?d-1-k:k]+e,!r[e]){var m=this.score?this.score(c,l,q,e,k):M(w,n,q,d,k);N(this,r,e,m,a,b)}e=""}case "forward":if(d>1){for(k=0;k1&&qe?0:1),n,q,k-1,m-1),t=this.bidirectional&&l>g;N(this,h,t?g:l,p,a,b,t?l:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function N(a,c,b,f,d,g,e){let k=e?a.ctx:a.map,m;if(!c[b]||e&&!(m=c[b])[e])e?(c=m||(c[b]=y()),c[e]=1,(m=k.get(e))?k=m:k.set(e,k=new Map)):c[b]=1,(m=k.get(b))?k=m:k.set(b,k=[]),k=k[f]||(k[f]=[]),g&&k.includes(d)||(k.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(k):a.reg.set(d,[k])))}function M(a,c,b,f,d){return b&&a>1?c+(f||0)<=a?b+(d||0):(a-1)/(c+(f||0))*(b+(d||0))+1|0:0};J.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));var f=[],d=0;if(b){a=b.query||a;c=b.limit||c;d=b.offset||0;var g=b.context;var e=b.suggest;var k=!0;var m=b.resolution}typeof k==="undefined"&&(k=!0);g=this.depth&&g!==!1;a=this.encoder.encode(a,!g);b=a.length;c=c||(k?100:0);if(b===1)return e=d,(d=O(this,a[0],""))&&d.length?I.call(this,d,c,e):[];if(b===2&&g&&!e)return e=d,(d=O(this,a[1],a[0]))&&d.length?I.call(this,d,c,e):[];k=y();var n=0;if(g){var h= -a[0];n=1}m||m===0||(m=h?this.v:this.resolution);for(let l,p;n1)b:{f=e;h=a.length;e=[];b=y();for(let l=0,p,t,z,x;l1)c:for(a=[],m=y(),f=e.length,k=f-1;k>=0;k--){if(b=(f=e[k])&&f.length)for(n=0;nc||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}h=e}else if(f=== -1){c=I.call(null,a[0],c,d);break a}c=h}return c};function O(a,c,b){let f;b&&(f=a.bidirectional&&c>b)&&(f=b,b=c,c=f);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function J(a,c){if(!this||this.constructor!==J)return new J(a);if(a){var b=typeof a==="string"?a:a.preset;b&&(a=Object.assign({},L[b],a))}else a={};b=a.context;const f=b===!0?{depth:1}:b||{},d=a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new F(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&b!=="default"&&b!=="exact"&&b||"strict";this.depth=b==="strict"&&f.depth||0;this.bidirectional=f.bidirectional!==!1;this.fastupdate=!!a.fastupdate;this.score= -a.score||null;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.v=f.resolution||3;this.rtl=d.rtl||a.rtl||!1}u=J.prototype;u.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};u.append=function(a,c){return this.add(a,c,!0)};u.contain=function(a){return this.reg.has(a)};u.update=function(a,c){const b=this,f=this.remove(a);return f&&f.then?f.then(()=>b.add(a,c)):this.add(a,c)}; -u.cleanup=function(){if(!this.fastupdate)return this;K(this.map);this.depth&&K(this.ctx);return this};y();export default {Index:J,Charset:null,Encoder:F,Document:null,Worker:null,Resolver:null,IndexedDB:null,Language:{}}; +(this.h?"|":"")+d;return this};r.addStemmer=function(a,c){this.stemmer||(this.stemmer=new Map);this.stemmer.set(a,c);this.h+=(this.h?"|":"")+a;this.u=null;this.cache&&G(this);return this};r.addFilter=function(a){typeof a==="function"?this.filter=a:(this.filter||(this.filter=new Set),this.filter.add(a));this.cache&&G(this);return this}; +r.addMapper=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length>1)return this.addMatcher(a,c);this.mapper||(this.mapper=new Map);this.mapper.set(a,c);this.cache&&G(this);return this};r.addMatcher=function(a,c){if(typeof a==="object")return this.addReplacer(a,c);if(a.length<2&&(this.dedupe||this.mapper))return this.addMapper(a,c);this.matcher||(this.matcher=new Map);this.matcher.set(a,c);this.g+=(this.g?"|":"")+a;this.s=null;this.cache&&G(this);return this}; +r.addReplacer=function(a,c){if(typeof a==="string")return this.addMatcher(a,c);this.replacer||(this.replacer=[]);this.replacer.push(a,c);this.cache&&G(this);return this}; +r.encode=function(a,c){if(this.cache&&a.length<=this.m)if(this.l){if(this.i.has(a))return this.i.get(a)}else this.l=setTimeout(G,50,this);this.normalize&&(typeof this.normalize==="function"?a=this.normalize(a):a=E?a.normalize("NFKD").replace(E,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&a.length>3&&(a=a.replace(C,"$1 $2").replace(D,"$1 $2").replace(B,"$1 "));const b=!(this.dedupe||this.mapper||this.filter||this.matcher||this.stemmer||this.replacer);let f=[], +d=z(),h,e,k=this.split||this.split===""?a.split(this.split):[a];for(let n=0,g,t;nthis.maxlength)){if(c){if(d[g])continue;d[g]=1}else{if(h===g)continue;h=g}if(b)f.push(g);else if(!this.filter||(typeof this.filter==="function"?this.filter(g):!this.filter.has(g))){if(this.cache&&g.length<=this.o)if(this.l){var l=this.j.get(g);if(l||l===""){l&&f.push(l);continue}}else this.l=setTimeout(G,50,this);if(this.stemmer){this.u||(this.u=new RegExp("(?!^)("+ +this.h+")$"));let w;for(;w!==g&&g.length>2;)w=g,g=g.replace(this.u,q=>this.stemmer.get(q))}if(g&&(this.mapper||this.dedupe&&g.length>1)){l="";for(let w=0,q="",m,p;w1&&(this.s||(this.s=new RegExp("("+this.g+")","g")),g=g.replace(this.s,w=>this.matcher.get(w)));if(g&&this.replacer)for(l=0;g&&lthis.A&&(this.j.clear(),this.o=this.o/1.1|0));if(g){if(g!==t)if(c){if(d[g])continue;d[g]=1}else{if(e===g)continue;e=g}f.push(g)}}}this.finalize&&(f=this.finalize(f)||f);this.cache&&a.length<=this.m&&(this.i.set(a,f),this.i.size>this.A&&(this.i.clear(),this.m=this.m/1.1|0));return f};function G(a){a.l=null;a.i.clear();a.j.clear()};function I(a,c,b){if(!a.length)return a;if(a.length===1)return a=a[0],a=b||a.length>c?a.slice(b,b+c):a;let f=[];for(let d=0,h,e;d=e){b-=e;continue}h=h.slice(b,b+c);e=h.length;b=0}e>c&&(h=h.slice(0,c),e=c);if(!f.length&&e>=c)return h;f.push(h);c-=e;if(!c)break}return f=f.length>1?[].concat.apply([],f):f[0]};z();J.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let f=0,d,h;f=0&&d.splice(e,1)}}else K(this.map,a),this.depth&&K(this.ctx,a);c||this.reg.delete(a)}return this}; +function K(a,c){let b=0;var f=typeof c==="undefined";if(a.constructor===Array)for(let d=0,h,e,k;d=0){if(h.length>1)return h.splice(e,1),1;delete a[d];if(b)return 1;k=1}else{if(k)return 1;b++}}}else for(let d of a.entries())f=d[0],K(d[1],c)?b++:a.delete(f);return b};const L={memory:{resolution:1},performance:{resolution:3,fastupdate:!0,context:{depth:1,resolution:1}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:3}}};J.prototype.add=function(a,c,b,f){if(c&&(a||a===0)){if(!f&&!b&&this.reg.has(a))return this.update(a,c);f=this.depth;c=this.encoder.encode(c,!f);const n=c.length;if(n){const g=z(),t=z(),w=this.resolution;for(let q=0;q2){for(let p=1,u,y,x,H;p2){for(let p=0,u;pp;h--){e=m.substring(p,h);u=this.rtl?d-1-p:p;var k=this.score?this.score(c,m,q,e,u):M(w,n,q,d,u);N(this,t,e,k,a,b)}break}case "bidirectional":case "reverse":if(d>1){for(k=d-1;k>0;k--){e=m[this.rtl?d-1-k:k]+e;var l=this.score?this.score(c,m,q,e,k):M(w,n,q,d,k);N(this,t,e,l,a,b)}e=""}case "forward":if(d>1){for(k=0;k1&&qe;const p=this.score?this.score(c,e,q,m,k-1):M(d+(n/2>d?0:1),n,q,h-1,k-1);N(this,g,l?e:m,p,a,b,l?m:e)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function N(a,c,b,f,d,h,e){let k,l;if(!(k=c[b])||e&&!k[e]){e?(c=k||(c[b]=z()),c[e]=1,l=a.ctx,(k=l.get(e))?l=k:l.set(e,l=new Map)):(l=a.map,c[b]=1);(k=l.get(b))?l=k:l.set(b,l=k=[]);if(h)for(let n=0,g;n1?c+(f||0)<=a?b+(d||0):(a-1)/(c+(f||0))*(b+(d||0))+1|0:0};J.prototype.search=function(a,c,b){b||(c||typeof a!=="object"?typeof c==="object"&&(b=c,c=0):(b=a,a=""));var f=[],d=0;if(b){a=b.query||a;c=b.limit||c;d=b.offset||0;var h=b.context;var e=b.suggest;var k=!0;var l=b.resolution}typeof k==="undefined"&&(k=!0);h=this.depth&&h!==!1;a=this.encoder.encode(a,!h);b=a.length;c=c||(k?100:0);if(b===1)return e=d,(d=O(this,a[0],""))&&d.length?I.call(this,d,c,e):[];if(b===2&&h&&!e)return e=d,(d=O(this,a[1],a[0]))&&d.length?I.call(this,d,c,e):[];k=z();var n=0;if(h){var g= +a[0];n=1}l||l===0||(l=g?this.v:this.resolution);for(let m,p;n1)b:{f=e;g=a.length;e=[];b=z();for(let m=0,p,u,y,x;m1)c:for(a=[],l=z(),f=e.length,k=f-1;k>=0;k--){if(b=(f=e[k])&&f.length)for(n=0;nc||d?e.slice(d,c+d):e;e=a}else{if(ac||d)e=e.slice(d,c+d)}g=e}else if(f=== +1){c=I.call(null,a[0],c,d);break a}c=g}return c};function O(a,c,b){let f;b&&(f=a.bidirectional&&c>b)&&(f=b,b=c,c=f);a=b?(a=a.ctx.get(b))&&a.get(c):a.map.get(c);return a};function J(a,c){if(!this||this.constructor!==J)return new J(a);if(a){var b=typeof a==="string"?a:a.preset;b&&(a=Object.assign({},L[b],a))}else a={};b=a.context;const f=b===!0?{depth:1}:b||{},d=a.encode||a.encoder||{};this.encoder=d.encode?d:typeof d==="object"?new F(d):{encode:d};this.resolution=a.resolution||9;this.tokenize=b=(b=a.tokenize)&&b!=="default"&&b!=="exact"&&b||"strict";this.depth=b==="strict"&&f.depth||0;this.bidirectional=f.bidirectional!==!1;this.fastupdate=!!a.fastupdate;this.score= +a.score||null;this.map=new Map;this.ctx=new Map;this.reg=c||(this.fastupdate?new Map:new Set);this.v=f.resolution||3;this.rtl=d.rtl||a.rtl||!1}r=J.prototype;r.clear=function(){this.map.clear();this.ctx.clear();this.reg.clear();return this};r.append=function(a,c){return this.add(a,c,!0)};r.contain=function(a){return this.reg.has(a)};r.update=function(a,c){const b=this,f=this.remove(a);return f&&f.then?f.then(()=>b.add(a,c)):this.add(a,c)}; +r.cleanup=function(){if(!this.fastupdate)return this;K(this.map);this.depth&&K(this.ctx);return this};z();export default {Index:J,Charset:null,Encoder:F,Document:null,Worker:null,Resolver:null,IndexedDB:null,Language:{}}; export const Index=J;export const Charset=null;export const Encoder=F;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/module-debug/db/clickhouse/index.js b/dist/module-debug/db/clickhouse/index.js index c494dac..ac8ac61 100644 --- a/dist/module-debug/db/clickhouse/index.js +++ b/dist/module-debug/db/clickhouse/index.js @@ -411,33 +411,24 @@ ClickhouseDB.prototype.transaction = function (task) { return task.call(this); }; -ClickhouseDB.prototype.commit = async function (flexsearch, _replace, _append) { +ClickhouseDB.prototype.commit = async function (flexsearch) { + let tasks = flexsearch.commit_task, + removals = []; - if (_replace) { - await this.clear(); + flexsearch.commit_task = []; - flexsearch.commit_task = []; - } else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for (let i = 0, task; i < tasks.length; i++) { - task = tasks[i]; - - if (task.clear) { - await this.clear(); - _replace = !0; - break; - } else { - tasks[i] = task.del; - } - } - if (!_replace) { - if (!_append) { - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && (await this.remove(tasks)); - } + for (let i = 0, task; i < tasks.length; i++) { + /** @dict */ + task = tasks[i]; + if (task.del) { + removals.push(task.del); + } else if (task.ins) {} } + + if (removals.length) { + await this.remove(removals); + } + if (!flexsearch.reg.size) { return; } diff --git a/dist/module-debug/db/indexeddb/index.js b/dist/module-debug/db/indexeddb/index.js index f688473..e5fc674 100644 --- a/dist/module-debug/db/indexeddb/index.js +++ b/dist/module-debug/db/indexeddb/index.js @@ -263,35 +263,24 @@ IdxDB.prototype.transaction = function (ref, modifier, task) { }); }; -IdxDB.prototype.commit = async function (flexsearch, _replace, _append) { +IdxDB.prototype.commit = async function (flexsearch) { + let tasks = flexsearch.commit_task, + removals = []; - if (_replace) { - await this.clear(); + flexsearch.commit_task = []; - flexsearch.commit_task = []; - } else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for (let i = 0, task; i < tasks.length; i++) { - /** @dict */ - task = tasks[i]; - - if (task.clear) { - await this.clear(); - _replace = !0; - break; - } else { - tasks[i] = task.del; - } - } - if (!_replace) { - if (!_append) { - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && (await this.remove(tasks)); + for (let i = 0, task; i < tasks.length; i++) { + /** @dict */ + task = tasks[i]; + if (task.del) { + removals.push(task.del); } } + if (removals.length) { + await this.remove(removals); + } + if (!flexsearch.reg.size) { return; } @@ -304,11 +293,6 @@ IdxDB.prototype.commit = async function (flexsearch, _replace, _append) { if (!value.length) continue; - if (_replace) { - store.put(value, key); - continue; - } - store.get(key).onsuccess = function () { let result = this.result, changed; @@ -353,11 +337,6 @@ IdxDB.prototype.commit = async function (flexsearch, _replace, _append) { if (!value.length) continue; - if (_replace) { - store.put(value, ctx_key + ":" + key); - continue; - } - store.get(ctx_key + ":" + key).onsuccess = function () { let result = this.result, changed; diff --git a/dist/module-debug/db/mongodb/index.js b/dist/module-debug/db/mongodb/index.js index ec05a19..1dccfa2 100644 --- a/dist/module-debug/db/mongodb/index.js +++ b/dist/module-debug/db/mongodb/index.js @@ -441,32 +441,22 @@ MongoDB.prototype.transaction = function (task) { return task.call(this); }; -MongoDB.prototype.commit = async function (flexsearch, _replace, _append) { +MongoDB.prototype.commit = async function (flexsearch) { + let tasks = flexsearch.commit_task, + removals = []; - if (_replace) { - await this.clear(); + flexsearch.commit_task = []; - flexsearch.commit_task = []; - } else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for (let i = 0, task; i < tasks.length; i++) { - task = tasks[i]; + for (let i = 0, task; i < tasks.length; i++) { + /** @dict */ + task = tasks[i]; + if (task.del) { + removals.push(task.del); + } else if (task.ins) {} + } - if (task.clear) { - await this.clear(); - _replace = !0; - break; - } else { - tasks[i] = task.del; - } - } - if (!_replace) { - if (!_append) { - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && (await this.remove(tasks)); - } + if (removals.length) { + await this.remove(removals); } if (!flexsearch.reg.size) { diff --git a/dist/module-debug/db/postgres/index.js b/dist/module-debug/db/postgres/index.js index 4582514..a6c8b51 100644 --- a/dist/module-debug/db/postgres/index.js +++ b/dist/module-debug/db/postgres/index.js @@ -418,32 +418,22 @@ PostgresDB.prototype.transaction = function (task) { }); }; -PostgresDB.prototype.commit = async function (flexsearch, _replace, _append) { +PostgresDB.prototype.commit = async function (flexsearch) { + let tasks = flexsearch.commit_task, + removals = []; - if (_replace) { - await this.clear(); + flexsearch.commit_task = []; - flexsearch.commit_task = []; - } else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for (let i = 0, task; i < tasks.length; i++) { - task = tasks[i]; + for (let i = 0, task; i < tasks.length; i++) { + /** @dict */ + task = tasks[i]; + if (task.del) { + removals.push(task.del); + } else if (task.ins) {} + } - if (task.clear) { - await this.clear(); - _replace = !0; - break; - } else { - tasks[i] = task.del; - } - } - if (!_replace) { - if (!_append) { - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && (await this.remove(tasks)); - } + if (removals.length) { + await this.remove(removals); } if (!flexsearch.reg.size) { diff --git a/dist/module-debug/db/redis/index.js b/dist/module-debug/db/redis/index.js index b700707..cee54fc 100644 --- a/dist/module-debug/db/redis/index.js +++ b/dist/module-debug/db/redis/index.js @@ -257,32 +257,22 @@ RedisDB.prototype.transaction = function (task, callback) { }); }; -RedisDB.prototype.commit = async function (flexsearch, _replace, _append) { +RedisDB.prototype.commit = async function (flexsearch) { + let tasks = flexsearch.commit_task, + removals = []; - if (_replace) { - await this.clear(); + flexsearch.commit_task = []; - flexsearch.commit_task = []; - } else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for (let i = 0, task; i < tasks.length; i++) { - task = tasks[i]; + for (let i = 0, task; i < tasks.length; i++) { + /** @dict */ + task = tasks[i]; + if (task.del) { + removals.push(task.del); + } else if (task.ins) {} + } - if (task.clear) { - await this.clear(); - _replace = !0; - break; - } else { - tasks[i] = "" + task.del; - } - } - if (!_replace) { - if (!_append) { - tasks = tasks.concat(toArray(flexsearch.reg, !0)); - } - tasks.length && (await this.remove(tasks)); - } + if (removals.length) { + await this.remove(removals); } if (!flexsearch.reg.size) { diff --git a/dist/module-debug/db/sqlite/index.js b/dist/module-debug/db/sqlite/index.js index 702a302..007ef97 100644 --- a/dist/module-debug/db/sqlite/index.js +++ b/dist/module-debug/db/sqlite/index.js @@ -250,6 +250,7 @@ SqliteDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = !0 params = ctx ? [ctx, key] : [key], table = "main." + (ctx ? "ctx" : "map") + this.field; + if (tags) { for (let i = 0; i < tags.length; i += 2) { stmt += ` AND ${table}.id IN (SELECT id FROM main.tag_${sanitize(tags[i])} WHERE tag = ?)`; @@ -293,6 +294,7 @@ SqliteDB.prototype.get = function (key, ctx, limit = 0, offset = 0, resolve = !0 params }); } + return result.then(function (rows) { return create_result(rows, resolve, enrich); }); @@ -316,15 +318,18 @@ SqliteDB.prototype.tag = function (tag, limit = 0, offset = 0, enrich = !1) { params: [tag] }); + enrich || promise.then(function (rows) { return create_result(rows, !0, !1); }); + return promise; }; function build_params(length, single_param) { let stmt = single_param ? ",(?)" : ",?"; + for (let i = 1; i < length;) { if (i <= length - i) { stmt += stmt; @@ -334,6 +339,7 @@ function build_params(length, single_param) { break; } } + return stmt.substring(1); } @@ -346,12 +352,11 @@ SqliteDB.prototype.enrich = function (ids) { } for (let count = 0; count < ids.length;) { + const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids, + stmt = build_params(chunk.length); - const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids; count += chunk.length; - let stmt = build_params(chunk.length); - promises.push(this.promisfy({ method: "all", stmt: `SELECT id, doc FROM main.reg WHERE id IN (${stmt})`, @@ -512,34 +517,26 @@ SqliteDB.prototype.transaction = async function (task, callback) { }); }; -SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) { +SqliteDB.prototype.commit = async function (flexsearch) { + let tasks = flexsearch.commit_task, + removals = [], + inserts = []; - if (_replace) { - await this.clear(); + flexsearch.commit_task = []; - flexsearch.commit_task = []; - } else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for (let i = 0, task; i < tasks.length; i++) { - task = tasks[i]; - - if (task.clear) { - await this.clear(); - _replace = !0; - break; - } else { - tasks[i] = task.del; - } - } - if (!_replace) { - if (!_append) { - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && (await this.remove(tasks)); + for (let i = 0, task; i < tasks.length; i++) { + task = tasks[i]; + if ("undefined" != typeof task.del) { + removals.push(task.del); + } else if ("undefined" != typeof task.ins) { + inserts.push(task.ins); } } + if (removals.length) { + await this.remove(removals); + } + if (!flexsearch.reg.size) { return; } @@ -613,13 +610,13 @@ SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) { stmt += (stmt ? "," : "") + "(?,?)"; chunk.push(id, "object" == typeof doc ? JSON.stringify(doc) : doc || null); if (chunk.length + 2 > MAXIMUM_QUERY_VARS) { - this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); stmt = ""; chunk = []; } } if (chunk.length) { - this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); } } else if (!flexsearch.bypass) { let ids = toArray(flexsearch.reg); @@ -627,7 +624,7 @@ SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) { const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids; count += chunk.length; const stmt = build_params(chunk.length, !0); - this.db.run("INSERT INTO main.reg (id) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); } } @@ -656,6 +653,10 @@ SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) { } }); + if (inserts.length) { + await this.cleanup(); + } + flexsearch.map.clear(); flexsearch.ctx.clear(); flexsearch.tag && flexsearch.tag.clear(); @@ -688,6 +689,13 @@ SqliteDB.prototype.remove = function (ids) { }); }; +SqliteDB.prototype.cleanup = function () { + return this.transaction(function () { + this.db.run("DELETE FROM main.map" + this.field + " WHERE ROWID IN (SELECT ROWID FROM (SELECT ROWID, row_number() OVER dupes AS count FROM main.map" + this.field + " _t WINDOW dupes AS (PARTITION BY id, key ORDER BY res) ) WHERE count > 1)"); + this.db.run("DELETE FROM main.ctx" + this.field + " WHERE ROWID IN (SELECT ROWID FROM (SELECT ROWID, row_number() OVER dupes AS count FROM main.ctx" + this.field + " _t WINDOW dupes AS (PARTITION BY id, ctx, key ORDER BY res) ) WHERE count > 1)"); + }); +}; + SqliteDB.prototype.promisfy = function (opt) { const db = this.db; return new Promise(function (resolve, reject) { diff --git a/dist/module-debug/document.js b/dist/module-debug/document.js index 5a439c3..79d759c 100644 --- a/dist/module-debug/document.js +++ b/dist/module-debug/document.js @@ -199,11 +199,11 @@ Document.prototype.mount = function (db) { }); }; -Document.prototype.commit = async function (replace, append) { +Document.prototype.commit = async function () { const promises = []; for (const index of this.index.values()) { - promises.push(index.commit(replace, append)); + promises.push(index.commit()); } await Promise.all(promises); this.reg.clear(); diff --git a/dist/module-debug/document/search.js b/dist/module-debug/document/search.js index 0cdc221..ce30200 100644 --- a/dist/module-debug/document/search.js +++ b/dist/module-debug/document/search.js @@ -264,7 +264,9 @@ Document.prototype.search = function (query, limit, options, _promises) { res = cache ? index.searchCache(query, limit, opt) : index.search(query, limit, opt); - opt_enrich && (opt.enrich = opt_enrich); + if (opt_enrich) { + opt.enrich = opt_enrich; + } if (promises) { promises[i] = res; diff --git a/dist/module-debug/index.js b/dist/module-debug/index.js index 8524e54..1f4892c 100644 --- a/dist/module-debug/index.js +++ b/dist/module-debug/index.js @@ -96,12 +96,12 @@ Index.prototype.mount = function (db) { } return db.mount(this); }; -Index.prototype.commit = function (replace, append) { +Index.prototype.commit = function () { if (this.commit_timer) { clearTimeout(this.commit_timer); this.commit_timer = null; } - return this.db.commit(this, replace, append); + return this.db.commit(this); }; Index.prototype.destroy = function () { if (this.commit_timer) { @@ -113,15 +113,12 @@ Index.prototype.destroy = function () { /** * @param {!Index} self - * @param {boolean=} replace - * @param {boolean=} append */ - -export function autoCommit(self, replace, append) { +export function autoCommit(self) { if (!self.commit_timer) { self.commit_timer = setTimeout(function () { self.commit_timer = null; - self.db.commit(self, replace, append); + self.db.commit(self); }, 1); } } diff --git a/dist/module-debug/index/add.js b/dist/module-debug/index/add.js index d0602be..ca0b70f 100644 --- a/dist/module-debug/index/add.js +++ b/dist/module-debug/index/add.js @@ -2,7 +2,7 @@ import { create_object } from "../common.js"; import Index, { autoCommit } from "../index.js"; import default_compress from "../compress.js"; -import { KeystoreArray } from "../keystore.js"; +import { KeystoreArray, KeystoreMap } from "../keystore.js"; /** * @param {!number|string} id @@ -10,7 +10,6 @@ import { KeystoreArray } from "../keystore.js"; * @param {boolean=} _append * @param {boolean=} _skip_update */ - Index.prototype.add = function (id, content, _append, _skip_update) { if (content && (id || 0 === id)) { @@ -24,28 +23,28 @@ Index.prototype.add = function (id, content, _append, _skip_update) { const depth = this.depth; content = this.encoder.encode(content, !depth); - const word_length = content.length; + const term_count = content.length; - if (word_length) { + if (term_count) { const dupes_ctx = create_object(), dupes = create_object(), resolution = this.resolution; - for (let i = 0; i < word_length; i++) { - let term = content[this.rtl ? word_length - 1 - i : i], + for (let i = 0; i < term_count; i++) { + let term = content[this.rtl ? term_count - 1 - i : i], term_length = term.length; if (term_length && (depth || !dupes[term])) { - let score = this.score ? this.score(content, term, i, null, 0) : get_score(resolution, word_length, i), + let score = this.score ? this.score(content, term, i, null, 0) : get_score(resolution, term_count, i), token = ""; switch (this.tokenize) { case "tolerant": - this.push_index(dupes, term, score, id, _append); + this._push_index(dupes, term, score, id, _append); if (2 < term_length) { for (let x = 1, char_a, char_b, prt_1, prt_2; x < term_length - 1; x++) { char_a = term.charAt(x); @@ -54,11 +53,13 @@ Index.prototype.add = function (id, content, _append, _skip_update) { prt_2 = term.substring(x + 2); token = prt_1 + char_a + prt_2; - dupes[token] || this.push_index(dupes, token, score, id, _append); + this._push_index(dupes, token, score, id, _append); token = prt_1 + prt_2; - dupes[token] || this.push_index(dupes, token, score, id, _append); + this._push_index(dupes, token, score, id, _append); } + + this._push_index(dupes, term.substring(0, term.length - 1), score, id, _append); } break; @@ -67,11 +68,9 @@ Index.prototype.add = function (id, content, _append, _skip_update) { for (let x = 0, _x; x < term_length; x++) { for (let y = term_length; y > x; y--) { token = term.substring(x, y); - if (!dupes[token]) { - _x = this.rtl ? term_length - 1 - x : x; - const partial_score = this.score ? this.score(content, term, i, token, _x) : get_score(resolution, word_length, i, term_length, _x); - this.push_index(dupes, token, partial_score, id, _append); - } + _x = this.rtl ? term_length - 1 - x : x; + const partial_score = this.score ? this.score(content, term, i, token, _x) : get_score(resolution, term_count, i, term_length, _x); + this._push_index(dupes, token, partial_score, id, _append); } } break; @@ -83,10 +82,8 @@ Index.prototype.add = function (id, content, _append, _skip_update) { if (1 < term_length) { for (let x = term_length - 1; 0 < x; x--) { token = term[this.rtl ? term_length - 1 - x : x] + token; - if (!dupes[token]) { - const partial_score = this.score ? this.score(content, term, i, token, x) : get_score(resolution, word_length, i, term_length, x); - this.push_index(dupes, token, partial_score, id, _append); - } + const partial_score = this.score ? this.score(content, term, i, token, x) : get_score(resolution, term_count, i, term_length, x); + this._push_index(dupes, token, partial_score, id, _append); } token = ""; } @@ -95,38 +92,28 @@ Index.prototype.add = function (id, content, _append, _skip_update) { if (1 < term_length) { for (let x = 0; x < term_length; x++) { token += term[this.rtl ? term_length - 1 - x : x]; - dupes[token] || this.push_index(dupes, token, score, id, _append); + this._push_index(dupes, token, score, id, _append); } break; } default: - this.push_index(dupes, term, score, id, _append); + this._push_index(dupes, term, score, id, _append); - if (depth) { - - if (1 < word_length && i < word_length - 1) { - const dupes_inner = create_object(), - resolution = this.resolution_ctx, - keyword = term, - size = Math.min(depth + 1, this.rtl ? i + 1 : word_length - i); + if (depth && 1 < term_count && i < term_count - 1) { + const resolution = this.resolution_ctx, + keyword = term, + size = Math.min(depth + 1, this.rtl ? i + 1 : term_count - i); - dupes_inner[keyword] = 1; + for (let x = 1; x < size; x++) { - for (let x = 1; x < size; x++) { + term = content[this.rtl ? term_count - 1 - i - x : i + x]; - term = content[this.rtl ? word_length - 1 - i - x : i + x]; + const swap = this.bidirectional && term > keyword, + context_score = this.score ? this.score(content, keyword, i, term, x - 1) : get_score(resolution + (term_count / 2 > resolution ? 0 : 1), term_count, i, size - 1, x - 1); - if (term && !dupes_inner[term]) { - - dupes_inner[term] = 1; - const context_score = this.score ? this.score(content, keyword, i, term, x - 1) : get_score(resolution + (word_length / 2 > resolution ? 0 : 1), word_length, i, size - 1, x - 1), - swap = this.bidirectional && term > keyword; - - this.push_index(dupes_ctx, swap ? keyword : term, context_score, id, _append, swap ? term : keyword); - } - } + this._push_index(dupes_ctx, swap ? keyword : term, context_score, id, _append, swap ? term : keyword); } } } @@ -134,14 +121,11 @@ Index.prototype.add = function (id, content, _append, _skip_update) { } this.fastupdate || this.reg.add(id); - } else { - content = ""; } } if (this.db) { - - content || this.commit_task.push({ del: id }); + this.commit_task.push(_append ? { ins: id } : { del: id }); this.commit_auto && autoCommit(this); } @@ -157,27 +141,27 @@ Index.prototype.add = function (id, content, _append, _skip_update) { * @param {boolean=} append * @param {string=} keyword */ +Index.prototype._push_index = function (dupes, term, score, id, append, keyword) { -Index.prototype.push_index = function (dupes, term, score, id, append, keyword) { - let arr = keyword ? this.ctx : this.map, - tmp; + let res, arr; - - if (!dupes[term] || keyword && !(tmp = dupes[term])[keyword]) { + if (!(res = dupes[term]) || keyword && !res[keyword]) { if (keyword) { - dupes = tmp || (dupes[term] = create_object()); + dupes = res || (dupes[term] = create_object()); dupes[keyword] = 1; if (this.compress) { keyword = default_compress(keyword); } - tmp = arr.get(keyword); - tmp ? arr = tmp : arr.set(keyword, arr = new Map()); + arr = this.ctx; + res = arr.get(keyword); + res ? arr = res : arr.set(keyword, arr = this.keystore ? new KeystoreMap(this.keystore) : new Map()); } else { + arr = this.map; dupes[term] = 1; } @@ -185,31 +169,48 @@ Index.prototype.push_index = function (dupes, term, score, id, append, keyword) term = default_compress(term); } - tmp = arr.get(term); - tmp ? arr = tmp : arr.set(term, arr = tmp = []); + res = arr.get(term); + res ? arr = res : arr.set(term, arr = res = []); - arr = arr[score] || (arr[score] = []); + if (append) { + for (let i = 0, arr; i < res.length; i++) { + arr = res[i]; + if (arr && arr.includes(id)) { + if (i <= score) { - if (!append || !arr.includes(id)) { - if (2147483647 === arr.length) { - const keystore = new KeystoreArray(arr); - if (this.fastupdate) { - for (let value of this.reg.values()) { - if (value.includes(arr)) { - value[value.indexOf(arr)] = keystore; + return; + } else { + + arr.splice(arr.indexOf(id), 1); + if (this.fastupdate) { + const tmp = this.reg.get(id); + tmp && tmp.splice(tmp.indexOf(arr), 1); } } + break; } - tmp[score] = arr = keystore; } + } + arr = arr[score] || (arr[score] = []); + arr.push(id); - arr.push(id); - + if (2147483647 === arr.length) { + const keystore = new KeystoreArray(arr); if (this.fastupdate) { - const tmp = this.reg.get(id); - tmp ? tmp.push(arr) : this.reg.set(id, [arr]); + for (let value of this.reg.values()) { + if (value.includes(arr)) { + value[value.indexOf(arr)] = keystore; + } + } } + res[score] = arr = keystore; + } + + + if (this.fastupdate) { + const tmp = this.reg.get(id); + tmp ? tmp.push(arr) : this.reg.set(id, [arr]); } } }; @@ -222,7 +223,6 @@ Index.prototype.push_index = function (dupes, term, score, id, append, keyword) * @param {number=} x * @returns {number} */ - function get_score(resolution, length, i, term_length, x) { return i && 1 < resolution ? length + (term_length || 0) <= resolution ? i + (x || 0) : 0 | (resolution - 1) / (length + (term_length || 0)) * (i + (x || 0)) + 1 : 0; diff --git a/dist/module-debug/index/search.js b/dist/module-debug/index/search.js index 5fb6c4e..b9b2f7e 100644 --- a/dist/module-debug/index/search.js +++ b/dist/module-debug/index/search.js @@ -114,7 +114,7 @@ Index.prototype.search = function (query, limit, options) { if (term && !dupes[term]) { dupes[term] = 1; - arr = await self.get_array(term, keyword, 0, 0, !1, !1); + arr = await self._get_array(term, keyword, 0, 0, !1, !1); arr = add_result(arr, /** @type {Array} */result, suggest, resolution); if (arr) { @@ -152,7 +152,7 @@ Index.prototype.search = function (query, limit, options) { if (term && !dupes[term]) { dupes[term] = 1; - arr = this.get_array(term, keyword, 0, 0, !1, !1); + arr = this._get_array(term, keyword, 0, 0, !1, !1); arr = add_result(arr, /** @type {Array} */result, suggest, resolution); if (arr) { @@ -227,7 +227,7 @@ function return_result(result, resolution, limit, offset, suggest, boost, resolv function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { - const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag); + const result = this._get_array(term, keyword, limit, offset, resolve, enrich, tag); if (this.db) { return result.then(function (result) { @@ -292,7 +292,7 @@ function add_result(arr, result, suggest, resolution) { * Promise * } */ -Index.prototype.get_array = function (term, keyword, limit, offset, resolve, enrich, tag) { +Index.prototype._get_array = function (term, keyword, limit, offset, resolve, enrich, tag) { let arr, swap; diff --git a/dist/module-debug/resolve/handler.js b/dist/module-debug/resolve/handler.js index c1bd90e..ae53b3b 100644 --- a/dist/module-debug/resolve/handler.js +++ b/dist/module-debug/resolve/handler.js @@ -70,11 +70,12 @@ Resolver.prototype.handler = function (method, fn, args) { offset = query.offset || 0; suggest = query.suggest; resolve = query.resolve; - highlight = resolve && query.highlight; + highlight = query.highlight || this.highlight; enrich = (highlight || query.enrich) && resolve; let opt_queue = query.queue, opt_async = query.async || opt_queue, - index = query.index; + index = query.index, + query_value = query.query; if (index) { @@ -83,7 +84,7 @@ Resolver.prototype.handler = function (method, fn, args) { index = this.index; } - if (query.query || query.tag) { + if (query_value || query.tag) { if (!index) { throw new Error("Resolver can't apply because the corresponding Index was never specified"); } @@ -91,9 +92,10 @@ Resolver.prototype.handler = function (method, fn, args) { const field = query.field || query.pluck; if (field) { - if (query.query) { - this.query = query.query; + if (query_value && (!this.query || highlight)) { + this.query = query_value; this.field = field; + this.highlight = highlight; } if (!index.index) { @@ -144,9 +146,7 @@ Resolver.prototype.handler = function (method, fn, args) { } else { query.resolve = !1; query.index = null; - result = opt_async ? index.searchAsync(query) : index.search(query); - query.resolve = resolve; query.index = index; } diff --git a/dist/module-debug/resolver.js b/dist/module-debug/resolver.js index 8dde904..9919ddb 100644 --- a/dist/module-debug/resolver.js +++ b/dist/module-debug/resolver.js @@ -27,6 +27,7 @@ export default function Resolver(result, index) { promises, query, field, + highlight, _await, _return; @@ -36,6 +37,7 @@ export default function Resolver(result, index) { boost = options.boost || 0; if (query = options.query) { field = options.field || options.pluck; + highlight = options.highlight; const resolve = options.resolve, async = options.async || options.queue; @@ -76,6 +78,8 @@ export default function Resolver(result, index) { /** @type {Function} */ this.return = _return || null; + /** @type {HighlightOptions|null} */ + this.highlight = /** @type {HighlightOptions|null} */highlight || null; /** @type {string} */ this.query = query || ""; /** @type {string} */ @@ -89,8 +93,7 @@ Resolver.prototype.limit = function (limit) { if (this.await) { const self = this; this.promises.push(function () { - self.limit(limit); - return self.result; + return self.limit(limit).result; }); } else { if (this.result.length) { @@ -121,8 +124,7 @@ Resolver.prototype.offset = function (offset) { if (this.await) { const self = this; this.promises.push(function () { - self.offset(offset); - return self.result; + return self.offset(offset).result; }); } else { if (this.result.length) { @@ -151,8 +153,7 @@ Resolver.prototype.boost = function (boost) { if (this.await) { const self = this; this.promises.push(function () { - self.boost(boost); - return self.result; + return self.boost(boost).result; }); } else { this.boostval += boost; @@ -215,12 +216,12 @@ Resolver.prototype.resolve = function (limit, offset, enrich, highlight, _resolv if (result.length) { if ("object" == typeof limit) { - highlight = limit.highlight; + highlight = limit.highlight || this.highlight; enrich = !!highlight || limit.enrich; offset = limit.offset; limit = limit.limit; } else { - highlight = highlight; + highlight = highlight || this.highlight; enrich = !!highlight || enrich; } result = _resolved ? enrich ? apply_enrich.call( @@ -241,7 +242,7 @@ Resolver.prototype.finalize = function (result, highlight) { } if (highlight && !this.query) { - console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); + console.warn('There was no query specified for highlighting. Please specify a query within the highlight resolver stage like { query: "...", highlight: ... }.'); } if (highlight && result.length && this.query) { @@ -251,6 +252,7 @@ Resolver.prototype.finalize = function (result, highlight) { const fn = this.return; this.index = this.result = this.promises = this.await = this.return = null; + this.highlight = null; this.query = this.field = ""; diff --git a/dist/module-min/db/clickhouse/index.js b/dist/module-min/db/clickhouse/index.js index 480be84..1fb11e5 100644 --- a/dist/module-min/db/clickhouse/index.js +++ b/dist/module-min/db/clickhouse/index.js @@ -115,7 +115,7 @@ import{ClickHouse}from"clickhouse";import StorageInterface from"../interface.js" ORDER BY ${e?"count DESC, res":"res"} ${c?"LIMIT "+c:""} ${d?"OFFSET "+d:""} - `,{params:j}).toPromise()}return i.then(function(a){return create_result(a,f,g)})},ClickhouseDB.prototype.info=function(){},ClickhouseDB.prototype.transaction=function(a){return a.call(this)},ClickhouseDB.prototype.commit=async function(a,b,c){if(b)await this.clear(),a.commit_task=[];else{let d=a.commit_task;a.commit_task=[];for(let a,c=0;c=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b{a.onsuccess=a.oncomplete=function(){b&&b(this.result),b=null,c(this.result)},a.onerror=a.onblocked=d,a=null})} \ No newline at end of file +const VERSION=1,IndexedDB="undefined"!=typeof window&&(window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB),IDBTransaction="undefined"!=typeof window&&(window.IDBTransaction||window.webkitIDBTransaction||window.msIDBTransaction),IDBKeyRange="undefined"!=typeof window&&(window.IDBKeyRange||window.webkitIDBKeyRange||window.msIDBKeyRange),fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{create_object,toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}const Index=create_object();export default function IdxDB(a,b={}){return this&&this.constructor===IdxDB?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?":"+sanitize(a):""),this.field=b.field?sanitize(b.field):"",this.type=b.type,this.support_tag_search=!1,this.fastupdate=!1,this.db=null,this.trx={}):new IdxDB(a,b)}IdxDB.prototype.mount=function(a){return a.index?a.mount(this):(a.db=this,this.open())},IdxDB.prototype.open=function(){if(this.db)return this.db;let a=this;navigator.storage&&navigator.storage.persist(),Index[a.id]||(Index[a.id]=[]),Index[a.id].push(a.field);const b=IndexedDB.open(a.id,VERSION);return b.onupgradeneeded=function(){const b=a.db=this.result;for(let c,d=0;d=e.length){d-=e.length;continue}const a=c?d+Math.min(e.length-d,c):e.length;for(let c=d;c=a.length)return[];if(!b&&!c)return a;const e=a.slice(c,c+b);return d?h.enrich(e):e})},IdxDB.prototype.enrich=function(a){"object"!=typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly"),c=b.objectStore("reg"),d=[];for(let b=0;b{a.onsuccess=a.oncomplete=function(){b&&b(this.result),b=null,c(this.result)},a.onerror=a.onblocked=d,a=null})} \ No newline at end of file diff --git a/dist/module-min/db/mongodb/index.js b/dist/module-min/db/mongodb/index.js index 1bb8b30..bef108c 100644 --- a/dist/module-min/db/mongodb/index.js +++ b/dist/module-min/db/mongodb/index.js @@ -1 +1 @@ -import{MongoClient}from"mongodb";const defaults={host:"localhost",port:"27017",user:null,pass:null},VERSION=1,fields=["map","ctx","tag","reg","cfg"];import StorageInterface from"../interface.js";import{toArray}from"../../common.js";function sanitize(a){return a.toLowerCase().replace(/[^a-z0-9_\-]/g,"")}let CLIENT,Index=Object.create(null);export default function MongoDB(a,b={}){return this&&this.constructor===MongoDB?void("object"==typeof a&&(b=a,a=a.name),!a&&console.info("Default storage space was used, because a name was not passed."),this.id="flexsearch"+(a?"-"+sanitize(a):""),this.field=b.field?"-"+sanitize(b.field):"",this.type=b.type||"",this.db=b.db||Index[this.id]||CLIENT||null,this.trx=!1,this.support_tag_search=!0,Object.assign(defaults,b),this.db&&delete defaults.db):new MongoDB(a,b)}MongoDB.prototype.mount=function(a){return a.index?a.mount(this):(a.db=this,this.open())};async function createCollection(a,b,c){"map"===b?(await a.createCollection("map"+c),await a.collection("map"+c).createIndex({key:1}),await a.collection("map"+c).createIndex({id:1})):"ctx"===b?(await a.createCollection("ctx"+c),await a.collection("ctx"+c).createIndex({ctx:1,key:1}),await a.collection("ctx"+c).createIndex({id:1})):"tag"===b?(await a.createCollection("tag"+c),await a.collection("tag"+c).createIndex({tag:1}),await a.collection("tag"+c).createIndex({id:1})):"reg"===b?(await a.createCollection("reg"),await a.collection("reg").createIndex({id:1})):"cfg"===b?await a.createCollection("cfg"+c):void 0}MongoDB.prototype.open=async function(){if(!this.db&&!(this.db=Index[this.id])&&!(this.db=CLIENT)){let a=defaults.url;a||(a=defaults.user?`mongodb://${defaults.user}:${defaults.pass}@${defaults.host}:${defaults.port}`:`mongodb://${defaults.host}:${defaults.port}`),this.db=CLIENT=new MongoClient(a),await this.db.connect()}this.db.db&&(this.db=Index[this.id]=this.db.db(this.id));const a=await this.db.listCollections().toArray();for(let b,c=0;cl;k.push({ctx:d?j:l,key:d?l:j}),l=j}const m={_id:1};f||(m.res=1),g&&(m.doc=1);const n=[{$match:{$or:k}},{$group:{_id:"$id",count:{$sum:1},res:e?{$sum:"$res"}:{$sum:"$res"}}}];if(e||n.push({$match:{count:b.length-1}}),g&&(m.doc="$doc.doc",n.push({$lookup:{from:"reg",localField:"_id",foreignField:"id",as:"doc"}},{$unwind:{path:"$doc",preserveNullAndEmptyArrays:!0}})),h){const a={};for(let b=0,c=1;bl;k.push({ctx:d?j:l,key:d?l:j}),l=j}const m={_id:1};f||(m.res=1),g&&(m.doc=1);const n=[{$match:{$or:k}},{$group:{_id:"$id",count:{$sum:1},res:e?{$sum:"$res"}:{$sum:"$res"}}}];if(e||n.push({$match:{count:b.length-1}}),g&&(m.doc="$doc.doc",n.push({$lookup:{from:"reg",localField:"_id",foreignField:"id",as:"doc"}},{$unwind:{path:"$doc",preserveNullAndEmptyArrays:!0}})),h){const a={};for(let b=0,c=1;bconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return DB&&(await this.db.disconnect()),this.db=DB=null,this},RedisDB.prototype.destroy=function(){return this.clear(!0)},RedisDB.prototype.clear=function(a=!1){function b(a){return a.length&&c.db.unlink(a)}if(!this.id)return;const c=this;return Promise.all([this.db.keys(this.id+"map"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"ctx"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"tag"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"ref"+(a?"":this.field)+"*").then(b),b([this.id+"cfg"+(a?"*":this.field),this.id+"doc",this.id+"reg"])])};function create_result(a,b,c,d,e){if(c){for(let c,e,f=0;f=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc","number"===this.type?a.map(a=>""+a):a).then(function(b){for(let c=0;ce,k.push(c+(f?d:e)+":"+(f?e:d)),l.push(1),e=d}else{const a=this.id+"map"+this.field+":";for(let c=0;cconsole.error(a)).connect()},RedisDB.prototype.close=async function(){return DB&&(await this.db.disconnect()),this.db=DB=null,this},RedisDB.prototype.destroy=function(){return this.clear(!0)},RedisDB.prototype.clear=function(a=!1){function b(a){return a.length&&c.db.unlink(a)}if(!this.id)return;const c=this;return Promise.all([this.db.keys(this.id+"map"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"ctx"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"tag"+(a?"":this.field)+"*").then(b),this.db.keys(this.id+"ref"+(a?"":this.field)+"*").then(b),b([this.id+"cfg"+(a?"*":this.field),this.id+"doc",this.id+"reg"])])};function create_result(a,b,c,d,e){if(c){for(let c,e,f=0;f=a.length)return[];if(!b&&!c)return a;const f=a.slice(c,c+b);return d?e.enrich(f):f})},RedisDB.prototype.enrich=function(a){return"object"!=typeof a&&(a=[a]),this.db.hmGet(this.id+"doc","number"===this.type?a.map(a=>""+a):a).then(function(b){for(let c=0;ce,k.push(c+(f?d:e)+":"+(f?e:d)),l.push(1),e=d}else{const a=this.id+"map"+this.field+":";for(let c=0;cMAXIMUM_QUERY_VARS?a.slice(b,b+MAXIMUM_QUERY_VARS):b?a.slice(b):a;b+=d.length;let e=build_params(d.length);c.push(this.promisfy({method:"all",stmt:`SELECT id, doc FROM main.reg WHERE id IN (${e})`,params:d}))}return Promise.all(c).then(function(a){for(let c,d=0;dm;k+=(k?" OR ":"")+`(ctx = ? AND key = ?)`,l.push(d?j:m,d?m:j),m=j}if(h){k="("+k+")";for(let a=0;aMAXIMUM_QUERY_VARS?a.slice(b,b+MAXIMUM_QUERY_VARS):b?a.slice(b):a,e=build_params(d.length);b+=d.length,c.push(this.promisfy({method:"all",stmt:`SELECT id, doc FROM main.reg WHERE id IN (${e})`,params:d}))}return Promise.all(c).then(function(a){for(let c,d=0;dm;k+=(k?" OR ":"")+`(ctx = ? AND key = ?)`,l.push(d?j:m,d?m:j),m=j}if(h){k="("+k+")";for(let a=0;aMAXIMUM_QUERY_VARS)&&(this.db.run("INSERT INTO main.map"+this.field+" (key, res, id) VALUES "+c,e),c="",e=[])}}for(const b of a.ctx){const a=b[0],c=b[1];for(const b of c){const c=b[0],d=b[1];for(let b,e=0;eMAXIMUM_QUERY_VARS)&&(this.db.run("INSERT INTO main.ctx"+this.field+" (ctx, key, res, id) VALUES "+d,f),d="",f=[])}}}if(a.store){let b="",c=[];for(const d of a.store.entries()){const a=d[0],e=d[1];b+=(b?",":"")+"(?,?)",c.push(a,"object"==typeof e?JSON.stringify(e):e||null),c.length+2>MAXIMUM_QUERY_VARS&&(this.db.run("INSERT INTO main.reg (id, doc) VALUES "+b,c),b="",c=[])}c.length&&this.db.run("INSERT INTO main.reg (id, doc) VALUES "+b,c)}else if(!a.bypass){let b=toArray(a.reg);for(let a=0;aMAXIMUM_QUERY_VARS?b.slice(a,a+MAXIMUM_QUERY_VARS):a?b.slice(a):b;a+=c.length;const d=build_params(c.length,!0);this.db.run("INSERT INTO main.reg (id) VALUES "+d,c)}}if(a.tag){let b="",c=[];for(const d of a.tag){const a=d[0],e=d[1];if(e.length){for(let d=0;dMAXIMUM_QUERY_VARS&&(this.db.run("INSERT INTO main.tag"+this.field+" (tag, id) VALUES "+b,c),b="",c=[])}}c.length&&this.db.run("INSERT INTO main.tag"+this.field+" (tag, id) VALUES "+b,c)}}),a.map.clear(),a.ctx.clear(),a.tag&&a.tag.clear(),a.store&&a.store.clear(),a.document||a.reg.clear())},SqliteDB.prototype.remove=function(a){"object"!=typeof a&&(a=[a]);let b;a.length>MAXIMUM_QUERY_VARS&&(b=a.slice(MAXIMUM_QUERY_VARS),a=a.slice(0,MAXIMUM_QUERY_VARS));const c=this;return this.transaction(function(){const b=build_params(a.length);this.db.run("DELETE FROM main.map"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.ctx"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.tag"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.reg WHERE id IN ("+b+")",a)}).then(function(a){return b?c.remove(b):a})},SqliteDB.prototype.promisfy=function(a){const b=this.db;return new Promise(function(c,d){b[a.method](a.stmt,a.params||[],function(b,e){a.callback&&a.callback(e),b?d(b):c(e)})})}; \ No newline at end of file + `,params:b})}return i.then(function(a){return create_result(a,f,g)})},SqliteDB.prototype.info=function(){},SqliteDB.prototype.transaction=async function(a,b){if(TRX[this.id])return await a.call(this);const c=this.db,d=this;return TRX[this.id]=new Promise(function(e,f){c.exec("PRAGMA optimize"),c.exec("PRAGMA busy_timeout = 5000"),c.exec("BEGIN"),c.parallelize(function(){a.call(d)}),c.exec("COMMIT",function(a,g){return TRX[d.id]=null,a?f(a):void(b&&b(g),e(g),c.exec("PRAGMA shrink_memory"))})})},SqliteDB.prototype.commit=async function(a){let b=a.commit_task,c=[],d=[];a.commit_task=[];for(let e,f=0;fMAXIMUM_QUERY_VARS)&&(this.db.run("INSERT INTO main.map"+this.field+" (key, res, id) VALUES "+c,e),c="",e=[])}}for(const b of a.ctx){const a=b[0],c=b[1];for(const b of c){const c=b[0],d=b[1];for(let b,e=0;eMAXIMUM_QUERY_VARS)&&(this.db.run("INSERT INTO main.ctx"+this.field+" (ctx, key, res, id) VALUES "+d,f),d="",f=[])}}}if(a.store){let b="",c=[];for(const d of a.store.entries()){const a=d[0],e=d[1];b+=(b?",":"")+"(?,?)",c.push(a,"object"==typeof e?JSON.stringify(e):e||null),c.length+2>MAXIMUM_QUERY_VARS&&(this.db.run("INSERT INTO main.reg (id, doc) VALUES "+b+" ON CONFLICT DO NOTHING",c),b="",c=[])}c.length&&this.db.run("INSERT INTO main.reg (id, doc) VALUES "+b+" ON CONFLICT DO NOTHING",c)}else if(!a.bypass){let b=toArray(a.reg);for(let a=0;aMAXIMUM_QUERY_VARS?b.slice(a,a+MAXIMUM_QUERY_VARS):a?b.slice(a):b;a+=c.length;const d=build_params(c.length,!0);this.db.run("INSERT INTO main.reg (id) VALUES "+d+" ON CONFLICT DO NOTHING",c)}}if(a.tag){let b="",c=[];for(const d of a.tag){const a=d[0],e=d[1];if(e.length){for(let d=0;dMAXIMUM_QUERY_VARS&&(this.db.run("INSERT INTO main.tag"+this.field+" (tag, id) VALUES "+b,c),b="",c=[])}}c.length&&this.db.run("INSERT INTO main.tag"+this.field+" (tag, id) VALUES "+b,c)}}),d.length&&(await this.cleanup()),a.map.clear(),a.ctx.clear(),a.tag&&a.tag.clear(),a.store&&a.store.clear(),a.document||a.reg.clear())},SqliteDB.prototype.remove=function(a){"object"!=typeof a&&(a=[a]);let b;a.length>MAXIMUM_QUERY_VARS&&(b=a.slice(MAXIMUM_QUERY_VARS),a=a.slice(0,MAXIMUM_QUERY_VARS));const c=this;return this.transaction(function(){const b=build_params(a.length);this.db.run("DELETE FROM main.map"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.ctx"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.tag"+c.field+" WHERE id IN ("+b+")",a),this.db.run("DELETE FROM main.reg WHERE id IN ("+b+")",a)}).then(function(a){return b?c.remove(b):a})},SqliteDB.prototype.cleanup=function(){return this.transaction(function(){this.db.run("DELETE FROM main.map"+this.field+" WHERE ROWID IN (SELECT ROWID FROM (SELECT ROWID, row_number() OVER dupes AS count FROM main.map"+this.field+" _t WINDOW dupes AS (PARTITION BY id, key ORDER BY res) ) WHERE count > 1)"),this.db.run("DELETE FROM main.ctx"+this.field+" WHERE ROWID IN (SELECT ROWID FROM (SELECT ROWID, row_number() OVER dupes AS count FROM main.ctx"+this.field+" _t WINDOW dupes AS (PARTITION BY id, ctx, key ORDER BY res) ) WHERE count > 1)")})},SqliteDB.prototype.promisfy=function(a){const b=this.db;return new Promise(function(c,d){b[a.method](a.stmt,a.params||[],function(b,e){a.callback&&a.callback(e),b?d(b):c(e)})})}; \ No newline at end of file diff --git a/dist/module-min/document.js b/dist/module-min/document.js index b75bdbc..51c8750 100644 --- a/dist/module-min/document.js +++ b/dist/module-min/document.js @@ -1 +1 @@ -import{IndexOptions,DocumentOptions,DocumentDescriptor,FieldOptions,StoreOptions,EncoderOptions}from"./type.js";import StorageInterface from"./db/interface.js";import Index from"./index.js";import WorkerIndex from"./worker.js";import Encoder,{fallback_encoder}from"./encoder.js";import Cache,{searchCache}from"./cache.js";import{is_string,is_object,parse_simple}from"./common.js";import apply_async from"./async.js";import{exportDocument,importDocument}from"./serialize.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import"./document/add.js";import"./document/search.js";import Charset from"./charset.js";export default function Document(a){if(!this||this.constructor!==Document)return new Document(a);const b=a.document||a.doc||a;let c,d;if(this.tree=[],this.field=[],this.marker=[],this.key=(c=b.key||b.id)&&parse_tree(c,this.marker)||"id",d=a.keystore||0,d&&(this.keystore=d),this.fastupdate=!!a.fastupdate,this.reg=!this.fastupdate||a.worker||a.db?d&&!0?new KeystoreSet(d):new Set:d&&!0?new KeystoreMap(d):new Map,this.storetree=(c=b.store||null)&&c&&!0!==c&&[],this.store=c?d&&!0?new KeystoreMap(d):new Map:null,this.cache=(c=a.cache||null)&&new Cache(c),a.cache=!1,this.worker=a.worker||!1,this.priority=a.priority||4,this.index=parse_descriptor.call(this,a,b),(this.tag=null,(c=b.tag)&&("string"==typeof c&&(c=[c]),c.length))){this.tag=new Map,this.tagtree=[],this.tagfield=[];for(let a,b,d=0;dc.add(a,b)):this.add(a,b)},Index.prototype.cleanup=function(){return this.fastupdate?(remove_index(this.map),this.depth&&remove_index(this.ctx),this):(!1,this)},Index.prototype.searchCache=searchCache,Index.prototype.export=exportIndex,Index.prototype.import=importIndex,Index.prototype.serialize=serialize,apply_async(Index.prototype); \ No newline at end of file +import{IndexOptions,ContextOptions,EncoderOptions}from"./type.js";import Encoder,{fallback_encoder}from"./encoder.js";import Cache,{searchCache}from"./cache.js";import Charset from"./charset.js";import{KeystoreMap,KeystoreSet}from"./keystore.js";import{is_array,is_string}from"./common.js";import{exportIndex,importIndex,serialize}from"./serialize.js";import{remove_index}from"./index/remove.js";import apply_preset from"./preset.js";import apply_async from"./async.js";import tick from"./profiler.js";import"./index/add.js";import"./index/search.js";import"./index/remove.js";export default function Index(a,b){if(!this||this.constructor!==Index)return new Index(a);!1,a=a?apply_preset(a):{};let c=a.context;const d=!0===c?{depth:1}:c||{},e=is_string(a.encoder)?Charset[a.encoder]:a.encode||a.encoder||{};this.encoder=e.encode?e:"object"==typeof e?new Encoder(e):{encode:e},this.compress=a.compress||a.compression||!1,this.resolution=a.resolution||9,this.tokenize=c=(c=a.tokenize)&&"default"!==c&&"exact"!==c&&c||"strict",this.depth="strict"===c&&d.depth||0,this.bidirectional=!1!==d.bidirectional,this.fastupdate=!!a.fastupdate,this.score=a.score||null,!1,c=a.keystore||0,c&&(this.keystore=c),this.map=c&&!0?new KeystoreMap(c):new Map,this.ctx=c&&!0?new KeystoreMap(c):new Map,this.reg=b||(this.fastupdate?c&&!0?new KeystoreMap(c):new Map:c&&!0?new KeystoreSet(c):new Set),this.resolution_ctx=d.resolution||3,this.rtl=e.rtl||a.rtl||!1,this.cache=(c=a.cache||null)&&new Cache(c),this.resolve=!1!==a.resolve,(c=a.db)&&(this.db=this.mount(c)),this.commit_auto=!1!==a.commit,this.commit_task=[],this.commit_timer=null,this.priority=a.priority||4}Index.prototype.mount=function(a){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),a.mount(this)},Index.prototype.commit=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.commit(this)},Index.prototype.destroy=function(){return this.commit_timer&&(clearTimeout(this.commit_timer),this.commit_timer=null),this.db.destroy()};export function autoCommit(a){a.commit_timer||(a.commit_timer=setTimeout(function(){a.commit_timer=null,a.db.commit(a)},1))}Index.prototype.clear=function(){return this.map.clear(),this.ctx.clear(),this.reg.clear(),this.cache&&this.cache.clear(),this.db?(this.commit_timer&&clearTimeout(this.commit_timer),this.commit_timer=null,this.commit_task=[],this.db.clear()):this},Index.prototype.append=function(a,b){return this.add(a,b,!0)},Index.prototype.contain=function(a){return this.db?this.db.has(a):this.reg.has(a)},Index.prototype.update=function(a,b){const c=this,d=this.remove(a);return d&&d.then?d.then(()=>c.add(a,b)):this.add(a,b)},Index.prototype.cleanup=function(){return this.fastupdate?(remove_index(this.map),this.depth&&remove_index(this.ctx),this):(!1,this)},Index.prototype.searchCache=searchCache,Index.prototype.export=exportIndex,Index.prototype.import=importIndex,Index.prototype.serialize=serialize,apply_async(Index.prototype); \ No newline at end of file diff --git a/dist/module-min/index/add.js b/dist/module-min/index/add.js index 808d359..7627c76 100644 --- a/dist/module-min/index/add.js +++ b/dist/module-min/index/add.js @@ -1 +1 @@ -import{create_object}from"../common.js";import Index,{autoCommit}from"../index.js";import default_compress from"../compress.js";import{KeystoreArray}from"../keystore.js";Index.prototype.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.reg.has(a))return this.update(a,b);const e=this.depth;b=this.encoder.encode(b,!e);const f=b.length;if(f){const d=create_object(),g=create_object(),h=this.resolution;for(let j=0;je;l--)if(m=i.substring(e,l),!g[m]){d=this.rtl?k-1-e:e;const l=this.score?this.score(b,i,j,m,d):get_score(h,f,j,k,d);this.push_index(g,m,l,a,c)}break}case"bidirectional":case"reverse":if(1h?0:1),f,j,l-1,e-1),n=this.bidirectional&&i>k;this.push_index(d,n?k:i,m,a,c,n?i:k)}}}}}this.fastupdate||this.reg.add(a)}else b=""}return this.db&&(b||this.commit_task.push({del:a}),this.commit_auto&&autoCommit(this)),this},Index.prototype.push_index=function(a,b,c,d,e,f){let g,h=f?this.ctx:this.map;if((!a[b]||f&&!(g=a[b])[f])&&(f?(a=g||(a[b]=create_object()),a[f]=1,this.compress&&(f=default_compress(f)),g=h.get(f),g?h=g:h.set(f,h=new Map)):a[b]=1,this.compress&&(b=default_compress(b)),g=h.get(b),g?h=g:h.set(b,h=g=[]),h=h[c]||(h[c]=[]),!e||!h.includes(d))){if(2147483647===h.length){const a=new KeystoreArray(h);if(this.fastupdate)for(let b of this.reg.values())b.includes(h)&&(b[b.indexOf(h)]=a);g[c]=h=a}if(h.push(d),this.fastupdate){const a=this.reg.get(d);a?a.push(h):this.reg.set(d,[h])}}};function get_score(a,b,c,d,e){return c&&1e;l--){m=i.substring(e,l),d=this.rtl?k-1-e:e;const n=this.score?this.score(b,i,j,m,d):get_score(h,f,j,k,d);this._push_index(g,m,n,a,c)}break}case"bidirectional":case"reverse":if(1h,m=this.score?this.score(b,h,j,i,e-1):get_score(g+(f/2>g?0:1),f,j,k-1,e-1);this._push_index(d,l?h:i,m,a,c,l?i:h)}}}}}this.fastupdate||this.reg.add(a)}}return this.db&&(this.commit_task.push(c?{ins:a}:{del:a}),this.commit_auto&&autoCommit(this)),this},Index.prototype._push_index=function(a,b,c,d,e,f){let g,h;if(!(g=a[b])||f&&!g[f]){if(f?(a=g||(a[b]=create_object()),a[f]=1,this.compress&&(f=default_compress(f)),h=this.ctx,g=h.get(f),g?h=g:h.set(f,h=this.keystore?new KeystoreMap(this.keystore):new Map)):(h=this.map,a[b]=1),this.compress&&(b=default_compress(b)),g=h.get(b),g?h=g:h.set(b,h=g=[]),e)for(let a,b=0;bb,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file +import{SearchOptions,SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";import{create_object,is_object,sort_by_length_down}from"../common.js";import Index from"../index.js";import default_compress from"../compress.js";import Resolver from"../resolver.js";import{intersect}from"../intersect.js";import resolve_default from"../resolve/default.js";Index.prototype.search=function(a,b,c){if(c||(b||"object"!=typeof a?"object"==typeof b&&(c=b,b=0):(c=a,a="")),c&&c.cache){c.cache=!1;const d=this.searchCache(a,b,c);return c.cache=!0,d}let d,e,f,g,h,i,j,k,l=[],m=0;c&&(a=c.query||a,b=c.limit||b,m=c.offset||0,e=c.context,f=c.suggest,g=c.resolve,k=g&&c.enrich,i=c.boost,j=c.resolution,h=this.db&&c.tag),"undefined"==typeof g&&(g=this.resolve),e=this.depth&&!1!==e;let n=this.encoder.encode(a,!e);if(d=n.length,b=b||(g?100:0),1===d)return single_term_query.call(this,n[0],"",b,m,g,k,h);if(2===d&&e&&!f)return single_term_query.call(this,n[1],n[0],b,m,g,k,h);let o,p=create_object(),q=0;if(e&&(o=n[0],q=1),j||0===j||(j=o?this.resolution_ctx:this.resolution),this.db){if(this.db.search){const a=this.db.search(this,n,b,m,f,g,k,h);if(!1!==a)return a}const a=this;return async function(){for(let b,c;qb,i&&(i=b,b=a,a=i)),this.compress&&(a=default_compress(a),b&&(b=default_compress(b))),this.db)?this.db.get(a,b,c,d,e,f,g):(b?(h=this.ctx.get(b),h=h&&h.get(a)):h=this.map.get(a),h)}; \ No newline at end of file diff --git a/dist/module-min/resolve/handler.js b/dist/module-min/resolve/handler.js index 9fa3d74..cb14df0 100644 --- a/dist/module-min/resolve/handler.js +++ b/dist/module-min/resolve/handler.js @@ -1 +1 @@ -import Resolver from"../resolver.js";import{ResolverOptions,SearchResults,EnrichedSearchResults,IntermediateSearchResults}from"../type.js";Resolver.prototype.handler=function(a,b,c){let d=c[0];if(d[0]&&d[0].query)return this[a].apply(this,d);if("and"===a||"not"===a){let a,b=this.result.length||this.await;if(!b&&!d.suggest)return 1 MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids, + stmt = build_params(chunk.length); - const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids; count += chunk.length; - let stmt = build_params(chunk.length); - promises.push(this.promisfy({ method: "all", stmt: `SELECT id, doc FROM main.reg WHERE id IN (${stmt})`, @@ -512,34 +517,26 @@ SqliteDB.prototype.transaction = async function (task, callback) { }); }; -SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) { +SqliteDB.prototype.commit = async function (flexsearch) { + let tasks = flexsearch.commit_task, + removals = [], + inserts = []; - if (_replace) { - await this.clear(); + flexsearch.commit_task = []; - flexsearch.commit_task = []; - } else { - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for (let i = 0, task; i < tasks.length; i++) { - task = tasks[i]; - - if (task.clear) { - await this.clear(); - _replace = !0; - break; - } else { - tasks[i] = task.del; - } - } - if (!_replace) { - if (!_append) { - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && (await this.remove(tasks)); + for (let i = 0, task; i < tasks.length; i++) { + task = tasks[i]; + if ("undefined" != typeof task.del) { + removals.push(task.del); + } else if ("undefined" != typeof task.ins) { + inserts.push(task.ins); } } + if (removals.length) { + await this.remove(removals); + } + if (!flexsearch.reg.size) { return; } @@ -613,13 +610,13 @@ SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) { stmt += (stmt ? "," : "") + "(?,?)"; chunk.push(id, "object" == typeof doc ? JSON.stringify(doc) : doc || null); if (chunk.length + 2 > MAXIMUM_QUERY_VARS) { - this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); stmt = ""; chunk = []; } } if (chunk.length) { - this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id, doc) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); } } else if (!flexsearch.bypass) { let ids = toArray(flexsearch.reg); @@ -627,7 +624,7 @@ SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) { const chunk = ids.length - count > MAXIMUM_QUERY_VARS ? ids.slice(count, count + MAXIMUM_QUERY_VARS) : count ? ids.slice(count) : ids; count += chunk.length; const stmt = build_params(chunk.length, !0); - this.db.run("INSERT INTO main.reg (id) VALUES " + stmt, chunk); + this.db.run("INSERT INTO main.reg (id) VALUES " + stmt + " ON CONFLICT DO NOTHING", chunk); } } @@ -656,6 +653,10 @@ SqliteDB.prototype.commit = async function (flexsearch, _replace, _append) { } }); + if (inserts.length) { + await this.cleanup(); + } + flexsearch.map.clear(); flexsearch.ctx.clear(); flexsearch.tag && flexsearch.tag.clear(); @@ -688,6 +689,13 @@ SqliteDB.prototype.remove = function (ids) { }); }; +SqliteDB.prototype.cleanup = function () { + return this.transaction(function () { + this.db.run("DELETE FROM main.map" + this.field + " WHERE ROWID IN (SELECT ROWID FROM (SELECT ROWID, row_number() OVER dupes AS count FROM main.map" + this.field + " _t WINDOW dupes AS (PARTITION BY id, key ORDER BY res) ) WHERE count > 1)"); + this.db.run("DELETE FROM main.ctx" + this.field + " WHERE ROWID IN (SELECT ROWID FROM (SELECT ROWID, row_number() OVER dupes AS count FROM main.ctx" + this.field + " _t WINDOW dupes AS (PARTITION BY id, ctx, key ORDER BY res) ) WHERE count > 1)"); + }); +}; + SqliteDB.prototype.promisfy = function (opt) { const db = this.db; return new Promise(function (resolve, reject) { diff --git a/dist/module/document.js b/dist/module/document.js index 766dfd3..5df22a0 100644 --- a/dist/module/document.js +++ b/dist/module/document.js @@ -195,11 +195,11 @@ Document.prototype.mount = function (db) { }); }; -Document.prototype.commit = async function (replace, append) { +Document.prototype.commit = async function () { const promises = []; for (const index of this.index.values()) { - promises.push(index.commit(replace, append)); + promises.push(index.commit()); } await Promise.all(promises); this.reg.clear(); diff --git a/dist/module/document/search.js b/dist/module/document/search.js index 4f970ef..1322bff 100644 --- a/dist/module/document/search.js +++ b/dist/module/document/search.js @@ -246,7 +246,9 @@ Document.prototype.search = function (query, limit, options, _promises) { res = cache ? index.searchCache(query, limit, opt) : index.search(query, limit, opt); - opt_enrich && (opt.enrich = opt_enrich); + if (opt_enrich) { + opt.enrich = opt_enrich; + } if (promises) { promises[i] = res; diff --git a/dist/module/index.js b/dist/module/index.js index 9069761..7524e33 100644 --- a/dist/module/index.js +++ b/dist/module/index.js @@ -91,12 +91,12 @@ Index.prototype.mount = function (db) { } return db.mount(this); }; -Index.prototype.commit = function (replace, append) { +Index.prototype.commit = function () { if (this.commit_timer) { clearTimeout(this.commit_timer); this.commit_timer = null; } - return this.db.commit(this, replace, append); + return this.db.commit(this); }; Index.prototype.destroy = function () { if (this.commit_timer) { @@ -108,15 +108,12 @@ Index.prototype.destroy = function () { /** * @param {!Index} self - * @param {boolean=} replace - * @param {boolean=} append */ - -export function autoCommit(self, replace, append) { +export function autoCommit(self) { if (!self.commit_timer) { self.commit_timer = setTimeout(function () { self.commit_timer = null; - self.db.commit(self, replace, append); + self.db.commit(self); }, 1); } } diff --git a/dist/module/index/add.js b/dist/module/index/add.js index d0602be..ca0b70f 100644 --- a/dist/module/index/add.js +++ b/dist/module/index/add.js @@ -2,7 +2,7 @@ import { create_object } from "../common.js"; import Index, { autoCommit } from "../index.js"; import default_compress from "../compress.js"; -import { KeystoreArray } from "../keystore.js"; +import { KeystoreArray, KeystoreMap } from "../keystore.js"; /** * @param {!number|string} id @@ -10,7 +10,6 @@ import { KeystoreArray } from "../keystore.js"; * @param {boolean=} _append * @param {boolean=} _skip_update */ - Index.prototype.add = function (id, content, _append, _skip_update) { if (content && (id || 0 === id)) { @@ -24,28 +23,28 @@ Index.prototype.add = function (id, content, _append, _skip_update) { const depth = this.depth; content = this.encoder.encode(content, !depth); - const word_length = content.length; + const term_count = content.length; - if (word_length) { + if (term_count) { const dupes_ctx = create_object(), dupes = create_object(), resolution = this.resolution; - for (let i = 0; i < word_length; i++) { - let term = content[this.rtl ? word_length - 1 - i : i], + for (let i = 0; i < term_count; i++) { + let term = content[this.rtl ? term_count - 1 - i : i], term_length = term.length; if (term_length && (depth || !dupes[term])) { - let score = this.score ? this.score(content, term, i, null, 0) : get_score(resolution, word_length, i), + let score = this.score ? this.score(content, term, i, null, 0) : get_score(resolution, term_count, i), token = ""; switch (this.tokenize) { case "tolerant": - this.push_index(dupes, term, score, id, _append); + this._push_index(dupes, term, score, id, _append); if (2 < term_length) { for (let x = 1, char_a, char_b, prt_1, prt_2; x < term_length - 1; x++) { char_a = term.charAt(x); @@ -54,11 +53,13 @@ Index.prototype.add = function (id, content, _append, _skip_update) { prt_2 = term.substring(x + 2); token = prt_1 + char_a + prt_2; - dupes[token] || this.push_index(dupes, token, score, id, _append); + this._push_index(dupes, token, score, id, _append); token = prt_1 + prt_2; - dupes[token] || this.push_index(dupes, token, score, id, _append); + this._push_index(dupes, token, score, id, _append); } + + this._push_index(dupes, term.substring(0, term.length - 1), score, id, _append); } break; @@ -67,11 +68,9 @@ Index.prototype.add = function (id, content, _append, _skip_update) { for (let x = 0, _x; x < term_length; x++) { for (let y = term_length; y > x; y--) { token = term.substring(x, y); - if (!dupes[token]) { - _x = this.rtl ? term_length - 1 - x : x; - const partial_score = this.score ? this.score(content, term, i, token, _x) : get_score(resolution, word_length, i, term_length, _x); - this.push_index(dupes, token, partial_score, id, _append); - } + _x = this.rtl ? term_length - 1 - x : x; + const partial_score = this.score ? this.score(content, term, i, token, _x) : get_score(resolution, term_count, i, term_length, _x); + this._push_index(dupes, token, partial_score, id, _append); } } break; @@ -83,10 +82,8 @@ Index.prototype.add = function (id, content, _append, _skip_update) { if (1 < term_length) { for (let x = term_length - 1; 0 < x; x--) { token = term[this.rtl ? term_length - 1 - x : x] + token; - if (!dupes[token]) { - const partial_score = this.score ? this.score(content, term, i, token, x) : get_score(resolution, word_length, i, term_length, x); - this.push_index(dupes, token, partial_score, id, _append); - } + const partial_score = this.score ? this.score(content, term, i, token, x) : get_score(resolution, term_count, i, term_length, x); + this._push_index(dupes, token, partial_score, id, _append); } token = ""; } @@ -95,38 +92,28 @@ Index.prototype.add = function (id, content, _append, _skip_update) { if (1 < term_length) { for (let x = 0; x < term_length; x++) { token += term[this.rtl ? term_length - 1 - x : x]; - dupes[token] || this.push_index(dupes, token, score, id, _append); + this._push_index(dupes, token, score, id, _append); } break; } default: - this.push_index(dupes, term, score, id, _append); + this._push_index(dupes, term, score, id, _append); - if (depth) { - - if (1 < word_length && i < word_length - 1) { - const dupes_inner = create_object(), - resolution = this.resolution_ctx, - keyword = term, - size = Math.min(depth + 1, this.rtl ? i + 1 : word_length - i); + if (depth && 1 < term_count && i < term_count - 1) { + const resolution = this.resolution_ctx, + keyword = term, + size = Math.min(depth + 1, this.rtl ? i + 1 : term_count - i); - dupes_inner[keyword] = 1; + for (let x = 1; x < size; x++) { - for (let x = 1; x < size; x++) { + term = content[this.rtl ? term_count - 1 - i - x : i + x]; - term = content[this.rtl ? word_length - 1 - i - x : i + x]; + const swap = this.bidirectional && term > keyword, + context_score = this.score ? this.score(content, keyword, i, term, x - 1) : get_score(resolution + (term_count / 2 > resolution ? 0 : 1), term_count, i, size - 1, x - 1); - if (term && !dupes_inner[term]) { - - dupes_inner[term] = 1; - const context_score = this.score ? this.score(content, keyword, i, term, x - 1) : get_score(resolution + (word_length / 2 > resolution ? 0 : 1), word_length, i, size - 1, x - 1), - swap = this.bidirectional && term > keyword; - - this.push_index(dupes_ctx, swap ? keyword : term, context_score, id, _append, swap ? term : keyword); - } - } + this._push_index(dupes_ctx, swap ? keyword : term, context_score, id, _append, swap ? term : keyword); } } } @@ -134,14 +121,11 @@ Index.prototype.add = function (id, content, _append, _skip_update) { } this.fastupdate || this.reg.add(id); - } else { - content = ""; } } if (this.db) { - - content || this.commit_task.push({ del: id }); + this.commit_task.push(_append ? { ins: id } : { del: id }); this.commit_auto && autoCommit(this); } @@ -157,27 +141,27 @@ Index.prototype.add = function (id, content, _append, _skip_update) { * @param {boolean=} append * @param {string=} keyword */ +Index.prototype._push_index = function (dupes, term, score, id, append, keyword) { -Index.prototype.push_index = function (dupes, term, score, id, append, keyword) { - let arr = keyword ? this.ctx : this.map, - tmp; + let res, arr; - - if (!dupes[term] || keyword && !(tmp = dupes[term])[keyword]) { + if (!(res = dupes[term]) || keyword && !res[keyword]) { if (keyword) { - dupes = tmp || (dupes[term] = create_object()); + dupes = res || (dupes[term] = create_object()); dupes[keyword] = 1; if (this.compress) { keyword = default_compress(keyword); } - tmp = arr.get(keyword); - tmp ? arr = tmp : arr.set(keyword, arr = new Map()); + arr = this.ctx; + res = arr.get(keyword); + res ? arr = res : arr.set(keyword, arr = this.keystore ? new KeystoreMap(this.keystore) : new Map()); } else { + arr = this.map; dupes[term] = 1; } @@ -185,31 +169,48 @@ Index.prototype.push_index = function (dupes, term, score, id, append, keyword) term = default_compress(term); } - tmp = arr.get(term); - tmp ? arr = tmp : arr.set(term, arr = tmp = []); + res = arr.get(term); + res ? arr = res : arr.set(term, arr = res = []); - arr = arr[score] || (arr[score] = []); + if (append) { + for (let i = 0, arr; i < res.length; i++) { + arr = res[i]; + if (arr && arr.includes(id)) { + if (i <= score) { - if (!append || !arr.includes(id)) { - if (2147483647 === arr.length) { - const keystore = new KeystoreArray(arr); - if (this.fastupdate) { - for (let value of this.reg.values()) { - if (value.includes(arr)) { - value[value.indexOf(arr)] = keystore; + return; + } else { + + arr.splice(arr.indexOf(id), 1); + if (this.fastupdate) { + const tmp = this.reg.get(id); + tmp && tmp.splice(tmp.indexOf(arr), 1); } } + break; } - tmp[score] = arr = keystore; } + } + arr = arr[score] || (arr[score] = []); + arr.push(id); - arr.push(id); - + if (2147483647 === arr.length) { + const keystore = new KeystoreArray(arr); if (this.fastupdate) { - const tmp = this.reg.get(id); - tmp ? tmp.push(arr) : this.reg.set(id, [arr]); + for (let value of this.reg.values()) { + if (value.includes(arr)) { + value[value.indexOf(arr)] = keystore; + } + } } + res[score] = arr = keystore; + } + + + if (this.fastupdate) { + const tmp = this.reg.get(id); + tmp ? tmp.push(arr) : this.reg.set(id, [arr]); } } }; @@ -222,7 +223,6 @@ Index.prototype.push_index = function (dupes, term, score, id, append, keyword) * @param {number=} x * @returns {number} */ - function get_score(resolution, length, i, term_length, x) { return i && 1 < resolution ? length + (term_length || 0) <= resolution ? i + (x || 0) : 0 | (resolution - 1) / (length + (term_length || 0)) * (i + (x || 0)) + 1 : 0; diff --git a/dist/module/index/search.js b/dist/module/index/search.js index 5fb6c4e..b9b2f7e 100644 --- a/dist/module/index/search.js +++ b/dist/module/index/search.js @@ -114,7 +114,7 @@ Index.prototype.search = function (query, limit, options) { if (term && !dupes[term]) { dupes[term] = 1; - arr = await self.get_array(term, keyword, 0, 0, !1, !1); + arr = await self._get_array(term, keyword, 0, 0, !1, !1); arr = add_result(arr, /** @type {Array} */result, suggest, resolution); if (arr) { @@ -152,7 +152,7 @@ Index.prototype.search = function (query, limit, options) { if (term && !dupes[term]) { dupes[term] = 1; - arr = this.get_array(term, keyword, 0, 0, !1, !1); + arr = this._get_array(term, keyword, 0, 0, !1, !1); arr = add_result(arr, /** @type {Array} */result, suggest, resolution); if (arr) { @@ -227,7 +227,7 @@ function return_result(result, resolution, limit, offset, suggest, boost, resolv function single_term_query(term, keyword, limit, offset, resolve, enrich, tag) { - const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag); + const result = this._get_array(term, keyword, limit, offset, resolve, enrich, tag); if (this.db) { return result.then(function (result) { @@ -292,7 +292,7 @@ function add_result(arr, result, suggest, resolution) { * Promise * } */ -Index.prototype.get_array = function (term, keyword, limit, offset, resolve, enrich, tag) { +Index.prototype._get_array = function (term, keyword, limit, offset, resolve, enrich, tag) { let arr, swap; diff --git a/dist/module/resolve/handler.js b/dist/module/resolve/handler.js index 626646a..e4457a1 100644 --- a/dist/module/resolve/handler.js +++ b/dist/module/resolve/handler.js @@ -70,11 +70,12 @@ Resolver.prototype.handler = function (method, fn, args) { offset = query.offset || 0; suggest = query.suggest; resolve = query.resolve; - highlight = resolve && query.highlight; + highlight = query.highlight || this.highlight; enrich = (highlight || query.enrich) && resolve; let opt_queue = query.queue, opt_async = query.async || opt_queue, - index = query.index; + index = query.index, + query_value = query.query; if (index) { @@ -83,14 +84,15 @@ Resolver.prototype.handler = function (method, fn, args) { index = this.index; } - if (query.query || query.tag) { + if (query_value || query.tag) { { const field = query.field || query.pluck; if (field) { - if (query.query) { - this.query = query.query; + if (query_value && (!this.query || highlight)) { + this.query = query_value; this.field = field; + this.highlight = highlight; } index = index.index.get(field); @@ -132,9 +134,7 @@ Resolver.prototype.handler = function (method, fn, args) { } else { query.resolve = !1; query.index = null; - result = opt_async ? index.searchAsync(query) : index.search(query); - query.resolve = resolve; query.index = index; } diff --git a/dist/module/resolver.js b/dist/module/resolver.js index 41b53a3..87c3483 100644 --- a/dist/module/resolver.js +++ b/dist/module/resolver.js @@ -27,6 +27,7 @@ export default function Resolver(result, index) { promises, query, field, + highlight, _await, _return; @@ -36,6 +37,7 @@ export default function Resolver(result, index) { boost = options.boost || 0; if (query = options.query) { field = options.field || options.pluck; + highlight = options.highlight; const resolve = options.resolve, async = options.async || options.queue; @@ -76,6 +78,8 @@ export default function Resolver(result, index) { /** @type {Function} */ this.return = _return || null; + /** @type {HighlightOptions|null} */ + this.highlight = /** @type {HighlightOptions|null} */highlight || null; /** @type {string} */ this.query = query || ""; /** @type {string} */ @@ -89,8 +93,7 @@ Resolver.prototype.limit = function (limit) { if (this.await) { const self = this; this.promises.push(function () { - self.limit(limit); - return self.result; + return self.limit(limit).result; }); } else { if (this.result.length) { @@ -121,8 +124,7 @@ Resolver.prototype.offset = function (offset) { if (this.await) { const self = this; this.promises.push(function () { - self.offset(offset); - return self.result; + return self.offset(offset).result; }); } else { if (this.result.length) { @@ -151,8 +153,7 @@ Resolver.prototype.boost = function (boost) { if (this.await) { const self = this; this.promises.push(function () { - self.boost(boost); - return self.result; + return self.boost(boost).result; }); } else { this.boostval += boost; @@ -215,12 +216,12 @@ Resolver.prototype.resolve = function (limit, offset, enrich, highlight, _resolv if (result.length) { if ("object" == typeof limit) { - highlight = limit.highlight; + highlight = limit.highlight || this.highlight; enrich = !!highlight || limit.enrich; offset = limit.offset; limit = limit.limit; } else { - highlight = highlight; + highlight = highlight || this.highlight; enrich = !!highlight || enrich; } result = _resolved ? enrich ? apply_enrich.call( @@ -247,6 +248,7 @@ Resolver.prototype.finalize = function (result, highlight) { const fn = this.return; this.index = this.result = this.promises = this.await = this.return = null; + this.highlight = null; this.query = this.field = ""; diff --git a/doc/result-highlighting.md b/doc/result-highlighting.md index fe3753c..c094b69 100644 --- a/doc/result-highlighting.md +++ b/doc/result-highlighting.md @@ -324,3 +324,27 @@ Result: ```js "... dolor sit amet conset..." ``` + +### Using Result Highlighting on Resolver + +When using complex queries by `Resolver` you can pass a highlight option to any one of the resolver stages that is also including a query. The last resolver stage will then automatically inherit necessary options. + +```js +const raw = new Resolver({ + index: index, + field: "title", + query: "some query" +}) +.or({ + field: "title", + // highlight requires a query + query: "highlight this", + // define on a single resolver stage + highlight: { /* ... */ } +}) +.not({ + field: "title", + query: "undefined", +}) +.resolve(); +``` \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 004fd00..dd28b69 100644 --- a/index.d.ts +++ b/index.d.ts @@ -282,7 +282,7 @@ declare module "flexsearch" { // Persistent Index mount(db: StorageInterface): Promise; - commit(replace_all_contents?: boolean): Promise; + commit(): Promise; destroy(): Promise; @@ -749,7 +749,7 @@ declare module "flexsearch" { // Persistent Index mount>(db: S): Promise; - commit(replace_all_contents?: boolean): Promise; + commit(): Promise; destroy(): Promise; @@ -941,8 +941,9 @@ declare module "flexsearch" { export type DefaultResolve< D extends DocumentData = undefined, + H extends HighlightOptions | boolean = false, R extends boolean = true, - E extends boolean = false + E extends boolean = H extends false ? false : true, > = { limit?: number; offset?: number; @@ -951,6 +952,9 @@ declare module "flexsearch" { enrich?: D extends undefined ? false : R extends true ? E : false; + highlight?: D extends undefined + ? false + : H; // R extends true ? H : false; }; export type ResolverOptions< @@ -961,7 +965,7 @@ declare module "flexsearch" { R extends boolean = false, E extends boolean = H extends false ? false : true, A extends boolean = false - > = Resolver | (DefaultResolve & { + > = Resolver | (DefaultResolve & { query?: string; index?: Index | Document | Worker; pluck?: FieldName; @@ -976,10 +980,6 @@ declare module "flexsearch" { cache?: boolean; async?: A; queue?: A; - /** only usable when "resolve" was not set to false */ - highlight?: D extends undefined - ? false - : R extends true ? H : false; }); export type HighlightBoundaryOptions = { @@ -1071,10 +1071,11 @@ declare module "flexsearch" { boost(boost: number): Resolver; resolve< - e extends boolean = E, + h extends HighlightOptions | boolean = H, + e extends boolean = h extends HighlightOptions ? true : E, a extends boolean = A - >(options?: DefaultResolve): - DocumentSearchResultsWrapper; + >(options?: DefaultResolve): + DocumentSearchResultsWrapper; } export class StorageInterface { diff --git a/package-lock.json b/package-lock.json index 9e815b5..ff224c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "flexsearch", - "version": "0.8.203", + "version": "0.8.205", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "flexsearch", - "version": "0.8.203", + "version": "0.8.205", "funding": [ { "type": "github", diff --git a/package.json b/package.json index 0674893..3f08e02 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "public": true, "preferGlobal": false, "name": "flexsearch", - "version": "0.8.204", + "version": "0.8.205", "description": "Next-Generation full-text search library for Browser and Node.js", "homepage": "https://github.com/nextapps-de/flexsearch/", "author": "Thomas Wilkerling", diff --git a/src/db/clickhouse/index.js b/src/db/clickhouse/index.js index 9ee8840..62231e0 100644 --- a/src/db/clickhouse/index.js +++ b/src/db/clickhouse/index.js @@ -496,36 +496,27 @@ ClickhouseDB.prototype.transaction = function(task){ return task.call(this); }; -ClickhouseDB.prototype.commit = async function(flexsearch, _replace, _append){ +ClickhouseDB.prototype.commit = async function(flexsearch){ - // process cleanup tasks - if(_replace){ - await this.clear(); - // there are just removals in the task queue - flexsearch.commit_task = []; - } - else{ - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - // there are just removals in the task queue - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else{ - tasks[i] = task.del; - } + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); + else if(task["ins"]){ + } } + + if(removals.length){ + await this.remove(removals); + } + if(!flexsearch.reg.size){ return; } diff --git a/src/db/indexeddb/index.js b/src/db/indexeddb/index.js index b44841d..4f4b308 100644 --- a/src/db/indexeddb/index.js +++ b/src/db/indexeddb/index.js @@ -380,36 +380,25 @@ IdxDB.prototype.transaction = function(ref, modifier, task){ // }); }; -IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ +IdxDB.prototype.commit = async function(flexsearch){ - // process cleanup tasks - if(_replace){ - await this.clear(); - // there are just removals in the task queue - flexsearch.commit_task = []; + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); + } + // else if(task["ins"]){ + // + // } } - else{ - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - /** @dict */ - task = tasks[i]; - // there are just removals in the task queue - if(task["clear"]){ - await this.clear(); - _replace = true; - break; - } - else{ - tasks[i] = task["del"]; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); - } + + if(removals.length){ + await this.remove(removals); } if(!flexsearch.reg.size){ @@ -424,10 +413,10 @@ IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ const value = item[1]; if(!value.length) continue; - if(_replace){ - store.put(value, key); - continue; - } + // if(_replace){ + // store.put(value, key); + // continue; + // } store.get(key).onsuccess = function(){ let result = this.result; @@ -481,10 +470,10 @@ IdxDB.prototype.commit = async function(flexsearch, _replace, _append){ const value = item[1]; if(!value.length) continue; - if(_replace){ - store.put(value, ctx_key + ":" + key); - continue; - } + // if(_replace){ + // store.put(value, ctx_key + ":" + key); + // continue; + // } store.get(ctx_key + ":" + key).onsuccess = function(){ let result = this.result; diff --git a/src/db/interface.js b/src/db/interface.js index 35e364d..dc1907d 100644 --- a/src/db/interface.js +++ b/src/db/interface.js @@ -21,7 +21,7 @@ StorageInterface.prototype.destroy = async function(){}; // ------------------------------ // transfer all changes of an index to the database -StorageInterface.prototype.commit = async function(index, _replace, _append){}; +StorageInterface.prototype.commit = async function(index/*, _replace, _append*/){}; /** * get results of a term "key" with optional context "ctx" * @param {!string} key diff --git a/src/db/mongodb/index.js b/src/db/mongodb/index.js index 62b3dc8..4032ce8 100644 --- a/src/db/mongodb/index.js +++ b/src/db/mongodb/index.js @@ -548,35 +548,25 @@ MongoDB.prototype.transaction = function(task){ return task.call(this); }; -MongoDB.prototype.commit = async function(flexsearch, _replace, _append){ +MongoDB.prototype.commit = async function(flexsearch){ - // process cleanup tasks - if(_replace){ - await this.clear(); - // there are just removals in the task queue - flexsearch.commit_task = []; + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); + } + else if(task["ins"]){ + + } } - else{ - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - // there are just removals in the task queue - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else{ - tasks[i] = task.del; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); - } + + if(removals.length){ + await this.remove(removals); } if(!flexsearch.reg.size){ diff --git a/src/db/postgres/index.js b/src/db/postgres/index.js index fc55ef7..dc755da 100644 --- a/src/db/postgres/index.js +++ b/src/db/postgres/index.js @@ -564,37 +564,25 @@ PostgresDB.prototype.transaction = function(task){ // }); // }; -PostgresDB.prototype.commit = async function(flexsearch, _replace, _append){ +PostgresDB.prototype.commit = async function(flexsearch){ - // process cleanup tasks - if(_replace){ - await this.clear(); - // there are just removals in the task queue - flexsearch.commit_task = []; + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); + } + else if(task["ins"]){ + + } } - else{ - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - // there are just removals in the task queue - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else{ - tasks[i] = task.del; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg)); - } - tasks.length && await this.remove(tasks); - } - //console.log("tasks:", tasks) + if(removals.length){ + await this.remove(removals); } if(!flexsearch.reg.size){ diff --git a/src/db/redis/index.js b/src/db/redis/index.js index b5d1759..caba23a 100644 --- a/src/db/redis/index.js +++ b/src/db/redis/index.js @@ -334,35 +334,25 @@ RedisDB.prototype.transaction = function(task, callback){ }); }; -RedisDB.prototype.commit = async function(flexsearch, _replace, _append){ +RedisDB.prototype.commit = async function(flexsearch){ - // process cleanup tasks - if(_replace){ - await this.clear(); - // there are just removals in the task queue - flexsearch.commit_task = []; + let tasks = flexsearch.commit_task; + let removals = []; + flexsearch.commit_task = []; + + for(let i = 0, task; i < tasks.length; i++){ + /** @dict */ + task = tasks[i]; + if(task["del"]){ + removals.push(task["del"]); + } + else if(task["ins"]){ + + } } - else{ - let tasks = flexsearch.commit_task; - flexsearch.commit_task = []; - for(let i = 0, task; i < tasks.length; i++){ - task = tasks[i]; - // there are just removals in the task queue - if(task.clear){ - await this.clear(); - _replace = true; - break; - } - else{ - tasks[i] = "" + task.del; - } - } - if(!_replace){ - if(!_append){ - tasks = tasks.concat(toArray(flexsearch.reg, /* stringify */ true)); - } - tasks.length && await this.remove(tasks); - } + + if(removals.length){ + await this.remove(removals); } if(!flexsearch.reg.size){ diff --git a/src/document.js b/src/document.js index b25f46e..325070f 100644 --- a/src/document.js +++ b/src/document.js @@ -255,11 +255,11 @@ if(SUPPORT_PERSISTENT){ }); }; - Document.prototype.commit = async function(replace, append){ + Document.prototype.commit = async function(/*replace, append*/){ // parallel: const promises = []; for(const index of this.index.values()){ - promises.push(index.commit(replace, append)); + promises.push(index.commit(/*replace, append*/)); } await Promise.all(promises); this.reg.clear(); diff --git a/src/index.js b/src/index.js index 1b7e473..d7137c6 100644 --- a/src/index.js +++ b/src/index.js @@ -154,12 +154,12 @@ if(SUPPORT_PERSISTENT){ } return db.mount(this); }; - Index.prototype.commit = function(replace){ + Index.prototype.commit = function(/*replace*/){ if(this.commit_timer){ clearTimeout(this.commit_timer); this.commit_timer = null; } - return this.db.commit(this, replace); + return this.db.commit(this/*, replace*/); }; Index.prototype.destroy = function(){ if(this.commit_timer){ @@ -172,15 +172,12 @@ if(SUPPORT_PERSISTENT){ /** * @param {!Index} self - * @param {boolean=} replace - * @param {boolean=} append */ - -export function autoCommit(self, replace, append){ +export function autoCommit(self/*, replace, append*/){ if(!self.commit_timer){ self.commit_timer = setTimeout(function(){ self.commit_timer = null; - self.db.commit(self, replace, append); + self.db.commit(self/*, replace, append*/); }, 1); } } diff --git a/src/resolve/handler.js b/src/resolve/handler.js index ce0e6ac..185ceb4 100644 --- a/src/resolve/handler.js +++ b/src/resolve/handler.js @@ -80,11 +80,12 @@ Resolver.prototype.handler = function(method, fn, args){ offset = query.offset || 0; suggest = query.suggest; resolve = query.resolve; - highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && resolve && query.highlight; + highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && (query.highlight || this.highlight); enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && (highlight || query.enrich) && resolve; let opt_queue = SUPPORT_ASYNC && query.queue; let opt_async = SUPPORT_ASYNC && (query.async || opt_queue); let index = query.index; + let query_value = query.query; if(index){ this.index || (this.index = index); @@ -93,7 +94,7 @@ Resolver.prototype.handler = function(method, fn, args){ index = this.index; } - if(query.query || query.tag){ + if(query_value || query.tag){ if(DEBUG){ if(!index){ @@ -105,9 +106,10 @@ Resolver.prototype.handler = function(method, fn, args){ const field = query.field || query.pluck; if(field){ - if(SUPPORT_STORE && SUPPORT_HIGHLIGHTING && query.query){ - this.query = query.query; + if(SUPPORT_STORE && SUPPORT_HIGHLIGHTING && query_value && (!this.query || highlight)){ + this.query = query_value; this.field = field; + this.highlight = highlight; } if(DEBUG){ @@ -166,11 +168,9 @@ Resolver.prototype.handler = function(method, fn, args){ else { query.resolve = false; query.index = null; - result = opt_async ? index.searchAsync(query) : index.search(query); - query.resolve = resolve; query.index = index; } diff --git a/src/resolver.js b/src/resolver.js index beaa2f6..751a1f9 100644 --- a/src/resolver.js +++ b/src/resolver.js @@ -2,7 +2,8 @@ import { DEBUG, SUPPORT_ASYNC, - SUPPORT_DOCUMENT, SUPPORT_HIGHLIGHTING, + SUPPORT_DOCUMENT, + SUPPORT_HIGHLIGHTING, SUPPORT_STORE } from "./config.js"; // <-- COMPILER BLOCK @@ -42,6 +43,7 @@ export default function Resolver(result, index){ let promises; let query; let field; + let highlight; let _await; let _return; @@ -51,6 +53,7 @@ export default function Resolver(result, index){ boost = options.boost || 0; if((query = options.query)){ field = options.field || options.pluck; + highlight = options.highlight; const resolve = options.resolve; const async = options.async || options.queue; options.resolve = false; @@ -94,6 +97,8 @@ export default function Resolver(result, index){ this.return = _return || null; if(SUPPORT_HIGHLIGHTING){ + /** @type {HighlightOptions|null} */ + this.highlight = /** @type {HighlightOptions|null} */ (highlight || null); /** @type {string} */ this.query = query || ""; /** @type {string} */ @@ -108,8 +113,7 @@ Resolver.prototype.limit = function(limit){ if(this.await){ const self = this; this.promises.push(function(){ - self.limit(limit); - return self.result; + return self.limit(limit).result; }); } else{ @@ -142,8 +146,7 @@ Resolver.prototype.offset = function(offset){ if(this.await){ const self = this; this.promises.push(function(){ - self.offset(offset); - return self.result; + return self.offset(offset).result; }); } else{ @@ -174,8 +177,7 @@ Resolver.prototype.boost = function(boost){ if(this.await){ const self = this; this.promises.push(function(){ - self.boost(boost); - return self.result; + return self.boost(boost).result; }); } else{ @@ -247,13 +249,13 @@ Resolver.prototype.resolve = function(limit, offset, enrich, highlight, _resolve if(result.length){ if(typeof limit === "object"){ - highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && limit.highlight; + highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && (limit.highlight || this.highlight); enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && (!!highlight || limit.enrich); offset = limit.offset; limit = limit.limit; } else{ - highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && highlight; + highlight = SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && (highlight || this.highlight); enrich = SUPPORT_DOCUMENT && SUPPORT_STORE && (!!highlight || enrich); } result = _resolved @@ -280,7 +282,7 @@ Resolver.prototype.finalize = function(result, highlight){ if(DEBUG){ if(highlight && !this.query){ - console.warn('There was no query specified for highlighting. Please specify a query within the last resolver stage like { query: "...", resolve: true, highlight: ... }.'); + console.warn('There was no query specified for highlighting. Please specify a query within the highlight resolver stage like { query: "...", highlight: ... }.'); } } if(SUPPORT_DOCUMENT && SUPPORT_STORE && SUPPORT_HIGHLIGHTING && highlight && result.length && this.query){ @@ -295,6 +297,7 @@ Resolver.prototype.finalize = function(result, highlight){ this.return = null; if(SUPPORT_HIGHLIGHTING){ + this.highlight = null; this.query = this.field = ""; } diff --git a/test/types.ts b/test/types.ts index d1499e9..30a2912 100644 --- a/test/types.ts +++ b/test/types.ts @@ -261,6 +261,9 @@ async function test_document() { const doc36: Promise = doc24.and({ queue: true, cache: true }).resolve(); const doc37: Promise = doc24.and({ queue: true, cache: true }).resolve({ enrich: true }); const doc38: Promise = doc24.and({ queue: true }, { enrich: true, highlight: true, resolve: true }); + const doc39: Promise = doc14.or({ queue: true, cache: true, query: "", highlight: "" }).not({}).resolve(); + const doc40: EnrichedResults = doc24.or({ cache: true, query: "", highlight: "" }).not({}).resolve(); + const doc41: EnrichedResults = doc24.or({ cache: true, query: "" }).not({}).resolve({ highlight: "" }); (function(){ const api1: Document = document.clear(); @@ -273,9 +276,7 @@ async function test_document() { const api8: Document = document.update({ id: 1, tags: [""], title: "", description: "" }); }()); - // highlight on .resolve() is never supported: - // @ts-expect-error - const err0: EnrichedResults = doc24.resolve({ highlight: "" }); + //const err0: EnrichedResults = doc24.resolve({ highlight: "" }); // @ts-expect-error const err1: DocumentData = doc1[0].result[0].doc; @@ -432,11 +433,14 @@ async function test_persistent() { const doc36: Promise = doc24.and({ queue: true, cache: true }).resolve(); const doc37: Promise = doc24.and({ queue: true, cache: true }).resolve({ enrich: true }); const doc38: Promise = doc24.and({ queue: true }, { enrich: true, highlight: true, resolve: true }); + const doc39: Promise = doc14.or({ queue: true, cache: true, query: "", highlight: "" }).not({}).resolve(); + const doc40: Promise = doc24.or({ cache: true, query: "", highlight: "" }).not({}).resolve(); + const doc41: Promise = doc24.or({ cache: true, query: "" }).not({}).resolve({ highlight: "" }); - const doc39: Resolver = doc24.and({ cache: true }); - const doc40: Promise = doc24.and({ cache: true }).resolve(); - const doc41: Promise = doc24.and({ cache: true }).resolve({ enrich: true }); - const doc42: Promise = doc24.and({}, { enrich: true, highlight: true, resolve: true }); + const doc42: Resolver = doc24.and({ cache: true }); + const doc43: Promise = doc24.and({ cache: true }).resolve(); + const doc44: Promise = doc24.and({ cache: true }).resolve({ enrich: true }); + const doc45: Promise = doc24.and({}, { enrich: true, highlight: true, resolve: true }); (function(){ const api1: Promise = document.clear(); @@ -450,10 +454,6 @@ async function test_persistent() { const api9: Promise = document.commit(); }()); - // highlight on .resolve() is never supported: - // @ts-expect-error - const err0: EnrichedResults = doc24.resolve({ highlight: "" }); - // @ts-expect-error const err1: DocumentData = doc1[0].result[0].doc; const err2: DocumentData = doc2[0].result[0].doc; @@ -607,11 +607,14 @@ async function test_worker() { const doc36: Promise = doc24.and({ queue: true, cache: true }).resolve(); const doc37: Promise = doc24.and({ queue: true, cache: true }).resolve({ enrich: true }); const doc38: Promise = doc24.and({ queue: true }, { enrich: true, highlight: true, resolve: true }); + const doc39: Promise = doc14.or({ queue: true, cache: true, query: "", highlight: "" }).not({}).resolve(); + const doc40: Promise = doc24.or({ cache: true, query: "", highlight: "" }).not({}).resolve(); + const doc41: Promise = doc24.or({ cache: true, query: "" }).not({}).resolve({ highlight: "" }); - const doc39: Resolver = doc24.and({ cache: true }); - const doc40: Promise = doc24.and({ cache: true }).resolve(); - const doc41: Promise = doc24.and({ cache: true }).resolve({ enrich: true }); - const doc42: Promise = doc24.and({}, { enrich: true, highlight: true, resolve: true }); + const doc42: Resolver = doc24.and({ cache: true }); + const doc43: Promise = doc24.and({ cache: true }).resolve(); + const doc44: Promise = doc24.and({ cache: true }).resolve({ enrich: true }); + const doc45: Promise = doc24.and({}, { enrich: true, highlight: true, resolve: true }); (function(){ const api1: Promise = document.clear(); @@ -624,10 +627,6 @@ async function test_worker() { const api8: Promise> = document.update({ id: 1, tags: [""], title: "", description: "" }); }()); - // highlight on .resolve() is never supported: - // @ts-expect-error - const err0: EnrichedResults = doc24.resolve({ highlight: "" }); - // @ts-expect-error const err1: DocumentData = doc1[0].result[0].doc; const err2: DocumentData = doc2[0].result[0].doc;